Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
3d06e2a4
Commit
3d06e2a4
authored
Nov 14, 2014
by
Hixie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Specs: hit testing (and some cleanup)
Review URL:
https://codereview.chromium.org/727993002
parent
f8340b77
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
11 deletions
+41
-11
block-layout.sky
examples/style/block-layout.sky
+1
-1
hex-layout.sky
examples/style/hex-layout.sky
+37
-7
toolbar-layout.sky
examples/style/toolbar-layout.sky
+3
-3
No files found.
examples/style/block-layout.sky
View file @
3d06e2a4
...
@@ -37,7 +37,7 @@ SKY MODULE
...
@@ -37,7 +37,7 @@ SKY MODULE
}
}
function getIntrinsicWidth() {
function getIntrinsicWidth() {
let width = this.node.getProperty('width');
let width = this.node.getProperty('width');
if (typeof
height
!= 'number') {
if (typeof
width
!= 'number') {
// e.g. width: auto
// e.g. width: auto
width = 0;
width = 0;
let children = this.walkChildren();
let children = this.walkChildren();
...
...
examples/style/hex-layout.sky
View file @
3d06e2a4
...
@@ -112,18 +112,48 @@
...
@@ -112,18 +112,48 @@
loop = children.next();
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);
sky.registerLayoutManager('beehive', BeehiveLayoutManager);
let BeehiveCountStyleValueType = new StyleValueType();
let BeehiveCountStyleValueType = new StyleValueType();
BeehiveCountStyleValueType.addParser((tokens) => {
BeehiveCountStyleValueType.addParser((tokens) => {
let token = tokens.next();
let token = tokens.next();
if (token.done) throw new Error();
if (token.done)
if (token.value.kind != 'number') throw new Error();
throw new Error();
if (token.value.value <= 0) throw new Error();
if (token.value.kind != 'number')
if (Math.trunc(token.value.value) != token.value.value) throw new Error();
throw new Error();
let result = token.value.value;
if (token.value.value <= 0)
if (!token.next().done) throw new Error();
throw new Error();
return result;
if (Math.trunc(token.value.value) != token.value.value) // is integer
throw new Error();
return {
value: token.value.value;
}
});
});
sky.registerProperty({
sky.registerProperty({
name: 'beehive-count',
name: 'beehive-count',
...
...
examples/style/toolbar-layout.sky
View file @
3d06e2a4
...
@@ -10,9 +10,9 @@ SKY MODULE
...
@@ -10,9 +10,9 @@ SKY MODULE
sky.registerLayoutManager('spring', module.exports.SpringLayoutManager);
sky.registerLayoutManager('spring', module.exports.SpringLayoutManager);
sky.registerProperty({
sky.registerProperty({
name: 'toolbar-spacing',
name: 'toolbar-spacing',
type: sky.LengthStyleValueType,
type: sky.
Positive
LengthStyleValueType,
inherits: true,
inherits: true,
initialValue:
{ value: 8, unit: 'px' }
,
initialValue:
8
,
needsLayout: true,
needsLayout: true,
});
});
module.exports.ToolbarLayoutManager = class ToolbarLayoutManager extends sky.LayoutManager {
module.exports.ToolbarLayoutManager = class ToolbarLayoutManager extends sky.LayoutManager {
...
@@ -131,7 +131,7 @@ SKY MODULE
...
@@ -131,7 +131,7 @@ SKY MODULE
}
}
function getIntrinsicWidth() {
function getIntrinsicWidth() {
let width = this.node.getProperty('width');
let width = this.node.getProperty('width');
if (typeof
height
!= 'number') {
if (typeof
width
!= 'number') {
let spacing = this.node.getProperty('toolbar-spacing');
let spacing = this.node.getProperty('toolbar-spacing');
if (typeof spacing != 'number')
if (typeof spacing != 'number')
spacing = 0;
spacing = 0;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment