Skip to content

Commit

Permalink
Move to getters for .value and .hashCode.
Browse files Browse the repository at this point in the history
  • Loading branch information
slightlyoff committed Oct 20, 2012
1 parent 32d0ea3 commit de663bb
Show file tree
Hide file tree
Showing 16 changed files with 624 additions and 582 deletions.
171 changes: 101 additions & 70 deletions demos/css/layout.js

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions demos/css/renderer.js
Expand Up @@ -119,6 +119,7 @@ var fillBoxMargin = function(box, ctx) {
var paintBorder = function(box, ctx) {
if (!box.node) return;
var b = box.edges.actual.border;
// var b = box.edges.actual.content;
// Gecko doesn't like giving us "border-width", "border-color",
// "border-style", etc., so we default to some edge to grab them from.
if (box.css("border-top-style").raw != "none") {
Expand All @@ -128,10 +129,12 @@ var paintBorder = function(box, ctx) {
var brw = box.css("border-right-width").px;
var right = b.right - brw / 2;
var bbw = box.css("border-bottom-width").px;
var bottom = b.bottom - bbw / 2;
var bottom = b.bottom + bbw; // / 2;
var blw = box.css("border-left-width").px;
var left = b.left + blw / 2;
console.log("top:", top, "right:", right, "bottom:", bottom, "left:", left);

// console.log("top:", top, "right:", right, "bottom:", bottom, "left:", left, "height:", b.height, "width:", b.width);

pathWithStyle(
ctx,
[
Expand Down Expand Up @@ -168,7 +171,7 @@ var _renderTo = function(boxes, ctx) {
}
if (box.text) {
paintText(box, ctx);
// paintOutline(box, ctx);
paintOutline(box, ctx);
} else if (box.node) {
paintBackground(box, ctx);
paintBorder(box, ctx);
Expand Down
48 changes: 24 additions & 24 deletions demos/panels/panels.js
Expand Up @@ -121,7 +121,7 @@ var valueSetter = function(item, varOrValue, oper, strength, weight) {

var valueGetter = function(item) {
if(!this["_" + item]) return; // undefined
return this.v[item].value();
return this.v[item].value;
};

var weak = c.Strength.weak;
Expand All @@ -136,7 +136,7 @@ var neq = function(a1, a2, a3) { return new c.Inequality(a1, a2, a3); };
var geq = function(a1, a2, str, w) { return new c.Inequality(a1, c.GEQ, a2, str, w); };
var leq = function(a1, a2, str, w) { return new c.Inequality(a1, c.LEQ, a2, str, w); };

var stay = function(v, strength, weight) {
var stay = function(v, strength, weight) {
return new c.StayConstraint(v, strength || weak, weight || 1.0);
};
var weakStay = function(v, w) { return stay(v, weak, w); };
Expand Down Expand Up @@ -255,8 +255,8 @@ scope.Panel = c.inherit({
var start = this._moveStartLocation;
start.x = e.pageX;
start.y = e.pageY;
start.left = this.v.left.value();
start.top = this.v.top.value();
start.left = this.v.left.value;
start.top = this.v.top.value;
s.addEditVar(this.v.left, strong)
.addEditVar(this.v.top, strong).beginEdit();
this._moving = true;
Expand All @@ -265,8 +265,8 @@ scope.Panel = c.inherit({

_mouseUp: function(e) {
if (this._moving) {
var l = this.v.left.value();
var t = this.v.top.value();
var l = this.v.left.value;
var t = this.v.top.value;
s.endEdit();
// Re-set the current value at the default strength (weak) instead of our
// (strong) edit-time updates to it.
Expand Down Expand Up @@ -296,7 +296,7 @@ scope.Panel = c.inherit({
"left",
"top" // , "right", "bottom"
].forEach(function(name) {
var v = this.v[name].value() + "px";
var v = this.v[name].value + "px";
this._debugShadow.style[name] = v;
s += name + ": " + v + " <br>";
}, this);
Expand All @@ -306,8 +306,8 @@ scope.Panel = c.inherit({
"preferredWidth",
"preferredHeight"
].forEach(function(name) {
var v = this.v[name].value() + "px";
s += name + ": " + this.v[name].value() + "px <br>";
var v = this.v[name].value + "px";
s += name + ": " + this.v[name].value + "px <br>";
}, this);

this._debugShadow.innerHTML = s;
Expand Down Expand Up @@ -368,7 +368,7 @@ scope.Panel = c.inherit({
}
});

// We add our constraints to the solver ONLY when we're
// We add our constraints to the solver ONLY when we're
s.autoSolve = false;
this.constraints.forEach(function(cns) { s.addConstraint(cns); });
s.resolve();
Expand Down Expand Up @@ -530,17 +530,17 @@ scope.Panel = c.inherit({
_updateStyles: function() {
// NOTE: "bottom" and "right" are assumed to be computed
[ "width", "height" ].forEach(function(name) {
this.style[name] = this.v[name].value() + "px";
this.style[name] = this.v[name].value + "px";
}, this);

// FIXME: caching? invalidation?
[ "left", "top" ].forEach(function(name) {
var v = this.v[name].value();
var v = this.v[name].value;
// If we're not direct children of the root, translate top/left to being
// in the CSS "absolute" coordinate space from our absolutely positioned
// parents
if (this.parentNode && this.parentNode != document.body) {
v = v - this.parentNode.v[name].value();
v = v - this.parentNode.v[name].value;
}
this.style[name] = v + "px";
}, this);
Expand Down Expand Up @@ -610,7 +610,7 @@ scope.Panel = c.inherit({
set left(v) { valueSetter.call(this, "left", v, "=", strong); },
set right(v) { valueSetter.call(this, "right", v, "=", strong); },

get top() { return valueGetter.call(this, "top"); },
get top() { return valueGetter.call(this, "top"); },
get bottom() { return valueGetter.call(this, "bottom"); },
get left() { return valueGetter.call(this, "left"); },
get right() { return valueGetter.call(this, "right"); },
Expand Down Expand Up @@ -641,7 +641,7 @@ scope.Panel = c.inherit({

set box(b) {
this._valueConstraintNames.forEach(function(prop) {
if (b.hasOwnProperty(prop)) { this[prop] = b[prop]; } }, this);
if (b.hasOwnProperty(prop)) { this[prop] = b[prop]; } }, this);

this._listConstraintNames.forEach(function(prop) {
if (b.hasOwnProperty(prop)) { this[prop] = b[prop]; } }, this);
Expand All @@ -652,7 +652,7 @@ scope.Panel = c.inherit({
this._centeredIn = [
// this.left = other.left + (other.width/2 - this.width/2)
eq(this.v.left,
c.Plus(other.v.left,
c.Plus(other.v.left,
c.Minus(
c.Divide(other.v.width, 2),
c.Divide(this.v.width, 2)
Expand All @@ -661,7 +661,7 @@ scope.Panel = c.inherit({

// this.top = other.top + (other.height/2 - this.height/2)
eq(this.v.top,
c.Plus(other.v.top,
c.Plus(other.v.top,
c.Minus(
c.Divide(other.v.height, 2),
c.Divide(this.v.height, 2)
Expand Down Expand Up @@ -693,7 +693,7 @@ HTMLElement.register(Panel);
scope.RootPanel = c.inherit({
extends: Panel,
initialize: function() {
if (document.rootPanel) {
if (document.rootPanel) {
throw "Attempting to create multiple roots on the same document!";
}

Expand Down Expand Up @@ -725,7 +725,7 @@ scope.RootPanel = c.inherit({

// Propigate viewport size changes.
var reCalc = function() {

// Measurement should be cheap here.
var iwv = window.innerWidth;
var ihv = window.innerHeight;
Expand All @@ -742,12 +742,12 @@ scope.RootPanel = c.inherit({

// console.timeEnd("resolve");

if (iwv != this.v.width.value()) {
if (iwv != this.v.width.value) {
// ZOMGWTFBBQ?
console.log("width: suggested:", iwv, "got:", this.v.width.value());
console.log("height: suggested:", ihv, "got:", this.v.height.value());
console.log("right: suggested:", iwv, "got:", this.v.right.value());
console.log("bottom: suggested:", ihv, "got:", this.v.bottom.value());
console.log("width: suggested:", iwv, "got:", this.v.width.value);
console.log("height: suggested:", ihv, "got:", this.v.height.value);
console.log("right: suggested:", iwv, "got:", this.v.right.value);
console.log("bottom: suggested:", ihv, "got:", this.v.bottom.value);
}
}.bind(this);

Expand Down

0 comments on commit de663bb

Please sign in to comment.