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

Reducing glutin dependency in egui_glow (#1151)

Use winit wherever possible
This commit is contained in:
triangle drawer
2022-01-25 01:08:27 +09:00
committed by GitHub
parent fa43d16c41
commit 9d596967b4
4 changed files with 28 additions and 31 deletions

View File

@@ -88,6 +88,8 @@
#![allow(clippy::manual_range_contains)]
pub mod painter;
#[cfg(feature = "winit")]
use egui_winit::winit;
pub use glow;
pub use painter::Painter;
#[cfg(feature = "winit")]
@@ -119,10 +121,7 @@ pub struct EguiGlow {
#[cfg(feature = "winit")]
impl EguiGlow {
pub fn new(
gl_window: &glutin::WindowedContext<glutin::PossiblyCurrent>,
gl: &glow::Context,
) -> Self {
pub fn new(window: &winit::window::Window, gl: &glow::Context) -> Self {
let painter = crate::Painter::new(gl, None, "")
.map_err(|error| {
crate::misc_util::glow_print_error(format!(
@@ -134,7 +133,7 @@ impl EguiGlow {
Self {
egui_ctx: Default::default(),
egui_winit: egui_winit::State::new(painter.max_texture_side(), gl_window.window()),
egui_winit: egui_winit::State::new(painter.max_texture_side(), window),
painter,
shapes: Default::default(),
textures_delta: Default::default(),
@@ -147,7 +146,7 @@ impl EguiGlow {
/// and only when this returns `false` pass on the events to your game.
///
/// Note that egui uses `tab` to move focus between elements, so this will always return `true` for tabs.
pub fn on_event(&mut self, event: &glutin::event::WindowEvent<'_>) -> bool {
pub fn on_event(&mut self, event: &winit::event::WindowEvent<'_>) -> bool {
self.egui_winit.on_event(&self.egui_ctx, event)
}
@@ -156,7 +155,7 @@ impl EguiGlow {
/// Call [`Self::paint`] later to paint.
pub fn run(
&mut self,
window: &glutin::window::Window,
window: &winit::window::Window,
run_ui: impl FnMut(&egui::Context),
) -> bool {
let raw_input = self.egui_winit.take_egui_input(window);
@@ -172,11 +171,7 @@ impl EguiGlow {
}
/// Paint the results of the last call to [`Self::run`].
pub fn paint(
&mut self,
gl_window: &glutin::WindowedContext<glutin::PossiblyCurrent>,
gl: &glow::Context,
) {
pub fn paint(&mut self, window: &winit::window::Window, gl: &glow::Context) {
let shapes = std::mem::take(&mut self.shapes);
let mut textures_delta = std::mem::take(&mut self.textures_delta);
@@ -185,7 +180,7 @@ impl EguiGlow {
}
let clipped_meshes = self.egui_ctx.tessellate(shapes);
let dimensions: [u32; 2] = gl_window.window().inner_size().into();
let dimensions: [u32; 2] = window.inner_size().into();
self.painter.paint_meshes(
gl,
dimensions,