functora_egui/widgets/command/
widget.rs1use crate::icons::lucide_icon::LucideIcon;
4
5#[derive(Clone, Debug)]
7pub struct CommandItem {
8 pub group: String,
9 pub group_icon: LucideIcon,
10 pub label: String,
11 pub icon: LucideIcon,
12}
13
14impl From<(String, String)> for CommandItem {
15 fn from((group, label): (String, String)) -> Self {
16 Self {
17 group,
18 group_icon: LucideIcon::Component,
19 label,
20 icon: LucideIcon::Component,
21 }
22 }
23}
24
25#[must_use]
27pub struct Command {
28 pub(crate) items: Vec<CommandItem>,
29 pub(crate) placeholder: String,
30}
31
32impl Command {
33 pub fn new(items: Vec<(String, String)>) -> Self {
35 Self {
36 items: items.into_iter().map(CommandItem::from).collect(),
37 placeholder: "Type a command or search...".to_owned(),
38 }
39 }
40
41 pub fn with_items(items: Vec<CommandItem>) -> Self {
43 Self {
44 items,
45 placeholder: "Type a command or search...".to_owned(),
46 }
47 }
48
49 pub fn placeholder(mut self, text: impl Into<String>) -> Self {
50 self.placeholder = text.into();
51 self
52 }
53}
54
55#[must_use]
58pub struct CommandValue<T: Clone> {
59 pub(crate) entries: Vec<(T, CommandItem)>,
60 pub(crate) placeholder: String,
61}
62
63impl<T: Clone> CommandValue<T> {
64 pub fn new(entries: Vec<(T, CommandItem)>) -> Self {
65 Self {
66 entries,
67 placeholder: "Type a command or search...".to_owned(),
68 }
69 }
70
71 pub fn placeholder(mut self, text: impl Into<String>) -> Self {
72 self.placeholder = text.into();
73 self
74 }
75}