Introduce window::Id to Event subscriptions

And remove `window::Id` from `Event` altogether.
This commit is contained in:
Héctor Ramón Jiménez 2024-06-04 23:20:33 +02:00
parent 49affc44ff
commit e400f972c1
No known key found for this signature in database
GPG key ID: 4C07CEC81AFA161F
19 changed files with 95 additions and 91 deletions

View file

@ -623,7 +623,6 @@ async fn run_instance<A, E, C>(
// Then, we can use the `interface_state` here to decide if a redraw
// is needed right away, or simply wait until a specific time.
let redraw_event = Event::Window(
window::Id::MAIN,
window::Event::RedrawRequested(Instant::now()),
);
@ -651,7 +650,11 @@ async fn run_instance<A, E, C>(
_ => ControlFlow::Wait,
});
runtime.broadcast(redraw_event, core::event::Status::Ignored);
runtime.broadcast(
redraw_event,
core::event::Status::Ignored,
window::Id::MAIN,
);
debug.draw_started();
let new_mouse_interaction = user_interface.draw(
@ -714,7 +717,6 @@ async fn run_instance<A, E, C>(
state.update(&window, &window_event, &mut debug);
if let Some(event) = conversion::window_event(
window::Id::MAIN,
window_event,
state.scale_factor(),
state.modifiers(),
@ -742,7 +744,7 @@ async fn run_instance<A, E, C>(
for (event, status) in
events.drain(..).zip(statuses.into_iter())
{
runtime.broadcast(event, status);
runtime.broadcast(event, status, window::Id::MAIN);
}
if !messages.is_empty()

View file

@ -126,7 +126,6 @@ pub fn window_attributes(
/// Converts a winit window event into an iced event.
pub fn window_event(
id: window::Id,
event: winit::event::WindowEvent,
scale_factor: f64,
modifiers: winit::keyboard::ModifiersState,
@ -137,16 +136,13 @@ pub fn window_event(
WindowEvent::Resized(new_size) => {
let logical_size = new_size.to_logical(scale_factor);
Some(Event::Window(
id,
window::Event::Resized {
width: logical_size.width,
height: logical_size.height,
},
))
Some(Event::Window(window::Event::Resized {
width: logical_size.width,
height: logical_size.height,
}))
}
WindowEvent::CloseRequested => {
Some(Event::Window(id, window::Event::CloseRequested))
Some(Event::Window(window::Event::CloseRequested))
}
WindowEvent::CursorMoved { position, .. } => {
let position = position.to_logical::<f64>(scale_factor);
@ -264,22 +260,19 @@ pub fn window_event(
self::modifiers(new_modifiers.state()),
)))
}
WindowEvent::Focused(focused) => Some(Event::Window(
id,
if focused {
window::Event::Focused
} else {
window::Event::Unfocused
},
)),
WindowEvent::Focused(focused) => Some(Event::Window(if focused {
window::Event::Focused
} else {
window::Event::Unfocused
})),
WindowEvent::HoveredFile(path) => {
Some(Event::Window(id, window::Event::FileHovered(path.clone())))
Some(Event::Window(window::Event::FileHovered(path.clone())))
}
WindowEvent::DroppedFile(path) => {
Some(Event::Window(id, window::Event::FileDropped(path.clone())))
Some(Event::Window(window::Event::FileDropped(path.clone())))
}
WindowEvent::HoveredFileCancelled => {
Some(Event::Window(id, window::Event::FilesHoveredLeft))
Some(Event::Window(window::Event::FilesHoveredLeft))
}
WindowEvent::Touch(touch) => {
Some(Event::Touch(touch_event(touch, scale_factor)))
@ -288,7 +281,7 @@ pub fn window_event(
let winit::dpi::LogicalPosition { x, y } =
position.to_logical(scale_factor);
Some(Event::Window(id, window::Event::Moved { x, y }))
Some(Event::Window(window::Event::Moved { x, y }))
}
_ => None,
}

View file

@ -492,13 +492,10 @@ async fn run_instance<A, E, C>(
let mut events = {
vec![(
Some(window::Id::MAIN),
core::Event::Window(
window::Id::MAIN,
window::Event::Opened {
position: main_window.position(),
size: main_window.size(),
},
),
core::Event::Window(window::Event::Opened {
position: main_window.position(),
size: main_window.size(),
}),
)]
};
@ -565,13 +562,10 @@ async fn run_instance<A, E, C>(
events.push((
Some(id),
core::Event::Window(
id,
window::Event::Opened {
position: window.position(),
size: window.size(),
},
),
core::Event::Window(window::Event::Opened {
position: window.position(),
size: window.size(),
}),
));
}
Event::EventLoopAwakened(event) => {
@ -623,7 +617,6 @@ async fn run_instance<A, E, C>(
// Then, we can use the `interface_state` here to decide if a redraw
// is needed right away, or simply wait until a specific time.
let redraw_event = core::Event::Window(
id,
window::Event::RedrawRequested(Instant::now()),
);
@ -665,6 +658,7 @@ async fn run_instance<A, E, C>(
runtime.broadcast(
redraw_event.clone(),
core::event::Status::Ignored,
id,
);
let _ = control_sender.start_send(Control::ChangeFlow(
@ -802,7 +796,7 @@ async fn run_instance<A, E, C>(
events.push((
None,
core::Event::Window(id, window::Event::Closed),
core::Event::Window(window::Event::Closed),
));
if window_manager.is_empty() {
@ -816,7 +810,6 @@ async fn run_instance<A, E, C>(
);
if let Some(event) = conversion::window_event(
id,
window_event,
window.state.scale_factor(),
window.state.modifiers(),
@ -874,7 +867,7 @@ async fn run_instance<A, E, C>(
.into_iter()
.zip(statuses.into_iter())
{
runtime.broadcast(event, status);
runtime.broadcast(event, status, id);
}
}