Fix more examples to work with dioxus-native (#5179)
* Enable native for hotdog, file-explorer, and bluetooth-scanner examples Signed-off-by: Nico Burns <nico@nicoburns.com> * Fix crash in calculator example Signed-off-by: Nico Burns <nico@nicoburns.com> * Add config macro for native * Add Config struct to dioxus-native * Re-export dioxus-native as dioxus::native * Fix calculator example to work with dioxus-native * Fix calculator_mutable example to work with dioxus-native --------- Signed-off-by: Nico Burns <nico@nicoburns.com>
This commit is contained in:
1 parent
8aefb2a1e2
commit
35e289fe28
13 files changed
+93
-18
No files matched your search
@@ -0,0 +1,32 @@
|
||||
use dioxus_core::LaunchConfig;
|
||||
use winit::window::WindowAttributes;
|
||||
|
||||
/// The configuration for the desktop application.
|
||||
pub struct Config {
|
||||
pub(crate) window_attributes: WindowAttributes,
|
||||
}
|
||||
|
||||
impl LaunchConfig for Config {}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
window_attributes: WindowAttributes::default().with_title(
|
||||
dioxus_cli_config::app_title().unwrap_or_else(|| "Dioxus App".to_string()),
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
/// Set the configuration for the window.
|
||||
pub fn with_window_attributes(mut self, attrs: WindowAttributes) -> Self {
|
||||
// We need to do a swap because the window builder only takes itself as muy self
|
||||
self.window_attributes = attrs;
|
||||
self
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
//! - `tracing`: Enables tracing support.
|
||||
|
||||
mod assets;
|
||||
mod config;
|
||||
mod contexts;
|
||||
mod dioxus_application;
|
||||
mod dioxus_renderer;
|
||||
@@ -29,12 +30,15 @@ pub use dioxus_renderer::{DioxusNativeWindowRenderer, Features, Limits};
|
||||
#[cfg(not(all(target_os = "ios", target_abi = "sim")))]
|
||||
pub use dioxus_renderer::use_wgpu;
|
||||
|
||||
use blitz_shell::{create_default_event_loop, BlitzShellEvent, Config, WindowConfig};
|
||||
pub use config::Config;
|
||||
pub use winit::dpi::{LogicalSize, PhysicalSize};
|
||||
pub use winit::window::WindowAttributes;
|
||||
|
||||
use blitz_shell::{create_default_event_loop, BlitzShellEvent, WindowConfig};
|
||||
use dioxus_core::{ComponentFunction, Element, VirtualDom};
|
||||
use link_handler::DioxusNativeNavigationProvider;
|
||||
use std::any::Any;
|
||||
use std::sync::Arc;
|
||||
use winit::window::WindowAttributes;
|
||||
|
||||
/// Launch an interactive HTML/CSS renderer driven by the Dioxus virtualdom
|
||||
pub fn launch(app: fn() -> Element) {
|
||||
@@ -77,15 +81,19 @@ pub fn launch_cfg_with_props<P: Clone + 'static, M: 'static>(
|
||||
let mut features = None;
|
||||
let mut limits = None;
|
||||
let mut window_attributes = None;
|
||||
let mut _config = None;
|
||||
let mut config = None;
|
||||
for mut cfg in configs {
|
||||
cfg = try_read_config!(cfg, features, Features);
|
||||
cfg = try_read_config!(cfg, limits, Limits);
|
||||
cfg = try_read_config!(cfg, window_attributes, WindowAttributes);
|
||||
cfg = try_read_config!(cfg, _config, Config);
|
||||
cfg = try_read_config!(cfg, config, Config);
|
||||
let _ = cfg;
|
||||
}
|
||||
|
||||
let mut config = config.unwrap_or_default();
|
||||
if let Some(window_attributes) = window_attributes {
|
||||
config.window_attributes = window_attributes;
|
||||
}
|
||||
let event_loop = create_default_event_loop::<BlitzShellEvent>();
|
||||
|
||||
// Turn on the runtime and enter it
|
||||
@@ -148,7 +156,7 @@ pub fn launch_cfg_with_props<P: Clone + 'static, M: 'static>(
|
||||
let config = WindowConfig::with_attributes(
|
||||
Box::new(doc) as _,
|
||||
renderer.clone(),
|
||||
window_attributes.unwrap_or_default(),
|
||||
config.window_attributes,
|
||||
);
|
||||
|
||||
// Create application
|
||||
|
||||
Reference in new issue
Block a user