summaryrefslogtreecommitdiff
path: root/src/ui/imgui_extensions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/imgui_extensions.cpp')
-rw-r--r--src/ui/imgui_extensions.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/ui/imgui_extensions.cpp b/src/ui/imgui_extensions.cpp
index 8485dbf..483f5f6 100644
--- a/src/ui/imgui_extensions.cpp
+++ b/src/ui/imgui_extensions.cpp
@@ -6,6 +6,7 @@
#include "config.hpp"
#include "locales.hpp"
#include "administration.hpp"
+#include "tinyfiledialogs.h"
namespace ImGui
{
@@ -42,6 +43,47 @@ namespace ImGui
}
}
+ bool FormFileSelector(char* buffer)
+ {
+ bool result = false;
+ float widthAvailable = ImGui::GetContentRegionAvail().x;
+ ImGui::SetNextItemWidth(widthAvailable*0.5f);
+
+ if (ImGui::Button("Select file..."))
+ {
+ // You can adjust filters, title, default path
+ const char *filterPatterns[] = { "*.png", "*.jpg", "*.pdf", "*" };
+ const char *file = tinyfd_openFileDialog(
+ "Choose a file", // dialog title
+ NULL, // default path
+ 4, // number of filter patterns
+ filterPatterns, // filter patterns array
+ NULL, // single filter description (can be NULL)
+ 0); // allowMultiple (0 = single)
+ if (file)
+ {
+ strops_copy(buffer, file, MAX_LEN_PATH);
+ buffer[MAX_LEN_PATH-1] = '\0';
+ result = true;
+ }
+ }
+
+ if (buffer[0] != '\0')
+ {
+ ImGui::SameLine();
+ if (ImGui::Button("Clear"))
+ {
+ buffer[0] = '\0';
+ result = true;
+ }
+ ImGui::SameLine();
+ ImGui::TextWrapped("Selected: %s", buffer);
+
+ }
+
+ return result;
+ }
+
void FormCountryCombo(char* buffer, size_t buf_size)
{
const char* selected_country = 0;