소스 검색

clamp selected_idx of ListBox

John Dodis 1 년 전
부모
커밋
5f1db41faa
1개의 변경된 파일4개의 추가작업 그리고 0개의 파일을 삭제
  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