|
@@ -1,38 +1,42 @@
|
|
|
use blitz_renderer_vello::BlitzVelloRenderer;
|
|
|
-use blitz_shell::BlitzApplication;
|
|
|
+use blitz_shell::{BlitzApplication, View};
|
|
|
use dioxus_core::{ScopeId, VirtualDom};
|
|
|
use dioxus_history::{History, MemoryHistory};
|
|
|
-use std::{collections::HashSet, rc::Rc};
|
|
|
+use std::{
|
|
|
+ cell::RefCell,
|
|
|
+ collections::{HashMap, HashSet},
|
|
|
+ rc::Rc,
|
|
|
+};
|
|
|
use winit::application::ApplicationHandler;
|
|
|
use winit::event::{StartCause, WindowEvent};
|
|
|
use winit::event_loop::{ActiveEventLoop, EventLoopProxy};
|
|
|
use winit::window::WindowId;
|
|
|
|
|
|
use crate::{
|
|
|
- assets::DioxusNativeNetProvider, contexts::DioxusNativeDocument,
|
|
|
- mutation_writer::MutationWriter, BlitzShellEvent, DioxusDocument, DioxusNativeEvent,
|
|
|
- WindowConfig,
|
|
|
+ assets::DioxusNativeNetProvider, contexts::NativeDocument, mutation_writer::MutationWriter,
|
|
|
+ BlitzShellEvent, DioxusDocument, DioxusNativeEvent, SharedNativeTexture, WindowConfig,
|
|
|
};
|
|
|
|
|
|
pub struct DioxusNativeApplication {
|
|
|
pending_vdom: Option<VirtualDom>,
|
|
|
- inner: BlitzApplication<DioxusDocument, BlitzVelloRenderer>,
|
|
|
+ // inner: BlitzApplication<DioxusDocument, BlitzVelloRenderer>,
|
|
|
+ pub windows: HashMap<WindowId, View<DioxusDocument, BlitzVelloRenderer>>,
|
|
|
+
|
|
|
proxy: EventLoopProxy<BlitzShellEvent>,
|
|
|
}
|
|
|
|
|
|
+pub struct DioxusNativeWindow {}
|
|
|
+
|
|
|
impl DioxusNativeApplication {
|
|
|
pub fn new(proxy: EventLoopProxy<BlitzShellEvent>, vdom: VirtualDom) -> Self {
|
|
|
Self {
|
|
|
pending_vdom: Some(vdom),
|
|
|
- inner: BlitzApplication::new(proxy.clone()),
|
|
|
+ windows: HashMap::new(),
|
|
|
proxy,
|
|
|
+ // inner: BlitzApplication::new(proxy.clone()),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- pub fn add_window(&mut self, window_config: WindowConfig<DioxusDocument, BlitzVelloRenderer>) {
|
|
|
- self.inner.add_window(window_config);
|
|
|
- }
|
|
|
-
|
|
|
fn handle_blitz_shell_event(
|
|
|
&mut self,
|
|
|
event_loop: &ActiveEventLoop,
|
|
@@ -47,7 +51,7 @@ impl DioxusNativeApplication {
|
|
|
))]
|
|
|
DioxusNativeEvent::DevserverEvent(event) => match event {
|
|
|
dioxus_devtools::DevserverMsg::HotReload(hotreload_message) => {
|
|
|
- for window in self.inner.windows.values_mut() {
|
|
|
+ for window in self.windows.values_mut() {
|
|
|
dioxus_devtools::apply_changes(&window.doc.vdom, hotreload_message);
|
|
|
window.poll();
|
|
|
}
|
|
@@ -64,7 +68,7 @@ impl DioxusNativeApplication {
|
|
|
contents,
|
|
|
window,
|
|
|
} => {
|
|
|
- if let Some(window) = self.inner.windows.get_mut(window) {
|
|
|
+ if let Some(window) = self.windows.get_mut(window) {
|
|
|
window.doc.create_head_element(name, attributes, contents);
|
|
|
window.poll();
|
|
|
}
|
|
@@ -102,46 +106,51 @@ impl ApplicationHandler<BlitzShellEvent> for DioxusNativeApplication {
|
|
|
|
|
|
// Create document + window from the baked virtualdom
|
|
|
let doc = DioxusDocument::new(vdom, net_provider);
|
|
|
- let window = WindowConfig::new(doc);
|
|
|
+ // let window = WindowConfig::new(doc);
|
|
|
|
|
|
// little hack since View::init is not public - fix this once alpha-2 is out
|
|
|
- let old_windows = self.inner.windows.keys().copied().collect::<HashSet<_>>();
|
|
|
- self.add_window(window);
|
|
|
- self.inner.resumed(event_loop);
|
|
|
- let new_windows = self.inner.windows.keys().cloned().collect::<HashSet<_>>();
|
|
|
+ // let old_windows = self.inner.windows.keys().copied().collect::<HashSet<_>>();
|
|
|
+ // self.inner.add_window(window);
|
|
|
+ // self.inner.resumed(event_loop);
|
|
|
+ // let new_windows = self.inner.windows.keys().cloned().collect::<HashSet<_>>();
|
|
|
|
|
|
// todo(jon): we should actually mess with the pending windows instead of passing along the contexts
|
|
|
- for window_id in new_windows.difference(&old_windows) {
|
|
|
- let window = self.inner.windows.get_mut(window_id).unwrap();
|
|
|
- window.doc.vdom.in_runtime(|| {
|
|
|
- let shared: Rc<dyn dioxus_document::Document> =
|
|
|
- Rc::new(DioxusNativeDocument::new(self.proxy.clone(), *window_id));
|
|
|
- ScopeId::ROOT.provide_context(shared);
|
|
|
- });
|
|
|
-
|
|
|
- // Add history
|
|
|
- let history_provider: Rc<dyn History> = Rc::new(MemoryHistory::default());
|
|
|
- window
|
|
|
- .doc
|
|
|
- .vdom
|
|
|
- .in_runtime(|| ScopeId::ROOT.provide_context(history_provider));
|
|
|
-
|
|
|
- // Queue rebuild
|
|
|
- let mut writer = MutationWriter::new(&mut window.doc.inner, &mut window.doc.vdom_state);
|
|
|
- window.doc.vdom.rebuild(&mut writer);
|
|
|
- drop(writer);
|
|
|
-
|
|
|
- // And then request redraw
|
|
|
- window.request_redraw();
|
|
|
- }
|
|
|
+ // for window_id in new_windows.difference(&old_windows) {
|
|
|
+ // let window = self.inner.windows.get_mut(window_id).unwrap();
|
|
|
+ // window.doc.vdom.in_runtime(|| {
|
|
|
+ // let document = Rc::new(NativeDocument::new(
|
|
|
+ // self.proxy.clone(),
|
|
|
+ // *window_id,
|
|
|
+ // window.renderer.clone(),
|
|
|
+ // ));
|
|
|
+ // let shared: Rc<dyn dioxus_document::Document> = document.clone();
|
|
|
+ // ScopeId::ROOT.provide_context(document);
|
|
|
+ // ScopeId::ROOT.provide_context(shared);
|
|
|
+ // });
|
|
|
+
|
|
|
+ // // Add history
|
|
|
+ // let history_provider: Rc<dyn History> = Rc::new(MemoryHistory::default());
|
|
|
+ // window
|
|
|
+ // .doc
|
|
|
+ // .vdom
|
|
|
+ // .in_runtime(|| ScopeId::ROOT.provide_context(history_provider));
|
|
|
+
|
|
|
+ // // Queue rebuild
|
|
|
+ // let mut writer = MutationWriter::new(&mut window.doc.inner, &mut window.doc.vdom_state);
|
|
|
+ // window.doc.vdom.rebuild(&mut writer);
|
|
|
+ // drop(writer);
|
|
|
+
|
|
|
+ // // And then request redraw
|
|
|
+ // window.request_redraw();
|
|
|
+ // }
|
|
|
}
|
|
|
|
|
|
fn suspended(&mut self, event_loop: &ActiveEventLoop) {
|
|
|
- self.inner.suspended(event_loop);
|
|
|
+ // self.inner.suspended(event_loop);
|
|
|
}
|
|
|
|
|
|
fn new_events(&mut self, event_loop: &ActiveEventLoop, cause: StartCause) {
|
|
|
- self.inner.new_events(event_loop, cause);
|
|
|
+ // self.inner.new_events(event_loop, cause);
|
|
|
}
|
|
|
|
|
|
fn window_event(
|
|
@@ -150,17 +159,17 @@ impl ApplicationHandler<BlitzShellEvent> for DioxusNativeApplication {
|
|
|
window_id: WindowId,
|
|
|
event: WindowEvent,
|
|
|
) {
|
|
|
- self.inner.window_event(event_loop, window_id, event);
|
|
|
+ // self.inner.window_event(event_loop, window_id, event);
|
|
|
}
|
|
|
|
|
|
fn user_event(&mut self, event_loop: &ActiveEventLoop, event: BlitzShellEvent) {
|
|
|
- match event {
|
|
|
- BlitzShellEvent::Embedder(event) => {
|
|
|
- if let Some(event) = event.downcast_ref::<DioxusNativeEvent>() {
|
|
|
- self.handle_blitz_shell_event(event_loop, event);
|
|
|
- }
|
|
|
- }
|
|
|
- event => self.inner.user_event(event_loop, event),
|
|
|
- }
|
|
|
+ // match event {
|
|
|
+ // BlitzShellEvent::Embedder(event) => {
|
|
|
+ // if let Some(event) = event.downcast_ref::<DioxusNativeEvent>() {
|
|
|
+ // self.handle_blitz_shell_event(event_loop, event);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // event => self.inner.user_event(event_loop, event),
|
|
|
+ // }
|
|
|
}
|
|
|
}
|