24 lines
505 B
Go
24 lines
505 B
Go
|
package alui
|
||
|
|
||
|
import (
|
||
|
"opslag.de/schobers/geom"
|
||
|
)
|
||
|
|
||
|
type center struct {
|
||
|
Proxy
|
||
|
}
|
||
|
|
||
|
func Center(control Control) Control {
|
||
|
return ¢er{Proxy: Proxy{Target: control}}
|
||
|
}
|
||
|
|
||
|
func (c *center) Layout(ctx *Context, bounds geom.RectangleF32) {
|
||
|
size := c.DesiredSize(ctx)
|
||
|
center := bounds.Center()
|
||
|
|
||
|
size.X = geom.Min32(size.X, bounds.Dx())
|
||
|
size.Y = geom.Min32(size.Y, bounds.Dy())
|
||
|
size = size.Mul(.5)
|
||
|
c.Proxy.Layout(ctx, geom.RectF32(center.X-size.X, center.Y-size.Y, center.X+size.X, center.Y+size.Y))
|
||
|
}
|