clairlune 0.7.0

Procedural, animated ASCII-art desktop wallpapers. Local, seeded and deterministic; no AI, no network.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
//! The Settings window's content: a sidebar of sections (PLAN.md section 8),
//! the current wallpaper as a status strip above every page, and rows of
//! name, one-line description and control (docs/design.md sections 3-5).

use super::style::{self, c, colors};
use crate::settings::{Settings, ThemeMode};
use crate::tokens::{radius, size, space};
use clairlune_scene::Theme;
use egui::{Align, Align2, Layout, Rect, RichText, Sense, Stroke, Ui, vec2};

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Section {
    Schedule,
    Theme,
    Display,
    Live,
    Buddy,
    Content,
    Archive,
    Export,
    General,
}

impl Section {
    pub const ALL: [Section; 9] = [
        Section::Schedule,
        Section::Theme,
        Section::Display,
        Section::Live,
        Section::Buddy,
        Section::Content,
        Section::Archive,
        Section::Export,
        Section::General,
    ];

    pub fn name(self) -> &'static str {
        match self {
            Section::Schedule => "Schedule",
            Section::Theme => "Theme",
            Section::Display => "Display",
            Section::Live => "Live",
            Section::Buddy => "Buddy",
            Section::Content => "Content",
            Section::Archive => "Archive",
            Section::Export => "Export",
            Section::General => "General",
        }
    }
}

/// What the app shows about the wallpaper on screen and its own state.
#[derive(Clone, Debug, Default)]
pub struct Status {
    /// e.g. "stroll in cave".
    pub what: String,
    pub seed: Option<u64>,
    pub theme: Option<Theme>,
    /// Minutes until the next scheduled change.
    pub next_in_minutes: Option<u64>,
    pub busy: bool,
    /// Registered to start at login; `None` where this build can't manage it.
    pub start_at_login: Option<bool>,
    /// A one-line result to show under the status (export done, an error).
    pub note: Option<String>,
}

/// Requests from the window to the app.
#[derive(Clone, Debug, PartialEq)]
pub enum UiAction {
    SettingsChanged,
    NewWallpaper,
    Previous,
    OpenArchive,
    OpenLogs,
    SavePng,
    SetStartAtLogin(bool),
    RestoreWallpaper,
}

pub struct ViewState {
    pub section: Section,
    pub thumb: Option<egui::TextureHandle>,
    /// The moon mark for empty states.
    pub moon: Option<egui::TextureHandle>,
}

const INTERVALS: [(u32, &str); 8] = [
    (15, "15 minutes"),
    (30, "30 minutes"),
    (60, "1 hour"),
    (180, "3 hours"),
    (360, "6 hours"),
    (720, "12 hours"),
    (1440, "1 day"),
    (0, "Only on demand"),
];

const LANDSCAPES: [(&str, &str); 9] = [
    ("canyon", "Canyon"),
    ("mountains", "Mountains"),
    ("forest", "Forest"),
    ("desert", "Desert"),
    ("snowfield", "Snowfield"),
    ("shore", "Shore"),
    ("city_rooftops", "City rooftops"),
    ("night_sky", "Night sky"),
    ("cave", "Cave"),
];

const ACTIVITIES: [(&str, &str); 7] = [
    ("warm_hands", "Warming hands by a fire"),
    ("stroll", "Strolling"),
    ("stargaze", "Stargazing (night only)"),
    ("wizard_magic", "Casting spells"),
    ("make_coffee", "Making coffee"),
    ("read_lantern", "Reading by a lantern"),
    ("play_guitar", "Playing guitar"),
];

/// Weather that shows as particles. Clear weather ("none", "stars") is
/// always allowed so every scene has something to fall back to.
const WEATHER: [(&str, &str); 5] = [
    ("snow", "Snow"),
    ("rain", "Rain"),
    ("fireflies", "Fireflies"),
    ("leaves", "Falling leaves"),
    ("dust", "Dust"),
];
const CLEAR_WEATHER: [&str; 2] = ["none", "stars"];

