From 9a2c61d9535e4eb344ba2ca1f387068c31491dee Mon Sep 17 00:00:00 2001 From: milarin Date: Mon, 24 Apr 2023 14:17:02 +0200 Subject: [PATCH] use gmath instead of locally implemented min/max functions --- utils.go | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/utils.go b/utils.go index f7becb3..e491cfa 100644 --- a/utils.go +++ b/utils.go @@ -3,6 +3,7 @@ package tui import ( "strings" + "git.milar.in/milarin/gmath" "github.com/gdamore/tcell" "github.com/mattn/go-runewidth" ) @@ -32,7 +33,7 @@ func WriteMultiLineString(b *ViewBuffer, str string, style Style, x, y int) (max return } lineWidth := WriteString(b, line, style, x, y+dy) - maxLineWidth = max(maxLineWidth, lineWidth) + maxLineWidth = gmath.Max(maxLineWidth, lineWidth) } return maxLineWidth, len(lines) } @@ -51,7 +52,7 @@ func MeasureMultiLineString(str string) (maxLineWidth, lineCount int) { lines := strings.Split(str, "\n") for _, line := range lines { lineWidth := MeasureString(line) - maxLineWidth = max(maxLineWidth, lineWidth) + maxLineWidth = gmath.Max(maxLineWidth, lineWidth) } return maxLineWidth, len(lines) } @@ -69,20 +70,6 @@ func runeWidth(r rune) int { // } } -func min(x, y int) int { - if x < y { - return x - } - return y -} - -func max(x, y int) int { - if x > y { - return x - } - return y -} - func iff[T any](condition bool, trueValue, falseValue T) T { if condition { return trueValue