Lua: ImGui

From Nomad DB

Watch Dogs: Legion ScriptHook 2.0 offers the ability to use ImGui from Lua. This page documents the available functions and a general overview on how to use them. For this purpose, we are using this library.

Event

You must use ImGui only within the OnRenderImGui event, which can also be used to identify what kind of input can be received. By default, no input is processed from ImGui!

local script = Script()
function script:OnRenderImGui()
	if ImGui.Begin("Demo") then
		ImGui.Text("Hello World")
		ImGui.End()
	end

	return ImGuiInputType.MouseForceShow + ImGuiInputType.MousePreventGameInput
end

ImGuiInputType

If you do not return a value in OnRenderImGui, then no input will be received by default. The following code snippet contains documentation of the different types. Please note that if multiple scripts want to render ImGui content, all flags will be combined.

-- Flags to specify how ImGui receives input
ImGuiInputType = {
	Default = 0,

	-- Force mouse to be visible
	MouseForceShow = 1,

	-- Prevent the game from receiving mouse input
	MousePreventGameInput = 2,

	-- Prevent the game from receiving keyboard input
	KeyboardPreventGameInput = 4
}

Functions

All common functions are available through Lua, e.g. imgui.Begin:

EndFrame, GetVersion, Begin, End, BeginChild, BeginChild_4, EndChild, IsWindowAppearing, IsWindowCollapsed, GetWindowPos, GetWindowSize, GetWindowWidth, GetWindowHeight, GetContentRegionMax, GetContentRegionAvail, GetContentRegionAvailWidth, GetWindowContentRegionMin, GetWindowContentRegionMax, GetWindowContentRegionWidth, SetNextWindowContentSize, SetNextWindowFocus, SetNextWindowBgAlpha, SetWindowFocus, SetWindowFontScale, SetWindowFocus_1, GetScrollX, GetScrollY, GetScrollMaxX, GetScrollMaxY, SetScrollX, SetScrollY, SetScrollFromPosY, PopFont, PushStyleColor, PushStyleColor_2, PopStyleColor, PushStyleVar, PushStyleVar_2, PopStyleVar, GetFontSize, GetFontTexUvWhitePixel, GetColorU32, GetColorU32_1, GetColorU32_1_1, PushItemWidth, PopItemWidth, CalcItemWidth, PushTextWrapPos, PopTextWrapPos, PushAllowKeyboardFocus, PopAllowKeyboardFocus, PushButtonRepeat, PopButtonRepeat, Separator, SameLine, NewLine, Spacing, Dummy, Indent, Unindent, BeginGroup, EndGroup, GetCursorPos, GetCursorPosX, GetCursorPosY, SetCursorPos, SetCursorPosX, SetCursorPosY, GetCursorStartPos, GetCursorScreenPos, SetCursorScreenPos, AlignTextToFramePadding, GetTextLineHeight, GetTextLineHeightWithSpacing, GetFrameHeight, GetFrameHeightWithSpacing, PushID, PushID_2, PushID_1, PopID, GetID, GetID_2, TextUnformatted, Button, SmallButton, InvisibleButton, Image, ImageButton, Checkbox, CheckboxFlags, RadioButton, RadioButton_3, ProgressBar, Bullet, EndCombo, Combo, DragFloat, DragFloatRange2, DragInt, DragIntRange2, InputFloat, InputInt, SliderFloat, SliderAngle, SliderInt, VSliderFloat, VSliderInt, TreeNode, TreePush, TreePop, TreeAdvanceToLabelPos, GetTreeNodeToLabelSpacing, Selectable, Selectable_4, ListBoxHeader, ListBoxHeader_3, ListBoxFooter, Value, Value_2, Value_2_2, Value_3, BeginTooltip, EndTooltip, BeginMainMenuBar, EndMainMenuBar, BeginMenuBar, EndMenuBar, BeginMenu, EndMenu, MenuItem, MenuItem_4, OpenPopup, BeginPopup, BeginPopupContextItem, BeginPopupContextWindow, BeginPopupContextVoid, BeginPopupModal, EndPopup, IsPopupOpen, CloseCurrentPopup, Columns, NextColumn, GetColumnWidth, SetColumnWidth, GetColumnOffset, SetColumnOffset, LogToTTY, LogToFile, LogToClipboard, LogFinish, LogButtons, EndDragDropSource, BeginDragDropTarget, EndDragDropTarget, PushClipRect, PopClipRect, SetItemDefaultFocus, SetKeyboardFocusHere, IsItemActive, IsItemFocused, IsItemClicked, IsItemVisible, IsAnyItemHovered, IsAnyItemActive, IsAnyItemFocused, GetItemRectMin, GetItemRectMax, GetItemRectSize, SetItemAllowOverlap, IsRectVisible, IsRectVisible_2, GetTime, GetStyleColorName, CalcTextSize, CalcListClipping, BeginChildFrame, EndChildFrame, ColorConvertFloat4ToU32, IsKeyDown, IsKeyPressed, IsKeyReleased, IsMouseDown, IsAnyMouseDown, IsMouseClicked, IsMouseDoubleClicked, IsMouseReleased, IsMouseDragging, IsMouseHoveringRect, GetMousePos, GetMousePosOnOpeningCurrentPopup, GetMouseDragDelta, ResetMouseDragDelta, SetMouseCursor, CaptureKeyboardFromApp, CaptureMouseFromApp, GetClipboardText, SetClipboardText,

DrawList (via imgui.DrawList_)

PushClipRect, PushClipRectFullScreen, PopClipRect, PushTextureID, PopTextureID, AddLine, AddRect, AddRectFilled, AddRectFilledMultiColor, AddQuad, AddQuadFilled, AddTriangle, AddTriangleFilled, AddCircle, AddCircleFilled, AddText, AddImage, AddImageQuad, AddImageRounded, AddBezierCurve, PathArcTo, PathArcToFast, PathBezierCurveTo, PathRect, ChannelsSplit, ChannelsMerge, ChannelsSetCurrent, AddDrawCmd, PrimReserve, PrimRect, PrimRectUV, PrimQuadUV)

Pointers

Lua doesn't have pointers but it has multiple return values so instead of giving it a pointer, you give it a value and it will pass back the new value.

C++

IMGUI_API bool Begin(const char* name, bool* p_opened = NULL, ImGuiWindowFlags flags = 0);

Lua

shoulddraw, p_opened = imgui.Begin("Name", p_opened)