remove windows method (use commands instead)
This commit is contained in:
parent
ac20f35c62
commit
5e4e410b18
6 changed files with 8 additions and 73 deletions
|
|
@ -131,6 +131,7 @@ impl Application for Example {
|
|||
}
|
||||
WindowMessage::CloseWindow => {
|
||||
let _ = self.windows.remove(&id);
|
||||
return window::close(id);
|
||||
}
|
||||
WindowMessage::Resized(pane_grid::ResizeEvent { split, ratio }) => {
|
||||
let window = self.windows.get_mut(&id).unwrap();
|
||||
|
|
@ -173,8 +174,9 @@ impl Application for Example {
|
|||
title: format!("New window ({})", self.windows.len()),
|
||||
};
|
||||
|
||||
self.windows
|
||||
.insert(window::Id::new(self.windows.len()), window);
|
||||
let window_id = window::Id::new(self.windows.len());
|
||||
self.windows.insert(window_id, window);
|
||||
return window::spawn(window_id, Default::default());
|
||||
}
|
||||
}
|
||||
WindowMessage::Dragged(pane_grid::DragEvent::Dropped {
|
||||
|
|
@ -243,13 +245,6 @@ impl Application for Example {
|
|||
})
|
||||
}
|
||||
|
||||
fn windows(&self) -> Vec<(window::Id, iced::window::Settings)> {
|
||||
self.windows
|
||||
.iter()
|
||||
.map(|(&id, _window)| (id, iced::window::Settings::default()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn close_requested(&self, window: window::Id) -> Self::Message {
|
||||
Message::Window(window, WindowMessage::CloseWindow)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -515,7 +515,7 @@ async fn run_instance<A, E, C>(
|
|||
);
|
||||
|
||||
// Update window
|
||||
state.synchronize(&application, &windows, &proxy);
|
||||
state.synchronize(&application, &windows);
|
||||
|
||||
let should_exit = application.should_exit();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
use crate::application::{self, StyleSheet as _};
|
||||
use crate::conversion;
|
||||
use crate::multi_window::{Application, Event};
|
||||
use crate::multi_window::Application;
|
||||
use crate::window;
|
||||
use crate::{Color, Debug, Point, Size, Viewport};
|
||||
|
||||
use iced_winit::winit;
|
||||
use winit::event::{Touch, WindowEvent};
|
||||
use winit::event_loop::EventLoopProxy;
|
||||
use winit::window::Window;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
|
@ -189,28 +188,7 @@ where
|
|||
&mut self,
|
||||
application: &A,
|
||||
windows: &HashMap<window::Id, Window>,
|
||||
proxy: &EventLoopProxy<Event<A::Message>>,
|
||||
) {
|
||||
let new_windows = application.windows();
|
||||
|
||||
// Check for windows to close
|
||||
for window_id in windows.keys() {
|
||||
if !new_windows.iter().any(|(id, _)| id == window_id) {
|
||||
proxy
|
||||
.send_event(Event::CloseWindow(*window_id))
|
||||
.expect("Failed to send message");
|
||||
}
|
||||
}
|
||||
|
||||
// Check for windows to spawn
|
||||
for (id, settings) in new_windows {
|
||||
if !windows.contains_key(&id) {
|
||||
proxy
|
||||
.send_event(Event::NewWindow(id, settings))
|
||||
.expect("Failed to send message");
|
||||
}
|
||||
}
|
||||
|
||||
let window = windows.values().next().expect("No window found");
|
||||
|
||||
// Update window title
|
||||
|
|
|
|||
|
|
@ -46,9 +46,6 @@ pub trait Application: Sized {
|
|||
/// title of your application when necessary.
|
||||
fn title(&self) -> String;
|
||||
|
||||
/// TODO(derezzedex)
|
||||
fn windows(&self) -> Vec<(window::Id, window::Settings)>;
|
||||
|
||||
/// Handles a __message__ and updates the state of the [`Application`].
|
||||
///
|
||||
/// This is where you define your __update logic__. All the __messages__,
|
||||
|
|
@ -170,16 +167,6 @@ where
|
|||
self.0.title()
|
||||
}
|
||||
|
||||
fn windows(&self) -> Vec<(window::Id, iced_winit::settings::Window)> {
|
||||
self.0
|
||||
.windows()
|
||||
.into_iter()
|
||||
.map(|(id, settings)| {
|
||||
(id, iced_winit::settings::Window::from(settings))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
|
||||
self.0.update(message)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,9 +68,6 @@ where
|
|||
/// The type of __messages__ your [`Program`] will produce.
|
||||
type Message: std::fmt::Debug + Send;
|
||||
|
||||
/// TODO(derezzedex)
|
||||
fn windows(&self) -> Vec<(window::Id, settings::Window)>;
|
||||
|
||||
/// Handles a __message__ and updates the state of the [`Program`].
|
||||
///
|
||||
/// This is where you define your __update logic__. All the __messages__,
|
||||
|
|
@ -459,7 +456,7 @@ async fn run_instance<A, E, C>(
|
|||
);
|
||||
|
||||
// Update window
|
||||
state.synchronize(&application, &windows, &proxy);
|
||||
state.synchronize(&application, &windows);
|
||||
|
||||
let should_exit = application.should_exit();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
use crate::application::{self, StyleSheet as _};
|
||||
use crate::conversion;
|
||||
use crate::multi_window::{Application, Event};
|
||||
use crate::multi_window::Application;
|
||||
use crate::window;
|
||||
use crate::{Color, Debug, Point, Size, Viewport};
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::marker::PhantomData;
|
||||
use winit::event::{Touch, WindowEvent};
|
||||
use winit::event_loop::EventLoopProxy;
|
||||
use winit::window::Window;
|
||||
|
||||
/// The state of a windowed [`Application`].
|
||||
|
|
@ -186,28 +185,7 @@ where
|
|||
&mut self,
|
||||
application: &A,
|
||||
windows: &HashMap<window::Id, Window>,
|
||||
proxy: &EventLoopProxy<Event<A::Message>>,
|
||||
) {
|
||||
let new_windows = application.windows();
|
||||
|
||||
// Check for windows to close
|
||||
for window_id in windows.keys() {
|
||||
if !new_windows.iter().any(|(id, _)| id == window_id) {
|
||||
proxy
|
||||
.send_event(Event::CloseWindow(*window_id))
|
||||
.expect("Failed to send message");
|
||||
}
|
||||
}
|
||||
|
||||
// Check for windows to spawn
|
||||
for (id, settings) in new_windows {
|
||||
if !windows.contains_key(&id) {
|
||||
proxy
|
||||
.send_event(Event::NewWindow(id, settings))
|
||||
.expect("Failed to send message");
|
||||
}
|
||||
}
|
||||
|
||||
let window = windows.values().next().expect("No window found");
|
||||
|
||||
// Update window title
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue