View: OK and Cancel in the corner of the view while a dialog or sketch is open (#6709) (#6714)

* claim: #6709

* feat(view): OK and Cancel in the corner of the view while a dialog or sketch is open (#6709)
This commit is contained in:
Lars Jansen
2026-10-26 10:40:36 +00:00
committed by GitHub
parent ffbcdc614c
commit 4a0d519727
16 changed files with 469 additions and 26 deletions
@@ -0,0 +1,18 @@
{
"en": {
"prefs.view_confirm_corner": "OK and Cancel in the view's corner",
"prefs.view_confirm_corner_note": "While a dialog or a sketch is open, a check and a cross at the top right of the view do what the dialog's OK and Cancel do, or finish and cancel the sketch. The view navigator moves down below them."
},
"ja": {
"prefs.view_confirm_corner": "ビューの隅に OK とキャンセル",
"prefs.view_confirm_corner_note": "ダイアログまたはスケッチを開いている間、ビュー右上のチェックとバツが、ダイアログの OK とキャンセルと同じ操作を行うか、スケッチを終了またはキャンセルします。ビューナビゲーターはその下に移動します。"
},
"ko": {
"prefs.view_confirm_corner": "뷰 모서리에 확인 및 취소",
"prefs.view_confirm_corner_note": "대화 상자나 스케치가 열려 있는 동안 뷰 오른쪽 위의 체크와 X 표시가 대화 상자의 확인과 취소와 같은 동작을 하거나 스케치를 마치고 취소합니다. 뷰 탐색기는 그 아래로 내려갑니다."
},
"zh": {
"prefs.view_confirm_corner": "在视图角落显示确定和取消",
"prefs.view_confirm_corner_note": "打开对话框或草图时,视图右上角的勾号和叉号与对话框的确定和取消作用相同,或完成和取消草图。视图导航器会下移到它们下方。"
}
}
+36 -8
View File
@@ -2502,10 +2502,31 @@ pub(crate) fn sync_feature_edit_sketch(app: &mut SolveApp) {
});
}
/// A dialog's primary and closing actions. Measure only closes; a deletion's primary action
/// says what it does.
pub(crate) fn action_labels(kind: &Kind) -> (&'static str, &'static str) {
match kind {
Kind::Measure { .. } => ("", "Close"),
Kind::ConfirmDelete { .. } => ("Delete", "Cancel"),
Kind::SaveMesh(k) => (crate::dialogs_save_mesh::button(k), "Cancel"),
Kind::ViewDxf { .. } => ("Export DXF…", "Cancel"),
_ => ("OK", "Cancel"),
}
}
/// Whether OK and Cancel in the view's corner act on the dialog (#6709): every docked dialog;
/// a deletion asks in a modal card of its own, which the corner must not answer.
pub(crate) fn corner_confirms(d: &Dialog) -> bool {
!matches!(d.kind, Kind::ConfirmDelete { .. })
}
/// Show the active dialog (if any), docked flush to an edge of the viewport just below the axis
/// view, sized to its content. The right edge is its place, except while a sketch is open: the
/// Sketch Palette keeps the right there, and the dialog takes the left so both stay on screen.
pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
// A click in the view's corner is for the dialog open this frame, or for none.
let corner = app.viewport.corner.take();
app.viewport.corner_ok = false;
sync_feature_edit_sketch(app);
if app.tree.redefine.is_none() {
app.viewport.dialog_rect = None;
@@ -2596,14 +2617,9 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
}
_ => !has_ok || !d.previews() || (built.unwrap_or_else(|| apply_commands(app, &d).is_ok()) && app.preview.error.is_none()),
};
// Measure only closes; a deletion's primary action says what it does.
let (ok_label, close_label) = match &d.kind {
Kind::Measure { .. } => ("", "Close"),
Kind::ConfirmDelete { .. } => ("Delete", "Cancel"),
Kind::SaveMesh(k) => (crate::dialogs_save_mesh::button(k), "Cancel"),
Kind::ViewDxf { .. } => ("Export DXF…", "Cancel"),
_ => ("OK", "Cancel"),
};
let (ok_label, close_label) = action_labels(&d.kind);
// What the footer's OK takes, for the check in the view's corner too (#6709).
let ok_enabled = valid && !ok_label.is_empty() && app.applying.is_none();
let panel = crate::ui_kit::Panel::new(&heading, egui::Id::new(("sc_dialog", title(&d.kind))), anchor, drag_bounds, side, frame)
.actions(ok_label, close_label);
let panel = if matches!(d.kind, Kind::Appearance(_) | Kind::Material { .. }) {
@@ -2707,6 +2723,18 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
}
});
app.viewport.dialog_rect = response.map(|r| r.response.rect);
// OK and Cancel in the view's corner do what the dialog's own do (#6709).
if app.issue_report.draft.is_none() {
match corner {
Some(crate::ui_kit::Action::Ok) if ok_enabled => {
ok = true;
apply_again = false;
}
Some(crate::ui_kit::Action::Cancel) => cancel = true,
_ => {}
}
}
app.viewport.corner_ok = ok_enabled;
}
if let Some(r) = app.viewport.dialog_rect {
crate::scenario::publish_rect("dialog:outer", r);
+47
View File
@@ -448,6 +448,53 @@ fn remaining_dialogs_keep_kit_chrome_and_cancel_restores_preview() {
}
}
/// OK and Cancel in the view's corner (#6709) do what the dialog's own do: the check applies and
/// closes, the cross cancels without a change, and the check is grey (and does nothing) whenever
/// the dialog's OK is.
#[test]
fn view_corner_ok_and_cancel_answer_the_dialog_like_its_own_buttons() {
for how in ["ok", "cancel"] {
let mut h = fixture();
h.call("ui.resize", json!({"width":1600,"height":1200}));
h.call("ui.prefs", json!({"view_confirm_corner": true}));
h.app.dialog = Some(representative(&h, "solid.revolve"));
h.settle();
assert_eq!(scenario::count_of("view:confirm:ok:enabled"), scenario::count_of("dialog:ok:enabled"));
assert_eq!(scenario::count_of("view:confirm:ok:enabled"), Some(1.0));
let (design, bodies) = (h.app.session.doc.to_json(), h.app.session.world_state().bodies.len());
h.step(&json!({"click":{"handle":format!("view:confirm:{how}")}})).unwrap();
h.settle();
assert!(h.app.dialog.is_none(), "{how}: the dialog closes");
if how == "ok" {
assert_eq!(h.app.session.world_state().bodies.len(), bodies + 1, "the check made the revolve");
} else {
assert_eq!(h.app.session.doc.to_json(), design, "the cross leaves the design as it was");
}
assert!(scenario::rect_of("view:confirm").is_none(), "{how}: no dialog and no sketch, no pair");
}
// A dialog whose OK is grey: so is the check, and clicking it changes nothing.
let mut h = fixture();
h.call("ui.resize", json!({"width":1600,"height":1200}));
h.call("ui.prefs", json!({"view_confirm_corner": true}));
h.app.start("solid.shell");
h.settle();
assert_eq!(scenario::count_of("dialog:ok:enabled"), Some(0.0));
assert_eq!(scenario::count_of("view:confirm:ok:enabled"), Some(0.0));
let design = h.app.session.doc.to_json();
h.step(&json!({"click":{"handle":"view:confirm:ok"}})).unwrap();
h.settle();
assert!(h.app.dialog.is_some(), "a grey check does nothing");
assert_eq!(h.app.session.doc.to_json(), design);
// Measure only closes: its check stays grey and the cross is its Close.
h.app.start("inspect.measure");
h.settle();
assert_eq!(scenario::count_of("view:confirm:ok:enabled"), Some(0.0));
h.step(&json!({"click":{"handle":"view:confirm:cancel"}})).unwrap();
h.settle();
assert!(h.app.dialog.is_none(), "the cross closes Measure");
}
fn resized_box_editor(command: &str, params: Value) -> (Harness, u64) {
let mut h = Harness::new();
for (id, params) in [
+3
View File
@@ -264,6 +264,7 @@ pub mod ui_kit;
mod ui_kit_guard_tests;
pub mod update;
mod value_step;
mod view_confirm;
pub mod view_pick;
pub mod viewport;
mod viewport_layout;
@@ -2002,6 +2003,8 @@ impl SolveApp {
self.show_workspace(ui);
}
});
// Before the dialog: a click on the view's OK or Cancel is for this frame's dialog.
view_confirm::show(self, ui.ctx());
dialogs::show(self, ui.ctx());
issue_report::CadInput::block(self, ui, report_input);
sketch_palette::show(self, ui.ctx());
+4
View File
@@ -566,6 +566,9 @@ 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(), PAGE_INTERFACE;
/// While a dialog or a sketch is open, OK and Cancel in the view's top right corner, with the
/// axis view moved down below them (#6709). Off by default.
view_confirm_corner: bool = false, PAGE_INTERFACE => check_id("prefs.view_confirm_corner");
/// Put the feature history to the left of the browser instead of below the viewport.
timeline_left: bool = false, PAGE_INTERFACE;
/// Measured outer width; the contents react to this width without a names mode.
@@ -3291,6 +3294,7 @@ mod tests {
("browser_float", json!(true), PAGE_INTERFACE),
("color_vision", json!("protan"), PAGE_INTERFACE),
("viewport_theme", json!("light"), PAGE_INTERFACE),
("view_confirm_corner", json!(true), PAGE_INTERFACE),
("nav", json!("blender"), PAGE_NAVIGATION),
("look_at_anim", json!(false), PAGE_NAVIGATION),
("selection_shift_add_only", json!(true), PAGE_SKETCH),
+5
View File
@@ -71,6 +71,11 @@ pub(super) fn interface(app: &mut SolveApp, ui: &mut egui::Ui, t: &Tokens) {
}
});
});
// Where a dialog's and a sketch's OK and Cancel also sit (#6709).
ui_kit::row(ui, "", |ui| {
let check = setting::view_confirm_corner(app, ui).on_hover_text(app.tr("prefs.view_confirm_corner_note"));
crate::scenario::publish_target("prefs:view_confirm_corner", check.rect);
});
ui_kit::text(ui, app.tr("prefs.layout_note"), ui_kit::Text::Hint("layout"));
ui_kit::LayoutPreview {
compact: app.ui.layout == crate::shell::LayoutMode::Docked,
+1
View File
@@ -122,6 +122,7 @@ pub(crate) fn covered_rects(app: &SolveApp) -> Vec<Rect> {
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()));
rects.extend(crate::view_confirm::rect(app));
rects.retain(|r| r.is_finite() && r.is_positive());
rects
}
+76
View File
@@ -162,3 +162,79 @@ mod exit_keeps_view {
assert!(app.cam_anim.is_none(), "no animation back");
}
}
/// OK and Cancel in the view's corner (#6709): in a sketch without a dialog, the check is Finish
/// Sketch and the cross Cancel Sketch, as on the ribbon; with a dialog open in the sketch, the pair
/// answers the dialog and the sketch stays open.
mod view_corner {
use crate::scenario::{self, Harness};
use serde_json::json;
fn sketching() -> Harness {
let mut h = Harness::new();
h.call("ui.prefs", json!({"view_confirm_corner": true}));
h.step(&json!({"start": "sketch.create"})).unwrap();
h.step(&json!({"click": {"plane": "XY"}})).unwrap();
h.app.run("sketch.line", json!({"points": [[0, 0], [30, 10]]})).unwrap();
h.settle();
assert!(h.app.session.active_sketch.is_some());
h
}
#[test]
fn the_check_finishes_and_the_cross_cancels_the_sketch() {
let mut h = sketching();
assert!(scenario::rect_of("view:confirm").is_some(), "the pair while a sketch is open");
assert_eq!(scenario::count_of("view:confirm:ok:enabled"), Some(1.0));
h.step(&json!({"click": {"handle": "view:confirm:ok"}})).unwrap();
h.settle();
assert_eq!(h.app.session.active_sketch, None, "finished");
assert_eq!(h.app.session.doc.features.len(), 1, "the sketch is kept");
assert!(scenario::rect_of("view:confirm").is_none());
let mut h = sketching();
h.step(&json!({"click": {"handle": "view:confirm:cancel"}})).unwrap();
h.settle();
assert_eq!(h.app.session.active_sketch, None, "cancelled");
assert!(h.app.session.doc.features.is_empty(), "a new sketch goes with what was drawn in it");
}
#[test]
fn a_refused_cancel_shows_its_error_and_keeps_the_sketch() {
let mut h = Harness::new();
h.call("ui.prefs", json!({"view_confirm_corner": true}));
for (command, params) in [
("sketch.create", json!({"plane": "XY", "name": "S"})),
("sketch.line", json!({"points": [[0, 0], [10, 0]]})),
("sketch.finish", json!({})),
("sketch.edit", json!({"sketch": "S"})),
("sketch.line", json!({"points": [[0, 5], [10, 5]]})),
("edit.undo", json!({})),
("edit.undo", json!({})),
] {
h.app.run(command, params).unwrap();
}
h.settle();
let design = h.app.session.doc.to_json();
h.step(&json!({"click": {"handle": "view:confirm:cancel"}})).unwrap();
h.settle();
assert!(h.app.session.active_sketch.is_some(), "the refused cancel leaves the sketch open");
assert_eq!(h.app.session.doc.to_json(), design);
let (message, _, error) = h.app.status.clone().expect("the refusal is shown");
assert!(error && message.contains("Undo"), "{message}");
}
#[test]
fn a_dialog_in_the_sketch_takes_the_pair() {
let mut h = sketching();
h.app.start("sketch.offset");
h.settle();
assert!(h.app.dialog.is_some());
assert_eq!(scenario::count_of("view:confirm:ok:enabled"), scenario::count_of("dialog:ok:enabled"));
h.step(&json!({"click": {"handle": "view:confirm:cancel"}})).unwrap();
h.settle();
assert!(h.app.dialog.is_none(), "the cross cancels the dialog");
assert!(h.app.session.active_sketch.is_some(), "and leaves the sketch open");
assert!(scenario::rect_of("view:confirm").is_some(), "the pair answers the sketch again");
}
}
+122
View File
@@ -0,0 +1,122 @@
//! OK and Cancel in the view's corner (Preferences › Interface, #6709). While a dialog is open,
//! a check and a cross at the top right of the view do what the dialog's own OK and Cancel do,
//! and the check greys out whenever the dialog's OK does. While a sketch is open without a
//! dialog, they are Finish Sketch and Cancel Sketch, as on the ribbon. The axis view moves down
//! below the pair while it is shown (`viewport_layout::Layout::with_content`), and the pair is
//! one of the shell's covered rects, so a click on it never picks or navigates.
use egui::{Rect, Sense, vec2};
use crate::SolveApp;
use crate::theme::Tokens;
use crate::ui_kit::{Action, Container, Surface};
/// Each target's side: large enough to hit without aiming.
const TARGET: f32 = 40.0;
/// What the pair answers.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum Answers {
/// The open dialog's OK and Cancel (also inside a sketch).
Dialog,
/// Finish Sketch and Cancel Sketch.
Sketch,
}
fn answers(app: &SolveApp) -> Option<Answers> {
if !app.preferences.view_confirm_corner || app.home.open || crate::render_workspace::active(app) {
return None;
}
match &app.dialog {
Some(dialog) => crate::dialogs::corner_confirms(dialog).then_some(Answers::Dialog),
None => app.session.active_sketch.is_some().then_some(Answers::Sketch),
}
}
/// The pair's size while it is shown, else zero: the view's layout keeps the corner for it.
pub(crate) fn size(app: &SolveApp) -> egui::Vec2 {
if answers(app).is_none() {
return egui::Vec2::ZERO;
}
let t = Tokens::get();
vec2(TARGET * 2.0 + t.space_4 * 3.0, TARGET + t.space_4 * 2.0)
}
/// Where the pair is while it is shown.
pub(crate) fn rect(app: &SolveApp) -> Option<Rect> {
answers(app)?;
app.viewport.layout.as_ref().map(|layout| layout.confirm).filter(|r| r.is_finite() && r.is_positive())
}
/// One of the pair: what it answers, where, its icon, the action its tooltip names and whether
/// it can be clicked.
struct Choice {
action: Action,
key: &'static str,
icon: &'static str,
label: &'static str,
enabled: bool,
}
/// Draws the pair and answers a click. A dialog's answer waits for `dialogs::show` in this frame
/// (`ViewportState::corner`), which acts on it as on its own OK and Cancel; a sketch's runs at
/// once, the way the ribbon's Finish Sketch and Cancel do (a refusal shows as their errors do).
pub(crate) fn show(app: &mut SolveApp, ctx: &egui::Context) {
let (Some(answers), Some(rect)) = (answers(app), rect(app)) else { return };
let choices = match answers {
Answers::Dialog => {
let (ok, cancel) = app.dialog.as_ref().map_or(("OK", "Cancel"), |dialog| crate::dialogs::action_labels(&dialog.kind));
[
Choice {
action: Action::Ok,
key: "view:confirm:ok",
icon: "finish",
label: if ok.is_empty() { "OK" } else { ok },
enabled: app.viewport.corner_ok,
},
Choice { action: Action::Cancel, key: "view:confirm:cancel", icon: "close", label: cancel, enabled: true },
]
}
Answers::Sketch => {
let command = |id: &str| solidcraft_engine::find_command(id).map(|spec| (spec.label, spec.info(&app.session).enabled));
let (finish, finish_enabled) = command("sketch.finish").unwrap_or(("Finish Sketch", false));
let (cancel, cancel_enabled) = command("sketch.cancel").unwrap_or(("Cancel Sketch", false));
[
Choice { action: Action::Ok, key: "view:confirm:ok", icon: "finish", label: finish, enabled: finish_enabled },
Choice { action: Action::Cancel, key: "view:confirm:cancel", icon: "sketch_cancel", label: cancel, enabled: cancel_enabled },
]
}
};
let t = Tokens::get();
let container = Container::new(ctx, Surface::Navigation);
let frame = container.frame(ctx, t.overlay, crate::frame::Side::Right);
let mut clicked = None;
container.area(egui::Id::new("sc_view_confirm")).order(egui::Order::Middle).fixed_pos(rect.min).fade_in(false).show(ctx, |ui| {
let (outer, _) = ui.allocate_exact_size(rect.size(), Sense::hover());
Container::paint_frame(ui.painter(), frame, outer.shrink(frame.stroke.width));
// The check, then the cross in the very corner, where a close sits on a title bar.
for (index, choice) in choices.iter().enumerate() {
let at = Rect::from_min_size(outer.min + vec2(t.space_4 + index as f32 * (TARGET + t.space_4), t.space_4), vec2(TARGET, TARGET));
let response = ui.interact(at, ui.id().with(choice.key), if choice.enabled { Sense::click() } else { Sense::hover() });
if choice.enabled && response.hovered() {
ui.painter().rect_filled(at, t.radius_sm, t.hover);
ui.ctx().set_cursor_icon(egui::CursorIcon::PointingHand);
}
crate::icons::paint_icon(ui.painter(), at.shrink(t.space_6), choice.icon, if choice.enabled { 1.0 } else { 0.35 });
let label = crate::i18n::tr_label(choice.label);
response.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, choice.enabled, label));
crate::scenario::publish_target(choice.key, at);
if response.on_hover_text(label).clicked() && choice.enabled {
clicked = Some(choice.action);
}
}
});
crate::scenario::publish_rect("view:confirm", rect);
crate::scenario::publish_count("view:confirm:ok:enabled", f64::from(choices.first().is_some_and(|choice| choice.enabled)));
match (answers, clicked) {
(Answers::Dialog, Some(action)) => app.viewport.corner = Some(action),
(Answers::Sketch, Some(Action::Ok)) => app.start_pinned("sketch.finish", None),
(Answers::Sketch, Some(Action::Cancel)) => app.start_pinned("sketch.cancel", None),
_ => {}
}
}
+11 -5
View File
@@ -98,6 +98,12 @@ pub struct ViewportState {
pub(crate) layout: Option<crate::viewport_layout::Layout>,
pub(crate) palette_rect: Option<Rect>,
pub(crate) dialog_rect: Option<Rect>,
/// OK or Cancel clicked in the view's corner for the open dialog (#6709), which
/// `dialogs::show` acts on in the same frame as its own buttons.
pub(crate) corner: Option<crate::ui_kit::Action>,
/// Whether the open dialog's OK was enabled when it was last drawn: the corner's check
/// greys out with it.
pub(crate) corner_ok: bool,
pub gpu: Option<GpuTarget>,
/// What the GPU drew last frame, shared with the renderer (the frame-rate details, #2548).
pub(crate) draw_stats: Option<crate::gpu::DrawStatsHandle>,
@@ -4775,11 +4781,11 @@ pub(crate) fn refresh_layout(app: &mut SolveApp, scale: f32) {
content.max.x = (chat.left() - crate::shell::SHELL_GAP).clamp(content.left(), content.right());
}
}
app.viewport.layout = Some(if app.ui.layout == crate::shell::LayoutMode::Docked {
crate::viewport_layout::Layout::new(rect, &docks, scale, app.preferences.navigator_style)
} else {
crate::viewport_layout::Layout::with_content(rect, content, &docks, scale, app.preferences.navigator_style)
});
// OK and Cancel in the view's corner (#6709) take the top right; the axis view goes below.
let corner = crate::view_confirm::size(app);
let content = if app.ui.layout == crate::shell::LayoutMode::Docked { rect } else { content };
app.viewport.layout =
Some(crate::viewport_layout::Layout::with_content(rect, content, &docks, scale, app.preferences.navigator_style, corner));
}
}
+34 -12
View File
@@ -10,8 +10,15 @@ pub(crate) struct Layout {
pub content: Rect,
pub axis_view: Rect,
pub navigation: Rect,
/// OK and Cancel in the view's corner (#6709), or nothing while they are not shown.
pub confirm: Rect,
}
/// How far the OK and Cancel pair sits in from the content's top right corner, and the space
/// between it and the axis view moved down below it.
const CORNER_INSET: f32 = 8.0;
const CORNER_GAP: f32 = 4.0;
/// Enumerate rectangles whose edges meet the viewport or a bounded number of overlays.
pub(crate) fn free_rect(view: Rect, obstacles: &[Rect]) -> Rect {
if !view.is_finite() || !view.is_positive() {
@@ -43,18 +50,34 @@ pub(crate) fn free_rect(view: Rect, obstacles: &[Rect]) -> Rect {
}
impl Layout {
/// The whole viewport as content, without the OK and Cancel pair.
#[cfg(test)]
pub fn new(viewport: Rect, docks: &[Rect], scale: f32, style: crate::prefs::NavigatorStyle) -> Self {
Self::with_content(viewport, viewport, docks, scale, style)
Self::with_content(viewport, viewport, docks, scale, style, egui::Vec2::ZERO)
}
pub fn with_content(viewport: Rect, content: Rect, docks: &[Rect], scale: f32, style: crate::prefs::NavigatorStyle) -> Self {
/// `corner` is the size of the OK and Cancel pair (#6709; zero while it is not shown): it is
/// held in the top right corner of the content, and the axis view moves down below it.
pub fn with_content(viewport: Rect, content: Rect, docks: &[Rect], scale: f32, style: crate::prefs::NavigatorStyle, corner: egui::Vec2) -> Self {
let scale = if scale.is_finite() && scale > 0.0 { scale } else { 1.0 };
let mut obstacles: Vec<_> = docks.iter().take(14).copied().filter(|r| r.is_finite()).map(|r| r.expand(4.0)).collect();
// Navigation is anchored to the viewport, never to transient dialog space.
let available = content;
let confirm = if corner.is_finite()
&& corner.x > 0.0
&& corner.y > 0.0
&& available.width() >= corner.x + CORNER_INSET
&& available.height() >= corner.y + CORNER_INSET
{
Rect::from_min_size(pos2(available.right() - CORNER_INSET - corner.x, available.top() + CORNER_INSET), corner)
} else {
Rect::NOTHING
};
// 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 = super::viewport::axis_view_size(style);
let mut axis_view = if available.width() >= cube_size && available.height() >= cube_size {
Rect::from_min_size(pos2(available.right() - cube_size, available.top()), vec2(cube_size, cube_size))
let mut axis_view = if available.width() >= cube_size && available.bottom() - top >= cube_size {
Rect::from_min_size(pos2(available.right() - cube_size, top), vec2(cube_size, cube_size))
} else {
Rect::NOTHING
};
@@ -69,21 +92,20 @@ impl Layout {
// On tiny viewports keep the bottom controls usable rather than overlapping them.
// This decision depends only on viewport size, never on an overlay.
if axis_view.intersect(navigation).is_positive() {
let compact = (navigation.top() - content.top() - 4.0).min(cube_size);
let compact = (navigation.top() - top - 4.0).min(cube_size);
axis_view = if style == crate::prefs::NavigatorStyle::Cube && compact >= 96.0 {
Rect::from_min_size(pos2(content.right() - compact, content.top()), vec2(compact, compact))
Rect::from_min_size(pos2(content.right() - compact, top), vec2(compact, compact))
} else {
Rect::NOTHING
};
}
if axis_view.is_positive() {
obstacles.push(axis_view);
}
if navigation.is_positive() {
obstacles.push(navigation);
for control in [axis_view, navigation, confirm] {
if control.is_positive() {
obstacles.push(control);
}
}
let drawable = free_rect(viewport, &obstacles).shrink(16.0 / scale);
Self { viewport, drawable, content, axis_view, navigation }
Self { viewport, drawable, content, axis_view, navigation, confirm }
}
}
@@ -309,6 +309,81 @@ fn opening_different_command_dialogs_keeps_published_navigation_positions() {
}
}
/// OK and Cancel in the view's corner (#6709): the pair holds the content's top right corner and
/// the axis view or cube moves down below it, clear of the pair and the navigation bar; without
/// the pair (or without room for it) nothing moves.
#[test]
fn the_corner_pair_takes_the_top_right_and_the_view_navigator_moves_below_it() {
let corner = vec2(92.0, 48.0);
for style in [crate::prefs::NavigatorStyle::Axes, crate::prefs::NavigatorStyle::Cube] {
for (width, height) in [(1400.0, 900.0), (700.0, 450.0), (310.0, 240.0), (160.0, 160.0), (90.0, 50.0)] {
let vp = Rect::from_min_size(pos2(20.0, 30.0), vec2(width, height));
let content = Rect::from_min_max(pos2(vp.left() + width * 0.25, vp.top()), vp.max);
let plain = Layout::with_content(vp, content, &[], 1.0, style, egui::Vec2::ZERO);
let held = Layout::with_content(vp, content, &[], 1.0, style, corner);
assert!(!plain.confirm.is_positive(), "{plain:?}");
assert_eq!(held.navigation, plain.navigation, "the navigation bar never moves");
assert!(!held.axis_view.intersect(held.navigation).is_positive(), "{held:?}");
if !held.confirm.is_positive() {
assert_eq!(held.axis_view, plain.axis_view, "no room for the pair: {held:?}");
continue;
}
assert_eq!(held.confirm.size(), corner);
assert!(content.contains_rect(held.confirm), "{held:?}");
assert_eq!((held.confirm.right(), held.confirm.top()), (content.right() - 8.0, content.top() + 8.0));
assert!(!held.drawable.intersect(held.confirm).is_positive(), "fit keeps the model clear of it");
if held.axis_view.is_positive() {
assert!(held.axis_view.top() >= held.confirm.bottom(), "{style:?} {width}x{height}: {held:?}");
assert_eq!(held.axis_view.right(), content.right());
assert!(content.contains_rect(held.axis_view));
}
}
}
let roomy = Layout::with_content(
Rect::from_min_size(pos2(0.0, 0.0), vec2(1400.0, 900.0)),
Rect::from_min_size(pos2(0.0, 0.0), vec2(1400.0, 900.0)),
&[],
1.0,
crate::prefs::NavigatorStyle::Axes,
corner,
);
assert!(roomy.confirm.is_positive() && roomy.axis_view.is_positive(), "{roomy:?}");
}
/// The pair in the running app: shown only with the preference and while a dialog is open, the
/// axis view below it, and the pointer over it reaching neither picking nor navigation.
#[test]
fn the_corner_pair_follows_the_dialog_and_keeps_the_pointer_from_the_model() {
for mode in [crate::shell::LayoutMode::Floating, crate::shell::LayoutMode::Docked] {
let mut h = Harness::new();
h.call("ui.set", json!({"layout":mode}));
h.app.run("solid.box", json!({"length":40,"width":30,"height":20})).unwrap();
h.settle();
let axis = crate::scenario::rect_of("axis_view:outer").unwrap();
h.app.start("solid.fillet");
h.settle();
assert!(crate::scenario::rect_of("view:confirm").is_none(), "off by default");
assert_eq!(crate::scenario::rect_of("axis_view:outer"), Some(axis));
h.call("ui.prefs", json!({"view_confirm_corner": true}));
h.settle();
let pair = crate::scenario::rect_of("view:confirm").expect("the pair while a dialog is open");
let moved = crate::scenario::rect_of("axis_view:outer").unwrap();
assert!(moved.top() >= pair.bottom() && moved.right() == axis.right(), "{mode:?}: {moved:?} below {pair:?}");
assert!(crate::shell::covered(&h.app, pair.center()), "one of the shell's covered rects");
let dialog = h.app.viewport.dialog_rect.unwrap();
assert!(!dialog.intersects(pair), "{mode:?}: {dialog:?} / {pair:?}");
let (ok, cancel) = (crate::scenario::rect_of("view:confirm:ok").unwrap(), crate::scenario::rect_of("view:confirm:cancel").unwrap());
assert!(pair.contains_rect(ok) && pair.contains_rect(cancel) && ok.right() < cancel.left(), "the check, then the cross in the corner");
assert!(ok.width() >= 40.0 && ok.height() >= 40.0, "large enough to hit easily");
h.step(&json!({"move":[pair.center().x, pair.center().y]})).unwrap();
assert_eq!(h.app.viewport.mouse, None, "{mode:?}: the model under the pair never sees the pointer");
h.app.dialog = None;
h.settle();
assert!(crate::scenario::rect_of("view:confirm").is_none(), "gone with the dialog");
assert_eq!(crate::scenario::rect_of("axis_view:outer"), Some(axis), "{mode:?}: the axis view returns");
}
}
#[test]
fn tiny_viewports_never_overlap_navigation_and_axis_view() {
for width in [39.0, 40.0, 90.0, 120.0, 160.0, 310.0] {
@@ -0,0 +1,31 @@
[
{"note": "Interface › OK and Cancel in the view's corner (#6709): a check and a cross at the view's top right. In a sketch they are Finish Sketch and Cancel Sketch; with a dialog open they are its OK and Cancel."},
{"call": "ui.prefs", "params": {"view_confirm_corner": true}},
{"start": "sketch.create"},
{"click": {"plane": "XY"}},
{"expect": {"sketching": true}},
{"start": "sketch.rectangle.two_point"},
{"click": {"sketch": [0, 0]}},
{"click": {"sketch": [40, 30]}},
{"key": "Escape"},
{"expect": {"sketch_curves": {"own": 4}, "handle_order": ["view:confirm:ok", "view:confirm:cancel"]}},
{"note": "The check finishes the sketch."},
{"click": {"handle": "view:confirm:ok"}},
{"expect": {"sketching": false, "features": 1, "errors": 0}},
{"note": "Extrude picks the sketch's one profile; the check is its OK."},
{"start": "solid.extrude"},
{"frames": 4},
{"expect": {"dialog": "Extrude", "bodies": 0}},
{"click": {"handle": "view:confirm:ok"}},
{"until": {"dialog": null}},
{"expect": {"bodies": 1, "features": 2, "errors": 0}},
{"note": "A new sketch, left with the cross: it goes, with what was drawn in it."},
{"start": "sketch.create"},
{"click": {"plane": "XY"}},
{"start": "sketch.line"},
{"click": {"sketch": [50, 0]}},
{"click": {"sketch": [70, 10]}},
{"key": "Escape"},
{"click": {"handle": "view:confirm:cancel"}},
{"expect": {"sketching": false, "features": 2, "errors": 0}}
]
+4
View File
@@ -67,6 +67,10 @@
keep the nearest quarter-turn heading. The house, the navigation bar's Home button and a middle-button double-click in the view go
home, framing what is shown now (Navigation › **Middle double-click** can make it Fit, which
keeps the orientation, or turn it off).
Interface › **OK and Cancel in the view's corner** puts a large check and cross at the view's
top right while a dialog or a sketch is open, and moves the axis view or cube down below them.
With a dialog open they do what its OK and Cancel do (the check is grey whenever OK is); in a
sketch without a dialog they are Finish Sketch and Cancel Sketch.
Right-click for the marking menu: eight commands around the cursor, plus a
menu for whatever is under it. Near the window's bottom or right edge a menu opens above or
to the left of the cursor, so it stays in view.
+1 -1
View File
@@ -245,7 +245,7 @@ labels; `prefs:measure_axis_distances` identifies the checkbox.
| `ui.home` | `open?`: bool; `sample?`: index | the start page: show or hide it, open a built-in sample (once built); returns `open` and the recent designs |
| `ui.shortcut` | `command`, `key?`, `replace?` | a command's key, or rebinds it (`""` clears; a key another command uses is refused unless `replace`) |
| `ui.help` | `item?`: `about`, `shortcuts` (read only), `report` (opens a report draft for review), `crashes` (the Crash Reports window) | the version, commit, build date and diagnostic text |
| `ui.prefs` | any of `default_units`, `nav` (`fusion`, `solidworks`, `inventor`, `alias`, `blender`, `tinkercad`, `openscad`, `touchpad`), `zoom_reverse`, `pan_reverse_x` (default false: horizontal scrolling pans the other way), `zoom_to_cursor`, `smooth_wheel_zoom` (default true), `trackpad_pan` (default true: two-finger scroll pans, except Touchpad always zooms; pinch zooms), `orbit_around` (`view_centre` (default: what Pan moves and Fit frames), `origin` (the world origin stays still on screen), `cursor` (the model point under the pointer when the drag began); the older `orbit_cursor` boolean still sets `cursor` when true), `look_at_anim`, `look_at_speed`, `middle_double_click` (`home` (default), `fit`, `off`), `msaa`, `show_frame_rate` (default false: frames per second in the view's bottom-right corner, counting the frames the view draws anyway; it reads 0 FPS once the view is idle), `window_system` (Linux: `auto` (default: XWayland whenever there is an X display, native Wayland on niri), `wayland`, `x11`; saved in `graphics.json`, applies at the next start; `SOLIDCRAFT_WAYLAND` overrides it), `graphics_adapter` (exact card name, or empty for Automatic; applies after restart; `WGPU_ADAPTER_NAME` takes precedence), `frame_rate_details` (default false: with the frame rate, a frame-time graph of the frames drawn with the triangles over it, a frame-time histogram and what the GPU drew; clicking the readout switches it), `length_decimals`, `angle_decimals`, `step_values` (default false: Up/Down and the wheel step a plain number in a focused value field), `theme` (`dark`, `light`, `system` or a theme file's id: a built-in one such as `gruvbox-dark`, or an imported one; the reply's `theme_ids` lists them), `viewport_theme` (`theme` (default: the theme's own), `light`, `dark`: the 3D view in the Light or Dark theme's colours whatever the window uses, #4146), `theme_import` (a `solidcraft-theme/1` file's JSON or text: adds the theme and turns it on; the reply's `theme_imported` is its id), `theme_remove` (an imported theme's id), `theme_export: true` (the reply's `theme_file` is the theme on now as a complete file; see [colour themes](book/src/guide/ui-tour.md#colour-themes)), `language` (`en`, `ja`, `de`, `fr`, `ko`, `ms`, `ru`, `uk`, `zh`; see [localization](localization.md)), `ui_scale`, `ui_font` (an installed font family or a font file for the interface; empty for the built-in font), `up_axis` (`z`, `y`), `offer_stand_up`, `extrude_auto_to_object` (default false: in the Extrude dialog, with a profile picked, a face, vertex or parallel plane picked off its plane switches the extent to To Object; it applies to Extrude dialogs opened afterwards), `hole_snaps` (default false: a Single hole snaps to its face's middle and round edges' centres), `hole_moves` (default false: a placed Single hole has a drag handle (`hole:<n>`), and a pick on a face that has a hole moves it there), `color_vision` (`off` (default), `protan`, `deutan`, `tritan`: colour vision modes, #778), `check_updates` (default true; [updates](book/src/guide/updates.md)); `open` (a page: General, Interface, Design, Navigation, Keyboard Shortcuts, Sketch, Graphics, AI, Plugins; Shortcuts, Assistant and Sketch & selection are aliases, and the former Selection page opens Sketch) opens the Preferences dialog there; `button`: `ok`, `cancel`, `apply`, `defaults`; `stand_up: true` stands up a just-opened Y-up file, `stand_up: false` leaves it as it is ("Leave it": the offer closes and `offer_stand_up` stays on); the offer's buttons are the handles `stand_up:stand`, `stand_up:leave` and `stand_up:never` | sets preferences (kept between runs), returns them all plus `dialog` (the open page or null), `dark`, `viewport_dark` (whether the 3D view is dark) and `stand_up_offer` |
| `ui.prefs` | any of `default_units`, `nav` (`fusion`, `solidworks`, `inventor`, `alias`, `blender`, `tinkercad`, `openscad`, `touchpad`), `zoom_reverse`, `pan_reverse_x` (default false: horizontal scrolling pans the other way), `zoom_to_cursor`, `smooth_wheel_zoom` (default true), `trackpad_pan` (default true: two-finger scroll pans, except Touchpad always zooms; pinch zooms), `orbit_around` (`view_centre` (default: what Pan moves and Fit frames), `origin` (the world origin stays still on screen), `cursor` (the model point under the pointer when the drag began); the older `orbit_cursor` boolean still sets `cursor` when true), `look_at_anim`, `look_at_speed`, `middle_double_click` (`home` (default), `fit`, `off`), `msaa`, `show_frame_rate` (default false: frames per second in the view's bottom-right corner, counting the frames the view draws anyway; it reads 0 FPS once the view is idle), `window_system` (Linux: `auto` (default: XWayland whenever there is an X display, native Wayland on niri), `wayland`, `x11`; saved in `graphics.json`, applies at the next start; `SOLIDCRAFT_WAYLAND` overrides it), `graphics_adapter` (exact card name, or empty for Automatic; applies after restart; `WGPU_ADAPTER_NAME` takes precedence), `frame_rate_details` (default false: with the frame rate, a frame-time graph of the frames drawn with the triangles over it, a frame-time histogram and what the GPU drew; clicking the readout switches it), `length_decimals`, `angle_decimals`, `step_values` (default false: Up/Down and the wheel step a plain number in a focused value field), `theme` (`dark`, `light`, `system` or a theme file's id: a built-in one such as `gruvbox-dark`, or an imported one; the reply's `theme_ids` lists them), `viewport_theme` (`theme` (default: the theme's own), `light`, `dark`: the 3D view in the Light or Dark theme's colours whatever the window uses, #4146), `theme_import` (a `solidcraft-theme/1` file's JSON or text: adds the theme and turns it on; the reply's `theme_imported` is its id), `theme_remove` (an imported theme's id), `theme_export: true` (the reply's `theme_file` is the theme on now as a complete file; see [colour themes](book/src/guide/ui-tour.md#colour-themes)), `language` (`en`, `ja`, `de`, `fr`, `ko`, `ms`, `ru`, `uk`, `zh`; see [localization](localization.md)), `ui_scale`, `ui_font` (an installed font family or a font file for the interface; empty for the built-in font), `up_axis` (`z`, `y`), `offer_stand_up`, `extrude_auto_to_object` (default false: in the Extrude dialog, with a profile picked, a face, vertex or parallel plane picked off its plane switches the extent to To Object; it applies to Extrude dialogs opened afterwards), `hole_snaps` (default false: a Single hole snaps to its face's middle and round edges' centres), `hole_moves` (default false: a placed Single hole has a drag handle (`hole:<n>`), and a pick on a face that has a hole moves it there), `color_vision` (`off` (default), `protan`, `deutan`, `tritan`: colour vision modes, #778), `view_confirm_corner` (default false: while a dialog or a sketch is open, a check and a cross at the view's top right, handles `view:confirm:ok` and `view:confirm:cancel`, do what the dialog's OK and Cancel do, or Finish Sketch and Cancel Sketch; the axis view or cube moves down below them, #6709), `check_updates` (default true; [updates](book/src/guide/updates.md)); `open` (a page: General, Interface, Design, Navigation, Keyboard Shortcuts, Sketch, Graphics, AI, Plugins; Shortcuts, Assistant and Sketch & selection are aliases, and the former Selection page opens Sketch) opens the Preferences dialog there; `button`: `ok`, `cancel`, `apply`, `defaults`; `stand_up: true` stands up a just-opened Y-up file, `stand_up: false` leaves it as it is ("Leave it": the offer closes and `offer_stand_up` stays on); the offer's buttons are the handles `stand_up:stand`, `stand_up:leave` and `stand_up:never` | sets preferences (kept between runs), returns them all plus `dialog` (the open page or null), `dark`, `viewport_dark` (whether the 3D view is dark) and `stand_up_offer` |
| `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. The pointer shows the command's localized name, including commands inside a closed toolbar group; an animated batch names each command it visits. It also follows the pointer input sent with `ui.move`, `ui.click`, `ui.drag` and `ui.scroll`, as each event reaches the app, and a press leaves a ripple. `"animate": false` on a call skips it |
+1
View File
@@ -48,6 +48,7 @@ windows use the shared composition, including its header and fixed outer frame.
| Dimension values, canvas placement values, canvas feedback and History resize seam | `dim_view`, `sketch_dims`, `canvas`, `timeline_left` | Model/control-anchored overlays; retain their coordinates rather than becoming docks |
| Status and loading/progress messages | `viewport`, `open_meshing` | Notification surfaces independent of layout |
| Navigation bar | `viewport` | Shared navigation surface; shell still computes its available canvas bounds |
| OK and Cancel in the view's corner | `view_confirm` | Navigation surface in its own area; the viewport layout reserves its corner and the shell counts it as covered |
| Home, model viewport, Render canvas and native Assistant window content | `home`, `lib`, `agent_chat/panel` | Central content hosts, not floating workspace panels |
| Loading input shield | `file_load` | Explicit input shield; must remain interactive while CAD input is blocked |