FuncDoodle
Loading...
Searching...
No Matches
Gui.h
Go to the documentation of this file.
1
16
17#pragma once
18
19#include <cstdlib>
20#include <filesystem>
21#include <imgui.h>
22#include <imgui_impl_glfw.h>
23#include <imgui_impl_opengl3.h>
24#include <imgui_internal.h>
25#include <nfd.h>
26#include <ostream>
27#include <vector>
28
33inline ImGuiCol InvertedImCol(uint8_t r, uint8_t g, uint8_t b) {
34 return IM_COL32(255 - r, 255 - g, 255 - b, 255);
35}
36
44inline std::ostream& operator<<(std::ostream& os, const ImGuiStyle& style) {
45 os << "ImGuiStyle { "
46 << "Alpha: " << style.Alpha << ", "
47 << "DisabledAlpha: " << style.DisabledAlpha << ", "
48 << "WindowPadding: (" << style.WindowPadding.x << ", "
49 << style.WindowPadding.y << "), "
50 << "WindowRounding: " << style.WindowRounding << ", "
51 << "WindowBorderSize: " << style.WindowBorderSize << ", "
52 << "FramePadding: (" << style.FramePadding.x << ", "
53 << style.FramePadding.y << "), "
54 << "FrameRounding: " << style.FrameRounding << ", "
55 << "ItemSpacing: (" << style.ItemSpacing.x << ", " << style.ItemSpacing.y
56 << "), "
57 << "ScrollbarSize: " << style.ScrollbarSize << ", "
58 << "ScrollbarRounding: " << style.ScrollbarRounding << ", "
59 << "GrabMinSize: " << style.GrabMinSize << ", "
60 << "GrabRounding: " << style.GrabRounding << ", "
61 << "TabRounding: " << style.TabRounding << " }\n";
62
63 os << "Colors:\n";
64 for (int i = 0; i < ImGuiCol_COUNT; ++i) {
65 const ImVec4& col = style.Colors[i];
66 os << " [" << ImGuiCol_(i) << "] (" << col.x << ", " << col.y << ", "
67 << col.z << ", " << col.w << ")\n";
68 }
69
70 return os;
71}
72
78 public:
86 const char* filterList = nullptr, const char* defaultPath = nullptr)
87 : m_FilterList(filterList), m_DefaultPath(defaultPath) {}
88
95 [[nodiscard]] std::filesystem::path Open() const {
96 nfdchar_t* outPath = nullptr;
97 nfdresult_t result =
98 NFD_OpenDialog(m_FilterList, m_DefaultPath, &outPath);
99
100 if (result == NFD_OKAY) {
101 std::filesystem::path path(outPath);
102 std::free(outPath);
103 return path;
104 }
105 return {};
106 }
107
114 [[nodiscard]] std::filesystem::path Save() const {
115 nfdchar_t* outPath = nullptr;
116 nfdresult_t result =
117 NFD_SaveDialog(m_FilterList, m_DefaultPath, &outPath);
118
119 if (result == NFD_OKAY) {
120 std::filesystem::path path(outPath);
121 std::free(outPath);
122 return path;
123 }
124 return {};
125 }
126
133 [[nodiscard]] std::vector<std::filesystem::path> OpenMultiple() const {
134 nfdpathset_t pathSet;
135 nfdresult_t result =
136 NFD_OpenDialogMultiple(m_FilterList, m_DefaultPath, &pathSet);
137
138 if (result == NFD_OKAY) {
139 std::vector<std::filesystem::path> paths;
140 size_t count = NFD_PathSet_GetCount(&pathSet);
141 paths.reserve(count);
142 for (size_t i = 0; i < count; ++i) {
143 nfdchar_t* path = NFD_PathSet_GetPath(&pathSet, i);
144 paths.emplace_back(path);
145 }
146 NFD_PathSet_Free(&pathSet);
147 return paths;
148 }
149 return {};
150 }
151
158 [[nodiscard]] std::filesystem::path Dir() const {
159 nfdchar_t* outPath = nullptr;
160 nfdresult_t result = NFD_PickFolder(m_DefaultPath, &outPath);
161
162 if (result == NFD_OKAY) {
163 std::filesystem::path path(outPath);
164 std::free(outPath);
165 return path;
166 }
167 return {};
168 }
169
170 private:
171 const char* m_FilterList;
172 const char* m_DefaultPath;
173};
ImGuiCol InvertedImCol(uint8_t r, uint8_t g, uint8_t b)
Definition Gui.h:33
std::ostream & operator<<(std::ostream &os, const ImGuiStyle &style)
Streams a readable dump of an ImGui style object.
Definition Gui.h:44
std::filesystem::path Dir() const
Opens a directory picker dialog.
Definition Gui.h:158
const char * m_FilterList
Definition Gui.h:171
std::filesystem::path Save() const
Opens a save-file dialog.
Definition Gui.h:114
const char * m_DefaultPath
Definition Gui.h:172
std::vector< std::filesystem::path > OpenMultiple() const
Opens a multi-select file picker dialog.
Definition Gui.h:133
FileDialog(const char *filterList=nullptr, const char *defaultPath=nullptr)
Creates a file dialog helper with optional filter and start path.
Definition Gui.h:85
std::filesystem::path Open() const
Opens a single-file picker dialog.
Definition Gui.h:95