From 4ef1faa389ad4672eafd1663003dd4a815b9b61b Mon Sep 17 00:00:00 2001
From: Joshua Slack
Date: Wed, 18 Oct 2017 17:29:28 -0500
Subject: Split minimum size into layout provided and optional user provided.
---
.../extension/ui/AbstractLabelUIComponent.java | 2 +-
.../extension/ui/AbstractUITextEntryComponent.java | 14 ++--
.../java/com/ardor3d/extension/ui/UIComponent.java | 76 ++++++++++++++++------
.../java/com/ardor3d/extension/ui/UIPieMenu.java | 2 +-
.../com/ardor3d/extension/ui/UIScrollPanel.java | 8 +--
.../ardor3d/extension/ui/layout/AnchorLayout.java | 14 ++--
.../ardor3d/extension/ui/layout/BorderLayout.java | 13 ++--
.../ardor3d/extension/ui/layout/GridLayout.java | 14 ++--
.../com/ardor3d/extension/ui/layout/RowLayout.java | 2 +-
9 files changed, 89 insertions(+), 56 deletions(-)
(limited to 'ardor3d-ui')
diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/AbstractLabelUIComponent.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/AbstractLabelUIComponent.java
index 6d87247..27f38e3 100644
--- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/AbstractLabelUIComponent.java
+++ b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/AbstractLabelUIComponent.java
@@ -64,7 +64,7 @@ public abstract class AbstractLabelUIComponent extends StateBasedUIComponent imp
height = Math.max(_iconDimensions.getHeight(), height);
}
- setMinimumContentSize(width, height);
+ setLayoutMinimumContentSize(width, height);
if (getContentWidth() < width) {
setContentWidth(width);
}
diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/AbstractUITextEntryComponent.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/AbstractUITextEntryComponent.java
index 8b6f0ff..0f6b93b 100644
--- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/AbstractUITextEntryComponent.java
+++ b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/AbstractUITextEntryComponent.java
@@ -3,7 +3,7 @@
*
* This file is part of Ardor3D.
*
- * Ardor3D is free software: you can redistribute it and/or modify it
+ * Ardor3D is free software: you can redistribute it and/or modify it
* under the terms of its license which may be found in the accompanying
* LICENSE file or at .
*/
@@ -13,12 +13,12 @@ package com.ardor3d.extension.ui;
import java.util.Map;
import com.ardor3d.extension.ui.text.RenderedText;
+import com.ardor3d.extension.ui.text.RenderedText.RenderedTextData;
import com.ardor3d.extension.ui.text.StyleConstants;
import com.ardor3d.extension.ui.text.TextCaret;
import com.ardor3d.extension.ui.text.TextFactory;
import com.ardor3d.extension.ui.text.TextSelection;
import com.ardor3d.extension.ui.text.UIKeyHandler;
-import com.ardor3d.extension.ui.text.RenderedText.RenderedTextData;
import com.ardor3d.extension.ui.util.Alignment;
import com.ardor3d.input.InputState;
import com.ardor3d.input.MouseButton;
@@ -83,7 +83,7 @@ public abstract class AbstractUITextEntryComponent extends StateBasedUIComponent
/**
* Set the text for this component. Also updates the minimum size of the component.
- *
+ *
* @param text
* the new text
*/
@@ -130,7 +130,7 @@ public abstract class AbstractUITextEntryComponent extends StateBasedUIComponent
/**
* Set the position of the text caret as an index to the current set text string. If the specified position is after
* the last possible index, it is set to the last possible index.
- *
+ *
* @param index
* the new position
*/
@@ -212,7 +212,7 @@ public abstract class AbstractUITextEntryComponent extends StateBasedUIComponent
}
}
- setMinimumContentSize(width, height);
+ setLayoutMinimumContentSize(width, height);
fireComponentDirty();
}
@@ -238,12 +238,12 @@ public abstract class AbstractUITextEntryComponent extends StateBasedUIComponent
@Override
public void mouseEntered(final int mouseX, final int mouseY, final InputState state) {
- // CursorUtil.getCursorFactory().getTextCursor().setActive();
+ // CursorUtil.getCursorFactory().getTextCursor().setActive();
}
@Override
public void mouseDeparted(final int mouseX, final int mouseY, final InputState state) {
- // CursorUtil.getCursorFactory().getDefaultCursor().setActive();
+ // CursorUtil.getCursorFactory().getDefaultCursor().setActive();
}
}
}
diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIComponent.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIComponent.java
index 051dc65..b132ca1 100644
--- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIComponent.java
+++ b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIComponent.java
@@ -54,6 +54,8 @@ import com.google.common.collect.Maps;
* TODO: alert/dirty needed for font style changes.
*/
public abstract class UIComponent extends Node implements UIKeyHandler {
+ private static final int DEFAULT_MAX_CONTENT_SIZE = 10000;
+
/** If true, use opacity settings to blend the components. Default is false. */
private static boolean _useTransparency = false;
@@ -63,9 +65,11 @@ public abstract class UIComponent extends Node implements UIKeyHandler {
/** The internal contents portion of this component. */
private final Dimension _contentsSize = new Dimension(10, 10);
/** The absolute minimum size of the internal contents portion of this component. */
- private final Dimension _minimumContentsSize = new Dimension(10, 10);
+ private final Dimension _layoutMinimumContentsSize = new Dimension(0, 0);
+ /** The absolute minimum size of the internal contents portion of this component. */
+ private final Dimension _minimumContentsSize = new Dimension(-1, -1);
/** The absolute maximum size of the internal contents portion of this component. */
- private final Dimension _maximumContentsSize = new Dimension(10000, 10000);
+ private final Dimension _maximumContentsSize = new Dimension(-1, -1);
/** A spacing between the component's border and its inner content area. */
private Insets _padding = new Insets(0, 0, 0, 0);
/** A border around this component. */
@@ -388,32 +392,50 @@ public abstract class UIComponent extends Node implements UIKeyHandler {
setLocalComponentHeight(height);
}
+ protected int getMinimumContentWidth() {
+ return _minimumContentsSize.getWidth() > 0 ? _minimumContentsSize.getWidth() : _layoutMinimumContentsSize
+ .getWidth();
+ }
+
+ protected int getMinimumContentHeight() {
+ return _minimumContentsSize.getHeight() > 0 ? _minimumContentsSize.getHeight() : _layoutMinimumContentsSize
+ .getHeight();
+ }
+
/**
* @return the width contained in _minimumContentsSize + the margin, border and padding values for left and right.
*/
public int getMinimumLocalComponentWidth() {
- return _minimumContentsSize.getWidth() + getTotalLeft() + getTotalRight();
+ return getMinimumContentWidth() + getTotalLeft() + getTotalRight();
}
/**
* @return the height contained in _minimumContentsSize + the margin, border and padding values for top and bottom.
*/
public int getMinimumLocalComponentHeight() {
- return _minimumContentsSize.getHeight() + getTotalTop() + getTotalBottom();
+ return getMinimumContentHeight() + getTotalTop() + getTotalBottom();
+ }
+
+ protected int getMaximumContentWidth() {
+ return _maximumContentsSize.getWidth() > 0 ? _maximumContentsSize.getWidth() : UIComponent.DEFAULT_MAX_CONTENT_SIZE;
+ }
+
+ protected int getMaximumContentHeight() {
+ return _maximumContentsSize.getHeight() > 0 ? _maximumContentsSize.getHeight() : UIComponent.DEFAULT_MAX_CONTENT_SIZE;
}
/**
* @return the width contained in _maximumContentsSize + the margin, border and padding values for left and right.
*/
public int getMaximumLocalComponentWidth() {
- return _maximumContentsSize.getWidth() + getTotalLeft() + getTotalRight();
+ return getMaximumContentWidth() + getTotalLeft() + getTotalRight();
}
/**
* @return the height contained in _maximumContentsSize + the margin, border and padding values for top and bottom.
*/
public int getMaximumLocalComponentHeight() {
- return _maximumContentsSize.getHeight() + getTotalTop() + getTotalBottom();
+ return getMaximumContentHeight() + getTotalTop() + getTotalBottom();
}
/**
@@ -427,12 +449,6 @@ public abstract class UIComponent extends Node implements UIKeyHandler {
public void setContentSize(final int width, final int height) {
setContentWidth(width);
setContentHeight(height);
- if (_maximumContentsSize.getWidth() < width) {
- _maximumContentsSize.setWidth(width);
- }
- if (_maximumContentsSize.getHeight() < height) {
- _maximumContentsSize.setHeight(height);
- }
}
/**
@@ -443,8 +459,7 @@ public abstract class UIComponent extends Node implements UIKeyHandler {
* the new height
*/
public void setContentHeight(final int height) {
- _contentsSize.setHeight(MathUtils.clamp(height, _minimumContentsSize.getHeight(),
- _maximumContentsSize.getHeight()));
+ _contentsSize.setHeight(MathUtils.clamp(height, getMinimumContentHeight(), getMaximumContentHeight()));
}
/**
@@ -455,8 +470,7 @@ public abstract class UIComponent extends Node implements UIKeyHandler {
* the new width
*/
public void setContentWidth(final int width) {
- _contentsSize
- .setWidth(MathUtils.clamp(width, _minimumContentsSize.getWidth(), _maximumContentsSize.getWidth()));
+ _contentsSize.setWidth(MathUtils.clamp(width, getMinimumContentWidth(), getMaximumContentWidth()));
}
/**
@@ -493,6 +507,11 @@ public abstract class UIComponent extends Node implements UIKeyHandler {
return _contentsSize.getHeight();
}
+ public void clearMaximumContentSize() {
+ _maximumContentsSize.set(-1, -1);
+ validateContentSize();
+ }
+
/**
* Sets the maximum content size of this component to the values given.
*
@@ -523,6 +542,22 @@ public abstract class UIComponent extends Node implements UIKeyHandler {
validateContentSize();
}
+ /**
+ * Sets the minimum content size of this component to the values given.
+ *
+ * @param width
+ * @param height
+ */
+ public void setLayoutMinimumContentSize(final int width, final int height) {
+ _layoutMinimumContentsSize.set(width, height);
+ validateContentSize();
+ }
+
+ public void clearMinimumContentSize() {
+ _minimumContentsSize.set(-1, -1);
+ validateContentSize();
+ }
+
/**
* Sets the minimum content size of this component to the values given.
*
@@ -574,10 +609,9 @@ public abstract class UIComponent extends Node implements UIKeyHandler {
* Ensures content size is between min and max.
*/
protected void validateContentSize() {
- final int width = MathUtils.clamp(_contentsSize.getWidth(), _minimumContentsSize.getWidth(),
- _maximumContentsSize.getWidth());
- final int height = MathUtils.clamp(_contentsSize.getHeight(), _minimumContentsSize.getHeight(),
- _maximumContentsSize.getHeight());
+ final int width = MathUtils.clamp(_contentsSize.getWidth(), getMinimumContentWidth(), getMaximumContentWidth());
+ final int height = MathUtils.clamp(_contentsSize.getHeight(), getMinimumContentHeight(),
+ getMaximumContentHeight());
_contentsSize.set(width, height);
}
@@ -586,7 +620,7 @@ public abstract class UIComponent extends Node implements UIKeyHandler {
* (if component is set to allow such resizing.)
*/
public void compact() {
- setContentSize(_minimumContentsSize.getWidth(), _minimumContentsSize.getHeight());
+ setContentSize(getMinimumContentWidth(), getMinimumContentHeight());
}
/**
diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIPieMenu.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIPieMenu.java
index f1f57a6..5d87e92 100644
--- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIPieMenu.java
+++ b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIPieMenu.java
@@ -235,7 +235,7 @@ public class UIPieMenu extends UIPopupMenu implements IPopOver {
@Override
public void updateMinimumSizeFromContents() {
- setMinimumContentSize(_outerRadius * 2, _outerRadius * 2);
+ setLayoutMinimumContentSize(_outerRadius * 2, _outerRadius * 2);
}
public int getSliceIndex(final UIPieMenuItem item) {
diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIScrollPanel.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIScrollPanel.java
index e7c74cb..e91ccaf 100644
--- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIScrollPanel.java
+++ b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/UIScrollPanel.java
@@ -3,7 +3,7 @@
*
* This file is part of Ardor3D.
*
- * Ardor3D is free software: you can redistribute it and/or modify it
+ * Ardor3D is free software: you can redistribute it and/or modify it
* under the terms of its license which may be found in the accompanying
* LICENSE file or at .
*/
@@ -70,7 +70,7 @@ public class UIScrollPanel extends UIPanel {
protected void drawComponent(final Renderer renderer) {
_clipRectangleStore.set(getHudX() + getTotalLeft(),
getHudY() + getTotalBottom() + horizontalScrollBar.getContentHeight(), getContentWidth()
- - verticalScrollBar.getContentWidth(),
+ - verticalScrollBar.getContentWidth(),
getContentHeight() - horizontalScrollBar.getContentHeight());
renderer.pushClip(_clipRectangleStore);
@@ -89,8 +89,8 @@ public class UIScrollPanel extends UIPanel {
@Override
public void updateMinimumSizeFromContents() {
super.updateMinimumSizeFromContents();
- setMinimumContentSize(verticalScrollBar.getLocalComponentWidth() + 1, horizontalScrollBar
- .getLocalComponentHeight() + 1);
+ setLayoutMinimumContentSize(verticalScrollBar.getLocalComponentWidth() + 1,
+ horizontalScrollBar.getLocalComponentHeight() + 1);
updateScrollBarSliders();
}
diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/layout/AnchorLayout.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/layout/AnchorLayout.java
index b136420..fa974d7 100644
--- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/layout/AnchorLayout.java
+++ b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/layout/AnchorLayout.java
@@ -3,7 +3,7 @@
*
* This file is part of Ardor3D.
*
- * Ardor3D is free software: you can redistribute it and/or modify it
+ * Ardor3D is free software: you can redistribute it and/or modify it
* under the terms of its license which may be found in the accompanying
* LICENSE file or at .
*/
@@ -32,20 +32,20 @@ import com.google.common.collect.Maps;
*
* As an example, the following would setup labelA in the top left corner of the container, 5 pixels from the top and 5
* pixels from the bottom. Directly below that (5 pixels from the bottom of labelA) is labelB, left aligned to labelA:
- *
+ *
*
* UIContainer container;
* UILabel labelA, labelB
- *
+ *
* ...
- *
+ *
* container.setLayout(new AnchorLayout());
* labelA.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, container, Alignment.TOP_LEFT, 5, -5));
* labelB.setLayoutData(new AnchorLayoutData(Alignment.TOP_LEFT, labelA, Alignment.BOTTOM_LEFT, 0, -5));
*
- *
+ *
*
- *
+ *
* @see AnchorLayoutData
*/
public class AnchorLayout extends UILayout {
@@ -116,7 +116,7 @@ public class AnchorLayout extends UILayout {
@Override
public void updateMinimumSizeFromContents(final UIContainer container) {
layoutContents(container);
- container.setMinimumContentSize(_maxX - _minX, _maxY - _minY);
+ container.setLayoutMinimumContentSize(_maxX - _minX, _maxY - _minY);
}
private void visit(final UIComponent toVisit) {
diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/layout/BorderLayout.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/layout/BorderLayout.java
index b7c7f40..9d1bcf5 100644
--- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/layout/BorderLayout.java
+++ b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/layout/BorderLayout.java
@@ -3,7 +3,7 @@
*
* This file is part of Ardor3D.
*
- * Ardor3D is free software: you can redistribute it and/or modify it
+ * Ardor3D is free software: you can redistribute it and/or modify it
* under the terms of its license which may be found in the accompanying
* LICENSE file or at .
*/
@@ -20,7 +20,7 @@ import com.ardor3d.scenegraph.Spatial;
/**
* This layout places components on the edges or in the center of a container, depending on the value of the layout data
* object they hold. The behavior is meant to be similar to awt's {@link java.awt.BorderLayout BorderLayout}.
- *
+ *
* @see BorderLayoutData
*/
public class BorderLayout extends UILayout {
@@ -102,9 +102,8 @@ public class BorderLayout extends UILayout {
comp.setLocalXY(-store.getX(), heightSouth - store.getY());
break;
case CENTER:
- comp.fitComponentIn(container.getContentWidth() - widthEast - widthWest, container
- .getContentHeight()
- - heightSouth - heightNorth);
+ comp.fitComponentIn(container.getContentWidth() - widthEast - widthWest,
+ container.getContentHeight() - heightSouth - heightNorth);
comp.getRelativeComponentBounds(store);
comp.setLocalXY(widthWest - store.getX(), heightSouth - store.getY());
}
@@ -114,8 +113,8 @@ public class BorderLayout extends UILayout {
@Override
public void updateMinimumSizeFromContents(final UIContainer container) {
- container.setMinimumContentSize(getMinimumWidth(container.getChildren()), getMinimumHeight(container
- .getChildren()));
+ container.setLayoutMinimumContentSize(getMinimumWidth(container.getChildren()),
+ getMinimumHeight(container.getChildren()));
}
private int getMinimumHeight(final List content) {
diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/layout/GridLayout.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/layout/GridLayout.java
index 44b9666..a835c35 100644
--- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/layout/GridLayout.java
+++ b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/layout/GridLayout.java
@@ -3,7 +3,7 @@
*
* This file is part of Ardor3D.
*
- * Ardor3D is free software: you can redistribute it and/or modify it
+ * Ardor3D is free software: you can redistribute it and/or modify it
* under the terms of its license which may be found in the accompanying
* LICENSE file or at .
*/
@@ -27,7 +27,7 @@ import com.ardor3d.scenegraph.Spatial;
* content plus some inter-cell spacing. The components should be added from top to down and left to right. Set the
* layout data of the last component in a row to wrap, e.g. by setLayoutData(GridLayoutData.Wrap); You can specify a
* horizontal span bigger than one to specify that a component should use multiple cells in the current row.
- *
+ *
* XXX: Note that this class does not currently support layout of rotated components.
*/
public class GridLayout extends UILayout {
@@ -55,7 +55,7 @@ public class GridLayout extends UILayout {
/**
* Create a GridLayout with the specified parameters and a vertical alignment to top and no distribution of vertical
* space.
- *
+ *
* @param interCellSpacingHorizontal
* @param interCellSpacingVertical
* @param leftMargin
@@ -72,7 +72,7 @@ public class GridLayout extends UILayout {
/**
* Create a Gridlayout with the specified parameters. If vertical space is distributed the vertical alignment does
* not matter.
- *
+ *
* @param interCellSpacingHorizontal
* @param interCellSpacingVertical
* @param leftMargin
@@ -90,7 +90,7 @@ public class GridLayout extends UILayout {
/**
* Create a GridLayout with the specified parameters. Any additional vertical space won't be distributed between
* rows.
- *
+ *
* @param interCellSpacingHorizontal
* @param interCellSpacingVertical
* @param leftMargin
@@ -109,7 +109,7 @@ public class GridLayout extends UILayout {
/**
* Create a GridLayout with the specified parameters. Note that the vertical alignment does not matter if you choose
* to distribute any additional space between rows.
- *
+ *
* @param interCellSpacingHorizontal
* @param interCellSpacingVertical
* @param leftMargin
@@ -169,7 +169,7 @@ public class GridLayout extends UILayout {
public void updateMinimumSizeFromContents(final UIContainer container) {
rebuildGrid(container);
grid.updateMinimalSize();
- container.setMinimumContentSize(grid.minWidth, grid.minHeight);
+ container.setLayoutMinimumContentSize(grid.minWidth, grid.minHeight);
}
private void rebuildGrid(final UIContainer container) {
diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/layout/RowLayout.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/layout/RowLayout.java
index a7fd43c..f3131bc 100644
--- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/layout/RowLayout.java
+++ b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/layout/RowLayout.java
@@ -224,7 +224,7 @@ public class RowLayout extends UILayout {
}
}
}
- container.setMinimumContentSize(minW, minH);
+ container.setLayoutMinimumContentSize(minW, minH);
}
private int getSumOfAllHeights(final List content) {
--
cgit v1.2.3