Skip to content

Commit

Permalink
Label: Fix StringView to be not visible when empty, so it doesn't add…
Browse files Browse the repository at this point in the history
… space to layout

ViewProxy: Fixed getChildrenMaxX, getChildrenMaxY to check last child margin
  • Loading branch information
reportmill committed Jul 22, 2021
1 parent bc3aced commit 5914e39
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/snap/view/Label.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
22 changes: 17 additions & 5 deletions src/snap/view/ViewProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ViewProxy<T extends View> extends Rect {
private T _view;

// The children
private ViewProxy<?> _children[];
private ViewProxy<?>[] _children;

// The insets
private Insets _insets;
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit 5914e39

Please sign in to comment.