demo_nanovg_launcher.cpp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Part of ImGui Bundle - MIT License - Copyright (c) 2022-2026 Pascal Thomet - https://github.com/pthom/imgui_bundle
  2. #include "imgui.h"
  3. #include "imgui_md_wrapper/imgui_md_wrapper.h"
  4. #include "hello_imgui/hello_imgui.h"
  5. #include "demo_utils/api_demos.h"
  6. void demo_nanovg_launcher()
  7. {
  8. static bool isFullDemoOpened = false, isSimpleDemoOpened = false;
  9. ImGuiMd::RenderUnindented(R"(
  10. [NanoVG](https://github.com/memononen/nanovg) provides antialiased 2D vector drawing library on top of OpenGL for UI and visualizations.
  11. )");
  12. if (!isFullDemoOpened && !isSimpleDemoOpened)
  13. {
  14. ImGui::SameLine(ImGui::GetWindowWidth() - HelloImGui::EmSize(14.0f));
  15. if (HelloImGui::ImageButtonFromAsset("images/nanovg_full_demo.jpg", ImVec2(HelloImGui::EmSize(11.0f), 0.f)))
  16. SpawnDemo("demo_nanovg_full");
  17. }
  18. int nbCodeLines = 35;
  19. if (ImGui::CollapsingHeader("Full Demo"))
  20. {
  21. isFullDemoOpened = true;
  22. ImGui::BeginGroup();
  23. ImGui::Text(
  24. "This is the original NanoVG demo, integrated to ImGui Bundle (and also ported to python).\n"
  25. "Click the button below to launch the demo"
  26. );
  27. ImGui::NewLine();
  28. if (ImGui::Button("Run full demo"))
  29. SpawnDemo("demo_nanovg_full");
  30. ImGui::EndGroup();
  31. ImGui::SameLine(ImGui::GetWindowWidth() - HelloImGui::EmSize(14.0f));
  32. if (HelloImGui::ImageButtonFromAsset("images/nanovg_full_demo.jpg", ImVec2(HelloImGui::EmSize(11.0f), 0.f)))
  33. SpawnDemo("demo_nanovg_full");
  34. ImGui::BeginTabBar("##tabs_nano_vg_code");
  35. if (ImGui::BeginTabItem("Launcher Code"))
  36. {
  37. ShowPythonVsCppFile("demos_nanovg/demo_nanovg_full", nbCodeLines);
  38. ImGui::EndTabItem();
  39. }
  40. if (ImGui::BeginTabItem("Rendering Code"))
  41. {
  42. ShowPythonVsCppFile("demos_nanovg/demo_nanovg_full/demo_nanovg_full_impl", nbCodeLines);
  43. ImGui::EndTabItem();
  44. }
  45. ImGui::EndTabBar();
  46. }
  47. else
  48. isFullDemoOpened = false;
  49. if (ImGui::CollapsingHeader("Simple Demo"))
  50. {
  51. isSimpleDemoOpened = true;
  52. ImGui::BeginGroup();
  53. ImGui::Text(
  54. "This is a simpler demo, that shows how to display NanoVG as the background, or as a texture.\n"
  55. "(via a framebuffer object)\n"
  56. "Click the button below to launch the demo"
  57. );
  58. ImGui::NewLine();
  59. if (ImGui::Button("Run simple demo"))
  60. SpawnDemo("demo_nanovg_heart");
  61. ImGui::EndGroup();
  62. ImGui::SameLine(ImGui::GetWindowWidth() - HelloImGui::EmSize(14.0f));
  63. if (HelloImGui::ImageButtonFromAsset("images/nanovg_demo_heart.jpg", ImVec2(HelloImGui::EmSize(11.0f), 0.f)))
  64. SpawnDemo("demo_nanovg_heart");
  65. ShowPythonVsCppFile("demos_nanovg/demo_nanovg_heart", nbCodeLines);
  66. }
  67. else
  68. isSimpleDemoOpened = false;
  69. }