C++11 syntactic sugar for ImGui with RAII guards

Overview

C++11 syntactic sugar for ImGui with RAII guards

This single header library adds a clean DSL (syntax sugar) to construct ImGui interfaces in c++11. It manages the stack with transparent RAII guards.

Requirements

Install

Just add imgui_sugar.hpp to your sources and include it when required.

Example usage

#include <imgui/imgui.h>
#include <imgui_sugar.hpp>

// ...

    static int left = 0, right = 0;
    ImGui::SetNextWindowPos(ImVec2(30, 50), ImGuiCond_FirstUseEver);
    set_StyleColor(ImGuiCol_WindowBg, ImVec4{0.88f, 0.88f, 0.88f, 1.0f});        
    set_StyleColor(ImGuiCol_Text, 0xff000000);

    with_Window("Test Window", nullptr, ImGuiWindowFlags_AlwaysAutoResize) {

        ImGui::Text("Hello");
        
        with_Group {
            ImGui::Text("Left %d", left);
            if (ImGui::Button("Incr Left"))
                ++left;
        }
        
        ImGui::SameLine();
        
        with_Group {
            set_StyleColor(ImGuiCol_Text, 0xffff0000);
        
            ImGui::Text("Right %d", right);
        
            if (ImGui::Button("Incr Right"))
                ++right;
        
            with_Child("##scrolling", ImVec2(200, 80)) {

                ImGui::Text("More text ...");
                ImGui::Text("More text ...");
                ImGui::Text("More text ...");
                
                with_StyleColor(ImGuiCol_Text, ImVec4{ 0, 0.5f, 0, 1.0f })
                    ImGui::Text("More text ...");
                
                ImGui::Text("More text ...");
                
                with_StyleColor(ImGuiCol_Text, ImVec4{ 0.5f, 0.0f, 0, 1.0f }) {
                    ImGui::Text("More text ...");
                    ImGui::Text("More text ...");
                }
            }
        }

        ImGui::Text("Bye...");
    }    


// ...

screenshot.png

Rational

  • Macros named with_* do start its own scope and automatically call End/Pop as required. (Yes the case where End/Pop call is unconditionall is respected).
with_Window(...) { 
    // ....
}

// If the scope contains a single statement, brackets are optional as usual.
with_StyleColor(ImGuiCol_Text, ImVec4{ 0, 0.5f, 0, 1.0f })
    ImGui::Text("More text ...");
  • Macros named set_* do not start its own scope but its state is managed by the surrounding scope.
{
    set_StyleColor(...);
    // ...
}

Scope definitions

Sugar function Begin Call End Call
with_Window(...) { ... } ImGui::Begin, ImGui::End
with_Child(...) { ... } ImGui::BeginChild, ImGui::EndChild
with_ChildFrame(...) { ... } ImGui::BeginChildFrame, ImGui::EndChildFrame
with_Combo(...) { ... } ImGui::BeginCombo, ImGui::EndCombo
with_ListBox(...) { ... } ImGui::BeginListBox, ImGui::EndListBox
with_MenuBar(...) { ... } ImGui::BeginMenuBar, ImGui::EndMenuBar
with_MainMenuBar(...) { ... } ImGui::BeginMainMenuBar, ImGui::EndMainMenuBar
with_Menu(...) { ... } ImGui::BeginMenu, ImGui::EndMenu
with_Popup(...) { ... } ImGui::BeginPopup, ImGui::EndPopup
with_PopupModal(...) { ... } ImGui::BeginPopupModal, ImGui::EndPopup
with_PopupContextItem(...) { ... } ImGui::BeginPopupContextItem, ImGui::EndPopup
with_PopupContextWindow(...) { ... } ImGui::BeginPopupContextWindow, ImGui::EndPopup
with_PopupContextVoid(...) { ... } ImGui::BeginPopupContextVoid, ImGui::EndPopup
with_Table(...) { ... } ImGui::BeginTable, ImGui::EndTable
with_TabBar(...) { ... } ImGui::BeginTabBar, ImGui::EndTabBar
with_TabItem(...) { ... } ImGui::BeginTabItem, ImGui::EndTabItem
with_DragDropSource(...) { ... } ImGui::BeginDragDropSource, ImGui::EndDragDropSource
with_DragDropTarget(...) { ... } ImGui::BeginDragDropTarget, ImGui::EndDragDropTarget
with_Group { ... } ImGui::BeginGroup, ImGui::EndGroup
with_Tooltip { ... } ImGui::BeginTooltip, ImGui::EndTooltip
with_Font(...) { ... } ImGui::PushFont, ImGui::PopFont
with_AllowKeyboardFocus(...) { ... } ImGui::PushAllowKeyboardFocus, ImGui::PopAllowKeyboardFocus
with_ButtonRepeat(...) { ... } ImGui::PushButtonRepeat, ImGui::PopButtonRepeat
with_ItemWidth(...) { ... } ImGui::PushItemWidth, ImGui::PopItemWidth
with_TextWrapPos(...) { ... } ImGui::PushTextWrapPos, ImGui::PopTextWrapPos
with_ID(...) { ... } ImGui::PushID, ImGui::PopID
with_ClipRect(...) { ... } ImGui::PushClipRect, ImGui::PopClipRect
with_TextureID(...) { ... } ImGui::PushTextureID, ImGui::PopTextureID
with_StyleColor(...) { ... } ImGui::PushStyleColor, ImGui::PopStyleColor
with_StyleVar(...) { ... } ImGui::PushStyleVar, ImGui::PopStyleVar
with_TreeNode(...) { ... } ImGui::TreeNode ImGui::TreePop
with_TreeNodeV(...) { ... } ImGui::TreeNodeV ImGui::TreePop
with_TreeNodeEx(...) { ... } ImGui::TreeNodeEx ImGui::TreePop
with_TreeNodeExV(...) { ... } ImGui::TreeNodeExV ImGui::TreePop
with_CollapsingHeader(...) { ... } ImGui::CollapsingHeader

