Skip to content

Commit

Permalink
UI: let the inputfile panel also support the saving dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
mgerhardy committed Nov 28, 2024
1 parent 1c7abd8 commit 834112e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
14 changes: 10 additions & 4 deletions src/modules/ui/IMGUIEx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,21 @@ bool InputVarString(const char *label, const core::VarPtr &var, ImGuiInputTextFl
return false;
}

void InputFile(const char *label, core::String *file, const io::FormatDescription *descriptions,
void InputFile(const char *label, bool load, core::String *file, const io::FormatDescription *descriptions,
ImGuiInputTextFlags flags, const video::FileDialogOptions &options) {
InputText(label, file, flags);
SameLine();
const core::String id = core::string::format(ICON_LC_FILE "##%s", label);
if (Button(id.c_str())) {
imguiApp()->openDialog([file] (const core::String &filename, const io::FormatDescription *desc) {
*file = filename;
}, options, descriptions);
if (load) {
imguiApp()->openDialog([file] (const core::String &filename, const io::FormatDescription *desc) {
*file = filename;
}, options, descriptions);
} else {
imguiApp()->saveDialog([file] (const core::String &filename, const io::FormatDescription *desc) {
*file = filename;
}, options, descriptions);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/ui/IMGUIEx.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ IMGUI_API void LoadingIndicatorCircle(const char *label, const float indicator_r
const ImVec4 &main_color = ImVec4(1.0f, 1.0f, 1.0f, 1.0f),
const ImVec4 &backdrop_color = ImVec4(0.0f, 0.0f, 0.5f, 1.0f),
const int circle_count = 13, const float speed = 1.0f);
IMGUI_API void InputFile(const char *label, core::String *file, const io::FormatDescription *descriptions,
IMGUI_API void InputFile(const char *label, bool load, core::String *file, const io::FormatDescription *descriptions,
ImGuiInputTextFlags flags = 0u, const video::FileDialogOptions &options = {});
IMGUI_API void InputFolder(const char *label, core::String *folder, ImGuiInputTextFlags flags = 0u);
IMGUI_API float CalcTextWidth(const char *text, bool withPadding = true);
Expand Down
4 changes: 2 additions & 2 deletions src/tools/voxconvert/VoxConvertUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ void VoxConvertUI::onRenderUI() {
ImGui::EndMenuBar();
}

ImGui::InputFile(_("Source"), &_sourceFile, voxelformat::voxelLoad());
ImGui::InputFile(_("Target"), &_targetFile, voxelformat::voxelSave());
ImGui::InputFile(_("Source"), true, &_sourceFile, voxelformat::voxelLoad());
ImGui::InputFile(_("Target"), false, &_targetFile, voxelformat::voxelSave());

const io::FormatDescription *sourceDesc = nullptr;
if (!_sourceFile.empty()) {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/voxedit/modules/voxedit-ui/BrushPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ void BrushPanel::updateTextBrushPanel(command::CommandExecutionListener &listene
ImGui::Separator();
addBrushClampingOption(brush);

ImGui::InputFile(_("Font"), &brush.font(), io::format::fonts(), ImGuiInputTextFlags_ReadOnly);
ImGui::InputFile(_("Font"), true, &brush.font(), io::format::fonts(), ImGuiInputTextFlags_ReadOnly);
if (brush.font() != _lastFont) {
_lastFont = brush.font();
brush.markDirty();
Expand Down
2 changes: 1 addition & 1 deletion src/tools/voxedit/modules/voxedit-ui/ScriptPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ bool ScriptPanel::updateScriptExecutionPanel(command::CommandExecutionListener &
}
case voxelgenerator::LUAParameterType::File: {
core::String &str = _scriptParameters[i];
ImGui::InputFile(p.name.c_str(), &str, nullptr);
ImGui::InputFile(p.name.c_str(), true, &str, nullptr);
break;
}
case voxelgenerator::LUAParameterType::Enum: {
Expand Down

0 comments on commit 834112e

Please sign in to comment.