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
fix/frame-free-area (squashed, 06e57ab8): a framed model fits the free area under the Library and timeline (lens shift, set on Frame); the left shelf shrinks to fit at 1080p 150/200%, captions shrink to 80% or drop with the name on hover. Shell.cpp tile widths combine tray-hscroll's fitW with the shelf fit
islandmedcbbd3e11cd28
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 5b7567a2..6b793b75 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -979,6 +979,9 @@ if(SCULPTFORGE_BUILD_TESTS)sculptforge_ui_test(uv_editor_scales_4k uv_editor_scales --size 3840x2160)# The Library on a 1280x720 screen (#80): its close button stays on screen.sculptforge_ui_test(library_small_screen_720 library_small_screen --size 1280x720)+ # Framing fits the model into the canvas the Library and the Sculpt Timeline leave free; the left shelf fits its+ # column (1080p at 100 / 150 / 200 %; tests/ui/hidpi/: only at that size).+ sculptforge_ui_test(frame_free_area_1080 hidpi/frame_free_area --size 1920x1080)# #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.sculptforge_ui_test(right_tray_looks_720 right_tray_looks --size 1280x720)diff --git a/changes/fix-frame-free-area.md b/changes/fix-frame-free-area.mdnew file mode 100644index 00000000..6c2004ee--- /dev/null+++ b/changes/fix-frame-free-area.md@@ -0,0 +1,12 @@+---+whats_new: **Frame** (F) fits the model into the part of the canvas the open Library and the Sculpt Timeline leave free, and the left shelf's brush tiles and colour picker shrink to fit short screens.+fixed: **Frame** (F, the Frame button), a new model and **Reset View** fit the model into the canvas the open Library+ and the Sculpt Timeline strip leave free: at 200 % on a 1080p screen the sphere's top sat under them. Opening or+ closing the Library doesn't move the view; the next Frame uses the new free area.+fixed: The left shelf's brush tiles and colour picker shrink to fit its column (and the wheel scrolls it past that):+ at 150 % on a 1080p screen the colour swatches ran under the bottom shelf.+testers:+ - Windows 1080p at 200 %: open the Library (,), press F: the whole model shows below the Library and the Timeline; close the Library: the view stays put.+ - Windows 1080p at 150 %: every left shelf item (brush, stroke, alpha, material tiles, the colour picker and its swatches) is fully visible above the bottom shelf.+---+Lens shift on the camera (Camera::shift), set by frame(); benches, headless renders and --run at launch keep the plain centred frame.diff --git a/src/app/App.cpp b/src/app/App.cppindex b2f344d4..f6fa90e2 100644--- a/src/app/App.cpp+++ b/src/app/App.cpp@@ -2024,7 +2024,7 @@ void App::resetView() {camera_.yaw = camera_.pitch = camera_.roll = 0.0f; // the view a new model opens with: from the frontcamera_.ortho = false;autoOrtho_ = false;- camera_.frame(sceneBounds());+ frameView(sceneBounds());status_ = "View reset";}@@ -2052,9 +2052,10 @@ void App::rollBy(float x, float y, float dx, float dy) {}float App::rollSweep(float x, float y, float dx, float dy) const {- // The angle the cursor sweeps around the canvas centre (near the centre, a sideways drag turns by its length).+ // The angle the cursor sweeps around the view's centre (near the centre, a sideways drag turns by its length):+ // where the target is on screen, off the canvas centre by the lens shift (Camera::frame).const CanvasRect c = canvasRect();- const glm::vec2 centre(c.x + c.w * 0.5f, c.y + c.h * 0.5f);+ const glm::vec2 centre(c.x + c.w * 0.5f * (1.0f + camera_.shift.x), c.y + c.h * 0.5f * (1.0f - camera_.shift.y));const glm::vec2 now(x, y), before(x - dx, y - dy);float angle = 0.0f;if (glm::length(now - centre) > 20.0f && glm::length(before - centre) > 20.0f) {@@ -2724,11 +2725,11 @@ void App::runCommand(const std::string& name, const Args& args) {if (r.ok && (name == "new_sphere" || name == "new_plane" || name == "new_head" || name == "new_starter_mesh" ||name == "open_obj" || name == "open" || name == "image_relief" || name == "image_inflate" || name == "splat_to_mesh" ||(name == "splat_transform" && args.contains("fit"))))- camera_.frame(sceneBounds());+ frameView(sceneBounds());// A new Part lands beside the model: bring it into view only if it isn't already.if (r.ok && (name == "part_append" || name == "part_duplicate" || name == "part_duplicate_linked") &&!onScreen(doc_.partBounds(doc_.activePart)))- camera_.frame(sceneBounds());+ frameView(sceneBounds());afterCommand(name, args, r);afterVdmCommand(name, r); // the VDM brush after vdm_set / vdm_capture, the top view after vdm_new_planewatchActiveBrush();@@ -2922,7 +2923,7 @@ void App::processPendingFiles() {case FileAction::SaveProject: saveProjectTo(f.path); break;case FileAction::AppendPart:runCommand("part_append", {{"path", f.path}});- if (lastCommandOk_) camera_.frame(sceneBounds()); // a model can be any size, anywhere+ if (lastCommandOk_) frameView(sceneBounds()); // a model can be any size, anywherebreak;case FileAction::ComfyWorkflow: setComfyWorkflow(f.path, comfyPickingText_); break;case FileAction::LoadLitSphere: runCommand("load_litsphere", {{"path", f.path}}); break;diff --git a/src/app/App.h b/src/app/App.hindex 77c9660b..772fcc5e 100644--- a/src/app/App.h+++ b/src/app/App.h@@ -1734,6 +1734,10 @@ private:public:// The part of the window the 3D view uses (logical px); the whole window while the UI is hidden.CanvasRect canvasRect() const;+ // The part of the canvas no band covers (the open Library, the Sculpt Timeline strip), as fractions of the+ // canvas from its top left (x0, y0, x1, y1): what framing fits the model into.+ glm::vec4 freeCanvasArea() const;+ void frameView(const AABB& box); // camera_.frame into freeCanvasArea()ShellGeometry shellGeometry() const; // every shell region for the current window (console rect, trays...)// Preferences > Interface > Look: applies uiPrefs_.look (colours, style, fonts, the viewport background).void applyLook();@@ -1937,6 +1941,8 @@ 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+ float shelfFit_[4] = {1.0f, 1.0f, 1.0f, 1.0f}; // a side shelf's tiles and colour picker shrink (to 0.6) before it scrolls+ int shelfClipped_[4] = {0, 0, 0, 0}; // items past a side shelf's visible bottom last frame (UI tests)// 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;@@ -2741,6 +2747,7 @@ private:float timelineTopInset_ = 0.0f; // how far down the canvas the strip (or its tab) reaches at the top; 0 at the bottomfloat timelineStripY_ = -1.0f; // the strip's (or tab's) top edge in window pixels this frame (-1: not shown)float timelineStripH_ = 0.0f; // and its height (UI tests: timeline_height)+ bool timelineDrawn_ = false; // drawTimelineUi has run (before it, framing assumes the strip at its default)void registerTimelineUiActions(); // view.timeline, timeline.timelapse, help.benchmarkvoid startTimelapse(const std::string& path, int width, int height, float seconds, int fps);bool timelapseStep(double budgetSeconds); // renders frames for up to the budget; false when finisheddiff --git a/src/app/Config.cpp b/src/app/Config.cppindex d391a5a5..93af069a 100644--- a/src/app/Config.cpp+++ b/src/app/Config.cpp@@ -735,7 +735,7 @@ void App::initActions() {add("view.wireframe", "Wireframe", "Render", "Shift+F", [this] { renderSettings_.wireframe = !renderSettings_.wireframe; },ICON_LC_GRID_3X3, nullptr, [this] { return renderSettings_.wireframe; }, nullptr,"Show the mesh's polygons (quads and triangles) over the surface.");- add("view.frame", "Frame model", "Transform", "F", [this] { camera_.frame(sceneBounds()); }, ICON_LC_SCAN, nullptr, nullptr,+ add("view.frame", "Frame model", "Transform", "F", [this] { frameView(sceneBounds()); }, ICON_LC_SCAN, nullptr, nullptr,nullptr, "Fit the whole model in the view.");add("color.pick", "Pick colour", "Color", "C", [this] { pickColorUnderCursor(); }, ICON_LC_PIPETTE, nullptr, nullptr, nullptr,"Take the paint colour from the model under the cursor.");diff --git a/src/app/Input.cpp b/src/app/Input.cppindex 998693dd..f6a6bcd7 100644--- a/src/app/Input.cpp+++ b/src/app/Input.cpp@@ -459,8 +459,8 @@ void App::viewOrbitStep(float yawDegrees, float pitchDegrees) {void App::frameActivePart() {const AABB b = doc_.partBounds(doc_.activePart); // (where it is: a moved linked copy, #94)- if (b.valid()) camera_.frame(b);- else camera_.frame(sceneBounds());+ if (b.valid()) frameView(b);+ else frameView(sceneBounds());}SDL_Keymod App::blenderMods(SDL_Keymod keyboard) const {diff --git a/src/app/LibraryBrowser.cpp b/src/app/LibraryBrowser.cppindex eeaf0748..71b80f93 100644--- a/src/app/LibraryBrowser.cpp+++ b/src/app/LibraryBrowser.cpp@@ -484,7 +484,7 @@ void LibraryBrowser::activate(App& app, const AssetEntry& e, bool append) {app.runCommand("new_plane");else {app.runCommand("new_cube");- if (app.lastCommandOk_) app.camera_.frame(app.sceneBounds());+ if (app.lastCommandOk_) app.frameView(app.sceneBounds());}});return;diff --git a/src/app/PanelAiLink.cpp b/src/app/PanelAiLink.cppindex 456cc95e..d53ae110 100644--- a/src/app/PanelAiLink.cpp+++ b/src/app/PanelAiLink.cpp@@ -540,15 +540,15 @@ bool App::aiApplyView(const Args& args, std::string& error) {camera_.pitch = -glm::radians(std::clamp(float(argNumber(args, "elevation", 0.0)), -89.0f, 89.0f)), camera_.roll = 0.0f;if (args.contains("ortho")) camera_.ortho = argBool(args, "ortho", false), autoOrtho_ = false;const std::string frame = argString(args, "frame");- if (frame == "all") camera_.frame(sceneBounds());- else if (frame == "active") camera_.frame(doc_.mesh.bounds());+ if (frame == "all") frameView(sceneBounds());+ else if (frame == "active") frameView(doc_.mesh.bounds());else if (!frame.empty()) {const int i = doc_.findPart(frame);if (i < 0) {error = "No Part \"" + frame + "\" (see scene_overview)";return false;}- camera_.frame(doc_.partMesh(i).bounds());+ frameView(doc_.partMesh(i).bounds());}if (args.contains("zoom")) {const float z = float(argNumber(args, "zoom", 1.0));diff --git a/src/app/PanelBlender.cpp b/src/app/PanelBlender.cppindex bc80b1a4..d17a0876 100644--- a/src/app/PanelBlender.cpp+++ b/src/app/PanelBlender.cpp@@ -67,7 +67,7 @@ void App::receiveFromBlender() {blenderSeenRevision_ = bridgeRevision(blenderInbox(root));}runCommand("blender_receive");- if (status_.rfind("Received", 0) == 0) camera_.frame(sceneBounds());+ if (status_.rfind("Received", 0) == 0) frameView(sceneBounds());}void App::drawBlenderMenu() {diff --git a/src/app/PanelBridge.cpp b/src/app/PanelBridge.cppindex 43b699ea..61c414db 100644--- a/src/app/PanelBridge.cpp+++ b/src/app/PanelBridge.cpp@@ -43,7 +43,7 @@ void App::runBridgeCommand(const std::string& name, const Args& args) {// A new mesh arrived: frame it (runCommand does this for "open").if ((name == "bridge_receive" || name == "bridge_import") &&(status_.rfind("Received", 0) == 0 || status_.rfind("Opened", 0) == 0))- camera_.frame(sceneBounds());+ frameView(sceneBounds());if (name == "bridge_send") bridgeListTime_ = fileTime(bridgeObjectListPath(bridgeFolder_[0] ? bridgeFolder_ : bridgeDefaultRoot()));}diff --git a/src/app/PanelMaya.cpp b/src/app/PanelMaya.cppindex 58070f7b..96934fc9 100644--- a/src/app/PanelMaya.cpp+++ b/src/app/PanelMaya.cpp@@ -427,7 +427,7 @@ void App::receiveFromMaya() {if (was == before.end() || was->second != revision) mayaLiveSeen_[id] = {revision, 0};}// (Live keeps the view: Maya's edits arrive while you look at them.)- if (status_.rfind("Received", 0) == 0 && !uiPrefs_.mayaLive) camera_.frame(sceneBounds());+ if (status_.rfind("Received", 0) == 0 && !uiPrefs_.mayaLive) frameView(sceneBounds());}void App::drawMayaMenu() {diff --git a/src/app/PanelParts.cpp b/src/app/PanelParts.cppindex e730ded6..cdf68ede 100644--- a/src/app/PanelParts.cpp+++ b/src/app/PanelParts.cpp@@ -153,7 +153,7 @@ void App::partClickRelease() {runCommand("part_select", {{"index", double(partClickTarget_)}});partSelected("Alt+click");}- if (partClickFrame_) camera_.frame(doc_.partBounds(doc_.activePart)); // Shift+Alt+click: frame it too+ if (partClickFrame_) frameView(doc_.partBounds(doc_.activePart)); // Shift+Alt+click: frame it too}partClickTarget_ = -1;partClickFrame_ = false;diff --git a/src/app/PanelPhone.cpp b/src/app/PanelPhone.cppindex 53740845..5140e066 100644--- a/src/app/PanelPhone.cpp+++ b/src/app/PanelPhone.cpp@@ -198,7 +198,7 @@ void App::handlePhoneCapture(const link::PhoneEvent& e) {// Splats load next to the sculpt; a mesh .ply becomes a new Part (never replacing the work).if (ext == ".splat" || plyHasSplats(file)) runCommand("open", {{"path", file}});else runCommand("part_append", {{"path", file}});- if (lastCommandOk_) camera_.frame(sceneBounds());+ if (lastCommandOk_) frameView(sceneBounds());return;}case link::CaptureKind::Face: return;diff --git a/src/app/PanelProject.cpp b/src/app/PanelProject.cppindex ef268170..b7282c1f 100644--- a/src/app/PanelProject.cpp+++ b/src/app/PanelProject.cpp@@ -383,6 +383,8 @@ void App::storeProjectSettings() {cam.set("pitch", double(camera_.pitch));cam.set("roll", double(camera_.roll));cam.set("fov_y", double(camera_.fovY));+ cam.set("shift_x", double(camera_.shift.x));+ cam.set("shift_y", double(camera_.shift.y));s.set("camera", std::move(cam));Json views = Json::array();for (const SavedView& v : savedViews_) {@@ -395,6 +397,8 @@ void App::storeProjectSettings() {o.set("roll", double(v.camera.roll));o.set("fov_y", double(v.camera.fovY));o.set("ortho", v.camera.ortho);+ o.set("shift_x", double(v.camera.shift.x));+ o.set("shift_y", double(v.camera.shift.y));views.push(std::move(o));}s.set("views", std::move(views));@@ -509,6 +513,10 @@ void App::applyProjectSettings() {camera_.roll = 0.0f; // projects from before free rotation have nonereadFloat(cam, "roll", camera_.roll);readFloat(cam, "fov_y", camera_.fovY);+ camera_.shift = glm::vec2(0.0f); // projects from before the lens shift have none+ readFloat(cam, "shift_x", camera_.shift.x);+ readFloat(cam, "shift_y", camera_.shift.y);+ camera_.shift = glm::clamp(camera_.shift, glm::vec2(-1.0f), glm::vec2(1.0f));camera_.distance = std::max(camera_.distance, 1e-4f);camera_.fovY = std::clamp(camera_.fovY, 0.05f, 3.0f);}@@ -526,6 +534,10 @@ void App::applyProjectSettings() {readFloat(o, "roll", v.camera.roll);readFloat(o, "fov_y", v.camera.fovY);readBool(o, "ortho", v.camera.ortho);+ v.camera.shift = glm::vec2(0.0f);+ readFloat(o, "shift_x", v.camera.shift.x);+ readFloat(o, "shift_y", v.camera.shift.y);+ v.camera.shift = glm::clamp(v.camera.shift, glm::vec2(-1.0f), glm::vec2(1.0f));v.camera.distance = std::max(v.camera.distance, 1e-4f);v.camera.fovY = std::clamp(v.camera.fovY, 0.05f, 3.0f);savedViews_.push_back(std::move(v));@@ -688,7 +700,7 @@ void App::afterCommand(const std::string& name, const Args& args, const CommandRconst std::string path = argString(args, "path", doc_.path);const bool project = name == "open_project" || (name == "open" && isProjectPath(path));if (project) {- if (!doc_.projectSettings["camera"].isObject()) camera_.frame(sceneBounds()); // e.g. saved by the CLI+ if (!doc_.projectSettings["camera"].isObject()) frameView(sceneBounds()); // e.g. saved by the CLIapplyProjectSettings(); // after runCommand framed the camera, so the saved view wins}if (project || name == "open" || name == "open_obj" || name == "save_project" || name == "save_obj")diff --git a/src/app/PanelSculptable.cpp b/src/app/PanelSculptable.cppindex a0f9d4e9..ede0df4f 100644--- a/src/app/PanelSculptable.cpp+++ b/src/app/PanelSculptable.cpp@@ -298,7 +298,7 @@ void App::pollSculptable() {lastCommandOk_ = true;clearLods();playingLayer_ = -1;- if (!onScreen(doc_.partBounds(doc_.activePart))) camera_.frame(sceneBounds());+ if (!onScreen(doc_.partBounds(doc_.activePart))) frameView(sceneBounds());updateTitle();consoleEcho("splat_to_mesh", job->args, r);}diff --git a/src/app/PanelSplatTrain.cpp b/src/app/PanelSplatTrain.cppindex 1a08e54e..9ad55ccd 100644--- a/src/app/PanelSplatTrain.cpp+++ b/src/app/PanelSplatTrain.cpp@@ -291,7 +291,7 @@ void App::pollSplatTrain() {renderSettings_.showMesh = false;status_ = "Showing the splat as it trains (Splats > Show mesh brings the sculpt back)";}- camera_.frame(sceneBounds());+ frameView(sceneBounds());}}if (s.job.busy()) return;diff --git a/src/app/PanelTimeline.cpp b/src/app/PanelTimeline.cppindex 186aa872..c3a3063f 100644--- a/src/app/PanelTimeline.cpp+++ b/src/app/PanelTimeline.cpp@@ -348,6 +348,11 @@ int App::runTimelapseCli() {}void App::drawTimelineUi() {+ // What the strip covers this frame (set where it is drawn below); framing keeps the model clear of it.+ timelineTopInset_ = 0.0f;+ timelineStripY_ = -1.0f;+ timelineStripH_ = 0.0f;+ timelineDrawn_ = true;if (!timelineUi_) timelineUi_ = std::make_shared<TimelineUiState>();TimelineUiState& s = *timelineUi_;if (!s.loaded) {@@ -420,9 +425,6 @@ void App::drawTimelineUi() {if (!layout_.libraryBottom) c.y += lib;c.h -= lib;}- timelineTopInset_ = 0.0f;- timelineStripY_ = -1.0f;- timelineStripH_ = 0.0f;if (c.w < 200 || c.h < 150 || hideUi_) return;const float margin = 10 * sc;if (!s.visible) {diff --git a/src/app/PanelUvEditor.cpp b/src/app/PanelUvEditor.cppindex db562ede..9ceafe1b 100644--- a/src/app/PanelUvEditor.cpp+++ b/src/app/PanelUvEditor.cpp@@ -881,7 +881,7 @@ void App::registerUvEditorActions() {showUvEditor_ = !showUvEditor_;if (showUvEditor_) { // the model to the left of the window, which opens over the right of the canvasconst CanvasRect cr = canvasRect();- camera_.frame(sceneBounds());+ frameView(sceneBounds());camera_.zoom(-1.5f);camera_.pan(-cr.w * 0.33f, 0.0f, cr.h);}diff --git a/src/app/PanelVdm.cpp b/src/app/PanelVdm.cppindex 04972af5..e33aca16 100644--- a/src/app/PanelVdm.cpp+++ b/src/app/PanelVdm.cpp@@ -122,7 +122,7 @@ void App::afterVdmCommand(const std::string& name, const CommandResult& r) {paintMode_ = false;} else if (name == "vdm_new_plane") { // sculpt it from the top, like the map sees itcamera_.setOrientation(glm::angleAxis(-1.5707963f, glm::vec3(1.0f, 0.0f, 0.0f)));- camera_.frame(doc_.mesh.bounds());+ frameView(doc_.mesh.bounds());}}diff --git a/src/app/Shell.cpp b/src/app/Shell.cppindex 9bc99f1a..c61e9565 100644--- a/src/app/Shell.cpp+++ b/src/app/Shell.cpp@@ -245,6 +245,23 @@ std::string elide(ImFont* font, const std::string& text, float width) {return s + "...";}+// A left shelf caption: at its font's size, else smaller down to 80 % of it (still readable), else none, so a+// column shrunk to fit (App::shelfFit_) never shows a cut word ("Stan..."); the tile's tooltip names it then.+// Returns false when it was left out.+bool fitCaption(ImDrawList* dl, ImFont* font, ImVec2 a, ImVec2 b, ImU32 col, const std::string& text) {+ if (!font) font = ImGui::GetFont();+ const float width = b.x - a.x;+ const float full = font->CalcTextSizeA(font->FontSize, FLT_MAX, 0.0f, text.c_str()).x;+ float size = font->FontSize;+ if (full > width) {+ size = std::floor(font->FontSize * width / std::max(full, 1.0f)); // text width scales with the size+ if (size < font->FontSize * 0.8f) return false;+ }+ const ImVec2 ts = font->CalcTextSizeA(size, FLT_MAX, 0.0f, text.c_str());+ dl->AddText(font, size, ImVec2(std::floor((a.x + b.x - ts.x) * 0.5f), std::floor((a.y + b.y - ts.y) * 0.5f)), col, text.c_str());+ return true;+}+constexpr float kPointsReadoutW = 190.0f; // the ActiveTris / TotalTris readout at the right of the top shelf, unscaledconstexpr float kMicroReadoutW = 100.0f; // ... and its "Micro 300.00M" in front while a visible Part has a micro level (#125)@@ -298,6 +315,8 @@ bool drawShelfTile(App& app, const Action& a, ImVec2 size) {ImDrawList* dl = ImGui::GetWindowDrawList();const float alpha = disabled ? 0.4f : 1.0f;ImFont* caption = look == int(ui::Look::IconLabel) ? app.fontTiny_ : app.fontSmall_;+ // On the left shelf (Stroke popup) a caption that doesn't fit is shrunk or left out, never cut (fitCaption).+ const bool leftShelf = std::strcmp(ImGui::GetCurrentWindow()->Name, kShelfWindows[kShelfLeft]) == 0;const float capH = caption ? caption->FontSize + 2.0f * s : 14.0f * s;if (look == int(ui::Look::IconLabel)) {// Right-shelf toggles are options (Mask, Paint, Wire): on is a raised grey with an accent bar down the@@ -315,8 +334,11 @@ bool drawShelfTile(App& app, const Action& a, ImVec2 size) {// off doesn't look disabled); disabled items are faded by alpha.const ImU32 fg = theme::u32(on ? (mode ? theme::textOnAccent : theme::textBright) : hovered || !a.checked ? theme::text : theme::textOff, alpha);centredText(dl, app.fontIcons_, p0, ImVec2(p1.x, p1.y - capH + 2.0f * s), fg, a.icon ? a.icon : "?");- centredText(dl, caption, ImVec2(p0.x, p1.y - capH), ImVec2(p1.x, p1.y - 1.0f * s), fg,- elide(caption ? caption : ImGui::GetFont(), label, size.x - 2.0f * s).c_str());+ if (!leftShelf)+ centredText(dl, caption, ImVec2(p0.x, p1.y - capH), ImVec2(p1.x, p1.y - 1.0f * s), fg,+ elide(caption ? caption : ImGui::GetFont(), label, size.x - 2.0f * s).c_str());+ else if (!fitCaption(dl, caption, ImVec2(p0.x + 1.0f * s, p1.y - capH), ImVec2(p1.x - 1.0f * s, p1.y - 1.0f * s), fg, label) && hovered)+ ui::DelayedTooltip(label.c_str());return clicked;}// Tile: a square picture (brush thumbnail or icon) with the name under it.@@ -345,8 +367,14 @@ bool drawShelfTile(App& app, const Action& a, ImVec2 size) {const std::string key = app.actions().shortcutText(a.id);if (key.size() == 1 && caption)dl->AddText(caption, caption->FontSize, ImVec2(p0.x + 3 * s, p0.y + 1 * s), theme::u32(theme::textDim), key.c_str());- centredText(dl, caption, ImVec2(p0.x, p1.y - capH), p1, theme::u32(on ? theme::accent : theme::text, alpha),- elide(caption ? caption : ImGui::GetFont(), label, size.x).c_str());+ if (leftShelf) {+ if (!fitCaption(dl, caption, ImVec2(p0.x, p1.y - capH), p1, theme::u32(on ? theme::accent : theme::text, alpha), label) &&+ hovered)+ ui::DelayedTooltip(label.c_str());+ } else {+ centredText(dl, caption, ImVec2(p0.x, p1.y - capH), p1, theme::u32(on ? theme::accent : theme::text, alpha),+ elide(caption ? caption : ImGui::GetFont(), label, size.x).c_str());+ }return clicked;}@@ -518,7 +546,7 @@ void App::registerShellActions() {// View (right shelf, Render palette). Frame keeps F; its short label fits the right shelf.add({"view.frame", "Frame", ICON_LC_SCAN, "Fit the whole model in the view.", "Transform", "F", "",- [this] { camera_.frame(sceneBounds()); }, nullptr, nullptr});+ [this] { frameView(sceneBounds()); }, nullptr, nullptr});flag("view.wire", "Wire", ICON_LC_GRID_3X3, "Render", "", &renderSettings_.wireframe,"Wireframe: show the polygons of the active Part (Shift+F).");flag("view.facegroups", "Groups", ICON_LC_SHAPES, "Render", "", &renderSettings_.showFaceGroups,@@ -853,6 +881,30 @@ CanvasRect App::canvasRect() const {return c;}+glm::vec4 App::freeCanvasArea() const {+ const CanvasRect c = canvasRect();+ if (hideUi_ || c.w < 1.0f || c.h < 1.0f) return glm::vec4(0.0f, 0.0f, 1.0f, 1.0f);+ float top = c.y, bottom = c.y + c.h;+ if (libraryBrowser_.open()) { // as drawTimeline places the strip beside it+ const float lib = std::min(LibraryBrowser::height(layout_, uiScale_), c.h);+ if (layout_.libraryBottom) bottom -= lib;+ else top += lib;+ }+ if (timelineStripY_ >= 0.0f) { // the strip (or its tab) as last drawn+ if (uiPrefs_.timelineTop) top = std::max(top, timelineStripY_ + timelineStripH_);+ else bottom = std::min(bottom, timelineStripY_);+ } else if (!timelineDrawn_) { // not drawn yet (the model at startup): as the bare compact strip will be (margin, row)+ const float h = (6.0f + 2.0f * 3.0f + 20.0f) * uiScale_;+ if (uiPrefs_.timelineTop) top += h;+ else bottom -= h;+ }+ // Nothing sensible left (a tiny window): the whole canvas.+ if (bottom - top < c.h * 0.25f) return glm::vec4(0.0f, 0.0f, 1.0f, 1.0f);+ return glm::vec4(0.0f, (top - c.y) / c.h, 1.0f, (bottom - c.y) / c.h);+}++void App::frameView(const AABB& box) { camera_.frame(box, freeCanvasArea()); }+void App::canvasRay(float x, float y, glm::vec3& origin, glm::vec3& dir) const {const CanvasRect c = canvasRect();camera_.screenRay(x - c.x, y - c.y, c.w, c.h, origin, dir);@@ -2287,11 +2339,37 @@ void App::drawShelf(int shelf, const CanvasRect& r) {}}+ // A side shelf taller than its column (the brush tiles and the colour picker at 150 % on a 1080p screen): its+ // tiles, the picker and the left shelf's action tiles shrink until everything fits, down to 0.6 of their size; past that the wheel scrolls it.+ // Their height is about proportional to the size (the captions aren't), so the next frame's fit is solved from+ // this one's and settles in a frame or two.+ if (vertical && !rects.empty()) {+ float scalable = 0.0f;+ for (size_t k = 0; k < rects.size(); ++k) {+ const std::string& id = list[size_t(indices[k])];+ // What shrinks: the tiles, the picker, and on the left shelf its action tiles (Stroke popup).+ if (id.rfind("widget.tile.", 0) == 0 || id == "widget.color" || (shelf == kShelfLeft && id != "sep" && actions_.find(id)))+ scalable += rects[k].GetHeight();+ }+ const float needed = rects.back().Max.y + ImGui::GetScrollY() - r.y + pad.y;+ shelfClipped_[shelf] = int(std::count_if(rects.begin(), rects.end(), [&](const ImRect& rc) { return rc.Max.y > r.y + r.h + 0.5f; }));+ float& fit = shelfFit_[shelf];+ if (scalable > 0.0f) {+ const float fixed = needed - scalable;+ const float want = std::clamp(fit * (r.h - 1.0f * s - fixed) / scalable, 0.6f, 1.0f);+ if (want < fit - 0.002f || want > fit + 0.02f) fit = want; // (growing back waits for a clear margin)+ } else {+ fit = 1.0f;+ }+ }+ImGuiWindow* window = ImGui::GetCurrentWindow();ImDrawList* dl = ImGui::GetWindowDrawList();- // Bottom shelf: the wheel scrolls it sideways when it doesn't fit.- if (shelf == kShelfBottom && ImGui::IsWindowHovered() && ImGui::GetIO().MouseWheel != 0.0f)- ImGui::SetScrollX(ImGui::GetScrollX() - ImGui::GetIO().MouseWheel * 60.0f * s);+ // Bottom shelf: the wheel scrolls it sideways when it doesn't fit; a side shelf, up and down.+ if ((shelf == kShelfBottom || vertical) && ImGui::IsWindowHovered() && ImGui::GetIO().MouseWheel != 0.0f) {+ if (vertical) ImGui::SetScrollY(ImGui::GetScrollY() - ImGui::GetIO().MouseWheel * 60.0f * s);+ else ImGui::SetScrollX(ImGui::GetScrollX() - ImGui::GetIO().MouseWheel * 60.0f * s);+ }if (layout_.customize)dashedRect(dl, ImVec2(r.x + 2.0f, r.y + 2.0f), ImVec2(r.x + r.w - 2.0f, r.y + r.h - 2.0f), theme::u32(theme::accent, 0.6f),4.0f * s);@@ -2454,7 +2532,7 @@ void App::drawShelfItem(int shelf, int index, const std::string& item, bool vert"Micro: the micro triangles of the visible Parts' micro levels (Geometry > Micro).","Draw");} else if (item.rfind("widget.tile.", 0) == 0) {- const float w = fitW((shell_.narrow ? 60.0f : 76.0f) * s);+ const float w = fitW(std::floor((shell_.narrow ? 60.0f : 76.0f) * s * shelfFit_[shelf]));const ImVec2 size(w, w + (fontSmall_ ? fontSmall_->FontSize : 12.0f) + 4.0f * s);centre(w);if (item == "widget.tile.brush") drawBrushTile("##tile.brush", size);@@ -2463,7 +2541,7 @@ void App::drawShelfItem(int shelf, int index, const std::string& item, bool vertelse if (item == "widget.tile.material") drawMaterialTile("##tile.material", size);else ImGui::Dummy(size);} else if (item == "widget.color") {- const float w = fitW((shell_.narrow ? 60.0f : 76.0f) * s);+ const float w = fitW(std::floor((shell_.narrow ? 60.0f : 76.0f) * s * shelfFit_[shelf]));centre(w);drawColorWidget(w);} else if (item == "widget.nav.move" || item == "widget.nav.zoom" || item == "widget.nav.rotate") {@@ -2535,7 +2613,7 @@ void App::drawShelfItem(int shelf, int index, const std::string& item, bool vertconst ImVec2 size = shelf == kShelfTop ? ImVec2(look == ui::Look::Icon ? rowH : 0.0f, rowH): shelf == kShelfRight ? ImVec2(fitW(44.0f * s), 40.0f * s): shelf == kShelfBottom ? ImVec2(bottomTileW_, shell::bottomShelfSize(layout_.shelfTiles).tileH * s)- : ImVec2(winW - 2.0f * padX, 60.0f * s);+ : ImVec2(winW - 2.0f * padX, std::floor(60.0f * s * shelfFit_[shelf]));centre(size.x);// Top shelf hierarchy, by meaning (docs/ui-design.md §10). Every item is the full row height in the same// font, so both rows share one baseline. Mode groups (Draw | Move | Scale | Rotate, Sculpt | Paint) and@@ -2819,8 +2897,8 @@ bool tileFrame(const char* id, ImVec2 size, ui::TileLift& lift, ImFont* font, copic1 = ImVec2(b.x, b.y - capH);dl->AddRectFilled(pic0, pic1, theme::u32(theme::tile), theme::rounding(4.0f * s));if (hovered) dl->AddRectFilled(pic0, pic1, theme::u32(theme::buttonHover, 0.45f), theme::rounding(4.0f * s)); // (a faint fill, no border)- centredText(dl, font, ImVec2(a.x, b.y - capH), b, theme::u32(hovered ? theme::text : theme::textDim),- elide(font ? font : ImGui::GetFont(), caption, size.x).c_str());+ if (!fitCaption(dl, font, ImVec2(a.x, b.y - capH), b, theme::u32(hovered ? theme::text : theme::textDim), caption) && hovered)+ ui::DelayedTooltip(caption.c_str()); // too narrow for its name (the column shrunk to fit): the name on hoverlift = ui::BeginTileLift(pic0, pic1); // the picture lifts, the caption staysdl->AddRectFilled(pic0, pic1, theme::u32(theme::tile), theme::rounding(4.0f * s));if (hovered) dl->AddRectFilled(pic0, pic1, theme::u32(theme::buttonHover, 0.45f), theme::rounding(4.0f * s)); // (a faint fill)diff --git a/src/app/Ui.cpp b/src/app/Ui.cppindex 73ed62d2..793dbb28 100644--- a/src/app/Ui.cpp+++ b/src/app/Ui.cpp@@ -567,6 +567,10 @@ bool ActionButton(App& app, const char* actionId, ImVec2 size, Look look) {const float s = uiScale();if (look == Look::Icon && !icon) look = Look::Label;if (look == Look::IconLabel && !icon) look = Look::Label;+ // Too narrow for its words (the left shelf's Fill when the column shrinks to fit, Shell.cpp): the icon alone.+ if (look == Look::IconLabel && size.x > 0.0f &&+ ImGui::CalcTextSize((std::string(icon) + " " + label).c_str()).x + 2.0f * ImGui::GetStyle().FramePadding.x > size.x)+ look = Look::Icon;if (look == Look::Icon && size.x <= 0.0f) size = ImVec2(ImGui::GetFrameHeight(), ImGui::GetFrameHeight());if (look == Look::Tile && size.x <= 0.0f) size = ImVec2(44.0f * s, 40.0f * s);diff --git a/src/app/UiTest.cpp b/src/app/UiTest.cppindex 022c3657..eab1be42 100644--- a/src/app/UiTest.cpp+++ b/src/app/UiTest.cpp@@ -301,6 +301,10 @@// shelf, px), title_height, glyphs_missing (glyphs drawn as "?" in the last frame),// glyphs_merged (typed characters taken from other fonts: SF_FALLBACK_FONTS, the system's),// font_atlas_kpx (the font atlas texture, thousands of pixels)+// expect_value model_top_clear / model_bottom_clear (px between the model's projected bounding box and the bands+// framing keeps it clear of: the open Library, the Sculpt Timeline strip; < 0: under one),+// camera_shift_y (the lens shift framing set, x1000; + up), left_column_clipped (left shelf+// items past its visible bottom)// expect_value look (0 Classic, 1 Forge Terminal, 2 Phosphor, 3 Blueprint), shell_layout (0 classic, 1 SculptForge)#include "app/App.h"#include "ai/Http.h"@@ -309,6 +313,7 @@#define SDL_PEN_INPUT_IN_PROXIMITY (1u << 31) // SDL 3.4's flag; older SDL 3 never sets it#endif#include "app/Demo.h"+#include "app/Shell.h"#include "app/Ui.h"#include "app/UserGlyphs.h"@@ -1140,6 +1145,27 @@ double Demo::query(const std::string& name, bool& known) const {if (name == "view_figure") return app_.uiPrefs_.showViewFigure ? 1.0 : 0.0;// The side view the axis gizmo names under it (0-5: +X +Y +Z -X -Y -Z, as axis_click), -1 between views.if (name == "axis_view") return double(axisGizmoAligned(app_.axisGizmoLayout()));+ // The model's projected bounding box against the free area framing fits it into (App::freeCanvasArea: the canvas+ // less the open Library and the Sculpt Timeline strip), px: >= 0 when it clears the band above (below) it.+ if (name == "model_top_clear" || name == "model_bottom_clear") {+ const auto c = app_.canvasRect();+ const glm::vec4 area = app_.freeCanvasArea();+ const AABB b = app_.sceneBounds();+ if (!b.valid()) return -1e9;+ const glm::mat4 vp = app_.camera_.projection() * app_.camera_.view();+ float top = 1e9f, bottom = -1e9f;+ for (int k = 0; k < 8; ++k) {+ const glm::vec3 p((k & 1) ? b.max.x : b.min.x, (k & 2) ? b.max.y : b.min.y, (k & 4) ? b.max.z : b.min.z);+ const glm::vec4 h = vp * glm::vec4(p, 1.0f);+ if (h.w <= 0.0f) return -1e9;+ const float y = c.y + (1.0f - h.y / h.w) * 0.5f * c.h;+ top = std::min(top, y);+ bottom = std::max(bottom, y);+ }+ return name == "model_top_clear" ? double(top - (c.y + area.y * c.h)) : double(c.y + area.w * c.h - bottom);+ }+ // Items of the left shelf (the brush tiles, the colour picker) past its visible bottom in the last frame.+ if (name == "left_column_clipped") return double(app_.shelfClipped_[kShelfLeft]);if (name == "timeline_y" || name == "axis_gizmo_y") {const auto c = app_.canvasRect();if (name == "timeline_y")@@ -1304,6 +1330,7 @@ double Demo::query(const std::string& name, bool& known) const {return app_.spaceMouseEcho(e) ? 1.0 : 0.0;}if (name == "camera_distance") return app_.camera_.distance;+ if (name == "camera_shift_y") return std::round(double(app_.camera_.shift.y) * 1000.0);if (name == "camera_pan") return glm::length(app_.camera_.target);if (name == "groups") {std::set<uint32_t> ids(m.facegroups.begin(), m.facegroups.end());diff --git a/src/render/Camera.cpp b/src/render/Camera.cppindex adc3b2b7..5fb4932a 100644--- a/src/render/Camera.cpp+++ b/src/render/Camera.cpp@@ -28,11 +28,14 @@ glm::mat4 Camera::view() const {}glm::mat4 Camera::projection() const {- if (!ortho) return glm::perspective(fovY, aspect, nearPlane(), farPlane());+ // The lens shift moves the image in clip space (scaled by w, so by `shift` after the divide).+ glm::mat4 lens(1.0f);+ lens[3] = glm::vec4(shift, 0.0f, 1.0f);+ if (!ortho) return lens * glm::perspective(fovY, aspect, nearPlane(), farPlane());// As tall as the perspective view at the target; the depth range reaches behind the eye, as in Blender, so// zooming in never clips the model.const float h = distance * std::tan(fovY * 0.5f);- return glm::ortho(-h * aspect, h * aspect, -h, h, -farPlane(), farPlane());+ return lens * glm::ortho(-h * aspect, h * aspect, -h, h, -farPlane(), farPlane());}void Camera::orbit(float dx, float dy) {@@ -93,18 +96,27 @@ void Camera::pan(float dx, float dy, float viewportHeight) {void Camera::zoom(float steps) { distance = std::clamp(distance * std::pow(0.88f, steps), 1e-4f, 1e6f); }-void Camera::frame(const AABB& box) {+void Camera::frame(const AABB& box, const glm::vec4& area) {if (!box.valid()) return;target = box.center();float radius = std::max(glm::length(box.extent()) * 0.5f, 1e-4f);- distance = radius / std::sin(fovY * 0.5f) * 1.1f;+ // The area's share of the view's height, or of its width if that is the tighter (in heights); the whole view+ // in a landscape window is 1, as before.+ const float x0 = std::clamp(area.x, 0.0f, 1.0f), y0 = std::clamp(area.y, 0.0f, 1.0f);+ const float x1 = std::clamp(area.z, x0, 1.0f), y1 = std::clamp(area.w, y0, 1.0f);+ float fit = std::min(y1 - y0, (x1 - x0) * std::max(aspect, 1e-3f));+ if (area == glm::vec4(0.0f, 0.0f, 1.0f, 1.0f)) fit = 1.0f; // the whole view: exactly as before+ fit = std::max(fit, 0.05f);+ const float half = std::atan(fit * std::tan(fovY * 0.5f));+ distance = radius / std::sin(half) * 1.1f;+ shift = glm::vec2(x0 + x1 - 1.0f, 1.0f - (y0 + y1));}void Camera::screenRay(float x, float y, float width, float height, glm::vec3& origin, glm::vec3& dir) const {// From the camera's own axes rather than by inverting projection * view: the same ray, without the matrix// inverse's rounding, so the brush lands under the cursor to a fraction of a pixel at any zoom.- const float nx = 2.0f * x / std::max(width, 1e-6f) - 1.0f;- const float ny = 1.0f - 2.0f * y / std::max(height, 1e-6f);+ const float nx = 2.0f * x / std::max(width, 1e-6f) - 1.0f - shift.x;+ const float ny = 1.0f - 2.0f * y / std::max(height, 1e-6f) - shift.y;const float t = std::tan(fovY * 0.5f);const glm::quat q = orientation();if (!ortho) {diff --git a/src/render/Camera.h b/src/render/Camera.hindex 86cd3b11..54505747 100644--- a/src/render/Camera.h+++ b/src/render/Camera.h@@ -21,6 +21,10 @@ public:float fovY = glm::radians(35.0f);float aspect = 1.0f;bool ortho = false; // orthographic: shows what a perspective view would at the target's depth (Numpad 5)+ // Lens shift in normalised device units: where the target lands off the view's centre. frame() sets it to the+ // centre of the free area it fits into (the canvas less the bands that cover it), so orbiting still turns about+ // the model and opening or closing a band doesn't move the view.+ glm::vec2 shift{0.0f};glm::quat orientation() const;glm::vec3 position() const;@@ -39,7 +43,9 @@ public:static glm::quat snapped(const glm::quat& q);void pan(float dxPixels, float dyPixels, float viewportHeight);void zoom(float steps);- void frame(const AABB& box);+ // The whole box in view, centred. `area` is the part of the view to fit it into, as fractions of the view's+ // width and height from its top left (x0, y0, x1, y1): the box is fitted to that and centred on it.+ void frame(const AABB& box, const glm::vec4& area = glm::vec4(0.0f, 0.0f, 1.0f, 1.0f));// Ray through a window coordinate (origin top-left).void screenRay(float x, float y, float width, float height, glm::vec3& origin, glm::vec3& dir) const;diff --git a/tests/test_camera.cpp b/tests/test_camera.cppindex 9a6957f5..09f91e71 100644--- a/tests/test_camera.cpp+++ b/tests/test_camera.cpp@@ -165,3 +165,38 @@ TEST(camera_orbit_lock_does_not_drift) {CHECK(near(glm::conjugate(c.orientation()) * axis, axisOnScreen, 1e-3f));}}++TEST(camera_frame_fits_the_free_area_and_rays_follow_the_shift) {+ // The lower 60 % of the view (bands across its top): the box's projection lies inside that area, centred on it,+ // and a ray cast through a pixel projects back onto it (the lens shift in both), perspective and orthographic.+ for (bool ortho : {false, true}) {+ Camera c;+ c.aspect = 16.0f / 9.0f;+ c.ortho = ortho;+ c.yaw = 0.4f;+ c.pitch = 0.3f;+ AABB box;+ box.expand(glm::vec3(-1.0f, -0.5f, -2.0f));+ box.expand(glm::vec3(1.5f, 2.0f, 0.5f));+ const glm::vec4 area(0.0f, 0.4f, 1.0f, 1.0f);+ c.frame(box, area);+ const glm::mat4 vp = c.projection() * c.view();+ for (int k = 0; k < 8; ++k) {+ const glm::vec3 p((k & 1) ? box.max.x : box.min.x, (k & 2) ? box.max.y : box.min.y, (k & 4) ? box.max.z : box.min.z);+ const glm::vec4 h = vp * glm::vec4(p, 1.0f);+ const float y = (1.0f - h.y / h.w) * 0.5f; // from the top+ CHECK(y > area.y && y < area.w);+ CHECK(std::abs(h.x / h.w) < 1.0f);+ }+ const glm::vec4 t = vp * glm::vec4(box.center(), 1.0f);+ CHECK(std::abs((1.0f - t.y / t.w) * 0.5f - 0.7f) < 1e-4f);+ glm::vec3 o, d;+ c.screenRay(300.0f, 700.0f, 1600.0f, 900.0f, o, d);+ const glm::vec4 q = vp * glm::vec4(o + d * (glm::length(c.position() - c.target)), 1.0f);+ CHECK(std::abs((q.x / q.w + 1.0f) * 0.5f * 1600.0f - 300.0f) < 0.05f);+ CHECK(std::abs((1.0f - q.y / q.w) * 0.5f * 900.0f - 700.0f) < 0.05f);+ // The whole view: centred, no shift, as before.+ c.frame(box);+ CHECK(c.shift == glm::vec2(0.0f));+ }+}diff --git a/tests/ui/hidpi/frame_free_area.sfui b/tests/ui/hidpi/frame_free_area.sfuinew file mode 100644index 00000000..b173d48d--- /dev/null+++ b/tests/ui/hidpi/frame_free_area.sfui@@ -0,0 +1,53 @@+# Framing fits the model into the canvas the overlays leave free (the open Library along the top, the Sculpt Timeline+# strip under it), and every left shelf item stays in view: run at 1920x1080 by CMake (ui_frame_free_area_1080), at+# UI scale 100 / 150 / 200 (ui-compact's shots: at 200 % the sphere's top sat under the bands; at 150 % the colour+# picker ran under the bottom shelf). The left shelf settles its fit in a frame or two after a scale change (wait_value).+run new_sphere subdivisions=3+expect_value model_top_clear >= 0+expect_value model_bottom_clear >= 0+key ,+expect_value library_open == 1+click "Library/Tool"+wait_idle 30++ui_scale 100+wait_idle 10+key f+wait_idle 5+expect_value model_top_clear >= 0+expect_value model_bottom_clear >= 0+wait_value left_column_clipped == 0 5+shot s100++ui_scale 150+wait_idle 10+key f+wait_idle 5+expect_value model_top_clear >= 0+expect_value model_bottom_clear >= 0+wait_value left_column_clipped == 0 5+shot s150++ui_scale 200+wait_idle 10+key f+wait_idle 5+expect_value model_top_clear >= 0+expect_value model_bottom_clear >= 0+wait_value left_column_clipped == 0 5+expect_value camera_shift_y < 0+shot s200++# Closing the Library doesn't move the view (the lens shift stays until the next Frame); framing again centres the+# model in the larger free area.+key ,+expect_value library_open == 0+wait_idle 5+expect_value camera_shift_y < 0+expect_value model_top_clear >= 0+key f+wait_idle 5+expect_value model_top_clear >= 0+expect_value model_bottom_clear >= 0+shot s200-closed+ui_scale 100