diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-01-17 16:11:26 -0500 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-01-17 16:11:26 -0500 |
| commit | bd9bce9f1278743e961a18cab688fdb09876560c (patch) | |
| tree | 9daec1c7725051930eb9db7904e50e6bd82d4ee8 /gui/widget/text.go | |
| parent | 0a696233d721c64d1bb53c7429624313113fa6f5 (diff) | |
| download | volute-bd9bce9f1278743e961a18cab688fdb09876560c.zip | |
add text label widget
Diffstat (limited to 'gui/widget/text.go')
| -rw-r--r-- | gui/widget/text.go | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/gui/widget/text.go b/gui/widget/text.go index 4723eda..5e37d70 100644 --- a/gui/widget/text.go +++ b/gui/widget/text.go @@ -14,11 +14,12 @@ import ( ) var ( - FONT = goregular.TTF - FONT_SIZE float64 = 15 - DPI float64 = 72 - BG_COLOR = image.White - TEXT_COLOR = image.Black + FONT = goregular.TTF + FONT_SIZE = 15 + DPI = 72 + PADDING = 3 + BG_COLOR = image.White + TEXT_COLOR = image.Black ) var face *concurrentFace @@ -29,8 +30,8 @@ func init() { log.Fatal(err) } fce, err := opentype.NewFace(fnt, &opentype.FaceOptions{ - Size: FONT_SIZE, - DPI: DPI, + Size: float64(FONT_SIZE), + DPI: float64(DPI), }) if err != nil { log.Fatal(err) @@ -38,6 +39,14 @@ func init() { face = &concurrentFace{sync.Mutex{}, fce} } +func TextWidth(nchars int) int { + return nchars*FONT_SIZE + 2*PADDING // very rough estimation +} + +func TextHeight() int { + return FONT_SIZE + 2*PADDING +} + func drawText(text []byte, dst draw.Image, r image.Rectangle) { drawer := font.Drawer{ Src: TEXT_COLOR, |