Skip to content

Commit c5e1089

Browse files
committed
Keep add buttons visible when adding list elements
1 parent 5e7804d commit c5e1089

File tree

5 files changed

+57
-29
lines changed

5 files changed

+57
-29
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Added option to revert config changes on exit (no change to exiting via ESC)
88
- Moved key selector button to adjacent trigger type button
99
- Added filter fields for notification and trigger lists
10+
- Fixed lists not auto-scrolling when adding new fields
1011

1112
## 2.3.8
1213

common/src/main/java/dev/terminalmc/chatnotify/gui/widget/list/AdvancedOptionList.java

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
*/
4949
public class AdvancedOptionList extends DragReorderList {
5050
private final Notification notif;
51+
private OptionList.Entry.ActionButtonEntry addExclTrigEntry;
52+
private OptionList.Entry.ActionButtonEntry addRespMsgEntry;
5153

5254
public AdvancedOptionList(Minecraft mc, int width, int height, int y, int entryWidth,
5355
int entryHeight, int entrySpacing, Notification notif) {
@@ -57,6 +59,22 @@ public AdvancedOptionList(Minecraft mc, int width, int height, int y, int entryW
5759
Entry.ResponseFieldEntry.class, notif::moveResponseMessage
5860
)));
5961
this.notif = notif;
62+
63+
addExclTrigEntry = new OptionList.Entry.ActionButtonEntry(
64+
entryX, entryWidth, entryHeight, Component.literal("+"), null, -1,
65+
(button) -> {
66+
notif.exclusionTriggers.add(new Trigger());
67+
init();
68+
ensureVisible(addExclTrigEntry);
69+
});
70+
71+
addRespMsgEntry = new OptionList.Entry.ActionButtonEntry(
72+
entryX, entryWidth, entryHeight, Component.literal("+"), null, -1,
73+
(button) -> {
74+
notif.responseMessages.add(new ResponseMessage());
75+
init();
76+
ensureVisible(addRespMsgEntry);
77+
});
6078
}
6179

6280
@Override
@@ -107,12 +125,8 @@ protected void addEntries() {
107125
addEntry(new Entry.ExclusionFieldEntry(dynEntryX, dynEntryWidth, entryHeight,
108126
this, notif, notif.exclusionTriggers.get(i), i));
109127
}
110-
addEntry(new OptionList.Entry.ActionButtonEntry(entryX, entryWidth, entryHeight,
111-
Component.literal("+"), null, -1,
112-
(button) -> {
113-
notif.exclusionTriggers.add(new Trigger());
114-
init();
115-
}));
128+
addExclTrigEntry.setBounds(entryX, entryWidth, entryHeight);
129+
addEntry(addExclTrigEntry);
116130
}
117131

