Skip to main content

Class ImGuiHelpers

Class containing various helper methods for use with ImGui inside Dalamud.

Assembly: Dalamud.dll
View Source
Declaration
public static class ImGuiHelpers

Properties

MainViewport

Gets the main viewport.

View Source
Declaration
public static ImGuiViewportPtr MainViewport { get; }

GlobalScale

Gets the global Dalamud scale.

View Source
Declaration
public static float GlobalScale { get; }

IsImGuiInitialized

Gets a value indicating whether ImGui is initialized and ready for use.

This does not necessarily mean you can call drawing functions.

View Source
Declaration
public static bool IsImGuiInitialized { get; }

GlobalScaleSafe

Gets the global Dalamud scale; even available before drawing is ready.

If you are sure that drawing is ready, at the point of using this, use Dalamud.Interface.Utility.ImGuiHelpers.GlobalScale instead.

View Source
Declaration
public static float GlobalScaleSafe { get; }

Methods

CheckIsWindowOnMainViewport()

Check if the current ImGui window is on the main viewport. Only valid within a window.

View Source
Declaration
public static bool CheckIsWindowOnMainViewport()
Returns

System.Boolean: Whether the window is on the main viewport.### ScaledVector2(float) Gets a System.Numerics.Vector2 that is pre-scaled with the Dalamud.Interface.Utility.ImGuiHelpers.GlobalScale multiplier.

View Source
Declaration
public static Vector2 ScaledVector2(float x)
Returns

System.Numerics.Vector2: A scaled Vector2.

Parameters
TypeNameDescription
System.SinglexVector2 X/Y parameter.

ScaledVector2(float, float)

Gets a System.Numerics.Vector2 that is pre-scaled with the Dalamud.Interface.Utility.ImGuiHelpers.GlobalScale multiplier.

View Source
Declaration
public static Vector2 ScaledVector2(float x, float y)
Returns

System.Numerics.Vector2: A scaled Vector2.

Parameters
TypeNameDescription
System.SinglexVector2 X parameter.
System.SingleyVector2 Y parameter.

ScaledVector4(float, float, float, float)

Gets a System.Numerics.Vector4 that is pre-scaled with the Dalamud.Interface.Utility.ImGuiHelpers.GlobalScale multiplier.

View Source
Declaration
public static Vector4 ScaledVector4(float x, float y, float z, float w)
Returns

System.Numerics.Vector4: A scaled Vector2.

Parameters
TypeNameDescription
System.SinglexVector4 X parameter.
System.SingleyVector4 Y parameter.
System.SinglezVector4 Z parameter.
System.SinglewVector4 W parameter.

ForceNextWindowMainViewport()

Force the next ImGui window to stay inside the main game window.

View Source
Declaration
public static void ForceNextWindowMainViewport()

ScaledDummy(float)

Create a dummy scaled by the global Dalamud scale.

View Source
Declaration
public static void ScaledDummy(float size)
Parameters
TypeNameDescription
System.SinglesizeThe size of the dummy.

ScaledDummy(float, float)

Create a dummy scaled by the global Dalamud scale.

View Source
Declaration
public static void ScaledDummy(float x, float y)
Parameters
TypeNameDescription
System.SinglexVector2 X parameter.
System.SingleyVector2 Y parameter.

ScaledDummy(Vector2)

Create a dummy scaled by the global Dalamud scale.

View Source
Declaration
public static void ScaledDummy(Vector2 size)
Parameters
TypeNameDescription
System.Numerics.Vector2sizeThe size of the dummy.

ScaledIndent(float)

Create an indent scaled by the global Dalamud scale.

View Source
Declaration
public static void ScaledIndent(float size)
Parameters
TypeNameDescription
System.SinglesizeThe size of the indent.

ScaledRelativeSameLine(float, float)

Use a relative ImGui.SameLine() from your current cursor position, scaled by the Dalamud global scale.

View Source
Declaration
public static void ScaledRelativeSameLine(float offset, float spacing = -1)
Parameters
TypeNameDescription
System.SingleoffsetThe offset from your current cursor position.
System.SinglespacingThe spacing to use.

SetNextWindowPosRelativeMainViewport(Vector2, ImGuiCond, Vector2)

Set the position of the next window relative to the main viewport.