pub fn show(
    ui: &mut Ui,
    theme: Theme,
    st: &mut ViewState,
    settings: &mut Settings,
    status: &Status,
    actions: &mut Vec<UiAction>,
) {
    let t = colors(theme);
    egui::Panel::left("sections")
        .exact_size(size::SIDEBAR)
        .resizable(false)
        .frame(
            egui::Frame::new()
                .fill(c(t.bg_sidebar))
                .inner_margin(egui::Margin::symmetric(space::S3 as i8, space::S4 as i8)),
        )
        .show(ui, |ui| sidebar(ui, theme, st));
    egui::CentralPanel::default()
        .frame(
            egui::Frame::new()
                .fill(c(t.bg))
                .inner_margin(egui::Margin::symmetric(space::S6 as i8, space::S5 as i8)),
        )
        .show(ui, |ui| {
            egui::ScrollArea::vertical().show(ui, |ui| {
                ui.set_max_width(size::PAGE_MAX);
                status_strip(ui, theme, st, status, actions);
                ui.add_space(space::S6);
                page(ui, theme, st.section, settings, status, actions);
            });
        });
}

fn sidebar(ui: &mut Ui, theme: Theme, st: &mut ViewState) {
    let t = colors(theme);
    ui.add_space(space::S2);
    for s in Section::ALL {
        let selected = st.section == s;
        let (rect, resp) = ui.allocate_exact_size(
            vec2(ui.available_width(), size::CONTROL + 4.0),
            Sense::click(),
        );
        resp.widget_info(|| egui::WidgetInfo::selected(egui::Role::Tab, true, selected, s.name()));
        if resp.hovered() && !selected {
            ui.painter()
                .rect_filled(rect, radius::CONTROL, c(t.bg).gamma_multiply(0.6));
        }
        if selected {
            ui.painter().rect_filled(rect, radius::CONTROL, c(t.bg));
            let bar =
                Rect::from_min_size(rect.min + vec2(0.0, 6.0), vec2(2.0, rect.height() - 12.0));
            ui.painter().rect_filled(bar, 1.0, c(t.accent));
        }
        let (font, color) = if selected {
            (style::body_medium(), c(t.text))
        } else {
            (style::body(), c(t.text_secondary))
        };
        ui.painter().text(
            rect.left_center() + vec2(space::S3, 0.0),
            Align2::LEFT_CENTER,
            s.name(),
            font,
            color,
        );
        if resp.has_focus() {
            focus_ring(ui, theme, rect, radius::CONTROL);
        }
        if resp.clicked() {
            st.section = s;
        }
    }
    ui.with_layout(Layout::bottom_up(Align::Min), |ui| {
        ui.label(
            RichText::new(format!("Clairlune {}", env!("CARGO_PKG_VERSION")))
                .font(style::mono())
                .color(c(t.text_secondary)),
        );
    });
}

fn focus_ring(ui: &Ui, theme: Theme, rect: Rect, r: f32) {
    ui.painter().rect_stroke(
        rect.expand(size::FOCUS_OFFSET),
        r + size::FOCUS_OFFSET,
        Stroke::new(size::FOCUS_RING, c(colors(theme).accent)),
        egui::StrokeKind::Outside,
    );
}

