airstruck / luigi

Lovely User Interfaces for Game Inventors
MIT License
114 stars 23 forks source link

How to integrate the layout with love2d? #57

Closed iddm closed 7 years ago

iddm commented 7 years ago

I want to implement my options dialog in my game with using luigi. Here is what I have:

local Layout = require("luigi.layout")

local Options = {}
Options.__index = Options

function Options.new(quit_callback)
    local self = setmetatable({}, Options)
    self.__quit = quit_callback
    self.layout = Layout(require("layouts.options"))
    return self
end

function Options:keypressed(key)
    if key == "escape" then
        self.layout:hide()
        self:__quit()
    end
end

function Options:draw()
    self.layout:show()
end

return Options

And the layout.options is the copy of example/layout/main.lua file. Everything works fine (it shows) then I call "draw" of Options object but I don't see any way to hide it. I want to be able to hide it by pressing escape as you can see in the Options:keypressed method.

P.S. If you are interested in my keypressed, draw methods - they are simply a delegates of love.keypressed, love.draw and other functions; I use custom stacked-view widget which passes it's top value to the love and it's top object's functions are called.

iddm commented 7 years ago

Okay, I understand. This happened because luigi menu hooked escape event but left other keys to work normally. Removing the menu from the layout or changing key check to anything else but escape makes it work.

iddm commented 7 years ago

But calling these functions does not hide the layout actually.. So, I am able to call the functions, but self.layout:hide() does not hide it, it remains on the screen.

iddm commented 7 years ago

Again, my fail. The code was not calling this delegate directly.