Dear ImGui API: Difference between revisions

From GiderosMobile
wip
 
(37 intermediate revisions by the same user not shown)
Line 4: Line 4:
GitHub '''https://github.com/MultiPain/Gideros_ImGui'''
GitHub '''https://github.com/MultiPain/Gideros_ImGui'''


= Main =
== Constructor ==
== Constructor ==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
Line 21: Line 20:


'''Functions''':
'''Functions''':
Settings/.Ini Utilities
* The disk functions are automatically called if io.IniFilename != NULL (default is "imgui.ini").
* Set io.IniFilename to NULL to load/save manually. Read io.WantSaveIniSettings description about handling .ini saving manually.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
IO:setFontDefault(font)
IO:setFontDefault(font)
Line 28: Line 31:
ImGuiBackendFlag = IO:getBackendFlags()
ImGuiBackendFlag = IO:getBackendFlags()
IO:setBackendFlags(ImGui.BackendFlag)
IO:setBackendFlags(ImGui.BackendFlag)
number = IO:getIniSavingRate()
number = IO:getIniSavingRate()
IO:setIniSavingRate(number)
IO:setIniSavingRate(number)
string = IO:getIniFilename()
string = IO:getIniFilename()
IO:setIniFilename(string)
IO:setIniFilename(string)
IO:saveIniSettings([path]) -- if path is not defined it uses default path, which is set by IO:setIniFilename()
IO:saveIniSettings([path]) -- if path is not defined the it uses default path, which is set by IO:setIniFilename()
IO:loadIniSettings([path])
IO:loadIniSettings([path])
string = IO:getLogFilename()
string = IO:getLogFilename()
IO:setLogFilename(string)
IO:setLogFilename(string)
number = IO:getMouseDoubleClickTime()
number = IO:getMouseDoubleClickTime()
IO:setMouseDoubleClickTime(number)
IO:setMouseDoubleClickTime(number)
Line 50: Line 51:
number = IO:getKeyRepeatRate()
number = IO:getKeyRepeatRate()
IO:setKeyRepeatRate(number)
IO:setKeyRepeatRate(number)
number = IO:getFontGlobalScale()
number = IO:getFontGlobalScale()
IO:setFontGlobalScale(number)
IO:setFontGlobalScale(number)
Line 85: Line 85:
x, y = IO:getMouseDelta()
x, y = IO:getMouseDelta()
number = IO:getMouseDownSec(mouse_button)
number = IO:getMouseDownSec(mouse_button)
IO:setDisplaySize(w, h)
IO:setDisplaySize(w, h)
w, h = IO:getDisplaySize()
w, h = IO:getDisplaySize()
number = IO:getDeltaTime()
number = IO:getDeltaTime()
IO:resetMouseDown() -- reset mouse buttons state
-- reset mouse buttons state
IO:resetKeysDown() -- reset key states (including ALT/SHIFT/CTRL/SUPER (META))
IO:resetMouseDown()
IO:setModKeyDown(key_code, bool) -- set ALT/SHIFT/CTRL/SUPER (META) key state ("key_code" is a gideros MOD key)
-- reset key states (including ALT/SHIFT/CTRL/SUPER (META))
IO:setKeysDown(key_code, bool) -- set any key state ("key_code" is a Gideros regular "keyCode")
IO:resetKeysDown()
IO:addInputCharactersUTF8(text) -- adds text to active text input widget
-- set ALT/SHIFT/CTRL/SUPER (META) key state
IO:setMouseWheel(number) -- emulate wheel scrolling
IO:setModKeyDown(key_code, bool) -- "key_code" is a gideros MOD key
IO:setMousePos(x, y) -- sets mouse position (data only, no visual changes)
-- set any key state
IO:setMouseDown(mouse_button, state) -- set mouse state, where index: 0 - left mouse, 1 - right, 2 - middle, 3 - unused, 4 - unused ("mouse_button" is a Gideros mouse button code)
IO:setKeysDown(key_code, bool) -- "key_code" is a gideros regular "keyCode"
-- adds text to active text input widget
IO:addInputCharactersUTF8(text)
-- emulate wheel scrolling
IO:setMouseWheel(number)
-- sets mouse position (data only, no visual changes)
IO:setMousePos(x, y)
-- set mouse state, where index: 0 - left mouse, 1 - right, 2 - middle, 3 - unused, 4 - unused.
IO:setMouseDown(mouse_button, state) -- "mouse_button" is a gideros mouse button code


