From 9da7349f639d98d8290011a24a05d40c73f8b61e Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 20 Aug 2020 08:30:52 +0200 Subject: [PATCH] gg: minor fixes --- vlib/gg/text_rendering.v | 7 +++++++ vlib/gx/color.v | 1 + 2 files changed, 8 insertions(+) diff --git a/vlib/gg/text_rendering.v b/vlib/gg/text_rendering.v index 43ca0c9855..873d6ad47a 100644 --- a/vlib/gg/text_rendering.v +++ b/vlib/gg/text_rendering.v @@ -103,6 +103,10 @@ fn (ctx &Context) set_cfg(cfg gx.TextCfg) { } pub fn (ctx &Context) draw_text(x, y int, text_ string, cfg gx.TextCfg) { + if !ctx.font_inited { + eprintln('gg: draw_text(): font not initialized') + return + } //text := text_.trim_space() // TODO remove/optimize mut text := text_ if text.contains('\t') { @@ -133,6 +137,9 @@ pub fn (ctx &Context) text_width(s string) int { } mut buf := [4]f32{} C.fonsTextBounds(ctx.ft.fons, 0, 0, s.str, 0, buf) + if s.ends_with(' ') { + return int((buf[2] - buf[0]) / ctx.scale) + ctx.text_width('i') // TODO fix this in fontstash? + } return int((buf[2] - buf[0]) / ctx.scale) } diff --git a/vlib/gx/color.v b/vlib/gx/color.v index 7b6536d8ae..d29bc89ce8 100644 --- a/vlib/gx/color.v +++ b/vlib/gx/color.v @@ -109,6 +109,7 @@ pub fn (c Color) str() string { const ( string_colors = { 'black': black + 'blue': blue 'red': red } )