docs: update local examples and docs to support new syntaxes

This commit is contained in:
Jonathan Kelley committed 2021-12-15 15:56:53 -05:00
1 parent e495b09bf1
commit 4de16c4779
118 files changed
+520 -1154

No files matched your search

+9 -9
View File
@@ -4,11 +4,11 @@ This crate provides an ergonomic API for Dioxus to build desktop apps.
```rust
fn main() {
dioxus::desktop::launch(App, |c| c)
dioxus::desktop::launch(App)
}
static App: FC<()> = |cx, props| {
let (count, set_count) = use_state(cx, || 0);
static App: Component<()> = |cx| {
let (count, set_count) = use_state(&cx, || 0);
cx.render(rsx!(
WebviewWindow {
@@ -34,7 +34,7 @@ Window management, system trays, notifications, and other desktop-related functi
Managing windows is done by simply rendering content into a `WebviewWindow` component.
```rust
static App: FC<()> = |cx, props| {
static App: Component<()> = |cx| {
rsx!(cx, WebviewWindow { "hello world" } )
}
```
@@ -46,7 +46,7 @@ Notifications also use a declarative approach. Sending a notification has never
The api has been somewhat modeled after https://github.com/mikaelbr/node-notifier
```rust
static Notifications: FC<()> = |cx, props| {
static Notifications: Component<()> = |cx| {
cx.render(rsx!(
Notification {
title: "title"
@@ -78,7 +78,7 @@ static Notifications: FC<()> = |cx, props| {
Dioxus Desktop supports app trays, which can be built with native menu groups or with a custom window.
```rust
static Tray: FC<()> = |cx, props| {
static Tray: Component<()> = |cx| {
cx.render(rsx!(
GlobalTray {
MenuGroup {
@@ -90,7 +90,7 @@ static Tray: FC<()> = |cx, props| {
};
// using a builder
static Tray: FC<()> = |cx, props| {
static Tray: Component<()> = |cx| {
let menu = MenuGroup::builder(cx)
.with_items([
MenuGroupItem::builder()
@@ -107,7 +107,7 @@ static Tray: FC<()> = |cx, props| {
}
// or with a custom window
static Tray: FC<()> = |cx, props| {
static Tray: Component<()> = |cx| {
rsx!(cx, GlobalTray { div { "custom buttons here" } })
};
```
@@ -116,7 +116,7 @@ static Tray: FC<()> = |cx, props| {
Declaring menus is convenient and cross-platform.
```rust
static Menu: FC<()> = |cx, props| {
static Menu: Component<()> = |cx| {
cx.render(rsx!(
MenuBarMajorItem { title: "File"
MenuGroup {
+3 -3
View File
@@ -12,11 +12,11 @@ use dioxus_html as dioxus_elements;
fn main() {
simple_logger::init().unwrap();
dioxus_desktop::launch(App, |c| c);
dioxus_desktop::launch(app);
}
static App: Component<()> = |cx, props| {
let mut count = use_state(cx, || 0);
fn app(cx: Scope<()>) -> Element {
let mut count = use_state(&cx, || 0);
log::debug!("count is {:?}", count);
cx.push_task(|| async move {
+1 -1
View File
@@ -90,7 +90,7 @@ fn syntax_works() {
use dioxus_hooks::*;
use dioxus_html as dioxus_elements;
static App: FC<()> = |cx, props| {
static App: Component<()> = |cx| {
cx.render(rsx! {
// left window
WebviewWindow {
+7 -1
View File
@@ -6,6 +6,9 @@
mod cfg;
mod escape;
mod events;
pub use wry;
pub use wry::application as tao;
// mod desktop_context;
use cfg::DesktopConfig;
@@ -28,7 +31,10 @@ use wry::{
webview::{WebView, WebViewBuilder},
};
pub fn launch(
pub fn launch(root: Component<()>) {
launch_with_props(root, (), |c| c)
}
pub fn launch_cfg(
root: Component<()>,
config_builder: impl for<'a, 'b> FnOnce(&'b mut DesktopConfig<'a>) -> &'b mut DesktopConfig<'a>,
) {