From 289a2cd78a9ebee51eb8661937b1756236450966 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Sat, 21 Feb 2026 18:44:24 +0100 Subject: [PATCH] Button --- .../org/saturnclient/ui2/elements/Button.java | 27 +++++-------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/saturnclient/ui2/elements/Button.java b/src/main/java/org/saturnclient/ui2/elements/Button.java index 0b74643..73a1a1c 100644 --- a/src/main/java/org/saturnclient/ui2/elements/Button.java +++ b/src/main/java/org/saturnclient/ui2/elements/Button.java @@ -1,43 +1,28 @@ package org.saturnclient.ui2.elements; -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.ElementContext; import org.saturnclient.ui2.RenderScope; import org.saturnclient.ui2.resources.Fonts; public class Button extends Element { - private static ThemeManager theme = new ThemeManager("Button", "hovering"); - private static Property bgColor = theme.property("bg-color", Property.color(0xFF000000)); - private static Property fgColor = theme.property("fg-color", Property.color(0xFFFFFFFF)); - private static Property cornerRadius = theme.property("corner-radius", Property.integer(10)); - private static Property font = theme.property("font", Property.font(1)); - - static { - theme.propertyStateDefault("hovering", "fg-color", 0xFF845eee); - } - private String text; private Runnable onClick; public Button(String text, Runnable onClick) { this.text = text; this.onClick = onClick; - this.dimensions(Fonts.getWidth(text, font.value) + 50, 38); } @Override public void render(RenderScope renderScope, ElementContext ctx) { - if (ctx.isHovering()) { - theme.setState("hovering"); - } else { - theme.setState(null); - } - renderScope.drawRoundedRectangle(0, 0, width, height, cornerRadius.value, bgColor.value); + renderScope.drawRoundedRectangle(0, 0, width, height, Theme.WIDGET_RADIUS.value, + ctx.isHovering() ? Theme.ACCENT.value : Theme.PRIMARY.value); - // renderScope.drawText(text, (width - Fonts.getWidth(text, font)) / 2, (height - Fonts.getHeight()) / 2, bold.value, fgColor.value); - renderScope.drawText(text, Fonts.centerX(width, text, font.value), Fonts.centerY(height), font.value, fgColor.value); + renderScope.drawText(text, Fonts.centerX(width, text, Theme.FONT.value), Fonts.centerY(height), + Theme.FONT.value, + ctx.isHovering() ? Theme.ACCENT_FG.value : Theme.PRIMARY_FG.value); } @Override