package org.saturnclient.ui.elements; import org.saturnclient.config.Theme; import org.saturnclient.ui.RenderScope; import org.saturnclient.ui.resources.Fonts; /** * The shared look of input fields: a faint box whose outline brightens on hover * and turns to the accent color while focused. */ public final class Field { /** Height of the fields in settings rows */ public static final int HEIGHT = 32; public static final float TEXT_SCALE = 0.68f; private Field() { } public static void drawBox(RenderScope renderScope, int width, int height, boolean hovered, boolean focused) { int border = focused ? Theme.withAlpha(0.6f, Theme.ACCENT.value) : hovered ? Theme.withAlpha(0.25f, Theme.FOREGROUND.value) : Theme.withAlpha(0.1f, Theme.FOREGROUND.value); renderScope.drawRoundedRectangle(0, 0, width, height, Theme.WIDGET_RADIUS.value, 1, Theme.withAlpha(0.06f, Theme.FOREGROUND.value), border); } /** * The y at which text drawn at {@code scale} is vertically centered in a * field of the given height. */ public static int textY(int height, float scale) { return (height - (int) (Fonts.getHeight() * scale)) / 2; } /** * Draws {@code text} centered in a field of the given size. */ public static void drawCenteredText(RenderScope renderScope, String text, int width, int height, int font, int color) { int x = (width - (int) (Fonts.getWidth(text, font) * TEXT_SCALE)) / 2; renderScope.drawText(TEXT_SCALE, text, x, textY(height, TEXT_SCALE), font, color); } }