Skip to content

Commit

Permalink
nanovg: add demos to full demo
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Jan 13, 2024
1 parent 476ce9f commit a0bdfde
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 4 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion bindings/imgui_bundle/demos_cpp/demo_imgui_bundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <functional>

void demo_immapp_launcher();
void demo_nanovg_launcher();
void demo_text_edit();
void demo_imgui_bundle_intro();
void demo_imgui_show_demo_window();
Expand Down Expand Up @@ -99,10 +100,11 @@ int main(int, char **)
DEMO_DETAILS("Text Editor", demo_text_edit),
DEMO_DETAILS("Widgets", demo_widgets),
DEMO_DETAILS("ImmVision", demo_immvision_launcher),
DEMO_DETAILS("imgui_tex_inspect", demo_tex_inspect_launcher),
DEMO_DETAILS("NanoVG", demo_nanovg_launcher),
DEMO_DETAILS("ImGuizmo", demo_imguizmo_launcher),
DEMO_DETAILS("Themes", demo_themes),
DEMO_DETAILS("Logger", demo_logger),
DEMO_DETAILS("tex_inspect", demo_tex_inspect_launcher),
};

for (const auto& demo: demos)
Expand Down
77 changes: 77 additions & 0 deletions bindings/imgui_bundle/demos_cpp/demo_nanovg_launcher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Part of ImGui Bundle - MIT License - Copyright (c) 2022-2024 Pascal Thomet - https://github.com/pthom/imgui_bundle
#include "imgui.h"
#include "imgui_md_wrapper/imgui_md_wrapper.h"
#include "hello_imgui/hello_imgui.h"
#include "demo_utils/api_demos.h"


