GioUtils/points/points.go
2025-01-31 00:04:31 +01:00

26 lines
1 KiB
Go

package points
import (
"image"
"gioui.org/layout"
)
// ContextCenter returns a point representing the center of the provide layout context.
func ContextCenter(gtx layout.Context) image.Point {
return image.Pt(gtx.Constraints.Max.X/2, gtx.Constraints.Max.Y/2)
}
// ContextCenterSquare returns two points representing the upper left corner (min) and lower right corner (max) of a square around the context center.
func ContextCenterSquare(gtx layout.Context, apothem int) (min image.Point, max image.Point) {
min = image.Pt(gtx.Constraints.Max.X/2-apothem, gtx.Constraints.Max.Y/2-apothem)
max = image.Pt(gtx.Constraints.Max.X/2+apothem, gtx.Constraints.Max.Y/2+apothem)
return
}
// CenterSquare returns two points representing the upper left corner (min) and lower right corner (max) of a square around the given center point.
func CenterSquare(center image.Point, apothem int) (min image.Point, max image.Point) {
min = image.Pt(center.X-apothem, center.Y-apothem)
max = image.Pt(center.X+apothem, center.Y+apothem)
return
}