Skip to content

Class "ImGui"⚓︎

An example mod using the ImGui class can be found here.

Info

You can get this class by using the global table "ImGui"

Example Code
1
local isblind = ImGui.GetVisible("braillemenu")

Reference⚓︎

对于元素类型,我们使用与 ImGui 本身相同的名称。查看 交互式 ImGui 示例

Icons⚓︎

所有 ImGui 文本都支持使用图标。目前,我们使用 "FontAwesome 6",它提供约 1400 个图标。你可以在此处搜索合适的图标:https://fontawesome.com/search?o=r&m=free&s=solid

Lua 中的图标用法

如果你想在小部件中添加图标,只需使用图标的 "Unicode" 表示形式,并将其放在 \u{ } 字符串中。你可以通过在 FontAwesome 页面上选择图标,然后查看弹出窗口的右上角来找到它。你可以像这样将其添加到元素中:

"\u{f0f9} My Text"

这将在文本 "My text" 前面添加 "truck-medical" 图标。

输出: " My Text"


Functions⚓︎

AddButton ()⚓︎

void AddButton ( string ParentId, string ElementId, string Label = "", function ClickCallback = nil, boolean IsSmall = false )⚓︎


AddCallback ()⚓︎

void AddCallback ( string ElementId, ImGuiCallback Type, Function func )⚓︎

为 ImGui 元素添加回调。一个元素每种类型只能有一个回调。

AddCheckbox ()⚓︎

void AddCheckbox ( string ParentId, string ElementId, string Label = "", function ChangeCallback = nil, boolean IsActive = false )⚓︎


AddCombobox ()⚓︎

void AddCombobox ( string ParentId, string ElementId, string Label = "", function ChangeCallback = nil, table Options, int SelectedIndex = 0, boolean IsSlider = false )⚓︎

添加一个组合框元素,它表示一个单行元素,允许你从下拉菜单中选择一个值。如果 isSlider 设置为 true,则可以通过与滑块元素交互来选择值,而不是使用下拉菜单。

示例代码
1
ImGui.AddCombobox("catInput", "combobox1", "Combobox", function(index, val) print(index, val) end, { "Item 1", "Item 2", "Item 3" }, 1)

AddDragFloat ()⚓︎

void AddDragFloat ( string ParentId, string ElementId, string Label = "", function ChangeCallback = nil, float DefaultVal = 0, float Speed = 1, float Min = INTEGER_MIN, float Min = INTEGER_MAX, string Formatting = "%.3f" )⚓︎


AddDragInteger ()⚓︎

void AddDragInteger ( string ParentId, string ElementId, string Label = "", function ChangeCallback = nil, int DefaultVal = 0, float Speed = 1, int Min = INTEGER_MIN, int Min = INTEGER_MAX, string Formatting = "%d%" )⚓︎


AddElement ()⚓︎

void AddElement ( string ParentId, string ElementId = "", ImGuiElement type, string Label = "" )⚓︎

向给定的父元素添加一个通用元素。对于添加像 "SameLine"、"Bullet" 或 "Text" 这样的控制元素很有用.


AddInputColor ()⚓︎

void AddInputColor ( string ParentId, string ElementId, string Label = "", function ChangeCallback = nil, float r = 0, float g = 0, float b = 0)⚓︎

添加一个颜色输入元素。如果设置了参数 a,则它作为 RGBA 输入。否则,它只是一个 RGB 输入。浮点值在 01 之间.

回调函数会分别传入 r、g、b 和 a 值作为参数.

Example Code
1
2
ImGui.AddInputColor("catInput", "inputColorRGB", "RGB input", function(r, g, b) print(r, g, b) end, 1, 0.25, 0.45)
ImGui.AddInputColor("catInput", "inputColorRGBA", "RGBA input", function(r, g, b, a) print(r, g, b, a) end, 0.5, 0.5, 0.5,0.5)

AddInputController ()⚓︎

void AddInputController ( string ParentId, string ElementId, string ButtonLabel = "", function ChangeCallback = nil, float DefaultVal = 0 )⚓︎

回调函数会传入 ButtonAction ID 和新按钮的 ImGuiKey 名称.

添加一个用于游戏手柄 / 控制器按钮的输入.


AddInputFloat ()⚓︎

void AddInputFloat ( string ParentId, string ElementId, string Label = "", function ChangeCallback = nil, float DefaultVal = 0, float Step = 1, float StepFast = 100 )⚓︎


AddInputInteger ()⚓︎

void AddInputInteger ( string ParentId, string ElementId, string Label = "", function ChangeCallback = nil, int DefaultVal = 0, int Step = 1, int StepFast = 100 )⚓︎


AddInputKeyboard ()⚓︎

