Modified script inspectors to use the vector widgets from SHEditorWidgets. SHEditorWidget is now a static class.
This commit is contained in:
parent
7010e1b688
commit
3730c2125f
|
@ -45,7 +45,7 @@ namespace SHADE
|
||||||
if (!component)
|
if (!component)
|
||||||
return;
|
return;
|
||||||
auto componentType = rttr::type::get(*component);
|
auto componentType = rttr::type::get(*component);
|
||||||
CheckBox("##IsActive", [component]() {return component->isActive; }, [component](bool const& active) {component->isActive = active; });
|
SHEditorWidgets::CheckBox("##IsActive", [component]() {return component->isActive; }, [component](bool const& active) {component->isActive = active; });
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (ImGui::CollapsingHeader(componentType.get_name().data()))
|
if (ImGui::CollapsingHeader(componentType.get_name().data()))
|
||||||
{
|
{
|
||||||
|
@ -57,11 +57,11 @@ namespace SHADE
|
||||||
|
|
||||||
if (type == rttr::type::get<SHVec4>())
|
if (type == rttr::type::get<SHVec4>())
|
||||||
{
|
{
|
||||||
DragVec4(property.get_name().data(), { "X", "Y", "Z", "W" }, [component, property]() {return property.get_value(component).template convert<SHVec4>(); }, [component, property](SHVec4 vec) {return property.set_value(component, vec); });
|
SHEditorWidgets::DragVec4(property.get_name().data(), { "X", "Y", "Z", "W" }, [component, property]() {return property.get_value(component).template convert<SHVec4>(); }, [component, property](SHVec4 vec) {return property.set_value(component, vec); });
|
||||||
}
|
}
|
||||||
else if (type == rttr::type::get<SHVec3>())
|
else if (type == rttr::type::get<SHVec3>())
|
||||||
{
|
{
|
||||||
DragVec3(property.get_name().data(), { "X", "Y", "Z" }, [component, property]() {return property.get_value(component).template convert<SHVec3>(); }, [component, property](SHVec3 vec) {return property.set_value(component, vec); });
|
SHEditorWidgets::DragVec3(property.get_name().data(), { "X", "Y", "Z" }, [component, property]() {return property.get_value(component).template convert<SHVec3>(); }, [component, property](SHVec3 vec) {return property.set_value(component, vec); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ namespace SHADE
|
||||||
SHEntity* entity = SHEntityManager::GetEntityByID(eid);
|
SHEntity* entity = SHEntityManager::GetEntityByID(eid);
|
||||||
|
|
||||||
ImGui::TextColored(ImGuiColors::green, "EID: %zu", eid);
|
ImGui::TextColored(ImGuiColors::green, "EID: %zu", eid);
|
||||||
CheckBox("##IsActive", [entity]()->bool {return entity->GetActive(); }, [entity](bool const& active) {entity->SetActive(active); });
|
SHEditorWidgets::CheckBox("##IsActive", [entity]()->bool {return entity->GetActive(); }, [entity](bool const& active) {entity->SetActive(active); });
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
|
||||||
ImGui::InputText("##EntityName", &entity->name);
|
ImGui::InputText("##EntityName", &entity->name);
|
||||||
|
|
|
@ -15,6 +15,7 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include "SHEditorUI.h"
|
#include "SHEditorUI.h"
|
||||||
// External Dependencies
|
// External Dependencies
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
|
#include "SHEditorWidgets.hpp"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -136,18 +137,24 @@ namespace SHADE
|
||||||
|
|
||||||
bool SHEditorUI::InputCheckbox(const std::string& label, bool& value)
|
bool SHEditorUI::InputCheckbox(const std::string& label, bool& value)
|
||||||
{
|
{
|
||||||
return ImGui::Checkbox(label.c_str(), &value);
|
ImGui::Text(label.c_str());
|
||||||
|
ImGui::SameLine();
|
||||||
|
return ImGui::Checkbox("#", &value);
|
||||||
}
|
}
|
||||||
bool SHEditorUI::InputInt(const std::string& label, int& value)
|
bool SHEditorUI::InputInt(const std::string& label, int& value)
|
||||||
{
|
{
|
||||||
return ImGui::InputInt(label.c_str(), &value,
|
ImGui::Text(label.c_str());
|
||||||
|
ImGui::SameLine();
|
||||||
|
return ImGui::InputInt("#", &value,
|
||||||
1, 10,
|
1, 10,
|
||||||
ImGuiInputTextFlags_EnterReturnsTrue);
|
ImGuiInputTextFlags_EnterReturnsTrue);
|
||||||
}
|
}
|
||||||
bool SHEditorUI::InputUnsignedInt(const std::string& label, unsigned int& value)
|
bool SHEditorUI::InputUnsignedInt(const std::string& label, unsigned int& value)
|
||||||
{
|
{
|
||||||
int signedVal = static_cast<int>(value);
|
int signedVal = static_cast<int>(value);
|
||||||
const bool CHANGED = InputInt(label, signedVal);
|
ImGui::Text(label.c_str());
|
||||||
|
ImGui::SameLine();
|
||||||
|
const bool CHANGED = InputInt("#", signedVal);
|
||||||
if (CHANGED)
|
if (CHANGED)
|
||||||
{
|
{
|
||||||
signedVal = std::clamp(signedVal, 0, std::numeric_limits<int>::max());
|
signedVal = std::clamp(signedVal, 0, std::numeric_limits<int>::max());
|
||||||
|
@ -157,19 +164,25 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
bool SHEditorUI::InputFloat(const std::string& label, float& value)
|
bool SHEditorUI::InputFloat(const std::string& label, float& value)
|
||||||
{
|
{
|
||||||
return ImGui::InputFloat(label.c_str(), &value,
|
ImGui::Text(label.c_str());
|
||||||
|
ImGui::SameLine();
|
||||||
|
return ImGui::InputFloat("#", &value,
|
||||||
0.1f, 1.0f, "%.3f",
|
0.1f, 1.0f, "%.3f",
|
||||||
ImGuiInputTextFlags_EnterReturnsTrue);
|
ImGuiInputTextFlags_EnterReturnsTrue);
|
||||||
}
|
}
|
||||||
bool SHEditorUI::InputDouble(const std::string& label, double& value)
|
bool SHEditorUI::InputDouble(const std::string& label, double& value)
|
||||||
{
|
{
|
||||||
return ImGui::InputDouble(label.c_str(), &value,
|
ImGui::Text(label.c_str());
|
||||||
|
ImGui::SameLine();
|
||||||
|
return ImGui::InputDouble("#", &value,
|
||||||
0.1, 1.0, "%.3f",
|
0.1, 1.0, "%.3f",
|
||||||
ImGuiInputTextFlags_EnterReturnsTrue);
|
ImGuiInputTextFlags_EnterReturnsTrue);
|
||||||
}
|
}
|
||||||
bool SHEditorUI::InputAngle(const std::string& label, double& value)
|
bool SHEditorUI::InputAngle(const std::string& label, double& value)
|
||||||
{
|
{
|
||||||
return ImGui::InputDouble(label.c_str(), &value,
|
ImGui::Text(label.c_str());
|
||||||
|
ImGui::SameLine();
|
||||||
|
return ImGui::InputDouble("#", &value,
|
||||||
1.0, 45.0, "%.3f",
|
1.0, 45.0, "%.3f",
|
||||||
ImGuiInputTextFlags_EnterReturnsTrue);
|
ImGuiInputTextFlags_EnterReturnsTrue);
|
||||||
}
|
}
|
||||||
|
@ -177,7 +190,9 @@ namespace SHADE
|
||||||
bool SHEditorUI::InputSlider(const std::string& label, double min, double max, double& value)
|
bool SHEditorUI::InputSlider(const std::string& label, double min, double max, double& value)
|
||||||
{
|
{
|
||||||
float val = static_cast<float>(value);
|
float val = static_cast<float>(value);
|
||||||
const bool CHANGED = ImGui::SliderFloat(label.c_str(), &val,
|
ImGui::Text(label.c_str());
|
||||||
|
ImGui::SameLine();
|
||||||
|
const bool CHANGED = ImGui::SliderFloat("#", &val,
|
||||||
static_cast<float>(min), static_cast<float>(max), "%.3f",
|
static_cast<float>(min), static_cast<float>(max), "%.3f",
|
||||||
ImGuiInputTextFlags_EnterReturnsTrue);
|
ImGuiInputTextFlags_EnterReturnsTrue);
|
||||||
|
|
||||||
|
@ -186,70 +201,27 @@ namespace SHADE
|
||||||
value = val;
|
value = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return CHANGED;
|
return CHANGED;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SHEditorUI::InputVec2(const std::string& label, SHVec2& value)
|
bool SHEditorUI::InputVec2(const std::string& label, SHVec2& value)
|
||||||
{
|
{
|
||||||
float vec[2] =
|
static const std::vector<std::string> COMPONENT_LABELS = { "X", "Y" };
|
||||||
{
|
return SHEditorWidgets::DragN<float, 2>(label, COMPONENT_LABELS, { &value.x, &value.y });
|
||||||
static_cast<float>(value.x),
|
|
||||||
static_cast<float>(value.y)
|
|
||||||
};
|
|
||||||
const bool CHANGED = ImGui::InputFloat2(label.c_str(), vec, "%.3f",
|
|
||||||
ImGuiInputTextFlags_EnterReturnsTrue);
|
|
||||||
if (CHANGED)
|
|
||||||
{
|
|
||||||
value.x = vec[0];
|
|
||||||
value.y = vec[1];
|
|
||||||
}
|
}
|
||||||
return CHANGED;
|
bool SHEditorUI::InputVec3(const std::string& label, SHVec3& value, float speed)
|
||||||
}
|
|
||||||
bool SHEditorUI::InputVec3(const std::string& label, SHVec3& value)
|
|
||||||
{
|
{
|
||||||
float vec[3] =
|
static const std::vector<std::string> COMPONENT_LABELS = { "X", "Y", "Z"};
|
||||||
{
|
return SHEditorWidgets::DragN<float, 3>(label, COMPONENT_LABELS, { &value.x, &value.y, &value.z }, speed, "%.3f");
|
||||||
static_cast<float>(value.x),
|
|
||||||
static_cast<float>(value.y),
|
|
||||||
static_cast<float>(value.z)
|
|
||||||
};
|
|
||||||
const bool CHANGED = ImGui::InputFloat3(label.c_str(), vec, "%.3f",
|
|
||||||
ImGuiInputTextFlags_EnterReturnsTrue);
|
|
||||||
if (CHANGED)
|
|
||||||
{
|
|
||||||
value.x = vec[0];
|
|
||||||
value.y = vec[1];
|
|
||||||
value.z = vec[2];
|
|
||||||
}
|
|
||||||
return CHANGED;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SHEditorUI::InputSliderVec3(const std::string& label, double min, double max, SHVec3& value)
|
|
||||||
{
|
|
||||||
float vec[3] =
|
|
||||||
{
|
|
||||||
static_cast<float>(value.x),
|
|
||||||
static_cast<float>(value.y),
|
|
||||||
static_cast<float>(value.z)
|
|
||||||
};
|
|
||||||
const bool CHANGED = ImGui::SliderFloat3(label.c_str(), vec,
|
|
||||||
static_cast<float>(min), static_cast<float>(max), "%.3f",
|
|
||||||
ImGuiInputTextFlags_EnterReturnsTrue);
|
|
||||||
if (CHANGED)
|
|
||||||
{
|
|
||||||
value.x = vec[0];
|
|
||||||
value.y = vec[1];
|
|
||||||
value.z = vec[2];
|
|
||||||
}
|
|
||||||
return CHANGED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SHEditorUI::InputTextField(const std::string& label, std::string& value)
|
bool SHEditorUI::InputTextField(const std::string& label, std::string& value)
|
||||||
{
|
{
|
||||||
std::array<char, TEXT_FIELD_MAX_LENGTH> buffer = { '\0' };
|
std::array<char, TEXT_FIELD_MAX_LENGTH> buffer = { '\0' };
|
||||||
strcpy_s(buffer.data(), TEXT_FIELD_MAX_LENGTH, value.c_str());
|
strcpy_s(buffer.data(), TEXT_FIELD_MAX_LENGTH, value.c_str());
|
||||||
const bool CHANGED = ImGui::InputText(label.c_str(), &buffer[0], TEXT_FIELD_MAX_LENGTH);
|
ImGui::Text(label.c_str());
|
||||||
|
ImGui::SameLine();
|
||||||
|
const bool CHANGED = ImGui::InputText("#", &buffer[0], TEXT_FIELD_MAX_LENGTH);
|
||||||
if (CHANGED)
|
if (CHANGED)
|
||||||
{
|
{
|
||||||
value = std::string(buffer.data(), buffer.data() + TEXT_FIELD_MAX_LENGTH);
|
value = std::string(buffer.data(), buffer.data() + TEXT_FIELD_MAX_LENGTH);
|
||||||
|
@ -259,11 +231,13 @@ namespace SHADE
|
||||||
|
|
||||||
bool SHEditorUI::InputEnumCombo(const std::string& label, int& v, const std::vector<std::string>& enumNames)
|
bool SHEditorUI::InputEnumCombo(const std::string& label, int& v, const std::vector<std::string>& enumNames)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Clamp input value
|
// Clamp input value
|
||||||
const std::string& INITIAL_NAME = v >= static_cast<int>(enumNames.size()) ? "Unknown" : enumNames[v];
|
const std::string& INITIAL_NAME = v >= static_cast<int>(enumNames.size()) ? "Unknown" : enumNames[v];
|
||||||
bool b = false;
|
bool b = false;
|
||||||
if (ImGui::BeginCombo(label.c_str(), INITIAL_NAME.c_str(), ImGuiComboFlags_None))
|
|
||||||
|
ImGui::Text(label.c_str());
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::BeginCombo("#", INITIAL_NAME.c_str(), ImGuiComboFlags_None))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < enumNames.size(); ++i)
|
for (int i = 0; i < enumNames.size(); ++i)
|
||||||
{
|
{
|
||||||
|
|
|
@ -244,18 +244,7 @@ namespace SHADE
|
||||||
/// <param name="label">Label used to identify this widget.</param>
|
/// <param name="label">Label used to identify this widget.</param>
|
||||||
/// <param name="value">Reference to the variable to store the result.</param>
|
/// <param name="value">Reference to the variable to store the result.</param>
|
||||||
/// <returns>True if the value was changed.</returns>
|
/// <returns>True if the value was changed.</returns>
|
||||||
static bool InputVec3(const std::string& label, SHVec3& value);
|
static bool InputVec3(const std::string& label, SHVec3& value, float speed = 0.1f);
|
||||||
/// <summary>
|
|
||||||
/// Creates a 3x double slider field widget for Vector3 input.
|
|
||||||
/// <br/>
|
|
||||||
/// Wraps up ImGui::InputSliderFloat3().
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="label">Label used to identify this widget.</param>
|
|
||||||
/// <param name="min">Minimum value of the slider.</param>
|
|
||||||
/// <param name="max">Maximum value of the slider.</param>
|
|
||||||
/// <param name="value">Reference to the variable to store the result.</param>
|
|
||||||
/// <returns>True if the value was changed.</returns>
|
|
||||||
static bool InputSliderVec3(const std::string& label, double min, double max, SHVec3& value);
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a text field widget for string input.
|
/// Creates a text field widget for string input.
|
||||||
/// <br/>
|
/// <br/>
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "Math/SHMath.h"
|
#include "Math/SHMath.h"
|
||||||
#include "Command/SHCommandManager.h"
|
#include "Command/SHCommandManager.h"
|
||||||
#include "SHImGuiHelpers.hpp"
|
#include "SHImGuiHelpers.hpp"
|
||||||
|
#include "SH_API.h"
|
||||||
|
|
||||||
//#==============================================================#
|
//#==============================================================#
|
||||||
//|| Library Includes ||
|
//|| Library Includes ||
|
||||||
|
@ -26,6 +27,12 @@ namespace SHADE
|
||||||
//#==============================================================#
|
//#==============================================================#
|
||||||
//|| Custom Widgets ||
|
//|| Custom Widgets ||
|
||||||
//#==============================================================#
|
//#==============================================================#
|
||||||
|
class SH_API SHEditorWidgets
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// Disable constructor for static class
|
||||||
|
SHEditorWidgets() = delete;
|
||||||
|
|
||||||
static bool Splitter(bool verticalSplit, float thickness, float* size1, float* size2, float minSize1, float minSize2, float splitterAxisSize = -1.0f)
|
static bool Splitter(bool verticalSplit, float thickness, float* size1, float* size2, float minSize1, float minSize2, float splitterAxisSize = -1.0f)
|
||||||
{
|
{
|
||||||
ImGuiWindow* window = ImGui::GetCurrentWindow();
|
ImGuiWindow* window = ImGui::GetCurrentWindow();
|
||||||
|
@ -181,7 +188,5 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
}//namespace SHADE
|
}//namespace SHADE
|
||||||
|
|
Loading…
Reference in New Issue