Split settings_ui::wire into one function per section

wire() registered every settings-page callback in one 416-line function,
fenced only by section comments. Each fenced section (opening and
closing, cache, faces, export, reset) is now its own private function
that wire() calls in the same order, with the section's own comment kept
as its doc comment. on_budget_changed and on_open are coerced to trait
objects at the top of wire() so the new functions take a plain
Rc<dyn Fn> rather than needing their own generic parameter, with no
change in the closures registered or the order they are registered in.
This commit is contained in:
2026-09-20 17:24:28 +02:00
parent 6b1aac477d
commit 04949741c1
2 changed files with 73 additions and 41 deletions
+48 -16
View File
@@ -403,14 +403,26 @@ pub fn wire<F, G>(
F: Fn(&Settings) + 'static,
G: Fn(&AppWindow) + 'static,
{
let on_budget_changed = Rc::new(on_budget_changed);
let on_budget_changed: Rc<dyn Fn(&Settings)> = Rc::new(on_budget_changed);
// Run when the page opens, to fill in figures this module does not own —
// the face-indexing coverage, which lives in the catalog. Read here rather
// than kept up to date continuously, because it is only ever looked at
// when this page is on screen and it is two counts and an indexed scan.
let on_open: Rc<dyn Fn(&AppWindow)> = Rc::new(on_open);
// --- opening and closing -------------------------------------------
wire_open_close(window, &controller, &on_open);
wire_cache(window, &controller, &on_budget_changed);
wire_faces(window, &controller, &on_budget_changed);
wire_export(window, &controller);
wire_reset(window, &controller, &on_budget_changed);
}
/// --- opening and closing -------------------------------------------
fn wire_open_close(
window: &AppWindow,
controller: &Rc<SettingsController>,
on_open: &Rc<dyn Fn(&AppWindow)>,
) {
{
let weak = window.as_weak();
let on_open = on_open.clone();
@@ -435,12 +447,18 @@ pub fn wire<F, G>(
w.set_show_settings(false);
});
}
}
// --- cache ---------------------------------------------------------
//
// A budget arrives as typed text. An unparseable entry leaves the previous
// value in place and `render` puts the stored one back in the field, so a
// typo is visibly rejected rather than silently shrinking a cache.
/// --- cache ---------------------------------------------------------
///
/// A budget arrives as typed text. An unparseable entry leaves the previous
/// value in place and `render` puts the stored one back in the field, so a
/// typo is visibly rejected rather than silently shrinking a cache.
fn wire_cache(
window: &AppWindow,
controller: &Rc<SettingsController>,
on_budget_changed: &Rc<dyn Fn(&Settings)>,
) {
{
let weak = window.as_weak();
let ctl = controller.clone();
@@ -546,14 +564,20 @@ pub fn wire<F, G>(
render(&w, &ctl);
});
}
}
// --- faces ---------------------------------------------------------
//
// TRACES: FR-CULL-8
// Notified like a budget change, because the effect is outside this
// page: the library controller carries the pipeline id into the next
// sync, and the coverage line under the picker has to be re-counted
// under the new id — which the caller's `on_budget_changed` does.
/// --- faces ---------------------------------------------------------
///
/// TRACES: FR-CULL-8
/// Notified like a budget change, because the effect is outside this
/// page: the library controller carries the pipeline id into the next
/// sync, and the coverage line under the picker has to be re-counted
/// under the new id — which the caller's `on_budget_changed` does.
fn wire_faces(
window: &AppWindow,
controller: &Rc<SettingsController>,
on_budget_changed: &Rc<dyn Fn(&Settings)>,
) {
{
let weak = window.as_weak();
let ctl = controller.clone();
@@ -568,8 +592,10 @@ pub fn wire<F, G>(
render(&w, &ctl);
});
}
}
// --- export --------------------------------------------------------
/// --- export --------------------------------------------------------
fn wire_export(window: &AppWindow, controller: &Rc<SettingsController>) {
{
let weak = window.as_weak();
let ctl = controller.clone();
@@ -797,8 +823,14 @@ pub fn wire<F, G>(
render(&w, &ctl);
});
}
}
// --- reset ---------------------------------------------------------
/// --- reset ---------------------------------------------------------
fn wire_reset(
window: &AppWindow,
controller: &Rc<SettingsController>,
on_budget_changed: &Rc<dyn Fn(&Settings)>,
) {
{
let weak = window.as_weak();
let ctl = controller.clone();