OLD | NEW |
(Empty) | |
| 1 SKY MODULE |
| 2 <import src="sky:core" as="sky"/> |
| 3 <!-- |
| 4 ! this module provides trivial vertical block layout |
| 5 ! no margins, padding, borders, etc |
| 6 !--> |
| 7 <script> |
| 8 module.exports.BlockLayoutManager = class BlockLayoutManager extends sky.Layout
Manager { |
| 9 function layout(width, height) { |
| 10 if (width == null) |
| 11 width = this.getIntrinsicWidth().value; |
| 12 let autoHeight = false; |
| 13 if (height == null) { |
| 14 height = 0; |
| 15 autoHeight = true; |
| 16 } |
| 17 this.assumeDimensions(width, height); |
| 18 let children = this.walkChildren(); |
| 19 let loop = children.next(); |
| 20 let y = 0; |
| 21 while (!loop.done) { |
| 22 let child = loop.value; |
| 23 if (child.needsLayout) { |
| 24 let dims = child.layoutManager.layout(width, null); |
| 25 this.setChildSize(child, dims.width, dims.height); |
| 26 } |
| 27 this.setChildPosition(child, 0, y); |
| 28 y += child.height; |
| 29 loop = children.next(); |
| 30 } |
| 31 if (autoHeight) |
| 32 height = y; |
| 33 return { |
| 34 width: width, |
| 35 height: height, |
| 36 } |
| 37 } |
| 38 function getIntrinsicWidth() { |
| 39 let width = this.node.getProperty('width'); |
| 40 if (typeof height != 'number') { |
| 41 // e.g. width: auto |
| 42 width = 0; |
| 43 let children = this.walkChildren(); |
| 44 let loop = children.next(); |
| 45 while (!loop.done) { |
| 46 let child = loop.value; |
| 47 let childWidth = child.layoutManager.getIntrinsicWidth(); |
| 48 if (width < childWidth.value) |
| 49 width = childWidth.value; |
| 50 loop = children.next(); |
| 51 } |
| 52 } |
| 53 return super(width); // applies and provides our own min-width/max-width ru
les |
| 54 } |
| 55 function getIntrinsicHeight() { |
| 56 let height = this.node.getProperty('height'); |
| 57 if (typeof height != 'number') { |
| 58 // e.g. height: auto |
| 59 height = 0; |
| 60 let children = this.walkChildren(); |
| 61 let loop = children.next(); |
| 62 while (!loop.done) { |
| 63 let child = loop.value; |
| 64 let childHeight = child.layoutManager.getIntrinsicHeight(); |
| 65 if (height < childHeight.value) |
| 66 height = childHeight.value; |
| 67 loop = children.next(); |
| 68 } |
| 69 } |
| 70 return super(height); // applies and provides our own min-width/max-width r
ules |
| 71 } |
| 72 } |
| 73 sky.registerLayoutManager('block', module.exports.BlockLayoutManager); |
| 74 </script> |
OLD | NEW |