hyprforge_ui/widgets/
suggestions.rs1use crate::density;
10use crate::theme::{self, spacing, surface, FontScale};
11use crate::widgets::{meta_text, scaled_text, selectable_row_style};
12use iced::widget::{button, column, container, opaque, row};
13use iced::{Element, Length};
14
15#[derive(Debug, Clone, PartialEq, Eq)]
17pub struct Suggestion {
18 pub label: String,
19 pub hint: Option<String>,
20}
21
22pub fn suggestions<'a, Message: Clone + 'a>(
30 heading: Option<String>,
31 rows: &[Suggestion],
32 highlighted: Option<usize>,
33 on_choose: impl Fn(usize) -> Message,
34 empty: Option<String>,
35 mono: bool,
36 scale: FontScale,
37) -> Option<Element<'a, Message>> {
38 if rows.is_empty() && empty.is_none() {
39 return None;
40 }
41 let font = if mono { theme::mono_font() } else { iced::Font::DEFAULT };
42 let mut list = column![].width(Length::Fill).spacing(1);
43 if let Some(heading) = heading {
44 list = list.push(
45 container(meta_text(heading, density::META_TEXT_BASE, scale).font(font))
46 .padding([spacing::XS as u16, spacing::SM as u16]),
47 );
48 }
49 if rows.is_empty() {
50 if let Some(empty) = empty {
51 list = list.push(
52 container(meta_text(empty, density::META_TEXT_BASE, scale))
53 .padding([spacing::XS as u16, spacing::SM as u16]),
54 );
55 }
56 }
57 for (index, item) in rows.iter().enumerate() {
58 let selected = highlighted == Some(index);
59 let mut content = row![scaled_text(item.label.clone(), density::META_TEXT_BASE, scale)
60 .font(font)
61 .width(Length::Fill)]
62 .height(Length::Fill)
66 .align_y(iced::Alignment::Center)
67 .spacing(spacing::MD);
68 if let Some(hint) = &item.hint {
69 let hint = meta_text(hint.clone(), density::META_TEXT_BASE, scale);
73 content = content.push(if selected { hint.color(theme::text()) } else { hint });
74 }
75 list = list.push(
76 button(content)
77 .on_press(on_choose(index))
78 .width(Length::Fill)
79 .height(Length::Fixed(density::row_height(scale)))
80 .padding([0, spacing::SM as u16])
81 .style(move |t: &iced::Theme, status| selectable_row_style(t, status, selected)),
82 );
83 }
84 let panel = container(list)
88 .padding(spacing::XS)
89 .width(Length::Fill)
90 .style(|_t: &iced::Theme| container::Style {
91 background: Some(iced::Background::Color(surface::sidebar())),
92 border: iced::Border {
93 color: surface::card_border(),
94 width: 1.0,
95 radius: density::inner_radius().into(),
96 },
97 ..container::Style::default()
98 });
99 Some(opaque(panel))
100}