From 5914e39bbb30c400938e2cab574709e30e91fde4 Mon Sep 17 00:00:00 2001 From: Jeff Martin Date: Thu, 22 Jul 2021 11:08:01 -0500 Subject: [PATCH] Label: Fix StringView to be not visible when empty, so it doesn't add space to layout ViewProxy: Fixed getChildrenMaxX, getChildrenMaxY to check last child margin --- src/snap/view/Label.java | 1 + src/snap/view/ViewProxy.java | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/snap/view/Label.java b/src/snap/view/Label.java index 5d92c552..a071ab4d 100644 --- a/src/snap/view/Label.java +++ b/src/snap/view/Label.java @@ -89,6 +89,7 @@ public void setText(String aValue) // Set value and fire prop change StringView sview = getStringView(); sview.setText(aValue); + sview.setVisible(aValue != null && aValue.length() > 0); firePropChange(Text_Prop, oldVal, aValue); } diff --git a/src/snap/view/ViewProxy.java b/src/snap/view/ViewProxy.java index d0f7561a..333a6897 100644 --- a/src/snap/view/ViewProxy.java +++ b/src/snap/view/ViewProxy.java @@ -12,7 +12,7 @@ public class ViewProxy extends Rect { private T _view; // The children - private ViewProxy _children[]; + private ViewProxy[] _children; // The insets private Insets _insets; @@ -320,10 +320,16 @@ public int getGrowHeightCount() */ public double getChildrenMaxXLastWithInsets() { + // Get LastChildMaxX, LastChildMarginRight ViewProxy[] children = getChildren(); - double childMaxX = children.length > 0 ? children[children.length-1].getMaxX() : 0; + ViewProxy lastChild = children.length > 0 ? children[children.length-1] : null; + double childMaxX = lastChild != null ? lastChild.getMaxX() : 0; + double lastChildMarginRight = lastChild != null ? lastChild.getMargin().right : 0; + + // Return LastChildMaxX plus padding right Insets ins = getInsetsAll(); - return Math.ceil(childMaxX + ins.right); + double rightInset = Math.max(ins.right, lastChildMarginRight); + return Math.ceil(childMaxX + rightInset); } /** @@ -344,10 +350,16 @@ public double getChildrenMaxXAllWithInsets() */ public double getChildrenMaxYLastWithInsets() { + // Get LastChildMaxY, LastChildMarginBottom ViewProxy[] children = getChildren(); - double childMaxY = children.length > 0 ? children[children.length-1].getMaxY() : 0; + ViewProxy lastChild = children.length > 0 ? children[children.length-1] : null; + double lastChildMaxY = lastChild != null ? lastChild.getMaxY() : 0; + double lastChildMarginBottom = lastChild != null ? lastChild.getMargin().bottom : 0; + + // Return LastChildMaxY plus padding bottom Insets ins = getInsetsAll(); - return Math.ceil(childMaxY + ins.bottom); + double bottomInset = Math.max(ins.bottom, lastChildMarginBottom); + return Math.ceil(lastChildMaxY + bottomInset); } /**