@@ -4,25 +4,49 @@ local errorManager = require("errorManager")
44
55local defaultTheme = {
66 default = {
7- background = colors .lightGray ,
7+ background = colors .cyan ,
88 foreground = colors .black ,
99 },
1010 BaseFrame = {
1111 background = colors .white ,
1212 foreground = colors .black ,
1313
14- Frame = {
14+ Container = {
15+ default = {
16+ background = colors .cyan ,
17+ foreground = colors .black ,
18+ },
1519 background = colors .black ,
16- names = {
17- basaltDebugLogClose = {
18- background = colors .blue ,
19- foreground = colors .white
20+ Button = {
21+ background = colors .cyan ,
22+ foreground = colors .black ,
23+ states = {
24+ clicked = {
25+ background = colors .white ,
26+ foreground = colors .black ,
27+ }
2028 }
2129 },
30+ Input = {
31+ background = colors .cyan ,
32+ foreground = colors .black ,
33+ },
34+ Label = {
35+ foreground = colors .white ,
36+ },
2237 },
2338 Button = {
2439 background = colors .cyan ,
2540 foreground = colors .black ,
41+ states = {
42+ clicked = {
43+ background = colors .black ,
44+ foreground = colors .cyan ,
45+ }
46+ }
47+ },
48+ Label = {
49+ foreground = colors .black ,
2650 },
2751
2852 names = {
@@ -96,26 +120,6 @@ local function lookUpTemplate(theme, path)
96120 return current
97121end
98122
99- local function getDefaultProperties (theme , elementType )
100- local result = {}
101- if theme .default then
102- for k ,v in pairs (theme .default ) do
103- if type (v ) ~= " table" then
104- result [k ] = v
105- end
106- end
107-
108- if theme .default [elementType ] then
109- for k ,v in pairs (theme .default [elementType ]) do
110- if type (v ) ~= " table" then
111- result [k ] = v
112- end
113- end
114- end
115- end
116- return result
117- end
118-
119123local function applyNamedStyles (result , theme , elementType , elementName , themeTable )
120124 if theme .default and theme .default .names and theme .default .names [elementName ] then
121125 for k ,v in pairs (theme .default .names [elementName ]) do
@@ -139,17 +143,46 @@ end
139143
140144local function collectThemeProps (theme , path , elementType , elementName )
141145 local result = {}
142- local themeTable = lookUpTemplate (theme , path )
143- if themeTable then
144- for k ,v in pairs (themeTable ) do
146+ if theme .default then
147+ for k ,v in pairs (theme .default ) do
145148 if type (v ) ~= " table" then
146149 result [k ] = v
147150 end
148151 end
149152 end
153+ local current = theme
154+ for i = 1 , # path do
155+ local types = path [i ]
156+ local found = false
157+
158+ for _ , elementType in ipairs (types ) do
159+ if current [elementType ] then
160+ current = current [elementType ]
161+ found = true
162+ if current .default then
163+ for k ,v in pairs (current .default ) do
164+ if type (v ) ~= " table" then
165+ result [k ] = v
166+ end
167+ end
168+ end
169+ break
170+ end
171+ end
172+
173+ if not found then
174+ current = nil
175+ break
176+ end
177+ end
150178
151- if next (result ) == nil then
152- result = getDefaultProperties (theme , elementType )
179+ local themeTable = lookUpTemplate (theme , path )
180+ if themeTable then
181+ for k ,v in pairs (themeTable ) do
182+ if type (v ) ~= " table" or k == " states" then
183+ result [k ] = v
184+ end
185+ end
153186 end
154187
155188 applyNamedStyles (result , theme , elementType , elementName , themeTable )
@@ -163,22 +196,53 @@ end
163196--- @param applyToChildren boolean ? Whether to apply theme to child elements (default : true )
164197--- @return BaseElement self The element instance
165198function BaseElement :applyTheme (applyToChildren )
199+ local backup = {}
200+ if self ._modifiedProperties then
201+ for prop , _ in pairs (self ._modifiedProperties ) do
202+ backup [prop ] = true
203+ end
204+ end
205+
166206 local styles = self :getTheme ()
167207 if (styles ~= nil ) then
168208 for prop , value in pairs (styles ) do
169- local config = self ._properties [prop ]
170- if (config )then
171- if ((config .type )== " color" )then
172- if (type (value )== " string" )then
173- if (colors [value ])then
174- value = colors [value ]
209+ if prop ~= " states" and not backup [prop ] then
210+ local config = self ._properties [prop ]
211+ if (config )then
212+ if ((config .type )== " color" )then
213+ if (type (value )== " string" )then
214+ if (colors [value ])then
215+ value = colors [value ]
216+ end
217+ end
218+ end
219+ self .set (prop , value )
220+ end
221+ end
222+ end
223+ if styles .states then
224+ for stateName , stateConfig in pairs (styles .states ) do
225+ for prop , value in pairs (stateConfig ) do
226+ if prop ~= " priority" then
227+ local config = self ._properties [prop ]
228+ local capitalizedName = prop :sub (1 ,1 ):upper () .. prop :sub (2 )
229+ if (config )then
230+ if ((config .type )== " color" )then
231+ if (type (value )== " string" )then
232+ if (colors [value ])then
233+ value = colors [value ]
234+ end
235+ end
236+ end
237+ self [" set" .. capitalizedName .. " State" ](self , stateName , value )
175238 end
176239 end
177240 end
178- self .set (prop , value )
179241 end
180242 end
181243 end
244+ self ._modifiedProperties = backup
245+
182246 if (applyToChildren ~= false )then
183247 if (self :isType (" Container" ))then
184248 local children = self .get (" children" )
0 commit comments