super-stt-app/src/ui/views/contexts/surface.rs
Line | Count | Source |
1 | | // SPDX-License-Identifier: GPL-3.0-only |
2 | | //! The two container styles this page draws with. |
3 | | //! |
4 | | //! Deliberately its own small module rather than a reach into |
5 | | //! [`views::models::surface`](crate::ui::views::models::surface): those helpers |
6 | | //! are `pub(super)` to the models tree, and widening a dozen of them so one |
7 | | //! other page can borrow two would make every one of them a shared surface that |
8 | | //! has to be kept stable. The card here is the same shape by construction — it |
9 | | //! reads the same theme tokens — and that is the part worth sharing. |
10 | | |
11 | | use cosmic::Element; |
12 | | use cosmic::iced::Length; |
13 | | use cosmic::widget; |
14 | | |
15 | | use crate::ui::messages::Message; |
16 | | |
17 | | /// A card: the page's one raised surface, accented when it is the active |
18 | | /// context. |
19 | 0 | pub(super) fn card<'a>( |
20 | 0 | content: impl Into<Element<'a, Message>>, |
21 | 0 | active: bool, |
22 | 0 | ) -> Element<'a, Message> { |
23 | 0 | widget::container(content.into()) |
24 | 0 | .padding(cosmic::theme::spacing().space_s) |
25 | 0 | .width(Length::Fill) |
26 | 0 | .class(cosmic::theme::Container::custom(move |theme| { |
27 | 0 | let cosmic = theme.cosmic(); |
28 | 0 | let component = &theme.current_container().component; |
29 | 0 | let border_color = if active { |
30 | 0 | cosmic.accent_color().into() |
31 | | } else { |
32 | 0 | component.divider.into() |
33 | | }; |
34 | 0 | cosmic::iced::widget::container::Style { |
35 | 0 | icon_color: Some(component.on.into()), |
36 | 0 | text_color: Some(component.on.into()), |
37 | 0 | background: Some(cosmic::iced::Background::Color(component.base.into())), |
38 | 0 | border: cosmic::iced::Border { |
39 | 0 | radius: cosmic.corner_radii.radius_m.into(), |
40 | 0 | width: 1.0, |
41 | 0 | color: border_color, |
42 | 0 | }, |
43 | 0 | shadow: cosmic::iced::Shadow { |
44 | 0 | color: cosmic::iced::Color { |
45 | 0 | r: 0.0, |
46 | 0 | g: 0.0, |
47 | 0 | b: 0.0, |
48 | 0 | a: 0.12, |
49 | 0 | }, |
50 | 0 | offset: cosmic::iced::Vector::new(0.0, 1.0), |
51 | 0 | blur_radius: 4.0, |
52 | 0 | }, |
53 | 0 | snap: true, |
54 | 0 | } |
55 | 0 | })) |
56 | 0 | .into() |
57 | 0 | } |
58 | | |
59 | | /// A faint rule inside a card. |
60 | 0 | pub(super) fn plain_divider<'a>() -> Element<'a, Message> { |
61 | 0 | widget::divider::horizontal::default().into() |
62 | 0 | } |
63 | | |
64 | | /// Dim a secondary line so it reads as a caption rather than as body text. |
65 | 0 | pub(super) fn muted<'a>(content: impl Into<Element<'a, Message>>) -> Element<'a, Message> { |
66 | 0 | widget::container(content.into()) |
67 | 0 | .class(cosmic::theme::Container::custom(|theme| { |
68 | 0 | let mut color: cosmic::iced::Color = theme.current_container().component.on.into(); |
69 | 0 | color.a *= 0.7; |
70 | 0 | cosmic::iced::widget::container::Style { |
71 | 0 | text_color: Some(color), |
72 | 0 | ..Default::default() |
73 | 0 | } |
74 | 0 | })) |
75 | 0 | .into() |
76 | 0 | } |