mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
layout,f32: add convenience functions for rectangles and points
layout.FRect, layout.FPt for converting from integer to floating point, useful for drawing operations. f32.Pt is a shorthand that mirrors image.Pt. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user