void AddInputKeyboard ( string ParentId, string ElementId, string ButtonLabel = "", function ChangeCallback = nil, float DefaultVal = 0 )⚓︎

添加一个用于键盘按钮的输入.

回调函数会传入 Keyboard key ID 和新按钮的 ImGuiKey 名称.


AddInputText ()⚓︎

void AddInputText ( string ParentId, string ElementId, string Description = "", function ChangeCallback = nil, string DefaultVal = "", string HintText = "" )⚓︎

添加一个文本输入元素。如果元素的输入为空,HintText 中的文本将作为“占位符”显示在输入元素内。


AddInputTextMultiline ()⚓︎

void AddInputTextMultiline ( string ParentId, string ElementId, string Description = "", function ChangeCallback = nil, string DefaultVal = "", float DisplayedLines = 6 )⚓︎

添加一个允许输入多行文本的文本输入元素。displayedLines 属性可用于更改元素的高度。


AddPlotHistogram ()⚓︎

void AddPlotHistogram ( string ParentId, string ElementId, string Label = "", table Values, string OverlayText = "", float Minimum = FLT_MIN, float Maximum = FLT_MAX, float Height = 40 )⚓︎

添加一个柱状图,将给定的数据显示为垂直条形。默认情况下,最小值和最大值是“动态”设置的,使图表能够完美适配其内容。


AddPlotLines ()⚓︎

void AddPlotLines ( string ParentId, string ElementId, string Label = "", table Values, string OverlayText = "", float Minimum = FLT_MIN, float Maximum = FLT_MAX, float Height = 40 )⚓︎

添加一个折线图,使用线条连接给定的值。默认情况下,最小值和最大值是“动态”设置的,使图表能够完美适配其内容。


AddProgressBar ()⚓︎

void AddProgressBar ( string ParentId, string ElementId, string Label = "", float Progress = 0, string OverlayText = "DEFAULT" )⚓︎

添加一个进度条元素。progress 值定义了填充百分比(范围从 01)。 如果未定义 overlayText,进度条将在进度条内显示当前的填充状态百分比(例如,当 progress 设置为 0.5 时显示 50%)。

如果 label 为空,进度条将在父元素的整个宽度上渲染。


AddRadioButtons ()⚓︎

void AddRadioButtons ( string ParentId, string ElementId, function ChangeCallback = nil, table options, int SelectedIndex = 0, boolean renderSameLine = true )⚓︎

Example Code
1
ImGui.AddRadioButtons("catInput", "radioButtons", function(index) print(index) end, { "Radio 1", "Radio 2", "Radio 3" }, 1)

AddSliderFloat ()⚓︎

void AddSliderFloat ( string ParentId, string ElementId, string Label = "", function ChangeCallback = nil, float DefaultVal = 0, float Min = INTEGER_MIN, float Max = INTEGER_MAX, string Formatting = "%.3f" )⚓︎


AddSliderInteger ()⚓︎

void AddSliderInteger ( string ParentId, string ElementId, string Label = "", function ChangeCallback = nil, int DefaultVal = 0, int Min = INTEGER_MIN, int Max = INTEGER_MAX, string Formatting = "%d%" )⚓︎


AddTab ()⚓︎

void AddTab ( string ParentId, string ElementId, string Label )⚓︎

父对象必须是一个标签栏(TabBar)。 标签(Tab)是一个可点击的区域,点击后会显示另一个页面或区域。


AddTabBar ()⚓︎

void AddTabBar ( string ParentId, string ElementId )⚓︎

标签栏(TabBar)是一个用于存储标签(Tab)元素的容器。


AddText ()⚓︎

void AddText ( string ParentId, string Text, boolean WrapText = false, string ElementId = "" )⚓︎

如果后续代码需要编辑该文本,也可以设置元素 ID。 创建一个文本元素。如果 wrapText 设置为 true,文本将在窗口边界处换行;如果设置为 false,窗口内容将扩展直到文本适应。


CreateMenu ()⚓︎

void CreateMenu ( string ElementId, string Label = "" )⚓︎

在《以撒的结合:忏悔》拓展模组 REPOTOGON 的主菜单栏中创建一个条目。


CreateWindow ()⚓︎

void CreateWindow ( string ElementId, string Title = "" )⚓︎

创建一个窗口对象。你需要使用 LinkWindowToElement()SetVisible() 来切换窗口的可见性。


ElementExists ()⚓︎

boolean ElementExists ( string ElementId )⚓︎

如果具有给定 ID 的元素已经存在,则返回 true


GetMousePosition ()⚓︎

void GetMousePosition ( )⚓︎

返回鼠标在屏幕坐标中的位置。 在使用 ImGui 时,请使用此函数代替 Input.GetMousePosition()


