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:
Zachary Hall 2023-07-17 14:56:02 -07:00
parent c06b28ca11
commit c5265450d9
4 changed files with 46 additions and 35 deletions

View file

@ -2,7 +2,7 @@
#include "imfilebrowser.h"
FileBrowser::FileBrowser(bool save) {
FileBrowser::FileBrowser(bool save, ImGuiFileBrowserFlags extra_fallback_flags) {
#ifdef PORTALS
g_set_application_name("Neko Player");
main_context = g_main_context_default();
@ -12,7 +12,7 @@ FileBrowser::FileBrowser(bool save) {
inner_filter_type = g_variant_type_new("a(us)");
#endif
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) {
filter_name = name;
@ -63,9 +63,11 @@ path FileBrowser::GetSelected() {
#endif
}
void FileBrowser::SetWindowSize(int w, int h) {
window_size = ImVec2(w, h);
fallback.SetWindowSize(w, h);
}
void FileBrowser::SetWindowPos(int x, int y) {
window_pos = ImVec2(x, y);
fallback.SetWindowPos(x, y);
}
void FileBrowser::Open() {

View file

@ -25,8 +25,10 @@ class FileBrowser {
GMainContext *main_context;
static void FileBrowserOpenCallback(GObject *src, GAsyncResult *res, gpointer data);
static void FileBrowserSaveCallback(GObject *src, GAsyncResult *res, gpointer data);
bool open = false;
#endif
optional<ImVec2> window_pos;
ImVec2 window_size;
bool open = false;
bool save;
ImGui::FileBrowser fallback;
path pwd;
@ -46,6 +48,6 @@ class FileBrowser {
void Open();
void ClearSelected();
bool IsOpened();
FileBrowser(bool save);
FileBrowser(bool save, ImGuiFileBrowserFlags extra_fallback_flags = 0);
~FileBrowser();
};

View file

@ -27,6 +27,8 @@ enum ImGuiFileBrowserFlags_
ImGuiFileBrowserFlags_CloseOnEsc = 1 << 5, // close file browser when pressing 'ESC'
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_NoMove = 1 << 8, // Disable movement of the window
ImGuiFileBrowserFlags_NoResize = 1 << 9, // Disable resizing of the window
};
namespace ImGui
@ -332,22 +334,23 @@ inline void ImGui::FileBrowser::Display()
{
if (posIsSet_)
SetNextWindowPos(
ImVec2(static_cast<float>(posX_), static_cast<float>(posY_)),
ImGuiCond_FirstUseEver);
ImVec2(static_cast<float>(posX_), static_cast<float>(posY_)));
SetNextWindowSize(
ImVec2(static_cast<float>(width_), static_cast<float>(height_)),
ImGuiCond_FirstUseEver);
ImVec2(static_cast<float>(width_), static_cast<float>(height_)));
}
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;
}
}
else if(!BeginPopupModal(openLabel_.c_str(), nullptr,
flags_ & ImGuiFileBrowserFlags_NoTitleBar ?
ImGuiWindowFlags_NoTitleBar : 0))
(flags_ & ImGuiFileBrowserFlags_NoMove ? ImGuiWindowFlags_NoMove : 0) |
(flags_ & ImGuiFileBrowserFlags_NoResize ? ImGuiWindowFlags_NoResize : 0) |
(flags_ & ImGuiFileBrowserFlags_NoTitleBar ? ImGuiWindowFlags_NoTitleBar : 0)))
{
return;
}

View file

@ -177,7 +177,7 @@ int main(int, char**)
bool show_demo_window = false;
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.SetTypeFilters("Audio files", { ".wav", ".ogg", ".mp3", ".qoa", ".flac", ".xm", ".mod"});
std::string userdir = std::getenv(
@ -380,34 +380,38 @@ int main(int, char**)
ImGui::SetNextItemWidth(ImGui::GetWindowWidth() - ImGui::GetCursorPosX() - ImGui::GetStyle().WindowPadding.x);
ImGui::InputText("##FilterInput", filter, 1024);
ImGui::Text("Select a theme...");
ImVec2 ListBoxSize = ImVec2(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x * 2.0f), -ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().WindowPadding.y);
if (ImGui::BeginTable("##Themes", 2, 0, ListBoxSize)) {
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("Remove", ImGuiTableColumnFlags_WidthFixed);
for (auto themePath : Theme::availableThemes) {
if (themePath.stem().string().starts_with(filter)) {
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
const bool is_selected = themePath == theme->file_path;
if (ImGui::Selectable(themePath.stem().generic_string().c_str(), is_selected, 0)) {
delete theme;
theme = new Theme(themePath);
theme->Apply(accent_color);
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();
ImVec2 ChildSize = ImVec2(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x * 2.0f), -ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().WindowPadding.y);
if (ImGui::BeginChildFrame(ImGui::GetID("##ThemesContainer"), ChildSize)) {
ImVec2 TableSize = ImVec2(ImGui::GetWindowWidth() - (ImGui::GetStyle().WindowPadding.x), -ImGui::GetTextLineHeightWithSpacing() - ImGui::GetStyle().WindowPadding.y);
if (ImGui::BeginTable("##Themes", 2, 0, TableSize)) {
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("Remove", ImGuiTableColumnFlags_WidthFixed);
for (auto themePath : Theme::availableThemes) {
if (themePath.stem().string().starts_with(filter)) {
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
const bool is_selected = themePath == theme->file_path;
if (ImGui::Selectable(themePath.stem().generic_string().c_str(), is_selected, 0)) {
delete theme;
theme = new Theme(themePath);
theme->Apply(accent_color);
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));
if (ImGui::SliderFloat("##AccentColor", &accent_color, 0.0, 360.0, "UI hue: %.0f°", ImGuiSliderFlags_NoRoundToFormat)) {