diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-01-19 22:43:07 -0500 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-01-19 22:43:07 -0500 |
| commit | 95944c92c6d9171e3a8a2619e62bbfa29d48bfef (patch) | |
| tree | e48c3bf421d69ef48ea9dade43f86ff9dc30e05b /gui/widget | |
| parent | 5d107e1443baa6762bbb30b62de68a25c011cf79 (diff) | |
| download | volute-95944c92c6d9171e3a8a2619e62bbfa29d48bfef.zip | |
refine widget screen space allocation
Diffstat (limited to 'gui/widget')
| -rw-r--r-- | gui/widget/text.go | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/gui/widget/text.go b/gui/widget/text.go index 6205bab..1b40096 100644 --- a/gui/widget/text.go +++ b/gui/widget/text.go @@ -38,12 +38,9 @@ func init() { face = &concurrentFace{sync.Mutex{}, fce} } -func TextWidth(nchars int) int { - return nchars*FONT_SIZE + 2*PAD // very rough estimation -} - -func TextHeight() int { - return FONT_SIZE + 2*PAD +func TextSize(text string) image.Point { + bounds := textBounds([]byte(text), font.Drawer{Face: face}) + return image.Point{bounds.Max.X - bounds.Min.X + 2*PAD, bounds.Max.Y - bounds.Min.Y + 2*PAD} } func drawText(text []byte, dst draw.Image, r image.Rectangle, fg, bg color.Color) { |