looper/backends/ui/imgui/file_browser.h

58 lines
1.5 KiB
C
Raw Normal View History

#pragma once
#include "config.h"
#include <string>
#include <vector>
#include <filesystem>
#include <optional>
2024-04-24 09:59:51 -07:00
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
#ifdef PORTALS
#include <libportal/portal.h>
#include <libportal/filechooser.h>
#endif
#include "imgui/imgui.h"
#include "imgui-filebrowser/imfilebrowser.h"
using std::string;
using std::vector;
using std::optional;
using namespace std::filesystem;
class FileBrowser {
#ifdef PORTALS
XdpPortal *portal;
GVariant *variant = NULL;
GVariantType *type = NULL;
GVariantType *inner_filter_type = NULL;
GMainLoop *main_loop;
GMainContext *main_context;
static void FileBrowserOpenCallback(GObject *src, GAsyncResult *res, gpointer data);
static void FileBrowserSaveCallback(GObject *src, GAsyncResult *res, gpointer data);
#endif
2024-04-24 09:59:51 -07:00
ImGuiFileBrowserFlags flags;
optional<ImVec2> window_pos;
ImVec2 window_size;
bool open = false;
bool save;
ImGui::FileBrowser fallback;
path pwd;
string filter_name;
vector<string> filters;
string title;
optional<path> selected;
public:
void SetTitle(string title);
void SetTypeFilters(string name, vector<string> filters);
void SetPwd(path path);
bool HasSelected();
path GetSelected();
void SetWindowSize(int width, int height);
void SetWindowPos(int x, int y);
void Display();
void Open();
void ClearSelected();
bool IsOpened();
FileBrowser(bool save, ImGuiFileBrowserFlags extra_fallback_flags = 0);
~FileBrowser();
};