Skip to content

Commit

Permalink
[Doc] imgui_demo.cpp: Add DEMO_MARKERS and DemoCodeWindow
Browse files Browse the repository at this point in the history
This commit provides the ability to pinpoint the exact location of
the code of all the demos in imgui_demo.cpp: when the "Code Lookup"
checkbox is ticked, the code location (file and line number)
of any demo currently hovered by the mouse will be shown in a tooltip.

Furthermore a basic code viewer is provided (which reads the code from
the imgui_demo.cpp file); as well as a "View on github" button.

Implementation notes:
- This feature is provided by the "DEMO_MARKER" macro.
  See example usage below
- Most of the code for this feature is grouped inside
  the namespace `DemoMarkerTools`.

Origin:
These modifications are the basis for a more complete interactive
imgui manual (https://pthom.github.io/imgui_manual_online/manual/imgui_manual.html).

This manual was first presented in the "Gallery/screenshots (part 11)"
discussion (ocornut#3075)

// Example usage of the DEMO_MARKER macro (with hierarchical demos):

     DEMO_MARKER("Widgets");                      // For clarity, calls to the DEMO_MARKER macro
     DEMO_MARKER("Widgets/Basic");                // should try to be hierarchical (via the use of "/" separators)
     ...

     DEMO_MARKER("Widgets/Basic/Checkbox");       // Here the call to DEMO_MARKER will start a new rectangular bounding
     static bool check = true;                    // around the next widget(s). Whenever the user clicks the "Help/Code Lookup"
     ImGui::Checkbox("checkbox", &check);         // button and then click this bounding, he will be shown the source code location,
                                                  // of this DEMO_MARKER call.

     DEMO_MARKER("Widgets/Basic/RadioButton");    // End of the previous bounding, start of a new one
     static int e = 0;
     ImGui::RadioButton("radio a", &e, 0); ImGui::SameLine();

----
  • Loading branch information
pthom committed Oct 19, 2021
1 parent bac748f commit 138fa8c
Showing 1 changed file with 797 additions and 7 deletions.
Loading

0 comments on commit 138fa8c

Please sign in to comment.