cimgui-go Documentation

repository·main·Indexed 19 days ago

https://github.com/allendang/cimgui-go

A Go wrapper for the Dear ImGui library, providing Go bindings for ImGui and plugins such as ImPlot and ImNodes. It includes multiple backends, including GLFW, SDL2, and Ebitengine. The project also features a codegen CLI tool for generating Go bindings for C projects based on JSON configurations and a markdown rendering component called imgui_markdown.

Tokens
116K
Snippets
344
Records
565
Agent score
67%

What's inside cimgui-go

  1. Overview of HIDAPI back-ends and platform support

    main

    HIDAPI is a multi-platform library for interfacing with USB and Bluetooth HID-Class devices. It supports Windows, Linux, FreeBSD, and Mac OS X.

    Supported Back-ends

    • Windows: Uses hid.dll.
    • Linux/hidraw: Uses the kernel's hidraw driver. Supports both USB and Bluetooth. Note that keyboards, mice, and certain blacklisted devices may not work. Older kernels (< 2.6.39) may lack feature report support.
    • Linux/libusb: Uses libusb-1.0. Supports USB only (no Bluetooth).
    • FreeBSD: Uses libusb-1.0.
    • Mac OS X: Uses IOHidManager.
  2. Introduction to GLFW

    main

    GLFW is an open-source, multi-platform library designed for developing applications using OpenGL, OpenGL ES, and Vulkan. It provides a platform-independent API for:

    • Creating windows, contexts, and surfaces
    • Reading input
    • Handling events

    Supported platforms include Windows, macOS, and Linux (with support for both Wayland and X11 on Linux).

  3. Overview of ImGuiColorTextEdit features

    main

    ImGuiColorTextEdit is a syntax highlighting text editor and text diff tool for Dear ImGui. Key capabilities include:

    • Syntax Highlighting: Extendable for multiple languages via a custom API.
    • Editing Features: Full undo/redo, multiple cursors/selections, auto-indent, and auto-completion for paired glyphs.
    • UI Enhancements: Word wrap, line folding (brackets and indentation), minimaps, and a find/replace interface.
    • Advanced API: Marker API for highlighting lines/tooltips, line decoration (for debuggers/IDEs), and user data attachment to lines.
    • Filtering: API to filter selections (e.g., uppercase/lowercase) or entire lines (e.g., Tabs to Spaces).
    • Compatibility: Works with latest Dear ImGui (v1.92.8+), supports UTF-8, and is C++17 based.
  4. What is Simple DirectMedia Layer (SDL)?

    main

    Simple DirectMedia Layer (SDL) is a cross-platform development library that provides low-level access to hardware components including:

    • Audio
    • Keyboard
    • Mouse
    • Joystick
    • Graphics hardware (via OpenGL and Direct3D)

    It is designed for use in video playback software, emulators, and games. SDL is written in C and works natively with C++, but bindings exist for other languages like C# and Python.

  5. Overview of ImGuizmo widgets

    main

    ImGuizmo provides a collection of Dear ImGui-based widgets for 3D manipulation and specialized editing tasks. Each widget is designed as a standalone component. Available widgets include:

    • ImViewGizmo: Used to manipulate view orientation.
    • ImGuizmo: A library for manipulating 4x4 float matrices (rotation, translation, and scale) using the Immediate Mode philosophy.
    • ImSequencer: A timeline sequencer for editing frame start/end ranges across multiple events.
    • GraphEditor: A node graph editor featuring connections and a delegate system for custom node rendering.
    • ImVectorEditor: A 2D vector geometry path editor supporting pen tools, anchor/handle editing, and open/closed paths. It supports host-provided transforms that compose with ImGuizmo object manipulation.
  6. What is Dear ImGui and when to use it

    main

    Dear ImGui is a bloat-free, fast, and portable graphical user interface library for C++. It is designed for content creation tools and visualization/debug tools rather than consumer-facing UIs. It outputs optimized vertex buffers that can be rendered within your existing 3D pipeline.

    Key Characteristics:

    • Renderer Agnostic: It doesn't touch your GPU directly; it provides vertex buffers and command lists for you to render.
    • Self-Contained: No external dependencies.
    • Immediate Mode: Minimizes state synchronization and UI-related state storage on the user side.
    • Target Use Cases: Game engine tooling, real-time 3D applications, fullscreen/embedded applications, and console platforms.

    Limitations:

    • Does not support full internationalization (RTL, bidirectional text, text shaping).
    • Does not support accessibility features.
  7. Run SDL applications via Microsoft GDK

    main

    This port enables SDL applications to run using Microsoft's Game Development Kit (GDK). It supports both Windows (GDK) and Xbox One/Xbox Series (GDKX).

    Note on Xbox: While the code is included in this release, you must be a licensed Xbox developer to access the GDKX libraries required to build for Xbox targets.

  8. Use TextEditor addons: Autocomplete and LSP

    main

    The ImGuiColorTextEdit widget supports two primary addons to enhance text editing capabilities:

    1. Simple trie-based autocomplete: Provides basic autocomplete functionality using a trie data structure.
    2. Language server bridge (LSP): Provides advanced language intelligence by bridging the editor to a Language Server Protocol (LSP) implementation.

    Detailed implementation and usage instructions for these addons can be found in their respective documentation files: ../docs/autocomplete.md and ../docs/lsp.md.

  9. Manage window closing and the close flag

    main

    When a user attempts to close a window (e.g., via Alt+F4 or a close widget), GLFW sets a close flag on the window. The window is not immediately destroyed. You can check this flag using glfwWindowShouldClose and use it as a condition for your main loop.

    To intercept a close request (for example, to show a 'Save changes?' dialog), set a close callback with glfwSetWindowCloseCallback. Inside the callback, you can call glfwSetWindowShouldClose(window, GLFW_FALSE) to cancel the close request.

    while (!glfwWindowShouldClose(window))
    {
        render(window);
    
        glfwSwapBuffers(window);
        glfwPollEvents();
    }
  10. Handle High-DPI and Retina Displays in SDL on iOS

    main

    On iOS, SDL uses "screen coordinates" (points) rather than pixels. For example, an iPhone 6 uses 375x667 points, even though its pixel resolution is 750x1334.

    Enabling High-DPI

    By default, SDL does not use the full pixel density. To enable high-DPI support, use the SDL_WINDOW_ALLOW_HIGHDPI flag when creating your window.

    Querying Sizes

    • SDL_GetWindowSize() and display mode sizes return screen coordinates.
    • To get the actual pixel dimensions of the framebuffer (for OpenGL or SDL_Renderer), use SDL_GL_GetDrawableSize() or SDL_GetRendererOutputSize().

    Rendering Tip

    When using OpenGL ES, you can use an orthographic projection matrix with screen coordinates (from SDL_GetWindowSize()) to ensure content scales correctly across different pixel densities.

  11. Generate a package based on a reference package

    main

    If you are generating a plugin or a secondary package that depends on symbols from a primary package (e.g., generating an ImPlot package that uses ImGui symbols), use the reference flags.

    By providing the JSON files of the primary package via --ref-enums and --ref-typedefs, and specifying its package name via --ref-pkg, the generator will use the existing Go symbols from the primary package instead of trying to re-generate them in the new package.

  12. Understand the role of Dear ImGui Backends

    main

    Dear ImGui is a core library that handles UI logic, but it does not handle platform-specific input or graphics rendering directly. To use it, you must integrate it with Backends.

    Core Requirements

    To run Dear ImGui, a backend must provide:

    1. Input: Mouse and keyboard inputs (fed into the ImGuiIO structure).
    2. Texture Management: Creating, updating, and destroying textures.
    3. Rendering: Rendering indexed textured triangles with a clipping rectangle.

    Backend Types

    Backends are generally categorized into two types:

    • Platform Backends: Responsible for mouse/keyboard/gamepad inputs, cursor shapes, timing, and windowing (e.g., Win32, SDL3, GLFW).
    • Renderer Backends: Responsible for creating the atlas texture and rendering the ImGui draw data (e.g., DirectX11, OpenGL3, Vulkan).

    For high-level frameworks, a single backend might handle both Platform and Renderer responsibilities (e.g., Allegro 5).