Code refactor and self-review.

This commit is contained in:
Jakub Sobon 2020-11-28 14:24:22 -05:00
parent 79f696a100
commit ee90ac89dc
No known key found for this signature in database
GPG Key ID: F2451A77FB05D3B7
2 changed files with 5 additions and 5 deletions

View File

@ -43,7 +43,7 @@ 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.
@ -52,9 +52,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
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

View File

@ -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)