Less clumsy configuration for desktop and mobile (#553)

* chore: dont use prebuilt builder pattern for configuring desktop

* chore: use regular config pattern for web

* Chore: update docs too

* chore: clean up some warnings
This commit is contained in:
Jon Kelley authored and GitHub committed 2022-09-13 16:22:27 -07:00
1 parent 41b450eedf
commit 540e785d8b
28 files changed
+172 -156

No files matched your search

+8 -8
View File
@@ -6,16 +6,16 @@ This calculator version uses React-style state management. All state is held as
use dioxus::events::*;
use dioxus::html::input_data::keyboard_types::Key;
use dioxus::prelude::*;
use dioxus_desktop::{Config, WindowBuilder};
fn main() {
use dioxus_desktop::tao::dpi::LogicalSize;
dioxus_desktop::launch_cfg(app, |cfg| {
cfg.with_window(|w| {
w.with_title("Calculator Demo")
.with_resizable(false)
.with_inner_size(LogicalSize::new(320.0, 530.0))
})
});
let config = Config::new().with_window(
WindowBuilder::default()
.with_title("Calculator")
.with_inner_size(dioxus_desktop::LogicalSize::new(300.0, 500.0)),
);
dioxus_desktop::launch_cfg(app, config);
}
fn app(cx: Scope) -> Element {
+10 -7
View File
@@ -2,14 +2,17 @@
//! to add things like stylesheets, scripts, and third-party JS libraries.
use dioxus::prelude::*;
use dioxus_desktop::Config;
fn main() {
dioxus_desktop::launch_cfg(app, |c| {
c.with_custom_head("<style>body { background-color: red; }</style>".into())
});
dioxus_desktop::launch_cfg(
app,
Config::new().with_custom_head("<style>body { background-color: red; }</style>".into()),
);
dioxus_desktop::launch_cfg(app, |c| {
c.with_custom_index(
dioxus_desktop::launch_cfg(
app,
Config::new().with_custom_index(
r#"
<!DOCTYPE html>
<html>
@@ -24,8 +27,8 @@ fn main() {
</html>
"#
.into(),
)
});
),
);
}
fn app(cx: Scope) -> Element {
+5 -1
View File
@@ -9,9 +9,13 @@
//! we dont need to clutter our code with `read` commands.
use dioxus::prelude::*;
use dioxus_desktop::{Config, WindowBuilder};
fn main() {
dioxus_desktop::launch_cfg(app, |c| c.with_window(|w| w.with_resizable(true)));
dioxus_desktop::launch_cfg(
app,
Config::new().with_window(WindowBuilder::new().with_resizable(true)),
);
}
fn app(cx: Scope) -> Element {
+6 -5
View File
@@ -1,12 +1,13 @@
use dioxus::prelude::*;
use dioxus_desktop::Config;
fn main() {
dioxus_desktop::launch_with_props(app, (), |c| {
c.with_file_drop_handler(|_w, e| {
println!("{:?}", e);
true
})
let cfg = Config::new().with_file_drop_handler(|_w, e| {
println!("{:?}", e);
true
});
dioxus_desktop::launch_with_props(app, (), cfg);
}
fn app(cx: Scope) -> Element {
+9 -8
View File
@@ -1,17 +1,18 @@
use dioxus::prelude::*;
use dioxus_desktop::tao::dpi::LogicalSize;
use dioxus_desktop::{tao::dpi::LogicalSize, Config, WindowBuilder};
use dioxus_router::{Link, Route, Router};
fn main() {
env_logger::init();
dioxus_desktop::launch_cfg(app, |c| {
c.with_window(|c| {
c.with_title("Spinsense Client")
.with_inner_size(LogicalSize::new(600, 1000))
.with_resizable(false)
})
})
let cfg = Config::new().with_window(
WindowBuilder::new()
.with_title("Spinsense Client")
.with_inner_size(LogicalSize::new(600, 1000))
.with_resizable(false),
);
dioxus_desktop::launch_cfg(app, cfg)
}
fn app(cx: Scope) -> Element {
+2 -1
View File
@@ -10,12 +10,13 @@
//! proof-of-concept for the hydration feature, but you'll probably only want to use hydration for the web.
use dioxus::prelude::*;
use dioxus_desktop::Config;
fn main() {
let vdom = VirtualDom::new(app);
let content = dioxus_ssr::render_vdom_cfg(&vdom, |f| f.pre_render(true));
dioxus_desktop::launch_cfg(app, |c| c.with_prerendered(content));
dioxus_desktop::launch_cfg(app, Config::new().with_prerendered(content));
}
fn app(cx: Scope) -> Element {
+9 -7
View File
@@ -21,15 +21,17 @@ use dioxus::events::*;
use dioxus::html::input_data::keyboard_types::Key;
use dioxus::prelude::*;
use dioxus_desktop::wry::application::dpi::LogicalSize;
use dioxus_desktop::{Config, WindowBuilder};
fn main() {
dioxus_desktop::launch_cfg(app, |cfg| {
cfg.with_window(|w| {
w.with_title("Calculator Demo")
.with_resizable(false)
.with_inner_size(LogicalSize::new(320.0, 530.0))
})
});
let cfg = Config::new().with_window(
WindowBuilder::new()
.with_title("Calculator Demo")
.with_resizable(false)
.with_inner_size(LogicalSize::new(320.0, 530.0)),
);
dioxus_desktop::launch_cfg(app, cfg);
}
fn app(cx: Scope) -> Element {
+8 -7
View File
@@ -14,15 +14,16 @@
//! primitives in our own custom components.
use dioxus::prelude::*;
use dioxus_desktop::{Config, LogicalSize, WindowBuilder};
fn main() {
use dioxus_desktop::tao::dpi::LogicalSize;
dioxus_desktop::launch_cfg(app, |cfg| {
cfg.with_window(|w| {
w.with_title("Doggo Fetcher")
.with_inner_size(LogicalSize::new(600.0, 800.0))
})
});
let cfg = Config::new().with_window(
WindowBuilder::new()
.with_title("Doggo Fetcher")
.with_inner_size(LogicalSize::new(600.0, 800.0)),
);
dioxus_desktop::launch_cfg(app, cfg);
}
#[derive(serde::Deserialize)]
+6 -3
View File
@@ -9,11 +9,14 @@
//! https://dev.to/arctic_hen7/how-to-set-up-tailwind-css-with-yew-and-trunk-il9
use dioxus::prelude::*;
use dioxus_desktop::Config;
fn main() {
dioxus_desktop::launch_cfg(app, |c| {
c.with_custom_head("<script src=\"https://cdn.tailwindcss.com\"></script>".to_string())
});
dioxus_desktop::launch_cfg(
app,
Config::new()
.with_custom_head("<script src=\"https://cdn.tailwindcss.com\"></script>".to_string()),
);
}
pub fn app(cx: Scope) -> Element {
+2 -2
View File
@@ -7,14 +7,14 @@ fn main() {
dioxus_desktop::launch(app);
}
#[derive(Eq, PartialEq)]
#[derive(PartialEq, Eq)]
pub enum FilterState {
All,
Active,
Completed,
}
#[derive(Debug, Eq, PartialEq, Clone)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct TodoItem {
pub id: u32,
pub checked: bool,
+8 -3
View File
@@ -1,9 +1,14 @@
use dioxus::prelude::*;
use dioxus_desktop::{Config, WindowBuilder};
fn main() {
dioxus_desktop::launch_cfg(app, |cfg| {
cfg.with_window(|w| w.with_title("BorderLess Demo").with_decorations(false))
});
let cfg = Config::new().with_window(
WindowBuilder::new()
.with_title("Borderless Window")
.with_decorations(false),
);
dioxus_desktop::launch_cfg(app, cfg);
}
fn app(cx: Scope) -> Element {