From cad816a19dd74dca46364de1da4c14230cbb0bb0 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sun, 12 Jul 2020 12:48:39 +0200 Subject: [PATCH] gg: text_height() --- vlib/gg/text_rendering.v | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/vlib/gg/text_rendering.v b/vlib/gg/text_rendering.v index 63e58e5ace..d7b388cf88 100644 --- a/vlib/gg/text_rendering.v +++ b/vlib/gg/text_rendering.v @@ -94,11 +94,21 @@ pub fn (ctx &Context) text_width(s string) int { return int((buf[2] - buf[0]) / ctx.scale) } -pub fn (ft &Context) text_height(s string) int { - return 0 +pub fn (ctx &Context) text_height(s string) int { + if !ctx.font_inited { + return 0 + } + mut buf := [4]f32 + C.fonsTextBounds(ctx.ft.fons, 0, 0, s.str, 0, buf) + return int((buf[3] - buf[1]) / ctx.scale) } -pub fn (ft &Context) text_size(s string) (int, int) { - return 0,0 +pub fn (ctx &Context) text_size(s string) (int, int) { + if !ctx.font_inited { + return 0,0 + } + mut buf := [4]f32 + C.fonsTextBounds(ctx.ft.fons, 0, 0, s.str, 0, buf) + return int((buf[2] - buf[0]) / ctx.scale), int((buf[3] - buf[1]) / ctx.scale) }