Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.
C++ 3d3d-sculptingcppdear-imguidigital-sculptingfbxgame-developmentgaussian-splattinggltfimage-to-3dmcpopenglopenusdsculptingtext-to-3dunreal-engine
UI scale applies live and follows each monitor's DPI (#87)
islandmed3469e1d7aca1
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a5607791..016ae5fb 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -6,6 +6,12 @@ All notable changes to SculptForge are listed here. The format follows## [Unreleased]+### Fixed+- Preferences > Interface > UI scale applies at once: text, controls and panels resize live, no restart (#87).+ Before, the choice waited for the next start and was lost unless Store Config saved it. Automatic now follows+ the monitor the window is on: on Windows (per-monitor DPI v2, now declared in the app's manifest) dragging the+ window between a 100 % and a 150 % monitor, or changing Settings > Display > Scale, rescales the UI right away.+## [0.10.8] - 2026-11-02### Fixeddiff --git a/CMakeLists.txt b/CMakeLists.txtindex dd947ce2..0c7736f3 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -360,6 +360,12 @@ if(SCULPTFORGE_BUILD_APP)endif()configure_file(packaging/windows/sculptforge.rc ${CMAKE_CURRENT_BINARY_DIR}/sculptforge.rc @ONLY)target_sources(sculptforge PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/sculptforge.rc)+ # Per-monitor DPI v2 from the first instruction (a window moved between 100 % and 150 % monitors stays sharp+ # and SDL reports each monitor's scale); MSVC merges it into the manifest the linker writes. (SDL 3 also asks+ # for it at start-up; the manifest covers what runs before, and other toolchains rely on that.)+ if(MSVC)+ target_sources(sculptforge PRIVATE packaging/windows/sculptforge.manifest)+ endif()endif()if(APPLE)# App icon: build an .icns from the 1024 px PNG with Apple's own tools.@@ -644,6 +650,13 @@ if(SCULPTFORGE_BUILD_TESTS)add_test(NAME ui_size_popup_scaled COMMAND sculptforge --ui-test ${CMAKE_CURRENT_SOURCE_DIR}/tests/ui/size_popup.sfui--size 2400x1350 --ui-out ${CMAKE_CURRENT_BINARY_DIR}/ui-shots/size_popup_scaled)set_tests_properties(ui_size_popup_scaled PROPERTIES LABELS ui TIMEOUT 300)+ # UI scale (#87) at 1600x900, where Automatic in a test is exactly 100 %; label "dpi": release.sh step check runs them before the tag.+ add_test(NAME ui_ui_scale_900 COMMAND sculptforge --ui-test ${CMAKE_CURRENT_SOURCE_DIR}/tests/ui/ui_scale.sfui+ --size 1600x900 --ui-out ${CMAKE_CURRENT_BINARY_DIR}/ui-shots/ui_scale_900)+ set_tests_properties(ui_ui_scale_900 PROPERTIES LABELS "ui;dpi" TIMEOUT 300)+ if(TEST ui_ui_scale)+ set_tests_properties(ui_ui_scale PROPERTIES LABELS "ui;dpi")+ endif()add_test(NAME ui_user_guide_1080 COMMAND sculptforge --ui-test ${CMAKE_CURRENT_SOURCE_DIR}/tests/ui/user_guide.sfui--size 1920x1080 --ui-out ${CMAKE_CURRENT_BINARY_DIR}/ui-shots/user_guide_1080)set_tests_properties(ui_user_guide_1080 PROPERTIES LABELS ui TIMEOUT 300)@@ -669,8 +682,8 @@ if(SCULPTFORGE_BUILD_TESTS)# The system clipboard is one per desktop (one X server under CI's xvfb-run), and on X11 every SDL program asks a# new clipboard owner what it holds: a program that quits meanwhile makes the owner's answer fail (BadWindow).# Scripts that set, read or paste it (or click a Copy / Paste button) run alone under ctest -j.- foreach(t ${SCULPTFORGE_UI_TESTS} shell_layout_1080 help_console_1080 size_popup_scaled user_guide_1080)- string(REGEX REPLACE "_1080$|_scaled$" "" base ${t})+ foreach(t ${SCULPTFORGE_UI_TESTS} shell_layout_1080 help_console_1080 size_popup_scaled user_guide_1080 ui_scale_900)+ string(REGEX REPLACE "_1080$|_scaled$|_900$" "" base ${t})get_filename_component(base ${base} NAME_WE)set(script ${CMAKE_CURRENT_SOURCE_DIR}/tests/ui/${base}.sfui)get_filename_component(name ${t} NAME_WE)diff --git a/docs/guide/interface.md b/docs/guide/interface.mdindex b2d5d8e9..0d970322 100644--- a/docs/guide/interface.md+++ b/docs/guide/interface.md@@ -480,7 +480,7 @@ Config keeps it.| **Auto collapse left tray** / **right tray** | On / Off | Collapse other palettes in the tray when one wouldn't fit || **Palettes strictly A-Z (ZBrush order)** | Off | Strict alphabetical palette bar instead of File and Edit first, Help last || **Left-handed layout** | Off | Mirrors the shelves and trays: tools on the right, navigation on the left |-| **UI scale** | Automatic | Size of text and controls (100% to 200%); takes effect at the next start |+| **UI scale** | Automatic | Size of text and controls (100% to 200%), applied at once; Automatic follows the monitor (see below) || **Camera notch** | Automatic | Keeps the interface below a laptop's camera notch in fullscreen (see below) |**Language** changes the interface at once, without a restart; Store Config keeps it for the next start. In@@ -490,6 +490,11 @@ Quad Remesh, Forge Spheres, Library, Lit Sphere, Clay Block, Add). The command pEnglish name. Anything not translated yet (most Ctrl-help descriptions, this guide) shows in English. Scripts and`sculptforge-cli` commands are the same in every language.+**UI scale** also applies at once: text, buttons, shelves and trays resize on the next frame; Store Config keeps it.+**Automatic** uses the scale of the monitor the window is on (Windows: **Settings > Display > Scale**; macOS and+Wayland: the display's scaling; X11: the desktop's font DPI). Drag the window to a monitor at another scale, or+change the system setting, and the interface follows. A chosen size (100% to 200%) stays the same on every monitor.+**Preferences > Input** sets the key **Style** (the first start sets it from your **Coming from** answer):**SculptForge** (the default for new installs): <kbd>1</kbd> to <kbd>9</kbd> and <kbd>0</kbd> pick the first tenbrushes, <kbd>I</kbd> opens Intensity like <kbd>U</kbd>, and <kbd>Ctrl</kbd>+drag on the background zooms whendiff --git a/docs/guide/troubleshooting.md b/docs/guide/troubleshooting.mdindex e6582e9c..15cbd335 100644--- a/docs/guide/troubleshooting.md+++ b/docs/guide/troubleshooting.md@@ -141,8 +141,11 @@ window.### Text and buttons are too small or too large-**Preferences > Interface > UI scale** sets the size (Automatic, 100% to 200%). It takes effect the next time-SculptForge starts, and only if you press **Store Config** (<kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>I</kbd>).+**Preferences > Interface > UI scale** sets the size (Automatic, 100% to 200%) and applies it at once. Press+**Store Config** (<kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>I</kbd>) to keep it for the next start. **Automatic** uses+the scale of the monitor the window is on: on Windows that is **Settings > Display > Scale**, per monitor, and the+interface follows when you drag the window to another monitor. On Linux under X11 it comes from the desktop's+font DPI (Xft.dpi); if Automatic looks wrong there, pick a size.### My layout or shortcuts are gone after a restartdiff --git a/docs/guide/whats-new.md b/docs/guide/whats-new.mdindex d8920df6..6d2ff93f 100644--- a/docs/guide/whats-new.md+++ b/docs/guide/whats-new.md@@ -5,6 +5,12 @@ chapter opens by itself the first time you start a new version; you can always f**Help > What's New**. Every detail is in the[changelog](https://github.com/islandmed/SculptForge/blob/main/CHANGELOG.md).+## Version 0.10.9++- **UI scale works live**: **Preferences > Interface > UI scale** (100% to 200%) resizes text and panels at once,+ no restart. **Automatic** follows the monitor the window is on, so on Windows moving it between a 100% and a+ 150% monitor rescales it right away (#87). See [The interface](interface.md#interface-preferences).+## Version 0.10.8- **Tablets in mouse mode work again**: on some Windows tablets with **Mouse mode** on (Preferences > Tablet) thediff --git a/packaging/windows/sculptforge.manifest b/packaging/windows/sculptforge.manifestnew file mode 100644index 00000000..3feab983--- /dev/null+++ b/packaging/windows/sculptforge.manifest@@ -0,0 +1,11 @@+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>+<!-- SculptForge on Windows: per-monitor DPI awareness v2, so the UI is crisp at 125/150/175 % and rescales live+ when the window moves to a monitor at another scale (#87). Merged into the linker's manifest (CMakeLists.txt). -->+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">+ <asmv3:application>+ <asmv3:windowsSettings>+ <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware>+ <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>+ </asmv3:windowsSettings>+ </asmv3:application>+</assembly>diff --git a/scripts/release.sh b/scripts/release.shindex 139643c7..c03d09aa 100755--- a/scripts/release.sh+++ b/scripts/release.sh@@ -155,6 +155,21 @@ words_ok() {grep -qF "expect_text \"Version $V\"" tests/ui/whats_new.sfui ||die "tests/ui/whats_new.sfui doesn't check Version $V" "update its first expect_text lines to the new section (the version and one line from it), commit, push main"}+# UI scale / DPI (#87): the Windows manifest still asks for per-monitor DPI v2, and the "dpi" UI tests (100-200 %, a+# display-scale event) pass on main's build. BUILD_DIR (default build) is the coordinator's tree, already built for+# the full ctest; only the app is rebuilt here.+dpi_ok() {+ local b=${BUILD_DIR:-build} heavy=(nice -n 19 ionice -c3)+ [ -x "$HOME/Work/.sf/heavy.sh" ] && heavy=("$HOME/Work/.sf/heavy.sh") # one heavy job machine-wide+ grep -q '<dpiAwareness[^>]*>PerMonitorV2' packaging/windows/sculptforge.manifest 2>/dev/null &&+ grep -q 'packaging/windows/sculptforge.manifest' CMakeLists.txt ||+ die "the Windows build no longer declares per-monitor DPI v2" "restore packaging/windows/sculptforge.manifest and its target_sources line in CMakeLists.txt (git log -p -- packaging/windows)"+ [ -f "$b/CTestTestfile.cmake" ] || die "no build tree at $b for the DPI UI tests" "cmake -S . -B $b -DCMAKE_BUILD_TYPE=Release, or BUILD_DIR=<your build> scripts/release.sh $V --from check"+ "${heavy[@]}" cmake --build "$b" --target sculptforge -j3 >/dev/null || die "the app doesn't build in $b" "cmake --build $b --target sculptforge and fix the error"+ SDL_APP_ID=sculptforge-agent "${heavy[@]}" ctest --test-dir "$b" -L dpi --output-on-failure >"$b/release-dpi.log" 2>&1 ||+ die "the UI scale / DPI tests fail (ctest -L dpi; log: $b/release-dpi.log)" "fix them on a branch, merge to main, run again from step check"+ ok "UI scale tests (100-200 %, display-scale event) pass; Windows manifest declares PerMonitorV2"+}# Everything the steps after the tag need that doesn't depend on the release existing. In mode "bump" a missing# card is fine when CARD is set (bump writes it).preflight() {@@ -316,6 +331,7 @@ step_check() {die "$T already tags $(git rev-list -n1 "$T"), not main's $(git rev-parse --short HEAD)" "if that is the release, continue: scripts/release.sh $V --from release; if not, pick the next version"fiok "version files, CHANGELOG, What's New, metainfo and guide say $V at $(git rev-parse --short HEAD)"+ dpi_ok}step_ci() {diff --git a/src/app/App.cpp b/src/app/App.cppindex 08c6194c..54712a8d 100644--- a/src/app/App.cpp+++ b/src/app/App.cpp@@ -4,6 +4,7 @@#include "core/LayerStack.h"#include "app/ShellQuote.h"#include "app/SpaceCamera.h"+#include "app/UiScale.h"#include "app/AirStroke.h"#include "app/AsyncStroke.h"#include "app/Calibration.h"@@ -198,105 +199,10 @@ bool App::init(const AppOptions& options) {std::snprintf(meshyKey_, sizeof meshyKey_, "%s", aiSettings_.meshyKey.c_str());std::snprintf(hfToken_, sizeof hfToken_, "%s", aiSettings_.hfToken.c_str());std::snprintf(comfyUrl_, sizeof comfyUrl_, "%s", aiSettings_.comfyUrl.c_str());- // Pixel density (Retina / Wayland scaling) is handled by the backend via the- // framebuffer scale; only scale the UI for any additional content scaling.- float density = SDL_GetWindowPixelDensity(window_);- float scale = SDL_GetWindowDisplayScale(window_) / (density > 0.0f ? density : 1.0f);- if (scale <= 0.0f) scale = 1.0f;initUiConfig(headless || !options.demo.empty()); // ui.json (layout, shortcuts, UI scale); never for tests and videos- if (!headless && uiPrefs_.uiScale > 0.0f) scale = uiPrefs_.uiScale;- if (recording) scale = float(options.height) / 900.0f; // UI sized for the video, not this screen- uiScale_ = scale;- theme::applyStyle();- ImGui::GetStyle().ScaleAllSizes(scale);- // Inter (SIL OFL), embedded in the binary. Rasterised at the final size for crisp text.- ImFontConfig fontConfig;- fontConfig.FontDataOwnedByAtlas = false;- fontConfig.OversampleH = 2;- fontRegular_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontRegular), int(assets::fontRegular_size),- 15.0f * scale, &fontConfig);- // Lucide icons (ISC/MIT) merged into the UI font, so ICON_LC_* strings work in any label.- {- static const ImWchar kIconRanges[] = {ICON_MIN_LC, ICON_MAX_LC, 0};- ImFontConfig icons;- icons.MergeMode = true;- icons.PixelSnapH = true;- icons.FontDataOwnedByAtlas = false;- icons.GlyphMinAdvanceX = 15.0f * scale;- icons.GlyphOffset = ImVec2(0, 2.0f * scale);- io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontLucide), int(assets::fontLucide_size),- 15.0f * scale, &icons, kIconRanges);- }- // Shell fonts: 12 px captions and 10 px right-shelf labels (with icons), large shelf icons, SemiBold titles.- {- auto addIcons = [&](float size) {- static const ImWchar kIconRanges[] = {ICON_MIN_LC, ICON_MAX_LC, 0};- ImFontConfig icons;- icons.MergeMode = true;- icons.PixelSnapH = true;- icons.FontDataOwnedByAtlas = false;- icons.GlyphMinAdvanceX = size * scale;- icons.GlyphOffset = ImVec2(0, size * 0.13f * scale);- io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontLucide), int(assets::fontLucide_size),- size * scale, &icons, kIconRanges);- };- fontSmall_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontRegular),- int(assets::fontRegular_size), 12.0f * scale, &fontConfig);- addIcons(12.0f);- fontTiny_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontRegular),- int(assets::fontRegular_size), 10.5f * scale, &fontConfig);- fontBold_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontSemiBold),- int(assets::fontSemiBold_size), 15.0f * scale, &fontConfig);- addIcons(15.0f);- static const ImWchar kIconRanges[] = {ICON_MIN_LC, ICON_MAX_LC, 0};- ImFontConfig big;- big.PixelSnapH = true;- big.FontDataOwnedByAtlas = false;- fontIcons_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontLucide), int(assets::fontLucide_size),- 20.0f * scale, &big, kIconRanges);- }- { // JetBrains Mono (SIL OFL) for the looks (Preferences > Interface > Look), with the icons and box drawing.- static const ImWchar kMonoRanges[] = {0x0020, 0x00FF, 0x2010, 0x2027, 0x2190, 0x21FF, 0x2500, 0x259F, 0x25A0, 0x25FF, 0};- static const ImWchar kIconRanges[] = {ICON_MIN_LC, ICON_MAX_LC, 0};- auto addMono = [&](const unsigned char* data, unsigned long long size, float px) {- ImFont* f = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(data), int(size), px * scale, &fontConfig, kMonoRanges);- ImFontConfig icons;- icons.MergeMode = true;- icons.PixelSnapH = true;- icons.FontDataOwnedByAtlas = false;- icons.GlyphMinAdvanceX = px * scale;- icons.GlyphOffset = ImVec2(0, px * 0.13f * scale);- io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontLucide), int(assets::fontLucide_size), px * scale,- &icons, kIconRanges);- return f;- };- fontMono_ = addMono(assets::fontMono, assets::fontMono_size, 15.0f);- fontMonoSmall_ = addMono(assets::fontMono, assets::fontMono_size, 12.0f);- fontMonoTiny_ = addMono(assets::fontMono, assets::fontMono_size, 10.5f);- fontMonoBold_ = addMono(assets::fontMonoBold, assets::fontMonoBold_size, 15.0f);- fontInterSmall_ = fontSmall_;- fontInterTiny_ = fontTiny_;- fontInterBold_ = fontBold_;- theme::fonts = {fontMono_, fontMonoSmall_, fontMonoBold_};- }- { // The support card's display sizes (PanelSupportCard.cpp): Latin only, so the atlas grows by a few glyphs.- static const ImWchar kCardRanges[] = {0x0020, 0x00FF, 0x2014, 0x2014, 0x2019, 0x2019, 0x2026, 0x2026, 0};- fontCardTitle_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontSemiBold),- int(assets::fontSemiBold_size), 40.0f * scale, &fontConfig, kCardRanges);- fontCardHead_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontSemiBold),- int(assets::fontSemiBold_size), 21.0f * scale, &fontConfig, kCardRanges);- fontCardBody_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontRegular),- int(assets::fontRegular_size), 16.5f * scale, &fontConfig, kCardRanges);- }- addHelpFonts(scale); // Ctrl-help titles (Inter SemiBold) and the console (ProggyClean)- guide_.addFonts(scale); // User Guide headings+ uiScale_ = targetUiScale(); // the style follows in applyLook below+ buildUiFonts(uiScale_);if (recording) {- fontCaption_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontSemiBold),- int(assets::fontSemiBold_size), float(options.height) * 0.042f,- &fontConfig);- fontCaptionSub_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontRegular),- int(assets::fontRegular_size), float(options.height) * 0.024f,- &fontConfig);ImGui::GetCurrentContext()->TestEngineHookItems = true; // lets the demo find buttons by labelio.IniFilename = nullptr; // fixed, reproducible layout}@@ -443,6 +349,7 @@ int App::runUiTest(int w, int h, int fps) {hardwareProfileFrameBegin(); // (only with SF_HW_PROFILE_IN_TESTS=1: tests use fixed settings)Demo::beginFrame();+ if (uiScaleDirty_) applyUiScale(); // (Preferences, a display-scale change: #87)ImGui_ImplOpenGL3_NewFrame();ImGui_ImplSDL3_NewFrame();keepImGuiOnPen();@@ -613,6 +520,7 @@ int App::runRecording() {updateCameraAspect();Demo::beginFrame();+ if (uiScaleDirty_) applyUiScale(); // (Preferences, a display-scale change: #87)ImGui_ImplOpenGL3_NewFrame();ImGui_ImplSDL3_NewFrame();keepImGuiOnPen();@@ -1025,6 +933,7 @@ int App::run() {updateSpaceMouse(dt);hardwareProfileFrameBegin(); // the frame governor's CPU and GPU timing+ if (uiScaleDirty_) applyUiScale(); // (Preferences, a display-scale change: #87)ImGui_ImplOpenGL3_NewFrame();ImGui_ImplSDL3_NewFrame();keepImGuiOnPen();@@ -1127,6 +1036,131 @@ int App::run() {return 0;}+// The UI scale (Preferences > Interface > UI scale, #87). Automatic follows the window's display: on Windows+// (per-monitor DPI v2) and with X11's Xft.dpi that is the content scale, and moving the window to a monitor at another+// scale sends SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED. Tests and videos size the UI for their frame instead.+float App::targetUiScale() const {+ float automatic = 1.0f;+ if (displayScaleOverride_ > 0.0f) automatic = displayScaleOverride_; // UI tests: display_scale+ else if (!options_.recordPath.empty() || !options_.uiTest.empty()) automatic = float(options_.height) / 900.0f;+ else if (window_) automatic = automaticUiScale(SDL_GetWindowDisplayScale(window_), SDL_GetWindowPixelDensity(window_));+ return resolveUiScale(uiPrefs_.uiScale, automatic);+}++// Live, between frames (the atlas can't change inside one): the fonts rasterised again at the new size, the style+// rebuilt from scratch (applyLook), and the shell lays itself out at uiScale_ on the next frame.+void App::applyUiScale() {+ uiScaleDirty_ = false;+ const float scale = targetUiScale();+ if (!uiScaleChanged(uiScale_, scale)) return;+ SDL_Log("UI scale %.0f%%", double(scale * 100.0f));+ uiScale_ = scale;+ ImGui::GetIO().Fonts->Clear();+ buildUiFonts(scale);+ if (ImGui::GetIO().BackendRendererUserData) ImGui_ImplOpenGL3_DestroyFontsTexture(); // the next NewFrame uploads it+ applyLook();+}++void App::requestUiScale() {+ uiScaleDirty_ = true;+ redrawIn(0.0);+}++// Every font the UI uses, rasterised at `scale` for crisp text (Dear ImGui 1.91 has no dynamic font sizes).+void App::buildUiFonts(float scale) {+ ImGuiIO& io = ImGui::GetIO();+ const bool recording = !options_.recordPath.empty() || !options_.uiTest.empty();+ // Inter (SIL OFL), embedded in the binary. Rasterised at the final size for crisp text.+ ImFontConfig fontConfig;+ fontConfig.FontDataOwnedByAtlas = false;+ fontConfig.OversampleH = 2;+ fontRegular_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontRegular), int(assets::fontRegular_size),+ 15.0f * scale, &fontConfig);+ // Lucide icons (ISC/MIT) merged into the UI font, so ICON_LC_* strings work in any label.+ {+ static const ImWchar kIconRanges[] = {ICON_MIN_LC, ICON_MAX_LC, 0};+ ImFontConfig icons;+ icons.MergeMode = true;+ icons.PixelSnapH = true;+ icons.FontDataOwnedByAtlas = false;+ icons.GlyphMinAdvanceX = 15.0f * scale;+ icons.GlyphOffset = ImVec2(0, 2.0f * scale);+ io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontLucide), int(assets::fontLucide_size),+ 15.0f * scale, &icons, kIconRanges);+ }+ // Shell fonts: 12 px captions and 10 px right-shelf labels (with icons), large shelf icons, SemiBold titles.+ {+ auto addIcons = [&](float size) {+ static const ImWchar kIconRanges[] = {ICON_MIN_LC, ICON_MAX_LC, 0};+ ImFontConfig icons;+ icons.MergeMode = true;+ icons.PixelSnapH = true;+ icons.FontDataOwnedByAtlas = false;+ icons.GlyphMinAdvanceX = size * scale;+ icons.GlyphOffset = ImVec2(0, size * 0.13f * scale);+ io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontLucide), int(assets::fontLucide_size),+ size * scale, &icons, kIconRanges);+ };+ fontSmall_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontRegular),+ int(assets::fontRegular_size), 12.0f * scale, &fontConfig);+ addIcons(12.0f);+ fontTiny_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontRegular),+ int(assets::fontRegular_size), 10.5f * scale, &fontConfig);+ fontBold_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontSemiBold),+ int(assets::fontSemiBold_size), 15.0f * scale, &fontConfig);+ addIcons(15.0f);+ static const ImWchar kIconRanges[] = {ICON_MIN_LC, ICON_MAX_LC, 0};+ ImFontConfig big;+ big.PixelSnapH = true;+ big.FontDataOwnedByAtlas = false;+ fontIcons_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontLucide), int(assets::fontLucide_size),+ 20.0f * scale, &big, kIconRanges);+ }+ { // JetBrains Mono (SIL OFL) for the looks (Preferences > Interface > Look), with the icons and box drawing.+ static const ImWchar kMonoRanges[] = {0x0020, 0x00FF, 0x2010, 0x2027, 0x2190, 0x21FF, 0x2500, 0x259F, 0x25A0, 0x25FF, 0};+ static const ImWchar kIconRanges[] = {ICON_MIN_LC, ICON_MAX_LC, 0};+ auto addMono = [&](const unsigned char* data, unsigned long long size, float px) {+ ImFont* f = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(data), int(size), px * scale, &fontConfig, kMonoRanges);+ ImFontConfig icons;+ icons.MergeMode = true;+ icons.PixelSnapH = true;+ icons.FontDataOwnedByAtlas = false;+ icons.GlyphMinAdvanceX = px * scale;+ icons.GlyphOffset = ImVec2(0, px * 0.13f * scale);+ io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontLucide), int(assets::fontLucide_size), px * scale,+ &icons, kIconRanges);+ return f;+ };+ fontMono_ = addMono(assets::fontMono, assets::fontMono_size, 15.0f);+ fontMonoSmall_ = addMono(assets::fontMono, assets::fontMono_size, 12.0f);+ fontMonoTiny_ = addMono(assets::fontMono, assets::fontMono_size, 10.5f);+ fontMonoBold_ = addMono(assets::fontMonoBold, assets::fontMonoBold_size, 15.0f);+ fontInterSmall_ = fontSmall_;+ fontInterTiny_ = fontTiny_;+ fontInterBold_ = fontBold_;+ theme::fonts = {fontMono_, fontMonoSmall_, fontMonoBold_};+ }+ { // The support card's display sizes (PanelSupportCard.cpp): Latin only, so the atlas grows by a few glyphs.+ static const ImWchar kCardRanges[] = {0x0020, 0x00FF, 0x2014, 0x2014, 0x2019, 0x2019, 0x2026, 0x2026, 0};+ fontCardTitle_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontSemiBold),+ int(assets::fontSemiBold_size), 40.0f * scale, &fontConfig, kCardRanges);+ fontCardHead_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontSemiBold),+ int(assets::fontSemiBold_size), 21.0f * scale, &fontConfig, kCardRanges);+ fontCardBody_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontRegular),+ int(assets::fontRegular_size), 16.5f * scale, &fontConfig, kCardRanges);+ }+ addHelpFonts(scale); // Ctrl-help titles (Inter SemiBold) and the console (ProggyClean)+ guide_.addFonts(scale); // User Guide headings+ if (recording) { // the demo captions, sized for the video+ fontCaption_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontSemiBold),+ int(assets::fontSemiBold_size), float(options_.height) * 0.042f,+ &fontConfig);+ fontCaptionSub_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontRegular),+ int(assets::fontRegular_size), float(options_.height) * 0.024f,+ &fontConfig);+ }+}+// ---------------------------------------------------------------------------// Input// ---------------------------------------------------------------------------@@ -1155,6 +1189,10 @@ void App::handleEvent(const SDL_Event& event) {if (radial_.hold != RadialHold::None) closeRadialMenu(); // its key or button's release won't come herespaceHeld_ = false; // Space let go in another window never reaches usbreak;+ case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED: // dragged to a monitor at another scale, or the system setting changed+ case SDL_EVENT_WINDOW_DISPLAY_CHANGED:+ if (e.window.windowID == SDL_GetWindowID(window_)) requestUiScale();+ break;case SDL_EVENT_WINDOW_CLOSE_REQUESTED:if (e.window.windowID == SDL_GetWindowID(window_)) requestQuit();break;diff --git a/src/app/App.h b/src/app/App.hindex 34fbdfa2..619079aa 100644--- a/src/app/App.h+++ b/src/app/App.h@@ -127,6 +127,7 @@ public:UiLayout& layout() { return layout_; }ThumbnailCache& thumbnails() { return thumbs_; }void shutdown();+ void requestUiScale(); // Preferences > Interface > UI scale changed: rebuilt live before the next frame (#87)enum class FileAction { OpenObj, SaveObj, ExportGlb, ExportLods, SaveBrush, LoadBrush, OpenImage, ExportUsd, SaveSplats, ExportUnreal, SaveProject, AppendSubtool, ComfyWorkflow, LoadMatcap, InsertMesh, Count };struct DialogRequest {@@ -213,6 +214,11 @@ private:int runUiTest(int width, int height, int fps);std::unique_ptr<Demo> demo_;float uiScale_ = 1.0f; // UI layout scale (fonts are rasterised at this scale)+ bool uiScaleDirty_ = false; // the UI scale may have changed: applyUiScale before the next frame+ float displayScaleOverride_ = 0.0f; // UI tests (display_scale): the display's content scale, 0 = the real one+ float targetUiScale() const; // what uiScale_ should be now (Preferences, the display; Config.cpp)+ void applyUiScale(); // rebuild fonts and style live when it changed (between frames)+ void buildUiFonts(float scale);ImFont* fontCaption_ = nullptr;ImFont* fontCaptionSub_ = nullptr;diff --git a/src/app/Config.cpp b/src/app/Config.cppindex 7174c9cf..3e045789 100644--- a/src/app/Config.cpp+++ b/src/app/Config.cpp@@ -762,6 +762,7 @@ bool App::readUiConfig(const std::string& path, std::string& err) {if (!fromJson(j["layout"], layout, err, prefs.shellLayout)) return false;uiPrefs_ = std::move(prefs);lookDirty_ = true;+ requestUiScale(); // its UI scaleconst bool customize = layout_.customize;layout_ = std::move(layout);layout_.customize = customize;@@ -1204,12 +1205,15 @@ void drawInterfaceSection(App& app) {ImGui::SetNextItemWidth(-FLT_MIN);if (ImGui::BeginCombo("##ui_scale", (std::string(tr("UI scale:")) + " " + tr(kScales[current])).c_str())) {for (int i = 0; i < 6; ++i)- if (ImGui::Selectable(tr(kScales[i]), i == current)) p.uiScale = kScaleValues[i];+ if (ImGui::Selectable(tr(kScales[i]), i == current)) {+ p.uiScale = kScaleValues[i];+ app.requestUiScale(); // live, from the next frame (#87)+ }ImGui::EndCombo();}ui::HelpText("UI scale", nullptr,- "Size of text and controls. Automatic follows the display. Takes effect the next time SculptForge starts "- "(Store Config to keep it).",+ "Size of text and controls, applied at once. Automatic follows the display the window is on (Windows: "+ "Settings > Display > Scale, per monitor). Store Config keeps it for the next start.","Preferences > Interface");static const char* kRotation[] = {"Free (ZBrush)", "Turntable"};ImGui::SetNextItemWidth(-FLT_MIN);diff --git a/src/app/UiScale.h b/src/app/UiScale.hnew file mode 100644index 00000000..6e092dd5--- /dev/null+++ b/src/app/UiScale.h@@ -0,0 +1,30 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+//+// The UI scale (Preferences > Interface > UI scale, #87): what the fonts and the style are built at. Pure functions,+// so sculptforge_tests checks them without a window.+#pragma once++#include <algorithm>+#include <cmath>++namespace sf {++// The scale "Automatic" follows: the display's content scale over its pixel density. Pixel density (Retina, a scaled+// Wayland output) is already covered by the framebuffer scale, so only the rest scales the UI. Windows (per-monitor+// DPI v2) reports 1.5 / 1 at 150 %, macOS 2 / 2 on Retina.+inline float automaticUiScale(float displayScale, float pixelDensity) {+ const float s = displayScale / (pixelDensity > 0.0f ? pixelDensity : 1.0f);+ return s > 0.0f && std::isfinite(s) ? s : 1.0f;+}++// The scale the UI is built at: the user's choice (0 = Automatic), kept to 50-300 %.+inline float resolveUiScale(float preference, float automatic) {+ return std::clamp(preference > 0.0f ? preference : automatic, 0.5f, 3.0f);+}++// True when the UI must be rebuilt to show `target` (fonts, style and layout all at the new scale); a display+// reporting 1.2499 after 1.25, or a repeated event, rebuilds nothing.+inline bool uiScaleChanged(float current, float target) { return std::abs(current - target) >= 0.005f; }++} // namespace sfdiff --git a/src/app/UiTest.cpp b/src/app/UiTest.cppindex fcef8be5..9059a619 100644--- a/src/app/UiTest.cpp+++ b/src/app/UiTest.cpp@@ -194,6 +194,10 @@// spacemouse_button N press and release button N (1 = left side button, 2 = right)// spacemouse_unplug unplug it// expect_value spacemouse_connected (1 when the app opened it), spacemouse_moving (1 while it moves the view)+// ui_scale PERCENT | auto Preferences > Interface > UI scale (applied live, #87); display_scale PERCENT: the display's+// content scale changes, with SDL's event (Windows DPI, another monitor)+// expect_value ui_scale (percent built now), font_height (default font, px), frame_height, panel_width (right+// shelf, px), title_height// expect_value look (0 Classic, 1 Forge Terminal, 2 Phosphor, 3 Blueprint), shell_layout (0 ZBrush-style, 1 SculptForge)#include "app/App.h"@@ -661,6 +665,15 @@ double Demo::query(const std::string& name, bool& known) const {// fractions of the canvas height from its top (-1: the strip isn't shown).if (name == "timeline_top") return app_.uiPrefs_.timelineTop ? 1.0 : 0.0;// The style's minimum window height in unscaled px (32): switching looks must not scale it again each time.+ if (name == "ui_scale") return std::round(double(app_.uiScale_) * 100.0); // percent, as built now (#87)+ if (name == "font_height") { // the default UI font's size in pixels, as rasterised in the atlas+ const ImGuiIO& io = ImGui::GetIO();+ const ImFont* f = io.FontDefault ? io.FontDefault : io.Fonts->Fonts.empty() ? nullptr : io.Fonts->Fonts[0];+ return f ? double(f->FontSize) : 0.0;+ }+ if (name == "frame_height") return double(ImGui::GetFrameHeight()); // a button's height: font + style padding+ if (name == "panel_width") return double(app_.shell_.rightShelf.w); // the right shelf, 52 logical px+ if (name == "title_height") return double(app_.shell_.title.h);if (name == "style_window_min") return double(ImGui::GetStyle().WindowMinSize.y / std::max(app_.uiScale_, 0.01f));if (name == "timeline_y" || name == "axis_gizmo_y") {const auto c = app_.canvasRect();@@ -1437,6 +1450,26 @@ bool Demo::parseStep(int line, const std::vector<std::string>& w, std::string& er = call("POST", "/api/capture/" + capture + "/finish", "");if (r.status != 200) fail(line, "finish refused: " + std::to_string(r.status) + " " + r.body + r.error);});+ } else if (verb == "ui_scale") { // ui_scale 175 | auto: as Preferences > Interface > UI scale picks it (#87)+ if (!need(1)) return false;+ const float v = w[1] == "auto" ? 0.0f : num(1, 100) / 100.0f;+ run([this, v] {+ app_.uiPrefs_.uiScale = v;+ app_.requestUiScale();+ });+ wait(0.2f);+ } else if (verb == "display_scale") {+ // display_scale 150: the window's display now reports this content scale and SDL says so+ // (SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED: Windows' per-monitor DPI, a move to a monitor at another scale)+ if (!need(1)) return false;+ run([this, v = num(1, 100) / 100.0f] {+ app_.displayScaleOverride_ = v;+ SDL_Event e{};+ e.type = SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED;+ e.window.windowID = SDL_GetWindowID(app_.window_);+ app_.handleEvent(e);+ });+ wait(0.2f);} else if (verb == "input_style") {// input_style zbrush|sculptforge|blender|maya: as Preferences > Input sets it (scripts written for one style)if (!need(1)) return false;diff --git a/tests/test_ui_scale.cpp b/tests/test_ui_scale.cppnew file mode 100644index 00000000..443dfb99--- /dev/null+++ b/tests/test_ui_scale.cpp@@ -0,0 +1,59 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+//+// The UI scale (#87, Windows DPI): what Automatic follows, the user's choice winning, and the shell growing by the+// scale at 100 / 125 / 150 / 175 / 200 %. tests/ui/ui_scale.sfui checks the same live in the app (fonts included).+#include "TestHarness.h"++#include "app/ShellGeometry.h"+#include "app/UiScale.h"++#include <cmath>++using namespace sf;++namespace {+bool near(float a, float b, float eps = 0.01f) { return std::abs(a - b) < eps; }+} // namespace++TEST(ui_scale_automatic_follows_the_display) {+ CHECK(near(automaticUiScale(1.0f, 1.0f), 1.0f));+ CHECK(near(automaticUiScale(1.25f, 1.0f), 1.25f)); // Windows 125 % (per-monitor DPI v2: pixels, density 1)+ CHECK(near(automaticUiScale(1.5f, 1.0f), 1.5f));+ CHECK(near(automaticUiScale(1.75f, 1.0f), 1.75f));+ CHECK(near(automaticUiScale(2.0f, 2.0f), 1.0f)); // macOS Retina: the framebuffer scale covers it+ CHECK(near(automaticUiScale(3.0f, 2.0f), 1.5f));+ CHECK(near(automaticUiScale(0.0f, 1.0f), 1.0f)); // SDL couldn't tell: 100 %+ CHECK(near(automaticUiScale(1.5f, 0.0f), 1.5f));+ CHECK(near(automaticUiScale(NAN, 1.0f), 1.0f));+}++TEST(ui_scale_choice_wins_and_is_clamped) {+ CHECK(near(resolveUiScale(0.0f, 1.5f), 1.5f)); // Automatic+ for (float s : {1.0f, 1.25f, 1.5f, 1.75f, 2.0f}) {+ CHECK(near(resolveUiScale(s, 1.0f), s));+ CHECK(near(resolveUiScale(s, 2.0f), s)); // a chosen scale ignores the display (#87: Automatic overrode it)+ }+ CHECK(near(resolveUiScale(9.0f, 1.0f), 3.0f));+ CHECK(near(resolveUiScale(0.0f, 0.1f), 0.5f));+ CHECK(uiScaleChanged(1.0f, 1.25f));+ CHECK(!uiScaleChanged(1.25f, 1.2499f)); // jitter from the system rebuilds nothing+}++TEST(ui_scale_matrix_shell_sizes) {+ // A 2400x1350 window (wide enough that no scale makes it narrow): every shell size grows with the scale.+ const ShellGeometry base = computeShell(standardLayout(), 2400, 1350, 1.0f);+ for (float s : {1.0f, 1.25f, 1.5f, 1.75f}) {+ const ShellGeometry g = computeShell(standardLayout(), 2400, 1350, s);+ CHECK(!g.narrow);+ CHECK(near(g.rightShelf.w, base.rightShelf.w * s, 1.0f));+ CHECK(near(g.leftShelf.w, base.leftShelf.w * s, 1.0f));+ CHECK(near(g.title.h, base.title.h * s, 1.0f));+ CHECK(near(g.topShelf.h, base.topShelf.h * s, 1.0f));+ CHECK(g.canvas.w < base.canvas.w + 0.5f && g.canvas.w > 0.0f);+ }+ // 200 % on the same window: 1200 logical px is a narrow window, the shelves still scale.+ const ShellGeometry g = computeShell(standardLayout(), 2400, 1350, 2.0f);+ CHECK(near(g.rightShelf.w, base.rightShelf.w * 2.0f, 1.0f));+ CHECK(near(g.title.h, base.title.h * 2.0f, 1.0f));+}diff --git a/tests/ui/ui_scale.sfui b/tests/ui/ui_scale.sfuinew file mode 100644index 00000000..471f95a1--- /dev/null+++ b/tests/ui/ui_scale.sfui@@ -0,0 +1,98 @@+# Preferences > Interface > UI scale applies at once, no restart (#87): text and panels grow by the chosen factor.+# Then Automatic follows the display, as on Windows with per-monitor DPI when the window moves to a monitor at+# another scale: SDL's display-scale event rebuilds the UI. CMake runs it at 1600x900 (ui_ui_scale_dpi) and at the+# default size; a preference is absolute, so the numbers are the same in both.+run new_sphere subdivisions=3++ui_scale 100+expect_value ui_scale == 100+expect_value font_height >= 14+expect_value font_height <= 16+expect_value panel_width >= 51+expect_value panel_width <= 53+remember title_height t100+remember frame_height f100+shot scale_100++ui_scale 125+expect_value ui_scale == 125+expect_value font_height >= 17.75+expect_value font_height <= 19.75+expect_value panel_width >= 64+expect_value panel_width <= 66+expect_value title_height >= $t100*1.24+expect_value title_height <= $t100*1.26+expect_value frame_height > $f100+shot scale_125++ui_scale 150+expect_value ui_scale == 150+expect_value font_height >= 21.5+expect_value font_height <= 23.5+expect_value panel_width >= 77+expect_value panel_width <= 79+shot scale_150++ui_scale 175+expect_value ui_scale == 175+expect_value font_height >= 25.25+expect_value font_height <= 27.25+expect_value panel_width >= 90+expect_value panel_width <= 92+expect_value frame_height >= $f100*1.5+shot scale_175++ui_scale 200+expect_value ui_scale == 200+expect_value font_height >= 29+expect_value font_height <= 31+expect_value panel_width >= 103+expect_value panel_width <= 105+expect_value title_height >= $t100*1.99+expect_value title_height <= $t100*2.01+shot scale_200++# Back to 100 %: everything returns to its size (the style is rebuilt from scratch, not scaled twice).+ui_scale 100+expect_value font_height >= 14+expect_value font_height <= 16+expect_value panel_width >= 51+expect_value panel_width <= 53+expect_value frame_height == $f100+expect_value style_window_min == 32++# Automatic follows the display: 150 % (a Windows laptop), then the window moves to a 100 % monitor, then 175 %.+ui_scale auto+display_scale 150+expect_value ui_scale == 150+expect_value font_height >= 21.5+expect_value font_height <= 23.5+expect_value panel_width >= 77+expect_value panel_width <= 79+shot display_150+display_scale 100+expect_value ui_scale == 100+expect_value font_height >= 14+expect_value font_height <= 16+display_scale 175+expect_value ui_scale == 175+expect_value font_height >= 25.25+expect_value font_height <= 27.25++# A chosen scale wins over the display's.+ui_scale 125+display_scale 200+expect_value ui_scale == 125+expect_value font_height >= 17.75+expect_value font_height <= 19.75++# Another look keeps the scale; the rebuilt fonts serve every window: the User Guide opens and draws at 125 %.+run ui_look look=classic layout=zbrush+expect_value ui_scale == 125+expect_value font_height >= 17.75+expect_value font_height <= 19.75+click "Help##palette.help"+click "User Guide##help.guide"+expect_value guide_open == 1+shot guide_125+key escape