package ui import "opslag.de/schobers/geom" var _ Control = &Overlays{} type Overlays struct { Proxy overlays map[string]Control order []string visible map[string]bool } func NewOverlays(over Control) *Overlays { return &Overlays{ Proxy: Proxy{Content: over}, overlays: map[string]Control{}, visible: map[string]bool{}, } } func (o *Overlays) AddOnTop(name string, control Control, visible bool) { o.order = append(o.order, name) o.overlays[name] = control o.visible[name] = visible } func (o *Overlays) AddOnBottom(name string, control Control, visible bool) { o.order = append([]string{name}, o.order...) o.overlays[name] = control o.visible[name] = visible } func (o *Overlays) Arrange(ctx Context, bounds geom.RectangleF32, offset geom.PointF32, parent Control) { o.Proxy.Arrange(ctx, bounds, offset, parent) for _, overlay := range o.overlays { overlay.Arrange(ctx, bounds, offset, parent) } } func (o *Overlays) Handle(ctx Context, e Event) { for overlay, visible := range o.visible { if visible { o.overlays[overlay].Handle(ctx, e) } } o.Proxy.Handle(ctx, e) } func (o *Overlays) Hide(name string) { o.visible[name] = false } func (o *Overlays) Render(ctx Context) { o.Proxy.Render(ctx) for overlay, visible := range o.visible { if visible { o.overlays[overlay].Render(ctx) } } } func (o *Overlays) Show(name string) { o.visible[name] = true } func (o *Overlays) Toggle(name string) { o.visible[name] = !o.visible[name] }