implement launch builder for the desktop and web platforms

This commit is contained in:
Evan Almloff committed 2024-01-16 08:42:16 -06:00
1 parent ef553a2cb2
commit 7e4d2debe0
70 files changed
+448 -431

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+1 -1
View File
@@ -1,7 +1,7 @@
use dioxus::{events::*, html::MouseEvent, prelude::*};
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
#[derive(Debug)]
+34 -14
View File
@@ -15,7 +15,7 @@ fn main() {
.with_inner_size(LogicalSize::new(300.0, 500.0)),
);
dioxus_desktop::launch_cfg(app, config);
LaunchBuilder::new(app).cfg(config);
}
fn app() -> Element {
@@ -61,9 +61,7 @@ fn app() -> Element {
style { {include_str!("./assets/calculator.css")} }
div { id: "wrapper",
div { class: "app",
div { class: "calculator",
tabindex: "0",
onkeydown: handle_key_down_event,
div { class: "calculator", tabindex: "0", onkeydown: handle_key_down_event,
div { class: "calculator-display", "{val}" }
div { class: "calculator-keypad",
div { class: "input-keys",
@@ -72,7 +70,7 @@ fn app() -> Element {
class: "calculator-key key-clear",
onclick: move |_| {
val.set(String::new());
if !val.cloned().is_empty(){
if !val.cloned().is_empty() {
val.set("0".into());
}
},
@@ -93,16 +91,22 @@ fn app() -> Element {
button {
class: "calculator-key key-percent",
onclick: move |_| {
val.set(
format!("{}", calc_val(val.cloned().as_str()) / 100.0)
);
val.set(format!("{}", calc_val(val.cloned().as_str()) / 100.0));
},
"%"
}
}
div { class: "digit-keys",
button { class: "calculator-key key-0", onclick: move |_| input_digit(0), "0" }
button { class: "calculator-key key-dot", onclick: move |_| val.write().push('.'), "●" }
button {
class: "calculator-key key-0",
onclick: move |_| input_digit(0),
"0"
}
button {
class: "calculator-key key-dot",
onclick: move |_| val.write().push('.'),
"●"
}
for k in 1..10 {
button {
class: "calculator-key {k}",
@@ -114,10 +118,26 @@ fn app() -> Element {
}
}
div { class: "operator-keys",
button { class: "calculator-key key-divide", onclick: move |_| input_operator("/"), "÷" }
button { class: "calculator-key key-multiply", onclick: move |_| input_operator("*"), "×" }
button { class: "calculator-key key-subtract", onclick: move |_| input_operator("-"), "−" }
button { class: "calculator-key key-add", onclick: move |_| input_operator("+"), "+" }
button {
class: "calculator-key key-divide",
onclick: move |_| input_operator("/"),
"÷"
}
button {
class: "calculator-key key-multiply",
onclick: move |_| input_operator("*"),
"×"
}
button {
class: "calculator-key key-subtract",
onclick: move |_| input_operator("-"),
"−"
}
button {
class: "calculator-key key-add",
onclick: move |_| input_operator("+"),
"+"
}
button {
class: "calculator-key key-equals",
onclick: move |_| val.set(format!("{}", calc_val(val.cloned().as_str()))),
+1 -1
View File
@@ -2,7 +2,7 @@ use dioxus::prelude::*;
use dioxus_signals::use_signal;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+1 -1
View File
@@ -6,7 +6,7 @@ use dioxus::prelude::*;
use futures_util::StreamExt;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+1 -1
View File
@@ -3,7 +3,7 @@ use std::rc::Rc;
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+1 -1
View File
@@ -4,7 +4,7 @@
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+1 -1
View File
@@ -3,7 +3,7 @@ use dioxus::prelude::*;
use dioxus_router::prelude::*;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
/// A type alias that reprsents a shared context between components
+1 -1
View File
@@ -1,7 +1,7 @@
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+3 -7
View File
@@ -5,13 +5,11 @@ use dioxus::prelude::*;
use dioxus_desktop::Config;
fn main() {
dioxus_desktop::launch_cfg(
app,
LaunchBuilder::new(app).cfg(
Config::new().with_custom_head("<style>body { background-color: red; }</style>".into()),
);
dioxus_desktop::launch_cfg(
app,
LaunchBuilder::new(app).cfg(
Config::new().with_custom_index(
r#"
<!DOCTYPE html>
@@ -33,8 +31,6 @@ fn main() {
fn app() -> Element {
rsx! {
div {
h1 {"hello world!"}
}
div { h1 { "hello world!" } }
}
}
+1 -1
View File
@@ -1,7 +1,7 @@
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+1 -1
View File
@@ -2,7 +2,7 @@ use dioxus::prelude::*;
use std::collections::HashMap;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+1 -1
View File
@@ -2,7 +2,7 @@ use dioxus::prelude::*;
use dioxus_desktop::{use_asset_handler, wry::http::Response};
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+1 -1
View File
@@ -1,7 +1,7 @@
use dioxus::{dioxus_core::CapturedError, prelude::*};
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+1 -1
View File
@@ -1,7 +1,7 @@
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+3 -3
View File
@@ -12,9 +12,9 @@ use dioxus::prelude::*;
use dioxus_desktop::{Config, WindowBuilder};
fn main() {
Config::new()
.with_window(WindowBuilder::new().with_resizable(true))
.launch(app)
LaunchBuilder::new(app)
.cfg(Config::new().with_window(WindowBuilder::new().with_resizable(true)))
.launch()
}
const _STYLE: &str = manganis::mg!(file("./examples/assets/fileexplorer.css"));
+1 -1
View File
@@ -4,7 +4,7 @@ use dioxus::prelude::*;
use tokio::time::sleep;
fn main() {
dioxus_desktop::launch(App);
launch(App);
}
fn App() -> Element {
+5 -7
View File
@@ -2,18 +2,16 @@ use dioxus::prelude::*;
use dioxus_desktop::Config;
fn main() {
Config::new()
.with_file_drop_handler(|_w, e| {
LaunchBuilder::new(app)
.cfg(Config::new().with_file_drop_handler(|_w, e| {
println!("{e:?}");
true
})
.launch(app)
}))
.launch()
}
fn app() -> Element {
rsx!(
div {
h1 { "drag a file here and check your console" }
}
div { h1 { "drag a file here and check your console" } }
)
}
+22 -16
View File
@@ -5,17 +5,17 @@ use dioxus_router::prelude::*;
fn main() {
env_logger::init();
Config::new()
.with_window(
LaunchBuilder::new(|| {
render! { Router::<Route> {} }
})
.cfg(
Config::new().with_window(
WindowBuilder::new()
.with_inner_size(LogicalSize::new(600, 1000))
.with_resizable(false),
)
.launch(|| {
render! {
Router::<Route> {}
}
});
),
)
.launch()
}
#[derive(Routable, Clone)]
@@ -36,18 +36,24 @@ enum Route {
fn Footer() -> Element {
render! {
div {
Outlet::<Route> { }
Outlet::<Route> {}
p {
"----"
}
p { "----" }
nav {
ul {
li { Link { to: Route::Home {}, "Home" } }
li { Link { to: Route::Games {}, "Games" } }
li { Link { to: Route::Play {}, "Play" } }
li { Link { to: Route::Settings {}, "Settings" } }
li {
Link { to: Route::Home {}, "Home" }
}
li {
Link { to: Route::Games {}, "Games" }
}
li {
Link { to: Route::Play {}, "Play" }
}
li {
Link { to: Route::Settings {}, "Settings" }
}
}
}
}
+1 -1
View File
@@ -6,7 +6,7 @@
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+1 -1
View File
@@ -3,7 +3,7 @@ use std::fmt::Display;
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+1 -1
View File
@@ -1,7 +1,7 @@
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+4 -4
View File
@@ -13,15 +13,15 @@ use dioxus::prelude::*;
use dioxus_desktop::Config;
fn main() {
Config::new()
.with_prerendered({
LaunchBuilder::new(app)
.cfg(Config::new().with_prerendered({
// We build the dom a first time, then pre-render it to HTML
let pre_rendered_dom = VirtualDom::prebuilt(app);
// We then launch the app with the pre-rendered HTML
dioxus_ssr::pre_render(&pre_rendered_dom)
})
.launch(app);
}))
.launch();
}
fn app() -> Element {
+1 -1
View File
@@ -5,7 +5,7 @@
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
const FIELDS: &[(&str, &str)] = &[
+1 -1
View File
@@ -2,7 +2,7 @@ use dioxus::prelude::*;
use dioxus_router::prelude::*;
fn main() {
dioxus_desktop::launch(App);
launch(App);
}
#[component]
+1 -1
View File
@@ -4,7 +4,7 @@
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+9 -5
View File
@@ -49,8 +49,7 @@ pub fn main() -> Result<()> {
// Right now we're going through dioxus-desktop but we'd like to go through dioxus-mobile
// That will seed the index.html with some fixes that prevent the page from scrolling/zooming etc
dioxus_desktop::launch_cfg(
app,
LaunchBuilder::new(app).cfg(
// Note that we have to disable the viewport goofiness of the browser.
// Dioxus_mobile should do this for us
Config::default().with_custom_index(include_str!("index.html").to_string()),
@@ -66,10 +65,15 @@ fn app() -> Element {
render! {
div {
h1 { "Hello, Mobile"}
div { margin_left: "auto", margin_right: "auto", width: "200px", padding: "10px", border: "1px solid black",
h1 { "Hello, Mobile" }
div {
margin_left: "auto",
margin_right: "auto",
width: "200px",
padding: "10px",
border: "1px solid black",
button {
onclick: move|_| {
onclick: move |_| {
println!("Clicked!");
items.push(items.len());
cx.needs_update_any(ScopeId::ROOT);
+1 -1
View File
@@ -1,7 +1,7 @@
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+1 -1
View File
@@ -7,7 +7,7 @@
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+1 -1
View File
@@ -7,7 +7,7 @@
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+1 -1
View File
@@ -2,7 +2,7 @@ use dioxus::prelude::*;
use dioxus_desktop::{tao::dpi::PhysicalPosition, LogicalSize, WindowBuilder};
fn main() {
dioxus_desktop::launch_cfg(app, make_config());
LaunchBuilder::new(app).cfg(make_config());
}
fn app() -> Element {
+1 -1
View File
@@ -32,7 +32,7 @@ fn main() {
.with_inner_size(LogicalSize::new(320.0, 530.0)),
);
dioxus_desktop::launch_cfg(app, cfg);
LaunchBuilder::new(app).cfg(cfg);
}
const STYLE: &str = include_str!("./assets/calculator.css");
+1 -1
View File
@@ -8,7 +8,7 @@
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+2 -6
View File
@@ -4,8 +4,7 @@ use std::rc::Rc;
use dioxus::{html::geometry::euclid::Rect, prelude::*};
fn main() {
dioxus_desktop::launch_cfg(
app,
LaunchBuilder::new(app).cfg(
dioxus_desktop::Config::default().with_custom_head(
r#"
<style type="text/css">
@@ -48,9 +47,6 @@ fn app() -> Element {
"This element is {dimensions():?}"
}
button {
onclick: read_dims,
"Read dimensions"
}
button { onclick: read_dims, "Read dimensions" }
)
}
+1 -1
View File
@@ -5,7 +5,7 @@
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+1 -1
View File
@@ -5,7 +5,7 @@ fn main() {
#[cfg(target_arch = "wasm32")]
dioxus_web::launch(App);
#[cfg(not(target_arch = "wasm32"))]
dioxus_desktop::launch(App);
launch(App);
}
// ANCHOR: router
+1 -1
View File
@@ -40,7 +40,7 @@
fn main() {
todo!()
// dioxus_desktop::launch(App);
// launch(App);
}
// use core::{fmt, str::FromStr};
+1 -1
View File
@@ -1,7 +1,7 @@
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+1 -1
View File
@@ -2,7 +2,7 @@ use dioxus::prelude::*;
use dioxus_desktop::use_global_shortcut;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+1 -1
View File
@@ -1,7 +1,7 @@
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+1 -1
View File
@@ -2,7 +2,7 @@ use dioxus::prelude::*;
use std::time::Duration;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+1 -1
View File
@@ -9,7 +9,7 @@ fn main() {
.with_module_level("dioxus", log::LevelFilter::Trace)
.init()
.unwrap();
dioxus_desktop::launch(App);
launch(App);
}
#[component]
+1 -1
View File
@@ -1,7 +1,7 @@
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+1 -1
View File
@@ -38,5 +38,5 @@ fn Nav() -> Element {
}
fn main() {
dioxus_desktop::launch(|| render!(Router::<Route> {}));
launch(|| render!(Router::<Route> {}));
}
+1 -1
View File
@@ -4,7 +4,7 @@ use futures_util::{future, stream, Stream, StreamExt};
use std::time::Duration;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+12 -19
View File
@@ -17,19 +17,21 @@ use dioxus::prelude::*;
use dioxus_desktop::{Config, LogicalSize, WindowBuilder};
fn main() {
Config::new()
.with_window(
WindowBuilder::new()
.with_title("Doggo Fetcher")
.with_inner_size(LogicalSize::new(600.0, 800.0)),
LaunchBuilder::new(app)
.cfg(
Config::new().with_window(
WindowBuilder::new()
.with_title("Doggo Fetcher")
.with_inner_size(LogicalSize::new(600.0, 800.0)),
),
)
.launch(app)
.launch()
}
fn app() -> Element {
rsx! {
div {
h1 {"Dogs are very important"}
h1 { "Dogs are very important" }
p {
"The dog or domestic dog (Canis familiaris[4][5] or Canis lupus familiaris[5])"
"is a domesticated descendant of the wolf which is characterized by an upturning tail."
@@ -39,7 +41,7 @@ fn app() -> Element {
}
h3 { "Illustrious Dog Photo" }
Doggo { }
Doggo {}
}
}
}
@@ -63,17 +65,8 @@ fn Doggo() -> Element {
match fut.value().read().as_ref() {
Some(Ok(resp)) => rsx! {
button {
onclick: move |_| fut.restart(),
"Click to fetch another doggo"
}
div {
img {
max_width: "500px",
max_height: "500px",
src: "{resp.message}",
}
}
button { onclick: move |_| fut.restart(), "Click to fetch another doggo" }
div { img { max_width: "500px", max_height: "500px", src: "{resp.message}" } }
},
Some(Err(_)) => rsx! { div { "loading dogs failed" } },
None => rsx! { div { "loading dogs..." } },
+1 -1
View File
@@ -4,7 +4,7 @@ use dioxus::prelude::*;
use rand::{thread_rng, Rng};
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+1 -1
View File
@@ -79,5 +79,5 @@ fn app() -> Element {
}
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
+1 -1
View File
@@ -6,7 +6,7 @@ const _STYLE: &str = manganis::mg!(file("./public/tailwind.css"));
fn main() {
#[cfg(not(target_arch = "wasm32"))]
dioxus_desktop::launch(app);
launch(app);
#[cfg(target_arch = "wasm32")]
dioxus_web::launch(app);
}
+1 -1
View File
@@ -6,7 +6,7 @@ use dioxus::prelude::*;
use std::time::Duration;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+1 -1
View File
@@ -3,7 +3,7 @@
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+1 -1
View File
@@ -4,7 +4,7 @@ use dioxus_elements::input_data::keyboard_types::Key;
use std::collections::HashMap;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
#[derive(PartialEq, Eq, Clone, Copy)]
+1 -1
View File
@@ -26,7 +26,7 @@ fn main() {
}
});
}
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+1 -1
View File
@@ -1,7 +1,7 @@
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+18 -13
View File
@@ -2,13 +2,15 @@ use dioxus::prelude::*;
use dioxus_desktop::{window, Config, WindowBuilder};
fn main() {
Config::new()
.with_window(
WindowBuilder::new()
.with_title("Borderless Window")
.with_decorations(false),
LaunchBuilder::new(app)
.cfg(
Config::new().with_window(
WindowBuilder::new()
.with_title("Borderless Window")
.with_decorations(false),
),
)
.launch(app)
.launch()
}
fn app() -> Element {
@@ -17,11 +19,16 @@ fn app() -> Element {
let mut decorations = use_signal(|| false);
rsx!(
link { href:"https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css", rel:"stylesheet" }
header { class: "text-gray-400 bg-gray-900 body-font", onmousedown: move |_| window().drag(),
link {
href: "https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css",
rel: "stylesheet"
}
header {
class: "text-gray-400 bg-gray-900 body-font",
onmousedown: move |_| window().drag(),
div { class: "container mx-auto flex flex-wrap p-5 flex-col md:flex-row items-center",
a { class: "flex title-font font-medium items-center text-white mb-4 md:mb-0",
span { class: "ml-3 text-xl", "Dioxus"}
span { class: "ml-3 text-xl", "Dioxus" }
}
nav { class: "md:ml-auto flex flex-wrap items-center text-base justify-center" }
button {
@@ -49,10 +56,8 @@ fn app() -> Element {
}
}
br {}
div {
class: "container mx-auto",
div {
class: "grid grid-cols-5",
div { class: "container mx-auto",
div { class: "grid grid-cols-5",
div {
button {
class: "inline-flex items-center text-white bg-green-500 border-0 py-1 px-3 hover:bg-green-700 rounded",
+4 -9
View File
@@ -5,9 +5,9 @@ use dioxus_desktop::use_wry_event_handler;
use dioxus_desktop::{Config, WindowCloseBehaviour};
fn main() {
Config::new()
.with_close_behaviour(WindowCloseBehaviour::CloseWindow)
.launch(app)
LaunchBuilder::new(app)
.cfg(Config::new().with_close_behaviour(WindowCloseBehaviour::CloseWindow))
.launch()
}
fn app() -> Element {
@@ -22,12 +22,7 @@ fn app() -> Element {
});
rsx! {
div {
width: "100%",
height: "100%",
display: "flex",
flex_direction: "column",
align_items: "center",
div { width: "100%", height: "100%", display: "flex", flex_direction: "column", align_items: "center",
if focused() {
"This window is focused!"
} else {
+1 -1
View File
@@ -1,7 +1,7 @@
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {
+1 -1
View File
@@ -5,7 +5,7 @@
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
launch(app);
}
fn app() -> Element {