From 065ace518cae7e51170e2ebee282839bc8a8b005 Mon Sep 17 00:00:00 2001 From: Sven Nilsen Date: Mon, 25 Jan 2016 13:24:45 +0100 Subject: [PATCH] Redesigned `CharacterCache` Closes https://github.com/PistonDevelopers/graphics/issues/1029 --- src/character.rs | 12 ++++++------ src/text.rs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/character.rs b/src/character.rs index 6c5cc27..5228e84 100644 --- a/src/character.rs +++ b/src/character.rs @@ -5,16 +5,16 @@ use ImageSize; /// Holds rendered character data. #[derive(Clone)] -pub struct Character { +pub struct Character<'a, T: 'a + ImageSize> { /// The offset of character. pub offset: [Scalar; 2], /// The size of character, including space. pub size: [Scalar; 2], /// The texture of the character. - pub texture: T, + pub texture: &'a T, } -impl Character { +impl<'a, T: ImageSize> Character<'a, T> { /// The left offset. pub fn left(&self) -> Scalar { self.offset[0] @@ -42,11 +42,11 @@ pub trait CharacterCache { type Texture: ImageSize; /// Get reference to character. - fn character( - &mut self, + fn character<'a>( + &'a mut self, font_size: FontSize, ch: char - ) -> &Character<::Texture>; + ) -> Character<'a, ::Texture>; /// Return the width for some given text. fn width(&mut self, size: FontSize, text: &str) -> ::math::Scalar { diff --git a/src/text.rs b/src/text.rs index 09e990b..898af8b 100644 --- a/src/text.rs +++ b/src/text.rs @@ -68,7 +68,7 @@ impl Text { ch_x = ch_x.round(); ch_y = ch_y.round(); } - image.draw(&character.texture, draw_state, transform.trans(ch_x, ch_y), g); + image.draw(character.texture, draw_state, transform.trans(ch_x, ch_y), g); x += character.width(); y += character.height(); }