forked from 1b-agent/fieldcraft-upstream
Craft-family shell, native file dialogs, samples and one-click Solve (#46)
* Native file pickers, background opening, drag and drop and recent files Open (models, SolidCraft designs and tagged meshes in one picker), Save, Save As, Write Deck and Recover go through the host's file pickers (rfd in the desktop app, injected as Services so the UI crate stays portable and tests answer them). Files open on a copy of the session in a worker thread and replace it only on success; files dropped on the window or named on the command line open the same way. A recent-files list, an unsaved-changes prompt, Cmd/Ctrl+O/S/Shift+S. Programmatic calls never open a picker: ui.start opens the form. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NmAttHhUZTokgPeEJia8sm * Samples and one-click Solve: results reachable from the window file.sample {name} opens a ready-to-run sample (the two parts, the cantilever with static and frequency steps, the bar impact) in place of the model; solve.run solves every step in order. Help > Samples, the empty viewport's start screen and the Tools > Samples entry open them (asking first over unsaved changes); Solve runs in the background like a file opening and the Results tab comes up. --sample [parts|cantilever|impact] on the command line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NmAttHhUZTokgPeEJia8sm * The Craft-family shell: title bar, workspace ribbon, browser, context panel, timeline The window now follows SolidCraft's and VectorCraft's layout and themes: - title bar with the mark, quick actions (File menu, save, undo, redo, Solve, search, theme, help), the model's document tab and the version; integrated under the macOS traffic lights, own caption buttons and resize zones elsewhere (titlebar.rs); - workspaces (Prepare, Model, Analysis, Results) with their tabs, and panels of icon buttons whose labelled drop-downs list the whole catalogue, coming-soon entries greyed with their milestone; panels collapse, then go into a » menu, when narrow; - the browser: geometry and mesh with eye toggles, definitions with counts, results; - no permanent Commands list: command search (S, Cmd/Ctrl+K) and a command line; - the context panel on the right only with context: the command form, results controls, the selected definition's properties with Edit and Delete; - navigation bar and orientation gizmo in the viewport; the journal timeline at the bottom with undo positions; - SolidCraft's light and dark tokens; craft-ui (IconButton, Tab, WidgetPalette). Menus and the search are view state (ui.set {menu, palette}), so captures show them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NmAttHhUZTokgPeEJia8sm * Shell polish, docs and licences Menus painted as the family's (flat File menu with recent files, decks and samples), the legend sized to its text, two-line panel labels inside the ribbon, glyphs the UI font has, offscreen captures without fade-in, ui.start runs in-window file actions (samples, recover, solve) but never a native picker, ui.select. Control protocol, architecture, ROADMAP, AGENTS and ATTRIBUTION updated; THIRD-PARTY-LICENSES.txt with craft-ui and rfd. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NmAttHhUZTokgPeEJia8sm * Title bar mark from the application icon; fluid steps and domains in the shell The title bar draws the app icon's bracket (assets/app-icon/icon-small.svg's faces) as SolidCraft draws its mark; the window keeps its title-bar flags after the rebase. solve.run solves fluid steps too (solve.fluid); the browser lists fluid domains. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NmAttHhUZTokgPeEJia8sm * Simplify: cached per-frame data, one command per timeline roll, workspace setters - Icon textures are kept per pixel size (the shell draws several sizes a frame; the cache used to clear on every size change and rasterise again). - Opening a model or recovering one starts from an empty session instead of copying the current one; the replaced session is freed off the window thread. - Element counts, timeline items, search results and the selected definition's properties are cached until what they show changes; timeline tooltips are built on hover; long lists in properties are summarised. - edit.undo and edit.redo take a count: a timeline click is one command. - solve.run dispatches on the step's procedure (no string round trip) and reports its name. - The workspace and tab change together through UiState::select_tab/select_workspace (ui.set {workspace} alone now sticks); no per-frame syncing. - One busy guard, Kind::verbs, a fit flag for background jobs, ModelApp::home_view, the title bar's actions as an enum, dead code removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NmAttHhUZTokgPeEJia8sm * Title bar: Solve and tools at the right end; no traffic-light inset in full screen The owner's feedback on the title bar: Solve, search, theme and help sit at its right end before the version; on macOS the left group (mark, name, quick actions) moves into the traffic lights' room in full screen, where there are none, and back when leaving it. The layout is a pure function (bar_layout) tested for both states, narrow windows and custom caption buttons. ui.fullscreen {on} for agents. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NmAttHhUZTokgPeEJia8sm * Caps labels in Inter SemiBold egui has no bold weight of its default font, so the ribbon's tabs and panel labels, the workspace switcher and its menu, menu headings, the browser header, the context panel's headers and the Solve label were thin, especially in the light theme. They now use a label font family: Inter SemiBold 4.1 (SIL OFL 1.1, unmodified, fonts/OFL.txt, ATTRIBUTION.md), with egui's fonts as fallback, installed with the theme on the live and offscreen contexts. theme::label_font falls back to the default font until the family is bound (fonts take effect from the next pass), so nothing can panic. Panels widen to their label's longest word. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NmAttHhUZTokgPeEJia8sm * docs: regenerate features.md after rebase Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NmAttHhUZTokgPeEJia8sm --------- Co-authored-by: jyviko <2501648+jyviko@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
87 files changed
+5068
-759
No files matched your search
+331
-38
@@ -1,25 +1,43 @@
|
||||
//! The ModelCraft egui front end.
|
||||
//!
|
||||
//! A thin shell over [`modelcraft_engine::Session`]: panels read engine state and act through
|
||||
//! commands ([`ModelApp::run`]); nothing here owns model data. The window has a menu bar, the
|
||||
//! model tree on the left, the 3D viewport in the middle, the commands (generated from the
|
||||
//! engine's registry) on the right and a status bar at the bottom. The control channel's
|
||||
//! requests are handled here ([`control`]); the desktop app owns the socket.
|
||||
//! commands ([`ModelApp::run`]); nothing here owns model data. The window follows the Craft
|
||||
//! family's layout (SolidCraft, VectorCraft):
|
||||
//!
|
||||
//! Structure and conventions follow SolidCraft's `crates/ui-egui` (MIT OR Apache-2.0), see
|
||||
//! ATTRIBUTION.md.
|
||||
//! - the title bar ([`appbar`]): the app, quick actions (File menu, save, undo, redo, Solve,
|
||||
//! search, theme, help) and the model's document tab;
|
||||
//! - the ribbon ([`toolbar`]): the workspace switcher, its tabs, and panels of icon buttons whose
|
||||
//! labelled drop-downs list the whole catalogue (coming-soon entries greyed with their
|
||||
//! milestone);
|
||||
//! - the browser on the left ([`browser`]): the model's geometry, mesh and definitions;
|
||||
//! - the viewport ([`viewport`]) with its navigation bar and orientation gizmo;
|
||||
//! - the context panel on the right ([`context`]), only while there is context: the open command
|
||||
//! form, the results controls, the selected definition's properties;
|
||||
//! - the command line and status ([`palette`]), and the journal timeline at the bottom
|
||||
//! ([`timeline`]). Every command is also one search away (S or Cmd/Ctrl+K).
|
||||
//!
|
||||
//! The control channel's requests are handled here ([`control`]); the desktop app owns the
|
||||
//! socket. Structure and conventions follow SolidCraft's `crates/ui-egui` (MIT OR Apache-2.0),
|
||||
//! see ATTRIBUTION.md.
|
||||
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
|
||||
#![forbid(unsafe_code)]
|
||||
|
||||
pub mod appbar;
|
||||
pub mod browser;
|
||||
pub mod capture;
|
||||
pub mod context;
|
||||
pub mod control;
|
||||
pub mod files;
|
||||
pub mod frame;
|
||||
pub mod gpu;
|
||||
pub mod icons;
|
||||
pub mod panels;
|
||||
pub mod palette;
|
||||
pub mod results;
|
||||
pub mod results_panel;
|
||||
pub mod scene;
|
||||
pub mod theme;
|
||||
pub mod timeline;
|
||||
pub mod titlebar;
|
||||
pub mod toolbar;
|
||||
pub mod viewport;
|
||||
|
||||
@@ -28,29 +46,43 @@ use std::sync::Arc;
|
||||
use std::sync::mpsc::{Receiver, Sender};
|
||||
|
||||
use modelcraft_engine::Session;
|
||||
use modelcraft_engine::catalogue::{self, Tab};
|
||||
use modelcraft_engine::catalogue::{self, Tab, Workspace};
|
||||
use modelcraft_render::{Aabb3, Camera, DisplayMesh, Scene, StandardView};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
pub use control::ControlRequest;
|
||||
pub use files::{Filter, Services};
|
||||
pub use scene::Style;
|
||||
|
||||
/// The version shown in Help and over the control channel.
|
||||
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
/// View settings: what is shown and how. `ui.set` changes any of them by name.
|
||||
/// View settings: what is shown and how, and which menu or search is open. `ui.set` changes any
|
||||
/// of them by name.
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct UiState {
|
||||
pub style: Style,
|
||||
pub show_nodes: bool,
|
||||
/// The open design and imported surfaces.
|
||||
pub show_geometry: bool,
|
||||
/// Elements.
|
||||
pub show_mesh: bool,
|
||||
pub perspective: bool,
|
||||
pub dark: bool,
|
||||
/// The browser (left).
|
||||
pub show_tree: bool,
|
||||
pub show_commands: bool,
|
||||
/// The toolbar tab shown.
|
||||
/// The journal timeline (bottom).
|
||||
pub show_timeline: bool,
|
||||
/// The workspace shown, and its toolbar tab.
|
||||
pub workspace: Workspace,
|
||||
pub tab: Tab,
|
||||
/// The command search (S, Cmd/Ctrl+K).
|
||||
pub palette: bool,
|
||||
/// The open menu: `file`, `help`, `workspace`, `view`, or a toolbar panel's drop-down as
|
||||
/// `<tab>/<panel>` (`mesh/Tet`).
|
||||
pub menu: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for UiState {
|
||||
@@ -58,15 +90,49 @@ impl Default for UiState {
|
||||
UiState {
|
||||
style: Style::ShadedEdges,
|
||||
show_nodes: false,
|
||||
show_geometry: true,
|
||||
show_mesh: true,
|
||||
perspective: false,
|
||||
dark: true,
|
||||
show_tree: true,
|
||||
show_commands: true,
|
||||
show_timeline: true,
|
||||
workspace: Workspace::default(),
|
||||
tab: Tab::default(),
|
||||
palette: false,
|
||||
menu: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl UiState {
|
||||
/// Show `tab`, on the current workspace when it has it, else on the first that does.
|
||||
pub fn select_tab(&mut self, tab: Tab) {
|
||||
self.tab = tab;
|
||||
self.workspace = Workspace::showing(tab, self.workspace);
|
||||
}
|
||||
|
||||
/// Show workspace `w` on its first tab.
|
||||
pub fn select_workspace(&mut self, w: Workspace) {
|
||||
self.workspace = w;
|
||||
self.tab = w.tabs().first().copied().unwrap_or(Tab::Tools);
|
||||
}
|
||||
|
||||
/// What the viewport shows.
|
||||
pub fn show(&self) -> scene::Show {
|
||||
scene::Show { geometry: self.show_geometry, mesh: self.show_mesh, nodes: self.show_nodes }
|
||||
}
|
||||
}
|
||||
|
||||
/// What a left drag in the viewport does (the navigation bar's modes).
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum NavMode {
|
||||
#[default]
|
||||
Orbit,
|
||||
Pan,
|
||||
Zoom,
|
||||
}
|
||||
|
||||
/// The parameter form a command opens when started from the Commands panel.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ParamsDialog {
|
||||
@@ -179,6 +245,40 @@ pub struct ModelApp {
|
||||
/// The app time (seconds) of the current frame.
|
||||
pub now: f64,
|
||||
pub quit_requested: bool,
|
||||
/// Host services: native file pickers, the recent-files file.
|
||||
pub services: files::Services,
|
||||
/// Recently opened and saved files.
|
||||
pub recent: files::Recent,
|
||||
/// The file opening in the background, and files waiting to open after it.
|
||||
pub loading: Option<files::Loading>,
|
||||
pub queued: std::collections::VecDeque<String>,
|
||||
/// The question the window is asking (unsaved changes, recover).
|
||||
pub prompt: Option<files::Prompt>,
|
||||
/// The window draws its own title bar and caption buttons (Windows, Linux).
|
||||
pub custom_titlebar: bool,
|
||||
/// The title bar runs under the macOS traffic lights.
|
||||
pub integrated_titlebar: bool,
|
||||
/// The command search's query and the command line's text.
|
||||
pub palette_text: String,
|
||||
pub command_line: String,
|
||||
/// Browser sections that are unfolded.
|
||||
pub tree_open: std::collections::BTreeSet<String>,
|
||||
/// The definition selected in the browser: (kind, name), its properties on the right.
|
||||
pub selected: Option<(browser::Def, String)>,
|
||||
/// What a left drag in the viewport does.
|
||||
pub nav: NavMode,
|
||||
/// Where the window's regions were drawn last frame (`ui.inspect`'s `layout`).
|
||||
pub layout: std::collections::BTreeMap<&'static str, egui::Rect>,
|
||||
/// The toolbar's panel labels drawn last frame, by `<tab>/<panel>`.
|
||||
pub panel_rects: Vec<(String, egui::Rect)>,
|
||||
/// The timeline's items and the journal state they were built for.
|
||||
timeline: Option<((u64, usize, (usize, usize)), std::sync::Arc<Vec<timeline::Item>>)>,
|
||||
/// The browser's element counts and the model revision they were counted at.
|
||||
element_counts: Option<(u64, Vec<(modelcraft_model::ElementKind, usize)>)>,
|
||||
/// The selected definition's property rows and what they were read for.
|
||||
properties: Option<((u64, browser::Def, String), std::sync::Arc<Vec<(String, String)>>)>,
|
||||
/// The search's query and its results.
|
||||
search: Option<(String, std::sync::Arc<Vec<palette::Hit>>)>,
|
||||
}
|
||||
|
||||
impl ModelApp {
|
||||
@@ -211,6 +311,24 @@ impl ModelApp {
|
||||
offscreen: None,
|
||||
now: 0.0,
|
||||
quit_requested: false,
|
||||
services: files::Services::default(),
|
||||
recent: files::Recent::default(),
|
||||
loading: None,
|
||||
queued: std::collections::VecDeque::new(),
|
||||
prompt: None,
|
||||
custom_titlebar: false,
|
||||
integrated_titlebar: false,
|
||||
palette_text: String::new(),
|
||||
command_line: String::new(),
|
||||
tree_open: ["mesh", "results"].into_iter().map(str::to_string).collect(),
|
||||
selected: None,
|
||||
nav: NavMode::default(),
|
||||
layout: std::collections::BTreeMap::new(),
|
||||
panel_rects: Vec::new(),
|
||||
timeline: None,
|
||||
element_counts: None,
|
||||
search: None,
|
||||
properties: None,
|
||||
};
|
||||
app.fit_view();
|
||||
app
|
||||
@@ -222,6 +340,13 @@ impl ModelApp {
|
||||
self
|
||||
}
|
||||
|
||||
/// Use the host's services (file pickers, the recent-files file) and load the recent list.
|
||||
pub fn with_services(mut self, services: files::Services) -> Self {
|
||||
self.recent = files::Recent::load(services.recent_path.clone());
|
||||
self.services = services;
|
||||
self
|
||||
}
|
||||
|
||||
/// Draw the viewport on the GPU (eframe's wgpu render state, with the app's depth buffer
|
||||
/// bits and MSAA sample count). Without it the viewport renders on the CPU. Device errors
|
||||
/// show in the status bar.
|
||||
@@ -234,6 +359,7 @@ impl ModelApp {
|
||||
/// Run a command with JSON parameters: what every panel, the control channel and scripts
|
||||
/// do. The result or the error goes to the status bar.
|
||||
pub fn run(&mut self, id: &str, params: Value) -> Result<Value, String> {
|
||||
self.ensure_idle()?;
|
||||
let revision = self.session.revision();
|
||||
let label = command_label(id);
|
||||
let r = self.session.execute(id, ¶ms).map_err(|e| e.to_string());
|
||||
@@ -242,7 +368,7 @@ impl ModelApp {
|
||||
self.model_changed();
|
||||
}
|
||||
// The results display commands reply with what is shown, which the viewport shows.
|
||||
let display = id.starts_with("results.") && id != "results.reactions";
|
||||
let display = (id.starts_with("results.") && id != "results.reactions") || id == "solve.run";
|
||||
match &r {
|
||||
Ok(v) if v.is_null() || changed || display => self.set_status(format!("{label} done"), false),
|
||||
Ok(v) => self.set_status(format!("{label}: {v}"), false),
|
||||
@@ -262,11 +388,22 @@ impl ModelApp {
|
||||
r
|
||||
}
|
||||
|
||||
/// What clicking a toolbar entry or a command in the Commands panel does: a command without
|
||||
/// parameters runs, one with parameters opens its form. `id` is a command or a catalogue
|
||||
/// entry; an entry that is coming soon does nothing and says when it comes. Programmatic calls
|
||||
/// use [`ModelApp::run`] instead.
|
||||
/// What a click on a toolbar entry, a menu row or a palette result does: a command without
|
||||
/// parameters runs, one with parameters opens its form, and the file entries (open, save,
|
||||
/// write a deck, recover) go through the host's file pickers. `id` is a command or a
|
||||
/// catalogue entry; an entry that is coming soon does nothing and says when it comes.
|
||||
/// Programmatic calls use [`ModelApp::run`] or [`ModelApp::start_programmatic`].
|
||||
pub fn start(&mut self, id: &str) -> Result<(), String> {
|
||||
self.begin(id, true)
|
||||
}
|
||||
|
||||
/// `ui.start` from the control channel: as a click, but never a native file picker (entries
|
||||
/// that need one open their command's form).
|
||||
pub fn start_programmatic(&mut self, id: &str) -> Result<(), String> {
|
||||
self.begin(id, false)
|
||||
}
|
||||
|
||||
fn begin(&mut self, id: &str, interactive: bool) -> Result<(), String> {
|
||||
let (command, preset) = match catalogue::find(id) {
|
||||
Some(c) => match c.command() {
|
||||
Some(command) => (command, c.preset()),
|
||||
@@ -279,16 +416,27 @@ impl ModelApp {
|
||||
None => (id, json!({})),
|
||||
};
|
||||
let spec = modelcraft_engine::find_command(command).ok_or_else(|| format!("unknown command `{command}`"))?;
|
||||
if self.file_action(spec.id, &preset, interactive) {
|
||||
self.dialog = None;
|
||||
return Ok(());
|
||||
}
|
||||
if spec.params.trim() == "{}" {
|
||||
self.dialog = None;
|
||||
self.run(spec.id, json!({})).map(|_| ())
|
||||
} else {
|
||||
// The form starts with the entry's preset; the rest (a path…) is filled in there.
|
||||
self.dialog = Some(ParamsDialog { command: spec.id, text: preset.to_string(), error: None });
|
||||
self.open_form(spec.id, preset);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Open a command's parameter form with `params` filled in.
|
||||
pub fn open_form(&mut self, command: &str, params: Value) {
|
||||
if let Some(spec) = modelcraft_engine::find_command(command) {
|
||||
self.dialog = Some(ParamsDialog { command: spec.id, text: params.to_string(), error: None });
|
||||
}
|
||||
}
|
||||
|
||||
/// Run the open parameter form; it closes when the command succeeds.
|
||||
pub fn run_dialog(&mut self) -> Result<Value, String> {
|
||||
let Some(d) = self.dialog.clone() else { return Err("no command form is open".into()) };
|
||||
@@ -411,7 +559,7 @@ impl ModelApp {
|
||||
pub fn scene_key(&self) -> u64 {
|
||||
let mut h = std::hash::DefaultHasher::new();
|
||||
let plot = self.plot.1.as_ref().map(|p| Arc::as_ptr(p) as usize);
|
||||
(self.revision, self.ui.style, self.ui.show_nodes, self.ui.dark, plot).hash(&mut h);
|
||||
(self.revision, self.ui.style, self.ui.show(), self.ui.dark, plot).hash(&mut h);
|
||||
h.finish()
|
||||
}
|
||||
|
||||
@@ -450,10 +598,10 @@ impl ModelApp {
|
||||
let key = self.scene_key();
|
||||
if self.scene.0 != Some(key) {
|
||||
let t = theme::Tokens::get(self.ui.dark);
|
||||
let (style, nodes) = (self.ui.style, self.ui.show_nodes);
|
||||
let (style, show) = (self.ui.style, self.ui.show());
|
||||
let s = match &self.plot.1 {
|
||||
Some(p) => results::scene(p, style, nodes, &t),
|
||||
None => scene::build(&self.display.1, style, nodes, &t),
|
||||
Some(p) => results::scene(p, style, show, &t),
|
||||
None => scene::build(&self.display.1, style, show, &t),
|
||||
};
|
||||
self.scene = (Some(key), s);
|
||||
}
|
||||
@@ -479,6 +627,12 @@ impl ModelApp {
|
||||
self.cam.fit(&b);
|
||||
}
|
||||
|
||||
/// The home view: isometric, the whole model framed.
|
||||
pub fn home_view(&mut self) {
|
||||
self.set_view(StandardView::Iso);
|
||||
self.fit_view();
|
||||
}
|
||||
|
||||
pub fn set_view(&mut self, v: StandardView) {
|
||||
self.cam.set_view(v);
|
||||
}
|
||||
@@ -491,6 +645,10 @@ impl ModelApp {
|
||||
self.styled = Some(self.ui.dark);
|
||||
}
|
||||
self.drain_control(ctx);
|
||||
if self.poll_loading() {
|
||||
ctx.request_repaint_after(std::time::Duration::from_millis(50));
|
||||
}
|
||||
self.dropped_files(ctx);
|
||||
self.shortcuts(ctx);
|
||||
self.cam.fov = if self.ui.perspective { PERSPECTIVE_FOV } else { 0.0 };
|
||||
if !self.synthetic.is_empty() {
|
||||
@@ -499,33 +657,57 @@ impl ModelApp {
|
||||
// Results coming up (a solve, a results command) bring the Results tab.
|
||||
let shown = self.session.results_view.is_some();
|
||||
if shown && !self.results_shown {
|
||||
self.ui.tab = Tab::Results;
|
||||
self.ui.select_tab(Tab::Results);
|
||||
}
|
||||
self.results_shown = shown;
|
||||
// A selected definition that is gone (undo, delete) is no longer selected.
|
||||
if self.selected.as_ref().is_some_and(|(kind, name)| !kind.exists(&self.session.model, name)) {
|
||||
self.selected = None;
|
||||
}
|
||||
if self.session.results_view.as_ref().is_some_and(|v| v.animate) {
|
||||
ctx.request_repaint_after(std::time::Duration::from_secs_f64(results::PERIOD / results::FRAMES as f64));
|
||||
}
|
||||
self.screenshots(ctx);
|
||||
}
|
||||
|
||||
/// Undo (Ctrl/Cmd+Z) and redo (Ctrl/Cmd+Shift+Z or Ctrl/Cmd+Y), unless a text field has the
|
||||
/// keyboard (it undoes its own typing).
|
||||
/// Undo (Ctrl/Cmd+Z), redo (Ctrl/Cmd+Shift+Z or Ctrl/Cmd+Y), open (Ctrl/Cmd+O), save
|
||||
/// (Ctrl/Cmd+S) and save as (Ctrl/Cmd+Shift+S), unless a text field has the keyboard (it
|
||||
/// undoes its own typing).
|
||||
fn shortcuts(&mut self, ctx: &egui::Context) {
|
||||
if ctx.memory(|m| m.focused().is_some()) {
|
||||
return;
|
||||
}
|
||||
let shortcut = |modifiers, key| egui::KeyboardShortcut::new(modifiers, key);
|
||||
// Shift+Z first: the plain shortcut matches it too.
|
||||
let (redo, undo) = ctx.input_mut(|i| {
|
||||
let redo = i.consume_shortcut(&shortcut(egui::Modifiers::COMMAND | egui::Modifiers::SHIFT, egui::Key::Z))
|
||||
|| i.consume_shortcut(&shortcut(egui::Modifiers::COMMAND, egui::Key::Y));
|
||||
(redo, i.consume_shortcut(&shortcut(egui::Modifiers::COMMAND, egui::Key::Z)))
|
||||
let shift = egui::Modifiers::COMMAND | egui::Modifiers::SHIFT;
|
||||
// Shift first: the plain shortcut matches it too.
|
||||
let (redo, undo, save_as, save, open) = ctx.input_mut(|i| {
|
||||
let redo = i.consume_shortcut(&shortcut(shift, egui::Key::Z)) || i.consume_shortcut(&shortcut(egui::Modifiers::COMMAND, egui::Key::Y));
|
||||
let undo = i.consume_shortcut(&shortcut(egui::Modifiers::COMMAND, egui::Key::Z));
|
||||
let save_as = i.consume_shortcut(&shortcut(shift, egui::Key::S));
|
||||
let save = i.consume_shortcut(&shortcut(egui::Modifiers::COMMAND, egui::Key::S));
|
||||
(redo, undo, save_as, save, i.consume_shortcut(&shortcut(egui::Modifiers::COMMAND, egui::Key::O)))
|
||||
});
|
||||
if redo {
|
||||
let _ = self.run("edit.redo", json!({}));
|
||||
} else if undo {
|
||||
let _ = self.run("edit.undo", json!({}));
|
||||
}
|
||||
if save_as {
|
||||
self.save_as();
|
||||
} else if save {
|
||||
self.save();
|
||||
}
|
||||
if open {
|
||||
self.open_dialog(None);
|
||||
}
|
||||
// The command search: S (as in SolidCraft) or Cmd/Ctrl+K.
|
||||
let search = ctx.input_mut(|i| {
|
||||
i.consume_shortcut(&shortcut(egui::Modifiers::COMMAND, egui::Key::K)) || i.consume_key(egui::Modifiers::NONE, egui::Key::S)
|
||||
});
|
||||
if search {
|
||||
self.ui.palette = true;
|
||||
self.ui.menu = None;
|
||||
}
|
||||
}
|
||||
|
||||
/// Inject synthetic events: one pointer event per frame (egui reads a press and release in
|
||||
@@ -558,17 +740,33 @@ impl ModelApp {
|
||||
/// Lay out the whole window.
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui) {
|
||||
self.show_gpu_errors();
|
||||
panels::menu_bar(self, ui);
|
||||
self.layout.clear();
|
||||
appbar::app_bar(self, ui);
|
||||
toolbar::toolbar(self, ui);
|
||||
panels::status_bar(self, ui);
|
||||
if self.ui.show_timeline {
|
||||
timeline::timeline(self, ui);
|
||||
}
|
||||
palette::command_line(self, ui);
|
||||
if self.ui.show_tree {
|
||||
panels::model_tree(self, ui);
|
||||
}
|
||||
if self.ui.show_commands {
|
||||
panels::commands(self, ui);
|
||||
browser::browser(self, ui);
|
||||
}
|
||||
context::panel(self, ui);
|
||||
egui::CentralPanel::default().frame(egui::Frame::NONE).show(ui, |ui| viewport::show(self, ui));
|
||||
panels::params_dialog(self, ui.ctx());
|
||||
palette::popup(self, ui.ctx());
|
||||
files::show(self, ui.ctx());
|
||||
if self.custom_titlebar {
|
||||
titlebar::resize_zones(ui);
|
||||
}
|
||||
}
|
||||
|
||||
/// Remember where a region of the window was drawn (`ui.inspect`'s `layout`).
|
||||
pub fn place(&mut self, region: &'static str, rect: egui::Rect) {
|
||||
self.layout.insert(region, rect);
|
||||
}
|
||||
|
||||
/// Open, or close when it is open, a menu (see [`UiState::menu`]).
|
||||
pub fn toggle_menu(&mut self, key: &str) {
|
||||
self.ui.menu = if self.ui.menu.as_deref() == Some(key) { None } else { Some(key.to_string()) };
|
||||
}
|
||||
|
||||
fn drain_control(&mut self, ctx: &egui::Context) {
|
||||
@@ -735,7 +933,7 @@ mod tests {
|
||||
assert!(d.tris.is_empty());
|
||||
// Without elements, geometry draws as faces with their boundaries; the camera frames it.
|
||||
let t = theme::Tokens::dark();
|
||||
let s = scene::build(&d, Style::ShadedEdges, false, &t);
|
||||
let s = scene::build(&d, Style::ShadedEdges, scene::Show::DEFAULT, &t);
|
||||
assert_eq!(s.tris.len(), d.surface_tris.len());
|
||||
assert!(s.tris.iter().all(|tri| tri.color == theme::rgb(t.geometry)));
|
||||
assert!(!d.bounds.is_empty());
|
||||
@@ -873,6 +1071,101 @@ mod tests {
|
||||
assert!(found, "a red legend swatch");
|
||||
}
|
||||
|
||||
fn region(app: &ModelApp, name: &str) -> egui::Rect {
|
||||
app.layout.get(name).copied().unwrap_or_else(|| panic!("no {name} in {:?}", app.layout.keys()))
|
||||
}
|
||||
|
||||
/// The family layout: title bar, ribbon, browser left, viewport, command line and timeline at
|
||||
/// the bottom; the context panel on the right only while there is context.
|
||||
#[test]
|
||||
fn the_window_is_laid_out_like_the_other_crafts() {
|
||||
let mut app = ModelApp::new(Session::default());
|
||||
app.open_sample("cantilever");
|
||||
let size = capture::CaptureSize { width: 1400.0, height: 900.0, scale: 1.0 };
|
||||
// `layout` is the live window's; a capture leaves it, so draw a frame of the UI directly.
|
||||
let frame = |app: &mut ModelApp| {
|
||||
let ctx = egui::Context::default();
|
||||
for _ in 0..2 {
|
||||
let raw = egui::RawInput {
|
||||
screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(size.width, size.height))),
|
||||
..Default::default()
|
||||
};
|
||||
let mut out = ctx.run_ui(raw, |ui| app.ui(ui));
|
||||
out.textures_delta.clear();
|
||||
}
|
||||
};
|
||||
frame(&mut app);
|
||||
let (bar, ribbon, browser, view) = (region(&app, "app_bar"), region(&app, "ribbon"), region(&app, "browser"), region(&app, "viewport"));
|
||||
let (line, timeline) = (region(&app, "command_line"), region(&app, "timeline"));
|
||||
assert_eq!((bar.top(), bar.height()), (0.0, appbar::HEIGHT));
|
||||
assert!((ribbon.top() - bar.bottom()).abs() < 1.0 && (ribbon.height() - toolbar::HEIGHT).abs() < 1.0, "{ribbon:?}");
|
||||
// The browser's content, inside its margin.
|
||||
assert!(browser.left() < 8.0 && (browser.width() - browser::WIDTH).abs() <= 14.0, "{browser:?}");
|
||||
assert!(view.left() >= browser.right() - 1.0 && view.top() >= ribbon.bottom() - 1.0 && view.bottom() <= line.top() + 1.0);
|
||||
assert!((timeline.bottom() - 900.0).abs() < 1.0 && line.bottom() <= timeline.top() + 1.0);
|
||||
assert!((view.right() - 1400.0).abs() < 1.0, "no context: the viewport reaches the right edge");
|
||||
assert!(!app.layout.contains_key("context"));
|
||||
for chrome in ["nav_bar", "axis_view", "workspace_switcher", "document_tab", "app_bar:solve"] {
|
||||
let r = region(&app, chrome);
|
||||
assert!(r.is_positive(), "{chrome}");
|
||||
}
|
||||
assert!(view.contains_rect(region(&app, "nav_bar")) && view.contains_rect(region(&app, "axis_view")));
|
||||
// A form brings the context panel; the viewport makes room.
|
||||
app.start("model.material.create").unwrap();
|
||||
frame(&mut app);
|
||||
let context = region(&app, "context");
|
||||
assert!(context.right() > 1390.0 && context.width() > 280.0, "{context:?}");
|
||||
assert!(region(&app, "viewport").right() <= context.left() + 1.0);
|
||||
// The search and a drop-down are drawn when their state says so.
|
||||
app.dialog = None;
|
||||
app.ui.palette = true;
|
||||
app.ui.menu = Some("mesh/Tet".into());
|
||||
app.ui.select_tab(Tab::Mesh);
|
||||
frame(&mut app);
|
||||
assert!(app.layout.contains_key("palette") && app.layout.contains_key("toolbar_dropdown"), "{:?}", app.layout.keys());
|
||||
assert_eq!(app.ui.workspace, Workspace::Prepare);
|
||||
}
|
||||
|
||||
/// No entry is lost: on every tab, at a wide and a narrow window, every catalogue entry is a
|
||||
/// button, a collapsed panel or a » panel, and a row of its panel's drop-down once it is open.
|
||||
#[test]
|
||||
fn every_catalogue_entry_is_reachable_from_its_tab() {
|
||||
for width in [1400.0, 960.0] {
|
||||
for tab in Tab::ALL {
|
||||
let mut app = ModelApp::new(Session::default());
|
||||
app.ui.select_tab(tab);
|
||||
let ctx = egui::Context::default();
|
||||
let run = |app: &mut ModelApp| {
|
||||
let raw = egui::RawInput {
|
||||
screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(width, 800.0))),
|
||||
..Default::default()
|
||||
};
|
||||
let mut out = ctx.run_ui(raw, |ui| app.ui(ui));
|
||||
out.textures_delta.clear();
|
||||
};
|
||||
run(&mut app);
|
||||
for c in catalogue::tab_entries(tab) {
|
||||
assert!(app.toolbar_rects.iter().any(|(id, ..)| *id == c.id), "{width}: {} is not on the {tab:?} tab", c.id);
|
||||
}
|
||||
for p in catalogue::panels(tab) {
|
||||
let Some(panel) = p.first().map(|c| c.panel) else { continue };
|
||||
let collapsed_or_more = app.toolbar_rects.iter().any(|(id, _, f)| *id == p[0].id && matches!(f, toolbar::Fit::More));
|
||||
if collapsed_or_more {
|
||||
continue;
|
||||
}
|
||||
app.ui.menu = Some(toolbar::panel_key(tab, panel));
|
||||
run(&mut app);
|
||||
run(&mut app);
|
||||
for c in p {
|
||||
let row = app.toolbar_rects.iter().any(|(id, r, f)| *id == c.id && *f == toolbar::Fit::Menu && r.is_positive());
|
||||
assert!(row, "{width}: {} has no row in the {panel} drop-down", c.id);
|
||||
}
|
||||
app.ui.menu = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn display_tolerance_follows_the_size() {
|
||||
let b = |max: [f64; 3]| Aabb3 { min: Vec3::ZERO, max: max.into() };
|
||||
|
||||
Reference in new issue
Block a user