Demonstrate create a simple property editor.
| 2932 | |
| 2933 | // Demonstrate create a simple property editor. |
| 2934 | static void ShowExampleAppPropertyEditor(bool* p_open) |
| 2935 | { |
| 2936 | ImGui::SetNextWindowSize(ImVec2(430,450), ImGuiCond_FirstUseEver); |
| 2937 | if (!ImGui::Begin("Example: Property editor", p_open)) |
| 2938 | { |
| 2939 | ImGui::End(); |
| 2940 | return; |
| 2941 | } |
| 2942 | |
| 2943 | ShowHelpMarker("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."); |
| 2944 | |
| 2945 | ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2,2)); |
| 2946 | ImGui::Columns(2); |
| 2947 | ImGui::Separator(); |
| 2948 | |
| 2949 | struct funcs |
| 2950 | { |
| 2951 | static void ShowDummyObject(const char* prefix, int uid) |
| 2952 | { |
| 2953 | ImGui::PushID(uid); // Use object uid as identifier. Most commonly you could also use the object pointer as a base ID. |
| 2954 | ImGui::AlignTextToFramePadding(); // Text and Tree nodes are less high than regular widgets, here we add vertical spacing to make the tree lines equal high. |
| 2955 | bool node_open = ImGui::TreeNode("Object", "%s_%u", prefix, uid); |
| 2956 | ImGui::NextColumn(); |
| 2957 | ImGui::AlignTextToFramePadding(); |
| 2958 | ImGui::Text("my sailor is rich"); |
| 2959 | ImGui::NextColumn(); |
| 2960 | if (node_open) |
| 2961 | { |
| 2962 | static float dummy_members[8] = { 0.0f,0.0f,1.0f,3.1416f,100.0f,999.0f }; |
| 2963 | for (int i = 0; i < 8; i++) |
| 2964 | { |
| 2965 | ImGui::PushID(i); // Use field index as identifier. |
| 2966 | if (i < 2) |
| 2967 | { |
| 2968 | ShowDummyObject("Child", 424242); |
| 2969 | } |
| 2970 | else |
| 2971 | { |
| 2972 | ImGui::AlignTextToFramePadding(); |
| 2973 | // Here we use a Selectable (instead of Text) to highlight on hover |
| 2974 | //ImGui::Text("Field_%d", i); |
| 2975 | char label[32]; |
| 2976 | sprintf(label, "Field_%d", i); |
| 2977 | ImGui::Bullet(); |
| 2978 | ImGui::Selectable(label); |
| 2979 | ImGui::NextColumn(); |
| 2980 | ImGui::PushItemWidth(-1); |
| 2981 | if (i >= 5) |
| 2982 | ImGui::InputFloat("##value", &dummy_members[i], 1.0f); |
| 2983 | else |
| 2984 | ImGui::DragFloat("##value", &dummy_members[i], 0.01f); |
| 2985 | ImGui::PopItemWidth(); |
| 2986 | ImGui::NextColumn(); |
| 2987 | } |
| 2988 | ImGui::PopID(); |
| 2989 | } |
| 2990 | ImGui::TreePop(); |
| 2991 | } |
no test coverage detected