Files
horizon-airdef/launcher/src/themes_page.rs
T
Ludovic Marie 8beaa57331 launcher: an accent colour and a picture behind Home
Settings > Launcher picks an accent (violet by default, blue, teal, green, amber, red, pink)
and the player's own picture behind Home. An accent turns the violet tokens to its hue and
adjusts their lightness until text on the Play button and the accent on every background read
as well as the violet's. The picture is checked, copied under a name of its hash and shown
cropped under the banner's veils. CLI: settings accent NAME, settings background PATH|default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 05:07:38 +01:00

156 lines
5.2 KiB
Rust

//! Settings' accent colour and Home background rows (`horizon_launcher::themes`).
use super::*;
use horizon_launcher::themes::{self, Accent};
use std::path::PathBuf;
/// Each accent's swatch, in points.
const SWATCH: f32 = 26.;
impl Launcher {
/// The theme Settings ask for, under the window's own light or dark.
pub(super) fn settings_theme(&self, window: &Window) -> Theme {
Theme::for_appearance(
self.settings.appearance,
self.settings.accent,
window.appearance(),
)
}
/// The picture behind Home, if the player keeps one.
pub(super) fn home_background(&self) -> Option<PathBuf> {
themes::background(&backend::data_dir(), self.settings.background.as_deref())
}
pub(super) fn accent_row(&self, cx: &mut Context<Self>) -> Div {
let t = self.theme;
let mut swatches = div().flex().gap(px(6.));
for accent in Accent::ALL {
let face = Theme::for_appearance(
if t.dark {
backend::Appearance::Dark
} else {
backend::Appearance::Light
},
accent,
gpui::WindowAppearance::Dark,
)
.face;
let chosen = self.settings.accent == accent;
swatches = swatches.child(
keyboard(
div().id(SharedString::from(format!("accent-{}", accent.name()))),
&t,
)
.size(px(SWATCH))
.bg(face)
.border_2()
.border_color(if chosen { t.ink } else { t.outline })
.cursor_pointer()
.when(chosen, |d| {
d.flex()
.items_center()
.justify_center()
.child(div().size(px(8.)).bg(t.on_face))
})
.on_click(cx.listener(move |this, _: &ClickEvent, window, cx| {
this.settings.accent = accent;
this.settings.save();
this.theme = this.settings_theme(window);
cx.notify();
})),
);
}
index_row(
0,
tr("Accent colour"),
Some(
div()
.child(tr(
"Horizon's violet by default. Every colour keeps text as easy to read.",
))
.into_any_element(),
),
Some(swatches.into_any_element()),
&t,
)
}
fn choose_background(&mut self, cx: &mut Context<Self>) {
let paths = cx.prompt_for_paths(PathPromptOptions {
files: true,
directories: false,
multiple: false,
prompt: Some(tr("Choose").to_string().into()),
});
cx.spawn(async move |this, cx| {
let Ok(Ok(Some(mut paths))) = paths.await else {
return;
};
let Some(path) = paths.pop() else {
return;
};
let _ = this.update(cx, |this, cx| {
this.take_background(&path);
cx.notify();
});
})
.detach();
}
fn take_background(&mut self, path: &std::path::Path) {
match themes::keep_background(&backend::data_dir(), path) {
Ok(name) => {
self.settings.background = Some(name);
self.settings.save();
self.background_error = None;
}
Err(e) => self.background_error = Some(e),
}
}
pub(super) fn home_background_row(&self, cx: &mut Context<Self>) -> Div {
let t = self.theme;
let custom = self.home_background().is_some();
let mut actions = div().flex().gap(px(4.)).child(
button(
"background-choose",
"Choose a picture…",
Kind::Secondary,
&t,
)
.on_click(cx.listener(|this, _: &ClickEvent, _, cx| {
this.choose_background(cx);
cx.notify();
})),
);
if custom {
actions = actions.child(
button("background-reset", "Landscape", Kind::Ghost, &t).on_click(cx.listener(
|this, _: &ClickEvent, _, cx| {
this.settings.background = None;
this.settings.save();
cx.notify();
},
)),
);
}
let said = if custom {
tr("Your picture, behind Home, cropped to fill it.")
} else {
tr("Horizon's landscape. Pick a PNG, JPEG or WebP picture of your own.")
};
let detail = div().flex().flex_col().child(said.to_string()).children(
self.background_error
.clone()
.map(|e| div().text_color(t.danger).child(e)),
);
index_row(
0,
tr("Home background"),
Some(detail.into_any_element()),
Some(actions.into_any_element()),
&t,
)
}
}