diff --git a/internal/area/area.go b/internal/area/area.go index 5a36b91..c013f2b 100644 --- a/internal/area/area.go +++ b/internal/area/area.go @@ -186,16 +186,16 @@ func Shrink(area image.Rectangle, topCells, rightCells, bottomCells, leftCells i } } - shrinked := area - shrinked.Min.X, _ = numbers.MinMaxInts([]int{shrinked.Min.X + leftCells, shrinked.Max.X}) - _, shrinked.Max.X = numbers.MinMaxInts([]int{shrinked.Max.X - rightCells, shrinked.Min.X}) - shrinked.Min.Y, _ = numbers.MinMaxInts([]int{shrinked.Min.Y + topCells, shrinked.Max.Y}) - _, shrinked.Max.Y = numbers.MinMaxInts([]int{shrinked.Max.Y - bottomCells, shrinked.Min.Y}) + shrunk := area + shrunk.Min.X, _ = numbers.MinMaxInts([]int{shrunk.Min.X + leftCells, shrunk.Max.X}) + _, shrunk.Max.X = numbers.MinMaxInts([]int{shrunk.Max.X - rightCells, shrunk.Min.X}) + shrunk.Min.Y, _ = numbers.MinMaxInts([]int{shrunk.Min.Y + topCells, shrunk.Max.Y}) + _, shrunk.Max.Y = numbers.MinMaxInts([]int{shrunk.Max.Y - bottomCells, shrunk.Min.Y}) - if shrinked.Dx() == 0 || shrinked.Dy() == 0 { + if shrunk.Dx() == 0 || shrunk.Dy() == 0 { return image.ZR, nil } - return shrinked, nil + return shrunk, nil } // ShrinkPercent returns a new area whose size is reduced by percentage of its diff --git a/widgets/donut/donut.go b/widgets/donut/donut.go index 0931583..4c7476a 100644 --- a/widgets/donut/donut.go +++ b/widgets/donut/donut.go @@ -192,15 +192,12 @@ func (d *Donut) drawLabel(cvs *canvas.Canvas, labelAr image.Rectangle) error { if err != nil { return err } - if err := draw.Text( + return draw.Text( cvs, d.opts.label, start, draw.TextOverrunMode(draw.OverrunModeThreeDot), draw.TextMaxX(labelAr.Max.X), draw.TextCellOpts(d.opts.labelCellOpts...), - ); err != nil { - return err - } - return nil + ) } // Draw draws the Donut widget onto the canvas. diff --git a/widgets/textinput/textinput.go b/widgets/textinput/textinput.go index cc2de60..0e7455f 100644 --- a/widgets/textinput/textinput.go +++ b/widgets/textinput/textinput.go @@ -110,15 +110,12 @@ func (ti *TextInput) drawLabel(cvs *canvas.Canvas, labelAr image.Rectangle) erro if err != nil { return err } - if err := draw.Text( + return draw.Text( cvs, ti.opts.label, start, draw.TextOverrunMode(draw.OverrunModeThreeDot), draw.TextMaxX(labelAr.Max.X), draw.TextCellOpts(ti.opts.labelCellOpts...), - ); err != nil { - return err - } - return nil + ) } // drawField draws the text input field. @@ -131,14 +128,11 @@ func (ti *TextInput) drawField(cvs *canvas.Canvas, text string) error { text = hideText(text, ti.opts.hideTextWith) } - if err := draw.Text( + return draw.Text( cvs, text, ti.forField.Min, draw.TextMaxX(ti.forField.Max.X), draw.TextCellOpts(cell.FgColor(ti.opts.textColor)), - ); err != nil { - return err - } - return nil + ) } // drawCursor draws the cursor within the text input field. diff --git a/widgets/textinput/textinputdemo/textinputdemo.go b/widgets/textinput/textinputdemo/textinputdemo.go index 79e2eb7..e628c7f 100644 --- a/widgets/textinput/textinputdemo/textinputdemo.go +++ b/widgets/textinput/textinputdemo/textinputdemo.go @@ -143,6 +143,9 @@ func main() { button.GlobalKey(keyboard.KeyEnter), button.FillColor(cell.ColorNumber(220)), ) + if err != nil { + panic(err) + } clearB, err := button.New("Clear", func() error { input.ReadAndClear() updateText <- "" @@ -151,6 +154,9 @@ func main() { button.WidthFor("Submit"), button.FillColor(cell.ColorNumber(220)), ) + if err != nil { + panic(err) + } quitB, err := button.New("Quit", func() error { cancel() return nil @@ -158,6 +164,9 @@ func main() { button.WidthFor("Submit"), button.FillColor(cell.ColorNumber(196)), ) + if err != nil { + panic(err) + } builder := grid.New() builder.Add(