aboutsummaryrefslogtreecommitdiffstats
path: root/gui/widget/text.go
diff options
context:
space:
mode:
Diffstat (limited to 'gui/widget/text.go')
-rw-r--r--gui/widget/text.go23
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,