Parent scoped guards

Sugar function Begin Call End Call
set_StyleColor(...) ImGui::PushStyleColor, ImGui::PopStyleColor
set_StyleVar(...) ImGui::PushStyleVar, ImGui::PopStyleVar

Abstraction cost

  • All guards do store a function pointer to the end callback and a boolean member with the returned value from begin callback.
  • No heap allocations are done at all.

Disclaimers

  • No guarantees.
  • This is very opinionated.
  • This uses templates and macros.
  • This is not a proposal, just something that you can use if you like it.

Contributions

Discussions and PRs are welcome :)

You might also like...
A small, dependency-free node editor extension for dear imgui.
A small, dependency-free node editor extension for dear imgui.

imnodes A small, dependency-free node editor extension for dear imgui. Features: Create nodes, links, and pins in an immediate-mode style Single heade

Tab module for imgui. Should be relatively forwardly compatible.
Tab module for imgui. Should be relatively forwardly compatible.

Tab module for imgui. Should be relatively forwardly compatible.

This is a imgui login that runs with keyauth with only uses the key and has tabs for you to paste your stuff in c++

KeyAuth-Imgui-key-Login This is a imgui login that runs with keyauth with only uses the key and has tabs for you to paste your stuff in c++ KeyAuth CP

A convenience C++ wrapper library for JSON-Glib providing friendly syntactic sugar for parsing JSON

This library is a wrapper for the json-glib library that aims to provide the user with a trivial alternative API to the API provided by the base json-

🔌 A C++ RAII Pipewire-API Wrapper

A C++ RAII PipeWire-API Wrapper Description Rohrkabel is a RAII wrapper around the pipewire-api that aims to simplify work with it, at the moment Rohr

o/ ImGui Builder is a graphical framework for assembling imgui codes in your interface easily
o/ ImGui Builder is a graphical framework for assembling imgui codes in your interface easily

IMGUI BUILDER The project consists a gui editor of the Imgui framework EDITOR Menu Export 1 - Export cpp file 2 - Cpp file Credits Credits for Shadowy

api & source menu base import imgui from imgui-js
api & source menu base import imgui from imgui-js

onetap v4 crack https://discord.gg/AXCtxVH4PB people asking me for otv4 source "bin2h" (meaning binary to hex) large hexadecimal array deleted all the

Simple ImGui external base. Uses ImGui DX9.
Simple ImGui external base. Uses ImGui DX9.

ImGui External Base 🖥️ What is this? ⚡ Hello all! I used to use noteffex's loader base for all my external ImGui projects. I got bored of using this

Dear ImGui Addons Branch = plain unmodified dear imgui plus some extra addon.
Dear ImGui Addons Branch = plain unmodified dear imgui plus some extra addon.

