Krolyxon
Commit 090b358

Branches

Refs →

budctlcratesbudctl-guisrcsettings.rs

80 lines · 2.6 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, container, space};
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 source = match (colors.file, colors.problem) {
21 (_, Some(problem)) => format!("Built in: {problem}"),
22 (Some(file), None) if file.exists() => format!("From {}", file.display()),
23 _ => "Built in".to_owned(),
24 };
25 let none = || -> Element<'a, Message> { space().into() };
26 let palette = ui::setting(look, Icon::Settings, "Colors", Some(source), none(), None, false);
27 let how = container(ui::note(
28 look,
29 "budctl follows a matugen palette with Aurora's Material 3 keys (primary, tertiary, surfaceLow, \
30 outline…), so ~/.cache/matugen/aurora.json works as it is: the file given with --theme, else \
31 ~/.config/budctl/theme.json, which starts out with the built-in colors. It is read again \
32 whenever the window gets focus.",
33 ))
34 .padding([0, 18]);
35 let keys = ui::setting(
36 look,
37 Icon::Keys,
38 "Keys",
39 Some("Vim-like keys work on every page".to_owned()),
40 ui::pill(look, "Show keys", false, Message::ShowHelp),
41 None,
42 false,
43 );
44 let files = ui::setting(
45 look,
46 Icon::Settings,
47 "Preferences",
48 Some("~/.config/budctl/config.json: default device, idle time, start page. Read at launch.".to_owned()),
49 none(),
50 None,
51 false,
52 );
53 let log = ui::setting(
54 look,
55 Icon::Info,
56 "Log",
57 Some("~/.local/state/budctl/gui.log: errors and session events, started afresh each launch.".to_owned()),
58 none(),
59 None,
60 false,
61 );
62 let about = ui::setting(
63 look,
64 Icon::Info,
65 concat!("budctl ", env!("CARGO_PKG_VERSION")),
66 Some("GPL-3.0-or-later. No telemetry, no account: it talks to your buds over Bluetooth only.".to_owned()),
67 none(),
68 None,
69 false,
70 );
71 column![
72 ui::title(look, "app settings · colors, keys, files"),
73 column![ui::card(look, vec![palette]), how].spacing(10),
74 ui::card(look, vec![keys]),
75 ui::card(look, vec![files, log]),
76 ui::card(look, vec![about]),
77 ]
78 .spacing(18)
79 .into()
80}