diff --git a/emigui/src/emigui.rs b/emigui/src/emigui.rs index 53a02420..0fcc5d71 100644 --- a/emigui/src/emigui.rs +++ b/emigui/src/emigui.rs @@ -15,7 +15,7 @@ pub struct Emigui { pub last_input: RawInput, pub ctx: Arc, stats: Stats, - anti_alias: bool, + mesher_options: MesherOptions, } impl Emigui { @@ -24,7 +24,7 @@ impl Emigui { last_input: Default::default(), ctx: Arc::new(Context::new(pixels_per_point)), stats: Default::default(), - anti_alias: true, + mesher_options: MesherOptions::default(), } } @@ -60,12 +60,9 @@ impl Emigui { } pub fn paint(&mut self) -> PaintBatches { - let mesher_options = MesherOptions { - anti_alias: self.anti_alias, - aa_size: 1.0 / self.last_input.pixels_per_point, - }; + self.mesher_options.aa_size = 1.0 / self.last_input.pixels_per_point; let paint_commands = self.ctx.drain_paint_lists(); - let batches = mesh_paint_commands(&mesher_options, &self.ctx.fonts, paint_commands); + let batches = mesh_paint_commands(&self.mesher_options, &self.ctx.fonts, paint_commands); self.stats = Default::default(); self.stats.num_batches = batches.len(); for (_, mesh) in &batches { @@ -77,7 +74,14 @@ impl Emigui { pub fn ui(&mut self, region: &mut Region) { region.foldable("Style", |region| { - region.add(Checkbox::new(&mut self.anti_alias, "Antialias")); + region.add(Checkbox::new( + &mut self.mesher_options.anti_alias, + "Antialias", + )); + region.add(Checkbox::new( + &mut self.mesher_options.debug_paint_clip_rects, + "Paint Clip Rects (debug)", + )); self.ctx.style_ui(region); }); diff --git a/emigui/src/mesher.rs b/emigui/src/mesher.rs index dd9ed81d..695ea02f 100644 --- a/emigui/src/mesher.rs +++ b/emigui/src/mesher.rs @@ -1,7 +1,13 @@ #![allow(clippy::identity_op)] /// Outputs render info in a format suitable for e.g. OpenGL. -use crate::{color::Color, fonts::Fonts, math::*, types::PaintCmd}; +use crate::{ + color::{srgba, Color}, + fonts::Fonts, + math::*, + types::PaintCmd, + Outline, +}; const WHITE_UV: (u16, u16) = (1, 1); @@ -239,6 +245,17 @@ use self::PathType::*; pub struct MesherOptions { pub anti_alias: bool, pub aa_size: f32, + pub debug_paint_clip_rects: bool, +} + +impl Default for MesherOptions { + fn default() -> Self { + Self { + anti_alias: true, + aa_size: 1.0, + debug_paint_clip_rects: false, + } + } } pub fn fill_closed_path( @@ -506,6 +523,21 @@ pub fn mesh_paint_commands( if batches.is_empty() || batches.last().unwrap().0 != clip_rect { batches.push((clip_rect, Mesh::default())); + + if options.debug_paint_clip_rects && !clip_rect.is_empty() { + let out_mesh = &mut batches.last_mut().unwrap().1; + mesh_command( + options, + fonts, + PaintCmd::Rect { + rect: clip_rect, + corner_radius: 0.0, + fill_color: Some(srgba(50, 100, 200, 64)), + outline: Some(Outline::new(1.0, srgba(200, 200, 200, 255))), + }, + out_mesh, + ) + } } let out_mesh = &mut batches.last_mut().unwrap().1;