Added a label to textboxes

This commit is contained in:
j4nk 2025-03-22 20:58:58 -04:00
parent 1f9a366025
commit 6ccade6e7c
2 changed files with 7 additions and 6 deletions

View File

@ -10,9 +10,9 @@ function oct_init()
-- textbox["y"] = 20
-- textbox["shape"] = "___________"
-- textbox["fg"] = TB_RED
textbox1 = create_textbox("textbox1", 50, 20, 20)
textbox2 = create_textbox("textbox2", 50, 22, 20)
textbox3 = create_textbox("textbox3", 50, 24, 20)
textbox1 = create_textbox("textbox1", 50, 20, 20, "textbox1: ")
textbox2 = create_textbox("textbox2", 50, 22, 20, "textbox2: ")
textbox3 = create_textbox("textbox3", 50, 24, 20, "textbox3: ")
register_textbox(textbox1)
register_textbox(textbox1)
register_textbox(textbox2)

7
ui.lua
View File

@ -9,11 +9,11 @@ require("termbox_defs")
-- upon a switch (i.e. TAB key), the list is rotated
registered_textboxes = {}
function create_textbox(id, pos_x, pos_y, max_length)
function create_textbox(id, pos_x, pos_y, max_length, label)
t = oct_tb_sprite_new()
t["x"] = pos_x
t["y"] = pos_y
t["shape"] = string.rep("_", max_length) -- what is displayed to user
t["shape"] = label .. string.rep("_", max_length) -- what is displayed to user
t["fg"] = TB_WHITE
local textbox = {}
@ -21,6 +21,7 @@ function create_textbox(id, pos_x, pos_y, max_length)
textbox["contents"] = "" -- what is returned when box is submitted
textbox["max_length"] = max_length
textbox["id"] = id
textbox["label"] = label
return textbox
end
@ -105,7 +106,7 @@ function handle_textbox(key, ch)
end
-- Update the user-visible sprite
registered_textboxes[1]["sprite"]["shape"] = textbox_contents_to_shape(registered_textboxes[1]["contents"], registered_textboxes[1]["max_length"])
registered_textboxes[1]["sprite"]["shape"] = registered_textboxes[1]["label"] .. textbox_contents_to_shape(registered_textboxes[1]["contents"], registered_textboxes[1]["max_length"])
-- Submit our registered textboxes
if (key == TB_KEY_ENTER)