Skip to content

Commit

Permalink
Make overlay resizing configure wrapping
Browse files Browse the repository at this point in the history
Instead of resizing every overlay component inside wrapped panel
component simply adjust wrap based on preferred size. Also remove the
configurable wrap after.

Signed-off-by: Tomas Slusny <[email protected]>
  • Loading branch information
deathbeam authored and Adam- committed Apr 13, 2020
1 parent d676542 commit d881a2f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,17 +266,6 @@ default boolean infoBoxVertical()
return false;
}

@ConfigItem(
keyName = "infoBoxWrap",
name = "Infobox wrap count",
description = "Configures the amount of infoboxes shown before wrapping",
position = 41
)
default int infoBoxWrap()
{
return 4;
}

@ConfigItem(
keyName = "infoBoxSize",
name = "Infobox size",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ class InventoryViewerOverlay extends Overlay
private InventoryViewerOverlay(Client client, ItemManager itemManager)
{
setPosition(OverlayPosition.BOTTOM_RIGHT);
panelComponent.setWrapping(4);
panelComponent.setWrap(true);
panelComponent.setGap(new Point(6, 4));
panelComponent.setPreferredSize(new Dimension(4 * (Constants.ITEM_SPRITE_WIDTH + 6), 0));
panelComponent.setOrientation(ComponentOrientation.HORIZONTAL);
this.itemManager = itemManager;
this.client = client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ private TeamCapesOverlay(TeamCapesPlugin plugin, TeamCapesConfig config, ItemMan
this.plugin = plugin;
this.config = config;
this.manager = manager;
panelComponent.setWrap(true);
panelComponent.setOrientation(ComponentOrientation.HORIZONTAL);
panelComponent.setWrapping(4);
getMenuEntries().add(new OverlayMenuEntry(RUNELITE_OVERLAY_CONFIG, OPTION_CONFIGURE, "Teamcapes overlay"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class PanelComponent implements LayoutableRenderableEntity
private Point preferredLocation = new Point();

@Setter
@Getter
private Dimension preferredSize = new Dimension(ComponentConstants.STANDARD_WIDTH, 0);

@Setter
Expand All @@ -57,7 +58,7 @@ public class PanelComponent implements LayoutableRenderableEntity
private ComponentOrientation orientation = ComponentOrientation.VERTICAL;

@Setter
private int wrapping = -1;
private boolean wrap = false;

@Setter
private Rectangle border = new Rectangle(
Expand Down Expand Up @@ -111,11 +112,23 @@ public Dimension render(Graphics2D graphics)
int totalWidth = 0;

// Render all children
for (int i = 0; i < children.size(); i ++)
for (final LayoutableRenderableEntity child : children)
{
final LayoutableRenderableEntity child = children.get(i);
// Correctly propagate child dimensions based on orientation and wrapping
if (!wrap)
{
switch (orientation)
{
case VERTICAL:
child.setPreferredSize(new Dimension(childPreferredSize.width, 0));
break;
case HORIZONTAL:
child.setPreferredSize(new Dimension(0, childPreferredSize.height));
break;
}
}

child.setPreferredLocation(new Point(x, y));
child.setPreferredSize(childPreferredSize);
final Dimension childDimension = child.render(graphics);

switch (orientation)
Expand All @@ -136,28 +149,38 @@ public Dimension render(Graphics2D graphics)
totalWidth = Math.max(totalWidth, width);
totalHeight = Math.max(totalHeight, height);

if (wrapping > 0 && i < children.size() - 1 && (i + 1) % wrapping == 0)
if (!wrap)
{
switch (orientation)
continue;
}

switch (orientation)
{
case VERTICAL:
{
case VERTICAL:
if (childPreferredSize.height > 0 && height >= childPreferredSize.height)
{
height = 0;
y = baseY;
int diff = childDimension.width + gap.x;
x += diff;
width += diff;
break;
}
case HORIZONTAL:

break;
}
case HORIZONTAL:
{
if (childPreferredSize.width > 0 && width >= childPreferredSize.width)
{
width = 0;
x = baseX;
int diff = childDimension.height + gap.y;
y += diff;
height += diff;
break;
}

break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
@Singleton
public class InfoBoxOverlay extends Overlay
{
private static final int GAP = 1;
private static final int DEFAULT_WRAP_COUNT = 4;

private final PanelComponent panelComponent = new PanelComponent();
private final InfoBoxManager infoboxManager;
private final TooltipManager tooltipManager;
Expand All @@ -67,9 +70,10 @@ private InfoBoxOverlay(
this.config = config;
setPosition(OverlayPosition.TOP_LEFT);

panelComponent.setWrap(true);
panelComponent.setBackgroundColor(null);
panelComponent.setBorder(new Rectangle());
panelComponent.setGap(new Point(1, 1));
panelComponent.setGap(new Point(GAP, GAP));
}

@Override
Expand All @@ -83,11 +87,13 @@ public Dimension render(Graphics2D graphics)
}

panelComponent.getChildren().clear();
panelComponent.setWrapping(config.infoBoxWrap());

// Set preferred size to the size of DEFAULT_WRAP_COUNT infoboxes, including the padding - which is applied
// to the last infobox prior to wrapping too.
panelComponent.setPreferredSize(new Dimension(DEFAULT_WRAP_COUNT * (config.infoBoxSize() + GAP), DEFAULT_WRAP_COUNT * (config.infoBoxSize() + GAP)));
panelComponent.setOrientation(config.infoBoxVertical()
? ComponentOrientation.VERTICAL
: ComponentOrientation.HORIZONTAL);
panelComponent.setPreferredSize(new Dimension(config.infoBoxSize(), config.infoBoxSize()));

for (InfoBox box : infoBoxes)
{
Expand All @@ -107,6 +113,7 @@ public Dimension render(Graphics2D graphics)
}
infoBoxComponent.setImage(box.getScaledImage());
infoBoxComponent.setTooltip(box.getTooltip());
infoBoxComponent.setPreferredSize(new Dimension(config.infoBoxSize(), config.infoBoxSize()));
panelComponent.getChildren().add(infoBoxComponent);
}

Expand Down

0 comments on commit d881a2f

Please sign in to comment.