super-stt-app/src/ui/icons.rs
Line | Count | Source |
1 | | // SPDX-License-Identifier: GPL-3.0-only |
2 | | |
3 | | //! Phosphor icons (regular weight) embedded for the settings UI. |
4 | | //! |
5 | | //! Source: <https://github.com/phosphor-icons/core> — SVGs use `currentColor`, |
6 | | //! so they pick up the active theme via the symbolic flag. |
7 | | |
8 | | use cosmic::iced::Length; |
9 | | use cosmic::iced::widget::svg; |
10 | | use cosmic::widget::icon::{self, Icon}; |
11 | | |
12 | | pub const GEAR: &[u8] = include_bytes!("../../resources/icons/phosphor/gear.svg"); |
13 | | pub const MICROPHONE: &[u8] = include_bytes!("../../resources/icons/phosphor/microphone.svg"); |
14 | | pub const KEYBOARD: &[u8] = include_bytes!("../../resources/icons/phosphor/keyboard.svg"); |
15 | | pub const BRAIN: &[u8] = include_bytes!("../../resources/icons/phosphor/brain.svg"); |
16 | | pub const PLUG: &[u8] = include_bytes!("../../resources/icons/phosphor/plug.svg"); |
17 | | pub const WARNING: &[u8] = include_bytes!("../../resources/icons/phosphor/warning.svg"); |
18 | | pub const CPU: &[u8] = include_bytes!("../../resources/icons/phosphor/cpu.svg"); |
19 | | pub const GRAPHICS_CARD: &[u8] = include_bytes!("../../resources/icons/phosphor/graphics-card.svg"); |
20 | | pub const CLOUD: &[u8] = include_bytes!("../../resources/icons/phosphor/cloud.svg"); |
21 | | pub const DOTS_THREE_VERTICAL: &[u8] = |
22 | | include_bytes!("../../resources/icons/phosphor/dots-three-vertical.svg"); |
23 | | pub const ARROWS_CLOCKWISE: &[u8] = |
24 | | include_bytes!("../../resources/icons/phosphor/arrows-clockwise.svg"); |
25 | | pub const PLAY: &[u8] = include_bytes!("../../resources/icons/phosphor/play.svg"); |
26 | | pub const STOP: &[u8] = include_bytes!("../../resources/icons/phosphor/stop.svg"); |
27 | | pub const GIT_BRANCH: &[u8] = include_bytes!("../../resources/icons/phosphor/git-branch.svg"); |
28 | | pub const BOOKS: &[u8] = include_bytes!("../../resources/icons/phosphor/books.svg"); |
29 | | |
30 | | /// The Super STT app logo (mic-with-"S"), themed via `currentColor`. Not a |
31 | | /// Phosphor glyph, so it lives at the app resources root rather than the |
32 | | /// phosphor set; shown beside the app name in the window header. |
33 | | pub const APP_LOGO: &[u8] = include_bytes!("../../resources/super-stt-icon.svg"); |
34 | | |
35 | | /// Build a themable [`Icon`] from one of the embedded Phosphor SVGs. |
36 | 0 | pub fn phosphor(bytes: &'static [u8]) -> Icon { |
37 | 0 | icon::from_svg_bytes(bytes).symbolic(true).icon() |
38 | 0 | } |
39 | | |
40 | | /// The symbolic [`Handle`](icon::Handle) for one of the embedded Phosphor SVGs, |
41 | | /// for widgets that take a handle directly (e.g. `button::icon`). |
42 | 0 | pub fn phosphor_handle(bytes: &'static [u8]) -> icon::Handle { |
43 | 0 | icon::from_svg_bytes(bytes).symbolic(true) |
44 | 0 | } |
45 | | |
46 | | /// Shared builder for a fixed-size symbolic Phosphor [`Svg`](cosmic::widget::Svg) |
47 | | /// tinted by a caller-supplied [`Svg`](cosmic::theme::Svg) color class. The |
48 | | /// plain [`Icon`] wrapper hides the `svg::Style::color` knob that does the |
49 | | /// tinting, so the tinted variants return the bare `Svg` widget instead. |
50 | 0 | fn tinted_svg( |
51 | 0 | bytes: &'static [u8], |
52 | 0 | size: f32, |
53 | 0 | class: cosmic::theme::Svg, |
54 | 0 | ) -> cosmic::widget::Svg<'static, cosmic::Theme> { |
55 | 0 | cosmic::widget::Svg::<cosmic::Theme>::new(svg::Handle::from_memory(bytes)) |
56 | 0 | .symbolic(true) |
57 | 0 | .class(class) |
58 | 0 | .width(Length::Fixed(size)) |
59 | 0 | .height(Length::Fixed(size)) |
60 | 0 | } |
61 | | |
62 | | /// A Phosphor icon tinted with the theme's *destructive* (red) color — used |
63 | | /// for unmet-requirement warnings inside a backend card. |
64 | 0 | pub fn phosphor_destructive( |
65 | 0 | bytes: &'static [u8], |
66 | 0 | size: f32, |
67 | 0 | ) -> cosmic::widget::Svg<'static, cosmic::Theme> { |
68 | 0 | tinted_svg( |
69 | 0 | bytes, |
70 | 0 | size, |
71 | 0 | cosmic::theme::Svg::custom(|t| svg::Style { |
72 | 0 | color: Some(t.cosmic().destructive.base.into()), |
73 | 0 | }), |
74 | | ) |
75 | 0 | } |
76 | | |
77 | | /// A Phosphor icon tinted with the theme's *warning* (yellow) color — used |
78 | | /// for the advisory "model may not fit in GPU memory" warning. |
79 | 0 | pub fn phosphor_warning( |
80 | 0 | bytes: &'static [u8], |
81 | 0 | size: f32, |
82 | 0 | ) -> cosmic::widget::Svg<'static, cosmic::Theme> { |
83 | 0 | tinted_svg( |
84 | 0 | bytes, |
85 | 0 | size, |
86 | 0 | cosmic::theme::Svg::custom(|t| svg::Style { |
87 | 0 | color: Some(t.cosmic().warning.base.into()), |
88 | 0 | }), |
89 | | ) |
90 | 0 | } |
91 | | |
92 | | /// A Phosphor icon tinted with an explicit `color` the caller resolves from |
93 | | /// the active theme. Used by the backend-capability chips, whose tone |
94 | | /// (accent / neutral) is chosen at view-build time. |
95 | 0 | pub fn phosphor_tinted( |
96 | 0 | bytes: &'static [u8], |
97 | 0 | size: f32, |
98 | 0 | color: cosmic::iced::Color, |
99 | 0 | ) -> cosmic::widget::Svg<'static, cosmic::Theme> { |
100 | 0 | tinted_svg( |
101 | 0 | bytes, |
102 | 0 | size, |
103 | 0 | cosmic::theme::Svg::custom(move |_| svg::Style { color: Some(color) }), |
104 | | ) |
105 | 0 | } |
106 | | |
107 | | /// The Super STT logo ([`APP_LOGO`]) rendered at `size` px, tinted to `color`. |
108 | | /// The "S" stays a transparent cutout (its mask drives the alpha, which the |
109 | | /// symbolic recolor preserves); everything else takes `color`. |
110 | 0 | pub fn app_logo( |
111 | 0 | size: f32, |
112 | 0 | color: cosmic::iced::Color, |
113 | 0 | ) -> cosmic::widget::Svg<'static, cosmic::Theme> { |
114 | 0 | tinted_svg( |
115 | | APP_LOGO, |
116 | 0 | size, |
117 | 0 | cosmic::theme::Svg::custom(move |_| svg::Style { color: Some(color) }), |
118 | | ) |
119 | 0 | } |