View Source
Declaration
public static void SetNextWindowPosRelativeMainViewport(Vector2 position, ImGuiCond condition = ImGuiCond.None, Vector2 pivot = default)
Parameters
TypeNameDescription
System.Numerics.Vector2positionThe position of the next window.
ImGuiNET.ImGuiCondconditionWhen to set the position.
System.Numerics.Vector2pivotThe pivot to set the position around.

SetWindowPosRelativeMainViewport(string, Vector2, ImGuiCond)

Set the position of a window relative to the main viewport.

View Source
Declaration
public static void SetWindowPosRelativeMainViewport(string name, Vector2 position, ImGuiCond condition = ImGuiCond.None)
Parameters
TypeNameDescription
System.StringnameThe name/ID of the window.
System.Numerics.Vector2positionThe position of the window.
ImGuiNET.ImGuiCondconditionWhen to set the position.

DefaultColorPalette(int)

Creates default color palette for use with color pickers.

View Source
Declaration
public static List<Vector4> DefaultColorPalette(int swatchCount = 32)
Returns

System.Collections.Generic.List<System.Numerics.Vector4>: Default color palette.

Parameters
TypeNameDescription
System.Int32swatchCountThe total number of swatches to use.

GetButtonSize(string)

Get the size of a button considering the default frame padding.

View Source
Declaration
public static Vector2 GetButtonSize(string text)
Returns

System.Numerics.Vector2: System.Numerics.Vector2 with the size of the button.

Parameters
TypeNameDescription
System.StringtextText in the button.

ClickToCopyText(string, string?)

Print out text that can be copied when clicked.

View Source
Declaration
public static void ClickToCopyText(string text, string? textCopy = null)
Parameters
TypeNameDescription
System.StringtextThe text to show.
System.StringtextCopyThe text to copy when clicked.

SeStringWrapped(ReadOnlySpan<byte>, scoped in SeStringDrawParams, ImGuiId, ImGuiButtonFlags)

Draws a SeString.

View Source
Declaration
public static SeStringDrawResult SeStringWrapped(ReadOnlySpan<byte> sss, scoped in SeStringDrawParams style = default, ImGuiId imGuiId = default, ImGuiButtonFlags buttonFlags = ImGuiButtonFlags.MouseButtonDefault)
Returns

Dalamud.Interface.ImGuiSeStringRenderer.SeStringDrawResult: Interaction result of the rendered text.

Parameters
TypeNameDescription
System.ReadOnlySpan<System.Byte>sssSeString to draw.
Dalamud.Interface.ImGuiSeStringRenderer.SeStringDrawParamsstyleInitial rendering style.
Dalamud.Interface.Utility.ImGuiIdimGuiIdImGui ID, if link functionality is desired.
ImGuiNET.ImGuiButtonFlagsbuttonFlagsButton flags to use on link interaction.

CompileSeStringWrapped(string, scoped in SeStringDrawParams, ImGuiId, ImGuiButtonFlags)

Creates and caches a SeString from a text macro representation, and then draws it.

View Source
Declaration
public static SeStringDrawResult CompileSeStringWrapped(string text, scoped in SeStringDrawParams style = default, ImGuiId imGuiId = default, ImGuiButtonFlags buttonFlags = ImGuiButtonFlags.MouseButtonDefault)
Returns

Dalamud.Interface.ImGuiSeStringRenderer.SeStringDrawResult: Interaction result of the rendered text.

Parameters
TypeNameDescription
System.StringtextSeString text macro representation.
Newline characters will be normalized to [Dalamud.Game.Text.SeStringHandling.Payloads.NewLinePayload](../../Dalamud.Game.Text.SeStringHandling.Payloads/Classes/NewLinePayload). |

| Dalamud.Interface.ImGuiSeStringRenderer.SeStringDrawParams | style | Initial rendering style. | | Dalamud.Interface.Utility.ImGuiId | imGuiId | ImGui ID, if link functionality is desired. | | ImGuiNET.ImGuiButtonFlags | buttonFlags | Button flags to use on link interaction. |

SafeTextWrapped(string)

Write unformatted text wrapped.

View Source
Declaration
public static void SafeTextWrapped(string text)
Parameters
TypeNameDescription
System.StringtextThe text to write.

SafeTextColoredWrapped(Vector4, string)

Write unformatted text wrapped.

View Source
Declaration
public static void SafeTextColoredWrapped(Vector4 color, string text)
Parameters
TypeNameDescription
System.Numerics.Vector4colorThe color of the text.
System.StringtextThe text to write.

