diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index 0196ef75..112b14de 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -46,6 +46,7 @@ #include "src/Rendering/SceneRenderer.h" #include #include +#include "UIDemoWindow.h" namespace Nuake { Ref 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(); diff --git a/Editor/src/Windows/UIDemoWindow.cpp b/Editor/src/Windows/UIDemoWindow.cpp new file mode 100644 index 00000000..39ec1513 --- /dev/null +++ b/Editor/src/Windows/UIDemoWindow.cpp @@ -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(); +} \ No newline at end of file diff --git a/Editor/src/Windows/UIDemoWindow.h b/Editor/src/Windows/UIDemoWindow.h new file mode 100644 index 00000000..af0d9859 --- /dev/null +++ b/Editor/src/Windows/UIDemoWindow.h @@ -0,0 +1,13 @@ +#pragma once + + +class UIDemoWindow +{ +public: + UIDemoWindow() = default; + ~UIDemoWindow() = default; + + void Draw(); +}; + + \ No newline at end of file diff --git a/Nuake/src/UI/ImUI.h b/Nuake/src/UI/ImUI.h new file mode 100644 index 00000000..b65a4f24 --- /dev/null +++ b/Nuake/src/UI/ImUI.h @@ -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; + } + } +} \ No newline at end of file