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

Fix some warnings

This commit is contained in:
Konkitoman
2023-07-28 18:28:16 +03:00
parent c56d09a2e5
commit bb0b80fb08
6 changed files with 77 additions and 111 deletions

View File

@@ -1147,7 +1147,10 @@ pub struct IntegrationInfo {
/// The OS native pixels-per-point /// The OS native pixels-per-point
pub native_pixels_per_point: Option<f32>, pub native_pixels_per_point: Option<f32>,
/// This is the id of the current native window
/// If this is the same as `parent_viewport` that means that is the main window
pub viewport_id: u64, pub viewport_id: u64,
/// This is the id of the current native window
pub parent_viewport: u64, pub parent_viewport: u64,
/// The position and size of the native window. /// The position and size of the native window.

View File

@@ -9,7 +9,7 @@ use raw_window_handle::{HasRawDisplayHandle as _, HasRawWindowHandle as _};
#[cfg(feature = "accesskit")] #[cfg(feature = "accesskit")]
use egui::accesskit; use egui::accesskit;
use egui::{epaint::ahash::HashMap, window::ViewportBuilder, Context, NumExt as _}; use egui::{window::ViewportBuilder, Context, NumExt as _};
#[cfg(feature = "accesskit")] #[cfg(feature = "accesskit")]
use egui_winit::accesskit_winit; use egui_winit::accesskit_winit;
use egui_winit::{native_pixels_per_point, EventResponse, WindowSettings}; use egui_winit::{native_pixels_per_point, EventResponse, WindowSettings};

View File

@@ -12,7 +12,7 @@ use winit::{
#[cfg(feature = "accesskit")] #[cfg(feature = "accesskit")]
use egui_winit::accesskit_winit; use egui_winit::accesskit_winit;
use egui_winit::{winit, EventResponse}; use egui_winit::winit;
use crate::{epi, Result}; use crate::{epi, Result};
@@ -192,7 +192,7 @@ fn run_and_return(
{ {
// This can happen if we close a window, and then reopen a new one, // This can happen if we close a window, and then reopen a new one,
// or if we have multiple windows open. // or if we have multiple windows open.
vec![EventResult::RepaintNext(window_id.clone())] vec![EventResult::RepaintNext(*window_id)]
} }
event => match winit_app.on_event(event_loop, event) { event => match winit_app.on_event(event_loop, event) {
@@ -416,18 +416,14 @@ fn run_and_exit(event_loop: EventLoop<UserEvent>, mut winit_app: impl WinitApp +
mod glow_integration { mod glow_integration {
use std::sync::Arc; use std::sync::Arc;
use egui::{epaint::ahash::HashMap, window::ViewportBuilder, Context, NumExt as _}; use egui::{epaint::ahash::HashMap, window::ViewportBuilder, NumExt as _, ViewportRender};
use egui_winit::EventResponse; use egui_winit::EventResponse;
use glow::HasContext;
use glutin::{ use glutin::{
display::GetGlDisplay, display::GetGlDisplay,
prelude::{GlDisplay, NotCurrentGlContextSurfaceAccessor, PossiblyCurrentGlContext}, prelude::{GlDisplay, NotCurrentGlContextSurfaceAccessor, PossiblyCurrentGlContext},
surface::GlSurface, surface::GlSurface,
}; };
use winit::{ use winit::{dpi::PhysicalSize, window::ResizeDirection};
dpi::{PhysicalPosition, PhysicalSize},
window::ResizeDirection,
};
use super::*; use super::*;
@@ -463,7 +459,7 @@ mod glow_integration {
window: Option<winit::window::Window>, window: Option<winit::window::Window>,
window_id: u64, window_id: u64,
parent_id: u64, parent_id: u64,
render: Option<Arc<Box<dyn Fn(&Context, u64, u64) + Sync + Send>>>, render: Option<Arc<Box<ViewportRender>>>,
pub egui_winit: Option<egui_winit::State>, pub egui_winit: Option<egui_winit::State>,
} }
/// This struct will contain both persistent and temporary glutin state. /// This struct will contain both persistent and temporary glutin state.
@@ -737,7 +733,7 @@ mod glow_integration {
.unwrap() .unwrap()
.make_not_current() .make_not_current()
.unwrap() .unwrap()
.make_current(&gl_surface) .make_current(gl_surface)
.unwrap(), .unwrap(),
); );
gl_surface.resize( gl_surface.resize(
@@ -856,10 +852,10 @@ mod glow_integration {
); );
#[cfg(feature = "accesskit")] #[cfg(feature = "accesskit")]
{ {
let mut window = &mut gl_window.windows[0]; let window = &mut gl_window.windows[0];
integration.init_accesskit( integration.init_accesskit(
&mut window.egui_winit.as_mut().unwrap(), window.egui_winit.as_mut().unwrap(),
&window.window.as_ref().unwrap(), window.window.as_ref().unwrap(),
self.repaint_proxy.lock().clone(), self.repaint_proxy.lock().clone(),
); );
} }
@@ -953,49 +949,40 @@ mod glow_integration {
} }
fn window(&self, window_id: winit::window::WindowId) -> Option<&winit::window::Window> { fn window(&self, window_id: winit::window::WindowId) -> Option<&winit::window::Window> {
self.running self.running.as_ref().and_then(|r| {
.as_ref() for window in r.gl_window.windows.iter() {
.map(|r| { if let Some(window) = &window.window {
for window in r.gl_window.windows.iter() { if window.id() == window_id {
if let Some(window) = &window.window { return Some(window);
if window.id() == window_id {
return Some(window);
}
} }
} }
None }
}) None
.flatten() })
} }
fn get_window_winit_id(&self, id: u64) -> Option<winit::window::WindowId> { fn get_window_winit_id(&self, id: u64) -> Option<winit::window::WindowId> {
self.running self.running.as_ref().and_then(|r| {
.as_ref() for window in r.gl_window.windows.iter() {
.map(|r| { if window.window_id == id {
for window in r.gl_window.windows.iter() { return window.window.as_ref().map(|w| w.id());
if window.window_id == id {
return window.window.as_ref().map(|w| w.id());
}
} }
None }
}) None
.flatten() })
} }
fn get_window_id(&self, id: &winit::window::WindowId) -> Option<u64> { fn get_window_id(&self, id: &winit::window::WindowId) -> Option<u64> {
self.running self.running.as_ref().and_then(|r| {
.as_ref() for window in r.gl_window.windows.iter() {
.map(|r| { if let Some(win) = &window.window {
for window in r.gl_window.windows.iter() { if win.id() == *id {
if let Some(win) = &window.window { return Some(window.window_id);
if win.id() == *id {
return Some(window.window_id);
}
} }
} }
None }
}) None
.flatten() })
} }
fn save_and_destroy(&mut self) { fn save_and_destroy(&mut self) {
@@ -1070,7 +1057,7 @@ mod glow_integration {
win.window.as_mut().unwrap().set_transparent(true); win.window.as_mut().unwrap().set_transparent(true);
egui_glow::painter::clear( egui_glow::painter::clear(
&gl, gl,
screen_size_in_pixels, screen_size_in_pixels,
app.clear_color(&integration.egui_ctx.style().visuals), app.clear_color(&integration.egui_ctx.style().visuals),
); );
@@ -1123,15 +1110,15 @@ mod glow_integration {
{ {
crate::profile_scope!("swap_buffers"); crate::profile_scope!("swap_buffers");
win.gl_surface let _ =
.as_ref() win.gl_surface
.expect("failed to get surface to swap buffers") .as_ref()
.swap_buffers( .expect("failed to get surface to swap buffers")
gl_window .swap_buffers(
.current_gl_context gl_window.current_gl_context.as_ref().expect(
.as_ref() "failed to get current context to swap buffers",
.expect("failed to get current context to swap buffers"), ),
); );
} }
integration.post_present(win.window.as_ref().unwrap()); integration.post_present(win.window.as_ref().unwrap());
@@ -1167,11 +1154,7 @@ mod glow_integration {
.into_iter() .into_iter()
.flat_map(|(id, time)| { .flat_map(|(id, time)| {
if time.is_zero() { if time.is_zero() {
if let Some(id) = window_map.get(&id) { window_map.get(&id).map(|id| EventResult::RepaintNext(*id))
Some(EventResult::RepaintNext(*id))
} else {
None
}
} else if let Some(repaint_after_instant) = } else if let Some(repaint_after_instant) =
std::time::Instant::now().checked_add(time) std::time::Instant::now().checked_add(time)
{ {
@@ -1181,11 +1164,9 @@ mod glow_integration {
// winit to use `WaitUntil(MAX_INSTANT)` explicitly. they can roll their own // winit to use `WaitUntil(MAX_INSTANT)` explicitly. they can roll their own
// egui backend impl i guess. // egui backend impl i guess.
if let Some(id) = window_map.get(&id) { window_map.get(&id).map(|id| {
Some(EventResult::RepaintAt(*id, repaint_after_instant)) EventResult::RepaintAt(*id, repaint_after_instant)
} else { })
None
}
} else { } else {
None None
} }
@@ -1206,7 +1187,7 @@ mod glow_integration {
// 0 is the main viewport/window that will not be known by the egui_ctx // 0 is the main viewport/window that will not be known by the egui_ctx
let mut active_viewports_ids = vec![0]; let mut active_viewports_ids = vec![0];
viewports.retain_mut(|(id, parent, builder, render)| { viewports.retain_mut(|(id, _, builder, render)| {
for w in gl_window.windows.iter_mut() { for w in gl_window.windows.iter_mut() {
if w.window_id == *id { if w.window_id == *id {
if w.builder != *builder { if w.builder != *builder {
@@ -1753,20 +1734,16 @@ mod wgpu_integration {
fn window(&self, window_id: winit::window::WindowId) -> Option<&winit::window::Window> { fn window(&self, window_id: winit::window::WindowId) -> Option<&winit::window::Window> {
self.running self.running
.as_ref() .as_ref()
.map(|r| r.windows_id.get(&window_id).map(|id| r.windows.get(id))) .and_then(|r| r.windows_id.get(&window_id).map(|id| r.windows.get(id)))
.flatten()
.flatten()
.map(|w| w.0.as_ref().map(|w| w))
.flatten() .flatten()
.and_then(|w| w.0.as_ref())
} }
fn get_window_winit_id(&self, id: u64) -> Option<winit::window::WindowId> { fn get_window_winit_id(&self, id: u64) -> Option<winit::window::WindowId> {
self.running self.running
.as_ref() .as_ref()
.map(|r| r.windows.get(&id)) .and_then(|r| r.windows.get(&id))
.flatten() .and_then(|w| w.0.as_ref().map(|w| w.id()))
.map(|w| w.0.as_ref().map(|w| w.id()))
.flatten()
} }
fn save_and_destroy(&mut self) { fn save_and_destroy(&mut self) {
@@ -1808,10 +1785,10 @@ mod wgpu_integration {
viewport_commands, viewport_commands,
}; };
{ {
let Some((viewport_id, (Some(window), Some(state), render, parent_viewport_id, _))) = windows_id.get(&window_id).map(|id|(windows.get_mut(id).map(|w|(*id, w)))).flatten() else{return vec![]}; let Some((viewport_id, (Some(window), Some(state), render, parent_viewport_id, _))) = windows_id.get(&window_id).and_then(|id|(windows.get_mut(id).map(|w|(*id, w)))) else{return vec![]};
integration.egui_ctx.set_current_viewport_id(viewport_id); integration.egui_ctx.set_current_viewport_id(viewport_id);
pollster::block_on(painter.set_window(viewport_id, Some(&window))); let _ = pollster::block_on(painter.set_window(viewport_id, Some(window)));
egui::FullOutput { egui::FullOutput {
platform_output, platform_output,
@@ -1939,7 +1916,7 @@ mod wgpu_integration {
}); });
} }
let Some((viewport_id, (Some(window), Some(state), render, parent_viewport_id, _))) = windows_id.get(&window_id).map(|id|(windows.get_mut(id).map(|w|(*id, w)))).flatten() else{return vec![]}; let Some((_, (Some(window), _, _, _, _))) = windows_id.get(&window_id).and_then(|id|(windows.get_mut(id).map(|w|(*id, w)))) else{return vec![]};
integration.maybe_autosave(app.as_mut(), window); integration.maybe_autosave(app.as_mut(), window);
if window.is_minimized() == Some(true) { if window.is_minimized() == Some(true) {
@@ -2070,23 +2047,21 @@ mod wgpu_integration {
_ => {} _ => {}
}; };
let event_response = let event_response = if let Some((id, (_, Some(state), _, _, _))) = running
if let Some((id, (Some(window), Some(state), _, _, _))) = running .windows_id
.windows_id .get(window_id)
.get(window_id) .and_then(|id| running.windows.get_mut(id).map(|w| (*id, w)))
.map(|id| running.windows.get_mut(id).map(|w| (*id, w))) {
.flatten() Some(running.integration.on_event(
{ running.app.as_mut(),
Some(running.integration.on_event( event,
running.app.as_mut(), window_id,
event, state,
window_id, id,
state, ))
id, } else {
)) None
} else { };
None
};
if running.integration.should_close() { if running.integration.should_close() {
EventResult::Exit EventResult::Exit
@@ -2115,8 +2090,7 @@ mod wgpu_integration {
if let Some((_, Some(state), _, _, _)) = running if let Some((_, Some(state), _, _, _)) = running
.windows_id .windows_id
.get(window_id) .get(window_id)
.map(|id| running.windows.get_mut(id)) .and_then(|id| running.windows.get_mut(id))
.flatten()
{ {
running.integration.on_accesskit_action_request( running.integration.on_accesskit_action_request(
request.clone(), request.clone(),

View File

@@ -180,16 +180,7 @@ struct ContextImpl {
repaint: Repaint, repaint: Repaint,
viewports: HashMap< viewports: HashMap<String, (ViewportBuilder, u64, u64, bool, Arc<Box<ViewportRender>>)>,
String,
(
ViewportBuilder,
u64,
u64,
bool,
Arc<Box<dyn Fn(&Context, u64, u64) + Sync + Send>>,
),
>,
viewport_commands: Vec<(u64, ViewportCommand)>, viewport_commands: Vec<(u64, ViewportCommand)>,
viewport_counter: u64, viewport_counter: u64,

View File

@@ -100,7 +100,7 @@ impl MyApp {
let threads = Vec::with_capacity(3); let threads = Vec::with_capacity(3);
let (on_done_tx, on_done_rc) = mpsc::sync_channel(0); let (on_done_tx, on_done_rc) = mpsc::sync_channel(0);
let mut slf = Self { let slf = Self {
data: Arc::new(RwLock::new(MyAppData { data: Arc::new(RwLock::new(MyAppData {
threads, threads,
on_done_tx, on_done_tx,

View File

@@ -2,12 +2,10 @@ use eframe::egui;
use eframe::egui::Id; use eframe::egui::Id;
use eframe::NativeOptions; use eframe::NativeOptions;
use std::sync::{Arc, RwLock};
fn main() { fn main() {
env_logger::init(); // Use `RUST_LOG=debug` to see logs. env_logger::init(); // Use `RUST_LOG=debug` to see logs.
eframe::run_simple_native( let _ = eframe::run_simple_native(
"Viewports Examples", "Viewports Examples",
NativeOptions { NativeOptions {
renderer: eframe::Renderer::Wgpu, renderer: eframe::Renderer::Wgpu,