This commit is contained in:
crschnick
2026-01-18 10:52:51 +00:00
parent 7161926d35
commit 7c85df982b
6 changed files with 54 additions and 40 deletions
@@ -2,7 +2,7 @@ package io.xpipe.app.browser.icon;
import io.xpipe.app.core.AppImages;
import io.xpipe.app.core.AppResources;
import io.xpipe.app.core.window.AppMainWindow;
import io.xpipe.app.core.AppScale;
import org.apache.commons.io.FilenameUtils;
public class BrowserIconManager {
@@ -18,7 +18,7 @@ public class BrowserIconManager {
}
public static void loadIfNecessary(String s) {
var res = AppMainWindow.get().displayScale().get() == 1.0 ? "24" : "40";
var res = AppScale.hasDefaultDisplayScale() ? "24" : "40";
var key = "browser/" + FilenameUtils.getBaseName(s) + "-" + res + ".png";
if (AppImages.hasImage(key)) {
return;
@@ -2,11 +2,13 @@ package io.xpipe.app.comp.base;
import io.xpipe.app.comp.Comp;
import io.xpipe.app.core.AppImages;
import io.xpipe.app.core.AppScale;
import io.xpipe.app.core.window.AppMainWindow;
import io.xpipe.app.platform.BindingsHelper;
import io.xpipe.core.FilePath;
import javafx.beans.binding.Bindings;
import javafx.beans.property.ReadOnlyStringWrapper;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ObservableDoubleValue;
@@ -35,33 +37,28 @@ public class PrettyImageHelper {
return Optional.empty();
}
private static ObservableValue<String> rasterizedImageIfExistsScaled(
private static String rasterizedImageIfExistsScaled(
String img, int height, int... availableSizes) {
ObservableDoubleValue obs =
AppMainWindow.get() != null ? AppMainWindow.get().displayScale() : new SimpleDoubleProperty(1.0);
return Bindings.createStringBinding(
() -> {
if (img == null) {
return null;
}
if (img == null) {
return null;
}
if (!img.endsWith(".svg")) {
return rasterizedImageIfExists(img, height).orElse(null);
}
if (!img.endsWith(".svg")) {
return rasterizedImageIfExists(img, height).orElse(null);
}
var mult = Math.round(obs.get() * height);
var base = FilePath.of(img).getBaseName();
var available = IntStream.of(availableSizes)
.filter(integer -> AppImages.hasImage(base + "-" + integer + ".png"))
.boxed()
.toList();
var closest = available.stream()
.filter(integer -> integer >= mult)
.findFirst()
.orElse(available.size() > 0 ? available.getLast() : 0);
return rasterizedImageIfExists(img, closest).orElse(null);
},
obs);
var scale = AppScale.getEffectiveDisplayScale();
var mult = Math.round(scale * height);
var base = FilePath.of(img).getBaseName();
var available = IntStream.of(availableSizes)
.filter(integer -> AppImages.hasImage(base + "-" + integer + ".png"))
.boxed()
.toList();
var closest = available.stream()
.filter(integer -> integer >= mult)
.findFirst()
.orElse(available.size() > 0 ? available.getLast() : 0);
return rasterizedImageIfExists(img, closest).orElse(null);
}
public static Comp<?> ofFixedSizeSquare(String img, int size) {
@@ -77,7 +74,7 @@ public class PrettyImageHelper {
return new PrettyImageComp(new SimpleStringProperty(null), w, h);
}
var binding = BindingsHelper.flatMap(img, s -> {
var binding = BindingsHelper.map(img, s -> {
return rasterizedImageIfExistsScaled(s, h, 16, 24, 40, 80);
});
return new PrettyImageComp(binding, w, h);
@@ -85,6 +82,6 @@ public class PrettyImageHelper {
public static Comp<?> ofSpecificFixedSize(String img, int w, int h) {
var b = rasterizedImageIfExistsScaled(img, h, h, h * 2);
return new PrettyImageComp(b, w, h);
return new PrettyImageComp(new ReadOnlyStringWrapper(b), w, h);
}
}
@@ -43,7 +43,7 @@ public class AppImages {
var exts = AppExtensionManager.getInstance().getContentModules();
for (Module ext : exts) {
AppResources.with(ext.getName(), "img/", basePath -> {
var skipLarge = AppMainWindow.get().displayScale().get() == 1.0;
var skipLarge = AppScale.hasDefaultDisplayScale();
Files.walkFileTree(basePath, new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
@@ -62,7 +62,7 @@ public class AppImages {
private static void loadOsIcons() {
AppResources.with(AppResources.MAIN_MODULE, "os", basePath -> {
var skipLarge = AppMainWindow.get().displayScale().get() == 1.0;
var skipLarge = AppScale.hasDefaultDisplayScale();
Files.walkFileTree(basePath, new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
@@ -80,7 +80,7 @@ public class AppImages {
private static void loadWelcomeImages() {
AppResources.with(AppResources.MAIN_MODULE, "welcome", basePath -> {
var skipLarge = AppMainWindow.get().displayScale().get() == 1.0;
var skipLarge = AppScale.hasDefaultDisplayScale();
Files.walkFileTree(basePath, new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
@@ -0,0 +1,25 @@
package io.xpipe.app.core;
import io.xpipe.app.prefs.AppPrefs;
import javafx.stage.Screen;
public class AppScale {
public static boolean hasDefaultDisplayScale() {
return getEffectiveDisplayScale() == 1.0;
}
public static double getEffectiveDisplayScale() {
if (AppPrefs.get() != null) {
var s = AppPrefs.get().uiScale().getValue();
if (s != null) {
var i = Math.min(300, Math.max(25, s));
var percent = i / 100.0;
return percent;
}
}
var def = Screen.getPrimary().getOutputScaleX();
return def;
}
}
@@ -156,14 +156,6 @@ public class AppMainWindow {
return INSTANCE;
}
public ObservableDoubleValue displayScale() {
if (getStage() == null) {
return new SimpleDoubleProperty(1.0);
}
return getStage().outputScaleXProperty();
}
public void show() {
stage.show();
if (OsType.ofLocal() == OsType.WINDOWS && !shown) {
@@ -76,7 +76,7 @@ public class SystemIconManager {
}
var dir = SystemIconCache.getDirectory(icon.getSource());
var res = AppMainWindow.get().displayScale().get() == 1.0 ? List.of(16, 24, 40) : List.of(16, 24, 40, 80);
var res = AppScale.hasDefaultDisplayScale() ? List.of(16, 24, 40) : List.of(16, 24, 40, 80);
var files = new ArrayList<Path>();
for (Integer re : res) {
files.add(dir.resolve(icon.getId() + "-" + re + ".png"));