scaffold
This commit is contained in:
@@ -0,0 +1,154 @@
|
||||
use gpui::{
|
||||
App, AppContext as _, Bounds, Context, IntoElement, ParentElement as _, Render, Styled as _,
|
||||
Window, WindowBounds, WindowOptions, div, px, size,
|
||||
};
|
||||
use gpui_native_icons::{IconAssets, IconRole, icon};
|
||||
use gpui_native_theme::Theme;
|
||||
use gpui_platform::application;
|
||||
|
||||
struct Gallery;
|
||||
|
||||
impl Render for Gallery {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let theme = Theme::global(cx);
|
||||
let colors = theme.colors;
|
||||
let variant = theme.variant;
|
||||
|
||||
let swatches: [(&str, gpui::Hsla); 18] = [
|
||||
("background", colors.background),
|
||||
("foreground", colors.foreground),
|
||||
("surface", colors.surface),
|
||||
("surface_foreground", colors.surface_foreground),
|
||||
("primary", colors.primary),
|
||||
("primary_foreground", colors.primary_foreground),
|
||||
("secondary", colors.secondary),
|
||||
("secondary_foreground", colors.secondary_foreground),
|
||||
("muted", colors.muted),
|
||||
("muted_foreground", colors.muted_foreground),
|
||||
("accent", colors.accent),
|
||||
("accent_foreground", colors.accent_foreground),
|
||||
("destructive", colors.destructive),
|
||||
("destructive_foreground", colors.destructive_foreground),
|
||||
("border", colors.border),
|
||||
("input", colors.input),
|
||||
("ring", colors.ring),
|
||||
("selection", colors.selection),
|
||||
];
|
||||
|
||||
div()
|
||||
.size_full()
|
||||
.font_family(".SystemUIFont")
|
||||
.bg(colors.background)
|
||||
.text_color(colors.foreground)
|
||||
.p_6()
|
||||
.flex()
|
||||
.flex_col()
|
||||
.gap_5()
|
||||
.child(
|
||||
div()
|
||||
.flex()
|
||||
.flex_col()
|
||||
.gap_1()
|
||||
.child(
|
||||
div()
|
||||
.text_xl()
|
||||
.font_weight(gpui::FontWeight::SEMIBOLD)
|
||||
.child("gpui-native-kit"),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.text_sm()
|
||||
.text_color(colors.muted_foreground)
|
||||
.child(format!(
|
||||
"phase A scaffold — variant: {variant:?} (system-resolved)"
|
||||
)),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.flex()
|
||||
.flex_col()
|
||||
.gap_2()
|
||||
.child(
|
||||
div()
|
||||
.text_sm()
|
||||
.font_weight(gpui::FontWeight::MEDIUM)
|
||||
.text_color(colors.muted_foreground)
|
||||
.child("color tokens"),
|
||||
)
|
||||
.child(div().flex().flex_wrap().gap_2().children(swatches.map(
|
||||
|(name, color)| {
|
||||
div()
|
||||
.flex()
|
||||
.items_center()
|
||||
.gap_2()
|
||||
.child(
|
||||
div()
|
||||
.size_6()
|
||||
.rounded_full()
|
||||
.border_1()
|
||||
.border_color(colors.border)
|
||||
.bg(color),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.text_xs()
|
||||
.text_color(colors.muted_foreground)
|
||||
.child(name),
|
||||
)
|
||||
},
|
||||
))),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.flex()
|
||||
.flex_col()
|
||||
.gap_2()
|
||||
.child(
|
||||
div()
|
||||
.text_sm()
|
||||
.font_weight(gpui::FontWeight::MEDIUM)
|
||||
.text_color(colors.muted_foreground)
|
||||
.child("icons (Lucide fallback; platform resolvers land later)"),
|
||||
)
|
||||
.child(
|
||||
div().flex().items_center().gap_4().children(
|
||||
IconRole::all()
|
||||
.iter()
|
||||
.map(|role| icon(*role).size(20.0).color(colors.foreground)),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
application().with_assets(IconAssets).run(|cx: &mut App| {
|
||||
Theme::init(cx);
|
||||
let bounds = Bounds::centered(None, size(px(720.0), px(480.0)), cx);
|
||||
if let Err(err) = cx.open_window(
|
||||
WindowOptions {
|
||||
window_bounds: Some(WindowBounds::Windowed(bounds)),
|
||||
titlebar: Some(gpui::TitlebarOptions {
|
||||
title: Some("gpui-native-kit gallery".into()),
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
|window, cx| {
|
||||
Theme::sync_from_window(window, cx);
|
||||
// Detached on purpose: the subscription lives as long as the window.
|
||||
window
|
||||
.observe_window_appearance(|window, cx| {
|
||||
Theme::sync_from_window(window, cx);
|
||||
cx.refresh_windows();
|
||||
})
|
||||
.detach();
|
||||
cx.new(|_| Gallery)
|
||||
},
|
||||
) {
|
||||
eprintln!("failed to open gallery window: {err}");
|
||||
}
|
||||
cx.activate(true);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user