doc: Add hello world example to README. (#1369)
This commit is contained in:
parent
47978bc50e
commit
1bcf5ac1b0
1 changed files with 46 additions and 0 deletions
46
README.md
46
README.md
|
|
@ -35,6 +35,52 @@ gpui = "0.2.0"
|
|||
gpui-component = "0.2.0"
|
||||
```
|
||||
|
||||
### Basic Example
|
||||
|
||||
```rs
|
||||
use gpui::*;
|
||||
use gpui_component::{button::*, *};
|
||||
|
||||
pub struct HelloWorld;
|
||||
impl Render for HelloWorld {
|
||||
fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
|
||||
div()
|
||||
.v_flex()
|
||||
.gap_2()
|
||||
.size_full()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.child("Hello, World!")
|
||||
.child(
|
||||
Button::new("ok")
|
||||
.primary()
|
||||
.label("Let's Go!")
|
||||
.on_click(|_, _, _| println!("Clicked!")),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let app = Application::new();
|
||||
|
||||
app.run(move |cx| {
|
||||
// This must be called before using any GPUI Component features.
|
||||
gpui_component::init(cx);
|
||||
|
||||
cx.spawn(async move |cx| {
|
||||
cx.open_window(WindowOptions::default(), |window, cx| {
|
||||
let view = cx.new(|_| HelloWorld);
|
||||
// This first level on the window, should be a Root.
|
||||
cx.new(|cx| Root::new(view.into(), window, cx))
|
||||
})?;
|
||||
|
||||
Ok::<_, anyhow::Error>(())
|
||||
})
|
||||
.detach();
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
### WebView
|
||||
|
||||
> Still early and experimental; there are a lot of limitations.
|
||||
|
|
|
|||
Loading…
Reference in a new issue