imgui_kit: small, standalone additions to Dear ImGui: em units, a fill row, aligned groups, columns, a label column, a flow, a help marker, icon buttons, a segmented switch.
The C++ API of imgui_kit: the signatures and the documentation of its headers. This page is generated by litgen, the engine behind the Python bindings of Dear ImGui Bundle. Functions without Python bindings are not listed.
imgui_kit.h¶
Demo¶
ImGuiKit::ShowDemoWindow¶
IMGUI_API void ShowDemoWindow(bool* p_open = nullptr);The kit’s demo window, as ImGui::ShowDemoWindow(). Removed by IMGUI_KIT_DISABLE_DEMO.
ImGuiKit::ShowDemoContents¶
IMGUI_API void ShowDemoContents();The demo’s content, in the current window (a host that places the window itself)
Em units¶
ImGuiKit::EmSize¶
IMGUI_API float EmSize();IMGUI_API float EmSize(float nb_lines);The current font size, in pixels
Sizes in multiples of the current font size, as the em unit of CSS: they follow the font, so they stay right on high-DPI screens and when the user zooms the text.
ImGuiKit::EmToVec2¶
IMGUI_API ImVec2 EmToVec2(float x, float y);IMGUI_API ImVec2 EmToVec2(ImVec2 v);A size or a position in em, in pixels
ImGuiKit::PixelsToEm¶
IMGUI_API ImVec2 PixelsToEm(ImVec2 pixels);Pixels, in em
ImGuiKit::PixelSizeToEm¶
IMGUI_API float PixelSizeToEm(float pixel_size);Layout¶
ImGuiKit::BeginFillRow¶
IMGUI_API float BeginFillRow(const char* str_id);Sets the next item’s width, and returns it
Dear ImGui sizes an item when it is called, before the items that follow it exist. The helpers below measure what they need on the previous frame (kept in the window’s state storage), so a row can know the width of its end, or a group its own width, before drawing them. The first frame draws them hidden while they are measured.
Fill row: the next item takes the line’s width, minus the items after FillRowTail().
| [====== slider, it fills the line ======] [>] (i) |
^ the fill item ^ the tail, on the right
Every widget that takes its width from SetNextItemWidth() fills the line this way: sliders, drags, InputText,
Combo, ColorEdit... A widget that takes a size argument instead (a plot, a child window) gets the width that
BeginFillRow() returns. Without a fill row, the room for the tail must be computed by hand, and an error of a
few pixels gives the window a horizontal scrollbar.
ImGuiKit::FillRowTail¶
IMGUI_API void FillRowTail();ImGuiKit::EndFillRow¶
IMGUI_API void EndFillRow();ImGuiKit::BeginAlignedGroup¶
IMGUI_API void BeginAlignedGroup(const char* str_id, float align_x);Aligned group: a group placed on the line from its width on the previous frame.
align_x: 0.0 = left, 0.5 = centered, 1.0 = right. It aligns the group’s box, not each line inside it.
Inside a column (below), it aligns within the column’s width instead of the line’s.
| [Cancel] [Apply] | <- BeginAlignedGroup("buttons", 1.0)ImGuiKit::EndAlignedGroup¶
IMGUI_API void EndAlignedGroup();ImGuiKit::BeginColumn¶
IMGUI_API void BeginColumn(const char* str_id);Column: a group that knows its width (from the previous frame), so that aligned groups inside it align within it.
Items under a knob, centered under it:
ImGuiKit::BeginColumn("clahe");
ImGuiKnobs::Knob("CLAHE", &clip, 1.0, 6.0);
ImGuiKit::BeginAlignedGroup("help", 0.5); // centered under the knob
ImGuiKit::HelpMarker("Contrast-limited adaptive histogram equalization...");
ImGuiKit::EndAlignedGroup();
ImGuiKit::EndColumn();
ImGui::SameLine(); // the next columnImGuiKit::EndColumn¶
IMGUI_API void EndColumn();ImGuiKit::BeginLabelColumn¶
IMGUI_API void BeginLabelColumn(const char* str_id, float labels_align_x = 0.0f);Label column: labels on the left, and the widgets after them aligned, at the widest label (of the previous frame).
Label() starts a row; the rest of the row is a normal line.
labels_align_x: 0.0 = left-aligned labels, 1.0 = right-aligned (as the x of the style’s ButtonTextAlign).
Volume [=======o========]
Output [x] Muted [Test sound]
ImGuiKit::BeginLabelColumn("audio");
ImGuiKit::Label("Volume");
ImGui::SliderFloat("##volume", &volume, 0.0, 1.0);
ImGuiKit::Label("Output");
ImGui::Checkbox("Muted", &muted);
ImGui::SameLine();
ImGui::Button("Test sound");
ImGuiKit::EndLabelColumn();ImGuiKit::Label¶
IMGUI_API void Label(const char* text);ImGuiKit::EndLabelColumn¶
IMGUI_API void EndLabelColumn();ImGuiKit::BeginGroupPanel¶
IMGUI_API void BeginGroupPanel(const char* label, const ImVec2& size = ImVec2(0, 0));Group panel: a group in a frame, its label set in the frame’s top border (as an HTML fieldset). The look of
thedmd’s group panel: ocornut/imgui#1496
size: (0, 0) = the content’s size; else at least that size.
+- Image info ----------+
| Size: 640 x 480 |
+-----------------------+
ImGuiKit::EndGroupPanel¶
IMGUI_API void EndGroupPanel();ImGuiKit::BeginFlow¶
IMGUI_API void BeginFlow(const char* str_id);Flow: items on the same line while they fit, then on the next one, as words in a paragraph.
Call FlowNext() before each item (the first one too). An item wider than the line takes a line of its own.
| [Coral] [Lavender] [Mint] |
| [Sunflower yellow] [Sky] |
ImGuiKit::BeginFlow("presets");for (int i = 0; i < count; i++) {
ImGuiKit::FlowNext(); if (ImGui::Button(labels[i])) ... }
ImGuiKit::EndFlow();ImGuiKit::FlowNext¶
IMGUI_API void FlowNext();ImGuiKit::EndFlow¶
IMGUI_API void EndFlow();Widgets¶
ImGuiKit::HelpMarker¶
IMGUI_API void HelpMarker(const char* text, float width_em = 0.0f);Help marker: a small drawn (i). It shows its text:
- with a mouse: in a tooltip while hovered; a click pins it in a popup, until a click elsewhere or Escape;
- on a touch screen (which has no hover): in a popup, opened by a tap.
width_em: the window’s width, in em (a parameter named _em is in em; the kit’s other sizes are in pixels, as
Dear ImGui’s); 0 = the text’s width on one line, up to 35 em (Dear ImGui’s tooltips do not wrap; its demo wraps
its help at 35 em). Never wider than the screen. The height: at most 60% of the screen; a
longer text scrolls in the popup, and the tooltip says to click to read it all.
The text: ’
’ starts a line with the default renderer; with a Markdown renderer, Markdown’s rules apply (a
single ’
’ joins the lines of a paragraph, an empty line separates paragraphs).
It goes to the next line when the current one has no room for it. Its ID is its text: two markers with the
same text in the same ID scope share their popup (use PushID() or BeginHelpMarker() to tell them apart).
ImGuiKit::BeginHelpMarker¶
IMGUI_API bool BeginHelpMarker(const char* str_id, float width_em = 0.0f);The same, with any content: draw it between the two calls when BeginHelpMarker() returns True. width_em: 0 = the content sizes the window (its text wraps at 35 em); give a width for a content that wraps to its window (Markdown).
if (ImGuiKit::BeginHelpMarker("##level_help")) { ImGui::Text("..."); ImGuiKit::EndHelpMarker(); }ImGuiKit::EndHelpMarker¶
IMGUI_API void EndHelpMarker();ImGuiKit::HelpMarkerWidth¶
IMGUI_API float HelpMarkerWidth();The width a help marker takes at the end of a line, with the spacing before it
ImGuiKit::IconButton¶
IMGUI_API bool IconButton(const char* str_id, ImGuiKitIcon icon, const ImVec2& size = ImVec2(0, 0));Icon button: a button with a symbol drawn with the draw list, centered (a font’s glyph often sits a little high in a button), in the text’s color. size: (0, 0) = a square of the frame’s height.
ImGuiKit::SegmentedSwitch¶
IMGUI_API bool SegmentedSwitch(const char* str_id, int* current, const char* const labels[], int labels_count);Segmented switch: exclusive choices in one frame, the current one filled. Its corners follow the style’s
FrameRounding, as buttons and sliders do.
( Demo | Code ) <- current = 1: "Code" is filledIt reacts at the press, not the release, which suits touch screens. Returns True when *current changed.
ImGuiKit::FitText¶
IMGUI_API const char* FitText(const char* text, float wrap_width, int max_lines);Fit text: the text, cut at a word and ended with an ellipsis, so that it takes at most max_lines once wrapped at wrap_width (in the current font). Returns the text itself when it fits; else a buffer of the kit, valid until the next call (copy it to keep two results).
ImGui::PushTextWrapPos(ImGui::GetCursorPosX() + width);
ImGui::TextUnformatted(ImGuiKit::FitText(summary, width, 2)); // two lines at most, then "..."
ImGui::PopTextWrapPos();ImGuiKitIcon_ (enum)¶
enum ImGuiKitIcon_The symbols of IconButton()
| Member | Value | |
|---|---|---|
ImGuiKitIcon_Minus | 0 | |
ImGuiKitIcon_Plus | 1 | |
ImGuiKitIcon_ZoomIn | 2 | |
ImGuiKitIcon_ZoomOut | 3 | |
ImGuiKitIcon_ZoomOneToOne | 4 | |
ImGuiKitIcon_ZoomFit, } | 5 |