gg: render text if we fell back to system default (#10307)
							parent
							
								
									ce3e71cb8e
								
							
						
					
					
						commit
						452a51c8fe
					
				
							
								
								
									
										14
									
								
								vlib/gg/gg.v
								
								
								
								
							
							
						
						
									
										14
									
								
								vlib/gg/gg.v
								
								
								
								
							| 
						 | 
					@ -104,8 +104,8 @@ pub:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[heap]
 | 
					[heap]
 | 
				
			||||||
pub struct Context {
 | 
					pub struct Context {
 | 
				
			||||||
	render_text bool
 | 
					 | 
				
			||||||
mut:
 | 
					mut:
 | 
				
			||||||
 | 
						render_text bool = true
 | 
				
			||||||
	// a cache with all images created by the user. used for sokol image init and to save space
 | 
						// 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)
 | 
						// (so that the user can store image ids, not entire Image objects)
 | 
				
			||||||
	image_cache   []Image
 | 
						image_cache   []Image
 | 
				
			||||||
| 
						 | 
					@ -159,7 +159,9 @@ fn gg_init_sokol_window(user_data voidptr) {
 | 
				
			||||||
	// if g.config.init_text {
 | 
						// if g.config.init_text {
 | 
				
			||||||
	// `os.is_file()` won't work on Android if the font file is embedded into the APK
 | 
						// `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 }
 | 
						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()
 | 
							// t := time.ticks()
 | 
				
			||||||
		g.ft = new_ft(
 | 
							g.ft = new_ft(
 | 
				
			||||||
			font_path: g.config.font_path
 | 
								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')
 | 
							// println('FT took ${time.ticks()-t} ms')
 | 
				
			||||||
		g.font_inited = true
 | 
							g.font_inited = true
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		if !exists {
 | 
					 | 
				
			||||||
		if g.config.font_bytes_normal.len > 0 {
 | 
							if g.config.font_bytes_normal.len > 0 {
 | 
				
			||||||
			g.ft = new_ft(
 | 
								g.ft = new_ft(
 | 
				
			||||||
				bytes_normal: g.config.font_bytes_normal
 | 
									bytes_normal: g.config.font_bytes_normal
 | 
				
			||||||
| 
						 | 
					@ -181,7 +182,10 @@ fn gg_init_sokol_window(user_data voidptr) {
 | 
				
			||||||
			g.font_inited = true
 | 
								g.font_inited = true
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			sfont := system_font_path()
 | 
								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(
 | 
								g.ft = new_ft(
 | 
				
			||||||
				font_path: sfont
 | 
									font_path: sfont
 | 
				
			||||||
				custom_bold_font_path: g.config.custom_bold_font_path
 | 
									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
 | 
								g.font_inited = true
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	//
 | 
						//
 | 
				
			||||||
	mut pipdesc := C.sg_pipeline_desc{
 | 
						mut pipdesc := C.sg_pipeline_desc{
 | 
				
			||||||
		label: c'alpha_image'
 | 
							label: c'alpha_image'
 | 
				
			||||||
| 
						 | 
					@ -327,7 +330,6 @@ pub fn new_context(cfg Config) &Context {
 | 
				
			||||||
		width: cfg.width
 | 
							width: cfg.width
 | 
				
			||||||
		height: cfg.height
 | 
							height: cfg.height
 | 
				
			||||||
		config: cfg
 | 
							config: cfg
 | 
				
			||||||
		render_text: cfg.font_path != '' || cfg.font_bytes_normal.len > 0
 | 
					 | 
				
			||||||
		ft: 0
 | 
							ft: 0
 | 
				
			||||||
		ui_mode: cfg.ui_mode
 | 
							ui_mode: cfg.ui_mode
 | 
				
			||||||
		native_rendering: cfg.native_rendering
 | 
							native_rendering: cfg.native_rendering
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue