[API] Bindings for ImGuiColorTextEdit (#79)
* Add ImGuiColorTextEdit submodule * ImGuiColorTextEdit integration * Remove unused Identifier class (oops) * Fix checkstyle * Small tweaks and fixes * Remove empty line before imports Co-authored-by: SpaiR <klimbetoo@gmail.com>
This commit is contained in:
1 parent
4d679fe220
commit
4e56056222
11 files changed
+786
-1
No files matched your search
@@ -13,3 +13,6 @@
|
||||
[submodule "include/implot"]
|
||||
path = include/implot
|
||||
url = https://github.com/epezent/implot.git
|
||||
[submodule "include/ImGuiColorTextEdit"]
|
||||
path = include/ImGuiColorTextEdit
|
||||
url = https://github.com/BalazsJako/ImGuiColorTextEdit
|
||||
@@ -256,6 +256,8 @@ dependencies {
|
||||
Immediate mode 3D gizmo for scene editing and other controls based on Dear Imgui.
|
||||
- [implot](https://github.com/epezent/implot/tree/555ff688a8134bc0c602123149abe9c17d577475) | [Example](https://github.com/SpaiR/imgui-java/blob/v1.84.1.0/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/v1.84.1.0/example/src/main/java/ExampleImGuiColorTextEdit.java) <br>
|
||||
Syntax highlighting text editor for ImGui.
|
||||
|
||||
## Freetype
|
||||
By default, Dear ImGui uses stb-truetype to render fonts. Yet there is an option to use FreeType font renderer. Go to the [imgui_freetype](https://github.com/ocornut/imgui/tree/256594575d95d56dda616c544c509740e74906b4/misc/freetype) to read about the difference.
|
||||
|
||||
@@ -46,7 +46,8 @@ class GenerateLibs extends DefaultTask {
|
||||
|
||||
// Copy ImGui h/cpp files
|
||||
project.copy { CopySpec spec ->
|
||||
['include/imgui', 'include/imnodes', 'include/imgui-node-editor', 'include/imguizmo', 'include/implot'].each {
|
||||
['include/imgui', 'include/imnodes', 'include/imgui-node-editor',
|
||||
'include/imguizmo', 'include/implot', 'include/ImGuiColorTextEdit'].each {
|
||||
spec.from(project.rootProject.file(it)) { CopySpec s -> s.include('*.h', '*.cpp', '*.inl') }
|
||||
}
|
||||
spec.from(project.rootProject.file('imgui-binding/src/main/native'))
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
import imgui.ImGui;
|
||||
import imgui.extension.texteditor.TextEditor;
|
||||
import imgui.extension.texteditor.TextEditorLanguageDefinition;
|
||||
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();
|
||||
|
||||
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;",
|
||||
"}"
|
||||
});
|
||||
}
|
||||
|
||||
public static void show(final ImBoolean showImColorTextEditWindow) {
|
||||
ImGui.setNextWindowSize(500, 400);
|
||||
if (ImGui.begin("Text Editor", showImColorTextEditWindow,
|
||||
ImGuiWindowFlags.HorizontalScrollbar | ImGuiWindowFlags.MenuBar)) {
|
||||
if (ImGui.beginMenuBar()) {
|
||||
if (ImGui.beginMenu("File")) {
|
||||
if (ImGui.menuItem("Save")) {
|
||||
String textToSave = EDITOR.getText();
|
||||
/// save text....
|
||||
}
|
||||
|
||||
ImGui.endMenu();
|
||||
}
|
||||
if (ImGui.beginMenu("Edit")) {
|
||||
final boolean ro = EDITOR.isReadOnly();
|
||||
if (ImGui.menuItem("Read-only mode", "", ro)) {
|
||||
EDITOR.setReadOnly(!ro);
|
||||
}
|
||||
|
||||
ImGui.separator();
|
||||
|
||||
if (ImGui.menuItem("Undo", "ALT-Backspace", !ro && EDITOR.canUndo())) {
|
||||
EDITOR.undo(1);
|
||||
}
|
||||
if (ImGui.menuItem("Redo", "Ctrl-Y", !ro && EDITOR.canRedo())) {
|
||||
EDITOR.redo(1);
|
||||
}
|
||||
|
||||
ImGui.separator();
|
||||
|
||||
if (ImGui.menuItem("Copy", "Ctrl-C", EDITOR.hasSelection())) {
|
||||
EDITOR.copy();
|
||||
}
|
||||
if (ImGui.menuItem("Cut", "Ctrl-X", !ro && EDITOR.hasSelection())) {
|
||||
EDITOR.cut();
|
||||
}
|
||||
if (ImGui.menuItem("Delete", "Del", !ro && EDITOR.hasSelection())) {
|
||||
EDITOR.delete();
|
||||
}
|
||||
if (ImGui.menuItem("Paste", "Ctrl-V", !ro && ImGui.getClipboardText() != null)) {
|
||||
EDITOR.paste();
|
||||
}
|
||||
|
||||
ImGui.endMenu();
|
||||
}
|
||||
|
||||
ImGui.endMenuBar();
|
||||
}
|
||||
|
||||
int cposX = EDITOR.getCursorPositionLine();
|
||||
int cposY = EDITOR.getCursorPositionColumn();
|
||||
|
||||
String overwrite = EDITOR.isOverwrite() ? "Ovr" : "Ins";
|
||||
String canUndo = EDITOR.canUndo() ? "*" : " ";
|
||||
|
||||
ImGui.text(cposX + "/" + cposY + " " + EDITOR.getTotalLines() + " lines | " + overwrite + " | " + canUndo);
|
||||
|
||||
EDITOR.render("TextEditor");
|
||||
|
||||
ImGui.end();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +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 Graph GRAPH = new Graph();
|
||||
|
||||
@@ -20,6 +21,7 @@ public class Extra {
|
||||
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);
|
||||
|
||||
if (SHOW_DEMO_WINDOW.get()) {
|
||||
ImGui.showDemoWindow(SHOW_DEMO_WINDOW);
|
||||
@@ -44,5 +46,9 @@ public class Extra {
|
||||
if (SHOW_IMPLOT_DEMO_WINDOW.get()) {
|
||||
ExampleImPlot.show(SHOW_IMPLOT_DEMO_WINDOW);
|
||||
}
|
||||
|
||||
if (SHOW_IMGUI_COLOR_TEXT_EDIT_WINDOW.get()) {
|
||||
ExampleImGuiColorTextEdit.show(SHOW_IMGUI_COLOR_TEXT_EDIT_WINDOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,377 @@
|
||||
package imgui.extension.texteditor;
|
||||
|
||||
import imgui.binding.ImGuiStructDestroyable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class TextEditor extends ImGuiStructDestroyable {
|
||||
/*JNI
|
||||
#include "_texteditor.h"
|
||||
|
||||
#define TEXT_EDITOR ((TextEditor*)STRUCT_PTR)
|
||||
*/
|
||||
|
||||
public TextEditor() {
|
||||
}
|
||||
|
||||
public TextEditor(final long ptr) {
|
||||
super(ptr);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected long create() {
|
||||
return nCreate();
|
||||
}
|
||||
|
||||
private native long nCreate(); /*
|
||||
return (intptr_t)(new TextEditor());
|
||||
*/
|
||||
|
||||
public void setLanguageDefinition(final TextEditorLanguageDefinition definition) {
|
||||
nSetLanguageDefinition(definition.ptr);
|
||||
}
|
||||
|
||||
public native void nSetLanguageDefinition(long ptr); /*
|
||||
TEXT_EDITOR->SetLanguageDefinition(*((TextEditor::LanguageDefinition*)ptr));
|
||||
*/
|
||||
|
||||
public native int[] getPalette(); /*
|
||||
const auto& palette = TEXT_EDITOR->GetPalette();
|
||||
|
||||
jintArray res = env->NewIntArray(palette.size());
|
||||
|
||||
jint arr[palette.size()];
|
||||
for (int i = 0; i < palette.size(); i++) {
|
||||
arr[i] = palette[i];
|
||||
}
|
||||
|
||||
env->SetIntArrayRegion(res, 0, palette.size(), arr);
|
||||
|
||||
return res;
|
||||
*/
|
||||
|
||||
public void setPalette(final int[] palette) {
|
||||
nSetPalette(palette, palette.length);
|
||||
}
|
||||
|
||||
public native void nSetPalette(int[] palette, int length); /*
|
||||
std::array<ImU32, (unsigned)TextEditor::PaletteIndex::Max> arr;
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
arr[i] = palette[i];
|
||||
}
|
||||
|
||||
TEXT_EDITOR->SetPalette(arr);
|
||||
*/
|
||||
|
||||
public void setErrorMarkers(final Map<Integer, String> errorMarkers) {
|
||||
final int[] keys = errorMarkers.keySet().stream().mapToInt(i -> i).toArray();
|
||||
final String[] values = errorMarkers.values().toArray(new String[0]);
|
||||
|
||||
nSetErrorMarkers(keys, keys.length, values, values.length);
|
||||
}
|
||||
|
||||
private native void nSetErrorMarkers(int[] keys, int keysLen, String[] values, int valuesLen); /*
|
||||
std::map<int, std::string> markers;
|
||||
|
||||
for (int i = 0; i < keysLen; i++) {
|
||||
int key = keys[i];
|
||||
jstring string = (jstring)env->GetObjectArrayElement(values, i);
|
||||
const char* value = env->GetStringUTFChars(string, JNI_FALSE);
|
||||
|
||||
markers.emplace(std::pair<int, std::string>(key, std::string(value)));
|
||||
}
|
||||
|
||||
TEXT_EDITOR->SetErrorMarkers(markers);
|
||||
*/
|
||||
|
||||
public void setBreakpoints(final int[] breakpoints) {
|
||||
nSetBreakpoints(breakpoints, breakpoints.length);
|
||||
}
|
||||
|
||||
private native void nSetBreakpoints(int[] breakpoints, int length); /*
|
||||
std::unordered_set<int> set;
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
set.emplace(breakpoints[i]);
|
||||
}
|
||||
|
||||
TEXT_EDITOR->SetBreakpoints(set);
|
||||
*/
|
||||
|
||||
public native void render(String title); /*
|
||||
TEXT_EDITOR->Render(title);
|
||||
*/
|
||||
|
||||
public native void setText(String text); /*
|
||||
TEXT_EDITOR->SetText(text);
|
||||
*/
|
||||
|
||||
public native String getText(); /*
|
||||
return env->NewStringUTF(TEXT_EDITOR->GetText().c_str());
|
||||
*/
|
||||
|
||||
public void setTextLines(final String[] lines) {
|
||||
nSetTextLines(lines, lines.length);
|
||||
}
|
||||
|
||||
private native void nSetTextLines(String[] lines, int length); /*
|
||||
std::vector<std::string> vec;
|
||||
vec.reserve(length);
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
jstring string = (jstring)env->GetObjectArrayElement(lines, i);
|
||||
const char* raw = env->GetStringUTFChars(string, JNI_FALSE);
|
||||
|
||||
vec.emplace_back(std::string(raw));
|
||||
}
|
||||
|
||||
TEXT_EDITOR->SetTextLines(vec);
|
||||
*/
|
||||
|
||||
public native String[] getTextLines(); /*
|
||||
const auto lines = TEXT_EDITOR->GetTextLines();
|
||||
|
||||
jobjectArray arr = (jobjectArray)env->NewObjectArray(lines.size(),
|
||||
env->FindClass("java/lang/String"),
|
||||
env->NewStringUTF(""));
|
||||
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
const auto& str = lines[i];
|
||||
|
||||
env->SetObjectArrayElement(arr, i, env->NewStringUTF(str.c_str()));
|
||||
}
|
||||
|
||||
return arr;
|
||||
*/
|
||||
|
||||
public native String getSelectedText(); /*
|
||||
return env->NewStringUTF(TEXT_EDITOR->GetSelectedText().c_str());
|
||||
*/
|
||||
|
||||
public native String getCurrentLineText(); /*
|
||||
return env->NewStringUTF(TEXT_EDITOR->GetCurrentLineText().c_str());
|
||||
*/
|
||||
|
||||
public native int getTotalLines(); /*
|
||||
return TEXT_EDITOR->GetTotalLines();
|
||||
*/
|
||||
|
||||
public native boolean isOverwrite(); /*
|
||||
return TEXT_EDITOR->IsOverwrite();
|
||||
*/
|
||||
|
||||
public native void setReadOnly(boolean value); /*
|
||||
TEXT_EDITOR->SetReadOnly(value);
|
||||
*/
|
||||
|
||||
public native boolean isReadOnly(); /*
|
||||
return TEXT_EDITOR->IsReadOnly();
|
||||
*/
|
||||
|
||||
public native boolean isTextChanged(); /*
|
||||
return TEXT_EDITOR->IsTextChanged();
|
||||
*/
|
||||
|
||||
public native boolean isCursorPositionChanged(); /*
|
||||
return TEXT_EDITOR->IsCursorPositionChanged();
|
||||
*/
|
||||
|
||||
public native boolean isColorizerEnabled(); /*
|
||||
return TEXT_EDITOR->IsColorizerEnabled();
|
||||
*/
|
||||
|
||||
public native void setColorizerEnable(boolean value); /*
|
||||
TEXT_EDITOR->SetColorizerEnable(value);
|
||||
*/
|
||||
|
||||
public native int getCursorPositionLine(); /*
|
||||
return TEXT_EDITOR->GetCursorPosition().mLine;
|
||||
*/
|
||||
|
||||
public native int getCursorPositionColumn(); /*
|
||||
return TEXT_EDITOR->GetCursorPosition().mColumn;
|
||||
*/
|
||||
|
||||
public native void setCursorPosition(int line, int column); /*
|
||||
TEXT_EDITOR->SetCursorPosition({ line, column });
|
||||
*/
|
||||
|
||||
public native void setHandleMouseInputs(boolean value); /*
|
||||
TEXT_EDITOR->SetHandleMouseInputs(value);
|
||||
*/
|
||||
|
||||
public native boolean isHandleMouseInputsEnabled(); /*
|
||||
return TEXT_EDITOR->IsHandleMouseInputsEnabled();
|
||||
*/
|
||||
|
||||
public native void setHandleKeyboardInputs(boolean value); /*
|
||||
TEXT_EDITOR->SetHandleKeyboardInputs(value);
|
||||
*/
|
||||
|
||||
public native boolean isHandleKeyboardInputsEnabled(); /*
|
||||
return TEXT_EDITOR->IsHandleKeyboardInputsEnabled();
|
||||
*/
|
||||
|
||||
public native void setImGuiChildIgnored(boolean value); /*
|
||||
TEXT_EDITOR->SetImGuiChildIgnored(value);
|
||||
*/
|
||||
|
||||
public native boolean isImGuiChildIgnored(); /*
|
||||
return TEXT_EDITOR->IsImGuiChildIgnored();
|
||||
*/
|
||||
|
||||
public native void setShowWhitespaces(boolean value); /*
|
||||
TEXT_EDITOR->SetShowWhitespaces(value);
|
||||
*/
|
||||
|
||||
public native boolean isShowingWhitespaces(); /*
|
||||
return TEXT_EDITOR->IsShowingWhitespaces();
|
||||
*/
|
||||
|
||||
public native void setTabSize(int value); /*
|
||||
TEXT_EDITOR->SetTabSize(value);
|
||||
*/
|
||||
|
||||
public native int getTabSize(); /*
|
||||
return TEXT_EDITOR->GetTabSize();
|
||||
*/
|
||||
|
||||
public native void insertText(String value); /*
|
||||
TEXT_EDITOR->InsertText(value);
|
||||
*/
|
||||
|
||||
public native void moveUp(int amount, boolean select); /*
|
||||
TEXT_EDITOR->MoveUp(amount, select);
|
||||
*/
|
||||
|
||||
public native void moveDown(int amount, boolean select); /*
|
||||
TEXT_EDITOR->MoveDown(amount, select);
|
||||
*/
|
||||
|
||||
public native void moveLeft(int amount, boolean select, boolean wordMode); /*
|
||||
TEXT_EDITOR->MoveLeft(amount, select, wordMode);
|
||||
*/
|
||||
|
||||
public native void moveRight(int amount, boolean select, boolean wordMode); /*
|
||||
TEXT_EDITOR->MoveRight(amount, select, wordMode);
|
||||
*/
|
||||
|
||||
public native void moveTop(boolean select); /*
|
||||
TEXT_EDITOR->MoveTop(select);
|
||||
*/
|
||||
|
||||
public native void moveBottom(boolean select); /*
|
||||
TEXT_EDITOR->MoveBottom(select);
|
||||
*/
|
||||
|
||||
public native void moveHome(boolean select); /*
|
||||
TEXT_EDITOR->MoveHome(select);
|
||||
*/
|
||||
|
||||
public native void moveEnd(boolean select); /*
|
||||
TEXT_EDITOR->MoveEnd(select);
|
||||
*/
|
||||
|
||||
public native void setSelectionStart(int line, int column); /*
|
||||
TEXT_EDITOR->SetSelectionStart({ line, column });
|
||||
*/
|
||||
|
||||
public native void setSelectionEnd(int line, int column); /*
|
||||
TEXT_EDITOR->SetSelectionEnd({ line, column });
|
||||
*/
|
||||
|
||||
public native void setSelection(int lineStart, int columnStart, int lineEnd, int columnEnd, int selectionMode); /*
|
||||
TEXT_EDITOR->SetSelection({ lineStart, columnStart }, { lineEnd, columnEnd },
|
||||
static_cast<TextEditor::SelectionMode>(selectionMode));
|
||||
*/
|
||||
|
||||
public native void selectWordUnderCursor(); /*
|
||||
TEXT_EDITOR->SelectWordUnderCursor();
|
||||
*/
|
||||
|
||||
public native void selectAll(); /*
|
||||
TEXT_EDITOR->SelectAll();
|
||||
*/
|
||||
|
||||
public native boolean hasSelection(); /*
|
||||
return TEXT_EDITOR->HasSelection();
|
||||
*/
|
||||
|
||||
public native void copy(); /*
|
||||
TEXT_EDITOR->Copy();
|
||||
*/
|
||||
|
||||
public native void cut(); /*
|
||||
TEXT_EDITOR->Cut();
|
||||
*/
|
||||
|
||||
public native void paste(); /*
|
||||
TEXT_EDITOR->Paste();
|
||||
*/
|
||||
|
||||
public native void delete(); /*
|
||||
TEXT_EDITOR->Delete();
|
||||
*/
|
||||
|
||||
public native boolean canUndo(); /*
|
||||
return TEXT_EDITOR->CanUndo();
|
||||
*/
|
||||
|
||||
public native boolean canRedo(); /*
|
||||
return TEXT_EDITOR->CanRedo();
|
||||
*/
|
||||
|
||||
public native void undo(int steps); /*
|
||||
TEXT_EDITOR->Undo(steps);
|
||||
*/
|
||||
|
||||
public native void redo(int steps); /*
|
||||
TEXT_EDITOR->Redo(steps);
|
||||
*/
|
||||
|
||||
public native int[] getDarkPalette(); /*
|
||||
const auto& palette = TEXT_EDITOR->GetDarkPalette();
|
||||
|
||||
jintArray res = env->NewIntArray(palette.size());
|
||||
|
||||
jint arr[palette.size()];
|
||||
for (int i = 0; i < palette.size(); i++) {
|
||||
arr[i] = palette[i];
|
||||
}
|
||||
|
||||
env->SetIntArrayRegion(res, 0, palette.size(), arr);
|
||||
|
||||
return res;
|
||||
*/
|
||||
|
||||
public native int[] getLightPalette(); /*
|
||||
const auto& palette = TEXT_EDITOR->GetLightPalette();
|
||||
|
||||
jintArray res = env->NewIntArray(palette.size());
|
||||
|
||||
jint arr[palette.size()];
|
||||
for (int i = 0; i < palette.size(); i++) {
|
||||
arr[i] = palette[i];
|
||||
}
|
||||
|
||||
env->SetIntArrayRegion(res, 0, palette.size(), arr);
|
||||
|
||||
return res;
|
||||
*/
|
||||
|
||||
public native int[] getRetroBluePalette(); /*
|
||||
const auto& palette = TEXT_EDITOR->GetRetroBluePalette();
|
||||
|
||||
jintArray res = env->NewIntArray(palette.size());
|
||||
|
||||
jint arr[palette.size()];
|
||||
for (int i = 0; i < palette.size(); i++) {
|
||||
arr[i] = palette[i];
|
||||
}
|
||||
|
||||
env->SetIntArrayRegion(res, 0, palette.size(), arr);
|
||||
|
||||
return res;
|
||||
*/
|
||||
}
|
||||
+205
@@ -0,0 +1,205 @@
|
||||
package imgui.extension.texteditor;
|
||||
|
||||
import imgui.binding.ImGuiStructDestroyable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class TextEditorLanguageDefinition extends ImGuiStructDestroyable {
|
||||
/*JNI
|
||||
#include "_texteditor.h"
|
||||
|
||||
#define LANG_DEF ((TextEditor::LanguageDefinition*)STRUCT_PTR)
|
||||
*/
|
||||
|
||||
public TextEditorLanguageDefinition() {
|
||||
}
|
||||
|
||||
public TextEditorLanguageDefinition(final long ptr) {
|
||||
super(ptr);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected long create() {
|
||||
return nCreate();
|
||||
}
|
||||
|
||||
private native long nCreate(); /*
|
||||
return (intptr_t)(new TextEditor::LanguageDefinition());
|
||||
*/
|
||||
|
||||
public native void setName(String name); /*
|
||||
LANG_DEF->mName = name;
|
||||
*/
|
||||
|
||||
public void setKeywords(final String[] keywords) {
|
||||
nSetKeywords(keywords, keywords.length);
|
||||
}
|
||||
|
||||
private native void nSetKeywords(String[] keywords, int length); /*
|
||||
std::unordered_set<std::string> set;
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
jstring string = (jstring)env->GetObjectArrayElement(keywords, i);
|
||||
const char* raw = env->GetStringUTFChars(string, JNI_FALSE);
|
||||
|
||||
set.emplace(std::string(raw));
|
||||
}
|
||||
|
||||
LANG_DEF->mKeywords = set;
|
||||
*/
|
||||
|
||||
public void setIdentifiers(final Map<String, String> identifiers) {
|
||||
final String[] keys = identifiers.keySet().toArray(new String[0]);
|
||||
final String[] decl = identifiers.values().toArray(new String[0]);
|
||||
|
||||
nSetIdentifiers(keys, keys.length, decl, decl.length);
|
||||
}
|
||||
|
||||
private native void nSetIdentifiers(String[] keys, int keysLen, String[] decl, int declLen); /*
|
||||
std::unordered_map<std::string, TextEditor::Identifier> identifiers;
|
||||
|
||||
for (int i = 0; i < keysLen; i++) {
|
||||
jstring string1 = (jstring)env->GetObjectArrayElement(keys, i);
|
||||
const char* key = env->GetStringUTFChars(string1, JNI_FALSE);
|
||||
|
||||
jstring string2 = (jstring)env->GetObjectArrayElement(decl, i);
|
||||
const char* value = env->GetStringUTFChars(string2, JNI_FALSE);
|
||||
|
||||
TextEditor::Identifier id;
|
||||
id.mDeclaration = std::string(value);
|
||||
|
||||
identifiers.insert(std::pair<std::string, TextEditor::Identifier>(std::string(key), id));
|
||||
}
|
||||
|
||||
LANG_DEF->mIdentifiers = identifiers;
|
||||
*/
|
||||
|
||||
public void setPreprocIdentifiers(final Map<String, String> identifiers) {
|
||||
final String[] keys = identifiers.keySet().toArray(new String[0]);
|
||||
final String[] decl = identifiers.values().toArray(new String[0]);
|
||||
|
||||
nSetPreprocIdentifiers(keys, keys.length, decl, decl.length);
|
||||
}
|
||||
|
||||
private native void nSetPreprocIdentifiers(String[] keys, int keysLen, String[] decl, int declLen); /*
|
||||
std::unordered_map<std::string, TextEditor::Identifier> preprocIdentifiers;
|
||||
|
||||
for (int i = 0; i < keysLen; i++) {
|
||||
jstring string1 = (jstring)env->GetObjectArrayElement(keys, i);
|
||||
const char* key = env->GetStringUTFChars(string1, JNI_FALSE);
|
||||
|
||||
jstring string2 = (jstring)env->GetObjectArrayElement(decl, i);
|
||||
const char* value = env->GetStringUTFChars(string2, JNI_FALSE);
|
||||
|
||||
TextEditor::Identifier id;
|
||||
id.mDeclaration = std::string(value);
|
||||
|
||||
preprocIdentifiers.insert(std::pair<std::string, TextEditor::Identifier>(std::string(key), id));
|
||||
}
|
||||
|
||||
LANG_DEF->mPreprocIdentifiers = preprocIdentifiers;
|
||||
*/
|
||||
|
||||
public native void setCommentStart(String value); /*
|
||||
LANG_DEF->mCommentStart = value;
|
||||
*/
|
||||
|
||||
public native void setCommentEnd(String value); /*
|
||||
LANG_DEF->mCommentEnd = value;
|
||||
*/
|
||||
|
||||
public native void setSingleLineComment(String value); /*
|
||||
LANG_DEF->mSingleLineComment = value;
|
||||
*/
|
||||
|
||||
public native void setPreprocChar(char value); /*
|
||||
LANG_DEF->mPreprocChar = value;
|
||||
*/
|
||||
|
||||
public native void setAutoIdentation(boolean value); /*
|
||||
LANG_DEF->mAutoIndentation = value;
|
||||
*/
|
||||
|
||||
public void setTokenRegexStrings(final Map<String, Integer> tokenRegexStrings) {
|
||||
final String[] keys = tokenRegexStrings.keySet().toArray(new String[0]);
|
||||
final int[] paletteIndexes = tokenRegexStrings.values().stream().mapToInt(i -> i).toArray();
|
||||
|
||||
nSetTokenRegexStrings(keys, keys.length, paletteIndexes, paletteIndexes.length);
|
||||
}
|
||||
|
||||
private native void nSetTokenRegexStrings(String[] keys, int keysLen, int[] paletteIndexes, int paletteIndexesLen); /*
|
||||
std::vector<std::pair<std::string, TextEditor::PaletteIndex>> tokenRegexStrings;
|
||||
|
||||
for (int i = 0; i < keysLen; i++) {
|
||||
jstring string = (jstring)env->GetObjectArrayElement(keys, i);
|
||||
const char* key = env->GetStringUTFChars(string, JNI_FALSE);
|
||||
|
||||
int value = paletteIndexes[i];
|
||||
|
||||
tokenRegexStrings.emplace_back(std::pair<std::string, TextEditor::PaletteIndex>(std::string(key),
|
||||
static_cast<TextEditor::PaletteIndex>(value)));
|
||||
}
|
||||
|
||||
LANG_DEF->mTokenRegexStrings = tokenRegexStrings;
|
||||
*/
|
||||
|
||||
private native void setCaseSensitive(boolean value); /*
|
||||
LANG_DEF->mCaseSensitive = value;
|
||||
*/
|
||||
|
||||
public static TextEditorLanguageDefinition cPlusPlus() {
|
||||
return new TextEditorLanguageDefinition(nCPlusPlus());
|
||||
}
|
||||
|
||||
public static TextEditorLanguageDefinition hlsl() {
|
||||
return new TextEditorLanguageDefinition(nHLSL());
|
||||
}
|
||||
|
||||
public static TextEditorLanguageDefinition glsl() {
|
||||
return new TextEditorLanguageDefinition(nGLSL());
|
||||
}
|
||||
|
||||
public static TextEditorLanguageDefinition c() {
|
||||
return new TextEditorLanguageDefinition(nC());
|
||||
}
|
||||
|
||||
public static TextEditorLanguageDefinition sql() {
|
||||
return new TextEditorLanguageDefinition(nSQL());
|
||||
}
|
||||
|
||||
public static TextEditorLanguageDefinition angelScript() {
|
||||
return new TextEditorLanguageDefinition(nAngelScript());
|
||||
}
|
||||
|
||||
public static TextEditorLanguageDefinition lua() {
|
||||
return new TextEditorLanguageDefinition(nLua());
|
||||
}
|
||||
|
||||
private static native long nCPlusPlus(); /*
|
||||
return (intptr_t)&TextEditor::LanguageDefinition::CPlusPlus();
|
||||
*/
|
||||
|
||||
private static native long nHLSL(); /*
|
||||
return (intptr_t)&TextEditor::LanguageDefinition::HLSL();
|
||||
*/
|
||||
|
||||
private static native long nGLSL(); /*
|
||||
return (intptr_t)&TextEditor::LanguageDefinition::GLSL();
|
||||
*/
|
||||
|
||||
private static native long nC(); /*
|
||||
return (intptr_t)&TextEditor::LanguageDefinition::C();
|
||||
*/
|
||||
|
||||
private static native long nSQL(); /*
|
||||
return (intptr_t)&TextEditor::LanguageDefinition::SQL();
|
||||
*/
|
||||
|
||||
private static native long nAngelScript(); /*
|
||||
return (intptr_t)&TextEditor::LanguageDefinition::AngelScript();
|
||||
*/
|
||||
|
||||
private static native long nLua(); /*
|
||||
return (intptr_t)&TextEditor::LanguageDefinition::Lua();
|
||||
*/
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package imgui.extension.texteditor.flag;
|
||||
|
||||
public final class TextEditorPaletteIndex {
|
||||
private TextEditorPaletteIndex() {
|
||||
}
|
||||
|
||||
public static final int Default = 0;
|
||||
public static final int Keyword = 1;
|
||||
public static final int Number = 2;
|
||||
public static final int String = 3;
|
||||
public static final int CharLiteral = 4;
|
||||
public static final int Punctuation = 5;
|
||||
public static final int Preprocessor = 6;
|
||||
public static final int Identifier = 7;
|
||||
public static final int KnownIdentifier = 8;
|
||||
public static final int PreprocIdentifier = 9;
|
||||
public static final int Comment = 10;
|
||||
public static final int MultiLineComment = 11;
|
||||
public static final int Background = 12;
|
||||
public static final int Cursor = 13;
|
||||
public static final int Selection = 14;
|
||||
public static final int ErrorMarker = 15;
|
||||
public static final int Breakpoint = 16;
|
||||
public static final int LineNumber = 17;
|
||||
public static final int CurrentLineFill = 18;
|
||||
public static final int CurrentLineFillInactive = 19;
|
||||
public static final int CurrentLineEdge = 20;
|
||||
public static final int Max = 21;
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package imgui.extension.texteditor.flag;
|
||||
|
||||
public final class TextEditorSelectionMode {
|
||||
private TextEditorSelectionMode() {
|
||||
}
|
||||
|
||||
public static final int Normal = 0;
|
||||
public static final int Word = 1;
|
||||
public static final int Line = 2;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
#include <regex>
|
||||
#include "_base.h"
|
||||
#include "_binding.h"
|
||||
#include "TextEditor.h"
|
||||
Submodule
+1
Submodule include/ImGuiColorTextEdit added at 0a88824f7d.
Reference in new issue
Block a user