editor/layout.rs
1//! How the editor lays the document out.
2//!
3//! Installed once at boot like the image store, and read at paint: where the
4//! document's text sits is the app's decision, and this crate holds only what
5//! it defaults to.
6
7use gpui::{App, Global};
8
9/// What the editor lays the document out with.
10#[derive(Clone, Copy, Debug, PartialEq)]
11pub struct Layout {
12 /// How far the document's text sits inside the editor's own box, leaving
13 /// the drag handle somewhere to be. Anything laid out above or below the
14 /// editor takes the same measure to line up with its text; under the
15 /// handle's own 18px the handle sits over the text instead of beside it.
16 pub text_inset: f32,
17}
18
19impl Layout {
20 /// How the editor lays out, or [`Layout::default`] before anything is
21 /// installed. Mirrors [`theme::Theme::of`].
22 pub fn of(cx: &App) -> Self {
23 cx.try_global::<Installed>()
24 .map_or_else(Self::default, |installed| installed.0)
25 }
26}
27
28impl Default for Layout {
29 fn default() -> Self {
30 Self { text_inset: 22.0 }
31 }
32}
33
34struct Installed(Layout);
35
36impl Global for Installed {}
37
38/// `editor::set_layout(cx, my_layout)` — call once at boot.
39pub fn set_layout(cx: &mut App, layout: Layout) {
40 cx.set_global(Installed(layout));
41}