Re-re-fork (#23)

This commit is contained in:
Miles Wirht
2026-03-22 12:21:07 -04:00
committed by GitHub
parent 18aeb44a54
commit de080b0773
246 changed files with 34208 additions and 11176 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
use gpui::{
App, Application, Bounds, BoxShadow, Context, Div, SharedString, Window, WindowBounds,
WindowOptions, div, hsla, point, prelude::*, px, relative, rgb, size,
WindowOptions, current_platform, div, hsla, point, prelude::*, px, relative, rgb, size,
};
struct Shadow {}
@@ -569,7 +569,7 @@ impl Render for Shadow {
}
fn main() {
Application::new().run(|cx: &mut App| {
Application::with_platform(current_platform(false)).run(|cx: &mut App| {
let bounds = Bounds::centered(None, size(px(1000.0), px(800.0)), cx);
cx.open_window(
WindowOptions {
+13 -12
View File
@@ -13,10 +13,11 @@ mod example_prelude;
use std::time::Duration;
use anyhow::Result;
use gpui::colors::Colors;
use gpui::{
Animation, AnimationExt as _, App, Application, AssetSource, Bounds, Colors, Context, Hsla,
Animation, AnimationExt as _, App, Application, AssetSource, Bounds, Context, Hsla,
SharedString, Transformation, Window, WindowBounds, WindowOptions, bounce, div, ease_in_out,
linear, percentage, prelude::*, px, size as gpui_size, svg,
linear, percentage, prelude::*, px, rgb, size as gpui_size, svg,
};
struct Assets {}
@@ -78,7 +79,7 @@ impl Render for AnimationExample {
.child(
div()
.text_sm()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.child("Animations, easing, and transformations in GPUI"),
),
)
@@ -99,8 +100,8 @@ impl Render for AnimationExample {
}
fn rotation_example(colors: &Colors) -> impl IntoElement {
let text_muted = colors.text_muted;
let accent = colors.accent;
let text_muted = colors.disabled;
let accent = colors.selected;
div()
.flex()
@@ -133,8 +134,8 @@ fn rotation_example(colors: &Colors) -> impl IntoElement {
}
fn bounce_example(colors: &Colors) -> impl IntoElement {
let text_muted = colors.text_muted;
let success = colors.success;
let text_muted = colors.disabled;
let success = rgb(0x388e3c);
div()
.flex()
@@ -167,8 +168,8 @@ fn bounce_example(colors: &Colors) -> impl IntoElement {
}
fn scale_example(colors: &Colors) -> impl IntoElement {
let text_muted = colors.text_muted;
let warning = colors.warning;
let text_muted = colors.disabled;
let warning = rgb(0xf9a825);
div()
.flex()
@@ -202,8 +203,8 @@ fn scale_example(colors: &Colors) -> impl IntoElement {
}
fn combined_example(colors: &Colors) -> impl IntoElement {
let text_muted = colors.text_muted;
let error = colors.error;
let text_muted = colors.disabled;
let error = rgb(0xd32f2f);
div()
.flex()
@@ -240,7 +241,7 @@ fn combined_example(colors: &Colors) -> impl IntoElement {
}
fn section(colors: &Colors, title: &'static str, content: impl IntoElement) -> impl IntoElement {
let surface: Hsla = colors.surface.into();
let surface: Hsla = colors.container.into();
div()
.flex()
+16 -15
View File
@@ -12,9 +12,10 @@ mod example_prelude;
use std::time::Duration;
use gpui::colors::Colors;
use gpui::{
App, Application, Bounds, Colors, Context, Entity, Render, Task, Window, WindowBounds,
WindowOptions, div, prelude::*, px, size,
App, Application, Bounds, Context, Entity, Render, Task, Window, WindowBounds, WindowOptions,
div, prelude::*, px, rgb, size,
};
// Example 1: Simple Foreground Task
@@ -272,7 +273,7 @@ impl Render for AsyncTasksExample {
.child(
div()
.text_sm()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.child("Spawning, background work, and task management"),
),
)
@@ -348,9 +349,9 @@ impl Render for AsyncTasksExample {
.child({
let is_running = cancellable.is_running();
let (bg, bg_hover) = if is_running {
(colors.error, colors.error_hover)
(rgb(0xd32f2f), rgb(0xe04545))
} else {
(colors.success, colors.success_hover)
(rgb(0x388e3c), rgb(0x43a047))
};
div()
.id("cancel-btn")
@@ -381,7 +382,7 @@ impl Render for AsyncTasksExample {
.child(
div()
.text_sm()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.child(format!("Numbers: {:?}", return_demo.numbers)),
)
.child(
@@ -446,7 +447,7 @@ fn demo_section(
.gap_3()
.p_4()
.rounded_lg()
.bg(colors.surface)
.bg(colors.container)
.border_1()
.border_color(colors.border)
.child(
@@ -464,7 +465,7 @@ fn demo_section(
.child(
div()
.text_xs()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.child(description),
),
)
@@ -477,10 +478,10 @@ fn button(
label: &'static str,
disabled: bool,
) -> gpui::Stateful<gpui::Div> {
let disabled_bg = colors.surface_hover;
let bg = colors.accent;
let bg_hover = colors.accent_hover;
let bg_active = colors.accent_active;
let disabled_bg = colors.selected;
let bg = colors.selected;
let bg_hover = colors.selected;
let bg_active = colors.selected;
let text = colors.selected_text;
div()
@@ -507,7 +508,7 @@ fn secondary_button(
id: impl Into<gpui::ElementId>,
label: &'static str,
) -> gpui::Stateful<gpui::Div> {
let bg = colors.surface_hover;
let bg = colors.selected;
let bg_hover = colors.border;
let text = colors.text;
@@ -526,8 +527,8 @@ fn secondary_button(
fn progress_bar(colors: &Colors, progress: u32) -> impl IntoElement {
let clamped = progress.min(100);
let bar_bg = colors.surface_hover;
let bar_fill = colors.success;
let bar_bg = colors.selected;
let bar_fill = rgb(0x388e3c);
div()
.h_2()
+22 -21
View File
@@ -11,9 +11,10 @@
mod example_prelude;
use example_prelude::init_example;
use gpui::colors::Colors;
use gpui::{
App, Application, Bounds, Colors, Context, Entity, IntoElement, Render, RenderOnce, Window,
WindowBounds, WindowOptions, div, prelude::*, px, size,
App, Application, Bounds, Context, Entity, IntoElement, Render, RenderOnce, Window,
WindowBounds, WindowOptions, div, prelude::*, px, rgb, size,
};
// ============================================================================
@@ -43,10 +44,10 @@ fn use_state_counter(colors: &Colors, window: &mut Window, cx: &mut App) -> impl
let count = state.read(cx).count;
let error = colors.error;
let error_hover = colors.error_hover;
let success = colors.success;
let success_hover = colors.success_hover;
let error = rgb(0xd32f2f);
let error_hover = rgb(0xe04545);
let success = rgb(0x388e3c);
let success_hover = rgb(0x43a047);
div()
.id("use-state-counter")
@@ -55,11 +56,11 @@ fn use_state_counter(colors: &Colors, window: &mut Window, cx: &mut App) -> impl
.gap_2()
.p_4()
.rounded_lg()
.bg(colors.surface)
.bg(colors.container)
.child(
div()
.text_sm()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.child("use_state Counter"),
)
.child(
@@ -164,10 +165,10 @@ impl RenderOnceCounter {
impl RenderOnce for RenderOnceCounter {
fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
let colors = self.colors;
let error = colors.error;
let error_hover = colors.error_hover;
let success = colors.success;
let success_hover = colors.success_hover;
let error = rgb(0xd32f2f);
let error_hover = rgb(0xe04545);
let success = rgb(0x388e3c);
let success_hover = rgb(0x43a047);
div()
.id("render-once-counter")
@@ -176,11 +177,11 @@ impl RenderOnce for RenderOnceCounter {
.gap_2()
.p_4()
.rounded_lg()
.bg(colors.surface)
.bg(colors.container)
.child(
div()
.text_sm()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.child("RenderOnce Counter"),
)
.child(
@@ -269,10 +270,10 @@ impl RenderCounter {
impl Render for RenderCounter {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let colors = Colors::for_appearance(window);
let error = colors.error;
let error_hover = colors.error_hover;
let success = colors.success;
let success_hover = colors.success_hover;
let error = rgb(0xd32f2f);
let error_hover = rgb(0xe04545);
let success = rgb(0x388e3c);
let success_hover = rgb(0x43a047);
div()
.id("render-counter")
@@ -281,11 +282,11 @@ impl Render for RenderCounter {
.gap_2()
.p_4()
.rounded_lg()
.bg(colors.surface)
.bg(colors.container)
.child(
div()
.text_sm()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.child("Render Counter"),
)
.child(
@@ -380,7 +381,7 @@ impl Render for CreatingComponentsExample {
.child(
div()
.text_sm()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.child("Three approaches to stateful components in GPUI"),
),
)
+18 -17
View File
@@ -7,8 +7,9 @@
//! 3. `window.paint_*` methods - Drawing quads, paths, and more
//! 4. Interactive drawing - Responding to mouse events
use gpui::colors::Colors;
use gpui::{
App, Application, Bounds, Colors, Context, Hsla, MouseButton, MouseDownEvent, MouseMoveEvent,
App, Application, Bounds, Context, Hsla, MouseButton, MouseDownEvent, MouseMoveEvent,
MouseUpEvent, Path, PathBuilder, Pixels, Point, Render, Rgba, Window, WindowBounds,
WindowOptions, canvas, div, fill, point, prelude::*, px, rgb, size,
};
@@ -23,9 +24,9 @@ mod example_prelude;
// - paint: Called during paint to actually draw
fn basic_shapes_canvas(colors: &Colors) -> impl IntoElement {
let error = colors.error;
let success = colors.success;
let accent = colors.accent;
let error = rgb(0xd32f2f);
let success = rgb(0x388e3c);
let accent = colors.selected;
canvas(
move |_bounds, _window, _cx| {},
@@ -106,8 +107,8 @@ fn create_triangle(p1: Point<Pixels>, p2: Point<Pixels>, p3: Point<Pixels>) -> P
}
fn custom_paths_canvas(colors: &Colors) -> impl IntoElement {
let warning = colors.warning;
let accent = colors.accent;
let warning = rgb(0xf9a825);
let accent = colors.selected;
canvas(
move |_bounds, _window, _cx| {},
@@ -169,10 +170,10 @@ impl DrawingCanvas {
fn get_colors(colors: &Colors) -> Vec<Rgba> {
vec![
colors.error,
colors.success,
colors.accent,
colors.warning,
rgb(0xd32f2f),
rgb(0x388e3c),
colors.selected,
rgb(0xf9a825),
rgb(0x8b5cf6), // Purple
rgb(0x06b6d4), // Cyan
]
@@ -277,12 +278,12 @@ impl Render for DrawingCanvas {
let current_color = self.current_color(&colors);
let palette = Self::get_colors(&colors);
let surface = colors.surface;
let surface = colors.container;
let border = colors.border;
let error = colors.error;
let error_hover = colors.error_hover;
let error = rgb(0xd32f2f);
let error_hover = rgb(0xe04545);
let text = colors.selected_text;
let text_muted = colors.text_muted;
let text_muted = colors.disabled;
div()
.flex()
@@ -393,7 +394,7 @@ impl Render for CustomDrawingExample {
.child(
div()
.text_sm()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.child("Canvas element, paths, and interactive painting"),
),
)
@@ -429,7 +430,7 @@ fn section(
content: impl IntoElement,
height: Pixels,
) -> impl IntoElement {
let surface: Hsla = colors.surface.into();
let surface: Hsla = colors.container.into();
div()
.flex()
@@ -455,7 +456,7 @@ fn section(
.child(
div()
.text_xs()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.child(description),
),
)
+28 -27
View File
@@ -11,10 +11,11 @@
mod example_prelude;
use example_prelude::init_example;
use gpui::colors::Colors;
use gpui::{
App, Application, Bounds, ClickEvent, Colors, Context, Entity, Half, Hsla, IntoElement,
MouseButton, MouseMoveEvent, Pixels, Point, Render, Window, WindowBounds, WindowOptions, div,
prelude::*, px, size,
App, Application, Bounds, ClickEvent, Context, Entity, Half, Hsla, IntoElement, MouseButton,
MouseMoveEvent, Pixels, Point, Render, Window, WindowBounds, WindowOptions, div, prelude::*,
px, rgb, size,
};
// ============================================================================
@@ -50,7 +51,7 @@ impl Render for ClickDemo {
.gap_3()
.p_4()
.rounded_lg()
.bg(colors.surface)
.bg(colors.container)
.child(
div()
.text_sm()
@@ -61,7 +62,7 @@ impl Render for ClickDemo {
.child(
div()
.text_xs()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.child("Single click, double click, or triple click the button"),
)
.child(
@@ -70,12 +71,12 @@ impl Render for ClickDemo {
.px_4()
.py_2()
.rounded_md()
.bg(colors.accent)
.bg(colors.selected)
.text_color(colors.selected_text)
.text_sm()
.cursor_pointer()
.hover(|style| style.bg(colors.accent_hover))
.active(|style| style.bg(colors.accent_active))
.hover(|style| style.bg(colors.selected))
.active(|style| style.bg(colors.selected))
.child("Click Me!")
// on_click receives a ClickEvent with click_count() method
.on_click(cx.listener(|this, event: &ClickEvent, _window, cx| {
@@ -98,13 +99,13 @@ impl Render for ClickDemo {
.child(
div()
.text_xs()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.child(format!("Total clicks: {}", self.click_count)),
)
.child(
div()
.text_xs()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.child(format!("Last: {}", self.last_click_type)),
),
)
@@ -144,7 +145,7 @@ impl Render for HoverDemo {
.gap_3()
.p_4()
.rounded_lg()
.bg(colors.surface)
.bg(colors.container)
.child(
div()
.text_sm()
@@ -155,7 +156,7 @@ impl Render for HoverDemo {
.child(
div()
.text_xs()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.child("Move your mouse in and out of the target"),
)
.child(
@@ -166,14 +167,14 @@ impl Render for HoverDemo {
.rounded_md()
.border_2()
.border_color(if is_hovered {
colors.accent
colors.selected
} else {
colors.border
})
.bg(if is_hovered {
colors.accent_hover
colors.selected
} else {
colors.surface_hover
colors.selected
})
.text_color(if is_hovered {
colors.selected_text
@@ -199,7 +200,7 @@ impl Render for HoverDemo {
.child(
div()
.text_xs()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.mt_2()
.child(format!("Times hovered: {}", self.hover_count)),
)
@@ -253,7 +254,7 @@ impl Render for MouseEventsDemo {
.gap_3()
.p_4()
.rounded_lg()
.bg(colors.surface)
.bg(colors.container)
.child(
div()
.text_sm()
@@ -264,7 +265,7 @@ impl Render for MouseEventsDemo {
.child(
div()
.text_xs()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.child("Move and click within the target area"),
)
.child(
@@ -274,14 +275,14 @@ impl Render for MouseEventsDemo {
.rounded_md()
.border_2()
.border_color(if is_pressed {
colors.accent
colors.selected
} else {
colors.border
})
.bg(if is_pressed {
colors.accent_hover
colors.selected
} else {
colors.surface_hover
colors.selected
})
.flex()
.items_center()
@@ -317,7 +318,7 @@ impl Render for MouseEventsDemo {
.gap_0p5()
.mt_2()
.text_xs()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.children(
self.event_log
.iter()
@@ -396,7 +397,7 @@ impl DragDropDemo {
impl Render for DragDropDemo {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let colors = Colors::for_appearance(window);
let item_colors = [colors.error, colors.success, colors.warning];
let item_colors = [rgb(0xd32f2f), rgb(0x388e3c), rgb(0xf9a825)];
div()
.flex()
@@ -404,7 +405,7 @@ impl Render for DragDropDemo {
.gap_3()
.p_4()
.rounded_lg()
.bg(colors.surface)
.bg(colors.container)
.child(
div()
.text_sm()
@@ -415,7 +416,7 @@ impl Render for DragDropDemo {
.child(
div()
.text_xs()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.child("Drag items to the drop zone below"),
)
.child(
@@ -464,7 +465,7 @@ impl Render for DragDropDemo {
.items_center()
.justify_center()
.text_xs()
.text_color(colors.text_muted)
.text_color(colors.disabled)
// on_drop receives the drag data when an item is dropped
.on_drop(cx.listener(|this, data: &DragData, _window, cx| {
this.dropped_item = Some(*data);
@@ -532,7 +533,7 @@ impl Render for InteractiveElementsExample {
.child(
div()
.text_sm()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.child("Click, hover, mouse events, and drag-and-drop in GPUI"),
),
)
+19 -18
View File
@@ -10,8 +10,9 @@
mod example_prelude;
use example_prelude::init_example;
use gpui::colors::Colors;
use gpui::{
App, Application, Bounds, Colors, Context, Div, Hsla, Render, Rgba, Window, WindowBounds,
App, Application, Bounds, Context, Div, Hsla, Render, Rgba, Window, WindowBounds,
WindowOptions, div, prelude::*, px, size,
};
@@ -34,7 +35,7 @@ fn block(label: &'static str, color: Hsla, text_color: Rgba) -> Div {
// Flexbox Examples
fn flexbox_row_example(colors: &Colors) -> impl IntoElement {
let text_muted = colors.text_muted;
let text_muted = colors.disabled;
let text = colors.selected_text;
div()
@@ -59,7 +60,7 @@ fn flexbox_row_example(colors: &Colors) -> impl IntoElement {
}
fn flexbox_column_example(colors: &Colors) -> impl IntoElement {
let text_muted = colors.text_muted;
let text_muted = colors.disabled;
let text = colors.selected_text;
div()
@@ -85,9 +86,9 @@ fn flexbox_column_example(colors: &Colors) -> impl IntoElement {
}
fn flexbox_justify_example(colors: &Colors) -> impl IntoElement {
let text_muted = colors.text_muted;
let text_muted = colors.disabled;
let text = colors.selected_text;
let surface = colors.surface;
let surface = colors.container;
div()
.flex()
@@ -136,7 +137,7 @@ fn flexbox_justify_example(colors: &Colors) -> impl IntoElement {
}
fn flexbox_grow_example(colors: &Colors) -> impl IntoElement {
let text_muted = colors.text_muted;
let text_muted = colors.disabled;
let text = colors.selected_text;
div()
@@ -162,7 +163,7 @@ fn flexbox_grow_example(colors: &Colors) -> impl IntoElement {
// Grid Examples
fn grid_basic_example(colors: &Colors) -> impl IntoElement {
let text_muted = colors.text_muted;
let text_muted = colors.disabled;
let text = colors.selected_text;
div()
@@ -190,7 +191,7 @@ fn grid_basic_example(colors: &Colors) -> impl IntoElement {
}
fn grid_span_example(colors: &Colors) -> impl IntoElement {
let text_muted = colors.text_muted;
let text_muted = colors.disabled;
let text = colors.selected_text;
div()
@@ -232,10 +233,10 @@ fn grid_span_example(colors: &Colors) -> impl IntoElement {
// Common Layout Patterns
fn app_shell_pattern(colors: &Colors) -> impl IntoElement {
let text_muted = colors.text_muted;
let text_muted = colors.disabled;
let text = colors.text;
let surface = colors.surface;
let surface_hover = colors.surface_hover;
let surface = colors.container;
let surface_hover = colors.selected;
let background = colors.background;
let border = colors.border;
@@ -300,10 +301,10 @@ fn app_shell_pattern(colors: &Colors) -> impl IntoElement {
}
fn centered_pattern(colors: &Colors) -> impl IntoElement {
let text_muted = colors.text_muted;
let text_muted = colors.disabled;
let text = colors.selected_text;
let surface = colors.surface;
let accent = colors.accent;
let surface = colors.container;
let accent = colors.selected;
div()
.flex()
@@ -337,8 +338,8 @@ fn centered_pattern(colors: &Colors) -> impl IntoElement {
}
fn stack_pattern(colors: &Colors) -> impl IntoElement {
let text_muted = colors.text_muted;
let surface = colors.surface;
let text_muted = colors.disabled;
let surface = colors.container;
div()
.flex()
@@ -421,7 +422,7 @@ impl Render for LayoutExample {
.child(
div()
.text_sm()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.child("Flexbox, Grid, and common layout patterns in GPUI"),
),
)
@@ -463,7 +464,7 @@ impl Render for LayoutExample {
}
fn section(colors: &Colors, title: &'static str, content: impl IntoElement) -> impl IntoElement {
let surface: Hsla = colors.surface.into();
let surface: Hsla = colors.container.into();
div()
.flex()
+40 -38
View File
@@ -6,9 +6,10 @@
//! 2. Conditional styling - when, when_some, map
//! 3. Theming patterns - using Colors for consistent styling
use gpui::colors::Colors;
use gpui::{
App, Application, Bounds, Colors, Context, FocusHandle, Hsla, KeyBinding, Menu, MenuItem,
Render, Rgba, Window, WindowBounds, WindowOptions, actions, div, prelude::*, px, rgb, size,
App, Application, Bounds, Context, FocusHandle, Hsla, KeyBinding, Menu, MenuItem, Render, Rgba,
Window, WindowBounds, WindowOptions, actions, div, prelude::*, px, rgb, size,
};
actions!(styling_example, [Quit, Tab, TabPrev]);
@@ -20,9 +21,9 @@ fn interactive_button(
label: &'static str,
colors: &Colors,
) -> impl IntoElement {
let accent = colors.accent;
let accent_hover = colors.accent_hover;
let accent_active = colors.accent_active;
let accent = colors.selected;
let accent_hover = colors.selected;
let accent_active = colors.selected;
let text = colors.selected_text;
div()
@@ -45,10 +46,10 @@ fn focus_button(
focus_handle: &FocusHandle,
colors: &Colors,
) -> impl IntoElement {
let surface = colors.surface;
let surface_hover = colors.surface_hover;
let surface = colors.container;
let surface_hover = colors.selected;
let text = colors.text;
let accent = colors.accent;
let accent = colors.selected;
let focus_ring: Rgba = rgb(0x60a5fa);
div()
@@ -77,7 +78,7 @@ fn interactive_states_section(colors: &Colors) -> impl IntoElement {
.child(
div()
.text_xs()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.child("hover() / active() - Mouse interaction states"),
)
.child(
@@ -93,10 +94,10 @@ fn interactive_states_section(colors: &Colors) -> impl IntoElement {
fn status_badge(status: &'static str, variant: StatusVariant, colors: &Colors) -> impl IntoElement {
let (bg, text): (Rgba, Rgba) = match variant {
StatusVariant::Success => (colors.success, colors.selected_text),
StatusVariant::Warning => (colors.warning, rgb(0x000000)),
StatusVariant::Error => (colors.error, colors.selected_text),
StatusVariant::Neutral => (colors.surface, colors.text),
StatusVariant::Success => (rgb(0x388e3c), colors.selected_text),
StatusVariant::Warning => (rgb(0xf9a825), rgb(0x000000)),
StatusVariant::Error => (rgb(0xd32f2f), colors.selected_text),
StatusVariant::Neutral => (colors.container, colors.text),
};
div()
@@ -124,11 +125,11 @@ fn list_item(
is_disabled: bool,
colors: &Colors,
) -> impl IntoElement {
let surface = colors.surface;
let surface_hover = colors.surface_hover;
let surface = colors.container;
let surface_hover = colors.selected;
let text = colors.text;
let text_muted = colors.text_muted;
let accent = colors.accent;
let text_muted = colors.disabled;
let accent = colors.selected;
div()
.id(id)
@@ -167,7 +168,7 @@ fn conditional_section(colors: &Colors) -> impl IntoElement {
.child(
div()
.text_xs()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.child("when() - Apply styles conditionally"),
)
.child(
@@ -182,7 +183,7 @@ fn conditional_section(colors: &Colors) -> impl IntoElement {
.child(
div()
.text_xs()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.mt_2()
.child("Status badges with variant-based styling"),
)
@@ -205,11 +206,11 @@ fn card_with_group_hover(
description: &'static str,
colors: &Colors,
) -> impl IntoElement {
let surface = colors.surface;
let surface = colors.container;
let border = colors.border;
let accent = colors.accent;
let accent = colors.selected;
let text = colors.text;
let text_muted = colors.text_muted;
let text_muted = colors.disabled;
div()
.id(id)
@@ -259,7 +260,7 @@ fn group_hover_section(colors: &Colors) -> impl IntoElement {
.child(
div()
.text_xs()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.child("group() / group_hover() - Parent hover affects children"),
)
.child(
@@ -292,7 +293,7 @@ struct StylingExample {
impl StylingExample {
fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
let focus_handle = cx.focus_handle();
window.focus(&focus_handle);
window.focus(&focus_handle, cx);
let buttons = vec![
cx.focus_handle().tab_index(1).tab_stop(true),
@@ -306,12 +307,12 @@ impl StylingExample {
}
}
fn on_tab(&mut self, _: &Tab, window: &mut Window, _: &mut Context<Self>) {
window.focus_next();
fn on_tab(&mut self, _: &Tab, window: &mut Window, cx: &mut Context<Self>) {
window.focus_next(cx);
}
fn on_tab_prev(&mut self, _: &TabPrev, window: &mut Window, _: &mut Context<Self>) {
window.focus_prev();
fn on_tab_prev(&mut self, _: &TabPrev, window: &mut Window, cx: &mut Context<Self>) {
window.focus_prev(cx);
}
}
@@ -349,7 +350,7 @@ impl Render for StylingExample {
.child(
div()
.text_sm()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.child("Interactive states, conditional styling, and theming"),
),
)
@@ -368,7 +369,7 @@ impl Render for StylingExample {
.child(
div()
.text_xs()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.child("focus() / focus_visible() - Keyboard navigation"),
)
.child(
@@ -415,7 +416,7 @@ impl Render for StylingExample {
.child(
div()
.text_xs()
.text_color(colors.text_muted)
.text_color(colors.disabled)
.child("Using Colors::for_appearance() for consistent theming"),
)
.child(
@@ -424,11 +425,11 @@ impl Render for StylingExample {
.flex_wrap()
.gap_2()
.child(color_swatch(&colors, "background", colors.background))
.child(color_swatch(&colors, "surface", colors.surface))
.child(color_swatch(&colors, "accent", colors.accent))
.child(color_swatch(&colors, "success", colors.success))
.child(color_swatch(&colors, "warning", colors.warning))
.child(color_swatch(&colors, "error", colors.error))
.child(color_swatch(&colors, "container", colors.container))
.child(color_swatch(&colors, "selected", colors.selected))
.child(color_swatch(&colors, "success", rgb(0x388e3c)))
.child(color_swatch(&colors, "warning", rgb(0xf9a825)))
.child(color_swatch(&colors, "error", rgb(0xd32f2f)))
.child(color_swatch(&colors, "border", colors.border)),
),
)),
@@ -437,7 +438,7 @@ impl Render for StylingExample {
}
fn section(colors: &Colors, title: &'static str, content: impl IntoElement) -> impl IntoElement {
let surface: Hsla = colors.surface.into();
let surface: Hsla = colors.container.into();
let border: Hsla = colors.border.into();
div()
@@ -460,7 +461,7 @@ fn section(colors: &Colors, title: &'static str, content: impl IntoElement) -> i
}
fn color_swatch(colors: &Colors, name: &'static str, color: Rgba) -> impl IntoElement {
let text_muted = colors.text_muted;
let text_muted = colors.disabled;
div()
.flex()
@@ -490,6 +491,7 @@ fn main() {
cx.set_menus(vec![Menu {
name: "Styling".into(),
items: vec![MenuItem::action("Quit", Quit)],
disabled: false,
}]);
cx.on_window_closed(|cx| {
if cx.windows().is_empty() {
+20 -19
View File
@@ -14,15 +14,16 @@ mod example_prelude;
use example_prelude::init_example;
use gpui::{
App, Application, Bounds, Colors, Context, FontStyle, FontWeight, Hsla, Render, StyledText,
TextOverflow, Window, WindowBounds, WindowOptions, div, prelude::*, px, relative, size,
App, Application, Bounds, Context, FontStyle, FontWeight, Hsla, Render, StyledText,
TextOverflow, Window, WindowBounds, WindowOptions, colors::Colors, current_platform, div,
prelude::*, px, relative, rgb, size,
};
// Text Styling Examples
fn text_sizes_example(colors: &Colors) -> impl IntoElement {
let text = colors.text;
let text_muted = colors.text_muted;
let text_muted = colors.disabled;
div()
.flex()
@@ -50,7 +51,7 @@ fn text_sizes_example(colors: &Colors) -> impl IntoElement {
fn text_weights_example(colors: &Colors) -> impl IntoElement {
let text = colors.text;
let text_muted = colors.text_muted;
let text_muted = colors.disabled;
div()
.flex()
@@ -116,8 +117,8 @@ fn text_weights_example(colors: &Colors) -> impl IntoElement {
fn text_alignment_example(colors: &Colors) -> impl IntoElement {
let text = colors.text;
let text_muted = colors.text_muted;
let surface = colors.surface;
let text_muted = colors.disabled;
let surface = colors.container;
div()
.flex()
@@ -167,9 +168,9 @@ fn text_alignment_example(colors: &Colors) -> impl IntoElement {
fn text_decoration_example(colors: &Colors) -> impl IntoElement {
let text = colors.text;
let text_muted = colors.text_muted;
let accent = colors.accent;
let error = colors.error;
let text_muted = colors.disabled;
let accent = colors.selected;
let error = rgb(0xd32f2f);
div()
.flex()
@@ -208,8 +209,8 @@ fn text_decoration_example(colors: &Colors) -> impl IntoElement {
fn text_overflow_example(colors: &Colors) -> impl IntoElement {
let text = colors.text;
let text_muted = colors.text_muted;
let surface = colors.surface;
let text_muted = colors.disabled;
let surface = colors.container;
let border = colors.border;
let long_text = "The quick brown fox jumps over the lazy dog. This is a long sentence that will overflow its container.";
@@ -333,7 +334,7 @@ fn text_overflow_example(colors: &Colors) -> impl IntoElement {
fn styled_text_example(colors: &Colors) -> impl IntoElement {
let text = colors.text;
let text_muted = colors.text_muted;
let text_muted = colors.disabled;
div()
.flex()
@@ -358,8 +359,8 @@ fn styled_text_example(colors: &Colors) -> impl IntoElement {
fn character_grid_example(colors: &Colors) -> impl IntoElement {
let text = colors.text;
let text_muted = colors.text_muted;
let surface = colors.surface;
let text_muted = colors.disabled;
let surface = colors.container;
let border = colors.border;
let characters = [
@@ -414,8 +415,8 @@ fn character_grid_example(colors: &Colors) -> impl IntoElement {
fn line_height_example(colors: &Colors) -> impl IntoElement {
let text = colors.text;
let text_muted = colors.text_muted;
let surface = colors.surface;
let text_muted = colors.disabled;
let surface = colors.container;
div()
.flex()
@@ -500,7 +501,7 @@ impl Render for TextExample {
.child("Text & Typography"),
)
.child(
div().text_sm().text_color(colors.text_muted).child(
div().text_sm().text_color(colors.disabled).child(
"Font styling, alignment, overflow, and unicode support",
),
),
@@ -546,7 +547,7 @@ impl Render for TextExample {
}
fn section(colors: &Colors, title: &'static str, content: impl IntoElement) -> impl IntoElement {
let surface: Hsla = colors.surface.into();
let surface: Hsla = colors.container.into();
div()
.flex()
@@ -566,7 +567,7 @@ fn section(colors: &Colors, title: &'static str, content: impl IntoElement) -> i
}
fn main() {
Application::new().run(|cx: &mut App| {
Application::with_platform(current_platform(false)).run(|cx: &mut App| {
let bounds = Bounds::centered(None, size(px(650.), px(900.)), cx);
cx.open_window(
WindowOptions {
+5 -5
View File
@@ -29,7 +29,7 @@ impl Example {
];
let focus_handle = cx.focus_handle();
window.focus(&focus_handle);
window.focus(&focus_handle, cx);
Self {
focus_handle,
@@ -40,13 +40,13 @@ impl Example {
}
}
fn on_tab(&mut self, _: &Tab, window: &mut Window, _: &mut Context<Self>) {
window.focus_next();
fn on_tab(&mut self, _: &Tab, window: &mut Window, cx: &mut Context<Self>) {
window.focus_next(cx);
self.message = SharedString::from("Pressed Tab - focus-visible border should appear!");
}
fn on_tab_prev(&mut self, _: &TabPrev, window: &mut Window, _: &mut Context<Self>) {
window.focus_prev();
fn on_tab_prev(&mut self, _: &TabPrev, window: &mut Window, cx: &mut Context<Self>) {
window.focus_prev(cx);
self.message =
SharedString::from("Pressed Shift-Tab - focus-visible border should appear!");
}
+10 -3
View File
@@ -546,8 +546,15 @@ impl Element for TextElement {
window.paint_quad(selection)
}
let line = prepaint.line.take().unwrap();
line.paint(bounds.origin, window.line_height(), window, cx)
.unwrap();
line.paint(
bounds.origin,
window.line_height(),
gpui::TextAlign::Left,
None,
window,
cx,
)
.unwrap();
if focus_handle.is_focused(window)
&& let Some(cursor) = prepaint.cursor.take()
@@ -736,7 +743,7 @@ fn main() {
window
.update(cx, |view, window, cx| {
window.focus(&view.text_input.focus_handle(cx));
window.focus(&view.text_input.focus_handle(cx), cx);
cx.activate(true);
})
.unwrap();
+2 -2
View File
@@ -55,7 +55,7 @@ fn main() {
cx.activate(false);
cx.new(|cx| {
let focus_handle = cx.focus_handle();
focus_handle.focus(window);
focus_handle.focus(window, cx);
ExampleWindow { focus_handle }
})
},
@@ -72,7 +72,7 @@ fn main() {
|window, cx| {
cx.new(|cx| {
let focus_handle = cx.focus_handle();
focus_handle.focus(window);
focus_handle.focus(window, cx);
ExampleWindow { focus_handle }
})
},
+2 -2
View File
@@ -4,7 +4,7 @@ use std::path::PathBuf;
use anyhow::Result;
use gpui::{
App, Application, AssetSource, Bounds, Context, SharedString, Window, WindowBounds,
WindowOptions, div, prelude::*, px, rgb, size, svg,
WindowOptions, current_platform, div, prelude::*, px, rgb, size, svg,
};
struct Assets {
@@ -68,7 +68,7 @@ impl Render for SvgExample {
}
fn main() {
Application::new()
Application::with_platform(current_platform(false))
.with_assets(Assets {
base: PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("examples"),
})
+5 -5
View File
@@ -22,7 +22,7 @@ impl Example {
];
let focus_handle = cx.focus_handle();
window.focus(&focus_handle);
window.focus(&focus_handle, cx);
Self {
focus_handle,
@@ -31,13 +31,13 @@ impl Example {
}
}
fn on_tab(&mut self, _: &Tab, window: &mut Window, _: &mut Context<Self>) {
window.focus_next();
fn on_tab(&mut self, _: &Tab, window: &mut Window, cx: &mut Context<Self>) {
window.focus_next(cx);
self.message = SharedString::from("You have pressed `Tab`.");
}
fn on_tab_prev(&mut self, _: &TabPrev, window: &mut Window, _: &mut Context<Self>) {
window.focus_prev();
fn on_tab_prev(&mut self, _: &TabPrev, window: &mut Window, cx: &mut Context<Self>) {
window.focus_prev(cx);
self.message = SharedString::from("You have pressed `Shift-Tab`.");
}
}
+3 -3
View File
@@ -1,6 +1,6 @@
use gpui::{
App, Application, Bounds, Context, KeyBinding, PromptButton, PromptLevel, Timer, Window,
WindowBounds, WindowKind, WindowOptions, actions, div, prelude::*, px, rgb, size,
App, Application, Bounds, Context, KeyBinding, PromptButton, PromptLevel, Window, WindowBounds,
WindowKind, WindowOptions, actions, div, prelude::*, px, rgb, size,
};
struct SubWindow {
@@ -188,7 +188,7 @@ impl Render for WindowDemo {
// Restore the application after 3 seconds
window
.spawn(cx, async move |cx| {
Timer::after(std::time::Duration::from_secs(3)).await;
smol::Timer::after(std::time::Duration::from_secs(3)).await;
cx.update(|_, cx| {
cx.activate(false);
})
+1
View File
@@ -29,6 +29,7 @@ pub fn init_example(cx: &mut App, name: impl Into<SharedString>) {
cx.set_menus(vec![Menu {
name: name.into(),
items: vec![MenuItem::action("Quit", Quit)],
disabled: false,
}]);
// Quit the app when all windows are closed