/// The wallpaper on screen, its seed and theme, the next change, and the two
/// actions people reach for most. With no wallpaper yet: the moon mark.
fn status_strip(
    ui: &mut Ui,
    theme: Theme,
    st: &ViewState,
    status: &Status,
    actions: &mut Vec<UiAction>,
) {
    let t = colors(theme);
    ui.horizontal_top(|ui| {
        let w = 256.0;
        let h = w * 9.0 / 16.0;
        let (rect, _) = ui.allocate_exact_size(vec2(w, h), Sense::hover());
        match &st.thumb {
            Some(tex) => {
                let tint = if status.busy {
                    egui::Color32::from_white_alpha(150)
                } else {
                    egui::Color32::WHITE
                };
                egui::Image::new(tex)
                    .corner_radius(radius::PANEL)
                    .tint(tint)
                    .paint_at(ui, rect);
            }
            None => {
                ui.painter()
                    .rect_filled(rect, radius::PANEL, c(t.bg_raised));
                if let Some(moon) = &st.moon {
                    let m = Rect::from_center_size(rect.center(), vec2(48.0, 48.0));
                    // Ivory reads on warm black; on paper it needs ink.
                    let tint = match theme {
                        Theme::Dark => egui::Color32::WHITE,
                        Theme::Light => c(t.text_secondary),
                    };
                    egui::Image::new(moon).tint(tint).paint_at(ui, m);
                }
            }
        }
        ui.painter().rect_stroke(
            rect,
            radius::PANEL,
            Stroke::new(size::HAIRLINE, c(t.hairline)),
            egui::StrokeKind::Inside,
        );
        ui.add_space(space::S5);
        ui.vertical(|ui| {
            let what = if status.busy {
                "Making a new wallpaper".to_string()
            } else if status.what.is_empty() {
                "No wallpaper yet".to_string()
            } else {
                capitalise(&status.what)
            };
            ui.label(RichText::new(what).font(style::body_strong()));
            let mut facts = Vec::new();
            if let Some(s) = status.seed {
                facts.push(format!("seed {s}"));
            }
            if let Some(th) = status.theme {
                facts.push(th.as_str().to_string());
            }
            if !facts.is_empty() {
                ui.label(
                    RichText::new(facts.join("  "))
                        .font(style::mono())
                        .color(c(t.text_secondary)),
                );
            }
            let next = match status.next_in_minutes {
                Some(0) => "Next change in under a minute".to_string(),
                Some(1) => "Next change in 1 minute".to_string(),
                Some(m) if m < 120 => format!("Next change in {m} minutes"),
                Some(m) => format!("Next change in {} hours", m / 60),
                None => "Changes only on demand".to_string(),
            };
            ui.label(RichText::new(next).color(c(t.text_secondary)));
            ui.add_space(space::S3);
            ui.horizontal(|ui| {
                ui.add_enabled_ui(!status.busy, |ui| {
                    if primary_button(ui, theme, "New wallpaper").clicked() {
                        actions.push(UiAction::NewWallpaper);
                    }
                    if ui.button("Previous").clicked() {
                        actions.push(UiAction::Previous);
                    }
                });
            });
            if let Some(note) = &status.note {
                ui.add_space(space::S1);
                ui.label(RichText::new(note).color(c(t.text_secondary)));
            }
        });
    });
}

fn capitalise(s: &str) -> String {
    let mut c = s.chars();
    match c.next() {
        Some(f) => f.to_uppercase().chain(c).collect(),
        None => String::new(),
    }
}

fn primary_button(ui: &mut Ui, theme: Theme, label: &str) -> egui::Response {
    let t = colors(theme);
    ui.add(
        egui::Button::new(
            RichText::new(label)
                .color(c(t.on_accent))
                .font(style::body_medium()),
        )
        .fill(c(t.accent))
        .stroke(Stroke::NONE)
        .min_size(vec2(0.0, size::BUTTON_PRIMARY)),
    )
}

/// A section heading with a hairline under it.
fn heading(ui: &mut Ui, theme: Theme, title: &str) {
    let t = colors(theme);
    ui.label(RichText::new(title).font(style::title()));
    ui.add_space(space::S2);
    hairline(ui, t.hairline);
    ui.add_space(space::S3);
}

fn hairline(ui: &mut Ui, color: crate::tokens::Rgb) {
    let (rect, _) = ui.allocate_exact_size(vec2(ui.available_width(), 1.0), Sense::hover());
    ui.painter().rect_filled(rect, 0.0, c(color));
}

/// A group label inside a page.
fn group(ui: &mut Ui, title: &str) {
    ui.add_space(space::S2);
    ui.label(RichText::new(title).font(style::section()));
    ui.add_space(space::S1);
}

/// One setting: name and control on the first line, description under it.
fn row(ui: &mut Ui, theme: Theme, name: &str, description: &str, control: impl FnOnce(&mut Ui)) {
    let t = colors(theme);
    ui.horizontal(|ui| {
        ui.label(RichText::new(name).font(style::body_strong()));
        ui.with_layout(Layout::right_to_left(Align::Center), control);
    });
    ui.label(RichText::new(description).color(c(t.text_secondary)));
    ui.add_space(space::S4);
}

