imgui_touch: a touch screen for Dear ImGui, as on a phone: the swipe, the long press, the pinch, the phone’s
keyboard. Set it up once, after imgui.create_context(): imgui_touch.setup(). An app run by Hello ImGui needs no
call (its setting: hello_imgui.RunnerParams.touch_config).
The C++ API of imgui_touch: the signatures and the documentation of its headers. This page is generated by litgen, the engine behind the Python bindings of Dear ImGui Bundle. Functions without Python bindings are not listed.
imgui_touch.h¶
Touch¶
ImGuiTouchScrollMode_ (enum)¶
enum ImGuiTouchScrollMode_Whether a finger that drags the content of a window scrolls it (the swipe)
| Member | Value | |
|---|---|---|
ImGuiTouchScrollMode_Auto | 0 | only when the input is a touch screen (io.MouseSource) |
ImGuiTouchScrollMode_Always | 1 | also with the mouse (left button): to try the phone’s behavior on a desktop |
ImGuiTouchScrollMode_Disabled, } | 2 |
ImGuiTouchAxis_ (enum)¶
enum ImGuiTouchAxis_The direction in which a widget takes a finger’s drags (ImGuiTouch::SetItemTakesDrags); the values of Dear ImGui’s internal ImGuiAxis
| Member | Value | |
|---|---|---|
ImGuiTouchAxis_Any = -1 | -1 | every direction, at once: a canvas, a knob, a plot |
ImGuiTouchAxis_X = 0 | 0 | a slider |
ImGuiTouchAxis_Y = 1 | 1 | a vertical slider |
ImGuiTouchPinchDelivery_ (enum)¶
enum ImGuiTouchPinchDelivery_How a pinch reaches a widget as wheel events (ImGuiTouch::SetItemPinchAsWheel)
| Member | Value | |
|---|---|---|
ImGuiTouchPinchDelivery_WheelContinuous | 0 | the exact amount at each frame: a widget that zooms by the wheel’s |
ImGuiTouchPinchDelivery_WheelNotches | 1 | whole notches (+1, -1): a widget that reads only the wheel’s sign |
ImGuiTouchPinchKind_ (enum)¶
enum ImGuiTouchPinchKind_What two fingers do, as the layer decides it once per gesture (ImGuiTouchPinch::Kind)
| Member | Value | |
|---|---|---|
ImGuiTouchPinchKind_Undecided | 0 | until their distance changed a little, or their middle moved a little |
ImGuiTouchPinchKind_Pinch | 1 | they spread or close |
ImGuiTouchPinchKind_Pan | 2 | they move together |
ImGuiTouchPinch (struct)¶
struct ImGuiTouchPinchTwo fingers on a widget, at this frame (ImGuiTouch::ItemPinch). A widget applies both the zoom and the pan at each frame: the content stays under the fingers, as on a map. ImGuiTouchPinch p = ImGuiTouch::ItemPinch(); if (p.Active)
| Member | |
|---|---|
bool Active; | two fingers are on this widget’s gesture (False: the deltas are neutral) |
bool Started; | the gesture’s first frame |
bool Ended; | the fingers lifted (or were cancelled) since the last frame: Active is False then |
ImVec2 Center; | the fingers’ middle, in screen coordinates |
ImVec2 CenterDelta; | its move since the last frame: the pan |
float ScaleDelta; | the fingers’ distance over the last frame’s: 1 when unchanged |
float Scale; | their distance over the distance at the start: 1 at the start |
ImGuiTouchPinchKind Kind; | pinch or pan, for a widget that wants one at a time |
ImGuiTouchPinch::ImGuiTouchPinch¶
ImGuiTouchPinch() : Active(false), Started(false), Ended(false), ScaleDelta(1.0f), Scale(1.0f), Kind(ImGuiTouchPinchKind_Undecided);ImGuiTouchPhase_ (enum)¶
enum ImGuiTouchPhase_The phase of a finger, as the platforms report it (ImGuiTouch::AddFingerEvent)
| Member | Value | |
|---|---|---|
ImGuiTouchPhase_Began | 0 | the finger landed |
ImGuiTouchPhase_Moved | 1 | it is still down (moved or not) |
ImGuiTouchPhase_Ended | 2 | it lifted |
ImGuiTouchPhase_Cancelled | 3 | the system took the touch over (a system gesture, a call): it lifted, and its press |
ImGuiTouchKeyboardInsets (struct)¶
struct ImGuiTouchKeyboardInsetsThe parts of the screen hidden by a phone’s keyboard: see ImGuiTouch::GetKeyboardInsets(). Top and Bottom are
distances inward from the display’s top and bottom edges, in Dear ImGui’s coordinates: the visible part is
[Top, io.DisplaySize.y - Bottom]. Zero when no keyboard shows.
| Member | |
|---|---|
float Top; | |
float Bottom; |
ImGuiTouchKeyboardInsets::ImGuiTouchKeyboardInsets¶
ImGuiTouchKeyboardInsets(float top = 0.0f, float bottom = 0.0f) : Top(top), Bottom(bottom);ImGuiTouchConfig (struct)¶
struct ImGuiTouchConfigThe settings, read at each frame: change them through ImGuiTouch::GetConfig()
| Member | |
|---|---|
ImGuiTouchScrollMode ScrollMode = ImGuiTouchScrollMode_Auto; | |
float HoldSeconds = 0.15f; | |
bool LongPressIsRightClick = true; | |
float LongPressSeconds = 0.5f; | iOS: about 500 ms |
bool ThinScrollbars = true; | |
bool PinchScalesFont = true; | |
float PinchFontScaleMin = 0.5f; | |
float PinchFontScaleMax = 5.0f; | |
bool SimulateTouch = false; |
ImGuiTouch::Setup¶
IMGUI_API void Setup(const ImGuiTouchConfig& config = ImGuiTouchConfig());Installs the touch layer in the current Dear ImGui context. Call once, after ImGui::CreateContext(); a later call replaces the config. Its state is freed with the context. The functions a reusable widget calls (they say so) do nothing without it; the others assert.
ImGuiTouch::IsInstalled¶
IMGUI_API bool IsInstalled();True once a setup was called in the current context
ImGuiTouch::GetConfig¶
IMGUI_API ImGuiTouchConfig& GetConfig();See it live: Gestures
Code from the demo
ImGuiTouchConfig& config = ImGuiTouch::GetConfig();ImGuiTouch::IsAnimating¶
IMGUI_API bool IsAnimating();See it live: Gestures
Code from the demo
ImGui::Text("Moving on its own: %s", ImGuiTouch::IsAnimating() ? "yes" : "no");True while the touch layer moves something on its own (a fling’s inertia, the bounce, a long press’s ring): an app that sleeps when nothing happens keeps drawing frames meanwhile. False without the touch layer.
ImGuiTouch::SetItemTakesDrags¶
IMGUI_API void SetItemTakesDrags(ImGuiTouchAxis axis = ImGuiTouchAxis_Any, bool long_press_is_right_click = true);See it live: Gestures
Code from the demo
static float row_value = 0.5f;
ImGui::SetNextItemWidth(card_width);
ImGui::SliderFloat("##row_slider", &row_value, 0.0f, 1.0f);
ImGuiTouch::SetItemTakesDrags(ImGuiTouchAxis_X);Right after a widget that a finger drags: a drag that starts on it goes to it, not to the swipe.
ImGuiTouchAxis_Any (a canvas, a knob, a plot): the widget gets the press at once, in every direction.
ImGuiTouchAxis_X or _Y (a slider, a vertical slider): the layer waits until the finger moved a little, then gives the drag to the widget if it goes along that axis, or scrolls the window if it goes across. long_press_is_right_click: a long press on it is still a right click. Nothing without the touch layer.
Dear ImGui’s own sliders and drags call it themselves when the build has IMGUI_HAS_ITEM_DRAG_AXIS_CALLBACK.
ImGuiTouch::ItemPinch¶
IMGUI_API ImGuiTouchPinch ItemPinch();See it live: Gestures
Two fingers on a widget: by default they scale the font (a pinch) or are a right drag (moved together). A widget changes that with one of these calls, right after it, at each frame, hovered or not (the claims of the last frame decide where the fingers land, and there is no mouse between two touches). When claims nest, the smallest holding both fingers wins; the gesture stays with it until they lift. Nothing without the touch layer.
The gesture itself (a canvas, a map): returns its data at this frame. The widget gets nothing else: no font scale, no wheel, no mouse drag. The item needs an id (an InvisibleButton, not an Image). Not with 2 or 3.
ImGuiTouch::RectPinch¶
IMGUI_API ImGuiTouchPinch RectPinch(ImGuiID id, const ImVec2& min, const ImVec2& max);The same, for a rectangle in screen coordinates and an id of the caller’s: a widget that is not one item
ImGuiTouch::SetItemPinchAsWheel¶
IMGUI_API void SetItemPinchAsWheel(float wheel_zoom_factor, ImGuiTouchPinchDelivery delivery = ImGuiTouchPinchDelivery_WheelContinuous);A widget that zooms with the wheel (a plot, an image): a pinch on it becomes wheel events, at the fingers’ center. wheel_zoom_factor: the widget’s zoom for one wheel unit (1.1: +10%). delivery: WheelNotches for a widget that reads only the wheel’s sign (ImPlot).
ImGuiTouch::SetRectPinchAsWheel¶
IMGUI_API void SetRectPinchAsWheel(const ImVec2& min, const ImVec2& max, float wheel_zoom_factor, ImGuiTouchPinchDelivery delivery = ImGuiTouchPinchDelivery_WheelContinuous, ImGuiID id = 0);ImGuiTouch::SetItemTwoFingerPanAsMouseDrag¶
IMGUI_API void SetItemTwoFingerPanAsMouseDrag(ImGuiMouseButton button);A widget that pans with a mouse button (a plot: left; a node editor: right): two fingers moved together on it become a drag with that button. Combines with 2. Alone, a pinch on the widget does nothing (the font keeps its size); with 2 alone, two fingers moved together are a right drag.
ImGuiTouch::SetRectTwoFingerPanAsMouseDrag¶
IMGUI_API void SetRectTwoFingerPanAsMouseDrag(const ImVec2& min, const ImVec2& max, ImGuiMouseButton button, ImGuiID id = 0);ImGuiTouch::PushClaimTransform¶
IMGUI_API void PushClaimTransform(float scale, const ImVec2& offset);The rectangle’s id (optional): the widget’s item that the first finger may hold when the second one lands (a canvas’s background); the gesture takes that press over, as with the item’s calls. Otherwise a widget that holds the press keeps it, and the two fingers do nothing.
A canvas that shows its widgets zoomed and moved (a node editor) wraps them in these, so that their claims (above, and SetItemTakesDrags) are where the widgets show: on screen, local * scale + offset. Nests. The gesture’s data (ItemPinch) stays in screen coordinates. Nothing without the touch layer.
ImGuiTouch::PopClaimTransform¶
IMGUI_API void PopClaimTransform();ImGuiTouch::AddFingerEvent¶
IMGUI_API void AddFingerEvent(int id, const ImVec2& pos, ImGuiTouchPhase phase);A finger on a touch screen, as the platform reports it: its id (any number the platform gives, stable while the
finger is down), its position (in the mouse’s coordinates), and its phase. Report every finger, the first one
included: Dear ImGui sees only the first finger, as the mouse; these events let the layer see the others. With two
fingers down: they spread or close, a pinch; they move together, a right drag. A desktop app with a mouse never
calls it. The platforms’ phases: iOS (UITouchPhase), Android (ACTION_DOWN, _MOVE, _UP, _CANCEL), SDL (finger down,
motion, up, and canceled in SDL3), Windows (WM_POINTER, its canceled flag). GLFW reports no fingers.
Cancelled: the system took the touch over. The finger lifts, and the press it made ends with no click (a widget
under it is not clicked, a swipe does not fling).
ImGuiTouch::GetKeyboardInsets¶
IMGUI_API ImGuiTouchKeyboardInsets GetKeyboardInsets();See it live: Keyboard

