mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-22 05:53:17 -06:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4e5af936c5 | ||
|
|
426a97a246 | ||
|
|
c088eba814 |
@@ -236,6 +236,9 @@ fn translated_groups() -> std::rc::Rc<Vec<IconPickerGroup<String>>> {
|
||||
})
|
||||
}
|
||||
|
||||
/// How many icons a row of the Icons dialog holds: the dialog is as wide as they are.
|
||||
pub(super) const ICONS_COLUMNS: usize = 12;
|
||||
|
||||
/// Insert › Icons: the library as a searchable grid with a filter row; Insert runs `insert.icon`.
|
||||
#[derive(Clone, Default, PartialEq, Serialize, Deserialize)]
|
||||
pub(crate) struct IconsForm {
|
||||
@@ -263,8 +266,11 @@ impl WordForm for IconsForm {
|
||||
|
||||
fn body(&mut self, ui: &mut Ui, cx: &mut FormCx<'_, '_>, _asks: &mut Vec<Asks>) -> bool {
|
||||
let groups = translated_groups();
|
||||
// Large previews, and a picker that keeps its height across categories (#7167).
|
||||
let out = IconPicker::new(Label::from(tl!("Icons")), Bind::bound(&mut self.picked), groups.as_slice())
|
||||
.group_display(IconPickerGroups::Filter)
|
||||
.large_previews()
|
||||
.columns(ICONS_COLUMNS)
|
||||
.empty(Label::from(tl!("No icons match your search.")))
|
||||
.show(ui);
|
||||
if out.picked.is_some() && out.response.double_clicked() {
|
||||
|
||||
@@ -1782,3 +1782,43 @@ fn colour_fields_say_their_label_and_colour_in_the_interface_language() {
|
||||
assert!(present, "the translated field is {name}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Insert › Icons keeps its size and place whichever category is picked (#7167): the footer's Cancel button, which
|
||||
/// stands at the dialog's lower edge, does not move.
|
||||
#[test]
|
||||
fn icons_dialog_keeps_its_size_across_categories() {
|
||||
let mut h = app_harness(app_with("x"));
|
||||
open_named(&mut h, "icons", json!({}));
|
||||
h.run_steps(6);
|
||||
let cancel = |h: &egui_kittest::Harness<'_, WordApp>| h.get_by_role_and_label(egui::accesskit::Role::Button, "Cancel").rect();
|
||||
let all = cancel(&h);
|
||||
for category in ["Arrows", "Transport", "All"] {
|
||||
h.get_by_label(category).click();
|
||||
h.run_steps(6);
|
||||
assert_eq!(cancel(&h), all, "the dialog moved or resized on {category}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Insert › Icons is as wide as its row of large previews (#7167), not as wide as the window lets a dialog be: the
|
||||
/// first row holds `ICONS_COLUMNS` icons and the next icon starts the second, and the dialog is narrower than one
|
||||
/// more column.
|
||||
#[test]
|
||||
fn icons_dialog_is_as_wide_as_its_columns() {
|
||||
let mut h = app_harness(app_with("x"));
|
||||
open_named(&mut h, "icons", json!({}));
|
||||
h.run_steps(6);
|
||||
let columns = super::bookmarks::ICONS_COLUMNS;
|
||||
// All lists the icons category by category.
|
||||
use wordcraft_render::icon_lib::{Category, ICONS};
|
||||
let order: Vec<&str> =
|
||||
Category::ALL.into_iter().flat_map(|c| ICONS.iter().filter(move |icon| icon.category == c)).map(|icon| icon.name).collect();
|
||||
let tile = |h: &egui_kittest::Harness<'_, WordApp>, at: usize| {
|
||||
let name = order[at];
|
||||
h.query_all_by_label(name).last().unwrap_or_else(|| panic!("no tile for {name}")).rect()
|
||||
};
|
||||
let (first, last, next) = (tile(&h, 0), tile(&h, columns - 1), tile(&h, columns));
|
||||
assert_eq!(last.top(), first.top(), "the first row holds {columns} icons");
|
||||
assert!(next.top() > first.top(), "icon {} starts the second row", columns + 1);
|
||||
let dialog = h.get_by_role(egui::accesskit::Role::Dialog).rect();
|
||||
assert!(dialog.width() < (columns + 1) as f32 * first.width(), "the dialog is {} wide for tiles of {}", dialog.width(), first.width());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user