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

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

Issue 727993002: Specs: hit testing (and some cleanup) (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 | « sky/examples/style/block-layout.sky ('k') | sky/examples/style/toolbar-layout.sky » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/examples/style/hex-layout.sky
diff --git a/sky/examples/style/hex-layout.sky b/sky/examples/style/hex-layout.sky
index ca286f0401a2c604ea34221c8a48b6502e7f7784..ac2acaf35ed0d44d6717d224cc72ff2385b48edc 100644
--- a/sky/examples/style/hex-layout.sky
+++ b/sky/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',
« no previous file with comments | « sky/examples/style/block-layout.sky ('k') | sky/examples/style/toolbar-layout.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698