Element core now deals with Config and Theme objects
This commit is contained in:
parent
43fea5c8ba
commit
8d90dbdc92
@ -2,6 +2,8 @@ package core
|
|||||||
|
|
||||||
import "image"
|
import "image"
|
||||||
import "image/color"
|
import "image/color"
|
||||||
|
import "git.tebibyte.media/sashakoshka/tomo/theme"
|
||||||
|
import "git.tebibyte.media/sashakoshka/tomo/config"
|
||||||
import "git.tebibyte.media/sashakoshka/tomo/canvas"
|
import "git.tebibyte.media/sashakoshka/tomo/canvas"
|
||||||
|
|
||||||
// Core is a struct that implements some core functionality common to most
|
// Core is a struct that implements some core functionality common to most
|
||||||
@ -14,13 +16,25 @@ type Core struct {
|
|||||||
minimumHeight int
|
minimumHeight int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config config.Config
|
||||||
|
theme theme.Theme
|
||||||
|
|
||||||
drawSizeChange func ()
|
drawSizeChange func ()
|
||||||
|
onConfigChange func ()
|
||||||
|
onThemeChange func ()
|
||||||
onMinimumSizeChange func ()
|
onMinimumSizeChange func ()
|
||||||
onDamage func (region canvas.Canvas)
|
onDamage func (region canvas.Canvas)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCore creates a new element core and its corresponding control.
|
// NewCore creates a new element core and its corresponding control.
|
||||||
func NewCore (drawSizeChange func ()) (core *Core, control CoreControl) {
|
func NewCore (
|
||||||
|
drawSizeChange func (),
|
||||||
|
onConfigChange func (),
|
||||||
|
onThemeChange func (),
|
||||||
|
) (
|
||||||
|
core *Core,
|
||||||
|
control CoreControl,
|
||||||
|
) {
|
||||||
core = &Core { drawSizeChange: drawSizeChange }
|
core = &Core { drawSizeChange: drawSizeChange }
|
||||||
control = CoreControl { core: core }
|
control = CoreControl { core: core }
|
||||||
return
|
return
|
||||||
@ -82,6 +96,24 @@ func (core *Core) OnMinimumSizeChange (callback func ()) {
|
|||||||
core.onMinimumSizeChange = callback
|
core.onMinimumSizeChange = callback
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetConfig fulfills the elements.Configurable interface. This should not need
|
||||||
|
// to be overridden.
|
||||||
|
func (core *Core) SetConfig (config config.Config) {
|
||||||
|
core.config = config
|
||||||
|
if core.onConfigChange != nil {
|
||||||
|
core.onConfigChange()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTheme fulfills the elements.Themeable interface. This should not need
|
||||||
|
// to be overridden.
|
||||||
|
func (core *Core) SetTheme (theme theme.Theme) {
|
||||||
|
core.theme = theme
|
||||||
|
if core.onThemeChange != nil {
|
||||||
|
core.onThemeChange()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// CoreControl is a struct that can exert control over a Core struct. It can be
|
// CoreControl is a struct that can exert control over a Core struct. It can be
|
||||||
// used as a canvas. It must not be directly embedded into an element, but
|
// used as a canvas. It must not be directly embedded into an element, but
|
||||||
// instead kept as a private member. When a Core struct is created, a
|
// instead kept as a private member. When a Core struct is created, a
|
||||||
@ -147,3 +179,13 @@ func (control CoreControl) ConstrainSize (
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Config returns the current configuration.
|
||||||
|
func (control CoreControl) Config () (config.Config) {
|
||||||
|
return control.core.config
|
||||||
|
}
|
||||||
|
|
||||||
|
// Theme returns the current theme.
|
||||||
|
func (control CoreControl) Theme () (theme.Theme) {
|
||||||
|
return control.core.theme
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user