Use one button style and an icon-only dock
Buttons no longer have a primary style: every button is the translucent outlined surface that brightens on hover, and only an icon button's icon takes the accent color. The title screen's dock shows just its icons. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -7,32 +7,27 @@ import org.saturnclient.config.Theme;
|
||||
import org.saturnclient.ui.Element;
|
||||
import org.saturnclient.ui.ElementContext;
|
||||
import org.saturnclient.ui.RenderScope;
|
||||
import org.saturnclient.ui.elements.Field;
|
||||
import org.saturnclient.ui.resources.Fonts;
|
||||
|
||||
/**
|
||||
* A glass bar of buttons, each an icon with its label.
|
||||
* A glass bar of square icon buttons.
|
||||
*/
|
||||
public class Dock extends Element {
|
||||
public record Item(IdentifierRef icon, String label, Runnable onClick) {
|
||||
public record Item(IdentifierRef icon, Runnable onClick) {
|
||||
}
|
||||
|
||||
public static final int HEIGHT = 52;
|
||||
|
||||
private static final int PADDING = 6;
|
||||
private static final int ITEM_HEIGHT = HEIGHT - PADDING * 2;
|
||||
private static final int ITEM_PADDING = 14;
|
||||
private static final int ICON = 17;
|
||||
private static final int ICON_GAP = 8;
|
||||
private static final int ITEM = HEIGHT - PADDING * 2;
|
||||
private static final int ICON = 18;
|
||||
private static final int GAP = 4;
|
||||
private static final float TEXT_SCALE = 0.7f;
|
||||
|
||||
private final List<Item> items;
|
||||
|
||||
public Dock(List<Item> items) {
|
||||
this.items = items;
|
||||
this.height = HEIGHT;
|
||||
this.width = getItemX(items.size()) - GAP + PADDING;
|
||||
this.width = PADDING * 2 + items.size() * ITEM + (items.size() - 1) * GAP;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -41,22 +36,17 @@ public class Dock extends Element {
|
||||
Theme.withAlpha(0.1f, Theme.FOREGROUND.value));
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
Item item = items.get(i);
|
||||
int x = getItemX(i);
|
||||
int itemWidth = getItemWidth(item);
|
||||
boolean hovered = ctx.isHovering(x, PADDING, itemWidth, ITEM_HEIGHT);
|
||||
boolean hovered = ctx.isHovering(x, PADDING, ITEM, ITEM);
|
||||
|
||||
if (hovered) {
|
||||
renderScope.drawRoundedRectangle(x, PADDING, itemWidth, ITEM_HEIGHT, Theme.WIDGET_RADIUS.value,
|
||||
renderScope.drawRoundedRectangle(x, PADDING, ITEM, ITEM, Theme.WIDGET_RADIUS.value,
|
||||
Theme.withAlpha(0.08f, Theme.FOREGROUND.value));
|
||||
}
|
||||
|
||||
int color = hovered ? Theme.ACCENT.value : Theme.PRIMARY_FG.value;
|
||||
renderScope.drawTexture(item.icon(), x + ITEM_PADDING, PADDING + (ITEM_HEIGHT - ICON) / 2, 0, 0, ICON,
|
||||
ICON, color);
|
||||
renderScope.drawText(TEXT_SCALE, item.label(), x + ITEM_PADDING + ICON + ICON_GAP,
|
||||
PADDING + Field.textY(ITEM_HEIGHT, TEXT_SCALE), Theme.FONT.value,
|
||||
hovered ? Theme.FOREGROUND.value : Theme.PRIMARY_FG.value);
|
||||
int offset = (ITEM - ICON) / 2;
|
||||
renderScope.drawTexture(items.get(i).icon(), x + offset, PADDING + offset, 0, 0, ICON, ICON,
|
||||
hovered ? Theme.ACCENT.value : Theme.PRIMARY_FG.value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,22 +54,14 @@ public class Dock extends Element {
|
||||
public void click(int mouseX, int mouseY) {
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
int x = getItemX(i);
|
||||
if (mouseX >= x && mouseX <= x + getItemWidth(items.get(i))) {
|
||||
if (mouseX >= x && mouseX <= x + ITEM) {
|
||||
items.get(i).onClick().run();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getItemX(int index) {
|
||||
int x = PADDING;
|
||||
for (int i = 0; i < index; i++) {
|
||||
x += getItemWidth(items.get(i)) + GAP;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
private static int getItemWidth(Item item) {
|
||||
return ITEM_PADDING * 2 + ICON + ICON_GAP + (int) (Fonts.getWidth(item.label(), Theme.FONT.value) * TEXT_SCALE);
|
||||
private static int getItemX(int index) {
|
||||
return PADDING + index * (ITEM + GAP);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user