Moves BeginGroupPanel to GuiWindow (#284)

This is where it is actually used.
This commit is contained in:
Kenix3
2023-05-22 21:40:16 -04:00
committed by GitHub
parent 6d29ff2dbc
commit 65e2c6e07d
6 changed files with 155 additions and 146 deletions
-122
View File
@@ -641,128 +641,6 @@ void Gui::LoadGuiTexture(const std::string& name, const std::string& path, const
mGuiTextures[name] = asset;
}
void Gui::BeginGroupPanel(const char* name, const ImVec2& size) {
ImGui::BeginGroup();
// auto cursorPos = ImGui::GetCursorScreenPos();
auto itemSpacing = ImGui::GetStyle().ItemSpacing;
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.0f, 0.0f));
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 0.0f));
auto frameHeight = ImGui::GetFrameHeight();
ImGui::BeginGroup();
ImVec2 effectiveSize = size;
if (size.x < 0.0f) {
effectiveSize.x = ImGui::GetContentRegionAvail().x;
} else {
effectiveSize.x = size.x;
}
ImGui::Dummy(ImVec2(effectiveSize.x, 0.0f));
ImGui::Dummy(ImVec2(frameHeight * 0.5f, 0.0f));
ImGui::SameLine(0.0f, 0.0f);
ImGui::BeginGroup();
ImGui::Dummy(ImVec2(frameHeight * 0.5f, 0.0f));
ImGui::SameLine(0.0f, 0.0f);
ImGui::TextUnformatted(name);
auto labelMin = ImGui::GetItemRectMin();
auto labelMax = ImGui::GetItemRectMax();
ImGui::SameLine(0.0f, 0.0f);
ImGui::Dummy(ImVec2(0.0, frameHeight + itemSpacing.y));
ImGui::BeginGroup();
// ImGui::GetWindowDrawList()->AddRect(labelMin, labelMax, IM_COL32(255, 0, 255, 255));
ImGui::PopStyleVar(2);
#if IMGUI_VERSION_NUM >= 17301
ImGui::GetCurrentWindow()->ContentRegionRect.Max.x -= frameHeight * 0.5f;
ImGui::GetCurrentWindow()->WorkRect.Max.x -= frameHeight * 0.5f;
ImGui::GetCurrentWindow()->InnerRect.Max.x -= frameHeight * 0.5f;
#else
ImGui::GetCurrentWindow()->ContentsRegionRect.Max.x -= frameHeight * 0.5f;
#endif
ImGui::GetCurrentWindow()->Size.x -= frameHeight;
auto itemWidth = ImGui::CalcItemWidth();
ImGui::PushItemWidth(ImMax(0.0f, itemWidth - frameHeight));
mGroupPanelLabelStack.push_back(ImRect(labelMin, labelMax));
}
void Gui::EndGroupPanel(float minHeight) {
ImGui::PopItemWidth();
auto itemSpacing = ImGui::GetStyle().ItemSpacing;
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.0f, 0.0f));
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 0.0f));
auto frameHeight = ImGui::GetFrameHeight();
ImGui::EndGroup();
ImGui::EndGroup();
ImGui::SameLine(0.0f, 0.0f);
ImGui::Dummy(ImVec2(frameHeight * 0.5f, 0.0f));
ImGui::Dummy(ImVec2(0.0, std::max(frameHeight - frameHeight * 0.5f - itemSpacing.y, minHeight)));
ImGui::EndGroup();
auto itemMin = ImGui::GetItemRectMin();
auto itemMax = ImGui::GetItemRectMax();
// ImGui::GetWindowDrawList()->AddRectFilled(itemMin, itemMax, IM_COL32(255, 0, 0, 64), 4.0f);
auto labelRect = mGroupPanelLabelStack.back();
mGroupPanelLabelStack.pop_back();
ImVec2 halfFrame = ImVec2(frameHeight * 0.25f, frameHeight) * 0.5f;
ImRect frameRect = ImRect(itemMin + halfFrame, itemMax - ImVec2(halfFrame.x, 0.0f));
labelRect.Min.x -= itemSpacing.x;
labelRect.Max.x += itemSpacing.x;
for (int i = 0; i < 4; ++i) {
switch (i) {
// left half-plane
case 0:
ImGui::PushClipRect(ImVec2(-FLT_MAX, -FLT_MAX), ImVec2(labelRect.Min.x, FLT_MAX), true);
break;
// right half-plane
case 1:
ImGui::PushClipRect(ImVec2(labelRect.Max.x, -FLT_MAX), ImVec2(FLT_MAX, FLT_MAX), true);
break;
// top
case 2:
ImGui::PushClipRect(ImVec2(labelRect.Min.x, -FLT_MAX), ImVec2(labelRect.Max.x, labelRect.Min.y), true);
break;
// bottom
case 3:
ImGui::PushClipRect(ImVec2(labelRect.Min.x, labelRect.Max.y), ImVec2(labelRect.Max.x, FLT_MAX), true);
break;
}
ImGui::GetWindowDrawList()->AddRect(frameRect.Min, frameRect.Max,
ImColor(ImGui::GetStyleColorVec4(ImGuiCol_Border)), halfFrame.x);
ImGui::PopClipRect();
}
ImGui::PopStyleVar(2);
#if IMGUI_VERSION_NUM >= 17301
ImGui::GetCurrentWindow()->ContentRegionRect.Max.x += frameHeight * 0.5f;
ImGui::GetCurrentWindow()->WorkRect.Max.x += frameHeight * 0.5f;
ImGui::GetCurrentWindow()->InnerRect.Max.x += frameHeight * 0.5f;
#else
ImGui::GetCurrentWindow()->ContentsRegionRect.Max.x += frameHeight * 0.5f;
#endif
ImGui::GetCurrentWindow()->Size.x += frameHeight;
ImGui::Dummy(ImVec2(0.0f, 0.0f));
ImGui::EndGroup();
}
std::shared_ptr<GameOverlay> Gui::GetGameOverlay() {
return mGameOverlay;
}
+3 -3
View File
@@ -1,7 +1,9 @@
#pragma once
#ifdef __cplusplus
#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif
#include <ImGui/imgui.h>
#include <ImGui/imgui_internal.h>
#include <memory>
@@ -12,6 +14,7 @@
#include "window/gui/GameOverlay.h"
#include "window/gui/InputViewer.h"
#include "window/gui/StatsWindow.h"
#include "window/gui/GuiWindow.h"
#include "window/gui/GuiMenuBar.h"
#include "libultraship/libultra/controller.h"
@@ -73,8 +76,6 @@ class Gui {
void LoadGuiTexture(const std::string& name, const std::string& path, const ImVec4& tint);
ImTextureID GetTextureByName(const std::string& name);
bool SupportsViewports();
void BeginGroupPanel(const char* name, const ImVec2& size);
void EndGroupPanel(float minHeight);
std::shared_ptr<GuiWindow> GetGuiWindow(const std::string& name);
std::shared_ptr<GameOverlay> GetGameOverlay();
std::shared_ptr<InputViewer> GetInputViewer();
@@ -105,7 +106,6 @@ class Gui {
std::shared_ptr<GuiMenuBar> mMenuBar;
std::map<std::string, GuiTexture> mGuiTextures;
std::map<std::string, std::shared_ptr<GuiWindow>> mGuiWindows;
ImVector<ImRect> mGroupPanelLabelStack;
};
} // namespace LUS
+123 -1
View File
@@ -1,4 +1,4 @@
#include "window/gui/GuiWindow.h"
#include "GuiWindow.h"
namespace LUS {
GuiWindow::GuiWindow(const std::string& consoleVariable, bool isVisible, const std::string& name)
@@ -12,4 +12,126 @@ GuiWindow::GuiWindow(const std::string& consoleVariable, const std::string& name
std::string GuiWindow::GetName() {
return mName;
}
void GuiWindow::BeginGroupPanel(const char* name, const ImVec2& size) {
ImGui::BeginGroup();
// auto cursorPos = ImGui::GetCursorScreenPos();
auto itemSpacing = ImGui::GetStyle().ItemSpacing;
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.0f, 0.0f));
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 0.0f));
auto frameHeight = ImGui::GetFrameHeight();
ImGui::BeginGroup();
ImVec2 effectiveSize = size;
if (size.x < 0.0f) {
effectiveSize.x = ImGui::GetContentRegionAvail().x;
} else {
effectiveSize.x = size.x;
}
ImGui::Dummy(ImVec2(effectiveSize.x, 0.0f));
ImGui::Dummy(ImVec2(frameHeight * 0.5f, 0.0f));
ImGui::SameLine(0.0f, 0.0f);
ImGui::BeginGroup();
ImGui::Dummy(ImVec2(frameHeight * 0.5f, 0.0f));
ImGui::SameLine(0.0f, 0.0f);
ImGui::TextUnformatted(name);
auto labelMin = ImGui::GetItemRectMin();
auto labelMax = ImGui::GetItemRectMax();
ImGui::SameLine(0.0f, 0.0f);
ImGui::Dummy(ImVec2(0.0, frameHeight + itemSpacing.y));
ImGui::BeginGroup();
// ImGui::GetWindowDrawList()->AddRect(labelMin, labelMax, IM_COL32(255, 0, 255, 255));
ImGui::PopStyleVar(2);
#if IMGUI_VERSION_NUM >= 17301
ImGui::GetCurrentWindow()->ContentRegionRect.Max.x -= frameHeight * 0.5f;
ImGui::GetCurrentWindow()->WorkRect.Max.x -= frameHeight * 0.5f;
ImGui::GetCurrentWindow()->InnerRect.Max.x -= frameHeight * 0.5f;
#else
ImGui::GetCurrentWindow()->ContentsRegionRect.Max.x -= frameHeight * 0.5f;
#endif
ImGui::GetCurrentWindow()->Size.x -= frameHeight;
auto itemWidth = ImGui::CalcItemWidth();
ImGui::PushItemWidth(ImMax(0.0f, itemWidth - frameHeight));
mGroupPanelLabelStack.push_back(ImRect(labelMin, labelMax));
}
void GuiWindow::EndGroupPanel(float minHeight) {
ImGui::PopItemWidth();
auto itemSpacing = ImGui::GetStyle().ItemSpacing;
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.0f, 0.0f));
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 0.0f));
auto frameHeight = ImGui::GetFrameHeight();
ImGui::EndGroup();
ImGui::EndGroup();
ImGui::SameLine(0.0f, 0.0f);
ImGui::Dummy(ImVec2(frameHeight * 0.5f, 0.0f));
ImGui::Dummy(ImVec2(0.0, std::max(frameHeight - frameHeight * 0.5f - itemSpacing.y, minHeight)));
ImGui::EndGroup();
auto itemMin = ImGui::GetItemRectMin();
auto itemMax = ImGui::GetItemRectMax();
// ImGui::GetWindowDrawList()->AddRectFilled(itemMin, itemMax, IM_COL32(255, 0, 0, 64), 4.0f);
auto labelRect = mGroupPanelLabelStack.back();
mGroupPanelLabelStack.pop_back();
ImVec2 halfFrame = ImVec2(frameHeight * 0.25f, frameHeight) * 0.5f;
ImRect frameRect = ImRect(itemMin + halfFrame, itemMax - ImVec2(halfFrame.x, 0.0f));
labelRect.Min.x -= itemSpacing.x;
labelRect.Max.x += itemSpacing.x;
for (int i = 0; i < 4; ++i) {
switch (i) {
// left half-plane
case 0:
ImGui::PushClipRect(ImVec2(-FLT_MAX, -FLT_MAX), ImVec2(labelRect.Min.x, FLT_MAX), true);
break;
// right half-plane
case 1:
ImGui::PushClipRect(ImVec2(labelRect.Max.x, -FLT_MAX), ImVec2(FLT_MAX, FLT_MAX), true);
break;
// top
case 2:
ImGui::PushClipRect(ImVec2(labelRect.Min.x, -FLT_MAX), ImVec2(labelRect.Max.x, labelRect.Min.y), true);
break;
// bottom
case 3:
ImGui::PushClipRect(ImVec2(labelRect.Min.x, labelRect.Max.y), ImVec2(labelRect.Max.x, FLT_MAX), true);
break;
}
ImGui::GetWindowDrawList()->AddRect(frameRect.Min, frameRect.Max,
ImColor(ImGui::GetStyleColorVec4(ImGuiCol_Border)), halfFrame.x);
ImGui::PopClipRect();
}
ImGui::PopStyleVar(2);
#if IMGUI_VERSION_NUM >= 17301
ImGui::GetCurrentWindow()->ContentRegionRect.Max.x += frameHeight * 0.5f;
ImGui::GetCurrentWindow()->WorkRect.Max.x += frameHeight * 0.5f;
ImGui::GetCurrentWindow()->InnerRect.Max.x += frameHeight * 0.5f;
#else
ImGui::GetCurrentWindow()->ContentsRegionRect.Max.x += frameHeight * 0.5f;
#endif
ImGui::GetCurrentWindow()->Size.x += frameHeight;
ImGui::Dummy(ImVec2(0.0f, 0.0f));
ImGui::EndGroup();
}
} // namespace LUS
+9
View File
@@ -1,6 +1,11 @@
#pragma once
#include <string>
#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif
#include <ImGui/imgui.h>
#include <ImGui/imgui_internal.h>
#include "window/gui/GuiElement.h"
namespace LUS {
@@ -12,7 +17,11 @@ class GuiWindow : public GuiElement {
std::string GetName();
protected:
void BeginGroupPanel(const char* name, const ImVec2& size);
void EndGroupPanel(float minHeight);
private:
std::string mName;
ImVector<ImRect> mGroupPanelLabelStack;
};
} // namespace LUS
+19 -19
View File
@@ -130,7 +130,7 @@ void InputEditorWindow::DrawControllerSchema() {
DrawControllerSelect(mCurrentPort);
Context::GetInstance()->GetWindow()->GetGui()->BeginGroupPanel("Buttons", ImVec2(150, 20));
BeginGroupPanel("Buttons", ImVec2(150, 20));
DrawButton("A", BTN_A, mCurrentPort, &mBtnReading);
DrawButton("B", BTN_B, mCurrentPort, &mBtnReading);
DrawButton("L", BTN_L, mCurrentPort, &mBtnReading);
@@ -139,24 +139,24 @@ void InputEditorWindow::DrawControllerSchema() {
DrawButton("START", BTN_START, mCurrentPort, &mBtnReading);
SEPARATION();
#ifdef __SWITCH__
Context::GetInstance()->GetWindow()->GetGui()->EndGroupPanel(isKeyboard ? 7.0f : 56.0f);
EndGroupPanel(isKeyboard ? 7.0f : 56.0f);
#else
Context::GetInstance()->GetWindow()->GetGui()->EndGroupPanel(isKeyboard ? 7.0f : 48.0f);
EndGroupPanel(isKeyboard ? 7.0f : 48.0f);
#endif
ImGui::SameLine();
Context::GetInstance()->GetWindow()->GetGui()->BeginGroupPanel("Digital Pad", ImVec2(150, 20));
BeginGroupPanel("Digital Pad", ImVec2(150, 20));
DrawButton("Up", BTN_DUP, mCurrentPort, &mBtnReading);
DrawButton("Down", BTN_DDOWN, mCurrentPort, &mBtnReading);
DrawButton("Left", BTN_DLEFT, mCurrentPort, &mBtnReading);
DrawButton("Right", BTN_DRIGHT, mCurrentPort, &mBtnReading);
SEPARATION();
#ifdef __SWITCH__
Context::GetInstance()->GetWindow()->GetGui()->EndGroupPanel(isKeyboard ? 53.0f : 122.0f);
EndGroupPanel(isKeyboard ? 53.0f : 122.0f);
#else
Context::GetInstance()->GetWindow()->GetGui()->EndGroupPanel(isKeyboard ? 53.0f : 94.0f);
EndGroupPanel(isKeyboard ? 53.0f : 94.0f);
#endif
ImGui::SameLine();
Context::GetInstance()->GetWindow()->GetGui()->BeginGroupPanel("Analog Stick", ImVec2(150, 20));
BeginGroupPanel("Analog Stick", ImVec2(150, 20));
DrawButton("Up", BTN_STICKUP, mCurrentPort, &mBtnReading);
DrawButton("Down", BTN_STICKDOWN, mCurrentPort, &mBtnReading);
DrawButton("Left", BTN_STICKLEFT, mCurrentPort, &mBtnReading);
@@ -195,15 +195,15 @@ void InputEditorWindow::DrawControllerSchema() {
ImGui::Dummy(ImVec2(0, 6));
}
#ifdef __SWITCH__
Context::GetInstance()->GetWindow()->GetGui()->EndGroupPanel(isKeyboard ? 52.0f : 52.0f);
EndGroupPanel(isKeyboard ? 52.0f : 52.0f);
#else
Context::GetInstance()->GetWindow()->GetGui()->EndGroupPanel(isKeyboard ? 52.0f : 24.0f);
EndGroupPanel(isKeyboard ? 52.0f : 24.0f);
#endif
ImGui::SameLine();
if (!isKeyboard) {
ImGui::SameLine();
Context::GetInstance()->GetWindow()->GetGui()->BeginGroupPanel("Right Stick", ImVec2(150, 20));
BeginGroupPanel("Right Stick", ImVec2(150, 20));
DrawButton("Up", BTN_VSTICKUP, mCurrentPort, &mBtnReading);
DrawButton("Down", BTN_VSTICKDOWN, mCurrentPort, &mBtnReading);
DrawButton("Left", BTN_VSTICKLEFT, mCurrentPort, &mBtnReading);
@@ -239,9 +239,9 @@ void InputEditorWindow::DrawControllerSchema() {
ImGui::PopItemWidth();
ImGui::EndChild();
#ifdef __SWITCH__
Context::GetInstance()->GetWindow()->GetGui()->EndGroupPanel(43.0f);
EndGroupPanel(43.0f);
#else
Context::GetInstance()->GetWindow()->GetGui()->EndGroupPanel(14.0f);
EndGroupPanel(14.0f);
#endif
}
@@ -249,7 +249,7 @@ void InputEditorWindow::DrawControllerSchema() {
#ifndef __WIIU__
ImGui::SameLine();
#endif
Context::GetInstance()->GetWindow()->GetGui()->BeginGroupPanel("Gyro Options", ImVec2(175, 20));
BeginGroupPanel("Gyro Options", ImVec2(175, 20));
float cursorX = ImGui::GetCursorPosX() + 5;
ImGui::SetCursorPosX(cursorX);
if (ImGui::Checkbox("Enable Gyro", &profile->UseGyro)) {
@@ -307,9 +307,9 @@ void InputEditorWindow::DrawControllerSchema() {
ImGui::PopItemWidth();
ImGui::EndChild();
#ifdef __SWITCH__
Context::GetInstance()->GetWindow()->GetGui()->EndGroupPanel(46.0f);
EndGroupPanel(46.0f);
#else
Context::GetInstance()->GetWindow()->GetGui()->EndGroupPanel(14.0f);
EndGroupPanel(14.0f);
#endif
}
@@ -317,13 +317,13 @@ void InputEditorWindow::DrawControllerSchema() {
const ImVec2 cursor = ImGui::GetCursorPos();
Context::GetInstance()->GetWindow()->GetGui()->BeginGroupPanel("C-Buttons", ImVec2(158, 20));
BeginGroupPanel("C-Buttons", ImVec2(158, 20));
DrawButton("Up", BTN_CUP, mCurrentPort, &mBtnReading);
DrawButton("Down", BTN_CDOWN, mCurrentPort, &mBtnReading);
DrawButton("Left", BTN_CLEFT, mCurrentPort, &mBtnReading);
DrawButton("Right", BTN_CRIGHT, mCurrentPort, &mBtnReading);
ImGui::Dummy(ImVec2(0, 5));
Context::GetInstance()->GetWindow()->GetGui()->EndGroupPanel(0.0f);
EndGroupPanel(0.0f);
ImGui::SetCursorPosX(cursor.x);
#ifdef __SWITCH__
@@ -333,7 +333,7 @@ void InputEditorWindow::DrawControllerSchema() {
#else
ImGui::SetCursorPosY(cursor.y + 120);
#endif
Context::GetInstance()->GetWindow()->GetGui()->BeginGroupPanel("Options", ImVec2(158, 20));
BeginGroupPanel("Options", ImVec2(158, 20));
float cursorX = ImGui::GetCursorPosX() + 5;
ImGui::SetCursorPosX(cursorX);
if (ImGui::Checkbox("Rumble Enabled", &profile->UseRumble)) {
@@ -376,7 +376,7 @@ void InputEditorWindow::DrawControllerSchema() {
}
ImGui::Dummy(ImVec2(0, 5));
Context::GetInstance()->GetWindow()->GetGui()->EndGroupPanel(isKeyboard ? 0.0f : 2.0f);
EndGroupPanel(isKeyboard ? 0.0f : 2.0f);
}
void InputEditorWindow::UpdateElement() {
+1 -1
View File
@@ -1,7 +1,7 @@
#pragma once
#include "stdint.h"
#include "GuiWindow.h"
#include "window/gui/GuiWindow.h"
#include <ImGui/imgui.h>
namespace LUS {