Skip to content

Commit

Permalink
Merge pull request #9 from brainrom/main
Browse files Browse the repository at this point in the history
ListBox selected value
  • Loading branch information
immortalx74 committed Nov 24, 2022
2 parents c3a6ebe + af6fce6 commit df3969e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ui/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1447,13 +1447,23 @@ function UI.TextBox( name, num_visible_chars, buffer )
return got_focus, buffer_changed, my_id, textbox_state[ tb_idx ].text
end

function UI.ListBox( name, num_visible_rows, num_visible_chars, collection )
function UI.ListBox( name, num_visible_rows, num_visible_chars, collection, selected )
local cur_window = windows[ #windows ]
local my_id = Hash( cur_window.name .. name )
local lst_idx = FindId( listbox_state, my_id )

if lst_idx == nil then
local l = { id = my_id, scroll = 1, selected_idx = 1 }
local selected_idx = 1
if (type(selected)=="number") then selected_idx = selected
elseif (type(selected)=="string") then
for i=1,#collection do
if selected == collection[i] then
selected_idx = i
break
end
end
end
local l = { id = my_id, scroll = 1, selected_idx = selected_idx }
table.insert( listbox_state, l )
lst_idx = #listbox_state
end
Expand Down

0 comments on commit df3969e

Please sign in to comment.