void demo_nanovg_launcher()
{
static bool isFullDemoOpened = false, isSimpleDemoOpened = false;
ImGuiMd::RenderUnindented(R"(
# NanoVG
[NanoVG](https://github.com/memononen/nanovg) Antialiased 2D vector drawing library on top of OpenGL for UI and visualizations.
)");

if (!isFullDemoOpened && !isSimpleDemoOpened)
{
ImGui::SameLine(ImGui::GetWindowWidth() - HelloImGui::EmSize(14.0f));
if (HelloImGui::ImageButtonFromAsset("images/nanovg_full_demo.jpg", ImVec2(HelloImGui::EmSize(11.0f), 0.f)))
SpawnDemo("demo_nanovg_full");
}

int nbCodeLines = 35;
if (ImGui::CollapsingHeader("Full Demo"))
{
isFullDemoOpened = true;
ImGui::BeginGroup();
ImGui::Text(
"This is the original NanoVG demo, integrated to ImGui Bundle (and also ported to python).\n"
"Click the button below to launch the demo"
);
ImGui::NewLine();
if (ImGui::Button("Run full demo"))
SpawnDemo("demo_nanovg_full");
ImGui::EndGroup();

ImGui::SameLine(ImGui::GetWindowWidth() - HelloImGui::EmSize(14.0f));
if (HelloImGui::ImageButtonFromAsset("images/nanovg_full_demo.jpg", ImVec2(HelloImGui::EmSize(11.0f), 0.f)))
SpawnDemo("demo_nanovg_full");

ImGui::BeginTabBar("##tabs_nano_vg_code");
if (ImGui::BeginTabItem("Launcher Code"))
{
ShowPythonVsCppFile("demos_nanovg/demo_nanovg_full", nbCodeLines);
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Rendering Code"))
{
ShowPythonVsCppFile("demos_nanovg/demo_nanovg_full/demo_nanovg_full_impl", nbCodeLines);
ImGui::EndTabItem();
}
ImGui::EndTabBar();
}
else
isFullDemoOpened = false;

if (ImGui::CollapsingHeader("Simple Demo"))
{
isSimpleDemoOpened = true;
ImGui::BeginGroup();
ImGui::Text(
"This is a simpler demo, that shows how to display NanoVG as the background, or as a texture.\n"
"(via a framebuffer object)\n"
"Click the button below to launch the demo"
);
ImGui::NewLine();
if (ImGui::Button("Run simple demo"))
SpawnDemo("demo_nanovg_heart");
ImGui::EndGroup();
ImGui::SameLine(ImGui::GetWindowWidth() - HelloImGui::EmSize(14.0f));
if (HelloImGui::ImageButtonFromAsset("images/nanovg_demo_heart.jpg", ImVec2(HelloImGui::EmSize(11.0f), 0.f)))
SpawnDemo("demo_nanovg_heart");
ShowPythonVsCppFile("demos_nanovg/demo_nanovg_heart", nbCodeLines);
}
else
isSimpleDemoOpened = false;
}
2 changes: 2 additions & 0 deletions bindings/imgui_bundle/demos_cpp/demo_utils/api_demos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,13 @@ void ShowPythonVsCppCode(const std::string& pythonCode, const std::string& cppCo
snippetCpp.DisplayedFilename = "C++ code";
snippetCpp.Language = Snippets::SnippetLanguage::Cpp;
snippetCpp.HeightInLines = nbLines;
snippetCpp.MaxHeightInLines = nbLines;

snippetPython.Code = pythonCode;
snippetPython.DisplayedFilename = "Python code";
snippetPython.Language = Snippets::SnippetLanguage::Python;
snippetPython.HeightInLines = nbLines;
snippetPython.MaxHeightInLines = nbLines;

Snippets::ShowSideBySideSnippets(snippetCpp, snippetPython);
ImGui::PopID();
Expand Down
4 changes: 3 additions & 1 deletion bindings/imgui_bundle/demos_python/demo_imgui_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from imgui_bundle.demos_python import demo_tex_inspect_launcher
from imgui_bundle.demos_python import demo_node_editor_launcher
from imgui_bundle.demos_python import demo_immapp_launcher
from imgui_bundle.demos_python import demo_nanovg_launcher
from imgui_bundle.demos_python import demo_themes
from imgui_bundle.demos_python import demo_logger
from imgui_bundle.demos_python import demo_utils # this will set the assets folder
Expand Down Expand Up @@ -94,10 +95,11 @@ class DemoDetails:
DemoDetails("Text Editor", demo_text_edit),
DemoDetails("Widgets", demo_widgets),
DemoDetails("ImmVision", demo_immvision_launcher),
DemoDetails("imgui_tex_inspect", demo_tex_inspect_launcher),
DemoDetails("NanoVG", demo_nanovg_launcher),
DemoDetails("ImGuizmo", demo_imguizmo_launcher),
DemoDetails("Themes", demo_themes),
DemoDetails("Logger", demo_logger),
DemoDetails("tex_inspect", demo_tex_inspect_launcher),
]

for demo in demos:
Expand Down
87 changes: 87 additions & 0 deletions bindings/imgui_bundle/demos_python/demo_nanovg_launcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Part of ImGui Bundle - MIT License - Copyright (c) 2022-2024 Pascal Thomet - https://github.com/pthom/imgui_bundle

from imgui_bundle import imgui, hello_imgui, imgui_md, immapp, ImVec2
from imgui_bundle.demos_python import demo_utils # this will set the assets folder


def _do_spawn_demo(demo_name: str):
import os.path
import subprocess
import sys
this_dir = os.path.dirname(__file__)
demo_file = this_dir + "/demos_nanovg/" + demo_name + ".py"
subprocess.Popen([sys.executable, demo_file])


def demo_gui():
static = demo_gui
if not hasattr(static, "is_full_demo_opened"):
static.is_full_demo_opened = False
if not hasattr(static, "is_simple_demo_opened"):
static.is_simple_demo_opened = False
if not hasattr(static, "show_full_demo_rendering_code"):
static.show_full_demo_rendering_code = False

imgui_md.render_unindented("""
# NanoVG
[NanoVG](https://github.com/memononen/nanovg) Antialiased 2D vector drawing library on top of OpenGL for UI and visualizations.
""")

if not static.is_full_demo_opened and not static.is_simple_demo_opened:
imgui.same_line(imgui.get_window_width() - hello_imgui.em_size(14.0))
if hello_imgui.image_button_from_asset("images/nanovg_full_demo.jpg", ImVec2(hello_imgui.em_size(11.0), 0.0)):
_do_spawn_demo("demo_nanovg_full")

nb_code_lines = 35

if imgui.collapsing_header("Full Demo"):
static.is_full_demo_opened = True
imgui.begin_group()
imgui.text(
"This is the original NanoVG demo, integrated to ImGui Bundle (and also ported to python).\n"
"Click the button below to launch the demo"
)
imgui.new_line()
if imgui.button("Run full demo"):
_do_spawn_demo("demo_nanovg_full")
imgui.end_group()

imgui.same_line(imgui.get_window_width() - hello_imgui.em_size(14.0))
if hello_imgui.image_button_from_asset("images/nanovg_full_demo.jpg", ImVec2(hello_imgui.em_size(11.0), 0.0)):
_do_spawn_demo("demo_nanovg_full")

if imgui.radio_button("Show launcher code", not static.show_full_demo_rendering_code):
static.show_full_demo_rendering_code = False
imgui.same_line()
if imgui.radio_button("Show rendering code", static.show_full_demo_rendering_code):
static.show_full_demo_rendering_code = True

if not static.show_full_demo_rendering_code:
demo_utils.show_python_vs_cpp_file("demos_nanovg/demo_nanovg_full", nb_code_lines)
else:
demo_utils.show_python_vs_cpp_file("demos_nanovg/demo_nanovg_full/demo_nanovg_full_impl", nb_code_lines)
else:
static.is_full_demo_opened = False

if imgui.collapsing_header("Simple Demo"):
static.is_simple_demo_opened = True
imgui.begin_group()
imgui.text(
"This is a simpler demo, that shows how to display NanoVG as the background, or as a texture.\n"
"(via a framebuffer object)\n"
"Click the button below to launch the demo"
)
imgui.new_line()
if imgui.button("Run simple demo"):
_do_spawn_demo("demo_nanovg_heart")
imgui.end_group()
imgui.same_line(imgui.get_window_width() - hello_imgui.em_size(14.0))
if hello_imgui.image_button_from_asset("images/nanovg_demo_heart.jpg", ImVec2(hello_imgui.em_size(11.0), 0.0)):
_do_spawn_demo("demo_nanovg_heart")
demo_utils.show_python_vs_cpp_file("demos_nanovg/demo_nanovg_heart", nb_code_lines)
else:
static.is_simple_demo_opened = False


if __name__ == "__main__":
immapp.run(demo_gui, window_size=(1000, 800), with_markdown=True, with_node_editor=True)
2 changes: 2 additions & 0 deletions bindings/imgui_bundle/demos_python/demo_utils/api_demos.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ def show_python_vs_cpp_code(python_code: str, cpp_code: str, nb_lines: int = 0):
snippet_cpp.code = cpp_code
snippet_cpp.displayed_filename = "C++ code"
snippet_cpp.height_in_lines = nb_lines
snippet_cpp.max_height_in_lines = nb_lines

snippet_python: immapp.snippets.SnippetData = immapp.snippets.SnippetData() # type: ignore
snippet_python.code = python_code
snippet_python.displayed_filename = "Python code"
snippet_python.height_in_lines = nb_lines
snippet_python.max_height_in_lines = nb_lines

immapp.snippets.show_side_by_side_snippets(snippet_python, snippet_cpp)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# port of bindings/imgui_bundle/demos_cpp/demos_nanovg/demo_nanovg_full.cpp
from imgui_bundle import imgui, nanovg as nvg, hello_imgui, ImVec2, ImVec4
from imgui_bundle.demos_python import demo_utils
import demo_nanovg_full_impl
from imgui_bundle.demos_python.demos_nanovg.demo_nanovg_full import demo_nanovg_full_impl
from typing import List


Expand Down
Empty file.
2 changes: 1 addition & 1 deletion external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ add_simple_external_library_with_sources(imguizmo ImGuizmo)
add_additional_sources_to_external_library(imguizmo ImGuizmo ImGuizmoPure)
# Build imgui_tex_inspect
if(HELLOIMGUI_HAS_OPENGL)
add_compile_definitions(IMGUI_BUNDLE_WITH_TEXT_INSPECT)
set(IMGUI_BUNDLE_WITH_TEXT_INSPECT ON CACHE INTERNAL "" FORCE)
add_simple_external_library_with_sources(imgui_tex_inspect imgui_tex_inspect)
target_sources(imgui_tex_inspect PRIVATE
Expand All @@ -96,6 +95,7 @@ if(HELLOIMGUI_HAS_OPENGL)
target_include_directories(imgui_tex_inspect PRIVATE imgui_tex_inspect/imgui_tex_inspect)
target_include_directories(imgui_tex_inspect PRIVATE imgui/imgui/backends)
target_compile_definitions(imgui_tex_inspect PRIVATE IMGUI_IMPL_OPENGL_LOADER_GLAD)
target_compile_definitions(imgui_tex_inspect PUBLIC IMGUI_BUNDLE_WITH_TEXT_INSPECT)
target_include_directories(imgui_tex_inspect PRIVATE hello_imgui/hello_imgui/external/OpenGL_Loaders/glad/include)
target_link_libraries(imgui_tex_inspect PUBLIC hello_imgui)
endif()
Expand Down

0 comments on commit a0bdfde

Please sign in to comment.