Skip to content

Commit 40da32a

Browse files
committed
gg: text_width()
1 parent e747dfd commit 40da32a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

vlib/gg/text_rendering.v

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,13 @@ pub fn (ft &FT) flush(){
8585
sfons.flush(ft.fons)
8686
}
8787

88-
pub fn (ft &Context) text_width(s string) int {
89-
return 0
88+
pub fn (ctx &Context) text_width(s string) int {
89+
if !ctx.font_inited {
90+
return 0
91+
}
92+
mut buf := [4]f32
93+
C.fonsTextBounds(ctx.ft.fons, 0, 0, s.str, 0, buf)
94+
return int((buf[2] - buf[0]) / ctx.scale)
9095
}
9196

9297
pub fn (ft &Context) text_height(s string) int {

0 commit comments

Comments
 (0)