IO:addKeyEvent(key, down) -- "key" is any ImGui KeyCode (check keyboard-keys), "down" is a boolean
-- "key" is any ImGui KeyCode (check [here](#keyboard-keys))
IO:addKeyAnalogEvent(key, down, number) -- "key" is any ImGui KeyCode (check keyboard-keys), "down" is a boolean
-- "down" is a boolean
IO:addMousePosEvent(x, y)
IO:addKeyEvent(key, down)
IO:addMouseButtonEvent(button, down) -- "button" is any ImGui button (check MouseButton), "down" is a boolean
IO:addKeyAnalogEvent(key, down, number)
IO:AddMousePosEvent(x, y)
-- "button" is any ImGui button (check [here](#MouseButton))
IO:addMouseButtonEvent(button, down)
IO:addMouseWheelEvent(x, y)
IO:addMouseWheelEvent(x, y)


Line 206: Line 216:
</syntaxhighlight>
</syntaxhighlight>


== DEFAULT STYLES ==
=== DEFAULT STYLES ===
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
ImGui:setDarkStyle()
ImGui:setDarkStyle()
Line 226: Line 236:
</syntaxhighlight>
</syntaxhighlight>


== Demos ==
=== Demos ===
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
is_openFlag = ImGui:showUserGuide()
is_openFlag = ImGui:showUserGuide()
Line 239: Line 249:
</syntaxhighlight>
</syntaxhighlight>


== Windows ==
* Begin() = push window to the stack and start appending to it. End() = pop window from the stack.
* You may append multiple times to the same window during the same frame.
* Passing bool* p_open != NULL shows a window-closing widget in the upper-right corner of the window, which clicking will set the boolean to false when clicked.
* Begin() return false to indicate the window is collapsed or fully clipped, so you may early out and omit submitting anything to the window. Always call a matching End() for each Begin() call, regardless of its return value! [Important: due to legacy reason, this is inconsistent with most other functions such as BeginMenu / EndMenu, BeginPopup / EndPopup, etc. where the EndXXX call should only be called if the corresponding BeginXXX function returned true. Begin and BeginChild are the only odd ones out. Will be fixed in a future update.]
* Note that the bottom of window stack always contains a window called "Debug".


<syntaxhighlight lang="lua">
p_open, draw = ImGui:beginWindow(label, p_open [, ImGui.WindowFlags = 0])
-- do not show "X" button
draw = ImGui:beginWindow(label, nil [, ImGui.WindowFlags = 0])
-- start a window with no borders, no paddings, no rounding and ImGui.WindowFlags_Fullscreen flag
p_open, draw = ImGui:beginFullScreenWindow(label, p_open [, ImGui.WindowFlags = 0])
-- do not show "X" button
draw = ImGui:beginFullScreenWindow(label, nil [, ImGui.WindowFlags = 0])
ImGui:endWindow()
</syntaxhighlight>


=== Child Windows ===
Use child windows to begin into a self-contained independent scrolling/clipping regions within a host window. Child windows can embed their own child. For each independent axis of size:
* == 0.0f -> use remaining host window size
* > 0.0f -> fixed size
* < 0.0f -> use remaining window size minus abs(size) Each axis can use a different mode, e.g. ImVec2(0,400). BeginChild() returns false to indicate the window is collapsed or fully clipped, so you may early out and omit submitting anything to the window.


'''Tip'''
Always call a matching EndChild() for each BeginChild() call, regardless of its return value [as with Begin: this is due to legacy reason and inconsistent with most BeginXXX functions apart from the regular Begin() which behaves like BeginChild().]


<syntaxhighlight lang="lua">
ImGui:beginChild(id [, w = 0, h = 0, borderFlag = false, ImGui.WindowFlags = 0])
ImGui:endChild()
</syntaxhighlight>


=== Windows Utilities ===
* Current window = the window we are appending into while inside a Begin() / End() block.
* Next window = next window we will Begin() into.


* Prefer using SetNextXXX functions (before Begin) rather than SetXXX functions (after Begin()).


<syntaxhighlight lang="lua">
flag = ImGui:isWindowAppearing()
flag = ImGui:isWindowCollapsed()
flag = ImGui:isWindowFocused([ImGui.FocusedFlags = 0])
flag = ImGui:isWindowHovered([ImGui.HoveredFlags = 0])
x, y = ImGui:getWindowPos()
w, h = ImGui:getWindowSize()
w = ImGui:getWindowWidth()
h = ImGui:getWindowHeight()
x1,y1, x2,y2 = ImGui:getWindowBounds() -- returns window region rectangle in global coordinates


ImGui:setNextWindowPos(x, y [, ImGui.Cond = 0, pivotX = 0, pivotY = 0])
ImGui:setNextWindowSize(w, h [, ImGui.Cond = 0])
ImGui:setNextWindowContentSize(w, h)
ImGui:setNextWindowCollapsed(flag [, ImGui.Cond = 0])
ImGui:setNextWindowFocus()
ImGui:setNextWindowBgAlpha(alpha)
ImGui:setNextWindowScroll(x, y)
ImGui:setWindowPos(name, x, y [, ImGui.Cond = 0]) OR ImGui:setWindowPos(x, y [, ImGui.Cond = 0])
ImGui:setWindowSize(name, w, h [, ImGui.Cond = 0]) OR ImGui:setWindowSize(w, h [, ImGui.Cond = 0])
ImGui:setWindowCollapsed(name, flag [, ImGui.Cond = 0]) OR ImGui:setWindowCollapsed(flag [, ImGui.Cond = 0])
ImGui:setWindowFocus(name) OR ImGui:setWindowFocus()
ImGui:setWindowFontScale(scale)
-- scroll window when touching void
ImGui:scrollWhenDragging(x, y)
</syntaxhighlight>


'''☠️Note: because Dear ImGui is an Immediate Mode GUI framework, functions that fetch window properties (like scrolling, window sizes, or content regions) internally query the "current window" pointer. If ImGui:begin() hasn't been called yet, or if ImGui:end() was already called, that pointer is NULL, causing a fatal segmentation fault/crash'''


 
=== Window size constraints ===
 
Can be used to set minimum and maximum window size, plus contraint the size if needed.
 
 
 
 
 
== EXPERIMENTAL ==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
p_open = ImGui:showLog(title, p_open [, ImGui.WindowFlags = 0]) -- draw log window
-- call this function before ImGui:beginWindow()
ImGui:writeLog(text)
ImGui:setNextWindowSizeConstraints(min_w, min_h, max_w, max_h [, resize_callback, user_data]))
-- resizeCallback is a function:
function (callbackData [, user_data])
-- do some math, and return desired size
-- ...
return desired_width, desired_height
end
</syntaxhighlight>
</syntaxhighlight>


Gestures (touch only, turned OFF by default) ''WIP'':
'''Resize callback''':
* tap gesture (Left Mouse Button)
* hold gesture (Right Mouse Button)
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
ImGui:setTouchGesturesEnabled(bool)
-- get window position
bool = ImGui:isTouchGesturesEnabled()
x, y = callbackData:getPos()
</syntaxhighlight>
x = callbackData:getX()
 
y = callbackData:getY()
 
 
 


-- get currrent size
current_width, current_height = callbackData:getCurrentSize()
current_width = callbackData:getCurrentWidth()
current_height = callbackData:getCurrentHeight()


-- get desired size
desired_width, desired_height = callbackData:getDesiredSize()
desired_width = callbackData:getDesiredWidth()
desired_height = callbackData:getDesiredHeight()
</syntaxhighlight>


'''Example''':
<syntaxhighlight lang="lua">
require "ImGui"


local function stepSize(callback_data, step)
local w, h = callback_data:getDesiredSize()
w = (w // step) * step
h = (h // step) * step
return w, h
end


local ui = ImGui.new()
stage:addChild(ui)


stage:addEventListener("enterFrame", function(e)
ui:newFrame(e.deltaTime)
-- window size step is 32 (last argument, that is passed to the callback as second argument)
ui:setNextWindowSizeConstraints(200, 200, 400, 400, stepSize, 32)
if (ui:beginWindow("My window")) then
ui:textWrapped("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
end
ui:endWindow()
ui:showDemoWindow()
ui:render()
ui:endFrame()
end)
</syntaxhighlight>


=== Content region ===
* Those functions are bound to be redesigned soon (they are confusing, incomplete and return values in local window coordinates which increases confusion)


<syntaxhighlight lang="lua">
scaleX, scaleY = ImGui:getContentRegionMax()
w, h = ImGui:getContentRegionAvail()
x, y = ImGui:getWindowContentRegionMin()
x, y = ImGui:getWindowContentRegionMax()
</syntaxhighlight>


'''☠️Note: because Dear ImGui is an Immediate Mode GUI framework, functions that fetch window properties (like scrolling, window sizes, or content regions) internally query the "current window" pointer. If ImGui:begin() hasn't been called yet, or if ImGui:end() was already called, that pointer is NULL, causing a fatal segmentation fault/crash'''


=== Windows Scrolling ===
<syntaxhighlight lang="lua">
x = ImGui:getScrollX()
y = ImGui:getScrollY()
maxX = ImGui:getScrollMaxX()
maxY = ImGui:getScrollMaxY()
ImGui:setScrollX(value)
ImGui:setScrollY(value)
ImGui:setScrollHereX([ratio = 0.5])
ImGui:setScrollHereY([ratio = 0.5])
ImGui:setScrollFromPosX(x [, ratio = 0.5])
ImGui:setScrollFromPosY(y [, ratio = 0.5])
</syntaxhighlight>


'''☠️Note: because Dear ImGui is an Immediate Mode GUI framework, functions that fetch window properties (like scrolling, window sizes, or content regions) internally query the "current window" pointer. If ImGui:begin() hasn't been called yet, or if ImGui:end() was already called, that pointer is NULL, causing a fatal segmentation fault/crash'''


'''Example'''
<syntaxhighlight lang="lua">
self.doresetscrollbar = false
...
self.doresetscrollbar = true


function Level1:onEnterFrame(e)
self.imgui:newFrame(e.deltaTime)
self.imgui:beginWindow("window") -- #1
if self.doresetscrollbar then
self.doresetscrollbar = false
self.imgui:setScrollY(0)
end
...
self.imgui:endWindow() -- #1
self.imgui:endFrame()
self.imgui:render()
end
</syntaxhighlight>


== Parameters stacks (shared) ==
<syntaxhighlight lang="lua">
ImGui:pushStyleColor(ImGui.Col, color, alpha) -- https://wiki.gideros.rocks/index.php/Dear_ImGui_Flags#Col
ImGui:popStyleColor([count = 1])
ImGui:pushStyleVar(ImGui.StyleVar, value) OR ImGui:pushStyleVar(ImGui.StyleVar, value1, value2)
ImGui:popStyleVar([count = 1])
color, alpha = ImGui:getStyleColor(ImGui.Col)
fontSize = ImGui:getFontSize()
</syntaxhighlight>


 
=== Parameters stacks (current window) ===
 
== FONTS ==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
IO = imgui:getIO()
ImGui:pushItemWidth(w)
FontAtlas = IO:getFonts()
ImGui:popItemWidth()
ImGui:setNextItemWidth(w)
w = ImGui:calcItemWidth()
ImGui:pushTextWrapPos([localX = 0])
ImGui:popTextWrapPos()
ImGui:pushTabStop(flag)
ImGui:popTabStop()
ImGui:pushButtonRepeat(flag)
ImGui:popButtonRepeat()
</syntaxhighlight>


Font = FontAtlas:addFont(ttf_font_path, font_size [, options])
== Cursor / Layout ==
* By "cursor" we mean the current output position.
* The typical widget behavior is to output themselves at the current cursor position, then move the cursor one line down.
* You can call SameLine() between widgets to undo the last carriage return and output at the right of the preceeding widget.
* '''Attention'''! We currently have inconsistencies between window-local and absolute positions we will aim to fix with future API:
** '''Window-local coordinates''': ''SameLine''(), ''GetCursorPos''(), ''SetCursorPos''(), ''GetCursorStartPos''(), ''GetContentRegionMax''(), ''GetWindowContentRegion''*(), ''PushTextWrapPos''()
** '''Absolute coordinate''': ''GetCursorScreenPos''(), ''SetCursorScreenPos''(), all ImDrawList:: functions


-- options (table): all parameters are optional
<syntaxhighlight lang="lua">
--     fontDataOwnedByAtlas - bool
ImGui:separator()
--     pixelSnapH - bool
ImGui:sameLine([offset_x = 0, spacing = -1])
--     mergeMode - bool
ImGui:newLine()
--     fontNo - number
ImGui:spacing()
--     oversampleH - number
ImGui:dummy(w, h)
--     oversampleV - number
ImGui:indent([indent = 0])
--     glyphExtraSpacingX - number
ImGui:unindent([indent = 0])
--     glyphExtraSpacingY - number
ImGui:beginGroup()
--     glyphOffsetX - number
ImGui:endGroup()
--     glyphOffsetY - number
--     glyphMinAdvanceX - number
x, y = ImGui:getCursorPos()
--     glyphMaxAdvanceX - number
x = ImGui:getCursorPosX()
--     rasterizerFlags - number
y = ImGui:getCursorPosY()
--     rasterizerMultiply - number
ImGui:setCursorPos(local_x, local_y)
--
ImGui:setCursorPosX(local_x)
--     glyphs - table:
ImGui:setCursorPosY(local_y)
--     text(string): represents available chars
x, y = ImGui:getCursorStartPos()
--     chars(table): list of specific char code (example: {0x7262, ...})
x, y = ImGui:getCursorScreenPos()
--     ranges(table): predefined glyph ranges (example: {ImGui.GlyphRanges_Default, ImGui.GlyphRanges_Japanese, ...})
ImGui:setCursorScreenPos(x, y)
FontAtlas:addFonts(fontsDescription)
ImGui:alignTextToFramePadding()
-- fontsDescriptions(table):
lineH = ImGui:getTextLineHeight()
--      description(table):
lineH = ImGui:getTextLineHeightWithSpacing()
--          ttf_font_path(string): path to a font
frameH = ImGui:getFrameHeight()
--          font_size(number): font size
frameH = ImGui:getFrameHeightWithSpacing()
--          options(table): see description above
</syntaxhighlight>
-- example:
-- FontAtlas:addFonts{ {"fonts/DroidSans.ttf", 16}, {"fonts/ProggyTiny.ttf", 16} }
 
Font = FontAtlas:getFont([index]) -- get font by index (if index is 0 or nil you will get default font instance)
FontAtlas:build() -- call after multiple FontAtlas:addFont(...) calls to update ImGui font atlas
FontAtlas:clearInputData()
FontAtlas:clearTexData()
FontAtlas:clearFonts()
FontAtlas:clear()
table = FontAtlas:getFonts() -- returns a table with all fonts (included default)
flag = FontAtlas:isBuilt()
number = FontAtlas:addCustomRectRegular(width, height)
number = FontAtlas:addCustomRectFontGlyph(font, id, width, height, advance_x [, offset_x, offset_y])
w, h, x, y, glyph_id, offset_x, offset_y, font, is_packed_flag = FontAtlas:getCustomRectByIndex(index)


ImGui:pushFont(font) -- font (table): object returned by FontAtlas:addFont(...) or FontAtlas:getFont([index])
== ID stack/scopes ==
ImGui:popFont()
* Read the FAQ for more details about how ID are handled in Dear Imgui. If you are creating widgets in a loop you most likely want to push a unique identifier (e.g. object pointer, loop index) to uniquely differentiate them.
</syntaxhighlight>
* The resulting ID are hashes of the entire stack.
* You can also use the "Label##foobar" syntax within widget label to distinguish them from each others.
* In this header file we use the "label"/"name" terminology to denote a string that will be displayed and used as an ID, whereas "str_id" denote a string that is only used as an ID and not normally displayed.


'''Minimal example''':
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local UI = ImGui.new()
ImGui:pushID(anyValue)  
local IO = UI:getIO()
ImGui:pushID(str)
local FontAtlas = IO:getFonts()
ImGui:popID()
local VDS_font = FontAtlas:addFont("fonts/VDS.ttf", 16, {
number = ImGui:getID(anyValue)
    oversampleH = 2,
number = ImGui:getID(str)
    oversampleV = 2,
number = ImGui:getItemID()
glyphs = {
</syntaxhighlight>
ranges = {ImGui.GlyphRanges_Cyrillic}
}
})
IO:setFontDefault(VDS_font)
FontAtlas:build()
stage:addChild(UI)


-- you can use multiple fonts at the same time
== WIDGETS ==
function enterFrame(e)
=== Widgets: Text ===
UI:newFrame(e.deltaTime)
<syntaxhighlight lang="lua">
ImGui:textUnformatted(text [, textEnd])
UI:pushFont(font1)
ImGui:text(text)
UI:text("Font1")
ImGui:textColored(text, color, alpha)
UI:popFont()
ImGui:textDisabled(text)
ImGui:textWrapped(text)
UI:pushFont(font2)
ImGui:labelText(text, label)
UI:text("Font2")
ImGui:bulletText(text)
UI:popFont()
ImGui:separatorText(label)
UI:render()
UI:endFrame()
end
</syntaxhighlight>
</syntaxhighlight>


'''Glyphs example''':
=== Widgets: Main ===
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local fonts = io:getFonts()
flag = ImGui:button(text [, w = 0, h = 0])
fonts:addFont(font_path, font_size, {
flag = ImGui:smallButton(text)
glyphs = {
flag = ImGui:invisibleButton(string_ID [, w = 0, h = 0])
ranges = {
flag = ImGui:arrowButton(string_ID [, ImGui.Dir = 0])
{
flag = ImGui:checkbox(text, flag)
0x2590,0x2593, -- range1
flags, is_changed = ImGui:checkboxFlags(label [, flags = 0, flags_value = 0])
0x2660,0x266B  -- range2
number, is_changed = ImGui:radioButton(text, number, number)
-- ...
is_changed = ImGui:radioButton(text, flag)
},
ImGui:progressBar(fraction [, anchor_x = -1, anchor_y = 0, overlay_string = nil])
ImGui.GlyphRanges_Cyrillic,
ImGui:bullet()
{
</syntaxhighlight>
0x01C0, 0x01C3 -- range3
 
},
=== Widgets: Images ===
ImGui.GlyphRanges_Korean
<syntaxhighlight lang="lua">
},
-- Images are streched (ImGui default functions)
ImGui:image(texture, w, h
-- same structure:
[, tint_color = 0xffffff, tint_alpha = 1,
ranges = {
border_color = 0xffffff, border_alpha = 0])
{
 
0x2590,0x2593, -- range1
ImGui:imageUV(texture,
0x2660,0x266B, -- range2
w, h,
0x01C0,0x01C3  -- range3
uv0x, uv0y,
-- ...
uv1x, uv1y,
},  
[, tint_color = 0xffffff, tint_alpha = 1, border_color = 0xffffff, border_alpha = 0])
ImGui.GlyphRanges_Cyrillic,  
 
ImGui.GlyphRanges_Korean
pressFlag = ImGui:imageButton(str_id, texture, w, h
}
[, tint_color = 0xffffff, tint_alpha = 1,
},
border_color = 0xffffff, border_alpha = 0])
mergeMode = true, -- merge into previous font
 
})
pressFlag = ImGui:imageButtonUV(str_id, texture, w, h,
fonts:build()
uv0x, uv0y, uv1x, uv1y
[, tint_color = 0xffffff, tint_alpha = 1,
border_color = 0xffffff, border_alpha = 0])
 
-- Images are scaled (extended by @MultiPain)
-- padding deprecated
-- (use "ImGui:pushStyleVar(ImGui.StyleVar_FramePadding, x, y)/ImGui:popStyleVar()")
ImGui:scaledImage(str_id, texture, w, h
[, fit_mode = ImGui.ImageScaleMode_LetterBox, keep_size = false,
anchor_x = 0.5, anchor_y = 0.5,
tint_col = 0xffffff, tint_alpha = 1,
border_col = 0, border_alpha = 0,
bg_col = 0, bg_alpha = 0])
 
pressFlag = ImGui:scaledImageButton(str_id, texture, w, h
[, fit_mode = ImGui.ImageScaleMode_LetterBox, keep_size = false,
ImGui.ButtonFlags = 0, anchor_x = 0.5, anchor_y = 0.5,
clip_offset_x = 0, clip_offset_y = 0,
tint_col = 0xffffff, tint_alpha = 1,
border_col = 0, border_alpha = 0,
bg_col = 0, bg_alpha = 0])
 
pressFlag = ImGui:scaledImageButtonWithText(texture, label, image_w, image_h
[, button_w = 0, button_h = 0, ImGui.ButtonFlags = 0,
fit_mode = ImGui.ImageScaleMode_LetterBox, keep_size = false,
anchor_x = 0.5, anchor_y = 0.5, image_side = ImGui.Dir_Left,
clip_offset_x = 0, clip_offset_y = 0,
tint_col = 0xffffff, tint_alpha = 1,
border_col = 0, border_alpha = 0,
bg_col = 0, bg_alpha = 0])
</syntaxhighlight>
</syntaxhighlight>


'''Icons example''':
=== Widgets: Combo Box ===
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local icon = utf8.char(0x2590)
openFlag = ImGui:beginCombo(text, preview_text [, ImGui.ComboFlags = 0])
ImGui:text("My icon >>" .. icon .. " << !!!")
ImGui:endCombo()
 
current_item, is_open = ImGui:combo(label, current_item, items) -- items (table): {"item1", "item2", ...}
-- or with new Luau support:
ImGui:text("My icon >> \u{2590} << !!!")
-- can be also stored in memory:
local icon = "\u{2590}"
</syntaxhighlight>
</syntaxhighlight>


== Font ==
=== Widgets: Drags ===
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
number = Font:getSize()
value, is_changed = ImGui:dragFloat(label, value
FontAtlas = Font:getContainerAtlas()
[, inc_step = 1, min = 0, max = 0,
Font:setScale(number)
format_string = "%.3f", ImGui.SliderFlags = 0])
number = Font:getScale()
 
number = Font:getAscent()
value1, value2, is_changed = ImGui:dragFloat2(label, value1, value2
number = Font:getDescent()
[, inc_step = 1, min = 0, max = 0,
bool = Font:isLoaded()
format_string = "%.3f", ImGui.SliderFlags = 0])
string = Font:getDebugName()
 
w, h = Font:calcTextSizeA(size, max_width, wrap_width, string)
value1, value2, value3, is_changed = ImGui:dragFloat3(label, value1, value2, value3
Font:calcWordWrapPositionA(scale, string, wrap_width) -- not tested
[, inc_step = 1, min = 0, max = 0,
format_string = "%.3f", ImGui.SliderFlags = 0])
 
value1, value2, value3, value4, is_changed = ImGui:dragFloat4(label, value1, value2, value3, value4
[, inc_step = 1, min = 0, max = 0,
format_string = "%.3f", ImGui.SliderFlags = 0])
 
value_min, value_max, is_changed = ImGui:dragFloatRange2(label, value_min, value_max
[, inc_step = 1, min = 0, max = 0,
format_min_string = "%.3f", ImGui.SliderFlags = 0])
-- table must be an array of any size > 0
is_changed = ImGui:dragFloatT(label, table
[, inc_step = 1, min = 0, max = 0,
format_string = "%.3f", ImGui.SliderFlags = 0])
 
value, is_changed = ImGui:dragInt(label, value
[, inc_step = 1, min = 0, max = 0,
format_string = "%d", ImGui.SliderFlags = 0])
 
value1, value2, is_changed = ImGui:dragInt2(label, value1, value2
[, inc_step = 1, min = 0, max = 0,
format_string = "%d", ImGui.SliderFlags = 0])
 
value1, value2, value3, is_changed = ImGui:dragInt3(label, value1, value2, value3
[, inc_step = 1, min = 0, max = 0,
format_string = "%d", ImGui.SliderFlags = 0])
 
value1, value2, value3, value4, is_changed = ImGui:dragInt4(label, value1, value2, value3, value4
[, inc_step = 1, min = 0, max = 0,
format_string = "%d", ImGui.SliderFlags = 0])
 
v_current_min, v_current_max, flag = ImGui:dragIntRange2(label, v_current_min, v_current_max
[, v_speed = 1, v_min = 0, v_max = 0,
format = "%d", format_max = nil, ImGui.SliderFlags = 0])
 
-- table must be an array of any size > 0
is_changed = ImGui:dragIntT(label, table
[, inc_step = 1, min = 0, max = 0,
format_string = "%d", ImGui.SliderFlags = 0])
</syntaxhighlight>
</syntaxhighlight>


== INPUTS ==
=== Widgets: Sliders ===
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
ImGui:onMouseHover(event)
value, is_changed = ImGui:sliderFloat(label, value
ImGui:onMouseMove(event)
[, min = 0, max = 0,
ImGui:onMouseDown(event)
format_string = "%.3f", ImGui.SliderFlags = 0])
ImGui:onMouseUp(event)
ImGui:onMouseWheel(event)


ImGui:onTouchMove(event)
value1, value2, is_changed = ImGui:sliderFloat2(label, value1, value2
ImGui:onTouchBegin(event)
[, min = 0, max = 0,
ImGui:onTouchEnd(event)
format_string = "%.3f", ImGui.SliderFlags = 0])
ImGui:onTouchCancel(event)


ImGui:onKeyUp(event)
value1, value2, value3, is_changed = ImGui:sliderFloat3(label, value1, value2, value3
ImGui:onKeyDown(event)
[, min = 0, max = 0,
ImGui:onKeyChar(event)
format_string = "%.3f", ImGui.SliderFlags = 0])
</syntaxhighlight>


'''Usage examples''':
value1, value2, value3, value4, is_changed = ImGui:sliderFloat4(label, value1, value2, value3, value4
<syntaxhighlight lang="lua">
[, min = 0, max = 0,
local UI = ImGui.new(nil, false, false, false)
format_string = "%.3f", ImGui.SliderFlags = 0])
</syntaxhighlight>


'''Mouse'''
value_in_rad, is_changed = ImGui:sliderAngle(label, value_in_rad
<syntaxhighlight lang="lua">
[, min_degrees = -360, max_degrees = 360,
stage:addEventListener("mouseHover", function(e) UI:onMouseHover(e) end)
format_string = "%.0f deg", ImGui.SliderFlags = 0])
stage:addEventListener("mouseMove", function(e) UI:onMouseMove(e) end)
stage:addEventListener("mouseDown", function(e) UI:onMouseDown(e) end)
stage:addEventListener("mouseUp", function(e) UI:onMouseUp(e) end)
stage:addEventListener("mouseWheel", function(e) UI:onMouseWheel(e) end)
</syntaxhighlight>


'''Touch'''
-- table must be an array of any size > 0
<syntaxhighlight lang="lua">
is_changed = ImGui:sliderFloatT(label, table
stage:addEventListener("touchesCancel", function(e) ui:onTouchCancel(e) end)
[, min = 0, max = 0,
stage:addEventListener("touchesMove", function(e) ui:onTouchMove(e) end)
format_string = "%.3f", ImGui.SliderFlags = 0])
stage:addEventListener("touchesBegin", function(e) ui:onTouchBegin(e) end)
stage:addEventListener("touchesEnd", function(e) ui:onTouchEnd(e) end)
</syntaxhighlight>


'''Keyboard'''
value, is_changed = ImGui:sliderInt(label, value
<syntaxhighlight lang="lua">
[, min = 0, max = 0,
stage:addEventListener("keyUp", function(e) UI:onKeyUp(e) end)
format_string = "%d, ImGui.SliderFlags = 0"])
stage:addEventListener("keyDown", function(e) UI:onKeyDown(e) end)
stage:addEventListener("keyChar", function(e) UI:onKeyChar(e) end)
</syntaxhighlight>


value1, value2, is_changed = ImGui:sliderInt2(label, value1, value2
[, min = 0, max = 0,
format_string = "%d, ImGui.SliderFlags = 0"])


== Color convert ==
value1, value2, value3, is_changed = ImGui:sliderInt3(label, value1, value2, value3
'''Note''': use ''DOT'' instead of ''COLON'', so you can use it without creating an ImGui object
[, min = 0, max = 0,
<syntaxhighlight lang="lua">
format_string = "%d, ImGui.SliderFlags = 0"])
r, g, b, a = ImGui.colorConvertHEXtoRGB(color [, alpha = 1])
 
hex = ImGui.colorConvertRGBtoHEX(r, g, b)
value1, value2, value3, value4, is_changed = ImGui:sliderInt4(label, value1, value2, value3, value4
h, s, v = ImGui.colorConvertRGBtoHSV(r, g, b)
[, min = 0, max = 0,
r, g, b = ImGui.colorConvertHSVtoRGB(h, s, v)
format_string = "%d, ImGui.SliderFlags = 0"])
h, s, v = ImGui.colorConvertHEXtoHSV(hex)
 
hex = ImGui.colorConvertHSVtoHEX(h, s, v)
-- table must be an array of any size > 0
is_changed = ImGui:sliderIntT(label, table
[, min = 0, max = 0,
format_string = "%d", ImGui.SliderFlags = 0])
 
value, is_changed = ImGui:vSliderFloat(label, w, h, value, min, max
[, format_string = "%.3f", ImGui.SliderFlags = 0])
 
value, is_changed = ImGui:vSliderInt(label, w, h, value, min, max
[, format_string = "%d", ImGui.SliderFlags = 0])
 
value, is_changed = ImGui:filledSliderFloat(label, mirror_flag, value
[, min = 0, max = 0,
format_string = "%.3f", ImGui.SliderFlags = 0])
 
value1, value2, is_changed = ImGui:filledSliderFloat2(label, mirror_flag, value1, value2
[, min = 0, max = 0,
format_string = "%.3f", ImGui.SliderFlags = 0])
 
value1, value2, value3, is_changed = ImGui:filledSliderFloat3(label, mirror_flag, value1, value2, value3
[, min = 0, max = 0,
format_string = "%.3f", ImGui.SliderFlags = 0])
 
value1, value2, value3, value4, is_changed = ImGui:filledSliderFloat4(label, mirror_flag, value1, value2, value3, value4
[, min = 0, max = 0,
format_string = "%.3f", ImGui.SliderFlags = 0])
 
-- table must be an array of any size > 0
is_changed = ImGui:filledSliderFloatT(label, mirror_flag, table
[, min = 0, max = 0,
format_string = "%.3f", ImGui.SliderFlags = 0])
 
value_in_rad, is_changed = ImGui:filledSliderAngle(label, mirror_flag, value_in_rad
[, min_degrees = -360, max_degrees = 360,
format_string = "%.0f deg", ImGui.SliderFlags = 0])
 
value, is_changed = ImGui:filledSliderInt(label, mirror_flag, value
[, min = 0, max = 0,
format_string = "%d", ImGui.SliderFlags = 0])
 
value1, value2, is_changed = ImGui:filledSliderInt2(label, mirror_flag, value1, value2
[, min = 0, max = 0,
format_string = "%d", ImGui.SliderFlags = 0])
 
value1, value2, value3, is_changed = ImGui:filledSliderInt3(label, mirror_flag, value1, value2, value3
[, min = 0, max = 0,
format_string = "%d", ImGui.SliderFlags = 0])
 
value1, value2, value3, value4, is_changed = ImGui:filledSliderInt4(label, mirror_flag, value1, value2, value3, value4
[, min = 0, max = 0,
format_string = "%d", ImGui.SliderFlags = 0])
 
-- table must be an array of any size > 0
is_changed = ImGui:filledSliderIntT(label, mirror_flag, table
[, min = 0, max = 0,
format_string = "%d", ImGui.SliderFlags = 0])
 
value, is_changed = ImGui:vFilledSliderFloat(label, mirror_flag, w, h, value, min, max
[, format_string = "%.3f", ImGui.SliderFlags = 0])
 
value, is_changed = ImGui:vFilledSliderInt(label, mirror_flag, w, h, value, min, max
[, format_string = "%d", ImGui.SliderFlags = 0])
</syntaxhighlight>
</syntaxhighlight>


 
=== Widgets: Input with Keyboard ===
== Context ==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
string OR nil = ImGui:getHoveredWindow()
text, flag = ImGui:inputText(label, text, buffer_size [, ImGui.InputTextFlags = 0])
string OR nil = ImGui:getHoveredWindowRoot()
text, flag = ImGui:inputTextMultiline(label, text, buffer_size [, w = 0, h = 0, ImGui.InputTextFlags = 0])
string OR nil = ImGui:getHoveredWindowUnderMovingWindow()
text, flag = ImGui:inputTextWithHint(label, text, hint, buffer_size [, ImGui.InputTextFlags = 0])
string OR nil = ImGui:getMovingWindow()
value,  flag = ImGui:inputFloat(label, value [, step = 0, step_fast = 0, format = "%.3f", ImGui.InputTextFlags = 0])
string OR nil = ImGui:getActiveIdWindow()
value1, value2, flag = ImGui:inputFloat2(label, value1, value2 [, format = "%.3f", ImGui.InputTextFlags = 0])
id = ImGui:getActiveId()
value1, value2, value3, flag = ImGui:inputFloat3(label, value1, value2, value3 [, format = "%.3f", ImGui.InputTextFlags = 0])
id = ImGui:getActiveIdPreviousFrame()
value1, value2, value3, value4, flag = ImGui:inputFloat4(label, value1, value2, value3, value4 [, format = "%.3f", ImGui.InputTextFlags = 0])
number = ImGui:getActiveIdTimer()
-- table must be an array of any size > 0
id = ImGui:getActiveIdAllowOverlap()
flag = ImGui:inputFloatT(label, table [, format = "%.3f", ImGui.InputTextFlags = 0])
id = ImGui:getHoveredId()
value,  flag = ImGui:inputInt(label, value [, step = 0, step_fast = 0, ImGui.InputTextFlags = 0])
id = ImGui:getHoveredIdPreviousFrame()
value1, value2, flag = ImGui:inputInt2(label, value1, value2 [, ImGui.InputTextFlags = 0])
number = ImGui:getHoveredIdTimer()
value1, value2, value3, flag = ImGui:inputInt3(label, value1, value2, value3 [, ImGui.InputTextFlags = 0])
id = ImGui:getHoveredIdAllowOverlap()
value1, value2, value3, value4, flag = ImGui:inputInt4(label, value1, value2, value3, value4 [, ImGui.InputTextFlags = 0])
bool = ImGui:getDragDropActive()
-- table must be an array of any size > 0
id = ImGui:getDragDropPayloadSourceId()
flag = ImGui:inputIntT(label, table [, format = "%d", ImGui.InputTextFlags = 0])
string = ImGui:getDragDropPayloadDataType()
value, flag = ImGui:inputDouble(label, value [, step = 0, step_fast = 0, format = "%.6f", ImGui.InputTextFlags = 0])
number = ImGui:getDragDropPayloadDataSize()
</syntaxhighlight>
</syntaxhighlight>
 
 
'''Input text callbacks''':
== WIDGETS & STUFF ==
=== Windows ===
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
p_open, draw = ImGui:beginWindow(label, p_open [, ImGui.WindowFlags = 0])
ImGui:inputText(label, text, buffer_size [, ImGui.InputTextFlags = 0, callback_function, user_data])
draw = ImGui:beginWindow(label, nil [, ImGui.WindowFlags = 0]) -- do not show "X" button
ImGui:inputTextMultiline(label, text, buffer_size [, ImGui.InputTextFlags = 0, callback_function, user_data])
p_open, draw = ImGui:beginFullScreenWindow(label, p_open [, ImGui.WindowFlags = 0]) -- start a window with no borders, no paddings, no rounding and ImGui.WindowFlags_Fullscreen flag
ImGui:inputTextWithHint(label, text, hint, buffer_size [, ImGui.InputTextFlags = 0, callback_function, user_data])
draw = ImGui:beginFullScreenWindow(label, nil [, ImGui.WindowFlags = 0]) -- do not show "X" button
ImGui:endWindow()
</syntaxhighlight>


=== Disabled groups ===
callback_function = function(callback_data, user_data)
<syntaxhighlight lang="lua">
-- do something with data
ImGui:beginDisabled(disabledFlag)
-- see below
ImGui:endDisabled()
end
</syntaxhighlight>
</syntaxhighlight>


=== Child Windows ===
'''callback_data''':
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
ImGui:beginChild(id [, w = 0, h = 0, borderFlag = false, ImGui.WindowFlags = 0])
ImGuiInputTextFlags = callback_data:getEventFlag()
ImGui:endChild()
ImGuiInputTextFlags = callback_data:getFlags()
</syntaxhighlight>


=== Windows Utilities ===
number = callback_data:getEventChar()
<syntaxhighlight lang="lua">
 
flag = ImGui:isWindowAppearing()
callback_data:setEventChar(number)
flag = ImGui:isWindowCollapsed()
flag = ImGui:isWindowFocused([ImGui.FocusedFlags = 0])
flag = ImGui:isWindowHovered([ImGui.HoveredFlags = 0])
x, y = ImGui:getWindowPos()
w, h = ImGui:getWindowSize()
w = ImGui:getWindowWidth()
h = ImGui:getWindowHeight()


x1,y1, x2,y2 = ImGui:getWindowBounds() -- returns window region rectangle in global coordinates
keyCode = callback_data:getEventKey()
ImGui:setNextWindowPos(x, y [, ImGui.Cond = 0, pivotX = 0, pivotY = 0])
ImGui:setNextWindowSize(w, h [, ImGui.Cond = 0])
ImGui:setNextWindowContentSize(w, h)
ImGui:setNextWindowCollapsed(flag [, ImGui.Cond = 0])
ImGui:setNextWindowFocus()
ImGui:setNextWindowBgAlpha(alpha)
ImGui:setNextWindowScroll(x, y)
ImGui:setWindowPos(name, x, y [, ImGui.Cond = 0]) OR ImGui:setWindowPos(x, y [, ImGui.Cond = 0])
ImGui:setWindowSize(name, w, h [, ImGui.Cond = 0]) OR ImGui:setWindowSize(w, h [, ImGui.Cond = 0])
ImGui:setWindowCollapsed(name, flag [, ImGui.Cond = 0]) OR ImGui:setWindowCollapsed(flag [, ImGui.Cond = 0])
ImGui:setWindowFocus(name) OR ImGui:setWindowFocus()
ImGui:setWindowFontScale(scale)
ImGui:scrollWhenDragging(x, y) -- scroll window when touching void
</syntaxhighlight>


=== Window size constraints ===
string = callback_data:getBuf()
Can be used to set minimum and maximum window size, plus contraint the size if needed.
<syntaxhighlight lang="lua">
ImGui:setNextWindowSizeConstraints(min_w, min_h, max_w, max_h [, resize_callback, user_data])) -- call this function before ImGui:beginWindow()
-- resizeCallback is a function:
function (callbackData [, user_data])
-- do some math, and return desired size
-- ...
return desired_width, desired_height
end
</syntaxhighlight>


'''Resize callback''':
callback_data:setBuf(string)
<syntaxhighlight lang="lua">
x, y = callbackData:getPos() -- get window position
x = callbackData:getX()
y = callbackData:getY()


current_width, current_height = callbackData:getCurrentSize() -- get currrent size
number = callback_data:getBufTextLen()
current_width = callbackData:getCurrentWidth()
current_height = callbackData:getCurrentHeight()


desired_width, desired_height = callbackData:getDesiredSize() -- get desired size
callback_data:setBufTextLen(number)
desired_width = callbackData:getDesiredWidth()
desired_height = callbackData:getDesiredHeight()
</syntaxhighlight>


'''Example''':
number = callback_data:getBufSize()
<syntaxhighlight lang="lua">
require "ImGui"


local function stepSize(callback_data, step)
callback_data:setBufDirty(bool)
local w, h = callback_data:getDesiredSize()
bool = callback_data:isBufDirty()
w = (w // step) * step
 
h = (h // step) * step
callback_data:setCursorPos(number)
return w, h
number = callback_data:getCursorPos()
end
 
callback_data:setSelectionStart(s_start)
number = callback_data:getSelectionStart()
 
callback_data:setSelectionEnd(s_end)
s_end = callback_data:getSelectionEnd()


local ui = ImGui.new()
callback_data:setSelection(s_start, s_end)
stage:addChild(ui)
s_start, s_end = callback_data:getSelection()


stage:addEventListener("enterFrame", function(e)
callback_data:selectAll()
ui:newFrame(e.deltaTime)
callback_data:clearSelection()
bool = callback_data:hasSelection()
-- window size step is 32 (last argument, that is passed to the callback as second argument)
 
ui:setNextWindowSizeConstraints(200, 200, 400, 400, stepSize, 32)
callback_data:deleteChars(position, bytesCount)
if (ui:beginWindow("My window")) then
callback_data:insertChars(position, text)
ui:textWrapped("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
end
ui:endWindow()
ui:showDemoWindow()
ui:render()
ui:endFrame()
end)
</syntaxhighlight>
</syntaxhighlight>


=== Content region ===
'''Example''':
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
scaleX, scaleY = ImGui:getContentRegionMax()
require "ImGui"
w, h = ImGui:getContentRegionAvail()
 
x, y = ImGui:getWindowContentRegionMin()
ui = ImGui.new()
x, y = ImGui:getWindowContentRegionMax()
stage:addChild(ui)
</syntaxhighlight>


=== Windows Scrolling ===
local testMessage1 = ""
<syntaxhighlight lang="lua">
local testMessage2 = ""
x = ImGui:getScrollX()
local testMessage3 = ""
y = ImGui:getScrollY()
maxX = ImGui:getScrollMaxX()
maxY = ImGui:getScrollMaxY()
ImGui:setScrollX(value)
ImGui:setScrollY(value)
ImGui:setScrollHereX([ratio = 0.5])
ImGui:setScrollHereY([ratio = 0.5])
ImGui:setScrollFromPosX(x [, ratio = 0.5])
ImGui:setScrollFromPosY(y [, ratio = 0.5])
</syntaxhighlight>


=== Parameters stacks (shared) ===
-- Add ".." at the end of current input string
<syntaxhighlight lang="lua">
function myCallback1(data)
ImGui:pushStyleColor(ImGui.Col, color, alpha)
data:insertChars(data:getCursorPos(), "..")
ImGui:popStyleColor([count = 1])
end
ImGui:pushStyleVar(ImGui.StyleVar, value) OR ImGui:pushStyleVar(ImGui.StyleVar, value1, value2)
ImGui:popStyleVar([count = 1])
color, alpha = ImGui:getStyleColor(ImGui.Col)
fontSize = ImGui:getFontSize()
</syntaxhighlight>


=== Parameters stacks (current window) ===
-- Replace all chars if UP/DOWN arrow is pressed
<syntaxhighlight lang="lua">
function myCallback2(data)
ImGui:pushItemWidth(w)
local key = data:getEventKey()
ImGui:popItemWidth()
if (key == key_code.UP) then
ImGui:setNextItemWidth(w)
data:deleteChars(0, data:getBufTextLen())
w = ImGui:calcItemWidth()
data:insertChars(0, "Pressed Up!")
ImGui:pushTextWrapPos([localX = 0])
data:selectAll()
ImGui:popTextWrapPos()
elseif (key == key_code.DOWN) then
ImGui:pushTabStop(flag)
data:deleteChars(0, data:getBufTextLen())
ImGui:popTabStop()
data:insertChars(0, "Pressed Down!")
ImGui:pushButtonRepeat(flag)
data:selectAll()
ImGui:popButtonRepeat()
end
</syntaxhighlight>
end


=== Cursor / Layout ===
-- Switch case of the first char
<syntaxhighlight lang="lua">
function myCallback3(data)
ImGui:separator()
local buf = data:getBuf()
ImGui:sameLine([offset_x = 0, spacing = -1])
local s = buf:sub(1,1)
ImGui:newLine()
if ((s >= 'a' and s <= 'z') or (s >= 'A' and s <= 'Z')) then
ImGui:spacing()
local first = string.char(string.byte(s) ~ 32)
ImGui:dummy(w, h)
data:setBuf(first .. buf:sub(2))
ImGui:indent([indent = 0])
data:setBufDirty(true)
ImGui:unindent([indent = 0])
end
ImGui:beginGroup()
end
ImGui:endGroup()
 
function enterFrame(e)
x, y = ImGui:getCursorPos()
ui:newFrame(e.deltaTime)
x = ImGui:getCursorPosX()
y = ImGui:getCursorPosY()
testMessage1 = ui:inputText(
ImGui:setCursorPos(local_x, local_y)
"Label1",
ImGui:setCursorPosX(local_x)
testMessage1,
ImGui:setCursorPosY(local_y)
64,
x, y = ImGui:getCursorStartPos()
ImGui.InputTextFlags_CallbackCompletion,  
x, y = ImGui:getCursorScreenPos()
myCallback1
ImGui:setCursorScreenPos(x, y)
)
ImGui:alignTextToFramePadding()
testMessage2 = ui:inputText(
lineH = ImGui:getTextLineHeight()
"Label2",  
lineH = ImGui:getTextLineHeightWithSpacing()
testMessage2,  
frameH = ImGui:getFrameHeight()
64,  
frameH = ImGui:getFrameHeightWithSpacing()
ImGui.InputTextFlags_CallbackHistory,
</syntaxhighlight>
myCallback2
 
)
=== ID stack/scopes ===
testMessage3 = ui:inputText(
<syntaxhighlight lang="lua">
"Label3",
ImGui:pushID(anyValue)  
testMessage3,
ImGui:pushID(str)
64,
ImGui:popID()
ImGui.InputTextFlags_CallbackEdit,
number = ImGui:getID(any_value)
myCallback3
number = ImGui:getID(string)
)
number = ImGui:getItemID()
ui:render()
ui:endFrame()
end
 
stage:addEventListener("enterFrame", enterFrame)
</syntaxhighlight>
</syntaxhighlight>


=== Widgets: Text ===
=== Widgets: Color Editor/Picker ===
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
ImGui:textUnformatted(text [, textEnd])
hexColor, is_touching = ImGui:colorEdit3(label, color [, ImGui.ColorEditFlags = 0]) -- alpha ignored, no need to pass it!
ImGui:text(text)
hexColor, alpha, is_touching = ImGui:colorEdit4(label, color [, alpha = 1, ImGui.ColorEditFlags = 0])
ImGui:textColored(text, color, alpha)
hexColor, is_touching = ImGui:colorPicker3(label, color [, ImGui.ColorEditFlags = 0])
ImGui:textDisabled(text)
hexColor, alpha, originalColor, originalAlpha, is_touching = ImGui:colorPicker4(label, color
ImGui:textWrapped(text)
[, alpha = 1, original_color = 0xffffff, original_alpha = 1, ImGui.ColorEditFlags = 0])
ImGui:labelText(text, label)
isHoveringFlag = ImGui:colorButton(string_ID, color [, alpha = 1, ImGui.ColorEditFlags = 0, w = 0, h = 0])
ImGui:bulletText(text)
ImGui:setColorEditOptions(ImGui.ColorEditFlags)
ImGui:separatorText(label)
</syntaxhighlight>
</syntaxhighlight>


=== Widgets: Main ===
=== Widgets: Trees ===
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
flag = ImGui:button(text [, w = 0, h = 0])
is_openFlag = ImGui:treeNode(label [, format_string])
flag = ImGui:smallButton(text)
ImGui:treeNodeEx(label, ImGui.TreeNodeFlags [, format_string])
flag = ImGui:invisibleButton(string_ID [, w = 0, h = 0])
ImGui:treePush(str_id)
flag = ImGui:arrowButton(string_ID [, ImGui.Dir = 0])
ImGui:treePop()
flag = ImGui:checkbox(text, flag)
number = ImGui:getTreeNodeToLabelSpacing()
flags, is_changed = ImGui:checkboxFlags(label [, flags = 0, flags_value = 0])
is_openFlag, p_open = ImGui:collapsingHeader(label, p_open [, ImGui.TreeNodeFlags = 0])
number, is_changed = ImGui:radioButton(text, number, number)
is_openFlag = ImGui:collapsingHeader(label [, ImGui.TreeNodeFlags = 0])
is_changed = ImGui:radioButton(text, flag)
ImGui:setNextItemOpen(is_open, ImGui.Cond)
ImGui:progressBar(fraction [, anchor_x = -1, anchor_y = 0, overlay_string = nil])
ImGui:bullet()
</syntaxhighlight>
</syntaxhighlight>


=== Widgets: Images ===
=== Widgets: Selectables ===
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
ImGui:image(texture, w, h [, tint_color = 0xffffff, tint_alpha = 1, border_color = 0xffffff, border_alpha = 0]) -- images are streched (ImGui default functions)
result?, selected = ImGui:selectable(label, selected [, ImGui.SelectableFlags = 0, w = 0, h = 0])
ImGui:imageUV(texture, w, h, uv0x, uv0y, uv1x, uv1y [, tint_color = 0xffffff, tint_alpha = 1, border_color = 0xffffff, border_alpha = 0]) -- images are streched (ImGui default functions)
pressFlag = ImGui:imageButton(str_id, texture, w, h [, tint_color = 0xffffff, tint_alpha = 1, border_color = 0xffffff, border_alpha = 0]) -- images are streched (ImGui default functions)
pressFlag = ImGui:imageButtonUV(str_id, texture, w, h, uv0x, uv0y, uv1x, uv1y [, tint_color = 0xffffff, tint_alpha = 1, border_color = 0xffffff, border_alpha = 0]) -- images are streched (ImGui default functions)
 
-- padding deprecated (use "ImGui:pushStyleVar(ImGui.StyleVar_FramePadding, x, y)/ImGui:popStyleVar()")
ImGui:scaledImage(str_id, texture, w, h [, fit_mode = ImGui.ImageScaleMode_LetterBox, keep_size = false, anchor_x = 0.5, anchor_y = 0.5, tint_col = 0xffffff, tint_alpha = 1, border_col = 0, border_alpha = 0, bg_col = 0, bg_alpha = 0]) -- images are scaled
pressFlag = ImGui:scaledImageButton(str_id, texture, w, h [, fit_mode = ImGui.ImageScaleMode_LetterBox, keep_size = false, ImGui.ButtonFlags = 0, anchor_x = 0.5, anchor_y = 0.5, clip_offset_x = 0, clip_offset_y = 0, tint_col = 0xffffff, tint_alpha = 1, border_col = 0, border_alpha = 0, bg_col = 0, bg_alpha = 0]) -- images are scaled
pressFlag = ImGui:scaledImageButtonWithText(texture, label, image_w, image_h [, button_w = 0, button_h = 0,  ImGui.ButtonFlags = 0, fit_mode = ImGui.ImageScaleMode_LetterBox, keep_size = false, anchor_x = 0.5, anchor_y = 0.5, image_side = ImGui.Dir_Left, clip_offset_x = 0, clip_offset_y = 0, tint_col = 0xffffff, tint_alpha = 1, border_col = 0, border_alpha = 0, bg_col = 0, bg_alpha = 0]) -- images are scaled
</syntaxhighlight>
</syntaxhighlight>


=== Widgets: Combo Box ===
=== Widgets: List Boxes ===
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
openFlag = ImGui:beginCombo(text, preview_text [, ImGui.ComboFlags = 0])
-- item_table: {"Item0", "Item1", ...}
ImGui:endCombo()
current_item, is_openFlag = ImGui:listBox(label, current_item, item_table [, max_visible_items = -1])
current_item, is_open = ImGui:combo(label, current_item, items) -- items (table): {"item1", "item2", ...}
result? = ImGui:listBoxHeader(label [, w = 0, h = 0])
</syntaxhighlight>
result? = ImGui:listBoxHeader2(label, items_count)
ImGui:listBoxFooter()
</syntaxhighlight>
 
=== Widgets: Data Plotting ===
'''Caching''':


=== Widgets: Drags ===
If you have big array of points it is better to cache it instead of translating lua table to C++ vector every time you call `ImGui:plotLines()`. But in this case you need to manage memory by yourself (free points pointer when you dont need it).
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
value, is_changed = ImGui:dragFloat(label, value [, inc_step = 1, min = 0, max = 0, format_string = "%.3f", ImGui.SliderFlags = 0])
-- store points in memory
value1, value2, is_changed = ImGui:dragFloat2(label, value1, value2 [, inc_step = 1, min = 0, max = 0, format_string = "%.3f", ImGui.SliderFlags = 0])
-- points_table: {0.01, 0.5, 10, -50, ...}
value1, value2, value3, is_changed = ImGui:dragFloat3(label, value1, value2, value3 [, inc_step = 1, min = 0, max = 0, format_string = "%.3f", ImGui.SliderFlags = 0])
-- ptr: c++ pointer to a given vector
value1, value2, value3, value4, is_changed = ImGui:dragFloat4(label, value1, value2, value3, value4 [, inc_step = 1, min = 0, max = 0, format_string = "%.3f", ImGui.SliderFlags = 0])
ptr = ImGui.cachePoints(points_table)
value_min, value_max, is_changed = ImGui:dragFloatRange2(label, value_min, value_max [, inc_step = 1, min = 0, max = 0, format_min_string = "%.3f", ImGui.SliderFlags = 0])
 
is_changed = ImGui:dragFloatT(label, table [, inc_step = 1, min = 0, max = 0, format_string = "%.3f", ImGui.SliderFlags = 0]) -- table must be an array of any size > 0
-- delete points from memory
value, is_changed = ImGui:dragInt(label, value [, inc_step = 1, min = 0, max = 0, format_string = "%d", ImGui.SliderFlags = 0])
ImGui.freePoints(ptr)
value1, value2, is_changed = ImGui:dragInt2(label, value1, value2 [, inc_step = 1, min = 0, max = 0, format_string = "%d", ImGui.SliderFlags = 0])
value1, value2, value3, is_changed = ImGui:dragInt3(label, value1, value2, value3 [, inc_step = 1, min = 0, max = 0, format_string = "%d", ImGui.SliderFlags = 0])
value1, value2, value3, value4, is_changed = ImGui:dragInt4(label, value1, value2, value3, value4 [, inc_step = 1, min = 0, max = 0, format_string = "%d", ImGui.SliderFlags = 0])
v_current_min, v_current_max, flag = ImGui:dragIntRange2(label, v_current_min, v_current_max [, v_speed = 1, v_min = 0, v_max = 0, format = "%d", format_max = nil, ImGui.SliderFlags = 0])
is_changed = ImGui:dragIntT(label, table [, inc_step = 1, min = 0, max = 0, format_string = "%d", ImGui.SliderFlags = 0]) -- table must be an array of any size > 0
</syntaxhighlight>
</syntaxhighlight>


=== Widgets: Sliders ===
'''Plot functions''':
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
value, is_changed = ImGui:sliderFloat(label, value [, min = 0, max = 0, format_string = "%.3f", ImGui.SliderFlags = 0])
-- len (number): points array length
value1, value2, is_changed = ImGui:sliderFloat2(label, value1, value2 [, min = 0, max = 0, format_string = "%.3f", ImGui.SliderFlags = 0])
ImGui:plotCachedLines(label, ptr, len,
value1, value2, value3, is_changed = ImGui:sliderFloat3(label, value1, value2, value3 [, min = 0, max = 0, format_string = "%.3f", ImGui.SliderFlags = 0])
[, values_offset = 0, overlay_text = nil,
value1, value2, value3, value4, is_changed = ImGui:sliderFloat4(label, value1, value2, value3, value4 [, min = 0, max = 0, format_string = "%.3f", ImGui.SliderFlags = 0])
scale_min = math.huge, scale_max = math.huge,
value_in_rad, is_changed = ImGui:sliderAngle(label, value_in_rad [, min_degrees = -360, max_degrees = 360, format_string = "%.0f deg", ImGui.SliderFlags = 0])
w = 0, h = 0])
is_changed = ImGui:sliderFloatT(label, table [, min = 0, max = 0, format_string = "%.3f", ImGui.SliderFlags = 0]) -- table must be an array of any size > 0
 
value, is_changed = ImGui:sliderInt(label, value [, min = 0, max = 0, format_string = "%d", ImGui.SliderFlags = 0])
ImGui:plotCachedHistogram(label, ptr, len,
value1, value2, is_changed = ImGui:sliderInt2(label, value1, value2 [, min = 0, max = 0, format_string = "%d", ImGui.SliderFlags = 0])
[, values_offset = 0, overlay_text = nil,
value1, value2, value3, is_changed = ImGui:sliderInt3(label, value1, value2, value3 [, min = 0, max = 0, format_string = "%d", ImGui.SliderFlags = 0])
scale_min = math.huge, scale_max = math.huge,
value1, value2, value3, value4, is_changed = ImGui:sliderInt4(label, value1, value2, value3, value4 [, min = 0, max = 0, format_string = "%d", ImGui.SliderFlags = 0])
w = 0, h = 0])
is_changed = ImGui:sliderIntT(label, table [, min = 0, max = 0, format_string = "%d", ImGui.SliderFlags = 0]) -- table must be an array of any size > 0
 
value, is_changed = ImGui:vSliderFloat(label, w, h, value, min, max [, format_string = "%.3f", ImGui.SliderFlags = 0])
ImGui:plotLines(label, points_table
value, is_changed = ImGui:vSliderInt(label, w, h, value, min, max [, format_string = "%d", ImGui.SliderFlags = 0])
[, values_offset = 0, overlay_text = nil,
value, is_changed = ImGui:filledSliderFloat(label, mirror_flag, value [, min = 0, max = 0, format_string = "%.3f", ImGui.SliderFlags = 0])
scale_min = math.huge, scale_max = math.huge,
value1, value2, is_changed = ImGui:filledSliderFloat2(label, mirror_flag, value1, value2 [, min = 0, max = 0, format_string = "%.3f", ImGui.SliderFlags = 0])
w = 0, h = 0])
value1, value2, value3, is_changed = ImGui:filledSliderFloat3(label, mirror_flag, value1, value2, value3 [, min = 0, max = 0, format_string = "%.3f", ImGui.SliderFlags = 0])
 
value1, value2, value3, value4, is_changed = ImGui:filledSliderFloat4(label, mirror_flag, value1, value2, value3, value4 [, min = 0, max = 0, format_string = "%.3f", ImGui.SliderFlags = 0])
ImGui:plotHistogram(label, points_table
is_changed = ImGui:filledSliderFloatT(label, mirror_flag, table [, min = 0, max = 0, format_string = "%.3f", ImGui.SliderFlags = 0]) -- table must be an array of any size > 0
[, values_offset = 0, overlay_text = nil,
value_in_rad, is_changed = ImGui:filledSliderAngle(label, mirror_flag, value_in_rad [, min_degrees = -360, max_degrees = 360, format_string = "%.0f deg", ImGui.SliderFlags = 0])
scale_min = math.huge, scale_max = math.huge,
value, is_changed = ImGui:filledSliderInt(label, mirror_flag, value [, min = 0, max = 0, format_string = "%d", ImGui.SliderFlags = 0])
w = 0, h = 0])
value1, value2, is_changed = ImGui:filledSliderInt2(label, mirror_flag, value1, value2 [, min = 0, max = 0, format_string = "%d", ImGui.SliderFlags = 0])
value1, value2, value3, is_changed = ImGui:filledSliderInt3(label, mirror_flag, value1, value2, value3 [, min = 0, max = 0, format_string = "%d", ImGui.SliderFlags = 0])
value1, value2, value3, value4, is_changed = ImGui:filledSliderInt4(label, mirror_flag, value1, value2, value3, value4 [, min = 0, max = 0, format_string = "%d", ImGui.SliderFlags = 0])
is_changed = ImGui:filledSliderIntT(label, mirror_flag, table [, min = 0, max = 0, format_string = "%d", ImGui.SliderFlags = 0]) -- table must be an array of any size > 0
value, is_changed = ImGui:vFilledSliderFloat(label, mirror_flag, w, h, value, min, max [, format_string = "%.3f", ImGui.SliderFlags = 0])
value, is_changed = ImGui:vFilledSliderInt(label, mirror_flag, w, h, value, min, max [, format_string = "%d", ImGui.SliderFlags = 0])
</syntaxhighlight>
</syntaxhighlight>


=== Widgets: Input with Keyboard ===
'''Example''':
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
text, flag = ImGui:inputText(label, text, buffer_size [, ImGui.InputTextFlags = 0])
-- delete ptr if it exist
text, flag = ImGui:inputTextMultiline(label, text, buffer_size [, w = 0, h = 0, ImGui.InputTextFlags = 0])
function deletePtr()
text, flag = ImGui:inputTextWithHint(label, text, hint, buffer_size [, ImGui.InputTextFlags = 0])
if pointsPtr then
value,  flag = ImGui:inputFloat(label, value [, step = 0, step_fast = 0, format = "%.3f", ImGui.InputTextFlags = 0])
ImGui.freePoints(pointsPtr)
value1, value2, flag = ImGui:inputFloat2(label, value1, value2 [, format = "%.3f", ImGui.InputTextFlags = 0])
end
value1, value2, value3, flag = ImGui:inputFloat3(label, value1, value2, value3 [, format = "%.3f", ImGui.InputTextFlags = 0])
value1, value2, value3, value4, flag = ImGui:inputFloat4(label, value1, value2, value3, value4 [, format = "%.3f", ImGui.InputTextFlags = 0])
flag = ImGui:inputFloatT(label, table [, format = "%.3f", ImGui.InputTextFlags = 0]) -- table must be an array of any size > 0
value,  flag = ImGui:inputInt(label, value [, step = 0, step_fast = 0, ImGui.InputTextFlags = 0])
value1, value2, flag = ImGui:inputInt2(label, value1, value2 [, ImGui.InputTextFlags = 0])
value1, value2, value3, flag = ImGui:inputInt3(label, value1, value2, value3 [, ImGui.InputTextFlags = 0])
value1, value2, value3, value4, flag = ImGui:inputInt4(label, value1, value2, value3, value4 [, ImGui.InputTextFlags = 0])
flag = ImGui:inputIntT(label, table [, format = "%d", ImGui.InputTextFlags = 0]) -- table must be an array of any size > 0
value, flag = ImGui:inputDouble(label, value [, step = 0, step_fast = 0, format = "%.6f", ImGui.InputTextFlags = 0])
</syntaxhighlight>
 
'''Input text callbacks''':
<syntaxhighlight lang="lua">
ImGui:inputText(label, text, buffer_size [, ImGui.InputTextFlags = 0, callback_function, user_data])
ImGui:inputTextMultiline(label, text, buffer_size [, ImGui.InputTextFlags = 0, callback_function, user_data])
ImGui:inputTextWithHint(label, text, hint, buffer_size [, ImGui.InputTextFlags = 0, callback_function, user_data])
 
callback_function = function(callback_data, user_data)
-- do something with data
-- see below
end
end
</syntaxhighlight>


'''callback_data''':
function onEnterFrame()
<syntaxhighlight lang="lua">
ui:newFrame(e.deltaTime)
ImGuiInputTextFlags = callback_data:getEventFlag()
ImGuiInputTextFlags = callback_data:getFlags()
if ui:button("Generate") then
deletePtr()
points = generatePoints() -- returns big array
pointsPtr = ImGui.cachePoints(points)
end
if pointsPtr then
ui:plotCachedLines("Big data", pointsPtr, #points)
end
ui:render()
ui:endFrame()
end


number = callback_data:getEventChar()
-- do not forget to clear memory when app is closing
function onAppExit()
deletePtr()
end
</syntaxhighlight>


callback_data:setEventChar(number)
=== Widgets: Value() Helpers ===
<syntaxhighlight lang="lua">
ImGui:value(prefix, bool)
ImGui:value(prefix, number)
ImGui:value(prefix, float, format_string)
</syntaxhighlight>


keyCode = callback_data:getEventKey()
=== Widgets: Menus ===
<syntaxhighlight lang="lua">
result? = ImGui:beginMenuBar()
ImGui:endMenuBar()
result? = ImGui:beginMainMenuBar()
ImGui:endMainMenuBar()
result = ImGui:beginMenu(label [, enabled = true])
result = ImGui:beginMenuEx(label, [icon = "", enabled = true])
ImGui:endMenu()
result = ImGui:menuItem(label [, shortcut = "", selected = false, enabled = true])
result = ImGui:menuItemEx(label, [icon = "", shortcut = "", selected = false, enabled = true])
</syntaxhighlight>


string = callback_data:getBuf()
=== Widgets: Tooltips ===
Tooltip are windows following the mouse which do not take focus away.
<syntaxhighlight lang="lua">
ImGui:beginTooltip()
ImGui:endTooltip()
ImGui:setTooltip(text)
</syntaxhighlight>


callback_data:setBuf(string)
=== Disabled groups ===
<syntaxhighlight lang="lua">
ImGui:beginDisabled(disabledFlag)
ImGui:endDisabled()
</syntaxhighlight>


number = callback_data:getBufTextLen()
== Popups, Modals ==
The properties of popups windows are: - They block normal mouse hovering detection outside them. (*1) - Unless modal, they can be closed by clicking anywhere outside them, or by pressing ESCAPE. Because hovering detection is disabled outside the popup, when clicking outside the click will not be seen by underlying widgets! (*'''1''')


callback_data:setBufTextLen(number)
* Their visibility state (~bool) is held internally by Dear ImGui instead of being held by the programmer as we are used to with regular Begin() calls. User can manipulate the visibility state by calling OpenPopup(), CloseCurrentPopup() etc.
* We default to use the right mouse (ImGuiMouseButton_Right=1) for the Popup Context functions.
* Those three properties are connected: we need to retain popup visibility state in the library because popups may be closed as any time.


number = callback_data:getBufSize()
('''1'''.) You can bypass that restriction and detect hovering even when normally blocked by a popup. To do this use the ImGuiHoveredFlags_AllowWhenBlockedByPopup when calling IsItemHovered() or IsWindowHovered(). This is what BeginPopupContextItem() and BeginPopupContextWindow() are doing already, allowing a right-click to reopen another popups without losing the click.


callback_data:setBufDirty(bool)
<syntaxhighlight lang="lua">
bool = callback_data:isBufDirty()
result? = ImGui:beginPopup(str_id [, ImGui.WindowFlags = 0])
p_open, result? = ImGui:beginPopupModal(str_id, p_open [, ImGui.WindowFlags = 0])
ImGui:endPopup()
ImGui:openPopup(str_id [, ImGui.PopupFlags = 0])
ImGui:openPopupOnItemClick(str_id [, ImGui.PopupFlags = 0])
ImGui:closeCurrentPopup()
result? = ImGui:beginPopupContextItem(str_id [, ImGui.PopupFlags = 0])
result? = ImGui:beginPopupContextWindow(str_id [, ImGui.PopupFlags = 0])
result? = ImGui:beginPopupContextVoid(str_id [, ImGui.PopupFlags = 0])
result? = ImGui:isPopupOpen(str_id [, ImGui.PopupFlags = 0])
</syntaxhighlight>


callback_data:setCursorPos(number)
== Columns ==
number = callback_data:getCursorPos()
* You can also use SameLine(pos_x) to mimic simplified columns.
* The columns API is work-in-progress and rather lacking (columns are arguably the worst part of dear imgui at the moment!)
* There is a maximum of 64 columns.
* Currently working on new 'Tables' api which will replace columns around Q2 2020 (see GitHub #2957).


callback_data:setSelectionStart(s_start)
<syntaxhighlight lang="lua">
number = callback_data:getSelectionStart()
ImGui:columns([count = 1, id = nil, border = true])
ImGui:nextColumn()
index = ImGui:getColumnIndex()
width = ImGui:getColumnWidth([column_index = -1])
ImGui:setColumnWidth(column_index, width)
offset = ImGui:getColumnOffset([column_index = -1])
ImGui:setColumnOffset(column_index, offset)
number = ImGui:getColumnsCount()
</syntaxhighlight>


callback_data:setSelectionEnd(s_end)
== Tab Bars, Tabs ==
s_end = callback_data:getSelectionEnd()
<syntaxhighlight lang="lua">
 
bool = ImGui:beginTabBar(str_id [, ImGui.TabBarFlags = 0])
callback_data:setSelection(s_start, s_end)
ImGui:endTabBar()
s_start, s_end = callback_data:getSelection()
p_open, bool = ImGui:beginTabItem(label, p_open [, ImGui.TabItemFlags = 0])
 
ImGui:endTabItem()
callback_data:selectAll()
ImGui:setTabItemClosed(tab_or_docked_window_label)
callback_data:clearSelection()
ImGui:tabItemButton(label [, ImGui.TabItemFlags = 0])
bool = callback_data:hasSelection()
 
callback_data:deleteChars(position, bytesCount)
callback_data:insertChars(position, text)
</syntaxhighlight>
</syntaxhighlight>


'''Example''':
== Logging/Capture ==
All text output from the interface can be captured into tty/file/clipboard. By default, tree nodes are automatically opened during logging.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
require "ImGui"
ImGui:logToTTY(auto_open_depth = -1)
 
ImGui:logToFile(auto_open_depth = -1, filename = nil)
ui = ImGui.new()
ImGui:logToClipboard(auto_open_depth = -1)
stage:addChild(ui)
ImGui:logFinish()  
ImGui:logButtons()  
ImGui:logText(text)
</syntaxhighlight>


local testMessage1 = ""
== Drag and drop ==
local testMessage2 = ""
<syntaxhighlight lang="lua">
local testMessage3 = ""
flag = ImGui:beginDragDropSource([ImGui.DragDropFlags flags = 0])
flag = ImGui:setNumDragDropPayload(str_type, number [, ImGui.Cond cond = 0])
flag = ImGui:setStrDragDropPayload(str_type, string [, ImGui.Cond cond = 0])
ImGui:endDragDropSource()
flag = ImGui:beginDragDropTarget()
ImGuiPayload = ImGui:acceptDragDropPayload(type [, ImGui.DragDropFlags flags = 0])
ImGui:endDragDropTarget()
ImGuiPayload = ImGui:getDragDropPayload()
</syntaxhighlight>


-- Add ".." at the end of current input string
'''Payload''':
function myCallback1(data)
<syntaxhighlight lang="lua">
data:insertChars(data:getCursorPos(), "..")
number = ImGuiPayload:getNumData()
end
string = ImGuiPayload:getStrData()
ImGuiPayload:clear()
number = ImGuiPayload:getDataSize()
flag = ImGuiPayload:isDataType(type) -- type must be the same as in "ImGui:acceptDragDropPayload(type)"
flag = ImGuiPayload:isPreview()
flag = ImGuiPayload:isDelivery()
</syntaxhighlight>
 
'''Usage example''':
<syntaxhighlight lang="lua">
require "ImGui"


-- Replace all chars if UP/DOWN arrow is pressed
local imgui = ImGui.new()
function myCallback2(data)
stage:addChild(imgui)
local key = data:getEventKey()
if (key == key_code.UP) then
data:deleteChars(0, data:getBufTextLen())
data:insertChars(0, "Pressed Up!")
data:selectAll()
elseif (key == key_code.DOWN) then
data:deleteChars(0, data:getBufTextLen())
data:insertChars(0, "Pressed Down!")
data:selectAll()
end
end


-- Switch case of the first char
local names = {
function myCallback3(data)
"Bobby", "Beatrice", "Betty",
local buf = data:getBuf()
"Brianna", "Barry", "Bernard",
local s = buf:sub(1,1)
"Bibi", "Blaine", "Bryn"
if ((s >= 'a' and s <= 'z') or (s >= 'A' and s <= 'Z')) then
}
local first = string.char(string.byte(s) ~ 32)
-- modes:
data:setBuf(first .. buf:sub(2))
local Mode_Copy = 0
data:setBufDirty(true)
local Mode_Move = 1
end
local Mode_Swap = 2
end
local mode = 0 -- current mode


function enterFrame(e)
function onEnterFrame(e)
ui:newFrame(e.deltaTime)
imgui:newFrame(e.deltaTime)
testMessage1 = ui:inputText(
if (imgui:radioButton("Copy", mode == Mode_Copy)) then mode = Mode_Copy end imgui:sameLine()
"Label1",  
if (imgui:radioButton("Move", mode == Mode_Move)) then mode = Mode_Move end imgui:sameLine()
testMessage1,
if (imgui:radioButton("Swap", mode == Mode_Swap)) then mode = Mode_Swap end
64,  
ImGui.InputTextFlags_CallbackCompletion,
for i,v in ipairs(names) do
myCallback1
imgui:pushID(i)
)
if (((i-1) % 3) ~= 0) then imgui:sameLine() end
testMessage2 = ui:inputText(
"Label2",  
imgui:button(v, 60, 60)
testMessage2,  
64,
if (imgui:beginDragDropSource(ImGui.DragDropFlags_None)) then
ImGui.InputTextFlags_CallbackHistory,
--imgui:setStrDragDropPayload("DND_DEMO_CELL", "ID_"..i) -- used for strings
myCallback2
imgui:setNumDragDropPayload("DND_DEMO_CELL", i) -- used for numbers
)
testMessage3 = ui:inputText(
if (mode == Mode_Copy) then imgui:text(("Copy %s"):format(v)) end
"Label3",  
if (mode == Mode_Move) then imgui:text(("Move %s"):format(v)) end
testMessage3,  
if (mode == Mode_Swap) then imgui:text(("Swap %s"):format(v)) end
64,
imgui:endDragDropSource()
ImGui.InputTextFlags_CallbackEdit,
end
myCallback3
)
if (imgui:beginDragDropTarget()) then
local payload = imgui:acceptDragDropPayload("DND_DEMO_CELL")
ui:render()
if (payload) then
ui:endFrame()
--local payload_n = tonumber(payload:getStrData():sub(4))  -- if "setStrDragDropPayload" was used
end
local payload_n = payload:getNumData() -- if "setNumDragDropPayload" was used
 
stage:addEventListener("enterFrame", enterFrame)
if (mode == Mode_Copy) then
</syntaxhighlight>
names[i] = names[payload_n];
 
end
=== Widgets: Color Editor/Picker ===
if (mode == Mode_Move) then
<syntaxhighlight lang="lua">
names[i] = names[payload_n];
hexColor, is_touching = ImGui:colorEdit3(label, color [, ImGui.ColorEditFlags = 0]) -- alpha ignored, no need to pass it!
names[payload_n] = "";
hexColor, alpha, is_touching = ImGui:colorEdit4(label, color [, alpha = 1, ImGui.ColorEditFlags = 0])
end
hexColor, is_touching = ImGui:colorPicker3(label, color [, ImGui.ColorEditFlags = 0])
hexColor, alpha, originalColor, originalAlpha, is_touching = ImGui:colorPicker4(label, color [, alpha = 1, original_color = 0xffffff, original_alpha = 1, ImGui.ColorEditFlags = 0])
if (mode == Mode_Swap) then
isHoveringFlag = ImGui:colorButton(string_ID, color [, alpha = 1, ImGui.ColorEditFlags = 0, w = 0, h = 0])
names[i], names[payload_n] = names[payload_n], names[i]
ImGui:setColorEditOptions(ImGui.ColorEditFlags)
end
end
imgui:endDragDropTarget()
end
imgui:popID()
end
imgui:render()
imgui:endFrame()
end
 
stage:addEventListener("enterFrame", onEnterFrame)
</syntaxhighlight>
</syntaxhighlight>


=== Widgets: Trees ===
== Clipping ==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
is_openFlag = ImGui:treeNode(label [, format_string])
ImGui:pushClipRect(min_x, min_y, max_x, max_y, intersect_with_current_clip_rect)
ImGui:treeNodeEx(label, ImGui.TreeNodeFlags [, format_string])
ImGui:popClipRect()
ImGui:treePush(str_id)
</syntaxhighlight>
ImGui:treePop()
 
number = ImGui:getTreeNodeToLabelSpacing()
== ImGuiListClipper ==
is_openFlag, p_open = ImGui:collapsingHeader(label, p_open [, ImGui.TreeNodeFlags = 0])
Try to avoid creating new instances in "enterFrame" event.
is_openFlag = ImGui:collapsingHeader(label [, ImGui.TreeNodeFlags = 0])
ImGui:setNextItemOpen(is_open, ImGui.Cond)
</syntaxhighlight>


=== Widgets: Selectables ===
'''Constructor''':
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
result?, selected = ImGui:selectable(label, selected [, ImGui.SelectableFlags = 0, w = 0, h = 0])
instance = ImGuiListClipper.new()
</syntaxhighlight>
</syntaxhighlight>


=== Widgets: List Boxes ===
'''Methods''':
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
current_item, is_openFlag = ImGui:listBox(label, current_item, item_table [, max_visible_items = -1]) -- item_table: {"Item0", "Item1", ...}
ImGuiListClipper:beginClip(number_of_items [, item_height = -1]) -- if item_height <= 0 then it is calculated automatically
result? = ImGui:listBoxHeader(label [, w = 0, h = 0])
ImGuiListClipper:endClip()
result? = ImGui:listBoxHeader2(label, items_count)
bool = ImGuiListClipper:step()
ImGui:listBoxFooter()
number = ImGuiListClipper:getDisplayStart()
number = ImGuiListClipper:getDisplayEnd()
number = ImGuiListClipper:getStartPosY()
number = ImGuiListClipper:getItemsCount()
ImGuiListClipper:forceDisplayRangeByIndices(number_min, number_max)
</syntaxhighlight>
</syntaxhighlight>


=== Widgets: Data Plotting ===
'''Usage example''':
'''Caching''':
<syntaxhighlight lang="lua">
require "ImGui"


If you have big array of points it is better to cache it instead of translating lua table to C++ vector every time you call `ImGui:plotLines()`. But in this case you need to manage memory by yourself (free points pointer when you dont need it).
local imgui = ImGui.new()
<syntaxhighlight lang="lua">
stage:addChild(imgui)
-- store points in memory
-- points_table: {0.01, 0.5, 10, -50, ...}
-- ptr: c++ pointer to a given vector
ptr = ImGui.cachePoints(points_table)


-- delete points from memory
clipper = ImGuiListClipper.new()
ImGui.freePoints(ptr)
</syntaxhighlight>


'''Plot functions''':
function onEnterFrame(e)
<syntaxhighlight lang="lua">
imgui:newFrame(e.deltaTime)
ImGui:plotCachedLines(label, ptr, len [, values_offset = 0, overlay_text = nil, scale_min = math.huge, scale_max = math.huge, w = 0, h = 0]) -- len (number): points array lenght
ImGui:plotCachedHistogram(label, ptr, len [, values_offset = 0, overlay_text = nil, scale_min = math.huge, scale_max = math.huge, w = 0, h = 0]) -- len (number): points array lenght
ImGui:plotLines(label, points_table [, values_offset = 0, overlay_text = nil, scale_min = math.huge, scale_max = math.huge, w = 0, h = 0])
ImGui:plotHistogram(label, points_table [, values_offset = 0, overlay_text = nil, scale_min = math.huge, scale_max = math.huge, w = 0, h = 0])
</syntaxhighlight>


'''Example''':
if (imgui:beginWindow("Clipper demo")) then
<syntaxhighlight lang="lua">
if (imgui:beginTable("table", 3)) then
-- delete ptr if it exist
imgui:tableSetupScrollFreeze(0, 1) -- cols, rows
function deletePtr()
imgui:tableSetupColumn("One")
if pointsPtr then
imgui:tableSetupColumn("Two")
ImGui.freePoints(pointsPtr)
imgui:tableSetupColumn("Three")
imgui:tableHeadersRow()
 
clipper:beginClip(100)
while (clipper:step()) do
for row = clipper:getDisplayStart(), clipper:getDisplayEnd() do
imgui:tableNextRow()
for column = 1, 3 do
imgui:tableSetColumnIndex(column - 1)
imgui:text(("col: %d; row: %d"):format(column, row))
end
end
end
clipper:endClip()
 
imgui:endTable()
end
end
end
imgui:endWindow()
imgui:endFrame()
imgui:render()
end
end


function onEnterFrame()
stage:addEventListener("enterFrame", onEnterFrame)
ui:newFrame(e.deltaTime)
if ui:button("Generate") then
deletePtr()
points = generatePoints() -- returns big array
pointsPtr = ImGui.cachePoints(points)
end
if pointsPtr then
ui:plotCachedLines("Big data", pointsPtr, #points)
end
ui:render()
ui:endFrame()
end
 
-- do not forget to clear memory when app is closing
function onAppExit()
deletePtr()
end
</syntaxhighlight>
</syntaxhighlight>


== Widgets: Value() Helpers ==
== Context ==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
ImGui:value(prefix, bool)
string OR nil = ImGui:getHoveredWindow()
ImGui:value(prefix, number)
string OR nil = ImGui:getHoveredWindowRoot()
ImGui:value(prefix, float, format_string)
string OR nil = ImGui:getHoveredWindowUnderMovingWindow()
string OR nil = ImGui:getMovingWindow()
string OR nil = ImGui:getActiveIdWindow()
id = ImGui:getActiveId()
id = ImGui:getActiveIdPreviousFrame()
number = ImGui:getActiveIdTimer()
id = ImGui:getActiveIdAllowOverlap()
id = ImGui:getHoveredId()
id = ImGui:getHoveredIdPreviousFrame()
number = ImGui:getHoveredIdTimer()
id = ImGui:getHoveredIdAllowOverlap()
bool = ImGui:getDragDropActive()
id = ImGui:getDragDropPayloadSourceId()
string = ImGui:getDragDropPayloadDataType()
number = ImGui:getDragDropPayloadDataSize()
</syntaxhighlight>
</syntaxhighlight>


== Widgets: Menus ==
== Focus, Activation ==
* Prefer using "SetItemDefaultFocus()" over "if (IsWindowAppearing()) SetScrollHereY()" when applicable to signify "this is the default item"
* Most of the functions are referring to the last/previous item we submitted.
* See Demo Window under "Widgets->Querying Status" for an interactive visualization of most of those functions.
 
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
result? = ImGui:beginMenuBar()
ImGui:setItemDefaultFocus()
ImGui:endMenuBar()
ImGui:setKeyboardFocusHere([offset = 0])
result? = ImGui:beginMainMenuBar()
flag = ImGui:isItemHovered([ImGui.HoveredFlags = 0])
ImGui:endMainMenuBar()
flag = ImGui:isItemActive()
result = ImGui:beginMenu(label [, enabled = true])
flag = ImGui:isItemFocused()
result = ImGui:beginMenuEx(label, [icon = "", enabled = true])
flag = ImGui:isItemClicked(mouse_button)
ImGui:endMenu()
flag = ImGui:isItemVisible()
result = ImGui:menuItem(label [, shortcut = "", selected = false, enabled = true])
flag = ImGui:isItemEdited()
result = ImGui:menuItemEx(label, [icon = "", shortcut = "", selected = false, enabled = true])
flag = ImGui:isItemActivated()
ImGui:beginTooltip()
flag = ImGui:isItemDeactivated()
ImGui:endTooltip()
flag = ImGui:isItemDeactivatedAfterEdit()
ImGui:setTooltip(text)
flag = ImGui:isItemToggledOpen()
flag = ImGui:isAnyItemHovered()
flag = ImGui:isAnyItemActive()
flag = ImGui:isAnyItemFocused()
minX, minY, maxX, maxY = ImGui:getItemRect()
x, y = ImGui:getItemRectMin()
x, y = ImGui:getItemRectMax()
w, h = ImGui:getItemRectSize()
ImGui:setItemAllowOverlap()
</syntaxhighlight>
</syntaxhighlight>


== Popups, Modals ==
== INPUTS ==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
result? = ImGui:beginPopup(str_id [, ImGui.WindowFlags = 0])
ImGui:onMouseHover(event)
p_open, result? = ImGui:beginPopupModal(str_id, p_open [, ImGui.WindowFlags = 0])
ImGui:onMouseMove(event)
ImGui:endPopup()
ImGui:onMouseDown(event)
ImGui:openPopup(str_id [, ImGui.PopupFlags = 0])
ImGui:onMouseUp(event)
ImGui:openPopupOnItemClick(str_id [, ImGui.PopupFlags = 0])
ImGui:onMouseWheel(event)
ImGui:closeCurrentPopup()
 
result? = ImGui:beginPopupContextItem(str_id [, ImGui.PopupFlags = 0])
ImGui:onTouchMove(event)
result? = ImGui:beginPopupContextWindow(str_id [, ImGui.PopupFlags = 0])
ImGui:onTouchBegin(event)
result? = ImGui:beginPopupContextVoid(str_id [, ImGui.PopupFlags = 0])
ImGui:onTouchEnd(event)
result? = ImGui:isPopupOpen(str_id [, ImGui.PopupFlags = 0])
ImGui:onTouchCancel(event)
 
ImGui:onKeyUp(event)
ImGui:onKeyDown(event)
ImGui:onKeyChar(event)
</syntaxhighlight>
 
'''Usage examples''':
<syntaxhighlight lang="lua">
local UI = ImGui.new(nil, false, false, false)
</syntaxhighlight>
</syntaxhighlight>


== Tables ==
'''Mouse'''
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
flag = ImGui:beginTable(str_id, column [, ImGui.TableFlags = 0, outer_w = 0, outer_h = 0, inner_width = 0])
stage:addEventListener("mouseHover", function(e) UI:onMouseHover(e) end)
ImGui:endTable()
stage:addEventListener("mouseMove", function(e) UI:onMouseMove(e) end)
ImGui:tableNextRow([ImGui.TableRowFlags = 0, min_row_height = 0])
stage:addEventListener("mouseDown", function(e) UI:onMouseDown(e) end)
flag = ImGui:tableNextColumn()
stage:addEventListener("mouseUp", function(e) UI:onMouseUp(e) end)
flag = ImGui:tableSetColumnIndex(column_n)
stage:addEventListener("mouseWheel", function(e) UI:onMouseWheel(e) end)
ImGui:tableSetupColumn(label [, ImGui.TableColumnFlags = 0, init_width_or_weight = 0, user_id = 0])
ImGui:tableSetupScrollFreeze(cols, rows)
ImGui:tableHeadersRow()
TableSortSpecs = ImGui:tableGetSortSpecs() -- see below
number = ImGui:tableGetColumnCount()
number = ImGui:tableGetColumnIndex()
number = ImGui:tableGetRowIndex()
string = ImGui:tableGetColumnName([column_n = -1])
ImGuiTableColumnFlags = ImGui:tableGetColumnFlags([column_n = -1])
ImGui:tableSetBgColor(ImGui.TableBgTarget, color [, alpha = 1, column_n = -1])
</syntaxhighlight>
</syntaxhighlight>


== Table sort specs ==
'''Touch'''
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
number = TableSortSpecs:getSpecsCount() -- TableSortSpecs = ImGui:tableGetSortSpecs()
stage:addEventListener("touchesCancel", function(e) ui:onTouchCancel(e) end)
flag = TableSortSpecs:isSpecsDirty() -- TableSortSpecs = ImGui:tableGetSortSpecs()
stage:addEventListener("touchesMove", function(e) ui:onTouchMove(e) end)
TableSortSpecs:setSpecsDirty(flag) -- TableSortSpecs = ImGui:tableGetSortSpecs()
stage:addEventListener("touchesBegin", function(e) ui:onTouchBegin(e) end)
table = TableSortSpecs:getColumnSortSpecs() -- TableSortSpecs = ImGui:tableGetSortSpecs(), see below
stage:addEventListener("touchesEnd", function(e) ui:onTouchEnd(e) end)
</syntaxhighlight>
</syntaxhighlight>


== Table column sort specs ==
'''Keyboard'''
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- table = TableSortSpecs:getColumnSortSpecs()
stage:addEventListener("keyUp", function(e) UI:onKeyUp(e) end)
-- each value of this table is an object that have these functions:
stage:addEventListener("keyDown", function(e) UI:onKeyDown(e) end)
number = item:getColumnUserID()  
stage:addEventListener("keyChar", function(e) UI:onKeyChar(e) end)
number = item:getColumnIndex() -- 0 based
number = item:getSortOrder() -- used in multi sorted tables
number = item:getSortDirection() -- ImGui.SortDirection_Ascending OR ImGui.SortDirection_Descending
</syntaxhighlight>
</syntaxhighlight>
Example: https://github.com/MultiPain/Gideros_examples/blob/master/ImGuiTablesDemo/assets/TablesDemo.lua</br>


== Columns ==
== Miscellaneous Utilities ==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
ImGui:columns([count = 1, id = nil, border = true])
flag = ImGui:isRectVisible(w, h [, max_x, max_y])
ImGui:nextColumn()
number = ImGui:getTime()
index = ImGui:getColumnIndex()
number = ImGui:getFrameCount()
width = ImGui:getColumnWidth([column_index = -1])
str = ImGui:getStyleColorName(idx)
ImGui:setColumnWidth(column_index, width)
flag = ImGui:beginChildFrame(id, w, h [, ImGui.WindowFlags = 0]) -- id (number)
offset = ImGui:getColumnOffset([column_index = -1])
ImGui:endChildFrame()
ImGui:setColumnOffset(column_index, offset)
number = ImGui:getColumnsCount()
</syntaxhighlight>
</syntaxhighlight>


== Tab Bars, Tabs ==
=== Text Utilities ===
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool = ImGui:beginTabBar(str_id [, ImGui.TabBarFlags = 0])
w, h = ImGui:calcTextSize(text [, hide_text_after_double_hash = false, wrap_width = -1])
ImGui:endTabBar()
</syntaxhighlight>
p_open, bool = ImGui:beginTabItem(label, p_open [, ImGui.TabItemFlags = 0])
ImGui:endTabItem()
ImGui:setTabItemClosed(tab_or_docked_window_label)
ImGui:tabItemButton(label [, ImGui.TabItemFlags = 0])
</syntaxhighlight>


== Logging/Capture ==
=== Color convert ===
'''Note''': use ''DOT'' instead of ''COLON'', so you can use it without creating an ImGui object
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
ImGui:logToTTY(auto_open_depth = -1)  
r, g, b, a = ImGui.colorConvertHEXtoRGB(color [, alpha = 1])
ImGui:logToFile(auto_open_depth = -1, filename = nil)  
hex = ImGui.colorConvertRGBtoHEX(r, g, b)
ImGui:logToClipboard(auto_open_depth = -1)  
h, s, v = ImGui.colorConvertRGBtoHSV(r, g, b)
ImGui:logFinish()  
r, g, b = ImGui.colorConvertHSVtoRGB(h, s, v)
ImGui:logButtons()  
h, s, v = ImGui.colorConvertHEXtoHSV(hex)
ImGui:logText(text)  
hex = ImGui.colorConvertHSVtoHEX(h, s, v)
</syntaxhighlight>
</syntaxhighlight>


== Drag and drop ==
=== Inputs Utilities: Keyboard ===
* For 'int user_key_index' you can use your own indices/enums according to how your backend/engine stored them in io.KeysDown[].
* We don't know the meaning of those value. You can use GetKeyIndex() to map a ImGuiKey_ value into the user index.
 
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
flag = ImGui:beginDragDropSource([ImGui.DragDropFlags flags = 0])
string = ImGui:getKeyName(keyCode)
flag = ImGui:setNumDragDropPayload(str_type, number [, ImGui.Cond cond = 0])
flag = ImGui:isKeyDown(keyCode)
flag = ImGui:setStrDragDropPayload(str_type, string [, ImGui.Cond cond = 0])
flag = ImGui:isKeyPressed(keyCode [, repeat = true])
ImGui:endDragDropSource()
flag = ImGui:isKeyReleased(keyCode)
flag = ImGui:beginDragDropTarget()
number = ImGui:getKeyPressedAmount(keyCode, repeat_delay, rate)
ImGuiPayload = ImGui:acceptDragDropPayload(type [, ImGui.DragDropFlags flags = 0])
ImGui:setNextFrameWantCaptureKeyboard([want_capture_keyboard_value = true])
ImGui:endDragDropTarget()
ImGuiPayload = ImGui:getDragDropPayload()
</syntaxhighlight>
</syntaxhighlight>


'''Payload''':
=== Shortcut system ===
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
number = ImGuiPayload:getNumData()
-- (keyChord: an ImGuiKey optionally OR-ed with one or more ImGuiMod_XXX values (ImGuiKey | ImGuiMod_XXX))
string = ImGuiPayload:getStrData()
ImGui:shortcut(keyChord [, owner_id = 0, ImGui.InputFlags = 0])
ImGuiPayload:clear()
 
number = ImGuiPayload:getDataSize()
-- (useful to disable CTRL + TAB combo: ImGui:setShortcutRouting(ImGui.Mod_Ctrl | ImGui.Key_Tab, ImGui.KeyOwner_None))
flag = ImGuiPayload:isDataType(type) -- type must be the same as in "ImGui:acceptDragDropPayload(type)"
ImGui:setShortcutRouting(keyChord [, owner_id = 0, ImGui.InputFlags = 0])
flag = ImGuiPayload:isPreview()
 
flag = ImGuiPayload:isDelivery()
ImGui:setItemKeyOwner(keyCode [, ImGui.InputFlags = 0])
 
ImGui:setKeyOwner(keyCode, owner_id, [, ImGui.InputFlags = 0])
</syntaxhighlight>
</syntaxhighlight>


'''Usage example''':
'''Focused window and global application ''button'' shortcut example'''
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
require "ImGui"
require "ImGui"
Line 1,172: Line 1,412:
local imgui = ImGui.new()
local imgui = ImGui.new()
stage:addChild(imgui)
stage:addChild(imgui)
imgui:setClassicStyle()
function onEnterFrame(e)
imgui:newFrame(e.deltaTime)


local names = {
-- focused window button shortcut
"Bobby", "Beatrice", "Betty",
if imgui:button("PLAY##01", 32*2, 32*0.6) or imgui:shortcut(ImGui.Key_P) then
"Brianna", "Barry", "Bernard",
print(ImGui:getItemID()) -- 2102678615
"Bibi", "Blaine", "Bryn"
end
}
imgui:sameLine(32*2.5)
-- modes:
-- focused window button shortcut (using item ID)
local Mode_Copy = 0
if imgui:button("PLAY##02", 32*2, 32*0.6) or imgui:shortcut(ImGui.Key_Q, 8325, ImGui.FocusedFlags_AnyWindow) then
local Mode_Move = 1
print(ImGui:getItemID()) -- 8325
local Mode_Swap = 2
end
 
local mode = 0 -- current mode
-- global app button shortcut
if imgui:button("PLAY##03", 32*2, 32*0.6) or imgui:isKeyPressed(KeyCode.C) then
print(ImGui:getItemID()) -- 1157645807
end
 
imgui:render()
imgui:endFrame()
end
 
stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
</syntaxhighlight>
 
'''Global application ''checkbox'' shortcut example'''
<syntaxhighlight lang="lua">
require "ImGui"
 
local imgui = ImGui.new()
stage:addChild(imgui)
imgui:setClassicStyle()
 
-- some vars
local islooping = false


function onEnterFrame(e)
function onEnterFrame(e)
imgui:newFrame(e.deltaTime)
imgui:newFrame(e.deltaTime)
local ischanged = false
if (imgui:radioButton("Copy", mode == Mode_Copy)) then mode = Mode_Copy end imgui:sameLine()
 
if (imgui:radioButton("Move", mode == Mode_Move)) then mode = Mode_Move end imgui:sameLine()
islooping, ischanged = imgui:checkbox("looping(L)", islooping)
if (imgui:radioButton("Swap", mode == Mode_Swap)) then mode = Mode_Swap end
if imgui:isKeyPressed(KeyCode.L) then
islooping = not islooping
for i,v in ipairs(names) do
ischanged = true
imgui:pushID(i)
end
if (((i-1) % 3) ~= 0) then imgui:sameLine() end
if ischanged then
print("islooping", islooping)
imgui:button(v, 60, 60)
end
 
if (imgui:beginDragDropSource(ImGui.DragDropFlags_None)) then
imgui:render()
--imgui:setStrDragDropPayload("DND_DEMO_CELL", "ID_"..i) -- used for strings
imgui:endFrame()
imgui:setNumDragDropPayload("DND_DEMO_CELL", i) -- used for numbers
end
 
if (mode == Mode_Copy) then imgui:text(("Copy %s"):format(v)) end
stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
if (mode == Mode_Move) then imgui:text(("Move %s"):format(v)) end
</syntaxhighlight>
if (mode == Mode_Swap) then imgui:text(("Swap %s"):format(v)) end
 
imgui:endDragDropSource()
=== Inputs Utilities: Mouse ===
end
* To refer to a mouse button, you may use named enums in your code e.g. ImGuiMouseButton_Left, ImGuiMouseButton_Right.
* You can also use regular integer: it is forever guaranteed that 0=Left, 1=Right, 2=Middle.
if (imgui:beginDragDropTarget()) then
* Dragging operations are only reported after mouse has moved a certain distance away from the initial clicking position (see 'lock_threshold' and 'io.MouseDraggingThreshold')
local payload = imgui:acceptDragDropPayload("DND_DEMO_CELL")
 
if (payload) then
<syntaxhighlight lang="lua">
--local payload_n = tonumber(payload:getStrData():sub(4))  -- if "setStrDragDropPayload" was used
-- "mouse_button" is any gideros mouse button code
local payload_n = payload:getNumData() -- if "setNumDragDropPayload" was used
flag = ImGui:isMouseDown(mouse_button)
flag = ImGui:isMouseClicked(mouse_button [, repeat = false]) -- "mouse_button" is any gideros mouse button code
if (mode == Mode_Copy) then
flag = ImGui:isMouseReleased(mouse_button) -- "mouse_button" is any gideros mouse button code
names[i] = names[payload_n];
flag = ImGui:isMouseDoubleClicked(mouse_button) -- "mouse_button" is any gideros mouse button code
end
flag = ImGui:isMouseHoveringRect(min_x, min_y, max_x, max_y [, clip = true])
if (mode == Mode_Move) then
flag = ImGui:isMousePosValid([x = inf, y = inf])
names[i] = names[payload_n];
flag = ImGui:isAnyMouseDown()
names[payload_n] = "";
x, y = ImGui:getMousePos()
end
x, y = ImGui:getMousePosOnOpeningCurrentPopup()
flag = ImGui:isMouseDragging(mouse_button [, lock_threshold = -1]) -- "mouse_button" is any gideros mouse button code
if (mode == Mode_Swap) then
x, y = ImGui:getMouseDragDelta(mouse_button [, lock_threshold = -1]) -- "mouse_button" is any gideros mouse button code
names[i], names[payload_n] = names[payload_n], names[i]
ImGui:resetMouseDragDelta(mouse_button) -- "mouse_button" is any gideros mouse button code
end
ImGuiMouseCursor = ImGui:getMouseCursor()
end
ImGui:setMouseCursor(ImGui.MouseCursor)
imgui:endDragDropTarget()
ImGui:setNextFrameWantCaptureMouse([want_capture_mouse_value = true])
end
ImGui:setNextFrameWantCaptureKeyboard([want_capture_keyboard_value = true])
imgui:popID()
ImGui:updateCursor()
end
imgui:render()
imgui:endFrame()
end
 
stage:addEventListener("enterFrame", onEnterFrame)
</syntaxhighlight>
</syntaxhighlight>


== Clipping ==
== FONTS ==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
ImGui:pushClipRect(min_x, min_y, max_x, max_y, intersect_with_current_clip_rect)
IO = imgui:getIO()
ImGui:popClipRect()
FontAtlas = IO:getFonts()
</syntaxhighlight>


== ImGuiListClipper ==
Font = FontAtlas:addFont(ttf_font_path, font_size [, options])
Try to avoid creating new instances in "enterFrame" event.


'''Constructor''':
-- options (table): all parameters are optional
<syntaxhighlight lang="lua">
--     fontDataOwnedByAtlas - bool
instance = ImGuiListClipper.new()
--     pixelSnapH - bool
</syntaxhighlight>
--     mergeMode - bool
 
--     fontNo - number
'''Methods''':
--     oversampleH - number
<syntaxhighlight lang="lua">
--     oversampleV - number
ImGuiListClipper:beginClip(number_of_items [, item_height = -1]) -- if item_height <= 0 then it is calculated automatically
--     glyphExtraSpacingX - number
ImGuiListClipper:endClip()
--     glyphExtraSpacingY - number
bool = ImGuiListClipper:step()
--     glyphOffsetX - number
number = ImGuiListClipper:getDisplayStart()
--     glyphOffsetY - number
number = ImGuiListClipper:getDisplayEnd()
--     glyphMinAdvanceX - number
number = ImGuiListClipper:getStartPosY()
--     glyphMaxAdvanceX - number
number = ImGuiListClipper:getItemsCount()
--     rasterizerFlags - number
ImGuiListClipper:forceDisplayRangeByIndices(number_min, number_max)
--     rasterizerMultiply - number
</syntaxhighlight>
--
--     glyphs - table:
--     text(string): represents available chars
--     chars(table): list of specific char code (example: {0x7262, ...})
--     ranges(table): predefined glyph ranges (example: {ImGui.GlyphRanges_Default, ImGui.GlyphRanges_Japanese, ...})
FontAtlas:addFonts(fontsDescription)
-- fontsDescriptions(table):
--      description(table):
--          ttf_font_path(string): path to a font
--          font_size(number): font size
--          options(table): see description above
-- example:
-- FontAtlas:addFonts{ {"fonts/DroidSans.ttf", 16}, {"fonts/ProggyTiny.ttf", 16} }


'''Usage example''':
Font = FontAtlas:getFont([index]) -- get font by index (if index is 0 or nil you will get default font instance)
<syntaxhighlight lang="lua">
FontAtlas:build() -- call after multiple FontAtlas:addFont(...) calls to update ImGui font atlas
require "ImGui"
FontAtlas:clearInputData()
 
FontAtlas:clearTexData()
local imgui = ImGui.new()
FontAtlas:clearFonts()
stage:addChild(imgui)
FontAtlas:clear()
table = FontAtlas:getFonts() -- returns a table with all fonts (included default)
flag = FontAtlas:isBuilt()
number = FontAtlas:addCustomRectRegular(width, height)
number = FontAtlas:addCustomRectFontGlyph(font, id, width, height, advance_x [, offset_x, offset_y])
w, h, x, y, glyph_id, offset_x, offset_y, font, is_packed_flag = FontAtlas:getCustomRectByIndex(index)


clipper = ImGuiListClipper.new()
ImGui:pushFont(font) -- font (table): object returned by FontAtlas:addFont(...) or FontAtlas:getFont([index])
ImGui:popFont()
</syntaxhighlight>


function onEnterFrame(e)
'''Minimal example''':
imgui:newFrame(e.deltaTime)
<syntaxhighlight lang="lua">
local UI = ImGui.new()
local IO = UI:getIO()
local FontAtlas = IO:getFonts()
local VDS_font = FontAtlas:addFont("fonts/VDS.ttf", 16, {
    oversampleH = 2,
    oversampleV = 2,
glyphs = {
ranges = {ImGui.GlyphRanges_Cyrillic}
}
})
IO:setFontDefault(VDS_font)
FontAtlas:build()
stage:addChild(UI)


if (imgui:beginWindow("Clipper demo")) then
-- you can use multiple fonts at the same time
if (imgui:beginTable("table", 3)) then
function enterFrame(e)
imgui:tableSetupScrollFreeze(0, 1) -- cols, rows
UI:newFrame(e.deltaTime)
imgui:tableSetupColumn("One")
imgui:tableSetupColumn("Two")
UI:pushFont(font1)
imgui:tableSetupColumn("Three")
UI:text("Font1")
imgui:tableHeadersRow()
UI:popFont()
UI:pushFont(font2)
UI:text("Font2")
UI:popFont()
UI:render()
UI:endFrame()
end
</syntaxhighlight>


clipper:beginClip(100)
'''Glyphs example''':
while (clipper:step()) do
<syntaxhighlight lang="lua">
for row = clipper:getDisplayStart(), clipper:getDisplayEnd() do
local fonts = io:getFonts()
imgui:tableNextRow()
fonts:addFont(font_path, font_size, {
for column = 1, 3 do
glyphs = {
imgui:tableSetColumnIndex(column - 1)
ranges = {
imgui:text(("col: %d; row: %d"):format(column, row))
{
end
0x2590,0x2593, -- range1
end
0x2660,0x266B  -- range2
end
-- ...
clipper:endClip()
},
 
ImGui.GlyphRanges_Cyrillic,
imgui:endTable()
{
end
0x01C0, 0x01C3 -- range3
end
},
imgui:endWindow()
ImGui.GlyphRanges_Korean
 
},
imgui:endFrame()
imgui:render()
-- same structure:
end
ranges = {
 
{
stage:addEventListener("enterFrame", onEnterFrame)
0x2590,0x2593, -- range1
0x2660,0x266B, -- range2
0x01C0,0x01C3  -- range3
-- ...
},
ImGui.GlyphRanges_Cyrillic,
ImGui.GlyphRanges_Korean
}
},
mergeMode = true, -- merge into previous font
})
fonts:build()
</syntaxhighlight>
</syntaxhighlight>


== ImGuiTextFilter ==
'''Icons example''':
Try to avoid creating new instaces in "enterFrame" event.
 
'''Constructor''':
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
filter = ImGuiTextFilter.new()
local icon = utf8.char(0x2590)
ImGui:text("My icon >>" .. icon .. " << !!!")
 
-- or with new Luau support:
ImGui:text("My icon >> \u{2590} << !!!")
-- can be also stored in memory:
local icon = "\u{2590}"
</syntaxhighlight>
</syntaxhighlight>


'''Methods''':
=== Font ===
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
isValueChanged = filter:draw(label [, width = 0]) -- draws the input field
number = Font:getSize()
isValueChanged = filter:drawWithHint(label, hint [, width = 0]) -- draws the input field (using ImGui:inutTextWithHint())
FontAtlas = Font:getContainerAtlas()
 
Font:setScale(number)
filter:setBuffer(text) -- set filter text
number = Font:getScale()
filter:build() -- update filter internals (see example below)
number = Font:getAscent()
bool = filter:passFilter(text) -- returns true if filter input matches with "text"
number = Font:getDescent()
bool = Font:isLoaded()
string = Font:getDebugName()
w, h = Font:calcTextSizeA(size, max_width, wrap_width, string)
Font:calcWordWrapPositionA(scale, string, wrap_width) -- not tested
</syntaxhighlight>
</syntaxhighlight>


'''Usage example 1''':</br>
== Tables ==
https://github.com/MultiPain/Gideros_ImGui/blob/master/imgui_src/imgui_demo.cpp#L5657
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
require "ImGui"
flag = ImGui:beginTable(str_id, column [, ImGui.TableFlags = 0, outer_w = 0, outer_h = 0, inner_width = 0])
 
ImGui:endTable()
local imgui = ImGui.new()
ImGui:tableNextRow([ImGui.TableRowFlags = 0, min_row_height = 0])
stage:addChild(imgui)
flag = ImGui:tableNextColumn()
flag = ImGui:tableSetColumnIndex(column_n)
ImGui:tableSetupColumn(label [, ImGui.TableColumnFlags = 0, init_width_or_weight = 0, user_id = 0])
ImGui:tableSetupScrollFreeze(cols, rows)
ImGui:tableHeadersRow()
TableSortSpecs = ImGui:tableGetSortSpecs() -- see below
number = ImGui:tableGetColumnCount()
number = ImGui:tableGetColumnIndex()
number = ImGui:tableGetRowIndex()
string = ImGui:tableGetColumnName([column_n = -1])
ImGuiTableColumnFlags = ImGui:tableGetColumnFlags([column_n = -1])
ImGui:tableSetBgColor(ImGui.TableBgTarget, color [, alpha = 1, column_n = -1])
</syntaxhighlight>


local filter = ImGuiTextFilter.new()
=== Table sort specs ===
local items = { "aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world" }
<syntaxhighlight lang="lua">
number = TableSortSpecs:getSpecsCount() -- TableSortSpecs = ImGui:tableGetSortSpecs()
flag = TableSortSpecs:isSpecsDirty() -- TableSortSpecs = ImGui:tableGetSortSpecs()
TableSortSpecs:setSpecsDirty(flag) -- TableSortSpecs = ImGui:tableGetSortSpecs()
table = TableSortSpecs:getColumnSortSpecs() -- TableSortSpecs = ImGui:tableGetSortSpecs(), see below
</syntaxhighlight>


function onEnterFrame(e)
=== Table column sort specs ===
imgui:newFrame(e.deltaTime)
<syntaxhighlight lang="lua">
 
-- table = TableSortSpecs:getColumnSortSpecs()
if (imgui:beginWindow("Filter demo")) then
-- each value of this table is an object that have these functions:
imgui:text([[
number = item:getColumnUserID()  
Filter usage:
number = item:getColumnIndex() -- 0 based
""        display all lines
number = item:getSortOrder() -- used in multi sorted tables
"xxx"      display lines containing "xxx"
number = item:getSortDirection() -- ImGui.SortDirection_Ascending OR ImGui.SortDirection_Descending
"xxx,yyy"  display lines containing "xxx" or "yyy"
</syntaxhighlight>
"-xxx"    hide lines containing "xxx"
Example: https://github.com/MultiPain/Gideros_examples/blob/master/ImGuiTablesDemo/assets/TablesDemo.lua</br>
]])


filter:draw("Filter")
== ImGuiTextFilter ==
Try to avoid creating new instaces in "enterFrame" event.


for i, text in ipairs(items) do
'''Constructor''':
if filter:passFilter(text) then
<syntaxhighlight lang="lua">
imgui:bulletText(text)
filter = ImGuiTextFilter.new()
end
</syntaxhighlight>
end
end
imgui:endWindow()


imgui:endFrame()
'''Methods''':
imgui:render()
<syntaxhighlight lang="lua">
end
-- draws the input field
isValueChanged = filter:draw(label [, width = 0])
-- draws the input field (using ImGui:inutTextWithHint())
isValueChanged = filter:drawWithHint(label, hint [, width = 0])


stage:addEventListener("enterFrame", onEnterFrame)
filter:setBuffer(text) -- set filter text
filter:build() -- update filter internals (see example below)
bool = filter:passFilter(text) -- returns true if filter input matches with "text"
</syntaxhighlight>
</syntaxhighlight>


'''Usage example 2''':
'''Usage example 1''':
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
require "ImGui"
require "ImGui"
Line 1,373: Line 1,707:


local filter = ImGuiTextFilter.new()
local filter = ImGuiTextFilter.new()
local searchText = ""
local items = { "aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world" }
local items = { "aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world" }


Line 1,379: Line 1,712:
imgui:newFrame(e.deltaTime)
imgui:newFrame(e.deltaTime)


-- draw standart text input control
if (imgui:beginWindow("Filter demo")) then
-- filter:drawWithHint("Filter", "Search")
imgui:text([[
-- draw custom control
Filter usage:
local ischanged = false
""        display all lines
searchText, ischanged = imgui:inputText("Filter", searchText, 256, ImGui.InputTextFlags_EnterReturnsTrue)
"xxx"      display lines containing "xxx"
if ischanged then
"xxx,yyy"  display lines containing "xxx" or "yyy"
filter:setBuffer(searchText)
"-xxx"    hide lines containing "xxx"
-- try to avoid calling "build" function every frame
]])
filter:build()
 
end
filter:draw("Filter")


for i, item in ipairs(items) do
for i, text in ipairs(items) do
if not filter:passFilter(item) then
if filter:passFilter(text) then
continue
imgui:bulletText(text)
end
end
end
imgui:bulletText(item)
end
end
imgui:endWindow()


imgui:endFrame()
imgui:endFrame()
Line 1,404: Line 1,738:
</syntaxhighlight>
</syntaxhighlight>


== Focus, Activation ==
'''Usage example 2''':
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
ImGui:setItemDefaultFocus()
require "ImGui"
ImGui:setKeyboardFocusHere([offset = 0])
 
flag = ImGui:isItemHovered([ImGui.HoveredFlags = 0])
local imgui = ImGui.new()
flag = ImGui:isItemActive()
stage:addChild(imgui)
flag = ImGui:isItemFocused()
 
flag = ImGui:isItemClicked(mouse_button)
local filter = ImGuiTextFilter.new()
flag = ImGui:isItemVisible()
local searchText = ""
flag = ImGui:isItemEdited()
local items = { "aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world" }
flag = ImGui:isItemActivated()
flag = ImGui:isItemDeactivated()
flag = ImGui:isItemDeactivatedAfterEdit()
flag = ImGui:isItemToggledOpen()
flag = ImGui:isAnyItemHovered()
flag = ImGui:isAnyItemActive()
flag = ImGui:isAnyItemFocused()
minX, minY, maxX, maxY = ImGui:getItemRect()
x, y = ImGui:getItemRectMin()
x, y = ImGui:getItemRectMax()
w, h = ImGui:getItemRectSize()
ImGui:setItemAllowOverlap()
</syntaxhighlight>


== Miscellaneous Utilities ==
function onEnterFrame(e)
<syntaxhighlight lang="lua">
imgui:newFrame(e.deltaTime)
flag = ImGui:isRectVisible(w, h [, max_x, max_y])
number = ImGui:getTime()
number = ImGui:getFrameCount()
str = ImGui:getStyleColorName(idx)
flag = ImGui:beginChildFrame(id, w, h [, ImGui.WindowFlags = 0]) -- id (number)
ImGui:endChildFrame()
</syntaxhighlight>


== Text Utilities ==
-- draw standart text input control
<syntaxhighlight lang="lua">
-- filter:drawWithHint("Filter", "Search")
w, h = ImGui:calcTextSize(text [, hide_text_after_double_hash = false, wrap_width = -1])
-- draw custom control
local ischanged = false
searchText, ischanged = imgui:inputText("Filter", searchText, 256, ImGui.InputTextFlags_EnterReturnsTrue)
if ischanged then
filter:setBuffer(searchText)
-- try to avoid calling "build" function every frame
filter:build()
end
 
for i, item in ipairs(items) do
if not filter:passFilter(item) then
continue
end
imgui:bulletText(item)
end
 
imgui:endFrame()
imgui:render()
end
 
stage:addEventListener("enterFrame", onEnterFrame)
</syntaxhighlight>
</syntaxhighlight>


== Inputs Utilities: Keyboard ==
== TextEditor ==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
string = ImGui:getKeyName(keyCode)
-- otherTextEditor: another "ImGuiTextEditor" instance to copy setting
flag = ImGui:isKeyDown(keyCode)
TextEditor = ImGuiTextEditor.new([other_text_editor])
flag = ImGui:isKeyPressed(keyCode [, repeat = true])
</syntaxhighlight>
flag = ImGui:isKeyReleased(keyCode)
 
number = ImGui:getKeyPressedAmount(keyCode, repeat_delay, rate)
ImGui:setNextFrameWantCaptureKeyboard([want_capture_keyboard_value = true])
</syntaxhighlight>
 
== Shortcut system ==
<syntaxhighlight lang="lua">
ImGui:shortcut(keyChord [, owner_id = 0, ImGui.InputFlags = 0]) -- keyChord: an ImGuiKey optionally OR-ed with one or more ImGuiMod_XXX values (ImGuiKey | ImGuiMod_XXX))
ImGui:setShortcutRouting(keyChord [, owner_id = 0, ImGui.InputFlags = 0]) -- useful to disable CTRL + TAB combo: ImGui:setShortcutRouting(ImGui.Mod_Ctrl | ImGui.Key_Tab, ImGui.KeyOwner_None)
 
ImGui:setItemKeyOwner(keyCode [, ImGui.InputFlags = 0])
 
ImGui:setKeyOwner(keyCode, owner_id, [, ImGui.InputFlags = 0])
</syntaxhighlight>
 
== Inputs Utilities: Mouse ==
<syntaxhighlight lang="lua">
flag = ImGui:isMouseDown(mouse_button) -- "mouse_button" is any gideros mouse button code
flag = ImGui:isMouseClicked(mouse_button [, repeat = false]) -- "mouse_button" is any gideros mouse button code
flag = ImGui:isMouseReleased(mouse_button) -- "mouse_button" is any gideros mouse button code
flag = ImGui:isMouseDoubleClicked(mouse_button) -- "mouse_button" is any gideros mouse button code
flag = ImGui:isMouseHoveringRect(min_x, min_y, max_x, max_y [, clip = true])
flag = ImGui:isMousePosValid([x = inf, y = inf])
flag = ImGui:isAnyMouseDown()
x, y = ImGui:getMousePos()
x, y = ImGui:getMousePosOnOpeningCurrentPopup()
flag = ImGui:isMouseDragging(mouse_button [, lock_threshold = -1]) -- "mouse_button" is any gideros mouse button code
x, y = ImGui:getMouseDragDelta(mouse_button [, lock_threshold = -1]) -- "mouse_button" is any gideros mouse button code
ImGui:resetMouseDragDelta(mouse_button) -- "mouse_button" is any gideros mouse button code
ImGuiMouseCursor = ImGui:getMouseCursor()
ImGui:setMouseCursor(ImGui.MouseCursor)
ImGui:setNextFrameWantCaptureMouse([want_capture_mouse_value = true])
ImGui:setNextFrameWantCaptureKeyboard([want_capture_keyboard_value = true])
ImGui:updateCursor()
</syntaxhighlight>
 
 
== TextEditor ==
<syntaxhighlight lang="lua">
TextEditor = ImGuiTextEditor.new([other_text_editor]) -- otherTextEditor: another "ImGuiTextEditor" instance to copy setting
</syntaxhighlight>
 
'''Functions''':
'''Functions''':
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
Line 1,639: Line 1,932:


== DRAW LISTS ==
== DRAW LISTS ==
 
'''Window draw list''':
=== Window draw list ===
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local list = ImGui:getWindowDrawList()
local list = ImGui:getWindowDrawList()
Line 1,825: Line 2,117:


stage:addEventListener("enterFrame", onEnterFrame)
stage:addEventListener("enterFrame", onEnterFrame)
</syntaxhighlight>
== EXPERIMENTAL ==
<syntaxhighlight lang="lua">
p_open = ImGui:showLog(title, p_open [, ImGui.WindowFlags = 0]) -- draw log window
ImGui:writeLog(text)
</syntaxhighlight>
Gestures (touch only, turned OFF by default) ''WIP'':
* tap gesture (Left Mouse Button)
* hold gesture (Right Mouse Button)
<syntaxhighlight lang="lua">
ImGui:setTouchGesturesEnabled(bool)
bool = ImGui:isTouchGesturesEnabled()
</syntaxhighlight>
</syntaxhighlight>



Latest revision as of 03:19, 27 October 2026

Dear ImGui LUA binding for Gideros Mobile

GitHub https://github.com/MultiPain/Gideros_ImGui

Constructor

-- font_atlas: copy fonts
-- mouse_listeners: adds internal mouse event listeners
-- keyboard_listeners: adds internal keyboard event listeners
-- touch_listeners: adds internal touch event listeners
ImGui.new([font_atlas = nil, mouse_listeners = true, keyboard_listeners = true, touch_listeners = false])

IO Functions

GetIO() access the IO structure (mouse/keyboard/gamepad inputs, time, various configuration options/flags)

local IO = ImGui:getIO()

Functions:

Settings/.Ini Utilities
* The disk functions are automatically called if io.IniFilename != NULL (default is "imgui.ini").
* Set io.IniFilename to NULL to load/save manually. Read io.WantSaveIniSettings description about handling .ini saving manually.
IO:setFontDefault(font)
ImGuiConfigFlag = IO:getConfigFlags()
IO:setConfigFlags(ImGui.ConfigFlag)
IO:addConfigFlags(ImGui.ConfigFlag)
ImGuiBackendFlag = IO:getBackendFlags()
IO:setBackendFlags(ImGui.BackendFlag)
number = IO:getIniSavingRate()
IO:setIniSavingRate(number)
string = IO:getIniFilename()
IO:setIniFilename(string)
IO:saveIniSettings([path]) -- if path is not defined the it uses default path, which is set by IO:setIniFilename()
IO:loadIniSettings([path])
string = IO:getLogFilename()
IO:setLogFilename(string)
number = IO:getMouseDoubleClickTime()
IO:setMouseDoubleClickTime(number)
number = IO:getMouseDragThreshold()
IO:setMouseDragThreshold(number)
flag = IO:getMouseDrawCursor()
IO:setMouseDrawCursor(flag)
number = IO:getMouseDoubleClickMaxDist()
IO:setMouseDoubleClickMaxDist(number)
number = IO:getKeyRepeatDelay()
IO:setKeyRepeatDelay(number)
number = IO:getKeyRepeatRate()
IO:setKeyRepeatRate(number)
number = IO:getFontGlobalScale()
IO:setFontGlobalScale(number)
bool = IO:getFontAllowUserScaling()
IO:setFontAllowUserScaling(bool)
number, number = IO:getDisplayFramebufferScale()
IO:setDisplayFramebufferScale(number, number)
bool = IO:getConfigMacOSXBehaviors()
IO:setConfigMacOSXBehaviors(bool)
bool = IO:getConfigInputTextCursorBlink()
IO:setConfigInputTextCursorBlink(bool)
bool = IO:getConfigWindowsResizeFromEdges()
IO:setConfigWindowsResizeFromEdges(bool)
bool = IO:getConfigWindowsMoveFromTitleBarOnly()
IO:setConfigWindowsMoveFromTitleBarOnly(bool)
number = IO:getConfigWindowsMemoryCompactTimer()
IO:setConfigWindowsMemoryCompactTimer(number)
string = IO:getBackendPlatformName()
string = IO:getBackendRendererName()
bool = IO:IsMouseDown(button)
number = IO:getMouseWheel()
number = IO:getMouseWheelH()
flag = IO:wantCaptureMouse()
flag = IO:wantCaptureKeyboard()
flag = IO:wantTextInput()
flag = IO:wantSetMousePos()
flag = IO:wantSaveIniSettings()
number = IO:getFramerate()
number = IO:getMetricsRenderVertices()
number = IO:getMetricsRenderIndices()
number = IO:getMetricsRenderWindows()
number = IO:getMetricsActiveWindows()
number = IO:getMetricsActiveAllocations()
x, y = IO:getMouseDelta()
number = IO:getMouseDownSec(mouse_button)
IO:setDisplaySize(w, h)
w, h = IO:getDisplaySize()
number = IO:getDeltaTime()
-- reset mouse buttons state
IO:resetMouseDown()
-- reset key states (including ALT/SHIFT/CTRL/SUPER (META))
IO:resetKeysDown()
-- set ALT/SHIFT/CTRL/SUPER (META) key state
IO:setModKeyDown(key_code, bool) -- "key_code" is a gideros MOD key
-- set any key state
IO:setKeysDown(key_code, bool) -- "key_code" is a gideros regular "keyCode"
-- adds text to active text input widget
IO:addInputCharactersUTF8(text)
-- emulate wheel scrolling
IO:setMouseWheel(number)
-- sets mouse position (data only, no visual changes)
IO:setMousePos(x, y)
-- set mouse state, where index: 0 - left mouse, 1 - right, 2 - middle, 3 - unused, 4 - unused.
IO:setMouseDown(mouse_button, state) -- "mouse_button" is a gideros mouse button code

-- "key" is any ImGui KeyCode (check [here](#keyboard-keys))
-- "down" is a boolean
IO:addKeyEvent(key, down)
IO:addKeyAnalogEvent(key, down, number)
IO:AddMousePosEvent(x, y)
-- "button" is any ImGui button (check [here](#MouseButton))
IO:addMouseButtonEvent(button, down)
IO:addMouseWheelEvent(x, y)

IO:setAppAcceptingEvents([accepting_events = true])

Style setters/getters

GetStyle() instance access the Style structure (colors, sizes). Always use PushStyleCol(), PushStyleVar() to modify style mid-frame!

local Style = ImGui:getStyle()

Setters/getters:

Style:setColor(ImGui.Col, color, alpha)
color, alpha = Style:getColor(ImGui.Col)
Style:setAlpha(value)
value = Style:getAlpha()

Style:setWindowRounding(value)
value = Style:getWindowRounding()
Style:setWindowBorderSize(value)
value = Style:getWindowBorderSize()
Style:setChildRounding(value)
value = Style:getChildRounding()
Style:setChildBorderSize(value)
value = Style:getChildBorderSize()
Style:setPopupRounding(value)
value = Style:getPopupRounding()
Style:setPopupBorderSize(value)
value = Style:getPopupBorderSize()
Style:setFrameRounding(value)
value = Style:getFrameRounding()
Style:setFrameBorderSize(value)
value = Style:getFrameBorderSize()
Style:setIndentSpacing(value)
value = Style:getIndentSpacing()
Style:setColumnsMinSpacing(value)
value = Style:getColumnsMinSpacing()
Style:setScrollbarSize(value)
value = Style:getScrollbarSize()
Style:setScrollbarRounding(value)
value = Style:getScrollbarRounding()
Style:setGrabMinSize(value)
value = Style:getGrabMinSize()
Style:setGrabRounding(value)
value = Style:getGrabRounding()
Style:setLogSliderDeadzone(value)
value = Style:getLogSliderDeadzone()
Style:setTabRounding(value)
value = Style:getTabRounding()
Style:setTabBorderSize(value)
value = Style:getTabBorderSize()
Style:setTabMinWidthForCloseButton(value)
value = Style:getTabMinWidthForCloseButton()
Style:setMouseCursorScale(value)
value = Style:getMouseCursorScale()
Style:setCurveTessellationTol(value)
value = Style:getCurveTessellationTol()
Style:setCircleSegmentMaxError(value)
value = Style:getCircleSegmentMaxError()
Style:setWindowPadding(x, y)
x, y = Style:getWindowPadding()
Style:setWindowMinSize(x, y)
x, y = Style:getWindowMinSize()
Style:setWindowTitleAlign(x, y)
x, y = Style:getWindowTitleAlign()
Style:setFramePadding(x, y)
x, y = Style:getFramePadding()
Style:setCellPadding(x, y)
x, y = Style:getCellPadding()
Style:setItemSpacing(x, y)
x, y = Style:getItemSpacing()
Style:setItemInnerSpacing(x, y)
x, y = Style:getItemInnerSpacing()
Style:setTouchExtraPadding(x, y)
x, y = Style:getTouchExtraPadding()
Style:setButtonTextAlign(x, y)
x, y = Style:getButtonTextAlign()
Style:setSelectableTextAlign(x, y)
x, y = Style:getSelectableTextAlign()
Style:setDisplayWindowPadding(x, y)
x, y = Style:getDisplayWindowPadding()
Style:setDisplaySafeAreaPadding(x, y)
x, y = Style:getDisplaySafeAreaPadding()
Style:setWindowMenuButtonPosition(ImGui.Dir)
dir = Style:getWindowMenuButtonPosition()
Style:setColorButtonPosition(ImGui.Dir)
dir = Style:getColorButtonPosition()
Style:setAntiAliasedLines(flag)
flag = Style:getAntiAliasedLines()
Style:setAntiAliasedLinesUseTex(flag)
flag = Style:getAntiAliasedLinesUseTex()
Style:setAntiAliasedFill(flag)
flag = Style:getAntiAliasedFill()
Style:setDisabledAlpha(number)
alpha = Style:getDisabledAlpha()
Style:setSeparatorTextBorderSize(number)
number = Style:getSeparatorTextBorderSize()
Style:setSeparatorTextAlign(x, y)
x, y = Style:getSeparatorTextAlign()
Style:setSeparatorTextPadding(x, y)
x, y = Style:getSeparatorTextPadding()

DEFAULT STYLES

ImGui:setDarkStyle()
ImGui:setLightStyle()
ImGui:setClassicStyle()

Render

NewFrame() start a new Dear ImGui frame, you can submit any command from this point until Render()/EndFrame().

EndFrame() ends the Dear ImGui frame. Automatically called by Render(). If you don't need to render data (skipping rendering) you may call EndFrame() without Render()... but you'll have wasted CPU already! If you don't need to render, better to not create any windows and not call NewFrame() at all!

Render() ends the Dear ImGui frame, finalize the draw data.

ImGui:newFrame(deltaTime)
ImGui:render()
ImGui:endFrame()

Demos

is_openFlag = ImGui:showUserGuide()
is_openFlag = ImGui:showDemoWindow([p_open])
is_openFlag = ImGui:showAboutWindow([p_open])
is_openFlag = ImGui:showStyleEditor()
is_openFlag = ImGui:showFontSelector()
is_openFlag = ImGui:showMetricsWindow([p_open])
is_openFlag = ImGui:showStyleSelector(label)
is_openFlag = ImGui:ShowStackToolWindow([p_open])
ImGui:showLuaStyleEditor()

Windows

  • Begin() = push window to the stack and start appending to it. End() = pop window from the stack.
  • You may append multiple times to the same window during the same frame.
  • Passing bool* p_open != NULL shows a window-closing widget in the upper-right corner of the window, which clicking will set the boolean to false when clicked.
  • Begin() return false to indicate the window is collapsed or fully clipped, so you may early out and omit submitting anything to the window. Always call a matching End() for each Begin() call, regardless of its return value! [Important: due to legacy reason, this is inconsistent with most other functions such as BeginMenu / EndMenu, BeginPopup / EndPopup, etc. where the EndXXX call should only be called if the corresponding BeginXXX function returned true. Begin and BeginChild are the only odd ones out. Will be fixed in a future update.]
  • Note that the bottom of window stack always contains a window called "Debug".
p_open, draw = ImGui:beginWindow(label, p_open [, ImGui.WindowFlags = 0])
-- do not show "X" button
draw = ImGui:beginWindow(label, nil [, ImGui.WindowFlags = 0])
-- start a window with no borders, no paddings, no rounding and ImGui.WindowFlags_Fullscreen flag
p_open, draw = ImGui:beginFullScreenWindow(label, p_open [, ImGui.WindowFlags = 0]) 
-- do not show "X" button
draw = ImGui:beginFullScreenWindow(label, nil [, ImGui.WindowFlags = 0]) 
ImGui:endWindow()

Child Windows

Use child windows to begin into a self-contained independent scrolling/clipping regions within a host window. Child windows can embed their own child. For each independent axis of size:

  • == 0.0f -> use remaining host window size
  • > 0.0f -> fixed size
  • < 0.0f -> use remaining window size minus abs(size) Each axis can use a different mode, e.g. ImVec2(0,400). BeginChild() returns false to indicate the window is collapsed or fully clipped, so you may early out and omit submitting anything to the window.
Tip
Always call a matching EndChild() for each BeginChild() call, regardless of its return value [as with Begin: this is due to legacy reason and inconsistent with most BeginXXX functions apart from the regular Begin() which behaves like BeginChild().]
ImGui:beginChild(id [, w = 0, h = 0, borderFlag = false, ImGui.WindowFlags = 0])
ImGui:endChild()

Windows Utilities

  • Current window = the window we are appending into while inside a Begin() / End() block.
  • Next window = next window we will Begin() into.
  • Prefer using SetNextXXX functions (before Begin) rather than SetXXX functions (after Begin()).
flag = ImGui:isWindowAppearing()
flag = ImGui:isWindowCollapsed()
flag = ImGui:isWindowFocused([ImGui.FocusedFlags = 0])
flag = ImGui:isWindowHovered([ImGui.HoveredFlags = 0])
x, y = ImGui:getWindowPos()
w, h = ImGui:getWindowSize()
w = ImGui:getWindowWidth()
h = ImGui:getWindowHeight()
x1,y1, x2,y2 = ImGui:getWindowBounds() -- returns window region rectangle in global coordinates

ImGui:setNextWindowPos(x, y [, ImGui.Cond = 0, pivotX = 0, pivotY = 0])
ImGui:setNextWindowSize(w, h [, ImGui.Cond = 0])
ImGui:setNextWindowContentSize(w, h)
ImGui:setNextWindowCollapsed(flag [, ImGui.Cond = 0])
ImGui:setNextWindowFocus()
ImGui:setNextWindowBgAlpha(alpha)
ImGui:setNextWindowScroll(x, y)
ImGui:setWindowPos(name, x, y [, ImGui.Cond = 0]) OR ImGui:setWindowPos(x, y [, ImGui.Cond = 0])
ImGui:setWindowSize(name, w, h [, ImGui.Cond = 0]) OR ImGui:setWindowSize(w, h [, ImGui.Cond = 0])
ImGui:setWindowCollapsed(name, flag [, ImGui.Cond = 0]) OR ImGui:setWindowCollapsed(flag [, ImGui.Cond = 0])
ImGui:setWindowFocus(name) OR ImGui:setWindowFocus()
ImGui:setWindowFontScale(scale)
-- scroll window when touching void
ImGui:scrollWhenDragging(x, y)
☠️Note: because Dear ImGui is an Immediate Mode GUI framework, functions that fetch window properties (like scrolling, window sizes, or content regions) internally query the "current window" pointer. If ImGui:begin() hasn't been called yet, or if ImGui:end() was already called, that pointer is NULL, causing a fatal segmentation fault/crash

Window size constraints

Can be used to set minimum and maximum window size, plus contraint the size if needed.

-- call this function before ImGui:beginWindow()
ImGui:setNextWindowSizeConstraints(min_w, min_h, max_w, max_h [, resize_callback, user_data]))
-- resizeCallback is a function:
function (callbackData [, user_data])
	-- do some math, and return desired size
	-- ...
	return desired_width, desired_height
end

Resize callback:

-- get window position
x, y = callbackData:getPos()
x = callbackData:getX()
y = callbackData:getY()

-- get currrent size
current_width, current_height = callbackData:getCurrentSize()
current_width = callbackData:getCurrentWidth()
current_height = callbackData:getCurrentHeight()

-- get desired size
desired_width, desired_height = callbackData:getDesiredSize()
desired_width = callbackData:getDesiredWidth()
desired_height = callbackData:getDesiredHeight()

Example:

require "ImGui"

local function stepSize(callback_data, step)
	local w, h = callback_data:getDesiredSize()
	w = (w // step) * step
	h = (h // step) * step
	return w, h
end

local ui = ImGui.new()
stage:addChild(ui)

stage:addEventListener("enterFrame", function(e)
	ui:newFrame(e.deltaTime)
	
	-- window size step is 32 (last argument, that is passed to the callback as second argument)
	ui:setNextWindowSizeConstraints(200, 200, 400, 400, stepSize, 32)
	if (ui:beginWindow("My window")) then 
		
		ui:textWrapped("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
	end
	ui:endWindow()
	
	ui:showDemoWindow()
	
	ui:render()
	ui:endFrame()
end)

Content region

  • Those functions are bound to be redesigned soon (they are confusing, incomplete and return values in local window coordinates which increases confusion)
scaleX, scaleY = ImGui:getContentRegionMax()
w, h = ImGui:getContentRegionAvail()
x, y = ImGui:getWindowContentRegionMin()
x, y = ImGui:getWindowContentRegionMax()
☠️Note: because Dear ImGui is an Immediate Mode GUI framework, functions that fetch window properties (like scrolling, window sizes, or content regions) internally query the "current window" pointer. If ImGui:begin() hasn't been called yet, or if ImGui:end() was already called, that pointer is NULL, causing a fatal segmentation fault/crash

Windows Scrolling

x = ImGui:getScrollX()
y = ImGui:getScrollY()
maxX = ImGui:getScrollMaxX()
maxY = ImGui:getScrollMaxY()
ImGui:setScrollX(value)
ImGui:setScrollY(value)
ImGui:setScrollHereX([ratio = 0.5])
ImGui:setScrollHereY([ratio = 0.5])
ImGui:setScrollFromPosX(x [, ratio = 0.5])
ImGui:setScrollFromPosY(y [, ratio = 0.5])
☠️Note: because Dear ImGui is an Immediate Mode GUI framework, functions that fetch window properties (like scrolling, window sizes, or content regions) internally query the "current window" pointer. If ImGui:begin() hasn't been called yet, or if ImGui:end() was already called, that pointer is NULL, causing a fatal segmentation fault/crash

Example

self.doresetscrollbar = false
...
self.doresetscrollbar = true

function Level1:onEnterFrame(e)
	self.imgui:newFrame(e.deltaTime)
	self.imgui:beginWindow("window") -- #1
	if self.doresetscrollbar then
		self.doresetscrollbar = false
		self.imgui:setScrollY(0)
	end
...
	self.imgui:endWindow() -- #1
	self.imgui:endFrame()
	self.imgui:render()
end

Parameters stacks (shared)

ImGui:pushStyleColor(ImGui.Col, color, alpha) -- https://wiki.gideros.rocks/index.php/Dear_ImGui_Flags#Col
ImGui:popStyleColor([count = 1])
ImGui:pushStyleVar(ImGui.StyleVar, value) OR ImGui:pushStyleVar(ImGui.StyleVar, value1, value2)
ImGui:popStyleVar([count = 1])
color, alpha = ImGui:getStyleColor(ImGui.Col)
fontSize = ImGui:getFontSize()

Parameters stacks (current window)

ImGui:pushItemWidth(w)
ImGui:popItemWidth()
ImGui:setNextItemWidth(w)
w = ImGui:calcItemWidth()
ImGui:pushTextWrapPos([localX = 0])
ImGui:popTextWrapPos()
ImGui:pushTabStop(flag)
ImGui:popTabStop()
ImGui:pushButtonRepeat(flag)
ImGui:popButtonRepeat()

Cursor / Layout

  • By "cursor" we mean the current output position.
  • The typical widget behavior is to output themselves at the current cursor position, then move the cursor one line down.
  • You can call SameLine() between widgets to undo the last carriage return and output at the right of the preceeding widget.
  • Attention! We currently have inconsistencies between window-local and absolute positions we will aim to fix with future API:
    • Window-local coordinates: SameLine(), GetCursorPos(), SetCursorPos(), GetCursorStartPos(), GetContentRegionMax(), GetWindowContentRegion*(), PushTextWrapPos()
    • Absolute coordinate: GetCursorScreenPos(), SetCursorScreenPos(), all ImDrawList:: functions
ImGui:separator()
ImGui:sameLine([offset_x = 0, spacing = -1])
ImGui:newLine()
ImGui:spacing()
ImGui:dummy(w, h)
ImGui:indent([indent = 0])
ImGui:unindent([indent = 0])
ImGui:beginGroup()
ImGui:endGroup()
 
x, y = ImGui:getCursorPos()
x = ImGui:getCursorPosX()
y = ImGui:getCursorPosY()
ImGui:setCursorPos(local_x, local_y)
ImGui:setCursorPosX(local_x)
ImGui:setCursorPosY(local_y)
x, y = ImGui:getCursorStartPos()
x, y = ImGui:getCursorScreenPos()
ImGui:setCursorScreenPos(x, y)
ImGui:alignTextToFramePadding()
lineH = ImGui:getTextLineHeight()
lineH = ImGui:getTextLineHeightWithSpacing()
frameH = ImGui:getFrameHeight()
frameH = ImGui:getFrameHeightWithSpacing()

ID stack/scopes

  • Read the FAQ for more details about how ID are handled in Dear Imgui. If you are creating widgets in a loop you most likely want to push a unique identifier (e.g. object pointer, loop index) to uniquely differentiate them.
  • The resulting ID are hashes of the entire stack.
  • You can also use the "Label##foobar" syntax within widget label to distinguish them from each others.
  • In this header file we use the "label"/"name" terminology to denote a string that will be displayed and used as an ID, whereas "str_id" denote a string that is only used as an ID and not normally displayed.
ImGui:pushID(anyValue) 
ImGui:pushID(str)
ImGui:popID()
number = ImGui:getID(anyValue)
number = ImGui:getID(str)
number = ImGui:getItemID()

WIDGETS

Widgets: Text

ImGui:textUnformatted(text [, textEnd])
ImGui:text(text)
ImGui:textColored(text, color, alpha)
ImGui:textDisabled(text)
ImGui:textWrapped(text)
ImGui:labelText(text, label)
ImGui:bulletText(text)
ImGui:separatorText(label)

Widgets: Main

flag = ImGui:button(text [, w = 0, h = 0])
flag = ImGui:smallButton(text)
flag = ImGui:invisibleButton(string_ID [, w = 0, h = 0])
flag = ImGui:arrowButton(string_ID [, ImGui.Dir = 0])
flag = ImGui:checkbox(text, flag)
flags, is_changed = ImGui:checkboxFlags(label [, flags = 0, flags_value = 0])
number, is_changed = ImGui:radioButton(text, number, number)
is_changed = ImGui:radioButton(text, flag)
ImGui:progressBar(fraction [, anchor_x = -1, anchor_y = 0, overlay_string = nil])
ImGui:bullet()

Widgets: Images

-- Images are streched (ImGui default functions)
ImGui:image(texture, w, h
	[, tint_color = 0xffffff, tint_alpha = 1,
	border_color = 0xffffff, border_alpha = 0])

ImGui:imageUV(texture,
	w, h,
	uv0x, uv0y,
	uv1x, uv1y,
	[, tint_color = 0xffffff, tint_alpha = 1, border_color = 0xffffff, border_alpha = 0])

pressFlag = ImGui:imageButton(str_id, texture, w, h
	[, tint_color = 0xffffff, tint_alpha = 1,
	border_color = 0xffffff, border_alpha = 0])

pressFlag = ImGui:imageButtonUV(str_id, texture, w, h,
	uv0x, uv0y, uv1x, uv1y
	[, tint_color = 0xffffff, tint_alpha = 1,
	border_color = 0xffffff, border_alpha = 0])

-- Images are scaled (extended by @MultiPain)
-- padding deprecated
-- (use "ImGui:pushStyleVar(ImGui.StyleVar_FramePadding, x, y)/ImGui:popStyleVar()")
ImGui:scaledImage(str_id, texture, w, h
	[, fit_mode = ImGui.ImageScaleMode_LetterBox, keep_size = false,
	anchor_x = 0.5, anchor_y = 0.5,
	tint_col = 0xffffff, tint_alpha = 1,
	border_col = 0, border_alpha = 0,
	bg_col = 0, bg_alpha = 0])

pressFlag = ImGui:scaledImageButton(str_id, texture, w, h
	[, fit_mode = ImGui.ImageScaleMode_LetterBox, keep_size = false,
	ImGui.ButtonFlags = 0, anchor_x = 0.5, anchor_y = 0.5,
	clip_offset_x = 0, clip_offset_y = 0,
	tint_col = 0xffffff, tint_alpha = 1,
	border_col = 0, border_alpha = 0,
	bg_col = 0, bg_alpha = 0])

pressFlag = ImGui:scaledImageButtonWithText(texture, label, image_w, image_h
	[, button_w = 0, button_h = 0, ImGui.ButtonFlags = 0,
	fit_mode = ImGui.ImageScaleMode_LetterBox, keep_size = false,
	anchor_x = 0.5, anchor_y = 0.5, image_side = ImGui.Dir_Left,
	clip_offset_x = 0, clip_offset_y = 0,
	tint_col = 0xffffff, tint_alpha = 1,
	border_col = 0, border_alpha = 0,
	bg_col = 0, bg_alpha = 0])

Widgets: Combo Box

openFlag = ImGui:beginCombo(text, preview_text [, ImGui.ComboFlags = 0])
ImGui:endCombo()
current_item, is_open = ImGui:combo(label, current_item, items) -- items (table): {"item1", "item2", ...}

Widgets: Drags

value, is_changed = ImGui:dragFloat(label, value
	[, inc_step = 1, min = 0, max = 0,
	format_string = "%.3f", ImGui.SliderFlags = 0])

value1, value2, is_changed = ImGui:dragFloat2(label, value1, value2
	[, inc_step = 1, min = 0, max = 0,
	format_string = "%.3f", ImGui.SliderFlags = 0])

value1, value2, value3, is_changed = ImGui:dragFloat3(label, value1, value2, value3
	[, inc_step = 1, min = 0, max = 0,
	format_string = "%.3f", ImGui.SliderFlags = 0])

value1, value2, value3, value4, is_changed = ImGui:dragFloat4(label, value1, value2, value3, value4
	[, inc_step = 1, min = 0, max = 0,
	format_string = "%.3f", ImGui.SliderFlags = 0])

value_min, value_max, is_changed = ImGui:dragFloatRange2(label, value_min, value_max
	[, inc_step = 1, min = 0, max = 0,
	format_min_string = "%.3f", ImGui.SliderFlags = 0])
-- table must be an array of any size > 0
is_changed = ImGui:dragFloatT(label, table
	[, inc_step = 1, min = 0, max = 0,
	format_string = "%.3f", ImGui.SliderFlags = 0])

value, is_changed = ImGui:dragInt(label, value
	[, inc_step = 1, min = 0, max = 0,
	format_string = "%d", ImGui.SliderFlags = 0])

value1, value2, is_changed = ImGui:dragInt2(label, value1, value2
	[, inc_step = 1, min = 0, max = 0,
	format_string = "%d", ImGui.SliderFlags = 0])

value1, value2, value3, is_changed = ImGui:dragInt3(label, value1, value2, value3
	[, inc_step = 1, min = 0, max = 0,
	format_string = "%d", ImGui.SliderFlags = 0])

value1, value2, value3, value4, is_changed = ImGui:dragInt4(label, value1, value2, value3, value4
	[, inc_step = 1, min = 0, max = 0,
	format_string = "%d", ImGui.SliderFlags = 0])

v_current_min, v_current_max, flag = ImGui:dragIntRange2(label, v_current_min, v_current_max
	[, v_speed = 1, v_min = 0, v_max = 0,
	format = "%d", format_max = nil, ImGui.SliderFlags = 0])

-- table must be an array of any size > 0
is_changed = ImGui:dragIntT(label, table
	[, inc_step = 1, min = 0, max = 0,
	format_string = "%d", ImGui.SliderFlags = 0])

Widgets: Sliders

value, is_changed = ImGui:sliderFloat(label, value
	[, min = 0, max = 0,
	format_string = "%.3f", ImGui.SliderFlags = 0])

value1, value2, is_changed = ImGui:sliderFloat2(label, value1, value2
	[, min = 0, max = 0,
	format_string = "%.3f", ImGui.SliderFlags = 0])

value1, value2, value3, is_changed = ImGui:sliderFloat3(label, value1, value2, value3
	[, min = 0, max = 0,
	format_string = "%.3f", ImGui.SliderFlags = 0])

value1, value2, value3, value4, is_changed = ImGui:sliderFloat4(label, value1, value2, value3, value4
	[, min = 0, max = 0,
	format_string = "%.3f", ImGui.SliderFlags = 0])

value_in_rad, is_changed = ImGui:sliderAngle(label, value_in_rad
	[, min_degrees = -360, max_degrees = 360,
	format_string = "%.0f deg", ImGui.SliderFlags = 0])

-- table must be an array of any size > 0
is_changed = ImGui:sliderFloatT(label, table
	[, min = 0, max = 0,
	format_string = "%.3f", ImGui.SliderFlags = 0])

value, is_changed = ImGui:sliderInt(label, value
	[, min = 0, max = 0,
	format_string = "%d, ImGui.SliderFlags = 0"])

value1, value2, is_changed = ImGui:sliderInt2(label, value1, value2
	[, min = 0, max = 0,
	format_string = "%d, ImGui.SliderFlags = 0"])

value1, value2, value3, is_changed = ImGui:sliderInt3(label, value1, value2, value3
	[, min = 0, max = 0,
	format_string = "%d, ImGui.SliderFlags = 0"])

value1, value2, value3, value4, is_changed = ImGui:sliderInt4(label, value1, value2, value3, value4
	[, min = 0, max = 0,
	format_string = "%d, ImGui.SliderFlags = 0"])

-- table must be an array of any size > 0
is_changed = ImGui:sliderIntT(label, table
	[, min = 0, max = 0,
	format_string = "%d", ImGui.SliderFlags = 0])

value, is_changed = ImGui:vSliderFloat(label, w, h, value, min, max
	[, format_string = "%.3f", ImGui.SliderFlags = 0])

value, is_changed = ImGui:vSliderInt(label, w, h, value, min, max
	[, format_string = "%d", ImGui.SliderFlags = 0])

value, is_changed = ImGui:filledSliderFloat(label, mirror_flag, value
	[, min = 0, max = 0,
	format_string = "%.3f", ImGui.SliderFlags = 0])

value1, value2, is_changed = ImGui:filledSliderFloat2(label, mirror_flag, value1, value2
	[, min = 0, max = 0,
	format_string = "%.3f", ImGui.SliderFlags = 0])

value1, value2, value3, is_changed = ImGui:filledSliderFloat3(label, mirror_flag, value1, value2, value3
	[, min = 0, max = 0,
	format_string = "%.3f", ImGui.SliderFlags = 0])

value1, value2, value3, value4, is_changed = ImGui:filledSliderFloat4(label, mirror_flag, value1, value2, value3, value4
	[, min = 0, max = 0,
	format_string = "%.3f", ImGui.SliderFlags = 0])

-- table must be an array of any size > 0
is_changed = ImGui:filledSliderFloatT(label, mirror_flag, table
	[, min = 0, max = 0,
	format_string = "%.3f", ImGui.SliderFlags = 0])

value_in_rad, is_changed = ImGui:filledSliderAngle(label, mirror_flag, value_in_rad
	[, min_degrees = -360, max_degrees = 360,
	format_string = "%.0f deg", ImGui.SliderFlags = 0])

value, is_changed = ImGui:filledSliderInt(label, mirror_flag, value
	[, min = 0, max = 0,
	format_string = "%d", ImGui.SliderFlags = 0])

value1, value2, is_changed = ImGui:filledSliderInt2(label, mirror_flag, value1, value2
	[, min = 0, max = 0,
	format_string = "%d", ImGui.SliderFlags = 0])

value1, value2, value3, is_changed = ImGui:filledSliderInt3(label, mirror_flag, value1, value2, value3
	[, min = 0, max = 0,
	format_string = "%d", ImGui.SliderFlags = 0])

value1, value2, value3, value4, is_changed = ImGui:filledSliderInt4(label, mirror_flag, value1, value2, value3, value4
	[, min = 0, max = 0,
	format_string = "%d", ImGui.SliderFlags = 0])

-- table must be an array of any size > 0
is_changed = ImGui:filledSliderIntT(label, mirror_flag, table
	[, min = 0, max = 0,
	format_string = "%d", ImGui.SliderFlags = 0])

value, is_changed = ImGui:vFilledSliderFloat(label, mirror_flag, w, h, value, min, max
	[, format_string = "%.3f", ImGui.SliderFlags = 0])

value, is_changed = ImGui:vFilledSliderInt(label, mirror_flag, w, h, value, min, max
	[, format_string = "%d", ImGui.SliderFlags = 0])

Widgets: Input with Keyboard

text, flag = ImGui:inputText(label, text, buffer_size [, ImGui.InputTextFlags = 0])
text, flag = ImGui:inputTextMultiline(label, text, buffer_size [, w = 0, h = 0, ImGui.InputTextFlags = 0])
text, flag = ImGui:inputTextWithHint(label, text, hint, buffer_size [, ImGui.InputTextFlags = 0])
value,  flag = ImGui:inputFloat(label, value [, step = 0, step_fast = 0, format = "%.3f", ImGui.InputTextFlags = 0])
value1, value2, flag = ImGui:inputFloat2(label, value1, value2 [, format = "%.3f", ImGui.InputTextFlags = 0])
value1, value2, value3, flag = ImGui:inputFloat3(label, value1, value2, value3 [, format = "%.3f", ImGui.InputTextFlags = 0])
value1, value2, value3, value4, flag = ImGui:inputFloat4(label, value1, value2, value3, value4 [, format = "%.3f", ImGui.InputTextFlags = 0])
-- table must be an array of any size > 0
flag = ImGui:inputFloatT(label, table [, format = "%.3f", ImGui.InputTextFlags = 0])
value,  flag = ImGui:inputInt(label, value [, step = 0, step_fast = 0, ImGui.InputTextFlags = 0])
value1, value2, flag = ImGui:inputInt2(label, value1, value2 [, ImGui.InputTextFlags = 0])
value1, value2, value3, flag = ImGui:inputInt3(label, value1, value2, value3 [, ImGui.InputTextFlags = 0])
value1, value2, value3, value4, flag = ImGui:inputInt4(label, value1, value2, value3, value4 [, ImGui.InputTextFlags = 0])
-- table must be an array of any size > 0
flag = ImGui:inputIntT(label, table [, format = "%d", ImGui.InputTextFlags = 0])
value, flag = ImGui:inputDouble(label, value [, step = 0, step_fast = 0, format = "%.6f", ImGui.InputTextFlags = 0])

Input text callbacks:

ImGui:inputText(label, text, buffer_size [, ImGui.InputTextFlags = 0, callback_function, user_data])
ImGui:inputTextMultiline(label, text, buffer_size [, ImGui.InputTextFlags = 0, callback_function, user_data])
ImGui:inputTextWithHint(label, text, hint, buffer_size [, ImGui.InputTextFlags = 0, callback_function, user_data])

callback_function = function(callback_data, user_data)
	-- do something with data
	-- see below
end

callback_data:

ImGuiInputTextFlags = callback_data:getEventFlag()
ImGuiInputTextFlags = callback_data:getFlags()

number = callback_data:getEventChar()

callback_data:setEventChar(number)

keyCode = callback_data:getEventKey()

string = callback_data:getBuf()

callback_data:setBuf(string)

number = callback_data:getBufTextLen()

callback_data:setBufTextLen(number)

number = callback_data:getBufSize()

callback_data:setBufDirty(bool)
bool = callback_data:isBufDirty()

callback_data:setCursorPos(number)
number = callback_data:getCursorPos()

callback_data:setSelectionStart(s_start)
number = callback_data:getSelectionStart()

callback_data:setSelectionEnd(s_end)
s_end = callback_data:getSelectionEnd()

callback_data:setSelection(s_start, s_end)
s_start, s_end = callback_data:getSelection()

callback_data:selectAll()
callback_data:clearSelection()
bool = callback_data:hasSelection()

callback_data:deleteChars(position, bytesCount)
callback_data:insertChars(position, text)

Example:

require "ImGui"

ui = ImGui.new()
stage:addChild(ui)

local testMessage1 = ""
local testMessage2 = ""
local testMessage3 = ""

-- Add ".." at the end of current input string
function myCallback1(data)
	data:insertChars(data:getCursorPos(), "..")
end

-- Replace all chars if UP/DOWN arrow is pressed
function myCallback2(data)
	local key = data:getEventKey()
	if (key == key_code.UP) then
		data:deleteChars(0, data:getBufTextLen())
		data:insertChars(0, "Pressed Up!")
		data:selectAll()
	elseif (key == key_code.DOWN) then
		data:deleteChars(0, data:getBufTextLen())
		data:insertChars(0, "Pressed Down!")
		data:selectAll()
	end
end

-- Switch case of the first char
function myCallback3(data)
	local buf = data:getBuf()
	local s = buf:sub(1,1)
	if ((s >= 'a' and s <= 'z') or (s >= 'A' and s <= 'Z')) then 
		local first = string.char(string.byte(s) ~ 32)
		data:setBuf(first .. buf:sub(2))
		data:setBufDirty(true)
	end
end

function enterFrame(e)
	ui:newFrame(e.deltaTime)
	
	testMessage1 = ui:inputText(
		"Label1", 
		testMessage1, 
		64, 
		ImGui.InputTextFlags_CallbackCompletion, 
		myCallback1
	)
	testMessage2 = ui:inputText(
		"Label2", 
		testMessage2, 
		64, 
		ImGui.InputTextFlags_CallbackHistory, 
		myCallback2
	)
	testMessage3 = ui:inputText(
		"Label3", 
		testMessage3, 
		64, 
		ImGui.InputTextFlags_CallbackEdit, 
		myCallback3
	)
	
	ui:render()
	ui:endFrame()
end

stage:addEventListener("enterFrame", enterFrame)

Widgets: Color Editor/Picker

hexColor, is_touching = ImGui:colorEdit3(label, color [, ImGui.ColorEditFlags = 0]) -- alpha ignored, no need to pass it!
hexColor, alpha, is_touching = ImGui:colorEdit4(label, color [, alpha = 1, ImGui.ColorEditFlags = 0])
hexColor, is_touching = ImGui:colorPicker3(label, color [, ImGui.ColorEditFlags = 0])
hexColor, alpha, originalColor, originalAlpha, is_touching = ImGui:colorPicker4(label, color
	[, alpha = 1, original_color = 0xffffff, original_alpha = 1, ImGui.ColorEditFlags = 0])
isHoveringFlag = ImGui:colorButton(string_ID, color [, alpha = 1, ImGui.ColorEditFlags = 0, w = 0, h = 0])
ImGui:setColorEditOptions(ImGui.ColorEditFlags)

Widgets: Trees

is_openFlag = ImGui:treeNode(label [, format_string])
ImGui:treeNodeEx(label, ImGui.TreeNodeFlags [, format_string])
ImGui:treePush(str_id)
ImGui:treePop()
number = ImGui:getTreeNodeToLabelSpacing()
is_openFlag, p_open = ImGui:collapsingHeader(label, p_open [, ImGui.TreeNodeFlags = 0])
is_openFlag = ImGui:collapsingHeader(label [, ImGui.TreeNodeFlags = 0])
ImGui:setNextItemOpen(is_open, ImGui.Cond)

Widgets: Selectables

result?, selected = ImGui:selectable(label, selected [, ImGui.SelectableFlags = 0, w = 0, h = 0])

Widgets: List Boxes

-- item_table: {"Item0", "Item1", ...}
current_item, is_openFlag = ImGui:listBox(label, current_item, item_table [, max_visible_items = -1])
result? = ImGui:listBoxHeader(label [, w = 0, h = 0])
result? = ImGui:listBoxHeader2(label, items_count)
ImGui:listBoxFooter()

Widgets: Data Plotting

Caching:

If you have big array of points it is better to cache it instead of translating lua table to C++ vector every time you call `ImGui:plotLines()`. But in this case you need to manage memory by yourself (free points pointer when you dont need it).

-- store points in memory
-- points_table: {0.01, 0.5, 10, -50, ...}
-- ptr: c++ pointer to a given vector
ptr = ImGui.cachePoints(points_table)

-- delete points from memory
ImGui.freePoints(ptr)

Plot functions:

-- len (number): points array length
ImGui:plotCachedLines(label, ptr, len,
	[, values_offset = 0, overlay_text = nil,
	scale_min = math.huge, scale_max = math.huge,
	w = 0, h = 0])

ImGui:plotCachedHistogram(label, ptr, len,
	[, values_offset = 0, overlay_text = nil,
	scale_min = math.huge, scale_max = math.huge,
	w = 0, h = 0])

ImGui:plotLines(label, points_table
	[, values_offset = 0, overlay_text = nil,
	scale_min = math.huge, scale_max = math.huge,
	w = 0, h = 0])

ImGui:plotHistogram(label, points_table
	[, values_offset = 0, overlay_text = nil,
	scale_min = math.huge, scale_max = math.huge,
	w = 0, h = 0])

Example:

-- delete ptr if it exist
function deletePtr()
	if pointsPtr then
		ImGui.freePoints(pointsPtr)
	end
end

function onEnterFrame()
	ui:newFrame(e.deltaTime)
	
	if ui:button("Generate") then
		deletePtr()
		points = generatePoints() -- returns big array
		pointsPtr = ImGui.cachePoints(points)
	end
	
	if pointsPtr then
		ui:plotCachedLines("Big data", pointsPtr, #points)
	end
	
	ui:render()
	ui:endFrame()
end

-- do not forget to clear memory when app is closing
function onAppExit()
	deletePtr()
end

Widgets: Value() Helpers

ImGui:value(prefix, bool)
ImGui:value(prefix, number)
ImGui:value(prefix, float, format_string)

Widgets: Menus

result? = ImGui:beginMenuBar()
ImGui:endMenuBar()
result? = ImGui:beginMainMenuBar()
ImGui:endMainMenuBar()
result = ImGui:beginMenu(label [, enabled = true])
result = ImGui:beginMenuEx(label, [icon = "", enabled = true])
ImGui:endMenu()
result = ImGui:menuItem(label [, shortcut = "", selected = false, enabled = true])
result = ImGui:menuItemEx(label, [icon = "", shortcut = "", selected = false, enabled = true])

Widgets: Tooltips

Tooltip are windows following the mouse which do not take focus away.

ImGui:beginTooltip()
ImGui:endTooltip()
ImGui:setTooltip(text)

Disabled groups

ImGui:beginDisabled(disabledFlag)
ImGui:endDisabled()

Popups, Modals

The properties of popups windows are: - They block normal mouse hovering detection outside them. (*1) - Unless modal, they can be closed by clicking anywhere outside them, or by pressing ESCAPE. Because hovering detection is disabled outside the popup, when clicking outside the click will not be seen by underlying widgets! (*1)

  • Their visibility state (~bool) is held internally by Dear ImGui instead of being held by the programmer as we are used to with regular Begin() calls. User can manipulate the visibility state by calling OpenPopup(), CloseCurrentPopup() etc.
  • We default to use the right mouse (ImGuiMouseButton_Right=1) for the Popup Context functions.
  • Those three properties are connected: we need to retain popup visibility state in the library because popups may be closed as any time.

(1.) You can bypass that restriction and detect hovering even when normally blocked by a popup. To do this use the ImGuiHoveredFlags_AllowWhenBlockedByPopup when calling IsItemHovered() or IsWindowHovered(). This is what BeginPopupContextItem() and BeginPopupContextWindow() are doing already, allowing a right-click to reopen another popups without losing the click.

result? = ImGui:beginPopup(str_id [, ImGui.WindowFlags = 0])
p_open, result? = ImGui:beginPopupModal(str_id, p_open [, ImGui.WindowFlags = 0])
ImGui:endPopup()
ImGui:openPopup(str_id [, ImGui.PopupFlags = 0])
ImGui:openPopupOnItemClick(str_id [, ImGui.PopupFlags = 0])
ImGui:closeCurrentPopup()
result? = ImGui:beginPopupContextItem(str_id [, ImGui.PopupFlags = 0])
result? = ImGui:beginPopupContextWindow(str_id [, ImGui.PopupFlags = 0])
result? = ImGui:beginPopupContextVoid(str_id [, ImGui.PopupFlags = 0])
result? = ImGui:isPopupOpen(str_id [, ImGui.PopupFlags = 0])

Columns

  • You can also use SameLine(pos_x) to mimic simplified columns.
  • The columns API is work-in-progress and rather lacking (columns are arguably the worst part of dear imgui at the moment!)
  • There is a maximum of 64 columns.
  • Currently working on new 'Tables' api which will replace columns around Q2 2020 (see GitHub #2957).
ImGui:columns([count = 1, id = nil, border = true])
ImGui:nextColumn()
index = ImGui:getColumnIndex()
width = ImGui:getColumnWidth([column_index = -1])
ImGui:setColumnWidth(column_index, width)
offset = ImGui:getColumnOffset([column_index = -1])
ImGui:setColumnOffset(column_index, offset)
number = ImGui:getColumnsCount()

Tab Bars, Tabs

bool = ImGui:beginTabBar(str_id [, ImGui.TabBarFlags = 0])
ImGui:endTabBar()
p_open, bool = ImGui:beginTabItem(label, p_open [, ImGui.TabItemFlags = 0])
ImGui:endTabItem()
ImGui:setTabItemClosed(tab_or_docked_window_label)
ImGui:tabItemButton(label [, ImGui.TabItemFlags = 0])

Logging/Capture

All text output from the interface can be captured into tty/file/clipboard. By default, tree nodes are automatically opened during logging.

ImGui:logToTTY(auto_open_depth = -1) 
ImGui:logToFile(auto_open_depth = -1, filename = nil) 
ImGui:logToClipboard(auto_open_depth = -1) 
ImGui:logFinish() 
ImGui:logButtons() 
ImGui:logText(text)

Drag and drop

flag = ImGui:beginDragDropSource([ImGui.DragDropFlags flags = 0])
flag = ImGui:setNumDragDropPayload(str_type, number [, ImGui.Cond cond = 0])
flag = ImGui:setStrDragDropPayload(str_type, string [, ImGui.Cond cond = 0])
ImGui:endDragDropSource()
flag = ImGui:beginDragDropTarget()
ImGuiPayload = ImGui:acceptDragDropPayload(type [, ImGui.DragDropFlags flags = 0])
ImGui:endDragDropTarget()
ImGuiPayload = ImGui:getDragDropPayload()

Payload:

number = ImGuiPayload:getNumData()
string = ImGuiPayload:getStrData()
ImGuiPayload:clear()
number = ImGuiPayload:getDataSize()
flag = ImGuiPayload:isDataType(type) -- type must be the same as in "ImGui:acceptDragDropPayload(type)"
flag = ImGuiPayload:isPreview()
flag = ImGuiPayload:isDelivery()

Usage example:

require "ImGui"

local imgui = ImGui.new()
stage:addChild(imgui)

local names = {
	"Bobby", "Beatrice", "Betty",
	"Brianna", "Barry", "Bernard",
	"Bibi", "Blaine", "Bryn"
}
-- modes:
local Mode_Copy = 0
local Mode_Move = 1
local Mode_Swap = 2
 
local mode = 0 -- current mode

function onEnterFrame(e)
	imgui:newFrame(e.deltaTime)
 
	if (imgui:radioButton("Copy", mode == Mode_Copy)) then mode = Mode_Copy end imgui:sameLine()
	if (imgui:radioButton("Move", mode == Mode_Move)) then mode = Mode_Move end imgui:sameLine()
	if (imgui:radioButton("Swap", mode == Mode_Swap)) then mode = Mode_Swap end
 
	for i,v in ipairs(names) do
		imgui:pushID(i)
		if (((i-1) % 3) ~= 0) then imgui:sameLine() end
 
		imgui:button(v, 60, 60)
 
		if (imgui:beginDragDropSource(ImGui.DragDropFlags_None)) then
			--imgui:setStrDragDropPayload("DND_DEMO_CELL", "ID_"..i) -- used for strings
			imgui:setNumDragDropPayload("DND_DEMO_CELL", i) -- used for numbers
 
			if (mode == Mode_Copy) then imgui:text(("Copy %s"):format(v)) end
			if (mode == Mode_Move) then imgui:text(("Move %s"):format(v)) end
			if (mode == Mode_Swap) then imgui:text(("Swap %s"):format(v)) end
			imgui:endDragDropSource()
		end
 
		if (imgui:beginDragDropTarget()) then
			local payload = imgui:acceptDragDropPayload("DND_DEMO_CELL")
			if (payload) then
				--local payload_n = tonumber(payload:getStrData():sub(4))  -- if "setStrDragDropPayload" was used
				local payload_n = payload:getNumData() -- if "setNumDragDropPayload" was used
 
				if (mode == Mode_Copy) then
					names[i] = names[payload_n];
				end
				if (mode == Mode_Move) then
					names[i] = names[payload_n];
					names[payload_n] = "";
				end
 
				if (mode == Mode_Swap) then
					names[i], names[payload_n] = names[payload_n], names[i]
				end
			end
			imgui:endDragDropTarget()
		end
		imgui:popID()
	end
	imgui:render()
	imgui:endFrame()
end

stage:addEventListener("enterFrame", onEnterFrame)

Clipping

ImGui:pushClipRect(min_x, min_y, max_x, max_y, intersect_with_current_clip_rect)
ImGui:popClipRect()

ImGuiListClipper

Try to avoid creating new instances in "enterFrame" event.

Constructor:

instance = ImGuiListClipper.new()

Methods:

ImGuiListClipper:beginClip(number_of_items [, item_height = -1]) -- if item_height <= 0 then it is calculated automatically
ImGuiListClipper:endClip()
bool = ImGuiListClipper:step()
number = ImGuiListClipper:getDisplayStart()
number = ImGuiListClipper:getDisplayEnd()
number = ImGuiListClipper:getStartPosY()
number = ImGuiListClipper:getItemsCount()
ImGuiListClipper:forceDisplayRangeByIndices(number_min, number_max)

Usage example:

require "ImGui"

local imgui = ImGui.new()
stage:addChild(imgui)

clipper = ImGuiListClipper.new()

function onEnterFrame(e)
	imgui:newFrame(e.deltaTime)

	if (imgui:beginWindow("Clipper demo")) then
		if (imgui:beginTable("table", 3)) then
			imgui:tableSetupScrollFreeze(0, 1) -- cols, rows
			imgui:tableSetupColumn("One")
			imgui:tableSetupColumn("Two")
			imgui:tableSetupColumn("Three")
			imgui:tableHeadersRow()

			clipper:beginClip(100)
			while (clipper:step()) do
				for row = clipper:getDisplayStart(), clipper:getDisplayEnd() do
					imgui:tableNextRow()
					for column = 1, 3 do
						imgui:tableSetColumnIndex(column - 1)
						imgui:text(("col: %d; row: %d"):format(column, row))
					end
				end
			end
			clipper:endClip()

			imgui:endTable()
		end
	end
	imgui:endWindow()

	imgui:endFrame()
	imgui:render()
end

stage:addEventListener("enterFrame", onEnterFrame)

Context

string OR nil = ImGui:getHoveredWindow()
string OR nil = ImGui:getHoveredWindowRoot()
string OR nil = ImGui:getHoveredWindowUnderMovingWindow()
string OR nil = ImGui:getMovingWindow()
string OR nil = ImGui:getActiveIdWindow()
id = ImGui:getActiveId()
id = ImGui:getActiveIdPreviousFrame()
number = ImGui:getActiveIdTimer()
id = ImGui:getActiveIdAllowOverlap()
id = ImGui:getHoveredId()
id = ImGui:getHoveredIdPreviousFrame()
number = ImGui:getHoveredIdTimer()
id = ImGui:getHoveredIdAllowOverlap()
bool = ImGui:getDragDropActive()
id = ImGui:getDragDropPayloadSourceId()
string = ImGui:getDragDropPayloadDataType()
number = ImGui:getDragDropPayloadDataSize()

Focus, Activation

  • Prefer using "SetItemDefaultFocus()" over "if (IsWindowAppearing()) SetScrollHereY()" when applicable to signify "this is the default item"
  • Most of the functions are referring to the last/previous item we submitted.
  • See Demo Window under "Widgets->Querying Status" for an interactive visualization of most of those functions.
ImGui:setItemDefaultFocus()
ImGui:setKeyboardFocusHere([offset = 0])
flag = ImGui:isItemHovered([ImGui.HoveredFlags = 0])
flag = ImGui:isItemActive()
flag = ImGui:isItemFocused()
flag = ImGui:isItemClicked(mouse_button)
flag = ImGui:isItemVisible()
flag = ImGui:isItemEdited()
flag = ImGui:isItemActivated()
flag = ImGui:isItemDeactivated()
flag = ImGui:isItemDeactivatedAfterEdit()
flag = ImGui:isItemToggledOpen()
flag = ImGui:isAnyItemHovered()
flag = ImGui:isAnyItemActive()
flag = ImGui:isAnyItemFocused()
minX, minY, maxX, maxY = ImGui:getItemRect()
x, y = ImGui:getItemRectMin()
x, y = ImGui:getItemRectMax()
w, h = ImGui:getItemRectSize()
ImGui:setItemAllowOverlap()

INPUTS

ImGui:onMouseHover(event)
ImGui:onMouseMove(event)
ImGui:onMouseDown(event)
ImGui:onMouseUp(event)
ImGui:onMouseWheel(event)

ImGui:onTouchMove(event)
ImGui:onTouchBegin(event)
ImGui:onTouchEnd(event)
ImGui:onTouchCancel(event)

ImGui:onKeyUp(event)
ImGui:onKeyDown(event)
ImGui:onKeyChar(event)

Usage examples:

local UI = ImGui.new(nil, false, false, false)

Mouse

stage:addEventListener("mouseHover", function(e) UI:onMouseHover(e) end)
stage:addEventListener("mouseMove", function(e) UI:onMouseMove(e) end)
stage:addEventListener("mouseDown", function(e) UI:onMouseDown(e) end)
stage:addEventListener("mouseUp", function(e) UI:onMouseUp(e) end)
stage:addEventListener("mouseWheel", function(e) UI:onMouseWheel(e) end)

Touch

stage:addEventListener("touchesCancel", function(e) ui:onTouchCancel(e) end)
stage:addEventListener("touchesMove", function(e) ui:onTouchMove(e) end)
stage:addEventListener("touchesBegin", function(e) ui:onTouchBegin(e) end)
stage:addEventListener("touchesEnd", function(e) ui:onTouchEnd(e) end)

Keyboard

stage:addEventListener("keyUp", function(e) UI:onKeyUp(e) end)
stage:addEventListener("keyDown", function(e) UI:onKeyDown(e) end)
stage:addEventListener("keyChar", function(e) UI:onKeyChar(e) end)

Miscellaneous Utilities

flag = ImGui:isRectVisible(w, h [, max_x, max_y])
number = ImGui:getTime()
number = ImGui:getFrameCount()
str = ImGui:getStyleColorName(idx)
flag = ImGui:beginChildFrame(id, w, h [, ImGui.WindowFlags = 0]) -- id (number)
ImGui:endChildFrame()

Text Utilities

w, h = ImGui:calcTextSize(text [, hide_text_after_double_hash = false, wrap_width = -1])

Color convert

Note: use DOT instead of COLON, so you can use it without creating an ImGui object

r, g, b, a = ImGui.colorConvertHEXtoRGB(color [, alpha = 1])
hex = ImGui.colorConvertRGBtoHEX(r, g, b)
h, s, v = ImGui.colorConvertRGBtoHSV(r, g, b)
r, g, b = ImGui.colorConvertHSVtoRGB(h, s, v)
h, s, v = ImGui.colorConvertHEXtoHSV(hex)
hex = ImGui.colorConvertHSVtoHEX(h, s, v)

Inputs Utilities: Keyboard

  • For 'int user_key_index' you can use your own indices/enums according to how your backend/engine stored them in io.KeysDown[].
  • We don't know the meaning of those value. You can use GetKeyIndex() to map a ImGuiKey_ value into the user index.
string = ImGui:getKeyName(keyCode)
flag = ImGui:isKeyDown(keyCode)
flag = ImGui:isKeyPressed(keyCode [, repeat = true])
flag = ImGui:isKeyReleased(keyCode)
number = ImGui:getKeyPressedAmount(keyCode, repeat_delay, rate)
ImGui:setNextFrameWantCaptureKeyboard([want_capture_keyboard_value = true])

Shortcut system

-- (keyChord: an ImGuiKey optionally OR-ed with one or more ImGuiMod_XXX values (ImGuiKey | ImGuiMod_XXX))
ImGui:shortcut(keyChord [, owner_id = 0, ImGui.InputFlags = 0])

-- (useful to disable CTRL + TAB combo: ImGui:setShortcutRouting(ImGui.Mod_Ctrl | ImGui.Key_Tab, ImGui.KeyOwner_None))
ImGui:setShortcutRouting(keyChord [, owner_id = 0, ImGui.InputFlags = 0])

ImGui:setItemKeyOwner(keyCode [, ImGui.InputFlags = 0])

ImGui:setKeyOwner(keyCode, owner_id, [, ImGui.InputFlags = 0])

Focused window and global application button shortcut example

require "ImGui"

local imgui = ImGui.new()
stage:addChild(imgui)
imgui:setClassicStyle()

function onEnterFrame(e)
	imgui:newFrame(e.deltaTime)

	-- focused window button shortcut
	if imgui:button("PLAY##01", 32*2, 32*0.6) or imgui:shortcut(ImGui.Key_P) then
		print(ImGui:getItemID()) -- 2102678615
	end
	imgui:sameLine(32*2.5)
	-- focused window button shortcut (using item ID)
	if imgui:button("PLAY##02", 32*2, 32*0.6) or imgui:shortcut(ImGui.Key_Q, 8325, ImGui.FocusedFlags_AnyWindow) then
		print(ImGui:getItemID()) -- 8325
	end

	-- global app button shortcut
	if imgui:button("PLAY##03", 32*2, 32*0.6) or imgui:isKeyPressed(KeyCode.C) then
		print(ImGui:getItemID()) -- 1157645807
	end

	imgui:render()
	imgui:endFrame()
end

stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)

Global application checkbox shortcut example

require "ImGui"

local imgui = ImGui.new()
stage:addChild(imgui)
imgui:setClassicStyle()

-- some vars
local islooping = false

function onEnterFrame(e)
	imgui:newFrame(e.deltaTime)
	local ischanged = false

	islooping, ischanged = imgui:checkbox("looping(L)", islooping)
	if imgui:isKeyPressed(KeyCode.L) then
		islooping = not islooping
		ischanged = true
	end
	if ischanged then
		print("islooping", islooping)
	end

	imgui:render()
	imgui:endFrame()
end

stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)

Inputs Utilities: Mouse

  • To refer to a mouse button, you may use named enums in your code e.g. ImGuiMouseButton_Left, ImGuiMouseButton_Right.
  • You can also use regular integer: it is forever guaranteed that 0=Left, 1=Right, 2=Middle.
  • Dragging operations are only reported after mouse has moved a certain distance away from the initial clicking position (see 'lock_threshold' and 'io.MouseDraggingThreshold')
-- "mouse_button" is any gideros mouse button code
flag = ImGui:isMouseDown(mouse_button)
flag = ImGui:isMouseClicked(mouse_button [, repeat = false]) -- "mouse_button" is any gideros mouse button code
flag = ImGui:isMouseReleased(mouse_button) -- "mouse_button" is any gideros mouse button code
flag = ImGui:isMouseDoubleClicked(mouse_button) -- "mouse_button" is any gideros mouse button code
flag = ImGui:isMouseHoveringRect(min_x, min_y, max_x, max_y [, clip = true])
flag = ImGui:isMousePosValid([x = inf, y = inf])
flag = ImGui:isAnyMouseDown()
x, y = ImGui:getMousePos()
x, y = ImGui:getMousePosOnOpeningCurrentPopup()
flag = ImGui:isMouseDragging(mouse_button [, lock_threshold = -1]) -- "mouse_button" is any gideros mouse button code
x, y = ImGui:getMouseDragDelta(mouse_button [, lock_threshold = -1]) -- "mouse_button" is any gideros mouse button code
ImGui:resetMouseDragDelta(mouse_button) -- "mouse_button" is any gideros mouse button code
ImGuiMouseCursor = ImGui:getMouseCursor()
ImGui:setMouseCursor(ImGui.MouseCursor)
ImGui:setNextFrameWantCaptureMouse([want_capture_mouse_value = true])
ImGui:setNextFrameWantCaptureKeyboard([want_capture_keyboard_value = true])
ImGui:updateCursor()

FONTS

IO = imgui:getIO()
FontAtlas = IO:getFonts()

Font = FontAtlas:addFont(ttf_font_path, font_size [, options])

-- options (table): all parameters are optional
--	    fontDataOwnedByAtlas - bool
--	    pixelSnapH - bool
--	    mergeMode - bool
--	    fontNo - number
--	    oversampleH - number
--	    oversampleV - number
--	    glyphExtraSpacingX - number
--	    glyphExtraSpacingY - number
--	    glyphOffsetX - number
--	    glyphOffsetY - number
--	    glyphMinAdvanceX - number
--	    glyphMaxAdvanceX - number
--	    rasterizerFlags - number
--	    rasterizerMultiply - number
--	
--	    glyphs - table:
--		    text(string): represents available chars
--		    chars(table): list of specific char code (example: {0x7262, ...})
--		    ranges(table): predefined glyph ranges (example: {ImGui.GlyphRanges_Default, ImGui.GlyphRanges_Japanese, ...})
FontAtlas:addFonts(fontsDescription)
-- fontsDescriptions(table):
--      description(table):
--          ttf_font_path(string): path to a font
--          font_size(number): font size
--          options(table): see description above
-- example:
-- FontAtlas:addFonts{ {"fonts/DroidSans.ttf", 16}, {"fonts/ProggyTiny.ttf", 16} }

Font = FontAtlas:getFont([index]) -- get font by index (if index is 0 or nil you will get default font instance)
FontAtlas:build() -- call after multiple FontAtlas:addFont(...) calls to update ImGui font atlas 
FontAtlas:clearInputData()
FontAtlas:clearTexData()
FontAtlas:clearFonts()
FontAtlas:clear()
table = FontAtlas:getFonts() -- returns a table with all fonts (included default)
flag = FontAtlas:isBuilt()
number = FontAtlas:addCustomRectRegular(width, height)
number = FontAtlas:addCustomRectFontGlyph(font, id, width, height, advance_x [, offset_x, offset_y])
w, h, x, y, glyph_id, offset_x, offset_y, font, is_packed_flag = FontAtlas:getCustomRectByIndex(index)

ImGui:pushFont(font) -- font (table): object returned by FontAtlas:addFont(...) or FontAtlas:getFont([index])
ImGui:popFont()

Minimal example:

local UI = ImGui.new()
local IO = UI:getIO()
local FontAtlas = IO:getFonts()
local VDS_font = FontAtlas:addFont("fonts/VDS.ttf", 16, {
    oversampleH = 2,
    oversampleV = 2,
	glyphs = {
		ranges = {ImGui.GlyphRanges_Cyrillic}
	}
})
IO:setFontDefault(VDS_font)
FontAtlas:build()
stage:addChild(UI)

-- you can use multiple fonts at the same time
function enterFrame(e)
	UI:newFrame(e.deltaTime)
	
	UI:pushFont(font1)
	UI:text("Font1")
	UI:popFont()
	
	UI:pushFont(font2)
	UI:text("Font2")
	UI:popFont()
	
	UI:render()
	UI:endFrame()
end

Glyphs example:

local fonts = io:getFonts()
fonts:addFont(font_path, font_size, {
	glyphs = {
		ranges = {
			{
				0x2590,0x2593, -- range1
				0x2660,0x266B  -- range2
				-- ...
			},
			ImGui.GlyphRanges_Cyrillic,
			{
				0x01C0, 0x01C3 -- range3
			},
			ImGui.GlyphRanges_Korean
		},
 
		-- same structure:
		ranges = {
			{
				0x2590,0x2593, -- range1
				0x2660,0x266B, -- range2
				0x01C0,0x01C3  -- range3
				-- ...
			}, 
			ImGui.GlyphRanges_Cyrillic, 
			ImGui.GlyphRanges_Korean
		}
	},
	mergeMode = true, -- merge into previous font
})
fonts:build()

Icons example:

local icon = utf8.char(0x2590)
ImGui:text("My icon >>" .. icon .. " << !!!")

-- or with new Luau support:
ImGui:text("My icon >> \u{2590} << !!!")
-- can be also stored in memory:
local icon = "\u{2590}"

Font

number = Font:getSize()
FontAtlas = Font:getContainerAtlas()
Font:setScale(number)
number = Font:getScale()
number = Font:getAscent()
number = Font:getDescent()
bool = Font:isLoaded()
string = Font:getDebugName()
w, h = Font:calcTextSizeA(size, max_width, wrap_width, string)
Font:calcWordWrapPositionA(scale, string, wrap_width) -- not tested

Tables

flag = ImGui:beginTable(str_id, column [, ImGui.TableFlags = 0, outer_w = 0, outer_h = 0, inner_width = 0])
ImGui:endTable()
ImGui:tableNextRow([ImGui.TableRowFlags = 0, min_row_height = 0])
flag = ImGui:tableNextColumn()
flag = ImGui:tableSetColumnIndex(column_n)
ImGui:tableSetupColumn(label [, ImGui.TableColumnFlags = 0, init_width_or_weight = 0, user_id = 0])
ImGui:tableSetupScrollFreeze(cols, rows)
ImGui:tableHeadersRow()
TableSortSpecs = ImGui:tableGetSortSpecs() -- see below
number = ImGui:tableGetColumnCount()
number = ImGui:tableGetColumnIndex()
number = ImGui:tableGetRowIndex()
string = ImGui:tableGetColumnName([column_n = -1])
ImGuiTableColumnFlags = ImGui:tableGetColumnFlags([column_n = -1])
ImGui:tableSetBgColor(ImGui.TableBgTarget, color [, alpha = 1, column_n = -1])

Table sort specs

number = TableSortSpecs:getSpecsCount() -- TableSortSpecs = ImGui:tableGetSortSpecs()
flag = TableSortSpecs:isSpecsDirty() -- TableSortSpecs = ImGui:tableGetSortSpecs()
TableSortSpecs:setSpecsDirty(flag) -- TableSortSpecs = ImGui:tableGetSortSpecs()
table = TableSortSpecs:getColumnSortSpecs() -- TableSortSpecs = ImGui:tableGetSortSpecs(), see below

Table column sort specs

-- table = TableSortSpecs:getColumnSortSpecs()
-- each value of this table is an object that have these functions:
number = item:getColumnUserID() 
number = item:getColumnIndex() -- 0 based
number = item:getSortOrder() -- used in multi sorted tables
number = item:getSortDirection() -- ImGui.SortDirection_Ascending OR ImGui.SortDirection_Descending

Example: https://github.com/MultiPain/Gideros_examples/blob/master/ImGuiTablesDemo/assets/TablesDemo.lua

ImGuiTextFilter

Try to avoid creating new instaces in "enterFrame" event.

Constructor:

filter = ImGuiTextFilter.new()

Methods:

-- draws the input field
isValueChanged = filter:draw(label [, width = 0])
-- draws the input field (using ImGui:inutTextWithHint())
isValueChanged = filter:drawWithHint(label, hint [, width = 0])

filter:setBuffer(text) -- set filter text
filter:build() -- update filter internals (see example below)
bool = filter:passFilter(text) -- returns true if filter input matches with "text"

Usage example 1:

require "ImGui"

local imgui = ImGui.new()
stage:addChild(imgui)

local filter = ImGuiTextFilter.new()
local items = { "aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world" }

function onEnterFrame(e)
	imgui:newFrame(e.deltaTime)

	if (imgui:beginWindow("Filter demo")) then
		imgui:text([[
Filter usage:
	""         display all lines
	"xxx"      display lines containing "xxx"
	"xxx,yyy"  display lines containing "xxx" or "yyy"
	"-xxx"     hide lines containing "xxx"
		]])

		filter:draw("Filter")

		for i, text in ipairs(items) do
			if filter:passFilter(text) then
				imgui:bulletText(text)
			end
		end
	end
	imgui:endWindow()

	imgui:endFrame()
	imgui:render()
end

stage:addEventListener("enterFrame", onEnterFrame)

Usage example 2:

require "ImGui"

local imgui = ImGui.new()
stage:addChild(imgui)

local filter = ImGuiTextFilter.new()
local searchText = ""
local items = { "aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world" }

function onEnterFrame(e)
	imgui:newFrame(e.deltaTime)

	-- draw standart text input control
--	filter:drawWithHint("Filter", "Search")
	-- draw custom control
	local ischanged = false
	searchText, ischanged = imgui:inputText("Filter", searchText, 256, ImGui.InputTextFlags_EnterReturnsTrue)
	if ischanged then
		filter:setBuffer(searchText)
		-- try to avoid calling "build" function every frame
		filter:build()
	end

	for i, item in ipairs(items) do
		if not filter:passFilter(item) then
			continue
		end
		imgui:bulletText(item)
	end

	imgui:endFrame()
	imgui:render()
end

stage:addEventListener("enterFrame", onEnterFrame)

TextEditor

-- otherTextEditor: another "ImGuiTextEditor" instance to copy setting
TextEditor = ImGuiTextEditor.new([other_text_editor])

Functions:

LanguageDefinition = TextEditor:getLanguageCPP()
LanguageDefinition = TextEditor:getLanguageGLSL()
LanguageDefinition = TextEditor:getLanguageHLSL()
LanguageDefinition = TextEditor:getLanguageC()
LanguageDefinition = TextEditor:getLanguageSQL()
LanguageDefinition = TextEditor:getLanguageAngelScript()
LanguageDefinition = TextEditor:getLanguageLua()

TextEditor:setLanguageDefinition(LanguageDefinition)
LanguageDefinition = TextEditor:getLanguageDefinition()

Palette = TextEditor:getPaletteDark()
Palette = TextEditor:getPaletteLight()
Palette = TextEditor:getPaletteRetro()

TextEditor:setPalette(Palette)
Palette = TextEditor:getPalette()

TextEditor:setPaletteColor(TE_ColorIndex, color [, alpha = 1]) -- see TextEditor enums below
color, alpha = TextEditor:getPaletteColor(TE_ColorIndex)

TextEditor:loadPalette(table) -- 42 elements table
-- example:
--[[ dark palete:
TextEditor:loadPalette{
	0x7f7f7f, 1,	-- Default
	0xd69c56, 1,	-- Keyword
	0x00ff00, 1,	-- Number
	0x7070e0, 1,	-- String
	0x70a0e0, 1,	-- Char literal
	0xffffff, 1,	-- Punctuation
	0x408080, 1,	-- Preprocessor
	0xaaaaaa, 1,	-- Identifier
	0x9bc64d, 1,	-- Known identifier
	0xc040a0, 1,	-- Preproc identifier
	0x206020, 1,	-- Comment (single line)
	0x406020, 1,	-- Comment (multi line)
	0x101010, 1,	-- Background
	0xe0e0e0, 1,	-- Cursor
	0xa06020, 0.5,	-- Selection
	0x0020ff, 0.5,	-- ErrorMarker
	0xf08000, 0.25, -- Breakpoint
	0x707000, 1,	-- Line number
	0x000000, 0.25, -- Current line fill
	0x808080, 0.25, -- Current line fill (inactive)
	0xa0a0a0, 0.25, -- Current line edge
}
]]

-- see below
TextEditor:setErrorMarkers(error_markers)
TextEditor:setBreakpoints(breakpoints)

TextEditor:render(string_id [, w = 0, h = 0, border = 0])

TextEditor:setText(string)
TextEditor:getText()
TextEditor:setTextLines(table) -- set editor text using table. Structure: {"line 1", "line 2", "line 3", ...}
table = TextEditor:getTextLines()

string = TextEditor:getSelectedText()
string = TextEditor:getCurrentLineText()

number = TextEditor:getTotalLines()
bool = TextEditor:isOverwrite()

bool = TextEditor:setReadOnly()
bool = TextEditor:isReadOnly()
bool = TextEditor:isTextChanged()
bool = TextEditor:isCursorPositionChanged()

TextEditor:setColorizerEnable()
bool = TextEditor:isColorizerEnabled()

line, column = TextEditor:getCursorPosition() -- 0 based line & column number 
TextEditor:setCursorPosition(line, column)

TextEditor:setHandleMouseInputs(bool)
bool = TextEditor:isHandleMouseInputsEnabled()

TextEditor:setHandleKeyboardInputs(bool)
bool = TextEditor:isHandleKeyboardInputsEnabled()

TextEditor:setTextEditorChildIgnored(bool)
bool = TextEditor:isTextEditorChildIgnored()

TextEditor:setShowWhitespaces(bool)
bool = TextEditor:isShowingWhitespaces()

TextEditor:setTabSize(size)
size = TextEditor:getTabSize()

TextEditor:insertText(string)

TextEditor:moveUp([amount = 1, select = false])
TextEditor:moveDown([amount = 1, select = false])
TextEditor:moveLeft([amount = 1, select = false])
TextEditor:moveRight([amount = 1, select = false])
TextEditor:moveTop([select = false])
TextEditor:moveBottom([select = false])
TextEditor:moveHome([select = false])
TextEditor:moveEnd([select = false])

TextEditor:setSelectionStart(line, column)
TextEditor:setSelectionEnd(line, column)
TextEditor:setSelection(start_line, start_column, end_line, end_column)
TextEditor:selectWordUnderCursor()
TextEditor:selectAll()
bool = TextEditor:hasSelection()

TextEditor:copy()
TextEditor:cut()
TextEditor:paste()
TextEditor:delete()

bool = TextEditor:canUndo()
bool = TextEditor:canRedo()
TextEditor:undo()
TextEditor:redo()

LanguageDefinition

string = LanguageDefinition:getName()

ErrorMarkers

ErrorMarkers = ImGuiErrorMarkers.new()

ErrorMarkers:add(line, message)
ErrorMarkers:remove(line)
message = ErrorMarkers:get(line)
number = ErrorMarkers:getSize()

Breakpoints

Breakpoints = ImGuiBreakpoints.new()

Breakpoints:add(line)
Breakpoints:remove(line)
bool = Breakpoints:get(line)
number = Breakpoints:getSize()

DRAW LISTS

Window draw list:

local list = ImGui:getWindowDrawList()

Background draw list:

local list = ImGui:getBackgroundDrawList()

Foreground draw list:

local list = ImGui:getForegroundDrawList()

Draw lists commands:

DrawList:pushClipRect(clip_rect_min_x, clip_rect_min_y, clip_rect_max_x, clip_rect_max_y [, intersect_with_current_clip_rect = false])
DrawList:pushClipRectFullScreen()
DrawList:popClipRect()
DrawList:pushTextureID(texture)
DrawList:popTextureID()
x, y = DrawList:getClipRectMin()
x, y = DrawList:getClipRectMax()
DrawList:addLine(p1_x, p1_y, p2_x, p2_y, color [, alpha = 1, thickness = 1])
DrawList:addRect(
	p_min_x, p_min_y, 
	p_max_x, p_max_y, 
	color 
	[, alpha = 1, 
	rounding = 0, rounding_corners = ImGui.DrawFlags_RoundCornersAll, 
	thickness = 1])
DrawList:addRectFilled(p_min_x, p_min_y, p_max_x, p_max_y, color [, alpha = 1, rounding = 0, rounding_corners = ImGui.DrawFlags_RoundCornersAll])
DrawList:addRectFilledMultiColor(p_min_x, p_min_y, p_max_x, p_max_y, color_upr_left, color_upr_right, color_bot_right, color_bot_left)
DrawList:addQuad(p1_x, p1_y, p2_x, p2_y, p3_x, p3_y, p4_x, p4_y, color [, alpha = 1, thickness = 1])
DrawList:addQuadFilled(p1_x, p1_y, p2_x, p2_y, p3_x, p3_y, p4_x, p4_y, color)
DrawList:addTriangle(p1_x, p1_y, p2_x, p2_y, p3_x, p3_y, color [, alpha = 1, thickness = 1])
DrawList:addTriangleFilled(p1_x, p1_y, p2_x, p2_y, p3_x, p3_y, color)
DrawList:addCircle(center_x, center_y, radius, color [, alpha = 1, num_segments = 12, thickness = 1])
DrawList:addCircleFilled(center_x, center_y, radius, color [, alpha = 1, num_segments = 12])
DrawList:addNgon(center_x, center_y, radius, color [, alpha = 1, num_segments = 12, thickness = 1])
DrawList:addNgonFilled(center_x, center_y, radius, color [, alpha = 1, num_segments = 12])
DrawList:addText(x, y, color, alpha, text) -- x, y (number), text_begin (string), text_end (string)
DrawList:addFontText(font, font_size, 
	pos_x, pos_y, 
	color, alpha, 
	text 
	[, wrap_with = 0, 
	cpu_fine_clip_rect_x, cpu_fine_clip_rect_y, 
	cpu_fine_clip_rect_w, cpu_fine_clip_rect_h])
DrawList:addPolyline(points_table, color, alpha, closed, thickness) -- points_table (table), color (number), closed (bool), thickness (number)
DrawList:addConvexPolyFilled(points_table, color) -- points_table (table), color (number)
DrawList:addBezierCubic(
	p1_x, p1_y, 
	p2_x, p2_y, 
	p3_x, p3_y, 
	p4_x, p4_y, 
	color, alpha, thickness [, num_segments = 0])
DrawList:addBezierQuadratic(
	p1_x, p1_y, 
	p2_x, p2_y, 
	p3_x, p3_y, 
	color, alpha, thickness [, num_segments = 0])
DrawList:addImage(texture, 
	x, y, 
	x + w, y + h 
	[, tint_color = 0xffffff, tint_alpha = 1]) 
DrawList:addImageUV(texture, 
	x, y, 
	x + w, y + h, 
	uv0x, uv0y, 
	uv1x, uv1y 
	[, tint_color = 0xffffff, tint_alpha = 1]) 
DrawList:addImageQuad(texture, 
	x, y, 
	x + w, y, 
	x + w, y + h, 
	x, y + h 
	[, tint_color = 0xffffff, tint_alpha = 1, 
	uv0x = 0, uv0y = 0, 
	uv1x = 1, uv1y = 0, 
	uv2x = 1, uv2y = 1, 
	uv3x = 0, uv3y = 1])
DrawList:addImageRounded(texture, 
	x, y, 
	x + w, 
	y + h, 
	tint_color, tint_alpha, round_radius 
	[, corner_flags = ImGui.CorenerFlags_All])
DrawList:addImageRoundedUV(texture, 
	x, y, 
	x + w, y + h, 
	uv0x, uv0y, 
	uv1x, uv1y, 
	tint_color, tint_alpha, round_radius 
	[, corner_flags = ImGui.CorenerFlags_All])
DrawList:pathClear()
DrawList:pathLineTo(x, y)
DrawList:pathLineToMergeDuplicate(x, y)
DrawList:pathFillConvex(color)
DrawList:pathStroke(color, alpha, closed [, thickness = 1])
DrawList:pathArcTo(center_x, center_y, radius, a_min, a_max [, num_segments = 10])
DrawList:pathArcToFast(center_x, center_y, radius, a_min, a_max)
DrawList:pathBezierCubicCurveTo(p2x, p2y, p3x, p3y, p4x, p4y [, num_segments = 0])
DrawList:pathBezierQuadraticCurveTo(p2x, p2y, p3x, p3y [, num_segments = 0])
DrawList:pathRect(min_x, min_y, max_x, max_y [, rounding = 0, ImGui.DrawFlags = 0])
-- CUSTOM
-- rotate any draw list item around its center point
DrawList:rotateBegin()
DrawList:rotateEnd(radians)
-- example:
...
local list = ImGui:getWindowDrawList()
list:rotateBegin()
list:addLine(100, 100, 100, 250, 0xff0000, 1, 10)
list:rotateEnd(math.pi/2.2)
...

Usage example:

-- reference: https://github.com/ocornut/imgui/issues/3606#issuecomment-731726406
require "ImGui"

local imgui = ImGui.new()
local IO = imgui:getIO()
local w = 320
local h = 180
IO:setDisplaySize(w*2, h*2)
stage:addChild(imgui)

local cos,sin,sqrt = math.cos, math.sin, math.sqrt
local HSV2RGB = ImGui.colorConvertHSVtoRGB
local RGB2HEX = ImGui.colorConvertRGBtoHEX
local p = { -1,-1, 1,-1, 1,1, -1,1 }
local function conv(z, szx, szy, ox, oy, vx, vy) return ((vx/z)*szx*5+szx*0.5)+ox, ((vy/z)*szy*5+szy*0.5)+oy end
local function R(vx, vy, ng) ng*=0.1 local cosn = cos(ng) local sinn = sin(ng) return vx*cosn-vy*sinn, vx*sinn+vy*cosn end
local function FX(d, ax, ay, bx, by, sw, sh, t)
	d:addRectFilled(ax,ay,bx,by,0,1,0)
	t *= 4
	for i = 0, 19 do
		local z = 21-i-(t-(t//1))*2
		local ng, ot0, ot1 = -t*2.1+z, -t+z*0.2, -t+(z+1)*0.2
		local s, of, pts =
			{ cos((t+z)*0.1)*0.2+1, sin((t+z)*0.1)*0.2+1, cos((t+z+1)*0.1)*0.2+1, sin((t+z+1)*0.1)*0.2+1 },
			{ cos(ot0)*0.3, sin(ot0)*0.3, cos(ot1)*0.3, sin(ot1)*0.3 },
			{ }
		for j = 0, 7 do
			local m, n = ((j%4)+1)*2, j//4
			pts[j*2+1], pts[j*2+2] =
				conv( (z+n)*2, sw, sh, ax, ay, R(p[m-1]*s[n*2+1]+of[n*2+1], p[m-0]*s[n*2+2]+of[n*2+2], ng+n) )
		end
		for j = 0, 3 do
			local it = ( (((i&1) ~= 0) and 0.5 or 0.6) + j*0.05 ) * ( (21-z)/21 )
			d:addConvexPolyFilled(
				{
					pts[j*2+1], pts[j*2+2], pts[((j+1)%4)*2+1], pts[((j+1)%4)*2+2],
					pts[(((j+1)%4)+4)*2+1], pts[(((j+1)%4)+4)*2+2], pts[(j+4)*2+1],
					pts[(j+4)*2+2]
				},
				RGB2HEX(HSV2RGB(0.6+sin(t*0.03)*0.5, 1, sqrt(it)))
			)
		end
	end
end

function onEnterFrame(e)
	imgui:newFrame(e.deltaTime)
	if imgui:beginWindow("FX", nil, ImGui.WindowFlags_AlwaysAutoResize) then
		imgui:invisibleButton("canvas", w, h)
		local min_x, min_y = imgui:getItemRectMin()
		local max_x, max_y = imgui:getItemRectMax()
		local draw_list = imgui:getWindowDrawList()
		draw_list:pushClipRect(min_x, min_y, max_x, max_y)
		FX(draw_list, min_x, min_y, max_x, max_y, w, h, imgui:getTime())
		draw_list:popClipRect()
	end
	imgui:endWindow()
	imgui:render()
	imgui:endFrame()
end

stage:addEventListener("enterFrame", onEnterFrame)

EXPERIMENTAL

p_open = ImGui:showLog(title, p_open [, ImGui.WindowFlags = 0]) -- draw log window
ImGui:writeLog(text)

Gestures (touch only, turned OFF by default) WIP:

  • tap gesture (Left Mouse Button)
  • hold gesture (Right Mouse Button)
ImGui:setTouchGesturesEnabled(bool)
bool = ImGui:isTouchGesturesEnabled()


Dear ImGui