Files
common/src/main/java/org/saturnclient/ui/PanelScreen.java
T
selimaj-devandclaude 351507d60d Fix scrolling and keep lists clear of the scrollbar
Scroll kept its position as an int, so wheel and trackpad deltas were
truncated: small ones were lost in one direction and a wheel notch moved
one unit. It now keeps a fractional position, scrolls 24 units a notch,
sizes and places its thumb consistently, and the thumb can be dragged or
the track clicked. PanelScreen's scrollWidth and scrollContentWidth keep
every scrolling list clear of the bar.

Sliders read a float step from its text, so 0.1 no longer shows 17
decimals, and show at most three; number boxes show at most three too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-09-27 17:54:12 +02:00

83 lines
2.6 KiB
Java

package org.saturnclient.ui;
import org.saturnclient.ui.components.Sidebar;
import org.saturnclient.ui.elements.ImageTexture;
import org.saturnclient.ui.elements.Panel;
import org.saturnclient.ui.elements.Scroll;
import org.saturnclient.ui.resources.Textures;
/**
* A screen laid out as the sidebar beside one panel, centered and shrunk to
* fit smaller windows. Subclasses fill the panel in {@link #panel()}, using the
* content bounds this class computes.
*/
public abstract class PanelScreen extends SaturnScreen {
private static final int MAX_WIDTH = 900;
private static final int MAX_HEIGHT = 580;
private static final int MARGIN = 40;
private static final int GAP = 12;
protected static final int PADDING = 20;
/** How far a scroll reaches past its content area, into the padding, for its bar */
private static final int SCROLL_OVERHANG = 14;
private final int sidebarItem;
protected int panelX, panelY, panelWidth, panelHeight;
/** The panel's area inside its padding */
protected int contentX, contentY, contentWidth, contentHeight;
/**
* @param sidebarItem the {@link Sidebar} item to highlight
*/
public PanelScreen(String title, int sidebarItem) {
super(title);
this.sidebarItem = sidebarItem;
}
@Override
public final void ui() {
panelWidth = Math.min(MAX_WIDTH, width - MARGIN * 2 - Sidebar.WIDTH - GAP);
panelHeight = Math.min(MAX_HEIGHT, height - MARGIN * 2);
int left = (width - (Sidebar.WIDTH + GAP + panelWidth)) / 2;
panelX = left + Sidebar.WIDTH + GAP;
panelY = (height - panelHeight) / 2;
contentX = panelX + PADDING;
contentY = panelY + PADDING;
contentWidth = panelWidth - PADDING * 2;
contentHeight = panelHeight - PADDING * 2;
draw(new Sidebar(sidebarItem, this.provider::close)
.dimensions(Sidebar.WIDTH, panelHeight)
.position(left, panelY));
draw(new Panel().dimensions(panelWidth, panelHeight).position(panelX, panelY));
panel();
draw(new ImageTexture(Textures.LOGO_TEXT_BIG).dimensions(180, 18).position(width - 180 - 20, height - 18 - 20));
}
/**
* Draws the panel's content.
*/
protected abstract void panel();
/**
* The width of a scroll filling {@code width} of the content area.
*/
protected static int scrollWidth(int width) {
return width + SCROLL_OVERHANG;
}
/**
* The width left for a scroll's children, clear of its scrollbar.
*/
protected static int scrollContentWidth(int width) {
return scrollWidth(width) - Scroll.SCROLLBAR_SPACE;
}
}