OLD | NEW |
1 SKY MODULE | 1 SKY MODULE |
2 <import src="sky:core" as="sky"/> | 2 <import src="sky:core" as="sky"/> |
3 <script> | 3 <script> |
4 // display: toolbar; | 4 // display: toolbar; |
5 // toolbar-spacing: <length> | 5 // toolbar-spacing: <length> |
6 // display: spring; // remaining space is split equally amongst the springs | 6 // display: spring; // remaining space is split equally amongst the springs |
7 // children are vertically centered, layout out left-to-right with toolbar-spac
ing space between them | 7 // children are vertically centered, layout out left-to-right with toolbar-spac
ing space between them |
8 // last child is hidden by default unless there's not enough room for the other
s, then it's shown last, right-aligned | 8 // last child is hidden by default unless there's not enough room for the other
s, then it's shown last, right-aligned |
9 module.exports.SpringLayoutManager = class SpringLayoutManager extends sky.Layo
utManager { } | 9 module.exports.SpringLayoutManager = class SpringLayoutManager extends sky.Layo
utManager { } |
10 sky.registerLayoutManager('spring', module.exports.SpringLayoutManager); | 10 sky.registerLayoutManager('spring', module.exports.SpringLayoutManager); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 let pendingSpacing = 0; | 45 let pendingSpacing = 0; |
46 children = this.walkChildren(); | 46 children = this.walkChildren(); |
47 loop = children.next(); | 47 loop = children.next(); |
48 while (!loop.done) { | 48 while (!loop.done) { |
49 let child = loop.value; | 49 let child = loop.value; |
50 let dims = null; | 50 let dims = null; |
51 if (child.layoutManager instanceof module.exports.SpringLayoutManager) { | 51 if (child.layoutManager instanceof module.exports.SpringLayoutManager) { |
52 springCount += 1; | 52 springCount += 1; |
53 pendingSpacing = spacing; // not +=, because we only have one extra spa
cing per batch of springs | 53 pendingSpacing = spacing; // not +=, because we only have one extra spa
cing per batch of springs |
54 } else { | 54 } else { |
55 if (child.needsLayout) { | 55 if (child.needsLayout || child.descendantNeedsLayout) { |
56 childHeight = child.layoutManager.getIntrinsicHeight(); | 56 childHeight = child.layoutManager.getIntrinsicHeight(); |
57 if (childHeight.value < height) | 57 if (childHeight.value < height) |
58 childHeight = childHeight.value; | 58 childHeight = childHeight.value; |
59 else | 59 else |
60 childHeight = height; | 60 childHeight = height; |
61 dims = child.layoutManager.layout(width, height); | 61 dims = child.layoutManager.layout(width, height); |
62 this.setChildSize(child, dims.width, dims.height); | 62 this.setChildSize(child, dims.width, dims.height); |
63 } else { | 63 } else { |
64 dims = { | 64 dims = { |
65 width: child.width, | 65 width: child.width, |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 if (result.minimum > result.maximum) | 178 if (result.minimum > result.maximum) |
179 result.maximum = result.minimum; | 179 result.maximum = result.minimum; |
180 if (result.value > result.maximum) | 180 if (result.value > result.maximum) |
181 result.value = result.maximum; | 181 result.value = result.maximum; |
182 if (result.value < result.minimum) | 182 if (result.value < result.minimum) |
183 result.value = result.minimum; | 183 result.value = result.minimum; |
184 return result; | 184 return result; |
185 } | 185 } |
186 function paintChildren(canvas) { | 186 function paintChildren(canvas) { |
187 let width = this.node.width; | 187 let width = this.node.width; |
| 188 let children = this.walkChildren(); |
188 let loop = children.next(); | 189 let loop = children.next(); |
189 while ((!loop.done) && (loop.value != this.firstSkippedChild)) | 190 while ((!loop.done) && (loop.value != this.firstSkippedChild)) |
190 this.paintChild(loop.value, canvas); | 191 this.paintChild(loop.value, canvas); |
191 if (this.showingOverflow) | 192 if (this.showingOverflow) |
192 this.paintChild(this.overflowChild, canvas); | 193 this.paintChild(this.overflowChild, canvas); |
193 } | 194 } |
194 function paintChild(child, canvas) { | 195 function inChild(child, x, y) { |
195 if (child.needsPaint) { | 196 return (x >= child.x) && (y >= child.y) && (x < child.x+child.width) && (y
< child.y+child.height); |
196 canvas.save(); | 197 } |
197 try { | 198 function hitTest(x, y) { |
198 canvas.beginPath(); | 199 let children = this.walkChildrenBackwards(); |
199 canvas.translate(child.x, child.y); | 200 let loop = children.next(); |
200 canvas.rect(0, 0, child.width, child.height); | 201 while ((!loop.done) && (loop.value != this.firstSkippedChild)) |
201 canvas.clip(); | 202 if (this.inChild(loop.value, x, y)) |
202 child.paint(canvas); | 203 return loop.value; |
203 } finally { | 204 if (this.showingOverflow) |
204 canvas.restore(); | 205 if (this.inChild(this.overflowChild, x, y)) |
205 } | 206 return this.overflowChild; |
206 } | |
207 } | 207 } |
208 } | 208 } |
209 sky.registerLayoutManager('toolbar', module.exports.ToolbarLayoutManager); | 209 sky.registerLayoutManager('toolbar', module.exports.ToolbarLayoutManager); |
210 </script> | 210 </script> |
OLD | NEW |