OLD | NEW |
1 SKY MODULE | 1 SKY MODULE |
2 <import src="sky:core" as="sky"/> | 2 <import src="sky:core" as="sky"/> |
3 <!-- | 3 <!-- |
4 ! this module provides trivial vertical block layout | 4 ! this module provides trivial vertical block layout |
5 ! no margins, padding, borders, etc | 5 ! no margins, padding, borders, etc |
6 !--> | 6 !--> |
7 <script> | 7 <script> |
8 module.exports.BlockLayoutManager = class BlockLayoutManager extends sky.Layout
Manager { | 8 module.exports.BlockLayoutManager = class BlockLayoutManager extends sky.Layout
Manager { |
9 function layout(width, height) { | 9 function layout(width, height) { |
10 this.markAsLaidOut(); | 10 this.markAsLaidOut(); |
11 if (width == null) | 11 if (width == null) |
12 width = this.getIntrinsicWidth().value; | 12 width = this.getIntrinsicWidth().value; |
13 let autoHeight = false; | 13 let autoHeight = false; |
14 if (height == null) { | 14 if (height == null) { |
15 height = 0; | 15 height = 0; |
16 autoHeight = true; | 16 autoHeight = true; |
17 } | 17 } |
18 this.assumeDimensions(width, height); | 18 this.assumeDimensions(width, height); |
19 let children = this.walkChildren(); | 19 let children = this.walkChildren(); |
20 let loop = children.next(); | 20 let loop = children.next(); |
21 let y = 0; | 21 let y = 0; |
22 while (!loop.done) { | 22 while (!loop.done) { |
23 let child = loop.value; | 23 let child = loop.value; |
24 if (child.needsLayout) { | 24 if (child.needsLayout || child.descendantNeedsLayout) { |
25 let dims = child.layoutManager.layout(width, null); | 25 let dims = child.layoutManager.layout(width, null); |
26 this.setChildSize(child, dims.width, dims.height); | 26 this.setChildSize(child, dims.width, dims.height); |
27 } | 27 } |
28 this.setChildPosition(child, 0, y); | 28 this.setChildPosition(child, 0, y); |
29 y += child.height; | 29 y += child.height; |
30 loop = children.next(); | 30 loop = children.next(); |
31 } | 31 } |
32 if (autoHeight) | 32 if (autoHeight) |
33 height = y; | 33 height = y; |
34 return { | 34 return { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 if (height < childHeight.value) | 66 if (height < childHeight.value) |
67 height = childHeight.value; | 67 height = childHeight.value; |
68 loop = children.next(); | 68 loop = children.next(); |
69 } | 69 } |
70 } | 70 } |
71 return super(height); // applies and provides our own min-height/max-height
rules | 71 return super(height); // applies and provides our own min-height/max-height
rules |
72 } | 72 } |
73 } | 73 } |
74 sky.registerLayoutManager('block', module.exports.BlockLayoutManager); | 74 sky.registerLayoutManager('block', module.exports.BlockLayoutManager); |
75 </script> | 75 </script> |
OLD | NEW |