Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor UI Changes #454

Merged
merged 9 commits into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 30 additions & 17 deletions Engine/Source/Runtime/ImGui/ImGuiUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ static bool ImGuiBoolProperty(const char* pName, bool& value)
return ImGui::Checkbox(pName, &value);
}

static void Text(const char *pText, float fontScale = 1.0f)
{
float old_fontScale = ImGui::GetFont()->Scale;
ImGui::GetFont()->Scale *= fontScale;
ImGui::PushFont(ImGui::GetFont());
ImGui::Text(pText);
ImGui::GetFont()->Scale = old_fontScale;
ImGui::PopFont();
}

template<typename EnumType>
static bool ImGuiEnumProperty(const char* pName, EnumType& value)
{
Expand All @@ -26,7 +36,7 @@ static bool ImGuiEnumProperty(const char* pName, EnumType& value)
ImGui::NextColumn();
ImGui::PushItemWidth(-1);

if (ImGui::BeginCombo("##combo", nameof::nameof_enum(value).data()))
if (ImGui::BeginCombo(pName, nameof::nameof_enum(value).data()))
{
auto enumCount = nameof::enum_count<EnumType>();
for (uint32_t enumIndex = 0U; enumIndex < enumCount; ++enumIndex)
Expand Down Expand Up @@ -133,42 +143,42 @@ static bool ImGuiVectorProperty(const char* pName, T& value, cd::Unit unit = cd:
value.Normalize();
}

ImGui::Columns(2);
ImGui::TextUnformatted(pName);
ImGui::NextColumn();
ImGui::PushItemWidth(-1);
constexpr float labelIndetation = 10.0f;

ImGui::Indent(labelIndetation);
ImGuiUtils::Text(pName, 0.8f);
ImGui::Unindent(labelIndetation);
ImGui::PushItemWidth(350);
ImGui::SameLine(100.0f);

//std::string metricName = std::format("%.2f{}", cd::GetUnitName(unit));
std::string metricName = "%.2f";
metricName += cd::GetUnitName(unit);
float delta = maxValue.x() - minValue.x();
float dragSpeed = (speed <= 0.0) ? (cd::Math::IsEqualToZero(delta) ? 1.0f : delta * 0.05f) : speed;
if constexpr (std::is_same<T, cd::Vec2f>())
{
if (ImGui::DragFloat2(pName, value.begin(), dragSpeed, minValue.x(), maxValue.x(), metricName.c_str()))
if (ImGui::DragFloat2("##no_label", value.begin(), dragSpeed, minValue.x(), maxValue.x(), metricName.c_str()))
{
dirty = true;
}
}
else if constexpr (std::is_same<T, cd::Vec3f>())
{
if (ImGui::DragFloat3(pName, value.begin(), dragSpeed, minValue.x(), maxValue.x(), metricName.c_str()))
if (ImGui::DragFloat3("##no_label", value.begin(), dragSpeed, minValue.x(), maxValue.x(), metricName.c_str()))
{
dirty = true;
}
}
else if constexpr (std::is_same<T, cd::Vec4f>())
{
if (ImGui::DragFloat4(pName, value.begin(), dragSpeed, minValue.x(), maxValue.x(), metricName.c_str()))
if (ImGui::DragFloat4("##no_label", value.begin(), dragSpeed, minValue.x(), maxValue.x(), metricName.c_str()))
{
dirty = true;
}
}

ImGui::PopItemWidth();
ImGui::NextColumn();
ImGui::Columns(1);

return dirty;
}

Expand All @@ -189,18 +199,18 @@ static bool ImGuiTransformProperty(const char* pName, cd::Transform& value)
value.SetRotation(cd::Quaternion::FromPitchYawRoll(pitch, eularAngles.y(), eularAngles.z()));
dirty = true;
}
constexpr float labelIndetation = 10.0f;

cd::Vec3f originScale = value.GetScale();
cd::Vec3f scale = originScale;
ImGui::TextUnformatted("Scale");
ImGui::SameLine();
ImGui::Indent(labelIndetation);
ImGuiUtils::Text("Scale", 0.8f);
ImGui::Unindent(labelIndetation);
bool UniformScaleEnabled = engine::TransformComponent::DoUseUniformScale();
ImGui::Checkbox("Uniform", &UniformScaleEnabled);
engine::TransformComponent::SetUseUniformScale(UniformScaleEnabled);

ImGui::NextColumn();
ImGui::PushItemWidth(-1);

ImGui::PushItemWidth(350);
ImGui::SameLine(100.0f);
if (ImGui::DragFloat3("##Scale", scale.begin(), 0.1f, 0.001f, 999.0f))
{
if (!cd::Math::IsEqualTo(scale.x(), originScale.x()))
Expand Down Expand Up @@ -258,6 +268,9 @@ static bool ImGuiTransformProperty(const char* pName, cd::Transform& value)

ImGui::PopItemWidth();
ImGui::NextColumn();
ImGui::SameLine();
ImGui::Checkbox("Uniform", &UniformScaleEnabled);
engine::TransformComponent::SetUseUniformScale(UniformScaleEnabled);
ImGui::Columns(1);

return dirty;
Expand Down
Loading