image_view: Limit zoom value digits

Only allow 4 integer digits and 2 decimal digits. That's what's actually respected by the input at max.

Closes #557
This commit is contained in:
Sophie Herold 2025-12-22 16:10:45 +01:00
parent 7684a4b421
commit 2102b44528
2 changed files with 31 additions and 0 deletions

View file

@ -199,6 +199,36 @@ mod imp {
),
);
self.zoom_value
.delegate()
.unwrap()
.connect_insert_text(move |entry, ins, pos| {
let mut text = entry.text().to_string();
text.insert_str(*pos as usize, ins);
text = text.replace('%', "");
text = text.trim().to_string();
let local_settings = util::locale_settings();
if let Some(thousands_sep) = local_settings.thousands_sep {
text = text.replace(&thousands_sep, "");
}
if let Some(decimal_point) = local_settings.decimal_point {
if let Some((integer_part, decimal_part)) = text.split_once(&decimal_point)
{
if integer_part.len() > 4 || decimal_part.len() > 2 {
entry.stop_signal_emission_by_name("insert-text");
}
} else {
// Complete text is integer part
if text.len() > 4 {
entry.stop_signal_emission_by_name("insert-text");
}
}
}
});
self.zoom_value.connect_changed(glib::clone!(
#[weak]
obj,