Update open dialog and theme selector
The open dialog now fills the window The theme selector now has a background again.
This commit is contained in:
parent
c06b28ca11
commit
c5265450d9
4 changed files with 46 additions and 35 deletions
|
@ -2,7 +2,7 @@
|
||||||
#include "imfilebrowser.h"
|
#include "imfilebrowser.h"
|
||||||
|
|
||||||
|
|
||||||
FileBrowser::FileBrowser(bool save) {
|
FileBrowser::FileBrowser(bool save, ImGuiFileBrowserFlags extra_fallback_flags) {
|
||||||
#ifdef PORTALS
|
#ifdef PORTALS
|
||||||
g_set_application_name("Neko Player");
|
g_set_application_name("Neko Player");
|
||||||
main_context = g_main_context_default();
|
main_context = g_main_context_default();
|
||||||
|
@ -12,7 +12,7 @@ FileBrowser::FileBrowser(bool save) {
|
||||||
inner_filter_type = g_variant_type_new("a(us)");
|
inner_filter_type = g_variant_type_new("a(us)");
|
||||||
#endif
|
#endif
|
||||||
this->save = save;
|
this->save = save;
|
||||||
fallback = ImGui::FileBrowser(save ? ImGuiFileBrowserFlags_CreateNewDir|ImGuiFileBrowserFlags_EnterNewFilename : 0);
|
fallback = ImGui::FileBrowser((save ? ImGuiFileBrowserFlags_CreateNewDir|ImGuiFileBrowserFlags_EnterNewFilename : 0) + extra_fallback_flags);
|
||||||
}
|
}
|
||||||
void FileBrowser::SetTypeFilters(string name, vector<string> filters) {
|
void FileBrowser::SetTypeFilters(string name, vector<string> filters) {
|
||||||
filter_name = name;
|
filter_name = name;
|
||||||
|
@ -63,9 +63,11 @@ path FileBrowser::GetSelected() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
void FileBrowser::SetWindowSize(int w, int h) {
|
void FileBrowser::SetWindowSize(int w, int h) {
|
||||||
|
window_size = ImVec2(w, h);
|
||||||
fallback.SetWindowSize(w, h);
|
fallback.SetWindowSize(w, h);
|
||||||
}
|
}
|
||||||
void FileBrowser::SetWindowPos(int x, int y) {
|
void FileBrowser::SetWindowPos(int x, int y) {
|
||||||
|
window_pos = ImVec2(x, y);
|
||||||
fallback.SetWindowPos(x, y);
|
fallback.SetWindowPos(x, y);
|
||||||
}
|
}
|
||||||
void FileBrowser::Open() {
|
void FileBrowser::Open() {
|
||||||
|
|
|
@ -25,8 +25,10 @@ class FileBrowser {
|
||||||
GMainContext *main_context;
|
GMainContext *main_context;
|
||||||
static void FileBrowserOpenCallback(GObject *src, GAsyncResult *res, gpointer data);
|
static void FileBrowserOpenCallback(GObject *src, GAsyncResult *res, gpointer data);
|
||||||
static void FileBrowserSaveCallback(GObject *src, GAsyncResult *res, gpointer data);
|
static void FileBrowserSaveCallback(GObject *src, GAsyncResult *res, gpointer data);
|
||||||
bool open = false;
|
|
||||||
#endif
|
#endif
|
||||||
|
optional<ImVec2> window_pos;
|
||||||
|
ImVec2 window_size;
|
||||||
|
bool open = false;
|
||||||
bool save;
|
bool save;
|
||||||
ImGui::FileBrowser fallback;
|
ImGui::FileBrowser fallback;
|
||||||
path pwd;
|
path pwd;
|
||||||
|
@ -46,6 +48,6 @@ class FileBrowser {
|
||||||
void Open();
|
void Open();
|
||||||
void ClearSelected();
|
void ClearSelected();
|
||||||
bool IsOpened();
|
bool IsOpened();
|
||||||
FileBrowser(bool save);
|
FileBrowser(bool save, ImGuiFileBrowserFlags extra_fallback_flags = 0);
|
||||||
~FileBrowser();
|
~FileBrowser();
|
||||||
};
|
};
|
|
@ -27,6 +27,8 @@ enum ImGuiFileBrowserFlags_
|
||||||
ImGuiFileBrowserFlags_CloseOnEsc = 1 << 5, // close file browser when pressing 'ESC'
|
ImGuiFileBrowserFlags_CloseOnEsc = 1 << 5, // close file browser when pressing 'ESC'
|
||||||
ImGuiFileBrowserFlags_CreateNewDir = 1 << 6, // allow user to create new directory
|
ImGuiFileBrowserFlags_CreateNewDir = 1 << 6, // allow user to create new directory
|
||||||
ImGuiFileBrowserFlags_MultipleSelection = 1 << 7, // allow user to select multiple files. this will hide ImGuiFileBrowserFlags_EnterNewFilename
|
ImGuiFileBrowserFlags_MultipleSelection = 1 << 7, // allow user to select multiple files. this will hide ImGuiFileBrowserFlags_EnterNewFilename
|
||||||
|
ImGuiFileBrowserFlags_NoMove = 1 << 8, // Disable movement of the window
|
||||||
|
ImGuiFileBrowserFlags_NoResize = 1 << 9, // Disable resizing of the window
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace ImGui
|
namespace ImGui
|
||||||
|
@ -332,22 +334,23 @@ inline void ImGui::FileBrowser::Display()
|
||||||
{
|
{
|
||||||
if (posIsSet_)
|
if (posIsSet_)
|
||||||
SetNextWindowPos(
|
SetNextWindowPos(
|
||||||
ImVec2(static_cast<float>(posX_), static_cast<float>(posY_)),
|
ImVec2(static_cast<float>(posX_), static_cast<float>(posY_)));
|
||||||
ImGuiCond_FirstUseEver);
|
|
||||||
SetNextWindowSize(
|
SetNextWindowSize(
|
||||||
ImVec2(static_cast<float>(width_), static_cast<float>(height_)),
|
ImVec2(static_cast<float>(width_), static_cast<float>(height_)));
|
||||||
ImGuiCond_FirstUseEver);
|
|
||||||
}
|
}
|
||||||
if(flags_ & ImGuiFileBrowserFlags_NoModal)
|
if(flags_ & ImGuiFileBrowserFlags_NoModal)
|
||||||
{
|
{
|
||||||
if(!BeginPopup(openLabel_.c_str()))
|
if(!BeginPopup(openLabel_.c_str(),
|
||||||
|
(flags_ & ImGuiFileBrowserFlags_NoMove ? ImGuiWindowFlags_NoMove : 0) |
|
||||||
|
(flags_ & ImGuiFileBrowserFlags_NoResize ? ImGuiWindowFlags_NoResize : 0)))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(!BeginPopupModal(openLabel_.c_str(), nullptr,
|
else if(!BeginPopupModal(openLabel_.c_str(), nullptr,
|
||||||
flags_ & ImGuiFileBrowserFlags_NoTitleBar ?
|
(flags_ & ImGuiFileBrowserFlags_NoMove ? ImGuiWindowFlags_NoMove : 0) |
|
||||||
ImGuiWindowFlags_NoTitleBar : 0))
|
(flags_ & ImGuiFileBrowserFlags_NoResize ? ImGuiWindowFlags_NoResize : 0) |
|
||||||
|
(flags_ & ImGuiFileBrowserFlags_NoTitleBar ? ImGuiWindowFlags_NoTitleBar : 0)))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
52
main.cpp
52
main.cpp
|
@ -177,7 +177,7 @@ int main(int, char**)
|
||||||
bool show_demo_window = false;
|
bool show_demo_window = false;
|
||||||
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
||||||
|
|
||||||
FileBrowser fileDialog(false);
|
FileBrowser fileDialog(false, ImGuiFileBrowserFlags_NoTitleBar|ImGuiFileBrowserFlags_NoMove|ImGuiFileBrowserFlags_NoResize);
|
||||||
fileDialog.SetTitle("Open...");
|
fileDialog.SetTitle("Open...");
|
||||||
fileDialog.SetTypeFilters("Audio files", { ".wav", ".ogg", ".mp3", ".qoa", ".flac", ".xm", ".mod"});
|
fileDialog.SetTypeFilters("Audio files", { ".wav", ".ogg", ".mp3", ".qoa", ".flac", ".xm", ".mod"});
|
||||||
std::string userdir = std::getenv(
|
std::string userdir = std::getenv(
|
||||||
|
@ -380,34 +380,38 @@ int main(int, char**)
|
||||||
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - ImGui::GetCursorPosX() - ImGui::GetStyle().WindowPadding.x);
|
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - ImGui::GetCursorPosX() - ImGui::GetStyle().WindowPadding.x);
|
||||||
ImGui::InputText("##FilterInput", filter, 1024);
|
ImGui::InputText("##FilterInput", filter, 1024);
|
||||||
ImGui::Text("Select a theme...");
|
ImGui::Text("Select a theme...");
|
||||||
ImVec2 ListBoxSize = ImVec2(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x * 2.0f), -ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().WindowPadding.y);
|
ImVec2 ChildSize = ImVec2(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x * 2.0f), -ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().WindowPadding.y);
|
||||||
if (ImGui::BeginTable("##Themes", 2, 0, ListBoxSize)) {
|
if (ImGui::BeginChildFrame(ImGui::GetID("##ThemesContainer"), ChildSize)) {
|
||||||
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthStretch);
|
ImVec2 TableSize = ImVec2(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x), -ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().WindowPadding.y);
|
||||||
ImGui::TableSetupColumn("Remove", ImGuiTableColumnFlags_WidthFixed);
|
if (ImGui::BeginTable("##Themes", 2, 0, TableSize)) {
|
||||||
for (auto themePath : Theme::availableThemes) {
|
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthStretch);
|
||||||
if (themePath.stem().string().starts_with(filter)) {
|
ImGui::TableSetupColumn("Remove", ImGuiTableColumnFlags_WidthFixed);
|
||||||
ImGui::TableNextRow();
|
for (auto themePath : Theme::availableThemes) {
|
||||||
ImGui::TableSetColumnIndex(0);
|
if (themePath.stem().string().starts_with(filter)) {
|
||||||
const bool is_selected = themePath == theme->file_path;
|
ImGui::TableNextRow();
|
||||||
if (ImGui::Selectable(themePath.stem().generic_string().c_str(), is_selected, 0)) {
|
ImGui::TableSetColumnIndex(0);
|
||||||
delete theme;
|
const bool is_selected = themePath == theme->file_path;
|
||||||
theme = new Theme(themePath);
|
if (ImGui::Selectable(themePath.stem().generic_string().c_str(), is_selected, 0)) {
|
||||||
theme->Apply(accent_color);
|
delete theme;
|
||||||
break;
|
theme = new Theme(themePath);
|
||||||
}
|
theme->Apply(accent_color);
|
||||||
if (is_selected) {
|
|
||||||
ImGui::SetItemDefaultFocus();
|
|
||||||
} else {
|
|
||||||
ImGui::TableSetColumnIndex(1);
|
|
||||||
if (ImGui::SmallButton((string(ICON_FK_WINDOW_CLOSE "##") + themePath.stem().generic_string()).c_str())) {
|
|
||||||
std::filesystem::remove(themePath);
|
|
||||||
Theme::updateAvailableThemes();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (is_selected) {
|
||||||
|
ImGui::SetItemDefaultFocus();
|
||||||
|
} else {
|
||||||
|
ImGui::TableSetColumnIndex(1);
|
||||||
|
if (ImGui::SmallButton((string(ICON_FK_WINDOW_CLOSE "##") + themePath.stem().generic_string()).c_str())) {
|
||||||
|
std::filesystem::remove(themePath);
|
||||||
|
Theme::updateAvailableThemes();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ImGui::EndTable();
|
||||||
}
|
}
|
||||||
ImGui::EndTable();
|
ImGui::EndChildFrame();
|
||||||
}
|
}
|
||||||
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - (ImGui::GetStyle().FramePadding.x * 4));
|
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - (ImGui::GetStyle().FramePadding.x * 4));
|
||||||
if (ImGui::SliderFloat("##AccentColor", &accent_color, 0.0, 360.0, "UI hue: %.0f°", ImGuiSliderFlags_NoRoundToFormat)) {
|
if (ImGui::SliderFloat("##AccentColor", &accent_color, 0.0, 360.0, "UI hue: %.0f°", ImGuiSliderFlags_NoRoundToFormat)) {
|
||||||
|
|
Loading…
Reference in a new issue