Add support for wrapping to PanelComponent
Add support for wrapping at x elements to PanelComponent, depends on panel component orientation. Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -55,6 +55,9 @@ public class PanelComponent implements LayoutableRenderableEntity
|
|||||||
@Setter
|
@Setter
|
||||||
private Orientation orientation = Orientation.VERTICAL;
|
private Orientation orientation = Orientation.VERTICAL;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
private int wrapping = -1;
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
private Rectangle border = new Rectangle(
|
private Rectangle border = new Rectangle(
|
||||||
ComponentConstants.STANDARD_BORDER,
|
ComponentConstants.STANDARD_BORDER,
|
||||||
@@ -100,9 +103,14 @@ public class PanelComponent implements LayoutableRenderableEntity
|
|||||||
preferredSize.width - border.x - border.width,
|
preferredSize.width - border.x - border.width,
|
||||||
preferredSize.height - border.y - border.height);
|
preferredSize.height - border.y - border.height);
|
||||||
|
|
||||||
|
// Calculate max width/height for infoboxes
|
||||||
|
int totalHeight = 0;
|
||||||
|
int totalWidth = 0;
|
||||||
|
|
||||||
// Render all children
|
// Render all children
|
||||||
for (final LayoutableRenderableEntity child : children)
|
for (int i = 0; i < children.size(); i ++)
|
||||||
{
|
{
|
||||||
|
final LayoutableRenderableEntity child = children.get(i);
|
||||||
child.setPreferredSize(childPreferredSize);
|
child.setPreferredSize(childPreferredSize);
|
||||||
graphics.translate(x, y);
|
graphics.translate(x, y);
|
||||||
final Dimension childDimension = child.render(graphics);
|
final Dimension childDimension = child.render(graphics);
|
||||||
@@ -121,14 +129,43 @@ public class PanelComponent implements LayoutableRenderableEntity
|
|||||||
height = Math.max(height, childDimension.height);
|
height = Math.max(height, childDimension.height);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate total size
|
||||||
|
totalWidth = Math.max(totalWidth, width);
|
||||||
|
totalHeight = Math.max(totalHeight, height);
|
||||||
|
|
||||||
|
if (wrapping > 0 && i < children.size() - 1 && (i + 1) % wrapping == 0)
|
||||||
|
{
|
||||||
|
switch (orientation)
|
||||||
|
{
|
||||||
|
case VERTICAL:
|
||||||
|
{
|
||||||
|
height = 0;
|
||||||
|
y = baseY;
|
||||||
|
int diff = childDimension.width + gap.x;
|
||||||
|
x += diff;
|
||||||
|
width += diff;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case HORIZONTAL:
|
||||||
|
{
|
||||||
|
width = 0;
|
||||||
|
x = baseX;
|
||||||
|
int diff = childDimension.height + gap.y;
|
||||||
|
y += diff;
|
||||||
|
height += diff;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove last child gap
|
// Remove last child gap
|
||||||
width -= gap.x;
|
totalWidth -= gap.x;
|
||||||
height -= gap.y;
|
totalHeight -= gap.y;
|
||||||
|
|
||||||
// Cache children bounds
|
// Cache children bounds
|
||||||
childDimensions.setSize(width, height);
|
childDimensions.setSize(totalWidth, totalHeight);
|
||||||
|
|
||||||
return dimension;
|
return dimension;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user