hold_for_default.rs

 1use gpui::{App, IntoElement, Modifiers, RenderOnce, Window};
 2use ui::{prelude::*, render_modifiers};
 3
 4#[derive(IntoElement)]
 5pub struct HoldForDefault {
 6    is_default: bool,
 7    more_content: bool,
 8}
 9
10impl HoldForDefault {
11    pub fn new(is_default: bool) -> Self {
12        Self {
13            is_default,
14            more_content: true,
15        }
16    }
17
18    #[allow(dead_code)]
19    pub fn more_content(mut self, more_content: bool) -> Self {
20        self.more_content = more_content;
21        self
22    }
23}
24
25impl RenderOnce for HoldForDefault {
26    fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
27        h_flex()
28            .when(self.more_content, |this| {
29                this.pt_1()
30                    .border_t_1()
31                    .border_color(cx.theme().colors().border_variant)
32            })
33            .gap_0p5()
34            .text_sm()
35            .text_color(Color::Muted.color(cx))
36            .child("Hold")
37            .child(h_flex().flex_shrink_0().children(render_modifiers(
38                &Modifiers::secondary_key(),
39                PlatformStyle::platform(),
40                None,
41                Some(TextSize::Default.rems(cx).into()),
42                false,
43            )))
44            .child(div().map(|this| {
45                if self.is_default {
46                    this.child("to unset as default")
47                } else {
48                    this.child("to set as default")
49                }
50            }))
51    }
52}