gg: minor fixes

pull/6178/head
Alexander Medvednikov 2020-08-20 08:30:52 +02:00
parent eabc2daf86
commit 9da7349f63
2 changed files with 8 additions and 0 deletions

View File

@ -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) { 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 //text := text_.trim_space() // TODO remove/optimize
mut text := text_ mut text := text_
if text.contains('\t') { if text.contains('\t') {
@ -133,6 +137,9 @@ pub fn (ctx &Context) text_width(s string) int {
} }
mut buf := [4]f32{} mut buf := [4]f32{}
C.fonsTextBounds(ctx.ft.fons, 0, 0, s.str, 0, buf) 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) return int((buf[2] - buf[0]) / ctx.scale)
} }

View File

@ -109,6 +109,7 @@ pub fn (c Color) str() string {
const ( const (
string_colors = { string_colors = {
'black': black 'black': black
'blue': blue
'red': red 'red': red
} }
) )