Make main windows docked, fix crashing bug when docking, and update ImGui

This commit is contained in:
Zachary Hall 2023-07-17 15:45:43 -07:00
parent c5265450d9
commit 3894aa8537
5 changed files with 23 additions and 10 deletions

View file

@ -4,7 +4,6 @@
FileBrowser::FileBrowser(bool save, ImGuiFileBrowserFlags extra_fallback_flags) {
#ifdef PORTALS
g_set_application_name("Neko Player");
main_context = g_main_context_default();
main_loop = g_main_loop_new(main_context, true);
portal = xdp_portal_new();

2
imgui

@ -1 +1 @@
Subproject commit d2291df55190e2f070af2635863f47a96d378a52
Subproject commit dc3e531ff28450bff73fde0163b1d076b6bb5605

View file

@ -68,6 +68,9 @@ string TimeToString(double time_code, uint8_t min_components = 1) {
// Main code
int main(int, char**)
{
#ifdef PORTALS
g_set_application_name("Neko Player");
#endif
bool enable_kms = std::getenv("LAP_KMS") != nullptr;
SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "false");
SDL_SetHint(SDL_HINT_APP_NAME, NAME);
@ -359,7 +362,7 @@ int main(int, char**)
ImGui::PopItemWidth();
}
ImGui::End();
if (prefs_window) {
if (prefs_window) {/*
ImVec2 min_size;
min_size.x = ImGui::GetFontSize() * 18;
min_size.y = (ImGui::GetFrameHeightWithSpacing() * 8) + (ImGui::GetFontSize());
@ -367,6 +370,8 @@ int main(int, char**)
max_size.x = 99999997952; // The compiler says that if this were just 9s it would be turned into this anyways.
max_size.y = 99999997952;
ImGui::SetNextWindowSizeConstraints(min_size, max_size);
*/
ImGui::SetNextWindowDockID(dockid);
ImGui::Begin("Preferences...", &prefs_window);
{
if (ImGui::Checkbox("Enable VSync", &vsync)) {
@ -411,8 +416,8 @@ int main(int, char**)
}
ImGui::EndTable();
}
ImGui::EndChildFrame();
}
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)) {
theme->Apply(accent_color);
@ -421,7 +426,7 @@ int main(int, char**)
ImGui::End();
}
if (theme_editor) {
Theme::ShowEditor(&theme_editor, theme);
Theme::ShowEditor(&theme_editor, theme, dockid, window_width, window_height);
theme->Apply(accent_color);
}
if (fileDialog.IsOpened()) {

View file

@ -26,11 +26,12 @@ ImVec4 change_accent_color(ImVec4 in, float hue) {
ImGui::ColorConvertHSVtoRGB(hsv.x, hsv.y, hsv.z, out.x, out.y, out.z);
return out;
}
bool Theme::ShowEditor(bool* open, Theme* &theme) {
static FileBrowser importDialog(false);
static FileBrowser exportDialog(true);
bool Theme::ShowEditor(bool* open, Theme* &theme, ImGuiID dockid, int window_width, int window_height) {
static FileBrowser importDialog(false, ImGuiFileBrowserFlags_NoTitleBar|ImGuiFileBrowserFlags_NoMove|ImGuiFileBrowserFlags_NoResize);
static FileBrowser exportDialog(true, ImGuiFileBrowserFlags_NoTitleBar|ImGuiFileBrowserFlags_NoMove|ImGuiFileBrowserFlags_NoResize);
static bool loadOpen = false;
static bool saveAsOpen = false;
ImGui::SetNextWindowDockID(dockid);
ImGui::Begin("Theme Editor", open);
ImGuiStyle& style = theme->style;
ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.50f);
@ -79,6 +80,14 @@ bool Theme::ShowEditor(bool* open, Theme* &theme) {
exportDialog.SetPwd(userdir);
exportDialog.Open();
}
if (importDialog.IsOpened()) {
importDialog.SetWindowSize(window_width, window_height);
importDialog.SetWindowPos(0, 0);
}
if (exportDialog.IsOpened()) {
exportDialog.SetWindowSize(window_width, window_height);
exportDialog.SetWindowPos(0, 0);
}
importDialog.Display();
exportDialog.Display();
if (!theme->file_path.empty()) {

View file

@ -17,7 +17,7 @@ class Theme {
static const char* prefPath;
string file_path;
std::set<int> HueEnabledColors;
static bool ShowEditor(bool *open, Theme* &theme);
static bool ShowEditor(bool *open, Theme* &theme, ImGuiID dockid, int window_width, int window_height);
void Apply(float hue);
void Save(string path);
void Save(path path);