Skip to content

Commit

Permalink
multiple windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhou121 committed Aug 10, 2023
1 parent 28d2026 commit 5786551
Show file tree
Hide file tree
Showing 15 changed files with 371 additions and 308 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ unicode-segmentation = "1.10.0"
leptos_reactive = { version = "0.5.0-alpha" }
glazier = { git = "https://github.com/lapce/glazier", features = [
"serde",
], rev = "86f0494fbf9ea6a4ba0754cac8412272860fa127" }
], rev = "db03ea4295daef69cb8d0877f2b2e5734cc116be" }
# glazier = { path = "../glazier", features = ["serde"] }
peniko = { git = "https://github.com/linebender/peniko", rev = "cafdac9a211a0fb2fec5656bd663d1ac770bcc81" }
wgpu = "0.15"
Expand Down
20 changes: 10 additions & 10 deletions reactive/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ impl Id {
/// Dispose the relevant resources that's linking to this Id, and the all the children
/// and grandchildren.
pub(crate) fn dispose(&self) {
let (children, signal) = RUNTIME.with(|runtime| {
if let Ok((children, signal)) = RUNTIME.try_with(|runtime| {
(
runtime.children.borrow_mut().remove(self),
runtime.signals.borrow_mut().remove(self),
)
});

if let Some(children) = children {
for child in children {
child.dispose();
}) {
if let Some(children) = children {
for child in children {
child.dispose();
}
}
}

if let Some(signal) = signal {
for (_, effect) in signal.subscribers() {
observer_clean_up(&effect);
if let Some(signal) = signal {
for (_, effect) in signal.subscribers() {
observer_clean_up(&effect);
}
}
}
}
Expand Down
39 changes: 15 additions & 24 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use glazier::{kurbo::Size, WindowBuilder};

use crate::{app_handle::AppHandle, view::View, window::WindowConfig};
use crate::{id::WindowId, new_window, view::View, window::WindowConfig};

type AppEventCallback = dyn Fn(&AppEvent);

pub fn launch<V: View + 'static>(app_view: impl Fn() -> V + 'static) {
Application::new().window(app_view, None).run()
Application::new()
.window(WindowId::next(), app_view, None)
.run()
}

pub enum AppEvent {
WillTerminate,
Reopen { has_visible_windows: bool },
}

/// Floem top level application
Expand All @@ -33,6 +34,14 @@ impl glazier::AppHandler for Application {
action(&AppEvent::WillTerminate);
}
}

fn should_handle_reopen(&mut self, has_visible_windows: bool) {
if let Some(action) = self.event_listener.as_ref() {
action(&AppEvent::Reopen {
has_visible_windows,
});
}
}
}

impl Application {
Expand All @@ -52,29 +61,11 @@ impl Application {
/// just chain more window method to the builder
pub fn window<V: View + 'static>(
self,
window_id: WindowId,
app_view: impl FnOnce() -> V + 'static,
config: Option<WindowConfig>,
) -> Self {
let application = self.application.clone();
{
let app = AppHandle::new(app_view);
let mut builder = WindowBuilder::new(application).size(
config
.as_ref()
.and_then(|c| c.size)
.unwrap_or_else(|| Size::new(800.0, 600.0)),
);
if let Some(position) = config.as_ref().and_then(|c| c.position) {
builder = builder.position(position);
}
if let Some(show_titlebar) = config.as_ref().and_then(|c| c.show_titlebar) {
builder = builder.show_titlebar(show_titlebar);
}

builder = builder.handler(Box::new(app));
let window = builder.build().unwrap();
window.show();
}
new_window(window_id, app_view, config);
self
}

Expand Down
Loading

0 comments on commit 5786551

Please sign in to comment.