Skip to content

Commit

Permalink
Slight fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
reportmill committed Jul 24, 2021
1 parent e1e8fc1 commit 5834e0e
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 39 deletions.
5 changes: 5 additions & 0 deletions src/snap/gfx/Border.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ public boolean equals(Object anObj)
*/
public static Border blackBorder() { return Borders.BLACK_BORDER; }

/**
* Returns a simple empty border.
*/
public static Border emptyBorder() { return Borders.EMPTY_BORDER; }

/**
* Creates an empty border for inset.
*/
Expand Down
1 change: 1 addition & 0 deletions src/snap/gfx/Borders.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class Borders {

// Common borders
public static final Border BLACK_BORDER = Border.createLineBorder(Color.BLACK, 1);
public static final Border EMPTY_BORDER = Border.createEmptyBorder(0);

// Border constants
private static Color BORDER_GRAY = Color.LIGHTGRAY;
Expand Down
36 changes: 19 additions & 17 deletions src/snap/view/ColView.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ public XMLElement toXMLView(XMLArchiver anArchiver)

// Archive Spacing, FillWidth
if (getSpacing() != 0)
e.add("Spacing", getSpacing());
e.add(Spacing_Prop, getSpacing());
if (isFillWidth())
e.add("FillWidth", true);
e.add(FillWidth_Prop, true);
return e;
}

Expand All @@ -100,10 +100,10 @@ public void fromXMLView(XMLArchiver anArchiver, XMLElement anElement)
super.fromXMLView(anArchiver, anElement);

// Unarchive Spacing, FillWidth
if (anElement.hasAttribute("Spacing"))
setSpacing(anElement.getAttributeFloatValue("Spacing"));
if (anElement.hasAttribute("FillWidth"))
setFillWidth(anElement.getAttributeBoolValue("FillWidth"));
if (anElement.hasAttribute(Spacing_Prop))
setSpacing(anElement.getAttributeFloatValue(Spacing_Prop));
if (anElement.hasAttribute(FillWidth_Prop))
setFillWidth(anElement.getAttributeBoolValue(FillWidth_Prop));
}

