[fonts] Example class comments
This commit is contained in:
1 parent
01b7bec5b2
commit
c8931af336
1 file changed
+48
-32
@@ -11,7 +11,6 @@ import imgui.enums.ImGuiConfigFlags;
|
|||||||
import imgui.enums.ImGuiInputTextFlags;
|
import imgui.enums.ImGuiInputTextFlags;
|
||||||
import imgui.enums.ImGuiKey;
|
import imgui.enums.ImGuiKey;
|
||||||
import imgui.enums.ImGuiMouseCursor;
|
import imgui.enums.ImGuiMouseCursor;
|
||||||
import imgui.enums.ImGuiWindowFlags;
|
|
||||||
import imgui.gl3.ImGuiImplGl3;
|
import imgui.gl3.ImGuiImplGl3;
|
||||||
import org.lwjgl.glfw.GLFWErrorCallback;
|
import org.lwjgl.glfw.GLFWErrorCallback;
|
||||||
import org.lwjgl.glfw.GLFWVidMode;
|
import org.lwjgl.glfw.GLFWVidMode;
|
||||||
@@ -47,16 +46,16 @@ public final class ImGuiGlfwExample {
|
|||||||
// Mouse cursors provided by GLFW
|
// Mouse cursors provided by GLFW
|
||||||
private final long[] mouseCursors = new long[ImGuiMouseCursor.COUNT];
|
private final long[] mouseCursors = new long[ImGuiMouseCursor.COUNT];
|
||||||
|
|
||||||
|
// LWJGL3 rendered itself (SHOULD be initialized)
|
||||||
private final ImGuiImplGl3 imGuiGl3 = new ImGuiImplGl3();
|
private final ImGuiImplGl3 imGuiGl3 = new ImGuiImplGl3();
|
||||||
|
|
||||||
// Local app variables go here
|
// Local variables for application goes here
|
||||||
private final String imguiDemoLink = "https://raw.githubusercontent.com/ocornut/imgui/v1.74/imgui_demo.cpp";
|
private final String imguiDemoLink = "https://raw.githubusercontent.com/ocornut/imgui/v1.74/imgui_demo.cpp"; // Link to put into clipboard
|
||||||
private final byte[] testPayload = "Test Payload".getBytes();
|
private final byte[] testPayload = "Test Payload".getBytes(); // Test data for payload. Should be represented as raw byt array.
|
||||||
private String dropTargetText = "Drop Here";
|
private String dropTargetText = "Drop Here";
|
||||||
private float[] backgroundColor = new float[]{0.5f, 0, 0};
|
private float[] backgroundColor = new float[]{0.5f, 0, 0}; // To modify background color dynamically
|
||||||
private int clickCount = 0;
|
private int clickCount = 0;
|
||||||
private final ImString resizableStr = new ImString(5);
|
private final ImString resizableStr = new ImString(5);
|
||||||
|
|
||||||
private final ImBool showDemoWindow = new ImBool();
|
private final ImBool showDemoWindow = new ImBool();
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -67,7 +66,7 @@ public final class ImGuiGlfwExample {
|
|||||||
destroyGlfw();
|
destroyGlfw();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method initializes GLFW window. All code is mostly a copy-paste from the official LWJGL3 website.
|
// Method initializes GLFW window. All code is mostly a copy-paste from the official LWJGL3 "Get Started": https://www.lwjgl.org/guide
|
||||||
private void initGlfw() {
|
private void initGlfw() {
|
||||||
// Setup an error callback. The default implementation
|
// Setup an error callback. The default implementation
|
||||||
// will print the error message in System.err.
|
// will print the error message in System.err.
|
||||||
@@ -85,7 +84,7 @@ public final class ImGuiGlfwExample {
|
|||||||
glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE); // the window will be maximized
|
glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE); // the window will be maximized
|
||||||
|
|
||||||
// Create the window
|
// Create the window
|
||||||
window = glfwCreateWindow(DEFAULT_WIDTH, DEFAULT_HEIGHT, "ImGui+GLFW+LWJGL Example", NULL, NULL);
|
window = glfwCreateWindow(DEFAULT_WIDTH, DEFAULT_HEIGHT, "Dear ImGui + GLFW + LWJGL Example", NULL, NULL);
|
||||||
|
|
||||||
if (window == NULL) {
|
if (window == NULL) {
|
||||||
throw new RuntimeException("Failed to create the GLFW window");
|
throw new RuntimeException("Failed to create the GLFW window");
|
||||||
@@ -125,19 +124,18 @@ public final class ImGuiGlfwExample {
|
|||||||
// This line is critical for Dear ImGui to work.
|
// This line is critical for Dear ImGui to work.
|
||||||
ImGui.createContext();
|
ImGui.createContext();
|
||||||
|
|
||||||
// ImGui provides three different color schemas for styling. We will use the classic one here.
|
// ImGui provides 3 different color schemas for styling. We will use the classic one here.
|
||||||
|
// Try others with ImGui.styleColors*() methods.
|
||||||
ImGui.styleColorsClassic();
|
ImGui.styleColorsClassic();
|
||||||
// ImGui.StyleColorsDark(); // This is a default style for ImGui
|
|
||||||
// ImGui.StyleColorsLight();
|
|
||||||
|
|
||||||
// Initialize ImGuiIO config
|
// Initialize ImGuiIO config
|
||||||
final ImGuiIO io = ImGui.getIO();
|
final ImGuiIO io = ImGui.getIO();
|
||||||
|
|
||||||
io.setIniFilename(null);
|
io.setIniFilename(null); // We don't want to save .ini file
|
||||||
io.setConfigFlags(ImGuiConfigFlags.NavEnableKeyboard);
|
io.setConfigFlags(ImGuiConfigFlags.NavEnableKeyboard); // Navigation with keyboard
|
||||||
io.setBackendFlags(ImGuiBackendFlags.HasMouseCursors);
|
io.setBackendFlags(ImGuiBackendFlags.HasMouseCursors); // Mouse cursors to display while resizing windows etc.
|
||||||
io.setBackendPlatformName("imgui_java_impl_glfw");
|
io.setBackendPlatformName("imgui_java_impl_glfw"); // For debug purpose
|
||||||
io.setBackendRendererName("imgui_java_impl_lwjgl");
|
io.setBackendRendererName("imgui_java_impl_lwjgl"); // For debug purpose
|
||||||
|
|
||||||
// Keyboard mapping. ImGui will use those indices to peek into the io.KeysDown[] array.
|
// Keyboard mapping. ImGui will use those indices to peek into the io.KeysDown[] array.
|
||||||
final int[] keyMap = new int[ImGuiKey.COUNT];
|
final int[] keyMap = new int[ImGuiKey.COUNT];
|
||||||
@@ -175,7 +173,9 @@ public final class ImGuiGlfwExample {
|
|||||||
mouseCursors[ImGuiMouseCursor.ResizeNWSE] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
mouseCursors[ImGuiMouseCursor.ResizeNWSE] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
||||||
mouseCursors[ImGuiMouseCursor.Hand] = glfwCreateStandardCursor(GLFW_HAND_CURSOR);
|
mouseCursors[ImGuiMouseCursor.Hand] = glfwCreateStandardCursor(GLFW_HAND_CURSOR);
|
||||||
|
|
||||||
// Here goes GLFW callbacks to update user input stuff in ImGui
|
// ------------------------------------------------------------
|
||||||
|
// Here goes GLFW callbacks to update user input in Dear ImGui
|
||||||
|
|
||||||
glfwSetKeyCallback(window, (w, key, scancode, action, mods) -> {
|
glfwSetKeyCallback(window, (w, key, scancode, action, mods) -> {
|
||||||
if (action == GLFW_PRESS) {
|
if (action == GLFW_PRESS) {
|
||||||
io.setKeysDown(key, true);
|
io.setKeysDown(key, true);
|
||||||
@@ -237,6 +237,7 @@ public final class ImGuiGlfwExample {
|
|||||||
imGuiGl3.init();
|
imGuiGl3.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Main application loop
|
||||||
private void loop() {
|
private void loop() {
|
||||||
double time = 0; // to track our frame delta value
|
double time = 0; // to track our frame delta value
|
||||||
|
|
||||||
@@ -247,8 +248,9 @@ public final class ImGuiGlfwExample {
|
|||||||
final double deltaTime = (time > 0) ? (currentTime - time) : 1f / 60f;
|
final double deltaTime = (time > 0) ? (currentTime - time) : 1f / 60f;
|
||||||
time = currentTime;
|
time = currentTime;
|
||||||
|
|
||||||
// Set the clear color
|
// Set the clear color and do clear itself
|
||||||
glClearColor(backgroundColor[0], backgroundColor[1], backgroundColor[2], 0.0f);
|
glClearColor(backgroundColor[0], backgroundColor[1], backgroundColor[2], 0.0f);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
// Get window size properties and mouse position
|
// Get window size properties and mouse position
|
||||||
glfwGetWindowSize(window, winWidth, winHeight);
|
glfwGetWindowSize(window, winWidth, winHeight);
|
||||||
@@ -268,16 +270,13 @@ public final class ImGuiGlfwExample {
|
|||||||
glfwSetCursor(window, mouseCursors[imguiCursor]);
|
glfwSetCursor(window, mouseCursors[imguiCursor]);
|
||||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||||
|
|
||||||
// Clear the framebuffer
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
|
||||||
|
|
||||||
// IMPORTANT!!
|
// IMPORTANT!!
|
||||||
// Any ImGui code SHOULD go between NewFrame()/Render() methods
|
// Any Dear ImGui code SHOULD go between NewFrame()/Render() methods
|
||||||
ImGui.newFrame();
|
ImGui.newFrame();
|
||||||
showUi(); // ImGui calls goes here
|
showUi();
|
||||||
ImGui.render();
|
ImGui.render();
|
||||||
|
|
||||||
// After ImGui#render call we provide draw data into LWJGL3 render.
|
// After ImGui#render call we provide draw data into LWJGL3 renderer.
|
||||||
// At that moment ImGui will be rendered to the current OpenGL context.
|
// At that moment ImGui will be rendered to the current OpenGL context.
|
||||||
imGuiGl3.render(ImGui.getDrawData());
|
imGuiGl3.render(ImGui.getDrawData());
|
||||||
|
|
||||||
@@ -292,9 +291,14 @@ public final class ImGuiGlfwExample {
|
|||||||
ImGui.setNextWindowSize(600, 300, ImGuiCond.Once);
|
ImGui.setNextWindowSize(600, 300, ImGuiCond.Once);
|
||||||
ImGui.setNextWindowPos(10, 10, ImGuiCond.Once);
|
ImGui.setNextWindowPos(10, 10, ImGuiCond.Once);
|
||||||
|
|
||||||
ImGui.begin("Custom window", ImGuiWindowFlags.NoDecoration); // Start Custom window
|
ImGui.begin("Custom window"); // Start Custom window
|
||||||
ImGui.text("Hello from Java!");
|
|
||||||
|
|
||||||
|
// Simple text label
|
||||||
|
ImGui.checkbox("Show demo window", showDemoWindow);
|
||||||
|
|
||||||
|
ImGui.separator();
|
||||||
|
|
||||||
|
// Drag'n'Drop functionality
|
||||||
ImGui.button("Drag me");
|
ImGui.button("Drag me");
|
||||||
if (ImGui.beginDragDropSource()) {
|
if (ImGui.beginDragDropSource()) {
|
||||||
ImGui.setDragDropPayload("payload_type", testPayload, testPayload.length);
|
ImGui.setDragDropPayload("payload_type", testPayload, testPayload.length);
|
||||||
@@ -311,11 +315,13 @@ public final class ImGuiGlfwExample {
|
|||||||
ImGui.endDragDropTarget();
|
ImGui.endDragDropTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Color picker
|
||||||
ImGui.alignTextToFramePadding();
|
ImGui.alignTextToFramePadding();
|
||||||
ImGui.text("Background color:");
|
ImGui.text("Background color:");
|
||||||
ImGui.sameLine();
|
ImGui.sameLine();
|
||||||
ImGui.colorEdit3("##click_counter_col", backgroundColor, ImGuiColorEditFlags.NoInputs | ImGuiColorEditFlags.NoDragDrop);
|
ImGui.colorEdit3("##click_counter_col", backgroundColor, ImGuiColorEditFlags.NoInputs | ImGuiColorEditFlags.NoDragDrop);
|
||||||
|
|
||||||
|
// Simple click counter
|
||||||
if (ImGui.button("Click")) {
|
if (ImGui.button("Click")) {
|
||||||
clickCount++;
|
clickCount++;
|
||||||
}
|
}
|
||||||
@@ -324,14 +330,24 @@ public final class ImGuiGlfwExample {
|
|||||||
}
|
}
|
||||||
ImGui.sameLine();
|
ImGui.sameLine();
|
||||||
ImGui.text("Count: " + clickCount);
|
ImGui.text("Count: " + clickCount);
|
||||||
ImGui.checkbox("Show demo window", showDemoWindow);
|
|
||||||
ImGui.newLine();
|
|
||||||
|
|
||||||
ImGui.inputText("Resizable input", resizableStr, ImGuiInputTextFlags.CallbackResize);
|
|
||||||
ImGui.text(String.format("text len: %d | buffer size: %d", resizableStr.getLength(), resizableStr.getBufferSize()));
|
|
||||||
ImGui.newLine();
|
|
||||||
|
|
||||||
ImGui.separator();
|
ImGui.separator();
|
||||||
|
|
||||||
|
// Input field with auto-resize ability
|
||||||
|
ImGui.text("You can use text inputs with auto-resizable strings!");
|
||||||
|
ImGui.inputText("Resizable input", resizableStr, ImGuiInputTextFlags.CallbackResize);
|
||||||
|
ImGui.text("text len:");
|
||||||
|
ImGui.sameLine();
|
||||||
|
ImGui.textColored(.12f, .6f, 1, 1, Integer.toString(resizableStr.getLength()));
|
||||||
|
ImGui.sameLine();
|
||||||
|
ImGui.text("| buffer size:");
|
||||||
|
ImGui.sameLine();
|
||||||
|
ImGui.textColored(1, .6f, 0, 1, Integer.toString(resizableStr.getBufferSize()));
|
||||||
|
|
||||||
|
ImGui.separator();
|
||||||
|
ImGui.newLine();
|
||||||
|
|
||||||
|
// Link to the original demo file
|
||||||
ImGui.text("Consider to look the original ImGui demo: ");
|
ImGui.text("Consider to look the original ImGui demo: ");
|
||||||
ImGui.setNextItemWidth(500);
|
ImGui.setNextItemWidth(500);
|
||||||
ImGui.textColored(0, .8f, 0, 1, imguiDemoLink);
|
ImGui.textColored(0, .8f, 0, 1, imguiDemoLink);
|
||||||
|
|||||||
Reference in new issue
Block a user