use gmath instead of locally implemented min/max functions

This commit is contained in:
milarin 2023-04-24 14:17:02 +02:00
parent e0874e6e4c
commit 9a2c61d953

View File

@ -3,6 +3,7 @@ package tui
import ( import (
"strings" "strings"
"git.milar.in/milarin/gmath"
"github.com/gdamore/tcell" "github.com/gdamore/tcell"
"github.com/mattn/go-runewidth" "github.com/mattn/go-runewidth"
) )
@ -32,7 +33,7 @@ func WriteMultiLineString(b *ViewBuffer, str string, style Style, x, y int) (max
return return
} }
lineWidth := WriteString(b, line, style, x, y+dy) lineWidth := WriteString(b, line, style, x, y+dy)
maxLineWidth = max(maxLineWidth, lineWidth) maxLineWidth = gmath.Max(maxLineWidth, lineWidth)
} }
return maxLineWidth, len(lines) return maxLineWidth, len(lines)
} }
@ -51,7 +52,7 @@ func MeasureMultiLineString(str string) (maxLineWidth, lineCount int) {
lines := strings.Split(str, "\n") lines := strings.Split(str, "\n")
for _, line := range lines { for _, line := range lines {
lineWidth := MeasureString(line) lineWidth := MeasureString(line)
maxLineWidth = max(maxLineWidth, lineWidth) maxLineWidth = gmath.Max(maxLineWidth, lineWidth)
} }
return maxLineWidth, len(lines) 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 { func iff[T any](condition bool, trueValue, falseValue T) T {
if condition { if condition {
return trueValue return trueValue