Preferences: number rows move out of category_fields

category_fields reached clippy's cognitive complexity limit (31/30) once
main took #8086. The Num arms move into num_row and num_field_row, next
to bool_row and choice_row; the rows draw and save as before.
This commit is contained in:
dotCooCoo
2026-11-18 06:29:22 -08:00
parent 5b0f70f2f4
commit 2a5fc378b1
+33 -28
View File
@@ -670,34 +670,7 @@ fn category_fields(ui: &mut egui::Ui, app: &mut VectorcraftApp, d: &mut Dialog,
// says the change applies at the next start.
PrefKind::Bool if sp.key == "lowLatencyDrawing" => desktop_startup_bool_row(ui, d, sp.key, sp.label, &t),
PrefKind::Bool => bool_row(ui, d, sp.key, sp.label),
// General › Hold Shortcut Delay acts only while Hold Shortcuts is on: dimmed while it
// is off, as in Edit › Keyboard Shortcuts, which shows it only then.
PrefKind::Num { min, max, unit } if sp.key == "keyHoldDelay" => {
ui.add_enabled_ui(d.bool("holdShortcuts"), |ui| {
labeled(ui, sp.label, |ui, _| {
let x = v.as_f64().unwrap_or(min);
if let Some(x) = widgets::range_field(ui, sp.key, x, min..=max, &format!(" {unit}"), 3, 110.0) {
d.fields.insert(sp.key.into(), json!(x));
}
});
});
}
PrefKind::Num { min, max, unit } => {
labeled(ui, sp.label, |ui, label_id| {
let mut x = v.as_f64().unwrap_or(min);
let new = if sp.key == "uiScaling" {
// Without internal text, both slider controls inherit the row's name across focus changes.
let response = widgets::slider(ui, egui::Slider::new(&mut x, min..=max).step_by(0.05)).labelled_by(label_id);
ui.add(egui::Label::new(tl!("Smaller ↔ Larger")).wrap_mode(egui::TextWrapMode::Extend));
response.changed().then_some(x)
} else {
widgets::range_field(ui, sp.key, x, min..=max, &format!(" {unit}"), 3, 110.0)
};
if let Some(x) = new {
d.fields.insert(sp.key.into(), json!(x));
}
});
}
PrefKind::Num { min, max, unit } => num_row(ui, d, sp.key, sp.label, min..=max, unit, &v),
PrefKind::Length { min, max, measure } => {
// In the dialog's own Units choice, so a change there shows right away.
let unit = vectorcraft_doc::Unit::named(&d.str(measure.pref_key())).unwrap_or_default();
@@ -896,6 +869,38 @@ fn choice_row(ui: &mut egui::Ui, d: &mut Dialog, key: &str, label: &str, opts: &
});
}
/// The row of the number preference `key` within `range`: a slider for Interface Scaling, a field
/// shown with `unit` otherwise.
fn num_row(ui: &mut egui::Ui, d: &mut Dialog, key: &str, label: &str, range: std::ops::RangeInclusive<f64>, unit: &str, v: &Value) {
if key == "uiScaling" {
labeled(ui, label, |ui, label_id| {
let mut x = v.as_f64().unwrap_or(*range.start());
// Without internal text, both slider controls inherit the row's name across focus changes.
let response = widgets::slider(ui, egui::Slider::new(&mut x, range).step_by(0.05)).labelled_by(label_id);
ui.add(egui::Label::new(tl!("Smaller ↔ Larger")).wrap_mode(egui::TextWrapMode::Extend));
if response.changed() {
d.fields.insert(key.into(), json!(x));
}
});
} else if key == "keyHoldDelay" {
// General › Hold Shortcut Delay acts only while Hold Shortcuts is on: dimmed while it
// is off, as in Edit › Keyboard Shortcuts, which shows it only then.
ui.add_enabled_ui(d.bool("holdShortcuts"), |ui| num_field_row(ui, d, key, label, range, unit, v));
} else {
num_field_row(ui, d, key, label, range, unit, v);
}
}
/// A number field for the preference `key`, kept within `range` and shown with `unit`.
fn num_field_row(ui: &mut egui::Ui, d: &mut Dialog, key: &str, label: &str, range: std::ops::RangeInclusive<f64>, unit: &str, v: &Value) {
labeled(ui, label, |ui, _| {
let x = v.as_f64().unwrap_or(*range.start());
if let Some(x) = widgets::range_field(ui, key, x, range, &format!(" {unit}"), 3, 110.0) {
d.fields.insert(key.into(), json!(x));
}
});
}
fn bool_row(ui: &mut egui::Ui, d: &mut Dialog, key: &str, label: &str) {
// The app's outlined checkbox (it translates `label`): egui's own has no border at rest.
let on = d.bool(key);