gpui-component/crates/story/examples/switch.rs
Jason Lee 8fa210bc21
text_view: Update Switch, Checkbox, Radio to let label method support TextView. (#649)
- Add `style` method to TextView.
- Add `inline` method to TextView to use default inline style.
2025-02-24 15:49:54 +08:00

35 lines
800 B
Rust

use gpui::*;
use story::{Assets, SwitchStory};
pub struct Example {
story: Entity<SwitchStory>,
}
impl Example {
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
let story = SwitchStory::view(window, cx);
Self { story }
}
fn view(window: &mut Window, cx: &mut App) -> Entity<Self> {
cx.new(|cx| Self::new(window, cx))
}
}
impl Render for Example {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
div().p_4().size_full().child(self.story.clone())
}
}
fn main() {
let app = Application::new().with_assets(Assets);
app.run(move |cx| {
story::init(cx);
cx.activate(true);
story::create_new_window("Switch Example", Example::view, cx);
});
}