mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 21:30:03 -04:00
Fix mouse input
Now on Context.create_viewport in the render function will we have viewport_id and parent_viewport_id New problem if a windows is fucused and we interact with other window the first event will be send to the last window that was focused
This commit is contained in:
@@ -432,7 +432,7 @@ impl EpiIntegration {
|
||||
let saved_memory: egui::Memory = self.egui_ctx.memory(|mem| mem.clone());
|
||||
self.egui_ctx
|
||||
.memory_mut(|mem| mem.set_everything_is_visible(true));
|
||||
let full_output = self.update(app, window, egui_winit, None);
|
||||
let full_output = self.update(app, window, egui_winit, None, 0, 0);
|
||||
self.pending_full_output.append(full_output); // Handle it next frame
|
||||
self.egui_ctx.memory_mut(|mem| *mem = saved_memory); // We don't want to remember that windows were huge.
|
||||
self.egui_ctx.clear_animations();
|
||||
@@ -496,7 +496,9 @@ impl EpiIntegration {
|
||||
app: &mut dyn epi::App,
|
||||
window: &winit::window::Window,
|
||||
egui_winit: &mut egui_winit::State,
|
||||
render: Option<Arc<Box<dyn Fn(&Context) + Sync + Send>>>,
|
||||
render: Option<Arc<Box<dyn Fn(&Context, u64, u64) + Sync + Send>>>,
|
||||
viewport_id: u64,
|
||||
parent_id: u64,
|
||||
) -> egui::FullOutput {
|
||||
let frame_start = std::time::Instant::now();
|
||||
|
||||
@@ -511,7 +513,7 @@ impl EpiIntegration {
|
||||
let full_output = self.egui_ctx.run(raw_input, |egui_ctx| {
|
||||
crate::profile_scope!("App::update");
|
||||
if let Some(render) = render {
|
||||
(render.as_ref())(egui_ctx)
|
||||
(render.as_ref())(egui_ctx, viewport_id, parent_id)
|
||||
} else {
|
||||
app.update(egui_ctx, &mut self.frame);
|
||||
}
|
||||
|
||||
@@ -454,7 +454,8 @@ mod glow_integration {
|
||||
gl_surface: Option<glutin::surface::Surface<glutin::surface::WindowSurface>>,
|
||||
window: Option<winit::window::Window>,
|
||||
window_id: u64,
|
||||
render: Option<Arc<Box<dyn Fn(&Context) + Sync + Send>>>,
|
||||
parent_id: u64,
|
||||
render: Option<Arc<Box<dyn Fn(&Context, u64, u64) + Sync + Send>>>,
|
||||
pub egui_winit: Option<egui_winit::State>,
|
||||
}
|
||||
/// This struct will contain both persistent and temporary glutin state.
|
||||
@@ -603,6 +604,7 @@ mod glow_integration {
|
||||
window_id: 0,
|
||||
egui_winit: None,
|
||||
render: None,
|
||||
parent_id: 0,
|
||||
}],
|
||||
window_maps,
|
||||
})
|
||||
@@ -1007,6 +1009,13 @@ mod glow_integration {
|
||||
painter,
|
||||
} = running;
|
||||
|
||||
let mut window_map = HashMap::default();
|
||||
for window in gl_window.windows.iter() {
|
||||
if let Some(win) = &window.window {
|
||||
window_map.insert(window.window_id, win.id());
|
||||
}
|
||||
}
|
||||
|
||||
let egui::FullOutput {
|
||||
platform_output,
|
||||
repaint_after,
|
||||
@@ -1052,6 +1061,8 @@ mod glow_integration {
|
||||
win.window.as_ref().unwrap(),
|
||||
win.egui_winit.as_mut().unwrap(),
|
||||
win.render.clone(),
|
||||
win.window_id,
|
||||
win.parent_id,
|
||||
);
|
||||
|
||||
integration.handle_platform_output(
|
||||
@@ -1123,24 +1134,37 @@ mod glow_integration {
|
||||
}
|
||||
|
||||
control_flow = if integration.should_close() {
|
||||
EventResult::Exit
|
||||
} else if repaint_after.is_zero() {
|
||||
EventResult::RepaintNext(win.window.as_ref().unwrap().id())
|
||||
} else if let Some(repaint_after_instant) =
|
||||
std::time::Instant::now().checked_add(repaint_after)
|
||||
{
|
||||
// if repaint_after is something huge and can't be added to Instant,
|
||||
// we will use `ControlFlow::Wait` instead.
|
||||
// technically, this might lead to some weird corner cases where the user *WANTS*
|
||||
// winit to use `WaitUntil(MAX_INSTANT)` explicitly. they can roll their own
|
||||
// egui backend impl i guess.
|
||||
|
||||
EventResult::RepaintAt(
|
||||
win.window.as_ref().unwrap().id(),
|
||||
repaint_after_instant,
|
||||
)
|
||||
vec![EventResult::Exit]
|
||||
} else {
|
||||
EventResult::Wait
|
||||
repaint_after
|
||||
.into_iter()
|
||||
.map(|(id, time)| {
|
||||
if time.is_zero() {
|
||||
if let Some(id) = window_map.get(&id) {
|
||||
Some(EventResult::RepaintNext(*id))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else if let Some(repaint_after_instant) =
|
||||
std::time::Instant::now().checked_add(time)
|
||||
{
|
||||
// if repaint_after is something huge and can't be added to Instant,
|
||||
// we will use `ControlFlow::Wait` instead.
|
||||
// technically, this might lead to some weird corner cases where the user *WANTS*
|
||||
// winit to use `WaitUntil(MAX_INSTANT)` explicitly. they can roll their own
|
||||
// egui backend impl i guess.
|
||||
|
||||
if let Some(id) = window_map.get(&id) {
|
||||
Some(EventResult::RepaintAt(*id, repaint_after_instant))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.flatten()
|
||||
.collect::<Vec<EventResult>>()
|
||||
};
|
||||
|
||||
integration.maybe_autosave(app.as_mut(), win.window.as_ref().unwrap());
|
||||
@@ -1156,7 +1180,7 @@ mod glow_integration {
|
||||
// 0 is the main viewport/window that will not be known by the egui_ctx
|
||||
let mut active_viewports_ids = vec![0];
|
||||
|
||||
viewports.retain_mut(|(id, builder, render)| {
|
||||
viewports.retain_mut(|(id, parent, builder, render)| {
|
||||
for w in gl_window.windows.iter_mut() {
|
||||
if w.window_id == *id {
|
||||
if w.builder != *builder {
|
||||
@@ -1169,6 +1193,7 @@ mod glow_integration {
|
||||
w.gl_surface = None;
|
||||
w.render = Some(render.clone());
|
||||
w.builder = builder.clone();
|
||||
w.parent_id = *id;
|
||||
}
|
||||
active_viewports_ids.push(*id);
|
||||
return false;
|
||||
@@ -1177,7 +1202,7 @@ mod glow_integration {
|
||||
true
|
||||
});
|
||||
|
||||
for (id, builder, render) in viewports {
|
||||
for (id, parent, builder, render) in viewports {
|
||||
gl_window.windows.push(Window {
|
||||
builder,
|
||||
gl_surface: None,
|
||||
@@ -1185,6 +1210,7 @@ mod glow_integration {
|
||||
window_id: id,
|
||||
egui_winit: None,
|
||||
render: Some(render.clone()),
|
||||
parent_id: parent,
|
||||
});
|
||||
active_viewports_ids.push(id);
|
||||
}
|
||||
@@ -1199,10 +1225,15 @@ mod glow_integration {
|
||||
control_flow
|
||||
};
|
||||
|
||||
windows_indexes
|
||||
let mut events = vec![EventResult::Wait];
|
||||
|
||||
for event in windows_indexes
|
||||
.into_iter()
|
||||
.map(|window_index| inner(window_index))
|
||||
.collect()
|
||||
{
|
||||
events.extend(event)
|
||||
}
|
||||
events
|
||||
} else {
|
||||
vec![EventResult::Wait]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user