wip: move examples around
This commit is contained in:
1 parent
d298b626d3
commit
1e6e5e611b
86 files changed
+160
-216
No files matched your search
@@ -1,6 +1,7 @@
|
||||
use std::cell::RefCell;
|
||||
|
||||
use dioxus::prelude::Scope;
|
||||
use dioxus::ScopeChildren;
|
||||
use dioxus_core as dioxus;
|
||||
use dioxus_core::{Context, Element, LazyNodes, NodeFactory, Properties};
|
||||
use dioxus_core_macro::Props;
|
||||
@@ -42,6 +43,8 @@ pub struct WebviewWindowProps<'a> {
|
||||
|
||||
/// focuse me
|
||||
onfocused: &'a dyn FnMut(()),
|
||||
|
||||
children: ScopeChildren<'a>,
|
||||
}
|
||||
|
||||
/// A handle to a
|
||||
@@ -70,9 +73,10 @@ pub fn WebviewWindow<'a>((cx, props): Scope<'a, WebviewWindowProps>) -> Element<
|
||||
);
|
||||
|
||||
// render the children directly
|
||||
cx.render(LazyNodes::new(move |f: NodeFactory| {
|
||||
f.fragment_from_iter(cx.children())
|
||||
}))
|
||||
todo!()
|
||||
// cx.render(LazyNodes::new(move |f: NodeFactory| {
|
||||
// f.fragment_from_iter(cx.children())
|
||||
// }))
|
||||
}
|
||||
|
||||
pub struct WindowHandle {}
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
position: fixed;
|
||||
}
|
||||
</style> -->
|
||||
<link rel="stylesheet" href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css">
|
||||
<script src="https://cdn.plot.ly/plotly-1.52.3.min.js"></script>
|
||||
</head>
|
||||
|
||||
|
||||
|
||||
@@ -20,9 +20,9 @@ use serde::{Deserialize, Serialize};
|
||||
pub use wry;
|
||||
|
||||
use wry::application::accelerator::{Accelerator, SysMods};
|
||||
use wry::application::event::{Event, StartCause, WindowEvent};
|
||||
use wry::application::event::{ElementState, Event, StartCause, WindowEvent};
|
||||
use wry::application::event_loop::{self, ControlFlow, EventLoop};
|
||||
use wry::application::keyboard::KeyCode;
|
||||
use wry::application::keyboard::{Key, KeyCode, ModifiersState};
|
||||
use wry::application::menu::{MenuBar, MenuItem, MenuItemAttributes};
|
||||
use wry::application::window::Fullscreen;
|
||||
use wry::webview::{WebView, WebViewBuilder};
|
||||
@@ -94,6 +94,11 @@ pub fn run<T: 'static + Send + Sync>(
|
||||
|
||||
let props_shared = Cell::new(Some(props));
|
||||
|
||||
// create local modifier state
|
||||
let mut modifiers = ModifiersState::default();
|
||||
|
||||
let quit_hotkey = Accelerator::new(SysMods::Cmd, KeyCode::KeyQ);
|
||||
|
||||
event_loop.run(move |event, event_loop, control_flow| {
|
||||
*control_flow = ControlFlow::Wait;
|
||||
|
||||
@@ -112,10 +117,8 @@ pub fn run<T: 'static + Send + Sync>(
|
||||
first_menu.add_native_item(MenuItem::HideOthers);
|
||||
first_menu.add_native_item(MenuItem::ShowAll);
|
||||
|
||||
let quit_item = first_menu.add_item(
|
||||
MenuItemAttributes::new("Quit")
|
||||
.with_accelerators(&Accelerator::new(SysMods::Cmd, KeyCode::KeyQ)),
|
||||
);
|
||||
first_menu.add_native_item(MenuItem::Quit);
|
||||
first_menu.add_native_item(MenuItem::CloseWindow);
|
||||
|
||||
// create second menu
|
||||
let mut second_menu = MenuBar::new();
|
||||
@@ -129,6 +132,7 @@ pub fn run<T: 'static + Send + Sync>(
|
||||
menu_bar_menu.add_submenu("Second menu", true, second_menu);
|
||||
|
||||
let window = WindowBuilder::new()
|
||||
.with_maximized(true)
|
||||
.with_menu(menu_bar_menu)
|
||||
.with_title("Dioxus App")
|
||||
.build(event_loop)
|
||||
@@ -197,6 +201,37 @@ pub fn run<T: 'static + Send + Sync>(
|
||||
event, window_id, ..
|
||||
} => match event {
|
||||
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
||||
WindowEvent::Destroyed { .. } => {
|
||||
webviews.remove(&window_id);
|
||||
if webviews.is_empty() {
|
||||
*control_flow = ControlFlow::Exit;
|
||||
}
|
||||
}
|
||||
// catch only pressed event
|
||||
WindowEvent::KeyboardInput { event, .. } => {
|
||||
log::debug!("keybowrd input");
|
||||
if quit_hotkey.matches(&modifiers, &event.physical_key) {
|
||||
log::debug!("quitting");
|
||||
|
||||
webviews.remove(&window_id);
|
||||
if webviews.is_empty() {
|
||||
*control_flow = ControlFlow::Exit;
|
||||
}
|
||||
}
|
||||
|
||||
// println!(
|
||||
// "KeyEvent: `Shift` + `1` | logical_key: {:?}",
|
||||
// &event.logical_key
|
||||
// );
|
||||
// we can match manually without `Accelerator`
|
||||
|
||||
// else if event.key_without_modifiers() == Key::Character("1")
|
||||
// && modifiers.is_empty()
|
||||
// {
|
||||
// println!("KeyEvent: `1`");
|
||||
// }
|
||||
}
|
||||
|
||||
WindowEvent::Resized(_) | WindowEvent::Moved(_) => {
|
||||
if let Some(view) = webviews.get_mut(&window_id) {
|
||||
let _ = view.resize();
|
||||
|
||||
Reference in new issue
Block a user