From 13d0753d977456a7fea4632565606f95567a47bf Mon Sep 17 00:00:00 2001 From: Olivier Pinon Date: Thu, 22 Oct 2020 00:27:29 +0200 Subject: [PATCH] Update to match new asset server --- crates/bevy_text/src/draw.rs | 6 +++--- crates/bevy_text/src/font_atlas_set.rs | 3 ++- crates/bevy_text/src/glyph_brush.rs | 4 ++-- crates/bevy_text/src/pipeline.rs | 12 ++++++------ crates/bevy_ui/src/widget/text.rs | 4 ++-- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/crates/bevy_text/src/draw.rs b/crates/bevy_text/src/draw.rs index fd5d36057c9bb..6813b4d869d7a 100644 --- a/crates/bevy_text/src/draw.rs +++ b/crates/bevy_text/src/draw.rs @@ -170,7 +170,7 @@ impl<'a> Drawable for TextDrawer<'a> { fn draw(&mut self, draw: &mut Draw, context: &mut DrawContext) -> Result<(), DrawError> { context.set_pipeline( draw, - bevy_sprite::SPRITE_SHEET_PIPELINE_HANDLE, + &bevy_sprite::SPRITE_SHEET_PIPELINE_HANDLE, &PipelineSpecialization { sample_count: self.msaa.samples, ..Default::default() @@ -179,13 +179,13 @@ impl<'a> Drawable for TextDrawer<'a> { let render_resource_context = &**context.render_resource_context; if let Some(RenderResourceId::Buffer(quad_vertex_buffer)) = render_resource_context - .get_asset_resource(bevy_sprite::QUAD_HANDLE, mesh::VERTEX_BUFFER_ASSET_INDEX) + .get_asset_resource(&bevy_sprite::QUAD_HANDLE, mesh::VERTEX_BUFFER_ASSET_INDEX) { draw.set_vertex_buffer(0, quad_vertex_buffer, 0); } let mut indices = 0..0; if let Some(RenderResourceId::Buffer(quad_index_buffer)) = render_resource_context - .get_asset_resource(bevy_sprite::QUAD_HANDLE, mesh::INDEX_BUFFER_ASSET_INDEX) + .get_asset_resource(&bevy_sprite::QUAD_HANDLE, mesh::INDEX_BUFFER_ASSET_INDEX) { draw.set_index_buffer(quad_index_buffer, 0); if let Some(buffer_info) = render_resource_context.get_buffer_info(quad_index_buffer) { diff --git a/crates/bevy_text/src/font_atlas_set.rs b/crates/bevy_text/src/font_atlas_set.rs index 95c01ec77e5c6..d2e72e94ee6a4 100644 --- a/crates/bevy_text/src/font_atlas_set.rs +++ b/crates/bevy_text/src/font_atlas_set.rs @@ -6,6 +6,7 @@ use bevy_math::Vec2; use bevy_render::texture::Texture; use bevy_sprite::TextureAtlas; use bevy_utils::HashMap; +use bevy_type_registry::TypeUuid; type FontSizeKey = FloatOrd; @@ -103,7 +104,7 @@ impl FontAtlasSet { .find_map(|atlas| { atlas .get_glyph_index(glyph_id) - .map(|glyph_index| (glyph_index, atlas.texture_atlas)) + .map(|glyph_index| (glyph_index, atlas.texture_atlas.clone_weak())) }) .map(|(glyph_index, texture_atlas)| GlyphAtlasInfo { texture_atlas, diff --git a/crates/bevy_text/src/glyph_brush.rs b/crates/bevy_text/src/glyph_brush.rs index 2f6d2ae614921..584d0f339c1ac 100644 --- a/crates/bevy_text/src/glyph_brush.rs +++ b/crates/bevy_text/src/glyph_brush.rs @@ -81,8 +81,8 @@ impl GlyphBrush { let mut vertices = Vec::new(); for glyph in glyphs { println!("processing a glyph: {:?}", glyph); - let handle = self.handles[glyph.font_id.0]; - let handle_font_atlas = Handle::::from(handle.id); + let handle = &self.handles[glyph.font_id.0]; + let handle_font_atlas: Handle = handle.as_weak(); let font_atlas_set = font_atlas_set_storage .get_or_insert_with(handle_font_atlas, || FontAtlasSet::default()); let position = glyph.glyph.position; diff --git a/crates/bevy_text/src/pipeline.rs b/crates/bevy_text/src/pipeline.rs index bdcbdb9b6d3e0..2869494f08d87 100644 --- a/crates/bevy_text/src/pipeline.rs +++ b/crates/bevy_text/src/pipeline.rs @@ -28,13 +28,13 @@ impl Default for TextPipeline { impl TextPipeline { pub fn measure( &mut self, - font_handle: &Handle, + font_handle: Handle, font_storage: &Assets, text: &str, size: f32, bounds: Size, ) -> Result { - let font = font_storage.get(font_handle).ok_or(TextError::NoSuchFont)?; + let font = font_storage.get(font_handle.clone()).ok_or(TextError::NoSuchFont)?; let font_id = self.get_or_insert_font_id(font_handle, font); let section = glyph_brush_layout::SectionText { @@ -56,23 +56,23 @@ impl TextPipeline { todo!() } - pub fn get_or_insert_font_id(&mut self, handle: &Handle, font: &Font) -> FontId { + pub fn get_or_insert_font_id(&mut self, handle: Handle, font: &Font) -> FontId { self.map_font_id - .entry(*handle) + .entry(handle.clone()) .or_insert(self.brush.add_font(handle.clone(), font.font.clone())) .clone() } pub fn queue_text( &mut self, - font_handle: &Handle, + font_handle: Handle, font_storage: &Assets, text: &str, size: f32, bounds: Size, screen_position: Vec2, ) -> Result<(), TextError> { - let font = font_storage.get(font_handle).ok_or(TextError::NoSuchFont)?; + let font = font_storage.get(font_handle.clone()).ok_or(TextError::NoSuchFont)?; let font_id = self.get_or_insert_font_id(font_handle, font); println!("the font id is {:?}", font_id); diff --git a/crates/bevy_ui/src/widget/text.rs b/crates/bevy_ui/src/widget/text.rs index b7e1bc052da31..30601808afb58 100644 --- a/crates/bevy_ui/src/widget/text.rs +++ b/crates/bevy_ui/src/widget/text.rs @@ -42,9 +42,9 @@ pub fn text_system( } */ println!("Queing text : {}", &text.value); - let screen_position = trans.translation(); + let screen_position = trans.translation; if let Err(e) = text_pipeline.queue_text( - &text.font, + text.font.clone(), &fonts, &text.value, text.style.font_size,