making config editable
This commit is contained in:
+33
-8
@@ -1,18 +1,43 @@
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
|
||||
#include <sophia/ui/panel.hpp>
|
||||
|
||||
namespace sophia {
|
||||
|
||||
void Panel::draw(const FrameInfo& frameInfo) {
|
||||
ImGuiWindowFlags flags = ImGuiWindowFlags_None;
|
||||
if (config.locked) {
|
||||
ImGuiWindowFlags Panel::Config::getWindowFlags() const {
|
||||
ImGuiWindowFlags flags = windowFlags;
|
||||
if (locked) {
|
||||
flags |= ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize |
|
||||
ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoCollapse;
|
||||
ImGuiWindowFlags_NoCollapse;
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
const ImGuiCond cond =
|
||||
config.locked ? ImGuiCond_Always : ImGuiCond_FirstUseEver;
|
||||
ImGuiDockNodeFlags Panel::Config::getDockNodeFlags() const {
|
||||
ImGuiDockNodeFlags flags = dockNodeFlags;
|
||||
if (locked) {
|
||||
flags |= static_cast<int>(ImGuiDockNodeFlags_NoUndocking) |
|
||||
static_cast<int>(ImGuiDockNodeFlags_NoResize) |
|
||||
static_cast<int>(ImGuiDockNodeFlags_NoCloseButton) |
|
||||
static_cast<int>(ImGuiDockNodeFlags_NoDockingOverMe) |
|
||||
static_cast<int>(ImGuiDockNodeFlags_NoDockingSplit);
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
bool Panel::Config::hasCloseButton() const { return closable && !locked; }
|
||||
|
||||
ImGuiCond Panel::Config::getPlacementCond() const {
|
||||
return locked ? ImGuiCond_Always : ImGuiCond_FirstUseEver;
|
||||
}
|
||||
|
||||
void Panel::draw(const FrameInfo& frameInfo) {
|
||||
ImGuiWindowClass windowClass;
|
||||
windowClass.DockNodeFlagsOverrideSet = config.getDockNodeFlags();
|
||||
ImGui::SetNextWindowClass(&windowClass);
|
||||
|
||||
const ImGuiCond cond = config.getPlacementCond();
|
||||
if (config.size.x > 0.0f || config.size.y > 0.0f) {
|
||||
ImGui::SetNextWindowSize(ImVec2(config.size.x, config.size.y), cond);
|
||||
}
|
||||
@@ -22,8 +47,8 @@ void Panel::draw(const FrameInfo& frameInfo) {
|
||||
}
|
||||
|
||||
bool open = true;
|
||||
const bool showCloseButton = config.closable && !config.locked;
|
||||
ImGui::Begin(config.name.c_str(), showCloseButton ? &open : nullptr, flags);
|
||||
ImGui::Begin(config.name.c_str(), config.hasCloseButton() ? &open : nullptr,
|
||||
config.getWindowFlags());
|
||||
onUpdate(frameInfo);
|
||||
ImGui::End();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user