/**
Expand Down Expand Up @@ -168,7 +168,7 @@ public static double getPrefHeightProxy(ViewProxy aPar, double aW)
public static void layoutProxy(ViewProxy aPar, boolean isFillWidth)
{
// If no children, just return
if (aPar.getChildCount()==0) return;
if (aPar.getChildCount() == 0) return;

// Load layout rects and return
layoutProxyY(aPar);
Expand Down Expand Up @@ -237,25 +237,26 @@ public static void layoutProxyY(ViewProxy aPar)
{
// Get parent info
ViewProxy[] children = aPar.getChildren();
Insets ins = aPar.getInsetsAll();
double spacing = aPar.getSpacing();
Insets ins = aPar.getInsetsAll(); // Should really just use Padding
double parentSpacing = aPar.getSpacing();

// Loop vars
double childY = 0;
ViewProxy lastChild = null;
double lastMargin = ins.top;

// Iterate over children to calculate bounds Y and Height
for (ViewProxy child : children) {

// Get child height
double childH = child.getBestHeight(-1); // cw?

// Update child x: advance for max of spacing and margins
double lastMargin = lastChild != null ? lastChild.getMargin().bottom : ins.top;
// Calculate spacing between lastChild and loop child
double loopMargin = child.getMargin().top;
double maxMargin = Math.max(lastMargin, loopMargin);
double childSpacing = lastChild != null ? Math.max(spacing, maxMargin) : maxMargin;
double childSpacing = Math.max(lastMargin, loopMargin);
if (lastChild != null)
childSpacing = Math.max(childSpacing, parentSpacing);

// Update ChildY with spacing and calculate ChildH
childY += childSpacing;
double childH = child.getBestHeight(-1);

// Set child bounds Y and Height
child.setY(childY);
Expand All @@ -264,6 +265,7 @@ public static void layoutProxyY(ViewProxy aPar)
// Update child Y loop var and last child
childY += childH;
lastChild = child;
lastMargin = child.getMargin().bottom;
}

// If Parent.Height -1, just return (laying out for PrefHeight)
Expand All @@ -272,7 +274,7 @@ public static void layoutProxyY(ViewProxy aPar)
return;

// Calculate total layout height (last child MaxY + margin/padding)
double bottomSpacing = Math.max(lastChild.getMargin().bottom, ins.bottom);
double bottomSpacing = Math.max(lastMargin, ins.bottom);
double layoutH = childY + bottomSpacing;

// Calculate extra space and add to growers or alignment
Expand Down
30 changes: 17 additions & 13 deletions src/snap/view/RowView.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ public XMLElement toXMLView(XMLArchiver anArchiver)

// Archive Spacing, FillHeight
if (getSpacing() != 0)
e.add("Spacing", getSpacing());
e.add(Spacing_Prop, getSpacing());
if (isFillHeight())
e.add("FillHeight", true);
e.add(FillHeight_Prop, true);
return e;
}

Expand All @@ -105,8 +105,10 @@ public void fromXMLView(XMLArchiver anArchiver, XMLElement anElement)
super.fromXMLView(anArchiver, anElement);

// Unarchive Spacing, FillHeight
setSpacing(anElement.getAttributeFloatValue("Spacing", 0));
setFillHeight(anElement.getAttributeBoolValue("FillHeight", false));
if (anElement.hasAttribute(Spacing_Prop))
setSpacing(anElement.getAttributeFloatValue(Spacing_Prop, 0));
if (anElement.hasAttribute(FillHeight_Prop))
setFillHeight(anElement.getAttributeBoolValue(FillHeight_Prop, false));
}

/**
Expand Down Expand Up @@ -185,25 +187,26 @@ private static void layoutProxyX(ViewProxy aPar)
{
// Get parent info
ViewProxy[] children = aPar.getChildren();
double spacing = aPar.getSpacing();
Insets ins = aPar.getInsetsAll();
double parentSpacing = aPar.getSpacing();

// Loop vars
double childX = 0;
ViewProxy lastChild = null;
double lastMargin = ins.left;

// Iterate over children to calculate bounds X and Width
for (ViewProxy child : children) {

// Get child width
double childW = child.getBestWidth(-1);

// Update child x: advance for max of spacing and margins
double lastMargin = lastChild != null ? lastChild.getMargin().right : ins.left;
// Calculate spacing between lastChild and loop child
double loopMargin = child.getMargin().left;
double maxMargin = Math.max(lastMargin, loopMargin);
double childSpacing = lastChild != null ? Math.max(spacing, maxMargin) : maxMargin;
double childSpacing = Math.max(lastMargin, loopMargin);
if (lastChild != null)
childSpacing = Math.max(childSpacing, parentSpacing);

// Update ChildY with spacing and calculate ChildH
childX += childSpacing;
double childW = child.getBestWidth(-1);

// Set child bounds X and Width
child.setX(childX);
Expand All @@ -212,6 +215,7 @@ private static void layoutProxyX(ViewProxy aPar)
// Update child x loop var and last child
childX += childW;
lastChild = child;
lastMargin = lastChild.getMargin().right;
}

// If Parent.Width -1, just return (laying out for PrefWidth)
Expand All @@ -220,7 +224,7 @@ private static void layoutProxyX(ViewProxy aPar)
return;

// Calculate total layout width (last child MaxX + margin/padding)
double rightSpacing = Math.max(lastChild.getMargin().right, ins.right);
double rightSpacing = Math.max(lastMargin, ins.right);
double layoutW = childX + rightSpacing;

// Calculate extra space and add to growers or alignment
Expand Down
3 changes: 2 additions & 1 deletion src/snap/view/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -1849,7 +1849,8 @@ public Insets getInsetsAll()
{
Insets ins = getPadding();
Border border = getBorder();
if (border!=null) ins = Insets.add(ins, border.getInsets());
if (border != null)
ins = Insets.add(ins, border.getInsets());
return ins;
}

Expand Down
57 changes: 49 additions & 8 deletions src/snap/view/ViewProxy.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package snap.view;
import snap.geom.*;
import snap.gfx.Border;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -14,8 +15,11 @@ public class ViewProxy<T extends View> extends Rect {
// The children
private ViewProxy<?>[] _children;

// The insets
private Insets _insets;
// The border
private Border _border;

// The Padding
private Insets _padding;

// The alignment
private Pos _align;
Expand Down Expand Up @@ -161,21 +165,58 @@ public <E extends View> ViewProxy<E>[] getChildrenForClass(Class<E> aClass)
}

/**
* Sets the insets.
* Returns the border.
*/
public Border getBorder()
{
if (_border != null) return _border;
return _border = _view != null ? _view.getBorder() : null;
}

/**
* Sets the border.
*/
public void setBorder(Border aBorder)
{
_border = aBorder;
}

/**
* Returns the border insets.
*/
public Insets getBorderInsets()
{
Border border = getBorder();
return border != null ? border.getInsets() : Insets.EMPTY;
}

/**
* Returns the padding.
*/
public Insets getPadding()
{
if (_padding != null) return _padding;
return _padding = _view != null ? _view.getPadding() : Insets.EMPTY;
}

/**
* Sets the padding.
*/
public void setInsets(Insets theIns)
public void setPadding(Insets theIns)
{
_insets = theIns;
_padding = theIns;
}

/**
* Returns the insets.
*/
public Insets getInsetsAll()
{
if (_insets != null) return _insets;
_insets = _view != null ? _view.getInsetsAll() : Insets.EMPTY;
return _insets;
Insets ins = getPadding();
Border border = getBorder();
if (border != null)
ins = Insets.add(ins, border.getInsets());
return ins;
}

/**
Expand Down

0 comments on commit 5834e0e

Please sign in to comment.