Skip to content

dextercd/Noita-Dear-ImGui

Repository files navigation

Noita Dear ImGui bindings

Users

If you want to install this mod, head over to the Releases and download the latest build (NoitaDearImGui-X.Y.Z.zip NOT the source code).

How to use this in your own mod?

You are not expected to bundle this mod with your own mod, you should instead instruct people to install this themselves alongside your mod.

Any mod below this mod in the load order can use the ImGui bindings. This mod requires 'unsafe' mode, but mods that use the ImGui bindings don't need unsafe mode themselves.

Make sure to occassionally switch the build type to 'Debug (for devs)' during development or if the game starts crashing. This often helps identify mistakes in use of the bindings.

Also check out the ImGui FAQ: https://github.com/ocornut/imgui/blob/master/docs/FAQ.md a lot of stuff there also applies to these bindings.

Documentation

There's generated documentation containing all the function signatures.

You can just refer to this file manually, but it's also possible to load into VS Code or any other editor that supports the LuaLS/Lua Language Server.

VS Code is pretty easy to setup:

  1. Get the Lua language server extension. https://marketplace.visualstudio.com/items?itemName=sumneko.lua
  2. Go into the extension's settings and add the imguidoc directory. This is included in the mod release zip.
  3. It should now be working. Press ctrl+space to trigger autocomplete.

Bindings

The bindings are a relatively close 1:1 mapping of the normal ImGui functions except:

  • References are used in ImGui to pass data in and alter it. Lua doesn't have references so this is turned into by-value arguments and additional return values.

  • Most structures are broken up into individual elements. So instead of a ImVec2 size argument, these bindings will accept two arguments size_x, size_y.

  • ImGui's Begin/BeginChild functions have an inconsistency that's explained here. This inconsistency is fixed in the bindings.

  • Enums don't have the ImGui prefix since you already have to use them through the imgui table.

This standard ImGui code:

ImGui::ColorEdit3("Color", (float*)&color,
    ImGuiColorEditFlags_PickerHueWheel | ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_NoAlpha);

turns into this with these Noita/Lua bindings:

_, r, g, b = imgui.ColorEdit3("Colour", r, g, b,
    bit.bor(imgui.ColorEditFlags.PickerHueWheel, imgui.ColorEditFlags.NoSidePreview, imgui.ColorEditFlags.NoAlpha))

Example mod

There's an example mod that shows the basics: https://github.com/dextercd/Noita-Dear-ImGui/blob/main/ExampleMod/init.lua

Credit

Many thanks to 🌸Rain🌸 (vexx32) on the Noita Discord for the Noita pixel and glyph ttf files she created: Discord message (Download).

  • This repo hosts a slightly altered version with '{', '}', and '~' characters added.

Thanks to Kaedenn for creating the initial documentation using this script he made.