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

Shape refactor (#705)

* More introspection stats about vertices/indices etc

* more serde derive

* #[inline] to Shape constructors

* Introduce RectShape

* Introduce CircleShape

* Introduce PathShape

* More serde derive

* impl Copy for RectShape and CircleShape

* Simplify some code

* More serde derive

* Add helpers for appending more input or output

* Serde derives for RawInput

* Rename Fonts::from_definitions to Fonts::new

* Add Output::take

* refactor EguiGlium slightly

* Derive PartialEq for RawInput

* Improve egui::util::History interface

* tweaks

* Improve History filter: add minimum length

* Calculate galley bounding rect

* tessellator: cull line segments and paths

* tessellator: cull meshes

* Fix bug in History bandwidth estimator
This commit is contained in:
Emil Ernerfeldt
2021-09-20 21:36:56 +02:00
committed by GitHub
parent 93c2fde1fc
commit e7cfda4941
36 changed files with 578 additions and 313 deletions

View File

@@ -34,7 +34,6 @@ use {
};
pub use copypasta::ClipboardContext;
use std::borrow::BorrowMut; // TODO: remove
pub struct GliumInputState {
pub pointer_pos_in_points: Option<Pos2>,
@@ -556,10 +555,21 @@ impl EguiGlium {
&self.egui_ctx
}
pub fn painter_mut(&mut self) -> &mut crate::Painter {
&mut self.painter
}
pub fn ctx_and_painter_mut(&mut self) -> (&egui::CtxRef, &mut crate::Painter) {
(&self.egui_ctx, &mut self.painter)
}
pub fn pixels_per_point(&self) -> f32 {
self.input_state
.raw
.pixels_per_point
.unwrap_or_else(|| self.egui_ctx.pixels_per_point())
}
pub fn on_event(&mut self, event: &glium::glutin::event::WindowEvent<'_>) {
crate::input_to_egui(
self.egui_ctx.pixels_per_point(),
@@ -575,13 +585,19 @@ impl EguiGlium {
}
pub fn begin_frame(&mut self, display: &glium::Display) {
let pixels_per_point = self
.input_state
.raw
.pixels_per_point
.unwrap_or_else(|| self.egui_ctx.pixels_per_point());
let raw_input = self.take_raw_input(display);
self.begin_frame_with_input(raw_input);
}
self.input_state.raw.time = Some(self.start_time.elapsed().as_nanos() as f64 * 1e-9);
pub fn begin_frame_with_input(&mut self, raw_input: RawInput) {
self.egui_ctx.begin_frame(raw_input);
}
/// Prepare for a new frame. Normally you would call [`Self::begin_frame`] instead.
pub fn take_raw_input(&mut self, display: &glium::Display) -> egui::RawInput {
let pixels_per_point = self.pixels_per_point();
self.input_state.raw.time = Some(self.start_time.elapsed().as_secs_f64());
// On Windows, a minimized window will have 0 width and height.
// See: https://github.com/rust-windowing/winit/issues/208
@@ -596,7 +612,7 @@ impl EguiGlium {
None
};
self.egui_ctx.begin_frame(self.input_state.raw.take());
self.input_state.raw.take()
}
/// Returns `needs_repaint` and shapes to draw.
@@ -605,10 +621,16 @@ impl EguiGlium {
display: &glium::Display,
) -> (bool, Vec<egui::epaint::ClippedShape>) {
let (egui_output, shapes) = self.egui_ctx.end_frame();
let needs_repaint = egui_output.needs_repaint;
self.handle_output(display, egui_output);
(needs_repaint, shapes)
}
pub fn handle_output(&mut self, display: &glium::Display, egui_output: egui::Output) {
if self.egui_ctx.memory().options.screen_reader {
self.screen_reader.speak(&egui_output.events_description());
}
if self.current_cursor_icon != egui_output.cursor_icon {
// call only when changed to prevent flickering near frame boundary
// when Windows OS tries to control cursor icon for window resizing
@@ -616,11 +638,7 @@ impl EguiGlium {
self.current_cursor_icon = egui_output.cursor_icon;
}
let needs_repaint = egui_output.needs_repaint;
handle_output(egui_output, self.clipboard.as_mut(), display);
(needs_repaint, shapes)
}
pub fn paint<T: glium::Surface>(
@@ -638,8 +656,4 @@ impl EguiGlium {
&self.egui_ctx.texture(),
);
}
pub fn painter_mut(&mut self) -> &mut Painter {
self.painter.borrow_mut()
}
}