Skip to content

Commit

Permalink
GUI: Settings window always pop at the top-left corner
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-dejoue committed Aug 26, 2023
1 parent 3be4dd0 commit 4c6d8fc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/gui/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ struct AppWindows
{
std::unique_ptr<SettingsWindow> settings;
std::vector<std::unique_ptr<PicrossFile>> picross;
struct
{
WindowLayout settings;
} layout;
};

void main_menu_bar(AppWindows& windows, bool& application_should_close, bool& gui_dark_mode)
Expand Down Expand Up @@ -185,7 +189,7 @@ int main(int argc, char *argv[])
if (windows.settings)
{
bool can_be_erased = false;
windows.settings->visit(can_be_erased);
windows.settings->visit(can_be_erased, windows.layout.settings);
assert(can_be_erased == false); // Always ON
}

Expand All @@ -195,7 +199,7 @@ int main(int argc, char *argv[])
#endif

// We delay the Settings window opening until after the first ImGui rendering pass so that the actual work space
// is known on first visit. This may be important for ImGui::Set* functions with ImGuiCond_Once.
// is known on first visit(). This is important for ImGui::Set* functions with flag ImGuiCond_Once.
if (!windows.settings) { windows.settings = std::make_unique<SettingsWindow>(settings); }

// Rendering
Expand Down
4 changes: 3 additions & 1 deletion src/gui/src/settings_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "settings.h"

#include <imgui_wrap.h>
#include "imgui_helpers.h"

#include <cassert>

Expand All @@ -13,12 +14,13 @@ SettingsWindow::SettingsWindow(Settings& settings)
{
}

void SettingsWindow::visit(bool& can_be_erased)
void SettingsWindow::visit(bool& can_be_erased, const WindowLayout& win_pos_sz)
{
can_be_erased = false; // Cannot close

ImGui::SetNextWindowSizeConstraints(ImVec2(0, 300), ImVec2(FLT_MAX, 600));

ImGui::SetNextWindowPosAndSize(win_pos_sz, ImGuiCond_Once);
constexpr ImGuiWindowFlags win_flags = ImGuiWindowFlags_AlwaysAutoResize
| ImGuiWindowFlags_NoSavedSettings;

Expand Down
4 changes: 3 additions & 1 deletion src/gui/src/settings_window.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "window_layout.h"

#include <string>

class Settings;
Expand All @@ -11,7 +13,7 @@ class SettingsWindow
SettingsWindow(const SettingsWindow&) = delete;
SettingsWindow& operator=(const SettingsWindow&) = delete;

void visit(bool& can_be_erased);
void visit(bool& can_be_erased, const WindowLayout& win_pos_sz);

private:
struct Animation
Expand Down

0 comments on commit 4c6d8fc

Please sign in to comment.