Search in sources :

Example 1 with WPressable

use of mathax.client.gui.widgets.pressable.WPressable in project Client by MatHax.

the class LeftRightListSettingScreen method abc.

private WTable abc(Consumer<List<Pair<T, Integer>>> addValues, boolean isLeft, Consumer<T> buttonAction) {
    // Create
    Cell<WTable> cell = this.table.add(theme.table()).top();
    WTable table = cell.widget();
    Consumer<T> forEach = t -> {
        if (!includeValue(t))
            return;
        table.add(getValueWidget(t));
        WPressable button = table.add(isLeft ? theme.plus() : theme.minus()).expandCellX().right().widget();
        button.action = () -> buttonAction.accept(t);
        table.row();
    };
    // Sort
    List<Pair<T, Integer>> values = new ArrayList<>();
    addValues.accept(values);
    if (!filterText.isEmpty())
        values.sort(Comparator.comparingInt(value -> -value.getRight()));
    for (Pair<T, Integer> pair : values) forEach.accept(pair.getLeft());
    if (table.cells.size() > 0)
        cell.expandX();
    return table;
}
Also used : Utils(mathax.client.utils.Utils) Pair(net.minecraft.util.Pair) GuiTheme(mathax.client.gui.GuiTheme) Collection(java.util.Collection) Registry(net.minecraft.util.registry.Registry) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) Cell(mathax.client.gui.utils.Cell) WTable(mathax.client.gui.widgets.containers.WTable) List(java.util.List) Setting(mathax.client.settings.Setting) WTextBox(mathax.client.gui.widgets.input.WTextBox) WPressable(mathax.client.gui.widgets.pressable.WPressable) Comparator(java.util.Comparator) WindowScreen(mathax.client.gui.WindowScreen) WWidget(mathax.client.gui.widgets.WWidget) WPressable(mathax.client.gui.widgets.pressable.WPressable) WTable(mathax.client.gui.widgets.containers.WTable) ArrayList(java.util.ArrayList) Pair(net.minecraft.util.Pair)

Aggregations

ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Consumer (java.util.function.Consumer)1 GuiTheme (mathax.client.gui.GuiTheme)1 WindowScreen (mathax.client.gui.WindowScreen)1 Cell (mathax.client.gui.utils.Cell)1 WWidget (mathax.client.gui.widgets.WWidget)1 WTable (mathax.client.gui.widgets.containers.WTable)1 WTextBox (mathax.client.gui.widgets.input.WTextBox)1 WPressable (mathax.client.gui.widgets.pressable.WPressable)1 Setting (mathax.client.settings.Setting)1 Utils (mathax.client.utils.Utils)1 Pair (net.minecraft.util.Pair)1 Registry (net.minecraft.util.registry.Registry)1