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    pub fn more_content(mut self, more_content: bool) -> Self {
19        self.more_content = more_content;
20        self
21    }
22}
23
24impl RenderOnce for HoldForDefault {
25    fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
26        h_flex()
27            .when(self.more_content, |this| {
28                this.pt_1()
29                    .border_t_1()
30                    .border_color(cx.theme().colors().border_variant)
31            })
32            .gap_0p5()
33            .text_sm()
34            .text_color(Color::Muted.color(cx))
35            .child("Hold")
36            .child(h_flex().flex_shrink_0().children(render_modifiers(
37                &Modifiers::secondary_key(),
38                PlatformStyle::platform(),
39                None,
40                Some(TextSize::Default.rems(cx).into()),
41                false,
42            )))
43            .child(div().map(|this| {
44                if self.is_default {
45                    this.child("to unset as default")
46                } else {
47                    this.child("to set as default")
48                }
49            }))
50    }
51}