/// An on/off switch: 36 x 20, the accent when on.
fn toggle(ui: &mut Ui, theme: Theme, on: &mut bool, label: &str) -> egui::Response {
    let t = colors(theme);
    let (rect, mut resp) = ui.allocate_exact_size(vec2(36.0, 20.0), Sense::click());
    if resp.clicked() {
        *on = !*on;
        resp.mark_changed();
    }
    resp.widget_info(|| egui::WidgetInfo::selected(egui::Role::CheckBox, true, *on, label));
    let k = ui.ctx().animate_bool_responsive(resp.id, *on);
    let enabled = ui.is_enabled();
    let (fill, stroke) = if *on {
        (c(t.accent), c(t.accent))
    } else {
        (c(t.bg_raised), c(t.border_control))
    };
    let fade = |col: egui::Color32| {
        if enabled {
            col
        } else {
            col.gamma_multiply(0.4)
        }
    };
    ui.painter().rect(
        rect,
        10.0,
        fade(fill),
        Stroke::new(1.0, fade(stroke)),
        egui::StrokeKind::Inside,
    );
    let x = egui::lerp(rect.left() + 10.0..=rect.right() - 10.0, k);
    let knob = if *on {
        c(t.on_accent)
    } else {
        c(t.border_control)
    };
    ui.painter()
        .circle_filled(egui::pos2(x, rect.center().y), 7.0, fade(knob));
    if resp.has_focus() {
        focus_ring(ui, theme, rect, 10.0);
    }
    resp
}

/// A row of mutually exclusive choices; the chosen one is filled. Options
/// marked `false` are shown but can't be chosen.
fn segmented<T: PartialEq + Copy>(
    ui: &mut Ui,
    theme: Theme,
    value: &mut T,
    options: &[(T, &str, bool)],
) -> bool {
    let t = colors(theme);
    let mut changed = false;
    ui.spacing_mut().item_spacing.x = space::S1;
    for (v, label, enabled) in options.iter().rev() {
        let on = *value == *v;
        let text = RichText::new(*label).color(if on { c(t.on_accent) } else { c(t.text) });
        let mut b = egui::Button::new(text).min_size(vec2(0.0, size::CONTROL));
        if on {
            b = b.fill(c(t.accent)).stroke(Stroke::NONE);
        }
        if ui.add_enabled(*enabled, b).clicked() && !on {
            *value = *v;
            changed = true;
        }
    }
    changed
}

/// A list of checkboxes over a filter list where empty means "all". At
/// least one stays checked.
fn filter_checks(ui: &mut Ui, list: &mut Vec<String>, items: &[(&str, &str)], always: &[&str]) {
    let all: Vec<String> = items.iter().map(|(id, _)| id.to_string()).collect();
    let mut on: Vec<bool> = items
        .iter()
        .map(|(id, _)| list.is_empty() || list.iter().any(|x| x == id))
        .collect();
    let mut changed = false;
    ui.horizontal_wrapped(|ui| {
        ui.spacing_mut().item_spacing = vec2(space::S4, space::S2);
        for (i, (_, label)) in items.iter().enumerate() {
            let last_one = on[i] && on.iter().filter(|x| **x).count() == 1;
            if ui
                .add_enabled(!last_one, egui::Checkbox::new(&mut on[i], *label))
                .changed()
            {
                changed = true;
            }
        }
    });
    if changed {
        let picked: Vec<String> = all
            .iter()
            .zip(&on)
            .filter(|(_, o)| **o)
            .map(|(id, _)| id.clone())
            .collect();
        *list = if picked.len() == all.len() {
            Vec::new()
        } else {
            always.iter().map(|s| s.to_string()).chain(picked).collect()
        };
    }
}

