Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/mvAppItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2666,6 +2666,7 @@ DearPyGui::GetEntityParser(mvAppItemType type)
args.push_back({ mvPyDataType::StringList, "items", mvArgType::POSITIONAL_ARG, "()", "A tuple of items to be shown in the listbox. Can consist of any combination of types. All items will be displayed as strings." });
args.push_back({ mvPyDataType::String, "default_value", mvArgType::KEYWORD_ARG, "''", "String value of the item that will be selected by default." });
args.push_back({ mvPyDataType::Integer, "num_items", mvArgType::KEYWORD_ARG, "3", "Expands the height of the listbox to show specified number of items." });
args.push_back({ mvPyDataType::Bool, "index_items", mvArgType::KEYWORD_ARG, "False", "Set the user_data to the index of the clicked item and not the item itself" });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description says the index would be in user_data, but the code actually puts it to app_data. The description needs to be corrected.


setup.about = "Adds a listbox. If height is not large enough to show all items a scroll bar will appear.";
break;
Expand Down
15 changes: 12 additions & 3 deletions src/mvBasicWidgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ DearPyGui::fill_configuration_dict(const mvListboxConfig& inConfig, PyObject* ou
return;
PyDict_SetItemString(outDict, "items", mvPyObject(ToPyList(inConfig.names)));
PyDict_SetItemString(outDict, "num_items", mvPyObject(ToPyInt(inConfig.itemsHeight)));
PyDict_SetItemString(outDict, "index", mvPyObject(ToPyBool(inConfig.sendindex)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the parser, the parameter is named "index_items". Here, its name is "index". Oops.

}

void
Expand Down Expand Up @@ -1172,6 +1173,7 @@ DearPyGui::set_configuration(PyObject* inDict, mvListboxConfig& outConfig, mvApp
return;

if (PyObject* item = PyDict_GetItemString(inDict, "num_items")) outConfig.itemsHeight = ToInt(item);
if (PyObject* item = PyDict_GetItemString(inDict, "index")) outConfig.sendindex = ToBool(item);
if (PyObject* item = PyDict_GetItemString(inDict, "items"))
{
outConfig.names = ToStringVect(item);
Expand Down Expand Up @@ -4743,9 +4745,16 @@ DearPyGui::draw_listbox(ImDrawList *drawlist, mvAppItem &item, mvListboxConfig &

if (ImGui::ListBox(item.info.internalLabel.c_str(), item.config.enabled ? &config.index : &config.disabledindex, config.charNames.data(), (int)config.names.size(), config.itemsHeight))
{
*config.value = config.names[config.index];
config.disabled_value = config.names[config.index];
auto value = *config.value;
if (config.sendindex) {
*config.value = std::to_string(config.index);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like the idea of converting the index to a string here. I think mvListbox::getPyValue() should handle it and return a string if index_items is False, and a number (the index) if it's True. The same for the callback: instead of converting the index to a string, it should call ToPyInt and return an integer.

config.disabled_value = std::to_string(config.index);
}
else {
*config.value = config.names[config.index];
config.disabled_value = config.names[config.index];
}

auto value = *config.value;

if(item.config.alias.empty())
mvSubmitCallback([&item, value]() {
Expand Down
1 change: 1 addition & 0 deletions src/mvBasicWidgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ struct mvListboxConfig
int disabledindex = 0;
std::shared_ptr<std::string> value = std::make_shared<std::string>("");
std::string disabled_value;
bool sendindex = false;
};

struct mvRadioButtonConfig
Expand Down