mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-21 20:08:40 +03:00
Started work on ImGui abstraction for consistent theming across the editor
This commit is contained in:
@@ -46,6 +46,7 @@
|
||||
#include "src/Rendering/SceneRenderer.h"
|
||||
#include <dependencies/glfw/include/GLFW/glfw3.h>
|
||||
#include <src/Rendering/Buffers/Framebuffer.h>
|
||||
#include "UIDemoWindow.h"
|
||||
|
||||
namespace Nuake {
|
||||
Ref<UI::UserInterface> userInterface;
|
||||
@@ -1544,6 +1545,7 @@ namespace Nuake {
|
||||
|
||||
bool isLoadingProject = false;
|
||||
bool isLoadingProjectQueue = false;
|
||||
UIDemoWindow m_DemoWindow;
|
||||
|
||||
int frameCount = 2;
|
||||
void EditorInterface::Draw()
|
||||
@@ -1610,6 +1612,8 @@ namespace Nuake {
|
||||
|
||||
pInterface.m_CurrentProject = Engine::GetProject();
|
||||
|
||||
m_DemoWindow.Draw();
|
||||
|
||||
_audioWindow->Draw();
|
||||
|
||||
DrawMenuBar();
|
||||
|
||||
20
Editor/src/Windows/UIDemoWindow.cpp
Normal file
20
Editor/src/Windows/UIDemoWindow.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "UIDemoWindow.h"
|
||||
|
||||
#include "src/UI/ImUI.h"
|
||||
|
||||
float floatSlider = 0.6f;
|
||||
bool checkbox = false;
|
||||
|
||||
void UIDemoWindow::Draw()
|
||||
{
|
||||
using namespace Nuake;
|
||||
|
||||
UI::BeginWindow("UI Demo");
|
||||
{
|
||||
UI::PrimaryButton("Primary Button");
|
||||
UI::SecondaryButton("Secondary Button");
|
||||
UI::FloatSlider("Float slider", floatSlider);
|
||||
UI::CheckBox("Checkbox", checkbox);
|
||||
}
|
||||
UI::EndWindow();
|
||||
}
|
||||
13
Editor/src/Windows/UIDemoWindow.h
Normal file
13
Editor/src/Windows/UIDemoWindow.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
class UIDemoWindow
|
||||
{
|
||||
public:
|
||||
UIDemoWindow() = default;
|
||||
~UIDemoWindow() = default;
|
||||
|
||||
void Draw();
|
||||
};
|
||||
|
||||
|
||||
154
Nuake/src/UI/ImUI.h
Normal file
154
Nuake/src/UI/ImUI.h
Normal file
@@ -0,0 +1,154 @@
|
||||
#pragma once
|
||||
#include "src/Core/Core.h"
|
||||
#include "src/Core/Maths.h"
|
||||
|
||||
#include "imgui/imgui.h"
|
||||
#include "../../../Editor/src/Misc/InterfaceFonts.h"
|
||||
|
||||
#include "src/Resource/FontAwesome5.h"
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
namespace UI
|
||||
{
|
||||
static uint32_t PrimaryCol = IM_COL32(97, 0, 255, 255);
|
||||
static uint32_t GrabCol = IM_COL32(97, 0, 255, 255);
|
||||
|
||||
static ImVec2 ButtonPadding = ImVec2(16.0f, 8.0f);
|
||||
static ImVec2 IconButtonPadding = ImVec2(8.0f, 8.0f);
|
||||
|
||||
void BeginWindow(const std::string& name)
|
||||
{
|
||||
ImGui::Begin(name.c_str());
|
||||
}
|
||||
|
||||
void EndWindow()
|
||||
{
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
bool PrimaryButton(const std::string& name)
|
||||
{
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(97, 0, 255, 255));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, IM_COL32(97, 0, 255, 200));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, IM_COL32(97, 0, 255, 255));
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4.0f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ButtonPadding);
|
||||
|
||||
UIFont boldFont(Bold);
|
||||
const bool buttonPressed = ImGui::Button(name.c_str());
|
||||
|
||||
ImGui::PopStyleColor(3);
|
||||
|
||||
ImGui::PopStyleVar(2);
|
||||
|
||||
return buttonPressed;
|
||||
}
|
||||
|
||||
bool SecondaryButton(const std::string& name)
|
||||
{
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(0, 0, 0, 0));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, IM_COL32(97, 0, 255, 200));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, IM_COL32(97, 0, 255, 255));
|
||||
ImGui::PushStyleColor(ImGuiCol_Border, PrimaryCol);
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 2.0f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4.0f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ButtonPadding);
|
||||
|
||||
UIFont boldFont(Bold);
|
||||
const bool buttonPressed = ImGui::Button(name.c_str());
|
||||
|
||||
ImGui::PopStyleVar(3);
|
||||
|
||||
ImGui::PopStyleColor(4);
|
||||
|
||||
return buttonPressed;
|
||||
}
|
||||
|
||||
bool IconButton(const std::string& icon)
|
||||
{
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4.0f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, IconButtonPadding);
|
||||
|
||||
const float height = ImGui::GetTextLineHeight() + ButtonPadding.y * 2.0;
|
||||
const bool isPressed = ImGui::Button(icon.c_str(), ImVec2(height, height));
|
||||
|
||||
ImGui::PopStyleVar(2);
|
||||
|
||||
return isPressed;
|
||||
}
|
||||
|
||||
bool FloatSlider(const std::string& name, float& input, float min = 0.0f, float max = 1.0f, float speed = 0.01f)
|
||||
{
|
||||
//ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, { 0, ImGui::GetStyle().ItemSpacing.y });
|
||||
//IconButton(ICON_FA_ANGLE_UP);
|
||||
//
|
||||
//ImGui::SameLine();
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4.0f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ButtonPadding);
|
||||
|
||||
const bool isUsing = ImGui::DragFloat(("##" + name).c_str(), &input, speed, min, max);
|
||||
|
||||
ImGui::PopStyleVar(2);
|
||||
|
||||
//ImGui::PopStyleColor();
|
||||
|
||||
return isUsing;
|
||||
}
|
||||
|
||||
bool CheckBox(const std::string& name, bool& value)
|
||||
{
|
||||
const float height = ImGui::GetTextLineHeight() + ButtonPadding.y * 2.0;
|
||||
|
||||
if (value)
|
||||
{
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(0, 0, 0, 0));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, IM_COL32(97, 0, 255, 200));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, PrimaryCol);
|
||||
ImGui::PushStyleColor(ImGuiCol_Border, PrimaryCol);
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 2.0f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4.0f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ButtonPadding);
|
||||
|
||||
const bool buttonPressed = ImGui::Button(("##" + name).c_str(), ImVec2(height, height));
|
||||
|
||||
ImGui::PopStyleVar(3);
|
||||
|
||||
ImGui::PopStyleColor(4);
|
||||
|
||||
if (buttonPressed)
|
||||
{
|
||||
value = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, PrimaryCol);
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, PrimaryCol);
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, PrimaryCol);
|
||||
ImGui::PushStyleColor(ImGuiCol_Border, IM_COL32(97, 0, 255, 200));
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 2.0f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4.0f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ButtonPadding);
|
||||
|
||||
const bool buttonPressed = ImGui::Button(("##" + name).c_str(), ImVec2(height, height));
|
||||
|
||||
ImGui::PopStyleVar(3);
|
||||
|
||||
ImGui::PopStyleColor(4);
|
||||
|
||||
if (buttonPressed)
|
||||
{
|
||||
value = true;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user