mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 02:09:00 +00:00
Table::plain_header_menu: the header menu lists Reset Columns without column commands (trial)
This commit is contained in:
@@ -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<RowTest<'a, K>>,
|
||||
@@ -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<K: Clone + Eq + Hash + Send + Sync + 'static> 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()
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user