T01 primitives: image, divider, backdrop, focus, pressable, measure, tooltip

Ely-built primitives plus gallery demos for every chapter-one entry,
including gpui natives. The gallery now scripts real input by posting
NSEvents to its own queue and shoots each interaction in both modes.
Codex gpt-6-astra (max): three rounds; the last finding, a two-line
doc comment, was fixed after the three-review cap.
This commit is contained in:
ZacharyZhang-NY committed 2026-09-25 00:39:06 -04:00
1 parent abf4cbcfc6
commit a13343c2a5
38 files changed
+2165 -157

No files matched your search

+58
View File
@@ -0,0 +1,58 @@
use gpui::{App, IntoElement, ParentElement, RenderOnce, SharedString, Styled, Window, div};
use crate::theme::{ActiveTheme, TextSize};
/// Hairline rule, across or down.
#[derive(IntoElement)]
pub struct Divider {
vertical: bool,
label: Option<SharedString>,
}
impl Divider {
pub fn horizontal() -> Self {
Self {
vertical: false,
label: None,
}
}
pub fn vertical() -> Self {
Self {
vertical: true,
label: None,
}
}
/// Text centered on a horizontal rule.
pub fn label(mut self, label: impl Into<SharedString>) -> Self {
self.label = Some(label.into());
self
}
}
impl RenderOnce for Divider {
fn render(self, _: &mut Window, cx: &mut App) -> impl IntoElement {
let theme = cx.theme();
let line = || div().border_color(theme.colors.border);
if self.vertical {
return line().h_full().border_l_1();
}
match self.label {
None => line().w_full().border_t_1(),
Some(label) => div()
.flex()
.items_center()
.gap_3()
.w_full()
.child(line().flex_1().border_t_1())
.child(
div()
.text_size(theme.text_size(TextSize::Xs))
.text_color(theme.colors.fg_subtle)
.child(label),
)
.child(line().flex_1().border_t_1()),
}
}
}