mirror of
https://github.com/emilk/egui.git
synced 2026-06-27 23:13:13 -04:00
Shape refactor (#705)
* More introspection stats about vertices/indices etc * more serde derive * #[inline] to Shape constructors * Introduce RectShape * Introduce CircleShape * Introduce PathShape * More serde derive * impl Copy for RectShape and CircleShape * Simplify some code * More serde derive * Add helpers for appending more input or output * Serde derives for RawInput * Rename Fonts::from_definitions to Fonts::new * Add Output::take * refactor EguiGlium slightly * Derive PartialEq for RawInput * Improve egui::util::History interface * tweaks * Improve History filter: add minimum length * Calculate galley bounding rect * tessellator: cull line segments and paths * tessellator: cull meshes * Fix bug in History bandwidth estimator
This commit is contained in:
@@ -118,7 +118,6 @@ pub struct FontDefinitions {
|
||||
///
|
||||
/// `epaint` has built-in-default for these,
|
||||
/// but you can override them if you like.
|
||||
#[cfg_attr(feature = "persistence", serde(skip))]
|
||||
pub font_data: BTreeMap<String, FontData>,
|
||||
|
||||
/// Which fonts (names) to use for each [`FontFamily`].
|
||||
@@ -219,7 +218,7 @@ pub struct Fonts {
|
||||
}
|
||||
|
||||
impl Fonts {
|
||||
pub fn from_definitions(pixels_per_point: f32, definitions: FontDefinitions) -> Self {
|
||||
pub fn new(pixels_per_point: f32, definitions: FontDefinitions) -> Self {
|
||||
assert!(
|
||||
0.0 < pixels_per_point && pixels_per_point < 100.0,
|
||||
"pixels_per_point out of range: {}",
|
||||
@@ -278,6 +277,11 @@ impl Fonts {
|
||||
}
|
||||
}
|
||||
|
||||
#[deprecated = "Renamed to Fonts::new"]
|
||||
pub fn from_definitions(pixels_per_point: f32, definitions: FontDefinitions) -> Self {
|
||||
Self::new(pixels_per_point, definitions)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn pixels_per_point(&self) -> f32 {
|
||||
self.pixels_per_point
|
||||
|
||||
@@ -333,11 +333,13 @@ fn galley_from_rows(fonts: &Fonts, job: Arc<LayoutJob>, mut rows: Vec<Row>) -> G
|
||||
|
||||
let format_summary = format_summary(&job);
|
||||
|
||||
let mut mesh_bounds = Rect::NOTHING;
|
||||
let mut num_vertices = 0;
|
||||
let mut num_indices = 0;
|
||||
|
||||
for row in &mut rows {
|
||||
row.visuals = tessellate_row(fonts, &job, &format_summary, row);
|
||||
mesh_bounds = mesh_bounds.union(row.visuals.mesh_bounds);
|
||||
num_vertices += row.visuals.mesh.vertices.len();
|
||||
num_indices += row.visuals.mesh.indices.len();
|
||||
}
|
||||
@@ -348,6 +350,7 @@ fn galley_from_rows(fonts: &Fonts, job: Arc<LayoutJob>, mut rows: Vec<Row>) -> G
|
||||
job,
|
||||
rows,
|
||||
rect,
|
||||
mesh_bounds,
|
||||
num_vertices,
|
||||
num_indices,
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ use emath::*;
|
||||
///
|
||||
/// Pass this to [`Fonts::layout_job]` or [`crate::text::layout`].
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
|
||||
pub struct LayoutJob {
|
||||
/// The complete text of this job, referenced by `LayoutSection`.
|
||||
pub text: String, // TODO: Cow<'static, str>
|
||||
@@ -136,6 +137,7 @@ impl std::hash::Hash for LayoutJob {
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
|
||||
pub struct LayoutSection {
|
||||
/// Can be used for first row indentation.
|
||||
pub leading_space: f32,
|
||||
@@ -161,6 +163,7 @@ impl std::hash::Hash for LayoutSection {
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#[derive(Copy, Clone, Debug, Hash, PartialEq)]
|
||||
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
|
||||
pub struct TextFormat {
|
||||
pub style: TextStyle,
|
||||
/// Text color
|
||||
@@ -225,6 +228,10 @@ pub struct Galley {
|
||||
/// * [`Align::RIGHT`]: rect.right() == 0.0
|
||||
pub rect: Rect,
|
||||
|
||||
/// Tight bounding box around all the meshes in all the rows.
|
||||
/// Can be used for culling.
|
||||
pub mesh_bounds: Rect,
|
||||
|
||||
/// Total number of vertices in all the row meshes.
|
||||
pub num_vertices: usize,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user