gpui-component/crates/story/src/welcome_story.rs
Jason Lee 74b3aa7e67
text_view: Add to support selection. (#1169)
### Links

Maybe we can do it in TextLayout in GPUI:


fda6eda3c2/crates/gpui/src/elements/text.rs (L309)

## Demo


https://github.com/user-attachments/assets/abbebee7-df8f-4067-86a7-15bc1a4c44cd

## Todo

- [x] Test for HTML View.
- [x] CodeBlock selection support.
- [x] Selection lines sometimes incorrect.
- [x] Listener Bounds changed to unselect.
2025-08-28 18:09:30 +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 + Focusable> {
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(),
)
}
}