Skip to content

Commit fff3126

Browse files
authored
Add an opt-in config option to normalise list setting column widths (#5941)
1 parent 54c4fb1 commit fff3126

4 files changed

Lines changed: 35 additions & 3 deletions

File tree

src/main/java/meteordevelopment/meteorclient/gui/screens/settings/base/CollectionListSettingScreen.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import meteordevelopment.meteorclient.gui.widgets.input.WTextBox;
1414
import meteordevelopment.meteorclient.gui.widgets.pressable.WPressable;
1515
import meteordevelopment.meteorclient.settings.Setting;
16+
import meteordevelopment.meteorclient.systems.config.Config;
1617

1718
import java.util.Collection;
1819
import java.util.function.Consumer;
@@ -76,6 +77,7 @@ private void initTable() {
7677
private WTable abc(Iterable<T> iterable, boolean isLeft, Consumer<T> buttonAction) {
7778
// Create
7879
Cell<WTable> cell = this.table.add(theme.table()).top();
80+
if (Config.get().syncListSettingWidths.get()) cell.group("sync-width");
7981
WTable table = cell.widget();
8082

8183
// Sort

src/main/java/meteordevelopment/meteorclient/gui/utils/Cell.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package meteordevelopment.meteorclient.gui.utils;
77

88
import meteordevelopment.meteorclient.gui.widgets.WWidget;
9+
import org.jetbrains.annotations.Nullable;
910

1011
public class Cell<T extends WWidget> {
1112
private final T widget;
@@ -24,6 +25,8 @@ public class Cell<T extends WWidget> {
2425

2526
public boolean expandCellX;
2627

28+
public @Nullable String group;
29+
2730
public Cell(T widget) {
2831
this.widget = widget;
2932
}
@@ -154,6 +157,12 @@ public Cell<T> expandX() {
154157

155158
// Other
156159

160+
/// Makes this cell's width match the largest cell in the group
161+
public Cell<T> group(String group) {
162+
this.group = group;
163+
return this;
164+
}
165+
157166
public void alignWidget() {
158167
if (expandWidgetX) {
159168
widget.x = x;

src/main/java/meteordevelopment/meteorclient/gui/widgets/containers/WTable.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
import meteordevelopment.meteorclient.gui.utils.Cell;
1313
import meteordevelopment.meteorclient.gui.widgets.WWidget;
1414

15-
import java.util.ArrayList;
16-
import java.util.Iterator;
17-
import java.util.List;
15+
import java.util.*;
1816

1917
public class WTable extends WContainer {
2018
public double horizontalSpacing = 3;
@@ -160,6 +158,8 @@ private void calculateInfo() {
160158
columnWidths.clear();
161159
rowExpandCellXCounts.clear();
162160

161+
Map<String, IntList> columnGroups = new HashMap<>();
162+
163163
// Loop over rows
164164
for (List<Cell<?>> row : rows) {
165165
double rowHeight = 0;
@@ -177,6 +177,8 @@ private void calculateInfo() {
177177
if (columnWidths.size() <= i) columnWidths.add(cellWidth);
178178
else columnWidths.set(i, Math.max(columnWidths.getDouble(i), cellWidth));
179179

180+
if (cell.group != null) columnGroups.computeIfAbsent(cell.group, k -> new IntArrayList()).add(i);
181+
180182
// Calculate row expandX count
181183
if (cell.expandCellX) rowExpandXCount++;
182184
}
@@ -185,5 +187,17 @@ private void calculateInfo() {
185187
rowHeights.add(rowHeight);
186188
rowExpandCellXCounts.add(rowExpandXCount);
187189
}
190+
191+
// Normalize group widths
192+
columnGroups.values().forEach(columns -> {
193+
double maxWidth = Integer.MIN_VALUE;
194+
for (int i : columns) {
195+
maxWidth = Math.max(maxWidth, columnWidths.getDouble(i));
196+
}
197+
198+
for (int i : columns) {
199+
columnWidths.set(i, maxWidth);
200+
}
201+
});
188202
}
189203
}

src/main/java/meteordevelopment/meteorclient/systems/config/Config.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ public class Config extends System<Config> {
9696
.build()
9797
);
9898

99+
public final Setting<Boolean> syncListSettingWidths = sgVisual.add(new BoolSetting.Builder()
100+
.name("sync-list-setting-widths")
101+
.description("Prevents the list setting screens from moving around as you add & remove elements.")
102+
.defaultValue(false)
103+
.build()
104+
);
105+
99106
// Modules
100107

101108
public final Setting<List<Module>> hiddenModules = sgModules.add(new ModuleListSetting.Builder()

0 commit comments

Comments
 (0)