fix(io): responsive side-panel width (ratio of window, clamped min/max)

Side panel (map slot) now sizes to ~25% of window width, clamped to
[160, 320] scaled px, recomputed on resize — instead of a fixed width.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-31 20:29:51 +02:00
parent 9316f67c31
commit b042d7e0ef

View File

@@ -30,6 +30,8 @@ import java.awt.GraphicsEnvironment;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.KeyEvent;
import java.io.InputStream;
import java.util.ArrayList;
@@ -55,6 +57,11 @@ public class SwingIO implements GameIO {
/** Unscaled size for the HUD and side-panel font, in points. */
private static final float SMALL_SIZE = 12.5f;
/** Side-panel width as a fraction of the window width, clamped by the bounds below. */
private static final double SIDE_RATIO = 0.25;
private static final int SIDE_MIN = 160;
private static final int SIDE_MAX = 320;
private final LinkedBlockingQueue<String> inputs = new LinkedBlockingQueue<>();
private final JFrame frame;
private final JTextPane output;
@@ -62,6 +69,7 @@ public class SwingIO implements GameIO {
private final JTextField input;
private final JLabel hud;
private final JTextArea side;
private final JScrollPane sideScroll;
private final Font baseFont;
/** Detected display scale (≥ 1.0); HiDPI panels report > 1.0 where supported. */
@@ -92,8 +100,7 @@ public class SwingIO implements GameIO {
side.setBackground(new Color(0x0e, 0x12, 0x18));
side.setForeground(new Color(0x6f, 0xcf, 0x73));
side.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
JScrollPane sideScroll = new JScrollPane(side);
sideScroll.setPreferredSize(new Dimension((int) (210 * uiScale), 0));
sideScroll = new JScrollPane(side);
input = new JTextField();
input.addActionListener(e -> {
@@ -112,9 +119,16 @@ public class SwingIO implements GameIO {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize((int) (900 * uiScale), (int) (600 * uiScale));
frame.setLocationRelativeTo(null);
frame.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
updateSideWidth();
}
});
installZoomKeys();
applyFonts();
updateSideWidth();
frame.setVisible(true);
input.requestFocusInWindow();
@@ -154,6 +168,16 @@ public class SwingIO implements GameIO {
}
}
/** Sizes the side panel to a fraction of the window width, clamped to [min, max] (scaled). */
private void updateSideWidth() {
int min = (int) (SIDE_MIN * uiScale);
int max = (int) (SIDE_MAX * uiScale);
int target = Math.max(min, Math.min(max, (int) (frame.getWidth() * SIDE_RATIO)));
sideScroll.setPreferredSize(new Dimension(target, 0));
sideScroll.revalidate();
frame.validate();
}
/** Re-derives and applies all component fonts from the current scale and zoom. */
private void applyFonts() {
float main = BASE_SIZE * uiScale * zoom;