The parts of the screen hidden by a phone’s keyboard (in Dear ImGui’s coordinates): a full-screen window keeps out of them. Zero when no keyboard shows, and without the touch layer.
ImGuiTouch::SetKeyboardInsets¶
IMGUI_API void SetKeyboardInsets(const ImGuiTouchKeyboardInsets& insets);A native app tells where its keyboard is (iOS: UIKeyboardWillChangeFrameNotification), and zero when it hides: the
values stay until the next call. While a keyboard shows, the windows that hold the text field scroll its caret
into view, above the keyboard. In a browser, SetupEmscriptenKeyboard() sets them (zero included). It works before
Setup() too: a native app may report its keyboard first.
ImGuiTouch::SetItemOpensUrl¶
IMGUI_API bool SetItemOpensUrl(const char* url);A link that opens in a new tab, in a browser, whatever the browser and the pointer. Right after the link’s item, at
each frame. The page opens the url from inside the tap’s or the click’s own handler, where every browser allows a
new tab (WebKit allows none from the frame loop, where Dear ImGui sees the click). A finger: a tap (lifted within
half a second, not moved); a mouse: a press and its release on the link.
Returns True when the page takes the link: the caller then does nothing on the click. False outside a browser,
without SetupEmscripten(), or for a scheme other than http, https and mailto: the caller opens the url itself.
ImGui::TextLink(“Read the docs”);
if (!ImGuiTouch::SetItemOpensUrl(url) && ImGui::IsItemClicked())
OpenInBrowser(url);
The same, for a rectangle in screen coordinates (a link that is not one item).
ImGuiTouch::SetRectOpensUrl¶
IMGUI_API bool SetRectOpensUrl(const ImVec2& min, const ImVec2& max, const char* url);Demo¶
ImGuiTouch::ShowDemoWindow¶
IMGUI_API void ShowDemoWindow(bool* p_open = nullptr);The touch layer’s demo window, as ImGui::ShowDemoWindow(): a list to swipe, sliders, a pinch on a canvas, a text field for the phone’s keyboard. Removed by IMGUI_TOUCH_DISABLE_DEMO.
ImGuiTouch::ShowDemoContents¶
IMGUI_API void ShowDemoContents();The demo’s content, in the current window (a host that places the window itself: a phone’s full screen)
}