| 700 | } |
| 701 | |
| 702 | static void implementation_test() { |
| 703 | ImGui::SeparatorText("Custom Implementation"); |
| 704 | ImGui::PushID("custom_implementation"); |
| 705 | ImGui::Indent(); |
| 706 | |
| 707 | |
| 708 | ImGui::Text("Custom vec3 type - default"); |
| 709 | HelpMarker("You can write a custom tag_invoke implementation for your types, ImReflect will find it at compile time."); |
| 710 | { |
| 711 | ImGui::PushID("vec3 default"); |
| 712 | const std::string code = R"(struct vec3 { |
| 713 | float x = 0, y = 0, z = 0; |
| 714 | }; |
| 715 | |
| 716 | // Type Settings |
| 717 | template<> |
| 718 | struct ImReflect::type_settings<vec3> : ImRequired<vec3> { |
| 719 | private: |
| 720 | bool _as_color = false; |
| 721 | public: |
| 722 | // If vec3 needs to be rendered as a color picker |
| 723 | type_settings<vec3>& as_color(const bool v = true) { _as_color = v; RETURN_THIS_T(vec3); } |
| 724 | bool is_color() { return _as_color; } |
| 725 | }; |
| 726 | |
| 727 | // Custom tag_invoke implementation |
| 728 | void tag_invoke(ImReflect::ImInput_t, const char* label, vec3& value, ImSettings& settings, ImResponse& response) { |
| 729 | // implementation... |
| 730 | } |
| 731 | )"; |
| 732 | static vec3 my_vec3; |
| 733 | IMGUI_SAMPLE_MULTI_CODE(code); |
| 734 | ImGui::Text("Output:"); |
| 735 | ImReflect::Input("my_vec3", my_vec3); |
| 736 | |
| 737 | ImGui::PopID(); |
| 738 | } |
| 739 | |
| 740 | ImGui::NewLine(); |
| 741 | |
| 742 | ImGui::Text("Custom vec3 type - as color"); |
| 743 | HelpMarker("You can use type settings in your custom implementation to modify behavior."); |
| 744 | { |
| 745 | ImGui::PushID("vec3 color"); |
| 746 | |
| 747 | const std::string code = R"(ImSettings config; |
| 748 | config.push<vec3>() |
| 749 | .as_color() |
| 750 | .pop(); |
| 751 | |
| 752 | ImReflect::Input("my_vec3", my_vec3, config);)"; |
| 753 | |
| 754 | ImSettings config; |
| 755 | config.push<vec3>() |
| 756 | .as_color() |
| 757 | .pop(); |
| 758 | |
| 759 | static vec3 my_vec3; |
no test coverage detected