mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Specs: hit testing (and some cleanup)
Review URL: https://codereview.chromium.org/727993002
This commit is contained in:
parent
f8340b77ef
commit
3d06e2a4e7
@ -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();
|
||||||
|
@ -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',
|
||||||
|
@ -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.PositiveLengthStyleValueType,
|
||||||
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
|
|||||||
}
|
}
|
||||||
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;
|
||||||
|
Loading…
Reference in New Issue
Block a user