Toggle
This commit is contained in:
@@ -1,22 +1,12 @@
|
|||||||
package org.saturnclient.ui2.components.inputs;
|
package org.saturnclient.ui2.components.inputs;
|
||||||
|
|
||||||
import org.saturnclient.saturnclient.config.Property;
|
import org.saturnclient.saturnclient.config.Property;
|
||||||
import org.saturnclient.saturnclient.config.ThemeManager;
|
import org.saturnclient.saturnclient.config.Theme;
|
||||||
import org.saturnclient.ui2.Element;
|
import org.saturnclient.ui2.Element;
|
||||||
import org.saturnclient.ui2.ElementContext;
|
import org.saturnclient.ui2.ElementContext;
|
||||||
import org.saturnclient.ui2.RenderScope;
|
import org.saturnclient.ui2.RenderScope;
|
||||||
|
|
||||||
public class Toggle extends Element {
|
public class Toggle extends Element {
|
||||||
private static ThemeManager theme = new ThemeManager("Toggle", "hovering", "enabled");
|
|
||||||
private static Property<Integer> bgColor = theme.property("bg-color", Property.color(0xFF808080));
|
|
||||||
private static Property<Integer> fgColor = theme.property("fg-color", Property.color(0xFF909090));
|
|
||||||
private static Property<Integer> cornerRadius = theme.property("corner-radius", Property.integer(30));
|
|
||||||
|
|
||||||
static {
|
|
||||||
theme.propertyStateDefault("enabled", "bg-color", 0xaf8B5CF6);
|
|
||||||
theme.propertyStateDefault("enabled", "fg-color", 0xff8B5CF6);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Property<Boolean> prop;
|
private Property<Boolean> prop;
|
||||||
|
|
||||||
public Toggle(Property<Boolean> prop) {
|
public Toggle(Property<Boolean> prop) {
|
||||||
@@ -27,19 +17,10 @@ public class Toggle extends Element {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(RenderScope renderScope, ElementContext ctx) {
|
public void render(RenderScope renderScope, ElementContext ctx) {
|
||||||
theme.setState(null);
|
renderScope.drawRoundedRectangle(0, 0, width, height, height,
|
||||||
|
prop.value ? Theme.ACCENT.value : Theme.PRIMARY.value);
|
||||||
if (prop.value) {
|
renderScope.drawRoundedRectangle(prop.value ? 30 : 0, 0, 30, 30, 30,
|
||||||
theme.setState("enabled");
|
prop.value ? Theme.ACCENT.value : Theme.PRIMARY.value);
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user