Skip to content

Commit

Permalink
Restyled default dynui, editor and inspectors
Browse files Browse the repository at this point in the history
  • Loading branch information
fLindahl committed Nov 17, 2024
1 parent 4c606f8 commit 4ee9362
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 54 deletions.
30 changes: 15 additions & 15 deletions code/addons/dynui/imguicontext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -452,28 +452,28 @@ ImguiContext::Create()

ImGuiStyle& style = ImGui::GetStyle();

style.FrameRounding = 2.0f;
style.FrameRounding = 0.0f;
style.GrabRounding = 0.0f;
style.ChildRounding = 0.0f;
style.WindowRounding = 2.0f;
style.WindowRounding = 0.0f;
style.PopupRounding = 0.0f;
style.ScrollbarRounding = 2.0f;
style.TabRounding = 3.0f;
style.ScrollbarRounding = 0.0f;
style.TabRounding = 0.0f;
style.TabMinWidthForCloseButton = FLT_MAX;
style.WindowTitleAlign = { 0.5f, 0.38f };
style.WindowTitleAlign = { 0.0f, 0.52f };
style.WindowMenuButtonPosition = ImGuiDir_Right;

style.WindowPadding = { 8.0f, 8.0f };
style.WindowPadding = { 10.0f, 10.0f };
// FIXME: ImGui seems to have problems with the "X" (close window) button when setting framepadding to anything higher than ~4. Could be the docking branch which is currently in beta.
style.FramePadding = { 4, 3 };//{ 16, 3 };
style.ItemInnerSpacing = { 4, 2 };
style.ItemSpacing = { 4, 5 };
style.IndentSpacing = 8.0f;
style.FramePadding = { 8, 3 };//{ 16, 3 };
style.ItemInnerSpacing = { 2, 2 };
style.ItemSpacing = { 2, 2 };
style.IndentSpacing = 10.0f;
style.GrabMinSize = 8.0f;

style.FrameBorderSize = 0.0f;
style.FrameBorderSize = 1.0f;
style.WindowBorderSize = 1.0f;
style.PopupBorderSize = 0.0f;
style.PopupBorderSize = 1.0f;
style.ChildBorderSize = 0.0f;

style.ScaleAllSizes(scaleFactor);
Expand Down Expand Up @@ -526,10 +526,10 @@ ImguiContext::Create()
colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
colors[ImGuiCol_TableHeaderBg] = ImVec4(0.19f, 0.19f, 0.20f, 1.00f);
colors[ImGuiCol_TableBorderStrong] = ImVec4(0.31f, 0.31f, 0.35f, 1.00f);
colors[ImGuiCol_TableBorderLight] = ImVec4(0.23f, 0.23f, 0.25f, 1.00f);
colors[ImGuiCol_TableBorderStrong] = ImVec4(0.039f, 0.039f, 0.039f, 1.00f);
colors[ImGuiCol_TableBorderLight] = ImVec4(0.174f, 0.174f, 0.174f, 1.00f);
colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.06f);
colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.022f);
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f);
colors[ImGuiCol_NavHighlight] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
Expand Down
2 changes: 0 additions & 2 deletions code/addons/graphicsfeature/managers/graphicsmanager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,7 @@ template <>
void
Game::ComponentDrawFuncT<GraphicsFeature::AreaLightShape>(Game::ComponentId component, void* data, bool* commit)
{
ImGui::SameLine();
ImGui::PushID(component.id + 0x125233 + reinterpret_cast<intptr_t>(data));

static const char* items[] {"Disk", "Rectangle", "Tube"};
static_assert(sizeof(items) / sizeof(const char*) == (int)GraphicsFeature::AreaLightShape::NumAreaLightShape);
GraphicsFeature::AreaLightShape* selectedItem = (GraphicsFeature::AreaLightShape*)data;
Expand Down
86 changes: 63 additions & 23 deletions code/application/game/componentinspection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ template<>
void
ComponentDrawFuncT<bool>(ComponentId component, void* data, bool* commit)
{
MemDb::Attribute* desc = MemDb::AttributeRegistry::GetAttribute(component);
ImGui::PushID(component.id + 0x125233 + reinterpret_cast<intptr_t>(data));
if (ImGui::Checkbox("##input_data", (bool*)data))
*commit = true;
Expand All @@ -135,8 +134,19 @@ template<>
void
ComponentDrawFuncT<int>(ComponentId component, void* data, bool* commit)
{
MemDb::Attribute* desc = MemDb::AttributeRegistry::GetAttribute(component);
ImGui::PushID(component.id + 0x125233 + reinterpret_cast<intptr_t>(data));
if (ImGui::InputInt("##input_data", (int*)data))
*commit = true;
ImGui::PopID();
}

//------------------------------------------------------------------------------
/**
*/
template <>
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))
*commit = true;
Expand All @@ -150,8 +160,19 @@ template<>
void
ComponentDrawFuncT<uint>(ComponentId component, void* data, bool* commit)
{
MemDb::Attribute* desc = MemDb::AttributeRegistry::GetAttribute(component);
ImGui::PushID(component.id + 0x125233 + reinterpret_cast<intptr_t>(data));
if (ImGui::InputInt("##input_data", (int*)data))
*commit = true;
ImGui::PopID();
}

