(node: Node<T>, x: number, y: number)
| 711 | } |
| 712 | |
| 713 | protected buildSection(node: Node<T>, x: number, y: number): LayoutNode { |
| 714 | if (this.anchorTo === 'end' && this.orientation === 'vertical') { |
| 715 | throw new Error( |
| 716 | 'ListLayout with anchorTo="end" only supports flat root-level items and an optional root loader.' |
| 717 | ); |
| 718 | } |
| 719 | |
| 720 | let collection = this.virtualizer!.collection; |
| 721 | let width = this.virtualizer!.size.width - this.padding - x; |
| 722 | let height = this.virtualizer!.size.height - this.padding - y; |
| 723 | let rect = |
| 724 | this.orientation === 'horizontal' ? new Rect(x, y, 0, height) : new Rect(x, y, width, 0); |
| 725 | let layoutInfo = new LayoutInfo(node.type, node.key, rect); |
| 726 | |
| 727 | let offset = this.orientation === 'horizontal' ? x : y; |
| 728 | let offsetProperty = this.orientation === 'horizontal' ? 'x' : 'y'; |
| 729 | let maxOffsetProperty = this.orientation === 'horizontal' ? 'maxX' : 'maxY'; |
| 730 | let heightProperty = this.orientation === 'horizontal' ? 'width' : 'height'; |
| 731 | |
| 732 | let skipped = 0; |
| 733 | let children: LayoutNode[] = []; |
| 734 | for (let child of getChildNodes(node, collection)) { |
| 735 | // skip if it is a content node, Tree specific for now, if we add content nodes to other collection items, we might need to reconsider this |
| 736 | if (child.type === 'content') { |
| 737 | continue; |
| 738 | } |
| 739 | |
| 740 | let rowHeight = (this.rowSize ?? this.estimatedRowSize ?? DEFAULT_HEIGHT) + this.gap; |
| 741 | |
| 742 | // Skip rows before the valid rectangle unless they are already cached. |
| 743 | if (offset + rowHeight < this.requestedRect[offsetProperty] && !this.isValid(node, offset)) { |
| 744 | offset += rowHeight; |
| 745 | skipped++; |
| 746 | continue; |
| 747 | } |
| 748 | |
| 749 | let layoutNode = |
| 750 | this.orientation === 'horizontal' |
| 751 | ? this.buildChild(child, offset, y, layoutInfo.key) |
| 752 | : this.buildChild(child, x, offset, layoutInfo.key); |
| 753 | offset = layoutNode.layoutInfo.rect[maxOffsetProperty] + this.gap; |
| 754 | children.push(layoutNode); |
| 755 | |
| 756 | if (offset > this.requestedRect[maxOffsetProperty]) { |
| 757 | // Estimate the remaining height for rows that we don't need to layout right now. |
| 758 | offset += |
| 759 | ([...getChildNodes(node, collection)].length - (children.length + skipped)) * rowHeight; |
| 760 | break; |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | offset -= this.gap; |
| 765 | rect[heightProperty] = offset - (this.orientation === 'horizontal' ? x : y); |
| 766 | |
| 767 | return { |
| 768 | layoutInfo, |
| 769 | children, |
| 770 | validRect: layoutInfo.rect.intersection(this.requestedRect), |
no test coverage detected