Fix Layer that specifies its own w/h (#943)

* Fix Layer that specifies its own w/h

* better handling for 0 and less nesting

* document bug
This commit is contained in:
jberg 2019-10-11 20:10:18 -07:00 committed by GitHub
parent 833907e1c2
commit 8881332f1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View file

@ -282,7 +282,7 @@ function Layout({ makiObject }) {
}
function Layer({ makiObject }) {
const { id, js_assets, image, x, y } = makiObject.attributes;
const { id, js_assets, image, x, y, w, h } = makiObject.attributes;
if (image == null) {
console.warn("Got an Layer without an image. Rendering null", id);
return null;
@ -305,10 +305,14 @@ function Layer({ makiObject }) {
if (img.y !== undefined) {
params.backgroundPositionY = -Number(img.y);
}
if (img.w !== undefined) {
if (w !== undefined) {
params.width = Number(w);
} else if (img.w !== undefined) {
params.width = Number(img.w);
}
if (img.h !== undefined) {
if (h !== undefined) {
params.height = Number(h);
} else if (img.h !== undefined) {
params.height = Number(img.h);
}
if (img.imgUrl !== undefined) {

View file

@ -139,6 +139,12 @@ class GuiObject extends MakiObject {
// TODO
// I don't know how it gets calculated exactly, but if a node has a minimum
// and maximum h, but no h, getwidth still returns a value, return min for now
// TODO: Need to return actual current width which can be based on underlying image
// CornerAmp has a calls like: obj.resize(newX, newY, obj.getwidth(), obj.getheight()),
// but the object has no width/height set, so it needs to return the width/height
// that potentially uses the image size like we do in the renderer.
// This is made more complicated because images depend on the current state and are
// potentially different attributes for different MakiObjects
return Number(this.attributes.h) || Number(this.attributes.minimum_h) || 0;
}
@ -146,6 +152,12 @@ class GuiObject extends MakiObject {
// TODO
// I don't know how it gets calculated exactly, but if a node has a minimum
// and maximum w, but no w, getwidth still returns a value, return min for now
// TODO: Need to return actual current width which can be based on underlying image
// CornerAmp has a calls like: obj.resize(newX, newY, obj.getwidth(), obj.getheight()),
// but the object has no width/height set, so it needs to return the width/height
// that potentially uses the image size like we do in the renderer.
// This is made more complicated because images depend on the current state and are
// potentially different attributes for different MakiObjects
return Number(this.attributes.w) || Number(this.attributes.minimum_w) || 0;
}