Skip to main content

gpui_base/grid_layout/
mod.rs

1//! A grid whose items the user drags and resizes into place.
2//!
3//! [`GridLayoutState`] owns the layout — one [`GridArea`] per item, in grid
4//! cells — and the rules it settles under; [`GridLayout`] places each
5//! [`GridItem`] in its area and turns pointer and keyboard input into layout
6//! changes. The pure layout arithmetic lives in `layout`, apart from pixels
7//! and entities.
8
9mod grid_layout;
10mod layout;
11mod state;
12
13pub use grid_layout::{GridItem, GridLayout, grid_drag_handle};
14pub use layout::GridArea;
15pub use state::{GridLayoutEvent, GridLayoutState};
16
17use gpui::{App, KeyBinding, actions};
18
19use crate::actions::Cancel;
20
21pub(super) const CONTEXT: &str = "GridLayout";
22
23actions!(
24    grid_layout,
25    [
26        /// Move the selected item one column toward the leading edge.
27        MoveLeft,
28        /// Move the selected item one column toward the trailing edge.
29        MoveRight,
30        /// Move the selected item up one row.
31        MoveUp,
32        /// Move the selected item down one row.
33        MoveDown,
34        /// Make the selected item one column narrower.
35        ShrinkWidth,
36        /// Make the selected item one column wider.
37        GrowWidth,
38        /// Make the selected item one row shorter.
39        ShrinkHeight,
40        /// Make the selected item one row taller.
41        GrowHeight,
42        /// Select the next item in reading order.
43        SelectNextItem,
44        /// Select the previous item in reading order.
45        SelectPreviousItem,
46    ]
47);
48
49pub(crate) fn init(cx: &mut App) {
50    cx.bind_keys([
51        KeyBinding::new("left", MoveLeft, Some(CONTEXT)),
52        KeyBinding::new("right", MoveRight, Some(CONTEXT)),
53        KeyBinding::new("up", MoveUp, Some(CONTEXT)),
54        KeyBinding::new("down", MoveDown, Some(CONTEXT)),
55        KeyBinding::new("shift-left", ShrinkWidth, Some(CONTEXT)),
56        KeyBinding::new("shift-right", GrowWidth, Some(CONTEXT)),
57        KeyBinding::new("shift-up", ShrinkHeight, Some(CONTEXT)),
58        KeyBinding::new("shift-down", GrowHeight, Some(CONTEXT)),
59        KeyBinding::new("tab", SelectNextItem, Some(CONTEXT)),
60        KeyBinding::new("shift-tab", SelectPreviousItem, Some(CONTEXT)),
61        KeyBinding::new("escape", Cancel, Some(CONTEXT)),
62    ]);
63}