hyprforge_ui/widgets/
badges.rs1use super::Tint;
4use crate::density;
5use crate::theme::{self, surface, FontScale};
6use iced::widget::{container, text, text::IntoFragment, Text};
7use iced::{Background, Border, Element};
8
9const CHIP_FILL_ALPHA: f32 = 0.10;
15const CHIP_BORDER_ALPHA: f32 = 0.45;
16
17pub fn chip<'a, Message: 'a>(
24 label: impl IntoFragment<'a>,
25 tint: Tint,
26 scale: FontScale,
27) -> Element<'a, Message> {
28 let color = tint.iced();
29 container(
30 text(label)
31 .font(theme::mono_font())
32 .size(scale.apply(density::META_TEXT_BASE * 0.9))
33 .color(color)
34 .wrapping(iced::widget::text::Wrapping::None),
37 )
38 .padding([1.0, scale.apply(6.0)])
39 .style(move |_t: &iced::Theme| container::Style {
40 background: Some(Background::Color(iced::Color { a: CHIP_FILL_ALPHA, ..color })),
41 border: Border {
42 radius: density::nested_radius().into(),
43 width: 1.0,
44 color: iced::Color { a: CHIP_BORDER_ALPHA, ..color },
45 },
46 ..container::Style::default()
47 })
48 .into()
49}
50
51pub fn removable_chip<'a, Message: Clone + 'a>(
61 label: impl IntoFragment<'a>,
62 on_remove: Message,
63 scale: FontScale,
64) -> Element<'a, Message> {
65 let size = scale.apply(density::META_TEXT_BASE * 0.9);
66 let cross = iced::widget::button(text("\u{00d7}").size(size).color(theme::text_dim()))
67 .padding([0.0, scale.apply(2.0)])
68 .on_press(on_remove)
69 .style(|_t: &iced::Theme, status| iced::widget::button::Style {
70 background: matches!(status, iced::widget::button::Status::Hovered)
71 .then(|| Background::Color(surface::card())),
72 text_color: theme::text(),
73 border: Border { radius: density::nested_radius().into(), ..Border::default() },
74 ..iced::widget::button::Style::default()
75 });
76 container(
77 iced::widget::row![
78 text(label)
79 .font(theme::mono_font())
80 .size(size)
81 .color(theme::text())
82 .wrapping(iced::widget::text::Wrapping::None),
83 cross,
84 ]
85 .spacing(scale.apply(2.0))
86 .align_y(iced::Alignment::Center),
87 )
88 .padding([0.0, scale.apply(4.0)])
89 .style(|_t: &iced::Theme| container::Style {
90 background: Some(Background::Color(surface::row())),
91 border: Border { radius: density::nested_radius().into(), width: 1.0, color: surface::card_border() },
92 ..container::Style::default()
93 })
94 .into()
95}
96
97pub fn keycap<'a, Message: 'a>(label: impl IntoFragment<'a>, scale: FontScale) -> Element<'a, Message> {
104 container(
105 text(label)
106 .font(iced::Font { weight: iced::font::Weight::Semibold, ..theme::mono_font() })
107 .size(scale.apply(density::META_TEXT_BASE * 0.85))
108 .color(theme::text()),
109 )
110 .padding([1.0, scale.apply(6.0)])
111 .style(|_t: &iced::Theme| container::Style {
112 background: Some(Background::Color(surface::sidebar())),
113 border: Border {
114 radius: density::nested_radius().into(),
115 width: 1.0,
116 color: surface::card_border(),
117 },
118 ..container::Style::default()
119 })
120 .into()
121}
122
123pub fn config_line<'a>(content: impl IntoFragment<'a>, scale: FontScale) -> Text<'a> {
129 text(content)
130 .font(theme::mono_font())
131 .size(scale.apply(density::META_TEXT_BASE * 0.9))
132 .color(theme::text_dim())
133}