Merge pull request #9294 from dotCooCoo/fix/dialog-list-max-rows

Dialogs: lists inside a scrolling body cap their rows, so debug builds draw them
This commit is contained in:
BFlat authored and GitHub committed 2026-11-25 18:20:23 +07:00
commit e21aec705f
10 files changed
+113 -16

No files matched your search

+20 -1
View File
@@ -31,6 +31,8 @@ pub const KIND: &str = "nearestSwatch";
/// The query that lists the matches, and how many of each colour's the dialog shows.
const FIND: &str = "addon.color.nearestSwatch";
const MATCHES: u64 = 3;
/// The rows the match list shows before it scrolls.
const LIST_ROWS: u16 = 12;
/// What the query read: the document and its revision, the library, Fill and Stroke. An answer
/// stands while these are what the dialog shows now.
@@ -155,7 +157,8 @@ fn body(ui: &mut Ui, fields: &mut Fields, libraries: &[Entry<String>], selected:
let lines = lines(found);
let keys: Vec<usize> = (0..lines.len()).collect();
let source = keyed(&keys, |i| *i);
List::<usize>::new(label(tl!("Find Nearest Swatch"))).select(SelectMode::None).show_items(ui, &source, &mut |&i, item| match lines.get(i) {
let list = List::<usize>::new(label(tl!("Find Nearest Swatch"))).select(SelectMode::None).max_rows(LIST_ROWS);
list.show_items(ui, &source, &mut |&i, item| match lines.get(i) {
Some(line) => {
let face = SwatchFace::new(line.color);
let row = ListRow::new(line.text.clone())
@@ -267,4 +270,20 @@ mod tests {
assert!(!host(&app, |h| h.confirm_by_id(&ctx, id)), "Apply is off");
assert!(host(&app, |h| h.is_open::<NearestDialog>()));
}
#[test]
fn find_nearest_swatch_draws_its_matches_and_buttons() {
let mut app = crate::testing::windowed(VectorcraftApp::new(Session::new(), Default::default()));
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
app.run("swatch.new", json!({"name": "Brand", "color": "#ff8000", "global": true})).unwrap();
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 40, "height": 40})).unwrap();
app.run("paint.setFill", json!({"color": "#ff8010"})).unwrap();
let mut p = crate::tests::panel_harness::Panel::new(app, crate::tests::picks::dialogs);
menus::invoke(&mut p.app(), COMMAND, serde_json::Value::Null);
p.frame();
p.frame();
for name in ["Brand", "Apply", "Cancel"] {
assert!(p.shows(name), "{name} is drawn");
}
}
}
+3
View File
@@ -33,6 +33,8 @@ pub const COMMAND: &str = "addon.select.byArtboards";
pub const KIND: &str = "selectByArtboards";
/// The relations the dialog offers: (value, label).
const RELATIONS: [(&str, &str); 3] = [("overlap", "Overlapping"), ("inside", "Fully Inside"), ("outside", "Fully Outside")];
/// The rows the artboard list shows before it scrolls.
const LIST_ROWS: u16 = 9;
/// Object › Plug-ins › Selection Tools.
pub fn menu() -> Vec<Node> {
@@ -170,6 +172,7 @@ fn body(ui: &mut Ui, fields: &mut Fields, rows: &[(String, String)], go_to: &mut
.allow_empty(true)
.activate(ActivateOn::DoubleClick)
.empty(label(tl!("No artboards match.")))
.max_rows(LIST_ROWS)
.selection(Bind::bound(&mut selection))
.show_items(ui, &source, &mut |&i, item| match rows.get(i) {
Some((name, size)) => {
@@ -46,6 +46,8 @@ pub const STATUSES: [(&str, &str, &str); 4] = [
];
/// The dialog's Show choices: (value, label).
const SHOW: [(&str, &str); 5] = [("all", "All"), ("linked", "Linked"), ("embedded", "Embedded"), ("missing", "Missing"), ("modified", "Modified")];
/// The rows the image table shows before it scrolls.
const LIST_ROWS: u16 = 9;
/// How often the statuses are looked at again while the document stays as it is (s): files
/// change on disk without the document knowing.
const RECHECK: f64 = 2.0;
@@ -317,6 +319,7 @@ fn body(ui: &mut Ui, fields: &mut Fields, rows: &[Value]) {
let out = Table::<u64>::new(label(tl!("Select by Link Status")), columns)
.select(SelectMode::None)
.empty(label(tl!("No images match.")))
.max_rows(LIST_ROWS)
.show_items(ui, &source, &mut |id, item| match lines.iter().find(|line| line.id == *id) {
Some(line) => ListRow::new(line.name.clone())
.cells(item.cells())
@@ -197,6 +197,18 @@ fn links_inside_a_symbol_are_left_out_of_selecting_by_status() {
assert_eq!(host(&app, |h| h.get::<LinkStatusDialog>().map(|d| d.rows.len())), Some(0), "the dialog lists no row of the symbol");
}
#[test]
fn the_dialog_draws_its_images_and_buttons() {
let dir = Folder::new("drawn");
let (app, ..) = app(&dir);
let mut p = crate::tests::panel_harness::Panel::new(app, crate::tests::picks::dialogs);
menus::invoke(&mut p.app(), COMMAND, Value::Null);
p.frame();
for name in ["river.png", "harbour.png", "Select", "Cancel"] {
assert!(p.shows(name), "{name} is drawn");
}
}
#[test]
fn the_dialog_lists_filters_and_selects_with_zoom() {
let dir = Folder::new("dialog");
+11
View File
@@ -87,6 +87,17 @@ fn select_by_artboards_opens_on_the_active_artboard_and_selects_on_ok() {
assert_eq!(app.session.active().unwrap().selection.objects, vec![vectorcraft_doc::NodeId(inside)]);
}
#[test]
fn select_by_artboards_draws_its_artboards_and_buttons() {
let (app, _) = banner();
let mut p = crate::tests::panel_harness::Panel::new(app, crate::tests::picks::dialogs);
menus::invoke(&mut p.app(), COMMAND, Value::Null);
p.frame();
for name in ["Banner", "Select All", "OK", "Cancel"] {
assert!(p.shows(name), "{name} is drawn");
}
}
#[test]
fn a_search_keeps_the_choice_it_hides_and_a_double_click_fits_its_artboard() {
// Boards 0 and 1 chosen, the search shows 0 and 2: picking row 2 leaves hidden board 1 chosen and drops shown board 0.
+12 -15
View File
@@ -349,22 +349,19 @@ impl BulletsDialog {
fn preset_row(ui: &mut Ui, label: &'static str, presets: &[Preset], current: Option<usize>) -> Option<usize> {
let mut selection = current.map_or_else(Selection::default, Selection::single);
let source = keyed(presets, |p: &Preset| p.at);
let _ = TileGrid::new(label).select(SelectMode::Single).caption(CaptionPlace::None).selection(Bind::bound(&mut selection)).show_items(
ui,
&source,
&mut |at, _| {
let Some(preset) = presets.get(*at) else { return Tile::new(String::new()) };
let face = preset.face.clone();
Tile::new(preset.name.clone()).thumb(ThumbAspect::SQUARE, move |cx, rect| {
cx.with_draw(|draw| match &face {
Face::Glyph(glyph) => draw.icon(rect, &IconSpec::glyph(*glyph)),
Face::Text(text) => {
let _ = draw.text(rect, &TextRun::new(text.as_str()).align(HAlign::Center));
}
})
let grid = TileGrid::new(label).select(SelectMode::Single).caption(CaptionPlace::None).natural_height(true);
let _ = grid.selection(Bind::bound(&mut selection)).show_items(ui, &source, &mut |at, _| {
let Some(preset) = presets.get(*at) else { return Tile::new(String::new()) };
let face = preset.face.clone();
Tile::new(preset.name.clone()).thumb(ThumbAspect::SQUARE, move |cx, rect| {
cx.with_draw(|draw| match &face {
Face::Glyph(glyph) => draw.icon(rect, &IconSpec::glyph(*glyph)),
Face::Text(text) => {
let _ = draw.text(rect, &TextRun::new(text.as_str()).align(HAlign::Center));
}
})
},
);
})
});
selection.lead.filter(|at| Some(*at) != current)
}
@@ -76,6 +76,8 @@ const IMPORT: &str = "type.compositeFonts.import";
/// The purpose of the file picks, which keeps their last folder.
const PURPOSE: &str = "compositeFonts";
/// The rows of a custom set's characters shown before they scroll.
const CHAR_ROWS: u16 = 5;
/// The table's columns: the class (or the custom set's name) is the row's label.
const CLASS: ColumnKey = ColumnKey::new("class");
@@ -656,6 +658,7 @@ impl CompositeFontsDialog {
let out = TileGrid::<usize>::new(tl!("Characters"))
.select(SelectMode::Single)
.thumb_size(ThumbSize::Small)
.max_rows(CHAR_ROWS)
.selection(Bind::given(selection))
.show_items(ui, &keyed(&keys, |k: &usize| *k), &mut |key, _| {
let c = chars.get(*key).copied().unwrap_or_default();
@@ -458,3 +458,19 @@ fn the_sample_draws_color_glyphs_in_their_colors() {
let (_, tall) = sample::measure(&f, 36.0);
assert!(tall.ascender.unwrap() > plain.ascender.unwrap() * 1.5, "{plain:?} {tall:?}");
}
/// With Custom on, the dialog draws the set's characters and its buttons.
#[test]
fn custom_character_sets_draw_their_characters_and_the_buttons() {
let mut p = crate::tests::panel_harness::Panel::new(app(), crate::tests::picks::dialogs);
open(&mut p.app()).unwrap();
new_font(&mut p.app());
dialog(&mut p.app(), |d| d.custom = true);
new_set(&mut p.app());
dialog(&mut p.app(), |d| d.entry = "AB".into());
edit(&mut p.app(), SetAction::AddChars).unwrap();
p.frame();
for name in ["A", "B", "OK", "Cancel"] {
assert!(p.shows(name), "{name} is drawn");
}
}
+15
View File
@@ -44,6 +44,8 @@ const EDITING: &str = "editing";
const MISSING: &str = "missing";
const ACTION: &str = "__action";
const LISTING: &str = "__list";
/// The rows the filter list shows before it scrolls.
const LIST_ROWS: u16 = 7;
/// The dialog's heading.
fn heading() -> String {
@@ -169,6 +171,7 @@ fn list_row(ui: &mut egui::Ui, fields: &mut DialogFields, _cx: &mut craft::ui::p
let out = List::<String>::new(heading())
.select(SelectMode::Single)
.activate(ActivateOn::DoubleClick)
.max_rows(LIST_ROWS)
.selection(Bind::bound(&mut selection))
.show_items(ui, &rows, &mut |key, icx| match rows.0.get(icx.at) {
Some((_, Kind::Missing)) => ListRow::new(key.clone()).ink(RowInk::Dimmed),
@@ -490,6 +493,18 @@ mod tests {
assert!(open_dialogs(&app).is_empty());
}
#[test]
fn the_dialog_draws_its_filters_and_buttons() {
let mut app = app();
rect(&mut app);
let mut p = crate::tests::panel_harness::Panel::new(app, crate::tests::picks::dialogs);
crate::menus::invoke(&mut p.app(), "ui.svgFilterDialog", json!({}));
p.frame();
for name in [DEFAULT_FILTERS[0].name, "New", "OK", "Cancel"] {
assert!(p.shows(name), "{name} is drawn");
}
}
#[test]
fn opened_for_an_applied_filter_ok_replaces_it() {
let mut app = app();
@@ -558,6 +558,24 @@ fn more_options_opens_bullets_and_numbering_on_its_tab() {
assert!(shown_tab(&app).is_some());
}
/// Bullets and Numbering draws every preset of each tab, and its buttons.
#[test]
fn bullets_and_numbering_draws_every_preset_and_its_buttons() {
use vectorcraft_doc::text::NumberStyle;
crate::i18n::set_current(crate::i18n::Lang::EN);
let (app, _) = editing_text("One\nTwo");
let mut p = crate::tests::panel_harness::Panel::new(crate::testing::windowed(app), crate::tests::picks::dialogs);
select_range(&mut p.app(), 0, 0);
let last_number = NumberStyle::ALL.last().map(|&style| crate::panels::paragraph::number_sample(style, 3)).unwrap_or_default();
for (tab, last) in [("bullets", "Filled Square".to_owned()), ("numbers", last_number)] {
p.app().run("ui.bulletsAndNumbering", json!({ "tab": tab })).unwrap();
p.frame();
for name in ["None", last.as_str(), "OK", "Cancel"] {
assert!(p.shows(name), "{name} is drawn on {tab}");
}
}
}
/// Type › Bullets and Numbering › Convert to Text (`type.convertListToText`) acts on the
/// paragraphs the Type tool's selection touches: their numbers become characters of the text
/// and their list goes, while the other paragraphs stay in the list, and the Type tool's caret