Skip to content

VectorCraft: An open-source, vector art tool written by scratch in pure Rust

Fix #1866: Preferences and Save PDF highlight the section shown

bflatasticf9b051d3d17f
diff --git a/crates/ui-egui/src/dialogs/save_pdf.rs b/crates/ui-egui/src/dialogs/save_pdf.rs
index b76e9d654..fcf5105f3 100644
--- a/crates/ui-egui/src/dialogs/save_pdf.rs
+++ b/crates/ui-egui/src/dialogs/save_pdf.rs
@@ -377,7 +377,7 @@ pub(super) fn section_list(ui: &mut egui::Ui, d: &mut Dialog, sections: &[&str],
for s in sections {
let sel = *s == section;
let label = egui::RichText::new(tl!(*s)).size(12.5).color(if sel { t.text_strong } else { t.text });
- if ui.add(egui::Button::selectable(sel, label).frame_when_inactive(false).min_size(egui::vec2(LIST_WIDTH - 12.0, 24.0))).clicked() {
+ if ui.add(egui::Button::selectable(sel, label).min_size(egui::vec2(LIST_WIDTH - 12.0, 24.0))).clicked() {
d.fields.insert("__section".into(), json!(s));
}
}
diff --git a/crates/ui-egui/src/prefs_dialog.rs b/crates/ui-egui/src/prefs_dialog.rs
index a4b049c9d..c0182b177 100644
--- a/crates/ui-egui/src/prefs_dialog.rs
+++ b/crates/ui-egui/src/prefs_dialog.rs
@@ -167,7 +167,7 @@ pub fn show(app: &mut VectorcraftApp, ctx: &egui::Context) {
for c in PREF_CATEGORIES {
let sel = *c == cat;
let text = egui::RichText::new(tl!(*c)).size(12.5).color(if sel { t.text_strong } else { t.text });
- let b = egui::Button::selectable(sel, text).frame_when_inactive(false).min_size(egui::vec2(184.0, 24.0));
+ let b = egui::Button::selectable(sel, text).min_size(egui::vec2(184.0, 24.0));
if ui.add(b).clicked() {
d.fields.insert("__category".into(), json!(c));
}
@@ -599,6 +599,34 @@ mod tests {
assert_eq!(saved["engine_prefs"]["systemTitleBar"], json!(true));
}
+ /// #1866: the category shown is highlighted in the list while the pointer is elsewhere.
+ #[test]
+ fn the_category_shown_is_highlighted() {
+ fn rects(s: &egui::Shape, out: &mut Vec<(egui::Rect, egui::Color32)>) {
+ match s {
+ egui::Shape::Rect(r) => out.push((r.rect, r.fill)),
+ egui::Shape::Vec(v) => v.iter().for_each(|s| rects(s, out)),
+ _ => {}
+ }
+ }
+ let mut a = app();
+ open(&mut a, Some("Units"));
+ let ctx = egui::Context::default();
+ crate::theme::install_fonts(&ctx);
+ // The window sizes itself on the first frame and draws on the second.
+ let mut out = ctx.run_ui(egui::RawInput::default(), |ui| show(&mut a, ui.ctx()));
+ out.textures_delta.clear();
+ let mut out = ctx.run_ui(egui::RawInput::default(), |ui| show(&mut a, ui.ctx()));
+ out.textures_delta.clear();
+ let mut shown = vec![];
+ out.shapes.iter().for_each(|c| rects(&c.shape, &mut shown));
+ // The list's rows, top to bottom: only the fourth (Units) is filled.
+ let rows: Vec<_> = shown.iter().filter(|(r, _)| r.width() == 184.0 && r.height() < 30.0).collect();
+ assert_eq!(rows.len(), PREF_CATEGORIES.len(), "{shown:?}");
+ let filled: Vec<usize> = rows.iter().enumerate().filter(|(_, (_, c))| c.a() > 0).map(|(i, _)| i).collect();
+ assert_eq!(filled, vec![3], "{rows:?}");
+ }
+
/// Units › Numbers Without Units Are Points (#394): the preference reaches the fields when it
/// changes, and its checkbox is dimmed unless a unit is Picas.
#[test]