1use crate::prelude::*;
2
3/// !!don't use this yet – it's not functional!!
4///
5/// pub crate until this is functional
6///
7/// just a placeholder for now for filling out the settings menu stories.
8#[derive(Debug, Clone, IntoElement)]
9pub(crate) struct DropdownMenu {
10 pub id: ElementId,
11 current_item: Option<SharedString>,
12 // items: Vec<SharedString>,
13 full_width: bool,
14 disabled: bool,
15}
16
17impl DropdownMenu {
18 pub fn new(id: impl Into<ElementId>, _cx: &WindowContext) -> Self {
19 Self {
20 id: id.into(),
21 current_item: None,
22 // items: Vec::new(),
23 full_width: false,
24 disabled: false,
25 }
26 }
27
28 pub fn current_item(mut self, current_item: Option<SharedString>) -> Self {
29 self.current_item = current_item;
30 self
31 }
32
33 pub fn full_width(mut self, full_width: bool) -> Self {
34 self.full_width = full_width;
35 self
36 }
37
38 pub fn disabled(mut self, disabled: bool) -> Self {
39 self.disabled = disabled;
40 self
41 }
42}
43
44impl RenderOnce for DropdownMenu {
45 fn render(self, cx: &mut WindowContext) -> impl IntoElement {
46 let disabled = self.disabled;
47
48 h_flex()
49 .id(self.id)
50 .justify_between()
51 .rounded_md()
52 .bg(cx.theme().colors().editor_background)
53 .pl_2()
54 .pr_1p5()
55 .py_0p5()
56 .gap_2()
57 .min_w_20()
58 .when_else(
59 self.full_width,
60 |full_width| full_width.w_full(),
61 |auto_width| auto_width.flex_none().w_auto(),
62 )
63 .when_else(
64 disabled,
65 |disabled| disabled.cursor_not_allowed(),
66 |enabled| enabled.cursor_pointer(),
67 )
68 .child(
69 Label::new(self.current_item.unwrap_or("".into())).color(if disabled {
70 Color::Disabled
71 } else {
72 Color::Default
73 }),
74 )
75 .child(
76 Icon::new(IconName::ChevronUpDown)
77 .size(IconSize::XSmall)
78 .color(if disabled {
79 Color::Disabled
80 } else {
81 Color::Muted
82 }),
83 )
84 }
85}