Page 9 of 9

Re: [Lib] SUIT - Simple User Interface Toolkit

Posted: Tue Feb 18, 2020 4:14 am
by pgimeno
Try suit.isHovered instead if suit:isHovered.

Yes, the docs could be a bit clearer on this point.

Re: [Lib] SUIT - Simple User Interface Toolkit

Posted: Wed Feb 26, 2020 5:27 pm
by megalukes
pgimeno wrote: Tue Feb 18, 2020 4:14 am Try suit.isHovered instead if suit:isHovered.

Yes, the docs could be a bit clearer on this point.
It worked! Thank you!

Re: [Lib] SUIT - Simple User Interface Toolkit

Posted: Tue Oct 15, 2024 2:47 pm
by ClaudeM
miko wrote: Tue Jan 05, 2016 9:33 am Is it possible to set a widget state? Currently the widget is active when a mouse is hovering over it, but I would like to use keyboard to select buttons (and see which is selected/active), and input to get a focus even if the mouse is not over it.
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
I expected the setActive function to do this, but the implementation is a test returning a boolean.

Code: Select all

function suit:setActive(id)
	return self.active ~= nil
end
Question for Matthias Richter: I thought the following code would help, but it seems to do nothing. Is it possible to get this function to make the widget active? How does SUIT remember that I have clicked the input widget?

Code: Select all

function suit:setActive(id)
	self.active = id
	self.hovered = id
--	return self.active ~= nil
end
Thank you.