Skip to content

Commit

Permalink
Fixing Issue hoffstadt#1236
Browse files Browse the repository at this point in the history
  • Loading branch information
Mstpyt committed Jan 5, 2023
1 parent d742791 commit 22e2b69
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
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" });

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)));
}

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);
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

0 comments on commit 22e2b69

Please sign in to comment.