Fixed style application

This commit is contained in:
Sasha Koshka 2024-06-12 00:39:00 -04:00
parent 02de78c997
commit 6619987b5a
3 changed files with 19 additions and 15 deletions

View File

@ -479,6 +479,7 @@ func (this *box) setParent (parent parent) {
this.SetFocused(false) this.SetFocused(false)
} }
this.parent = parent this.parent = parent
this.recursiveReApply()
} }
func (this *box) getParent () parent { func (this *box) getParent () parent {
@ -527,6 +528,8 @@ func (this *box) invalidateMinimum () {
} }
func (this *box) recursiveReApply () { func (this *box) recursiveReApply () {
if this.getHierarchy() == nil { return }
// re-apply styling, icons *if needed* // re-apply styling, icons *if needed*
// style // style

View File

@ -13,10 +13,6 @@ type Hierarchy struct {
system *System system *System
canvas canvas.Canvas canvas canvas.Canvas
style tomo.Style
styleNonce int
iconsNonce int
root anyBox root anyBox
focused anyBox focused anyBox
hovered anyBox hovered anyBox
@ -146,14 +142,11 @@ func (this *Hierarchy) Close () {
this.system.removeHierarchy(this) this.system.removeHierarchy(this)
} }
func (this *Hierarchy) setStyle (style tomo.Style) { func (this *Hierarchy) setStyle () {
this.style = style
this.styleNonce ++
if this.root != nil { this.root.recursiveReApply() } if this.root != nil { this.root.recursiveReApply() }
} }
func (this *Hierarchy) setIcons (icons tomo.Icons) { func (this *Hierarchy) setIcons () {
this.iconsNonce ++
if this.root != nil { this.root.recursiveReApply() } if this.root != nil { this.root.recursiveReApply() }
} }
@ -166,15 +159,15 @@ func (this *Hierarchy) getWindow () tomo.Window {
} }
func (this *Hierarchy) getStyle () tomo.Style { func (this *Hierarchy) getStyle () tomo.Style {
return this.style return this.system.style
} }
func (this *Hierarchy) getStyleNonce () int { func (this *Hierarchy) getStyleNonce () int {
return this.styleNonce return this.system.styleNonce
} }
func (this *Hierarchy) getIconsNonce () int { func (this *Hierarchy) getIconsNonce () int {
return this.iconsNonce return this.system.iconsNonce
} }
func (this *Hierarchy) getCanvas () canvas.Canvas { func (this *Hierarchy) getCanvas () canvas.Canvas {

View File

@ -10,6 +10,11 @@ import "git.tebibyte.media/tomo/backend/internal/util"
// and Boxes. // and Boxes.
type System struct { type System struct {
link BackendLink link BackendLink
style tomo.Style
styleNonce int
iconsNonce int
hierarchies util.Set[*Hierarchy] hierarchies util.Set[*Hierarchy]
} }
@ -41,15 +46,18 @@ func New (link BackendLink) *System {
// SetStyle sets the tomo.Style that is applied to objects, and notifies them // SetStyle sets the tomo.Style that is applied to objects, and notifies them
// that the style has changed. // that the style has changed.
func (this *System) SetStyle (style tomo.Style) { func (this *System) SetStyle (style tomo.Style) {
this.style = style
this.styleNonce ++
for hierarchy := range this.hierarchies { for hierarchy := range this.hierarchies {
hierarchy.setStyle(style) hierarchy.setStyle()
} }
} }
// SetIcons notifies objects that the icons have changed. // SetIcons notifies objects that the icons have changed.
func (this *System) SetIcons (icons tomo.Icons) { func (this *System) SetIcons (icons tomo.Icons) {
this.iconsNonce ++
for hierarchy := range this.hierarchies { for hierarchy := range this.hierarchies {
hierarchy.setIcons(icons) hierarchy.setIcons()
} }
} }