Krolyxon
Commit c7666c2

Branches

Refs →

budctlcratesbudctl-guisrcearbuds.rs

67 lines · 2.0 KB · Rust

1//! The Earbud settings page: find the buds, and what they run.
2
3use iced::Element;
4use iced::widget::{column, text};
5
6use crate::buds::Buds;
7use crate::icons::Icon;
8use crate::theme::Look;
9use crate::ui;
10use crate::{Item, Marks, Message};
11
12/// What the keyboard cursor can rest on.
13pub fn items() -> Vec<Item> {
14 vec![Item::Find]
15}
16
17/// `ringing`: the buds were told to ring and not yet to stop.
18pub fn view<'a>(look: Look, buds: &'a Buds, ringing: bool, marks: Marks) -> Element<'a, Message> {
19 let p = look.p;
20 let about = match (marks.pending.contains(&Item::Find), ringing) {
21 (true, false) => "Starting…",
22 (true, true) => "Stopping…",
23 (false, true) => "Ringing: stop it once you have found them",
24 (false, false) => "Plays a loud sound from both buds",
25 };
26 let find = ui::setting(
27 look,
28 Icon::Find,
29 "Find my earbuds",
30 Some(about.to_owned()),
31 ui::pill(look, if ringing { "Stop" } else { "Ring" }, ringing, Message::Find),
32 None,
33 marks.focus == Some(Item::Find),
34 );
35 let value = |value: Option<&'a str>| -> Element<'a, Message> {
36 text(value.unwrap_or("Unknown")).size(14).color(p.dim).into()
37 };
38 let status = &buds.status;
39 let facts = vec![
40 ui::setting(look, Icon::Earbud, "Name", None, value(Some(&buds.name)), None, false),
41 ui::setting(
42 look,
43 Icon::Chip,
44 "Firmware",
45 None,
46 value(status.firmware.as_deref()),
47 None,
48 false,
49 ),
50 ui::setting(
51 look,
52 Icon::Info,
53 "Audio codec",
54 None,
55 value(status.codec.as_deref()),
56 None,
57 false,
58 ),
59 ];
60 column![
61 ui::title(look, "Earbud settings"),
62 ui::card(look, vec![find]),
63 column![ui::heading(look, "About these buds"), ui::card(look, facts)].spacing(10),
64 ]
65 .spacing(18)
66 .into()
67}