Ver Fonte

clamp selected_idx of ListBox

John Dodis há 1 ano atrás
pai
commit
5f1db41faa
1 ficheiros alterados com 4 adições e 0 exclusões
  1. 4 0
      ui2d/ui2d.lua

+ 4 - 0
ui2d/ui2d.lua

@@ -1415,6 +1415,10 @@ function UI2D.ListBox( name, num_visible_rows, num_visible_chars, collection, se
 		y_offset = y_offset + font.h
 	end
 
+	if #collection > 0 then
+		listbox_state[ lst_idx ].selected_idx = Clamp( listbox_state[ lst_idx ].selected_idx, 0, #collection )
+	end
+
 	return result, listbox_state[ lst_idx ].selected_idx
 end