Redid the entity system a bit to make it more reliable

Now it supports things like parenting elements before they are
added to a window and elements no longer have to constantly check
for a nil entity
This commit is contained in:
2023-04-15 01:14:36 -04:00
parent 5cf0b162c0
commit 437aef0c27
12 changed files with 129 additions and 96 deletions

View File

@@ -3,6 +3,8 @@ package x
import "image"
import "git.tebibyte.media/sashakoshka/tomo"
import "git.tebibyte.media/sashakoshka/tomo/canvas"
import "git.tebibyte.media/sashakoshka/tomo/default/theme"
import "git.tebibyte.media/sashakoshka/tomo/default/config"
type entitySet map[*entity] struct { }
@@ -24,8 +26,8 @@ type system struct {
focused *entity
canvas canvas.BasicCanvas
theme tomo.Theme
config tomo.Config
theme theme.Wrapped
config config.Wrapped
invalidateIgnore bool
drawingInvalid entitySet
@@ -41,7 +43,7 @@ func (system *system) initialize () {
}
func (system *system) SetTheme (theme tomo.Theme) {
system.theme = theme
system.theme.Theme = theme
system.propagate (func (entity *entity) bool {
if child, ok := system.child.element.(tomo.Themeable); ok {
child.SetTheme(theme)
@@ -51,7 +53,7 @@ func (system *system) SetTheme (theme tomo.Theme) {
}
func (system *system) SetConfig (config tomo.Config) {
system.config = config
system.config.Config = config
system.propagate (func (entity *entity) bool {
if child, ok := system.child.element.(tomo.Configurable); ok {
child.SetConfig(config)