ci/woodpecker/push/woodpecker Pipeline was successful
Registration order was the only thing deciding what a widget was drawn over, which forced a domain to keep one ordered list of every widget it owns — the one shape that cannot be split into a file per widget. A widget now says where it belongs: Layer, the eight LayerScene..LayerCursor constants, the optional Layered interface and LayerOf for wrappers. Draw runs from the bottom layer up, Tick from the top down, and registration order only breaks ties inside a layer. Every built-in declares its own; anything that stays quiet sits on LayerHUD, so existing HUDs come out where they were. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
29 lines
774 B
Go
29 lines
774 B
Go
package inkwell
|
|
|
|
import "sort"
|
|
|
|
// WidgetManager registers Widget instances. Same shape as every other manager.
|
|
type WidgetManager = Manager[Widget]
|
|
|
|
// reversedWidgets iterates from the top layer down — used by the engine
|
|
// for top-down input dispatch (the widget drawn on top gets the click
|
|
// first).
|
|
func reversedWidgets(m *WidgetManager) []Widget {
|
|
ordered := orderedWidgets(m)
|
|
out := make([]Widget, len(ordered))
|
|
for i, w := range ordered {
|
|
out[len(ordered)-1-i] = w
|
|
}
|
|
return out
|
|
}
|
|
|
|
// orderedWidgets iterates bottom-up draw order: by layer, and by
|
|
// registration order inside a layer.
|
|
func orderedWidgets(m *WidgetManager) []Widget {
|
|
all := m.All()
|
|
sort.SliceStable(all, func(i, j int) bool {
|
|
return LayerOf(all[i]) < LayerOf(all[j])
|
|
})
|
|
return all
|
|
}
|