forked from SpaiR/imgui-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExampleImGuiColorTextEdit.java
More file actions
109 lines (93 loc) · 4 KB
/
ExampleImGuiColorTextEdit.java
File metadata and controls
109 lines (93 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import imgui.ImGui;
import imgui.extension.texteditor.TextEditor;
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;
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 {
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, ImGuiCond.FirstUseEver);
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.isReadOnlyEnabled();
if (ImGui.menuItem("Read-only mode", "", ro)) {
EDITOR.setReadOnlyEnabled(!ro);
}
ImGui.separator();
if (ImGui.menuItem("Undo", "Ctrl-Z", !ro && EDITOR.canUndo())) {
EDITOR.undo();
}
if (ImGui.menuItem("Redo", "Ctrl-Y", !ro && EDITOR.canRedo())) {
EDITOR.redo();
}
ImGui.separator();
if (ImGui.menuItem("Copy", "Ctrl-C", EDITOR.anyCursorHasSelection())) {
EDITOR.copy();
}
if (ImGui.menuItem("Cut", "Ctrl-X", !ro && EDITOR.anyCursorHasSelection())) {
EDITOR.cut();
}
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();
}
TextEditorCursorPosition cpos = EDITOR.getMainCursorPosition();
String overwrite = EDITOR.isOverwriteEnabled() ? "Ovr" : "Ins";
String canUndo = EDITOR.canUndo() ? "*" : " ";
ImGui.text(cpos.line + "/" + cpos.column + " " + EDITOR.getLineCount() + " lines | " + overwrite + " | " + canUndo);
EDITOR.render("TextEditor");
ImGui.end();
}
}
}