Skip to content

Commit

Permalink
update egui to 0.26.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Baezon committed Mar 3, 2024
1 parent 6981ce3 commit 02e56bb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "egui_glium"
version = "0.23.0"
version = "0.26.2"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
description = "Bindings for using egui natively using the glium library"
edition = "2021"
Expand Down Expand Up @@ -29,25 +29,25 @@ links = ["egui-winit/links"]


[dependencies]
egui = { version = "0.23.0", default-features = false, features = [
egui = { version = "0.26.2", default-features = false, features = [
"bytemuck",
"default_fonts"
] }
egui-winit = { version = "0.23.0", default-features = false }
egui-winit = { version = "0.26.2", default-features = false }

ahash = { version = "0.8.1", default-features = false, features = [
"no-rng", # we don't need DOS-protection, so we let users opt-in to it instead
"std",
] }
bytemuck = "1.7"
glium = "0.33"
winit = "0.28"
glium = "0.34"
winit = "0.29"

#! ### Optional dependencies
## Enable this when generating docs.
document-features = { version = "0.2", optional = true }


[dev-dependencies]
egui_demo_lib = { version = "0.23.0", default-features = false }
egui_demo_lib = { version = "0.26.2", default-features = false }
image = { version = "0.24", default-features = false, features = ["png"] }
47 changes: 27 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pub use egui_winit::EventResponse;

/// Convenience wrapper for using [`egui`] from a [`glium`] app.
pub struct EguiGlium {
pub egui_ctx: egui::Context,
pub egui_winit: egui_winit::State,
pub painter: crate::Painter,

Expand All @@ -35,53 +34,59 @@ pub struct EguiGlium {

impl EguiGlium {
pub fn new<E>(
viewport_id: egui::ViewportId,
display: &glium::Display<WindowSurface>,
window: &winit::window::Window,
event_loop: &EventLoopWindowTarget<E>,
) -> Self {
let painter = crate::Painter::new(display);

let mut egui_winit = egui_winit::State::new(event_loop);
egui_winit.set_max_texture_side(painter.max_texture_side());
let pixels_per_point = window.scale_factor() as f32;
egui_winit.set_pixels_per_point(pixels_per_point);
let egui_winit = egui_winit::State::new(
Default::default(),
viewport_id,
event_loop,
Some(pixels_per_point),
Some(painter.max_texture_side()),
);

Self {
egui_ctx: Default::default(),
egui_winit,
painter,
shapes: Default::default(),
textures_delta: Default::default(),
}
}

pub fn on_event(&mut self, event: &winit::event::WindowEvent<'_>) -> EventResponse {
self.egui_winit.on_event(&self.egui_ctx, event)
pub fn egui_ctx(&self) -> &egui::Context {
self.egui_winit.egui_ctx()
}

/// Returns `true` if egui requests a repaint.
///
/// Call [`Self::paint`] later to paint.
pub fn run(
pub fn on_event(
&mut self,
window: &winit::window::Window,
run_ui: impl FnMut(&egui::Context),
) -> std::time::Duration {
event: &winit::event::WindowEvent,
) -> EventResponse {
self.egui_winit.on_window_event(window, event)
}

/// Runs the main egui render.
///
/// Call [`Self::paint`] later to paint.
pub fn run(&mut self, window: &winit::window::Window, run_ui: impl FnMut(&egui::Context)) {
let raw_input = self.egui_winit.take_egui_input(window);
let egui::FullOutput {
platform_output,
repaint_after,
textures_delta,
shapes,
} = self.egui_ctx.run(raw_input, run_ui);
..
} = self.egui_ctx().run(raw_input, run_ui);

self.egui_winit
.handle_platform_output(window, &self.egui_ctx, platform_output);
.handle_platform_output(window, platform_output);

self.shapes = shapes;
self.textures_delta.append(textures_delta);

repaint_after
}

/// Paint the results of the last call to [`Self::run`].
Expand All @@ -92,11 +97,13 @@ impl EguiGlium {
) {
let shapes = std::mem::take(&mut self.shapes);
let textures_delta = std::mem::take(&mut self.textures_delta);
let clipped_primitives = self.egui_ctx.tessellate(shapes);
let clipped_primitives = self
.egui_ctx()
.tessellate(shapes, self.egui_ctx().pixels_per_point());
self.painter.paint_and_update_textures(
display,
target,
self.egui_ctx.pixels_per_point(),
self.egui_ctx().pixels_per_point(),
&clipped_primitives,
&textures_delta,
);
Expand Down

0 comments on commit 02e56bb

Please sign in to comment.