Skip to content

Commit

Permalink
Inspector styling
Browse files Browse the repository at this point in the history
  • Loading branch information
fLindahl committed Nov 17, 2024
1 parent 1e7466e commit 5c37caa
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 23 deletions.
34 changes: 26 additions & 8 deletions code/application/game/componentinspection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void
ComponentDrawFuncT<int>(ComponentId component, void* data, bool* commit)
{
ImGui::PushID(component.id + 0x125233 + reinterpret_cast<intptr_t>(data));
if (ImGui::InputInt("##input_data", (int*)data))
if (ImGui::DragInt("##input_data", (int*)data))
*commit = true;
ImGui::PopID();
}
Expand All @@ -148,7 +148,7 @@ void
ComponentDrawFuncT<int64>(ComponentId component, void* data, bool* commit)
{
ImGui::PushID(component.id + 0x125233 + reinterpret_cast<intptr_t>(data));
if (ImGui::InputInt("##input_data", (int*)data))
if (ImGui::DragInt("##input_data", (int*)data))
*commit = true;
ImGui::PopID();
}
Expand All @@ -161,7 +161,7 @@ void
ComponentDrawFuncT<uint>(ComponentId component, void* data, bool* commit)
{
ImGui::PushID(component.id + 0x125233 + reinterpret_cast<intptr_t>(data));
if (ImGui::InputInt("##input_data", (int*)data))
if (ImGui::DragInt("##input_data", (int*)data), 1.0f, 0, 0xFFFFFFFF)
*commit = true;
ImGui::PopID();
}
Expand All @@ -174,7 +174,7 @@ void
ComponentDrawFuncT<uint64>(ComponentId component, void* data, bool* commit)
{
ImGui::PushID(component.id + 0x125233 + reinterpret_cast<intptr_t>(data));
if (ImGui::InputInt("##input_data", (int*)data))
if (ImGui::DragInt("##input_data", (int*)data, 1.0f, 0, 0xFFFFFFFF))
*commit = true;
ImGui::PopID();
}
Expand All @@ -187,7 +187,7 @@ void
ComponentDrawFuncT<float>(ComponentId component, void* data, bool* commit)
{
ImGui::PushID(component.id + 0x125233 + reinterpret_cast<intptr_t>(data));
if (ImGui::InputFloat("##float_input", (float*)data))
if (ImGui::DragFloat("##float_input", (float*)data))
*commit = true;
ImGui::PopID();
}
Expand Down Expand Up @@ -292,7 +292,7 @@ ComponentDrawFuncT<Game::Position>(ComponentId component, void* data, bool* comm
ImGui::Text("Position");
ImGui::TableSetColumnIndex(1);
ImGui::PushID(component.id + 0x125233 + reinterpret_cast<intptr_t>(data));
if (ImGui::InputFloat3("##pos", (float*)data))
if (ImGui::DragFloat3("##pos", (float*)data, 0.01f))
*commit = true;
ImGui::PopID();
}
Expand All @@ -309,7 +309,7 @@ ComponentDrawFuncT<Game::Orientation>(ComponentId component, void* data, bool* c
ImGui::Text("Orientation");
ImGui::TableSetColumnIndex(1);
ImGui::PushID(component.id + 0x125233 + reinterpret_cast<intptr_t>(data));
if (ImGui::InputFloat4("##orient", (float*)data))
if (ImGui::DragFloat4("##orient", (float*)data, 0.01f))
*commit = true;
ImGui::PopID();
}
Expand All @@ -326,8 +326,26 @@ ComponentDrawFuncT<Game::Scale>(ComponentId component, void* data, bool* commit)
ImGui::Text("Scale");
ImGui::TableSetColumnIndex(1);
ImGui::PushID(component.id + 0x125233 + reinterpret_cast<intptr_t>(data));
if (ImGui::InputFloat3("##scl", (float*)data))

static bool uniformScaling = true;
if (uniformScaling)
{
float* f = (float*)data;
if (ImGui::DragFloat("##scl", f, 0.01f))
{
f[1] = f[0];
f[2] = f[0];
*commit = true;
}
}
else if (ImGui::DragFloat3("##scl", (float*)data, 0.01f))
{
*commit = true;
}

