Command search: the ribbon field animates into the search field; the footer fills the sheet edge to edge

This commit is contained in:
Nathan Dane
2026-10-20 18:25:53 +02:00
parent 41f5957d60
commit 6c9ddc2528
6 changed files with 476 additions and 201 deletions
+288 -160
View File
@@ -29,6 +29,8 @@ pub struct ShortcutBox {
pub recent: Vec<String>,
pub pinned: Vec<String>,
design: Option<(u64, Vec<DesignRow>)>,
/// Retained paint content while closing; the public query still clears immediately.
closing_text: String,
}
impl ShortcutBox {
@@ -276,27 +278,48 @@ fn close(app: &mut SolveApp) {
}
pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
if !app.ui.palette_open {
app.sbox.at = None;
app.sbox.focus = false;
return;
}
let t = Tokens::get();
let screen = ctx.content_rect();
if app.sbox.at.is_none() {
app.sbox.focus = true;
}
let fallback = *app.sbox.at.get_or_insert(screen.center());
let anchor =
ctx.data(|d| d.get_temp::<Rect>(egui::Id::new("sc_ribbon_search"))).map(|r| r.left_bottom() + vec2(0.0, t.space_6)).unwrap_or(fallback);
let anchor = if anchor.x.is_finite() && anchor.y.is_finite() { anchor } else { screen.center() };
app.sbox.text = bounded(&app.sbox.text);
let width = ui_kit::CommandSearch::width().min((screen.width() - t.space_8).max(t.space_24));
let height = (screen.height() - anchor.y - t.space_8).max(t.space_24 * 4.0);
let pos = pos2(
anchor.x.clamp(screen.left() + t.space_4, (screen.right() - width - t.space_4).max(screen.left() + t.space_4)),
anchor.y.max(screen.top() + t.space_4),
let open = app.ui.palette_open;
// Respect egui's instant/reduced animation policy, with a 120 ms upper bound.
let progress = ctx.animate_bool_with_time_and_easing(
egui::Id::new("sc_search_expansion"),
open,
ctx.global_style().animation_time.clamp(0.0, 0.12),
egui::emath::easing::cubic_out,
);
let ribbon = ctx.data(|d| d.get_temp::<Rect>(egui::Id::new("sc_ribbon_search")));
if !open {
app.sbox.focus = false;
ctx.memory_mut(|m| m.surrender_focus(egui::Id::new("sc_sbox_text")));
if progress == 0.0 {
app.sbox.at = None;
}
if ribbon.is_none() && progress == 0.0 {
return;
}
}
let fallback = app.sbox.at.filter(|p| p.x.is_finite() && p.y.is_finite()).unwrap_or(screen.center());
let width = ui_kit::CommandSearch::width().min((screen.width() - t.space_8).max(t.space_24));
let closed = ribbon.unwrap_or_else(|| {
Rect::from_min_size(
pos2(
fallback.x.clamp(screen.left() + t.space_4, (screen.right() - width - t.space_4).max(screen.left() + t.space_4)),
fallback.y.max(screen.top() + t.space_4),
),
vec2(width, t.control_height),
)
});
let field_size = egui::lerp(closed.size()..=vec2(width, t.control_height + t.space_12), progress);
let pos = pos2(closed.right() - field_size.x, closed.top());
let height = (screen.bottom() - pos.y - field_size.y - t.space_8).max(t.space_24 * 4.0);
let mut query = if open {
bounded(&app.sbox.text)
} else if progress > 0.0 {
app.sbox.closing_text.clone()
} else {
String::new()
};
let (up, down, enter, esc, tab, keep) = ctx.input(|i| {
(
i.key_pressed(egui::Key::ArrowUp),
@@ -312,158 +335,184 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
let mut rows = Vec::new();
let mut design = Vec::new();
let mut mode = None;
let response = crate::frame::area(egui::Id::new("sc_sbox")).fixed_pos(pos).order(egui::Order::Foreground).fade_in(false).show(ctx, |ui| {
ui.set_width(width);
ui.spacing_mut().item_spacing.y = t.space_6;
ui_kit::scope(ui, |ui| {
ui.spacing_mut().item_spacing.y = t.space_6;
let invalid = typed(&app.sbox.text).is_some_and(|(_, result)| result.is_err());
let field = ui_kit::CommandSearch::field(ui, &mut app.sbox.text, invalid, std::mem::take(&mut app.sbox.focus), MAX_QUERY);
if field.changed() {
app.sbox.index = 0;
}
mode = typed(&app.sbox.text).map(|(id, result)| (id.to_owned(), result));
if mode.is_none() {
rows = search(app, &app.sbox.text)
.into_iter()
.filter(|r| {
!app.sbox.text.trim().is_empty()
|| (app.sbox.recent.is_empty() && app.sbox.pinned.is_empty())
|| app.sbox.recent.iter().chain(&app.sbox.pinned).any(|id| id == r.0)
})
.take(if app.sbox.text.trim().is_empty() {
if app.sbox.recent.is_empty() && app.sbox.pinned.is_empty() { 8 } else { MAX_RESULTS }
} else {
56
})
.collect();
design = if app.sbox.text.trim().is_empty() { Vec::new() } else { design_rows(app, &app.sbox.text.clone()) };
}
let enabled: Vec<_> = rows
.iter()
.map(|r| solidcraft_engine::find_command(r.0).is_some_and(|c| c.info(&app.session).enabled))
.chain(design.iter().map(|_| true))
.take(MAX_RESULTS)
.collect();
if down || up {
let step = if down { 1 } else { enabled.len().saturating_sub(1) };
for _ in 0..enabled.len() {
app.sbox.index = (app.sbox.index + step) % enabled.len().max(1);
if enabled.get(app.sbox.index).copied().unwrap_or(false) {
break;
}
}
}
app.sbox.index = app.sbox.index.min(enabled.len().saturating_sub(1));
if !enabled.get(app.sbox.index).copied().unwrap_or(false) {
app.sbox.index = enabled.iter().position(|v| *v).unwrap_or(0);
}
ui_kit::Menu::show(ui, width, |ui| {
egui::ScrollArea::vertical().max_height((height - t.control_height * 4.0).max(t.control_height)).show(ui, |ui| {
if let Some((id, result)) = &mode {
let mut row = ui_kit::MenuItem::new(
"search:run",
crate::i18n::tr("search.run"),
solidcraft_engine::find_command(id).map_or("", |c| c.icon),
);
row.enabled = result.is_ok();
row.highlighted = true;
let badge = crate::i18n::tr(if result.is_ok() { "search.valid" } else { "search.invalid" });
row.shortcut = badge;
if row
.search_row(ui, "", id, Some(if result.is_ok() { ui_kit::SearchBadge::Valid } else { ui_kit::SearchBadge::Invalid }))
.clicked()
let response =
crate::frame::area(egui::Id::new("sc_sbox")).fixed_pos(pos).order(egui::Order::Foreground).fade_in(false).constrain(false).show(ctx, |ui| {
// Area rounds its origin; place the child at the exact interpolated bounds
// so the field's right edge does not drift during expansion.
ui.scope_builder(egui::UiBuilder::new().max_rect(Rect::from_min_size(pos, vec2(field_size.x, height + field_size.y))), |ui| {
ui.set_width(field_size.x);
ui.spacing_mut().item_spacing.y = 0.0;
ui_kit::scope(ui, |ui| {
ui.spacing_mut().item_spacing.y = 0.0;
let invalid = typed(&query).is_some_and(|(_, result)| result.is_err());
let field =
ui_kit::CommandSearch::field(ui, &mut query, invalid, std::mem::take(&mut app.sbox.focus), open, field_size.y, MAX_QUERY);
if !open && progress == 0.0 {
if field.clicked()
|| ui.interact(Rect::from_min_size(pos, field_size), ui.id().with("search_open"), egui::Sense::click()).clicked()
{
picked = Some(0);
app.start("ui.palette");
ctx.request_repaint();
}
match result {
Ok(params) => {
ui_kit::CommandSearch::detail(ui, &format!("{id}\n{}", serde_json::to_string_pretty(params).unwrap_or_default()))
}
Err(error) => {
ui_kit::text(ui, error, ui_kit::Text::Error("command_parameters"));
return;
}
if field.changed() {
app.sbox.index = 0;
}
mode = typed(&query).map(|(id, result)| (id.to_owned(), result));
if mode.is_none() {
rows = search(app, &query)
.into_iter()
.filter(|r| {
!query.trim().is_empty()
|| (app.sbox.recent.is_empty() && app.sbox.pinned.is_empty())
|| app.sbox.recent.iter().chain(&app.sbox.pinned).any(|id| id == r.0)
})
.take(if query.trim().is_empty() {
if app.sbox.recent.is_empty() && app.sbox.pinned.is_empty() { 8 } else { MAX_RESULTS }
} else {
56
})
.collect();
design = if query.trim().is_empty() { Vec::new() } else { design_rows(app, &query) };
}
let enabled: Vec<_> = rows
.iter()
.map(|r| solidcraft_engine::find_command(r.0).is_some_and(|c| c.info(&app.session).enabled))
.chain(design.iter().map(|_| true))
.take(MAX_RESULTS)
.collect();
if down || up {
let step = if down { 1 } else { enabled.len().saturating_sub(1) };
for _ in 0..enabled.len() {
app.sbox.index = (app.sbox.index + step) % enabled.len().max(1);
if enabled.get(app.sbox.index).copied().unwrap_or(false) {
break;
}
}
} else {
let empty = app.sbox.text.trim().is_empty();
let mut last_recent = None;
for (index, (id, label, icon, place)) in rows.iter().enumerate() {
let recent = empty && app.sbox.recent.iter().any(|r| r == id);
if last_recent != Some(recent) {
let count = rows.iter().filter(|r| (empty && app.sbox.recent.iter().any(|id| id == r.0)) == recent).count();
ui_kit::CommandSearch::heading(ui, if recent { "search.recent" } else { "search.commands" }, count);
last_recent = Some(recent);
}
let mut item = ui_kit::MenuItem::new(id, label, icon);
item.enabled = enabled.get(index).copied().unwrap_or(false);
item.highlighted = index == app.sbox.index;
let shortcut = crate::keymap::effective(app, id).unwrap_or_default();
item.shortcut = &shortcut;
let path = place.map_or_else(|| id.to_string(), |(tab, panel)| format!("{tab} › {panel}"));
let response = item.search_row(ui, &app.sbox.text, &path, None);
if item.highlighted && (up || down) {
ui.scroll_to_rect(response.rect, None);
}
if response.clicked() {
picked = Some(index);
}
if response.secondary_clicked() {
menu = Some((response.rect.left_bottom(), (*id).to_owned()));
}
}
if !design.is_empty() {
ui_kit::CommandSearch::heading(ui, "search.design", design.len());
}
for (index, row) in design.iter().enumerate() {
let handle = format!("search:design:{index}");
let mut item = ui_kit::MenuItem::new(&handle, &row.label, row.icon);
item.highlighted = app.sbox.index == rows.len() + index;
let badge = crate::i18n::tr(match row.target {
DesignTarget::Feature(_) => "search.feature",
DesignTarget::Parameter(_) => "search.parameter",
});
item.shortcut = badge;
let response = item.search_row(ui, &app.sbox.text, &row.detail, Some(ui_kit::SearchBadge::Kind));
if item.highlighted && (up || down) {
ui.scroll_to_rect(response.rect, None);
}
if response.clicked() {
picked = Some(rows.len() + index);
}
}
if rows.is_empty() && design.is_empty() {
ui.add_space(t.space_16);
ui.with_layout(egui::Layout::top_down(egui::Align::Center), |ui| {
ui_kit::text(
ui,
&crate::i18n::format("search.no_match", &[("query", &app.sbox.text)]),
ui_kit::Text::Heading("search_no_match"),
);
if let Some(label) = closest(&app.sbox.text) {
ui_kit::text(
ui,
&crate::i18n::format("search.suggest", &[("label", label)]),
ui_kit::Text::Report("search_suggest", false),
}
app.sbox.index = app.sbox.index.min(enabled.len().saturating_sub(1));
if !enabled.get(app.sbox.index).copied().unwrap_or(false) {
app.sbox.index = enabled.iter().position(|v| *v).unwrap_or(0);
}
ui.add_enabled_ui(open, |ui| {
ui_kit::CommandSearch::sheet(ui, field_size.x, progress, mode.is_some(), |ui| {
egui::ScrollArea::vertical().max_height((height - t.control_height * 4.0).max(t.control_height)).show(ui, |ui| {
if let Some((id, result)) = &mode {
let mut row = ui_kit::MenuItem::new(
"search:run",
crate::i18n::tr("search.run"),
solidcraft_engine::find_command(id).map_or("", |c| c.icon),
);
row.enabled = result.is_ok();
row.highlighted = true;
let badge = crate::i18n::tr(if result.is_ok() { "search.valid" } else { "search.invalid" });
row.shortcut = badge;
if row
.search_row(
ui,
"",
id,
Some(if result.is_ok() { ui_kit::SearchBadge::Valid } else { ui_kit::SearchBadge::Invalid }),
)
.clicked()
{
picked = Some(0);
}
match result {
Ok(params) => ui_kit::CommandSearch::detail(
ui,
&format!("{id}\n{}", serde_json::to_string_pretty(params).unwrap_or_default()),
),
Err(error) => {
ui_kit::text(ui, error, ui_kit::Text::Error("command_parameters"));
}
}
} else {
let empty = query.trim().is_empty();
let mut last_recent = None;
for (index, (id, label, icon, place)) in rows.iter().enumerate() {
let recent = empty && app.sbox.recent.iter().any(|r| r == id);
if last_recent != Some(recent) {
let count =
rows.iter().filter(|r| (empty && app.sbox.recent.iter().any(|id| id == r.0)) == recent).count();
ui_kit::CommandSearch::heading(ui, if recent { "search.recent" } else { "search.commands" }, count);
last_recent = Some(recent);
}
let mut item = ui_kit::MenuItem::new(id, label, icon);
item.enabled = enabled.get(index).copied().unwrap_or(false);
item.highlighted = index == app.sbox.index;
let shortcut = crate::keymap::effective(app, id).unwrap_or_default();
item.shortcut = &shortcut;
let path = place.map_or_else(|| id.to_string(), |(tab, panel)| format!("{tab} › {panel}"));
let response = item.search_row(ui, &query, &path, None);
if item.highlighted && (up || down) {
ui.scroll_to_rect(response.rect, None);
}
if response.clicked() {
picked = Some(index);
}
if response.secondary_clicked() {
menu = Some((response.rect.left_bottom(), (*id).to_owned()));
}
}
if !design.is_empty() {
ui_kit::CommandSearch::heading(ui, "search.design", design.len());
}
for (index, row) in design.iter().enumerate() {
let handle = format!("search:design:{index}");
let mut item = ui_kit::MenuItem::new(&handle, &row.label, row.icon);
item.highlighted = app.sbox.index == rows.len() + index;
let badge = crate::i18n::tr(match row.target {
DesignTarget::Feature(_) => "search.feature",
DesignTarget::Parameter(_) => "search.parameter",
});
item.shortcut = badge;
let response = item.search_row(ui, &query, &row.detail, Some(ui_kit::SearchBadge::Kind));
if item.highlighted && (up || down) {
ui.scroll_to_rect(response.rect, None);
}
if response.clicked() {
picked = Some(rows.len() + index);
}
}
if rows.is_empty() && design.is_empty() {
ui.add_space(t.space_16);
ui.with_layout(egui::Layout::top_down(egui::Align::Center), |ui| {
ui_kit::text(
ui,
&crate::i18n::format("search.no_match", &[("query", &query)]),
ui_kit::Text::Heading("search_no_match"),
);
if let Some(label) = closest(&query) {
ui_kit::text(
ui,
&crate::i18n::format("search.suggest", &[("label", label)]),
ui_kit::Text::Report("search_suggest", false),
);
}
});
ui.add_space(t.space_8);
}
if empty {
ui_kit::text(
ui,
&crate::i18n::format("search.try", &[("example", r#"solid.extrude {"distance": 20}"#)]),
ui_kit::Text::Note("search_try"),
);
}
}
});
ui.add_space(t.space_8);
}
if empty {
ui_kit::text(
ui,
&crate::i18n::format("search.try", &[("example", r#"solid.extrude {"distance": 20}"#)]),
ui_kit::Text::Note("search_try"),
);
}
}
});
});
});
ui_kit::CommandSearch::footer(ui, mode.is_some());
});
});
});
crate::scenario::publish_target("ribbon:search_popup", response.response.rect);
crate::scenario::publish_target("palette:outer", response.response.rect);
if !open {
return;
}
app.sbox.text = query;
app.sbox.closing_text = app.sbox.text.clone();
if let Some((at, id)) = menu {
crate::context_menu::open_for(app, at, crate::context_menu::Target::ToolbarCommand { id });
return;
@@ -516,6 +565,9 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
if esc || outside {
close(app);
}
if app.ui.palette_open != open {
ctx.request_repaint();
}
}
#[cfg(test)]
@@ -740,6 +792,82 @@ mod tests {
h.call("ui.palette", json!({"open":false}));
assert!(!h.app.ui.palette_open);
}
#[test]
fn ribbon_field_is_one_editor_and_interpolates_with_anchored_right_edge() {
let mut h = crate::scenario::Harness::new();
h.app.home.open = false;
h.frames(3);
let closed = crate::scenario::rect_of("ribbon:search").unwrap();
assert_eq!(closed.height(), 28.0);
assert!(closed.width() < 520.0);
h.call("ui.palette", json!({}));
h.frame();
let middle = crate::scenario::rect_of("ribbon:search").unwrap();
assert!(middle.width() > closed.width() && middle.width() < 520.0, "{closed:?} -> {middle:?}");
assert!(middle.height() > 28.0 && middle.height() < 40.0, "{middle:?}");
let width_fraction = (middle.width() - closed.width()) / (520.0 - closed.width());
let height_fraction = (middle.height() - 28.0) / 12.0;
assert!((width_fraction - height_fraction).abs() < 0.001);
assert_eq!(middle.right(), closed.right());
let unfolding = crate::scenario::rect_of("ribbon:search_popup").unwrap();
assert_eq!(unfolding.top(), middle.bottom());
h.frames(10);
let field = crate::scenario::rect_of("ribbon:search").unwrap();
assert_eq!(field.size(), vec2(520.0, 40.0));
assert_eq!(field.right(), closed.right());
assert_eq!(Some(field), crate::scenario::rect_of("shortcut:search"));
assert_eq!(Some(field), crate::scenario::rect_of("palette:search"));
let sheet = crate::scenario::rect_of("ribbon:search_popup").unwrap();
assert_eq!(sheet.top(), field.bottom());
assert_eq!(sheet.x_range(), field.x_range());
assert!(sheet.height() > unfolding.height());
let footer = crate::scenario::rect_of("ribbon:search_footer").unwrap();
assert_eq!(footer, Rect::from_min_max(pos2(sheet.left(), footer.top()), sheet.right_bottom()));
// Inspect native accessibility widgets, not just aliases or painted labels.
let nodes = &h.output.accesskit_update.as_ref().unwrap().nodes;
let search_edit = h.ctx.read_response(egui::Id::new("sc_sbox_text")).unwrap().rect;
let fields: Vec<_> = nodes
.iter()
.filter(|(_, n)| n.role() == egui::accesskit::Role::TextInput)
.filter(|(_, n)| n.bounds().is_some_and(|b| b.y0 >= f64::from(field.top()) && b.y1 <= f64::from(sheet.bottom())))
.collect();
assert_eq!(fields.len(), 1, "one editor in the field and sheet: {fields:?}");
assert!(field.contains_rect(search_edit));
let editor_id = fields[0].0;
h.step(&json!({"key":"Escape"})).unwrap();
h.frame();
let shrinking = crate::scenario::rect_of("ribbon:search").unwrap();
assert!(shrinking.width() > closed.width() && shrinking.width() < field.width());
assert!(shrinking.height() > 28.0 && shrinking.height() < 40.0);
assert_eq!(shrinking.right(), closed.right());
h.frames(10);
assert_eq!(crate::scenario::rect_of("ribbon:search").unwrap(), closed);
h.step(&json!({"click":{"handle":"ribbon:search"}})).unwrap();
h.frames(10);
assert!(h.app.ui.palette_open);
let nodes = &h.output.accesskit_update.as_ref().unwrap().nodes;
assert!(nodes.iter().any(|(id, n)| *id == editor_id && n.role() == egui::accesskit::Role::TextInput));
}
#[test]
fn search_respects_instant_animation_and_click_away_reverses_it() {
let mut h = crate::scenario::Harness::new();
h.app.home.open = false;
h.ctx.global_style_mut(|style| style.animation_time = 0.0);
h.frames(3);
let closed = crate::scenario::rect_of("ribbon:search").unwrap();
h.step(&json!({"click":{"handle":"ribbon:search"}})).unwrap();
h.frames(2);
assert!(h.app.ui.palette_open);
let field = crate::scenario::rect_of("ribbon:search").unwrap();
assert_eq!(field.size(), vec2(520.0, 40.0));
assert_eq!(field.right(), closed.right());
h.step(&json!({"click":[10,600]})).unwrap();
h.frames(2);
assert!(!h.app.ui.palette_open);
assert_eq!(crate::scenario::rect_of("ribbon:search").unwrap(), closed);
}
#[test]
fn saved_pins_remain_visible_without_a_query_or_recent_commands() {
let mut h = crate::scenario::Harness::new();
+3 -23
View File
@@ -794,29 +794,9 @@ fn ribbon_tabs(app: &mut SolveApp, ui: &mut egui::Ui, row: Rect) {
pos2((row.right() - search_width - inset).max(row.left()), row.top() + inset),
vec2(search_width, TAB_ROW_HEIGHT - 2.0 * inset),
);
let resp = ui.interact(search, ui.id().with("ribbon_search"), Sense::click());
crate::scenario::publish_target("ribbon:search", search);
ui.ctx().data_mut(|d| d.insert_temp(egui::Id::new("sc_ribbon_search"), search));
ui.painter().rect(search, corner, t.field, Stroke::new(1.0, t.border), egui::StrokeKind::Inside);
// The existing zoom glyph is the icon system's magnifier; no new artwork.
icons::paint_icon(ui.painter(), Rect::from_center_size(search.left_center() + vec2(12.0, 0.0), vec2(16.0, 16.0)), "zoom", 1.0);
let label = app.tr_label("Search commands");
if search_width > 24.0 {
ui.painter().text(
search.left_center() + vec2(29.0, 0.0),
Align2::LEFT_CENTER,
label,
FontId::proportional(crate::theme::Tokens::get().font_label),
t.text_dim,
);
let cap = Rect::from_center_size(search.right_center() - vec2(14.0, 0.0), vec2(16.0, 16.0));
ui.painter().rect(cap, 3.0, t.toolbar, Stroke::new(1.0, t.border), egui::StrokeKind::Inside);
ribbon_text(ui, cap.center(), "S", t.font_small, t.text_dim, false);
}
resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, label));
if resp.on_hover_text(label).clicked() {
app.start("ui.palette");
}
// The single editor is drawn on the foreground layer by shortcut_box::show, so it
// can grow over the ribbon without being clipped to the tab row.
ui.ctx().data_mut(|d| d.insert_temp(egui::Id::new("sc_ribbon_search"), search.with_max_y(search.top() + t.control_height)));
let changed = ui.ctx().data_mut(|d| {
let id = egui::Id::new("sc_ribbon_visible_tab");
let state = (app.ui.tab.clone(), row.width());
+90 -3
View File
@@ -30,8 +30,8 @@ macro_rules! element {
const ELEMENTS: &[Element] = &[
element!("command_search", |ui, _| {
let mut query = "fillet".to_owned();
CommandSearch::field(ui, &mut query, false, true, 4096);
Menu::show(ui, ui.available_width(), |ui| {
CommandSearch::field(ui, &mut query, false, true, true, Tokens::get().control_height + Tokens::get().space_12, 4096);
CommandSearch::sheet(ui, ui.available_width(), 1.0, false, |ui| {
CommandSearch::heading(ui, "search.commands", 1);
let c = solidcraft_engine::find_command("solid.fillet").unwrap();
let mut row = MenuItem::new(c.id, c.label, c.icon);
@@ -39,7 +39,6 @@ const ELEMENTS: &[Element] = &[
row.shortcut = "F";
row.search_row(ui, &query, "MODEL › MODIFY", None);
CommandSearch::detail(ui, "radius 6 mm");
CommandSearch::footer(ui, false);
});
}),
element!("menu", |ui, _| {
@@ -1141,7 +1140,12 @@ fn command_search_board_in_both_themes() {
let popup = scenario::rect_of("ribbon:search_popup").unwrap();
let field = scenario::rect_of("shortcut:search").unwrap();
assert_eq!(field.height(), 40.0);
assert_eq!(field.width(), 520.0);
assert_eq!(popup.width(), 520.0);
assert_eq!(popup.top(), field.bottom());
assert_eq!(popup.x_range(), field.x_range());
let footer = scenario::rect_of("ribbon:search_footer").unwrap();
assert_eq!(footer, egui::Rect::from_min_max(egui::pos2(popup.left(), footer.top()), popup.right_bottom()));
assert!(bounds.contains_rect(popup), "{state}: {popup:?}");
match state {
"matches" => {
@@ -1292,3 +1296,86 @@ fn confirm_radial_and_menu_danger_keep_multitone_artwork() {
}
crate::theme::set_dark(previous);
}
/// Run the application UI, including the ribbon, and optionally save each transition.
#[test]
fn command_search_ribbon_transition_clips_content_in_both_themes() {
use super::checks::tests::{raster, textures_update};
use std::collections::HashMap;
let previous = crate::theme::is_dark();
for dark in [false, true] {
crate::theme::set_dark(dark);
let ctx = crate::fonts::test_context();
ctx.set_visuals(if dark { egui::Visuals::dark() } else { egui::Visuals::light() });
let mut app = crate::test_support::sample_app();
app.home.open = false;
app.ui.dark = dark;
let bounds = egui::Rect::from_min_size(egui::Pos2::ZERO, vec2(1600.0, 1000.0));
let mut textures = HashMap::new();
let mut closed = egui::Rect::NOTHING;
for frame in 0..26 {
if frame == 3 {
crate::shortcut_box::open(&mut app, None);
app.sbox.text = "fillet".into();
} else if frame == 14 {
app.ui.palette_open = false;
app.sbox.text.clear();
}
scenario::clear_handles();
let mut output = ctx.run_ui(
egui::RawInput { screen_rect: Some(bounds), time: Some(f64::from(frame) / 60.0), focused: true, ..Default::default() },
|ui| {
app.logic(ui.ctx());
app.ui(ui);
},
);
textures_update(&mut textures, &output.textures_delta);
output.textures_delta.clear();
let field = scenario::rect_of("ribbon:search").unwrap();
if frame == 2 {
closed = field;
}
if (3..14).contains(&frame) {
let sheet = scenario::rect_of("ribbon:search_popup").unwrap();
assert_eq!(sheet.top(), field.bottom());
// Actual result text is painted with the unfolding sheet's clip,
// rather than relying on a smaller background hiding overflow.
let mut result_texts = 0;
for shape in &output.shapes {
if let egui::Shape::Text(text) = &shape.shape
&& text.galley.job.text.contains("Fillet")
&& text.pos.y >= sheet.top()
&& text.pos.x >= sheet.left()
&& text.pos.x < sheet.right()
{
result_texts += 1;
assert!(shape.clip_rect.bottom() <= sheet.bottom() + 0.5, "{frame}: {:?} vs {sheet:?}", shape.clip_rect);
}
}
if frame == 12 {
assert!(result_texts > 0);
}
}
let state = match frame {
2 => Some("closed"),
4 => Some("opening"),
12 => Some("open"),
15 => Some("closing"),
25 => Some("closed-again"),
_ => None,
};
if frame == 12 {
assert_eq!(field.size(), vec2(520.0, 40.0));
assert_eq!(field.right(), closed.right());
} else if frame == 25 {
assert_eq!(field, closed);
}
if let (Some(state), Ok(dir)) = (state, std::env::var("SOLIDCRAFT_SEARCH_EVIDENCE")) {
std::fs::create_dir_all(&dir).unwrap();
let image = raster(&ctx, output.shapes, output.pixels_per_point, bounds, &textures);
image.save(std::path::Path::new(&dir).join(format!("ribbon-{state}-{}.png", if dark { "dark" } else { "light" }))).unwrap();
}
}
}
crate::theme::set_dark(previous);
}
+65 -13
View File
@@ -1,4 +1,4 @@
//! Command-search composition: a taller editor and two-line MenuItem variant.
//! Command-search composition: one expanding ribbon editor and a clipped results sheet.
//! Domain ranking and command dispatch stay with the caller.
use crate::{icons, theme::Tokens};
use egui::{FontId, Rect, Response, Sense, Stroke, Ui, pos2, vec2};
@@ -18,11 +18,10 @@ impl CommandSearch {
t.form_card_width * 2.0 - t.space_8
}
pub(crate) fn field(ui: &mut Ui, value: &mut String, invalid: bool, focus: bool, limit: usize) -> Response {
pub(crate) fn field(ui: &mut Ui, value: &mut String, invalid: bool, focus: bool, open: bool, height: f32, limit: usize) -> Response {
let t = Tokens::get();
let height = t.control_height + t.space_12;
let (r, _) = ui.allocate_exact_size(vec2(ui.available_width(), height), Sense::hover());
let focused = focus || ui.memory(|m| m.has_focus(egui::Id::new("sc_sbox_text")));
let focused = open && (focus || ui.memory(|m| m.has_focus(egui::Id::new("sc_sbox_text"))));
let ink = if invalid {
t.form_error
} else if focused {
@@ -36,21 +35,28 @@ impl CommandSearch {
ui.painter().rect(r, t.radius_xl, t.control_fill, Stroke::new(1.0, ink), egui::StrokeKind::Inside);
icons::paint_icon(
ui.painter(),
Rect::from_center_size(r.left_center() + vec2(t.space_12 + t.space_8, 0.0), vec2(t.space_16, t.space_16)),
Rect::from_center_size(r.left_center() + vec2((t.space_12 + t.space_8).min(r.width() / 2.0), 0.0), vec2(t.space_16, t.space_16)),
"zoom",
1.0,
);
let cap = if value.is_empty() { "S" } else { "Esc" };
Self::key(ui, r.right_center() - vec2(t.space_10, 0.0), cap);
let editor = Rect::from_min_max(r.min + vec2(t.space_24 + t.space_16, 0.0), r.max - vec2(t.space_24 * 2.0, 0.0));
let cap = if open { "Esc" } else { "S" };
if r.width() > t.space_24 {
Self::key(ui, r.right_center() - vec2(t.space_10, 0.0), cap);
}
let editor = Rect::from_min_max(
pos2((r.left() + t.space_24 + t.space_16).min(r.right()), r.top()),
pos2((r.right() - t.space_24 * 2.0).max((r.left() + t.space_24 + t.space_16).min(r.right())), r.bottom()),
);
let mono = value.contains('{');
let response = ui
.scope_builder(egui::UiBuilder::new().max_rect(editor), |ui| {
ui.set_clip_rect(ui.clip_rect().intersect(editor));
ui.add_sized(
editor.size(),
super::fields::text_input(egui::TextEdit::singleline(value))
.id(egui::Id::new("sc_sbox_text"))
.char_limit(limit)
.interactive(open)
.frame(egui::Frame::NONE)
.hint_text(crate::i18n::tr_label("Search commands"))
.font(if mono { FontId::monospace(t.font_label) } else { FontId::proportional(t.font_button) }),
@@ -60,6 +66,7 @@ impl CommandSearch {
if focus {
response.request_focus();
}
crate::scenario::publish_target("ribbon:search", r);
crate::scenario::publish_target("shortcut:search", r);
crate::scenario::publish_target("palette:search", r);
response
@@ -89,14 +96,59 @@ impl CommandSearch {
);
}
pub(crate) fn footer(ui: &mut Ui, command: bool) {
/// Lay out the full sheet, but allocate and paint only its unfolding height. The
/// remembered natural height is refreshed with a sizing pass when results change.
pub(crate) fn sheet(ui: &mut Ui, width: f32, progress: f32, command: bool, add: impl FnOnce(&mut Ui)) -> Rect {
let t = Tokens::get();
ui.add_space(t.space_6);
ui.painter().hline(ui.available_rect_before_wrap().x_range(), ui.cursor().top(), Stroke::new(1.0, t.dialog_rule));
egui::Frame::NONE.fill(t.dialog_footer).inner_margin(t.space_6).show(ui, |ui| {
ui.set_min_width((ui.available_width() - t.space_12).max(0.0));
let id = ui.id().with("search_sheet_height");
let known = ui.ctx().data(|d| d.get_temp::<f32>(id)).unwrap_or(0.0);
let origin = ui.cursor().min;
let clip = Rect::from_min_size(origin, vec2(width, known * progress));
let background = ui.painter().add(egui::Shape::Noop);
let mut child =
ui.new_child(egui::UiBuilder::new().id_salt("search_sheet").max_rect(Rect::from_min_size(origin, vec2(width, ui.available_height()))));
child.set_clip_rect(ui.clip_rect().intersect(clip));
child.spacing_mut().item_spacing.y = 0.0;
egui::Frame::NONE.inner_margin(egui::Margin { left: t.space_6 as i8, right: t.space_6 as i8, top: t.space_4 as i8, bottom: 0 }).show(
&mut child,
|ui| {
ui.set_width((width - t.space_12).max(0.0));
add(ui);
},
);
child.add_space(t.space_6);
Self::footer(&mut child, command);
let natural = child.min_rect().height();
ui.ctx().data_mut(|d| d.insert_temp(id, natural));
if (known - natural).abs() > 0.5 {
ui.ctx().request_discard("command search sheet resized");
}
let sheet = Rect::from_min_size(origin, vec2(width, natural * progress));
let frame = super::Menu::frame().inner_margin(0);
ui.painter().set(background, frame.paint(sheet.shrink(frame.stroke.width)));
// The edge-to-edge footer shares the card silhouette; keep the outer rule
// above its fill, as an overflow-clipped footer would in the board.
ui.painter().rect_stroke(sheet, t.radius_xl, frame.stroke, egui::StrokeKind::Inside);
ui.allocate_rect(sheet, Sense::hover());
crate::scenario::publish_target("ribbon:search_popup", sheet);
crate::scenario::publish_target("palette:outer", sheet);
sheet
}
fn footer(ui: &mut Ui, command: bool) {
let t = Tokens::get();
let start = ui.cursor().min;
let width = ui.available_width();
let background = ui.painter().add(egui::Shape::Noop);
egui::Frame::NONE.inner_margin(egui::Margin::symmetric(t.space_14 as i8, t.space_3 as i8)).show(ui, |ui| {
ui.set_width((width - t.space_14 * 2.0).max(0.0));
super::text(ui, crate::i18n::tr(if command { "search.command_keys" } else { "search.keys" }), super::Text::Note("search_keys"));
});
let r = Rect::from_min_max(start, pos2(start.x + width, ui.min_rect().bottom()));
ui.painter()
.set(background, egui::Shape::rect_filled(r, egui::CornerRadius { nw: 0, ne: 0, sw: t.radius_xl, se: t.radius_xl }, t.dialog_footer));
ui.painter().hline(r.x_range(), r.top(), Stroke::new(1.0, t.dialog_rule));
crate::scenario::publish_rect("ribbon:search_footer", r);
}
}
+14 -1
View File
@@ -92,22 +92,35 @@ fn docked_ribbon_geometry_and_search() {
assert_eq!(workspace.width(), 88.0);
assert_eq!(workspace.top(), ribbon.top());
assert_eq!(workspace.bottom(), ribbon.bottom() - 1.0);
assert_eq!(search.height(), 22.0);
assert_eq!(search.height(), 28.0);
assert_eq!(search.width(), if width == 1600.0 { 188.0 } else { 24.0 });
assert!(ribbon.contains_rect(search));
assert!(search.left() > workspace.right());
assert!(h.app.viewport.rect.unwrap().top() >= toolbar::APP_BAR_HEIGHT + toolbar::RIBBON_HEIGHT);
h.step(&json!({"click":{"handle":"ribbon:search"}})).unwrap();
assert!(h.app.ui.palette_open);
h.frames(10);
let field = rect_of("ribbon:search").unwrap();
assert_eq!(field.width(), 520.0_f32.min(width - 8.0));
assert_eq!(field.height(), 40.0);
assert_eq!(field.right(), search.right());
assert_eq!(Some(field), rect_of("shortcut:search"));
assert_eq!(Some(field), rect_of("palette:search"));
let popup = rect_of("ribbon:search_popup").unwrap();
assert_eq!(popup.top(), field.bottom());
assert_eq!(popup.x_range(), field.x_range());
assert!(popup.top() >= search.bottom());
assert!(popup.left() <= search.left());
h.step(&json!({"key":"Escape"})).unwrap();
assert!(!h.app.ui.palette_open);
h.frames(10);
assert_eq!(rect_of("ribbon:search").unwrap(), search);
h.step(&json!({"key":"S"})).unwrap();
assert!(h.app.ui.palette_open);
h.frames(10);
assert_eq!(rect_of("ribbon:search_popup").unwrap().min, popup.min);
h.step(&json!({"key":"Escape"})).unwrap();
h.frames(10);
}
h.call("ui.resize", json!({"width":1600,"height":1000}));
h.frames(4);
+16 -1
View File
@@ -57,7 +57,7 @@ table. Panel/Window/Confirm compositions also have dedicated geometry and intera
| Module / element | Use and options | Main tokens |
| --- | --- | --- |
| search: `CommandSearch`, `MenuItem::search_row` | Ribbon search composition: 40 pt bounded field, magnifier and S/Esc keycap, 38 pt two-line menu row with 26 pt icon tile, accent bold substring, path, shortcut/kind keycap, counts, JSON detail box and footer. The ordinary 30 pt menu row cannot fit a second line; this variant keeps its enabled/selected states and scenario IDs. Ranking and dispatch stay with the caller. | `form_card_width × 2 − space_8` (520 pt), `control_height`, `space_2/3/4/6/8/10/12/16/24`, `radius_xl/control_radius`, `control_fill`, `dialog_body/footer/rule/border`, `form_ink/dim/primary/error/error_fill/success/success_fill`, `selected_ink`, `accent_soft`, typography |
| search: `CommandSearch`, `MenuItem::search_row` | Ribbon search composition: one persistent ribbon editor expands from 28 to 40 pt and to 520 pt wide with its right edge anchored, magnifier and S/Esc keycap, 38 pt two-line menu row with 26 pt icon tile, accent bold substring, path, shortcut/kind keycap, counts, JSON detail box and footer. The ordinary 30 pt menu row cannot fit a second line; this variant keeps its enabled/selected states and scenario IDs. Ranking and dispatch stay with the caller. | `form_card_width × 2 − space_8` (520 pt), `control_height`, `space_2/3/4/6/8/10/12/14/16/24`, `radius_xl/control_radius`, `control_fill`, `dialog_body/footer/rule/border`, `form_ink/dim/primary/error/error_fill/success/success_fill`, `selected_ink`, `accent_soft`, typography |
| menu: `Menu`, `MenuItem` | Shared popup, 30 pt rows, 28 pt icon column, clipped labels, right-aligned mono shortcuts, submenu chevrons, checked/unchecked and document swatches, inert 40% disabled rows and danger ink; headings and separators; ribbon drag/pin targets retained | `dialog_body/border/rule`, `radius_xl`, `control_height/radius`, `form_ink/dim/primary/error`, `accent_soft`, typography and spacing |
| radial: `radial_menu` | Eight rounded annular sectors, parallel 4 pt gaps, 9 pt circular corner joins, tab-accent artwork and hover, centre label/key; existing hold/flick/release dispatch | `dialog_body/border`, `form_ink/dim`, `TabAccent`, icon palette, font/spacing tokens |
| panel: `Window`, `WindowPage` | Shared card frame, header, optional page list, bounded content and footer with a left action | `form_header/footer_height`, `form_card_width`, `form_label_width`, `control_height`, `dialog_footer/rule`, `selected_bg/ink`, spacing |
@@ -341,3 +341,18 @@ actual side endpoints at both radii and sample all four rounded corners. Optiona
CPU-rendered menu evidence can be produced without a window with
`SOLIDCRAFT_MENU_EVIDENCE=/tmp/menus cargo test -p solidcraft-ui-egui --lib menu_board_in_both_themes`.
Desktop interaction and visual acceptance still require a reviewer capture.
Command search uses the ribbon field itself (`sc_sbox_text`); `ribbon:search`,
`shortcut:search` and `palette:search` all identify that same field. Opening gives
it the accent focus ring, cursor and Esc keycap. The field and the attached results
sheet unfold in 120 ms with egui cubic ease-out, capped by egui's animation time
so instant settings remain instant. Esc, click away and command dispatch reverse
the animation. Only the visible sheet height participates in layout and hit testing;
result content is clipped while unfolding. The sheet's `ribbon:search_popup` /
`palette:outer` handles exclude the field. Its footer (`ribbon:search_footer`)
fills the bottom strip edge to edge, with rounded bottom corners and a 1 pt top
rule. Ranking, command mode and keyboard routing remain with the caller.
Generate CPU-rendered evidence of all five search states and the actual ribbon's
closed/opening/open/closing transition in both themes with
`SOLIDCRAFT_SEARCH_EVIDENCE=/tmp/search cargo test -p solidcraft-ui-egui --lib command_search`.