Try suit.isHovered instead if suit:isHovered.
Yes, the docs could be a bit clearer on this point.
[Lib] SUIT - Simple User Interface Toolkit
Re: [Lib] SUIT - Simple User Interface Toolkit
There is another option: When using an immediate mode GUI, we keep state in the game (the library does not do this for us). In the following code, the input variable keeps the state of the input widget and accumulates the input string. We can also use it for force focus, but we must be careful to do this only once. Try doing this every time; the result is funny.
Code: Select all
-- suit up
--
local suit = require 'suit'
local font
local name = ""
local have_name = false
-- storage and control for text input
--
local input = {text = ""}
local focused = false
function love.load()
font = love.graphics.newFont("JosefinSans-Regular.ttf", 20)
love.graphics.setFont(font)
end
-- all the UI is defined in love.update or functions that are called from here
--
function love.update(dt)
-- put the layout origin at position (100,100)
-- the layout will grow down and to the right from this point
--
local state
suit.layout:reset(100,100)
-- put a label widget at the layout origin, with a cell size of 200 by 30 pixels
--
suit.Label("Please type your name.", {align = "left"}, suit.layout:row(300,30))
-- force focus, only once
--
if not focused then
input.forcefocus = true
focused = true
end
-- capture input
--
state = suit.Input(input, {id = "name"}, suit.layout:row())
if state.submitted then
print( input.text )
name = input.text
have_name = true
end
end
function love.draw()
-- draw the gui
--
suit.draw()
if have_name then
love.graphics.setFont(font,24)
love.graphics.print(name, 300, 300)
end
end
function love.textedited(text, start, length)
-- for IME input
--
suit.textedited(text, start, length)
end
function love.textinput(t)
-- forward text input to SUIT
--
suit.textinput(t)
end
function love.keypressed(key)
-- forward keypresses to SUIT
--
suit.keypressed(key)
-- allow q to quit
--
if key == "q" then
love.event.quit()
end
end
Code: Select all
function suit:setActive(id)
return self.active ~= nil
end
Code: Select all
function suit:setActive(id)
self.active = id
self.hovered = id
-- return self.active ~= nil
end
Who is online
Users browsing this forum: No registered users and 3 guests