2019-03-12 20:11:43 +00:00
|
|
|
package ui
|
|
|
|
|
|
|
|
import "opslag.de/schobers/geom"
|
|
|
|
|
|
|
|
type Length struct {
|
|
|
|
float32
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Length) Value() float32 {
|
|
|
|
if l == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return l.float32
|
|
|
|
}
|
|
|
|
|
2019-04-10 19:26:57 +00:00
|
|
|
func (l *Length) Zero(value float32) float32 {
|
2019-03-12 20:11:43 +00:00
|
|
|
if l == nil {
|
2019-04-10 19:26:57 +00:00
|
|
|
return value
|
2019-03-12 20:11:43 +00:00
|
|
|
}
|
2019-04-10 19:26:57 +00:00
|
|
|
return l.Value()
|
2019-03-12 20:11:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Fixed(l float32) *Length { return &Length{l} }
|
|
|
|
|
|
|
|
func Infinite() *Length { return &Length{geom.NaN32()} }
|
|
|
|
|
2021-07-19 05:58:46 +00:00
|
|
|
func ZL() *Length { return &Length{0} }
|
|
|
|
|
2019-03-12 20:11:43 +00:00
|
|
|
type SideLengths struct {
|
|
|
|
Left *Length
|
|
|
|
Top *Length
|
|
|
|
Right *Length
|
|
|
|
Bottom *Length
|
|
|
|
}
|
2021-07-19 05:58:46 +00:00
|
|
|
|
|
|
|
func (l SideLengths) InsetRect(r geom.RectangleF32) geom.RectangleF32 {
|
|
|
|
return Sides{
|
|
|
|
Left: l.Left.Value(),
|
|
|
|
Top: l.Top.Value(),
|
|
|
|
Right: l.Right.Value(),
|
|
|
|
Bottom: l.Bottom.Value(),
|
|
|
|
}.InsetRect(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l SideLengths) Zero(value float32) Sides {
|
|
|
|
return Sides{
|
|
|
|
Left: l.Left.Zero(value),
|
|
|
|
Top: l.Top.Zero(value),
|
|
|
|
Right: l.Right.Zero(value),
|
|
|
|
Bottom: l.Bottom.Zero(value),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type Sides struct {
|
|
|
|
Left float32
|
|
|
|
Top float32
|
|
|
|
Right float32
|
|
|
|
Bottom float32
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s Sides) InsetRect(r geom.RectangleF32) geom.RectangleF32 {
|
|
|
|
if r.Dx() < (s.Left + s.Right) {
|
|
|
|
r.Min.X += r.Dx() * s.Left / (s.Left + s.Right)
|
|
|
|
r.Max.X = r.Min.X
|
|
|
|
} else {
|
|
|
|
r.Min.X += s.Left
|
|
|
|
r.Max.X -= s.Right
|
|
|
|
}
|
|
|
|
if r.Dy() < (s.Top + s.Bottom) {
|
|
|
|
r.Min.Y += r.Dy() * s.Top / (s.Top + s.Bottom)
|
|
|
|
r.Max.Y = r.Min.Y
|
|
|
|
} else {
|
|
|
|
r.Min.Y += s.Top
|
|
|
|
r.Max.Y -= s.Bottom
|
|
|
|
}
|
|
|
|
return r
|
|
|
|
}
|