Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: sky/examples/style/block-layout.sky

Issue 980323003: Clean up examples directory (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/examples/shell/sensor.sky ('k') | sky/examples/style/hex-layout.sky » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 || child.descendantNeedsLayout) {
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 this.markAsLaidOut();
34 return {
35 width: width,
36 height: height,
37 }
38 }
39 function layoutDescendants() {
40 this.layout(node.width, node.height);
41 }
42 function getIntrinsicWidth() {
43 let width = this.node.getProperty('width');
44 if (typeof width != 'number') {
45 // e.g. width: auto
46 width = 0;
47 let children = this.walkChildren();
48 let loop = children.next();
49 while (!loop.done) {
50 let child = loop.value;
51 let childWidth = child.layoutManager.getIntrinsicWidth();
52 if (width < childWidth.value)
53 width = childWidth.value;
54 loop = children.next();
55 }
56 }
57 return super(width); // applies and provides our own min-width/max-width ru les
58 }
59 function getIntrinsicHeight() {
60 let height = this.node.getProperty('height');
61 if (typeof height != 'number') {
62 // e.g. height: auto
63 height = 0;
64 let children = this.walkChildren();
65 let loop = children.next();
66 while (!loop.done) {
67 let child = loop.value;
68 let childHeight = child.layoutManager.getIntrinsicHeight();
69 if (height < childHeight.value)
70 height = childHeight.value;
71 loop = children.next();
72 }
73 }
74 return super(height); // applies and provides our own min-height/max-height rules
75 }
76 }
77 sky.registerLayoutManager('block', module.exports.BlockLayoutManager);
78 </script>
OLDNEW
« no previous file with comments | « sky/examples/shell/sensor.sky ('k') | sky/examples/style/hex-layout.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698