AdjustGlyphMetrics(ImFontPtr, float, float)

Unscales fonts after they have been rendered onto atlas.

View Source
Declaration
public static void AdjustGlyphMetrics(this ImFontPtr fontPtr, float scale, float round = 0)
Parameters
TypeNameDescription
ImGuiNET.ImFontPtrfontPtrFont to scale.
System.SinglescaleScale.
System.SingleroundIf a positive number is given, numbers will be rounded to this.

CopyGlyphsAcrossFonts(ImFontPtr?, ImFontPtr?, bool, bool, int, int)

Fills missing glyphs in target font from source font, if both are not null.

View Source
Declaration
[Obsolete("Use the non-nullable variant.", true)]
public static void CopyGlyphsAcrossFonts(ImFontPtr? source, ImFontPtr? target, bool missingOnly, bool rebuildLookupTable = true, int rangeLow = 32, int rangeHigh = 65534)
Parameters
TypeNameDescription
System.Nullable<ImGuiNET.ImFontPtr>sourceSource font.
System.Nullable<ImGuiNET.ImFontPtr>targetTarget font.
System.BooleanmissingOnlyWhether to copy missing glyphs only.
System.BooleanrebuildLookupTableWhether to call target.BuildLookupTable().
System.Int32rangeLowLow codepoint range to copy.
System.Int32rangeHighHigh codepoing range to copy.

CopyGlyphsAcrossFonts(ImFontPtr, ImFontPtr, bool, bool, int, int)

Fills missing glyphs in target font from source font, if both are not null.

View Source
Declaration
public static void CopyGlyphsAcrossFonts(ImFontPtr source, ImFontPtr target, bool missingOnly, bool rebuildLookupTable = true, int rangeLow = 32, int rangeHigh = 65534)
Parameters
TypeNameDescription
ImGuiNET.ImFontPtrsourceSource font.
ImGuiNET.ImFontPtrtargetTarget font.
System.BooleanmissingOnlyWhether to copy missing glyphs only.
System.BooleanrebuildLookupTableWhether to call target.BuildLookupTable().
System.Int32rangeLowLow codepoint range to copy.
System.Int32rangeHighHigh codepoing range to copy.

VirtualKeyToImGuiKey(VirtualKey)

Map a VirtualKey keycode to an ImGuiKey enum value.

View Source
Declaration
public static ImGuiKey VirtualKeyToImGuiKey(VirtualKey key)
Returns

ImGuiNET.ImGuiKey: The ImGuiKey that corresponds to this VirtualKey, or ImGuiKey.None otherwise.

Parameters
TypeNameDescription
Dalamud.Game.ClientState.Keys.VirtualKeykeyThe VirtualKey value to retrieve the ImGuiKey counterpart for.

ImGuiKeyToVirtualKey(ImGuiKey)

Map an ImGuiKey enum value to a VirtualKey code.

View Source
Declaration
public static VirtualKey ImGuiKeyToVirtualKey(ImGuiKey key)
Returns

Dalamud.Game.ClientState.Keys.VirtualKey: The VirtualKey that corresponds to this ImGuiKey, or VirtualKey.NO_KEY otherwise.

Parameters
TypeNameDescription
ImGuiNET.ImGuiKeykeyThe ImGuiKey value to retrieve the VirtualKey counterpart for.

CenteredText(string)

Show centered text.

View Source
Declaration
public static void CenteredText(string text)
Parameters
TypeNameDescription
System.StringtextText to show.

CenterCursorForText(string)

Center the ImGui cursor for a certain text.

View Source
Declaration
public static void CenterCursorForText(string text)
Parameters
TypeNameDescription
System.StringtextThe text to center for.

CenterCursorFor(float)

Center the ImGui cursor for an item with a certain width.

View Source
Declaration
public static void CenterCursorFor(float itemWidth)
Parameters
TypeNameDescription
System.SingleitemWidthThe width to center for.

AllocateMemory(int)

Allocates memory on the heap using ImGuiNET.ImGuiNative.igMemAlloc(uint)

Memory must be freed using ImGuiNET.ImGuiNative.igMemFree(void*).

Note that null is a valid return value when <code class="paramref">length</code> is 0.

View Source
Declaration
public static void* AllocateMemory(int length)
Returns

System.Void*: The allocated memory.

