Add remaining controls to component view
This commit is contained in:
parent
ac70758341
commit
02ec5d88e8
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "../Components/SHComponent.h"
|
||||
#include <rttr/registration>
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -27,4 +28,50 @@ namespace SHADE
|
|||
std::string value{};
|
||||
};
|
||||
|
||||
class SHComponent_ENUM : public SHComponent
|
||||
{
|
||||
public:
|
||||
enum class Option
|
||||
{
|
||||
OPT_A,
|
||||
OPT_B,
|
||||
OPT_C
|
||||
};
|
||||
|
||||
bool boolTest{};
|
||||
int intTest{};
|
||||
float floatTest{};
|
||||
double doubleTest{};
|
||||
long longTest{};
|
||||
uint8_t uint8Test{};
|
||||
uint16_t uint16Test{};
|
||||
uint32_t uint32Test{};
|
||||
uint64_t uint64Test{};
|
||||
|
||||
|
||||
Option option;
|
||||
RTTR_ENABLE()
|
||||
};
|
||||
|
||||
RTTR_REGISTRATION
|
||||
{
|
||||
using namespace rttr;
|
||||
registration::enumeration<SHComponent_ENUM::Option>("Option")
|
||||
(
|
||||
value("Option A", SHComponent_ENUM::Option::OPT_A),
|
||||
value("Option B", SHComponent_ENUM::Option::OPT_B),
|
||||
value("Option C", SHComponent_ENUM::Option::OPT_C)
|
||||
);
|
||||
rttr::registration::class_<SHComponent_ENUM>("Enum Component")
|
||||
.property("Option", &SHComponent_ENUM::option)
|
||||
.property("boolTest", &SHComponent_ENUM::boolTest)
|
||||
.property("intTest", &SHComponent_ENUM::intTest)( metadata("MIN", 0.0f), metadata("MAX", 1.f))
|
||||
.property("floatTest", &SHComponent_ENUM::floatTest)(metadata("MIN", 0.0f), metadata("MAX", 1.f))
|
||||
.property("doubleTest", &SHComponent_ENUM::doubleTest)(metadata("MIN", 0.0f), metadata("MAX", 1.f))
|
||||
.property("uint8Test", &SHComponent_ENUM::uint8Test)(metadata("MIN", 0.0f), metadata("MAX", 1.f))
|
||||
.property("uint16Test", &SHComponent_ENUM::uint16Test)(metadata("MIN", 0.0f), metadata("MAX", 1.f))
|
||||
.property("uint32Test", &SHComponent_ENUM::uint32Test)(metadata("MIN", 0.0f), metadata("MAX", 1.f))
|
||||
.property("uint64Test", &SHComponent_ENUM::uint64Test)(metadata("MIN", 0.0f), metadata("MAX", 1.f));
|
||||
}
|
||||
|
||||
}
|
|
@ -12,6 +12,7 @@
|
|||
#include "Editor/IconsMaterialDesign.h"
|
||||
#include "ECS_Base/Components/SHComponent.h"
|
||||
#include "Editor/SHEditorWidgets.hpp"
|
||||
#include "Reflection/SHReflectionMetadata.h"
|
||||
namespace SHADE
|
||||
{
|
||||
template<typename T, std::enable_if_t<std::is_base_of<SHComponent, T>::value, bool> = true>
|
||||
|
@ -65,14 +66,112 @@ namespace SHADE
|
|||
ComboBox(property.get_name().data(), list, [component, property]{return property.get_value(component).to_int();}, [component, property](int const& idx)
|
||||
{
|
||||
auto enumAlign = property.get_enumeration();
|
||||
auto names = enumAlign.get_names();
|
||||
|
||||
property.set_value(component, *(enumAlign.get_values().begin().operator++(idx)));
|
||||
auto values = enumAlign.get_values();
|
||||
auto it = std::next(values.begin(), idx);
|
||||
property.set_value(component, *it);
|
||||
});
|
||||
}
|
||||
else if(type.is_arithmetic())
|
||||
{
|
||||
|
||||
if (type == rttr::type::get<bool>())
|
||||
{
|
||||
CheckBox(property.get_name().data(), [component, property]{return property.get_value(component).to_bool();}, [component, property](bool const& result){property.set_value(component, result);});
|
||||
}
|
||||
//else if (type == rttr::type::get<char>())
|
||||
//{
|
||||
//
|
||||
//}
|
||||
else if (type == rttr::type::get<int8_t>() || type == rttr::type::get<int16_t>() || type == rttr::type::get<int32_t>() || type == rttr::type::get<int64_t>())
|
||||
{
|
||||
auto metaMin = property.get_metadata(META::min);
|
||||
auto metaMax = property.get_metadata(META::max);
|
||||
if(metaMin && metaMax)
|
||||
{
|
||||
SliderInt(property.get_name().data(), metaMin.template get_value<int>(), metaMin.template get_value<int>(), [component, property]{return property.get_value(component).to_int();}, [component, property](int const& result){property.set_value(component, result);});
|
||||
}
|
||||
else
|
||||
{
|
||||
DragInt(property.get_name().data(), [component, property]{return property.get_value(component).to_int();}, [component, property](int const& result){property.set_value(component, result);});
|
||||
}
|
||||
}
|
||||
else if (type == rttr::type::get<uint8_t>())
|
||||
{
|
||||
auto metaMin = property.get_metadata(META::min);
|
||||
auto metaMax = property.get_metadata(META::max);
|
||||
if(metaMin.is_valid() && metaMax.is_valid())
|
||||
{
|
||||
SliderScalar<uint8_t>(property.get_name().data(), ImGuiDataType_U8, metaMin.template get_value<uint8_t>(), metaMax.template get_value<uint8_t>(), [component, property]{return property.get_value(component).to_uint8();}, [component, property](uint8_t const& result){property.set_value(component, result);},"%zu");
|
||||
}
|
||||
else
|
||||
{
|
||||
DragScalar<uint8_t>(property.get_name().data(), ImGuiDataType_U8, [component, property]{return property.get_value(component).to_uint8();}, [component, property](uint8_t const& result){property.set_value(component, result);},0.1f,0,0,"%zu");
|
||||
}
|
||||
}
|
||||
else if (type == rttr::type::get<uint16_t>())
|
||||
{
|
||||
auto metaMin = property.get_metadata(META::min);
|
||||
auto metaMax = property.get_metadata(META::max);
|
||||
if(metaMin.is_valid() && metaMax.is_valid())
|
||||
{
|
||||
SliderScalar<uint16_t>(property.get_name().data(), ImGuiDataType_U16, metaMin.template get_value<uint16_t>(), metaMin.template get_value<uint16_t>(), [component, property]{return property.get_value(component).to_uint16();}, [component, property](uint16_t const& result){property.set_value(component, result);},"%zu");
|
||||
}
|
||||
else
|
||||
{
|
||||
DragScalar<uint16_t>(property.get_name().data(), ImGuiDataType_U16, [component, property]{return property.get_value(component).to_uint16();}, [component, property](uint16_t const& result){property.set_value(component, result);},0.1f,0,0,"%zu");
|
||||
}
|
||||
}
|
||||
else if (type == rttr::type::get<uint32_t>())
|
||||
{
|
||||
auto metaMin = property.get_metadata(META::min);
|
||||
auto metaMax = property.get_metadata(META::max);
|
||||
if (metaMin.is_valid() && metaMax.is_valid())
|
||||
{
|
||||
SliderScalar<uint32_t>(property.get_name().data(), ImGuiDataType_U32, metaMin.template get_value<uint32_t>(), metaMin.template get_value<uint32_t>(), [component, property]{ return property.get_value(component).to_uint32(); }, [component, property](uint32_t const& result){property.set_value(component, result); },"%zu");
|
||||
}
|
||||
else
|
||||
{
|
||||
DragScalar<uint32_t>(property.get_name().data(), ImGuiDataType_U32, [component, property]{ return property.get_value(component).to_uint32(); }, [component, property](uint32_t const& result){property.set_value(component, result); },0.1f,0,0,"%zu");
|
||||
}
|
||||
}
|
||||
else if (type == rttr::type::get<uint64_t>())
|
||||
{
|
||||
auto metaMin = property.get_metadata(META::min);
|
||||
auto metaMax = property.get_metadata(META::max);
|
||||
if(metaMin.is_valid() && metaMax.is_valid())
|
||||
{
|
||||
SliderScalar<uint64_t>(property.get_name().data(), ImGuiDataType_U64, metaMin.template get_value<uint64_t>(), metaMin.template get_value<uint64_t>(), [component, property]{return property.get_value(component).to_uint64();}, [component, property](uint64_t const& result){property.set_value(component, result);},"%zu");
|
||||
}
|
||||
else
|
||||
{
|
||||
DragScalar<uint64_t>(property.get_name().data(), ImGuiDataType_U64, [component, property]{return property.get_value(component).to_uint64();}, [component, property](uint64_t const& result){property.set_value(component, result);},0.1f,0,0,"%zu");
|
||||
}
|
||||
}
|
||||
else if (type == rttr::type::get<float>())
|
||||
{
|
||||
auto metaMin = property.get_metadata(META::min);
|
||||
auto metaMax = property.get_metadata(META::max);
|
||||
if(metaMin.is_valid() && metaMax.is_valid())
|
||||
{
|
||||
SliderFloat(property.get_name().data(), metaMin.template get_value<float>(), metaMin.template get_value<float>(), [component, property]{return property.get_value(component).to_float();}, [component, property](float const& result){property.set_value(component, result);});
|
||||
}
|
||||
else
|
||||
{
|
||||
DragFloat(property.get_name().data(), [component, property]{return property.get_value(component).to_float();}, [component, property](float const& result){property.set_value(component, result);});
|
||||
}
|
||||
}
|
||||
else if (type == rttr::type::get<double>())
|
||||
{
|
||||
auto metaMin = property.get_metadata(META::min);
|
||||
auto metaMax = property.get_metadata(META::max);
|
||||
if(metaMin.is_valid() && metaMax.is_valid())
|
||||
{
|
||||
SliderScalar<double>(property.get_name().data(), ImGuiDataType_Double, metaMin.template get_value<double>(), metaMin.template get_value<double>(), [component, property]{return property.get_value(component).to_double();}, [component, property](double const& result){property.set_value(component, result);});
|
||||
}
|
||||
else
|
||||
{
|
||||
DragScalar<double>(property.get_name().data(), ImGuiDataType_Double, [component, property]{return property.get_value(component).to_double();}, [component, property](double const& result){property.set_value(component, result);}, 0.1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (type == rttr::type::get<SHVec4>())
|
||||
{
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "Editor/SHImGuiHelpers.hpp"
|
||||
#include "Editor/SHEditorWidgets.hpp"
|
||||
#include "SHEditorComponentView.hpp"
|
||||
#include "ECS_Base/UnitTesting/SHTestComponents.h"
|
||||
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
|
||||
|
||||
namespace SHADE
|
||||
|
@ -54,11 +55,20 @@ namespace SHADE
|
|||
{
|
||||
DrawComponent(transformComponent);
|
||||
}
|
||||
if(auto renderableComponent = SHComponentManager::GetComponent_s<SHRenderable>(eid))
|
||||
{
|
||||
DrawComponent(renderableComponent);
|
||||
}
|
||||
if(auto testComponent = SHComponentManager::GetComponent_s<SHComponent_ENUM>(eid))
|
||||
{
|
||||
DrawComponent(testComponent);
|
||||
}
|
||||
ImGui::Separator();
|
||||
if(ImGui::BeginMenu(std::format("{} Add Component", ICON_MD_LIBRARY_ADD).data()))
|
||||
{
|
||||
DrawAddComponentButton<SHTransformComponent>(eid);
|
||||
DrawAddComponentButton<SHRenderable>(eid);
|
||||
DrawAddComponentButton<SHComponent_ENUM>(eid);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -202,6 +202,7 @@ namespace SHADE
|
|||
float speed = 1.0f, T p_min = T(), T p_max = T(), const char* displayFormat = "%.3f", ImGuiSliderFlags flags = 0)
|
||||
{
|
||||
T value = get();
|
||||
std::cout << value <<" \n";
|
||||
//bool hasChange = ImGui::DragScalar(fieldLabel.c_str(), data_type, &value, speed, &p_min, &p_max, displayFormat, flags);
|
||||
|
||||
if (ImGui::DragScalar(fieldLabel.c_str(), data_type, &value, speed, &p_min, &p_max, displayFormat, flags))
|
||||
|
@ -257,6 +258,23 @@ namespace SHADE
|
|||
|
||||
return false;
|
||||
}
|
||||
template <typename T>
|
||||
static bool SliderScalar(const std::string& fieldLabel, ImGuiDataType data_type, T min, T max, std::function<T(void)> get, std::function<void(T const&)> set,
|
||||
const char* displayFormat = "%.3f", ImGuiSliderFlags flags = 0)
|
||||
{
|
||||
T value = get();
|
||||
if (ImGui::SliderScalar(fieldLabel.c_str(), data_type, &value, &min, &max, displayFormat, flags))
|
||||
{
|
||||
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left, false) && !ImGui::IsMouseDragging(ImGuiMouseButton_Left, -0.2f))
|
||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<T>>(get(), value, set)), false);
|
||||
else if (ImGui::IsMouseDragging(ImGuiMouseButton_Left))
|
||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<T>>(get(), value, set)), true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool SliderFloat(const std::string& fieldLabel, float min, float max, std::function<float(void)> get, std::function<void(float const&)> set,
|
||||
const char* displayFormat = "%.3f", ImGuiSliderFlags flags = 0)
|
||||
|
@ -295,14 +313,17 @@ namespace SHADE
|
|||
|
||||
static bool ComboBox(const std::string& fieldLabel, std::vector<const char*> list, std::function<int(void)> get, std::function<void(int const&)> set)
|
||||
{
|
||||
bool edited = false;
|
||||
int selected = get();
|
||||
if (ImGui::Combo(fieldLabel.c_str(), &selected, list.data(), list.size()))
|
||||
ImGui::PushID(fieldLabel.c_str());
|
||||
ImGui::Text(fieldLabel.c_str()); ImGui::SameLine();
|
||||
|
||||
if (edited = ImGui::Combo("##Combo", &selected, list.data(), list.size()))
|
||||
{
|
||||
SHCommandManager::PerformCommand(std::reinterpret_pointer_cast<SHBaseCommand>(std::make_shared<SHCommand<int>>(get(), selected, set)), false);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
ImGui::PopID();
|
||||
return edited;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
#include "string_view"
|
||||
namespace SHADE
|
||||
{
|
||||
namespace META
|
||||
{
|
||||
constexpr const char* min = "MIN";
|
||||
constexpr const char* max = "MAX";
|
||||
constexpr const char* tooltip = "tooltip";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue