1- /*
21import imgui .ImGui ;
32import imgui .extension .texteditor .TextEditor ;
4- import imgui.extension.texteditor.TextEditorCoordinates;
5- import imgui.extension.texteditor.TextEditorLanguageDefinition;
3+ import imgui .extension .texteditor .TextEditorCursorPosition ;
4+ import imgui .extension .texteditor .TextEditorLanguage ;
5+ import imgui .extension .texteditor .flag .TextEditorColor ;
6+ import imgui .extension .texteditor .flag .TextEditorScroll ;
7+ import imgui .flag .ImGuiCond ;
68import imgui .flag .ImGuiWindowFlags ;
79import imgui .type .ImBoolean ;
810
9- import java.util.HashMap;
10- import java.util.Map;
11-
1211public class ExampleImGuiColorTextEdit {
1312 private static final TextEditor EDITOR = new TextEditor ();
13+ private static final String DEMO_TEXT =
14+ "// Demo C++ Code\n " +
15+ "\n " +
16+ "#include <iostream>\n " +
17+ "#include <random>\n " +
18+ "#include <vector>\n " +
19+ "\n " +
20+ "int main(int, char**) {\n " +
21+ " std::random_device rd;\n " +
22+ " std::mt19937 gen(rd());\n " +
23+ " std::uniform_int_distribution<> distrib(0, 1000);\n " +
24+ " std::vector<int> numbers;\n " +
25+ "\n " +
26+ " for (int i = 0; i < 100; i++) {\n " +
27+ " numbers.emplace_back(distrib(gen));\n " +
28+ " }\n " +
29+ "\n " +
30+ " for (auto n : numbers) {\n " +
31+ " std::cout << n << std::endl;\n " +
32+ " }\n " +
33+ "\n " +
34+ " return 0;\n " +
35+ "}\n " ;
36+
1437
1538 static {
16- TextEditorLanguageDefinition lang = TextEditorLanguageDefinition.C();
17-
18- String[] ppnames = {
19- "NULL", "PM_REMOVE",
20- "ZeroMemory", "DXGI_SWAP_EFFECT_DISCARD", "D3D_FEATURE_LEVEL", "D3D_DRIVER_TYPE_HARDWARE", "WINAPI", "D3D11_SDK_VERSION", "assert"};
21- String[] ppvalues = {
22- "#define NULL ((void*)0)",
23- "#define PM_REMOVE (0x0001)",
24- "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); ",
25- "enum DXGI_SWAP_EFFECT::DXGI_SWAP_EFFECT_DISCARD = 0",
26- "enum D3D_FEATURE_LEVEL",
27- "enum D3D_DRIVER_TYPE::D3D_DRIVER_TYPE_HARDWARE = ( D3D_DRIVER_TYPE_UNKNOWN + 1 )",
28- "#define WINAPI __stdcall",
29- "#define D3D11_SDK_VERSION (7)",
30- " #define assert(expression) (void)( \n" +
31- " (!!(expression)) || \n" +
32- " (_wassert(_CRT_WIDE(#expression), _CRT_WIDE(__FILE__), (unsigned)(__LINE__)), 0) \n" +
33- " )"
34- };
35-
36- // Adding custom preproc identifiers
37- Map<String, String> preprocIdentifierMap = new HashMap<>();
38- for (int i = 0; i < ppnames.length; ++i) {
39- preprocIdentifierMap.put(ppnames[i], ppvalues[i]);
40- }
41- lang.setPreprocIdentifiers(preprocIdentifierMap);
42-
43- String[] identifiers = {
44- "HWND", "HRESULT", "LPRESULT","D3D11_RENDER_TARGET_VIEW_DESC", "DXGI_SWAP_CHAIN_DESC","MSG","LRESULT","WPARAM", "LPARAM","UINT","LPVOID",
45- "ID3D11Device", "ID3D11DeviceContext", "ID3D11Buffer", "ID3D11Buffer", "ID3D10Blob", "ID3D11VertexShader", "ID3D11InputLayout", "ID3D11Buffer",
46- "ID3D10Blob", "ID3D11PixelShader", "ID3D11SamplerState", "ID3D11ShaderResourceView", "ID3D11RasterizerState", "ID3D11BlendState", "ID3D11DepthStencilState",
47- "IDXGISwapChain", "ID3D11RenderTargetView", "ID3D11Texture2D", "TextEditor" };
48- String[] idecls = {
49- "typedef HWND_* HWND", "typedef long HRESULT", "typedef long* LPRESULT", "struct D3D11_RENDER_TARGET_VIEW_DESC", "struct DXGI_SWAP_CHAIN_DESC",
50- "typedef tagMSG MSG\n * Message structure","typedef LONG_PTR LRESULT","WPARAM", "LPARAM","UINT","LPVOID",
51- "ID3D11Device", "ID3D11DeviceContext", "ID3D11Buffer", "ID3D11Buffer", "ID3D10Blob", "ID3D11VertexShader", "ID3D11InputLayout", "ID3D11Buffer",
52- "ID3D10Blob", "ID3D11PixelShader", "ID3D11SamplerState", "ID3D11ShaderResourceView", "ID3D11RasterizerState", "ID3D11BlendState", "ID3D11DepthStencilState",
53- "IDXGISwapChain", "ID3D11RenderTargetView", "ID3D11Texture2D", "class TextEditor" };
54-
55- // Adding custom identifiers
56- Map<String, String> identifierMap = new HashMap<>();
57- for (int i = 0; i < ppnames.length; ++i) {
58- identifierMap.put(identifiers[i], idecls[i]);
59- }
60- lang.setIdentifiers(identifierMap);
61-
62- EDITOR.setLanguageDefinition(lang);
63-
64- // Adding error markers
65- Map<Integer, String> errorMarkers = new HashMap<>();
66- errorMarkers.put(1, "Expected '>'");
67- EDITOR.setErrorMarkers(errorMarkers);
68-
69- EDITOR.setTextLines(new String[]{
70- "#include <iostream",
71- "",
72- "int main() {",
73- " std::cout << \"Hello, World!\" << std::endl;",
74- "}"
75- });
39+ EDITOR .setText (DEMO_TEXT );
40+ EDITOR .setLanguage (TextEditorLanguage .Cpp ());
41+ EDITOR .setPaletteColor (TextEditorColor .currentLineNumber , 0xFFFFC080 );
42+ EDITOR .scrollToLine (9 , TextEditorScroll .alignMiddle );
7643 }
7744
7845 public static void show (final ImBoolean showImColorTextEditWindow ) {
79- ImGui.setNextWindowSize(500, 400);
46+ ImGui .setNextWindowSize (500 , 400 , ImGuiCond . FirstUseEver );
8047 if (ImGui .begin ("Text Editor" , showImColorTextEditWindow ,
8148 ImGuiWindowFlags .HorizontalScrollbar | ImGuiWindowFlags .MenuBar )) {
8249 if (ImGui .beginMenuBar ()) {
@@ -89,52 +56,54 @@ public static void show(final ImBoolean showImColorTextEditWindow) {
8956 ImGui .endMenu ();
9057 }
9158 if (ImGui .beginMenu ("Edit" )) {
92- final boolean ro = EDITOR.isReadOnly ();
59+ final boolean ro = EDITOR .isReadOnlyEnabled ();
9360 if (ImGui .menuItem ("Read-only mode" , "" , ro )) {
94- EDITOR.setReadOnly (!ro);
61+ EDITOR .setReadOnlyEnabled (!ro );
9562 }
9663
9764 ImGui .separator ();
9865
99- if (ImGui.menuItem("Undo", "ALT-Backspace ", !ro && EDITOR.canUndo())) {
100- EDITOR.undo(1 );
66+ if (ImGui .menuItem ("Undo" , "Ctrl-Z " , !ro && EDITOR .canUndo ())) {
67+ EDITOR .undo ();
10168 }
10269 if (ImGui .menuItem ("Redo" , "Ctrl-Y" , !ro && EDITOR .canRedo ())) {
103- EDITOR.redo(1 );
70+ EDITOR .redo ();
10471 }
10572
10673 ImGui .separator ();
10774
108- if (ImGui.menuItem("Copy", "Ctrl-C", EDITOR.hasSelection ())) {
75+ if (ImGui .menuItem ("Copy" , "Ctrl-C" , EDITOR .anyCursorHasSelection ())) {
10976 EDITOR .copy ();
11077 }
111- if (ImGui.menuItem("Cut", "Ctrl-X", !ro && EDITOR.hasSelection ())) {
78+ if (ImGui .menuItem ("Cut" , "Ctrl-X" , !ro && EDITOR .anyCursorHasSelection ())) {
11279 EDITOR .cut ();
11380 }
114- if (ImGui.menuItem("Delete", "Del", !ro && EDITOR.hasSelection ())) {
115- EDITOR.delete( );
81+ if (ImGui .menuItem ("Delete" , "Del" , !ro && EDITOR .anyCursorHasSelection ())) {
82+ EDITOR .replaceTextInAllCursors ( "" );
11683 }
11784 if (ImGui .menuItem ("Paste" , "Ctrl-V" , !ro && ImGui .getClipboardText () != null )) {
11885 EDITOR .paste ();
11986 }
87+ if (ImGui .menuItem ("Select All" , "Ctrl-A" , !EDITOR .isEmpty ())) {
88+ EDITOR .selectAll ();
89+ }
12090
12191 ImGui .endMenu ();
12292 }
12393
12494 ImGui .endMenuBar ();
12595 }
12696
127- TextEditorCoordinates cpos = EDITOR.getCursorPosition ();
97+ TextEditorCursorPosition cpos = EDITOR .getMainCursorPosition ();
12898
129- String overwrite = EDITOR.isOverwrite () ? "Ovr" : "Ins";
99+ String overwrite = EDITOR .isOverwriteEnabled () ? "Ovr" : "Ins" ;
130100 String canUndo = EDITOR .canUndo () ? "*" : " " ;
131101
132- ImGui.text(cpos.mLine + "/" + cpos.mColumn + " " + EDITOR.getTotalLines () + " lines | " + overwrite + " | " + canUndo);
102+ ImGui .text (cpos .line + "/" + cpos .column + " " + EDITOR .getLineCount () + " lines | " + overwrite + " | " + canUndo );
133103
134104 EDITOR .render ("TextEditor" );
135105
136106 ImGui .end ();
137107 }
138108 }
139109}
140- */
0 commit comments