# imgui_kit, for AI assistants

imgui_kit adds small, standalone helpers to Dear ImGui (C++, 1.93 or later, docking or master; MIT): layout helpers, a few widgets, em units, and a mouse wheel that stays with the window it scrolls. Repository: https://github.com/pthom/imgui_kit

## Where the truth is

- `imgui_kit.h`: the whole API, one header, by `[SECTION]`: Em units, Layout, Widgets, Wheel session, Idling, Enums. Each function has its doc comment there. Read it to check that a name exists and how to call it.
- `imgui_kit_demo.cpp`: a section per helper (its `IMGUI_DEMO_MARKER`), the usual way to call each one.
- Live, with its code beside it: https://pthom.github.io/imgui_explorer/?lib=imguikit (a section: `&demo=Layout%2FFill%20row`).

## Build

Copy `imgui_kit*.h` and `imgui_kit*.cpp` beside Dear ImGui (leave out `imgui_kit_demo.cpp`, or define `IMGUI_KIT_DISABLE_DEMO`), or with CMake: `add_subdirectory(imgui_kit)` then link `imgui_kit` (it uses an existing `imgui` target). C++11, no STL in the core.

## Layout and widgets (namespace ImGuiKit)

- Sizes in em, which follow the font: `EmSize()`, `EmToVec2(w, h)`. Prefer them to pixels.
- Begin/End pairs: `BeginFillRow` / `FillRowTail` / `EndFillRow` (a widget fills the line, the items after the tail stay on the right), `BeginLabelColumn` / `Label` / `EndLabelColumn`, `BeginAlignedGroup` (right or centered), `BeginColumn`, `BeginGroupPanel`, `BeginFlow` (items that wrap).
- The layout helpers measure their parts on the previous frame: the first frame draws them hidden. Call them at each frame, with a stable id.
- Widgets: `HelpMarker` (an (i): a tooltip on hover, a popup on a click or a tap), `IconButton`, `SegmentedSwitch`, `FitText`, `ResizeHandle`.

## The wheel session (ImGuiKit::SetupWheelSession)

Set up once, after `ImGui::CreateContext()`; it then runs at each frame through Dear ImGui's context hooks: `ImGuiKit::SetupWheelSession();` (the wheel stays with the window it scrolls).

The traps:
- A widget that reads the wheel claims it while hovered: `if (ImGui::SetItemKeyOwner(ImGuiKey_MouseWheelY)) ...`. Otherwise the wheel session gives the wheel to the window that scrolls.
- An app that sleeps when idle keeps drawing while `ImGuiKit::IsAnimating()` is true (the kit's widgets' animations). A widget of yours that animates calls `ImGuiKit::RequestAnimation()` at each frame of its animation.
- With Dear ImGui's Test Engine: set the kit up before `ImGuiTestEngine_Start()` (hooks run in the order they were added).
- Hello ImGui sets it up itself: its setting is `RunnerParams::wheelSession`.

Touch screens (the swipe, the long press, the pinch, the phone's keyboard) are in their own library: https://github.com/pthom/imgui_touch

## Python

Dear ImGui Bundle binds the kit as `imgui_bundle.imgui_kit` (snake_case names; each Begin/End pair is also a context manager, e.g. `with imgui_kit.fill_row("id") as row:`). Its guide for AI assistants: https://imgui-bundle.pages.dev/llms.txt, and the kit's API in plain text: https://imgui-bundle.pages.dev/llms/api/imgui_kit.txt
