crash from pressing keys, related to textInput function in editor/ui.lua
This commit is contained in:
parent
56014fd8f6
commit
0f17b262e3
@ -9,13 +9,13 @@ ui.theme = {
|
||||
text_dim = {0.50, 0.50, 0.55}, -- low-key forgot
|
||||
accent = {0.27, 0.52, 0.90}, -- low-key also forgot
|
||||
hover = {0.22, 0.22, 0.25},
|
||||
active = {0.20, 0.40, 0.75}, -- i low-key forgot again
|
||||
active = {0.20, 0.40, 0.75}, -- i low-key forgot again, probably made for when a toggle or something is turned on
|
||||
}
|
||||
|
||||
ui.events = {}
|
||||
ui._wasDown = false
|
||||
ui._focused = nil
|
||||
|
||||
ui._inputs = {}
|
||||
|
||||
|
||||
function ui.emit(event)
|
||||
@ -67,4 +67,22 @@ function ui.text(x, y, w, h, text) -- expand on this, havent fully read the text
|
||||
love.graphics.printf(text, x, y + h/2-7, w, "center")
|
||||
end
|
||||
|
||||
function ui.textInput(x,y,w,h,placeholder)
|
||||
if ui.on(placeholder) then
|
||||
ui.button(x,y,w,h,tostring(ui._inputs[ui._focused]))
|
||||
else
|
||||
ui.button(x,y,w,h,placeholder)
|
||||
end
|
||||
end
|
||||
|
||||
function love.textinput(t)
|
||||
ui._inputs[ui._focused] = (tostring(ui._inputs[ui._focused] or "")) .. t
|
||||
end
|
||||
|
||||
function love.keypressed(key)
|
||||
if key == "backspace" then
|
||||
ui._inputs[ui._focused] = ui._inputs[ui._focused]:sub(tostring(ui._inputs[ui._focused]):len())
|
||||
end
|
||||
end
|
||||
|
||||
return ui
|
||||
3
main.lua
3
main.lua
@ -12,8 +12,9 @@ function love.draw()
|
||||
ui.panel(50,50,50,50)
|
||||
ui.button(100,200,100,100,"hello world")
|
||||
if ui.on("hello world") then -- detect if the button is pressed.
|
||||
ui.panel(250,250,250,250)
|
||||
ui.panel(250,250,100,100)
|
||||
end
|
||||
ui.textInput(50,400,100,100,"textInput")
|
||||
|
||||
ui.flush() -- KEEP AT END
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user