-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImGuiFD.h
134 lines (100 loc) · 3.14 KB
/
ImGuiFD.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#ifndef __IMGUIFD_H__
#define __IMGUIFD_H__
#define IMGUIFD_VERSION "0.1 alpha"
#define IMGUIFD_VERSION_NUM 0
// uncomment this for stl support
//#define IMGUIFD_ENABLE_STL 1
#ifdef _MSC_VER
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS 1
#endif
#endif
#define IMGUI_DEFINE_MATH_OPERATORS 1
#include "imgui.h"
#include <stdint.h>
#include <ctime>
/*
Example Filters:
NULL
"*"
"*.txt"
"."
"{*},{*.txt,*.text}"
"{*},{Text Files:*.txt,*.text}"
*/
enum {
ImGuiFDMode_LoadFile = 0,
ImGuiFDMode_SaveFile,
ImGuiFDMode_OpenDir,
};
typedef uint8_t ImGuiFDMode;
enum {
ImGuiFDDialogFlags_Modal = 1<<0
};
typedef int ImGuiFDDialogFlags;
namespace ImGuiFD {
struct DirEntry {
public:
DirEntry();
DirEntry(const DirEntry& src);
DirEntry& operator=(const DirEntry& src);
~DirEntry();
ImGuiID id = (ImGuiID)-1;
const char* name = 0;
const char* dir = 0;
const char* path = 0;
bool isFolder = false;
uint64_t size = (uint64_t)-1;
time_t lastModified = -1;
time_t creationDate = -1;
};
struct GlobalSettings {
bool showDirFirst = true;
bool adjustIconWidth = true;
ImVec4 iconTextCol = { .08f, .08f, .78f, 1 };
const float iconModeSizeDef = 100;
float iconModeSize = iconModeSizeDef;
enum {
DisplayMode_List = 0,
DisplayMode_Icons = 1
};
uint8_t displayMode = DisplayMode_Icons;
ImVec4 descTextCol = { .7f, .7f, .7f, 1 };
bool asciiArtIcons = true;
};
static GlobalSettings settings;
struct FileData {
struct Image {
ImTextureID texID;
int width;
int height;
int origWidth = -1;
int origHeight = -1;
uint64_t memSize;
void* userData = 0;
bool dimDone = false;
bool loadDone = false;
}* thumbnail;
bool loadingFinished = false;
uint64_t getSize() const;
};
typedef FileData* (*RequestFileDataCallback)(const DirEntry& entry, int maxDimSize);
typedef void (*FreeFileDataCallback)(ImGuiID id);
void SetFileDataCallback(RequestFileDataCallback loadCallB, FreeFileDataCallback unloadCallB);
void GetFileDialog(const char* str_id, const char* filter, const char* path, ImGuiFDDialogFlags flags = 0, size_t maxSelections = 1);
void OpenDialog(const char* str_id, ImGuiFDMode mode, const char* path, const char* filter = NULL, ImGuiFDDialogFlags flags = 0, size_t maxSelections = 1);
void CloseDialog(const char* str_id);
void CloseCurrentDialog();
bool BeginDialog(const char* str_id);
bool BeginDialog(ImGuiID id);
void EndDialog();
bool ActionDone(); // was Open/Cancel (=> anything) pressed?
bool SelectionMade(); // was Open (and not Cancel) pressed?
const char* GetResultStringRaw();
size_t GetSelectionStringsAmt();
const char* GetSelectionNameString(size_t ind);
const char* GetSelectionPathString(size_t ind);
void DrawDebugWin(const char* str_id);
void Shutdown();
}
#endif