gg: document pub functions in text_rendering and m4/vector (#13961)

pull/13963/head
Larpon 2022-04-06 18:34:02 +02:00 committed by GitHub
parent c5d8d27b90
commit 56e6fd01c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -22,6 +22,7 @@ pub mut:
* Utility * Utility
* *
*********************************************************************/ *********************************************************************/
// str returns a `string` representation of `Vec4`.
pub fn (x Vec4) str() string { pub fn (x Vec4) str() string {
return '|${x.e[0]:-6.3},${x.e[1]:-6.3},${x.e[2]:-6.3},${x.e[3]:-6.3}|' return '|${x.e[0]:-6.3},${x.e[1]:-6.3},${x.e[2]:-6.3},${x.e[3]:-6.3}|'
} }

View File

@ -118,6 +118,7 @@ fn new_ft(c FTConfig) ?&FT {
} }
} }
// set_cfg sets the current text configuration
pub fn (ctx &Context) set_cfg(cfg gx.TextCfg) { pub fn (ctx &Context) set_cfg(cfg gx.TextCfg) {
if !ctx.font_inited { if !ctx.font_inited {
return return
@ -146,6 +147,8 @@ 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)
} }
// draw_text draws the string in `text_` starting at top-left position `x`,`y`.
// 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) {
$if macos { $if macos {
if ctx.native_rendering { if ctx.native_rendering {
@ -172,18 +175,18 @@ pub fn (ctx &Context) draw_text(x int, y int, text_ string, cfg gx.TextCfg) {
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
} }
// draw_text draws the string in `text_` starting at top-left position `x`,`y` using
// default text settings.
pub fn (ctx &Context) draw_text_def(x int, y int, text string) { pub fn (ctx &Context) draw_text_def(x int, y int, text string) {
ctx.draw_text(x, y, text) ctx.draw_text(x, y, text)
} }
/* // flush prepares the font for use.
pub fn (mut gg FT) init_font() {
}
*/
pub fn (ft &FT) flush() { pub fn (ft &FT) flush() {
sfons.flush(ft.fons) sfons.flush(ft.fons)
} }
// text_width returns the width of the `string` `s` in pixels.
pub fn (ctx &Context) text_width(s string) int { pub fn (ctx &Context) text_width(s string) int {
$if macos { $if macos {
if ctx.native_rendering { if ctx.native_rendering {
@ -210,6 +213,7 @@ pub fn (ctx &Context) text_width(s string) int {
return int((buf[2] - buf[0]) / ctx.scale) return int((buf[2] - buf[0]) / ctx.scale)
} }
// 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_cfg(cfg) TODO
if !ctx.font_inited { if !ctx.font_inited {
@ -220,6 +224,7 @@ pub fn (ctx &Context) text_height(s string) int {
return int((buf[3] - buf[1]) / ctx.scale) return int((buf[3] - buf[1]) / ctx.scale)
} }
// 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_cfg(cfg) TODO
if !ctx.font_inited { if !ctx.font_inited {