Adds extra/custom ImGui methods
Slightly shrink default font size Asset folder always open in asset browsermaster
parent
f8cb13d856
commit
ce3dd3f984
@ -0,0 +1,106 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* File - imgui_ext.cpp
|
||||||
|
* Author - Joey Pollack
|
||||||
|
* Date - 2022/07/07 (y/m/d)
|
||||||
|
* Mod Date - 2022/07/07 (y/m/d)
|
||||||
|
* Description - Adds new and custom methods to the imgui api
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#include "imgui_ext.h"
|
||||||
|
|
||||||
|
#include <dearimgui/imgui.h>
|
||||||
|
#include <dearimgui/imgui_internal.h>
|
||||||
|
|
||||||
|
namespace lunarium
|
||||||
|
{
|
||||||
|
/// This function was taken from the Hazel engine written by Cherno!
|
||||||
|
/// https://github.com/TheCherno/Hazel/blob/master/Hazelnut/src/Panels/SceneHierarchyPanel.cpp
|
||||||
|
void ImGuiExt::Vec3Control(const std::string& label, glm::vec3& values, float resetValue, float columnWidth)
|
||||||
|
{
|
||||||
|
ImGui::PushID(label.c_str());
|
||||||
|
|
||||||
|
ImGui::Columns(2);
|
||||||
|
ImGui::SetColumnWidth(0, columnWidth);
|
||||||
|
ImGui::Text(label.c_str());
|
||||||
|
ImGui::NextColumn();
|
||||||
|
|
||||||
|
ImGui::PushMultiItemsWidths(3, ImGui::CalcItemWidth());
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2{ 0, 0 });
|
||||||
|
|
||||||
|
float lineHeight = GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.0f;
|
||||||
|
ImVec2 buttonSize = { lineHeight + 3.0f, lineHeight };
|
||||||
|
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.8f, 0.1f, 0.15f, 1.0f });
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.9f, 0.2f, 0.2f, 1.0f });
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.8f, 0.1f, 0.15f, 1.0f });
|
||||||
|
//ImGui::PushFont(boldFont);
|
||||||
|
if (ImGui::Button("X", buttonSize))
|
||||||
|
values.x = resetValue;
|
||||||
|
//ImGui::PopFont();
|
||||||
|
ImGui::PopStyleColor(3);
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::DragFloat("##X", &values.x, 0.1f, 0.0f, 0.0f, "%.2f");
|
||||||
|
ImGui::PopItemWidth();
|
||||||
|
ImGui::SameLine();
|
||||||
|
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.2f, 0.7f, 0.2f, 1.0f });
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.3f, 0.8f, 0.3f, 1.0f });
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.2f, 0.7f, 0.2f, 1.0f });
|
||||||
|
//ImGui::PushFont(boldFont);
|
||||||
|
if (ImGui::Button("Y", buttonSize))
|
||||||
|
values.y = resetValue;
|
||||||
|
//ImGui::PopFont();
|
||||||
|
ImGui::PopStyleColor(3);
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::DragFloat("##Y", &values.y, 0.1f, 0.0f, 0.0f, "%.2f");
|
||||||
|
ImGui::PopItemWidth();
|
||||||
|
ImGui::SameLine();
|
||||||
|
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{ 0.1f, 0.25f, 0.8f, 1.0f });
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{ 0.2f, 0.35f, 0.9f, 1.0f });
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4{ 0.1f, 0.25f, 0.8f, 1.0f });
|
||||||
|
//ImGui::PushFont(boldFont);
|
||||||
|
if (ImGui::Button("Z", buttonSize))
|
||||||
|
values.z = resetValue;
|
||||||
|
//ImGui::PopFont();
|
||||||
|
ImGui::PopStyleColor(3);
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::DragFloat("##Z", &values.z, 0.1f, 0.0f, 0.0f, "%.2f");
|
||||||
|
ImGui::PopItemWidth();
|
||||||
|
|
||||||
|
ImGui::PopStyleVar();
|
||||||
|
|
||||||
|
ImGui::Columns(1);
|
||||||
|
|
||||||
|
ImGui::PopID();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Only works if this is the only item on the line
|
||||||
|
void ImGuiExt::TextCentered(const std::string text)
|
||||||
|
{
|
||||||
|
auto windowWidth = ImGui::GetWindowSize().x;
|
||||||
|
auto textWidth = ImGui::CalcTextSize(text.c_str()).x;
|
||||||
|
|
||||||
|
ImGui::SetCursorPosX((windowWidth - textWidth) * 0.5f);
|
||||||
|
ImGui::Text(text.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not recommended but the only way to do it for now
|
||||||
|
// https://github.com/ocornut/imgui/discussions/3862
|
||||||
|
bool ImGuiExt::ButtonCentered(const char* label, float alignment)
|
||||||
|
{
|
||||||
|
ImGuiStyle& style = ImGui::GetStyle();
|
||||||
|
|
||||||
|
float size = ImGui::CalcTextSize(label).x + style.FramePadding.x * 2.0f;
|
||||||
|
float avail = ImGui::GetContentRegionAvail().x;
|
||||||
|
|
||||||
|
float off = (avail - size) * alignment;
|
||||||
|
if (off > 0.0f)
|
||||||
|
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + off);
|
||||||
|
|
||||||
|
return ImGui::Button(label);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* File - imgui_ext.h
|
||||||
|
* Author - Joey Pollack
|
||||||
|
* Date - 2022/07/07 (y/m/d)
|
||||||
|
* Mod Date - 2022/07/07 (y/m/d)
|
||||||
|
* Description - Adds new and custom methods to the imgui api
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef LUNARIUM_IMGUI_EXT_H_
|
||||||
|
#define LUNARIUM_IMGUI_EXT_H_
|
||||||
|
|
||||||
|
#include <core/common_defs.h>
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace lunarium
|
||||||
|
{
|
||||||
|
class ImGuiExt
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/// This function was taken from the Hazel engine written by Cherno!
|
||||||
|
/// https://github.com/TheCherno/Hazel/blob/master/Hazelnut/src/Panels/SceneHierarchyPanel.cpp
|
||||||
|
static void Vec3Control(const std::string& label, glm::vec3& values, float resetValue = 0.0f, float columnWidth = 100.0f);
|
||||||
|
static void TextCentered(const std::string text);
|
||||||
|
static bool ButtonCentered(const char* label, float alignment = 0.5f);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // LUNARIUM_IMGUI_EXT_H_
|
||||||
Loading…
Reference in New Issue