SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Navigation bar: can sit at the top of the view (#8183) (#8793)
phanoob22353893443b
diff --git a/assets/locales/pending/navigation-bar-top-edge.json b/assets/locales/pending/navigation-bar-top-edge.jsonnew file mode 100644index 0000000000..349f202643--- /dev/null+++ b/assets/locales/pending/navigation-bar-top-edge.json@@ -0,0 +1,52 @@+{+ "en": {+ "navbar.custom.edge": "Edge",+ "navbar.custom.edge_bottom": "Bottom",+ "navbar.custom.edge_top": "Top"+ },+ "fr": {+ "navbar.custom.edge": "Bord",+ "navbar.custom.edge_bottom": "Bas",+ "navbar.custom.edge_top": "Haut"+ },+ "de": {+ "navbar.custom.edge": "Rand",+ "navbar.custom.edge_bottom": "Unten",+ "navbar.custom.edge_top": "Oben"+ },+ "it": {+ "navbar.custom.edge": "Bordo",+ "navbar.custom.edge_bottom": "In basso",+ "navbar.custom.edge_top": "In alto"+ },+ "es": {+ "navbar.custom.edge": "Borde",+ "navbar.custom.edge_bottom": "Abajo",+ "navbar.custom.edge_top": "Arriba"+ },+ "ar": {+ "navbar.custom.edge": "الحافة",+ "navbar.custom.edge_bottom": "أسفل",+ "navbar.custom.edge_top": "أعلى"+ },+ "he": {+ "navbar.custom.edge": "קצה",+ "navbar.custom.edge_bottom": "למטה",+ "navbar.custom.edge_top": "למעלה"+ },+ "ja": {+ "navbar.custom.edge": "端",+ "navbar.custom.edge_bottom": "下",+ "navbar.custom.edge_top": "上"+ },+ "vi": {+ "navbar.custom.edge": "Cạnh",+ "navbar.custom.edge_bottom": "Dưới",+ "navbar.custom.edge_top": "Trên"+ },+ "zh": {+ "navbar.custom.edge": "边缘",+ "navbar.custom.edge_bottom": "底部",+ "navbar.custom.edge_top": "顶部"+ }+}diff --git a/crates/ui-egui/src/navigation_bar.rs b/crates/ui-egui/src/navigation_bar.rsindex 9152425dc7..9bcba8bc91 100644--- a/crates/ui-egui/src/navigation_bar.rs+++ b/crates/ui-egui/src/navigation_bar.rs@@ -116,6 +116,15 @@ pub enum Position {Right,}+/// The edge of the 3D view the bar sits on (#8183): the bottom, or the top, under the ribbon.+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]+#[serde(rename_all = "snake_case")]+pub enum Edge {+ #[default]+ Bottom,+ Top,+}+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]#[serde(rename_all = "snake_case")]pub enum Size {@@ -166,6 +175,7 @@ pub struct NavigationBar {pub slots: Vec<String>,pub slot_options: std::collections::BTreeMap<String, SlotOptions>,pub position: Position,+ pub edge: Edge,pub size: Size,pub labels: Labels,pub idle: Idle,@@ -180,6 +190,7 @@ impl Default for NavigationBar {.collect(),slot_options: Default::default(),position: Position::default(),+ edge: Edge::default(),size: Size::default(),labels: Labels::default(),idle: Idle::default(),@@ -223,6 +234,9 @@ impl<'de> Deserialize<'de> for NavigationBar {if let Some(v) = value.get("position") {bar.position = serde_json::from_value(v.clone()).unwrap_or_default();}+ if let Some(v) = value.get("edge") {+ bar.edge = serde_json::from_value(v.clone()).unwrap_or_default();+ }if let Some(v) = value.get("size") {bar.size = serde_json::from_value(v.clone()).unwrap_or_default();}@@ -252,6 +266,7 @@ pub(crate) fn validate(value: &Value) -> Result<(), String> {})}),"position" => serde_json::from_value::<Position>(value.clone()).is_ok(),+ "edge" => serde_json::from_value::<Edge>(value.clone()).is_ok(),"size" => serde_json::from_value::<Size>(value.clone()).is_ok(),"labels" => serde_json::from_value::<Labels>(value.clone()).is_ok(),"idle" => serde_json::from_value::<Idle>(value.clone()).is_ok(),diff --git a/crates/ui-egui/src/navigation_bar_tests.rs b/crates/ui-egui/src/navigation_bar_tests.rsindex b49c3a55c3..9dbaf8d944 100644--- a/crates/ui-egui/src/navigation_bar_tests.rs+++ b/crates/ui-egui/src/navigation_bar_tests.rs@@ -151,6 +151,39 @@ fn measured_bar_honours_size_position_and_ignores_unknown_slots() {}}+#[test]+fn a_bar_on_the_top_edge_sits_under_the_top_and_keeps_the_corner_controls_below_it() {+ use crate::ui_kit::NAV_BOTTOM;+ // Older settings have no edge and keep the bar at the bottom; a bad value recovers the same way.+ let old: NavigationBar = serde_json::from_value(json!({"position": "right"})).unwrap();+ assert_eq!(old.edge, Edge::Bottom);+ let bad: NavigationBar = serde_json::from_value(json!({"edge": "sideways"})).unwrap();+ assert_eq!(bad.edge, Edge::Bottom);+ assert!(validate(&json!({"edge": "sideways"})).is_err());+ assert!(validate(&json!({"edge": "top"})).is_ok());+ let canvas = Rect::from_min_size(pos2(20.0, 30.0), vec2(900.0, 600.0));+ for position in [Position::Centre, Position::Left, Position::Right] {+ for edge in [Edge::Bottom, Edge::Top] {+ let prefs: NavigationBar = serde_json::from_value(json!({"position": position, "edge": edge})).unwrap();+ assert_eq!(serde_json::to_value(&prefs).unwrap()["edge"], if edge == Edge::Top { "top" } else { "bottom" });+ let bar = measure(canvas, &prefs, NavCaps::MODEL, |_| 50.0);+ match edge {+ Edge::Bottom => assert_eq!(bar.rect.bottom(), canvas.bottom() - NAV_BOTTOM),+ Edge::Top => assert_eq!(bar.rect.top(), canvas.top() + NAV_BOTTOM),+ }+ for corner in [egui::Vec2::ZERO, vec2(120.0, 32.0)] {+ let layout =+ crate::viewport_layout::Layout::with_content(canvas, canvas, &[], 1.0, crate::prefs::NavigatorStyle::Cube, corner, bar.rect);+ // The axis view keeps its full size: on top, it moves down past the bar instead.+ assert_eq!(layout.axis_view.width(), crate::viewport::axis_view_size(crate::prefs::NavigatorStyle::Cube));+ assert!(!layout.axis_view.intersect(bar.rect).is_positive(), "{position:?} {edge:?}");+ assert!(!layout.confirm.intersect(bar.rect).is_positive(), "{position:?} {edge:?}");+ assert!(!layout.confirm.intersect(layout.axis_view).is_positive(), "{position:?} {edge:?}");+ }+ }+ }+}+#[test]fn navigation_slot_visuals_never_use_focus_as_a_fill() {use crate::ui_kit::{NavigationFill, navigation_visual};diff --git a/crates/ui-egui/src/navigation_bar_view.rs b/crates/ui-egui/src/navigation_bar_view.rsindex 1ad6fa9299..3668ec8a13 100644--- a/crates/ui-egui/src/navigation_bar_view.rs+++ b/crates/ui-egui/src/navigation_bar_view.rs@@ -1,6 +1,6 @@//! Measured single-row navigation bar. Commands own all view changes.use crate::navigation::NavCaps;-use crate::navigation_bar::{self, Idle, Kind, Labels, MenuDisplay, NavigationBar, Position, Slot};+use crate::navigation_bar::{self, Edge, Idle, Kind, Labels, MenuDisplay, NavigationBar, Position, Slot};use crate::theme::Tokens;use crate::ui_kit::{self, Container, Surface};use crate::{SolveApp, viewport::NavMode};@@ -88,7 +88,12 @@ fn measure_row(content: Rect, prefs: &NavigationBar, caps: NavCaps, label_width:Position::Left => content.left() + NAV_EDGE,Position::Right => content.right() - NAV_EDGE - row_width,};- result.rect = Rect::from_min_size(pos2(left, content.bottom() - height - NAV_BOTTOM), vec2(row_width, height));+ // The same gap from either edge of the view.+ let top = match prefs.edge {+ navigation_bar::Edge::Bottom => content.bottom() - height - NAV_BOTTOM,+ navigation_bar::Edge::Top => content.top() + NAV_BOTTOM,+ };+ result.rect = Rect::from_min_size(pos2(left, top), vec2(row_width, height));let mut x = left + inset;for slot in slots.iter().take(visible) {let w = width(slot, result.labels, result.values);@@ -175,7 +180,7 @@ fn activate(app: &mut SolveApp, slot: &Slot) {}}-fn tooltip(app: &SolveApp, response: egui::Response, slot: &Slot, hidden: Option<&str>, top: f32) -> egui::Response {+fn tooltip(app: &SolveApp, response: egui::Response, slot: &Slot, hidden: Option<&str>, along: Rect, edge: Edge) -> egui::Response {let label = if let Some(hidden) = hidden {app.tr(hidden).to_owned()} else if slot.id == "visual_style" {@@ -186,7 +191,7 @@ fn tooltip(app: &SolveApp, response: egui::Response, slot: &Slot, hidden: Optionapp.tr(slot.label).to_owned()};let key = slot.command.and_then(|id| crate::keymap::display_for(app, id));- ui_kit::navigation_tooltip(&response, top, &label, key.as_deref());+ ui_kit::navigation_tooltip(&response, along, edge, &label, key.as_deref());response}@@ -253,7 +258,7 @@ pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect) {menu: false,},);- ui_kit::navigation_tooltip(&response, bar.rect.top(), app.tr("navbar.more"), None);+ ui_kit::navigation_tooltip(&response, bar.rect, app.preferences.navigation_bar.edge, app.tr("navbar.more"), None);crate::scenario::publish_target("nav:more", response.rect);context_menu(app, &response, None);if response.clicked() {@@ -265,12 +270,14 @@ pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect) {if !open.is_empty() && anchor.is_positive() {let child_popup_open = egui::Popup::is_any_open(ui.ctx());let ctx = ui.ctx().clone();- let menu = Container::new(&ctx, Surface::Popup)- .area(menu_id.with("popup"))- .order(egui::Order::Foreground)- .pivot(Align2::RIGHT_BOTTOM)- .fixed_pos(anchor.right_top() - vec2(0.0, ui_kit::NAV_POPUP_GAP))- .show(&ctx, |ui| {+ // Menus open into the view: up from a bar at the bottom, down from one at the top.+ let (pivot, at) = match app.preferences.navigation_bar.edge {+ Edge::Bottom => (Align2::RIGHT_BOTTOM, anchor.right_top() - vec2(0.0, ui_kit::NAV_POPUP_GAP)),+ Edge::Top => (Align2::RIGHT_TOP, anchor.right_bottom() + vec2(0.0, ui_kit::NAV_POPUP_GAP)),+ };+ let menu = Container::new(&ctx, Surface::Popup).area(menu_id.with("popup")).order(egui::Order::Foreground).pivot(pivot).fixed_pos(at).show(+ &ctx,+ |ui| {ui_kit::navigation_menu(ui, if open == "more" { ui_kit::NAV_MORE_WIDTH } else { ui_kit::NAV_POPUP_WIDTH }, |ui| {match open.as_str() {"visual_style" => {@@ -283,7 +290,8 @@ pub(crate) fn show(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect) {_ => open.clear(),}});- });+ },+ );let outside = !child_popup_open&& ui.input(|i| {i.pointer.any_pressed() && i.pointer.interact_pos().is_some_and(|p| !menu.response.rect.contains(p) && !bar.rect.contains(p))@@ -383,7 +391,9 @@ pub(crate) fn paint_row(egui::WidgetInfo::selected(egui::WidgetType::Button, ui.is_enabled(), selected(app, slot.id) || open == slot.id, app.tr(slot.label))});}- responses.push((index, *slot, tooltip(app, response, slot, hidden, bar.rect.top())));+ // The settings' preview keeps its tips above, wherever the bar sits in the view.+ let edge = if editing.is_some() { Edge::Bottom } else { app.preferences.navigation_bar.edge };+ responses.push((index, *slot, tooltip(app, response, slot, hidden, bar.rect, edge)));}responses}@@ -462,7 +472,7 @@ fn overflow_menu(app: &mut SolveApp, ui: &mut egui::Ui, slots: &[&Slot], open: &if slot.id == "display" {crate::scenario::publish_handle("nav:view", response.rect.center());}- if tooltip(app, response.clone(), slot, None, response.rect.top()).clicked() {+ if tooltip(app, response.clone(), slot, None, response.rect, Edge::Bottom).clicked() {if slot.kind == Kind::Menu {*open = slot.id.to_owned();} else {diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rsindex c3b3e51a34..637d61ec8d 100644--- a/crates/ui-egui/src/prefs.rs+++ b/crates/ui-egui/src/prefs.rs@@ -3228,26 +3228,27 @@ pub(crate) fn reveal_preference(h: &mut crate::scenario::Harness, handle: &str)mod tests {#[test]fn navigation_bar_preferences_round_trip_and_recover_hostile_fields() {- use crate::navigation_bar::{Idle, Labels, NavigationBar, Position, Size};+ use crate::navigation_bar::{Edge, Idle, Labels, NavigationBar, Position, Size};use serde_json::json;assert_eq!(super::lenient(&json!({})).navigation_bar, NavigationBar::default());let p = super::lenient(&json!({"navigation_bar": {"slots":["pan", "future_slot", "pan", "separator", "separator", "separator", "separator", "separator", 7, "fit"],- "position":"bottom_left", "size":"regular", "labels":"labels", "idle":"hide"+ "position":"bottom_left", "edge":"top", "size":"regular", "labels":"labels", "idle":"hide"}}));assert_eq!(p.navigation_bar.slots, ["pan", "future_slot", "separator", "separator", "separator", "separator", "fit"]);assert_eq!(- (p.navigation_bar.position, p.navigation_bar.size, p.navigation_bar.labels, p.navigation_bar.idle),- (Position::Left, Size::Regular, Labels::Labels, Idle::Hide)+ (p.navigation_bar.position, p.navigation_bar.edge, p.navigation_bar.size, p.navigation_bar.labels, p.navigation_bar.idle),+ (Position::Left, Edge::Top, Size::Regular, Labels::Labels, Idle::Hide));let saved = serde_json::to_value(&p).unwrap();assert_eq!(serde_json::from_value::<super::Prefs>(saved).unwrap(), p);- for field in ["position", "size", "labels", "idle"] {+ for field in ["position", "edge", "size", "labels", "idle"] {let mut value = serde_json::to_value(&p).unwrap();value["navigation_bar"][field] = json!({"wrong":"type"});let mut expected = p.clone();match field {"position" => expected.navigation_bar.position = Position::default(),+ "edge" => expected.navigation_bar.edge = Edge::default(),"size" => expected.navigation_bar.size = Size::default(),"labels" => expected.navigation_bar.labels = Labels::default(),_ => expected.navigation_bar.idle = Idle::default(),diff --git a/crates/ui-egui/src/prefs/navbar.rs b/crates/ui-egui/src/prefs/navbar.rsindex 573d26bcfa..d68ef6efe4 100644--- a/crates/ui-egui/src/prefs/navbar.rs+++ b/crates/ui-egui/src/prefs/navbar.rs@@ -1,6 +1,6 @@//! Navigation bar editor. The shared viewport painter owns the preview's appearance.use crate::navigation::NavCaps;-use crate::navigation_bar::{self, Idle, Kind, Labels, MenuDisplay, NavigationBar, Position, Size, SlotOptions};+use crate::navigation_bar::{self, Edge, Idle, Kind, Labels, MenuDisplay, NavigationBar, Position, Size, SlotOptions};use crate::navigation_bar_view;use crate::{SolveApp, scenario, theme::Tokens, ui_kit};use egui::{Rect, Sense, vec2};@@ -379,6 +379,9 @@ fn appearance(app: &mut SolveApp, ui: &mut egui::Ui) {}},);+ segments(ui, "edge", &mut usize::from(bar.edge == Edge::Top), &["navbar.custom.edge_bottom", "navbar.custom.edge_top"], |i| {+ bar.edge = if i == 1 { Edge::Top } else { Edge::Bottom }+ });segments(ui, "size", &mut usize::from(bar.size == Size::Regular), &["navbar.custom.compact", "navbar.custom.regular"], |i| {bar.size = if i == 1 { Size::Regular } else { Size::Compact }});diff --git a/crates/ui-egui/src/ui_kit/navigation_menu.rs b/crates/ui-egui/src/ui_kit/navigation_menu.rsindex e4bfc322ca..1fb5ca6c11 100644--- a/crates/ui-egui/src/ui_kit/navigation_menu.rs+++ b/crates/ui-egui/src/ui_kit/navigation_menu.rs@@ -1,6 +1,6 @@//! Popup and tooltip skin from the approved navigation boards.use super::{Container, Surface, navigation::*};-use crate::{icons, theme::Tokens};+use crate::{icons, navigation_bar::Edge, theme::Tokens};use egui::{Align2, FontId, Rect, Response, Sense, Ui, pos2, vec2};pub(crate) fn navigation_popup_frame() -> egui::Frame {@@ -107,7 +107,9 @@ pub(crate) fn navigation_menu_separator(ui: &mut Ui) {ui.painter().hline(rect.shrink2(vec2(t.space_2, 0.0)).x_range(), rect.center().y, egui::Stroke::new(NAV_BORDER, t.dialog_rule));}-pub(crate) fn navigation_tooltip(response: &Response, top: f32, label: &str, shortcut: Option<&str>) {+/// A tip beyond `along` (the bar, or the row it names): above it, or below it for a bar on the+/// view's top edge.+pub(crate) fn navigation_tooltip(response: &Response, along: Rect, edge: Edge, label: &str, shortcut: Option<&str>) {let ctx = &response.ctx;let id = response.id.with("nav_tooltip_delay");if !response.hovered() {@@ -127,8 +129,11 @@ pub(crate) fn navigation_tooltip(response: &Response, top: f32, label: &str, sho.area(response.id.with("nav_tooltip")).order(egui::Order::Tooltip).interactable(false)- .pivot(Align2::CENTER_BOTTOM)- .fixed_pos(pos2(response.rect.center().x, top - NAV_POPUP_GAP))+ .pivot(if edge == Edge::Top { Align2::CENTER_TOP } else { Align2::CENTER_BOTTOM })+ .fixed_pos(match edge {+ Edge::Bottom => pos2(response.rect.center().x, along.top() - NAV_POPUP_GAP),+ Edge::Top => pos2(response.rect.center().x, along.bottom() + NAV_POPUP_GAP),+ }).show(ctx, |ui| {Container::new(ctx, Surface::Popup).show_frame(ui, frame, ui.max_rect(), |ui| {ui.spacing_mut().item_spacing.x = t.space_8;diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rsindex 39505d09ce..75739ba8ae 100644--- a/crates/ui-egui/src/viewport.rs+++ b/crates/ui-egui/src/viewport.rs@@ -4867,7 +4867,13 @@ fn agent_chip(app: &mut SolveApp, ui: &egui::Ui, view: Rect, taken: &[Rect]) ->let galley = painter.layout_no_wrap(format!("{label} · {computing}"), FontId::proportional(t.font_label), t.text);let stop = painter.layout_no_wrap(crate::i18n::tr("ui.agent_chat_stop").to_string(), FontId::proportional(t.font_label), t.text);let size = vec2(galley.size().x + stop.size().x + 54.0, galley.size().y.max(stop.size().y) + 8.0);- let nav = app.viewport.layout.as_ref().map(|l| l.navigation).filter(|n| n.is_positive() && n.is_finite());+ // Above the navigation bar while it sits on the bottom edge; a bar on top leaves the bottom free.+ let nav = app+ .viewport+ .layout+ .as_ref()+ .map(|l| l.navigation)+ .filter(|n| n.is_positive() && n.is_finite() && app.preferences.navigation_bar.edge == crate::navigation_bar::Edge::Bottom);let (x, bottom) = nav.map_or((view.center().x, view.bottom() - t.space_8), |n| (n.center().x, n.top() - t.space_8));let x = x.clamp(view.left() + size.x * 0.5, (view.right() - size.x * 0.5).max(view.left() + size.x * 0.5));let mut r = Rect::from_min_size(pos2(x - size.x * 0.5, bottom - size.y), size);diff --git a/crates/ui-egui/src/viewport_layout.rs b/crates/ui-egui/src/viewport_layout.rsindex 59236e8c07..4ce015ef88 100644--- a/crates/ui-egui/src/viewport_layout.rs+++ b/crates/ui-egui/src/viewport_layout.rs@@ -117,12 +117,23 @@ impl Layout {} else {Rect::NOTHING};+ // A navigation bar on the view's top edge (#8183) keeps the pair and the axis view below it.+ let bar_on_top = navigation.is_positive() && navigation.center().y < available.center().y;+ let below_bar = |rect: Rect| {+ if bar_on_top && rect.intersect(navigation).is_positive() {+ rect.translate(vec2(0.0, navigation.bottom() + CORNER_GAP - rect.top()))+ } else {+ rect+ }+ };+ let confirm = below_bar(confirm);// The axis view starts below the pair while it is shown.let top = if confirm.is_positive() { confirm.bottom() + CORNER_GAP } else { available.top() };let cube_size = if fit_in_content { 110.0 } else { super::viewport::axis_view_size(style) };let axis_left = |size| {if inspector_side == Some(crate::frame::Side::Left) { available.left() } else { available.right() - size }};+ let top = below_bar(Rect::from_min_size(pos2(axis_left(cube_size), top), vec2(cube_size, cube_size))).top();let mut axis_view = if available.width() >= cube_size && available.bottom() - top >= cube_size {Rect::from_min_size(pos2(axis_left(cube_size), top), vec2(cube_size, cube_size))} else {