| 1 | //! The App settings page: where the colors come from, the keys, and what budctl is. |
| 2 | |
| 3 | use std::path::Path; |
| 4 | |
| 5 | use iced::Element; |
| 6 | use iced::widget::{column, space, text}; |
| 7 | |
| 8 | use crate::Message; |
| 9 | use crate::icons::Icon; |
| 10 | use crate::theme::Look; |
| 11 | use crate::ui; |
| 12 | |
| 13 | /// Where the colors come from: the palette file followed, if any, and why it could not be used. |
| 14 | pub struct Colors<'a> { |
| 15 | pub file: Option<&'a Path>, |
| 16 | pub problem: Option<&'a str>, |
| 17 | } |
| 18 | |
| 19 | pub 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, which starts out with the built-in colors. \ |
| 31 | It is read again whenever the window gets focus.", |
| 32 | ) |
| 33 | .size(13) |
| 34 | .color(p.dim); |
| 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"), |
| 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 | } |