Parameters
TypeNameDescription
System.Int32lengthThe length of allocated memory.
Exceptions

System.OutOfMemoryException
If ImGuiNET.ImGuiNative.igMemAlloc(uint) returns null.

NewFontGlyphRangeBuilderPtrScoped(out ImFontGlyphRangesBuilderPtr)

Creates a new instance of ImGuiNET.ImFontGlyphRangesBuilderPtr with a natively backed memory.

View Source
Declaration
public static IDisposable NewFontGlyphRangeBuilderPtrScoped(out ImFontGlyphRangesBuilderPtr builder)
Returns

System.IDisposable: Disposable you can call.

Parameters
TypeNameDescription
ImGuiNET.ImFontGlyphRangesBuilderPtrbuilderThe created instance.

BuildRangesToArray(ImFontGlyphRangesBuilderPtr, bool, bool)

Builds ImGui Glyph Ranges for use with Dalamud.Interface.ManagedFontAtlas.SafeFontConfig.GlyphRanges.

View Source
Declaration
public static ushort[] BuildRangesToArray(this ImFontGlyphRangesBuilderPtr builder, bool addFallbackCodepoints = true, bool addEllipsisCodepoints = true)
Returns

System.UInt16[]: When disposed, the resource allocated for the range will be freed.

Parameters
TypeNameDescription
ImGuiNET.ImFontGlyphRangesBuilderPtrbuilderThe builder.
System.BooleanaddFallbackCodepointsAdd fallback codepoints to the range.
System.BooleanaddEllipsisCodepointsAdd ellipsis codepoints to the range.

CreateImGuiRangesFrom(params UnicodeRange[])

Creates glyph ranges from System.Text.Unicode.UnicodeRange.

Use values from System.Text.Unicode.UnicodeRanges.

View Source
Declaration
public static ushort[] CreateImGuiRangesFrom(params UnicodeRange[] ranges)
Returns

System.UInt16[]: The range array that can be used for Dalamud.Interface.ManagedFontAtlas.SafeFontConfig.GlyphRanges.

Parameters
TypeNameDescription
System.Text.Unicode.UnicodeRange[]rangesThe unicode ranges.

CreateImGuiRangesFrom(IEnumerable<UnicodeRange>)

Creates glyph ranges from System.Text.Unicode.UnicodeRange.

Use values from System.Text.Unicode.UnicodeRanges.

View Source
Declaration
public static ushort[] CreateImGuiRangesFrom(IEnumerable<UnicodeRange> ranges)
Returns

System.UInt16[]: The range array that can be used for Dalamud.Interface.ManagedFontAtlas.SafeFontConfig.GlyphRanges.

Parameters
TypeNameDescription
System.Collections.Generic.IEnumerable<System.Text.Unicode.UnicodeRange>rangesThe unicode ranges.

IsNull(ImFontPtr)

Determines whether <code class="paramref">ptr</code> is empty.

View Source
Declaration
public static bool IsNull(this ImFontPtr ptr)
Returns

System.Boolean: Whether it is empty.

Parameters
TypeNameDescription
ImGuiNET.ImFontPtrptrThe pointer.

IsNotNullAndLoaded(ImFontPtr)

Determines whether <code class="paramref">ptr</code> is empty.

View Source
Declaration
public static bool IsNotNullAndLoaded(this ImFontPtr ptr)
Returns

System.Boolean: Whether it is empty.

Parameters
TypeNameDescription
ImGuiNET.ImFontPtrptrThe pointer.

IsNull(ImFontAtlasPtr)

Determines whether <code class="paramref">ptr</code> is empty.

View Source
Declaration
public static bool IsNull(this ImFontAtlasPtr ptr)
Returns

System.Boolean: Whether it is empty.

Parameters
TypeNameDescription
ImGuiNET.ImFontAtlasPtrptrThe pointer.

OrElse(ImFontPtr, ImFontPtr)

If <code class="paramref">self</code> is default, then returns <code class="paramref">other</code>.

View Source
Declaration
public static ImFontPtr OrElse(this ImFontPtr self, ImFontPtr other)
Returns

ImGuiNET.ImFontPtr: <code class="paramref">self</code> if it is not default; otherwise, <code class="paramref">other</code>.

Parameters
TypeNameDescription
ImGuiNET.ImFontPtrselfThe self.
ImGuiNET.ImFontPtrotherThe other.