A Dear ImGui settings menu in C# and Rust
Dear ImGui isn't only for C++. Here is the same small settings window — two checkboxes, a volume slider and an Apply button — in C# with ImGui.NET and in Rust with imgui-rs.
C# with ImGui.NET
ImGui.NET mirrors the C++ API closely; values you change are passed with ref. Run this between ImGui.NewFrame() and ImGui.Render(), with whichever renderer you use (for example Silk.NET).
C#
using System.Numerics;
using ImGuiNET;
bool vsync = true;
bool fullscreen = false;
float volume = 50f;
void SettingsWindow()
{
ImGui.SetNextWindowSize(new Vector2(380, 0), ImGuiCond.FirstUseEver);
ImGui.Begin("Game Settings");
ImGui.Checkbox("V-Sync", ref vsync);
ImGui.Checkbox("Fullscreen", ref fullscreen);
ImGui.SliderFloat("Volume", ref volume, 0f, 100f, "%.0f");
if (ImGui.Button("Apply", new Vector2(-1, 0)))
{
ApplySettings(vsync, fullscreen, volume);
}
ImGui.End();
}Rust with imgui-rs
imgui-rs uses a builder for windows and a closure for their contents; widgets take &mut values.
Rust
use imgui::{Condition, Ui};
struct Settings {
vsync: bool,
fullscreen: bool,
volume: f32,
}
fn settings_window(ui: &Ui, s: &mut Settings) {
ui.window("Game Settings")
.size([380.0, 0.0], Condition::FirstUseEver)
.build(|| {
ui.checkbox("V-Sync", &mut s.vsync);
ui.checkbox("Fullscreen", &mut s.fullscreen);
ui.slider("Volume", 0.0, 100.0, &mut s.volume);
if ui.button_with_size("Apply", [-1.0, 0.0]) {
apply_settings(s);
}
});
}What differs from C++
- State lives in your variables or struct, passed by
ref(C#) or&mut(Rust) — the same idea as pointers in C++. - Sizes are
Vector2in C# and[f32; 2]arrays in Rust instead ofImVec2. - Begin / End become a builder with a closure in Rust, so you can't forget
End().
Kavro designs the window once and generates it for C++ (Dear ImGui + DirectX 11), C# (ImGui.NET + Silk.NET on .NET 8) or Rust (imgui-rs + glium) — with the project files to build it.
More guides
Dear ImGui login window example (C++)A complete Dear ImGui login window in C++: centered window, username and password fields, remember me, a full-width button and an error message. Copy the code or build it visually.A custom Dear ImGui dark theme (code you can paste)Make Dear ImGui look modern: a complete dark theme with rounded corners, padding and hex colors for ImGuiStyle. Paste the function and call it once after creating the context.ImGui toggle switch and rounded buttonsHow to make an iOS-style toggle switch and rounded, colored buttons in Dear ImGui with ImDrawList and style pushes. Short C++ functions you can copy.