-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathButtonLayout.java
More file actions
65 lines (50 loc) · 1.61 KB
/
ButtonLayout.java
File metadata and controls
65 lines (50 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package dev.ryanland.colossus.sys.interactions.button;
import net.dv8tion.jda.api.components.actionrow.ActionRow;
import net.dv8tion.jda.api.components.buttons.Button;
import java.util.ArrayList;
import java.util.List;
/**
* Collection of {@link ButtonRow ButtonRows} with additional helper methods.
*/
public class ButtonLayout {
public ButtonLayout(ButtonRow... rows) {
add(rows);
}
private List<ButtonRow> rows = new ArrayList<>(5);
public List<ButtonRow> getRows() {
return rows;
}
public ButtonLayout add(ButtonRow... rows) {
this.rows.addAll(List.of(rows));
return this;
}
public ButtonLayout add(int index, ButtonRow row) {
rows.add(index, row);
return this;
}
public ButtonLayout addButton(int rowIndex, BaseButton... buttons) {
rows.get(rowIndex).add(buttons);
return this;
}
public ButtonLayout insertButton(int rowIndex, int buttonIndex, BaseButton button) {
rows.get(rowIndex).add(buttonIndex, button);
return this;
}
public int size() {
return rows.size();
}
public ButtonRow get(int index) {
return rows.get(index);
}
public List<ActionRow> toActionRows() {
return rows.stream().map(ButtonRow::toActionRow).toList();
}
public List<BaseButton> getBaseButtons() {
List<BaseButton> buttons = new ArrayList<>();
rows.forEach(row -> buttons.addAll(row.getButtons()));
return buttons;
}
public List<Button> getButtons() {
return getBaseButtons().stream().map(BaseButton::button).toList();
}
}