Skip to content

Commit

Permalink
Rename "vertices" to "glyphs"
Browse files Browse the repository at this point in the history
  • Loading branch information
AlisCode committed Nov 11, 2020
1 parent c36a9e3 commit ec390ae
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
6 changes: 3 additions & 3 deletions crates/bevy_text/src/draw.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::TextVertices;
use crate::TextGlyphs;
use bevy_math::{Mat4, Vec3};
use bevy_render::{
color::Color,
Expand Down Expand Up @@ -51,7 +51,7 @@ pub struct DrawableText<'a> {
pub asset_render_resource_bindings: &'a mut AssetRenderResourceBindings,
pub position: Vec3,
pub style: &'a TextStyle,
pub text_vertices: &'a TextVertices,
pub text_glyphs: &'a TextGlyphs,
pub msaa: &'a Msaa,
pub font_quad_vertex_descriptor: &'a VertexBufferDescriptor,
}
Expand Down Expand Up @@ -93,7 +93,7 @@ impl<'a> Drawable for DrawableText<'a> {
// set global bindings
context.set_bind_groups_from_bindings(draw, &mut [self.render_resource_bindings])?;

for tv in &**self.text_vertices {
for tv in &**self.text_glyphs {
let atlas_render_resource_bindings = self
.asset_render_resource_bindings
.get_mut(&tv.atlas_info.texture_atlas)
Expand Down
20 changes: 10 additions & 10 deletions crates/bevy_text/src/glyph_brush.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ impl GlyphBrush {
) -> Result<Vec<PositionedGlyph>, TextError> {
let mut sq = self.section_queue.lock();
let sq = std::mem::replace(&mut *sq, Vec::new());
let vertices = sq
let glyphs = sq
.into_iter()
.map(|section_glyphs| {
if section_glyphs.is_empty() {
return Ok(Vec::new());
}
let mut vertices = Vec::new();
let mut glyphs = Vec::new();
let sg = section_glyphs.first().unwrap();
let mut min_x: f32 = sg.glyph.position.x;
let mut max_y: f32 = sg.glyph.position.y;
Expand Down Expand Up @@ -123,19 +123,19 @@ impl GlyphBrush {
let y = max_y - bounds.max.y + glyph_height / 2.0 + 0.5;
let position = Vec2::new(x, y);

vertices.push(PositionedGlyph {
glyphs.push(PositionedGlyph {
position,
atlas_info,
});
}
}
Ok(vertices)
Ok(glyphs)
})
.collect::<Result<Vec<_>, TextError>>()?
.into_iter()
.flatten()
.collect();
Ok(vertices)
Ok(glyphs)
}

pub fn add_font(&mut self, handle: Handle<Font>, font: FontArc) -> FontId {
Expand All @@ -154,18 +154,18 @@ pub struct PositionedGlyph {
}

#[derive(Debug, Default, Clone)]
pub struct TextVertices(Vec<PositionedGlyph>);
pub struct TextGlyphs(Vec<PositionedGlyph>);

impl std::ops::Deref for TextVertices {
impl std::ops::Deref for TextGlyphs {
type Target = Vec<PositionedGlyph>;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl TextVertices {
pub fn set(&mut self, vertices: Vec<PositionedGlyph>) {
self.0 = vertices;
impl std::ops::DerefMut for TextGlyphs {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
6 changes: 3 additions & 3 deletions crates/bevy_ui/src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use bevy_render::{
pipeline::{RenderPipeline, RenderPipelines},
};
use bevy_sprite::{ColorMaterial, QUAD_HANDLE};
use bevy_text::TextVertices;
use bevy_text::TextGlyphs;
use bevy_transform::prelude::{GlobalTransform, Transform};

#[derive(Bundle, Clone, Debug)]
Expand Down Expand Up @@ -89,7 +89,7 @@ pub struct TextComponents {
pub focus_policy: FocusPolicy,
pub transform: Transform,
pub global_transform: GlobalTransform,
pub text_vertices: TextVertices,
pub text_glyphs: TextGlyphs,
}

impl Default for TextComponents {
Expand All @@ -106,7 +106,7 @@ impl Default for TextComponents {
style: Default::default(),
transform: Default::default(),
global_transform: Default::default(),
text_vertices: Default::default(),
text_glyphs: Default::default(),
}
}
}
Expand Down
20 changes: 11 additions & 9 deletions crates/bevy_ui/src/widget/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use bevy_render::{
texture::Texture,
};
use bevy_sprite::{TextureAtlas, QUAD_HANDLE};
use bevy_text::{DrawableText, Font, FontAtlasSet, TextPipeline, TextStyle, TextVertices};
use bevy_text::{DrawableText, Font, FontAtlasSet, TextGlyphs, TextPipeline, TextStyle};
use bevy_transform::prelude::GlobalTransform;

#[derive(Debug, Default)]
Expand Down Expand Up @@ -38,8 +38,8 @@ pub fn text_constraint(min_size: Val, size: Val, max_size: Val) -> f32 {
}
}

/// Computes the size of a text block and updates the TextVertices with the
/// new computed vertices
/// Computes the size of a text block and updates the TextGlyphs with the
/// new computed glyphs from the layout
pub fn text_system(
mut textures: ResMut<Assets<Texture>>,
fonts: Res<Assets<Font>>,
Expand All @@ -48,11 +48,11 @@ pub fn text_system(
mut text_pipeline: ResMut<TextPipeline>,
mut text_query: Query<(
Or<(Changed<Text>, Changed<Style>)>,
&mut TextVertices,
&mut TextGlyphs,
&mut CalculatedSize,
)>,
) {
for ((text, style), mut vertices, mut calculated_size) in text_query.iter_mut() {
for ((text, style), mut glyphs, mut calculated_size) in text_query.iter_mut() {
let node_size = Size::new(
text_constraint(style.min_size.width, style.size.width, style.max_size.width),
text_constraint(
Expand Down Expand Up @@ -89,7 +89,9 @@ pub fn text_system(
&mut textures,
) {
Err(e) => println!("Error when drawing text: {:?}", e),
Ok(new_vertices) => vertices.set(new_vertices),
Ok(new_glyphs) => {
**glyphs = new_glyphs;
}
}
}
}
Expand All @@ -101,20 +103,20 @@ pub fn draw_text_system(
meshes: Res<Assets<Mesh>>,
mut render_resource_bindings: ResMut<RenderResourceBindings>,
mut asset_render_resource_bindings: ResMut<AssetRenderResourceBindings>,
mut query: Query<(&mut Draw, &Text, &TextVertices, &Node, &GlobalTransform)>,
mut query: Query<(&mut Draw, &Text, &TextGlyphs, &Node, &GlobalTransform)>,
) {
let font_quad = meshes.get(&QUAD_HANDLE).unwrap();
let vertex_buffer_descriptor = font_quad.get_vertex_buffer_descriptor();

for (mut draw, text, text_vertices, node, global_transform) in query.iter_mut() {
for (mut draw, text, text_glyphs, node, global_transform) in query.iter_mut() {
let position = global_transform.translation - (node.size / 2.0).extend(0.0);

let mut drawable_text = DrawableText {
render_resource_bindings: &mut render_resource_bindings,
asset_render_resource_bindings: &mut asset_render_resource_bindings,
position,
msaa: &msaa,
text_vertices,
text_glyphs,
font_quad_vertex_descriptor: &vertex_buffer_descriptor,
style: &text.style,
};
Expand Down

0 comments on commit ec390ae

Please sign in to comment.