diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-01-19 22:14:37 -0500 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-01-19 22:14:37 -0500 |
| commit | 5d107e1443baa6762bbb30b62de68a25c011cf79 (patch) | |
| tree | 022e0451a670473e663899568128c3d63df53e5f /gui/widget | |
| parent | 54d71a24b6eaa191b2777f6070de252fc26801a3 (diff) | |
| download | volute-5d107e1443baa6762bbb30b62de68a25c011cf79.zip | |
right justify text
Diffstat (limited to 'gui/widget')
| -rw-r--r-- | gui/widget/text.go | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/gui/widget/text.go b/gui/widget/text.go index e336874..6205bab 100644 --- a/gui/widget/text.go +++ b/gui/widget/text.go @@ -18,7 +18,7 @@ var ( FONT = goregular.TTF FONT_SIZE = 15 DPI = 72 - PADDING = 3 + PAD = 3 ) var face *concurrentFace @@ -39,11 +39,11 @@ func init() { } func TextWidth(nchars int) int { - return nchars*FONT_SIZE + 2*PADDING // very rough estimation + return nchars*FONT_SIZE + 2*PAD // very rough estimation } func TextHeight() int { - return FONT_SIZE + 2*PADDING + return FONT_SIZE + 2*PAD } func drawText(text []byte, dst draw.Image, r image.Rectangle, fg, bg color.Color) { @@ -64,9 +64,9 @@ func drawText(text []byte, dst draw.Image, r image.Rectangle, fg, bg color.Color drawer.DrawBytes(text) // draw text image over background - left := image.Pt(bounds.Min.X, (bounds.Min.Y+bounds.Max.Y)/2) - target := image.Pt(r.Min.X, (r.Min.Y+r.Max.Y)/2) - delta := target.Sub(left) + leftCentre := image.Pt(bounds.Min.X, (bounds.Min.Y+bounds.Max.Y)/2) + target := image.Pt(r.Max.X-bounds.Max.X-PAD, (r.Min.Y+r.Max.Y)/2) + delta := target.Sub(leftCentre) draw.Draw(dst, bounds.Add(delta).Intersect(r), drawer.Dst, bounds.Min, draw.Src) } |