From ee90ac89dccd11e7cf8552d5a8c3d1766df2dce5 Mon Sep 17 00:00:00 2001 From: Jakub Sobon Date: Sat, 28 Nov 2020 14:24:22 -0500 Subject: [PATCH] Code refactor and self-review. --- CHANGELOG.md | 7 ++----- widgets/button/button.go | 3 +++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1be0107..0e6bd2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,18 +43,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - the `button` widget allows users to specify multiple trigger keys. - the `button` widget now supports different keys for the global and focused scope. -- the `button` widget can now be drawn without the shadow and the press +- the `button` widget can now be drawn without the shadow or the press animation. - the `button` widget can now be drawn without horizontal padding around its text. -- the `button`widget now allows specifying cell options for each cell of the +- the `button` widget now allows specifying cell options for each cell of the displayed text. Separate cell options can be specified for each of button's main states (up, focused and up, down). - the `button` widget allows specifying separate fill color values for each of its main states (up, focused and up, down). -- added a new demo called `formdemo` under the `button` widget that - demonstrates the ability of `termdash` to display forms with editable content - and keyboard navigation. ## [0.13.0] - 17-Nov-2020 diff --git a/widgets/button/button.go b/widgets/button/button.go index 54ee903..071f5b2 100644 --- a/widgets/button/button.go +++ b/widgets/button/button.go @@ -209,7 +209,10 @@ func (b *Button) Draw(cvs *canvas.Canvas, meta *widgetapi.Meta) error { if err := cvs.SetAreaCells(buttonAr, buttonRune, cell.BgColor(fillColor)); err != nil { return err } + return b.drawText(cvs, meta, buttonAr) +} +func (b *Button) drawText(cvs *canvas.Canvas, meta *widgetapi.Meta, buttonAr image.Rectangle) error { pad := b.opts.textHorizontalPadding textAr := image.Rect(buttonAr.Min.X+pad, buttonAr.Min.Y, buttonAr.Dx()-pad, buttonAr.Max.Y) start, err := alignfor.Text(textAr, b.text.String(), align.HorizontalCenter, align.VerticalMiddle)