Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

Keep Auto font size in the field properties Appearance tab

NetterSilver2f208a289b28
diff --git a/crates/ui-egui/src/prepare.rs b/crates/ui-egui/src/prepare.rs
index 37747f14c..d4e20f254 100644
--- a/crates/ui-egui/src/prepare.rs
+++ b/crates/ui-egui/src/prepare.rs
@@ -977,7 +977,10 @@ pub(crate) fn body(ui: &mut egui::Ui, d: &mut FieldDraft, t: &crate::theme::Toke
if ui.add(widgets::checkbox(&mut auto, tl!("Auto"))).changed() {
d.font_size = if auto { 0.0 } else { 12.0 };
}
- ui.add_enabled(!auto, egui::DragValue::new(&mut d.font_size).range(2.0..=100.0).speed(0.25).suffix(" pt"));
+ ui.add_enabled(
+ !auto,
+ egui::DragValue::new(&mut d.font_size).range(2.0..=100.0).clamp_existing_to_range(false).speed(0.25).suffix(" pt"),
+ );
});
ui.end_row();
if let Some(l) = d.look.as_mut() {
diff --git a/crates/ui-egui/tests/prepare.rs b/crates/ui-egui/tests/prepare.rs
index b23f1a9f8..ea006911d 100644
--- a/crates/ui-egui/tests/prepare.rs
+++ b/crates/ui-egui/tests/prepare.rs
@@ -193,6 +193,20 @@ fn appearance_tab_restyles_the_field() {
assert_eq!((l.style, l.font, l.fill), (BorderStyle::Dashed, FieldFont::Courier, Some([1.0, 1.0, 0.8])));
}
+#[test]
+fn appearance_tab_keeps_auto_font_size() {
+ let mut h = harness();
+ h.state_mut().execute("form.prepare");
+ h.run_steps(2);
+ h.state_mut().open_field_props("city", 0);
+ h.run_steps(2);
+ h.get_by_label("Appearance").click();
+ h.run_steps(2);
+ h.state_mut().field_props.as_mut().unwrap().font_size = 0.0;
+ h.run_steps(3);
+ assert_eq!(h.state().field_props.as_ref().unwrap().font_size, 0.0, "Auto (0) must survive a frame");
+}
+
#[test]
fn position_tab_rotates_a_field() {
let mut h = harness();