1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

gg: rename Context.set_cfg() -> Context.set_text_cfg() (#15904)

This commit is contained in:
Tim Marston 2022-09-29 13:24:16 +01:00 committed by GitHub
parent 2d08950e4c
commit 711bb6def7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 8 deletions

View File

@ -539,7 +539,7 @@ pub fn (ctx &Context) show_fps() {
sgl.defaults() sgl.defaults()
sgl.matrix_mode_projection() sgl.matrix_mode_projection()
sgl.ortho(0.0, f32(sapp.width()), f32(sapp.height()), 0.0, -1.0, 1.0) sgl.ortho(0.0, f32(sapp.width()), f32(sapp.height()), 0.0, -1.0, 1.0)
ctx.set_cfg(ctx.fps.text_config) ctx.set_text_cfg(ctx.fps.text_config)
if ctx.fps.width == 0 { if ctx.fps.width == 0 {
mut fps := unsafe { &ctx.fps } mut fps := unsafe { &ctx.fps }
fps.width, fps.height = ctx.text_size('00') // maximum size; prevents blinking on variable width fonts fps.width, fps.height = ctx.text_size('00') // maximum size; prevents blinking on variable width fonts

View File

@ -17,7 +17,7 @@ pub fn (ctx &Context) has_text_style() bool {
pub fn (ctx &Context) set_text_style(font_name string, font_path string, size int, color gx.Color, align int, vertical_align int) {} pub fn (ctx &Context) set_text_style(font_name string, font_path string, size int, color gx.Color, align int, vertical_align int) {}
// default draw_text (draw_text_def but without set_cfg) // default draw_text (draw_text_def but without set_text_cfg)
pub fn (ctx &Context) draw_text_default(x int, y int, text string) { pub fn (ctx &Context) draw_text_default(x int, y int, text string) {
scale := if ctx.ft.scale == 0 { f32(1) } else { ctx.ft.scale } scale := if ctx.ft.scale == 0 { f32(1) } else { ctx.ft.scale }
ctx.ft.fons.draw_text(x * scale, y * scale, text) // TODO: check offsets/alignment ctx.ft.fons.draw_text(x * scale, y * scale, text) // TODO: check offsets/alignment

View File

@ -118,8 +118,8 @@ fn new_ft(c FTConfig) ?&FT {
} }
} }
// set_cfg sets the current text configuration // set_text_cfg sets the current text configuration
pub fn (ctx &Context) set_cfg(cfg gx.TextCfg) { pub fn (ctx &Context) set_text_cfg(cfg gx.TextCfg) {
if !ctx.font_inited { if !ctx.font_inited {
return return
} }
@ -147,6 +147,12 @@ pub fn (ctx &Context) set_cfg(cfg gx.TextCfg) {
ctx.ft.fons.vert_metrics(&ascender, &descender, &lh) ctx.ft.fons.vert_metrics(&ascender, &descender, &lh)
} }
// set_cfg sets the current text configuration
[deprecated: 'use set_text_cfg() instead']
pub fn (ctx &Context) set_cfg(cfg gx.TextCfg) {
ctx.set_text_cfg(cfg)
}
// draw_text draws the string in `text_` starting at top-left position `x`,`y`. // draw_text draws the string in `text_` starting at top-left position `x`,`y`.
// Text settings can be provided with `cfg`. // Text settings can be provided with `cfg`.
pub fn (ctx &Context) draw_text(x int, y int, text_ string, cfg gx.TextCfg) { pub fn (ctx &Context) draw_text(x int, y int, text_ string, cfg gx.TextCfg) {
@ -170,7 +176,7 @@ pub fn (ctx &Context) draw_text(x int, y int, text_ string, cfg gx.TextCfg) {
// if text.contains('\t') { // if text.contains('\t') {
// text = text.replace('\t', ' ') // text = text.replace('\t', ' ')
// } // }
ctx.set_cfg(cfg) ctx.set_text_cfg(cfg)
scale := if ctx.ft.scale == 0 { f32(1) } else { ctx.ft.scale } scale := if ctx.ft.scale == 0 { f32(1) } else { ctx.ft.scale }
ctx.ft.fons.draw_text(x * scale, y * scale, text_) // TODO: check offsets/alignment ctx.ft.fons.draw_text(x * scale, y * scale, text_) // TODO: check offsets/alignment
} }
@ -193,7 +199,7 @@ pub fn (ctx &Context) text_width(s string) int {
return C.darwin_text_width(s) return C.darwin_text_width(s)
} }
} }
// ctx.set_cfg(cfg) TODO // ctx.set_text_cfg(cfg) TODO
if !ctx.font_inited { if !ctx.font_inited {
return 0 return 0
} }
@ -215,7 +221,7 @@ pub fn (ctx &Context) text_width(s string) int {
// text_height returns the height of the `string` `s` in pixels. // text_height returns the height of the `string` `s` in pixels.
pub fn (ctx &Context) text_height(s string) int { pub fn (ctx &Context) text_height(s string) int {
// ctx.set_cfg(cfg) TODO // ctx.set_text_cfg(cfg) TODO
if !ctx.font_inited { if !ctx.font_inited {
return 0 return 0
} }
@ -226,7 +232,7 @@ pub fn (ctx &Context) text_height(s string) int {
// text_size returns the width and height of the `string` `s` in pixels. // text_size returns the width and height of the `string` `s` in pixels.
pub fn (ctx &Context) text_size(s string) (int, int) { pub fn (ctx &Context) text_size(s string) (int, int) {
// ctx.set_cfg(cfg) TODO // ctx.set_text_cfg(cfg) TODO
if !ctx.font_inited { if !ctx.font_inited {
return 0, 0 return 0, 0
} }