MCPcopy Create free account
hub / github.com/danoon2/Boxedwine / ShowExampleAppPropertyEditor

Function ShowExampleAppPropertyEditor

lib/imgui/imgui_demo.cpp:4169–4234  ·  view source on GitHub ↗

Demonstrate create a simple property editor.

Source from the content-addressed store, hash-verified

4167
4168// Demonstrate create a simple property editor.
4169static void ShowExampleAppPropertyEditor(bool* p_open)
4170{
4171 ImGui::SetNextWindowSize(ImVec2(430,450), ImGuiCond_FirstUseEver);
4172 if (!ImGui::Begin("Example: Property editor", p_open))
4173 {
4174 ImGui::End();
4175 return;
4176 }
4177
4178 HelpMarker("This example shows how you may implement a property editor using two columns.\nAll objects/fields data are dummies here.\nRemember that in many simple cases, you can use ImGui::SameLine(xxx) to position\nyour cursor horizontally instead of using the Columns() API.");
4179
4180 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2,2));
4181 ImGui::Columns(2);
4182 ImGui::Separator();
4183
4184 struct funcs
4185 {
4186 static void ShowDummyObject(const char* prefix, int uid)
4187 {
4188 ImGui::PushID(uid); // Use object uid as identifier. Most commonly you could also use the object pointer as a base ID.
4189 ImGui::AlignTextToFramePadding(); // Text and Tree nodes are less high than regular widgets, here we add vertical spacing to make the tree lines equal high.
4190 bool node_open = ImGui::TreeNode("Object", "%s_%u", prefix, uid);
4191 ImGui::NextColumn();
4192 ImGui::AlignTextToFramePadding();
4193 ImGui::Text("my sailor is rich");
4194 ImGui::NextColumn();
4195 if (node_open)
4196 {
4197 static float dummy_members[8] = { 0.0f,0.0f,1.0f,3.1416f,100.0f,999.0f };
4198 for (int i = 0; i < 8; i++)
4199 {
4200 ImGui::PushID(i); // Use field index as identifier.
4201 if (i < 2)
4202 {
4203 ShowDummyObject("Child", 424242);
4204 }
4205 else
4206 {
4207 // Here we use a TreeNode to highlight on hover (we could use e.g. Selectable as well)
4208 ImGui::AlignTextToFramePadding();
4209 ImGui::TreeNodeEx("Field", ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_Bullet, "Field_%d", i);
4210 ImGui::NextColumn();
4211 ImGui::SetNextItemWidth(-1);
4212 if (i >= 5)
4213 ImGui::InputFloat("##value", &dummy_members[i], 1.0f);
4214 else
4215 ImGui::DragFloat("##value", &dummy_members[i], 0.01f);
4216 ImGui::NextColumn();
4217 }
4218 ImGui::PopID();
4219 }
4220 ImGui::TreePop();
4221 }
4222 ImGui::PopID();
4223 }
4224 };
4225
4226 // Iterate dummy objects with dummy members (all the same data)

Callers 1

ShowDemoWindowMethod · 0.85

Calls 2

ImVec2Class · 0.85
HelpMarkerFunction · 0.85

Tested by

no test coverage detected