The library started its life and is best known as "ImGui" only due to the fact that I didn't give it a proper name when I released it. However, the term IMGUI (immediate-mode graphical user interface) was coined before and is being used in variety of other situations. It seemed confusing and unfair to hog the name. To reduce the ambiguity without affecting existing codebases, I have decided on an alternate, longer name "dear imgui" that people can use to refer to this specific library in ambiguous situations.
<b>How do I update to a newer version of ImGui?</b>
<br><b>Can I have multiple widgets with the same label? Can I have widget without a label? (Yes)</b>
<br><b>What is ImTextureID and how do I display an image?</b>
<br><b>I integrated ImGui in my engine and the text or lines are blurry..</b>
<br><b>I integrated ImGui in my engine and some elements are disappearing when I move windows around..</b>
<br><b>How can I have multiple widgets with the same label? Can I have widget without a label? (Yes). A primer on the purpose of labels/IDs.</b>
<br><b>How can I tell when ImGui wants my mouse/keyboard inputs and when I can pass them to my application?</b>
<br><b>How can I load a different font than the default?</b>
<br><b>How can I load multiple fonts?</b>
<br><b>How can I display and input non-latin characters such as Chinese, Japanese, Korean, Cyrillic?</b>
<br><b>How can I use the drawing facilities without an ImGui window? (using ImDrawList API)</b>
// By using D3DCompile() from <d3dcompiler.h> / d3dcompiler.lib, we introduce a dependency to a given version of d3dcompiler_XX.dll (see D3DCOMPILER_DLL_A)
// If you would like to use this DX11 sample code but remove this dependency you can:
// 1) compile once, save the compiled shader blobs into a file or source code and pass them to CreateVertexShader()/CreatePixelShader() [prefered solution]
// 2) use code to detect any version of the DLL and grab a pointer to D3DCompile from the DLL.
// See https://github.com/ocornut/imgui/pull/638 for sources and details.
// By using D3DCompile() from <d3dcompiler.h> / d3dcompiler.lib, we introduce a dependency to a given version of d3dcompiler_XX.dll (see D3DCOMPILER_DLL_A)
// If you would like to use this DX11 sample code but remove this dependency you can:
// 1) compile once, save the compiled shader blobs into a file or source code and pass them to CreateVertexShader()/CreatePixelShader() [prefered solution]
// 2) use code to detect any version of the DLL and grab a pointer to D3DCompile from the DLL.
// See https://github.com/ocornut/imgui/pull/638 for sources and details.
// Being agnostic of whether <d3dx9.h> or <DirectXMath.h> can be used, we aren't relying on D3DXMatrixIdentity()/D3DXMatrixOrthoOffCenterLH() or DirectX::XMMatrixIdentity()/DirectX::XMMatrixOrthographicOffCenterLH()
The code in imgui.cpp embeds a copy of 'ProggyClean.ttf' that you can use without any external files.
Those are only provided as a convenience, you can load your own .TTF files.
The files in this folder are only provided as a convenience, you can use any of your own .TTF files.
Fonts are rasterized in a single texture at the time of calling either of io.Fonts.GetTexDataAsAlpha8()/GetTexDataAsRGBA32()/Build().
If you want to use icons in ImGui, a good idea is to merge an icon font within your main font, and refer to icons directly in your strings.
You can use headers files with definitions for popular icon fonts codepoints, by Juliette Foucaut, at https://github.com/juliettef/IconFontCppHeaders
---------------------------------
LOADING INSTRUCTIONS
---------------------------------
@ -35,10 +39,10 @@
Combine two fonts into one:
// Load main font
// Load a first font
io.Fonts->AddFontDefault();
// Add character ranges and merge into main font
// Add character ranges and merge into the previous font
// The ranges array is not copied by the AddFont* functions and is used lazily
// so ensure it is available for duration of font usage
static const ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 }; // will not be copied by AddFont* so keep in scope.
@ -63,6 +67,16 @@
ImFont* font = io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels);
font->DisplayOffset.y += 1; // Render 1 pixel down
---------------------------------
REMAP CODEPOINTS
---------------------------------
All your strings needs to use UTF-8 encoding. Specifying literal in your source code using a local code page (such as CP-923 for Japanese CP-1251 for Cyrillic) will not work.
In C++11 you can encode a string literal in UTF-8 by using the u8"hello" syntax. Otherwise you can convert yourself to UTF-8 or load text data from file already saved as UTF-8.
You can also try to remap your local codepage characters to their Unicode codepoint using font->AddRemapChar(), but international users may have problems reading/editing your source code.
---------------------------------
EMBED A FONT IN SOURCE CODE
---------------------------------
@ -75,8 +89,9 @@
ImFont* font = io.Fonts->AddFontFromMemoryCompressedBase85TTF(compressed_data_base85, size_pixels, ...);
structImGuiStyle;// Runtime data for styling/colors
structImGuiTextFilter;// Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
structImGuiTextBuffer;// Text buffer for logging/accumulating text
structImGuiTextEditCallbackData;// Shared state of ImGui::InputText() when using custom callbacks (advanced)
structImGuiTextEditCallbackData;// Shared state of ImGui::InputText() when using custom ImGuiTextEditCallback (rare/advanced use)
structImGuiSizeConstraintCallbackData;// Structure used to constraint window size in custom ways when using custom ImGuiSizeConstraintCallback (rare/advanced use)
structImGuiListClipper;// Helper to manually clip large list of items
structImGuiContext;// ImGui context (opaque)
// Enumerations (declared as int for compatibility and to not pollute the top of this file)
typedefunsignedintImU32;
@ -70,7 +72,9 @@ typedef int ImGuiWindowFlags; // window flags for Begin*() // e
typedefintImGuiSetCond;// condition flags for Set*() // enum ImGuiSetCond_
typedefintImGuiInputTextFlags;// flags for InputText*() // enum ImGuiInputTextFlags_
typedefintImGuiSelectableFlags;// flags for Selectable() // enum ImGuiSelectableFlags_
typedefintImGuiTreeNodeFlags;// flags for TreeNode*(), Collapsing*() // enum ImGuiTreeNodeFlags_
IMGUI_APIvoidShowTestWindow(bool* opened=NULL);// test window demonstrating ImGui features
IMGUI_APIvoidShowMetricsWindow(bool* opened=NULL);// metrics window for debugging ImGui
IMGUI_APIvoidShowStyleEditor(ImGuiStyle*ref=NULL);// style editor block. you can pass in a reference ImGuiStyle structure to compare to, revert to and save to (else it uses the default style)
IMGUI_APIvoidShowTestWindow(bool*p_open =NULL);// test window demonstrating ImGui features
IMGUI_APIvoidShowMetricsWindow(bool*p_open =NULL);// metrics window for debugging ImGui
// Window
IMGUI_APIboolBegin(constchar*name,bool*p_opened=NULL,ImGuiWindowFlagsflags=0);// push window to the stack and start appending to it. see .cpp for details. return false when window is collapsed, so you can early out in your code. 'bool* p_opened' creates a widget on the upper-right to close the window (which sets your bool to false).
IMGUI_APIboolBegin(constchar*name,bool*p_opened,constImVec2&size_on_first_use,floatbg_alpha=-1.0f,ImGuiWindowFlagsflags=0);// OBSOLETE. this is the older/longer API. the extra parameters aren't very relevant. call SetNextWindowSize() instead if you want to set a window size. For regular windows, 'size_on_first_use' only applies to the first time EVER the window is created and probably not what you want! might obsolete this API eventually.
IMGUI_APIvoidEnd();// finish appending to current window, pop it off the window stack.
IMGUI_APIboolBeginChild(constchar*str_id,constImVec2&size=ImVec2(0,0),boolborder=false,ImGuiWindowFlagsextra_flags=0);// begin a scrolling region. size==0.0f: use remaining window size, size<0.0f: use remaining window size minus abs(size). size>0.0f: fixed size. each axis can use a different mode, e.g. ImVec2(0,400).
IMGUI_APIboolBegin(constchar*name,bool*p_open=NULL,ImGuiWindowFlagsflags=0);// push window to the stack and start appending to it. see .cpp for details. return false when window is collapsed, so you can early out in your code. 'bool* p_open' creates a widget on the upper-right to close the window (which sets your bool to false).
IMGUI_APIboolBegin(constchar*name,bool*p_open,constImVec2&size_on_first_use,floatbg_alpha=-1.0f,ImGuiWindowFlagsflags=0);// OBSOLETE. this is the older/longer API. the extra parameters aren't very relevant. call SetNextWindowSize() instead if you want to set a window size. For regular windows, 'size_on_first_use' only applies to the first time EVER the window is created and probably not what you want! might obsolete this API eventually.
IMGUI_APIvoidEnd();// finish appending to current window, pop it off the window stack.
IMGUI_APIboolBeginChild(constchar*str_id,constImVec2&size=ImVec2(0,0),boolborder=false,ImGuiWindowFlagsextra_flags=0);// begin a scrolling region. size==0.0f: use remaining window size, size<0.0f: use remaining window size minus abs(size). size>0.0f: fixed size. each axis can use a different mode, e.g. ImVec2(0,400).
IMGUI_APIImVec2GetContentRegionMax();// current content boundaries (typically window boundaries including scrolling, or current column boundaries), in windows coordinates
IMGUI_APIvoidSetNextWindowPos(constImVec2&pos,ImGuiSetCondcond=0);// set next window position. call before Begin()
IMGUI_APIvoidSetNextWindowPosCenter(ImGuiSetCondcond=0);// set next window position to be centered on screen. call before Begin()
IMGUI_APIvoidSetNextWindowSize(constImVec2&size,ImGuiSetCondcond=0);// set next window size. set axis to 0.0f to force an auto-fit on this axis. call before Begin()
IMGUI_APIvoidSetNextWindowSizeConstraints(constImVec2&size_min,constImVec2&size_max,ImGuiSizeConstraintCallbackcustom_callback=NULL,void*custom_callback_data=NULL);// set next window size limits. use -1,-1 on either X/Y axis to preserve the current size. Use callback to apply non-trivial programmatic constraints.
IMGUI_APIvoidSetNextWindowContentSize(constImVec2&size);// set next window content size (enforce the range of scrollbars). set axis to 0.0f to leave it automatic. call before Begin()
IMGUI_APIvoidSetNextWindowContentWidth(floatwidth);// set next window content width (enforce the range of horizontal scrollbar). call before Begin()
IMGUI_APIvoidSetNextWindowCollapsed(boolcollapsed,ImGuiSetCondcond=0);// set next window collapsed state. call before Begin()
IMGUI_APIvoidSetNextWindowFocus();// set next window to be focused / front-most. call before Begin()
IMGUI_APIvoidSetWindowPos(constImVec2&pos,ImGuiSetCondcond=0);// set current window position - call within Begin()/End(). may incur tearing
IMGUI_APIvoidSetWindowSize(constImVec2&size,ImGuiSetCondcond=0);// set current window size. set to ImVec2(0,0) to force an auto-fit. may incur tearing
IMGUI_APIvoidSetWindowCollapsed(boolcollapsed,ImGuiSetCondcond=0);// set current window collapsed state
IMGUI_APIvoidSetWindowFocus();// set current window to be focused / front-most
IMGUI_APIvoidSetWindowPos(constImVec2&pos,ImGuiSetCondcond=0);// (not recommended) set current window position - call within Begin()/End(). prefer using SetNextWindowPos(), as this may incur tearing and side-effects.
IMGUI_APIvoidSetWindowSize(constImVec2&size,ImGuiSetCondcond=0);// (not recommended) set current window size - call within Begin()/End(). set to ImVec2(0,0) to force an auto-fit. prefer using SetNextWindowSize(), as this may incur tearing and minor side-effects.
IMGUI_APIvoidSetWindowCollapsed(boolcollapsed,ImGuiSetCondcond=0);// (not recommended) set current window collapsed state. prefer using SetNextWindowCollapsed().
IMGUI_APIvoidSetWindowFocus();// (not recommended) set current window to be focused / front-most. prefer using SetNextWindowFocus().
IMGUI_APIvoidSetWindowPos(constchar*name,constImVec2&pos,ImGuiSetCondcond=0);// set named window position.
IMGUI_APIvoidSetWindowSize(constchar*name,constImVec2&size,ImGuiSetCondcond=0);// set named window size. set axis to 0.0f to force an auto-fit on this axis.
IMGUI_APIvoidSetWindowCollapsed(constchar*name,boolcollapsed,ImGuiSetCondcond=0);// set named window collapsed state
@ -157,7 +162,7 @@ namespace ImGui
IMGUI_APIvoidSetScrollY(floatscroll_y);// set scrolling amount [0..GetScrollMaxY()]
IMGUI_APIvoidSetScrollHere(floatcenter_y_ratio=0.5f);// adjust scrolling amount to make current cursor position visible. center_y_ratio=0.0: top, 0.5: center, 1.0: bottom.
IMGUI_APIvoidSetScrollFromPosY(floatpos_y,floatcenter_y_ratio=0.5f);// adjust scrolling amount to make given position valid. use GetCursorPos() or GetCursorStartPos()+offset to get valid positions.
IMGUI_APIvoidSetKeyboardFocusHere(intoffset=0);// focus keyboard on the next widget. Use positive 'offset' to access sub components of a multiple component widget
IMGUI_APIvoidSetKeyboardFocusHere(intoffset=0);// focus keyboard on the next widget. Use positive 'offset' to access sub components of a multiple component widget. Use negative 'offset' to access previous widgets.
IMGUI_APIvoidSetStateStorage(ImGuiStorage*tree);// replace tree state storage with our own (if you want to manipulate it yourself, typically clear subsection of it)
IMGUI_APIImGuiStorage*GetStateStorage();
@ -189,10 +194,11 @@ namespace ImGui
// Cursor / Layout
IMGUI_APIvoidSeparator();// horizontal line
IMGUI_APIvoidSameLine(floatpos_x=0.0f,floatspacing_w=-1.0f);// call between widgets or groups to layout them horizontally
IMGUI_APIvoidSpacing();// add spacing
IMGUI_APIvoidNewLine();// undo a SameLine()
IMGUI_APIvoidSpacing();// add vertical spacing
IMGUI_APIvoidDummy(constImVec2&size);// add a dummy item of given size
IMGUI_APIvoidIndent();// move content position toward the right by style.IndentSpacing pixels
IMGUI_APIvoidUnindent();// move content position back to the left (cancel Indent)
IMGUI_APIvoidIndent(floatindent_w=0.0f);// move content position toward the right, by style.IndentSpacing or indent_w if >0
IMGUI_APIvoidUnindent(floatindent_w=0.0f);// move content position back to the left, by style.IndentSpacing or indent_w if >0
IMGUI_APIvoidBeginGroup();// lock horizontal starting position + capture group bounding box into one "item" (so you can use IsItemHovered() or layout primitives such as SameLine() on whole group, etc.)
IMGUI_APIvoidEndGroup();
IMGUI_APIImVec2GetCursorPos();// cursor position is relative to window position
@ -202,7 +208,7 @@ namespace ImGui
IMGUI_APIvoidSetCursorPosX(floatx);// "
IMGUI_APIvoidSetCursorPosY(floaty);// "
IMGUI_APIImVec2GetCursorStartPos();// initial cursor position
IMGUI_APIImVec2GetCursorScreenPos();// cursor position in absolute screen coordinates [0..io.DisplaySize]
IMGUI_APIImVec2GetCursorScreenPos();// cursor position in absolute screen coordinates [0..io.DisplaySize] (useful to work with ImDrawList API)
IMGUI_APIvoidSetCursorScreenPos(constImVec2&pos);// cursor position in absolute screen coordinates [0..io.DisplaySize]
IMGUI_APIvoidAlignFirstTextHeightToWidgets();// call once if the first item on the line is a Text() item and you want to vertically lower it to match subsequent (bigger) widgets
IMGUI_APIfloatGetTextLineHeight();// height of font == GetWindowFontSize()
@ -210,7 +216,7 @@ namespace ImGui
IMGUI_APIfloatGetItemsLineHeightWithSpacing();// distance (in pixels) between 2 consecutive lines of standard height widgets == GetWindowFontSize() + GetStyle().FramePadding.y*2 + GetStyle().ItemSpacing.y
// Columns
// You can also use SameLine(pos_x) for simplified columning. The columns API is still work-in-progress.
// You can also use SameLine(pos_x) for simplified columning. The columns API is still work-in-progress and rather lacking.
IMGUI_APIvoidColumns(intcount=1,constchar*id=NULL,boolborder=true);// setup number of columns. use an identifier to distinguish multiple column sets. close with Columns(1).
IMGUI_APIvoidNextColumn();// next column
IMGUI_APIintGetColumnIndex();// get current column index
@ -243,15 +249,14 @@ namespace ImGui
IMGUI_APIvoidTextUnformatted(constchar*text,constchar*text_end=NULL);// doesn't require null terminated string if 'text_end' is specified. no copy done to any bounded stack buffer, recommended for long chunks of text
IMGUI_APIvoidLabelText(constchar*label,constchar*fmt,...)IM_PRINTFARGS(2);// display text+label aligned the same way as value+label widgets
IMGUI_APIvoidBullet();// draw a small circle and keep the cursor on the same line. advance cursor x position by GetTreeNodeToLabelSpacing(), same distance that TreeNode() uses
IMGUI_APIvoidBulletText(constchar*fmt,...)IM_PRINTFARGS(1);// shortcut for Bullet()+Text()
IMGUI_APIboolCombo(constchar*label,int*current_item,constchar*items_separated_by_zeros,intheight_in_items=-1);// separate items with \0, end item-list with \0\0
IMGUI_APIboolColorEdit3(constchar*label,floatcol[3],ImGuiColorEditFlagsflags=0);// click on colored squared to open a color picker, right-click for options
IMGUI_APIboolColorEdit3(constchar*label,floatcol[3],ImGuiColorEditFlagsflags=0);// click on colored squared to open a color picker, right-click for options. Hint: 'float col[3]' function argument is same as 'float* col'. You can pass address of first element out of a contiguous set, e.g. &myvector.x
IMGUI_APIboolColorEdit4(constchar*label,floatcol[4],ImGuiColorEditFlagsflags=0x01);// 0x01 = ImGuiColorEditFlags_Alpha = very dodgily backward compatible with 'bool show_alpha=true'
// Widgets: Drags (tip: ctrl+click on a drag box to input with keyboard. manually input values aren't clamped, can go off-bounds)
// For all the Float2/Float3/Float4/Int2/Int3/Int4 versions of every functions, remember than a 'float v[3]' function argument is the same as 'float* v'. You can pass address of your first element out of a contiguous set, e.g. &myvector.x
IMGUI_APIboolDragFloat(constchar*label,float*v,floatv_speed=1.0f,floatv_min=0.0f,floatv_max=0.0f,constchar*display_format="%.3f",floatpower=1.0f);// If v_min >= v_max we have no bound
IMGUI_APIboolTreeNode(constchar*str_label_id);// if returning 'true' the node is open and the user is responsible for calling TreePop().
IMGUI_APIboolTreeNode(constchar* label);// if returning 'true' the node is open and the tree id is pushed into the id stack. user is responsible for calling TreePop().
IMGUI_APIboolTreeNode(constchar*str_id,constchar*fmt,...)IM_PRINTFARGS(2);// read the FAQ about why and how to use ID. to align arbitrary text at the same level as a TreeNode() you can use Bullet().
IMGUI_APIvoidTreePush(constchar*str_id=NULL);// ~ Indent()+PushId(). Already called by TreeNode() when returning true, but you can call Push/Pop yourself for layout purpose
IMGUI_APIvoidTreePush(constvoid*ptr_id=NULL);// "
IMGUI_APIvoidTreePop();
IMGUI_APIvoidSetNextTreeNodeOpened(boolopened,ImGuiSetCondcond=0);// set next tree node/collapsing header to be opened.
IMGUI_APIvoidTreePop();// ~ Unindent()+PopId()
IMGUI_APIvoidTreeAdvanceToLabelPos();// advance cursor x position by GetTreeNodeToLabelSpacing()
IMGUI_APIfloatGetTreeNodeToLabelSpacing();// horizontal distance preceeding label when using TreeNode*() or Bullet() == (g.FontSize + style.FramePadding.x*2) for a regular unframed TreeNode
IMGUI_APIvoidSetNextTreeNodeOpen(boolis_open,ImGuiSetCondcond=0);// set next TreeNode/CollapsingHeader open state.
IMGUI_APIboolCollapsingHeader(constchar*label,ImGuiTreeNodeFlagsflags=0);// if returning 'true' the header is open. doesn't indent nor push on ID stack. user doesn't have to call TreePop().
IMGUI_APIboolCollapsingHeader(constchar*label,bool*p_open,ImGuiTreeNodeFlagsflags=0);// when 'p_open' isn't NULL, display an additional small close button on upper right of the header
// Widgets: Selectable / Lists
IMGUI_APIboolSelectable(constchar*label,boolselected=false,ImGuiSelectableFlagsflags=0,constImVec2&size=ImVec2(0,0));// size.x==0.0: use remaining width, size.x>0.0: specify width. size.y==0.0: use label height, size.y>0.0: specify height
@ -353,15 +368,15 @@ namespace ImGui
// Popups
IMGUI_APIvoidOpenPopup(constchar*str_id);// mark popup as open. popups are closed when user click outside, or activate a pressable item, or CloseCurrentPopup() is called within a BeginPopup()/EndPopup() block. popup identifiers are relative to the current ID-stack (so OpenPopup and BeginPopup needs to be at the same level).
IMGUI_APIboolBeginPopup(constchar*str_id);// return true if popup if opened and start outputting to it. only call EndPopup() if BeginPopup() returned true!
IMGUI_APIboolBeginPopupModal(constchar*name,bool*p_opened=NULL,ImGuiWindowFlagsextra_flags=0);// modal dialog (can't close them by clicking outside)
IMGUI_APIboolBeginPopup(constchar*str_id);// return true if the popup is open, and you can start outputting to it. only call EndPopup() if BeginPopup() returned true!
IMGUI_APIboolBeginPopupModal(constchar*name,bool*p_open=NULL,ImGuiWindowFlagsextra_flags=0);// modal dialog (can't close them by clicking outside)
IMGUI_APIboolBeginPopupContextItem(constchar*str_id,intmouse_button=1);// helper to open and begin popup when clicked on last item. read comments in .cpp!
IMGUI_APIboolBeginPopupContextWindow(boolalso_over_items=true,constchar*str_id=NULL,intmouse_button=1);// helper to open and begin popup when clicked on current window.
IMGUI_APIboolBeginPopupContextVoid(constchar*str_id=NULL,intmouse_button=1);// helper to open and begin popup when clicked in void (no window).
IMGUI_APIvoidEndPopup();
IMGUI_APIvoidCloseCurrentPopup();// close the popup we have begin-ed into. clicking on a MenuItem or Selectable automatically close the current popup.
// Logging: all text output from interface is redirected to tty/file/clipboard. Tree nodes are automatically opened.
// Logging: all text output from interface is redirected to tty/file/clipboard. By default, tree nodes are automatically opened during logging.
IMGUI_APIvoidLogToTTY(intmax_depth=-1);// start logging to tty
IMGUI_APIvoidLogToFile(intmax_depth=-1,constchar*filename=NULL);// start logging to file
IMGUI_APIvoidLogToClipboard(intmax_depth=-1);// start logging to OS clipboard
@ -377,6 +392,7 @@ namespace ImGui
IMGUI_APIboolIsItemHovered();// was the last item hovered by mouse?
IMGUI_APIboolIsItemHoveredRect();// was the last item hovered by mouse? even if another item is active or window is blocked by popup while we are hovering this
IMGUI_APIboolIsItemActive();// was the last item active? (e.g. button being held, text field being edited- items that don't interact will always return false)
IMGUI_APIboolIsItemClicked(intmouse_button=0);// was the last item clicked? (e.g. button/node just clicked on)
IMGUI_APIboolIsItemVisible();// was the last item visible? (aka not out of sight due to clipping/scrolling.)
IMGUI_APIboolIsAnyItemHovered();
IMGUI_APIboolIsAnyItemActive();
@ -386,8 +402,9 @@ namespace ImGui
IMGUI_APIvoidSetItemAllowOverlap();// allow last item to be overlapped by a subsequent item. sometimes useful with invisible buttons, selectables, etc. to catch unused area.
IMGUI_APIboolIsWindowHovered();// is current window hovered and hoverable (not blocked by a popup) (differentiate child windows from each others)
IMGUI_APIboolIsWindowFocused();// is current window focused
IMGUI_APIboolIsRootWindowFocused();// is current root window focused (top parent window in case of child windows)
IMGUI_APIboolIsRootWindowFocused();// is current root window focused (root = top-most parent of a child, otherwise self)
IMGUI_APIboolIsRootWindowOrAnyChildFocused();// is current root window or any of its child (including current window) focused
IMGUI_APIboolIsRootWindowOrAnyChildHovered();// is current root window or any of its child (including current window) hovered and hoverable (not blocked by a popup)
IMGUI_APIboolIsRectVisible(constImVec2&size);// test if rectangle of given size starting from cursor pos is visible (not clipped). to perform coarse clipping on user's side (as an optimization)
IMGUI_APIboolIsPosHoveringAnyWindow(constImVec2&pos);// is given position hovering any active imgui window
IMGUI_APIfloatGetTime();
@ -433,17 +450,20 @@ namespace ImGui
IMGUI_APIconstchar*GetClipboardText();
IMGUI_APIvoidSetClipboardText(constchar*text);
// Internal state/context access - if you want to use multiple ImGui context, or share context between modules (e.g. DLL), or allocate the memory yourself
// Internal context access - if you want to use multiple context, share context between modules (e.g. DLL). There is a default context created and active by default.
// All contexts share a same ImFontAtlas by default. If you want different font atlas, you can new() them and overwrite the GetIO().Fonts variable of an ImGui context.
ImGuiInputTextFlags_Multiline=1<<20// For internal use by InputTextMultiline()
};
// Flags for ImGui::TreeNodeEx(), ImGui::CollapsingHeader*()
enumImGuiTreeNodeFlags_
{
ImGuiTreeNodeFlags_Selected=1<<0,// Draw as selected
ImGuiTreeNodeFlags_Framed=1<<1,// Full colored frame (e.g. for CollapsingHeader)
ImGuiTreeNodeFlags_AllowOverlapMode=1<<2,// Hit testing to allow subsequent widgets to overlap this one
ImGuiTreeNodeFlags_NoTreePushOnOpen=1<<3,// Don't do a TreePush() when open (e.g. for CollapsingHeader) = no extra indent nor pushing on ID stack
ImGuiTreeNodeFlags_NoAutoOpenOnLog=1<<4,// Don't automatically and temporarily open node when Logging is active (by default logging will automatically open tree nodes)
ImGuiTreeNodeFlags_DefaultOpen=1<<5,// Default node to be open
ImGuiTreeNodeFlags_OpenOnDoubleClick=1<<6,// Need double-click to open node
ImGuiTreeNodeFlags_OpenOnArrow=1<<7,// Only open when clicking on the arrow part. If ImGuiTreeNodeFlags_OpenOnDoubleClick is also set, single-click arrow or double-click all box to open.
ImGuiTreeNodeFlags_Leaf=1<<8,// No collapsing, no arrow (use as a convenience for leaf nodes).
ImGuiTreeNodeFlags_Bullet=1<<9,// Display a bullet instead of arrow
//ImGuITreeNodeFlags_SpanAllAvailWidth = 1 << 10, // FIXME: TODO: Extend hit box horizontally even if not framed
//ImGuiTreeNodeFlags_NoScrollOnOpen = 1 << 11, // FIXME: TODO: Disable automatic scroll on TreePop() if node got just open and contents is not visible
ImVec2ItemSpacing;// Horizontal and vertical spacing between widgets/lines
ImVec2ItemInnerSpacing;// Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label)
ImVec2TouchExtraPadding;// Expand reactive bounding box for touch-based system where touch position is not accurate enough. Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget. So don't grow this too much!
floatIndentSpacing;// Horizontal indentation when e.g. entering a tree node
floatIndentSpacing;// Horizontal indentation when e.g. entering a tree node. Generally == (FontSize + FramePadding.x*2).
floatColumnsMinSpacing;// Minimum horizontal spacing between two columns
floatScrollbarSize;// Width of the vertical scrollbar, Height of the horizontal scrollbar
floatScrollbarRounding;// Radius of grab corners for scrollbar
@ -705,7 +743,7 @@ struct ImGuiIO
floatMouseDoubleClickMaxDist;// = 6.0f // Distance threshold to stay in to validate a double-click, in pixels.
floatMouseDragThreshold;// = 6.0f // Distance threshold before considering we are dragging
intKeyMap[ImGuiKey_COUNT];// <unset> // Map of indices into the KeysDown[512] entries array
floatKeyRepeatDelay;// = 0.250f // When holding a key/button, time before it starts repeating, in seconds. (for actions where 'repeat' is active)
floatKeyRepeatDelay;// = 0.250f // When holding a key/button, time before it starts repeating, in seconds (for buttons in Repeat mode, etc.).
floatKeyRepeatRate;// = 0.020f // When holding a key/button, rate at which it repeats, in seconds.
void*UserData;// = NULL // Store your own data for retrieval by callbacks.
@ -764,7 +802,7 @@ struct ImGuiIO
// Functions
IMGUI_APIvoidAddInputCharacter(ImWcharc);// Helper to add a new character into InputCharacters[]
IMGUI_APIvoidAddInputCharactersUTF8(constchar*utf8_chars);// Helper to add new characters into InputCharacters[] from an UTF-8 string
IMGUI_APIvoidClearInputCharacters(){InputCharacters[0]=0;}// Helper to clear the text input buffer
inlinevoidClearInputCharacters(){InputCharacters[0]=0;}// Helper to clear the text input buffer
// Resizing callback data to apply custom constraint. As enabled by SetNextWindowSizeConstraints(). Callback is called during the next Begin().
// NB: For basic min/max size constraint on each axis you don't need to use the callback! The SetNextWindowSizeConstraints() parameters are enough.
structImGuiSizeConstraintCallbackData
{
void*UserData;// Read-only. What user passed to SetNextWindowSizeConstraints()
ImVec2Pos;// Read-only. Window position, for reference.
ImVec2CurrentSize;// Read-only. Current window size.
ImVec2DesiredSize;// Read-write. Desired size, based on user's mouse position. Write to this field to restrain resizing.
};
// ImColor() helper to implicity converts colors to either ImU32 (packed 4x1 byte) or ImVec4 (4x1 float)
// Prefer using IM_COL32() macros if you want a guaranteed compile-time ImU32 for usage with ImDrawList API.
// Avoid storing ImColor! Store either u32 of ImVec4. This is not a full-featured color class.
// None of the ImGui API are using ImColor directly but you can use it as a convenience to pass colors in either ImU32 or ImVec4 formats.
structImColor
@ -1017,36 +1070,33 @@ struct ImColor
};
// Helper: Manually clip large list of items.
// If you are displaying thousands of even spaced items and you have a random access to the list, you can perform clipping yourself to save on CPU.
// If you are submitting lots of evenly spaced items and you have a random access to the list, you can perform coarse clipping based on visibility to save yourself from processing those items at all.
// The clipper calculates the range of visible items and advance the cursor to compensate for the non-visible items we have skipped.
// ImGui already clip items based on their bounds but it needs to measure text size to do so. Coarse clipping before submission makes this cost and your own data fetching/submission cost null.
// for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) // display only visible items
// ImGui::Text("line number %d", i);
// clipper.End();
// NB: 'count' is only used to clamp the result, if you don't know your count you can use INT_MAX
// ImGuiListClipper clipper(1000); // we have 1000 elements, evenly spaced.
// while (clipper.Step())
// for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
// ImGui::Text("line number %d", i);
// - Step 0: the clipper let you process the first element, regardless of it being visible or not, so we can measure the element height (step skipped if we passed a known height as second arg to constructor).
// - Step 1: the clipper infer height from first element, calculate the actual range of elements to display, and position the cursor before the first element.
// - (Step 2: dummy step only required if an explicit items_height was passed to constructor or Begin() and user call Step(). Does nothing and switch to Step 3.)
// - Step 3: the clipper validate that we have reached the expected Y position (corresponding to element DisplayEnd), advance the cursor to the end of the list and then returns 'false' to end the loop.
~ImGuiListClipper(){IM_ASSERT(ItemsCount==-1);}// user forgot to call End()
// items_count: Use -1 to ignore (you can call Begin later). Use INT_MAX if you don't know how many items you have (in which case the cursor won't be advanced in the final step).
// items_height: Use -1.0f to be calculated automatically on first step. Otherwise pass in the distance between your items, typically GetTextLineHeightWithSpacing() or GetItemsLineHeightWithSpacing().
// If you don't specify an items_height, you NEED to call Step(). If you specify items_height you may call the old Begin()/End() api directly, but prefer calling Step().
ImGuiListClipper(intitems_count=-1,floatitems_height=-1.0f){Begin(items_count,items_height);}// NB: Begin() initialize every fields (as we allow user to call Begin/End multiple times on a same instance if they want).
~ImGuiListClipper(){IM_ASSERT(ItemsCount==-1);}// Assert if user forgot to call End() or Step() until false.
voidBegin(intcount,floatheight)// items_height: generally pass GetTextLineHeightWithSpacing() or GetItemsLineHeightWithSpacing()
{
IM_ASSERT(ItemsCount==-1);
ItemsCount=count;
ItemsHeight=height;
ImGui::CalcListClipping(ItemsCount,ItemsHeight,&DisplayStart,&DisplayEnd);// calculate how many to clip/display
// NB- You most likely do NOT need to use draw callbacks just to create your own widget or customized UI rendering (you can poke into the draw list for that)
// Draw callback may be useful for example, if you want to render a complex 3D scene inside a UI element, change your GPU render state, etc.
// The expected behavior from your rendering loop is:
// if (cmd.UserCallback != NULL)
// cmd.UserCallback(parent_list, cmd);
// else
// RenderTriangles()
// Draw callback may be useful for example, A) Change your GPU render state, B) render a complex 3D scene inside a UI element (without an intermediate texture/render target), etc.
// The expected behavior from your rendering function is 'if (cmd.UserCallback != NULL) cmd.UserCallback(parent_list, cmd); else RenderTriangles()'
// Vertex index (override with, e.g. '#define ImDrawIdx unsigned int' in ImConfig)
// Vertex index (override with '#define ImDrawIdx unsigned int' inside in imconfig.h)
#ifndef ImDrawIdx
typedefunsignedshortImDrawIdx;
#endif
@ -1223,7 +1269,7 @@ struct ImFontConfig
intOversampleH,OversampleV;// 3, 1 // Rasterize at higher quality for sub-pixel positioning. We don't use sub-pixel positions on the Y axis.
boolPixelSnapH;// false // Align every character to pixel boundary (if enabled, set OversampleH/V to 1)
ImVec2GlyphExtraSpacing;// 0, 0 // Extra spacing (in pixels) between glyphs
constImWchar*GlyphRanges;// // List of Unicode range (2 value per range, values are inclusive, zero-terminated list)
constImWchar*GlyphRanges;// // Pointer to a user-provided list of Unicode range (2 value per range, values are inclusive, zero-terminated list). THE ARRAY DATA NEEDS TO PERSIST AS LONG AS THE FONT IS ALIVE.
boolMergeMode;// false // Merge into previous ImFont, so you can combine multiple inputs font into one ImFont (e.g. ASCII font + icons + Japanese glyphs).
boolMergeGlyphCenterV;// false // When merging (multiple ImFontInput for one ImFont), vertically center new glyphs instead of aligning their baseline
@ -1242,6 +1288,7 @@ struct ImFontConfig
// 3. Upload the pixels data into a texture within your graphics system.
// 4. Call SetTexID(my_tex_id); and pass the pointer/identifier to your texture. This value will be passed back to you during rendering to identify the texture.
// 5. Call ClearTexData() to free textures memory on the heap.
// NB: If you use a 'glyph_ranges' array you need to make sure that your array persist up until the ImFont is cleared. We only copy the pointer, not the data.
structImFontAtlas
{
IMGUI_APIImFontAtlas();
@ -1267,7 +1314,7 @@ struct ImFontAtlas
voidSetTexID(void*id){TexID=id;}
// Helpers to retrieve list of common Unicode ranges (2 value per range, values are inclusive, zero-terminated list)
// (Those functions could be static but aren't so most users don't have to refer to the ImFontAtlas:: name ever if in their code; just using io.Fonts->)
// NB: Make sure that your string are UTF-8 and NOT in your local code page. See FAQ for details.
IMGUI_APIconstImWchar*GetGlyphRangesDefault();// Basic Latin, Extended Latin
IMGUI_APIconstImWchar*GetGlyphRangesKorean();// Default + Korean characters
IMGUI_APIconstImWchar*GetGlyphRangesJapanese();// Default + Hiragana, Katakana, Half-Width, Selection of 1946 Ideographs
#pragma clang diagnostic ignored "-Wold-style-cast" // warning : use of old-style cast // yes, they are more terse.
#pragma clang diagnostic ignored "-Wdeprecated-declarations" // warning : 'xx' is deprecated: The POSIX name for this item.. // for strdup used in demo code (so user can copy & paste the code)
#pragma clang diagnostic ignored "-Wint-to-void-pointer-cast" // warning : cast to 'void *' from smaller integer type 'int'
#pragma clang diagnostic ignored "-Wformat-security" // warning : warning: format string is not a string literal
#endif
#ifdef __GNUC__
#pragma clang diagnostic ignored "-Wexit-time-destructors" // warning : declaration requires an exit-time destructor // exit-time destruction order is undefined. if MemFree() leads to users code that has been disabled before exit it might cause problems. ImGui coding style welcomes static/globals.
#pragma clang diagnostic ignored "-Wreserved-id-macro" // warning : macro name is a reserved identifier //
#elif defined(__GNUC__)
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" // warning: cast to pointer from integer of different size
#pragma GCC diagnostic ignored "-Wformat-security" // warning : format string is not a string literal (potentially insecure)
#pragma GCC diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function
#pragma GCC diagnostic ignored "-Wconversion" // warning: conversion to 'xxxx' from 'xxxx' may alter its value
#endif
// Play it nice with Windows users. Notepad in 2015 still doesn't display text data with Unix-style \n.
ImGui::TextWrapped("The logging API redirects all text output so you can easily capture the content of a window or a block. Tree nodes can be automatically expanded. You can also call ImGui::LogText() to output directly to the log without a visual output.");
if(i>0){ImGui::SameLine();if(ImGui::SmallButton("Set as default")){atlas->Fonts[i]=atlas->Fonts[0];atlas->Fonts[0]=font;}}
ImGui::PushFont(font);
ImGui::Text("The quick brown fox jumps over the lazy dog");
ImGui::PopFont();
if(ImGui::TreeNode("Details"))
ShowHelpMarker("This is a more standard looking tree with selectable nodes.\nClick to select, CTRL+Click to toggle, click on arrows or double-click to open.");
staticintselection_mask=(1<<2);// Dumb representation of what may be user-side selection state. You may carry selection state inside or outside your objects in whatever format you see fit.
intnode_clicked=-1;// Temporary storage of what node we have clicked to process selection at the end of the loop. May be a pointer to your own node type, etc.
ImGui::PushStyleVar(ImGuiStyleVar_IndentSpacing,ImGui::GetFontSize()*3);// Increase spacing to differentiate leaves from expanded contents.
for(inti=0;i<6;i++)
{
ImGui::DragFloat("font scale",&font->Scale,0.005f,0.3f,2.0f,"%.1f");// scale only this font
// Leaf: The only reason we have a TreeNode at all is to allow selection of the leaf. Otherwise we can use BulletText() or TreeAdvanceToLabelPos()+Text().
// Update selection state. Process outside of tree loop to avoid visual inconsistencies during the clicking-frame.
if(ImGui::GetIO().KeyCtrl)
selection_mask^=(1<<node_clicked);// CTRL+click to toggle
else//if (!(selection_mask & (1 << node_clicked))) // Depending on selection behavior you want, this commented bit preserve selection when clicking on item that is part of the selection
selection_mask=(1<<node_clicked);// Click to single-select
ImGui::TextWrapped("The logging API redirects all text output so you can easily capture the content of a window or a block. Tree nodes can be automatically expanded. You can also call ImGui::LogText() to output directly to the log without a visual output.");
if(ImGui::TreeNode("Node##1")){for(inti=0;i<6;i++)ImGui::BulletText("Item %d..",i);ImGui::TreePop();}// Dummy tree data
ImGui::AlignFirstTextHeightToWidgets();// Vertically align text node a bit lower so it'll be vertically centered with upcoming widget. Otherwise you can use SmallButton (smaller fit).
booltree_opened=ImGui::TreeNode("Node##2");// Common mistake to avoid: if we want to SameLine after TreeNode we need to do it before we add child content.
boolnode_open=ImGui::TreeNode("Node##2");// Common mistake to avoid: if we want to SameLine after TreeNode we need to do it before we add child content.
if(ImGui::SmallButton("Add Dummy Text")){AddLog("%d some text",Items.Size);AddLog("some more text");AddLog("display very important message here!");}ImGui::SameLine();
if(ImGui::SmallButton("Add Dummy Error"))AddLog("[error] something went wrong");ImGui::SameLine();
if(ImGui::SmallButton("Scroll to bottom"))ScrollToBottom=true;
//static float t = 0.0f; if (ImGui::GetTime() - t > 0.02f) { t = ImGui::GetTime(); AddLog("Spam %f", t); }
ImGui::Separator();
@ -1952,24 +2072,33 @@ struct ExampleAppConsole
ImGui::PopStyleVar();
ImGui::Separator();
// Display every line as a separate entry so we can change their color or add custom widgets. If you only want raw text you can use ImGui::TextUnformatted(log.begin(), log.end());
// NB- if you have thousands of entries this approach may be too inefficient. You can seek and display only the lines that are visible - CalcListClipping() is a helper to compute this information.
// If your items are of variable size you may want to implement code similar to what CalcListClipping() does. Or split your data into fixed height items to allow random-seeking into your list.
// Display every line as a separate entry so we can change their color or add custom widgets. If you only want raw text you can use ImGui::TextUnformatted(log.begin(), log.end());
// NB- if you have thousands of entries this approach may be too inefficient and may require user-side clipping to only process visible items.
// You can seek and display only the lines that are visible using the ImGuiListClipper helper, if your elements are evenly spaced and you have cheap random access to the elements.
// To use the clipper we could replace the 'for (int i = 0; i < Items.Size; i++)' loop with:
// ImGuiListClipper clipper(Items.Size);
// while (clipper.Step())
// for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
// However take note that you can not use this code as is if a filter is active because it breaks the 'cheap random-access' property. We would need random-access on the post-filtered list.
// A typical application wanting coarse clipping and filtering may want to pre-compute an array of indices that passed the filtering test, recomputing this array when user changes the filter,
// and appending newly elements as they are inserted. This is left as a task to the user until we can manage to improve this example code!
// If your items are of variable size you may want to implement code similar to what ImGuiListClipper does. Or split your data into fixed height items to allow random-seeking into your list.
ImGui::PushID(uid);// Use object uid as identifier. Most commonly you could also use the object pointer as a base ID.
ImGui::AlignFirstTextHeightToWidgets();// Text and Tree nodes are less high than regular widgets, here we add vertical spacing to make the tree lines equal high.
#pragma clang diagnostic ignored "-Wfloat-equal" // warning : comparing floating point with == or != is unsafe // storing and comparing against same constants ok.
#pragma clang diagnostic ignored "-Wglobal-constructors" // warning : declaration requires a global destructor // similar to above, not sure what the exact difference it.
// Internal state of the currently focused/edited text input box
@ -349,7 +345,7 @@ struct ImGuiPopupRef
};
// Main state for ImGui
structImGuiState
structImGuiContext
{
boolInitialized;
ImGuiIOIO;
@ -378,14 +374,16 @@ struct ImGuiState
boolActiveIdIsAlive;
boolActiveIdIsJustActivated;// Set at the time of activation for one frame
boolActiveIdAllowOverlap;// Set only by active widget
ImVec2ActiveIdClickOffset;// Clicked offset from upper-left corner, if applicable (currently only set by ButtonBehavior)
ImGuiWindow*ActiveIdWindow;
ImGuiWindow*MovedWindow;// Track the child window we clicked on to move a window. Pointer is only valid if ActiveID is the "#MOVE" identifier of a window.
ImGuiWindow*MovedWindow;// Track the child window we clicked on to move a window.
ImDrawDataRenderDrawData;// Main ImDrawData instance to pass render information to the user
@ -414,13 +416,12 @@ struct ImGuiState
ImFontInputTextPasswordFont;
ImGuiIDScalarAsInputTextId;// Temporary text input when CTRL+clicking on a slider, etc.
ImGuiStorageColorEditModeStorage;// Store user selection of color edit mode
ImVec2ActiveClickDeltaToCenter;
floatDragCurrentValue;// Currently dragged value, always float, not rounded by end-user precision settings
ImVec2DragLastMouseDelta;
floatDragSpeedDefaultRatio;// If speed == 0.0f, uses (max-min) * DragSpeedDefaultRatio
floatDragSpeedScaleSlow;
floatDragSpeedScaleFast;
ImVec2ScrollbarClickDeltaToGrabCenter;// Distance between mouse and center of grab box, normalized in parent space. Use storage?
ImVec2ScrollbarClickDeltaToGrabCenter;// Distance between mouse and center of grab box, normalized in parent space. Use storage?
charTooltip[1024];
char*PrivateClipboard;// If no custom clipboard handler is defined
ImVec2OsImePosRequest,OsImePosSet;// Cursor position request & last passed to the OS Input Method Editor
@ -440,7 +441,7 @@ struct ImGuiState
intCaptureKeyboardNextFrame;
charTempBuffer[1024*3+1];// temporary text buffer
ImGuiState()
ImGuiContext()
{
Initialized=false;
Font=NULL;
@ -462,8 +463,10 @@ struct ImGuiState
ActiveIdIsAlive=false;
ActiveIdIsJustActivated=false;
ActiveIdAllowOverlap=false;
ActiveIdClickOffset=ImVec2(-1,-1);
ActiveIdWindow=NULL;
MovedWindow=NULL;
MovedWindowMoveId=0;
SettingsDirtyTimer=0.0f;
SetNextWindowPosVal=ImVec2(0.0f,0.0f);
@ -474,11 +477,12 @@ struct ImGuiState
SetNextWindowContentSizeCond=0;
SetNextWindowCollapsedCond=0;
SetNextWindowFocus=false;
SetNextTreeNodeOpenedVal=false;
SetNextTreeNodeOpenedCond=0;
SetNextWindowSizeConstraintCallback=NULL;
SetNextWindowSizeConstraintCallbackUserData=NULL;
SetNextTreeNodeOpenVal=false;
SetNextTreeNodeOpenCond=0;
ScalarAsInputTextId=0;
ActiveClickDeltaToCenter=ImVec2(0.0f,0.0f);
DragCurrentValue=0.0f;
DragLastMouseDelta=ImVec2(0.0f,0.0f);
DragSpeedDefaultRatio=0.01f;
@ -602,6 +606,7 @@ struct IMGUI_API ImGuiWindow
ImVec2SizeFull;// Size when non collapsed
ImVec2SizeContents;// Size of contents (== extents reach of the drawing cursor) from previous frame
ImVec2SizeContentsExplicit;// Size of contents explicitly set by the user via SetNextWindowContentSize()
ImRectContentsRegionRect;// Maximum visible content position in window coordinates. ~~ (SizeContentsExplicit ? SizeContentsExplicit : Size - ScrollbarSizes) - CursorStartPos, per axis
ImVec2WindowPadding;// Window padding at the time of begin. We need to lock it, in particular manipulation of the ShowBorder would have an effect
ImGuiIDMoveID;// == window->GetID("#MOVE")
ImVec2Scroll;
@ -629,7 +634,7 @@ struct IMGUI_API ImGuiWindow
ImGuiDrawContextDC;// Temporary per-window data, reset at the beginning of the frame
ImVector<ImGuiID>IDStack;// ID stack. ID are hashes seeded with the value at the top of the stack
IMGUI_APIboolTreeNodeBehaviorIsOpened(ImGuiIDid,ImGuiTreeNodeFlagsflags=0);// Consume previous SetNextTreeNodeOpened() data, if any. May return true when logging
IMGUI_APIboolTreeNodeBehaviorIsOpen(ImGuiIDid,ImGuiTreeNodeFlagsflags=0);// Consume previous SetNextTreeNodeOpened() data, if any. May return true when logging