layout,widget: transpose Constraints to use image.Points for limits

Instead of

    type Contraints struct {
	    Width, Height Constraint
    }

use

    type Constraints struct {
	    Min, Max image.Point
    }

which leads to simpler use. For example, the Min method is trivally replaced by
the field, and the RigidConstraints constructor is no longer a net win.

API Change. Rewrites:

    gofmt -r 'gtx.Constraints.Min() -> gtx.Constraints.Min'
    gofmt -r 'gtx.Constraints.Width.Min -> gtx.Constraints.Min.X'
    gofmt -r 'gtx.Constraints.Height.Min -> gtx.Constraints.Min.Y'
    gofmt -r 'gtx.Constraints.Height.Max -> gtx.Constraints.Max.Y'
    gofmt -r 'gtx.Constraints.Width.Max -> gtx.Constraints.Max.X'

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-05-19 09:50:37 +02:00
parent 67a9d9e9d7
commit 7bf3265ccd
16 changed files with 99 additions and 122 deletions
+1 -2
View File
@@ -3,7 +3,6 @@
package material
import (
"image"
"image/color"
"gioui.org/f32"
@@ -66,7 +65,7 @@ func argb(c uint32) color.RGBA {
func fill(gtx *layout.Context, col color.RGBA) {
cs := gtx.Constraints
d := image.Point{X: cs.Width.Min, Y: cs.Height.Min}
d := cs.Min
dr := f32.Rectangle{
Max: f32.Point{X: float32(d.X), Y: float32(d.Y)},
}