1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 22:30:03 -04:00

Remove Rc<RefCell<…>>

This commit is contained in:
Emil Ernerfeldt
2023-11-11 20:06:44 +01:00
parent 3a87db2dc3
commit 7e96001f83

View File

@@ -885,7 +885,8 @@ mod glow_integration {
// re-initializing the `GlowWinitRunning` state on Android if the application // re-initializing the `GlowWinitRunning` state on Android if the application
// suspends and resumes. // suspends and resumes.
app_creator: Option<epi::AppCreator>, app_creator: Option<epi::AppCreator>,
focused_viewport: Rc<RefCell<Option<ViewportId>>>,
focused_viewport: Option<ViewportId>,
} }
impl GlowWinitApp { impl GlowWinitApp {
@@ -902,7 +903,7 @@ mod glow_integration {
native_options, native_options,
running: None, running: None,
app_creator: Some(app_creator), app_creator: Some(app_creator),
focused_viewport: Rc::new(RefCell::new(Some(ViewportId::ROOT))), focused_viewport: Some(ViewportId::ROOT),
} }
} }
@@ -1342,12 +1343,12 @@ mod glow_integration {
} }
fn is_focused(&self, window_id: winit::window::WindowId) -> bool { fn is_focused(&self, window_id: winit::window::WindowId) -> bool {
if let Some(is_focused) = self.focused_viewport.borrow().as_ref() { if let Some(focused_viewport) = self.focused_viewport {
if let Some(running) = self.running.as_ref() { if let Some(running) = self.running.as_ref() {
if let Some(window_id) = if let Some(window_id) =
running.glutin_ctx.borrow().viewport_maps.get(&window_id) running.glutin_ctx.borrow().viewport_maps.get(&window_id)
{ {
return *is_focused == *window_id; return focused_viewport == *window_id;
} }
} }
} }
@@ -1606,7 +1607,7 @@ mod glow_integration {
egui_winit::process_viewport_commands( egui_winit::process_viewport_commands(
vec![command], vec![command],
viewport_id, viewport_id,
*self.focused_viewport.borrow(), self.focused_viewport,
&window.borrow(), &window.borrow(),
); );
} }
@@ -1690,18 +1691,16 @@ mod glow_integration {
match &event { match &event {
winit::event::WindowEvent::Focused(new_focused) => { winit::event::WindowEvent::Focused(new_focused) => {
self.focused_viewport.replace( self.focused_viewport = new_focused
new_focused .then(|| {
.then(|| { running
running .glutin_ctx
.glutin_ctx .borrow_mut()
.borrow_mut() .viewport_maps
.viewport_maps .get(window_id)
.get(window_id) .copied()
.copied() })
}) .flatten();
.flatten(),
);
} }
winit::event::WindowEvent::Resized(physical_size) => { winit::event::WindowEvent::Resized(physical_size) => {
repaint_asap = true; repaint_asap = true;