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

Unified Diff: sky/examples/style/block-layout.sky

Issue 716013002: Specs: Initial hack at extensible style/layout (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sky/examples/style/hex-layout.sky » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/examples/style/block-layout.sky
diff --git a/sky/examples/style/block-layout.sky b/sky/examples/style/block-layout.sky
new file mode 100644
index 0000000000000000000000000000000000000000..b303db047e51ffe798fbe606c20dcb7135d2baf3
--- /dev/null
+++ b/sky/examples/style/block-layout.sky
@@ -0,0 +1,74 @@
+SKY MODULE
+<import src="sky:core" as="sky"/>
+<!--
+ ! this module provides trivial vertical block layout
+ ! no margins, padding, borders, etc
+ !-->
+<script>
+ module.exports.BlockLayoutManager = class BlockLayoutManager extends sky.LayoutManager {
+ function layout(width, height) {
+ if (width == null)
+ width = this.getIntrinsicWidth().value;
+ let autoHeight = false;
+ if (height == null) {
+ height = 0;
+ autoHeight = true;
+ }
+ this.assumeDimensions(width, height);
+ let children = this.walkChildren();
+ let loop = children.next();
+ let y = 0;
+ while (!loop.done) {
+ let child = loop.value;
+ if (child.needsLayout) {
+ let dims = child.layoutManager.layout(width, null);
+ this.setChildSize(child, dims.width, dims.height);
+ }
+ this.setChildPosition(child, 0, y);
+ y += child.height;
+ loop = children.next();
+ }
+ if (autoHeight)
+ height = y;
+ return {
+ width: width,
+ height: height,
+ }
+ }
+ function getIntrinsicWidth() {
+ let width = this.node.getProperty('width');
+ if (typeof height != 'number') {
+ // e.g. width: auto
+ width = 0;
+ let children = this.walkChildren();
+ let loop = children.next();
+ while (!loop.done) {
+ let child = loop.value;
+ let childWidth = child.layoutManager.getIntrinsicWidth();
+ if (width < childWidth.value)
+ width = childWidth.value;
+ loop = children.next();
+ }
+ }
+ return super(width); // applies and provides our own min-width/max-width rules
+ }
+ function getIntrinsicHeight() {
+ let height = this.node.getProperty('height');
+ if (typeof height != 'number') {
+ // e.g. height: auto
+ height = 0;
+ let children = this.walkChildren();
+ let loop = children.next();
+ while (!loop.done) {
+ let child = loop.value;
+ let childHeight = child.layoutManager.getIntrinsicHeight();
+ if (height < childHeight.value)
+ height = childHeight.value;
+ loop = children.next();
+ }
+ }
+ return super(height); // applies and provides our own min-width/max-width rules
+ }
+ }
+ sky.registerLayoutManager('block', module.exports.BlockLayoutManager);
+</script>
« no previous file with comments | « no previous file | sky/examples/style/hex-layout.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698