Scale the interface fractionally on Linux
Java2D on X11 (and so under XWayland) truncates its scale to a whole number, drawing 150 % at 100 %. On Linux, pin Java2D to 1 and hand the full factor to FlatLaf, taken from XSETTINGS Xft/DPI, KWin's Xwayland scale or GDK_SCALE, or chosen in Options → Design. The client's own sizes now go through UIScale: borders, gaps, dialog and row sizes, icons (rendered at the scaled size, so they stay crisp), custom-painted components and font sizes in the HTML views. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.ts3client.ui;
|
||||
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
@@ -15,14 +17,25 @@ import java.awt.image.BufferedImage;
|
||||
* so a machine with no icon pack installed still gets a complete (if plain) set.
|
||||
* Everything else — menu and dialog decoration — simply stays blank without a pack,
|
||||
* which is why {@link #of(String)} may return {@code null}.
|
||||
*
|
||||
* <p>Icons come at the interface's scale; the variants taking a size take it in pixels.
|
||||
*/
|
||||
public final class Icons {
|
||||
|
||||
/** The box the built-in painters draw in. */
|
||||
private static final int SZ = IconTheme.SIZE;
|
||||
|
||||
private Icons() {
|
||||
}
|
||||
|
||||
private static int small() {
|
||||
return UIScale.scale(IconTheme.SIZE);
|
||||
}
|
||||
|
||||
private static int large() {
|
||||
return UIScale.scale(IconTheme.TOOLBAR_SIZE);
|
||||
}
|
||||
|
||||
private interface Painter {
|
||||
void paint(Graphics2D g);
|
||||
}
|
||||
@@ -44,13 +57,13 @@ public final class Icons {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @return the pack's icon at a given size, or {@code null} when it has none */
|
||||
/** @return the pack's icon at {@code size} pixels, or {@code null} when it has none */
|
||||
public static ImageIcon of(String key, int size) {
|
||||
return IconTheme.icon(key, size);
|
||||
}
|
||||
|
||||
private static ImageIcon themed(String key, Painter fallback) {
|
||||
return themed(key, SZ, fallback);
|
||||
return themed(key, small(), fallback);
|
||||
}
|
||||
|
||||
private static ImageIcon themed(String key, int size, Painter fallback) {
|
||||
@@ -64,14 +77,14 @@ public final class Icons {
|
||||
*/
|
||||
private static ImageIcon themed(String[] keys, Painter fallback) {
|
||||
for (String key : keys) {
|
||||
ImageIcon icon = IconTheme.icon(key, SZ);
|
||||
ImageIcon icon = IconTheme.icon(key, small());
|
||||
if (icon != null) return icon;
|
||||
}
|
||||
return make(fallback);
|
||||
}
|
||||
|
||||
private static ImageIcon make(Painter p) {
|
||||
return make(SZ, p);
|
||||
return make(small(), p);
|
||||
}
|
||||
|
||||
/** Runs a painter (which draws in a 16×16 box) scaled to {@code size}. */
|
||||
@@ -129,7 +142,7 @@ public final class Icons {
|
||||
// ---- client status icons ----
|
||||
|
||||
public static ImageIcon clientIdle() {
|
||||
return clientIdle(SZ);
|
||||
return clientIdle(small());
|
||||
}
|
||||
|
||||
public static ImageIcon clientIdle(int size) {
|
||||
@@ -137,7 +150,7 @@ public final class Icons {
|
||||
}
|
||||
|
||||
public static ImageIcon clientTalking() {
|
||||
return clientTalking(SZ);
|
||||
return clientTalking(small());
|
||||
}
|
||||
|
||||
public static ImageIcon clientTalking(int size) {
|
||||
@@ -145,7 +158,7 @@ public final class Icons {
|
||||
}
|
||||
|
||||
public static ImageIcon clientAway() {
|
||||
return clientAway(SZ);
|
||||
return clientAway(small());
|
||||
}
|
||||
|
||||
public static ImageIcon clientAway(int size) {
|
||||
@@ -154,12 +167,12 @@ public final class Icons {
|
||||
|
||||
/** A channel commander that is not talking. */
|
||||
public static ImageIcon clientCommander() {
|
||||
return clientCommander(SZ);
|
||||
return clientCommander(small());
|
||||
}
|
||||
|
||||
/** A channel commander that is talking. */
|
||||
public static ImageIcon clientCommanderTalking() {
|
||||
return clientCommanderTalking(SZ);
|
||||
return clientCommanderTalking(small());
|
||||
}
|
||||
|
||||
public static ImageIcon clientQuery() {
|
||||
@@ -167,7 +180,7 @@ public final class Icons {
|
||||
}
|
||||
|
||||
public static ImageIcon micMuted() {
|
||||
return micMuted(SZ);
|
||||
return micMuted(small());
|
||||
}
|
||||
|
||||
public static ImageIcon micMuted(int size) {
|
||||
@@ -175,7 +188,7 @@ public final class Icons {
|
||||
}
|
||||
|
||||
public static ImageIcon speakerMuted() {
|
||||
return speakerMuted(SZ);
|
||||
return speakerMuted(small());
|
||||
}
|
||||
|
||||
public static ImageIcon speakerMuted(int size) {
|
||||
@@ -184,7 +197,7 @@ public final class Icons {
|
||||
|
||||
/** The capture device is unavailable (another tab holds it), as opposed to muted. */
|
||||
public static ImageIcon micDisabled() {
|
||||
return micDisabled(SZ);
|
||||
return micDisabled(small());
|
||||
}
|
||||
|
||||
public static ImageIcon micDisabled(int size) {
|
||||
@@ -193,7 +206,7 @@ public final class Icons {
|
||||
|
||||
/** The playback device is unavailable, as opposed to muted/deafened. */
|
||||
public static ImageIcon speakerDisabled() {
|
||||
return speakerDisabled(SZ);
|
||||
return speakerDisabled(small());
|
||||
}
|
||||
|
||||
public static ImageIcon speakerDisabled(int size) {
|
||||
@@ -202,7 +215,7 @@ public final class Icons {
|
||||
|
||||
/** TS3's "Local Mic Mute": silenced, but not reported as muted. */
|
||||
public static ImageIcon micLocalMuted() {
|
||||
return micLocalMuted(SZ);
|
||||
return micLocalMuted(small());
|
||||
}
|
||||
|
||||
public static ImageIcon micLocalMuted(int size) {
|
||||
@@ -222,32 +235,32 @@ public final class Icons {
|
||||
// ---- toolbar / action icons ----
|
||||
|
||||
public static ImageIcon connect() {
|
||||
return themed("CONNECT", IconTheme.TOOLBAR_SIZE, Icons::paintConnect);
|
||||
return themed("CONNECT", large(), Icons::paintConnect);
|
||||
}
|
||||
|
||||
public static ImageIcon disconnect() {
|
||||
return themed("DISCONNECT", IconTheme.TOOLBAR_SIZE, Icons::paintDisconnect);
|
||||
return themed("DISCONNECT", large(), Icons::paintDisconnect);
|
||||
}
|
||||
|
||||
public static ImageIcon mic() {
|
||||
return themed("CAPTURE", IconTheme.TOOLBAR_SIZE, Icons::paintMic);
|
||||
return themed("CAPTURE", large(), Icons::paintMic);
|
||||
}
|
||||
|
||||
public static ImageIcon speaker() {
|
||||
return themed("PLAYBACK", IconTheme.TOOLBAR_SIZE, Icons::paintSpeaker);
|
||||
return themed("PLAYBACK", large(), Icons::paintSpeaker);
|
||||
}
|
||||
|
||||
public static ImageIcon micMutedLarge() {
|
||||
return themed("INPUT_MUTED", IconTheme.TOOLBAR_SIZE, Icons::paintMicMuted);
|
||||
return themed("INPUT_MUTED", large(), Icons::paintMicMuted);
|
||||
}
|
||||
|
||||
public static ImageIcon speakerMutedLarge() {
|
||||
return themed("OUTPUT_MUTED", IconTheme.TOOLBAR_SIZE, Icons::paintSpeakerMuted);
|
||||
return themed("OUTPUT_MUTED", large(), Icons::paintSpeakerMuted);
|
||||
}
|
||||
|
||||
/** Marks the server that currently owns the microphone. */
|
||||
public static ImageIcon micActive() {
|
||||
return themed("ACTIVATE_MICROPHONE", IconTheme.TOOLBAR_SIZE, Icons::paintMicActive);
|
||||
return themed("ACTIVATE_MICROPHONE", large(), Icons::paintMicActive);
|
||||
}
|
||||
|
||||
/** The same marker at tab-label size. */
|
||||
@@ -262,7 +275,7 @@ public final class Icons {
|
||||
public static ImageIcon channelClientPair() {
|
||||
ImageIcon channel = channel(true);
|
||||
ImageIcon edit = themed("EDIT", Icons::paintEdit);
|
||||
int gap = 8;
|
||||
int gap = UIScale.scale(8);
|
||||
int width = channel.getIconWidth() + gap + edit.getIconWidth();
|
||||
int height = Math.max(channel.getIconHeight(), edit.getIconHeight());
|
||||
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
@@ -282,15 +295,15 @@ public final class Icons {
|
||||
|
||||
/** The toolbar's away marker. */
|
||||
public static ImageIcon away() {
|
||||
return themed("AWAY", IconTheme.TOOLBAR_SIZE, g -> paintPerson(g, Theme.away()));
|
||||
return themed("AWAY", large(), g -> paintPerson(g, Theme.away()));
|
||||
}
|
||||
|
||||
public static ImageIcon settings() {
|
||||
return themed("SETTINGS", IconTheme.TOOLBAR_SIZE, Icons::paintSettings);
|
||||
return themed("SETTINGS", large(), Icons::paintSettings);
|
||||
}
|
||||
|
||||
public static ImageIcon app() {
|
||||
return app(SZ);
|
||||
return app(small());
|
||||
}
|
||||
|
||||
public static ImageIcon app(int size) {
|
||||
|
||||
Reference in New Issue
Block a user