Demo: Moved property editor demo to its own mini example applet (#414)

This commit is contained in:
ocornut 2015-11-28 17:16:59 +00:00
parent d3df39fed1
commit 32d2768734

View File

@ -47,6 +47,7 @@
static void ShowExampleAppConsole(bool* opened); static void ShowExampleAppConsole(bool* opened);
static void ShowExampleAppLog(bool* opened); static void ShowExampleAppLog(bool* opened);
static void ShowExampleAppLayout(bool* opened); static void ShowExampleAppLayout(bool* opened);
static void ShowExampleAppPropertyEditor(bool* opened);
static void ShowExampleAppLongText(bool* opened); static void ShowExampleAppLongText(bool* opened);
static void ShowExampleAppAutoResize(bool* opened); static void ShowExampleAppAutoResize(bool* opened);
static void ShowExampleAppFixedOverlay(bool* opened); static void ShowExampleAppFixedOverlay(bool* opened);
@ -93,6 +94,7 @@ void ImGui::ShowTestWindow(bool* opened)
static bool show_app_console = false; static bool show_app_console = false;
static bool show_app_log = false; static bool show_app_log = false;
static bool show_app_layout = false; static bool show_app_layout = false;
static bool show_app_property_editor = false;
static bool show_app_long_text = false; static bool show_app_long_text = false;
static bool show_app_auto_resize = false; static bool show_app_auto_resize = false;
static bool show_app_fixed_overlay = false; static bool show_app_fixed_overlay = false;
@ -104,6 +106,7 @@ void ImGui::ShowTestWindow(bool* opened)
if (show_app_console) ShowExampleAppConsole(&show_app_console); if (show_app_console) ShowExampleAppConsole(&show_app_console);
if (show_app_log) ShowExampleAppLog(&show_app_log); if (show_app_log) ShowExampleAppLog(&show_app_log);
if (show_app_layout) ShowExampleAppLayout(&show_app_layout); if (show_app_layout) ShowExampleAppLayout(&show_app_layout);
if (show_app_property_editor) ShowExampleAppPropertyEditor(&show_app_property_editor);
if (show_app_long_text) ShowExampleAppLongText(&show_app_long_text); if (show_app_long_text) ShowExampleAppLongText(&show_app_long_text);
if (show_app_auto_resize) ShowExampleAppAutoResize(&show_app_auto_resize); if (show_app_auto_resize) ShowExampleAppAutoResize(&show_app_auto_resize);
if (show_app_fixed_overlay) ShowExampleAppFixedOverlay(&show_app_fixed_overlay); if (show_app_fixed_overlay) ShowExampleAppFixedOverlay(&show_app_fixed_overlay);
@ -163,6 +166,7 @@ void ImGui::ShowTestWindow(bool* opened)
ImGui::MenuItem("Console", NULL, &show_app_console); ImGui::MenuItem("Console", NULL, &show_app_console);
ImGui::MenuItem("Log", NULL, &show_app_log); ImGui::MenuItem("Log", NULL, &show_app_log);
ImGui::MenuItem("Simple layout", NULL, &show_app_layout); ImGui::MenuItem("Simple layout", NULL, &show_app_layout);
ImGui::MenuItem("Property editor", NULL, &show_app_property_editor);
ImGui::MenuItem("Long text display", NULL, &show_app_long_text); ImGui::MenuItem("Long text display", NULL, &show_app_long_text);
ImGui::MenuItem("Auto-resizing window", NULL, &show_app_auto_resize); ImGui::MenuItem("Auto-resizing window", NULL, &show_app_auto_resize);
ImGui::MenuItem("Simple overlay", NULL, &show_app_fixed_overlay); ImGui::MenuItem("Simple overlay", NULL, &show_app_fixed_overlay);
@ -1319,56 +1323,6 @@ void ImGui::ShowTestWindow(bool* opened)
ImGui::TreePop(); ImGui::TreePop();
} }
if (ImGui::TreeNode("Property tree"))
{
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2,2));
ImGui::Columns(2);
ImGui::Separator();
ImGui::Text("Item1"); ImGui::NextColumn();
ImGui::Text("value1"); ImGui::NextColumn();
// Iterate dummy objects with dummy members (all the same data)
static float members[6] = { 0.0f,1.0f,3.1416f,100.0f,999.0f };
for (int obj_i = 0; obj_i < 3; obj_i++)
{
ImGui::PushID(obj_i);
bool opened = ImGui::TreeNode("Object", "Object%d", obj_i);
ImGui::NextColumn();
ImGui::Text("my tailor is rich");
ImGui::NextColumn();
if (opened)
{
for (int i = 0; i < 6; i++)
{
ImGui::PushID(i);
ImGui::AlignFirstTextHeightToWidgets();
// Here we use a Selectable (instead of Text) to highlight on hover
//ImGui::Text("Field%d", i);
char label[32];
sprintf(label, "Field%d", i);
ImGui::Selectable(label);
ImGui::NextColumn();
ImGui::PushItemWidth(-1);
if (i >= 3)
ImGui::InputFloat("##value", &members[i], 1.0f);
else
ImGui::DragFloat("##value", &members[i], 0.01f);
ImGui::PopItemWidth();
ImGui::NextColumn();
ImGui::PopID();
}
ImGui::TreePop();
}
ImGui::PopID();
}
ImGui::Columns(1);
ImGui::Separator();
ImGui::PopStyleVar();
ImGui::TreePop();
}
bool opened = ImGui::TreeNode("Tree within single cell"); bool opened = ImGui::TreeNode("Tree within single cell");
ImGui::SameLine(); ShowHelpMarker("NB: Tree node must be poped before ending the cell.\nThere's no storage of state per-cell."); ImGui::SameLine(); ShowHelpMarker("NB: Tree node must be poped before ending the cell.\nThere's no storage of state per-cell.");
if (opened) if (opened)
@ -2217,6 +2171,76 @@ static void ShowExampleAppLayout(bool* opened)
ImGui::End(); ImGui::End();
} }
static void ShowExampleAppPropertyEditor(bool* opened)
{
ImGui::SetNextWindowSize(ImVec2(430,450), ImGuiSetCond_FirstUseEver);
if (!ImGui::Begin("Example: Property editor", opened))
{
ImGui::End();
return;
}
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2,2));
ImGui::Columns(2);
ImGui::Separator();
ImGui::Text("Item1"); ImGui::NextColumn();
ImGui::Text("value1"); ImGui::NextColumn();
struct funcs
{
static void ShowDummyObject(const char* prefix, ImU32 uid)
{
ImGui::PushID(uid); // Use object uid as identifier. Most commonly you could also use the object pointer as a base ID.
bool opened = ImGui::TreeNode("Object", "%s_%u", prefix, uid);
ImGui::NextColumn();
ImGui::Text("my sailor is rich");
ImGui::NextColumn();
if (opened)
{
static float dummy_members[8] = { 0.0f,0.0f,1.0f,3.1416f,100.0f,999.0f };
for (int i = 0; i < 8; i++)
{
ImGui::PushID(i); // Use field index as identifier.
if (i < 2)
{
ShowDummyObject("Child", ImGui::GetID("foo"));
}
else
{
ImGui::AlignFirstTextHeightToWidgets();
// Here we use a Selectable (instead of Text) to highlight on hover
//ImGui::Text("Field_%d", i);
char label[32];
sprintf(label, "Field_%d", i);
ImGui::Selectable(label);
ImGui::NextColumn();
ImGui::PushItemWidth(-1);
if (i >= 5)
ImGui::InputFloat("##value", &dummy_members[i], 1.0f);
else
ImGui::DragFloat("##value", &dummy_members[i], 0.01f);
ImGui::PopItemWidth();
ImGui::NextColumn();
}
ImGui::PopID();
}
ImGui::TreePop();
}
ImGui::PopID();
}
};
// Iterate dummy objects with dummy members (all the same data)
for (int obj_i = 0; obj_i < 3; obj_i++)
funcs::ShowDummyObject("Object", obj_i);
ImGui::Columns(1);
ImGui::Separator();
ImGui::PopStyleVar();
ImGui::End();
}
static void ShowExampleAppLongText(bool* opened) static void ShowExampleAppLongText(bool* opened)
{ {
ImGui::SetNextWindowSize(ImVec2(520,600), ImGuiSetCond_FirstUseEver); ImGui::SetNextWindowSize(ImVec2(520,600), ImGuiSetCond_FirstUseEver);