mirror of
https://github.com/ocornut/imgui.git
synced 2024-12-03 21:59:15 +08:00
Demo: Property Editor: rearrange code + replace use of bool to proper ImGuiChildFlags.
Amend 46691d1
This commit is contained in:
parent
9c1f922b02
commit
4247f190c2
173
imgui_demo.cpp
173
imgui_demo.cpp
@ -83,6 +83,7 @@ Index of this file:
|
|||||||
// [SECTION] Example App: Debug Console / ShowExampleAppConsole()
|
// [SECTION] Example App: Debug Console / ShowExampleAppConsole()
|
||||||
// [SECTION] Example App: Debug Log / ShowExampleAppLog()
|
// [SECTION] Example App: Debug Log / ShowExampleAppLog()
|
||||||
// [SECTION] Example App: Simple Layout / ShowExampleAppLayout()
|
// [SECTION] Example App: Simple Layout / ShowExampleAppLayout()
|
||||||
|
// [SECTION] Helpers: ExampleTreeNode, ExampleMemberInfo (for use by Property Editor etc.)
|
||||||
// [SECTION] Example App: Property Editor / ShowExampleAppPropertyEditor()
|
// [SECTION] Example App: Property Editor / ShowExampleAppPropertyEditor()
|
||||||
// [SECTION] Example App: Long Text / ShowExampleAppLongText()
|
// [SECTION] Example App: Long Text / ShowExampleAppLongText()
|
||||||
// [SECTION] Example App: Auto Resize / ShowExampleAppAutoResize()
|
// [SECTION] Example App: Auto Resize / ShowExampleAppAutoResize()
|
||||||
@ -7744,7 +7745,7 @@ static void ShowExampleAppLayout(bool* p_open)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// [SECTION] Example App: Property Editor / ShowExampleAppPropertyEditor()
|
// [SECTION] Helpers: ExampleTreeNode, ExampleMemberInfo (for use by Property Editor etc.)
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
// Simple representation for a tree
|
// Simple representation for a tree
|
||||||
@ -7819,92 +7820,98 @@ static ExampleTreeNode* ExampleTree_CreateDemoTree()
|
|||||||
return node_L0;
|
return node_L0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PropertyEditor_ShowTreeNode(ExampleTreeNode* node)
|
//-----------------------------------------------------------------------------
|
||||||
{
|
// [SECTION] Example App: Property Editor / ShowExampleAppPropertyEditor()
|
||||||
// Object tree node
|
//-----------------------------------------------------------------------------
|
||||||
ImGui::PushID((int)node->UID);
|
|
||||||
ImGui::TableNextRow();
|
|
||||||
ImGui::TableSetColumnIndex(0);
|
|
||||||
ImGui::AlignTextToFramePadding();
|
|
||||||
ImGuiTreeNodeFlags tree_flags = ImGuiTreeNodeFlags_None;
|
|
||||||
tree_flags |= ImGuiTreeNodeFlags_SpanAllColumns | ImGuiTreeNodeFlags_AllowOverlap; // Highlight whole row for visibility
|
|
||||||
tree_flags |= ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick; // Standard opening mode as we are likely to want to add selection afterwards
|
|
||||||
tree_flags |= ImGuiTreeNodeFlags_NavLeftJumpsBackHere; // Left arrow support
|
|
||||||
bool node_open = ImGui::TreeNodeEx("##Object", tree_flags, "%s", node->Name);
|
|
||||||
ImGui::TableSetColumnIndex(1);
|
|
||||||
ImGui::TextDisabled("UID: 0x%08X", node->UID);
|
|
||||||
|
|
||||||
// Display child and data
|
struct ExampleAppPropertyEditor
|
||||||
if (node_open)
|
{
|
||||||
for (ExampleTreeNode* child : node->Childs)
|
void Draw(ExampleTreeNode* root_node)
|
||||||
PropertyEditor_ShowTreeNode(child);
|
|
||||||
if (node_open && node->HasData)
|
|
||||||
{
|
{
|
||||||
// In a typical application, the structure description would be derived from a data-driven system.
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2, 2));
|
||||||
// - We try to mimic this with our ExampleMemberInfo structure and the ExampleTreeNodeMemberInfos[] array.
|
ImGuiTableFlags table_flags = ImGuiTableFlags_BordersOuter | ImGuiTableFlags_Resizable | ImGuiTableFlags_ScrollY | ImGuiTableFlags_RowBg;
|
||||||
// - Limits and some details are hard-coded to simplify the demo.
|
if (ImGui::BeginTable("##split", 2, table_flags))
|
||||||
// - Text and Selectable are less high than framed widgets, using AlignTextToFramePadding() we add vertical spacing to make the selectable lines equal high.
|
|
||||||
for (const ExampleMemberInfo& field_desc : ExampleTreeNodeMemberInfos)
|
|
||||||
{
|
{
|
||||||
ImGui::TableNextRow();
|
ImGui::TableSetupScrollFreeze(0, 1);
|
||||||
ImGui::TableSetColumnIndex(0);
|
ImGui::TableSetupColumn("Object", ImGuiTableColumnFlags_WidthStretch, 1.0f);
|
||||||
ImGui::AlignTextToFramePadding();
|
ImGui::TableSetupColumn("Contents", ImGuiTableColumnFlags_WidthStretch, 2.0f); // Default twice larger
|
||||||
ImGui::PushItemFlag(ImGuiItemFlags_NoTabStop | ImGuiItemFlags_NoNav, true);
|
ImGui::TableHeadersRow();
|
||||||
ImGui::Selectable(field_desc.Name, false, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowOverlap);
|
for (ExampleTreeNode* node : root_node->Childs)
|
||||||
ImGui::PopItemFlag();
|
DrawTreeNode(node);
|
||||||
ImGui::TableSetColumnIndex(1);
|
ImGui::EndTable();
|
||||||
ImGui::PushID(field_desc.Name);
|
|
||||||
void* field_ptr = (void*)(((unsigned char*)node) + field_desc.Offset);
|
|
||||||
switch (field_desc.DataType)
|
|
||||||
{
|
|
||||||
case ImGuiDataType_Bool:
|
|
||||||
{
|
|
||||||
IM_ASSERT(field_desc.DataCount == 1);
|
|
||||||
ImGui::Checkbox("##Editor", (bool*)field_ptr);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ImGuiDataType_S32:
|
|
||||||
{
|
|
||||||
int v_min = INT_MIN, v_max = INT_MAX;
|
|
||||||
ImGui::SetNextItemWidth(-FLT_MIN);
|
|
||||||
ImGui::DragScalarN("##Editor", field_desc.DataType, field_ptr, field_desc.DataCount, 1.0f, &v_min, &v_max);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ImGuiDataType_Float:
|
|
||||||
{
|
|
||||||
float v_min = 0.0f, v_max = 1.0f;
|
|
||||||
ImGui::SetNextItemWidth(-FLT_MIN);
|
|
||||||
ImGui::SliderScalarN("##Editor", field_desc.DataType, field_ptr, field_desc.DataCount, &v_min, &v_max);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ImGui::PopID();
|
|
||||||
}
|
}
|
||||||
|
ImGui::PopStyleVar();
|
||||||
}
|
}
|
||||||
if (node_open)
|
|
||||||
ImGui::TreePop();
|
|
||||||
ImGui::PopID();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void PropertyEditor_ShowTree(ExampleTreeNode* root_node)
|
void DrawTreeNode(ExampleTreeNode* node)
|
||||||
{
|
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2, 2));
|
|
||||||
ImGuiTableFlags table_flags = ImGuiTableFlags_BordersOuter | ImGuiTableFlags_Resizable | ImGuiTableFlags_ScrollY | ImGuiTableFlags_RowBg;
|
|
||||||
if (ImGui::BeginTable("##split", 2, table_flags))
|
|
||||||
{
|
{
|
||||||
ImGui::TableSetupScrollFreeze(0, 1);
|
// Object tree node
|
||||||
ImGui::TableSetupColumn("Object", ImGuiTableColumnFlags_WidthStretch, 1.0f);
|
ImGui::PushID((int)node->UID);
|
||||||
ImGui::TableSetupColumn("Contents", ImGuiTableColumnFlags_WidthStretch, 2.0f); // Default twice larger
|
ImGui::TableNextRow();
|
||||||
ImGui::TableHeadersRow();
|
ImGui::TableSetColumnIndex(0);
|
||||||
for (ExampleTreeNode* node : root_node->Childs)
|
ImGui::AlignTextToFramePadding();
|
||||||
PropertyEditor_ShowTreeNode(node);
|
ImGuiTreeNodeFlags tree_flags = ImGuiTreeNodeFlags_None;
|
||||||
ImGui::EndTable();
|
tree_flags |= ImGuiTreeNodeFlags_SpanAllColumns | ImGuiTreeNodeFlags_AllowOverlap; // Highlight whole row for visibility
|
||||||
}
|
tree_flags |= ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick; // Standard opening mode as we are likely to want to add selection afterwards
|
||||||
ImGui::PopStyleVar();
|
tree_flags |= ImGuiTreeNodeFlags_NavLeftJumpsBackHere; // Left arrow support
|
||||||
}
|
bool node_open = ImGui::TreeNodeEx("##Object", tree_flags, "%s", node->Name);
|
||||||
|
ImGui::TableSetColumnIndex(1);
|
||||||
|
ImGui::TextDisabled("UID: 0x%08X", node->UID);
|
||||||
|
|
||||||
// Demonstrate create a simple property editor.
|
// Display child and data
|
||||||
// This demo is a bit lackluster nowadays, would be nice to improve.
|
if (node_open)
|
||||||
|
for (ExampleTreeNode* child : node->Childs)
|
||||||
|
DrawTreeNode(child);
|
||||||
|
if (node_open && node->HasData)
|
||||||
|
{
|
||||||
|
// In a typical application, the structure description would be derived from a data-driven system.
|
||||||
|
// - We try to mimic this with our ExampleMemberInfo structure and the ExampleTreeNodeMemberInfos[] array.
|
||||||
|
// - Limits and some details are hard-coded to simplify the demo.
|
||||||
|
// - Text and Selectable are less high than framed widgets, using AlignTextToFramePadding() we add vertical spacing to make the selectable lines equal high.
|
||||||
|
for (const ExampleMemberInfo& field_desc : ExampleTreeNodeMemberInfos)
|
||||||
|
{
|
||||||
|
ImGui::TableNextRow();
|
||||||
|
ImGui::TableSetColumnIndex(0);
|
||||||
|
ImGui::AlignTextToFramePadding();
|
||||||
|
ImGui::PushItemFlag(ImGuiItemFlags_NoTabStop | ImGuiItemFlags_NoNav, true);
|
||||||
|
ImGui::Selectable(field_desc.Name, false, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowOverlap);
|
||||||
|
ImGui::PopItemFlag();
|
||||||
|
ImGui::TableSetColumnIndex(1);
|
||||||
|
ImGui::PushID(field_desc.Name);
|
||||||
|
void* field_ptr = (void*)(((unsigned char*)node) + field_desc.Offset);
|
||||||
|
switch (field_desc.DataType)
|
||||||
|
{
|
||||||
|
case ImGuiDataType_Bool:
|
||||||
|
{
|
||||||
|
IM_ASSERT(field_desc.DataCount == 1);
|
||||||
|
ImGui::Checkbox("##Editor", (bool*)field_ptr);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ImGuiDataType_S32:
|
||||||
|
{
|
||||||
|
int v_min = INT_MIN, v_max = INT_MAX;
|
||||||
|
ImGui::SetNextItemWidth(-FLT_MIN);
|
||||||
|
ImGui::DragScalarN("##Editor", field_desc.DataType, field_ptr, field_desc.DataCount, 1.0f, &v_min, &v_max);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ImGuiDataType_Float:
|
||||||
|
{
|
||||||
|
float v_min = 0.0f, v_max = 1.0f;
|
||||||
|
ImGui::SetNextItemWidth(-FLT_MIN);
|
||||||
|
ImGui::SliderScalarN("##Editor", field_desc.DataType, field_ptr, field_desc.DataCount, &v_min, &v_max);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui::PopID();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (node_open)
|
||||||
|
ImGui::TreePop();
|
||||||
|
ImGui::PopID();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Demonstrate creating a simple property editor.
|
||||||
static void ShowExampleAppPropertyEditor(bool* p_open)
|
static void ShowExampleAppPropertyEditor(bool* p_open)
|
||||||
{
|
{
|
||||||
ImGui::SetNextWindowSize(ImVec2(430, 450), ImGuiCond_FirstUseEver);
|
ImGui::SetNextWindowSize(ImVec2(430, 450), ImGuiCond_FirstUseEver);
|
||||||
@ -7915,11 +7922,9 @@ static void ShowExampleAppPropertyEditor(bool* p_open)
|
|||||||
}
|
}
|
||||||
|
|
||||||
IMGUI_DEMO_MARKER("Examples/Property Editor");
|
IMGUI_DEMO_MARKER("Examples/Property Editor");
|
||||||
static ExampleTreeNode* tree_data = NULL;
|
static ExampleAppPropertyEditor property_editor;
|
||||||
if (tree_data == NULL)
|
static ExampleTreeNode* tree_data = ExampleTree_CreateDemoTree();
|
||||||
tree_data = ExampleTree_CreateDemoTree();
|
property_editor.Draw(tree_data);
|
||||||
|
|
||||||
PropertyEditor_ShowTree(tree_data);
|
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
@ -412,8 +412,8 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG
|
|||||||
SetNextWindowScroll(ImVec2(0.0f, 0.0f));
|
SetNextWindowScroll(ImVec2(0.0f, 0.0f));
|
||||||
|
|
||||||
// Create scrolling region (without border and zero window padding)
|
// Create scrolling region (without border and zero window padding)
|
||||||
ImGuiWindowFlags child_flags = (flags & ImGuiTableFlags_ScrollX) ? ImGuiWindowFlags_HorizontalScrollbar : ImGuiWindowFlags_None;
|
ImGuiWindowFlags child_window_flags = (flags & ImGuiTableFlags_ScrollX) ? ImGuiWindowFlags_HorizontalScrollbar : ImGuiWindowFlags_None;
|
||||||
BeginChildEx(name, instance_id, outer_rect.GetSize(), false, child_flags);
|
BeginChildEx(name, instance_id, outer_rect.GetSize(), ImGuiChildFlags_None, child_window_flags);
|
||||||
table->InnerWindow = g.CurrentWindow;
|
table->InnerWindow = g.CurrentWindow;
|
||||||
table->WorkRect = table->InnerWindow->WorkRect;
|
table->WorkRect = table->InnerWindow->WorkRect;
|
||||||
table->OuterRect = table->InnerWindow->Rect();
|
table->OuterRect = table->InnerWindow->Rect();
|
||||||
|
@ -4284,7 +4284,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|||||||
PushStyleVar(ImGuiStyleVar_ChildRounding, style.FrameRounding);
|
PushStyleVar(ImGuiStyleVar_ChildRounding, style.FrameRounding);
|
||||||
PushStyleVar(ImGuiStyleVar_ChildBorderSize, style.FrameBorderSize);
|
PushStyleVar(ImGuiStyleVar_ChildBorderSize, style.FrameBorderSize);
|
||||||
PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); // Ensure no clip rect so mouse hover can reach FramePadding edges
|
PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); // Ensure no clip rect so mouse hover can reach FramePadding edges
|
||||||
bool child_visible = BeginChildEx(label, id, frame_bb.GetSize(), true, ImGuiWindowFlags_NoMove);
|
bool child_visible = BeginChildEx(label, id, frame_bb.GetSize(), ImGuiChildFlags_Border, ImGuiWindowFlags_NoMove);
|
||||||
g.NavActivateId = backup_activate_id;
|
g.NavActivateId = backup_activate_id;
|
||||||
PopStyleVar(3);
|
PopStyleVar(3);
|
||||||
PopStyleColor();
|
PopStyleColor();
|
||||||
|
Loading…
Reference in New Issue
Block a user