Update PropertiesPanel
- Made PropertiesPanel prettier
This commit is contained in:
parent
0f9a8ff95e
commit
51133194fc
2 changed files with 72 additions and 4 deletions
|
@ -6,7 +6,7 @@
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
|
#include <imgui_internal.h>
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
|
@ -35,8 +35,20 @@ namespace Light {
|
||||||
|
|
||||||
if (ImGui::TreeNodeEx((void*)typeid(TransformComponent).hash_code(), ImGuiTreeNodeFlags_DefaultOpen, "Transform"))
|
if (ImGui::TreeNodeEx((void*)typeid(TransformComponent).hash_code(), ImGuiTreeNodeFlags_DefaultOpen, "Transform"))
|
||||||
{
|
{
|
||||||
auto transform = m_EntityContext.GetComponent<TransformComponent>().GetTransform();
|
auto& transform = m_EntityContext.GetComponent<TransformComponent>();
|
||||||
ImGui::DragFloat3("Position", glm::value_ptr(transform[3]), 0.5f);
|
|
||||||
|
DrawVec3Control("Translation", transform.translation);
|
||||||
|
|
||||||
|
ImGui::TreePop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_EntityContext.HasComponent<SpriteRendererComponent>())
|
||||||
|
{
|
||||||
|
if (ImGui::TreeNodeEx((void*)typeid(SpriteRendererComponent).hash_code(), ImGuiTreeNodeFlags_DefaultOpen, "Sprite"))
|
||||||
|
{
|
||||||
|
auto& spriteRenderer = m_EntityContext.GetComponent<SpriteRendererComponent>();
|
||||||
|
ImGui::ColorEdit4("Color", &spriteRenderer.tint[0]);
|
||||||
|
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
}
|
}
|
||||||
|
@ -103,7 +115,6 @@ namespace Light {
|
||||||
if (ImGui::DragFloat("Far Plane", &farPlane))
|
if (ImGui::DragFloat("Far Plane", &farPlane))
|
||||||
camera.SetPerspectiveFarPlane(farPlane);
|
camera.SetPerspectiveFarPlane(farPlane);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,4 +126,58 @@ namespace Light {
|
||||||
m_EntityContext = entity;
|
m_EntityContext = entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PropertiesPanel::DrawVec3Control(const std::string& label, glm::vec3& values, float resetValue /*= 0.0f*/, float columnWidth /*= 100.0f*/)
|
||||||
|
{
|
||||||
|
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));
|
||||||
|
if (ImGui::Button("X", buttonSize))
|
||||||
|
values.x = resetValue;
|
||||||
|
ImGui::PopStyleColor(3);
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::DragFloat("##X", &values.x, 0.1f);
|
||||||
|
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));
|
||||||
|
if (ImGui::Button("Y", buttonSize))
|
||||||
|
values.x = resetValue;
|
||||||
|
ImGui::PopStyleColor(3);
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::DragFloat("##Y", &values.y, 0.1f);
|
||||||
|
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));
|
||||||
|
if (ImGui::Button("Z", buttonSize))
|
||||||
|
values.x = resetValue;
|
||||||
|
ImGui::PopStyleColor(3);
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::DragFloat("##Z", &values.z, 0.1f);
|
||||||
|
ImGui::PopItemWidth();
|
||||||
|
|
||||||
|
ImGui::PopStyleVar();
|
||||||
|
ImGui::Columns(1);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -18,6 +18,9 @@ namespace Light {
|
||||||
void OnUserInterfaceUpdate();
|
void OnUserInterfaceUpdate();
|
||||||
|
|
||||||
void SetEntityContext(Entity entity);
|
void SetEntityContext(Entity entity);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void DrawVec3Control(const std::string& label, glm::vec3& values, float resetValue = 0.0f, float columnWidth = 100.0f);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue