Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
url = https://github.com/epezent/implot.git
[submodule "include/ImGuiColorTextEdit"]
path = include/ImGuiColorTextEdit
url = https://github.com/BalazsJako/ImGuiColorTextEdit
url = https://github.com/goossens/ImGuiColorTextEdit
[submodule "include/ImGuiFileDialog"]
path = include/ImGuiFileDialog
url = https://github.com/aiekick/ImGuiFileDialog
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ See examples in the `example` module for more information about how to use them.
Immediate mode 3D gizmo for scene editing and other controls based on Dear ImGui.
- [implot](https://github.com/epezent/implot/tree/v1.0) | [Example](https://github.com/SpaiR/imgui-java/blob/main/example/src/main/java/ExampleImPlot.java) <br>
Advanced 2D Plotting for Dear ImGui.
- [ImGuiColorTextEdit](https://github.com/BalazsJako/ImGuiColorTextEdit/tree/0a88824f7de8d0bd11d8419066caa7d3469395c4) | [Example](https://github.com/SpaiR/imgui-java/blob/main/example/src/main/java/ExampleImGuiColorTextEdit.java) <br>
- [ImGuiColorTextEdit](https://github.com/goossens/ImGuiColorTextEdit/tree/0a88824f7de8d0bd11d8419066caa7d3469395c4) | [Example](https://github.com/SpaiR/imgui-java/blob/main/example/src/main/java/ExampleImGuiColorTextEdit.java) <br>
Syntax highlighting text editor for ImGui.
- [ImGuiFileDialog](https://github.com/aiekick/ImGuiFileDialog/tree/4d42dfba125cbd4780a90fbc5f75e7dfbae64060) | [Example](https://github.com/SpaiR/imgui-java/blob/main/example/src/main/java/ExampleImGuiFileDialog.java) <br>
A file selection dialog built for ImGui.
Expand Down
19 changes: 17 additions & 2 deletions buildSrc/src/main/groovy/tool/generator/GenerateLibs.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class GenerateLibs extends DefaultTask {
'include/imgui-node-editor',
'include/imguizmo',
'include/implot',
// 'include/ImGuiColorTextEdit',
'include/ImGuiColorTextEdit',
// 'include/ImGuiFileDialog',
'include/imgui_club/imgui_memory_editor',
'include/imgui-knobs'
Expand Down Expand Up @@ -80,6 +80,12 @@ class GenerateLibs extends DefaultTask {
spec.into(jniDir)
}

// Ensure the active ImGuiColorTextEdit snapshot wins even if a stale TextEditor.* exists in the JNI dir.
project.copy { CopySpec spec ->
spec.from(project.rootProject.file('include/ImGuiColorTextEdit')) { CopySpec s -> s.include('TextEditor.h', 'TextEditor.cpp') }
spec.into(jniDir)
}

if (withFreeType) {
project.copy { CopySpec spec ->
spec.from(project.rootProject.file('include/imgui/misc/freetype')) { CopySpec it -> it.include('*.h', '*.cpp') }
Expand Down Expand Up @@ -108,12 +114,14 @@ class GenerateLibs extends DefaultTask {

if (forWindows) {
def win64 = BuildTarget.newDefaultTarget(Os.Windows, Architecture.Bitness._64)
requireCpp17(win64)
addFreeTypeIfEnabled(win64)
buildTargets += win64
}

if (forLinux) {
def linux64 = BuildTarget.newDefaultTarget(Os.Linux, Architecture.Bitness._64)
requireCpp17(linux64)
addFreeTypeIfEnabled(linux64)
buildTargets += linux64
}
Expand Down Expand Up @@ -166,13 +174,20 @@ class GenerateLibs extends DefaultTask {
def minMacOsVersion = '10.15'
def macTarget = BuildTarget.newDefaultTarget(Os.MacOsX, Architecture.Bitness._64, arch)
macTarget.libName = "libimgui-java64.dylib" // Lib for arm64 will be named the same for consistency.
macTarget.cppFlags += ' -std=c++14'
requireCpp17(macTarget)
macTarget.cppFlags = macTarget.cppFlags.replace('10.7', minMacOsVersion)
macTarget.linkerFlags = macTarget.linkerFlags.replace('10.7', minMacOsVersion)
addFreeTypeIfEnabled(macTarget)
return macTarget
}

void requireCpp17(BuildTarget target) {
target.cppFlags = target.cppFlags.replace(' -std=c++14', '')
if (!target.cppFlags.contains('-std=c++17')) {
target.cppFlags += ' -std=c++17'
}
}

void addFreeTypeIfEnabled(BuildTarget target) {
if (!withFreeType) {
return
Expand Down
6 changes: 3 additions & 3 deletions buildSrc/src/main/kotlin/tool/generator/api/jni_content.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private fun convertParams2jni(f: Factory, params: List<CtParameter<*>>, defaults
setType<CtTypedElement<Any>>(f.createTypeParam("double"))
setSimpleName<CtNamedElement>("${p.simpleName}MaxY")
}
} else if (p.isType("TextEditorCoordinates")) {
} else if (p.isType("TextEditorCursorPosition")) {
result += f.createParameter<Any>().apply {
setType<CtTypedElement<Any>>(f.createTypeParam("int"))
setSimpleName<CtNamedElement>("${p.simpleName}Line")
Expand Down Expand Up @@ -167,8 +167,8 @@ private fun joinInBodyParams(params: List<CtParameter<*>>, defaults: IntArray):
"ImPlotRect(${p.simpleName}MinX, ${p.simpleName}MinY, ${p.simpleName}MaxX, ${p.simpleName}MaxY)"
}

"TextEditorCoordinates" -> {
"TextEditor::Coordinates(${p.simpleName}Line, ${p.simpleName}Column)"
"TextEditorCursorPosition" -> {
"TextEditor::CursorPosition(${p.simpleName}Line, ${p.simpleName}Column)"
}

else -> p.simpleName
Expand Down
6 changes: 3 additions & 3 deletions buildSrc/src/main/kotlin/tool/generator/api/jvm_content.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private fun joinInBodyParams(params: List<CtParameter<*>>, defaults: IntArray):
"ImPlotRange" -> "${p.simpleName}.min, ${p.simpleName}.max"
"ImPlotRect" -> "${p.simpleName}.x.min, ${p.simpleName}.y.min, ${p.simpleName}.x.max, ${p.simpleName}.y.max"

"TextEditorCoordinates" -> "${p.simpleName}.mLine, ${p.simpleName}.mColumn"
"TextEditorCursorPosition" -> "${p.simpleName}.line, ${p.simpleName}.column"

"String[]" -> "${p.simpleName}, ${p.simpleName}.length"

Expand Down Expand Up @@ -425,7 +425,7 @@ private fun methodCoordinatesUnwrappedContent(method: CtMethod<*>, fromIndex: In
val paramNames = mutableSetOf<String>()

for ((idx, p) in newMethod.parameters.withIndex()) {
if (p.isType("TextEditorCoordinates") && idx >= fromIndex) {
if (p.isType("TextEditorCursorPosition") && idx >= fromIndex) {
paramNames += p.simpleName

val paramX = p.factory.createParameter<Any>()
Expand Down Expand Up @@ -529,7 +529,7 @@ private fun transformMethodToContent(
if (params.find { it.isType("ImPlotRect") } != null) {
methodPlotLimitsUnwrappedContent(method, fromIndex).takeIf(String::isNotEmpty)?.run(result::add)
}
if (params.find { it.isType("TextEditorCoordinates") } != null) {
if (params.find { it.isType("TextEditorCursorPosition") } != null) {
methodCoordinatesUnwrappedContent(method, fromIndex).takeIf(String::isNotEmpty)?.run(result::add)
}
return result
Expand Down
3 changes: 2 additions & 1 deletion buildSrc/src/main/kotlin/tool/generator/api/util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ val DST_RETURN_TYPE_SET = setOf(
"ImPlotPoint",
"ImPlotRange",
"ImPlotRect",
"TextEditorCoordinates",
"TextEditorCursorPosition",
"TextEditorCursorSelection",
)

fun CtElement.hasAnnotation(annotationName: String): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"info" : {
"source" : "include/ImGuiColorTextEdit/TextEditor.h",
"hash" : "1e5c6cd321f415c393ab30d4800a0dc2",
"url" : "https://github.com/BalazsJako/ImGuiColorTextEdit",
"url" : "https://github.com/goossens/ImGuiColorTextEdit",
"revision" : "0a88824f7de8d0bd11d8419066caa7d3469395c4"
},
"decls" : [ {
Expand Down
129 changes: 49 additions & 80 deletions example/src/main/java/ExampleImGuiColorTextEdit.java
Original file line number Diff line number Diff line change
@@ -1,82 +1,49 @@
/*
import imgui.ImGui;
import imgui.extension.texteditor.TextEditor;
import imgui.extension.texteditor.TextEditorCoordinates;
import imgui.extension.texteditor.TextEditorLanguageDefinition;
import imgui.extension.texteditor.TextEditorCursorPosition;
import imgui.extension.texteditor.TextEditorLanguage;
import imgui.extension.texteditor.flag.TextEditorColor;
import imgui.extension.texteditor.flag.TextEditorScroll;
import imgui.flag.ImGuiCond;
import imgui.flag.ImGuiWindowFlags;
import imgui.type.ImBoolean;

import java.util.HashMap;
import java.util.Map;

public class ExampleImGuiColorTextEdit {
private static final TextEditor EDITOR = new TextEditor();
private static final String DEMO_TEXT =
"// Demo C++ Code\n" +
"\n" +
"#include <iostream>\n" +
"#include <random>\n" +
"#include <vector>\n" +
"\n" +
"int main(int, char**) {\n" +
" std::random_device rd;\n" +
" std::mt19937 gen(rd());\n" +
" std::uniform_int_distribution<> distrib(0, 1000);\n" +
" std::vector<int> numbers;\n" +
"\n" +
" for (int i = 0; i < 100; i++) {\n" +
" numbers.emplace_back(distrib(gen));\n" +
" }\n" +
"\n" +
" for (auto n : numbers) {\n" +
" std::cout << n << std::endl;\n" +
" }\n" +
"\n" +
" return 0;\n" +
"}\n";


static {
TextEditorLanguageDefinition lang = TextEditorLanguageDefinition.C();

String[] ppnames = {
"NULL", "PM_REMOVE",
"ZeroMemory", "DXGI_SWAP_EFFECT_DISCARD", "D3D_FEATURE_LEVEL", "D3D_DRIVER_TYPE_HARDWARE", "WINAPI", "D3D11_SDK_VERSION", "assert"};
String[] ppvalues = {
"#define NULL ((void*)0)",
"#define PM_REMOVE (0x0001)",
"Microsoft's own memory zapper function\n(which is a macro actually)\nvoid ZeroMemory(\n\t[in] PVOID Destination,\n\t[in] SIZE_T Length\n); ",
"enum DXGI_SWAP_EFFECT::DXGI_SWAP_EFFECT_DISCARD = 0",
"enum D3D_FEATURE_LEVEL",
"enum D3D_DRIVER_TYPE::D3D_DRIVER_TYPE_HARDWARE = ( D3D_DRIVER_TYPE_UNKNOWN + 1 )",
"#define WINAPI __stdcall",
"#define D3D11_SDK_VERSION (7)",
" #define assert(expression) (void)( \n" +
" (!!(expression)) || \n" +
" (_wassert(_CRT_WIDE(#expression), _CRT_WIDE(__FILE__), (unsigned)(__LINE__)), 0) \n" +
" )"
};

// Adding custom preproc identifiers
Map<String, String> preprocIdentifierMap = new HashMap<>();
for (int i = 0; i < ppnames.length; ++i) {
preprocIdentifierMap.put(ppnames[i], ppvalues[i]);
}
lang.setPreprocIdentifiers(preprocIdentifierMap);

String[] identifiers = {
"HWND", "HRESULT", "LPRESULT","D3D11_RENDER_TARGET_VIEW_DESC", "DXGI_SWAP_CHAIN_DESC","MSG","LRESULT","WPARAM", "LPARAM","UINT","LPVOID",
"ID3D11Device", "ID3D11DeviceContext", "ID3D11Buffer", "ID3D11Buffer", "ID3D10Blob", "ID3D11VertexShader", "ID3D11InputLayout", "ID3D11Buffer",
"ID3D10Blob", "ID3D11PixelShader", "ID3D11SamplerState", "ID3D11ShaderResourceView", "ID3D11RasterizerState", "ID3D11BlendState", "ID3D11DepthStencilState",
"IDXGISwapChain", "ID3D11RenderTargetView", "ID3D11Texture2D", "TextEditor" };
String[] idecls = {
"typedef HWND_* HWND", "typedef long HRESULT", "typedef long* LPRESULT", "struct D3D11_RENDER_TARGET_VIEW_DESC", "struct DXGI_SWAP_CHAIN_DESC",
"typedef tagMSG MSG\n * Message structure","typedef LONG_PTR LRESULT","WPARAM", "LPARAM","UINT","LPVOID",
"ID3D11Device", "ID3D11DeviceContext", "ID3D11Buffer", "ID3D11Buffer", "ID3D10Blob", "ID3D11VertexShader", "ID3D11InputLayout", "ID3D11Buffer",
"ID3D10Blob", "ID3D11PixelShader", "ID3D11SamplerState", "ID3D11ShaderResourceView", "ID3D11RasterizerState", "ID3D11BlendState", "ID3D11DepthStencilState",
"IDXGISwapChain", "ID3D11RenderTargetView", "ID3D11Texture2D", "class TextEditor" };

// Adding custom identifiers
Map<String, String> identifierMap = new HashMap<>();
for (int i = 0; i < ppnames.length; ++i) {
identifierMap.put(identifiers[i], idecls[i]);
}
lang.setIdentifiers(identifierMap);

EDITOR.setLanguageDefinition(lang);

// Adding error markers
Map<Integer, String> errorMarkers = new HashMap<>();
errorMarkers.put(1, "Expected '>'");
EDITOR.setErrorMarkers(errorMarkers);

EDITOR.setTextLines(new String[]{
"#include <iostream",
"",
"int main() {",
" std::cout << \"Hello, World!\" << std::endl;",
"}"
});
EDITOR.setText(DEMO_TEXT);
EDITOR.setLanguage(TextEditorLanguage.Cpp());
EDITOR.setPaletteColor(TextEditorColor.currentLineNumber, 0xFFFFC080);
EDITOR.scrollToLine(9, TextEditorScroll.alignMiddle);
}

public static void show(final ImBoolean showImColorTextEditWindow) {
ImGui.setNextWindowSize(500, 400);
ImGui.setNextWindowSize(500, 400, ImGuiCond.FirstUseEver);
if (ImGui.begin("Text Editor", showImColorTextEditWindow,
ImGuiWindowFlags.HorizontalScrollbar | ImGuiWindowFlags.MenuBar)) {
if (ImGui.beginMenuBar()) {
Expand All @@ -89,52 +56,54 @@ public static void show(final ImBoolean showImColorTextEditWindow) {
ImGui.endMenu();
}
if (ImGui.beginMenu("Edit")) {
final boolean ro = EDITOR.isReadOnly();
final boolean ro = EDITOR.isReadOnlyEnabled();
if (ImGui.menuItem("Read-only mode", "", ro)) {
EDITOR.setReadOnly(!ro);
EDITOR.setReadOnlyEnabled(!ro);
}

ImGui.separator();

if (ImGui.menuItem("Undo", "ALT-Backspace", !ro && EDITOR.canUndo())) {
EDITOR.undo(1);
if (ImGui.menuItem("Undo", "Ctrl-Z", !ro && EDITOR.canUndo())) {
EDITOR.undo();
}
if (ImGui.menuItem("Redo", "Ctrl-Y", !ro && EDITOR.canRedo())) {
EDITOR.redo(1);
EDITOR.redo();
}

ImGui.separator();

if (ImGui.menuItem("Copy", "Ctrl-C", EDITOR.hasSelection())) {
if (ImGui.menuItem("Copy", "Ctrl-C", EDITOR.anyCursorHasSelection())) {
EDITOR.copy();
}
if (ImGui.menuItem("Cut", "Ctrl-X", !ro && EDITOR.hasSelection())) {
if (ImGui.menuItem("Cut", "Ctrl-X", !ro && EDITOR.anyCursorHasSelection())) {
EDITOR.cut();
}
if (ImGui.menuItem("Delete", "Del", !ro && EDITOR.hasSelection())) {
EDITOR.delete();
if (ImGui.menuItem("Delete", "Del", !ro && EDITOR.anyCursorHasSelection())) {
EDITOR.replaceTextInAllCursors("");
}
if (ImGui.menuItem("Paste", "Ctrl-V", !ro && ImGui.getClipboardText() != null)) {
EDITOR.paste();
}
if (ImGui.menuItem("Select All", "Ctrl-A", !EDITOR.isEmpty())) {
EDITOR.selectAll();
}

ImGui.endMenu();
}

ImGui.endMenuBar();
}

TextEditorCoordinates cpos = EDITOR.getCursorPosition();
TextEditorCursorPosition cpos = EDITOR.getMainCursorPosition();

String overwrite = EDITOR.isOverwrite() ? "Ovr" : "Ins";
String overwrite = EDITOR.isOverwriteEnabled() ? "Ovr" : "Ins";
String canUndo = EDITOR.canUndo() ? "*" : " ";

ImGui.text(cpos.mLine + "/" + cpos.mColumn + " " + EDITOR.getTotalLines() + " lines | " + overwrite + " | " + canUndo);
ImGui.text(cpos.line + "/" + cpos.column + " " + EDITOR.getLineCount() + " lines | " + overwrite + " | " + canUndo);

EDITOR.render("TextEditor");

ImGui.end();
}
}
}
*/
10 changes: 5 additions & 5 deletions example/src/main/java/Extra.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Extra {
private static final ImBoolean SHOW_DRAG_N_DROP_WINDOW = new ImBoolean(false);
private static final ImBoolean SHOW_IMPLOT_DEMO_WINDOW = new ImBoolean(false);
private static final ImBoolean SHOW_IMGUIZMO_DEMO = new ImBoolean(false);
// private static final ImBoolean SHOW_IMGUI_COLOR_TEXT_EDIT_WINDOW = new ImBoolean(false);
private static final ImBoolean SHOW_IMGUI_COLOR_TEXT_EDIT_WINDOW = new ImBoolean(false);
// private static final ImBoolean SHOW_IMGUI_FILE_DIALOG_WINDOW = new ImBoolean(false);
private static final ImBoolean SHOW_IMGUI_MEMORY_EDITOR_WINDOW = new ImBoolean(false);
private static final ImBoolean SHOW_IMGUI_CANVAS_EDITOR_WINDOW = new ImBoolean(false);
Expand All @@ -26,7 +26,7 @@ public static void show(final Application app) {
ImGui.checkbox("Show Drag'N'Drop Demo Window", SHOW_DRAG_N_DROP_WINDOW);
ImGui.checkbox("Show ImPlot Demo Window", SHOW_IMPLOT_DEMO_WINDOW);
ImGui.checkbox("Show ImGuizmo Demo Window", SHOW_IMGUIZMO_DEMO);
// ImGui.checkbox("Show ImGuiColorTextEdit Demo Window", SHOW_IMGUI_COLOR_TEXT_EDIT_WINDOW);
ImGui.checkbox("Show ImGuiColorTextEdit Demo Window", SHOW_IMGUI_COLOR_TEXT_EDIT_WINDOW);
// ImGui.checkbox("Show ImGuiFileDialog Demo Window", SHOW_IMGUI_FILE_DIALOG_WINDOW);
ImGui.checkbox("Show ImGui MemoryEditor Demo Window", SHOW_IMGUI_MEMORY_EDITOR_WINDOW);
ImGui.checkbox("Show ImGui Canvas Demo Window", SHOW_IMGUI_CANVAS_EDITOR_WINDOW);
Expand Down Expand Up @@ -57,9 +57,9 @@ public static void show(final Application app) {
ExampleImPlot.show(SHOW_IMPLOT_DEMO_WINDOW);
}

// if (SHOW_IMGUI_COLOR_TEXT_EDIT_WINDOW.get()) {
// ExampleImGuiColorTextEdit.show(SHOW_IMGUI_COLOR_TEXT_EDIT_WINDOW);
// }
if (SHOW_IMGUI_COLOR_TEXT_EDIT_WINDOW.get()) {
ExampleImGuiColorTextEdit.show(SHOW_IMGUI_COLOR_TEXT_EDIT_WINDOW);
}

// if (SHOW_IMGUI_FILE_DIALOG_WINDOW.get()) {
// ExampleImGuiFileDialog.show(SHOW_IMGUI_FILE_DIALOG_WINDOW);
Expand Down
Loading