chore: minor cleanups of text layout code
This commit is contained in:
parent
6f318242d7
commit
b33f85c2f8
|
@ -117,7 +117,7 @@ pub fn layout(self: *Chunk, opts: LayoutOptions) void {
|
|||
if (should_wrap) {
|
||||
cursor.y += self.offsetLineByHeight(line_start_idx, i).y_offset;
|
||||
line_start_idx = i;
|
||||
if (cursor.x > self.size.width) self.size.width = @intCast(cursor.x);
|
||||
self.size.width = @max(self.size.width, @as(u31, @intCast(cursor.x)));
|
||||
cursor.x = -span.span.origin_off.x;
|
||||
}
|
||||
|
||||
|
@ -132,11 +132,11 @@ pub fn layout(self: *Chunk, opts: LayoutOptions) void {
|
|||
cursor.y += last_metrics.y_offset;
|
||||
|
||||
self.size.height = @intCast(cursor.y + last_metrics.bottom_padding);
|
||||
if (cursor.x > self.size.width) self.size.width = @intCast(cursor.x);
|
||||
self.size.width = @max(self.size.width, @as(u31, @intCast(cursor.x)));
|
||||
}
|
||||
|
||||
/// Offsets all chunks in the given range downwards by their line y_offset and returns that line's
|
||||
/// height metrics..
|
||||
/// height metrics.
|
||||
fn offsetLineByHeight(self: *const Chunk, start_idx: usize, end_idx: usize) zenolith.text.HeightMetrics {
|
||||
var max = zenolith.text.HeightMetrics{
|
||||
.y_offset = 0,
|
||||
|
|
|
@ -77,7 +77,7 @@ pub fn updateGlyphs(
|
|||
}
|
||||
}
|
||||
|
||||
/// Positions the glyphs of the span and sets baseline_y.
|
||||
/// Positions the glyphs of the span and sets origin_off.
|
||||
pub fn layout(self: *Span) void {
|
||||
var cursor = Position.zero;
|
||||
var min_y: i32 = 0;
|
||||
|
@ -85,18 +85,16 @@ pub fn layout(self: *Span) void {
|
|||
for (self.glyphs.items) |*pglyph| {
|
||||
pglyph.position = cursor.add(pglyph.glyph.bearing);
|
||||
|
||||
if (pglyph.glyph.bearing.y < min_y) min_y = pglyph.glyph.bearing.y;
|
||||
min_y = @min(min_y, pglyph.glyph.bearing.y);
|
||||
|
||||
cursor.x += pglyph.glyph.advance;
|
||||
}
|
||||
|
||||
//for (self.glyphs.items) |*pglyph| {
|
||||
// pglyph.position.y -= min_y;
|
||||
//}
|
||||
self.origin_off = .{
|
||||
.x = if (self.glyphs.items.len > 0) self.glyphs.items[0].position.x else 0,
|
||||
.y = -min_y,
|
||||
};
|
||||
|
||||
self.origin_off = if (self.glyphs.items.len > 0) self.glyphs.items[0].position else Position.zero;
|
||||
self.origin_off.y = -min_y;
|
||||
//self.baseline_y = @intCast(-min_y);
|
||||
self.baseline_width = @intCast(cursor.x);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue