ImGuiΒΆ
The ImGui Lua wrapper is a package that provides a Lua interface for the popular ImGui module. It allows developers to create in-game user interfaces using the familiar Lua programming language. The wrapper offers a simple and easy-to-use API that mirrors the C++ API of the ImGui module. This package provides a wide range of UI elements and widgets, customizable styling options, and support for multiple languages and internationalization. With this package, developers can easily add robust UI functionality to their games and applications written in Lua. The package also supports advanced layout and positioning options and built-in support for common UI interactions such as drag and drop, and context menus.
Some of the key features include:
A wide range of UI elements and widgets
Customizable styling options
Support for multiple languages and internationalization
Advanced layout and positioning options
Support for keyboard and mouse input
Built-in support for common UI interactions such as drag and drop, and context menus.
ReferenceΒΆ
- ImGui.setGlobalWindowPadding(x, y)ΒΆ
Sets the global window padding for all windows.
- Parameters:
x (
number
) β Padding for the x-axis.y (
number
) β Padding for the y-axis.
- ImGui.setGlobalWindowRounding(r)ΒΆ
Sets the global window rounding for all windows.
- Parameters:
r (
number
) β Rounding value.
- ImGui.setGlobalFramePadding(x, y)ΒΆ
Sets the global frame padding for all windows.
- Parameters:
x (
number
) β Padding for the x-axis.y (
number
) β Padding for the y-axis.
- ImGui.setGlobalFrameRounding(r)ΒΆ
Sets the global frame rounding for all windows.
- Parameters:
r (
number
) β Rounding value.
- ImGui.setGlobalItemSpacing(x, y)ΒΆ
Sets the global item spacing for all windows.
- Parameters:
x (
number
) β Spacing for the x-axis.y (
number
) β Spacing for the y-axis.
- ImGui.setGlobalItemInnerSpacing(x, y)ΒΆ
Sets the global item inner spacing for all windows.
- Parameters:
x (
number
) β Inner spacing for the x-axis.y (
number
) β Inner spacing for the y-axis.
- ImGui.setGlobalIndentSpacing(value)ΒΆ
Sets the global indent spacing for all windows.
- Parameters:
value (
number
) β Indent spacing value.
- ImGui.setGlobalScrollbarSize(value)ΒΆ
Sets the global scrollbar size for all windows.
- Parameters:
value (
number
) β Scrollbar size value.
- ImGui.setGlobalScrollbarRounding(value)ΒΆ
Sets the global scrollbar rounding for all windows.
- Parameters:
value (
number
) β The value of the scrollbar rounding.
- ImGui.setGlobalGrabMinSize(value)ΒΆ
Sets the global minimum width/height of a grab box for slider/scrollbar for all windows.
- Parameters:
value (
number
) β The value of the minimum grab.
- ImGui.setGlobalGrabRounding(value)ΒΆ
Sets the global radius of grabs corners rounding for all windows. Set to 0.0 to have rectangular slider grabs.
- Parameters:
value (
number
) β The value of grabs corners rounding.
- ImGui.beginDialog(text, x, y, flags)ΒΆ
Begins a new dialog.
- Parameters:
text (
str
) β The title of the dialog.x (
number
) β The x coordinate of the dialog (optional).y (
number
) β The y coordinate of the dialog (optional).flags (
WindowFlags
) β Configuration flags.
- ImGui.endDialog()ΒΆ
Ends the current dialog.
- ImGui.beginMainMenuBar()ΒΆ
Begins the main menu bar. See Creating Menu bars example.
- Returns:
Return true if the main menu bar is open, otherwise false.
- Return type:
boolean
- ImGui.endMainMenuBar()ΒΆ
Ends the current main menu bar.
- ImGui.beginMenuBar()ΒΆ
Begins a new menu-bar inside current window.
To be displayed correctly, the dialog parent needs to have the ImGui.WindowFlags.MenuBar flag enabled. See Creating Menu bars example.
- Returns:
Return true if the menu bar is open, otherwise false.
- Return type:
boolean
- ImGui.endMenuBar()ΒΆ
Ends the current menu bar.
- ImGui.beginMenu(label)ΒΆ
Begins a new menu.
- Parameters:
label (
str
) β the label of the menu. See Creating Menu bars example- Returns:
Return true if the menu is open, otherwise false.
- Return type:
boolean
- ImGui.endMenu()ΒΆ
Ends the current menu.
Creates a new menu item.
- Parameters:
mainLabel (
str
) β The main label of the menu item.secondaryLabel (
str
) β The secondary label of the menu item.
- Returns:
Return true if the menu item is pressed, otherwise false.
- Return type:
boolean
- ImGui.beginChild(label)ΒΆ
Begins a child window. See Using Groups and Child for a full example
- Parameters:
label (
str
) β the label of the child window.
- ImGui.endChild()ΒΆ
Ends the current child window.
- ImGui.beginGroup()ΒΆ
Begins a new group of items. See Using Groups and Child for a full example
- ImGui.endGroup()ΒΆ
Ends the current group of items.
- ImGui.beginTable(mode, number)ΒΆ
Begins a new table. See Using Tables for a full example.
- Parameters:
mode (
str
) β The mode of the table.number (
number
) β The number of the table.
- Returns:
Return true if the table is open, otherwise false.
- Return type:
boolean
- ImGui.endTable()ΒΆ
Ends the current table.
- ImGui.tableNextRow()ΒΆ
Appends into into the next row of the table.
- ImGui.tableNextColumn()ΒΆ
Appends into into the next column of the table.
- ImGui.tableNextRow()
Moves to the next row in the table.
- ImGui.moveToNextColumn()ΒΆ
Moves to the next column in the table.
- ImGui.tableSetCell(label)ΒΆ
Sets a cell in the table.
- Parameters:
label (
str
) β The label of the cell.
- ImGui.createColumns(numberCols)ΒΆ
Creates the specified number of columns in the current window.
- Parameters:
numberCols (
number
) β The number of columns.
- ImGui.beginTabBar(label, flags)ΒΆ
Begins a new tab bar. See Using the Tab Bar element. for a full example.
- Parameters:
label (
str
) β The label of the tab bar.flags (
TabBarFlags
) β Configuration flags.
- Returns:
Return true if the tab bar is open, otherwise false.
- Return type:
boolean
- ImGui.endTabBar()ΒΆ
Ends the current tab bar.
- ImGui.beginTabItem(label, flags)ΒΆ
Begins a new tab item.
- Parameters:
label (
str
) β The label of the tab item.flags (
TabBarFlags
) β Configuration flags.
- Returns:
Return true if the tab item is open, otherwise false.
- Return type:
boolean
- ImGui.endTabItem()ΒΆ
Ends the current tab item.
- ImGui.beginTooltip()ΒΆ
Begins a new tooltip.
- ImGui.endTooltip()ΒΆ
Ends the current tab item.
- ImGui.beginPopup(label, flags)ΒΆ
Begins a new popup window. See Creating different types of popups. for a full example.
- Parameters:
label (
str
) β The label of the pop up item.flags (
PopupFlags
) β Configuration flags.
- Returns:
Return true if the popup is open, otherwise false.
- Return type:
boolean
- ImGui.endPopup()ΒΆ
Ends the current popup window.
- ImGui.openPopup()ΒΆ
Opens a popup window identified by the label.
- ImGui.closeCurrentPopup()ΒΆ
Closes the current popup window.
- ImGui.beginPopupModal(label, flags)ΒΆ
Begins a new modal popup window.
- Parameters:
label (
str
) β The label of the pop up modal item.flags (
PopupFlags
) β Configuration flags.
- Returns:
Return true if the popup is open, otherwise false.
- Return type:
boolean
- ImGui.text(text)ΒΆ
Displays text to the current window.
- Parameters:
text (
str
) β The text to be displayed.
- ImGui.textColored(text, color)ΒΆ
Displays text to the current window with a given color.
- Parameters:
text (
str
) β the text to be displayed.color (
WidgetColor
) β An instance of WidgetColor.
- ImGui.textWrapped(text)ΒΆ
Displays wrapped text to the current window
- Parameters:
text (
str
) β The text to be displayed.
- ImGui.inputText(label, widgetString, flags)ΒΆ
Creates a text input widget.
- Parameters:
label (
str
) β the label to add to the input widget.widgetString (
WidgetString
) β An intance of WidgetString to interact with the inputText widget.flags (
InputTextFlags
) β The flags to be used for the input label (optional).
Usage:
1 2 3
local gui = require 'engine/imgui' widgetString = gui.WidgetString:new(32, "") gui.inputText("your name", widgetString)
- ImGui.inputNumber(label, widgetNumber, flags)ΒΆ
Creates a number input widget.
- Parameters:
label (
str
) β the label to add to the input widget.widgetNumber (
WidgetNumber
) β An intance of WidgetString to interact with the inputNumber widget.flags (
InputTextFlags
) β The flags to be used for the input label (optional). They are the same for InputText.
Usage:
1 2 3
local gui = require 'engine/imgui' widgetNumber = gui.WidgetNumber:new(42) gui.inputNumber("Answer to The Ultimate Question of Life", widgetNumber)
- ImGui.bulletText(text)ΒΆ
Creates a bullet point with accompanying text.
- Parameters:
text (
str
) β The text to display next to the bullet point.
- ImGui.progressBar(status)ΒΆ
Creates a new progress bar.
- Parameters:
status (
number
) β Progress status (0.0f to 1.0f) to represent in the progress bar.
- ImGui.sliderFloat(label, number, minValue, maxValue, format, flags)ΒΆ
Creates a new float slider.
- Parameters:
label (
str
) β the label to add to the slider.number (
WidgetNumber
) β The widgetNumber to use as storage.minValue (
number
) β the minimum value for the slider.maxValue (
number
) β the maximum value for the slider.format (
str
) β format of the string in the slider. The default if omitted is β%fβ.flags (
SliderFlags
) β The flags to be used for the slider (optional).
- ImGui.sliderInt(label, number, minValue, maxValue, format, flags)ΒΆ
Creates a new integer slider.
- Parameters:
label (
str
) β The label to add to the slider.number (
WidgetNumber
) β The widgetNumber to use as storage.minValue (
number
) β The minimum value for the slider.maxValue (
number
) β The maximum value for the slider.format (
str
) β The format of the string in the slider. The default if omitted is β%dβ.flags (
SliderFlags
) β The flags to be used for the slider (optional).
- ImGui.sliderVector3(label, widgetVector3, minValue, maxValue, format, flags)ΒΆ
Creates a set of three sliders for manipulating a vector3 object.
- Parameters:
label (
str
) β The label to display next to the sliders.widgetVector3 (
WidgetVector3
) β The vector3 widget object.minValue (
number
) β The minimum value for the slider.maxValue (
number
) β The maximum value for the slider.format (
str
) β The format of the string in the slider. The default if omitted is β%fβ.flags (
SliderFlags
) β The flags to be used for the slider (optional).
- ImGui.button(text, width, height)ΒΆ
Creates a new button.
- Parameters:
text (
str
) β The text to be displayed on the button.width (
number
) β The width of the button (optional).height (
number
) β The height of the button (optional).
- Returns:
Returns true if the button was clicked, otherwise false.
- Return type:
boolean
- ImGui.logButtons()ΒΆ
Logs button events in the ImGui interface.
- ImGui.logToClipboard()ΒΆ
Logs the current ImGui interface to the clipboard. Useful for debugging.
- ImGui.logFinish()ΒΆ
Stops logging events in the ImGui interface.
- ImGui.logText(text)ΒΆ
Logs a text in the ImGui interface.
- Parameters:
text (
str
) β the text to log
- ImGui.separator()ΒΆ
Adds an horizontal separator between items.
- ImGui.spacing()ΒΆ
Adds horizontal spacing between items.
- ImGui.sameLine(spacing, offset)ΒΆ
The next item will be created on the same line.
- Parameters:
spacing (
number
) β The spacing between items in pixels. If not given, the default spacing is used.offset (
number
) β The X position where the next item should start in window coordiantes. If not given, the item is placed right after the previous one.
- ImGui.selectable(text, flags)ΒΆ
Creates a selectable item.
- Parameters:
text (
str
) β Text in the selectable item.flags (
SelectableFlags
) β Configuration flags.
- ImGui.checkbox(label, number)ΒΆ
Creates a new checkbox.
- Parameters:
label (
str
) β The label of the checkbox.number (
WidgetNumber
) β The widgetNumber to use as storage.
- ImGui.checkboxFlags(label, flags)ΒΆ
Creates a new checkbox to enable/disable flags.
- Parameters:
label (
str
) β The label of the checkbox.flags (
ConfigFlags
) β Configuration flags.
- ImGui.combo(label, number, items)ΒΆ
Creates a combo box with a list of items to choose from.
are indexed from 0 and arrays in Lua are indexed from 1. You will need to offset the arrays.
- Parameters:
label (
str
) β The label of the combo box.number (
WidgetNumber
) β The widgetNumber to use as storage. Note that arrays in ImGUIitems (
array
) β An array of strings to use as options.
- ImGui.collapsingHeader(label)ΒΆ
Creates a collapsing header with a given label.
- Parameters:
label (
str
) β The label of the header.- Returns:
Return true if the header is open, false if it is closed.
- Return type:
boolean
- ImGui.treeNode(label)ΒΆ
Creates a tree node.
- Parameters:
label (
str
) β The label of the tree node.- Returns:
A boolean indicating whether the tree node is open.
- Return type:
boolean
Usage:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
local gui = require 'engine/imgui' local TreeController = Class.new(Entity) function TreeController:rendergui() gui.beginDialog("Tree Example") if gui.treeNode("Click to expand") then if gui.isItemToggledOpen() then gui.text("Just opened!") end gui.text("Some content...") gui.treePop() end gui.endDialog() end return TreeController
- ImGui.treePop()ΒΆ
Ends the current tree node.
Called after treeNode(), it ends a tree node and automatically pops it from the ImGui tree structure.
- ImGui.treePush(label)ΒΆ
Add a tree node to the GUI with the given label.
- Parameters:
label (
str
) β The label to display on the tree node.
- ImGui.colorPicker(label, color, flag)ΒΆ
Creates a color picker.
- Parameters:
label (
str
) β The label of the color picker.color (
WidgetColor
) β An instance of WidgetColor.flag (
ColorEditFlags
) β User given flags to change the behaviour the behaviour of the widget.
Usage:
1 2 3 4 5 6
local gui = Nk.ImGui gui.beginDialog("Color picker") gui.colorPicker("Pick a color", color1) gui.spacing() gui.colorEdit("Edit a color", color2) gui.endDialog()
- ImGui.colorEdit(label, color, flag)ΒΆ
Creates a color edit. Similar to ColorPicker
- Parameters:
label (
str
) β The label of the color picker.color (
WidgetColor
) β An instance of WidgetColor.flag (
ColorEditFlags
) β User given flags to change the behaviour of the widget.
- ImGui.setNextWindowPos(x, y)ΒΆ
Sets the position of the next window.
- Parameters:
x (
number
) β The x-coordinate of the window position.y (
number
) β The y-coordinate of the window position.
- ImGui.setNextWindowSize(x, y)ΒΆ
Sets the size of the next window.
- Parameters:
x (
number
) β Width of the window.y (
number
) β Height of the window.
- ImGui.setNextWindowContentSize(x, y)ΒΆ
Sets the content size of the ColorEditFlagsnext window.
- Parameters:
x (
number
) β Width of the window contenty (
number
) β Height of the window content
- ImGui.setNextWindowSizeConstraints(x, y)ΒΆ
Sets the size constraints of the next window.
- Parameters:
x (
number
) β Minimum width of the window.y (
number
) β Minimum height of the window.
- ImGui.setNextWindowCollapsed(collapsed)ΒΆ
Sets the collapsed state of the next window.
- Parameters:
collapsed (
boolean
) β Whether the window should be collapsed or not.
- ImGui.setNextWindowFocus(focused)ΒΆ
Sets the focus state of the next window.
- Parameters:
focused (
boolean
) β Whether the window should be focused or not.
- ImGui.setNextWindowBgAlpha(alpha)ΒΆ
Sets the background alpha value of the next window.
- Parameters:
alpha (
number
) β The alpha value of the background, between 0 and 1.
- ImGui.isItemHovered()ΒΆ
Determines if the current item is hovered by the mouse cursor. For an example, see Accesing item states..
- Returns:
True if the current item is being hovered by the mouse cursor, false otherwise.
- Return type:
boolean
- ImGui.isItemClicked()ΒΆ
Determines if the current item has been clicked. For an example, see Accesing item states..
- Returns:
True if the current item has been clicked, false otherwise.
- Return type:
boolean
- ImGui.isItemToggledOpen()ΒΆ
Determines if the current item is open. For an example, see Accesing item states..
- Returns:
True if the current item is toggled open, false otherwise.
- Return type:
boolean
- ImGui.isMouseClicked(event)ΒΆ
Returns true if the mouse was clicked on the given event.
- Parameters:
event (
MouseButton
) β The event for which to check for a mouse click.
- ImGui.setMouseCursor(cursor)ΒΆ
Sets the mouse cursor to the given cursor type.
- Parameters:
cursor (
MouseCursor
) β The cursor type to set.
- class ImGui.WidgetStringΒΆ
A class to internally store strings to be used in the Lumino environment.
- new(length, initialValue)ΒΆ
Creates a new WidgetString object with the given length and initial value.
- Parameters:
length (
number
) β The lenght (in btyes) of the buffer where the string is stored.initialValue (
str
) β The intial value of the string.
- getValue()ΒΆ
Retrieves the value stored inside an instance of WidgetString.
- Returns:
The string stored inside the instance of WidgetString.
- Return type:
str
- class ImGui.WidgetNumberΒΆ
A class to internally store numbers to be used in the Lumino Lua environment.
- new(initialValue)ΒΆ
Creates a new WidgetNumber object with the given initial value
- Parameters:
initialValue (
number
) β The initial value stored internally.
- getValue()ΒΆ
Retrieves the value stored inside an instance of WidgetNumber.
- Returns:
The value interally stored inside the widget number.
- Return type:
number
- setValue(value)ΒΆ
Sets a new internal value to an instance of WidgetNumber.
- Parameters:
value (
number
) β The value to set the widget number to.
- class ImGui.WidgetVector3ΒΆ
A class to internally store a 3D vector to be used in the Lumino Lua environment.
- new(x, y, z)ΒΆ
Creates a new WidgetVector3 object with the given initial values for x, y, z.
- Parameters:
x (
number
) β The initial x component value.y (
number
) β The initial y component value.z (
number
) β The initial z component value.
- Returns:
A new WidgetVector3 instance.
- Return type:
- getValue()ΒΆ
Retrieves the vector components stored inside an instance of WidgetVector3.
- Returns:
The x, y, z components stored in the widget.
- Return type:
number or number or number
- setValue(x, y, z)ΒΆ
Sets new internal values for the x, y, z components of an instance of WidgetVector3.
- Parameters:
x (
number
) β The x component to set.y (
number
) β The y component to set.z (
number
) β The z component to set.
- class ImGui.WidgetColorΒΆ
A class to internally link numbers to be used in the Dear ImGui api from the Lumino codebase to Lua environment.
- new(r, g, b, a)ΒΆ
Creates a new WidgetColor object with the given RGBA values. The RGBA values range from 0 to 1.
- Parameters:
r (
number
) β The red color component channel.g (
number
) β The green color component channel.b (
number
) β The blue color component channel.a (
number
) β The alpha color component channel.
- Returns:
A new WidgetColor instance.
- Return type:
- getValue()ΒΆ
Retrieves the RGBA components stored inside an instance of WidgetColor. The RGBA values range from 0 to 1.
- Returns:
The r, g, b, a components stored in the widget.
- Return type:
number or number or number or number
- setValue(r, g, b, a)ΒΆ
Sets new internal values for the r, g, b, a components of an instance of WidgetColor. The RGBA values range from 0 to 1.
- Parameters:
r (
number
) β The r component to set.g (
number
) β The g component to set.b (
number
) β The b component to set.a (
number
) β The a component to set.
- class ImGui.ImGuiΒΆ
- class ImGui.BackendFlagsΒΆ
Enumeration of the available backend flags.
Name
Description
None
No flag set.
HasGamepad
Backend platform supports gamepad and currently has one connected.
HasMouseCursors
Backend platform supports honoring GetMouseCursor() value to change the OS cursor shape.
HasSetMousePos
Backend platform supports io.WantSetMousePos requests to reposition the OS mouse position (only used if ImGuiConfigFlags_NavEnableSetMousePos is set).
RendererHasVtxOffset
Backend renderer supports ImDrawCmd::VtxOffset. This enables output of large meshes (64K+ vertices) while still using 16-bit indices.
- class ImGui.ConfigFlagsΒΆ
Enumeration of the available configuration flags.
Name
Description
None
No flag set.
NavEnableKeyboard
Enable keyboard controls.
NavEnableGamepad
Enable gamepad controls.
NavEnableSetMousePos
Enable mouse repositioning requests with io.WantSetMousePos.
NavNoCaptureKeyboard
Disable keyboard capture by ImGui.
NoMouse
Disable mouse controls.
NoMouseCursorChange
Disable mouse cursor change requests.
IsSRGB
Enable sRGB gamma correction.
IsTouchScreen
Enable touch screen controls.
- class ImGui.WindowFlagsΒΆ
Enumeration of the available window flags.
Name
Description
None
No flag set.
NoTitleBar
Window doesnβt have a title bar.
NoResize
Window canβt be resized.
NoMove
Window canβt be moved.
NoScrollbar
Window has no scrollbar.
NoScrollWithMouse
Window scrollbar doesnβt respond to mouse scrolling.
NoCollapse
Window canβt be collapsed.
AlwaysAutoResize
Window should resize to its content every frame.
ShowBorders
Window has borders.
NoSavedSettings
Never save settings (inodependent of ImGuiConfigFlags_NoSaveSettings).
NoMouseInputs
Window will not receive mouse inputs.
MenuBar
Window has a menu-bar.
HorizontalScrollbar
Window has a horizontal scrollbar.
NoFocusOnAppearing
Window doesnβt take focus when first appearing.
NoBringToFrontOnFocus
Window doesnβt bring to front when taking focus.
AlwaysVerticalScrollbar
Window has a vertical scrollbar.
AlwaysHorizontalScrollbar
Window has a horizontal scrollbar.
AlwaysUseWindowPadding
Ensure child windows without border uses style.WindowPadding (ignored by default for non-bordered child windows, because more convenient).
NoNavInputs
No gamepad/keyboard navigation within the window.
NoNavFocus
No focusing toward this window with gamepad/keyboard navigation (e.g. skipped by CTRL+TAB).
UnsavedDocument
Display a dot next to the title. When used in a tab/docking context, tab is selected when clicking the X + closure is not assumed (will wait for user to stop submitting the tab). Otherwise closure is assumed when pressing the X, so if you keep submitting the tab may reappear at end of tab bar.
NoNav
No gamepad/keyboard navigation within the window and no focusing toward this window with gamepad/keyboard navigation.
NoDecoration
Disable title-bar, resizing borders, and scrollbar.
NoInputs
Window is completely sealed and wonβt receive inputs.
- class ImGui.TabBarFlagsΒΆ
Enumeration of available tab bar flags.
Name
Description
None
No flags.
Reorderable
Allow manually dragging tabs to re-order them + New tabs are appended at the end of list.
AutoSelectNewTabs
Automatically select new tabs when they appear.
TabListPopupButton
Disable buttons to open the tab list popup.
NoCloseWithMiddleMouseButton
Disable behavior of closing tabs (that are submitted with p_open != NULL) with middle mouse button.
NoTabListScrollingButtons
Disable scrolling buttons (apply when fitting policy is ImGuiTabBarFlags_FittingPolicyScroll).
NoTooltip
Disable tooltips when hovering a tab.
FittingPolicyResizeDown
Resize tabs when they donβt fit.
FittingPolicyScroll
Add scroll buttons when tabs donβt fit.
FittingPolicyMask
Fitting policy mask (defaults to ImGuiTabBarFlags_FittingPolicyResizeDown | ImGuiTabBarFlags_FittingPolicyScroll).
FittingPolicyDefault
Fitting policy when there are no tabs.
- class ImGui.PopupFlagsΒΆ
Enumeration of available popup flags.
Name
Description
None
No flag set.
MouseButtonLeft
Open on Left Mouse release.
MouseButtonRight
Open on Right Mouse release.
MouseButtonMiddle
Open on Middle Mouse release.
MouseButtonMask
Bit mask for buttons.
MouseButtonDefault
Open on MouseButtonRight Mouse release (default).
NoOpenOverExistingPopup
Donβt open if thereβs already a popup at the same level of the popup stack.
NoOpenOverItems
Donβt return true when hovering items, only when hovering empty space.
AnyPopupId
Ignore the ImGuiID parameter and test for any popup.
AnyPopupLevel
Search/test at any level of the popup stack.
- class ImGui.InputTextFlagsΒΆ
Enumeration for input text flags.
Name
Description
None
No flags.
CharsDecimal
Allow decimals and operators (0123456789.+-/).
CharsHexadecimal
Allow decimals, operators ad letters (0123456789ABCDEFabcdef).
CharsUppercase
Turn lowercase letters into uppercase.
CharsNoBlank
Filter out spaces, tabs.
AutoSelectAll
Select entire text when first taking mouse focus.
EnterReturnsTrue
Return βtrueβ when Enter is pressed (as opposed to every time the value was modified).
CallbackCompletion
Callback on pressing TAB (for completion handling).
CallbackHistory
Callback on pressing Up/Down arrows (for history handling).
CallbackAlways
Callback on each iteration. User code may query cursor position, modify text buffer.
CallbackCharFilter
Callback on character inputs to replace or discard them. Modify βEventCharβ to replace or discard, or return 1 in callback to discard.
AllowTabInput
Pressing TAB input a βtβ character into the text field.
CtrlEnterForNewLine
In multi-line mode, unfocus with Enter, add new line with Ctrl+Enter (default is opposite unfocus with Ctrl+Enter, add line with Enter).
NoHorizontalScroll
Disable following the cursor horizontally.
AlwaysOverwrite
Overwrite mode.
ReadOnly
Read-only mode.
Password
Password mode, display all characters as ββ.
NoUndoRedo
Disable undo/redo. Note that input text owns the text data while active, if you want to provide your own undo/redo stack you need e.g. to call ClearActiveID().
CharsScientific
Allow scientific notation input (0123456789.+-*/eE).
CallbackResize
Callback on buffer capacity changes request (beyond βbuf_sizeβ parameter value), allowing the string to grow.
CallbackEdit
Callback on any edit.
EscapeClearsAll
Clears the input when Escape key is pressed.
- class ImGui.SliderFlagsΒΆ
Enumeration for slider flags
Name
Description
None
No flag set.
AlwaysClamp
Clamp value to min/max bounds when input manually with CTRL+Click. By default CTRL+Click allows going out of bounds.
Logarithmic
Make the widget logarithmic (linear otherwise). Consider using ImGuiSliderFlags_NoRoundToFormat with this if using a format-string with small amount of digits.
NoRoundToFormat
Disable rounding underlying value to match precision of the display format string (e.g. %.3f values are rounded to those 3 digits).
NoInput
Disable CTRL+Click or Enter key allowing to input text directly into the widget.
- class ImGui.SelectableFlagsΒΆ
Enum for selectable flags
Name
Description
None
No flag set.
DontClosePopups
Clicking this doesnβt close parent popup window.
SpanAllColumns
Selectable frame can span all columns (text will still fit in current column).
AllowDoubleClick
Generate press events on double clicks too.
Disabled
Cannot be selected, display grayed out text.
AllowItemOverlap
(WIP) Hit testing to allow subsequent widgets to overlap this one.
- class ImGui.ColorEditFlagsΒΆ
Enumeration of flags for the color editing widgets.
Name
Description
None
No flag set.
NoAlpha
ColorEdit, ColorPicker, ColorButton: ignore Alpha component (will only read 3 components from the input pointer).
NoPicker
ColorEdit: disable picker when clicking on color square.
NoOptions
ColorEdit: disable toggling options menu when right-clicking on inputs/small preview.
NoSmallPreview
ColorEdit, ColorPicker: disable color square preview next to the inputs. (e.g. to show only the inputs)
NoInputs
ColorEdit, ColorPicker: disable inputs sliders/text widgets (e.g. to show only the small preview color square).
NoTooltip
ColorEdit, ColorPicker, ColorButton: disable tooltip when hovering the preview.
NoLabel
ColorEdit, ColorPicker: disable display of inline text label (the label is still forwarded to the tooltip and picker).
NoSidePreview
ColorPicker: disable bigger color preview on right side of the picker, use small color square preview instead.
NoDragDrop
ColorEdit: disable drag and drop target. ColorButton: disable drag and drop source.
NoBorder
ColorButton: disable border (which is enforced by default)
AlphaBar
ColorEdit, ColorPicker: show vertical alpha bar/gradient in picker.
AlphaPreview
ColorEdit, ColorPicker, ColorButton: display preview as a transparent color over a checkerboard, instead of opaque.
AlphaPreviewHalf
ColorEdit, ColorPicker, ColorButton: display half opaque / half checkerboard, instead of opaque.
HDR
ColorEdit: Currently only disable 0.0f..1.0f limits in RGBA edition (note: you probably want to use ImGuiColorEditFlags_Float flag as well).
DisplayRGB
ColorEdit: override display type among RGB.
DisplayHSV
ColorEdit: override display type among HSV.
DisplayHex
ColorEdit: override display type among Hex.
Uint8
Display values formatted as 0..255.
Float
Display values formatted as 0.0f..1.0f floats instead of 0..255 integers. No round-trip of value via integers.
PickerHueBar
Display a bar for Hue and rectangle for Sat/Value.
PickerHueWheel
Display a wheel for Hue and triangle for Sat/Value.
InputRGB
Input and output data in RGB format.
InputHSV
Input and output data in HSV format.
- class ImGui.MouseButtonΒΆ
Enumeration for mouse button events.
Name
Description
Left
Index for the left mouse button.
Right
Index for the right mouse button.
Middle
Index for the middle mouse button.
COUNT
The number of mouse buttons.
- class ImGui.MouseCursorΒΆ
Enumeration of mouse cursor types for use with SetMouseCursor().
Name
Description
None
No cursor.
Arrow
Arrow cursor.
TextInput
Text input I-beam cursor.
ResizeAll
(Unused by Dear ImGui functions).
ResizeNS
Vertical resize cursor.
ResizeEW
Horizontal resize cursor.
ResizeNESW
Cursor for resizing bottom-left corner of window.
ResizeNWSE
Cursor for resizing bottom-right corner of window.
Hand
Sets mouse cursor to hand.
NotAllowed
Cursor for disallowed interaction (usually a crossed circle).
COUNT
Number of cursor types.
ExamplesΒΆ
local Imgui = require 'engine/imgui'
local Controller = Class.new(Entity)
function Controller:rendergui()
-- Begins a new main menu bar on top of the screen
if (Imgui.beginMainMenuBar()) then
if (Imgui.beginMenu("File")) then
if (Imgui.menuItem("New", "Open New File")) then
-- new file logic here
end
if (Imgui.menuItem("Open", "Open New File")) then
-- open file logic here
end
if (Imgui.menuItem("Save", "Save File")) then
-- save file logic here
end
Imgui.endMenu()
end
if (Imgui.beginMenu("Edit", "Edit File")) then
if (Imgui.menuItem("Undo", "Undo Change")) then
-- undo logic here
end
if (Imgui.menuItem("Redo", "Redo change")) then
-- redo logic here
end
Imgui.endMenu()
end
Imgui.endMainMenuBar()
end
-- Dialog with menu bar (outside the main menu bar condition)
if (Imgui.beginDialog("Dialog Menu Test", 200, 100, Imgui.WindowFlags.MenuBar)) then
if (Imgui.beginMenuBar()) then
-- Need to use beginMenu for dropdown menus
if (Imgui.beginMenu("Objects")) then
if (Imgui.menuItem("Meshes", "Add Mesh")) then
-- mesh logic here
end
if (Imgui.menuItem("Materials", "Add Material")) then
-- material logic here
end
Imgui.endMenu() -- Don't forget to end the menu
end
if (Imgui.beginMenu("PostFx")) then
if (Imgui.menuItem("Bloom", "Add Bloom")) then
-- bloom effect logic here
end
if (Imgui.menuItem("Depth of Field", "Add DoF")) then
-- DoF logic here
end
Imgui.endMenu() -- Don't forget to end the menu
end
Imgui.endMenuBar() -- End the menu bar
end
Imgui.text("Dialog menu test")
-- Rest of dialog content here
Imgui.endDialog()
end
end
return Controller
local Imgui = require 'engine/imgui'
local Controller = Class.new(Entity)
function Controller:rendergui()
-- First dialog with child window example (positioned to the left)
if (Imgui.beginDialog("Child Window Example", 550, 650, Imgui.WindowFlags.MenuBar)) then
-- Add a menu bar to the dialog
if (Imgui.beginMenuBar()) then
if (Imgui.beginMenu("File")) then
if (Imgui.menuItem("Save", "Save content")) then
-- Save logic
end
if (Imgui.menuItem("Load", "Load content")) then
-- Load logic
end
Imgui.endMenu()
end
if (Imgui.beginMenu("View")) then
if (Imgui.menuItem("Refresh", "Refresh content")) then
-- Refresh logic
end
Imgui.endMenu()
end
Imgui.endMenuBar()
end
-- Add title with some padding
Imgui.spacing()
Imgui.text("CHILD WINDOW EXAMPLE")
Imgui.separator()
Imgui.spacing()
-- Make child window slightly smaller to ensure padding
if (Imgui.beginChild("Scrolling", 520, 480, true)) then
for n=1,30,1 do
Imgui.text("Scrollable content item " .. n)
if (n % 5 == 0) then
-- Imgui.pushItemWidth(200) -- Control width of buttons
if (Imgui.button("Button " .. n)) then
-- Button action logic
end
-- Imgui.popItemWidth()
Imgui.spacing()
end
end
Imgui.endChild()
end
Imgui.spacing()
Imgui.separator()
Imgui.spacing()
Imgui.text("Footer content")
-- Center the close button
local windowWidth = 550
local buttonWidth = 100
-- Imgui.setCursorPosX((windowWidth - buttonWidth) / 2)
if (Imgui.button("Close", buttonWidth, 30)) then
-- Close logic
end
Imgui.endDialog()
end
-- Second dialog with group example (positioned to the right)
if (Imgui.beginDialog("Group Example", 600, 400)) then
-- Add title with some padding
Imgui.spacing()
Imgui.text("GROUP LAYOUT EXAMPLE")
Imgui.separator()
Imgui.spacing()
-- Create the first group
Imgui.beginGroup()
Imgui.text("Group 1")
Imgui.spacing()
-- Imgui.pushItemWidth(150) -- Consistent control width
if (Imgui.button("Button 1", 150, 30)) then
-- Button 1 logic
end
Imgui.spacing()
if (Imgui.button("Button 2", 150, 30)) then
-- Button 2 logic
end
Imgui.spacing()
-- Add a slider to the first group
local value1 = 50 -- This should be a class variable in practice
-- value1 = Imgui.sliderFloat("Slider 1", value1, 0, 100)
-- Imgui.popItemWidth()
Imgui.endGroup()
-- Place the second group on the same line with ample spacing
Imgui.sameLine(250) -- Add more spacing between groups
-- Create the second group
Imgui.beginGroup()
Imgui.text("Group 2")
Imgui.spacing()
-- Imgui.pushItemWidth(150) -- Consistent control width
if (Imgui.button("Button 3", 150, 30)) then
-- Button 3 logic
end
Imgui.spacing()
if (Imgui.button("Button 4", 150, 30)) then
-- Button 4 logic
end
Imgui.spacing()
-- Add a checkbox to the second group
local checked = false -- This should be a class variable in practice
-- checked = Imgui.checkbox("Option 1", checked)
-- Imgui.popItemWidth()
Imgui.endGroup()
-- Add a visual separator with ample spacing
Imgui.spacing()
Imgui.spacing()
Imgui.separator()
Imgui.spacing()
Imgui.spacing()
-- Create a third group below
Imgui.text("Groups can also be used for vertical layout:")
Imgui.spacing()
-- Center this group
local windowWidth = 600
local groupWidth = 400
-- Imgui.setCursorPosX((windowWidth - groupWidth) / 2)
Imgui.beginGroup()
Imgui.text("Group 3 - Controls")
Imgui.spacing()
if (Imgui.button("Save Settings", 180, 30)) then
-- Save settings logic
end
Imgui.sameLine(200)
if (Imgui.button("Load Settings", 180, 30)) then
-- Load settings logic
end
Imgui.endGroup()
Imgui.spacing()
Imgui.spacing()
Imgui.separator()
Imgui.spacing()
-- Center the close button
-- Imgui.setCursorPosX((windowWidth - 100) / 2)
if (Imgui.button("Close Dialog", 100, 30)) then
-- Close dialog logic
end
Imgui.endDialog()
end
end
return Controller
local Imgui = require 'engine/imgui'
local TableController = Class.new(Entity)
function TableController:rendergui()
-- Demo dialog with table examples
if (Imgui.beginDialog("Table Examples")) then
-- Add title with some padding
Imgui.spacing()
Imgui.text("TABLE INTERFACE EXAMPLES")
Imgui.separator()
Imgui.spacing()
-- Basic Table Example
Imgui.text("Basic 3-Column Table Example:")
Imgui.spacing()
if (Imgui.beginTable("BasicTable", 3)) then
-- Table headers
Imgui.tableNextColumn()
Imgui.text("Name")
Imgui.tableNextColumn()
Imgui.text("Value")
Imgui.tableNextColumn()
Imgui.text("Description")
-- First row
Imgui.tableNextRow()
Imgui.tableNextColumn()
Imgui.text("Item 1")
Imgui.tableNextColumn()
Imgui.text("42")
Imgui.tableNextColumn()
Imgui.text("First item description")
-- Second row
Imgui.tableNextRow()
Imgui.tableNextColumn()
Imgui.text("Item 2")
Imgui.tableNextColumn()
Imgui.text("75")
Imgui.tableNextColumn()
Imgui.text("Second item description")
-- Third row
Imgui.tableNextRow()
Imgui.tableNextColumn()
Imgui.text("Item 3")
Imgui.tableNextColumn()
Imgui.text("150")
Imgui.tableNextColumn()
Imgui.text("Third item description")
Imgui.endTable()
end
Imgui.spacing()
Imgui.separator()
Imgui.spacing()
-- Table with interactive elements
Imgui.text("Table with Interactive Elements:")
Imgui.spacing()
if (Imgui.beginTable("InteractiveTable", 3)) then
-- Table headers
Imgui.tableNextColumn()
Imgui.text("Control")
Imgui.tableNextColumn()
Imgui.text("Status")
Imgui.tableNextColumn()
Imgui.text("Action")
-- Row 1
Imgui.tableNextRow()
Imgui.tableNextColumn()
Imgui.text("Option A")
Imgui.tableNextColumn()
Imgui.text("Enabled")
Imgui.tableNextColumn()
if (Imgui.button("Disable A", 100, 25)) then
-- Disable logic
end
-- Row 2
Imgui.tableNextRow()
Imgui.tableNextColumn()
Imgui.text("Option B")
Imgui.tableNextColumn()
Imgui.text("Disabled")
Imgui.tableNextColumn()
if (Imgui.button("Enable B", 100, 25)) then
-- Enable logic
end
-- Row 3
Imgui.tableNextRow()
Imgui.tableNextColumn()
Imgui.text("Option C")
Imgui.tableNextColumn()
Imgui.text("Enabled")
Imgui.tableNextColumn()
if (Imgui.button("Disable C", 100, 25)) then
-- Disable logic
end
Imgui.endTable()
end
Imgui.spacing()
Imgui.separator()
Imgui.spacing()
-- Data Table Example
Imgui.text("Data Entry Table Example:")
Imgui.spacing()
-- Use columns as an alternative layout option
Imgui.createColumns(2)
-- Left column - table
if (Imgui.beginTable("DataTable", 2)) then
-- Headers
Imgui.tableNextColumn()
Imgui.text("Parameter")
Imgui.tableNextColumn()
Imgui.text("Value")
-- Generate some data rows
for i=1,6,1 do
Imgui.tableNextRow()
Imgui.tableNextColumn()
Imgui.text("Parameter " .. i)
Imgui.tableNextColumn()
Imgui.text(tostring(i * 10))
end
Imgui.endTable()
end
-- Move to the second column
Imgui.moveToNextColumn()
-- Right column - controls
Imgui.text("Controls:")
Imgui.spacing()
if (Imgui.button("Add Row", 120, 30)) then
-- Add row logic
end
Imgui.spacing()
if (Imgui.button("Remove Row", 120, 30)) then
-- Remove row logic
end
Imgui.spacing()
if (Imgui.button("Update Values", 120, 30)) then
-- Update values logic
end
-- Reset columns
Imgui.createColumns(1)
Imgui.spacing()
Imgui.spacing()
Imgui.separator()
Imgui.spacing()
-- Footer with button
if (Imgui.button("Close", 100, 30)) then
-- Close dialog logic
end
Imgui.endDialog()
end
end
return TableController
local Imgui = require 'engine/imgui'
local TabBarController = Class.new(Entity)
function TabBarController:rendergui()
-- Demo dialog with various tab bar examples
Imgui.setNextWindowSize(750,850)
if (Imgui.beginDialog("Tab Bar Examples")) then
-- Add title with some padding
Imgui.spacing()
Imgui.text("TAB BAR INTERFACE EXAMPLES")
Imgui.separator()
Imgui.spacing()
-- Define some colors for use in our tabs (commented out until createColor is supported)
-- local colorBlue = Imgui.createColor(0, 0.5, 1, 1)
-- local colorGreen = Imgui.createColor(0, 0.8, 0, 1)
-- local colorRed = Imgui.createColor(1, 0, 0, 1)
-- local colorYellow = Imgui.createColor(1, 0.9, 0, 1)
-- Basic Tab Bar Example
Imgui.text("Basic Tab Bar:")
Imgui.spacing()
if (Imgui.beginTabBar("BasicTabBar", Imgui.TabBarFlags.None)) then
-- First tab
if (Imgui.beginTabItem("Overview")) then
Imgui.spacing()
Imgui.text("This is a basic tab bar example.")
Imgui.spacing()
Imgui.text("Each tab contains different content and can be selected by clicking on the tab header.")
Imgui.spacing()
-- Using regular text instead of colored text
Imgui.text("Try clicking on the other tabs to see their content!")
-- Imgui.textColored("Try clicking on the other tabs to see their content!", colorBlue)
Imgui.endTabItem()
end
-- Second tab
if (Imgui.beginTabItem("Details")) then
Imgui.spacing()
Imgui.text("Tab Details:")
Imgui.spacing()
Imgui.text("- Tabs organize content into separate sections")
Imgui.text("- Only one tab is visible at a time")
Imgui.text("- Tabs can contain any UI elements")
Imgui.spacing()
if (Imgui.button("Click Me!", 120, 30)) then
-- Button action logic
end
Imgui.endTabItem()
end
-- Third tab
if (Imgui.beginTabItem("Help")) then
Imgui.spacing()
Imgui.text("Tab Navigation:")
Imgui.spacing()
Imgui.text("- Click on tab headers to switch between tabs")
Imgui.text("- Each tab maintains its own state")
Imgui.endTabItem()
end
Imgui.endTabBar()
end
Imgui.spacing()
Imgui.separator()
Imgui.spacing()
-- Advanced Tab Bar with Flags
Imgui.text("Advanced Tab Bar with Flags:")
Imgui.spacing()
-- Combining multiple flags
local tabFlags = Imgui.TabBarFlags.Reorderable + Imgui.TabBarFlags.AutoSelectNewTabs
if (Imgui.beginTabBar("AdvancedTabBar", tabFlags)) then
-- Data tab
if (Imgui.beginTabItem("Data", Imgui.TabBarFlags.None)) then
Imgui.spacing()
Imgui.text("Data View")
Imgui.spacing()
-- Add a table inside the tab
if (Imgui.beginTable("DataTable", 3)) then
-- Table headers
Imgui.tableNextColumn()
Imgui.text("Name")
-- Imgui.textColored("Name", colorBlue)
Imgui.tableNextColumn()
Imgui.text("Value")
-- Imgui.textColored("Value", colorBlue)
Imgui.tableNextColumn()
Imgui.text("Status")
-- Imgui.textColored("Status", colorBlue)
-- Row 1
Imgui.tableNextRow()
Imgui.tableNextColumn()
Imgui.text("Alpha")
Imgui.tableNextColumn()
Imgui.text("42")
Imgui.tableNextColumn()
Imgui.text("Active")
-- Imgui.textColored("Active", colorGreen)
-- Row 2
Imgui.tableNextRow()
Imgui.tableNextColumn()
Imgui.text("Beta")
Imgui.tableNextColumn()
Imgui.text("78")
Imgui.tableNextColumn()
Imgui.text("Pending")
-- Imgui.textColored("Pending", colorYellow)
-- Row 3
Imgui.tableNextRow()
Imgui.tableNextColumn()
Imgui.text("Gamma")
Imgui.tableNextColumn()
Imgui.text("15")
Imgui.tableNextColumn()
Imgui.text("Inactive")
-- Imgui.textColored("Inactive", colorRed)
Imgui.endTable()
end
Imgui.spacing()
Imgui.text("This tab demonstrates a data view with a table.")
Imgui.text("Try dragging this tab to reorder it (Reorderable flag is enabled).")
Imgui.endTabItem()
end
-- Settings tab
if (Imgui.beginTabItem("Settings", Imgui.TabBarFlags.None)) then
Imgui.spacing()
Imgui.text("Settings Panel")
Imgui.spacing()
-- Create columns for settings
Imgui.createColumns(2)
-- Left column
Imgui.text("General Settings:")
Imgui.spacing()
if (Imgui.button("Save Configuration", 150, 30)) then
-- Save config logic
end
Imgui.spacing()
if (Imgui.button("Load Configuration", 150, 30)) then
-- Load config logic
end
-- Move to right column
Imgui.moveToNextColumn()
Imgui.text("Display Settings:")
Imgui.spacing()
if (Imgui.button("Set Resolution", 150, 30)) then
-- Resolution logic
end
Imgui.spacing()
if (Imgui.button("Toggle Fullscreen", 150, 30)) then
-- Fullscreen logic
end
-- Reset columns
Imgui.createColumns(1)
Imgui.spacing()
Imgui.separator()
Imgui.spacing()
Imgui.text("This tab demonstrates settings with a column layout.")
Imgui.endTabItem()
end
-- Statistics tab
if (Imgui.beginTabItem("Statistics", Imgui.TabBarFlags.None)) then
Imgui.spacing()
Imgui.text("Statistics View")
Imgui.spacing()
-- Use a child window for scrollable content
if (Imgui.beginChild("StatsContent", 0, 200, true)) then
Imgui.text("Performance Metrics:")
Imgui.spacing()
for i=1,10,1 do
Imgui.text("Metric " .. i .. ": " .. math.random(10, 100) .. "%")
Imgui.spacing()
end
Imgui.endChild()
end
Imgui.spacing()
Imgui.text("This tab demonstrates scrollable content in a child window.")
Imgui.endTabItem()
end
Imgui.endTabBar()
end
Imgui.spacing()
Imgui.separator()
Imgui.spacing()
-- Nested Tab Bars Example
Imgui.text("Nested Tab Bars:")
Imgui.spacing()
if (Imgui.beginTabBar("OuterTabBar", Imgui.TabBarFlags.None)) then
-- First outer tab
if (Imgui.beginTabItem("Main")) then
Imgui.spacing()
Imgui.text("Main Content")
Imgui.spacing()
-- Nested inner tab bar
if (Imgui.beginTabBar("InnerTabBar", Imgui.TabBarFlags.None)) then
-- First inner tab
if (Imgui.beginTabItem("Sub-A")) then
Imgui.spacing()
Imgui.text("This is Sub-section A")
Imgui.spacing()
Imgui.text("Nested tab bars can help organize complex interfaces.")
Imgui.endTabItem()
end
-- Second inner tab
if (Imgui.beginTabItem("Sub-B")) then
Imgui.spacing()
Imgui.text("This is Sub-section B")
Imgui.spacing()
if (Imgui.button("Action B", 100, 30)) then
-- Action logic
end
Imgui.endTabItem()
end
-- Third inner tab
if (Imgui.beginTabItem("Sub-C")) then
Imgui.spacing()
Imgui.text("This is Sub-section C")
Imgui.spacing()
Imgui.text("Nested tabs can go multiple levels deep if needed.")
-- Imgui.textColored("Nested tabs can go multiple levels deep if needed.", colorBlue)
Imgui.endTabItem()
end
Imgui.endTabBar()
end
Imgui.endTabItem()
end
-- Second outer tab
if (Imgui.beginTabItem("Options")) then
Imgui.spacing()
Imgui.text("Options Panel")
Imgui.spacing()
if (Imgui.button("Apply", 100, 30)) then
-- Apply logic
end
Imgui.sameLine(120)
if (Imgui.button("Reset", 100, 30)) then
-- Reset logic
end
Imgui.endTabItem()
end
Imgui.endTabBar()
end
Imgui.spacing()
Imgui.separator()
Imgui.spacing()
-- Footer with button
if (Imgui.button("Close", 100, 30)) then
-- Close dialog logic
end
Imgui.endDialog()
end
end
return TabBarController
local Imgui = require 'engine/imgui'
local PopupController = Class.new(Entity)
function PopupController:rendergui()
-- Demo dialog with various popup examples
if (Imgui.beginDialog("Popup Examples")) then
-- Add title with some padding
Imgui.spacing()
Imgui.text("POPUP INTERFACE EXAMPLES")
Imgui.separator()
Imgui.spacing()
-- Basic Popup Example
Imgui.text("Basic Popup:")
Imgui.spacing()
if (Imgui.button("Open Basic Popup", 150, 30)) then
Imgui.openPopup("BasicPopup")
end
-- Basic popup implementation
if (Imgui.beginPopup("BasicPopup")) then
Imgui.text("This is a basic popup!")
Imgui.spacing()
Imgui.text("Popups appear over the current window")
Imgui.text("and capture keyboard/mouse inputs.")
Imgui.spacing()
if (Imgui.button("Close", 100, 30)) then
Imgui.closeCurrentPopup()
end
Imgui.endPopup()
end
Imgui.spacing()
Imgui.separator()
Imgui.spacing()
-- Context Menu Popup Example
Imgui.text("Context Menu Popup (Right-click below):")
Imgui.spacing()
-- Create a rectangle or area where right-click will open the popup
-- In actual implementation, you might have a visual element here
Imgui.text("Right-click in this area to open context menu")
-- Use PopupFlags.MouseButtonRight to open on right mouse button
if (Imgui.beginPopup("ContextMenu", Imgui.PopupFlags.MouseButtonRight)) then
Imgui.text("Context Menu")
Imgui.separator()
if (Imgui.button("Option 1", 120, 25)) then
-- Option 1 logic
Imgui.closeCurrentPopup()
end
if (Imgui.button("Option 2", 120, 25)) then
-- Option 2 logic
Imgui.closeCurrentPopup()
end
if (Imgui.button("Option 3", 120, 25)) then
-- Option 3 logic
Imgui.closeCurrentPopup()
end
Imgui.separator()
if (Imgui.button("Cancel", 120, 25)) then
Imgui.closeCurrentPopup()
end
Imgui.endPopup()
end
Imgui.spacing()
Imgui.separator()
Imgui.spacing()
-- Modal Popup Example
Imgui.text("Modal Popup (blocks interaction with other windows):")
Imgui.spacing()
if (Imgui.button("Open Modal Dialog", 150, 30)) then
Imgui.openPopup("ModalPopup")
end
-- Modal popup - blocks interaction with other windows until closed
if (Imgui.beginPopupModal("ModalPopup")) then
Imgui.text("This is a modal popup")
Imgui.spacing()
Imgui.text("Modal popups prevent interaction with other windows")
Imgui.text("until they are closed. They're useful for important")
Imgui.text("decisions or notifications that require attention.")
Imgui.spacing()
-- Create a simple form inside the modal
Imgui.text("Enter value:")
-- Here you would typically have an input field
Imgui.spacing()
Imgui.separator()
Imgui.spacing()
-- Buttons at the bottom
if (Imgui.button("Confirm", 100, 30)) then
-- Confirm action logic
Imgui.closeCurrentPopup()
end
Imgui.sameLine(120)
if (Imgui.button("Cancel", 100, 30)) then
Imgui.closeCurrentPopup()
end
Imgui.endPopup()
end
Imgui.spacing()
Imgui.separator()
Imgui.spacing()
-- Nested Popup Example
Imgui.text("Nested Popups:")
Imgui.spacing()
if (Imgui.button("Open Parent Popup", 150, 30)) then
Imgui.openPopup("ParentPopup")
end
-- Parent popup that contains a button to open a child popup
if (Imgui.beginPopup("ParentPopup")) then
Imgui.text("Parent Popup")
Imgui.spacing()
Imgui.text("This popup contains a button to open another popup.")
Imgui.spacing()
if (Imgui.button("Open Child Popup", 150, 30)) then
Imgui.openPopup("ChildPopup")
end
-- Nested child popup
if (Imgui.beginPopup("ChildPopup")) then
Imgui.text("Child Popup")
Imgui.spacing()
Imgui.text("This is a popup inside another popup!")
Imgui.spacing()
if (Imgui.button("Close Child", 120, 30)) then
Imgui.closeCurrentPopup() -- Closes only the child popup
end
Imgui.endPopup()
end
Imgui.spacing()
Imgui.separator()
Imgui.spacing()
if (Imgui.button("Close Parent", 120, 30)) then
Imgui.closeCurrentPopup() -- Closes the parent popup
end
Imgui.endPopup()
end
Imgui.spacing()
Imgui.separator()
Imgui.spacing()
-- Popup with Complex Content Example
Imgui.text("Popup with Complex Content:")
Imgui.spacing()
if (Imgui.button("Open Complex Popup", 150, 30)) then
Imgui.openPopup("ComplexPopup")
end
-- Popup containing more complex UI elements
if (Imgui.beginPopup("ComplexPopup")) then
Imgui.text("Complex Popup Example")
Imgui.spacing()
-- Create columns inside the popup
Imgui.createColumns(2)
-- Left column
Imgui.text("Column 1")
Imgui.spacing()
if (Imgui.button("Button 1", 120, 30)) then
-- Button 1 logic
end
Imgui.spacing()
if (Imgui.button("Button 2", 120, 30)) then
-- Button 2 logic
end
-- Right column
Imgui.moveToNextColumn()
Imgui.text("Column 2")
Imgui.spacing()
-- Add a table inside the popup
if (Imgui.beginTable("PopupTable", 2)) then
Imgui.tableNextColumn()
Imgui.text("Name")
Imgui.tableNextColumn()
Imgui.text("Value")
Imgui.tableNextRow()
Imgui.tableNextColumn()
Imgui.text("Item 1")
Imgui.tableNextColumn()
Imgui.text("100")
Imgui.tableNextRow()
Imgui.tableNextColumn()
Imgui.text("Item 2")
Imgui.tableNextColumn()
Imgui.text("200")
Imgui.endTable()
end
-- Reset columns
Imgui.createColumns(1)
Imgui.spacing()
Imgui.separator()
Imgui.spacing()
if (Imgui.button("Close", 100, 30)) then
Imgui.closeCurrentPopup()
end
Imgui.endPopup()
end
Imgui.spacing()
Imgui.separator()
Imgui.spacing()
-- File Menu Popup Example
Imgui.text("Menu-Style Popup:")
Imgui.spacing()
if (Imgui.button("Show File Menu", 150, 30)) then
Imgui.openPopup("FileMenuPopup")
end
-- Menu-style popup
if (Imgui.beginPopup("FileMenuPopup")) then
Imgui.text("File")
Imgui.separator()
if (Imgui.button("New", 100, 25)) then
-- New file logic
Imgui.closeCurrentPopup()
end
if (Imgui.button("Open...", 100, 25)) then
-- Open file logic
Imgui.closeCurrentPopup()
end
if (Imgui.button("Save", 100, 25)) then
-- Save file logic
Imgui.closeCurrentPopup()
end
if (Imgui.button("Save As...", 100, 25)) then
-- Save as logic
Imgui.closeCurrentPopup()
end
Imgui.separator()
if (Imgui.button("Exit", 100, 25)) then
-- Exit logic
Imgui.closeCurrentPopup()
end
Imgui.endPopup()
end
Imgui.spacing()
Imgui.separator()
Imgui.spacing()
-- Footer with button to close the dialog
if (Imgui.button("Close Dialog", 120, 30)) then
-- Close dialog logic
end
Imgui.endDialog()
end
end
return PopupController
local Imgui = require 'engine/imgui'
local ItemStateController = Class.new(Entity)
function ItemStateController:init()
-- State tracking for persistent UI behaviors
self.showExtraInfo = {} -- Track which nodes should show extra info
self.clickCounter = {} -- Track click counts for items
self.hoveredItems = {} -- Track which items were hovered last frame
end
function ItemStateController:rendergui()
Imgui.beginDialog("Item State Functions Example")
Imgui.text("This example demonstrates various item state functions:")
Imgui.spacing()
Imgui.text("- isItemHovered(): Detects when mouse is over an item")
Imgui.text("- isItemClicked(): Detects when an item is clicked")
Imgui.text("- isItemToggledOpen(): Detects when an item is freshly opened")
Imgui.spacing()
Imgui.separator()
Imgui.spacing()
-- SECTION 1: isItemHovered example
Imgui.text("1. isItemHovered() Example:")
Imgui.spacing()
-- Button that changes appearance when hovered
if Imgui.button("Hover over me", 150, 30) then
-- Button action
end
-- Check if the button is being hovered
if Imgui.isItemHovered() then
Imgui.text("Button is currently being hovered!")
-- Track this item as hovered for next frame
self.hoveredItems["hover_button"] = true
else
if self.hoveredItems["hover_button"] then
Imgui.text("Button was previously hovered")
else
Imgui.text("Button has not been hovered yet")
end
end
Imgui.spacing()
Imgui.separator()
Imgui.spacing()
-- SECTION 2: isItemClicked example
Imgui.text("2. isItemClicked() Example:")
Imgui.spacing()
-- Initialize click counter if not exists
if self.clickCounter["click_button"] == nil then
self.clickCounter["click_button"] = 0
end
-- Button that counts clicks
if Imgui.button("Click me", 150, 30) then
-- Button action happens here (standard button behavior)
end
-- Check if the button was clicked this frame
if Imgui.isItemClicked() then
self.clickCounter["click_button"] = self.clickCounter["click_button"] + 1
end
-- Display click count (persistent across frames)
Imgui.text("Button has been clicked " .. self.clickCounter["click_button"] .. " times")
Imgui.spacing()
Imgui.separator()
Imgui.spacing()
-- SECTION 3: isItemToggledOpen example with persistent state
Imgui.text("3. isItemToggledOpen() Example:")
Imgui.spacing()
-- Tree node 1: Basic example that toggles persistent visibility
local nodeId = "info_node"
local isOpen = Imgui.treeNode("Click to toggle extra information")
-- When node is first opened, update our persistent visibility state
if isOpen and Imgui.isItemToggledOpen() then
-- Toggle the visibility state when opened
self.showExtraInfo[nodeId] = not self.showExtraInfo[nodeId]
end
if isOpen then
-- Show basic content always visible when open
Imgui.text("Basic information (always visible)")
-- Show extra information if toggled on (persists across opening/closing)
if self.showExtraInfo[nodeId] then
Imgui.spacing()
Imgui.text("EXTRA INFORMATION PANEL:")
Imgui.text("This panel remains visible until you toggle it off")
Imgui.text("by opening the tree node again.")
-- Add a button to manually hide extra info
if Imgui.button("Hide Extra Info", 150, 30) then
self.showExtraInfo[nodeId] = false
end
else
Imgui.spacing()
Imgui.text("Extra information is currently hidden.")
Imgui.text("Open and close this node to toggle visibility.")
end
Imgui.treePop()
end
-- Tree node 2: Combines all three behaviors
Imgui.spacing()
local nodeId2 = "combined_node"
-- Initialize click counter if not exists
if self.clickCounter[nodeId2] == nil then
self.clickCounter[nodeId2] = 0
end
local isOpen2 = Imgui.treeNode("Combined example (hover, click, toggle)")
-- Check if node was clicked (must be done immediately after creating the tree node)
if Imgui.isItemClicked() then
self.clickCounter[nodeId2] = self.clickCounter[nodeId2] + 1
end
-- Check if node is being hovered
local isHovered = Imgui.isItemHovered()
-- Check if node was just opened
local wasJustToggled = Imgui.isItemToggledOpen()
if isOpen2 then
-- First check if this node was just opened
if wasJustToggled then
Imgui.text("Node was just opened!")
end
-- Show if the node is being hovered
if isHovered then
Imgui.text("Node is being hovered right now")
end
-- Show how many times this node has been clicked
Imgui.text("This node has been clicked " .. self.clickCounter[nodeId2] .. " times")
Imgui.treePop()
end
Imgui.endDialog()
end
return ItemStateController