Dear ImGui (This library is available under a free and permissive license, but needs financial support to sustain its continued improvements. In addit

imgui-filebrowser is a header-only file browser implementation for dear-imgui. C++ 17 is required.
imgui-filebrowser is a header-only file browser implementation for dear-imgui. C++ 17 is required.

imgui-filebrowser imgui-filebrowser is a header-only file browser implementation for dear-imgui. C++ 17 is required. Getting Started imfilebrowser.h s

An addon of imgui for supporting docks in the imgui's window
An addon of imgui for supporting docks in the imgui's window

An addon of imgui for support dock in the window

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies

Dear ImGui (This library is available under a free and permissive license, but needs financial support to sustain its continued improvements. In addit

Advanced 2D Plotting for Dear ImGui
Advanced 2D Plotting for Dear ImGui

ImPlot ImPlot is an immediate mode, GPU accelerated plotting library for Dear ImGui. It aims to provide a first-class API that ImGui fans will love. I

Simpler ImGui Backend Implementation for VulkanHpp.
Simpler ImGui Backend Implementation for VulkanHpp.

ImGui-VulkanHpp Simpler ImGui Backend Implementation for VulkanHpp.

Dear IMGUI + Render + Window handling, amalgamation in two files ready to use
Dear IMGUI + Render + Window handling, amalgamation in two files ready to use

imgui-app Imgui-app is an amalgamation of two amazing projects Dear Imgui and Sokol libraries into two files to make it very easy to start working wit

A file dialog library for Dear ImGui
A file dialog library for Dear ImGui

ImFileDialog A simple file dialog library for Dear ImGui. This library supports favorites, actual Windows icons, image previews, zooming in, etc... DI

dear imgui + glfw framework
dear imgui + glfw framework

ImFrame ImFrame is a lightweight framework designed to provide you with a window and graphical backend for the Dear ImGui library. Unlike more traditi

Markdown renderer for Dear ImGui using MD4C parser
Markdown renderer for Dear ImGui using MD4C parser

imgui_md Markdown renderer for Dear ImGui using MD4C parser. C++11 or above imgui_md currently supports the following markdown functionality: Wrapped

A cross-platform wrapper for using SDL2 with ImGui

ImSDL2 ImSDL2 is an open source "wrapper" of imgui backends available for SDL2. It aims to provide a backend-independent yet simple interface for inte

Releases(v1.0.5)
Owner
Frank David Martínez M
Frank David Martínez M
Dear ImGui Addons Branch = plain unmodified dear imgui plus some extra addon.

Dear ImGui (This library is available under a free and permissive license, but needs financial support to sustain its continued improvements. In addit

Flix 351 Nov 24, 2022
Portal 2/Portal Reloaded internal cheat sdk with imgui-based menu

portal2-internal A simple Portal 2/Portal Reloaded internal cheat base with imgui-based menu coded in a few days because why not Features: simple menu

es3n1n 34 Nov 30, 2022
Minimal-ish implementation of Unreal Online Subsystem + ImGui UI

Minimal-ish implementation of Unreal Online Subsystem + ImGui UI

Brace Yourself Games 4 Mar 14, 2022
Sea of Thieves - Advanced ESP /w ImGui for XBox Version (Steam has to be written)

??‍☠️ Sea of Thieves - External Tool Premium Sea of Thieves - Advanced ESP /w ImGui for XBox Version (Steam has to be written) How to: Check latest ga

Kamil 12 Sep 21, 2022
CHIP-8 Emulator/Debugger made with C++ 17, OpenGL & ImGui.

Description (Some frames were deleted to make the GIF smaller) CHIP-8 interpreter/debugger made with C++ 17. SDL 2.0.16 for window creation, event han

Alexsander Bispo 6 Jan 7, 2022
MTEngineSDL is a SDL2+ImGui engine for macOS, Linux and MS Windows.

Hello and welcome to the MTEngineSDL! This is an application host framework for starting custom apps created using SDL2, ImGui and OpenGL. How to comp

null 3 Jan 10, 2022
A drop-in entity editor for EnTT with Dear ImGui

imgui_entt_entity_editor A drop-in, single-file entity editor for EnTT, with ImGui as graphical backend. demo-code (live) Editor Editor with Entiy-Lis

Erik Scholz 146 Nov 19, 2022
imGuIZMO.quat is a ImGui widget: like a trackball it provides a way to rotate models, lights, or objects with mouse, and graphically visualize their position in space, also around any single axis (Shift/Ctrl/Alt/Super)

imGuIZMO.quat v3.0 imGuIZMO.quat is a ImGui widget: like a trackball it provides a way to rotate models, lights, or objects with mouse, and graphicall

Michele Morrone 273 Dec 2, 2022
A single-file, immediate-mode sequencer widget for C++17, Dear ImGui and EnTT

A single-file, immediate-mode sequencer widget for C++17, Dear ImGui and EnTT Table of Contents Overview Features Design Decisions Todo Open Questions

Alan Jefferson 191 Nov 24, 2022
An improved plot widget for Dear ImGui, aimed at displaying audio data

imgui-plot An improved plot widget for Dear ImGui, aimed at displaying audio data TOC Screenshots Rationale Usage Installation FAQ Screenshots Display

Anton Lobashev 396 Nov 19, 2022