GetVisible ()⚓︎

boolean GetVisible ( string ElementId )⚓︎

获取窗口元素是否可见。


GetWindowPinned ()⚓︎

boolean GetWindowPinned ( string WindowId )⚓︎

获取窗口的固定状态。


Hide ()⚓︎

void Hide ( )⚓︎

关闭 ImGui。


ImGuiToWorld ()⚓︎

void ImGuiToWorld ( Vector Position )⚓︎

将 ImGui 坐标转换为世界坐标。

Bug

当游戏的缩放因子超过最大渲染缩放时,此函数无法正常工作。


IsVisible ()⚓︎

boolean IsVisible ( )⚓︎

当玩家正在积极使用 ImGui 时调用。这不会由“固定”窗口触发。


LinkWindowToElement ()⚓︎

void LinkWindowToElement ( string WindowId, string ElementId )⚓︎

将窗口或弹出元素连接到另一个元素,使该元素充当该窗口的“开关

示例代码
1
2
3
4
5
此代码创建一个新的菜单条目,其中包含一个菜单项,点击该菜单项会切换一个窗口
ImGui.CreateMenu("myMenu", "Test Menu")
ImGui.AddElement("myMenu", "myButton", ImGuiElement.MenuItem, "Some Text")
ImGui.CreateWindow("myWindow", "Some Window title")
ImGui.LinkWindowToElement("myWindow", "myButton")

PushNotification ()⚓︎

void PushNotification ( string Text, ImGuiNotificationType notificationType = 0, int lifetime = 5000 )⚓︎

以通知样式显示一个弹出消息窗口。


RemoveCallback ()⚓︎

void RemoveCallback ( string ElementId, ImGuiCallback type )⚓︎

从元素中移除指定类型的回调函数。


RemoveColor ()⚓︎

void RemoveColor ( string ElementId, ImGuiColor colorType )⚓︎

从元素中移除指定类型的颜色修饰符。


RemoveElement ()⚓︎

void RemoveElement ( string ElementId )⚓︎

用于移除任何类型元素的通用函数。


RemoveMenu ()⚓︎

void RemoveMenu ( string ElementId )⚓︎


RemoveWindow ()⚓︎

void RemoveWindow ( string ElementId )⚓︎


Reset ()⚓︎

void Reset ( )⚓︎

移除所有自定义定义的 ImGui 元素,并将 ImGui 恢复到其原始状态。


SetColor ()⚓︎

void SetColor ( string ElementId, ImGuiColor ColorType, float r, float g, float b, float a = 1.0 )⚓︎

为指定元素添加颜色修饰符。


SetHelpmarker ()⚓︎

void SetHelpmarker ( string ElementId, string Text )⚓︎

为指定元素添加一个帮助标记。帮助标记是一个显示在元素右侧的 (?) 元素,当鼠标悬停在其上时会显示一个工具提示。


SetTextColor ()⚓︎

void SetTextColor ( string ElementId, float r, float g, float b, float a = 1.0 )⚓︎

为指定元素的文本添加颜色修饰符的快捷函数。


SetTooltip ()⚓︎

void SetTooltip ( string ElementId, string Text )⚓︎

为指定元素添加一个工具提示。当用户将鼠标悬停在该元素上时,工具提示将显示出来。


SetVisible ()⚓︎

void SetVisible ( string ElementId, boolean Visible )⚓︎


SetWindowPinned ()⚓︎

void SetWindowPinned ( string WindowId, boolean Pinned )⚓︎

设置窗口的固定状态,使窗口在 ImGui 界面未激活时也保持可见。


SetWindowPosition ()⚓︎

void SetWindowPosition ( string WindowId, float x, float y )⚓︎

在屏幕坐标中设置窗口的位置。


SetWindowSize ()⚓︎

void SetWindowSize ( string WindowId, float width, float Height )⚓︎

以像素为单位设置窗口的宽度和高度。


Show ()⚓︎

void Show ( )⚓︎

打开 ImGui 界面。


UpdateData ()⚓︎

void UpdateData ( string ElementId, ImGuiData DataType, int NewDataValue )⚓︎

更新指定元素的任意数据。有关可能更新的数据,请参阅 ImGuiData

数据类型和预期的新数据值是针对每个元素进行评估的。因此,如果你尝试更新某个元素中未使用的数据,此函数将抛出错误。


UpdateText ()⚓︎

void UpdateText ( string ElementId, string Text )⚓︎

更新元素文本或标签的快捷函数。


WorldToImGui ()⚓︎

void WorldToImGui ( Vector Position )⚓︎

将世界坐标转换为 ImGui 坐标。

Bug

当游戏的缩放因子超过最大渲染缩放时,此函数无法正常工作。