75 lines
2.5 KiB
Java
75 lines
2.5 KiB
Java
package io.gitlab.jfronny.inceptum.gtk.control;
|
|
|
|
import io.gitlab.jfronny.inceptum.gtk.util.I18n;
|
|
import org.gtk.gtk.*;
|
|
import org.jetbrains.annotations.Nullable;
|
|
import org.jetbrains.annotations.PropertyKey;
|
|
|
|
import java.util.function.Consumer;
|
|
import java.util.function.IntConsumer;
|
|
|
|
public class IRow extends Box {
|
|
public IRow(@PropertyKey(resourceBundle = I18n.BUNDLE) String title, @PropertyKey(resourceBundle = I18n.BUNDLE) @Nullable String subtitle, Object... args) {
|
|
super(Orientation.HORIZONTAL, 40);
|
|
margin = 8;
|
|
Widget head;
|
|
ILabel lab = new ILabel(title, args);
|
|
lab.halign = Align.START;
|
|
if (subtitle != null) {
|
|
Box headB = new Box(Orientation.VERTICAL, 0);
|
|
headB.append(lab);
|
|
ILabel lab1 = new ILabel(subtitle, ILabel.Mode.SUBTITLE, args);
|
|
lab1.halign = Align.START;
|
|
headB.append(lab1);
|
|
head = headB;
|
|
} else {
|
|
head = lab;
|
|
}
|
|
head.halign = Align.START;
|
|
head.valign = Align.CENTER;
|
|
append(head);
|
|
}
|
|
|
|
public void setButton(@PropertyKey(resourceBundle = I18n.BUNDLE) String text, Button.Clicked action) {
|
|
firstChild.hexpand = true;
|
|
Button btn = Button.newWithLabel(I18n.get(text));
|
|
btn.valign = Align.CENTER;
|
|
btn.halign = Align.END;
|
|
btn.onClicked(action);
|
|
append(btn);
|
|
}
|
|
|
|
public void setDropdown(String[] options, int defaultIndex, IntConsumer changed) {
|
|
firstChild.hexpand = true;
|
|
DropDown btn = DropDown.newFromStrings(options);
|
|
btn.valign = Align.CENTER;
|
|
btn.halign = Align.END;
|
|
btn.selected = defaultIndex;
|
|
btn.onNotify("selected", pspec -> {
|
|
changed.accept(btn.selected);
|
|
});
|
|
append(btn);
|
|
}
|
|
|
|
public void setCheckbox(@PropertyKey(resourceBundle = I18n.BUNDLE) String text, boolean value, Consumer<Boolean> changed) {
|
|
firstChild.hexpand = true;
|
|
CheckButton btn = CheckButton.newWithLabel(I18n.get(text));
|
|
btn.valign = Align.CENTER;
|
|
btn.halign = Align.END;
|
|
btn.active = value;
|
|
btn.onToggled(() -> changed.accept(btn.active));
|
|
append(btn);
|
|
}
|
|
|
|
public Entry setEntry(String value, Consumer<String> onChanged) {
|
|
Entry entry = new Entry();
|
|
entry.text = value;
|
|
entry.hexpand = true;
|
|
entry.valign = Align.CENTER;
|
|
entry.halign = Align.FILL;
|
|
entry.onChanged(() -> onChanged.accept(entry.text));
|
|
append(entry);
|
|
return entry;
|
|
}
|
|
}
|