Krolyxon
Commit c7666c2

Branches

Refs →

budctlcratesbudctl-guisrcsettings.rs

60 lines · 1.9 KB · Rust

1//! The App settings page: where the colors come from, the keys, and what budctl is.
2
3use std::path::Path;
4
5use iced::Element;
6use iced::widget::{column, space, text};
7
8use crate::Message;
9use crate::icons::Icon;
10use crate::theme::Look;
11use crate::ui;
12
13/// Where the colors come from: the palette file followed, if any, and why it could not be used.
14pub struct Colors<'a> {
15 pub file: Option<&'a Path>,
16 pub problem: Option<&'a str>,
17}
18
19pub fn view<'a>(look: Look, colors: Colors<'a>) -> Element<'a, Message> {
20 let p = look.p;
21 let source = match (colors.file, colors.problem) {
22 (_, Some(problem)) => format!("Built in: {problem}"),
23 (Some(file), None) if file.exists() => format!("From {}", file.display()),
24 _ => "Built in".to_owned(),
25 };
26 let none = || -> Element<'a, Message> { space().into() };
27 let palette = ui::setting(look, Icon::Settings, "Colors", Some(source), none(), None, false);
28 let how = text(
29 "budctl follows a matugen palette with Aurora's keys (bg, fg, primary, surface…): the file given \
30 with --theme, else ~/.config/budctl/theme.json. It is read again whenever the window gets focus.",
31 )
32 .size(13)
33 .color(p.dim);
34 let keys = ui::setting(
35 look,
36 Icon::Keys,
37 "Keys",
38 Some("Vim-like keys work on every page".to_owned()),
39 ui::pill(look, "Show keys", false, Message::ShowHelp),
40 None,
41 false,
42 );
43 let about = ui::setting(
44 look,
45 Icon::Info,
46 concat!("budctl ", env!("CARGO_PKG_VERSION")),
47 Some("GPL-3.0-or-later. No telemetry, no account: it talks to your buds over Bluetooth only.".to_owned()),
48 none(),
49 None,
50 false,
51 );
52 column![
53 ui::title(look, "App settings"),
54 column![ui::card(look, vec![palette]), how].spacing(10),
55 ui::card(look, vec![keys]),
56 ui::card(look, vec![about]),
57 ]
58 .spacing(18)
59 .into()
60}