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 content = content.push(meta_text(hint.clone(), density::META_TEXT_BASE, scale));
70 }
71 list = list.push(
72 button(content)
73 .on_press(on_choose(index))
74 .width(Length::Fill)
75 .height(Length::Fixed(density::row_height(scale)))
76 .padding([0, spacing::SM as u16])
77 .style(move |t: &iced::Theme, status| selectable_row_style(t, status, selected)),
78 );
79 }
80 let panel = container(list)
84 .padding(spacing::XS)
85 .width(Length::Fill)
86 .style(|_t: &iced::Theme| container::Style {
87 background: Some(iced::Background::Color(surface::sidebar())),
88 border: iced::Border {
89 color: surface::card_border(),
90 width: 1.0,
91 radius: density::inner_radius().into(),
92 },
93 ..container::Style::default()
94 });
95 Some(opaque(panel))
96}