Skip to main content

gpui_kit/foundation/
mod.rs

1//! The contracts every component in this library implements.
2//!
3//! Components are `RenderOnce` builders. They read the active theme from the
4//! application context instead of accepting a `&Theme` argument, and they
5//! derive both their GPUI element id and their semantic assertion id from a
6//! single caller-supplied [`Ident`].
7
8pub mod direction;
9mod ident;
10mod interaction;
11pub(crate) mod stepping;
12mod styled_ext;
13
14pub use direction::{
15    ActiveDirection, DirectionalExt, LayoutDirection, LogicalSide, PhysicalSide,
16    set_layout_direction,
17};
18pub use ident::Ident;
19pub use interaction::{HoverLift, Pressable};
20pub use styled_ext::{FocusRing, StyledExt, text};
21
22pub use gpui_kit_theme::{
23    ActiveTheme, ControlSize, Density, Elevation, Layer, ThemeRegistry, activate_theme, set_density,
24};
25
26/// A control that can refuse interaction.
27///
28/// Implementations must not install action handlers while disabled, so a
29/// disabled control cannot fire even if a host mis-routes an event.
30pub trait Disableable {
31    fn disabled(self, disabled: bool) -> Self;
32}
33
34/// A control that can present itself as the current choice.
35pub trait Selectable {
36    fn selected(self, selected: bool) -> Self;
37}
38
39/// A control that resolves its metrics from the token control scale.
40pub trait Sizable: Sized {
41    fn control_size(self, size: ControlSize) -> Self;
42
43    fn xs(self) -> Self {
44        self.control_size(ControlSize::Xs)
45    }
46
47    fn small(self) -> Self {
48        self.control_size(ControlSize::Sm)
49    }
50
51    fn medium(self) -> Self {
52        self.control_size(ControlSize::Md)
53    }
54
55    fn large(self) -> Self {
56        self.control_size(ControlSize::Lg)
57    }
58}