Skip to content

Commit

Permalink
GDExt example: add imgui_markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
pkdawson committed Jul 13, 2024
1 parent 2e98523 commit 5a92096
Show file tree
Hide file tree
Showing 13 changed files with 326 additions and 1 deletion.
11 changes: 11 additions & 0 deletions doc/examples/GDExt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ FetchContent_Declare(
)
FetchContent_MakeAvailable(implot)

FetchContent_Declare(
imgui_markdown
GIT_REPOSITORY https://github.com/enkisoftware/imgui_markdown
GIT_TAG main
)
FetchContent_MakeAvailable(imgui_markdown)

add_library(gdexample SHARED)
target_compile_features(gdexample PRIVATE cxx_std_20)
target_compile_definitions(gdexample PUBLIC
Expand All @@ -45,10 +52,13 @@ target_sources(gdexample PRIVATE
${FETCHCONTENT_BASE_DIR}/implot-src/implot_demo.cpp
${FETCHCONTENT_BASE_DIR}/implot-src/implot_items.cpp
${FETCHCONTENT_BASE_DIR}/implot-src/implot.h
${FETCHCONTENT_BASE_DIR}/imgui_markdown-src/imgui_markdown.h
src/example.cpp
src/example.h
src/register_types.cpp
src/register_types.h
src/gdmarkdown.cpp
src/gdmarkdown.h
)

target_link_libraries(gdexample PUBLIC godot-cpp)
Expand All @@ -58,6 +68,7 @@ target_include_directories(gdexample PRIVATE
${IMGUI_GODOT_INCLUDE}
${FETCHCONTENT_BASE_DIR}/imgui-src
${FETCHCONTENT_BASE_DIR}/implot-src
${FETCHCONTENT_BASE_DIR}/imgui_markdown-src
)

set_property(TARGET gdexample
Expand Down
10 changes: 9 additions & 1 deletion doc/examples/GDExt/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ if not os.path.exists("imgui"):
if not os.path.exists("implot"):
subprocess.call("git clone https://github.com/epezent/implot", shell=True)

if not os.path.exists("imgui_markdown"):
subprocess.call(
"git clone https://github.com/enkisoftware/imgui_markdown", shell=True
)

env = SConscript("godot-cpp/SConstruct")
env = env.Clone()

Expand All @@ -31,7 +36,10 @@ env.Append(CPPPATH=["imgui", IMGUI_GODOT_INCLUDE])

# ImPlot
sources += Glob(f"implot/*.cpp")
env.Append(CPPPATH=["implot", IMGUI_GODOT_INCLUDE])
env.Append(CPPPATH=["implot"])

# imgui_markdown
env.Append(CPPPATH=["imgui_markdown"])

if env["platform"] == "macos":
library = env.SharedLibrary(
Expand Down
Binary file added doc/examples/GDExt/project/Hack-Bold.ttf
Binary file not shown.
33 changes: 33 additions & 0 deletions doc/examples/GDExt/project/Hack-Bold.ttf.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[remap]

importer="font_data_dynamic"
type="FontFile"
uid="uid://geey1pyskdev"
path="res://.godot/imported/Hack-Bold.ttf-691cdc24fdde9142fc0f47c007a581d0.fontdata"

[deps]

source_file="res://Hack-Bold.ttf"
dest_files=["res://.godot/imported/Hack-Bold.ttf-691cdc24fdde9142fc0f47c007a581d0.fontdata"]

[params]

Rendering=null
antialiasing=1
generate_mipmaps=false
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
allow_system_fallback=true
force_autohinter=false
hinting=1
subpixel_positioning=1
oversampling=0.0
Fallbacks=null
fallbacks=[]
Compress=null
compress=true
preload=[]
language_support={}
script_support={}
opentype_features={}
Binary file added doc/examples/GDExt/project/Hack-Italic.ttf
Binary file not shown.
33 changes: 33 additions & 0 deletions doc/examples/GDExt/project/Hack-Italic.ttf.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[remap]

importer="font_data_dynamic"
type="FontFile"
uid="uid://ccn210ltcrs6i"
path="res://.godot/imported/Hack-Italic.ttf-da10696e2f4be4192574d1c950d4085f.fontdata"

[deps]

source_file="res://Hack-Italic.ttf"
dest_files=["res://.godot/imported/Hack-Italic.ttf-da10696e2f4be4192574d1c950d4085f.fontdata"]

[params]

Rendering=null
antialiasing=1
generate_mipmaps=false
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
allow_system_fallback=true
force_autohinter=false
hinting=1
subpixel_positioning=1
oversampling=0.0
Fallbacks=null
fallbacks=[]
Compress=null
compress=true
preload=[]
language_support={}
script_support={}
opentype_features={}
Binary file added doc/examples/GDExt/project/Hack-Regular.ttf
Binary file not shown.
33 changes: 33 additions & 0 deletions doc/examples/GDExt/project/Hack-Regular.ttf.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[remap]

importer="font_data_dynamic"
type="FontFile"
uid="uid://2se0brkpdxhs"
path="res://.godot/imported/Hack-Regular.ttf-4957220eed9c50075bb4de8b4fadc317.fontdata"

[deps]

source_file="res://Hack-Regular.ttf"
dest_files=["res://.godot/imported/Hack-Regular.ttf-4957220eed9c50075bb4de8b4fadc317.fontdata"]

[params]

Rendering=null
antialiasing=1
generate_mipmaps=false
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
allow_system_fallback=true
force_autohinter=false
hinting=1
subpixel_positioning=1
oversampling=0.0
Fallbacks=null
fallbacks=[]
Compress=null
compress=true
preload=[]
language_support={}
script_support={}
opentype_features={}
46 changes: 46 additions & 0 deletions doc/examples/GDExt/project/imgui_config.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[gd_resource type="Resource" script_class="ImGuiConfig" load_steps=11 format=3 uid="uid://c58buectmbwmf"]

[ext_resource type="Script" path="res://addons/imgui-godot/scripts/ImGuiFont.gd" id="1_0saup"]
[ext_resource type="FontFile" uid="uid://2se0brkpdxhs" path="res://Hack-Regular.ttf" id="1_7tey3"]
[ext_resource type="Script" path="res://addons/imgui-godot/scripts/ImGuiConfig.gd" id="1_nq4e5"]
[ext_resource type="FontFile" uid="uid://geey1pyskdev" path="res://Hack-Bold.ttf" id="3_5fv0r"]
[ext_resource type="FontFile" uid="uid://ccn210ltcrs6i" path="res://Hack-Italic.ttf" id="4_34el5"]

[sub_resource type="Resource" id="Resource_57j4v"]
script = ExtResource("1_0saup")
FontData = ExtResource("1_7tey3")
FontSize = 16
Merge = false

[sub_resource type="Resource" id="Resource_4trot"]
script = ExtResource("1_0saup")
FontData = ExtResource("3_5fv0r")
FontSize = 32
Merge = false

[sub_resource type="Resource" id="Resource_okot8"]
script = ExtResource("1_0saup")
FontData = ExtResource("3_5fv0r")
FontSize = 24
Merge = false

[sub_resource type="Resource" id="Resource_3knfi"]
script = ExtResource("1_0saup")
FontData = ExtResource("3_5fv0r")
FontSize = 16
Merge = false

[sub_resource type="Resource" id="Resource_2wpqv"]
script = ExtResource("1_0saup")
FontData = ExtResource("4_34el5")
FontSize = 16
Merge = false

[resource]
script = ExtResource("1_nq4e5")
Fonts = Array[ExtResource("1_0saup")]([SubResource("Resource_57j4v"), SubResource("Resource_4trot"), SubResource("Resource_okot8"), SubResource("Resource_3knfi"), SubResource("Resource_2wpqv")])
AddDefaultFont = false
Scale = 1.0
IniFilename = "user://imgui.ini"
Renderer = "RenderingDevice"
Layer = 128
6 changes: 6 additions & 0 deletions doc/examples/GDExt/project/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@

config_version=5

[addons]

imgui/config="res://imgui_config.tres"

[application]

config/name="GDExt"
run/main_scene="res://main.tscn"
config/features=PackedStringArray("4.2", "Forward Plus")
run/max_fps=144
config/icon="res://icon.svg"

[autoload]
Expand All @@ -22,6 +27,7 @@ ImGuiRoot="*res://addons/imgui-godot/data/ImGuiRoot.tscn"
[display]

window/subwindows/embed_subwindows=false
window/vsync/vsync_mode=0

[editor_plugins]

Expand Down
38 changes: 38 additions & 0 deletions doc/examples/GDExt/src/example.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
#include "example.h"
#include "gdmarkdown.h"
#include <godot_cpp/classes/resource_loader.hpp>
#include <imgui-godot.h>
#include <implot.h>

using godot::Engine;
using godot::ResourceLoader;

static const std::string markdownText = R"(
# H1 Header
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
## H2 Header
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
### H3 Header
* Item 1
* Item 2
* Item 3
*Emphasis* and **strong emphasis** change the appearance of the text.
Link: [Godot Engine](https://godotengine.org)
robot eye ![an atlas texture](res://robot_eye.tres)
big robot
![](res://icon.svg)
)";

void Example::_bind_methods()
{
}
Expand All @@ -20,7 +46,13 @@ Example::~Example()

void Example::_ready()
{
#ifdef DEBUG_ENABLED
if (Engine::get_singleton()->is_editor_hint())
return;
#endif

_img = ResourceLoader::get_singleton()->load("res://robot_eye.tres");
ImGui::InitMarkdown();
}

void Example::_process(double delta)
Expand All @@ -40,5 +72,11 @@ void Example::_process(double delta)
ImGui::Image(_img, {64, 64});
ImGui::End();

ImGui::ShowDemoWindow();

ImPlot::ShowDemoWindow();

ImGui::Begin("Markdown example");
ImGui::Markdown(markdownText);
ImGui::End();
}
Loading

0 comments on commit 5a92096

Please sign in to comment.