Dialogs: OK and Cancel at the top (#6708) (#6713)

* claim: #6708

* feat(dialogs): OK and Cancel at the top (#6708)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lars Jansen
2026-10-27 02:42:23 +00:00
committed by GitHub
parent 4b327bab1f
commit 2d629069c6
14 changed files with 686 additions and 64 deletions
@@ -0,0 +1,18 @@
{
"en": {
"prefs.dialog_buttons": "Dialog buttons",
"prefs.top": "Top"
},
"ja": {
"prefs.dialog_buttons": "ダイアログのボタン",
"prefs.top": "上"
},
"ko": {
"prefs.dialog_buttons": "대화 상자 버튼",
"prefs.top": "위쪽"
},
"zh": {
"prefs.dialog_buttons": "对话框按钮",
"prefs.top": "顶部"
}
}
+114
View File
@@ -481,6 +481,85 @@ fn remaining_dialogs_keep_kit_chrome_and_cancel_restores_preview() {
}
}
/// Interface › Dialog buttons › Top (#6708): every card made by the shared panel moves its
/// actions into the header row, with the footer's enabled states, handles and close behaviour.
#[test]
fn top_dialog_buttons_keep_every_cards_states_handles_and_close() {
for command in [
"solid.revolve",
"solid.shell",
"solid.box",
"joint.create",
"solid.thread",
"inspect.measure",
"contact.create",
"motion.study",
"explode.create",
"parts.insert",
"joint.drive",
"inspect.interference",
"file.save_mesh",
"file.export_view_dxf",
"sheet.flat_pattern",
] {
let mut seen = Vec::new();
for placement in ["bottom", "top"] {
let mut h = fixture();
h.call("ui.resize", json!({"width":1600,"height":1200}));
h.call("ui.prefs", json!({"dialog_buttons": placement}));
let design = h.app.session.doc.to_json();
h.app.start(command);
h.frames(4);
let header = scenario::rect_of("dialog:header").unwrap_or_else(|| panic!("{command} {placement}: no header"));
let cancel = scenario::handle_at("dialog:cancel").unwrap_or_else(|| panic!("{command} {placement}: no cancel"));
seen.push((
scenario::count_of("dialog:ok:enabled"),
scenario::rect_of("dialog:ok").is_some(),
scenario::rect_of("dialog:apply").is_some(),
));
if placement == "top" {
assert!(scenario::rect_of("dialog:footer").is_none(), "{command}: no footer row");
assert!(header.contains(cancel), "{command}: cancel in the header {header:?}");
assert!(scenario::rect_of("dialog:ok").is_none_or(|ok| header.contains_rect(ok)), "{command}: OK in the header");
assert_eq!(scenario::handle_at("dialog:close"), Some(cancel), "{command}: Cancel is the close");
} else {
assert!(scenario::rect_of("dialog:footer").unwrap().contains(cancel), "{command}: cancel in the footer");
}
h.step(&json!({"click":{"handle":"dialog:close"}})).unwrap();
assert!(h.app.dialog.is_none(), "{command} {placement}: closed");
assert_eq!(h.app.session.doc.to_json(), design, "{command} {placement}: closing keeps the design");
}
assert_eq!(seen.first(), seen.get(1), "{command}: OK and Apply as at the bottom");
}
}
/// With the buttons at the top, OK, Enter and Esc do what they do with them at the bottom.
#[test]
fn top_dialog_buttons_apply_and_cancel_like_the_footer() {
for how in ["click", "enter", "escape"] {
let mut h = fixture();
h.call("ui.resize", json!({"width":1600,"height":1200}));
h.call("ui.prefs", json!({"dialog_buttons": "top"}));
h.app.dialog = Some(representative(&h, "solid.revolve"));
h.settle();
assert_eq!(scenario::count_of("dialog:ok:enabled"), Some(1.0));
let (design, bodies) = (h.app.session.doc.to_json(), h.app.session.world_state().bodies.len());
let step = match how {
"click" => json!({"click":{"handle":"dialog:OK"}}),
"enter" => json!({"key":"Enter"}),
_ => json!({"key":"Escape"}),
};
h.step(&step).unwrap();
h.settle();
assert!(h.app.dialog.is_none(), "{how}: the dialog closes");
if how == "escape" {
assert_eq!(h.app.session.doc.to_json(), design, "Esc leaves the design as it was");
} else {
assert_eq!(h.app.session.world_state().bodies.len(), bodies + 1, "{how}: the revolve is made");
}
}
}
/// 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.
@@ -528,6 +607,41 @@ fn view_corner_ok_and_cancel_answer_the_dialog_like_its_own_buttons() {
assert!(h.app.dialog.is_none(), "the cross closes Measure");
}
/// Both options at once (#6708 with #6709): the check in the view's corner greys out with the OK
/// in the title row, the pair keeps clear of the dialog, and either OK applies it.
#[test]
fn top_dialog_buttons_and_the_view_corner_agree() {
let open = |command: &str| {
let mut h = fixture();
h.call("ui.resize", json!({"width":1600,"height":1200}));
h.call("ui.prefs", json!({"dialog_buttons": "top", "view_confirm_corner": true}));
if command == "solid.revolve" {
h.app.dialog = Some(representative(&h, command));
} else {
h.app.start(command);
}
h.settle();
h
};
for (command, enabled) in [("solid.revolve", 1.0), ("solid.shell", 0.0)] {
let _h = open(command);
let header = scenario::rect_of("dialog:header").unwrap();
assert!(scenario::rect_of("dialog:footer").is_none(), "{command}");
assert!(header.contains_rect(scenario::rect_of("dialog:ok").unwrap()), "{command}: OK in the title row");
assert_eq!(scenario::count_of("dialog:ok:enabled"), Some(enabled), "{command}");
assert_eq!(scenario::count_of("view:confirm:ok:enabled"), Some(enabled), "{command}: the check follows the title row's OK");
assert!(!scenario::rect_of("view:confirm").unwrap().intersects(header), "{command}: the pair keeps clear of the dialog");
}
for handle in ["dialog:ok", "view:confirm:ok"] {
let mut h = open("solid.revolve");
let bodies = h.app.session.world_state().bodies.len();
h.step(&json!({"click":{"handle":handle}})).unwrap();
h.settle();
assert!(h.app.dialog.is_none(), "{handle}: the dialog closes");
assert_eq!(h.app.session.world_state().bodies.len(), bodies + 1, "{handle}: the revolve is made");
}
}
fn resized_box_editor(command: &str, params: Value) -> (Harness, u64) {
let mut h = Harness::new();
for (id, params) in [
@@ -128,6 +128,28 @@ fn apply_commits_once_keeps_values_and_waits_for_new_selection_ok_closes() {
}
}
/// Interface › Dialog buttons › Top (#6708): Apply sits between Cancel and OK in the header row
/// and still commits once, keeping the dialog open.
#[test]
fn apply_in_the_header_row_commits_once_and_keeps_the_dialog() {
let mut h = fixture();
h.call("ui.prefs", json!({"dialog_buttons":"top"}));
h.app.dialog = Some(picked(&h, "sketch.offset"));
h.settle();
let header = scenario::rect_of("dialog:header").unwrap();
assert!(scenario::rect_of("dialog:footer").is_none());
let (cancel, apply, ok) =
(scenario::rect_of("dialog:cancel").unwrap(), scenario::rect_of("dialog:apply").unwrap(), scenario::rect_of("dialog:ok").unwrap());
assert!(header.contains_rect(cancel) && header.contains_rect(apply) && header.contains_rect(ok));
assert!(cancel.right() < apply.left() && apply.right() < ok.left());
let undo = h.app.session.undo.len();
h.step(&json!({"click":{"handle":"dialog:apply"}})).unwrap();
h.settle();
assert_eq!(h.app.session.undo.len(), undo + 1, "one Apply, one undo");
assert!(h.app.dialog.is_some(), "Apply keeps the dialog");
assert_eq!(scenario::rect_of("dialog:apply"), Some(apply), "the buttons stay where they were");
}
#[test]
fn picked_list_removes_one_item_and_field_still_activates_input() {
let mut h = fixture();
+1
View File
@@ -2124,6 +2124,7 @@ impl SolveApp {
self.ui.show_timeline = true;
}
self.ui.layout.publish(ui.ctx());
self.preferences.dialog_buttons.publish(ui.ctx());
scenario::clear_handles();
self.poll_feature_edit(ui.ctx());
self.poll_deferred(ui.ctx());
+32
View File
@@ -628,6 +628,8 @@ preference_settings! {
layout: crate::shell::LayoutMode = Default::default(), PAGE_INTERFACE;
/// Show command names beneath ribbon icons, independently of workspace layout.
ribbon_labels: bool = true, PAGE_INTERFACE;
/// Where a dialog's OK and Cancel sit: under its inputs (the default) or in its title row (#6708).
dialog_buttons: crate::ui_kit::DialogButtons = Default::default(), PAGE_INTERFACE;
/// Interface scale (1 = 100 %).
ui_scale: f32 = 1.0, PAGE_INTERFACE, accept(0.5..=2.5);
/// Interface font: an installed font family (or a font file), or empty for the built-in one
@@ -3397,6 +3399,7 @@ mod tests {
("ui_font", json!("test font"), PAGE_INTERFACE),
("layout", json!("compact"), PAGE_INTERFACE),
("ribbon_labels", json!(false), PAGE_INTERFACE),
("dialog_buttons", json!("top"), PAGE_INTERFACE),
("timeline_left", json!(true), PAGE_INTERFACE),
("timeline_under_browser", json!(true), PAGE_INTERFACE),
("history_sketches", json!("under_feature"), PAGE_INTERFACE),
@@ -4027,6 +4030,35 @@ mod tests {
assert_eq!(h.app.preferences.history_sketches, HistorySketches::UnderFeature);
}
#[test]
fn dialog_buttons_default_bottom_and_follow_preferences_transactions() {
use crate::ui_kit::DialogButtons;
let old: Prefs = serde_json::from_value(json!({"ribbon_labels": false})).unwrap();
assert_eq!(old.dialog_buttons, DialogButtons::Bottom, "settings from before keep the footer");
assert_eq!(lenient(&json!({"dialog_buttons": "sideways"})).dialog_buttons, DialogButtons::Bottom);
let mut h = crate::scenario::Harness::new();
h.call("ui.prefs", json!({"open": "Interface"}));
super::reveal_preference(&mut h, "prefs:dialog_buttons:top");
h.step(&json!({"click": {"handle": "prefs:dialog_buttons:top"}})).unwrap();
assert_eq!(h.app.preferences.dialog_buttons, DialogButtons::Top);
h.call("ui.prefs", json!({"button": "cancel"}));
assert_eq!(h.app.preferences.dialog_buttons, DialogButtons::Bottom);
let reply = h.call("ui.prefs", json!({"dialog_buttons": "top"}));
assert_eq!(reply["result"]["dialog_buttons"], "top");
let mut restored = SolveApp::new(solidcraft_engine::Session::default(), Default::default());
restored.load_prefs(&h.app.prefs());
assert_eq!(restored.preferences.dialog_buttons, DialogButtons::Top);
let before = h.app.preferences.clone();
assert!(control(&mut h.app, &json!({"dialog_buttons": "sideways"})).is_err());
assert_eq!(h.app.preferences, before, "an unknown value changes nothing");
h.call("ui.prefs", json!({"open": "Interface"}));
h.call("ui.prefs", json!({"button": "defaults"}));
assert_eq!(h.app.preferences.dialog_buttons, DialogButtons::Bottom);
h.call("ui.prefs", json!({"button": "cancel"}));
assert_eq!(h.app.preferences.dialog_buttons, DialogButtons::Top);
}
#[test]
fn free_orbit_defaults_off_and_follows_preferences_transactions() {
let old: Prefs = serde_json::from_value(json!({"nav":"solidworks"})).unwrap();
+17
View File
@@ -42,6 +42,23 @@ pub(super) fn interface(app: &mut SolveApp, ui: &mut egui::Ui, t: &Tokens) {
app.preferences.ribbon_labels = selected == 0;
}
});
// Where every feature dialog puts its OK and Cancel (#6708).
ui_kit::row(ui, app.tr("prefs.dialog_buttons"), |ui| {
let placements = [crate::ui_kit::DialogButtons::Bottom, crate::ui_kit::DialogButtons::Top];
let mut selected = placements.iter().position(|p| *p == app.preferences.dialog_buttons).unwrap_or(0);
if ui_kit::segmented(ui, &mut selected, &[app.tr("prefs.bottom"), app.tr("prefs.top")], Default::default())
&& let Some(placement) = placements.get(selected)
{
app.preferences.dialog_buttons = *placement;
}
});
// Handles that don't depend on the language, by the saved value.
let row = app.tr("prefs.dialog_buttons");
for (label, key) in [("prefs.bottom", "bottom"), ("prefs.top", "top")] {
if let Some(at) = crate::scenario::handle_at(&format!("dialog:{row}:{}", app.tr(label))) {
crate::scenario::publish_handle(&format!("prefs:dialog_buttons:{key}"), at);
}
}
ui_kit::row(ui, app.tr("prefs.history"), |ui| {
let mut selected = if app.preferences.timeline_left { if app.preferences.timeline_under_browser { 2 } else { 1 } } else { 0 };
if ui_kit::segmented(
+157 -55
View File
@@ -121,20 +121,7 @@ pub(super) fn footer_with_left(
let inner = band.shrink2(vec2(t.space_12, t.space_10));
scenario::publish_rect("dialog:footer:actions", inner);
let mut action = if ui.is_enabled() { keyboard(ui.ctx(), ok_enabled) } else { Action::None };
let primary_fill = if t.borders.bevel.is_some() && !danger {
t.control_fill
} else if danger {
t.form_error
} else {
t.form_primary
};
let primary_ink = if t.borders.bevel.is_some() && !danger {
t.form_ink
} else if danger && crate::theme::contrast_ratio(t.on_accent, primary_fill) < 4.5 {
t.tab_on_fill_dark
} else {
t.on_accent
};
let look = ActionLook::new(ok_enabled, selected, danger);
let mut actions_left = inner.right();
let row = ui.scope_builder(egui::UiBuilder::new().max_rect(inner).layout(egui::Layout::left_to_right(egui::Align::Center)), |ui| {
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
@@ -143,49 +130,16 @@ pub(super) fn footer_with_left(
if (kind == Action::Apply && (apply_label.is_none() || confirm)) || (kind == Action::Ok && ok_label.is_empty()) || label.is_empty() {
continue;
}
let marked = selected == Some(kind);
let primary = kind == Action::Ok && selected.is_none_or(|s| s == Action::Ok);
let live = kind == Action::Cancel || ok_enabled;
ui.spacing_mut().button_padding = vec2(if primary { t.space_16 } else { t.space_12 }, 0.0);
let text = RichText::new(crate::i18n::tr_label(label)).size(t.font_label).color(if primary && ok_enabled {
primary_ink
} else if primary {
t.form_dim
} else {
t.form_ink
});
let response = ui.add_enabled(
live,
egui::Button::new(if primary && ok_enabled { text.bold_face() } else { text })
.selected(marked && !primary)
.fill(if primary && ok_enabled {
primary_fill
} else if marked {
t.selected_bg
} else {
t.control_fill
})
.stroke(if primary && ok_enabled {
egui::Stroke::NONE
} else if marked && !primary {
egui::Stroke::new(1.0, t.form_primary)
} else {
t.control_border_stroke(t.control_border)
})
.wrap_mode(egui::TextWrapMode::Extend)
.corner_radius(t.control_radius)
.min_size(vec2(if primary { t.space_24 * 3.0 } else { 0.0 }, t.form_button_height)),
let primary = look.primary(kind);
let response = action_button(
ui,
label,
kind,
&look,
if primary { t.space_16 } else { t.space_12 },
if primary { t.space_24 * 3.0 } else { 0.0 },
);
t.button_bevel(ui, &response, false);
pointer_on_hover(ui, &response);
actions_left = actions_left.min(response.rect.left());
let key = match kind {
Action::Ok => "dialog:ok",
Action::Apply => "dialog:apply",
_ => "dialog:cancel",
};
scenario::publish_target(key, response.rect);
scenario::publish_handle(&format!("dialog:{label}"), response.rect.center());
if response.clicked() {
action = kind;
}
@@ -225,6 +179,154 @@ pub(super) fn footer_with_left(
action
}
/// What every OK, Apply and Cancel button shares, wherever the row of them sits.
struct ActionLook {
ok_enabled: bool,
selected: Option<Action>,
primary_fill: egui::Color32,
primary_ink: egui::Color32,
}
impl ActionLook {
fn new(ok_enabled: bool, selected: Option<Action>, danger: bool) -> Self {
let t = Tokens::get();
let primary_fill = if t.borders.bevel.is_some() && !danger {
t.control_fill
} else if danger {
t.form_error
} else {
t.form_primary
};
let primary_ink = if t.borders.bevel.is_some() && !danger {
t.form_ink
} else if danger && crate::theme::contrast_ratio(t.on_accent, primary_fill) < 4.5 {
t.tab_on_fill_dark
} else {
t.on_accent
};
Self { ok_enabled, selected, primary_fill, primary_ink }
}
/// OK carries the accent unless the keyboard marks another action.
fn primary(&self, kind: Action) -> bool {
kind == Action::Ok && self.selected.is_none_or(|s| s == Action::Ok)
}
}
/// One OK, Apply or Cancel button, `padding` at its sides and at least `min_width` wide, with its
/// scenario handles (`dialog:ok`, `dialog:apply`, `dialog:cancel` and `dialog:<label>`).
fn action_button(ui: &mut Ui, label: &str, kind: Action, look: &ActionLook, padding: f32, min_width: f32) -> Response {
let t = Tokens::get();
let ok_enabled = look.ok_enabled;
let marked = look.selected == Some(kind);
let primary = look.primary(kind);
let live = kind == Action::Cancel || ok_enabled;
ui.spacing_mut().button_padding = vec2(padding, 0.0);
let text = RichText::new(crate::i18n::tr_label(label)).size(t.font_label).color(if primary && ok_enabled {
look.primary_ink
} else if primary {
t.form_dim
} else {
t.form_ink
});
let response = ui.add_enabled(
live,
egui::Button::new(if primary && ok_enabled { text.bold_face() } else { text })
.selected(marked && !primary)
.fill(if primary && ok_enabled {
look.primary_fill
} else if marked {
t.selected_bg
} else {
t.control_fill
})
.stroke(if primary && ok_enabled {
egui::Stroke::NONE
} else if marked && !primary {
egui::Stroke::new(1.0, t.form_primary)
} else {
t.control_border_stroke(t.control_border)
})
.wrap_mode(egui::TextWrapMode::Extend)
.corner_radius(t.control_radius)
.min_size(vec2(min_width, t.form_button_height)),
);
t.button_bevel(ui, &response, false);
pointer_on_hover(ui, &response);
let key = match kind {
Action::Ok => "dialog:ok",
Action::Apply => "dialog:apply",
_ => "dialog:cancel",
};
scenario::publish_target(key, response.rect);
scenario::publish_handle(&format!("dialog:{label}"), response.rect.center());
response
}
/// A panel's OK, Apply and Cancel in its header row (`DialogButtons::Top`): the footer's buttons,
/// in the footer's order, with its enabled states, keyboard and scenario handles. Each is as wide
/// as its label in the bold face, so the row keeps its place whatever the panel's inputs do.
/// Tokens: `form_button_height`, `font_label`, `space_4/8`, and the footer's button tokens.
pub(crate) struct HeaderActions<'a> {
/// Right to left: OK, Apply, Cancel (those with a label).
slots: Vec<(Action, &'a str, egui::Rect)>,
}
impl<'a> HeaderActions<'a> {
/// Lays the buttons out right to left from `right`, centred on `band`, never past its left.
pub(crate) fn new(ui: &Ui, band: egui::Rect, right: f32, ok: &'a str, apply: Option<&'a str>, cancel: &'a str) -> Self {
let t = Tokens::get();
let mut slots = Vec::new();
let mut x = right;
for (label, kind) in [(ok, Action::Ok), (apply.unwrap_or(""), Action::Apply), (cancel, Action::Cancel)] {
if label.is_empty() {
continue;
}
let text = ui.painter().layout_no_wrap(crate::i18n::tr_label(label).to_owned(), crate::fonts::bold(t.font_label), t.form_ink);
let width = (text.size().x.ceil() + t.space_8 * 2.0).min((x - band.left()).max(0.0));
let rect = egui::Rect::from_min_max(
egui::pos2(x - width, band.center().y - t.form_button_height / 2.0),
egui::pos2(x, band.center().y + t.form_button_height / 2.0),
);
slots.push((kind, label, rect));
x = (rect.left() - t.space_4).max(band.left());
}
Self { slots }
}
/// Where the buttons start; `right` when there are none.
pub(crate) fn left(&self, right: f32) -> f32 {
self.slots.iter().map(|(_, _, rect)| rect.left()).fold(right, f32::min)
}
pub(crate) fn rect(&self, kind: Action) -> Option<egui::Rect> {
self.slots.iter().find(|(k, _, _)| *k == kind).map(|(_, _, rect)| *rect)
}
/// Draws the buttons; returns what was clicked, or what Enter and Esc ask for.
pub(crate) fn show(&self, ui: &mut Ui, ok_enabled: bool) -> Action {
let ok_enabled = ok_enabled && self.rect(Action::Ok).is_some();
scenario::publish_count("dialog:ok:enabled", f64::from(ok_enabled && ui.is_enabled()));
let mut action = if ui.is_enabled() { keyboard(ui.ctx(), ok_enabled) } else { Action::None };
let look = ActionLook::new(ok_enabled, None, false);
let padding = Tokens::get().space_8;
for (kind, label, rect) in &self.slots {
let builder = egui::UiBuilder::new()
.id_salt(("header_action", *kind as u8))
.max_rect(*rect)
.layout(egui::Layout::centered_and_justified(egui::Direction::LeftToRight));
let response = ui.scope_builder(builder, |ui| action_button(ui, label, *kind, &look, padding, 0.0)).inner;
if response.clicked() {
action = *kind;
}
}
if let Some(all) = self.slots.iter().map(|(_, _, rect)| *rect).reduce(|a, b| a.union(b)) {
scenario::publish_rect("dialog:header:actions", all);
}
action
}
}
/// One equal-width secondary action, with optional existing icon master.
pub(crate) struct PairButton<'a> {
pub key: &'a str,
+1 -1
View File
@@ -48,8 +48,8 @@ pub(crate) use history::*;
pub(crate) use layout::*;
pub(crate) use menu::{Menu, MenuItem, rename_menu, workspace_menu};
pub(crate) use metrics::{ContentWidth, header_height, row_height, table_row_height};
pub use panel::Window;
pub(crate) use panel::{ComputeStatus, FeatureOptions, Panel, Part, WindowPage, panel_header_hover};
pub use panel::{DialogButtons, Window};
#[cfg(test)]
pub(crate) use panel::{collapsible_header, header};
pub(crate) use preferences::*;
+133 -5
View File
@@ -62,6 +62,124 @@ fn header_impl(ui: &mut Ui, icon: &str, title: &str, collapsed: Option<&mut bool
t.secondary_hline(ui.painter(), rect.x_range(), rect.bottom(), t.dialog_rule);
}
/// Where a feature panel's OK, Cancel and Apply sit (Preferences › Interface › Dialog buttons,
/// #6708). The app publishes the preference each frame, so every `Panel::feature` follows it.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum DialogButtons {
/// In a footer row under the inputs (how it always was). Also what a value this version
/// doesn't know reads as (`prefs::lenient`).
#[default]
Bottom,
/// In the header row, right of the title, where they stay while sections open and close.
Top,
}
impl DialogButtons {
pub(crate) fn publish(self, ctx: &egui::Context) {
ctx.data_mut(|data| data.insert_temp(egui::Id::new("sc_dialog_buttons"), self));
}
pub(crate) fn current(ctx: &egui::Context) -> Self {
ctx.data(|data| data.get_temp(egui::Id::new("sc_dialog_buttons"))).unwrap_or_default()
}
}
/// The header row of a feature panel whose actions sit at the top. It is laid out before the
/// body, and its icon, title and buttons are drawn after it, once the compute status and whether
/// OK is enabled are known. Same tokens as `header`, plus `HeaderActions`'.
struct TopHeader<'a> {
icon: egui::Rect,
title: egui::Rect,
actions: super::HeaderActions<'a>,
}
impl<'a> TopHeader<'a> {
fn new(ui: &mut Ui, ok: &'a str, apply: Option<&'a str>, cancel: &'a str, collapsed: Option<&mut bool>, close: &mut bool) -> Self {
let t = Tokens::get();
let (band, _) = ui.allocate_exact_size(vec2(dimension(ui.available_width()), header_height()), egui::Sense::hover());
let icon = egui::Rect::from_center_size(
egui::pos2(band.left() + t.space_12 + t.form_icon_size / 2.0, band.center().y),
vec2(t.form_icon_size, t.form_icon_size),
);
// The buttons end where the fields below do.
let end = (band.right() - t.space_12).max(band.left());
let actions = super::HeaderActions::new(ui, band, end, ok, apply, cancel);
let buttons = actions.left(end);
// Nothing placed yet beside the buttons: the next control keeps clear of them.
let beside_buttons = |right: f32| buttons < end && right >= buttons;
// An icon target to the left of what is already placed, `space_4` clear of the buttons.
let target = |right: f32| {
let right = if beside_buttons(right) { right - t.space_4 } else { right };
egui::Rect::from_center_size(
egui::pos2((right - t.form_close_size / 2.0).max(band.left()), band.center().y),
vec2(t.form_close_size, t.form_close_size),
)
};
let mut right = buttons;
// The header's close does what Cancel does in every panel, so with Cancel up here it is
// left out: one control for one action, and its width goes to the title. Its handle
// moves to Cancel, so automation that closes a panel keeps working.
if let Some(cancel_rect) = actions.rect(super::Action::Cancel) {
scenario::publish_handle("dialog:close", cancel_rect.center());
} else {
let close_rect = target(right);
let response = icon_button_at(ui, close_rect, "close", "Close");
scenario::publish_handle("dialog:close", response.rect.center());
if response.clicked() {
*close = true;
}
right = close_rect.left();
}
if let Some(collapsed) = collapsed {
let fold = target(right);
let response = super::disclosure_button_at(ui, fold, !*collapsed, crate::i18n::tr_label(if *collapsed { "Expand" } else { "Collapse" }));
scenario::publish_handle("dialog:collapse", response.rect.center());
if response.clicked() {
*collapsed = !*collapsed;
}
right = fold.left();
}
// Text next to a text button keeps a gap; an icon target carries its own padding.
if beside_buttons(right) {
right = (right - t.space_6).max(band.left());
}
let left = (icon.right() + t.space_8).min(right);
let title = egui::Rect::from_min_max(egui::pos2(left, band.top()), egui::pos2(right.max(left), band.bottom()));
// Dragging the panel by its title must not start on a button.
scenario::publish_handle("dialog:title", title.center());
scenario::publish_rect("dialog:header", band);
t.secondary_hline(ui.painter(), band.x_range(), band.bottom(), t.dialog_rule);
Self { icon, title, actions }
}
/// The icon (the compute spinner while busy), the title (the compute status while there is
/// one: the footer that showed it is gone) and the buttons. Returns the action asked for.
fn finish(&self, ui: &mut Ui, icon: &str, title: &str, state: &ComputeStatus, ok_enabled: bool) -> super::Action {
let t = Tokens::get();
if state.busy {
egui::Spinner::new().size(t.space_14).paint_at(ui, self.icon);
let status = state.text.as_deref().unwrap_or_else(|| crate::i18n::tr_label("Updating the preview"));
ui.interact(self.icon, ui.id().with("compute_status"), egui::Sense::hover()).on_hover_text(status);
ui.ctx().request_repaint_after(std::time::Duration::from_millis(100));
} else {
crate::icons::paint_icon(ui.painter(), self.icon, icon, 1.0);
}
let heading = crate::fonts::semibold(t.font_heading);
match state.text.as_deref() {
Some(status) => paint_text(ui, self.title, status, crate::fonts::medium(t.font_label), t.form_dim, false),
None => paint_text(ui, self.title, title, heading.clone(), t.form_ink, false),
}
let title_response = ui.interact(self.title, ui.make_persistent_id("title_text"), egui::Sense::hover());
title_response.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Label, ui.is_enabled(), title));
// The buttons take the row's width first; a title that no longer fits says itself on hover.
if ui.painter().layout_no_wrap(title.to_owned(), heading, t.form_ink).size().x > self.title.width() {
title_response.on_hover_text(title);
}
self.actions.show(ui, ok_enabled)
}
}
/// A bounded docked or floating card. Uses form_card_width and the caller's tokenised frame.
/// Window IDs and content scopes are retained so moving a card does not reset field focus.
pub(crate) struct Panel<'a> {
@@ -287,16 +405,21 @@ impl<'a> Panel<'a> {
let band = egui::Rect::from_min_size(min, vec2(ui.available_width(), super::header_height()));
crate::frame::drag_dock(ui, band, heading.drag_key, heading.moved, self.bounded_anchor(ui.ctx()) - heading.docked);
let mut close = false;
if let Some(collapsed) = collapsed.as_deref_mut() {
collapsible_header(ui, heading.icon, heading.title, collapsed, || close = true);
let top = if DialogButtons::current(ui.ctx()) == DialogButtons::Top {
Some(TopHeader::new(ui, self.ok, heading.apply_label, self.cancel, collapsed.as_deref_mut(), &mut close))
} else {
header(ui, heading.icon, heading.title, || close = true);
}
if let Some(collapsed) = collapsed.as_deref_mut() {
collapsible_header(ui, heading.icon, heading.title, collapsed, || close = true);
} else {
header(ui, heading.icon, heading.title, || close = true);
}
None
};
let bottom = self.viewport.bottom()
- super::Container::new(ui.ctx(), super::Surface::Feature).gap()
- self.frame.inner_margin.bottomf()
- self.frame.stroke.width;
let footer_height = t.form_footer_height;
let footer_height = if top.is_some() { 0.0 } else { t.form_footer_height };
let fields_height = (bottom - ui.cursor().top() - footer_height - ui.spacing().item_spacing.y).max(0.0);
let fields_height = self.body_rows.map_or(fields_height, |rows| fields_height.min(rows * t.control_height + t.space_12 * 2.0));
let fields_rect = egui::Rect::from_min_size(ui.cursor().min, vec2(ui.available_width(), fields_height));
@@ -331,6 +454,11 @@ impl<'a> Panel<'a> {
})
.inner
};
if let Some(top) = &top {
let action = top.finish(ui, heading.icon, heading.title, &state, valid && !state.applying);
super::Container::finish_content(ui, self.positioned_frame(ui.ctx()));
return (close, action);
}
let corners = self.positioned_frame(ui.ctx()).corner_radius;
let action = super::footer(
ui,
+155
View File
@@ -128,6 +128,161 @@ fn panel_keeps_actions_and_body_geometry_in_both_layouts() {
}
}
/// One frame of a feature panel with `rows` body rows, the given `placement` published.
fn feature_frame_with(
ctx: &egui::Context,
placement: DialogButtons,
rows: usize,
valid: bool,
collapsed: Option<&mut bool>,
events: Vec<egui::Event>,
) -> (bool, Action) {
let vp = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(640.0, 480.0));
scenario::clear_handles();
let mut result = (false, Action::None);
let mut collapsed = collapsed;
crate::test_support::frame(ctx, egui::RawInput { screen_rect: Some(vp), events, focused: true, ..Default::default() }, |_| {
placement.publish(ctx);
let side = crate::frame::Side::Right;
let frame = Panel::feature_frame(ctx, crate::shell::LayoutMode::Floating, side);
let anchor = egui::pos2(vp.right() - crate::shell::SHELL_GAP, vp.top());
let panel = Panel::new("Fillet", egui::Id::new("top_actions"), anchor, vp, side, frame);
panel.window(ctx).show(ctx, |ui| {
let heading = FeatureOptions {
icon: "fillet",
title: "Fillet",
drag_key: "top_actions",
moved: egui::Vec2::ZERO,
docked: anchor,
apply_label: Some("Apply"),
};
let body = |ui: &mut Ui| {
for row_index in 0..rows {
text(ui, &format!("Input {row_index}"), Text::Note("row"));
}
ComputeStatus { text: None, busy: false, applying: false }
};
result = match collapsed.as_deref_mut() {
Some(collapsed) => panel.feature_collapsible(ui, heading, false, valid, collapsed, body),
None => panel.feature(ui, heading, false, valid, body),
};
});
});
result
}
#[test]
fn top_placement_puts_the_actions_in_the_header_row_where_they_stay() {
let ctx = crate::fonts::test_context();
for _ in 0..3 {
feature_frame_with(&ctx, DialogButtons::Top, 2, true, None, Vec::new());
}
let header = scenario::rect_of("dialog:header").unwrap();
assert_eq!(header.height(), Tokens::get().form_header_height);
assert!(scenario::rect_of("dialog:footer").is_none(), "the footer row is gone");
let (ok, apply, cancel) =
(scenario::rect_of("dialog:ok").unwrap(), scenario::rect_of("dialog:apply").unwrap(), scenario::rect_of("dialog:cancel").unwrap());
for (name, rect) in [("ok", ok), ("apply", apply), ("cancel", cancel)] {
assert!(header.contains_rect(rect), "{name} {rect:?} sits in the header {header:?}");
assert_eq!(rect.height(), Tokens::get().form_button_height, "{name}");
}
assert!(cancel.right() < apply.left() && apply.right() < ok.left(), "the footer's order: Cancel, Apply, then OK at the right");
assert_eq!(scenario::handle_at("dialog:close"), Some(cancel.center()), "Cancel stands in for the close button");
assert!(scenario::handle_at("dialog:OK").is_some() && scenario::handle_at("dialog:Cancel").is_some());
assert!(scenario::handle_at("dialog:title").is_some_and(|at| at.x < cancel.left()), "the title drags clear of the buttons");
assert_eq!(scenario::count_of("dialog:ok:enabled"), Some(1.0));
// More inputs, a longer card: the buttons stay where they were.
for _ in 0..2 {
feature_frame_with(&ctx, DialogButtons::Top, 24, true, None, Vec::new());
}
assert_eq!(scenario::rect_of("dialog:ok"), Some(ok));
assert_eq!(scenario::rect_of("dialog:cancel"), Some(cancel));
// OK greys out exactly as it does in the footer, and a click on it then does nothing.
feature_frame_with(&ctx, DialogButtons::Top, 2, false, None, Vec::new());
assert_eq!(scenario::count_of("dialog:ok:enabled"), Some(0.0));
let at = ok.center();
feature_frame_with(&ctx, DialogButtons::Top, 2, false, None, crate::test_support::pointer(at, true));
assert_eq!(feature_frame_with(&ctx, DialogButtons::Top, 2, false, None, crate::test_support::pointer(at, false)).1, Action::None);
feature_frame_with(&ctx, DialogButtons::Bottom, 2, false, None, Vec::new());
assert_eq!(scenario::count_of("dialog:ok:enabled"), Some(0.0), "the same state at the bottom");
// The buttons and the keys answer as the footer's do.
for (target, expected) in [(ok, Action::Ok), (apply, Action::Apply), (cancel, Action::Cancel)] {
feature_frame_with(&ctx, DialogButtons::Top, 2, true, None, Vec::new());
feature_frame_with(&ctx, DialogButtons::Top, 2, true, None, crate::test_support::pointer(target.center(), true));
let clicked = feature_frame_with(&ctx, DialogButtons::Top, 2, true, None, crate::test_support::pointer(target.center(), false));
assert_eq!(clicked, (false, expected));
}
for (key, expected) in [(egui::Key::Escape, Action::Cancel), (egui::Key::Enter, Action::Ok)] {
feature_frame_with(&ctx, DialogButtons::Top, 2, true, None, Vec::new());
assert_eq!(feature_frame_with(&ctx, DialogButtons::Top, 2, true, None, crate::test_support::key(key)).1, expected, "{key:?}");
}
}
/// With no footer to show it, the compute status takes the title's place and the spinner the
/// icon's, until the feature is in; OK stays grey meanwhile, as in the footer.
#[test]
fn top_placement_shows_the_compute_status_in_the_title_row() {
let ctx = crate::fonts::test_context();
let vp = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(640.0, 480.0));
let mut output = None;
for _ in 0..3 {
scenario::clear_handles();
output = Some(crate::test_support::frame(&ctx, egui::RawInput { screen_rect: Some(vp), ..Default::default() }, |_| {
DialogButtons::Top.publish(&ctx);
let side = crate::frame::Side::Right;
let anchor = egui::pos2(vp.right() - crate::shell::SHELL_GAP, vp.top());
let panel = Panel::new(
"Fillet",
egui::Id::new("top_status"),
anchor,
vp,
side,
Panel::feature_frame(&ctx, crate::shell::LayoutMode::Floating, side),
);
panel.window(&ctx).show(&ctx, |ui| {
let heading = FeatureOptions {
icon: "fillet",
title: "Fillet",
drag_key: "top_status",
moved: egui::Vec2::ZERO,
docked: anchor,
apply_label: None,
};
panel.feature(ui, heading, true, true, |ui| {
text(ui, "Input", Text::Note("row"));
ComputeStatus { text: Some("Computing… 3 s".into()), busy: true, applying: true }
});
});
}));
}
let texts: Vec<String> = output.iter().flat_map(crate::test_support::text_shapes).map(|shape| shape.galley.job.text.clone()).collect();
assert!(texts.iter().any(|text| text == "Computing… 3 s"), "{texts:?}");
assert!(!texts.iter().any(|text| text == "Fillet"), "the status stands in for the title: {texts:?}");
assert_eq!(scenario::count_of("dialog:ok:enabled"), Some(0.0), "OK waits for the feature");
assert!(scenario::rect_of("dialog:header").unwrap().contains_rect(scenario::rect_of("dialog:cancel").unwrap()));
}
#[test]
fn top_placement_keeps_a_managers_fold_beside_the_actions() {
let ctx = crate::fonts::test_context();
let mut collapsed = false;
for _ in 0..3 {
feature_frame_with(&ctx, DialogButtons::Top, 4, true, Some(&mut collapsed), Vec::new());
}
let header = scenario::rect_of("dialog:header").unwrap();
let fold = scenario::handle_at("dialog:collapse").unwrap();
let cancel = scenario::rect_of("dialog:cancel").unwrap();
assert!(header.contains(fold) && fold.x < cancel.left(), "{fold:?} left of {cancel:?}");
assert!(scenario::handle_at("dialog:title").is_some_and(|at| at.x < fold.x));
feature_frame_with(&ctx, DialogButtons::Top, 4, true, Some(&mut collapsed), crate::test_support::pointer(fold, true));
feature_frame_with(&ctx, DialogButtons::Top, 4, true, Some(&mut collapsed), crate::test_support::pointer(fold, false));
assert!(collapsed);
assert_eq!(scenario::rect_of("dialog:cancel"), Some(cancel), "folding leaves the buttons in place");
}
#[test]
fn palette_scrolls_short_views_and_retains_its_status_and_action_handles() {
for layout in [crate::shell::LayoutMode::Docked, crate::shell::LayoutMode::Floating] {
@@ -0,0 +1,27 @@
[
{"note": "Interface › Dialog buttons › Top (#6708): a dialog's OK and Cancel sit in its title row, right of the title. The buttons keep their handles, Cancel takes the close button's, and Enter and Esc work as before."},
{"call": "engine.execute", "params": {"command": "sketch.create", "params": {"plane": "XY", "name": "Sketch1"}}},
{"call": "engine.execute", "params": {"command": "sketch.rectangle.two_point", "params": {"p0": [0, 0], "p1": [40, 30]}}},
{"call": "engine.execute", "params": {"command": "sketch.finish", "params": {}}},
{"call": "ui.prefs", "params": {"open": "Interface"}},
{"click": {"handle": "prefs:dialog_buttons:top"}},
{"widget": "OK"},
{"expect": {"prefs": {"dialog": null, "dialog_buttons": "top"}}},
{"note": "Extrude picks the sketch's one profile; its buttons are in the title row."},
{"start": "solid.extrude"},
{"frames": 4},
{"expect": {"dialog": "Extrude", "handle_order": ["dialog:title", "dialog:Cancel", "dialog:OK"], "bodies": 0}},
{"note": "Esc cancels, and so does the close handle, now on Cancel."},
{"key": "Escape"},
{"expect": {"dialog": null, "bodies": 0}},
{"start": "solid.extrude"},
{"frames": 4},
{"click": {"handle": "dialog:close"}},
{"expect": {"dialog": null, "bodies": 0}},
{"note": "OK in the title row makes the feature."},
{"start": "solid.extrude"},
{"frames": 4},
{"click": {"handle": "dialog:OK"}},
{"until": {"dialog": null}},
{"expect": {"bodies": 1, "errors": 0}}
]
+3 -1
View File
@@ -80,7 +80,9 @@
identity or change the exported solid. Unsupported or uncertain wall geometry
keeps its existing edge presentation.
- **Dialogs** dock on the right with a live preview. Most features also show drag handles and a
value box in the viewport.
value box in the viewport. Interface › **Dialog buttons** › **Top** puts OK, Cancel and Apply in
the dialog's title row, right of the title, where they stay while sections open and close;
Cancel then also takes the place of the close button. Enter and Esc work as before.
- **Timeline** (bottom). Every feature in order. Double-click to edit, drag the marker to roll
back, and drag features to reorder them. Preferences can put the timeline vertically at the
far left of the viewport, beside the browser. Its seam handle switches between icon
File diff suppressed because one or more lines are too long
+5 -1
View File
@@ -29,6 +29,10 @@ preferences, manager cards, prompts, context menus and the sketch palette. Impor
pinned actions, compute status and keyboard routing. `wide()` uses three card
widths. `feature_frame` and `palette_frame` retain docked/floating surfaces.
`FeatureOptions::apply_label` adds Apply; `Panel::actions` supplies custom labels.
With `DialogButtons::Top` published (Preferences › Interface › Dialog buttons), `feature`
puts the actions in the header row through `HeaderActions` instead of a footer: the same
buttons, enabled states, keyboard and handles, each as wide as its bold label, with Cancel
standing in for the close button and the compute status in the title's place.
`body_rows` caps a manager's scrolling body independently of its position; short
viewports still keep the header and actions visible.
- `Window` composes the shared Panel frame with a 40 pt icon/title/close header,
@@ -122,7 +126,7 @@ table. Panel/Window/Confirm compositions also have dedicated geometry and intera
| `primary_button` | Accent action outside a footer | `accent`, `on_accent`, form tokens |
| `icon_button_at` | Icon action inside a supplied rectangle | `form_icon_inset`, `text/dim`, icon palette |
| `button_pair`, `PairButton` | Equal secondary actions, optional icons and selected state | `form_button_height`, control/selection/icon tokens |
| `footer`, `Footer`, `Action` | OK/Cancel with optional Apply, compute status or selected action | `form_footer/button_height`, `dialog_footer/rule`, `control_*`, `accent`, spacing |
| `footer`, `Footer`, `Action`, `HeaderActions` | OK/Cancel with optional Apply, compute status or selected action; `HeaderActions` puts the same buttons in a header row | `form_footer/button_height`, `dialog_footer/rule`, `control_*`, `accent`, spacing |
| `keyboard` | Esc cancels, unowned Enter submits when valid | none |
| `action_menu`, `command_menu_button` | Nested dense action menu or ribbon overflow action retaining its icon, shortcut and enabled state | form control/font tokens, `space_16`, icon palette |
| table: `table`, `table_custom`, `Column`, `Table::headers`, `Table::row`, `TableRow::cell`, `Table::add_prompt` | Left-aligned headers/cells, horizontal overflow, selected/hover rows and empty state. `table_custom` supplies header actions through `headers`. `Column::flex` shares remaining width by weight, freezing columns at their control minimums before redistributing the remaining space; `Column::icon_only` hides the heading while retaining its automation identity. `add_prompt` is the final slim dashed line and requests a regular draft row from its owner; `Column::new(label, width)` uses label-column multiples, `min_content_width(points)` reserves measured control content; `ContentWidth::name` measures strong configuration names | label-column tokens, `control_height`, `dialog_rule/footer`, `selected_bg`, spacing |