zntg/ui/visual.go

45 lines
941 B
Go
Raw Permalink Normal View History

2019-04-11 18:03:36 +00:00
package ui
import (
"image/color"
2019-04-11 18:03:36 +00:00
"opslag.de/schobers/geom"
)
func Background(content Control, c color.Color) Control {
return &background{Proxy: Proxy{Content: content}, Background: c}
}
type background struct {
2019-04-11 18:03:36 +00:00
Proxy
Background color.Color
}
func (b *background) Render(ctx Context) {
bounds := b.Proxy.Bounds()
if b.Background != nil {
ctx.Renderer().FillRectangle(bounds, b.Background)
}
b.Proxy.Render(ctx)
2019-04-11 18:03:36 +00:00
}
func Shadow(content Control) *shadow {
s := &shadow{}
s.Content = content
return s
}
type shadow struct {
Proxy
}
2019-04-11 18:03:36 +00:00
func (s *shadow) Render(ctx Context) {
s.Proxy.Render(ctx)
b := s.Bounds()
shadow := RGBA(0xBD, 0xBD, 0xBD, 0x2F)
ctx.Renderer().FillRectangle(geom.RectF32(b.Min.X, b.Min.Y, b.Max.X, b.Min.Y+3), shadow)
ctx.Renderer().FillRectangle(geom.RectF32(b.Min.X, b.Min.Y, b.Max.X, b.Min.Y+2), shadow)
ctx.Renderer().FillRectangle(geom.RectF32(b.Min.X, b.Min.Y, b.Max.X, b.Min.Y+1), shadow)
}