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 {
Rotation,
Theme,
Display,
Live,
Buddy,
Content,
Archive,
Export,
General,
}
impl Section {
pub const ALL: [Section; 9] = [
Section::Rotation,
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::Rotation => "Rotation",
Section::Theme => "Theme",
Section::Display => "Display",
Section::Live => "Live",
Section::Buddy => "Buddy",
Section::Content => "Content",
Section::Archive => "Archive",
Section::Export => "Export",
Section::General => "General",
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct Permission {
pub name: &'static str,
pub granted: bool,
pub open: UiAction,
}
#[derive(Clone, Debug, Default)]
pub struct Status {
pub what: String,
pub seed: Option<u64>,
pub theme: Option<Theme>,
pub next_in_minutes: Option<u64>,
pub busy: bool,
pub start_at_login: Option<bool>,
pub permissions: Vec<Permission>,
pub ask_start_at_login: bool,
pub monitors: Vec<(String, String)>,
pub update_note: Option<String>,
pub update_url: Option<String>,
pub checking_updates: bool,
pub update_in_place: bool,
pub update_how: Option<String>,
pub installing: Option<String>,
pub report: String,
pub removal: Option<Result<String, String>>,
pub note: Option<String>,
pub timeline_next: Option<String>,
pub timeline_problems: Vec<String>,
pub live: Option<String>,
pub live_supported: Option<String>,
pub crash_reports: usize,
pub detailed_until: Option<String>,
}
#[derive(Clone, Debug, PartialEq)]
pub enum UiAction {
SettingsChanged,
NewWallpaper,
Previous,
OpenArchive,
OpenLogs,
OpenCrashReports,
ExportDiagnostics,
SetDetailedLogging(bool),
SavePng,
SaveGif,
SetStartAtLogin(bool),
AnswerStartAtLogin(bool),
CheckUpdates,
OpenUpdate,
InstallUpdate,
ReportProblem,
RemoveEverything,
OpenLoginItems,
Quit,
RestoreWallpaper,
SaveToLibrary,
OpenLibrary,
EditTimeline,
OpenArchiveFolder,
ApplyArchive(String),
PinArchive {
name: String,
pinned: bool,
},
SaveArchiveToLibrary(String),
ExportArchive {
name: String,
gif: bool,
},
DeleteArchive(String),
TimelineChanged,
ApplyLibrary(String),
UpdateLibrary(Box<crate::library::Item>),
DeleteLibrary {
id: String,
forget: crate::timeline::Forget,
},
ExportLibrary {
id: String,
gif: bool,
},
}
pub struct ViewState {
pub section: Section,
pub thumb: Option<egui::TextureHandle>,
pub moon: Option<egui::TextureHandle>,
pub toast: Option<(String, std::time::Instant)>,
pub page: PageState,
}
#[derive(Default)]
pub struct PageState {
pub content_monitor: Option<String>,
pub report_open: bool,
pub toast: Option<String>,
pub scroll_to: Option<f32>,
pub remove_confirm: bool,
pub welcome_no_login: bool,
}
const TOAST: std::time::Duration = std::time::Duration::from_secs(2);
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"),
];
pub(super) type Item = (&'static str, &'static str, &'static str);
pub(super) const LOOKS: [Item; 2] = [
("line", "Line art", "The land in strokes of text"),
(
"dither",
"Dithered",
"Light and dark masses of dots and bars",
),
];
pub(super) const ZOOMS: [Item; 3] = [
("close", "Close", "Clawd up close, as he has always been"),
(
"wide",
"Wide",
"Clawd about half the size, in a bigger landscape",
),
("vast", "Vast", "Clawd tiny in a huge landscape"),
];
pub(super) const LANDSCAPES: [Item; 16] = [
("canyon", "Canyon", ""),
("mountains", "Mountains", ""),
("forest", "Forest", ""),
("desert", "Desert", ""),
("snowfield", "Snowfield", ""),
("shore", "Shore", ""),
("city_rooftops", "Rooftops", "City rooftops"),
("night_sky", "Night sky", ""),
("cave", "Cave", ""),
(
"interior",
"Indoors",
"A room, with a landscape through the window",
),
("meadow", "Meadow", "Rolling grass and wildflowers"),
("lake", "Lake", "Mountains mirrored in still water"),
("volcano", "Volcano", "A smoking cone and lava fields"),
("islands", "Islands", "Palm islets on a calm sea"),
("lunar", "The Moon", "Craters, with the Earth in the sky"),
("bamboo", "Bamboo", "A bamboo grove"),
];
pub(super) const ACTIVITIES: [Item; 32] = [
("warm_hands", "Campfire", "Warming hands by a fire"),
("stroll", "Strolling", ""),
("stargaze", "Stargazing", "Night only"),
("wizard_magic", "Spells", "Casting spells"),
("make_coffee", "Coffee", "Making coffee"),
("read_lantern", "Reading", "Reading by a lantern"),
("play_guitar", "Guitar", "Playing guitar"),
("fishing", "Fishing", "Off a pier, shore only"),
("fly_kite", "Kite", "Flying a kite, daytime"),
("skip_stones", "Skipping stones", "Shore only"),
("broom_flight", "Broom flight", "Evening and night"),
("paint_easel", "Painting", "At an easel, daytime"),
("snowballs", "Snowballs", "Snow only"),
("balloon_ride", "Balloon ride", "A hot-air balloon, daytime"),
("picnic", "Picnic", "Daytime"),
("chess", "Chess", ""),
("tennis", "Tennis", "Against a wall, daytime"),
("rowing", "Rowing", "A boat, shore only"),
("skiing", "Skiing", "Snow only"),
(
"hike_ridge",
"Ridge hike",
"Mountains; the land scrolls past",
),
("ski_tour", "Ski touring", "Snow; the land scrolls past"),
("sledding", "Sledding", "Snow; the land scrolls past"),
(
"forest_walk",
"Forest walk",
"Forest; the land scrolls past",
),
(
"desert_trek",
"Desert trek",
"Desert; the land scrolls past",
),
(
"broom_journey",
"Broom journey",
"Evening and night; the land scrolls past below",
),
(
"balloon_journey",
"Balloon journey",
"Daytime; the land drifts past below",
),
("bubbles", "Bubbles", "Blowing bubbles, daytime"),
("meditate", "Meditating", "By a cairn"),
("dance", "Dancing", "Evening and night"),
(
"catch_snowflakes",
"Snowflakes",
"Catching them, when it snows",
),
("sweep", "Sweeping", "Daytime"),
("hot_cocoa", "Hot cocoa", "In the cold"),
];
pub(super) const WEATHER: [Item; 11] = [
("snow", "Snow", ""),
("rain", "Rain", ""),
("fireflies", "Fireflies", ""),
("leaves", "Leaves", "Falling leaves"),
("dust", "Dust", ""),
("petals", "Petals", "Blossom drifting down"),
("fog", "Fog", "Mist along the ground"),
("blizzard", "Blizzard", "Snow on a gale"),
("ash", "Ash", "Falling ash, by a volcano"),
("sparkle", "Frost", "Ice crystals glinting in the cold"),
("confetti", "Confetti", "Over the rooftops"),
];
pub(super) 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| {
let mut area = egui::ScrollArea::vertical();
if let Some(y) = st.page.scroll_to.take() {
area = area.vertical_scroll_offset(y);
}
area.show(ui, |ui| {
ui.set_max_width(size::PAGE_MAX);
status_strip(ui, theme, st, status, actions);
ui.add_space(space::S6);
let buddy = settings.buddy.show;
page(
ui,
theme,
st.section,
&mut st.page,
settings,
status,
actions,
);
if let Some(text) = st.page.toast.take() {
st.toast = Some((text, std::time::Instant::now()));
}
if settings.buddy.show != buddy {
let text = if settings.buddy.show {
"Clawd joins the next wallpaper"
} else {
"Clawd skips the next wallpaper"
};
st.toast = Some((text.to_string(), std::time::Instant::now()));
}
});
});
toast(ui, theme, st);
if status.ask_start_at_login {
let before = settings.clone();
welcome(ui, theme, settings, status, &mut st.page, actions);
if *settings != before {
actions.push(UiAction::SettingsChanged);
}
}
}
fn tray_name() -> &'static str {
if cfg!(target_os = "macos") {
"menu bar"
} else {
"tray"
}
}
fn welcome(
ui: &mut Ui,
theme: Theme,
s: &mut Settings,
status: &Status,
ps: &mut PageState,
actions: &mut Vec<UiAction>,
) {
use crate::settings::{ThemeMode, WallpaperMode};
let t = colors(theme);
let modal = egui::Modal::new(egui::Id::unique("welcome"))
.frame(
egui::Frame::new()
.fill(c(t.bg_raised))
.stroke(Stroke::new(size::HAIRLINE, c(t.hairline)))
.corner_radius(radius::PANEL)
.inner_margin(egui::Margin::same(space::S5 as i8)),
)
.show(ui.ctx(), |ui| {
ui.set_max_width(460.0);
ui.label(RichText::new("Welcome to Clairlune").font(style::section()));
ui.add_space(space::S2);
ui.label(
RichText::new(
"A new landscape drawn in text on your desktop, with Clawd doing something in it, and a new one every hour. Everything is made on this computer.",
)
.color(c(t.text_secondary)),
);
ui.add_space(space::S4);
let line = |ui: &mut Ui, name: &str, control: &mut dyn FnMut(&mut Ui)| {
ui.horizontal(|ui| {
ui.label(RichText::new(name).font(style::body_strong()));
ui.with_layout(Layout::right_to_left(Align::Center), |ui| control(ui));
});
ui.add_space(space::S2);
};
let can_live = status.live_supported.is_none();
line(ui, "Wallpaper", &mut |ui| {
segmented(
ui,
theme,
&mut s.display.mode,
&[
(WallpaperMode::Still, "Still frame", true),
(WallpaperMode::Live, "Live", can_live),
],
);
});
let mut mode = match s.theme.mode {
ThemeMode::Schedule => ThemeMode::FollowSystem,
m => m,
};
let was = mode;
line(ui, "Theme", &mut |ui| {
segmented(
ui,
theme,
&mut mode,
&[
(ThemeMode::FollowSystem, "Like the system", true),
(ThemeMode::Light, "Light", true),
(ThemeMode::Dark, "Dark", true),
],
);
});
if mode != was {
s.theme.mode = mode;
}
if status.monitors.len() > 1 {
line(ui, "Monitors", &mut |ui| {
segmented(
ui,
theme,
&mut s.display.span,
&[(false, "One scene each", true), (true, "One across all", true)],
);
});
}
let mut login = !ps.welcome_no_login;
line(ui, "Start with the computer", &mut |ui| {
toggle(ui, theme, &mut login, "Start with the computer");
});
ps.welcome_no_login = !login;
ui.label(
RichText::new(format!(
"Live plays the scene behind your icons and pauses while an app covers the screen. Clairlune keeps running in the {}; all of this, and much more, is in Settings.",
tray_name()
))
.color(c(t.text_secondary)),
);
ui.add_space(space::S4);
ui.horizontal(|ui| {
if primary_button(ui, theme, "Start").clicked() {
actions.push(UiAction::AnswerStartAtLogin(login));
}
});
});
if modal.should_close()
&& !actions
.iter()
.any(|a| matches!(a, UiAction::AnswerStartAtLogin(_)))
{
actions.push(UiAction::AnswerStartAtLogin(false));
}
}
fn toast(ui: &mut Ui, theme: Theme, st: &mut ViewState) {
let Some((text, since)) = &st.toast else {
return;
};
let age = since.elapsed();
if age >= TOAST {
st.toast = None;
return;
}
let a = age.as_secs_f32();
let left = TOAST.as_secs_f32() - a;
let alpha = (a / 0.15).min(left / 0.5).clamp(0.0, 1.0);
let t = colors(theme);
egui::Area::new(egui::Id::unique("toast"))
.order(egui::Order::Foreground)
.anchor(Align2::CENTER_BOTTOM, vec2(0.0, -space::S6))
.interactable(false)
.show(ui.ctx(), |ui| {
egui::Frame::new()
.fill(c(t.bg_raised).gamma_multiply(alpha))
.stroke(Stroke::new(
size::HAIRLINE,
c(t.hairline).gamma_multiply(alpha),
))
.corner_radius(radius::PANEL)
.inner_margin(egui::Margin::symmetric(space::S4 as i8, space::S2 as i8))
.show(ui, |ui| {
ui.label(RichText::new(text).color(c(t.text_secondary).gamma_multiply(alpha)));
});
});
ui.ctx().request_repaint();
}
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)),
);
});
}
pub(super) 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,
);
}
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));
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 {
None if status.timeline_next.is_some() => {
status.timeline_next.clone().unwrap_or_default()
}
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_wrapped(|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 ui.button("Save to library").clicked() {
actions.push(UiAction::SaveToLibrary);
}
});
});
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(),
}
}
pub(super) 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)),
)
}
pub(super) 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);
}
pub(super) 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));
}
pub(super) 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);
}
fn theme_schedule(ui: &mut Ui, theme: Theme, s: &mut Settings) {
let t = colors(theme);
let note = |ui: &mut Ui, text: &str| {
ui.label(RichText::new(text).color(c(t.text_secondary)));
ui.add_space(space::S4);
};
row(
ui,
theme,
"Follow the sun",
"Dark from sunset to sunrise where you are. Worked out on this computer; nothing goes online.",
|ui| {
toggle(ui, theme, &mut s.theme.follow_sun, "Follow the sun");
},
);
if s.theme.follow_sun {
ui.label(RichText::new("Location").font(style::body_strong()));
let location = settled_text(
ui,
"theme-location",
&mut s.theme.location,
"40.71, -74.01",
220.0,
|t| t.trim().is_empty() || crate::sun::parse_location(t).is_some(),
);
match crate::sun::parse_location(&location) {
Some((lat, lon)) => {
let today = jiff::ZonedDateTime::now().date();
let text = match crate::sun::daylight(today, lat, lon) {
crate::sun::Daylight::Normal { rise, set } => format!(
"Today: sunrise {}, sunset {}.",
crate::timeline::local_hhmm(rise),
crate::timeline::local_hhmm(set)
),
crate::sun::Daylight::AlwaysUp => "The sun stays up all day today.".into(),
crate::sun::Daylight::AlwaysDown => "The sun stays down all day today.".into(),
};
note(ui, &text);
}
None => note(
ui,
"Latitude and longitude in degrees, south and west negative: 40.71, -74.01 for New York.",
),
}
return;
}
let mut valid = true;
row(
ui,
theme,
"Dark between",
"Light the rest of the day. 24-hour times.",
|ui| {
let ok = |text: &str| crate::settings::parse_clock(text).is_some();
let light = settled_text(
ui,
"theme-light-from",
&mut s.theme.light_from,
"",
56.0,
ok,
);
ui.label("and");
let dark = settled_text(ui, "theme-dark-from", &mut s.theme.dark_from, "", 56.0, ok);
valid = ok(&dark) && ok(&light);
},
);
if !valid {
note(ui, "Use 24-hour times like 19:00 and 07:00.");
}
}
fn settled_text(
ui: &mut Ui,
name: &str,
value: &mut String,
hint: &str,
width: f32,
valid: impl Fn(&str) -> bool,
) -> String {
let id = egui::Id::unique(("settled-text", name));
let mut text = ui
.data(|d| d.get_temp::<String>(id))
.unwrap_or_else(|| value.clone());
let r = ui.add(
egui::TextEdit::singleline(&mut text)
.id(id.with("edit"))
.hint_text(hint)
.desired_width(width),
);
if r.lost_focus() && valid(&text) {
value.clone_from(&text);
ui.data_mut(|d| d.remove::<String>(id));
} else if r.has_focus() || r.lost_focus() {
ui.data_mut(|d| d.insert_temp(id, text.clone()));
}
text
}
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);
});
if !description.is_empty() {
ui.label(RichText::new(description).color(c(t.text_secondary)));
}
ui.add_space(space::S4);
}
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
}
pub(super) 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;
let ordered: Vec<_> = if ui.layout().prefer_right_to_left() {
options.iter().rev().collect()
} else {
options.iter().collect()
};
for (v, label, enabled) in ordered {
let on = *value == *v;
let color = if on {
t.on_accent
} else if *enabled {
t.text
} else {
t.text_disabled
};
let text = RichText::new(*label).color(c(color));
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
}
pub(super) fn filter_checks(ui: &mut Ui, list: &mut Vec<String>, items: &[Item], 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::S2, space::S2);
for (i, (_, label, hint)) in items.iter().enumerate() {
let last_one = on[i] && on.iter().filter(|x| **x).count() == 1;
let mut r = chip(ui, on[i], label, !last_one);
if !hint.is_empty() {
r = r.on_hover_text(*hint);
}
if r.clicked() {
on[i] = !on[i];
changed = true;
}
}
if on.iter().any(|o| !o) {
let link = ui.add(
egui::Label::new(
RichText::new("All")
.color(ui.visuals().hyperlink_color)
.font(style::body()),
)
.sense(egui::Sense::click()),
);
if link
.on_hover_cursor(egui::CursorIcon::PointingHand)
.clicked()
{
on.fill(true);
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 chip(ui: &mut Ui, on: bool, label: &str, enabled: bool) -> egui::Response {
let v = ui.visuals().clone();
let accent = v.selection.bg_fill;
let text = if on {
v.text_color()
} else {
v.widgets.noninteractive.fg_stroke.color
};
let font = style::body();
let galley = ui.painter().layout_no_wrap(label.to_string(), font, text);
let check_w = if on { 14.0 } else { 0.0 };
let pad = space::S3;
let h = 26.0;
let w = galley.size().x + 2.0 * pad + check_w;
let sense = if enabled {
egui::Sense::click()
} else {
egui::Sense::hover()
};
let (rect, resp) = ui.allocate_exact_size(vec2(w, h), sense);
if ui.is_rect_visible(rect) {
let p = ui.painter();
let radius = egui::CornerRadius::same((h / 2.0) as u8);
let hovered = resp.hovered() && enabled;
let (fill, stroke) = if on {
(
accent.gamma_multiply(if hovered { 0.28 } else { 0.18 }),
Stroke::new(1.0, accent.gamma_multiply(0.9)),
)
} else {
(
if hovered {
v.widgets.hovered.weak_bg_fill
} else {
egui::Color32::TRANSPARENT
},
Stroke::new(1.0, v.widgets.noninteractive.bg_stroke.color),
)
};
p.rect(rect, radius, fill, stroke, egui::StrokeKind::Inside);
let mut x = rect.left() + pad;
if on {
let cy = rect.center().y;
let pts = [
egui::pos2(x, cy),
egui::pos2(x + 3.5, cy + 3.5),
egui::pos2(x + 9.0, cy - 3.5),
];
p.line(pts.to_vec(), Stroke::new(1.6, accent));
x += check_w;
}
let y = rect.center().y - galley.size().y / 2.0;
p.galley(egui::pos2(x, y), galley, text);
}
resp.on_hover_cursor(if enabled {
egui::CursorIcon::PointingHand
} else {
egui::CursorIcon::NotAllowed
})
}
fn page(
ui: &mut Ui,
theme: Theme,
section: Section,
ps: &mut PageState,
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::Rotation => {
use crate::settings::RotationMode;
row(
ui,
theme,
"Mode",
"Generate makes a new scene on a schedule. Timeline follows a daily plan of saved wallpapers and random scenes.",
|ui| {
segmented(
ui,
theme,
&mut s.rotation.mode,
&[
(RotationMode::Generate, "Generate", true),
(RotationMode::Timeline, "Timeline", true),
],
);
},
);
let timeline = s.rotation.mode == RotationMode::Timeline;
if timeline {
row(
ui,
theme,
"Timeline",
"Which wallpaper shows when, for every day or each weekday.",
|ui| {
if ui.button("Edit timeline").clicked() {
actions.push(UiAction::EditTimeline);
}
},
);
if let Some(next) = &status.timeline_next {
ui.label(
RichText::new(next)
.font(style::mono())
.color(c(t.text_secondary)),
);
ui.add_space(space::S2);
}
for p in &status.timeline_problems {
ui.label(RichText::new(p).color(c(t.danger)));
}
if !status.timeline_problems.is_empty() {
ui.add_space(space::S4);
}
}
let (name, description) = if timeline {
(
"Days without slots change every",
"Days with no slots get new scenes on this interval.",
)
} else {
("Change wallpaper every", "A new scene on this interval.")
};
row(ui, theme, name, description, |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);
}
});
});
if !timeline {
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),
(ThemeMode::Schedule, "Schedule", true),
],
);
},
);
if s.theme.mode == ThemeMode::Schedule {
theme_schedule(ui, theme, s);
}
}
Section::Display => {
use crate::settings::WallpaperMode;
let can_live = status.live_supported.is_none();
row(
ui,
theme,
"Wallpaper mode",
"Live plays the scene behind your desktop icons: Clawd moves, fires flicker, snow falls. Still frame sets one image and does nothing between changes.",
|ui| {
segmented(
ui,
theme,
&mut s.display.mode,
&[
(WallpaperMode::Still, "Still frame", true),
(WallpaperMode::Live, "Live", can_live),
],
);
},
);
if let Some(why) = &status.live_supported {
ui.label(RichText::new(why).color(c(t.text_secondary)));
ui.add_space(space::S4);
} else if s.display.mode == WallpaperMode::Live
&& let Some(live) = &status.live
{
ui.label(
RichText::new(live)
.font(style::mono())
.color(c(t.text_secondary)),
);
ui.add_space(space::S4);
}
row(
ui,
theme,
"Monitors",
"One scene each, at each monitor's own resolution, or one wide scene spread across all of them (best with monitors side by side).",
|ui| {
segmented(
ui,
theme,
&mut s.display.span,
&[(false, "One each", true), (true, "Spread across", true)],
);
},
);
if status.monitors.len() > 1 && s.display.mode == WallpaperMode::Live && can_live {
group(ui, "Each monitor");
ui.label(
RichText::new(
"A monitor can keep the still frame while Live plays on the others. What each one shows is set under Content.",
)
.color(c(t.text_secondary)),
);
ui.add_space(space::S2);
for (id, label) in &status.monitors {
let mut still = s.still_only(id);
let was = still;
ui.horizontal(|ui| {
ui.label(RichText::new(label).font(style::body_strong()));
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
segmented(
ui,
theme,
&mut still,
&[(false, "Live", true), (true, "Still frame", true)],
);
});
});
ui.add_space(space::S2);
if still != was {
s.edit_monitor(id, label, |m| m.still = still);
}
}
ui.add_space(space::S2);
}
}
Section::Live => {
const SMOOTHNESS: [(u32, &str, &str); 5] = [
(
6,
"Battery saver",
"6 frames a second: the lightest, and the choppiest. Every setting moves at the same speed.",
),
(
12,
"Balanced",
"12 frames a second, the pixel art's own rhythm. Every setting moves at the same speed.",
),
(
24,
"Smooth",
"24 frames a second: smoother, a little more work. Every setting moves at the same speed.",
),
(
30,
"Very smooth",
"30 frames a second. Every setting moves at the same speed.",
),
(
60,
"Ultra smooth",
"60 frames a second: the smoothest, the most work. Every setting moves at the same speed.",
),
];
let current = SMOOTHNESS
.iter()
.find(|(f, _, _)| *f == s.live.smoothness_fps)
.copied()
.unwrap_or(SMOOTHNESS[1]);
row(ui, theme, "Smoothness", current.2, |ui| {
egui::ComboBox::from_id_salt("smoothness")
.selected_text(current.1)
.show_ui(ui, |ui| {
for (fps, name, _) in SMOOTHNESS {
ui.selectable_value(&mut s.live.smoothness_fps, fps, name);
}
});
});
row(
ui,
theme,
"Pause behind full-screen apps",
"When an app fills the screen (maximized, zoomed or full screen), the wallpaper under it stops moving.",
|ui| {
use crate::settings::CoverPause;
segmented(
ui,
theme,
&mut s.live.pause_when_covered,
&[
(CoverPause::ThatMonitor, "That monitor", true),
(CoverPause::AllMonitors, "All monitors", true),
(CoverPause::Off, "Off", true),
],
);
},
);
row(
ui,
theme,
"Battery saver on battery",
"On battery, drop to 6 frames a second.",
|ui| {
toggle(
ui,
theme,
&mut s.live.battery_saver_on_battery,
"Battery saver on battery",
);
},
);
if cfg!(target_os = "macos") {
row(
ui,
theme,
"Lighter on Retina screens",
"Draws the wallpaper at half the resolution on Retina screens: about a quarter of the memory and less work, with slightly softer text. Applies to the wallpaper on screen now.",
|ui| {
toggle(
ui,
theme,
&mut s.live.lighter_on_retina,
"Lighter on Retina screens",
);
},
);
}
row(
ui,
theme,
"Pause on battery",
"On battery, stop the animation; the frame stays on screen.",
|ui| {
toggle(ui, theme, &mut s.live.pause_on_battery, "Pause on battery");
},
);
ui.label(
RichText::new(
"Live also pauses while the computer is locked or the displays are off. Frames are drawn on the graphics card the monitor is plugged into.",
)
.color(c(t.text_secondary)),
);
if s.display.mode != crate::settings::WallpaperMode::Live {
ui.add_space(space::S2);
ui.label(
RichText::new("The wallpaper is a still frame now (Display, Wallpaper mode).")
.color(c(t.text_secondary)),
);
}
}
Section::Buddy => {
ui.horizontal(|ui| {
ui.label(RichText::new("Show Clawd").font(style::body_strong()));
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
toggle(ui, theme, &mut s.buddy.show, "Show Clawd");
});
});
}
Section::Content => {
ui.label(
RichText::new(
"New scenes pick from what's selected; hover for what each needs. Changes apply to the next wallpaper.",
)
.color(c(t.text_secondary)),
);
let span = s.display.span;
if status.monitors.len() > 1 {
ui.add_space(space::S3);
if span {
ui.label(
RichText::new(
"The monitors share one spread-across scene, so it picks from the choices for all of them.",
)
.color(c(t.text_secondary)),
);
} else {
let mut pick = ps
.content_monitor
.as_ref()
.and_then(|id| status.monitors.iter().position(|(m, _)| m == id))
.map_or(0, |i| i + 1);
let mut options = vec![(0usize, "All monitors", true)];
for (i, (_, label)) in status.monitors.iter().enumerate() {
options.push((i + 1, label.as_str(), true));
}
ui.horizontal_wrapped(|ui| {
segmented(ui, theme, &mut pick, &options);
});
ps.content_monitor = pick
.checked_sub(1)
.and_then(|i| status.monitors.get(i))
.map(|(id, _)| id.clone());
}
ui.add_space(space::S3);
}
let selected = ps
.content_monitor
.clone()
.filter(|_| !span)
.and_then(|id| status.monitors.iter().find(|(m, _)| *m == id).cloned());
if let Some((id, label)) = &selected {
let mut own = s.monitor(id).is_some_and(|m| m.content.is_some());
let was = own;
row(
ui,
theme,
"Its own choices",
"On, this monitor's new scenes pick from the choices below, set for it alone. Off, it picks from the choices for all monitors.",
|ui| {
toggle(ui, theme, &mut own, "Its own choices");
},
);
if own != was {
let shared = s.content.clone();
s.edit_monitor(id, label, |m| m.content = own.then_some(shared));
}
}
let own_id = selected
.as_ref()
.map(|(id, _)| id.clone())
.filter(|id| s.monitor(id).is_some_and(|m| m.content.is_some()));
let mut shown = s.content.clone();
let editable = selected.is_none() || own_id.is_some();
let content: &mut crate::settings::Content = match &own_id {
Some(id) => s
.display
.monitors
.iter_mut()
.find(|m| m.id == *id)
.and_then(|m| m.content.as_mut())
.expect("checked above"),
None if selected.is_some() => &mut shown,
None => &mut s.content,
};
ui.add_enabled_ui(editable, |ui| {
group(ui, "Landscapes");
filter_checks(ui, &mut content.archetypes, &LANDSCAPES, &[]);
ui.add_space(space::S4);
group(ui, "What Clawd does");
filter_checks(ui, &mut content.activities, &ACTIVITIES, &[]);
ui.add_space(space::S4);
group(ui, "Weather");
filter_checks(ui, &mut content.weather, &WEATHER, &CLEAR_WEATHER);
ui.add_space(space::S4);
group(ui, "Look");
ui.label(
RichText::new(
"Line art draws the land in strokes of text. Dithered draws it as light and dark masses, every character a dot or a bar sized by how bright it is there.",
)
.color(c(t.text_secondary)),
);
filter_checks(ui, &mut content.looks, &LOOKS, &[]);
ui.add_space(space::S2);
row(
ui,
theme,
"Contrast",
"How strong the ink is against the background. Vary picks one for each wallpaper.",
|ui| {
use crate::settings::Contrast;
segmented(
ui,
theme,
&mut content.contrast,
&[
(Contrast::Soft, "Soft", true),
(Contrast::Normal, "Normal", true),
(Contrast::High, "High", true),
(Contrast::Vary, "Vary", true),
],
);
},
);
ui.add_space(space::S4);
group(ui, "Zoom");
ui.label(
RichText::new(
"How far back the view stands. Close shows Clawd as he has always been; Wide and Vast make him smaller and the landscape bigger. With more than one on, each wallpaper picks one.",
)
.color(c(t.text_secondary)),
);
filter_checks(ui, &mut content.zooms, &ZOOMS, &[]);
});
}
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,
"Library",
"Wallpapers you saved. They are never deleted automatically.",
|ui| {
if ui.button("Open").clicked() {
actions.push(UiAction::OpenLibrary);
}
},
);
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);
}
},
);
row(
ui,
theme,
"Save current as GIF",
"A 6-second loop of the scene as it plays, for sharing. Saved wallpapers keep the full scene.",
|ui| {
if ui.button("Save").clicked() {
actions.push(UiAction::SaveGif);
}
},
);
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 => {
let tray_desc = format!(
"Starts quietly in the {} when you sign in, with no window.",
tray_name()
);
match status.start_at_login {
Some(mut on) => row(ui, theme, "Start at login", &tray_desc, |ui| {
if toggle(ui, theme, &mut on, "Start at login").changed() {
actions.push(UiAction::SetStartAtLogin(on));
}
}),
None => row(
ui,
theme,
"Start at login",
"Not available on this system.",
|ui| {
ui.add_enabled_ui(false, |ui| {
let mut off = false;
toggle(ui, theme, &mut off, "Start at login");
});
},
),
}
let (icon_name, back) = if cfg!(target_os = "macos") {
("Show menu bar icon", "Launchpad or Spotlight")
} else if cfg!(windows) {
("Show tray icon", "the Start menu")
} else {
("Show tray icon", "your app menu")
};
row(
ui,
theme,
icon_name,
&format!(
"Hidden, Clairlune keeps running in the background. Open it again from {back} to come back here."
),
|ui| {
toggle(ui, theme, &mut s.general.show_tray_icon, icon_name);
},
);
if cfg!(any(target_os = "macos", windows)) {
group(ui, "Permissions");
if status.permissions.is_empty() {
ui.label(
RichText::new("Nothing to allow for what's on now.")
.color(c(t.text_secondary)),
);
ui.add_space(space::S4);
}
for p in &status.permissions {
ui.horizontal(|ui| {
ui.label(RichText::new(p.name).font(style::body_strong()));
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
if p.granted {
ui.label(RichText::new("Granted").color(c(t.accent)));
} else if ui.button("Open Settings").clicked() {
actions.push(p.open.clone());
}
});
});
ui.add_space(space::S3);
}
ui.add_space(space::S2);
}
row(ui, theme, "Check for updates", "Once a day", |ui| {
toggle(ui, theme, &mut s.general.check_updates, "Check for updates");
});
ui.horizontal_wrapped(|ui| {
let busy = status.checking_updates || status.installing.is_some();
let label = if status.checking_updates {
"Checking\u{2026}"
} else {
"Check now"
};
if ui.add_enabled(!busy, egui::Button::new(label)).clicked() {
actions.push(UiAction::CheckUpdates);
}
if status.update_url.is_some() {
if status.update_in_place {
if status.installing.is_none()
&& primary_button(ui, theme, "Update now").clicked()
{
actions.push(UiAction::InstallUpdate);
}
if ui.button("What's new").clicked() {
actions.push(UiAction::OpenUpdate);
}
} else if primary_button(ui, theme, "Download").clicked() {
actions.push(UiAction::OpenUpdate);
}
}
let note = status.installing.clone().unwrap_or_else(|| {
status
.update_note
.clone()
.unwrap_or_else(|| format!("Clairlune {}", env!("CARGO_PKG_VERSION")))
});
ui.label(RichText::new(note).color(c(t.text_secondary)));
});
if status.update_url.is_some()
&& status.installing.is_none()
&& let Some(how) = &status.update_how
{
ui.label(RichText::new(how).color(c(t.text_secondary)));
} else if status.update_url.is_some()
&& status.update_in_place
&& status.installing.is_none()
{
ui.label(
RichText::new(
"Update now downloads it from GitHub, checks it, installs it and starts Clairlune again.",
)
.color(c(t.text_secondary)),
);
}
ui.add_space(space::S4);
row(ui, theme, "Quit Clairlune", "", |ui| {
if ui.button("Quit").clicked() {
actions.push(UiAction::Quit);
}
});
row(ui, theme, "Restore my wallpaper", "", |ui| {
if ui.button("Restore").clicked() {
actions.push(UiAction::RestoreWallpaper);
}
});
row(ui, theme, "Remove Clairlune", "", |ui| {
if ui.button("Remove\u{2026}").clicked() {
ps.remove_confirm = !ps.remove_confirm;
}
});
if ps.remove_confirm {
egui::Frame::new()
.fill(c(t.bg_sidebar))
.stroke(Stroke::new(size::HAIRLINE, c(t.hairline)))
.corner_radius(egui::CornerRadius::same(6))
.inner_margin(egui::Margin::same(space::S4 as i8))
.show(ui, |ui| {
ui.label(
RichText::new("Remove Clairlune from this computer?")
.font(style::body_strong()),
);
ui.add_space(space::S2);
let mut goes = vec![
"Your wallpaper from before Clairlune comes back.".to_string(),
"Starting with the computer is turned off.".to_string(),
];
goes.push(
"Its settings, archive, library, saved scenes and logs are deleted. PNGs and GIFs you exported stay where you saved them."
.into(),
);
if let Some(Ok(app)) = &status.removal {
goes.push(format!("Then Clairlune quits, and {app} goes too."));
} else {
goes.push("Then Clairlune quits.".into());
}
for g in &goes {
ui.label(RichText::new(format!("\u{2022} {g}")).color(c(t.text_secondary)));
}
if let Some(Err(how)) = &status.removal {
ui.add_space(space::S1);
ui.label(RichText::new(how).color(c(t.text_secondary)));
}
ui.add_space(space::S3);
ui.horizontal(|ui| {
let danger = egui::Button::new(
RichText::new("Remove everything").color(c(t.on_accent)),
)
.fill(c(t.danger));
if ui.add(danger).clicked() {
actions.push(UiAction::RemoveEverything);
ps.remove_confirm = false;
}
if ui.button("Cancel").clicked() {
ps.remove_confirm = false;
}
});
});
ui.add_space(space::S4);
}
row(
ui,
theme,
"Report a problem",
"Opens a new issue on GitHub with the details below filled in, for you to describe what happened and send (a GitHub account is needed). Nothing is sent until you do.",
|ui| {
if primary_button(ui, theme, "Report on GitHub").clicked() {
actions.push(UiAction::ReportProblem);
}
if ui.button("Copy details").clicked() {
ui.ctx().copy_text(status.report.clone());
ps.toast = Some("Copied the details".into());
}
},
);
let shown = if ps.report_open {
"Hide the details"
} else {
"Show the details"
};
if ui.link(shown).clicked() {
ps.report_open = !ps.report_open;
}
if ps.report_open {
egui::Frame::new()
.fill(c(t.bg_sidebar))
.corner_radius(egui::CornerRadius::same(6))
.inner_margin(egui::Margin::same(space::S3 as i8))
.show(ui, |ui| {
egui::ScrollArea::vertical()
.id_salt("report")
.max_height(220.0)
.min_scrolled_height(200.0)
.show(ui, |ui| {
ui.label(
RichText::new(&status.report)
.font(style::mono())
.color(c(t.text_secondary)),
);
});
});
}
ui.add_space(space::S4);
row(ui, theme, "Logs", "Details for bug reports.", |ui| {
if ui.button("Open").clicked() {
actions.push(UiAction::OpenLogs);
}
});
let detailed_text = match &status.detailed_until {
Some(until) => format!("On until {until}, then back to normal."),
None => "Logs much more for a day, for a bug report.".to_string(),
};
row(ui, theme, "Detailed logging", &detailed_text, |ui| {
let mut on = status.detailed_until.is_some();
if toggle(ui, theme, &mut on, "Detailed logging").changed() {
actions.push(UiAction::SetDetailedLogging(on));
}
});
row(
ui,
theme,
"Diagnostics",
"One zip for a bug report: system facts, recent logs, crash reports, recipes and settings, with your home folder written as ~. Nothing is sent anywhere.",
|ui| {
if ui.button("Export").clicked() {
actions.push(UiAction::ExportDiagnostics);
}
},
);
if status.crash_reports > 0 {
let n = status.crash_reports;
row(
ui,
theme,
"Crash reports",
&format!(
"{n} report{} from times Clairlune stopped unexpectedly.",
if n == 1 { "" } else { "s" }
),
|ui| {
if ui.button("Open").clicked() {
actions.push(UiAction::OpenCrashReports);
}
},
);
}
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::*;
fn ask_frames(events: &[egui::Event], frames: usize) -> Vec<UiAction> {
let ctx = egui::Context::default();
style::apply(&ctx, Theme::Light);
let mut st = ViewState {
section: Section::General,
thumb: None,
moon: None,
toast: None,
page: PageState::default(),
};
let mut settings = Settings::default();
let status = Status {
ask_start_at_login: true,
start_at_login: Some(false),
..Status::default()
};
let mut actions = Vec::new();
for i in 0..frames {
let input = egui::RawInput {
screen_rect: Some(egui::Rect::from_min_size(
egui::Pos2::ZERO,
vec2(900.0, 640.0),
)),
events: if i + 1 == frames {
events.to_vec()
} else {
Vec::new()
},
..Default::default()
};
ctx.run_ui(input, |ui| {
show(
ui,
Theme::Light,
&mut st,
&mut settings,
&status,
&mut actions,
)
})
.drop_without_applying_deltas();
}
actions
}
#[test]
fn the_first_run_question_waits_and_escape_is_not_now() {
assert!(ask_frames(&[], 3).is_empty());
let escape = |pressed| egui::Event::Key {
key: egui::Key::Escape,
physical_key: None,
pressed,
repeat: false,
modifiers: egui::Modifiers::NONE,
};
assert_eq!(
ask_frames(&[escape(true), escape(false)], 3),
vec![UiAction::AnswerStartAtLogin(false)]
);
}
#[test]
fn a_half_typed_time_reaches_the_settings_only_when_done() {
use egui::{Event, Key, Modifiers, RawInput};
let ctx = egui::Context::default();
let mut value = String::new();
let frame = |events: Vec<Event>, value: &mut String| {
let input = RawInput {
events,
..Default::default()
};
ctx.run_ui(input, |ui| {
settled_text(ui, "test-clock", value, "", 56.0, |t| {
crate::settings::parse_clock(t).is_some()
});
})
.drop_without_applying_deltas();
};
frame(Vec::new(), &mut value);
ctx.memory_mut(|m| {
m.request_focus(egui::Id::unique(("settled-text", "test-clock")).with("edit"))
});
frame(Vec::new(), &mut value);
for key in ["2", "0", ":", "0", "0"] {
frame(vec![Event::Text(key.into())], &mut value);
assert_eq!(value, "", "changed while typing");
}
let enter = |pressed| Event::Key {
key: Key::Enter,
physical_key: None,
pressed,
repeat: false,
modifiers: Modifiers::NONE,
};
frame(vec![enter(true), enter(false)], &mut value);
frame(Vec::new(), &mut value);
assert_eq!(value, "20:00");
}
#[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}");
}
let zooms: Vec<&str> = ZOOMS.iter().map(|(id, _, _)| *id).collect();
assert_eq!(zooms, clairlune_scene::ZOOMS);
}
}