From d6e232b3f76633fb8e3a45893946b024b6d5be53 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sat, 4 Jan 2025 10:13:30 -0500 Subject: [PATCH] Fixed ui rendering issue with getting vertical metrics unscaled. --- code/font/vefontcache/vefontcache.odin | 9 +++++---- code/sectr/engine/render.odin | 10 +++++----- code/sectr/font/provider.odin | 2 +- code/sectr/ui/core/layout_compute.odin | 8 ++++---- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/code/font/vefontcache/vefontcache.odin b/code/font/vefontcache/vefontcache.odin index 4572d3c..174c0ec 100644 --- a/code/font/vefontcache/vefontcache.odin +++ b/code/font/vefontcache/vefontcache.odin @@ -613,17 +613,18 @@ measure_text_size :: #force_inline proc( ctx : ^Context, font : Font_ID, px_size return shaped.size } -get_font_vertical_metrics :: #force_inline proc ( ctx : ^Context, font : Font_ID ) -> ( ascent, descent, line_gap : f32 ) +get_font_vertical_metrics :: #force_inline proc ( ctx : ^Context, font : Font_ID, px_szie : f32 ) -> ( ascent, descent, line_gap : f32 ) { assert( ctx != nil ) assert( font >= 0 && int(font) < len(ctx.entries) ) entry := & ctx.entries[ font ] // ascent_i32, descent_i32, line_gap_i32 := parser_get_font_vertical_metrics( entry.parser_info ) + font_scale := parser_scale( entry.parser_info, px_szie ) - ascent = entry.ascent - descent = entry.descent - line_gap = entry.line_gap + ascent = font_scale * entry.ascent + descent = font_scale * entry.descent + line_gap = font_scale * entry.line_gap return } diff --git a/code/sectr/engine/render.odin b/code/sectr/engine/render.odin index 753b036..80bdcf3 100644 --- a/code/sectr/engine/render.odin +++ b/code/sectr/engine/render.odin @@ -937,7 +937,7 @@ draw_text_shape_pos_norm :: #force_inline proc( shape : ShapedText, id : FontID, ve_id, resolved_size := font_provider_resolve_draw_id( id, font_size * config.font_size_screen_scalar ) color_norm := normalize_rgba8(color) - screen_size_norm := Vec2{1 / width, 1 / height} + screen_size_norm := Vec2 { 1 / width, 1 / height } ve.set_colour( & font_provider_ctx.ve_ctx, color_norm ) ve.draw_text_shape( & font_provider_ctx.ve_ctx, ve_id, f32(resolved_size), pos, screen_size_norm * scale * (1 / config.font_size_screen_scalar), shape ) @@ -977,10 +977,10 @@ draw_text_string_pos_extent_zoomed :: #force_inline proc( text : string, id : Fo text_scale : Vec2 = screen_size_norm // if config.cam_zoom_mode == .Smooth { - diff_scalar := 1 + (zoom_adjust_size - f32_resolved_size) / f32_resolved_size - text_scale = diff_scalar * screen_size_norm - text_scale.x = clamp( text_scale.x, 0, screen_size.x ) - text_scale.y = clamp( text_scale.y, 0, screen_size.y ) + diff_scalar := 1 + (zoom_adjust_size - f32_resolved_size) / f32_resolved_size + text_scale = diff_scalar * screen_size_norm + text_scale.x = clamp( text_scale.x, 0, screen_size.x ) + text_scale.y = clamp( text_scale.y, 0, screen_size.y ) } // Down-sample back diff --git a/code/sectr/font/provider.odin b/code/sectr/font/provider.odin index 3c8648e..99db79a 100644 --- a/code/sectr/font/provider.odin +++ b/code/sectr/font/provider.odin @@ -142,7 +142,7 @@ measure_text_size :: #force_inline proc( text : string, font : FontID, font_size get_font_vertical_metrics :: #force_inline proc ( font : FontID, font_size := Font_Use_Default_Size ) -> ( ascent, descent, line_gap : f32 ) { ve_id, size := font_provider_resolve_draw_id( font, font_size ) - ascent, descent, line_gap = ve.get_font_vertical_metrics( & get_state().font_provider_ctx.ve_ctx, ve_id ) + ascent, descent, line_gap = ve.get_font_vertical_metrics( & get_state().font_provider_ctx.ve_ctx, ve_id, font_size ) return } diff --git a/code/sectr/ui/core/layout_compute.odin b/code/sectr/ui/core/layout_compute.odin index d8e3570..6f237a0 100644 --- a/code/sectr/ui/core/layout_compute.odin +++ b/code/sectr/ui/core/layout_compute.odin @@ -191,14 +191,14 @@ ui_box_compute_layout :: proc( box : ^UI_Box, { ascent, descent, line_gap := get_font_vertical_metrics(style.font, layout.font_size) - offset := text_size - offset += { 0, -descent } + // offset := text_size + // offset += { 0, -descent } content_size := content_bounds.max - content_bounds.min text_pos : Vec2 - text_pos = content_bounds.min - text_pos += { 0, -descent } + text_pos = content_bounds.min text_pos += (content_size - text_size) * layout.text_alignment + text_pos += { 0, -descent } computed.text_size = text_size computed.text_pos = text_pos