mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
ui: get rid of Inf
It's not worth the special cases. Use a large value where needed (layout.List, text.Editor...) instead. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+6
-16
@@ -5,7 +5,6 @@ package text
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
"math"
|
||||
"unicode/utf8"
|
||||
|
||||
"gioui.org/ui"
|
||||
@@ -36,6 +35,8 @@ type lineIterator struct {
|
||||
y, prevDesc fixed.Int26_6
|
||||
}
|
||||
|
||||
const inf = 1e6
|
||||
|
||||
func (l *lineIterator) Next() (String, f32.Point, bool) {
|
||||
for len(l.Lines) > 0 {
|
||||
line := l.Lines[0]
|
||||
@@ -92,8 +93,8 @@ func (l Label) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
||||
dims.Size = cs.Constrain(dims.Size)
|
||||
padTop, padBottom := textPadding(lines)
|
||||
clip := image.Rectangle{
|
||||
Min: image.Point{X: -ui.Inf, Y: -padTop},
|
||||
Max: image.Point{X: ui.Inf, Y: dims.Size.Y + padBottom},
|
||||
Min: image.Point{X: -inf, Y: -padTop},
|
||||
Max: image.Point{X: inf, Y: dims.Size.Y + padBottom},
|
||||
}
|
||||
l.it = lineIterator{
|
||||
Lines: lines,
|
||||
@@ -120,21 +121,10 @@ func (l Label) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
|
||||
return dims
|
||||
}
|
||||
|
||||
func itof(i int) float32 {
|
||||
switch i {
|
||||
case ui.Inf:
|
||||
return float32(math.Inf(+1))
|
||||
case -ui.Inf:
|
||||
return float32(math.Inf(-1))
|
||||
default:
|
||||
return float32(i)
|
||||
}
|
||||
}
|
||||
|
||||
func toRectF(r image.Rectangle) f32.Rectangle {
|
||||
return f32.Rectangle{
|
||||
Min: f32.Point{X: itof(r.Min.X), Y: itof(r.Min.Y)},
|
||||
Max: f32.Point{X: itof(r.Max.X), Y: itof(r.Max.Y)},
|
||||
Min: f32.Point{X: float32(r.Min.X), Y: float32(r.Min.Y)},
|
||||
Max: f32.Point{X: float32(r.Max.X), Y: float32(r.Max.Y)},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user