Skip to content

Commit

Permalink
fix: width/height ignored by file dialog #1476 and added min/max sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffstadt committed Dec 13, 2021
1 parent afaf60c commit 638baf1
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DearPyGui/dearpygui/_dearpygui.pyi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions DearPyGui/dearpygui/_dearpygui_RTD.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions DearPyGui/dearpygui/dearpygui.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion DearPyGui/dearpygui/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ def _scroll_programmatically(sender, app_data, user_data):

with dpg.tree_node(label="File/Directory Selector"):

with dpg.file_dialog(label="Demo File Dialog", show=False, callback=lambda s, a, u : print(s, a, u), tag="__demo_filedialog"):
with dpg.file_dialog(label="Demo File Dialog", width=300, height=400, show=False, callback=lambda s, a, u : print(s, a, u), tag="__demo_filedialog"):
dpg.add_file_extension(".*", color=(255, 255, 255, 255))
dpg.add_file_extension("Source files (*.cpp *.h *.hpp){.cpp,.h,.hpp}", color=(0, 255, 255, 255))
dpg.add_file_extension(".cpp", color=(255, 255, 0, 255))
Expand Down
35 changes: 34 additions & 1 deletion DearPyGui/src/core/AppItems/composite/mvFileDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ namespace Marvel {
args.push_back({ mvPyDataType::Integer, "file_count", mvArgType::KEYWORD_ARG, "0", "Number of visible files in the dialog." });
args.push_back({ mvPyDataType::Bool, "modal", mvArgType::KEYWORD_ARG, "False", "Forces user interaction with the file selector." });
args.push_back({ mvPyDataType::Bool, "directory_selector", mvArgType::KEYWORD_ARG, "False", "Shows only directory/paths as options. Allows selection of directory/paths only." });
args.push_back({ mvPyDataType::IntList, "min_size", mvArgType::KEYWORD_ARG, "[100, 100]", "Minimum window size." });
args.push_back({ mvPyDataType::IntList, "max_size", mvArgType::KEYWORD_ARG, "[30000, 30000]", "Maximum window size." });

mvPythonParserSetup setup;
setup.about = "Displays a file or directory selector depending on keywords. Displays a file dialog by default. Callback will be ran when the file or directory picker is closed. The app_data arguemnt will be populated with information related to the file and directory as a dictionary.";
Expand Down Expand Up @@ -127,8 +129,25 @@ namespace Marvel {
{
//mvFontScope fscope(this);

if (_dirtyPos)
{
ImGui::SetNextWindowPos(_state.pos);
_dirtyPos = false;
}

if (_dirty_size)
{
ImGui::SetNextWindowSize(ImVec2((float)_width, (float)_height));
_dirty_size = false;
}

// display
if (_instance.Display(_internalLabel, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings, ImVec2(500, 600)))
if (_instance.IsOpened())
{
_state.rectSize = { _instance.windowSizeDPG.x, _instance.windowSizeDPG.y };
}

if (_instance.Display(_internalLabel, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings, _min_size, _max_size))
{

// action if OK
Expand Down Expand Up @@ -195,6 +214,18 @@ namespace Marvel {
if (PyObject* item = PyDict_GetItemString(dict, "modal")) _modal = ToBool(item);
if (PyObject* item = PyDict_GetItemString(dict, "directory_selector")) _directory = ToBool(item);

if (PyObject* item = PyDict_GetItemString(dict, "min_size"))
{
auto min_size = ToIntVect(item);
_min_size = { (float)min_size[0], (float)min_size[1] };
}

if (PyObject* item = PyDict_GetItemString(dict, "max_size"))
{
auto max_size = ToIntVect(item);
_max_size = { (float)max_size[0], (float)max_size[1] };
}

}

void mvFileDialog::getSpecificConfiguration(PyObject* dict)
Expand All @@ -218,6 +249,8 @@ namespace Marvel {
//PyDict_SetItemString(dict, "file_name_buffer", mvPyObject(ToPyString(_instance.FileNameBuffer)));
PyDict_SetItemString(dict, "current_path", mvPyObject(ToPyString(_instance.GetCurrentPath())));
PyDict_SetItemString(dict, "current_filter", mvPyObject(ToPyString(_instance.GetCurrentFilter())));
PyDict_SetItemString(dict, "min_size", mvPyObject(ToPyPair(_min_size.x, _min_size.y)));
PyDict_SetItemString(dict, "max_size", mvPyObject(ToPyPair(_max_size.x, _max_size.y)));

auto selections = _instance.GetSelection();

Expand Down
2 changes: 2 additions & 0 deletions DearPyGui/src/core/AppItems/composite/mvFileDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ namespace Marvel {
int _fileCount = 0;
bool _modal = false;
bool _directory = false;
mvVec2 _min_size = { 100.0f, 100.0f };
mvVec2 _max_size = { 30000.0f, 30000.0f };
};

}
2 changes: 2 additions & 0 deletions DearPyGui/vendor/ImGuiFileDialog/ImGuiFileDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3397,6 +3397,8 @@ namespace IGFD
}
#endif // IMGUI_HAS_VIEWPORT

windowSizeDPG = ImGui::GetWindowSize();

prFileDialogInternal.puName = name; //-V820
puAnyWindowsHovered |= ImGui::IsWindowHovered();

Expand Down
1 change: 1 addition & 0 deletions DearPyGui/vendor/ImGuiFileDialog/ImGuiFileDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,7 @@ namespace IGFD

public:
bool puAnyWindowsHovered = false; // not remember why haha :) todo : to check if we can remove
ImVec2 windowSizeDPG = ImVec2(0.0f, 0.0f);

public:
static FileDialog* Instance() // Singleton for easier accces form anywhere but only one dialog at a time
Expand Down

0 comments on commit 638baf1

Please sign in to comment.