GTK: Support search in IRow dropdown
ci/woodpecker/push/docs Pipeline was successful Details
ci/woodpecker/push/woodpecker Pipeline was successful Details

This commit is contained in:
Johannes Frohnmeyer 2023-01-29 11:16:18 +01:00
parent fe0c23b97b
commit 5c9ce78ebf
Signed by: Johannes
GPG Key ID: E76429612C2929F4
5 changed files with 13 additions and 57 deletions

View File

@ -1,49 +0,0 @@
package io.gitlab.jfronny.inceptum.gtk.control;
import io.gitlab.jfronny.commons.throwable.ThrowingRunnable;
import io.gitlab.jfronny.inceptum.gtk.menu.MenuBuilder;
import org.gtk.gtk.MenuButton;
import java.util.LinkedList;
import java.util.List;
import java.util.function.*;
public class Dropdown<T> extends MenuButton {
private final T[] source;
private final List<Consumer<T>> onChange = new LinkedList<>();
private int selected;
public Dropdown(T[] source, int def, Function<T, String> stringify) {
this.source = source;
MenuBuilder builder = MenuBuilder.create(this, "nil");
this.selected = def;
for (int i = 0; i < source.length; i++) {
String n = stringify.apply(source[i]);
if (def == i) label = n;
builder.literalButton("" + i, n, new LB(i, n));
}
}
public void onChanged(Consumer<T> action) {
onChange.add(action);
}
private class LB implements ThrowingRunnable<RuntimeException> {
private final int i;
private final String n;
public LB(int i, String n) {
this.i = i;
this.n = n;
}
@Override
public void run() throws RuntimeException {
if (selected != i) {
selected = i;
for (Consumer<T> action : onChange) action.accept(source[i]);
Dropdown.this.label = n;
}
}
}
}

View File

@ -48,17 +48,21 @@ public class IRow extends Box {
btn.onNotify("selected", pspec -> {
changed.accept(btn.selected);
});
btn.expression = new PropertyExpression(StringObject.type, null, "string");
append(btn);
return btn;
}
public CheckButton setCheckbox(@PropertyKey(resourceBundle = I18n.BUNDLE) String text, boolean value, Consumer<Boolean> changed) {
public Switch setCheckbox(boolean value, Consumer<Boolean> changed) {
firstChild.hexpand = true;
CheckButton btn = CheckButton.newWithLabel(I18n.get(text));
Switch btn = new Switch();
btn.valign = Align.CENTER;
btn.halign = Align.END;
btn.active = value;
btn.onToggled(() -> changed.accept(btn.active));
btn.onStateSet(state -> {
changed.accept(state);
return false;
});
append(btn);
return btn;
}

View File

@ -23,7 +23,7 @@ public class LauncherSettingsWindow extends Window {
{
IRow row = new IRow("settings.snapshots", "settings.snapshots.subtitle");
listBox.append(row);
row.setCheckbox("settings.snapshots", InceptumConfig.snapshots, b -> {
row.setCheckbox(InceptumConfig.snapshots, b -> {
InceptumConfig.snapshots = b;
InceptumConfig.saveConfig();
});

View File

@ -52,7 +52,7 @@ public class GeneralTab extends SettingsTab {
section("instance.settings.general.game", section -> {
{
var ref = new Object() {
CheckButton fabricEnabled = null;
Switch fabricEnabled = null;
Runnable versionChanged = null;
DropDown fabricVersion = null;
String defaultFabric = null;
@ -74,11 +74,11 @@ public class GeneralTab extends SettingsTab {
: versions[i];
instance.writeMeta();
ref.versionChanged.run();
});
}).enableSearch = true;
var fabricRow = section.row("instance.settings.general.game.fabric.enabled", "instance.settings.general.game.fabric.enabled.subtitle");
var loaderRow = section.row("instance.settings.general.game.fabric.version", "instance.settings.general.game.fabric.version.subtitle");
loaderRow.visible = instance.isFabric;
ref.fabricEnabled = fabricRow.setCheckbox("instance.settings.general.game.fabric.enabled", instance.isFabric, bl -> {
ref.fabricEnabled = fabricRow.setCheckbox(instance.isFabric, bl -> {
if (bl) {
if (ref.fabricVersions != null && ref.fabricVersions.length != 0 && ref.defaultFabric != null) {
instance.meta.gameVersion = GameVersionParser.createVersionWithFabric(instance.gameVersion, ref.defaultFabric);
@ -116,6 +116,7 @@ public class GeneralTab extends SettingsTab {
instance.meta.gameVersion = i == -1 ? instance.gameVersion : GameVersionParser.createVersionWithFabric(instance.gameVersion, ref.fabricVersions[i]);
instance.writeMeta();
});
ref.fabricVersion.enableSearch = true;
}
{
var row = section.row("instance.settings.general.game.java", "instance.settings.general.game.java.subtitle");

View File

@ -9,7 +9,7 @@ menu.account.new=New
menu.file=File
menu.file.exit=Exit
menu.file.new=New Instance
menu.file.redownload=Re-download resources
menu.file.redownload=Re-Download Resources
menu.help=Help
menu.help.about=About
menu.help.log=Log