Merge pull request #4606 from dotCooCoo/fix/table-header-tip-and-about-resize

Tables: header tooltips name only what the column does; About credit columns resize
This commit is contained in:
BFlat authored and GitHub committed 2026-12-01 13:24:56 +07:00
commit 7d4f24b688
4 files changed
+82 -7

No files matched your search

@@ -418,7 +418,7 @@ impl Header {
let x = rect.min.x.clamp(view.min.x, view.max.x);
Rect::from_x_y_ranges(x..=rect.max.x.clamp(x, view.max.x), rect.y_range())
};
let help = pcx.words::<HeaderWords>().tip.clone();
let words = pcx.words::<HeaderWords>();
for (at, (spec, width)) in self.specs.iter().zip(widths).enumerate() {
let (rect, rest) = flow.take_start(width);
flow = rest;
@@ -432,7 +432,11 @@ impl Header {
}
let part = pcx.part(HEADER.at(hash), shown(rect)).sense(sense);
let part = if hosted { part } else { part.focusable() };
part.priority(HitPriority::new(HitLevel::Body, 0)).state_layer().tooltip(spec.tip.clone().unwrap_or_else(|| help.clone()));
let part = part.priority(HitPriority::new(HitLevel::Body, 0)).state_layer();
// The default tooltip names only what this cell does: a hosted cell neither sorts nor moves.
if let Some(tip) = spec.tip.clone().or_else(|| words.tip(spec.sortable && !hosted, spec.movable && !hosted, spec.resizable)) {
part.tooltip(tip);
}
if spec.resizable {
let edge = if rtl {
Rect::from_min_size(rect.min, Vec2::new(grip, rect.height()))
+18 -3
View File
@@ -1,9 +1,24 @@
//! `HeaderWords`: the words of a collection's header row.
craft_ui::words! {
/// The words of the header row.
/// The words of the header row. A header whose column gives no tooltip (`ColumnSpec::tip`) shows one sentence for
/// each thing the pointer does to it: `sort` when the column sorts, `move_column` when it moves and `resize` when
/// it resizes, in that order, and no tooltip when it does none of them.
pub struct HeaderWords {
/// A header's tooltip when its column gives none (`ColumnSpec::tip`).
tip: "table.headerTip" = "Click to sort, drag to move the column. Drag its edge to resize it.";
sort: "table.headerSort" = "Click to sort.";
move_column: "table.headerMove" = "Drag to move the column.";
resize: "table.headerResize" = "Drag its edge to resize it.";
}
}
impl HeaderWords {
/// The tooltip of a header cell whose column sorts, moves and resizes as the flags say, or `None` when it does none.
pub(crate) fn tip(&self, sortable: bool, movable: bool, resizable: bool) -> Option<crate::runtime::env::Label> {
let parts: Vec<&str> = [(sortable, &self.sort), (movable, &self.move_column), (resizable, &self.resize)]
.into_iter()
.filter(|(on, _)| *on)
.map(|(_, word)| word.as_str())
.collect();
(!parts.is_empty()).then(|| parts.join(" ").into())
}
}
@@ -592,7 +592,7 @@ impl Shown<'_> {
.iter()
.map(|key| {
let width = if *key == ContributorSort::Name { ColumnWidth::fill(1.0) } else { ColumnWidth::Content };
let mut column = ColumnSpec::new(key.column(), key.labels(words).1.clone(), width).sortable();
let mut column = ColumnSpec::new(key.column(), key.labels(words).1.clone(), width).sortable().resizable();
if key.numeric() {
column = column.numeric();
}
@@ -651,7 +651,7 @@ impl Shown<'_> {
.iter()
.map(|column| {
let width = if *column == ModelColumn::Company { ColumnWidth::fill(1.0) } else { ColumnWidth::Content };
let spec = ColumnSpec::new(column.key(), column.head(words), width);
let spec = ColumnSpec::new(column.key(), column.head(words), width).resizable();
if column.numeric() { spec.numeric() } else { spec }
})
.collect();
@@ -314,6 +314,62 @@ fn about_tab_is_a_field() {
assert_eq!(fields, Some(json!({ "tab": "contributors" })), "the field lists the tab a click picked");
}
/// The header cell of the column `head`.
fn header(fixture: &Fixture, head: &str) -> craft_ui::testing::Target {
fixture.by_role(Role::COLUMN_HEADER).into_iter().find(|cell| fixture.tree().name_of(cell.node) == Some(head)).expect("the table has the column")
}
/// Drags the end edge of the column `head` by `by` and returns the column's width before and after.
fn drag_edge(fixture: &mut Fixture, head: &str, by: f32) -> (f32, f32) {
let before = header(fixture, head).rect;
fixture.drag_at(egui::Pos2::new(before.max.x - 1.0, before.center().y), Vec2::new(by, 0.0)).idle(10);
(before.width(), header(fixture, head).rect.width())
}
/// The text the tooltip of the column `head` paints after the pointer rests on its header.
fn header_tip(fixture: &mut Fixture, head: &str) -> String {
use craft_ui::contract::tooltip::DELAY;
use craft_ui::testing::pointer;
let before: Vec<String> = fixture.texts().iter().map(|run| run.text.clone()).collect();
let cell = header(fixture, head);
fixture.frame(vec![pointer::moved(cell.rect.center())]);
fixture.advance(DELAY * 2.0).settle();
let mut fresh: Vec<String> = fixture.texts().iter().map(|run| run.text.clone()).filter(|text| !before.contains(text)).collect();
fresh.dedup();
fresh.join(" ")
}
/// The Models table's columns resize by a drag of a header's edge, and the header's tooltip names only that, since the
/// table neither sorts nor moves its columns.
#[trial]
fn the_models_tables_columns_resize_by_their_header_edge() {
let credits = Credits::new(Vec::new(), vec![ModelCredit::new("Anthropic", "Writer", "2").work(4, 100, 10)], 4);
let mut fixture = Fixture::new(move |ui| {
let _ = AboutDialog::new(&INFO, &credits).tab(Bind::given(AboutTab::Models)).show(ui);
});
fixture.room(Vec2::new(1400.0, 1000.0)).idle(30);
let (before, after) = drag_edge(&mut fixture, "Company", 60.0);
assert!(after > before + 30.0, "a drag of the Company edge widens the column: {before} to {after}");
let (before, after) = drag_edge(&mut fixture, "Company", -40.0);
assert!(after < before - 20.0, "a drag back narrows it: {before} to {after}");
assert_eq!(header_tip(&mut fixture, "Company"), "Drag its edge to resize it.", "the tooltip names only the resize");
}
/// The Contributors table's columns resize by a drag of a header's edge, and the header's tooltip names the sort and
/// the resize, without a move the table does not offer.
#[trial]
fn the_contributors_tables_columns_resize_by_their_header_edge() {
let mut fixture = Fixture::new(move |ui| {
let _ = AboutDialog::new(&INFO, &CREDITS).tab(Bind::given(AboutTab::Contributors)).show(ui);
});
fixture.room(Vec2::new(1400.0, 1000.0)).idle(30);
let table = fixture.by_label("Table").expect("the View control offers Table");
fixture.click(&table).idle(30);
let (before, after) = drag_edge(&mut fixture, "Name", 60.0);
assert!(after > before + 30.0, "a drag of the Name edge widens the column: {before} to {after}");
assert_eq!(header_tip(&mut fixture, "Name"), "Click to sort. Drag its edge to resize it.", "the tooltip names the sort and the resize");
}
/// Guards the app tabs of the About dialog: an app tab is listed after Models, `tab` takes its name and shows its
/// body, a click on it reports its name in the field, and a name that is neither built in nor an app tab's is refused.
#[trial]