Browse Source

Showing two of three ways to get the selected index of a listbox component.

David Piuva 3 years ago
parent
commit
510f4ce817
1 changed files with 4 additions and 2 deletions
  1. 4 2
      Source/SDK/guiExample/main.cpp

+ 4 - 2
Source/SDK/guiExample/main.cpp

@@ -46,7 +46,8 @@ void dsrMain(List<String> args) {
 	component_setKeyDownEvent(myListBox, [](const KeyboardEvent& event) {
 		if (event.dsrKey == DsrKey_Delete) {
 			// Delete from list
-			int64_t index = string_toInteger(component_call(myListBox, U"GetSelectedIndex"));
+			int64_t index = component_getProperty_integer(myListBox, U"SelectedIndex", false, 0);
+			//int64_t index = string_toInteger(component_call(myListBox, U"GetSelectedIndex")); // There is also a getter for the index
 			if (index > -1) {
 				component_call(myListBox, U"RemoveElement", string_combine(index));
 			}
@@ -60,7 +61,8 @@ void dsrMain(List<String> args) {
 	});
 	// Only triggered by mouse presses like any other component
 	component_setPressedEvent(myListBox, []() {
-		int64_t index = string_toInteger(component_call(myListBox, U"GetSelectedIndex"));
+		int64_t index = component_getProperty_integer(myListBox, U"SelectedIndex", false, 0);
+		//int64_t index = string_toInteger(component_call(myListBox, U"GetSelectedIndex")); // There is also a getter for the index
 		String content = component_call(myListBox, U"GetSelectedText");
 		printText("Pressed event: content is (", content, ") at index ", index, "\n");
 	});