diff --git a/f32/f32.go b/f32/f32.go index 70229f2b..798e3bf0 100644 --- a/f32/f32.go +++ b/f32/f32.go @@ -33,9 +33,9 @@ func (r Rectangle) String() string { return r.Min.String() + "-" + r.Max.String() } -// Rect is a shorthand to Rectangle{Point{x0, y0}, Point{x1, y1}}. +// Rect is a shorthand for Rectangle{Point{x0, y0}, Point{x1, y1}}. // The returned Rectangle has x0 and y0 swapped if necessary so that -// it's correctly formed +// it's correctly formed. func Rect(x0, y0, x1, y1 float32) Rectangle { if x0 > x1 { x0, x1 = x1, x0 @@ -46,6 +46,11 @@ func Rect(x0, y0, x1, y1 float32) Rectangle { return Rectangle{Point{x0, y0}, Point{x1, y1}} } +// Pt is shorthand for Point{X: x, Y: y}. +func Pt(x, y float32) Point { + return Point{X: x, Y: y} +} + // Add return the point p+p2. func (p Point) Add(p2 Point) Point { return Point{X: p.X + p2.X, Y: p.Y + p2.Y} diff --git a/layout/layout.go b/layout/layout.go index 8d3a3d12..60e18a38 100644 --- a/layout/layout.go +++ b/layout/layout.go @@ -5,6 +5,7 @@ package layout import ( "image" + "gioui.org/f32" "gioui.org/op" "gioui.org/unit" ) @@ -66,6 +67,20 @@ func Exact(size image.Point) Constraints { } } +// FPt converts an point to a f32.Point. +func FPt(p image.Point) f32.Point { + return f32.Point{ + X: float32(p.X), Y: float32(p.Y), + } +} + +// FRect converts a rectangle to a f32.Rectangle. +func FRect(r image.Rectangle) f32.Rectangle { + return f32.Rectangle{ + Min: FPt(r.Min), Max: FPt(r.Max), + } +} + // Constrain a size so each dimension is in the range [min;max]. func (c Constraints) Constrain(size image.Point) image.Point { if min := c.Min.X; size.X < min {