Preferences: move the dimmed checkboxes' conditions into a helper

category_fields reached a cognitive complexity of 31 after the merge of main, over clippy's limit of 30. The conditions that dim Scroll Sideways with Cmd/Ctrl + Wheel, Numbers Without Units Are Points, Show Tool Cards, Animated Zoom and Show samples on white move to bool_enabled, and category_fields draws those five checkboxes in one match arm.
This commit is contained in:
dotCooCoo
2026-11-18 13:54:14 -08:00
parent bcfeca7c48
commit 2bd860e63c
+24 -22
View File
@@ -561,6 +561,27 @@ impl DescribedRows {
}
}
/// Whether the checkbox of the setting `key` is enabled, for a setting that acts only while
/// another setting allows it and is dimmed otherwise. `None` for every other setting.
fn bool_enabled(d: &Dialog, key: &str) -> Option<bool> {
match key {
// General › Scroll Sideways with Cmd/Ctrl + Wheel acts only while Zoom with Mouse Wheel
// is off: dimmed while it is on.
"ctrlWheelScrollsSideways" => Some(!d.bool("zoomWithMouseWheel")),
// Units › Numbers Without Units Are Points only tells points from picas: dimmed
// unless a unit is Picas.
"numbersWithoutUnitsArePoints" => Some(picas_in_use(d)),
// General › Show Tool Cards replaces the tool tips: dimmed while Show Tool Tips is off.
"showToolCards" => Some(d.bool("showToolTips")),
// Performance › Animated Zoom needs GPU Performance: dimmed while it is off.
"animatedZoom" => Some(d.bool("gpuPerformance")),
// Type › Show samples on white draws the samples that Enable in-menu font previews
// shows: dimmed while previews are off.
"fontSamplesOnWhite" => Some(d.bool("fontPreview")),
_ => None,
}
}
/// The fields of the category `cat`. → The rows under the pointer and with the keyboard focus.
fn category_fields(ui: &mut egui::Ui, app: &mut VectorcraftApp, d: &mut Dialog, cat: &str) -> DescribedRows {
let t = Tokens::get(ui.ctx());
@@ -600,29 +621,10 @@ fn category_fields(ui: &mut egui::Ui, app: &mut VectorcraftApp, d: &mut Dialog,
let v = d.fields.get(sp.key).cloned().unwrap_or(Value::Null);
let top = ui.cursor().top();
let mark = found_mark(ui, d, sp.key);
let enabled = bool_enabled(d, sp.key);
match sp.kind {
// General › Scroll Sideways with Cmd/Ctrl + Wheel acts only while Zoom with Mouse Wheel
// is off: dimmed while it is on.
PrefKind::Bool if sp.key == "ctrlWheelScrollsSideways" => {
ui.add_enabled_ui(!d.bool("zoomWithMouseWheel"), |ui| bool_row(ui, d, sp.key, sp.label));
}
// Units › Numbers Without Units Are Points only tells points from picas: dimmed
// unless a unit is Picas.
PrefKind::Bool if sp.key == "numbersWithoutUnitsArePoints" => {
ui.add_enabled_ui(picas_in_use(d), |ui| bool_row(ui, d, sp.key, sp.label));
}
// General › Show Tool Cards replaces the tool tips: dimmed while Show Tool Tips is off.
PrefKind::Bool if sp.key == "showToolCards" => {
ui.add_enabled_ui(d.bool("showToolTips"), |ui| bool_row(ui, d, sp.key, sp.label));
}
// Performance › Animated Zoom needs GPU Performance: dimmed while it is off.
PrefKind::Bool if sp.key == "animatedZoom" => {
ui.add_enabled_ui(d.bool("gpuPerformance"), |ui| bool_row(ui, d, sp.key, sp.label));
}
// Type › Show samples on white draws the samples that Enable in-menu font previews
// shows: dimmed while previews are off.
PrefKind::Bool if sp.key == "fontSamplesOnWhite" => {
ui.add_enabled_ui(d.bool("fontPreview"), |ui| bool_row(ui, d, sp.key, sp.label));
PrefKind::Bool if enabled.is_some() => {
ui.add_enabled_ui(enabled == Some(true), |ui| bool_row(ui, d, sp.key, sp.label));
}
// Windows and Linux only: macOS always has the system's title bar, the web has none.
PrefKind::Bool if sp.key == "systemTitleBar" => {