Commit edcbad76 authored by Hixie's avatar Hixie

Specs: update the layout and paint schemes to match discussions better

Review URL: https://codereview.chromium.org/745863002
parent 85817b24
These are work-in-progress examples of how the language might look. Some of these examples are examples of what sky supports now.
They won't currently work. Others are examples of what sky hopes to one day support.
Therefore not all these examples actually work today.
...@@ -21,7 +21,7 @@ SKY MODULE ...@@ -21,7 +21,7 @@ SKY MODULE
let y = 0; let y = 0;
while (!loop.done) { while (!loop.done) {
let child = loop.value; let child = loop.value;
if (child.needsLayout) { if (child.needsLayout || child.descendantNeedsLayout) {
let dims = child.layoutManager.layout(width, null); let dims = child.layoutManager.layout(width, null);
this.setChildSize(child, dims.width, dims.height); this.setChildSize(child, dims.width, dims.height);
} }
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
let y = 0; let y = 0;
while (!loop.done) { while (!loop.done) {
let child = loop.value; let child = loop.value;
if (child.needsLayout) { if (child.needsLayout || child.descendantNeedsLayout) {
child.layoutManager.layout(cellDim, cellDim); child.layoutManager.layout(cellDim, cellDim);
// we ignore the size the child reported from layout(), and force it to the cell dimensions // we ignore the size the child reported from layout(), and force it to the cell dimensions
this.setChildSize(child, cellDim, cellDim); this.setChildSize(child, cellDim, cellDim);
...@@ -40,30 +40,6 @@ ...@@ -40,30 +40,6 @@
height: height, height: height,
} }
} }
function getIntrinsicWidth() {
// this is the logic that LayoutManager.getIntrinsicWidth() has by default
// shown here because I wrote it before realising it should be the default
let width = this.node.getProperty('width');
if (typeof width != 'number')
width = 0;
let minWidth = this.node.getProperty('min-width');
if (typeof width != 'number')
minWidth = 0;
let maxWidth = this.node.getProperty('max-width');
if (typeof width != 'number')
maxWidth = Infinity;
if (maxWidth < minWidth)
maxWidth = minWidth;
if (width > maxWidth)
width = maxWidth;
if (width < minWidth)
width = minWidth;
return {
minimum: minWidth,
value: width,
maximum: maxWidth,
};
}
function getIntrinsicHeight() { function getIntrinsicHeight() {
let height = this.node.getProperty('height'); let height = this.node.getProperty('height');
if (typeof height != 'number') { if (typeof height != 'number') {
...@@ -93,20 +69,19 @@ ...@@ -93,20 +69,19 @@
let loop = children.next(); let loop = children.next();
while (!loop.done) { while (!loop.done) {
let child = loop.value; let child = loop.value;
if (child.needsPaint) { if (child.needsPaint || child.descendantNeedsPaint) {
canvas.save(); canvas.save();
try { try {
canvas.beginPath(); canvas.beginPath();
canvas.translate(child.x, child.y); canvas.moveTo(child.x, child.y + cellDim/4);
canvas.moveTo(0, cellDim/4); canvas.lineTo(child.x + cellDim/2, child.y);
canvas.lineTo(cellDim/2, 0); canvas.lineTo(child.x + cellDim, child.y + cellDim/4);
canvas.lineTo(cellDim, cellDim/4); canvas.lineTo(child.x + cellDim, child.y + 3*cellDim/4);
canvas.lineTo(cellDim, 3*cellDim/4); canvas.lineTo(child.x + cellDim/2, child.y + cellDim);
canvas.lineTo(cellDim/2, cellDim); canvas.moveTo(child.x, child.y + 3*cellDim/4);
canvas.moveTo(0, 3*cellDim/4);
canvas.closePath(); canvas.closePath();
canvas.clip(); canvas.clip();
child.paint(canvas); this.paintChild(child);
} finally { } finally {
canvas.restore(); canvas.restore();
} }
......
...@@ -52,7 +52,7 @@ SKY MODULE ...@@ -52,7 +52,7 @@ SKY MODULE
springCount += 1; springCount += 1;
pendingSpacing = spacing; // not +=, because we only have one extra spacing per batch of springs pendingSpacing = spacing; // not +=, because we only have one extra spacing per batch of springs
} else { } else {
if (child.needsLayout) { if (child.needsLayout || child.descendantNeedsLayout) {
childHeight = child.layoutManager.getIntrinsicHeight(); childHeight = child.layoutManager.getIntrinsicHeight();
if (childHeight.value < height) if (childHeight.value < height)
childHeight = childHeight.value; childHeight = childHeight.value;
...@@ -185,25 +185,25 @@ SKY MODULE ...@@ -185,25 +185,25 @@ SKY MODULE
} }
function paintChildren(canvas) { function paintChildren(canvas) {
let width = this.node.width; let width = this.node.width;
let children = this.walkChildren();
let loop = children.next(); let loop = children.next();
while ((!loop.done) && (loop.value != this.firstSkippedChild)) while ((!loop.done) && (loop.value != this.firstSkippedChild))
this.paintChild(loop.value, canvas); this.paintChild(loop.value, canvas);
if (this.showingOverflow) if (this.showingOverflow)
this.paintChild(this.overflowChild, canvas); this.paintChild(this.overflowChild, canvas);
} }
function paintChild(child, canvas) { function inChild(child, x, y) {
if (child.needsPaint) { return (x >= child.x) && (y >= child.y) && (x < child.x+child.width) && (y < child.y+child.height);
canvas.save(); }
try { function hitTest(x, y) {
canvas.beginPath(); let children = this.walkChildrenBackwards();
canvas.translate(child.x, child.y); let loop = children.next();
canvas.rect(0, 0, child.width, child.height); while ((!loop.done) && (loop.value != this.firstSkippedChild))
canvas.clip(); if (this.inChild(loop.value, x, y))
child.paint(canvas); return loop.value;
} finally { if (this.showingOverflow)
canvas.restore(); if (this.inChild(this.overflowChild, x, y))
} return this.overflowChild;
}
} }
} }
sky.registerLayoutManager('toolbar', module.exports.ToolbarLayoutManager); sky.registerLayoutManager('toolbar', module.exports.ToolbarLayoutManager);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment