From b5e0109bfe1622c4f866291b2dbb7926c9bd4f3b Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 22 Nov 2026 21:04:25 -0500 Subject: [PATCH] Table::plain_header_menu: the header menu lists Reset Columns without column commands (trial) --- crates/ui-widgets/src/table/view.rs | 7 ++++++- crates/ui-widgets/tests/it/table.rs | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/crates/ui-widgets/src/table/view.rs b/crates/ui-widgets/src/table/view.rs index 697e9edaf..452862b18 100644 --- a/crates/ui-widgets/src/table/view.rs +++ b/crates/ui-widgets/src/table/view.rs @@ -62,6 +62,10 @@ pub struct Table<'a, K: Clone + Eq + Hash + Send + Sync + 'static> { /// A tree: rows are indented by depth and groups open and close. #[prop] tree: bool, + /// The header menu lists the column choices and Reset Columns only, without the column commands (Resize Column, + /// Move Column Left and Right): a table whose columns the pointer arranges. + #[prop] + plain_header_menu: bool, /// Which rows may be renamed; a rename request on another row does nothing. #[prop(func = "Fn(&K) -> bool")] can_rename: Option>, @@ -91,6 +95,7 @@ impl<'a, K: Clone + Eq + Hash + Send + Sync + 'static> Table<'a, K> { column_layout: None, reveal: None, tree: false, + plain_header_menu: false, can_rename: None, rename_draft: None, can_drag: None, @@ -133,7 +138,7 @@ impl Component for Table<'_, K> { let (at, for_column) = (menu.at, menu.column.is_some()); let hidden = cx.hidden_columns().to_vec(); let hideable: Vec<_> = self.items.columns.iter().filter(|spec| spec.hideable).map(|spec| (spec.key.clone(), spec.header.clone())).collect(); - let commands: Vec<(ColumnCommands, bool)> = if for_column { + let commands: Vec<(ColumnCommands, bool)> = if for_column && !self.plain_header_menu { ColumnCommands::ALL.into_iter().map(|command| (command, cx.column_command_enabled(command))).collect() } else { Vec::new() diff --git a/crates/ui-widgets/tests/it/table.rs b/crates/ui-widgets/tests/it/table.rs index 23826147c..ef9a351df 100644 --- a/crates/ui-widgets/tests/it/table.rs +++ b/crates/ui-widgets/tests/it/table.rs @@ -391,3 +391,25 @@ fn columns_wider_than_the_table_keep_their_least_width_scroll_sideways_with_the_ assert!(moved_cell > 1.0, "the wheel scrolls the columns sideways: {moved_cell}"); assert!((moved_cell - moved_text).abs() < 0.5, "the header scrolls with the rows: header {moved_cell}, row {moved_text}"); } + +/// Production's header menu lists Reset Columns and no column commands: a table can ask for that menu. +#[trial] +fn a_plain_header_menu_lists_no_column_commands() { + let mut fixture = Fixture::new(|ui| { + let columns = vec![ + ColumnSpec::new(NAME, "Name", ColumnWidth::Controls(6.0)).movable(), + ColumnSpec::new(DATE, "Date", ColumnWidth::Controls(4.0)).movable(), + ]; + let keys = [0_usize, 1]; + let source = keyed(&keys, |key: &usize| *key); + Table::new("Files", columns) + .plain_header_menu(true) + .show_items(ui, &source, &mut |key, icx| ListRow::new(format!("File {key}")).cells(icx.cells())); + }); + fixture.in_room(Room::Dialog).settle(); + let name = fixture.by_label("Name").expect("the header cell").center(); + secondary_click(&mut fixture, name); + assert!(menu_row(&fixture, Role::MENU_ITEM, "Reset Columns").is_some(), "the menu opens with Reset Columns"); + assert!(menu_row(&fixture, Role::MENU_ITEM, "Move Column Right").is_none(), "no column commands"); + assert!(menu_row(&fixture, Role::MENU_ITEM, "Resize Column…").is_none(), "no Resize Column"); +}