ImGui

Bindings for ImGui directly inside lua.

Not all ImGui methods or enums are available. If you're in need of a specific method, you can ask on our Discord and we will try to add support for it as soon as possible.

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)

  • id - The id of the window

  • windowFlags - 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()

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)

  • colorIndex - The color index as a ImGuiCol

  • color - The color as a Vec4

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.

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)

  • 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)

  • varIndex - The variable index as a ImGuiStyleVar

  • floatValue - 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.

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)

  • varIndex - The variable index as a ImGuiStyleVar

  • vec2Value - 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.

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)

  • 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)

  • name - The name of the font

  • size - 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

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()

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)

  • 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:

  1. Locate the directory C:\Users\your user\Anvil

  2. Create a new directory called texture_assets

  3. You can store any images of format .png, .jpg or .jpeg in this folder

  4. The 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()

Begin a menu bar.

ImGui.EndMenuBar()

Ends a menu bar.

ImGui.BeginMenu(menuName)

  • menuName - The name of the menu.

Begin a menu.

ImGui.EndMenu()

End a menu bar.

ImGui.MenuItem(label, shortCut, selected)

  • label - The label of the menu item

  • shortCut - 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)

Use this to have the next ImGui Element on the same "line" meaning vertical position.

  • offsetFromStart - align to specified x position

  • spacing - 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)

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)

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)

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)

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 label

  • state - 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])

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 label

  • size - 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])

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