making config editable

This commit is contained in:
2026-09-19 21:13:41 -07:00
parent da6bda7ca7
commit f814ad969f
3 changed files with 49 additions and 14 deletions
+15 -5
View File
@@ -1,5 +1,7 @@
#pragma once
#include <imgui.h>
#include <glm/glm.hpp>
#include <optional>
#include <sophia/frame_info.hpp>
@@ -11,9 +13,11 @@ namespace sophia {
class Panel {
public:
struct Config {
std::string name;
const std::string name;
ImGuiWindowFlags windowFlags = ImGuiWindowFlags_None;
ImGuiDockNodeFlags dockNodeFlags = ImGuiDockNodeFlags_None;
// Locked panels can't be moved, resized, docked, collapsed or closed.
bool locked = false;
bool closable = true;
@@ -21,20 +25,27 @@ class Panel {
// every frame when locked.
glm::vec2 size{0.0f, 0.0f};
std::optional<glm::vec2> position;
ImGuiWindowFlags getWindowFlags() const;
ImGuiDockNodeFlags getDockNodeFlags() const;
bool hasCloseButton() const;
ImGuiCond getPlacementCond() const;
};
Panel(const Panel&) = delete;
Panel& operator=(const Panel&) = delete;
Panel(Panel&&) noexcept = default;
Panel& operator=(Panel&&) noexcept = default;
Panel& operator=(Panel&&) = delete;
explicit Panel(Config config) : config{std::move(config)} {}
virtual ~Panel() = default;
// Owns the ImGui window: Begin, onUpdate, End.
void draw(const FrameInfo& frameInfo);
Config& getConfig() { return config; }
const Config& getConfig() const { return config; }
const std::string& getName() const { return config.name; }
bool isLocked() const { return config.locked; }
@@ -43,7 +54,6 @@ class Panel {
void toggleVisible() { this->visible = !this->visible; }
protected:
// Draw the panel's contents; the window is already open.
virtual void onUpdate(const FrameInfo& frameInfo) = 0;
bool visible = true;