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:
Elias Naur
2019-07-29 12:12:51 +02:00
parent 1b684ffab6
commit 5f2adf9b2f
10 changed files with 33 additions and 81 deletions
+1 -4
View File
@@ -82,9 +82,6 @@ func (f *Flex) Rigid() Constraints {
f.begin(modeRigid)
mainc := axisMainConstraint(f.Axis, f.cs)
mainMax := mainc.Max
if mainc.Max != ui.Inf {
mainMax -= f.size
}
return axisConstraints(f.Axis, Constraint{Max: mainMax}, axisCrossConstraint(f.Axis, f.cs))
}
@@ -92,7 +89,7 @@ func (f *Flex) Flexible(weight float32) Constraints {
f.begin(modeFlex)
mainc := axisMainConstraint(f.Axis, f.cs)
var flexSize int
if mainc.Max != ui.Inf && mainc.Max > f.size {
if mainc.Max > f.size {
maxSize := mainc.Max - f.size
flexSize = mainc.Max - f.rigidSize
flexSize = int(float32(flexSize)*weight + .5)
+14 -18
View File
@@ -75,25 +75,21 @@ func (in *Inset) Begin(c ui.Config, ops *ui.Ops, cs Constraints) Constraints {
in.begun = true
in.cs = cs
mcs := cs
if mcs.Width.Max != ui.Inf {
mcs.Width.Min -= in.left + in.right
mcs.Width.Max -= in.left + in.right
if mcs.Width.Min < 0 {
mcs.Width.Min = 0
}
if mcs.Width.Max < mcs.Width.Min {
mcs.Width.Max = mcs.Width.Min
}
mcs.Width.Min -= in.left + in.right
mcs.Width.Max -= in.left + in.right
if mcs.Width.Min < 0 {
mcs.Width.Min = 0
}
if mcs.Height.Max != ui.Inf {
mcs.Height.Min -= in.top + in.bottom
mcs.Height.Max -= in.top + in.bottom
if mcs.Height.Min < 0 {
mcs.Height.Min = 0
}
if mcs.Height.Max < mcs.Height.Min {
mcs.Height.Max = mcs.Height.Min
}
if mcs.Width.Max < mcs.Width.Min {
mcs.Width.Max = mcs.Width.Min
}
mcs.Height.Min -= in.top + in.bottom
mcs.Height.Max -= in.top + in.bottom
if mcs.Height.Min < 0 {
mcs.Height.Min = 0
}
if mcs.Height.Max < mcs.Height.Min {
mcs.Height.Max = mcs.Height.Min
}
in.stack.Push(ops)
ui.TransformOp{}.Offset(toPointF(image.Point{X: in.left, Y: in.top})).Add(ops)
+5 -3
View File
@@ -56,6 +56,8 @@ const (
iterateBackward
)
const inf = 1e6
// Init prepares the list for iterating through its elements with Next.
func (l *List) Init(cfg ui.Config, q input.Queue, ops *ui.Ops, cs Constraints, len int) {
if l.more {
@@ -117,7 +119,7 @@ func (l *List) Index() int {
// Constraints is the constraints for the current element.
func (l *List) Constraints() Constraints {
return axisConstraints(l.Axis, Constraint{Max: ui.Inf}, axisCrossConstraint(l.Axis, l.cs))
return axisConstraints(l.Axis, Constraint{Max: inf}, axisCrossConstraint(l.Axis, l.cs))
}
func (l *List) More() bool {
@@ -223,8 +225,8 @@ func (l *List) Layout() Dimens {
min, max = mainc.Max-max, mainc.Max-min
}
r := image.Rectangle{
Min: axisPoint(l.Axis, min, -ui.Inf),
Max: axisPoint(l.Axis, max, ui.Inf),
Min: axisPoint(l.Axis, min, -inf),
Max: axisPoint(l.Axis, max, inf),
}
var stack ui.StackOp
stack.Push(ops)