ImGui
Bindings for ImGui directly inside lua.
ImGui.Begin(id)
ImGui.Begin(id)
id
- The id of the window
Begins a new ImGui Window with the given id.
Example:
function render()
ImGui.Begin("mymenu")
ImGui.Text("some text")
ImGui.End()
end
engine.addEventListener("render", render)
ImGui.Begin(id, windowFlags)
ImGui.Begin(id, windowFlags)
id
- The id of the windowwindowFlags
- The flags for the window
Begins a new ImGui Window with the given id and additional window flags. For a list of available windowflags, check here.
Example:
function render()
ImGui.Begin("mymenu", ImGuiWindowFlags.NoTitleBar)
ImGui.Text("some text")
ImGui.End()
end
engine.addEventListener("render", render)
ImGui.End()
ImGui.End()
Ends a ImGui Window.
Example:
function render()
ImGui.Begin("mymenu")
ImGui.Text("some text")
ImGui.End()
end
engine.addEventListener("render", render)
ImGui.PushStyleColor(colorIndex, color)
ImGui.PushStyleColor(colorIndex, color)
Pushes a style color identified by the colorIndex. For available indices check here. All following rendered elements targeted by the index will have this color applied to them.
For each time you push a style color, you WILL have to use ImGui.PopStyleColor after you're doing using the given color for elements.
Example:
function render()
ImGui.PushStyleColor(ImGuiCol.WindowBg, Vec4:new(255, 0, 0, 255))
ImGui.Begin("mymenu", ImGuiWindowFlags.NoTitleBar)
ImGui.Text("some text")
ImGui.End()
ImGui.PopStyleColor()
end
engine.addEventListener("render", render)
ImGui.PopStyleColor(count)
ImGui.PopStyleColor(count)
count
- How many style colors to pop of the color stack
Pops a number of style colors of the color stack.
Example:
function render()
ImGui.PushStyleColor(ImGuiCol.WindowBg, Vec4:new(255, 0, 0, 255))
ImGui.Begin("mymenu", ImGuiWindowFlags.NoTitleBar)
ImGui.Text("some text")
ImGui.End()
ImGui.PopStyleColor()
end
engine.addEventListener("render", render)
ImGui.PushStyleVarFloat(varIndex, floatValue)
ImGui.PushStyleVarFloat(varIndex, floatValue)
varIndex
- The variable index as a ImGuiStyleVarfloatValue
- The value to set the var to
Pushes a style var identified by the varIndex. For available indices check here. All following rendered elements targeted by the index will have this style variable applied to them.
For each time you push a style variable, you WILL have to use ImGui.PopStyleVar after you're doing using the given style variable for elements.
Example:
function render()
ImGui.PushStyleVarFloat(ImGuiStyleVar.WindowRounding, 10.0)
ImGui.Begin("mymenu", ImGuiWindowFlags.NoTitleBar)
ImGui.Text("some text")
ImGui.End()
ImGui.PopStyleVar()
end
engine.addEventListener("render", render)
ImGui.PushStyleVarVec2(varIndex, vec2Value)
ImGui.PushStyleVarVec2(varIndex, vec2Value)
varIndex
- The variable index as a ImGuiStyleVarvec2Value
- The Vec2 value to set the var to
Pushes a style var identified by the varIndex. For available indices check here. All following rendered elements targeted by the index will have this style variable applied to them.
For each time you push a style variable, you WILL have to use ImGui.PopStyleVar after you're doing using the given style variable for elements.
Example:
function render()
ImGui.PushStyleVarVec2(ImGuiStyleVar.WindowPadding, Vec2:new(16, 16))
ImGui.Begin("mymenu", ImGuiWindowFlags.NoTitleBar)
ImGui.Text("some text")
ImGui.End()
ImGui.PopStyleVar()
end
engine.addEventListener("render", render)
ImGui.PopStyleVar(count)
ImGui.PopStyleVar(count)
count
- How many style variables to pop of the style variable stack
Pops a number of style variable of the style variable stack.
Example:
function render()
ImGui.PushStyleVarVec2(ImGuiStyleVar.WindowPadding, Vec2:new(16, 16))
ImGui.Begin("mymenu", ImGuiWindowFlags.NoTitleBar)
ImGui.Text("some text")
ImGui.End()
ImGui.PopStyleVar()
end
engine.addEventListener("render", render)
ImGui.PushFont(name, size)
ImGui.PushFont(name, size)
name
- The name of the fontsize
- The size in pixels of the font
Available Fonts:
Verdana
VerdanaBold
Impact
Beyblade
Dameron
RobotoMono-Light
Available Font sizes:
12, 14, 16, 18, 24, 32, 36, 48, 60
Pushes a font. All following elements containing text will have this font applied until it is popped with ImGui.PopFont
Make sure to use ImGui.PopFont after you're done using the font. For one PushFont you want one PopFont.
Example:
function render()
ImGui.PushFont("VerdanaBold", 32)
ImGui.Begin("mymenu", ImGuiWindowFlags.NoTitleBar)
ImGui.Text("This is written in Verdana Bold.")
ImGui.End()
ImGui.PopFont()
end
engine.addEventListener("render", render)
ImGui.PopFont()
ImGui.PopFont()
Pops a font.
Example:
function render()
ImGui.PushFont("VerdanaBold", 32)
ImGui.Begin("mymenu", ImGuiWindowFlags.NoTitleBar)
ImGui.Text("This is written in Verdana Bold.")
ImGui.End()
ImGui.PopFont() --This is important here
end
engine.addEventListener("render", render)
ImGui.GetTexture(name)
ImGui.GetTexture(name)
name
- The name of the texture.
Returns a pointer to a IDirect3DTexture9. This can be directly used wherever the ImGui lua bindings expect a texture. For example ImGui.Image
Custom Textures
Custom Textures can be loaded the following way:
Locate the directory C:\Users\
your user
\AnvilCreate a new directory called texture_assets
You can store any images of format
.png
,.jpg
or.jpeg
in this folderThe name of each file will be the key which you pass to ImGui.GetTexture
Custom Textures Example Scenario
Suppose you put a file called icon.png into the texture_assets directory. To get access to this image as a texture that you can pass to other ImGui functions, do the following:
ImGui.GetTexture("icon")
Full Example:
function render()
ImGui.Begin("mymenu")
ImGui.Image(ImGui.GetTexture("icon"))
ImGui.End()
end
engine.addEventListener("render", render)
ImGui.BeginMenuBar()
ImGui.BeginMenuBar()
Begin a menu bar.
You will have to pass the ImGuiWindowFlags.MenuBar flag to the ImGui.Begin
in order to see the menubar!
ImGui.EndMenuBar()
ImGui.EndMenuBar()
Ends a menu bar.
ImGui.BeginMenu(menuName)
ImGui.BeginMenu(menuName)
menuName
- The name of the menu.
Begin a menu.
ImGui.EndMenu()
ImGui.EndMenu()
End a menu bar.
ImGui.MenuItem(label, shortCut, selected)
ImGui.MenuItem(label, shortCut, selected)
label
- The label of the menu itemshortCut
- Shortcut.selected
- If the menu item is selected.
Example:
local mOpen = false
local mSave = false
local function render()
ImGui.PushStyleColor(ImGuiCol.WindowBg, Vec4:new(0, 0, 0, 1))
ImGui.Begin("lua window")
if (ImGui.BeginMenuBar()) then
if (ImGui.BeginMenu("File")) then
mOpen = ImGui.MenuItem("Open", "", mOpen)
mSave = ImGui.MenuItem("Save", "", mSave)
ImGui.EndMenu()
end
ImGui.EndMenuBar()
end
ImGui.End()
ImGui.PopStyleColor(1)
end
engine.addEventListener("render", render)
ImGui.SameLine(offsetFromStart, spacing)
ImGui.SameLine(offsetFromStart, spacing)
Use this to have the next ImGui Element on the same "line" meaning vertical position.
offsetFromStart
- align to specified x positionspacing
- horizontal spacing amount in pixels
Example:
function render()
ImGui.PushFont("VerdanaBold", 16)
ImGui.Begin("mymenu")
ImGui.Text("Hello WOrld.")
ImGui.SameLine(0, 16)
ImGui.Text("I am written on the same line.")
ImGui.End()
ImGui.PopFont() --This is important here
end
engine.addEventListener("render", render)
ImGui.Image(texture, size)
ImGui.Image(texture, size)
Renders a texture with the given size.
texture
- The texture to use. Use ImGui.GetTexture to obtain a texture.size
- The size of the image as a Vec2
Example:
function render()
ImGui.PushFont("VerdanaBold", 16)
ImGui.Begin("mymenu")
ImGui.Image(ImGui.GetTexture("superman"), Vec2:new(128, 128))
ImGui.End()
ImGui.PopFont() --This is important here
end
engine.addEventListener("render", render)
ImGui.Text(text)
ImGui.Text(text)
Renders the given text.
text
- The text to render
Example:
function render()
ImGui.PushFont("VerdanaBold", 16)
ImGui.Begin("mymenu")
ImGui.Text(string.format("Hello my name is %s", "Jeff"))
ImGui.End()
ImGui.PopFont() --This is important here
end
engine.addEventListener("render", render)
ImGui.calcTextSize(text)
ImGui.calcTextSize(text)
Returns the size of the given text in the context of the currently used font as a Vec2.
text
- The text
Example:
function render()
ImGui.PushFont("VerdanaBold", 16)
ImGui.Begin("mymenu")
local text = string.format("Hello my name is %s", "Jeff")
local textSize = ImGui.calcTextSize(text)
ImGui.Text(string.format("The text has a size of %s", textSize:toString()))
ImGui.End()
ImGui.PopFont() --This is important here
end
engine.addEventListener("render", render)
ImGui.Checkbox(text, state)
ImGui.Checkbox(text, state)
Renders a checkbox with the given text as label. Returns a tuple of two boolean values.
The first boolean indicates if the checkbox was clicked this frame. The second boolean indicates the current state of the checkbox.
text
- The labelstate
- The current state of the checkbox
Example:
local useBhop = false;
local useBhopChanged = false;
function render()
ImGui.PushFont("VerdanaBold", 16)
ImGui.Begin("mymenu")
useBhopChanged, useBhop = ImGui.Checkbox("Enable bhop", useBhop)
if (useBhopChanged) then
print(string.format("Bhop checkbox changed state and is now: %s", tostring(useBhop)))
end
ImGui.End()
ImGui.PopFont() --This is important here
end
engine.addEventListener("render", render)
ImGui.Button(text, [size])
ImGui.Button(text, [size])
Renders a checkbox with the given text as label. Returns a tuple of two boolean values.
The first boolean indicates if the checkbox was clicked this frame. The second boolean indicates the current state of the checkbox.
label
- The labelsize
- The size of the button. Optional.
Example:
function render()
ImGui.PushFont("VerdanaBold", 16)
ImGui.Begin("mymenu")
if (ImGui.Button("Do something")) then
print("Button was clicked")
--Do some code...
end
if (ImGui.Button("Big button", Vec2:new(300, 300))) then
print("Big Button was clicked")
end
ImGui.End()
ImGui.PopFont() --This is important here
end
engine.addEventListener("render", render)
ImGui.GetRandomColor([alphaFloat])
ImGui.GetRandomColor([alphaFloat])
Returns a random color.
alphaFloat
- The alpha value of the color, expects 0 - 1. Optional.
Example:
local color = ImGui.GetRandomColor() -- Alpha 1.0
local transparentColor = ImGui.GetRandomColor(0.5) --Transparent
function render()
draw.circleFilled(Vec2:new(200,300), 60, color, 20)
draw.circleFilled(Vec2:new(200,400), 60, transparentColor, 20)
end
engine.addEventListener("render", render)
Last updated