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,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

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)