add window::Id to view
This commit is contained in:
parent
01bad4f896
commit
2fe58e1261
2 changed files with 35 additions and 12 deletions
|
|
@ -88,7 +88,10 @@ pub trait Application: Sized {
|
||||||
/// Returns the widgets to display in the [`Application`].
|
/// Returns the widgets to display in the [`Application`].
|
||||||
///
|
///
|
||||||
/// These widgets can produce __messages__ based on user interaction.
|
/// These widgets can produce __messages__ based on user interaction.
|
||||||
fn view(&self) -> Element<'_, Self::Message, crate::Renderer<Self::Theme>>;
|
fn view(
|
||||||
|
&self,
|
||||||
|
window: window::Id,
|
||||||
|
) -> Element<'_, Self::Message, crate::Renderer<Self::Theme>>;
|
||||||
|
|
||||||
/// Returns the scale factor of the [`Application`].
|
/// Returns the scale factor of the [`Application`].
|
||||||
///
|
///
|
||||||
|
|
@ -178,8 +181,11 @@ where
|
||||||
self.0.update(message)
|
self.0.update(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view(&self) -> Element<'_, Self::Message, Self::Renderer> {
|
fn view(
|
||||||
self.0.view()
|
&self,
|
||||||
|
window: window::Id,
|
||||||
|
) -> Element<'_, Self::Message, Self::Renderer> {
|
||||||
|
self.0.view(window)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn theme(&self) -> A::Theme {
|
fn theme(&self) -> A::Theme {
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,10 @@ where
|
||||||
/// Returns the widgets to display in the [`Program`].
|
/// Returns the widgets to display in the [`Program`].
|
||||||
///
|
///
|
||||||
/// These widgets can produce __messages__ based on user interaction.
|
/// These widgets can produce __messages__ based on user interaction.
|
||||||
fn view(&self) -> Element<'_, Self::Message, Self::Renderer>;
|
fn view(
|
||||||
|
&self,
|
||||||
|
window: window::Id,
|
||||||
|
) -> Element<'_, Self::Message, Self::Renderer>;
|
||||||
|
|
||||||
/// Initializes the [`Application`] with the flags provided to
|
/// Initializes the [`Application`] with the flags provided to
|
||||||
/// [`run`] as part of the [`Settings`].
|
/// [`run`] as part of the [`Settings`].
|
||||||
|
|
@ -331,6 +334,7 @@ async fn run_instance<A, E, C>(
|
||||||
&mut renderer,
|
&mut renderer,
|
||||||
state.logical_size(),
|
state.logical_size(),
|
||||||
&mut debug,
|
&mut debug,
|
||||||
|
id,
|
||||||
);
|
);
|
||||||
|
|
||||||
let window_state: WindowState<A, C> = WindowState { surface, state };
|
let window_state: WindowState<A, C> = WindowState { surface, state };
|
||||||
|
|
@ -354,6 +358,7 @@ async fn run_instance<A, E, C>(
|
||||||
&mut proxy,
|
&mut proxy,
|
||||||
&mut debug,
|
&mut debug,
|
||||||
&windows,
|
&windows,
|
||||||
|
&window_ids,
|
||||||
|| compositor.fetch_information(),
|
|| compositor.fetch_information(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -369,10 +374,8 @@ async fn run_instance<A, E, C>(
|
||||||
match event {
|
match event {
|
||||||
event::Event::MainEventsCleared => {
|
event::Event::MainEventsCleared => {
|
||||||
for id in states.keys().copied().collect::<Vec<_>>() {
|
for id in states.keys().copied().collect::<Vec<_>>() {
|
||||||
let (filtered, remaining): (Vec<_>, Vec<_>) = events
|
let (filtered, remaining): (Vec<_>, Vec<_>) =
|
||||||
.iter()
|
events.iter().cloned().partition(
|
||||||
.cloned()
|
|
||||||
.partition(
|
|
||||||
|(window_id, _event): &(
|
|(window_id, _event): &(
|
||||||
Option<crate::window::Id>,
|
Option<crate::window::Id>,
|
||||||
iced_native::event::Event,
|
iced_native::event::Event,
|
||||||
|
|
@ -382,7 +385,10 @@ async fn run_instance<A, E, C>(
|
||||||
);
|
);
|
||||||
|
|
||||||
events.retain(|el| remaining.contains(el));
|
events.retain(|el| remaining.contains(el));
|
||||||
let filtered: Vec<_> = filtered.into_iter().map(|(_id, event)| event.clone()).collect();
|
let filtered: Vec<_> = filtered
|
||||||
|
.into_iter()
|
||||||
|
.map(|(_id, event)| event)
|
||||||
|
.collect();
|
||||||
|
|
||||||
let cursor_position =
|
let cursor_position =
|
||||||
states.get(&id).unwrap().state.cursor_position();
|
states.get(&id).unwrap().state.cursor_position();
|
||||||
|
|
@ -407,7 +413,8 @@ async fn run_instance<A, E, C>(
|
||||||
|
|
||||||
debug.event_processing_finished();
|
debug.event_processing_finished();
|
||||||
|
|
||||||
for event in filtered.into_iter().zip(statuses.into_iter()) {
|
for event in filtered.into_iter().zip(statuses.into_iter())
|
||||||
|
{
|
||||||
runtime.broadcast(event);
|
runtime.broadcast(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -444,6 +451,7 @@ async fn run_instance<A, E, C>(
|
||||||
&mut debug,
|
&mut debug,
|
||||||
&mut messages,
|
&mut messages,
|
||||||
&windows,
|
&windows,
|
||||||
|
&window_ids,
|
||||||
|| compositor.fetch_information(),
|
|| compositor.fetch_information(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -489,7 +497,7 @@ async fn run_instance<A, E, C>(
|
||||||
mouse_interaction = new_mouse_interaction;
|
mouse_interaction = new_mouse_interaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
for window in windows.values(){
|
for window in windows.values() {
|
||||||
window.request_redraw();
|
window.request_redraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -530,6 +538,7 @@ async fn run_instance<A, E, C>(
|
||||||
&mut renderer,
|
&mut renderer,
|
||||||
state.logical_size(),
|
state.logical_size(),
|
||||||
&mut debug,
|
&mut debug,
|
||||||
|
id,
|
||||||
);
|
);
|
||||||
|
|
||||||
let window_state: WindowState<A, C> =
|
let window_state: WindowState<A, C> =
|
||||||
|
|
@ -707,12 +716,13 @@ pub fn build_user_interface<'a, A: Application>(
|
||||||
renderer: &mut A::Renderer,
|
renderer: &mut A::Renderer,
|
||||||
size: Size,
|
size: Size,
|
||||||
debug: &mut Debug,
|
debug: &mut Debug,
|
||||||
|
id: window::Id,
|
||||||
) -> UserInterface<'a, A::Message, A::Renderer>
|
) -> UserInterface<'a, A::Message, A::Renderer>
|
||||||
where
|
where
|
||||||
<A::Renderer as crate::Renderer>::Theme: StyleSheet,
|
<A::Renderer as crate::Renderer>::Theme: StyleSheet,
|
||||||
{
|
{
|
||||||
debug.view_started();
|
debug.view_started();
|
||||||
let view = application.view();
|
let view = application.view(id);
|
||||||
debug.view_finished();
|
debug.view_finished();
|
||||||
|
|
||||||
debug.layout_started();
|
debug.layout_started();
|
||||||
|
|
@ -735,6 +745,7 @@ pub fn update<A: Application, E: Executor>(
|
||||||
debug: &mut Debug,
|
debug: &mut Debug,
|
||||||
messages: &mut Vec<A::Message>,
|
messages: &mut Vec<A::Message>,
|
||||||
windows: &HashMap<window::Id, winit::window::Window>,
|
windows: &HashMap<window::Id, winit::window::Window>,
|
||||||
|
window_ids: &HashMap<winit::window::WindowId, window::Id>,
|
||||||
graphics_info: impl FnOnce() -> compositor::Information + Copy,
|
graphics_info: impl FnOnce() -> compositor::Information + Copy,
|
||||||
) where
|
) where
|
||||||
<A::Renderer as crate::Renderer>::Theme: StyleSheet,
|
<A::Renderer as crate::Renderer>::Theme: StyleSheet,
|
||||||
|
|
@ -757,6 +768,7 @@ pub fn update<A: Application, E: Executor>(
|
||||||
proxy,
|
proxy,
|
||||||
debug,
|
debug,
|
||||||
windows,
|
windows,
|
||||||
|
window_ids,
|
||||||
graphics_info,
|
graphics_info,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -777,6 +789,7 @@ pub fn run_command<A, E>(
|
||||||
proxy: &mut winit::event_loop::EventLoopProxy<Event<A::Message>>,
|
proxy: &mut winit::event_loop::EventLoopProxy<Event<A::Message>>,
|
||||||
debug: &mut Debug,
|
debug: &mut Debug,
|
||||||
windows: &HashMap<window::Id, winit::window::Window>,
|
windows: &HashMap<window::Id, winit::window::Window>,
|
||||||
|
window_ids: &HashMap<winit::window::WindowId, window::Id>,
|
||||||
_graphics_info: impl FnOnce() -> compositor::Information + Copy,
|
_graphics_info: impl FnOnce() -> compositor::Information + Copy,
|
||||||
) where
|
) where
|
||||||
A: Application,
|
A: Application,
|
||||||
|
|
@ -787,7 +800,9 @@ pub fn run_command<A, E>(
|
||||||
use iced_native::system;
|
use iced_native::system;
|
||||||
use iced_native::window;
|
use iced_native::window;
|
||||||
|
|
||||||
|
// TODO(derezzedex)
|
||||||
let window = windows.values().next().expect("No window found");
|
let window = windows.values().next().expect("No window found");
|
||||||
|
let id = *window_ids.get(&window.id()).unwrap();
|
||||||
|
|
||||||
for action in command.actions() {
|
for action in command.actions() {
|
||||||
match action {
|
match action {
|
||||||
|
|
@ -868,6 +883,7 @@ pub fn run_command<A, E>(
|
||||||
renderer,
|
renderer,
|
||||||
state.logical_size(),
|
state.logical_size(),
|
||||||
debug,
|
debug,
|
||||||
|
id,
|
||||||
);
|
);
|
||||||
|
|
||||||
while let Some(mut operation) = current_operation.take() {
|
while let Some(mut operation) = current_operation.take() {
|
||||||
|
|
@ -933,6 +949,7 @@ where
|
||||||
renderer,
|
renderer,
|
||||||
state.logical_size(),
|
state.logical_size(),
|
||||||
debug,
|
debug,
|
||||||
|
id,
|
||||||
);
|
);
|
||||||
|
|
||||||
let _ = interfaces.insert(id, user_interface);
|
let _ = interfaces.insert(id, user_interface);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue