(node: Node<T>, x: number, y: number)
| 735 | } |
| 736 | |
| 737 | protected buildSection(node: Node<T>, x: number, y: number): LayoutNode { |
| 738 | if (this.anchorTo === 'end' && this.orientation === 'vertical') { |
| 739 | throw new Error( |
| 740 | 'ListLayout with anchorTo="end" only supports flat root-level items and an optional root loader.' |
| 741 | ); |
| 742 | } |
| 743 | |
| 744 | let collection = this.virtualizer!.collection; |
| 745 | let width = this.virtualizer!.size.width - this.padding - x; |
| 746 | let height = this.virtualizer!.size.height - this.padding - y; |
| 747 | let rect = |
| 748 | this.orientation === 'horizontal' ? new Rect(x, y, 0, height) : new Rect(x, y, width, 0); |
| 749 | let layoutInfo = new LayoutInfo(node.type, node.key, rect); |
| 750 | |
| 751 | let offset = this.orientation === 'horizontal' ? x : y; |
| 752 | let offsetProperty = this.orientation === 'horizontal' ? 'x' : 'y'; |
| 753 | let maxOffsetProperty = this.orientation === 'horizontal' ? 'maxX' : 'maxY'; |
| 754 | let heightProperty = this.orientation === 'horizontal' ? 'width' : 'height'; |
| 755 | |
| 756 | let skipped = 0; |
| 757 | let children: LayoutNode[] = []; |
| 758 | for (let child of getChildNodes(node, collection)) { |
| 759 | // 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 |
| 760 | if (child.type === 'content') { |
| 761 | continue; |
| 762 | } |
| 763 | |
| 764 | let rowHeight = (this.rowSize ?? this.estimatedRowSize ?? DEFAULT_HEIGHT) + this.gap; |
| 765 | |
| 766 | // Skip rows before the valid rectangle unless they are already cached. |
| 767 | if (offset + rowHeight < this.requestedRect[offsetProperty] && !this.isValid(node, offset)) { |
| 768 | offset += rowHeight; |
| 769 | skipped++; |
| 770 | continue; |
| 771 | } |
| 772 | |
| 773 | let layoutNode = |
| 774 | this.orientation === 'horizontal' |
| 775 | ? this.buildChild(child, offset, y, layoutInfo.key) |
| 776 | : this.buildChild(child, x, offset, layoutInfo.key); |
| 777 | offset = layoutNode.layoutInfo.rect[maxOffsetProperty] + this.gap; |
| 778 | children.push(layoutNode); |
| 779 | |
| 780 | if (offset > this.requestedRect[maxOffsetProperty]) { |
| 781 | // Estimate the remaining height for rows that we don't need to layout right now. |
| 782 | offset += |
| 783 | ([...getChildNodes(node, collection)].length - (children.length + skipped)) * rowHeight; |
| 784 | break; |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | offset -= this.gap; |
| 789 | rect[heightProperty] = offset - (this.orientation === 'horizontal' ? x : y); |
| 790 | |
| 791 | return { |
| 792 | layoutInfo, |
| 793 | children, |
| 794 | validRect: layoutInfo.rect.intersection(this.requestedRect), |
no test coverage detected