| 469 | |
| 470 | |
| 471 | static void nested_reflection_test() { |
| 472 | ImGui::SeparatorText("Nested Struct / Class Reflection"); |
| 473 | ImGui::PushID("nested reflection"); |
| 474 | ImGui::Indent(); |
| 475 | |
| 476 | static Bar bar; |
| 477 | |
| 478 | ImGui::Text("Nested Structs"); |
| 479 | HelpMarker("You need to define the ``IMGUI_REFLECT`` macro for each struct, this determines what is reflected"); |
| 480 | { |
| 481 | const std::string code = R"(struct Foo { |
| 482 | int a; |
| 483 | float b; |
| 484 | bool c; |
| 485 | }; |
| 486 | IMGUI_REFLECT(Foo, a, b, c) |
| 487 | |
| 488 | struct Bar { |
| 489 | int x; |
| 490 | float y; |
| 491 | bool z; |
| 492 | Foo foo; |
| 493 | }; |
| 494 | IMGUI_REFLECT(Bar, x, y, z, foo)"; |
| 495 | |
| 496 | IMGUI_SAMPLE_MULTI_CODE(code); |
| 497 | |
| 498 | ImGui::Text("Output:"); |
| 499 | ImReflect::Input("foo", bar); |
| 500 | } |
| 501 | |
| 502 | ImGui::NewLine(); |
| 503 | |
| 504 | ImGui::Text("Nested Structs - pushing"); |
| 505 | HelpMarker("Push setting inside another struct."); |
| 506 | { |
| 507 | auto config = ImSettings(); |
| 508 | config.push<Foo>() |
| 509 | .push<int>() |
| 510 | .min(0) |
| 511 | .max(10) |
| 512 | .as_slider() |
| 513 | .pop() |
| 514 | .pop(); |
| 515 | |
| 516 | const std::string code = R"(auto config = ImSettings(); |
| 517 | config.push<Bar>() |
| 518 | .push<Foo>() |
| 519 | .push<int>() |
| 520 | .min(0) |
| 521 | .max(10) |
| 522 | .as_slider() |
| 523 | .pop() // int |
| 524 | .pop() // Foo |
| 525 | .pop(); // Bar)"; |
| 526 | IMGUI_SAMPLE_MULTI_CODE(code); |
| 527 | |
| 528 | ImGui::Text("Output:"); |
no test coverage detected