From ca4d3e62c47d8d173a88887727907173a85735f7 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Fri, 7 Jun 2024 18:57:16 -0400 Subject: [PATCH] Remedy #10 --- backend.go | 11 +++++++++++ icon.go | 2 ++ object.go | 2 ++ theme.go | 10 ++-------- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/backend.go b/backend.go index ba987b1..a6a9bfa 100644 --- a/backend.go +++ b/backend.go @@ -33,6 +33,17 @@ type Backend interface { // must reject any canvas that was not made by it. NewCanvas (image.Rectangle) canvas.CanvasCloser + // SetStyle sets the style that will be used on objects. The backend is + // in charge of applying the style to objects. When this method is + // called, it must propagate a StyleChange event to all boxes it is + // keeping track of. + SetStyle (Style) + + // SetIcons sets the icon set that icons will be pulled from. When this + // method is called, it must propagate an IconChange event to all boxes + // it is keeping track of. + SetIcons (Icons) + // Run runs the event loop until Stop() is called, or the backend // experiences a fatal error. Run () error diff --git a/icon.go b/icon.go index 8895605..31d6be0 100644 --- a/icon.go +++ b/icon.go @@ -419,5 +419,7 @@ var icons Icons // SetIcons sets the icon set. func SetIcons (icns Icons) { + assertBackend() icons = icns + backend.SetIcons(icns) } diff --git a/object.go b/object.go index 5cb53e7..8a46bfa 100644 --- a/object.go +++ b/object.go @@ -124,6 +124,8 @@ type Box interface { OnScroll (func (deltaX, deltaY float64)) event.Cookie OnKeyDown (func (key input.Key, numberPad bool)) event.Cookie OnKeyUp (func (key input.Key, numberPad bool)) event.Cookie + OnStyleChange (func ()) event.Cookie + OnIconsChange (func ()) event.Cookie } // CanvasBox is a box that can be drawn to. diff --git a/theme.go b/theme.go index 1d09649..8621c33 100644 --- a/theme.go +++ b/theme.go @@ -77,13 +77,7 @@ var style Style // SetStyle sets the style. func SetStyle (sty Style) { + assertBackend() style = sty -} - -// Apply applies the current style to the given object, according its role. This -// may register event listeners with the given object; closing the returned -// cookie will remove them. -func Apply (object Object) event.Cookie { - if style == nil { return event.NoCookie { } } - return style.Apply(object) + backend.SetStyle(sty) }