From afddcda7a327b7af96d13a88f5d5c08bc1c4d01f Mon Sep 17 00:00:00 2001 From: Larpon Date: Fri, 29 Jan 2021 11:13:06 +0100 Subject: [PATCH] examples: make raven text run on android, fix text scaling (#8394) --- examples/gg/raven_text_rendering.v | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/examples/gg/raven_text_rendering.v b/examples/gg/raven_text_rendering.v index 0bd1274eb9..d6378cdb77 100644 --- a/examples/gg/raven_text_rendering.v +++ b/examples/gg/raven_text_rendering.v @@ -3,6 +3,7 @@ module main import gg import gx import os +import math const ( win_width = 600 @@ -66,7 +67,11 @@ fn main() { mut app := &App{ gg: 0 } - app.gg = gg.new_context({ + mut font_path := os.resource_abs_path(os.join_path('..', 'assets', 'fonts', 'RobotoMono-Regular.ttf')) + $if android { + font_path = 'fonts/RobotoMono-Regular.ttf' + } + app.gg = gg.new_context( width: win_width height: win_height use_ortho: true // This is needed for 2D drawing @@ -75,16 +80,24 @@ fn main() { user_data: app bg_color: bg_color frame_fn: frame - font_path: os.resource_abs_path('../assets/fonts/RobotoMono-Regular.ttf') // window_user_ptr: ctx - }) + font_path: font_path // window_user_ptr: ctx + ) app.gg.run() } fn frame(mut app App) { app.gg.begin() + width := gg.window_size().width + mut scale_factor := math.round(f32(width) / win_width) + if scale_factor <= 0 { + scale_factor = 1 + } + text_cfg := gx.TextCfg{ + size: 16 * int(scale_factor) + } mut y := 10 for line in lines { - app.gg.draw_text_def(10, y, line) + app.gg.draw_text(10, y, line, text_cfg) y += 30 } app.gg.end()