Wrap the theme presets onto more rows when the cards get too narrow

With five presets, the cards at a larger menu scale were narrower than
the widgets in their previews.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-03 06:11:48 +02:00
co-authored by claude
parent 917eba1e17
commit fd9ec3222c
2 changed files with 10 additions and 3 deletions
@@ -12,6 +12,8 @@ import org.saturnclient.ui.resources.Fonts;
*/ */
public class ThemePresetCard extends Element { public class ThemePresetCard extends Element {
public static final int HEIGHT = 92; public static final int HEIGHT = 92;
/** The narrowest card that still fits its preview's widgets */
public static final int MIN_WIDTH = 100;
private static final int PADDING = 10; private static final int PADDING = 10;
private static final int PREVIEW_HEIGHT = 44; private static final int PREVIEW_HEIGHT = 44;
@@ -102,15 +102,20 @@ public class ClientSettings extends PanelScreen {
Map<String, Property> properties = Theme.config.getProperties(); Map<String, Property> properties = Theme.config.getProperties();
int y = PropertyList.drawSection(scroll, "Presets", 0) + 10; int y = PropertyList.drawSection(scroll, "Presets", 0) + 10;
int cardWidth = (width - PRESET_GAP * (Theme.PRESETS.size() - 1)) / Theme.PRESETS.size(); // One row when the cards fit, otherwise as many rows as they need
int columns = Math.max(1, Math.min(Theme.PRESETS.size(),
(width + PRESET_GAP) / (ThemePresetCard.MIN_WIDTH + PRESET_GAP)));
int rows = (Theme.PRESETS.size() + columns - 1) / columns;
int cardWidth = (width - PRESET_GAP * (columns - 1)) / columns;
for (int i = 0; i < Theme.PRESETS.size(); i++) { for (int i = 0; i < Theme.PRESETS.size(); i++) {
// Rebuild so the color inputs show the preset's colors // Rebuild so the color inputs show the preset's colors
scroll.draw(new ThemePresetCard(Theme.PRESETS.get(i), cardWidth, this::init) scroll.draw(new ThemePresetCard(Theme.PRESETS.get(i), cardWidth, this::init)
.position(i * (cardWidth + PRESET_GAP), y)); .position(i % columns * (cardWidth + PRESET_GAP),
y + i / columns * (ThemePresetCard.HEIGHT + PRESET_GAP)));
} }
y += ThemePresetCard.HEIGHT + SECTION_GAP; y += rows * ThemePresetCard.HEIGHT + (rows - 1) * PRESET_GAP + SECTION_GAP;
y = PropertyList.drawSection(scroll, "Colors", y) + 10; y = PropertyList.drawSection(scroll, "Colors", y) + 10;
y = ColorGrid.draw(scroll, properties, width, y) + SECTION_GAP; y = ColorGrid.draw(scroll, properties, width, y) + SECTION_GAP;