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
+181
-47
@@ -1,15 +1,18 @@
|
||||
//! The 3D viewport: the model drawn on the GPU (or on the CPU without one), camera navigation,
|
||||
//! the standard-view buttons and an axis indicator.
|
||||
//! the navigation bar (bottom centre) and the orientation gizmo (top right), as in SolidCraft.
|
||||
//!
|
||||
//! Navigation: left drag orbits, right or middle drag (or Shift + left drag) pans, the wheel or a
|
||||
//! pinch zooms at the cursor, a double click or F frames the model.
|
||||
//! Navigation: left drag orbits (or pans or zooms: the navigation bar's modes), right or middle
|
||||
//! drag (or Shift + left drag) pans, the wheel or a pinch zooms at the cursor, a double click or F
|
||||
//! frames the model. The gizmo's axis tips turn the view to look along them. The bar and the gizmo
|
||||
//! follow SolidCraft's `viewport.rs` (MIT OR Apache-2.0), see ATTRIBUTION.md.
|
||||
|
||||
use egui::{Color32, Pos2, Rect, Sense, Stroke, Vec2, pos2, vec2};
|
||||
use modelcraft_render::{StandardView, Vec3};
|
||||
|
||||
use crate::ModelApp;
|
||||
use crate::gpu::{GpuScene, ViewportCallback};
|
||||
use crate::icons::{self, Look};
|
||||
use crate::theme::Tokens;
|
||||
use crate::{ModelApp, NavMode, Style};
|
||||
|
||||
/// Wheel zoom per point scrolled.
|
||||
const ZOOM_PER_POINT: f64 = 0.0015;
|
||||
@@ -17,6 +20,7 @@ const ZOOM_PER_POINT: f64 = 0.0015;
|
||||
pub fn show(app: &mut ModelApp, ui: &mut egui::Ui) {
|
||||
let rect = ui.available_rect_before_wrap();
|
||||
app.viewport.rect = Some(rect);
|
||||
app.place("viewport", rect);
|
||||
let response = ui.allocate_rect(rect, Sense::click_and_drag());
|
||||
navigate(app, ui, &response, rect);
|
||||
if response.clicked()
|
||||
@@ -32,18 +36,34 @@ pub fn show(app: &mut ModelApp, ui: &mut egui::Ui) {
|
||||
} else {
|
||||
paint_cpu(app, ui, &painter, rect);
|
||||
}
|
||||
if app.display().bounds.is_empty() {
|
||||
painter.text(
|
||||
rect.center(),
|
||||
egui::Align2::CENTER_CENTER,
|
||||
"The model is empty.\nOpen a design or add nodes and elements, or start with --sample.",
|
||||
egui::FontId::proportional(15.0),
|
||||
t.text_dim,
|
||||
);
|
||||
if app.display().bounds.is_empty() && app.busy().is_none() {
|
||||
start_screen(app, ui, rect, &t);
|
||||
}
|
||||
axis_indicator(app, &painter, rect, &t);
|
||||
view_buttons(app, ui, rect, &t);
|
||||
crate::results_panel::show(app, ui, rect, &t);
|
||||
axis_view(app, ui, rect, &t);
|
||||
nav_bar(app, ui, rect, &t);
|
||||
}
|
||||
|
||||
/// The empty viewport: open a file or a sample (the samples are ready to solve).
|
||||
fn start_screen(app: &mut ModelApp, ui: &mut egui::Ui, rect: Rect, t: &Tokens) {
|
||||
let mut open = None;
|
||||
let mut pick = false;
|
||||
let area = Rect::from_center_size(rect.center(), vec2(440.0_f32.min(rect.width() - 24.0), 300.0_f32.min(rect.height() - 24.0)));
|
||||
let mut child = ui.new_child(egui::UiBuilder::new().max_rect(area).layout(egui::Layout::top_down(egui::Align::Min)));
|
||||
egui::Frame::NONE.fill(t.overlay).corner_radius(6.0).inner_margin(egui::Margin::same(14)).show(&mut child, |ui| {
|
||||
ui.label(egui::RichText::new("Start").size(16.0).color(t.overlay_text));
|
||||
ui.label(egui::RichText::new("Open a model, a SolidCraft design or a tagged mesh — or drop one here.").color(t.text_dim));
|
||||
ui.add_space(4.0);
|
||||
pick = ui.button("Open…").clicked();
|
||||
ui.add_space(8.0);
|
||||
ui.label(egui::RichText::new("Samples").color(t.overlay_text));
|
||||
crate::files::sample_rows(ui, t, &mut open);
|
||||
});
|
||||
if pick {
|
||||
app.open_dialog(None);
|
||||
} else if let Some(n) = open {
|
||||
app.open_sample(n);
|
||||
}
|
||||
}
|
||||
|
||||
/// A click on a results plot probes the node nearest to the face under the pointer.
|
||||
@@ -61,12 +81,12 @@ fn navigate(app: &mut ModelApp, ui: &egui::Ui, response: &egui::Response, rect:
|
||||
let d = response.drag_delta();
|
||||
let (dx, dy) = (f64::from(d.x), f64::from(d.y));
|
||||
let shift = ui.input(|i| i.modifiers.shift);
|
||||
if response.dragged_by(egui::PointerButton::Primary) && !shift {
|
||||
let left = response.dragged_by(egui::PointerButton::Primary);
|
||||
if left && !shift && app.nav == NavMode::Orbit {
|
||||
app.cam.orbit(dx, dy);
|
||||
} else if response.dragged_by(egui::PointerButton::Secondary)
|
||||
|| response.dragged_by(egui::PointerButton::Middle)
|
||||
|| (response.dragged_by(egui::PointerButton::Primary) && shift)
|
||||
{
|
||||
} else if left && !shift && app.nav == NavMode::Zoom {
|
||||
app.cam.zoom_at((dy * ZOOM_PER_POINT * 4.0).exp(), None);
|
||||
} else if response.dragged_by(egui::PointerButton::Secondary) || response.dragged_by(egui::PointerButton::Middle) || left {
|
||||
app.cam.pan(dx, dy, h);
|
||||
}
|
||||
if response.double_clicked() || (response.hovered() && ui.input(|i| i.key_pressed(egui::Key::F) && i.modifiers.is_none())) {
|
||||
@@ -156,42 +176,156 @@ fn paint_cpu(app: &mut ModelApp, ui: &egui::Ui, painter: &egui::Painter, rect: R
|
||||
}
|
||||
}
|
||||
|
||||
/// X, Y and Z drawn from the lower-left corner in the current view direction.
|
||||
fn axis_indicator(app: &ModelApp, painter: &egui::Painter, rect: Rect, t: &Tokens) {
|
||||
/// The orientation gizmo's arm length and tip radius (points).
|
||||
const AXIS_LENGTH: f32 = 38.0;
|
||||
const AXIS_RADIUS: f32 = 11.0;
|
||||
|
||||
/// The standard view looking along `d` from outside (the one whose eye side is nearest `d`).
|
||||
fn view_along(d: Vec3) -> StandardView {
|
||||
let mut best = (StandardView::Front, f64::NEG_INFINITY);
|
||||
for v in StandardView::ALL.into_iter().filter(|v| *v != StandardView::Iso) {
|
||||
let mut c = modelcraft_render::Camera::default();
|
||||
c.set_view(v);
|
||||
let score = c.back().dot(d);
|
||||
if score > best.1 {
|
||||
best = (v, score);
|
||||
}
|
||||
}
|
||||
best.0
|
||||
}
|
||||
|
||||
/// The orientation gizmo (top right): the six signed axes in the current view, back to front;
|
||||
/// clicking a tip looks along it, the house returns to the home view.
|
||||
fn axis_view(app: &mut ModelApp, ui: &mut egui::Ui, rect: Rect, t: &Tokens) {
|
||||
let area = Rect::from_center_size(pos2(rect.right() - 68.0, rect.top() + 68.0), Vec2::splat(116.0));
|
||||
if !rect.contains_rect(area) {
|
||||
return;
|
||||
}
|
||||
app.place("axis_view", area);
|
||||
let c = area.center();
|
||||
let (r, u, b) = app.cam.basis();
|
||||
let origin = rect.left_bottom() + vec2(44.0, -44.0);
|
||||
let len = 30.0;
|
||||
let mut axes = [(Vec3::X, t.axis_x, "X"), (Vec3::Y, t.axis_y, "Y"), (Vec3::Z, t.axis_z, "Z")];
|
||||
// Farthest first, so the nearest axis is drawn on top.
|
||||
axes.sort_by(|a, b2| a.0.dot(b).total_cmp(&b2.0.dot(b)));
|
||||
for (axis, color, name) in axes {
|
||||
let tip = origin + Vec2::new(axis.dot(r) as f32, -axis.dot(u) as f32) * len;
|
||||
painter.line_segment([origin, tip], Stroke::new(2.0, color));
|
||||
painter.text(tip + (tip - origin).normalized() * 9.0, egui::Align2::CENTER_CENTER, name, egui::FontId::proportional(12.0), color);
|
||||
let mut tips: Vec<(&str, Vec3, Pos2, f64, Color32)> = [
|
||||
("X", Vec3::X, t.axis_x),
|
||||
("-X", Vec3::new(-1.0, 0.0, 0.0), t.axis_x),
|
||||
("Y", Vec3::Y, t.axis_y),
|
||||
("-Y", Vec3::new(0.0, -1.0, 0.0), t.axis_y),
|
||||
("Z", Vec3::Z, t.axis_z),
|
||||
("-Z", Vec3::new(0.0, 0.0, -1.0), t.axis_z),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(name, d, col)| (name, d, c + vec2(d.dot(r) as f32 * AXIS_LENGTH, -(d.dot(u) as f32) * AXIS_LENGTH), d.dot(b), col))
|
||||
.collect();
|
||||
tips.sort_by(|a, b2| a.3.total_cmp(&b2.3));
|
||||
let hover = ui.input(|i| i.pointer.hover_pos()).filter(|p| area.contains(*p));
|
||||
let hovered = hover.and_then(|p| tips.iter().rposition(|(_, _, at, _, _)| at.distance(p) <= AXIS_RADIUS));
|
||||
let painter = ui.painter_at(rect);
|
||||
if hover.is_some() {
|
||||
painter.circle_filled(c, 55.0, t.overlay);
|
||||
}
|
||||
for (i, (name, _, at, depth, col)) in tips.iter().enumerate() {
|
||||
let positive = !name.starts_with('-');
|
||||
let ink = if *depth < -0.01 { col.gamma_multiply(0.55) } else { *col };
|
||||
painter.line_segment([c, *at], Stroke::new(if positive { 2.0 } else { 1.0 }, ink));
|
||||
let hot = hovered == Some(i);
|
||||
painter.circle_filled(*at, AXIS_RADIUS, if hot { t.accent_soft } else { t.overlay });
|
||||
painter.circle_stroke(*at, AXIS_RADIUS, Stroke::new(if hot { 2.0 } else { 1.0 }, if hot { t.accent } else { ink }));
|
||||
painter.text(*at, egui::Align2::CENTER_CENTER, *name, egui::FontId::proportional(11.0), ink);
|
||||
}
|
||||
let resp = ui.interact(area, ui.id().with("mc_axis_view"), Sense::click());
|
||||
if let Some(i) = hovered
|
||||
&& let Some((name, d, ..)) = tips.get(i)
|
||||
{
|
||||
let view = view_along(*d);
|
||||
let resp = resp.clone().on_hover_text(format!("Look from {name} ({})", view.label()));
|
||||
if resp.clicked() {
|
||||
app.set_view(view);
|
||||
}
|
||||
}
|
||||
let home = Rect::from_center_size(pos2(c.x - 44.0, c.y - 44.0), Vec2::splat(18.0));
|
||||
let hr = ui.interact(home, ui.id().with("mc_axis_home"), Sense::click());
|
||||
if hr.hovered() {
|
||||
painter.rect_filled(home.expand(2.0), 3.0, t.hover);
|
||||
}
|
||||
icons::paint(app, ui, "ui.home", home, Look::Normal);
|
||||
if hr.on_hover_text("Home view").clicked() {
|
||||
app.home_view();
|
||||
}
|
||||
}
|
||||
|
||||
/// The standard views and Fit, as text buttons along the viewport's top edge.
|
||||
fn view_buttons(app: &mut ModelApp, ui: &mut egui::Ui, rect: Rect, t: &Tokens) {
|
||||
let area = Rect::from_min_size(rect.left_top() + vec2(8.0, 8.0), vec2(rect.width() - 16.0, 26.0));
|
||||
let mut child = ui.new_child(egui::UiBuilder::new().max_rect(area).layout(egui::Layout::left_to_right(egui::Align::Center)));
|
||||
egui::Frame::NONE.fill(t.overlay).corner_radius(4.0).inner_margin(egui::Margin::symmetric(4, 2)).show(&mut child, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
for v in StandardView::ALL {
|
||||
if view_button(ui, v.label(), t).clicked() {
|
||||
app.set_view(v);
|
||||
/// The navigation bar's buttons: (key, icon, tooltip).
|
||||
const NAV: [(&str, &str, &str); 7] = [
|
||||
("orbit", "ui.orbit", "Orbit: left drag turns the view"),
|
||||
("pan", "ui.pan", "Pan: left drag moves the view (or right or middle drag)"),
|
||||
("zoom", "ui.zoom", "Zoom: left drag up and down (or the wheel)"),
|
||||
("fit", "ui.fit", "Fit the model (F, or a double click)"),
|
||||
("home", "ui.home", "Home view"),
|
||||
("perspective", "ui.perspective", "Perspective or orthographic"),
|
||||
("style", "ui.style", "Visual style and what is shown"),
|
||||
];
|
||||
|
||||
/// The navigation bar, bottom centre: navigation modes, fit, home, projection, and the display
|
||||
/// menu (style, geometry, mesh, nodes).
|
||||
fn nav_bar(app: &mut ModelApp, ui: &mut egui::Ui, rect: Rect, t: &Tokens) {
|
||||
let w = NAV.len() as f32 * 30.0 + 10.0;
|
||||
let bar = Rect::from_center_size(pos2(rect.center().x, rect.bottom() - 22.0), vec2(w, 30.0));
|
||||
if !rect.contains_rect(bar) {
|
||||
return;
|
||||
}
|
||||
app.place("nav_bar", bar);
|
||||
ui.painter().rect(bar, 6.0, t.overlay, Stroke::new(1.0, t.border), egui::StrokeKind::Inside);
|
||||
let mut style_button = None;
|
||||
for (i, (key, icon, tip)) in NAV.iter().enumerate() {
|
||||
let br = Rect::from_min_size(pos2(bar.left() + 5.0 + i as f32 * 30.0, bar.top() + 2.0), Vec2::splat(26.0));
|
||||
let resp = ui.interact(br, ui.id().with(("mc_nav", *key)), Sense::click());
|
||||
let active = match *key {
|
||||
"orbit" => app.nav == NavMode::Orbit,
|
||||
"pan" => app.nav == NavMode::Pan,
|
||||
"zoom" => app.nav == NavMode::Zoom,
|
||||
"perspective" => app.ui.perspective,
|
||||
"style" => app.ui.menu.as_deref() == Some("view"),
|
||||
_ => false,
|
||||
};
|
||||
if active || resp.hovered() {
|
||||
ui.painter().rect_filled(br, 4.0, if active { t.accent_soft } else { t.hover });
|
||||
}
|
||||
icons::paint(app, ui, icon, br.shrink(4.0), Look::Normal);
|
||||
resp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::Button, true, active, *tip));
|
||||
if resp.on_hover_text(*tip).clicked() {
|
||||
match *key {
|
||||
"orbit" => app.nav = NavMode::Orbit,
|
||||
"pan" => app.nav = NavMode::Pan,
|
||||
"zoom" => app.nav = NavMode::Zoom,
|
||||
"fit" => app.fit_view(),
|
||||
"home" => {
|
||||
app.home_view();
|
||||
}
|
||||
"perspective" => app.ui.perspective = !app.ui.perspective,
|
||||
_ => app.toggle_menu("view"),
|
||||
}
|
||||
}
|
||||
if *key == "style" {
|
||||
style_button = Some(br);
|
||||
}
|
||||
}
|
||||
if let Some(br) = style_button {
|
||||
crate::frame::settings_menu(app, ui, "view", br, |app, ui| {
|
||||
let t = Tokens::get(app.ui.dark);
|
||||
crate::frame::menu_heading(ui, &t, "STYLE");
|
||||
for s in Style::ALL {
|
||||
if ui.radio(app.ui.style == s, s.label()).clicked() {
|
||||
app.ui.style = s;
|
||||
}
|
||||
}
|
||||
ui.separator();
|
||||
if view_button(ui, "Fit", t).on_hover_text("Frame the whole model (F, or double-click)").clicked() {
|
||||
app.fit_view();
|
||||
}
|
||||
crate::frame::menu_heading(ui, &t, "SHOW");
|
||||
ui.checkbox(&mut app.ui.show_geometry, "Geometry");
|
||||
ui.checkbox(&mut app.ui.show_mesh, "Mesh");
|
||||
ui.checkbox(&mut app.ui.show_nodes, "Nodes");
|
||||
ui.separator();
|
||||
ui.checkbox(&mut app.ui.show_tree, "Browser");
|
||||
ui.checkbox(&mut app.ui.show_timeline, "Timeline");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn view_button(ui: &mut egui::Ui, label: &str, t: &Tokens) -> egui::Response {
|
||||
ui.add(egui::Button::new(egui::RichText::new(label).color(t.overlay_text).size(12.0)).frame(false).min_size(vec2(0.0, 20.0)))
|
||||
}
|
||||
}
|
||||
|
||||
/// The screen point (points) of a world point in the viewport drawn last frame.
|
||||
|
||||
Reference in new issue
Block a user