Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

different themes along different instances not working #59

Open
ironchestgames opened this issue Oct 26, 2017 · 4 comments
Open

different themes along different instances not working #59

ironchestgames opened this issue Oct 26, 2017 · 4 comments

Comments

@ironchestgames
Copy link

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
Copy link
Author

ironchestgames commented Oct 27, 2017

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

@vrld
Copy link
Owner

vrld commented Oct 28, 2017

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

@ironchestgames
Copy link
Author

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.

@ghost
Copy link

ghost commented Dec 8, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants