suit icon indicating copy to clipboard operation
suit copied to clipboard

different themes along different instances not working

Open ironchestgames opened this issue 8 years ago • 4 comments

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

ironchestgames avatar Oct 26 '17 22:10 ironchestgames

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

ironchestgames avatar Oct 27 '17 21:10 ironchestgames

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)…

vrld avatar Oct 28 '17 10:10 vrld

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.

ironchestgames avatar Oct 28 '17 23:10 ironchestgames

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.

ghost avatar Dec 08 '17 16:12 ghost