fn page(
    ui: &mut Ui,
    theme: Theme,
    section: Section,
    s: &mut Settings,
    status: &Status,
    actions: &mut Vec<UiAction>,
) {
    let t = colors(theme);
    let before = s.clone();
    heading(ui, theme, section.name());
    match section {
        Section::Schedule => {
            row(
                ui,
                theme,
                "Change wallpaper every",
                "A new scene on this interval.",
                |ui| {
                    let current = INTERVALS
                        .iter()
                        .find(|(m, _)| *m == s.schedule.change_every_minutes)
                        .map(|(_, l)| *l)
                        .unwrap_or("Custom");
                    egui::ComboBox::from_id_salt("interval")
                        .selected_text(current)
                        .width(160.0)
                        .show_ui(ui, |ui| {
                            for (m, label) in INTERVALS {
                                ui.selectable_value(&mut s.schedule.change_every_minutes, m, label);
                            }
                        });
                },
            );
            row(
                ui,
                theme,
                "Also change at login",
                "Start each session with a fresh scene.",
                |ui| {
                    toggle(
                        ui,
                        theme,
                        &mut s.schedule.change_at_login,
                        "Also change at login",
                    );
                },
            );
            row(
                ui,
                theme,
                "Pause",
                "Keep the current wallpaper until you resume.",
                |ui| {
                    toggle(ui, theme, &mut s.schedule.paused, "Pause");
                },
            );
        }
        Section::Theme => {
            row(
                ui,
                theme,
                "Appearance",
                "Light and dark scenes use different times of day and palettes. Night-only scenes stay dark.",
                |ui| {
                    segmented(
                        ui,
                        theme,
                        &mut s.theme.mode,
                        &[
                            (ThemeMode::FollowSystem, "Follow system", true),
                            (ThemeMode::Light, "Light", true),
                            (ThemeMode::Dark, "Dark", true),
                        ],
                    );
                },
            );
        }
        Section::Display => {
            let mut still = true;
            row(
                ui,
                theme,
                "Wallpaper mode",
                "Still frame sets one image through the system. Animated wallpapers arrive in a later version.",
                |ui| {
                    segmented(
                        ui,
                        theme,
                        &mut still,
                        &[(true, "Still frame", true), (false, "Live", false)],
                    );
                },
            );
            row(
                ui,
                theme,
                "Monitors",
                "Each monitor gets its own scene at its own resolution, all from one seed.",
                |_| {},
            );
        }
        Section::Live => {
            ui.label(
                RichText::new(
                    "Animated wallpapers (embers, snow, Clawd moving) need the live renderer, which arrives in a later version. Until then the wallpaper is a still frame of the same scene.",
                )
                .color(c(t.text_secondary)),
            );
        }
        Section::Buddy => {
            row(
                ui,
                theme,
                "Show Clawd",
                "The pixel-art character in each scene.",
                |ui| {
                    toggle(ui, theme, &mut s.buddy.show, "Show Clawd");
                },
            );
            ui.label(
                RichText::new("Clawd is Anthropic's character, drawn here as fan art. Turning him off keeps the scenes and their props.")
                    .color(c(t.text_secondary)),
            );
        }
        Section::Content => {
            ui.label(
                RichText::new(
                    "New scenes pick from what's checked. Changes apply to the next wallpaper.",
                )
                .color(c(t.text_secondary)),
            );
            group(ui, "Landscapes");
            filter_checks(ui, &mut s.content.archetypes, &LANDSCAPES, &[]);
            ui.add_space(space::S4);
            group(ui, "What Clawd does");
            filter_checks(ui, &mut s.content.activities, &ACTIVITIES, &[]);
            ui.add_space(space::S4);
            group(ui, "Weather");
            filter_checks(ui, &mut s.content.weather, &WEATHER, &CLEAR_WEATHER);
        }
        Section::Archive => {
            row(
                ui,
                theme,
                "Keep wallpapers for",
                "Older ones are deleted unless pinned.",
                |ui| {
                    let label = match s.archive.keep_days {
                        0 => "Forever".to_string(),
                        1 => "1 day".to_string(),
                        d => format!("{d} days"),
                    };
                    egui::ComboBox::from_id_salt("keep")
                        .selected_text(label)
                        .width(160.0)
                        .show_ui(ui, |ui| {
                            for (d, l) in [
                                (1, "1 day"),
                                (7, "7 days"),
                                (30, "30 days"),
                                (90, "90 days"),
                                (0, "Forever"),
                            ] {
                                ui.selectable_value(&mut s.archive.keep_days, d, l);
                            }
                        });
                },
            );
            row(
                ui,
                theme,
                "Size limit",
                "The oldest wallpapers go first when the archive grows past this.",
                |ui| {
                    egui::ComboBox::from_id_salt("cap")
                        .selected_text(format!("{} GB", s.archive.max_mb.div_ceil(1024).max(1)))
                        .width(160.0)
                        .show_ui(ui, |ui| {
                            for gb in [1u64, 2, 5, 10] {
                                ui.selectable_value(
                                    &mut s.archive.max_mb,
                                    gb * 1024,
                                    format!("{gb} GB"),
                                );
                            }
                        });
                },
            );
            row(
                ui,
                theme,
                "Archive folder",
                "Every wallpaper set, with its recipe and images.",
                |ui| {
                    if ui.button("Open").clicked() {
                        actions.push(UiAction::OpenArchive);
                    }
                },
            );
        }
        Section::Export => {
            row(
                ui,
                theme,
                "Save current as PNG",
                "Copies the primary monitor's wallpaper to the export folder.",
                |ui| {
                    if ui.button("Save").clicked() {
                        actions.push(UiAction::SavePng);
                    }
                },
            );
            ui.label(RichText::new("Export folder").font(style::body_strong()));
            let hint = "Empty: Pictures\\Clairlune";
            ui.add(
                egui::TextEdit::singleline(&mut s.export.folder)
                    .hint_text(hint)
                    .desired_width(f32::INFINITY),
            );
            ui.label(RichText::new("Where saved images go.").color(c(t.text_secondary)));
        }
        Section::General => {
            match status.start_at_login {
                Some(mut on) => row(
                    ui,
                    theme,
                    "Start at login",
                    "Run Clairlune in the tray when you sign in.",
                    |ui| {
                        if toggle(ui, theme, &mut on, "Start at login").changed() {
                            actions.push(UiAction::SetStartAtLogin(on));
                        }
                    },
                ),
                None => row(
                    ui,
                    theme,
                    "Start at login",
                    "Available with the installers for this system.",
                    |ui| {
                        ui.add_enabled_ui(false, |ui| {
                            let mut off = false;
                            toggle(ui, theme, &mut off, "Start at login");
                        });
                    },
                ),
            }
            row(
                ui,
                theme,
                "Restore my wallpaper",
                "Puts back the wallpaper you had before Clairlune and pauses the schedule.",
                |ui| {
                    if ui.button("Restore").clicked() {
                        actions.push(UiAction::RestoreWallpaper);
                    }
                },
            );
            row(ui, theme, "Logs", "Details for bug reports.", |ui| {
                if ui.button("Open").clicked() {
                    actions.push(UiAction::OpenLogs);
                }
            });
            ui.add_space(space::S2);
            hairline(ui, t.hairline);
            ui.add_space(space::S3);
            ui.label(
                RichText::new(format!(
                    "Clairlune {}  generator {}",
                    env!("CARGO_PKG_VERSION"),
                    clairlune_scene::GENERATOR_VERSION
                ))
                .font(style::mono())
                .color(c(t.text_secondary)),
            );
            ui.label(
                RichText::new(
                    "Unofficial fan project, not affiliated with or endorsed by Anthropic. Clawd is Anthropic's character. Code under MIT or Apache-2.0; fonts under the SIL Open Font License.",
                )
                .color(c(t.text_secondary)),
            );
        }
    }
    if *s != before {
        actions.push(UiAction::SettingsChanged);
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn content_lists_cover_the_real_ids() {
        for (id, _) in LANDSCAPES {
            assert!(clairlune_scene::archetype::archetype(id).is_some(), "{id}");
        }
        let catalog = clairlune_scene::activity::builtin_catalog();
        for (id, _) in ACTIVITIES {
            assert!(catalog.get(id).is_some(), "{id}");
        }
        assert_eq!(
            ACTIVITIES.len(),
            catalog.activities.len(),
            "a new activity needs a label"
        );
        for id in WEATHER.iter().map(|(id, _)| *id).chain(CLEAR_WEATHER) {
            assert!(clairlune_scene::archetype::WEATHERS.contains(&id), "{id}");
        }
    }
}