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 what a block caret paints as in an inactive window.
32    fn inactive_caret(&self) -> crate::input::InactiveCaret;
33
34    /// Sets it and refreshes windows. Defaults to `Hollow`.
35    fn set_inactive_caret(&mut self, inactive: crate::input::InactiveCaret);
36
37    /// Reads scrollbar visibility.
38    fn scrollbar_visibility(&self) -> crate::scroll::Visibility;
39
40    /// Sets default scrollbar visibility and refreshes windows.
41    fn set_scrollbar_visibility(&mut self, value: crate::scroll::Visibility);
42
43    /// Reads the preset color set pickers offer.
44    fn color_swatches(&self) -> std::rc::Rc<[crate::color::Swatch]>;
45
46    /// Replaces the preset color set and refreshes windows. Defaults to
47    /// [`crate::color::default_swatches`].
48    fn set_color_swatches(&mut self, set: impl Into<std::rc::Rc<[crate::color::Swatch]>>);
49
50    /// Reads the menu indent step.
51    fn menu_indent(&self) -> crate::menu::MenuIndent;
52
53    /// Sets how far each [`crate::menu::Item::indented`] level moves a row in,
54    /// and refreshes windows. Defaults to 12px.
55    fn set_menu_indent(&mut self, indent: crate::menu::MenuIndent);
56}
57
58impl AppExt for App {
59    fn caption_style(&self) -> crate::titlebar::CaptionStyle {
60        crate::titlebar::caption_style(self)
61    }
62
63    fn set_caption_style(&mut self, style: crate::titlebar::CaptionStyle) {
64        self.set_global(style);
65        self.refresh_windows();
66    }
67
68    fn caret_blink(&self) -> bool {
69        crate::input::caret_blink(self)
70    }
71
72    fn set_caret_blink(&mut self, blink: bool) {
73        crate::input::set_caret_blink(blink, self)
74    }
75
76    fn caret_shape(&self) -> crate::input::CaretShape {
77        crate::input::caret::caret_shape(self)
78    }
79
80    fn set_caret_shape(&mut self, shape: crate::input::CaretShape) {
81        crate::input::caret::set_caret_shape(shape, self)
82    }
83
84    fn caret_height(&self) -> crate::input::CaretHeight {
85        crate::input::caret::caret_height(self)
86    }
87
88    fn set_caret_height(&mut self, height: crate::input::CaretHeight) {
89        crate::input::caret::set_caret_height(height, self)
90    }
91
92    fn inactive_caret(&self) -> crate::input::InactiveCaret {
93        crate::input::caret::inactive_caret(self)
94    }
95
96    fn set_inactive_caret(&mut self, inactive: crate::input::InactiveCaret) {
97        crate::input::caret::set_inactive_caret(inactive, self)
98    }
99
100    fn scrollbar_visibility(&self) -> crate::scroll::Visibility {
101        crate::scroll::overlay::visibility(self)
102    }
103
104    fn set_scrollbar_visibility(&mut self, value: crate::scroll::Visibility) {
105        crate::scroll::overlay::set_visibility(value, self)
106    }
107
108    fn color_swatches(&self) -> std::rc::Rc<[crate::color::Swatch]> {
109        crate::color::swatches(self)
110    }
111
112    fn set_color_swatches(&mut self, set: impl Into<std::rc::Rc<[crate::color::Swatch]>>) {
113        crate::color::set_swatches(set, self)
114    }
115
116    fn menu_indent(&self) -> crate::menu::MenuIndent {
117        crate::menu::indent(self)
118    }
119
120    fn set_menu_indent(&mut self, indent: crate::menu::MenuIndent) {
121        crate::menu::set_indent(indent, self)
122    }
123}