Browse Source

Add option to debug paint clip rects

pull/2/head
Emil Ernerfeldt 5 years ago
parent
commit
609473f85a
  1. 20
      emigui/src/emigui.rs
  2. 34
      emigui/src/mesher.rs

20
emigui/src/emigui.rs

@ -15,7 +15,7 @@ pub struct Emigui {
pub last_input: RawInput,
pub ctx: Arc<Context>,
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);
});

34
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;

Loading…
Cancel
Save