From 0f17b262e34873b943ea7fc8402e9a43107d12a9 Mon Sep 17 00:00:00 2001 From: JayK Date: Sat, 23 May 2026 18:56:00 -0700 Subject: [PATCH] crash from pressing keys, related to textInput function in editor/ui.lua --- editor/ui.lua | 22 ++++++++++++++++++++-- main.lua | 5 +++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/editor/ui.lua b/editor/ui.lua index 63a1ad6..a0d8070 100644 --- a/editor/ui.lua +++ b/editor/ui.lua @@ -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 \ No newline at end of file diff --git a/main.lua b/main.lua index b6718fc..dbeb86c 100644 --- a/main.lua +++ b/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 \ No newline at end of file