Skip to main content

ui/
app.rs

1//! App-owned configuration.
2
3use gpui::App;
4
5/// Configuration carried by the application. Import as `use ui::AppExt as _;`.
6pub trait AppExt {
7    /// Reads the caption button style. Defaults to `Rectangular`.
8    fn caption_style(&self) -> crate::titlebar::CaptionStyle;
9
10    /// Sets the caption button style and refreshes windows.
11    fn set_caption_style(&mut self, style: crate::titlebar::CaptionStyle);
12
13    /// Reads caret blink.
14    fn caret_blink(&self) -> bool;
15
16    /// Enables blinking or holds carets solid, then refreshes windows.
17    fn set_caret_blink(&mut self, blink: bool);
18
19    /// Reads caret shape.
20    fn caret_shape(&self) -> crate::input::CaretShape;
21
22    /// Sets text caret shape and refreshes windows. Defaults to `Bar`.
23    fn set_caret_shape(&mut self, shape: crate::input::CaretShape);
24
25    /// Reads block caret height.
26    fn caret_height(&self) -> crate::input::CaretHeight;
27
28    /// Sets block caret height and refreshes windows. Defaults to `Line`.
29    fn set_caret_height(&mut self, height: crate::input::CaretHeight);
30
31    /// Reads scrollbar visibility.
32    fn scrollbar_visibility(&self) -> crate::scroll::Visibility;
33
34    /// Sets default scrollbar visibility and refreshes windows.
35    fn set_scrollbar_visibility(&mut self, value: crate::scroll::Visibility);
36
37    /// Reads the preset color set pickers offer.
38    fn color_swatches(&self) -> std::rc::Rc<[crate::color::Swatch]>;
39
40    /// Replaces the preset color set and refreshes windows. Defaults to
41    /// [`crate::color::default_swatches`].
42    fn set_color_swatches(&mut self, set: impl Into<std::rc::Rc<[crate::color::Swatch]>>);
43
44    /// Reads the menu indent step.
45    fn menu_indent(&self) -> crate::menu::MenuIndent;
46
47    /// Sets how far each [`crate::menu::Item::indented`] level moves a row in,
48    /// and refreshes windows. Defaults to 12px.
49    fn set_menu_indent(&mut self, indent: crate::menu::MenuIndent);
50}
51
52impl AppExt for App {
53    fn caption_style(&self) -> crate::titlebar::CaptionStyle {
54        crate::titlebar::caption_style(self)
55    }
56
57    fn set_caption_style(&mut self, style: crate::titlebar::CaptionStyle) {
58        self.set_global(style);
59        self.refresh_windows();
60    }
61
62    fn caret_blink(&self) -> bool {
63        crate::input::caret_blink(self)
64    }
65
66    fn set_caret_blink(&mut self, blink: bool) {
67        crate::input::set_caret_blink(blink, self)
68    }
69
70    fn caret_shape(&self) -> crate::input::CaretShape {
71        crate::input::caret::caret_shape(self)
72    }
73
74    fn set_caret_shape(&mut self, shape: crate::input::CaretShape) {
75        crate::input::caret::set_caret_shape(shape, self)
76    }
77
78    fn caret_height(&self) -> crate::input::CaretHeight {
79        crate::input::caret::caret_height(self)
80    }
81
82    fn set_caret_height(&mut self, height: crate::input::CaretHeight) {
83        crate::input::caret::set_caret_height(height, self)
84    }
85
86    fn scrollbar_visibility(&self) -> crate::scroll::Visibility {
87        crate::scroll::overlay::visibility(self)
88    }
89
90    fn set_scrollbar_visibility(&mut self, value: crate::scroll::Visibility) {
91        crate::scroll::overlay::set_visibility(value, self)
92    }
93
94    fn color_swatches(&self) -> std::rc::Rc<[crate::color::Swatch]> {
95        crate::color::swatches(self)
96    }
97
98    fn set_color_swatches(&mut self, set: impl Into<std::rc::Rc<[crate::color::Swatch]>>) {
99        crate::color::set_swatches(set, self)
100    }
101
102    fn menu_indent(&self) -> crate::menu::MenuIndent {
103        crate::menu::indent(self)
104    }
105
106    fn set_menu_indent(&mut self, indent: crate::menu::MenuIndent) {
107        crate::menu::set_indent(indent, self)
108    }
109}