mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40:03 -04:00
[epaint] Replace tuple (Rect, Shape) with tuple-struct ClippedShape
This commit is contained in:
@@ -61,7 +61,7 @@ pub use {
|
||||
shape::Shape,
|
||||
stats::PaintStats,
|
||||
stroke::Stroke,
|
||||
tessellator::{PaintJob, PaintJobs, TessellationOptions},
|
||||
tessellator::TessellationOptions,
|
||||
text::{Galley, TextStyle},
|
||||
texture_atlas::{Texture, TextureAtlas},
|
||||
triangles::{Triangles, Vertex},
|
||||
@@ -101,3 +101,21 @@ pub(crate) struct PaintRect {
|
||||
pub fill: Color32,
|
||||
pub stroke: Stroke,
|
||||
}
|
||||
|
||||
/// A [`Shape`] within a clip rectangle.
|
||||
///
|
||||
/// Everything is using logical points.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ClippedShape(
|
||||
/// Clip / scissor rectangle.
|
||||
/// Only show the part of the [`shape`] that falls within this.
|
||||
pub emath::Rect,
|
||||
/// The shape
|
||||
pub Shape,
|
||||
);
|
||||
|
||||
/// A clip triangle and some textured triangles, all in points (logical pixels).
|
||||
pub type PaintJob = (emath::Rect, Triangles);
|
||||
|
||||
/// Grouped by clip rectangles, in points (logical pixels).
|
||||
pub type PaintJobs = Vec<PaintJob>;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use {crate::*, emath::*};
|
||||
use crate::*;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
enum ElementSize {
|
||||
@@ -146,13 +146,13 @@ pub struct PaintStats {
|
||||
}
|
||||
|
||||
impl PaintStats {
|
||||
pub fn from_shapes(shapes: &[(Rect, Shape)]) -> Self {
|
||||
pub fn from_shapes(shapes: &[ClippedShape]) -> Self {
|
||||
let mut stats = Self::default();
|
||||
stats.shape_path.element_size = ElementSize::Heterogenous; // nicer display later
|
||||
stats.shape_vec.element_size = ElementSize::Heterogenous; // nicer display later
|
||||
|
||||
stats.shapes = AllocInfo::from_slice(shapes);
|
||||
for (_, shape) in shapes {
|
||||
for ClippedShape(_, shape) in shapes {
|
||||
stats.add(shape);
|
||||
}
|
||||
stats
|
||||
|
||||
@@ -9,12 +9,6 @@ use crate::{text::Fonts, *};
|
||||
use emath::*;
|
||||
use std::f32::consts::TAU;
|
||||
|
||||
/// A clip triangle and some textured triangles.
|
||||
pub type PaintJob = (Rect, Triangles);
|
||||
|
||||
/// Grouped by clip rectangles, in pixel coordinates
|
||||
pub type PaintJobs = Vec<PaintJob>;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
@@ -670,14 +664,14 @@ impl Tessellator {
|
||||
/// ## Returns
|
||||
/// A list of clip rectangles with matching [`Triangles`].
|
||||
pub fn tessellate_shapes(
|
||||
shapes: Vec<(Rect, Shape)>,
|
||||
shapes: Vec<ClippedShape>,
|
||||
options: TessellationOptions,
|
||||
fonts: &Fonts,
|
||||
) -> Vec<(Rect, Triangles)> {
|
||||
let mut tessellator = Tessellator::from_options(options);
|
||||
|
||||
let mut jobs = PaintJobs::default();
|
||||
for (clip_rect, shape) in shapes {
|
||||
for ClippedShape(clip_rect, shape) in shapes {
|
||||
let start_new_job = match jobs.last() {
|
||||
None => true,
|
||||
Some(job) => job.0 != clip_rect || job.1.texture_id != shape.texture_id(),
|
||||
|
||||
@@ -29,7 +29,7 @@ pub struct Triangles {
|
||||
/// The vertex data indexed by `indices`.
|
||||
pub vertices: Vec<Vertex>,
|
||||
|
||||
/// The texture to use when drawing these triangles
|
||||
/// The texture to use when drawing these triangles.
|
||||
pub texture_id: TextureId,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user