Skip to content

Commit

Permalink
Redesigned CharacterCache
Browse files Browse the repository at this point in the history
  • Loading branch information
bvssvni committed Jan 25, 2016
1 parent 10ae2d0 commit 065ace5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/character.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ use ImageSize;

/// Holds rendered character data.
#[derive(Clone)]
pub struct Character<T: ImageSize> {
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<T: ImageSize> Character<T> {
impl<'a, T: ImageSize> Character<'a, T> {
/// The left offset.
pub fn left(&self) -> Scalar {
self.offset[0]
Expand Down Expand Up @@ -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<<Self as CharacterCache>::Texture>;
) -> Character<'a, <Self as CharacterCache>::Texture>;

/// Return the width for some given text.
fn width(&mut self, size: FontSize, text: &str) -> ::math::Scalar {
Expand Down
2 changes: 1 addition & 1 deletion src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 065ace5

Please # to comment.