//------------------------------------------------------------------------------
/**
*/
template <>
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))
*commit = true;
Expand All @@ -165,8 +186,6 @@ template<>
void
ComponentDrawFuncT<float>(ComponentId component, void* data, bool* commit)
{
MemDb::Attribute* desc = MemDb::AttributeRegistry::GetAttribute(component);

ImGui::PushID(component.id + 0x125233 + reinterpret_cast<intptr_t>(data));
if (ImGui::InputFloat("##float_input", (float*)data))
*commit = true;
Expand All @@ -180,7 +199,6 @@ template<>
void
ComponentDrawFuncT<Util::StringAtom>(ComponentId component, void* data, bool* commit)
{
MemDb::Attribute* desc = MemDb::AttributeRegistry::GetAttribute(component);
ImGui::PushID(component.id + 0x125233 + reinterpret_cast<intptr_t>(data));
ImGui::Text(((Util::StringAtom*)data)->Value());
if (ImGui::BeginDragDropTarget())
Expand All @@ -204,8 +222,6 @@ template<>
void
ComponentDrawFuncT<Math::mat4>(ComponentId component, void* data, bool* commit)
{
MemDb::Attribute* desc = MemDb::AttributeRegistry::GetAttribute(component);

ImGui::PushID(component.id + 0x125233 + reinterpret_cast<intptr_t>(data));
if (ImGui::InputFloat4("##row0", (float*)data))
*commit = true;
Expand All @@ -225,10 +241,34 @@ template<>
void
ComponentDrawFuncT<Math::vec3>(ComponentId component, void* data, bool* commit)
{
MemDb::Attribute* desc = MemDb::AttributeRegistry::GetAttribute(component);
ImGui::PushID(component.id + 0x125233 + reinterpret_cast<intptr_t>(data));
if (ImGui::InputFloat3("##vec3", (float*)data))
*commit = true;
ImGui::PopID();
}

//------------------------------------------------------------------------------
/**
*/
template <>
void
ComponentDrawFuncT<Math::vec4>(ComponentId component, void* data, bool* commit)
{
ImGui::PushID(component.id + 0x125233 + reinterpret_cast<intptr_t>(data));
if (ImGui::InputFloat3("##vec", (float*)data))
if (ImGui::InputFloat4("##vec4", (float*)data))
*commit = true;
ImGui::PopID();
}

//------------------------------------------------------------------------------
/**
*/
template <>
void
ComponentDrawFuncT<Math::quat>(ComponentId component, void* data, bool* commit)
{
ImGui::PushID(component.id + 0x125233 + reinterpret_cast<intptr_t>(data));
if (ImGui::InputFloat4("##quat", (float*)data))
*commit = true;
ImGui::PopID();
}
Expand All @@ -240,9 +280,10 @@ template<>
void
ComponentDrawFuncT<Game::Position>(ComponentId component, void* data, bool* commit)
{
MemDb::Attribute* desc = MemDb::AttributeRegistry::GetAttribute(component);

ImGui::SameLine();
ImGui::TableSetColumnIndex(0);
ImGui::AlignTextToFramePadding();
ImGui::Text("Position");
ImGui::TableSetColumnIndex(1);
ImGui::PushID(component.id + 0x125233 + reinterpret_cast<intptr_t>(data));
if (ImGui::InputFloat3("##pos", (float*)data))
*commit = true;
Expand All @@ -256,9 +297,10 @@ template<>
void
ComponentDrawFuncT<Game::Orientation>(ComponentId component, void* data, bool* commit)
{
MemDb::Attribute* desc = MemDb::AttributeRegistry::GetAttribute(component);

ImGui::SameLine();
ImGui::TableSetColumnIndex(0);
ImGui::AlignTextToFramePadding();
ImGui::Text("Orientation");
ImGui::TableSetColumnIndex(1);
ImGui::PushID(component.id + 0x125233 + reinterpret_cast<intptr_t>(data));
if (ImGui::InputFloat4("##orient", (float*)data))
*commit = true;
Expand All @@ -272,9 +314,10 @@ template<>
void
ComponentDrawFuncT<Game::Scale>(ComponentId component, void* data, bool* commit)
{
MemDb::Attribute* desc = MemDb::AttributeRegistry::GetAttribute(component);

ImGui::SameLine();
ImGui::TableSetColumnIndex(0);
ImGui::AlignTextToFramePadding();
ImGui::Text("Scale");
ImGui::TableSetColumnIndex(1);
ImGui::PushID(component.id + 0x125233 + reinterpret_cast<intptr_t>(data));
if (ImGui::InputFloat3("##scl", (float*)data))
*commit = true;
Expand All @@ -288,11 +331,8 @@ template<>
void
ComponentDrawFuncT<Util::Color>(ComponentId component, void* data, bool* commit)
{
MemDb::Attribute* desc = MemDb::AttributeRegistry::GetAttribute(component);

ImGui::SameLine();
ImGui::PushID(component.id + 0x125233 + reinterpret_cast<intptr_t>(data));
if (ImGui::ColorEdit4("##scl", (float*)data))
if (ImGui::ColorEdit4("##color", (float*)data))
*commit = true;
ImGui::PopID();
}
Expand Down
15 changes: 12 additions & 3 deletions code/application/game/componentinspection.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,16 @@ InspectorDrawField(ComponentId component, void* data, bool* commit)
Util::String fieldName = TYPE::Traits::field_names[i];
fieldName.CamelCaseToWords();
fieldName.Capitalize();
ImGui::TableSetColumnIndex(0);
ImGui::Text(fieldName.AsCharPtr());
ImGui::SameLine();
ImGui::TableSetColumnIndex(1);
ComponentDrawFuncT<field_type>(component, (byte*)data + TYPE::Traits::field_byte_offsets[i], commit);
InspectorDrawField<TYPE, i + 1>(component, data, commit);

if constexpr (i < TYPE::Traits::num_fields - 1)
{
ImGui::TableNextRow();
InspectorDrawField<TYPE, i + 1>(component, data, commit);
}
}
}

Expand All @@ -79,7 +85,6 @@ ComponentDrawFuncT(ComponentId component, void* data, bool* commit)
{
if constexpr (TYPE::Traits::num_fields > 0 && !std::is_enum<TYPE>())
{
//UnrollTypesAndInspect<TYPE>(std::make_index_sequence<TYPE::Traits::num_fields>(), component, data, commit);
InspectorDrawField<TYPE>(component, data, commit);
}
}
Expand All @@ -89,11 +94,15 @@ ComponentDrawFuncT(ComponentId component, void* data, bool* commit)
template<> void ComponentDrawFuncT<Game::Entity>(ComponentId, void*, bool*);
template<> void ComponentDrawFuncT<bool>(ComponentId, void*, bool*);
template<> void ComponentDrawFuncT<int>(ComponentId, void*, bool*);
template<> void ComponentDrawFuncT<int64>(ComponentId, void*, bool*);
template<> void ComponentDrawFuncT<uint>(ComponentId, void*, bool*);
template<> void ComponentDrawFuncT<uint64>(ComponentId, void*, bool*);
template<> void ComponentDrawFuncT<float>(ComponentId, void*, bool*);
template<> void ComponentDrawFuncT<Util::StringAtom>(ComponentId, void*, bool*);
template<> void ComponentDrawFuncT<Math::mat4>(ComponentId, void*, bool*);
template<> void ComponentDrawFuncT<Math::vec3>(ComponentId, void*, bool*);
template<> void ComponentDrawFuncT<Math::vec4>(ComponentId, void*, bool*);
template<> void ComponentDrawFuncT<Math::quat>(ComponentId, void*, bool*);
template<> void ComponentDrawFuncT<Game::Position>(ComponentId, void*, bool*);
template<> void ComponentDrawFuncT<Game::Orientation>(ComponentId, void*, bool*);
template<> void ComponentDrawFuncT<Game::Scale>(ComponentId, void*, bool*);
Expand Down
45 changes: 34 additions & 11 deletions toolkit/editor/editor/ui/windows/inspector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,32 @@ Inspector::Run(SaveMode save)
{
continue;
}

ImGui::Spacing();
ImGui::Spacing();

ImGui::PushID(0xA3FC + (int)component.id); // offset the ids with some magic number
Util::String componentName = MemDb::AttributeRegistry::GetAttribute(component)->name.AsString();
componentName.CamelCaseToWords();
componentName.Capitalize();
ImGui::Text(componentName.AsCharPtr());
ImGui::SameLine();

if (component != Game::GetComponentId<Game::Position>() &&
component != Game::GetComponentId<Game::Orientation>() &&
if (component != Game::GetComponentId<Game::Position>() && component != Game::GetComponentId<Game::Orientation>() &&
component != Game::GetComponentId<Game::Scale>())
{
Util::String componentName = MemDb::AttributeRegistry::GetAttribute(component)->name.AsString();
componentName.CamelCaseToWords();
componentName.Capitalize();

ImGui::AlignTextToFramePadding();
ImGui::Text(componentName.AsCharPtr());
ImGui::SameLine();

ImGuiStyle const& style = ImGui::GetStyle();
float widthNeeded = ImGui::CalcTextSize("Remove").x + style.FramePadding.x * 2.f + style.ItemSpacing.x;
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - widthNeeded);
if (ImGui::Button("Remove"))
{
Edit::RemoveComponent(entity, component);
ImGui::PopID();
return; // return, otherwise we're reading stale data.
}
ImGui::Spacing();
}

auto& tempComponent = this->tempComponents[i];
Expand Down Expand Up @@ -163,7 +172,22 @@ Inspector::Run(SaveMode save)
}

bool commitChange = false;
Game::ComponentInspection::DrawInspector(component, tempComponent.buffer, &commitChange);

const ImGuiTableFlags flags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_RowBg | ImGuiTableFlags_Borders |
ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable;
if (ImGui::BeginTable("table1", 2, flags))
{
ImGui::TableSetupColumn("FieldName", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("FieldValue", ImGuiTableColumnFlags_WidthStretch);

//ImGui::TableHeadersRow();
ImGui::TableNextRow();
Game::ComponentInspection::DrawInspector(component, tempComponent.buffer, &commitChange);
ImGui::EndTable();
ImGui::Spacing();
ImGui::Spacing();
ImGui::Spacing();
}

if (commitChange)
{
Expand Down Expand Up @@ -232,8 +256,7 @@ Inspector::ShowAddComponentMenu()
Game::Position::Traits::name,
Game::Orientation::Traits::name,
Game::Scale::Traits::name,
Game::IsActive::Traits::name
};
Game::IsActive::Traits::name};

for (SizeT i = 0; i < numComponents; i++)
{
Expand Down

0 comments on commit 4ee9362

Please sign in to comment.