118132
addEntry(new OptionList.Entry.TextEntry(entryX, entryWidth, entryHeight,
@@ -130,12 +144,8 @@ protected void addEntries() {
130144
addEntry(e);
131145
addEntry(new SpaceEntry(e));
132146
}
133-
addEntry(new OptionList.Entry.ActionButtonEntry(entryX, entryWidth, entryHeight,
134-
Component.literal("+"), null, -1,
135-
(button) -> {
136-
notif.responseMessages.add(new ResponseMessage());
137-
init();
138-
}));
147+
addRespMsgEntry.setBounds(entryX, entryWidth, entryHeight);
148+
addEntry(addRespMsgEntry);
139149
}
140150

141151
addEntry(new OptionList.Entry.TextEntry(entryX, entryWidth, entryHeight,

common/src/main/java/dev/terminalmc/chatnotify/gui/widget/list/MainOptionList.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,23 @@
5454
public class MainOptionList extends DragReorderList {
5555
private String filterString = "";
5656
private @Nullable Pattern filterPattern = null;
57+
private OptionList.Entry.ActionButtonEntry addNotifEntry;
5758

5859
public MainOptionList(Minecraft mc, int width, int height, int y, int entryWidth,
5960
int entryHeight, int entrySpacing) {
6061
super(mc, width, height, y, entryWidth, entryHeight, entrySpacing, () -> {},
6162
new HashMap<>(Map.of(Entry.NotifConfigEntry.class, (source, dest) ->
6263
Config.get().changeNotifPriority(++source, ++dest))));
64+
65+
addNotifEntry = new OptionList.Entry.ActionButtonEntry(
66+
entryX, entryWidth, entryHeight, Component.literal("+"), null, -1,
67+
(button) -> {
68+
Config.get().addNotif();
69+
filterString = "";
70+
filterPattern = null;
71+
init();
72+
ensureVisible(addNotifEntry);
73+
});
6374
}
6475

6576
@Override
@@ -71,14 +82,8 @@ protected void addEntries() {
7182
addEntry(new Entry.TitleAndSearchEntry(entryX, entryWidth, entryHeight, this));
7283

7384
refreshNotifSubList();
74-
addEntry(new OptionList.Entry.ActionButtonEntry(entryX, entryWidth, entryHeight,
75-
Component.literal("+"), null, -1,
76-
(button) -> {
77-
Config.get().addNotif();
78-
filterString = "";
79-
filterPattern = null;
80-
init();
81-
}));
85+
addNotifEntry.setBounds(entryX, entryWidth, entryHeight);
86+
addEntry(addNotifEntry);
8287
}
8388

8489
protected void refreshNotifSubList() {

common/src/main/java/dev/terminalmc/chatnotify/gui/widget/list/NotifOptionList.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class NotifOptionList extends DragReorderList {
4848
private final Notification notif;
4949
private String filterString = "";
5050
private @Nullable Pattern filterPattern = null;
51+
private OptionList.Entry.ActionButtonEntry addTriggerEntry;
5152

5253
public NotifOptionList(Minecraft mc, int width, int height, int y, int entryWidth,
5354
int entryHeight, int entrySpacing, Notification notif) {
@@ -57,21 +58,25 @@ public NotifOptionList(Minecraft mc, int width, int height, int y, int entryWidt
5758
moveTrigger(notif, source, dest))));
5859
this.notif = notif;
5960
notif.editing = true;
61+
62+
addTriggerEntry = new OptionList.Entry.ActionButtonEntry(
63+
entryX, entryWidth, entryHeight, Component.literal("+"), null, -1,
64+
(button) -> {
65+
notif.triggers.add(new Trigger());
66+
filterString = "";
67+
filterPattern = null;
68+
init();
69+
ensureVisible(addTriggerEntry);
70+
});
6071
}
6172

6273
@Override
6374
protected void addEntries() {
6475
addEntry(new Entry.TitleAndSearchEntry(entryX, entryWidth, entryHeight, this));
6576

6677
refreshTriggerSubList();
67-
addEntry(new OptionList.Entry.ActionButtonEntry(entryX, entryWidth, entryHeight,
68-
Component.literal("+"), null, -1,
69-
(button) -> {
70-
notif.triggers.add(new Trigger());
71-
filterString = "";
72-
filterPattern = null;
73-
init();
74-
}));
78+
addTriggerEntry.setBounds(entryX, entryWidth, entryHeight);
79+
addEntry(addTriggerEntry);
7580

7681
addEntry(new OptionList.Entry.TextEntry(entryX, entryWidth, entryHeight,
7782
localized("option", "notif"), null, -1));

common/src/main/java/dev/terminalmc/chatnotify/gui/widget/list/OptionList.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,14 @@ public TextEntry(int x, int width, int height, Component message,
227227
}
228228

229229
public static class ActionButtonEntry extends Entry {
230+
private final Button button;
231+
230232
public ActionButtonEntry(int x, int width, int height, Component message,
231233
@Nullable Tooltip tooltip, int tooltipDelay,
232234
Button.OnPress onPress) {
233235
super();
234236

235-
Button button = Button.builder(message, onPress)
237+
button = Button.builder(message, onPress)
236238
.pos(x, 0)
237239
.size(width, height)
238240
.build();
@@ -241,6 +243,11 @@ public ActionButtonEntry(int x, int width, int height, Component message,
241243

242244
elements.add(button);
243245
}
246+
247+
public void setBounds(int x, int width, int height) {
248+
button.setPosition(x, 0);
249+
button.setSize(width, height);
250+
}
244251
}
245252

246253
public static class SilentActionButtonEntry extends Entry {

0 commit comments

Comments
 (0)