Warn if using an TextShape
from before a change to pixels_per_point
Closes https://github.com/emilk/egui/issues/1915
This commit is contained in:
parent
9c58f12a6c
commit
39b63f6163
4 changed files with 23 additions and 0 deletions
|
@ -13,6 +13,11 @@ pub use crate::{CubicBezierShape, QuadraticBezierShape};
|
||||||
|
|
||||||
/// A paint primitive such as a circle or a piece of text.
|
/// A paint primitive such as a circle or a piece of text.
|
||||||
/// Coordinates are all screen space points (not physical pixels).
|
/// Coordinates are all screen space points (not physical pixels).
|
||||||
|
///
|
||||||
|
/// You should generally recreate your [`Shape`]s each frame,
|
||||||
|
/// but storing them should also be fine with one exception:
|
||||||
|
/// [`Shape::Text`] depends on the current `pixels_per_point` (dpi scale)
|
||||||
|
/// and so must be recreated every time `pixels_per_point` changes.
|
||||||
#[must_use = "Add a Shape to a Painter"]
|
#[must_use = "Add a Shape to a Painter"]
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum Shape {
|
pub enum Shape {
|
||||||
|
@ -37,6 +42,8 @@ pub enum Shape {
|
||||||
Rect(RectShape),
|
Rect(RectShape),
|
||||||
|
|
||||||
/// Text.
|
/// Text.
|
||||||
|
///
|
||||||
|
/// This needs to be recreated if `pixels_per_point` (dpi scale) changes.
|
||||||
Text(TextShape),
|
Text(TextShape),
|
||||||
|
|
||||||
/// A general triangle mesh.
|
/// A general triangle mesh.
|
||||||
|
@ -604,6 +611,8 @@ impl Rounding {
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
/// How to paint some text on screen.
|
/// How to paint some text on screen.
|
||||||
|
///
|
||||||
|
/// This needs to be recreated if `pixels_per_point` (dpi scale) changes.
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
pub struct TextShape {
|
pub struct TextShape {
|
||||||
|
|
|
@ -1334,6 +1334,11 @@ impl Tessellator {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if galley.pixels_per_point != self.pixels_per_point {
|
||||||
|
eprintln!("epaint: WARNING: pixels_per_point (dpi scale) have changed between text layout and tessellation. \
|
||||||
|
You must recreate your text shapes if pixels_per_point changes.");
|
||||||
|
}
|
||||||
|
|
||||||
out.vertices.reserve(galley.num_vertices);
|
out.vertices.reserve(galley.num_vertices);
|
||||||
out.indices.reserve(galley.num_indices);
|
out.indices.reserve(galley.num_indices);
|
||||||
|
|
||||||
|
|
|
@ -478,6 +478,7 @@ fn galley_from_rows(point_scale: PointScale, job: Arc<LayoutJob>, mut rows: Vec<
|
||||||
mesh_bounds,
|
mesh_bounds,
|
||||||
num_vertices,
|
num_vertices,
|
||||||
num_indices,
|
num_indices,
|
||||||
|
pixels_per_point: point_scale.pixels_per_point,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -309,6 +309,8 @@ impl Default for TextWrapping {
|
||||||
/// Text that has been layed out, ready for painting.
|
/// Text that has been layed out, ready for painting.
|
||||||
///
|
///
|
||||||
/// You can create a [`Galley`] using [`crate::Fonts::layout_job`];
|
/// You can create a [`Galley`] using [`crate::Fonts::layout_job`];
|
||||||
|
///
|
||||||
|
/// This needs to be recreated if `pixels_per_point` (dpi scale) changes.
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
pub struct Galley {
|
pub struct Galley {
|
||||||
|
@ -341,6 +343,12 @@ pub struct Galley {
|
||||||
|
|
||||||
/// Total number of indices in all the row meshes.
|
/// Total number of indices in all the row meshes.
|
||||||
pub num_indices: usize,
|
pub num_indices: usize,
|
||||||
|
|
||||||
|
/// The number of physical pixels for each logical point.
|
||||||
|
/// Since this affects the layout, we keep track of it
|
||||||
|
/// so that we can warn if this has changed once we get to
|
||||||
|
/// tessellation.
|
||||||
|
pub pixels_per_point: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
|
Loading…
Reference in a new issue