Add option to debug paint clip rects
This commit is contained in:
parent
ed67cc6e59
commit
609473f85a
2 changed files with 45 additions and 9 deletions
|
@ -15,7 +15,7 @@ pub struct Emigui {
|
||||||
pub last_input: RawInput,
|
pub last_input: RawInput,
|
||||||
pub ctx: Arc<Context>,
|
pub ctx: Arc<Context>,
|
||||||
stats: Stats,
|
stats: Stats,
|
||||||
anti_alias: bool,
|
mesher_options: MesherOptions,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Emigui {
|
impl Emigui {
|
||||||
|
@ -24,7 +24,7 @@ impl Emigui {
|
||||||
last_input: Default::default(),
|
last_input: Default::default(),
|
||||||
ctx: Arc::new(Context::new(pixels_per_point)),
|
ctx: Arc::new(Context::new(pixels_per_point)),
|
||||||
stats: Default::default(),
|
stats: Default::default(),
|
||||||
anti_alias: true,
|
mesher_options: MesherOptions::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,12 +60,9 @@ impl Emigui {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn paint(&mut self) -> PaintBatches {
|
pub fn paint(&mut self) -> PaintBatches {
|
||||||
let mesher_options = MesherOptions {
|
self.mesher_options.aa_size = 1.0 / self.last_input.pixels_per_point;
|
||||||
anti_alias: self.anti_alias,
|
|
||||||
aa_size: 1.0 / self.last_input.pixels_per_point,
|
|
||||||
};
|
|
||||||
let paint_commands = self.ctx.drain_paint_lists();
|
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 = Default::default();
|
||||||
self.stats.num_batches = batches.len();
|
self.stats.num_batches = batches.len();
|
||||||
for (_, mesh) in &batches {
|
for (_, mesh) in &batches {
|
||||||
|
@ -77,7 +74,14 @@ impl Emigui {
|
||||||
|
|
||||||
pub fn ui(&mut self, region: &mut Region) {
|
pub fn ui(&mut self, region: &mut Region) {
|
||||||
region.foldable("Style", |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);
|
self.ctx.style_ui(region);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,13 @@
|
||||||
#![allow(clippy::identity_op)]
|
#![allow(clippy::identity_op)]
|
||||||
|
|
||||||
/// Outputs render info in a format suitable for e.g. OpenGL.
|
/// 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);
|
const WHITE_UV: (u16, u16) = (1, 1);
|
||||||
|
|
||||||
|
@ -239,6 +245,17 @@ use self::PathType::*;
|
||||||
pub struct MesherOptions {
|
pub struct MesherOptions {
|
||||||
pub anti_alias: bool,
|
pub anti_alias: bool,
|
||||||
pub aa_size: f32,
|
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(
|
pub fn fill_closed_path(
|
||||||
|
@ -506,6 +523,21 @@ pub fn mesh_paint_commands(
|
||||||
|
|
||||||
if batches.is_empty() || batches.last().unwrap().0 != clip_rect {
|
if batches.is_empty() || batches.last().unwrap().0 != clip_rect {
|
||||||
batches.push((clip_rect, Mesh::default()));
|
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;
|
let out_mesh = &mut batches.last_mut().unwrap().1;
|
||||||
|
|
Loading…
Reference in a new issue