gpui-component/crates/story/src/welcome_story.rs
Jason Lee 5e504d10bb
chore: Refactor tab key to switch focus. (#991)
Wait https://github.com/zed-industries/zed/pull/33008,
https://github.com/zed-industries/zed/pull/34804 to merge.


https://github.com/user-attachments/assets/3c21ebc9-44a0-4311-bb0f-5f63fe8d4bb3

- Improved `focus_ring` to render like an outline.
- Added to support press `Enter`, `Space` key to trigger Checkbox,
Button, Radio.

## Break Changes

- The `FocusableExt` has been changed to only for crate internal.
- The `FocusableCycle` has been removed, now GPUI has it own tab stop
implementation.
2025-09-29 16:48:24 +08:00

60 lines
1.4 KiB
Rust

use gpui::{
App, AppContext, Context, Entity, FocusHandle, Focusable, ParentElement, Render, Styled, Window,
};
use gpui_component::{dock::PanelControl, text::TextView, v_flex};
use crate::Story;
pub struct WelcomeStory {
focus_handle: FocusHandle,
}
impl WelcomeStory {
pub fn view(window: &mut Window, cx: &mut App) -> Entity<Self> {
cx.new(|cx| Self::new(window, cx))
}
fn new(_: &mut Window, cx: &mut Context<Self>) -> Self {
Self {
focus_handle: cx.focus_handle(),
}
}
}
impl Story for WelcomeStory {
fn title() -> &'static str {
"Introduction"
}
fn description() -> &'static str {
"UI components for building fantastic desktop application by using GPUI."
}
fn new_view(window: &mut Window, cx: &mut App) -> Entity<impl Render> {
Self::view(window, cx)
}
fn zoomable() -> Option<PanelControl> {
None
}
}
impl Focusable for WelcomeStory {
fn focus_handle(&self, _: &gpui::App) -> gpui::FocusHandle {
self.focus_handle.clone()
}
}
impl Render for WelcomeStory {
fn render(
&mut self,
window: &mut gpui::Window,
cx: &mut gpui::Context<Self>,
) -> impl gpui::IntoElement {
v_flex().p_4().gap_5().child(
TextView::markdown("intro", include_str!("../../../README.md"), window, cx)
.selectable(),
)
}
}