diff --git a/examples/style/block-layout.sky b/examples/style/block-layout.sky index b303db047e..0cfac2bb07 100644 --- a/examples/style/block-layout.sky +++ b/examples/style/block-layout.sky @@ -37,7 +37,7 @@ SKY MODULE } function getIntrinsicWidth() { let width = this.node.getProperty('width'); - if (typeof height != 'number') { + if (typeof width != 'number') { // e.g. width: auto width = 0; let children = this.walkChildren(); diff --git a/examples/style/hex-layout.sky b/examples/style/hex-layout.sky index ca286f0401..ac2acaf35e 100644 --- a/examples/style/hex-layout.sky +++ b/examples/style/hex-layout.sky @@ -112,18 +112,48 @@ loop = children.next(); } } + function inHex(topLeftX, topLeftY, width, height, hitX, hitY) { + let centerX = topLeftX - width/2; + let absCenteredHitX = Math.abs(hitX - centerX); + if (absCenteredHitX > width/2) + return false; + let centerY = topLeftY - height/2; + let absCenteredHitY = Math.abs(hitY - centerY); + if (absCenteredHitY > height/2) + return false; + if (absCenteredHitY < height * absCenteredHitX / (2 * width) + height / 2) + return true; + return false; + } + function hitTest(x, y) { + let cellCount = this.node.getProperty('beehive-count'); + let cellDim = width / cellCount; + let children = this.walkChildren(); + let loop = children.next(); + while (!loop.done) { + let child = loop.value; + if (this.inHex(child.x, child.y, child.width, child.height, x, y)) + return child.layoutManager.hitText(x, y); + loop = children.next(); + } + return this.node; + } } sky.registerLayoutManager('beehive', BeehiveLayoutManager); let BeehiveCountStyleValueType = new StyleValueType(); BeehiveCountStyleValueType.addParser((tokens) => { let token = tokens.next(); - if (token.done) throw new Error(); - if (token.value.kind != 'number') throw new Error(); - if (token.value.value <= 0) throw new Error(); - if (Math.trunc(token.value.value) != token.value.value) throw new Error(); - let result = token.value.value; - if (!token.next().done) throw new Error(); - return result; + if (token.done) + throw new Error(); + if (token.value.kind != 'number') + throw new Error(); + if (token.value.value <= 0) + throw new Error(); + if (Math.trunc(token.value.value) != token.value.value) // is integer + throw new Error(); + return { + value: token.value.value; + } }); sky.registerProperty({ name: 'beehive-count', diff --git a/examples/style/toolbar-layout.sky b/examples/style/toolbar-layout.sky index a43ce3fc5d..b0f59644bb 100644 --- a/examples/style/toolbar-layout.sky +++ b/examples/style/toolbar-layout.sky @@ -10,9 +10,9 @@ SKY MODULE sky.registerLayoutManager('spring', module.exports.SpringLayoutManager); sky.registerProperty({ name: 'toolbar-spacing', - type: sky.LengthStyleValueType, + type: sky.PositiveLengthStyleValueType, inherits: true, - initialValue: { value: 8, unit: 'px' }, + initialValue: 8, needsLayout: true, }); module.exports.ToolbarLayoutManager = class ToolbarLayoutManager extends sky.LayoutManager { @@ -131,7 +131,7 @@ SKY MODULE } function getIntrinsicWidth() { let width = this.node.getProperty('width'); - if (typeof height != 'number') { + if (typeof width != 'number') { let spacing = this.node.getProperty('toolbar-spacing'); if (typeof spacing != 'number') spacing = 0;