gg: render text if we fell back to system default (#10307)

pull/10323/head
KJ Lawrence 2021-06-02 09:00:14 -04:00 committed by GitHub
parent ce3e71cb8e
commit 452a51c8fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 22 deletions

View File

@ -104,8 +104,8 @@ pub:
[heap]
pub struct Context {
render_text bool
mut:
render_text bool = true
// a cache with all images created by the user. used for sokol image init and to save space
// (so that the user can store image ids, not entire Image objects)
image_cache []Image
@ -159,7 +159,9 @@ fn gg_init_sokol_window(user_data voidptr) {
// if g.config.init_text {
// `os.is_file()` won't work on Android if the font file is embedded into the APK
exists := $if !android { os.is_file(g.config.font_path) } $else { true }
if g.config.font_path != '' && exists {
if g.config.font_path != '' && !exists {
g.render_text = false
} else if g.config.font_path != '' && exists {
// t := time.ticks()
g.ft = new_ft(
font_path: g.config.font_path
@ -169,7 +171,6 @@ fn gg_init_sokol_window(user_data voidptr) {
// println('FT took ${time.ticks()-t} ms')
g.font_inited = true
} else {
if !exists {
if g.config.font_bytes_normal.len > 0 {
g.ft = new_ft(
bytes_normal: g.config.font_bytes_normal
@ -181,7 +182,10 @@ fn gg_init_sokol_window(user_data voidptr) {
g.font_inited = true
} else {
sfont := system_font_path()
eprintln('font file "$g.config.font_path" does not exist, the system font was used instead.')
if g.config.font_path != '' {
eprintln('font file "$g.config.font_path" does not exist, the system font ($sfont) was used instead.')
}
g.ft = new_ft(
font_path: sfont
custom_bold_font_path: g.config.custom_bold_font_path
@ -190,7 +194,6 @@ fn gg_init_sokol_window(user_data voidptr) {
g.font_inited = true
}
}
}
//
mut pipdesc := C.sg_pipeline_desc{
label: c'alpha_image'
@ -327,7 +330,6 @@ pub fn new_context(cfg Config) &Context {
width: cfg.width
height: cfg.height
config: cfg
render_text: cfg.font_path != '' || cfg.font_bytes_normal.len > 0
ft: 0
ui_mode: cfg.ui_mode
native_rendering: cfg.native_rendering