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
36inline std::ostream& operator<<(std::ostream& os, const ImGuiStyle& style) {
37 os << "ImGuiStyle { "
38 << "Alpha: " << style.Alpha << ", "
39 << "DisabledAlpha: " << style.DisabledAlpha << ", "
40 << "WindowPadding: (" << style.WindowPadding.x << ", "
41 << style.WindowPadding.y << "), "
42 << "WindowRounding: " << style.WindowRounding << ", "
43 << "WindowBorderSize: " << style.WindowBorderSize << ", "
44 << "FramePadding: (" << style.FramePadding.x << ", "
45 << style.FramePadding.y << "), "
46 << "FrameRounding: " << style.FrameRounding << ", "
47 << "ItemSpacing: (" << style.ItemSpacing.x << ", " << style.ItemSpacing.y
48 << "), "
49 << "ScrollbarSize: " << style.ScrollbarSize << ", "
50 << "ScrollbarRounding: " << style.ScrollbarRounding << ", "
51 << "GrabMinSize: " << style.GrabMinSize << ", "
52 << "GrabRounding: " << style.GrabRounding << ", "
53 << "TabRounding: " << style.TabRounding << " }\n";
54
55 os << "Colors:\n";
56 for (int i = 0; i < ImGuiCol_COUNT; ++i) {
57 const ImVec4& col = style.Colors[i];
58 os << " [" << ImGuiCol_(i) << "] (" << col.x << ", " << col.y << ", "
59 << col.z << ", " << col.w << ")\n";
60 }
61
62 return os;
63}
64
70 public:
78 const char* filterList = nullptr, const char* defaultPath = nullptr)
79 : m_FilterList(filterList), m_DefaultPath(defaultPath) {}
80
87 [[nodiscard]] std::filesystem::path Open() const {
88 nfdchar_t* outPath = nullptr;
89 nfdresult_t result =
90 NFD_OpenDialog(m_FilterList, m_DefaultPath, &outPath);
91
92 if (result == NFD_OKAY) {
93 std::filesystem::path path(outPath);
94 std::free(outPath);
95 return path;
96 }
97 return {};
98 }
99
106 [[nodiscard]] std::filesystem::path Save() const {
107 nfdchar_t* outPath = nullptr;
108 nfdresult_t result =
109 NFD_SaveDialog(m_FilterList, m_DefaultPath, &outPath);
110
111 if (result == NFD_OKAY) {
112 std::filesystem::path path(outPath);
113 std::free(outPath);
114 return path;
115 }
116 return {};
117 }
118
125 [[nodiscard]] std::vector<std::filesystem::path> OpenMultiple() const {
126 nfdpathset_t pathSet;
127 nfdresult_t result =
128 NFD_OpenDialogMultiple(m_FilterList, m_DefaultPath, &pathSet);
129
130 if (result == NFD_OKAY) {
131 std::vector<std::filesystem::path> paths;
132 size_t count = NFD_PathSet_GetCount(&pathSet);
133 paths.reserve(count);
134 for (size_t i = 0; i < count; ++i) {
135 nfdchar_t* path = NFD_PathSet_GetPath(&pathSet, i);
136 paths.emplace_back(path);
137 }
138 NFD_PathSet_Free(&pathSet);
139 return paths;
140 }
141 return {};
142 }
143
150 [[nodiscard]] std::filesystem::path Dir() const {
151 nfdchar_t* outPath = nullptr;
152 nfdresult_t result = NFD_PickFolder(m_DefaultPath, &outPath);
153
154 if (result == NFD_OKAY) {
155 std::filesystem::path path(outPath);
156 std::free(outPath);
157 return path;
158 }
159 return {};
160 }
161
162 private:
163 const char* m_FilterList;
164 const char* m_DefaultPath;
165};
std::ostream & operator<<(std::ostream &os, const ImGuiStyle &style)
Streams a readable dump of an ImGui style object.
Definition Gui.h:36
std::filesystem::path Dir() const
Opens a directory picker dialog.
Definition Gui.h:150
const char * m_FilterList
Definition Gui.h:163
std::filesystem::path Save() const
Opens a save-file dialog.
Definition Gui.h:106
const char * m_DefaultPath
Definition Gui.h:164
std::vector< std::filesystem::path > OpenMultiple() const
Opens a multi-select file picker dialog.
Definition Gui.h:125
FileDialog(const char *filterList=nullptr, const char *defaultPath=nullptr)
Creates a file dialog helper with optional filter and start path.
Definition Gui.h:77
std::filesystem::path Open() const
Opens a single-file picker dialog.
Definition Gui.h:87