Make overlay resizing configure wrapping
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 <slusnucky@gmail.com>
This commit is contained in:
@@ -266,17 +266,6 @@ public interface RuneLiteConfig extends Config
|
||||
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",
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -56,8 +56,8 @@ public class TeamCapesOverlay extends Overlay
|
||||
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"));
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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(
|
||||
@@ -111,11 +112,23 @@ public class PanelComponent implements LayoutableRenderableEntity
|
||||
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)
|
||||
@@ -136,28 +149,38 @@ public class PanelComponent implements LayoutableRenderableEntity
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,9 @@ import net.runelite.client.ui.overlay.tooltip.TooltipManager;
|
||||
@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;
|
||||
@@ -67,9 +70,10 @@ public class InfoBoxOverlay extends Overlay
|
||||
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
|
||||
@@ -83,11 +87,13 @@ public class InfoBoxOverlay extends Overlay
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -107,6 +113,7 @@ public class InfoBoxOverlay extends Overlay
|
||||
}
|
||||
infoBoxComponent.setImage(box.getScaledImage());
|
||||
infoBoxComponent.setTooltip(box.getTooltip());
|
||||
infoBoxComponent.setPreferredSize(new Dimension(config.infoBoxSize(), config.infoBoxSize()));
|
||||
panelComponent.getChildren().add(infoBoxComponent);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user