From 8ab39cd535fb8154a032c186a18db506b11c2d7b Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Sun, 31 May 2026 21:26:09 +0200 Subject: [PATCH] fix(io): auto-scale GUI text with window size, consistent with the map Body text/HUD font now derives from a window-relative auto-scale (starting at uiScale, growing as the window grows) and is re-applied on resize, so the text tracks the window like the map does. Ctrl +/- zoom still multiplies on top of both. Removes the resize hiccup where only the map reacted. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../java/thb/jeanluc/adventure/io/SwingIO.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/SwingIO.java b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/SwingIO.java index 3fab999..86b9b53 100644 --- a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/SwingIO.java +++ b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/SwingIO.java @@ -120,6 +120,7 @@ public class SwingIO implements GameIO { @Override public void componentResized(ComponentEvent e) { updateSideWidth(); + applyFonts(); } }); @@ -178,10 +179,21 @@ public class SwingIO implements GameIO { map.repaint(); } - /** Re-derives and applies all component fonts from the current scale and zoom. */ + /** + * Auto-scale derived from the window size relative to the design size + * (900x600). At the initial size this equals {@link #uiScale}; growing the + * window grows the text, mirroring how the map fits its panel. + */ + private float frameScale() { + double s = Math.min(frame.getWidth() / 900.0, frame.getHeight() / 600.0); + return (float) Math.max(0.6, Math.min(2.6, s)); + } + + /** Re-derives and applies all component fonts from the window auto-scale and zoom. */ private void applyFonts() { - float main = BASE_SIZE * uiScale * zoom; - float small = SMALL_SIZE * uiScale * zoom; + float auto = frameScale(); + float main = BASE_SIZE * auto * zoom; + float small = SMALL_SIZE * auto * zoom; output.setFont(baseFont.deriveFont(main)); input.setFont(baseFont.deriveFont(main)); hud.setFont(baseFont.deriveFont(small));