chore: refactor to GuiManager
All checks were successful
CI / build-and-test (push) Successful in 2m9s
All checks were successful
CI / build-and-test (push) Successful in 2m9s
This commit is contained in:
@@ -77,6 +77,7 @@ add_executable(simian
|
||||
src/ScriptEngine.cpp
|
||||
src/ScriptBindings.cpp
|
||||
src/HotReload.cpp
|
||||
src/GuiManager.cpp
|
||||
src/log/log.c
|
||||
)
|
||||
|
||||
|
||||
39
imgui.ini
39
imgui.ini
@@ -15,43 +15,50 @@ Collapsed=0
|
||||
|
||||
[Window][Left Panel]
|
||||
Pos=8,31
|
||||
Size=389,561
|
||||
Size=359,561
|
||||
Collapsed=0
|
||||
DockId=0x00000001,0
|
||||
|
||||
[Window][Right Panel]
|
||||
Pos=8,31
|
||||
Pos=403,31
|
||||
Size=389,561
|
||||
Collapsed=0
|
||||
DockId=0x00000001,1
|
||||
DockId=0x00000004,0
|
||||
|
||||
[Window][##TOAST2]
|
||||
Pos=530,314
|
||||
Size=250,82
|
||||
Pos=558,365
|
||||
Size=222,65
|
||||
Collapsed=0
|
||||
|
||||
[Window][##TOAST1]
|
||||
Pos=530,406
|
||||
Size=250,82
|
||||
Pos=558,440
|
||||
Size=222,65
|
||||
Collapsed=0
|
||||
|
||||
[Window][##TOAST0]
|
||||
Pos=530,498
|
||||
Size=250,82
|
||||
Pos=558,515
|
||||
Size=222,65
|
||||
Collapsed=0
|
||||
|
||||
[Window][##TOAST4]
|
||||
Pos=530,130
|
||||
Size=250,82
|
||||
Pos=558,215
|
||||
Size=222,65
|
||||
Collapsed=0
|
||||
|
||||
[Window][##TOAST3]
|
||||
Pos=530,222
|
||||
Size=250,82
|
||||
Pos=558,290
|
||||
Size=222,65
|
||||
Collapsed=0
|
||||
|
||||
[Window][##TOAST5]
|
||||
Pos=558,140
|
||||
Size=222,65
|
||||
Collapsed=0
|
||||
|
||||
[Docking][Data]
|
||||
DockSpace ID=0x9076BACA Window=0x34F970D7 Pos=8,31 Size=784,561 Split=X
|
||||
DockNode ID=0x00000001 Parent=0x9076BACA SizeRef=389,561 Selected=0x6D1308E5
|
||||
DockNode ID=0x00000002 Parent=0x9076BACA SizeRef=393,561 CentralNode=1
|
||||
DockSpace ID=0x9076BACA Window=0x34F970D7 Pos=8,31 Size=784,561 Split=X
|
||||
DockNode ID=0x00000003 Parent=0x9076BACA SizeRef=393,561 Split=X
|
||||
DockNode ID=0x00000001 Parent=0x00000003 SizeRef=389,561 Selected=0x995FC207
|
||||
DockNode ID=0x00000002 Parent=0x00000003 SizeRef=393,561 CentralNode=1
|
||||
DockNode ID=0x00000004 Parent=0x9076BACA SizeRef=389,561 Selected=0x6D1308E5
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "ScriptEngine.h"
|
||||
#include "HotReload.h"
|
||||
#include "GuiManager.h"
|
||||
|
||||
class Application {
|
||||
public:
|
||||
@@ -16,6 +17,7 @@ private:
|
||||
HotReload* hotReload;
|
||||
bool scriptCompilationError;
|
||||
FILE* logFile;
|
||||
GuiManager guiManager;
|
||||
|
||||
static const int WINDOW_WIDTH = 800;
|
||||
static const int WINDOW_HEIGHT = 600;
|
||||
|
||||
20
include/GuiManager.h
Normal file
20
include/GuiManager.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include "rlImGui.h"
|
||||
#include "imgui.h"
|
||||
#include "extras/IconsFontAwesome6.h"
|
||||
#include "gui/fa-solid-900.h"
|
||||
#include "gui/ImGuiNotify.hpp"
|
||||
|
||||
class GuiManager {
|
||||
public:
|
||||
GuiManager();
|
||||
~GuiManager();
|
||||
|
||||
void Initialize();
|
||||
void Render();
|
||||
void Shutdown();
|
||||
|
||||
private:
|
||||
void SetupDockspace();
|
||||
void RenderNotifications();
|
||||
};
|
||||
@@ -8,8 +8,8 @@
|
||||
#include "rlImGui.h"
|
||||
#include "imgui.h"
|
||||
#include "extras/IconsFontAwesome6.h"
|
||||
#include "gui/fa-solid-900.h"
|
||||
#include "gui/ImGuiNotify.hpp"
|
||||
#include "GuiManager.h"
|
||||
#endif
|
||||
const char *Application::WINDOW_TITLE = "Raylib + AngelScript";
|
||||
const char *Application::SCRIPT_FILE = "scripts/test.as";
|
||||
@@ -56,23 +56,7 @@ bool Application::Initialize()
|
||||
scriptCompilationError = !scriptEngine.CompileScript(SCRIPT_FILE);
|
||||
|
||||
#if HAVE_RLIMGUI
|
||||
// Initialize rlImGui if available (sets up ImGui context & fonts)
|
||||
rlImGuiSetup(true);
|
||||
// Enable docking support if ImGui is available
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
|
||||
io.Fonts->AddFontDefault();
|
||||
|
||||
float baseFontSize = 16.0f;
|
||||
float iconFontSize = baseFontSize * 2.0f / 3.0f; // FontAwesome fonts need to have their sizes reduced by 2.0f/3.0f in order to align correctly
|
||||
|
||||
static constexpr ImWchar iconsRanges[] = {ICON_MIN_FA, ICON_MAX_16_FA, 0};
|
||||
ImFontConfig iconsConfig;
|
||||
iconsConfig.MergeMode = true;
|
||||
iconsConfig.PixelSnapH = true;
|
||||
iconsConfig.GlyphMinAdvanceX = iconFontSize;
|
||||
io.Fonts->AddFontFromMemoryCompressedTTF(fa_solid_900_compressed_data, fa_solid_900_compressed_size, iconFontSize, &iconsConfig, iconsRanges);
|
||||
guiManager.Initialize();
|
||||
#endif
|
||||
|
||||
return true;
|
||||
@@ -108,6 +92,12 @@ void Application::Update(float deltaTime)
|
||||
|
||||
// Call script Update function
|
||||
scriptEngine.CallScriptFunction(scriptEngine.GetUpdateFunction(), deltaTime);
|
||||
|
||||
#if HAVE_RLIMGUI
|
||||
if (IsKeyPressed(KEY_SPACE)) {
|
||||
ImGui::InsertNotification({ImGuiToastType::Success,3000, "Space key was pressed!"});
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Application::Draw()
|
||||
@@ -125,87 +115,7 @@ void Application::Draw()
|
||||
scriptEngine.CallScriptFunction(scriptEngine.GetDrawFunction());
|
||||
|
||||
#if HAVE_RLIMGUI
|
||||
// Simple ImGui demo window to verify integration
|
||||
rlImGuiBegin();
|
||||
{
|
||||
// Dockspace host
|
||||
static bool dockspaceOpen = true;
|
||||
static bool opt_fullscreen = true;
|
||||
static ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_None;
|
||||
|
||||
ImGuiWindowFlags window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking;
|
||||
if (opt_fullscreen)
|
||||
{
|
||||
ImGuiViewport *viewport = ImGui::GetMainViewport();
|
||||
ImGui::SetNextWindowPos(viewport->WorkPos);
|
||||
ImGui::SetNextWindowSize(viewport->WorkSize);
|
||||
ImGui::SetNextWindowViewport(viewport->ID);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
|
||||
window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove;
|
||||
window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;
|
||||
}
|
||||
|
||||
// Begin host window
|
||||
ImGui::Begin("DockSpaceHost", &dockspaceOpen, window_flags);
|
||||
if (opt_fullscreen)
|
||||
ImGui::PopStyleVar(2);
|
||||
|
||||
// DockSpace
|
||||
ImGuiID dockspace_id = ImGui::GetID("MyDockSpace");
|
||||
ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags);
|
||||
|
||||
// Example child windows that can be docked
|
||||
ImGui::Begin("Left Panel");
|
||||
ImGui::Text("This is a dockable left panel.");
|
||||
ImGui::End();
|
||||
|
||||
ImGui::Begin("Right Panel");
|
||||
ImGui::Text("This is a dockable right panel. Drag the tabs around to dock.");
|
||||
ImGui::End();
|
||||
|
||||
ImGui::End(); // DockSpaceHost
|
||||
if (IsKeyPressed(KEY_SPACE))
|
||||
{
|
||||
log_info("Space pressed");
|
||||
ImGui::InsertNotification({ImGuiToastType::Success, 3000, "That is a success! %s", "(Format here)"});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Notifications Rendering Start
|
||||
*/
|
||||
|
||||
// Notifications style setup
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.f); // Disable round borders
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.f); // Disable borders
|
||||
|
||||
// Notifications color setup
|
||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.10f, 0.10f, 0.10f, 1.00f)); // Background color
|
||||
|
||||
|
||||
// Main rendering function
|
||||
ImGui::RenderNotifications();
|
||||
|
||||
|
||||
//——————————————————————————————— WARNING ———————————————————————————————
|
||||
// Argument MUST match the amount of ImGui::PushStyleVar() calls
|
||||
ImGui::PopStyleVar(2);
|
||||
// Argument MUST match the amount of ImGui::PushStyleColor() calls
|
||||
ImGui::PopStyleColor(1);
|
||||
|
||||
/**
|
||||
* Notifications Rendering End
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
rlImGuiEnd();
|
||||
|
||||
ImGui::UpdatePlatformWindows();
|
||||
ImGui::RenderPlatformWindowsDefault();
|
||||
|
||||
guiManager.Render();
|
||||
#endif
|
||||
|
||||
EndDrawing();
|
||||
@@ -222,9 +132,11 @@ void Application::Shutdown()
|
||||
scriptEngine.Shutdown();
|
||||
|
||||
#if HAVE_RLIMGUI
|
||||
guiManager.Shutdown();
|
||||
#endif
|
||||
|
||||
// Shutdown rlImGui first while the GL context and window are still valid
|
||||
rlImGuiShutdown();
|
||||
#endif
|
||||
|
||||
// Shutdown script engine
|
||||
scriptEngine.Shutdown();
|
||||
@@ -239,7 +151,4 @@ void Application::Shutdown()
|
||||
fclose(logFile);
|
||||
logFile = nullptr;
|
||||
}
|
||||
|
||||
#if HAVE_RLIMGUI
|
||||
#endif
|
||||
}
|
||||
84
src/GuiManager.cpp
Normal file
84
src/GuiManager.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
#include "GuiManager.h"
|
||||
#include "raylib.h"
|
||||
|
||||
GuiManager::GuiManager() {}
|
||||
|
||||
GuiManager::~GuiManager() {}
|
||||
|
||||
void GuiManager::Initialize() {
|
||||
rlImGuiSetup(true);
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
|
||||
io.Fonts->AddFontDefault();
|
||||
|
||||
float baseFontSize = 16.0f;
|
||||
float iconFontSize = baseFontSize * 2.0f / 3.0f;
|
||||
|
||||
static constexpr ImWchar iconsRanges[] = {ICON_MIN_FA, ICON_MAX_16_FA, 0};
|
||||
ImFontConfig iconsConfig;
|
||||
iconsConfig.MergeMode = true;
|
||||
iconsConfig.PixelSnapH = true;
|
||||
iconsConfig.GlyphMinAdvanceX = iconFontSize;
|
||||
io.Fonts->AddFontFromMemoryCompressedTTF(fa_solid_900_compressed_data, fa_solid_900_compressed_size, iconFontSize, &iconsConfig, iconsRanges);
|
||||
}
|
||||
|
||||
void GuiManager::Render() {
|
||||
rlImGuiBegin();
|
||||
SetupDockspace();
|
||||
RenderNotifications();
|
||||
rlImGuiEnd();
|
||||
|
||||
ImGui::UpdatePlatformWindows();
|
||||
ImGui::RenderPlatformWindowsDefault();
|
||||
}
|
||||
|
||||
void GuiManager::Shutdown() {
|
||||
rlImGuiShutdown();
|
||||
}
|
||||
|
||||
void GuiManager::SetupDockspace() {
|
||||
static bool dockspaceOpen = true;
|
||||
static bool opt_fullscreen = true;
|
||||
static ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_None;
|
||||
|
||||
ImGuiWindowFlags window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking;
|
||||
if (opt_fullscreen) {
|
||||
ImGuiViewport *viewport = ImGui::GetMainViewport();
|
||||
ImGui::SetNextWindowPos(viewport->WorkPos);
|
||||
ImGui::SetNextWindowSize(viewport->WorkSize);
|
||||
ImGui::SetNextWindowViewport(viewport->ID);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
|
||||
window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove;
|
||||
window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;
|
||||
}
|
||||
|
||||
ImGui::Begin("DockSpaceHost", &dockspaceOpen, window_flags);
|
||||
if (opt_fullscreen)
|
||||
ImGui::PopStyleVar(2);
|
||||
|
||||
ImGuiID dockspace_id = ImGui::GetID("MyDockSpace");
|
||||
ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags);
|
||||
|
||||
ImGui::Begin("Left Panel");
|
||||
ImGui::Text("This is a dockable left panel.");
|
||||
ImGui::End();
|
||||
|
||||
ImGui::Begin("Right Panel");
|
||||
ImGui::Text("This is a dockable right panel. Drag the tabs around to dock.");
|
||||
ImGui::End();
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void GuiManager::RenderNotifications() {
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.f);
|
||||
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.10f, 0.10f, 0.10f, 1.00f));
|
||||
|
||||
ImGui::RenderNotifications();
|
||||
|
||||
ImGui::PopStyleVar(2);
|
||||
ImGui::PopStyleColor(1);
|
||||
}
|
||||
Reference in New Issue
Block a user