Skip to content

Commit

Permalink
Fix text renderer (#131)
Browse files Browse the repository at this point in the history
fix glyph cache layout

The row height was never summed to itself so from the third row
onwards would appear in the same height as the second row

The code is therefore simplied to always track the `max_height`
attained by any given glyph

Fixes #112
  • Loading branch information
Uriopass authored Dec 21, 2023
1 parent 6427909 commit 6485906
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions crates/yakui-widgets/src/text_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct GlyphCache {
pub texture_size: UVec2,
glyphs: HashMap<GlyphRasterConfig, URect>,
next_pos: UVec2,
row_height: u32,
max_height: u32,
}

impl GlyphCache {
Expand Down Expand Up @@ -60,14 +60,12 @@ impl GlyphCache {

let glyph_max = self.next_pos + glyph_size;
let pos = if glyph_max.x < self.texture_size.x {
let pos = self.next_pos;
self.row_height = self.row_height.max(glyph_size.y + 1);
pos
self.next_pos
} else {
let pos = UVec2::new(0, self.row_height);
self.row_height = 0;
pos
UVec2::new(0, self.max_height)
};

self.max_height = self.max_height.max(pos.y + glyph_size.y + 1);
self.next_pos = pos + UVec2::new(glyph_size.x + 1, 0);

let size = texture.size();
Expand Down Expand Up @@ -111,7 +109,7 @@ impl TextGlobalState {
texture: None,
glyphs: HashMap::new(),
next_pos: UVec2::ONE,
row_height: 0,
max_height: 0,

// Not initializing to zero to avoid divide by zero issues if we do
// intialize the texture incorrectly.
Expand Down

0 comments on commit 6485906

Please sign in to comment.