added a toggle
This commit is contained in:
@@ -0,0 +1,53 @@
|
|||||||
|
package org.saturnclient.ui2.components.inputs;
|
||||||
|
|
||||||
|
import org.saturnclient.saturnclient.config.ConfigManager;
|
||||||
|
import org.saturnclient.saturnclient.config.Property;
|
||||||
|
import org.saturnclient.ui2.resources.Fonts;
|
||||||
|
|
||||||
|
public class IntInput extends Input {
|
||||||
|
public Property<Integer> prop;
|
||||||
|
|
||||||
|
public IntInput(Property<Integer> prop) {
|
||||||
|
this.width = 120;
|
||||||
|
this.height = Fonts.getHeight();
|
||||||
|
this.prop = prop;
|
||||||
|
this.text = String.valueOf(prop.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void charTyped(char chr) {
|
||||||
|
if ((Character.isDigit(chr) || chr == '.') && text.length() < 10) {
|
||||||
|
if (text.equals("0") && cursorPosition == 1) {
|
||||||
|
text = "" + chr;
|
||||||
|
} else {
|
||||||
|
text = text.substring(0, cursorPosition) +
|
||||||
|
chr +
|
||||||
|
text.substring(cursorPosition);
|
||||||
|
|
||||||
|
prop.value = text.isEmpty() ? 0 : Integer.parseInt(text);
|
||||||
|
ConfigManager.save();
|
||||||
|
|
||||||
|
cursorPosition++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void backspace() {
|
||||||
|
if (text.length() == 0) {
|
||||||
|
text = "0";
|
||||||
|
cursorPosition = 1;
|
||||||
|
}
|
||||||
|
prop.value = Integer.parseInt(text);
|
||||||
|
ConfigManager.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void checkReset() {
|
||||||
|
if (prop.isReset) {
|
||||||
|
this.text = String.valueOf(prop.value);
|
||||||
|
this.cursorPosition = 0;
|
||||||
|
prop.isReset = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package org.saturnclient.ui2.components.inputs;
|
||||||
|
|
||||||
|
import org.saturnclient.saturnclient.config.Property;
|
||||||
|
import org.saturnclient.saturnclient.config.ThemeManager;
|
||||||
|
import org.saturnclient.ui2.Element;
|
||||||
|
import org.saturnclient.ui2.ElementContext;
|
||||||
|
import org.saturnclient.ui2.RenderScope;
|
||||||
|
|
||||||
|
public class Toggle extends Element {
|
||||||
|
private static ThemeManager theme = new ThemeManager("Toggle", "hovering", "enabled");
|
||||||
|
private static Property<Integer> bgColor = theme.property("bg-color", new Property<Integer>(0xFF808080));
|
||||||
|
private static Property<Integer> fgColor = theme.property("fg-color", new Property<Integer>(0xFF909090));
|
||||||
|
private static Property<Integer> cornerRadius = theme.property("corner-radius", new Property<Integer>(30));
|
||||||
|
|
||||||
|
static {
|
||||||
|
theme.propertyStateDefault("enabled", "bg-color", 0xaf8B5CF6);
|
||||||
|
theme.propertyStateDefault("enabled", "fg-color", 0xff8B5CF6);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Property<Boolean> prop;
|
||||||
|
|
||||||
|
public Toggle(Property<Boolean> prop) {
|
||||||
|
this.prop = prop;
|
||||||
|
this.width = 60;
|
||||||
|
this.height = 30;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(RenderScope renderScope, ElementContext ctx) {
|
||||||
|
if (prop.value) {
|
||||||
|
theme.setState("enabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctx.isHovering()) {
|
||||||
|
theme.applyState("hovering");
|
||||||
|
}
|
||||||
|
|
||||||
|
renderScope.drawRoundedRectangle(0, 0, width, height, cornerRadius.value, bgColor.value);
|
||||||
|
|
||||||
|
renderScope.drawRoundedRectangle(prop.value ? 30 : 0, 0, 30, 30, 30, fgColor.value);
|
||||||
|
|
||||||
|
theme.setState(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void click(int mouseX, int mouseY) {
|
||||||
|
prop.value = !prop.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user