From 63f210b49fa1d3eba4c2fb540d02c7465969b838 Mon Sep 17 00:00:00 2001 From: Nathan Dane Date: Wed, 21 Oct 2026 18:56:55 +0000 Subject: [PATCH] Restyle the vertical history sidebar (#2028) (#3953) * Vertical history strip: left of the browser, compact rows, hollow-circle marker, collapsed rail hover * Vertical history strip: seam handle to expand and collapse names, drag to resize with snap * Vertical history strip: no empty gap below the transport * Show the history seam arrow only on hover (#2028) * Extract a shared panel drag grip * Rebuild responsive history sizing and three-way docking * Share browser and History collapse hover styling * Show the History title as soon as its text fits * Animate stacked browser and History expansion and collapse * Make panel folding responsive and independent of frame delays * Let folding panel contents shrink continuously to header height * Use four explicit History transport actions in every layout * Resize the shared Browser and History column from either card --- ROADMAP.md | 2 +- assets/locales/cs.json | 6 + assets/locales/da.json | 6 + assets/locales/de.json | 6 + assets/locales/en.json | 16 +- assets/locales/es.json | 6 + assets/locales/fr.json | 6 + assets/locales/gl.json | 6 + assets/locales/hu.json | 6 + assets/locales/id.json | 6 + assets/locales/it.json | 6 + assets/locales/ja.json | 16 +- assets/locales/ko.json | 6 + assets/locales/ms.json | 6 + assets/locales/nl.json | 6 + assets/locales/pl.json | 6 + assets/locales/pt-BR.json | 6 + assets/locales/ro.json | 6 + assets/locales/ru.json | 6 + assets/locales/sv.json | 6 + assets/locales/tr.json | 6 + assets/locales/uk.json | 6 + assets/locales/vi.json | 6 + assets/locales/zh-TW.json | 6 + assets/locales/zh.json | 16 +- crates/engine/src/cmd/view_navigation.rs | 40 + crates/ui-egui/src/agent_chat/panel.rs | 10 +- crates/ui-egui/src/browser.rs | 167 ++-- crates/ui-egui/src/browser_card_tests.rs | 57 ++ crates/ui-egui/src/control.rs | 2 +- crates/ui-egui/src/lib.rs | 52 +- crates/ui-egui/src/prefs.rs | 25 +- crates/ui-egui/src/shell.rs | 10 + crates/ui-egui/src/shell_tests.rs | 19 +- crates/ui-egui/src/timeline.rs | 143 ++-- crates/ui-egui/src/timeline_left.rs | 942 +++++++++++++++++++---- crates/ui-egui/src/ui_kit/disclosure.rs | 15 +- crates/ui-egui/src/ui_kit/gallery.rs | 210 ++++- crates/ui-egui/src/ui_kit/history.rs | 687 +++++++++++++++++ crates/ui-egui/src/ui_kit/mod.rs | 4 +- crates/ui-egui/src/ui_kit/panel.rs | 6 + crates/ui-egui/tests/icon_audit.rs | 8 +- docs/book/src/guide/ui-tour.md | 5 +- docs/control-protocol.md | 1 + docs/ui-kit.md | 33 + 45 files changed, 2232 insertions(+), 380 deletions(-) create mode 100644 crates/ui-egui/src/ui_kit/history.rs diff --git a/ROADMAP.md b/ROADMAP.md index c269a33ec..592b07a55 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -55,7 +55,7 @@ PCB / Package, Render, Animation, Simulation, Manufacture/CAM, Drawings. | M3 | General fillets and chamfers (curved edges, chains, vertex blends); saddle rolling-ball surfaces now use continuous seam sections and arc-length fitting with shared contact boundaries and bounded accuracy checks; tiny rim edges remain selected instead of nearby wall seams when filleting (#2498) | in progress | 30 | | M4 | Files: STEP import (done — [docs/step-import.md](docs/step-import.md)), FreeCAD/Rhino solids through cadmpeg (done, desktop and CLI), 3MF export and 3MF/STL import as mesh bodies (done), 3MF with B-rep face tags ([docs/formats/3mf-face-tags.md](docs/formats/3mf-face-tags.md), done), constant-section parametric mesh reconstruction, DXF sketches, OBJ import | in progress | 6 | | M5 | Persistent naming of faces and edges (docs/book/src/dev/naming.md): faces named from their exact kernel-reported history (sketch curve sides, caps, revolve sections, primitive sides, blends, shell inner walls, pattern/mirror copies; split pieces told apart by the faces around them, lumps of a cut body named after their faces), edges by their faces; fillets/chamfers, sketches on faces, shell/draft/offset/replace faces, hole placements, joint origins and face appearances resolve by name first and warn when the entity split or vanished: done. sheet metal edges by base sketch line and flange side, shell inner faces, sweep and loft roles: done. kernel-reported face history: done (merged faces answer to every name; operations without history yet fall back to geometric names, flagged unverified; format 14 keeps older designs' geometric names). Left: history through sheet metal, plastic, surface and emboss features; FaceSource certificates through history | in progress | 20 | -| M6 | UI depth: selection feedback and origin (done), timeline editing (done: hover and selection highlight modifier faces, including fillets and chamfers; edit feature, history marker drag, dependency-checked single and multi-item reorder, suppress, rename, delete with dependents, re-resolved references; redefining selections refreshes persistent edge/face references while retaining feature identity and dimension names; optional compact named left feature history with rollback bar, multi-selection and persistent folders above the parts browser), right-docked dialogs (done), live previews for every feature dialog (done), keyboard-first commands with on-canvas value boxes and sketch inline dimensions (done), drag manipulators with automatic join/cut (done: extrude incl. two sides, fillet, shell, hole depth, move, pattern spacing, revolve rotator, extrude taper), dark theme (done), right-click menu with Repeat (done), measure tool (done), section analysis (done), selection filter (done), drag-solve of sketch points (done); appearance controls now preserve body/face/component targeting, named transparent looks, reuse/search and override removal; preferences | in progress | 6 | +| M6 | UI depth: selection feedback and origin (done), timeline editing (done: hover and selection highlight modifier faces, including fillets and chamfers; edit feature, history marker drag, dependency-checked single and multi-item reorder, suppress, rename, delete with dependents, re-resolved references; redefining selections refreshes persistent edge/face references while retaining feature identity and dimension names; responsive feature history with width-driven icons/names/title, snapping width resize, bottom/left/browser-stack docking, shared-column collapse, rollback bar, multi-selection and persistent folders), right-docked dialogs (done), live previews for every feature dialog (done), keyboard-first commands with on-canvas value boxes and sketch inline dimensions (done), drag manipulators with automatic join/cut (done: extrude incl. two sides, fillet, shell, hole depth, move, pattern spacing, revolve rotator, extrude taper), dark theme (done), right-click menu with Repeat (done), measure tool (done), section analysis (done), selection filter (done), drag-solve of sketch points (done); appearance controls now preserve body/face/component targeting, named transparent looks, reuse/search and override removal; preferences | in progress | 6 | | M7 | Thin extrude (walls along open or closed curves: centre, inside, outside or two sides; mitred corners, crossing walls joined; #721), sweep, loft (incl. to a point), rib and web (to next / depth), emboss (planar faces and exact radial emboss/deboss of bounded orthogonal profiles on complete exterior cylinders/sleeves), thread (cosmetic, and modelled M3–M20 outside and inside: the ISO profile screwed in as a faceted cut), coil (smooth B-spline helical walls), pipe, pattern on path, patterns of bodies and components, replace face (parallel), align, remove, feature copy/paste: done. Unique eligible cylindrical targets are inferred for new Emboss features. Left: general curved-face emboss and exact (unfaceted) modelled threads | in progress | 12 | | M8 | Surface workspace (#772). Done: Patch (sketch regions; edge loops filled G0, plus `crown`), Stitch, Thicken (planes and cylinders), Extend (straight edges of planar surfaces), Trim (by a plane, a face or sketch curves swept onto the surface, keeping a side or the picked regions; mutual trim of two surfaces, extended to meet and stitched, #767), Delete Face (healing), Boundary Fill, zebra/draft/curvature-map analysis, Surface Extrude/Revolve/Sweep/Loft from open and closed curves, Offset, Unstitch and Reverse Normal; the continuity-driven core (`kernel/src/bridge.rs`, G0–G3 Hermite rows) with **Blend** (`surface.blend`, #764: edge chains along one or several faces, closed rims paired seam to seam or from picked seams, a dialog), **Match** (`surface.match`), **Boundary** (`surface.boundary`, #763 — two sketch curves exact with G0–G3, three or four as the flat patch of their loop, and curve networks: Coons and Gordon surfaces through sketch, 3D-sketch or edge curves, a point for a three-sided side, G1/G2 against the faces along one direction's edges, joined into their body on request; G1/G2 on two sides that meet at a corner waits for the Gregory-type corner), **Fair** (`surface.fair`, CV fairing), **continuity analysis** (`inspect.continuity`, #770; a toolbar tool with edge markers and a legend, and curvature combs along face isocurves) and a multi-section **loft** with per-end continuity and crown, and guide rails on solid and surface lofts (one or two, scaling or stretching the sections between; #201). Also in the Class-A pass: G1…G4 blend curves in the sketch, chord and variable-radius fillets on curved edges (with honest refusals where the fit cannot hold), and a G2 corner patch where filleted edges meet (kernel; the command refuses until the patch's sections can be sewn to the blends' contacts). Left: bias/form-factor fillet sections (design recorded), a Gregory-type corner, surface Fillet between separate surface bodies (#769), Ruled (#762), Untrim (#761), curved-face Extend (#760), and every remaining #757–#772 item | deferred | — | | M9 | Components and assemblies: New Component / Create Components from Bodies, active component, per-component origin/bodies/sketches/timeline entries, occurrences with transforms, Copy/Paste vs Paste New, nested Browser tree with visibility and isolate; Ground, Move/Copy of occurrences, joints (rigid, revolute, slider, cylindrical, pin-slot, planar, ball) by joint origins with limits and Drive Joints, closed kinematic loops (four-bar, slider-crank: the loop's other joints follow the driven one on its branch, and driving stops where a loop can no longer close), cams (`joint.cam`: a revolute cam drives a slider or revolute follower along a closed sketch profile or the cam's edges, knife, roller or flat followers, worked out again when the profile changes; drives, studies, closed loops, contact sets), As-built Joint, Rigid Group, Contact Sets (driving and motion studies stop where bodies in a set would pass through each other), Motion Study (joint values keyed along a timeline, playback, export of occurrence positions as JSON/CSV), motion analysis (joint values and a point's path charted over a study as value, velocity and acceleration; the parts that collide along a study, with the steps where they do), Exploded views (automatic or by hand, shown without changing placements); interference, per-component physical properties; STEP with assembly structure; URDF export for robot simulators (links with meshes, mass and inertia; joint chains whose values match Drive Joints; docs/urdf.md). Physical properties now measure material-aware component/occurrence placements, descendants and repeated instances, including pending moves and body reassignment offsets; contact geometry and automatic exploded centres respect those offsets. Groundwork done: component tree, occurrences with transforms (instances, Paste New), world placement, active component as authoring frame, ground, Capture/Revert Position, moving bodies and sketches. UI: ASSEMBLE panel dialogs for New Component, Joint (snaps on faces, edges, circles and vertices; animated motion preview; offsets, flip, limits), As-built Joint, Joint Origin, Rigid Group, Drive Joints (live slider), Motion Link, Cam and Interference (overlaps shown red); joints in the timeline and the Browser | in progress | 32 | diff --git a/assets/locales/cs.json b/assets/locales/cs.json index 260faad8e..bbd15354e 100644 --- a/assets/locales/cs.json +++ b/assets/locales/cs.json @@ -167,6 +167,7 @@ "HISTORY": "HISTORIE", "Height": "Výška", "Hidden edges": "Skryté hrany", + "History layout": "Rozložení historie", "Holes": "Otvory", "Holes (edges on them)": "Otvory (jejich hrany)", "Home view": "Výchozí pohled", @@ -1526,6 +1527,11 @@ "ui.hideOrigin": "Skrýt počátek", "ui.hidePlanes": "Skrýt roviny", "ui.hideProfile": "Skrýt profil", + "ui.history_back": "O krok zpět", + "ui.history_below_browser": "Pod prohlížečem", + "ui.history_first": "Přejít na začátek", + "ui.history_forward": "O krok vpřed", + "ui.history_last": "Přejít na konec", "ui.history_title": "Historie", "ui.hole": "Otvor", "ui.hole_tap_type": "Typ závitu otvoru", diff --git a/assets/locales/da.json b/assets/locales/da.json index 759299242..74781809a 100644 --- a/assets/locales/da.json +++ b/assets/locales/da.json @@ -167,6 +167,7 @@ "HISTORY": "HISTORIK", "Height": "Højde", "Hidden edges": "Skjulte kanter", + "History layout": "Historiklayout", "Holes": "Huller", "Holes (edges on them)": "Huller (kanterne omkring dem)", "Home view": "Hjemmevisning", @@ -1526,6 +1527,11 @@ "ui.hideOrigin": "Skjul nulpunkt", "ui.hidePlanes": "Skjul planer", "ui.hideProfile": "Skjul profil", + "ui.history_back": "Gå ét trin tilbage", + "ui.history_below_browser": "Under browseren", + "ui.history_first": "Gå til begyndelsen", + "ui.history_forward": "Gå ét trin frem", + "ui.history_last": "Gå til slutningen", "ui.history_title": "Historik", "ui.hole": "Hul", "ui.hole_tap_type": "Hullets gevindtype", diff --git a/assets/locales/de.json b/assets/locales/de.json index 3c586cdd7..b242a26d9 100644 --- a/assets/locales/de.json +++ b/assets/locales/de.json @@ -167,6 +167,7 @@ "HISTORY": "VERLAUF", "Height": "Höhe", "Hidden edges": "Verdeckte Kanten", + "History layout": "Verlaufslayout", "Holes": "Löcher", "Holes (edges on them)": "Löcher (ihre Kanten)", "Home view": "Startansicht", @@ -1526,6 +1527,11 @@ "ui.hideOrigin": "Ursprung ausblenden", "ui.hidePlanes": "Ebenen ausblenden", "ui.hideProfile": "Profil ausblenden", + "ui.history_back": "Einen Schritt zurück", + "ui.history_below_browser": "Unter dem Browser", + "ui.history_first": "Zum Anfang", + "ui.history_forward": "Einen Schritt vor", + "ui.history_last": "Zum Ende", "ui.history_title": "Verlauf", "ui.hole": "Bohrung", "ui.hole_tap_type": "Gewindetyp", diff --git a/assets/locales/en.json b/assets/locales/en.json index 9d184597a..32faca657 100644 --- a/assets/locales/en.json +++ b/assets/locales/en.json @@ -168,6 +168,8 @@ "HISTORY": "HISTORY", "Height": "Height", "Hidden edges": "Hidden edges", + "History layout": "History layout", + "History names": "History names", "Holes": "Holes", "Holes (edges on them)": "Holes (edges on them)", "Home view": "Home view", @@ -1538,7 +1540,19 @@ "ui.hideOrigin": "Hide Origin", "ui.hidePlanes": "Hide Planes", "ui.hideProfile": "Hide Profile", + "ui.history_back": "Go back one step", + "ui.history_below_browser": "Below browser", + "ui.history_edge_hint": "double-click the edge", + "ui.history_first": "Go to beginning", + "ui.history_forward": "Go forward one step", + "ui.history_hide_names": "Hide names", + "ui.history_last": "Go to end", + "ui.history_marker_tip": "History marker: drag to roll the model back; new features go here", + "ui.history_names": "Names", + "ui.history_play": "Play to the end", + "ui.history_show_names": "Show names", "ui.history_title": "History", + "ui.history_toggle_names": "Show or hide feature names", "ui.hole": "Hole", "ui.hole_tap_type": "Hole Tap Type", "ui.hole_type": "Hole Type", @@ -1832,7 +1846,7 @@ "ui.tie_ends": "Tie", "ui.tie_ends_tip": "Constrain all untied ends", "ui.timeline_bottom": "Bottom timeline", - "ui.timeline_left_note": "The left layout shows the rollback bar above the parts and scene browser.", + "ui.timeline_left_note": "The vertical history sits to the left of the browser. Toggle feature names on the strip.", "ui.timeline_left_sidebar": "Left sidebar", "ui.tip_angle": "Tip Angle", "ui.to_object": "To Object", diff --git a/assets/locales/es.json b/assets/locales/es.json index bd09496fc..77c44315d 100644 --- a/assets/locales/es.json +++ b/assets/locales/es.json @@ -167,6 +167,7 @@ "HISTORY": "HISTORIAL", "Height": "Altura", "Hidden edges": "Aristas ocultas", + "History layout": "Disposición del historial", "Holes": "Agujeros", "Holes (edges on them)": "Agujeros (aristas que contienen)", "Home view": "Vista de inicio", @@ -1526,6 +1527,11 @@ "ui.hideOrigin": "Ocultar origen", "ui.hidePlanes": "Ocultar planos", "ui.hideProfile": "Ocultar perfil", + "ui.history_back": "Retroceder un paso", + "ui.history_below_browser": "Debajo del explorador", + "ui.history_first": "Ir al principio", + "ui.history_forward": "Avanzar un paso", + "ui.history_last": "Ir al final", "ui.history_title": "Historial", "ui.hole": "Agujero", "ui.hole_tap_type": "Tipo de roscado del agujero", diff --git a/assets/locales/fr.json b/assets/locales/fr.json index 1d4821ed6..9f54fcfbe 100644 --- a/assets/locales/fr.json +++ b/assets/locales/fr.json @@ -167,6 +167,7 @@ "HISTORY": "HISTORIQUE", "Height": "Hauteur", "Hidden edges": "Arêtes cachées", + "History layout": "Disposition de l’historique", "Holes": "Trous", "Holes (edges on them)": "Trous (par leurs arêtes)", "Home view": "Vue d'accueil", @@ -1532,6 +1533,11 @@ "ui.hideOrigin": "Masquer l'origine", "ui.hidePlanes": "Masquer les plans", "ui.hideProfile": "Masquer le profil", + "ui.history_back": "Reculer d’une étape", + "ui.history_below_browser": "Sous le navigateur", + "ui.history_first": "Aller au début", + "ui.history_forward": "Avancer d’une étape", + "ui.history_last": "Aller à la fin", "ui.history_title": "Historique", "ui.hole": "Perçage", "ui.hole_tap_type": "Type de taraudage", diff --git a/assets/locales/gl.json b/assets/locales/gl.json index 5f9c5b23c..a4a3d36d3 100644 --- a/assets/locales/gl.json +++ b/assets/locales/gl.json @@ -167,6 +167,7 @@ "HISTORY": "HISTORIAL", "Height": "Altura", "Hidden edges": "Arestas ocultas", + "History layout": "Disposición do historial", "Holes": "Furados", "Holes (edges on them)": "Furados (arestas sobre eles)", "Home view": "Vista de inicio", @@ -1526,6 +1527,11 @@ "ui.hideOrigin": "Ocultar a orixe", "ui.hidePlanes": "Ocultar os planos", "ui.hideProfile": "Ocultar o perfil", + "ui.history_back": "Retroceder un paso", + "ui.history_below_browser": "Debaixo do explorador", + "ui.history_first": "Ir ao comezo", + "ui.history_forward": "Avanzar un paso", + "ui.history_last": "Ir ao final", "ui.history_title": "Historial", "ui.hole": "Furado", "ui.hole_tap_type": "Tipo de roscado do furado", diff --git a/assets/locales/hu.json b/assets/locales/hu.json index a7889ffc1..f7ac25b92 100644 --- a/assets/locales/hu.json +++ b/assets/locales/hu.json @@ -167,6 +167,7 @@ "HISTORY": "ELŐZMÉNYEK", "Height": "Magasság", "Hidden edges": "Rejtett élek", + "History layout": "Előzmények elrendezése", "Holes": "Furatok", "Holes (edges on them)": "Furatok (rajtuk lévő élek)", "Home view": "Kezdőnézet", @@ -1526,6 +1527,11 @@ "ui.hideOrigin": "Origó elrejtése", "ui.hidePlanes": "Síkok elrejtése", "ui.hideProfile": "Profil elrejtése", + "ui.history_back": "Egy lépéssel vissza", + "ui.history_below_browser": "Böngésző alatt", + "ui.history_first": "Ugrás az elejére", + "ui.history_forward": "Egy lépéssel előre", + "ui.history_last": "Ugrás a végére", "ui.history_title": "Előzmények", "ui.hole": "Furat", "ui.hole_tap_type": "Furat menettípusa", diff --git a/assets/locales/id.json b/assets/locales/id.json index 18759b05c..7b8c2d9cc 100644 --- a/assets/locales/id.json +++ b/assets/locales/id.json @@ -167,6 +167,7 @@ "HISTORY": "RIWAYAT", "Height": "Tinggi", "Hidden edges": "Tepi tersembunyi", + "History layout": "Tata letak riwayat", "Holes": "Lubang", "Holes (edges on them)": "Lubang (tepi di atasnya)", "Home view": "Tampilan awal", @@ -1526,6 +1527,11 @@ "ui.hideOrigin": "Sembunyikan Origin", "ui.hidePlanes": "Sembunyikan Bidang", "ui.hideProfile": "Sembunyikan Profil", + "ui.history_back": "Mundur satu langkah", + "ui.history_below_browser": "Di bawah browser", + "ui.history_first": "Ke awal", + "ui.history_forward": "Maju satu langkah", + "ui.history_last": "Ke akhir", "ui.history_title": "Riwayat", "ui.hole": "Lubang", "ui.hole_tap_type": "Tipe Tap Lubang", diff --git a/assets/locales/it.json b/assets/locales/it.json index 76bc619d3..360991eb3 100644 --- a/assets/locales/it.json +++ b/assets/locales/it.json @@ -168,6 +168,7 @@ "HISTORY": "CRONOLOGIA", "Height": "Altezza", "Hidden edges": "Spigoli nascosti", + "History layout": "Disposizione cronologia", "Holes": "Fori", "Holes (edges on them)": "Fori (spigoli dei fori)", "Home view": "Vista iniziale", @@ -1529,6 +1530,11 @@ "ui.hideOrigin": "Nascondi origine", "ui.hidePlanes": "Nascondi piani", "ui.hideProfile": "Nascondi profilo", + "ui.history_back": "Indietro di un passaggio", + "ui.history_below_browser": "Sotto il browser", + "ui.history_first": "Vai all’inizio", + "ui.history_forward": "Avanti di un passaggio", + "ui.history_last": "Vai alla fine", "ui.history_title": "Cronologia", "ui.hole": "Foro", "ui.hole_tap_type": "Tipo di maschiatura del foro", diff --git a/assets/locales/ja.json b/assets/locales/ja.json index 7a80e4b68..62bd497dc 100644 --- a/assets/locales/ja.json +++ b/assets/locales/ja.json @@ -168,6 +168,8 @@ "HISTORY": "履歴", "Height": "高さ", "Hidden edges": "隠線", + "History layout": "履歴のレイアウト", + "History names": "履歴名", "Holes": "穴", "Holes (edges on them)": "穴(そのエッジ)", "Home view": "ホームビュー", @@ -1538,7 +1540,19 @@ "ui.hideOrigin": "原点を非表示", "ui.hidePlanes": "平面を非表示", "ui.hideProfile": "プロファイルを非表示", + "ui.history_back": "1ステップ戻る", + "ui.history_below_browser": "ブラウザーの下", + "ui.history_edge_hint": "端をダブルクリック", + "ui.history_first": "先頭に移動", + "ui.history_forward": "1ステップ進む", + "ui.history_hide_names": "名前を非表示", + "ui.history_last": "末尾に移動", + "ui.history_marker_tip": "履歴マーカー:ドラッグしてモデルをロールバックします。新しいフィーチャーはここに追加されます", + "ui.history_names": "名前", + "ui.history_play": "最後まで再生", + "ui.history_show_names": "名前を表示", "ui.history_title": "履歴", + "ui.history_toggle_names": "フィーチャー名を表示・非表示", "ui.hole": "穴", "ui.hole_tap_type": "ねじ穴タイプ", "ui.hole_type": "穴タイプ", @@ -1832,7 +1846,7 @@ "ui.tie_ends": "拘束", "ui.tie_ends_tip": "未拘束をすべて拘束", "ui.timeline_bottom": "下部タイムライン", - "ui.timeline_left_note": "左レイアウトでは、ロールバックバーがパーツとシーンブラウザーの上に表示されます。", + "ui.timeline_left_note": "縦の履歴はブラウザーの左に表示されます。ストリップでフィーチャー名の表示を切り替えられます。", "ui.timeline_left_sidebar": "左サイドバー", "ui.tip_angle": "先端角度", "ui.to_object": "オブジェクトまで", diff --git a/assets/locales/ko.json b/assets/locales/ko.json index bc8fdc434..9f5d16bb7 100644 --- a/assets/locales/ko.json +++ b/assets/locales/ko.json @@ -167,6 +167,7 @@ "HISTORY": "이력", "Height": "높이", "Hidden edges": "숨겨진 모서리", + "History layout": "기록 레이아웃", "Holes": "구멍", "Holes (edges on them)": "구멍 (구멍의 모서리)", "Home view": "홈 뷰", @@ -1526,6 +1527,11 @@ "ui.hideOrigin": "원점 숨기기", "ui.hidePlanes": "평면 숨기기", "ui.hideProfile": "윤곽 숨기기", + "ui.history_back": "한 단계 뒤로", + "ui.history_below_browser": "브라우저 아래", + "ui.history_first": "처음으로 이동", + "ui.history_forward": "한 단계 앞으로", + "ui.history_last": "끝으로 이동", "ui.history_title": "기록", "ui.hole": "구멍", "ui.hole_tap_type": "탭 유형", diff --git a/assets/locales/ms.json b/assets/locales/ms.json index 9ccabe2df..e94a45751 100644 --- a/assets/locales/ms.json +++ b/assets/locales/ms.json @@ -167,6 +167,7 @@ "HISTORY": "SEJARAH", "Height": "Ketinggian", "Hidden edges": "Tepi tersembunyi", + "History layout": "Susun atur sejarah", "Holes": "Lubang", "Holes (edges on them)": "Lubang (tepi lubang)", "Home view": "Pandangan utama", @@ -1526,6 +1527,11 @@ "ui.hideOrigin": "Sembunyi Titik Asal", "ui.hidePlanes": "Sembunyi Satah", "ui.hideProfile": "Sembunyi Profil", + "ui.history_back": "Undur satu langkah", + "ui.history_below_browser": "Di bawah pelayar", + "ui.history_first": "Pergi ke permulaan", + "ui.history_forward": "Maju satu langkah", + "ui.history_last": "Pergi ke penghujung", "ui.history_title": "Sejarah", "ui.hole": "Lubang", "ui.hole_tap_type": "Jenis Bebenang Lubang", diff --git a/assets/locales/nl.json b/assets/locales/nl.json index eca13bcb1..4ad7d7000 100644 --- a/assets/locales/nl.json +++ b/assets/locales/nl.json @@ -167,6 +167,7 @@ "HISTORY": "GESCHIEDENIS", "Height": "Hoogte", "Hidden edges": "Verborgen randen", + "History layout": "Geschiedenisindeling", "Holes": "Gaten", "Holes (edges on them)": "Gaten (randen erop)", "Home view": "Beginweergave", @@ -1526,6 +1527,11 @@ "ui.hideOrigin": "Oorsprong verbergen", "ui.hidePlanes": "Vlakken verbergen", "ui.hideProfile": "Profiel verbergen", + "ui.history_back": "Eén stap terug", + "ui.history_below_browser": "Onder de browser", + "ui.history_first": "Naar het begin", + "ui.history_forward": "Eén stap vooruit", + "ui.history_last": "Naar het einde", "ui.history_title": "Geschiedenis", "ui.hole": "Gat", "ui.hole_tap_type": "Type tapgat", diff --git a/assets/locales/pl.json b/assets/locales/pl.json index cf1d39e25..2acada1e9 100644 --- a/assets/locales/pl.json +++ b/assets/locales/pl.json @@ -167,6 +167,7 @@ "HISTORY": "HISTORIA", "Height": "Wysokość", "Hidden edges": "Krawędzie niewidoczne", + "History layout": "Układ historii", "Holes": "Otwory", "Holes (edges on them)": "Otwory (krawędzie na nich)", "Home view": "Widok główny", @@ -1526,6 +1527,11 @@ "ui.hideOrigin": "Ukryj początek układu", "ui.hidePlanes": "Ukryj płaszczyzny", "ui.hideProfile": "Ukryj profil", + "ui.history_back": "Cofnij o jeden krok", + "ui.history_below_browser": "Pod przeglądarką", + "ui.history_first": "Przejdź do początku", + "ui.history_forward": "Przejdź o jeden krok do przodu", + "ui.history_last": "Przejdź do końca", "ui.history_title": "Historia", "ui.hole": "Otwór", "ui.hole_tap_type": "Typ gwintu otworu", diff --git a/assets/locales/pt-BR.json b/assets/locales/pt-BR.json index 278ecbd0b..964727458 100644 --- a/assets/locales/pt-BR.json +++ b/assets/locales/pt-BR.json @@ -167,6 +167,7 @@ "HISTORY": "HISTÓRICO", "Height": "Altura", "Hidden edges": "Arestas ocultas", + "History layout": "Layout do histórico", "Holes": "Furos", "Holes (edges on them)": "Furos (arestas neles)", "Home view": "Vista inicial", @@ -1526,6 +1527,11 @@ "ui.hideOrigin": "Ocultar origem", "ui.hidePlanes": "Ocultar planos", "ui.hideProfile": "Ocultar perfil", + "ui.history_back": "Voltar uma etapa", + "ui.history_below_browser": "Abaixo do navegador", + "ui.history_first": "Ir para o início", + "ui.history_forward": "Avançar uma etapa", + "ui.history_last": "Ir para o fim", "ui.history_title": "Histórico", "ui.hole": "Furo", "ui.hole_tap_type": "Tipo de rosca do furo", diff --git a/assets/locales/ro.json b/assets/locales/ro.json index 24e40fc1d..4c535f3b4 100644 --- a/assets/locales/ro.json +++ b/assets/locales/ro.json @@ -167,6 +167,7 @@ "HISTORY": "ISTORIC", "Height": "Înălțime", "Hidden edges": "Muchii ascunse", + "History layout": "Aspectul istoricului", "Holes": "Găuri", "Holes (edges on them)": "Găuri (muchiile lor)", "Home view": "Vizualizare de start", @@ -1526,6 +1527,11 @@ "ui.hideOrigin": "Ascunde originea", "ui.hidePlanes": "Ascunde planele", "ui.hideProfile": "Ascunde profilul", + "ui.history_back": "Un pas înapoi", + "ui.history_below_browser": "Sub navigator", + "ui.history_first": "Mergi la început", + "ui.history_forward": "Un pas înainte", + "ui.history_last": "Mergi la sfârșit", "ui.history_title": "Istoric", "ui.hole": "Gaură", "ui.hole_tap_type": "Tip de filetare gaură", diff --git a/assets/locales/ru.json b/assets/locales/ru.json index bfcee7c0d..d2156fa15 100644 --- a/assets/locales/ru.json +++ b/assets/locales/ru.json @@ -167,6 +167,7 @@ "HISTORY": "ИСТОРИЯ", "Height": "Высота", "Hidden edges": "Скрытые рёбра", + "History layout": "Расположение истории", "Holes": "Отверстия", "Holes (edges on them)": "Отверстия (рёбра на них)", "Home view": "Главный вид", @@ -1526,6 +1527,11 @@ "ui.hideOrigin": "Скрыть начало координат", "ui.hidePlanes": "Скрыть плоскости", "ui.hideProfile": "Скрыть профиль", + "ui.history_back": "На один шаг назад", + "ui.history_below_browser": "Под браузером", + "ui.history_first": "Перейти в начало", + "ui.history_forward": "На один шаг вперёд", + "ui.history_last": "Перейти в конец", "ui.history_title": "История", "ui.hole": "Отверстие", "ui.hole_tap_type": "Тип резьбы отверстия", diff --git a/assets/locales/sv.json b/assets/locales/sv.json index ad0a19dc6..e6b07be92 100644 --- a/assets/locales/sv.json +++ b/assets/locales/sv.json @@ -167,6 +167,7 @@ "HISTORY": "HISTORIK", "Height": "Höjd", "Hidden edges": "Dolda kanter", + "History layout": "Historiklayout", "Holes": "Hål", "Holes (edges on them)": "Hål (kanter på dem)", "Home view": "Hemvy", @@ -1526,6 +1527,11 @@ "ui.hideOrigin": "Dölj origo", "ui.hidePlanes": "Dölj plan", "ui.hideProfile": "Dölj profil", + "ui.history_back": "Gå ett steg bakåt", + "ui.history_below_browser": "Under webbläsaren", + "ui.history_first": "Gå till början", + "ui.history_forward": "Gå ett steg framåt", + "ui.history_last": "Gå till slutet", "ui.history_title": "Historik", "ui.hole": "Hål", "ui.hole_tap_type": "Typ av gängning för hål", diff --git a/assets/locales/tr.json b/assets/locales/tr.json index 52db14dc4..2b41a5d58 100644 --- a/assets/locales/tr.json +++ b/assets/locales/tr.json @@ -167,6 +167,7 @@ "HISTORY": "GEÇMİŞ", "Height": "Yükseklik", "Hidden edges": "Gizli kenarlar", + "History layout": "Geçmiş düzeni", "Holes": "Delikler", "Holes (edges on them)": "Delikler (kenarları)", "Home view": "Başlangıç görünümü", @@ -1526,6 +1527,11 @@ "ui.hideOrigin": "Orijini gizle", "ui.hidePlanes": "Düzlemleri gizle", "ui.hideProfile": "Profili gizle", + "ui.history_back": "Bir adım geri git", + "ui.history_below_browser": "Tarayıcının altında", + "ui.history_first": "Başlangıca git", + "ui.history_forward": "Bir adım ileri git", + "ui.history_last": "Sona git", "ui.history_title": "Geçmiş", "ui.hole": "Delik", "ui.hole_tap_type": "Diş türü", diff --git a/assets/locales/uk.json b/assets/locales/uk.json index 720bff257..1879b9de1 100644 --- a/assets/locales/uk.json +++ b/assets/locales/uk.json @@ -167,6 +167,7 @@ "HISTORY": "ІСТОРІЯ", "Height": "Висота", "Hidden edges": "Приховані ребра", + "History layout": "Розташування історії", "Holes": "Отвори", "Holes (edges on them)": "Отвори (ребра на них)", "Home view": "Головний вид", @@ -1526,6 +1527,11 @@ "ui.hideOrigin": "Приховати початок координат", "ui.hidePlanes": "Приховати площини", "ui.hideProfile": "Приховати профіль", + "ui.history_back": "На один крок назад", + "ui.history_below_browser": "Під браузером", + "ui.history_first": "Перейти на початок", + "ui.history_forward": "На один крок уперед", + "ui.history_last": "Перейти в кінець", "ui.history_title": "Історія", "ui.hole": "Отвір", "ui.hole_tap_type": "Тип різьби отвору", diff --git a/assets/locales/vi.json b/assets/locales/vi.json index 66f2d32d7..74b71bba4 100644 --- a/assets/locales/vi.json +++ b/assets/locales/vi.json @@ -167,6 +167,7 @@ "HISTORY": "LỊCH SỬ", "Height": "Chiều cao", "Hidden edges": "Nét khuất", + "History layout": "Bố cục lịch sử", "Holes": "Lỗ", "Holes (edges on them)": "Lỗ (các cạnh trên lỗ)", "Home view": "Góc nhìn chuẩn (Home)", @@ -1526,6 +1527,11 @@ "ui.hideOrigin": "Ẩn Gốc tọa độ", "ui.hidePlanes": "Ẩn các mặt phẳng", "ui.hideProfile": "Ẩn biên dạng", + "ui.history_back": "Lùi một bước", + "ui.history_below_browser": "Bên dưới trình duyệt", + "ui.history_first": "Về đầu", + "ui.history_forward": "Tiến một bước", + "ui.history_last": "Đến cuối", "ui.history_title": "Lịch sử", "ui.hole": "Tạo lỗ", "ui.hole_tap_type": "Kiểu ta-rô ren lỗ", diff --git a/assets/locales/zh-TW.json b/assets/locales/zh-TW.json index 8c177f277..13d847e07 100644 --- a/assets/locales/zh-TW.json +++ b/assets/locales/zh-TW.json @@ -167,6 +167,7 @@ "HISTORY": "歷程記錄", "Height": "高度", "Hidden edges": "隱藏線", + "History layout": "歷程配置", "Holes": "孔", "Holes (edges on them)": "孔(孔上的邊)", "Home view": "主檢視", @@ -1526,6 +1527,11 @@ "ui.hideOrigin": "隱藏原點", "ui.hidePlanes": "隱藏平面", "ui.hideProfile": "隱藏輪廓", + "ui.history_back": "後退一步", + "ui.history_below_browser": "瀏覽器下方", + "ui.history_first": "移至開頭", + "ui.history_forward": "前進一步", + "ui.history_last": "移至結尾", "ui.history_title": "歷程記錄", "ui.hole": "孔", "ui.hole_tap_type": "攻牙類型", diff --git a/assets/locales/zh.json b/assets/locales/zh.json index ac79a95c7..65dcd1fc6 100644 --- a/assets/locales/zh.json +++ b/assets/locales/zh.json @@ -168,6 +168,8 @@ "HISTORY": "历史", "Height": "高度", "Hidden edges": "隐藏线", + "History layout": "历史布局", + "History names": "历史名称", "Holes": "孔", "Holes (edges on them)": "孔(孔上的边)", "Home view": "主视图", @@ -1538,7 +1540,19 @@ "ui.hideOrigin": "隐藏原点", "ui.hidePlanes": "隐藏平面", "ui.hideProfile": "隐藏轮廓", + "ui.history_back": "后退一步", + "ui.history_below_browser": "浏览器下方", + "ui.history_edge_hint": "双击边缘", + "ui.history_first": "转到开头", + "ui.history_forward": "前进一步", + "ui.history_hide_names": "隐藏名称", + "ui.history_last": "转到末尾", + "ui.history_marker_tip": "历史标记:拖动以回退模型;新特征将在此处添加", + "ui.history_names": "名称", + "ui.history_play": "播放至末尾", + "ui.history_show_names": "显示名称", "ui.history_title": "历史", + "ui.history_toggle_names": "显示或隐藏特征名称", "ui.hole": "孔", "ui.hole_tap_type": "孔攻丝类型", "ui.hole_type": "孔类型", @@ -1832,7 +1846,7 @@ "ui.tie_ends": "约束", "ui.tie_ends_tip": "约束全部未约束端点", "ui.timeline_bottom": "底部时间轴", - "ui.timeline_left_note": "左侧布局下,回退条显示在零件和场景浏览器的上方。", + "ui.timeline_left_note": "垂直历史位于浏览器左侧。可在历史条上切换特征名称的显示。", "ui.timeline_left_sidebar": "左侧边栏", "ui.tip_angle": "尖端角度", "ui.to_object": "到对象", diff --git a/crates/engine/src/cmd/view_navigation.rs b/crates/engine/src/cmd/view_navigation.rs index a2d0bb643..0a3fde2f4 100644 --- a/crates/engine/src/cmd/view_navigation.rs +++ b/crates/engine/src/cmd/view_navigation.rs @@ -7,6 +7,8 @@ use crate::params::{bad, num, req_vec2, req_vec3, vec3}; use crate::{Result, Session}; pub static COMMANDS: &[CommandSpec] = &[ +CommandSpec::new("view.history_layout", "History layout", history_layout) + .icon("settings").noundo().doc_only().params("width?: 1..1000000; dock?: bottom|left|under_browser; collapsed?: bool → validated layout request; display only, never opens a dialog"), CommandSpec::new("view.graphics_preset", "Graphics Preset", graphics_preset) .icon("settings").noundo().doc_only().params("preset: performance|quality → preset, enabled, display_quality, supersampling, supersampling_adaptive; Quality: AO, Fine, adaptive 2x SSAA; Performance: no AO, Normal, no SSAA"), CommandSpec::new("view.ambient_occlusion", "Ambient Occlusion", ambient_occlusion) @@ -17,6 +19,30 @@ CommandSpec::new("view.navigate", "Navigate View", navigate) .doc_only() .params("camera: Camera; direction?: [x,y,z] in the camera's up-axis frame; or action: left|right|up|down|clockwise|counterclockwise|home|fit, degrees?: 0..180 (how far left|right|up|down turn; default 90); or motion: pan|orbit|zoom, delta?: [dx,dy] (pixels, each ±10000), viewport?: [width,height] (1..1000000, required for pan or pivot), pivot?: [x,y,z], factor?: 0.05..20 (required for zoom), anchor?: [x,y,z] → camera, fit, continuous?")]; +fn history_layout(_s: &mut Session, p: &Value) -> Result { + let cmd = "view.history_layout"; + let mut result = serde_json::Map::new(); + if let Some(value) = p.get("width") { + let width = value + .as_f64() + .filter(|v| v.is_finite() && (1.0..=1_000_000.0).contains(v)) + .ok_or_else(|| bad(cmd, "width must be finite and within 1..1000000"))?; + result.insert("width".into(), json!(width)); + } + if let Some(value) = p.get("dock") { + let dock = value + .as_str() + .filter(|v| matches!(*v, "bottom" | "left" | "under_browser")) + .ok_or_else(|| bad(cmd, "dock must be bottom, left or under_browser"))?; + result.insert("dock".into(), json!(dock)); + } + if let Some(value) = p.get("collapsed") { + let collapsed = value.as_bool().ok_or_else(|| bad(cmd, "collapsed must be a boolean"))?; + result.insert("collapsed".into(), json!(collapsed)); + } + Ok(Value::Object(result)) +} + fn navigate(_s: &mut Session, p: &Value) -> Result { let cmd = "view.navigate"; let mut cam: Camera = @@ -349,3 +375,17 @@ mod graphics_preset_tests { assert!(s.undo.is_empty()); } } + +#[cfg(test)] +#[test] +fn history_layout_validates_geometry_without_changing_the_design() { + let mut s = Session::default(); + let doc = s.doc.clone(); + let request = json!({"width":240.0,"dock":"under_browser","collapsed":true}); + assert_eq!(s.execute("view.history_layout", &request).unwrap(), request); + for p in [json!({"width":-1}), json!({"width":1e20}), json!({"width":"wide"}), json!({"dock":"nowhere"}), json!({"collapsed":42})] { + assert!(s.execute("view.history_layout", &p).is_err()); + } + assert_eq!(s.doc, doc); + assert!(s.undo.is_empty()); +} diff --git a/crates/ui-egui/src/agent_chat/panel.rs b/crates/ui-egui/src/agent_chat/panel.rs index 39309352c..a85fa1517 100644 --- a/crates/ui-egui/src/agent_chat/panel.rs +++ b/crates/ui-egui/src/agent_chat/panel.rs @@ -445,19 +445,11 @@ fn strip(app: &mut SolveApp, ui: &mut egui::Ui) { /// Pop out (or Dock, in its own window), Minimise and Close. In its own window the system moves /// and minimises it, so there is no grip and no Minimise. fn header(app: &mut SolveApp, ui: &mut egui::Ui, left: bool) { - let t = Tokens::get(); let state = app.agent_chat.state(); let popped = app.preferences.agent_chat_popped; ui.horizontal(|ui| { let title = { - let (grip, _) = ui.allocate_exact_size(vec2(if popped { 0.0 } else { 10.0 }, 18.0), Sense::hover()); - if !popped { - for row in 0..3 { - for col in 0..2 { - ui.painter().circle_filled(grip.left_top() + vec2(2.5 + col as f32 * 5.0, 4.0 + row as f32 * 5.0), 1.1, t.text_dim); - } - } - } + let grip = if popped { ui.allocate_exact_size(vec2(0.0, 18.0), Sense::hover()).0 } else { ui_kit::panel_grip(ui).rect }; let l = ui.label( RichText::new(tr("ui.agent_chat")).semibold().color(crate::theme::Tokens::get().text).size(crate::theme::Tokens::get().font_heading), ); diff --git a/crates/ui-egui/src/browser.rs b/crates/ui-egui/src/browser.rs index c78c3ea98..a2c9791fc 100644 --- a/crates/ui-egui/src/browser.rs +++ b/crates/ui-egui/src/browser.rs @@ -278,7 +278,7 @@ pub fn group_action(app: &mut SolveApp, action: &str, p: &Value) { // Drawing // --------------------------------------------------------------------------------------------- -const ROW_H: f32 = 26.0; +const ROW_H: f32 = crate::ui_kit::TREE_ROW_HEIGHT; /// The floating card's inner margin: the header highlight sits this far from the card's top, left /// and right edges, so its corners are concentric with the card's. const CARD_INSET: f32 = 4.0; @@ -663,12 +663,7 @@ fn lit_row((selected, hovered): (bool, bool)) -> (bool, Mark) { } pub fn browser(app: &mut SolveApp, ui: &mut egui::Ui) { - browser_panel(app, ui, false); -} - -/// The left-sidebar layout: feature history first, parts and scene browser below it. -pub fn browser_below_timeline(app: &mut SolveApp, ui: &mut egui::Ui) { - browser_panel(app, ui, true); + browser_panel(app, ui); } /// How narrow the browser sidebar may be dragged, and how wide (the viewport keeps the rest). @@ -679,7 +674,7 @@ const BROWSER_RAIL: f32 = 6.0; /// How opaque the floating browser's card is; the workspace shows through the rest. const BROWSER_FLOAT_ALPHA: f32 = 0.4; -fn browser_panel(app: &mut SolveApp, ui: &mut egui::Ui, timeline_above: bool) { +fn browser_panel(app: &mut SolveApp, ui: &mut egui::Ui) { let t = Tokens::get(); app.tree.order.clear(); DRAWN.with(|d| d.borrow_mut().clear()); @@ -691,76 +686,28 @@ fn browser_panel(app: &mut SolveApp, ui: &mut egui::Ui, timeline_above: bool) { .resizable(false) .frame(egui::Frame::NONE.fill(t.panel).inner_margin(egui::Margin::symmetric(t.space_6 as i8, t.space_6 as i8))) .show(ui, |ui| { - if timeline_above { - let available = ui.available_height(); - let browser_collapsed = app.preferences.timeline_left_browser_collapsed; - let max_timeline_height = (available - if browser_collapsed { 30.0 } else { 130.0 }).max(150.0); - let remembered = app.preferences.timeline_left_height; - let timeline_height = - if remembered.is_finite() { remembered.clamp(150.0, max_timeline_height) } else { 360.0_f32.clamp(150.0, max_timeline_height) }; - ui.allocate_ui_with_layout(vec2(ui.available_width(), timeline_height), egui::Layout::top_down(egui::Align::Min), |ui| { - crate::timeline_left::left_timeline(app, ui) - }); - if !browser_collapsed { - let (rect, _) = ui.allocate_exact_size(vec2(ui.available_width(), 8.0), egui::Sense::hover()); - let response = ui - .interact(rect, egui::Id::new("left_history_divider"), egui::Sense::drag()) - .on_hover_cursor(egui::CursorIcon::ResizeVertical); - if response.dragged() { - let delta = ui.input(|input| input.pointer.delta().y); - if delta.is_finite() { - app.preferences.timeline_left_height = (timeline_height + delta).clamp(150.0, max_timeline_height); - } - } - ui.painter().hline(rect.x_range(), rect.center().y, egui::Stroke::new(1.0, t.border)); - crate::scenario::publish_handle("left-history-divider", rect.center()); - } - let (rect, response) = ui.allocate_exact_size(vec2(ui.available_width(), crate::ui_kit::row_height()), Sense::click()); - crate::ui_kit::disclosure( - ui.painter(), - pos2(rect.left() + t.form_section_icon_size / 2.0, rect.center().y), - !browser_collapsed, - t.text_dim, - ); - ui.painter().text( - pos2(rect.left() + t.form_section_icon_size + t.space_8, rect.center().y), - egui::Align2::LEFT_CENTER, - "BROWSER", - crate::fonts::semibold(t.font_small), - t.text_dim, - ); - response - .widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::CollapsingHeader, ui.is_enabled(), !browser_collapsed, "BROWSER")); - crate::scenario::publish_handle("left-browser-toggle", response.rect.center()); - if response.clicked() { - app.preferences.timeline_left_browser_collapsed = !browser_collapsed; - } - if !browser_collapsed { - ui.add_space(t.space_4); - browser_rows(app, ui, &mut acts); - } - } else { - browser_contents(app, ui, &mut acts, false); - } + browser_contents(app, ui, &mut acts, false); }); - resize_browser(app, ui, panel.response.rect, width); + resize_column(app, ui, panel.response.rect, width, "left-browser-rail"); finish_browser(app, ui, acts); } -fn browser_width(remembered: f32) -> f32 { +pub(crate) fn browser_width(remembered: f32) -> f32 { if remembered.is_finite() { remembered.clamp(MIN_BROWSER_WIDTH, MAX_BROWSER_WIDTH) } else { crate::prefs::DEFAULT_BROWSER_WIDTH } } -fn resize_browser(app: &mut SolveApp, ui: &egui::Ui, rect: Rect, width: f32) { +/// Either card in a stacked column changes the same remembered width. +pub(crate) fn resize_column(app: &mut SolveApp, ui: &egui::Ui, rect: Rect, width: f32, handle: &'static str) { let rail = Rect::from_x_y_ranges(rect.right() - BROWSER_RAIL..=rect.right(), rect.y_range()); - let response = ui.interact(rail, egui::Id::new("sc_browser_rail"), Sense::drag()).on_hover_cursor(egui::CursorIcon::ResizeHorizontal); + let response = + ui.interact(rail, egui::Id::new(("sc_shared_column_rail", handle)), Sense::drag()).on_hover_cursor(egui::CursorIcon::ResizeHorizontal); if response.dragged() { let delta = ui.input(|input| input.pointer.delta().x); if delta.is_finite() { app.preferences.browser_width = (width + delta).clamp(MIN_BROWSER_WIDTH, MAX_BROWSER_WIDTH); } } - crate::scenario::publish_handle("left-browser-rail", pos2(rect.right() - BROWSER_RAIL / 2.0, rect.center().y)); + crate::scenario::publish_handle(handle, pos2(rect.right() - BROWSER_RAIL / 2.0, rect.center().y)); } /// One browser card for the floating shell and the docked shell's optional overlay. @@ -774,7 +721,21 @@ pub fn floating(app: &mut SolveApp, ui: &mut egui::Ui, available: Rect) { let gap = crate::shell::SHELL_GAP; let top_gap = if app.ui.layout == crate::shell::LayoutMode::Docked { gap } else { 0.0 }; let width = browser_width(app.preferences.browser_width); - let bounds = floating_bounds(available, app.shell.history, width, top_gap); + let vertical = app.ui.show_timeline && app.preferences.timeline_left; + let mut available = available; + let stacked = crate::timeline_left::stacked(app); + if vertical + && !stacked + && let Some(history) = app.shell.history + { + available.min.x = (history.right() + gap).min(available.right()) - gap; + } + let collapsed = vertical && !stacked && app.preferences.timeline_left_browser_collapsed; + let bounds = if stacked { + crate::timeline_left::stacked_rects(app, available).0 + } else { + floating_bounds(available, if vertical { None } else { app.shell.history }, if collapsed { t.space_24 + t.space_10 } else { width }, top_gap) + }; app.shell.browser = None; let min_height = HEADER_H + 2.0 * (CARD_INSET + 1.0); if bounds.is_positive() && bounds.height() >= min_height { @@ -786,9 +747,19 @@ pub fn floating(app: &mut SolveApp, ui: &mut egui::Ui, available: Rect) { let response = frame.show(ui, |ui| { ui.set_width(inner_width); ui.set_max_height(inner_height); - browser_contents(app, ui, &mut acts, true); + if stacked { + ui.set_min_height(inner_height); + ui.set_clip_rect(ui.clip_rect().intersect(Rect::from_min_size(ui.max_rect().min, vec2(inner_width, inner_height)))); + } + if collapsed { + browser_collapsed_rail(app, ui); + } else { + browser_contents(app, ui, &mut acts, true); + } }); - resize_browser(app, ui, response.response.rect, width); + if !collapsed { + resize_column(app, ui, response.response.rect, width, "left-browser-rail"); + } }); let rect = card.response.rect; app.shell.browser = Some(rect); @@ -801,7 +772,34 @@ pub fn floating(app: &mut SolveApp, ui: &mut egui::Ui, available: Rect) { finish_browser(app, ui, acts); } -fn floating_bounds(available: Rect, history: Option, width: f32, top_gap: f32) -> Rect { +fn browser_collapsed_rail(app: &mut SolveApp, ui: &mut egui::Ui) { + let t = Tokens::get(); + let title_top = t.space_24 + ui.spacing().item_spacing.y; + let height = title_top + t.space_24 * 4.0 + t.space_8; + let (rect, _) = ui.allocate_exact_size(vec2(ui.available_width(), height), Sense::hover()); + // Include the card margin in the hit target; keep the tint inside that margin. + let response = + ui.interact(rect.expand(CARD_INSET + 1.0), ui.id().with("browser_header"), Sense::click()).on_hover_cursor(egui::CursorIcon::PointingHand); + if response.hovered() || response.has_focus() { + crate::ui_kit::panel_header_hover(ui.painter(), rect); + } + let disclosure = Rect::from_min_size(rect.min, vec2(rect.width(), t.space_24)); + crate::ui_kit::disclosure(ui.painter(), disclosure.center(), false, t.text_dim); + crate::scenario::publish_handle("left-browser-toggle", disclosure.center()); + crate::scenario::publish_target("browser:header", disclosure); + response.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, ui.is_enabled(), crate::i18n::tr("ui.browser_title"))); + if response.on_hover_text(crate::i18n::tr("ui.browser_expand")).clicked() { + app.preferences.timeline_left_browser_collapsed = false; + } + let galley = ui.painter().layout_no_wrap(crate::i18n::tr("ui.browser_title").to_owned(), crate::fonts::semibold(t.font_body), t.text); + let title = Rect::from_min_max(rect.min + vec2(0.0, title_top), rect.max); + ui.painter().add( + egui::epaint::TextShape::new(title.center() - galley.size() / 2.0, galley, t.text) + .with_angle_and_anchor(std::f32::consts::FRAC_PI_2, egui::Align2::CENTER_CENTER), + ); +} + +pub(crate) fn floating_bounds(available: Rect, history: Option, width: f32, top_gap: f32) -> Rect { let gap = crate::shell::SHELL_GAP; let min = available.min + vec2(gap, top_gap); let right = (available.right() - gap).max(min.x); @@ -813,12 +811,20 @@ fn browser_contents(app: &mut SolveApp, ui: &mut egui::Ui, acts: &mut Actions, c let t = Tokens::get(); // Only the floating card folds; the docked column keeps its full height. browser_header(app, ui, collapsible); - if collapsible && app.tree.panel_collapsed { + let stacked = crate::timeline_left::stacked(app); + if collapsible + && (if stacked { + (app.preferences.timeline_left_browser_collapsed && app.shell.history_folding.is_none_or(|p| p[0] >= 1.0)) + || ui.available_height() <= t.space_3 + } else { + app.tree.panel_collapsed && !(app.ui.show_timeline && app.preferences.timeline_left) + }) + { return; } ui.painter().hline(ui.max_rect().x_range(), ui.cursor().top() + 1.0, egui::Stroke::new(1.0, t.toolbar.lerp_to_gamma(t.border, 0.5))); ui.add_space(t.space_3); - if collapsible { + if collapsible && !stacked { browser_rows_hugging(app, ui, acts); } else { browser_rows(app, ui, acts); @@ -832,9 +838,14 @@ fn browser_header(app: &mut SolveApp, ui: &mut egui::Ui, collapsible: bool) { let (rect, _) = ui.allocate_exact_size(vec2(ui.available_width(), HEADER_H), Sense::hover()); let response = ui.interact(rect, ui.id().with("browser_header"), if collapsible { Sense::click() } else { Sense::hover() }); crate::scenario::publish_target("browser:header", rect); - let collapsed = collapsible && app.tree.panel_collapsed; + let vertical = app.ui.show_timeline && app.preferences.timeline_left; + let stacked = crate::timeline_left::stacked(app); + let collapsed = collapsible && if stacked { app.preferences.timeline_left_browser_collapsed } else { !vertical && app.tree.panel_collapsed }; + if vertical { + crate::scenario::publish_handle("left-browser-toggle", rect.center()); + } if collapsible && (response.hovered() || response.has_focus()) { - ui.painter().rect_filled(rect, t.radius_lg.saturating_sub(CARD_INSET as u8), t.hover); + crate::ui_kit::panel_header_hover(ui.painter(), rect); } let title = crate::i18n::tr("ui.browser_title").to_string(); let kind = if collapsible { egui::WidgetType::Button } else { egui::WidgetType::Label }; @@ -853,8 +864,14 @@ fn browser_header(app: &mut SolveApp, ui: &mut egui::Ui, collapsible: bool) { ui.painter().galley(pos2(right - galley.size().x, rect.center().y - galley.size().y / 2.0), galley, t.text_dim); if collapsible { let tip = crate::i18n::tr(if collapsed { "ui.browser_expand" } else { "ui.browser_collapse" }); - if response.on_hover_text(tip).clicked() { - app.tree.panel_collapsed = !app.tree.panel_collapsed; + if response.on_hover_cursor(egui::CursorIcon::PointingHand).on_hover_text(tip).clicked() { + if stacked { + app.preferences.timeline_left_browser_collapsed = !app.preferences.timeline_left_browser_collapsed; + } else if vertical { + app.preferences.timeline_left_browser_collapsed = true; + } else { + app.tree.panel_collapsed = !app.tree.panel_collapsed; + } } } } @@ -925,6 +942,8 @@ fn rows_scrolling(app: &mut SolveApp, ui: &mut egui::Ui, acts: &mut Actions, shr prepare_model(app); acts.lit = Lit::of(app); egui::ScrollArea::vertical() + // The card may animate all the way down to its header. + .min_scrolled_height(0.0) .auto_shrink([false, shrink_height]) .scroll_source(egui::scroll_area::ScrollSource { scroll_bar: true, mouse_wheel: true, ..egui::scroll_area::ScrollSource::NONE }) .show(ui, |ui| { diff --git a/crates/ui-egui/src/browser_card_tests.rs b/crates/ui-egui/src/browser_card_tests.rs index d3e72973b..263a40b02 100644 --- a/crates/ui-egui/src/browser_card_tests.rs +++ b/crates/ui-egui/src/browser_card_tests.rs @@ -252,3 +252,60 @@ fn a_long_body_name_stays_inside_the_card_and_ends_in_an_ellipsis() { assert!(label.right() <= card.right(), "{label:?} spills out of {card:?}"); assert!(label.width() > 100.0, "the name keeps the room it has: {label:?}"); } + +#[test] +fn collapsed_rail_shares_header_hover_inset_and_expands_from_its_whole_card() { + let previous = crate::theme::is_dark(); + for dark in [false, true] { + crate::theme::set_dark(dark); + for collapsed in [false, true] { + let ctx = crate::fonts::test_context(); + ctx.global_style_mut(|style| style.animation_time = 0.0); + let mut app = SolveApp::new(Default::default(), Default::default()); + app.ui.tab = "SURFACE".into(); + app.preferences.timeline_left = true; + app.preferences.timeline_left_browser_collapsed = collapsed; + crate::theme::TabAccent::publish(&app, &ctx); + let bounds = Rect::from_min_size(Pos2::ZERO, vec2(600.0, 700.0)); + let draw = |app: &mut SolveApp, events| { + crate::test_support::frame(&ctx, egui::RawInput { screen_rect: Some(bounds), events, ..Default::default() }, |ui| { + floating(app, ui, bounds); + }) + }; + for _ in 0..3 { + draw(&mut app, vec![]); + } + let card = rect_of("browser:card").unwrap(); + let header = rect_of("browser:header").unwrap(); + // Hover at the bottom margin, far away from the disclosure and rotated title. + let at = if collapsed { card.center_bottom() - vec2(0.0, 2.0) } else { header.center() }; + draw(&mut app, vec![egui::Event::PointerMoved(at)]); + let output = draw(&mut app, vec![egui::Event::PointerMoved(at)]); + assert_eq!(output.platform_output.cursor_icon, egui::CursorIcon::PointingHand); + let accent = crate::theme::TabAccent::current(&ctx); + let mut hover = None; + for shape in &output.shapes { + crate::test_support::each_shape(&shape.shape, &mut |shape| { + if let egui::Shape::Rect(rect) = shape + && rect.fill == accent.soft + { + hover = Some(rect.clone()); + } + }); + } + let hover = + hover.unwrap_or_else(|| panic!("dark={dark}, collapsed={collapsed}, at={at:?}, accent={accent:?}, shapes={:?}", output.shapes)); + let inset = CARD_INSET + 1.0; // shared frame's inner margin and border + assert_eq!(hover.rect, if collapsed { card.shrink(inset) } else { header }); + assert_eq!(hover.rect.left() - card.left(), inset); + assert_eq!(card.right() - hover.rect.right(), inset); + assert_eq!(hover.corner_radius, egui::CornerRadius::same(Tokens::get().radius_lg.saturating_sub(CARD_INSET as u8))); + if collapsed { + draw(&mut app, crate::test_support::pointer(at, true)); + draw(&mut app, crate::test_support::pointer(at, false)); + assert!(!app.preferences.timeline_left_browser_collapsed, "the bottom margin expands the rail"); + } + } + } + crate::theme::set_dark(previous); +} diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index f45bb1aab..7b2a6d52d 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -101,7 +101,7 @@ fn key_from(name: &str) -> Option { fn execute(app: &mut SolveApp, id: &str, params: Value) -> Result { let r = app.run(id, params); if r.is_ok() - && !matches!(id, "view.navigate" | "view.ambient_occlusion" | "view.graphics_preset") + && !matches!(id, "view.navigate" | "view.ambient_occlusion" | "view.graphics_preset" | "view.history_layout") && app.session.active_sketch.is_none() && app.session.world_state().bodies.len() == 1 && app.session.undo.len() <= 2 diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index d2085b7dc..9abe87c57 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -743,6 +743,20 @@ impl SolveApp { let r = self.session.execute(id, ¶ms).map_err(|e| e.to_string()); self.big_operation |= now_ms() - t0 >= recovery_ui::BIG_OPERATION_MS; if let Ok(v) = &r { + if id == "view.history_layout" { + if let Some(width) = v.get("width").and_then(Value::as_f64) { + self.preferences.timeline_left_width = ui_kit::history_snap_width(width as f32); + } + if let Some(dock) = v.get("dock").and_then(Value::as_str) { + self.preferences.timeline_left = dock != "bottom"; + self.preferences.timeline_under_browser = dock == "under_browser"; + self.preferences.timeline_collapsed = false; + self.preferences.timeline_left_browser_collapsed = false; + } + if let Some(collapsed) = v.get("collapsed").and_then(Value::as_bool) { + self.preferences.timeline_collapsed = collapsed; + } + } if matches!(id, "view.ambient_occlusion" | "view.graphics_preset") { self.preferences.ambient_occlusion = v.get("enabled").and_then(Value::as_bool).unwrap_or(false); if id == "view.graphics_preset" { @@ -872,6 +886,10 @@ impl SolveApp { return; } // A display toggle leaves the current modelling tool and camera in place. + if id == "view.history_layout" { + let _ = self.run(id, json!({})); + return; + } if id == "view.ambient_occlusion" { let _ = self.run(id, json!({"enabled": !self.preferences.ambient_occlusion})); return; @@ -1529,6 +1547,7 @@ impl SolveApp { let floating = self.ui.layout == shell::LayoutMode::Floating; let show_timeline = self.ui.show_timeline && !render_workspace::active(self); let left_timeline = show_timeline && self.preferences.timeline_left; + timeline_left::animate_folds(self, ui.ctx()); if !floating { toolbar::toolbar(self, ui); } @@ -1537,16 +1556,23 @@ impl SolveApp { timeline::timeline(self, ui); } // A floating browser keeps the workspace the whole width and covers viewport input. - let browser_float = self.ui.show_browser && (self.preferences.browser_float || (floating && !left_timeline)); + let browser_float = self.ui.show_browser && (self.preferences.browser_float || floating || left_timeline); if !browser_float { self.shell.browser = None; } - self.shell.history = None; + if floating || left_timeline || !show_timeline { + self.shell.history = None; + } let full = ui.available_rect_before_wrap(); if floating { let cards = shell::Cards::new(full, self.ui.layout); self.shell.cards = vec![cards.workspace, cards.ribbon]; - self.shell.history = (show_timeline && !left_timeline).then(|| timeline::floating_rect(full)); + self.shell.history = if left_timeline { + let below_ribbon = egui::Rect::from_min_max(egui::pos2(full.left(), cards.bottom), full.max); + Some(timeline_left::floating_rect(self, below_ribbon)) + } else { + show_timeline.then(|| timeline::floating_rect(full)) + }; // Draw the scene first, then let the unchanged panel layouts cover it. The // viewport keeps its full projection even underneath the browser and cards. preview::update(self, ui.ctx()); @@ -1572,15 +1598,12 @@ impl SolveApp { if floating && show_timeline && !left_timeline { timeline::timeline(self, ui); } - if self.ui.show_browser && !browser_float { - if left_timeline { - browser::browser_below_timeline(self, ui); - } else { - browser::browser(self, ui); - } - } else if left_timeline { + if left_timeline { timeline_left::left_panel(self, ui); } + if self.ui.show_browser && !browser_float { + browser::browser(self, ui); + } if render_workspace::active(self) { render_workspace::panel(self, ui); } @@ -1590,13 +1613,20 @@ impl SolveApp { let viewport = ui.available_rect_before_wrap(); browser::floating(self, ui, viewport); } + if !floating && timeline_left::stacked(self) { + let width = browser::browser_width(self.preferences.browser_width) + shell::SHELL_GAP * 2.0; + egui::Panel::left("sc_history_browser_column").exact_size(width).resizable(false).frame(egui::Frame::NONE).show(ui, |_| {}); + } egui::CentralPanel::default().frame(egui::Frame::NONE).show(ui, |ui| { if floating { let panel_content = ui.max_rect(); let mut content = panel_content; - if let Some(history) = self.shell.history { + if let Some(history) = self.shell.history.filter(|_| !left_timeline) { content.max.y = (history.top() - shell::SHELL_GAP).max(content.top()); } + if left_timeline && let Some(history) = self.shell.history { + content.min.x = (history.right() + shell::SHELL_GAP).min(content.right()); + } if let Some(browser) = self.shell.browser { content.min.x = (browser.right() + shell::SHELL_GAP).min(content.right()); } diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs index ed56a365d..595f6cab8 100644 --- a/crates/ui-egui/src/prefs.rs +++ b/crates/ui-egui/src/prefs.rs @@ -444,14 +444,19 @@ preference_settings! { /// Interface font: an installed font family (or a font file), or empty for the built-in one /// (#1290). Menus, dialogs and labels use it; glyphs it lacks fall back as before. ui_font: String = String::new(), 0; - /// Put the feature history above the parts browser in the left sidebar instead of along the - /// bottom of the viewport. + /// Put the feature history to the left of the browser instead of below the viewport. timeline_left: bool = false, 0; - /// Height of the feature-history section when it shares the left sidebar with the browser. + /// Measured outer width; the contents react to this width without a names mode. + timeline_left_width: f32 = 130.0, 0; + /// Share the browser column, vertically, instead of a separate left column. + timeline_under_browser: bool = false, 0; + /// Fold the shared-column history to its header. + timeline_collapsed: bool = false, 0; + /// Legacy shared-column height, retained for preference compatibility. timeline_left_height: f32 = 360.0, 0; - /// Whether the browser below the left feature history is collapsed. + /// Whether the browser beside the vertical history is collapsed to its rail. timeline_left_browser_collapsed: bool = false, 0; - /// Width of the left sidebar holding the browser (and the feature history above it), which + /// Width of the browser sidebar, which /// the user drags wider or narrower at its right edge. browser_width: f32 = DEFAULT_BROWSER_WIDTH, 0; /// Draw the parts browser on a translucent card over the 3D view instead of a column of its @@ -1138,14 +1143,18 @@ fn page(app: &mut SolveApp, ui: &mut egui::Ui, t: &Tokens) { ui_kit::row(ui, app.tr_label("Interface font"), |ui| ui_font_row(app, ui)); } ui_kit::row(ui, app.tr("ui.feature_history"), |ui| { - let mut selected = usize::from(app.preferences.timeline_left); + let mut selected = if app.preferences.timeline_left { if app.preferences.timeline_under_browser { 2 } else { 1 } } else { 0 }; if ui_kit::segmented( ui, &mut selected, - &[crate::i18n::tr("ui.timeline_bottom"), crate::i18n::tr("ui.timeline_left_sidebar")], + &[ + crate::i18n::tr("ui.timeline_bottom"), + crate::i18n::tr("ui.timeline_left_sidebar"), + crate::i18n::tr("ui.history_below_browser"), + ], Default::default(), ) { - app.preferences.timeline_left = selected == 1; + let _ = app.run("view.history_layout", json!({"dock": match selected { 1=>"left",2=>"under_browser",_=>"bottom" }})); } }); ui_kit::text(ui, app.tr("ui.timeline_left_note"), ui_kit::Text::Note("timeline")); diff --git a/crates/ui-egui/src/shell.rs b/crates/ui-egui/src/shell.rs index 42a8771ec..48f6d34eb 100644 --- a/crates/ui-egui/src/shell.rs +++ b/crates/ui-egui/src/shell.rs @@ -80,6 +80,13 @@ pub(crate) struct State { pub panels: Vec, pub browser: Option, pub history: Option, + /// In-memory seam drag width, never serialized as a preference. + pub history_drag_width: Option, + /// Unreserved canvas bounds used by History docking targets. + pub history_dock_space: Option, + /// Browser/history collapse progress shared by both cards for this frame. + pub history_folding: Option<[f32; 2]>, + pub history_fold_motion: Option<[crate::timeline_left::FoldMotion; 2]>, pub content: Option, } @@ -91,6 +98,9 @@ pub(crate) fn covered_rects(app: &SolveApp) -> Vec { rects.extend(app.shell.panels.iter().copied()); rects.extend(app.shell.history); } + if app.ui.show_timeline && app.preferences.timeline_left { + rects.extend(app.shell.history.map(|card| crate::ui_kit::HistorySeam::new(card).pill)); + } rects.extend(app.shell.browser.filter(|_| app.ui.show_browser)); rects.extend(app.viewport.palette_rect.filter(|_| app.session.active_sketch.is_some())); rects.extend(app.viewport.dialog_rect.filter(|_| app.dialog.is_some() || app.tree.redefine.is_some())); diff --git a/crates/ui-egui/src/shell_tests.rs b/crates/ui-egui/src/shell_tests.rs index aa9d52349..238eaf800 100644 --- a/crates/ui-egui/src/shell_tests.rs +++ b/crates/ui-egui/src/shell_tests.rs @@ -230,9 +230,9 @@ fn floating_browser_clears_cards_shields_input_and_can_dock_again() { assert!(crate::browser::drawn_rows().iter().any(|(name, _, _, open)| name == "Origin" && *open == Some(true))); h.app.preferences.browser_float = false; h.settle(); - assert_eq!(h.app.shell.browser.is_some(), mode == LayoutMode::Floating && !timeline_left); + assert_eq!(h.app.shell.browser.is_some(), mode == LayoutMode::Floating || timeline_left); assert!(rect_of("browser:float").is_none()); - assert_eq!(rect_of("browser:card").is_some(), mode == LayoutMode::Floating && !timeline_left); + assert_eq!(rect_of("browser:card").is_some(), mode == LayoutMode::Floating || timeline_left); // The saved width follows both the floating card and the docked column. let rail = crate::scenario::handle_at("left-browser-rail").unwrap(); let width = h.app.preferences.browser_width; @@ -284,7 +284,7 @@ fn browser_and_history_cards_block_input_while_their_gaps_and_space_below_browse } #[test] -fn left_history_keeps_the_existing_column_in_both_modes() { +fn left_history_and_browser_share_the_left_edge_without_moving_right_controls() { for mode in [LayoutMode::Floating, LayoutMode::Docked] { let mut h = Harness::new(); h.app.ui.layout = mode; @@ -292,14 +292,21 @@ fn left_history_keeps_the_existing_column_in_both_modes() { h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"name":"First"})).unwrap(); h.settle(); assert!(rect_of("history:card").is_none()); - assert!(rect_of("browser:card").is_none()); + let history = rect_of("history:vertical").unwrap(); + let browser = rect_of("browser:card").unwrap(); + assert!(history.right() < browser.left()); assert!(crate::scenario::handle_at("timeline:First").is_some()); let viewport = h.app.viewport.rect.unwrap(); let content = content_rect(&h.app, viewport); - assert_eq!(content.left(), 250.0); + assert_eq!(viewport.left(), if mode == LayoutMode::Floating { 0.0 } else { crate::ui_kit::history_width(true) }); + assert_eq!(content.left(), if mode == LayoutMode::Floating { browser.right() + SHELL_GAP } else { viewport.left() }); assert_eq!(content.bottom(), viewport.bottom()); if mode == LayoutMode::Floating { - assert!(covered(&h.app, pos2(125.0, content.center().y))); + assert!(covered(&h.app, history.center())); + assert!(covered(&h.app, browser.center())); + let gap_x = (history.right() + browser.left()) / 2.0; + assert!(covered(&h.app, pos2(gap_x, history.center().y)), "the seam pill shields viewport input"); + assert!(!covered(&h.app, pos2(gap_x, history.top() + 4.0)), "the rest of the shell gap remains available"); } } } diff --git a/crates/ui-egui/src/timeline.rs b/crates/ui-egui/src/timeline.rs index 1303b7171..03f82296f 100644 --- a/crates/ui-egui/src/timeline.rs +++ b/crates/ui-egui/src/timeline.rs @@ -1,6 +1,5 @@ //! The timeline (bottom): features in order, the rollback marker, errors and warnings. -pub(crate) use crate::icons::glyphs::transport_glyph; use egui::{Rect, Sense, Stroke, UiBuilder, pos2, vec2}; use serde_json::{Value, json}; use solidcraft_engine::doc::{ @@ -8,8 +7,23 @@ use solidcraft_engine::doc::{ construct::{AxisDef, PointDef}, }; +use crate::SolveApp; use crate::theme::Tokens; -use crate::{SolveApp, icons}; + +/// Apply transport actions from the current marker; endpoints stay bounded, including an +/// empty design. All orientations reach the same rollback command. +pub(crate) fn run_transport(app: &mut SolveApp, control: crate::ui_kit::HistoryTransport) { + let n = app.session.doc.features.len(); + let marker = app.session.doc.marker.unwrap_or(n); + let position = match control { + crate::ui_kit::HistoryTransport::First => 0, + crate::ui_kit::HistoryTransport::Back => marker.saturating_sub(1), + crate::ui_kit::HistoryTransport::Forward => marker.saturating_add(1).min(n), + crate::ui_kit::HistoryTransport::Last => n, + }; + let params = if position < n { json!({"position":position}) } else { json!({}) }; + let _ = app.run_heavy("timeline.roll_to", params); +} // Snapshot only the data used by timeline interactions. Cloning FeatureKind here would // also copy imported mesh vertices and triangles on every frame. @@ -255,6 +269,7 @@ fn toggle_feature(app: &mut SolveApp, id: u64) { pub fn timeline(app: &mut SolveApp, ui: &mut egui::Ui) { let t = Tokens::get(); + app.shell.history_dock_space = Some(ui.available_rect_before_wrap()); if app.ui.layout == crate::shell::LayoutMode::Floating { let rect = floating_rect(ui.available_rect_before_wrap()); // A window too short for the card (the ribbon already fills it) leaves the history out @@ -273,6 +288,7 @@ pub fn timeline(app: &mut SolveApp, ui: &mut egui::Ui) { let response = egui::Panel::bottom("sc_timeline").exact_size(40.0).frame(egui::Frame::NONE.fill(t.timeline)).show(ui, |ui| { timeline_contents(app, ui, false); }); + app.shell.history = Some(response.response.rect); crate::scenario::publish_rect("history:strip", response.response.rect); } } @@ -295,36 +311,27 @@ fn timeline_contents(app: &mut SolveApp, ui: &mut egui::Ui, floating: bool) { let marker = app.session.doc.marker.unwrap_or(n); // Playback controls. let mut x = r.left() + t.space_10; - if floating { - let label = p.layout_no_wrap(crate::i18n::tr("ui.history_title").to_string(), egui::FontId::proportional(t.font_label), t.text); - p.galley(pos2(x, r.center().y - label.size().y / 2.0), label.clone(), t.text); + let grip_rect = Rect::from_center_size(pos2(x + t.space_10 / 2.0, r.center().y), vec2(t.space_10, t.space_16 + t.space_2)); + let mut grip_ui = ui.new_child(UiBuilder::new().max_rect(grip_rect).layout(egui::Layout::left_to_right(egui::Align::Center))); + let grip = crate::ui_kit::panel_grip(&mut grip_ui).rect; + x += t.space_10 + t.space_8; + let mut drag_rect = grip; + let label = p.layout_no_wrap(crate::i18n::tr("ui.history_title").to_string(), crate::fonts::semibold(t.font_heading), t.text); + if x + label.size().x + t.space_12 + crate::ui_kit::history_transport_width() <= r.right() { + let title_rect = Rect::from_min_size(pos2(x, r.center().y - label.size().y / 2.0), label.size()); + p.galley(title_rect.min, label.clone(), t.text); + drag_rect = drag_rect.union(title_rect); x += label.size().x + t.space_12; } - let controls = [("first", Some(0usize)), ("back", Some(marker.saturating_sub(1))), ("forward", Some((marker + 1).min(n))), ("last", None)]; - for (what, target) in controls { - let br = Rect::from_center_size(pos2(x + 11.0, r.center().y), vec2(22.0, 22.0)); - crate::scenario::publish_handle(&format!("history:{what}"), br.center()); - let resp = ui.interact(br, ui.id().with(("tl", what)), Sense::click()); - if resp.hovered() { - p.rect_filled(br, 3.0, t.hover); + let response = ui.interact(drag_rect, egui::Id::new("sc_history_dock_grip"), Sense::drag()); + crate::scenario::publish_handle("history:grip", drag_rect.center()); + crate::timeline_left::dock_drag(app, ui, &response); + for control in crate::ui_kit::HistoryTransport::ALL { + let br = Rect::from_center_size(pos2(x + t.space_24 / 2.0, r.center().y), vec2(t.space_24, t.space_24)); + if control.show(ui, br).clicked() { + run_transport(app, control); } - transport_glyph(&p, br.center(), what, t.icon); - if resp - .on_hover_text(match what { - "first" => "Roll back to the start", - "back" => "Step back one feature", - "forward" => "Step forward one feature", - _ => "Play to the end", - }) - .clicked() - { - let pos = match target { - Some(k) if k < n => json!({"position": k}), - _ => json!({}), - }; - let _ = app.run_heavy("timeline.roll_to", pos); - } - x += 24.0; + x += t.space_24 + t.space_2; } x += 14.0; // The features scroll horizontally in the space right of the playback controls. @@ -360,8 +367,8 @@ fn timeline_contents(app: &mut SolveApp, ui: &mut egui::Ui, floating: bool) { let mut marker_rect: Option = None; for (i, (id, name, icon, suppressed, ty, kind)) in feats.iter().enumerate() { if i == marker { - marker_rect = Some(Rect::from_min_size(pos2(x, r.top() + 5.0), vec2(6.0, r.height() - 10.0))); - x += 10.0; + marker_rect = Some(Rect::from_min_size(pos2(x, r.top() + 5.0), vec2(t.space_12, r.height() - 10.0))); + x += t.space_16; } xs.push(x); let br = Rect::from_min_size(pos2(x, r.top() + 6.0), vec2(28.0, 28.0)); @@ -376,49 +383,19 @@ fn timeline_contents(app: &mut SolveApp, ui: &mut egui::Ui, floating: bool) { if resp.hovered() { hovered = Some(*id); } - let bg = if err.is_some() { - t.timeline_item_error - } else if sel || (floating && marker > 0 && i == marker - 1) { - accent.soft - } else if resp.hovered() || from_view == Some(*id) { - t.hover - } else { - t.timeline_item - }; - let edge = if err.is_some() { - t.error - } else if from_view == Some(*id) || (floating && marker > 0 && i == marker - 1) { - accent.color - } else { - t.border - }; - p.rect(br, 3.0, bg, Stroke::new(1.0, edge), egui::StrokeKind::Inside); - let ink = if rolled || *suppressed { t.border } else { t.icon }; - icons::paint( - &p, - br.shrink(4.0), + crate::ui_kit::HistoryChip { icon, - ink, - if rolled { t.panel_header } else { t.icon_fill }, - if rolled { t.border } else { t.accent }, - ); - if *suppressed { - p.line_segment([br.left_bottom() + vec2(4.0, -4.0), br.right_top() + vec2(-4.0, 4.0)], Stroke::new(1.5, t.text_dim)); - } - // A failed feature has a mark of its own, not only its colour (#972). - if err.is_some() { - icons::paint(&p, Rect::from_min_size(br.right_top() - vec2(10.0, 0.0), vec2(10.0, 10.0)), "error", t.panel, t.error, t.error); - } - if warn.is_some() && err.is_none() { - icons::paint( - &p, - Rect::from_min_size(br.right_top() - vec2(10.0, 0.0), vec2(10.0, 10.0)), - "warning", - t.icon, - t.warning, - t.warning, - ); + name, + kind: ty, + selected: sel || (floating && marker > 0 && i == marker - 1), + hovered: resp.hovered() || from_view == Some(*id), + dim: rolled, + suppressed: *suppressed, + error: err.is_some(), + warning: warn.is_some(), + accent, } + .paint(&p, br, crate::ui_kit::HistoryStyle::Bottom); let mut tip = status_text(name, ty, err.as_deref(), warn.as_deref()); if let Some(r) = res { tip += &format!("\n{:.1} ms", r.ms); @@ -488,7 +465,7 @@ fn timeline_contents(app: &mut SolveApp, ui: &mut egui::Ui, floating: bool) { } let end = x; if marker >= feats.len() { - marker_rect = Some(Rect::from_min_size(pos2(x, r.top() + 5.0), vec2(6.0, r.height() - 10.0))); + marker_rect = Some(Rect::from_min_size(pos2(x, r.top() + 5.0), vec2(t.space_12, r.height() - 10.0))); } // The history marker: drag it to roll the model back or forward. if let Some(mr) = marker_rect { @@ -497,14 +474,7 @@ fn timeline_contents(app: &mut SolveApp, ui: &mut egui::Ui, floating: bool) { if resp.drag_started() { drag = Some(Drag::Marker); } - let col = if resp.hovered() || drag == Some(Drag::Marker) { - accent.color - } else if !floating && accent.color == t.accent { - t.timeline_marker - } else { - accent.color - }; - p.rect_filled(mr, 1.0, col); + crate::ui_kit::history_marker(&p, mr, false, accent); resp.on_hover_text("History marker: drag to roll the model back; new features go here"); } let content_end = crate::dialogs_assembly::timeline_joints(app, ui, &p, end + 10.0, r); @@ -514,9 +484,11 @@ fn timeline_contents(app: &mut SolveApp, ui: &mut egui::Ui, floating: bool) { if let (Some(dg), Some(pp)) = (drag.as_ref(), pointer) { let slot = slot_at(&xs, end, pp.x); let sx = xs.get(slot).copied().unwrap_or(end) - 4.0; - p.line_segment( - [pos2(sx, r.top() + 3.0), pos2(sx, r.bottom() - 3.0)], - Stroke::new(2.0, if matches!(dg, Drag::Marker) { accent.color } else { t.sketch_accent }), + crate::ui_kit::history_drop_bar( + &p, + Rect::from_min_max(pos2(sx, r.top() + 3.0), pos2(sx, r.bottom() - 3.0)), + false, + if matches!(dg, Drag::Marker) { accent.color } else { t.sketch_accent }, ); } let released = ui.input(|i| i.pointer.any_released()); @@ -852,6 +824,7 @@ mod tests { assert_eq!(chips.last().unwrap().fill, accent.soft); assert_eq!(chips.last().unwrap().stroke.color, accent.color); let marker = crate::scenario::rect_of("history:marker").unwrap(); - assert!(out.shapes.iter().any(|s| matches!(&s.shape, egui::Shape::Rect(r) if r.rect == marker && r.fill == accent.color))); + assert!(out.shapes.iter().any(|s| matches!(&s.shape, egui::Shape::Circle(c) + if marker.contains(c.center) && c.fill == t.timeline && c.stroke == egui::Stroke::new(t.space_2, accent.color)))); } } diff --git a/crates/ui-egui/src/timeline_left.rs b/crates/ui-egui/src/timeline_left.rs index 8a6c84594..50f0232e9 100644 --- a/crates/ui-egui/src/timeline_left.rs +++ b/crates/ui-egui/src/timeline_left.rs @@ -1,13 +1,10 @@ //! The left feature-history panel: named rows, folders, rollback and drag-and-drop. -use crate::fonts::RichTextExt as _; -use egui::{Color32, Rect, RichText, Sense, Stroke, pos2, vec2}; +use egui::{Rect, Sense, Stroke, pos2, vec2}; use serde_json::json; use crate::theme::Tokens; -use crate::timeline::{ - TimelineKind, clipboard_buttons, delete_feature, delete_features, icon_of, message_button, selected_feature_ids, transport_glyph, -}; +use crate::timeline::{TimelineKind, clipboard_buttons, delete_feature, delete_features, icon_of, message_button, selected_feature_ids}; use crate::{SolveApp, icons}; const FOLDER_INDENT: f32 = 14.0; @@ -58,76 +55,350 @@ impl TimelineItem { } } -/// A standalone left feature-history panel, used when the parts browser is hidden. +/// Saved width; contents are selected from the actual available width at render time. +pub(crate) fn strip_width(app: &SolveApp) -> f32 { + app.shell + .history_drag_width + .map(crate::ui_kit::history_clamp_width) + .unwrap_or_else(|| crate::ui_kit::history_snap_width(app.preferences.timeline_left_width)) +} + +pub(crate) fn stacked(app: &SolveApp) -> bool { + app.ui.show_timeline && app.preferences.timeline_left && app.preferences.timeline_under_browser +} + +fn header_outer_height() -> f32 { + let t = Tokens::get(); + crate::ui_kit::TREE_ROW_HEIGHT + t.space_8 + t.space_2 +} + +/// Small, allocation-free transition. Wall-clock progress avoids accumulating lag when +/// a frame is delayed; retargeting starts at the visible value, including mid-flight. +#[derive(Clone, Copy, Debug)] +pub(crate) struct FoldMotion { + from: f32, + to: f32, + started: f64, +} + +impl FoldMotion { + fn value(self, now: f64, duration: f32) -> f32 { + if duration <= 0.0 { + return self.to; + } + let elapsed = ((now - self.started) / f64::from(duration)).clamp(0.0, 1.0) as f32; + egui::lerp(self.from..=self.to, egui::emath::easing::cubic_out(elapsed)) + } + + fn advance(&mut self, target: f32, now: f64, duration: f32) -> f32 { + let value = self.value(now, duration); + if self.to != target { + *self = Self { from: value, to: target, started: now }; + } + self.value(now, duration) + } +} + +/// Calculate only two scalars per frame; cards and input geometry share the result. +pub(crate) fn animate_folds(app: &mut SolveApp, ctx: &egui::Context) { + if !stacked(app) { + app.shell.history_folding = None; + app.shell.history_fold_motion = None; + return; + } + let duration = ctx.global_style().animation_time.clamp(0.0, 0.12); + let now = ctx.input(|input| input.time); + let targets = [f32::from(app.preferences.timeline_left_browser_collapsed), f32::from(app.preferences.timeline_collapsed)]; + let motions = app.shell.history_fold_motion.get_or_insert_with(|| targets.map(|to| FoldMotion { from: to, to, started: now })); + let progress = [motions[0].advance(targets[0], now, duration), motions[1].advance(targets[1], now, duration)]; + app.shell.history_folding = Some(progress); + if progress != targets { + ctx.request_repaint(); + } +} + +/// Shared bounds keep browser and history at exactly the same width. Their split is half +/// the available height. One folded header gives the other the remainder; two folded +/// headers sit together at the top. +pub(crate) fn stacked_rects(app: &SolveApp, available: Rect) -> (Rect, Rect) { + let progress = app + .shell + .history_folding + .unwrap_or([f32::from(app.preferences.timeline_left_browser_collapsed), f32::from(app.preferences.timeline_collapsed)]); + column_rects_at(app, available, progress[0], progress[1]) +} + +fn column_rects(app: &SolveApp, available: Rect, browser_collapsed: bool, history_collapsed: bool) -> (Rect, Rect) { + column_rects_at(app, available, f32::from(browser_collapsed), f32::from(history_collapsed)) +} + +fn column_rects_at(app: &SolveApp, available: Rect, browser_fold: f32, history_fold: f32) -> (Rect, Rect) { + let gap = crate::shell::SHELL_GAP; + let top_gap = if app.ui.layout == crate::shell::LayoutMode::Docked { gap } else { 0.0 }; + let column = crate::browser::floating_bounds(available, None, crate::browser::browser_width(app.preferences.browser_width), top_gap); + if !app.ui.show_browser { + let height = egui::lerp(column.height()..=header_outer_height().min(column.height()), history_fold); + let history = Rect::from_min_size(column.min, vec2(column.width(), height)); + return (Rect::NOTHING, history); + } + let budget = (column.height() - gap).max(0.0); + let header = header_outer_height().min(budget / 2.0); + let expanded_browser = egui::lerp(budget / 2.0..=(budget - header).max(0.0), history_fold); + let browser_height = egui::lerp(expanded_browser..=header, browser_fold); + let browser = Rect::from_min_size(column.min, vec2(column.width(), browser_height)); + let history_top = (browser.bottom() + gap).min(column.bottom()); + let history_height = egui::lerp((column.bottom() - history_top).max(0.0)..=header, history_fold); + let history = Rect::from_min_size(pos2(column.left(), history_top), vec2(column.width(), history_height)); + (browser, history) +} + +pub(crate) fn floating_rect(app: &SolveApp, available: Rect) -> Rect { + if stacked(app) { + return stacked_rects(app, available).1; + } + let gap = crate::shell::SHELL_GAP; + let top_gap = if app.ui.layout == crate::shell::LayoutMode::Docked { gap } else { 0.0 }; + let min = pos2((available.left() + gap).min(available.right()), (available.top() + top_gap).min(available.bottom())); + Rect::from_min_max(min, pos2((min.x + strip_width(app)).min((available.right() - gap).max(min.x)), (available.bottom() - gap).max(min.y))) +} + +/// Full-height left card, or a card sharing the browser column below it. pub fn left_panel(app: &mut SolveApp, ui: &mut egui::Ui) { let t = Tokens::get(); - egui::Panel::left("sc_timeline_left") - .exact_size(250.0) - .resizable(false) - .frame(egui::Frame::NONE.fill(t.panel).inner_margin(egui::Margin::symmetric(6, 6))) - .show(ui, |ui| left_timeline(app, ui)); -} - -/// Vertical feature history with named rows, folders and a horizontal rollback bar. The caller -/// gives this a bounded height so the parts and scene browser can use the space below it. -pub fn left_timeline(app: &mut SolveApp, ui: &mut egui::Ui) { - let t = Tokens::get(); - let groups = app.session.doc.timeline_groups.clone(); - ui.horizontal(|ui| { - // Reserve the selection menu's measured height even when no features are selected. - let font = egui::TextStyle::Button.resolve(ui.style()); - let menu_height = ui.fonts_mut(|fonts| fonts.row_height(&font)) + 2.0 * ui.spacing().button_padding.y; - ui.set_min_height(menu_height.ceil().max(22.0)); - ui.label(RichText::new("FEATURE HISTORY").size(crate::theme::Tokens::get().font_small).semibold().color(t.text_dim)); - ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { - let count = selected_feature_ids(app).len() + app.tree.picked_timeline_groups.len(); - if count > 0 { - crate::ui_kit::Menu::button(ui, format!("{count} selected"), |ui| selection_actions(app, ui, &groups)); + let available = ui.available_rect_before_wrap(); + app.shell.history_dock_space = Some(available); + if app.ui.layout == crate::shell::LayoutMode::Floating || stacked(app) { + let bounds = floating_rect(app, available); + app.shell.history = None; + if !bounds.is_finite() || bounds.width() < crate::ui_kit::history_width(false) || bounds.height() < t.control_height { + return; + } + let frame = crate::frame::shell_card(t.panel).inner_margin(t.space_4); + let inner = (bounds.size() - frame.total_margin().sum()).max(egui::Vec2::ZERO); + let card = crate::frame::area(egui::Id::new("sc_timeline_left_card")).fixed_pos(bounds.min).order(egui::Order::Middle).show(ui.ctx(), |ui| { + let response = frame.show(ui, |ui| { + ui.set_min_size(inner); + ui.set_max_size(inner); + ui.set_clip_rect(ui.clip_rect().intersect(Rect::from_min_size(ui.max_rect().min, inner))); + left_timeline(app, ui); + }); + if stacked(app) { + let width = crate::browser::browser_width(app.preferences.browser_width); + crate::browser::resize_column(app, ui, response.response.rect, width, "left-history-rail"); } }); - }); - timeline_transport(app, ui); - ui.separator(); - - egui::ScrollArea::vertical() - .id_salt("sc_left_timeline_scroll") - .auto_shrink([false, false]) - .scroll_source(egui::scroll_area::ScrollSource { scroll_bar: true, mouse_wheel: true, ..egui::scroll_area::ScrollSource::NONE }) - .show(ui, |ui| vertical_features(app, ui)); + app.shell.history = Some(card.response.rect); + crate::scenario::publish_rect("history:vertical", card.response.rect); + if !stacked(app) { + seam_handle(app, ui, card.response.rect); + } + } else { + let width = strip_width(app).min(ui.available_width().max(0.0)); + if width < crate::ui_kit::history_width(false) { + return; + } + let response = egui::Panel::left("sc_timeline_left") + .exact_size(width) + .resizable(false) + .frame(egui::Frame::NONE.fill(t.panel).inner_margin(t.space_4)) + .show(ui, |ui| left_timeline(app, ui)); + crate::scenario::publish_rect("history:vertical", response.response.rect); + app.shell.history = Some(response.response.rect); + seam_handle(app, ui, response.response.rect); + } } -fn timeline_transport(app: &mut SolveApp, ui: &mut egui::Ui) { +fn names_fit(width: f32) -> bool { let t = Tokens::get(); - let n = app.session.doc.features.len(); - let marker = app.session.doc.marker.unwrap_or(n); - ui.horizontal(|ui| { - ui.spacing_mut().item_spacing.x = 2.0; - let controls = [("first", Some(0usize)), ("back", Some(marker.saturating_sub(1))), ("forward", Some((marker + 1).min(n))), ("last", None)]; - for (what, target) in controls { - let (rect, response) = ui.allocate_exact_size(vec2(24.0, 22.0), Sense::click()); - if response.hovered() { - ui.painter().rect_filled(rect, 3.0, t.hover); - } - transport_glyph(ui.painter(), rect.center(), what, t.icon); - if response - .on_hover_text(match what { - "first" => "Roll back to the start", - "back" => "Step back one feature", - "forward" => "Step forward one feature", - _ => "Play to the end", - }) - .clicked() - { - let params = match target { - Some(position) if position < n => json!({"position": position}), - _ => json!({}), - }; - let _ = app.run_heavy("timeline.roll_to", params); + width >= crate::ui_kit::history_width(true) - (t.space_8 + t.space_2) +} + +fn seam_handle(app: &mut SolveApp, ui: &mut egui::Ui, card: Rect) { + let seam = crate::ui_kit::HistorySeam::new(card); + let bounds = seam.edge.union(seam.pill); + crate::frame::area(egui::Id::new("history_seam_overlay")).order(egui::Order::Foreground).fixed_pos(bounds.min).show(ui.ctx(), |ui| { + ui.set_min_size(bounds.size()); + ui.set_clip_rect(ui.ctx().content_rect()); + let result = crate::ui_kit::history_seam(ui, card, card.width() >= crate::ui_kit::history_width(true)); + if let Some(width) = result.width { + app.shell.history_drag_width = Some(width); + ui.ctx().request_repaint(); + if result.released { + let _ = app.run("view.history_layout", json!({"width": width})); + app.shell.history_drag_width = None; } + } else if result.toggle { + let width = crate::ui_kit::history_width(card.width() < crate::ui_kit::history_width(true)); + let _ = app.run("view.history_layout", json!({"width":width})); + ui.ctx().request_repaint(); } }); } +/// Width alone chooses icons, names, horizontal transport and the optional title. +pub fn left_timeline(app: &mut SolveApp, ui: &mut egui::Ui) { + let t = Tokens::get(); + let names = names_fit(ui.available_width()); + timeline_transport(app, ui, names); + if stacked(app) + && ((app.preferences.timeline_collapsed && app.shell.history_folding.is_none_or(|p| p[1] >= 1.0)) || ui.available_height() <= t.space_3) + { + return; + } + ui.painter().hline(ui.max_rect().x_range(), ui.cursor().top(), Stroke::new(1.0, t.border)); + ui.add_space(t.space_3); + egui::ScrollArea::vertical() + .id_salt("sc_left_timeline_scroll") + // The animated card owns its height, including the last few closing frames. + .min_scrolled_height(0.0) + .auto_shrink([false, false]) + .scroll_source(egui::scroll_area::ScrollSource { scroll_bar: true, mouse_wheel: true, ..egui::scroll_area::ScrollSource::NONE }) + .show(ui, |ui| vertical_features(app, ui, names)); +} + +fn timeline_transport(app: &mut SolveApp, ui: &mut egui::Ui, names: bool) { + let t = Tokens::get(); + let count = crate::ui_kit::HistoryTransport::ALL.len() as f32; + let height = if names { crate::ui_kit::TREE_ROW_HEIGHT } else { t.control_height * count + t.space_2 * (count - 1.0) }; + let (header, _) = ui.allocate_exact_size(vec2(ui.available_width(), height), Sense::hover()); + crate::scenario::publish_rect("history:transport", header); + crate::scenario::publish_rect("history:header", header); + let mut controls_right = header.right(); + if names && stacked(app) { + let fold = Rect::from_center_size(pos2(controls_right - t.space_24 / 2.0, header.center().y), vec2(t.space_24, t.space_24)); + let response = crate::ui_kit::panel_disclosure_button_at( + ui, + fold, + !app.preferences.timeline_collapsed, + crate::i18n::tr(if app.preferences.timeline_collapsed { "ui.expand" } else { "ui.collapse" }), + ); + crate::scenario::publish_handle("history:collapse", fold.center()); + if response.clicked() { + let _ = app.run("view.history_layout", json!({"collapsed":!app.preferences.timeline_collapsed})); + } + controls_right = fold.left() - t.space_2; + } + if names { + let mut grip = ui.new_child( + egui::UiBuilder::new() + .max_rect(Rect::from_min_size(header.min, vec2(t.space_10, height))) + .layout(egui::Layout::left_to_right(egui::Align::Center)), + ); + let handle = crate::ui_kit::panel_grip(&mut grip).rect; + let controls_width = crate::ui_kit::history_transport_width(); + let title = crate::i18n::tr("ui.history_title"); + let galley = ui.painter().layout_no_wrap(title.to_owned(), crate::fonts::semibold(t.font_heading), t.text); + let text_left = handle.right() + t.space_8; + let text_right = controls_right - controls_width - t.space_8; + let drag_rect = if text_right - text_left >= galley.size().x { + let title_rect = Rect::from_min_max(pos2(text_left, header.top()), pos2(text_right, header.bottom())); + ui.painter().galley(pos2(text_left, header.center().y - galley.size().y / 2.0), galley, t.text); + crate::scenario::publish_rect("history:title", title_rect); + handle.union(title_rect) + } else { + handle + }; + let drag = ui.interact(drag_rect, egui::Id::new("sc_history_dock_grip"), Sense::drag()); + crate::scenario::publish_handle("history:grip", drag_rect.center()); + dock_drag(app, ui, &drag); + } + for (i, control) in crate::ui_kit::HistoryTransport::ALL.into_iter().enumerate() { + let side = if names { t.space_24 } else { t.control_height }; + let rect = if names { + Rect::from_min_size( + pos2(controls_right - crate::ui_kit::history_transport_width() + i as f32 * (side + t.space_2), header.center().y - side / 2.0), + vec2(side, side), + ) + } else { + Rect::from_min_size(pos2(header.center().x - side / 2.0, header.top() + i as f32 * (side + t.space_2)), vec2(side, side)) + }; + if control.show(ui, rect).clicked() { + crate::timeline::run_transport(app, control); + } + } +} + +#[derive(Clone, Copy, Debug, PartialEq)] +pub(crate) enum Dock { + Bottom, + Left, + UnderBrowser, +} + +impl Dock { + fn id(self) -> &'static str { + match self { + Self::Bottom => "bottom", + Self::Left => "left", + Self::UnderBrowser => "under_browser", + } + } +} + +fn dock_target(app: &SolveApp, available: Rect, at: egui::Pos2) -> Option { + let t = Tokens::get(); + if !available.contains(at) { + return None; + } + if at.y >= available.bottom() - t.space_24 * 2.0 { + return Some(Dock::Bottom); + } + if at.x <= available.left() + t.space_24 * 2.0 { + return Some(Dock::Left); + } + let column = stacked_rects(app, available).0; + if app.ui.show_browser && at.x <= column.right() && at.y >= column.top() + header_outer_height() { Some(Dock::UnderBrowser) } else { None } +} + +pub(crate) fn dock_drag(app: &mut SolveApp, ui: &egui::Ui, drag: &egui::Response) { + if drag.hovered() { + ui.ctx().set_cursor_icon(egui::CursorIcon::Grab); + } + let Some(available) = app.shell.history_dock_space else { + return; + }; + let target = ui.ctx().pointer_latest_pos().and_then(|at| dock_target(app, available, at)); + if drag.dragged() { + ui.ctx().set_cursor_icon(egui::CursorIcon::Grabbing); + if let Some(target) = target { + let zone = match target { + Dock::Bottom => { + if app.ui.layout == crate::shell::LayoutMode::Floating { + crate::timeline::floating_rect(available) + } else { + Rect::from_min_max(pos2(available.left(), (available.bottom() - 40.0).max(available.top())), available.max) + } + } + Dock::Left => { + let mut rect = available; + let gap = if app.ui.layout == crate::shell::LayoutMode::Floating { crate::shell::SHELL_GAP } else { 0.0 }; + rect.min.x += gap; + rect.max.x = (rect.left() + strip_width(app)).min(available.right() - gap); + rect.max.y -= gap; + rect + } + Dock::UnderBrowser => column_rects(app, available, false, false).1, + }; + let t = Tokens::get(); + let painter = ui.ctx().layer_painter(egui::LayerId::new(egui::Order::Foreground, egui::Id::new("history_dock_preview"))); + painter.rect(zone, t.radius_lg, t.accent.gamma_multiply(0.18), Stroke::new(t.space_2, t.accent), egui::StrokeKind::Inside); + crate::scenario::publish_rect("history:dock_preview", zone); + crate::scenario::publish_rect(&format!("history:dock:{}", target.id()), zone); + let label = crate::i18n::tr(match target { + Dock::Bottom => "ui.timeline_bottom", + Dock::Left => "ui.timeline_left_sidebar", + Dock::UnderBrowser => "ui.history_below_browser", + }); + painter.text(zone.center(), egui::Align2::CENTER_CENTER, label, crate::fonts::semibold(t.font_heading), t.text); + } + } + if drag.drag_stopped() + && let Some(target) = target + { + let _ = app.run("view.history_layout", json!({"dock":target.id()})); + } +} + fn nearest_vertical_slot(slots: &[VerticalSlot], y: f32) -> Option { slots.iter().min_by(|a, b| (a.y - y).abs().total_cmp(&(b.y - y).abs())).copied() } @@ -197,17 +468,14 @@ fn vertical_drop_bar_left(panel_left: f32, target: Option, groups: &[solidc fn vertical_marker(app: &mut SolveApp, ui: &mut egui::Ui, drag: &mut Option) { let t = Tokens::get(); - let (rect, response) = ui.allocate_exact_size(vec2(ui.available_width(), 7.0), Sense::drag()); - let line = Rect::from_min_max(pos2(rect.left() + 8.0, rect.center().y - 1.5), pos2(rect.right() - 5.0, rect.center().y + 1.5)); - let colour = crate::theme::TabAccent::for_tab(&t, &app.ui.tab).color; - ui.painter().rect_filled(line, 1.5, colour); - ui.painter().circle_filled(pos2(line.right(), line.center().y), 4.0, colour); + let (rect, response) = ui.allocate_exact_size(vec2(ui.available_width(), t.space_12), Sense::drag()); + crate::ui_kit::history_marker(ui.painter(), rect, true, crate::theme::TabAccent::for_tab(&t, &app.ui.tab)); crate::scenario::publish_handle("timeline:rollback", rect.center()); + crate::scenario::publish_rect("history:marker", rect); if response.drag_started() { *drag = Some(Drag::Marker); } - response.on_hover_text("Rollback bar: drag to roll the model back; new features are inserted here"); - let _ = app; + response.on_hover_text(crate::i18n::tr("ui.history_marker_tip")); } fn group_for(groups: &[solidcraft_engine::doc::TimelineGroup], feature: u64) -> Option { @@ -496,12 +764,16 @@ fn timeline_group_name( group: &solidcraft_engine::doc::TimelineGroup, rect: Rect, offset: f32, + names: bool, t: &Tokens, ) -> bool { let editing = matches!(app.menu.rename.as_ref().map(|rename| &rename.what), Some(crate::context_menu::RenameWhat::TimelineGroup(id)) if *id == group.id); if !editing { - ui.painter().text( + if !names { + return false; + } + ui.painter().with_clip_rect(rect.intersect(ui.clip_rect())).text( pos2(rect.left() + 40.0 + offset, rect.center().y), egui::Align2::LEFT_CENTER, &group.name, @@ -540,6 +812,7 @@ fn timeline_group_name( fn vertical_group_row( app: &mut SolveApp, + names: bool, ui: &mut egui::Ui, group: &solidcraft_engine::doc::TimelineGroup, groups: &[solidcraft_engine::doc::TimelineGroup], @@ -562,18 +835,18 @@ fn vertical_group_row( group: group.parent, indent_group: previous_visible_group.filter(|previous| Some(*previous) != group.parent), }); - let (rect, response) = ui.allocate_exact_size(vec2(ui.available_width(), 23.0), Sense::click_and_drag()); + let (rect, response) = ui.allocate_exact_size(vec2(ui.available_width(), crate::ui_kit::TREE_ROW_HEIGHT), Sense::click_and_drag()); drop_zones.push((rect, group.id)); slots.push(VerticalSlot { y: rect.bottom(), position: if open { position } else { end_position }, group: Some(group.id), indent_group: None }); if selected || response.hovered() { ui.painter().rect_filled(rect, 3.0, if selected { crate::theme::TabAccent::current(ui.ctx()).soft } else { t.hover }); } - let offset = depth as f32 * 14.0; + let offset = if names { depth as f32 * 14.0 } else { 0.0 }; let centre = pos2(rect.left() + 9.0 + offset, rect.center().y); crate::ui_kit::disclosure(ui.painter(), centre, open, t.text_dim); let icon = Rect::from_center_size(pos2(rect.left() + 27.5 + offset, rect.center().y), vec2(17.0, 17.0)); icons::paint(ui.painter(), icon, "folder", t.icon, t.icon_fill, t.accent); - let renaming = timeline_group_name(app, ui, group, rect, offset, &t); + let renaming = timeline_group_name(app, ui, group, rect, offset, names, &t); crate::scenario::publish_handle(&format!("timeline-folder:{}", group.name), rect.center()); let fold_rect = Rect::from_min_max(pos2(rect.left() + offset, rect.top()), pos2(rect.left() + offset + 18.0, rect.bottom())); crate::scenario::publish_handle(&format!("timeline-folder-fold:{}", group.name), fold_rect.center()); @@ -611,9 +884,9 @@ fn vertical_group_row( open } -fn vertical_features(app: &mut SolveApp, ui: &mut egui::Ui) { +fn vertical_features(app: &mut SolveApp, ui: &mut egui::Ui, names: bool) { let t = Tokens::get(); - ui.spacing_mut().item_spacing.y = 0.0; + ui.spacing_mut().item_spacing.y = if names { t.space_2 } else { t.space_4 }; let features: Vec<_> = app .session .doc @@ -665,6 +938,7 @@ fn vertical_features(app: &mut SolveApp, ui: &mut egui::Ui) { if group_ancestors_are_open(app, &groups, group.id) && shown_groups.insert(group.id) { vertical_group_row( app, + names, ui, group, &groups, @@ -694,62 +968,44 @@ fn vertical_features(app: &mut SolveApp, ui: &mut egui::Ui) { let has_patterns = matches!(kind, TimelineKind::Sketch) && crate::sketch_pattern_tree::has_patterns(app, *id); let pattern_key = format!("timeline/sketch/{id}/patterns"); let patterns_open = crate::browser::is_open(app, &pattern_key, true); - let (rect, response) = ui.allocate_exact_size(vec2(ui.available_width(), 24.0), Sense::click_and_drag()); + let style = if names { crate::ui_kit::HistoryStyle::Names } else { crate::ui_kit::HistoryStyle::Icons }; + let (row, response) = ui.allocate_exact_size(vec2(ui.available_width(), style.height()), Sense::click_and_drag()); + let rect = if style == crate::ui_kit::HistoryStyle::Icons { + Rect::from_center_size(row.center(), vec2(style.height(), style.height())) + } else { + row + }; + crate::scenario::publish_rect(&format!("history:feature:{name}"), rect); let fold_rect = Rect::from_min_size(rect.left_top() + vec2(indent, 0.0), vec2(16.0, rect.height())); let on_fold = has_patterns && response.interact_pointer_pos().is_some_and(|p| fold_rect.contains(p)); crate::scenario::publish_handle(&format!("timeline:{name}"), rect.center()); let result = app.session.model.result(*id); + let elapsed = result.map(|r| r.ms); let error = result.and_then(|result| result.error.clone()); let warning = result.and_then(|result| result.warning.clone()); let rolled = index >= marker; let selected = app.session.selection.iter().any(|selection| matches!(selection, solidcraft_engine::Sel::Feature { id: selected } if selected == id)); - let background = if error.is_some() { - t.timeline_item_error - } else if selected { - crate::theme::TabAccent::current(ui.ctx()).soft - } else if response.hovered() || from_view == Some(*id) { - t.hover - } else { - Color32::TRANSPARENT - }; - if background != Color32::TRANSPARENT { - ui.painter().rect_filled(rect, 3.0, background); + // Folder and sketch-pattern disclosure targets retain their original handles. + let inset = if names { indent + if has_patterns { 16.0 } else { 0.0 } } else { 0.0 }; + let chip = Rect::from_min_max(rect.min + vec2(inset.min(rect.width()), 0.0), rect.max); + crate::ui_kit::HistoryChip { + icon, + name, + kind: ty, + selected, + hovered: response.hovered() || from_view == Some(*id), + dim: rolled, + suppressed: *suppressed, + error: error.is_some(), + warning: warning.is_some(), + accent: crate::theme::TabAccent::for_tab(&t, &app.ui.tab), } + .paint(ui.painter(), chip, style); if has_patterns { crate::ui_kit::disclosure(ui.painter(), fold_rect.center(), patterns_open, t.text_dim); crate::scenario::publish_handle(&format!("timeline-sketch-fold:{name}"), fold_rect.center()); } - let icon_rect = - Rect::from_center_size(pos2(rect.left() + 13.0 + indent + if has_patterns { 16.0 } else { 0.0 }, rect.center().y), vec2(18.0, 18.0)); - let ink = if rolled || *suppressed { t.border } else { t.icon }; - icons::paint(ui.painter(), icon_rect, icon, ink, if rolled { t.panel_header } else { t.icon_fill }, if rolled { t.border } else { t.accent }); - if *suppressed { - ui.painter().line_segment([icon_rect.left_bottom(), icon_rect.right_top()], Stroke::new(1.5, t.text_dim)); - } - let text_colour = if rolled || *suppressed { t.text_dim } else { t.text }; - ui.painter().text( - pos2(icon_rect.right() + 7.0, rect.center().y), - egui::Align2::LEFT_CENTER, - name, - egui::FontId::proportional(crate::theme::Tokens::get().font_body), - text_colour, - ); - // A failed feature has a mark of its own, not only its colour (#972). - if error.is_some() { - let at = Rect::from_min_size(pos2(rect.right() - 15.0, rect.center().y - 6.0), vec2(12.0, 12.0)); - icons::paint(ui.painter(), at, "error", t.panel, t.error, t.error); - } - if warning.is_some() && error.is_none() { - icons::paint( - ui.painter(), - Rect::from_min_size(pos2(rect.right() - 15.0, rect.center().y - 6.0), vec2(12.0, 12.0)), - "warning", - t.icon, - t.warning, - t.warning, - ); - } if response.hovered() { hovered = Some(*id); } @@ -760,9 +1016,23 @@ fn vertical_features(app: &mut SolveApp, ui: &mut egui::Ui) { let origin_x = drag_press_x(&response, rect.center().x); drag = Some(Drag::Items(selected_drag_items(app, origin_x, group_id))); } - let mut tip = crate::timeline::status_text(name, ty, error.as_deref(), warning.as_deref()); - tip.push_str("\nDouble-click to edit · drag to reorder · right-click for more"); - let response = response.on_hover_text(tip); + let mut tooltip = egui::Tooltip::for_enabled(&response); + tooltip.popup = tooltip.popup.align(egui::RectAlign::RIGHT_START); + tooltip.show(|ui| { + let summary = app + .session + .doc + .features + .get(index) + .and_then(|f| f.kind.expressions().first().map(ToString::to_string)) + .unwrap_or_else(|| elapsed.map_or_else(String::new, |ms| format!("{ms:.1} ms"))); + let kind = crate::i18n::tr_label(ty.strip_suffix("Feature").unwrap_or(ty)); + let mut tip = format!("{name} · {kind} · {summary}"); + if error.is_some() || warning.is_some() { + tip.push_str(&format!("\n{}", crate::timeline::status_text(name, ty, error.as_deref(), warning.as_deref()))); + } + crate::ui_kit::text(ui, &tip, crate::ui_kit::Text::Value("history", false)); + }); if response.clicked() && on_fold { crate::browser::toggle(app, &pattern_key, true); } else if response.clicked() { @@ -809,7 +1079,7 @@ fn vertical_features(app: &mut SolveApp, ui: &mut egui::Ui) { ui.close(); } }); - if has_patterns && patterns_open { + if names && has_patterns && patterns_open { let depth = group_id.map_or(1, |group| group_depth(&groups, group) + 2); crate::sketch_pattern_tree::rows(app, ui, *id, depth, "timeline", None, false); } @@ -821,6 +1091,7 @@ fn vertical_features(app: &mut SolveApp, ui: &mut egui::Ui) { if group_ancestors_are_open(app, &groups, group.id) && shown_groups.insert(group.id) { vertical_group_row( app, + names, ui, group, &groups, @@ -859,9 +1130,11 @@ fn vertical_features(app: &mut SolveApp, ui: &mut egui::Ui) { ui.painter().rect_stroke(rect.shrink(1.0), 3.0, Stroke::new(2.0, t.sketch_accent), egui::StrokeKind::Inside); } else { let left = vertical_drop_bar_left(ui.min_rect().left(), folder_target, &groups); - ui.painter().line_segment( - [pos2(left, slot.y), pos2(ui.max_rect().right() - 5.0, slot.y)], - Stroke::new(2.0, if matches!(active, Drag::Marker) { crate::theme::TabAccent::current(ui.ctx()).color } else { t.sketch_accent }), + crate::ui_kit::history_drop_bar( + ui.painter(), + Rect::from_min_max(pos2(left, slot.y), pos2(ui.max_rect().right() - 5.0, slot.y)), + true, + if matches!(active, Drag::Marker) { crate::theme::TabAccent::current(ui.ctx()).color } else { t.sketch_accent }, ); } } @@ -913,45 +1186,394 @@ mod tests { use crate::scenario::{Harness, handle_at}; #[test] - fn left_history_shows_named_features_and_folders_above_the_browser() { - let mut harness = Harness::new(); - harness.app.preferences.timeline_left = true; - harness.app.run("solid.box", json!({"length": 20, "width": 15, "height": 10, "name": "Base"})).unwrap(); - harness.app.run("solid.fillet", json!({"edges": [[20, 7.5, 10]], "radius": 1, "name": "Round"})).unwrap(); - harness.app.run("timeline.group", json!({"name": "Housing", "features": ["Base", "Round"]})).unwrap(); - harness.frames(4); - - let folder = handle_at("timeline-folder:Housing").unwrap(); - let base = handle_at("timeline:Base").unwrap(); - let round = handle_at("timeline:Round").unwrap(); - let browser = handle_at("row:Untitled").unwrap(); - assert!(folder.x < 250.0 && base.x < 250.0 && round.x < 250.0); - assert!(folder.y < base.y && base.y < round.y); - assert!(round.y < browser.y, "the parts/scene browser belongs below the feature history"); + fn docking_previews_match_all_three_destinations_and_stacked_collapse_shares_height() { + for mode in [crate::shell::LayoutMode::Floating, crate::shell::LayoutMode::Docked] { + let mut h = Harness::new(); + h.app.home.open = false; + h.app.ui.layout = mode; + h.call("ui.resize", json!({"width":1400,"height":1000})); + h.app.preferences.timeline_left = true; + h.app.preferences.timeline_left_width = 240.0; + h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"name":"First"})).unwrap(); + h.frames(6); + let design = h.app.session.doc.to_json(); + let projection = h.app.viewport.rect; + for (dock, point) in [("bottom", pos2(700.0, 990.0)), ("left", pos2(10.0, 400.0)), ("under_browser", pos2(130.0, 700.0))] { + let grip = handle_at("history:grip").expect("dock grip"); + h.app.synthetic.push(egui::Event::PointerMoved(grip)); + h.frame(); + h.app.synthetic.push(egui::Event::PointerButton { + pos: grip, + button: egui::PointerButton::Primary, + pressed: true, + modifiers: egui::Modifiers::NONE, + }); + h.frame(); + h.app.synthetic.push(egui::Event::PointerMoved(point)); + h.frames(2); + let preview = crate::scenario::rect_of("history:dock_preview").expect("dock preview"); + h.app.synthetic.push(egui::Event::PointerButton { + pos: point, + button: egui::PointerButton::Primary, + pressed: false, + modifiers: egui::Modifiers::NONE, + }); + h.frames(6); + assert_eq!(h.app.preferences.timeline_left, dock != "bottom"); + assert_eq!(h.app.preferences.timeline_under_browser, dock == "under_browser"); + let card = h.app.shell.history.expect("history bounds"); + assert!( + (preview.min - card.min).length() < 1.0 && (preview.max - card.max).length() < 1.0, + "{mode:?} {dock}: preview={preview:?} card={card:?}" + ); + assert_eq!(h.app.session.doc.to_json(), design); + if mode == crate::shell::LayoutMode::Floating { + assert_eq!(h.app.viewport.rect, projection); + } + } + let browser = h.app.shell.browser.unwrap(); + let history = h.app.shell.history.unwrap(); + assert!((browser.width() - history.width()).abs() < 1.0); + assert!((browser.height() - history.height()).abs() < 1.0); + assert!(browser.bottom() < history.top()); + let at = handle_at("history:collapse").unwrap(); + h.call("ui.click", json!({"x":at.x,"y":at.y})); + h.frames(5); + assert!(h.app.shell.history.unwrap().height() <= header_outer_height() + 1.0); + assert!(h.app.shell.browser.unwrap().height() > browser.height() * 1.5); + let at = handle_at("left-browser-toggle").unwrap(); + h.call("ui.click", json!({"x":at.x,"y":at.y})); + h.frames(5); + assert!(h.app.preferences.timeline_left_browser_collapsed); + assert!(h.app.preferences.timeline_collapsed); + let folded_browser = h.app.shell.browser.unwrap(); + let folded_history = h.app.shell.history.unwrap(); + assert!(folded_browser.height() <= header_outer_height() + 1.0); + assert!(folded_history.height() <= header_outer_height() + 1.0); + assert!((folded_history.top() - folded_browser.bottom() - crate::shell::SHELL_GAP).abs() < 1.0); + let at = handle_at("history:collapse").unwrap(); + h.call("ui.click", json!({"x":at.x,"y":at.y})); + h.frames(5); + assert!(h.app.preferences.timeline_left_browser_collapsed); + assert!(!h.app.preferences.timeline_collapsed); + assert!(h.app.shell.history.unwrap().height() > history.height() * 1.5); + h.app.preferences.browser_width = 310.0; + h.frames(5); + assert!((h.app.shell.history.unwrap().width() - 310.0).abs() < 1.0); + assert!((h.app.shell.browser.unwrap().width() - 310.0).abs() < 1.0); + // Browser-first collapse must also leave both independent folded headers at the top. + let at = handle_at("history:collapse").unwrap(); + h.call("ui.click", json!({"x":at.x,"y":at.y})); + h.frames(5); + assert!(h.app.preferences.timeline_left_browser_collapsed && h.app.preferences.timeline_collapsed); + assert!((h.app.shell.browser.unwrap().top() - browser.top()).abs() < 1.0); + assert!(h.app.shell.history.unwrap().bottom() < browser.top() + header_outer_height() * 2.0 + crate::shell::SHELL_GAP + 1.0); + } } #[test] - fn history_browser_divider_resizes_and_browser_collapses() { - let mut harness = Harness::new(); - harness.app.preferences.timeline_left = true; - harness.app.preferences.timeline_left_height = 180.0; - harness.frames(4); + fn folding_cards_follow_their_bounds_through_the_last_animation_frame() { + for mode in [crate::shell::LayoutMode::Floating, crate::shell::LayoutMode::Docked] { + let mut h = Harness::new(); + h.app.home.open = false; + h.app.ui.layout = mode; + h.app.preferences.timeline_left = true; + h.app.preferences.timeline_under_browser = true; + h.app.preferences.browser_width = 220.0; + h.app.run("solid.box", json!({"length":10,"width":10,"height":10})).unwrap(); + h.frames(6); + // Both closing orders, expansion, and reversal before a transition completes. + for (browser, history, frames) in + [(true, false, 12), (true, true, 12), (false, true, 12), (false, false, 12), (true, true, 3), (false, false, 12)] + { + h.app.preferences.timeline_left_browser_collapsed = browser; + h.app.preferences.timeline_collapsed = history; + for frame in 0..frames { + h.frame(); + let available = h.app.shell.history_dock_space.unwrap(); + let expected = stacked_rects(&h.app, available); + for (name, actual, target) in + [("Browser", h.app.shell.browser.unwrap(), expected.0), ("History", h.app.shell.history.unwrap(), expected.1)] + { + assert!( + (actual.min - target.min).length() < 1.0 && (actual.max - target.max).length() < 1.0, + "{mode:?} {name}, frame {frame}, folds ({browser}, {history}): {actual:?} != {target:?}" + ); + } + } + } + } + } - let divider = handle_at("left-history-divider").unwrap(); - let before = harness.app.preferences.timeline_left_height; - harness.step(&json!({"drag": [[divider.x, divider.y], [divider.x, divider.y + 40.0]]})).unwrap(); - assert!( - harness.app.preferences.timeline_left_height > before + 20.0, - "dragging the divider should remember a taller history section: {before} -> {}", - harness.app.preferences.timeline_left_height - ); + #[test] + fn all_four_transport_buttons_move_to_their_named_positions_in_every_layout() { + for mode in [crate::shell::LayoutMode::Floating, crate::shell::LayoutMode::Docked] { + for (dock, width) in + [("bottom", 130.0), ("left", 56.0), ("left", crate::ui_kit::history_width(true)), ("left", 320.0), ("under_browser", 170.0)] + { + let mut h = Harness::new(); + h.app.home.open = false; + h.app.ui.layout = mode; + h.app.preferences.browser_width = 170.0; + h.app.run("view.history_layout", json!({"dock":dock,"width":width})).unwrap(); + for i in 0..3 { + h.app + .run( + "solid.box", + json!({"length":10,"width":10,"height":10,"corner":[i*20,0,0],"operation":"new_body","name":format!("Step {i}")}), + ) + .unwrap(); + } + h.settle(); + let features = h.app.session.doc.features.clone(); + for control in crate::ui_kit::HistoryTransport::ALL { + let button = crate::scenario::rect_of(&format!("history:{}", control.id())).unwrap(); + let header = crate::scenario::rect_of(if dock == "bottom" { + if mode == crate::shell::LayoutMode::Floating { "history:card" } else { "history:strip" } + } else { + "history:header" + }) + .unwrap(); + assert!(header.contains_rect(button), "{mode:?} {dock} {width}: transport button {button:?} outside {header:?}"); + } + for (control, position) in [ + ("first", Some(0)), + ("back", Some(0)), + ("forward", Some(1)), + ("forward", Some(2)), + ("back", Some(1)), + ("last", None), + ("back", Some(2)), + ("back", Some(1)), + ("forward", Some(2)), + ("forward", None), + ("forward", None), + ("first", Some(0)), + ("last", None), + ] { + h.step(&json!({"click":{"handle":format!("history:{control}")}})).unwrap(); + h.settle(); + assert_eq!(h.app.session.doc.marker, position, "{mode:?} {dock} {width}: {control}"); + assert_eq!(h.app.session.model.state().bodies.len(), position.unwrap_or(3)); + assert_eq!(h.app.session.doc.features, features, "transport only moves the marker"); + } + } + } + } - harness.step(&json!({"click": {"handle": "left-browser-toggle"}})).unwrap(); - assert!(harness.app.preferences.timeline_left_browser_collapsed); - assert!(handle_at("row:Untitled").is_none(), "the collapsed browser should hide its rows"); - harness.step(&json!({"click": {"handle": "left-browser-toggle"}})).unwrap(); - assert!(!harness.app.preferences.timeline_left_browser_collapsed); - assert!(handle_at("row:Untitled").is_some(), "expanding the browser should restore its rows"); + #[test] + fn seam_snaps_only_between_thin_and_medium_and_persists_free_widths() { + let medium = crate::ui_kit::history_width(true); + for (width, delta, expected) in [(56.0, 40.0, medium), (medium, -40.0, 56.0), (medium, 63.0, medium + 63.0), (320.0, -41.0, 279.0)] { + let mut h = Harness::new(); + h.app.preferences.timeline_left = true; + h.app.preferences.timeline_left_width = width; + h.settle(); + let card = crate::scenario::rect_of("history:vertical").unwrap(); + let start = pos2(card.right() - 4.0, card.top() + 12.0); + h.step(&json!({"drag":[[start.x,start.y],[start.x+delta,start.y]]})).unwrap(); + h.settle(); + assert!((h.app.preferences.timeline_left_width - expected).abs() < 1.0); + assert!(h.app.shell.history_drag_width.is_none()); + assert!((crate::scenario::rect_of("history:vertical").unwrap().width() - expected).abs() < 1.0); + assert!(h.app.dialog.is_none()); + let mut restored = Harness::new(); + restored.app.load_prefs(&h.app.prefs()); + assert_eq!(restored.app.preferences.timeline_left_width, expected); + } + } + + #[test] + fn contents_follow_measured_width_without_a_names_setting() { + for width in [56.0, crate::ui_kit::history_width(true), 168.0, 213.0, 320.0] { + let mut h = Harness::new(); + h.app.preferences.timeline_left = true; + h.app.preferences.timeline_left_width = width; + h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"name":"First"})).unwrap(); + h.settle(); + let row = crate::scenario::rect_of("history:feature:First").unwrap(); + let back = handle_at("history:back").unwrap(); + let play = handle_at("history:last").unwrap(); + assert_eq!(row.height(), if width < crate::ui_kit::history_width(true) { 38.0 } else { crate::ui_kit::TREE_ROW_HEIGHT }); + assert_eq!(handle_at("history:grip").is_some(), width >= crate::ui_kit::history_width(true)); + assert_eq!(back.y == play.y, width >= crate::ui_kit::history_width(true)); + if width == crate::ui_kit::history_width(true) { + assert!(crate::scenario::rect_of("history:title").is_none()); + } + if width >= 213.0 { + assert!(crate::scenario::rect_of("history:title").is_some()); + } + assert!(!crate::shortcut_box::search(&h.app, "history names").iter().any(|row| row.0 == "view.history_names")); + } + } + + #[test] + fn transport_to_first_item_gap_is_at_most_twelve_points() { + let previous = crate::theme::is_dark(); + for dark in [false, true] { + crate::theme::set_dark(dark); + for mode in [crate::shell::LayoutMode::Floating, crate::shell::LayoutMode::Docked] { + for names in [false, true] { + let mut h = Harness::new(); + h.app.ui.dark = dark; + h.app.preferences.theme = if dark { "dark" } else { "light" }.into(); + h.app.ui.layout = mode; + h.app.preferences.timeline_left = true; + h.app.preferences.timeline_left_width = crate::ui_kit::history_width(names); + h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"name":"First"})).unwrap(); + for selected in [false, true] { + if selected { + let id = h.app.session.doc.features.first().unwrap().id; + h.app.run("select.set", json!({"items":[{"type":"feature","id":id}]})).unwrap(); + } + h.settle(); + assert_eq!(crate::theme::is_dark(), dark); + let transport = crate::scenario::rect_of("history:transport").unwrap(); + let first = crate::scenario::rect_of("history:feature:First").unwrap(); + let gap = first.top() - transport.bottom(); + assert!((0.0..=12.0).contains(&gap), "gap={gap} dark={dark} mode={mode:?} names={names} selected={selected}"); + } + } + } + } + crate::theme::set_dark(previous); + } + + #[test] + fn rendered_strip_content_never_exceeds_the_viewport_during_resize() { + for mode in [crate::shell::LayoutMode::Floating, crate::shell::LayoutMode::Docked] { + for width in [70.0, 100.0, 130.0, 200.0] { + for drag_width in [None, Some(60.0), Some(112.0), Some(160.0)] { + let ctx = crate::fonts::test_context(); + let mut app = crate::test_support::sample_app(); + app.ui.layout = mode; + app.preferences.timeline_left = true; + app.shell.history_drag_width = drag_width; + let screen = Rect::from_min_size(egui::Pos2::ZERO, vec2(width, 600.0)); + for _ in 0..3 { + let mut out = ctx.run_ui(egui::RawInput { screen_rect: Some(screen), ..Default::default() }, |ui| left_panel(&mut app, ui)); + out.textures_delta.clear(); + } + if let Some(card) = app.shell.history { + assert!(screen.contains_rect(card), "mode={mode:?} viewport={screen:?} card={card:?}"); + } + } + } + } + } + + #[test] + fn history_seam_widths_stay_inside_small_viewports() { + let mut app = crate::test_support::sample_app(); + for names in [false, true] { + app.preferences.timeline_left_width = crate::ui_kit::history_width(names); + for drag in [None, Some(112.0), Some(f32::INFINITY)] { + app.shell.history_drag_width = drag; + for width in [0.0, 20.0, 56.0, 100.0, 200.0, 800.0] { + let available = Rect::from_min_size(pos2(15.0, 30.0), vec2(width, 300.0)); + assert!(available.contains_rect(floating_rect(&app, available))); + } + } + } + } + + #[test] + fn both_widths_keep_selection_reorder_marker_transport_and_feature_menus() { + for names in [false, true] { + let mut h = Harness::new(); + h.app.preferences.timeline_left = true; + h.app.preferences.timeline_left_width = crate::ui_kit::history_width(names); + for (name, x) in [("First", 0), ("Second", 20)] { + h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"corner":[x,0,0],"operation":"new_body","name":name})).unwrap(); + } + h.settle(); + h.step(&json!({"click":{"handle":"timeline:First"}})).unwrap(); + h.step(&json!({"click":{"handle":"timeline:Second"},"ctrl":true})).unwrap(); + assert_eq!(selected_feature_ids(&h.app).len(), 2); + h.step(&json!({"click":{"handle":"timeline:Second"},"button":"right"})).unwrap(); + h.step(&json!({"widget":"Copy"})).unwrap(); + assert_eq!(h.app.session.clipboard.len(), 2); + h.app.run("select.clear", json!({})).unwrap(); + h.settle(); + let first = handle_at("timeline:First").unwrap(); + h.step(&json!({"drag":[{"handle":"timeline:Second"},[first.x,first.y-15.0]]})).unwrap(); + h.settle(); + assert_eq!(h.app.session.doc.features.first().unwrap().name, "Second"); + let first = handle_at("timeline:Second").unwrap(); + h.step(&json!({"drag":[{"handle":"timeline:rollback"},[first.x,first.y-15.0]]})).unwrap(); + h.settle(); + assert_eq!(h.app.session.doc.marker, Some(0)); + h.step(&json!({"click":{"handle":"history:forward"}})).unwrap(); + h.settle(); + assert_eq!(h.app.session.doc.marker, Some(1)); + h.step(&json!({"click":{"handle":"history:last"}})).unwrap(); + h.settle(); + assert_eq!(h.app.session.doc.marker, None); + h.frames(40); + h.step(&json!({"click":{"handle":"timeline:First"},"double":true})).unwrap(); + h.frames(3); + assert!(h.app.dialog.is_some(), "double-click edits the feature, names={names}"); + } + } + + #[test] + fn history_is_left_of_the_browser_in_both_layouts_widths_and_browser_states() { + for mode in [crate::shell::LayoutMode::Floating, crate::shell::LayoutMode::Docked] { + for names in [false, true] { + for collapsed in [false, true] { + let mut h = Harness::new(); + h.app.ui.layout = mode; + h.app.preferences.timeline_left = true; + h.app.preferences.timeline_left_width = crate::ui_kit::history_width(names); + h.app.preferences.timeline_left_browser_collapsed = collapsed; + h.app.run("solid.box", json!({"length":20,"width":15,"height":10,"name":"Base"})).unwrap(); + h.app.run("solid.fillet", json!({"edges":[[20,7.5,10]],"radius":1,"name":"Round"})).unwrap(); + h.app.run("timeline.group", json!({"name":"Housing","features":["Base","Round"]})).unwrap(); + h.settle(); + let history = crate::scenario::rect_of("history:vertical").unwrap(); + let browser = crate::scenario::rect_of("browser:card").unwrap(); + assert!(history.right() < browser.left(), "{mode:?}, names={names}, collapsed={collapsed}: {history:?}, {browser:?}"); + assert_eq!(history.width(), crate::ui_kit::history_width(names)); + assert_eq!(handle_at("row:Untitled").is_none(), collapsed); + let folder = handle_at("timeline-folder:Housing").unwrap(); + let base = handle_at("timeline:Base").unwrap(); + let round = handle_at("timeline:Round").unwrap(); + assert!(folder.y < base.y && base.y < round.y); + let row = crate::scenario::rect_of("history:feature:Base").unwrap(); + assert_eq!(row.height(), if names { crate::ui_kit::TREE_ROW_HEIGHT } else { 38.0 }); + if names && !collapsed { + let browser_row = crate::browser::drawn_rows().into_iter().find(|r| r.0 == "Untitled").unwrap().1; + assert_eq!(row.height(), browser_row.height()); + } + } + } + } + } + + #[test] + fn history_width_toggle_and_browser_rail_persist_independently() { + let mut h = Harness::new(); + h.app.preferences.timeline_left = true; + h.settle(); + h.step(&json!({"click":{"handle":"history:names"}})).unwrap(); + assert!(h.app.preferences.timeline_left_width < crate::ui_kit::history_width(true)); + h.step(&json!({"click":{"handle":"left-browser-toggle"}})).unwrap(); + assert!(h.app.preferences.timeline_left_browser_collapsed); + assert!(handle_at("row:Untitled").is_none()); + let mut restored = Harness::new(); + restored.app.load_prefs(&h.app.prefs()); + assert!(restored.app.preferences.timeline_left_width < crate::ui_kit::history_width(true)); + assert!(restored.app.preferences.timeline_left_browser_collapsed); + h.settle(); + h.step(&json!({"click":{"handle":"left-browser-toggle"}})).unwrap(); + assert!(!h.app.preferences.timeline_left_browser_collapsed); + assert!(handle_at("row:Untitled").is_some()); + h.step(&json!({"click":{"handle":"history:names"}})).unwrap(); + assert!(h.app.preferences.timeline_left_width >= crate::ui_kit::history_width(true)); + h.step(&json!({"key":"Enter"})).unwrap(); + assert!(h.app.preferences.timeline_left_width < crate::ui_kit::history_width(true), "focused seam handles Enter in the app"); + h.step(&json!({"key":"Space"})).unwrap(); + assert!(h.app.preferences.timeline_left_width >= crate::ui_kit::history_width(true), "focused seam handles Space in the app"); } #[test] @@ -1179,7 +1801,7 @@ mod tests { harness.frames(4); harness.step(&json!({"click": {"handle": "timeline:Feature"}})).unwrap(); - harness.step(&json!({"widget": "1 selected"})).unwrap(); + harness.step(&json!({"click": {"handle": "timeline:Feature"}, "button": "right"})).unwrap(); harness.step(&json!({"widget": "Add to New Folder"})).unwrap(); harness.frames(2); diff --git a/crates/ui-egui/src/ui_kit/disclosure.rs b/crates/ui-egui/src/ui_kit/disclosure.rs index 62ed11754..34d12c622 100644 --- a/crates/ui-egui/src/ui_kit/disclosure.rs +++ b/crates/ui-egui/src/ui_kit/disclosure.rs @@ -13,13 +13,26 @@ pub(crate) fn disclosure(painter: &Painter, center: Pos2, open: bool, ink: Color /// Fold action in existing chrome. Stable identity across state changes, with the caller's /// translated tooltip and scenario handles. Tokens: control_radius, hover, form_ink/dim. pub(crate) fn disclosure_button_at(ui: &mut Ui, rect: Rect, open: bool, label: &str) -> Response { + disclosure_button_with_hover(ui, rect, open, label, false) +} + +/// Panel fold action with the browser's shared blue hover tint. +pub(crate) fn panel_disclosure_button_at(ui: &mut Ui, rect: Rect, open: bool, label: &str) -> Response { + disclosure_button_with_hover(ui, rect, open, label, true) +} + +fn disclosure_button_with_hover(ui: &mut Ui, rect: Rect, open: bool, label: &str, panel: bool) -> Response { let t = Tokens::get(); let response = ui.interact(rect, ui.make_persistent_id("disclosure_button"), egui::Sense::click()); if response.clicked() { response.request_focus(); } if response.hovered() { - ui.painter().rect_filled(rect, t.control_radius, t.hover); + if panel { + super::panel_header_hover(ui.painter(), rect); + } else { + ui.painter().rect_filled(rect, t.control_radius, t.hover); + } } disclosure(ui.painter(), rect.center(), open, if response.hovered() || response.has_focus() { t.form_ink } else { t.form_dim }); response.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::CollapsingHeader, ui.is_enabled(), open, label)); diff --git a/crates/ui-egui/src/ui_kit/gallery.rs b/crates/ui-egui/src/ui_kit/gallery.rs index f002e7dc8..84808167a 100644 --- a/crates/ui-egui/src/ui_kit/gallery.rs +++ b/crates/ui-egui/src/ui_kit/gallery.rs @@ -28,6 +28,32 @@ macro_rules! element { // One entry per element/variant: names, rendering and geometry expectations stay together. const ELEMENTS: &[Element] = &[ + element!("history_transport", |ui, _| { + ui.horizontal(|ui| { + let side = Tokens::get().space_24; + for control in HistoryTransport::ALL { + let (rect, _) = ui.allocate_exact_size(vec2(side, side), egui::Sense::hover()); + control.show(ui, rect); + } + }); + }), + element!("history_marker", |ui, _| { + let t = Tokens::get(); + let accent = crate::theme::TabAccent::for_tab(&t, "SURFACE"); + ui.horizontal(|ui| { + let (rect, _) = ui.allocate_exact_size(vec2(t.space_24 * 7.0, t.space_12), egui::Sense::hover()); + ui.painter().rect_filled(rect, 0.0, t.panel); + history_marker(ui.painter(), rect, true, accent); + let (rect, _) = ui.allocate_exact_size(vec2(t.space_12, t.control_height), egui::Sense::hover()); + ui.painter().rect_filled(rect, 0.0, t.timeline); + history_marker(ui.painter(), rect, false, accent); + }); + }), + element!("history_seam_rest", |ui, _| history_seam_example(ui, HistoryHandleState::Rest)), + element!("history_seam_hover", |ui, _| history_seam_example(ui, HistoryHandleState::Hover)), + element!("history_seam_drag", |ui, _| history_seam_example(ui, HistoryHandleState::Drag)), + element!("history_icons", |ui, _| history_example(ui, false)), + element!("history_names", |ui, _| history_example(ui, true)), element!("command_search", |ui, _| { let mut query = "fillet".to_owned(); CommandSearch::field( @@ -441,6 +467,13 @@ const ELEMENTS: &[Element] = &[ ui.push_id(open, |ui| disclosure_button_at(ui, rect, open, crate::i18n::tr_label(if open { "Collapse" } else { "Expand" }))); } }), + element!("panel_disclosure_button_at", |ui, _| { + let t = Tokens::get(); + for open in [true, false] { + let (rect, _) = ui.allocate_exact_size(vec2(t.form_close_size, t.form_close_size), egui::Sense::hover()); + ui.push_id(open, |ui| panel_disclosure_button_at(ui, rect, open, crate::i18n::tr_label(if open { "Collapse" } else { "Expand" }))); + } + }), element!("dropdown_indicator", |ui, _| { let t = Tokens::get(); let (rect, _) = ui.allocate_exact_size(vec2(t.form_section_icon_size, t.form_section_icon_size), egui::Sense::hover()); @@ -713,7 +746,7 @@ const ELEMENTS: &[Element] = &[ fn example(ui: &mut Ui, element: &Element) -> (&'static str, Option<&'static str>) { let mut sample = Sample { value: "12 mm".into(), second: "25 mm".into(), selected: 0, checked: true }; let rect = ui.scope(|ui| (element.draw)(ui, &mut sample)).response.rect; - if matches!(element.name, "menu" | "menu_submenu" | "rename_menu" | "workspace_menu" | "command_search") { + if matches!(element.name, "menu" | "menu_submenu" | "rename_menu" | "workspace_menu" | "command_search" | "history_icons" | "history_names") { // A popup's elevation is painted outside its layout rectangle. Reserve those // actual shadow bounds as part of the gallery sample, keeping the paint guard strict. ui.expand_to_include_rect(rect + Menu::frame().shadow.margin()); @@ -1070,6 +1103,112 @@ fn gallery_covers_every_inline_element() { } } +#[cfg(test)] +fn history_seam_example(ui: &mut Ui, state: HistoryHandleState) { + let t = Tokens::get(); + let allocation = ui.allocate_space(vec2(280.0, 250.0)).1; + for (names, offset) in [(false, 0.0), (true, 125.0)] { + let width = if state == HistoryHandleState::Drag { 112.0 } else { history_width(names) }; + // Separate samples vertically so the guide/chip fits within the gallery allocation. + let card = egui::Rect::from_min_size(allocation.min + vec2(t.space_8, offset + t.space_8), vec2(width, 104.0)); + ui.painter().rect(card, t.radius_lg, t.panel, egui::Stroke::new(1.0, t.border), egui::StrokeKind::Inside); + HistorySeam::new(card).paint(ui.painter(), card, names, state); + } +} + +#[cfg(test)] +fn history_example(ui: &mut Ui, names: bool) { + let mut app = crate::test_support::sample_app(); + app.preferences.timeline_left = true; + app.preferences.timeline_left_width = crate::ui_kit::history_width(names); + app.run("timeline.roll_to", serde_json::json!({"position":3})).unwrap(); + let feature = app.session.doc.features.get(2).unwrap().id; + app.run("select.set", serde_json::json!({"items":[{"type":"feature","id":feature}]})).unwrap(); + let width = crate::timeline_left::strip_width(&app); + let rect = ui.allocate_space(vec2(width, 650.0)).1; + ui.scope_builder(egui::UiBuilder::new().max_rect(rect.shrink(5.0)), |ui| { + ui.painter().add(crate::frame::shell_card(Tokens::get().panel).paint(rect)); + crate::timeline_left::left_timeline(&mut app, ui); + }); +} + +/// CPU captures of the actual vertical strip and browser, in both themes and widths. +#[test] +fn history_board_in_both_themes_and_widths() { + use super::checks::tests::{raster, textures_update}; + use std::collections::HashMap; + let previous = crate::theme::is_dark(); + for dark in [false, true] { + for names in [false, true] { + for collapsed in [false, true] { + for state in [HistoryHandleState::Rest, HistoryHandleState::Hover, HistoryHandleState::Drag] { + crate::theme::set_dark(dark); + let ctx = crate::fonts::test_context(); + ctx.set_visuals(if dark { egui::Visuals::dark() } else { egui::Visuals::light() }); + ctx.global_style_mut(|style| style.animation_time = 0.0); + let mut app = crate::test_support::sample_app(); + app.preferences.timeline_left = true; + app.preferences.timeline_left_width = crate::ui_kit::history_width(names); + app.preferences.timeline_left_browser_collapsed = collapsed; + app.run("timeline.roll_to", serde_json::json!({"position":3})).unwrap(); + let feature = app.session.doc.features.get(2).unwrap().id; + app.run("select.set", serde_json::json!({"items":[{"type":"feature","id":feature}]})).unwrap(); + let bounds = egui::Rect::from_min_size(egui::Pos2::ZERO, vec2(560.0, 680.0)); + let mut textures = HashMap::new(); + let mut image = None; + let mut drag_start = None; + for pass in 0..9 { + let mut events = vec![]; + if pass >= 2 { + let card = app.shell.history.unwrap(); + if state == HistoryHandleState::Hover { + events.push(egui::Event::PointerMoved(card.right_center())); + } else if state == HistoryHandleState::Drag { + let start = *drag_start.get_or_insert(egui::pos2(card.right() - 4.0, card.top() + 12.0)); + if pass == 2 { + events = crate::test_support::pointer(start, true); + } else if pass == 3 { + events.push(egui::Event::PointerMoved(start + vec2(112.0 - history_width(names), 0.0))); + } + } + } + let mut output = ctx.run_ui( + egui::RawInput { screen_rect: Some(bounds), time: Some(pass as f64 * 0.2), focused: true, events, ..Default::default() }, + |ui| { + ui.painter().rect_filled(bounds, 0.0, Tokens::get().viewport_top); + crate::timeline_left::left_panel(&mut app, ui); + crate::browser::floating(&mut app, ui, bounds); + }, + ); + textures_update(&mut textures, &output.textures_delta); + output.textures_delta.clear(); + image = Some(raster(&ctx, output.shapes, output.pixels_per_point, bounds, &textures)); + } + if state == HistoryHandleState::Drag { + assert_eq!(app.shell.history_drag_width, Some(112.0)); + assert_eq!(app.shell.history.unwrap().width(), 112.0); + } + assert!(app.shell.history.unwrap().right() < app.shell.browser.unwrap().left()); + if let Ok(dir) = std::env::var("SOLIDCRAFT_HISTORY_EVIDENCE") { + std::fs::create_dir_all(&dir).unwrap(); + image + .unwrap() + .save(std::path::Path::new(&dir).join(format!( + "history-{}-{}-{}-{:?}.png", + if names { "names" } else { "icons" }, + if collapsed { "rail" } else { "browser" }, + if dark { "dark" } else { "light" }, + state + ))) + .unwrap(); + } + } + } + } + } + crate::theme::set_dark(previous); +} + /// Render actual egui geometry without a desktop window. Opt-in PNGs are reviewer evidence. #[test] fn menu_board_in_both_themes() { @@ -1186,20 +1325,20 @@ fn command_search_board_in_both_themes() { } /// Exercise the actual surface painters, including deliberately shared artwork whose -/// own accent differs from its tone or tab. +/// own accent differs from its tone, tab or feature kind. #[test] -fn confirm_radial_and_menu_danger_keep_multitone_artwork() { +fn confirm_radial_and_history_rows_keep_multitone_artwork() { let previous = crate::theme::is_dark(); for dark in [false, true] { crate::theme::set_dark(dark); let mut cases = vec![ - ("warning", "extrude", "MODEL", Some("construction"), 20), - ("danger", "extrude", "MODEL", Some("constraint"), 20), - ("info", "extrude", "MODEL", None, 20), - ("warning", "status_warning", "MODEL", Some("construction"), 20), - ("danger", "delete", "MODEL", Some("constraint"), 20), - ("danger_menu", "delete", "MODEL", Some("constraint"), 16), - ("info", "surface_extrude", "MODEL", None, 20), + ("warning", "extrude", "", "MODEL", Some("construction"), 20), + ("danger", "extrude", "", "MODEL", Some("constraint"), 20), + ("info", "extrude", "", "MODEL", None, 20), + ("warning", "status_warning", "", "MODEL", Some("construction"), 20), + ("danger", "delete", "", "MODEL", Some("constraint"), 20), + ("danger_menu", "delete", "", "MODEL", Some("constraint"), 16), + ("info", "surface_extrude", "", "MODEL", None, 20), ]; for (tab, ramp) in [ ("SKETCH", Some("sketch")), @@ -1212,11 +1351,26 @@ fn confirm_radial_and_menu_danger_keep_multitone_artwork() { ("unknown", None), ] { for surface in ["radial", "radial_hover"] { - cases.push((surface, "extrude", tab, ramp, 24)); + cases.push((surface, "extrude", "", tab, ramp, 24)); } } + for (kind, ramp) in [ + ("Sketch", Some("sketch")), + ("SurfaceExtrudeFeature", Some("surface")), + ("MeshFeature", Some("mesh")), + ("FormFeature", Some("form")), + ("ExtrudeFeature", None), + ] { + for (surface, side) in [("history_names", 15), ("history_icons", 19)] { + cases.push((surface, "extrude", kind, "MODEL", ramp, side)); + } + } + // Surface feature names without the Surface prefix use the same alias rule + // as the browser's timeline::icon_of assignments. + cases.push(("history_names", "surface_extrude", "ExtrudeFeature", "MODEL", Some("surface"), 15)); + cases.push(("history_names", "continuity", "MatchFeature", "MODEL", Some("surface"), 15)); let mut dominant_accents: std::collections::HashMap<&str, std::collections::HashSet> = std::collections::HashMap::new(); - for (surface, icon, tab, ramp, side) in cases { + for (surface, icon, kind, tab, ramp, side) in cases { let ctx = crate::fonts::test_context(); ctx.set_visuals(if dark { egui::Visuals::dark() } else { egui::Visuals::light() }); let mut app = crate::SolveApp::new(Default::default(), Default::default()); @@ -1239,6 +1393,26 @@ fn confirm_radial_and_menu_danger_keep_multitone_artwork() { item.danger = true; item.show(ui); } + "history_names" | "history_icons" => { + let style = if surface == "history_names" { HistoryStyle::Names } else { HistoryStyle::Icons }; + HistoryChip { + icon, + name: "Extrude1", + kind, + selected: false, + hovered: false, + dim: false, + suppressed: false, + error: false, + warning: false, + accent: crate::theme::TabAccent::for_tab(&Tokens::get(), "MODEL"), + } + .paint( + ui.painter(), + egui::Rect::from_min_size(egui::pos2(20.0, 20.0), vec2(158.0, style.height())), + style, + ); + } _ => { let tone = match surface { "warning" => Tone::Warning, @@ -1260,7 +1434,7 @@ fn confirm_radial_and_menu_danger_keep_multitone_artwork() { }) .expect("the surface must upload its icon texture"); let colours: std::collections::HashSet<_> = image.pixels.iter().filter(|pixel| pixel.a() == 255).copied().collect(); - assert!(colours.len() >= 2, "{surface}/{icon}/{tab}, dark={dark}: opaque artwork is a silhouette"); + assert!(colours.len() >= 2, "{surface}/{icon}/{kind}/{tab}, dark={dark}: opaque artwork is a silhouette"); let resolved = crate::icon_svg::resolve(icon); assert!(!resolved.placeholder, "{icon} needs a master"); let look = crate::icon_svg::Look { dark, accent: ramp.and_then(crate::icon_svg::accent_index), vision: crate::theme::vision() }; @@ -1282,7 +1456,7 @@ fn confirm_radial_and_menu_danger_keep_multitone_artwork() { assert_eq!( image.as_ref(), &egui::ColorImage::from_rgba_premultiplied([side, side], expected.data()), - "{surface}/{tab}: preserve roles with {ramp:?}" + "{surface}/{kind}/{tab}: preserve roles with {ramp:?}" ); if icon == "extrude" { let dominant = ["active-1", "active-2", "active-3"] @@ -1293,7 +1467,7 @@ fn confirm_radial_and_menu_danger_keep_multitone_artwork() { .into_iter() .max_by_key(|(count, _)| *count) .unwrap(); - assert!(dominant.0 > 0, "{surface}/{tab}: missing accent pixels"); + assert!(dominant.0 > 0, "{surface}/{kind}/{tab}: missing accent pixels"); let group = if matches!(surface, "warning" | "danger" | "info") { "confirm" } else { surface }; dominant_accents.entry(group).or_default().insert(dominant.1); } @@ -1302,11 +1476,13 @@ fn confirm_radial_and_menu_danger_keep_multitone_artwork() { super::checks::tests::textures_update(&mut textures, &output.textures_delta); let capture = super::checks::tests::raster(&ctx, output.shapes.clone(), output.pixels_per_point, bounds, &textures); std::fs::create_dir_all(&dir).unwrap(); - capture.save(std::path::Path::new(&dir).join(format!("{surface}-{icon}-{tab}-{}.png", if dark { "dark" } else { "light" }))).unwrap(); + capture + .save(std::path::Path::new(&dir).join(format!("{surface}-{icon}-{kind}-{tab}-{}.png", if dark { "dark" } else { "light" }))) + .unwrap(); } output.textures_delta.clear(); } - for (group, count) in [("confirm", 3), ("radial", 5), ("radial_hover", 5)] { + for (group, count) in [("confirm", 3), ("radial", 5), ("radial_hover", 5), ("history_names", 5), ("history_icons", 5)] { assert_eq!(dominant_accents[group].len(), count, "{group}, dark={dark}: dominant accent pixels must differ across mappings"); } } diff --git a/crates/ui-egui/src/ui_kit/history.rs b/crates/ui-egui/src/ui_kit/history.rs new file mode 100644 index 000000000..4272f89c0 --- /dev/null +++ b/crates/ui-egui/src/ui_kit/history.rs @@ -0,0 +1,687 @@ +//! Shared history chips, dense name rows, drop bars and rollback markers. +use crate::{ + icons, + theme::{TabAccent, Tokens}, +}; +use egui::{Painter, Rect, Stroke, pos2, vec2}; + +/// Browser and named history rows use the same density. +pub(crate) const TREE_ROW_HEIGHT: f32 = 26.0; + +#[derive(Clone, Copy, PartialEq)] +pub(crate) enum HistoryStyle { + Bottom, + Icons, + Names, +} + +impl HistoryStyle { + pub fn height(self) -> f32 { + let t = Tokens::get(); + match self { + Self::Bottom => t.control_height, + Self::Icons => t.control_height + t.space_10, + Self::Names => TREE_ROW_HEIGHT, + } + } +} + +pub(crate) struct HistoryChip<'a> { + pub icon: &'a str, + pub name: &'a str, + pub kind: &'a str, + pub selected: bool, + pub hovered: bool, + pub dim: bool, + pub suppressed: bool, + pub error: bool, + pub warning: bool, + pub accent: TabAccent, +} + +/// Share the feature classification across chips and name rows. Surface aliases also +/// cover Patch/Stitch/Thicken and other surface features without a Surface-prefixed kind. +fn feature_icon_accent(kind: &str, icon: &str) -> Option<&'static str> { + let tab = if kind.starts_with("Sketch") { + "SKETCH" + } else if kind.starts_with("Surface") || icon.starts_with("surface_") || icon == "continuity" { + "SURFACE" + } else if kind.starts_with("Mesh") { + "MESH" + } else if kind.starts_with("Form") { + "FORM" + } else { + "MODEL" + }; + crate::theme::icon_accent_for_tab(tab) +} + +impl HistoryChip<'_> { + /// All strip variants use this painter; no connections are drawn between features. + pub fn paint(&self, painter: &Painter, rect: Rect, style: HistoryStyle) { + let t = Tokens::get(); + let mut p = painter.clone(); + if self.dim || self.suppressed { + p.multiply_opacity(0.42); + } + let fill = if self.error { + t.form_error_fill + } else if self.selected { + self.accent.soft + } else if self.hovered { + t.hover + } else if style == HistoryStyle::Names { + egui::Color32::TRANSPARENT + } else { + t.timeline_item + }; + let edge = if self.error { + t.form_error + } else if self.selected || self.hovered { + self.accent.color + } else { + t.border + }; + let radius = if style == HistoryStyle::Icons { t.radius_lg } else { t.radius_sm }; + if style != HistoryStyle::Names || self.error { + let weight = if style == HistoryStyle::Icons && (self.selected || self.error) { 1.5 } else { 1.0 }; + p.rect(rect, radius, fill, Stroke::new(weight, edge), egui::StrokeKind::Inside); + } else { + p.rect_filled(rect, radius, fill); + } + let names = style == HistoryStyle::Names; + let side = if names { + t.space_14 + 1.0 + } else if style == HistoryStyle::Icons { + t.space_16 + t.space_3 + } else { + rect.height() - t.space_8 + }; + let icon = + Rect::from_center_size(if names { pos2(rect.left() + t.space_8 + side / 2.0, rect.center().y) } else { rect.center() }, vec2(side, side)); + icons::paint_accented(&p, icon, self.icon, feature_icon_accent(self.kind, self.icon), 1.0); + if names { + let ink = if self.selected { self.accent.ink } else { t.text }; + let font = if self.selected { crate::fonts::semibold(t.font_body) } else { egui::FontId::proportional(t.font_body) }; + let text_rect = Rect::from_min_max( + pos2(icon.right() + t.space_6 + 1.0, rect.top()), + pos2(rect.right() - if self.error || self.warning { t.space_16 } else { t.space_8 }, rect.bottom()), + ); + let galley = p.layout_no_wrap(self.name.to_owned(), font, ink); + p.with_clip_rect(text_rect.intersect(p.clip_rect())).galley(pos2(text_rect.left(), rect.center().y - galley.size().y / 2.0), galley, ink); + } + if self.suppressed { + p.line_segment([icon.left_bottom(), icon.right_top()], Stroke::new(1.5, t.text_dim)); + } + if self.error || self.warning { + let side = if names { t.space_12 } else { t.space_10 }; + let at = if names { pos2(rect.right() - t.space_3 - side, rect.center().y - side / 2.0) } else { rect.right_top() - vec2(side, 0.0) }; + icons::paint_icon(&p, Rect::from_min_size(at, vec2(side, side)), if self.error { "error" } else { "warning" }, 1.0); + } + } +} + +/// A single drop indicator in either strip orientation. +pub(crate) fn history_drop_bar(p: &Painter, rect: Rect, vertical: bool, colour: egui::Color32) { + let points = if vertical { + [pos2(rect.left(), rect.center().y), pos2(rect.right(), rect.center().y)] + } else { + [pos2(rect.center().x, rect.top()), pos2(rect.center().x, rect.bottom())] + }; + p.line_segment(points, Stroke::new(Tokens::get().space_2, colour)); +} + +/// Rollback line and hollow end circle; a vertical strip uses a horizontal line. +pub(crate) fn history_marker(p: &Painter, rect: Rect, vertical: bool, accent: TabAccent) { + let t = Tokens::get(); + let outer_radius = t.space_10 / 2.0; + let centre = if vertical { pos2(rect.right() - outer_radius, rect.center().y) } else { pos2(rect.center().x, rect.bottom() - outer_radius) }; + let direction = if vertical { vec2(1.0, 0.0) } else { vec2(0.0, 1.0) }; + let start = if vertical { rect.left_center() } else { rect.center_top() }; + // The line reaches one point inside the circle's outer edge, as on the reference board. + let end = centre - direction * (outer_radius - 1.0); + p.line_segment([start, end], Stroke::new(t.space_2, accent.color)); + // Circle strokes are centred on their radius: inset by half the stroke for a 10 pt outside diameter. + p.circle(centre, outer_radius - t.space_2 / 2.0, if vertical { t.panel } else { t.timeline }, Stroke::new(t.space_2, accent.color)); +} + +/// The same four rollback controls are used in every History orientation. +#[derive(Clone, Copy)] +pub(crate) enum HistoryTransport { + First, + Back, + Forward, + Last, +} + +impl HistoryTransport { + pub const ALL: [Self; 4] = [Self::First, Self::Back, Self::Forward, Self::Last]; + + pub fn id(self) -> &'static str { + match self { + Self::First => "first", + Self::Back => "back", + Self::Forward => "forward", + Self::Last => "last", + } + } + + fn label(self) -> &'static str { + crate::i18n::tr(match self { + Self::First => "ui.history_first", + Self::Back => "ui.history_back", + Self::Forward => "ui.history_forward", + Self::Last => "ui.history_last", + }) + } + + pub fn show(self, ui: &mut egui::Ui, rect: Rect) -> egui::Response { + let t = Tokens::get(); + let response = ui.interact(rect, ui.id().with(("history_transport", self.id())), egui::Sense::click()); + crate::scenario::publish_target(&format!("history:{}", self.id()), rect); + if response.hovered() { + ui.painter().rect_filled(rect, t.radius_sm, t.hover); + } + icons::glyphs::transport_glyph(ui.painter(), rect.center(), self.id(), t.icon); + response.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, ui.is_enabled(), self.label())); + response.on_hover_cursor(egui::CursorIcon::PointingHand).on_hover_text(self.label()) + } +} + +pub(crate) fn history_transport_width() -> f32 { + let t = Tokens::get(); + t.space_24 * HistoryTransport::ALL.len() as f32 + t.space_2 * (HistoryTransport::ALL.len() - 1) as f32 +} + +/// Thin and minimum named widths; wider named panels retain their measured width. +pub(crate) fn history_width(names: bool) -> f32 { + let t = Tokens::get(); + if names { history_transport_width() + t.space_10 * 2.0 + t.space_8 } else { t.control_height * 2.0 } +} + +pub(crate) fn history_clamp_width(width: f32) -> f32 { + if width.is_finite() { width.clamp(history_width(false), Tokens::get().space_24 * 26.0) } else { history_width(false) } +} + +/// Only the gap between thin and medium snaps. Every larger width is retained. +pub(crate) fn history_snap_width(width: f32) -> f32 { + let width = history_clamp_width(width); + if width < (history_width(false) + history_width(true)) / 2.0 { history_width(false) } else { width.max(history_width(true)) } +} + +/// The same six-dot grip is used by Assistant and History headers. +pub(crate) fn panel_grip(ui: &mut egui::Ui) -> egui::Response { + let t = Tokens::get(); + let (rect, response) = ui.allocate_exact_size(vec2(t.space_10, t.space_16 + t.space_2), egui::Sense::hover()); + for row in 0..3 { + for col in 0..2 { + ui.painter().circle_filled(rect.left_top() + vec2(2.5 + col as f32 * 5.0, 4.0 + row as f32 * 5.0), 1.1, t.text_dim); + } + } + response +} + +#[derive(Clone, Copy, Debug, PartialEq)] +pub(crate) enum HistoryHandleState { + Rest, + Hover, + Drag, +} + +/// Seam geometry is independent of the strip's contents and consumes no layout space. +pub(crate) struct HistorySeam { + pub grip: Rect, + pub pill: Rect, + pub edge: Rect, +} + +impl HistorySeam { + pub fn new(card: Rect) -> Self { + let t = Tokens::get(); + Self { + grip: Rect::from_center_size(pos2(card.right() - t.space_2 - t.space_3 / 2.0, card.center().y), vec2(t.space_3, TREE_ROW_HEIGHT)), + pill: Rect::from_center_size(card.right_center(), vec2(t.space_16 + t.space_2, t.control_height + t.space_16)), + edge: Rect::from_min_max(pos2(card.right() - t.space_10, card.top()), card.right_bottom()), + } + } + + pub fn paint(&self, p: &Painter, card: Rect, names: bool, state: HistoryHandleState) { + let t = Tokens::get(); + let accent = TabAccent::current(p.ctx()); + match state { + HistoryHandleState::Rest => { + p.rect_filled(self.grip, t.space_2, t.control_border); + } + HistoryHandleState::Hover => { + p.rect(self.pill, self.pill.width() / 2.0, accent.soft, Stroke::new(1.0, accent.color), egui::StrokeKind::Inside); + let c = self.pill.center(); + let dir = if names { -1.0 } else { 1.0 }; + p.add(egui::Shape::line( + vec![c + vec2(-dir * t.space_2, -t.space_4), c + vec2(dir * t.space_2, 0.0), c + vec2(-dir * t.space_2, t.space_4)], + Stroke::new(t.space_2, accent.color), + )); + } + HistoryHandleState::Drag => { + p.rect_stroke(card, t.radius_lg, Stroke::new(1.0, accent.color), egui::StrokeKind::Inside); + } + } + } +} + +pub(crate) struct HistorySeamResponse { + pub toggle: bool, + pub width: Option, + pub released: bool, + #[cfg(test)] + pub response: egui::Response, +} + +/// Focusable seam button and edge gesture, shared by the panel and CPU interaction tests. +pub(crate) fn history_seam(ui: &mut egui::Ui, card: Rect, names: bool) -> HistorySeamResponse { + let seam = HistorySeam::new(card); + let id = ui.id().with("history_seam"); + let edge = ui.interact(seam.edge, id.with("edge"), egui::Sense::CLICK | egui::Sense::DRAG); + let button = ui.interact(seam.pill, id, egui::Sense::click_and_drag()); + let label = crate::i18n::tr(if names { "ui.collapse" } else { "ui.expand" }); + button.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, ui.is_enabled(), label)); + if button.clicked() { + button.request_focus(); + } + let drag = if button.dragged() || button.drag_started() || button.drag_stopped() { &button } else { &edge }; + let start_id = id.with("start_width"); + if drag.drag_started() { + let press_x = ui.input(|i| i.pointer.press_origin()).map_or(card.right(), |p| p.x); + ui.data_mut(|d| d.insert_temp(start_id, (card.width(), press_x))); + } + let width = if drag.dragged() || drag.drag_stopped() { + let (start_width, press_x) = ui.data(|d| d.get_temp::<(f32, f32)>(start_id)).unwrap_or((card.width(), card.right())); + let pointer_x = ui.input(|i| i.pointer.latest_pos()).map_or(press_x, |p| p.x); + Some(history_clamp_width(start_width + pointer_x - press_x)) + } else { + None + }; + if drag.drag_stopped() { + ui.data_mut(|d| d.remove::<(f32, f32)>(start_id)); + } + let dragging = width.is_some(); + if dragging || edge.hovered() { + ui.ctx().set_cursor_icon(egui::CursorIcon::ResizeHorizontal); + } + if !dragging && button.hovered() { + ui.ctx().set_cursor_icon(egui::CursorIcon::PointingHand); + } + let hovered = edge.hovered() || button.hovered(); + let state = if dragging { + HistoryHandleState::Drag + } else if hovered { + HistoryHandleState::Hover + } else { + HistoryHandleState::Rest + }; + seam.paint(ui.painter(), card, names, state); + let response = button.clone().union(edge.clone()); + if hovered && !dragging { + let mut tip = egui::Tooltip::for_widget(&response); + let t = Tokens::get(); + let frame = egui::Frame::NONE + .fill(t.dialog_body) + .stroke(Stroke::new(1.0, t.dialog_border)) + .corner_radius(t.radius_md) + .inner_margin(egui::Margin::symmetric(t.space_8 as i8, t.space_4 as i8)) + .shadow(t.shell_shadow()); + tip.popup = tip.popup.anchor(seam.pill).align(egui::RectAlign::RIGHT_START).frame(frame); + tip.show(|ui| { + let t = Tokens::get(); + ui.label(egui::RichText::new(label).font(crate::fonts::semibold(t.font_body)).color(t.text)); + ui.label(egui::RichText::new(crate::i18n::tr("ui.history_edge_hint")).size(t.font_small).color(t.text_dim)); + }); + } + crate::scenario::publish_handle("history:names", seam.pill.center()); + crate::scenario::publish_rect("history:seam", seam.edge); + crate::scenario::publish_rect("history:handle", seam.pill); + // egui's click response includes Enter and Space for a focused button. + HistorySeamResponse { + toggle: button.clicked() || edge.double_clicked(), + width, + released: drag.drag_stopped(), + #[cfg(test)] + response, + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn seam_geometry_and_paint_states_follow_tokens_in_both_themes() { + let previous = crate::theme::is_dark(); + for dark in [false, true] { + crate::theme::set_dark(dark); + for names in [false, true] { + let card = Rect::from_min_size(pos2(20.0, 30.0), vec2(history_width(names), 280.0)); + let seam = HistorySeam::new(card); + assert_eq!(seam.grip.size(), vec2(3.0, 26.0)); + assert_eq!(seam.grip.center().y, card.center().y); + assert_eq!(seam.grip.right(), card.right() - 2.0); + assert_eq!(seam.pill.size(), vec2(18.0, 44.0)); + assert_eq!(seam.pill.center(), card.right_center()); + assert_eq!(seam.edge.width(), 10.0); + for state in [HistoryHandleState::Rest, HistoryHandleState::Hover, HistoryHandleState::Drag] { + let ctx = crate::fonts::test_context(); + let mut out = ctx.run_ui(egui::RawInput::default(), |ui| seam.paint(ui.painter(), card, names, state)); + out.textures_delta.clear(); + let t = Tokens::get(); + let accent = TabAccent::current(&ctx); + let rect = out + .shapes + .iter() + .find_map(|s| match &s.shape { + egui::Shape::Rect(r) => Some(r), + _ => None, + }) + .unwrap(); + match state { + HistoryHandleState::Rest => { + assert_eq!(rect.rect, seam.grip); + assert_eq!(rect.fill, t.control_border); + } + HistoryHandleState::Hover => { + assert_eq!(rect.rect, seam.pill); + assert_eq!(rect.fill, accent.soft); + assert_eq!(rect.stroke.color, accent.color); + } + HistoryHandleState::Drag => { + assert_eq!(rect.rect, card); + assert_eq!(rect.stroke.color, accent.color); + assert!(!out.shapes.iter().any(|s| matches!(&s.shape, egui::Shape::Text(_)))); + assert!(!out.shapes.iter().any(|s| matches!(s.shape, egui::Shape::LineSegment { .. }))); + } + } + } + } + } + crate::theme::set_dark(previous); + } + + struct SeamHarness { + ctx: egui::Context, + names: bool, + width: f32, + time: f64, + focused: bool, + } + + impl SeamHarness { + fn new(names: bool) -> Self { + let mut h = Self { ctx: crate::fonts::test_context(), names, width: history_width(names), time: 0.0, focused: false }; + h.frame(vec![]); + h.frame(vec![]); + h + } + + fn card(&self) -> Rect { + Rect::from_min_size(pos2(20.0, 20.0), vec2(self.width, 280.0)) + } + + fn frame(&mut self, events: Vec) -> egui::FullOutput { + self.time += 0.05; + let card = self.card(); + let mut out = self.ctx.run_ui( + egui::RawInput { + screen_rect: Some(Rect::from_min_size(egui::Pos2::ZERO, vec2(400.0, 400.0))), + time: Some(self.time), + focused: true, + events, + ..Default::default() + }, + |ui| { + let result = history_seam(ui, card, self.names); + self.focused = result.response.has_focus(); + if let Some(width) = result.width { + self.width = width; + if result.released { + self.names = history_snap_width(width) >= history_width(true); + self.width = history_snap_width(width); + } + } else if result.toggle { + self.names = !self.names; + self.width = history_width(self.names); + } + }, + ); + out.textures_delta.clear(); + out + } + } + + #[test] + fn seam_edge_cursor_pill_click_double_click_and_keyboard_toggle() { + use crate::test_support::{key, pointer}; + let mut h = SeamHarness::new(false); + let edge = pos2(h.card().right() - 4.0, h.card().top() + 30.0); + assert_eq!(h.frame(vec![egui::Event::PointerMoved(edge)]).platform_output.cursor_icon, egui::CursorIcon::ResizeHorizontal); + let pill = h.card().right_center(); + assert_eq!(h.frame(vec![egui::Event::PointerMoved(pill)]).platform_output.cursor_icon, egui::CursorIcon::PointingHand); + h.frame(pointer(pill, true)); + h.frame(pointer(pill, false)); + assert!(h.names); + let mut h = SeamHarness::new(false); + for _ in 0..2 { + h.frame(pointer(edge, true)); + h.frame(pointer(edge, false)); + } + assert!(h.names, "double-click toggles once"); + let mut h = SeamHarness::new(false); + h.ctx.enable_accesskit(); + let focus = h.frame(key(egui::Key::Tab)); + assert!( + focus + .platform_output + .events + .iter() + .any(|e| matches!(e, egui::output::OutputEvent::FocusGained(info) if info.label.as_deref() == Some("Expand"))) + ); + h.frame(vec![]); + assert!(h.focused, "Tab reaches the seam button"); + h.frame(key(egui::Key::Enter)); + assert!(h.names); + h.frame(key(egui::Key::Space)); + assert!(!h.names); + } + + #[test] + fn seam_drag_resizes_continuously_and_snaps_both_directions() { + use crate::test_support::pointer; + for (names, delta, expected) in [(false, 40.0, true), (false, 20.0, false), (true, -40.0, false), (true, -20.0, true)] { + for pill in [false, true] { + let mut h = SeamHarness::new(names); + let start = if pill { h.card().right_center() } else { pos2(h.card().right() - 4.0, h.card().top() + 30.0) }; + let end = start + vec2(delta, 0.0); + h.frame(pointer(start, true)); + h.frame(vec![egui::Event::PointerMoved(start + vec2(delta / 2.0, 0.0))]); + h.frame(vec![egui::Event::PointerMoved(end)]); + assert_eq!(h.width, history_width(names) + delta, "continuous width before release"); + h.frame(pointer(end, false)); + assert_eq!(h.names, expected); + assert_eq!(h.width, history_snap_width(history_width(names) + delta)); + } + } + for hostile in [f32::NAN, f32::INFINITY, f32::NEG_INFINITY, -1000.0, 10000.0] { + assert!((history_width(false)..=Tokens::get().space_24 * 26.0).contains(&history_clamp_width(hostile))); + } + } + + #[test] + fn chip_selection_error_and_rollback_use_tokens_in_both_themes() { + let previous = crate::theme::is_dark(); + for dark in [false, true] { + crate::theme::set_dark(dark); + let t = Tokens::get(); + let accent = TabAccent::for_tab(&t, "SURFACE"); + for style in [HistoryStyle::Icons, HistoryStyle::Names] { + for (selected, error, dim) in [(true, false, false), (false, true, false), (true, false, true)] { + let rect = Rect::from_min_size(pos2(20.0, 20.0), vec2(158.0, style.height())); + let ctx = crate::fonts::test_context(); + let mut out = ctx.run_ui(egui::RawInput::default(), |ui| { + HistoryChip { + icon: "surface_extrude", + name: "Offset1", + kind: "SurfaceOffsetFeature", + selected, + hovered: false, + dim, + suppressed: false, + error, + warning: false, + accent, + } + .paint(ui.painter(), rect, style) + }); + out.textures_delta.clear(); + let background = out + .shapes + .iter() + .find_map(|s| match &s.shape { + egui::Shape::Rect(r) if r.rect == rect => Some(r), + _ => None, + }) + .unwrap(); + let opacity = if dim { 0.42 } else { 1.0 }; + assert_eq!(background.fill, if error { t.form_error_fill } else { accent.soft }.gamma_multiply(opacity)); + if style == HistoryStyle::Icons || error { + assert_eq!(background.stroke.color, if error { t.form_error } else { accent.color }.gamma_multiply(opacity)); + } + if style == HistoryStyle::Names { + let text = out + .shapes + .iter() + .find_map(|s| match &s.shape { + egui::Shape::Text(t) => Some(t), + _ => None, + }) + .unwrap(); + assert_eq!(text.galley.text(), "Offset1"); + assert_eq!(text.fallback_color, if selected { accent.ink } else { t.text }.gamma_multiply(opacity)); + } + } + } + } + crate::theme::set_dark(previous); + } + + #[test] + fn chips_have_no_connector_shapes_in_either_theme_or_width() { + let previous = crate::theme::is_dark(); + for dark in [false, true] { + crate::theme::set_dark(dark); + let t = Tokens::get(); + for style in [HistoryStyle::Bottom, HistoryStyle::Icons, HistoryStyle::Names] { + let ctx = crate::fonts::test_context(); + let mut out = ctx.run_ui(egui::RawInput::default(), |ui| { + for index in 0..3 { + let rect = Rect::from_min_size( + pos2(20.0, 20.0 + index as f32 * (style.height() + t.space_4)), + vec2(if style == HistoryStyle::Names { 158.0 } else { style.height() }, style.height()), + ); + HistoryChip { + icon: "box", + name: "Box", + kind: "BoxFeature", + selected: index == 0, + hovered: false, + dim: index == 2, + suppressed: false, + error: false, + warning: false, + accent: TabAccent::for_tab(&t, "MODEL"), + } + .paint(ui.painter(), rect, style); + } + }); + out.textures_delta.clear(); + let mut connections = 0; + for clipped in out.shapes { + crate::test_support::each_shape(&clipped.shape, &mut |shape| { + if matches!(shape, egui::Shape::LineSegment { .. } | egui::Shape::Path(_)) { + connections += 1; + } + }); + } + assert_eq!(connections, 0, "dark={dark}"); + } + } + crate::theme::set_dark(previous); + } + + #[test] + fn both_strip_orientations_share_the_drop_bar_and_marker_geometry() { + let t = Tokens::get(); + let accent = TabAccent::for_tab(&t, "SURFACE"); + for vertical in [false, true] { + let rect = Rect::from_min_size(pos2(20.0, 20.0), if vertical { vec2(160.0, 12.0) } else { vec2(12.0, 28.0) }); + let ctx = crate::fonts::test_context(); + let mut out = ctx.run_ui(egui::RawInput::default(), |ui| history_drop_bar(ui.painter(), rect, vertical, accent.color)); + out.textures_delta.clear(); + let lines: Vec<_> = out + .shapes + .iter() + .filter_map(|s| if let egui::Shape::LineSegment { points, stroke } = s.shape { Some((points, stroke)) } else { None }) + .collect(); + assert_eq!(lines.len(), 1); + assert_eq!(lines[0].1, Stroke::new(t.space_2, accent.color)); + assert_eq!(lines[0].0, if vertical { [rect.left_center(), rect.right_center()] } else { [rect.center_top(), rect.center_bottom()] }); + } + let previous = crate::theme::is_dark(); + for dark in [false, true] { + crate::theme::set_dark(dark); + let t = Tokens::get(); + let accent = TabAccent::for_tab(&t, "SURFACE"); + // Both vertical widths retain the 12 pt marker row; the bottom strip rotates it. + for (vertical, size) in [(true, vec2(46.0, 12.0)), (true, vec2(158.0, 12.0)), (false, vec2(12.0, 28.0))] { + let rect = Rect::from_min_size(pos2(20.0, 20.0), size); + let ctx = crate::fonts::test_context(); + let mut out = ctx.run_ui(egui::RawInput::default(), |ui| history_marker(ui.painter(), rect, vertical, accent)); + out.textures_delta.clear(); + let lines: Vec<_> = out + .shapes + .iter() + .filter_map(|s| match s.shape { + egui::Shape::LineSegment { points, stroke } => Some((points, stroke)), + _ => None, + }) + .collect(); + assert_eq!(lines.len(), 1); + assert_eq!(lines[0].1, Stroke::new(2.0, accent.color)); + let circles: Vec<_> = out + .shapes + .iter() + .filter_map(|s| match &s.shape { + egui::Shape::Circle(c) => Some(c), + _ => None, + }) + .collect(); + assert_eq!(circles.len(), 1); + let circle = circles[0]; + assert_eq!(circle.stroke, Stroke::new(2.0, accent.color)); + assert_eq!(circle.fill, if vertical { t.panel } else { t.timeline }); + assert_ne!(circle.fill, accent.color); + let outer = circle.radius + circle.stroke.width / 2.0; + assert_eq!(outer * 2.0, 10.0); + let bounds = Rect::from_center_size(circle.center, vec2(outer * 2.0, outer * 2.0)); + assert!(rect.contains_rect(bounds)); + assert_eq!(lines[0].0[0], if vertical { rect.left_center() } else { rect.center_top() }); + if vertical { + assert_eq!(rect.height(), 12.0); + assert_eq!(bounds.right(), rect.right()); + assert_eq!(lines[0].0[1], pos2(bounds.left() + 1.0, circle.center.y)); + } else { + assert_eq!(bounds.bottom(), rect.bottom()); + assert_eq!(lines[0].0[1], pos2(circle.center.x, bounds.top() + 1.0)); + } + assert!(!out.shapes.iter().any(|s| matches!(s.shape, egui::Shape::Path(_))), "no arrowheads"); + } + } + crate::theme::set_dark(previous); + } +} diff --git a/crates/ui-egui/src/ui_kit/mod.rs b/crates/ui-egui/src/ui_kit/mod.rs index 16efb3126..0c5bb13a9 100644 --- a/crates/ui-egui/src/ui_kit/mod.rs +++ b/crates/ui-egui/src/ui_kit/mod.rs @@ -8,6 +8,7 @@ mod color; mod confirm; mod disclosure; mod fields; +mod history; mod layout; mod menu; mod metrics; @@ -26,10 +27,11 @@ pub(crate) use color::*; pub(crate) use confirm::{Confirm, Tone}; pub(crate) use disclosure::*; pub(crate) use fields::*; +pub(crate) use history::*; pub(crate) use layout::*; pub(crate) use menu::{Menu, MenuItem, rename_menu, workspace_menu}; pub(crate) use metrics::{ContentWidth, header_height, row_height, table_row_height}; -pub(crate) use panel::{ComputeStatus, FeatureOptions, Panel, Part, Window, WindowPage}; +pub(crate) use panel::{ComputeStatus, FeatureOptions, Panel, Part, Window, WindowPage, panel_header_hover}; #[cfg(test)] pub(crate) use panel::{collapsible_header, header}; pub(crate) use radial::{RADIAL_RADIUS, radial_menu}; diff --git a/crates/ui-egui/src/ui_kit/panel.rs b/crates/ui-egui/src/ui_kit/panel.rs index 66221d944..6bc0de46b 100644 --- a/crates/ui-egui/src/ui_kit/panel.rs +++ b/crates/ui-egui/src/ui_kit/panel.rs @@ -3,6 +3,12 @@ use super::{actions::icon_button_at, metrics::*, text::paint_text}; use crate::{scenario, theme::Tokens}; use egui::{Ui, vec2}; +/// Shared active-tab hover tint for the browser and collapsible panel chrome. +pub(crate) fn panel_header_hover(painter: &egui::Painter, rect: egui::Rect) { + let t = Tokens::get(); + painter.rect_filled(rect, t.radius_lg.saturating_sub(t.space_4 as u8), crate::theme::TabAccent::current(painter.ctx()).soft); +} + /// Feature title/icon/close band. Tokens: `form_header_height, form_icon_size, form_close_size, form_inset, font_label, text, dialog_rule, space_8/10; icon_button_at tokens`. pub(crate) fn header(ui: &mut Ui, icon: &str, title: &str, on_close: impl FnOnce()) { header_impl(ui, icon, title, None, on_close); diff --git a/crates/ui-egui/tests/icon_audit.rs b/crates/ui-egui/tests/icon_audit.rs index 79359e409..c642a4a8e 100644 --- a/crates/ui-egui/tests/icon_audit.rs +++ b/crates/ui-egui/tests/icon_audit.rs @@ -210,6 +210,10 @@ fn requested_menu_icons_have_artwork_and_match_manifest() { history.frames(3); context_rows(&mut history, "timeline:", &mut requested); } + // The seam has its own checked display menu, independent of feature and folder rows. + history.step(&json!({"click":{"handle":"history:names"},"button":"right"})).unwrap(); + collect(&mut history, "history seam", &mut requested); + escape(&mut history); let features = history.app.session.doc.features.iter().take(2).map(|f| f.id).collect::>(); let group = history.app.run("timeline.group", json!({"features":features,"name":"Audit history folder"})).unwrap()["group"].as_u64().unwrap(); history.frames(3); @@ -217,13 +221,13 @@ fn requested_menu_icons_have_artwork_and_match_manifest() { history.app.tree.picked_timeline_groups.clear(); history.app.run("select.set", json!({"items":features.iter().map(|id| json!({"type":"feature","id":id})).collect::>()})).unwrap(); history.frames(3); - history.step(&json!({"widget":"2 selected"})).unwrap(); + history.step(&json!({"click":{"handle":"timeline:History A"},"button":"right"})).unwrap(); collect(&mut history, "history feature selection", &mut requested); escape(&mut history); history.app.run("select.clear", json!({})).unwrap(); history.app.tree.picked_timeline_groups = vec![group]; history.frames(3); - history.step(&json!({"widget":"1 selected"})).unwrap(); + history.step(&json!({"click":{"handle":"timeline-folder:Audit history folder"},"button":"right"})).unwrap(); collect(&mut history, "history folder selection", &mut requested); escape(&mut history); history.app.tree.picked_timeline_groups.clear(); diff --git a/docs/book/src/guide/ui-tour.md b/docs/book/src/guide/ui-tour.md index f3e270834..ea62b84e5 100644 --- a/docs/book/src/guide/ui-tour.md +++ b/docs/book/src/guide/ui-tour.md @@ -66,7 +66,10 @@ - **Dialogs** dock on the right with a live preview. Most features also show drag handles and a value box in the viewport. - **Timeline** (bottom). Every feature in order. Double-click to edit, drag the marker to roll - back, and drag features to reorder them. + back, and drag features to reorder them. Preferences can put the timeline vertically at the + far left of the viewport, beside the browser. Its seam handle switches between icon + chips and compact feature names; the browser can collapse to a rail beside either width. + Previous, Play and Next sit at the top. Double-click Previous to roll to the start. - **Command search (S).** Click the ribbon search field or press S to open the search popup below it. Results group commands by their ribbon path and show matching features and user parameters from this design. With an empty query, recent commands appear first, followed by diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 48d56c985..50609e6d7 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -209,6 +209,7 @@ labels; `prefs:measure_axis_distances` identifies the checkbox. | `ui.capture` | `action?`: `capture`, `revert`, `cancel` | answers the Capture Position question (asked when a command starts or the design is saved while components were moved without capturing); without `action`, what waits | | `ui.window` | `action`: minimize, maximize, restore, toggle, close | what the title bar's caption buttons do (on Windows and Linux the application bar is the title bar); close asks about unsaved designs first | | `ui.agent_cursor` | `show` (bool), `speed`: a number from 1 to 5 (times the normal speed) or `"instant"` (no animation: the command runs at once and the pointer jumps to where it acted), `follow_camera` (bool); all optional | the settings. While the cursor is shown, `engine.execute` first glides to the command's toolbar button and to each pick, then runs and replies; later requests wait their turn. `"animate": false` on a call skips it | +| `engine.execute` → `view.history_layout` | `width?`, `dock?`: `bottom`, `left`, `under_browser`, `collapsed?` | Resize/dock the history without opening a dialog or changing the design. Contents respond to measured width; browser-stacked history shares its width and splits height equally. One folded header gives the expanded card the rest; two folded headers stay at the top. | | `ui.agent_chat` | `features?`, `toolbar_button?`, `permissions?` (`ask`, `edits`, `all`), `add_agent?` ({`name`, `kind`: `acp` or `api`, `command` or `base_url` + `model`}; no keys), `default_agent?`, `agent?` (the conversation's agent, by id), `mode?` (the agent's own mode), `model?` (one of its models), `open?`, `side?` (`left`, `right`), `minimized?`, `popped?` (in its own window), `width?`, `picker?`, `refresh?`, `connect?`, `stop?`, `attach?`: a file's path (a picture, a text file or a CAD file, for the next message; CAD files are imported at once), `remove_file?` (index of a file on the next message), `send?`: text (files alone make a message too), `attach_view?`, `permission?`: an option id or `"cancel"` (the newest question of the agent's own), `approve?`: true, false or `"always"` (the oldest request held for Allow/Deny), `cancel?` (Stop: the queue stays), `send_now?` (stop the running step, then send the queued messages), `remove_pending?` (index), `new_chat?` (clear the chat, new session), `undo?` (the last message's changes) | the chat's state: `features`, `agents` (found and added), `currentAgent`, `state` (off, starting, ready, busy, auth, exited), `popped`, `window` (its place and size), `agent`, `modes`, `mode`, `models`, `model`, `authMethods`, `toolsPort`, `pid`, `waiting`, `turn`, `pending` (queued messages, with their `files`), `attachments` (the files on the next message, by name), `loading` (pictures still being read for it, by name), `stopped`, `detection` and the conversation (`items`). With `features` off only the settings apply. Desktop only; see [Agent chat](agent-chat.md) | | `ui.resize` | `width`, `height` | | | `app.quit` | `force?` (quit without asking about unsaved designs) | `quitting` (the window closes), `asking` (a "save changes?" prompt is open) | diff --git a/docs/ui-kit.md b/docs/ui-kit.md index a90f6fb13..241fa580e 100644 --- a/docs/ui-kit.md +++ b/docs/ui-kit.md @@ -57,6 +57,7 @@ table. Panel/Window/Confirm compositions also have dedicated geometry and intera | Module / element | Use and options | Main tokens | | --- | --- | --- | +| history: `HistoryChip`, `HistoryStyle`, `history_drop_bar`, `history_marker`, `HistorySeam`, `history_seam` | One painter family for bottom chips, 38 pt vertical icon chips and single-line 26 pt name rows (the browser's shared `TREE_ROW_HEIGHT`). Selected items use the active tab tint/ink/border; all variants retain multi-tone feature artwork using one shared kind-to-accent rule (Sketch green, Surface orange, Mesh yellow, Form purple, solids base blue); rolled-back items have 42% opacity. Error/warning badges, suppression strikes, horizontal/vertical drop bars and rollback line/hollow circle are shared. No connector lines. | `control_height`, `space_2/3/4/6/8/10/12/14/16/24`, radii, typography, `TabAccent`, `timeline_item`, `control_border`, `text/dim`, `form_error/fill` | | search: `CommandSearch`, `MenuItem::search_row` | Ribbon search composition: one persistent ribbon editor expands from 28 to 40 pt and to 520 pt wide with its right edge anchored, magnifier and S/Esc keycap, 38 pt two-line menu row with 26 pt icon tile, accent bold substring, path, shortcut/kind keycap, counts, JSON detail box and footer. The ordinary 30 pt menu row cannot fit a second line; this variant keeps its enabled/selected states and scenario IDs. Ranking and dispatch stay with the caller. | `form_card_width × 2 − space_8` (520 pt), `control_height`, `space_2/3/4/6/8/10/12/14/16/24`, `radius_xl/control_radius`, `control_fill`, `dialog_body/footer/rule/border`, `form_ink/dim/primary/error/error_fill/success/success_fill`, `selected_ink`, `accent_soft`, typography | | menu: `Menu`, `MenuItem` | Shared popup, 30 pt rows, 28 pt icon column, clipped labels, right-aligned mono shortcuts, submenu chevrons, checked/unchecked and document swatches, inert 40% disabled rows and danger ink; headings and separators; ribbon drag/pin targets retained | `dialog_body/border/rule`, `radius_xl`, `control_height/radius`, `form_ink/dim/primary/error`, `accent_soft`, typography and spacing | | radial: `radial_menu` | Eight rounded annular sectors, parallel 4 pt gaps, 9 pt circular corner joins, tab-accent artwork and hover, centre label/key; existing hold/flick/release dispatch | `dialog_body/border`, `form_ink/dim`, `TabAccent`, icon palette, font/spacing tokens | @@ -108,6 +109,38 @@ table. Panel/Window/Confirm compositions also have dedicated geometry and intera | status: `status_header`, `StatusHeader` | Supplied icon/name/status and constraint meter | `font_label`, `text/dim`, `accent`, sketch/header tokens | | `progress` | Clamped determinate progress | `space_3/6`, `dialog_rule`, `accent` | +History contents are selected from measured panel width. A 56 pt thin strip shows icons +and four vertical transport controls: beginning, back, forward and end. The minimum named +width is 130 pt; it adds horizontal transport and the same six-dot window grip as Assistant. +When the remaining header space fits its measured text, **History** appears between grip +and transport. No names-mode flag +or command selects these layouts. The seam snaps between 56 and 130 pt; widths from 130 +through 624 pt remain continuous and persist as `timeline_left_width`. + +Drag the grip or title to dock along the bottom, at the full-height left edge, or beneath +the browser. Either card's right edge resizes their shared width. This position divides +available column height equally. Folding either card leaves its header visible and gives the remainder to +the other. If both are folded, their headers sit together at the top of the column. +Expansion and collapse share a smooth cubic transition capped at 120 ms, respecting +the interface’s instant-animation setting. Their collapse controls share the same active-tab blue hover tint. Browser resizing also resizes History. +The `view.history_layout` command validates width, docking and collapse requests without +altering the design or opening dialogs. Floating mode preserves viewport projection. + +The seam handle overlays the strip's right edge without taking layout space. Its grip is +visible at rest; the arrow appears only on hover. Click, double-click the edge, or use +Enter/Space on the focused handle to resize between thin and minimum named widths. Drag +freely above the named minimum; resizing draws no dotted guide or name label. Header/title dragging +and the edge width gesture are separate from feature/folder and rollback dragging. +The rollback marker is 12 pt high. +Its 2 pt line uses the active tab fill and ends in a 10 pt hollow circle with a 2 pt accent +border and the card/panel surface inside. The circle overlaps the line end by 1 pt. The bottom +strip uses the same painter, rotated. Folder selection, range selection, context menus, +sketch-pattern children, drag reordering and command JSON retain their existing behavior and handles. +`history_icons`, `history_names`, `history_marker` and the `history_seam_rest/hover/drag` states +have light/dark gallery references. The CPU +board test captures both strip widths with expanded and collapsed browsers +(`SOLIDCRAFT_HISTORY_EVIDENCE`). + `text(ui, text, options)` supports the existing text behaviors and the new error band: | Option | Layout and scenario publication |