ImGui::SameLine();
ImGui::Checkbox("Uniform scale", &uniformScaling);

ImGui::PopID();
}

Expand Down
15 changes: 6 additions & 9 deletions code/application/game/componentinspection.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,17 @@ InspectorDrawField(ComponentId component, void* data, bool* commit)
{
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
{
ImGui::SetTooltip(TYPE::Traits::field_descriptions[i]);
if (ImGui::BeginTooltip())
{
ImGui::TextDisabled(TYPE::Traits::field_typenames[i]);
ImGui::Text(TYPE::Traits::field_descriptions[i]);
ImGui::EndTooltip();
}
}
}
ImGui::TableSetColumnIndex(1);
ComponentDrawFuncT<field_type>(component, (byte*)data + TYPE::Traits::field_byte_offsets[i], commit);

ImGui::SameLine();
ImGuiStyle const& style = ImGui::GetStyle();
float widthNeeded =
ImGui::CalcTextSize(TYPE::Traits::field_typenames[i]).x + style.FramePadding.x * 2.f + style.ItemSpacing.x;
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - widthNeeded);
ImGui::AlignTextToFramePadding();
ImGui::TextDisabled(TYPE::Traits::field_typenames[i]);

if constexpr (i < TYPE::Traits::num_fields - 1)
{
ImGui::TableNextRow();
Expand Down
4 changes: 2 additions & 2 deletions toolkit/editor/editor/ui/windows/inspector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ Inspector::Run(SaveMode save)

bool commitChange = false;

const ImGuiTableFlags flags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_RowBg | ImGuiTableFlags_Borders |
ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable;
const ImGuiTableFlags flags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable |
ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable;
if (ImGui::BeginTable("table1", 2, flags))
{
ImGui::TableSetupColumn("FieldName", ImGuiTableColumnFlags_WidthFixed);
Expand Down
19 changes: 15 additions & 4 deletions toolkit/editor/editor/ui/windows/outline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "editor/ui/uimanager.h"
#include "editor/tools/selectiontool.h"
#include "editor/cmds.h"
#include "core/cvar.h"

using namespace Editor;

Expand Down Expand Up @@ -47,6 +48,8 @@ Outline::Run(SaveMode save)
static ImGuiTextFilter blueprintFilter;
static float filterDistance = 0.0f;

static Core::CVar* cl_debug_worlds = Core::CVarGet("cl_debug_worlds");

if (ImGui::Button("Filter"))
{
ImGui::OpenPopup(filterPopup);
Expand Down Expand Up @@ -142,6 +145,7 @@ Outline::Run(SaveMode save)
);
ImGui::SameLine();
ImGui::SetCursorPosX(xPos);
ImGui::AlignTextToFramePadding();
ImGui::TextDisabled("|-");
ImGui::SameLine();

Expand All @@ -150,11 +154,18 @@ Outline::Run(SaveMode save)
ImGui::Text(" "); // hack: this just replaces the image until that works again

ImGui::SameLine();
ImGui::SetCursorPosY(yPos + 3);
ImGui::AlignTextToFramePadding();
ImGui::Text(edit.name.AsCharPtr());
ImGui::SameLine();
ImGui::TextColored({0,0.4f,0.1f,0.3f}, edit.guid.AsString().AsCharPtr());
ImGui::SetCursorPosY(yPos);

if (Core::CVarReadInt(cl_debug_worlds) > 0)
{
ImGui::SameLine();
ImGuiStyle const& style = ImGui::GetStyle();
float widthNeeded = ImGui::CalcTextSize(edit.guid.AsString().AsCharPtr()).x + style.FramePadding.x * 2.f + style.ItemSpacing.x;
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + Math::max(ImGui::GetContentRegionAvail().x - widthNeeded, 0.0f));
ImGui::AlignTextToFramePadding();
ImGui::TextColored({0.1,0.2f,0.1f,0.5f}, edit.guid.AsString().AsCharPtr());
}
ImGui::PopID();
ImGui::EndGroup();

Expand Down

0 comments on commit 5c37caa

Please sign in to comment.