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: high-DPI windows fit the screen (#105), tray in every look at 1280 px (#107), QuickMenu thumbnails
islandmed74a8aa534e75
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 445bd309..d792c8d1 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -730,6 +730,15 @@ if(SCULPTFORGE_BUILD_TESTS)add_test(NAME ui_library_small_screen_720 COMMAND sculptforge --ui-test ${CMAKE_CURRENT_SOURCE_DIR}/tests/ui/library_small_screen.sfui--size 1280x720 --ui-out ${CMAKE_CURRENT_BINARY_DIR}/ui-shots/library_small_screen_720)set_tests_properties(ui_library_small_screen_720 PROPERTIES LABELS ui TIMEOUT 300)+ # #107: every look's right tray on a 1280x720 screen; #105: a Windows laptop at 150-200 % (2560x1600 at 200 % is+ # 1280x800 logical px), nothing past the window's edges.+ add_test(NAME ui_right_tray_looks_720 COMMAND sculptforge --ui-test ${CMAKE_CURRENT_SOURCE_DIR}/tests/ui/right_tray_looks.sfui+ --size 1280x720 --ui-out ${CMAKE_CURRENT_BINARY_DIR}/ui-shots/right_tray_looks_720)+ add_test(NAME ui_windows_dpi_2560 COMMAND sculptforge --ui-test ${CMAKE_CURRENT_SOURCE_DIR}/tests/ui/windows_dpi.sfui+ --size 2560x1600 --ui-out ${CMAKE_CURRENT_BINARY_DIR}/ui-shots/windows_dpi_2560)+ add_test(NAME ui_windows_dpi_2160 COMMAND sculptforge --ui-test ${CMAKE_CURRENT_SOURCE_DIR}/tests/ui/windows_dpi.sfui+ --size 2160x1350 --ui-out ${CMAKE_CURRENT_BINARY_DIR}/ui-shots/windows_dpi_2160)+ set_tests_properties(ui_right_tray_looks_720 ui_windows_dpi_2560 ui_windows_dpi_2160 PROPERTIES LABELS "ui;dpi" TIMEOUT 300)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)diff --git a/changes/fix-0.10.11-ui.md b/changes/fix-0.10.11-ui.mdnew file mode 100644index 00000000..dfa42f05--- /dev/null+++ b/changes/fix-0.10.11-ui.md@@ -0,0 +1,25 @@+---+whats_new: **High-DPI laptops**: on a Windows laptop at 150-200 % scaling the window opens inside the screen at a+ size the interface fits, and nothing runs past its edges.+whats_new: **Right tray in every look**: Forge Terminal, Phosphor and Blueprint open the right tray on 1280 px screens,+ as Classic does.+whats_new: **QuickMenu**: square thumbnails and the look's own colours.+fixed: Windows at 150-200 % display scaling (#105, a 2560x1600 laptop): the window opened at its 100 % size, 800-1067+ logical px wide, and the shelves and status bar ran past its right edge. The window now opens inside the screen's+ usable area at the display's scale (maximised when that doesn't fit), its title bar on screen, and keeps its+ logical size when the scale changes; the status bar drops its readouts before they reach the menus.+fixed: The right tray stayed closed and wouldn't open on screens under 1920 px with Forge Terminal, Phosphor or+ Blueprint (#107, thanks ebarranco): the tiled looks' gaps made a 1280 px window count as too narrow for a tray.+fixed: The QuickMenu (right click) squashed its brush, alpha and material thumbnails and had a blue tint in the+ Neutral look (thanks ThinkingPolygons): the thumbnails are square and uncropped, the background the look's grey.+testers:+ - Windows laptop at 150 % or 200 % scaling (e.g. 2560x1600): start SculptForge; the window is inside the screen,+ the left shelf, the right shelf and tray, and the status bar's search and close buttons all show.+ - Any OS, a 1280x720 or 1366x768 screen: Preferences > Interface > Look > Forge Terminal, Phosphor, Blueprint; the+ right tray is open and its divider closes and opens it.+ - Right click on the canvas in the default look (Neutral): the brush, stroke, alpha and material thumbnails are+ round spheres, not ovals; the menu is grey, no blue.+---+UI tests: windows_dpi (2560x1600 and 2160x1350, at 1280 and 1440 logical px; offscreen_items == 0), right_tray_looks+(1280x720), right_click_menu (quickmenu-neutral shot). Unit tests: shell_tiled_look_not_narrow_at_1280,+window_fits_display.diff --git a/src/app/App.cpp b/src/app/App.cppindex 8176a49f..b7bcf205 100644--- a/src/app/App.cpp+++ b/src/app/App.cpp@@ -142,8 +142,8 @@ bool App::init(const AppOptions& options) {wintab_.open(window_); // Windows: pressure from a tablet driver without Windows Ink (Wintab.h)// Focused from the start when the window system says so: the FOCUS_GAINED event can come before the loop runs.windowFocused_ = (SDL_GetWindowFlags(window_) & SDL_WINDOW_INPUT_FOCUS) != 0;- if (rememberWindow_) { // #35: where and how big it was last time- if (saved.placed) SDL_SetWindowPosition(window_, saved.x, saved.y);+ if (rememberWindow_) { // #35: where and how big it was last time, inside the screen (#105)+ fitWindowToDisplay(saved);if (restoresFullscreen(saved.fullscreen)) SDL_SetWindowFullscreen(window_, true);// #41, #85: on macOS full screen is a Space of its own; entered at start-up (before the first frame, or right// after it) the menu bar and traffic lights couldn't be revealed. A window that was full screen comes back@@ -1061,6 +1061,24 @@ int App::run() {return options_.benchmark && proofSkippedScenes() ? 2 : 0; // (--benchmark: a scene skipped for memory)}+// #105: the window on its display's usable area at the display's scale. A Windows laptop at 150-200 % opened the+// 1600x960 window stored at 100 % (or by older versions) 800-1067 logical px wide, the shelves past its right edge.+void App::fitWindowToDisplay(const WindowState& saved) {+ const SDL_Point corner{saved.x + 100, saved.y + 10}; // (loadWindowState: a display shows this much of it)+ const SDL_DisplayID display = saved.placed ? SDL_GetDisplayForPoint(&corner) : SDL_GetDisplayForWindow(window_);+ SDL_Rect usable;+ if (!display || !SDL_GetDisplayUsableBounds(display, &usable)) return;+ const float scale = automaticUiScale(SDL_GetDisplayContentScale(display), SDL_GetWindowPixelDensity(window_));+ WindowBorders b;+ if (!SDL_GetWindowBordersSize(window_, &b.top, &b.left, &b.bottom, &b.right) || b.top <= 0)+ b = {int(32.0f * scale), 0, 0, 0}; // not shown yet (X11): about a title bar+ const WindowFit fit = fitWindow({saved.x, saved.y, saved.w, saved.h}, saved.stored, saved.placed, saved.scale,+ {usable.x, usable.y, usable.w, usable.h}, b, scale);+ SDL_SetWindowSize(window_, fit.rect.w, fit.rect.h);+ SDL_SetWindowPosition(window_, fit.rect.x, fit.rect.y);+ if (fit.maximize && !saved.fullscreen) SDL_MaximizeWindow(window_);+}+// 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.diff --git a/src/app/App.h b/src/app/App.hindex a4a5ed30..f7f28c27 100644--- a/src/app/App.h+++ b/src/app/App.h@@ -1431,6 +1431,10 @@ private:uint64_t activeTrisKey_ = ~uint64_t(0); // the top shelf's ActiveTris, recounted when the scene changessize_t activeTris_ = 0;float bottomTileW_ = 58.0f; // bottom shelf tiles shrink (down to 44 px) before the shelf scrolls+ // The top shelf when its row doesn't fit (#105: 1280 logical px at Windows' 200 %): the sliders leave room for the+ // items after them (topShelfTailW_, measured last frame), then the icon buttons drop their labels.+ bool topShelfCompact_ = false;+ float topShelfFullW_ = 0.0f, topShelfTailW_ = 0.0f;int navDrag_ = -1; // right-shelf drag button being dragged (0 move, 1 zoom, 2 rotate)ImVec2 navLast_{0, 0}; // the cursor at its last frame (the drag moves by the cursor's own steps)std::string statusShown_; // for colouring fresh errors in the title strip@@ -1510,7 +1514,12 @@ private:std::string uiConfigPath() const;// Window size, position, maximised and full screen, kept in window.json beside ui.json (#35). Not for tests,// renders, recordings or proof mode.- struct WindowState { int w = 1600, h = 960, x = 0, y = 0; bool placed = false, maximized = false, fullscreen = false; };+ struct WindowState {+ int w = 1600, h = 960, x = 0, y = 0;+ float scale = 0.0f; // the UI scale Automatic picked when stored (0: before 0.10.11, taken as 100 %)+ bool stored = false, placed = false, maximized = false, fullscreen = false;+ };+ void fitWindowToDisplay(const WindowState& saved); // #105: inside the screen, at its scale (ShellGeometry.h)static WindowState loadWindowState();void saveWindowState() const;bool rememberWindow_ = false;diff --git a/src/app/Config.cpp b/src/app/Config.cppindex 9a886dc6..c8e196b7 100644--- a/src/app/Config.cpp+++ b/src/app/Config.cpp@@ -5,6 +5,7 @@// the Preferences > Config / Interface / Hotkeys / LightBox sections, the F1// Controls sheet (generated from the action registry) and ZBrush-style// shortcut assignment.+#include "app/UiScale.h"#include "app/Config.h"#include "app/App.h"@@ -739,6 +740,8 @@ App::WindowState App::loadWindowState() {Json j;std::string err;if (!Json::parse(std::string(std::istreambuf_iterator<char>(f), {}), j, err)) return st;+ st.stored = true;+ st.scale = std::clamp(float(j["scale"].asNumber(0.0)), 0.0f, 4.0f);st.w = std::clamp(int(j["w"].asNumber(st.w)), 640, 16384);st.h = std::clamp(int(j["h"].asNumber(st.h)), 400, 16384);st.maximized = j["maximized"].asBool(false);@@ -774,10 +777,12 @@ void App::saveWindowState() const {SDL_GetWindowSize(window_, &st.w, &st.h);SDL_GetWindowPosition(window_, &st.x, &st.y);st.placed = true;+ st.scale = automaticUiScale(SDL_GetWindowDisplayScale(window_), SDL_GetWindowPixelDensity(window_));}Json j;j.set("w", double(st.w));j.set("h", double(st.h));+ if (st.scale > 0.0f) j.set("scale", double(st.scale));if (st.placed) {j.set("x", double(st.x));j.set("y", double(st.y));diff --git a/src/app/Demo.cpp b/src/app/Demo.cppindex dd064a21..57378fa5 100644--- a/src/app/Demo.cpp+++ b/src/app/Demo.cpp@@ -40,6 +40,8 @@ struct ItemTable {};std::vector<Seeded> frame;std::vector<std::string> scopes; // Demo::pushScope: panels drawn inside the shell's trays and drop-downs+ // Items whose visible part runs past the window's edge this frame (#105): "window/label".+ std::map<ImGuiID, std::string> offscreen;};ItemTable& items() {static ItemTable t;@@ -53,6 +55,21 @@ void ImGuiTestEngineHook_ItemAdd(ImGuiContext* ctx, ImGuiID id, const ImRect& bbImRect clip = bb;if (ctx && ctx->CurrentWindow) {clip = ctx->CurrentWindow->ClipRect;+ // Out of reach: past the screen, or cut off by its window where that window can't scroll to it (#105).+ const ImGuiWindow* win = ctx->CurrentWindow;+ ImRect bounds = win->Rect();+ bounds.ClipWith(ImRect(ImVec2(0, 0), ctx->IO.DisplaySize));+ const bool wheel = !(win->Flags & ImGuiWindowFlags_NoScrollWithMouse);+ const bool scrollX = win->ScrollMax.x > 0.0f && (win->ScrollbarX || wheel);+ const bool scrollY = win->ScrollMax.y > 0.0f && (win->ScrollbarY || wheel);+ constexpr float kSlack = 4.0f; // a spacer's padding over the edge hides nothing+ const bool outX = bb.Min.x < bounds.Min.x - kSlack || bb.Max.x > bounds.Max.x + kSlack;+ const bool outY = bb.Min.y < bounds.Min.y - kSlack || bb.Max.y > bounds.Max.y + kSlack;+ const bool offScreen = bb.Min.x < -kSlack || bb.Min.y < -kSlack || bb.Max.x > ctx->IO.DisplaySize.x + kSlack ||+ bb.Max.y > ctx->IO.DisplaySize.y + kSlack;+ if (bb.GetWidth() > 1.0f && bb.GetHeight() > 1.0f && ((outX && !scrollX) || (outY && !scrollY) || (offScreen && !scrollX && !scrollY)))+ items().offscreen[id] = std::string(win->RootWindow->Name) + "/(unlabelled at " + std::to_string(int(bb.Min.x)) ++ "," + std::to_string(int(bb.Min.y)) + ")";clip.ClipWith(ImRect(ImVec2(0, 0), ctx->IO.DisplaySize));}items().rects[id] = {bb, clip};@@ -69,6 +86,7 @@ void ImGuiTestEngineHook_ItemInfo(ImGuiContext* ctx, ImGuiID id, const char* labif (!label || it == items().rects.end()) return;std::string text(label);std::string window = ctx && ctx->CurrentWindow ? ctx->CurrentWindow->RootWindow->Name : "";+ if (auto off = items().offscreen.find(id); off != items().offscreen.end()) off->second = window + "/" + text;if (const size_t hash = window.find("##"); hash != std::string::npos) window.resize(hash);auto add = [&](const std::string& key) {items().byLabel[key] = it->second;@@ -116,6 +134,7 @@ glm::vec3 onSphere(float latDeg, float lonDeg, float r = 1.0f) {void Demo::beginFrame() {items().byLabel.clear();+ items().offscreen.clear();items().frame.clear();items().scopes.clear();}@@ -139,6 +158,12 @@ std::vector<std::string> Demo::similarItems(const std::string& label) {return out;}+std::vector<std::string> Demo::offscreenItems() {+ std::vector<std::string> out;+ for (const auto& [id, name] : items().offscreen) out.push_back(name);+ return out;+}+bool Demo::findItem(const std::string& label, ImVec2& center, bool* visible, ImVec4* clipOut) const {auto found = [&](const Placed& p) {center = p.rect.GetCenter();diff --git a/src/app/Demo.h b/src/app/Demo.hindex 4f9efb41..e966c857 100644--- a/src/app/Demo.h+++ b/src/app/Demo.h@@ -55,6 +55,7 @@ public:static void pushScope(const char* name);static void popScope();static std::vector<std::string> similarItems(const std::string& label); // for test failure messages+ static std::vector<std::string> offscreenItems(); // items drawn past the window's edge last frame ("window/label")// UI tests (UiTest.cpp). Steps that fail stop the run; failures() lists why.bool loadScript(const std::string& path, std::string& error);diff --git a/src/app/Input.cpp b/src/app/Input.cppindex 87660c52..22de0bea 100644--- a/src/app/Input.cpp+++ b/src/app/Input.cpp@@ -712,27 +712,29 @@ void App::drawQuickMenu() {}const float s = uiScale_;const float tile = 56.0f * s;- const float width = 4 * tile + 3 * ImGui::GetStyle().ItemSpacing.x + 150.0f * s;+ // As on the left shelf: a square picture with its caption under it (a square tile squashed the thumbnails).+ const ImVec2 tileSize(tile, tile + (fontSmall_ ? fontSmall_->FontSize : 12.0f) + 4.0f * s);+ const float width = 4 * tile + 3 * ImGui::GetStyle().ItemSpacing.x + 188.0f * s;ImGui::SetNextWindowPos(ImVec2(quickMenu_.at.x - width * 0.5f, quickMenu_.at.y - tile * 0.5f), ImGuiCond_Appearing);ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 6.0f);ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(8, 8));- ImGui::PushStyleColor(ImGuiCol_WindowBg, IM_COL32(37, 37, 40, 245));+ ImGui::PushStyleColor(ImGuiCol_WindowBg, theme::u32(theme::panelBg, 0.96f)); // the look's own grey, no blue tintbool close = false;if (ImGui::Begin("Quick Menu##quickmenu", nullptr,ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings |ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoFocusOnAppearing)) {ImGui::BeginGroup();- drawBrushTile("##qm_brush", ImVec2(tile, tile));+ drawBrushTile("##qm_brush", tileSize);ImGui::SameLine();- drawStrokeTile("##qm_stroke", ImVec2(tile, tile));+ drawStrokeTile("##qm_stroke", tileSize);ImGui::SameLine();- drawAlphaTile("##qm_alpha", ImVec2(tile, tile));+ drawAlphaTile("##qm_alpha", tileSize);ImGui::SameLine();- drawMaterialTile("##qm_material", ImVec2(tile, tile));+ drawMaterialTile("##qm_material", tileSize);ImGui::EndGroup();- ImGui::SameLine();+ ImGui::SameLine(0.0f, 8.0f * s);ImGui::BeginGroup();- const float sw = 150.0f * s;+ const float sw = 180.0f * s; // "Draw Size 60 px 289 mm" wholeImGui::SetNextItemWidth(sw);drawSizeSlider("##qm_drawsize", "Quick Menu", "Brush radius in screen pixels (0.5 to 800), and in mm on the surface.");float focal = focalShift_ * 100.0f;diff --git a/src/app/LightBox.cpp b/src/app/LightBox.cppindex 36d6a2ee..516de802 100644--- a/src/app/LightBox.cpp+++ b/src/app/LightBox.cpp@@ -606,7 +606,12 @@ void LightBox::drawHeader(App& app, float width) {float tabsW = 2.0f * (ImGui::GetFrameHeight() + 2.0f) + 10.0f * scale; // (Back / Forward)for (int i = 0; i < int(LibraryTab::Count); ++i)tabsW += ImGui::CalcTextSize(tr(libraryTabName(LibraryTab(i)))).x + 2.0f * style.FramePadding.x;- const float roomForTabs = origin.x + width - ImGui::GetCursorScreenPos().x - ImGui::GetFrameHeight() - 16.0f * scale;+ // (and beside the right-hand group at its most compact: a short filter, the rows, icon-only buttons; #105)+ const float iconW = ImGui::CalcTextSize(ICON_LC_FOLDER_PLUS).x + 2.0f * style.FramePadding.x;+ const float compactGroupW = 70.0f * scale + 4 * (ImGui::GetFrameHeight() + 2.0f) + 3.0f * iconW + 4 * 8.0f * scale ++ (place_.tab == LibraryTab::QuickSave ? iconW + 8.0f * scale : 0.0f);+ const float roomForTabs = origin.x + width - ImGui::GetCursorScreenPos().x - ImGui::GetFrameHeight() - 16.0f * scale -+ compactGroupW - 16.0f * scale;if (tabsW > roomForTabs) {float widest = 0.0f;for (int i = 0; i < int(LibraryTab::Count); ++i)diff --git a/src/app/Shell.cpp b/src/app/Shell.cppindex 4015bc55..29e8ad41 100644--- a/src/app/Shell.cpp+++ b/src/app/Shell.cpp@@ -1470,6 +1470,9 @@ void App::drawStatusBar(const ShellGeometry& g) {};for (int drop : {2, 4, 1})if (total() > right - menusEnd - 120.0f * s) shown.erase(std::remove(shown.begin(), shown.end(), drop), shown.end());+ // A narrow window (#105: 800 logical px at Windows' 200 %): never over the menus; the triangles go, then the mode.+ for (int drop : {3, 5, 0})+ if (total() > right - menusEnd) shown.erase(std::remove(shown.begin(), shown.end(), drop), shown.end());float mx = right - total();const float modulesX = mx;for (size_t k = 0; k < shown.size(); ++k) {@@ -1959,6 +1962,26 @@ void App::drawShelf(int shelf, const CanvasRect& r) {indices.push_back(i);}ImGui::PopStyleVar();+ if (shelf == kShelfTop && !rects.empty()) {+ // What follows the Intensity slider on its line, and whether the row fits (with the sliders at their least).+ float tail = 0.0f, right = rects[0].Max.x;+ for (size_t k = 0; k < rects.size(); ++k) {+ right = std::max(right, rects[k].Max.x);+ if (list[size_t(indices[k])] == "widget.strength") {+ tail = 0.0f;+ for (size_t j = k + 1; j < rects.size() && std::abs(rects[j].Min.y - rects[k].Min.y) < 1.0f; ++j)+ tail = rects[j].Max.x - rects[k].Max.x;+ }+ }+ topShelfTailW_ = tail;+ const float needed = right - r.x + pad.x;+ if (!topShelfCompact_ && needed > r.w + 1.0f) {+ topShelfCompact_ = true;+ topShelfFullW_ = needed / s; // logical px: the UI scale may change before the shelf widens+ } else if (topShelfCompact_ && r.w / s >= topShelfFullW_) {+ topShelfCompact_ = false;+ }+ }ImGuiWindow* window = ImGui::GetCurrentWindow();ImDrawList* dl = ImGui::GetWindowDrawList();@@ -2052,7 +2075,7 @@ void App::drawShelfItem(int shelf, int index, const std::string& item, bool vert} else if (item == "widget.draw_size" || item == "widget.strength") {ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(8.0f * s, (rowH - ImGui::GetFontSize()) * 0.5f));// 180 px each, narrower when the row is full (e.g. with the contextual Vertex / Texture buttons at 1600 px).- const float avail = ImGui::GetContentRegionAvail().x - (item == "widget.draw_size" ? 4.0f * s : 0.0f);+ const float avail = ImGui::GetContentRegionAvail().x - (item == "widget.draw_size" ? 4.0f * s : 0.0f) - topShelfTailW_;ImGui::SetNextItemWidth(vertical ? 180.0f * s: std::clamp(item == "widget.draw_size" ? avail * 0.5f : avail, 120.0f * s, 180.0f * s));if (item == "widget.draw_size") {@@ -2178,8 +2201,10 @@ void App::drawShelfItem(int shelf, int index, const std::string& item, bool vert: "One of your custom brushes.","Bottom shelf");} else if (const Action* a = actions_.find(item == "brush.paint" ? std::string("draw.paint") : item)) {- const ui::Look look = shelf != kShelfTop ? ui::Look::Tile : a->icon ? ui::Look::IconLabel : ui::Look::Label;- const ImVec2 size = shelf == kShelfTop ? ImVec2(0.0f, rowH)+ const ui::Look look = shelf != kShelfTop ? ui::Look::Tile+ : a->icon ? (topShelfCompact_ ? ui::Look::Icon : ui::Look::IconLabel)+ : ui::Look::Label;+ const ImVec2 size = shelf == kShelfTop ? ImVec2(look == ui::Look::Icon ? rowH : 0.0f, rowH): shelf == kShelfRight ? ImVec2(44.0f * s, 40.0f * s): shelf == kShelfBottom ? ImVec2(bottomTileW_, shell::bottomShelfSize(layout_.shelfTiles).tileH * s): ImVec2(winW - 2.0f * padX, 60.0f * s);@@ -2329,6 +2354,14 @@ bool App::canvasNavButton(const char* id, const char* icon, const char* englishLnamespace {+// The largest square centred in a tile's picture area, inset by `pad`: thumbnails are square renders, never stretched.+void squareIn(ImVec2& a, ImVec2& b, float pad) {+ const float side = std::max(1.0f, std::min(b.x - a.x, b.y - a.y) - 2.0f * pad);+ const ImVec2 c((a.x + b.x) * 0.5f, (a.y + b.y) * 0.5f);+ a = ImVec2(std::floor(c.x - side * 0.5f), std::floor(c.y - side * 0.5f));+ b = ImVec2(a.x + side, a.y + side);+}+// Tile frame: the picture square and the caption under it. Returns true when clicked.// A left-shelf tile; it lifts on hover (`lift` ends when the caller has drawn the picture).bool tileFrame(const char* id, ImVec2 size, ui::TileLift& lift, ImFont* font, const std::string& caption, float s, ImVec2& pic0,@@ -2382,8 +2415,9 @@ void App::drawBrushTile(const char* id, ImVec2 size) {const ImVec2 c((a.x + b.x) * 0.5f, (a.y + b.y) * 0.5f);const float r = (b.x - a.x) * 0.36f;if (tex) {- dl->AddImageRounded(tex, ImVec2(a.x + 2 * s, a.y + 2 * s), ImVec2(b.x - 2 * s, b.y - 2 * s), ImVec2(0, 0), ImVec2(1, 1),- IM_COL32_WHITE, theme::rounding(4.0f * s));+ ImVec2 p0 = a, p1 = b;+ squareIn(p0, p1, 2.0f * s);+ dl->AddImageRounded(tex, p0, p1, ImVec2(0, 0), ImVec2(1, 1), IM_COL32_WHITE, theme::rounding(4.0f * s));} else if (guidesMode_) { // QRemesh Guides (PanelRetopo.cpp)dl->AddCircleFilled(c, r, theme::u32(theme::tile), 32);centredText(dl, fontIcons_, a, b, IM_COL32(255, 196, 64, 255), ICON_LC_SPLINE);@@ -2477,9 +2511,12 @@ void App::drawAlphaTile(const char* id, ImVec2 size) {if (vdmBrushActive() && doc_.brushVdm) { // the VDM brush's 3D alpha (ZBrush shows VDMs in the alpha slot)ui::TileLiftScope lift;const bool clicked = tileFrame(id, size, lift.lift, fontSmall_, doc_.brushVdm->name, s, a, b);- if (ImTextureID tex = thumbs_.vdm(doc_.brushVdm))- ImGui::GetWindowDrawList()->AddImageRounded(tex, ImVec2(a.x + 2 * s, a.y + 2 * s), ImVec2(b.x - 2 * s, b.y - 2 * s),- ImVec2(0, 0), ImVec2(1, 1), IM_COL32_WHITE, theme::rounding(4.0f * s));+ if (ImTextureID tex = thumbs_.vdm(doc_.brushVdm)) {+ ImVec2 p0 = a, p1 = b;+ squareIn(p0, p1, 2.0f * s);+ ImGui::GetWindowDrawList()->AddImageRounded(tex, p0, p1, ImVec2(0, 0), ImVec2(1, 1), IM_COL32_WHITE,+ theme::rounding(4.0f * s));+ }if (clicked) openPicker(Picker::Alpha, ImVec2(ImGui::GetItemRectMax().x + 4.0f * s, ImGui::GetItemRectMin().y));ui::HelpText("VDM", nullptr, "The VDM brush's vector displacement map. Click to pick another.", "Left shelf");return;@@ -2489,10 +2526,12 @@ void App::drawAlphaTile(const char* id, ImVec2 size) {ImDrawList* dl = ImGui::GetWindowDrawList();ImTextureID tex = thumbs_.alpha(doc_.brushAlpha);if (tex) {- dl->AddImageRounded(tex, ImVec2(a.x + 2 * s, a.y + 2 * s), ImVec2(b.x - 2 * s, b.y - 2 * s), ImVec2(0, 0), ImVec2(1, 1),- IM_COL32_WHITE, theme::rounding(4.0f * s));+ ImVec2 p0 = a, p1 = b;+ squareIn(p0, p1, 2.0f * s);+ dl->AddImageRounded(tex, p0, p1, ImVec2(0, 0), ImVec2(1, 1), IM_COL32_WHITE, theme::rounding(4.0f * s));} else {constexpr int kCells = 26;+ squareIn(a, b, 0.0f);const float inset = 6.0f * s, cell = (b.x - a.x - 2.0f * inset) / kCells;dl->AddRectFilled(ImVec2(a.x + inset, a.y + inset), ImVec2(b.x - inset, b.y - inset), IM_COL32(0, 0, 0, 255), theme::rounding(3.0f * s));for (int y = 0; y < kCells; ++y)@@ -2518,7 +2557,9 @@ void App::drawMaterialTile(const char* id, ImVec2 size) {const ImVec2 c((a.x + b.x) * 0.5f, (a.y + b.y) * 0.5f);const float r = (b.x - a.x) * 0.4f;if (ImTextureID thumb = thumbs_.material(m)) { // a rendered sphere on a transparent background- dl->AddImage(thumb, ImVec2(a.x + 2 * s, a.y + 2 * s), ImVec2(b.x - 2 * s, b.y - 2 * s));+ ImVec2 p0 = a, p1 = b;+ squareIn(p0, p1, 2.0f * s);+ dl->AddImage(thumb, p0, p1);} else if (const GLuint t = m >= 0 ? renderer_.matcapTexture(m) : 0) {// Until then the raw matcap (a sphere picture already; stored bottom-up).dl->AddImageRounded(ImTextureID(uintptr_t(t)), ImVec2(c.x - r, c.y - r), ImVec2(c.x + r, c.y + r), ImVec2(0, 1),diff --git a/src/app/ShellGeometry.cpp b/src/app/ShellGeometry.cppindex 934c7553..5ec97baf 100644--- a/src/app/ShellGeometry.cpp+++ b/src/app/ShellGeometry.cpp@@ -3,6 +3,7 @@#include "app/ShellGeometry.h"#include <algorithm>+#include <cmath>namespace sf {@@ -13,6 +14,33 @@ float trayWidth(float stored, float logicalWindowWidth) {return std::clamp(stored, kTrayMinW, kTrayMaxW);}+WindowFit fitWindow(WindowRect win, bool stored, bool placed, float storedScale, const WindowRect& usable,+ const WindowBorders& b, float scale) {+ WindowFit fit;+ const float s = scale > 0.0f ? scale : 1.0f, was = storedScale > 0.0f ? storedScale : 1.0f;+ const int availW = std::max(1, usable.w - b.left - b.right), availH = std::max(1, usable.h - b.top - b.bottom);+ int wantW = win.w, wantH = win.h;+ if (!stored) {+ wantW = int(1600.0f * s + 0.5f);+ wantH = int(960.0f * s + 0.5f);+ } else if (std::abs(s - was) >= 0.01f) {+ wantW = int(float(win.w) * s / was + 0.5f);+ wantH = int(float(win.h) * s / was + 0.5f);+ }+ fit.maximize = wantW > availW || wantH > availH;+ win.w = std::min(wantW, availW);+ win.h = std::min(wantH, availH);+ if (!placed) {+ win.x = usable.x + b.left + (availW - win.w) / 2;+ win.y = usable.y + b.top + (availH - win.h) / 2;+ } else {+ win.x = std::clamp(win.x, usable.x + b.left, usable.x + usable.w - b.right - win.w);+ win.y = std::clamp(win.y, usable.y + b.top, usable.y + usable.h - b.bottom - win.h);+ }+ fit.rect = win;+ return fit;+}+ShellMetrics sculptForgeMetrics(float gap) {ShellMetrics m;m.titleH = 30;@@ -29,6 +57,7 @@ ShellGeometry computeShell(const UiLayout& l, float W, float H, float s, float tShellMetrics inner = m;inner.gap = 0.0f;inner.grow = m.gap;+ inner.windowW = W;UiLayout unmirrored = l; // mirrored at the end, dividers includedunmirrored.leftHanded = false;ShellGeometry g = computeShell(unmirrored, W - 2.0f * half, H - 2.0f * half, s, topInset, inner);@@ -63,7 +92,8 @@ ShellGeometry computeShell(const UiLayout& l, float W, float H, float s, float t}ShellGeometry g;g.scale = s;- const float logicalW = s > 0.0f ? W / s : W;+ const float windowW = m.windowW > 0.0f ? m.windowW : W;+ const float logicalW = s > 0.0f ? windowW / s : windowW;g.narrow = logicalW < kNarrowWidth;g.shelves = l.shelvesVisible;diff --git a/src/app/ShellGeometry.h b/src/app/ShellGeometry.hindex 0f2d7248..39269998 100644--- a/src/app/ShellGeometry.h+++ b/src/app/ShellGeometry.h@@ -21,6 +21,25 @@ constexpr bool kMacWindows = false;#endifconstexpr bool restoresFullscreen(bool savedFullscreen, bool mac = kMacWindows) { return savedFullscreen && !mac; }+// Where a new or restored window goes (#105), in the window system's units: inside the display's usable area with+// its frame (`borders`: the title bar on top), title bar on screen. `scale` is the UI scale Automatic picks there.+// A window never stored opens 1600x960 logical px, centred, maximised when that doesn't fit; a+// stored one keeps its logical size: stored at another scale (`storedScale`; files before 0.10.11 have none: 100 %),+// it grows or shrinks with it (a 1600x960 window at Windows' 200 % was 800 logical px wide and the shelves ran off+// its right edge), maximised when that doesn't fit.+struct WindowRect {+ int x = 0, y = 0, w = 0, h = 0;+};+struct WindowBorders {+ int top = 0, left = 0, bottom = 0, right = 0;+};+struct WindowFit {+ WindowRect rect;+ bool maximize = false;+};+WindowFit fitWindow(WindowRect window, bool stored, bool placed, float storedScale, const WindowRect& usable,+ const WindowBorders& borders, float scale);+struct ShellGeometry {CanvasRect notchBand; // h 0 unless the top of the window is unsafe (camera notch)CanvasRect title, paletteBar;@@ -63,6 +82,8 @@ struct ShellMetrics {// (bars and shelves grow by the gap first, so what's inside keeps its size); the dividers// become the gaps beside the traysfloat grow = 0.0f; // (internal) added to the bars' and shelves' sizes+ float windowW = 0.0f; // (internal) the whole window's width when laying out inside the gaps: narrow and the+ // tray width follow the window, not the gap-inset span (#107)};ShellMetrics sculptForgeMetrics(float gap); // the SculptForge layout: menus in the status bar, a one-row tool shelfdiff --git a/src/app/UiTest.cpp b/src/app/UiTest.cppindex 53005264..c4e0f2df 100644--- a/src/app/UiTest.cpp+++ b/src/app/UiTest.cpp@@ -84,7 +84,7 @@// user library), library_files (.sfbrush files in it; UI tests get an empty// one in --ui-out/brush-library), ui_config (1 once Store Config wrote ui.json),// console_open, command_palette_open, customize, shelves_visible,-// right_tray_open, left_tray_open, lightbox_open, guide_open, guide_hits (search results), shelves (1 shown), left_tray / right_tray (palettes in+// right_tray_open, left_tray_open, right_tray_shown (drawn), shell_narrow, offscreen_items (past the window edge), lightbox_open, guide_open, guide_hits (search results), shelves (1 shown), left_tray / right_tray (palettes in// the tray, -1 when closed); OP is == != < <= > >=; N may be $NAME, $NAME*K,// $NAME+K or $NAME-K (see remember)// moved (vertices moved since `snapshot`), moved_max / moved_sum (distance),@@ -236,7 +236,7 @@// 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)+// content scale changes, with SDL's event (Windows DPI, another monitor); logical_width W: the display scale that makes the window W logical px wide (#105)// 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)@@ -689,6 +689,13 @@ double Demo::query(const std::string& name, bool& known) const {if (name == "shelves_visible") return app_.layout_.shelvesVisible ? 1.0 : 0.0;if (name == "right_tray_open") return app_.layout_.rightTrayOpen ? 1.0 : 0.0;if (name == "left_tray_open") return app_.layout_.leftTrayOpen ? 1.0 : 0.0;+ if (name == "right_tray_shown") return app_.shell_.rightTray.w > 0.0f ? 1.0 : 0.0; // drawn, not just set open (#107)+ if (name == "shell_narrow") return app_.shell_.narrow ? 1.0 : 0.0;+ if (name == "offscreen_items") { // items drawn past the window's edge last frame (#105); names them in the log+ const std::vector<std::string> off = Demo::offscreenItems();+ for (const std::string& o : off) std::fprintf(stderr, "offscreen: %s\n", o.c_str());+ return double(off.size());+ }if (name == "lightbox_open") return app_.lightbox_.open() ? 1.0 : 0.0;if (name == "guide_open") return app_.guide_.isOpen() ? 1.0 : 0.0;if (name == "guide_hits") return double(app_.guide_.searchHits());@@ -1688,6 +1695,20 @@ bool Demo::parseStep(int line, const std::vector<std::string>& w, std::string& eapp_.handleEvent(e);});wait(0.2f);+ } else if (verb == "logical_width") {+ // logical_width 1280: the display reports the scale that makes the window this many logical px wide, as a+ // Windows laptop at 150-200 % does (#105: 2560x1600 at 200 % is 1280x800)+ if (!need(1)) return false;+ run([this, v = num(1, 1280)] {+ int pw = 0, ph = 0; // window units, as the shell lays out (the pixel density is covered by the framebuffer)+ SDL_GetWindowSize(app_.window_, &pw, &ph);+ app_.displayScaleOverride_ = float(pw) / std::max(1.0f, 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_shell_layout.cpp b/tests/test_shell_layout.cppindex fd140a8c..b8aa354e 100644--- a/tests/test_shell_layout.cpp+++ b/tests/test_shell_layout.cpp@@ -191,3 +191,42 @@ TEST(window_restore_fullscreen) {CHECK(!restoresFullscreen(true));#endif}++// #107: a tiled look's gaps don't make a 1280 px window narrow; the right tray opens as it does in Classic.+TEST(shell_tiled_look_not_narrow_at_1280) {+ const UiLayout l = standardLayout(1);+ const ShellGeometry classic = computeShell(l, 1280, 720, 1.0f, 0.0f, sculptForgeMetrics(0.0f));+ const ShellGeometry tiled = computeShell(l, 1280, 720, 1.0f, 0.0f, sculptForgeMetrics(6.0f));+ CHECK(!classic.narrow && !tiled.narrow);+ CHECK(classic.rightTray.w > 0.0f && tiled.rightTray.w > 0.0f);+ CHECK(tiled.rightTray.x + tiled.rightTray.w <= 1280.0f);+ CHECK(computeShell(l, 1200, 720, 1.0f, 0.0f, sculptForgeMetrics(6.0f)).narrow); // below 1280: narrow, as before+}++// #105: windows go inside the display's usable area, at its scale.+TEST(window_fits_display) {+ // A Legion 5 Pro: 2560x1600, the taskbar 96 px at 200 %, a 62 px title bar.+ const WindowRect usable{0, 0, 2560, 1504};+ const WindowBorders frame{62, 0, 0, 0};+ // The 1600x960 stored by 0.10.10 (no scale): 3200x1920 at 200 %, which doesn't fit: maximised, inside.+ WindowFit f = fitWindow({100, 100, 1600, 960}, true, true, 0.0f, usable, frame, 2.0f);+ CHECK(f.maximize);+ CHECK(f.rect.x >= 0 && f.rect.y >= 62 && f.rect.x + f.rect.w <= 2560 && f.rect.y + f.rect.h <= 1504);+ // At 150 %: 2400x1440 just fits under the title bar, moved up 36 px to clear the taskbar.+ f = fitWindow({100, 100, 1600, 960}, true, true, 0.0f, usable, frame, 1.5f);+ CHECK(!f.maximize && f.rect.w == 2400 && f.rect.h == 1440 && f.rect.x == 100 && f.rect.y == 64);+ // Stored at 150 % and opened at 150 %: as it was.+ f = fitWindow({200, 150, 1800, 1100}, true, true, 1.5f, usable, frame, 1.5f);+ CHECK(!f.maximize && f.rect.x == 200 && f.rect.y == 150 && f.rect.w == 1800 && f.rect.h == 1100);+ // A first start at 125 %: 2000x1200, centred.+ f = fitWindow({0, 0, 1600, 960}, false, false, 0.0f, usable, frame, 1.25f);+ CHECK(!f.maximize && f.rect.w == 2000 && f.rect.h == 1200 && f.rect.x == 280 && f.rect.y == 62 + (1442 - 1200) / 2);+ // Half off the screen to the left and above (a monitor that went, a moved taskbar): pulled back in.+ f = fitWindow({-300, -40, 1600, 960}, true, true, 1.0f, usable, frame, 1.0f);+ CHECK(!f.maximize && f.rect.x == 0 && f.rect.y == 62);+ f = fitWindow({2000, 1000, 1600, 960}, true, true, 1.0f, usable, frame, 1.0f);+ CHECK(f.rect.x == 960 && f.rect.y == 1504 - 960);+ // A second monitor left of the main one.+ f = fitWindow({-1900, 50, 1600, 960}, true, true, 1.0f, {-1920, 0, 1920, 1040}, {30, 0, 0, 0}, 1.0f);+ CHECK(f.rect.x == -1900 && f.rect.y == 50);+}diff --git a/tests/ui/right_click_menu.sfui b/tests/ui/right_click_menu.sfuiindex 39486e63..fd451f63 100644--- a/tests/ui/right_click_menu.sfui+++ b/tests/ui/right_click_menu.sfui@@ -70,3 +70,17 @@ button_drag right 0.12 0.3 0.12 0.3 0.1expect_value quickmenu_open == 0button_drag right 0.12 0.3 0.12 0.5expect_value camera_pitch != $p0++# The QuickMenu in the default look (Forge Terminal, Neutral): square, uncropped thumbnails, the look's own grey+# behind them (Discord: squashed thumbnails, a blue tint).+click "Preferences##palette.preferences"+click "Right click opens the Quick Menu##input.right_click_menu"+expect_value right_click_menu == 1+key escape+run ui_look look=forge scheme=neutral+wait_idle 30+button_drag right 0.3 0.3 0.3 0.3 0.1+expect_value quickmenu_open == 1+wait_idle 30+shot quickmenu-neutral+key escapediff --git a/tests/ui/right_tray_looks.sfui b/tests/ui/right_tray_looks.sfuinew file mode 100644index 00000000..d0b47337--- /dev/null+++ b/tests/ui/right_tray_looks.sfui@@ -0,0 +1,26 @@+# #107: on a 1280x720 screen (CMake: ui_right_tray_looks_720, at 100 %) the right tray of every look opens and+# closes from its divider, as in Classic, and starts open.+run new_sphere subdivisions=3+display_scale 100+wait_idle 30+run ui_look look=forge+wait_idle 30+expect_value right_tray_open == 1+expect_value right_tray_shown == 1+shot forge-open+click "##rightdivider"+expect_value right_tray_open == 0+expect_value right_tray_shown == 0+click "##rightdivider"+expect_value right_tray_open == 1+expect_value right_tray_shown == 1+run ui_look look=phosphor+wait_idle 30+expect_value right_tray_shown == 1+run ui_look look=blueprint+wait_idle 30+expect_value right_tray_shown == 1+shot blueprint-open+run ui_look look=classic+wait_idle 30+expect_value right_tray_shown == 1diff --git a/tests/ui/windows_dpi.sfui b/tests/ui/windows_dpi.sfuinew file mode 100644index 00000000..18bafaad--- /dev/null+++ b/tests/ui/windows_dpi.sfui@@ -0,0 +1,48 @@+# A Windows laptop at 150-200 % display scaling (#105: a Legion 5 Pro, 2560x1600 at 200 % is 1280x800 logical px):+# nothing is drawn past the window's edges, in both layouts and every look, with the Library open or closed; and a+# tiled look's right tray opens on a 1280 px wide window as in Classic (#107). CMake also runs it at 2560x1600 and+# 2160x1350 (ui_windows_dpi_*).+run new_sphere subdivisions=3+logical_width 1280+wait_idle 30+expect_value shell_narrow == 0+expect_value right_tray_shown == 1+expect_value offscreen_items == 0+shot sculptforge-1280+key ,+expect_value lightbox_open == 1+wait_idle 30+expect_value offscreen_items == 0+shot library-1280+key escape+expect_value lightbox_open == 0++run ui_look look=phosphor+wait_idle 30+expect_value right_tray_shown == 1+expect_value offscreen_items == 0+run ui_look look=blueprint+wait_idle 30+expect_value right_tray_shown == 1+expect_value offscreen_items == 0+shot blueprint-1280++run ui_look look=classic layout=zbrush+wait_idle 30+expect_value right_tray_shown == 1+expect_value offscreen_items == 0+shot classic-1280+key ,+wait_idle 30+expect_value offscreen_items == 0+key escape++logical_width 1440+wait_idle 30+expect_value offscreen_items == 0+shot classic-1440+run ui_look look=forge layout=sculptforge+wait_idle 30+expect_value right_tray_shown == 1+expect_value offscreen_items == 0+shot sculptforge-1440