1
mirror of https://github.com/Shiewk/Widgets.git synced 2026-04-28 11:34:17 +02:00

Provide maximum recommended width to setting options

This commit is contained in:
Shy
2024-12-06 14:12:48 +01:00
parent 83cc672fd4
commit f2214c6b00
2 changed files with 19 additions and 1 deletions
@@ -14,6 +14,7 @@ public abstract class WidgetSettingOption implements Drawable, Widget {
private final Text name; private final Text name;
private int x = 0; private int x = 0;
private int y = 0; private int y = 0;
private int maxRenderWidth = 200; // this will always be changed before rendering
private boolean focused = false; private boolean focused = false;
private BooleanSupplier shouldShow = WidgetUtils.TRUE_SUPPLIER; private BooleanSupplier shouldShow = WidgetUtils.TRUE_SUPPLIER;
@@ -22,6 +23,14 @@ public abstract class WidgetSettingOption implements Drawable, Widget {
this.name = name; this.name = name;
} }
public void setMaxRenderWidth(int maxRenderWidth) {
this.maxRenderWidth = maxRenderWidth;
}
public int getMaxRenderWidth() {
return maxRenderWidth;
}
public final String getId() { public final String getId() {
return id; return id;
} }
@@ -19,12 +19,21 @@ public class WidgetSettingsEditWidget extends ScrollableWidget {
private int contentsHeight = 10; private int contentsHeight = 10;
public WidgetSettingsEditWidget(int x, int y, int width, int height, TextRenderer textRenderer, ModWidget widget, Runnable onChange) { public WidgetSettingsEditWidget(int x, int y, int width, int height, TextRenderer textRenderer, ModWidget widget, Runnable onChange) {
super(x, y, width, height, Text.empty()); super(x, y, width, height, Text.empty());
this.textRenderer = textRenderer;
this.widget = widget; this.widget = widget;
this.textRenderer = textRenderer;
this.onChange = onChange; this.onChange = onChange;
for (WidgetSettingOption customSetting : widget.getSettings().getCustomSettings()) { for (WidgetSettingOption customSetting : widget.getSettings().getCustomSettings()) {
customSetting.setFocused(false); customSetting.setFocused(false);
} }
setWidth(width);
}
@Override
public void setWidth(int width) {
for (WidgetSettingOption setting : widget.getSettings().getCustomSettings()) {
setting.setMaxRenderWidth(width - 10);
}
super.setWidth(width);
} }
@Override @Override