different themes along different instances not working
Hiya guys! Thanks for this lib, I love it!
I have a problem with different instances with different themes, I can't get the solution in the docs to work. With some digging I think it is a bug in SUIT.
I think the problem is in the line below, it has a hard reference to the local theme table created on line 5.
https://github.com/vrld/SUIT/blob/ecce6820d7b72d324796850760e3b2d32e7e3fee/theme.lua#L18
Here is game code, that should work, but doesn't.
local suit = require('suit')
local dress -- called the instance the same as in the documentation
function love.load()
dress = suit.new()
-- this is copied from the documentation, I only changed the color values
dress.theme = setmetatable({}, {__index = suit.theme})
-- NOTE: you have to replace the whole color table. E.g., replacing only
-- dress.theme.color.normal will also change suit.theme.color.normal!
dress.theme.color = {
normal = {bg = {255, 0, 0}, fg = { 0, 255, 0}},
hovered = {bg = {255, 0, 255}, fg = {255, 255, 0}},
active = {bg = {0, 255, 255}, fg = {255, 255, 0}}
}
end
function love.update(dt)
dress:Button('text', 100, 100, 100, 100)
end
function love.draw()
dress:draw()
end
In the mean time I solved it like this:
-- in love.load
instance.theme = require('suit/theme')
Then the instance get its own theme instance which I can mutate however I want
Thanks for reporting and pointing out the very line of the bug. Unfortunately, a minimally invasive fix is not obvious (at least not to me)…
Thanks for getting back so quickly!
I have an okay-ish general way that I do in my game code. Here is the code:
function getNewTheme()
package.loaded['suit/theme']=false
return require('suit/theme')
end
-- this is in love.load
instance1.theme = getNewTheme()
instance2.theme = getNewTheme()
-- now I can mess with the themes however I want
This could perhaps be a helper function in the lib, or something.
Whats the current state of theming atm? I would love to use this library for all in-game gui... rather than just a debug ui.