Skip to content

dear imgui

Dear Imgui is an immediate mode gui framework written in c++. This is a cheasheet like blog post containing commonly used components.

Creating a imgui window.

Creating a Window
const char *label = "App";
ImGui::Begin(label);
ImGui::End();

imgui renders top - bottom, left - right by default

Making the Window Static

constexpr static auto window_flags = ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse;
const char *label = "App";
ImGui::Begin(label, nullptr, window_flags);
ImGui::End();

To Display Text

ImGui::Text("Hello world");

Rendering Content in the Same Line can be done by calling the ImGui::SameLine().

Drawing a Line Separator

ImGui::Separator(); # creates a horizontal line separator

Button Click

if (ImGui::Button("Back")) { 
`   // Action on button click.

Creating a Popup

ImGui::OpenPopUp("Create"); 

To make a label hidden use ### before the label

To set a window position

ImGui::SetNextWindowPos(ImVec2(width here, height here));

To set a window size

ImGui::SetNextWindowSize(ImVec2(width here, height here));

To have a text input with multiple lines, we'll use TextInputMultiline

To Create a Child window inside a Imgui Window

ImGui::BeginChild("LineNumbers") 
// child window code here
ImGui::EndChild();

Creating an imgui window

ImGui::Begin();
ImGui::End(); # every begin call should be accompanied with an end call.

Taking Single Line UserInput

const char buffer[16] = {"\0"};
ImGui::InputText("###sort, buffer, size(buffer));

Creating a PopUp

ImGui::OpenPopUp("Delete");
ImGui::BeginPopUpModal("Delete");
ImGui::EndPopup():

Setting the cursor ( Implies where we want to start drawing )

ImGui::SetCursorPosY(ImGui::GetWindowHeight() - 100.0F);

Adding a style component to an element

ImGui::PushStyleVar('style item here');
ImGui::PopStyleVar();

Plotting a graph with ImPlot

ImPlot::BeginPlot("###label", ImVec2(-1.0F, -1.0F));
ImPlot::PlotLine("label", x_axis_data, y_axis_data);
ImPlot::EndPlot();

Placing a Modal in the Center of the main Window.

const static auto flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar;