diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt
index b4669fb1..2f4fa041 100644
--- a/docs/CHANGELOG.txt
+++ b/docs/CHANGELOG.txt
@@ -38,13 +38,17 @@ DOCKING FEATURES
- Added Docking system: [BETA] (#2109, #351)
- Added ImGuiConfigFlags_DockingEnable flag to enable Docking.
Set with `io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;`.
- - Added DockSpace() API.
+ - Added DockSpace(), DockSpaceOverViewport() API.
- Added ImGuiDockNodeFlags flags for DockSpace().
- - Added SetNextWindowDock(), SetNextWindowClass() API.
- - Added GetWindowDockId(), IsWindowDocked() API.
+ - Added SetNextWindowDockID(), SetNextWindowClass() API.
+ - Added GetWindowDockID(), IsWindowDocked() API.
- Added ImGuiWindowFlags_NoDocking window flag to disable the possibility for a window to be docked.
Popup, Menu and Child windows always have the ImGuiWindowFlags_NoDocking flag set.
- - Added io.ConfigDockingWithShift option to configure docking mode.
+ - Added ImGuiWindowClass to specify advanced docking/viewport related flags via SetNextWindowClass().
+ - Added io.ConfigDockingNoSplit option.
+ - Added io.ConfigDockingWithShift option.
+ - Added io.ConfigDockingAlwaysTabBar option.
+ - Added io.ConfigDockingTransparentPayload option.
- Style: Added ImGuiCol_DockingPreview, ImGuiCol_DockingEmptyBg colors.
- Demo: Added "DockSpace" example app showcasing use of explicit dockspace nodes.
@@ -80,6 +84,7 @@ Other changes:
- Added UpdatePlatformWindows(), RenderPlatformWindows(), DestroyPlatformWindows() for usage for application core.
- Added FindViewportByID(), FindViewportByPlatformHandle() for usage by back-ends.
- Added ImGuiConfigFlags_ViewportsEnable configuration flag and other viewport options.
+- Added io.ConfigViewportsNoAutoMerge, io.ConfigViewportsNoTaskBarIcon, io.ConfigViewportsNoDecoration, io.ConfigViewportsNoDefaultParent options.
- Added ImGuiBackendFlags_PlatformHasViewports, ImGuiBackendFlags_RendererHasViewports, ImGuiBackendFlags_HasMouseHoveredViewport backend flags.
- Added io.MainViewport, io.Viewports, io.MouseHoveredViewport (MouseHoveredViewport is optional _even_ for multi-viewport support).
- Added ImGuiViewport structure, ImGuiViewportFlags flags.
@@ -94,16 +99,419 @@ Other changes:
-----------------------------------------------------------------------
- VERSION 1.68 (In progress)
+ VERSION 1.73 WIP (In Progress)
-----------------------------------------------------------------------
Other Changes:
+- ColorPicker: Made rendering aware of global style alpha of the picker can be faded out. (#2711)
+ Note that some elements won't accurately fade down with the same intensity, and the color wheel
+ when enabled will have small overlap glitches with (style.Alpha < 1.0).
+- ColorEdit: Disable Hue edit when Saturation==0 instead of letting Hue values jump around.
+- TabBar: fixed ScrollToBar request creating bouncing loop when tab is larger than available space.
+- TabBar: fixed single-tab not shrinking their width down.
+- TabBar: feed desired width (sum of unclipped tabs width) into layout system to allow for auto-resize. (#2768)
+ (before 1.71 tab bars fed the sum of current width which created feedback loops in certain situations).
+- TabBar: improved shrinking for large number of tabs to avoid leaving extraneous space on the right side.
+ Individuals tabs are given integer-rounded width and remainder is spread between tabs left-to-right.
+- SliderScalar: Improved assert when using U32 or U64 types with a large v_max value. (#2765) [@loicmouton]
+- DragInt, DragFloat, DragScalar: Using (v_min > v_max) allows locking any edit to the value.
+- ImDrawList: clarified the name of many parameters so reading the code is a little easier. (#2740)
+- Using offsetof() when available in C++11. Avoids Clang sanitizer complaining about old-style macros. (#94)
+- Added a mechanism to compact/free the larger allocations of unused windows (buffers are compacted when
+ a window is unused for 60 seconds, as per io.ConfigWindowsMemoryCompactTimer = 60.0f). Note that memory
+ usage has never been reported as a problem, so this is merely a touch of overzealous luxury. (#2636)
+- Backends: DX11: Fixed GSGetShader() call not passing an initialized instance count,
+ would generally make the debug layer complain (Added in 1.72).
+- Backends: Vulkan: Added support for specifying multisample count.
+ Set ImGui_ImplVulkan_InitInfo::MSAASamples to one of the VkSampleCountFlagBits values
+ to use, default is non-multisampled as before. (#2705, #2706) [@vilya]
+- Misc: Updated stb_rect_pack from 0.99 to 1.00 (fixes by @rygorous: off-by-1 bug in best-fit heuristic,
+ fix handling of rectangles too large to fit inside texture). (#2762) [@tido64]
+
+
+-----------------------------------------------------------------------
+ VERSION 1.72b (Released 2019-07-31)
+-----------------------------------------------------------------------
+
+Other Changes:
+
+- Nav, Scrolling: Fixed programmatic scroll leading to a slightly incorrect scroll offset when
+ the window has decorations or a menu-bar (broken in 1.71). This was mostly noticeable when
+ a keyboard/gamepad movement led to scrolling the view, or using e.g. SetScrollHereY() function.
+- Nav: Made hovering non-MenuItem Selectable not re-assign the source item for keyboard navigation.
+- Nav: Fixed an issue with NavFlattened window flag (beta) where widgets not entirely fitting
+ in child window (often selectables because of their protruding sides) would be not considered
+ as entry points to to navigate toward the child window. (#787)
+
+
+-----------------------------------------------------------------------
+ VERSION 1.72 (Released 2019-07-27)
+-----------------------------------------------------------------------
+
+Breaking Changes:
+- Removed redirecting functions/enums names that were marked obsolete in 1.51 (June 2017):
+ - ImGuiCol_Column*, ImGuiSetCond_* enums.
+ - IsItemHoveredRect(), IsPosHoveringAnyWindow(), IsMouseHoveringAnyWindow(), IsMouseHoveringWindow() functions.
+ - IMGUI_ONCE_UPON_A_FRAME macro.
+ If you were still using the old names, read "API Breaking Changes" section of imgui.cpp to find out
+ the new names or equivalent features.
+- Renamed ImFontAtlas::CustomRect to ImFontAtlasCustomRect. Kept redirection typedef (will obsolete).
+- Removed TreeAdvanceToLabelPos() which is rarely used and only does SetCursorPosX(GetCursorPosX() + GetTreeNodeToLabelSpacing()).
+ Kept redirection function (will obsolete). (#581, #324)
+
+Other Changes:
+- Scrolling: Made mouse-wheel scrolling lock the underlying window until the mouse is moved again or
+ until a short delay expires (~2 seconds). This allow uninterrupted scroll even if child windows are
+ passing under the mouse cursor. (#2604)
+- Scrolling: Made it possible for mouse wheel and navigation-triggered scrolling to override a call to
+ SetScrollX()/SetScrollY(), making it possible to use a simpler stateless pattern for auto-scrolling:
+ // (Submit items..)
+ if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) // If scrolling at the already at the bottom..
+ ImGui::SetScrollHereY(1.0f); // ..make last item fully visible
+- Scrolling: Added SetScrollHereX(), SetScrollFromPosX() for completeness. (#1580) [@kevreco]
+- Scrolling: Mouse wheel scrolling while hovering a child window is automatically forwarded to parent window
+ if ScrollMax is zero on the scrolling axis.
+ Also still the case if ImGuiWindowFlags_NoScrollWithMouse is set (not new), but previously the forwarding
+ would be disabled if ImGuiWindowFlags_NoScrollbar was set on the child window, which is not the case
+ any more. Forwarding can still be disabled by setting ImGuiWindowFlags_NoInputs. (amend #1502, #1380).
+- Window: Fixed InnerClipRect right-most coordinates using wrong padding setting (introduced in 1.71).
+- Window: Fixed old SetWindowFontScale() api value from not being inherited by child window. Added
+ comments about the right way to scale your UI (load a font at the right side, rebuild atlas, scale style).
+- Scrollbar: Avoid overlapping the opposite side when window (often a child window) is forcibly too small.
+- Combo: Hide arrow when there's not enough space even for the square button.
+- InputText: Testing for newly added ImGuiKey_KeyPadEnter key. (#2677, #2005) [@amc522]
+- TabBar: Fixed unfocused tab bar separator color (was using ImGuiCol_Tab, should use ImGuiCol_TabUnfocusedActive).
+- Columns: Fixed a regression from 1.71 where the right-side of the contents rectangle within each column
+ would wrongly use a WindowPadding.x instead of ItemSpacing.x like it always did. (#125, #2666)
+- Columns: Made the right-most edge reaches up to the clipping rectangle (removing half of WindowPadding.x
+ worth of asymmetrical/extraneous padding, note that there's another half that conservatively has to offset
+ the right-most column, otherwise it's clipping width won't match the other columns). (#125, #2666)
+- Columns: Improved honoring alignment with various values of ItemSpacing.x and WindowPadding.x. (#125, #2666)
+- Columns: Made GetColumnOffset() and GetColumnWidth() behave when there's no column set, consistently with
+ other column functions. (#2683)
+- InputTextMultiline: Fixed vertical scrolling tracking glitch.
+- Word-wrapping: Fixed overzealous word-wrapping when glyph edge lands exactly on the limit. Because
+ of this, auto-fitting exactly unwrapped text would make it wrap. (fixes initial 1.15 commit, 78645a7d).
+- Style: Attenuated default opacity of ImGuiCol_Separator in Classic and Light styles.
+- Style: Added style.ColorButtonPosition (left/right, defaults to ImGuiDir_Right) to move the color button
+ of ColorEdit3/ColorEdit4 functions to either side of the inputs.
+- IO: Added ImGuiKey_KeyPadEnter and support in various back-ends (previously back-ends would need to
+ specifically redirect key-pad keys to their regular counterpart). This is a temporary attenuating measure
+ until we actually refactor and add whole sets of keys into the ImGuiKey enum. (#2677, #2005) [@amc522]
+- Misc: Made Button(), ColorButton() not trigger an "edited" event leading to IsItemDeactivatedAfterEdit()
+ returning true. This also effectively make ColorEdit4() not incorrect trigger IsItemDeactivatedAfterEdit()
+ when clicking the color button to open the picker popup. (#1875)
+- Misc: Added IMGUI_DISABLE_METRICS_WINDOW imconfig.h setting to explicitly compile out ShowMetricsWindow().
+- Debug, Metrics: Added "Tools->Item Picker" tool which allow clicking on a widget to break in the debugger
+ within the item code. The tool calls IM_DEBUG_BREAK() which can be redefined in imconfig.h if needed.
+- ImDrawList: Fixed CloneOutput() helper crashing. (#1860) [@gviot]
+- ImDrawList::ChannelsSplit(), ImDrawListSplitter: Fixed an issue with merging draw commands between
+ channel 0 and 1. (#2624)
+- ImDrawListSplitter: Fixed memory leak when using low-level split api (was not affecting ImDrawList api,
+ also this type was added in 1.71 and not advertised as a public-facing feature).
+- Fonts: binary_to_compressed_c.cpp: Display an error message if failing to open/read the input font file.
+- Demo: Log, Console: Using a simpler stateless pattern for auto-scrolling.
+- Demo: Widgets: Showing how to use the format parameter of Slider/Drag functions to display the name
+ of an enum value instead of the underlying integer value.
+- Backends: DX10/DX11: Backup, clear and restore Geometry Shader is any is bound when calling renderer.
+- Backends: DX11: Clear Hull Shader, Domain Shader, Compute Shader before rendering. Not backing/restoring them.
+- Backends: OSX: Disabled default native Mac clipboard copy/paste implementation in core library (added in 1.71),
+ because it needs application to be linked with '-framework ApplicationServices'. It can be explicitly
+ enabled back by using '#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS' in imconfig.h. Re-added
+ equivalent using NSPasteboard api in the imgui_impl_osx.mm experimental back-end. (#2546)
+- Backends: SDL2: Added dummy ImGui_ImplSDL2_InitForD3D() function to make D3D support more visible.
+ (#2482, #2632) [@josiahmanson]
+- Examples: Added SDL2+DirectX11 example application. (#2632, #2612, #2482) [@vincenthamm]
+
+
+-----------------------------------------------------------------------
+ VERSION 1.71 (Released 2019-06-12)
+-----------------------------------------------------------------------
+
+Breaking Changes:
+- IO: changed AddInputCharacter(unsigned short c) signature to AddInputCharacter(unsigned int c).
+- Renamed SetNextTreeNodeOpen() to SetNextItemOpen(). Kept inline redirection function (will obsolete).
+- Window: rendering of child windows outer decorations (e.g. bg color, border, scrollbars) is now
+ performed as part of their parent window, avoiding the creation of an extraneous draw commands.
+ If you have overlapping child windows with decorations, and relied on their relative z-order to be
+ mapped to submission their order, this will affect your rendering. The optimization is disabled
+ if the parent window has no visual output because it appears to be the most common situation leading
+ to the creation of overlapping child windows. Please reach out if you are affected by this change!
+
+Other Changes:
+- Window: clarified behavior of SetNextWindowContentSize(). Content size is defined as the size available
+ after removal of WindowPadding on each sides. So SetNextWindowContentSize(ImVec2(100,100)) + auto-resize
+ will always allow submitting a 100x100 item without creating a scrollbar, regarding of WindowPadding.
+ The exact meaning of ContentSize for decorated windows was previously ill-defined.
+- Window: Fixed auto-resize with AlwaysVerticalScrollbar or AlwaysHorizontalScrollbar flags.
+- Window: Fixed one case where auto-resize by double-clicking the resize grip would make either scrollbar
+ appear for a single frame after the resize.
+- Separator: Revert 1.70 "Declare its thickness (1.0f) to the layout" change. It's not incorrect
+ but it breaks existing some layout patterns. Will return back to it when we expose Separator flags.
+- Fixed InputScalar, InputScalarN, SliderScalarN, DragScalarN with non-visible label from inserting
+ style.ItemInnerSpacing.x worth of trailing spacing.
+- Fixed InputFloatX, SliderFloatX, DragFloatX functions erroneously reporting IsItemEdited() multiple
+ times when the text input doesn't match the formatted output value (e.g. input "1" shows "1.000").
+ It wasn't much of a problem because we typically use the return value instead of IsItemEdited() here.
+- Fixed uses of IsItemDeactivated(), IsItemDeactivatedAfterEdit() on multi-components widgets and
+ after EndGroup(). (#2550, #1875)
+- Fixed crash when appending with BeginMainMenuBar() more than once and no other window are showing. (#2567)
+- ColorEdit: Fixed the color picker popup only displaying inputs as HSV instead of showing multiple
+ options. (#2587, broken in 1.69 by #2384).
+- CollapsingHeader: Better clipping when a close button is enabled and it overlaps the label. (#600)
+- Scrollbar: Minor bounding box adjustment to cope with various border size.
+- Scrollbar, Style: Changed default style.ScrollbarSize from 16 to 14.
+- Combo: Fixed rounding not applying with the ImGuiComboFlags_NoArrowButton flag. (#2607) [@DucaRii]
+- Nav: Fixed gamepad/keyboard moving of window affecting contents size incorrectly, sometimes leading
+ to scrollbars appearing during the movement.
+- Nav: Fixed rare crash when e.g. releasing Alt-key while focusing a window with a menu at the same
+ frame as clearing the focus. This was in most noticeable in back-ends such as Glfw and SDL which
+ emits key release events when focusing another viewport, leading to Alt+clicking on void on another
+ viewport triggering the issue. (#2609)
+- TreeNode, CollapsingHeader: Fixed highlight frame not covering horizontal area fully when using
+ horizontal scrolling. (#2211, #2579)
+- TabBar: Fixed BeginTabBar() within a window with horizontal scrolling from creating a feedback
+ loop with the horizontal contents size.
+- Columns: Fixed Columns() within a window with horizontal scrolling from not covering the full
+ horizontal area (previously only worked with an explicit contents size). (#125)
+- Columns: Fixed Separator from creating an extraneous draw command. (#125)
+- Columns: Fixed Selectable with SpanAllColumns flag from creating an extraneous draw command. (#125)
+- Style: Added style.WindowMenuButtonPosition (left/right, defaults to ImGuiDir_Left) to move the
+ collapsing/docking button to the other side of the title bar.
+- Style: Made window close button cross slightly smaller.
+- Log/Capture: Fixed BeginTabItem() label not being included in a text log/capture.
+- ImDrawList: Added ImDrawCmd::VtxOffset value to support large meshes (64k+ vertices) using 16-bits indices.
+ The renderer back-end needs to set 'io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset' to enable
+ this, and honor the ImDrawCmd::VtxOffset field. Otherwise the value will always be zero.
+ This has the advantage of preserving smaller index buffers and allowing to execute on hardware that do not
+ support 32-bits indices. Most examples back-ends have been modified to support the VtxOffset field.
+- ImDrawList: Added ImDrawCmd::IdxOffset value, equivalent to summing element count for each draw command.
+ This is provided for convenience and consistency with VtxOffset.
+- ImDrawCallback: Allow to override the signature of ImDrawCallback by #define-ing it. This is meant to
+ facilitate custom rendering back-ends passing local render-specific data to the draw callback.
+- ImFontAtlas: FreeType: Added RasterizerFlags::Monochrome flag to disable font anti-aliasing. Combine
+ with RasterizerFlags::MonoHinting for best results. (#2545) [@HolyBlackCat]
+- ImFontGlyphRangesBuilder: Fixed unnecessarily over-sized buffer, which incidentally was also not
+ fully cleared. Fixed edge-case overflow when adding character 0xFFFF. (#2568). [@NIKE3500]
+- Demo: Added full "Dear ImGui" prefix to the title of "Dear ImGui Demo" and "Dear ImGui Metrics" windows.
+- Backends: Add native Mac clipboard copy/paste default implementation in core library to match what we are
+ dealing with Win32, and to facilitate integration in custom engines. (#2546) [@andrewwillmott]
+- Backends: OSX: imgui_impl_osx: Added mouse cursor support. (#2585, #1873) [@actboy168]
+- Examples/Backends: DirectX9/10/11/12, Metal, Vulkan, OpenGL3 (Desktop GL only): Added support for large meshes
+ (64k+ vertices) with 16-bits indices, enable 'ImGuiBackendFlags_RendererHasVtxOffset' in those back-ends.
+- Examples/Backends: Don't filter characters under 0x10000 before calling io.AddInputCharacter(),
+ the filtering is done in io.AddInputCharacter() itself. This is in prevision for fuller Unicode
+ support. (#2538, #2541)
+
+
+-----------------------------------------------------------------------
+ VERSION 1.70 (Released 2019-05-06)
+-----------------------------------------------------------------------
+
+Breaking Changes:
+- ImDrawList: Improved algorithm for mitre joints on thick lines, preserving correct thickness
+ up to 90 degrees angles (e.g. rectangles). If you have custom rendering using thick lines,
+ they will appear a little thicker now. (#2518) [@rmitton]
+- Obsoleted GetContentRegionAvailWidth(), use GetContentRegionAvail().x instead.
+ Kept inline redirection function.
+- Examples: Vulkan: Added MinImageCount/ImageCount fields in ImGui_ImplVulkan_InitInfo, required
+ during initialization to specify the number of in-flight image requested by swap chains.
+ (was previously a hard #define IMGUI_VK_QUEUED_FRAMES 2). (#2071, #1677) [@nathanvoglsam]
+- Examples: Vulkan: Tidying up the demo/internals helpers (most engine/app should not rely
+ on them but it is possible you have!).
+
+Other Changes:
+- ImDrawList: Added ImDrawCallback_ResetRenderState, a special ImDrawList::AddCallback() value
+ to request the renderer back-end to reset its render state. (#2037, #1639, #2452)
+ Examples: Added support for ImDrawCallback_ResetRenderState in all renderer back-ends. Each
+ renderer code setting up initial render state has been moved to a function so it could be
+ called at the start of rendering and when a ResetRenderState is requested. [@ocornut, @bear24rw]
+- InputText: Fixed selection background rendering one frame after the cursor movement when
+ first transitioning from no-selection to has-selection. (Bug in 1.69) (#2436) [@Nazg-Gul]
+- InputText: Work-around for buggy standard libraries where isprint('\t') returns true. (#2467, #1336)
+- InputText: Fixed ImGuiInputTextFlags_AllowTabInput leading to two tabs characters being inserted
+ if the back-end provided both Key and Character input. (#2467, #1336)
+- Layout: Added SetNextItemWidth() helper to avoid using PushItemWidth/PopItemWidth() for single items.
+ Note that SetNextItemWidth() currently only affect the same subset of items as PushItemWidth(),
+ generally referred to as the large framed+labeled items. Because the new SetNextItemWidth()
+ function is explicit we may later extend its effect to more items.
+- Layout: Fixed PushItemWidth(-width) for right-side alignment laying out some items (button, listbox, etc.)
+ with negative sizes if the 'width' argument was smaller than the available width at the time of item
+ submission.
+- Window: Fixed window with the AlwaysAutoResize flag unnecessarily extending their hovering boundaries
+ by a few pixels (this is used to facilitate resizing from borders when available for a given window).
+ One of the noticeable minor side effect was that navigating menus would have had a tendency to disable
+ highlight from parent menu items earlier than necessary while approaching the child menu.
+- Window: Close button is horizontally aligned with style.FramePadding.x.
+- Window: Fixed contents region being off by WindowBorderSize amount on the right when scrollbar is active.
+- Window: Fixed SetNextWindowSizeConstraints() with non-rounded positions making windows drift. (#2067, #2530)
+- Popups: Closing a popup restores the focused/nav window in place at the time of the popup opening,
+ instead of restoring the window that was in the window stack at the time of the OpenPopup call. (#2517)
+ Among other things, this allows opening a popup while no window are focused, and pressing Escape to
+ clear the focus again.
+- Popups: Fixed right-click from closing all popups instead of aiming at the hovered popup level
+ (regression in 1.67).
+- Selectable: With ImGuiSelectableFlags_AllowDoubleClick doesn't return true on the mouse button release
+ following the double-click. Only first mouse release + second mouse down (double-click) returns true.
+ Likewise for internal ButtonBehavior() with both _PressedOnClickRelease | _PressedOnDoubleClick. (#2503)
+- GetMouseDragDelta(): also returns the delta on the mouse button released frame. (#2419)
+- GetMouseDragDelta(): verify that mouse positions are valid otherwise returns zero.
+- Inputs: Also add support for horizontal scroll with Shift+Mouse Wheel. (#2424, #1463) [@LucaRood]
+- PlotLines, PlotHistogram: Ignore NaN values when calculating min/max bounds. (#2485)
+- Columns: Fixed boundary of clipping being off by 1 pixel within the left column. (#125)
+- Separator: Declare its thickness (1.0f) to the layout, making items around separator more symmetrical.
+- Combo, Slider, Scrollbar: Improve rendering in situation when there's only a few pixels available (<3 pixels).
+- Nav: Fixed Drag/Slider functions going into text input mode when keyboard CTRL is held while pressing NavActivate.
+- Drag and Drop: Fixed drag source with ImGuiDragDropFlags_SourceAllowNullID and null ID from receiving click
+ regardless of being covered by another window (it didn't honor correct hovering rules). (#2521)
+- ImDrawList: Improved algorithm for mitre joints on thick lines, preserving correct thickness up to 90 degrees
+ angles, also faster to output. (#2518) [@rmitton]
+- Misc: Added IM_MALLOC/IM_FREE macros mimicking IM_NEW/IM_DELETE so user doesn't need to revert
+ to using the ImGui::MemAlloc()/MemFree() calls directly.
+- Misc: Made IMGUI_CHECKVERSION() macro also check for matching size of ImDrawIdx.
+- Metrics: Added "Show windows rectangles" tool to visualize the different rectangles.
+- Demo: Improved trees in columns demo.
+- Examples: OpenGL: Added a dummy GL call + comments in ImGui_ImplOpenGL3_Init() to detect uninitialized
+ GL function loaders early, and help users understand what they are missing. (#2421)
+- Examples: SDL: Added support for SDL_GameController gamepads (enable with ImGuiConfigFlags_NavEnableGamepad). (#2509) [@DJLink]
+- Examples: Emscripten: Added Emscripten+SDL+GLES2 example. (#2494, #2492, #2351, #336) [@nicolasnoble, @redblobgames]
+- Examples: Metal: Added Glfw+Metal example. (#2527) [@bear24rw]
+- Examples: OpenGL3: Minor tweaks + not calling glBindBuffer more than necessary in the render loop.
+- Examples: Vulkan: Fixed in-flight buffers issues when using multi-viewports. (#2461, #2348, #2378, #2097)
+- Examples: Vulkan: Added missing support for 32-bit indices (#define ImDrawIdx unsigned int).
+- Examples: Vulkan: Avoid passing negative coordinates to vkCmdSetScissor, which debug validation layers do not like.
+- Examples: Vulkan: Added ImGui_ImplVulkan_SetMinImageCount() to change min image count at runtime. (#2071) [@nathanvoglsam]
+- Examples: DirectX9: Fixed erroneous assert in ImGui_ImplDX9_InvalidateDeviceObjects(). (#2454)
+- Examples: DirectX10/11/12, Allegro, Marmalade: Render functions early out when display size is zero (minimized). (#2496)
+- Examples: GLUT: Fixed existing FreeGLUT example to work with regular GLUT. (#2465) [@andrewwillmott]
+- Examples: GLUT: Renamed imgui_impl_freeglut.cpp/.h to imgui_impl_glut.cpp/.h. (#2465) [@andrewwillmott]
+- Examples: GLUT: Made io.DeltaTime always > 0. (#2430)
+- Examples: Visual Studio: Updated default platform toolset+sdk in vcproj files from v100+sdk7 (vs2010)
+ to v110+sdk8 (vs2012). This is mostly so we can remove reliance on DXSDK_DIR for the DX10/DX11 example,
+ which if existing and when switching to recent SDK ends up conflicting and creating warnings.
+
+
+-----------------------------------------------------------------------
+ VERSION 1.69 (Released 2019-03-13)
+-----------------------------------------------------------------------
+
+Breaking Changes:
+
+- Renamed ColorEdit/ColorPicker's ImGuiColorEditFlags_RGB/_HSV/_HEX flags to respectively
+ ImGuiColorEditFlags_DisplayRGB/_DisplayHSV/_DisplayHex. This is because the addition of
+ new flag ImGuiColorEditFlags_InputHSV makes the earlier one ambiguous.
+ Kept redirection enum values (will obsolete). (#2384) [@haldean]
+- Renamed GetOverlayDrawList() to GetForegroundDrawList(). Kept redirection function (will obsolete). (#2391)
+
+Other Changes:
+
+- Added GetBackgroundDrawList() helper to quickly get access to a ImDrawList that will be rendered
+ behind every other windows. (#2391, #545)
+- DragScalar, InputScalar, SliderScalar: Added support for u8/s8/u16/s16 data types (ImGuiDataType_S8, etc.)
+ We are reusing function instances of larger types to reduce code size. (#643, #320, #708, #1011)
+- Added InputTextWithHint() to display a description/hint in the text box when no text
+ has been entered. (#2400) [@Organic-Code, @ocornut]
+- Nav: Fixed a tap on AltGR (e.g. German keyboard) from navigating to the menu layer.
+- Nav: Fixed Ctrl+Tab keeping active InputText() of a previous window active after the switch. (#2380)
+- Fixed IsItemDeactivated()/IsItemDeactivatedAfterEdit() from not correctly returning true
+ when tabbing out of a focusable widget (Input/Slider/Drag) in most situations. (#2215, #1875)
+- InputInt, InputFloat, InputScalar: Fix to keep the label of the +/- buttons centered when
+ style.FramePadding.x is abnormally larger than style.FramePadding.y. Since the buttons are
+ meant to be square (to align with e.g. color button) we always use FramePadding.y. (#2367)
+- InputInt, InputScalar: +/- buttons now respects the natural type limits instead of
+ overflowing or underflowing the value.
+- InputText: Fixed an edge case crash that would happen if another widget sharing the same ID
+ is being swapped with an InputText that has yet to be activated.
+- InputText: Fixed various display corruption related to swapping the underlying buffer while
+ a input widget is active (both for writable and read-only paths). Often they would manifest
+ when manipulating the scrollbar of a multi-line input text.
+- ColorEdit, ColorPicker, ColorButton: Added ImGuiColorEditFlags_InputHSV to manipulate color
+ values encoded as HSV (in order to avoid HSV<>RGB round trips and associated singularities).
+ (#2383, #2384) [@haldean]
+- ColorPicker: Fixed a bug/assertion when displaying a color picker in a collapsed window
+ while dragging its title bar. (#2389)
+- ColorEdit: Fixed tooltip not honoring the ImGuiColorEditFlags_NoAlpha contract of never
+ reading the 4th float in the array (value was read and discarded). (#2384) [@haldean]
+- MenuItem, Selectable: Fixed disabled widget interfering with navigation (fix c2db7f63 in 1.67).
+- TabBar: Fixed a crash when using many BeginTabBar() recursively (didn't affect docking). (#2371)
+- TabBar: Added extra mis-usage error recovery. Past the assert, common mis-usage don't lead to
+ hard crashes any more, facilitating integration with scripting languages. (#1651)
+- TabBar: Fixed ImGuiTabItemFlags_SetSelected being ignored if the tab is not visible (with
+ scrolling policy enabled) or if is currently appearing.
+- TabBar: Fixed Tab tooltip code making drag and drop tooltip disappear during the frame where
+ the drag payload activate a tab.
+- TabBar: Reworked scrolling policy (when ImGuiTabBarFlags_FittingPolicyScroll is set) to
+ teleport the view when aiming at a tab far away the visible section, and otherwise accelerate
+ the scrolling speed to cap the scrolling time to 0.3 seconds.
+- Text: Fixed large Text/TextUnformatted calls not feeding their size into layout when starting
+ below the lower point of the current clipping rectangle. This bug has been there since v1.0!
+ It was hardly noticeable but would affect the scrolling range, which in turn would affect
+ some scrolling request functions when called during the appearing frame of a window.
+- Plot: Fixed divide-by-zero in PlotLines() when passing a count of 1. (#2387) [@Lectem]
+- Log/Capture: Fixed LogXXX functions emitting extraneous leading carriage return.
+- Log/Capture: Fixed an issue when empty string on a new line would not emit a carriage return.
+- Log/Capture: Fixed LogXXX functions 'auto_open_depth' parameter being treated as an absolute
+ tree depth instead of a relative one.
+- Log/Capture: Fixed CollapsingHeader trailing ascii representation being "#" instead of "##".
+- ImFont: Added GetGlyphRangesVietnamese() helper. (#2403)
+- Misc: Asserting in NewFrame() if style.WindowMinSize is zero or smaller than (1.0f,1.0f).
+- Demo: Using GetBackgroundDrawList() and GetForegroundDrawList() in "Custom Rendering" demo.
+- Demo: InputText: Demonstrating use of ImGuiInputTextFlags_CallbackResize. (#2006, #1443, #1008).
+- Examples: GLFW, SDL: Preserve DisplayFramebufferScale when main viewport is minimized.
+ (This is particularly useful for the viewport branch because we are not supporting per-viewport
+ frame-buffer scale. It fixes windows not refreshing when main viewport is minimized.) (#2416)
+- Examples: OpenGL: Fix to be able to run on ES 2.0 / WebGL 1.0. [@rmitton, @gabrielcuvillier]
+- Examples: OpenGL: Fix for OSX not supporting OpenGL 4.5, we don't try to read GL_CLIP_ORIGIN
+ even if the OpenGL headers/loader happens to define the value. (#2366, #2186)
+- Examples: Allegro: Added support for touch events (emulating mouse). (#2219) [@dos1]
+- Examples: DirectX9: Minor changes to match the other DirectX examples more closely. (#2394)
+
+
+-----------------------------------------------------------------------
+ VERSION 1.68 (Released 2019-02-19)
+-----------------------------------------------------------------------
+
+Breaking Changes:
+
+- Removed io.DisplayVisibleMin/DisplayVisibleMax (which were marked obsolete and removed from viewport/docking branch already).
+- Made it illegal/assert when io.DisplayTime == 0.0f (with an exception for the first frame).
+ If for some reason your time step calculation gives you a zero value, replace it with a dummy small value!
+
+Other Changes:
+
- Added .editorconfig file for text editors to standardize using spaces. (#2038) [@kudaba]
+- ImDrawData: Added FramebufferScale field (currently a copy of the value from io.DisplayFramebufferScale).
+ This is to allow render functions being written without pulling any data from ImGuiIO, allowing incoming
+ multi-viewport feature to behave on Retina display and with multiple displays.
+ If you are not using a custom binding, please update your render function code ahead of time,
+ and use draw_data->FramebufferScale instead of io.DisplayFramebufferScale. (#2306, #1676)
+- Added IsItemActivated() as an extension to the IsItemDeactivated/IsItemDeactivatedAfterEdit functions
+ which are useful to implement variety of undo patterns. (#820, #956, #1875)
- InputText: Fixed a bug where ESCAPE would not restore the initial value in all situations. (#2321) [@relick]
- InputText: Fixed a bug where ESCAPE would be first captured by the Keyboard Navigation code. (#2321, #787)
+- InputText: Fixed redo buffer exhaustion handling (rare) which could corrupt the undo character buffer. (#2333)
+ The way the redo/undo buffers work would have made it generally unnoticeable to the user.
- Fixed range-version of PushID() and GetID() not honoring the ### operator to restart from the seed value.
- Fixed CloseCurrentPopup() on a child-menu of a modal incorrectly closing the modal. (#2308)
+- Tabs: Added ImGuiTabBarFlags_TabListPopupButton flag to show a popup button on manual tab bars. (#261, #351)
+- Tabs: Removed ImGuiTabBarFlags_NoTabListPopupButton which was available in 1.67 but actually had zero use.
+- Tabs: Fixed a minor clipping glitch when changing style's FramePadding from frame to frame.
+- Tabs: Fixed border (when enabled) so it is aligned correctly mid-pixel and appears as bright as other borders.
+- Style, Selectable: Added ImGuiStyle::SelectableTextAlign and ImGuiStyleVar_SelectableTextAlign. (#2347) [@haldean]
+- Menus: Tweaked horizontal overlap between parent and child menu (to help convey relative depth)
+ from using style.ItemSpacing.x to style.ItemInnerSpacing.x, the later being expected to be smaller. (#1086)
+- RadioButton: Fixed label horizontal alignment to precisely match Checkbox().
- Window: When resizing from an edge, the border is more visible and better follow the rounded corners.
+- Window: Fixed initial width of collapsed windows not taking account of contents width (broken in 1.67). (#2336, #176)
+- Scrollbar: Fade out and disable interaction when too small, in order to facilitate using the resize grab on very
+ small window, as well as reducing visual noise/overlap.
+- ListBox: Better optimized when clipped / non-visible.
+- InputTextMultiline: Better optimized when clipped / non-visible.
+- Font: Fixed high-level ImGui::CalcTextSize() used by most widgets from erroneously subtracting 1.0f*scale to
+ calculated text width. Among noticeable side-effects, it would make sequences of repeated Text/SameLine calls
+ not align the same as a single call, and create mismatch between high-level size calculation and those performed
+ with the lower-level ImDrawList api. (#792) [@SlNPacifist]
+- Font: Fixed building atlas when specifying duplicate/overlapping ranges within a same font. (#2353, #2233)
- ImDrawList: Fixed AddCircle(), AddCircleFilled() angle step being off, which was visible when drawing a "circle"
with a small number of segments (e.g. an hexagon). (#2287) [@baktery]
- ImGuiTextBuffer: Added append() function (unformatted).
@@ -111,11 +519,20 @@ Other Changes:
- ImFontAtlas: FreeType: Added support for imgui allocators + custom FreeType only SetAllocatorFunctions. (#2285) [@Vuhdo]
- ImFontAtlas: FreeType: Fixed using imgui_freetype.cpp in unity builds. (#2302)
- Demo: Fixed "Log" demo not initializing properly, leading to the first line not showing before a Clear. (#2318) [@bluescan]
+- Demo: Added "Auto-scroll" option in Log/Console demos. (#2300) [@nicolasnoble, @ocornut]
+- Examples: Metal, OpenGL2, OpenGL3, Vulkan: Fixed offsetting of clipping rectangle with ImDrawData::DisplayPos != (0,0)
+ when the display frame-buffer scale scale is not (1,1). While this doesn't make a difference when using master branch,
+ this is effectively fixing support for multi-viewport with Mac Retina Displays on those examples. (#2306) [@rasky, @ocornut]
+ Also using ImDrawData::FramebufferScale instead of io.DisplayFramebufferScale.
+- Examples: Clarified the use the ImDrawData::DisplayPos to offset clipping rectangles.
- Examples: Win32: Using GetForegroundWindow()+IsChild() instead of GetActiveWindow() to be compatible with windows created
in a different thread or parent. (#1951, #2087, #2156, #2232) [many people]
-- Examples: Win32: Added support for XInput games (if ImGuiConfigFlags_NavEnableGamepad is enabled).
+- Examples: SDL: Using the SDL_WINDOW_ALLOW_HIGHDPI flag. (#2306, #1676) [@rasky]
+- Examples: Win32: Added support for XInput gamepads (if ImGuiConfigFlags_NavEnableGamepad is enabled).
- Examples: Win32: Added support for mouse buttons 4 and 5 via WM_XBUTTON* messages. (#2264)
- Examples: DirectX9: Explicitly disable fog (D3DRS_FOGENABLE) before drawing in case user state has it set. (#2288, #2230)
+- Examples: OpenGL2: Added #define GL_SILENCE_DEPRECATION to cope with newer XCode warnings.
+- Examples: OpenGL3: Using GLSL 4.10 shaders for any GLSL version over 410 (e.g. 430, 450). (#2329) [@BrutPitt]
-----------------------------------------------------------------------
@@ -128,7 +545,7 @@ Breaking Changes:
side-effect because the window would have ID zero. In particular it is causing problems in viewport/docking branches.
- Renamed io.ConfigResizeWindowsFromEdges to io.ConfigWindowsResizeFromEdges and removed its [Beta] mark.
The addition of new configuration options in the Docking branch is pushing for a little reorganization of those names.
-- Renamed ImFontAtlas::GlyphRangesBuilder to ImFontGlyphRangesBuilder. Keep redirection typedef (will obsolete).
+- Renamed ImFontAtlas::GlyphRangesBuilder to ImFontGlyphRangesBuilder. Kept redirection typedef (will obsolete).
Other Changes:
@@ -310,29 +727,36 @@ Changes:
Breaking Changes:
-- Style: Renamed ImGuiCol_ModalWindowDarkening to ImGuiCol_ModalWindowDimBg for consistency with other features. Kept redirection enum (will obsolete).
+- Style: Renamed ImGuiCol_ModalWindowDarkening to ImGuiCol_ModalWindowDimBg for consistency with other features.
+ Kept redirection enum (will obsolete).
- Changed ImGui::GetTime() return value from float to double to avoid accumulating floating point imprecision over time.
-- Removed per-window ImGuiWindowFlags_ResizeFromAnySide Beta flag in favor `io.ConfigResizeWindowsFromEdges=true` to enable the feature globally. (#1495)
+- Removed per-window ImGuiWindowFlags_ResizeFromAnySide Beta flag in favor `io.ConfigResizeWindowsFromEdges=true` to
+ enable the feature globally. (#1495)
The feature is not currently enabled by default because it is not satisfying enough, but will eventually be.
-- InputText: Renamed ImGuiTextEditCallback to ImGuiInputTextCallback, ImGuiTextEditCallbackData to ImGuiInputTextCallbackData for consistency.
- Kept redirection types (will obsolete).
-- InputText: Removed ImGuiTextEditCallbackData::ReadOnly since it is a duplication of (ImGuiTextEditCallbackData::Flags & ImGuiInputTextFlags_ReadOnly).
+- InputText: Renamed ImGuiTextEditCallback to ImGuiInputTextCallback, ImGuiTextEditCallbackData to ImGuiInputTextCallbackData
+ for consistency. Kept redirection types (will obsolete).
+- InputText: Removed ImGuiTextEditCallbackData::ReadOnly because it is a duplication of (::Flags & ImGuiInputTextFlags_ReadOnly).
- Renamed IsItemDeactivatedAfterChange() to IsItemDeactivatedAfterEdit() for consistency with new IsItemEdited() API.
Kept redirection function (will obsolete soonish as IsItemDeactivatedAfterChange() is very recent).
-- Renamed io.OptCursorBlink to io.ConfigCursorBlink [-> io.ConfigInputTextCursorBlink in 1.65], io.OptMacOSXBehaviors to io.ConfigMacOSXBehaviors for consistency. (#1427, #473)
+- Renamed io.OptCursorBlink to io.ConfigCursorBlink [-> io.ConfigInputTextCursorBlink in 1.65], io.OptMacOSXBehaviors to
+ io.ConfigMacOSXBehaviors for consistency. (#1427, #473)
- Removed obsolete redirection functions: CollapsingHeader() variation with 2 bools - marked obsolete in v1.49, May 2016.
Other Changes:
- ArrowButton: Fixed to honor PushButtonRepeat() setting (and internals' ImGuiItemFlags_ButtonRepeat).
- ArrowButton: Setup current line text baseline so that ArrowButton() + SameLine() + Text() are aligned properly.
-- Nav: Added a CTRL+TAB window list and changed the highlight system accordingly. The change is motivated by upcoming Docking features. (#787)
+- Nav: Added a CTRL+TAB window list and changed the highlight system accordingly. The change is motivated by upcoming
+ Docking features. (#787)
- Nav: Made CTRL+TAB skip menus + skip the current navigation window if is has the ImGuiWindow_NoNavFocus set. (#787)
- While it was previously possible, you won't be able to CTRL-TAB out and immediately back in a window with the ImGuiWindow_NoNavFocus flag.
+ While it was previously possible, you won't be able to CTRL-TAB out and immediately back in a window with the
+ ImGuiWindow_NoNavFocus flag.
- Window: Allow menu and popups windows from ignoring the style.WindowMinSize values so short menus/popups are not padded. (#1909)
-- Window: Added global io.ConfigResizeWindowsFromEdges option to enable resizing windows from their edges and from the lower-left corner. (#1495)
+- Window: Added global io.ConfigResizeWindowsFromEdges option to enable resizing windows from their edges and from
+ the lower-left corner. (#1495)
- Window: Collapse button shows hovering highlight + clicking and dragging on it allows to drag the window as well.
-- Added IsItemEdited() to query if the last item modified its value (or was pressed). This is equivalent to the bool returned by most widgets.
+- Added IsItemEdited() to query if the last item modified its value (or was pressed). This is equivalent to the bool
+ returned by most widgets.
It is useful in some situation e.g. using InputText() with ImGuiInputTextFlags_EnterReturnsTrue. (#2034)
- InputText: Added support for buffer size/capacity changes via the ImGuiInputTextFlags_CallbackResize flag. (#2006, #1443, #1008).
- InputText: Fixed not tracking the cursor horizontally when modifying the text buffer through a callback.
@@ -395,11 +819,14 @@ Other Changes:
Breaking Changes:
-- TreeNodeEx(): The helper ImGuiTreeNodeFlags_CollapsingHeader flag now include ImGuiTreeNodeFlags_NoTreePushOnOpen. The flag was already set by CollapsingHeader().
- The only difference is if you were using TreeNodeEx() manually with ImGuiTreeNodeFlags_CollapsingHeader and without ImGuiTreeNodeFlags_NoTreePushOnOpen.
- In this case you can remove the ImGuiTreeNodeFlags_NoTreePushOnOpen flag from your call (ImGuiTreeNodeFlags_CollapsingHeader & ~ImGuiTreeNodeFlags_NoTreePushOnOpen). (#1864)
+- TreeNodeEx(): The helper ImGuiTreeNodeFlags_CollapsingHeader flag now include ImGuiTreeNodeFlags_NoTreePushOnOpen.
+ The flag was already set by CollapsingHeader().
+ The only difference is if you were using TreeNodeEx() manually with ImGuiTreeNodeFlags_CollapsingHeader and without
+ ImGuiTreeNodeFlags_NoTreePushOnOpen. In this case you can remove the ImGuiTreeNodeFlags_NoTreePushOnOpen flag from
+ your call (ImGuiTreeNodeFlags_CollapsingHeader & ~ImGuiTreeNodeFlags_NoTreePushOnOpen). (#1864)
This also apply if you were using internal's TreeNodeBehavior() with the ImGuiTreeNodeFlags_CollapsingHeader flag directly.
-- ImFontAtlas: Renamed GetGlyphRangesChinese() to GetGlyphRangesChineseFull() to distinguish new smaller variants and discourage using the full set. (#1859)
+- ImFontAtlas: Renamed GetGlyphRangesChinese() to GetGlyphRangesChineseFull() to distinguish new smaller variants and
+ discourage using the full set. (#1859)
Other Changes:
@@ -412,12 +839,13 @@ Other Changes:
before: imgui_impl_glfw_vulkan.cpp --> after: imgui_impl_glfw.cpp + imgui_impl_vulkan.cpp
before: imgui_impl_sdl_gl3.cpp --> after: imgui_impl_sdl2.cpp + imgui_impl_opengl2.cpp
before: imgui_impl_sdl_gl3.cpp --> after: imgui_impl_sdl2.cpp + imgui_impl_opengl3.cpp etc.
- - The idea is what we can now easily combine and maintain back-ends and reduce code redundancy. Individual files are smaller and more reusable.
- Integration of imgui into a new/custom engine may also be easier as there is less overlap between "windowing / inputs" and "rendering" code,
- so you may study or grab one half of the code and not the other.
- - This change was motivated by the fact that adding support for the upcoming multi-viewport feature requires more work from the Platform and Renderer
- back-ends, and the amount of redundancy across files was becoming too difficult to maintain. If you use default back-ends, you'll benefit from an
- easy update path to support multi-viewports later (for future ImGui 1.7x).
+ - The idea is what we can now easily combine and maintain back-ends and reduce code redundancy. Individual files are
+ smaller and more reusable. Integration of imgui into a new/custom engine may also be easier as there is less overlap
+ between "windowing / inputs" and "rendering" code, so you may study or grab one half of the code and not the other.
+ - This change was motivated by the fact that adding support for the upcoming multi-viewport feature requires more work
+ from the Platform and Renderer back-ends, and the amount of redundancy across files was becoming too difficult to
+ maintain. If you use default back-ends, you'll benefit from an easy update path to support multi-viewports later
+ (for future ImGui 1.7x).
- This is not strictly a breaking change if you keep your old bindings, but when you'll want to fully update your bindings,
expect to have to reshuffle a few things.
- Each example still has its own main.cpp which you may refer you to understand how to initialize and glue everything together.
@@ -430,26 +858,36 @@ Other Changes:
- Nav: Added support for PageUp/PageDown (explorer-style: first aim at bottom/top most item, when scroll a page worth of contents). (#787)
- Nav: To keep the navigated item in view we also attempt to scroll the parent window as well as the current window. (#787)
- ColorEdit3, ColorEdit4, ColorButton: Added ImGuiColorEditFlags_NoDragDrop flag to disable ColorEditX as drag target and ColorButton as drag source. (#1826)
-- BeginDragDropSource(): Offset tooltip position so it is off the mouse cursor, but also closer to it than regular tooltips, and not clamped by viewport. (#1739)
-- BeginDragDropTarget(): Added ImGuiDragDropFlags_AcceptNoPreviewTooltip flag to request hiding the drag source tooltip from the target site. (#143)
-- BeginCombo(), BeginMainMenuBar(), BeginChildFrame(): Temporary style modification are restored at the end of BeginXXX instead of EndXXX, to not affect tooltips and child windows.
+- BeginDragDropSource(): Offset tooltip position so it is off the mouse cursor, but also closer to it than regular tooltips,
+ and not clamped by viewport. (#1739)
+- BeginDragDropTarget(): Added ImGuiDragDropFlags_AcceptNoPreviewTooltip flag to request hiding the drag source tooltip
+ from the target site. (#143)
+- BeginCombo(), BeginMainMenuBar(), BeginChildFrame(): Temporary style modification are restored at the end of BeginXXX
+ instead of EndXXX, to not affect tooltips and child windows.
- Popup: Improved handling of (erroneously) repeating calls to OpenPopup() to not close the popup's child popups. (#1497, #1533, #1865).
- InputTextMultiline(): Fixed double navigation highlight when scrollbar is active. (#787)
-- InputText(): Fixed Undo corruption after pasting large amount of text (Redo will still fail when undo buffers are exhausted, but text won't be corrupted).
+- InputText(): Fixed Undo corruption after pasting large amount of text (Redo will still fail when undo buffers are exhausted,
+ but text won't be corrupted).
- SliderFloat(): When using keyboard/gamepad and a zero precision format string (e.g. "%.0f"), always step in integer units. (#1866)
-- ImFontConfig: Added GlyphMinAdvanceX/GlyphMaxAdvanceX settings useful to make a font appears monospaced, particularly useful for icon fonts. (#1869)
-- ImFontAtlas: Added GetGlyphRangesChineseSimplifiedCommon() helper that returns a list of ~2500 most common Simplified Chinese characters. (#1859) [@JX-Master, @ocornut]
+- ImFontConfig: Added GlyphMinAdvanceX/GlyphMaxAdvanceX settings useful to make a font appears monospaced, particularly useful
+ for icon fonts. (#1869)
+- ImFontAtlas: Added GetGlyphRangesChineseSimplifiedCommon() helper that returns a list of ~2500 most common Simplified Chinese
+ characters. (#1859) [@JX-Master, @ocornut]
- Examples: OSX: Added imgui_impl_osx.mm binding to be used along with e.g. imgui_impl_opengl2.cpp. (#281, #1870) [@pagghiu, @itamago, @ocornut]
- Examples: GLFW: Made it possible to Shutdown/Init the backend again (by reseting the time storage properly). (#1827) [@ice1000]
- Examples: Win32: Fixed handling of mouse wheel messages to support sub-unit scrolling messages (typically sent by track-pads). (#1874) [@zx64]
- Examples: SDL+Vulkan: Added SDL+Vulkan example.
- Examples: Allegro5: Added support for ImGuiConfigFlags_NoMouseCursorChange flag. Added clipboard support.
-- Examples: Allegro5: Unindexing buffers ourselves as Allegro indexed drawing primitives are buggy in the DirectX9 back-end (will be fixed in Allegro 5.2.5+).
+- Examples: Allegro5: Unindexing buffers ourselves as Allegro indexed drawing primitives are buggy in the DirectX9 back-end
+ (will be fixed in Allegro 5.2.5+).
- Examples: DirectX12: Moved the ID3D12GraphicsCommandList* parameter from ImGui_ImplDX12_NewFrame() to ImGui_ImplDX12_RenderDrawData() which makes a lots more sense. (#301)
-- Examples: Vulkan: Reordered parameters ImGui_ImplVulkan_RenderDrawData() to be consistent with other bindings, a good occasion since we refactored the code.
+- Examples: Vulkan: Reordered parameters ImGui_ImplVulkan_RenderDrawData() to be consistent with other bindings,
+ a good occasion since we refactored the code.
- Examples: FreeGLUT: Added FreeGLUT bindings. Added FreeGLUT+OpenGL2 example. (#801)
-- Examples: The functions in imgui_impl_xxx.cpp are prefixed with IMGUI_IMPL_API (which defaults to IMGUI_API) to facilitate some uses. (#1888)
-- Examples: Fixed bindings to use ImGuiMouseCursor_COUNT instead of old name ImGuiMouseCursor_Count_ so they can compile with IMGUI_DISABLE_OBSOLETE_FUNCTIONS. (#1887)
+- Examples: The functions in imgui_impl_xxx.cpp are prefixed with IMGUI_IMPL_API (which defaults to IMGUI_API) to facilitate
+ some uses. (#1888)
+- Examples: Fixed bindings to use ImGuiMouseCursor_COUNT instead of old name ImGuiMouseCursor_Count_ so they can compile
+ with IMGUI_DISABLE_OBSOLETE_FUNCTIONS. (#1887)
- Misc: Updated stb_textedit from 1.09 + patches to 1.12 + minor patches.
- Internals: PushItemFlag() flags are inherited by BeginChild().
@@ -460,41 +898,56 @@ Other Changes:
Breaking Changes:
-- DragInt(): The default compile-time format string has been changed from "%.0f" to "%d", as we are not using integers internally any more.
- If you used DragInt() with custom format strings, make sure you change them to use %d or an integer-compatible format.
- To honor backward-compatibility, the DragInt() code will currently parse and modify format strings to replace %*f with %d, giving time to users to upgrade their code.
- If you have IMGUI_DISABLE_OBSOLETE_FUNCTIONS enabled, the code will instead assert! You may run a reg-exp search on your codebase for e.g. "DragInt.*%f" to you find them.
-- InputFloat(): Obsoleted InputFloat() functions taking an optional "int decimal_precision" in favor of an equivalent and more flexible "const char* format",
- consistent with other functions. Kept redirection functions (will obsolete).
-- Misc: IM_DELETE() helper function added in 1.60 doesn't set the input pointer to NULL, more consistent with standard expectation and allows passing r-values.
+- DragInt(): The default compile-time format string has been changed from "%.0f" to "%d", as we are not using integers internally
+ any more. If you used DragInt() with custom format strings, make sure you change them to use %d or an integer-compatible format.
+ To honor backward-compatibility, the DragInt() code will currently parse and modify format strings to replace %*f with %d,
+ giving time to users to upgrade their code.
+ If you have IMGUI_DISABLE_OBSOLETE_FUNCTIONS enabled, the code will instead assert! You may run a reg-exp search on your
+ codebase for e.g. "DragInt.*%f" to you find them.
+- InputFloat(): Obsoleted InputFloat() functions taking an optional "int decimal_precision" in favor of an equivalent and more
+ flexible "const char* format", consistent with other functions. Kept redirection functions (will obsolete).
+- Misc: IM_DELETE() helper function added in 1.60 doesn't set the input pointer to NULL, more consistent with standard
+ expectation and allows passing r-values.
Other Changes:
- Added DragScalar, DragScalarN: supports signed/unsigned, 32/64 bits, float/double data types. (#643, #320, #708, #1011)
- Added InputScalar, InputScalarN: supports signed/unsigned, 32/64 bits, float/double data types. (#643, #320, #708, #1011)
- Added SliderScalar, SliderScalarN: supports signed/unsigned, 32/64 bits, float/double data types. (#643, #320, #708, #1011)
-- Window: Fixed pop-ups/tooltips/menus not honoring style.DisplaySafeAreaPadding as well as it should have (part of menus displayed outside the safe area, etc.).
+- Window: Fixed pop-ups/tooltips/menus not honoring style.DisplaySafeAreaPadding as well as it should have (part of menus
+ displayed outside the safe area, etc.).
- Window: Fixed windows using the ImGuiWindowFlags_NoSavedSettings flag from not using the same default position as other windows. (#1760)
- Window: Relaxed the internal stack size checker to allow Push/Begin/Pop/.../End patterns to be used with PushStyleColor, PushStyleVar, PushFont without causing a false positive assert. (#1767)
- Window: Fixed the default proportional item width lagging by one frame on resize.
-- Columns: Fixed a bug introduced in 1.51 where columns would affect the contents size of their container, often creating feedback loops when ImGuiWindowFlags_AlwaysAutoResize was used. (#1760)
+- Columns: Fixed a bug introduced in 1.51 where columns would affect the contents size of their container, often creating
+ feedback loops when ImGuiWindowFlags_AlwaysAutoResize was used. (#1760)
- Settings: Fixed saving an empty .ini file if CreateContext/DestroyContext are called without a single call to NewFrame(). (#1741)
-- Settings: Added LoadIniSettingsFromDisk(), LoadIniSettingsFromMemory(), SaveIniSettingsToDisk(), SaveIniSettingsToMemory() to manually load/save .ini settings. (#923, #993)
-- Settings: Added io.WantSaveIniSettings flag, which is set to notify the application that e.g. SaveIniSettingsToMemory() should be called. (#923, #993)
-- Scrolling: Fixed a case where using SetScrollHere(1.0f) at the bottom of a window on the same frame the window height has been growing would have the scroll clamped using the previous height. (#1804)
-- MenuBar: Made BeginMainMenuBar() honor style.DisplaySafeAreaPadding so the text can be made visible on TV settings that don't display all pixels. (#1439) [@dougbinks]
+- Settings: Added LoadIniSettingsFromDisk(), LoadIniSettingsFromMemory(), SaveIniSettingsToDisk(), SaveIniSettingsToMemory()
+ to manually load/save .ini settings. (#923, #993)
+- Settings: Added io.WantSaveIniSettings flag, which is set to notify the application that e.g. SaveIniSettingsToMemory()
+ should be called. (#923, #993)
+- Scrolling: Fixed a case where using SetScrollHere(1.0f) at the bottom of a window on the same frame the window height
+ has been growing would have the scroll clamped using the previous height. (#1804)
+- MenuBar: Made BeginMainMenuBar() honor style.DisplaySafeAreaPadding so the text can be made visible on TV settings that
+ don't display all pixels. (#1439) [@dougbinks]
- InputText: On Mac OS X, filter out characters when the CMD modifier is held. (#1747) [@sivu]
- InputText: On Mac OS X, support CMD+SHIFT+Z for Redo. CMD+Y is also supported as major apps seems to default to support both. (#1765) [@lfnoise]
- InputText: Fixed returning true when edition is cancelled with ESC and the current buffer matches the initial value.
-- InputFloat,InputFloat2,InputFloat3,InputFloat4: Added variations taking a more flexible and consistent optional "const char* format" parameter instead of "int decimal_precision".
- This allow using custom formats to display values in scientific notation, and is generally more consistent with other API. Obsoleted functions using the optional "int decimal_precision" parameter. (#648)
-- DragFloat, DragInt: Cancel mouse tweak when current value is initially past the min/max boundaries and mouse is pushing in the same direction (keyboard/gamepad version already did this).
+- InputFloat,InputFloat2,InputFloat3,InputFloat4: Added variations taking a more flexible and consistent optional
+ "const char* format" parameter instead of "int decimal_precision". This allow using custom formats to display values
+ in scientific notation, and is generally more consistent with other API.
+ Obsoleted functions using the optional "int decimal_precision" parameter. (#648, #712)
+- DragFloat, DragInt: Cancel mouse tweak when current value is initially past the min/max boundaries and mouse is pushing
+ in the same direction (keyboard/gamepad version already did this).
- DragFloat, DragInt: Honor natural type limits (e.g. INT_MAX, FLT_MAX) instead of wrapping around. (#708, #320)
- DragFloat, SliderFloat: Fixes to allow input of scientific notation numbers when using CTRL+Click to input the value. (~#648, #1011)
-- DragFloat, SliderFloat: Rounding-on-write uses the provided format string instead of parsing the precision from the string, which allows for finer uses of %e %g etc. (#648, #642)
-- DragFloat: Improved computation when using the power curve. Improved lost of input precision with very small steps. Added an assert than power-curve requires a min/max range. (~#642)
+- DragFloat, SliderFloat: Rounding-on-write uses the provided format string instead of parsing the precision from the string,
+ which allows for finer uses of %e %g etc. (#648, #642)
+- DragFloat: Improved computation when using the power curve. Improved lost of input precision with very small steps.
+ Added an assert than power-curve requires a min/max range. (~#642)
- DragFloat: The 'power' parameter is only honored if the min/max parameter are also setup.
-- DragInt, SliderInt: Fixed handling of large integers (we previously passed data around internally as float, which reduced the range of valid integers).
+- DragInt, SliderInt: Fixed handling of large integers (we previously passed data around internally as float, which reduced
+ the range of valid integers).
- ColorEdit: Fixed not being able to pass the ImGuiColorEditFlags_NoAlpha or ImGuiColorEditFlags_HDR flags to SetColorEditOptions().
- Nav: Fixed hovering a Selectable() with the mouse so that it update the navigation cursor (as it happened in the pre-1.60 navigation branch). (#787)
- Style: Changed default style.DisplaySafeAreaPadding values from (4,4) to (3,3) so it is smaller than FramePadding and has no effect on main menu bar on a computer. (#1439)
@@ -834,7 +1287,7 @@ Breaking Changes:
- Removed `IsItemRectHovered()`, `IsWindowRectHovered()` recently introduced in 1.51 which were merely the more consistent/correct names for the above functions which are now obsolete anyway. (#1382)
- Changed `IsWindowHovered()` default parameters behavior to return false if an item is active in another window (e.g. click-dragging item from another window to this window). You can use the newly introduced IsWindowHovered() flags to requests this specific behavior if you need it. (#1382)
- Renamed imconfig.h's `IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS`/`IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCS` to `IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS`/`IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS` for consistency.
-- Renamed ImFont::Glyph to ImFontGlyph. Keep redirection typedef (will obsolete).
+- Renamed ImFont::Glyph to ImFontGlyph. Kept redirection typedef (will obsolete).
Other Changes:
@@ -1231,6 +1684,469 @@ Other Changes:
- Various extra comments and clarification in the code.
- Various other fixes and optimizations.
+
+-----------------------------------------------------------------------
+ VERSION 1.47 (2015-12-25)
+-----------------------------------------------------------------------
+
+Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.47
+
+Changes:
+
+- Rebranding "ImGui" -> "dear imgui" as an optional first name to reduce ambiguity with IMGUI term. (#21)
+- Added ProgressBar(). (#333)
+- InputText(): Added ImGuiInputTextFlags_Password mode: hide display, disable logging/copying to clipboard. (#237, #363, #374)
+- Added GetColorU32() helper to retrieve color given enum with global alpha and extra applied.
+- Added ImGuiIO::ClearInputCharacters() superfluous helper.
+- Fixed ImDrawList draw command merging bug where using PopClipRect() along with PushTextureID()/PopTextureID() functions
+ would occasionally restore an incorrect clipping rectangle.
+- Fixed ImDrawList draw command merging so PushTextureID(XXX)/PopTextureID()/PushTextureID(XXX) sequence are now properly merged.
+- Fixed large popups positioning issues when their contents on either axis is larger than DisplaySize,
+ and WindowPadding < DisplaySafeAreaPadding.
+- Fixed border rendering in various situations when using non-pixel aligned glyphs.
+- Fixed border rendering of windows to always contain the border within the window.
+- Fixed Shutdown() leaking font atlas data if NewFrame() was never called. (#396, #303)
+- Fixed int>void\* warnings for 64-bits architectures with fancy warnings enabled.
+- Renamed the dubious Color() helpers to ValueColor() - dangerously named, rarely used and probably to be made obsolete.
+- InputText(): Fixed and better handling of using keyboard while mouse button if being held and dragging. (#429)
+- InputText(): Replace OS IME (Input Method Editor) cursor on top-left when we are not text editing.
+- TreeNode(), CollapsingHeader(), Bullet(), BulletText(): various sizing and layout fixes to better support laying out
+ multiple item with different height on same line. (#414, #282)
+- Begin(): Initial window creation with ImGuiWindowFlags_NoBringToFrontOnFocus flag pushes it at the front of global window list.
+- BeginPopupContextWindow() and BeginPopupContextVoid() reopen window on subsequent click. (#439)
+- ColorEdit4(): Fixed broken tooltip on hovering the color button. (actually fixes #373, #380)
+- ImageButton(): uses FrameRounding up to a maximum of available framing size. (#394)
+- Columns: Fixed bug with indentation within columns, also making code a bit shorter/faster. (#414, #125)
+- Columns: Columns set with no implicit id include the columns count within the id to reduce collisions. (#125)
+- Columns: Removed one unnecessary allocation when columns are not used by a window. (#125)
+- ImFontAtlas: Tweaked GetGlyphRangesJapanese() so it is easier to modify.
+- ImFontAtlas: Updated stb_rect_pack.h to 0.08.
+- Metrics: Fixed computing ImDrawCmd bounding box when the draw buffer have been unindexed.
+- Demo: Added a simple "Property Editor" demo applet. (#125, #414)
+- Demo: Fixed assertion in "Custom Rendering" demo when holding both mouse buttons. (#393)
+- Demo: Lots of extra comments, fixes.
+- Demo: Tweaks to Style Editor.
+- Examples: Not clearing input data/tex data in atlas (will be required for dynamic atlas anyway).
+- Examples: Added /Zi (output debug information) to Win32 batch files.
+- Examples: Various fixes for resizing window and recreating graphic context.
+- Examples: OpenGL2/3: Save/restore viewport as part of default render function. (#392, #441).
+- Examples; OpenGL3: Fixed gl3w.c for Linux when compiled with a C++ compiler. (#411)
+- Examples: DirectX: Removed assumption about Unicode build in example main.cpp. (#399)
+- Examples: DirectX10: Added DirectX10 example. (#424)
+- Examples: DirectX11: Downgraded requirement from shader model 5.0 to 4.0. (#420)
+- Examples: DirectX11: Removed Debug flag from graphics context. (#415)
+- Examples: Added SDL+OpenGL3 example. (#356)
+
+
+-----------------------------------------------------------------------
+ VERSION 1.46 (2015-10-18)
+-----------------------------------------------------------------------
+
+Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.46
+
+Changes:
+
+- Begin*(): added ImGuiWindowFlags_NoFocusOnAppearing flag. (#314)
+- Begin*(): added ImGuiWindowFlags_NoBringToFrontOnFocus flag.
+- Added GetDrawData() alternative to setting a Render function pointer in ImGuiIO structure.
+- Added SetClipboardText(), GetClipboardText() helper shortcuts that user code can call directly without reading
+ from the ImGuiIO structure (to match MemAlloc/MemFree)
+- Fixed handling of malformed UTF-8 at the end of a non-zero terminated string range.
+- Fixed mouse click detection when passing DeltaTime 0.0. (#338)
+- Fixed IsKeyReleased() and IsMouseReleased() returning true on the first frame.
+- Fixed using SetNextWindow\* functions on Modal windows with a ImGuiSetCond_Appearing condition. (#377)
+- IsMouseHoveringRect(): Added 'bool clip' parameter to disable clipping provided rectangle. (#316)
+- InputText(): added ImGuiInputTextFlags_ReadOnly flag. (#211)
+- InputText(): lose cursor/undo-stack when reactivating focus is buffer has changed size.
+- InputText(): fixed ignoring text inputs when ALT or ALTGR are pressed. (#334)
+- InputText(): fixed mouse-dragging not tracking the cursor when text doesn't fit. (#339)
+- InputText(): fixed cursor pixel-perfect alignment when horizontally scrolling.
+- InputText(): fixed crash when passing a buf_size==0 (which can be of use for read-only selectable text boxes). (#360)
+- InputFloat() fixed explicit precision modifier, both display and input were broken.
+- PlotHistogram(): improved rendering of histogram with a lot of values.
+- Dummy(): creates an item so functions such as IsItemHovered() can be used.
+- BeginChildFrame() helper: added the extra_flags parameter.
+- Scrollbar: fixed rounding of background + child window consistenly have ChildWindowBg color under ScrollbarBg fill. (#355).
+- Scrollbar: background color less translucent in default style so it works better when changing background color.
+- Scrollbar: fixed minor rendering offset when borders are enabled. (#365)
+- ImDrawList: fixed 1 leak per ImDrawList using the ChannelsSplit() API (via Columns). (#318)
+- ImDrawList: fixed rectangle rendering glitches with width/height <= 1/2 and rounding enabled.
+- ImDrawList: AddImage() uv parameters default to (0,0) and (1,1).
+- ImFontAtlas: Added TexDesiredWidth and tweaked default cheapo best-width choice. (#327)
+- ImFontAtlas: Added GetGlyphRangesKorean() helper to retrieve unicode ranges for Korean. (#348)
+- ImGuiTextFilter::Draw() helper return bool and build when filter is modified.
+- ImGuiTextBuffer: added c_str() helper.
+- ColorEdit4(): fixed hovering the color button always showing 1.0 alpha. (#373)
+- ColorConvertFloat4ToU32() round the floats instead of truncating them.
+- Window: Fixed window lower-right clipping limit so it plays more friendly with both OpenGL and DirectX coordinates.
+- Internal: Extracted a EndFrame() function out of Render() but kept it internal/private + clarified some asserts. (#335)
+- Internal: Added missing IMGUI_API definitions in imgui_internal.h (#326)
+- Internal: ImLoadFileToMemory() return void\* instead of taking void*\* + allow optional int\* file_size.
+- Demo: Horizontal scrollbar demo allows to enable simultanaeous scrollbars on both axises.
+- Tools: binary_to_compressed_c.cpp: added -nocompress option.
+- Examples: Added example for the Marmalade platform.
+- Examples: Added batch files to build Windows examples with VS.
+- Examples: OpenGL3: Saving/restoring more GL state correctly. (#347)
+- Examples: OpenGL2/3: Added msys2/mingw64 target to Makefiles.
+
+
+-----------------------------------------------------------------------
+ VERSION 1.45 (2015-09-01)
+-----------------------------------------------------------------------
+
+Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.45
+
+Breaking Changes:
+
+- With the addition of better horizontal scrolling primitives I had to make some consistency fixes.
+ `GetCursorPos()` `SetCursorPos()` `GetContentRegionMax()` `GetWindowContentRegionMin()` `GetWindowContentRegionMax()`
+ are now incorporating the scrolling amount. They were incorrectly not incorporating this amount previously.
+ It PROBABLY shouldn't break anything, but that depends on how you used them. Namely:
+ - If you always used SetCursorPos() with values relative to GetCursorPos() there shouldn't be a problem.
+ However if you used absolute coordinates, note that SetCursorPosY(100.0f) will put you at +100 from the initial Y position (which may be scrolled out of the view), NOT at +100 from the window top border. Since there wasn't any official scrolling value on X axis (past just manually moving the cursor) this can only affect you if you used to set absolute coordinates on the Y axis which is hopefully rare/unlikely, and trivial to fix.
+ - The value of GetWindowContentRegionMax() isn't necessarily close to GetWindowWidth() if horizontally scrolling.
+ Previously they were roughly interchangeable (roughly because the content region exclude window padding).
+
+Other Changes:
+
+- Added Horizontal Scrollbar via ImGuiWindowFlags_HorizontalScroll (#246).
+- Added GetScrollX(), GetScrollX(), GetScrollMaxX() apis (#246).
+- Added SetNextWindowContentSize(), SetNextWindowContentWidth() to explicitly set the content size of a window, which
+ define the range of scrollbar. When set explicitly it also define the base value from which widget width are derived.
+- Added IO.WantTextInput telling when ImGui is expecting text input, so that e.g. OS on-screen keyboard can be enabled.
+- Added printf attribute to printf-like text formatting functions (Clang/GCC).
+- Added GetMousePosOnOpeningCurrentPopup() helper.
+- Added GetContentRegionAvailWidth() helper.
+- Malformed UTF-8 data don't terminate string, output 0xFFFD instead (#307).
+- ImDrawList: Added AddBezierCurve(), PathBezierCurveTo() API for cubic bezier curves (#311).
+- ImDrawList: Allow to override ImDrawIdx type (#292).
+- ImDrawList: Added an assert on overflowing index value (#292).
+- ImDrawList: Fixed issues with channels split/merge. Now functional without manually adding a draw cmd. Added comments.
+- ImDrawData: Added ScaleClipRects() helper useful when rendering scaled. (#287).
+- Fixed Bullet() inconsistent layout behaviour when clipped.
+- Fixed IsWindowHovered() not taking account of window hoverability (may be disabled because of a popup).
+- Fixed InvisibleButton() not honoring negative size consistently with other widgets that do so.
+- Fixed OpenPopup() accessing current window, effectively opening "Debug" when called from an empty window stack.
+- TreeNode(): Fixed IsItemHovered() result being inconsistent with interaction visuals (#282).
+- TreeNode(): Fixed mouse interaction padding past the node label being accounted for in layout (#282).
+- BeginChild(): Passing a ImGuiWindowFlags_NoMove inhibits moving parent window from this child.
+- BeginChild() fixed missing rounding for child sizes which leaked into layout and have items misaligned.
+- Begin(): Removed default name = "Debug" parameter. We already have a "Debug" window pushed to the stack in the first place so it's not really a useful default.
+- Begin(): Minor fixes with windows main clipping rectangle (e.g. child window with border).
+- Begin(): Window flags are only read on the first call of the frame. Subsequent calls ignore flags, which allows appending to a window without worryin about flags.
+- InputText(): ignore character input when ctrl/alt are held. (Normally those text input are ignored by most wrappers.) (#279).
+- Demo: Fixed incorrectly formed string passed to Combo (#298).
+- Demo: Added simple Log demo.
+- Demo: Added horizontal scrolling example + enabled in console, log and child examples (#246).
+- Style: made scrollbars rounded by default. Because nice. Minor menu bar background alpha tweak. (#246)
+- Metrics: display indices along with triangles count (#299) and some internal state.
+- ImGuiTextFilter::PassFilter() supports string range. Added [] helper to ImGuiTextBuffer.
+- ImGuiTextFilter::Draw() default parameter width=0.0f for no override, allow override with negative values.
+- Examples: OpenGL2/OpenGL3: fix for retina displays. Default font current lack crispness.
+- Examples: OpenGL2/OpenGL3: save/restore more GL state correctly.
+- Examples: DirectX9/DirectX11: resizing buffers dynamically (#299).
+- Examples: DirectX9/DirectX11: added missing middle mouse button to Windows event handler.
+- Examples: DirectX11: fix for Visual Studio 2015 presumably shipping with an updated version of DX11.
+- Examples: iOS: fixed missing files in project.
+
+
+-----------------------------------------------------------------------
+ VERSION 1.44 (2015-08-08)
+-----------------------------------------------------------------------
+
+Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.44
+
+Breaking Changes:
+
+- imgui.cpp has been split intro extra files: imgui_demo.cpp, imgui_draw.cpp, imgui_internal.h.
+ Add the two extra .cpp to your project or #include them from another .cpp file. (#219)
+
+Other Changes:
+
+- Internal data structure and several useful functions are now exposed in imgui_internal.h. This should make it easier
+ and more natural to extend ImGui. However please note that none of the content in imgui_internal.h is guaranteed
+ for forward-compatibility and code using those types/functions may occasionally break. (#219)
+- All sample code is in imgui_demo.cpp. Please keep this file in your project and consider allowing your code to call
+ the ShowTestWindow() function as de-facto guide to ImGui features. It will be stripped out by the linker when unused.
+- Added GetContentRegionAvail() helper (basically GetContentRegionMax() - GetCursorPos()).
+- Added ImGuiWindowFlags_NoInputs for totally input-passthru window.
+- Button(): honor negative size consistently with other widgets that do so (width -100 to align the button 100 pixels
+ before the right-most position of the contents region).
+- InputTextMultiline(): honor negative size consistently with other widgets that do so.
+- Combo() clamp popup to lower edge of visible area.
+- InputInt(): value doesn't pass through an int>float>int casting chain, fix handling lost of precision with "large" integer.
+- InputInt() allow hexadecimal input (awkwardly via ImGuiInputTextFlags_CharsHexadecimal but we will allow format
+ string in InputInt* later).
+- Checkbox(), RadioButton(): fixed scaling of checkbox and radio button for the filling of "active" visual.
+- Columns: never assume horizontal space for scrollbar if NoScrollbar flag is explicitly set.
+- Slider: fixed using FramePadding between frame and grab visual. Scaling that spacing would look odd.
+- Fixed lower-right resize grip hit box not scaling along with its rendered size (#287)
+- ImDrawList: Fixed angles in ImDrawList::PathArcTo(), PathArcToFast() (v1.43) being off by an extra PI for no reason.
+- ImDrawList: Added ImDrawList::AddText() shorthand helper.
+- ImDrawList: Add missing support for anti-aliased thick-lines (#133, also ref #288)
+- ImFontAtlas: Added AddFontFromMemoryCompressedBase85TTF() to load base85 encoded font string. Default font encoded
+ as base85 saves ~100 lines / 26 KB of source code. Added base85 output to the binary_to_compressed_c tool.
+- Build fix for MinGW (#276).
+- Examples: OpenGL3: Fixed running on script core profiles for OSX (#277).
+- Examples: OpenGL3: Simplified code using glBufferData for vertices as well (#277, #278)
+- Examples: DirectX11: Clear font texture view to ensure Release() doesn't get called twice (#290).
+- Updated to stb_truetype 1.07 (back to vanilla version as our minor changes are now in master & fix unlikely assert
+ with odd fonts (#280)
+
+
+-----------------------------------------------------------------------
+ VERSION 1.43 (2015-07-17)
+-----------------------------------------------------------------------
+
+Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.43
+
+Breaking Changes:
+
+- This is a rather important release and we unfortunately had to break the rendering API.
+ ImGui now requires you to render indexed vertices instead of non-indexed ones. The fix should be very easy.
+ Sorry for that! This change is saving a fair amount of CPU/GPU and enables us to get anti-aliasing for a marginal cost.
+ Each ImDrawList now contains both a vertex buffer and an index buffer. For each command, render ElemCount/3 triangles
+ using indices from the index buffer.
+- If you are using a vanilla copy of one of the imgui_impl_XXXX.cpp provided in the example, you just need to update
+ your copy and you can ignore the rest.
+- The signature of the io.RenderDrawListsFn handler has changed
+ From: ImGui_XXXX_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count)
+ To: ImGui_XXXX_RenderDrawLists(ImDrawData* draw_data)
+ With: argument 'cmd_lists' -> 'draw_data->CmdLists'
+ argument 'cmd_lists_count' -> 'draw_data->CmdListsCount'
+ ImDrawList 'commands' -> 'CmdBuffer'
+ ImDrawList 'vtx_buffer' -> 'VtxBuffer'
+ ImDrawList n/a -> 'IdxBuffer' (new)
+ ImDrawCmd 'vtx_count' -> 'ElemCount'
+ ImDrawCmd 'clip_rect' -> 'ClipRect'
+ ImDrawCmd 'user_callback' -> 'UserCallback'
+ ImDrawCmd 'texture_id' -> 'TextureId'
+- If you REALLY cannot render indexed primitives, you can call the draw_data->DeIndexAllBuffers() method to de-index
+ the buffers. This is slow and a waste of CPU/GPU. Prefer using indexed rendering!
+ Refer to code in the examples/ folder or ask on the GitHub if you are unsure of how to upgrade. Please upgrade!
+
+Other Changes:
+
+- Added anti-aliasing on lines and shapes based on primitives by @MikkoMononen (#133).
+ Between the use of indexed-rendering and the fact that the entire rendering codebase has been optimized and massaged
+ enough, with anti-aliasing enabled ImGui 1.43 is now running FASTER than 1.41.
+ Made some extra effort in making the code run faster in your typical Debug build.
+- Anti-aliasing can be disabled in the ImGuiStyle structure via the AntiAliasedLines/AntiAliasedShapes fields for further gains.
+- ImDrawList: Added AddPolyline(), AddConvexPolyFilled() with optional anti-aliasing.
+- ImDrawList: Added stateful path building and stroking API. PathLineTo(), PathArcTo(), PathRect(), PathFill(), PathStroke()
+ with optional anti-aliasing.
+- ImDrawList: Added AddRectFilledMultiColor() helper.
+- ImDrawList: Added multi-channel rendering so out of order elements can be rendered in separate channels and then merged
+ back together (used by columns).
+- ImDrawList: Fixed merging draw commands when equal clip rectangles are in the two first commands.
+- ImDrawList: Fixed window draw lists not destructed properly on Shutdown().
+- ImDrawData: Added DeIndexAllBuffers() helper.
+- Added lots of new font options ImFontAtlas::AddFont() and the new ImFontConfig structure.
+ - Added support for oversampling (ImFontConfig: OversampleH, OversampleV) and sub-pixel positioning (ImFontConfig: PixelSnapH).
+ Oversampling allows sub-pixel positioning but can also be used as a way to get some leeway with scaling fonts without re-rasterizing.
+ - Added GlyphExtraSpacing option to add extra horizontal spacing between characters (#242).
+ - Added MergeMode option to merge glyphs from different font inputs into a same font (#182, #232).
+ - Added FontDataOwnedByAtlas option to keep ownership from the TTF data buffer and request the atlas to make a copy (#220).
+- Updated to stb_truetype 1.06 (+ minor mods) with better font rasterization.
+- InputText: Added ImGuiInputTextFlags_NoHorizontalScroll flag.
+- InputText: Added ImGuiInputTextFlags_AlwaysInsertMode flag.
+- InputText: Added HasSelection() helper in ImGuiTextEditCallbackData as a clarification.
+- InputText: Fix for using END key on a multi-line text editor (#275)
+- Columns: Dispatch render of each column in a sub-draw list and merge on closure, saving a lot of draw calls! (#125)
+- Popups: Fixed Combo boxes inside menus. (#272)
+- Style: Added GrabRounding setting to make the sliders etc. grabs rounded.
+- Changed SameLine() parameters from int to float.
+- Fixed incorrect assert triggering when code stole ActiveID from user moving a window by calling e.g. SetKeyboardFocusHere().
+- Fixed CollapsingHeader() label rendering outside its frame in columns context where ClipRect max isn't aligned with the
+ right-side of the header.
+- Metrics window: calculate bounding box of actual vertices when hovering a draw list.
+- Examples: Showing more information in the Fonts section.
+- Examples: Added a gratuitous About window.
+- Examples: Updated all examples code (OpenGL/DX9/DX11/SDL/Allegro/iOS) to use indexed rendering.
+- Examples: Fixed the SDL2 example to support Unicode text input (#274).
+
+
+-----------------------------------------------------------------------
+ VERSION 1.42 (2015-07-08)
+-----------------------------------------------------------------------
+
+Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.42
+
+Breaking Changes:
+
+- Renamed SetScrollPosHere() to SetScrollHere(). Kept inline redirection function (will obsolete).
+- Renamed GetScrollPosY() to GetScrollY(). Necessary to reduce confusion and make scrolling API consistent,
+ because positions (e.g. cursor position) are not equivalent to scrolling amount.
+- Removed obsolete GetDefaultFontData() function that would assert anyway.
+ If you are updating from <1.30 you'll get a compile error instead of an assertion. (obsoleted 2015/01/11)
+
+Other Changes:
+
+- Added SDL2 example application (courtesy of @CedricGuillemet)
+- Added iOS example application (courtesy of @joeld42)
+- Added Allegro 5 example application (courtesy of @bggd)
+- Added TitleBgActive color in style so focused window is made visible. (#253)
+- Added CaptureKeyboardFromApp() / CaptureMouseFromApp() to manually enforce inputs capturing.
+- Added DragFloatRange2() DragIntRange2() helpers. (#76)
+- Added a Y centering ratio to SetScrollFromCursorPos() which can be used to aim the top or bottom of the window. (#150)
+- Added SetScrollY(), SetScrollFromPos(), GetCursorStartPos() for manual scrolling manipulations. (#150).
+- Added GetKeyIndex() helper for converting from ImGuiKey_\* enum to user's keycodes. Basically pulls from io.KeysMap[].
+- Added missing ImGuiKey_PageUp, ImGuiKey_PageDown so more UI code can be written without referring to implementation-side keycodes.
+- MenuItem() can be activated on release. (#245)
+- Allowing NewFrame() with DeltaTime==0.0f to not assert.
+- Fixed IsMouseDragging(). (#260)
+- Fixed PlotLines(), PlotHistogram() using incorrect hovering test so they would show their tooltip even when there is
+ a popup between mouse and the graph.
+- Fixed window padding being reported incorrectly for child windows with borders when parent have no borders.
+- Fixed a bug with TextUnformatted() clipping of long text blob when clipping y1 line sits on the first line of text. (#257)
+- Fixed text baseline alignment of small button (no padding) after regular buttons.
+- Fixed ListBoxHeader() not honoring negative sizes the same way as BeginChild() or BeginChildFrame(). (#263)
+- Fixed warnings for more pedantic compiler settings (#258).
+- ImVector<> cannot be re-defined anymore, cannot be replaced with std::vector<>. Allowed us to clean up and optimize
+ lots of code. Yeah! (#262)
+- ImDrawList: store pointer to their owner name for easier auditing/debugging.
+- Examples: added scroll tracking example with SetScrollFromCursorPos().
+- Examples: metrics windows render clip rectangle when hovering over a draw call.
+- Lots of small optimization (particularly to run faster on unoptimized builds) and tidying up.
+- Added font links in extra_fonts/ + instructions for using compressed fonts in C array.
+
+
+-----------------------------------------------------------------------
+ VERSION 1.41 (2015-06-26)
+-----------------------------------------------------------------------
+
+Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.41
+
+Breaking Changes:
+
+- Changed ImageButton() default bg_col parameter from (0,0,0,1) (black) to (0,0,0,0) (transparent).
+ Only makes a difference when texture have transparency.
+- Changed Selectable() API from (label, selected, size) to (label, selected, flags, size).
+ Size override should be used very rarely so hopefully it doesn't affect many people. Sorry!
+
+Other Changes:
+
+- Added InputTextMultiline() multi-line text editor, vertical scrolling, selection, optimized enough to handle rather
+ big chunks of text in stateless context (thousands of lines are ok), option for allowing Tab to be input, option
+ for validating with Return or Ctrl+Return (#200).
+- Added modal window API, BeginPopupModal(), follows the popup api scheme. Modal windows can be closed by clicking
+ outside. By default the rest of the screen is dimmed (using ImGuiCol_ModalWindowDarkening). Modal windows can be stacked.
+- Added GetGlyphRangesCyrillic() helper (#237).
+- Added SetNextWindowPosCenter() to center a window prior to knowing its size. (#249)
+- Added IsWindowHovered() helper.
+- Added IsMouseReleased(), IsKeyReleased() helpers to allow to user to avoid tracking them. (#248)
+- Allow Set*WindowSize() calls to be used with popups.
+- Window: AutoFit can be triggered on each axis separately via SetNextWindowSize(), etc.
+- Window: fixed scrolling with mouse wheel while window was collapsed.
+- Window: fixed mouse wheel scroll issues.
+- DragFloat(), SliderFloat(): Fixed rounding of negative numbers which sometime made the negative lower bound unreachable.
+- InputText(): lifted character count limit.
+- InputText(): fixes in case of using per-window font scaling.
+- Selectable(), MenuItem(): do not use frame rounding for hovering/selection.
+- Selectable(): Added flag ImGuiSelectableFlags_DontClosePopups.
+- Selectable(): Added flag ImGuiSelectableFlags_SpanAllColumns (#125).
+- Combo(): Fixed issue with activating a Combo() not taking active id (#241).
+- ColorButton(), ColorEdit4(): fix to ensure that the colored square stays square when non-default padding settings are used.
+- BeginChildFrame(): returns bool like BeginChild() for clipping.
+- SetScrollPosHere(): takes account of item height + more accurate centering + fixed precision issue.
+- ImFont: ignoring '\r'.
+- ImFont: added GetCharAdvance() helper. Exposed font Ascent and font Descent.
+- ImFont: additional rendering optimizations.
+- Metrics windows display storage size.
+
+
+-----------------------------------------------------------------------
+ VERSION 1.40 (2015-05-31)
+-----------------------------------------------------------------------
+
+Decorated log: https://github.com/ocornut/imgui/releases/tag/v1.40
+
+Breaking Changes:
+
+- The BeginPopup() API (introduced in 1.37) had to be changed to allow for stacked popups and menus.
+ Use OpenPopup() to toggle the opened state and BeginPopup() to append.**
+- The third parameter of Button(), 'repeat_if_held' has been removed. While it's been very rarely used,
+ some code will possibly break if you didn't rely on the default parameter.
+ Use PushButtonRepeat()/PopButtonRepeat() to configure repeat.
+- Renamed IsRectClipped() to !IsRectVisible() for consistency (opposite return value!). Kept inline redirection function (will obsolete)
+- Renamed GetWindowCollapsed() to IsWindowCollapsed() for consistency. Kept inline indirection function (will obsolete).
+
+Other Changes:
+
+- Menus: Added a menu system! Menus are typically populated with menu items and sub-menus, but you can add any sort of
+ widgets in them (buttons, text inputs, sliders, etc.). (#126)
+- Menus: Added MenuItem() to append a menu item. Optional shortcut display, acts a button & toggle with checked/unchecked state,
+ disabled mode. Menu items can be used in any window.
+- Menus: Added BeginMenu() to append a sub-menu. Note that you generally want to add sub-menu inside a popup or a menu-bar.
+ They will work inside a normal window but it will be a bit unusual.
+- Menus: Added BeginMenuBar() to append to window menu-bar (set ImGuiWindowFlags_MenuBar to enable).
+- Menus: Added BeginMainMenuBar() helper to append to a fullscreen main menu-bar.
+- Popups: Support for stacked popups. Each popup level inhibit inputs to lower levels. The menus system is based on this. (#126).
+- Popups: Added BeginPopupContextItem(), BeginPopupContextWindow(), BeginPopupContextVoid() to create a popup window on mouse-click.
+- Popups: Popups have borders by default (#197), attenuated border alpha in default theme.
+- Popups & Tooltip: Fit within display. Handling various positioning/sizing/scrolling edge cases. Better hysteresis when moving
+ in corners. Tooltip always tries to stay away from mouse-cursor.
+- Added ImGuiStorage::GetVoidPtrRef() for manipulating stored void*.
+- Added IsKeyDown() IsMouseDown() as convenience and for consistency with existing functions (instead of reading them from IO structures).
+- Added Dummy() helper to advance layout by a given size. Unlike InvisibleButton() this doesn't catch any click.
+- Added configurable io.KeyRepeatDelay, io.KeyRepeatRate keyboard and mouse repeat rate.
+- Added PushButtonRepeat() / PopButtonRepeat() to enable hold-button-to-repeat press on any button.
+- Removed the third 'repeat' parameter of Button().
+- Added IsAnyItemHovered() helper.
+- Added GetItemsLineHeightWithSpacing() helper.
+- Added ImGuiListClipper helper for clipping large list of evenly sized items, to avoid using CalcListClipping() directly.
+- Separator: within group start on group horizontal offset. (#205)
+- InputText: Fixed incorrect edit state after text buffer is appended to by user via the callback. (#206)
+- InputText: CTRL+letter-key shortcuts (e.g. CTRL+C/V/X) makes sure only CTRL is pressed. (#214)
+- InputText: Fixed cursor generating a zero-width wire-frame rectangle turning into a division by zero (would go unnoticed
+ unless you trapped exceptions).
+- InputFloatN/InputIntN: Flags parameter added to match scalar versions. (#218)
+- Selectable: Horizontal filling not declared to ItemSize() so Selectable(),SameLine() works and we can better auto-fit the window.
+- Selectable: Handling text baseline alignment for line that aren't of text height.
+- Combo: Empty label doesn't add ItemInnerSpacing alignment, matching other widgets.
+- EndGroup: Carries the text base offset from the last line of the group (sort of incorrect but better than nothing,
+ should use the first line of the group, will implement in the future).
+- Columns: distinguish columns-set ID from other widgets as a convenience, added asserts and sailors.
+- ListBox: ListBox() function only use public API to encourage creating custom versions. ListBoxHeader() can return false.
+- ListBox: Uses ImGuiListClipper and assume items of matching height, so large lists can be handled.
+- Plot: overlay label clipped within frame when not fitting.
+- Window: Added ImGuiSetCond_Appearing to test the hidden->visible transition in SetWindow***/SetNextWindow*** functions.
+- Window: Auto-fitting cancel out one worth of vertical spacing for vertical symmetry (like what group and tooltip do).
+- Window: Default item width for auto-resizing windows expressed as a factor of font height, scales better with different font.
+- Window: Fixed auto-fit calculation mismatch of whether a scrollbar will be added by maximum height clamping. Also honor NoScrollBar in the case of height clamping, not adding extra horizontal space.
+- Window: Hovering require to hover same child window. Reverted 860cf57 (December 3). Might break something if you have
+ child overlapping items in parent window.
+- Window: Fixed appending multiple times to an existing child via multiple BeginChild/EndChild calls to same child name.
+ Allows a simple form of out-of-order appending.
+- Window: Fixed auto-filling child window using WindowMinSize at their minimum size, irrelevant.
+- Metrics: Added io.MetricsActiveWindows counter. (#213.
+- Metrics: Added io.MetricsAllocs counter (number of active memory allocations).
+- Metrics: ShowMetricsWindow() shows popups stack, allocations.
+- Style: Added style.DisplayWindowPadding to prevent windows from reaching edges of display (similar to style.DisplaySafeAreaPadding which is still in effect and also affect popups/tooltips).
+- Style: Removed style.AutoFitPadding, using style.WindowPadding makes more sense (the default values were already the same).
+- Style: Added style.ScrollbarRounding. (#212)
+- Style: Added ImGuiCol_TextDisabled for disabled text. Added TextDisabled() helper.
+- Style: Added style.WindowTitleAlign alignment options, to e.g. center title on windows. (#222)
+- ImVector: tweak growth strategy, matches vector from VS2010.
+- ImFontAtlas: Added ClearFonts(), making the different clear funcs more explicit. (#224)
+- ImFontAtlas: Fixed appending new fonts without clearing existing fonts. Clearing input data left to application. (#224)
+- ImDrawList: Merge draw command better, cases of multiple Begin/End gets merged properly.
+- Store common stacked settings contiguously in memory to avoid heap allocation for unused features, and reduce cache misses.
+- Shutdown() tests for g.IO.Fonts not being NULL to ease use of multiple ImGui contexts. (#207)
+- Added IMGUI_DISABLE_OBSOLETE_FUNCTIONS define to disable the functions that are meant to be removed.
+- Examples: Added ? marks with tooltips next to various widgets. Added more comments in the demo window.
+- Examples: Added Menu-bar example.
+- Examples: Added Simple Layout example.
+- Examples: AutoResize demo doesn't use TextWrapped().
+- Examples: Console example uses standard malloc/free, makes more sense as a copy & pastable example.
+- Examples: DirectX9/11: Fixed key mapping for down arrow.
+- Examples: DirectX9/11: hide OS cursor if ImGui is drawing it. (#155)
+- Examples: DirectX11: explicitly set rasterizer state.
+- Examples: OpenGL3: Add conditional compilation of forward compat as required by glfw on OSX. (#229)
+- Fixed build with Visual Studio 2008 (possibly earlier versions as well).
+- Other fixes, comments, tweaks.
+
+
-----------------------------------------------------------------------
For older version, see https://github.com/ocornut/imgui/releases
diff --git a/docs/README.md b/docs/README.md
index a6c4b416..5a706354 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -1,9 +1,12 @@
dear imgui
=====
-[![Build Status](https://travis-ci.org/ocornut/imgui.svg?branch=master)](https://travis-ci.org/ocornut/imgui)
+[![Build Status](https://api.travis-ci.com/ocornut/imgui.svg?branch=master)](https://travis-ci.com/ocornut/imgui)
[![Coverity Status](https://scan.coverity.com/projects/4720/badge.svg)](https://scan.coverity.com/projects/4720)
-_(This library is free as in freedom, but needs your support to sustain its development. In addition to maintenance and stability there are many desirable features yet to be added. If your company is using dear imgui, please consider reaching out for invoiced financial support. If you are an individual using dear imgui, please consider donating via Patreon or PayPal.)_
+_(This library is available under a free and permissive licence, but needs financial support to sustain its continued improvements. In addition to maintenance and stability there are many desirable features yet to be added. If your company is using dear imgui, please consider reaching out. If you are an individual using dear imgui, please consider supporting the project via Patreon or PayPal.)_
+
+Businesses: support continued development via invoiced technical support & maintenance contracts:
+ _E-mail: omarcornut at gmail dot com_
Individuals/hobbyists: support continued maintenance and development via the monthly Patreon:
[![Patreon](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/patreon_01.png)](http://www.patreon.com/imgui)
@@ -11,16 +14,13 @@ Individuals/hobbyists: support continued maintenance and development via the mon
Individuals/hobbyists: support continued maintenance and development via PayPal:
[![PayPal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WGHNC6MBFLZ2S)
-Businesses: support continued maintenance and development via support contracts or sponsoring:
- _E-mail: omarcornut at gmail dot com_
-
Dear ImGui is a bloat-free graphical user interface library for C++. It outputs optimized vertex buffers that you can render anytime in your 3D-pipeline enabled application. It is fast, portable, renderer agnostic and self-contained (no external dependencies).
Dear ImGui is designed to enable fast iterations and to empower programmers to create content creation tools and visualization / debug tools (as opposed to UI for the average end-user). It favors simplicity and productivity toward this goal, and lacks certain features normally found in more high-level libraries.
Dear ImGui is particularly suited to integration in games engine (for tooling), real-time 3D applications, fullscreen applications, embedded applications, or any applications on consoles platforms where operating system features are non-standard.
-See [Software using dear imgui](https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui), [Quotes](https://github.com/ocornut/imgui/wiki/Quotes) and [Gallery](https://github.com/ocornut/imgui/issues/2265) pages to get an idea of its use cases.
+See [Software using dear imgui](https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui), [Quotes](https://github.com/ocornut/imgui/wiki/Quotes) and [Gallery](https://github.com/ocornut/imgui/issues/2529) pages to get an idea of its use cases.
Dear ImGui is self-contained within a few files that you can easily copy and compile into your application/engine:
- imgui.cpp
@@ -102,7 +102,7 @@ Demo Binaries
-------------
You should be able to build the examples from sources (tested on Windows/Mac/Linux). If you don't, let me know! If you want to have a quick look at some Dear ImGui features, you can download Windows binaries of the demo app here:
-- [imgui-demo-binaries-20181008.zip](http://www.miracleworld.net/imgui/binaries/imgui-demo-binaries-20181008.zip) (Windows binaries, Dear ImGui 1.66 WIP built 2018/10/08, master branch, 5 executables)
+- [imgui-demo-binaries-20190715.zip](http://www.dearimgui.org/binaries/imgui-demo-binaries-20190715.zip) (Windows binaries, Dear ImGui 1.72 WIP built 2019/07/15, master branch, 5 executables)
The demo applications are unfortunately not yet DPI aware so expect some blurriness on a 4K screen. For DPI awareness in your application, you can load/reload your font at different scale, and scale your Style with `style.ScaleAllSizes()`.
@@ -122,35 +122,37 @@ Languages: (third-party bindings)
- Haxe/hxcpp: [linc_imgui](https://github.com/Aidan63/linc_imgui)
- Java: [jimgui](https://github.com/ice1000/jimgui)
- JavaScript: [imgui-js](https://github.com/flyover/imgui-js)
+- Julia: [CImGui.jl](https://github.com/Gnimuc/CImGui.jl)
- Lua: [LuaJIT-ImGui](https://github.com/sonoro1234/LuaJIT-ImGui), [imgui_lua_bindings](https://github.com/patrickriordan/imgui_lua_bindings) or [lua-ffi-bindings](https://github.com/thenumbernine/lua-ffi-bindings)
- Odin: [odin-dear_imgui](https://github.com/ThisDrunkDane/odin-dear_imgui)
- Pascal: [imgui-pas](https://github.com/dpethes/imgui-pas)
- PureBasic: [pb-cimgui](https://github.com/hippyau/pb-cimgui)
-- Python: [pyimgui](https://github.com/swistakm/pyimgui) or [bimpy](https://github.com/podgorskiy/bimpy)
+- Python: [pyimgui](https://github.com/swistakm/pyimgui) or [bimpy](https://github.com/podgorskiy/bimpy) or [ogre-imgui](https://github.com/OGRECave/ogre-imgui)
- Ruby: [ruby-imgui](https://github.com/vaiorabbit/ruby-imgui)
- Rust: [imgui-rs](https://github.com/Gekkio/imgui-rs) or [imgui-rust](https://github.com/nsf/imgui-rust)
- Swift [swift-imgui](https://github.com/mnmly/Swift-imgui)
Frameworks:
- Renderers: DirectX 9/10/11/12, Metal, OpenGL2, OpenGL3+/ES2/ES3, Vulkan: [examples/](https://github.com/ocornut/imgui/tree/master/examples)
-- Platform: GLFW, SDL, Win32, OSX, Freeglut: [examples/](https://github.com/ocornut/imgui/tree/master/examples)
-- Framework: Allegro 5, Marmalade: [examples/](https://github.com/ocornut/imgui/tree/master/examples)
-- Unmerged PR: SDL2 + OpenGLES + Emscripten: [#336](https://github.com/ocornut/imgui/pull/336)
+- Platform: GLFW, SDL, Win32, OSX, GLUT: [examples/](https://github.com/ocornut/imgui/tree/master/examples)
+- Framework: Allegro 5, Emscripten, Marmalade: [examples/](https://github.com/ocornut/imgui/tree/master/examples)
- Unmerged PR: Android: [#421](https://github.com/ocornut/imgui/pull/421)
+- bsf: [bsfimgui](https://github.com/pgruenbacher/bsfImgui)
- Cinder: [Cinder-ImGui](https://github.com/simongeilfus/Cinder-ImGui)
- Cocos2d-x: [imguix](https://github.com/c0i/imguix), [#551](https://github.com/ocornut/imgui/issues/551)
- Flexium: [FlexGUI](https://github.com/DXsmiley/FlexGUI)
- GML/GameMakerStudio2: [ImGuiGML](https://marketplace.yoyogames.com/assets/6221/imguigml)
- Irrlicht: [IrrIMGUI](https://github.com/ZahlGraf/IrrIMGUI)
-- Ogre: [ogreimgui](https://bitbucket.org/LMCrashy/ogreimgui/src)
+- Ogre: [ogre-imgui](https://github.com/OGRECave/ogre-imgui)
- OpenFrameworks: [ofxImGui](https://github.com/jvcleave/ofxImGui)
- OpenSceneGraph/OSG: [gist](https://gist.github.com/fulezi/d2442ca7626bf270226014501357042c)
-- ORX: [pr #1843](https://github.com/ocornut/imgui/pull/1843)
+- ORX: [ImGuiOrx](https://github.com/thegwydd/ImGuiOrx), [#1843](https://github.com/ocornut/imgui/pull/1843)
+- px_render: [px_render_imgui.h](https://github.com/pplux/px/blob/master/px_render_imgui.h), [#1935](https://github.com/ocornut/imgui/pull/1935)
- LÖVE+Lua: [love-imgui](https://github.com/slages/love-imgui)
- Magnum: [ImGuiIntegration](https://doc.magnum.graphics/magnum/namespaceMagnum_1_1ImGuiIntegration.html) ([example](https://doc.magnum.graphics/magnum/examples-imgui.html))
- NanoRT: [syoyo/imgui](https://github.com/syoyo/imgui/tree/nanort)
- Qt: [imgui-qt3d](https://github.com/alpqr/imgui-qt3d) / [QOpenGLWindow (qtimgui)](https://github.com/ocornut/imgui/issues/1910) / [QtDirect3D](https://github.com/giladreich/QtDirect3D) / [qt6](https://github.com/alpqr/qvk6/tree/imgui/examples/rhi/imguidemo)
-- SFML: [imgui-sfml](https://github.com/EliasD/imgui-sfml)
+- SFML: [imgui-sfml](https://github.com/eliasdaler/imgui-sfml)
- Software renderer: [imgui_software_renderer](https://github.com/emilk/imgui_software_renderer)
- Unreal Engine 4: [segross/UnrealImGui](https://github.com/segross/UnrealImGui) or [sronsse/UnrealEngine_ImGui](https://github.com/sronsse/UnrealEngine_ImGui)
@@ -159,8 +161,8 @@ For other bindings: see [Bindings](https://github.com/ocornut/imgui/wiki/Binding
Roadmap
-------
Some of the goals for 2019 are:
-- Finish work on docking, tabs. (see [#2109](https://github.com/ocornut/imgui/issues/2109), public branch looking for feedback)
-- Finish work on multiple viewports / multiple OS windows. (see [#1542](https://github.com/ocornut/imgui/issues/1542), public branch looking for feedback)
+- Finish work on docking, tabs. (see [#2109](https://github.com/ocornut/imgui/issues/2109), in public `docking` branch looking for feedback)
+- Finish work on multiple viewports / multiple OS windows. (see [#1542](https://github.com/ocornut/imgui/issues/1542), in public `docking` branch looking for feedback)
- Finish work on gamepad/keyboard controls. (see [#787](https://github.com/ocornut/imgui/issues/787))
- Add an automation and testing system, both to test the library and end-user apps. (see [#435](https://github.com/ocornut/imgui/issues/435))
- Make Columns better. (they are currently pretty terrible!)
@@ -176,8 +178,8 @@ User screenshots:
[Gallery Part 5](https://github.com/ocornut/imgui/issues/1269) (Aug 2017 to Feb 2018)
[Gallery Part 6](https://github.com/ocornut/imgui/issues/1607) (Feb 2018 to June 2018)
[Gallery Part 7](https://github.com/ocornut/imgui/issues/1902) (June 2018 to January 2019)
- [Gallery Part 8](https://github.com/ocornut/imgui/issues/2265) (January 2019 onward)
- Also see the [Mega screenshots](https://github.com/ocornut/imgui/issues/1273) for an idea of the available features.
+ [Gallery Part 8](https://github.com/ocornut/imgui/issues/2265) (January 2019 to May 2019)
+ [Gallery Part 9](https://github.com/ocornut/imgui/issues/2529) (May 2019 onward)
Custom engine
[![screenshot game](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/v149/gallery_TheDragonsTrap-01-thumb.jpg)](https://cloud.githubusercontent.com/assets/8225057/20628927/33e14cac-b329-11e6-80f6-9524e93b048a.png)
@@ -197,61 +199,66 @@ References
The Immediate Mode GUI paradigm may at first appear unusual to some users. This is mainly because "Retained Mode" GUIs have been so widespread and predominant. The following links can give you a better understanding about how Immediate Mode GUIs works.
- [Johannes 'johno' Norneby's article](http://www.johno.se/book/imgui.html).
- [A presentation by Rickard Gustafsson and Johannes Algelind](http://www.cse.chalmers.se/edu/year/2011/course/TDA361/Advanced%20Computer%20Graphics/IMGUI.pdf).
-- [Jari Komppa's tutorial on building an ImGui library](http://iki.fi/sol/imgui/).
+- [Jari Komppa's tutorial on building an IMGUI library](http://iki.fi/sol/imgui/).
- [Casey Muratori's original video that popularized the concept](https://mollyrocket.com/861).
- [Nicolas Guillemot's CppCon'16 flash-talk about Dear ImGui](https://www.youtube.com/watch?v=LSRJ1jZq90k).
- [Thierry Excoffier's Zero Memory Widget](http://perso.univ-lyon1.fr/thierry.excoffier/ZMW/).
See the [Wiki](https://github.com/ocornut/imgui/wiki) for more references and [Bindings](https://github.com/ocornut/imgui/wiki/Bindings) for third-party bindings to different languages and frameworks.
-Support Forums
---------------
+Support
+-------
+
+If you are new to Dear ImGui and have issues with: compiling, linking, adding fonts, wiring inputs, running or displaying Dear ImGui: please post on the Discourse forums: https://discourse.dearimgui.org.
-If you have issues with: compiling, linking, adding fonts, running or displaying Dear ImGui, or wiring inputs: please post on the Discourse forums: https://discourse.dearimgui.org.
+Otherwise for any other questions, bug reports, requests, feedback, you may post on https://github.com/ocornut/imgui/issues. Please read and fill the New Issue template carefully.
-For any other questions, bug reports, requests, feedback, you may post on https://github.com/ocornut/imgui/issues. Please read and fill the New Issue template carefully.
+Private support is available for paying customers.
Frequently Asked Question (FAQ)
-------------------------------
**Where is the documentation?**
-- The documentation is at the top of imgui.cpp + effectively imgui.h.
-- Example code is in imgui_demo.cpp and particularly the ImGui::ShowDemoWindow() function. It covers most features of ImGui so you can read the code and call the function itself to see its output.
-- Standalone example applications using e.g. OpenGL/DirectX are provided in the examples/ folder.
-- We obviously needs better documentation! Consider contributing or becoming a [Patron](http://www.patreon.com/imgui) to promote this effort.
-- Your programming IDE is your friend, find the type or function declaration to find comments associated to it.
+ This library is poorly documented at the moment and expects of the user to be acquainted with C/C++.
+ - Run the examples/ applications and explore them.
+ - See demo code in imgui_demo.cpp and particularly the ImGui::ShowDemoWindow() function.
+ - The demo covers most features of Dear ImGui, so you can read the code and see its output.
+ - See documentation and comments at the top of imgui.cpp + effectively imgui.h.
+ - Dozens of standalone example applications using e.g. OpenGL/DirectX are provided in the examples/ folder to explain how to integrate Dear ImGui with your own engine/application.
+ - Your programming IDE is your friend, find the type or function declaration to find comments associated to it.
+ - We obviously needs better documentation! Consider contributing or becoming a [Patron](http://www.patreon.com/imgui) to promote this effort.
**Which version should I get?**
I occasionally tag [Releases](https://github.com/ocornut/imgui/releases) but it is generally safe and recommended to sync to master/latest. The library is fairly stable and regressions tend to be fixed fast when reported.
-You may also peak at the [Multi-Viewport](https://github.com/ocornut/imgui/issues/1542) and [Docking](https://github.com/ocornut/imgui/issues/2109) branches. Even though they are marked beta, several projects are using them and they are kept in sync with master regularly.
+You may also peak at the [Multi-Viewport](https://github.com/ocornut/imgui/issues/1542) and [Docking](https://github.com/ocornut/imgui/issues/2109) features in the `docking` branch. Many projects are using this branch and it is kept in sync with master regularly.
**Who uses Dear ImGui?**
-See the [Quotes](https://github.com/ocornut/imgui/wiki/Quotes) and [Software using dear imgui](https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui) pages for an (incomplete) list of games/software which are publicly known to use dear imgui. Please add yours if you can!
+See the [Quotes](https://github.com/ocornut/imgui/wiki/Quotes) and [Software using dear imgui](https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui) Wiki pages for a list of games/software which are publicly known to use dear imgui. Please add yours if you can!
**Why the odd dual naming, "Dear ImGui" vs "ImGui"?**
-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.
+The library started its life as "ImGui" due to the fact that I didn't give it a proper name when I released 1.0 and had no particular expectation that it would take off. However, the term IMGUI (immediate-mode graphical user interface) was coined before and is being used in variety of other situations (e.g. Unity uses it own implementation of the IMGUI paradigm). To reduce this 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. Please try to refer to this library as "Dear ImGui".
-**How can I tell whether to dispatch mouse/keyboard to imgui or to my application?**
+**How can I tell whether to dispatch mouse/keyboard to Dear ImGui or to my application?**
**How can I display an image? What is ImTextureID, how does it works?**
- **How can I have multiple widgets with the same label or with an empty label? A primer on labels and the ID Stack.**
+ **Why are multiple widgets reacting when I interact with a single one? How can I have multiple widgets with the same label or with an empty label? A primer on labels and the ID Stack...**
**How can I use my own math types instead of ImVec2/ImVec4?**
**How can I load a different font than the default?**
**How can I easily use icons in my application?**
**How can I load multiple fonts?**
**How can I display and input non-latin characters such as Chinese, Japanese, Korean, Cyrillic?** ([example](https://github.com/ocornut/imgui/wiki/Loading-Font-Example))
**How can I interact with standard C++ types (such as std::string and std::vector)?**
- **How can I use the drawing facilities without an Dear ImGui window? (using ImDrawList API)**
+ **How can I use the drawing facilities without a Dear ImGui window? (using ImDrawList API)**
**How can I use this without a mouse, without a keyboard or without a screen? (gamepad, input share, remote display)**
**I integrated Dear ImGui in my engine and the text or lines are blurry..**
**I integrated Dear ImGui in my engine and some elements are disappearing when I move windows around..**
**How can I help?**
-See the FAQ in imgui.cpp for answers.
+See the FAQ in [imgui.cpp](https://github.com/ocornut/imgui/blob/master/imgui.cpp) for answers.
**Can you create elaborate/serious tools with Dear ImGui?**
@@ -269,7 +276,7 @@ You can alter the look of the interface to some degree: changing colors, sizes,
Dear ImGui takes advantage of a few C++ languages features for convenience but nothing anywhere Boost-insanity/quagmire. Dear ImGui does NOT require C++11 so it can be used with most old C++ compilers. Dear ImGui doesn't use any C++ header file. Language-wise, function overloading and default parameters are used to make the API easier to use and code more terse. Doing so I believe the API is sitting on a sweet spot and giving up on those features would make the API more cumbersome. Other features such as namespace, constructors and templates (in the case of the ImVector<> class) are also relied on as a convenience.
-There is an auto-generated [c-api for Dear ImGui (cimgui)](https://github.com/cimgui/cimgui) by Sonoro1234 and Stephan Dilly. This is designed for binding other languages. If possible, I would suggest using your target language functionalities to try replicating the function overloading and default parameters used in C++ else the API may be harder to use. Also see [Bindings](https://github.com/ocornut/imgui/wiki/Bindings) for third-party bindings to other languages.
+There is an auto-generated [c-api for Dear ImGui (cimgui)](https://github.com/cimgui/cimgui) by Sonoro1234 and Stephan Dilly. It is designed for creating binding to other languages. If possible, I would suggest using your target language functionalities to try replicating the function overloading and default parameters used in C++ else the API may be harder to use. Also see [Bindings](https://github.com/ocornut/imgui/wiki/Bindings) for various third-party bindings.
Support dear imgui
------------------
@@ -279,11 +286,14 @@ Support dear imgui
- You may participate in the [Discourse forums](https://discourse.dearimgui.org) and the GitHub [issues tracker](https://github.com/ocornut/imgui/issues).
- You may help with development and submit pull requests! Please understand that by submitting a PR you are also submitting a request for the maintainer to review your code and then take over its maintenance forever. PR should be crafted both in the interest in the end-users and also to ease the maintainer into understanding and accepting it.
- See [Help wanted](https://github.com/ocornut/imgui/wiki/Help-Wanted) on the [Wiki](https://github.com/ocornut/imgui/wiki/) for some more ideas.
-- Convince your company to financially support this project.
+- Have your company financially support this project.
**How can I help financing further development of Dear ImGui?**
-Your contributions are keeping this project alive. The library is free as in freedom, but continued maintenance and development are a full-time endeavor. In addition to maintenance and stability there are many desirable features yet to be added. If your company is using dear imgui, please consider reaching out for financial support. If you are an individual using dear imgui, please consider donating via Patreon or PayPal. Thank you!
+Your contributions are keeping this project alive. The library is available under a free and permissive licence, but continued maintenance and development are a full-time endeavor and I would like to grow the team. In addition to maintenance and stability there are many desirable features yet to be added. If your company is using dear imgui, please consider reaching out for invoiced technical support and maintenance contracts. If you are an individual using dear imgui, please consider supporting the project via Patreon or PayPal. Thank you!
+
+Businesses: support continued development via invoiced technical support & maintenance contracts:
+ _E-mail: omarcornut at gmail dot com_
Individuals/hobbyists: support continued maintenance and development via the monthly Patreon:
[![Patreon](https://raw.githubusercontent.com/wiki/ocornut/imgui/web/patreon_01.png)](http://www.patreon.com/imgui)
@@ -291,22 +301,20 @@ Individuals/hobbyists: support continued maintenance and development via the mon
Individuals/hobbyists: support continued maintenance and development via PayPal:
[![PayPal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WGHNC6MBFLZ2S)
-Businesses: support continued maintenance and development via support contracts or sponsoring:
- _E-mail: omarcornut at gmail dot com_
-
Ongoing dear imgui development is financially supported by users and private sponsors, recently:
**Platinum-chocolate sponsors**
-- **Blizzard Entertainment**.
+- Blizzard Entertainment
+- Google
**Double-chocolate sponsors**
- Media Molecule, Mobigame, Aras Pranckevičius, Greggman, DotEmu, Nadeo, Supercell, Runner, Aiden Koss, Kylotonn.
**Salty caramel supporters**
-- Recognition Robotics, ikrima, Geoffrey Evans, Mercury Labs, Singularity Demo Group, Lionel Landwerlin, Ron Gilbert, Brandon Townsend, Nikhil Deshpande, Cort Stratton, drudru, Harfang 3D, Jeff Roberts, Rainway inc, Ondra Voves, Mesh Consultants.
+- Remedy Entertainment, Recognition Robotics, ikrima, Geoffrey Evans, Mercury Labs, Singularity Demo Group, Lionel Landwerlin, Ron Gilbert, Brandon Townsend, Morten Skaaning, Nikhil Deshpande, Cort Stratton, drudru, Harfang 3D, Jeff Roberts, Rainway inc, Ondra Voves, Mesh Consultants, Unit 2 Games, Neil Bickford.
**Caramel supporters**
-- Jerome Lanquetot, Daniel Collin, Ctrl Alt Ninja, Neil Henning, Neil Blakey-Milner, Aleksei, NeiloGD, Eric, Game Atelier, Vincent Hamm, Colin Riley, Sergio Gonzales, Andrew Berridge, Roy Eltham, Game Preservation Society, Josh Faust, Martin Donlon, Codecat, Doug McNabb, Emmanuel Julien, Guillaume Chereau, Jeffrey Slutter, Jeremiah Deckard, r-lyeh, Nekith, Joshua Fisher, Malte Hoffmann, Mustafa Karaalioglu, Merlyn Morgan-Graham, Per Vognsen, Fabian Giesen, Jan Staubach, Matt Hargett, John Shearer, Jesse Chounard, kingcoopa, Jonas Bernemann, Johan Andersson, Michael Labbe, Tomasz Golebiowski, Louis Schnellbach, Jimmy Andrews, Bojan Endrovski, Robin Berg Pettersen, Rachel Crawford, Andrew Johnson, Sean Hunter, Jordan Mellow, Nefarius Software Solutions, Laura Wieme, Robert Nix, Mick Honey, Steven Kah Hien Wong, Bartosz Bielecki, Oscar Penas, A M, Liam Moynihan, Artometa, Mark Lee, Dimitri Diakopoulos, Pete Goodwin.
+- Jerome Lanquetot, Daniel Collin, Ctrl Alt Ninja, Neil Henning, Neil Blakey-Milner, Aleksei, NeiloGD, Eric, Game Atelier, Vincent Hamm, Colin Riley, Sergio Gonzales, Andrew Berridge, Roy Eltham, Game Preservation Society, Josh Faust, Martin Donlon, Codecat, Doug McNabb, Emmanuel Julien, Guillaume Chereau, Jeffrey Slutter, Jeremiah Deckard, r-lyeh, Nekith, Joshua Fisher, Malte Hoffmann, Mustafa Karaalioglu, Merlyn Morgan-Graham, Per Vognsen, Fabian Giesen, Jan Staubach, Matt Hargett, John Shearer, Jesse Chounard, kingcoopa, Jonas Bernemann, Johan Andersson, Michael Labbe, Tomasz Golebiowski, Louis Schnellbach, Jimmy Andrews, Bojan Endrovski, Robin Berg Pettersen, Rachel Crawford, Andrew Johnson, Sean Hunter, Jordan Mellow, Nefarius Software Solutions, Laura Wieme, Robert Nix, Mick Honey, Steven Kah Hien Wong, Bartosz Bielecki, Oscar Penas, A M, Liam Moynihan, Artometa, Mark Lee, Dimitri Diakopoulos, Pete Goodwin, Johnathan Roatch, nyu lea, Oswald Hurlem, Semyon Smelyanskiy, Le Bach, Jeong MyeongSoo, Chris Matthews, Astrofra, Frederik De Bleser, Anticrisis.
And all other past and present supporters; THANK YOU!
(Please contact me if you would like to be added or removed from this list)
@@ -316,7 +324,7 @@ Credits
Developed by [Omar Cornut](http://www.miracleworld.net) and every direct or indirect contributors to the GitHub. The early version of this library was developed with the support of [Media Molecule](http://www.mediamolecule.com) and first used internally on the game [Tearaway](http://tearaway.mediamolecule.com).
-I first discovered the IMGUI paradigm at [Q-Games](http://www.q-games.com) where Atman had dropped his own simple implementation in the codebase, which I spent quite some time improving and thinking about. It turned out that Atman was exposed to the concept directly by working with Casey. When I moved to Media Molecule I rewrote a new library trying to overcome the flaws and limitations of the first one I've worked with. It became this library and since then I have spent an unreasonable amount of time iterating on it.
+I first discovered the IMGUI paradigm at [Q-Games](http://www.q-games.com) where Atman Binstock had dropped his own simple implementation in the codebase, which I spent quite some time improving and thinking about. It turned out that Atman was exposed to the concept directly by working with Casey. When I moved to Media Molecule I rewrote a new library trying to overcome the flaws and limitations of the first one I've worked with. It became this library and since then I have spent an unreasonable amount of time iterating and improving it.
Embeds [ProggyClean.ttf](http://upperbounds.net) font by Tristan Grimmer (MIT license).
@@ -327,4 +335,4 @@ Inspiration, feedback, and testing for early versions: Casey Muratori, Atman Bin
License
-------
-Dear ImGui is licensed under the MIT License, see LICENSE for more information.
+Dear ImGui is licensed under the MIT License, see [LICENSE.txt](https://github.com/ocornut/imgui/blob/master/LICENSE.txt) for more information.
diff --git a/docs/TODO.txt b/docs/TODO.txt
index b32a5a0d..e006ba68 100644
--- a/docs/TODO.txt
+++ b/docs/TODO.txt
@@ -9,6 +9,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
- doc/test: checklist app to verify binding/integration of imgui (test inputs, rendering, callback, etc.).
- doc/tips: tips of the day: website? applet in imgui_club?
+ - window: preserve/restore relative focus ordering (persistent or not) (#2304) -> also see docking reference to same #.
- window: calling SetNextWindowSize() every frame with <= 0 doesn't do anything, may be useful to allow (particularly when used for a single axis). (#690)
- window: add a way for very transient windows (non-saved, temporary overlay over hundreds of objects) to "clean" up from the global window list. perhaps a lightweight explicit cleanup pass.
- window: auto-fit feedback loop when user relies on any dynamic layout (window width multiplier, column) appears weird to end-user. clarify.
@@ -25,15 +26,21 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
- window: using SetWindowPos() inside Begin() and moving the window with the mouse reacts a very ugly glitch. We should just defer the SetWindowPos() call.
- window: GetWindowSize() returns (0,0) when not calculated? (#1045)
- window: investigate better auto-positioning for new windows.
- - window/opt: freeze window flag: if not focused/hovered, return false, render with previous ImDrawList. and/or reduce refresh rate.
+ - window: top most window flag? (#2574)
+ - window/opt: freeze window flag: if not focused/hovered, return false, render with previous ImDrawList. and/or reduce refresh rate. -> this may require enforcing that it is illegal to submit contents if Begin returns false.
- window/child: the first draw command of a child window could be moved into the current draw command of the parent window (unless child+tooltip?).
+ - window/child: border could be emitted in parent as well.
+ - window/child: allow SetNextWindowContentSize() to work on child windows.
- window/clipping: some form of clipping when DisplaySize (or corresponding viewport) is zero.
+ - window/tab: add a way to signify that a window or docked window requires attention (e.g. blinking title bar).
+ ! scrolling: exposing horizontal scrolling with Shift+Wheel even when scrollbar is disabled expose lots of issues (#2424, #1463)
- scrolling: while holding down a scrollbar, try to keep the same contents visible (at least while not moving mouse)
- scrolling: allow immediately effective change of scroll after Begin() if we haven't appended items yet.
- scrolling/clipping: separator on the initial position of a window is not visible (cursorpos.y <= clippos.y). (2017-08-20: can't repro)
- scrolling/style: shadows on scrollable areas to denote that there is more contents
- - drawdata: make it easy to clone (or swap?) a ImDrawData so user can easily save that data if they use threaded rendering.
+ - drawdata: make it easy to clone (or swap?) a full ImDrawData so user can easily save that data if they use threaded rendering. (e.g. #2646)
+ ! drawlist: add calctextsize func to facilitate consistent code from user pov (currently need to use ImGui or ImFont alternatives!)
- drawlist: end-user probably can't call Clear() directly because we expect a texture to be pushed in the stack.
- drawlist: maintaining bounding box per command would allow to merge draw command when clipping isn't relied on (typical non-scrolling window or non-overflowing column would merge with previous command).
- drawlist: primitives/helpers to manipulate vertices post submission, so e.g. a quad/rect can be resized to fit later submitted content, _without_ using the ChannelSplit api
@@ -42,10 +49,12 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
- drawlist: would be good to be able to deep copy of ImDrawData (we have a deep copy of ImDrawList now).
- drawlist: rendering: provide a way for imgui to output to a single/global vertex buffer, re-order indices only at the end of the frame (ref: https://gist.github.com/floooh/10388a0afbe08fce9e617d8aefa7d302)
- drawlist: callback: add an extra void* in ImDrawCallback to allow passing render-local data to the callback (would break API).
+ - drawlist: AddRect vs AddLine position confusing (#2441)
+ - drawlist: channel splitter should be external helper and not stored in ImDrawList.
- drawlist/opt: store rounded corners in texture to use 1 quad per corner (filled and wireframe) to lower the cost of rounding. (#1962)
- drawlist/opt: AddRect() axis aligned pixel aligned (no-aa) could use 8 triangles instead of 16 and no normal calculation.
+ - drawlist/opt: thick AA line could be doable in same number of triangles as 1.0 AA line by storing gradient+full color in atlas.
- - main: considering adding an Init() function? some constructs are awkward in the implementation because of the lack of them.
- main: find a way to preserve relative orders of multiple reappearing windows (so an app toggling between "modes" e.g. fullscreen vs all tools) won't lose relative ordering.
- main: IsItemHovered() make it more consistent for various type of widgets, widgets with multiple components, etc. also effectively IsHovered() region sometimes differs from hot region, e.g tree nodes
- main: IsItemHovered() info stored in a stack? so that 'if TreeNode() { Text; TreePop; } if IsHovered' return the hover state of the TreeNode?
@@ -54,11 +63,16 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
- widgets: display mode: widget-label, label-widget (aligned on column or using fixed size), label-newline-tab-widget etc. (#395)
- widgets: clean up widgets internal toward exposing everything and stabilizing imgui_internals.h.
- widgets: add visuals for Disabled/ReadOnly mode and expose publicly (#211)
- - widgets: add always-allow-overlap mode.
+ - widgets: add always-allow-overlap mode. This should perhaps be the default.
- widgets: start exposing PushItemFlag() and ImGuiItemFlags
- widgets: alignment options in style (e.g. center Selectable, Right-Align within Button, etc.) #1260
- widgets: activate by identifier (trigger button, focus given id)
- - widgets: a way to represent "mixed" values, so e.g. all values replaced with **, including check-boxes, colors, etc. with support for multi-components widgets (e.g. SliderFloat3, make only "Y" mixed)
+ - widgets: a way to represent "mixed" values, so e.g. all values replaced with *, including check-boxes, colors, etc. with support for multi-components widgets (e.g. SliderFloat3, make only "Y" mixed) (#2644)
+ - widgets: selectable: generic BeginSelectable()/EndSelectable() mechanism.
+ - widgets: selectable: a way to visualize partial/mixed selection (e.g. parent tree node has children with mixed selection)
+ - widgets: checkbox: checkbox with custom glyph inside frame.
+ - widgets: coloredit: keep reporting as active when picker is on?
+ - widgets: group/scalarn functions: expose more per-component information. e.g. store NextItemData.ComponentIdx set by scalarn function, groups can expose them back somehow.
- input text: clean up the mess caused by converting UTF-8 <> wchar. the code is rather inefficient right now and super fragile.
- input text: reorganize event handling, allow CharFilter to modify buffers, allow multiple events? (#541)
@@ -72,8 +86,13 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
- input text: add discard flag (e.g. ImGuiInputTextFlags_DiscardActiveBuffer) or make it easier to clear active focus for text replacement during edition (#725)
- input text: display bug when clicking a drag/slider after an input text in a different window has all-selected text (order dependent). actually a very old bug but no one appears to have noticed it.
- input text: allow centering/positioning text so that ctrl+clicking Drag or Slider keeps the textual value at the same pixel position.
- - input text: what's the easiest way to implement a nice IP/Mac address input editor?
- - input text: Global callback system so user can plug in an expression evaluator easily.
+ - input text: decorrelate layout from inputs - e.g. what's the easiest way to implement a nice IP/Mac address input editor?
+ - input text: global callback system so user can plug in an expression evaluator easily. (#1691)
+ - input text: force scroll to end or scroll to a given line/contents (so user can implement a log or a search feature)
+ - input text: a way to preview completion (e.g. disabled text completing from the cursor)
+ - input text: a side bar that could e.g. preview where errors are. probably left to the user to draw but we'd need to give them the info there.
+ - input text: a way for the user to provide syntax coloring.
+ - input text: Shift+TAB with ImGuiInputTextFlags_AllowTabInput could eat preceding blanks, up to tab_count.
- input text multi-line: don't directly call AddText() which does an unnecessary vertex reserve for character count prior to clipping. and/or more line-based clipping to AddText(). and/or reorganize TextUnformatted/RenderText for more efficiency for large text (e.g TextUnformatted could clip and log separately, etc).
- input text multi-line: support for cut/paste without selection (cut/paste the current line)
- input text multi-line: line numbers? status bar? (follow up on #200)
@@ -91,9 +110,12 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
- layout: horizontal flow until no space left (#404)
- layout: more generic alignment state (left/right/centered) for single items?
- layout: clean up the InputFloatN/SliderFloatN/ColorEdit4 layout code. item width should include frame padding.
- - layout: BeginGroup() needs a border option. (~#1496)
- layout: vertical alignment of mixed height items (e.g. buttons) within a same line (#1284)
+ - group: BeginGroup() needs a border option. (~#1496)
+ - group: IsHovered() after EndGroup() covers whole aabb rather than the intersection of individual items. Is that desirable?
+ - group: merge deactivation/activation within same group (fwd WasEdited flag). (#2550)
+
- columns: sizing policy (e.g. for each column: fixed size, %, fill, distribute default size among fills) (#513, #125)
- columns: add a conditional parameter to SetColumnOffset() (#513, #125)
- columns: headers. re-orderable. (#513, #125)
@@ -101,6 +123,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
- columns: option to alternate background colors on odd/even scanlines.
- columns: allow columns to recurse.
- columns: allow a same columns set to be interrupted by e.g. CollapsingHeader and resume with columns in sync when moving them.
+ - columns: sizing is lossy when columns width is very small (default width may turn negative etc.)
- columns: separator function or parameter that works within the column (currently Separator() bypass all columns) (#125)
- columns: flag to add horizontal separator above/below?
- columns/layout: setup minimum line height (equivalent of automatically calling AlignFirstTextHeightToWidgets)
@@ -120,14 +143,20 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
- clipper: ability to force display 1 item in the list would be convenient (for patterns where we need to set active id etc.)
- clipper: ability to disable the clipping through a simple flag/bool.
- clipper: ability to run without knowing full count in advance.
+ - clipper: horizontal clipping support. (#2580)
- - splitter/separator: formalize the splitter idiom into an official api (we want to handle n-way split) (#319)
+ - separator: expose flags (#759)
+ - separator: width, thickness, centering (#1643)
+ - splitter: formalize the splitter idiom into an official api (we want to handle n-way split) (#319)
- dock: merge docking branch (#2109)
- - dock: A~ Unreal style document system (requires low-level controls of dockspace serialization fork/copy/delete). this is mostly working but the DockBuilderXXX api are not exposed/finished.
+ - dock: B: ordering currently held in tab bar should be implicitly held by windows themselves (also see #2304)
+ - dock: B- tab bar: the order/focus restoring code could be part of TabBar and not DockNode? (#8)
+ - dock: B~ rework code to be able to lazily create tab bar instance in a single place. The _Unsorted tab flag could be replacing a trailing-counter in DockNode?
+ - dock: B~ fully track windows/settings reference in dock nodes. perhaps find a representation that allows facilitate use of dock builder functions.
+ - dock: B~ Unreal style document system (requires low-level controls of dockspace serialization fork/copy/delete). this is mostly working but the DockBuilderXXX api are not exposed/finished.
- dock: B: when docking outer, perform size locking on neighbors nodes the same way we do it with splitters, so other nodes are not resized.
- dock: B~ central node resizing behavior incorrect.
- - dock: B~ central node ID retrieval API?
- dock: B: changing title font/style per-window is not supported as dock nodes are created in NewFrame.
- dock: B- dock node inside its own viewports creates 1 temporary viewport per window on startup before ditching them (doesn't affect the user nor request platform windows to be created, but unnecessary)
- dock: B- resize sibling locking behavior may be less desirable if we merged same-axis sibling in a same node level?
@@ -141,7 +170,6 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
- dock: B- dpi: look at interaction with the hi-dpi and multi-dpi stuff.
- dock: B- tab bar: appearing on first frame with a dumb layout would do less harm that not appearing? (when behind dynamic branch) or store titles + render in EndTabBar()
- dock: B- tab bar: make selected tab always shows its full title?
- - dock: B- tab bar: the order/focus restoring code could be part of TabBar and not DockNode? (#8)
- dock: B- nav: design interactions so nav controls can dock/undock
- dock: B- dockspace: flag to lock the dock tree and/or sizes (ImGuiDockNodeFlags_Locked?)
- dock: B- reintroduce collapsing a floating dock node. also collapsing a docked dock node!
@@ -153,12 +181,11 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
- tabs: make EndTabBar fail if users doesn't respect BeginTabBar return value, for consistency/future-proofing.
- tabs: persistent order/focus in BeginTabBar() api (#261, #351)
- - ext: stl-ish friendly extension (imgui_stl.h) that has wrapper for std::string, std::vector etc.
-
- button: provide a button that looks framed. (?)
- image/image button: misalignment on padded/bordered button?
- image/image button: parameters are confusing, image() has tint_col,border_col whereas imagebutton() has bg_col/tint_col. Even thou they are different parameters ordering could be more consistent. can we fix that?
- - image button: not taking an explicit id is odd.
+ - image button: not taking an explicit id can be problematic. (#2464, #1390)
+ - slider/drag: ctrl+click when format doesn't include a % character.. disable? display underlying value in default format? (see TempInputTextScalar)
- slider: allow using the [-]/[+] buttons used by InputFloat()/InputInt()
- slider: initial absolute click is imprecise. change to relative movement slider (same as scrollbar). (#1946)
- slider: add dragging-based widgets to edit values with mouse (on 2 axises), saving screen real-estate.
@@ -169,7 +196,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
- knob: rotating knob widget (#942)
- drag float: power/logarithmic slider and drags are weird. (#1316)
- drag float: up/down axis
- - drag float: power != 0.0f with current value being outside the the range keeps the value stuck.
+ - drag float: power != 0.0f with current value being outside the range keeps the value stuck.
- drag float: added leeway on edge (e.g. a few invisible steps past the clamp limits)
- combo: use clipper: make it easier to disable clipper with a single flag.
@@ -183,7 +210,9 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
- listbox: user may want to initial scroll to focus on the one selected value?
- listbox: expose hovered item for a basic ListBox
- listbox: keyboard navigation.
+ - listbox: disable capturing mouse wheel if the listbox has no scrolling. (#1681)
- listbox: scrolling should track modified selection.
+ - listbox: future api should allow to enable horizontal scrolling (#2510)
!- popups/menus: clarify usage of popups id, how MenuItem/Selectable closing parent popups affects the ID, etc. this is quite fishy needs improvement! (#331, #402)
- popups/modal: make modal title bar blink when trying to click outside the modal
@@ -205,21 +234,24 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
- shortcuts: programmatically access shortcuts "Focus("&Save"))
- menus: menu-bar: main menu-bar could affect clamping of windows position (~ akin to modifying DisplayMin)
- menus: hovering from menu to menu on a menu-bar has 1 frame without any menu, which is a little annoying. ideally either 0 either longer.
+ - menus: could merge draw call in most cases (how about storing an optional aabb in ImDrawCmd to move the burden of merging in a single spot).
- text: selectable text (for copy) as a generic feature (ItemFlags?)
- text: proper alignment options in imgui_internal.h
- - text wrapped: figure out better way to use TextWrapped() in an always auto-resize context (tooltip, etc.) (#249)
- text: it's currently impossible to have a window title with "##". perhaps an official workaround would be nice. \ style inhibitor? non-visible ascii code to insert between #?
- text: provided a framed text helper, e.g. https://pastebin.com/1Laxy8bT
+ - text: refactor TextUnformatted (or underlying function) to more explicitly request if we need width measurement or not
- text link/url button: underlined. should api expose an ID or use text contents as ID? which colors enum to use?
+ - text/wrapped: should be a more first-class citizen, e.g. wrapped text within a Selectable with known width
+ - text/wrapped: figure out better way to use TextWrapped() in an always auto-resize context (tooltip, etc.) (#249)
- - tree node / optimization: avoid formatting when clipped.
- - tree node: tree-node/header right-most side doesn't take account of horizontal scrolling.
- tree node: add treenode/treepush int variants? not there because (void*) cast from int warns on some platforms/settings?
- tree node: try to apply scrolling at time of TreePop() if node was just opened and end of node is past scrolling limits?
- tree node / selectable render mismatch which is visible if you use them both next to each other (e.g. cf. property viewer)
- tree node: tweak color scheme to distinguish headers from selected tree node (#581)
- tree node: leaf/non-leaf highlight mismatch.
+ - tree node: _NoIndentOnOpen flag? would require to store a per-depth bit mask to store info for pop (or whatever is cheaper)
+ - tree node/opt: could avoid formatting when clipped (flag assuming we don't care about width/height, assume single line height?)
- settings: write more decent code to allow saving/loading new fields: columns, selected tree nodes?
- settings: api for per-tool simple persistent data (bool,int,float,columns sizes,etc.) in .ini file (#437)
@@ -232,29 +264,36 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
- style: a concept of "compact style" that the end-user can easily rely on (e.g. PushStyleCompact()?) that maps to other settings? avoid implementing duplicate helpers such as SmallCheckbox(), etc.
- style: try to make PushStyleVar() more robust to incorrect parameters (to be more friendly to edit & continues situation).
- style: global scale setting.
+ - style: FramePadding could be different for up vs down (#584)
- style: WindowPadding needs to be EVEN as the 0.5 multiplier used on this value probably have a subtle effect on clip rectangle
- style: have a more global HSV setter (e.g. alter hue on all elements). consider replacing active/hovered by offset in HSV space? (#438, #707, #1223)
- style: gradients fill (#1223) ~ 2 bg colors for each fill? tricky with rounded shapes and using textures for corners.
- style editor: color child window height expressed in multiple of line height.
- - log: LogButtons() options for specifying depth and/or hiding depth slider
- log: have more control over the log scope (e.g. stop logging when leaving current tree node scope)
- log: be able to log anything (e.g. right-click on a window/tree-node, shows context menu? log into tty/file/clipboard)
- log: let user copy any window content to clipboard easily (CTRL+C on windows? while moving it? context menu?). code is commented because it fails with multiple Begin/End pairs.
+ - log: obsolete LogButtons() all together.
+ - log: LogButtons() options for specifying depth and/or hiding depth slider
- filters: set a current filter that tree node can automatically query to hide themselves
- filters: handle wild-cards (with implicit leading/trailing *), reg-exprs
- filters: fuzzy matches (may use code at blog.forrestthewoods.com/4cffeed33fdb)
+ - drag and drop: drag tooltip hovering over source widget with IsItemHovered/SetTooltip flickers.
+ - drag and drop: fix/support/options for overlapping drag sources.
- drag and drop: releasing a drop shows the "..." tooltip for one frame - since e13e598 (#1725)
+ - drag and drop: drag source on a group object (would need e.g. an invisible button covering group in EndGroup) https://twitter.com/paniq/status/1121446364909535233
- drag and drop: have some way to know when a drag begin from BeginDragDropSource() pov.
- drag and drop: allow preview tooltip to be submitted from a different place than the drag source. (#1725)
- drag and drop: allow using with other mouse buttons (where activeid won't be set). (#1637)
- drag and drop: make it easier and provide a demo to have tooltip both are source and target site, with a more detailed one on target site (tooltip ordering problem)
- - drag and drop: test with reordering nodes (in a list, or a tree node). (#143)
+ - drag and drop: demo with reordering nodes (in a list, or a tree node). (#143)
- drag and drop: test integrating with os drag and drop (make it easy to do a naive WM_DROPFILE integration)
+ - drag and drop: allow for multiple payload types. (#143)
- drag and drop: make payload optional? (#143)
- - drag and drop: feedback when hovering a modal (cursor?)
+ - drag and drop: (#143) "both an in-process pointer and a promise to generate a serialized version, for whether the drag ends inside or outside the same process"
+ - drag and drop: feedback when hovering a region blocked by modal (mouse cursor "NO"?)
- node/graph editor (#306)
- pie menus patterns (#434)
- markup: simple markup language for color change? (#902)
@@ -265,22 +304,24 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
- font: a CalcTextHeight() helper could run faster than CalcTextSize().y
- font: enforce monospace through ImFontConfig (for icons?) + create dual ImFont output from same input, reusing rasterized data but with different glyphs/AdvanceX
- font: finish CustomRectRegister() to allow mapping Unicode codepoint to custom texture data
+ - font: make it easier to submit own bitmap font (same texture, another texture?). (#2127, #2575)
- font: PushFontSize API (#1018)
- font: MemoryTTF taking ownership confusing/not obvious, maybe default should be opposite?
+ - font: storing MinAdvanceX per font would allow us to skip calculating line width (under a threshold of character count) in loops looking for block width
- font/demo: add tools to show glyphs used by a text blob, display U16 value, list missing glyphs.
- font/demo: demonstrate use of ImFontGlyphRangesBuilder.
- font/atlas: add a missing Glyphs.reserve()
- font/atlas: incremental updates
- font/atlas: dynamic font atlas to avoid baking huge ranges into bitmap and make scaling easier.
- - font/atlas: allow user to submit its own primitive to be rectpacked, and allow to map them on a Unicode point.
- font/draw: vertical and/or rotated text renderer (#705) - vertical is easier clipping wise
- font/draw: need to be able to specify wrap start position.
- font/draw: better reserve policy for large horizontal block of text (shouldn't reserve for all clipped lines)
+ - font/draw: underline, squiggle line rendering helpers.
- font: optimization: for monospace font (like the default one) we can trim IndexXAdvance as long as trailing value is == FallbackXAdvance (need to make sure TAB is still correct), would save on cache line.
- font: add support for kerning, probably optional. A) perhaps default to (32..128)^2 matrix ~ 9K entries = 36KB, then hash for non-ascii?. B) or sparse lookup into per-char list?
- font: add a simpler CalcTextSizeA() api? current one ok but not welcome if user needs to call it directly (without going through ImGui::CalcTextSize)
- - font: fix AddRemapChar() to work before font has been built.
- - font: what would it take to support codepoint higher than 0xFFFF? (smileys, etc.)
+ - font: fix AddRemapChar() to work before atlas has been built.
+ - font: what would it take to support codepoint higher than 0xFFFF? (smileys, etc.) (#2538, #2541)
- font: (api breaking) remove "TTF" from symbol names. also because it now supports OTF.
- font/opt: Considering storing standalone AdvanceX table as 16-bit fixed point integer?
- font/opt: Glyph currently 40 bytes (2+9*4). Consider storing UV as 16 bits integer? (->32 bytes). X0/Y0/X1/Y1 as 16 fixed-point integers? Or X0/Y0 as float and X1/Y1 as fixed8_8?
@@ -301,6 +342,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
- nav/menus: allow pressing Menu to leave a sub-menu.
- nav/menus: a way to access the main menu bar with Alt? (currently needs CTRL+TAB)
- nav/menus: when using the main menu bar, even though we restore focus after, the underlying window loses its title bar highlight during menu manipulation. could we prevent it?
+ - nav/menus: main menu bar currently cannot restore a NULL focus. Could save NavWindow at the time of being focused, similarly to what popup do?
- nav: simulate right-click or context activation? (SHIFT+F10)
- nav: tabs should go through most/all widgets (in submission order?).
- nav: when CTRL-Tab/windowing is active, the HoveredWindow detection doesn't take account of the window display re-ordering.
@@ -312,7 +354,6 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
- focus: SetKeyboardFocusHere() on with >= 0 offset could be done on same frame (else latch and modulate on beginning of next frame)
- focus: unable to use SetKeyboardFocusHere() on clipped widgets. (#787)
- - examples: move ImGui::NewFrame() out of the backend _NewFrame() ?
- viewport: make it possible to have no main/hosting viewport
- viewport: We set ImGuiViewportFlags_NoFocusOnAppearing in a way that is required for GLFW/SDL binding, but could be handled better without
on a custom e.g. Win32 bindings. It prevents newly dragged-out viewports from taking the focus, which makes ALT+F4 more ambiguous.
@@ -332,21 +373,26 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
- inputs: support track pad style scrolling & slider edit.
- inputs/io: backspace and arrows in the context of a text input could use system repeat rate.
- inputs/io: clarify/standardize/expose repeat rate and repeat delays (#1808)
+ - inputs: add mouse cursor for unavailable/no? IDC_NO/SDL_SYSTEM_CURSOR_NO.
+ - inputs/scrolling: support for smooth scrolling (#2462, #2569)
- misc: idle: expose "woken up" boolean (set by inputs) and/or animation time (for cursor blink) for back-end to be able stop refreshing easily.
- misc: idle: if cursor blink if the _only_ visible animation, core imgui could rewrite vertex alpha to avoid CPU pass on ImGui:: calls.
+ - misc: idle: if cursor blink if the _only_ visible animation, could even expose a dirty rectangle that optionally can be leverage by some app to render in a smaller viewport, getting rid of much pixel shading cost.
- misc: make the ImGuiCond values linear (non-power-of-two). internal storage for ImGuiWindow can use integers to combine into flags (Why?)
- misc: provide a way to compile out the entire implementation while providing a dummy API (e.g. #define IMGUI_DUMMY_IMPL)
- misc: PushItemFlag(): add a flag to disable keyboard capture when used with mouse? (#1682)
- misc: use more size_t in public api?
+ - misc: possible compile-time support for string view/range instead of char* would e.g. facilitate usage with Rust (#683)
+ - misc: possible compile-time support for wchar_t instead of char*?
- backend: bgfx? https://gist.github.com/RichardGale/6e2b74bc42b3005e08397236e4be0fd0
- - web/emscriptem: refactor some examples to facilitate integration with emscripten main loop system. (#1713, #336)
- - web/emscriptem: with refactored examples, we could provide a direct imgui_impl_emscripten platform layer (see eg. https://github.com/floooh/sokol-samples/blob/master/html5/imgui-emsc.cc#L42)
+ - emscriptem: with refactored examples, we could provide a direct imgui_impl_emscripten platform layer (see eg. https://github.com/floooh/sokol-samples/blob/master/html5/imgui-emsc.cc#L42)
- remote: make a system like RemoteImGui first-class citizen/project (#75)
- - demo: find a way to demonstrate textures in the examples application, as it such a a common issue for new users.
+ - demo: find a way to demonstrate textures in the examples application, as it such a common issue for new users.
+ - demo: demonstrate using PushStyleVar() in more details.
- demo: add vertical separator demo
- demo: add virtual scrolling example?
- demo: demonstrate Plot offset
@@ -354,6 +400,10 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i
- examples: provide a zero frame-rate/idle example.
- examples: apple: example_apple should be using modern GL3.
- examples: glfw: could go idle when minimized? if (glfwGetWindowAttrib(window, GLFW_ICONIFIED)) { glfwWaitEvents(); continue; } // issue: DeltaTime will be super high on resume, perhaps provide a way to let impl know (#440)
+ - examples: opengl: rename imgui_impl_opengl2 to impl_opengl_legacy and imgui_impl_opengl3 to imgui_impl_opengl? (#1900)
+ - examples: opengl: could use a single vertex buffer and glBufferSubData for uploads?
+ - examples: opengl: explicitly disable GL_STENCIL_TEST in bindings.
+ - examples: vulkan: viewport: support for synchronized swapping of multiple swap chains.
- optimization: replace vsnprintf with stb_printf? or enable the defines/infrastructure to allow it (#1038)
- optimization: add clipping for multi-component widgets (SliderFloatX, ColorEditX, etc.). one problem is that nav branch can't easily clip parent group when there is a move request.
- optimization: add a flag to disable most of rendering, for the case where the user expect to skip it (#335)
diff --git a/docs/issue_template.md b/docs/issue_template.md
index 73330b22..21f0c1a9 100644
--- a/docs/issue_template.md
+++ b/docs/issue_template.md
@@ -3,12 +3,16 @@
1. PLEASE CAREFULLY READ:
https://github.com/ocornut/imgui/issues/2261
-2. IF YOU ARE HAVING AN ISSUE COMPILING/LINKING/RUNNING/DISPLAYING/ADDING FONTS, please post on the "Getting Started" Discourse forum:
-https://discourse.dearimgui.org/c/getting-started
+2. IF YOU ARE HAVING AN ISSUE COMPILING/LINKING/RUNNING/LOADING FONTS, please post on the "Getting Started" Discourse forum:
+https://discourse.dearimgui.org
-3. PLEASE MAKE SURE that you have: read the FAQ in imgui.cpp; explored the contents of ShowDemoWindow() including the Examples menu; searched among Issues; used your IDE to search for keywords in all sources and text files; and read the link provided in (1).
+3. PLEASE MAKE SURE that you have: read the FAQ in imgui.cpp; explored the contents of `ShowDemoWindow()` including the Examples menu; searched among Issues; used your IDE to search for keywords in all sources and text files; and read the link provided in (1).
-4. Delete points 1-4 and PLEASE FILL THE TEMPLATE BELOW before submitting your issue.
+4. Be mindful that messages are being sent to the e-mail box of "Watching" users. Try to proof-read your messages before sending them. Edits are not seen by those users.
+
+5. Delete points 1-5 and PLEASE FILL THE TEMPLATE BELOW before submitting your issue.
+
+Thank you!
----
diff --git a/examples/.gitignore b/examples/.gitignore
index b9e1bb62..d56b94f0 100644
--- a/examples/.gitignore
+++ b/examples/.gitignore
@@ -25,12 +25,16 @@ project.xcworkspace
xcuserdata
## Emscripten output
+*.o.tmp
*.out.js
*.out.wasm
+example_emscripten/example_emscripten.*
## Unix executables
example_glfw_opengl2/example_glfw_opengl2
example_glfw_opengl3/example_glfw_opengl3
+example_glut_opengl2/example_glut_opengl2
+example_null/example_null
example_sdl_opengl2/example_sdl_opengl2
example_sdl_opengl3/example_sdl_opengl3
diff --git a/examples/README.txt b/examples/README.txt
index 0ca44d33..ef595645 100644
--- a/examples/README.txt
+++ b/examples/README.txt
@@ -1,3 +1,5 @@
+-----------------------------------------------------------------------
+ dear imgui, v1.73 WIP
-----------------------------------------------------------------------
examples/README.txt
(This is the README file for the examples/ folder. See docs/ for more documentation)
@@ -27,7 +29,7 @@ This folder contains two things:
They are the in the XXXX_example/ sub-folders.
You can find binaries of some of those example applications at:
- http://www.miracleworld.net/imgui/binaries
+ http://www.dearimgui.org/binaries
---------------------------------------
@@ -90,9 +92,9 @@ Most the example bindings are split in 2 parts:
This is counter-intuitive, but this will get you running faster! Once you better understand how imgui
works and is bound, you can rewrite the code using your own systems.
- - From Dear ImGui 1.XX we added an (optional) feature called "viewport" which allows imgui windows to be
+ - Road-map: Dear ImGui 1.80 (WIP currently in the "docking" branch) will allows imgui windows to be
seamlessly detached from the main application window. This is achieved using an extra layer to the
- platform and renderer bindings, which allows imgui to communicate platform-specific requests such as
+ platform and renderer bindings, which allows Dear ImGui to communicate platform-specific requests such as
"create an additional OS window", "create a render context", "get the OS position of this window" etc.
When using this feature, the coupling with your OS/renderer becomes much tighter than a regular imgui
integration. It is also much more complicated and require more work to integrate correctly.
@@ -106,10 +108,10 @@ Most the example bindings are split in 2 parts:
List of Platforms Bindings in this repository:
imgui_impl_glfw.cpp ; GLFW (Windows, macOS, Linux, etc.) http://www.glfw.org/
- imgui_impl_osx.mm ; macOS native API
+ imgui_impl_osx.mm ; macOS native API (not as feature complete as glfw/sdl back-ends)
imgui_impl_sdl.cpp ; SDL2 (Windows, macOS, Linux, iOS, Android) https://www.libsdl.org
imgui_impl_win32.cpp ; Win32 native API (Windows)
- imgui_impl_freeglut.cpp ; FreeGLUT (if you really miss the 90's)
+ imgui_impl_glut.cpp ; GLUT/FreeGLUT (absolutely not recommended in 2019)
List of Renderer Bindings in this repository:
@@ -118,8 +120,8 @@ List of Renderer Bindings in this repository:
imgui_impl_dx11.cpp ; DirectX11
imgui_impl_dx12.cpp ; DirectX12
imgui_impl_metal.mm ; Metal (with ObjC)
- imgui_impl_opengl2.cpp ; OpenGL2 (legacy, fixed pipeline <- don't use with modern OpenGL context)
- imgui_impl_opengl3.cpp ; OpenGL3, OpenGL ES 2, OpenGL ES 3 (modern programmable pipeline)
+ imgui_impl_opengl2.cpp ; OpenGL 2 (legacy, fixed pipeline <- don't use with modern OpenGL context)
+ imgui_impl_opengl3.cpp ; OpenGL 3/4, OpenGL ES 2, OpenGL ES 3 (modern programmable pipeline)
imgui_impl_vulkan.cpp ; Vulkan
List of high-level Frameworks Bindings in this repository: (combine Platform + Renderer)
@@ -127,13 +129,15 @@ List of high-level Frameworks Bindings in this repository: (combine Platform + R
imgui_impl_allegro5.cpp
imgui_impl_marmalade.cpp
+Note that Dear ImGui works with Emscripten.
+The examples_emscripten/ app uses sdl.cpp + opengl3.cpp but other combinations are possible.
Third-party framework, graphics API and languages bindings are listed at:
https://github.com/ocornut/imgui/wiki/Bindings
Languages: C, C#, ChaiScript, D, Go, Haxe, Java, Lua, Odin, Pascal, PureBasic, Python, Rust, Swift...
- Frameworks: Cinder, Cocoa (OSX), Cocos2d-x, Emscripten, SFML, GML/GameMaker Studio, Irrlicht, Ogre,
- OpenSceneGraph, openFrameworks, LOVE, NanoRT, Nim Game Lib, Qt3d, SFML, Unreal Engine 4...
+ Frameworks: Cinder, Cocoa (OSX), Cocos2d-x, SFML, GML/GameMaker Studio, Irrlicht, Ogre, OpenSceneGraph,
+ openFrameworks, LOVE, NanoRT, Nim Game Lib, Qt3d, SFML, Unreal Engine 4...
Miscellaneous: Software Renderer, RemoteImgui, etc.
@@ -154,33 +158,32 @@ Building:
directly with a command-line compiler.
-example_win32_directx9/
- DirectX9 example, Windows only.
- = main.cpp + imgui_impl_win32.cpp + imgui_impl_dx9.cpp
-
-example_win32_directx10/
- DirectX10 example, Windows only.
- = main.cpp + imgui_impl_win32.cpp + imgui_impl_dx10.cpp
-
-example_win32_directx11/
- DirectX11 example, Windows only.
- = main.cpp + imgui_impl_win32.cpp + imgui_impl_dx11.cpp
-
-example_win32_directx12/
- DirectX12 example, Windows only.
- = main.cpp + imgui_impl_win32.cpp + imgui_impl_dx12.cpp
- This is quite long and tedious, because: DirectX12.
+example_allegro5/
+ Allegro 5 example.
+ = main.cpp + imgui_impl_allegro5.cpp
example_apple_metal/
OSX & iOS + Metal.
= main.m + imgui_impl_osx.mm + imgui_impl_metal.mm
It is based on the "cross-platform" game template provided with Xcode as of Xcode 9.
- (NB: you may still want to use GLFW or SDL which will also support Windows, Linux along with OSX.)
+ (NB: imgui_impl_osx.mm is currently not as feature complete as other platforms back-ends.
+ You may prefer to use the GLFW Or SDL back-ends, which will also support Windows and Linux.)
example_apple_opengl2/
OSX + OpenGL2.
= main.mm + imgui_impl_osx.mm + imgui_impl_opengl2.cpp
- (NB: you may still want to use GLFW or SDL which will also support Windows, Linux along with OSX.)
+ (NB: imgui_impl_osx.mm is currently not as feature complete as other platforms back-ends.
+ You may prefer to use the GLFW Or SDL back-ends, which will also support Windows and Linux.)
+
+example_empscripten:
+ Emcripten + SDL2 + OpenGL3+/ES2/ES3 example.
+ = main.cpp + imgui_impl_sdl.cpp + imgui_impl_opengl3.cpp
+ Note that other examples based on SDL or GLFW + OpenGL could easily be modified to work with Emscripten.
+ We provide this to make the Emscripten differences obvious, and have them not pollute all other examples.
+
+example_glfw_metal/
+ GLFW (Mac) + Metal example.
+ = main.mm + imgui_impl_glfw.cpp + imgui_impl_metal.mm.
example_glfw_opengl2/
GLFW + OpenGL2 example (legacy, fixed pipeline).
@@ -197,11 +200,35 @@ example_glfw_opengl3/
= main.cpp + imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp
This uses more modern OpenGL calls and custom shaders.
Prefer using that if you are using modern OpenGL in your application (anything with shaders).
+ (Please be mindful that accessing OpenGL3+ functions requires a function loader, which are a frequent
+ source for confusion for new users. We use a loader in imgui_impl_opengl3.cpp which may be different
+ from the one your app normally use. Read imgui_impl_opengl3.h for details and how to change it.)
example_glfw_vulkan/
GLFW (Win32, Mac, Linux) + Vulkan example.
= main.cpp + imgui_impl_glfw.cpp + imgui_impl_vulkan.cpp
This is quite long and tedious, because: Vulkan.
+ For this example, the main.cpp file exceptionally use helpers function from imgui_impl_vulkan.h/cpp.
+
+example_glut_opengl2/
+ GLUT (e.g., FreeGLUT on Linux/Windows, GLUT framework on OSX) + OpenGL2.
+ = main.cpp + imgui_impl_glut.cpp + imgui_impl_opengl2.cpp
+ Note that GLUT/FreeGLUT is largely obsolete software, prefer using GLFW or SDL.
+
+example_marmalade/
+ Marmalade example using IwGx.
+ = main.cpp + imgui_impl_marmalade.cpp
+
+example_null
+ Null example, compile and link imgui, create context, run headless with no inputs and no graphics output.
+ = main.cpp
+ This is used to quickly test compilation of core imgui files in as many setups as possible.
+ Because this application doesn't create a window nor a graphic context, there's no graphics output.
+
+example_sdl_directx11/
+ SDL2 + DirectX11 example, Windows only.
+ = main.cpp + imgui_impl_sdl.cpp + imgui_impl_dx11.cpp
+ This to demonstrate usage of DirectX with SDL.
example_sdl_opengl2/
SDL2 (Win32, Mac, Linux etc.) + OpenGL example (legacy, fixed pipeline).
@@ -218,20 +245,29 @@ example_sdl_opengl3/
= main.cpp + imgui_impl_sdl.cpp + imgui_impl_opengl3.cpp
This uses more modern OpenGL calls and custom shaders.
Prefer using that if you are using modern OpenGL in your application (anything with shaders).
+ (Please be mindful that accessing OpenGL3+ functions requires a function loader, which are a frequent
+ source for confusion for new users. We use a loader in imgui_impl_opengl3.cpp which may be different
+ from the one your app normally use. Read imgui_impl_opengl3.h for details and how to change it.)
example_sdl_vulkan/
SDL2 (Win32, Mac, Linux, etc.) + Vulkan example.
= main.cpp + imgui_impl_sdl.cpp + imgui_impl_vulkan.cpp
This is quite long and tedious, because: Vulkan.
+ For this example, the main.cpp file exceptionally use helpers function from imgui_impl_vulkan.h/cpp.
-example_allegro5/
- Allegro 5 example.
- = main.cpp + imgui_impl_allegro5.cpp
+example_win32_directx9/
+ DirectX9 example, Windows only.
+ = main.cpp + imgui_impl_win32.cpp + imgui_impl_dx9.cpp
-example_freeglut_opengl2/
- FreeGLUT + OpenGL2.
- = main.cpp + imgui_impl_freeglut.cpp + imgui_impl_opengl2.cpp
+example_win32_directx10/
+ DirectX10 example, Windows only.
+ = main.cpp + imgui_impl_win32.cpp + imgui_impl_dx10.cpp
-example_marmalade/
- Marmalade example using IwGx.
- = main.cpp + imgui_impl_marmalade.cpp
+example_win32_directx11/
+ DirectX11 example, Windows only.
+ = main.cpp + imgui_impl_win32.cpp + imgui_impl_dx11.cpp
+
+example_win32_directx12/
+ DirectX12 example, Windows only.
+ = main.cpp + imgui_impl_win32.cpp + imgui_impl_dx12.cpp
+ This is quite long and tedious, because: DirectX12.
diff --git a/examples/example_allegro5/README.md b/examples/example_allegro5/README.md
index 5fdcc504..5ef45557 100644
--- a/examples/example_allegro5/README.md
+++ b/examples/example_allegro5/README.md
@@ -1,22 +1,32 @@
# Configuration
-Dear ImGui outputs 16-bit vertex indices by default.
-Allegro doesn't support them natively, so we have two solutions: convert the indices manually in imgui_impl_allegro5.cpp, or compile imgui with 32-bit indices.
+Dear ImGui outputs 16-bit vertex indices by default.
+Allegro doesn't support them natively, so we have two solutions: convert the indices manually in imgui_impl_allegro5.cpp, or compile dear imgui with 32-bit indices.
You can either modify imconfig.h that comes with Dear ImGui (easier), or set a C++ preprocessor option IMGUI_USER_CONFIG to find to a filename.
We are providing `imconfig_allegro5.h` that enables 32-bit indices.
Note that the back-end supports _BOTH_ 16-bit and 32-bit indices, but 32-bit indices will be slightly faster as they won't require a manual conversion.
# How to Build
-- On Ubuntu 14.04+
+### On Ubuntu 14.04+
```bash
-g++ -DIMGUI_USER_CONFIG=\"examples/example_allegro5/imconfig_allegro5.h\" -I .. -I ../.. main.cpp ..\imgui_impl_allegro5.cpp ../../imgui*.cpp -lallegro -lallegro_primitives -o allegro5_example
+g++ -DIMGUI_USER_CONFIG=\"examples/example_allegro5/imconfig_allegro5.h\" -I .. -I ../.. main.cpp ../imgui_impl_allegro5.cpp ../../imgui*.cpp -lallegro -lallegro_primitives -o allegro5_example
```
-- On Windows with Visual Studio's CLI
+### On Windows with Visual Studio's CLI
+You may install Allegro using vcpkg:
+```
+git clone https://github.com/Microsoft/vcpkg
+cd vcpkg
+.\bootstrap-vcpkg.bat
+.\vcpkg install allegro5
+.\vcpkg integrate install ; optional, automatically register include/libs in Visual Studio
+```
+
+Build:
```
set ALLEGRODIR=path_to_your_allegro5_folder
cl /Zi /MD /I %ALLEGRODIR%\include /DIMGUI_USER_CONFIG=\"examples/example_allegro5/imconfig_allegro5.h\" /I .. /I ..\.. main.cpp ..\imgui_impl_allegro5.cpp ..\..\imgui*.cpp /link /LIBPATH:%ALLEGRODIR%\lib allegro-5.0.10-monolith-md.lib user32.lib
diff --git a/examples/example_allegro5/example_allegro5.vcxproj b/examples/example_allegro5/example_allegro5.vcxproj
index b0792697..c86dcb2b 100644
--- a/examples/example_allegro5/example_allegro5.vcxproj
+++ b/examples/example_allegro5/example_allegro5.vcxproj
@@ -21,29 +21,34 @@
{2AE17FDE-F7F3-4CAC-ADAB-0710EDA4F741}example_allegro5
+ 8.1ApplicationtrueMultiByte
+ v110ApplicationtrueMultiByte
+ v110ApplicationfalsetrueMultiByte
+ v110ApplicationfalsetrueMultiByte
+ v110
diff --git a/examples/example_apple_opengl2/example_apple_opengl2.xcodeproj/project.pbxproj b/examples/example_apple_opengl2/example_apple_opengl2.xcodeproj/project.pbxproj
index 20504102..5bdf74b5 100644
--- a/examples/example_apple_opengl2/example_apple_opengl2.xcodeproj/project.pbxproj
+++ b/examples/example_apple_opengl2/example_apple_opengl2.xcodeproj/project.pbxproj
@@ -38,14 +38,11 @@
4080A99F20B034280036BA46 /* imgui_impl_osx.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = imgui_impl_osx.mm; path = ../imgui_impl_osx.mm; sourceTree = ""; };
4080A9A020B034280036BA46 /* imgui_impl_opengl2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = imgui_impl_opengl2.h; path = ../imgui_impl_opengl2.h; sourceTree = ""; };
4080A9A120B034280036BA46 /* imgui_impl_osx.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = imgui_impl_osx.h; path = ../imgui_impl_osx.h; sourceTree = ""; };
- 4080A9A420B0343C0036BA46 /* stb_truetype.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = stb_truetype.h; path = ../../stb_truetype.h; sourceTree = ""; };
4080A9A520B0343C0036BA46 /* imgui_internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = imgui_internal.h; path = ../../imgui_internal.h; sourceTree = ""; };
4080A9A620B0343C0036BA46 /* imgui_demo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = imgui_demo.cpp; path = ../../imgui_demo.cpp; sourceTree = ""; };
4080A9A720B0343C0036BA46 /* imgui.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = imgui.cpp; path = ../../imgui.cpp; sourceTree = ""; };
4080A9A820B0343C0036BA46 /* imgui.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = imgui.h; path = ../../imgui.h; sourceTree = ""; };
- 4080A9A920B0343C0036BA46 /* stb_rect_pack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = stb_rect_pack.h; path = ../../stb_rect_pack.h; sourceTree = ""; };
4080A9AA20B0343C0036BA46 /* imgui_draw.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = imgui_draw.cpp; path = ../../imgui_draw.cpp; sourceTree = ""; };
- 4080A9AB20B0343C0036BA46 /* stb_textedit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = stb_textedit.h; path = ../../stb_textedit.h; sourceTree = ""; };
4080A9AC20B0343C0036BA46 /* imconfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = imconfig.h; path = ../../imconfig.h; sourceTree = ""; };
4080A9B220B034E40036BA46 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
4080A9B420B034EA0036BA46 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = System/Library/Frameworks/OpenGL.framework; sourceTree = SDKROOT; };
@@ -74,9 +71,6 @@
4080A9A620B0343C0036BA46 /* imgui_demo.cpp */,
4080A9AA20B0343C0036BA46 /* imgui_draw.cpp */,
4080A9A520B0343C0036BA46 /* imgui_internal.h */,
- 4080A9A920B0343C0036BA46 /* stb_rect_pack.h */,
- 4080A9AB20B0343C0036BA46 /* stb_textedit.h */,
- 4080A9A420B0343C0036BA46 /* stb_truetype.h */,
4080A99E20B034280036BA46 /* imgui_impl_opengl2.cpp */,
4080A9A020B034280036BA46 /* imgui_impl_opengl2.h */,
4080A9A120B034280036BA46 /* imgui_impl_osx.h */,
diff --git a/examples/example_apple_opengl2/main.mm b/examples/example_apple_opengl2/main.mm
index d4d7a0a9..b5442ec4 100644
--- a/examples/example_apple_opengl2/main.mm
+++ b/examples/example_apple_opengl2/main.mm
@@ -91,14 +91,14 @@
ImGui::Render();
[[self openGLContext] makeCurrentContext];
- ImGuiIO& io = ImGui::GetIO();
- GLsizei width = (GLsizei)(io.DisplaySize.x * io.DisplayFramebufferScale.x);
- GLsizei height = (GLsizei)(io.DisplaySize.y * io.DisplayFramebufferScale.y);
+ ImDrawData* draw_data = ImGui::GetDrawData();
+ GLsizei width = (GLsizei)(draw_data->DisplaySize.x * draw_data->FramebufferScale.x);
+ GLsizei height = (GLsizei)(draw_data->DisplaySize.y * draw_data->FramebufferScale.y);
glViewport(0, 0, width, height);
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
glClear(GL_COLOR_BUFFER_BIT);
- ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());
+ ImGui_ImplOpenGL2_RenderDrawData(draw_data);
// Present
[[self openGLContext] flushBuffer];
diff --git a/examples/example_emscripten/Makefile b/examples/example_emscripten/Makefile
new file mode 100644
index 00000000..9edfafd0
--- /dev/null
+++ b/examples/example_emscripten/Makefile
@@ -0,0 +1,60 @@
+#
+# Makefile to use with emscripten
+# See https://emscripten.org/docs/getting_started/downloads.html
+# for installation instructions. This Makefile assumes you have
+# loaded emscripten's environment.
+#
+# Running `make` will produce three files:
+# - example_emscripten.html
+# - example_emscripten.js
+# - example_emscripten.wasm
+#
+# All three are needed to run the demo.
+
+CC = emcc
+CXX = em++
+
+EXE = example_emscripten.html
+SOURCES = main.cpp
+SOURCES += ../imgui_impl_sdl.cpp ../imgui_impl_opengl3.cpp
+SOURCES += ../../imgui.cpp ../../imgui_demo.cpp ../../imgui_draw.cpp ../../imgui_widgets.cpp
+OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
+UNAME_S := $(shell uname -s)
+
+EMS = -s USE_SDL=2 -s WASM=1
+EMS += -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_TRAP_MODE=clamp
+EMS += -s DISABLE_EXCEPTION_CATCHING=1 -s NO_EXIT_RUNTIME=0
+EMS += -s ASSERTIONS=1 -s NO_FILESYSTEM=1
+#EMS += -s SAFE_HEAP=1 ## Adds overhead
+
+CPPFLAGS = -I../ -I../../
+#CPPFLAGS += -g
+CPPFLAGS += -Wall -Wformat -Os
+CPPFLAGS += $(EMS)
+LIBS = $(EMS)
+LDFLAGS = --shell-file shell_minimal.html
+
+##---------------------------------------------------------------------
+## BUILD RULES
+##---------------------------------------------------------------------
+
+%.o:%.cpp
+ $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
+
+%.o:../%.cpp
+ $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
+
+%.o:../../%.cpp
+ $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
+
+%.o:../libs/gl3w/GL/%.c
+ $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
+
+all: $(EXE)
+ @echo Build complete for $(EXE)
+
+$(EXE): $(OBJS)
+ $(CXX) -o $@ $^ $(LIBS) $(LDFLAGS)
+
+clean:
+ rm -f $(EXE) $(OBJS) *.js *.wasm *.wasm.pre
diff --git a/examples/example_emscripten/README.md b/examples/example_emscripten/README.md
new file mode 100644
index 00000000..c607ed73
--- /dev/null
+++ b/examples/example_emscripten/README.md
@@ -0,0 +1,8 @@
+
+# How to Build
+
+- You need to install Emscripten from https://emscripten.org/docs/getting_started/downloads.html, and have the environment variables set, as described in https://emscripten.org/docs/getting_started/downloads.html#installation-instructions
+
+```
+em++ -I.. -I../.. main.cpp ../imgui_impl_sdl.cpp ../imgui_impl_opengl3.cpp ../../imgui*.cpp -s USE_SDL=2 -s USE_WEBGL2=1 -s WASM=1 -s FULL_ES3=1 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN_TRAP_MODE=clamp --shell-file shell_minimal.html -o example-emscripten.html
+```
diff --git a/examples/example_emscripten/main.cpp b/examples/example_emscripten/main.cpp
new file mode 100644
index 00000000..90055718
--- /dev/null
+++ b/examples/example_emscripten/main.cpp
@@ -0,0 +1,171 @@
+// dear imgui: standalone example application for Emscripten, using SDL2 + OpenGL3
+// This is mostly the same code as the SDL2 + OpenGL3 example, simply with the modifications needed to run on Emscripten.
+// It is possible to combine both code into a single source file that will compile properly on Desktop and using Emscripten.
+// See https://github.com/ocornut/imgui/pull/2492 as an example on how to do just that.
+//
+// If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp.
+// (Emscripten is a C++-to-javascript compiler, used to publish executables for the web. See https://emscripten.org/)
+
+#include "imgui.h"
+#include "imgui_impl_sdl.h"
+#include "imgui_impl_opengl3.h"
+#include
+#include
+#include
+#include
+
+// Emscripten requires to have full control over the main loop. We're going to store our SDL book-keeping variables globally.
+// Having a single function that acts as a loop prevents us to store state in the stack of said function. So we need some location for this.
+SDL_Window* g_Window = NULL;
+SDL_GLContext g_GLContext = NULL;
+
+// For clarity, our main loop code is declared at the end.
+void main_loop(void*);
+
+int main(int, char**)
+{
+ // Setup SDL
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
+ {
+ printf("Error: %s\n", SDL_GetError());
+ return -1;
+ }
+
+ // For the browser using Emscripten, we are going to use WebGL1 with GL ES2. See the Makefile. for requirement details.
+ // It is very likely the generated file won't work in many browsers. Firefox is the only sure bet, but I have successfully
+ // run this code on Chrome for Android for example.
+ const char* glsl_version = "#version 100";
+ //const char* glsl_version = "#version 300 es";
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
+
+ // Create window with graphics context
+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+ SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
+ SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
+ SDL_DisplayMode current;
+ SDL_GetCurrentDisplayMode(0, ¤t);
+ SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
+ g_Window = SDL_CreateWindow("Dear ImGui Emscripten example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);
+ g_GLContext = SDL_GL_CreateContext(g_Window);
+ if (!g_GLContext)
+ {
+ fprintf(stderr, "Failed to initialize WebGL context!\n");
+ return 1;
+ }
+ SDL_GL_SetSwapInterval(1); // Enable vsync
+
+ // Setup Dear ImGui context
+ IMGUI_CHECKVERSION();
+ ImGui::CreateContext();
+ ImGuiIO& io = ImGui::GetIO(); (void)io;
+ io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
+ //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
+ io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
+
+ // For an Emscripten build we are disabling file-system access, so let's not attempt to do a fopen() of the imgui.ini file.
+ // You may manually call LoadIniSettingsFromMemory() to load settings from your own storage.
+ io.IniFilename = NULL;
+
+ // Setup Dear ImGui style
+ ImGui::StyleColorsDark();
+ //ImGui::StyleColorsClassic();
+
+ // Setup Platform/Renderer bindings
+ ImGui_ImplSDL2_InitForOpenGL(g_Window, g_GLContext);
+ ImGui_ImplOpenGL3_Init(glsl_version);
+
+ // Load Fonts
+ // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
+ // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
+ // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
+ // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call.
+ // - Read 'misc/fonts/README.txt' for more instructions and details.
+ // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
+ //io.Fonts->AddFontDefault();
+ //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f);
+ //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f);
+ //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
+ //io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f);
+ //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
+ //IM_ASSERT(font != NULL);
+
+ // This function call won't return, and will engage in an infinite loop, processing events from the browser, and dispatching them.
+ emscripten_set_main_loop_arg(main_loop, NULL, 0, true);
+}
+
+void main_loop(void* arg)
+{
+ ImGuiIO& io = ImGui::GetIO();
+ IM_UNUSED(arg); // We can pass this argument as the second parameter of emscripten_set_main_loop_arg(), but we don't use that.
+
+ // Our state (make them static = more or less global) as a convenience to keep the example terse.
+ static bool show_demo_window = true;
+ static bool show_another_window = false;
+ static ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
+
+ // Poll and handle events (inputs, window resize, etc.)
+ // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
+ // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
+ // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
+ // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
+ SDL_Event event;
+ while (SDL_PollEvent(&event))
+ {
+ ImGui_ImplSDL2_ProcessEvent(&event);
+ // Capture events here, based on io.WantCaptureMouse and io.WantCaptureKeyboard
+ }
+
+ // Start the Dear ImGui frame
+ ImGui_ImplOpenGL3_NewFrame();
+ ImGui_ImplSDL2_NewFrame(g_Window);
+ ImGui::NewFrame();
+
+ // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
+ if (show_demo_window)
+ ImGui::ShowDemoWindow(&show_demo_window);
+
+ // 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window.
+ {
+ static float f = 0.0f;
+ static int counter = 0;
+
+ ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
+
+ ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
+ ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
+ ImGui::Checkbox("Another Window", &show_another_window);
+
+ ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
+ ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
+
+ if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
+ counter++;
+ ImGui::SameLine();
+ ImGui::Text("counter = %d", counter);
+
+ ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
+ ImGui::End();
+ }
+
+ // 3. Show another simple window.
+ if (show_another_window)
+ {
+ ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)
+ ImGui::Text("Hello from another window!");
+ if (ImGui::Button("Close Me"))
+ show_another_window = false;
+ ImGui::End();
+ }
+
+ // Rendering
+ ImGui::Render();
+ SDL_GL_MakeCurrent(g_Window, g_GLContext);
+ glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
+ glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
+ glClear(GL_COLOR_BUFFER_BIT);
+ ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
+ SDL_GL_SwapWindow(g_Window);
+}
diff --git a/examples/example_emscripten/shell_minimal.html b/examples/example_emscripten/shell_minimal.html
new file mode 100644
index 00000000..514385d7
--- /dev/null
+++ b/examples/example_emscripten/shell_minimal.html
@@ -0,0 +1,64 @@
+
+
+
+
+
+ Dear ImGui Emscripten example
+
+
+
+
+
+ {{{ SCRIPT }}}
+
+
diff --git a/examples/example_glfw_metal/Makefile b/examples/example_glfw_metal/Makefile
new file mode 100644
index 00000000..35f17737
--- /dev/null
+++ b/examples/example_glfw_metal/Makefile
@@ -0,0 +1,44 @@
+#
+# You will need GLFW (http://www.glfw.org):
+# brew install glfw
+#
+
+#CXX = g++
+#CXX = clang++
+
+EXE = example_glfw_metal
+SOURCES = main.mm
+SOURCES += ../imgui_impl_glfw.cpp ../imgui_impl_metal.mm
+SOURCES += ../../imgui.cpp ../../imgui_widgets.cpp ../../imgui_demo.cpp ../../imgui_draw.cpp
+OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
+
+LIBS = -framework Metal -framework MetalKit -framework Cocoa -framework IOKit -framework CoreVideo -framework QuartzCore
+LIBS += -L/usr/local/lib -lglfw
+
+CXXFLAGS = -I../ -I../../ -I/usr/local/include
+CXXFLAGS += -Wall -Wformat
+CFLAGS = $(CXXFLAGS)
+
+%.o:%.cpp
+ $(CXX) $(CXXFLAGS) -c -o $@ $<
+
+%.o:../%.cpp
+ $(CXX) $(CXXFLAGS) -c -o $@ $<
+
+%.o:../../%.cpp
+ $(CXX) $(CXXFLAGS) -c -o $@ $<
+
+%.o:../%.mm
+ $(CXX) $(CXXFLAGS) -ObjC++ -fobjc-weak -fobjc-arc -c -o $@ $<
+
+%.o:%.mm
+ $(CXX) $(CXXFLAGS) -ObjC++ -fobjc-weak -fobjc-arc -c -o $@ $<
+
+all: $(EXE)
+ @echo Build complete
+
+$(EXE): $(OBJS)
+ $(CXX) -o $@ $^ $(CXXFLAGS) $(LIBS)
+
+clean:
+ rm -f $(EXE) $(OBJS)
diff --git a/examples/example_glfw_metal/main.mm b/examples/example_glfw_metal/main.mm
new file mode 100644
index 00000000..3a25a9de
--- /dev/null
+++ b/examples/example_glfw_metal/main.mm
@@ -0,0 +1,167 @@
+// ImGui - standalone example application for GLFW + Metal, using programmable pipeline
+// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
+
+#include "imgui.h"
+#include "imgui_impl_glfw.h"
+#include "imgui_impl_metal.h"
+
+#define GLFW_INCLUDE_NONE
+#define GLFW_EXPOSE_NATIVE_COCOA
+#include
+#include
+
+#import
+#import
+
+#include
+
+static void glfw_error_callback(int error, const char* description)
+{
+ fprintf(stderr, "Glfw Error %d: %s\n", error, description);
+}
+
+int main(int, char**)
+{
+ // Setup Dear ImGui binding
+ IMGUI_CHECKVERSION();
+ ImGui::CreateContext();
+ ImGuiIO& io = ImGui::GetIO(); (void)io;
+ //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
+ //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
+
+ // Setup style
+ ImGui::StyleColorsDark();
+ //ImGui::StyleColorsClassic();
+
+ // Load Fonts
+ // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
+ // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
+ // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
+ // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call.
+ // - Read 'misc/fonts/README.txt' for more instructions and details.
+ // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
+ //io.Fonts->AddFontDefault();
+ //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f);
+ //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f);
+ //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
+ //io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f);
+ //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
+ //IM_ASSERT(font != NULL);
+
+ // Setup window
+ glfwSetErrorCallback(glfw_error_callback);
+ if (!glfwInit())
+ return 1;
+
+ // Create window with graphics context
+ glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
+ GLFWwindow* window = glfwCreateWindow(1280, 720, "Dear ImGui GLFW+Metal example", NULL, NULL);
+ if (window == NULL)
+ return 1;
+
+ id device = MTLCreateSystemDefaultDevice();;
+ id commandQueue = [device newCommandQueue];
+
+ ImGui_ImplGlfw_InitForOpenGL(window, true);
+ ImGui_ImplMetal_Init(device);
+
+ NSWindow *nswin = glfwGetCocoaWindow(window);
+ CAMetalLayer *layer = [CAMetalLayer layer];
+ layer.device = device;
+ layer.pixelFormat = MTLPixelFormatBGRA8Unorm;
+ nswin.contentView.layer = layer;
+ nswin.contentView.wantsLayer = YES;
+
+ MTLRenderPassDescriptor *renderPassDescriptor = [MTLRenderPassDescriptor new];
+
+ // Our state
+ bool show_demo_window = true;
+ bool show_another_window = false;
+ float clear_color[4] = {0.45f, 0.55f, 0.60f, 1.00f};
+
+ // Main loop
+ while (!glfwWindowShouldClose(window))
+ {
+ // Poll and handle events (inputs, window resize, etc.)
+ // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
+ // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
+ // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
+ // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
+ glfwPollEvents();
+
+ int width, height;
+ glfwGetFramebufferSize(window, &width, &height);
+ layer.drawableSize = CGSizeMake(width, height);
+ id drawable = [layer nextDrawable];
+
+ id commandBuffer = [commandQueue commandBuffer];
+ renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColorMake(clear_color[0], clear_color[1], clear_color[2], clear_color[3]);
+ renderPassDescriptor.colorAttachments[0].texture = drawable.texture;
+ renderPassDescriptor.colorAttachments[0].loadAction = MTLLoadActionClear;
+ renderPassDescriptor.colorAttachments[0].storeAction = MTLStoreActionStore;
+ id renderEncoder = [commandBuffer renderCommandEncoderWithDescriptor:renderPassDescriptor];
+ [renderEncoder pushDebugGroup:@"ImGui demo"];
+
+ // Start the Dear ImGui frame
+ ImGui_ImplMetal_NewFrame(renderPassDescriptor);
+ ImGui_ImplGlfw_NewFrame();
+ ImGui::NewFrame();
+
+ // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
+ if (show_demo_window)
+ ImGui::ShowDemoWindow(&show_demo_window);
+
+ // 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window.
+ {
+ static float f = 0.0f;
+ static int counter = 0;
+
+ ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
+
+ ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
+ ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
+ ImGui::Checkbox("Another Window", &show_another_window);
+
+ ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
+ ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
+
+ if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
+ counter++;
+ ImGui::SameLine();
+ ImGui::Text("counter = %d", counter);
+
+ ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
+ ImGui::End();
+ }
+
+ // 3. Show another simple window.
+ if (show_another_window)
+ {
+ ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)
+ ImGui::Text("Hello from another window!");
+ if (ImGui::Button("Close Me"))
+ show_another_window = false;
+ ImGui::End();
+ }
+
+ // Rendering
+ ImGui::Render();
+ ImGui_ImplMetal_RenderDrawData(ImGui::GetDrawData(), commandBuffer, renderEncoder);
+
+ [renderEncoder popDebugGroup];
+ [renderEncoder endEncoding];
+
+ [commandBuffer presentDrawable:drawable];
+ [commandBuffer commit];
+ }
+
+ // Cleanup
+ ImGui_ImplMetal_Shutdown();
+ ImGui_ImplGlfw_Shutdown();
+ ImGui::DestroyContext();
+
+ glfwDestroyWindow(window);
+ glfwTerminate();
+
+ return 0;
+}
diff --git a/examples/example_glfw_opengl2/Makefile b/examples/example_glfw_opengl2/Makefile
index 482b0e5d..3649b717 100644
--- a/examples/example_glfw_opengl2/Makefile
+++ b/examples/example_glfw_opengl2/Makefile
@@ -19,39 +19,46 @@ SOURCES = main.cpp
SOURCES += ../imgui_impl_glfw.cpp ../imgui_impl_opengl2.cpp
SOURCES += ../../imgui.cpp ../../imgui_demo.cpp ../../imgui_draw.cpp ../../imgui_widgets.cpp
OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
-
UNAME_S := $(shell uname -s)
+CXXFLAGS = -I../ -I../../
+CXXFLAGS += -g -Wall -Wformat
+LIBS =
+
+##---------------------------------------------------------------------
+## BUILD FLAGS PER PLATFORM
+##---------------------------------------------------------------------
ifeq ($(UNAME_S), Linux) #LINUX
ECHO_MESSAGE = "Linux"
- LIBS = -lGL `pkg-config --static --libs glfw3`
+ LIBS += -lGL `pkg-config --static --libs glfw3`
- CXXFLAGS = -I../ -I../../ `pkg-config --cflags glfw3`
- CXXFLAGS += -Wall -Wformat
+ CXXFLAGS += `pkg-config --cflags glfw3`
CFLAGS = $(CXXFLAGS)
endif
ifeq ($(UNAME_S), Darwin) #APPLE
ECHO_MESSAGE = "Mac OS X"
- LIBS = -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo
- #LIBS += -L/usr/local/lib -lglfw3
- LIBS += -L/usr/local/lib -lglfw
+ LIBS += -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo
+ LIBS += -L/usr/local/lib -L/opt/local/lib
+ #LIBS += -lglfw3
+ LIBS += -lglfw
- CXXFLAGS = -I../ -I../../ -I/usr/local/include
- CXXFLAGS += -Wall -Wformat
+ CXXFLAGS += -I/usr/local/include -I/opt/local/include
CFLAGS = $(CXXFLAGS)
endif
ifeq ($(findstring MINGW,$(UNAME_S)),MINGW)
- ECHO_MESSAGE = "Windows"
- LIBS = -lglfw3 -lgdi32 -lopengl32 -limm32
+ ECHO_MESSAGE = "MinGW"
+ LIBS += -lglfw3 -lgdi32 -lopengl32 -limm32
- CXXFLAGS = -I../ -I../../ -I../libs/gl3w `pkg-config --cflags glfw3`
- CXXFLAGS += -Wall -Wformat
- CFLAGS = $(CXXFLAGS)
+ CXXFLAGS += -I../libs/gl3w `pkg-config --cflags glfw3`
+ CFLAGS = $(CXXFLAGS)
endif
+##---------------------------------------------------------------------
+## BUILD RULES
+##---------------------------------------------------------------------
%.o:%.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
diff --git a/examples/example_glfw_opengl2/example_glfw_opengl2.vcxproj b/examples/example_glfw_opengl2/example_glfw_opengl2.vcxproj
index 73c7ba9d..b265fea0 100644
--- a/examples/example_glfw_opengl2/example_glfw_opengl2.vcxproj
+++ b/examples/example_glfw_opengl2/example_glfw_opengl2.vcxproj
@@ -21,29 +21,34 @@
{9CDA7840-B7A5-496D-A527-E95571496D18}example_glfw_opengl2
+ 8.1ApplicationtrueMultiByte
+ v110ApplicationtrueMultiByte
+ v110ApplicationfalsetrueMultiByte
+ v110ApplicationfalsetrueMultiByte
+ v110
@@ -85,11 +90,11 @@
Level4Disabled
- ..\..;..;$(SolutionDir)\libs\glfw\include;%(AdditionalIncludeDirectories)
+ ..\..;..;..\libs\glfw\include;%(AdditionalIncludeDirectories)true
- $(SolutionDir)\libs\glfw\lib-vc2010-32;%(AdditionalLibraryDirectories)
+ ..\libs\glfw\lib-vc2010-32;%(AdditionalLibraryDirectories)opengl32.lib;glfw3.lib;%(AdditionalDependencies)Consolemsvcrt.lib
@@ -99,11 +104,11 @@
Level4Disabled
- ..\..;..;$(SolutionDir)\libs\glfw\include;%(AdditionalIncludeDirectories)
+ ..\..;..;..\libs\glfw\include;%(AdditionalIncludeDirectories)true
- $(SolutionDir)\libs\glfw\lib-vc2010-64;%(AdditionalLibraryDirectories)
+ ..\libs\glfw\lib-vc2010-64;%(AdditionalLibraryDirectories)opengl32.lib;glfw3.lib;%(AdditionalDependencies)Consolemsvcrt.lib
@@ -115,14 +120,14 @@
MaxSpeedtruetrue
- ..\..;..;$(SolutionDir)\libs\glfw\include;%(AdditionalIncludeDirectories)
+ ..\..;..;..\libs\glfw\include;%(AdditionalIncludeDirectories)falsetruetruetrue
- $(SolutionDir)\libs\glfw\lib-vc2010-32;%(AdditionalLibraryDirectories)
+ ..\libs\glfw\lib-vc2010-32;%(AdditionalLibraryDirectories)opengl32.lib;glfw3.lib;%(AdditionalDependencies)Console
@@ -135,14 +140,14 @@
MaxSpeedtruetrue
- ..\..;..;$(SolutionDir)\libs\glfw\include;%(AdditionalIncludeDirectories)
+ ..\..;..;..\libs\glfw\include;%(AdditionalIncludeDirectories)falsetruetruetrue
- $(SolutionDir)\libs\glfw\lib-vc2010-64;%(AdditionalLibraryDirectories)
+ ..\libs\glfw\lib-vc2010-64;%(AdditionalLibraryDirectories)opengl32.lib;glfw3.lib;%(AdditionalDependencies)Console
diff --git a/examples/example_glfw_opengl2/main.cpp b/examples/example_glfw_opengl2/main.cpp
index 4873b1f9..7d04f273 100644
--- a/examples/example_glfw_opengl2/main.cpp
+++ b/examples/example_glfw_opengl2/main.cpp
@@ -10,6 +10,9 @@
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl2.h"
#include
+#ifdef __APPLE__
+#define GL_SILENCE_DEPRECATION
+#endif
#include
// [Win32] Our example includes a copy of glfw3.lib pre-compiled with VS2010 to maximize ease of testing and compatibility with old VS compilers.
@@ -44,8 +47,8 @@ int main(int, char**)
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
- //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons;
- //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge;
+ //io.ConfigViewportsNoAutoMerge = true;
+ //io.ConfigViewportsNoTaskBarIcon = true;
// Setup Dear ImGui style
ImGui::StyleColorsDark();
@@ -78,6 +81,7 @@ int main(int, char**)
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
//IM_ASSERT(font != NULL);
+ // Our state
bool show_demo_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
diff --git a/examples/example_glfw_opengl3/Makefile b/examples/example_glfw_opengl3/Makefile
index a9c7007f..e8cf4614 100644
--- a/examples/example_glfw_opengl3/Makefile
+++ b/examples/example_glfw_opengl3/Makefile
@@ -21,13 +21,17 @@ SOURCES += ../../imgui.cpp ../../imgui_demo.cpp ../../imgui_draw.cpp ../../imgui
OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
UNAME_S := $(shell uname -s)
+CXXFLAGS = -I../ -I../../
+CXXFLAGS += -g -Wall -Wformat
+LIBS =
+
##---------------------------------------------------------------------
## OPENGL LOADER
##---------------------------------------------------------------------
## Using OpenGL loader: gl3w [default]
SOURCES += ../libs/gl3w/GL/gl3w.c
-CXXFLAGS = -I../libs/gl3w
+CXXFLAGS += -I../libs/gl3w
## Using OpenGL loader: glew
## (This assumes a system-wide installation)
@@ -44,31 +48,29 @@ CXXFLAGS = -I../libs/gl3w
ifeq ($(UNAME_S), Linux) #LINUX
ECHO_MESSAGE = "Linux"
- LIBS = -lGL `pkg-config --static --libs glfw3`
+ LIBS += -lGL `pkg-config --static --libs glfw3`
- CXXFLAGS += -I../ -I../../ `pkg-config --cflags glfw3`
- CXXFLAGS += -Wall -Wformat
+ CXXFLAGS += `pkg-config --cflags glfw3`
CFLAGS = $(CXXFLAGS)
endif
ifeq ($(UNAME_S), Darwin) #APPLE
ECHO_MESSAGE = "Mac OS X"
- LIBS = -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo
- #LIBS += -L/usr/local/lib -lglfw3
- LIBS += -L/usr/local/lib -lglfw
+ LIBS += -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo
+ LIBS += -L/usr/local/lib -L/opt/local/lib
+ #LIBS += -lglfw3
+ LIBS += -lglfw
- CXXFLAGS += -I../ -I../../ -I/usr/local/include
- CXXFLAGS += -Wall -Wformat
+ CXXFLAGS += -I/usr/local/include -I/opt/local/include
CFLAGS = $(CXXFLAGS)
endif
ifeq ($(findstring MINGW,$(UNAME_S)),MINGW)
- ECHO_MESSAGE = "Windows"
- LIBS = -lglfw3 -lgdi32 -lopengl32 -limm32
+ ECHO_MESSAGE = "MinGW"
+ LIBS += -lglfw3 -lgdi32 -lopengl32 -limm32
- CXXFLAGS += -I../ -I../../ `pkg-config --cflags glfw3`
- CXXFLAGS += -Wall -Wformat
- CFLAGS = $(CXXFLAGS)
+ CXXFLAGS += `pkg-config --cflags glfw3`
+ CFLAGS = $(CXXFLAGS)
endif
##---------------------------------------------------------------------
diff --git a/examples/example_glfw_opengl3/example_glfw_opengl3.vcxproj b/examples/example_glfw_opengl3/example_glfw_opengl3.vcxproj
index 172a34d8..47d25380 100644
--- a/examples/example_glfw_opengl3/example_glfw_opengl3.vcxproj
+++ b/examples/example_glfw_opengl3/example_glfw_opengl3.vcxproj
@@ -21,29 +21,34 @@
{4a1fb5ea-22f5-42a8-ab92-1d2df5d47fb9}example_glfw_opengl3
+ 8.1ApplicationtrueMultiByte
+ v110ApplicationtrueMultiByte
+ v110ApplicationfalsetrueMultiByte
+ v110ApplicationfalsetrueMultiByte
+ v110
@@ -85,11 +90,11 @@
Level4Disabled
- ..\..;..;$(SolutionDir)\libs\glfw\include;$(SolutionDir)\libs\gl3w;%(AdditionalIncludeDirectories)
+ ..\..;..;..\libs\glfw\include;..\libs\gl3w;%(AdditionalIncludeDirectories)true
- $(SolutionDir)\libs\glfw\lib-vc2010-32;%(AdditionalLibraryDirectories)
+ ..\libs\glfw\lib-vc2010-32;%(AdditionalLibraryDirectories)opengl32.lib;glfw3.lib;%(AdditionalDependencies)Consolemsvcrt.lib
@@ -99,11 +104,11 @@
Level4Disabled
- ..\..;..;$(SolutionDir)\libs\glfw\include;$(SolutionDir)\libs\gl3w;%(AdditionalIncludeDirectories)
+ ..\..;..;..\libs\glfw\include;..\libs\gl3w;%(AdditionalIncludeDirectories)true
- $(SolutionDir)\libs\glfw\lib-vc2010-64;%(AdditionalLibraryDirectories)
+ ..\libs\glfw\lib-vc2010-64;%(AdditionalLibraryDirectories)opengl32.lib;glfw3.lib;%(AdditionalDependencies)Consolemsvcrt.lib
@@ -115,14 +120,14 @@
MaxSpeedtruetrue
- ..\..;..;$(SolutionDir)\libs\glfw\include;$(SolutionDir)\libs\gl3w;%(AdditionalIncludeDirectories)
+ ..\..;..;..\libs\glfw\include;..\libs\gl3w;%(AdditionalIncludeDirectories)falsetruetruetrue
- $(SolutionDir)\libs\glfw\lib-vc2010-32;%(AdditionalLibraryDirectories)
+ ..\libs\glfw\lib-vc2010-32;%(AdditionalLibraryDirectories)opengl32.lib;glfw3.lib;%(AdditionalDependencies)Console
@@ -135,14 +140,14 @@
MaxSpeedtruetrue
- ..\..;..;$(SolutionDir)\libs\glfw\include;$(SolutionDir)\libs\gl3w;%(AdditionalIncludeDirectories)
+ ..\..;..;..\libs\glfw\include;..\libs\gl3w;%(AdditionalIncludeDirectories)falsetruetruetrue
- $(SolutionDir)\libs\glfw\lib-vc2010-64;%(AdditionalLibraryDirectories)
+ ..\libs\glfw\lib-vc2010-64;%(AdditionalLibraryDirectories)opengl32.lib;glfw3.lib;%(AdditionalDependencies)Console
diff --git a/examples/example_glfw_opengl3/main.cpp b/examples/example_glfw_opengl3/main.cpp
index bb2b1525..a92a1f7b 100644
--- a/examples/example_glfw_opengl3/main.cpp
+++ b/examples/example_glfw_opengl3/main.cpp
@@ -90,8 +90,8 @@ int main(int, char**)
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
- //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons;
- //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge;
+ //io.ConfigViewportsNoAutoMerge = true;
+ //io.ConfigViewportsNoTaskBarIcon = true;
// Setup Dear ImGui style
ImGui::StyleColorsDark();
@@ -124,6 +124,7 @@ int main(int, char**)
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
//IM_ASSERT(font != NULL);
+ // Our state
bool show_demo_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
diff --git a/examples/example_glfw_vulkan/CMakeLists.txt b/examples/example_glfw_vulkan/CMakeLists.txt
index 82d7ab47..68155ec8 100644
--- a/examples/example_glfw_vulkan/CMakeLists.txt
+++ b/examples/example_glfw_vulkan/CMakeLists.txt
@@ -1,3 +1,8 @@
+# Example usage:
+# mkdir build
+# cd build
+# cmake -g "Visual Studio 14 2015" ..
+
cmake_minimum_required(VERSION 2.8)
project(imgui_example_glfw_vulkan C CXX)
@@ -18,7 +23,7 @@ option(GLFW_DOCUMENT_INTERNALS "Include internals in documentation" OFF)
add_subdirectory(${GLFW_DIR} binary_dir EXCLUDE_FROM_ALL)
include_directories(${GLFW_DIR}/include)
-# ImGui
+# Dear ImGui
set(IMGUI_DIR ../../)
include_directories(${IMGUI_DIR} ..)
diff --git a/examples/example_glfw_vulkan/example_glfw_vulkan.vcxproj b/examples/example_glfw_vulkan/example_glfw_vulkan.vcxproj
index b0305e8f..9e2c9b38 100644
--- a/examples/example_glfw_vulkan/example_glfw_vulkan.vcxproj
+++ b/examples/example_glfw_vulkan/example_glfw_vulkan.vcxproj
@@ -1,4 +1,4 @@
-
+
@@ -21,29 +21,34 @@
{57E2DF5A-6FC8-45BB-99DD-91A18C646E80}example_glfw_vulkan
+ 8.1ApplicationtrueMultiByte
+ v110ApplicationtrueMultiByte
+ v110ApplicationfalsetrueMultiByte
+ v110ApplicationfalsetrueMultiByte
+ v110
@@ -85,11 +90,11 @@
Level4Disabled
- ..\..;..;%VULKAN_SDK%\include;$(SolutionDir)\libs\glfw\include;%(AdditionalIncludeDirectories)
+ ..\..;..;%VULKAN_SDK%\include;..\libs\glfw\include;%(AdditionalIncludeDirectories)true
- %VULKAN_SDK%\lib32;$(SolutionDir)\libs\glfw\lib-vc2010-32;%(AdditionalLibraryDirectories)
+ %VULKAN_SDK%\lib32;..\libs\glfw\lib-vc2010-32;%(AdditionalLibraryDirectories)vulkan-1.lib;glfw3.lib;%(AdditionalDependencies)Consolemsvcrt.lib
@@ -99,11 +104,11 @@
Level4Disabled
- ..\..;..;%VULKAN_SDK%\include;$(SolutionDir)\libs\glfw\include;%(AdditionalIncludeDirectories)
+ ..\..;..;%VULKAN_SDK%\include;..\libs\glfw\include;%(AdditionalIncludeDirectories)true
- %VULKAN_SDK%\lib;$(SolutionDir)\libs\glfw\lib-vc2010-64;%(AdditionalLibraryDirectories)
+ %VULKAN_SDK%\lib;..\libs\glfw\lib-vc2010-64;%(AdditionalLibraryDirectories)vulkan-1.lib;glfw3.lib;%(AdditionalDependencies)Consolemsvcrt.lib
@@ -115,14 +120,14 @@
MaxSpeedtruetrue
- ..\..;..;%VULKAN_SDK%\include;$(SolutionDir)\libs\glfw\include;%(AdditionalIncludeDirectories)
+ ..\..;..;%VULKAN_SDK%\include;..\libs\glfw\include;%(AdditionalIncludeDirectories)falsetruetruetrue
- %VULKAN_SDK%\lib32;$(SolutionDir)\libs\glfw\lib-vc2010-32;%(AdditionalLibraryDirectories)
+ %VULKAN_SDK%\lib32;..\libs\glfw\lib-vc2010-32;%(AdditionalLibraryDirectories)vulkan-1.lib;glfw3.lib;%(AdditionalDependencies)Console
@@ -135,14 +140,14 @@
MaxSpeedtruetrue
- ..\..;..;%VULKAN_SDK%\include;$(SolutionDir)\libs\glfw\include;%(AdditionalIncludeDirectories)
+ ..\..;..;%VULKAN_SDK%\include;..\libs\glfw\include;%(AdditionalIncludeDirectories)falsetruetruetrue
- %VULKAN_SDK%\lib;$(SolutionDir)\libs\glfw\lib-vc2010-64;%(AdditionalLibraryDirectories)
+ %VULKAN_SDK%\lib;..\libs\glfw\lib-vc2010-64;%(AdditionalLibraryDirectories)vulkan-1.lib;glfw3.lib;%(AdditionalDependencies)Console
diff --git a/examples/example_glfw_vulkan/glsl_shader.frag b/examples/example_glfw_vulkan/glsl_shader.frag
index 313a8880..ce7e6f72 100644
--- a/examples/example_glfw_vulkan/glsl_shader.frag
+++ b/examples/example_glfw_vulkan/glsl_shader.frag
@@ -3,7 +3,7 @@ layout(location = 0) out vec4 fColor;
layout(set=0, binding=0) uniform sampler2D sTexture;
-layout(location = 0) in struct{
+layout(location = 0) in struct {
vec4 Color;
vec2 UV;
} In;
diff --git a/examples/example_glfw_vulkan/glsl_shader.vert b/examples/example_glfw_vulkan/glsl_shader.vert
index 20b29082..9425365a 100644
--- a/examples/example_glfw_vulkan/glsl_shader.vert
+++ b/examples/example_glfw_vulkan/glsl_shader.vert
@@ -3,16 +3,16 @@ layout(location = 0) in vec2 aPos;
layout(location = 1) in vec2 aUV;
layout(location = 2) in vec4 aColor;
-layout(push_constant) uniform uPushConstant{
+layout(push_constant) uniform uPushConstant {
vec2 uScale;
vec2 uTranslate;
} pc;
-out gl_PerVertex{
+out gl_PerVertex {
vec4 gl_Position;
};
-layout(location = 0) out struct{
+layout(location = 0) out struct {
vec4 Color;
vec2 UV;
} Out;
@@ -21,5 +21,5 @@ void main()
{
Out.Color = aColor;
Out.UV = aUV;
- gl_Position = vec4(aPos*pc.uScale+pc.uTranslate, 0, 1);
+ gl_Position = vec4(aPos * pc.uScale + pc.uTranslate, 0, 1);
}
diff --git a/examples/example_glfw_vulkan/main.cpp b/examples/example_glfw_vulkan/main.cpp
index b2e902e3..308ad788 100644
--- a/examples/example_glfw_vulkan/main.cpp
+++ b/examples/example_glfw_vulkan/main.cpp
@@ -1,6 +1,13 @@
// dear imgui: standalone example application for Glfw + Vulkan
// If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp.
+// Important note to the reader who wish to integrate imgui_impl_vulkan.cpp/.h in their own engine/app.
+// - Common ImGui_ImplVulkan_XXX functions and structures are used to interface with imgui_impl_vulkan.cpp/.h.
+// You will use those if you want to use this rendering back-end in your engine/app.
+// - Helper ImGui_ImplVulkanH_XXX functions and structures are only used by this example (main.cpp) and by
+// the back-end itself (imgui_impl_vulkan.cpp), but should PROBABLY NOT be used by your own engine/app code.
+// Read comments in imgui_impl_vulkan.h.
+
#include "imgui.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_vulkan.h"
@@ -23,19 +30,21 @@
#define IMGUI_VULKAN_DEBUG_REPORT
#endif
-static VkAllocationCallbacks* g_Allocator = NULL;
-static VkInstance g_Instance = VK_NULL_HANDLE;
-static VkPhysicalDevice g_PhysicalDevice = VK_NULL_HANDLE;
-static VkDevice g_Device = VK_NULL_HANDLE;
-static uint32_t g_QueueFamily = (uint32_t)-1;
-static VkQueue g_Queue = VK_NULL_HANDLE;
-static VkDebugReportCallbackEXT g_DebugReport = VK_NULL_HANDLE;
-static VkPipelineCache g_PipelineCache = VK_NULL_HANDLE;
-static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE;
-
-static ImGui_ImplVulkanH_WindowData g_WindowData;
-static bool g_ResizeWanted = false;
-static int g_ResizeWidth = 0, g_ResizeHeight = 0;
+static VkAllocationCallbacks* g_Allocator = NULL;
+static VkInstance g_Instance = VK_NULL_HANDLE;
+static VkPhysicalDevice g_PhysicalDevice = VK_NULL_HANDLE;
+static VkDevice g_Device = VK_NULL_HANDLE;
+static uint32_t g_QueueFamily = (uint32_t)-1;
+static VkQueue g_Queue = VK_NULL_HANDLE;
+static VkDebugReportCallbackEXT g_DebugReport = VK_NULL_HANDLE;
+static VkPipelineCache g_PipelineCache = VK_NULL_HANDLE;
+static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE;
+
+static ImGui_ImplVulkanH_Window g_MainWindowData;
+static int g_MinImageCount = 2;
+static bool g_SwapChainRebuild = false;
+static int g_SwapChainResizeWidth = 0;
+static int g_SwapChainResizeHeight = 0;
static void check_vk_result(VkResult err)
{
@@ -99,6 +108,7 @@ static void SetupVulkan(const char** extensions, uint32_t extensions_count)
// Create Vulkan Instance without any debug feature
err = vkCreateInstance(&create_info, g_Allocator, &g_Instance);
check_vk_result(err);
+ IM_UNUSED(g_DebugReport);
#endif
}
@@ -107,6 +117,7 @@ static void SetupVulkan(const char** extensions, uint32_t extensions_count)
uint32_t gpu_count;
err = vkEnumeratePhysicalDevices(g_Instance, &gpu_count, NULL);
check_vk_result(err);
+ IM_ASSERT(gpu_count > 0);
VkPhysicalDevice* gpus = (VkPhysicalDevice*)malloc(sizeof(VkPhysicalDevice) * gpu_count);
err = vkEnumeratePhysicalDevices(g_Instance, &gpu_count, gpus);
@@ -132,7 +143,7 @@ static void SetupVulkan(const char** extensions, uint32_t extensions_count)
break;
}
free(queues);
- IM_ASSERT(g_QueueFamily != -1);
+ IM_ASSERT(g_QueueFamily != (uint32_t)-1);
}
// Create Logical Device (with 1 queue)
@@ -183,7 +194,9 @@ static void SetupVulkan(const char** extensions, uint32_t extensions_count)
}
}
-static void SetupVulkanWindowData(ImGui_ImplVulkanH_WindowData* wd, VkSurfaceKHR surface, int width, int height)
+// All the ImGui_ImplVulkanH_XXX structures/functions are optional helpers used by the demo.
+// Your real engine/app may not use them.
+static void SetupVulkanWindow(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface, int width, int height)
{
wd->Surface = surface;
@@ -211,14 +224,12 @@ static void SetupVulkanWindowData(ImGui_ImplVulkanH_WindowData* wd, VkSurfaceKHR
//printf("[vulkan] Selected PresentMode = %d\n", wd->PresentMode);
// Create SwapChain, RenderPass, Framebuffer, etc.
- ImGui_ImplVulkanH_CreateWindowDataCommandBuffers(g_PhysicalDevice, g_Device, g_QueueFamily, wd, g_Allocator);
- ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(g_PhysicalDevice, g_Device, wd, g_Allocator, width, height);
+ IM_ASSERT(g_MinImageCount >= 2);
+ ImGui_ImplVulkanH_CreateWindow(g_Instance, g_PhysicalDevice, g_Device, wd, g_QueueFamily, g_Allocator, width, height, g_MinImageCount);
}
static void CleanupVulkan()
{
- ImGui_ImplVulkanH_WindowData* wd = &g_WindowData;
- ImGui_ImplVulkanH_DestroyWindowData(g_Instance, g_Device, wd, g_Allocator);
vkDestroyDescriptorPool(g_Device, g_DescriptorPool, g_Allocator);
#ifdef IMGUI_VULKAN_DEBUG_REPORT
@@ -231,79 +242,86 @@ static void CleanupVulkan()
vkDestroyInstance(g_Instance, g_Allocator);
}
-static void FrameRender(ImGui_ImplVulkanH_WindowData* wd)
+static void CleanupVulkanWindow()
{
- VkResult err;
+ ImGui_ImplVulkanH_DestroyWindow(g_Instance, g_Device, &g_MainWindowData, g_Allocator);
+}
+
+static void FrameRender(ImGui_ImplVulkanH_Window* wd)
+{
+ VkResult err;
+
+ VkSemaphore image_acquired_semaphore = wd->FrameSemaphores[wd->SemaphoreIndex].ImageAcquiredSemaphore;
+ VkSemaphore render_complete_semaphore = wd->FrameSemaphores[wd->SemaphoreIndex].RenderCompleteSemaphore;
+ err = vkAcquireNextImageKHR(g_Device, wd->Swapchain, UINT64_MAX, image_acquired_semaphore, VK_NULL_HANDLE, &wd->FrameIndex);
+ check_vk_result(err);
+
+ ImGui_ImplVulkanH_Frame* fd = &wd->Frames[wd->FrameIndex];
+ {
+ err = vkWaitForFences(g_Device, 1, &fd->Fence, VK_TRUE, UINT64_MAX); // wait indefinitely instead of periodically checking
+ check_vk_result(err);
+
+ err = vkResetFences(g_Device, 1, &fd->Fence);
+ check_vk_result(err);
+ }
+ {
+ err = vkResetCommandPool(g_Device, fd->CommandPool, 0);
+ check_vk_result(err);
+ VkCommandBufferBeginInfo info = {};
+ info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
+ info.flags |= VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
+ err = vkBeginCommandBuffer(fd->CommandBuffer, &info);
+ check_vk_result(err);
+ }
+ {
+ VkRenderPassBeginInfo info = {};
+ info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
+ info.renderPass = wd->RenderPass;
+ info.framebuffer = fd->Framebuffer;
+ info.renderArea.extent.width = wd->Width;
+ info.renderArea.extent.height = wd->Height;
+ info.clearValueCount = 1;
+ info.pClearValues = &wd->ClearValue;
+ vkCmdBeginRenderPass(fd->CommandBuffer, &info, VK_SUBPASS_CONTENTS_INLINE);
+ }
- VkSemaphore& image_acquired_semaphore = wd->Frames[wd->FrameIndex].ImageAcquiredSemaphore;
- err = vkAcquireNextImageKHR(g_Device, wd->Swapchain, UINT64_MAX, image_acquired_semaphore, VK_NULL_HANDLE, &wd->FrameIndex);
- check_vk_result(err);
+ // Record Imgui Draw Data and draw funcs into command buffer
+ ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), fd->CommandBuffer);
- ImGui_ImplVulkanH_FrameData* fd = &wd->Frames[wd->FrameIndex];
+ // Submit command buffer
+ vkCmdEndRenderPass(fd->CommandBuffer);
{
- err = vkWaitForFences(g_Device, 1, &fd->Fence, VK_TRUE, UINT64_MAX); // wait indefinitely instead of periodically checking
- check_vk_result(err);
-
- err = vkResetFences(g_Device, 1, &fd->Fence);
- check_vk_result(err);
- }
- {
- err = vkResetCommandPool(g_Device, fd->CommandPool, 0);
- check_vk_result(err);
- VkCommandBufferBeginInfo info = {};
- info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
- info.flags |= VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
- err = vkBeginCommandBuffer(fd->CommandBuffer, &info);
- check_vk_result(err);
- }
- {
- VkRenderPassBeginInfo info = {};
- info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
- info.renderPass = wd->RenderPass;
- info.framebuffer = wd->Framebuffer[wd->FrameIndex];
- info.renderArea.extent.width = wd->Width;
- info.renderArea.extent.height = wd->Height;
- info.clearValueCount = 1;
- info.pClearValues = &wd->ClearValue;
- vkCmdBeginRenderPass(fd->CommandBuffer, &info, VK_SUBPASS_CONTENTS_INLINE);
- }
-
- // Record Imgui Draw Data and draw funcs into command buffer
- ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), fd->CommandBuffer);
-
- // Submit command buffer
- vkCmdEndRenderPass(fd->CommandBuffer);
- {
- VkPipelineStageFlags wait_stage = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
- VkSubmitInfo info = {};
- info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
- info.waitSemaphoreCount = 1;
- info.pWaitSemaphores = &image_acquired_semaphore;
- info.pWaitDstStageMask = &wait_stage;
- info.commandBufferCount = 1;
- info.pCommandBuffers = &fd->CommandBuffer;
- info.signalSemaphoreCount = 1;
- info.pSignalSemaphores = &fd->RenderCompleteSemaphore;
-
- err = vkEndCommandBuffer(fd->CommandBuffer);
- check_vk_result(err);
- err = vkQueueSubmit(g_Queue, 1, &info, fd->Fence);
- check_vk_result(err);
- }
+ VkPipelineStageFlags wait_stage = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
+ VkSubmitInfo info = {};
+ info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
+ info.waitSemaphoreCount = 1;
+ info.pWaitSemaphores = &image_acquired_semaphore;
+ info.pWaitDstStageMask = &wait_stage;
+ info.commandBufferCount = 1;
+ info.pCommandBuffers = &fd->CommandBuffer;
+ info.signalSemaphoreCount = 1;
+ info.pSignalSemaphores = &render_complete_semaphore;
+
+ err = vkEndCommandBuffer(fd->CommandBuffer);
+ check_vk_result(err);
+ err = vkQueueSubmit(g_Queue, 1, &info, fd->Fence);
+ check_vk_result(err);
+ }
}
-static void FramePresent(ImGui_ImplVulkanH_WindowData* wd)
+static void FramePresent(ImGui_ImplVulkanH_Window* wd)
{
- ImGui_ImplVulkanH_FrameData* fd = &wd->Frames[wd->FrameIndex];
- VkPresentInfoKHR info = {};
- info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
- info.waitSemaphoreCount = 1;
- info.pWaitSemaphores = &fd->RenderCompleteSemaphore;
- info.swapchainCount = 1;
- info.pSwapchains = &wd->Swapchain;
- info.pImageIndices = &wd->FrameIndex;
- VkResult err = vkQueuePresentKHR(g_Queue, &info);
- check_vk_result(err);
+ VkSemaphore render_complete_semaphore = wd->FrameSemaphores[wd->SemaphoreIndex].RenderCompleteSemaphore;
+ VkPresentInfoKHR info = {};
+ info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
+ info.waitSemaphoreCount = 1;
+ info.pWaitSemaphores = &render_complete_semaphore;
+ info.swapchainCount = 1;
+ info.pSwapchains = &wd->Swapchain;
+ info.pImageIndices = &wd->FrameIndex;
+ VkResult err = vkQueuePresentKHR(g_Queue, &info);
+ check_vk_result(err);
+ wd->SemaphoreIndex = (wd->SemaphoreIndex + 1) % wd->ImageCount; // Now we can use the next set of semaphores
}
static void glfw_error_callback(int error, const char* description)
@@ -313,14 +331,14 @@ static void glfw_error_callback(int error, const char* description)
static void glfw_resize_callback(GLFWwindow*, int w, int h)
{
- g_ResizeWanted = true;
- g_ResizeWidth = w;
- g_ResizeHeight = h;
+ g_SwapChainRebuild = true;
+ g_SwapChainResizeWidth = w;
+ g_SwapChainResizeHeight = h;
}
int main(int, char**)
{
- // Setup window
+ // Setup GLFW window
glfwSetErrorCallback(glfw_error_callback);
if (!glfwInit())
return 1;
@@ -347,8 +365,8 @@ int main(int, char**)
int w, h;
glfwGetFramebufferSize(window, &w, &h);
glfwSetFramebufferSizeCallback(window, glfw_resize_callback);
- ImGui_ImplVulkanH_WindowData* wd = &g_WindowData;
- SetupVulkanWindowData(wd, surface, w, h);
+ ImGui_ImplVulkanH_Window* wd = &g_MainWindowData;
+ SetupVulkanWindow(wd, surface, w, h);
// Setup Dear ImGui context
IMGUI_CHECKVERSION();
@@ -358,8 +376,8 @@ int main(int, char**)
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
- //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons;
- //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge;
+ //io.ConfigViewportsNoAutoMerge = true;
+ //io.ConfigViewportsNoTaskBarIcon = true;
// Setup Dear ImGui style
ImGui::StyleColorsDark();
@@ -384,6 +402,8 @@ int main(int, char**)
init_info.PipelineCache = g_PipelineCache;
init_info.DescriptorPool = g_DescriptorPool;
init_info.Allocator = g_Allocator;
+ init_info.MinImageCount = g_MinImageCount;
+ init_info.ImageCount = wd->ImageCount;
init_info.CheckVkResultFn = check_vk_result;
ImGui_ImplVulkan_Init(&init_info, wd->RenderPass);
@@ -429,9 +449,10 @@ int main(int, char**)
err = vkDeviceWaitIdle(g_Device);
check_vk_result(err);
- ImGui_ImplVulkan_InvalidateFontUploadObjects();
+ ImGui_ImplVulkan_DestroyFontUploadObjects();
}
+ // Our state
bool show_demo_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
@@ -445,11 +466,14 @@ int main(int, char**)
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
glfwPollEvents();
- if (g_ResizeWanted)
- {
- ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(g_PhysicalDevice, g_Device, &g_WindowData, g_Allocator, g_ResizeWidth, g_ResizeHeight);
- g_ResizeWanted = false;
- }
+
+ if (g_SwapChainRebuild)
+ {
+ g_SwapChainRebuild = false;
+ ImGui_ImplVulkan_SetMinImageCount(g_MinImageCount);
+ ImGui_ImplVulkanH_CreateWindow(g_Instance, g_PhysicalDevice, g_Device, &g_MainWindowData, g_QueueFamily, g_Allocator, g_SwapChainResizeWidth, g_SwapChainResizeHeight, g_MinImageCount);
+ g_MainWindowData.FrameIndex = 0;
+ }
// Start the Dear ImGui frame
ImGui_ImplVulkan_NewFrame();
@@ -496,7 +520,7 @@ int main(int, char**)
// Rendering
ImGui::Render();
memcpy(&wd->ClearValue.color.float32[0], &clear_color, 4 * sizeof(float));
- FrameRender(wd);
+ FrameRender(wd);
// Update and Render additional Platform Windows
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
@@ -514,6 +538,8 @@ int main(int, char**)
ImGui_ImplVulkan_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
+
+ CleanupVulkanWindow();
CleanupVulkan();
glfwDestroyWindow(window);
diff --git a/examples/example_glut_opengl2/Makefile b/examples/example_glut_opengl2/Makefile
new file mode 100644
index 00000000..c381c0c9
--- /dev/null
+++ b/examples/example_glut_opengl2/Makefile
@@ -0,0 +1,68 @@
+#
+# Cross Platform Makefile
+# Compatible with MSYS2/MINGW, Ubuntu 14.04.1 and Mac OS X
+#
+# Linux:
+# apt-get install freeglut3-dev
+#
+
+#CXX = g++
+#CXX = clang++
+
+EXE = example_glut_opengl2
+SOURCES = main.cpp
+SOURCES += ../imgui_impl_glut.cpp ../imgui_impl_opengl2.cpp
+SOURCES += ../../imgui.cpp ../../imgui_demo.cpp ../../imgui_draw.cpp ../../imgui_widgets.cpp
+OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
+UNAME_S := $(shell uname -s)
+
+CXXFLAGS = -I../ -I../../
+CXXFLAGS += -g -Wall -Wformat
+LIBS =
+
+##---------------------------------------------------------------------
+## BUILD FLAGS PER PLATFORM
+##---------------------------------------------------------------------
+
+ifeq ($(UNAME_S), Linux) #LINUX
+ ECHO_MESSAGE = "Linux"
+ LIBS += -lGL -lglut
+ CFLAGS = $(CXXFLAGS)
+endif
+
+ifeq ($(UNAME_S), Darwin) #APPLE
+ ECHO_MESSAGE = "Mac OS X"
+ LIBS += -framework OpenGL -framework GLUT
+ LIBS += -L/usr/local/lib -L/opt/local/lib
+
+ CXXFLAGS += -I/usr/local/include -I/opt/local/include
+ CFLAGS = $(CXXFLAGS)
+endif
+
+ifeq ($(findstring MINGW,$(UNAME_S)),MINGW)
+ ECHO_MESSAGE = "MinGW"
+ LIBS += -lgdi32 -lopengl32 -limm32 -lglut
+ CFLAGS = $(CXXFLAGS)
+endif
+
+##---------------------------------------------------------------------
+## BUILD RULES
+##---------------------------------------------------------------------
+
+%.o:%.cpp
+ $(CXX) $(CXXFLAGS) -c -o $@ $<
+
+%.o:../%.cpp
+ $(CXX) $(CXXFLAGS) -c -o $@ $<
+
+%.o:../../%.cpp
+ $(CXX) $(CXXFLAGS) -c -o $@ $<
+
+all: $(EXE)
+ @echo Build complete for $(ECHO_MESSAGE)
+
+$(EXE): $(OBJS)
+ $(CXX) -o $@ $^ $(CXXFLAGS) $(LIBS)
+
+clean:
+ rm -f $(EXE) $(OBJS)
diff --git a/examples/example_freeglut_opengl2/example_freeglut_opengl2.vcxproj b/examples/example_glut_opengl2/example_glut_opengl2.vcxproj
similarity index 95%
rename from examples/example_freeglut_opengl2/example_freeglut_opengl2.vcxproj
rename to examples/example_glut_opengl2/example_glut_opengl2.vcxproj
index e3bd4176..9a239516 100644
--- a/examples/example_freeglut_opengl2/example_freeglut_opengl2.vcxproj
+++ b/examples/example_glut_opengl2/example_glut_opengl2.vcxproj
@@ -20,30 +20,35 @@
{F90D0333-5FB1-440D-918D-DD39A1B5187E}
- example_freeglut_opengl2
+ example_glut_opengl2
+ 8.1ApplicationtrueMultiByte
+ v110ApplicationtrueMultiByte
+ v110ApplicationfalsetrueMultiByte
+ v110ApplicationfalsetrueMultiByte
+ v110
@@ -154,7 +159,7 @@
-
+
@@ -162,7 +167,7 @@
-
+
diff --git a/examples/example_freeglut_opengl2/example_freeglut_opengl2.vcxproj.filters b/examples/example_glut_opengl2/example_glut_opengl2.vcxproj.filters
similarity index 93%
rename from examples/example_freeglut_opengl2/example_freeglut_opengl2.vcxproj.filters
rename to examples/example_glut_opengl2/example_glut_opengl2.vcxproj.filters
index eb6d8526..290d43d7 100644
--- a/examples/example_freeglut_opengl2/example_freeglut_opengl2.vcxproj.filters
+++ b/examples/example_glut_opengl2/example_glut_opengl2.vcxproj.filters
@@ -22,7 +22,7 @@
imgui
-
+ sources
@@ -42,7 +42,7 @@
imgui
-
+ sources
@@ -55,4 +55,4 @@
sources
-
\ No newline at end of file
+
diff --git a/examples/example_freeglut_opengl2/main.cpp b/examples/example_glut_opengl2/main.cpp
similarity index 86%
rename from examples/example_freeglut_opengl2/main.cpp
rename to examples/example_glut_opengl2/main.cpp
index 0060371b..b4731264 100644
--- a/examples/example_freeglut_opengl2/main.cpp
+++ b/examples/example_glut_opengl2/main.cpp
@@ -1,16 +1,24 @@
-// dear imgui: standalone example application for FreeGLUT + OpenGL2, using legacy fixed pipeline
+// dear imgui: standalone example application for GLUT/FreeGLUT + OpenGL2, using legacy fixed pipeline
// If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp.
-// (Using GLUT or FreeGLUT is not recommended unless you really miss the 90's)
+
+// !!! GLUT/FreeGLUT IS OBSOLETE SOFTWARE. Using GLUT is not recommended unless you really miss the 90's. !!!
+// !!! If someone or something is teaching you GLUT in 2019, you are being abused. Please show some resistance. !!!
+// !!! Nowadays, prefer using GLFW or SDL instead!
#include "imgui.h"
-#include "../imgui_impl_freeglut.h"
+#include "../imgui_impl_glut.h"
#include "../imgui_impl_opengl2.h"
-#include
+#ifdef __APPLE__
+ #include
+#else
+ #include
+#endif
#ifdef _MSC_VER
#pragma warning (disable: 4505) // unreferenced local function has been removed
#endif
+// Our state
static bool show_demo_window = true;
static bool show_another_window = false;
static ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
@@ -59,7 +67,7 @@ void glut_display_func()
{
// Start the Dear ImGui frame
ImGui_ImplOpenGL2_NewFrame();
- ImGui_ImplFreeGLUT_NewFrame();
+ ImGui_ImplGLUT_NewFrame();
my_display_code();
@@ -85,17 +93,20 @@ int main(int argc, char** argv)
{
// Create GLUT window
glutInit(&argc, argv);
+#ifdef __FREEGLUT_EXT_H__
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
+#endif
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_MULTISAMPLE);
glutInitWindowSize(1280, 720);
- glutCreateWindow("Dear ImGui FreeGLUT+OpenGL2 Example");
+ glutCreateWindow("Dear ImGui GLUT+OpenGL2 Example");
// Setup GLUT display function
- // We will also call ImGui_ImplFreeGLUT_InstallFuncs() to get all the other functions installed for us,
- // otherwise it is possible to install our own functions and call the imgui_impl_freeglut.h functions ourselves.
+ // We will also call ImGui_ImplGLUT_InstallFuncs() to get all the other functions installed for us,
+ // otherwise it is possible to install our own functions and call the imgui_impl_glut.h functions ourselves.
glutDisplayFunc(glut_display_func);
// Setup Dear ImGui context
+ IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
@@ -106,8 +117,8 @@ int main(int argc, char** argv)
//ImGui::StyleColorsClassic();
// Setup Platform/Renderer bindings
- ImGui_ImplFreeGLUT_Init();
- ImGui_ImplFreeGLUT_InstallFuncs();
+ ImGui_ImplGLUT_Init();
+ ImGui_ImplGLUT_InstallFuncs();
ImGui_ImplOpenGL2_Init();
// Load Fonts
@@ -129,7 +140,7 @@ int main(int argc, char** argv)
// Cleanup
ImGui_ImplOpenGL2_Shutdown();
- ImGui_ImplFreeGLUT_Shutdown();
+ ImGui_ImplGLUT_Shutdown();
ImGui::DestroyContext();
return 0;
diff --git a/examples/example_marmalade/main.cpp b/examples/example_marmalade/main.cpp
index 026b0ec7..624d1aa7 100644
--- a/examples/example_marmalade/main.cpp
+++ b/examples/example_marmalade/main.cpp
@@ -45,6 +45,7 @@ int main(int, char**)
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
//IM_ASSERT(font != NULL);
+ // Our state
bool show_demo_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
diff --git a/examples/example_null/Makefile b/examples/example_null/Makefile
new file mode 100644
index 00000000..012758fe
--- /dev/null
+++ b/examples/example_null/Makefile
@@ -0,0 +1,59 @@
+#
+# Cross Platform Makefile
+# Compatible with MSYS2/MINGW, Ubuntu 14.04.1 and Mac OS X
+#
+
+EXE = example_null
+SOURCES = main.cpp
+SOURCES += ../../imgui.cpp ../../imgui_demo.cpp ../../imgui_draw.cpp ../../imgui_widgets.cpp
+OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
+UNAME_S := $(shell uname -s)
+
+CXXFLAGS = -I../ -I../../
+CXXFLAGS += -g -Wall -Wformat
+LIBS =
+
+##---------------------------------------------------------------------
+## BUILD FLAGS PER PLATFORM
+##---------------------------------------------------------------------
+
+ifeq ($(UNAME_S), Linux) #LINUX
+ ECHO_MESSAGE = "Linux"
+ CFLAGS = $(CXXFLAGS)
+endif
+
+ifeq ($(UNAME_S), Darwin) #APPLE
+ ECHO_MESSAGE = "Mac OS X"
+ CFLAGS = $(CXXFLAGS)
+endif
+
+ifeq ($(findstring MINGW,$(UNAME_S)),MINGW)
+ ECHO_MESSAGE = "MinGW"
+ CFLAGS = $(CXXFLAGS)
+endif
+
+##---------------------------------------------------------------------
+## BUILD RULES
+##---------------------------------------------------------------------
+
+%.o:%.cpp
+ $(CXX) $(CXXFLAGS) -c -o $@ $<
+
+%.o:../%.cpp
+ $(CXX) $(CXXFLAGS) -c -o $@ $<
+
+%.o:../../%.cpp
+ $(CXX) $(CXXFLAGS) -c -o $@ $<
+
+%.o:../libs/gl3w/GL/%.c
+# %.o:../libs/glad/src/%.c
+ $(CC) $(CFLAGS) -c -o $@ $<
+
+all: $(EXE)
+ @echo Build complete for $(ECHO_MESSAGE)
+
+$(EXE): $(OBJS)
+ $(CXX) -o $@ $^ $(CXXFLAGS) $(LIBS)
+
+clean:
+ rm -f $(EXE) $(OBJS)
diff --git a/examples/example_null/main.cpp b/examples/example_null/main.cpp
index 90521f9b..aa2f6dba 100644
--- a/examples/example_null/main.cpp
+++ b/examples/example_null/main.cpp
@@ -1,4 +1,6 @@
-// dear imgui: null/dummy example application (compile and link imgui with no inputs, no outputs)
+// dear imgui: null/dummy example application
+// (compile and link imgui, create context, run headless with NO INPUTS, NO GRAPHICS OUTPUT)
+// This is useful to test building, but you cannot interact with anything here!
#include "imgui.h"
#include
@@ -13,7 +15,7 @@ int main(int, char**)
int tex_w, tex_h;
io.Fonts->GetTexDataAsRGBA32(&tex_pixels, &tex_w, &tex_h);
- for (int n = 0; n < 50; n++)
+ for (int n = 0; n < 20; n++)
{
printf("NewFrame() %d\n", n);
io.DisplaySize = ImVec2(1920, 1080);
diff --git a/examples/example_sdl_directx11/build_win32.bat b/examples/example_sdl_directx11/build_win32.bat
new file mode 100644
index 00000000..8fc702bb
--- /dev/null
+++ b/examples/example_sdl_directx11/build_win32.bat
@@ -0,0 +1,8 @@
+@REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler.
+set OUT_DIR=Debug
+set OUT_EXE=example_sdl_directx11
+set INCLUDES=/I.. /I..\.. /I%SDL2_DIR%\include /I "%WindowsSdkDir%Include\um" /I "%WindowsSdkDir%Include\shared" /I "%DXSDK_DIR%Include"
+set SOURCES=main.cpp ..\imgui_impl_sdl.cpp ..\imgui_impl_dx11.cpp ..\..\imgui*.cpp
+set LIBS=/libpath:%SDL2_DIR%\lib\x86 SDL2.lib SDL2main.lib /LIBPATH:"%DXSDK_DIR%/Lib/x86" d3d11.lib d3dcompiler.lib
+mkdir %OUT_DIR%
+cl /nologo /Zi /MD %INCLUDES% %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% /subsystem:console
diff --git a/examples/example_sdl_directx11/example_sdl_directx11.vcxproj b/examples/example_sdl_directx11/example_sdl_directx11.vcxproj
new file mode 100644
index 00000000..e28a5d25
--- /dev/null
+++ b/examples/example_sdl_directx11/example_sdl_directx11.vcxproj
@@ -0,0 +1,181 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ Win32
+
+
+ Release
+ x64
+
+
+
+ {9E1987E3-1F19-45CA-B9C9-D31E791836D8}
+ example_sdl_directx11
+ 8.1
+ example_sdl_directx11
+
+
+
+ Application
+ true
+ MultiByte
+ v110
+
+
+ Application
+ true
+ MultiByte
+ v110
+
+
+ Application
+ false
+ true
+ MultiByte
+ v110
+
+
+ Application
+ false
+ true
+ MultiByte
+ v110
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $(ProjectDir)$(Configuration)\
+ $(ProjectDir)$(Configuration)\
+ $(IncludePath)
+
+
+ $(ProjectDir)$(Configuration)\
+ $(ProjectDir)$(Configuration)\
+ $(IncludePath)
+
+
+ $(ProjectDir)$(Configuration)\
+ $(ProjectDir)$(Configuration)\
+ $(IncludePath)
+
+
+ $(ProjectDir)$(Configuration)\
+ $(ProjectDir)$(Configuration)\
+ $(IncludePath)
+
+
+
+ Level4
+ Disabled
+ ..\..;..;%SDL2_DIR%\include;%(AdditionalIncludeDirectories)
+
+
+ true
+ %SDL2_DIR%\lib\x86;$(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories)
+ SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies)
+ Console
+ msvcrt.lib
+
+
+
+
+ Level4
+ Disabled
+ ..\..;..;%SDL2_DIR%\include;%(AdditionalIncludeDirectories)
+
+
+ true
+ %SDL2_DIR%\lib\x64;$(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories)
+ SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies)
+ Console
+ msvcrt.lib
+
+
+
+
+ Level4
+ MaxSpeed
+ true
+ true
+ ..\..;..;%SDL2_DIR%\include;%(AdditionalIncludeDirectories)
+ false
+
+
+ true
+ true
+ true
+ %SDL2_DIR%\lib\x86;$(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories)
+ SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies)
+ Console
+
+
+
+
+
+
+ Level4
+ MaxSpeed
+ true
+ true
+ ..\..;..;%SDL2_DIR%\include;%(AdditionalIncludeDirectories)
+ false
+
+
+ true
+ true
+ true
+ %SDL2_DIR%\lib\x64;$(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories)
+ SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies)
+ Console
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/example_sdl_directx11/example_sdl_directx11.vcxproj.filters b/examples/example_sdl_directx11/example_sdl_directx11.vcxproj.filters
new file mode 100644
index 00000000..b2345067
--- /dev/null
+++ b/examples/example_sdl_directx11/example_sdl_directx11.vcxproj.filters
@@ -0,0 +1,57 @@
+
+
+
+
+ {0587d7a3-f2ce-4d56-b84f-a0005d3bfce6}
+
+
+ {08e36723-ce4f-4cff-9662-c40801cf1acf}
+
+
+
+
+ imgui
+
+
+ imgui
+
+
+ imgui
+
+
+ sources
+
+
+ sources
+
+
+
+
+ imgui
+
+
+ sources
+
+
+ imgui
+
+
+ imgui
+
+
+ sources
+
+
+ imgui
+
+
+ sources
+
+
+
+
+
+ sources
+
+
+
\ No newline at end of file
diff --git a/examples/example_sdl_directx11/main.cpp b/examples/example_sdl_directx11/main.cpp
new file mode 100644
index 00000000..3c7ee18e
--- /dev/null
+++ b/examples/example_sdl_directx11/main.cpp
@@ -0,0 +1,238 @@
+// dear imgui: standalone example application for SDL2 + DirectX 11
+// If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp.
+// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
+
+#include "imgui.h"
+#include "imgui_impl_sdl.h"
+#include "imgui_impl_dx11.h"
+#include
+#include
+#include
+#include
+
+// Data
+static ID3D11Device* g_pd3dDevice = NULL;
+static ID3D11DeviceContext* g_pd3dDeviceContext = NULL;
+static IDXGISwapChain* g_pSwapChain = NULL;
+static ID3D11RenderTargetView* g_mainRenderTargetView = NULL;
+
+// Forward declarations of helper functions
+bool CreateDeviceD3D(HWND hWnd);
+void CleanupDeviceD3D();
+void CreateRenderTarget();
+void CleanupRenderTarget();
+
+// Main code
+int main(int, char**)
+{
+ // Setup SDL
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
+ {
+ printf("Error: %s\n", SDL_GetError());
+ return -1;
+ }
+
+ // Setup window
+ SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
+ SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+DirectX11 example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);
+ SDL_SysWMinfo wmInfo;
+ SDL_VERSION(&wmInfo.version);
+ SDL_GetWindowWMInfo(window, &wmInfo);
+ HWND hwnd = (HWND)wmInfo.info.win.window;
+
+ // Initialize Direct3D
+ if (!CreateDeviceD3D(hwnd))
+ {
+ CleanupDeviceD3D();
+ return 1;
+ }
+
+ // Setup Dear ImGui context
+ IMGUI_CHECKVERSION();
+ ImGui::CreateContext();
+ ImGuiIO& io = ImGui::GetIO(); (void)io;
+ io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
+ //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
+ io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
+ io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
+ //io.ConfigViewportsNoAutoMerge = true;
+ //io.ConfigViewportsNoTaskBarIcon = true;
+
+ // Setup Dear ImGui style
+ ImGui::StyleColorsDark();
+ //ImGui::StyleColorsClassic();
+
+ // When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones.
+ ImGuiStyle& style = ImGui::GetStyle();
+ if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
+ {
+ style.WindowRounding = 0.0f;
+ style.Colors[ImGuiCol_WindowBg].w = 1.0f;
+ }
+
+ // Setup Platform/Renderer bindings
+ ImGui_ImplSDL2_InitForD3D(window);
+ ImGui_ImplDX11_Init(g_pd3dDevice, g_pd3dDeviceContext);
+
+ // Load Fonts
+ // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
+ // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
+ // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
+ // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call.
+ // - Read 'misc/fonts/README.txt' for more instructions and details.
+ // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
+ //io.Fonts->AddFontDefault();
+ //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f);
+ //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f);
+ //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
+ //io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f);
+ //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
+ //IM_ASSERT(font != NULL);
+
+ // Our state
+ bool show_demo_window = true;
+ bool show_another_window = false;
+ ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
+
+ // Main loop
+ bool done = false;
+ while (!done)
+ {
+ // Poll and handle events (inputs, window resize, etc.)
+ // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
+ // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
+ // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
+ // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
+ SDL_Event event;
+ while (SDL_PollEvent(&event))
+ {
+ ImGui_ImplSDL2_ProcessEvent(&event);
+ if (event.type == SDL_QUIT)
+ done = true;
+ if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
+ done = true;
+ }
+
+ // Start the Dear ImGui frame
+ ImGui_ImplDX11_NewFrame();
+ ImGui_ImplSDL2_NewFrame(window);
+ ImGui::NewFrame();
+
+ // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
+ if (show_demo_window)
+ ImGui::ShowDemoWindow(&show_demo_window);
+
+ // 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window.
+ {
+ static float f = 0.0f;
+ static int counter = 0;
+
+ ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
+
+ ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
+ ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
+ ImGui::Checkbox("Another Window", &show_another_window);
+
+ ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
+ ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
+
+ if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
+ counter++;
+ ImGui::SameLine();
+ ImGui::Text("counter = %d", counter);
+
+ ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
+ ImGui::End();
+ }
+
+ // 3. Show another simple window.
+ if (show_another_window)
+ {
+ ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)
+ ImGui::Text("Hello from another window!");
+ if (ImGui::Button("Close Me"))
+ show_another_window = false;
+ ImGui::End();
+ }
+
+ // Rendering
+ ImGui::Render();
+ g_pd3dDeviceContext->OMSetRenderTargets(1, &g_mainRenderTargetView, NULL);
+ g_pd3dDeviceContext->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_color);
+ ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
+
+ // Update and Render additional Platform Windows
+ if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
+ {
+ ImGui::UpdatePlatformWindows();
+ ImGui::RenderPlatformWindowsDefault();
+ }
+
+ g_pSwapChain->Present(1, 0); // Present with vsync
+ //g_pSwapChain->Present(0, 0); // Present without vsync
+ }
+
+ // Cleanup
+ ImGui_ImplDX11_Shutdown();
+ ImGui_ImplSDL2_Shutdown();
+ ImGui::DestroyContext();
+
+ CleanupDeviceD3D();
+ SDL_DestroyWindow(window);
+ SDL_Quit();
+
+ return 0;
+}
+
+// Helper functions
+
+bool CreateDeviceD3D(HWND hWnd)
+{
+ // Setup swap chain
+ DXGI_SWAP_CHAIN_DESC sd;
+ ZeroMemory(&sd, sizeof(sd));
+ sd.BufferCount = 2;
+ sd.BufferDesc.Width = 0;
+ sd.BufferDesc.Height = 0;
+ sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
+ sd.BufferDesc.RefreshRate.Numerator = 60;
+ sd.BufferDesc.RefreshRate.Denominator = 1;
+ sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
+ sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
+ sd.OutputWindow = hWnd;
+ sd.SampleDesc.Count = 1;
+ sd.SampleDesc.Quality = 0;
+ sd.Windowed = TRUE;
+ sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
+
+ UINT createDeviceFlags = 0;
+ //createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
+ D3D_FEATURE_LEVEL featureLevel;
+ const D3D_FEATURE_LEVEL featureLevelArray[2] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0, };
+ if (D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, featureLevelArray, 2, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceContext) != S_OK)
+ return false;
+
+ CreateRenderTarget();
+ return true;
+}
+
+void CleanupDeviceD3D()
+{
+ CleanupRenderTarget();
+ if (g_pSwapChain) { g_pSwapChain->Release(); g_pSwapChain = NULL; }
+ if (g_pd3dDeviceContext) { g_pd3dDeviceContext->Release(); g_pd3dDeviceContext = NULL; }
+ if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; }
+}
+
+void CreateRenderTarget()
+{
+ ID3D11Texture2D* pBackBuffer;
+ g_pSwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer));
+ g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &g_mainRenderTargetView);
+ pBackBuffer->Release();
+}
+
+void CleanupRenderTarget()
+{
+ if (g_mainRenderTargetView) { g_mainRenderTargetView->Release(); g_mainRenderTargetView = NULL; }
+}
diff --git a/examples/example_sdl_opengl2/Makefile b/examples/example_sdl_opengl2/Makefile
index 4a948aa4..ce29a249 100644
--- a/examples/example_sdl_opengl2/Makefile
+++ b/examples/example_sdl_opengl2/Makefile
@@ -15,40 +15,49 @@
#CXX = clang++
EXE = example_sdl_opengl2
-SOURCES = main.cpp ../imgui_impl_sdl.cpp ../imgui_impl_opengl2.cpp
+SOURCES = main.cpp
+SOURCES += ../imgui_impl_sdl.cpp ../imgui_impl_opengl2.cpp
SOURCES += ../../imgui.cpp ../../imgui_demo.cpp ../../imgui_draw.cpp ../../imgui_widgets.cpp
OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
-
UNAME_S := $(shell uname -s)
+CXXFLAGS = -I../ -I../../
+CXXFLAGS += -g -Wall -Wformat
+LIBS =
+
+##---------------------------------------------------------------------
+## BUILD FLAGS PER PLATFORM
+##---------------------------------------------------------------------
ifeq ($(UNAME_S), Linux) #LINUX
ECHO_MESSAGE = "Linux"
- LIBS = -lGL -ldl `sdl2-config --libs`
+ LIBS += -lGL -ldl `sdl2-config --libs`
- CXXFLAGS = -I ../ -I../../ `sdl2-config --cflags`
- CXXFLAGS += -Wall -Wformat
+ CXXFLAGS += `sdl2-config --cflags`
CFLAGS = $(CXXFLAGS)
endif
ifeq ($(UNAME_S), Darwin) #APPLE
ECHO_MESSAGE = "Mac OS X"
- LIBS = -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo `sdl2-config --libs`
+ LIBS += -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo `sdl2-config --libs`
+ LIBS += -L/usr/local/lib -L/opt/local/lib
- CXXFLAGS = -I ../ -I../../ -I/usr/local/include `sdl2-config --cflags`
- CXXFLAGS += -Wall -Wformat
+ CXXFLAGS += `sdl2-config --cflags`
+ CXXFLAGS += -I/usr/local/include -I/opt/local/include
CFLAGS = $(CXXFLAGS)
endif
ifeq ($(findstring MINGW,$(UNAME_S)),MINGW)
- ECHO_MESSAGE = "Windows"
- LIBS = -lgdi32 -lopengl32 -limm32 `pkg-config --static --libs sdl2`
+ ECHO_MESSAGE = "MinGW"
+ LIBS += -lgdi32 -lopengl32 -limm32 `pkg-config --static --libs sdl2`
- CXXFLAGS = -I ../ -I../../ `pkg-config --cflags sdl2`
- CXXFLAGS += -Wall -Wformat
- CFLAGS = $(CXXFLAGS)
+ CXXFLAGS += `pkg-config --cflags sdl2`
+ CFLAGS = $(CXXFLAGS)
endif
+##---------------------------------------------------------------------
+## BUILD RULES
+##---------------------------------------------------------------------
%.o:%.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
diff --git a/examples/example_sdl_opengl2/build_win32.bat b/examples/example_sdl_opengl2/build_win32.bat
index 97692d9e..d209b2a2 100644
--- a/examples/example_sdl_opengl2/build_win32.bat
+++ b/examples/example_sdl_opengl2/build_win32.bat
@@ -1,8 +1,8 @@
@REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler.
set OUT_DIR=Debug
-set OUT_EXE=example_sdl_opengl2.exe
+set OUT_EXE=example_sdl_opengl2
set INCLUDES=/I.. /I..\.. /I%SDL2_DIR%\include
set SOURCES=main.cpp ..\imgui_impl_sdl.cpp ..\imgui_impl_opengl2.cpp ..\..\imgui*.cpp
set LIBS=/libpath:%SDL2_DIR%\lib\x86 SDL2.lib SDL2main.lib opengl32.lib
mkdir %OUT_DIR%
-cl /nologo /Zi /MD %INCLUDES% %SOURCES% /Fe%OUT_DIR%/%OUT_DIR%.exe /Fo%OUT_DIR%/ /link %LIBS% /subsystem:console
+cl /nologo /Zi /MD %INCLUDES% %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% /subsystem:console
diff --git a/examples/example_sdl_opengl2/example_sdl_opengl2.vcxproj b/examples/example_sdl_opengl2/example_sdl_opengl2.vcxproj
index af7637ec..83a6a8a0 100644
--- a/examples/example_sdl_opengl2/example_sdl_opengl2.vcxproj
+++ b/examples/example_sdl_opengl2/example_sdl_opengl2.vcxproj
@@ -21,29 +21,34 @@
{2AE17FDE-F7F3-4CAC-ADAB-0710EDA4F741}example_sdl_opengl2
+ 8.1ApplicationtrueMultiByte
+ v110ApplicationtrueMultiByte
+ v110ApplicationfalsetrueMultiByte
+ v110ApplicationfalsetrueMultiByte
+ v110
@@ -85,7 +90,7 @@
Level4Disabled
- ..\..;..;%SDL2_DIR%\include;$(SolutionDir)\libs\gl3w;%(AdditionalIncludeDirectories)
+ ..\..;..;%SDL2_DIR%\include;%(AdditionalIncludeDirectories)true
@@ -99,7 +104,7 @@
Level4Disabled
- ..\..;..;%SDL2_DIR%\include;$(SolutionDir)\libs\gl3w;%(AdditionalIncludeDirectories)
+ ..\..;..;%SDL2_DIR%\include;%(AdditionalIncludeDirectories)true
@@ -115,7 +120,7 @@
MaxSpeedtruetrue
- ..\..;..;%SDL2_DIR%\include;$(SolutionDir)\libs\gl3w;%(AdditionalIncludeDirectories)
+ ..\..;..;%SDL2_DIR%\include;%(AdditionalIncludeDirectories)false
@@ -135,7 +140,7 @@
MaxSpeedtruetrue
- ..\..;..;%SDL2_DIR%\include;$(SolutionDir)\libs\gl3w;%(AdditionalIncludeDirectories)
+ ..\..;..;%SDL2_DIR%\include;%(AdditionalIncludeDirectories)false
diff --git a/examples/example_sdl_opengl2/main.cpp b/examples/example_sdl_opengl2/main.cpp
index c69c9489..f811fcf5 100644
--- a/examples/example_sdl_opengl2/main.cpp
+++ b/examples/example_sdl_opengl2/main.cpp
@@ -13,10 +13,11 @@
#include
#include
+// Main code
int main(int, char**)
{
// Setup SDL
- if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) != 0)
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
{
printf("Error: %s\n", SDL_GetError());
return -1;
@@ -28,9 +29,8 @@ int main(int, char**)
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
- SDL_DisplayMode current;
- SDL_GetCurrentDisplayMode(0, ¤t);
- SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+OpenGL example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE);
+ SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
+ SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+OpenGL example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
SDL_GL_MakeCurrent(window, gl_context);
SDL_GL_SetSwapInterval(1); // Enable vsync
@@ -40,10 +40,11 @@ int main(int, char**)
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
+ //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
- //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons;
- //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge;
+ //io.ConfigViewportsNoAutoMerge = true;
+ //io.ConfigViewportsNoTaskBarIcon = true;
// Setup Dear ImGui style
ImGui::StyleColorsDark();
@@ -76,6 +77,7 @@ int main(int, char**)
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
//IM_ASSERT(font != NULL);
+ // Our state
bool show_demo_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
diff --git a/examples/example_sdl_opengl3/Makefile b/examples/example_sdl_opengl3/Makefile
index 69874119..76601a1b 100644
--- a/examples/example_sdl_opengl3/Makefile
+++ b/examples/example_sdl_opengl3/Makefile
@@ -21,13 +21,17 @@ SOURCES += ../../imgui.cpp ../../imgui_demo.cpp ../../imgui_draw.cpp ../../imgui
OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
UNAME_S := $(shell uname -s)
+CXXFLAGS = -I../ -I../../
+CXXFLAGS += -g -Wall -Wformat
+LIBS =
+
##---------------------------------------------------------------------
## OPENGL LOADER
##---------------------------------------------------------------------
## Using OpenGL loader: gl3w [default]
SOURCES += ../libs/gl3w/GL/gl3w.c
-CXXFLAGS = -I../libs/gl3w
+CXXFLAGS += -I../libs/gl3w
## Using OpenGL loader: glew
## (This assumes a system-wide installation)
@@ -44,28 +48,27 @@ CXXFLAGS = -I../libs/gl3w
ifeq ($(UNAME_S), Linux) #LINUX
ECHO_MESSAGE = "Linux"
- LIBS = -lGL -ldl `sdl2-config --libs`
+ LIBS += -lGL -ldl `sdl2-config --libs`
- CXXFLAGS = -I../ -I../../ -I../libs/gl3w `sdl2-config --cflags`
- CXXFLAGS += -Wall -Wformat
+ CXXFLAGS += -I../libs/gl3w `sdl2-config --cflags`
CFLAGS = $(CXXFLAGS)
endif
ifeq ($(UNAME_S), Darwin) #APPLE
ECHO_MESSAGE = "Mac OS X"
- LIBS = -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo `sdl2-config --libs`
+ LIBS += -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo `sdl2-config --libs`
+ LIBS += -L/usr/local/lib -L/opt/local/lib
- CXXFLAGS = -I../ -I../../ -I../libs/gl3w -I/usr/local/include `sdl2-config --cflags`
- CXXFLAGS += -Wall -Wformat
+ CXXFLAGS += -I../libs/gl3w `sdl2-config --cflags`
+ CXXFLAGS += -I/usr/local/include -I/opt/local/include
CFLAGS = $(CXXFLAGS)
endif
ifeq ($(findstring MINGW,$(UNAME_S)),MINGW)
- ECHO_MESSAGE = "Windows"
- LIBS = -lgdi32 -lopengl32 -limm32 `pkg-config --static --libs sdl2`
+ ECHO_MESSAGE = "MinGW"
+ LIBS += -lgdi32 -lopengl32 -limm32 `pkg-config --static --libs sdl2`
- CXXFLAGS = -I../ -I../../ -I../libs/gl3w `pkg-config --cflags sdl2`
- CXXFLAGS += -Wall -Wformat
+ CXXFLAGS += -I../libs/gl3w `pkg-config --cflags sdl2`
CFLAGS = $(CXXFLAGS)
endif
diff --git a/examples/example_sdl_opengl3/build_win32.bat b/examples/example_sdl_opengl3/build_win32.bat
index f263c4b3..ce105602 100644
--- a/examples/example_sdl_opengl3/build_win32.bat
+++ b/examples/example_sdl_opengl3/build_win32.bat
@@ -1,6 +1,6 @@
@REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler.
set OUT_DIR=Debug
-set OUT_EXE=example_sdl_opengl3.exe
+set OUT_EXE=example_sdl_opengl3
set INCLUDES=/I.. /I..\.. /I%SDL2_DIR%\include /I..\libs\gl3w
set SOURCES=main.cpp ..\imgui_impl_sdl.cpp ..\imgui_impl_opengl3.cpp ..\..\imgui*.cpp ..\libs\gl3w\GL\gl3w.c
set LIBS=/libpath:%SDL2_DIR%\lib\x86 SDL2.lib SDL2main.lib opengl32.lib
diff --git a/examples/example_sdl_opengl3/example_sdl_opengl3.vcxproj b/examples/example_sdl_opengl3/example_sdl_opengl3.vcxproj
index 9fda1897..54aaa796 100644
--- a/examples/example_sdl_opengl3/example_sdl_opengl3.vcxproj
+++ b/examples/example_sdl_opengl3/example_sdl_opengl3.vcxproj
@@ -21,29 +21,34 @@
{BBAEB705-1669-40F3-8567-04CF6A991F4C}example_sdl_opengl3
+ 8.1ApplicationtrueMultiByte
+ v110ApplicationtrueMultiByte
+ v110ApplicationfalsetrueMultiByte
+ v110ApplicationfalsetrueMultiByte
+ v110
@@ -85,7 +90,7 @@
Level4Disabled
- ..\..;..;%SDL2_DIR%\include;$(SolutionDir)\libs\gl3w;%(AdditionalIncludeDirectories)
+ ..\..;..;%SDL2_DIR%\include;..\libs\gl3w;%(AdditionalIncludeDirectories)true
@@ -99,7 +104,7 @@
Level4Disabled
- ..\..;..;%SDL2_DIR%\include;$(SolutionDir)\libs\gl3w;%(AdditionalIncludeDirectories)
+ ..\..;..;%SDL2_DIR%\include;..\libs\gl3w;%(AdditionalIncludeDirectories)true
@@ -115,7 +120,7 @@
MaxSpeedtruetrue
- ..\..;..;%SDL2_DIR%\include;$(SolutionDir)\libs\gl3w;%(AdditionalIncludeDirectories)
+ ..\..;..;%SDL2_DIR%\include;..\libs\gl3w;%(AdditionalIncludeDirectories)false
@@ -135,7 +140,7 @@
MaxSpeedtruetrue
- ..\..;..;%SDL2_DIR%\include;$(SolutionDir)\libs\gl3w;%(AdditionalIncludeDirectories)
+ ..\..;..;%SDL2_DIR%\include;..\libs\gl3w;%(AdditionalIncludeDirectories)false
diff --git a/examples/example_sdl_opengl3/main.cpp b/examples/example_sdl_opengl3/main.cpp
index a6e164a3..2e838631 100644
--- a/examples/example_sdl_opengl3/main.cpp
+++ b/examples/example_sdl_opengl3/main.cpp
@@ -22,10 +22,11 @@
#include IMGUI_IMPL_OPENGL_LOADER_CUSTOM
#endif
+// Main code
int main(int, char**)
{
// Setup SDL
- if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) != 0)
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
{
printf("Error: %s\n", SDL_GetError());
return -1;
@@ -52,9 +53,8 @@ int main(int, char**)
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
- SDL_DisplayMode current;
- SDL_GetCurrentDisplayMode(0, ¤t);
- SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+OpenGL3 example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE);
+ SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
+ SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+OpenGL3 example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
SDL_GL_MakeCurrent(window, gl_context);
SDL_GL_SetSwapInterval(1); // Enable vsync
@@ -80,10 +80,11 @@ int main(int, char**)
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
+ //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
- //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons;
- //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge;
+ //io.ConfigViewportsNoAutoMerge = true;
+ //io.ConfigViewportsNoTaskBarIcon = true;
// Setup Dear ImGui style
ImGui::StyleColorsDark();
@@ -116,6 +117,7 @@ int main(int, char**)
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
//IM_ASSERT(font != NULL);
+ // Our state
bool show_demo_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
diff --git a/examples/example_sdl_vulkan/example_sdl_vulkan.vcxproj b/examples/example_sdl_vulkan/example_sdl_vulkan.vcxproj
index 622dc093..ac701a2a 100644
--- a/examples/example_sdl_vulkan/example_sdl_vulkan.vcxproj
+++ b/examples/example_sdl_vulkan/example_sdl_vulkan.vcxproj
@@ -21,29 +21,34 @@
{BAE3D0B5-9695-4EB1-AD0F-75890EB4A3B3}example_sdl_vulkan
+ 8.1ApplicationtrueMultiByte
+ v110ApplicationtrueMultiByte
+ v110ApplicationfalsetrueMultiByte
+ v110ApplicationfalsetrueMultiByte
+ v110
diff --git a/examples/example_sdl_vulkan/main.cpp b/examples/example_sdl_vulkan/main.cpp
index 87ed6265..1dc694c3 100644
--- a/examples/example_sdl_vulkan/main.cpp
+++ b/examples/example_sdl_vulkan/main.cpp
@@ -1,6 +1,13 @@
// dear imgui: standalone example application for SDL2 + Vulkan
// If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp.
+// Important note to the reader who wish to integrate imgui_impl_vulkan.cpp/.h in their own engine/app.
+// - Common ImGui_ImplVulkan_XXX functions and structures are used to interface with imgui_impl_vulkan.cpp/.h.
+// You will use those if you want to use this rendering back-end in your engine/app.
+// - Helper ImGui_ImplVulkanH_XXX functions and structures are only used by this example (main.cpp) and by
+// the back-end itself (imgui_impl_vulkan.cpp), but should PROBABLY NOT be used by your own engine/app code.
+// Read comments in imgui_impl_vulkan.h.
+
#include "imgui.h"
#include "imgui_impl_sdl.h"
#include "imgui_impl_vulkan.h"
@@ -15,17 +22,21 @@
#define IMGUI_VULKAN_DEBUG_REPORT
#endif
-static VkAllocationCallbacks* g_Allocator = NULL;
-static VkInstance g_Instance = VK_NULL_HANDLE;
-static VkPhysicalDevice g_PhysicalDevice = VK_NULL_HANDLE;
-static VkDevice g_Device = VK_NULL_HANDLE;
-static uint32_t g_QueueFamily = (uint32_t)-1;
-static VkQueue g_Queue = VK_NULL_HANDLE;
-static VkDebugReportCallbackEXT g_DebugReport = VK_NULL_HANDLE;
-static VkPipelineCache g_PipelineCache = VK_NULL_HANDLE;
-static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE;
-
-static ImGui_ImplVulkanH_WindowData g_WindowData;
+static VkAllocationCallbacks* g_Allocator = NULL;
+static VkInstance g_Instance = VK_NULL_HANDLE;
+static VkPhysicalDevice g_PhysicalDevice = VK_NULL_HANDLE;
+static VkDevice g_Device = VK_NULL_HANDLE;
+static uint32_t g_QueueFamily = (uint32_t)-1;
+static VkQueue g_Queue = VK_NULL_HANDLE;
+static VkDebugReportCallbackEXT g_DebugReport = VK_NULL_HANDLE;
+static VkPipelineCache g_PipelineCache = VK_NULL_HANDLE;
+static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE;
+
+static ImGui_ImplVulkanH_Window g_MainWindowData;
+static uint32_t g_MinImageCount = 2;
+static bool g_SwapChainRebuild = false;
+static int g_SwapChainResizeWidth = 0;
+static int g_SwapChainResizeHeight = 0;
static void check_vk_result(VkResult err)
{
@@ -89,6 +100,7 @@ static void SetupVulkan(const char** extensions, uint32_t extensions_count)
// Create Vulkan Instance without any debug feature
err = vkCreateInstance(&create_info, g_Allocator, &g_Instance);
check_vk_result(err);
+ IM_UNUSED(g_DebugReport);
#endif
}
@@ -97,6 +109,7 @@ static void SetupVulkan(const char** extensions, uint32_t extensions_count)
uint32_t gpu_count;
err = vkEnumeratePhysicalDevices(g_Instance, &gpu_count, NULL);
check_vk_result(err);
+ IM_ASSERT(gpu_count > 0);
VkPhysicalDevice* gpus = (VkPhysicalDevice*)malloc(sizeof(VkPhysicalDevice) * gpu_count);
err = vkEnumeratePhysicalDevices(g_Instance, &gpu_count, gpus);
@@ -122,7 +135,7 @@ static void SetupVulkan(const char** extensions, uint32_t extensions_count)
break;
}
free(queues);
- IM_ASSERT(g_QueueFamily != -1);
+ IM_ASSERT(g_QueueFamily != (uint32_t)-1);
}
// Create Logical Device (with 1 queue)
@@ -173,7 +186,9 @@ static void SetupVulkan(const char** extensions, uint32_t extensions_count)
}
}
-static void SetupVulkanWindowData(ImGui_ImplVulkanH_WindowData* wd, VkSurfaceKHR surface, int width, int height)
+// All the ImGui_ImplVulkanH_XXX structures/functions are optional helpers used by the demo.
+// Your real engine/app may not use them.
+static void SetupVulkanWindow(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface, int width, int height)
{
wd->Surface = surface;
@@ -201,14 +216,12 @@ static void SetupVulkanWindowData(ImGui_ImplVulkanH_WindowData* wd, VkSurfaceKHR
//printf("[vulkan] Selected PresentMode = %d\n", wd->PresentMode);
// Create SwapChain, RenderPass, Framebuffer, etc.
- ImGui_ImplVulkanH_CreateWindowDataCommandBuffers(g_PhysicalDevice, g_Device, g_QueueFamily, wd, g_Allocator);
- ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(g_PhysicalDevice, g_Device, wd, g_Allocator, width, height);
+ IM_ASSERT(g_MinImageCount >= 2);
+ ImGui_ImplVulkanH_CreateWindow(g_Instance, g_PhysicalDevice, g_Device, wd, g_QueueFamily, g_Allocator, width, height, g_MinImageCount);
}
static void CleanupVulkan()
{
- ImGui_ImplVulkanH_WindowData* wd = &g_WindowData;
- ImGui_ImplVulkanH_DestroyWindowData(g_Instance, g_Device, wd, g_Allocator);
vkDestroyDescriptorPool(g_Device, g_DescriptorPool, g_Allocator);
#ifdef IMGUI_VULKAN_DEBUG_REPORT
@@ -221,20 +234,26 @@ static void CleanupVulkan()
vkDestroyInstance(g_Instance, g_Allocator);
}
-static void FrameRender(ImGui_ImplVulkanH_WindowData* wd)
+static void CleanupVulkanWindow()
{
- VkResult err;
+ ImGui_ImplVulkanH_DestroyWindow(g_Instance, g_Device, &g_MainWindowData, g_Allocator);
+}
- VkSemaphore& image_acquired_semaphore = wd->Frames[wd->FrameIndex].ImageAcquiredSemaphore;
- err = vkAcquireNextImageKHR(g_Device, wd->Swapchain, UINT64_MAX, image_acquired_semaphore, VK_NULL_HANDLE, &wd->FrameIndex);
- check_vk_result(err);
+static void FrameRender(ImGui_ImplVulkanH_Window* wd)
+{
+ VkResult err;
+
+ VkSemaphore image_acquired_semaphore = wd->FrameSemaphores[wd->SemaphoreIndex].ImageAcquiredSemaphore;
+ VkSemaphore render_complete_semaphore = wd->FrameSemaphores[wd->SemaphoreIndex].RenderCompleteSemaphore;
+ err = vkAcquireNextImageKHR(g_Device, wd->Swapchain, UINT64_MAX, image_acquired_semaphore, VK_NULL_HANDLE, &wd->FrameIndex);
+ check_vk_result(err);
- ImGui_ImplVulkanH_FrameData* fd = &wd->Frames[wd->FrameIndex];
+ ImGui_ImplVulkanH_Frame* fd = &wd->Frames[wd->FrameIndex];
{
- err = vkWaitForFences(g_Device, 1, &fd->Fence, VK_TRUE, UINT64_MAX); // wait indefinitely instead of periodically checking
+ err = vkWaitForFences(g_Device, 1, &fd->Fence, VK_TRUE, UINT64_MAX); // wait indefinitely instead of periodically checking
check_vk_result(err);
- err = vkResetFences(g_Device, 1, &fd->Fence);
+ err = vkResetFences(g_Device, 1, &fd->Fence);
check_vk_result(err);
}
{
@@ -250,7 +269,7 @@ static void FrameRender(ImGui_ImplVulkanH_WindowData* wd)
VkRenderPassBeginInfo info = {};
info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
info.renderPass = wd->RenderPass;
- info.framebuffer = wd->Framebuffer[wd->FrameIndex];
+ info.framebuffer = fd->Framebuffer;
info.renderArea.extent.width = wd->Width;
info.renderArea.extent.height = wd->Height;
info.clearValueCount = 1;
@@ -258,22 +277,22 @@ static void FrameRender(ImGui_ImplVulkanH_WindowData* wd)
vkCmdBeginRenderPass(fd->CommandBuffer, &info, VK_SUBPASS_CONTENTS_INLINE);
}
- // Record Imgui Draw Data and draw funcs into command buffer
- ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), fd->CommandBuffer);
+ // Record Imgui Draw Data and draw funcs into command buffer
+ ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), fd->CommandBuffer);
- // Submit command buffer
+ // Submit command buffer
vkCmdEndRenderPass(fd->CommandBuffer);
{
VkPipelineStageFlags wait_stage = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
VkSubmitInfo info = {};
info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
info.waitSemaphoreCount = 1;
- info.pWaitSemaphores = &image_acquired_semaphore;
+ info.pWaitSemaphores = &image_acquired_semaphore;
info.pWaitDstStageMask = &wait_stage;
info.commandBufferCount = 1;
info.pCommandBuffers = &fd->CommandBuffer;
info.signalSemaphoreCount = 1;
- info.pSignalSemaphores = &fd->RenderCompleteSemaphore;
+ info.pSignalSemaphores = &render_complete_semaphore;
err = vkEndCommandBuffer(fd->CommandBuffer);
check_vk_result(err);
@@ -282,33 +301,33 @@ static void FrameRender(ImGui_ImplVulkanH_WindowData* wd)
}
}
-static void FramePresent(ImGui_ImplVulkanH_WindowData* wd)
+static void FramePresent(ImGui_ImplVulkanH_Window* wd)
{
- ImGui_ImplVulkanH_FrameData* fd = &wd->Frames[wd->FrameIndex];
+ VkSemaphore render_complete_semaphore = wd->FrameSemaphores[wd->SemaphoreIndex].RenderCompleteSemaphore;
VkPresentInfoKHR info = {};
info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
info.waitSemaphoreCount = 1;
- info.pWaitSemaphores = &fd->RenderCompleteSemaphore;
+ info.pWaitSemaphores = &render_complete_semaphore;
info.swapchainCount = 1;
info.pSwapchains = &wd->Swapchain;
- info.pImageIndices = &wd->FrameIndex;
- VkResult err = vkQueuePresentKHR(g_Queue, &info);
+ info.pImageIndices = &wd->FrameIndex;
+ VkResult err = vkQueuePresentKHR(g_Queue, &info);
check_vk_result(err);
+ wd->SemaphoreIndex = (wd->SemaphoreIndex + 1) % wd->ImageCount; // Now we can use the next set of semaphores
}
int main(int, char**)
{
// Setup SDL
- if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) != 0)
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
{
printf("Error: %s\n", SDL_GetError());
- return 1;
+ return -1;
}
// Setup window
- SDL_DisplayMode current;
- SDL_GetCurrentDisplayMode(0, ¤t);
- SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+Vulkan example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_VULKAN|SDL_WINDOW_RESIZABLE);
+ SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
+ SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+Vulkan example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);
// Setup Vulkan
uint32_t extensions_count = 0;
@@ -330,13 +349,15 @@ int main(int, char**)
// Create Framebuffers
int w, h;
SDL_GetWindowSize(window, &w, &h);
- ImGui_ImplVulkanH_WindowData* wd = &g_WindowData;
- SetupVulkanWindowData(wd, surface, w, h);
+ ImGui_ImplVulkanH_Window* wd = &g_MainWindowData;
+ SetupVulkanWindow(wd, surface, w, h);
// Setup Dear ImGui context
+ IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
+ //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons;
@@ -365,6 +386,8 @@ int main(int, char**)
init_info.PipelineCache = g_PipelineCache;
init_info.DescriptorPool = g_DescriptorPool;
init_info.Allocator = g_Allocator;
+ init_info.MinImageCount = g_MinImageCount;
+ init_info.ImageCount = wd->ImageCount;
init_info.CheckVkResultFn = check_vk_result;
ImGui_ImplVulkan_Init(&init_info, wd->RenderPass);
@@ -410,9 +433,10 @@ int main(int, char**)
err = vkDeviceWaitIdle(g_Device);
check_vk_result(err);
- ImGui_ImplVulkan_InvalidateFontUploadObjects();
+ ImGui_ImplVulkan_DestroyFontUploadObjects();
}
+ // Our state
bool show_demo_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
@@ -433,7 +457,19 @@ int main(int, char**)
if (event.type == SDL_QUIT)
done = true;
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_RESIZED && event.window.windowID == SDL_GetWindowID(window))
- ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(g_PhysicalDevice, g_Device, &g_WindowData, g_Allocator, (int)event.window.data1, (int)event.window.data2);
+ {
+ g_SwapChainResizeWidth = (int)event.window.data1;
+ g_SwapChainResizeHeight = (int)event.window.data2;
+ g_SwapChainRebuild = true;
+ }
+ }
+
+ if (g_SwapChainRebuild)
+ {
+ g_SwapChainRebuild = false;
+ ImGui_ImplVulkan_SetMinImageCount(g_MinImageCount);
+ ImGui_ImplVulkanH_CreateWindow(g_Instance, g_PhysicalDevice, g_Device, &g_MainWindowData, g_QueueFamily, g_Allocator, g_SwapChainResizeWidth, g_SwapChainResizeHeight, g_MinImageCount);
+ g_MainWindowData.FrameIndex = 0;
}
// Start the Dear ImGui frame
@@ -481,7 +517,7 @@ int main(int, char**)
// Rendering
ImGui::Render();
memcpy(&wd->ClearValue.color.float32[0], &clear_color, 4 * sizeof(float));
- FrameRender(wd);
+ FrameRender(wd);
// Update and Render additional Platform Windows
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
@@ -499,6 +535,8 @@ int main(int, char**)
ImGui_ImplVulkan_Shutdown();
ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext();
+
+ CleanupVulkanWindow();
CleanupVulkan();
SDL_DestroyWindow(window);
diff --git a/examples/example_win32_directx10/example_win32_directx10.vcxproj b/examples/example_win32_directx10/example_win32_directx10.vcxproj
index 5e2973b9..0f351dde 100644
--- a/examples/example_win32_directx10/example_win32_directx10.vcxproj
+++ b/examples/example_win32_directx10/example_win32_directx10.vcxproj
@@ -21,29 +21,34 @@
{345A953E-A004-4648-B442-DC5F9F11068C}example_win32_directx10
+ 8.1ApplicationtrueUnicode
+ v110ApplicationtrueUnicode
+ v110ApplicationfalsetrueUnicode
+ v110ApplicationfalsetrueUnicode
+ v110
@@ -81,7 +86,7 @@
Level4Disabled
- ..\..;..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include;
+ ..\..;..;%(AdditionalIncludeDirectories);true
@@ -94,7 +99,7 @@
Level4Disabled
- ..\..;..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include;
+ ..\..;..;%(AdditionalIncludeDirectories);true
@@ -109,7 +114,7 @@
MaxSpeedtruetrue
- ..\..;..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include;
+ ..\..;..;%(AdditionalIncludeDirectories);false
@@ -127,7 +132,7 @@
MaxSpeedtruetrue
- ..\..;..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include;
+ ..\..;..;%(AdditionalIncludeDirectories);false
diff --git a/examples/example_win32_directx10/main.cpp b/examples/example_win32_directx10/main.cpp
index 8e0e8ec3..6d94c9a7 100644
--- a/examples/example_win32_directx10/main.cpp
+++ b/examples/example_win32_directx10/main.cpp
@@ -15,112 +15,45 @@ static ID3D10Device* g_pd3dDevice = NULL;
static IDXGISwapChain* g_pSwapChain = NULL;
static ID3D10RenderTargetView* g_mainRenderTargetView = NULL;
-void CreateRenderTarget()
-{
- ID3D10Texture2D* pBackBuffer;
- g_pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&pBackBuffer);
- g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &g_mainRenderTargetView);
- pBackBuffer->Release();
-}
-
-void CleanupRenderTarget()
-{
- if (g_mainRenderTargetView) { g_mainRenderTargetView->Release(); g_mainRenderTargetView = NULL; }
-}
-
-HRESULT CreateDeviceD3D(HWND hWnd)
-{
- // Setup swap chain
- DXGI_SWAP_CHAIN_DESC sd;
- ZeroMemory(&sd, sizeof(sd));
- sd.BufferCount = 2;
- sd.BufferDesc.Width = 0;
- sd.BufferDesc.Height = 0;
- sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
- sd.BufferDesc.RefreshRate.Numerator = 60;
- sd.BufferDesc.RefreshRate.Denominator = 1;
- sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
- sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
- sd.OutputWindow = hWnd;
- sd.SampleDesc.Count = 1;
- sd.SampleDesc.Quality = 0;
- sd.Windowed = TRUE;
- sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
-
- UINT createDeviceFlags = 0;
- //createDeviceFlags |= D3D10_CREATE_DEVICE_DEBUG;
- if (D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, D3D10_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice) != S_OK)
- return E_FAIL;
-
- CreateRenderTarget();
-
- return S_OK;
-}
-
-void CleanupDeviceD3D()
-{
- CleanupRenderTarget();
- if (g_pSwapChain) { g_pSwapChain->Release(); g_pSwapChain = NULL; }
- if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; }
-}
-
-extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
-LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam))
- return true;
-
- switch (msg)
- {
- case WM_SIZE:
- if (g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED)
- {
- CleanupRenderTarget();
- g_pSwapChain->ResizeBuffers(0, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam), DXGI_FORMAT_UNKNOWN, 0);
- CreateRenderTarget();
- }
- return 0;
- case WM_SYSCOMMAND:
- if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu
- return 0;
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
- }
- return DefWindowProc(hWnd, msg, wParam, lParam);
-}
-
+// Forward declarations of helper functions
+bool CreateDeviceD3D(HWND hWnd);
+void CleanupDeviceD3D();
+void CreateRenderTarget();
+void CleanupRenderTarget();
+LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
+
+// Main code
int main(int, char**)
{
ImGui_ImplWin32_EnableDpiAwareness();
// Create application window
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, _T("ImGui Example"), NULL };
- RegisterClassEx(&wc);
- HWND hwnd = CreateWindow(wc.lpszClassName, _T("Dear ImGui DirectX10 Example"), WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL);
+ ::RegisterClassEx(&wc);
+ HWND hwnd = ::CreateWindow(wc.lpszClassName, _T("Dear ImGui DirectX10 Example"), WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL);
// Initialize Direct3D
- if (CreateDeviceD3D(hwnd) < 0)
+ if (!CreateDeviceD3D(hwnd))
{
CleanupDeviceD3D();
- UnregisterClass(wc.lpszClassName, wc.hInstance);
+ ::UnregisterClass(wc.lpszClassName, wc.hInstance);
return 1;
}
// Show the window
- ShowWindow(hwnd, SW_SHOWDEFAULT);
- UpdateWindow(hwnd);
+ ::ShowWindow(hwnd, SW_SHOWDEFAULT);
+ ::UpdateWindow(hwnd);
// Setup Dear ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
+ //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
- //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons;
- //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge;
+ //io.ConfigViewportsNoAutoMerge = true;
+ //io.ConfigViewportsNoTaskBarIcon = true;
// Setup Dear ImGui style
ImGui::StyleColorsDark();
@@ -153,6 +86,7 @@ int main(int, char**)
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
//IM_ASSERT(font != NULL);
+ // Our state
bool show_demo_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
@@ -167,10 +101,10 @@ int main(int, char**)
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
- if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
+ if (::PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
{
- TranslateMessage(&msg);
- DispatchMessage(&msg);
+ ::TranslateMessage(&msg);
+ ::DispatchMessage(&msg);
continue;
}
@@ -238,8 +172,86 @@ int main(int, char**)
ImGui::DestroyContext();
CleanupDeviceD3D();
- DestroyWindow(hwnd);
- UnregisterClass(wc.lpszClassName, wc.hInstance);
+ ::DestroyWindow(hwnd);
+ ::UnregisterClass(wc.lpszClassName, wc.hInstance);
return 0;
}
+
+// Helper functions
+
+bool CreateDeviceD3D(HWND hWnd)
+{
+ // Setup swap chain
+ DXGI_SWAP_CHAIN_DESC sd;
+ ZeroMemory(&sd, sizeof(sd));
+ sd.BufferCount = 2;
+ sd.BufferDesc.Width = 0;
+ sd.BufferDesc.Height = 0;
+ sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
+ sd.BufferDesc.RefreshRate.Numerator = 60;
+ sd.BufferDesc.RefreshRate.Denominator = 1;
+ sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
+ sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
+ sd.OutputWindow = hWnd;
+ sd.SampleDesc.Count = 1;
+ sd.SampleDesc.Quality = 0;
+ sd.Windowed = TRUE;
+ sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
+
+ UINT createDeviceFlags = 0;
+ //createDeviceFlags |= D3D10_CREATE_DEVICE_DEBUG;
+ if (D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, D3D10_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice) != S_OK)
+ return false;
+
+ CreateRenderTarget();
+ return true;
+}
+
+void CleanupDeviceD3D()
+{
+ CleanupRenderTarget();
+ if (g_pSwapChain) { g_pSwapChain->Release(); g_pSwapChain = NULL; }
+ if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; }
+}
+
+void CreateRenderTarget()
+{
+ ID3D10Texture2D* pBackBuffer;
+ g_pSwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer));
+ g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &g_mainRenderTargetView);
+ pBackBuffer->Release();
+}
+
+void CleanupRenderTarget()
+{
+ if (g_mainRenderTargetView) { g_mainRenderTargetView->Release(); g_mainRenderTargetView = NULL; }
+}
+
+// Win32 message handler
+extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
+LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam))
+ return true;
+
+ switch (msg)
+ {
+ case WM_SIZE:
+ if (g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED)
+ {
+ CleanupRenderTarget();
+ g_pSwapChain->ResizeBuffers(0, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam), DXGI_FORMAT_UNKNOWN, 0);
+ CreateRenderTarget();
+ }
+ return 0;
+ case WM_SYSCOMMAND:
+ if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu
+ return 0;
+ break;
+ case WM_DESTROY:
+ ::PostQuitMessage(0);
+ return 0;
+ }
+ return ::DefWindowProc(hWnd, msg, wParam, lParam);
+}
diff --git a/examples/example_win32_directx11/example_win32_directx11.vcxproj b/examples/example_win32_directx11/example_win32_directx11.vcxproj
index 166602a3..ce2434b0 100644
--- a/examples/example_win32_directx11/example_win32_directx11.vcxproj
+++ b/examples/example_win32_directx11/example_win32_directx11.vcxproj
@@ -27,23 +27,27 @@
ApplicationtrueUnicode
+ v110ApplicationtrueUnicode
+ v110ApplicationfalsetrueUnicode
+ v110ApplicationfalsetrueUnicode
+ v110
@@ -81,7 +85,7 @@
Level4Disabled
- ..\..;..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include;
+ ..\..;..;%(AdditionalIncludeDirectories);true
@@ -94,7 +98,7 @@
Level4Disabled
- ..\..;..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include;
+ ..\..;..;%(AdditionalIncludeDirectories);true
@@ -109,7 +113,7 @@
MaxSpeedtruetrue
- ..\..;..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include;
+ ..\..;..;%(AdditionalIncludeDirectories);false
@@ -127,7 +131,7 @@
MaxSpeedtruetrue
- ..\..;..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include;
+ ..\..;..;%(AdditionalIncludeDirectories);false
diff --git a/examples/example_win32_directx11/main.cpp b/examples/example_win32_directx11/main.cpp
index a8156cac..d765ba1b 100644
--- a/examples/example_win32_directx11/main.cpp
+++ b/examples/example_win32_directx11/main.cpp
@@ -15,134 +15,52 @@ static ID3D11DeviceContext* g_pd3dDeviceContext = NULL;
static IDXGISwapChain* g_pSwapChain = NULL;
static ID3D11RenderTargetView* g_mainRenderTargetView = NULL;
-void CreateRenderTarget()
-{
- ID3D11Texture2D* pBackBuffer;
- g_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer);
- g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &g_mainRenderTargetView);
- pBackBuffer->Release();
-}
-
-void CleanupRenderTarget()
-{
- if (g_mainRenderTargetView) { g_mainRenderTargetView->Release(); g_mainRenderTargetView = NULL; }
-}
-
-HRESULT CreateDeviceD3D(HWND hWnd)
-{
- // Setup swap chain
- DXGI_SWAP_CHAIN_DESC sd;
- ZeroMemory(&sd, sizeof(sd));
- sd.BufferCount = 2;
- sd.BufferDesc.Width = 0;
- sd.BufferDesc.Height = 0;
- sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
- sd.BufferDesc.RefreshRate.Numerator = 60;
- sd.BufferDesc.RefreshRate.Denominator = 1;
- sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
- sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
- sd.OutputWindow = hWnd;
- sd.SampleDesc.Count = 1;
- sd.SampleDesc.Quality = 0;
- sd.Windowed = TRUE;
- sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
-
- UINT createDeviceFlags = 0;
- //createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
- D3D_FEATURE_LEVEL featureLevel;
- const D3D_FEATURE_LEVEL featureLevelArray[2] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0, };
- if (D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, featureLevelArray, 2, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceContext) != S_OK)
- return E_FAIL;
-
- CreateRenderTarget();
-
- return S_OK;
-}
-
-void CleanupDeviceD3D()
-{
- CleanupRenderTarget();
- if (g_pSwapChain) { g_pSwapChain->Release(); g_pSwapChain = NULL; }
- if (g_pd3dDeviceContext) { g_pd3dDeviceContext->Release(); g_pd3dDeviceContext = NULL; }
- if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; }
-}
-
-#ifndef WM_DPICHANGED
-#define WM_DPICHANGED 0x02E0 // From Windows SDK 8.1+ headers
-#endif
-
-extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
-LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam))
- return true;
-
- switch (msg)
- {
- case WM_SIZE:
- if (g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED)
- {
- CleanupRenderTarget();
- g_pSwapChain->ResizeBuffers(0, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam), DXGI_FORMAT_UNKNOWN, 0);
- CreateRenderTarget();
- }
- return 0;
- case WM_SYSCOMMAND:
- if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu
- return 0;
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
- case WM_DPICHANGED:
- if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_DpiEnableScaleViewports)
- {
- //const int dpi = HIWORD(wParam);
- //printf("WM_DPICHANGED to %d (%.0f%%)\n", dpi, (float)dpi / 96.0f * 100.0f);
- const RECT* suggested_rect = (RECT*)lParam;
- ::SetWindowPos(hWnd, NULL, suggested_rect->left, suggested_rect->top, suggested_rect->right - suggested_rect->left, suggested_rect->bottom - suggested_rect->top, SWP_NOZORDER | SWP_NOACTIVATE);
- }
- break;
- }
- return DefWindowProc(hWnd, msg, wParam, lParam);
-}
-
+// Forward declarations of helper functions
+bool CreateDeviceD3D(HWND hWnd);
+void CleanupDeviceD3D();
+void CreateRenderTarget();
+void CleanupRenderTarget();
+LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
+
+// Main code
int main(int, char**)
{
ImGui_ImplWin32_EnableDpiAwareness();
// Create application window
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, _T("ImGui Example"), NULL };
- RegisterClassEx(&wc);
- HWND hwnd = CreateWindow(wc.lpszClassName, _T("Dear ImGui DirectX11 Example"), WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL);
+ ::RegisterClassEx(&wc);
+ HWND hwnd = ::CreateWindow(wc.lpszClassName, _T("Dear ImGui DirectX11 Example"), WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL);
// Initialize Direct3D
- if (CreateDeviceD3D(hwnd) < 0)
+ if (!CreateDeviceD3D(hwnd))
{
CleanupDeviceD3D();
- UnregisterClass(wc.lpszClassName, wc.hInstance);
+ ::UnregisterClass(wc.lpszClassName, wc.hInstance);
return 1;
}
// Show the window
- ShowWindow(hwnd, SW_SHOWDEFAULT);
- UpdateWindow(hwnd);
+ ::ShowWindow(hwnd, SW_SHOWDEFAULT);
+ ::UpdateWindow(hwnd);
// Setup Dear ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
+ //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
- //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons;
- //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge;
- io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleFonts; // FIXME-DPI: THIS CURRENTLY DOESN'T WORK AS EXPECTED. DON'T USE IN USER APP!
- io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleViewports; // FIXME-DPI
//io.ConfigViewportsNoAutoMerge = true;
- //io.ConfigViewportsNoTaskBarIcon = false;
- //io.ConfigDockingTabBarOnSingleWindows = true;
+ //io.ConfigViewportsNoTaskBarIcon = true;
+ //io.ConfigViewportsNoDefaultParent = true;
+ //io.ConfigDockingAlwaysTabBar = true;
//io.ConfigDockingTransparentPayload = true;
+#if 1
+ io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleFonts; // FIXME-DPI: THIS CURRENTLY DOESN'T WORK AS EXPECTED. DON'T USE IN USER APP!
+ io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleViewports; // FIXME-DPI
+#endif
// Setup Dear ImGui style
ImGui::StyleColorsDark();
@@ -190,10 +108,10 @@ int main(int, char**)
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
- if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
+ if (::PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
{
- TranslateMessage(&msg);
- DispatchMessage(&msg);
+ ::TranslateMessage(&msg);
+ ::DispatchMessage(&msg);
continue;
}
@@ -256,13 +174,108 @@ int main(int, char**)
//g_pSwapChain->Present(0, 0); // Present without vsync
}
+ // Cleanup
ImGui_ImplDX11_Shutdown();
ImGui_ImplWin32_Shutdown();
ImGui::DestroyContext();
CleanupDeviceD3D();
- DestroyWindow(hwnd);
- UnregisterClass(wc.lpszClassName, wc.hInstance);
+ ::DestroyWindow(hwnd);
+ ::UnregisterClass(wc.lpszClassName, wc.hInstance);
return 0;
}
+
+// Helper functions
+
+bool CreateDeviceD3D(HWND hWnd)
+{
+ // Setup swap chain
+ DXGI_SWAP_CHAIN_DESC sd;
+ ZeroMemory(&sd, sizeof(sd));
+ sd.BufferCount = 2;
+ sd.BufferDesc.Width = 0;
+ sd.BufferDesc.Height = 0;
+ sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
+ sd.BufferDesc.RefreshRate.Numerator = 60;
+ sd.BufferDesc.RefreshRate.Denominator = 1;
+ sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
+ sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
+ sd.OutputWindow = hWnd;
+ sd.SampleDesc.Count = 1;
+ sd.SampleDesc.Quality = 0;
+ sd.Windowed = TRUE;
+ sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
+
+ UINT createDeviceFlags = 0;
+ //createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
+ D3D_FEATURE_LEVEL featureLevel;
+ const D3D_FEATURE_LEVEL featureLevelArray[2] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0, };
+ if (D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, featureLevelArray, 2, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceContext) != S_OK)
+ return false;
+
+ CreateRenderTarget();
+ return true;
+}
+
+void CleanupDeviceD3D()
+{
+ CleanupRenderTarget();
+ if (g_pSwapChain) { g_pSwapChain->Release(); g_pSwapChain = NULL; }
+ if (g_pd3dDeviceContext) { g_pd3dDeviceContext->Release(); g_pd3dDeviceContext = NULL; }
+ if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; }
+}
+
+void CreateRenderTarget()
+{
+ ID3D11Texture2D* pBackBuffer;
+ g_pSwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer));
+ g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &g_mainRenderTargetView);
+ pBackBuffer->Release();
+}
+
+void CleanupRenderTarget()
+{
+ if (g_mainRenderTargetView) { g_mainRenderTargetView->Release(); g_mainRenderTargetView = NULL; }
+}
+
+#ifndef WM_DPICHANGED
+#define WM_DPICHANGED 0x02E0 // From Windows SDK 8.1+ headers
+#endif
+
+// Win32 message handler
+extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
+LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam))
+ return true;
+
+ switch (msg)
+ {
+ case WM_SIZE:
+ if (g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED)
+ {
+ CleanupRenderTarget();
+ g_pSwapChain->ResizeBuffers(0, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam), DXGI_FORMAT_UNKNOWN, 0);
+ CreateRenderTarget();
+ }
+ return 0;
+ case WM_SYSCOMMAND:
+ if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu
+ return 0;
+ break;
+ case WM_DESTROY:
+ ::PostQuitMessage(0);
+ return 0;
+ case WM_DPICHANGED:
+ if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_DpiEnableScaleViewports)
+ {
+ //const int dpi = HIWORD(wParam);
+ //printf("WM_DPICHANGED to %d (%.0f%%)\n", dpi, (float)dpi / 96.0f * 100.0f);
+ const RECT* suggested_rect = (RECT*)lParam;
+ ::SetWindowPos(hWnd, NULL, suggested_rect->left, suggested_rect->top, suggested_rect->right - suggested_rect->left, suggested_rect->bottom - suggested_rect->top, SWP_NOZORDER | SWP_NOACTIVATE);
+ }
+ break;
+ }
+ return ::DefWindowProc(hWnd, msg, wParam, lParam);
+}
diff --git a/examples/example_win32_directx12/main.cpp b/examples/example_win32_directx12/main.cpp
index 54bc7524..26a16f0f 100644
--- a/examples/example_win32_directx12/main.cpp
+++ b/examples/example_win32_directx12/main.cpp
@@ -36,265 +36,46 @@ static HANDLE g_hSwapChainWaitableObject = NULL;
static ID3D12Resource* g_mainRenderTargetResource[NUM_BACK_BUFFERS] = {};
static D3D12_CPU_DESCRIPTOR_HANDLE g_mainRenderTargetDescriptor[NUM_BACK_BUFFERS] = {};
-void CreateRenderTarget()
-{
- for (UINT i = 0; i < NUM_BACK_BUFFERS; i++)
- {
- ID3D12Resource* pBackBuffer = NULL;
- g_pSwapChain->GetBuffer(i, IID_PPV_ARGS(&pBackBuffer));
- g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, g_mainRenderTargetDescriptor[i]);
- g_mainRenderTargetResource[i] = pBackBuffer;
- }
-}
-
-void WaitForLastSubmittedFrame()
-{
- FrameContext* frameCtxt = &g_frameContext[g_frameIndex % NUM_FRAMES_IN_FLIGHT];
-
- UINT64 fenceValue = frameCtxt->FenceValue;
- if (fenceValue == 0)
- return; // No fence was signaled
-
- frameCtxt->FenceValue = 0;
- if (g_fence->GetCompletedValue() >= fenceValue)
- return;
-
- g_fence->SetEventOnCompletion(fenceValue, g_fenceEvent);
- WaitForSingleObject(g_fenceEvent, INFINITE);
-}
-
-FrameContext* WaitForNextFrameResources()
-{
- UINT nextFrameIndex = g_frameIndex + 1;
- g_frameIndex = nextFrameIndex;
-
- HANDLE waitableObjects[] = { g_hSwapChainWaitableObject, NULL };
- DWORD numWaitableObjects = 1;
-
- FrameContext* frameCtxt = &g_frameContext[nextFrameIndex % NUM_FRAMES_IN_FLIGHT];
- UINT64 fenceValue = frameCtxt->FenceValue;
- if (fenceValue != 0) // means no fence was signaled
- {
- frameCtxt->FenceValue = 0;
- g_fence->SetEventOnCompletion(fenceValue, g_fenceEvent);
- waitableObjects[1] = g_fenceEvent;
- numWaitableObjects = 2;
- }
-
- WaitForMultipleObjects(numWaitableObjects, waitableObjects, TRUE, INFINITE);
-
- return frameCtxt;
-}
-
-void ResizeSwapChain(HWND hWnd, int width, int height)
-{
- DXGI_SWAP_CHAIN_DESC1 sd;
- g_pSwapChain->GetDesc1(&sd);
- sd.Width = width;
- sd.Height = height;
-
- IDXGIFactory4* dxgiFactory = NULL;
- g_pSwapChain->GetParent(IID_PPV_ARGS(&dxgiFactory));
-
- g_pSwapChain->Release();
- CloseHandle(g_hSwapChainWaitableObject);
-
- IDXGISwapChain1* swapChain1 = NULL;
- dxgiFactory->CreateSwapChainForHwnd(g_pd3dCommandQueue, hWnd, &sd, NULL, NULL, &swapChain1);
- swapChain1->QueryInterface(IID_PPV_ARGS(&g_pSwapChain));
- swapChain1->Release();
- dxgiFactory->Release();
-
- g_pSwapChain->SetMaximumFrameLatency(NUM_BACK_BUFFERS);
-
- g_hSwapChainWaitableObject = g_pSwapChain->GetFrameLatencyWaitableObject();
- assert(g_hSwapChainWaitableObject != NULL);
-}
-
-void CleanupRenderTarget()
-{
- WaitForLastSubmittedFrame();
-
- for (UINT i = 0; i < NUM_BACK_BUFFERS; i++)
- if (g_mainRenderTargetResource[i]) { g_mainRenderTargetResource[i]->Release(); g_mainRenderTargetResource[i] = NULL; }
-}
-
-HRESULT CreateDeviceD3D(HWND hWnd)
-{
- // Setup swap chain
- DXGI_SWAP_CHAIN_DESC1 sd;
- {
- ZeroMemory(&sd, sizeof(sd));
- sd.BufferCount = NUM_BACK_BUFFERS;
- sd.Width = 0;
- sd.Height = 0;
- sd.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
- sd.Flags = DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT;
- sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
- sd.SampleDesc.Count = 1;
- sd.SampleDesc.Quality = 0;
- sd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
- sd.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED;
- sd.Scaling = DXGI_SCALING_STRETCH;
- sd.Stereo = FALSE;
- }
-
- if (DX12_ENABLE_DEBUG_LAYER)
- {
- ID3D12Debug* dx12Debug = NULL;
- if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&dx12Debug))))
- {
- dx12Debug->EnableDebugLayer();
- dx12Debug->Release();
- }
- }
-
- D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_0;
- if (D3D12CreateDevice(NULL, featureLevel, IID_PPV_ARGS(&g_pd3dDevice)) != S_OK)
- return E_FAIL;
-
- {
- D3D12_DESCRIPTOR_HEAP_DESC desc = {};
- desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
- desc.NumDescriptors = NUM_BACK_BUFFERS;
- desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
- desc.NodeMask = 1;
- if (g_pd3dDevice->CreateDescriptorHeap(&desc, IID_PPV_ARGS(&g_pd3dRtvDescHeap)) != S_OK)
- return E_FAIL;
-
- SIZE_T rtvDescriptorSize = g_pd3dDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
- D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = g_pd3dRtvDescHeap->GetCPUDescriptorHandleForHeapStart();
- for (UINT i = 0; i < NUM_BACK_BUFFERS; i++)
- {
- g_mainRenderTargetDescriptor[i] = rtvHandle;
- rtvHandle.ptr += rtvDescriptorSize;
- }
- }
-
- {
- D3D12_DESCRIPTOR_HEAP_DESC desc = {};
- desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
- desc.NumDescriptors = 1;
- desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
- if (g_pd3dDevice->CreateDescriptorHeap(&desc, IID_PPV_ARGS(&g_pd3dSrvDescHeap)) != S_OK)
- return E_FAIL;
- }
-
- {
- D3D12_COMMAND_QUEUE_DESC desc = {};
- desc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
- desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
- desc.NodeMask = 1;
- if (g_pd3dDevice->CreateCommandQueue(&desc, IID_PPV_ARGS(&g_pd3dCommandQueue)) != S_OK)
- return E_FAIL;
- }
-
- for (UINT i = 0; i < NUM_FRAMES_IN_FLIGHT; i++)
- if (g_pd3dDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&g_frameContext[i].CommandAllocator)) != S_OK)
- return E_FAIL;
-
- if (g_pd3dDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, g_frameContext[0].CommandAllocator, NULL, IID_PPV_ARGS(&g_pd3dCommandList)) != S_OK ||
- g_pd3dCommandList->Close() != S_OK)
- return E_FAIL;
-
- if (g_pd3dDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&g_fence)) != S_OK)
- return E_FAIL;
-
- g_fenceEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
- if (g_fenceEvent == NULL)
- return E_FAIL;
-
- {
- IDXGIFactory4* dxgiFactory = NULL;
- IDXGISwapChain1* swapChain1 = NULL;
- if (CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory)) != S_OK ||
- dxgiFactory->CreateSwapChainForHwnd(g_pd3dCommandQueue, hWnd, &sd, NULL, NULL, &swapChain1) != S_OK ||
- swapChain1->QueryInterface(IID_PPV_ARGS(&g_pSwapChain)) != S_OK)
- return E_FAIL;
- swapChain1->Release();
- dxgiFactory->Release();
- g_pSwapChain->SetMaximumFrameLatency(NUM_BACK_BUFFERS);
- g_hSwapChainWaitableObject = g_pSwapChain->GetFrameLatencyWaitableObject();
- }
-
- CreateRenderTarget();
-
- return S_OK;
-}
-
-void CleanupDeviceD3D()
-{
- CleanupRenderTarget();
- if (g_pSwapChain) { g_pSwapChain->Release(); g_pSwapChain = NULL; }
- if (g_hSwapChainWaitableObject != NULL) { CloseHandle(g_hSwapChainWaitableObject); }
- for (UINT i = 0; i < NUM_FRAMES_IN_FLIGHT; i++)
- if (g_frameContext[i].CommandAllocator) { g_frameContext[i].CommandAllocator->Release(); g_frameContext[i].CommandAllocator = NULL; }
- if (g_pd3dCommandQueue) { g_pd3dCommandQueue->Release(); g_pd3dCommandQueue = NULL; }
- if (g_pd3dCommandList) { g_pd3dCommandList->Release(); g_pd3dCommandList = NULL; }
- if (g_pd3dRtvDescHeap) { g_pd3dRtvDescHeap->Release(); g_pd3dRtvDescHeap = NULL; }
- if (g_pd3dSrvDescHeap) { g_pd3dSrvDescHeap->Release(); g_pd3dSrvDescHeap = NULL; }
- if (g_fence) { g_fence->Release(); g_fence = NULL; }
- if (g_fenceEvent) { CloseHandle(g_fenceEvent); g_fenceEvent = NULL; }
- if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; }
-}
-
-extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
-LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam))
- return true;
-
- switch (msg)
- {
- case WM_SIZE:
- if (g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED)
- {
- ImGui_ImplDX12_InvalidateDeviceObjects();
- CleanupRenderTarget();
- ResizeSwapChain(hWnd, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam));
- CreateRenderTarget();
- ImGui_ImplDX12_CreateDeviceObjects();
- }
- return 0;
- case WM_SYSCOMMAND:
- if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu
- return 0;
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
- }
- return DefWindowProc(hWnd, msg, wParam, lParam);
-}
-
+// Forward declarations of helper functions
+bool CreateDeviceD3D(HWND hWnd);
+void CleanupDeviceD3D();
+void CreateRenderTarget();
+void CleanupRenderTarget();
+void WaitForLastSubmittedFrame();
+FrameContext* WaitForNextFrameResources();
+void ResizeSwapChain(HWND hWnd, int width, int height);
+LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
+
+// Main code
int main(int, char**)
{
// Create application window
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, _T("ImGui Example"), NULL };
- RegisterClassEx(&wc);
- HWND hwnd = CreateWindow(wc.lpszClassName, _T("Dear ImGui DirectX12 Example"), WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL);
+ ::RegisterClassEx(&wc);
+ HWND hwnd = ::CreateWindow(wc.lpszClassName, _T("Dear ImGui DirectX12 Example"), WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL);
// Initialize Direct3D
- if (CreateDeviceD3D(hwnd) < 0)
+ if (!CreateDeviceD3D(hwnd))
{
CleanupDeviceD3D();
- UnregisterClass(wc.lpszClassName, wc.hInstance);
+ ::UnregisterClass(wc.lpszClassName, wc.hInstance);
return 1;
}
// Show the window
- ShowWindow(hwnd, SW_SHOWDEFAULT);
- UpdateWindow(hwnd);
+ ::ShowWindow(hwnd, SW_SHOWDEFAULT);
+ ::UpdateWindow(hwnd);
// Setup Dear ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
+ //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows (FIXME: Currently broken in DX12 back-end, need some work!)
- //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons;
- //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge;
+ //io.ConfigViewportsNoAutoMerge = true;
+ //io.ConfigViewportsNoTaskBarIcon = true;
// Setup Dear ImGui style
ImGui::StyleColorsDark();
@@ -330,6 +111,7 @@ int main(int, char**)
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
//IM_ASSERT(font != NULL);
+ // Our state
bool show_demo_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
@@ -344,10 +126,10 @@ int main(int, char**)
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
- if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
+ if (::PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
{
- TranslateMessage(&msg);
- DispatchMessage(&msg);
+ ::TranslateMessage(&msg);
+ ::DispatchMessage(&msg);
continue;
}
@@ -442,8 +224,241 @@ int main(int, char**)
ImGui::DestroyContext();
CleanupDeviceD3D();
- DestroyWindow(hwnd);
- UnregisterClass(wc.lpszClassName, wc.hInstance);
+ ::DestroyWindow(hwnd);
+ ::UnregisterClass(wc.lpszClassName, wc.hInstance);
return 0;
}
+
+// Helper functions
+
+bool CreateDeviceD3D(HWND hWnd)
+{
+ // Setup swap chain
+ DXGI_SWAP_CHAIN_DESC1 sd;
+ {
+ ZeroMemory(&sd, sizeof(sd));
+ sd.BufferCount = NUM_BACK_BUFFERS;
+ sd.Width = 0;
+ sd.Height = 0;
+ sd.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
+ sd.Flags = DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT;
+ sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
+ sd.SampleDesc.Count = 1;
+ sd.SampleDesc.Quality = 0;
+ sd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
+ sd.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED;
+ sd.Scaling = DXGI_SCALING_STRETCH;
+ sd.Stereo = FALSE;
+ }
+
+ if (DX12_ENABLE_DEBUG_LAYER)
+ {
+ ID3D12Debug* dx12Debug = NULL;
+ if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&dx12Debug))))
+ {
+ dx12Debug->EnableDebugLayer();
+ dx12Debug->Release();
+ }
+ }
+
+ D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_0;
+ if (D3D12CreateDevice(NULL, featureLevel, IID_PPV_ARGS(&g_pd3dDevice)) != S_OK)
+ return false;
+
+ {
+ D3D12_DESCRIPTOR_HEAP_DESC desc = {};
+ desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
+ desc.NumDescriptors = NUM_BACK_BUFFERS;
+ desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
+ desc.NodeMask = 1;
+ if (g_pd3dDevice->CreateDescriptorHeap(&desc, IID_PPV_ARGS(&g_pd3dRtvDescHeap)) != S_OK)
+ return false;
+
+ SIZE_T rtvDescriptorSize = g_pd3dDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
+ D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = g_pd3dRtvDescHeap->GetCPUDescriptorHandleForHeapStart();
+ for (UINT i = 0; i < NUM_BACK_BUFFERS; i++)
+ {
+ g_mainRenderTargetDescriptor[i] = rtvHandle;
+ rtvHandle.ptr += rtvDescriptorSize;
+ }
+ }
+
+ {
+ D3D12_DESCRIPTOR_HEAP_DESC desc = {};
+ desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
+ desc.NumDescriptors = 1;
+ desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
+ if (g_pd3dDevice->CreateDescriptorHeap(&desc, IID_PPV_ARGS(&g_pd3dSrvDescHeap)) != S_OK)
+ return false;
+ }
+
+ {
+ D3D12_COMMAND_QUEUE_DESC desc = {};
+ desc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
+ desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
+ desc.NodeMask = 1;
+ if (g_pd3dDevice->CreateCommandQueue(&desc, IID_PPV_ARGS(&g_pd3dCommandQueue)) != S_OK)
+ return false;
+ }
+
+ for (UINT i = 0; i < NUM_FRAMES_IN_FLIGHT; i++)
+ if (g_pd3dDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&g_frameContext[i].CommandAllocator)) != S_OK)
+ return false;
+
+ if (g_pd3dDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, g_frameContext[0].CommandAllocator, NULL, IID_PPV_ARGS(&g_pd3dCommandList)) != S_OK ||
+ g_pd3dCommandList->Close() != S_OK)
+ return false;
+
+ if (g_pd3dDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&g_fence)) != S_OK)
+ return false;
+
+ g_fenceEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
+ if (g_fenceEvent == NULL)
+ return false;
+
+ {
+ IDXGIFactory4* dxgiFactory = NULL;
+ IDXGISwapChain1* swapChain1 = NULL;
+ if (CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory)) != S_OK ||
+ dxgiFactory->CreateSwapChainForHwnd(g_pd3dCommandQueue, hWnd, &sd, NULL, NULL, &swapChain1) != S_OK ||
+ swapChain1->QueryInterface(IID_PPV_ARGS(&g_pSwapChain)) != S_OK)
+ return false;
+ swapChain1->Release();
+ dxgiFactory->Release();
+ g_pSwapChain->SetMaximumFrameLatency(NUM_BACK_BUFFERS);
+ g_hSwapChainWaitableObject = g_pSwapChain->GetFrameLatencyWaitableObject();
+ }
+
+ CreateRenderTarget();
+ return true;
+}
+
+void CleanupDeviceD3D()
+{
+ CleanupRenderTarget();
+ if (g_pSwapChain) { g_pSwapChain->Release(); g_pSwapChain = NULL; }
+ if (g_hSwapChainWaitableObject != NULL) { CloseHandle(g_hSwapChainWaitableObject); }
+ for (UINT i = 0; i < NUM_FRAMES_IN_FLIGHT; i++)
+ if (g_frameContext[i].CommandAllocator) { g_frameContext[i].CommandAllocator->Release(); g_frameContext[i].CommandAllocator = NULL; }
+ if (g_pd3dCommandQueue) { g_pd3dCommandQueue->Release(); g_pd3dCommandQueue = NULL; }
+ if (g_pd3dCommandList) { g_pd3dCommandList->Release(); g_pd3dCommandList = NULL; }
+ if (g_pd3dRtvDescHeap) { g_pd3dRtvDescHeap->Release(); g_pd3dRtvDescHeap = NULL; }
+ if (g_pd3dSrvDescHeap) { g_pd3dSrvDescHeap->Release(); g_pd3dSrvDescHeap = NULL; }
+ if (g_fence) { g_fence->Release(); g_fence = NULL; }
+ if (g_fenceEvent) { CloseHandle(g_fenceEvent); g_fenceEvent = NULL; }
+ if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; }
+}
+
+void CreateRenderTarget()
+{
+ for (UINT i = 0; i < NUM_BACK_BUFFERS; i++)
+ {
+ ID3D12Resource* pBackBuffer = NULL;
+ g_pSwapChain->GetBuffer(i, IID_PPV_ARGS(&pBackBuffer));
+ g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, g_mainRenderTargetDescriptor[i]);
+ g_mainRenderTargetResource[i] = pBackBuffer;
+ }
+}
+
+void CleanupRenderTarget()
+{
+ WaitForLastSubmittedFrame();
+
+ for (UINT i = 0; i < NUM_BACK_BUFFERS; i++)
+ if (g_mainRenderTargetResource[i]) { g_mainRenderTargetResource[i]->Release(); g_mainRenderTargetResource[i] = NULL; }
+}
+
+void WaitForLastSubmittedFrame()
+{
+ FrameContext* frameCtxt = &g_frameContext[g_frameIndex % NUM_FRAMES_IN_FLIGHT];
+
+ UINT64 fenceValue = frameCtxt->FenceValue;
+ if (fenceValue == 0)
+ return; // No fence was signaled
+
+ frameCtxt->FenceValue = 0;
+ if (g_fence->GetCompletedValue() >= fenceValue)
+ return;
+
+ g_fence->SetEventOnCompletion(fenceValue, g_fenceEvent);
+ WaitForSingleObject(g_fenceEvent, INFINITE);
+}
+
+FrameContext* WaitForNextFrameResources()
+{
+ UINT nextFrameIndex = g_frameIndex + 1;
+ g_frameIndex = nextFrameIndex;
+
+ HANDLE waitableObjects[] = { g_hSwapChainWaitableObject, NULL };
+ DWORD numWaitableObjects = 1;
+
+ FrameContext* frameCtxt = &g_frameContext[nextFrameIndex % NUM_FRAMES_IN_FLIGHT];
+ UINT64 fenceValue = frameCtxt->FenceValue;
+ if (fenceValue != 0) // means no fence was signaled
+ {
+ frameCtxt->FenceValue = 0;
+ g_fence->SetEventOnCompletion(fenceValue, g_fenceEvent);
+ waitableObjects[1] = g_fenceEvent;
+ numWaitableObjects = 2;
+ }
+
+ WaitForMultipleObjects(numWaitableObjects, waitableObjects, TRUE, INFINITE);
+
+ return frameCtxt;
+}
+
+void ResizeSwapChain(HWND hWnd, int width, int height)
+{
+ DXGI_SWAP_CHAIN_DESC1 sd;
+ g_pSwapChain->GetDesc1(&sd);
+ sd.Width = width;
+ sd.Height = height;
+
+ IDXGIFactory4* dxgiFactory = NULL;
+ g_pSwapChain->GetParent(IID_PPV_ARGS(&dxgiFactory));
+
+ g_pSwapChain->Release();
+ CloseHandle(g_hSwapChainWaitableObject);
+
+ IDXGISwapChain1* swapChain1 = NULL;
+ dxgiFactory->CreateSwapChainForHwnd(g_pd3dCommandQueue, hWnd, &sd, NULL, NULL, &swapChain1);
+ swapChain1->QueryInterface(IID_PPV_ARGS(&g_pSwapChain));
+ swapChain1->Release();
+ dxgiFactory->Release();
+
+ g_pSwapChain->SetMaximumFrameLatency(NUM_BACK_BUFFERS);
+
+ g_hSwapChainWaitableObject = g_pSwapChain->GetFrameLatencyWaitableObject();
+ assert(g_hSwapChainWaitableObject != NULL);
+}
+
+// Win32 message handler
+extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
+LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam))
+ return true;
+
+ switch (msg)
+ {
+ case WM_SIZE:
+ if (g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED)
+ {
+ ImGui_ImplDX12_InvalidateDeviceObjects();
+ CleanupRenderTarget();
+ ResizeSwapChain(hWnd, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam));
+ CreateRenderTarget();
+ ImGui_ImplDX12_CreateDeviceObjects();
+ }
+ return 0;
+ case WM_SYSCOMMAND:
+ if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu
+ return 0;
+ break;
+ case WM_DESTROY:
+ ::PostQuitMessage(0);
+ return 0;
+ }
+ return ::DefWindowProc(hWnd, msg, wParam, lParam);
+}
diff --git a/examples/example_win32_directx9/example_win32_directx9.vcxproj b/examples/example_win32_directx9/example_win32_directx9.vcxproj
index 08f21c87..25bdd859 100644
--- a/examples/example_win32_directx9/example_win32_directx9.vcxproj
+++ b/examples/example_win32_directx9/example_win32_directx9.vcxproj
@@ -21,29 +21,34 @@
{4165A294-21F2-44CA-9B38-E3F935ABADF5}example_win32_directx9
+ 8.1ApplicationtrueUnicode
+ v110ApplicationtrueUnicode
+ v110ApplicationfalsetrueUnicode
+ v110ApplicationfalsetrueUnicode
+ v110
@@ -85,7 +90,7 @@
true
- $(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories)
+ $(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories)d3d9.lib;%(AdditionalDependencies)Console
@@ -98,7 +103,7 @@
true
- $(DXSDK_DIR)Lib\x64;%(AdditionalLibraryDirectories)
+ $(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories)d3d9.lib;%(AdditionalDependencies)Console
@@ -116,7 +121,7 @@
truetruetrue
- $(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories)
+ $(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories)d3d9.lib;%(AdditionalDependencies)Console
@@ -134,7 +139,7 @@
truetruetrue
- $(DXSDK_DIR)Lib\x64;%(AdditionalLibraryDirectories)
+ $(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories)d3d9.lib;%(AdditionalDependencies)Console
diff --git a/examples/example_win32_directx9/main.cpp b/examples/example_win32_directx9/main.cpp
index 931e5f51..44a57347 100644
--- a/examples/example_win32_directx9/main.cpp
+++ b/examples/example_win32_directx9/main.cpp
@@ -10,85 +10,61 @@
#include
// Data
+static LPDIRECT3D9 g_pD3D = NULL;
static LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
-static D3DPRESENT_PARAMETERS g_d3dpp;
+static D3DPRESENT_PARAMETERS g_d3dpp = {};
-extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
-LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam))
- return true;
-
- switch (msg)
- {
- case WM_SIZE:
- if (g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED)
- {
- ImGui_ImplDX9_InvalidateDeviceObjects();
- g_d3dpp.BackBufferWidth = LOWORD(lParam);
- g_d3dpp.BackBufferHeight = HIWORD(lParam);
- HRESULT hr = g_pd3dDevice->Reset(&g_d3dpp);
- if (hr == D3DERR_INVALIDCALL)
- IM_ASSERT(0);
- ImGui_ImplDX9_CreateDeviceObjects();
- }
- return 0;
- case WM_SYSCOMMAND:
- if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu
- return 0;
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
- }
- return DefWindowProc(hWnd, msg, wParam, lParam);
-}
+// Forward declarations of helper functions
+bool CreateDeviceD3D(HWND hWnd);
+void CleanupDeviceD3D();
+void ResetDevice();
+LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
+// Main code
int main(int, char**)
{
+ ImGui_ImplWin32_EnableDpiAwareness();
+
// Create application window
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, _T("ImGui Example"), NULL };
- RegisterClassEx(&wc);
- HWND hwnd = CreateWindow(wc.lpszClassName, _T("Dear ImGui DirectX9 Example"), WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL);
+ ::RegisterClassEx(&wc);
+ HWND hwnd = ::CreateWindow(wc.lpszClassName, _T("Dear ImGui DirectX9 Example"), WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL);
// Initialize Direct3D
- LPDIRECT3D9 pD3D;
- if ((pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL)
+ if (!CreateDeviceD3D(hwnd))
{
- UnregisterClass(wc.lpszClassName, wc.hInstance);
- return 0;
+ CleanupDeviceD3D();
+ ::UnregisterClass(wc.lpszClassName, wc.hInstance);
+ return 1;
}
- ZeroMemory(&g_d3dpp, sizeof(g_d3dpp));
- g_d3dpp.Windowed = TRUE;
- g_d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
- g_d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
- g_d3dpp.EnableAutoDepthStencil = TRUE;
- g_d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
- g_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; // Present with vsync
- //g_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; // Present without vsync, maximum unthrottled framerate
- // Create the D3DDevice
- if (pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &g_d3dpp, &g_pd3dDevice) < 0)
- {
- pD3D->Release();
- UnregisterClass(wc.lpszClassName, wc.hInstance);
- return 0;
- }
+ // Show the window
+ ::ShowWindow(hwnd, SW_SHOWDEFAULT);
+ ::UpdateWindow(hwnd);
// Setup Dear ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
+ //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
- //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons;
- //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge;
+ //io.ConfigViewportsNoAutoMerge = true;
+ //io.ConfigViewportsNoTaskBarIcon = true;
// Setup Dear ImGui style
ImGui::StyleColorsDark();
//ImGui::StyleColorsClassic();
+ // When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones.
+ ImGuiStyle& style = ImGui::GetStyle();
+ if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
+ {
+ style.WindowRounding = 0.0f;
+ style.Colors[ImGuiCol_WindowBg].w = 1.0f;
+ }
+
// Setup Platform/Renderer bindings
ImGui_ImplWin32_Init(hwnd);
ImGui_ImplDX9_Init(g_pd3dDevice);
@@ -108,6 +84,7 @@ int main(int, char**)
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
//IM_ASSERT(font != NULL);
+ // Our state
bool show_demo_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
@@ -115,8 +92,6 @@ int main(int, char**)
// Main loop
MSG msg;
ZeroMemory(&msg, sizeof(msg));
- ShowWindow(hwnd, SW_SHOWDEFAULT);
- UpdateWindow(hwnd);
while (msg.message != WM_QUIT)
{
// Poll and handle messages (inputs, window resize, etc.)
@@ -124,10 +99,10 @@ int main(int, char**)
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
- if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
+ if (::PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
{
- TranslateMessage(&msg);
- DispatchMessage(&msg);
+ ::TranslateMessage(&msg);
+ ::DispatchMessage(&msg);
continue;
}
@@ -186,25 +161,106 @@ int main(int, char**)
ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData());
g_pd3dDevice->EndScene();
}
+
+ // Update and Render additional Platform Windows
+ if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
+ {
+ ImGui::UpdatePlatformWindows();
+ ImGui::RenderPlatformWindowsDefault();
+ }
+
HRESULT result = g_pd3dDevice->Present(NULL, NULL, NULL, NULL);
// Handle loss of D3D9 device
if (result == D3DERR_DEVICELOST && g_pd3dDevice->TestCooperativeLevel() == D3DERR_DEVICENOTRESET)
- {
- ImGui_ImplDX9_InvalidateDeviceObjects();
- g_pd3dDevice->Reset(&g_d3dpp);
- ImGui_ImplDX9_CreateDeviceObjects();
- }
+ ResetDevice();
}
ImGui_ImplDX9_Shutdown();
ImGui_ImplWin32_Shutdown();
ImGui::DestroyContext();
- if (g_pd3dDevice) g_pd3dDevice->Release();
- if (pD3D) pD3D->Release();
- DestroyWindow(hwnd);
- UnregisterClass(wc.lpszClassName, wc.hInstance);
+ CleanupDeviceD3D();
+ ::DestroyWindow(hwnd);
+ ::UnregisterClass(wc.lpszClassName, wc.hInstance);
return 0;
}
+
+// Helper functions
+
+bool CreateDeviceD3D(HWND hWnd)
+{
+ if ((g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL)
+ return false;
+
+ // Create the D3DDevice
+ ZeroMemory(&g_d3dpp, sizeof(g_d3dpp));
+ g_d3dpp.Windowed = TRUE;
+ g_d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
+ g_d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
+ g_d3dpp.EnableAutoDepthStencil = TRUE;
+ g_d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
+ g_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; // Present with vsync
+ //g_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; // Present without vsync, maximum unthrottled framerate
+ if (g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &g_d3dpp, &g_pd3dDevice) < 0)
+ return false;
+
+ return true;
+}
+
+void CleanupDeviceD3D()
+{
+ if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; }
+ if (g_pD3D) { g_pD3D->Release(); g_pD3D = NULL; }
+}
+
+void ResetDevice()
+{
+ ImGui_ImplDX9_InvalidateDeviceObjects();
+ HRESULT hr = g_pd3dDevice->Reset(&g_d3dpp);
+ if (hr == D3DERR_INVALIDCALL)
+ IM_ASSERT(0);
+ ImGui_ImplDX9_CreateDeviceObjects();
+}
+
+#ifndef WM_DPICHANGED
+#define WM_DPICHANGED 0x02E0 // From Windows SDK 8.1+ headers
+#endif
+
+// Win32 message handler
+extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
+LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam))
+ return true;
+
+ switch (msg)
+ {
+ case WM_SIZE:
+ if (g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED)
+ {
+ g_d3dpp.BackBufferWidth = LOWORD(lParam);
+ g_d3dpp.BackBufferHeight = HIWORD(lParam);
+ ResetDevice();
+ }
+ return 0;
+ case WM_SYSCOMMAND:
+ if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu
+ return 0;
+ break;
+ case WM_DESTROY:
+ ::PostQuitMessage(0);
+ return 0;
+ case WM_DPICHANGED:
+ if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_DpiEnableScaleViewports)
+ {
+ //const int dpi = HIWORD(wParam);
+ //printf("WM_DPICHANGED to %d (%.0f%%)\n", dpi, (float)dpi / 96.0f * 100.0f);
+ const RECT* suggested_rect = (RECT*)lParam;
+ ::SetWindowPos(hWnd, NULL, suggested_rect->left, suggested_rect->top, suggested_rect->right - suggested_rect->left, suggested_rect->bottom - suggested_rect->top, SWP_NOZORDER | SWP_NOACTIVATE);
+ }
+ break;
+ }
+ return ::DefWindowProc(hWnd, msg, wParam, lParam);
+}
diff --git a/examples/imgui_examples.sln b/examples/imgui_examples.sln
index 488496de..d68f69ec 100644
--- a/examples/imgui_examples.sln
+++ b/examples/imgui_examples.sln
@@ -23,6 +23,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example_sdl_opengl3", "exam
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example_sdl_vulkan", "example_sdl_vulkan\example_sdl_vulkan.vcxproj", "{BAE3D0B5-9695-4EB1-AD0F-75890EB4A3B3}"
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example_sdl_directx11", "example_sdl_directx11\example_sdl_directx11.vcxproj", "{9E1987E3-1F19-45CA-B9C9-D31E791836D8}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@@ -31,14 +33,6 @@ Global
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {9CDA7840-B7A5-496D-A527-E95571496D18}.Debug|Win32.ActiveCfg = Debug|Win32
- {9CDA7840-B7A5-496D-A527-E95571496D18}.Debug|Win32.Build.0 = Debug|Win32
- {9CDA7840-B7A5-496D-A527-E95571496D18}.Debug|x64.ActiveCfg = Debug|x64
- {9CDA7840-B7A5-496D-A527-E95571496D18}.Debug|x64.Build.0 = Debug|x64
- {9CDA7840-B7A5-496D-A527-E95571496D18}.Release|Win32.ActiveCfg = Release|Win32
- {9CDA7840-B7A5-496D-A527-E95571496D18}.Release|Win32.Build.0 = Release|Win32
- {9CDA7840-B7A5-496D-A527-E95571496D18}.Release|x64.ActiveCfg = Release|x64
- {9CDA7840-B7A5-496D-A527-E95571496D18}.Release|x64.Build.0 = Release|x64
{4165A294-21F2-44CA-9B38-E3F935ABADF5}.Debug|Win32.ActiveCfg = Debug|Win32
{4165A294-21F2-44CA-9B38-E3F935ABADF5}.Debug|Win32.Build.0 = Debug|Win32
{4165A294-21F2-44CA-9B38-E3F935ABADF5}.Debug|x64.ActiveCfg = Debug|x64
@@ -47,6 +41,14 @@ Global
{4165A294-21F2-44CA-9B38-E3F935ABADF5}.Release|Win32.Build.0 = Release|Win32
{4165A294-21F2-44CA-9B38-E3F935ABADF5}.Release|x64.ActiveCfg = Release|x64
{4165A294-21F2-44CA-9B38-E3F935ABADF5}.Release|x64.Build.0 = Release|x64
+ {345A953E-A004-4648-B442-DC5F9F11068C}.Debug|Win32.ActiveCfg = Debug|Win32
+ {345A953E-A004-4648-B442-DC5F9F11068C}.Debug|Win32.Build.0 = Debug|Win32
+ {345A953E-A004-4648-B442-DC5F9F11068C}.Debug|x64.ActiveCfg = Debug|x64
+ {345A953E-A004-4648-B442-DC5F9F11068C}.Debug|x64.Build.0 = Debug|x64
+ {345A953E-A004-4648-B442-DC5F9F11068C}.Release|Win32.ActiveCfg = Release|Win32
+ {345A953E-A004-4648-B442-DC5F9F11068C}.Release|Win32.Build.0 = Release|Win32
+ {345A953E-A004-4648-B442-DC5F9F11068C}.Release|x64.ActiveCfg = Release|x64
+ {345A953E-A004-4648-B442-DC5F9F11068C}.Release|x64.Build.0 = Release|x64
{9F316E83-5AE5-4939-A723-305A94F48005}.Debug|Win32.ActiveCfg = Debug|Win32
{9F316E83-5AE5-4939-A723-305A94F48005}.Debug|Win32.Build.0 = Debug|Win32
{9F316E83-5AE5-4939-A723-305A94F48005}.Debug|x64.ActiveCfg = Debug|x64
@@ -55,6 +57,22 @@ Global
{9F316E83-5AE5-4939-A723-305A94F48005}.Release|Win32.Build.0 = Release|Win32
{9F316E83-5AE5-4939-A723-305A94F48005}.Release|x64.ActiveCfg = Release|x64
{9F316E83-5AE5-4939-A723-305A94F48005}.Release|x64.Build.0 = Release|x64
+ {B4CF9797-519D-4AFE-A8F4-5141A6B521D3}.Debug|Win32.ActiveCfg = Debug|Win32
+ {B4CF9797-519D-4AFE-A8F4-5141A6B521D3}.Debug|Win32.Build.0 = Debug|Win32
+ {B4CF9797-519D-4AFE-A8F4-5141A6B521D3}.Debug|x64.ActiveCfg = Debug|x64
+ {B4CF9797-519D-4AFE-A8F4-5141A6B521D3}.Debug|x64.Build.0 = Debug|x64
+ {B4CF9797-519D-4AFE-A8F4-5141A6B521D3}.Release|Win32.ActiveCfg = Release|Win32
+ {B4CF9797-519D-4AFE-A8F4-5141A6B521D3}.Release|Win32.Build.0 = Release|Win32
+ {B4CF9797-519D-4AFE-A8F4-5141A6B521D3}.Release|x64.ActiveCfg = Release|x64
+ {B4CF9797-519D-4AFE-A8F4-5141A6B521D3}.Release|x64.Build.0 = Release|x64
+ {9CDA7840-B7A5-496D-A527-E95571496D18}.Debug|Win32.ActiveCfg = Debug|Win32
+ {9CDA7840-B7A5-496D-A527-E95571496D18}.Debug|Win32.Build.0 = Debug|Win32
+ {9CDA7840-B7A5-496D-A527-E95571496D18}.Debug|x64.ActiveCfg = Debug|x64
+ {9CDA7840-B7A5-496D-A527-E95571496D18}.Debug|x64.Build.0 = Debug|x64
+ {9CDA7840-B7A5-496D-A527-E95571496D18}.Release|Win32.ActiveCfg = Release|Win32
+ {9CDA7840-B7A5-496D-A527-E95571496D18}.Release|Win32.Build.0 = Release|Win32
+ {9CDA7840-B7A5-496D-A527-E95571496D18}.Release|x64.ActiveCfg = Release|x64
+ {9CDA7840-B7A5-496D-A527-E95571496D18}.Release|x64.Build.0 = Release|x64
{4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Debug|Win32.ActiveCfg = Debug|Win32
{4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Debug|Win32.Build.0 = Debug|Win32
{4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Debug|x64.ActiveCfg = Debug|x64
@@ -63,14 +81,14 @@ Global
{4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Release|Win32.Build.0 = Release|Win32
{4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Release|x64.ActiveCfg = Release|x64
{4A1FB5EA-22F5-42A8-AB92-1D2DF5D47FB9}.Release|x64.Build.0 = Release|x64
- {345A953E-A004-4648-B442-DC5F9F11068C}.Debug|Win32.ActiveCfg = Debug|Win32
- {345A953E-A004-4648-B442-DC5F9F11068C}.Debug|Win32.Build.0 = Debug|Win32
- {345A953E-A004-4648-B442-DC5F9F11068C}.Debug|x64.ActiveCfg = Debug|x64
- {345A953E-A004-4648-B442-DC5F9F11068C}.Debug|x64.Build.0 = Debug|x64
- {345A953E-A004-4648-B442-DC5F9F11068C}.Release|Win32.ActiveCfg = Release|Win32
- {345A953E-A004-4648-B442-DC5F9F11068C}.Release|Win32.Build.0 = Release|Win32
- {345A953E-A004-4648-B442-DC5F9F11068C}.Release|x64.ActiveCfg = Release|x64
- {345A953E-A004-4648-B442-DC5F9F11068C}.Release|x64.Build.0 = Release|x64
+ {57E2DF5A-6FC8-45BB-99DD-91A18C646E80}.Debug|Win32.ActiveCfg = Debug|Win32
+ {57E2DF5A-6FC8-45BB-99DD-91A18C646E80}.Debug|Win32.Build.0 = Debug|Win32
+ {57E2DF5A-6FC8-45BB-99DD-91A18C646E80}.Debug|x64.ActiveCfg = Debug|x64
+ {57E2DF5A-6FC8-45BB-99DD-91A18C646E80}.Debug|x64.Build.0 = Debug|x64
+ {57E2DF5A-6FC8-45BB-99DD-91A18C646E80}.Release|Win32.ActiveCfg = Release|Win32
+ {57E2DF5A-6FC8-45BB-99DD-91A18C646E80}.Release|Win32.Build.0 = Release|Win32
+ {57E2DF5A-6FC8-45BB-99DD-91A18C646E80}.Release|x64.ActiveCfg = Release|x64
+ {57E2DF5A-6FC8-45BB-99DD-91A18C646E80}.Release|x64.Build.0 = Release|x64
{2AE17FDE-F7F3-4CAC-ADAB-0710EDA4F741}.Debug|Win32.ActiveCfg = Debug|Win32
{2AE17FDE-F7F3-4CAC-ADAB-0710EDA4F741}.Debug|Win32.Build.0 = Debug|Win32
{2AE17FDE-F7F3-4CAC-ADAB-0710EDA4F741}.Debug|x64.ActiveCfg = Debug|x64
@@ -87,14 +105,6 @@ Global
{BBAEB705-1669-40F3-8567-04CF6A991F4C}.Release|Win32.Build.0 = Release|Win32
{BBAEB705-1669-40F3-8567-04CF6A991F4C}.Release|x64.ActiveCfg = Release|x64
{BBAEB705-1669-40F3-8567-04CF6A991F4C}.Release|x64.Build.0 = Release|x64
- {57E2DF5A-6FC8-45BB-99DD-91A18C646E80}.Debug|Win32.ActiveCfg = Debug|Win32
- {57E2DF5A-6FC8-45BB-99DD-91A18C646E80}.Debug|Win32.Build.0 = Debug|Win32
- {57E2DF5A-6FC8-45BB-99DD-91A18C646E80}.Debug|x64.ActiveCfg = Debug|x64
- {57E2DF5A-6FC8-45BB-99DD-91A18C646E80}.Debug|x64.Build.0 = Debug|x64
- {57E2DF5A-6FC8-45BB-99DD-91A18C646E80}.Release|Win32.ActiveCfg = Release|Win32
- {57E2DF5A-6FC8-45BB-99DD-91A18C646E80}.Release|Win32.Build.0 = Release|Win32
- {57E2DF5A-6FC8-45BB-99DD-91A18C646E80}.Release|x64.ActiveCfg = Release|x64
- {57E2DF5A-6FC8-45BB-99DD-91A18C646E80}.Release|x64.Build.0 = Release|x64
{BAE3D0B5-9695-4EB1-AD0F-75890EB4A3B3}.Debug|Win32.ActiveCfg = Debug|Win32
{BAE3D0B5-9695-4EB1-AD0F-75890EB4A3B3}.Debug|Win32.Build.0 = Debug|Win32
{BAE3D0B5-9695-4EB1-AD0F-75890EB4A3B3}.Debug|x64.ActiveCfg = Debug|x64
@@ -103,14 +113,14 @@ Global
{BAE3D0B5-9695-4EB1-AD0F-75890EB4A3B3}.Release|Win32.Build.0 = Release|Win32
{BAE3D0B5-9695-4EB1-AD0F-75890EB4A3B3}.Release|x64.ActiveCfg = Release|x64
{BAE3D0B5-9695-4EB1-AD0F-75890EB4A3B3}.Release|x64.Build.0 = Release|x64
- {B4CF9797-519D-4AFE-A8F4-5141A6B521D3}.Debug|Win32.ActiveCfg = Debug|Win32
- {B4CF9797-519D-4AFE-A8F4-5141A6B521D3}.Debug|Win32.Build.0 = Debug|Win32
- {B4CF9797-519D-4AFE-A8F4-5141A6B521D3}.Debug|x64.ActiveCfg = Debug|x64
- {B4CF9797-519D-4AFE-A8F4-5141A6B521D3}.Debug|x64.Build.0 = Debug|x64
- {B4CF9797-519D-4AFE-A8F4-5141A6B521D3}.Release|Win32.ActiveCfg = Release|Win32
- {B4CF9797-519D-4AFE-A8F4-5141A6B521D3}.Release|Win32.Build.0 = Release|Win32
- {B4CF9797-519D-4AFE-A8F4-5141A6B521D3}.Release|x64.ActiveCfg = Release|x64
- {B4CF9797-519D-4AFE-A8F4-5141A6B521D3}.Release|x64.Build.0 = Release|x64
+ {9E1987E3-1F19-45CA-B9C9-D31E791836D8}.Debug|Win32.ActiveCfg = Debug|Win32
+ {9E1987E3-1F19-45CA-B9C9-D31E791836D8}.Debug|Win32.Build.0 = Debug|Win32
+ {9E1987E3-1F19-45CA-B9C9-D31E791836D8}.Debug|x64.ActiveCfg = Debug|x64
+ {9E1987E3-1F19-45CA-B9C9-D31E791836D8}.Debug|x64.Build.0 = Debug|x64
+ {9E1987E3-1F19-45CA-B9C9-D31E791836D8}.Release|Win32.ActiveCfg = Release|Win32
+ {9E1987E3-1F19-45CA-B9C9-D31E791836D8}.Release|Win32.Build.0 = Release|Win32
+ {9E1987E3-1F19-45CA-B9C9-D31E791836D8}.Release|x64.ActiveCfg = Release|x64
+ {9E1987E3-1F19-45CA-B9C9-D31E791836D8}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/examples/imgui_impl_allegro5.cpp b/examples/imgui_impl_allegro5.cpp
index 8d534516..525ad5c9 100644
--- a/examples/imgui_impl_allegro5.cpp
+++ b/examples/imgui_impl_allegro5.cpp
@@ -15,6 +15,10 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
+// 2019-07-21: Inputs: Added mapping for ImGuiKey_KeyPadEnter.
+// 2019-05-11: Inputs: Don't filter character value from ALLEGRO_EVENT_KEY_CHAR before calling AddInputCharacter().
+// 2019-04-30: Renderer: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
+// 2018-11-30: Platform: Added touchscreen support.
// 2018-11-30: Misc: Setting up io.BackendPlatformName/io.BackendRendererName so they can be displayed in the About Window.
// 2018-06-13: Platform: Added clipboard support (from Allegro 5.1.12).
// 2018-06-13: Renderer: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle.
@@ -59,19 +63,9 @@ struct ImDrawVertAllegro
ALLEGRO_COLOR col;
};
-// Render function.
-// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
-void ImGui_ImplAllegro5_RenderDrawData(ImDrawData* draw_data)
+static void ImGui_ImplAllegro5_SetupRenderState(ImDrawData* draw_data)
{
- // Backup Allegro state that will be modified
- ALLEGRO_TRANSFORM last_transform = *al_get_current_transform();
- ALLEGRO_TRANSFORM last_projection_transform = *al_get_current_projection_transform();
- int last_clip_x, last_clip_y, last_clip_w, last_clip_h;
- al_get_clipping_rectangle(&last_clip_x, &last_clip_y, &last_clip_w, &last_clip_h);
- int last_blender_op, last_blender_src, last_blender_dst;
- al_get_blender(&last_blender_op, &last_blender_src, &last_blender_dst);
-
- // Setup render state
+ // Setup blending
al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA);
// Setup orthographic projection matrix
@@ -87,7 +81,28 @@ void ImGui_ImplAllegro5_RenderDrawData(ImDrawData* draw_data)
al_orthographic_transform(&transform, L, T, 1.0f, R, B, -1.0f);
al_use_projection_transform(&transform);
}
+}
+
+// Render function.
+// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
+void ImGui_ImplAllegro5_RenderDrawData(ImDrawData* draw_data)
+{
+ // Avoid rendering when minimized
+ if (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f)
+ return;
+
+ // Backup Allegro state that will be modified
+ ALLEGRO_TRANSFORM last_transform = *al_get_current_transform();
+ ALLEGRO_TRANSFORM last_projection_transform = *al_get_current_projection_transform();
+ int last_clip_x, last_clip_y, last_clip_w, last_clip_h;
+ al_get_clipping_rectangle(&last_clip_x, &last_clip_y, &last_clip_w, &last_clip_h);
+ int last_blender_op, last_blender_src, last_blender_dst;
+ al_get_blender(&last_blender_op, &last_blender_src, &last_blender_dst);
+
+ // Setup desired render state
+ ImGui_ImplAllegro5_SetupRenderState(draw_data);
+ // Render command lists
for (int n = 0; n < draw_data->CmdListsCount; n++)
{
const ImDrawList* cmd_list = draw_data->CmdLists[n];
@@ -122,19 +137,26 @@ void ImGui_ImplAllegro5_RenderDrawData(ImDrawData* draw_data)
indices = (const int*)cmd_list->IdxBuffer.Data;
}
+ // Render command lists
int idx_offset = 0;
- ImVec2 pos = draw_data->DisplayPos;
+ ImVec2 clip_off = draw_data->DisplayPos;
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
{
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
if (pcmd->UserCallback)
{
- pcmd->UserCallback(cmd_list, pcmd);
+ // User callback, registered via ImDrawList::AddCallback()
+ // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
+ if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
+ ImGui_ImplAllegro5_SetupRenderState(draw_data);
+ else
+ pcmd->UserCallback(cmd_list, pcmd);
}
else
{
+ // Draw
ALLEGRO_BITMAP* texture = (ALLEGRO_BITMAP*)pcmd->TextureId;
- al_set_clipping_rectangle(pcmd->ClipRect.x - pos.x, pcmd->ClipRect.y - pos.y, pcmd->ClipRect.z - pcmd->ClipRect.x, pcmd->ClipRect.w - pcmd->ClipRect.y);
+ al_set_clipping_rectangle(pcmd->ClipRect.x - clip_off.x, pcmd->ClipRect.y - clip_off.y, pcmd->ClipRect.z - pcmd->ClipRect.x, pcmd->ClipRect.w - pcmd->ClipRect.y);
al_draw_prim(&vertices[0], g_VertexDecl, texture, idx_offset, idx_offset + pcmd->ElemCount, ALLEGRO_PRIM_TRIANGLE_LIST);
}
idx_offset += pcmd->ElemCount;
@@ -152,7 +174,7 @@ bool ImGui_ImplAllegro5_CreateDeviceObjects()
{
// Build texture atlas
ImGuiIO &io = ImGui::GetIO();
- unsigned char *pixels;
+ unsigned char* pixels;
int width, height;
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
@@ -261,12 +283,14 @@ bool ImGui_ImplAllegro5_Init(ALLEGRO_DISPLAY* display)
io.KeyMap[ImGuiKey_Space] = ALLEGRO_KEY_SPACE;
io.KeyMap[ImGuiKey_Enter] = ALLEGRO_KEY_ENTER;
io.KeyMap[ImGuiKey_Escape] = ALLEGRO_KEY_ESCAPE;
+ io.KeyMap[ImGuiKey_KeyPadEnter] = ALLEGRO_KEY_PAD_ENTER;
io.KeyMap[ImGuiKey_A] = ALLEGRO_KEY_A;
io.KeyMap[ImGuiKey_C] = ALLEGRO_KEY_C;
io.KeyMap[ImGuiKey_V] = ALLEGRO_KEY_V;
io.KeyMap[ImGuiKey_X] = ALLEGRO_KEY_X;
io.KeyMap[ImGuiKey_Y] = ALLEGRO_KEY_Y;
io.KeyMap[ImGuiKey_Z] = ALLEGRO_KEY_Z;
+ io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
#if ALLEGRO_HAS_CLIPBOARD
io.SetClipboardTextFn = ImGui_ImplAllegro5_SetClipboardText;
@@ -304,13 +328,35 @@ bool ImGui_ImplAllegro5_ProcessEvent(ALLEGRO_EVENT *ev)
switch (ev->type)
{
case ALLEGRO_EVENT_MOUSE_AXES:
- io.MouseWheel += ev->mouse.dz;
- io.MouseWheelH += ev->mouse.dw;
+ if (ev->mouse.display == g_Display)
+ {
+ io.MouseWheel += ev->mouse.dz;
+ io.MouseWheelH += ev->mouse.dw;
+ io.MousePos = ImVec2(ev->mouse.x, ev->mouse.y);
+ }
+ return true;
+ case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
+ case ALLEGRO_EVENT_MOUSE_BUTTON_UP:
+ if (ev->mouse.display == g_Display && ev->mouse.button <= 5)
+ io.MouseDown[ev->mouse.button - 1] = (ev->type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN);
+ return true;
+ case ALLEGRO_EVENT_TOUCH_MOVE:
+ if (ev->touch.display == g_Display)
+ io.MousePos = ImVec2(ev->touch.x, ev->touch.y);
+ return true;
+ case ALLEGRO_EVENT_TOUCH_BEGIN:
+ case ALLEGRO_EVENT_TOUCH_END:
+ case ALLEGRO_EVENT_TOUCH_CANCEL:
+ if (ev->touch.display == g_Display && ev->touch.primary)
+ io.MouseDown[0] = (ev->type == ALLEGRO_EVENT_TOUCH_BEGIN);
+ return true;
+ case ALLEGRO_EVENT_MOUSE_LEAVE_DISPLAY:
+ if (ev->mouse.display == g_Display)
+ io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
return true;
case ALLEGRO_EVENT_KEY_CHAR:
if (ev->keyboard.display == g_Display)
- if (ev->keyboard.unichar > 0 && ev->keyboard.unichar < 0x10000)
- io.AddInputCharacter((unsigned short)ev->keyboard.unichar);
+ io.AddInputCharacter((unsigned int)ev->keyboard.unichar);
return true;
case ALLEGRO_EVENT_KEY_DOWN:
case ALLEGRO_EVENT_KEY_UP:
@@ -375,21 +421,5 @@ void ImGui_ImplAllegro5_NewFrame()
io.KeyAlt = al_key_down(&keys, ALLEGRO_KEY_ALT) || al_key_down(&keys, ALLEGRO_KEY_ALTGR);
io.KeySuper = al_key_down(&keys, ALLEGRO_KEY_LWIN) || al_key_down(&keys, ALLEGRO_KEY_RWIN);
- ALLEGRO_MOUSE_STATE mouse;
- if (keys.display == g_Display)
- {
- al_get_mouse_state(&mouse);
- io.MousePos = ImVec2((float)mouse.x, (float)mouse.y);
- }
- else
- {
- io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
- }
-
- al_get_mouse_state(&mouse);
- io.MouseDown[0] = mouse.buttons & (1 << 0);
- io.MouseDown[1] = mouse.buttons & (1 << 1);
- io.MouseDown[2] = mouse.buttons & (1 << 2);
-
ImGui_ImplAllegro5_UpdateMouseCursor();
}
diff --git a/examples/imgui_impl_dx10.cpp b/examples/imgui_impl_dx10.cpp
index de3c9e38..90deb230 100644
--- a/examples/imgui_impl_dx10.cpp
+++ b/examples/imgui_impl_dx10.cpp
@@ -4,6 +4,7 @@
// Implemented features:
// [X] Renderer: User texture binding. Use 'ID3D10ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
// [X] Renderer: Multi-viewport support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
+// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices.
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
// If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
@@ -11,7 +12,10 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
-// 2018-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
+// 2019-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
+// 2019-07-21: DirectX10: Backup, clear and restore Geometry Shader is any is bound when calling ImGui_ImplDX10_RenderDrawData().
+// 2019-05-29: DirectX10: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag.
+// 2019-04-30: DirectX10: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
// 2018-12-03: Misc: Added #pragma comment statement to automatically link with d3dcompiler.lib when using D3DCompile().
// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
// 2018-07-13: DirectX10: Fixed unreleased resources in Init and Shutdown functions.
@@ -61,10 +65,46 @@ struct VERTEX_CONSTANT_BUFFER
static void ImGui_ImplDX10_InitPlatformInterface();
static void ImGui_ImplDX10_ShutdownPlatformInterface();
+static void ImGui_ImplDX10_SetupRenderState(ImDrawData* draw_data, ID3D10Device* ctx)
+{
+ // Setup viewport
+ D3D10_VIEWPORT vp;
+ memset(&vp, 0, sizeof(D3D10_VIEWPORT));
+ vp.Width = (UINT)draw_data->DisplaySize.x;
+ vp.Height = (UINT)draw_data->DisplaySize.y;
+ vp.MinDepth = 0.0f;
+ vp.MaxDepth = 1.0f;
+ vp.TopLeftX = vp.TopLeftY = 0;
+ ctx->RSSetViewports(1, &vp);
+
+ // Bind shader and vertex buffers
+ unsigned int stride = sizeof(ImDrawVert);
+ unsigned int offset = 0;
+ ctx->IASetInputLayout(g_pInputLayout);
+ ctx->IASetVertexBuffers(0, 1, &g_pVB, &stride, &offset);
+ ctx->IASetIndexBuffer(g_pIB, sizeof(ImDrawIdx) == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT, 0);
+ ctx->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
+ ctx->VSSetShader(g_pVertexShader);
+ ctx->VSSetConstantBuffers(0, 1, &g_pVertexConstantBuffer);
+ ctx->PSSetShader(g_pPixelShader);
+ ctx->PSSetSamplers(0, 1, &g_pFontSampler);
+ ctx->GSSetShader(NULL);
+
+ // Setup render state
+ const float blend_factor[4] = { 0.f, 0.f, 0.f, 0.f };
+ ctx->OMSetBlendState(g_pBlendState, blend_factor, 0xffffffff);
+ ctx->OMSetDepthStencilState(g_pDepthStencilState, 0);
+ ctx->RSSetState(g_pRasterizerState);
+}
+
// Render function
// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
{
+ // Avoid rendering when minimized
+ if (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f)
+ return;
+
ID3D10Device* ctx = g_pd3dDevice;
// Create and grow vertex/index buffers if needed
@@ -114,7 +154,7 @@ void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
g_pIB->Unmap();
// Setup orthographic projection matrix into our constant buffer
- // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayMin is (0,0) for single viewport apps.
+ // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
{
void* mapped_resource;
if (g_pVertexConstantBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &mapped_resource) != S_OK)
@@ -151,6 +191,7 @@ void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
ID3D10SamplerState* PSSampler;
ID3D10PixelShader* PS;
ID3D10VertexShader* VS;
+ ID3D10GeometryShader* GS;
D3D10_PRIMITIVE_TOPOLOGY PrimitiveTopology;
ID3D10Buffer* IndexBuffer, *VertexBuffer, *VSConstantBuffer;
UINT IndexBufferOffset, VertexBufferStride, VertexBufferOffset;
@@ -169,43 +210,20 @@ void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
ctx->PSGetShader(&old.PS);
ctx->VSGetShader(&old.VS);
ctx->VSGetConstantBuffers(0, 1, &old.VSConstantBuffer);
+ ctx->GSGetShader(&old.GS);
ctx->IAGetPrimitiveTopology(&old.PrimitiveTopology);
ctx->IAGetIndexBuffer(&old.IndexBuffer, &old.IndexBufferFormat, &old.IndexBufferOffset);
ctx->IAGetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset);
ctx->IAGetInputLayout(&old.InputLayout);
- // Setup viewport
- D3D10_VIEWPORT vp;
- memset(&vp, 0, sizeof(D3D10_VIEWPORT));
- vp.Width = (UINT)draw_data->DisplaySize.x;
- vp.Height = (UINT)draw_data->DisplaySize.y;
- vp.MinDepth = 0.0f;
- vp.MaxDepth = 1.0f;
- vp.TopLeftX = vp.TopLeftY = 0;
- ctx->RSSetViewports(1, &vp);
-
- // Bind shader and vertex buffers
- unsigned int stride = sizeof(ImDrawVert);
- unsigned int offset = 0;
- ctx->IASetInputLayout(g_pInputLayout);
- ctx->IASetVertexBuffers(0, 1, &g_pVB, &stride, &offset);
- ctx->IASetIndexBuffer(g_pIB, sizeof(ImDrawIdx) == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT, 0);
- ctx->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
- ctx->VSSetShader(g_pVertexShader);
- ctx->VSSetConstantBuffers(0, 1, &g_pVertexConstantBuffer);
- ctx->PSSetShader(g_pPixelShader);
- ctx->PSSetSamplers(0, 1, &g_pFontSampler);
-
- // Setup render state
- const float blend_factor[4] = { 0.f, 0.f, 0.f, 0.f };
- ctx->OMSetBlendState(g_pBlendState, blend_factor, 0xffffffff);
- ctx->OMSetDepthStencilState(g_pDepthStencilState, 0);
- ctx->RSSetState(g_pRasterizerState);
+ // Setup desired DX state
+ ImGui_ImplDX10_SetupRenderState(draw_data, ctx);
// Render command lists
- int vtx_offset = 0;
- int idx_offset = 0;
- ImVec2 pos = draw_data->DisplayPos;
+ // (Because we merged all buffers into a single one, we maintain our own offset into them)
+ int global_vtx_offset = 0;
+ int global_idx_offset = 0;
+ ImVec2 clip_off = draw_data->DisplayPos;
for (int n = 0; n < draw_data->CmdListsCount; n++)
{
const ImDrawList* cmd_list = draw_data->CmdLists[n];
@@ -214,23 +232,27 @@ void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
if (pcmd->UserCallback)
{
- // User callback (registered via ImDrawList::AddCallback)
- pcmd->UserCallback(cmd_list, pcmd);
+ // User callback, registered via ImDrawList::AddCallback()
+ // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
+ if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
+ ImGui_ImplDX10_SetupRenderState(draw_data, ctx);
+ else
+ pcmd->UserCallback(cmd_list, pcmd);
}
else
{
// Apply scissor/clipping rectangle
- const D3D10_RECT r = { (LONG)(pcmd->ClipRect.x - pos.x), (LONG)(pcmd->ClipRect.y - pos.y), (LONG)(pcmd->ClipRect.z - pos.x), (LONG)(pcmd->ClipRect.w - pos.y)};
+ const D3D10_RECT r = { (LONG)(pcmd->ClipRect.x - clip_off.x), (LONG)(pcmd->ClipRect.y - clip_off.y), (LONG)(pcmd->ClipRect.z - clip_off.x), (LONG)(pcmd->ClipRect.w - clip_off.y)};
ctx->RSSetScissorRects(1, &r);
// Bind texture, Draw
ID3D10ShaderResourceView* texture_srv = (ID3D10ShaderResourceView*)pcmd->TextureId;
ctx->PSSetShaderResources(0, 1, &texture_srv);
- ctx->DrawIndexed(pcmd->ElemCount, idx_offset, vtx_offset);
+ ctx->DrawIndexed(pcmd->ElemCount, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset);
}
- idx_offset += pcmd->ElemCount;
}
- vtx_offset += cmd_list->VtxBuffer.Size;
+ global_idx_offset += cmd_list->IdxBuffer.Size;
+ global_vtx_offset += cmd_list->VtxBuffer.Size;
}
// Restore modified DX state
@@ -243,6 +265,7 @@ void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
ctx->PSSetSamplers(0, 1, &old.PSSampler); if (old.PSSampler) old.PSSampler->Release();
ctx->PSSetShader(old.PS); if (old.PS) old.PS->Release();
ctx->VSSetShader(old.VS); if (old.VS) old.VS->Release();
+ ctx->GSSetShader(old.GS); if (old.GS) old.GS->Release();
ctx->VSSetConstantBuffers(0, 1, &old.VSConstantBuffer); if (old.VSConstantBuffer) old.VSConstantBuffer->Release();
ctx->IASetPrimitiveTopology(old.PrimitiveTopology);
ctx->IASetIndexBuffer(old.IndexBuffer, old.IndexBufferFormat, old.IndexBufferOffset); if (old.IndexBuffer) old.IndexBuffer->Release();
@@ -476,8 +499,9 @@ bool ImGui_ImplDX10_Init(ID3D10Device* device)
{
// Setup back-end capabilities flags
ImGuiIO& io = ImGui::GetIO();
- io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
io.BackendRendererName = "imgui_impl_dx10";
+ io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
+ io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
// Get factory from device
IDXGIDevice* pDXGIDevice = NULL;
@@ -493,6 +517,7 @@ bool ImGui_ImplDX10_Init(ID3D10Device* device)
}
if (pDXGIDevice) pDXGIDevice->Release();
if (pDXGIAdapter) pDXGIAdapter->Release();
+ g_pd3dDevice->AddRef();
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
ImGui_ImplDX10_InitPlatformInterface();
@@ -504,7 +529,7 @@ void ImGui_ImplDX10_Shutdown()
ImGui_ImplDX10_ShutdownPlatformInterface();
ImGui_ImplDX10_InvalidateDeviceObjects();
if (g_pFactory) { g_pFactory->Release(); g_pFactory = NULL; }
- g_pd3dDevice = NULL;
+ if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; }
}
void ImGui_ImplDX10_NewFrame()
@@ -533,7 +558,9 @@ static void ImGui_ImplDX10_CreateWindow(ImGuiViewport* viewport)
ImGuiViewportDataDx10* data = IM_NEW(ImGuiViewportDataDx10)();
viewport->RendererUserData = data;
- HWND hwnd = (HWND)viewport->PlatformHandle;
+ // PlatformHandleRaw should always be a HWND, whereas PlatformHandle might be a higher-level handle (e.g. GLFWWindow*, SDL_Window*).
+ // Some back-ends will leave PlatformHandleRaw NULL, in which case we assume PlatformHandle will contain the HWND.
+ HWND hwnd = viewport->PlatformHandleRaw ? (HWND)viewport->PlatformHandleRaw : (HWND)viewport->PlatformHandle;
IM_ASSERT(hwnd != 0);
// Create swap chain
diff --git a/examples/imgui_impl_dx10.h b/examples/imgui_impl_dx10.h
index 17bfaaf4..4309dc65 100644
--- a/examples/imgui_impl_dx10.h
+++ b/examples/imgui_impl_dx10.h
@@ -4,6 +4,7 @@
// Implemented features:
// [X] Renderer: User texture binding. Use 'ID3D10ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
// [X] Renderer: Multi-viewport support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
+// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices.
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
// If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
diff --git a/examples/imgui_impl_dx11.cpp b/examples/imgui_impl_dx11.cpp
index 9a242784..14e1b437 100644
--- a/examples/imgui_impl_dx11.cpp
+++ b/examples/imgui_impl_dx11.cpp
@@ -4,6 +4,7 @@
// Implemented features:
// [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
// [X] Renderer: Multi-viewport support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
+// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices.
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
// If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp
@@ -11,7 +12,11 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
-// 2018-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
+// 2019-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
+// 2019-08-01: DirectX11: Fixed code querying the Geometry Shader state (would generally error with Debug layer enabled).
+// 2019-07-21: DirectX11: Backup, clear and restore Geometry Shader is any is bound when calling ImGui_ImplDX10_RenderDrawData. Clearing Hull/Domain/Compute shaders without backup/restore.
+// 2019-05-29: DirectX11: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag.
+// 2019-04-30: DirectX11: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
// 2018-12-03: Misc: Added #pragma comment statement to automatically link with d3dcompiler.lib when using D3DCompile().
// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
// 2018-08-01: DirectX11: Querying for IDXGIFactory instead of IDXGIFactory1 to increase compatibility.
@@ -61,10 +66,49 @@ struct VERTEX_CONSTANT_BUFFER
static void ImGui_ImplDX11_InitPlatformInterface();
static void ImGui_ImplDX11_ShutdownPlatformInterface();
+static void ImGui_ImplDX11_SetupRenderState(ImDrawData* draw_data, ID3D11DeviceContext* ctx)
+{
+ // Setup viewport
+ D3D11_VIEWPORT vp;
+ memset(&vp, 0, sizeof(D3D11_VIEWPORT));
+ vp.Width = draw_data->DisplaySize.x;
+ vp.Height = draw_data->DisplaySize.y;
+ vp.MinDepth = 0.0f;
+ vp.MaxDepth = 1.0f;
+ vp.TopLeftX = vp.TopLeftY = 0;
+ ctx->RSSetViewports(1, &vp);
+
+ // Setup shader and vertex buffers
+ unsigned int stride = sizeof(ImDrawVert);
+ unsigned int offset = 0;
+ ctx->IASetInputLayout(g_pInputLayout);
+ ctx->IASetVertexBuffers(0, 1, &g_pVB, &stride, &offset);
+ ctx->IASetIndexBuffer(g_pIB, sizeof(ImDrawIdx) == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT, 0);
+ ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
+ ctx->VSSetShader(g_pVertexShader, NULL, 0);
+ ctx->VSSetConstantBuffers(0, 1, &g_pVertexConstantBuffer);
+ ctx->PSSetShader(g_pPixelShader, NULL, 0);
+ ctx->PSSetSamplers(0, 1, &g_pFontSampler);
+ ctx->GSSetShader(NULL, NULL, 0);
+ ctx->HSSetShader(NULL, NULL, 0); // In theory we should backup and restore this as well.. very infrequently used..
+ ctx->DSSetShader(NULL, NULL, 0); // In theory we should backup and restore this as well.. very infrequently used..
+ ctx->CSSetShader(NULL, NULL, 0); // In theory we should backup and restore this as well.. very infrequently used..
+
+ // Setup blend state
+ const float blend_factor[4] = { 0.f, 0.f, 0.f, 0.f };
+ ctx->OMSetBlendState(g_pBlendState, blend_factor, 0xffffffff);
+ ctx->OMSetDepthStencilState(g_pDepthStencilState, 0);
+ ctx->RSSetState(g_pRasterizerState);
+}
+
// Render function
// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
{
+ // Avoid rendering when minimized
+ if (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f)
+ return;
+
ID3D11DeviceContext* ctx = g_pd3dDeviceContext;
// Create and grow vertex/index buffers if needed
@@ -96,7 +140,7 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
return;
}
- // Copy and convert all vertices into a single contiguous buffer
+ // Upload vertex/index data into a single contiguous GPU buffer
D3D11_MAPPED_SUBRESOURCE vtx_resource, idx_resource;
if (ctx->Map(g_pVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &vtx_resource) != S_OK)
return;
@@ -116,7 +160,7 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
ctx->Unmap(g_pIB, 0);
// Setup orthographic projection matrix into our constant buffer
- // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayMin is (0,0) for single viewport apps.
+ // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
{
D3D11_MAPPED_SUBRESOURCE mapped_resource;
if (ctx->Map(g_pVertexConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_resource) != S_OK)
@@ -153,8 +197,9 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
ID3D11SamplerState* PSSampler;
ID3D11PixelShader* PS;
ID3D11VertexShader* VS;
- UINT PSInstancesCount, VSInstancesCount;
- ID3D11ClassInstance* PSInstances[256], *VSInstances[256]; // 256 is max according to PSSetShader documentation
+ ID3D11GeometryShader* GS;
+ UINT PSInstancesCount, VSInstancesCount, GSInstancesCount;
+ ID3D11ClassInstance *PSInstances[256], *VSInstances[256], *GSInstances[256]; // 256 is max according to PSSetShader documentation
D3D11_PRIMITIVE_TOPOLOGY PrimitiveTopology;
ID3D11Buffer* IndexBuffer, *VertexBuffer, *VSConstantBuffer;
UINT IndexBufferOffset, VertexBufferStride, VertexBufferOffset;
@@ -170,72 +215,54 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
ctx->OMGetDepthStencilState(&old.DepthStencilState, &old.StencilRef);
ctx->PSGetShaderResources(0, 1, &old.PSShaderResource);
ctx->PSGetSamplers(0, 1, &old.PSSampler);
- old.PSInstancesCount = old.VSInstancesCount = 256;
+ old.PSInstancesCount = old.VSInstancesCount = old.GSInstancesCount = 256;
ctx->PSGetShader(&old.PS, old.PSInstances, &old.PSInstancesCount);
ctx->VSGetShader(&old.VS, old.VSInstances, &old.VSInstancesCount);
ctx->VSGetConstantBuffers(0, 1, &old.VSConstantBuffer);
+ ctx->GSGetShader(&old.GS, old.GSInstances, &old.GSInstancesCount);
+
ctx->IAGetPrimitiveTopology(&old.PrimitiveTopology);
ctx->IAGetIndexBuffer(&old.IndexBuffer, &old.IndexBufferFormat, &old.IndexBufferOffset);
ctx->IAGetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset);
ctx->IAGetInputLayout(&old.InputLayout);
- // Setup viewport
- D3D11_VIEWPORT vp;
- memset(&vp, 0, sizeof(D3D11_VIEWPORT));
- vp.Width = draw_data->DisplaySize.x;
- vp.Height = draw_data->DisplaySize.y;
- vp.MinDepth = 0.0f;
- vp.MaxDepth = 1.0f;
- vp.TopLeftX = vp.TopLeftY = 0;
- ctx->RSSetViewports(1, &vp);
-
- // Bind shader and vertex buffers
- unsigned int stride = sizeof(ImDrawVert);
- unsigned int offset = 0;
- ctx->IASetInputLayout(g_pInputLayout);
- ctx->IASetVertexBuffers(0, 1, &g_pVB, &stride, &offset);
- ctx->IASetIndexBuffer(g_pIB, sizeof(ImDrawIdx) == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT, 0);
- ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
- ctx->VSSetShader(g_pVertexShader, NULL, 0);
- ctx->VSSetConstantBuffers(0, 1, &g_pVertexConstantBuffer);
- ctx->PSSetShader(g_pPixelShader, NULL, 0);
- ctx->PSSetSamplers(0, 1, &g_pFontSampler);
-
- // Setup render state
- const float blend_factor[4] = { 0.f, 0.f, 0.f, 0.f };
- ctx->OMSetBlendState(g_pBlendState, blend_factor, 0xffffffff);
- ctx->OMSetDepthStencilState(g_pDepthStencilState, 0);
- ctx->RSSetState(g_pRasterizerState);
+ // Setup desired DX state
+ ImGui_ImplDX11_SetupRenderState(draw_data, ctx);
// Render command lists
- int vtx_offset = 0;
- int idx_offset = 0;
- ImVec2 pos = draw_data->DisplayPos;
+ // (Because we merged all buffers into a single one, we maintain our own offset into them)
+ int global_idx_offset = 0;
+ int global_vtx_offset = 0;
+ ImVec2 clip_off = draw_data->DisplayPos;
for (int n = 0; n < draw_data->CmdListsCount; n++)
{
const ImDrawList* cmd_list = draw_data->CmdLists[n];
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
{
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
- if (pcmd->UserCallback)
+ if (pcmd->UserCallback != NULL)
{
- // User callback (registered via ImDrawList::AddCallback)
- pcmd->UserCallback(cmd_list, pcmd);
+ // User callback, registered via ImDrawList::AddCallback()
+ // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
+ if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
+ ImGui_ImplDX11_SetupRenderState(draw_data, ctx);
+ else
+ pcmd->UserCallback(cmd_list, pcmd);
}
else
{
// Apply scissor/clipping rectangle
- const D3D11_RECT r = { (LONG)(pcmd->ClipRect.x - pos.x), (LONG)(pcmd->ClipRect.y - pos.y), (LONG)(pcmd->ClipRect.z - pos.x), (LONG)(pcmd->ClipRect.w - pos.y) };
+ const D3D11_RECT r = { (LONG)(pcmd->ClipRect.x - clip_off.x), (LONG)(pcmd->ClipRect.y - clip_off.y), (LONG)(pcmd->ClipRect.z - clip_off.x), (LONG)(pcmd->ClipRect.w - clip_off.y) };
ctx->RSSetScissorRects(1, &r);
// Bind texture, Draw
ID3D11ShaderResourceView* texture_srv = (ID3D11ShaderResourceView*)pcmd->TextureId;
ctx->PSSetShaderResources(0, 1, &texture_srv);
- ctx->DrawIndexed(pcmd->ElemCount, idx_offset, vtx_offset);
+ ctx->DrawIndexed(pcmd->ElemCount, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset);
}
- idx_offset += pcmd->ElemCount;
}
- vtx_offset += cmd_list->VtxBuffer.Size;
+ global_idx_offset += cmd_list->IdxBuffer.Size;
+ global_vtx_offset += cmd_list->VtxBuffer.Size;
}
// Restore modified DX state
@@ -250,6 +277,7 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
for (UINT i = 0; i < old.PSInstancesCount; i++) if (old.PSInstances[i]) old.PSInstances[i]->Release();
ctx->VSSetShader(old.VS, old.VSInstances, old.VSInstancesCount); if (old.VS) old.VS->Release();
ctx->VSSetConstantBuffers(0, 1, &old.VSConstantBuffer); if (old.VSConstantBuffer) old.VSConstantBuffer->Release();
+ ctx->GSSetShader(old.GS, old.GSInstances, old.GSInstancesCount); if (old.GS) old.GS->Release();
for (UINT i = 0; i < old.VSInstancesCount; i++) if (old.VSInstances[i]) old.VSInstances[i]->Release();
ctx->IASetPrimitiveTopology(old.PrimitiveTopology);
ctx->IASetIndexBuffer(old.IndexBuffer, old.IndexBufferFormat, old.IndexBufferOffset); if (old.IndexBuffer) old.IndexBuffer->Release();
@@ -483,8 +511,9 @@ bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_co
{
// Setup back-end capabilities flags
ImGuiIO& io = ImGui::GetIO();
- io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
io.BackendRendererName = "imgui_impl_dx11";
+ io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
+ io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
// Get factory from device
IDXGIDevice* pDXGIDevice = NULL;
@@ -501,6 +530,8 @@ bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_co
}
if (pDXGIDevice) pDXGIDevice->Release();
if (pDXGIAdapter) pDXGIAdapter->Release();
+ g_pd3dDevice->AddRef();
+ g_pd3dDeviceContext->AddRef();
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
ImGui_ImplDX11_InitPlatformInterface();
@@ -513,8 +544,8 @@ void ImGui_ImplDX11_Shutdown()
ImGui_ImplDX11_ShutdownPlatformInterface();
ImGui_ImplDX11_InvalidateDeviceObjects();
if (g_pFactory) { g_pFactory->Release(); g_pFactory = NULL; }
- g_pd3dDevice = NULL;
- g_pd3dDeviceContext = NULL;
+ if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; }
+ if (g_pd3dDeviceContext) { g_pd3dDeviceContext->Release(); g_pd3dDeviceContext = NULL; }
}
void ImGui_ImplDX11_NewFrame()
@@ -543,7 +574,9 @@ static void ImGui_ImplDX11_CreateWindow(ImGuiViewport* viewport)
ImGuiViewportDataDx11* data = IM_NEW(ImGuiViewportDataDx11)();
viewport->RendererUserData = data;
- HWND hwnd = (HWND)viewport->PlatformHandle;
+ // PlatformHandleRaw should always be a HWND, whereas PlatformHandle might be a higher-level handle (e.g. GLFWWindow*, SDL_Window*).
+ // Some back-end will leave PlatformHandleRaw NULL, in which case we assume PlatformHandle will contain the HWND.
+ HWND hwnd = viewport->PlatformHandleRaw ? (HWND)viewport->PlatformHandleRaw : (HWND)viewport->PlatformHandle;
IM_ASSERT(hwnd != 0);
// Create swap chain
diff --git a/examples/imgui_impl_dx11.h b/examples/imgui_impl_dx11.h
index 665cbc73..ea02c731 100644
--- a/examples/imgui_impl_dx11.h
+++ b/examples/imgui_impl_dx11.h
@@ -4,6 +4,7 @@
// Implemented features:
// [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
// [X] Renderer: Multi-viewport support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
+// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices.
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
// If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
diff --git a/examples/imgui_impl_dx12.cpp b/examples/imgui_impl_dx12.cpp
index 0325435e..058b454e 100644
--- a/examples/imgui_impl_dx12.cpp
+++ b/examples/imgui_impl_dx12.cpp
@@ -3,7 +3,9 @@
// Implemented features:
// [X] Renderer: User texture binding. Use 'D3D12_GPU_DESCRIPTOR_HANDLE' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
-// Issues:
+// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices.
+// Missing features, issues:
+// [ ] Renderer: Missing multi-viewport support.
// [ ] 64-bit only for now! (Because sizeof(ImTextureId) == sizeof(void*)). See github.com/ocornut/imgui/pull/301
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
@@ -12,6 +14,9 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
+// 2019-05-29: DirectX12: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag.
+// 2019-04-30: DirectX12: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
+// 2019-03-29: Misc: Various minor tidying up.
// 2018-12-03: Misc: Added #pragma comment statement to automatically link with d3dcompiler.lib when using D3DCompile().
// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
// 2018-06-12: DirectX12: Moved the ID3D12GraphicsCommandList* parameter from NewFrame() to RenderDrawData().
@@ -43,14 +48,14 @@ static D3D12_GPU_DESCRIPTOR_HANDLE g_hFontSrvGpuDescHandle = {};
struct FrameResources
{
- ID3D12Resource* IB;
- ID3D12Resource* VB;
- int VertexBufferSize;
- int IndexBufferSize;
+ ID3D12Resource* IndexBuffer;
+ ID3D12Resource* VertexBuffer;
+ int IndexBufferSize;
+ int VertexBufferSize;
};
-static FrameResources* g_pFrameResources = NULL;
-static UINT g_numFramesInFlight = 0;
-static UINT g_frameIndex = UINT_MAX;
+static FrameResources* g_pFrameResources = NULL;
+static UINT g_numFramesInFlight = 0;
+static UINT g_frameIndex = UINT_MAX;
struct VERTEX_CONSTANT_BUFFER
{
@@ -61,24 +66,79 @@ struct VERTEX_CONSTANT_BUFFER
static void ImGui_ImplDX12_InitPlatformInterface();
static void ImGui_ImplDX12_ShutdownPlatformInterface();
+static void ImGui_ImplDX12_SetupRenderState(ImDrawData* draw_data, ID3D12GraphicsCommandList* ctx, FrameResources* fr)
+{
+ // Setup orthographic projection matrix into our constant buffer
+ // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right).
+ VERTEX_CONSTANT_BUFFER vertex_constant_buffer;
+ {
+ float L = draw_data->DisplayPos.x;
+ float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x;
+ float T = draw_data->DisplayPos.y;
+ float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y;
+ float mvp[4][4] =
+ {
+ { 2.0f/(R-L), 0.0f, 0.0f, 0.0f },
+ { 0.0f, 2.0f/(T-B), 0.0f, 0.0f },
+ { 0.0f, 0.0f, 0.5f, 0.0f },
+ { (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f },
+ };
+ memcpy(&vertex_constant_buffer.mvp, mvp, sizeof(mvp));
+ }
+
+ // Setup viewport
+ D3D12_VIEWPORT vp;
+ memset(&vp, 0, sizeof(D3D12_VIEWPORT));
+ vp.Width = draw_data->DisplaySize.x;
+ vp.Height = draw_data->DisplaySize.y;
+ vp.MinDepth = 0.0f;
+ vp.MaxDepth = 1.0f;
+ vp.TopLeftX = vp.TopLeftY = 0.0f;
+ ctx->RSSetViewports(1, &vp);
+
+ // Bind shader and vertex buffers
+ unsigned int stride = sizeof(ImDrawVert);
+ unsigned int offset = 0;
+ D3D12_VERTEX_BUFFER_VIEW vbv;
+ memset(&vbv, 0, sizeof(D3D12_VERTEX_BUFFER_VIEW));
+ vbv.BufferLocation = fr->VertexBuffer->GetGPUVirtualAddress() + offset;
+ vbv.SizeInBytes = fr->VertexBufferSize * stride;
+ vbv.StrideInBytes = stride;
+ ctx->IASetVertexBuffers(0, 1, &vbv);
+ D3D12_INDEX_BUFFER_VIEW ibv;
+ memset(&ibv, 0, sizeof(D3D12_INDEX_BUFFER_VIEW));
+ ibv.BufferLocation = fr->IndexBuffer->GetGPUVirtualAddress();
+ ibv.SizeInBytes = fr->IndexBufferSize * sizeof(ImDrawIdx);
+ ibv.Format = sizeof(ImDrawIdx) == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT;
+ ctx->IASetIndexBuffer(&ibv);
+ ctx->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
+ ctx->SetPipelineState(g_pPipelineState);
+ ctx->SetGraphicsRootSignature(g_pRootSignature);
+ ctx->SetGraphicsRoot32BitConstants(0, 16, &vertex_constant_buffer, 0);
+
+ // Setup blend factor
+ const float blend_factor[4] = { 0.f, 0.f, 0.f, 0.f };
+ ctx->OMSetBlendFactor(blend_factor);
+}
+
// Render function
// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandList* ctx)
{
+ // Avoid rendering when minimized
+ if (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f)
+ return;
+
// FIXME: I'm assuming that this only gets called once per frame!
// If not, we can't just re-allocate the IB or VB, we'll have to do a proper allocator.
g_frameIndex = g_frameIndex + 1;
- FrameResources* frameResources = &g_pFrameResources[g_frameIndex % g_numFramesInFlight];
- ID3D12Resource* g_pVB = frameResources->VB;
- ID3D12Resource* g_pIB = frameResources->IB;
- int g_VertexBufferSize = frameResources->VertexBufferSize;
- int g_IndexBufferSize = frameResources->IndexBufferSize;
+ FrameResources* fr = &g_pFrameResources[g_frameIndex % g_numFramesInFlight];
// Create and grow vertex/index buffers if needed
- if (!g_pVB || g_VertexBufferSize < draw_data->TotalVtxCount)
+ if (fr->VertexBuffer == NULL || fr->VertexBufferSize < draw_data->TotalVtxCount)
{
- if (g_pVB) { g_pVB->Release(); g_pVB = NULL; }
- g_VertexBufferSize = draw_data->TotalVtxCount + 5000;
+ if (fr->VertexBuffer != NULL) { fr->VertexBuffer->Release(); fr->VertexBuffer = NULL; }
+ fr->VertexBufferSize = draw_data->TotalVtxCount + 5000;
D3D12_HEAP_PROPERTIES props;
memset(&props, 0, sizeof(D3D12_HEAP_PROPERTIES));
props.Type = D3D12_HEAP_TYPE_UPLOAD;
@@ -87,7 +147,7 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL
D3D12_RESOURCE_DESC desc;
memset(&desc, 0, sizeof(D3D12_RESOURCE_DESC));
desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
- desc.Width = g_VertexBufferSize * sizeof(ImDrawVert);
+ desc.Width = fr->VertexBufferSize * sizeof(ImDrawVert);
desc.Height = 1;
desc.DepthOrArraySize = 1;
desc.MipLevels = 1;
@@ -95,15 +155,13 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL
desc.SampleDesc.Count = 1;
desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
desc.Flags = D3D12_RESOURCE_FLAG_NONE;
- if (g_pd3dDevice->CreateCommittedResource(&props, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_GENERIC_READ, NULL, IID_PPV_ARGS(&g_pVB)) < 0)
+ if (g_pd3dDevice->CreateCommittedResource(&props, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_GENERIC_READ, NULL, IID_PPV_ARGS(&fr->VertexBuffer)) < 0)
return;
- frameResources->VB = g_pVB;
- frameResources->VertexBufferSize = g_VertexBufferSize;
}
- if (!g_pIB || g_IndexBufferSize < draw_data->TotalIdxCount)
+ if (fr->IndexBuffer == NULL || fr->IndexBufferSize < draw_data->TotalIdxCount)
{
- if (g_pIB) { g_pIB->Release(); g_pIB = NULL; }
- g_IndexBufferSize = draw_data->TotalIdxCount + 10000;
+ if (fr->IndexBuffer != NULL) { fr->IndexBuffer->Release(); fr->IndexBuffer = NULL; }
+ fr->IndexBufferSize = draw_data->TotalIdxCount + 10000;
D3D12_HEAP_PROPERTIES props;
memset(&props, 0, sizeof(D3D12_HEAP_PROPERTIES));
props.Type = D3D12_HEAP_TYPE_UPLOAD;
@@ -112,7 +170,7 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL
D3D12_RESOURCE_DESC desc;
memset(&desc, 0, sizeof(D3D12_RESOURCE_DESC));
desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
- desc.Width = g_IndexBufferSize * sizeof(ImDrawIdx);
+ desc.Width = fr->IndexBufferSize * sizeof(ImDrawIdx);
desc.Height = 1;
desc.DepthOrArraySize = 1;
desc.MipLevels = 1;
@@ -120,19 +178,17 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL
desc.SampleDesc.Count = 1;
desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
desc.Flags = D3D12_RESOURCE_FLAG_NONE;
- if (g_pd3dDevice->CreateCommittedResource(&props, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_GENERIC_READ, NULL, IID_PPV_ARGS(&g_pIB)) < 0)
+ if (g_pd3dDevice->CreateCommittedResource(&props, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_GENERIC_READ, NULL, IID_PPV_ARGS(&fr->IndexBuffer)) < 0)
return;
- frameResources->IB = g_pIB;
- frameResources->IndexBufferSize = g_IndexBufferSize;
}
- // Copy and convert all vertices into a single contiguous buffer
+ // Upload vertex/index data into a single contiguous GPU buffer
void* vtx_resource, *idx_resource;
D3D12_RANGE range;
memset(&range, 0, sizeof(D3D12_RANGE));
- if (g_pVB->Map(0, &range, &vtx_resource) != S_OK)
+ if (fr->VertexBuffer->Map(0, &range, &vtx_resource) != S_OK)
return;
- if (g_pIB->Map(0, &range, &idx_resource) != S_OK)
+ if (fr->IndexBuffer->Map(0, &range, &idx_resource) != S_OK)
return;
ImDrawVert* vtx_dst = (ImDrawVert*)vtx_resource;
ImDrawIdx* idx_dst = (ImDrawIdx*)idx_resource;
@@ -144,86 +200,43 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL
vtx_dst += cmd_list->VtxBuffer.Size;
idx_dst += cmd_list->IdxBuffer.Size;
}
- g_pVB->Unmap(0, &range);
- g_pIB->Unmap(0, &range);
-
- // Setup orthographic projection matrix into our constant buffer
- // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayMin is (0,0) for single viewport apps.
- VERTEX_CONSTANT_BUFFER vertex_constant_buffer;
- {
- VERTEX_CONSTANT_BUFFER* constant_buffer = &vertex_constant_buffer;
- float L = draw_data->DisplayPos.x;
- float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x;
- float T = draw_data->DisplayPos.y;
- float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y;
- float mvp[4][4] =
- {
- { 2.0f/(R-L), 0.0f, 0.0f, 0.0f },
- { 0.0f, 2.0f/(T-B), 0.0f, 0.0f },
- { 0.0f, 0.0f, 0.5f, 0.0f },
- { (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f },
- };
- memcpy(&constant_buffer->mvp, mvp, sizeof(mvp));
- }
-
- // Setup viewport
- D3D12_VIEWPORT vp;
- memset(&vp, 0, sizeof(D3D12_VIEWPORT));
- vp.Width = draw_data->DisplaySize.x;
- vp.Height = draw_data->DisplaySize.y;
- vp.MinDepth = 0.0f;
- vp.MaxDepth = 1.0f;
- vp.TopLeftX = vp.TopLeftY = 0.0f;
- ctx->RSSetViewports(1, &vp);
-
- // Bind shader and vertex buffers
- unsigned int stride = sizeof(ImDrawVert);
- unsigned int offset = 0;
- D3D12_VERTEX_BUFFER_VIEW vbv;
- memset(&vbv, 0, sizeof(D3D12_VERTEX_BUFFER_VIEW));
- vbv.BufferLocation = g_pVB->GetGPUVirtualAddress() + offset;
- vbv.SizeInBytes = g_VertexBufferSize * stride;
- vbv.StrideInBytes = stride;
- ctx->IASetVertexBuffers(0, 1, &vbv);
- D3D12_INDEX_BUFFER_VIEW ibv;
- memset(&ibv, 0, sizeof(D3D12_INDEX_BUFFER_VIEW));
- ibv.BufferLocation = g_pIB->GetGPUVirtualAddress();
- ibv.SizeInBytes = g_IndexBufferSize * sizeof(ImDrawIdx);
- ibv.Format = sizeof(ImDrawIdx) == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT;
- ctx->IASetIndexBuffer(&ibv);
- ctx->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
- ctx->SetPipelineState(g_pPipelineState);
- ctx->SetGraphicsRootSignature(g_pRootSignature);
- ctx->SetGraphicsRoot32BitConstants(0, 16, &vertex_constant_buffer, 0);
+ fr->VertexBuffer->Unmap(0, &range);
+ fr->IndexBuffer->Unmap(0, &range);
- // Setup render state
- const float blend_factor[4] = { 0.f, 0.f, 0.f, 0.f };
- ctx->OMSetBlendFactor(blend_factor);
+ // Setup desired DX state
+ ImGui_ImplDX12_SetupRenderState(draw_data, ctx, fr);
// Render command lists
- int vtx_offset = 0;
- int idx_offset = 0;
- ImVec2 pos = draw_data->DisplayPos;
+ // (Because we merged all buffers into a single one, we maintain our own offset into them)
+ int global_vtx_offset = 0;
+ int global_idx_offset = 0;
+ ImVec2 clip_off = draw_data->DisplayPos;
for (int n = 0; n < draw_data->CmdListsCount; n++)
{
const ImDrawList* cmd_list = draw_data->CmdLists[n];
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
{
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
- if (pcmd->UserCallback)
+ if (pcmd->UserCallback != NULL)
{
- pcmd->UserCallback(cmd_list, pcmd);
+ // User callback, registered via ImDrawList::AddCallback()
+ // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
+ if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
+ ImGui_ImplDX12_SetupRenderState(draw_data, ctx, fr);
+ else
+ pcmd->UserCallback(cmd_list, pcmd);
}
else
{
- const D3D12_RECT r = { (LONG)(pcmd->ClipRect.x - pos.x), (LONG)(pcmd->ClipRect.y - pos.y), (LONG)(pcmd->ClipRect.z - pos.x), (LONG)(pcmd->ClipRect.w - pos.y) };
+ // Apply Scissor, Bind texture, Draw
+ const D3D12_RECT r = { (LONG)(pcmd->ClipRect.x - clip_off.x), (LONG)(pcmd->ClipRect.y - clip_off.y), (LONG)(pcmd->ClipRect.z - clip_off.x), (LONG)(pcmd->ClipRect.w - clip_off.y) };
ctx->SetGraphicsRootDescriptorTable(1, *(D3D12_GPU_DESCRIPTOR_HANDLE*)&pcmd->TextureId);
ctx->RSSetScissorRects(1, &r);
- ctx->DrawIndexedInstanced(pcmd->ElemCount, 1, idx_offset, vtx_offset, 0);
+ ctx->DrawIndexedInstanced(pcmd->ElemCount, 1, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset, 0);
}
- idx_offset += pcmd->ElemCount;
}
- vtx_offset += cmd_list->VtxBuffer.Size;
+ global_idx_offset += cmd_list->IdxBuffer.Size;
+ global_vtx_offset += cmd_list->VtxBuffer.Size;
}
}
@@ -494,9 +507,9 @@ bool ImGui_ImplDX12_CreateDeviceObjects()
// Create the input layout
static D3D12_INPUT_ELEMENT_DESC local_layout[] = {
- { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((ImDrawVert*)0)->pos), D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
- { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((ImDrawVert*)0)->uv), D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
- { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (size_t)(&((ImDrawVert*)0)->col), D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
+ { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (UINT)IM_OFFSETOF(ImDrawVert, pos), D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
+ { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (UINT)IM_OFFSETOF(ImDrawVert, uv), D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
+ { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (UINT)IM_OFFSETOF(ImDrawVert, col), D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
};
psoDesc.InputLayout = { local_layout, 3 };
}
@@ -580,15 +593,17 @@ void ImGui_ImplDX12_InvalidateDeviceObjects()
if (!g_pd3dDevice)
return;
+ ImGuiIO& io = ImGui::GetIO();
if (g_pVertexShaderBlob) { g_pVertexShaderBlob->Release(); g_pVertexShaderBlob = NULL; }
if (g_pPixelShaderBlob) { g_pPixelShaderBlob->Release(); g_pPixelShaderBlob = NULL; }
if (g_pRootSignature) { g_pRootSignature->Release(); g_pRootSignature = NULL; }
if (g_pPipelineState) { g_pPipelineState->Release(); g_pPipelineState = NULL; }
- if (g_pFontTextureResource) { g_pFontTextureResource->Release(); g_pFontTextureResource = NULL; ImGui::GetIO().Fonts->TexID = NULL; } // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well.
+ if (g_pFontTextureResource) { g_pFontTextureResource->Release(); g_pFontTextureResource = NULL; io.Fonts->TexID = NULL; } // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well.
for (UINT i = 0; i < g_numFramesInFlight; i++)
{
- if (g_pFrameResources[i].IB) { g_pFrameResources[i].IB->Release(); g_pFrameResources[i].IB = NULL; }
- if (g_pFrameResources[i].VB) { g_pFrameResources[i].VB->Release(); g_pFrameResources[i].VB = NULL; }
+ FrameResources* fr = &g_pFrameResources[i];
+ if (fr->IndexBuffer) { fr->IndexBuffer->Release(); fr->IndexBuffer = NULL; }
+ if (fr->VertexBuffer) { fr->VertexBuffer->Release(); fr->VertexBuffer = NULL; }
}
}
@@ -597,8 +612,9 @@ bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FO
{
// Setup back-end capabilities flags
ImGuiIO& io = ImGui::GetIO();
- io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional) // FIXME-VIEWPORT: Actually unfinished..
io.BackendRendererName = "imgui_impl_dx12";
+ io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
+ io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional) // FIXME-VIEWPORT: Actually unfinished..
g_pd3dDevice = device;
g_RTVFormat = rtv_format;
@@ -611,10 +627,11 @@ bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FO
// Create buffers with a default size (they will later be grown as needed)
for (int i = 0; i < num_frames_in_flight; i++)
{
- g_pFrameResources[i].IB = NULL;
- g_pFrameResources[i].VB = NULL;
- g_pFrameResources[i].VertexBufferSize = 5000;
- g_pFrameResources[i].IndexBufferSize = 10000;
+ FrameResources* fr = &g_pFrameResources[i];
+ fr->IndexBuffer = NULL;
+ fr->VertexBuffer = NULL;
+ fr->IndexBufferSize = 10000;
+ fr->VertexBufferSize = 5000;
}
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
@@ -628,10 +645,10 @@ void ImGui_ImplDX12_Shutdown()
ImGui_ImplDX12_ShutdownPlatformInterface();
ImGui_ImplDX12_InvalidateDeviceObjects();
delete[] g_pFrameResources;
+ g_pFrameResources = NULL;
g_pd3dDevice = NULL;
g_hFontSrvCpuDescHandle.ptr = 0;
g_hFontSrvGpuDescHandle.ptr = 0;
- g_pFrameResources = NULL;
g_numFramesInFlight = 0;
g_frameIndex = UINT_MAX;
}
@@ -664,7 +681,9 @@ static void ImGui_ImplDX12_CreateWindow(ImGuiViewport* viewport)
/*
// FIXME-PLATFORM
- HWND hwnd = (HWND)viewport->PlatformHandle;
+ // PlatformHandleRaw should always be a HWND, whereas PlatformHandle might be a higher-level handle (e.g. GLFWWindow*, SDL_Window*).
+ // Some back-ends will leave PlatformHandleRaw NULL, in which case we assume PlatformHandle will contain the HWND.
+ HWND hwnd = viewport->PlatformHandleRaw ? (HWND)viewport->PlatformHandleRaw : (HWND)viewport->PlatformHandle;
IM_ASSERT(hwnd != 0);
// Create swap chain
diff --git a/examples/imgui_impl_dx12.h b/examples/imgui_impl_dx12.h
index e5b9dc4e..cf34c144 100644
--- a/examples/imgui_impl_dx12.h
+++ b/examples/imgui_impl_dx12.h
@@ -3,7 +3,9 @@
// Implemented features:
// [X] Renderer: User texture binding. Use 'D3D12_GPU_DESCRIPTOR_HANDLE' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
-// Issues:
+// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices.
+// Missing features, issues:
+// [ ] Renderer: Missing multi-viewport support.
// [ ] 64-bit only for now! (Because sizeof(ImTextureId) == sizeof(void*)). See github.com/ocornut/imgui/pull/301
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
diff --git a/examples/imgui_impl_dx9.cpp b/examples/imgui_impl_dx9.cpp
index 3653ec25..2c22885e 100644
--- a/examples/imgui_impl_dx9.cpp
+++ b/examples/imgui_impl_dx9.cpp
@@ -3,6 +3,8 @@
// Implemented features:
// [X] Renderer: User texture binding. Use 'LPDIRECT3DTEXTURE9' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
+// [X] Renderer: Multi-viewport support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
+// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices.
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
// If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
@@ -10,6 +12,10 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
+// 2019-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
+// 2019-05-29: DirectX9: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag.
+// 2019-04-30: DirectX9: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
+// 2019-03-29: Misc: Fixed erroneous assert in ImGui_ImplDX9_InvalidateDeviceObjects().
// 2019-01-16: Misc: Disabled fog before drawing UI's. Fixes issue #2288.
// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
// 2018-06-08: Misc: Extracted imgui_impl_dx9.cpp/.h away from the old combined DX9+Win32 example.
@@ -41,6 +47,68 @@ struct CUSTOMVERTEX
};
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1)
+// Forward Declarations
+static void ImGui_ImplDX9_InitPlatformInterface();
+static void ImGui_ImplDX9_ShutdownPlatformInterface();
+static void ImGui_ImplDX9_CreateDeviceObjectsForPlatformWindows();
+static void ImGui_ImplDX9_InvalidateDeviceObjectsForPlatformWindows();
+
+static void ImGui_ImplDX9_SetupRenderState(ImDrawData* draw_data)
+{
+ // Setup viewport
+ D3DVIEWPORT9 vp;
+ vp.X = vp.Y = 0;
+ vp.Width = (DWORD)draw_data->DisplaySize.x;
+ vp.Height = (DWORD)draw_data->DisplaySize.y;
+ vp.MinZ = 0.0f;
+ vp.MaxZ = 1.0f;
+ g_pd3dDevice->SetViewport(&vp);
+
+ // Setup render state: fixed-pipeline, alpha-blending, no face culling, no depth testing, shade mode (for gradient)
+ g_pd3dDevice->SetPixelShader(NULL);
+ g_pd3dDevice->SetVertexShader(NULL);
+ g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
+ g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, false);
+ g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, false);
+ g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
+ g_pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, false);
+ g_pd3dDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
+ g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
+ g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
+ g_pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, true);
+ g_pd3dDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);
+ g_pd3dDevice->SetRenderState(D3DRS_FOGENABLE, false);
+ g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
+ g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
+ g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
+ g_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
+ g_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
+ g_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
+ g_pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
+ g_pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
+
+ // Setup orthographic projection matrix
+ // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
+ // Being agnostic of whether or can be used, we aren't relying on D3DXMatrixIdentity()/D3DXMatrixOrthoOffCenterLH() or DirectX::XMMatrixIdentity()/DirectX::XMMatrixOrthographicOffCenterLH()
+ {
+ float L = draw_data->DisplayPos.x + 0.5f;
+ float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x + 0.5f;
+ float T = draw_data->DisplayPos.y + 0.5f;
+ float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y + 0.5f;
+ D3DMATRIX mat_identity = { { { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f } } };
+ D3DMATRIX mat_projection =
+ { { {
+ 2.0f/(R-L), 0.0f, 0.0f, 0.0f,
+ 0.0f, 2.0f/(T-B), 0.0f, 0.0f,
+ 0.0f, 0.0f, 0.5f, 0.0f,
+ (L+R)/(L-R), (T+B)/(B-T), 0.5f, 1.0f
+ } } };
+ g_pd3dDevice->SetTransform(D3DTS_WORLD, &mat_identity);
+ g_pd3dDevice->SetTransform(D3DTS_VIEW, &mat_identity);
+ g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &mat_projection);
+ }
+}
+
// Render function.
// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data)
@@ -110,84 +178,40 @@ void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data)
g_pd3dDevice->SetIndices(g_pIB);
g_pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
- // Setup viewport
- D3DVIEWPORT9 vp;
- vp.X = vp.Y = 0;
- vp.Width = (DWORD)draw_data->DisplaySize.x;
- vp.Height = (DWORD)draw_data->DisplaySize.y;
- vp.MinZ = 0.0f;
- vp.MaxZ = 1.0f;
- g_pd3dDevice->SetViewport(&vp);
-
- // Setup render state: fixed-pipeline, alpha-blending, no face culling, no depth testing, shade mode (for gradient)
- g_pd3dDevice->SetPixelShader(NULL);
- g_pd3dDevice->SetVertexShader(NULL);
- g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
- g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, false);
- g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, false);
- g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
- g_pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, false);
- g_pd3dDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
- g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
- g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
- g_pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, true);
- g_pd3dDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);
- g_pd3dDevice->SetRenderState(D3DRS_FOGENABLE, false);
- g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
- g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
- g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
- g_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
- g_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
- g_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
- g_pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
- g_pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
-
- // Setup orthographic projection matrix
- // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayMin is (0,0) for single viewport apps.
- // Being agnostic of whether or can be used, we aren't relying on D3DXMatrixIdentity()/D3DXMatrixOrthoOffCenterLH() or DirectX::XMMatrixIdentity()/DirectX::XMMatrixOrthographicOffCenterLH()
- {
- float L = draw_data->DisplayPos.x + 0.5f;
- float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x + 0.5f;
- float T = draw_data->DisplayPos.y + 0.5f;
- float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y + 0.5f;
- D3DMATRIX mat_identity = { { { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f } } };
- D3DMATRIX mat_projection =
- { { {
- 2.0f/(R-L), 0.0f, 0.0f, 0.0f,
- 0.0f, 2.0f/(T-B), 0.0f, 0.0f,
- 0.0f, 0.0f, 0.5f, 0.0f,
- (L+R)/(L-R), (T+B)/(B-T), 0.5f, 1.0f
- } } };
- g_pd3dDevice->SetTransform(D3DTS_WORLD, &mat_identity);
- g_pd3dDevice->SetTransform(D3DTS_VIEW, &mat_identity);
- g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &mat_projection);
- }
+ // Setup desired DX state
+ ImGui_ImplDX9_SetupRenderState(draw_data);
// Render command lists
- int vtx_offset = 0;
- int idx_offset = 0;
- ImVec2 pos = draw_data->DisplayPos;
+ // (Because we merged all buffers into a single one, we maintain our own offset into them)
+ int global_vtx_offset = 0;
+ int global_idx_offset = 0;
+ ImVec2 clip_off = draw_data->DisplayPos;
for (int n = 0; n < draw_data->CmdListsCount; n++)
{
const ImDrawList* cmd_list = draw_data->CmdLists[n];
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
{
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
- if (pcmd->UserCallback)
+ if (pcmd->UserCallback != NULL)
{
- pcmd->UserCallback(cmd_list, pcmd);
+ // User callback, registered via ImDrawList::AddCallback()
+ // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
+ if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
+ ImGui_ImplDX9_SetupRenderState(draw_data);
+ else
+ pcmd->UserCallback(cmd_list, pcmd);
}
else
{
- const RECT r = { (LONG)(pcmd->ClipRect.x - pos.x), (LONG)(pcmd->ClipRect.y - pos.y), (LONG)(pcmd->ClipRect.z - pos.x), (LONG)(pcmd->ClipRect.w - pos.y) };
+ const RECT r = { (LONG)(pcmd->ClipRect.x - clip_off.x), (LONG)(pcmd->ClipRect.y - clip_off.y), (LONG)(pcmd->ClipRect.z - clip_off.x), (LONG)(pcmd->ClipRect.w - clip_off.y) };
const LPDIRECT3DTEXTURE9 texture = (LPDIRECT3DTEXTURE9)pcmd->TextureId;
g_pd3dDevice->SetTexture(0, texture);
g_pd3dDevice->SetScissorRect(&r);
- g_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, vtx_offset, 0, (UINT)cmd_list->VtxBuffer.Size, idx_offset, pcmd->ElemCount/3);
+ g_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, pcmd->VtxOffset + global_vtx_offset, 0, (UINT)cmd_list->VtxBuffer.Size, pcmd->IdxOffset + global_idx_offset, pcmd->ElemCount/3);
}
- idx_offset += pcmd->ElemCount;
}
- vtx_offset += cmd_list->VtxBuffer.Size;
+ global_idx_offset += cmd_list->IdxBuffer.Size;
+ global_vtx_offset += cmd_list->VtxBuffer.Size;
}
// Restore the DX9 transform
@@ -202,17 +226,26 @@ void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data)
bool ImGui_ImplDX9_Init(IDirect3DDevice9* device)
{
+ // Setup back-end capabilities flags
ImGuiIO& io = ImGui::GetIO();
io.BackendRendererName = "imgui_impl_dx9";
+ io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
+ io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
g_pd3dDevice = device;
+ g_pd3dDevice->AddRef();
+
+ if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
+ ImGui_ImplDX9_InitPlatformInterface();
+
return true;
}
void ImGui_ImplDX9_Shutdown()
{
+ ImGui_ImplDX9_ShutdownPlatformInterface();
ImGui_ImplDX9_InvalidateDeviceObjects();
- g_pd3dDevice = NULL;
+ if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; }
}
static bool ImGui_ImplDX9_CreateFontsTexture()
@@ -246,6 +279,7 @@ bool ImGui_ImplDX9_CreateDeviceObjects()
return false;
if (!ImGui_ImplDX9_CreateFontsTexture())
return false;
+ ImGui_ImplDX9_CreateDeviceObjectsForPlatformWindows();
return true;
}
@@ -253,28 +287,151 @@ void ImGui_ImplDX9_InvalidateDeviceObjects()
{
if (!g_pd3dDevice)
return;
- if (g_pVB)
+ if (g_pVB) { g_pVB->Release(); g_pVB = NULL; }
+ if (g_pIB) { g_pIB->Release(); g_pIB = NULL; }
+ if (g_FontTexture) { g_FontTexture->Release(); g_FontTexture = NULL; ImGui::GetIO().Fonts->TexID = NULL; } // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well.
+ ImGui_ImplDX9_InvalidateDeviceObjectsForPlatformWindows();
+}
+
+void ImGui_ImplDX9_NewFrame()
+{
+ if (!g_FontTexture)
+ ImGui_ImplDX9_CreateDeviceObjects();
+}
+
+//--------------------------------------------------------------------------------------------------------
+// MULTI-VIEWPORT / PLATFORM INTERFACE SUPPORT
+// This is an _advanced_ and _optional_ feature, allowing the back-end to create and handle multiple viewports simultaneously.
+// If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first..
+//--------------------------------------------------------------------------------------------------------
+
+struct ImGuiViewportDataDx9
+{
+ IDirect3DSwapChain9* SwapChain;
+ D3DPRESENT_PARAMETERS d3dpp;
+
+ ImGuiViewportDataDx9() { SwapChain = NULL; ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS)); }
+ ~ImGuiViewportDataDx9() { IM_ASSERT(SwapChain == NULL); }
+};
+
+static void ImGui_ImplDX9_CreateWindow(ImGuiViewport* viewport)
+{
+ ImGuiViewportDataDx9* data = IM_NEW(ImGuiViewportDataDx9)();
+ viewport->RendererUserData = data;
+
+ // PlatformHandleRaw should always be a HWND, whereas PlatformHandle might be a higher-level handle (e.g. GLFWWindow*, SDL_Window*).
+ // Some back-ends will leave PlatformHandleRaw NULL, in which case we assume PlatformHandle will contain the HWND.
+ HWND hwnd = viewport->PlatformHandleRaw ? (HWND)viewport->PlatformHandleRaw : (HWND)viewport->PlatformHandle;
+ IM_ASSERT(hwnd != 0);
+
+ ZeroMemory(&data->d3dpp, sizeof(D3DPRESENT_PARAMETERS));
+ data->d3dpp.Windowed = TRUE;
+ data->d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
+ data->d3dpp.BackBufferWidth = (UINT)viewport->Size.x;
+ data->d3dpp.BackBufferHeight = (UINT)viewport->Size.y;
+ data->d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
+ data->d3dpp.hDeviceWindow = hwnd;
+ data->d3dpp.EnableAutoDepthStencil = FALSE;
+ data->d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
+ data->d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; // Present without vsync
+
+ HRESULT hr = g_pd3dDevice->CreateAdditionalSwapChain(&data->d3dpp, &data->SwapChain); IM_UNUSED(hr);
+ IM_ASSERT(hr == D3D_OK);
+ IM_ASSERT(data->SwapChain != NULL);
+}
+
+static void ImGui_ImplDX9_DestroyWindow(ImGuiViewport* viewport)
+{
+ // The main viewport (owned by the application) will always have RendererUserData == NULL since we didn't create the data for it.
+ if (ImGuiViewportDataDx9* data = (ImGuiViewportDataDx9*)viewport->RendererUserData)
{
- g_pVB->Release();
- g_pVB = NULL;
+ if (data->SwapChain)
+ data->SwapChain->Release();
+ data->SwapChain = NULL;
+ ZeroMemory(&data->d3dpp, sizeof(D3DPRESENT_PARAMETERS));
+ IM_DELETE(data);
}
- if (g_pIB)
+ viewport->RendererUserData = NULL;
+}
+
+static void ImGui_ImplDX9_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
+{
+ ImGuiViewportDataDx9* data = (ImGuiViewportDataDx9*)viewport->RendererUserData;
+ if (data->SwapChain)
{
- g_pIB->Release();
- g_pIB = NULL;
+ data->SwapChain->Release();
+ data->SwapChain = NULL;
+ data->d3dpp.BackBufferWidth = (UINT)size.x;
+ data->d3dpp.BackBufferHeight = (UINT)size.y;
+ HRESULT hr = g_pd3dDevice->CreateAdditionalSwapChain(&data->d3dpp, &data->SwapChain); IM_UNUSED(hr);
+ IM_ASSERT(hr == D3D_OK);
}
+}
- // At this point note that we set ImGui::GetIO().Fonts->TexID to be == g_FontTexture, so clear both.
- ImGuiIO& io = ImGui::GetIO();
- IM_ASSERT(g_FontTexture == io.Fonts->TexID);
- if (g_FontTexture)
- g_FontTexture->Release();
- g_FontTexture = NULL;
- io.Fonts->TexID = NULL;
+static void ImGui_ImplDX9_RenderWindow(ImGuiViewport* viewport, void*)
+{
+ ImGuiViewportDataDx9* data = (ImGuiViewportDataDx9*)viewport->RendererUserData;
+ ImVec4 clear_color = ImVec4(0.0f, 0.0f, 0.0f, 1.0f);
+
+ LPDIRECT3DSURFACE9 render_target = NULL;
+ LPDIRECT3DSURFACE9 last_render_target = NULL;
+ LPDIRECT3DSURFACE9 last_depth_stencil = NULL;
+ data->SwapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &render_target);
+ g_pd3dDevice->GetRenderTarget(0, &last_render_target);
+ g_pd3dDevice->GetDepthStencilSurface(&last_depth_stencil);
+ g_pd3dDevice->SetRenderTarget(0, render_target);
+ g_pd3dDevice->SetDepthStencilSurface(NULL);
+
+ if (!(viewport->Flags & ImGuiViewportFlags_NoRendererClear))
+ {
+ D3DCOLOR clear_col_dx = D3DCOLOR_RGBA((int)(clear_color.x*255.0f), (int)(clear_color.y*255.0f), (int)(clear_color.z*255.0f), (int)(clear_color.w*255.0f));
+ g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, clear_col_dx, 1.0f, 0);
+ }
+
+ ImGui_ImplDX9_RenderDrawData(viewport->DrawData);
+
+ // Restore render target
+ g_pd3dDevice->SetRenderTarget(0, last_render_target);
+ g_pd3dDevice->SetDepthStencilSurface(last_depth_stencil);
+ render_target->Release();
+ last_render_target->Release();
+ if (last_depth_stencil) last_depth_stencil->Release();
}
-void ImGui_ImplDX9_NewFrame()
+static void ImGui_ImplDX9_SwapBuffers(ImGuiViewport* viewport, void*)
{
- if (!g_FontTexture)
- ImGui_ImplDX9_CreateDeviceObjects();
+ ImGuiViewportDataDx9* data = (ImGuiViewportDataDx9*)viewport->RendererUserData;
+ HRESULT hr = data->SwapChain->Present(NULL, NULL, data->d3dpp.hDeviceWindow, NULL, NULL);
+ IM_ASSERT(hr == D3D_OK);
+}
+
+static void ImGui_ImplDX9_InitPlatformInterface()
+{
+ ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
+ platform_io.Renderer_CreateWindow = ImGui_ImplDX9_CreateWindow;
+ platform_io.Renderer_DestroyWindow = ImGui_ImplDX9_DestroyWindow;
+ platform_io.Renderer_SetWindowSize = ImGui_ImplDX9_SetWindowSize;
+ platform_io.Renderer_RenderWindow = ImGui_ImplDX9_RenderWindow;
+ platform_io.Renderer_SwapBuffers = ImGui_ImplDX9_SwapBuffers;
+}
+
+static void ImGui_ImplDX9_ShutdownPlatformInterface()
+{
+ ImGui::DestroyPlatformWindows();
+}
+
+static void ImGui_ImplDX9_CreateDeviceObjectsForPlatformWindows()
+{
+ ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
+ for (int i = 1; i < platform_io.Viewports.Size; i++)
+ if (!platform_io.Viewports[i]->RendererUserData)
+ ImGui_ImplDX9_CreateWindow(platform_io.Viewports[i]);
+}
+
+static void ImGui_ImplDX9_InvalidateDeviceObjectsForPlatformWindows()
+{
+ ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
+ for (int i = 1; i < platform_io.Viewports.Size; i++)
+ if (platform_io.Viewports[i]->RendererUserData)
+ ImGui_ImplDX9_DestroyWindow(platform_io.Viewports[i]);
}
diff --git a/examples/imgui_impl_dx9.h b/examples/imgui_impl_dx9.h
index 95902f74..08dc3bbe 100644
--- a/examples/imgui_impl_dx9.h
+++ b/examples/imgui_impl_dx9.h
@@ -3,6 +3,8 @@
// Implemented features:
// [X] Renderer: User texture binding. Use 'LPDIRECT3DTEXTURE9' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
+// [X] Renderer: Multi-viewport support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
+// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices.
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
// If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
@@ -18,5 +20,5 @@ IMGUI_IMPL_API void ImGui_ImplDX9_NewFrame();
IMGUI_IMPL_API void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data);
// Use if you want to reset your rendering device without losing ImGui state.
-IMGUI_IMPL_API void ImGui_ImplDX9_InvalidateDeviceObjects();
IMGUI_IMPL_API bool ImGui_ImplDX9_CreateDeviceObjects();
+IMGUI_IMPL_API void ImGui_ImplDX9_InvalidateDeviceObjects();
diff --git a/examples/imgui_impl_freeglut.h b/examples/imgui_impl_freeglut.h
deleted file mode 100644
index 909f0725..00000000
--- a/examples/imgui_impl_freeglut.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// dear imgui: Platform Binding for FreeGLUT
-// This needs to be used along with a Renderer (e.g. OpenGL2)
-
-// Issues:
-// [ ] Platform: GLUT is unable to distinguish e.g. Backspace from CTRL+H or TAB from CTRL+I
-// [ ] Platform: Missing gamepad support.
-
-// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
-// If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
-// https://github.com/ocornut/imgui
-
-#pragma once
-
-IMGUI_IMPL_API bool ImGui_ImplFreeGLUT_Init();
-IMGUI_IMPL_API void ImGui_ImplFreeGLUT_InstallFuncs();
-IMGUI_IMPL_API void ImGui_ImplFreeGLUT_Shutdown();
-IMGUI_IMPL_API void ImGui_ImplFreeGLUT_NewFrame();
-
-// You can call ImGui_ImplFreeGLUT_InstallFuncs() to get all those functions installed automatically,
-// or call them yourself from your own GLUT handlers. We are using the same weird names as GLUT for consistency..
-//---------------------------------------- GLUT name --------------------------------------------- Decent Name ---------
-IMGUI_IMPL_API void ImGui_ImplFreeGLUT_ReshapeFunc(int w, int h); // ~ ResizeFunc
-IMGUI_IMPL_API void ImGui_ImplFreeGLUT_MotionFunc(int x, int y); // ~ MouseMoveFunc
-IMGUI_IMPL_API void ImGui_ImplFreeGLUT_MouseFunc(int button, int state, int x, int y); // ~ MouseButtonFunc
-IMGUI_IMPL_API void ImGui_ImplFreeGLUT_MouseWheelFunc(int button, int dir, int x, int y); // ~ MouseWheelFunc
-IMGUI_IMPL_API void ImGui_ImplFreeGLUT_KeyboardFunc(unsigned char c, int x, int y); // ~ CharPressedFunc
-IMGUI_IMPL_API void ImGui_ImplFreeGLUT_KeyboardUpFunc(unsigned char c, int x, int y); // ~ CharReleasedFunc
-IMGUI_IMPL_API void ImGui_ImplFreeGLUT_SpecialFunc(int key, int x, int y); // ~ KeyPressedFunc
-IMGUI_IMPL_API void ImGui_ImplFreeGLUT_SpecialUpFunc(int key, int x, int y); // ~ KeyReleasedFunc
diff --git a/examples/imgui_impl_glfw.cpp b/examples/imgui_impl_glfw.cpp
index 07df5cc5..166f06a1 100644
--- a/examples/imgui_impl_glfw.cpp
+++ b/examples/imgui_impl_glfw.cpp
@@ -1,7 +1,7 @@
// dear imgui: Platform Binding for GLFW
// This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan..)
// (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
-// (Requires: GLFW 3.1+)
+// (Requires: GLFW 3.1+. Prefer GLFW 3.3+ for full feature support.)
// Implemented features:
// [X] Platform: Clipboard support.
@@ -16,7 +16,10 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
-// 2018-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
+// 2019-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
+// 2019-07-21: Inputs: Added mapping for ImGuiKey_KeyPadEnter.
+// 2019-05-11: Inputs: Don't filter value from character callback before calling AddInputCharacter().
+// 2019-03-12: Misc: Preserve DisplayFramebufferScale when main window is minimized.
// 2018-11-30: Misc: Setting up io.BackendPlatformName so it can be displayed in the About Window.
// 2018-11-07: Inputs: When installing our GLFW callbacks, we save user's previously installed ones - if any - and chain call them.
// 2018-08-01: Inputs: Workaround for Emscripten which doesn't seem to handle focus related calls.
@@ -43,12 +46,14 @@
#define GLFW_EXPOSE_NATIVE_WIN32
#include // for glfwGetWin32Window
#endif
-#define GLFW_HAS_WINDOW_TOPMOST (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3200) // 3.2+ GLFW_FLOATING
-#define GLFW_HAS_WINDOW_HOVERED (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ GLFW_HOVERED
-#define GLFW_HAS_WINDOW_ALPHA (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ glfwSetWindowOpacity
-#define GLFW_HAS_PER_MONITOR_DPI (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ glfwGetMonitorContentScale
-#define GLFW_HAS_VULKAN (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3200) // 3.2+ glfwCreateWindowSurface
-#define GLFW_HAS_FOCUS_WINDOW (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3200) // 3.2+ glfwFocusWindow
+#define GLFW_HAS_WINDOW_TOPMOST (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3200) // 3.2+ GLFW_FLOATING
+#define GLFW_HAS_WINDOW_HOVERED (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ GLFW_HOVERED
+#define GLFW_HAS_WINDOW_ALPHA (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ glfwSetWindowOpacity
+#define GLFW_HAS_PER_MONITOR_DPI (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ glfwGetMonitorContentScale
+#define GLFW_HAS_VULKAN (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3200) // 3.2+ glfwCreateWindowSurface
+#define GLFW_HAS_FOCUS_WINDOW (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3200) // 3.2+ glfwFocusWindow
+#define GLFW_HAS_FOCUS_ON_SHOW (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ GLFW_FOCUS_ON_SHOW
+#define GLFW_HAS_MONITOR_WORK_AREA (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ glfwGetMonitorWorkarea
// Data
enum GlfwClientApi
@@ -128,8 +133,7 @@ void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c)
g_PrevUserCallbackChar(window, c);
ImGuiIO& io = ImGui::GetIO();
- if (c > 0 && c < 0x10000)
- io.AddInputCharacter((unsigned short)c);
+ io.AddInputCharacter(c);
}
static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, GlfwClientApi client_api)
@@ -163,6 +167,7 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw
io.KeyMap[ImGuiKey_Space] = GLFW_KEY_SPACE;
io.KeyMap[ImGuiKey_Enter] = GLFW_KEY_ENTER;
io.KeyMap[ImGuiKey_Escape] = GLFW_KEY_ESCAPE;
+ io.KeyMap[ImGuiKey_KeyPadEnter] = GLFW_KEY_KP_ENTER;
io.KeyMap[ImGuiKey_A] = GLFW_KEY_A;
io.KeyMap[ImGuiKey_C] = GLFW_KEY_C;
io.KeyMap[ImGuiKey_V] = GLFW_KEY_V;
@@ -199,6 +204,9 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw
// Our mouse update function expect PlatformHandle to be filled for the main viewport
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
main_viewport->PlatformHandle = (void*)g_Window;
+#ifdef _WIN32
+ main_viewport->PlatformHandleRaw = glfwGetWin32Window(g_Window);
+#endif
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
ImGui_ImplGlfw_InitPlatformInterface();
@@ -230,12 +238,8 @@ void ImGui_ImplGlfw_Shutdown()
static void ImGui_ImplGlfw_UpdateMousePosAndButtons()
{
- ImGuiIO& io = ImGui::GetIO();
- const ImVec2 mouse_pos_backup = io.MousePos;
- io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
- io.MouseHoveredViewport = 0;
-
// Update buttons
+ ImGuiIO& io = ImGui::GetIO();
for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++)
{
// If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
@@ -243,6 +247,10 @@ static void ImGui_ImplGlfw_UpdateMousePosAndButtons()
g_MouseJustPressed[i] = false;
}
+ // Update mouse position
+ const ImVec2 mouse_pos_backup = io.MousePos;
+ io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
+ io.MouseHoveredViewport = 0;
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
for (int n = 0; n < platform_io.Viewports.Size; n++)
{
@@ -323,6 +331,43 @@ static void ImGui_ImplGlfw_UpdateMouseCursor()
}
}
+static void ImGui_ImplGlfw_UpdateGamepads()
+{
+ ImGuiIO& io = ImGui::GetIO();
+ memset(io.NavInputs, 0, sizeof(io.NavInputs));
+ if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0)
+ return;
+
+ // Update gamepad inputs
+ #define MAP_BUTTON(NAV_NO, BUTTON_NO) { if (buttons_count > BUTTON_NO && buttons[BUTTON_NO] == GLFW_PRESS) io.NavInputs[NAV_NO] = 1.0f; }
+ #define MAP_ANALOG(NAV_NO, AXIS_NO, V0, V1) { float v = (axes_count > AXIS_NO) ? axes[AXIS_NO] : V0; v = (v - V0) / (V1 - V0); if (v > 1.0f) v = 1.0f; if (io.NavInputs[NAV_NO] < v) io.NavInputs[NAV_NO] = v; }
+ int axes_count = 0, buttons_count = 0;
+ const float* axes = glfwGetJoystickAxes(GLFW_JOYSTICK_1, &axes_count);
+ const unsigned char* buttons = glfwGetJoystickButtons(GLFW_JOYSTICK_1, &buttons_count);
+ MAP_BUTTON(ImGuiNavInput_Activate, 0); // Cross / A
+ MAP_BUTTON(ImGuiNavInput_Cancel, 1); // Circle / B
+ MAP_BUTTON(ImGuiNavInput_Menu, 2); // Square / X
+ MAP_BUTTON(ImGuiNavInput_Input, 3); // Triangle / Y
+ MAP_BUTTON(ImGuiNavInput_DpadLeft, 13); // D-Pad Left
+ MAP_BUTTON(ImGuiNavInput_DpadRight, 11); // D-Pad Right
+ MAP_BUTTON(ImGuiNavInput_DpadUp, 10); // D-Pad Up
+ MAP_BUTTON(ImGuiNavInput_DpadDown, 12); // D-Pad Down
+ MAP_BUTTON(ImGuiNavInput_FocusPrev, 4); // L1 / LB
+ MAP_BUTTON(ImGuiNavInput_FocusNext, 5); // R1 / RB
+ MAP_BUTTON(ImGuiNavInput_TweakSlow, 4); // L1 / LB
+ MAP_BUTTON(ImGuiNavInput_TweakFast, 5); // R1 / RB
+ MAP_ANALOG(ImGuiNavInput_LStickLeft, 0, -0.3f, -0.9f);
+ MAP_ANALOG(ImGuiNavInput_LStickRight,0, +0.3f, +0.9f);
+ MAP_ANALOG(ImGuiNavInput_LStickUp, 1, +0.3f, +0.9f);
+ MAP_ANALOG(ImGuiNavInput_LStickDown, 1, -0.3f, -0.9f);
+ #undef MAP_BUTTON
+ #undef MAP_ANALOG
+ if (axes_count > 0 && buttons_count > 0)
+ io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
+ else
+ io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
+}
+
void ImGui_ImplGlfw_NewFrame()
{
ImGuiIO& io = ImGui::GetIO();
@@ -334,7 +379,8 @@ void ImGui_ImplGlfw_NewFrame()
glfwGetWindowSize(g_Window, &w, &h);
glfwGetFramebufferSize(g_Window, &display_w, &display_h);
io.DisplaySize = ImVec2((float)w, (float)h);
- io.DisplayFramebufferScale = ImVec2(w > 0 ? ((float)display_w / w) : 0, h > 0 ? ((float)display_h / h) : 0);
+ if (w > 0 && h > 0)
+ io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h);
if (g_WantUpdateMonitors)
ImGui_ImplGlfw_UpdateMonitors();
@@ -346,39 +392,8 @@ void ImGui_ImplGlfw_NewFrame()
ImGui_ImplGlfw_UpdateMousePosAndButtons();
ImGui_ImplGlfw_UpdateMouseCursor();
- // Gamepad navigation mapping
- memset(io.NavInputs, 0, sizeof(io.NavInputs));
- if (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad)
- {
- // Update gamepad inputs
- #define MAP_BUTTON(NAV_NO, BUTTON_NO) { if (buttons_count > BUTTON_NO && buttons[BUTTON_NO] == GLFW_PRESS) io.NavInputs[NAV_NO] = 1.0f; }
- #define MAP_ANALOG(NAV_NO, AXIS_NO, V0, V1) { float v = (axes_count > AXIS_NO) ? axes[AXIS_NO] : V0; v = (v - V0) / (V1 - V0); if (v > 1.0f) v = 1.0f; if (io.NavInputs[NAV_NO] < v) io.NavInputs[NAV_NO] = v; }
- int axes_count = 0, buttons_count = 0;
- const float* axes = glfwGetJoystickAxes(GLFW_JOYSTICK_1, &axes_count);
- const unsigned char* buttons = glfwGetJoystickButtons(GLFW_JOYSTICK_1, &buttons_count);
- MAP_BUTTON(ImGuiNavInput_Activate, 0); // Cross / A
- MAP_BUTTON(ImGuiNavInput_Cancel, 1); // Circle / B
- MAP_BUTTON(ImGuiNavInput_Menu, 2); // Square / X
- MAP_BUTTON(ImGuiNavInput_Input, 3); // Triangle / Y
- MAP_BUTTON(ImGuiNavInput_DpadLeft, 13); // D-Pad Left
- MAP_BUTTON(ImGuiNavInput_DpadRight, 11); // D-Pad Right
- MAP_BUTTON(ImGuiNavInput_DpadUp, 10); // D-Pad Up
- MAP_BUTTON(ImGuiNavInput_DpadDown, 12); // D-Pad Down
- MAP_BUTTON(ImGuiNavInput_FocusPrev, 4); // L1 / LB
- MAP_BUTTON(ImGuiNavInput_FocusNext, 5); // R1 / RB
- MAP_BUTTON(ImGuiNavInput_TweakSlow, 4); // L1 / LB
- MAP_BUTTON(ImGuiNavInput_TweakFast, 5); // R1 / RB
- MAP_ANALOG(ImGuiNavInput_LStickLeft, 0, -0.3f, -0.9f);
- MAP_ANALOG(ImGuiNavInput_LStickRight,0, +0.3f, +0.9f);
- MAP_ANALOG(ImGuiNavInput_LStickUp, 1, +0.3f, +0.9f);
- MAP_ANALOG(ImGuiNavInput_LStickDown, 1, -0.3f, -0.9f);
- #undef MAP_BUTTON
- #undef MAP_ANALOG
- if (axes_count > 0 && buttons_count > 0)
- io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
- else
- io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
- }
+ // Update game controllers (if enabled and available)
+ ImGui_ImplGlfw_UpdateGamepads();
}
//--------------------------------------------------------------------------------------------------------
@@ -391,8 +406,9 @@ struct ImGuiViewportDataGlfw
{
GLFWwindow* Window;
bool WindowOwned;
+ int IgnoreWindowSizeEventFrame;
- ImGuiViewportDataGlfw() { Window = NULL; WindowOwned = false; }
+ ImGuiViewportDataGlfw() { Window = NULL; WindowOwned = false; IgnoreWindowSizeEventFrame = -1; }
~ImGuiViewportDataGlfw() { IM_ASSERT(Window == NULL); }
};
@@ -411,7 +427,22 @@ static void ImGui_ImplGlfw_WindowPosCallback(GLFWwindow* window, int, int)
static void ImGui_ImplGlfw_WindowSizeCallback(GLFWwindow* window, int, int)
{
if (ImGuiViewport* viewport = ImGui::FindViewportByPlatformHandle(window))
+ {
+ if (ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData)
+ {
+ // GLFW may dispatch window size event after calling glfwSetWindowSize().
+ // However depending on the platform the callback may be invoked at different time: on Windows it
+ // appears to be called within the glfwSetWindowSize() call whereas on Linux it is queued and invoked
+ // during glfwPollEvents().
+ // Because the event doesn't always fire on glfwSetWindowSize() we use a frame counter tag to only
+ // ignore recent glfwSetWindowSize() calls.
+ bool ignore_event = (ImGui::GetFrameCount() <= data->IgnoreWindowSizeEventFrame + 1);
+ data->IgnoreWindowSizeEventFrame = -1;
+ if (ignore_event)
+ return;
+ }
viewport->PlatformRequestResize = true;
+ }
}
static void ImGui_ImplGlfw_CreateWindow(ImGuiViewport* viewport)
@@ -420,8 +451,12 @@ static void ImGui_ImplGlfw_CreateWindow(ImGuiViewport* viewport)
viewport->PlatformUserData = data;
// GLFW 3.2 unfortunately always set focus on glfwCreateWindow() if GLFW_VISIBLE is set, regardless of GLFW_FOCUSED
+ // With GLFW 3.3, the hint GLFW_FOCUS_ON_SHOW fixes this problem
glfwWindowHint(GLFW_VISIBLE, false);
glfwWindowHint(GLFW_FOCUSED, false);
+#if GLFW_HAS_FOCUS_ON_SHOW
+ glfwWindowHint(GLFW_FOCUS_ON_SHOW, false);
+ #endif
glfwWindowHint(GLFW_DECORATED, (viewport->Flags & ImGuiViewportFlags_NoDecoration) ? false : true);
#if GLFW_HAS_WINDOW_TOPMOST
glfwWindowHint(GLFW_FLOATING, (viewport->Flags & ImGuiViewportFlags_TopMost) ? true : false);
@@ -430,6 +465,9 @@ static void ImGui_ImplGlfw_CreateWindow(ImGuiViewport* viewport)
data->Window = glfwCreateWindow((int)viewport->Size.x, (int)viewport->Size.y, "No Title Yet", NULL, share_window);
data->WindowOwned = true;
viewport->PlatformHandle = (void*)data->Window;
+#ifdef _WIN32
+ viewport->PlatformHandleRaw = glfwGetWin32Window(data->Window);
+#endif
glfwSetWindowPos(data->Window, (int)viewport->Pos.x, (int)viewport->Pos.y);
// Install callbacks for secondary viewports
@@ -454,7 +492,7 @@ static void ImGui_ImplGlfw_DestroyWindow(ImGuiViewport* viewport)
if (data->WindowOwned)
{
#if GLFW_HAS_GLFW_HOVERED && defined(_WIN32)
- HWND hwnd = glfwGetWin32Window(data->Window);
+ HWND hwnd = (HWND)viewport->PlatformHandleRaw;
::RemovePropA(hwnd, "IMGUI_VIEWPORT");
#endif
glfwDestroyWindow(data->Window);
@@ -465,6 +503,7 @@ static void ImGui_ImplGlfw_DestroyWindow(ImGuiViewport* viewport)
viewport->PlatformUserData = viewport->PlatformHandle = NULL;
}
+// FIXME-VIEWPORT: Implement same work-around for Linux/OSX in the meanwhile.
#if defined(_WIN32) && GLFW_HAS_GLFW_HOVERED
static WNDPROC g_GlfwWndProc = NULL;
static LRESULT CALLBACK WndProcNoInputs(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
@@ -489,7 +528,7 @@ static void ImGui_ImplGlfw_ShowWindow(ImGuiViewport* viewport)
#if defined(_WIN32)
// GLFW hack: Hide icon from task bar
- HWND hwnd = glfwGetWin32Window(data->Window);
+ HWND hwnd = (HWND)viewport->PlatformHandleRaw;
if (viewport->Flags & ImGuiViewportFlags_NoTaskBarIcon)
{
LONG ex_style = ::GetWindowLong(hwnd, GWL_EXSTYLE);
@@ -506,13 +545,17 @@ static void ImGui_ImplGlfw_ShowWindow(ImGuiViewport* viewport)
::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)WndProcNoInputs);
#endif
+#if !GLFW_HAS_FOCUS_ON_SHOW
// GLFW hack: GLFW 3.2 has a bug where glfwShowWindow() also activates/focus the window.
- // The fix was pushed to GLFW repository on 2018/01/09 and should be included in GLFW 3.3. See https://github.com/glfw/glfw/issues/1179
+ // The fix was pushed to GLFW repository on 2018/01/09 and should be included in GLFW 3.3 via a GLFW_FOCUS_ON_SHOW window attribute.
+ // See https://github.com/glfw/glfw/issues/1189
+ // FIXME-VIEWPORT: Implement same work-around for Linux/OSX in the meanwhile.
if (viewport->Flags & ImGuiViewportFlags_NoFocusOnAppearing)
{
::ShowWindow(hwnd, SW_SHOWNA);
return;
}
+#endif
#endif
glfwShowWindow(data->Window);
@@ -543,6 +586,17 @@ static ImVec2 ImGui_ImplGlfw_GetWindowSize(ImGuiViewport* viewport)
static void ImGui_ImplGlfw_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
{
ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData;
+#if __APPLE__
+ // Native OS windows are positioned from the bottom-left corner on macOS, whereas on other platforms they are
+ // positioned from the upper-left corner. GLFW makes an effort to convert macOS style coordinates, however it
+ // doesn't handle it when changing size. We are manually moving the window in order for changes of size to be based
+ // on the upper-left corner.
+ int x, y, width, height;
+ glfwGetWindowPos(data->Window, &x, &y);
+ glfwGetWindowSize(data->Window, &width, &height);
+ glfwSetWindowPos(data->Window, x, y - height + size.y);
+#endif
+ data->IgnoreWindowSizeEventFrame = ImGui::GetFrameCount();
glfwSetWindowSize(data->Window, (int)size.x, (int)size.y);
}
@@ -594,7 +648,10 @@ static void ImGui_ImplGlfw_SwapBuffers(ImGuiViewport* viewport, void*)
{
ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData;
if (g_ClientApi == GlfwClientApi_OpenGL)
+ {
+ glfwMakeContextCurrent(data->Window);
glfwSwapBuffers(data->Window);
+ }
}
//--------------------------------------------------------------------------------------------------------
@@ -611,13 +668,12 @@ static void ImGui_ImplGlfw_SwapBuffers(ImGuiViewport* viewport, void*)
static void ImGui_ImplWin32_SetImeInputPos(ImGuiViewport* viewport, ImVec2 pos)
{
COMPOSITIONFORM cf = { CFS_FORCE_POSITION, { (LONG)(pos.x - viewport->Pos.x), (LONG)(pos.y - viewport->Pos.y) }, { 0, 0, 0, 0 } };
- if (ImGuiViewportDataGlfw* data = (ImGuiViewportDataGlfw*)viewport->PlatformUserData)
- if (HWND hwnd = glfwGetWin32Window(data->Window))
- if (HIMC himc = ::ImmGetContext(hwnd))
- {
- ::ImmSetCompositionWindow(himc, &cf);
- ::ImmReleaseContext(hwnd, himc);
- }
+ if (HWND hwnd = (HWND)viewport->PlatformHandleRaw)
+ if (HIMC himc = ::ImmGetContext(hwnd))
+ {
+ ::ImmSetCompositionWindow(himc, &cf);
+ ::ImmReleaseContext(hwnd, himc);
+ }
}
#else
#define HAS_WIN32_IME 0
@@ -664,8 +720,17 @@ static void ImGui_ImplGlfw_UpdateMonitors()
int x, y;
glfwGetMonitorPos(glfw_monitors[n], &x, &y);
const GLFWvidmode* vid_mode = glfwGetVideoMode(glfw_monitors[n]);
+#if GLFW_HAS_MONITOR_WORK_AREA
+ monitor.MainPos = ImVec2((float)x, (float)y);
+ monitor.MainSize = ImVec2((float)vid_mode->width, (float)vid_mode->height);
+ int w, h;
+ glfwGetMonitorWorkarea(glfw_monitors[n], &x, &y, &w, &h);
+ monitor.WorkPos = ImVec2((float)x, (float)y);;
+ monitor.WorkSize = ImVec2((float)w, (float)h);
+#else
monitor.MainPos = monitor.WorkPos = ImVec2((float)x, (float)y);
monitor.MainSize = monitor.WorkSize = ImVec2((float)vid_mode->width, (float)vid_mode->height);
+#endif
#if GLFW_HAS_PER_MONITOR_DPI
// Warning: the validity of monitor DPI information on Windows depends on the application DPI awareness settings, which generally needs to be set in the manifest or at runtime.
float x_scale, y_scale;
diff --git a/examples/imgui_impl_freeglut.cpp b/examples/imgui_impl_glut.cpp
similarity index 67%
rename from examples/imgui_impl_freeglut.cpp
rename to examples/imgui_impl_glut.cpp
index 42d56417..56d8c553 100644
--- a/examples/imgui_impl_freeglut.cpp
+++ b/examples/imgui_impl_glut.cpp
@@ -1,8 +1,14 @@
-// dear imgui: Platform Binding for FreeGLUT
+// dear imgui: Platform Binding for GLUT/FreeGLUT
// This needs to be used along with a Renderer (e.g. OpenGL2)
+// !!! GLUT/FreeGLUT IS OBSOLETE SOFTWARE. Using GLUT is not recommended unless you really miss the 90's. !!!
+// !!! If someone or something is teaching you GLUT in 2019, you are being abused. Please show some resistance. !!!
+// !!! Nowadays, prefer using GLFW or SDL instead!
+
// Issues:
// [ ] Platform: GLUT is unable to distinguish e.g. Backspace from CTRL+H or TAB from CTRL+I
+// [ ] Platform: Missing mouse cursor shape/visibility support.
+// [ ] Platform: Missing clipboard support (not supported by Glut).
// [ ] Platform: Missing gamepad support.
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
@@ -11,12 +17,18 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
+// 2019-04-03: Misc: Renamed imgui_impl_freeglut.cpp/.h to imgui_impl_glut.cpp/.h.
+// 2019-03-25: Misc: Made io.DeltaTime always above zero.
// 2018-11-30: Misc: Setting up io.BackendPlatformName so it can be displayed in the About Window.
-// 2018-03-22: Added FreeGLUT Platform binding.
+// 2018-03-22: Added GLUT Platform binding.
#include "imgui.h"
-#include "imgui_impl_freeglut.h"
-#include
+#include "imgui_impl_glut.h"
+#ifdef __APPLE__
+ #include
+#else
+ #include
+#endif
#ifdef _MSC_VER
#pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff)
@@ -24,10 +36,10 @@
static int g_Time = 0; // Current time, in milliseconds
-bool ImGui_ImplFreeGLUT_Init()
+bool ImGui_ImplGLUT_Init()
{
ImGuiIO& io = ImGui::GetIO();
- io.BackendPlatformName ="imgui_impl_freeglut";
+ io.BackendPlatformName ="imgui_impl_glut";
g_Time = 0;
@@ -47,6 +59,7 @@ bool ImGui_ImplFreeGLUT_Init()
io.KeyMap[ImGuiKey_Space] = ' ';
io.KeyMap[ImGuiKey_Enter] = 13; // == CTRL+M
io.KeyMap[ImGuiKey_Escape] = 27;
+ io.KeyMap[ImGuiKey_KeyPadEnter] = 13; // == CTRL+M
io.KeyMap[ImGuiKey_A] = 'A';
io.KeyMap[ImGuiKey_C] = 'C';
io.KeyMap[ImGuiKey_V] = 'V';
@@ -57,36 +70,41 @@ bool ImGui_ImplFreeGLUT_Init()
return true;
}
-void ImGui_ImplFreeGLUT_InstallFuncs()
+void ImGui_ImplGLUT_InstallFuncs()
{
- glutReshapeFunc(ImGui_ImplFreeGLUT_ReshapeFunc);
- glutMotionFunc(ImGui_ImplFreeGLUT_MotionFunc);
- glutPassiveMotionFunc(ImGui_ImplFreeGLUT_MotionFunc);
- glutMouseFunc(ImGui_ImplFreeGLUT_MouseFunc);
- glutMouseWheelFunc(ImGui_ImplFreeGLUT_MouseWheelFunc);
- glutKeyboardFunc(ImGui_ImplFreeGLUT_KeyboardFunc);
- glutKeyboardUpFunc(ImGui_ImplFreeGLUT_KeyboardUpFunc);
- glutSpecialFunc(ImGui_ImplFreeGLUT_SpecialFunc);
- glutSpecialUpFunc(ImGui_ImplFreeGLUT_SpecialUpFunc);
+ glutReshapeFunc(ImGui_ImplGLUT_ReshapeFunc);
+ glutMotionFunc(ImGui_ImplGLUT_MotionFunc);
+ glutPassiveMotionFunc(ImGui_ImplGLUT_MotionFunc);
+ glutMouseFunc(ImGui_ImplGLUT_MouseFunc);
+#ifdef __FREEGLUT_EXT_H__
+ glutMouseWheelFunc(ImGui_ImplGLUT_MouseWheelFunc);
+#endif
+ glutKeyboardFunc(ImGui_ImplGLUT_KeyboardFunc);
+ glutKeyboardUpFunc(ImGui_ImplGLUT_KeyboardUpFunc);
+ glutSpecialFunc(ImGui_ImplGLUT_SpecialFunc);
+ glutSpecialUpFunc(ImGui_ImplGLUT_SpecialUpFunc);
}
-void ImGui_ImplFreeGLUT_Shutdown()
+void ImGui_ImplGLUT_Shutdown()
{
}
-void ImGui_ImplFreeGLUT_NewFrame()
+void ImGui_ImplGLUT_NewFrame()
{
// Setup time step
ImGuiIO& io = ImGui::GetIO();
int current_time = glutGet(GLUT_ELAPSED_TIME);
- io.DeltaTime = (current_time - g_Time) / 1000.0f;
+ int delta_time_ms = (current_time - g_Time);
+ if (delta_time_ms <= 0)
+ delta_time_ms = 1;
+ io.DeltaTime = delta_time_ms / 1000.0f;
g_Time = current_time;
// Start the frame
ImGui::NewFrame();
}
-static void ImGui_ImplFreeGLUT_UpdateKeyboardMods()
+static void ImGui_ImplGLUT_UpdateKeyboardMods()
{
ImGuiIO& io = ImGui::GetIO();
int mods = glutGetModifiers();
@@ -95,13 +113,13 @@ static void ImGui_ImplFreeGLUT_UpdateKeyboardMods()
io.KeyAlt = (mods & GLUT_ACTIVE_ALT) != 0;
}
-void ImGui_ImplFreeGLUT_KeyboardFunc(unsigned char c, int x, int y)
+void ImGui_ImplGLUT_KeyboardFunc(unsigned char c, int x, int y)
{
// Send character to imgui
//printf("char_down_func %d '%c'\n", c, c);
ImGuiIO& io = ImGui::GetIO();
if (c >= 32)
- io.AddInputCharacter((unsigned short)c);
+ io.AddInputCharacter((unsigned int)c);
// Store letters in KeysDown[] array as both uppercase and lowercase + Handle GLUT translating CTRL+A..CTRL+Z as 1..26.
// This is a hacky mess but GLUT is unable to distinguish e.g. a TAB key from CTRL+I so this is probably the best we can do here.
@@ -113,11 +131,11 @@ void ImGui_ImplFreeGLUT_KeyboardFunc(unsigned char c, int x, int y)
io.KeysDown[c] = io.KeysDown[c - 'A' + 'a'] = true;
else
io.KeysDown[c] = true;
- ImGui_ImplFreeGLUT_UpdateKeyboardMods();
+ ImGui_ImplGLUT_UpdateKeyboardMods();
(void)x; (void)y; // Unused
}
-void ImGui_ImplFreeGLUT_KeyboardUpFunc(unsigned char c, int x, int y)
+void ImGui_ImplGLUT_KeyboardUpFunc(unsigned char c, int x, int y)
{
//printf("char_up_func %d '%c'\n", c, c);
ImGuiIO& io = ImGui::GetIO();
@@ -129,31 +147,31 @@ void ImGui_ImplFreeGLUT_KeyboardUpFunc(unsigned char c, int x, int y)
io.KeysDown[c] = io.KeysDown[c - 'A' + 'a'] = false;
else
io.KeysDown[c] = false;
- ImGui_ImplFreeGLUT_UpdateKeyboardMods();
+ ImGui_ImplGLUT_UpdateKeyboardMods();
(void)x; (void)y; // Unused
}
-void ImGui_ImplFreeGLUT_SpecialFunc(int key, int x, int y)
+void ImGui_ImplGLUT_SpecialFunc(int key, int x, int y)
{
//printf("key_down_func %d\n", key);
ImGuiIO& io = ImGui::GetIO();
if (key + 256 < IM_ARRAYSIZE(io.KeysDown))
io.KeysDown[key + 256] = true;
- ImGui_ImplFreeGLUT_UpdateKeyboardMods();
+ ImGui_ImplGLUT_UpdateKeyboardMods();
(void)x; (void)y; // Unused
}
-void ImGui_ImplFreeGLUT_SpecialUpFunc(int key, int x, int y)
+void ImGui_ImplGLUT_SpecialUpFunc(int key, int x, int y)
{
//printf("key_up_func %d\n", key);
ImGuiIO& io = ImGui::GetIO();
if (key + 256 < IM_ARRAYSIZE(io.KeysDown))
io.KeysDown[key + 256] = false;
- ImGui_ImplFreeGLUT_UpdateKeyboardMods();
+ ImGui_ImplGLUT_UpdateKeyboardMods();
(void)x; (void)y; // Unused
}
-void ImGui_ImplFreeGLUT_MouseFunc(int glut_button, int state, int x, int y)
+void ImGui_ImplGLUT_MouseFunc(int glut_button, int state, int x, int y)
{
ImGuiIO& io = ImGui::GetIO();
io.MousePos = ImVec2((float)x, (float)y);
@@ -167,7 +185,8 @@ void ImGui_ImplFreeGLUT_MouseFunc(int glut_button, int state, int x, int y)
io.MouseDown[button] = false;
}
-void ImGui_ImplFreeGLUT_MouseWheelFunc(int button, int dir, int x, int y)
+#ifdef __FREEGLUT_EXT_H__
+void ImGui_ImplGLUT_MouseWheelFunc(int button, int dir, int x, int y)
{
ImGuiIO& io = ImGui::GetIO();
io.MousePos = ImVec2((float)x, (float)y);
@@ -177,14 +196,15 @@ void ImGui_ImplFreeGLUT_MouseWheelFunc(int button, int dir, int x, int y)
io.MouseWheel -= 1.0;
(void)button; // Unused
}
+#endif
-void ImGui_ImplFreeGLUT_ReshapeFunc(int w, int h)
+void ImGui_ImplGLUT_ReshapeFunc(int w, int h)
{
ImGuiIO& io = ImGui::GetIO();
io.DisplaySize = ImVec2((float)w, (float)h);
}
-void ImGui_ImplFreeGLUT_MotionFunc(int x, int y)
+void ImGui_ImplGLUT_MotionFunc(int x, int y)
{
ImGuiIO& io = ImGui::GetIO();
io.MousePos = ImVec2((float)x, (float)y);
diff --git a/examples/imgui_impl_glut.h b/examples/imgui_impl_glut.h
new file mode 100644
index 00000000..506c3867
--- /dev/null
+++ b/examples/imgui_impl_glut.h
@@ -0,0 +1,35 @@
+// dear imgui: Platform Binding for GLUT/FreeGLUT
+// This needs to be used along with a Renderer (e.g. OpenGL2)
+
+// !!! GLUT/FreeGLUT IS OBSOLETE SOFTWARE. Using GLUT is not recommended unless you really miss the 90's. !!!
+// !!! If someone or something is teaching you GLUT in 2019, you are being abused. Please show some resistance. !!!
+// !!! Nowadays, prefer using GLFW or SDL instead!
+
+// Issues:
+// [ ] Platform: GLUT is unable to distinguish e.g. Backspace from CTRL+H or TAB from CTRL+I
+// [ ] Platform: Missing mouse cursor shape/visibility support.
+// [ ] Platform: Missing clipboard support (not supported by Glut).
+// [ ] Platform: Missing gamepad support.
+
+// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
+// If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
+// https://github.com/ocornut/imgui
+
+#pragma once
+
+IMGUI_IMPL_API bool ImGui_ImplGLUT_Init();
+IMGUI_IMPL_API void ImGui_ImplGLUT_InstallFuncs();
+IMGUI_IMPL_API void ImGui_ImplGLUT_Shutdown();
+IMGUI_IMPL_API void ImGui_ImplGLUT_NewFrame();
+
+// You can call ImGui_ImplGLUT_InstallFuncs() to get all those functions installed automatically,
+// or call them yourself from your own GLUT handlers. We are using the same weird names as GLUT for consistency..
+//---------------------------------------- GLUT name --------------------------------------------- Decent Name ---------
+IMGUI_IMPL_API void ImGui_ImplGLUT_ReshapeFunc(int w, int h); // ~ ResizeFunc
+IMGUI_IMPL_API void ImGui_ImplGLUT_MotionFunc(int x, int y); // ~ MouseMoveFunc
+IMGUI_IMPL_API void ImGui_ImplGLUT_MouseFunc(int button, int state, int x, int y); // ~ MouseButtonFunc
+IMGUI_IMPL_API void ImGui_ImplGLUT_MouseWheelFunc(int button, int dir, int x, int y); // ~ MouseWheelFunc
+IMGUI_IMPL_API void ImGui_ImplGLUT_KeyboardFunc(unsigned char c, int x, int y); // ~ CharPressedFunc
+IMGUI_IMPL_API void ImGui_ImplGLUT_KeyboardUpFunc(unsigned char c, int x, int y); // ~ CharReleasedFunc
+IMGUI_IMPL_API void ImGui_ImplGLUT_SpecialFunc(int key, int x, int y); // ~ KeyPressedFunc
+IMGUI_IMPL_API void ImGui_ImplGLUT_SpecialUpFunc(int key, int x, int y); // ~ KeyReleasedFunc
diff --git a/examples/imgui_impl_marmalade.cpp b/examples/imgui_impl_marmalade.cpp
index 45435977..497a5705 100644
--- a/examples/imgui_impl_marmalade.cpp
+++ b/examples/imgui_impl_marmalade.cpp
@@ -3,6 +3,8 @@
// Implemented features:
// [X] Renderer: User texture binding. Use 'CIwTexture*' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
+// Missing features:
+// [ ] Renderer: Clipping rectangles are not honored.
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
// If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
@@ -10,6 +12,8 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
+// 2019-07-21: Inputs: Added mapping for ImGuiKey_KeyPadEnter.
+// 2019-05-11: Inputs: Don't filter value from character callback before calling AddInputCharacter().
// 2018-11-30: Misc: Setting up io.BackendPlatformName/io.BackendRendererName so they can be displayed in the About Window.
// 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_Marmalade_RenderDrawData() in the .h file so you can call it yourself.
// 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves.
@@ -38,9 +42,9 @@ static ImVec2 g_RenderScale = ImVec2(1.0f,1.0f);
// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
void ImGui_Marmalade_RenderDrawData(ImDrawData* draw_data)
{
- // Handle cases of screen coordinates != from framebuffer coordinates (e.g. retina displays)
- ImGuiIO& io = ImGui::GetIO();
- draw_data->ScaleClipRects(io.DisplayFramebufferScale);
+ // Avoid rendering when minimized
+ if (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f)
+ return;
// Render command lists
for (int n = 0; n < draw_data->CmdListsCount; n++)
@@ -54,7 +58,7 @@ void ImGui_Marmalade_RenderDrawData(ImDrawData* draw_data)
for (int i = 0; i < nVert; i++)
{
- // TODO: optimize multiplication on gpu using vertex shader/projection matrix.
+ // FIXME-OPT: optimize multiplication on GPU using vertex shader/projection matrix.
pVertStream[i].x = cmd_list->VtxBuffer[i].pos.x * g_RenderScale.x;
pVertStream[i].y = cmd_list->VtxBuffer[i].pos.y * g_RenderScale.y;
pUVStream[i].x = cmd_list->VtxBuffer[i].uv.x;
@@ -76,6 +80,7 @@ void ImGui_Marmalade_RenderDrawData(ImDrawData* draw_data)
}
else
{
+ // FIXME: Not honoring ClipRect fields.
CIwMaterial* pCurrentMaterial = IW_GX_ALLOC_MATERIAL();
pCurrentMaterial->SetShadeMode(CIwMaterial::SHADE_FLAT);
pCurrentMaterial->SetCullMode(CIwMaterial::CULL_NONE);
@@ -163,8 +168,7 @@ int32 ImGui_Marmalade_CharCallback(void* system_data, void* user_data)
{
ImGuiIO& io = ImGui::GetIO();
s3eKeyboardCharEvent* e = (s3eKeyboardCharEvent*)system_data;
- if ((e->m_Char > 0 && e->m_Char < 0x10000))
- io.AddInputCharacter((unsigned short)e->m_Char);
+ io.AddInputCharacter((unsigned int)e->m_Char);
return 0;
}
@@ -232,6 +236,7 @@ bool ImGui_Marmalade_Init(bool install_callbacks)
io.KeyMap[ImGuiKey_Space] = s3eKeySpace;
io.KeyMap[ImGuiKey_Enter] = s3eKeyEnter;
io.KeyMap[ImGuiKey_Escape] = s3eKeyEsc;
+ io.KeyMap[ImGuiKey_KeyPadEnter] = s3eKeyNumPadEnter;
io.KeyMap[ImGuiKey_A] = s3eKeyA;
io.KeyMap[ImGuiKey_C] = s3eKeyC;
io.KeyMap[ImGuiKey_V] = s3eKeyV;
diff --git a/examples/imgui_impl_metal.h b/examples/imgui_impl_metal.h
index 731ec20b..6c6e4ca9 100644
--- a/examples/imgui_impl_metal.h
+++ b/examples/imgui_impl_metal.h
@@ -3,6 +3,7 @@
// Implemented features:
// [X] Renderer: User texture binding. Use 'MTLTexture' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
+// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices.
// Missing features:
// [ ] Renderer: Multi-viewport / platform windows.
diff --git a/examples/imgui_impl_metal.mm b/examples/imgui_impl_metal.mm
index 24b9bf68..abfeb169 100644
--- a/examples/imgui_impl_metal.mm
+++ b/examples/imgui_impl_metal.mm
@@ -3,6 +3,7 @@
// Implemented features:
// [X] Renderer: User texture binding. Use 'MTLTexture' as ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
+// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices.
// Missing features:
// [ ] Renderer: Multi-viewport / platform windows.
@@ -12,6 +13,9 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
+// 2019-05-29: Metal: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag.
+// 2019-04-30: Metal: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
+// 2019-02-11: Metal: Projecting clipping rectangles correctly using draw_data->FramebufferScale to allow multi-viewports for retina display.
// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
// 2018-07-05: Metal: Added new Metal backend implementation.
@@ -19,7 +23,7 @@
#include "imgui_impl_metal.h"
#import
-// #import // Not suported in XCode 9.2. Maybe a macro to detect the SDK version can be used (something like #if MACOS_SDK >= 10.13 ...)
+// #import // Not supported in XCode 9.2. Maybe a macro to detect the SDK version can be used (something like #if MACOS_SDK >= 10.13 ...)
#import
#pragma mark - Support classes
@@ -57,6 +61,12 @@
- (void)enqueueReusableBuffer:(MetalBuffer *)buffer;
- (id)renderPipelineStateForFrameAndDevice:(id)device;
- (void)emptyRenderPipelineStateCache;
+- (void)setupRenderState:(ImDrawData *)drawData
+ commandBuffer:(id)commandBuffer
+ commandEncoder:(id)commandEncoder
+ renderPipelineState:(id)renderPipelineState
+ vertexBuffer:(MetalBuffer *)vertexBuffer
+ vertexBufferOffset:(size_t)vertexBufferOffset;
- (void)renderDrawData:(ImDrawData *)drawData
commandBuffer:(id)commandBuffer
commandEncoder:(id)commandEncoder;
@@ -70,6 +80,7 @@ bool ImGui_ImplMetal_Init(id device)
{
ImGuiIO& io = ImGui::GetIO();
io.BackendRendererName = "imgui_impl_metal";
+ io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
@@ -88,7 +99,7 @@ void ImGui_ImplMetal_Shutdown()
void ImGui_ImplMetal_NewFrame(MTLRenderPassDescriptor *renderPassDescriptor)
{
- IM_ASSERT(g_sharedMetalContext != nil && "No Metal context. Did you call ImGui_ImplMetal_Init?");
+ IM_ASSERT(g_sharedMetalContext != nil && "No Metal context. Did you call ImGui_ImplMetal_Init() ?");
g_sharedMetalContext.framebufferDescriptor = [[FramebufferDescriptor alloc] initWithRenderPassDescriptor:renderPassDescriptor];
}
@@ -284,7 +295,7 @@ void ImGui_ImplMetal_DestroyDeviceObjects()
- (_Nullable id)renderPipelineStateForFrameAndDevice:(id)device
{
// Try to retrieve a render pipeline state that is compatible with the framebuffer config for this frame
- // Thie hit rate for this cache should be very near 100%.
+ // The hit rate for this cache should be very near 100%.
id renderPipelineState = self.renderPipelineStateCache[self.framebufferDescriptor];
if (renderPipelineState == nil)
@@ -398,18 +409,13 @@ void ImGui_ImplMetal_DestroyDeviceObjects()
[self.renderPipelineStateCache removeAllObjects];
}
-- (void)renderDrawData:(ImDrawData *)drawData
- commandBuffer:(id)commandBuffer
- commandEncoder:(id)commandEncoder
+- (void)setupRenderState:(ImDrawData *)drawData
+ commandBuffer:(id)commandBuffer
+ commandEncoder:(id)commandEncoder
+ renderPipelineState:(id)renderPipelineState
+ vertexBuffer:(MetalBuffer *)vertexBuffer
+ vertexBufferOffset:(size_t)vertexBufferOffset
{
- // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
- ImGuiIO &io = ImGui::GetIO();
- int fb_width = (int)(drawData->DisplaySize.x * io.DisplayFramebufferScale.x);
- int fb_height = (int)(drawData->DisplaySize.y * io.DisplayFramebufferScale.y);
- if (fb_width <= 0 || fb_height <= 0 || drawData->CmdListsCount == 0)
- return;
- drawData->ScaleClipRects(io.DisplayFramebufferScale);
-
[commandEncoder setCullMode:MTLCullModeNone];
[commandEncoder setDepthStencilState:g_sharedMetalContext.depthStencilState];
@@ -420,12 +426,13 @@ void ImGui_ImplMetal_DestroyDeviceObjects()
{
.originX = 0.0,
.originY = 0.0,
- .width = double(fb_width),
- .height = double(fb_height),
+ .width = (double)(drawData->DisplaySize.x * drawData->FramebufferScale.x),
+ .height = (double)(drawData->DisplaySize.y * drawData->FramebufferScale.y),
.znear = 0.0,
.zfar = 1.0
};
[commandEncoder setViewport:viewport];
+
float L = drawData->DisplayPos.x;
float R = drawData->DisplayPos.x + drawData->DisplaySize.x;
float T = drawData->DisplayPos.y;
@@ -439,71 +446,93 @@ void ImGui_ImplMetal_DestroyDeviceObjects()
{ 0.0f, 0.0f, 1/(F-N), 0.0f },
{ (R+L)/(L-R), (T+B)/(B-T), N/(F-N), 1.0f },
};
-
[commandEncoder setVertexBytes:&ortho_projection length:sizeof(ortho_projection) atIndex:1];
- size_t vertexBufferLength = 0;
- size_t indexBufferLength = 0;
- for (int n = 0; n < drawData->CmdListsCount; n++)
- {
- const ImDrawList* cmd_list = drawData->CmdLists[n];
- vertexBufferLength += cmd_list->VtxBuffer.Size * sizeof(ImDrawVert);
- indexBufferLength += cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx);
- }
+ [commandEncoder setRenderPipelineState:renderPipelineState];
+
+ [commandEncoder setVertexBuffer:vertexBuffer.buffer offset:0 atIndex:0];
+ [commandEncoder setVertexBufferOffset:vertexBufferOffset atIndex:0];
+}
- MetalBuffer *vertexBuffer = [self dequeueReusableBufferOfLength:vertexBufferLength device:commandBuffer.device];
- MetalBuffer *indexBuffer = [self dequeueReusableBufferOfLength:indexBufferLength device:commandBuffer.device];
+- (void)renderDrawData:(ImDrawData *)drawData
+ commandBuffer:(id)commandBuffer
+ commandEncoder:(id)commandEncoder
+{
+ // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
+ int fb_width = (int)(drawData->DisplaySize.x * drawData->FramebufferScale.x);
+ int fb_height = (int)(drawData->DisplaySize.y * drawData->FramebufferScale.y);
+ if (fb_width <= 0 || fb_height <= 0 || drawData->CmdListsCount == 0)
+ return;
id renderPipelineState = [self renderPipelineStateForFrameAndDevice:commandBuffer.device];
- [commandEncoder setRenderPipelineState:renderPipelineState];
- [commandEncoder setVertexBuffer:vertexBuffer.buffer offset:0 atIndex:0];
+ size_t vertexBufferLength = drawData->TotalVtxCount * sizeof(ImDrawVert);
+ size_t indexBufferLength = drawData->TotalIdxCount * sizeof(ImDrawIdx);
+ MetalBuffer* vertexBuffer = [self dequeueReusableBufferOfLength:vertexBufferLength device:commandBuffer.device];
+ MetalBuffer* indexBuffer = [self dequeueReusableBufferOfLength:indexBufferLength device:commandBuffer.device];
+
+ [self setupRenderState:drawData commandBuffer:commandBuffer commandEncoder:commandEncoder renderPipelineState:renderPipelineState vertexBuffer:vertexBuffer vertexBufferOffset:0];
+ // Will project scissor/clipping rectangles into framebuffer space
+ ImVec2 clip_off = drawData->DisplayPos; // (0,0) unless using multi-viewports
+ ImVec2 clip_scale = drawData->FramebufferScale; // (1,1) unless using retina display which are often (2,2)
+
+ // Render command lists
size_t vertexBufferOffset = 0;
size_t indexBufferOffset = 0;
- ImVec2 pos = drawData->DisplayPos;
for (int n = 0; n < drawData->CmdListsCount; n++)
{
const ImDrawList* cmd_list = drawData->CmdLists[n];
- ImDrawIdx idx_buffer_offset = 0;
memcpy((char *)vertexBuffer.buffer.contents + vertexBufferOffset, cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.Size * sizeof(ImDrawVert));
memcpy((char *)indexBuffer.buffer.contents + indexBufferOffset, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx));
- [commandEncoder setVertexBufferOffset:vertexBufferOffset atIndex:0];
-
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
{
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
if (pcmd->UserCallback)
{
- // User callback (registered via ImDrawList::AddCallback)
- pcmd->UserCallback(cmd_list, pcmd);
+ // User callback, registered via ImDrawList::AddCallback()
+ // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
+ if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
+ [self setupRenderState:drawData commandBuffer:commandBuffer commandEncoder:commandEncoder renderPipelineState:renderPipelineState vertexBuffer:vertexBuffer vertexBufferOffset:vertexBufferOffset];
+ else
+ pcmd->UserCallback(cmd_list, pcmd);
}
else
{
- ImVec4 clip_rect = ImVec4(pcmd->ClipRect.x - pos.x, pcmd->ClipRect.y - pos.y, pcmd->ClipRect.z - pos.x, pcmd->ClipRect.w - pos.y);
+ // Project scissor/clipping rectangles into framebuffer space
+ ImVec4 clip_rect;
+ clip_rect.x = (pcmd->ClipRect.x - clip_off.x) * clip_scale.x;
+ clip_rect.y = (pcmd->ClipRect.y - clip_off.y) * clip_scale.y;
+ clip_rect.z = (pcmd->ClipRect.z - clip_off.x) * clip_scale.x;
+ clip_rect.w = (pcmd->ClipRect.w - clip_off.y) * clip_scale.y;
+
if (clip_rect.x < fb_width && clip_rect.y < fb_height && clip_rect.z >= 0.0f && clip_rect.w >= 0.0f)
{
// Apply scissor/clipping rectangle
- MTLScissorRect scissorRect = { .x = NSUInteger(clip_rect.x),
+ MTLScissorRect scissorRect =
+ {
+ .x = NSUInteger(clip_rect.x),
.y = NSUInteger(clip_rect.y),
.width = NSUInteger(clip_rect.z - clip_rect.x),
- .height = NSUInteger(clip_rect.w - clip_rect.y) };
+ .height = NSUInteger(clip_rect.w - clip_rect.y)
+ };
[commandEncoder setScissorRect:scissorRect];
// Bind texture, Draw
if (pcmd->TextureId != NULL)
[commandEncoder setFragmentTexture:(__bridge id)(pcmd->TextureId) atIndex:0];
+
+ [commandEncoder setVertexBufferOffset:(vertexBufferOffset + pcmd->VtxOffset * sizeof(ImDrawVert)) atIndex:0];
[commandEncoder drawIndexedPrimitives:MTLPrimitiveTypeTriangle
indexCount:pcmd->ElemCount
indexType:sizeof(ImDrawIdx) == 2 ? MTLIndexTypeUInt16 : MTLIndexTypeUInt32
indexBuffer:indexBuffer.buffer
- indexBufferOffset:indexBufferOffset + idx_buffer_offset];
+ indexBufferOffset:indexBufferOffset + pcmd->IdxOffset * sizeof(ImDrawIdx)];
}
}
- idx_buffer_offset += pcmd->ElemCount * sizeof(ImDrawIdx);
}
vertexBufferOffset += cmd_list->VtxBuffer.Size * sizeof(ImDrawVert);
diff --git a/examples/imgui_impl_opengl2.cpp b/examples/imgui_impl_opengl2.cpp
index 9e32ea2f..145321ff 100644
--- a/examples/imgui_impl_opengl2.cpp
+++ b/examples/imgui_impl_opengl2.cpp
@@ -20,11 +20,13 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
// 2018-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
+// 2019-04-30: OpenGL: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
+// 2019-02-11: OpenGL: Projecting clipping rectangles correctly using draw_data->FramebufferScale to allow multi-viewports for retina display.
// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
// 2018-08-03: OpenGL: Disabling/restoring GL_LIGHTING and GL_COLOR_MATERIAL to increase compatibility with legacy OpenGL applications.
// 2018-06-08: Misc: Extracted imgui_impl_opengl2.cpp/.h away from the old combined GLFW/SDL+OpenGL2 examples.
// 2018-06-08: OpenGL: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle.
-// 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplGlfwGL2_RenderDrawData() in the .h file so you can call it yourself.
+// 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplOpenGL2_RenderDrawData() in the .h file so you can call it yourself.
// 2017-09-01: OpenGL: Save and restore current polygon mode.
// 2016-09-10: OpenGL: Uploading font texture as RGBA32 to increase compatibility with users shaders (not ideal).
// 2016-09-05: OpenGL: Fixed save and restore of current scissor rectangle.
@@ -45,6 +47,7 @@
#define WINGDIAPI __declspec(dllimport) // Some Windows OpenGL headers need this
#endif
#if defined(__APPLE__)
+#define GL_SILENCE_DEPRECATION
#include
#else
#include
@@ -62,8 +65,9 @@ bool ImGui_ImplOpenGL2_Init()
{
// Setup back-end capabilities flags
ImGuiIO& io = ImGui::GetIO();
- io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
io.BackendRendererName = "imgui_impl_opengl2";
+ io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
+
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
ImGui_ImplOpenGL2_InitPlatformInterface();
return true;
@@ -81,26 +85,9 @@ void ImGui_ImplOpenGL2_NewFrame()
ImGui_ImplOpenGL2_CreateDeviceObjects();
}
-// OpenGL2 Render function.
-// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
-// Note that this implementation is little overcomplicated because we are saving/setting up/restoring every OpenGL state explicitly, in order to be able to run within any OpenGL engine that doesn't do so.
-void ImGui_ImplOpenGL2_RenderDrawData(ImDrawData* draw_data)
+static void ImGui_ImplOpenGL2_SetupRenderState(ImDrawData* draw_data, int fb_width, int fb_height)
{
- // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
- ImGuiIO& io = ImGui::GetIO();
- int fb_width = (int)(draw_data->DisplaySize.x * io.DisplayFramebufferScale.x);
- int fb_height = (int)(draw_data->DisplaySize.y * io.DisplayFramebufferScale.y);
- if (fb_width == 0 || fb_height == 0)
- return;
- draw_data->ScaleClipRects(io.DisplayFramebufferScale);
-
- // We are using the OpenGL fixed pipeline to make the example code simpler to read!
// Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers, polygon fill.
- GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
- GLint last_polygon_mode[2]; glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode);
- GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport);
- GLint last_scissor_box[4]; glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box);
- glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_CULL_FACE);
@@ -114,16 +101,16 @@ void ImGui_ImplOpenGL2_RenderDrawData(ImDrawData* draw_data)
glEnable(GL_TEXTURE_2D);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
- // If you are using this code with non-legacy OpenGL header/contexts (which you should not, prefer using imgui_impl_opengl3.cpp!!),
+ // If you are using this code with non-legacy OpenGL header/contexts (which you should not, prefer using imgui_impl_opengl3.cpp!!),
// you may need to backup/reset/restore current shader using the lines below. DO NOT MODIFY THIS FILE! Add the code in your calling function:
- // GLint last_program;
+ // GLint last_program;
// glGetIntegerv(GL_CURRENT_PROGRAM, &last_program);
// glUseProgram(0);
// ImGui_ImplOpenGL2_RenderDrawData(...);
// glUseProgram(last_program)
// Setup viewport, orthographic projection matrix
- // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayMin is (0,0) for single viewport apps.
+ // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
@@ -132,9 +119,34 @@ void ImGui_ImplOpenGL2_RenderDrawData(ImDrawData* draw_data)
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
+}
+
+// OpenGL2 Render function.
+// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
+// Note that this implementation is little overcomplicated because we are saving/setting up/restoring every OpenGL state explicitly, in order to be able to run within any OpenGL engine that doesn't do so.
+void ImGui_ImplOpenGL2_RenderDrawData(ImDrawData* draw_data)
+{
+ // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
+ int fb_width = (int)(draw_data->DisplaySize.x * draw_data->FramebufferScale.x);
+ int fb_height = (int)(draw_data->DisplaySize.y * draw_data->FramebufferScale.y);
+ if (fb_width == 0 || fb_height == 0)
+ return;
+
+ // Backup GL state
+ GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
+ GLint last_polygon_mode[2]; glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode);
+ GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport);
+ GLint last_scissor_box[4]; glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box);
+ glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT);
+
+ // Setup desired GL state
+ ImGui_ImplOpenGL2_SetupRenderState(draw_data, fb_width, fb_height);
+
+ // Will project scissor/clipping rectangles into framebuffer space
+ ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports
+ ImVec2 clip_scale = draw_data->FramebufferScale; // (1,1) unless using retina display which are often (2,2)
// Render command lists
- ImVec2 pos = draw_data->DisplayPos;
for (int n = 0; n < draw_data->CmdListsCount; n++)
{
const ImDrawList* cmd_list = draw_data->CmdLists[n];
@@ -149,12 +161,22 @@ void ImGui_ImplOpenGL2_RenderDrawData(ImDrawData* draw_data)
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
if (pcmd->UserCallback)
{
- // User callback (registered via ImDrawList::AddCallback)
- pcmd->UserCallback(cmd_list, pcmd);
+ // User callback, registered via ImDrawList::AddCallback()
+ // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
+ if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
+ ImGui_ImplOpenGL2_SetupRenderState(draw_data, fb_width, fb_height);
+ else
+ pcmd->UserCallback(cmd_list, pcmd);
}
else
{
- ImVec4 clip_rect = ImVec4(pcmd->ClipRect.x - pos.x, pcmd->ClipRect.y - pos.y, pcmd->ClipRect.z - pos.x, pcmd->ClipRect.w - pos.y);
+ // Project scissor/clipping rectangles into framebuffer space
+ ImVec4 clip_rect;
+ clip_rect.x = (pcmd->ClipRect.x - clip_off.x) * clip_scale.x;
+ clip_rect.y = (pcmd->ClipRect.y - clip_off.y) * clip_scale.y;
+ clip_rect.z = (pcmd->ClipRect.z - clip_off.x) * clip_scale.x;
+ clip_rect.w = (pcmd->ClipRect.w - clip_off.y) * clip_scale.y;
+
if (clip_rect.x < fb_width && clip_rect.y < fb_height && clip_rect.z >= 0.0f && clip_rect.w >= 0.0f)
{
// Apply scissor/clipping rectangle
@@ -169,7 +191,7 @@ void ImGui_ImplOpenGL2_RenderDrawData(ImDrawData* draw_data)
}
}
- // Restore modified state
+ // Restore modified GL state
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp
index 4459c215..e8202705 100644
--- a/examples/imgui_impl_opengl3.cpp
+++ b/examples/imgui_impl_opengl3.cpp
@@ -1,10 +1,12 @@
-// dear imgui: Renderer for OpenGL3 / OpenGL ES2 / OpenGL ES3 (modern OpenGL with shaders / programmatic pipeline)
+// dear imgui: Renderer for modern OpenGL with shaders / programmatic pipeline
+// - Desktop GL: 3.x 4.x
+// - Embedded GL: ES 2.0 (WebGL 1.0), ES 3.0 (WebGL 2.0)
// This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..)
-// (Note: We are using GL3W as a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc..)
// Implemented features:
// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
// [X] Renderer: Multi-viewport support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
+// [x] Renderer: Desktop GL only: Support for large meshes (64k+ vertices) with 16-bits indices.
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
// If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
@@ -12,9 +14,17 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
-// 2018-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
+// 2019-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
+// 2019-05-29: OpenGL: Desktop GL only: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag.
+// 2019-04-30: OpenGL: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
+// 2019-03-29: OpenGL: Not calling glBindBuffer more than necessary in the render loop.
+// 2019-03-15: OpenGL: Added a dummy GL call + comments in ImGui_ImplOpenGL3_Init() to detect uninitialized GL function loaders early.
+// 2019-03-03: OpenGL: Fix support for ES 2.0 (WebGL 1.0).
+// 2019-02-20: OpenGL: Fix for OSX not supporting OpenGL 4.5, we don't try to read GL_CLIP_ORIGIN even if defined by the headers/loader.
+// 2019-02-11: OpenGL: Projecting clipping rectangles correctly using draw_data->FramebufferScale to allow multi-viewports for retina display.
+// 2019-02-01: OpenGL: Using GLSL 410 shaders for any version over 410 (e.g. 430, 450).
// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
-// 2018-11-13: OpenGL: Support for GL 4.5's glClipControl(GL_UPPER_LEFT).
+// 2018-11-13: OpenGL: Support for GL 4.5's glClipControl(GL_UPPER_LEFT) / GL_CLIP_ORIGIN.
// 2018-08-29: OpenGL: Added support for more OpenGL loaders: glew and glad, with comments indicative that any loader can be used.
// 2018-08-09: OpenGL: Default to OpenGL ES 3 on iOS and Android. GLSL version default to "#version 300 ES".
// 2018-07-30: OpenGL: Support for GLSL 300 ES and 410 core. Fixes for Emscripten compilation.
@@ -38,17 +48,17 @@
// version version string
//----------------------------------------
// 2.0 110 "#version 110"
-// 2.1 120
-// 3.0 130
-// 3.1 140
+// 2.1 120 "#version 120"
+// 3.0 130 "#version 130"
+// 3.1 140 "#version 140"
// 3.2 150 "#version 150"
-// 3.3 330
-// 4.0 400
+// 3.3 330 "#version 330 core"
+// 4.0 400 "#version 400 core"
// 4.1 410 "#version 410 core"
-// 4.2 420
-// 4.3 430
-// ES 2.0 100 "#version 100"
-// ES 3.0 300 "#version 300 es"
+// 4.2 420 "#version 410 core"
+// 4.3 430 "#version 430 core"
+// ES 2.0 100 "#version 100" = WebGL 1.0
+// ES 3.0 300 "#version 300 es" = WebGL 2.0
//----------------------------------------
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
@@ -67,37 +77,52 @@
#include "TargetConditionals.h"
#endif
-// iOS, Android and Emscripten can use GL ES 3
-// Call ImGui_ImplOpenGL3_Init() with "#version 300 es"
-#if (defined(__APPLE__) && TARGET_OS_IOS) || (defined(__ANDROID__)) || (defined(__EMSCRIPTEN__))
-#define USE_GL_ES3
+// Auto-detect GL version
+#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3)
+#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__))
+#define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es"
+#elif defined(__EMSCRIPTEN__)
+#define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100"
+#endif
#endif
-#ifdef USE_GL_ES3
-// OpenGL ES 3
+#if defined(IMGUI_IMPL_OPENGL_ES2)
+#include
+#elif defined(IMGUI_IMPL_OPENGL_ES3)
+#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV))
+#include // Use GL ES 3
+#else
#include // Use GL ES 3
+#endif
#else
-// Regular OpenGL
-// About OpenGL function loaders: modern OpenGL doesn't have a standard header file and requires individual function pointers to be loaded manually.
-// Helper libraries are often used for this purpose! Here we are supporting a few common ones: gl3w, glew, glad.
-// You may use another loader/header of your choice (glext, glLoadGen, etc.), or chose to manually implement your own.
+// About Desktop OpenGL function loaders:
+// Modern desktop OpenGL doesn't have a standard portable header file to load OpenGL function pointers.
+// Helper libraries are often used for this purpose! Here we are supporting a few common ones (gl3w, glew, glad).
+// You may use another loader/header of your choice (glext, glLoadGen, etc.), or chose to manually implement your own.
#if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
-#include
+#include // Needs to be initialized with gl3wInit() in user's code
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
-#include
+#include // Needs to be initialized with glewInit() in user's code
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
-#include
+#include // Needs to be initialized with gladLoadGL() in user's code
#else
#include IMGUI_IMPL_OPENGL_LOADER_CUSTOM
#endif
#endif
+// Desktop GL has glDrawElementsBaseVertex() which GL ES and WebGL don't have.
+#if defined(IMGUI_IMPL_OPENGL_ES2) || defined(IMGUI_IMPL_OPENGL_ES3)
+#define IMGUI_IMPL_OPENGL_HAS_DRAW_WITH_BASE_VERTEX 0
+#else
+#define IMGUI_IMPL_OPENGL_HAS_DRAW_WITH_BASE_VERTEX 1
+#endif
+
// OpenGL Data
static char g_GlslVersionString[32] = "";
static GLuint g_FontTexture = 0;
static GLuint g_ShaderHandle = 0, g_VertHandle = 0, g_FragHandle = 0;
-static int g_AttribLocationTex = 0, g_AttribLocationProjMtx = 0;
-static int g_AttribLocationPosition = 0, g_AttribLocationUV = 0, g_AttribLocationColor = 0;
+static int g_AttribLocationTex = 0, g_AttribLocationProjMtx = 0; // Uniforms location
+static int g_AttribLocationVtxPos = 0, g_AttribLocationVtxUV = 0, g_AttribLocationVtxColor = 0; // Vertex attributes location
static unsigned int g_VboHandle = 0, g_ElementsHandle = 0;
// Forward Declarations
@@ -109,11 +134,17 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version)
{
// Setup back-end capabilities flags
ImGuiIO& io = ImGui::GetIO();
- io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
io.BackendRendererName = "imgui_impl_opengl3";
+#if IMGUI_IMPL_OPENGL_HAS_DRAW_WITH_BASE_VERTEX
+ io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
+#endif
+ io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
// Store GLSL version string so we can refer to it later in case we recreate shaders. Note: GLSL version is NOT the same as GL version. Leave this to NULL if unsure.
-#ifdef USE_GL_ES3
+#if defined(IMGUI_IMPL_OPENGL_ES2)
+ if (glsl_version == NULL)
+ glsl_version = "#version 100";
+#elif defined(IMGUI_IMPL_OPENGL_ES3)
if (glsl_version == NULL)
glsl_version = "#version 300 es";
#else
@@ -124,6 +155,12 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version)
strcpy(g_GlslVersionString, glsl_version);
strcat(g_GlslVersionString, "\n");
+ // Make a dummy GL call (we don't actually need the result)
+ // IF YOU GET A CRASH HERE: it probably means that you haven't initialized the OpenGL function loader used by this code.
+ // Desktop OpenGL 3/4 need a function loader. See the IMGUI_IMPL_OPENGL_LOADER_xxx explanation above.
+ GLint current_texture;
+ glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_texture);
+
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
ImGui_ImplOpenGL3_InitPlatformInterface();
@@ -142,18 +179,66 @@ void ImGui_ImplOpenGL3_NewFrame()
ImGui_ImplOpenGL3_CreateDeviceObjects();
}
+static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_width, int fb_height, GLuint vertex_array_object)
+{
+ // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, polygon fill
+ glEnable(GL_BLEND);
+ glBlendEquation(GL_FUNC_ADD);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glDisable(GL_CULL_FACE);
+ glDisable(GL_DEPTH_TEST);
+ glEnable(GL_SCISSOR_TEST);
+#ifdef GL_POLYGON_MODE
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+#endif
+
+ // Setup viewport, orthographic projection matrix
+ // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
+ glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height);
+ float L = draw_data->DisplayPos.x;
+ float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x;
+ float T = draw_data->DisplayPos.y;
+ float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y;
+ const float ortho_projection[4][4] =
+ {
+ { 2.0f/(R-L), 0.0f, 0.0f, 0.0f },
+ { 0.0f, 2.0f/(T-B), 0.0f, 0.0f },
+ { 0.0f, 0.0f, -1.0f, 0.0f },
+ { (R+L)/(L-R), (T+B)/(B-T), 0.0f, 1.0f },
+ };
+ glUseProgram(g_ShaderHandle);
+ glUniform1i(g_AttribLocationTex, 0);
+ glUniformMatrix4fv(g_AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]);
+#ifdef GL_SAMPLER_BINDING
+ glBindSampler(0, 0); // We use combined texture/sampler state. Applications using GL 3.3 may set that otherwise.
+#endif
+
+ (void)vertex_array_object;
+#ifndef IMGUI_IMPL_OPENGL_ES2
+ glBindVertexArray(vertex_array_object);
+#endif
+
+ // Bind vertex/index buffers and setup attributes for ImDrawVert
+ glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle);
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_ElementsHandle);
+ glEnableVertexAttribArray(g_AttribLocationVtxPos);
+ glEnableVertexAttribArray(g_AttribLocationVtxUV);
+ glEnableVertexAttribArray(g_AttribLocationVtxColor);
+ glVertexAttribPointer(g_AttribLocationVtxPos, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, pos));
+ glVertexAttribPointer(g_AttribLocationVtxUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, uv));
+ glVertexAttribPointer(g_AttribLocationVtxColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, col));
+}
+
// OpenGL3 Render function.
// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
// Note that this implementation is little overcomplicated because we are saving/setting up/restoring every OpenGL state explicitly, in order to be able to run within any OpenGL engine that doesn't do so.
void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
{
// Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
- ImGuiIO& io = ImGui::GetIO();
- int fb_width = (int)(draw_data->DisplaySize.x * io.DisplayFramebufferScale.x);
- int fb_height = (int)(draw_data->DisplaySize.y * io.DisplayFramebufferScale.y);
+ int fb_width = (int)(draw_data->DisplaySize.x * draw_data->FramebufferScale.x);
+ int fb_height = (int)(draw_data->DisplaySize.y * draw_data->FramebufferScale.y);
if (fb_width <= 0 || fb_height <= 0)
return;
- draw_data->ScaleClipRects(io.DisplayFramebufferScale);
// Backup GL state
GLenum last_active_texture; glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint*)&last_active_texture);
@@ -164,7 +249,9 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
GLint last_sampler; glGetIntegerv(GL_SAMPLER_BINDING, &last_sampler);
#endif
GLint last_array_buffer; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer);
- GLint last_vertex_array; glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array);
+#ifndef IMGUI_IMPL_OPENGL_ES2
+ GLint last_vertex_array_object; glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array_object);
+#endif
#ifdef GL_POLYGON_MODE
GLint last_polygon_mode[2]; glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode);
#endif
@@ -181,97 +268,79 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
GLboolean last_enable_depth_test = glIsEnabled(GL_DEPTH_TEST);
GLboolean last_enable_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
bool clip_origin_lower_left = true;
-#ifdef GL_CLIP_ORIGIN
+#if defined(GL_CLIP_ORIGIN) && !defined(__APPLE__)
GLenum last_clip_origin = 0; glGetIntegerv(GL_CLIP_ORIGIN, (GLint*)&last_clip_origin); // Support for GL 4.5's glClipControl(GL_UPPER_LEFT)
if (last_clip_origin == GL_UPPER_LEFT)
clip_origin_lower_left = false;
#endif
- // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, polygon fill
- glEnable(GL_BLEND);
- glBlendEquation(GL_FUNC_ADD);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glDisable(GL_CULL_FACE);
- glDisable(GL_DEPTH_TEST);
- glEnable(GL_SCISSOR_TEST);
-#ifdef GL_POLYGON_MODE
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+ // Setup desired GL state
+ // Recreate the VAO every time (this is to easily allow multiple GL contexts to be rendered to. VAO are not shared among GL contexts)
+ // The renderer would actually work without any VAO bound, but then our VertexAttrib calls would overwrite the default one currently bound.
+ GLuint vertex_array_object = 0;
+#ifndef IMGUI_IMPL_OPENGL_ES2
+ glGenVertexArrays(1, &vertex_array_object);
#endif
+ ImGui_ImplOpenGL3_SetupRenderState(draw_data, fb_width, fb_height, vertex_array_object);
- // Setup viewport, orthographic projection matrix
- // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayMin is (0,0) for single viewport apps.
- glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height);
- float L = draw_data->DisplayPos.x;
- float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x;
- float T = draw_data->DisplayPos.y;
- float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y;
- const float ortho_projection[4][4] =
- {
- { 2.0f/(R-L), 0.0f, 0.0f, 0.0f },
- { 0.0f, 2.0f/(T-B), 0.0f, 0.0f },
- { 0.0f, 0.0f, -1.0f, 0.0f },
- { (R+L)/(L-R), (T+B)/(B-T), 0.0f, 1.0f },
- };
- glUseProgram(g_ShaderHandle);
- glUniform1i(g_AttribLocationTex, 0);
- glUniformMatrix4fv(g_AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]);
-#ifdef GL_SAMPLER_BINDING
- glBindSampler(0, 0); // We use combined texture/sampler state. Applications using GL 3.3 may set that otherwise.
-#endif
- // Recreate the VAO every time
- // (This is to easily allow multiple GL contexts. VAO are not shared among GL contexts, and we don't track creation/deletion of windows so we don't have an obvious key to use to cache them.)
- GLuint vao_handle = 0;
- glGenVertexArrays(1, &vao_handle);
- glBindVertexArray(vao_handle);
- glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle);
- glEnableVertexAttribArray(g_AttribLocationPosition);
- glEnableVertexAttribArray(g_AttribLocationUV);
- glEnableVertexAttribArray(g_AttribLocationColor);
- glVertexAttribPointer(g_AttribLocationPosition, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, pos));
- glVertexAttribPointer(g_AttribLocationUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, uv));
- glVertexAttribPointer(g_AttribLocationColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, col));
-
- // Draw
- ImVec2 pos = draw_data->DisplayPos;
+ // Will project scissor/clipping rectangles into framebuffer space
+ ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports
+ ImVec2 clip_scale = draw_data->FramebufferScale; // (1,1) unless using retina display which are often (2,2)
+
+ // Render command lists
for (int n = 0; n < draw_data->CmdListsCount; n++)
{
const ImDrawList* cmd_list = draw_data->CmdLists[n];
- const ImDrawIdx* idx_buffer_offset = 0;
- glBindBuffer(GL_ARRAY_BUFFER, g_VboHandle);
+ // Upload vertex/index buffers
glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)cmd_list->VtxBuffer.Size * sizeof(ImDrawVert), (const GLvoid*)cmd_list->VtxBuffer.Data, GL_STREAM_DRAW);
-
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_ElementsHandle);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx), (const GLvoid*)cmd_list->IdxBuffer.Data, GL_STREAM_DRAW);
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
{
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
- if (pcmd->UserCallback)
+ if (pcmd->UserCallback != NULL)
{
- // User callback (registered via ImDrawList::AddCallback)
- pcmd->UserCallback(cmd_list, pcmd);
+ // User callback, registered via ImDrawList::AddCallback()
+ // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
+ if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
+ ImGui_ImplOpenGL3_SetupRenderState(draw_data, fb_width, fb_height, vertex_array_object);
+ else
+ pcmd->UserCallback(cmd_list, pcmd);
}
else
{
- ImVec4 clip_rect = ImVec4(pcmd->ClipRect.x - pos.x, pcmd->ClipRect.y - pos.y, pcmd->ClipRect.z - pos.x, pcmd->ClipRect.w - pos.y);
+ // Project scissor/clipping rectangles into framebuffer space
+ ImVec4 clip_rect;
+ clip_rect.x = (pcmd->ClipRect.x - clip_off.x) * clip_scale.x;
+ clip_rect.y = (pcmd->ClipRect.y - clip_off.y) * clip_scale.y;
+ clip_rect.z = (pcmd->ClipRect.z - clip_off.x) * clip_scale.x;
+ clip_rect.w = (pcmd->ClipRect.w - clip_off.y) * clip_scale.y;
+
if (clip_rect.x < fb_width && clip_rect.y < fb_height && clip_rect.z >= 0.0f && clip_rect.w >= 0.0f)
{
// Apply scissor/clipping rectangle
if (clip_origin_lower_left)
glScissor((int)clip_rect.x, (int)(fb_height - clip_rect.w), (int)(clip_rect.z - clip_rect.x), (int)(clip_rect.w - clip_rect.y));
else
- glScissor((int)clip_rect.x, (int)clip_rect.y, (int)clip_rect.z, (int)clip_rect.w); // Support for GL 4.5's glClipControl(GL_UPPER_LEFT)
+ glScissor((int)clip_rect.x, (int)clip_rect.y, (int)clip_rect.z, (int)clip_rect.w); // Support for GL 4.5 rarely used glClipControl(GL_UPPER_LEFT)
// Bind texture, Draw
glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId);
- glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset);
+#if IMGUI_IMPL_OPENGL_HAS_DRAW_WITH_BASE_VERTEX
+ glDrawElementsBaseVertex(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx)), (GLint)pcmd->VtxOffset);
+#else
+ glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx)));
+#endif
}
}
- idx_buffer_offset += pcmd->ElemCount;
}
}
- glDeleteVertexArrays(1, &vao_handle);
+
+ // Destroy the temporary VAO
+#ifndef IMGUI_IMPL_OPENGL_ES2
+ glDeleteVertexArrays(1, &vertex_array_object);
+#endif
// Restore modified GL state
glUseProgram(last_program);
@@ -280,7 +349,9 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data)
glBindSampler(0, last_sampler);
#endif
glActiveTexture(last_active_texture);
- glBindVertexArray(last_vertex_array);
+#ifndef IMGUI_IMPL_OPENGL_ES2
+ glBindVertexArray(last_vertex_array_object);
+#endif
glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
glBlendEquationSeparate(last_blend_equation_rgb, last_blend_equation_alpha);
glBlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha);
@@ -310,7 +381,9 @@ bool ImGui_ImplOpenGL3_CreateFontsTexture()
glBindTexture(GL_TEXTURE_2D, g_FontTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+#ifdef GL_UNPACK_ROW_LENGTH
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
+#endif
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
// Store our identifier
@@ -341,7 +414,7 @@ static bool CheckShader(GLuint handle, const char* desc)
glGetShaderiv(handle, GL_INFO_LOG_LENGTH, &log_length);
if ((GLboolean)status == GL_FALSE)
fprintf(stderr, "ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to compile %s!\n", desc);
- if (log_length > 0)
+ if (log_length > 1)
{
ImVector buf;
buf.resize((int)(log_length + 1));
@@ -359,7 +432,7 @@ static bool CheckProgram(GLuint handle, const char* desc)
glGetProgramiv(handle, GL_INFO_LOG_LENGTH, &log_length);
if ((GLboolean)status == GL_FALSE)
fprintf(stderr, "ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to link %s! (with GLSL '%s')\n", desc, g_GlslVersionString);
- if (log_length > 0)
+ if (log_length > 1)
{
ImVector buf;
buf.resize((int)(log_length + 1));
@@ -372,10 +445,13 @@ static bool CheckProgram(GLuint handle, const char* desc)
bool ImGui_ImplOpenGL3_CreateDeviceObjects()
{
// Backup GL state
- GLint last_texture, last_array_buffer, last_vertex_array;
+ GLint last_texture, last_array_buffer;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture);
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer);
+#ifndef IMGUI_IMPL_OPENGL_ES2
+ GLint last_vertex_array;
glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array);
+#endif
// Parse GLSL version string
int glsl_version = 130;
@@ -489,7 +565,7 @@ bool ImGui_ImplOpenGL3_CreateDeviceObjects()
vertex_shader = vertex_shader_glsl_120;
fragment_shader = fragment_shader_glsl_120;
}
- else if (glsl_version == 410)
+ else if (glsl_version >= 410)
{
vertex_shader = vertex_shader_glsl_410_core;
fragment_shader = fragment_shader_glsl_410_core;
@@ -526,9 +602,9 @@ bool ImGui_ImplOpenGL3_CreateDeviceObjects()
g_AttribLocationTex = glGetUniformLocation(g_ShaderHandle, "Texture");
g_AttribLocationProjMtx = glGetUniformLocation(g_ShaderHandle, "ProjMtx");
- g_AttribLocationPosition = glGetAttribLocation(g_ShaderHandle, "Position");
- g_AttribLocationUV = glGetAttribLocation(g_ShaderHandle, "UV");
- g_AttribLocationColor = glGetAttribLocation(g_ShaderHandle, "Color");
+ g_AttribLocationVtxPos = glGetAttribLocation(g_ShaderHandle, "Position");
+ g_AttribLocationVtxUV = glGetAttribLocation(g_ShaderHandle, "UV");
+ g_AttribLocationVtxColor = glGetAttribLocation(g_ShaderHandle, "Color");
// Create buffers
glGenBuffers(1, &g_VboHandle);
@@ -539,7 +615,9 @@ bool ImGui_ImplOpenGL3_CreateDeviceObjects()
// Restore modified GL state
glBindTexture(GL_TEXTURE_2D, last_texture);
glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer);
+#ifndef IMGUI_IMPL_OPENGL_ES2
glBindVertexArray(last_vertex_array);
+#endif
return true;
}
diff --git a/examples/imgui_impl_opengl3.h b/examples/imgui_impl_opengl3.h
index e7ee13ac..00901ac4 100644
--- a/examples/imgui_impl_opengl3.h
+++ b/examples/imgui_impl_opengl3.h
@@ -1,28 +1,34 @@
-// dear imgui: Renderer for OpenGL3 / OpenGL ES2 / OpenGL ES3 (modern OpenGL with shaders / programmatic pipeline)
+// dear imgui: Renderer for modern OpenGL with shaders / programmatic pipeline
+// - Desktop GL: 3.x 4.x
+// - Embedded GL: ES 2.0 (WebGL 1.0), ES 3.0 (WebGL 2.0)
// This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..)
-// (Note: We are using GL3W as a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc..)
// Implemented features:
// [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp.
// [X] Renderer: Multi-viewport support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
+// [x] Renderer: Desktop GL only: Support for large meshes (64k+ vertices) with 16-bits indices.
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
// If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
// https://github.com/ocornut/imgui
-// About OpenGL function loaders:
-// About OpenGL function loaders: modern OpenGL doesn't have a standard header file and requires individual function pointers to be loaded manually.
-// Helper libraries are often used for this purpose! Here we are supporting a few common ones: gl3w, glew, glad.
-// You may use another loader/header of your choice (glext, glLoadGen, etc.), or chose to manually implement your own.
+// About Desktop OpenGL function loaders:
+// Modern desktop OpenGL doesn't have a standard portable header file to load OpenGL function pointers.
+// Helper libraries are often used for this purpose! Here we are supporting a few common ones (gl3w, glew, glad).
+// You may use another loader/header of your choice (glext, glLoadGen, etc.), or chose to manually implement your own.
// About GLSL version:
-// The 'glsl_version' initialization parameter should be NULL (default) or a "#version XXX" string.
-// On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es"
-// Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp.
+// The 'glsl_version' initialization parameter should be NULL (default) or a "#version XXX" string.
+// On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es"
+// Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp.
#pragma once
-// Set default OpenGL loader to be gl3w
+// Specific OpenGL versions
+//#define IMGUI_IMPL_OPENGL_ES2 // Auto-detected on Emscripten
+//#define IMGUI_IMPL_OPENGL_ES3 // Auto-detected on iOS/Android
+
+// Set default OpenGL3 loader to be gl3w
#if !defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) \
&& !defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) \
&& !defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) \
diff --git a/examples/imgui_impl_osx.h b/examples/imgui_impl_osx.h
index 0947025c..54e86157 100644
--- a/examples/imgui_impl_osx.h
+++ b/examples/imgui_impl_osx.h
@@ -1,10 +1,12 @@
// dear imgui: Platform Binding for OSX / Cocoa
// This needs to be used along with a Renderer (e.g. OpenGL2, OpenGL3, Vulkan, Metal..)
-// [BETA] Beta bindings, not well tested. If you want a portable application, prefer using the Glfw or SDL platform bindings on Mac.
+// [ALPHA] Early bindings, not well tested. If you want a portable application, prefer using the GLFW or SDL platform bindings on Mac.
+// Implemented features:
+// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
+// [X] Platform: OSX clipboard is supported within core Dear ImGui (no specific code in this back-end).
// Issues:
// [ ] Platform: Keys are all generally very broken. Best using [event keycode] and not [event characters]..
-// [ ] Platform: Mouse cursor shapes and visibility are not supported (see end of https://github.com/glfw/glfw/issues/427)
// [ ] Platform: Multi-viewport / platform windows.
@class NSEvent;
diff --git a/examples/imgui_impl_osx.mm b/examples/imgui_impl_osx.mm
index e5a027b8..ab667d98 100644
--- a/examples/imgui_impl_osx.mm
+++ b/examples/imgui_impl_osx.mm
@@ -1,10 +1,12 @@
// dear imgui: Platform Binding for OSX / Cocoa
// This needs to be used along with a Renderer (e.g. OpenGL2, OpenGL3, Vulkan, Metal..)
-// [BETA] Beta bindings, not well tested. If you want a portable application, prefer using the Glfw or SDL platform bindings on Mac.
+// [ALPHA] Early bindings, not well tested. If you want a portable application, prefer using the GLFW or SDL platform bindings on Mac.
+// Implemented features:
+// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
+// [X] Platform: OSX clipboard is supported within core Dear ImGui (no specific code in this back-end).
// Issues:
// [ ] Platform: Keys are all generally very broken. Best using [event keycode] and not [event characters]..
-// [ ] Platform: Mouse cursor shapes and visibility are not supported (see end of https://github.com/glfw/glfw/issues/427)
// [ ] Platform: Multi-viewport / platform windows.
#include "imgui.h"
@@ -13,11 +15,25 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
+// 2019-07-21: Readded clipboard handlers as they are not enabled by default in core imgui.cpp (reverted 2019-05-18 change).
+// 2019-05-28: Inputs: Added mouse cursor shape and visibility support.
+// 2019-05-18: Misc: Removed clipboard handlers as they are now supported by core imgui.cpp.
+// 2019-05-11: Inputs: Don't filter character values before calling AddInputCharacter() apart from 0xF700..0xFFFF range.
// 2018-11-30: Misc: Setting up io.BackendPlatformName so it can be displayed in the About Window.
// 2018-07-07: Initial version.
// Data
static CFAbsoluteTime g_Time = 0.0;
+static NSCursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = { 0 };
+static bool g_MouseCursorHidden = false;
+
+// Undocumented methods for creating cursors.
+@interface NSCursor()
++ (id)_windowResizeNorthWestSouthEastCursor;
++ (id)_windowResizeNorthEastSouthWestCursor;
++ (id)_windowResizeNorthSouthCursor;
++ (id)_windowResizeEastWestCursor;
+@end
// Functions
bool ImGui_ImplOSX_Init()
@@ -25,7 +41,7 @@ bool ImGui_ImplOSX_Init()
ImGuiIO& io = ImGui::GetIO();
// Setup back-end capabilities flags
- //io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
+ io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
//io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
//io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports; // We can create multi-viewports on the Platform side (optional)
//io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport; // We can set io.MouseHoveredViewport correctly (optional, not easy)
@@ -33,28 +49,43 @@ bool ImGui_ImplOSX_Init()
// Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array.
const int offset_for_function_keys = 256 - 0xF700;
- io.KeyMap[ImGuiKey_Tab] = '\t';
- io.KeyMap[ImGuiKey_LeftArrow] = NSLeftArrowFunctionKey + offset_for_function_keys;
- io.KeyMap[ImGuiKey_RightArrow] = NSRightArrowFunctionKey + offset_for_function_keys;
- io.KeyMap[ImGuiKey_UpArrow] = NSUpArrowFunctionKey + offset_for_function_keys;
- io.KeyMap[ImGuiKey_DownArrow] = NSDownArrowFunctionKey + offset_for_function_keys;
- io.KeyMap[ImGuiKey_PageUp] = NSPageUpFunctionKey + offset_for_function_keys;
- io.KeyMap[ImGuiKey_PageDown] = NSPageDownFunctionKey + offset_for_function_keys;
- io.KeyMap[ImGuiKey_Home] = NSHomeFunctionKey + offset_for_function_keys;
- io.KeyMap[ImGuiKey_End] = NSEndFunctionKey + offset_for_function_keys;
- io.KeyMap[ImGuiKey_Insert] = NSInsertFunctionKey + offset_for_function_keys;
- io.KeyMap[ImGuiKey_Delete] = NSDeleteFunctionKey + offset_for_function_keys;
- io.KeyMap[ImGuiKey_Backspace] = 127;
- io.KeyMap[ImGuiKey_Space] = 32;
- io.KeyMap[ImGuiKey_Enter] = 13;
- io.KeyMap[ImGuiKey_Escape] = 27;
- io.KeyMap[ImGuiKey_A] = 'A';
- io.KeyMap[ImGuiKey_C] = 'C';
- io.KeyMap[ImGuiKey_V] = 'V';
- io.KeyMap[ImGuiKey_X] = 'X';
- io.KeyMap[ImGuiKey_Y] = 'Y';
- io.KeyMap[ImGuiKey_Z] = 'Z';
+ io.KeyMap[ImGuiKey_Tab] = '\t';
+ io.KeyMap[ImGuiKey_LeftArrow] = NSLeftArrowFunctionKey + offset_for_function_keys;
+ io.KeyMap[ImGuiKey_RightArrow] = NSRightArrowFunctionKey + offset_for_function_keys;
+ io.KeyMap[ImGuiKey_UpArrow] = NSUpArrowFunctionKey + offset_for_function_keys;
+ io.KeyMap[ImGuiKey_DownArrow] = NSDownArrowFunctionKey + offset_for_function_keys;
+ io.KeyMap[ImGuiKey_PageUp] = NSPageUpFunctionKey + offset_for_function_keys;
+ io.KeyMap[ImGuiKey_PageDown] = NSPageDownFunctionKey + offset_for_function_keys;
+ io.KeyMap[ImGuiKey_Home] = NSHomeFunctionKey + offset_for_function_keys;
+ io.KeyMap[ImGuiKey_End] = NSEndFunctionKey + offset_for_function_keys;
+ io.KeyMap[ImGuiKey_Insert] = NSInsertFunctionKey + offset_for_function_keys;
+ io.KeyMap[ImGuiKey_Delete] = NSDeleteFunctionKey + offset_for_function_keys;
+ io.KeyMap[ImGuiKey_Backspace] = 127;
+ io.KeyMap[ImGuiKey_Space] = 32;
+ io.KeyMap[ImGuiKey_Enter] = 13;
+ io.KeyMap[ImGuiKey_Escape] = 27;
+ io.KeyMap[ImGuiKey_KeyPadEnter] = 13;
+ io.KeyMap[ImGuiKey_A] = 'A';
+ io.KeyMap[ImGuiKey_C] = 'C';
+ io.KeyMap[ImGuiKey_V] = 'V';
+ io.KeyMap[ImGuiKey_X] = 'X';
+ io.KeyMap[ImGuiKey_Y] = 'Y';
+ io.KeyMap[ImGuiKey_Z] = 'Z';
+
+ // Load cursors. Some of them are undocumented.
+ g_MouseCursorHidden = false;
+ g_MouseCursors[ImGuiMouseCursor_Arrow] = [NSCursor arrowCursor];
+ g_MouseCursors[ImGuiMouseCursor_TextInput] = [NSCursor IBeamCursor];
+ g_MouseCursors[ImGuiMouseCursor_ResizeAll] = [NSCursor closedHandCursor];
+ g_MouseCursors[ImGuiMouseCursor_Hand] = [NSCursor pointingHandCursor];
+ g_MouseCursors[ImGuiMouseCursor_ResizeNS] = [NSCursor respondsToSelector:@selector(_windowResizeNorthSouthCursor)] ? [NSCursor _windowResizeNorthSouthCursor] : [NSCursor resizeUpDownCursor];
+ g_MouseCursors[ImGuiMouseCursor_ResizeEW] = [NSCursor respondsToSelector:@selector(_windowResizeEastWestCursor)] ? [NSCursor _windowResizeEastWestCursor] : [NSCursor resizeLeftRightCursor];
+ g_MouseCursors[ImGuiMouseCursor_ResizeNESW] = [NSCursor respondsToSelector:@selector(_windowResizeNorthEastSouthWestCursor)] ? [NSCursor _windowResizeNorthEastSouthWestCursor] : [NSCursor closedHandCursor];
+ g_MouseCursors[ImGuiMouseCursor_ResizeNWSE] = [NSCursor respondsToSelector:@selector(_windowResizeNorthWestSouthEastCursor)] ? [NSCursor _windowResizeNorthWestSouthEastCursor] : [NSCursor closedHandCursor];
+ // Note that imgui.cpp also include default OSX clipboard handlers which can be enabled
+ // by adding '#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS' in imconfig.h and adding '-framework ApplicationServices' to your linker command-line.
+ // Since we are already in ObjC land here, it is easy for us to add a clipboard handler using the NSPasteboard api.
io.SetClipboardTextFn = [](void*, const char* str) -> void
{
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
@@ -88,6 +119,34 @@ void ImGui_ImplOSX_Shutdown()
{
}
+static void ImGui_ImplOSX_UpdateMouseCursor()
+{
+ ImGuiIO& io = ImGui::GetIO();
+ if (io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange)
+ return;
+
+ ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor();
+ if (io.MouseDrawCursor || imgui_cursor == ImGuiMouseCursor_None)
+ {
+ // Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
+ if (!g_MouseCursorHidden)
+ {
+ g_MouseCursorHidden = true;
+ [NSCursor hide];
+ }
+ }
+ else
+ {
+ // Show OS mouse cursor
+ [g_MouseCursors[g_MouseCursors[imgui_cursor] ? imgui_cursor : ImGuiMouseCursor_Arrow] set];
+ if (g_MouseCursorHidden)
+ {
+ g_MouseCursorHidden = false;
+ [NSCursor unhide];
+ }
+ }
+}
+
void ImGui_ImplOSX_NewFrame(NSView* view)
{
// Setup display size
@@ -102,6 +161,8 @@ void ImGui_ImplOSX_NewFrame(NSView* view)
CFAbsoluteTime current_time = CFAbsoluteTimeGetCurrent();
io.DeltaTime = current_time - g_Time;
g_Time = current_time;
+
+ ImGui_ImplOSX_UpdateMouseCursor();
}
static int mapCharacterToKey(int c)
@@ -190,8 +251,8 @@ bool ImGui_ImplOSX_HandleEvent(NSEvent* event, NSView* view)
for (int i = 0; i < len; i++)
{
int c = [str characterAtIndex:i];
- if (c < 0xF700 && !io.KeyCtrl)
- io.AddInputCharacter((unsigned short)c);
+ if (!io.KeyCtrl && !(c >= 0xF700 && c <= 0xFFFF))
+ io.AddInputCharacter((unsigned int)c);
// We must reset in case we're pressing a sequence of special keys while keeping the command pressed
int key = mapCharacterToKey(c);
diff --git a/examples/imgui_impl_sdl.cpp b/examples/imgui_impl_sdl.cpp
index e1c505f5..a42de2c2 100644
--- a/examples/imgui_impl_sdl.cpp
+++ b/examples/imgui_impl_sdl.cpp
@@ -7,10 +7,10 @@
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
// [X] Platform: Clipboard support.
// [X] Platform: Keyboard arrays indexed using SDL_SCANCODE_* codes, e.g. ImGui::IsKeyPressed(SDL_SCANCODE_SPACE).
+// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
// [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
// Missing features:
// [ ] Platform: SDL2 handling of IME under Windows appears to be broken and it explicitly disable the regular Windows IME. You can restore Windows IME by compiling SDL with SDL_DISABLE_WINDOWS_IME.
-// [ ] Platform: Gamepad support (need to use SDL_GameController API to fill the io.NavInputs[] value when ImGuiConfigFlags_NavEnableGamepad is set).
// [ ] Platform: Multi-viewport + Minimized windows seems to break mouse wheel events (at least under Windows).
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
@@ -19,7 +19,10 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
-// 2018-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
+// 2019-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
+// 2019-07-21: Inputs: Added mapping for ImGuiKey_KeyPadEnter.
+// 2019-04-23: Inputs: Added support for SDL_GameController (if ImGuiConfigFlags_NavEnableGamepad is set by user application).
+// 2019-03-12: Misc: Preserve DisplayFramebufferScale when main window is minimized.
// 2018-12-21: Inputs: Workaround for Android/iOS which don't seem to handle focus related calls.
// 2018-11-30: Misc: Setting up io.BackendPlatformName so it can be displayed in the About Window.
// 2018-11-14: Changed the signature of ImGui_ImplSDL2_ProcessEvent() to take a 'const SDL_Event*'.
@@ -175,6 +178,7 @@ static bool ImGui_ImplSDL2_Init(SDL_Window* window, void* sdl_gl_context)
io.KeyMap[ImGuiKey_Space] = SDL_SCANCODE_SPACE;
io.KeyMap[ImGuiKey_Enter] = SDL_SCANCODE_RETURN;
io.KeyMap[ImGuiKey_Escape] = SDL_SCANCODE_ESCAPE;
+ io.KeyMap[ImGuiKey_KeyPadEnter] = SDL_SCANCODE_RETURN2;
io.KeyMap[ImGuiKey_A] = SDL_SCANCODE_A;
io.KeyMap[ImGuiKey_C] = SDL_SCANCODE_C;
io.KeyMap[ImGuiKey_V] = SDL_SCANCODE_V;
@@ -198,6 +202,12 @@ static bool ImGui_ImplSDL2_Init(SDL_Window* window, void* sdl_gl_context)
// Our mouse update function expect PlatformHandle to be filled for the main viewport
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
main_viewport->PlatformHandle = (void*)window;
+#if defined(_WIN32)
+ SDL_SysWMinfo info;
+ SDL_VERSION(&info.version);
+ if (SDL_GetWindowWMInfo(window, &info))
+ main_viewport->PlatformHandleRaw = info.info.win.window;
+#endif
// We need SDL_CaptureMouse(), SDL_GetGlobalMouseState() from SDL 2.0.4+ to support multiple viewports.
// We left the call to ImGui_ImplSDL2_InitPlatformInterface() outside of #ifdef to avoid unused-function warnings.
@@ -221,6 +231,14 @@ bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window)
return ImGui_ImplSDL2_Init(window, NULL);
}
+bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window)
+{
+#if !defined(_WIN32)
+ IM_ASSERT(0 && "Unsupported");
+#endif
+ return ImGui_ImplSDL2_Init(window, NULL);
+}
+
void ImGui_ImplSDL2_Shutdown()
{
ImGui_ImplSDL2_ShutdownPlatformInterface();
@@ -269,13 +287,12 @@ static void ImGui_ImplSDL2_UpdateMousePosAndButtons()
io.MouseDown[2] = g_MousePressed[2] || (mouse_buttons & SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0;
g_MousePressed[0] = g_MousePressed[1] = g_MousePressed[2] = false;
-#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
+#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE && !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !(defined(__APPLE__) && TARGET_OS_IOS)
// SDL 2.0.4 and later has SDL_GetGlobalMouseState() and SDL_CaptureMouse()
int mouse_x_global, mouse_y_global;
SDL_GetGlobalMouseState(&mouse_x_global, &mouse_y_global);
-#if !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !(defined(__APPLE__) && TARGET_OS_IOS)
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
// Multi-viewport mode: mouse position in OS absolute coordinates (io.MousePos is (0,0) when the mouse is on the upper-left of the primary monitor)
@@ -284,7 +301,6 @@ static void ImGui_ImplSDL2_UpdateMousePosAndButtons()
io.MousePos = ImVec2((float)mouse_x_global, (float)mouse_y_global);
}
else
-#endif
{
// Single-viewport mode: mouse position in client window coordinatesio.MousePos is (0,0) when the mouse is on the upper-left corner of the app window)
if (SDL_GetWindowFlags(g_Window) & SDL_WINDOW_INPUT_FOCUS)
@@ -326,6 +342,47 @@ static void ImGui_ImplSDL2_UpdateMouseCursor()
}
}
+static void ImGui_ImplSDL2_UpdateGamepads()
+{
+ ImGuiIO& io = ImGui::GetIO();
+ memset(io.NavInputs, 0, sizeof(io.NavInputs));
+ if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0)
+ return;
+
+ // Get gamepad
+ SDL_GameController* game_controller = SDL_GameControllerOpen(0);
+ if (!game_controller)
+ {
+ io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
+ return;
+ }
+
+ // Update gamepad inputs
+ #define MAP_BUTTON(NAV_NO, BUTTON_NO) { io.NavInputs[NAV_NO] = (SDL_GameControllerGetButton(game_controller, BUTTON_NO) != 0) ? 1.0f : 0.0f; }
+ #define MAP_ANALOG(NAV_NO, AXIS_NO, V0, V1) { float vn = (float)(SDL_GameControllerGetAxis(game_controller, AXIS_NO) - V0) / (float)(V1 - V0); if (vn > 1.0f) vn = 1.0f; if (vn > 0.0f && io.NavInputs[NAV_NO] < vn) io.NavInputs[NAV_NO] = vn; }
+ const int thumb_dead_zone = 8000; // SDL_gamecontroller.h suggests using this value.
+ MAP_BUTTON(ImGuiNavInput_Activate, SDL_CONTROLLER_BUTTON_A); // Cross / A
+ MAP_BUTTON(ImGuiNavInput_Cancel, SDL_CONTROLLER_BUTTON_B); // Circle / B
+ MAP_BUTTON(ImGuiNavInput_Menu, SDL_CONTROLLER_BUTTON_X); // Square / X
+ MAP_BUTTON(ImGuiNavInput_Input, SDL_CONTROLLER_BUTTON_Y); // Triangle / Y
+ MAP_BUTTON(ImGuiNavInput_DpadLeft, SDL_CONTROLLER_BUTTON_DPAD_LEFT); // D-Pad Left
+ MAP_BUTTON(ImGuiNavInput_DpadRight, SDL_CONTROLLER_BUTTON_DPAD_RIGHT); // D-Pad Right
+ MAP_BUTTON(ImGuiNavInput_DpadUp, SDL_CONTROLLER_BUTTON_DPAD_UP); // D-Pad Up
+ MAP_BUTTON(ImGuiNavInput_DpadDown, SDL_CONTROLLER_BUTTON_DPAD_DOWN); // D-Pad Down
+ MAP_BUTTON(ImGuiNavInput_FocusPrev, SDL_CONTROLLER_BUTTON_LEFTSHOULDER); // L1 / LB
+ MAP_BUTTON(ImGuiNavInput_FocusNext, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); // R1 / RB
+ MAP_BUTTON(ImGuiNavInput_TweakSlow, SDL_CONTROLLER_BUTTON_LEFTSHOULDER); // L1 / LB
+ MAP_BUTTON(ImGuiNavInput_TweakFast, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); // R1 / RB
+ MAP_ANALOG(ImGuiNavInput_LStickLeft, SDL_CONTROLLER_AXIS_LEFTX, -thumb_dead_zone, -32768);
+ MAP_ANALOG(ImGuiNavInput_LStickRight, SDL_CONTROLLER_AXIS_LEFTX, +thumb_dead_zone, +32767);
+ MAP_ANALOG(ImGuiNavInput_LStickUp, SDL_CONTROLLER_AXIS_LEFTY, -thumb_dead_zone, -32767);
+ MAP_ANALOG(ImGuiNavInput_LStickDown, SDL_CONTROLLER_AXIS_LEFTY, +thumb_dead_zone, +32767);
+
+ io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
+ #undef MAP_BUTTON
+ #undef MAP_ANALOG
+}
+
void ImGui_ImplSDL2_NewFrame(SDL_Window* window)
{
ImGuiIO& io = ImGui::GetIO();
@@ -337,7 +394,8 @@ void ImGui_ImplSDL2_NewFrame(SDL_Window* window)
SDL_GetWindowSize(window, &w, &h);
SDL_GL_GetDrawableSize(window, &display_w, &display_h);
io.DisplaySize = ImVec2((float)w, (float)h);
- io.DisplayFramebufferScale = ImVec2(w > 0 ? ((float)display_w / w) : 0, h > 0 ? ((float)display_h / h) : 0);
+ if (w > 0 && h > 0)
+ io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h);
// Setup time step (we don't use SDL_GetTicks() because it is using millisecond resolution)
static Uint64 frequency = SDL_GetPerformanceFrequency();
@@ -347,6 +405,9 @@ void ImGui_ImplSDL2_NewFrame(SDL_Window* window)
ImGui_ImplSDL2_UpdateMousePosAndButtons();
ImGui_ImplSDL2_UpdateMouseCursor();
+
+ // Update game controllers (if enabled and available)
+ ImGui_ImplSDL2_UpdateGamepads();
}
//--------------------------------------------------------------------------------------------------------
@@ -384,9 +445,9 @@ static void ImGui_ImplSDL2_CreateWindow(ImGuiViewport* viewport)
SDL_GL_MakeCurrent(main_viewport_data->Window, main_viewport_data->GLContext);
}
- // We don't enable SDL_WINDOW_RESIZABLE because it enforce windows decorations
Uint32 sdl_flags = 0;
sdl_flags |= use_opengl ? SDL_WINDOW_OPENGL : SDL_WINDOW_VULKAN;
+ sdl_flags |= SDL_GetWindowFlags(g_Window) & SDL_WINDOW_ALLOW_HIGHDPI;
sdl_flags |= SDL_WINDOW_HIDDEN;
sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoDecoration) ? SDL_WINDOW_BORDERLESS : 0;
sdl_flags |= (viewport->Flags & ImGuiViewportFlags_NoDecoration) ? 0 : SDL_WINDOW_RESIZABLE;
@@ -402,7 +463,14 @@ static void ImGui_ImplSDL2_CreateWindow(ImGuiViewport* viewport)
}
if (use_opengl && backup_context)
SDL_GL_MakeCurrent(data->Window, backup_context);
+
viewport->PlatformHandle = (void*)data->Window;
+#if defined(_WIN32)
+ SDL_SysWMinfo info;
+ SDL_VERSION(&info.version);
+ if (SDL_GetWindowWMInfo(data->Window, &info))
+ viewport->PlatformHandleRaw = info.info.win.window;
+#endif
}
static void ImGui_ImplSDL2_DestroyWindow(ImGuiViewport* viewport)
@@ -424,28 +492,23 @@ static void ImGui_ImplSDL2_ShowWindow(ImGuiViewport* viewport)
{
ImGuiViewportDataSDL2* data = (ImGuiViewportDataSDL2*)viewport->PlatformUserData;
#if defined(_WIN32)
- SDL_SysWMinfo info;
- SDL_VERSION(&info.version);
- if (SDL_GetWindowWMInfo(data->Window, &info))
- {
- HWND hwnd = info.info.win.window;
+ HWND hwnd = (HWND)viewport->PlatformHandleRaw;
- // SDL hack: Hide icon from task bar
- // Note: SDL 2.0.6+ has a SDL_WINDOW_SKIP_TASKBAR flag which is supported under Windows but the way it create the window breaks our seamless transition.
- if (viewport->Flags & ImGuiViewportFlags_NoTaskBarIcon)
- {
- LONG ex_style = ::GetWindowLong(hwnd, GWL_EXSTYLE);
- ex_style &= ~WS_EX_APPWINDOW;
- ex_style |= WS_EX_TOOLWINDOW;
- ::SetWindowLong(hwnd, GWL_EXSTYLE, ex_style);
- }
+ // SDL hack: Hide icon from task bar
+ // Note: SDL 2.0.6+ has a SDL_WINDOW_SKIP_TASKBAR flag which is supported under Windows but the way it create the window breaks our seamless transition.
+ if (viewport->Flags & ImGuiViewportFlags_NoTaskBarIcon)
+ {
+ LONG ex_style = ::GetWindowLong(hwnd, GWL_EXSTYLE);
+ ex_style &= ~WS_EX_APPWINDOW;
+ ex_style |= WS_EX_TOOLWINDOW;
+ ::SetWindowLong(hwnd, GWL_EXSTYLE, ex_style);
+ }
- // SDL hack: SDL always activate/focus windows :/
- if (viewport->Flags & ImGuiViewportFlags_NoFocusOnAppearing)
- {
- ::ShowWindow(hwnd, SW_SHOWNA);
- return;
- }
+ // SDL hack: SDL always activate/focus windows :/
+ if (viewport->Flags & ImGuiViewportFlags_NoFocusOnAppearing)
+ {
+ ::ShowWindow(hwnd, SW_SHOWNA);
+ return;
}
#endif
diff --git a/examples/imgui_impl_sdl.h b/examples/imgui_impl_sdl.h
index ac1d7e54..ac06a781 100644
--- a/examples/imgui_impl_sdl.h
+++ b/examples/imgui_impl_sdl.h
@@ -6,10 +6,11 @@
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
// [X] Platform: Clipboard support.
// [X] Platform: Keyboard arrays indexed using SDL_SCANCODE_* codes, e.g. ImGui::IsKeyPressed(SDL_SCANCODE_SPACE).
+// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
// [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
// Missing features:
// [ ] Platform: SDL2 handling of IME under Windows appears to be broken and it explicitly disable the regular Windows IME. You can restore Windows IME by compiling SDL with SDL_DISABLE_WINDOWS_IME.
-// [ ] Platform: Gamepad support (need to use SDL_GameController API to fill the io.NavInputs[] value when ImGuiConfigFlags_NavEnableGamepad is set).
+// [ ] Platform: Multi-viewport + Minimized windows seems to break mouse wheel events (at least under Windows).
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
// If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
@@ -22,6 +23,7 @@ typedef union SDL_Event SDL_Event;
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context);
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window);
+IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window);
IMGUI_IMPL_API void ImGui_ImplSDL2_Shutdown();
IMGUI_IMPL_API void ImGui_ImplSDL2_NewFrame(SDL_Window* window);
IMGUI_IMPL_API bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event);
diff --git a/examples/imgui_impl_vulkan.cpp b/examples/imgui_impl_vulkan.cpp
index 77675b2c..5990f320 100644
--- a/examples/imgui_impl_vulkan.cpp
+++ b/examples/imgui_impl_vulkan.cpp
@@ -1,8 +1,10 @@
// dear imgui: Renderer for Vulkan
// This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..)
+// Implemented features:
+// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices.
+// [x] Platform: Multi-viewport / platform windows. With issues (flickering when creating a new viewport).
// Missing features:
-// [ ] Platform: Multi-viewport / platform windows.
// [ ] Renderer: User texture binding. Changes of ImTextureID aren't supported by this binding! See https://github.com/ocornut/imgui/pull/914
// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
@@ -12,8 +14,23 @@
// The aim of imgui_impl_vulkan.h/.cpp is to be usable in your engine without any modification.
// IF YOU FEEL YOU NEED TO MAKE ANY CHANGE TO THIS CODE, please share them and your feedback at https://github.com/ocornut/imgui/
+// Important note to the reader who wish to integrate imgui_impl_vulkan.cpp/.h in their own engine/app.
+// - Common ImGui_ImplVulkan_XXX functions and structures are used to interface with imgui_impl_vulkan.cpp/.h.
+// You will use those if you want to use this rendering back-end in your engine/app.
+// - Helper ImGui_ImplVulkanH_XXX functions and structures are only used by this example (main.cpp) and by
+// the back-end itself (imgui_impl_vulkan.cpp), but should PROBABLY NOT be used by your own engine/app code.
+// Read comments in imgui_impl_vulkan.h.
+
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
+// 2019-08-01: Vulkan: Added support for specifying multisample count. Set ImGui_ImplVulkan_InitInfo::MSAASamples to one of the VkSampleCountFlagBits values to use, default is non-multisampled as before.
+// 2019-05-29: Vulkan: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag.
+// 2019-04-30: Vulkan: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
+// 2019-04-04: *BREAKING CHANGE*: Vulkan: Added ImageCount/MinImageCount fields in ImGui_ImplVulkan_InitInfo, required for initialization (was previously a hard #define IMGUI_VK_QUEUED_FRAMES 2). Added ImGui_ImplVulkan_SetMinImageCount().
+// 2019-04-04: Vulkan: Added VkInstance argument to ImGui_ImplVulkanH_CreateWindow() optional helper.
+// 2019-04-04: Vulkan: Avoid passing negative coordinates to vkCmdSetScissor, which debug validation layers do not like.
+// 2019-04-01: Vulkan: Support for 32-bit index buffer (#define ImDrawIdx unsigned int).
+// 2019-02-16: Vulkan: Viewport and clipping rectangles correctly using draw_data->FramebufferScale to allow retina display.
// 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
// 2018-08-25: Vulkan: Fixed mishandled VkSurfaceCapabilitiesKHR::maxImageCount=0 case.
// 2018-06-22: Inverted the parameters to ImGui_ImplVulkan_RenderDrawData() to be consistent with other bindings.
@@ -32,46 +49,70 @@
#include "imgui_impl_vulkan.h"
#include
-// Vulkan data
-static const VkAllocationCallbacks* g_Allocator = NULL;
-static VkPhysicalDevice g_PhysicalDevice = VK_NULL_HANDLE;
-static VkInstance g_Instance = VK_NULL_HANDLE;
-static VkDevice g_Device = VK_NULL_HANDLE;
-static uint32_t g_QueueFamily = (uint32_t)-1;
-static VkQueue g_Queue = VK_NULL_HANDLE;
-static VkPipelineCache g_PipelineCache = VK_NULL_HANDLE;
-static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE;
-static VkRenderPass g_RenderPass = VK_NULL_HANDLE;
-static void (*g_CheckVkResultFn)(VkResult err) = NULL;
-
-static VkDeviceSize g_BufferMemoryAlignment = 256;
-static VkPipelineCreateFlags g_PipelineCreateFlags = 0;
-
-static VkDescriptorSetLayout g_DescriptorSetLayout = VK_NULL_HANDLE;
-static VkPipelineLayout g_PipelineLayout = VK_NULL_HANDLE;
-static VkDescriptorSet g_DescriptorSet = VK_NULL_HANDLE;
-static VkPipeline g_Pipeline = VK_NULL_HANDLE;
-
-// Frame data
-struct FrameDataForRender
+// Reusable buffers used for rendering 1 current in-flight frame, for ImGui_ImplVulkan_RenderDrawData()
+// [Please zero-clear before use!]
+struct ImGui_ImplVulkanH_FrameRenderBuffers
+{
+ VkDeviceMemory VertexBufferMemory;
+ VkDeviceMemory IndexBufferMemory;
+ VkDeviceSize VertexBufferSize;
+ VkDeviceSize IndexBufferSize;
+ VkBuffer VertexBuffer;
+ VkBuffer IndexBuffer;
+};
+
+// Each viewport will hold 1 ImGui_ImplVulkanH_WindowRenderBuffers
+// [Please zero-clear before use!]
+struct ImGui_ImplVulkanH_WindowRenderBuffers
{
- VkDeviceMemory VertexBufferMemory;
- VkDeviceMemory IndexBufferMemory;
- VkDeviceSize VertexBufferSize;
- VkDeviceSize IndexBufferSize;
- VkBuffer VertexBuffer;
- VkBuffer IndexBuffer;
+ uint32_t Index;
+ uint32_t Count;
+ ImGui_ImplVulkanH_FrameRenderBuffers* FrameRenderBuffers;
};
-static int g_FrameIndex = 0;
-static FrameDataForRender g_FramesDataBuffers[IMGUI_VK_QUEUED_FRAMES] = {};
+
+// For multi-viewport support
+struct ImGuiViewportDataVulkan
+{
+ bool WindowOwned;
+ ImGui_ImplVulkanH_Window Window; // Used by secondary viewports only
+ ImGui_ImplVulkanH_WindowRenderBuffers RenderBuffers; // Used by all viewports
+
+ ImGuiViewportDataVulkan() { WindowOwned = false; memset(&RenderBuffers, 0, sizeof(RenderBuffers)); }
+ ~ImGuiViewportDataVulkan() { }
+};
+
+// Vulkan data
+static ImGui_ImplVulkan_InitInfo g_VulkanInitInfo = {};
+static VkRenderPass g_RenderPass = VK_NULL_HANDLE;
+static VkDeviceSize g_BufferMemoryAlignment = 256;
+static VkPipelineCreateFlags g_PipelineCreateFlags = 0x00;
+static VkDescriptorSetLayout g_DescriptorSetLayout = VK_NULL_HANDLE;
+static VkPipelineLayout g_PipelineLayout = VK_NULL_HANDLE;
+static VkDescriptorSet g_DescriptorSet = VK_NULL_HANDLE;
+static VkPipeline g_Pipeline = VK_NULL_HANDLE;
// Font data
-static VkSampler g_FontSampler = VK_NULL_HANDLE;
-static VkDeviceMemory g_FontMemory = VK_NULL_HANDLE;
-static VkImage g_FontImage = VK_NULL_HANDLE;
-static VkImageView g_FontView = VK_NULL_HANDLE;
-static VkDeviceMemory g_UploadBufferMemory = VK_NULL_HANDLE;
-static VkBuffer g_UploadBuffer = VK_NULL_HANDLE;
+static VkSampler g_FontSampler = VK_NULL_HANDLE;
+static VkDeviceMemory g_FontMemory = VK_NULL_HANDLE;
+static VkImage g_FontImage = VK_NULL_HANDLE;
+static VkImageView g_FontView = VK_NULL_HANDLE;
+static VkDeviceMemory g_UploadBufferMemory = VK_NULL_HANDLE;
+static VkBuffer g_UploadBuffer = VK_NULL_HANDLE;
+
+// Forward Declarations
+bool ImGui_ImplVulkan_CreateDeviceObjects();
+void ImGui_ImplVulkan_DestroyDeviceObjects();
+void ImGui_ImplVulkanH_DestroyFrame(VkDevice device, ImGui_ImplVulkanH_Frame* fd, const VkAllocationCallbacks* allocator);
+void ImGui_ImplVulkanH_DestroyFrameSemaphores(VkDevice device, ImGui_ImplVulkanH_FrameSemaphores* fsd, const VkAllocationCallbacks* allocator);
+void ImGui_ImplVulkanH_DestroyFrameRenderBuffers(VkDevice device, ImGui_ImplVulkanH_FrameRenderBuffers* buffers, const VkAllocationCallbacks* allocator);
+void ImGui_ImplVulkanH_DestroyWindowRenderBuffers(VkDevice device, ImGui_ImplVulkanH_WindowRenderBuffers* buffers, const VkAllocationCallbacks* allocator);
+void ImGui_ImplVulkanH_DestroyAllViewportsRenderBuffers(VkDevice device, const VkAllocationCallbacks* allocator);
+void ImGui_ImplVulkanH_CreateWindowSwapChain(VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wd, const VkAllocationCallbacks* allocator, int w, int h, uint32_t min_image_count);
+void ImGui_ImplVulkanH_CreateWindowCommandBuffers(VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wd, uint32_t queue_family, const VkAllocationCallbacks* allocator);
+
+//-----------------------------------------------------------------------------
+// SHADERS
+//-----------------------------------------------------------------------------
// Forward Declarations
static void ImGui_ImplVulkan_InitPlatformInterface();
@@ -79,6 +120,23 @@ static void ImGui_ImplVulkan_ShutdownPlatformInterface();
// glsl_shader.vert, compiled with:
// # glslangValidator -V -x -o glsl_shader.vert.u32 glsl_shader.vert
+/*
+#version 450 core
+layout(location = 0) in vec2 aPos;
+layout(location = 1) in vec2 aUV;
+layout(location = 2) in vec4 aColor;
+layout(push_constant) uniform uPushConstant { vec2 uScale; vec2 uTranslate; } pc;
+
+out gl_PerVertex { vec4 gl_Position; };
+layout(location = 0) out struct { vec4 Color; vec2 UV; } Out;
+
+void main()
+{
+ Out.Color = aColor;
+ Out.UV = aUV;
+ gl_Position = vec4(aPos * pc.uScale + pc.uTranslate, 0, 1);
+}
+*/
static uint32_t __glsl_shader_vert_spv[] =
{
0x07230203,0x00010000,0x00080001,0x0000002e,0x00000000,0x00020011,0x00000001,0x0006000b,
@@ -126,6 +184,16 @@ static uint32_t __glsl_shader_vert_spv[] =
// glsl_shader.frag, compiled with:
// # glslangValidator -V -x -o glsl_shader.frag.u32 glsl_shader.frag
+/*
+#version 450 core
+layout(location = 0) out vec4 fColor;
+layout(set=0, binding=0) uniform sampler2D sTexture;
+layout(location = 0) in struct { vec4 Color; vec2 UV; } In;
+void main()
+{
+ fColor = In.Color * texture(sTexture, In.UV.st);
+}
+*/
static uint32_t __glsl_shader_frag_spv[] =
{
0x07230203,0x00010000,0x00080001,0x0000001e,0x00000000,0x00020011,0x00000001,0x0006000b,
@@ -155,10 +223,15 @@ static uint32_t __glsl_shader_frag_spv[] =
0x00010038
};
+//-----------------------------------------------------------------------------
+// FUNCTIONS
+//-----------------------------------------------------------------------------
+
static uint32_t ImGui_ImplVulkan_MemoryType(VkMemoryPropertyFlags properties, uint32_t type_bits)
{
+ ImGui_ImplVulkan_InitInfo* v = &g_VulkanInitInfo;
VkPhysicalDeviceMemoryProperties prop;
- vkGetPhysicalDeviceMemoryProperties(g_PhysicalDevice, &prop);
+ vkGetPhysicalDeviceMemoryProperties(v->PhysicalDevice, &prop);
for (uint32_t i = 0; i < prop.memoryTypeCount; i++)
if ((prop.memoryTypes[i].propertyFlags & properties) == properties && type_bits & (1<CheckVkResultFn)
+ v->CheckVkResultFn(err);
}
static void CreateOrResizeBuffer(VkBuffer& buffer, VkDeviceMemory& buffer_memory, VkDeviceSize& p_buffer_size, size_t new_size, VkBufferUsageFlagBits usage)
{
+ ImGui_ImplVulkan_InitInfo* v = &g_VulkanInitInfo;
VkResult err;
if (buffer != VK_NULL_HANDLE)
- vkDestroyBuffer(g_Device, buffer, g_Allocator);
- if (buffer_memory)
- vkFreeMemory(g_Device, buffer_memory, g_Allocator);
+ vkDestroyBuffer(v->Device, buffer, v->Allocator);
+ if (buffer_memory != VK_NULL_HANDLE)
+ vkFreeMemory(v->Device, buffer_memory, v->Allocator);
VkDeviceSize vertex_buffer_size_aligned = ((new_size - 1) / g_BufferMemoryAlignment + 1) * g_BufferMemoryAlignment;
VkBufferCreateInfo buffer_info = {};
@@ -185,72 +260,26 @@ static void CreateOrResizeBuffer(VkBuffer& buffer, VkDeviceMemory& buffer_memory
buffer_info.size = vertex_buffer_size_aligned;
buffer_info.usage = usage;
buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
- err = vkCreateBuffer(g_Device, &buffer_info, g_Allocator, &buffer);
+ err = vkCreateBuffer(v->Device, &buffer_info, v->Allocator, &buffer);
check_vk_result(err);
VkMemoryRequirements req;
- vkGetBufferMemoryRequirements(g_Device, buffer, &req);
+ vkGetBufferMemoryRequirements(v->Device, buffer, &req);
g_BufferMemoryAlignment = (g_BufferMemoryAlignment > req.alignment) ? g_BufferMemoryAlignment : req.alignment;
VkMemoryAllocateInfo alloc_info = {};
alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
alloc_info.allocationSize = req.size;
alloc_info.memoryTypeIndex = ImGui_ImplVulkan_MemoryType(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, req.memoryTypeBits);
- err = vkAllocateMemory(g_Device, &alloc_info, g_Allocator, &buffer_memory);
+ err = vkAllocateMemory(v->Device, &alloc_info, v->Allocator, &buffer_memory);
check_vk_result(err);
- err = vkBindBufferMemory(g_Device, buffer, buffer_memory, 0);
+ err = vkBindBufferMemory(v->Device, buffer, buffer_memory, 0);
check_vk_result(err);
p_buffer_size = new_size;
}
-// Render function
-// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
-void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer command_buffer)
+static void ImGui_ImplVulkan_SetupRenderState(ImDrawData* draw_data, VkCommandBuffer command_buffer, ImGui_ImplVulkanH_FrameRenderBuffers* rb, int fb_width, int fb_height)
{
- VkResult err;
- if (draw_data->TotalVtxCount == 0)
- return;
-
- FrameDataForRender* fd = &g_FramesDataBuffers[g_FrameIndex];
- g_FrameIndex = (g_FrameIndex + 1) % IMGUI_VK_QUEUED_FRAMES;
-
- // Create the Vertex and Index buffers:
- size_t vertex_size = draw_data->TotalVtxCount * sizeof(ImDrawVert);
- size_t index_size = draw_data->TotalIdxCount * sizeof(ImDrawIdx);
- if (!fd->VertexBuffer || fd->VertexBufferSize < vertex_size)
- CreateOrResizeBuffer(fd->VertexBuffer, fd->VertexBufferMemory, fd->VertexBufferSize, vertex_size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT);
- if (!fd->IndexBuffer || fd->IndexBufferSize < index_size)
- CreateOrResizeBuffer(fd->IndexBuffer, fd->IndexBufferMemory, fd->IndexBufferSize, index_size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT);
-
- // Upload Vertex and index Data:
- {
- ImDrawVert* vtx_dst = NULL;
- ImDrawIdx* idx_dst = NULL;
- err = vkMapMemory(g_Device, fd->VertexBufferMemory, 0, vertex_size, 0, (void**)(&vtx_dst));
- check_vk_result(err);
- err = vkMapMemory(g_Device, fd->IndexBufferMemory, 0, index_size, 0, (void**)(&idx_dst));
- check_vk_result(err);
- for (int n = 0; n < draw_data->CmdListsCount; n++)
- {
- const ImDrawList* cmd_list = draw_data->CmdLists[n];
- memcpy(vtx_dst, cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.Size * sizeof(ImDrawVert));
- memcpy(idx_dst, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx));
- vtx_dst += cmd_list->VtxBuffer.Size;
- idx_dst += cmd_list->IdxBuffer.Size;
- }
- VkMappedMemoryRange range[2] = {};
- range[0].sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
- range[0].memory = fd->VertexBufferMemory;
- range[0].size = VK_WHOLE_SIZE;
- range[1].sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
- range[1].memory = fd->IndexBufferMemory;
- range[1].size = VK_WHOLE_SIZE;
- err = vkFlushMappedMemoryRanges(g_Device, 2, range);
- check_vk_result(err);
- vkUnmapMemory(g_Device, fd->VertexBufferMemory);
- vkUnmapMemory(g_Device, fd->IndexBufferMemory);
- }
-
// Bind pipeline and descriptor sets:
{
vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, g_Pipeline);
@@ -260,10 +289,10 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer comm
// Bind Vertex And Index Buffer:
{
- VkBuffer vertex_buffers[1] = { fd->VertexBuffer };
+ VkBuffer vertex_buffers[1] = { rb->VertexBuffer };
VkDeviceSize vertex_offset[1] = { 0 };
vkCmdBindVertexBuffers(command_buffer, 0, 1, vertex_buffers, vertex_offset);
- vkCmdBindIndexBuffer(command_buffer, fd->IndexBuffer, 0, VK_INDEX_TYPE_UINT16);
+ vkCmdBindIndexBuffer(command_buffer, rb->IndexBuffer, 0, sizeof(ImDrawIdx) == 2 ? VK_INDEX_TYPE_UINT16 : VK_INDEX_TYPE_UINT32);
}
// Setup viewport:
@@ -271,15 +300,15 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer comm
VkViewport viewport;
viewport.x = 0;
viewport.y = 0;
- viewport.width = draw_data->DisplaySize.x;
- viewport.height = draw_data->DisplaySize.y;
+ viewport.width = (float)fb_width;
+ viewport.height = (float)fb_height;
viewport.minDepth = 0.0f;
viewport.maxDepth = 1.0f;
vkCmdSetViewport(command_buffer, 0, 1, &viewport);
}
// Setup scale and translation:
- // Our visible imgui space lies from draw_data->DisplayPps (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayMin is (0,0) for single viewport apps.
+ // Our visible imgui space lies from draw_data->DisplayPps (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
{
float scale[2];
scale[0] = 2.0f / draw_data->DisplaySize.x;
@@ -290,43 +319,138 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer comm
vkCmdPushConstants(command_buffer, g_PipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, sizeof(float) * 0, sizeof(float) * 2, scale);
vkCmdPushConstants(command_buffer, g_PipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, sizeof(float) * 2, sizeof(float) * 2, translate);
}
+}
- // Render the command lists:
- int vtx_offset = 0;
- int idx_offset = 0;
- ImVec2 display_pos = draw_data->DisplayPos;
+// Render function
+// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
+void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer command_buffer)
+{
+ // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
+ int fb_width = (int)(draw_data->DisplaySize.x * draw_data->FramebufferScale.x);
+ int fb_height = (int)(draw_data->DisplaySize.y * draw_data->FramebufferScale.y);
+ if (fb_width <= 0 || fb_height <= 0 || draw_data->TotalVtxCount == 0)
+ return;
+
+ ImGui_ImplVulkan_InitInfo* v = &g_VulkanInitInfo;
+
+ // Allocate array to store enough vertex/index buffers. Each unique viewport gets its own storage.
+ ImGuiViewportDataVulkan* viewport_renderer_data = (ImGuiViewportDataVulkan*)draw_data->OwnerViewport->RendererUserData;
+ IM_ASSERT(viewport_renderer_data != NULL);
+ ImGui_ImplVulkanH_WindowRenderBuffers* wrb = &viewport_renderer_data->RenderBuffers;
+ if (wrb->FrameRenderBuffers == NULL)
+ {
+ wrb->Index = 0;
+ wrb->Count = v->ImageCount;
+ wrb->FrameRenderBuffers = (ImGui_ImplVulkanH_FrameRenderBuffers*)IM_ALLOC(sizeof(ImGui_ImplVulkanH_FrameRenderBuffers) * wrb->Count);
+ memset(wrb->FrameRenderBuffers, 0, sizeof(ImGui_ImplVulkanH_FrameRenderBuffers) * wrb->Count);
+ }
+ IM_ASSERT(wrb->Count == v->ImageCount);
+ wrb->Index = (wrb->Index + 1) % wrb->Count;
+ ImGui_ImplVulkanH_FrameRenderBuffers* rb = &wrb->FrameRenderBuffers[wrb->Index];
+
+ VkResult err;
+
+ // Create or resize the vertex/index buffers
+ size_t vertex_size = draw_data->TotalVtxCount * sizeof(ImDrawVert);
+ size_t index_size = draw_data->TotalIdxCount * sizeof(ImDrawIdx);
+ if (rb->VertexBuffer == VK_NULL_HANDLE || rb->VertexBufferSize < vertex_size)
+ CreateOrResizeBuffer(rb->VertexBuffer, rb->VertexBufferMemory, rb->VertexBufferSize, vertex_size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT);
+ if (rb->IndexBuffer == VK_NULL_HANDLE || rb->IndexBufferSize < index_size)
+ CreateOrResizeBuffer(rb->IndexBuffer, rb->IndexBufferMemory, rb->IndexBufferSize, index_size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT);
+
+ // Upload vertex/index data into a single contiguous GPU buffer
+ {
+ ImDrawVert* vtx_dst = NULL;
+ ImDrawIdx* idx_dst = NULL;
+ err = vkMapMemory(v->Device, rb->VertexBufferMemory, 0, vertex_size, 0, (void**)(&vtx_dst));
+ check_vk_result(err);
+ err = vkMapMemory(v->Device, rb->IndexBufferMemory, 0, index_size, 0, (void**)(&idx_dst));
+ check_vk_result(err);
+ for (int n = 0; n < draw_data->CmdListsCount; n++)
+ {
+ const ImDrawList* cmd_list = draw_data->CmdLists[n];
+ memcpy(vtx_dst, cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.Size * sizeof(ImDrawVert));
+ memcpy(idx_dst, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx));
+ vtx_dst += cmd_list->VtxBuffer.Size;
+ idx_dst += cmd_list->IdxBuffer.Size;
+ }
+ VkMappedMemoryRange range[2] = {};
+ range[0].sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
+ range[0].memory = rb->VertexBufferMemory;
+ range[0].size = VK_WHOLE_SIZE;
+ range[1].sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
+ range[1].memory = rb->IndexBufferMemory;
+ range[1].size = VK_WHOLE_SIZE;
+ err = vkFlushMappedMemoryRanges(v->Device, 2, range);
+ check_vk_result(err);
+ vkUnmapMemory(v->Device, rb->VertexBufferMemory);
+ vkUnmapMemory(v->Device, rb->IndexBufferMemory);
+ }
+
+ // Setup desired Vulkan state
+ ImGui_ImplVulkan_SetupRenderState(draw_data, command_buffer, rb, fb_width, fb_height);
+
+ // Will project scissor/clipping rectangles into framebuffer space
+ ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports
+ ImVec2 clip_scale = draw_data->FramebufferScale; // (1,1) unless using retina display which are often (2,2)
+
+ // Render command lists
+ // (Because we merged all buffers into a single one, we maintain our own offset into them)
+ int global_vtx_offset = 0;
+ int global_idx_offset = 0;
for (int n = 0; n < draw_data->CmdListsCount; n++)
{
const ImDrawList* cmd_list = draw_data->CmdLists[n];
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
{
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
- if (pcmd->UserCallback)
+ if (pcmd->UserCallback != NULL)
{
- pcmd->UserCallback(cmd_list, pcmd);
+ // User callback, registered via ImDrawList::AddCallback()
+ // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
+ if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
+ ImGui_ImplVulkan_SetupRenderState(draw_data, command_buffer, rb, fb_width, fb_height);
+ else
+ pcmd->UserCallback(cmd_list, pcmd);
}
else
{
- // Apply scissor/clipping rectangle
- // FIXME: We could clamp width/height based on clamped min/max values.
- VkRect2D scissor;
- scissor.offset.x = (int32_t)(pcmd->ClipRect.x - display_pos.x) > 0 ? (int32_t)(pcmd->ClipRect.x - display_pos.x) : 0;
- scissor.offset.y = (int32_t)(pcmd->ClipRect.y - display_pos.y) > 0 ? (int32_t)(pcmd->ClipRect.y - display_pos.y) : 0;
- scissor.extent.width = (uint32_t)(pcmd->ClipRect.z - pcmd->ClipRect.x);
- scissor.extent.height = (uint32_t)(pcmd->ClipRect.w - pcmd->ClipRect.y + 1); // FIXME: Why +1 here?
- vkCmdSetScissor(command_buffer, 0, 1, &scissor);
-
- // Draw
- vkCmdDrawIndexed(command_buffer, pcmd->ElemCount, 1, idx_offset, vtx_offset, 0);
+ // Project scissor/clipping rectangles into framebuffer space
+ ImVec4 clip_rect;
+ clip_rect.x = (pcmd->ClipRect.x - clip_off.x) * clip_scale.x;
+ clip_rect.y = (pcmd->ClipRect.y - clip_off.y) * clip_scale.y;
+ clip_rect.z = (pcmd->ClipRect.z - clip_off.x) * clip_scale.x;
+ clip_rect.w = (pcmd->ClipRect.w - clip_off.y) * clip_scale.y;
+
+ if (clip_rect.x < fb_width && clip_rect.y < fb_height && clip_rect.z >= 0.0f && clip_rect.w >= 0.0f)
+ {
+ // Negative offsets are illegal for vkCmdSetScissor
+ if (clip_rect.x < 0.0f)
+ clip_rect.x = 0.0f;
+ if (clip_rect.y < 0.0f)
+ clip_rect.y = 0.0f;
+
+ // Apply scissor/clipping rectangle
+ VkRect2D scissor;
+ scissor.offset.x = (int32_t)(clip_rect.x);
+ scissor.offset.y = (int32_t)(clip_rect.y);
+ scissor.extent.width = (uint32_t)(clip_rect.z - clip_rect.x);
+ scissor.extent.height = (uint32_t)(clip_rect.w - clip_rect.y);
+ vkCmdSetScissor(command_buffer, 0, 1, &scissor);
+
+ // Draw
+ vkCmdDrawIndexed(command_buffer, pcmd->ElemCount, 1, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset, 0);
+ }
}
- idx_offset += pcmd->ElemCount;
}
- vtx_offset += cmd_list->VtxBuffer.Size;
+ global_idx_offset += cmd_list->IdxBuffer.Size;
+ global_vtx_offset += cmd_list->VtxBuffer.Size;
}
}
bool ImGui_ImplVulkan_CreateFontsTexture(VkCommandBuffer command_buffer)
{
+ ImGui_ImplVulkan_InitInfo* v = &g_VulkanInitInfo;
ImGuiIO& io = ImGui::GetIO();
unsigned char* pixels;
@@ -352,17 +476,17 @@ bool ImGui_ImplVulkan_CreateFontsTexture(VkCommandBuffer command_buffer)
info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
- err = vkCreateImage(g_Device, &info, g_Allocator, &g_FontImage);
+ err = vkCreateImage(v->Device, &info, v->Allocator, &g_FontImage);
check_vk_result(err);
VkMemoryRequirements req;
- vkGetImageMemoryRequirements(g_Device, g_FontImage, &req);
+ vkGetImageMemoryRequirements(v->Device, g_FontImage, &req);
VkMemoryAllocateInfo alloc_info = {};
alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
alloc_info.allocationSize = req.size;
alloc_info.memoryTypeIndex = ImGui_ImplVulkan_MemoryType(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, req.memoryTypeBits);
- err = vkAllocateMemory(g_Device, &alloc_info, g_Allocator, &g_FontMemory);
+ err = vkAllocateMemory(v->Device, &alloc_info, v->Allocator, &g_FontMemory);
check_vk_result(err);
- err = vkBindImageMemory(g_Device, g_FontImage, g_FontMemory, 0);
+ err = vkBindImageMemory(v->Device, g_FontImage, g_FontMemory, 0);
check_vk_result(err);
}
@@ -376,7 +500,7 @@ bool ImGui_ImplVulkan_CreateFontsTexture(VkCommandBuffer command_buffer)
info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
info.subresourceRange.levelCount = 1;
info.subresourceRange.layerCount = 1;
- err = vkCreateImageView(g_Device, &info, g_Allocator, &g_FontView);
+ err = vkCreateImageView(v->Device, &info, v->Allocator, &g_FontView);
check_vk_result(err);
}
@@ -392,7 +516,7 @@ bool ImGui_ImplVulkan_CreateFontsTexture(VkCommandBuffer command_buffer)
write_desc[0].descriptorCount = 1;
write_desc[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
write_desc[0].pImageInfo = desc_image;
- vkUpdateDescriptorSets(g_Device, 1, write_desc, 0, NULL);
+ vkUpdateDescriptorSets(v->Device, 1, write_desc, 0, NULL);
}
// Create the Upload Buffer:
@@ -402,34 +526,34 @@ bool ImGui_ImplVulkan_CreateFontsTexture(VkCommandBuffer command_buffer)
buffer_info.size = upload_size;
buffer_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
- err = vkCreateBuffer(g_Device, &buffer_info, g_Allocator, &g_UploadBuffer);
+ err = vkCreateBuffer(v->Device, &buffer_info, v->Allocator, &g_UploadBuffer);
check_vk_result(err);
VkMemoryRequirements req;
- vkGetBufferMemoryRequirements(g_Device, g_UploadBuffer, &req);
+ vkGetBufferMemoryRequirements(v->Device, g_UploadBuffer, &req);
g_BufferMemoryAlignment = (g_BufferMemoryAlignment > req.alignment) ? g_BufferMemoryAlignment : req.alignment;
VkMemoryAllocateInfo alloc_info = {};
alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
alloc_info.allocationSize = req.size;
alloc_info.memoryTypeIndex = ImGui_ImplVulkan_MemoryType(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, req.memoryTypeBits);
- err = vkAllocateMemory(g_Device, &alloc_info, g_Allocator, &g_UploadBufferMemory);
+ err = vkAllocateMemory(v->Device, &alloc_info, v->Allocator, &g_UploadBufferMemory);
check_vk_result(err);
- err = vkBindBufferMemory(g_Device, g_UploadBuffer, g_UploadBufferMemory, 0);
+ err = vkBindBufferMemory(v->Device, g_UploadBuffer, g_UploadBufferMemory, 0);
check_vk_result(err);
}
// Upload to Buffer:
{
char* map = NULL;
- err = vkMapMemory(g_Device, g_UploadBufferMemory, 0, upload_size, 0, (void**)(&map));
+ err = vkMapMemory(v->Device, g_UploadBufferMemory, 0, upload_size, 0, (void**)(&map));
check_vk_result(err);
memcpy(map, pixels, upload_size);
VkMappedMemoryRange range[1] = {};
range[0].sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
range[0].memory = g_UploadBufferMemory;
range[0].size = upload_size;
- err = vkFlushMappedMemoryRanges(g_Device, 1, range);
+ err = vkFlushMappedMemoryRanges(v->Device, 1, range);
check_vk_result(err);
- vkUnmapMemory(g_Device, g_UploadBufferMemory);
+ vkUnmapMemory(v->Device, g_UploadBufferMemory);
}
// Copy to Image:
@@ -478,6 +602,7 @@ bool ImGui_ImplVulkan_CreateFontsTexture(VkCommandBuffer command_buffer)
bool ImGui_ImplVulkan_CreateDeviceObjects()
{
+ ImGui_ImplVulkan_InitInfo* v = &g_VulkanInitInfo;
VkResult err;
VkShaderModule vert_module;
VkShaderModule frag_module;
@@ -488,13 +613,13 @@ bool ImGui_ImplVulkan_CreateDeviceObjects()
vert_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
vert_info.codeSize = sizeof(__glsl_shader_vert_spv);
vert_info.pCode = (uint32_t*)__glsl_shader_vert_spv;
- err = vkCreateShaderModule(g_Device, &vert_info, g_Allocator, &vert_module);
+ err = vkCreateShaderModule(v->Device, &vert_info, v->Allocator, &vert_module);
check_vk_result(err);
VkShaderModuleCreateInfo frag_info = {};
frag_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
frag_info.codeSize = sizeof(__glsl_shader_frag_spv);
frag_info.pCode = (uint32_t*)__glsl_shader_frag_spv;
- err = vkCreateShaderModule(g_Device, &frag_info, g_Allocator, &frag_module);
+ err = vkCreateShaderModule(v->Device, &frag_info, v->Allocator, &frag_module);
check_vk_result(err);
}
@@ -511,7 +636,7 @@ bool ImGui_ImplVulkan_CreateDeviceObjects()
info.minLod = -1000;
info.maxLod = 1000;
info.maxAnisotropy = 1.0f;
- err = vkCreateSampler(g_Device, &info, g_Allocator, &g_FontSampler);
+ err = vkCreateSampler(v->Device, &info, v->Allocator, &g_FontSampler);
check_vk_result(err);
}
@@ -527,7 +652,7 @@ bool ImGui_ImplVulkan_CreateDeviceObjects()
info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
info.bindingCount = 1;
info.pBindings = binding;
- err = vkCreateDescriptorSetLayout(g_Device, &info, g_Allocator, &g_DescriptorSetLayout);
+ err = vkCreateDescriptorSetLayout(v->Device, &info, v->Allocator, &g_DescriptorSetLayout);
check_vk_result(err);
}
@@ -535,10 +660,10 @@ bool ImGui_ImplVulkan_CreateDeviceObjects()
{
VkDescriptorSetAllocateInfo alloc_info = {};
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
- alloc_info.descriptorPool = g_DescriptorPool;
+ alloc_info.descriptorPool = v->DescriptorPool;
alloc_info.descriptorSetCount = 1;
alloc_info.pSetLayouts = &g_DescriptorSetLayout;
- err = vkAllocateDescriptorSets(g_Device, &alloc_info, &g_DescriptorSet);
+ err = vkAllocateDescriptorSets(v->Device, &alloc_info, &g_DescriptorSet);
check_vk_result(err);
}
@@ -556,7 +681,7 @@ bool ImGui_ImplVulkan_CreateDeviceObjects()
layout_info.pSetLayouts = set_layout;
layout_info.pushConstantRangeCount = 1;
layout_info.pPushConstantRanges = push_constants;
- err = vkCreatePipelineLayout(g_Device, &layout_info, g_Allocator, &g_PipelineLayout);
+ err = vkCreatePipelineLayout(v->Device, &layout_info, v->Allocator, &g_PipelineLayout);
check_vk_result(err);
}
@@ -613,7 +738,10 @@ bool ImGui_ImplVulkan_CreateDeviceObjects()
VkPipelineMultisampleStateCreateInfo ms_info = {};
ms_info.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
- ms_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
+ if (v->MSAASamples != 0)
+ ms_info.rasterizationSamples = v->MSAASamples;
+ else
+ ms_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
VkPipelineColorBlendAttachmentState color_attachment[1] = {};
color_attachment[0].blendEnable = VK_TRUE;
@@ -654,78 +782,70 @@ bool ImGui_ImplVulkan_CreateDeviceObjects()
info.pDynamicState = &dynamic_state;
info.layout = g_PipelineLayout;
info.renderPass = g_RenderPass;
- err = vkCreateGraphicsPipelines(g_Device, g_PipelineCache, 1, &info, g_Allocator, &g_Pipeline);
+ err = vkCreateGraphicsPipelines(v->Device, v->PipelineCache, 1, &info, v->Allocator, &g_Pipeline);
check_vk_result(err);
- vkDestroyShaderModule(g_Device, vert_module, g_Allocator);
- vkDestroyShaderModule(g_Device, frag_module, g_Allocator);
+ vkDestroyShaderModule(v->Device, vert_module, v->Allocator);
+ vkDestroyShaderModule(v->Device, frag_module, v->Allocator);
return true;
}
-void ImGui_ImplVulkan_InvalidateFontUploadObjects()
+void ImGui_ImplVulkan_DestroyFontUploadObjects()
{
+ ImGui_ImplVulkan_InitInfo* v = &g_VulkanInitInfo;
if (g_UploadBuffer)
{
- vkDestroyBuffer(g_Device, g_UploadBuffer, g_Allocator);
+ vkDestroyBuffer(v->Device, g_UploadBuffer, v->Allocator);
g_UploadBuffer = VK_NULL_HANDLE;
}
if (g_UploadBufferMemory)
{
- vkFreeMemory(g_Device, g_UploadBufferMemory, g_Allocator);
+ vkFreeMemory(v->Device, g_UploadBufferMemory, v->Allocator);
g_UploadBufferMemory = VK_NULL_HANDLE;
}
}
-void ImGui_ImplVulkan_InvalidateDeviceObjects()
+void ImGui_ImplVulkan_DestroyDeviceObjects()
{
- ImGui_ImplVulkan_InvalidateFontUploadObjects();
-
- for (int i = 0; i < IMGUI_VK_QUEUED_FRAMES; i++)
- {
- FrameDataForRender* fd = &g_FramesDataBuffers[i];
- if (fd->VertexBuffer) { vkDestroyBuffer (g_Device, fd->VertexBuffer, g_Allocator); fd->VertexBuffer = VK_NULL_HANDLE; }
- if (fd->VertexBufferMemory) { vkFreeMemory (g_Device, fd->VertexBufferMemory, g_Allocator); fd->VertexBufferMemory = VK_NULL_HANDLE; }
- if (fd->IndexBuffer) { vkDestroyBuffer (g_Device, fd->IndexBuffer, g_Allocator); fd->IndexBuffer = VK_NULL_HANDLE; }
- if (fd->IndexBufferMemory) { vkFreeMemory (g_Device, fd->IndexBufferMemory, g_Allocator); fd->IndexBufferMemory = VK_NULL_HANDLE; }
- }
-
- if (g_FontView) { vkDestroyImageView(g_Device, g_FontView, g_Allocator); g_FontView = VK_NULL_HANDLE; }
- if (g_FontImage) { vkDestroyImage(g_Device, g_FontImage, g_Allocator); g_FontImage = VK_NULL_HANDLE; }
- if (g_FontMemory) { vkFreeMemory(g_Device, g_FontMemory, g_Allocator); g_FontMemory = VK_NULL_HANDLE; }
- if (g_FontSampler) { vkDestroySampler(g_Device, g_FontSampler, g_Allocator); g_FontSampler = VK_NULL_HANDLE; }
- if (g_DescriptorSetLayout) { vkDestroyDescriptorSetLayout(g_Device, g_DescriptorSetLayout, g_Allocator); g_DescriptorSetLayout = VK_NULL_HANDLE; }
- if (g_PipelineLayout) { vkDestroyPipelineLayout(g_Device, g_PipelineLayout, g_Allocator); g_PipelineLayout = VK_NULL_HANDLE; }
- if (g_Pipeline) { vkDestroyPipeline(g_Device, g_Pipeline, g_Allocator); g_Pipeline = VK_NULL_HANDLE; }
+ ImGui_ImplVulkan_InitInfo* v = &g_VulkanInitInfo;
+ ImGui_ImplVulkanH_DestroyAllViewportsRenderBuffers(v->Device, v->Allocator);
+ ImGui_ImplVulkan_DestroyFontUploadObjects();
+
+ if (g_FontView) { vkDestroyImageView(v->Device, g_FontView, v->Allocator); g_FontView = VK_NULL_HANDLE; }
+ if (g_FontImage) { vkDestroyImage(v->Device, g_FontImage, v->Allocator); g_FontImage = VK_NULL_HANDLE; }
+ if (g_FontMemory) { vkFreeMemory(v->Device, g_FontMemory, v->Allocator); g_FontMemory = VK_NULL_HANDLE; }
+ if (g_FontSampler) { vkDestroySampler(v->Device, g_FontSampler, v->Allocator); g_FontSampler = VK_NULL_HANDLE; }
+ if (g_DescriptorSetLayout) { vkDestroyDescriptorSetLayout(v->Device, g_DescriptorSetLayout, v->Allocator); g_DescriptorSetLayout = VK_NULL_HANDLE; }
+ if (g_PipelineLayout) { vkDestroyPipelineLayout(v->Device, g_PipelineLayout, v->Allocator); g_PipelineLayout = VK_NULL_HANDLE; }
+ if (g_Pipeline) { vkDestroyPipeline(v->Device, g_Pipeline, v->Allocator); g_Pipeline = VK_NULL_HANDLE; }
}
bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass render_pass)
{
// Setup back-end capabilities flags
ImGuiIO& io = ImGui::GetIO();
- io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
io.BackendRendererName = "imgui_impl_vulkan";
+ io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
+ io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
IM_ASSERT(info->Instance != VK_NULL_HANDLE);
IM_ASSERT(info->PhysicalDevice != VK_NULL_HANDLE);
IM_ASSERT(info->Device != VK_NULL_HANDLE);
IM_ASSERT(info->Queue != VK_NULL_HANDLE);
IM_ASSERT(info->DescriptorPool != VK_NULL_HANDLE);
+ IM_ASSERT(info->MinImageCount >= 2);
+ IM_ASSERT(info->ImageCount >= info->MinImageCount);
IM_ASSERT(render_pass != VK_NULL_HANDLE);
- g_Instance = info->Instance;
- g_PhysicalDevice = info->PhysicalDevice;
- g_Device = info->Device;
- g_QueueFamily = info->QueueFamily;
- g_Queue = info->Queue;
+ g_VulkanInitInfo = *info;
g_RenderPass = render_pass;
- g_PipelineCache = info->PipelineCache;
- g_DescriptorPool = info->DescriptorPool;
- g_Allocator = info->Allocator;
- g_CheckVkResultFn = info->CheckVkResultFn;
-
ImGui_ImplVulkan_CreateDeviceObjects();
+ // Our render function expect RendererUserData to be storing the window render buffer we need (for the main viewport we won't use ->Window)
+ ImGuiViewport* main_viewport = ImGui::GetMainViewport();
+ main_viewport->RendererUserData = IM_NEW(ImGuiViewportDataVulkan)();
+
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
ImGui_ImplVulkan_InitPlatformInterface();
@@ -734,17 +854,42 @@ bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass rend
void ImGui_ImplVulkan_Shutdown()
{
+ // First destroy objects in all viewports
+ ImGui_ImplVulkan_DestroyDeviceObjects();
+
+ // Manually delete main viewport render data in-case we haven't initialized for viewports
+ ImGuiViewport* main_viewport = ImGui::GetMainViewport();
+ if (ImGuiViewportDataVulkan* data = (ImGuiViewportDataVulkan*)main_viewport->RendererUserData)
+ IM_DELETE(data);
+ main_viewport->RendererUserData = NULL;
+
+ // Clean up windows
ImGui_ImplVulkan_ShutdownPlatformInterface();
- ImGui_ImplVulkan_InvalidateDeviceObjects();
}
void ImGui_ImplVulkan_NewFrame()
{
}
+void ImGui_ImplVulkan_SetMinImageCount(uint32_t min_image_count)
+{
+ IM_ASSERT(min_image_count >= 2);
+ if (g_VulkanInitInfo.MinImageCount == min_image_count)
+ return;
+
+ IM_ASSERT(0); // FIXME-VIEWPORT: Unsupported. Need to recreate all swap chains!
+ ImGui_ImplVulkan_InitInfo* v = &g_VulkanInitInfo;
+ VkResult err = vkDeviceWaitIdle(v->Device);
+ check_vk_result(err);
+ ImGui_ImplVulkanH_DestroyAllViewportsRenderBuffers(v->Device, v->Allocator);
+
+ g_VulkanInitInfo.MinImageCount = min_image_count;
+}
+
//-------------------------------------------------------------------------
// Internal / Miscellaneous Vulkan Helpers
+// (Used by example's main.cpp. Used by multi-viewport features. PROBABLY NOT used by your own app.)
//-------------------------------------------------------------------------
// You probably do NOT need to use or care about those functions.
// Those functions only exist because:
@@ -752,40 +897,12 @@ void ImGui_ImplVulkan_NewFrame()
// 2) the upcoming multi-viewport feature will need them internally.
// Generally we avoid exposing any kind of superfluous high-level helpers in the bindings,
// but it is too much code to duplicate everywhere so we exceptionally expose them.
-// Your application/engine will likely already have code to setup all that stuff (swap chain, render pass, frame buffers, etc.).
+//
+// Your engine/app will likely _already_ have code to setup all that stuff (swap chain, render pass, frame buffers, etc.).
// You may read this code to learn about Vulkan, but it is recommended you use you own custom tailored code to do equivalent work.
-// (those functions do not interact with any of the state used by the regular ImGui_ImplVulkan_XXX functions)
+// (The ImGui_ImplVulkanH_XXX functions do not interact with any of the state used by the regular ImGui_ImplVulkan_XXX functions)
//-------------------------------------------------------------------------
-#include // malloc
-
-ImGui_ImplVulkanH_FrameData::ImGui_ImplVulkanH_FrameData()
-{
- BackbufferIndex = 0;
- CommandPool = VK_NULL_HANDLE;
- CommandBuffer = VK_NULL_HANDLE;
- Fence = VK_NULL_HANDLE;
- ImageAcquiredSemaphore = VK_NULL_HANDLE;
- RenderCompleteSemaphore = VK_NULL_HANDLE;
-}
-
-ImGui_ImplVulkanH_WindowData::ImGui_ImplVulkanH_WindowData()
-{
- Width = Height = 0;
- Swapchain = VK_NULL_HANDLE;
- Surface = VK_NULL_HANDLE;
- memset(&SurfaceFormat, 0, sizeof(SurfaceFormat));
- PresentMode = VK_PRESENT_MODE_MAX_ENUM_KHR;
- RenderPass = VK_NULL_HANDLE;
- ClearEnable = true;
- memset(&ClearValue, 0, sizeof(ClearValue));
- BackBufferCount = 0;
- memset(&BackBuffer, 0, sizeof(BackBuffer));
- memset(&BackBufferView, 0, sizeof(BackBufferView));
- memset(&Framebuffer, 0, sizeof(Framebuffer));
- FrameIndex = 0;
-}
-
VkSurfaceFormatKHR ImGui_ImplVulkanH_SelectSurfaceFormat(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkFormat* request_formats, int request_formats_count, VkColorSpaceKHR request_color_space)
{
IM_ASSERT(request_formats != NULL);
@@ -852,7 +969,7 @@ VkPresentModeKHR ImGui_ImplVulkanH_SelectPresentMode(VkPhysicalDevice physical_d
return VK_PRESENT_MODE_FIFO_KHR; // Always available
}
-void ImGui_ImplVulkanH_CreateWindowDataCommandBuffers(VkPhysicalDevice physical_device, VkDevice device, uint32_t queue_family, ImGui_ImplVulkanH_WindowData* wd, const VkAllocationCallbacks* allocator)
+void ImGui_ImplVulkanH_CreateWindowCommandBuffers(VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wd, uint32_t queue_family, const VkAllocationCallbacks* allocator)
{
IM_ASSERT(physical_device != VK_NULL_HANDLE && device != VK_NULL_HANDLE);
(void)physical_device;
@@ -860,9 +977,10 @@ void ImGui_ImplVulkanH_CreateWindowDataCommandBuffers(VkPhysicalDevice physical_
// Create Command Buffers
VkResult err;
- for (int i = 0; i < IMGUI_VK_QUEUED_FRAMES; i++)
+ for (uint32_t i = 0; i < wd->ImageCount; i++)
{
- ImGui_ImplVulkanH_FrameData* fd = &wd->Frames[i];
+ ImGui_ImplVulkanH_Frame* fd = &wd->Frames[i];
+ ImGui_ImplVulkanH_FrameSemaphores* fsd = &wd->FrameSemaphores[i];
{
VkCommandPoolCreateInfo info = {};
info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
@@ -890,9 +1008,9 @@ void ImGui_ImplVulkanH_CreateWindowDataCommandBuffers(VkPhysicalDevice physical_
{
VkSemaphoreCreateInfo info = {};
info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
- err = vkCreateSemaphore(device, &info, allocator, &fd->ImageAcquiredSemaphore);
+ err = vkCreateSemaphore(device, &info, allocator, &fsd->ImageAcquiredSemaphore);
check_vk_result(err);
- err = vkCreateSemaphore(device, &info, allocator, &fd->RenderCompleteSemaphore);
+ err = vkCreateSemaphore(device, &info, allocator, &fsd->RenderCompleteSemaphore);
check_vk_result(err);
}
}
@@ -910,24 +1028,26 @@ int ImGui_ImplVulkanH_GetMinImageCountFromPresentMode(VkPresentModeKHR present_m
return 1;
}
-void ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_WindowData* wd, const VkAllocationCallbacks* allocator, int w, int h)
+// Also destroy old swap chain and in-flight frames data, if any.
+void ImGui_ImplVulkanH_CreateWindowSwapChain(VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wd, const VkAllocationCallbacks* allocator, int w, int h, uint32_t min_image_count)
{
- uint32_t min_image_count = 2; // FIXME: this should become a function parameter
-
VkResult err;
VkSwapchainKHR old_swapchain = wd->Swapchain;
err = vkDeviceWaitIdle(device);
check_vk_result(err);
+ // We don't use ImGui_ImplVulkanH_DestroyWindow() because we want to preserve the old swapchain to create the new one.
// Destroy old Framebuffer
- for (uint32_t i = 0; i < wd->BackBufferCount; i++)
+ for (uint32_t i = 0; i < wd->ImageCount; i++)
{
- if (wd->BackBufferView[i])
- vkDestroyImageView(device, wd->BackBufferView[i], allocator);
- if (wd->Framebuffer[i])
- vkDestroyFramebuffer(device, wd->Framebuffer[i], allocator);
+ ImGui_ImplVulkanH_DestroyFrame(device, &wd->Frames[i], allocator);
+ ImGui_ImplVulkanH_DestroyFrameSemaphores(device, &wd->FrameSemaphores[i], allocator);
}
- wd->BackBufferCount = 0;
+ IM_FREE(wd->Frames);
+ IM_FREE(wd->FrameSemaphores);
+ wd->Frames = NULL;
+ wd->FrameSemaphores = NULL;
+ wd->ImageCount = 0;
if (wd->RenderPass)
vkDestroyRenderPass(device, wd->RenderPass, allocator);
@@ -940,7 +1060,7 @@ void ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(VkPhysicalDevice
VkSwapchainCreateInfoKHR info = {};
info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
info.surface = wd->Surface;
- info.minImageCount = min_image_count;
+ info.minImageCount = min_image_count;
info.imageFormat = wd->SurfaceFormat.format;
info.imageColorSpace = wd->SurfaceFormat.colorSpace;
info.imageArrayLayers = 1;
@@ -955,9 +1075,9 @@ void ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(VkPhysicalDevice
err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_device, wd->Surface, &cap);
check_vk_result(err);
if (info.minImageCount < cap.minImageCount)
- info.minImageCount = cap.minImageCount;
- else if (cap.maxImageCount != 0 && info.minImageCount > cap.maxImageCount)
- info.minImageCount = cap.maxImageCount;
+ info.minImageCount = cap.minImageCount;
+ else if (cap.maxImageCount != 0 && info.minImageCount > cap.maxImageCount)
+ info.minImageCount = cap.maxImageCount;
if (cap.currentExtent.width == 0xffffffff)
{
@@ -971,10 +1091,21 @@ void ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(VkPhysicalDevice
}
err = vkCreateSwapchainKHR(device, &info, allocator, &wd->Swapchain);
check_vk_result(err);
- err = vkGetSwapchainImagesKHR(device, wd->Swapchain, &wd->BackBufferCount, NULL);
+ err = vkGetSwapchainImagesKHR(device, wd->Swapchain, &wd->ImageCount, NULL);
check_vk_result(err);
- err = vkGetSwapchainImagesKHR(device, wd->Swapchain, &wd->BackBufferCount, wd->BackBuffer);
+ VkImage backbuffers[16] = {};
+ IM_ASSERT(wd->ImageCount >= min_image_count);
+ IM_ASSERT(wd->ImageCount < IM_ARRAYSIZE(backbuffers));
+ err = vkGetSwapchainImagesKHR(device, wd->Swapchain, &wd->ImageCount, backbuffers);
check_vk_result(err);
+
+ IM_ASSERT(wd->Frames == NULL);
+ wd->Frames = (ImGui_ImplVulkanH_Frame*)IM_ALLOC(sizeof(ImGui_ImplVulkanH_Frame) * wd->ImageCount);
+ wd->FrameSemaphores = (ImGui_ImplVulkanH_FrameSemaphores*)IM_ALLOC(sizeof(ImGui_ImplVulkanH_FrameSemaphores) * wd->ImageCount);
+ memset(wd->Frames, 0, sizeof(wd->Frames[0]) * wd->ImageCount);
+ memset(wd->FrameSemaphores, 0, sizeof(wd->FrameSemaphores[0]) * wd->ImageCount);
+ for (uint32_t i = 0; i < wd->ImageCount; i++)
+ wd->Frames[i].Backbuffer = backbuffers[i];
}
if (old_swapchain)
vkDestroySwapchainKHR(device, old_swapchain, allocator);
@@ -1028,10 +1159,11 @@ void ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(VkPhysicalDevice
info.components.a = VK_COMPONENT_SWIZZLE_A;
VkImageSubresourceRange image_range = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 };
info.subresourceRange = image_range;
- for (uint32_t i = 0; i < wd->BackBufferCount; i++)
+ for (uint32_t i = 0; i < wd->ImageCount; i++)
{
- info.image = wd->BackBuffer[i];
- err = vkCreateImageView(device, &info, allocator, &wd->BackBufferView[i]);
+ ImGui_ImplVulkanH_Frame* fd = &wd->Frames[i];
+ info.image = fd->Backbuffer;
+ err = vkCreateImageView(device, &info, allocator, &fd->BackbufferView);
check_vk_result(err);
}
}
@@ -1047,38 +1179,90 @@ void ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(VkPhysicalDevice
info.width = wd->Width;
info.height = wd->Height;
info.layers = 1;
- for (uint32_t i = 0; i < wd->BackBufferCount; i++)
+ for (uint32_t i = 0; i < wd->ImageCount; i++)
{
- attachment[0] = wd->BackBufferView[i];
- err = vkCreateFramebuffer(device, &info, allocator, &wd->Framebuffer[i]);
+ ImGui_ImplVulkanH_Frame* fd = &wd->Frames[i];
+ attachment[0] = fd->BackbufferView;
+ err = vkCreateFramebuffer(device, &info, allocator, &fd->Framebuffer);
check_vk_result(err);
}
}
}
-void ImGui_ImplVulkanH_DestroyWindowData(VkInstance instance, VkDevice device, ImGui_ImplVulkanH_WindowData* wd, const VkAllocationCallbacks* allocator)
+void ImGui_ImplVulkanH_CreateWindow(VkInstance instance, VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wd, uint32_t queue_family, const VkAllocationCallbacks* allocator, int width, int height, uint32_t min_image_count)
+{
+ (void)instance;
+ ImGui_ImplVulkanH_CreateWindowSwapChain(physical_device, device, wd, allocator, width, height, min_image_count);
+ ImGui_ImplVulkanH_CreateWindowCommandBuffers(physical_device, device, wd, queue_family, allocator);
+}
+
+void ImGui_ImplVulkanH_DestroyWindow(VkInstance instance, VkDevice device, ImGui_ImplVulkanH_Window* wd, const VkAllocationCallbacks* allocator)
{
vkDeviceWaitIdle(device); // FIXME: We could wait on the Queue if we had the queue in wd-> (otherwise VulkanH functions can't use globals)
//vkQueueWaitIdle(g_Queue);
- for (int i = 0; i < IMGUI_VK_QUEUED_FRAMES; i++)
+ for (uint32_t i = 0; i < wd->ImageCount; i++)
{
- ImGui_ImplVulkanH_FrameData* fd = &wd->Frames[i];
- vkDestroyFence(device, fd->Fence, allocator);
- vkFreeCommandBuffers(device, fd->CommandPool, 1, &fd->CommandBuffer);
- vkDestroyCommandPool(device, fd->CommandPool, allocator);
- vkDestroySemaphore(device, fd->ImageAcquiredSemaphore, allocator);
- vkDestroySemaphore(device, fd->RenderCompleteSemaphore, allocator);
- }
- for (uint32_t i = 0; i < wd->BackBufferCount; i++)
- {
- vkDestroyImageView(device, wd->BackBufferView[i], allocator);
- vkDestroyFramebuffer(device, wd->Framebuffer[i], allocator);
+ ImGui_ImplVulkanH_DestroyFrame(device, &wd->Frames[i], allocator);
+ ImGui_ImplVulkanH_DestroyFrameSemaphores(device, &wd->FrameSemaphores[i], allocator);
}
+ IM_FREE(wd->Frames);
+ IM_FREE(wd->FrameSemaphores);
+ wd->Frames = NULL;
+ wd->FrameSemaphores = NULL;
vkDestroyRenderPass(device, wd->RenderPass, allocator);
vkDestroySwapchainKHR(device, wd->Swapchain, allocator);
vkDestroySurfaceKHR(instance, wd->Surface, allocator);
- *wd = ImGui_ImplVulkanH_WindowData();
+
+ *wd = ImGui_ImplVulkanH_Window();
+}
+
+void ImGui_ImplVulkanH_DestroyFrame(VkDevice device, ImGui_ImplVulkanH_Frame* fd, const VkAllocationCallbacks* allocator)
+{
+ vkDestroyFence(device, fd->Fence, allocator);
+ vkFreeCommandBuffers(device, fd->CommandPool, 1, &fd->CommandBuffer);
+ vkDestroyCommandPool(device, fd->CommandPool, allocator);
+ fd->Fence = VK_NULL_HANDLE;
+ fd->CommandBuffer = VK_NULL_HANDLE;
+ fd->CommandPool = VK_NULL_HANDLE;
+
+ vkDestroyImageView(device, fd->BackbufferView, allocator);
+ vkDestroyFramebuffer(device, fd->Framebuffer, allocator);
+}
+
+void ImGui_ImplVulkanH_DestroyFrameSemaphores(VkDevice device, ImGui_ImplVulkanH_FrameSemaphores* fsd, const VkAllocationCallbacks* allocator)
+{
+ vkDestroySemaphore(device, fsd->ImageAcquiredSemaphore, allocator);
+ vkDestroySemaphore(device, fsd->RenderCompleteSemaphore, allocator);
+ fsd->ImageAcquiredSemaphore = fsd->RenderCompleteSemaphore = VK_NULL_HANDLE;
+}
+
+void ImGui_ImplVulkanH_DestroyFrameRenderBuffers(VkDevice device, ImGui_ImplVulkanH_FrameRenderBuffers* buffers, const VkAllocationCallbacks* allocator)
+{
+ if (buffers->VertexBuffer) { vkDestroyBuffer(device, buffers->VertexBuffer, allocator); buffers->VertexBuffer = VK_NULL_HANDLE; }
+ if (buffers->VertexBufferMemory) { vkFreeMemory(device, buffers->VertexBufferMemory, allocator); buffers->VertexBufferMemory = VK_NULL_HANDLE; }
+ if (buffers->IndexBuffer) { vkDestroyBuffer(device, buffers->IndexBuffer, allocator); buffers->IndexBuffer = VK_NULL_HANDLE; }
+ if (buffers->IndexBufferMemory) { vkFreeMemory(device, buffers->IndexBufferMemory, allocator); buffers->IndexBufferMemory = VK_NULL_HANDLE; }
+ buffers->VertexBufferSize = 0;
+ buffers->IndexBufferSize = 0;
+}
+
+void ImGui_ImplVulkanH_DestroyWindowRenderBuffers(VkDevice device, ImGui_ImplVulkanH_WindowRenderBuffers* buffers, const VkAllocationCallbacks* allocator)
+{
+ for (uint32_t n = 0; n < buffers->Count; n++)
+ ImGui_ImplVulkanH_DestroyFrameRenderBuffers(device, &buffers->FrameRenderBuffers[n], allocator);
+ IM_FREE(buffers->FrameRenderBuffers);
+ buffers->FrameRenderBuffers = NULL;
+ buffers->Index = 0;
+ buffers->Count = 0;
+}
+
+void ImGui_ImplVulkanH_DestroyAllViewportsRenderBuffers(VkDevice device, const VkAllocationCallbacks* allocator)
+{
+ ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
+ for (int n = 0; n < platform_io.Viewports.Size; n++)
+ if (ImGuiViewportDataVulkan* data = (ImGuiViewportDataVulkan*)platform_io.Viewports[n]->RendererUserData)
+ ImGui_ImplVulkanH_DestroyWindowRenderBuffers(device, &data->RenderBuffers, allocator);
}
//--------------------------------------------------------------------------------------------------------
@@ -1086,52 +1270,43 @@ void ImGui_ImplVulkanH_DestroyWindowData(VkInstance instance, VkDevice device, I
// This is an _advanced_ and _optional_ feature, allowing the back-end to create and handle multiple viewports simultaneously.
// If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first..
//--------------------------------------------------------------------------------------------------------
-// FIXME-PLATFORM: Vulkan support unfinished
-//--------------------------------------------------------------------------------------------------------
-
-struct ImGuiViewportDataVulkan
-{
- ImGui_ImplVulkanH_WindowData WindowData;
-
- ImGuiViewportDataVulkan() { }
- ~ImGuiViewportDataVulkan() { }
-};
static void ImGui_ImplVulkan_CreateWindow(ImGuiViewport* viewport)
{
ImGuiViewportDataVulkan* data = IM_NEW(ImGuiViewportDataVulkan)();
viewport->RendererUserData = data;
- ImGui_ImplVulkanH_WindowData* wd = &data->WindowData;
+ ImGui_ImplVulkanH_Window* wd = &data->Window;
+ ImGui_ImplVulkan_InitInfo* v = &g_VulkanInitInfo;
// Create surface
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
- VkResult err = (VkResult)platform_io.Platform_CreateVkSurface(viewport, (ImU64)g_Instance, (const void*)g_Allocator, (ImU64*)&wd->Surface);
+ VkResult err = (VkResult)platform_io.Platform_CreateVkSurface(viewport, (ImU64)v->Instance, (const void*)v->Allocator, (ImU64*)&wd->Surface);
check_vk_result(err);
// Check for WSI support
VkBool32 res;
- vkGetPhysicalDeviceSurfaceSupportKHR(g_PhysicalDevice, g_QueueFamily, wd->Surface, &res);
+ vkGetPhysicalDeviceSurfaceSupportKHR(v->PhysicalDevice, v->QueueFamily, wd->Surface, &res);
if (res != VK_TRUE)
{
- fprintf(stderr, "Error no WSI support on physical device 0\n");
- exit(-1);
+ IM_ASSERT(0); // Error: no WSI support on physical device
+ return;
}
// Select Surface Format
const VkFormat requestSurfaceImageFormat[] = { VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_B8G8R8_UNORM, VK_FORMAT_R8G8B8_UNORM };
const VkColorSpaceKHR requestSurfaceColorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR;
- wd->SurfaceFormat = ImGui_ImplVulkanH_SelectSurfaceFormat(g_PhysicalDevice, wd->Surface, requestSurfaceImageFormat, (size_t)IM_ARRAYSIZE(requestSurfaceImageFormat), requestSurfaceColorSpace);
+ wd->SurfaceFormat = ImGui_ImplVulkanH_SelectSurfaceFormat(v->PhysicalDevice, wd->Surface, requestSurfaceImageFormat, (size_t)IM_ARRAYSIZE(requestSurfaceImageFormat), requestSurfaceColorSpace);
// Select Present Mode
// FIXME-VULKAN: Even thought mailbox seems to get us maximum framerate with a single window, it halves framerate with a second window etc. (w/ Nvidia and SDK 1.82.1)
VkPresentModeKHR present_modes[] = { VK_PRESENT_MODE_MAILBOX_KHR, VK_PRESENT_MODE_IMMEDIATE_KHR, VK_PRESENT_MODE_FIFO_KHR };
- wd->PresentMode = ImGui_ImplVulkanH_SelectPresentMode(g_PhysicalDevice, wd->Surface, &present_modes[0], IM_ARRAYSIZE(present_modes));
+ wd->PresentMode = ImGui_ImplVulkanH_SelectPresentMode(v->PhysicalDevice, wd->Surface, &present_modes[0], IM_ARRAYSIZE(present_modes));
//printf("[vulkan] Secondary window selected PresentMode = %d\n", wd->PresentMode);
// Create SwapChain, RenderPass, Framebuffer, etc.
wd->ClearEnable = (viewport->Flags & ImGuiViewportFlags_NoRendererClear) ? false : true;
- ImGui_ImplVulkanH_CreateWindowDataCommandBuffers(g_PhysicalDevice, g_Device, g_QueueFamily, wd, g_Allocator);
- ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(g_PhysicalDevice, g_Device, wd, g_Allocator, (int)viewport->Size.x, (int)viewport->Size.y);
+ ImGui_ImplVulkanH_CreateWindow(v->Instance, v->PhysicalDevice, v->Device, wd, v->QueueFamily, v->Allocator, (int)viewport->Size.x, (int)viewport->Size.y, v->MinImageCount);
+ data->WindowOwned = true;
}
static void ImGui_ImplVulkan_DestroyWindow(ImGuiViewport* viewport)
@@ -1139,7 +1314,10 @@ static void ImGui_ImplVulkan_DestroyWindow(ImGuiViewport* viewport)
// The main viewport (owned by the application) will always have RendererUserData == NULL since we didn't create the data for it.
if (ImGuiViewportDataVulkan* data = (ImGuiViewportDataVulkan*)viewport->RendererUserData)
{
- ImGui_ImplVulkanH_DestroyWindowData(g_Instance, g_Device, &data->WindowData, g_Allocator);
+ ImGui_ImplVulkan_InitInfo* v = &g_VulkanInitInfo;
+ if (data->WindowOwned)
+ ImGui_ImplVulkanH_DestroyWindow(v->Instance, v->Device, &data->Window, v->Allocator);
+ ImGui_ImplVulkanH_DestroyWindowRenderBuffers(v->Device, &data->RenderBuffers, v->Allocator);
IM_DELETE(data);
}
viewport->RendererUserData = NULL;
@@ -1150,31 +1328,35 @@ static void ImGui_ImplVulkan_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
ImGuiViewportDataVulkan* data = (ImGuiViewportDataVulkan*)viewport->RendererUserData;
if (data == NULL) // This is NULL for the main viewport (which is left to the user/app to handle)
return;
- data->WindowData.ClearEnable = (viewport->Flags & ImGuiViewportFlags_NoRendererClear) ? false : true;
- ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(g_PhysicalDevice, g_Device, &data->WindowData, g_Allocator, (int)size.x, (int)size.y);
+ ImGui_ImplVulkan_InitInfo* v = &g_VulkanInitInfo;
+ data->Window.ClearEnable = (viewport->Flags & ImGuiViewportFlags_NoRendererClear) ? false : true;
+ ImGui_ImplVulkanH_CreateWindow(v->Instance, v->PhysicalDevice, v->Device, &data->Window, v->QueueFamily, v->Allocator, (int)size.x, (int)size.y, v->MinImageCount);
}
static void ImGui_ImplVulkan_RenderWindow(ImGuiViewport* viewport, void*)
{
ImGuiViewportDataVulkan* data = (ImGuiViewportDataVulkan*)viewport->RendererUserData;
- ImGui_ImplVulkanH_WindowData* wd = &data->WindowData;
+ ImGui_ImplVulkanH_Window* wd = &data->Window;
+ ImGui_ImplVulkan_InitInfo* v = &g_VulkanInitInfo;
VkResult err;
+ ImGui_ImplVulkanH_Frame* fd = &wd->Frames[wd->FrameIndex];
+ ImGui_ImplVulkanH_FrameSemaphores* fsd = &wd->FrameSemaphores[wd->SemaphoreIndex];
{
- ImGui_ImplVulkanH_FrameData* fd = &wd->Frames[wd->FrameIndex];
for (;;)
{
- err = vkWaitForFences(g_Device, 1, &fd->Fence, VK_TRUE, 100);
+ err = vkWaitForFences(v->Device, 1, &fd->Fence, VK_TRUE, 100);
if (err == VK_SUCCESS) break;
if (err == VK_TIMEOUT) continue;
check_vk_result(err);
}
{
- err = vkAcquireNextImageKHR(g_Device, wd->Swapchain, UINT64_MAX, fd->ImageAcquiredSemaphore, VK_NULL_HANDLE, &fd->BackbufferIndex);
+ err = vkAcquireNextImageKHR(v->Device, wd->Swapchain, UINT64_MAX, fsd->ImageAcquiredSemaphore, VK_NULL_HANDLE, &wd->FrameIndex);
check_vk_result(err);
+ fd = &wd->Frames[wd->FrameIndex];
}
{
- err = vkResetCommandPool(g_Device, fd->CommandPool, 0);
+ err = vkResetCommandPool(v->Device, fd->CommandPool, 0);
check_vk_result(err);
VkCommandBufferBeginInfo info = {};
info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
@@ -1189,7 +1371,7 @@ static void ImGui_ImplVulkan_RenderWindow(ImGuiViewport* viewport, void*)
VkRenderPassBeginInfo info = {};
info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
info.renderPass = wd->RenderPass;
- info.framebuffer = wd->Framebuffer[fd->BackbufferIndex];
+ info.framebuffer = fd->Framebuffer;
info.renderArea.extent.width = wd->Width;
info.renderArea.extent.height = wd->Height;
info.clearValueCount = (viewport->Flags & ImGuiViewportFlags_NoRendererClear) ? 0 : 1;
@@ -1198,28 +1380,27 @@ static void ImGui_ImplVulkan_RenderWindow(ImGuiViewport* viewport, void*)
}
}
- ImGui_ImplVulkan_RenderDrawData(viewport->DrawData, wd->Frames[wd->FrameIndex].CommandBuffer);
+ ImGui_ImplVulkan_RenderDrawData(viewport->DrawData, fd->CommandBuffer);
{
- ImGui_ImplVulkanH_FrameData* fd = &wd->Frames[wd->FrameIndex];
vkCmdEndRenderPass(fd->CommandBuffer);
{
VkPipelineStageFlags wait_stage = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
VkSubmitInfo info = {};
info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
info.waitSemaphoreCount = 1;
- info.pWaitSemaphores = &fd->ImageAcquiredSemaphore;
+ info.pWaitSemaphores = &fsd->ImageAcquiredSemaphore;
info.pWaitDstStageMask = &wait_stage;
info.commandBufferCount = 1;
info.pCommandBuffers = &fd->CommandBuffer;
info.signalSemaphoreCount = 1;
- info.pSignalSemaphores = &fd->RenderCompleteSemaphore;
+ info.pSignalSemaphores = &fsd->RenderCompleteSemaphore;
err = vkEndCommandBuffer(fd->CommandBuffer);
check_vk_result(err);
- err = vkResetFences(g_Device, 1, &fd->Fence);
+ err = vkResetFences(v->Device, 1, &fd->Fence);
check_vk_result(err);
- err = vkQueueSubmit(g_Queue, 1, &info, fd->Fence);
+ err = vkQueueSubmit(v->Queue, 1, &info, fd->Fence);
check_vk_result(err);
}
}
@@ -1228,22 +1409,25 @@ static void ImGui_ImplVulkan_RenderWindow(ImGuiViewport* viewport, void*)
static void ImGui_ImplVulkan_SwapBuffers(ImGuiViewport* viewport, void*)
{
ImGuiViewportDataVulkan* data = (ImGuiViewportDataVulkan*)viewport->RendererUserData;
- ImGui_ImplVulkanH_WindowData* wd = &data->WindowData;
+ ImGui_ImplVulkanH_Window* wd = &data->Window;
+ ImGui_ImplVulkan_InitInfo* v = &g_VulkanInitInfo;
VkResult err;
- uint32_t PresentIndex = wd->FrameIndex;
+ uint32_t present_index = wd->FrameIndex;
- ImGui_ImplVulkanH_FrameData* fd = &wd->Frames[PresentIndex];
+ ImGui_ImplVulkanH_FrameSemaphores* fsd = &wd->FrameSemaphores[wd->SemaphoreIndex];
VkPresentInfoKHR info = {};
info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
info.waitSemaphoreCount = 1;
- info.pWaitSemaphores = &fd->RenderCompleteSemaphore;
+ info.pWaitSemaphores = &fsd->RenderCompleteSemaphore;
info.swapchainCount = 1;
info.pSwapchains = &wd->Swapchain;
- info.pImageIndices = &fd->BackbufferIndex;
- err = vkQueuePresentKHR(g_Queue, &info);
+ info.pImageIndices = &present_index;
+ err = vkQueuePresentKHR(v->Queue, &info);
check_vk_result(err);
- wd->FrameIndex = (wd->FrameIndex + 1) % IMGUI_VK_QUEUED_FRAMES;
+
+ wd->FrameIndex = (wd->FrameIndex + 1) % wd->ImageCount; // This is for the next vkWaitForFences()
+ wd->SemaphoreIndex = (wd->SemaphoreIndex + 1) % wd->ImageCount; // Now we can use the next set of semaphores
}
void ImGui_ImplVulkan_InitPlatformInterface()
diff --git a/examples/imgui_impl_vulkan.h b/examples/imgui_impl_vulkan.h
index ec9eb54b..76daf9a2 100644
--- a/examples/imgui_impl_vulkan.h
+++ b/examples/imgui_impl_vulkan.h
@@ -1,6 +1,8 @@
// dear imgui: Renderer for Vulkan
// This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..)
+// Implemented features:
+// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bits indices.
// Missing features:
// [ ] Platform: Multi-viewport / platform windows.
// [ ] Renderer: User texture binding. Changes of ImTextureID aren't supported by this binding! See https://github.com/ocornut/imgui/pull/914
@@ -12,24 +14,33 @@
// The aim of imgui_impl_vulkan.h/.cpp is to be usable in your engine without any modification.
// IF YOU FEEL YOU NEED TO MAKE ANY CHANGE TO THIS CODE, please share them and your feedback at https://github.com/ocornut/imgui/
+// Important note to the reader who wish to integrate imgui_impl_vulkan.cpp/.h in their own engine/app.
+// - Common ImGui_ImplVulkan_XXX functions and structures are used to interface with imgui_impl_vulkan.cpp/.h.
+// You will use those if you want to use this rendering back-end in your engine/app.
+// - Helper ImGui_ImplVulkanH_XXX functions and structures are only used by this example (main.cpp) and by
+// the back-end itself (imgui_impl_vulkan.cpp), but should PROBABLY NOT be used by your own engine/app code.
+// Read comments in imgui_impl_vulkan.h.
+
#pragma once
#include
-#define IMGUI_VK_QUEUED_FRAMES 2
-
-// Please zero-clear before use.
+// Initialization data, for ImGui_ImplVulkan_Init()
+// [Please zero-clear before use!]
struct ImGui_ImplVulkan_InitInfo
{
- VkInstance Instance;
- VkPhysicalDevice PhysicalDevice;
- VkDevice Device;
- uint32_t QueueFamily;
- VkQueue Queue;
- VkPipelineCache PipelineCache;
- VkDescriptorPool DescriptorPool;
- const VkAllocationCallbacks* Allocator;
- void (*CheckVkResultFn)(VkResult err);
+ VkInstance Instance;
+ VkPhysicalDevice PhysicalDevice;
+ VkDevice Device;
+ uint32_t QueueFamily;
+ VkQueue Queue;
+ VkPipelineCache PipelineCache;
+ VkDescriptorPool DescriptorPool;
+ uint32_t MinImageCount; // >= 2
+ uint32_t ImageCount; // >= MinImageCount
+ VkSampleCountFlagBits MSAASamples; // >= VK_SAMPLE_COUNT_1_BIT
+ const VkAllocationCallbacks* Allocator;
+ void (*CheckVkResultFn)(VkResult err);
};
// Called by user code
@@ -38,15 +49,13 @@ IMGUI_IMPL_API void ImGui_ImplVulkan_Shutdown();
IMGUI_IMPL_API void ImGui_ImplVulkan_NewFrame();
IMGUI_IMPL_API void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer command_buffer);
IMGUI_IMPL_API bool ImGui_ImplVulkan_CreateFontsTexture(VkCommandBuffer command_buffer);
-IMGUI_IMPL_API void ImGui_ImplVulkan_InvalidateFontUploadObjects();
-
-// Called by ImGui_ImplVulkan_Init() might be useful elsewhere.
-IMGUI_IMPL_API bool ImGui_ImplVulkan_CreateDeviceObjects();
-IMGUI_IMPL_API void ImGui_ImplVulkan_InvalidateDeviceObjects();
+IMGUI_IMPL_API void ImGui_ImplVulkan_DestroyFontUploadObjects();
+IMGUI_IMPL_API void ImGui_ImplVulkan_SetMinImageCount(uint32_t min_image_count); // To override MinImageCount after initialization (e.g. if swap chain is recreated)
//-------------------------------------------------------------------------
// Internal / Miscellaneous Vulkan Helpers
+// (Used by example's main.cpp. Used by multi-viewport features. PROBABLY NOT used by your own engine/app.)
//-------------------------------------------------------------------------
// You probably do NOT need to use or care about those functions.
// Those functions only exist because:
@@ -54,36 +63,44 @@ IMGUI_IMPL_API void ImGui_ImplVulkan_InvalidateDeviceObjects();
// 2) the multi-viewport / platform window implementation needs them internally.
// Generally we avoid exposing any kind of superfluous high-level helpers in the bindings,
// but it is too much code to duplicate everywhere so we exceptionally expose them.
-// Your application/engine will likely already have code to setup all that stuff (swap chain, render pass, frame buffers, etc.).
+//
+// Your engine/app will likely _already_ have code to setup all that stuff (swap chain, render pass, frame buffers, etc.).
// You may read this code to learn about Vulkan, but it is recommended you use you own custom tailored code to do equivalent work.
-// (those functions do not interact with any of the state used by the regular ImGui_ImplVulkan_XXX functions)
+// (The ImGui_ImplVulkanH_XXX functions do not interact with any of the state used by the regular ImGui_ImplVulkan_XXX functions)
//-------------------------------------------------------------------------
-struct ImGui_ImplVulkanH_FrameData;
-struct ImGui_ImplVulkanH_WindowData;
+struct ImGui_ImplVulkanH_Frame;
+struct ImGui_ImplVulkanH_Window;
-IMGUI_IMPL_API void ImGui_ImplVulkanH_CreateWindowDataCommandBuffers(VkPhysicalDevice physical_device, VkDevice device, uint32_t queue_family, ImGui_ImplVulkanH_WindowData* wd, const VkAllocationCallbacks* allocator);
-IMGUI_IMPL_API void ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_WindowData* wd, const VkAllocationCallbacks* allocator, int w, int h);
-IMGUI_IMPL_API void ImGui_ImplVulkanH_DestroyWindowData(VkInstance instance, VkDevice device, ImGui_ImplVulkanH_WindowData* wd, const VkAllocationCallbacks* allocator);
+// Helpers
+IMGUI_IMPL_API void ImGui_ImplVulkanH_CreateWindow(VkInstance instance, VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wnd, uint32_t queue_family, const VkAllocationCallbacks* allocator, int w, int h, uint32_t min_image_count);
+IMGUI_IMPL_API void ImGui_ImplVulkanH_DestroyWindow(VkInstance instance, VkDevice device, ImGui_ImplVulkanH_Window* wnd, const VkAllocationCallbacks* allocator);
IMGUI_IMPL_API VkSurfaceFormatKHR ImGui_ImplVulkanH_SelectSurfaceFormat(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkFormat* request_formats, int request_formats_count, VkColorSpaceKHR request_color_space);
IMGUI_IMPL_API VkPresentModeKHR ImGui_ImplVulkanH_SelectPresentMode(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkPresentModeKHR* request_modes, int request_modes_count);
IMGUI_IMPL_API int ImGui_ImplVulkanH_GetMinImageCountFromPresentMode(VkPresentModeKHR present_mode);
// Helper structure to hold the data needed by one rendering frame
-struct ImGui_ImplVulkanH_FrameData
+// (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own engine/app.)
+// [Please zero-clear before use!]
+struct ImGui_ImplVulkanH_Frame
{
- uint32_t BackbufferIndex; // Keep track of recently rendered swapchain frame indices
VkCommandPool CommandPool;
VkCommandBuffer CommandBuffer;
VkFence Fence;
+ VkImage Backbuffer;
+ VkImageView BackbufferView;
+ VkFramebuffer Framebuffer;
+};
+
+struct ImGui_ImplVulkanH_FrameSemaphores
+{
VkSemaphore ImageAcquiredSemaphore;
VkSemaphore RenderCompleteSemaphore;
-
- IMGUI_IMPL_API ImGui_ImplVulkanH_FrameData();
};
// Helper structure to hold the data needed by one rendering context into one OS window
-struct ImGui_ImplVulkanH_WindowData
+// (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own engine/app.)
+struct ImGui_ImplVulkanH_Window
{
int Width;
int Height;
@@ -94,13 +111,17 @@ struct ImGui_ImplVulkanH_WindowData
VkRenderPass RenderPass;
bool ClearEnable;
VkClearValue ClearValue;
- uint32_t BackBufferCount;
- VkImage BackBuffer[16];
- VkImageView BackBufferView[16];
- VkFramebuffer Framebuffer[16];
- uint32_t FrameIndex;
- ImGui_ImplVulkanH_FrameData Frames[IMGUI_VK_QUEUED_FRAMES];
-
- IMGUI_IMPL_API ImGui_ImplVulkanH_WindowData();
+ uint32_t FrameIndex; // Current frame being rendered to (0 <= FrameIndex < FrameInFlightCount)
+ uint32_t ImageCount; // Number of simultaneous in-flight frames (returned by vkGetSwapchainImagesKHR, usually derived from min_image_count)
+ uint32_t SemaphoreIndex; // Current set of swapchain wait semaphores we're using (needs to be distinct from per frame data)
+ ImGui_ImplVulkanH_Frame* Frames;
+ ImGui_ImplVulkanH_FrameSemaphores* FrameSemaphores;
+
+ ImGui_ImplVulkanH_Window()
+ {
+ memset(this, 0, sizeof(*this));
+ PresentMode = VK_PRESENT_MODE_MAX_ENUM_KHR;
+ ClearEnable = true;
+ }
};
diff --git a/examples/imgui_impl_win32.cpp b/examples/imgui_impl_win32.cpp
index 7b60dd1b..8a2b6771 100644
--- a/examples/imgui_impl_win32.cpp
+++ b/examples/imgui_impl_win32.cpp
@@ -20,6 +20,7 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
// 2018-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
+// 2019-05-11: Inputs: Don't filter value from WM_CHAR before calling AddInputCharacter().
// 2019-01-17: Misc: Using GetForegroundWindow()+IsChild() instead of GetActiveWindow() to be compatible with windows created in a different thread or parent.
// 2019-01-17: Inputs: Added support for mouse buttons 4 and 5 via WM_XBUTTON* messages.
// 2019-01-15: Inputs: Added support for XInput gamepads (if ImGuiConfigFlags_NavEnableGamepad is set by user application).
@@ -72,7 +73,7 @@ bool ImGui_ImplWin32_Init(void* hwnd)
// Our mouse update function expect PlatformHandle to be filled for the main viewport
g_hWnd = (HWND)hwnd;
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
- main_viewport->PlatformHandle = (void*)g_hWnd;
+ main_viewport->PlatformHandle = main_viewport->PlatformHandleRaw = (void*)g_hWnd;
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
ImGui_ImplWin32_InitPlatformInterface();
@@ -92,6 +93,7 @@ bool ImGui_ImplWin32_Init(void* hwnd)
io.KeyMap[ImGuiKey_Space] = VK_SPACE;
io.KeyMap[ImGuiKey_Enter] = VK_RETURN;
io.KeyMap[ImGuiKey_Escape] = VK_ESCAPE;
+ io.KeyMap[ImGuiKey_KeyPadEnter] = VK_RETURN;
io.KeyMap[ImGuiKey_A] = 'A';
io.KeyMap[ImGuiKey_C] = 'C';
io.KeyMap[ImGuiKey_V] = 'V';
@@ -197,14 +199,6 @@ static void ImGui_ImplWin32_UpdateMousePos()
if (ImGuiViewport* viewport = ImGui::FindViewportByPlatformHandle((void*)hovered_hwnd))
if ((viewport->Flags & ImGuiViewportFlags_NoInputs) == 0) // FIXME: We still get our NoInputs window with WM_NCHITTEST/HTTRANSPARENT code when decorated?
io.MouseHoveredViewport = viewport->ID;
-
-#if 0
- POINT pos;
- if (HWND active_window = ::GetForegroundWindow())
- if (active_window == g_hWnd || ::IsChild(active_window, g_hWnd))
- if (::GetCursorPos(&pos) && ::ScreenToClient(g_hWnd, &pos))
- io.MousePos = ImVec2((float)pos.x, (float)pos.y);
-#endif
}
#ifdef _MSC_VER
@@ -212,7 +206,7 @@ static void ImGui_ImplWin32_UpdateMousePos()
#endif
// Gamepad navigation mapping
-void ImGui_ImplWin32_UpdateGameControllers()
+static void ImGui_ImplWin32_UpdateGamepads()
{
ImGuiIO& io = ImGui::GetIO();
memset(io.NavInputs, 0, sizeof(io.NavInputs));
@@ -294,8 +288,8 @@ void ImGui_ImplWin32_NewFrame()
ImGui_ImplWin32_UpdateMouseCursor();
}
- // Update game controllers (if available)
- ImGui_ImplWin32_UpdateGameControllers();
+ // Update game controllers (if enabled and available)
+ ImGui_ImplWin32_UpdateGamepads();
}
// Allow compilation with old Windows SDK. MinGW doesn't have default _WIN32_WINNT/WINVER versions.
@@ -311,7 +305,7 @@ void ImGui_ImplWin32_NewFrame()
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
-// PS: In this Win32 handler, we use the capture API (GetCapture/SetCapture/ReleaseCapture) to be able to read mouse coordinations when dragging mouse outside of our window bounds.
+// PS: In this Win32 handler, we use the capture API (GetCapture/SetCapture/ReleaseCapture) to be able to read mouse coordinates when dragging mouse outside of our window bounds.
// PS: We treat DBLCLK messages as regular mouse down messages, so this code will work on windows classes that have the CS_DBLCLKS flag set. Our own example app code doesn't set this flag.
IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
@@ -369,8 +363,7 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARA
return 0;
case WM_CHAR:
// You can also use ToAscii()+GetKeyboardState() to retrieve characters.
- if (wParam > 0 && wParam < 0x10000)
- io.AddInputCharacter((unsigned short)wParam);
+ io.AddInputCharacter((unsigned int)wParam);
return 0;
case WM_SETCURSOR:
if (LOWORD(lParam) == HTCLIENT && ImGui_ImplWin32_UpdateMouseCursor())
@@ -447,6 +440,10 @@ void ImGui_ImplWin32_EnableDpiAwareness()
}
}
+#ifdef _MSC_VER
+#pragma comment(lib, "gdi32") // GetDeviceCaps()
+#endif
+
float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor)
{
UINT xdpi = 96, ydpi = 96;
@@ -551,7 +548,7 @@ static void ImGui_ImplWin32_CreateWindow(ImGuiViewport* viewport)
parent_window, NULL, ::GetModuleHandle(NULL), NULL); // Parent window, Menu, Instance, Param
data->HwndOwned = true;
viewport->PlatformRequestResize = false;
- viewport->PlatformHandle = data->Hwnd;
+ viewport->PlatformHandle = viewport->PlatformHandleRaw = data->Hwnd;
}
static void ImGui_ImplWin32_DestroyWindow(ImGuiViewport* viewport)
diff --git a/imconfig.h b/imconfig.h
index 825505bf..22a21db0 100644
--- a/imconfig.h
+++ b/imconfig.h
@@ -3,10 +3,10 @@
// Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure.
// You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions.
//-----------------------------------------------------------------------------
-// A) You may edit imconfig.h (and not overwrite it when updating imgui, or maintain a patch/branch with your modifications to imconfig.h)
+// A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/branch with your modifications to imconfig.h)
// B) or add configuration directives in your own file and compile with #define IMGUI_USER_CONFIG "myfilename.h"
-// If you do so you need to make sure that configuration settings are defined consistently _everywhere_ dear imgui is used, which include
-// the imgui*.cpp files but also _any_ of your code that uses imgui. This is because some compile-time options have an affect on data structures.
+// If you do so you need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include
+// the imgui*.cpp files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures.
// Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts.
// Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using.
//-----------------------------------------------------------------------------
@@ -17,7 +17,8 @@
//#define IM_ASSERT(_EXPR) MyAssert(_EXPR)
//#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts
-//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows.
+//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows
+// Using dear imgui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.
//#define IMGUI_API __declspec( dllexport )
//#define IMGUI_API __declspec( dllimport )
@@ -25,13 +26,15 @@
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
//---- Don't implement demo windows functionality (ShowDemoWindow()/ShowStyleEditor()/ShowUserGuide() methods will be empty)
-//---- It is very strongly recommended to NOT disable the demo windows during development. Please read the comments in imgui_demo.cpp.
+// It is very strongly recommended to NOT disable the demo windows during development. Please read the comments in imgui_demo.cpp.
//#define IMGUI_DISABLE_DEMO_WINDOWS
+//#define IMGUI_DISABLE_METRICS_WINDOW
//---- Don't implement some functions to reduce linkage requirements.
//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc.
//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] Don't implement default IME handler. Won't use and link with ImmGetContext/ImmSetCompositionWindow.
-//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function.
+//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, ime).
+//#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices').
//#define IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself if you don't want to link with vsnprintf.
//#define IMGUI_DISABLE_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 wrapper so you can implement them yourself. Declare your prototypes in imconfig.h.
//#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions().
@@ -61,9 +64,26 @@
operator MyVec4() const { return MyVec4(x,y,z,w); }
*/
-//---- Use 32-bit vertex indices (default is 16-bit) to allow meshes with more than 64K vertices. Render function needs to support it.
+//---- Using 32-bits vertex indices (default is 16-bits) is one way to allow large meshes with more than 64K vertices.
+// Your renderer back-end will need to support it (most example renderer back-ends support both 16/32-bits indices).
+// Another way to allow large meshes while keeping 16-bits indices is to handle ImDrawCmd::VtxOffset in your renderer.
+// Read about ImGuiBackendFlags_RendererHasVtxOffset for details.
//#define ImDrawIdx unsigned int
+//---- Override ImDrawCallback signature (will need to modify renderer back-ends accordingly)
+//struct ImDrawList;
+//struct ImDrawCmd;
+//typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data);
+//#define ImDrawCallback MyImDrawCallback
+
+//---- Debug Tools
+// Use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.
+//#define IM_DEBUG_BREAK IM_ASSERT(0)
+//#define IM_DEBUG_BREAK __debugbreak()
+// Have the Item Picker break in the ItemAdd() function instead of ItemHoverable() - which is earlier in the code, will catch a few extra items, allow picking items other than Hovered one.
+// This adds a small runtime cost which is why it is not enabled by default.
+//#define IMGUI_DEBUG_TOOL_ITEM_PICKER_EX
+
//---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files.
/*
namespace ImGui
diff --git a/imgui.cpp b/imgui.cpp
index 598a41f5..1c58b447 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -1,4 +1,4 @@
-// dear imgui, v1.68 WIP
+// dear imgui, v1.73 WIP
// (main code and documentation)
// Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp for demo code.
@@ -6,7 +6,7 @@
// Get latest version at https://github.com/ocornut/imgui
// Releases change-log at https://github.com/ocornut/imgui/releases
// Technical Support for Getting Started https://discourse.dearimgui.org/c/getting-started
-// Gallery (please post your screenshots/video there!): https://github.com/ocornut/imgui/issues/1269
+// Gallery (please post your screenshots/video there!): https://github.com/ocornut/imgui/issues/2529
// Developed by Omar Cornut and every direct or indirect contributors to the GitHub.
// See LICENSE.txt for copyright and licensing details (standard MIT License).
@@ -37,16 +37,21 @@ DOCUMENTATION
- Using gamepad/keyboard navigation controls.
- API BREAKING CHANGES (read me when you update!)
- FREQUENTLY ASKED QUESTIONS (FAQ), TIPS
+ - Where is the documentation?
+ - Which version should I get?
+ - Who uses Dear ImGui?
+ - Why the odd dual naming, "Dear ImGui" vs "ImGui"?
- How can I tell whether to dispatch mouse/keyboard to imgui or to my application?
- How can I display an image? What is ImTextureID, how does it works?
- - How can I have multiple widgets with the same label or with an empty label? A primer on labels and the ID Stack.
+ - Why are multiple widgets reacting when I interact with a single one? How can I have
+ multiple widgets with the same label or with an empty label? A primer on labels and the ID Stack...
- How can I use my own math types instead of ImVec2/ImVec4?
- How can I load a different font than the default?
- How can I easily use icons in my application?
- How can I load multiple fonts?
- How can I display and input non-latin characters such as Chinese, Japanese, Korean, Cyrillic?
- How can I interact with standard C++ types (such as std::string and std::vector)?
- - How can I use the drawing facilities without an ImGui window? (using ImDrawList API)
+ - How can I use the drawing facilities without a Dear ImGui window? (using ImDrawList API)
- How can I use Dear ImGui on a platform that doesn't have a mouse or a keyboard? (input share, remoting, gamepad)
- I integrated Dear ImGui in my engine and the text or lines are blurry..
- I integrated Dear ImGui in my engine and some elements are clipping or disappearing when I move windows around..
@@ -58,24 +63,24 @@ CODE
// [SECTION] FORWARD DECLARATIONS
// [SECTION] CONTEXT AND MEMORY ALLOCATORS
// [SECTION] MAIN USER FACING STRUCTURES (ImGuiStyle, ImGuiIO)
-// [SECTION] MISC HELPER/UTILITIES (Maths, String, Format, Hash, File functions)
-// [SECTION] MISC HELPER/UTILITIES (ImText* functions)
-// [SECTION] MISC HELPER/UTILITIES (Color functions)
+// [SECTION] MISC HELPERS/UTILITIES (Maths, String, Format, Hash, File functions)
+// [SECTION] MISC HELPERS/UTILITIES (ImText* functions)
+// [SECTION] MISC HELPERS/UTILITIES (Color functions)
// [SECTION] ImGuiStorage
// [SECTION] ImGuiTextFilter
// [SECTION] ImGuiTextBuffer
// [SECTION] ImGuiListClipper
// [SECTION] RENDER HELPERS
// [SECTION] MAIN CODE (most of the code! lots of stuff, needs tidying up!)
+// [SECTION] SCROLLING
// [SECTION] TOOLTIPS
// [SECTION] POPUPS
-// [SECTION] VIEWPORTS, PLATFORM WINDOWS
// [SECTION] KEYBOARD/GAMEPAD NAVIGATION
-// [SECTION] COLUMNS
// [SECTION] DRAG AND DROP
-// [SECTION] DOCKING
// [SECTION] LOGGING/CAPTURING
// [SECTION] SETTINGS
+// [SECTION] VIEWPORTS, PLATFORM WINDOWS
+// [SECTION] DOCKING
// [SECTION] PLATFORM DEPENDENT HELPERS
// [SECTION] METRICS/DEBUG WINDOW
@@ -169,11 +174,11 @@ CODE
- Run and study the examples and demo in imgui_demo.cpp to get acquainted with the library.
- Add the Dear ImGui source files to your projects or using your preferred build system.
It is recommended you build and statically link the .cpp files as part of your project and not as shared library (DLL).
- - You can later customize the imconfig.h file to tweak some compile-time behavior, such as integrating imgui types with your own maths types.
+ - You can later customize the imconfig.h file to tweak some compile-time behavior, such as integrating Dear ImGui types with your own maths types.
- When using Dear ImGui, your programming IDE is your friend: follow the declaration of variables, functions and types to find comments about them.
- Dear ImGui never touches or knows about your GPU state. The only function that knows about GPU is the draw function that you provide.
Effectively it means you can create widgets at any time in your code, regardless of considerations of being in "update" vs "render"
- phases of your own application. All rendering informatioe are stored into command-lists that you will retrieve after calling ImGui::Render().
+ phases of your own application. All rendering information are stored into command-lists that you will retrieve after calling ImGui::Render().
- Refer to the bindings and demo applications in the examples/ folder for instruction on how to setup your code.
- If you are running over a standard OS with a common graphics API, you should be able to use unmodified imgui_impl_*** files from the examples/ folder.
@@ -248,16 +253,16 @@ CODE
io.MouseDown[1] = my_mouse_buttons[1];
// Call NewFrame(), after this point you can use ImGui::* functions anytime
- // (So you want to try calling NewFrame() as early as you can in your mainloop to be able to use imgui everywhere)
+ // (So you want to try calling NewFrame() as early as you can in your mainloop to be able to use Dear ImGui everywhere)
ImGui::NewFrame();
// Most of your application code here
ImGui::Text("Hello, world!");
- MyGameUpdate(); // may use any ImGui functions, e.g. ImGui::Begin("My window"); ImGui::Text("Hello, world!"); ImGui::End();
- MyGameRender(); // may use any ImGui functions as well!
+ MyGameUpdate(); // may use any Dear ImGui functions, e.g. ImGui::Begin("My window"); ImGui::Text("Hello, world!"); ImGui::End();
+ MyGameRender(); // may use any Dear ImGui functions as well!
- // Render imgui, swap buffers
- // (You want to try calling EndFrame/Render as late as you can, to be able to use imgui in your own game rendering code)
+ // Render dear imgui, swap buffers
+ // (You want to try calling EndFrame/Render as late as you can, to be able to use Dear ImGui in your own game rendering code)
ImGui::EndFrame();
ImGui::Render();
ImDrawData* draw_data = ImGui::GetDrawData();
@@ -279,8 +284,8 @@ CODE
for (int n = 0; n < draw_data->CmdListsCount; n++)
{
const ImDrawList* cmd_list = draw_data->CmdLists[n];
- const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data; // vertex buffer generated by ImGui
- const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data; // index buffer generated by ImGui
+ const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data; // vertex buffer generated by Dear ImGui
+ const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data; // index buffer generated by Dear ImGui
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
{
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
@@ -291,7 +296,7 @@ CODE
else
{
// The texture for the draw call is specified by pcmd->TextureId.
- // The vast majority of draw calls will use the imgui texture atlas, which value you have set yourself during initialization.
+ // The vast majority of draw calls will use the Dear ImGui texture atlas, which value you have set yourself during initialization.
MyEngineBindTexture((MyTexture*)pcmd->TextureId);
// We are using scissoring to clip some objects. All low-level graphics API should supports it.
@@ -316,8 +321,8 @@ CODE
- The examples/ folders contains many actual implementation of the pseudo-codes above.
- When calling NewFrame(), the 'io.WantCaptureMouse', 'io.WantCaptureKeyboard' and 'io.WantTextInput' flags are updated.
- They tell you if Dear ImGui intends to use your inputs. When a flag is set you want to hide the corresponding inputs
- from the rest of your application. In every cases you need to pass on the inputs to imgui. Refer to the FAQ for more information.
+ They tell you if Dear ImGui intends to use your inputs. When a flag is set you want to hide the corresponding inputs from the
+ rest of your application. In every cases you need to pass on the inputs to Dear ImGui. Refer to the FAQ for more information.
- Please read the FAQ below!. Amusingly, it is called a FAQ because people frequently run into the same issues!
USING GAMEPAD/KEYBOARD NAVIGATION CONTROLS
@@ -366,18 +371,32 @@ CODE
When you are not sure about a old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files.
You can read releases logs https://github.com/ocornut/imgui/releases for more details.
- (Viewport Branch)
- - 2018/XX/XX (1.XX) - when multi-viewports are enabled, all positions will be in your natural OS coordinates space. It means that:
+ (Docking/Viewport Branch)
+ - 2019/XX/XX (1.XX) - when multi-viewports are enabled, all positions will be in your natural OS coordinates space. It means that:
- reference to hard-coded positions such as in SetNextWindowPos(ImVec2(0,0)) are probably not what you want anymore.
you may use GetMainViewport()->Pos to offset hard-coded positions, e.g. SetNextWindowPos(GetMainViewport()->Pos)
- likewise io.MousePos and GetMousePos() will use OS coordinates.
If you query mouse positions to interact with non-imgui coordinates you will need to offset them, e.g. subtract GetWindowViewport()->Pos.
- - 2018/XX/XX (1.XX) - Moved IME support functions from io.ImeSetInputScreenPosFn, io.ImeWindowHandle to the PlatformIO api.
- - 2018/XX/XX (1.XX) - removed io.DisplayVisibleMin, io.DisplayVisibleMax settings (they were used to clip within the (0,0)..DisplaySize range, I don't know of anyone using it)
-
-
+ - 2019/XX/XX (1.XX) - Moved IME support functions from io.ImeSetInputScreenPosFn, io.ImeWindowHandle to the PlatformIO api.
+
+
+ - 2019/07/15 (1.72) - removed TreeAdvanceToLabelPos() which is rarely used and only does SetCursorPosX(GetCursorPosX() + GetTreeNodeToLabelSpacing()). Kept redirection function (will obsolete).
+ - 2019/07/12 (1.72) - renamed ImFontAtlas::CustomRect to ImFontAtlasCustomRect. Kept redirection typedef (will obsolete).
+ - 2019/06/14 (1.72) - removed redirecting functions/enums names that were marked obsolete in 1.51 (June 2017): ImGuiCol_Column*, ImGuiSetCond_*, IsItemHoveredRect(), IsPosHoveringAnyWindow(), IsMouseHoveringAnyWindow(), IsMouseHoveringWindow(), IMGUI_ONCE_UPON_A_FRAME. Grep this log for details and new names.
+ - 2019/06/07 (1.71) - rendering of child window outer decorations (bg color, border, scrollbars) is now performed as part of the parent window. If you have
+ overlapping child windows in a same parent, and relied on their relative z-order to be mapped to their submission order, this will affect your rendering.
+ This optimization is disabled if the parent window has no visual output, because it appears to be the most common situation leading to the creation of overlapping child windows.
+ Please reach out if you are affected.
+ - 2019/05/13 (1.71) - renamed SetNextTreeNodeOpen() to SetNextItemOpen(). Kept inline redirection function (will obsolete).
+ - 2019/05/11 (1.71) - changed io.AddInputCharacter(unsigned short c) signature to io.AddInputCharacter(unsigned int c).
+ - 2019/04/29 (1.70) - improved ImDrawList thick strokes (>1.0f) preserving correct thickness up to 90 degrees angles (e.g. rectangles). If you have custom rendering using thick lines, they will appear thicker now.
+ - 2019/04/29 (1.70) - removed GetContentRegionAvailWidth(), use GetContentRegionAvail().x instead. Kept inline redirection function (will obsolete).
+ - 2019/03/04 (1.69) - renamed GetOverlayDrawList() to GetForegroundDrawList(). Kept redirection function (will obsolete).
+ - 2019/02/26 (1.69) - renamed ImGuiColorEditFlags_RGB/ImGuiColorEditFlags_HSV/ImGuiColorEditFlags_HEX to ImGuiColorEditFlags_DisplayRGB/ImGuiColorEditFlags_DisplayHSV/ImGuiColorEditFlags_DisplayHex. Kept redirection enums (will obsolete).
+ - 2019/02/14 (1.68) - made it illegal/assert when io.DisplayTime == 0.0f (with an exception for the first frame). If for some reason your time step calculation gives you a zero value, replace it with a dummy small value!
+ - 2019/02/01 (1.68) - removed io.DisplayVisibleMin/DisplayVisibleMax (which were marked obsolete and removed from viewport/docking branch already).
- 2019/01/06 (1.67) - renamed io.InputCharacters[], marked internal as was always intended. Please don't access directly, and use AddInputCharacter() instead!
- - 2019/01/06 (1.67) - renamed ImFontAtlas::GlyphRangesBuilder to ImFontGlyphRangesBuilder. Keep redirection typedef (will obsolete).
+ - 2019/01/06 (1.67) - renamed ImFontAtlas::GlyphRangesBuilder to ImFontGlyphRangesBuilder. Kept redirection typedef (will obsolete).
- 2018/12/20 (1.67) - made it illegal to call Begin("") with an empty string. This somehow half-worked before but had various undesirable side-effects.
- 2018/12/10 (1.67) - renamed io.ConfigResizeWindowsFromEdges to io.ConfigWindowsResizeFromEdges as we are doing a large pass on configuration flags.
- 2018/10/12 (1.66) - renamed misc/stl/imgui_stl.* to misc/cpp/imgui_stdlib.* in prevision for other C++ helper files.
@@ -396,8 +415,9 @@ CODE
- 2018/07/22 (1.63) - changed ImGui::GetTime() return value from float to double to avoid accumulating floating point imprecisions over time.
- 2018/07/08 (1.63) - style: renamed ImGuiCol_ModalWindowDarkening to ImGuiCol_ModalWindowDimBg for consistency with other features. Kept redirection enum (will obsolete).
- 2018/06/08 (1.62) - examples: the imgui_impl_xxx files have been split to separate platform (Win32, Glfw, SDL2, etc.) from renderer (DX11, OpenGL, Vulkan, etc.).
- old binding will still work as is, however prefer using the separated bindings as they will be updated to be multi-viewport conformant.
+ old bindings will still work as is, however prefer using the separated bindings as they will be updated to support multi-viewports.
when adopting new bindings follow the main.cpp code of your preferred examples/ folder to know which functions to call.
+ in particular, note that old bindings called ImGui::NewFrame() at the end of their ImGui_ImplXXXX_NewFrame() function.
- 2018/06/06 (1.62) - renamed GetGlyphRangesChinese() to GetGlyphRangesChineseFull() to distinguish other variants and discourage using the full set.
- 2018/06/06 (1.62) - TreeNodeEx()/TreeNodeBehavior(): the ImGuiTreeNodeFlags_CollapsingHeader helper now include the ImGuiTreeNodeFlags_NoTreePushOnOpen flag. See Changelog for details.
- 2018/05/03 (1.61) - DragInt(): the default compile-time format string has been changed from "%.0f" to "%d", as we are not using integers internally any more.
@@ -444,9 +464,12 @@ CODE
- 2017/10/20 (1.52) - changed IsWindowHovered() default parameters behavior to return false if an item is active in another window (e.g. click-dragging item from another window to this window). You can use the newly introduced IsWindowHovered() flags to requests this specific behavior if you need it.
- 2017/10/20 (1.52) - marked IsItemHoveredRect()/IsMouseHoveringWindow() as obsolete, in favor of using the newly introduced flags for IsItemHovered() and IsWindowHovered(). See https://github.com/ocornut/imgui/issues/1382 for details.
removed the IsItemRectHovered()/IsWindowRectHovered() names introduced in 1.51 since they were merely more consistent names for the two functions we are now obsoleting.
+ IsItemHoveredRect() --> IsItemHovered(ImGuiHoveredFlags_RectOnly)
+ IsMouseHoveringAnyWindow() --> IsWindowHovered(ImGuiHoveredFlags_AnyWindow)
+ IsMouseHoveringWindow() --> IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem) [weird, old behavior]
- 2017/10/17 (1.52) - marked the old 5-parameters version of Begin() as obsolete (still available). Use SetNextWindowSize()+Begin() instead!
- 2017/10/11 (1.52) - renamed AlignFirstTextHeightToWidgets() to AlignTextToFramePadding(). Kept inline redirection function (will obsolete).
- - 2017/09/26 (1.52) - renamed ImFont::Glyph to ImFontGlyph. Keep redirection typedef (will obsolete).
+ - 2017/09/26 (1.52) - renamed ImFont::Glyph to ImFontGlyph. Kept redirection typedef (will obsolete).
- 2017/09/25 (1.52) - removed SetNextWindowPosCenter() because SetNextWindowPos() now has the optional pivot information to do the same and more. Kept redirection function (will obsolete).
- 2017/08/25 (1.52) - io.MousePos needs to be set to ImVec2(-FLT_MAX,-FLT_MAX) when mouse is unavailable/missing. Previously ImVec2(-1,-1) was enough but we now accept negative mouse coordinates. In your binding if you need to support unavailable mouse, make sure to replace "io.MousePos = ImVec2(-1,-1)" with "io.MousePos = ImVec2(-FLT_MAX,-FLT_MAX)".
- 2017/08/22 (1.51) - renamed IsItemHoveredRect() to IsItemRectHovered(). Kept inline redirection function (will obsolete). -> (1.52) use IsItemHovered(ImGuiHoveredFlags_RectOnly)!
@@ -454,10 +477,10 @@ CODE
- renamed IsMouseHoveringWindow() to IsWindowRectHovered() for consistency. Kept inline redirection function (will obsolete).
- 2017/08/20 (1.51) - renamed GetStyleColName() to GetStyleColorName() for consistency.
- 2017/08/20 (1.51) - added PushStyleColor(ImGuiCol idx, ImU32 col) overload, which _might_ cause an "ambiguous call" compilation error if you are using ImColor() with implicit cast. Cast to ImU32 or ImVec4 explicily to fix.
- - 2017/08/15 (1.51) - marked the weird IMGUI_ONCE_UPON_A_FRAME helper macro as obsolete. prefer using the more explicit ImGuiOnceUponAFrame.
+ - 2017/08/15 (1.51) - marked the weird IMGUI_ONCE_UPON_A_FRAME helper macro as obsolete. prefer using the more explicit ImGuiOnceUponAFrame type.
- 2017/08/15 (1.51) - changed parameter order for BeginPopupContextWindow() from (const char*,int buttons,bool also_over_items) to (const char*,int buttons,bool also_over_items). Note that most calls relied on default parameters completely.
- - 2017/08/13 (1.51) - renamed ImGuiCol_Columns*** to ImGuiCol_Separator***. Kept redirection enums (will obsolete).
- - 2017/08/11 (1.51) - renamed ImGuiSetCond_*** types and flags to ImGuiCond_***. Kept redirection enums (will obsolete).
+ - 2017/08/13 (1.51) - renamed ImGuiCol_Column to ImGuiCol_Separator, ImGuiCol_ColumnHovered to ImGuiCol_SeparatorHovered, ImGuiCol_ColumnActive to ImGuiCol_SeparatorActive. Kept redirection enums (will obsolete).
+ - 2017/08/11 (1.51) - renamed ImGuiSetCond_Always to ImGuiCond_Always, ImGuiSetCond_Once to ImGuiCond_Once, ImGuiSetCond_FirstUseEver to ImGuiCond_FirstUseEver, ImGuiSetCond_Appearing to ImGuiCond_Appearing. Kept redirection enums (will obsolete).
- 2017/08/09 (1.51) - removed ValueColor() helpers, they are equivalent to calling Text(label) + SameLine() + ColorButton().
- 2017/08/08 (1.51) - removed ColorEditMode() and ImGuiColorEditMode in favor of ImGuiColorEditFlags and parameters to the various Color*() functions. The SetColorEditOptions() allows to initialize default but the user can still change them with right-click context menu.
- changed prototype of 'ColorEdit4(const char* label, float col[4], bool show_alpha = true)' to 'ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flags = 0)', where passing flags = 0x01 is a safe no-op (hello dodgy backward compatibility!). - check and run the demo window, under "Color/Picker Widgets", to understand the various new options.
@@ -560,7 +583,40 @@ CODE
FREQUENTLY ASKED QUESTIONS (FAQ), TIPS
======================================
- Q: How can I tell whether to dispatch mouse/keyboard to imgui or to my application?
+ Q: Where is the documentation?
+ A: This library is poorly documented at the moment and expects of the user to be acquainted with C/C++.
+ - Run the examples/ and explore them.
+ - See demo code in imgui_demo.cpp and particularly the ImGui::ShowDemoWindow() function.
+ - The demo covers most features of Dear ImGui, so you can read the code and see its output.
+ - See documentation and comments at the top of imgui.cpp + effectively imgui.h.
+ - Dozens of standalone example applications using e.g. OpenGL/DirectX are provided in the examples/
+ folder to explain how to integrate Dear ImGui with your own engine/application.
+ - Your programming IDE is your friend, find the type or function declaration to find comments
+ associated to it.
+
+ Q: Which version should I get?
+ A: I occasionally tag Releases (https://github.com/ocornut/imgui/releases) but it is generally safe
+ and recommended to sync to master/latest. The library is fairly stable and regressions tend to be
+ fixed fast when reported. You may also peak at the 'docking' branch which includes:
+ - Docking/Merging features (https://github.com/ocornut/imgui/issues/2109)
+ - Multi-viewport features (https://github.com/ocornut/imgui/issues/1542)
+ Many projects are using this branch and it is kept in sync with master regularly.
+
+ Q: Who uses Dear ImGui?
+ A: See "Quotes" (https://github.com/ocornut/imgui/wiki/Quotes) and
+ "Software using Dear ImGui" (https://github.com/ocornut/imgui/wiki/Software-using-dear-imgui) Wiki pages
+ for a list of games/software which are publicly known to use dear imgui. Please add yours if you can!
+
+ Q: Why the odd dual naming, "Dear ImGui" vs "ImGui"?
+ A: The library started its life as "ImGui" due to the fact that I didn't give it a proper name when
+ when I released 1.0, and had no particular expectation that it would take off. However, the term IMGUI
+ (immediate-mode graphical user interface) was coined before and is being used in variety of other
+ situations (e.g. Unity uses it own implementation of the IMGUI paradigm).
+ To reduce the ambiguity without affecting existing code bases, I have decided on an alternate,
+ longer name "Dear ImGui" that people can use to refer to this specific library.
+ Please try to refer to this library as "Dear ImGui".
+
+ Q: How can I tell whether to dispatch mouse/keyboard to Dear ImGui or to my application?
A: You can read the 'io.WantCaptureMouse', 'io.WantCaptureKeyboard' and 'io.WantTextInput' flags from the ImGuiIO structure (e.g. if (ImGui::GetIO().WantCaptureMouse) { ... } )
- When 'io.WantCaptureMouse' is set, imgui wants to use your mouse state, and you may want to discard/hide the inputs from the rest of your application.
- When 'io.WantCaptureKeyboard' is set, imgui wants to use your keyboard state, and you may want to discard/hide the inputs from the rest of your application.
@@ -593,7 +649,7 @@ CODE
- In the examples/ bindings, for each graphics API binding we decided on a type that is likely to be a good representation for specifying
an image from the end-user perspective. This is what the _examples_ rendering functions are using:
- OpenGL: ImTextureID = GLuint (see ImGui_ImplGlfwGL3_RenderDrawData() function in imgui_impl_glfw_gl3.cpp)
+ OpenGL: ImTextureID = GLuint (see ImGui_ImplOpenGL3_RenderDrawData() function in imgui_impl_opengl3.cpp)
DirectX9: ImTextureID = LPDIRECT3DTEXTURE9 (see ImGui_ImplDX9_RenderDrawData() function in imgui_impl_dx9.cpp)
DirectX11: ImTextureID = ID3D11ShaderResourceView* (see ImGui_ImplDX11_RenderDrawData() function in imgui_impl_dx11.cpp)
DirectX12: ImTextureID = D3D12_GPU_DESCRIPTOR_HANDLE (see ImGui_ImplDX12_RenderDrawData() function in imgui_impl_dx12.cpp)
@@ -645,8 +701,8 @@ CODE
// Now that we have an OpenGL texture, assuming our imgui rendering function (imgui_impl_xxx.cpp file) takes GLuint as ImTextureID, we can display it:
ImGui::Image((void*)(intptr_t)my_opengl_texture, ImVec2(my_image_width, my_image_height));
- C/C++ tip: a void* is pointer-sized storage. You may safely store any pointer or integer into it by casting your value to ImTexture / void*, and vice-versa.
- Because both end-points (user code and rendering function) are under your control, you know exactly what is stored inside the ImTexture / void*.
+ C/C++ tip: a void* is pointer-sized storage. You may safely store any pointer or integer into it by casting your value to ImTextureID / void*, and vice-versa.
+ Because both end-points (user code and rendering function) are under your control, you know exactly what is stored inside the ImTextureID / void*.
Examples:
GLuint my_tex = XXX;
@@ -661,8 +717,8 @@ CODE
Finally, you may call ImGui::ShowMetricsWindow() to explore/visualize/understand how the ImDrawList are generated.
+ Q: Why are multiple widgets reacting when I interact with a single one?
Q: How can I have multiple widgets with the same label or with an empty label?
- Q: I have multiple widgets with the same label, and only the first one works. Why is that?
A: A primer on labels and the ID Stack...
Dear ImGui internally need to uniquely identify UI elements.
@@ -779,7 +835,7 @@ CODE
Q: How can I use my own math types instead of ImVec2/ImVec4?
A: You can edit imconfig.h and setup the IM_VEC2_CLASS_EXTRA/IM_VEC4_CLASS_EXTRA macros to add implicit type conversions.
- This way you'll be able to use your own types everywhere, e.g. passsing glm::vec2 to ImGui functions instead of ImVec2.
+ This way you'll be able to use your own types everywhere, e.g. passing glm::vec2 to ImGui functions instead of ImVec2.
Q: How can I load a different font than the default?
A: Use the font atlas to load the TTF/OTF file you want:
@@ -801,6 +857,8 @@ CODE
main font. Then you can refer to icons within your strings.
You may want to see ImFontConfig::GlyphMinAdvanceX to make your icon look monospace to facilitate alignment.
(Read the 'misc/fonts/README.txt' file for more details about icons font loading.)
+ With some extra effort, you may use colorful icon by registering custom rectangle space inside the font atlas,
+ and copying your own graphics data into it. See misc/fonts/README.txt about using the AddCustomRectFontGlyph API.
Q: How can I load multiple fonts?
A: Use the font atlas to pack them into a single texture:
@@ -816,9 +874,9 @@ CODE
// Options
ImFontConfig config;
- config.OversampleH = 3;
+ config.OversampleH = 2;
config.OversampleV = 1;
- config.GlyphOffset.y -= 2.0f; // Move everything by 2 pixels up
+ config.GlyphOffset.y -= 1.0f; // Move everything by 1 pixels up
config.GlyphExtraSpacing.x = 1.0f; // Increase spacing between characters
io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_pixels, &config);
@@ -883,9 +941,10 @@ CODE
A: - You can create a dummy window. Call Begin() with the NoBackground | NoDecoration | NoSavedSettings | NoInputs flags.
(The ImGuiWindowFlags_NoDecoration flag itself is a shortcut for NoTitleBar | NoResize | NoScrollbar | NoCollapse)
Then you can retrieve the ImDrawList* via GetWindowDrawList() and draw to it in any way you like.
- - You can call ImGui::GetOverlayDrawList() and use this draw list to display contents over every other imgui windows (1 overlay per viewport).
- - You can create your own ImDrawList instance. You'll need to initialize them ImGui::GetDrawListSharedData(), or create your own ImDrawListSharedData,
- and then call your rendered code with your own ImDrawList or ImDrawData data.
+ - You can call ImGui::GetBackgroundDrawList() or ImGui::GetForegroundDrawList() and use those draw list to display
+ contents behind or over every other imgui windows (one bg/fg drawlist per viewport).
+ - You can create your own ImDrawList instance. You'll need to initialize them ImGui::GetDrawListSharedData(), or create
+ your own ImDrawListSharedData, and then call your rendered code with your own ImDrawList or ImDrawData data.
Q: How can I use this without a mouse, without a keyboard or without a screen? (gamepad, input share, remote display)
A: - You can control Dear ImGui with a gamepad. Read about navigation in "Using gamepad/keyboard navigation controls".
@@ -940,7 +999,7 @@ CODE
#endif
#include "imgui_internal.h"
-#include // toupper, isprint
+#include // toupper
#include // vsnprintf, sscanf, printf
#if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier
#include // intptr_t
@@ -951,7 +1010,7 @@ CODE
// Debug options
#define IMGUI_DEBUG_NAV_SCORING 0 // Display navigation scoring preview when hovering items. Display last moving direction matches when holding CTRL
#define IMGUI_DEBUG_NAV_RECTS 0 // Display the reference navigation rectangle for each window
-#define IMGUI_DEBUG_DOCKING_INI 0 // Save additional comments in .ini file (makes saving slower)
+#define IMGUI_DEBUG_INI_SETTINGS 0 // Save additional comments in .ini file (particularly helps for Docking, but makes saving slower)
// Visual Studio warnings
#ifdef _MSC_VER
@@ -960,13 +1019,13 @@ CODE
#endif
// Clang/GCC warnings with -Weverything
-#ifdef __clang__
+#if defined(__clang__)
#pragma clang diagnostic ignored "-Wunknown-pragmas" // warning : unknown warning group '-Wformat-pedantic *' // not all warnings are known by all clang versions.. so ignoring warnings triggers new warnings on some configuration. great!
#pragma clang diagnostic ignored "-Wold-style-cast" // warning : use of old-style cast // yes, they are more terse.
#pragma clang diagnostic ignored "-Wfloat-equal" // warning : comparing floating point with == or != is unsafe // storing and comparing against same constants (typically 0.0f) is ok.
#pragma clang diagnostic ignored "-Wformat-nonliteral" // warning : format string is not a string literal // passing non-literal to vsnformat(). yes, user passing incorrect format strings can crash the code.
#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 "-Wglobal-constructors" // warning : declaration requires a global destructor // similar to above, not sure what the exact difference it.
+#pragma clang diagnostic ignored "-Wglobal-constructors" // warning : declaration requires a global destructor // similar to above, not sure what the exact difference is.
#pragma clang diagnostic ignored "-Wsign-conversion" // warning : implicit conversion changes signedness //
#pragma clang diagnostic ignored "-Wformat-pedantic" // warning : format specifies type 'void *' but the argument has type 'xxxx *' // unreasonable, would lead to casting every %p arg to void*. probably enabled by -pedantic.
#pragma clang diagnostic ignored "-Wint-to-void-pointer-cast" // warning : cast to 'void *' from smaller integer type 'int'
@@ -977,6 +1036,8 @@ CODE
#pragma clang diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function // using printf() is a misery with this as C++ va_arg ellipsis changes float to double.
#endif
#elif defined(__GNUC__)
+// We disable -Wpragmas because GCC doesn't provide an has_warning equivalent and some forks/patches may not following the warning/version association.
+#pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind
#pragma GCC diagnostic ignored "-Wunused-function" // warning: 'xxxx' defined but not used
#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" // warning: cast to pointer from integer of different size
#pragma GCC diagnostic ignored "-Wformat" // warning: format '%p' expects argument of type 'void*', but argument 6 has type 'ImGuiWindow*'
@@ -984,9 +1045,7 @@ CODE
#pragma GCC diagnostic ignored "-Wconversion" // warning: conversion to 'xxxx' from 'xxxx' may alter its value
#pragma GCC diagnostic ignored "-Wformat-nonliteral" // warning: format not a string literal, format string not checked
#pragma GCC diagnostic ignored "-Wstrict-overflow" // warning: assuming signed overflow does not occur when assuming that (X - c) > X is always false
-#if __GNUC__ >= 8
-#pragma GCC diagnostic ignored "-Wclass-memaccess" // warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead
-#endif
+#pragma GCC diagnostic ignored "-Wclass-memaccess" // [__GNUC__ >= 8] warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead
#endif
// When using CTRL+TAB (or Gamepad Square+L/R) we delay the visual a little in order to reduce visual noise doing a fast switch.
@@ -996,6 +1055,7 @@ static const float NAV_WINDOWING_LIST_APPEAR_DELAY = 0.15f; // Time
// Window resizing from edges (when io.ConfigWindowsResizeFromEdges = true and ImGuiBackendFlags_HasMouseCursors is set in io.BackendFlags by back-end)
static const float WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS = 4.0f; // Extend outside and inside windows. Affect FindHoveredWindow().
static const float WINDOWS_RESIZE_FROM_EDGES_FEEDBACK_TIMER = 0.04f; // Reduce visual noise by only highlighting the border after a certain time.
+static const float WINDOWS_MOUSE_WHEEL_SCROLL_LOCK_TIMER = 2.00f; // Lock scrolled window (so it doesn't pick child windows that are scrolling through) for a certaint time, unless mouse moved.
// Docking
static const float DOCKING_TRANSPARENT_PAYLOAD_ALPHA = 0.50f; // For use with io.ConfigDockingTransparentPayload. Apply to Viewport _or_ WindowBg in host viewport.
@@ -1005,9 +1065,6 @@ static const float DOCKING_TRANSPARENT_PAYLOAD_ALPHA = 0.50f; // For u
//-------------------------------------------------------------------------
static void SetCurrentWindow(ImGuiWindow* window);
-static void SetWindowPos(ImGuiWindow* window, const ImVec2& pos, ImGuiCond cond);
-static void SetWindowSize(ImGuiWindow* window, const ImVec2& size, ImGuiCond cond);
-static void SetWindowCollapsed(ImGuiWindow* window, bool collapsed, ImGuiCond cond);
static void SetWindowHitTestHole(ImGuiWindow* window, const ImVec2& pos, const ImVec2& size);
static void FindHoveredWindow();
static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFlags flags);
@@ -1037,16 +1094,20 @@ static void NavUpdateWindowingList();
static void NavUpdateMoveResult();
static float NavUpdatePageUpPageDown(int allowed_dir_flags);
static inline void NavUpdateAnyRequestFlag();
-static void NavProcessItem(ImGuiWindow* window, const ImRect& nav_bb, const ImGuiID id);
+static void NavProcessItem(ImGuiWindow* window, const ImRect& nav_bb, ImGuiID id);
static ImVec2 NavCalcPreferredRefPos();
-static void NavSaveLastChildNavWindow(ImGuiWindow* nav_window);
+static void NavSaveLastChildNavWindowIntoParent(ImGuiWindow* nav_window);
static ImGuiWindow* NavRestoreLastChildNavWindow(ImGuiWindow* window);
+static int FindWindowFocusIndex(ImGuiWindow* window);
// Misc
static void UpdateMouseInputs();
static void UpdateMouseWheel();
-static void UpdateManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4]);
-static void RenderOuterBorders(ImGuiWindow* window);
+static bool UpdateManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4]);
+static void UpdateDebugToolItemPicker();
+static void RenderWindowOuterBorders(ImGuiWindow* window);
+static void RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar_rect, bool title_bar_is_highlight, bool handle_borders_and_resize_grips, int resize_grip_count, const ImU32 resize_grip_col[4], float resize_grip_draw_size);
+static void RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& title_bar_rect, const char* name, bool* p_open);
static void EndFrameDrawDimmedBackgrounds();
// Viewports
@@ -1056,10 +1117,12 @@ static void UpdateViewportsNewFrame();
static void UpdateViewportsEndFrame();
static void UpdateSelectWindowViewport(ImGuiWindow* window);
static bool UpdateTryMergeWindowIntoHostViewport(ImGuiWindow* window, ImGuiViewportP* host_viewport);
+static bool UpdateTryMergeWindowIntoHostViewports(ImGuiWindow* window);
static void SetCurrentViewport(ImGuiWindow* window, ImGuiViewportP* viewport);
static bool GetWindowAlwaysWantOwnViewport(ImGuiWindow* window);
static int FindPlatformMonitorForPos(const ImVec2& pos);
static int FindPlatformMonitorForRect(const ImRect& r);
+static void UpdateViewportPlatformMonitor(ImGuiViewportP* viewport);
}
@@ -1112,6 +1175,7 @@ ImGuiStyle::ImGuiStyle()
WindowBorderSize = 1.0f; // Thickness of border around windows. Generally set to 0.0f or 1.0f. Other values not well tested.
WindowMinSize = ImVec2(32,32); // Minimum window size
WindowTitleAlign = ImVec2(0.0f,0.5f);// Alignment for title bar text
+ WindowMenuButtonPosition= ImGuiDir_Left; // Position of the collapsing/docking button in the title bar (left/right). Defaults to ImGuiDir_Left.
ChildRounding = 0.0f; // Radius of child window corners rounding. Set to 0.0f to have rectangular child windows
ChildBorderSize = 1.0f; // Thickness of border around child windows. Generally set to 0.0f or 1.0f. Other values not well tested.
PopupRounding = 0.0f; // Radius of popup window corners rounding. Set to 0.0f to have rectangular child windows
@@ -1123,14 +1187,16 @@ ImGuiStyle::ImGuiStyle()
ItemInnerSpacing = ImVec2(4,4); // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label)
TouchExtraPadding = ImVec2(0,0); // 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!
IndentSpacing = 21.0f; // Horizontal spacing when e.g. entering a tree node. Generally == (FontSize + FramePadding.x*2).
- ColumnsMinSpacing = 6.0f; // Minimum horizontal spacing between two columns
- ScrollbarSize = 16.0f; // Width of the vertical scrollbar, Height of the horizontal scrollbar
+ ColumnsMinSpacing = 6.0f; // Minimum horizontal spacing between two columns. Preferably > (FramePadding.x + 1).
+ ScrollbarSize = 14.0f; // Width of the vertical scrollbar, Height of the horizontal scrollbar
ScrollbarRounding = 9.0f; // Radius of grab corners rounding for scrollbar
GrabMinSize = 10.0f; // Minimum width/height of a grab box for slider/scrollbar
GrabRounding = 0.0f; // Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs.
TabRounding = 4.0f; // Radius of upper corners of a tab. Set to 0.0f to have rectangular tabs.
TabBorderSize = 0.0f; // Thickness of border around tabs.
+ ColorButtonPosition = ImGuiDir_Right; // Side of the color button in the ColorEdit4 widget (left/right). Defaults to ImGuiDir_Right.
ButtonTextAlign = ImVec2(0.5f,0.5f);// Alignment of button text when button is larger than text.
+ SelectableTextAlign = ImVec2(0.0f,0.0f);// Alignment of selectable text when button is larger than text.
DisplayWindowPadding = ImVec2(19,19); // Window position are clamped to be visible within the display area or monitors by at least this amount. Only applies to regular windows.
DisplaySafeAreaPadding = ImVec2(3,3); // If you cannot see the edge of your screen (e.g. on a TV) increase the safe area padding. Covers popups/tooltips as well regular windows.
MouseCursorScale = 1.0f; // Scale software rendered mouse cursor (when io.MouseDrawCursor is enabled). May be removed later.
@@ -1153,7 +1219,6 @@ void ImGuiStyle::ScaleAllSizes(float scale_factor)
PopupRounding = ImFloor(PopupRounding * scale_factor);
FramePadding = ImFloor(FramePadding * scale_factor);
FrameRounding = ImFloor(FrameRounding * scale_factor);
- TabRounding = ImFloor(TabRounding * scale_factor);
ItemSpacing = ImFloor(ItemSpacing * scale_factor);
ItemInnerSpacing = ImFloor(ItemInnerSpacing * scale_factor);
TouchExtraPadding = ImFloor(TouchExtraPadding * scale_factor);
@@ -1163,6 +1228,7 @@ void ImGuiStyle::ScaleAllSizes(float scale_factor)
ScrollbarRounding = ImFloor(ScrollbarRounding * scale_factor);
GrabMinSize = ImFloor(GrabMinSize * scale_factor);
GrabRounding = ImFloor(GrabRounding * scale_factor);
+ TabRounding = ImFloor(TabRounding * scale_factor);
DisplayWindowPadding = ImFloor(DisplayWindowPadding * scale_factor);
DisplaySafeAreaPadding = ImFloor(DisplaySafeAreaPadding * scale_factor);
MouseCursorScale = ImFloor(MouseCursorScale * scale_factor);
@@ -1198,14 +1264,14 @@ ImGuiIO::ImGuiIO()
// Docking options (when ImGuiConfigFlags_DockingEnable is set)
ConfigDockingNoSplit = false;
ConfigDockingWithShift = false;
- ConfigDockingTabBarOnSingleWindows = false;
+ ConfigDockingAlwaysTabBar = false;
ConfigDockingTransparentPayload = false;
// Viewport options (when ImGuiConfigFlags_ViewportsEnable is set)
ConfigViewportsNoAutoMerge = false;
ConfigViewportsNoTaskBarIcon = false;
ConfigViewportsNoDecoration = true;
- ConfigViewportsNoParent = false;
+ ConfigViewportsNoDefaultParent = false;
// Miscellaneous options
MouseDrawCursor = false;
@@ -1217,6 +1283,7 @@ ImGuiIO::ImGuiIO()
ConfigInputTextCursorBlink = true;
ConfigWindowsResizeFromEdges = true;
ConfigWindowsMoveFromTitleBarOnly = false;
+ ConfigWindowsMemoryCompactTimer = 60.0f;
// Platform Functions
BackendPlatformName = BackendRendererName = NULL;
@@ -1241,9 +1308,10 @@ ImGuiIO::ImGuiIO()
// Pass in translated ASCII characters for text input.
// - with glfw you can get those from the callback set in glfwSetCharCallback()
// - on Windows you can get those using ToAscii+keyboard state, or via the WM_CHAR message
-void ImGuiIO::AddInputCharacter(ImWchar c)
+void ImGuiIO::AddInputCharacter(unsigned int c)
{
- InputQueueCharacters.push_back(c);
+ if (c > 0 && c < 0x10000)
+ InputQueueCharacters.push_back((ImWchar)c);
}
void ImGuiIO::AddInputCharactersUTF8(const char* utf8_chars)
@@ -1252,7 +1320,7 @@ void ImGuiIO::AddInputCharactersUTF8(const char* utf8_chars)
{
unsigned int c = 0;
utf8_chars += ImTextCharFromUtf8(&c, utf8_chars, NULL);
- if (c > 0 && c <= 0xFFFF)
+ if (c > 0 && c < 0x10000)
InputQueueCharacters.push_back((ImWchar)c);
}
}
@@ -1263,7 +1331,7 @@ void ImGuiIO::ClearInputCharacters()
}
//-----------------------------------------------------------------------------
-// [SECTION] MISC HELPER/UTILITIES (Maths, String, Format, Hash, File functions)
+// [SECTION] MISC HELPERS/UTILITIES (Maths, String, Format, Hash, File functions)
//-----------------------------------------------------------------------------
ImVec2 ImLineClosestPoint(const ImVec2& a, const ImVec2& b, const ImVec2& p)
@@ -1331,7 +1399,7 @@ int ImStrnicmp(const char* str1, const char* str2, size_t count)
void ImStrncpy(char* dst, const char* src, size_t count)
{
- if (count < 1)
+ if (count < 1)
return;
if (count > 1)
strncpy(dst, src, count - 1);
@@ -1341,7 +1409,7 @@ void ImStrncpy(char* dst, const char* src, size_t count)
char* ImStrdup(const char* str)
{
size_t len = strlen(str);
- void* buf = ImGui::MemAlloc(len + 1);
+ void* buf = IM_ALLOC(len + 1);
return (char*)memcpy(buf, (const void*)str, len + 1);
}
@@ -1351,8 +1419,8 @@ char* ImStrdupcpy(char* dst, size_t* p_dst_size, const char* src)
size_t src_size = strlen(src) + 1;
if (dst_buf_size < src_size)
{
- ImGui::MemFree(dst);
- dst = (char*)ImGui::MemAlloc(src_size);
+ IM_FREE(dst);
+ dst = (char*)IM_ALLOC(src_size);
if (p_dst_size)
*p_dst_size = src_size;
}
@@ -1367,7 +1435,7 @@ const char* ImStrchrRange(const char* str, const char* str_end, char c)
int ImStrlenW(const ImWchar* str)
{
- //return (int)wcslen((const wchar_t*)str); // FIXME-OPT: Could use this when wchar_t are 16-bits
+ //return (int)wcslen((const wchar_t*)str); // FIXME-OPT: Could use this when wchar_t are 16-bits
int n = 0;
while (*str++) n++;
return n;
@@ -1484,7 +1552,7 @@ int ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args)
// CRC32 needs a 1KB lookup table (not cache friendly)
// Although the code to generate the table is simple and shorter than the table itself, using a const table allows us to easily:
// - avoid an unnecessary branch/memory tap, - keep the ImHashXXX functions usable by static constructors, - make it thread-safe.
-static const ImU32 GCrc32LookupTable[256] =
+static const ImU32 GCrc32LookupTable[256] =
{
0x00000000,0x77073096,0xEE0E612C,0x990951BA,0x076DC419,0x706AF48F,0xE963A535,0x9E6495A3,0x0EDB8832,0x79DCB8A4,0xE0D5E91E,0x97D2D988,0x09B64C2B,0x7EB17CBD,0xE7B82D07,0x90BF1D91,
0x1DB71064,0x6AB020F2,0xF3B97148,0x84BE41DE,0x1ADAD47D,0x6DDDE4EB,0xF4D4B551,0x83D385C7,0x136C9856,0x646BA8C0,0xFD62F97A,0x8A65C9EC,0x14015C4F,0x63066CD9,0xFA0F3D63,0x8D080DF5,
@@ -1523,27 +1591,27 @@ ImU32 ImHashData(const void* data_p, size_t data_size, ImU32 seed)
// - If we reach ### in the string we discard the hash so far and reset to the seed.
// - We don't do 'current += 2; continue;' after handling ### to keep the code smaller/faster (measured ~10% diff in Debug build)
// FIXME-OPT: Replace with e.g. FNV1a hash? CRC32 pretty much randomly access 1KB. Need to do proper measurements.
-ImU32 ImHashStr(const char* data, size_t data_size, ImU32 seed)
+ImU32 ImHashStr(const char* data_p, size_t data_size, ImU32 seed)
{
seed = ~seed;
ImU32 crc = seed;
- const unsigned char* src = (const unsigned char*)data;
+ const unsigned char* data = (const unsigned char*)data_p;
const ImU32* crc32_lut = GCrc32LookupTable;
if (data_size != 0)
{
while (data_size-- != 0)
{
- unsigned char c = *src++;
- if (c == '#' && src[0] == '#' && src[1] == '#')
+ unsigned char c = *data++;
+ if (c == '#' && data_size >= 2 && data[0] == '#' && data[1] == '#')
crc = seed;
crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c];
}
}
else
{
- while (unsigned char c = *src++)
+ while (unsigned char c = *data++)
{
- if (c == '#' && src[0] == '#' && src[1] == '#')
+ if (c == '#' && data[0] == '#' && data[1] == '#')
crc = seed;
crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c];
}
@@ -1568,7 +1636,7 @@ FILE* ImFileOpen(const char* filename, const char* mode)
}
// Load file content into memory
-// Memory allocated with ImGui::MemAlloc(), must be freed by user using ImGui::MemFree()
+// Memory allocated with IM_ALLOC(), must be freed by user using IM_FREE() == ImGui::MemFree()
void* ImFileLoadToMemory(const char* filename, const char* file_open_mode, size_t* out_file_size, int padding_bytes)
{
IM_ASSERT(filename && file_open_mode);
@@ -1587,7 +1655,7 @@ void* ImFileLoadToMemory(const char* filename, const char* file_open_mode, size_
}
size_t file_size = (size_t)file_size_signed;
- void* file_data = ImGui::MemAlloc(file_size + padding_bytes);
+ void* file_data = IM_ALLOC(file_size + padding_bytes);
if (file_data == NULL)
{
fclose(f);
@@ -1596,7 +1664,7 @@ void* ImFileLoadToMemory(const char* filename, const char* file_open_mode, size_
if (fread(file_data, 1, file_size, f) != file_size)
{
fclose(f);
- ImGui::MemFree(file_data);
+ IM_FREE(file_data);
return NULL;
}
if (padding_bytes > 0)
@@ -1793,7 +1861,7 @@ int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_e
}
//-----------------------------------------------------------------------------
-// [SECTION] MISC HELPER/UTILTIES (Color functions)
+// [SECTION] MISC HELPERS/UTILTIES (Color functions)
// Note: The Convert functions are early design which are not consistent with other API.
//-----------------------------------------------------------------------------
@@ -1906,15 +1974,15 @@ ImU32 ImGui::GetColorU32(ImU32 col)
//-----------------------------------------------------------------------------
// std::lower_bound but without the bullshit
-static ImGuiStorage::Pair* LowerBound(ImVector& data, ImGuiID key)
+static ImGuiStorage::ImGuiStoragePair* LowerBound(ImVector& data, ImGuiID key)
{
- ImGuiStorage::Pair* first = data.Data;
- ImGuiStorage::Pair* last = data.Data + data.Size;
+ ImGuiStorage::ImGuiStoragePair* first = data.Data;
+ ImGuiStorage::ImGuiStoragePair* last = data.Data + data.Size;
size_t count = (size_t)(last - first);
while (count > 0)
{
size_t count2 = count >> 1;
- ImGuiStorage::Pair* mid = first + count2;
+ ImGuiStorage::ImGuiStoragePair* mid = first + count2;
if (mid->key < key)
{
first = ++mid;
@@ -1936,18 +2004,18 @@ void ImGuiStorage::BuildSortByKey()
static int IMGUI_CDECL PairCompareByID(const void* lhs, const void* rhs)
{
// We can't just do a subtraction because qsort uses signed integers and subtracting our ID doesn't play well with that.
- if (((const Pair*)lhs)->key > ((const Pair*)rhs)->key) return +1;
- if (((const Pair*)lhs)->key < ((const Pair*)rhs)->key) return -1;
+ if (((const ImGuiStoragePair*)lhs)->key > ((const ImGuiStoragePair*)rhs)->key) return +1;
+ if (((const ImGuiStoragePair*)lhs)->key < ((const ImGuiStoragePair*)rhs)->key) return -1;
return 0;
}
};
if (Data.Size > 1)
- ImQsort(Data.Data, (size_t)Data.Size, sizeof(Pair), StaticFunc::PairCompareByID);
+ ImQsort(Data.Data, (size_t)Data.Size, sizeof(ImGuiStoragePair), StaticFunc::PairCompareByID);
}
int ImGuiStorage::GetInt(ImGuiID key, int default_val) const
{
- ImGuiStorage::Pair* it = LowerBound(const_cast&>(Data), key);
+ ImGuiStoragePair* it = LowerBound(const_cast&>(Data), key);
if (it == Data.end() || it->key != key)
return default_val;
return it->val_i;
@@ -1960,7 +2028,7 @@ bool ImGuiStorage::GetBool(ImGuiID key, bool default_val) const
float ImGuiStorage::GetFloat(ImGuiID key, float default_val) const
{
- ImGuiStorage::Pair* it = LowerBound(const_cast&>(Data), key);
+ ImGuiStoragePair* it = LowerBound(const_cast&>(Data), key);
if (it == Data.end() || it->key != key)
return default_val;
return it->val_f;
@@ -1968,7 +2036,7 @@ float ImGuiStorage::GetFloat(ImGuiID key, float default_val) const
void* ImGuiStorage::GetVoidPtr(ImGuiID key) const
{
- ImGuiStorage::Pair* it = LowerBound(const_cast&>(Data), key);
+ ImGuiStoragePair* it = LowerBound(const_cast&>(Data), key);
if (it == Data.end() || it->key != key)
return NULL;
return it->val_p;
@@ -1977,9 +2045,9 @@ void* ImGuiStorage::GetVoidPtr(ImGuiID key) const
// References are only valid until a new value is added to the storage. Calling a Set***() function or a Get***Ref() function invalidates the pointer.
int* ImGuiStorage::GetIntRef(ImGuiID key, int default_val)
{
- ImGuiStorage::Pair* it = LowerBound(Data, key);
+ ImGuiStoragePair* it = LowerBound(Data, key);
if (it == Data.end() || it->key != key)
- it = Data.insert(it, Pair(key, default_val));
+ it = Data.insert(it, ImGuiStoragePair(key, default_val));
return &it->val_i;
}
@@ -1990,27 +2058,27 @@ bool* ImGuiStorage::GetBoolRef(ImGuiID key, bool default_val)
float* ImGuiStorage::GetFloatRef(ImGuiID key, float default_val)
{
- ImGuiStorage::Pair* it = LowerBound(Data, key);
+ ImGuiStoragePair* it = LowerBound(Data, key);
if (it == Data.end() || it->key != key)
- it = Data.insert(it, Pair(key, default_val));
+ it = Data.insert(it, ImGuiStoragePair(key, default_val));
return &it->val_f;
}
void** ImGuiStorage::GetVoidPtrRef(ImGuiID key, void* default_val)
{
- ImGuiStorage::Pair* it = LowerBound(Data, key);
+ ImGuiStoragePair* it = LowerBound(Data, key);
if (it == Data.end() || it->key != key)
- it = Data.insert(it, Pair(key, default_val));
+ it = Data.insert(it, ImGuiStoragePair(key, default_val));
return &it->val_p;
}
// FIXME-OPT: Need a way to reuse the result of lower_bound when doing GetInt()/SetInt() - not too bad because it only happens on explicit interaction (maximum one a frame)
void ImGuiStorage::SetInt(ImGuiID key, int val)
{
- ImGuiStorage::Pair* it = LowerBound(Data, key);
+ ImGuiStoragePair* it = LowerBound(Data, key);
if (it == Data.end() || it->key != key)
{
- Data.insert(it, Pair(key, val));
+ Data.insert(it, ImGuiStoragePair(key, val));
return;
}
it->val_i = val;
@@ -2023,10 +2091,10 @@ void ImGuiStorage::SetBool(ImGuiID key, bool val)
void ImGuiStorage::SetFloat(ImGuiID key, float val)
{
- ImGuiStorage::Pair* it = LowerBound(Data, key);
+ ImGuiStoragePair* it = LowerBound(Data, key);
if (it == Data.end() || it->key != key)
{
- Data.insert(it, Pair(key, val));
+ Data.insert(it, ImGuiStoragePair(key, val));
return;
}
it->val_f = val;
@@ -2034,10 +2102,10 @@ void ImGuiStorage::SetFloat(ImGuiID key, float val)
void ImGuiStorage::SetVoidPtr(ImGuiID key, void* val)
{
- ImGuiStorage::Pair* it = LowerBound(Data, key);
+ ImGuiStoragePair* it = LowerBound(Data, key);
if (it == Data.end() || it->key != key)
{
- Data.insert(it, Pair(key, val));
+ Data.insert(it, ImGuiStoragePair(key, val));
return;
}
it->val_p = val;
@@ -2071,16 +2139,14 @@ ImGuiTextFilter::ImGuiTextFilter(const char* default_filter)
bool ImGuiTextFilter::Draw(const char* label, float width)
{
if (width != 0.0f)
- ImGui::PushItemWidth(width);
+ ImGui::SetNextItemWidth(width);
bool value_changed = ImGui::InputText(label, InputBuf, IM_ARRAYSIZE(InputBuf));
- if (width != 0.0f)
- ImGui::PopItemWidth();
if (value_changed)
Build();
return value_changed;
}
-void ImGuiTextFilter::TextRange::split(char separator, ImVector* out) const
+void ImGuiTextFilter::ImGuiTextRange::split(char separator, ImVector* out) const
{
out->resize(0);
const char* wb = b;
@@ -2089,25 +2155,25 @@ void ImGuiTextFilter::TextRange::split(char separator, ImVector* out)
{
if (*we == separator)
{
- out->push_back(TextRange(wb, we));
+ out->push_back(ImGuiTextRange(wb, we));
wb = we + 1;
}
we++;
}
if (wb != we)
- out->push_back(TextRange(wb, we));
+ out->push_back(ImGuiTextRange(wb, we));
}
void ImGuiTextFilter::Build()
{
Filters.resize(0);
- TextRange input_range(InputBuf, InputBuf+strlen(InputBuf));
+ ImGuiTextRange input_range(InputBuf, InputBuf+strlen(InputBuf));
input_range.split(',', &Filters);
CountGrep = 0;
for (int i = 0; i != Filters.Size; i++)
{
- TextRange& f = Filters[i];
+ ImGuiTextRange& f = Filters[i];
while (f.b < f.e && ImCharIsBlankA(f.b[0]))
f.b++;
while (f.e > f.b && ImCharIsBlankA(f.e[-1]))
@@ -2129,19 +2195,19 @@ bool ImGuiTextFilter::PassFilter(const char* text, const char* text_end) const
for (int i = 0; i != Filters.Size; i++)
{
- const TextRange& f = Filters[i];
+ const ImGuiTextRange& f = Filters[i];
if (f.empty())
continue;
if (f.b[0] == '-')
{
// Subtract
- if (ImStristr(text, text_end, f.begin()+1, f.end()) != NULL)
+ if (ImStristr(text, text_end, f.b + 1, f.e) != NULL)
return false;
}
else
{
// Grep
- if (ImStristr(text, text_end, f.begin(), f.end()) != NULL)
+ if (ImStristr(text, text_end, f.b, f.e) != NULL)
return true;
}
}
@@ -2224,20 +2290,64 @@ void ImGuiTextBuffer::appendfv(const char* fmt, va_list args)
//-----------------------------------------------------------------------------
// [SECTION] ImGuiListClipper
-// This is currently not as flexible/powerful as it should be, needs some rework (see TODO)
+// This is currently not as flexible/powerful as it should be and really confusing/spaghetti, mostly because we changed
+// the API mid-way through development and support two ways to using the clipper, needs some rework (see TODO)
//-----------------------------------------------------------------------------
+// Helper to calculate coarse clipping of large list of evenly sized items.
+// NB: Prefer using the ImGuiListClipper higher-level helper if you can! Read comments and instructions there on how those use this sort of pattern.
+// NB: 'items_count' is only used to clamp the result, if you don't know your count you can use INT_MAX
+void ImGui::CalcListClipping(int items_count, float items_height, int* out_items_display_start, int* out_items_display_end)
+{
+ ImGuiContext& g = *GImGui;
+ ImGuiWindow* window = g.CurrentWindow;
+ if (g.LogEnabled)
+ {
+ // If logging is active, do not perform any clipping
+ *out_items_display_start = 0;
+ *out_items_display_end = items_count;
+ return;
+ }
+ if (window->SkipItems)
+ {
+ *out_items_display_start = *out_items_display_end = 0;
+ return;
+ }
+
+ // We create the union of the ClipRect and the NavScoringRect which at worst should be 1 page away from ClipRect
+ ImRect unclipped_rect = window->ClipRect;
+ if (g.NavMoveRequest)
+ unclipped_rect.Add(g.NavScoringRectScreen);
+
+ const ImVec2 pos = window->DC.CursorPos;
+ int start = (int)((unclipped_rect.Min.y - pos.y) / items_height);
+ int end = (int)((unclipped_rect.Max.y - pos.y) / items_height);
+
+ // When performing a navigation request, ensure we have one item extra in the direction we are moving to
+ if (g.NavMoveRequest && g.NavMoveClipDir == ImGuiDir_Up)
+ start--;
+ if (g.NavMoveRequest && g.NavMoveClipDir == ImGuiDir_Down)
+ end++;
+
+ start = ImClamp(start, 0, items_count);
+ end = ImClamp(end + 1, start, items_count);
+ *out_items_display_start = start;
+ *out_items_display_end = end;
+}
+
static void SetCursorPosYAndSetupDummyPrevLine(float pos_y, float line_height)
{
// Set cursor position and a few other things so that SetScrollHereY() and Columns() can work when seeking cursor.
// FIXME: It is problematic that we have to do that here, because custom/equivalent end-user code would stumble on the same issue.
// The clipper should probably have a 4th step to display the last item in a regular manner.
- ImGui::SetCursorPosY(pos_y);
- ImGuiWindow* window = ImGui::GetCurrentWindow();
- window->DC.CursorPosPrevLine.y = window->DC.CursorPos.y - line_height; // Setting those fields so that SetScrollHereY() can properly function after the end of our clipper usage.
- window->DC.PrevLineSize.y = (line_height - GImGui->Style.ItemSpacing.y); // If we end up needing more accurate data (to e.g. use SameLine) we may as well make the clipper have a fourth step to let user process and display the last item in their list.
- if (window->DC.ColumnsSet)
- window->DC.ColumnsSet->LineMinY = window->DC.CursorPos.y; // Setting this so that cell Y position are set properly
+ ImGuiContext& g = *GImGui;
+ ImGuiWindow* window = g.CurrentWindow;
+ window->DC.CursorPos.y = pos_y;
+ window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, pos_y);
+ window->DC.CursorPosPrevLine.y = window->DC.CursorPos.y - line_height; // Setting those fields so that SetScrollHereY() can properly function after the end of our clipper usage.
+ window->DC.PrevLineSize.y = (line_height - g.Style.ItemSpacing.y); // If we end up needing more accurate data (to e.g. use SameLine) we may as well make the clipper have a fourth step to let user process and display the last item in their list.
+ if (ImGuiColumns* columns = window->DC.CurrentColumns)
+ columns->LineMinY = window->DC.CursorPos.y; // Setting this so that cell Y position are set properly
}
// Use case A: Begin() called from constructor with items_height<0, then called again from Sync() in StepNo 1
@@ -2245,7 +2355,10 @@ static void SetCursorPosYAndSetupDummyPrevLine(float pos_y, float line_height)
// FIXME-LEGACY: Ideally we should remove the Begin/End functions but they are part of the legacy API we still support. This is why some of the code in Step() calling Begin() and reassign some fields, spaghetti style.
void ImGuiListClipper::Begin(int count, float items_height)
{
- StartPosY = ImGui::GetCursorPosY();
+ ImGuiContext& g = *GImGui;
+ ImGuiWindow* window = g.CurrentWindow;
+
+ StartPosY = window->DC.CursorPos.y;
ItemsHeight = items_height;
ItemsCount = count;
StepNo = 0;
@@ -2272,7 +2385,10 @@ void ImGuiListClipper::End()
bool ImGuiListClipper::Step()
{
- if (ItemsCount == 0 || ImGui::GetCurrentWindowRead()->SkipItems)
+ ImGuiContext& g = *GImGui;
+ ImGuiWindow* window = g.CurrentWindow;
+
+ if (ItemsCount == 0 || window->SkipItems)
{
ItemsCount = -1;
return false;
@@ -2281,16 +2397,16 @@ bool ImGuiListClipper::Step()
{
DisplayStart = 0;
DisplayEnd = 1;
- StartPosY = ImGui::GetCursorPosY();
+ StartPosY = window->DC.CursorPos.y;
StepNo = 1;
return true;
}
if (StepNo == 1) // 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.
{
if (ItemsCount == 1) { ItemsCount = -1; return false; }
- float items_height = ImGui::GetCursorPosY() - StartPosY;
+ float items_height = window->DC.CursorPos.y - StartPosY;
IM_ASSERT(items_height > 0.0f); // If this triggers, it means Item 0 hasn't moved the cursor vertically
- Begin(ItemsCount-1, items_height);
+ Begin(ItemsCount - 1, items_height);
DisplayStart++;
DisplayEnd++;
StepNo = 3;
@@ -2413,6 +2529,60 @@ void ImGui::RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, cons
LogRenderedText(&pos_min, text, text_display_end);
}
+
+// Another overly complex function until we reorganize everything into a nice all-in-one helper.
+// This is made more complex because we have dissociated the layout rectangle (pos_min..pos_max) which define _where_ the ellipsis is, from actual clipping of text and limit of the ellipsis display.
+// This is because in the context of tabs we selectively hide part of the text when the Close Button appears, but we don't want the ellipsis to move.
+void ImGui::RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, const ImVec2& pos_max, float clip_max_x, float ellipsis_max_x, const char* text, const char* text_end_full, const ImVec2* text_size_if_known)
+{
+ ImGuiContext& g = *GImGui;
+ if (text_end_full == NULL)
+ text_end_full = FindRenderedTextEnd(text);
+ const ImVec2 text_size = text_size_if_known ? *text_size_if_known : CalcTextSize(text, text_end_full, false, 0.0f);
+
+ if (text_size.x > pos_max.x - pos_min.x)
+ {
+ // Hello wo...
+ // | | |
+ // min max ellipsis_max
+ // <-> this is generally some padding value
+
+ // FIXME-STYLE: RenderPixelEllipsis() style should use actual font data.
+ const ImFont* font = draw_list->_Data->Font;
+ const float font_size = draw_list->_Data->FontSize;
+ const int ellipsis_dot_count = 3;
+ const float ellipsis_width = (1.0f + 1.0f) * ellipsis_dot_count - 1.0f;
+ const char* text_end_ellipsis = NULL;
+
+ float text_width = ImMax((pos_max.x - ellipsis_width) - pos_min.x, 1.0f);
+ float text_size_clipped_x = font->CalcTextSizeA(font_size, text_width, 0.0f, text, text_end_full, &text_end_ellipsis).x;
+ if (text == text_end_ellipsis && text_end_ellipsis < text_end_full)
+ {
+ // Always display at least 1 character if there's no room for character + ellipsis
+ text_end_ellipsis = text + ImTextCountUtf8BytesFromChar(text, text_end_full);
+ text_size_clipped_x = font->CalcTextSizeA(font_size, FLT_MAX, 0.0f, text, text_end_ellipsis).x;
+ }
+ while (text_end_ellipsis > text && ImCharIsBlankA(text_end_ellipsis[-1]))
+ {
+ // Trim trailing space before ellipsis
+ text_end_ellipsis--;
+ text_size_clipped_x -= font->CalcTextSizeA(font_size, FLT_MAX, 0.0f, text_end_ellipsis, text_end_ellipsis + 1).x; // Ascii blanks are always 1 byte
+ }
+ RenderTextClippedEx(draw_list, pos_min, ImVec2(clip_max_x, pos_max.y), text, text_end_ellipsis, &text_size, ImVec2(0.0f, 0.0f));
+
+ const float ellipsis_x = pos_min.x + text_size_clipped_x + 1.0f;
+ if (ellipsis_x + ellipsis_width - 1.0f <= ellipsis_max_x)
+ RenderPixelEllipsis(draw_list, ImVec2(ellipsis_x, pos_min.y), GetColorU32(ImGuiCol_Text), ellipsis_dot_count);
+ }
+ else
+ {
+ RenderTextClippedEx(draw_list, pos_min, ImVec2(clip_max_x, pos_max.y), text, text_end_full, &text_size, ImVec2(0.0f, 0.0f));
+ }
+
+ if (g.LogEnabled)
+ LogRenderedText(&pos_min, text, text_end_full);
+}
+
// Render a rectangle shaped with optional rounding and borders
void ImGui::RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border, float rounding)
{
@@ -2440,13 +2610,11 @@ void ImGui::RenderFrameBorder(ImVec2 p_min, ImVec2 p_max, float rounding)
}
// Render an arrow aimed to be aligned with text (p_min is a position in the same space text would be positioned). To e.g. denote expanded/collapsed state
-void ImGui::RenderArrow(ImVec2 p_min, ImGuiDir dir, float scale)
+void ImGui::RenderArrow(ImDrawList* draw_list, ImVec2 pos, ImU32 col, ImGuiDir dir, float scale)
{
- ImGuiContext& g = *GImGui;
-
- const float h = g.FontSize * 1.00f;
+ const float h = draw_list->_Data->FontSize * 1.00f;
float r = h * 0.40f * scale;
- ImVec2 center = p_min + ImVec2(h * 0.50f, h * 0.50f * scale);
+ ImVec2 center = pos + ImVec2(h * 0.50f, h * 0.50f * scale);
ImVec2 a, b, c;
switch (dir)
@@ -2470,15 +2638,12 @@ void ImGui::RenderArrow(ImVec2 p_min, ImGuiDir dir, float scale)
IM_ASSERT(0);
break;
}
-
- g.CurrentWindow->DrawList->AddTriangleFilled(center + a, center + b, center + c, GetColorU32(ImGuiCol_Text));
+ draw_list->AddTriangleFilled(center + a, center + b, center + c, col);
}
-void ImGui::RenderBullet(ImVec2 pos)
+void ImGui::RenderBullet(ImDrawList* draw_list, ImVec2 pos, ImU32 col)
{
- ImGuiContext& g = *GImGui;
- ImGuiWindow* window = g.CurrentWindow;
- window->DrawList->AddCircleFilled(pos, g.FontSize*0.20f, GetColorU32(ImGuiCol_Text), 8);
+ draw_list->AddCircleFilled(pos, draw_list->_Data->FontSize * 0.20f, col, 8);
}
void ImGui::RenderCheckMark(ImVec2 pos, ImU32 col, float sz)
@@ -2540,7 +2705,7 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name)
: DrawListInst(&context->DrawListSharedData)
{
Name = ImStrdup(name);
- ID = ImHashStr(name, 0);
+ ID = ImHashStr(name);
IDStack.push_back(ID);
Flags = FlagsPreviousFrame = ImGuiWindowFlags_None;
Viewport = NULL;
@@ -2549,7 +2714,7 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name)
ViewportPos = ImVec2(FLT_MAX, FLT_MAX);
Pos = ImVec2(0.0f, 0.0f);
Size = SizeFull = ImVec2(0.0f, 0.0f);
- SizeContents = SizeContentsExplicit = ImVec2(0.0f, 0.0f);
+ ContentSize = ContentSizeExplicit = ImVec2(0.0f, 0.0f);
WindowPadding = ImVec2(0.0f, 0.0f);
WindowRounding = 0.0f;
WindowBorderSize = 0.0f;
@@ -2569,6 +2734,7 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name)
SkipItems = false;
Appearing = false;
Hidden = false;
+ IsFallbackWindow = false;
HasCloseButton = false;
ResizeBorderHeld = -1;
BeginCount = 0;
@@ -2579,11 +2745,13 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name)
AutoFitOnlyGrows = false;
AutoFitChildAxises = 0x00;
AutoPosLastDirection = ImGuiDir_None;
- HiddenFramesRegular = HiddenFramesForResize = 0;
+ HiddenFramesCanSkipItems = HiddenFramesCannotSkipItems = 0;
SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = SetWindowDockAllowFlags = ImGuiCond_Always | ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing;
SetWindowPosVal = SetWindowPosPivot = ImVec2(FLT_MAX, FLT_MAX);
LastFrameActive = -1;
+ LastFrameJustFocused = -1;
+ LastTimeActive = -1.0f;
ItemWidthDefault = 0.0f;
FontWindowScale = FontDpiScale = 1.0f;
SettingsIdx = -1;
@@ -2600,13 +2768,12 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name)
NavRectRel[0] = NavRectRel[1] = ImRect();
NavLastChildNavWindow = NULL;
- FocusIdxAllCounter = FocusIdxTabCounter = -1;
- FocusIdxAllRequestCurrent = FocusIdxTabRequestCurrent = INT_MAX;
- FocusIdxAllRequestNext = FocusIdxTabRequestNext = INT_MAX;
+ MemoryCompacted = false;
+ MemoryDrawListIdxCapacity = MemoryDrawListVtxCapacity = 0;
DockNode = DockNodeAsHost = NULL;
DockId = 0;
- DockTabItemStatusFlags = 0;
+ DockTabItemStatusFlags = ImGuiItemStatusFlags_None;
DockOrder = -1;
DockIsActive = DockTabIsVisible = DockTabWantClose = false;
}
@@ -2616,7 +2783,7 @@ ImGuiWindow::~ImGuiWindow()
IM_ASSERT(DrawList == &DrawListInst);
IM_DELETE(Name);
for (int i = 0; i != ColumnsStorage.Size; i++)
- ColumnsStorage[i].~ImGuiColumnsSet();
+ ColumnsStorage[i].~ImGuiColumns();
}
ImGuiID ImGuiWindow::GetID(const char* str, const char* str_end)
@@ -2635,6 +2802,14 @@ ImGuiID ImGuiWindow::GetID(const void* ptr)
return id;
}
+ImGuiID ImGuiWindow::GetID(int n)
+{
+ ImGuiID seed = IDStack.back();
+ ImGuiID id = ImHashData(&n, sizeof(n), seed);
+ ImGui::KeepAliveID(id);
+ return id;
+}
+
ImGuiID ImGuiWindow::GetIDNoKeepAlive(const char* str, const char* str_end)
{
ImGuiID seed = IDStack.back();
@@ -2647,6 +2822,12 @@ ImGuiID ImGuiWindow::GetIDNoKeepAlive(const void* ptr)
return ImHashData(&ptr, sizeof(void*), seed);
}
+ImGuiID ImGuiWindow::GetIDNoKeepAlive(int n)
+{
+ ImGuiID seed = IDStack.back();
+ return ImHashData(&n, sizeof(n), seed);
+}
+
// This is only used in rare/specific situations to manufacture an ID out of nowhere.
ImGuiID ImGuiWindow::GetIDFromRectangle(const ImRect& r_abs)
{
@@ -2665,6 +2846,36 @@ static void SetCurrentWindow(ImGuiWindow* window)
g.FontSize = g.DrawListSharedData.FontSize = window->CalcFontSize();
}
+// Free up/compact internal window buffers, we can use this when a window becomes unused.
+// This is currently unused by the library, but you may call this yourself for easy GC.
+// Not freed:
+// - ImGuiWindow, ImGuiWindowSettings, Name
+// - StateStorage, ColumnsStorage (may hold useful data)
+// This should have no noticeable visual effect. When the window reappear however, expect new allocation/buffer growth/copy cost.
+void ImGui::GcCompactTransientWindowBuffers(ImGuiWindow* window)
+{
+ window->MemoryCompacted = true;
+ window->MemoryDrawListIdxCapacity = window->DrawList->IdxBuffer.Capacity;
+ window->MemoryDrawListVtxCapacity = window->DrawList->VtxBuffer.Capacity;
+ window->IDStack.clear();
+ window->DrawList->ClearFreeMemory();
+ window->DC.ChildWindows.clear();
+ window->DC.ItemFlagsStack.clear();
+ window->DC.ItemWidthStack.clear();
+ window->DC.TextWrapPosStack.clear();
+ window->DC.GroupStack.clear();
+}
+
+void ImGui::GcAwakeTransientWindowBuffers(ImGuiWindow* window)
+{
+ // We stored capacity of the ImDrawList buffer to reduce growth-caused allocation/copy when awakening.
+ // The other buffers tends to amortize much faster.
+ window->MemoryCompacted = false;
+ window->DrawList->IdxBuffer.reserve(window->MemoryDrawListIdxCapacity);
+ window->DrawList->VtxBuffer.reserve(window->MemoryDrawListVtxCapacity);
+ window->MemoryDrawListIdxCapacity = window->MemoryDrawListVtxCapacity = 0;
+}
+
void ImGui::SetNavID(ImGuiID id, int nav_layer)
{
ImGuiContext& g = *GImGui;
@@ -2691,7 +2902,8 @@ void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window)
if (g.ActiveIdIsJustActivated)
{
g.ActiveIdTimer = 0.0f;
- g.ActiveIdHasBeenEdited = false;
+ g.ActiveIdHasBeenPressedBefore = false;
+ g.ActiveIdHasBeenEditedBefore = false;
if (id != 0)
{
g.LastActiveId = id;
@@ -2703,6 +2915,7 @@ void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window)
g.ActiveIdBlockNavInputFlags = 0;
g.ActiveIdAllowOverlap = false;
g.ActiveIdWindow = window;
+ g.ActiveIdHasBeenEditedThisFrame = false;
if (id)
{
g.ActiveIdIsAlive = id;
@@ -2770,7 +2983,8 @@ void ImGui::MarkItemEdited(ImGuiID id)
IM_ASSERT(g.ActiveId == id || g.ActiveId == 0 || g.DragDropActive);
IM_UNUSED(id); // Avoid unused variable warnings when asserts are compiled out.
//IM_ASSERT(g.CurrentWindow->DC.LastItemId == id);
- g.ActiveIdHasBeenEdited = true;
+ g.ActiveIdHasBeenEditedThisFrame = true;
+ g.ActiveIdHasBeenEditedBefore = true;
g.CurrentWindow->DC.LastItemStatusFlags |= ImGuiItemStatusFlags_Edited;
}
@@ -2808,10 +3022,11 @@ void ImGui::ItemSize(const ImVec2& size, float text_offset_y)
return;
// Always align ourselves on pixel boundaries
- const float line_height = ImMax(window->DC.CurrentLineSize.y, size.y);
- const float text_base_offset = ImMax(window->DC.CurrentLineTextBaseOffset, text_offset_y);
+ const float line_height = ImMax(window->DC.CurrLineSize.y, size.y);
+ const float text_base_offset = ImMax(window->DC.CurrLineTextBaseOffset, text_offset_y);
//if (g.IO.KeyAlt) window->DrawList->AddRect(window->DC.CursorPos, window->DC.CursorPos + ImVec2(size.x, line_height), IM_COL32(255,0,0,200)); // [DEBUG]
- window->DC.CursorPosPrevLine = ImVec2(window->DC.CursorPos.x + size.x, window->DC.CursorPos.y);
+ window->DC.CursorPosPrevLine.x = window->DC.CursorPos.x + size.x;
+ window->DC.CursorPosPrevLine.y = window->DC.CursorPos.y;
window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x);
window->DC.CursorPos.y = (float)(int)(window->DC.CursorPos.y + line_height + g.Style.ItemSpacing.y);
window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, window->DC.CursorPosPrevLine.x);
@@ -2820,7 +3035,7 @@ void ImGui::ItemSize(const ImVec2& size, float text_offset_y)
window->DC.PrevLineSize.y = line_height;
window->DC.PrevLineTextBaseOffset = text_base_offset;
- window->DC.CurrentLineSize.y = window->DC.CurrentLineTextBaseOffset = 0.0f;
+ window->DC.CurrLineSize.y = window->DC.CurrLineTextBaseOffset = 0.0f;
// Horizontal layout mode
if (window->DC.LayoutType == ImGuiLayoutType_Horizontal)
@@ -2844,23 +3059,37 @@ bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb_arg)
{
// Navigation processing runs prior to clipping early-out
// (a) So that NavInitRequest can be honored, for newly opened windows to select a default widget
- // (b) So that we can scroll up/down past clipped items. This adds a small O(N) cost to regular navigation requests unfortunately, but it is still limited to one window.
- // it may not scale very well for windows with ten of thousands of item, but at least NavMoveRequest is only set on user interaction, aka maximum once a frame.
- // We could early out with "if (is_clipped && !g.NavInitRequest) return false;" but when we wouldn't be able to reach unclipped widgets. This would work if user had explicit scrolling control (e.g. mapped on a stick)
+ // (b) So that we can scroll up/down past clipped items. This adds a small O(N) cost to regular navigation requests
+ // unfortunately, but it is still limited to one window. It may not scale very well for windows with ten of
+ // thousands of item, but at least NavMoveRequest is only set on user interaction, aka maximum once a frame.
+ // We could early out with "if (is_clipped && !g.NavInitRequest) return false;" but when we wouldn't be able
+ // to reach unclipped widgets. This would work if user had explicit scrolling control (e.g. mapped on a stick).
+ // We intentionally don't check if g.NavWindow != NULL because g.NavAnyRequest should only be set when it is non null.
+ // If we crash on a NULL g.NavWindow we need to fix the bug elsewhere.
window->DC.NavLayerActiveMaskNext |= window->DC.NavLayerCurrentMask;
if (g.NavId == id || g.NavAnyRequest)
if (g.NavWindow->RootWindowForNav == window->RootWindowForNav)
if (window == g.NavWindow || ((window->Flags | g.NavWindow->Flags) & ImGuiWindowFlags_NavFlattened))
NavProcessItem(window, nav_bb_arg ? *nav_bb_arg : bb, id);
+
+ // [DEBUG] Item Picker tool, when enabling the "extended" version we perform the check in ItemAdd()
+#ifdef IMGUI_DEBUG_TOOL_ITEM_PICKER_EX
+ if (id == g.DebugItemPickerBreakID)
+ {
+ IM_DEBUG_BREAK();
+ g.DebugItemPickerBreakID = 0;
+ }
+#endif
}
window->DC.LastItemId = id;
window->DC.LastItemRect = bb;
window->DC.LastItemStatusFlags = ImGuiItemStatusFlags_None;
+ g.NextItemData.Flags = ImGuiNextItemDataFlags_None;
#ifdef IMGUI_ENABLE_TEST_ENGINE
if (id != 0)
- ImGuiTestEngineHook_ItemAdd(&g, nav_bb_arg ? *nav_bb_arg : bb, id);
+ IMGUI_TEST_ENGINE_ITEM_ADD(nav_bb_arg ? *nav_bb_arg : bb, id);
#endif
// Clipping test
@@ -2903,7 +3132,8 @@ bool ImGui::IsItemHovered(ImGuiHoveredFlags flags)
if (g.ActiveId != 0 && g.ActiveId != window->DC.LastItemId && !g.ActiveIdAllowOverlap && g.ActiveId != window->MoveId)
return false;
- // Test if interactions on this window are blocked by an active popup or modal
+ // Test if interactions on this window are blocked by an active popup or modal.
+ // The ImGuiHoveredFlags_AllowWhenBlockedByPopup flag will be tested here.
if (!IsWindowContentHoverable(window, flags))
return false;
@@ -2911,7 +3141,7 @@ bool ImGui::IsItemHovered(ImGuiHoveredFlags flags)
if ((window->DC.ItemFlags & ImGuiItemFlags_Disabled) && !(flags & ImGuiHoveredFlags_AllowWhenDisabled))
return false;
- // Special handling for the dummy item after Begin() which represent the title bar or tab.
+ // Special handling for the dummy item after Begin() which represent the title bar or tab.
// When the window is collapsed (SkipItems==true) that last item will never be overwritten so we need to detect the case.
if ((window->DC.LastItemId == window->ID || window->DC.LastItemId == window->MoveId) && window->WriteAccessed)
return false;
@@ -2938,6 +3168,17 @@ bool ImGui::ItemHoverable(const ImRect& bb, ImGuiID id)
return false;
SetHoveredID(id);
+
+ // [DEBUG] Item Picker tool!
+ // We perform the check here because SetHoveredID() is not frequently called (1~ time a frame), making
+ // the cost of this tool near-zero. We can get slightly better call-stack and support picking non-hovered
+ // items if we perform the test in ItemAdd(), but that would incur a small runtime cost.
+ // #define IMGUI_DEBUG_TOOL_ITEM_PICKER_EX in imconfig.h if you want this check to also be performed in ItemAdd().
+ if (g.DebugItemPickerActive && g.HoveredIdPreviousFrame == id)
+ GetForegroundDrawList()->AddRect(bb.Min, bb.Max, IM_COL32(255, 255, 0, 255));
+ if (g.DebugItemPickerBreakID == id)
+ IM_DEBUG_BREAK();
+
return true;
}
@@ -2952,26 +3193,39 @@ bool ImGui::IsClippedEx(const ImRect& bb, ImGuiID id, bool clip_even_when_logged
return false;
}
-bool ImGui::FocusableItemRegister(ImGuiWindow* window, ImGuiID id, bool tab_stop)
+// Process TAB/Shift+TAB. Be mindful that this function may _clear_ the ActiveID when tabbing out.
+bool ImGui::FocusableItemRegister(ImGuiWindow* window, ImGuiID id)
{
ImGuiContext& g = *GImGui;
+ // Increment counters
const bool is_tab_stop = (window->DC.ItemFlags & (ImGuiItemFlags_NoTabStop | ImGuiItemFlags_Disabled)) == 0;
- window->FocusIdxAllCounter++;
+ window->DC.FocusCounterAll++;
if (is_tab_stop)
- window->FocusIdxTabCounter++;
+ window->DC.FocusCounterTab++;
- // Process keyboard input at this point: TAB/Shift-TAB to tab out of the currently focused item.
- // Note that we can always TAB out of a widget that doesn't allow tabbing in.
- if (tab_stop && (g.ActiveId == id) && window->FocusIdxAllRequestNext == INT_MAX && window->FocusIdxTabRequestNext == INT_MAX && !g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_Tab))
- window->FocusIdxTabRequestNext = window->FocusIdxTabCounter + (g.IO.KeyShift ? (is_tab_stop ? -1 : 0) : +1); // Modulo on index will be applied at the end of frame once we've got the total counter of items.
+ // Process TAB/Shift-TAB to tab *OUT* of the currently focused item.
+ // (Note that we can always TAB out of a widget that doesn't allow tabbing in)
+ if (g.ActiveId == id && g.FocusTabPressed && !(g.ActiveIdBlockNavInputFlags & (1 << ImGuiNavInput_KeyTab_)) && g.FocusRequestNextWindow == NULL)
+ {
+ g.FocusRequestNextWindow = window;
+ g.FocusRequestNextCounterTab = window->DC.FocusCounterTab + (g.IO.KeyShift ? (is_tab_stop ? -1 : 0) : +1); // Modulo on index will be applied at the end of frame once we've got the total counter of items.
+ }
- if (window->FocusIdxAllCounter == window->FocusIdxAllRequestCurrent)
- return true;
- if (is_tab_stop && window->FocusIdxTabCounter == window->FocusIdxTabRequestCurrent)
+ // Handle focus requests
+ if (g.FocusRequestCurrWindow == window)
{
- g.NavJustTabbedId = id;
- return true;
+ if (window->DC.FocusCounterAll == g.FocusRequestCurrCounterAll)
+ return true;
+ if (is_tab_stop && window->DC.FocusCounterTab == g.FocusRequestCurrCounterTab)
+ {
+ g.NavJustTabbedId = id;
+ return true;
+ }
+
+ // If another item is about to be focused, we clear our own active id
+ if (g.ActiveId == id)
+ ClearActiveID();
}
return false;
@@ -2979,21 +3233,8 @@ bool ImGui::FocusableItemRegister(ImGuiWindow* window, ImGuiID id, bool tab_stop
void ImGui::FocusableItemUnregister(ImGuiWindow* window)
{
- window->FocusIdxAllCounter--;
- window->FocusIdxTabCounter--;
-}
-
-ImVec2 ImGui::CalcItemSize(ImVec2 size, float default_x, float default_y)
-{
- ImGuiContext& g = *GImGui;
- ImVec2 content_max;
- if (size.x < 0.0f || size.y < 0.0f)
- content_max = g.CurrentWindow->Pos + GetContentRegionMax();
- if (size.x <= 0.0f)
- size.x = (size.x == 0.0f) ? default_x : ImMax(content_max.x - g.CurrentWindow->DC.CursorPos.x, 4.0f) + size.x;
- if (size.y <= 0.0f)
- size.y = (size.y == 0.0f) ? default_y : ImMax(content_max.y - g.CurrentWindow->DC.CursorPos.y, 4.0f) + size.y;
- return size;
+ window->DC.FocusCounterAll--;
+ window->DC.FocusCounterTab--;
}
float ImGui::CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x)
@@ -3001,15 +3242,16 @@ float ImGui::CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x)
if (wrap_pos_x < 0.0f)
return 0.0f;
- ImGuiWindow* window = GetCurrentWindowRead();
+ ImGuiWindow* window = GImGui->CurrentWindow;
if (wrap_pos_x == 0.0f)
- wrap_pos_x = GetContentRegionMax().x + window->Pos.x;
+ wrap_pos_x = window->WorkRect.Max.x;
else if (wrap_pos_x > 0.0f)
wrap_pos_x += window->Pos.x - window->Scroll.x; // wrap_pos_x is provided is window local space
return ImMax(wrap_pos_x - pos.x, 1.0f);
}
+// IM_ALLOC() == ImGui::MemAlloc()
void* ImGui::MemAlloc(size_t size)
{
if (ImGuiContext* ctx = GImGui)
@@ -3017,6 +3259,7 @@ void* ImGui::MemAlloc(size_t size)
return GImAllocatorAllocFunc(size, GImAllocatorUserData);
}
+// IM_FREE() == ImGui::MemFree()
void ImGui::MemFree(void* ptr)
{
if (ptr)
@@ -3027,13 +3270,15 @@ void ImGui::MemFree(void* ptr)
const char* ImGui::GetClipboardText()
{
- return GImGui->IO.GetClipboardTextFn ? GImGui->IO.GetClipboardTextFn(GImGui->IO.ClipboardUserData) : "";
+ ImGuiContext& g = *GImGui;
+ return g.IO.GetClipboardTextFn ? g.IO.GetClipboardTextFn(g.IO.ClipboardUserData) : "";
}
void ImGui::SetClipboardText(const char* text)
{
- if (GImGui->IO.SetClipboardTextFn)
- GImGui->IO.SetClipboardTextFn(GImGui->IO.ClipboardUserData, text);
+ ImGuiContext& g = *GImGui;
+ if (g.IO.SetClipboardTextFn)
+ g.IO.SetClipboardTextFn(g.IO.ClipboardUserData, text);
}
const char* ImGui::GetVersion()
@@ -3041,7 +3286,7 @@ const char* ImGui::GetVersion()
return IMGUI_VERSION;
}
-// Internal state access - if you want to share ImGui state between modules (e.g. DLL) or allocate it yourself
+// Internal state access - if you want to share Dear ImGui state between modules (e.g. DLL) or allocate it yourself
// Note that we still point to some static data and members (such as GFontAtlas), so the state instance you end up using will point to the static data within its module
ImGuiContext* ImGui::GetCurrentContext()
{
@@ -3057,9 +3302,12 @@ void ImGui::SetCurrentContext(ImGuiContext* ctx)
#endif
}
-// Helper function to verify that the type sizes are matching between the calling file's compilation unit and imgui.cpp's compilation unit
-// If the user has inconsistent compilation settings, imgui configuration #define, packing pragma, etc. you may see different structures from what imgui.cpp sees which is highly problematic.
-bool ImGui::DebugCheckVersionAndDataLayout(const char* version, size_t sz_io, size_t sz_style, size_t sz_vec2, size_t sz_vec4, size_t sz_vert)
+// Helper function to verify ABI compatibility between caller code and compiled version of Dear ImGui.
+// Verify that the type sizes are matching between the calling file's compilation unit and imgui.cpp's compilation unit
+// If the user has inconsistent compilation settings, imgui configuration #define, packing pragma, etc. your user code
+// may see different structures than what imgui.cpp sees, which is problematic.
+// We usually require settings to be in imconfig.h to make sure that they are accessible to all compilation units involved with Dear ImGui.
+bool ImGui::DebugCheckVersionAndDataLayout(const char* version, size_t sz_io, size_t sz_style, size_t sz_vec2, size_t sz_vec4, size_t sz_vert, size_t sz_idx)
{
bool error = false;
if (strcmp(version, IMGUI_VERSION)!=0) { error = true; IM_ASSERT(strcmp(version,IMGUI_VERSION)==0 && "Mismatched version string!"); }
@@ -3068,6 +3316,7 @@ bool ImGui::DebugCheckVersionAndDataLayout(const char* version, size_t sz_io, si
if (sz_vec2 != sizeof(ImVec2)) { error = true; IM_ASSERT(sz_vec2 == sizeof(ImVec2) && "Mismatched struct layout!"); }
if (sz_vec4 != sizeof(ImVec4)) { error = true; IM_ASSERT(sz_vec4 == sizeof(ImVec4) && "Mismatched struct layout!"); }
if (sz_vert != sizeof(ImDrawVert)) { error = true; IM_ASSERT(sz_vert == sizeof(ImDrawVert) && "Mismatched struct layout!"); }
+ if (sz_idx != sizeof(ImDrawIdx)) { error = true; IM_ASSERT(sz_idx == sizeof(ImDrawIdx) && "Mismatched struct layout!"); }
return !error;
}
@@ -3099,7 +3348,7 @@ void ImGui::DestroyContext(ImGuiContext* ctx)
ImGuiIO& ImGui::GetIO()
{
- IM_ASSERT(GImGui != NULL && "No current context. Did you call ImGui::CreateContext() or ImGui::SetCurrentContext()?");
+ IM_ASSERT(GImGui != NULL && "No current context. Did you call ImGui::CreateContext() and ImGui::SetCurrentContext() ?");
return GImGui->IO;
}
@@ -3111,7 +3360,7 @@ ImGuiPlatformIO& ImGui::GetPlatformIO()
ImGuiStyle& ImGui::GetStyle()
{
- IM_ASSERT(GImGui != NULL && "No current context. Did you call ImGui::CreateContext() or ImGui::SetCurrentContext()?");
+ IM_ASSERT(GImGui != NULL && "No current context. Did you call ImGui::CreateContext() and ImGui::SetCurrentContext() ?");
return GImGui->Style;
}
@@ -3132,33 +3381,50 @@ int ImGui::GetFrameCount()
return GImGui->FrameCount;
}
-ImDrawList* ImGui::GetOverlayDrawList(ImGuiViewport* viewport_public)
+static ImDrawList* GetViewportDrawList(ImGuiViewportP* viewport, size_t drawlist_no, const char* drawlist_name)
{
- // Create the draw list on demand, because it is not frequently used for all viewports
+ // Create the draw list on demand, because they are not frequently used for all viewports
ImGuiContext& g = *GImGui;
- ImGuiViewportP* viewport = (ImGuiViewportP*)viewport_public;
- if (viewport->OverlayDrawList == NULL)
+ IM_ASSERT(drawlist_no >= 0 && drawlist_no < IM_ARRAYSIZE(viewport->DrawLists));
+ ImDrawList* draw_list = viewport->DrawLists[drawlist_no];
+ if (draw_list == NULL)
{
- viewport->OverlayDrawList = IM_NEW(ImDrawList)(&g.DrawListSharedData);
- viewport->OverlayDrawList->_OwnerName = "##Overlay";
+ draw_list = IM_NEW(ImDrawList)(&g.DrawListSharedData);
+ draw_list->_OwnerName = drawlist_name;
+ viewport->DrawLists[drawlist_no] = draw_list;
}
// Our ImDrawList system requires that there is always a command
- if (viewport->LastFrameOverlayDrawList != g.FrameCount)
+ if (viewport->LastFrameDrawLists[drawlist_no] != g.FrameCount)
{
- viewport->OverlayDrawList->Clear();
- viewport->OverlayDrawList->PushTextureID(g.IO.Fonts->TexID);
- viewport->OverlayDrawList->PushClipRect(viewport->Pos, viewport->Pos + viewport->Size, false);
- viewport->OverlayDrawList->Flags = (g.Style.AntiAliasedLines ? ImDrawListFlags_AntiAliasedLines : 0) | (g.Style.AntiAliasedFill ? ImDrawListFlags_AntiAliasedFill : 0);
- viewport->LastFrameOverlayDrawList = g.FrameCount;
+ draw_list->Clear();
+ draw_list->PushTextureID(g.IO.Fonts->TexID);
+ draw_list->PushClipRect(viewport->Pos, viewport->Pos + viewport->Size, false);
+ viewport->LastFrameDrawLists[drawlist_no] = g.FrameCount;
}
- return viewport->OverlayDrawList;
+ return draw_list;
+}
+
+ImDrawList* ImGui::GetBackgroundDrawList(ImGuiViewport* viewport)
+{
+ return GetViewportDrawList((ImGuiViewportP*)viewport, 0, "##Background");
}
-ImDrawList* ImGui::GetOverlayDrawList()
+ImDrawList* ImGui::GetBackgroundDrawList()
{
ImGuiWindow* window = GImGui->CurrentWindow;
- return GetOverlayDrawList(window->Viewport);
+ return GetBackgroundDrawList(window->Viewport);
+}
+
+ImDrawList* ImGui::GetForegroundDrawList(ImGuiViewport* viewport)
+{
+ return GetViewportDrawList((ImGuiViewportP*)viewport, 1, "##Foreground");
+}
+
+ImDrawList* ImGui::GetForegroundDrawList()
+{
+ ImGuiWindow* window = GImGui->CurrentWindow;
+ return GetForegroundDrawList(window->Viewport);
}
ImDrawListSharedData* ImGui::GetDrawListSharedData()
@@ -3187,6 +3453,32 @@ void ImGui::StartMouseMovingWindow(ImGuiWindow* window)
g.MovingWindow = window;
}
+void ImGui::StartMouseDragFromTitleBar(ImGuiWindow* window, ImGuiDockNode* node, bool from_collapse_button)
+{
+ ImGuiContext& g = *GImGui;
+ bool can_extract_dock_node = false;
+ if (node != NULL && node->VisibleWindow && (node->VisibleWindow->Flags & ImGuiWindowFlags_NoMove) == 0)
+ {
+ ImGuiDockNode* root_node = DockNodeGetRootNode(node);
+ if (root_node->OnlyNodeWithWindows != node || (root_node->CentralNode != NULL))
+ if (from_collapse_button || root_node->IsDockSpace())
+ can_extract_dock_node = true;
+ }
+
+ const bool clicked = IsMouseClicked(0);
+ const bool dragging = IsMouseDragging(0, g.IO.MouseDragThreshold * 1.70f);
+ if (can_extract_dock_node && dragging)
+ {
+ DockContextQueueUndockNode(&g, node);
+ g.ActiveIdClickOffset = g.IO.MouseClickedPos[0] - node->Pos;
+ }
+ else if (!can_extract_dock_node && (clicked || dragging) && g.MovingWindow != window)
+ {
+ StartMouseMovingWindow(window);
+ g.ActiveIdClickOffset = g.IO.MouseClickedPos[0] - window->RootWindow->Pos;
+ }
+}
+
// Handle mouse moving window
// Note: moving window with the navigation keys (Square + d-pad / CTRL+TAB + Arrows) are processed in NavUpdateWindowing()
void ImGui::UpdateMouseMovingWindowNewFrame()
@@ -3215,7 +3507,7 @@ void ImGui::UpdateMouseMovingWindowNewFrame()
{
// Try to merge the window back into the main viewport.
// This works because MouseViewport should be != MovingWindow->Viewport on release (as per code in UpdateViewports)
- if (g.ConfigFlagsForFrame & ImGuiConfigFlags_ViewportsEnable)
+ if (g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable)
UpdateTryMergeWindowIntoHostViewport(moving_window, g.MouseViewport);
// Restore the mouse viewport so that we don't hover the viewport _under_ the moved window during the frame we released the mouse button.
@@ -3263,20 +3555,21 @@ void ImGui::UpdateMouseMovingWindowEndFrame()
if (!g.HoveredRootWindow->TitleBarRect().Contains(g.IO.MouseClickedPos[0]))
g.MovingWindow = NULL;
}
- else if (g.NavWindow != NULL && GetFrontMostPopupModal() == NULL)
+ else if (g.NavWindow != NULL && GetTopMostPopupModal() == NULL)
{
// Clicking on void disable focus
FocusWindow(NULL);
}
}
- // With right mouse button we close popups without changing focus
- // (The left mouse button path calls FocusWindow which will lead NewFrame->ClosePopupsOverWindow to trigger)
+ // With right mouse button we close popups without changing focus based on where the mouse is aimed
+ // Instead, focus will be restored to the window under the bottom-most closed popup.
+ // (The left mouse button path calls FocusWindow on the hovered window, which will lead NewFrame->ClosePopupsOverWindow to trigger)
if (g.IO.MouseClicked[1])
{
- // Find the top-most window between HoveredWindow and the front most Modal Window.
+ // Find the top-most window between HoveredWindow and the top-most Modal Window.
// This is where we can trim the popup stack.
- ImGuiWindow* modal = GetFrontMostPopupModal();
+ ImGuiWindow* modal = GetTopMostPopupModal();
bool hovered_window_above_modal = false;
if (modal == NULL)
hovered_window_above_modal = true;
@@ -3288,7 +3581,7 @@ void ImGui::UpdateMouseMovingWindowEndFrame()
if (window == g.HoveredWindow)
hovered_window_above_modal = true;
}
- ClosePopupsOverWindow(hovered_window_above_modal ? g.HoveredWindow : modal);
+ ClosePopupsOverWindow(hovered_window_above_modal ? g.HoveredWindow : modal, true);
}
}
@@ -3297,7 +3590,7 @@ static void TranslateWindow(ImGuiWindow* window, const ImVec2& delta)
window->Pos += delta;
window->ClipRect.Translate(delta);
window->OuterRectClipped.Translate(delta);
- window->InnerMainRect.Translate(delta);
+ window->InnerRect.Translate(delta);
window->DC.CursorPos += delta;
window->DC.CursorStartPos += delta;
window->DC.CursorMaxPos += delta;
@@ -3311,7 +3604,7 @@ static void ScaleWindow(ImGuiWindow* window, float scale)
window->Pos = ImFloor((window->Pos - origin) * scale + origin);
window->Size = ImFloor(window->Size * scale);
window->SizeFull = ImFloor(window->SizeFull * scale);
- window->SizeContents = ImFloor(window->SizeContents * scale);
+ window->ContentSize = ImFloor(window->ContentSize * scale);
}
static bool IsWindowActiveAndVisible(ImGuiWindow* window)
@@ -3357,6 +3650,7 @@ static void ImGui::UpdateMouseInputs()
g.IO.MouseClickedTime[i] = g.Time;
}
g.IO.MouseClickedPos[i] = g.IO.MousePos;
+ g.IO.MouseDownWasDoubleClick[i] = g.IO.MouseDoubleClicked[i];
g.IO.MouseDragMaxDistanceAbs[i] = ImVec2(0.0f, 0.0f);
g.IO.MouseDragMaxDistanceSqr[i] = 0.0f;
}
@@ -3368,53 +3662,96 @@ static void ImGui::UpdateMouseInputs()
g.IO.MouseDragMaxDistanceAbs[i].x = ImMax(g.IO.MouseDragMaxDistanceAbs[i].x, delta_from_click_pos.x < 0.0f ? -delta_from_click_pos.x : delta_from_click_pos.x);
g.IO.MouseDragMaxDistanceAbs[i].y = ImMax(g.IO.MouseDragMaxDistanceAbs[i].y, delta_from_click_pos.y < 0.0f ? -delta_from_click_pos.y : delta_from_click_pos.y);
}
+ if (!g.IO.MouseDown[i] && !g.IO.MouseReleased[i])
+ g.IO.MouseDownWasDoubleClick[i] = false;
if (g.IO.MouseClicked[i]) // Clicking any mouse button reactivate mouse hovering which may have been deactivated by gamepad/keyboard navigation
g.NavDisableMouseHover = false;
}
}
-void ImGui::UpdateMouseWheel()
+static void StartLockWheelingWindow(ImGuiWindow* window)
{
ImGuiContext& g = *GImGui;
- if (!g.HoveredWindow || g.HoveredWindow->Collapsed)
+ if (g.WheelingWindow == window)
return;
+ g.WheelingWindow = window;
+ g.WheelingWindowRefMousePos = g.IO.MousePos;
+ g.WheelingWindowTimer = WINDOWS_MOUSE_WHEEL_SCROLL_LOCK_TIMER;
+}
+
+void ImGui::UpdateMouseWheel()
+{
+ ImGuiContext& g = *GImGui;
+
+ // Reset the locked window if we move the mouse or after the timer elapses
+ if (g.WheelingWindow != NULL)
+ {
+ g.WheelingWindowTimer -= g.IO.DeltaTime;
+ if (IsMousePosValid() && ImLengthSqr(g.IO.MousePos - g.WheelingWindowRefMousePos) > g.IO.MouseDragThreshold * g.IO.MouseDragThreshold)
+ g.WheelingWindowTimer = 0.0f;
+ if (g.WheelingWindowTimer <= 0.0f)
+ {
+ g.WheelingWindow = NULL;
+ g.WheelingWindowTimer = 0.0f;
+ }
+ }
+
if (g.IO.MouseWheel == 0.0f && g.IO.MouseWheelH == 0.0f)
return;
- // If a child window has the ImGuiWindowFlags_NoScrollWithMouse flag, we give a chance to scroll its parent (unless either ImGuiWindowFlags_NoInputs or ImGuiWindowFlags_NoScrollbar are also set).
- ImGuiWindow* window = g.HoveredWindow;
- ImGuiWindow* scroll_window = window;
- while ((scroll_window->Flags & ImGuiWindowFlags_ChildWindow) && (scroll_window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(scroll_window->Flags & ImGuiWindowFlags_NoScrollbar) && !(scroll_window->Flags & ImGuiWindowFlags_NoMouseInputs) && scroll_window->ParentWindow)
- scroll_window = scroll_window->ParentWindow;
- const bool scroll_allowed = !(scroll_window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(scroll_window->Flags & ImGuiWindowFlags_NoMouseInputs);
+ ImGuiWindow* window = g.WheelingWindow ? g.WheelingWindow : g.HoveredWindow;
+ if (!window || window->Collapsed)
+ return;
- if (g.IO.MouseWheel != 0.0f)
+ // Zoom / Scale window
+ // FIXME-OBSOLETE: This is an old feature, it still works but pretty much nobody is using it and may be best redesigned.
+ if (g.IO.MouseWheel != 0.0f && g.IO.KeyCtrl && g.IO.FontAllowUserScaling)
{
- if (g.IO.KeyCtrl && g.IO.FontAllowUserScaling)
+ StartLockWheelingWindow(window);
+ const float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f);
+ const float scale = new_font_scale / window->FontWindowScale;
+ window->FontWindowScale = new_font_scale;
+ if (!(window->Flags & ImGuiWindowFlags_ChildWindow))
{
- // Zoom / Scale window
- const float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f);
- const float scale = new_font_scale / window->FontWindowScale;
- window->FontWindowScale = new_font_scale;
-
const ImVec2 offset = window->Size * (1.0f - scale) * (g.IO.MousePos - window->Pos) / window->Size;
- window->Pos += offset;
- window->Size *= scale;
- window->SizeFull *= scale;
+ SetWindowPos(window, window->Pos + offset, 0);
+ window->Size = ImFloor(window->Size * scale);
+ window->SizeFull = ImFloor(window->SizeFull * scale);
}
- else if (!g.IO.KeyCtrl && scroll_allowed)
+ return;
+ }
+
+ // Mouse wheel scrolling
+ // If a child window has the ImGuiWindowFlags_NoScrollWithMouse flag, we give a chance to scroll its parent
+
+ // Vertical Mouse Wheel scrolling
+ const float wheel_y = (g.IO.MouseWheel != 0.0f && !g.IO.KeyShift) ? g.IO.MouseWheel : 0.0f;
+ if (wheel_y != 0.0f && !g.IO.KeyCtrl)
+ {
+ StartLockWheelingWindow(window);
+ while ((window->Flags & ImGuiWindowFlags_ChildWindow) && ((window->ScrollMax.y == 0.0f) || ((window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs))))
+ window = window->ParentWindow;
+ if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs))
{
- // Mouse wheel vertical scrolling
- float scroll_amount = 5 * scroll_window->CalcFontSize();
- scroll_amount = (float)(int)ImMin(scroll_amount, (scroll_window->ContentsRegionRect.GetHeight() + scroll_window->WindowPadding.y * 2.0f) * 0.67f);
- SetWindowScrollY(scroll_window, scroll_window->Scroll.y - g.IO.MouseWheel * scroll_amount);
+ float max_step = window->InnerRect.GetHeight() * 0.67f;
+ float scroll_step = ImFloor(ImMin(5 * window->CalcFontSize(), max_step));
+ SetScrollY(window, window->Scroll.y - wheel_y * scroll_step);
}
}
- if (g.IO.MouseWheelH != 0.0f && scroll_allowed && !g.IO.KeyCtrl)
+
+ // Horizontal Mouse Wheel scrolling, or Vertical Mouse Wheel w/ Shift held
+ const float wheel_x = (g.IO.MouseWheelH != 0.0f && !g.IO.KeyShift) ? g.IO.MouseWheelH : (g.IO.MouseWheel != 0.0f && g.IO.KeyShift) ? g.IO.MouseWheel : 0.0f;
+ if (wheel_x != 0.0f && !g.IO.KeyCtrl)
{
- // Mouse wheel horizontal scrolling (for hardware that supports it)
- float scroll_amount = scroll_window->CalcFontSize();
- SetWindowScrollX(scroll_window, scroll_window->Scroll.x - g.IO.MouseWheelH * scroll_amount);
+ StartLockWheelingWindow(window);
+ while ((window->Flags & ImGuiWindowFlags_ChildWindow) && ((window->ScrollMax.x == 0.0f) || ((window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs))))
+ window = window->ParentWindow;
+ if (!(window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs))
+ {
+ float max_step = window->InnerRect.GetWidth() * 0.67f;
+ float scroll_step = ImFloor(ImMin(2 * window->CalcFontSize(), max_step));
+ SetScrollX(window, window->Scroll.x - wheel_x * scroll_step);
+ }
}
}
@@ -3431,7 +3768,7 @@ void ImGui::UpdateHoveredWindowAndCaptureFlags()
IM_ASSERT(g.HoveredWindow == NULL || g.HoveredWindow == g.MovingWindow || g.HoveredWindow->Viewport == g.MouseViewport);
// Modal windows prevents cursor from hovering behind them.
- ImGuiWindow* modal_window = GetFrontMostPopupModal();
+ ImGuiWindow* modal_window = GetTopMostPopupModal();
if (modal_window)
if (g.HoveredRootWindow && !IsWindowChildOf(g.HoveredRootWindow, modal_window))
g.HoveredWindow = g.HoveredRootWindow = g.HoveredWindowUnderMovingWindow = NULL;
@@ -3460,13 +3797,13 @@ void ImGui::UpdateHoveredWindowAndCaptureFlags()
if (!mouse_avail_to_imgui && !mouse_dragging_extern_payload)
g.HoveredWindow = g.HoveredRootWindow = g.HoveredWindowUnderMovingWindow = NULL;
- // Update io.WantCaptureMouse for the user application (true = dispatch mouse info to imgui, false = dispatch mouse info to imgui + app)
+ // Update io.WantCaptureMouse for the user application (true = dispatch mouse info to imgui, false = dispatch mouse info to Dear ImGui + app)
if (g.WantCaptureMouseNextFrame != -1)
g.IO.WantCaptureMouse = (g.WantCaptureMouseNextFrame != 0);
else
g.IO.WantCaptureMouse = (mouse_avail_to_imgui && (g.HoveredWindow != NULL || mouse_any_down)) || (!g.OpenPopupStack.empty());
- // Update io.WantCaptureKeyboard for the user application (true = dispatch keyboard info to imgui, false = dispatch keyboard info to imgui + app)
+ // Update io.WantCaptureKeyboard for the user application (true = dispatch keyboard info to imgui, false = dispatch keyboard info to Dear ImGui + app)
if (g.WantCaptureKeyboardNextFrame != -1)
g.IO.WantCaptureKeyboard = (g.WantCaptureKeyboardNextFrame != 0);
else
@@ -3478,25 +3815,22 @@ void ImGui::UpdateHoveredWindowAndCaptureFlags()
g.IO.WantTextInput = (g.WantTextInputNextFrame != -1) ? (g.WantTextInputNextFrame != 0) : false;
}
-void ImGui::NewFrame()
+static void NewFrameSanityChecks()
{
- IM_ASSERT(GImGui != NULL && "No current context. Did you call ImGui::CreateContext() or ImGui::SetCurrentContext()?");
ImGuiContext& g = *GImGui;
-#ifdef IMGUI_ENABLE_TEST_ENGINE
- ImGuiTestEngineHook_PreNewFrame(&g);
-#endif
-
// Check user data
// (We pass an error message in the assert expression to make it visible to programmers who are not using a debugger, as most assert handlers display their argument)
IM_ASSERT(g.Initialized);
- IM_ASSERT(g.IO.DeltaTime >= 0.0f && "Need a positive DeltaTime (zero is tolerated but will cause some timing issues)");
- IM_ASSERT(g.IO.DisplaySize.x >= 0.0f && g.IO.DisplaySize.y >= 0.0f && "Invalid DisplaySize value");
+ IM_ASSERT((g.IO.DeltaTime > 0.0f || g.FrameCount == 0) && "Need a positive DeltaTime!");
+ IM_ASSERT((g.FrameCount == 0 || g.FrameCountEnded == g.FrameCount) && "Forgot to call Render() or EndFrame() at the end of the previous frame?");
+ IM_ASSERT(g.IO.DisplaySize.x >= 0.0f && g.IO.DisplaySize.y >= 0.0f && "Invalid DisplaySize value!");
IM_ASSERT(g.IO.Fonts->Fonts.Size > 0 && "Font Atlas not built. Did you call io.Fonts->GetTexDataAsRGBA32() / GetTexDataAsAlpha8() ?");
IM_ASSERT(g.IO.Fonts->Fonts[0]->IsLoaded() && "Font Atlas not built. Did you call io.Fonts->GetTexDataAsRGBA32() / GetTexDataAsAlpha8() ?");
- IM_ASSERT(g.Style.CurveTessellationTol > 0.0f && "Invalid style setting");
- IM_ASSERT(g.Style.Alpha >= 0.0f && g.Style.Alpha <= 1.0f && "Invalid style setting. Alpha cannot be negative (allows us to avoid a few clamps in color computations)");
- IM_ASSERT((g.FrameCount == 0 || g.FrameCountEnded == g.FrameCount) && "Forgot to call Render() or EndFrame() at the end of the previous frame?");
+ IM_ASSERT(g.Style.CurveTessellationTol > 0.0f && "Invalid style setting!");
+ IM_ASSERT(g.Style.Alpha >= 0.0f && g.Style.Alpha <= 1.0f && "Invalid style setting. Alpha cannot be negative (allows us to avoid a few clamps in color computations)!");
+ IM_ASSERT(g.Style.WindowMinSize.x >= 1.0f && g.Style.WindowMinSize.y >= 1.0f && "Invalid style setting.");
+ IM_ASSERT(g.Style.WindowMenuButtonPosition == ImGuiDir_Left || g.Style.WindowMenuButtonPosition == ImGuiDir_Right);
for (int n = 0; n < ImGuiKey_COUNT; n++)
IM_ASSERT(g.IO.KeyMap[n] >= -1 && g.IO.KeyMap[n] < IM_ARRAYSIZE(g.IO.KeysDown) && "io.KeyMap[] contains an out of bound value (need to be 0..512, or -1 for unmapped key)");
@@ -3507,6 +3841,26 @@ void ImGui::NewFrame()
// Perform simple check: the beta io.ConfigWindowsResizeFromEdges option requires back-end to honor mouse cursor changes and set the ImGuiBackendFlags_HasMouseCursors flag accordingly.
if (g.IO.ConfigWindowsResizeFromEdges && !(g.IO.BackendFlags & ImGuiBackendFlags_HasMouseCursors))
g.IO.ConfigWindowsResizeFromEdges = false;
+}
+
+void ImGui::NewFrame()
+{
+ IM_ASSERT(GImGui != NULL && "No current context. Did you call ImGui::CreateContext() and ImGui::SetCurrentContext() ?");
+ ImGuiContext& g = *GImGui;
+
+#ifdef IMGUI_ENABLE_TEST_ENGINE
+ ImGuiTestEngineHook_PreNewFrame(&g);
+#endif
+
+ // Check and assert for various common IO and Configuration mistakes
+ NewFrameSanityChecks();
+
+ // Perform simple check: error if Docking or Viewport are enabled _exactly_ on frame 1 (instead of frame 0 or later), which is a common error leading to loss of .ini data.
+ g.ConfigFlagsLastFrame = g.ConfigFlagsCurrFrame;
+ if (g.FrameCount == 1 && (g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable) && (g.ConfigFlagsLastFrame & ImGuiConfigFlags_DockingEnable) == 0)
+ IM_ASSERT(0 && "Please set DockingEnable before the first call to NewFrame()! Otherwise you will lose your .ini settings!");
+ if (g.FrameCount == 1 && (g.IO.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) && (g.ConfigFlagsLastFrame & ImGuiConfigFlags_ViewportsEnable) == 0)
+ IM_ASSERT(0 && "Please set ViewportsEnable before the first call to NewFrame()! Otherwise you will lose your .ini settings!");
// Perform simple checks: multi-viewport and platform windows support
if (g.IO.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
@@ -3538,11 +3892,13 @@ void ImGui::NewFrame()
for (int monitor_n = 0; monitor_n < g.PlatformIO.Monitors.Size; monitor_n++)
{
ImGuiPlatformMonitor& mon = g.PlatformIO.Monitors[monitor_n];
+ IM_UNUSED(mon);
IM_ASSERT(mon.MainSize.x > 0.0f && mon.MainSize.y > 0.0f && "Monitor bounds not setup properly.");
IM_ASSERT(mon.WorkSize.x > 0.0f && mon.WorkSize.y > 0.0f && "Monitor bounds not setup properly. If you don't have work area information, just copy Min/Max into them.");
IM_ASSERT(mon.DpiScale != 0.0f);
}
}
+ g.ConfigFlagsCurrFrame = g.IO.ConfigFlags;
// Load settings on first frame (if not explicitly loaded manually before)
if (!g.SettingsLoaded)
@@ -3572,22 +3928,28 @@ void ImGui::NewFrame()
g.FrameCount += 1;
g.TooltipOverrideCount = 0;
g.WindowsActiveCount = 0;
- g.ConfigFlagsForFrame = g.IO.ConfigFlags;
UpdateViewportsNewFrame();
- // Setup current font, and draw list shared data
+ // Setup current font and draw list shared data
// FIXME-VIEWPORT: the concept of a single ClipRectFullscreen is not ideal!
g.IO.Fonts->Locked = true;
SetCurrentFont(GetDefaultFont());
IM_ASSERT(g.Font->IsLoaded());
- ImVec2 virtual_space_max(0,0);
+ ImRect virtual_space(FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX);
for (int n = 0; n < g.Viewports.Size; n++)
- virtual_space_max = ImMax(virtual_space_max, g.Viewports[n]->Pos + g.Viewports[n]->Size);
- g.DrawListSharedData.ClipRectFullscreen = ImVec4(0.0f, 0.0f, virtual_space_max.x, virtual_space_max.y);
+ virtual_space.Add(g.Viewports[n]->GetRect());
+ g.DrawListSharedData.ClipRectFullscreen = ImVec4(virtual_space.Min.x, virtual_space.Min.y, virtual_space.Max.x, virtual_space.Max.y);
g.DrawListSharedData.CurveTessellationTol = g.Style.CurveTessellationTol;
-
- // Mark rendering data as invalid to prevent user who may have a handle on it to use it. Setup Overlay draw list for the viewport.
+ g.DrawListSharedData.InitialFlags = ImDrawListFlags_None;
+ if (g.Style.AntiAliasedLines)
+ g.DrawListSharedData.InitialFlags |= ImDrawListFlags_AntiAliasedLines;
+ if (g.Style.AntiAliasedFill)
+ g.DrawListSharedData.InitialFlags |= ImDrawListFlags_AntiAliasedFill;
+ if (g.IO.BackendFlags & ImGuiBackendFlags_RendererHasVtxOffset)
+ g.DrawListSharedData.InitialFlags |= ImDrawListFlags_AllowVtxOffset;
+
+ // Mark rendering data as invalid to prevent user who may have a handle on it to use it.
for (int n = 0; n < g.Viewports.Size; n++)
{
ImGuiViewportP* viewport = g.Viewports[n];
@@ -3618,12 +3980,13 @@ void ImGui::NewFrame()
g.LastActiveIdTimer += g.IO.DeltaTime;
g.ActiveIdPreviousFrame = g.ActiveId;
g.ActiveIdPreviousFrameWindow = g.ActiveIdWindow;
- g.ActiveIdPreviousFrameHasBeenEdited = g.ActiveIdHasBeenEdited;
+ g.ActiveIdPreviousFrameHasBeenEditedBefore = g.ActiveIdHasBeenEditedBefore;
g.ActiveIdIsAlive = 0;
+ g.ActiveIdHasBeenEditedThisFrame = false;
g.ActiveIdPreviousFrameIsAlive = false;
g.ActiveIdIsJustActivated = false;
- if (g.ScalarAsInputTextId && g.ActiveId != g.ScalarAsInputTextId)
- g.ScalarAsInputTextId = 0;
+ if (g.TempInputTextId != 0 && g.ActiveId != g.TempInputTextId)
+ g.TempInputTextId = 0;
// Drag and drop
g.DragDropAcceptIdPrev = g.DragDropAcceptIdCurr;
@@ -3650,7 +4013,7 @@ void ImGui::NewFrame()
// Undocking
// (needs to be before UpdateMouseMovingWindowNewFrame so the window is already offset and following the mouse on the detaching frame)
- DockContextNewFrameUpdateUndocking(&g);
+ DockContextUpdateUndocking(&g);
// Find hovered window
// (needs to be before UpdateMouseMovingWindowNewFrame so we fill g.HoveredWindowUnderMovingWindow on the mouse release frame)
@@ -3660,7 +4023,7 @@ void ImGui::NewFrame()
UpdateMouseMovingWindowNewFrame();
// Background darkening/whitening
- if (GetFrontMostPopupModal() != NULL || (g.NavWindowingTarget != NULL && g.NavWindowingHighlightAlpha > 0.0f))
+ if (GetTopMostPopupModal() != NULL || (g.NavWindowingTarget != NULL && g.NavWindowingHighlightAlpha > 0.0f))
g.DimBgRatio = ImMin(g.DimBgRatio + g.IO.DeltaTime * 6.0f, 1.0f);
else
g.DimBgRatio = ImMax(g.DimBgRatio - g.IO.DeltaTime * 10.0f, 0.0f);
@@ -3674,17 +4037,39 @@ void ImGui::NewFrame()
UpdateMouseWheel();
// Pressing TAB activate widget focus
- if (g.ActiveId == 0 && g.NavWindow != NULL && g.NavWindow->Active && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs) && !g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_Tab, false))
+ g.FocusTabPressed = (g.NavWindow && g.NavWindow->Active && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs) && !g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_Tab));
+ if (g.ActiveId == 0 && g.FocusTabPressed)
{
+ // Note that SetKeyboardFocusHere() sets the Next fields mid-frame. To be consistent we also
+ // manipulate the Next fields even, even though they will be turned into Curr fields by the code below.
+ g.FocusRequestNextWindow = g.NavWindow;
+ g.FocusRequestNextCounterAll = INT_MAX;
if (g.NavId != 0 && g.NavIdTabCounter != INT_MAX)
- g.NavWindow->FocusIdxTabRequestNext = g.NavIdTabCounter + 1 + (g.IO.KeyShift ? -1 : 1);
+ g.FocusRequestNextCounterTab = g.NavIdTabCounter + 1 + (g.IO.KeyShift ? -1 : 1);
else
- g.NavWindow->FocusIdxTabRequestNext = g.IO.KeyShift ? -1 : 0;
+ g.FocusRequestNextCounterTab = g.IO.KeyShift ? -1 : 0;
+ }
+
+ // Turn queued focus request into current one
+ g.FocusRequestCurrWindow = NULL;
+ g.FocusRequestCurrCounterAll = g.FocusRequestCurrCounterTab = INT_MAX;
+ if (g.FocusRequestNextWindow != NULL)
+ {
+ ImGuiWindow* window = g.FocusRequestNextWindow;
+ g.FocusRequestCurrWindow = window;
+ if (g.FocusRequestNextCounterAll != INT_MAX && window->DC.FocusCounterAll != -1)
+ g.FocusRequestCurrCounterAll = ImModPositive(g.FocusRequestNextCounterAll, window->DC.FocusCounterAll + 1);
+ if (g.FocusRequestNextCounterTab != INT_MAX && window->DC.FocusCounterTab != -1)
+ g.FocusRequestCurrCounterTab = ImModPositive(g.FocusRequestNextCounterTab, window->DC.FocusCounterTab + 1);
+ g.FocusRequestNextWindow = NULL;
+ g.FocusRequestNextCounterAll = g.FocusRequestNextCounterTab = INT_MAX;
}
+
g.NavIdTabCounter = INT_MAX;
- // Mark all windows as not visible
+ // Mark all windows as not visible and compact unused memory.
IM_ASSERT(g.WindowsFocusOrder.Size == g.Windows.Size);
+ const float memory_compact_start_time = (g.IO.ConfigWindowsMemoryCompactTimer >= 0.0f) ? (float)g.Time - g.IO.ConfigWindowsMemoryCompactTimer : FLT_MAX;
for (int i = 0; i != g.Windows.Size; i++)
{
ImGuiWindow* window = g.Windows[i];
@@ -3692,33 +4077,66 @@ void ImGui::NewFrame()
window->BeginCount = 0;
window->Active = false;
window->WriteAccessed = false;
+
+ // Garbage collect (this is totally functional but we may need decide if the side-effects are desirable)
+ if (!window->WasActive && !window->MemoryCompacted && window->LastTimeActive < memory_compact_start_time)
+ GcCompactTransientWindowBuffers(window);
}
// Closing the focused window restore focus to the first active root window in descending z-order
if (g.NavWindow && !g.NavWindow->WasActive)
- FocusPreviousWindowIgnoringOne(NULL);
+ FocusTopMostWindowUnderOne(NULL, NULL);
// No window should be open at the beginning of the frame.
// But in order to allow the user to call NewFrame() multiple times without calling Render(), we are doing an explicit clear.
g.CurrentWindowStack.resize(0);
g.BeginPopupStack.resize(0);
- ClosePopupsOverWindow(g.NavWindow);
+ ClosePopupsOverWindow(g.NavWindow, false);
// Docking
- DockContextNewFrameUpdateDocking(&g);
+ DockContextUpdateDocking(&g);
+
+ // [DEBUG] Item picker tool - start with DebugStartItemPicker() - useful to visually select an item and break into its call-stack.
+ UpdateDebugToolItemPicker();
// Create implicit/fallback window - which we will only render it if the user has added something to it.
// We don't use "Debug" to avoid colliding with user trying to create a "Debug" window with custom flags.
// This fallback is particularly important as it avoid ImGui:: calls from crashing.
+ g.FrameScopePushedFallbackWindow = true;
SetNextWindowSize(ImVec2(400,400), ImGuiCond_FirstUseEver);
Begin("Debug##Default");
- g.FrameScopePushedImplicitWindow = true;
+ IM_ASSERT(g.CurrentWindow->IsFallbackWindow == true);
#ifdef IMGUI_ENABLE_TEST_ENGINE
ImGuiTestEngineHook_PostNewFrame(&g);
#endif
}
+// [DEBUG] Item picker tool - start with DebugStartItemPicker() - useful to visually select an item and break into its call-stack.
+void ImGui::UpdateDebugToolItemPicker()
+{
+ ImGuiContext& g = *GImGui;
+ g.DebugItemPickerBreakID = 0;
+ if (g.DebugItemPickerActive)
+ {
+ const ImGuiID hovered_id = g.HoveredIdPreviousFrame;
+ ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
+ if (ImGui::IsKeyPressedMap(ImGuiKey_Escape))
+ g.DebugItemPickerActive = false;
+ if (ImGui::IsMouseClicked(0) && hovered_id)
+ {
+ g.DebugItemPickerBreakID = hovered_id;
+ g.DebugItemPickerActive = false;
+ }
+ ImGui::SetNextWindowBgAlpha(0.60f);
+ ImGui::BeginTooltip();
+ ImGui::Text("HoveredId: 0x%08X", hovered_id);
+ ImGui::Text("Press ESC to abort picking.");
+ ImGui::TextColored(GetStyleColorVec4(hovered_id ? ImGuiCol_Text : ImGuiCol_TextDisabled), "Click to break in debugger!");
+ ImGui::EndTooltip();
+ }
+}
+
void ImGui::Initialize(ImGuiContext* context)
{
ImGuiContext& g = *context;
@@ -3727,7 +4145,7 @@ void ImGui::Initialize(ImGuiContext* context)
// Add .ini handle for ImGuiWindow type
ImGuiSettingsHandler ini_handler;
ini_handler.TypeName = "Window";
- ini_handler.TypeHash = ImHashStr("Window", 0);
+ ini_handler.TypeHash = ImHashStr("Window");
ini_handler.ReadOpenFn = SettingsHandlerWindow_ReadOpen;
ini_handler.ReadLineFn = SettingsHandlerWindow_ReadLine;
ini_handler.WriteAllFn = SettingsHandlerWindow_WriteAll;
@@ -3737,6 +4155,7 @@ void ImGui::Initialize(ImGuiContext* context)
ImGuiViewportP* viewport = IM_NEW(ImGuiViewportP)();
viewport->ID = IMGUI_VIEWPORT_DEFAULT_ID;
viewport->Idx = 0;
+ viewport->PlatformWindowCreated = true;
g.Viewports.push_back(viewport);
g.PlatformIO.MainViewport = g.Viewports[0]; // Make it accessible in public-facing GetPlatformIO() immediately (before the first call to EndFrame)
g.PlatformIO.Viewports.push_back(g.Viewports[0]);
@@ -3760,7 +4179,7 @@ void ImGui::Shutdown(ImGuiContext* context)
}
g.IO.Fonts = NULL;
- // Cleanup of other data are conditional on actually having initialized ImGui.
+ // Cleanup of other data are conditional on actually having initialized Dear ImGui.
if (!g.Initialized)
return;
@@ -3801,14 +4220,18 @@ void ImGui::Shutdown(ImGuiContext* context)
g.FontStack.clear();
g.OpenPopupStack.clear();
g.BeginPopupStack.clear();
+
g.CurrentViewport = g.MouseViewport = g.MouseLastHoveredViewport = NULL;
for (int i = 0; i < g.Viewports.Size; i++)
IM_DELETE(g.Viewports[i]);
g.Viewports.clear();
+
+ g.TabBars.Clear();
+ g.CurrentTabBarStack.clear();
+ g.ShrinkWidthBuffer.clear();
+
g.PrivateClipboard.clear();
- g.InputTextState.TextW.clear();
- g.InputTextState.InitialText.clear();
- g.InputTextState.TempBuffer.clear();
+ g.InputTextState.ClearFreeMemory();
for (int i = 0; i < g.SettingsWindows.Size; i++)
IM_DELETE(g.SettingsWindows[i].Name);
@@ -3820,7 +4243,7 @@ void ImGui::Shutdown(ImGuiContext* context)
fclose(g.LogFile);
g.LogFile = NULL;
}
- g.LogClipboard.clear();
+ g.LogBuffer.clear();
g.Initialized = false;
}
@@ -3844,7 +4267,7 @@ static void AddWindowToSortBuffer(ImVector* out_sorted_windows, Im
{
int count = window->DC.ChildWindows.Size;
if (count > 1)
- ImQsort(window->DC.ChildWindows.begin(), (size_t)count, sizeof(ImGuiWindow*), ChildWindowComparer);
+ ImQsort(window->DC.ChildWindows.Data, (size_t)count, sizeof(ImGuiWindow*), ChildWindowComparer);
for (int i = 0; i < count; i++)
{
ImGuiWindow* child = window->DC.ChildWindows[i];
@@ -3868,19 +4291,28 @@ static void AddDrawListToDrawData(ImVector* out_list, ImDrawList* d
return;
}
- // Draw list sanity check. Detect mismatch between PrimReserve() calls and incrementing _VtxCurrentIdx, _VtxWritePtr etc. May trigger for you if you are using PrimXXX functions incorrectly.
+ // Draw list sanity check. Detect mismatch between PrimReserve() calls and incrementing _VtxCurrentIdx, _VtxWritePtr etc.
+ // May trigger for you if you are using PrimXXX functions incorrectly.
IM_ASSERT(draw_list->VtxBuffer.Size == 0 || draw_list->_VtxWritePtr == draw_list->VtxBuffer.Data + draw_list->VtxBuffer.Size);
IM_ASSERT(draw_list->IdxBuffer.Size == 0 || draw_list->_IdxWritePtr == draw_list->IdxBuffer.Data + draw_list->IdxBuffer.Size);
- IM_ASSERT((int)draw_list->_VtxCurrentIdx == draw_list->VtxBuffer.Size);
+ if (!(draw_list->Flags & ImDrawListFlags_AllowVtxOffset))
+ IM_ASSERT((int)draw_list->_VtxCurrentIdx == draw_list->VtxBuffer.Size);
// Check that draw_list doesn't use more vertices than indexable (default ImDrawIdx = unsigned short = 2 bytes = 64K vertices per ImDrawList = per window)
// If this assert triggers because you are drawing lots of stuff manually:
- // A) Make sure you are coarse clipping, because ImDrawList let all your vertices pass. You can use the Metrics window to inspect draw list contents.
- // B) If you need/want meshes with more than 64K vertices, uncomment the '#define ImDrawIdx unsigned int' line in imconfig.h to set the index size to 4 bytes.
- // You'll need to handle the 4-bytes indices to your renderer. For example, the OpenGL example code detect index size at compile-time by doing:
- // glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset);
- // Your own engine or render API may use different parameters or function calls to specify index sizes. 2 and 4 bytes indices are generally supported by most API.
- // C) If for some reason you cannot use 4 bytes indices or don't want to, a workaround is to call BeginChild()/EndChild() before reaching the 64K limit to split your draw commands in multiple draw lists.
+ // - First, make sure you are coarse clipping yourself and not trying to draw many things outside visible bounds.
+ // Be mindful that the ImDrawList API doesn't filter vertices. Use the Metrics window to inspect draw list contents.
+ // - If you want large meshes with more than 64K vertices, you can either:
+ // (A) Handle the ImDrawCmd::VtxOffset value in your renderer back-end, and set 'io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset'.
+ // Most example back-ends already support this from 1.71. Pre-1.71 back-ends won't.
+ // Some graphics API such as GL ES 1/2 don't have a way to offset the starting vertex so it is not supported for them.
+ // (B) Or handle 32-bits indices in your renderer back-end, and uncomment '#define ImDrawIdx unsigned int' line in imconfig.h.
+ // Most example back-ends already support this. For example, the OpenGL example code detect index size at compile-time:
+ // glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset);
+ // Your own engine or render API may use different parameters or function calls to specify index sizes.
+ // 2 and 4 bytes indices are generally supported by most graphics API.
+ // - If for some reason neither of those solutions works for you, a workaround is to call BeginChild()/EndChild() before reaching
+ // the 64K limit to split your draw commands in multiple draw lists.
if (sizeof(ImDrawIdx) == 2)
IM_ASSERT(draw_list->_VtxCurrentIdx < (1 << 16) && "Too many vertices in ImDrawList using 16-bit indices. Read comment above");
@@ -3935,6 +4367,8 @@ static void SetupViewportDrawData(ImGuiViewportP* viewport, ImVectorTotalVtxCount = draw_data->TotalIdxCount = 0;
draw_data->DisplayPos = viewport->Pos;
draw_data->DisplaySize = viewport->Size;
+ draw_data->FramebufferScale = ImGui::GetIO().DisplayFramebufferScale; // FIXME-VIEWPORT: This may vary on a per-monitor/viewport basis?
+ draw_data->OwnerViewport = viewport;
for (int n = 0; n < draw_lists->Size; n++)
{
draw_data->TotalVtxCount += draw_lists->Data[n]->VtxBuffer.Size;
@@ -3970,7 +4404,7 @@ static void ImGui::EndFrameDrawDimmedBackgrounds()
ImGuiContext& g = *GImGui;
// Draw modal whitening background on _other_ viewports than the one the modal is one
- ImGuiWindow* modal_window = GetFrontMostPopupModal();
+ ImGuiWindow* modal_window = GetTopMostPopupModal();
const bool dim_bg_for_modal = (modal_window != NULL);
const bool dim_bg_for_window_list = (g.NavWindowingTargetAnim != NULL);
if (dim_bg_for_modal || dim_bg_for_window_list)
@@ -3983,7 +4417,7 @@ static void ImGui::EndFrameDrawDimmedBackgrounds()
continue;
if (g.NavWindowingTargetAnim && viewport == g.NavWindowingTargetAnim->Viewport)
continue;
- ImDrawList* draw_list = GetOverlayDrawList(viewport);
+ ImDrawList* draw_list = GetForegroundDrawList(viewport);
const ImU32 dim_bg_col = GetColorU32(dim_bg_for_modal ? ImGuiCol_ModalWindowDimBg : ImGuiCol_NavWindowingDimBg, g.DimBgRatio);
draw_list->AddRectFilled(viewport->Pos, viewport->Pos + viewport->Size, dim_bg_col);
}
@@ -4050,7 +4484,7 @@ void ImGui::EndFrame()
}
// Hide implicit/fallback "Debug" window if it hasn't been used
- g.FrameScopePushedImplicitWindow = false;
+ g.FrameScopePushedFallbackWindow = false;
if (g.CurrentWindow && !g.CurrentWindow->WriteAccessed)
g.CurrentWindow->Active = false;
End();
@@ -4125,23 +4559,30 @@ void ImGui::Render()
if (g.FrameCountEnded != g.FrameCount)
EndFrame();
g.FrameCountRendered = g.FrameCount;
-
- // Gather ImDrawList to render (for each active window)
g.IO.MetricsRenderVertices = g.IO.MetricsRenderIndices = g.IO.MetricsRenderWindows = 0;
+
+ // Add background ImDrawList (for each active viewport)
for (int n = 0; n != g.Viewports.Size; n++)
- g.Viewports[n]->DrawDataBuilder.Clear();
- ImGuiWindow* windows_to_render_front_most[2];
- windows_to_render_front_most[0] = (g.NavWindowingTarget && !(g.NavWindowingTarget->Flags & ImGuiWindowFlags_NoBringToFrontOnFocus)) ? g.NavWindowingTarget->RootWindow : NULL;
- windows_to_render_front_most[1] = g.NavWindowingTarget ? g.NavWindowingList : NULL;
+ {
+ ImGuiViewportP* viewport = g.Viewports[n];
+ viewport->DrawDataBuilder.Clear();
+ if (viewport->DrawLists[0] != NULL)
+ AddDrawListToDrawData(&viewport->DrawDataBuilder.Layers[0], GetBackgroundDrawList(viewport));
+ }
+
+ // Add ImDrawList to render (for each active window)
+ ImGuiWindow* windows_to_render_top_most[2];
+ windows_to_render_top_most[0] = (g.NavWindowingTarget && !(g.NavWindowingTarget->Flags & ImGuiWindowFlags_NoBringToFrontOnFocus)) ? g.NavWindowingTarget->RootWindow : NULL;
+ windows_to_render_top_most[1] = (g.NavWindowingTarget ? g.NavWindowingList : NULL);
for (int n = 0; n != g.Windows.Size; n++)
{
ImGuiWindow* window = g.Windows[n];
- if (IsWindowActiveAndVisible(window) && (window->Flags & ImGuiWindowFlags_ChildWindow) == 0 && window != windows_to_render_front_most[0] && window != windows_to_render_front_most[1])
+ if (IsWindowActiveAndVisible(window) && (window->Flags & ImGuiWindowFlags_ChildWindow) == 0 && window != windows_to_render_top_most[0] && window != windows_to_render_top_most[1])
AddRootWindowToDrawData(window);
}
- for (int n = 0; n < IM_ARRAYSIZE(windows_to_render_front_most); n++)
- if (windows_to_render_front_most[n] && IsWindowActiveAndVisible(windows_to_render_front_most[n])) // NavWindowingTarget is always temporarily displayed as the front-most window
- AddRootWindowToDrawData(windows_to_render_front_most[n]);
+ for (int n = 0; n < IM_ARRAYSIZE(windows_to_render_top_most); n++)
+ if (windows_to_render_top_most[n] && IsWindowActiveAndVisible(windows_to_render_top_most[n])) // NavWindowingTarget is always temporarily displayed as the tp-most window
+ AddRootWindowToDrawData(windows_to_render_top_most[n]);
// Draw software mouse cursor if requested
if (g.IO.MouseDrawCursor)
@@ -4153,8 +4594,11 @@ void ImGui::Render()
{
ImGuiViewportP* viewport = g.Viewports[n];
viewport->DrawDataBuilder.FlattenIntoSingleLayer();
- if (viewport->OverlayDrawList != NULL)
- AddDrawListToDrawData(&viewport->DrawDataBuilder.Layers[0], GetOverlayDrawList(viewport));
+
+ // Add foreground ImDrawList (for each active viewport)
+ if (viewport->DrawLists[1] != NULL)
+ AddDrawListToDrawData(&viewport->DrawDataBuilder.Layers[0], GetForegroundDrawList(viewport));
+
SetupViewportDrawData(viewport, &viewport->DrawDataBuilder.Layers[0]);
g.IO.MetricsRenderVertices += viewport->DrawData->TotalVtxCount;
g.IO.MetricsRenderIndices += viewport->DrawData->TotalIdxCount;
@@ -4185,69 +4629,24 @@ ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_tex
return ImVec2(0.0f, font_size);
ImVec2 text_size = font->CalcTextSizeA(font_size, FLT_MAX, wrap_width, text, text_display_end, NULL);
- // Cancel out character spacing for the last character of a line (it is baked into glyph->AdvanceX field)
- const float font_scale = font_size / font->FontSize;
- const float character_spacing_x = 1.0f * font_scale;
- if (text_size.x > 0.0f)
- text_size.x -= character_spacing_x;
+ // Round
text_size.x = (float)(int)(text_size.x + 0.95f);
return text_size;
}
-// Helper to calculate coarse clipping of large list of evenly sized items.
-// NB: Prefer using the ImGuiListClipper higher-level helper if you can! Read comments and instructions there on how those use this sort of pattern.
-// NB: 'items_count' is only used to clamp the result, if you don't know your count you can use INT_MAX
-void ImGui::CalcListClipping(int items_count, float items_height, int* out_items_display_start, int* out_items_display_end)
+// Find window given position, search front-to-back
+// FIXME: Note that we have an inconsequential lag here: OuterRectClipped is updated in Begin(), so windows moved programatically
+// with SetWindowPos() and not SetNextWindowPos() will have that rectangle lagging by a frame at the time FindHoveredWindow() is
+// called, aka before the next Begin(). Moving window isn't affected.
+static void FindHoveredWindow()
{
ImGuiContext& g = *GImGui;
- ImGuiWindow* window = g.CurrentWindow;
- if (g.LogEnabled)
- {
- // If logging is active, do not perform any clipping
- *out_items_display_start = 0;
- *out_items_display_end = items_count;
- return;
- }
- if (window->SkipItems)
- {
- *out_items_display_start = *out_items_display_end = 0;
- return;
- }
-
- // We create the union of the ClipRect and the NavScoringRect which at worst should be 1 page away from ClipRect
- ImRect unclipped_rect = window->ClipRect;
- if (g.NavMoveRequest)
- unclipped_rect.Add(g.NavScoringRectScreen);
- const ImVec2 pos = window->DC.CursorPos;
- int start = (int)((unclipped_rect.Min.y - pos.y) / items_height);
- int end = (int)((unclipped_rect.Max.y - pos.y) / items_height);
-
- // When performing a navigation request, ensure we have one item extra in the direction we are moving to
- if (g.NavMoveRequest && g.NavMoveClipDir == ImGuiDir_Up)
- start--;
- if (g.NavMoveRequest && g.NavMoveClipDir == ImGuiDir_Down)
- end++;
-
- start = ImClamp(start, 0, items_count);
- end = ImClamp(end + 1, start, items_count);
- *out_items_display_start = start;
- *out_items_display_end = end;
-}
-
-// Find window given position, search front-to-back
-// FIXME: Note that we have an inconsequential lag here: OuterRectClipped is updated in Begin(), so windows moved programatically
-// with SetWindowPos() and not SetNextWindowPos() will have that rectangle lagging by a frame at the time FindHoveredWindow() is
-// called, aka before the next Begin(). Moving window isn't affected.
-static void FindHoveredWindow()
-{
- ImGuiContext& g = *GImGui;
-
- // Special handling for the window being moved: Ignore the mouse viewport check (because it may reset/lose its viewport during the undocking frame)
- ImGuiViewportP* moving_window_viewport = g.MovingWindow ? g.MovingWindow->Viewport : NULL;
- if (g.MovingWindow)
- g.MovingWindow->Viewport = g.MouseViewport;
+ // Special handling for the window being moved: Ignore the mouse viewport check (because it may reset/lose its viewport during the undocking frame)
+ ImGuiViewportP* moving_window_viewport = g.MovingWindow ? g.MovingWindow->Viewport : NULL;
+ if (g.MovingWindow)
+ g.MovingWindow->Viewport = g.MouseViewport;
ImGuiWindow* hovered_window = NULL;
ImGuiWindow* hovered_window_ignoring_moving_window = NULL;
@@ -4269,7 +4668,7 @@ static void FindHoveredWindow()
// Using the clipped AABB, a child window will typically be clipped by its parent (not always)
ImRect bb(window->OuterRectClipped);
- if ((window->Flags & ImGuiWindowFlags_ChildWindow) || (window->Flags & ImGuiWindowFlags_NoResize))
+ if (window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize))
bb.Expand(padding_regular);
else
bb.Expand(padding_for_resize_from_edges);
@@ -4295,7 +4694,7 @@ static void FindHoveredWindow()
g.HoveredWindow = hovered_window;
g.HoveredRootWindow = g.HoveredWindow ? g.HoveredWindow->RootWindow : NULL;
- g.HoveredWindowUnderMovingWindow = g.MovingWindow ? hovered_window_ignoring_moving_window : NULL;
+ g.HoveredWindowUnderMovingWindow = hovered_window_ignoring_moving_window;
if (g.MovingWindow)
g.MovingWindow->Viewport = moving_window_viewport;
@@ -4325,15 +4724,18 @@ bool ImGui::IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool c
int ImGui::GetKeyIndex(ImGuiKey imgui_key)
{
IM_ASSERT(imgui_key >= 0 && imgui_key < ImGuiKey_COUNT);
- return GImGui->IO.KeyMap[imgui_key];
+ ImGuiContext& g = *GImGui;
+ return g.IO.KeyMap[imgui_key];
}
// Note that imgui doesn't know the semantic of each entry of io.KeysDown[]. Use your own indices/enums according to how your back-end/engine stored them into io.KeysDown[]!
bool ImGui::IsKeyDown(int user_key_index)
{
- if (user_key_index < 0) return false;
- IM_ASSERT(user_key_index >= 0 && user_key_index < IM_ARRAYSIZE(GImGui->IO.KeysDown));
- return GImGui->IO.KeysDown[user_key_index];
+ if (user_key_index < 0)
+ return false;
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(user_key_index >= 0 && user_key_index < IM_ARRAYSIZE(g.IO.KeysDown));
+ return g.IO.KeysDown[user_key_index];
}
int ImGui::CalcTypematicPressedRepeatAmount(float t, float t_prev, float repeat_delay, float repeat_rate)
@@ -4349,7 +4751,7 @@ int ImGui::CalcTypematicPressedRepeatAmount(float t, float t_prev, float repeat_
int ImGui::GetKeyPressedAmount(int key_index, float repeat_delay, float repeat_rate)
{
ImGuiContext& g = *GImGui;
- if (key_index < 0)
+ if (key_index < 0)
return 0;
IM_ASSERT(key_index >= 0 && key_index < IM_ARRAYSIZE(g.IO.KeysDown));
const float t = g.IO.KeysDownDuration[key_index];
@@ -4359,7 +4761,7 @@ int ImGui::GetKeyPressedAmount(int key_index, float repeat_delay, float repeat_r
bool ImGui::IsKeyPressed(int user_key_index, bool repeat)
{
ImGuiContext& g = *GImGui;
- if (user_key_index < 0)
+ if (user_key_index < 0)
return false;
IM_ASSERT(user_key_index >= 0 && user_key_index < IM_ARRAYSIZE(g.IO.KeysDown));
const float t = g.IO.KeysDownDuration[user_key_index];
@@ -4404,8 +4806,9 @@ bool ImGui::IsMouseClicked(int button, bool repeat)
if (repeat && t > g.IO.KeyRepeatDelay)
{
- float delay = g.IO.KeyRepeatDelay, rate = g.IO.KeyRepeatRate;
- if ((ImFmod(t - delay, rate) > rate*0.5f) != (ImFmod(t - delay - g.IO.DeltaTime, rate) > rate*0.5f))
+ // FIXME: 2019/05/03: Our old repeat code was wrong here and led to doubling the repeat rate, which made it an ok rate for repeat on mouse hold.
+ int amount = CalcTypematicPressedRepeatAmount(t, t - g.IO.DeltaTime, g.IO.KeyRepeatDelay, g.IO.KeyRepeatRate * 0.5f);
+ if (amount > 0)
return true;
}
@@ -4426,17 +4829,25 @@ bool ImGui::IsMouseDoubleClicked(int button)
return g.IO.MouseDoubleClicked[button];
}
-bool ImGui::IsMouseDragging(int button, float lock_threshold)
+// [Internal] This doesn't test if the button is pressed
+bool ImGui::IsMouseDragPastThreshold(int button, float lock_threshold)
{
ImGuiContext& g = *GImGui;
IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
- if (!g.IO.MouseDown[button])
- return false;
if (lock_threshold < 0.0f)
lock_threshold = g.IO.MouseDragThreshold;
return g.IO.MouseDragMaxDistanceSqr[button] >= lock_threshold * lock_threshold;
}
+bool ImGui::IsMouseDragging(int button, float lock_threshold)
+{
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
+ if (!g.IO.MouseDown[button])
+ return false;
+ return IsMouseDragPastThreshold(button, lock_threshold);
+}
+
ImVec2 ImGui::GetMousePos()
{
return GImGui->IO.MousePos;
@@ -4462,7 +4873,7 @@ bool ImGui::IsMousePosValid(const ImVec2* mouse_pos)
return p.x >= MOUSE_INVALID && p.y >= MOUSE_INVALID;
}
-// Return the delta from the initial clicking position.
+// Return the delta from the initial clicking position while the mouse button is clicked or was just released.
// This is locked and return 0.0f until the mouse moves past a distance threshold at least once.
// NB: This is only valid if IsMousePosValid(). Back-ends in theory should always keep mouse position valid when dragging even outside the client window.
ImVec2 ImGui::GetMouseDragDelta(int button, float lock_threshold)
@@ -4471,9 +4882,10 @@ ImVec2 ImGui::GetMouseDragDelta(int button, float lock_threshold)
IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
if (lock_threshold < 0.0f)
lock_threshold = g.IO.MouseDragThreshold;
- if (g.IO.MouseDown[button])
+ if (g.IO.MouseDown[button] || g.IO.MouseReleased[button])
if (g.IO.MouseDragMaxDistanceSqr[button] >= lock_threshold * lock_threshold)
- return g.IO.MousePos - g.IO.MouseClickedPos[button]; // Assume we can only get active with left-mouse button (at the moment).
+ if (IsMousePosValid(&g.IO.MousePos) && IsMousePosValid(&g.IO.MouseClickedPos[button]))
+ return g.IO.MousePos - g.IO.MouseClickedPos[button];
return ImVec2(0.0f, 0.0f);
}
@@ -4516,17 +4928,31 @@ bool ImGui::IsItemActive()
return false;
}
+bool ImGui::IsItemActivated()
+{
+ ImGuiContext& g = *GImGui;
+ if (g.ActiveId)
+ {
+ ImGuiWindow* window = g.CurrentWindow;
+ if (g.ActiveId == window->DC.LastItemId && g.ActiveIdPreviousFrame != window->DC.LastItemId)
+ return true;
+ }
+ return false;
+}
+
bool ImGui::IsItemDeactivated()
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
+ if (window->DC.LastItemStatusFlags & ImGuiItemStatusFlags_HasDeactivated)
+ return (window->DC.LastItemStatusFlags & ImGuiItemStatusFlags_Deactivated) != 0;
return (g.ActiveIdPreviousFrame == window->DC.LastItemId && g.ActiveIdPreviousFrame != 0 && g.ActiveId != window->DC.LastItemId);
}
bool ImGui::IsItemDeactivatedAfterEdit()
{
ImGuiContext& g = *GImGui;
- return IsItemDeactivated() && (g.ActiveIdPreviousFrameHasBeenEdited || (g.ActiveId == 0 && g.ActiveIdHasBeenEdited));
+ return IsItemDeactivated() && (g.ActiveIdPreviousFrameHasBeenEditedBefore || (g.ActiveId == 0 && g.ActiveIdHasBeenEditedBefore));
}
bool ImGui::IsItemFocused()
@@ -4550,6 +4976,12 @@ bool ImGui::IsItemClicked(int mouse_button)
return IsMouseClicked(mouse_button) && IsItemHovered(ImGuiHoveredFlags_None);
}
+bool ImGui::IsItemToggledSelection()
+{
+ ImGuiContext& g = *GImGui;
+ return (g.CurrentWindow->DC.LastItemStatusFlags & ImGuiItemStatusFlags_ToggledSelection) ? true : false;
+}
+
bool ImGui::IsAnyItemHovered()
{
ImGuiContext& g = *GImGui;
@@ -4762,13 +5194,14 @@ ImGuiWindow* ImGui::FindWindowByID(ImGuiID id)
ImGuiWindow* ImGui::FindWindowByName(const char* name)
{
- ImGuiID id = ImHashStr(name, 0);
+ ImGuiID id = ImHashStr(name);
return FindWindowByID(id);
}
static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFlags flags)
{
ImGuiContext& g = *GImGui;
+ //IMGUI_DEBUG_LOG("CreateNewWindow '%s', flags = 0x%08X\n", name, flags);
// Create window the first time
ImGuiWindow* window = IM_NEW(ImGuiWindow)(&g, name);
@@ -4789,21 +5222,21 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFl
if (settings->ViewportId)
{
window->ViewportId = settings->ViewportId;
- window->ViewportPos = settings->ViewportPos;
+ window->ViewportPos = ImVec2(settings->ViewportPos.x, settings->ViewportPos.y);
}
else
{
window->ViewportPos = main_viewport->Pos;
}
- window->Pos = ImFloor(settings->Pos + window->ViewportPos);
+ window->Pos = ImVec2(settings->Pos.x + window->ViewportPos.x, settings->Pos.y + window->ViewportPos.y);
window->Collapsed = settings->Collapsed;
- if (ImLengthSqr(settings->Size) > 0.00001f)
- size = ImFloor(settings->Size);
+ if (settings->Size.x > 0 && settings->Size.y > 0)
+ size = ImVec2(settings->Size.x, settings->Size.y);
window->DockId = settings->DockId;
window->DockOrder = settings->DockOrder;
}
- window->Size = window->SizeFull = window->SizeFullAtLastBegin = ImFloor(size);
- window->DC.CursorMaxPos = window->Pos; // So first call to CalcSizeContents() doesn't return crazy values
+ window->Size = window->SizeFull = ImFloor(size);
+ window->DC.CursorStartPos = window->DC.CursorMaxPos = window->Pos; // So first call to CalcContentSize() doesn't return crazy values
if ((flags & ImGuiWindowFlags_AlwaysAutoResize) != 0)
{
@@ -4837,10 +5270,10 @@ static ImGuiWindow* GetWindowForTitleAndMenuHeight(ImGuiWindow* window)
return (window->DockNodeAsHost && window->DockNodeAsHost->VisibleWindow) ? window->DockNodeAsHost->VisibleWindow : window;
}
-static ImVec2 CalcSizeAfterConstraint(ImGuiWindow* window, ImVec2 new_size)
+static ImVec2 CalcWindowSizeAfterConstraint(ImGuiWindow* window, ImVec2 new_size)
{
ImGuiContext& g = *GImGui;
- if (g.NextWindowData.SizeConstraintCond != 0)
+ if (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasSizeConstraint)
{
// Using -1,-1 on either X/Y axis to preserve the current size.
ImRect cr = g.NextWindowData.SizeConstraintRect;
@@ -4856,6 +5289,8 @@ static ImVec2 CalcSizeAfterConstraint(ImGuiWindow* window, ImVec2 new_size)
g.NextWindowData.SizeCallback(&data);
new_size = data.DesiredSize;
}
+ new_size.x = ImFloor(new_size.x);
+ new_size.y = ImFloor(new_size.y);
}
// Minimum size
@@ -4868,27 +5303,31 @@ static ImVec2 CalcSizeAfterConstraint(ImGuiWindow* window, ImVec2 new_size)
return new_size;
}
-static ImVec2 CalcSizeContents(ImGuiWindow* window)
+static ImVec2 CalcWindowContentSize(ImGuiWindow* window)
{
if (window->Collapsed)
- return window->SizeContents;
- if (window->Hidden && window->HiddenFramesForResize == 0 && window->HiddenFramesRegular > 0)
- return window->SizeContents;
+ if (window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0)
+ return window->ContentSize;
+ if (window->Hidden && window->HiddenFramesCannotSkipItems == 0 && window->HiddenFramesCanSkipItems > 0)
+ return window->ContentSize;
ImVec2 sz;
- sz.x = (float)(int)((window->SizeContentsExplicit.x != 0.0f) ? window->SizeContentsExplicit.x : (window->DC.CursorMaxPos.x - window->Pos.x + window->Scroll.x));
- sz.y = (float)(int)((window->SizeContentsExplicit.y != 0.0f) ? window->SizeContentsExplicit.y : (window->DC.CursorMaxPos.y - window->Pos.y + window->Scroll.y));
- return sz + window->WindowPadding;
+ sz.x = (float)(int)((window->ContentSizeExplicit.x != 0.0f) ? window->ContentSizeExplicit.x : window->DC.CursorMaxPos.x - window->DC.CursorStartPos.x);
+ sz.y = (float)(int)((window->ContentSizeExplicit.y != 0.0f) ? window->ContentSizeExplicit.y : window->DC.CursorMaxPos.y - window->DC.CursorStartPos.y);
+ return sz;
}
-static ImVec2 CalcSizeAutoFit(ImGuiWindow* window, const ImVec2& size_contents)
+static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_contents)
{
ImGuiContext& g = *GImGui;
ImGuiStyle& style = g.Style;
+ ImVec2 size_decorations = ImVec2(0.0f, window->TitleBarHeight() + window->MenuBarHeight());
+ ImVec2 size_pad = window->WindowPadding * 2.0f;
+ ImVec2 size_desired = size_contents + size_pad + size_decorations;
if (window->Flags & ImGuiWindowFlags_Tooltip)
{
// Tooltip always resize
- return size_contents;
+ return size_desired;
}
else
{
@@ -4905,14 +5344,16 @@ static ImVec2 CalcSizeAutoFit(ImGuiWindow* window, const ImVec2& size_contents)
const int monitor_idx = window->ViewportAllowPlatformMonitorExtend;
if (monitor_idx >= 0 && monitor_idx < g.PlatformIO.Monitors.Size)
avail_size = g.PlatformIO.Monitors[monitor_idx].WorkSize;
- ImVec2 size_auto_fit = ImClamp(size_contents, size_min, ImMax(size_min, avail_size - g.Style.DisplaySafeAreaPadding * 2.0f));
+ ImVec2 size_auto_fit = ImClamp(size_desired, size_min, ImMax(size_min, avail_size - g.Style.DisplaySafeAreaPadding * 2.0f));
// When the window cannot fit all contents (either because of constraints, either because screen is too small),
// we are growing the size on the other axis to compensate for expected scrollbar. FIXME: Might turn bigger than ViewportSize-WindowPadding.
- ImVec2 size_auto_fit_after_constraint = CalcSizeAfterConstraint(window, size_auto_fit);
- if (size_auto_fit_after_constraint.x < size_contents.x && !(window->Flags & ImGuiWindowFlags_NoScrollbar) && (window->Flags & ImGuiWindowFlags_HorizontalScrollbar))
+ ImVec2 size_auto_fit_after_constraint = CalcWindowSizeAfterConstraint(window, size_auto_fit);
+ bool will_have_scrollbar_x = (size_auto_fit_after_constraint.x - size_pad.x - size_decorations.x < size_contents.x && !(window->Flags & ImGuiWindowFlags_NoScrollbar) && (window->Flags & ImGuiWindowFlags_HorizontalScrollbar)) || (window->Flags & ImGuiWindowFlags_AlwaysHorizontalScrollbar);
+ bool will_have_scrollbar_y = (size_auto_fit_after_constraint.y - size_pad.y - size_decorations.y < size_contents.y && !(window->Flags & ImGuiWindowFlags_NoScrollbar)) || (window->Flags & ImGuiWindowFlags_AlwaysVerticalScrollbar);
+ if (will_have_scrollbar_x)
size_auto_fit.y += style.ScrollbarSize;
- if (size_auto_fit_after_constraint.y < size_contents.y && !(window->Flags & ImGuiWindowFlags_NoScrollbar))
+ if (will_have_scrollbar_y)
size_auto_fit.x += style.ScrollbarSize;
return size_auto_fit;
}
@@ -4920,47 +5361,10 @@ static ImVec2 CalcSizeAutoFit(ImGuiWindow* window, const ImVec2& size_contents)
ImVec2 ImGui::CalcWindowExpectedSize(ImGuiWindow* window)
{
- ImVec2 size_contents = CalcSizeContents(window);
- return CalcSizeAfterConstraint(window, CalcSizeAutoFit(window, size_contents));
-}
-
-float ImGui::GetWindowScrollMaxX(ImGuiWindow* window)
-{
- return ImMax(0.0f, window->SizeContents.x - (window->SizeFull.x - window->ScrollbarSizes.x));
-}
-
-float ImGui::GetWindowScrollMaxY(ImGuiWindow* window)
-{
- return ImMax(0.0f, window->SizeContents.y - (window->SizeFull.y - window->ScrollbarSizes.y));
-}
-
-static ImVec2 CalcNextScrollFromScrollTargetAndClamp(ImGuiWindow* window, bool snap_on_edges)
-{
- ImGuiContext& g = *GImGui;
- ImVec2 scroll = window->Scroll;
- if (window->ScrollTarget.x < FLT_MAX)
- {
- float cr_x = window->ScrollTargetCenterRatio.x;
- scroll.x = window->ScrollTarget.x - cr_x * (window->SizeFull.x - window->ScrollbarSizes.x);
- }
- if (window->ScrollTarget.y < FLT_MAX)
- {
- // 'snap_on_edges' allows for a discontinuity at the edge of scrolling limits to take account of WindowPadding so that scrolling to make the last item visible scroll far enough to see the padding.
- float cr_y = window->ScrollTargetCenterRatio.y;
- float target_y = window->ScrollTarget.y;
- if (snap_on_edges && cr_y <= 0.0f && target_y <= window->WindowPadding.y)
- target_y = 0.0f;
- if (snap_on_edges && cr_y >= 1.0f && target_y >= window->SizeContents.y - window->WindowPadding.y + g.Style.ItemSpacing.y)
- target_y = window->SizeContents.y;
- scroll.y = target_y - (1.0f - cr_y) * (window->TitleBarHeight() + window->MenuBarHeight()) - cr_y * (window->SizeFull.y - window->ScrollbarSizes.y);
- }
- scroll = ImMax(scroll, ImVec2(0.0f, 0.0f));
- if (!window->Collapsed && !window->SkipItems)
- {
- scroll.x = ImMin(scroll.x, ImGui::GetWindowScrollMaxX(window));
- scroll.y = ImMin(scroll.y, ImGui::GetWindowScrollMaxY(window));
- }
- return scroll;
+ ImVec2 size_contents = CalcWindowContentSize(window);
+ ImVec2 size_auto_fit = CalcWindowAutoFitSize(window, size_contents);
+ ImVec2 size_final = CalcWindowSizeAfterConstraint(window, size_auto_fit);
+ return size_final;
}
static ImGuiCol GetWindowBgColorIdxFromFlags(ImGuiWindowFlags flags)
@@ -4977,7 +5381,7 @@ static void CalcResizePosSizeFromAnyCorner(ImGuiWindow* window, const ImVec2& co
ImVec2 pos_min = ImLerp(corner_target, window->Pos, corner_norm); // Expected window upper-left
ImVec2 pos_max = ImLerp(window->Pos + window->Size, corner_target, corner_norm); // Expected window lower-right
ImVec2 size_expected = pos_max - pos_min;
- ImVec2 size_constrained = CalcSizeAfterConstraint(window, size_expected);
+ ImVec2 size_constrained = CalcWindowSizeAfterConstraint(window, size_expected);
*out_pos = pos_min;
if (corner_norm.x == 0.0f)
out_pos->x -= (size_constrained.x - size_expected.x);
@@ -5014,15 +5418,18 @@ static ImRect GetResizeBorderRect(ImGuiWindow* window, int border_n, float perp_
}
// Handle resize for: Resize Grips, Borders, Gamepad
-static void ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4])
+// Return true when using auto-fit (double click on resize grip)
+static bool ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4])
{
ImGuiContext& g = *GImGui;
ImGuiWindowFlags flags = window->Flags;
+
if ((flags & ImGuiWindowFlags_NoResize) || (flags & ImGuiWindowFlags_AlwaysAutoResize) || window->AutoFitFramesX > 0 || window->AutoFitFramesY > 0)
- return;
+ return false;
if (window->WasActive == false) // Early out to avoid running this code for e.g. an hidden implicit/fallback Debug window.
- return;
+ return false;
+ bool ret_auto_fit = false;
const int resize_border_count = g.IO.ConfigWindowsResizeFromEdges ? 4 : 0;
const float grip_draw_size = (float)(int)ImMax(g.FontSize * 1.35f, window->WindowRounding + 1.0f + g.FontSize * 0.2f);
const float grip_hover_inner_size = (float)(int)(grip_draw_size * 0.75f);
@@ -5031,6 +5438,19 @@ static void ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au
ImVec2 pos_target(FLT_MAX, FLT_MAX);
ImVec2 size_target(FLT_MAX, FLT_MAX);
+ // Clip mouse interaction rectangles within the viewport (in practice the narrowing is going to happen most of the time).
+ // - Not narrowing would mostly benefit the situation where OS windows _without_ decoration have a threshold for hovering when outside their limits.
+ // This is however not the case with current back-ends under Win32, but a custom borderless window implementation would benefit from it.
+ // - When decoration are enabled we typically benefit from that distance, but then our resize elements would be conflicting with OS resize elements, so we also narrow.
+ // - Note that we are unable to tell if the platform setup allows hovering with a distance threshold (on Win32, decorated window have such threshold).
+ ImRect clip_viewport_rect(-FLT_MAX, -FLT_MAX, +FLT_MAX, +FLT_MAX);
+ if (!(g.IO.BackendFlags & ImGuiBackendFlags_HasMouseHoveredViewport) || (g.IO.MouseHoveredViewport != window->ViewportId) || !(window->Viewport->Flags & ImGuiViewportFlags_NoDecoration))
+ clip_viewport_rect = window->Viewport->GetRect();
+
+ // Resize grips and borders are on layer 1
+ window->DC.NavLayerCurrent = ImGuiNavLayer_Menu;
+ window->DC.NavLayerCurrentMask = (1 << ImGuiNavLayer_Menu);
+
// Manual resize grips
PushID("#RESIZE");
for (int resize_grip_n = 0; resize_grip_n < resize_grip_count; resize_grip_n++)
@@ -5042,16 +5462,18 @@ static void ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au
ImRect resize_rect(corner - grip.InnerDir * grip_hover_outer_size, corner + grip.InnerDir * grip_hover_inner_size);
if (resize_rect.Min.x > resize_rect.Max.x) ImSwap(resize_rect.Min.x, resize_rect.Max.x);
if (resize_rect.Min.y > resize_rect.Max.y) ImSwap(resize_rect.Min.y, resize_rect.Max.y);
+ resize_rect.ClipWith(clip_viewport_rect);
bool hovered, held;
ButtonBehavior(resize_rect, window->GetID((void*)(intptr_t)resize_grip_n), &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus);
- //GetOverlayDrawList(window)->AddRect(resize_rect.Min, resize_rect.Max, IM_COL32(255, 255, 0, 255));
+ //GetForegroundDrawList(window)->AddRect(resize_rect.Min, resize_rect.Max, IM_COL32(255, 255, 0, 255));
if (hovered || held)
g.MouseCursor = (resize_grip_n & 1) ? ImGuiMouseCursor_ResizeNESW : ImGuiMouseCursor_ResizeNWSE;
if (held && g.IO.MouseDoubleClicked[0] && resize_grip_n == 0)
{
// Manual auto-fit when double-clicking
- size_target = CalcSizeAfterConstraint(window, size_auto_fit);
+ size_target = CalcWindowSizeAfterConstraint(window, size_auto_fit);
+ ret_auto_fit = true;
ClearActiveID();
}
else if (held)
@@ -5068,12 +5490,13 @@ static void ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au
{
bool hovered, held;
ImRect border_rect = GetResizeBorderRect(window, border_n, grip_hover_inner_size, WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS);
+ border_rect.ClipWith(clip_viewport_rect);
ButtonBehavior(border_rect, window->GetID((void*)(intptr_t)(border_n + 4)), &hovered, &held, ImGuiButtonFlags_FlattenChildren);
- //GetOverlayDrawList(window)->AddRect(border_rect.Min, border_rect.Max, IM_COL32(255, 255, 0, 255));
+ //GetForegroundDrawList(window)->AddRect(border_rect.Min, border_rect.Max, IM_COL32(255, 255, 0, 255));
if ((hovered && g.HoveredIdTimer > WINDOWS_RESIZE_FROM_EDGES_FEEDBACK_TIMER) || held)
{
g.MouseCursor = (border_n & 1) ? ImGuiMouseCursor_ResizeEW : ImGuiMouseCursor_ResizeNS;
- if (held)
+ if (held)
*border_held = border_n;
}
if (held)
@@ -5089,6 +5512,10 @@ static void ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au
}
PopID();
+ // Resize nav layer
+ window->DC.NavLayerCurrent = ImGuiNavLayer_Main;
+ window->DC.NavLayerCurrentMask = (1 << ImGuiNavLayer_Main);
+
// Navigation resize (keyboard/gamepad)
if (g.NavWindowingTarget && g.NavWindowingTarget->RootWindow == window)
{
@@ -5105,12 +5532,12 @@ static void ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au
g.NavDisableMouseHover = true;
resize_grip_col[0] = GetColorU32(ImGuiCol_ResizeGripActive);
// FIXME-NAV: Should store and accumulate into a separate size buffer to handle sizing constraints properly, right now a constraint will make us stuck.
- size_target = CalcSizeAfterConstraint(window, window->SizeFull + nav_resize_delta);
+ size_target = CalcWindowSizeAfterConstraint(window, window->SizeFull + nav_resize_delta);
}
}
// Apply back modified position/size to window
- if (size_target.x != FLT_MAX && (size_target.x != window->SizeFull.x || size_target.y != window->SizeFull.y))
+ if (size_target.x != FLT_MAX)
{
window->SizeFull = size_target;
MarkIniSettingsDirty(window);
@@ -5122,6 +5549,7 @@ static void ImGui::UpdateManualResize(ImGuiWindow* window, const ImVec2& size_au
}
window->Size = window->SizeFull;
+ return ret_auto_fit;
}
static inline void ClampWindowRect(ImGuiWindow* window, const ImRect& rect, const ImVec2& padding)
@@ -5131,7 +5559,7 @@ static inline void ClampWindowRect(ImGuiWindow* window, const ImRect& rect, cons
window->Pos = ImMin(rect.Max - padding, ImMax(window->Pos + size_for_clamping, rect.Min + padding) - size_for_clamping);
}
-static void ImGui::RenderOuterBorders(ImGuiWindow* window)
+static void ImGui::RenderWindowOuterBorders(ImGuiWindow* window)
{
ImGuiContext& g = *GImGui;
float rounding = window->WindowRounding;
@@ -5168,6 +5596,205 @@ static void ImGui::RenderOuterBorders(ImGuiWindow* window)
}
}
+// Draw background and borders
+// Draw and handle scrollbars
+void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar_rect, bool title_bar_is_highlight, bool handle_borders_and_resize_grips, int resize_grip_count, const ImU32 resize_grip_col[4], float resize_grip_draw_size)
+{
+ ImGuiContext& g = *GImGui;
+ ImGuiStyle& style = g.Style;
+ ImGuiWindowFlags flags = window->Flags;
+
+ // Draw window + handle manual resize
+ // As we highlight the title bar when want_focus is set, multiple reappearing windows will have have their title bar highlighted on their reappearing frame.
+ const float window_rounding = window->WindowRounding;
+ const float window_border_size = window->WindowBorderSize;
+ if (window->Collapsed)
+ {
+ // Title bar only
+ float backup_border_size = style.FrameBorderSize;
+ g.Style.FrameBorderSize = window->WindowBorderSize;
+ ImU32 title_bar_col = GetColorU32((title_bar_is_highlight && !g.NavDisableHighlight) ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBgCollapsed);
+ RenderFrame(title_bar_rect.Min, title_bar_rect.Max, title_bar_col, true, window_rounding);
+ g.Style.FrameBorderSize = backup_border_size;
+ }
+ else
+ {
+ // Window background
+ if (!(flags & ImGuiWindowFlags_NoBackground))
+ {
+ bool is_docking_transparent_payload = false;
+ if (g.DragDropActive && (g.FrameCount - g.DragDropAcceptFrameCount) <= 1 && g.IO.ConfigDockingTransparentPayload)
+ if (g.DragDropPayload.IsDataType(IMGUI_PAYLOAD_TYPE_WINDOW) && *(ImGuiWindow**)g.DragDropPayload.Data == window)
+ is_docking_transparent_payload = true;
+
+ ImU32 bg_col = GetColorU32(GetWindowBgColorIdxFromFlags(flags));
+ if (window->ViewportOwned)
+ {
+ // No alpha
+ bg_col = (bg_col | IM_COL32_A_MASK);
+ if (is_docking_transparent_payload)
+ window->Viewport->Alpha *= DOCKING_TRANSPARENT_PAYLOAD_ALPHA;
+ }
+ else
+ {
+ // Adjust alpha. For docking
+ float alpha = 1.0f;
+ if (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasBgAlpha)
+ alpha = g.NextWindowData.BgAlphaVal;
+ if (is_docking_transparent_payload)
+ alpha *= DOCKING_TRANSPARENT_PAYLOAD_ALPHA;
+ if (alpha != 1.0f)
+ bg_col = (bg_col & ~IM_COL32_A_MASK) | (IM_F32_TO_INT8_SAT(alpha) << IM_COL32_A_SHIFT);
+ }
+ window->DrawList->AddRectFilled(window->Pos + ImVec2(0, window->TitleBarHeight()), window->Pos + window->Size, bg_col, window_rounding, (flags & ImGuiWindowFlags_NoTitleBar) ? ImDrawCornerFlags_All : ImDrawCornerFlags_Bot);
+ }
+
+ // Title bar
+ // (when docked, DockNode are drawing their own title bar. Individual windows however do NOT set the _NoTitleBar flag,
+ // in order for their pos/size to be matching their undocking state.)
+ if (!(flags & ImGuiWindowFlags_NoTitleBar) && !window->DockIsActive)
+ {
+ ImU32 title_bar_col = GetColorU32(title_bar_is_highlight ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBg);
+ window->DrawList->AddRectFilled(title_bar_rect.Min, title_bar_rect.Max, title_bar_col, window_rounding, ImDrawCornerFlags_Top);
+ }
+
+ // Menu bar
+ if (flags & ImGuiWindowFlags_MenuBar)
+ {
+ ImRect menu_bar_rect = window->MenuBarRect();
+ menu_bar_rect.ClipWith(window->Rect()); // Soft clipping, in particular child window don't have minimum size covering the menu bar so this is useful for them.
+ window->DrawList->AddRectFilled(menu_bar_rect.Min + ImVec2(window_border_size, 0), menu_bar_rect.Max - ImVec2(window_border_size, 0), GetColorU32(ImGuiCol_MenuBarBg), (flags & ImGuiWindowFlags_NoTitleBar) ? window_rounding : 0.0f, ImDrawCornerFlags_Top);
+ if (style.FrameBorderSize > 0.0f && menu_bar_rect.Max.y < window->Pos.y + window->Size.y)
+ window->DrawList->AddLine(menu_bar_rect.GetBL(), menu_bar_rect.GetBR(), GetColorU32(ImGuiCol_Border), style.FrameBorderSize);
+ }
+
+ // Docking: Unhide tab bar (small triangle in the corner)
+ if (window->DockNode && window->DockNode->IsHiddenTabBar() && !window->DockNode->IsNoTabBar())
+ {
+ float unhide_sz_draw = ImFloor(g.FontSize * 0.70f);
+ float unhide_sz_hit = ImFloor(g.FontSize * 0.55f);
+ ImVec2 p = window->DockNode->Pos;
+ ImRect r(p, p + ImVec2(unhide_sz_hit, unhide_sz_hit));
+ bool hovered, held;
+ if (ButtonBehavior(r, window->GetID("#UNHIDE"), &hovered, &held, ImGuiButtonFlags_FlattenChildren))
+ window->DockNode->WantHiddenTabBarToggle = true;
+ // FIXME-DOCK: Ideally we'd use ImGuiCol_TitleBgActive/ImGuiCol_TitleBg here, but neither is guaranteed to be visible enough at this sort of size..
+ ImU32 col = GetColorU32(((held && hovered) || (window->DockNode->IsFocused && !hovered)) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
+ window->DrawList->AddTriangleFilled(p, p + ImVec2(unhide_sz_draw, 0.0f), p + ImVec2(0.0f, unhide_sz_draw), col);
+ }
+
+ // Scrollbars
+ if (window->ScrollbarX)
+ Scrollbar(ImGuiAxis_X);
+ if (window->ScrollbarY)
+ Scrollbar(ImGuiAxis_Y);
+
+ // Render resize grips (after their input handling so we don't have a frame of latency)
+ if (handle_borders_and_resize_grips && !(flags & ImGuiWindowFlags_NoResize))
+ {
+ for (int resize_grip_n = 0; resize_grip_n < resize_grip_count; resize_grip_n++)
+ {
+ const ImGuiResizeGripDef& grip = resize_grip_def[resize_grip_n];
+ const ImVec2 corner = ImLerp(window->Pos, window->Pos + window->Size, grip.CornerPosN);
+ window->DrawList->PathLineTo(corner + grip.InnerDir * ((resize_grip_n & 1) ? ImVec2(window_border_size, resize_grip_draw_size) : ImVec2(resize_grip_draw_size, window_border_size)));
+ window->DrawList->PathLineTo(corner + grip.InnerDir * ((resize_grip_n & 1) ? ImVec2(resize_grip_draw_size, window_border_size) : ImVec2(window_border_size, resize_grip_draw_size)));
+ window->DrawList->PathArcToFast(ImVec2(corner.x + grip.InnerDir.x * (window_rounding + window_border_size), corner.y + grip.InnerDir.y * (window_rounding + window_border_size)), window_rounding, grip.AngleMin12, grip.AngleMax12);
+ window->DrawList->PathFillConvex(resize_grip_col[resize_grip_n]);
+ }
+ }
+
+ // Borders (for dock node host they will be rendered over after the tab bar)
+ if (handle_borders_and_resize_grips && !window->DockNodeAsHost)
+ RenderWindowOuterBorders(window);
+ }
+}
+
+// Render title text, collapse button, close button
+// When inside a dock node, this is handled in DockNodeUpdateTabBar() instead.
+void ImGui::RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& title_bar_rect, const char* name, bool* p_open)
+{
+ ImGuiContext& g = *GImGui;
+ ImGuiStyle& style = g.Style;
+ ImGuiWindowFlags flags = window->Flags;
+
+ const bool has_close_button = (p_open != NULL);
+ const bool has_collapse_button = !(flags & ImGuiWindowFlags_NoCollapse);
+
+ // Close & Collapse button are on the Menu NavLayer and don't default focus (unless there's nothing else on that layer)
+ const ImGuiItemFlags item_flags_backup = window->DC.ItemFlags;
+ window->DC.ItemFlags |= ImGuiItemFlags_NoNavDefaultFocus;
+ window->DC.NavLayerCurrent = ImGuiNavLayer_Menu;
+ window->DC.NavLayerCurrentMask = (1 << ImGuiNavLayer_Menu);
+
+ // Layout buttons
+ // FIXME: Would be nice to generalize the subtleties expressed here into reusable code.
+ float pad_l = style.FramePadding.x;
+ float pad_r = style.FramePadding.x;
+ float button_sz = g.FontSize;
+ ImVec2 close_button_pos;
+ ImVec2 collapse_button_pos;
+ if (has_close_button)
+ {
+ pad_r += button_sz;
+ close_button_pos = ImVec2(title_bar_rect.Max.x - pad_r - style.FramePadding.x, title_bar_rect.Min.y);
+ }
+ if (has_collapse_button && style.WindowMenuButtonPosition == ImGuiDir_Right)
+ {
+ pad_r += button_sz;
+ collapse_button_pos = ImVec2(title_bar_rect.Max.x - pad_r - style.FramePadding.x, title_bar_rect.Min.y);
+ }
+ if (has_collapse_button && style.WindowMenuButtonPosition == ImGuiDir_Left)
+ {
+ collapse_button_pos = ImVec2(title_bar_rect.Min.x + pad_l - style.FramePadding.x, title_bar_rect.Min.y);
+ pad_l += button_sz;
+ }
+
+ // Collapse button (submitting first so it gets priority when choosing a navigation init fallback)
+ if (has_collapse_button)
+ if (CollapseButton(window->GetID("#COLLAPSE"), collapse_button_pos, NULL))
+ window->WantCollapseToggle = true; // Defer actual collapsing to next frame as we are too far in the Begin() function
+
+ // Close button
+ if (has_close_button)
+ if (CloseButton(window->GetID("#CLOSE"), close_button_pos))
+ *p_open = false;
+
+ window->DC.NavLayerCurrent = ImGuiNavLayer_Main;
+ window->DC.NavLayerCurrentMask = (1 << ImGuiNavLayer_Main);
+ window->DC.ItemFlags = item_flags_backup;
+
+ // Title bar text (with: horizontal alignment, avoiding collapse/close button, optional "unsaved document" marker)
+ // FIXME: Refactor text alignment facilities along with RenderText helpers, this is WAY too much messy code..
+ const char* UNSAVED_DOCUMENT_MARKER = "*";
+ const float marker_size_x = (flags & ImGuiWindowFlags_UnsavedDocument) ? CalcTextSize(UNSAVED_DOCUMENT_MARKER, NULL, false).x : 0.0f;
+ const ImVec2 text_size = CalcTextSize(name, NULL, true) + ImVec2(marker_size_x, 0.0f);
+
+ // As a nice touch we try to ensure that centered title text doesn't get affected by visibility of Close/Collapse button,
+ // while uncentered title text will still reach edges correct.
+ if (pad_l > style.FramePadding.x)
+ pad_l += g.Style.ItemInnerSpacing.x;
+ if (pad_r > style.FramePadding.x)
+ pad_r += g.Style.ItemInnerSpacing.x;
+ if (style.WindowTitleAlign.x > 0.0f && style.WindowTitleAlign.x < 1.0f)
+ {
+ float centerness = ImSaturate(1.0f - ImFabs(style.WindowTitleAlign.x - 0.5f) * 2.0f); // 0.0f on either edges, 1.0f on center
+ float pad_extend = ImMin(ImMax(pad_l, pad_r), title_bar_rect.GetWidth() - pad_l - pad_r - text_size.x);
+ pad_l = ImMax(pad_l, pad_extend * centerness);
+ pad_r = ImMax(pad_r, pad_extend * centerness);
+ }
+
+ ImRect layout_r(title_bar_rect.Min.x + pad_l, title_bar_rect.Min.y, title_bar_rect.Max.x - pad_r, title_bar_rect.Max.y);
+ ImRect clip_r(layout_r.Min.x, layout_r.Min.y, layout_r.Max.x + g.Style.ItemInnerSpacing.x, layout_r.Max.y);
+ //if (g.IO.KeyCtrl) window->DrawList->AddRect(layout_r.Min, layout_r.Max, IM_COL32(255, 128, 0, 255)); // [DEBUG]
+ RenderTextClipped(layout_r.Min, layout_r.Max, name, NULL, &text_size, style.WindowTitleAlign, &clip_r);
+ if (flags & ImGuiWindowFlags_UnsavedDocument)
+ {
+ ImVec2 marker_pos = ImVec2(ImMax(layout_r.Min.x, layout_r.Min.x + (layout_r.GetWidth() - text_size.x) * style.WindowTitleAlign.x) + text_size.x, layout_r.Min.y) + ImVec2(2 - marker_size_x, 0.0f);
+ ImVec2 off = ImVec2(0.0f, (float)(int)(-g.FontSize * 0.25f));
+ RenderTextClipped(marker_pos + off, layout_r.Max + off, UNSAVED_DOCUMENT_MARKER, NULL, NULL, ImVec2(0, style.WindowTitleAlign.y), &clip_r);
+ }
+}
+
void ImGui::UpdateWindowParentAndRootLinks(ImGuiWindow* window, ImGuiWindowFlags flags, ImGuiWindow* parent_window)
{
window->ParentWindow = parent_window;
@@ -5187,7 +5814,7 @@ void ImGui::UpdateWindowParentAndRootLinks(ImGuiWindow* window, ImGuiWindowFlags
}
}
-// Push a new ImGui window to add widgets to.
+// Push a new Dear ImGui window to add widgets to.
// - A default window called "Debug" is automatically stacked at the beginning of every frame so you can use widgets without explicitly calling a Begin/End pair.
// - Begin/End can be called multiple times during the frame with the same window name to append content.
// - The window name is used as a unique identifier to preserve window information across frames (and save rudimentary information to the .ini file).
@@ -5205,10 +5832,9 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
// Find or create
ImGuiWindow* window = FindWindowByName(name);
const bool window_just_created = (window == NULL);
- const bool window_is_fallback = (g.CurrentWindowStack.Size == 0);
if (window_just_created)
{
- ImVec2 size_on_first_use = (g.NextWindowData.SizeCond != 0) ? g.NextWindowData.SizeVal : ImVec2(0.0f, 0.0f); // Any condition flag will do since we are creating a new window here.
+ ImVec2 size_on_first_use = (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasSize) ? g.NextWindowData.SizeVal : ImVec2(0.0f, 0.0f); // Any condition flag will do since we are creating a new window here.
window = CreateNewWindow(name, size_on_first_use, flags);
}
@@ -5221,13 +5847,14 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
const int current_frame = g.FrameCount;
const bool first_begin_of_the_frame = (window->LastFrameActive != current_frame);
+ window->IsFallbackWindow = (g.CurrentWindowStack.Size == 0 && g.FrameScopePushedFallbackWindow);
// Update the Appearing flag
bool window_just_activated_by_user = (window->LastFrameActive < current_frame - 1); // Not using !WasActive because the implicit "Debug" window would always toggle off->on
- const bool window_just_appearing_after_hidden_for_resize = (window->HiddenFramesForResize > 0);
+ const bool window_just_appearing_after_hidden_for_resize = (window->HiddenFramesCannotSkipItems > 0);
if (flags & ImGuiWindowFlags_Popup)
{
- ImGuiPopupRef& popup_ref = g.OpenPopupStack[g.BeginPopupStack.Size];
+ ImGuiPopupData& popup_ref = g.OpenPopupStack[g.BeginPopupStack.Size];
window_just_activated_by_user |= (window->PopupId != popup_ref.PopupId); // We recycle popups so treat window as activated if popup id changed
window_just_activated_by_user |= (window != popup_ref.Window);
}
@@ -5241,6 +5868,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
window->FlagsPreviousFrame = window->Flags;
window->Flags = (ImGuiWindowFlags)flags;
window->LastFrameActive = current_frame;
+ window->LastTimeActive = (float)g.Time;
window->BeginOrderWithinParent = 0;
window->BeginOrderWithinContext = (short)(g.WindowsActiveCount++);
}
@@ -5252,16 +5880,19 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
// Docking
// (NB: during the frame dock nodes are created, it is possible that (window->DockIsActive == false) even though (window->DockNode->Windows.Size > 1)
IM_ASSERT(window->DockNode == NULL || window->DockNodeAsHost == NULL); // Cannot be both
- if (g.NextWindowData.DockCond)
+ if (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasDock)
SetWindowDock(window, g.NextWindowData.DockId, g.NextWindowData.DockCond);
if (first_begin_of_the_frame)
{
bool has_dock_node = (window->DockId != 0 || window->DockNode != NULL);
- bool new_auto_dock_node = !has_dock_node && g.IO.ConfigDockingTabBarOnSingleWindows && !(flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoDocking)) && !window_is_fallback;
+ bool new_auto_dock_node = !has_dock_node && GetWindowAlwaysWantOwnTabBar(window);
if (has_dock_node || new_auto_dock_node)
{
BeginDocked(window, p_open);
flags = window->Flags;
+
+ // Docking currently override constraints
+ g.NextWindowData.Flags &= ~ImGuiNextWindowDataFlags_HasSizeConstraint;
}
}
@@ -5270,6 +5901,10 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
ImGuiWindow* parent_window = first_begin_of_the_frame ? ((flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Popup)) ? parent_window_in_stack : NULL) : window->ParentWindow;
IM_ASSERT(parent_window != NULL || !(flags & ImGuiWindowFlags_ChildWindow));
+ // We allow window memory to be compacted so recreate the base stack when needed.
+ if (window->IDStack.Size == 0)
+ window->IDStack.push_back(window->ID);
+
// Add to stack
// We intentionally set g.CurrentWindow to NULL to prevent usage until when the viewport is set, then will call SetCurrentWindow()
g.CurrentWindowStack.push_back(window);
@@ -5277,7 +5912,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
CheckStacksSize(window, true);
if (flags & ImGuiWindowFlags_Popup)
{
- ImGuiPopupRef& popup_ref = g.OpenPopupStack[g.BeginPopupStack.Size];
+ ImGuiPopupData& popup_ref = g.OpenPopupStack[g.BeginPopupStack.Size];
popup_ref.Window = window;
g.BeginPopupStack.push_back(popup_ref);
window->PopupId = popup_ref.PopupId;
@@ -5289,7 +5924,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
// Process SetNextWindow***() calls
bool window_pos_set_by_api = false;
bool window_size_x_set_by_api = false, window_size_y_set_by_api = false;
- if (g.NextWindowData.PosCond)
+ if (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasPos)
{
window_pos_set_by_api = (window->SetWindowPosAllowFlags & g.NextWindowData.PosCond) != 0;
if (window_pos_set_by_api && ImLengthSqr(g.NextWindowData.PosPivotVal) > 0.00001f)
@@ -5305,27 +5940,21 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
SetWindowPos(window, g.NextWindowData.PosVal, g.NextWindowData.PosCond);
}
}
- if (g.NextWindowData.SizeCond)
+ if (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasSize)
{
window_size_x_set_by_api = (window->SetWindowSizeAllowFlags & g.NextWindowData.SizeCond) != 0 && (g.NextWindowData.SizeVal.x > 0.0f);
window_size_y_set_by_api = (window->SetWindowSizeAllowFlags & g.NextWindowData.SizeCond) != 0 && (g.NextWindowData.SizeVal.y > 0.0f);
SetWindowSize(window, g.NextWindowData.SizeVal, g.NextWindowData.SizeCond);
}
- if (g.NextWindowData.ContentSizeCond)
- {
- // Adjust passed "client size" to become a "window size"
- window->SizeContentsExplicit = g.NextWindowData.ContentSizeVal;
- if (window->SizeContentsExplicit.y != 0.0f)
- window->SizeContentsExplicit.y += window->TitleBarHeight() + window->MenuBarHeight();
- }
+ if (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasContentSize)
+ window->ContentSizeExplicit = g.NextWindowData.ContentSizeVal;
else if (first_begin_of_the_frame)
- {
- window->SizeContentsExplicit = ImVec2(0.0f, 0.0f);
- }
- window->WindowClass = g.NextWindowData.WindowClass;
- if (g.NextWindowData.CollapsedCond)
+ window->ContentSizeExplicit = ImVec2(0.0f, 0.0f);
+ if (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasWindowClass)
+ window->WindowClass = g.NextWindowData.WindowClass;
+ if (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasCollapsed)
SetWindowCollapsed(window, g.NextWindowData.CollapsedVal, g.NextWindowData.CollapsedCond);
- if (g.NextWindowData.FocusCond)
+ if (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasFocus)
FocusWindow(window);
if (window->Appearing)
SetWindowConditionAllowFlags(window, ImGuiCond_Appearing, false);
@@ -5342,6 +5971,10 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
window->ClipRect = ImVec4(-FLT_MAX,-FLT_MAX,+FLT_MAX,+FLT_MAX);
window->IDStack.resize(1);
+ // Restore buffer capacity when woken from a compacted state, to avoid
+ if (window->MemoryCompacted)
+ GcAwakeTransientWindowBuffers(window);
+
// Update stored window name when it changes (which can _only_ happen with the "###" operator, so the ID would stay unchanged).
// The title bar always display the 'name' parameter, so we only update the string storage if it needs to be visible to the end-user elsewhere.
bool window_title_visible_elsewhere = false;
@@ -5359,28 +5992,28 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
// UPDATE CONTENTS SIZE, UPDATE HIDDEN STATUS
// Update contents size from last frame for auto-fitting (or use explicit size)
- window->SizeContents = CalcSizeContents(window);
- if (window->HiddenFramesRegular > 0)
- window->HiddenFramesRegular--;
- if (window->HiddenFramesForResize > 0)
- window->HiddenFramesForResize--;
+ window->ContentSize = CalcWindowContentSize(window);
+ if (window->HiddenFramesCanSkipItems > 0)
+ window->HiddenFramesCanSkipItems--;
+ if (window->HiddenFramesCannotSkipItems > 0)
+ window->HiddenFramesCannotSkipItems--;
// Hide new windows for one frame until they calculate their size
if (window_just_created && (!window_size_x_set_by_api || !window_size_y_set_by_api))
- window->HiddenFramesForResize = 1;
+ window->HiddenFramesCannotSkipItems = 1;
// Hide popup/tooltip window when re-opening while we measure size (because we recycle the windows)
- // We reset Size/SizeContents for reappearing popups/tooltips early in this function, so further code won't be tempted to use the old size.
+ // We reset Size/ContentSize for reappearing popups/tooltips early in this function, so further code won't be tempted to use the old size.
if (window_just_activated_by_user && (flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_Tooltip)) != 0)
{
- window->HiddenFramesForResize = 1;
+ window->HiddenFramesCannotSkipItems = 1;
if (flags & ImGuiWindowFlags_AlwaysAutoResize)
{
if (!window_size_x_set_by_api)
window->Size.x = window->SizeFull.x = 0.f;
if (!window_size_y_set_by_api)
window->Size.y = window->SizeFull.y = 0.f;
- window->SizeContents = ImVec2(0.f, 0.f);
+ window->ContentSize = ImVec2(0.f, 0.f);
}
}
@@ -5393,7 +6026,9 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
SetCurrentWindow(window);
flags = window->Flags;
- // Lock border size and padding for the frame (so that altering them doesn't cause inconsistencies)
+ // LOCK BORDER SIZE AND PADDING FOR THE FRAME (so that altering them doesn't cause inconsistencies)
+ // We read Style data after the call to UpdateSelectWindowViewport() which might be swapping the style.
+
if (flags & ImGuiWindowFlags_ChildWindow)
window->WindowBorderSize = style.ChildBorderSize;
else
@@ -5429,49 +6064,47 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
// SIZE
// Calculate auto-fit size, handle automatic resize
- const ImVec2 size_auto_fit = CalcSizeAutoFit(window, window->SizeContents);
- ImVec2 size_full_modified(FLT_MAX, FLT_MAX);
+ const ImVec2 size_auto_fit = CalcWindowAutoFitSize(window, window->ContentSize);
+ bool use_current_size_for_scrollbar_x = window_just_created;
+ bool use_current_size_for_scrollbar_y = window_just_created;
if ((flags & ImGuiWindowFlags_AlwaysAutoResize) && !window->Collapsed)
{
// Using SetNextWindowSize() overrides ImGuiWindowFlags_AlwaysAutoResize, so it can be used on tooltips/popups, etc.
if (!window_size_x_set_by_api)
- window->SizeFull.x = size_full_modified.x = size_auto_fit.x;
+ {
+ window->SizeFull.x = size_auto_fit.x;
+ use_current_size_for_scrollbar_x = true;
+ }
if (!window_size_y_set_by_api)
- window->SizeFull.y = size_full_modified.y = size_auto_fit.y;
+ {
+ window->SizeFull.y = size_auto_fit.y;
+ use_current_size_for_scrollbar_y = true;
+ }
}
else if (window->AutoFitFramesX > 0 || window->AutoFitFramesY > 0)
{
// Auto-fit may only grow window during the first few frames
// We still process initial auto-fit on collapsed windows to get a window width, but otherwise don't honor ImGuiWindowFlags_AlwaysAutoResize when collapsed.
if (!window_size_x_set_by_api && window->AutoFitFramesX > 0)
- window->SizeFull.x = size_full_modified.x = window->AutoFitOnlyGrows ? ImMax(window->SizeFull.x, size_auto_fit.x) : size_auto_fit.x;
+ {
+ window->SizeFull.x = window->AutoFitOnlyGrows ? ImMax(window->SizeFull.x, size_auto_fit.x) : size_auto_fit.x;
+ use_current_size_for_scrollbar_x = true;
+ }
if (!window_size_y_set_by_api && window->AutoFitFramesY > 0)
- window->SizeFull.y = size_full_modified.y = window->AutoFitOnlyGrows ? ImMax(window->SizeFull.y, size_auto_fit.y) : size_auto_fit.y;
+ {
+ window->SizeFull.y = window->AutoFitOnlyGrows ? ImMax(window->SizeFull.y, size_auto_fit.y) : size_auto_fit.y;
+ use_current_size_for_scrollbar_y = true;
+ }
if (!window->Collapsed)
MarkIniSettingsDirty(window);
}
- //if (window->DockNode && window->DockIsActive)
- // size_full_modified = window->SizeFull;
-
// Apply minimum/maximum window size constraints and final size
- window->SizeFull = CalcSizeAfterConstraint(window, window->SizeFull);
+ window->SizeFull = CalcWindowSizeAfterConstraint(window, window->SizeFull);
window->Size = window->Collapsed && !(flags & ImGuiWindowFlags_ChildWindow) ? window->TitleBarRect().GetSize() : window->SizeFull;
- // SCROLLBAR STATUS
-
- // Update scrollbar status (based on the Size that was effective during last frame or the auto-resized Size).
- if (!window->Collapsed)
- {
- // When reading the current size we need to read it after size constraints have been applied
- float size_x_for_scrollbars = size_full_modified.x != FLT_MAX ? window->SizeFull.x : window->SizeFullAtLastBegin.x;
- float size_y_for_scrollbars = size_full_modified.y != FLT_MAX ? window->SizeFull.y : window->SizeFullAtLastBegin.y;
- window->ScrollbarY = (flags & ImGuiWindowFlags_AlwaysVerticalScrollbar) || ((window->SizeContents.y > size_y_for_scrollbars) && !(flags & ImGuiWindowFlags_NoScrollbar));
- window->ScrollbarX = (flags & ImGuiWindowFlags_AlwaysHorizontalScrollbar) || ((window->SizeContents.x > size_x_for_scrollbars - (window->ScrollbarY ? style.ScrollbarSize : 0.0f)) && !(flags & ImGuiWindowFlags_NoScrollbar) && (flags & ImGuiWindowFlags_HorizontalScrollbar));
- if (window->ScrollbarX && !window->ScrollbarY)
- window->ScrollbarY = (window->SizeContents.y > size_y_for_scrollbars - style.ScrollbarSize) && !(flags & ImGuiWindowFlags_NoScrollbar);
- window->ScrollbarSizes = ImVec2(window->ScrollbarY ? style.ScrollbarSize : 0.0f, window->ScrollbarX ? style.ScrollbarSize : 0.0f);
- }
+ // Decoration size
+ const float decoration_up_height = window->TitleBarHeight() + window->MenuBarHeight();
// POSITION
@@ -5493,9 +6126,9 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
window->Pos = parent_window->DC.CursorPos;
}
- const bool window_pos_with_pivot = (window->SetWindowPosVal.x != FLT_MAX && window->HiddenFramesForResize == 0);
+ const bool window_pos_with_pivot = (window->SetWindowPosVal.x != FLT_MAX && window->HiddenFramesCannotSkipItems == 0);
if (window_pos_with_pivot)
- SetWindowPos(window, ImMax(style.DisplaySafeAreaPadding, window->SetWindowPosVal - window->SizeFull * window->SetWindowPosPivot), 0); // Position given a pivot (e.g. for centering)
+ SetWindowPos(window, window->SetWindowPosVal - window->SizeFull * window->SetWindowPosPivot, 0); // Position given a pivot (e.g. for centering)
else if ((flags & ImGuiWindowFlags_ChildMenu) != 0)
window->Pos = FindBestWindowPosForPopup(window);
else if ((flags & ImGuiWindowFlags_Popup) != 0 && !window_pos_set_by_api && window_just_appearing_after_hidden_for_resize)
@@ -5504,7 +6137,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
window->Pos = FindBestWindowPosForPopup(window);
// Late create viewport if we don't fit within our current host viewport.
- if (window->ViewportAllowPlatformMonitorExtend >= 0 && !window->ViewportOwned && !window->Viewport->PlatformWindowMinimized)
+ if (window->ViewportAllowPlatformMonitorExtend >= 0 && !window->ViewportOwned && !(window->Viewport->Flags & ImGuiViewportFlags_Minimized))
if (!window->Viewport->GetRect().Contains(window->Rect()))
{
// This is based on the assumption that the DPI will be known ahead (same as the DPI of the selection done in UpdateSelectWindowViewport)
@@ -5518,40 +6151,74 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
SetCurrentWindow(window);
}
+ bool viewport_rect_changed = false;
if (window->ViewportOwned)
{
+ // Synchronize window --> viewport in most situations
// Synchronize viewport -> window in case the platform window has been moved or resized from the OS/WM
if (window->Viewport->PlatformRequestMove)
+ {
window->Pos = window->Viewport->Pos;
+ MarkIniSettingsDirty(window);
+ }
+ else if (memcmp(&window->Viewport->Pos, &window->Pos, sizeof(window->Pos)) != 0)
+ {
+ viewport_rect_changed = true;
+ window->Viewport->Pos = window->Pos;
+ }
+
if (window->Viewport->PlatformRequestResize)
+ {
window->Size = window->SizeFull = window->Viewport->Size;
+ MarkIniSettingsDirty(window);
+ }
+ else if (memcmp(&window->Viewport->Size, &window->Size, sizeof(window->Size)) != 0)
+ {
+ viewport_rect_changed = true;
+ window->Viewport->Size = window->Size;
+ }
+
+ // The viewport may have changed monitor since the global update in UpdateViewportsNewFrame()
+ // Either a SetNextWindowPos() call in the current frame or a SetWindowPos() call in the previous frame may have this effect.
+ if (viewport_rect_changed)
+ UpdateViewportPlatformMonitor(window->Viewport);
// Update common viewport flags
ImGuiViewportFlags viewport_flags = (window->Viewport->Flags) & ~(ImGuiViewportFlags_TopMost | ImGuiViewportFlags_NoTaskBarIcon | ImGuiViewportFlags_NoDecoration);
+ const bool is_short_lived_floating_window = (flags & (ImGuiWindowFlags_ChildMenu | ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_Popup)) != 0;
if (flags & ImGuiWindowFlags_Tooltip)
viewport_flags |= ImGuiViewportFlags_TopMost;
- if (g.IO.ConfigViewportsNoTaskBarIcon || (flags & (ImGuiWindowFlags_ChildMenu | ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_Popup)) != 0)
+ if (g.IO.ConfigViewportsNoTaskBarIcon || is_short_lived_floating_window)
viewport_flags |= ImGuiViewportFlags_NoTaskBarIcon;
- if (g.IO.ConfigViewportsNoDecoration || (flags & (ImGuiWindowFlags_ChildMenu | ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_Popup)) != 0)
+ if (g.IO.ConfigViewportsNoDecoration || is_short_lived_floating_window)
viewport_flags |= ImGuiViewportFlags_NoDecoration;
- if ((viewport_flags & ImGuiViewportFlags_NoDecoration) && (viewport_flags & ImGuiViewportFlags_NoTaskBarIcon))
+
+ // For popups and menus that may be protruding out of their parent viewport, we enable _NoFocusOnClick so that clicking on them
+ // won't steal the OS focus away from their parent window (which may be reflected in OS the title bar decoration).
+ // Setting _NoFocusOnClick would technically prevent us from bringing back to front in case they are being covered by an OS window from a different app,
+ // but it shouldn't be much of a problem considering those are already popups that are closed when clicking elsewhere.
+ if (is_short_lived_floating_window && (flags & ImGuiWindowFlags_Modal) == 0)
viewport_flags |= ImGuiViewportFlags_NoFocusOnAppearing | ImGuiViewportFlags_NoFocusOnClick;
// We can overwrite viewport flags using ImGuiWindowClass (advanced users)
// We don't default to the main viewport because.
if (window->WindowClass.ParentViewportId)
window->Viewport->ParentViewportId = window->WindowClass.ParentViewportId;
+ else if ((flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_Tooltip)) && parent_window_in_stack)
+ window->Viewport->ParentViewportId = parent_window_in_stack->Viewport->ID;
else
- window->Viewport->ParentViewportId = g.IO.ConfigViewportsNoParent ? 0 : IMGUI_VIEWPORT_DEFAULT_ID;
- if (window->WindowClass.ViewportFlagsOverrideMask)
- viewport_flags = (viewport_flags & ~window->WindowClass.ViewportFlagsOverrideMask) | (window->WindowClass.ViewportFlagsOverrideValue & window->WindowClass.ViewportFlagsOverrideMask);
+ window->Viewport->ParentViewportId = g.IO.ConfigViewportsNoDefaultParent ? 0 : IMGUI_VIEWPORT_DEFAULT_ID;
+ if (window->WindowClass.ViewportFlagsOverrideSet)
+ viewport_flags |= window->WindowClass.ViewportFlagsOverrideSet;
+ if (window->WindowClass.ViewportFlagsOverrideClear)
+ viewport_flags &= ~window->WindowClass.ViewportFlagsOverrideClear;
// We also tell the back-end that clearing the platform window won't be necessary, as our window is filling the viewport and we have disabled BgAlpha
viewport_flags |= ImGuiViewportFlags_NoRendererClear;
window->Viewport->Flags = viewport_flags;
}
- // Clamp position so window stays visible within its viewport or monitor
+ // Clamp position/size so window stays visible within its viewport or monitor
// Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing.
ImRect viewport_rect = window->Viewport->GetRect();
if (!window_pos_set_by_api && !(flags & ImGuiWindowFlags_ChildWindow) && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0)
@@ -5580,23 +6247,13 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
if (window->ViewportOwned)
window->WindowRounding = 0.0f;
- // Prepare for item focus requests
- window->FocusIdxAllRequestCurrent = (window->FocusIdxAllRequestNext == INT_MAX || window->FocusIdxAllCounter == -1) ? INT_MAX : (window->FocusIdxAllRequestNext + (window->FocusIdxAllCounter+1)) % (window->FocusIdxAllCounter+1);
- window->FocusIdxTabRequestCurrent = (window->FocusIdxTabRequestNext == INT_MAX || window->FocusIdxTabCounter == -1) ? INT_MAX : (window->FocusIdxTabRequestNext + (window->FocusIdxTabCounter+1)) % (window->FocusIdxTabCounter+1);
- window->FocusIdxAllCounter = window->FocusIdxTabCounter = -1;
- window->FocusIdxAllRequestNext = window->FocusIdxTabRequestNext = INT_MAX;
-
- // Apply scrolling
- window->Scroll = CalcNextScrollFromScrollTargetAndClamp(window, true);
- window->ScrollTarget = ImVec2(FLT_MAX, FLT_MAX);
-
// Apply window focus (new and reactivated windows are moved to front)
bool want_focus = false;
if (window_just_activated_by_user && !(flags & ImGuiWindowFlags_NoFocusOnAppearing))
{
if (flags & ImGuiWindowFlags_Popup)
want_focus = true;
- else if ((window->DockIsActive || !(flags & ImGuiWindowFlags_ChildWindow)) && !(flags & ImGuiWindowFlags_Tooltip))
+ else if ((window->DockIsActive || (flags & ImGuiWindowFlags_ChildWindow) == 0) && !(flags & ImGuiWindowFlags_Tooltip))
want_focus = true;
}
@@ -5607,12 +6264,13 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
int border_held = -1;
ImU32 resize_grip_col[4] = { 0 };
const int resize_grip_count = g.IO.ConfigWindowsResizeFromEdges ? 2 : 1; // 4
- const float grip_draw_size = (float)(int)ImMax(g.FontSize * 1.35f, window->WindowRounding + 1.0f + g.FontSize * 0.2f);
+ const float resize_grip_draw_size = (float)(int)ImMax(g.FontSize * 1.35f, window->WindowRounding + 1.0f + g.FontSize * 0.2f);
if (handle_borders_and_resize_grips && !window->Collapsed)
- UpdateManualResize(window, size_auto_fit, &border_held, resize_grip_count, &resize_grip_col[0]);
+ if (UpdateManualResize(window, size_auto_fit, &border_held, resize_grip_count, &resize_grip_col[0]))
+ use_current_size_for_scrollbar_x = use_current_size_for_scrollbar_y = true;
window->ResizeBorderHeld = (signed char)border_held;
- // Synchronize window --> viewport
+ // Synchronize window --> viewport again and one last time (clamping and manual resize may have affected either)
if (window->ViewportOwned)
{
if (!window->Viewport->PlatformRequestMove)
@@ -5625,25 +6283,95 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
// Save last known viewport position within the window itself (so it can be saved in .ini file and restored)
window->ViewportPos = window->Viewport->Pos;
+ // SCROLLBAR VISIBILITY
+
+ // Update scrollbar visibility (based on the Size that was effective during last frame or the auto-resized Size).
+ if (!window->Collapsed)
+ {
+ // When reading the current size we need to read it after size constraints have been applied.
+ // When we use InnerRect here we are intentionally reading last frame size, same for ScrollbarSizes values before we set them again.
+ ImVec2 avail_size_from_current_frame = ImVec2(window->SizeFull.x, window->SizeFull.y - decoration_up_height);
+ ImVec2 avail_size_from_last_frame = window->InnerRect.GetSize() + window->ScrollbarSizes;
+ ImVec2 needed_size_from_last_frame = window_just_created ? ImVec2(0, 0) : window->ContentSize + window->WindowPadding * 2.0f;
+ float size_x_for_scrollbars = use_current_size_for_scrollbar_x ? avail_size_from_current_frame.x : avail_size_from_last_frame.x;
+ float size_y_for_scrollbars = use_current_size_for_scrollbar_y ? avail_size_from_current_frame.y : avail_size_from_last_frame.y;
+ //bool scrollbar_y_from_last_frame = window->ScrollbarY; // FIXME: May want to use that in the ScrollbarX expression? How many pros vs cons?
+ window->ScrollbarY = (flags & ImGuiWindowFlags_AlwaysVerticalScrollbar) || ((needed_size_from_last_frame.y > size_y_for_scrollbars) && !(flags & ImGuiWindowFlags_NoScrollbar));
+ window->ScrollbarX = (flags & ImGuiWindowFlags_AlwaysHorizontalScrollbar) || ((needed_size_from_last_frame.x > size_x_for_scrollbars - (window->ScrollbarY ? style.ScrollbarSize : 0.0f)) && !(flags & ImGuiWindowFlags_NoScrollbar) && (flags & ImGuiWindowFlags_HorizontalScrollbar));
+ if (window->ScrollbarX && !window->ScrollbarY)
+ window->ScrollbarY = (needed_size_from_last_frame.y > size_y_for_scrollbars) && !(flags & ImGuiWindowFlags_NoScrollbar);
+ window->ScrollbarSizes = ImVec2(window->ScrollbarY ? style.ScrollbarSize : 0.0f, window->ScrollbarX ? style.ScrollbarSize : 0.0f);
+ }
+
+ // UPDATE RECTANGLES (1- THOSE NOT AFFECTED BY SCROLLING)
+ // Update various regions. Variables they depends on should be set above in this function.
+ // We set this up after processing the resize grip so that our rectangles doesn't lag by a frame.
+
+ // Outer rectangle
+ // Not affected by window border size. Used by:
+ // - FindHoveredWindow() (w/ extra padding when border resize is enabled)
+ // - Begin() initial clipping rect for drawing window background and borders.
+ // - Begin() clipping whole child
+ const ImRect host_rect = ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_Popup) && !window_is_child_tooltip) ? parent_window->ClipRect : viewport_rect;
+ const ImRect outer_rect = window->Rect();
+ const ImRect title_bar_rect = window->TitleBarRect();
+ window->OuterRectClipped = outer_rect;
+ if (window->DockIsActive)
+ window->OuterRectClipped.Min.y += window->TitleBarHeight();
+ window->OuterRectClipped.ClipWith(host_rect);
+
+ // Inner rectangle
+ // Not affected by window border size. Used by:
+ // - InnerClipRect
+ // - ScrollToBringRectIntoView()
+ // - NavUpdatePageUpPageDown()
+ // - Scrollbar()
+ window->InnerRect.Min.x = window->Pos.x;
+ window->InnerRect.Min.y = window->Pos.y + decoration_up_height;
+ window->InnerRect.Max.x = window->Pos.x + window->Size.x - window->ScrollbarSizes.x;
+ window->InnerRect.Max.y = window->Pos.y + window->Size.y - window->ScrollbarSizes.y;
+
+ // Inner clipping rectangle.
+ // Will extend a little bit outside the normal work region.
+ // This is to allow e.g. Selectable or CollapsingHeader or some separators to cover that space.
+ // Force round operator last to ensure that e.g. (int)(max.x-min.x) in user's render code produce correct result.
+ // Note that if our window is collapsed we will end up with an inverted (~null) clipping rectangle which is the correct behavior.
+ // Affected by window/frame border size. Used by:
+ // - Begin() initial clip rect
+ float top_border_size = (((flags & ImGuiWindowFlags_MenuBar) || !(flags & ImGuiWindowFlags_NoTitleBar)) ? style.FrameBorderSize : window->WindowBorderSize);
+ window->InnerClipRect.Min.x = ImFloor(0.5f + window->InnerRect.Min.x + ImMax(ImFloor(window->WindowPadding.x * 0.5f), window->WindowBorderSize));
+ window->InnerClipRect.Min.y = ImFloor(0.5f + window->InnerRect.Min.y + top_border_size);
+ window->InnerClipRect.Max.x = ImFloor(0.5f + window->InnerRect.Max.x - ImMax(ImFloor(window->WindowPadding.x * 0.5f), window->WindowBorderSize));
+ window->InnerClipRect.Max.y = ImFloor(0.5f + window->InnerRect.Max.y - window->WindowBorderSize);
+ window->InnerClipRect.ClipWithFull(host_rect);
+
// Default item width. Make it proportional to window size if window manually resizes
if (window->Size.x > 0.0f && !(flags & ImGuiWindowFlags_Tooltip) && !(flags & ImGuiWindowFlags_AlwaysAutoResize))
window->ItemWidthDefault = (float)(int)(window->Size.x * 0.65f);
else
window->ItemWidthDefault = (float)(int)(g.FontSize * 16.0f);
+ // SCROLLING
+
+ // Lock down maximum scrolling
+ // The value of ScrollMax are ahead from ScrollbarX/ScrollbarY which is intentionally using InnerRect from previous rect in order to accommodate
+ // for right/bottom aligned items without creating a scrollbar.
+ window->ScrollMax.x = ImMax(0.0f, window->ContentSize.x + window->WindowPadding.x * 2.0f - window->InnerRect.GetWidth());
+ window->ScrollMax.y = ImMax(0.0f, window->ContentSize.y + window->WindowPadding.y * 2.0f - window->InnerRect.GetHeight());
+
+ // Apply scrolling
+ window->Scroll = CalcNextScrollFromScrollTargetAndClamp(window, true);
+ window->ScrollTarget = ImVec2(FLT_MAX, FLT_MAX);
+
// DRAWING
// Setup draw list and outer clipping rectangle
window->DrawList->Clear();
- window->DrawList->Flags = (g.Style.AntiAliasedLines ? ImDrawListFlags_AntiAliasedLines : 0) | (g.Style.AntiAliasedFill ? ImDrawListFlags_AntiAliasedFill : 0);
window->DrawList->PushTextureID(g.Font->ContainerAtlas->TexID);
- if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_Popup) && !window_is_child_tooltip)
- PushClipRect(parent_window->ClipRect.Min, parent_window->ClipRect.Max, true);
- else
- PushClipRect(viewport_rect.Min, viewport_rect.Max, true);
+ PushClipRect(host_rect.Min, host_rect.Max, false);
// Draw modal or window list full viewport dimming background (for other viewports we'll render them in EndFrame)
- const bool dim_bg_for_modal = (flags & ImGuiWindowFlags_Modal) && window == GetFrontMostPopupModal() && window->HiddenFramesForResize <= 0;
+ const bool dim_bg_for_modal = (flags & ImGuiWindowFlags_Modal) && window == GetTopMostPopupModal() && window->HiddenFramesCannotSkipItems <= 0;
const bool dim_bg_for_window_list = g.NavWindowingTargetAnim && ((window == g.NavWindowingTargetAnim->RootWindow) || (g.NavWindowingList && (window == g.NavWindowingList) && g.NavWindowingList->Viewport != g.NavWindowingTargetAnim->Viewport));
if (dim_bg_for_modal || dim_bg_for_window_list)
{
@@ -5660,153 +6388,99 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
window->DrawList->AddRectFilled(bb.Min, bb.Max, GetColorU32(ImGuiCol_NavWindowingHighlight, g.NavWindowingHighlightAlpha * 0.25f), g.Style.WindowRounding);
}
- // Draw window + handle manual resize
- // As we highlight the title bar when want_focus is set, multiple reappearing windows will have have their title bar highlighted on their reappearing frame.
- const float window_rounding = window->WindowRounding;
- const float window_border_size = window->WindowBorderSize;
- const ImGuiWindow* window_to_highlight = g.NavWindowingTarget ? g.NavWindowingTarget : g.NavWindow;
- const bool title_bar_is_highlight = want_focus || (window_to_highlight && (window->RootWindowForTitleBarHighlight == window_to_highlight->RootWindowForTitleBarHighlight || (window->DockNode && window->DockNode == window_to_highlight->DockNode)));
- const ImRect title_bar_rect = window->TitleBarRect();
- if (window->Collapsed)
- {
- // Title bar only
- float backup_border_size = style.FrameBorderSize;
- g.Style.FrameBorderSize = window->WindowBorderSize;
- ImU32 title_bar_col = GetColorU32((title_bar_is_highlight && !g.NavDisableHighlight) ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBgCollapsed);
- RenderFrame(title_bar_rect.Min, title_bar_rect.Max, title_bar_col, true, window_rounding);
- g.Style.FrameBorderSize = backup_border_size;
- }
- else
- {
- // Window background
- if (!(flags & ImGuiWindowFlags_NoBackground))
- {
- bool is_docking_transparent_payload = false;
- if (g.DragDropActive && (g.FrameCount - g.DragDropAcceptFrameCount) <= 1 && g.IO.ConfigDockingTransparentPayload)
- if (g.DragDropPayload.IsDataType(IMGUI_PAYLOAD_TYPE_WINDOW) && *(ImGuiWindow**)g.DragDropPayload.Data == window)
- is_docking_transparent_payload = true;
-
- ImU32 bg_col = GetColorU32(GetWindowBgColorIdxFromFlags(flags));
- if (window->ViewportOwned)
- {
- // No alpha
- bg_col = (bg_col | IM_COL32_A_MASK);
- if (is_docking_transparent_payload)
- window->Viewport->Alpha *= DOCKING_TRANSPARENT_PAYLOAD_ALPHA;
- }
- else
- {
- // Adjust alpha. For docking
- float alpha = 1.0f;
- if (g.NextWindowData.BgAlphaCond != 0)
- alpha = g.NextWindowData.BgAlphaVal;
- if (is_docking_transparent_payload)
- alpha *= DOCKING_TRANSPARENT_PAYLOAD_ALPHA;
- if (alpha != 1.0f)
- bg_col = (bg_col & ~IM_COL32_A_MASK) | (IM_F32_TO_INT8_SAT(alpha) << IM_COL32_A_SHIFT);
- }
- window->DrawList->AddRectFilled(window->Pos + ImVec2(0, window->TitleBarHeight()), window->Pos + window->Size, bg_col, window_rounding, (flags & ImGuiWindowFlags_NoTitleBar) ? ImDrawCornerFlags_All : ImDrawCornerFlags_Bot);
- }
- g.NextWindowData.BgAlphaCond = 0;
-
- // Title bar
- // (when docked, DockNode are drawing their own title bar. Individual windows however do NOT set the _NoTitleBar flag,
- // in order for their pos/size to be matching their undocking state.)
- if (!(flags & ImGuiWindowFlags_NoTitleBar) && !window->DockIsActive)
- {
- ImU32 title_bar_col = GetColorU32(title_bar_is_highlight ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBg);
- window->DrawList->AddRectFilled(title_bar_rect.Min, title_bar_rect.Max, title_bar_col, window_rounding, ImDrawCornerFlags_Top);
- }
+ const bool is_undocked_or_docked_visible = !window->DockIsActive || window->DockTabIsVisible;
- // Menu bar
- if (flags & ImGuiWindowFlags_MenuBar)
- {
- ImRect menu_bar_rect = window->MenuBarRect();
- menu_bar_rect.ClipWith(window->Rect()); // Soft clipping, in particular child window don't have minimum size covering the menu bar so this is useful for them.
- window->DrawList->AddRectFilled(menu_bar_rect.Min+ImVec2(window_border_size,0), menu_bar_rect.Max-ImVec2(window_border_size,0), GetColorU32(ImGuiCol_MenuBarBg), (flags & ImGuiWindowFlags_NoTitleBar) ? window_rounding : 0.0f, ImDrawCornerFlags_Top);
- if (style.FrameBorderSize > 0.0f && menu_bar_rect.Max.y < window->Pos.y + window->Size.y)
- window->DrawList->AddLine(menu_bar_rect.GetBL(), menu_bar_rect.GetBR(), GetColorU32(ImGuiCol_Border), style.FrameBorderSize);
- }
+ // Since 1.71, child window can render their decoration (bg color, border, scrollbars, etc.) within their parent to save a draw call.
+ // When using overlapping child windows, this will break the assumption that child z-order is mapped to submission order.
+ // We disable this when the parent window has zero vertices, which is a common pattern leading to laying out multiple overlapping child.
+ // We also disabled this when we have dimming overlay behind this specific one child.
+ // FIXME: More code may rely on explicit sorting of overlapping child window and would need to disable this somehow. Please get in contact if you are affected.
+ if (is_undocked_or_docked_visible)
+ {
+ bool render_decorations_in_parent = false;
+ if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_Popup) && !window_is_child_tooltip)
+ if (window->DrawList->CmdBuffer.back().ElemCount == 0 && parent_window->DrawList->VtxBuffer.Size > 0)
+ render_decorations_in_parent = true;
+ if (render_decorations_in_parent)
+ window->DrawList = parent_window->DrawList;
- // Docking: Unhide tab bar
- if (window->DockNode && window->DockNode->IsHiddenTabBar)
- {
- float unhide_sz_draw = ImFloor(g.FontSize * 0.70f);
- float unhide_sz_hit = ImFloor(g.FontSize * 0.55f);
- ImVec2 p = window->DockNode->Pos;
- ImRect r(p, p + ImVec2(unhide_sz_hit, unhide_sz_hit));
- bool hovered, held;
- if (ButtonBehavior(r, window->GetID("#UNHIDE"), &hovered, &held, ImGuiButtonFlags_FlattenChildren))
- window->DockNode->WantHiddenTabBarToggle = true;
- // FIXME-DOCK: Ideally we'd use ImGuiCol_TitleBgActive/ImGuiCol_TitleBg here, but neither is guaranteed to be visible enough at this sort of size..
- ImU32 col = GetColorU32(((held && hovered) || (window->DockNode->IsFocused && !hovered)) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
- window->DrawList->AddTriangleFilled(p, p + ImVec2(unhide_sz_draw, 0.0f), p + ImVec2(0.0f, unhide_sz_draw), col);
- }
+ // Handle title bar, scrollbar, resize grips and resize borders
+ const ImGuiWindow* window_to_highlight = g.NavWindowingTarget ? g.NavWindowingTarget : g.NavWindow;
+ const bool title_bar_is_highlight = want_focus || (window_to_highlight && (window->RootWindowForTitleBarHighlight == window_to_highlight->RootWindowForTitleBarHighlight || (window->DockNode && window->DockNode == window_to_highlight->DockNode)));
+ RenderWindowDecorations(window, title_bar_rect, title_bar_is_highlight, handle_borders_and_resize_grips, resize_grip_count, resize_grip_col, resize_grip_draw_size);
- // Scrollbars
- if (window->ScrollbarX)
- Scrollbar(ImGuiLayoutType_Horizontal);
- if (window->ScrollbarY)
- Scrollbar(ImGuiLayoutType_Vertical);
+ if (render_decorations_in_parent)
+ window->DrawList = &window->DrawListInst;
+ }
- // Render resize grips (after their input handling so we don't have a frame of latency)
- if (handle_borders_and_resize_grips && !(flags & ImGuiWindowFlags_NoResize))
+ // Draw navigation selection/windowing rectangle border
+ if (g.NavWindowingTargetAnim == window)
+ {
+ float rounding = ImMax(window->WindowRounding, g.Style.WindowRounding);
+ ImRect bb = window->Rect();
+ bb.Expand(g.FontSize);
+ if (bb.Contains(viewport_rect)) // If a window fits the entire viewport, adjust its highlight inward
{
- for (int resize_grip_n = 0; resize_grip_n < resize_grip_count; resize_grip_n++)
- {
- const ImGuiResizeGripDef& grip = resize_grip_def[resize_grip_n];
- const ImVec2 corner = ImLerp(window->Pos, window->Pos + window->Size, grip.CornerPosN);
- window->DrawList->PathLineTo(corner + grip.InnerDir * ((resize_grip_n & 1) ? ImVec2(window_border_size, grip_draw_size) : ImVec2(grip_draw_size, window_border_size)));
- window->DrawList->PathLineTo(corner + grip.InnerDir * ((resize_grip_n & 1) ? ImVec2(grip_draw_size, window_border_size) : ImVec2(window_border_size, grip_draw_size)));
- window->DrawList->PathArcToFast(ImVec2(corner.x + grip.InnerDir.x * (window_rounding + window_border_size), corner.y + grip.InnerDir.y * (window_rounding + window_border_size)), window_rounding, grip.AngleMin12, grip.AngleMax12);
- window->DrawList->PathFillConvex(resize_grip_col[resize_grip_n]);
- }
+ bb.Expand(-g.FontSize - 1.0f);
+ rounding = window->WindowRounding;
}
-
- // Borders (for dock node host they will be rendered over after the tab bar)
- if (handle_borders_and_resize_grips && !window->DockNodeAsHost)
- RenderOuterBorders(window);
- }
-
- // Store a backup of SizeFull which we will use next frame to decide if we need scrollbars.
- window->SizeFullAtLastBegin = window->SizeFull;
-
- // Update various regions. Variables they depends on are set above in this function.
- // FIXME: window->ContentsRegionRect.Max is currently very misleading / partly faulty, but some BeginChild() patterns relies on it.
+ window->DrawList->AddRect(bb.Min, bb.Max, GetColorU32(ImGuiCol_NavWindowingHighlight, g.NavWindowingHighlightAlpha), rounding, ~0, 3.0f);
+ }
+
+ // UPDATE RECTANGLES (2- THOSE AFFECTED BY SCROLLING)
+
+ // Work rectangle.
+ // Affected by window padding and border size. Used by:
+ // - Columns() for right-most edge
+ // - TreeNode(), CollapsingHeader() for right-most edge
+ // - BeginTabBar() for right-most edge
+ const bool allow_scrollbar_x = !(flags & ImGuiWindowFlags_NoScrollbar) && (flags & ImGuiWindowFlags_HorizontalScrollbar);
+ const bool allow_scrollbar_y = !(flags & ImGuiWindowFlags_NoScrollbar);
+ const float work_rect_size_x = (window->ContentSizeExplicit.x != 0.0f ? window->ContentSizeExplicit.x : ImMax(allow_scrollbar_x ? window->ContentSize.x : 0.0f, window->Size.x - window->WindowPadding.x * 2.0f - window->ScrollbarSizes.x));
+ const float work_rect_size_y = (window->ContentSizeExplicit.y != 0.0f ? window->ContentSizeExplicit.y : ImMax(allow_scrollbar_y ? window->ContentSize.y : 0.0f, window->Size.y - window->WindowPadding.y * 2.0f - decoration_up_height - window->ScrollbarSizes.y));
+ window->WorkRect.Min.x = ImFloor(window->InnerRect.Min.x - window->Scroll.x + ImMax(window->WindowPadding.x, window->WindowBorderSize));
+ window->WorkRect.Min.y = ImFloor(window->InnerRect.Min.y - window->Scroll.y + ImMax(window->WindowPadding.y, window->WindowBorderSize));
+ window->WorkRect.Max.x = window->WorkRect.Min.x + work_rect_size_x;
+ window->WorkRect.Max.y = window->WorkRect.Min.y + work_rect_size_y;
+
+ // [LEGACY] Contents Region
+ // FIXME-OBSOLETE: window->ContentsRegionRect.Max is currently very misleading / partly faulty, but some BeginChild() patterns relies on it.
+ // Used by:
+ // - Mouse wheel scrolling + many other things
window->ContentsRegionRect.Min.x = window->Pos.x - window->Scroll.x + window->WindowPadding.x;
- window->ContentsRegionRect.Min.y = window->Pos.y - window->Scroll.y + window->WindowPadding.y + window->TitleBarHeight() + window->MenuBarHeight();
- window->ContentsRegionRect.Max.x = window->Pos.x - window->Scroll.x - window->WindowPadding.x + (window->SizeContentsExplicit.x != 0.0f ? window->SizeContentsExplicit.x : (window->Size.x - window->ScrollbarSizes.x));
- window->ContentsRegionRect.Max.y = window->Pos.y - window->Scroll.y - window->WindowPadding.y + (window->SizeContentsExplicit.y != 0.0f ? window->SizeContentsExplicit.y : (window->Size.y - window->ScrollbarSizes.y));
+ window->ContentsRegionRect.Min.y = window->Pos.y - window->Scroll.y + window->WindowPadding.y + decoration_up_height;
+ window->ContentsRegionRect.Max.x = window->ContentsRegionRect.Min.x + (window->ContentSizeExplicit.x != 0.0f ? window->ContentSizeExplicit.x : (window->Size.x - window->WindowPadding.x * 2.0f - window->ScrollbarSizes.x));
+ window->ContentsRegionRect.Max.y = window->ContentsRegionRect.Min.y + (window->ContentSizeExplicit.y != 0.0f ? window->ContentSizeExplicit.y : (window->Size.y - window->WindowPadding.y * 2.0f - decoration_up_height - window->ScrollbarSizes.y));
// Setup drawing context
// (NB: That term "drawing context / DC" lost its meaning a long time ago. Initially was meant to hold transient data only. Nowadays difference between window-> and window->DC-> is dubious.)
window->DC.Indent.x = 0.0f + window->WindowPadding.x - window->Scroll.x;
window->DC.GroupOffset.x = 0.0f;
window->DC.ColumnsOffset.x = 0.0f;
- window->DC.CursorStartPos = window->Pos + ImVec2(window->DC.Indent.x + window->DC.ColumnsOffset.x, window->TitleBarHeight() + window->MenuBarHeight() + window->WindowPadding.y - window->Scroll.y);
+ window->DC.CursorStartPos = window->Pos + ImVec2(window->DC.Indent.x + window->DC.ColumnsOffset.x, decoration_up_height + window->WindowPadding.y - window->Scroll.y);
window->DC.CursorPos = window->DC.CursorStartPos;
window->DC.CursorPosPrevLine = window->DC.CursorPos;
window->DC.CursorMaxPos = window->DC.CursorStartPos;
- window->DC.CurrentLineSize = window->DC.PrevLineSize = ImVec2(0.0f, 0.0f);
- window->DC.CurrentLineTextBaseOffset = window->DC.PrevLineTextBaseOffset = 0.0f;
+ window->DC.CurrLineSize = window->DC.PrevLineSize = ImVec2(0.0f, 0.0f);
+ window->DC.CurrLineTextBaseOffset = window->DC.PrevLineTextBaseOffset = 0.0f;
window->DC.NavHideHighlightOneFrame = false;
- window->DC.NavHasScroll = (GetWindowScrollMaxY(window) > 0.0f);
+ window->DC.NavHasScroll = (window->ScrollMax.y > 0.0f);
window->DC.NavLayerActiveMask = window->DC.NavLayerActiveMaskNext;
window->DC.NavLayerActiveMaskNext = 0x00;
window->DC.MenuBarAppending = false;
- window->DC.LogLinePosY = window->DC.CursorPos.y - 9999.0f;
window->DC.ChildWindows.resize(0);
window->DC.LayoutType = ImGuiLayoutType_Vertical;
window->DC.ParentLayoutType = parent_window ? parent_window->DC.LayoutType : ImGuiLayoutType_Vertical;
+ window->DC.FocusCounterAll = window->DC.FocusCounterTab = -1;
window->DC.ItemFlags = parent_window ? parent_window->DC.ItemFlags : ImGuiItemFlags_Default_;
window->DC.ItemWidth = window->ItemWidthDefault;
window->DC.TextWrapPos = -1.0f; // disabled
window->DC.ItemFlagsStack.resize(0);
window->DC.ItemWidthStack.resize(0);
window->DC.TextWrapPosStack.resize(0);
- window->DC.ColumnsSet = NULL;
+ window->DC.CurrentColumns = NULL;
window->DC.TreeDepth = 0;
- window->DC.TreeDepthMayJumpToParentOnPop = 0x00;
+ window->DC.TreeStoreMayJumpToParentOnPop = 0x00;
window->DC.StateStorage = &window->StateStorage;
window->DC.GroupStack.resize(0);
window->MenuColumns.Update(3, style.ItemSpacing.x, window_just_activated_by_user);
@@ -5836,69 +6510,18 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
{
window->Viewport->PlatformRequestClose = false;
g.NavWindowingToggleLayer = false; // Assume user mapped PlatformRequestClose on ALT-F4 so we disable ALT for menu toggle. False positive not an issue.
- //IMGUI_DEBUG_LOG("Window '%s' PlatformRequestClose\n", window->Name);
+ IMGUI_DEBUG_LOG_VIEWPORT("Window '%s' PlatformRequestClose\n", window->Name);
*p_open = false;
}
}
// Title bar
if (!(flags & ImGuiWindowFlags_NoTitleBar) && !window->DockIsActive)
- {
- // Close & collapse button are on layer 1 (same as menus) and don't default focus
- const ImGuiItemFlags item_flags_backup = window->DC.ItemFlags;
- window->DC.ItemFlags |= ImGuiItemFlags_NoNavDefaultFocus;
- window->DC.NavLayerCurrent = ImGuiNavLayer_Menu;
- window->DC.NavLayerCurrentMask = (1 << ImGuiNavLayer_Menu);
-
- // Collapse button
- if (!(flags & ImGuiWindowFlags_NoCollapse))
- if (CollapseButton(window->GetID("#COLLAPSE"), window->Pos, NULL))
- window->WantCollapseToggle = true; // Defer collapsing to next frame as we are too far in the Begin() function
-
- // Close button
- if (p_open != NULL)
- {
- const float rad = g.FontSize * 0.5f;
- if (CloseButton(window->GetID("#CLOSE"), ImVec2(window->Pos.x + window->Size.x - style.FramePadding.x - rad, window->Pos.y + style.FramePadding.y + rad), rad + 1))
- *p_open = false;
- }
-
- window->DC.NavLayerCurrent = ImGuiNavLayer_Main;
- window->DC.NavLayerCurrentMask = (1 << ImGuiNavLayer_Main);
- window->DC.ItemFlags = item_flags_backup;
-
- // Title bar text (with: horizontal alignment, avoiding collapse/close button, optional "unsaved document" marker)
- // FIXME: Refactor text alignment facilities along with RenderText helpers, this is too much code..
- const char* UNSAVED_DOCUMENT_MARKER = "*";
- float marker_size_x = (flags & ImGuiWindowFlags_UnsavedDocument) ? CalcTextSize(UNSAVED_DOCUMENT_MARKER, NULL, false).x : 0.0f;
- ImVec2 text_size = CalcTextSize(name, NULL, true) + ImVec2(marker_size_x, 0.0f);
- ImRect text_r = title_bar_rect;
- float pad_left = (flags & ImGuiWindowFlags_NoCollapse) ? style.FramePadding.x : (style.FramePadding.x + g.FontSize + style.ItemInnerSpacing.x);
- float pad_right = (p_open == NULL) ? style.FramePadding.x : (style.FramePadding.x + g.FontSize + style.ItemInnerSpacing.x);
- if (style.WindowTitleAlign.x > 0.0f)
- pad_right = ImLerp(pad_right, pad_left, style.WindowTitleAlign.x);
- text_r.Min.x += pad_left;
- text_r.Max.x -= pad_right;
- ImRect clip_rect = text_r;
- clip_rect.Max.x = window->Pos.x + window->Size.x - (p_open ? title_bar_rect.GetHeight() - 3 : style.FramePadding.x); // Match the size of CloseButton()
- RenderTextClipped(text_r.Min, text_r.Max, name, NULL, &text_size, style.WindowTitleAlign, &clip_rect);
- if (flags & ImGuiWindowFlags_UnsavedDocument)
- {
- ImVec2 marker_pos = ImVec2(ImMax(text_r.Min.x, text_r.Min.x + (text_r.GetWidth() - text_size.x) * style.WindowTitleAlign.x) + text_size.x, text_r.Min.y) + ImVec2(2 - marker_size_x, 0.0f);
- ImVec2 off = ImVec2(0.0f, (float)(int)(-g.FontSize * 0.25f));
- RenderTextClipped(marker_pos + off, text_r.Max + off, UNSAVED_DOCUMENT_MARKER, NULL, NULL, ImVec2(0, style.WindowTitleAlign.y), &clip_rect);
- }
- }
+ RenderWindowTitleBarContents(window, title_bar_rect, name, p_open);
// Clear hit test shape every frame
window->HitTestHoleSize.x = window->HitTestHoleSize.y = 0;
- // Save clipped aabb so we can access it in constant-time in FindHoveredWindow()
- window->OuterRectClipped = window->Rect();
- if (window->DockIsActive)
- window->OuterRectClipped.Min.y += window->TitleBarHeight();
- window->OuterRectClipped.ClipWith(window->ClipRect);
-
// Pressing CTRL+C while holding on a window copy its content to the clipboard
// This works but 1. doesn't handle multiple Begin/End pairs, 2. recursing into another Begin/End pair - so we need to work that out and add better logging scope.
// Maybe we can support CTRL+C on every element?
@@ -5908,29 +6531,14 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
LogToClipboard();
*/
- // Inner rectangle
- // We set this up after processing the resize grip so that our clip rectangle doesn't lag by a frame
- // Note that if our window is collapsed we will end up with an inverted (~null) clipping rectangle which is the correct behavior.
- window->InnerMainRect.Min.x = title_bar_rect.Min.x + window->WindowBorderSize;
- window->InnerMainRect.Min.y = title_bar_rect.Max.y + window->MenuBarHeight() + (((flags & ImGuiWindowFlags_MenuBar) || !(flags & ImGuiWindowFlags_NoTitleBar)) ? style.FrameBorderSize : window->WindowBorderSize);
- window->InnerMainRect.Max.x = window->Pos.x + window->Size.x - window->ScrollbarSizes.x - window->WindowBorderSize;
- window->InnerMainRect.Max.y = window->Pos.y + window->Size.y - window->ScrollbarSizes.y - window->WindowBorderSize;
- //window->DrawList->AddRect(window->InnerRect.Min, window->InnerRect.Max, IM_COL32_WHITE);
-
- // Inner clipping rectangle
- // Force round operator last to ensure that e.g. (int)(max.x-min.x) in user's render code produce correct result.
- window->InnerClipRect.Min.x = ImFloor(0.5f + window->InnerMainRect.Min.x + ImMax(0.0f, ImFloor(window->WindowPadding.x*0.5f - window->WindowBorderSize)));
- window->InnerClipRect.Min.y = ImFloor(0.5f + window->InnerMainRect.Min.y);
- window->InnerClipRect.Max.x = ImFloor(0.5f + window->InnerMainRect.Max.x - ImMax(0.0f, ImFloor(window->WindowPadding.x*0.5f - window->WindowBorderSize)));
- window->InnerClipRect.Max.y = ImFloor(0.5f + window->InnerMainRect.Max.y);
-
if (g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable)
{
// Docking: Dragging a dockable window (or any of its child) turns it into a drag and drop source.
// We need to do this _before_ we overwrite window->DC.LastItemId below because BeginAsDockableDragDropSource() also overwrites it.
- if ((g.ActiveId == window->MoveId) && ((g.IO.ConfigDockingWithShift && g.IO.KeyShift) || (!g.IO.ConfigDockingWithShift)))
- if ((window->RootWindow->Flags & (ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDocking)) == 0)
- BeginAsDockableDragDropSource(window);
+ if ((g.ActiveId == window->MoveId) && (g.IO.ConfigDockingWithShift == g.IO.KeyShift))
+ if ((window->Flags & ImGuiWindowFlags_NoMove) == 0)
+ if ((window->RootWindow->Flags & (ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDocking)) == 0)
+ BeginAsDockableDragDropSource(window);
// Docking: Any dockable window can act as a target. For dock node hosts we call BeginAsDockableDragDropTarget() in DockNodeUpdate() instead.
if (g.DragDropActive && !(flags & ImGuiWindowFlags_NoDocking))
@@ -5939,7 +6547,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
BeginAsDockableDragDropTarget(window);
}
- // We fill last item data based on Title Bar or Tab, in order for IsItemHovered() and IsItemActive() to be usable after Begin().
+ // We fill last item data based on Title Bar/Tab, in order for IsItemHovered() and IsItemActive() to be usable after Begin().
// This is useful to allow creating context menus on title bar only, etc.
if (window->DockIsActive)
{
@@ -5953,6 +6561,11 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
window->DC.LastItemStatusFlags = IsMouseHoveringRect(title_bar_rect.Min, title_bar_rect.Max, false) ? ImGuiItemStatusFlags_HoveredRect : 0;
window->DC.LastItemRect = title_bar_rect;
}
+
+#ifdef IMGUI_ENABLE_TEST_ENGINE
+ if (!(window->Flags & ImGuiWindowFlags_NoTitleBar))
+ IMGUI_TEST_ENGINE_ITEM_ADD(window->DC.LastItemRect, window->DC.LastItemId);
+#endif
}
else
{
@@ -5969,10 +6582,19 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
window->WriteAccessed = false;
window->BeginCount++;
- g.NextWindowData.Clear();
+ g.NextWindowData.ClearFlags();
+ // When we are about to select this tab (which will only be visible on the _next frame_), flag it with a non-zero HiddenFramesCannotSkipItems.
+ // This will have the important effect of actually returning true in Begin() and not setting SkipItems, allowing an earlier submission of the window contents.
+ // This is analogous to regular windows being hidden from one frame.
+ // It is especially important as e.g. nested TabBars would otherwise generate flicker in the form of one empty frame, or focus requests won't be processed.
if (window->DockIsActive && !window->DockTabIsVisible)
- window->HiddenFramesRegular = 1;
+ {
+ if (window->LastFrameJustFocused == g.FrameCount)
+ window->HiddenFramesCannotSkipItems = 1;
+ else
+ window->HiddenFramesCanSkipItems = 1;
+ }
if (flags & ImGuiWindowFlags_ChildWindow)
{
@@ -5981,24 +6603,30 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
IM_ASSERT((flags & ImGuiWindowFlags_NoTitleBar) != 0 || (window->DockIsActive));
if (!(flags & ImGuiWindowFlags_AlwaysAutoResize) && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0)
if (window->OuterRectClipped.Min.x >= window->OuterRectClipped.Max.x || window->OuterRectClipped.Min.y >= window->OuterRectClipped.Max.y)
- window->HiddenFramesRegular = 1;
+ window->HiddenFramesCanSkipItems = 1;
- // Completely hide along with parent or if parent is collapsed
- if (parent_window && (parent_window->Collapsed || parent_window->Hidden))
- window->HiddenFramesRegular = 1;
+ // Hide along with parent or if parent is collapsed
+ if (parent_window && (parent_window->Collapsed || parent_window->HiddenFramesCanSkipItems > 0))
+ window->HiddenFramesCanSkipItems = 1;
+ if (parent_window && (parent_window->Collapsed || parent_window->HiddenFramesCannotSkipItems > 0))
+ window->HiddenFramesCannotSkipItems = 1;
}
// Don't render if style alpha is 0.0 at the time of Begin(). This is arbitrary and inconsistent but has been there for a long while (may remove at some point)
if (style.Alpha <= 0.0f)
- window->HiddenFramesRegular = 1;
+ window->HiddenFramesCanSkipItems = 1;
// Update the Hidden flag
- window->Hidden = (window->HiddenFramesRegular > 0) || (window->HiddenFramesForResize > 0);
+ window->Hidden = (window->HiddenFramesCanSkipItems > 0) || (window->HiddenFramesCannotSkipItems > 0);
- // Return false if we don't intend to display anything to allow user to perform an early out optimization
- window->SkipItems = (window->Collapsed || !window->Active || window->Hidden) && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0 && window->HiddenFramesForResize <= 0;
+ // Update the SkipItems flag, used to early out of all items functions (no layout required)
+ bool skip_items = false;
+ if (window->Collapsed || !window->Active || window->Hidden)
+ if (window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0 && window->HiddenFramesCannotSkipItems <= 0)
+ skip_items = true;
+ window->SkipItems = skip_items;
- return !window->SkipItems;
+ return !skip_items;
}
// Old Begin() API with 5 parameters, avoid calling this version directly! Use SetNextWindowSize()/SetNextWindowBgAlpha() + Begin() instead.
@@ -6021,7 +6649,7 @@ void ImGui::End()
{
ImGuiContext& g = *GImGui;
- if (g.CurrentWindowStack.Size <= 1 && g.FrameScopePushedImplicitWindow)
+ if (g.CurrentWindowStack.Size <= 1 && g.FrameScopePushedFallbackWindow)
{
IM_ASSERT(g.CurrentWindowStack.Size > 1 && "Calling End() too many times!");
return; // FIXME-ERRORHANDLING
@@ -6030,7 +6658,7 @@ void ImGui::End()
ImGuiWindow* window = g.CurrentWindow;
- if (window->DC.ColumnsSet != NULL)
+ if (window->DC.CurrentColumns)
EndColumns();
if (!(window->Flags & ImGuiWindowFlags_DockNodeHost)) // Pop inner window clip rectangle
PopClipRect();
@@ -6059,7 +6687,7 @@ void ImGui::BringWindowToFocusFront(ImGuiWindow* window)
ImGuiContext& g = *GImGui;
if (g.WindowsFocusOrder.back() == window)
return;
- for (int i = g.WindowsFocusOrder.Size - 2; i >= 0; i--) // We can ignore the front most window
+ for (int i = g.WindowsFocusOrder.Size - 2; i >= 0; i--) // We can ignore the top-most window
if (g.WindowsFocusOrder[i] == window)
{
memmove(&g.WindowsFocusOrder[i], &g.WindowsFocusOrder[i + 1], (size_t)(g.WindowsFocusOrder.Size - i - 1) * sizeof(ImGuiWindow*));
@@ -6074,7 +6702,7 @@ void ImGui::BringWindowToDisplayFront(ImGuiWindow* window)
ImGuiWindow* current_front_window = g.Windows.back();
if (current_front_window == window || current_front_window->RootWindow == window)
return;
- for (int i = g.Windows.Size - 2; i >= 0; i--) // We can ignore the front most window
+ for (int i = g.Windows.Size - 2; i >= 0; i--) // We can ignore the top-most window
if (g.Windows[i] == window)
{
memmove(&g.Windows[i], &g.Windows[i + 1], (size_t)(g.Windows.Size - i - 1) * sizeof(ImGuiWindow*));
@@ -6114,9 +6742,13 @@ void ImGui::FocusWindow(ImGuiWindow* window)
//IMGUI_DEBUG_LOG("FocusWindow(\"%s\")\n", window ? window->Name : NULL);
}
+ // Close popups if any
+ ClosePopupsOverWindow(window, false);
+
// Passing NULL allow to disable keyboard focus
if (!window)
return;
+ window->LastFrameJustFocused = g.FrameCount;
// Select in dock node
if (window->DockNode && window->DockNode->TabBar)
@@ -6137,42 +6769,64 @@ void ImGui::FocusWindow(ImGuiWindow* window)
BringWindowToDisplayFront(window);
}
-void ImGui::FocusPreviousWindowIgnoringOne(ImGuiWindow* ignore_window)
+void ImGui::FocusTopMostWindowUnderOne(ImGuiWindow* under_this_window, ImGuiWindow* ignore_window)
{
ImGuiContext& g = *GImGui;
- for (int i = g.WindowsFocusOrder.Size - 1; i >= 0; i--)
+
+ int start_idx = g.WindowsFocusOrder.Size - 1;
+ if (under_this_window != NULL)
+ {
+ int under_this_window_idx = FindWindowFocusIndex(under_this_window);
+ if (under_this_window_idx != -1)
+ start_idx = under_this_window_idx - 1;
+ }
+ for (int i = start_idx; i >= 0; i--)
{
// We may later decide to test for different NoXXXInputs based on the active navigation input (mouse vs nav) but that may feel more confusing to the user.
ImGuiWindow* window = g.WindowsFocusOrder[i];
if (window != ignore_window && window->WasActive && !(window->Flags & ImGuiWindowFlags_ChildWindow))
if ((window->Flags & (ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs)) != (ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs))
{
+ // FIXME-DOCKING: This is failing (lagging by one frame) for docked windows.
+ // If A and B are docked into window and B disappear, at the NewFrame() call site window->NavLastChildNavWindow will still point to B.
+ // We might leverage the tab order implicitly stored in window->DockNodeAsHost->TabBar (essentially the 'most_recently_selected_tab' code in tab bar will do that but on next update)
+ // to tell which is the "previous" window. Or we may leverage 'LastFrameFocused/LastFrameJustFocused' and have this function handle child window itself?
ImGuiWindow* focus_window = NavRestoreLastChildNavWindow(window);
FocusWindow(focus_window);
return;
}
}
+ FocusWindow(NULL);
+}
+
+void ImGui::SetNextItemWidth(float item_width)
+{
+ ImGuiContext& g = *GImGui;
+ g.NextItemData.Flags |= ImGuiNextItemDataFlags_HasWidth;
+ g.NextItemData.Width = item_width;
}
void ImGui::PushItemWidth(float item_width)
{
- ImGuiWindow* window = GetCurrentWindow();
+ ImGuiContext& g = *GImGui;
+ ImGuiWindow* window = g.CurrentWindow;
window->DC.ItemWidth = (item_width == 0.0f ? window->ItemWidthDefault : item_width);
window->DC.ItemWidthStack.push_back(window->DC.ItemWidth);
+ g.NextItemData.Flags &= ~ImGuiNextItemDataFlags_HasWidth;
}
void ImGui::PushMultiItemsWidths(int components, float w_full)
{
- ImGuiWindow* window = GetCurrentWindow();
- const ImGuiStyle& style = GImGui->Style;
- if (w_full <= 0.0f)
- w_full = CalcItemWidth();
+ ImGuiContext& g = *GImGui;
+ ImGuiWindow* window = g.CurrentWindow;
+ const ImGuiStyle& style = g.Style;
const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.ItemInnerSpacing.x) * (components-1)) / (float)components));
const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one + style.ItemInnerSpacing.x) * (components-1)));
window->DC.ItemWidthStack.push_back(w_item_last);
for (int i = 0; i < components-1; i++)
window->DC.ItemWidthStack.push_back(w_item_one);
window->DC.ItemWidth = window->DC.ItemWidthStack.back();
+ g.NextItemData.Flags &= ~ImGuiNextItemDataFlags_HasWidth;
}
void ImGui::PopItemWidth()
@@ -6182,27 +6836,58 @@ void ImGui::PopItemWidth()
window->DC.ItemWidth = window->DC.ItemWidthStack.empty() ? window->ItemWidthDefault : window->DC.ItemWidthStack.back();
}
+// Calculate default item width given value passed to PushItemWidth() or SetNextItemWidth().
+// The SetNextItemWidth() data is generally cleared/consumed by ItemAdd() or NextItemData.ClearFlags()
float ImGui::CalcItemWidth()
{
- ImGuiWindow* window = GetCurrentWindowRead();
- float w = window->DC.ItemWidth;
+ ImGuiContext& g = *GImGui;
+ ImGuiWindow* window = g.CurrentWindow;
+ float w;
+ if (g.NextItemData.Flags & ImGuiNextItemDataFlags_HasWidth)
+ w = g.NextItemData.Width;
+ else
+ w = window->DC.ItemWidth;
if (w < 0.0f)
{
- // Align to a right-side limit. We include 1 frame padding in the calculation because this is how the width is always used (we add 2 frame padding to it), but we could move that responsibility to the widget as well.
- float width_to_right_edge = GetContentRegionAvail().x;
- w = ImMax(1.0f, width_to_right_edge + w);
+ float region_max_x = GetContentRegionMaxAbs().x;
+ w = ImMax(1.0f, region_max_x - window->DC.CursorPos.x + w);
}
w = (float)(int)w;
return w;
}
+// [Internal] Calculate full item size given user provided 'size' parameter and default width/height. Default width is often == CalcItemWidth().
+// Those two functions CalcItemWidth vs CalcItemSize are awkwardly named because they are not fully symmetrical.
+// Note that only CalcItemWidth() is publicly exposed.
+// The 4.0f here may be changed to match CalcItemWidth() and/or BeginChild() (right now we have a mismatch which is harmless but undesirable)
+ImVec2 ImGui::CalcItemSize(ImVec2 size, float default_w, float default_h)
+{
+ ImGuiWindow* window = GImGui->CurrentWindow;
+
+ ImVec2 region_max;
+ if (size.x < 0.0f || size.y < 0.0f)
+ region_max = GetContentRegionMaxAbs();
+
+ if (size.x == 0.0f)
+ size.x = default_w;
+ else if (size.x < 0.0f)
+ size.x = ImMax(4.0f, region_max.x - window->DC.CursorPos.x + size.x);
+
+ if (size.y == 0.0f)
+ size.y = default_h;
+ else if (size.y < 0.0f)
+ size.y = ImMax(4.0f, region_max.y - window->DC.CursorPos.y + size.y);
+
+ return size;
+}
+
void ImGui::SetCurrentFont(ImFont* font)
{
ImGuiContext& g = *GImGui;
IM_ASSERT(font && font->IsLoaded()); // Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ?
IM_ASSERT(font->Scale > 0.0f);
g.Font = font;
- g.FontBaseSize = g.IO.FontGlobalScale * g.Font->FontSize * g.Font->Scale;
+ g.FontBaseSize = ImMax(1.0f, g.IO.FontGlobalScale * g.Font->FontSize * g.Font->Scale);
g.FontSize = g.CurrentWindow ? g.CurrentWindow->CalcFontSize() : 0.0f;
ImFontAtlas* atlas = g.Font->ContainerAtlas;
@@ -6324,28 +7009,29 @@ struct ImGuiStyleVarInfo
static const ImGuiStyleVarInfo GStyleVarInfo[] =
{
- { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, Alpha) }, // ImGuiStyleVar_Alpha
- { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowPadding) }, // ImGuiStyleVar_WindowPadding
- { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowRounding) }, // ImGuiStyleVar_WindowRounding
- { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowBorderSize) }, // ImGuiStyleVar_WindowBorderSize
- { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowMinSize) }, // ImGuiStyleVar_WindowMinSize
- { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowTitleAlign) }, // ImGuiStyleVar_WindowTitleAlign
- { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, ChildRounding) }, // ImGuiStyleVar_ChildRounding
- { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, ChildBorderSize) }, // ImGuiStyleVar_ChildBorderSize
- { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, PopupRounding) }, // ImGuiStyleVar_PopupRounding
- { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, PopupBorderSize) }, // ImGuiStyleVar_PopupBorderSize
- { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, FramePadding) }, // ImGuiStyleVar_FramePadding
- { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, FrameRounding) }, // ImGuiStyleVar_FrameRounding
- { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, FrameBorderSize) }, // ImGuiStyleVar_FrameBorderSize
- { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, ItemSpacing) }, // ImGuiStyleVar_ItemSpacing
- { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, ItemInnerSpacing) }, // ImGuiStyleVar_ItemInnerSpacing
- { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, IndentSpacing) }, // ImGuiStyleVar_IndentSpacing
- { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, ScrollbarSize) }, // ImGuiStyleVar_ScrollbarSize
- { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, ScrollbarRounding) }, // ImGuiStyleVar_ScrollbarRounding
- { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, GrabMinSize) }, // ImGuiStyleVar_GrabMinSize
- { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, GrabRounding) }, // ImGuiStyleVar_GrabRounding
- { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, TabRounding) }, // ImGuiStyleVar_TabRounding
- { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, ButtonTextAlign) }, // ImGuiStyleVar_ButtonTextAlign
+ { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, Alpha) }, // ImGuiStyleVar_Alpha
+ { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowPadding) }, // ImGuiStyleVar_WindowPadding
+ { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowRounding) }, // ImGuiStyleVar_WindowRounding
+ { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowBorderSize) }, // ImGuiStyleVar_WindowBorderSize
+ { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowMinSize) }, // ImGuiStyleVar_WindowMinSize
+ { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, WindowTitleAlign) }, // ImGuiStyleVar_WindowTitleAlign
+ { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, ChildRounding) }, // ImGuiStyleVar_ChildRounding
+ { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, ChildBorderSize) }, // ImGuiStyleVar_ChildBorderSize
+ { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, PopupRounding) }, // ImGuiStyleVar_PopupRounding
+ { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, PopupBorderSize) }, // ImGuiStyleVar_PopupBorderSize
+ { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, FramePadding) }, // ImGuiStyleVar_FramePadding
+ { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, FrameRounding) }, // ImGuiStyleVar_FrameRounding
+ { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, FrameBorderSize) }, // ImGuiStyleVar_FrameBorderSize
+ { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, ItemSpacing) }, // ImGuiStyleVar_ItemSpacing
+ { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, ItemInnerSpacing) }, // ImGuiStyleVar_ItemInnerSpacing
+ { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, IndentSpacing) }, // ImGuiStyleVar_IndentSpacing
+ { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, ScrollbarSize) }, // ImGuiStyleVar_ScrollbarSize
+ { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, ScrollbarRounding) }, // ImGuiStyleVar_ScrollbarRounding
+ { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, GrabMinSize) }, // ImGuiStyleVar_GrabMinSize
+ { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, GrabRounding) }, // ImGuiStyleVar_GrabRounding
+ { ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImGuiStyle, TabRounding) }, // ImGuiStyleVar_TabRounding
+ { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, ButtonTextAlign) }, // ImGuiStyleVar_ButtonTextAlign
+ { ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImGuiStyle, SelectableTextAlign) }, // ImGuiStyleVar_SelectableTextAlign
};
static const ImGuiStyleVarInfo* GetStyleVarInfo(ImGuiStyleVar idx)
@@ -6366,7 +7052,7 @@ void ImGui::PushStyleVar(ImGuiStyleVar idx, float val)
*pvar = val;
return;
}
- IM_ASSERT(0); // Called function with wrong-type? Variable is not a float.
+ IM_ASSERT(0 && "Called PushStyleVar() float variant but variable is not a float!");
}
void ImGui::PushStyleVar(ImGuiStyleVar idx, const ImVec2& val)
@@ -6380,7 +7066,7 @@ void ImGui::PushStyleVar(ImGuiStyleVar idx, const ImVec2& val)
*pvar = val;
return;
}
- IM_ASSERT(0); // Called function with wrong-type? Variable is not a ImVec2.
+ IM_ASSERT(0 && "Called PushStyleVar() ImVec2 variant but variable is not a ImVec2!");
}
void ImGui::PopStyleVar(int count)
@@ -6505,7 +7191,7 @@ bool ImGui::IsWindowHovered(ImGuiHoveredFlags flags)
}
}
- if (!IsWindowContentHoverable(g.HoveredRootWindow, flags))
+ if (!IsWindowContentHoverable(g.HoveredWindow, flags))
return false;
if (!(flags & ImGuiHoveredFlags_AllowWhenBlockedByActiveItem))
if (g.ActiveId != 0 && !g.ActiveIdAllowOverlap && g.ActiveId != g.HoveredWindow->MoveId)
@@ -6573,21 +7259,7 @@ ImVec2 ImGui::GetWindowPos()
return window->Pos;
}
-void ImGui::SetWindowScrollX(ImGuiWindow* window, float new_scroll_x)
-{
- window->DC.CursorMaxPos.x += window->Scroll.x; // SizeContents is generally computed based on CursorMaxPos which is affected by scroll position, so we need to apply our change to it.
- window->Scroll.x = new_scroll_x;
- window->DC.CursorMaxPos.x -= window->Scroll.x;
-}
-
-void ImGui::SetWindowScrollY(ImGuiWindow* window, float new_scroll_y)
-{
- window->DC.CursorMaxPos.y += window->Scroll.y; // SizeContents is generally computed based on CursorMaxPos which is affected by scroll position, so we need to apply our change to it.
- window->Scroll.y = new_scroll_y;
- window->DC.CursorMaxPos.y -= window->Scroll.y;
-}
-
-static void SetWindowPos(ImGuiWindow* window, const ImVec2& pos, ImGuiCond cond)
+void ImGui::SetWindowPos(ImGuiWindow* window, const ImVec2& pos, ImGuiCond cond)
{
// Test condition (NB: bit 0 is always true) and clear flags for next time
if (cond && (window->SetWindowPosAllowFlags & cond) == 0)
@@ -6600,8 +7272,10 @@ static void SetWindowPos(ImGuiWindow* window, const ImVec2& pos, ImGuiCond cond)
// Set
const ImVec2 old_pos = window->Pos;
window->Pos = ImFloor(pos);
- window->DC.CursorPos += (window->Pos - old_pos); // As we happen to move the window while it is being appended to (which is a bad idea - will smear) let's at least offset the cursor
- window->DC.CursorMaxPos += (window->Pos - old_pos); // And more importantly we need to adjust this so size calculation doesn't get affected.
+ ImVec2 offset = window->Pos - old_pos;
+ window->DC.CursorPos += offset; // As we happen to move the window while it is being appended to (which is a bad idea - will smear) let's at least offset the cursor
+ window->DC.CursorMaxPos += offset; // And more importantly we need to offset CursorMaxPos/CursorStartPos this so ContentSize calculation doesn't get affected.
+ window->DC.CursorStartPos += offset;
}
void ImGui::SetWindowPos(const ImVec2& pos, ImGuiCond cond)
@@ -6622,7 +7296,7 @@ ImVec2 ImGui::GetWindowSize()
return window->Size;
}
-static void SetWindowSize(ImGuiWindow* window, const ImVec2& size, ImGuiCond cond)
+void ImGui::SetWindowSize(ImGuiWindow* window, const ImVec2& size, ImGuiCond cond)
{
// Test condition (NB: bit 0 is always true) and clear flags for next time
if (cond && (window->SetWindowSizeAllowFlags & cond) == 0)
@@ -6665,7 +7339,7 @@ void ImGui::SetWindowSize(const char* name, const ImVec2& size, ImGuiCond cond)
SetWindowSize(window, size, cond);
}
-static void SetWindowCollapsed(ImGuiWindow* window, bool collapsed, ImGuiCond cond)
+void ImGui::SetWindowCollapsed(ImGuiWindow* window, bool collapsed, ImGuiCond cond)
{
// Test condition (NB: bit 0 is always true) and clear flags for next time
if (cond && (window->SetWindowCollapsedAllowFlags & cond) == 0)
@@ -6679,8 +7353,8 @@ static void SetWindowCollapsed(ImGuiWindow* window, bool collapsed, ImGuiCond co
static void SetWindowHitTestHole(ImGuiWindow* window, const ImVec2& pos, const ImVec2& size)
{
IM_ASSERT(window->HitTestHoleSize.x == 0); // We don't support multiple holes/hit test filters
- window->HitTestHoleSize = ImVec2ih((short)size.x, (short)size.y);
- window->HitTestHoleOffset = ImVec2ih((short)(pos.x - window->Pos.x), (short)(pos.y - window->Pos.y));
+ window->HitTestHoleSize = ImVec2ih(size);
+ window->HitTestHoleOffset = ImVec2ih(pos - window->Pos);
}
void ImGui::SetWindowCollapsed(bool collapsed, ImGuiCond cond)
@@ -6728,6 +7402,7 @@ void ImGui::SetNextWindowPos(const ImVec2& pos, ImGuiCond cond, const ImVec2& pi
{
ImGuiContext& g = *GImGui;
IM_ASSERT(cond == 0 || ImIsPowerOfTwo(cond)); // Make sure the user doesn't attempt to combine multiple condition flags.
+ g.NextWindowData.Flags |= ImGuiNextWindowDataFlags_HasPos;
g.NextWindowData.PosVal = pos;
g.NextWindowData.PosPivotVal = pivot;
g.NextWindowData.PosCond = cond ? cond : ImGuiCond_Always;
@@ -6747,6 +7422,7 @@ void ImGui::SetNextWindowSize(const ImVec2& size, ImGuiCond cond)
{
ImGuiContext& g = *GImGui;
IM_ASSERT(cond == 0 || ImIsPowerOfTwo(cond)); // Make sure the user doesn't attempt to combine multiple condition flags.
+ g.NextWindowData.Flags |= ImGuiNextWindowDataFlags_HasSize;
g.NextWindowData.SizeVal = size;
g.NextWindowData.SizeCond = cond ? cond : ImGuiCond_Always;
}
@@ -6754,23 +7430,26 @@ void ImGui::SetNextWindowSize(const ImVec2& size, ImGuiCond cond)
void ImGui::SetNextWindowSizeConstraints(const ImVec2& size_min, const ImVec2& size_max, ImGuiSizeCallback custom_callback, void* custom_callback_user_data)
{
ImGuiContext& g = *GImGui;
- g.NextWindowData.SizeConstraintCond = ImGuiCond_Always;
+ g.NextWindowData.Flags |= ImGuiNextWindowDataFlags_HasSizeConstraint;
g.NextWindowData.SizeConstraintRect = ImRect(size_min, size_max);
g.NextWindowData.SizeCallback = custom_callback;
g.NextWindowData.SizeCallbackUserData = custom_callback_user_data;
}
+// Content size = inner scrollable rectangle, padded with WindowPadding.
+// SetNextWindowContentSize(ImVec2(100,100) + ImGuiWindowFlags_AlwaysAutoResize will always allow submitting a 100x100 item.
void ImGui::SetNextWindowContentSize(const ImVec2& size)
{
ImGuiContext& g = *GImGui;
- g.NextWindowData.ContentSizeVal = size; // In Begin() we will add the size of window decorations (title bar, menu etc.) to that to form a SizeContents value.
- g.NextWindowData.ContentSizeCond = ImGuiCond_Always;
+ g.NextWindowData.Flags |= ImGuiNextWindowDataFlags_HasContentSize;
+ g.NextWindowData.ContentSizeVal = size;
}
void ImGui::SetNextWindowCollapsed(bool collapsed, ImGuiCond cond)
{
ImGuiContext& g = *GImGui;
IM_ASSERT(cond == 0 || ImIsPowerOfTwo(cond)); // Make sure the user doesn't attempt to combine multiple condition flags.
+ g.NextWindowData.Flags |= ImGuiNextWindowDataFlags_HasCollapsed;
g.NextWindowData.CollapsedVal = collapsed;
g.NextWindowData.CollapsedCond = cond ? cond : ImGuiCond_Always;
}
@@ -6778,26 +7457,27 @@ void ImGui::SetNextWindowCollapsed(bool collapsed, ImGuiCond cond)
void ImGui::SetNextWindowFocus()
{
ImGuiContext& g = *GImGui;
- g.NextWindowData.FocusCond = ImGuiCond_Always; // Using a Cond member for consistency (may transition all of them to single flag set for fast Clear() op)
+ g.NextWindowData.Flags |= ImGuiNextWindowDataFlags_HasFocus;
}
void ImGui::SetNextWindowBgAlpha(float alpha)
{
ImGuiContext& g = *GImGui;
+ g.NextWindowData.Flags |= ImGuiNextWindowDataFlags_HasBgAlpha;
g.NextWindowData.BgAlphaVal = alpha;
- g.NextWindowData.BgAlphaCond = ImGuiCond_Always; // Using a Cond member for consistency (may transition all of them to single flag set for fast Clear() op)
}
void ImGui::SetNextWindowViewport(ImGuiID id)
{
ImGuiContext& g = *GImGui;
- g.NextWindowData.ViewportCond = ImGuiCond_Always;
+ g.NextWindowData.Flags |= ImGuiNextWindowDataFlags_HasViewport;
g.NextWindowData.ViewportId = id;
}
void ImGui::SetNextWindowDockID(ImGuiID id, ImGuiCond cond)
{
ImGuiContext& g = *GImGui;
+ g.NextWindowData.Flags |= ImGuiNextWindowDataFlags_HasDock;
g.NextWindowData.DockCond = cond ? cond : ImGuiCond_Always;
g.NextWindowData.DockId = id;
}
@@ -6805,46 +7485,55 @@ void ImGui::SetNextWindowDockID(ImGuiID id, ImGuiCond cond)
void ImGui::SetNextWindowClass(const ImGuiWindowClass* window_class)
{
ImGuiContext& g = *GImGui;
+ IM_ASSERT((window_class->ViewportFlagsOverrideSet & window_class->ViewportFlagsOverrideClear) == 0); // Cannot set both set and clear for the same bit
+ g.NextWindowData.Flags |= ImGuiNextWindowDataFlags_HasWindowClass;
g.NextWindowData.WindowClass = *window_class;
}
-// In window space (not screen space!)
+// FIXME: This is in window space (not screen space!). We should try to obsolete all those functions.
ImVec2 ImGui::GetContentRegionMax()
{
- ImGuiWindow* window = GetCurrentWindowRead();
+ ImGuiContext& g = *GImGui;
+ ImGuiWindow* window = g.CurrentWindow;
ImVec2 mx = window->ContentsRegionRect.Max - window->Pos;
- if (window->DC.ColumnsSet)
- mx.x = GetColumnOffset(window->DC.ColumnsSet->Current + 1) - window->WindowPadding.x;
+ if (window->DC.CurrentColumns)
+ mx.x = window->WorkRect.Max.x - window->Pos.x;
return mx;
}
-ImVec2 ImGui::GetContentRegionAvail()
+// [Internal] Absolute coordinate. Saner. This is not exposed until we finishing refactoring work rect features.
+ImVec2 ImGui::GetContentRegionMaxAbs()
{
- ImGuiWindow* window = GetCurrentWindowRead();
- return GetContentRegionMax() - (window->DC.CursorPos - window->Pos);
+ ImGuiContext& g = *GImGui;
+ ImGuiWindow* window = g.CurrentWindow;
+ ImVec2 mx = window->ContentsRegionRect.Max;
+ if (window->DC.CurrentColumns)
+ mx.x = window->WorkRect.Max.x;
+ return mx;
}
-float ImGui::GetContentRegionAvailWidth()
+ImVec2 ImGui::GetContentRegionAvail()
{
- return GetContentRegionAvail().x;
+ ImGuiWindow* window = GImGui->CurrentWindow;
+ return GetContentRegionMaxAbs() - window->DC.CursorPos;
}
// In window space (not screen space!)
ImVec2 ImGui::GetWindowContentRegionMin()
{
- ImGuiWindow* window = GetCurrentWindowRead();
+ ImGuiWindow* window = GImGui->CurrentWindow;
return window->ContentsRegionRect.Min - window->Pos;
}
ImVec2 ImGui::GetWindowContentRegionMax()
{
- ImGuiWindow* window = GetCurrentWindowRead();
+ ImGuiWindow* window = GImGui->CurrentWindow;
return window->ContentsRegionRect.Max - window->Pos;
}
float ImGui::GetWindowContentRegionWidth()
{
- ImGuiWindow* window = GetCurrentWindowRead();
+ ImGuiWindow* window = GImGui->CurrentWindow;
return window->ContentsRegionRect.GetWidth();
}
@@ -6975,58 +7664,6 @@ void ImGui::SetCursorScreenPos(const ImVec2& pos)
window->DC.CursorMaxPos = ImMax(window->DC.CursorMaxPos, window->DC.CursorPos);
}
-float ImGui::GetScrollX()
-{
- return GImGui->CurrentWindow->Scroll.x;
-}
-
-float ImGui::GetScrollY()
-{
- return GImGui->CurrentWindow->Scroll.y;
-}
-
-float ImGui::GetScrollMaxX()
-{
- return GetWindowScrollMaxX(GImGui->CurrentWindow);
-}
-
-float ImGui::GetScrollMaxY()
-{
- return GetWindowScrollMaxY(GImGui->CurrentWindow);
-}
-
-void ImGui::SetScrollX(float scroll_x)
-{
- ImGuiWindow* window = GetCurrentWindow();
- window->ScrollTarget.x = scroll_x;
- window->ScrollTargetCenterRatio.x = 0.0f;
-}
-
-void ImGui::SetScrollY(float scroll_y)
-{
- ImGuiWindow* window = GetCurrentWindow();
- window->ScrollTarget.y = scroll_y + window->TitleBarHeight() + window->MenuBarHeight(); // title bar height canceled out when using ScrollTargetRelY
- window->ScrollTargetCenterRatio.y = 0.0f;
-}
-
-void ImGui::SetScrollFromPosY(float local_y, float center_y_ratio)
-{
- // We store a target position so centering can occur on the next frame when we are guaranteed to have a known window size
- ImGuiWindow* window = GetCurrentWindow();
- IM_ASSERT(center_y_ratio >= 0.0f && center_y_ratio <= 1.0f);
- window->ScrollTarget.y = (float)(int)(local_y + window->Scroll.y);
- window->ScrollTargetCenterRatio.y = center_y_ratio;
-}
-
-// center_y_ratio: 0.0f top of last item, 0.5f vertical center of last item, 1.0f bottom of last item.
-void ImGui::SetScrollHereY(float center_y_ratio)
-{
- ImGuiWindow* window = GetCurrentWindow();
- float target_y = window->DC.CursorPosPrevLine.y - window->Pos.y; // Top of last item, in window space
- target_y += (window->DC.PrevLineSize.y * center_y_ratio) + (GImGui->Style.ItemSpacing.y * (center_y_ratio - 0.5f) * 2.0f); // Precisely aim above, in the middle or below the last line.
- SetScrollFromPosY(target_y, center_y_ratio);
-}
-
void ImGui::ActivateItem(ImGuiID id)
{
ImGuiContext& g = *GImGui;
@@ -7036,9 +7673,11 @@ void ImGui::ActivateItem(ImGuiID id)
void ImGui::SetKeyboardFocusHere(int offset)
{
IM_ASSERT(offset >= -1); // -1 is allowed but not below
- ImGuiWindow* window = GetCurrentWindow();
- window->FocusIdxAllRequestNext = window->FocusIdxAllCounter + 1 + offset;
- window->FocusIdxTabRequestNext = INT_MAX;
+ ImGuiContext& g = *GImGui;
+ ImGuiWindow* window = g.CurrentWindow;
+ g.FocusRequestNextWindow = window;
+ g.FocusRequestNextCounterAll = window->DC.FocusCounterAll + 1 + offset;
+ g.FocusRequestNextCounterTab = INT_MAX;
}
void ImGui::SetItemDefaultFocus()
@@ -7090,9 +7729,15 @@ void ImGui::PushID(const void* ptr_id)
void ImGui::PushID(int int_id)
{
- const void* ptr_id = (void*)(intptr_t)int_id;
ImGuiWindow* window = GImGui->CurrentWindow;
- window->IDStack.push_back(window->GetIDNoKeepAlive(ptr_id));
+ window->IDStack.push_back(window->GetIDNoKeepAlive(int_id));
+}
+
+// Push a given id value ignoring the ID stack as a seed.
+void ImGui::PushOverrideID(ImGuiID id)
+{
+ ImGuiWindow* window = GImGui->CurrentWindow;
+ window->IDStack.push_back(id);
}
void ImGui::PopID()
@@ -7121,13 +7766,13 @@ ImGuiID ImGui::GetID(const void* ptr_id)
bool ImGui::IsRectVisible(const ImVec2& size)
{
- ImGuiWindow* window = GImGui->CurrentWindow;;
+ ImGuiWindow* window = GImGui->CurrentWindow;
return window->ClipRect.Overlaps(ImRect(window->DC.CursorPos, window->DC.CursorPos + size));
}
bool ImGui::IsRectVisible(const ImVec2& rect_min, const ImVec2& rect_max)
{
- ImGuiWindow* window = GImGui->CurrentWindow;;
+ ImGuiWindow* window = GImGui->CurrentWindow;
return window->ClipRect.Overlaps(ImRect(rect_min, rect_max));
}
@@ -7143,76 +7788,90 @@ void ImGui::BeginGroup()
group_data.BackupCursorMaxPos = window->DC.CursorMaxPos;
group_data.BackupIndent = window->DC.Indent;
group_data.BackupGroupOffset = window->DC.GroupOffset;
- group_data.BackupCurrentLineSize = window->DC.CurrentLineSize;
- group_data.BackupCurrentLineTextBaseOffset = window->DC.CurrentLineTextBaseOffset;
- group_data.BackupLogLinePosY = window->DC.LogLinePosY;
+ group_data.BackupCurrLineSize = window->DC.CurrLineSize;
+ group_data.BackupCurrLineTextBaseOffset = window->DC.CurrLineTextBaseOffset;
group_data.BackupActiveIdIsAlive = g.ActiveIdIsAlive;
group_data.BackupActiveIdPreviousFrameIsAlive = g.ActiveIdPreviousFrameIsAlive;
- group_data.AdvanceCursor = true;
+ group_data.EmitItem = true;
window->DC.GroupOffset.x = window->DC.CursorPos.x - window->Pos.x - window->DC.ColumnsOffset.x;
window->DC.Indent = window->DC.GroupOffset;
window->DC.CursorMaxPos = window->DC.CursorPos;
- window->DC.CurrentLineSize = ImVec2(0.0f, 0.0f);
- window->DC.LogLinePosY = window->DC.CursorPos.y - 9999.0f; // To enforce Log carriage return
+ window->DC.CurrLineSize = ImVec2(0.0f, 0.0f);
+ if (g.LogEnabled)
+ g.LogLinePosY = -FLT_MAX; // To enforce Log carriage return
}
void ImGui::EndGroup()
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = GetCurrentWindow();
- IM_ASSERT(!window->DC.GroupStack.empty()); // Mismatched BeginGroup()/EndGroup() calls
+ IM_ASSERT(!window->DC.GroupStack.empty()); // Mismatched BeginGroup()/EndGroup() calls
ImGuiGroupData& group_data = window->DC.GroupStack.back();
- ImRect group_bb(group_data.BackupCursorPos, window->DC.CursorMaxPos);
- group_bb.Max = ImMax(group_bb.Min, group_bb.Max);
+ ImRect group_bb(group_data.BackupCursorPos, ImMax(window->DC.CursorMaxPos, group_data.BackupCursorPos));
window->DC.CursorPos = group_data.BackupCursorPos;
window->DC.CursorMaxPos = ImMax(group_data.BackupCursorMaxPos, window->DC.CursorMaxPos);
window->DC.Indent = group_data.BackupIndent;
window->DC.GroupOffset = group_data.BackupGroupOffset;
- window->DC.CurrentLineSize = group_data.BackupCurrentLineSize;
- window->DC.CurrentLineTextBaseOffset = group_data.BackupCurrentLineTextBaseOffset;
- window->DC.LogLinePosY = window->DC.CursorPos.y - 9999.0f; // To enforce Log carriage return
+ window->DC.CurrLineSize = group_data.BackupCurrLineSize;
+ window->DC.CurrLineTextBaseOffset = group_data.BackupCurrLineTextBaseOffset;
+ if (g.LogEnabled)
+ g.LogLinePosY = -FLT_MAX; // To enforce Log carriage return
- if (group_data.AdvanceCursor)
+ if (!group_data.EmitItem)
{
- window->DC.CurrentLineTextBaseOffset = ImMax(window->DC.PrevLineTextBaseOffset, group_data.BackupCurrentLineTextBaseOffset); // FIXME: Incorrect, we should grab the base offset from the *first line* of the group but it is hard to obtain now.
- ItemSize(group_bb.GetSize(), group_data.BackupCurrentLineTextBaseOffset);
- ItemAdd(group_bb, 0);
+ window->DC.GroupStack.pop_back();
+ return;
}
+ window->DC.CurrLineTextBaseOffset = ImMax(window->DC.PrevLineTextBaseOffset, group_data.BackupCurrLineTextBaseOffset); // FIXME: Incorrect, we should grab the base offset from the *first line* of the group but it is hard to obtain now.
+ ItemSize(group_bb.GetSize(), 0.0f);
+ ItemAdd(group_bb, 0);
+
// If the current ActiveId was declared within the boundary of our group, we copy it to LastItemId so IsItemActive(), IsItemDeactivated() etc. will be functional on the entire group.
// It would be be neater if we replaced window.DC.LastItemId by e.g. 'bool LastItemIsActive', but would put a little more burden on individual widgets.
- // (and if you grep for LastItemId you'll notice it is only used in that context.
- if ((group_data.BackupActiveIdIsAlive != g.ActiveId) && (g.ActiveIdIsAlive == g.ActiveId) && g.ActiveId) // && g.ActiveIdWindow->RootWindow == window->RootWindow)
+ // Also if you grep for LastItemId you'll notice it is only used in that context.
+ // (The tests not symmetrical because ActiveIdIsAlive is an ID itself, in order to be able to handle ActiveId being overwritten during the frame.)
+ const bool group_contains_curr_active_id = (group_data.BackupActiveIdIsAlive != g.ActiveId) && (g.ActiveIdIsAlive == g.ActiveId) && g.ActiveId;
+ const bool group_contains_prev_active_id = !group_data.BackupActiveIdPreviousFrameIsAlive && g.ActiveIdPreviousFrameIsAlive;
+ if (group_contains_curr_active_id)
window->DC.LastItemId = g.ActiveId;
- else if (!group_data.BackupActiveIdPreviousFrameIsAlive && g.ActiveIdPreviousFrameIsAlive) // && g.ActiveIdPreviousFrameWindow->RootWindow == window->RootWindow)
+ else if (group_contains_prev_active_id)
window->DC.LastItemId = g.ActiveIdPreviousFrame;
window->DC.LastItemRect = group_bb;
- window->DC.GroupStack.pop_back();
+ // Forward Edited flag
+ if (group_contains_curr_active_id && g.ActiveIdHasBeenEditedThisFrame)
+ window->DC.LastItemStatusFlags |= ImGuiItemStatusFlags_Edited;
+
+ // Forward Deactivated flag
+ window->DC.LastItemStatusFlags |= ImGuiItemStatusFlags_HasDeactivated;
+ if (group_contains_prev_active_id && g.ActiveId != g.ActiveIdPreviousFrame)
+ window->DC.LastItemStatusFlags |= ImGuiItemStatusFlags_Deactivated;
+ window->DC.GroupStack.pop_back();
//window->DrawList->AddRect(group_bb.Min, group_bb.Max, IM_COL32(255,0,255,255)); // [Debug]
}
// Gets back to previous line and continue with horizontal layout
-// pos_x == 0 : follow right after previous item
-// pos_x != 0 : align to specified x position (relative to window/group left)
-// spacing_w < 0 : use default spacing if pos_x == 0, no spacing if pos_x != 0
-// spacing_w >= 0 : enforce spacing amount
-void ImGui::SameLine(float pos_x, float spacing_w)
+// offset_from_start_x == 0 : follow right after previous item
+// offset_from_start_x != 0 : align to specified x position (relative to window/group left)
+// spacing_w < 0 : use default spacing if pos_x == 0, no spacing if pos_x != 0
+// spacing_w >= 0 : enforce spacing amount
+void ImGui::SameLine(float offset_from_start_x, float spacing_w)
{
ImGuiWindow* window = GetCurrentWindow();
if (window->SkipItems)
return;
ImGuiContext& g = *GImGui;
- if (pos_x != 0.0f)
+ if (offset_from_start_x != 0.0f)
{
if (spacing_w < 0.0f) spacing_w = 0.0f;
- window->DC.CursorPos.x = window->Pos.x - window->Scroll.x + pos_x + spacing_w + window->DC.GroupOffset.x + window->DC.ColumnsOffset.x;
+ window->DC.CursorPos.x = window->Pos.x - window->Scroll.x + offset_from_start_x + spacing_w + window->DC.GroupOffset.x + window->DC.ColumnsOffset.x;
window->DC.CursorPos.y = window->DC.CursorPosPrevLine.y;
}
else
@@ -7221,8 +7880,8 @@ void ImGui::SameLine(float pos_x, float spacing_w)
window->DC.CursorPos.x = window->DC.CursorPosPrevLine.x + spacing_w;
window->DC.CursorPos.y = window->DC.CursorPosPrevLine.y;
}
- window->DC.CurrentLineSize = window->DC.PrevLineSize;
- window->DC.CurrentLineTextBaseOffset = window->DC.PrevLineTextBaseOffset;
+ window->DC.CurrLineSize = window->DC.PrevLineSize;
+ window->DC.CurrLineTextBaseOffset = window->DC.PrevLineTextBaseOffset;
}
void ImGui::Indent(float indent_w)
@@ -7241,6 +7900,178 @@ void ImGui::Unindent(float indent_w)
window->DC.CursorPos.x = window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x;
}
+
+//-----------------------------------------------------------------------------
+// [SECTION] SCROLLING
+//-----------------------------------------------------------------------------
+
+static ImVec2 CalcNextScrollFromScrollTargetAndClamp(ImGuiWindow* window, bool snap_on_edges)
+{
+ ImGuiContext& g = *GImGui;
+ ImVec2 scroll = window->Scroll;
+ if (window->ScrollTarget.x < FLT_MAX)
+ {
+ float cr_x = window->ScrollTargetCenterRatio.x;
+ float target_x = window->ScrollTarget.x;
+ if (snap_on_edges && cr_x <= 0.0f && target_x <= window->WindowPadding.x)
+ target_x = 0.0f;
+ else if (snap_on_edges && cr_x >= 1.0f && target_x >= window->ContentSize.x + window->WindowPadding.x + g.Style.ItemSpacing.x)
+ target_x = window->ContentSize.x + window->WindowPadding.x * 2.0f;
+ scroll.x = target_x - cr_x * (window->SizeFull.x - window->ScrollbarSizes.x);
+ }
+ if (window->ScrollTarget.y < FLT_MAX)
+ {
+ // 'snap_on_edges' allows for a discontinuity at the edge of scrolling limits to take account of WindowPadding so that scrolling to make the last item visible scroll far enough to see the padding.
+ float decoration_up_height = window->TitleBarHeight() + window->MenuBarHeight();
+ float cr_y = window->ScrollTargetCenterRatio.y;
+ float target_y = window->ScrollTarget.y;
+ if (snap_on_edges && cr_y <= 0.0f && target_y <= window->WindowPadding.y)
+ target_y = 0.0f;
+ if (snap_on_edges && cr_y >= 1.0f && target_y >= window->ContentSize.y + window->WindowPadding.y + g.Style.ItemSpacing.y)
+ target_y = window->ContentSize.y + window->WindowPadding.y * 2.0f;
+ scroll.y = target_y - cr_y * (window->SizeFull.y - window->ScrollbarSizes.y - decoration_up_height);
+ }
+ scroll = ImMax(scroll, ImVec2(0.0f, 0.0f));
+ if (!window->Collapsed && !window->SkipItems)
+ {
+ scroll.x = ImMin(scroll.x, window->ScrollMax.x);
+ scroll.y = ImMin(scroll.y, window->ScrollMax.y);
+ }
+ return scroll;
+}
+
+// Scroll to keep newly navigated item fully into view
+ImVec2 ImGui::ScrollToBringRectIntoView(ImGuiWindow* window, const ImRect& item_rect)
+{
+ ImGuiContext& g = *GImGui;
+ ImRect window_rect(window->InnerRect.Min - ImVec2(1, 1), window->InnerRect.Max + ImVec2(1, 1));
+ //GetForegroundDrawList(window)->AddRect(window_rect.Min, window_rect.Max, IM_COL32_WHITE); // [DEBUG]
+
+ ImVec2 delta_scroll;
+ if (!window_rect.Contains(item_rect))
+ {
+ if (window->ScrollbarX && item_rect.Min.x < window_rect.Min.x)
+ SetScrollFromPosX(window, item_rect.Min.x - window->Pos.x + g.Style.ItemSpacing.x, 0.0f);
+ else if (window->ScrollbarX && item_rect.Max.x >= window_rect.Max.x)
+ SetScrollFromPosX(window, item_rect.Max.x - window->Pos.x + g.Style.ItemSpacing.x, 1.0f);
+ if (item_rect.Min.y < window_rect.Min.y)
+ SetScrollFromPosY(window, item_rect.Min.y - window->Pos.y - g.Style.ItemSpacing.y, 0.0f);
+ else if (item_rect.Max.y >= window_rect.Max.y)
+ SetScrollFromPosY(window, item_rect.Max.y - window->Pos.y + g.Style.ItemSpacing.y, 1.0f);
+
+ ImVec2 next_scroll = CalcNextScrollFromScrollTargetAndClamp(window, false);
+ delta_scroll = next_scroll - window->Scroll;
+ }
+
+ // Also scroll parent window to keep us into view if necessary
+ if (window->Flags & ImGuiWindowFlags_ChildWindow)
+ delta_scroll += ScrollToBringRectIntoView(window->ParentWindow, ImRect(item_rect.Min - delta_scroll, item_rect.Max - delta_scroll));
+
+ return delta_scroll;
+}
+
+float ImGui::GetScrollX()
+{
+ ImGuiWindow* window = GImGui->CurrentWindow;
+ return window->Scroll.x;
+}
+
+float ImGui::GetScrollY()
+{
+ ImGuiWindow* window = GImGui->CurrentWindow;
+ return window->Scroll.y;
+}
+
+float ImGui::GetScrollMaxX()
+{
+ ImGuiWindow* window = GImGui->CurrentWindow;
+ return window->ScrollMax.x;
+}
+
+float ImGui::GetScrollMaxY()
+{
+ ImGuiWindow* window = GImGui->CurrentWindow;
+ return window->ScrollMax.y;
+}
+
+void ImGui::SetScrollX(float scroll_x)
+{
+ ImGuiWindow* window = GetCurrentWindow();
+ window->ScrollTarget.x = scroll_x;
+ window->ScrollTargetCenterRatio.x = 0.0f;
+}
+
+void ImGui::SetScrollY(float scroll_y)
+{
+ ImGuiWindow* window = GetCurrentWindow();
+ window->ScrollTarget.y = scroll_y;
+ window->ScrollTargetCenterRatio.y = 0.0f;
+}
+
+void ImGui::SetScrollX(ImGuiWindow* window, float new_scroll_x)
+{
+ window->ScrollTarget.x = new_scroll_x;
+ window->ScrollTargetCenterRatio.x = 0.0f;
+}
+
+void ImGui::SetScrollY(ImGuiWindow* window, float new_scroll_y)
+{
+ window->ScrollTarget.y = new_scroll_y;
+ window->ScrollTargetCenterRatio.y = 0.0f;
+}
+
+
+void ImGui::SetScrollFromPosX(ImGuiWindow* window, float local_x, float center_x_ratio)
+{
+ // We store a target position so centering can occur on the next frame when we are guaranteed to have a known window size
+ IM_ASSERT(center_x_ratio >= 0.0f && center_x_ratio <= 1.0f);
+ window->ScrollTarget.x = (float)(int)(local_x + window->Scroll.x);
+ window->ScrollTargetCenterRatio.x = center_x_ratio;
+}
+
+void ImGui::SetScrollFromPosY(ImGuiWindow* window, float local_y, float center_y_ratio)
+{
+ // We store a target position so centering can occur on the next frame when we are guaranteed to have a known window size
+ IM_ASSERT(center_y_ratio >= 0.0f && center_y_ratio <= 1.0f);
+ const float decoration_up_height = window->TitleBarHeight() + window->MenuBarHeight();
+ local_y -= decoration_up_height;
+ window->ScrollTarget.y = (float)(int)(local_y + window->Scroll.y);
+ window->ScrollTargetCenterRatio.y = center_y_ratio;
+}
+
+void ImGui::SetScrollFromPosX(float local_x, float center_x_ratio)
+{
+ ImGuiContext& g = *GImGui;
+ SetScrollFromPosX(g.CurrentWindow, local_x, center_x_ratio);
+}
+
+void ImGui::SetScrollFromPosY(float local_y, float center_y_ratio)
+{
+ ImGuiContext& g = *GImGui;
+ SetScrollFromPosY(g.CurrentWindow, local_y, center_y_ratio);
+}
+
+// center_x_ratio: 0.0f left of last item, 0.5f horizontal center of last item, 1.0f right of last item.
+void ImGui::SetScrollHereX(float center_x_ratio)
+{
+ ImGuiContext& g = *GImGui;
+ ImGuiWindow* window = g.CurrentWindow;
+ float target_x = window->DC.LastItemRect.Min.x - window->Pos.x; // Left of last item, in window space
+ float last_item_width = window->DC.LastItemRect.GetWidth();
+ target_x += (last_item_width * center_x_ratio) + (g.Style.ItemSpacing.x * (center_x_ratio - 0.5f) * 2.0f); // Precisely aim before, in the middle or after the last item.
+ SetScrollFromPosX(target_x, center_x_ratio);
+}
+
+// center_y_ratio: 0.0f top of last item, 0.5f vertical center of last item, 1.0f bottom of last item.
+void ImGui::SetScrollHereY(float center_y_ratio)
+{
+ ImGuiContext& g = *GImGui;
+ ImGuiWindow* window = g.CurrentWindow;
+ float target_y = window->DC.CursorPosPrevLine.y - window->Pos.y; // Top of last item, in window space
+ target_y += (window->DC.PrevLineSize.y * center_y_ratio) + (g.Style.ItemSpacing.y * (center_y_ratio - 0.5f) * 2.0f); // Precisely aim above, in the middle or below the last line.
+ SetScrollFromPosY(target_y, center_y_ratio);
+}
+
//-----------------------------------------------------------------------------
// [SECTION] TOOLTIPS
//-----------------------------------------------------------------------------
@@ -7278,7 +8109,7 @@ void ImGui::BeginTooltipEx(ImGuiWindowFlags extra_flags, bool override_previous_
{
// Hide previous tooltip from being displayed. We can't easily "reset" the content of a window so we create a new one.
window->Hidden = true;
- window->HiddenFramesRegular = 1;
+ window->HiddenFramesCanSkipItems = 1;
ImFormatString(window_name, IM_ARRAYSIZE(window_name), "##Tooltip_%02d", ++g.TooltipOverrideCount);
}
ImGuiWindowFlags flags = ImGuiWindowFlags_Tooltip|ImGuiWindowFlags_NoInputs|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoDocking;
@@ -7326,7 +8157,7 @@ bool ImGui::IsPopupOpen(const char* str_id)
return g.OpenPopupStack.Size > g.BeginPopupStack.Size && g.OpenPopupStack[g.BeginPopupStack.Size].PopupId == g.CurrentWindow->GetID(str_id);
}
-ImGuiWindow* ImGui::GetFrontMostPopupModal()
+ImGuiWindow* ImGui::GetTopMostPopupModal()
{
ImGuiContext& g = *GImGui;
for (int n = g.OpenPopupStack.Size-1; n >= 0; n--)
@@ -7351,10 +8182,10 @@ void ImGui::OpenPopupEx(ImGuiID id)
ImGuiContext& g = *GImGui;
ImGuiWindow* parent_window = g.CurrentWindow;
int current_stack_size = g.BeginPopupStack.Size;
- ImGuiPopupRef popup_ref; // Tagged as new ref as Window will be set back to NULL if we write this into OpenPopupStack.
+ ImGuiPopupData popup_ref; // Tagged as new ref as Window will be set back to NULL if we write this into OpenPopupStack.
popup_ref.PopupId = id;
popup_ref.Window = NULL;
- popup_ref.ParentWindow = parent_window;
+ popup_ref.SourceWindow = g.NavWindow;
popup_ref.OpenFrameCount = g.FrameCount;
popup_ref.OpenParentId = parent_window->IDStack.back();
popup_ref.OpenPopupPos = NavCalcPreferredRefPos();
@@ -7401,7 +8232,7 @@ bool ImGui::OpenPopupOnItemClick(const char* str_id, int mouse_button)
return false;
}
-void ImGui::ClosePopupsOverWindow(ImGuiWindow* ref_window)
+void ImGui::ClosePopupsOverWindow(ImGuiWindow* ref_window, bool restore_focus_to_window_under_popup)
{
ImGuiContext& g = *GImGui;
if (g.OpenPopupStack.empty())
@@ -7415,52 +8246,54 @@ void ImGui::ClosePopupsOverWindow(ImGuiWindow* ref_window)
// Find the highest popup which is a descendant of the reference window (generally reference window = NavWindow)
for (; popup_count_to_keep < g.OpenPopupStack.Size; popup_count_to_keep++)
{
- ImGuiPopupRef& popup = g.OpenPopupStack[popup_count_to_keep];
+ ImGuiPopupData& popup = g.OpenPopupStack[popup_count_to_keep];
if (!popup.Window)
continue;
IM_ASSERT((popup.Window->Flags & ImGuiWindowFlags_Popup) != 0);
if (popup.Window->Flags & ImGuiWindowFlags_ChildWindow)
continue;
- // Trim the stack if popups are not direct descendant of the reference window (which is often the NavWindow)
- bool popup_or_descendent_has_focus = false;
- for (int m = popup_count_to_keep; m < g.OpenPopupStack.Size && !popup_or_descendent_has_focus; m++)
- if (g.OpenPopupStack[m].Window && g.OpenPopupStack[m].Window->RootWindow == ref_window->RootWindow)
- popup_or_descendent_has_focus = true;
- if (!popup_or_descendent_has_focus)
+ // Trim the stack when popups are not direct descendant of the reference window (the reference window is often the NavWindow)
+ bool popup_or_descendent_is_ref_window = false;
+ for (int m = popup_count_to_keep; m < g.OpenPopupStack.Size && !popup_or_descendent_is_ref_window; m++)
+ if (ImGuiWindow* popup_window = g.OpenPopupStack[m].Window)
+ if (popup_window->RootWindow == ref_window->RootWindow)
+ popup_or_descendent_is_ref_window = true;
+ if (!popup_or_descendent_is_ref_window)
break;
}
}
if (popup_count_to_keep < g.OpenPopupStack.Size) // This test is not required but it allows to set a convenient breakpoint on the statement below
{
//IMGUI_DEBUG_LOG("ClosePopupsOverWindow(%s) -> ClosePopupToLevel(%d)\n", ref_window->Name, popup_count_to_keep);
- ClosePopupToLevel(popup_count_to_keep, false);
+ ClosePopupToLevel(popup_count_to_keep, restore_focus_to_window_under_popup);
}
}
-void ImGui::ClosePopupToLevel(int remaining, bool apply_focus_to_window_under)
+void ImGui::ClosePopupToLevel(int remaining, bool restore_focus_to_window_under_popup)
{
- IM_ASSERT(remaining >= 0);
ImGuiContext& g = *GImGui;
- ImGuiWindow* focus_window = (remaining > 0) ? g.OpenPopupStack[remaining-1].Window : g.OpenPopupStack[0].ParentWindow;
+ IM_ASSERT(remaining >= 0 && remaining < g.OpenPopupStack.Size);
+ ImGuiWindow* focus_window = g.OpenPopupStack[remaining].SourceWindow;
+ ImGuiWindow* popup_window = g.OpenPopupStack[remaining].Window;
g.OpenPopupStack.resize(remaining);
- // FIXME: This code is faulty and we may want to eventually to replace or remove the 'apply_focus_to_window_under=true' path completely.
- // Instead of using g.OpenPopupStack[remaining-1].Window etc. we should find the highest root window that is behind the popups we are closing.
- // The current code will set focus to the parent of the popup window which is incorrect.
- // It rarely manifested until now because UpdateMouseMovingWindowNewFrame() would call FocusWindow() again on the clicked window,
- // leading to a chain of focusing A (clicked window) then B (parent window of the popup) then A again.
- // However if the clicked window has the _NoMove flag set we would be left with B focused.
- // For now, we have disabled this path when called from ClosePopupsOverWindow() because the users of ClosePopupsOverWindow() don't need to alter focus anyway,
- // but we should inspect and fix this properly.
- if (apply_focus_to_window_under)
+ if (restore_focus_to_window_under_popup)
{
- if (g.NavLayer == 0)
- focus_window = NavRestoreLastChildNavWindow(focus_window);
- FocusWindow(focus_window);
- }
-}
-
+ if (focus_window && !focus_window->WasActive && popup_window)
+ {
+ // Fallback
+ FocusTopMostWindowUnderOne(popup_window, NULL);
+ }
+ else
+ {
+ if (g.NavLayer == 0 && focus_window)
+ focus_window = NavRestoreLastChildNavWindow(focus_window);
+ FocusWindow(focus_window);
+ }
+ }
+}
+
// Close the popup we have begin-ed into.
void ImGui::CloseCurrentPopup()
{
@@ -7492,22 +8325,23 @@ void ImGui::CloseCurrentPopup()
window->DC.NavHideHighlightOneFrame = true;
}
-bool ImGui::BeginPopupEx(ImGuiID id, ImGuiWindowFlags extra_flags)
+bool ImGui::BeginPopupEx(ImGuiID id, ImGuiWindowFlags flags)
{
ImGuiContext& g = *GImGui;
if (!IsPopupOpen(id))
{
- g.NextWindowData.Clear(); // We behave like Begin() and need to consume those values
+ g.NextWindowData.ClearFlags(); // We behave like Begin() and need to consume those values
return false;
}
char name[20];
- if (extra_flags & ImGuiWindowFlags_ChildMenu)
+ if (flags & ImGuiWindowFlags_ChildMenu)
ImFormatString(name, IM_ARRAYSIZE(name), "##Menu_%02d", g.BeginPopupStack.Size); // Recycle windows based on depth
else
ImFormatString(name, IM_ARRAYSIZE(name), "##Popup_%08x", id); // Not recycling, so we can close/open during the same frame
- bool is_open = Begin(name, NULL, extra_flags | ImGuiWindowFlags_Popup);
+ flags |= ImGuiWindowFlags_Popup | ImGuiWindowFlags_NoDocking;
+ bool is_open = Begin(name, NULL, flags);
if (!is_open) // NB: Begin can return false when the popup is completely clipped (e.g. zero size display)
EndPopup();
@@ -7519,15 +8353,15 @@ bool ImGui::BeginPopup(const char* str_id, ImGuiWindowFlags flags)
ImGuiContext& g = *GImGui;
if (g.OpenPopupStack.Size <= g.BeginPopupStack.Size) // Early out for performance
{
- g.NextWindowData.Clear(); // We behave like Begin() and need to consume those values
+ g.NextWindowData.ClearFlags(); // We behave like Begin() and need to consume those values
return false;
}
- flags |= ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoDocking;
+ flags |= ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings;
return BeginPopupEx(g.CurrentWindow->GetID(str_id), flags);
}
// If 'p_open' is specified for a modal popup window, the popup will have a regular close button which will close the popup.
-// Note that popup visibility status is owned by imgui (and manipulated with e.g. OpenPopup) so the actual value of *p_open is meaningless here.
+// Note that popup visibility status is owned by Dear ImGui (and manipulated with e.g. OpenPopup) so the actual value of *p_open is meaningless here.
bool ImGui::BeginPopupModal(const char* name, bool* p_open, ImGuiWindowFlags flags)
{
ImGuiContext& g = *GImGui;
@@ -7535,14 +8369,17 @@ bool ImGui::BeginPopupModal(const char* name, bool* p_open, ImGuiWindowFlags fla
const ImGuiID id = window->GetID(name);
if (!IsPopupOpen(id))
{
- g.NextWindowData.Clear(); // We behave like Begin() and need to consume those values
+ g.NextWindowData.ClearFlags(); // We behave like Begin() and need to consume those values
return false;
}
// Center modal windows by default
// FIXME: Should test for (PosCond & window->SetWindowPosAllowFlags) with the upcoming window.
- if (g.NextWindowData.PosCond == 0)
- SetNextWindowPos(window->Viewport->GetCenter(), ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
+ if ((g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasPos) == 0)
+ {
+ ImGuiViewportP* viewport = window->WasActive ? window->Viewport : (ImGuiViewportP*)GetMainViewport(); // FIXME-VIEWPORT: What may be our reference viewport?
+ SetNextWindowPos(viewport->GetCenter(), ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
+ }
flags |= ImGuiWindowFlags_Popup | ImGuiWindowFlags_Modal | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoDocking;
const bool is_open = Begin(name, p_open, flags);
@@ -7558,7 +8395,7 @@ bool ImGui::BeginPopupModal(const char* name, bool* p_open, ImGuiWindowFlags fla
void ImGui::EndPopup()
{
- ImGuiContext& g = *GImGui;
+ ImGuiContext& g = *GImGui;
IM_ASSERT(g.CurrentWindow->Flags & ImGuiWindowFlags_Popup); // Mismatched BeginPopup()/EndPopup() calls
IM_ASSERT(g.BeginPopupStack.Size > 0);
@@ -7574,6 +8411,8 @@ void ImGui::EndPopup()
bool ImGui::BeginPopupContextItem(const char* str_id, int mouse_button)
{
ImGuiWindow* window = GImGui->CurrentWindow;
+ if (window->SkipItems)
+ return false;
ImGuiID id = str_id ? window->GetID(str_id) : window->DC.LastItemId; // If user hasn't passed an ID, we can use the LastItemID. Using LastItemID as a Popup ID won't conflict!
IM_ASSERT(id != 0); // You cannot pass a NULL str_id if the last item has no identifier (e.g. a Text() item)
if (IsMouseReleased(mouse_button) && IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup))
@@ -7610,8 +8449,8 @@ bool ImGui::BeginPopupContextVoid(const char* str_id, int mouse_button)
ImVec2 ImGui::FindBestWindowPosForPopupEx(const ImVec2& ref_pos, const ImVec2& size, ImGuiDir* last_dir, const ImRect& r_outer, const ImRect& r_avoid, ImGuiPopupPositionPolicy policy)
{
ImVec2 base_pos_clamped = ImClamp(ref_pos, r_outer.Min, r_outer.Max - size);
- //GImGui->OverlayDrawList.AddRect(r_avoid.Min, r_avoid.Max, IM_COL32(255,0,0,255));
- //GImGui->OverlayDrawList.AddRect(r_outer.Min, r_outer.Max, IM_COL32(0,255,0,255));
+ //GetForegroundDrawList()->AddRect(r_avoid.Min, r_avoid.Max, IM_COL32(255,0,0,255));
+ //GetForegroundDrawList()->AddRect(r_outer.Min, r_outer.Max, IM_COL32(0,255,0,255));
// Combo Box policy (we want a connecting edge)
if (policy == ImGuiPopupPositionPolicy_ComboBox)
@@ -7686,10 +8525,10 @@ ImVec2 ImGui::FindBestWindowPosForPopup(ImGuiWindow* window)
ImGuiContext& g = *GImGui;
if (window->Flags & ImGuiWindowFlags_ChildMenu)
{
- // Child menus typically request _any_ position within the parent menu item, and then our FindBestWindowPosForPopup() function will move the new menu outside the parent bounds.
+ // Child menus typically request _any_ position within the parent menu item, and then we move the new menu outside the parent bounds.
// This is how we end up with child menus appearing (most-commonly) on the right of the parent menu.
ImGuiWindow* parent_window = window->ParentWindow;
- float horizontal_overlap = g.Style.ItemSpacing.x; // We want some overlap to convey the relative depth of each menu (currently the amount of overlap is hard-coded to style.ItemSpacing.x).
+ float horizontal_overlap = g.Style.ItemInnerSpacing.x; // We want some overlap to convey the relative depth of each menu (currently the amount of overlap is hard-coded to style.ItemSpacing.x).
ImRect r_outer = GetWindowAllowedExtentRect(window);
ImRect r_avoid;
if (parent_window->DC.MenuBarAppending)
@@ -7724,5867 +8563,6040 @@ ImVec2 ImGui::FindBestWindowPosForPopup(ImGuiWindow* window)
return window->Pos;
}
+
//-----------------------------------------------------------------------------
-// [SECTION] VIEWPORTS, PLATFORM WINDOWS
+// [SECTION] KEYBOARD/GAMEPAD NAVIGATION
//-----------------------------------------------------------------------------
-ImGuiViewport* ImGui::GetMainViewport()
-{
- ImGuiContext& g = *GImGui;
- return g.Viewports[0];
-}
-
-ImGuiViewport* ImGui::FindViewportByID(ImGuiID id)
-{
- ImGuiContext& g = *GImGui;
- for (int n = 0; n < g.Viewports.Size; n++)
- if (g.Viewports[n]->ID == id)
- return g.Viewports[n];
- return NULL;
-}
-
-ImGuiViewport* ImGui::FindViewportByPlatformHandle(void* platform_handle)
-{
- ImGuiContext& g = *GImGui;
- for (int i = 0; i != g.Viewports.Size; i++)
- if (g.Viewports[i]->PlatformHandle == platform_handle)
- return g.Viewports[i];
- return NULL;
-}
-
-void ImGui::SetCurrentViewport(ImGuiWindow* current_window, ImGuiViewportP* viewport)
+ImGuiDir ImGetDirQuadrantFromDelta(float dx, float dy)
{
- ImGuiContext& g = *GImGui;
- (void)current_window;
-
- if (viewport)
- viewport->LastFrameActive = g.FrameCount;
- if (g.CurrentViewport == viewport)
- return;
- g.CurrentViewport = viewport;
- //IMGUI_DEBUG_LOG("SetCurrentViewport changed '%s' 0x%08X\n", current_window ? current_window->Name : NULL, viewport ? viewport->ID : 0);
-
- // Notify platform layer of viewport changes
- // FIXME-DPI: This is only currently used for experimenting with handling of multiple DPI
- if (g.CurrentViewport && g.PlatformIO.Platform_OnChangedViewport)
- g.PlatformIO.Platform_OnChangedViewport(g.CurrentViewport);
+ if (ImFabs(dx) > ImFabs(dy))
+ return (dx > 0.0f) ? ImGuiDir_Right : ImGuiDir_Left;
+ return (dy > 0.0f) ? ImGuiDir_Down : ImGuiDir_Up;
}
-static void SetWindowViewport(ImGuiWindow* window, ImGuiViewportP* viewport)
+static float inline NavScoreItemDistInterval(float a0, float a1, float b0, float b1)
{
- window->Viewport = viewport;
- window->ViewportId = viewport->ID;
- window->ViewportOwned = (viewport->Window == window);
+ if (a1 < b0)
+ return a1 - b0;
+ if (b1 < a0)
+ return a0 - b1;
+ return 0.0f;
}
-static bool ImGui::GetWindowAlwaysWantOwnViewport(ImGuiWindow* window)
+static void inline NavClampRectToVisibleAreaForMoveDir(ImGuiDir move_dir, ImRect& r, const ImRect& clip_rect)
{
- // Tooltips and menus are not automatically forced into their own viewport when the NoMerge flag is set, however the multiplication of viewports makes them more likely to protude and create their own.
- ImGuiContext& g = *GImGui;
- if (g.IO.ConfigViewportsNoAutoMerge && (g.ConfigFlagsForFrame & ImGuiConfigFlags_ViewportsEnable))
- if (!window->DockIsActive)
- if ((window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_ChildMenu | ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_Popup)) == 0)
- return true;
- return false;
+ if (move_dir == ImGuiDir_Left || move_dir == ImGuiDir_Right)
+ {
+ r.Min.y = ImClamp(r.Min.y, clip_rect.Min.y, clip_rect.Max.y);
+ r.Max.y = ImClamp(r.Max.y, clip_rect.Min.y, clip_rect.Max.y);
+ }
+ else
+ {
+ r.Min.x = ImClamp(r.Min.x, clip_rect.Min.x, clip_rect.Max.x);
+ r.Max.x = ImClamp(r.Max.x, clip_rect.Min.x, clip_rect.Max.x);
+ }
}
-static bool ImGui::UpdateTryMergeWindowIntoHostViewport(ImGuiWindow* window, ImGuiViewportP* viewport)
+// Scoring function for directional navigation. Based on https://gist.github.com/rygorous/6981057
+static bool NavScoreItem(ImGuiNavMoveResult* result, ImRect cand)
{
ImGuiContext& g = *GImGui;
- if (!(viewport->Flags & ImGuiViewportFlags_CanHostOtherWindows) || window->Viewport == viewport || viewport->PlatformWindowMinimized)
- return false;
- if (!viewport->GetRect().Contains(window->Rect()))
- return false;
- if (GetWindowAlwaysWantOwnViewport(window))
+ ImGuiWindow* window = g.CurrentWindow;
+ if (g.NavLayer != window->DC.NavLayerCurrent)
return false;
- for (int n = 0; n < g.Windows.Size; n++)
+ const ImRect& curr = g.NavScoringRectScreen; // Current modified source rect (NB: we've applied Max.x = Min.x in NavUpdate() to inhibit the effect of having varied item width)
+ g.NavScoringCount++;
+
+ // When entering through a NavFlattened border, we consider child window items as fully clipped for scoring
+ if (window->ParentWindow == g.NavWindow)
{
- ImGuiWindow* window_behind = g.Windows[n];
- if (window_behind == window)
- break;
- if (window_behind->WasActive && window_behind->ViewportOwned && !(window_behind->Flags & ImGuiWindowFlags_ChildWindow))
- if (window_behind->Viewport->GetRect().Overlaps(window->Rect()))
- return false;
+ IM_ASSERT((window->Flags | g.NavWindow->Flags) & ImGuiWindowFlags_NavFlattened);
+ if (!window->ClipRect.Overlaps(cand))
+ return false;
+ cand.ClipWithFull(window->ClipRect); // This allows the scored item to not overlap other candidates in the parent window
}
- // Move to the existing viewport, Move child/hosted windows as well (FIXME-OPT: iterate child)
- ImGuiViewportP* old_viewport = window->Viewport;
- if (window->ViewportOwned)
- for (int n = 0; n < g.Windows.Size; n++)
- if (g.Windows[n]->Viewport == old_viewport)
- SetWindowViewport(g.Windows[n], viewport);
- SetWindowViewport(window, viewport);
- BringWindowToDisplayFront(window);
+ // We perform scoring on items bounding box clipped by the current clipping rectangle on the other axis (clipping on our movement axis would give us equal scores for all clipped items)
+ // For example, this ensure that items in one column are not reached when moving vertically from items in another column.
+ NavClampRectToVisibleAreaForMoveDir(g.NavMoveClipDir, cand, window->ClipRect);
- return true;
-}
+ // Compute distance between boxes
+ // FIXME-NAV: Introducing biases for vertical navigation, needs to be removed.
+ float dbx = NavScoreItemDistInterval(cand.Min.x, cand.Max.x, curr.Min.x, curr.Max.x);
+ float dby = NavScoreItemDistInterval(ImLerp(cand.Min.y, cand.Max.y, 0.2f), ImLerp(cand.Min.y, cand.Max.y, 0.8f), ImLerp(curr.Min.y, curr.Max.y, 0.2f), ImLerp(curr.Min.y, curr.Max.y, 0.8f)); // Scale down on Y to keep using box-distance for vertically touching items
+ if (dby != 0.0f && dbx != 0.0f)
+ dbx = (dbx/1000.0f) + ((dbx > 0.0f) ? +1.0f : -1.0f);
+ float dist_box = ImFabs(dbx) + ImFabs(dby);
-// Scale all windows (position, size). Use when e.g. changing DPI. (This is a lossy operation!)
-void ImGui::ScaleWindowsInViewport(ImGuiViewportP* viewport, float scale)
-{
- ImGuiContext& g = *GImGui;
- if (viewport->Window)
+ // Compute distance between centers (this is off by a factor of 2, but we only compare center distances with each other so it doesn't matter)
+ float dcx = (cand.Min.x + cand.Max.x) - (curr.Min.x + curr.Max.x);
+ float dcy = (cand.Min.y + cand.Max.y) - (curr.Min.y + curr.Max.y);
+ float dist_center = ImFabs(dcx) + ImFabs(dcy); // L1 metric (need this for our connectedness guarantee)
+
+ // Determine which quadrant of 'curr' our candidate item 'cand' lies in based on distance
+ ImGuiDir quadrant;
+ float dax = 0.0f, day = 0.0f, dist_axial = 0.0f;
+ if (dbx != 0.0f || dby != 0.0f)
{
- ScaleWindow(viewport->Window, scale);
+ // For non-overlapping boxes, use distance between boxes
+ dax = dbx;
+ day = dby;
+ dist_axial = dist_box;
+ quadrant = ImGetDirQuadrantFromDelta(dbx, dby);
+ }
+ else if (dcx != 0.0f || dcy != 0.0f)
+ {
+ // For overlapping boxes with different centers, use distance between centers
+ dax = dcx;
+ day = dcy;
+ dist_axial = dist_center;
+ quadrant = ImGetDirQuadrantFromDelta(dcx, dcy);
}
else
{
- for (int i = 0; i != g.Windows.Size; i++)
- if (g.Windows[i]->Viewport == viewport)
- ScaleWindow(g.Windows[i], scale);
+ // Degenerate case: two overlapping buttons with same center, break ties arbitrarily (note that LastItemId here is really the _previous_ item order, but it doesn't matter)
+ quadrant = (window->DC.LastItemId < g.NavId) ? ImGuiDir_Left : ImGuiDir_Right;
}
-}
-// If the back-end doesn't set MouseLastHoveredViewport or doesn't honor ImGuiViewportFlags_NoInputs, we do a search ourselves.
-// A) It won't take account of the possibility that non-imgui windows may be in-between our dragged window and our target window.
-// B) It requires Platform_GetWindowFocus to be implemented by back-end.
-static ImGuiViewportP* FindViewportHoveredFromPlatformWindowStack(const ImVec2 mouse_platform_pos)
-{
- ImGuiContext& g = *GImGui;
- ImGuiViewportP* best_candidate = NULL;
- for (int n = 0; n < g.Viewports.Size; n++)
+#if IMGUI_DEBUG_NAV_SCORING
+ char buf[128];
+ if (ImGui::IsMouseHoveringRect(cand.Min, cand.Max))
{
- ImGuiViewportP* viewport = g.Viewports[n];
- if (!(viewport->Flags & ImGuiViewportFlags_NoInputs) && !viewport->PlatformWindowMinimized && viewport->GetRect().Contains(mouse_platform_pos))
- if (best_candidate == NULL || best_candidate->LastFrontMostStampCount < viewport->LastFrontMostStampCount)
- best_candidate = viewport;
+ ImFormatString(buf, IM_ARRAYSIZE(buf), "dbox (%.2f,%.2f->%.4f)\ndcen (%.2f,%.2f->%.4f)\nd (%.2f,%.2f->%.4f)\nnav %c, quadrant %c", dbx, dby, dist_box, dcx, dcy, dist_center, dax, day, dist_axial, "WENS"[g.NavMoveDir], "WENS"[quadrant]);
+ ImDrawList* draw_list = ImGui::GetForegroundDrawList(window);
+ draw_list->AddRect(curr.Min, curr.Max, IM_COL32(255,200,0,100));
+ draw_list->AddRect(cand.Min, cand.Max, IM_COL32(255,255,0,200));
+ draw_list->AddRectFilled(cand.Max-ImVec2(4,4), cand.Max+ImGui::CalcTextSize(buf)+ImVec2(4,4), IM_COL32(40,0,0,150));
+ draw_list->AddText(g.IO.FontDefault, 13.0f, cand.Max, ~0U, buf);
}
- return best_candidate;
-}
-
-static void ImGui::UpdateViewportsNewFrame()
-{
- ImGuiContext& g = *GImGui;
- IM_ASSERT(g.PlatformIO.Viewports.Size <= g.Viewports.Size);
-
- // Update Minimized status (we need it first in order to decide if we'll apply Pos/Size of the main viewport)
- for (int n = 0; n < g.Viewports.Size; n++)
+ else if (g.IO.KeyCtrl) // Hold to preview score in matching quadrant. Press C to rotate.
{
- ImGuiViewportP* viewport = g.Viewports[n];
- const bool platform_funcs_available = (n == 0 || viewport->PlatformWindowCreated);
- if ((g.ConfigFlagsForFrame & ImGuiConfigFlags_ViewportsEnable))
- if (g.PlatformIO.Platform_GetWindowMinimized && platform_funcs_available)
- viewport->PlatformWindowMinimized = g.PlatformIO.Platform_GetWindowMinimized(viewport);
+ if (ImGui::IsKeyPressedMap(ImGuiKey_C)) { g.NavMoveDirLast = (ImGuiDir)((g.NavMoveDirLast + 1) & 3); g.IO.KeysDownDuration[g.IO.KeyMap[ImGuiKey_C]] = 0.01f; }
+ if (quadrant == g.NavMoveDir)
+ {
+ ImFormatString(buf, IM_ARRAYSIZE(buf), "%.0f/%.0f", dist_box, dist_center);
+ ImDrawList* draw_list = ImGui::GetForegroundDrawList(window);
+ draw_list->AddRectFilled(cand.Min, cand.Max, IM_COL32(255, 0, 0, 200));
+ draw_list->AddText(g.IO.FontDefault, 13.0f, cand.Min, IM_COL32(255, 255, 255, 255), buf);
+ }
}
+ #endif
- // Create/update main viewport with current platform position and size
- ImGuiViewportP* main_viewport = g.Viewports[0];
- IM_ASSERT(main_viewport->ID == IMGUI_VIEWPORT_DEFAULT_ID);
- IM_ASSERT(main_viewport->Window == NULL);
- ImVec2 main_viewport_platform_pos = ImVec2(0.0f, 0.0f);
- ImVec2 main_viewport_platform_size = g.IO.DisplaySize;
- if (g.ConfigFlagsForFrame & ImGuiConfigFlags_ViewportsEnable)
- main_viewport_platform_pos = main_viewport->PlatformWindowMinimized ? main_viewport->Pos : g.PlatformIO.Platform_GetWindowPos(main_viewport);
- AddUpdateViewport(NULL, IMGUI_VIEWPORT_DEFAULT_ID, main_viewport_platform_pos, main_viewport_platform_size, ImGuiViewportFlags_CanHostOtherWindows);
-
- g.CurrentViewport = NULL;
- g.MouseViewport = NULL;
- for (int n = 0; n < g.Viewports.Size; n++)
+ // Is it in the quadrant we're interesting in moving to?
+ bool new_best = false;
+ if (quadrant == g.NavMoveDir)
{
- // Erase unused viewports
- ImGuiViewportP* viewport = g.Viewports[n];
- viewport->Idx = n;
-
- if (n > 0 && viewport->LastFrameActive < g.FrameCount - 2)
+ // Does it beat the current best candidate?
+ if (dist_box < result->DistBox)
{
- // Clear references to this viewport in windows (window->ViewportId becomes the master data)
- for (int window_n = 0; window_n < g.Windows.Size; window_n++)
- if (g.Windows[window_n]->Viewport == viewport)
- {
- g.Windows[window_n]->Viewport = NULL;
- g.Windows[window_n]->ViewportOwned = false;
- }
- if (viewport == g.MouseLastHoveredViewport)
- g.MouseLastHoveredViewport = NULL;
- g.Viewports.erase(g.Viewports.Data + n);
-
- // Destroy
- //IMGUI_DEBUG_LOG("Delete Viewport %08X (%s)\n", viewport->ID, viewport->Window ? viewport->Window->Name : "n/a");
- DestroyPlatformWindow(viewport); // In most circumstances the platform window will already be destroyed here.
- IM_ASSERT(g.PlatformIO.Viewports.contains(viewport) == false);
- IM_DELETE(viewport);
- n--;
- continue;
+ result->DistBox = dist_box;
+ result->DistCenter = dist_center;
+ return true;
}
-
- const bool platform_funcs_available = (n == 0 || viewport->PlatformWindowCreated);
- if ((g.ConfigFlagsForFrame & ImGuiConfigFlags_ViewportsEnable))
+ if (dist_box == result->DistBox)
{
- // Update Position and Size (from Platform Window to ImGui) if requested.
- // We do it early in the frame instead of waiting for UpdatePlatformWindows() to avoid a frame of lag when moving/resizing using OS facilities.
- if (!viewport->PlatformWindowMinimized && platform_funcs_available)
+ // Try using distance between center points to break ties
+ if (dist_center < result->DistCenter)
{
- if (viewport->PlatformRequestMove)
- viewport->Pos = viewport->LastPlatformPos = g.PlatformIO.Platform_GetWindowPos(viewport);
- if (viewport->PlatformRequestResize)
- viewport->Size = viewport->LastPlatformSize = g.PlatformIO.Platform_GetWindowSize(viewport);
+ result->DistCenter = dist_center;
+ new_best = true;
}
+ else if (dist_center == result->DistCenter)
+ {
+ // Still tied! we need to be extra-careful to make sure everything gets linked properly. We consistently break ties by symbolically moving "later" items
+ // (with higher index) to the right/downwards by an infinitesimal amount since we the current "best" button already (so it must have a lower index),
+ // this is fairly easy. This rule ensures that all buttons with dx==dy==0 will end up being linked in order of appearance along the x axis.
+ if (((g.NavMoveDir == ImGuiDir_Up || g.NavMoveDir == ImGuiDir_Down) ? dby : dbx) < 0.0f) // moving bj to the right/down decreases distance
+ new_best = true;
+ }
+ }
+ }
- // Update monitor (we'll use this info to clamp windows and save windows lost in a removed monitor)
- viewport->PlatformMonitor = (short)FindPlatformMonitorForRect(viewport->GetRect());
- }
-
- // Reset alpha every frame. Users of transparency (docking) needs to request a lower alpha back.
- viewport->Alpha = 1.0f;
-
- // Translate imgui windows when a Host Viewport has been moved
- // (This additionally keeps windows at the same place when ImGuiConfigFlags_ViewportsEnable is toggled!)
- ImVec2 viewport_delta = viewport->Pos - viewport->LastPos;
- if ((viewport->Flags & ImGuiViewportFlags_CanHostOtherWindows) && (viewport_delta.x != 0.0f || viewport_delta.y != 0.0f))
- for (int window_n = 0; window_n < g.Windows.Size; window_n++)
- if (g.Windows[window_n]->Viewport == viewport || (g.ConfigFlagsForFrame & ImGuiConfigFlags_ViewportsEnable) == 0)
- TranslateWindow(g.Windows[window_n], viewport_delta);
+ // Axial check: if 'curr' has no link at all in some direction and 'cand' lies roughly in that direction, add a tentative link. This will only be kept if no "real" matches
+ // are found, so it only augments the graph produced by the above method using extra links. (important, since it doesn't guarantee strong connectedness)
+ // This is just to avoid buttons having no links in a particular direction when there's a suitable neighbor. you get good graphs without this too.
+ // 2017/09/29: FIXME: This now currently only enabled inside menu bars, ideally we'd disable it everywhere. Menus in particular need to catch failure. For general navigation it feels awkward.
+ // Disabling it may lead to disconnected graphs when nodes are very spaced out on different axis. Perhaps consider offering this as an option?
+ if (result->DistBox == FLT_MAX && dist_axial < result->DistAxial) // Check axial match
+ if (g.NavLayer == 1 && !(g.NavWindow->Flags & ImGuiWindowFlags_ChildMenu))
+ if ((g.NavMoveDir == ImGuiDir_Left && dax < 0.0f) || (g.NavMoveDir == ImGuiDir_Right && dax > 0.0f) || (g.NavMoveDir == ImGuiDir_Up && day < 0.0f) || (g.NavMoveDir == ImGuiDir_Down && day > 0.0f))
+ {
+ result->DistAxial = dist_axial;
+ new_best = true;
+ }
- // Update DPI scale
- float new_dpi_scale;
- if (g.PlatformIO.Platform_GetWindowDpiScale && platform_funcs_available)
- new_dpi_scale = g.PlatformIO.Platform_GetWindowDpiScale(viewport);
- else if (viewport->PlatformMonitor != -1)
- new_dpi_scale = g.PlatformIO.Monitors[viewport->PlatformMonitor].DpiScale;
- else
- new_dpi_scale = (viewport->DpiScale != 0.0f) ? viewport->DpiScale : 1.0f;
- if (viewport->DpiScale != 0.0f && new_dpi_scale != viewport->DpiScale)
- {
- float scale_factor = new_dpi_scale / viewport->DpiScale;
- if (g.IO.ConfigFlags & ImGuiConfigFlags_DpiEnableScaleViewports)
- ScaleWindowsInViewport(viewport, scale_factor);
- //if (viewport == GetMainViewport())
- // g.PlatformInterface.SetWindowSize(viewport, viewport->Size * scale_factor);
+ return new_best;
+}
- // Scale our window moving pivot so that the window will rescale roughly around the mouse position.
- // FIXME-VIEWPORT: This currently creates a resizing feedback loop when a window is straddling a DPI transition border.
- // (Minor: since our sizes do not perfectly linearly scale, deferring the click offset scale until we know the actual window scale ratio may get us slightly more precise mouse positioning.)
- //if (g.MovingWindow != NULL && g.MovingWindow->Viewport == viewport)
- // g.ActiveIdClickOffset = ImFloor(g.ActiveIdClickOffset * scale_factor);
- }
- viewport->DpiScale = new_dpi_scale;
- }
+// We get there when either NavId == id, or when g.NavAnyRequest is set (which is updated by NavUpdateAnyRequestFlag above)
+static void ImGui::NavProcessItem(ImGuiWindow* window, const ImRect& nav_bb, const ImGuiID id)
+{
+ ImGuiContext& g = *GImGui;
+ //if (!g.IO.NavActive) // [2017/10/06] Removed this possibly redundant test but I am not sure of all the side-effects yet. Some of the feature here will need to work regardless of using a _NoNavInputs flag.
+ // return;
+
+ const ImGuiItemFlags item_flags = window->DC.ItemFlags;
+ const ImRect nav_bb_rel(nav_bb.Min - window->Pos, nav_bb.Max - window->Pos);
- if (!(g.ConfigFlagsForFrame & ImGuiConfigFlags_ViewportsEnable))
+ // Process Init Request
+ if (g.NavInitRequest && g.NavLayer == window->DC.NavLayerCurrent)
{
- g.MouseViewport = main_viewport;
- return;
+ // Even if 'ImGuiItemFlags_NoNavDefaultFocus' is on (typically collapse/close button) we record the first ResultId so they can be used as a fallback
+ if (!(item_flags & ImGuiItemFlags_NoNavDefaultFocus) || g.NavInitResultId == 0)
+ {
+ g.NavInitResultId = id;
+ g.NavInitResultRectRel = nav_bb_rel;
+ }
+ if (!(item_flags & ImGuiItemFlags_NoNavDefaultFocus))
+ {
+ g.NavInitRequest = false; // Found a match, clear request
+ NavUpdateAnyRequestFlag();
+ }
}
- // Mouse handling: decide on the actual mouse viewport for this frame between the active/focused viewport and the hovered viewport.
- // Note that 'viewport_hovered' should skip over any viewport that has the ImGuiViewportFlags_NoInputs flags set.
- ImGuiViewportP* viewport_hovered = NULL;
- if (g.IO.BackendFlags & ImGuiBackendFlags_HasMouseHoveredViewport)
+ // Process Move Request (scoring for navigation)
+ // FIXME-NAV: Consider policy for double scoring (scoring from NavScoringRectScreen + scoring from a rect wrapped according to current wrapping policy)
+ if ((g.NavId != id || (g.NavMoveRequestFlags & ImGuiNavMoveFlags_AllowCurrentNavId)) && !(item_flags & (ImGuiItemFlags_Disabled|ImGuiItemFlags_NoNav)))
{
- viewport_hovered = g.IO.MouseHoveredViewport ? (ImGuiViewportP*)FindViewportByID(g.IO.MouseHoveredViewport) : NULL;
- if (viewport_hovered && (viewport_hovered->Flags & ImGuiViewportFlags_NoInputs))
+ ImGuiNavMoveResult* result = (window == g.NavWindow) ? &g.NavMoveResultLocal : &g.NavMoveResultOther;
+#if IMGUI_DEBUG_NAV_SCORING
+ // [DEBUG] Score all items in NavWindow at all times
+ if (!g.NavMoveRequest)
+ g.NavMoveDir = g.NavMoveDirLast;
+ bool new_best = NavScoreItem(result, nav_bb) && g.NavMoveRequest;
+#else
+ bool new_best = g.NavMoveRequest && NavScoreItem(result, nav_bb);
+#endif
+ if (new_best)
{
- // Back-end failed at honoring its contract if it returned a viewport with the _NoInputs flag.
- IM_ASSERT(0);
- viewport_hovered = FindViewportHoveredFromPlatformWindowStack(g.IO.MousePos);
+ result->ID = id;
+ result->SelectScopeId = g.MultiSelectScopeId;
+ result->Window = window;
+ result->RectRel = nav_bb_rel;
}
+
+ const float VISIBLE_RATIO = 0.70f;
+ if ((g.NavMoveRequestFlags & ImGuiNavMoveFlags_AlsoScoreVisibleSet) && window->ClipRect.Overlaps(nav_bb))
+ if (ImClamp(nav_bb.Max.y, window->ClipRect.Min.y, window->ClipRect.Max.y) - ImClamp(nav_bb.Min.y, window->ClipRect.Min.y, window->ClipRect.Max.y) >= (nav_bb.Max.y - nav_bb.Min.y) * VISIBLE_RATIO)
+ if (NavScoreItem(&g.NavMoveResultLocalVisibleSet, nav_bb))
+ {
+ result = &g.NavMoveResultLocalVisibleSet;
+ result->ID = id;
+ result->SelectScopeId = g.MultiSelectScopeId;
+ result->Window = window;
+ result->RectRel = nav_bb_rel;
+ }
}
- else
+
+ // Update window-relative bounding box of navigated item
+ if (g.NavId == id)
{
- // If the back-end doesn't know how to honor ImGuiViewportFlags_NoInputs, we do a search ourselves. Note that this search:
- // A) won't take account of the possibility that non-imgui windows may be in-between our dragged window and our target window.
- // B) uses LastFrameAsRefViewport as a flawed replacement for the last time a window was focused (we could/should fix that by introducing Focus functions in PlatformIO)
- viewport_hovered = FindViewportHoveredFromPlatformWindowStack(g.IO.MousePos);
+ g.NavWindow = window; // Always refresh g.NavWindow, because some operations such as FocusItem() don't have a window.
+ g.NavLayer = window->DC.NavLayerCurrent;
+ g.NavIdIsAlive = true;
+ g.NavIdTabCounter = window->DC.FocusCounterTab;
+ window->NavRectRel[window->DC.NavLayerCurrent] = nav_bb_rel; // Store item bounding box (relative to window position)
}
- if (viewport_hovered != NULL)
- g.MouseLastHoveredViewport = viewport_hovered;
- else if (g.MouseLastHoveredViewport == NULL)
- g.MouseLastHoveredViewport = g.Viewports[0];
-
- // Update mouse reference viewport
- // (when moving a window we aim at its viewport, but this will be overwritten below if we go in drag and drop mode)
- if (g.MovingWindow)
- g.MouseViewport = g.MovingWindow->Viewport;
- else
- g.MouseViewport = g.MouseLastHoveredViewport;
+}
- // When dragging something, always refer to the last hovered viewport.
- // - when releasing a moving window we will revert to aiming behind (at viewport_hovered)
- // - when we are between viewports, our dragged preview will tend to show in the last viewport _even_ if we don't have tooltips in their viewports (when lacking monitor info)
- // - consider the case of holding on a menu item to browse child menus: even thou a mouse button is held, there's no active id because menu items only react on mouse release.
- const bool is_mouse_dragging_with_an_expected_destination = g.DragDropActive;
- if (is_mouse_dragging_with_an_expected_destination && viewport_hovered == NULL)
- viewport_hovered = g.MouseLastHoveredViewport;
- if (is_mouse_dragging_with_an_expected_destination || g.ActiveId == 0 || !IsAnyMouseDown())
- if (viewport_hovered != NULL && viewport_hovered != g.MouseViewport && !(viewport_hovered->Flags & ImGuiViewportFlags_NoInputs))
- g.MouseViewport = viewport_hovered;
+bool ImGui::NavMoveRequestButNoResultYet()
+{
+ ImGuiContext& g = *GImGui;
+ return g.NavMoveRequest && g.NavMoveResultLocal.ID == 0 && g.NavMoveResultOther.ID == 0;
+}
- IM_ASSERT(g.MouseViewport != NULL);
+void ImGui::NavMoveRequestCancel()
+{
+ ImGuiContext& g = *GImGui;
+ g.NavMoveRequest = false;
+ NavUpdateAnyRequestFlag();
}
-// Update user-facing viewport list (g.Viewports -> g.PlatformIO.Viewports after filtering out some)
-static void ImGui::UpdateViewportsEndFrame()
+void ImGui::NavMoveRequestForward(ImGuiDir move_dir, ImGuiDir clip_dir, const ImRect& bb_rel, ImGuiNavMoveFlags move_flags)
{
ImGuiContext& g = *GImGui;
- g.PlatformIO.MainViewport = g.Viewports[0];
- g.PlatformIO.Viewports.resize(0);
- for (int i = 0; i < g.Viewports.Size; i++)
- {
- ImGuiViewportP* viewport = g.Viewports[i];
- viewport->LastPos = viewport->Pos;
- if (viewport->LastFrameActive < g.FrameCount || viewport->Size.x <= 0.0f || viewport->Size.y <= 0.0f)
- if (i > 0) // Always include main viewport in the list
- continue;
- if (viewport->Window && !IsWindowActiveAndVisible(viewport->Window))
- continue;
- if (i > 0)
- IM_ASSERT(viewport->Window != NULL);
- g.PlatformIO.Viewports.push_back(viewport);
- }
- g.Viewports[0]->ClearRequestFlags(); // Clear main viewport flags because UpdatePlatformWindows() won't do it and may not even be called
+ IM_ASSERT(g.NavMoveRequestForward == ImGuiNavForward_None);
+ ImGui::NavMoveRequestCancel();
+ g.NavMoveDir = move_dir;
+ g.NavMoveClipDir = clip_dir;
+ g.NavMoveRequestForward = ImGuiNavForward_ForwardQueued;
+ g.NavMoveRequestFlags = move_flags;
+ g.NavWindow->NavRectRel[g.NavLayer] = bb_rel;
}
-// FIXME: We should ideally refactor the system to call this every frame (we currently don't)
-ImGuiViewportP* ImGui::AddUpdateViewport(ImGuiWindow* window, ImGuiID id, const ImVec2& pos, const ImVec2& size, ImGuiViewportFlags flags)
+void ImGui::NavMoveRequestTryWrapping(ImGuiWindow* window, ImGuiNavMoveFlags move_flags)
{
ImGuiContext& g = *GImGui;
- IM_ASSERT(id != 0);
+ if (g.NavWindow != window || !NavMoveRequestButNoResultYet() || g.NavMoveRequestForward != ImGuiNavForward_None || g.NavLayer != 0)
+ return;
+ IM_ASSERT(move_flags != 0); // No points calling this with no wrapping
+ ImRect bb_rel = window->NavRectRel[0];
- if (window != NULL)
+ ImGuiDir clip_dir = g.NavMoveDir;
+ if (g.NavMoveDir == ImGuiDir_Left && (move_flags & (ImGuiNavMoveFlags_WrapX | ImGuiNavMoveFlags_LoopX)))
{
- if (g.MovingWindow && g.MovingWindow->RootWindow == window)
- flags |= ImGuiViewportFlags_NoInputs | ImGuiViewportFlags_NoFocusOnAppearing;
- if ((window->Flags & ImGuiWindowFlags_NoMouseInputs) && (window->Flags & ImGuiWindowFlags_NoNavInputs))
- flags |= ImGuiViewportFlags_NoInputs;
- if (window->Flags & ImGuiWindowFlags_NoFocusOnAppearing)
- flags |= ImGuiViewportFlags_NoFocusOnAppearing;
+ bb_rel.Min.x = bb_rel.Max.x = ImMax(window->SizeFull.x, window->ContentSize.x + window->WindowPadding.x * 2.0f) - window->Scroll.x;
+ if (move_flags & ImGuiNavMoveFlags_WrapX) { bb_rel.TranslateY(-bb_rel.GetHeight()); clip_dir = ImGuiDir_Up; }
+ NavMoveRequestForward(g.NavMoveDir, clip_dir, bb_rel, move_flags);
}
-
- ImGuiViewportP* viewport = (ImGuiViewportP*)FindViewportByID(id);
- if (viewport)
+ if (g.NavMoveDir == ImGuiDir_Right && (move_flags & (ImGuiNavMoveFlags_WrapX | ImGuiNavMoveFlags_LoopX)))
{
- if (!viewport->PlatformRequestMove)
- viewport->Pos = pos;
- if (!viewport->PlatformRequestResize)
- viewport->Size = size;
+ bb_rel.Min.x = bb_rel.Max.x = -window->Scroll.x;
+ if (move_flags & ImGuiNavMoveFlags_WrapX) { bb_rel.TranslateY(+bb_rel.GetHeight()); clip_dir = ImGuiDir_Down; }
+ NavMoveRequestForward(g.NavMoveDir, clip_dir, bb_rel, move_flags);
}
- else
+ if (g.NavMoveDir == ImGuiDir_Up && (move_flags & (ImGuiNavMoveFlags_WrapY | ImGuiNavMoveFlags_LoopY)))
{
- // New viewport
- viewport = IM_NEW(ImGuiViewportP)();
- viewport->ID = id;
- viewport->Idx = g.Viewports.Size;
- viewport->Pos = viewport->LastPos = pos;
- viewport->Size = size;
- viewport->PlatformMonitor = (short)FindPlatformMonitorForRect(viewport->GetRect());
- g.Viewports.push_back(viewport);
- //IMGUI_DEBUG_LOG("Add Viewport %08X (%s)\n", id, window->Name);
-
- // We normally setup for all viewports in NewFrame() but here need to handle the mid-frame creation of a new viewport.
- // We need to extend the fullscreen clip rect so the OverlayDrawList clip is correct for that the first frame
- g.DrawListSharedData.ClipRectFullscreen.z = ImMax(g.DrawListSharedData.ClipRectFullscreen.z, viewport->Pos.x + viewport->Size.x);
- g.DrawListSharedData.ClipRectFullscreen.w = ImMax(g.DrawListSharedData.ClipRectFullscreen.w, viewport->Pos.y + viewport->Size.y);
-
- // Store initial DpiScale before the OS platform window creation, based on expected monitor data.
- // This is so we can select an appropriate font size on the first frame of our window lifetime
- if (viewport->PlatformMonitor != -1)
- viewport->DpiScale = g.PlatformIO.Monitors[viewport->PlatformMonitor].DpiScale;
+ bb_rel.Min.y = bb_rel.Max.y = ImMax(window->SizeFull.y, window->ContentSize.y + window->WindowPadding.y * 2.0f) - window->Scroll.y;
+ if (move_flags & ImGuiNavMoveFlags_WrapY) { bb_rel.TranslateX(-bb_rel.GetWidth()); clip_dir = ImGuiDir_Left; }
+ NavMoveRequestForward(g.NavMoveDir, clip_dir, bb_rel, move_flags);
+ }
+ if (g.NavMoveDir == ImGuiDir_Down && (move_flags & (ImGuiNavMoveFlags_WrapY | ImGuiNavMoveFlags_LoopY)))
+ {
+ bb_rel.Min.y = bb_rel.Max.y = -window->Scroll.y;
+ if (move_flags & ImGuiNavMoveFlags_WrapY) { bb_rel.TranslateX(+bb_rel.GetWidth()); clip_dir = ImGuiDir_Right; }
+ NavMoveRequestForward(g.NavMoveDir, clip_dir, bb_rel, move_flags);
}
-
- viewport->Window = window;
- viewport->Flags = flags;
- viewport->LastFrameActive = g.FrameCount;
- IM_ASSERT(window == NULL || viewport->ID == window->ID);
-
- if (window != NULL)
- window->ViewportOwned = true;
-
- return viewport;
}
-// FIXME-VIEWPORT: This is all super messy and ought to be clarified or rewritten.
-static void ImGui::UpdateSelectWindowViewport(ImGuiWindow* window)
+// FIXME: This could be replaced by updating a frame number in each window when (window == NavWindow) and (NavLayer == 0).
+// This way we could find the last focused window among our children. It would be much less confusing this way?
+static void ImGui::NavSaveLastChildNavWindowIntoParent(ImGuiWindow* nav_window)
{
- ImGuiContext& g = *GImGui;
- ImGuiWindowFlags flags = window->Flags;
- window->ViewportAllowPlatformMonitorExtend = -1;
+ ImGuiWindow* parent_window = nav_window;
+ while (parent_window && (parent_window->Flags & ImGuiWindowFlags_ChildWindow) != 0 && (parent_window->Flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_ChildMenu)) == 0)
+ parent_window = parent_window->ParentWindow;
+ if (parent_window && parent_window != nav_window)
+ parent_window->NavLastChildNavWindow = nav_window;
+}
- // Restore main viewport if multi-viewport is not supported by the back-end
- ImGuiViewportP* main_viewport = g.Viewports[0];
- if (!(g.ConfigFlagsForFrame & ImGuiConfigFlags_ViewportsEnable))
- {
- SetWindowViewport(window, main_viewport);
- return;
- }
-
- window->ViewportOwned = false;
-
- // Appearing popups reset their viewport so they can inherit again
- if ((flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_Tooltip)) && window->Appearing)
- {
- window->Viewport = NULL;
- window->ViewportId = 0;
- }
+// Restore the last focused child.
+// Call when we are expected to land on the Main Layer (0) after FocusWindow()
+static ImGuiWindow* ImGui::NavRestoreLastChildNavWindow(ImGuiWindow* window)
+{
+ if (window->NavLastChildNavWindow && window->NavLastChildNavWindow->WasActive)
+ return window->NavLastChildNavWindow;
+ if (window->DockNodeAsHost && window->DockNodeAsHost->TabBar)
+ if (ImGuiTabItem* tab = TabBarFindMostRecentlySelectedTabForActiveWindow(window->DockNodeAsHost->TabBar))
+ return tab->Window;
+ return window;
+}
- if (!g.NextWindowData.ViewportCond)
- {
- // By default inherit from parent window
- if (window->Viewport == NULL && window->ParentWindow)
- window->Viewport = window->ParentWindow->Viewport;
+static void NavRestoreLayer(ImGuiNavLayer layer)
+{
+ ImGuiContext& g = *GImGui;
+ g.NavLayer = layer;
+ if (layer == 0)
+ g.NavWindow = ImGui::NavRestoreLastChildNavWindow(g.NavWindow);
+ if (g.NavWindow->NavLastIds[layer] != 0)
+ ImGui::SetNavIDWithRectRel(g.NavWindow->NavLastIds[layer], layer, g.NavWindow->NavRectRel[layer]);
+ else
+ ImGui::NavInitWindow(g.NavWindow, true);
+}
- // Attempt to restore saved viewport id (= window that hasn't been activated yet), try to restore the viewport based on saved 'window->ViewportPos' restored from .ini file
- if (window->Viewport == NULL && window->ViewportId != 0)
- {
- window->Viewport = (ImGuiViewportP*)FindViewportByID(window->ViewportId);
- if (window->Viewport == NULL && window->ViewportPos.x != FLT_MAX && window->ViewportPos.y != FLT_MAX)
- window->Viewport = AddUpdateViewport(window, window->ID, window->ViewportPos, window->Size, ImGuiViewportFlags_None);
- }
- }
+static inline void ImGui::NavUpdateAnyRequestFlag()
+{
+ ImGuiContext& g = *GImGui;
+ g.NavAnyRequest = g.NavMoveRequest || g.NavInitRequest || (IMGUI_DEBUG_NAV_SCORING && g.NavWindow != NULL);
+ if (g.NavAnyRequest)
+ IM_ASSERT(g.NavWindow != NULL);
+}
- if (g.NextWindowData.ViewportCond)
+// This needs to be called before we submit any widget (aka in or before Begin)
+void ImGui::NavInitWindow(ImGuiWindow* window, bool force_reinit)
+{
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(window == g.NavWindow);
+ bool init_for_nav = false;
+ if (!(window->Flags & ImGuiWindowFlags_NoNavInputs))
+ if (!(window->Flags & ImGuiWindowFlags_ChildWindow) || (window->Flags & ImGuiWindowFlags_Popup) || (window->NavLastIds[0] == 0) || force_reinit)
+ init_for_nav = true;
+ if (init_for_nav)
{
- // Code explicitly request a viewport
- window->Viewport = (ImGuiViewportP*)FindViewportByID(g.NextWindowData.ViewportId);
- window->ViewportId = g.NextWindowData.ViewportId; // Store ID even if Viewport isn't resolved yet.
+ SetNavID(0, g.NavLayer);
+ g.NavInitRequest = true;
+ g.NavInitRequestFromMove = false;
+ g.NavInitResultId = 0;
+ g.NavInitResultRectRel = ImRect();
+ NavUpdateAnyRequestFlag();
}
- else if ((flags & ImGuiWindowFlags_ChildWindow) || (flags & ImGuiWindowFlags_ChildMenu))
+ else
{
- // Always inherit viewport from parent window
- window->Viewport = window->ParentWindow->Viewport;
+ g.NavId = window->NavLastIds[0];
}
- else if (flags & ImGuiWindowFlags_Tooltip)
+}
+
+static ImVec2 ImGui::NavCalcPreferredRefPos()
+{
+ ImGuiContext& g = *GImGui;
+ if (g.NavDisableHighlight || !g.NavDisableMouseHover || !g.NavWindow)
{
- window->Viewport = g.MouseViewport;
+ // Mouse (we need a fallback in case the mouse becomes invalid after being used)
+ if (IsMousePosValid(&g.IO.MousePos))
+ return g.IO.MousePos;
+ return g.LastValidMousePos;
}
- else if (GetWindowAlwaysWantOwnViewport(window))
+ else
{
- window->Viewport = AddUpdateViewport(window, window->ID, window->Pos, window->Size, ImGuiViewportFlags_None);
+ // When navigation is active and mouse is disabled, decide on an arbitrary position around the bottom left of the currently navigated item.
+ const ImRect& rect_rel = g.NavWindow->NavRectRel[g.NavLayer];
+ ImVec2 pos = g.NavWindow->Pos + ImVec2(rect_rel.Min.x + ImMin(g.Style.FramePadding.x * 4, rect_rel.GetWidth()), rect_rel.Max.y - ImMin(g.Style.FramePadding.y, rect_rel.GetHeight()));
+ ImRect visible_rect = g.NavWindow->Viewport->GetRect();
+ return ImFloor(ImClamp(pos, visible_rect.Min, visible_rect.Max)); // ImFloor() is important because non-integer mouse position application in back-end might be lossy and result in undesirable non-zero delta.
}
- else if (g.MovingWindow && g.MovingWindow->RootWindow == window && IsMousePosValid())
+}
+
+float ImGui::GetNavInputAmount(ImGuiNavInput n, ImGuiInputReadMode mode)
+{
+ ImGuiContext& g = *GImGui;
+ if (mode == ImGuiInputReadMode_Down)
+ return g.IO.NavInputs[n]; // Instant, read analog input (0.0f..1.0f, as provided by user)
+
+ const float t = g.IO.NavInputsDownDuration[n];
+ if (t < 0.0f && mode == ImGuiInputReadMode_Released) // Return 1.0f when just released, no repeat, ignore analog input.
+ return (g.IO.NavInputsDownDurationPrev[n] >= 0.0f ? 1.0f : 0.0f);
+ if (t < 0.0f)
+ return 0.0f;
+ if (mode == ImGuiInputReadMode_Pressed) // Return 1.0f when just pressed, no repeat, ignore analog input.
+ return (t == 0.0f) ? 1.0f : 0.0f;
+ if (mode == ImGuiInputReadMode_Repeat)
+ return (float)CalcTypematicPressedRepeatAmount(t, t - g.IO.DeltaTime, g.IO.KeyRepeatDelay * 0.80f, g.IO.KeyRepeatRate * 0.80f);
+ if (mode == ImGuiInputReadMode_RepeatSlow)
+ return (float)CalcTypematicPressedRepeatAmount(t, t - g.IO.DeltaTime, g.IO.KeyRepeatDelay * 1.00f, g.IO.KeyRepeatRate * 2.00f);
+ if (mode == ImGuiInputReadMode_RepeatFast)
+ return (float)CalcTypematicPressedRepeatAmount(t, t - g.IO.DeltaTime, g.IO.KeyRepeatDelay * 0.80f, g.IO.KeyRepeatRate * 0.30f);
+ return 0.0f;
+}
+
+ImVec2 ImGui::GetNavInputAmount2d(ImGuiNavDirSourceFlags dir_sources, ImGuiInputReadMode mode, float slow_factor, float fast_factor)
+{
+ ImVec2 delta(0.0f, 0.0f);
+ if (dir_sources & ImGuiNavDirSourceFlags_Keyboard)
+ delta += ImVec2(GetNavInputAmount(ImGuiNavInput_KeyRight_, mode) - GetNavInputAmount(ImGuiNavInput_KeyLeft_, mode), GetNavInputAmount(ImGuiNavInput_KeyDown_, mode) - GetNavInputAmount(ImGuiNavInput_KeyUp_, mode));
+ if (dir_sources & ImGuiNavDirSourceFlags_PadDPad)
+ delta += ImVec2(GetNavInputAmount(ImGuiNavInput_DpadRight, mode) - GetNavInputAmount(ImGuiNavInput_DpadLeft, mode), GetNavInputAmount(ImGuiNavInput_DpadDown, mode) - GetNavInputAmount(ImGuiNavInput_DpadUp, mode));
+ if (dir_sources & ImGuiNavDirSourceFlags_PadLStick)
+ delta += ImVec2(GetNavInputAmount(ImGuiNavInput_LStickRight, mode) - GetNavInputAmount(ImGuiNavInput_LStickLeft, mode), GetNavInputAmount(ImGuiNavInput_LStickDown, mode) - GetNavInputAmount(ImGuiNavInput_LStickUp, mode));
+ if (slow_factor != 0.0f && IsNavInputDown(ImGuiNavInput_TweakSlow))
+ delta *= slow_factor;
+ if (fast_factor != 0.0f && IsNavInputDown(ImGuiNavInput_TweakFast))
+ delta *= fast_factor;
+ return delta;
+}
+
+static void ImGui::NavUpdate()
+{
+ ImGuiContext& g = *GImGui;
+ g.IO.WantSetMousePos = false;
+#if 0
+ if (g.NavScoringCount > 0) IMGUI_DEBUG_LOG("NavScoringCount %d for '%s' layer %d (Init:%d, Move:%d)\n", g.FrameCount, g.NavScoringCount, g.NavWindow ? g.NavWindow->Name : "NULL", g.NavLayer, g.NavInitRequest || g.NavInitResultId != 0, g.NavMoveRequest);
+#endif
+
+ // Set input source as Gamepad when buttons are pressed before we map Keyboard (some features differs when used with Gamepad vs Keyboard)
+ bool nav_keyboard_active = (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0;
+ bool nav_gamepad_active = (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (g.IO.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0;
+ if (nav_gamepad_active)
+ if (g.IO.NavInputs[ImGuiNavInput_Activate] > 0.0f || g.IO.NavInputs[ImGuiNavInput_Input] > 0.0f || g.IO.NavInputs[ImGuiNavInput_Cancel] > 0.0f || g.IO.NavInputs[ImGuiNavInput_Menu] > 0.0f)
+ g.NavInputSource = ImGuiInputSource_NavGamepad;
+
+ // Update Keyboard->Nav inputs mapping
+ if (nav_keyboard_active)
{
- if (window->Viewport != NULL && window->Viewport->Window == window)
- window->Viewport = AddUpdateViewport(window, window->ID, window->Pos, window->Size, ImGuiViewportFlags_None);
+ #define NAV_MAP_KEY(_KEY, _NAV_INPUT) do { if (IsKeyDown(g.IO.KeyMap[_KEY])) { g.IO.NavInputs[_NAV_INPUT] = 1.0f; g.NavInputSource = ImGuiInputSource_NavKeyboard; } } while (0)
+ NAV_MAP_KEY(ImGuiKey_Space, ImGuiNavInput_Activate );
+ NAV_MAP_KEY(ImGuiKey_Enter, ImGuiNavInput_Input );
+ NAV_MAP_KEY(ImGuiKey_Escape, ImGuiNavInput_Cancel );
+ NAV_MAP_KEY(ImGuiKey_LeftArrow, ImGuiNavInput_KeyLeft_ );
+ NAV_MAP_KEY(ImGuiKey_RightArrow,ImGuiNavInput_KeyRight_);
+ NAV_MAP_KEY(ImGuiKey_UpArrow, ImGuiNavInput_KeyUp_ );
+ NAV_MAP_KEY(ImGuiKey_DownArrow, ImGuiNavInput_KeyDown_ );
+ NAV_MAP_KEY(ImGuiKey_Tab, ImGuiNavInput_KeyTab_ );
+ if (g.IO.KeyCtrl)
+ g.IO.NavInputs[ImGuiNavInput_TweakSlow] = 1.0f;
+ if (g.IO.KeyShift)
+ g.IO.NavInputs[ImGuiNavInput_TweakFast] = 1.0f;
+ if (g.IO.KeyAlt && !g.IO.KeyCtrl) // AltGR is Alt+Ctrl, also even on keyboards without AltGR we don't want Alt+Ctrl to open menu.
+ g.IO.NavInputs[ImGuiNavInput_KeyMenu_] = 1.0f;
+ #undef NAV_MAP_KEY
}
- else
+ memcpy(g.IO.NavInputsDownDurationPrev, g.IO.NavInputsDownDuration, sizeof(g.IO.NavInputsDownDuration));
+ for (int i = 0; i < IM_ARRAYSIZE(g.IO.NavInputs); i++)
+ g.IO.NavInputsDownDuration[i] = (g.IO.NavInputs[i] > 0.0f) ? (g.IO.NavInputsDownDuration[i] < 0.0f ? 0.0f : g.IO.NavInputsDownDuration[i] + g.IO.DeltaTime) : -1.0f;
+
+ // Process navigation init request (select first/default focus)
+ // In very rare cases g.NavWindow may be null (e.g. clearing focus after requesting an init request, which does happen when releasing Alt while clicking on void)
+ if (g.NavInitResultId != 0 && (!g.NavDisableHighlight || g.NavInitRequestFromMove) && g.NavWindow)
{
- // Merge into host viewport?
- // We cannot test window->ViewportOwned as it set lower in the function.
- bool try_to_merge_into_host_viewport = (window->Viewport && window == window->Viewport->Window && g.ActiveId == 0);
- if (try_to_merge_into_host_viewport)
- UpdateTryMergeWindowIntoHostViewport(window, g.Viewports[0]);
+ // Apply result from previous navigation init request (will typically select the first item, unless SetItemDefaultFocus() has been called)
+ if (g.NavInitRequestFromMove)
+ SetNavIDWithRectRel(g.NavInitResultId, g.NavLayer, g.NavInitResultRectRel);
+ else
+ SetNavID(g.NavInitResultId, g.NavLayer);
+ g.NavWindow->NavRectRel[g.NavLayer] = g.NavInitResultRectRel;
}
+ g.NavInitRequest = false;
+ g.NavInitRequestFromMove = false;
+ g.NavInitResultId = 0;
+ g.NavJustMovedToId = 0;
- // Fallback to default viewport
- if (window->Viewport == NULL)
- window->Viewport = main_viewport;
+ // Process navigation move request
+ if (g.NavMoveRequest)
+ NavUpdateMoveResult();
- // Mark window as allowed to protrude outside of its viewport and into the current monitor
- if (flags & (ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_Popup))
+ // When a forwarded move request failed, we restore the highlight that we disabled during the forward frame
+ if (g.NavMoveRequestForward == ImGuiNavForward_ForwardActive)
{
- // We need to take account of the possibility that mouse may become invalid.
- // Popups/Tooltip always set ViewportAllowPlatformMonitorExtend so GetWindowAllowedExtentRect() will return full monitor bounds.
- ImVec2 mouse_ref = (flags & ImGuiWindowFlags_Tooltip) ? g.IO.MousePos : g.BeginPopupStack.back().OpenMousePos;
- bool use_mouse_ref = (g.NavDisableHighlight || !g.NavDisableMouseHover || !g.NavWindow);
- bool mouse_valid = IsMousePosValid(&mouse_ref);
- if ((window->Appearing || (flags & ImGuiWindowFlags_Tooltip)) && (!use_mouse_ref || mouse_valid))
- window->ViewportAllowPlatformMonitorExtend = FindPlatformMonitorForPos((use_mouse_ref && mouse_valid) ? mouse_ref : NavCalcPreferredRefPos());
- else
- window->ViewportAllowPlatformMonitorExtend = window->Viewport->PlatformMonitor;
+ IM_ASSERT(g.NavMoveRequest);
+ if (g.NavMoveResultLocal.ID == 0 && g.NavMoveResultOther.ID == 0)
+ g.NavDisableHighlight = false;
+ g.NavMoveRequestForward = ImGuiNavForward_None;
}
- else if (window->Viewport && window != window->Viewport->Window && window->Viewport->Window && !(flags & ImGuiWindowFlags_ChildWindow))
+
+ // Apply application mouse position movement, after we had a chance to process move request result.
+ if (g.NavMousePosDirty && g.NavIdIsAlive)
{
- // When called from Begin() we don't have access to a proper version of the Hidden flag yet, so we replicate this code.
- const bool will_be_visible = (window->DockIsActive && !window->DockTabIsVisible) ? false : true;
- if ((window->Flags & ImGuiWindowFlags_DockNodeHost) && window->Viewport->LastFrameActive < g.FrameCount && will_be_visible)
- {
- // Steal/transfer ownership
- //IMGUI_DEBUG_LOG("[%05d] Window '%s' steal Viewport %08X from Window '%s'\n", g.FrameCount, window->Name, window->Viewport->ID, window->Viewport->Window->Name);
- window->Viewport->Window = window;
- window->Viewport->ID = window->ID;
- window->Viewport->LastNameHash = 0;
- }
- else if (!UpdateTryMergeWindowIntoHostViewport(window, g.Viewports[0])) // Merge?
+ // Set mouse position given our knowledge of the navigated item position from last frame
+ if ((g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableSetMousePos) && (g.IO.BackendFlags & ImGuiBackendFlags_HasSetMousePos))
{
- // New viewport
- window->Viewport = AddUpdateViewport(window, window->ID, window->Pos, window->Size, ImGuiViewportFlags_NoFocusOnAppearing);
+ if (!g.NavDisableHighlight && g.NavDisableMouseHover && g.NavWindow)
+ {
+ g.IO.MousePos = g.IO.MousePosPrev = NavCalcPreferredRefPos();
+ g.IO.WantSetMousePos = true;
+ }
}
+ g.NavMousePosDirty = false;
}
+ g.NavIdIsAlive = false;
+ g.NavJustTabbedId = 0;
+ IM_ASSERT(g.NavLayer == 0 || g.NavLayer == 1);
- // Regular (non-child, non-popup) windows by default are also allowed to protrude
- // Child windows are kept contained within their parent.
- else if (window->ViewportAllowPlatformMonitorExtend < 0 && (flags & ImGuiWindowFlags_ChildWindow) == 0)
- window->ViewportAllowPlatformMonitorExtend = window->Viewport->PlatformMonitor;
-
- // Update flags
- window->ViewportOwned = (window == window->Viewport->Window);
-
- // If the OS window has a title bar, hide our imgui title bar
- //if (window->ViewportOwned && !(window->Viewport->Flags & ImGuiViewportFlags_NoDecoration))
- // window->Flags |= ImGuiWindowFlags_NoTitleBar;
+ // Store our return window (for returning from Layer 1 to Layer 0) and clear it as soon as we step back in our own Layer 0
+ if (g.NavWindow)
+ NavSaveLastChildNavWindowIntoParent(g.NavWindow);
+ if (g.NavWindow && g.NavWindow->NavLastChildNavWindow != NULL && g.NavLayer == 0)
+ g.NavWindow->NavLastChildNavWindow = NULL;
- window->ViewportId = window->Viewport->ID;
-}
+ // Update CTRL+TAB and Windowing features (hold Square to move/resize/etc.)
+ NavUpdateWindowing();
-// Called by user at the end of the main loop, after EndFrame()
-// This will handle the creation/update of all OS windows via function defined in the ImGuiPlatformIO api.
-void ImGui::UpdatePlatformWindows()
-{
- ImGuiContext& g = *GImGui;
- IM_ASSERT(g.FrameCountEnded == g.FrameCount && "Forgot to call Render() or EndFrame() before UpdatePlatformWindows()?");
- IM_ASSERT(g.FrameCountPlatformEnded < g.FrameCount);
- g.FrameCountPlatformEnded = g.FrameCount;
- if (!(g.ConfigFlagsForFrame & ImGuiConfigFlags_ViewportsEnable))
- return;
+ // Set output flags for user application
+ g.IO.NavActive = (nav_keyboard_active || nav_gamepad_active) && g.NavWindow && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs);
+ g.IO.NavVisible = (g.IO.NavActive && g.NavId != 0 && !g.NavDisableHighlight) || (g.NavWindowingTarget != NULL);
- // Create/resize/destroy platform windows to match each active viewport.
- // Skip the main viewport (index 0), which is always fully handled by the application!
- for (int i = 1; i < g.Viewports.Size; i++)
+ // Process NavCancel input (to close a popup, get back to parent, clear focus)
+ if (IsNavInputPressed(ImGuiNavInput_Cancel, ImGuiInputReadMode_Pressed))
{
- ImGuiViewportP* viewport = g.Viewports[i];
-
- // Destroy platform window if the viewport hasn't been submitted or if it is hosting a hidden window (the implicit/fallback Debug window will be registered its viewport then be disabled)
- bool destroy_platform_window = false;
- destroy_platform_window |= (viewport->LastFrameActive < g.FrameCount - 1);
- destroy_platform_window |= (viewport->Window && !IsWindowActiveAndVisible(viewport->Window));
- if (destroy_platform_window)
+ if (g.ActiveId != 0)
{
- DestroyPlatformWindow(viewport);
- continue;
+ if (!(g.ActiveIdBlockNavInputFlags & (1 << ImGuiNavInput_Cancel)))
+ ClearActiveID();
}
-
- // New windows that appears directly in a new viewport won't always have a size on their first frame
- if (viewport->LastFrameActive < g.FrameCount || viewport->Size.x <= 0 || viewport->Size.y <= 0)
- continue;
-
- // Create window
- bool is_new_platform_window = (viewport->PlatformWindowCreated == false);
- if (is_new_platform_window)
+ else if (g.NavWindow && (g.NavWindow->Flags & ImGuiWindowFlags_ChildWindow) && !(g.NavWindow->Flags & ImGuiWindowFlags_Popup) && g.NavWindow->ParentWindow && g.NavWindow != g.NavWindow->RootWindowDockStop)
{
- //IMGUI_DEBUG_LOG("Create Platform Window %08X (%s)\n", viewport->ID, viewport->Window ? viewport->Window->Name : "n/a");
- g.PlatformIO.Platform_CreateWindow(viewport);
- if (g.PlatformIO.Renderer_CreateWindow != NULL)
- g.PlatformIO.Renderer_CreateWindow(viewport);
- viewport->LastNameHash = 0;
- viewport->LastPlatformPos = viewport->LastPlatformSize = ImVec2(FLT_MAX, FLT_MAX); // By clearing those we'll enforce a call to Platform_SetWindowPos/Size below, before Platform_ShowWindow (FIXME: Is that necessary?)
- viewport->LastRendererSize = viewport->Size; // We don't need to call Renderer_SetWindowSize() as it is expected Renderer_CreateWindow() already did it.
- viewport->PlatformWindowCreated = true;
+ // Exit child window
+ ImGuiWindow* child_window = g.NavWindow;
+ ImGuiWindow* parent_window = g.NavWindow->ParentWindow;
+ IM_ASSERT(child_window->ChildId != 0);
+ FocusWindow(parent_window);
+ SetNavID(child_window->ChildId, 0);
+ g.NavIdIsAlive = false;
+ if (g.NavDisableMouseHover)
+ g.NavMousePosDirty = true;
}
-
- // Apply Position and Size (from ImGui to Platform/Renderer back-ends)
- if ((viewport->LastPlatformPos.x != viewport->Pos.x || viewport->LastPlatformPos.y != viewport->Pos.y) && !viewport->PlatformRequestMove)
- g.PlatformIO.Platform_SetWindowPos(viewport, viewport->Pos);
- if ((viewport->LastPlatformSize.x != viewport->Size.x || viewport->LastPlatformSize.y != viewport->Size.y) && !viewport->PlatformRequestResize)
- g.PlatformIO.Platform_SetWindowSize(viewport, viewport->Size);
- if ((viewport->LastRendererSize.x != viewport->Size.x || viewport->LastRendererSize.y != viewport->Size.y) && g.PlatformIO.Renderer_SetWindowSize)
- g.PlatformIO.Renderer_SetWindowSize(viewport, viewport->Size);
- viewport->LastPlatformPos = viewport->Pos;
- viewport->LastPlatformSize = viewport->LastRendererSize = viewport->Size;
-
- // Update title bar (if it changed)
- if (ImGuiWindow* window_for_title = GetWindowForTitleDisplay(viewport->Window))
+ else if (g.OpenPopupStack.Size > 0)
{
- const char* title_begin = window_for_title->Name;
- char* title_end = (char*)(intptr_t)FindRenderedTextEnd(title_begin);
- const ImGuiID title_hash = ImHashStr(title_begin, title_end - title_begin);
- if (viewport->LastNameHash != title_hash)
- {
- char title_end_backup_c = *title_end;
- *title_end = 0; // Cut existing buffer short instead of doing an alloc/free, no small gain.
- g.PlatformIO.Platform_SetWindowTitle(viewport, title_begin);
- *title_end = title_end_backup_c;
- viewport->LastNameHash = title_hash;
- }
+ // Close open popup/menu
+ if (!(g.OpenPopupStack.back().Window->Flags & ImGuiWindowFlags_Modal))
+ ClosePopupToLevel(g.OpenPopupStack.Size - 1, true);
+ }
+ else if (g.NavLayer != 0)
+ {
+ // Leave the "menu" layer
+ NavRestoreLayer(ImGuiNavLayer_Main);
}
+ else
+ {
+ // Clear NavLastId for popups but keep it for regular child window so we can leave one and come back where we were
+ if (g.NavWindow && ((g.NavWindow->Flags & ImGuiWindowFlags_Popup) || !(g.NavWindow->Flags & ImGuiWindowFlags_ChildWindow)))
+ g.NavWindow->NavLastIds[0] = 0;
+ g.NavId = 0;
+ }
+ }
- // Update alpha (if it changed)
- if (viewport->LastAlpha != viewport->Alpha && g.PlatformIO.Platform_SetWindowAlpha)
- g.PlatformIO.Platform_SetWindowAlpha(viewport, viewport->Alpha);
- viewport->LastAlpha = viewport->Alpha;
+ // Process manual activation request
+ g.NavActivateId = g.NavActivateDownId = g.NavActivatePressedId = g.NavInputId = 0;
+ if (g.NavId != 0 && !g.NavDisableHighlight && !g.NavWindowingTarget && g.NavWindow && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs))
+ {
+ bool activate_down = IsNavInputDown(ImGuiNavInput_Activate);
+ bool activate_pressed = activate_down && IsNavInputPressed(ImGuiNavInput_Activate, ImGuiInputReadMode_Pressed);
+ if (g.ActiveId == 0 && activate_pressed)
+ g.NavActivateId = g.NavId;
+ if ((g.ActiveId == 0 || g.ActiveId == g.NavId) && activate_down)
+ g.NavActivateDownId = g.NavId;
+ if ((g.ActiveId == 0 || g.ActiveId == g.NavId) && activate_pressed)
+ g.NavActivatePressedId = g.NavId;
+ if ((g.ActiveId == 0 || g.ActiveId == g.NavId) && IsNavInputPressed(ImGuiNavInput_Input, ImGuiInputReadMode_Pressed))
+ g.NavInputId = g.NavId;
+ }
+ if (g.NavWindow && (g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs))
+ g.NavDisableHighlight = true;
+ if (g.NavActivateId != 0)
+ IM_ASSERT(g.NavActivateDownId == g.NavActivateId);
+ g.NavMoveRequest = false;
- // Optional, general purpose call to allow the back-end to perform general book-keeping even if things haven't changed.
- if (g.PlatformIO.Platform_UpdateWindow)
- g.PlatformIO.Platform_UpdateWindow(viewport);
+ // Process programmatic activation request
+ if (g.NavNextActivateId != 0)
+ g.NavActivateId = g.NavActivateDownId = g.NavActivatePressedId = g.NavInputId = g.NavNextActivateId;
+ g.NavNextActivateId = 0;
- if (is_new_platform_window)
+ // Initiate directional inputs request
+ const int allowed_dir_flags = (g.ActiveId == 0) ? ~0 : g.ActiveIdAllowNavDirFlags;
+ if (g.NavMoveRequestForward == ImGuiNavForward_None)
+ {
+ g.NavMoveDir = ImGuiDir_None;
+ g.NavMoveRequestFlags = ImGuiNavMoveFlags_None;
+ if (g.NavWindow && !g.NavWindowingTarget && allowed_dir_flags && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs))
{
- // On startup ensure new platform window don't steal focus (give it a few frames, as nested contents may lead to viewport being created a few frames late)
- if (g.FrameCount < 3)
- viewport->Flags |= ImGuiViewportFlags_NoFocusOnAppearing;
-
- // Show window
- g.PlatformIO.Platform_ShowWindow(viewport);
-
- // Even without focus, we assume the window becomes front-most.
- // This is useful for our platform z-order heuristic when io.MouseHoveredViewport is not available.
- if (viewport->LastFrontMostStampCount != g.WindowsFrontMostStampCount)
- viewport->LastFrontMostStampCount = ++g.WindowsFrontMostStampCount;
+ if ((allowed_dir_flags & (1<ClearRequestFlags();
+ // Update PageUp/PageDown scroll
+ float nav_scoring_rect_offset_y = 0.0f;
+ if (nav_keyboard_active)
+ nav_scoring_rect_offset_y = NavUpdatePageUpPageDown(allowed_dir_flags);
+
+ // If we initiate a movement request and have no current NavId, we initiate a InitDefautRequest that will be used as a fallback if the direction fails to find a match
+ if (g.NavMoveDir != ImGuiDir_None)
+ {
+ g.NavMoveRequest = true;
+ g.NavMoveDirLast = g.NavMoveDir;
+ }
+ if (g.NavMoveRequest && g.NavId == 0)
+ {
+ g.NavInitRequest = g.NavInitRequestFromMove = true;
+ g.NavInitResultId = 0;
+ g.NavDisableHighlight = false;
}
+ NavUpdateAnyRequestFlag();
- // Update our implicit z-order knowledge of platform windows, which is used when the back-end cannot provide io.MouseHoveredViewport.
- // When setting Platform_GetWindowFocus, it is expected that the platform back-end can handle calls without crashing if it doesn't have data stored.
- if (g.PlatformIO.Platform_GetWindowFocus != NULL)
+ // Scrolling
+ if (g.NavWindow && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs) && !g.NavWindowingTarget)
{
- ImGuiViewportP* focused_viewport = NULL;
- for (int n = 0; n < g.Viewports.Size && focused_viewport == NULL; n++)
+ // *Fallback* manual-scroll with Nav directional keys when window has no navigable item
+ ImGuiWindow* window = g.NavWindow;
+ const float scroll_speed = ImFloor(window->CalcFontSize() * 100 * g.IO.DeltaTime + 0.5f); // We need round the scrolling speed because sub-pixel scroll isn't reliably supported.
+ if (window->DC.NavLayerActiveMask == 0x00 && window->DC.NavHasScroll && g.NavMoveRequest)
{
- ImGuiViewportP* viewport = g.Viewports[n];
- if (n == 0 || viewport->PlatformWindowCreated)
- if (g.PlatformIO.Platform_GetWindowFocus(viewport))
- focused_viewport = viewport;
+ if (g.NavMoveDir == ImGuiDir_Left || g.NavMoveDir == ImGuiDir_Right)
+ SetScrollX(window, ImFloor(window->Scroll.x + ((g.NavMoveDir == ImGuiDir_Left) ? -1.0f : +1.0f) * scroll_speed));
+ if (g.NavMoveDir == ImGuiDir_Up || g.NavMoveDir == ImGuiDir_Down)
+ SetScrollY(window, ImFloor(window->Scroll.y + ((g.NavMoveDir == ImGuiDir_Up) ? -1.0f : +1.0f) * scroll_speed));
}
- if (focused_viewport && g.PlatformLastFocusedViewport != focused_viewport->ID)
+
+ // *Normal* Manual scroll with NavScrollXXX keys
+ // Next movement request will clamp the NavId reference rectangle to the visible area, so navigation will resume within those bounds.
+ ImVec2 scroll_dir = GetNavInputAmount2d(ImGuiNavDirSourceFlags_PadLStick, ImGuiInputReadMode_Down, 1.0f/10.0f, 10.0f);
+ if (scroll_dir.x != 0.0f && window->ScrollbarX)
{
- if (focused_viewport->LastFrontMostStampCount != g.WindowsFrontMostStampCount)
- focused_viewport->LastFrontMostStampCount = ++g.WindowsFrontMostStampCount;
- g.PlatformLastFocusedViewport = focused_viewport->ID;
+ SetScrollX(window, ImFloor(window->Scroll.x + scroll_dir.x * scroll_speed));
+ g.NavMoveFromClampedRefRect = true;
+ }
+ if (scroll_dir.y != 0.0f)
+ {
+ SetScrollY(window, ImFloor(window->Scroll.y + scroll_dir.y * scroll_speed));
+ g.NavMoveFromClampedRefRect = true;
}
}
-}
-// This is a default/basic function for performing the rendering/swap of multiple Platform Windows.
-// Custom renderers may prefer to not call this function at all, and instead iterate the publicly exposed platform data and handle rendering/sync themselves.
-// The Render/Swap functions stored in ImGuiPlatformIO are merely here to allow for this helper to exist, but you can do it yourself:
-//
-// ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
-// for (int i = 1; i < platform_io.Viewports.Size; i++)
-// MyRenderFunction(platform_io.Viewports[i], my_args);
-// for (int i = 1; i < platform_io.Viewports.Size; i++)
-// MySwapBufferFunction(platform_io.Viewports[i], my_args);
-//
-void ImGui::RenderPlatformWindowsDefault(void* platform_render_arg, void* renderer_render_arg)
-{
- // Skip the main viewport (index 0), which is always fully handled by the application!
- ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
- for (int i = 1; i < platform_io.Viewports.Size; i++)
+ // Reset search results
+ g.NavMoveResultLocal.Clear();
+ g.NavMoveResultLocalVisibleSet.Clear();
+ g.NavMoveResultOther.Clear();
+
+ // When we have manually scrolled (without using navigation) and NavId becomes out of bounds, we project its bounding box to the visible area to restart navigation within visible items
+ if (g.NavMoveRequest && g.NavMoveFromClampedRefRect && g.NavLayer == 0)
{
- ImGuiViewport* viewport = platform_io.Viewports[i];
- if (platform_io.Platform_RenderWindow) platform_io.Platform_RenderWindow(viewport, platform_render_arg);
- if (platform_io.Renderer_RenderWindow) platform_io.Renderer_RenderWindow(viewport, renderer_render_arg);
+ ImGuiWindow* window = g.NavWindow;
+ ImRect window_rect_rel(window->InnerRect.Min - window->Pos - ImVec2(1,1), window->InnerRect.Max - window->Pos + ImVec2(1,1));
+ if (!window_rect_rel.Contains(window->NavRectRel[g.NavLayer]))
+ {
+ float pad = window->CalcFontSize() * 0.5f;
+ window_rect_rel.Expand(ImVec2(-ImMin(window_rect_rel.GetWidth(), pad), -ImMin(window_rect_rel.GetHeight(), pad))); // Terrible approximation for the intent of starting navigation from first fully visible item
+ window->NavRectRel[g.NavLayer].ClipWith(window_rect_rel);
+ g.NavId = 0;
+ }
+ g.NavMoveFromClampedRefRect = false;
}
- for (int i = 1; i < platform_io.Viewports.Size; i++)
+
+ // For scoring we use a single segment on the left side our current item bounding box (not touching the edge to avoid box overlap with zero-spaced items)
+ ImRect nav_rect_rel = (g.NavWindow && !g.NavWindow->NavRectRel[g.NavLayer].IsInverted()) ? g.NavWindow->NavRectRel[g.NavLayer] : ImRect(0,0,0,0);
+ g.NavScoringRectScreen = g.NavWindow ? ImRect(g.NavWindow->Pos + nav_rect_rel.Min, g.NavWindow->Pos + nav_rect_rel.Max) : ImRect(0,0,0,0);
+ g.NavScoringRectScreen.TranslateY(nav_scoring_rect_offset_y);
+ g.NavScoringRectScreen.Min.x = ImMin(g.NavScoringRectScreen.Min.x + 1.0f, g.NavScoringRectScreen.Max.x);
+ g.NavScoringRectScreen.Max.x = g.NavScoringRectScreen.Min.x;
+ IM_ASSERT(!g.NavScoringRectScreen.IsInverted()); // Ensure if we have a finite, non-inverted bounding box here will allows us to remove extraneous ImFabs() calls in NavScoreItem().
+ //GetForegroundDrawList()->AddRect(g.NavScoringRectScreen.Min, g.NavScoringRectScreen.Max, IM_COL32(255,200,0,255)); // [DEBUG]
+ g.NavScoringCount = 0;
+#if IMGUI_DEBUG_NAV_RECTS
+ if (g.NavWindow)
{
- ImGuiViewport* viewport = platform_io.Viewports[i];
- if (platform_io.Platform_SwapBuffers) platform_io.Platform_SwapBuffers(viewport, platform_render_arg);
- if (platform_io.Renderer_SwapBuffers) platform_io.Renderer_SwapBuffers(viewport, renderer_render_arg);
+ ImDrawList* draw_list = GetForegroundDrawList(g.NavWindow);
+ if (1) { for (int layer = 0; layer < 2; layer++) draw_list->AddRect(g.NavWindow->Pos + g.NavWindow->NavRectRel[layer].Min, g.NavWindow->Pos + g.NavWindow->NavRectRel[layer].Max, IM_COL32(255,200,0,255)); } // [DEBUG]
+ if (1) { ImU32 col = (!g.NavWindow->Hidden) ? IM_COL32(255,0,255,255) : IM_COL32(255,0,0,255); ImVec2 p = NavCalcPreferredRefPos(); char buf[32]; ImFormatString(buf, 32, "%d", g.NavLayer); draw_list->AddCircleFilled(p, 3.0f, col); draw_list->AddText(NULL, 13.0f, p + ImVec2(8,-4), col, buf); }
}
+#endif
}
-static int ImGui::FindPlatformMonitorForPos(const ImVec2& pos)
+// Apply result from previous frame navigation directional move request
+static void ImGui::NavUpdateMoveResult()
{
ImGuiContext& g = *GImGui;
- for (int monitor_n = 0; monitor_n < g.PlatformIO.Monitors.Size; monitor_n++)
+ if (g.NavMoveResultLocal.ID == 0 && g.NavMoveResultOther.ID == 0)
{
- const ImGuiPlatformMonitor& monitor = g.PlatformIO.Monitors[monitor_n];
- if (ImRect(monitor.MainPos, monitor.MainPos + monitor.MainSize).Contains(pos))
- return monitor_n;
+ // In a situation when there is no results but NavId != 0, re-enable the Navigation highlight (because g.NavId is not considered as a possible result)
+ if (g.NavId != 0)
+ {
+ g.NavDisableHighlight = false;
+ g.NavDisableMouseHover = true;
+ }
+ return;
}
- return -1;
-}
-// Search for the monitor with the largest intersection area with the given rectangle
-// We generally try to avoid searching loops but the monitor count should be very small here
-static int ImGui::FindPlatformMonitorForRect(const ImRect& rect)
-{
- ImGuiContext& g = *GImGui;
+ // Select which result to use
+ ImGuiNavMoveResult* result = (g.NavMoveResultLocal.ID != 0) ? &g.NavMoveResultLocal : &g.NavMoveResultOther;
- // Use a minimum threshold of 1.0f so a zero-sized rect will still find its monitor given its position.
- // This is necessary for tooltips which always resize down to zero at first.
- const float surface_threshold = ImMax(rect.GetWidth() * rect.GetHeight() * 0.5f, 1.0f);
- int best_monitor_n = -1;
- float best_monitor_surface = 0.001f;
+ // PageUp/PageDown behavior first jumps to the bottom/top mostly visible item, _otherwise_ use the result from the previous/next page.
+ if (g.NavMoveRequestFlags & ImGuiNavMoveFlags_AlsoScoreVisibleSet)
+ if (g.NavMoveResultLocalVisibleSet.ID != 0 && g.NavMoveResultLocalVisibleSet.ID != g.NavId)
+ result = &g.NavMoveResultLocalVisibleSet;
- for (int monitor_n = 0; monitor_n < g.PlatformIO.Monitors.Size && best_monitor_surface < surface_threshold; monitor_n++)
- {
- const ImGuiPlatformMonitor& monitor = g.PlatformIO.Monitors[monitor_n];
- const ImRect monitor_rect = ImRect(monitor.MainPos, monitor.MainPos + monitor.MainSize);
- if (monitor_rect.Contains(rect))
- return monitor_n;
- ImRect overlapping_rect = rect;
- overlapping_rect.ClipWithFull(monitor_rect);
- float overlapping_surface = overlapping_rect.GetWidth() * overlapping_rect.GetHeight();
- if (overlapping_surface < best_monitor_surface)
- continue;
- best_monitor_surface = overlapping_surface;
- best_monitor_n = monitor_n;
+ // Maybe entering a flattened child from the outside? In this case solve the tie using the regular scoring rules.
+ if (result != &g.NavMoveResultOther && g.NavMoveResultOther.ID != 0 && g.NavMoveResultOther.Window->ParentWindow == g.NavWindow)
+ if ((g.NavMoveResultOther.DistBox < result->DistBox) || (g.NavMoveResultOther.DistBox == result->DistBox && g.NavMoveResultOther.DistCenter < result->DistCenter))
+ result = &g.NavMoveResultOther;
+ IM_ASSERT(g.NavWindow && result->Window);
+
+ // Scroll to keep newly navigated item fully into view.
+ if (g.NavLayer == 0)
+ {
+ ImRect rect_abs = ImRect(result->RectRel.Min + result->Window->Pos, result->RectRel.Max + result->Window->Pos);
+ ImVec2 delta_scroll = ScrollToBringRectIntoView(result->Window, rect_abs);
+
+ // Offset our result position so mouse position can be applied immediately after in NavUpdate()
+ result->RectRel.TranslateX(-delta_scroll.x);
+ result->RectRel.TranslateY(-delta_scroll.y);
}
- return best_monitor_n;
+
+ ClearActiveID();
+ g.NavWindow = result->Window;
+ if (g.NavId != result->ID)
+ {
+ // Don't set NavJustMovedToId if just landed on the same spot (which may happen with ImGuiNavMoveFlags_AllowCurrentNavId)
+ g.NavJustMovedToId = result->ID;
+ g.NavJustMovedToMultiSelectScopeId = result->SelectScopeId;
+ }
+ SetNavIDWithRectRel(result->ID, g.NavLayer, result->RectRel);
+ g.NavMoveFromClampedRefRect = false;
}
-void ImGui::DestroyPlatformWindow(ImGuiViewportP* viewport)
+static float ImGui::NavUpdatePageUpPageDown(int allowed_dir_flags)
{
ImGuiContext& g = *GImGui;
- if (g.PlatformIO.Renderer_DestroyWindow)
- g.PlatformIO.Renderer_DestroyWindow(viewport);
- if (g.PlatformIO.Platform_DestroyWindow)
- g.PlatformIO.Platform_DestroyWindow(viewport);
- IM_ASSERT(viewport->RendererUserData == NULL);
- IM_ASSERT(viewport->PlatformUserData == NULL);
- viewport->PlatformHandle = NULL;
- viewport->RendererUserData = viewport->PlatformHandle = NULL;
- viewport->PlatformWindowCreated = false;
- viewport->ClearRequestFlags();
+ if (g.NavMoveDir != ImGuiDir_None || g.NavWindow == NULL)
+ return 0.0f;
+ if ((g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs) || g.NavWindowingTarget != NULL || g.NavLayer != 0)
+ return 0.0f;
+
+ ImGuiWindow* window = g.NavWindow;
+ bool page_up_held = IsKeyDown(g.IO.KeyMap[ImGuiKey_PageUp]) && (allowed_dir_flags & (1 << ImGuiDir_Up));
+ bool page_down_held = IsKeyDown(g.IO.KeyMap[ImGuiKey_PageDown]) && (allowed_dir_flags & (1 << ImGuiDir_Down));
+ if (page_up_held != page_down_held) // If either (not both) are pressed
+ {
+ if (window->DC.NavLayerActiveMask == 0x00 && window->DC.NavHasScroll)
+ {
+ // Fallback manual-scroll when window has no navigable item
+ if (IsKeyPressed(g.IO.KeyMap[ImGuiKey_PageUp], true))
+ SetScrollY(window, window->Scroll.y - window->InnerRect.GetHeight());
+ else if (IsKeyPressed(g.IO.KeyMap[ImGuiKey_PageDown], true))
+ SetScrollY(window, window->Scroll.y + window->InnerRect.GetHeight());
+ }
+ else
+ {
+ const ImRect& nav_rect_rel = window->NavRectRel[g.NavLayer];
+ const float page_offset_y = ImMax(0.0f, window->InnerRect.GetHeight() - window->CalcFontSize() * 1.0f + nav_rect_rel.GetHeight());
+ float nav_scoring_rect_offset_y = 0.0f;
+ if (IsKeyPressed(g.IO.KeyMap[ImGuiKey_PageUp], true))
+ {
+ nav_scoring_rect_offset_y = -page_offset_y;
+ g.NavMoveDir = ImGuiDir_Down; // Because our scoring rect is offset, we intentionally request the opposite direction (so we can always land on the last item)
+ g.NavMoveClipDir = ImGuiDir_Up;
+ g.NavMoveRequestFlags = ImGuiNavMoveFlags_AllowCurrentNavId | ImGuiNavMoveFlags_AlsoScoreVisibleSet;
+ }
+ else if (IsKeyPressed(g.IO.KeyMap[ImGuiKey_PageDown], true))
+ {
+ nav_scoring_rect_offset_y = +page_offset_y;
+ g.NavMoveDir = ImGuiDir_Up; // Because our scoring rect is offset, we intentionally request the opposite direction (so we can always land on the last item)
+ g.NavMoveClipDir = ImGuiDir_Down;
+ g.NavMoveRequestFlags = ImGuiNavMoveFlags_AllowCurrentNavId | ImGuiNavMoveFlags_AlsoScoreVisibleSet;
+ }
+ return nav_scoring_rect_offset_y;
+ }
+ }
+ return 0.0f;
}
-void ImGui::DestroyPlatformWindows()
+static int ImGui::FindWindowFocusIndex(ImGuiWindow* window) // FIXME-OPT O(N)
{
- // We call the destroy window on every viewport (including the main viewport, index 0) to give a chance to the back-end
- // to clear any data they may have stored in e.g. PlatformUserData, RendererUserData.
- // It is convenient for the platform back-end code to store something in the main viewport, in order for e.g. the mouse handling
- // code to operator a consistent manner.
- // It is expected that the back-end can handle calls to Renderer_DestroyWindow/Platform_DestroyWindow without
- // crashing if it doesn't have data stored.
ImGuiContext& g = *GImGui;
- for (int i = 0; i < g.Viewports.Size; i++)
- DestroyPlatformWindow(g.Viewports[i]);
+ for (int i = g.WindowsFocusOrder.Size-1; i >= 0; i--)
+ if (g.WindowsFocusOrder[i] == window)
+ return i;
+ return -1;
}
-//-----------------------------------------------------------------------------
-// [SECTION] KEYBOARD/GAMEPAD NAVIGATION
-//-----------------------------------------------------------------------------
-
-ImGuiDir ImGetDirQuadrantFromDelta(float dx, float dy)
+static ImGuiWindow* FindWindowNavFocusable(int i_start, int i_stop, int dir) // FIXME-OPT O(N)
{
- if (ImFabs(dx) > ImFabs(dy))
- return (dx > 0.0f) ? ImGuiDir_Right : ImGuiDir_Left;
- return (dy > 0.0f) ? ImGuiDir_Down : ImGuiDir_Up;
+ ImGuiContext& g = *GImGui;
+ for (int i = i_start; i >= 0 && i < g.WindowsFocusOrder.Size && i != i_stop; i += dir)
+ if (ImGui::IsWindowNavFocusable(g.WindowsFocusOrder[i]))
+ return g.WindowsFocusOrder[i];
+ return NULL;
}
-static float inline NavScoreItemDistInterval(float a0, float a1, float b0, float b1)
+static void NavUpdateWindowingHighlightWindow(int focus_change_dir)
{
- if (a1 < b0)
- return a1 - b0;
- if (b1 < a0)
- return a0 - b1;
- return 0.0f;
-}
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(g.NavWindowingTarget);
+ if (g.NavWindowingTarget->Flags & ImGuiWindowFlags_Modal)
+ return;
-static void inline NavClampRectToVisibleAreaForMoveDir(ImGuiDir move_dir, ImRect& r, const ImRect& clip_rect)
-{
- if (move_dir == ImGuiDir_Left || move_dir == ImGuiDir_Right)
- {
- r.Min.y = ImClamp(r.Min.y, clip_rect.Min.y, clip_rect.Max.y);
- r.Max.y = ImClamp(r.Max.y, clip_rect.Min.y, clip_rect.Max.y);
- }
- else
- {
- r.Min.x = ImClamp(r.Min.x, clip_rect.Min.x, clip_rect.Max.x);
- r.Max.x = ImClamp(r.Max.x, clip_rect.Min.x, clip_rect.Max.x);
- }
+ const int i_current = ImGui::FindWindowFocusIndex(g.NavWindowingTarget);
+ ImGuiWindow* window_target = FindWindowNavFocusable(i_current + focus_change_dir, -INT_MAX, focus_change_dir);
+ if (!window_target)
+ window_target = FindWindowNavFocusable((focus_change_dir < 0) ? (g.WindowsFocusOrder.Size - 1) : 0, i_current, focus_change_dir);
+ if (window_target) // Don't reset windowing target if there's a single window in the list
+ g.NavWindowingTarget = g.NavWindowingTargetAnim = window_target;
+ g.NavWindowingToggleLayer = false;
}
-// Scoring function for directional navigation. Based on https://gist.github.com/rygorous/6981057
-static bool NavScoreItem(ImGuiNavMoveResult* result, ImRect cand)
+// Windowing management mode
+// Keyboard: CTRL+Tab (change focus/move/resize), Alt (toggle menu layer)
+// Gamepad: Hold Menu/Square (change focus/move/resize), Tap Menu/Square (toggle menu layer)
+static void ImGui::NavUpdateWindowing()
{
ImGuiContext& g = *GImGui;
- ImGuiWindow* window = g.CurrentWindow;
- if (g.NavLayer != window->DC.NavLayerCurrent)
- return false;
+ ImGuiWindow* apply_focus_window = NULL;
+ bool apply_toggle_layer = false;
- const ImRect& curr = g.NavScoringRectScreen; // Current modified source rect (NB: we've applied Max.x = Min.x in NavUpdate() to inhibit the effect of having varied item width)
- g.NavScoringCount++;
+ ImGuiWindow* modal_window = GetTopMostPopupModal();
+ if (modal_window != NULL)
+ {
+ g.NavWindowingTarget = NULL;
+ return;
+ }
- // When entering through a NavFlattened border, we consider child window items as fully clipped for scoring
- if (window->ParentWindow == g.NavWindow)
+ // Fade out
+ if (g.NavWindowingTargetAnim && g.NavWindowingTarget == NULL)
{
- IM_ASSERT((window->Flags | g.NavWindow->Flags) & ImGuiWindowFlags_NavFlattened);
- if (!window->ClipRect.Contains(cand))
- return false;
- cand.ClipWithFull(window->ClipRect); // This allows the scored item to not overlap other candidates in the parent window
+ g.NavWindowingHighlightAlpha = ImMax(g.NavWindowingHighlightAlpha - g.IO.DeltaTime * 10.0f, 0.0f);
+ if (g.DimBgRatio <= 0.0f && g.NavWindowingHighlightAlpha <= 0.0f)
+ g.NavWindowingTargetAnim = NULL;
}
- // We perform scoring on items bounding box clipped by the current clipping rectangle on the other axis (clipping on our movement axis would give us equal scores for all clipped items)
- // For example, this ensure that items in one column are not reached when moving vertically from items in another column.
- NavClampRectToVisibleAreaForMoveDir(g.NavMoveClipDir, cand, window->ClipRect);
+ // Start CTRL-TAB or Square+L/R window selection
+ bool start_windowing_with_gamepad = !g.NavWindowingTarget && IsNavInputPressed(ImGuiNavInput_Menu, ImGuiInputReadMode_Pressed);
+ bool start_windowing_with_keyboard = !g.NavWindowingTarget && g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_Tab) && (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard);
+ if (start_windowing_with_gamepad || start_windowing_with_keyboard)
+ if (ImGuiWindow* window = g.NavWindow ? g.NavWindow : FindWindowNavFocusable(g.WindowsFocusOrder.Size - 1, -INT_MAX, -1))
+ {
+ g.NavWindowingTarget = g.NavWindowingTargetAnim = window;
+ g.NavWindowingTimer = g.NavWindowingHighlightAlpha = 0.0f;
+ g.NavWindowingToggleLayer = start_windowing_with_keyboard ? false : true;
+ g.NavInputSource = start_windowing_with_keyboard ? ImGuiInputSource_NavKeyboard : ImGuiInputSource_NavGamepad;
+ }
- // Compute distance between boxes
- // FIXME-NAV: Introducing biases for vertical navigation, needs to be removed.
- float dbx = NavScoreItemDistInterval(cand.Min.x, cand.Max.x, curr.Min.x, curr.Max.x);
- float dby = NavScoreItemDistInterval(ImLerp(cand.Min.y, cand.Max.y, 0.2f), ImLerp(cand.Min.y, cand.Max.y, 0.8f), ImLerp(curr.Min.y, curr.Max.y, 0.2f), ImLerp(curr.Min.y, curr.Max.y, 0.8f)); // Scale down on Y to keep using box-distance for vertically touching items
- if (dby != 0.0f && dbx != 0.0f)
- dbx = (dbx/1000.0f) + ((dbx > 0.0f) ? +1.0f : -1.0f);
- float dist_box = ImFabs(dbx) + ImFabs(dby);
+ // Gamepad update
+ g.NavWindowingTimer += g.IO.DeltaTime;
+ if (g.NavWindowingTarget && g.NavInputSource == ImGuiInputSource_NavGamepad)
+ {
+ // Highlight only appears after a brief time holding the button, so that a fast tap on PadMenu (to toggle NavLayer) doesn't add visual noise
+ g.NavWindowingHighlightAlpha = ImMax(g.NavWindowingHighlightAlpha, ImSaturate((g.NavWindowingTimer - NAV_WINDOWING_HIGHLIGHT_DELAY) / 0.05f));
- // Compute distance between centers (this is off by a factor of 2, but we only compare center distances with each other so it doesn't matter)
- float dcx = (cand.Min.x + cand.Max.x) - (curr.Min.x + curr.Max.x);
- float dcy = (cand.Min.y + cand.Max.y) - (curr.Min.y + curr.Max.y);
- float dist_center = ImFabs(dcx) + ImFabs(dcy); // L1 metric (need this for our connectedness guarantee)
+ // Select window to focus
+ const int focus_change_dir = (int)IsNavInputPressed(ImGuiNavInput_FocusPrev, ImGuiInputReadMode_RepeatSlow) - (int)IsNavInputPressed(ImGuiNavInput_FocusNext, ImGuiInputReadMode_RepeatSlow);
+ if (focus_change_dir != 0)
+ {
+ NavUpdateWindowingHighlightWindow(focus_change_dir);
+ g.NavWindowingHighlightAlpha = 1.0f;
+ }
- // Determine which quadrant of 'curr' our candidate item 'cand' lies in based on distance
- ImGuiDir quadrant;
- float dax = 0.0f, day = 0.0f, dist_axial = 0.0f;
- if (dbx != 0.0f || dby != 0.0f)
- {
- // For non-overlapping boxes, use distance between boxes
- dax = dbx;
- day = dby;
- dist_axial = dist_box;
- quadrant = ImGetDirQuadrantFromDelta(dbx, dby);
- }
- else if (dcx != 0.0f || dcy != 0.0f)
- {
- // For overlapping boxes with different centers, use distance between centers
- dax = dcx;
- day = dcy;
- dist_axial = dist_center;
- quadrant = ImGetDirQuadrantFromDelta(dcx, dcy);
- }
- else
- {
- // Degenerate case: two overlapping buttons with same center, break ties arbitrarily (note that LastItemId here is really the _previous_ item order, but it doesn't matter)
- quadrant = (window->DC.LastItemId < g.NavId) ? ImGuiDir_Left : ImGuiDir_Right;
+ // Single press toggles NavLayer, long press with L/R apply actual focus on release (until then the window was merely rendered top-most)
+ if (!IsNavInputDown(ImGuiNavInput_Menu))
+ {
+ g.NavWindowingToggleLayer &= (g.NavWindowingHighlightAlpha < 1.0f); // Once button was held long enough we don't consider it a tap-to-toggle-layer press anymore.
+ if (g.NavWindowingToggleLayer && g.NavWindow)
+ apply_toggle_layer = true;
+ else if (!g.NavWindowingToggleLayer)
+ apply_focus_window = g.NavWindowingTarget;
+ g.NavWindowingTarget = NULL;
+ }
}
-#if IMGUI_DEBUG_NAV_SCORING
- char buf[128];
- if (ImGui::IsMouseHoveringRect(cand.Min, cand.Max))
+ // Keyboard: Focus
+ if (g.NavWindowingTarget && g.NavInputSource == ImGuiInputSource_NavKeyboard)
{
- ImFormatString(buf, IM_ARRAYSIZE(buf), "dbox (%.2f,%.2f->%.4f)\ndcen (%.2f,%.2f->%.4f)\nd (%.2f,%.2f->%.4f)\nnav %c, quadrant %c", dbx, dby, dist_box, dcx, dcy, dist_center, dax, day, dist_axial, "WENS"[g.NavMoveDir], "WENS"[quadrant]);
- ImDrawList* draw_list = ImGui::GetOverlayDrawList(window);
- draw_list->AddRect(curr.Min, curr.Max, IM_COL32(255,200,0,100));
- draw_list->AddRect(cand.Min, cand.Max, IM_COL32(255,255,0,200));
- draw_list->AddRectFilled(cand.Max-ImVec2(4,4), cand.Max+ImGui::CalcTextSize(buf)+ImVec2(4,4), IM_COL32(40,0,0,150));
- draw_list->AddText(g.IO.FontDefault, 13.0f, cand.Max, ~0U, buf);
+ // Visuals only appears after a brief time after pressing TAB the first time, so that a fast CTRL+TAB doesn't add visual noise
+ g.NavWindowingHighlightAlpha = ImMax(g.NavWindowingHighlightAlpha, ImSaturate((g.NavWindowingTimer - NAV_WINDOWING_HIGHLIGHT_DELAY) / 0.05f)); // 1.0f
+ if (IsKeyPressedMap(ImGuiKey_Tab, true))
+ NavUpdateWindowingHighlightWindow(g.IO.KeyShift ? +1 : -1);
+ if (!g.IO.KeyCtrl)
+ apply_focus_window = g.NavWindowingTarget;
}
- else if (g.IO.KeyCtrl) // Hold to preview score in matching quadrant. Press C to rotate.
+
+ // Keyboard: Press and Release ALT to toggle menu layer
+ // FIXME: We lack an explicit IO variable for "is the imgui window focused", so compare mouse validity to detect the common case of back-end clearing releases all keys on ALT-TAB
+ if (IsNavInputPressed(ImGuiNavInput_KeyMenu_, ImGuiInputReadMode_Pressed))
+ g.NavWindowingToggleLayer = true;
+ if ((g.ActiveId == 0 || g.ActiveIdAllowOverlap) && g.NavWindowingToggleLayer && IsNavInputPressed(ImGuiNavInput_KeyMenu_, ImGuiInputReadMode_Released))
+ if (IsMousePosValid(&g.IO.MousePos) == IsMousePosValid(&g.IO.MousePosPrev))
+ apply_toggle_layer = true;
+
+ // Move window
+ if (g.NavWindowingTarget && !(g.NavWindowingTarget->Flags & ImGuiWindowFlags_NoMove))
{
- if (ImGui::IsKeyPressedMap(ImGuiKey_C)) { g.NavMoveDirLast = (ImGuiDir)((g.NavMoveDirLast + 1) & 3); g.IO.KeysDownDuration[g.IO.KeyMap[ImGuiKey_C]] = 0.01f; }
- if (quadrant == g.NavMoveDir)
+ ImVec2 move_delta;
+ if (g.NavInputSource == ImGuiInputSource_NavKeyboard && !g.IO.KeyShift)
+ move_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_Keyboard, ImGuiInputReadMode_Down);
+ if (g.NavInputSource == ImGuiInputSource_NavGamepad)
+ move_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_PadLStick, ImGuiInputReadMode_Down);
+ if (move_delta.x != 0.0f || move_delta.y != 0.0f)
{
- ImFormatString(buf, IM_ARRAYSIZE(buf), "%.0f/%.0f", dist_box, dist_center);
- ImDrawList* draw_list = ImGui::GetOverlayDrawList(window);
- draw_list->AddRectFilled(cand.Min, cand.Max, IM_COL32(255, 0, 0, 200));
- draw_list->AddText(g.IO.FontDefault, 13.0f, cand.Min, IM_COL32(255, 255, 255, 255), buf);
+ const float NAV_MOVE_SPEED = 800.0f;
+ const float move_speed = ImFloor(NAV_MOVE_SPEED * g.IO.DeltaTime * ImMin(g.IO.DisplayFramebufferScale.x, g.IO.DisplayFramebufferScale.y)); // FIXME: Doesn't code variable framerate very well
+ SetWindowPos(g.NavWindowingTarget->RootWindow, g.NavWindowingTarget->RootWindow->Pos + move_delta * move_speed, ImGuiCond_Always);
+ g.NavDisableMouseHover = true;
+ MarkIniSettingsDirty(g.NavWindowingTarget);
}
}
- #endif
- // Is it in the quadrant we're interesting in moving to?
- bool new_best = false;
- if (quadrant == g.NavMoveDir)
+ // Apply final focus
+ if (apply_focus_window && (g.NavWindow == NULL || apply_focus_window != g.NavWindow->RootWindowDockStop))
{
- // Does it beat the current best candidate?
- if (dist_box < result->DistBox)
- {
- result->DistBox = dist_box;
- result->DistCenter = dist_center;
- return true;
- }
- if (dist_box == result->DistBox)
- {
- // Try using distance between center points to break ties
- if (dist_center < result->DistCenter)
- {
- result->DistCenter = dist_center;
- new_best = true;
- }
- else if (dist_center == result->DistCenter)
- {
- // Still tied! we need to be extra-careful to make sure everything gets linked properly. We consistently break ties by symbolically moving "later" items
- // (with higher index) to the right/downwards by an infinitesimal amount since we the current "best" button already (so it must have a lower index),
- // this is fairly easy. This rule ensures that all buttons with dx==dy==0 will end up being linked in order of appearance along the x axis.
- if (((g.NavMoveDir == ImGuiDir_Up || g.NavMoveDir == ImGuiDir_Down) ? dby : dbx) < 0.0f) // moving bj to the right/down decreases distance
- new_best = true;
- }
- }
- }
-
- // Axial check: if 'curr' has no link at all in some direction and 'cand' lies roughly in that direction, add a tentative link. This will only be kept if no "real" matches
- // are found, so it only augments the graph produced by the above method using extra links. (important, since it doesn't guarantee strong connectedness)
- // This is just to avoid buttons having no links in a particular direction when there's a suitable neighbor. you get good graphs without this too.
- // 2017/09/29: FIXME: This now currently only enabled inside menu bars, ideally we'd disable it everywhere. Menus in particular need to catch failure. For general navigation it feels awkward.
- // Disabling it may lead to disconnected graphs when nodes are very spaced out on different axis. Perhaps consider offering this as an option?
- if (result->DistBox == FLT_MAX && dist_axial < result->DistAxial) // Check axial match
- if (g.NavLayer == 1 && !(g.NavWindow->Flags & ImGuiWindowFlags_ChildMenu))
- if ((g.NavMoveDir == ImGuiDir_Left && dax < 0.0f) || (g.NavMoveDir == ImGuiDir_Right && dax > 0.0f) || (g.NavMoveDir == ImGuiDir_Up && day < 0.0f) || (g.NavMoveDir == ImGuiDir_Down && day > 0.0f))
- {
- result->DistAxial = dist_axial;
- new_best = true;
- }
-
- return new_best;
-}
-
-// We get there when either NavId == id, or when g.NavAnyRequest is set (which is updated by NavUpdateAnyRequestFlag above)
-static void ImGui::NavProcessItem(ImGuiWindow* window, const ImRect& nav_bb, const ImGuiID id)
-{
- ImGuiContext& g = *GImGui;
- //if (!g.IO.NavActive) // [2017/10/06] Removed this possibly redundant test but I am not sure of all the side-effects yet. Some of the feature here will need to work regardless of using a _NoNavInputs flag.
- // return;
+ ImGuiViewport* previous_viewport = g.NavWindow ? g.NavWindow->Viewport : NULL;
+ ClearActiveID();
+ g.NavDisableHighlight = false;
+ g.NavDisableMouseHover = true;
+ apply_focus_window = NavRestoreLastChildNavWindow(apply_focus_window);
+ ClosePopupsOverWindow(apply_focus_window, false);
+ FocusWindow(apply_focus_window);
+ if (apply_focus_window->NavLastIds[0] == 0)
+ NavInitWindow(apply_focus_window, false);
- const ImGuiItemFlags item_flags = window->DC.ItemFlags;
- const ImRect nav_bb_rel(nav_bb.Min - window->Pos, nav_bb.Max - window->Pos);
+ // If the window only has a menu layer, select it directly
+ if (apply_focus_window->DC.NavLayerActiveMask == (1 << ImGuiNavLayer_Menu))
+ g.NavLayer = ImGuiNavLayer_Menu;
- // Process Init Request
- if (g.NavInitRequest && g.NavLayer == window->DC.NavLayerCurrent)
- {
- // Even if 'ImGuiItemFlags_NoNavDefaultFocus' is on (typically collapse/close button) we record the first ResultId so they can be used as a fallback
- if (!(item_flags & ImGuiItemFlags_NoNavDefaultFocus) || g.NavInitResultId == 0)
- {
- g.NavInitResultId = id;
- g.NavInitResultRectRel = nav_bb_rel;
- }
- if (!(item_flags & ImGuiItemFlags_NoNavDefaultFocus))
- {
- g.NavInitRequest = false; // Found a match, clear request
- NavUpdateAnyRequestFlag();
- }
+ // Request OS level focus
+ if (apply_focus_window->Viewport != previous_viewport && g.PlatformIO.Platform_SetWindowFocus)
+ g.PlatformIO.Platform_SetWindowFocus(apply_focus_window->Viewport);
}
+ if (apply_focus_window)
+ g.NavWindowingTarget = NULL;
- // Process Move Request (scoring for navigation)
- // FIXME-NAV: Consider policy for double scoring (scoring from NavScoringRectScreen + scoring from a rect wrapped according to current wrapping policy)
- if ((g.NavId != id || (g.NavMoveRequestFlags & ImGuiNavMoveFlags_AllowCurrentNavId)) && !(item_flags & ImGuiItemFlags_NoNav))
+ // Apply menu/layer toggle
+ if (apply_toggle_layer && g.NavWindow)
{
- ImGuiNavMoveResult* result = (window == g.NavWindow) ? &g.NavMoveResultLocal : &g.NavMoveResultOther;
-#if IMGUI_DEBUG_NAV_SCORING
- // [DEBUG] Score all items in NavWindow at all times
- if (!g.NavMoveRequest)
- g.NavMoveDir = g.NavMoveDirLast;
- bool new_best = NavScoreItem(result, nav_bb) && g.NavMoveRequest;
-#else
- bool new_best = g.NavMoveRequest && NavScoreItem(result, nav_bb);
-#endif
- if (new_best)
+ // Move to parent menu if necessary
+ ImGuiWindow* new_nav_window = g.NavWindow;
+ while (new_nav_window->ParentWindow
+ && (new_nav_window->DC.NavLayerActiveMask & (1 << ImGuiNavLayer_Menu)) == 0
+ && (new_nav_window->Flags & ImGuiWindowFlags_ChildWindow) != 0
+ && (new_nav_window->Flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_ChildMenu)) == 0)
+ new_nav_window = new_nav_window->ParentWindow;
+ if (new_nav_window != g.NavWindow)
{
- result->ID = id;
- result->Window = window;
- result->RectRel = nav_bb_rel;
+ ImGuiWindow* old_nav_window = g.NavWindow;
+ FocusWindow(new_nav_window);
+ new_nav_window->NavLastChildNavWindow = old_nav_window;
}
+ g.NavDisableHighlight = false;
+ g.NavDisableMouseHover = true;
- const float VISIBLE_RATIO = 0.70f;
- if ((g.NavMoveRequestFlags & ImGuiNavMoveFlags_AlsoScoreVisibleSet) && window->ClipRect.Overlaps(nav_bb))
- if (ImClamp(nav_bb.Max.y, window->ClipRect.Min.y, window->ClipRect.Max.y) - ImClamp(nav_bb.Min.y, window->ClipRect.Min.y, window->ClipRect.Max.y) >= (nav_bb.Max.y - nav_bb.Min.y) * VISIBLE_RATIO)
- if (NavScoreItem(&g.NavMoveResultLocalVisibleSet, nav_bb))
- {
- result = &g.NavMoveResultLocalVisibleSet;
- result->ID = id;
- result->Window = window;
- result->RectRel = nav_bb_rel;
- }
- }
-
- // Update window-relative bounding box of navigated item
- if (g.NavId == id)
- {
- g.NavWindow = window; // Always refresh g.NavWindow, because some operations such as FocusItem() don't have a window.
- g.NavLayer = window->DC.NavLayerCurrent;
- g.NavIdIsAlive = true;
- g.NavIdTabCounter = window->FocusIdxTabCounter;
- window->NavRectRel[window->DC.NavLayerCurrent] = nav_bb_rel; // Store item bounding box (relative to window position)
+ // When entering a regular menu bar with the Alt key, we always reinitialize the navigation ID. It however persist on docking tab tabs.
+ const ImGuiNavLayer new_nav_layer = (g.NavWindow->DC.NavLayerActiveMask & (1 << ImGuiNavLayer_Menu)) ? (ImGuiNavLayer)((int)g.NavLayer ^ 1) : ImGuiNavLayer_Main;
+ const bool preserve_layer_1_nav_id = (new_nav_window->DockNodeAsHost != NULL);
+ if (new_nav_layer == ImGuiNavLayer_Menu && !preserve_layer_1_nav_id)
+ g.NavWindow->NavLastIds[ImGuiNavLayer_Menu] = 0;
+ NavRestoreLayer(new_nav_layer);
}
}
-bool ImGui::NavMoveRequestButNoResultYet()
-{
- ImGuiContext& g = *GImGui;
- return g.NavMoveRequest && g.NavMoveResultLocal.ID == 0 && g.NavMoveResultOther.ID == 0;
-}
-
-void ImGui::NavMoveRequestCancel()
+// Window has already passed the IsWindowNavFocusable()
+static const char* GetFallbackWindowNameForWindowingList(ImGuiWindow* window)
{
- ImGuiContext& g = *GImGui;
- g.NavMoveRequest = false;
- NavUpdateAnyRequestFlag();
+ if (window->Flags & ImGuiWindowFlags_Popup)
+ return "(Popup)";
+ if ((window->Flags & ImGuiWindowFlags_MenuBar) && strcmp(window->Name, "##MainMenuBar") == 0)
+ return "(Main menu bar)";
+ if (window->DockNodeAsHost)
+ return "(Dock node)";
+ return "(Untitled)";
}
-void ImGui::NavMoveRequestForward(ImGuiDir move_dir, ImGuiDir clip_dir, const ImRect& bb_rel, ImGuiNavMoveFlags move_flags)
+// Overlay displayed when using CTRL+TAB. Called by EndFrame().
+void ImGui::NavUpdateWindowingList()
{
ImGuiContext& g = *GImGui;
- IM_ASSERT(g.NavMoveRequestForward == ImGuiNavForward_None);
- ImGui::NavMoveRequestCancel();
- g.NavMoveDir = move_dir;
- g.NavMoveClipDir = clip_dir;
- g.NavMoveRequestForward = ImGuiNavForward_ForwardQueued;
- g.NavMoveRequestFlags = move_flags;
- g.NavWindow->NavRectRel[g.NavLayer] = bb_rel;
-}
+ IM_ASSERT(g.NavWindowingTarget != NULL);
-void ImGui::NavMoveRequestTryWrapping(ImGuiWindow* window, ImGuiNavMoveFlags move_flags)
-{
- ImGuiContext& g = *GImGui;
- if (g.NavWindow != window || !NavMoveRequestButNoResultYet() || g.NavMoveRequestForward != ImGuiNavForward_None || g.NavLayer != 0)
+ if (g.NavWindowingTimer < NAV_WINDOWING_LIST_APPEAR_DELAY)
return;
- IM_ASSERT(move_flags != 0); // No points calling this with no wrapping
- ImRect bb_rel = window->NavRectRel[0];
- ImGuiDir clip_dir = g.NavMoveDir;
- if (g.NavMoveDir == ImGuiDir_Left && (move_flags & (ImGuiNavMoveFlags_WrapX | ImGuiNavMoveFlags_LoopX)))
- {
- bb_rel.Min.x = bb_rel.Max.x = ImMax(window->SizeFull.x, window->SizeContents.x) - window->Scroll.x;
- if (move_flags & ImGuiNavMoveFlags_WrapX) { bb_rel.TranslateY(-bb_rel.GetHeight()); clip_dir = ImGuiDir_Up; }
- NavMoveRequestForward(g.NavMoveDir, clip_dir, bb_rel, move_flags);
- }
- if (g.NavMoveDir == ImGuiDir_Right && (move_flags & (ImGuiNavMoveFlags_WrapX | ImGuiNavMoveFlags_LoopX)))
- {
- bb_rel.Min.x = bb_rel.Max.x = -window->Scroll.x;
- if (move_flags & ImGuiNavMoveFlags_WrapX) { bb_rel.TranslateY(+bb_rel.GetHeight()); clip_dir = ImGuiDir_Down; }
- NavMoveRequestForward(g.NavMoveDir, clip_dir, bb_rel, move_flags);
- }
- if (g.NavMoveDir == ImGuiDir_Up && (move_flags & (ImGuiNavMoveFlags_WrapY | ImGuiNavMoveFlags_LoopY)))
- {
- bb_rel.Min.y = bb_rel.Max.y = ImMax(window->SizeFull.y, window->SizeContents.y) - window->Scroll.y;
- if (move_flags & ImGuiNavMoveFlags_WrapY) { bb_rel.TranslateX(-bb_rel.GetWidth()); clip_dir = ImGuiDir_Left; }
- NavMoveRequestForward(g.NavMoveDir, clip_dir, bb_rel, move_flags);
- }
- if (g.NavMoveDir == ImGuiDir_Down && (move_flags & (ImGuiNavMoveFlags_WrapY | ImGuiNavMoveFlags_LoopY)))
+ if (g.NavWindowingList == NULL)
+ g.NavWindowingList = FindWindowByName("###NavWindowingList");
+ ImGuiViewportP* viewport = /*g.NavWindow ? g.NavWindow->Viewport :*/ (ImGuiViewportP*)GetMainViewport();
+ SetNextWindowSizeConstraints(ImVec2(viewport->Size.x * 0.20f, viewport->Size.y * 0.20f), ImVec2(FLT_MAX, FLT_MAX));
+ SetNextWindowPos(viewport->Pos + viewport->Size * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
+ PushStyleVar(ImGuiStyleVar_WindowPadding, g.Style.WindowPadding * 2.0f);
+ Begin("###NavWindowingList", NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings);
+ for (int n = g.WindowsFocusOrder.Size - 1; n >= 0; n--)
{
- bb_rel.Min.y = bb_rel.Max.y = -window->Scroll.y;
- if (move_flags & ImGuiNavMoveFlags_WrapY) { bb_rel.TranslateX(+bb_rel.GetWidth()); clip_dir = ImGuiDir_Right; }
- NavMoveRequestForward(g.NavMoveDir, clip_dir, bb_rel, move_flags);
+ ImGuiWindow* window = g.WindowsFocusOrder[n];
+ if (!IsWindowNavFocusable(window))
+ continue;
+ const char* label = window->Name;
+ if (label == FindRenderedTextEnd(label))
+ label = GetFallbackWindowNameForWindowingList(window);
+ Selectable(label, g.NavWindowingTarget == window);
}
+ End();
+ PopStyleVar();
}
-static void ImGui::NavSaveLastChildNavWindow(ImGuiWindow* nav_window)
-{
- ImGuiWindow* parent_window = nav_window;
- while (parent_window && (parent_window->Flags & ImGuiWindowFlags_ChildWindow) != 0 && (parent_window->Flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_ChildMenu)) == 0)
- parent_window = parent_window->ParentWindow;
- if (parent_window && parent_window != nav_window)
- parent_window->NavLastChildNavWindow = nav_window;
-}
-// Call when we are expected to land on Layer 0 after FocusWindow()
-static ImGuiWindow* ImGui::NavRestoreLastChildNavWindow(ImGuiWindow* window)
-{
- return window->NavLastChildNavWindow ? window->NavLastChildNavWindow : window;
-}
+//-----------------------------------------------------------------------------
+// [SECTION] DRAG AND DROP
+//-----------------------------------------------------------------------------
-static void NavRestoreLayer(ImGuiNavLayer layer)
+void ImGui::ClearDragDrop()
{
ImGuiContext& g = *GImGui;
- g.NavLayer = layer;
- if (layer == 0)
- g.NavWindow = ImGui::NavRestoreLastChildNavWindow(g.NavWindow);
- if (g.NavWindow->NavLastIds[layer] != 0)
- ImGui::SetNavIDWithRectRel(g.NavWindow->NavLastIds[layer], layer, g.NavWindow->NavRectRel[layer]);
- else
- ImGui::NavInitWindow(g.NavWindow, true);
-}
+ g.DragDropActive = false;
+ g.DragDropPayload.Clear();
+ g.DragDropAcceptFlags = ImGuiDragDropFlags_None;
+ g.DragDropAcceptIdCurr = g.DragDropAcceptIdPrev = 0;
+ g.DragDropAcceptIdCurrRectSurface = FLT_MAX;
+ g.DragDropAcceptFrameCount = -1;
-static inline void ImGui::NavUpdateAnyRequestFlag()
-{
- ImGuiContext& g = *GImGui;
- g.NavAnyRequest = g.NavMoveRequest || g.NavInitRequest || (IMGUI_DEBUG_NAV_SCORING && g.NavWindow != NULL);
- if (g.NavAnyRequest)
- IM_ASSERT(g.NavWindow != NULL);
+ g.DragDropPayloadBufHeap.clear();
+ memset(&g.DragDropPayloadBufLocal, 0, sizeof(g.DragDropPayloadBufLocal));
}
-// This needs to be called before we submit any widget (aka in or before Begin)
-void ImGui::NavInitWindow(ImGuiWindow* window, bool force_reinit)
+// Call when current ID is active.
+// When this returns true you need to: a) call SetDragDropPayload() exactly once, b) you may render the payload visual/description, c) call EndDragDropSource()
+bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags)
{
ImGuiContext& g = *GImGui;
- IM_ASSERT(window == g.NavWindow);
- bool init_for_nav = false;
- if (!(window->Flags & ImGuiWindowFlags_NoNavInputs))
- if (!(window->Flags & ImGuiWindowFlags_ChildWindow) || (window->Flags & ImGuiWindowFlags_Popup) || (window->NavLastIds[0] == 0) || force_reinit)
- init_for_nav = true;
- if (init_for_nav)
- {
- SetNavID(0, g.NavLayer);
- g.NavInitRequest = true;
- g.NavInitRequestFromMove = false;
- g.NavInitResultId = 0;
- g.NavInitResultRectRel = ImRect();
- NavUpdateAnyRequestFlag();
+ ImGuiWindow* window = g.CurrentWindow;
+
+ bool source_drag_active = false;
+ ImGuiID source_id = 0;
+ ImGuiID source_parent_id = 0;
+ int mouse_button = 0;
+ if (!(flags & ImGuiDragDropFlags_SourceExtern))
+ {
+ source_id = window->DC.LastItemId;
+ if (source_id != 0 && g.ActiveId != source_id) // Early out for most common case
+ return false;
+ if (g.IO.MouseDown[mouse_button] == false)
+ return false;
+
+ if (source_id == 0)
+ {
+ // If you want to use BeginDragDropSource() on an item with no unique identifier for interaction, such as Text() or Image(), you need to:
+ // A) Read the explanation below, B) Use the ImGuiDragDropFlags_SourceAllowNullID flag, C) Swallow your programmer pride.
+ if (!(flags & ImGuiDragDropFlags_SourceAllowNullID))
+ {
+ IM_ASSERT(0);
+ return false;
+ }
+
+ // Early out
+ if ((window->DC.LastItemStatusFlags & ImGuiItemStatusFlags_HoveredRect) == 0 && (g.ActiveId == 0 || g.ActiveIdWindow != window))
+ return false;
+
+ // Magic fallback (=somehow reprehensible) to handle items with no assigned ID, e.g. Text(), Image()
+ // We build a throwaway ID based on current ID stack + relative AABB of items in window.
+ // THE IDENTIFIER WON'T SURVIVE ANY REPOSITIONING OF THE WIDGET, so if your widget moves your dragging operation will be canceled.
+ // We don't need to maintain/call ClearActiveID() as releasing the button will early out this function and trigger !ActiveIdIsAlive.
+ source_id = window->DC.LastItemId = window->GetIDFromRectangle(window->DC.LastItemRect);
+ bool is_hovered = ItemHoverable(window->DC.LastItemRect, source_id);
+ if (is_hovered && g.IO.MouseClicked[mouse_button])
+ {
+ SetActiveID(source_id, window);
+ FocusWindow(window);
+ }
+ if (g.ActiveId == source_id) // Allow the underlying widget to display/return hovered during the mouse release frame, else we would get a flicker.
+ g.ActiveIdAllowOverlap = is_hovered;
+ }
+ else
+ {
+ g.ActiveIdAllowOverlap = false;
+ }
+ if (g.ActiveId != source_id)
+ return false;
+ source_parent_id = window->IDStack.back();
+ source_drag_active = IsMouseDragging(mouse_button);
}
else
{
- g.NavId = window->NavLastIds[0];
+ window = NULL;
+ source_id = ImHashStr("#SourceExtern");
+ source_drag_active = true;
}
-}
-static ImVec2 ImGui::NavCalcPreferredRefPos()
-{
- ImGuiContext& g = *GImGui;
- if (g.NavDisableHighlight || !g.NavDisableMouseHover || !g.NavWindow)
- {
- // Mouse (we need a fallback in case the mouse becomes invalid after being used)
- if (IsMousePosValid(&g.IO.MousePos))
- return g.IO.MousePos;
- return g.LastValidMousePos;
- }
- else
+ if (source_drag_active)
{
- // When navigation is active and mouse is disabled, decide on an arbitrary position around the bottom left of the currently navigated item.
- const ImRect& rect_rel = g.NavWindow->NavRectRel[g.NavLayer];
- ImVec2 pos = g.NavWindow->Pos + ImVec2(rect_rel.Min.x + ImMin(g.Style.FramePadding.x * 4, rect_rel.GetWidth()), rect_rel.Max.y - ImMin(g.Style.FramePadding.y, rect_rel.GetHeight()));
- ImRect visible_rect = g.NavWindow->Viewport->GetRect();
- return ImFloor(ImClamp(pos, visible_rect.Min, visible_rect.Max)); // ImFloor() is important because non-integer mouse position application in back-end might be lossy and result in undesirable non-zero delta.
+ if (!g.DragDropActive)
+ {
+ IM_ASSERT(source_id != 0);
+ ClearDragDrop();
+ ImGuiPayload& payload = g.DragDropPayload;
+ payload.SourceId = source_id;
+ payload.SourceParentId = source_parent_id;
+ g.DragDropActive = true;
+ g.DragDropSourceFlags = flags;
+ g.DragDropMouseButton = mouse_button;
+ }
+ g.DragDropSourceFrameCount = g.FrameCount;
+ g.DragDropWithinSourceOrTarget = true;
+
+ if (!(flags & ImGuiDragDropFlags_SourceNoPreviewTooltip))
+ {
+ // Target can request the Source to not display its tooltip (we use a dedicated flag to make this request explicit)
+ // We unfortunately can't just modify the source flags and skip the call to BeginTooltip, as caller may be emitting contents.
+ BeginTooltip();
+ if (g.DragDropAcceptIdPrev && (g.DragDropAcceptFlags & ImGuiDragDropFlags_AcceptNoPreviewTooltip))
+ {
+ ImGuiWindow* tooltip_window = g.CurrentWindow;
+ tooltip_window->SkipItems = true;
+ tooltip_window->HiddenFramesCanSkipItems = 1;
+ }
+ }
+
+ if (!(flags & ImGuiDragDropFlags_SourceNoDisableHover) && !(flags & ImGuiDragDropFlags_SourceExtern))
+ window->DC.LastItemStatusFlags &= ~ImGuiItemStatusFlags_HoveredRect;
+
+ return true;
}
+ return false;
}
-float ImGui::GetNavInputAmount(ImGuiNavInput n, ImGuiInputReadMode mode)
+void ImGui::EndDragDropSource()
{
ImGuiContext& g = *GImGui;
- if (mode == ImGuiInputReadMode_Down)
- return g.IO.NavInputs[n]; // Instant, read analog input (0.0f..1.0f, as provided by user)
+ IM_ASSERT(g.DragDropActive);
+ IM_ASSERT(g.DragDropWithinSourceOrTarget && "Not after a BeginDragDropSource()?");
- const float t = g.IO.NavInputsDownDuration[n];
- if (t < 0.0f && mode == ImGuiInputReadMode_Released) // Return 1.0f when just released, no repeat, ignore analog input.
- return (g.IO.NavInputsDownDurationPrev[n] >= 0.0f ? 1.0f : 0.0f);
- if (t < 0.0f)
- return 0.0f;
- if (mode == ImGuiInputReadMode_Pressed) // Return 1.0f when just pressed, no repeat, ignore analog input.
- return (t == 0.0f) ? 1.0f : 0.0f;
- if (mode == ImGuiInputReadMode_Repeat)
- return (float)CalcTypematicPressedRepeatAmount(t, t - g.IO.DeltaTime, g.IO.KeyRepeatDelay * 0.80f, g.IO.KeyRepeatRate * 0.80f);
- if (mode == ImGuiInputReadMode_RepeatSlow)
- return (float)CalcTypematicPressedRepeatAmount(t, t - g.IO.DeltaTime, g.IO.KeyRepeatDelay * 1.00f, g.IO.KeyRepeatRate * 2.00f);
- if (mode == ImGuiInputReadMode_RepeatFast)
- return (float)CalcTypematicPressedRepeatAmount(t, t - g.IO.DeltaTime, g.IO.KeyRepeatDelay * 0.80f, g.IO.KeyRepeatRate * 0.30f);
- return 0.0f;
-}
+ if (!(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoPreviewTooltip))
+ EndTooltip();
-ImVec2 ImGui::GetNavInputAmount2d(ImGuiNavDirSourceFlags dir_sources, ImGuiInputReadMode mode, float slow_factor, float fast_factor)
-{
- ImVec2 delta(0.0f, 0.0f);
- if (dir_sources & ImGuiNavDirSourceFlags_Keyboard)
- delta += ImVec2(GetNavInputAmount(ImGuiNavInput_KeyRight_, mode) - GetNavInputAmount(ImGuiNavInput_KeyLeft_, mode), GetNavInputAmount(ImGuiNavInput_KeyDown_, mode) - GetNavInputAmount(ImGuiNavInput_KeyUp_, mode));
- if (dir_sources & ImGuiNavDirSourceFlags_PadDPad)
- delta += ImVec2(GetNavInputAmount(ImGuiNavInput_DpadRight, mode) - GetNavInputAmount(ImGuiNavInput_DpadLeft, mode), GetNavInputAmount(ImGuiNavInput_DpadDown, mode) - GetNavInputAmount(ImGuiNavInput_DpadUp, mode));
- if (dir_sources & ImGuiNavDirSourceFlags_PadLStick)
- delta += ImVec2(GetNavInputAmount(ImGuiNavInput_LStickRight, mode) - GetNavInputAmount(ImGuiNavInput_LStickLeft, mode), GetNavInputAmount(ImGuiNavInput_LStickDown, mode) - GetNavInputAmount(ImGuiNavInput_LStickUp, mode));
- if (slow_factor != 0.0f && IsNavInputDown(ImGuiNavInput_TweakSlow))
- delta *= slow_factor;
- if (fast_factor != 0.0f && IsNavInputDown(ImGuiNavInput_TweakFast))
- delta *= fast_factor;
- return delta;
+ // Discard the drag if have not called SetDragDropPayload()
+ if (g.DragDropPayload.DataFrameCount == -1)
+ ClearDragDrop();
+ g.DragDropWithinSourceOrTarget = false;
}
-// Scroll to keep newly navigated item fully into view
-// NB: We modify rect_rel by the amount we scrolled for, so it is immediately updated.
-static void NavScrollToBringItemIntoView(ImGuiWindow* window, const ImRect& item_rect)
+// Use 'cond' to choose to submit payload on drag start or every frame
+bool ImGui::SetDragDropPayload(const char* type, const void* data, size_t data_size, ImGuiCond cond)
{
- ImRect window_rect(window->InnerMainRect.Min - ImVec2(1, 1), window->InnerMainRect.Max + ImVec2(1, 1));
- //GetOverlayDrawList(window)->AddRect(window_rect.Min, window_rect.Max, IM_COL32_WHITE); // [DEBUG]
- if (window_rect.Contains(item_rect))
- return;
-
ImGuiContext& g = *GImGui;
- if (window->ScrollbarX && item_rect.Min.x < window_rect.Min.x)
- {
- window->ScrollTarget.x = item_rect.Min.x - window->Pos.x + window->Scroll.x - g.Style.ItemSpacing.x;
- window->ScrollTargetCenterRatio.x = 0.0f;
- }
- else if (window->ScrollbarX && item_rect.Max.x >= window_rect.Max.x)
- {
- window->ScrollTarget.x = item_rect.Max.x - window->Pos.x + window->Scroll.x + g.Style.ItemSpacing.x;
- window->ScrollTargetCenterRatio.x = 1.0f;
- }
- if (item_rect.Min.y < window_rect.Min.y)
- {
- window->ScrollTarget.y = item_rect.Min.y - window->Pos.y + window->Scroll.y - g.Style.ItemSpacing.y;
- window->ScrollTargetCenterRatio.y = 0.0f;
- }
- else if (item_rect.Max.y >= window_rect.Max.y)
+ ImGuiPayload& payload = g.DragDropPayload;
+ if (cond == 0)
+ cond = ImGuiCond_Always;
+
+ IM_ASSERT(type != NULL);
+ IM_ASSERT(strlen(type) < IM_ARRAYSIZE(payload.DataType) && "Payload type can be at most 32 characters long");
+ IM_ASSERT((data != NULL && data_size > 0) || (data == NULL && data_size == 0));
+ IM_ASSERT(cond == ImGuiCond_Always || cond == ImGuiCond_Once);
+ IM_ASSERT(payload.SourceId != 0); // Not called between BeginDragDropSource() and EndDragDropSource()
+
+ if (cond == ImGuiCond_Always || payload.DataFrameCount == -1)
{
- window->ScrollTarget.y = item_rect.Max.y - window->Pos.y + window->Scroll.y + g.Style.ItemSpacing.y;
- window->ScrollTargetCenterRatio.y = 1.0f;
+ // Copy payload
+ ImStrncpy(payload.DataType, type, IM_ARRAYSIZE(payload.DataType));
+ g.DragDropPayloadBufHeap.resize(0);
+ if (data_size > sizeof(g.DragDropPayloadBufLocal))
+ {
+ // Store in heap
+ g.DragDropPayloadBufHeap.resize((int)data_size);
+ payload.Data = g.DragDropPayloadBufHeap.Data;
+ memcpy(payload.Data, data, data_size);
+ }
+ else if (data_size > 0)
+ {
+ // Store locally
+ memset(&g.DragDropPayloadBufLocal, 0, sizeof(g.DragDropPayloadBufLocal));
+ payload.Data = g.DragDropPayloadBufLocal;
+ memcpy(payload.Data, data, data_size);
+ }
+ else
+ {
+ payload.Data = NULL;
+ }
+ payload.DataSize = (int)data_size;
}
+ payload.DataFrameCount = g.FrameCount;
+
+ return (g.DragDropAcceptFrameCount == g.FrameCount) || (g.DragDropAcceptFrameCount == g.FrameCount - 1);
}
-static void ImGui::NavUpdate()
+bool ImGui::BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id)
{
ImGuiContext& g = *GImGui;
- g.IO.WantSetMousePos = false;
-#if 0
- if (g.NavScoringCount > 0) IMGUI_DEBUG_LOG("NavScoringCount %d for '%s' layer %d (Init:%d, Move:%d)\n", g.FrameCount, g.NavScoringCount, g.NavWindow ? g.NavWindow->Name : "NULL", g.NavLayer, g.NavInitRequest || g.NavInitResultId != 0, g.NavMoveRequest);
-#endif
+ if (!g.DragDropActive)
+ return false;
- // Set input source as Gamepad when buttons are pressed before we map Keyboard (some features differs when used with Gamepad vs Keyboard)
- bool nav_keyboard_active = (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0;
- bool nav_gamepad_active = (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (g.IO.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0;
- if (nav_gamepad_active)
- if (g.IO.NavInputs[ImGuiNavInput_Activate] > 0.0f || g.IO.NavInputs[ImGuiNavInput_Input] > 0.0f || g.IO.NavInputs[ImGuiNavInput_Cancel] > 0.0f || g.IO.NavInputs[ImGuiNavInput_Menu] > 0.0f)
- g.NavInputSource = ImGuiInputSource_NavGamepad;
+ ImGuiWindow* window = g.CurrentWindow;
+ if (g.HoveredWindowUnderMovingWindow == NULL || window->RootWindow != g.HoveredWindowUnderMovingWindow->RootWindow)
+ return false;
+ IM_ASSERT(id != 0);
+ if (!IsMouseHoveringRect(bb.Min, bb.Max) || (id == g.DragDropPayload.SourceId))
+ return false;
+ if (window->SkipItems)
+ return false;
- // Update Keyboard->Nav inputs mapping
- if (nav_keyboard_active)
- {
- #define NAV_MAP_KEY(_KEY, _NAV_INPUT) if (IsKeyDown(g.IO.KeyMap[_KEY])) { g.IO.NavInputs[_NAV_INPUT] = 1.0f; g.NavInputSource = ImGuiInputSource_NavKeyboard; }
- NAV_MAP_KEY(ImGuiKey_Space, ImGuiNavInput_Activate );
- NAV_MAP_KEY(ImGuiKey_Enter, ImGuiNavInput_Input );
- NAV_MAP_KEY(ImGuiKey_Escape, ImGuiNavInput_Cancel );
- NAV_MAP_KEY(ImGuiKey_LeftArrow, ImGuiNavInput_KeyLeft_ );
- NAV_MAP_KEY(ImGuiKey_RightArrow,ImGuiNavInput_KeyRight_);
- NAV_MAP_KEY(ImGuiKey_UpArrow, ImGuiNavInput_KeyUp_ );
- NAV_MAP_KEY(ImGuiKey_DownArrow, ImGuiNavInput_KeyDown_ );
- if (g.IO.KeyCtrl) g.IO.NavInputs[ImGuiNavInput_TweakSlow] = 1.0f;
- if (g.IO.KeyShift) g.IO.NavInputs[ImGuiNavInput_TweakFast] = 1.0f;
- if (g.IO.KeyAlt) g.IO.NavInputs[ImGuiNavInput_KeyMenu_] = 1.0f;
- #undef NAV_MAP_KEY
- }
- memcpy(g.IO.NavInputsDownDurationPrev, g.IO.NavInputsDownDuration, sizeof(g.IO.NavInputsDownDuration));
- for (int i = 0; i < IM_ARRAYSIZE(g.IO.NavInputs); i++)
- g.IO.NavInputsDownDuration[i] = (g.IO.NavInputs[i] > 0.0f) ? (g.IO.NavInputsDownDuration[i] < 0.0f ? 0.0f : g.IO.NavInputsDownDuration[i] + g.IO.DeltaTime) : -1.0f;
+ IM_ASSERT(g.DragDropWithinSourceOrTarget == false);
+ g.DragDropTargetRect = bb;
+ g.DragDropTargetId = id;
+ g.DragDropWithinSourceOrTarget = true;
+ return true;
+}
- // Process navigation init request (select first/default focus)
- if (g.NavInitResultId != 0 && (!g.NavDisableHighlight || g.NavInitRequestFromMove))
- {
- // Apply result from previous navigation init request (will typically select the first item, unless SetItemDefaultFocus() has been called)
- IM_ASSERT(g.NavWindow);
- if (g.NavInitRequestFromMove)
- SetNavIDWithRectRel(g.NavInitResultId, g.NavLayer, g.NavInitResultRectRel);
- else
- SetNavID(g.NavInitResultId, g.NavLayer);
- g.NavWindow->NavRectRel[g.NavLayer] = g.NavInitResultRectRel;
- }
- g.NavInitRequest = false;
- g.NavInitRequestFromMove = false;
- g.NavInitResultId = 0;
- g.NavJustMovedToId = 0;
+// We don't use BeginDragDropTargetCustom() and duplicate its code because:
+// 1) we use LastItemRectHoveredRect which handles items that pushes a temporarily clip rectangle in their code. Calling BeginDragDropTargetCustom(LastItemRect) would not handle them.
+// 2) and it's faster. as this code may be very frequently called, we want to early out as fast as we can.
+// Also note how the HoveredWindow test is positioned differently in both functions (in both functions we optimize for the cheapest early out case)
+bool ImGui::BeginDragDropTarget()
+{
+ ImGuiContext& g = *GImGui;
+ if (!g.DragDropActive)
+ return false;
- // Process navigation move request
- if (g.NavMoveRequest)
- NavUpdateMoveResult();
-
- // When a forwarded move request failed, we restore the highlight that we disabled during the forward frame
- if (g.NavMoveRequestForward == ImGuiNavForward_ForwardActive)
- {
- IM_ASSERT(g.NavMoveRequest);
- if (g.NavMoveResultLocal.ID == 0 && g.NavMoveResultOther.ID == 0)
- g.NavDisableHighlight = false;
- g.NavMoveRequestForward = ImGuiNavForward_None;
- }
-
- // Apply application mouse position movement, after we had a chance to process move request result.
- if (g.NavMousePosDirty && g.NavIdIsAlive)
- {
- // Set mouse position given our knowledge of the navigated item position from last frame
- if ((g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableSetMousePos) && (g.IO.BackendFlags & ImGuiBackendFlags_HasSetMousePos))
- {
- if (!g.NavDisableHighlight && g.NavDisableMouseHover && g.NavWindow)
- {
- g.IO.MousePos = g.IO.MousePosPrev = NavCalcPreferredRefPos();
- g.IO.WantSetMousePos = true;
- }
- }
- g.NavMousePosDirty = false;
- }
- g.NavIdIsAlive = false;
- g.NavJustTabbedId = 0;
- IM_ASSERT(g.NavLayer == 0 || g.NavLayer == 1);
-
- // Store our return window (for returning from Layer 1 to Layer 0) and clear it as soon as we step back in our own Layer 0
- if (g.NavWindow)
- NavSaveLastChildNavWindow(g.NavWindow);
- if (g.NavWindow && g.NavWindow->NavLastChildNavWindow != NULL && g.NavLayer == 0)
- g.NavWindow->NavLastChildNavWindow = NULL;
-
- // Update CTRL+TAB and Windowing features (hold Square to move/resize/etc.)
- NavUpdateWindowing();
-
- // Set output flags for user application
- g.IO.NavActive = (nav_keyboard_active || nav_gamepad_active) && g.NavWindow && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs);
- g.IO.NavVisible = (g.IO.NavActive && g.NavId != 0 && !g.NavDisableHighlight) || (g.NavWindowingTarget != NULL);
-
- // Process NavCancel input (to close a popup, get back to parent, clear focus)
- if (IsNavInputPressed(ImGuiNavInput_Cancel, ImGuiInputReadMode_Pressed))
- {
- if (g.ActiveId != 0)
- {
- if (!(g.ActiveIdBlockNavInputFlags & (1 << ImGuiNavInput_Cancel)))
- ClearActiveID();
- }
- else if (g.NavWindow && (g.NavWindow->Flags & ImGuiWindowFlags_ChildWindow) && !(g.NavWindow->Flags & ImGuiWindowFlags_Popup) && g.NavWindow->ParentWindow && g.NavWindow != g.NavWindow->RootWindowDockStop)
- {
- // Exit child window
- ImGuiWindow* child_window = g.NavWindow;
- ImGuiWindow* parent_window = g.NavWindow->ParentWindow;
- IM_ASSERT(child_window->ChildId != 0);
- FocusWindow(parent_window);
- SetNavID(child_window->ChildId, 0);
- g.NavIdIsAlive = false;
- if (g.NavDisableMouseHover)
- g.NavMousePosDirty = true;
- }
- else if (g.OpenPopupStack.Size > 0)
- {
- // Close open popup/menu
- if (!(g.OpenPopupStack.back().Window->Flags & ImGuiWindowFlags_Modal))
- ClosePopupToLevel(g.OpenPopupStack.Size - 1, true);
- }
- else if (g.NavLayer != 0)
- {
- // Leave the "menu" layer
- NavRestoreLayer(ImGuiNavLayer_Main);
- }
- else
- {
- // Clear NavLastId for popups but keep it for regular child window so we can leave one and come back where we were
- if (g.NavWindow && ((g.NavWindow->Flags & ImGuiWindowFlags_Popup) || !(g.NavWindow->Flags & ImGuiWindowFlags_ChildWindow)))
- g.NavWindow->NavLastIds[0] = 0;
- g.NavId = 0;
- }
- }
-
- // Process manual activation request
- g.NavActivateId = g.NavActivateDownId = g.NavActivatePressedId = g.NavInputId = 0;
- if (g.NavId != 0 && !g.NavDisableHighlight && !g.NavWindowingTarget && g.NavWindow && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs))
- {
- bool activate_down = IsNavInputDown(ImGuiNavInput_Activate);
- bool activate_pressed = activate_down && IsNavInputPressed(ImGuiNavInput_Activate, ImGuiInputReadMode_Pressed);
- if (g.ActiveId == 0 && activate_pressed)
- g.NavActivateId = g.NavId;
- if ((g.ActiveId == 0 || g.ActiveId == g.NavId) && activate_down)
- g.NavActivateDownId = g.NavId;
- if ((g.ActiveId == 0 || g.ActiveId == g.NavId) && activate_pressed)
- g.NavActivatePressedId = g.NavId;
- if ((g.ActiveId == 0 || g.ActiveId == g.NavId) && IsNavInputPressed(ImGuiNavInput_Input, ImGuiInputReadMode_Pressed))
- g.NavInputId = g.NavId;
- }
- if (g.NavWindow && (g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs))
- g.NavDisableHighlight = true;
- if (g.NavActivateId != 0)
- IM_ASSERT(g.NavActivateDownId == g.NavActivateId);
- g.NavMoveRequest = false;
-
- // Process programmatic activation request
- if (g.NavNextActivateId != 0)
- g.NavActivateId = g.NavActivateDownId = g.NavActivatePressedId = g.NavInputId = g.NavNextActivateId;
- g.NavNextActivateId = 0;
-
- // Initiate directional inputs request
- const int allowed_dir_flags = (g.ActiveId == 0) ? ~0 : g.ActiveIdAllowNavDirFlags;
- if (g.NavMoveRequestForward == ImGuiNavForward_None)
- {
- g.NavMoveDir = ImGuiDir_None;
- g.NavMoveRequestFlags = ImGuiNavMoveFlags_None;
- if (g.NavWindow && !g.NavWindowingTarget && allowed_dir_flags && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs))
- {
- if ((allowed_dir_flags & (1<Flags & ImGuiWindowFlags_NoNavInputs) && !g.NavWindowingTarget)
- {
- // *Fallback* manual-scroll with Nav directional keys when window has no navigable item
- ImGuiWindow* window = g.NavWindow;
- const float scroll_speed = ImFloor(window->CalcFontSize() * 100 * g.IO.DeltaTime + 0.5f); // We need round the scrolling speed because sub-pixel scroll isn't reliably supported.
- if (window->DC.NavLayerActiveMask == 0x00 && window->DC.NavHasScroll && g.NavMoveRequest)
- {
- if (g.NavMoveDir == ImGuiDir_Left || g.NavMoveDir == ImGuiDir_Right)
- SetWindowScrollX(window, ImFloor(window->Scroll.x + ((g.NavMoveDir == ImGuiDir_Left) ? -1.0f : +1.0f) * scroll_speed));
- if (g.NavMoveDir == ImGuiDir_Up || g.NavMoveDir == ImGuiDir_Down)
- SetWindowScrollY(window, ImFloor(window->Scroll.y + ((g.NavMoveDir == ImGuiDir_Up) ? -1.0f : +1.0f) * scroll_speed));
- }
-
- // *Normal* Manual scroll with NavScrollXXX keys
- // Next movement request will clamp the NavId reference rectangle to the visible area, so navigation will resume within those bounds.
- ImVec2 scroll_dir = GetNavInputAmount2d(ImGuiNavDirSourceFlags_PadLStick, ImGuiInputReadMode_Down, 1.0f/10.0f, 10.0f);
- if (scroll_dir.x != 0.0f && window->ScrollbarX)
- {
- SetWindowScrollX(window, ImFloor(window->Scroll.x + scroll_dir.x * scroll_speed));
- g.NavMoveFromClampedRefRect = true;
- }
- if (scroll_dir.y != 0.0f)
- {
- SetWindowScrollY(window, ImFloor(window->Scroll.y + scroll_dir.y * scroll_speed));
- g.NavMoveFromClampedRefRect = true;
- }
- }
-
- // Reset search results
- g.NavMoveResultLocal.Clear();
- g.NavMoveResultLocalVisibleSet.Clear();
- g.NavMoveResultOther.Clear();
+ ImGuiWindow* window = g.CurrentWindow;
+ if (!(window->DC.LastItemStatusFlags & ImGuiItemStatusFlags_HoveredRect))
+ return false;
+ if (g.HoveredWindowUnderMovingWindow == NULL || window->RootWindow != g.HoveredWindowUnderMovingWindow->RootWindow)
+ return false;
- // When we have manually scrolled (without using navigation) and NavId becomes out of bounds, we project its bounding box to the visible area to restart navigation within visible items
- if (g.NavMoveRequest && g.NavMoveFromClampedRefRect && g.NavLayer == 0)
- {
- ImGuiWindow* window = g.NavWindow;
- ImRect window_rect_rel(window->InnerMainRect.Min - window->Pos - ImVec2(1,1), window->InnerMainRect.Max - window->Pos + ImVec2(1,1));
- if (!window_rect_rel.Contains(window->NavRectRel[g.NavLayer]))
- {
- float pad = window->CalcFontSize() * 0.5f;
- window_rect_rel.Expand(ImVec2(-ImMin(window_rect_rel.GetWidth(), pad), -ImMin(window_rect_rel.GetHeight(), pad))); // Terrible approximation for the intent of starting navigation from first fully visible item
- window->NavRectRel[g.NavLayer].ClipWith(window_rect_rel);
- g.NavId = 0;
- }
- g.NavMoveFromClampedRefRect = false;
- }
+ const ImRect& display_rect = (window->DC.LastItemStatusFlags & ImGuiItemStatusFlags_HasDisplayRect) ? window->DC.LastItemDisplayRect : window->DC.LastItemRect;
+ ImGuiID id = window->DC.LastItemId;
+ if (id == 0)
+ id = window->GetIDFromRectangle(display_rect);
+ if (g.DragDropPayload.SourceId == id)
+ return false;
- // For scoring we use a single segment on the left side our current item bounding box (not touching the edge to avoid box overlap with zero-spaced items)
- ImRect nav_rect_rel = (g.NavWindow && !g.NavWindow->NavRectRel[g.NavLayer].IsInverted()) ? g.NavWindow->NavRectRel[g.NavLayer] : ImRect(0,0,0,0);
- g.NavScoringRectScreen = g.NavWindow ? ImRect(g.NavWindow->Pos + nav_rect_rel.Min, g.NavWindow->Pos + nav_rect_rel.Max) : ImRect(0,0,0,0);
- g.NavScoringRectScreen.TranslateY(nav_scoring_rect_offset_y);
- g.NavScoringRectScreen.Min.x = ImMin(g.NavScoringRectScreen.Min.x + 1.0f, g.NavScoringRectScreen.Max.x);
- g.NavScoringRectScreen.Max.x = g.NavScoringRectScreen.Min.x;
- IM_ASSERT(!g.NavScoringRectScreen.IsInverted()); // Ensure if we have a finite, non-inverted bounding box here will allows us to remove extraneous ImFabs() calls in NavScoreItem().
- //g.OverlayDrawList.AddRect(g.NavScoringRectScreen.Min, g.NavScoringRectScreen.Max, IM_COL32(255,200,0,255)); // [DEBUG]
- g.NavScoringCount = 0;
-#if IMGUI_DEBUG_NAV_RECTS
- if (g.NavWindow) { for (int layer = 0; layer < 2; layer++) GetOverlayDrawList(g.NavWindow)->AddRect(g.NavWindow->Pos + g.NavWindow->NavRectRel[layer].Min, g.NavWindow->Pos + g.NavWindow->NavRectRel[layer].Max, IM_COL32(255,200,0,255)); } // [DEBUG]
- if (g.NavWindow) { ImU32 col = (!g.NavWindow->Hidden) ? IM_COL32(255,0,255,255) : IM_COL32(255,0,0,255); ImVec2 p = NavCalcPreferredRefPos(); char buf[32]; ImFormatString(buf, 32, "%d", g.NavLayer); GetOverlayDrawList(g.NavWindow)->AddCircleFilled(p, 3.0f, col); GetOverlayDrawList(g.NavWindow)->AddText(NULL, 13.0f, p + ImVec2(8,-4), col, buf); }
-#endif
+ IM_ASSERT(g.DragDropWithinSourceOrTarget == false);
+ g.DragDropTargetRect = display_rect;
+ g.DragDropTargetId = id;
+ g.DragDropWithinSourceOrTarget = true;
+ return true;
}
-// Apply result from previous frame navigation directional move request
-static void ImGui::NavUpdateMoveResult()
+bool ImGui::IsDragDropPayloadBeingAccepted()
{
ImGuiContext& g = *GImGui;
- if (g.NavMoveResultLocal.ID == 0 && g.NavMoveResultOther.ID == 0)
- {
- // In a situation when there is no results but NavId != 0, re-enable the Navigation highlight (because g.NavId is not considered as a possible result)
- if (g.NavId != 0)
- {
- g.NavDisableHighlight = false;
- g.NavDisableMouseHover = true;
- }
- return;
- }
-
- // Select which result to use
- ImGuiNavMoveResult* result = (g.NavMoveResultLocal.ID != 0) ? &g.NavMoveResultLocal : &g.NavMoveResultOther;
-
- // PageUp/PageDown behavior first jumps to the bottom/top mostly visible item, _otherwise_ use the result from the previous/next page.
- if (g.NavMoveRequestFlags & ImGuiNavMoveFlags_AlsoScoreVisibleSet)
- if (g.NavMoveResultLocalVisibleSet.ID != 0 && g.NavMoveResultLocalVisibleSet.ID != g.NavId)
- result = &g.NavMoveResultLocalVisibleSet;
-
- // Maybe entering a flattened child from the outside? In this case solve the tie using the regular scoring rules.
- if (result != &g.NavMoveResultOther && g.NavMoveResultOther.ID != 0 && g.NavMoveResultOther.Window->ParentWindow == g.NavWindow)
- if ((g.NavMoveResultOther.DistBox < result->DistBox) || (g.NavMoveResultOther.DistBox == result->DistBox && g.NavMoveResultOther.DistCenter < result->DistCenter))
- result = &g.NavMoveResultOther;
- IM_ASSERT(g.NavWindow && result->Window);
-
- // Scroll to keep newly navigated item fully into view.
- if (g.NavLayer == 0)
- {
- ImRect rect_abs = ImRect(result->RectRel.Min + result->Window->Pos, result->RectRel.Max + result->Window->Pos);
- NavScrollToBringItemIntoView(result->Window, rect_abs);
-
- // Estimate upcoming scroll so we can offset our result position so mouse position can be applied immediately after in NavUpdate()
- ImVec2 next_scroll = CalcNextScrollFromScrollTargetAndClamp(result->Window, false);
- ImVec2 delta_scroll = result->Window->Scroll - next_scroll;
- result->RectRel.Translate(delta_scroll);
-
- // Also scroll parent window to keep us into view if necessary (we could/should technically recurse back the whole the parent hierarchy).
- if (result->Window->Flags & ImGuiWindowFlags_ChildWindow)
- NavScrollToBringItemIntoView(result->Window->ParentWindow, ImRect(rect_abs.Min + delta_scroll, rect_abs.Max + delta_scroll));
- }
-
- ClearActiveID();
- g.NavWindow = result->Window;
- SetNavIDWithRectRel(result->ID, g.NavLayer, result->RectRel);
- g.NavJustMovedToId = result->ID;
- g.NavMoveFromClampedRefRect = false;
+ return g.DragDropActive && g.DragDropAcceptIdPrev != 0;
}
-static float ImGui::NavUpdatePageUpPageDown(int allowed_dir_flags)
+const ImGuiPayload* ImGui::AcceptDragDropPayload(const char* type, ImGuiDragDropFlags flags)
{
ImGuiContext& g = *GImGui;
- if (g.NavMoveDir == ImGuiDir_None && g.NavWindow && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs) && !g.NavWindowingTarget && g.NavLayer == 0)
+ ImGuiWindow* window = g.CurrentWindow;
+ ImGuiPayload& payload = g.DragDropPayload;
+ IM_ASSERT(g.DragDropActive); // Not called between BeginDragDropTarget() and EndDragDropTarget() ?
+ IM_ASSERT(payload.DataFrameCount != -1); // Forgot to call EndDragDropTarget() ?
+ if (type != NULL && !payload.IsDataType(type))
+ return NULL;
+
+ // Accept smallest drag target bounding box, this allows us to nest drag targets conveniently without ordering constraints.
+ // NB: We currently accept NULL id as target. However, overlapping targets requires a unique ID to function!
+ const bool was_accepted_previously = (g.DragDropAcceptIdPrev == g.DragDropTargetId);
+ ImRect r = g.DragDropTargetRect;
+ float r_surface = r.GetWidth() * r.GetHeight();
+ if (r_surface < g.DragDropAcceptIdCurrRectSurface)
{
- ImGuiWindow* window = g.NavWindow;
- bool page_up_held = IsKeyDown(g.IO.KeyMap[ImGuiKey_PageUp]) && (allowed_dir_flags & (1 << ImGuiDir_Up));
- bool page_down_held = IsKeyDown(g.IO.KeyMap[ImGuiKey_PageDown]) && (allowed_dir_flags & (1 << ImGuiDir_Down));
- if (page_up_held != page_down_held) // If either (not both) are pressed
- {
- if (window->DC.NavLayerActiveMask == 0x00 && window->DC.NavHasScroll)
- {
- // Fallback manual-scroll when window has no navigable item
- if (IsKeyPressed(g.IO.KeyMap[ImGuiKey_PageUp], true))
- SetWindowScrollY(window, window->Scroll.y - window->InnerClipRect.GetHeight());
- else if (IsKeyPressed(g.IO.KeyMap[ImGuiKey_PageDown], true))
- SetWindowScrollY(window, window->Scroll.y + window->InnerClipRect.GetHeight());
- }
- else
- {
- const ImRect& nav_rect_rel = window->NavRectRel[g.NavLayer];
- const float page_offset_y = ImMax(0.0f, window->InnerClipRect.GetHeight() - window->CalcFontSize() * 1.0f + nav_rect_rel.GetHeight());
- float nav_scoring_rect_offset_y = 0.0f;
- if (IsKeyPressed(g.IO.KeyMap[ImGuiKey_PageUp], true))
- {
- nav_scoring_rect_offset_y = -page_offset_y;
- g.NavMoveDir = ImGuiDir_Down; // Because our scoring rect is offset, we intentionally request the opposite direction (so we can always land on the last item)
- g.NavMoveClipDir = ImGuiDir_Up;
- g.NavMoveRequestFlags = ImGuiNavMoveFlags_AllowCurrentNavId | ImGuiNavMoveFlags_AlsoScoreVisibleSet;
- }
- else if (IsKeyPressed(g.IO.KeyMap[ImGuiKey_PageDown], true))
- {
- nav_scoring_rect_offset_y = +page_offset_y;
- g.NavMoveDir = ImGuiDir_Up; // Because our scoring rect is offset, we intentionally request the opposite direction (so we can always land on the last item)
- g.NavMoveClipDir = ImGuiDir_Down;
- g.NavMoveRequestFlags = ImGuiNavMoveFlags_AllowCurrentNavId | ImGuiNavMoveFlags_AlsoScoreVisibleSet;
- }
- return nav_scoring_rect_offset_y;
- }
- }
+ g.DragDropAcceptFlags = flags;
+ g.DragDropAcceptIdCurr = g.DragDropTargetId;
+ g.DragDropAcceptIdCurrRectSurface = r_surface;
}
- return 0.0f;
-}
-static int FindWindowFocusIndex(ImGuiWindow* window) // FIXME-OPT O(N)
-{
- ImGuiContext& g = *GImGui;
- for (int i = g.WindowsFocusOrder.Size-1; i >= 0; i--)
- if (g.WindowsFocusOrder[i] == window)
- return i;
- return -1;
-}
-
-static ImGuiWindow* FindWindowNavFocusable(int i_start, int i_stop, int dir) // FIXME-OPT O(N)
-{
- ImGuiContext& g = *GImGui;
- for (int i = i_start; i >= 0 && i < g.WindowsFocusOrder.Size && i != i_stop; i += dir)
- if (ImGui::IsWindowNavFocusable(g.WindowsFocusOrder[i]))
- return g.WindowsFocusOrder[i];
- return NULL;
-}
-
-static void NavUpdateWindowingHighlightWindow(int focus_change_dir)
-{
- ImGuiContext& g = *GImGui;
- IM_ASSERT(g.NavWindowingTarget);
- if (g.NavWindowingTarget->Flags & ImGuiWindowFlags_Modal)
- return;
+ // Render default drop visuals
+ payload.Preview = was_accepted_previously;
+ flags |= (g.DragDropSourceFlags & ImGuiDragDropFlags_AcceptNoDrawDefaultRect); // Source can also inhibit the preview (useful for external sources that lives for 1 frame)
+ if (!(flags & ImGuiDragDropFlags_AcceptNoDrawDefaultRect) && payload.Preview)
+ {
+ // FIXME-DRAG: Settle on a proper default visuals for drop target.
+ r.Expand(3.5f);
+ bool push_clip_rect = !window->ClipRect.Contains(r);
+ if (push_clip_rect) window->DrawList->PushClipRect(r.Min-ImVec2(1,1), r.Max+ImVec2(1,1));
+ window->DrawList->AddRect(r.Min, r.Max, GetColorU32(ImGuiCol_DragDropTarget), 0.0f, ~0, 2.0f);
+ if (push_clip_rect) window->DrawList->PopClipRect();
+ }
- const int i_current = FindWindowFocusIndex(g.NavWindowingTarget);
- ImGuiWindow* window_target = FindWindowNavFocusable(i_current + focus_change_dir, -INT_MAX, focus_change_dir);
- if (!window_target)
- window_target = FindWindowNavFocusable((focus_change_dir < 0) ? (g.WindowsFocusOrder.Size - 1) : 0, i_current, focus_change_dir);
- if (window_target) // Don't reset windowing target if there's a single window in the list
- g.NavWindowingTarget = g.NavWindowingTargetAnim = window_target;
- g.NavWindowingToggleLayer = false;
+ g.DragDropAcceptFrameCount = g.FrameCount;
+ payload.Delivery = was_accepted_previously && !IsMouseDown(g.DragDropMouseButton); // For extern drag sources affecting os window focus, it's easier to just test !IsMouseDown() instead of IsMouseReleased()
+ if (!payload.Delivery && !(flags & ImGuiDragDropFlags_AcceptBeforeDelivery))
+ return NULL;
+
+ return &payload;
}
-// Window management mode (hold to: change focus/move/resize, tap to: toggle menu layer)
-static void ImGui::NavUpdateWindowing()
+const ImGuiPayload* ImGui::GetDragDropPayload()
{
ImGuiContext& g = *GImGui;
- ImGuiWindow* apply_focus_window = NULL;
- bool apply_toggle_layer = false;
+ return g.DragDropActive ? &g.DragDropPayload : NULL;
+}
- ImGuiWindow* modal_window = GetFrontMostPopupModal();
- if (modal_window != NULL)
- {
- g.NavWindowingTarget = NULL;
- return;
- }
+// We don't really use/need this now, but added it for the sake of consistency and because we might need it later.
+void ImGui::EndDragDropTarget()
+{
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(g.DragDropActive);
+ IM_ASSERT(g.DragDropWithinSourceOrTarget);
+ g.DragDropWithinSourceOrTarget = false;
+}
- // Fade out
- if (g.NavWindowingTargetAnim && g.NavWindowingTarget == NULL)
- {
- g.NavWindowingHighlightAlpha = ImMax(g.NavWindowingHighlightAlpha - g.IO.DeltaTime * 10.0f, 0.0f);
- if (g.DimBgRatio <= 0.0f && g.NavWindowingHighlightAlpha <= 0.0f)
- g.NavWindowingTargetAnim = NULL;
- }
- // Start CTRL-TAB or Square+L/R window selection
- bool start_windowing_with_gamepad = !g.NavWindowingTarget && IsNavInputPressed(ImGuiNavInput_Menu, ImGuiInputReadMode_Pressed);
- bool start_windowing_with_keyboard = !g.NavWindowingTarget && g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_Tab) && (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard);
- if (start_windowing_with_gamepad || start_windowing_with_keyboard)
- if (ImGuiWindow* window = g.NavWindow ? g.NavWindow : FindWindowNavFocusable(g.WindowsFocusOrder.Size - 1, -INT_MAX, -1))
- {
- g.NavWindowingTarget = g.NavWindowingTargetAnim = window;
- g.NavWindowingTimer = g.NavWindowingHighlightAlpha = 0.0f;
- g.NavWindowingToggleLayer = start_windowing_with_keyboard ? false : true;
- g.NavInputSource = start_windowing_with_keyboard ? ImGuiInputSource_NavKeyboard : ImGuiInputSource_NavGamepad;
- }
+//-----------------------------------------------------------------------------
+// [SECTION] LOGGING/CAPTURING
+//-----------------------------------------------------------------------------
+// All text output from the interface can be captured into tty/file/clipboard.
+// By default, tree nodes are automatically opened during logging.
+//-----------------------------------------------------------------------------
- // Gamepad update
- g.NavWindowingTimer += g.IO.DeltaTime;
- if (g.NavWindowingTarget && g.NavInputSource == ImGuiInputSource_NavGamepad)
- {
- // Highlight only appears after a brief time holding the button, so that a fast tap on PadMenu (to toggle NavLayer) doesn't add visual noise
- g.NavWindowingHighlightAlpha = ImMax(g.NavWindowingHighlightAlpha, ImSaturate((g.NavWindowingTimer - NAV_WINDOWING_HIGHLIGHT_DELAY) / 0.05f));
+// Pass text data straight to log (without being displayed)
+void ImGui::LogText(const char* fmt, ...)
+{
+ ImGuiContext& g = *GImGui;
+ if (!g.LogEnabled)
+ return;
- // Select window to focus
- const int focus_change_dir = (int)IsNavInputPressed(ImGuiNavInput_FocusPrev, ImGuiInputReadMode_RepeatSlow) - (int)IsNavInputPressed(ImGuiNavInput_FocusNext, ImGuiInputReadMode_RepeatSlow);
- if (focus_change_dir != 0)
- {
- NavUpdateWindowingHighlightWindow(focus_change_dir);
- g.NavWindowingHighlightAlpha = 1.0f;
- }
+ va_list args;
+ va_start(args, fmt);
+ if (g.LogFile)
+ vfprintf(g.LogFile, fmt, args);
+ else
+ g.LogBuffer.appendfv(fmt, args);
+ va_end(args);
+}
- // Single press toggles NavLayer, long press with L/R apply actual focus on release (until then the window was merely rendered front-most)
- if (!IsNavInputDown(ImGuiNavInput_Menu))
- {
- g.NavWindowingToggleLayer &= (g.NavWindowingHighlightAlpha < 1.0f); // Once button was held long enough we don't consider it a tap-to-toggle-layer press anymore.
- if (g.NavWindowingToggleLayer && g.NavWindow)
- apply_toggle_layer = true;
- else if (!g.NavWindowingToggleLayer)
- apply_focus_window = g.NavWindowingTarget;
- g.NavWindowingTarget = NULL;
- }
- }
+// Internal version that takes a position to decide on newline placement and pad items according to their depth.
+// We split text into individual lines to add current tree level padding
+void ImGui::LogRenderedText(const ImVec2* ref_pos, const char* text, const char* text_end)
+{
+ ImGuiContext& g = *GImGui;
+ ImGuiWindow* window = g.CurrentWindow;
- // Keyboard: Focus
- if (g.NavWindowingTarget && g.NavInputSource == ImGuiInputSource_NavKeyboard)
- {
- // Visuals only appears after a brief time after pressing TAB the first time, so that a fast CTRL+TAB doesn't add visual noise
- g.NavWindowingHighlightAlpha = ImMax(g.NavWindowingHighlightAlpha, ImSaturate((g.NavWindowingTimer - NAV_WINDOWING_HIGHLIGHT_DELAY) / 0.05f)); // 1.0f
- if (IsKeyPressedMap(ImGuiKey_Tab, true))
- NavUpdateWindowingHighlightWindow(g.IO.KeyShift ? +1 : -1);
- if (!g.IO.KeyCtrl)
- apply_focus_window = g.NavWindowingTarget;
- }
+ if (!text_end)
+ text_end = FindRenderedTextEnd(text, text_end);
- // Keyboard: Press and Release ALT to toggle menu layer
- // FIXME: We lack an explicit IO variable for "is the imgui window focused", so compare mouse validity to detect the common case of back-end clearing releases all keys on ALT-TAB
- if (IsNavInputPressed(ImGuiNavInput_KeyMenu_, ImGuiInputReadMode_Pressed))
- g.NavWindowingToggleLayer = true;
- if ((g.ActiveId == 0 || g.ActiveIdAllowOverlap) && g.NavWindowingToggleLayer && IsNavInputPressed(ImGuiNavInput_KeyMenu_, ImGuiInputReadMode_Released))
- if (IsMousePosValid(&g.IO.MousePos) == IsMousePosValid(&g.IO.MousePosPrev))
- apply_toggle_layer = true;
+ const bool log_new_line = ref_pos && (ref_pos->y > g.LogLinePosY + 1);
+ if (ref_pos)
+ g.LogLinePosY = ref_pos->y;
+ if (log_new_line)
+ g.LogLineFirstItem = true;
- // Move window
- if (g.NavWindowingTarget && !(g.NavWindowingTarget->Flags & ImGuiWindowFlags_NoMove))
+ const char* text_remaining = text;
+ if (g.LogDepthRef > window->DC.TreeDepth) // Re-adjust padding if we have popped out of our starting depth
+ g.LogDepthRef = window->DC.TreeDepth;
+ const int tree_depth = (window->DC.TreeDepth - g.LogDepthRef);
+ for (;;)
{
- ImVec2 move_delta;
- if (g.NavInputSource == ImGuiInputSource_NavKeyboard && !g.IO.KeyShift)
- move_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_Keyboard, ImGuiInputReadMode_Down);
- if (g.NavInputSource == ImGuiInputSource_NavGamepad)
- move_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_PadLStick, ImGuiInputReadMode_Down);
- if (move_delta.x != 0.0f || move_delta.y != 0.0f)
+ // Split the string. Each new line (after a '\n') is followed by spacing corresponding to the current depth of our log entry.
+ // We don't add a trailing \n to allow a subsequent item on the same line to be captured.
+ const char* line_start = text_remaining;
+ const char* line_end = ImStreolRange(line_start, text_end);
+ const bool is_first_line = (line_start == text);
+ const bool is_last_line = (line_end == text_end);
+ if (!is_last_line || (line_start != line_end))
{
- const float NAV_MOVE_SPEED = 800.0f;
- const float move_speed = ImFloor(NAV_MOVE_SPEED * g.IO.DeltaTime * ImMin(g.IO.DisplayFramebufferScale.x, g.IO.DisplayFramebufferScale.y)); // FIXME: Doesn't code variable framerate very well
- g.NavWindowingTarget->RootWindow->Pos += move_delta * move_speed;
- g.NavDisableMouseHover = true;
- MarkIniSettingsDirty(g.NavWindowingTarget);
+ const int char_count = (int)(line_end - line_start);
+ if (log_new_line || !is_first_line)
+ LogText(IM_NEWLINE "%*s%.*s", tree_depth * 4, "", char_count, line_start);
+ else if (g.LogLineFirstItem)
+ LogText("%*s%.*s", tree_depth * 4, "", char_count, line_start);
+ else
+ LogText(" %.*s", char_count, line_start);
+ g.LogLineFirstItem = false;
}
- }
-
- // Apply final focus
- if (apply_focus_window && (g.NavWindow == NULL || apply_focus_window != g.NavWindow->RootWindowDockStop))
- {
- ImGuiViewport* previous_viewport = g.NavWindow ? g.NavWindow->Viewport : NULL;
- g.NavDisableHighlight = false;
- g.NavDisableMouseHover = true;
- apply_focus_window = NavRestoreLastChildNavWindow(apply_focus_window);
- ClosePopupsOverWindow(apply_focus_window);
- FocusWindow(apply_focus_window);
- if (apply_focus_window->NavLastIds[0] == 0)
- NavInitWindow(apply_focus_window, false);
-
- // If the window only has a menu layer, select it directly
- if (apply_focus_window->DC.NavLayerActiveMask == (1 << ImGuiNavLayer_Menu))
- g.NavLayer = ImGuiNavLayer_Menu;
-
- // Request OS level focus
- if (apply_focus_window->Viewport != previous_viewport && g.PlatformIO.Platform_SetWindowFocus)
- g.PlatformIO.Platform_SetWindowFocus(apply_focus_window->Viewport);
- }
- if (apply_focus_window)
- g.NavWindowingTarget = NULL;
-
- // Apply menu/layer toggle
- if (apply_toggle_layer && g.NavWindow)
- {
- // Move to parent menu if necessary
- ImGuiWindow* new_nav_window = g.NavWindow;
- while (new_nav_window->ParentWindow
- && (new_nav_window->DC.NavLayerActiveMask & (1 << 1)) == 0
- && (new_nav_window->Flags & ImGuiWindowFlags_ChildWindow) != 0
- && (new_nav_window->Flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_ChildMenu)) == 0)
- new_nav_window = new_nav_window->ParentWindow;
- if (new_nav_window != g.NavWindow)
+ else if (log_new_line)
{
- ImGuiWindow* old_nav_window = g.NavWindow;
- FocusWindow(new_nav_window);
- new_nav_window->NavLastChildNavWindow = old_nav_window;
+ // An empty "" string at a different Y position should output a carriage return.
+ LogText(IM_NEWLINE);
+ break;
}
- g.NavDisableHighlight = false;
- g.NavDisableMouseHover = true;
- // When entering a regular menu bar with the Alt key, we always reinitialize the navigation ID. It however persist on docking tab tabs.
- const ImGuiNavLayer new_nav_layer = (g.NavWindow->DC.NavLayerActiveMask & (1 << ImGuiNavLayer_Menu)) ? (ImGuiNavLayer)((int)g.NavLayer ^ 1) : ImGuiNavLayer_Main;
- const bool preserve_layer_1_nav_id = (new_nav_window->DockNodeAsHost != NULL);
- if (new_nav_layer == ImGuiNavLayer_Menu && !preserve_layer_1_nav_id)
- g.NavWindow->NavLastIds[ImGuiNavLayer_Menu] = 0;
- NavRestoreLayer(new_nav_layer);
+ if (is_last_line)
+ break;
+ text_remaining = line_end + 1;
}
}
-// Window has already passed the IsWindowNavFocusable()
-static const char* GetFallbackWindowNameForWindowingList(ImGuiWindow* window)
+// Start logging/capturing text output
+void ImGui::LogBegin(ImGuiLogType type, int auto_open_depth)
{
- if (window->Flags & ImGuiWindowFlags_Popup)
- return "(Popup)";
- if ((window->Flags & ImGuiWindowFlags_MenuBar) && strcmp(window->Name, "##MainMenuBar") == 0)
- return "(Main menu bar)";
- if (window->DockNodeAsHost)
- return "(Dock node)";
- return "(Untitled)";
+ ImGuiContext& g = *GImGui;
+ ImGuiWindow* window = g.CurrentWindow;
+ IM_ASSERT(g.LogEnabled == false);
+ IM_ASSERT(g.LogFile == NULL);
+ IM_ASSERT(g.LogBuffer.empty());
+ g.LogEnabled = true;
+ g.LogType = type;
+ g.LogDepthRef = window->DC.TreeDepth;
+ g.LogDepthToExpand = ((auto_open_depth >= 0) ? auto_open_depth : g.LogDepthToExpandDefault);
+ g.LogLinePosY = FLT_MAX;
+ g.LogLineFirstItem = true;
}
-// Overlay displayed when using CTRL+TAB. Called by EndFrame().
-void ImGui::NavUpdateWindowingList()
+void ImGui::LogToTTY(int auto_open_depth)
{
ImGuiContext& g = *GImGui;
- IM_ASSERT(g.NavWindowingTarget != NULL);
-
- if (g.NavWindowingTimer < NAV_WINDOWING_LIST_APPEAR_DELAY)
+ if (g.LogEnabled)
return;
-
- if (g.NavWindowingList == NULL)
- g.NavWindowingList = FindWindowByName("###NavWindowingList");
- ImGuiViewportP* viewport = /*g.NavWindow ? g.NavWindow->Viewport :*/ (ImGuiViewportP*)GetMainViewport();
- SetNextWindowSizeConstraints(ImVec2(viewport->Size.x * 0.20f, viewport->Size.y * 0.20f), ImVec2(FLT_MAX, FLT_MAX));
- SetNextWindowPos(viewport->Pos + viewport->Size * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
- PushStyleVar(ImGuiStyleVar_WindowPadding, g.Style.WindowPadding * 2.0f);
- Begin("###NavWindowingList", NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings);
- for (int n = g.WindowsFocusOrder.Size - 1; n >= 0; n--)
- {
- ImGuiWindow* window = g.WindowsFocusOrder[n];
- if (!IsWindowNavFocusable(window))
- continue;
- const char* label = window->Name;
- if (label == FindRenderedTextEnd(label))
- label = GetFallbackWindowNameForWindowingList(window);
- Selectable(label, g.NavWindowingTarget == window);
- }
- End();
- PopStyleVar();
+ LogBegin(ImGuiLogType_TTY, auto_open_depth);
+ g.LogFile = stdout;
}
-//-----------------------------------------------------------------------------
-// [SECTION] COLUMNS
-// In the current version, Columns are very weak. Needs to be replaced with a more full-featured system.
-//-----------------------------------------------------------------------------
-
-void ImGui::NextColumn()
+// Start logging/capturing text output to given file
+void ImGui::LogToFile(int auto_open_depth, const char* filename)
{
- ImGuiWindow* window = GetCurrentWindow();
- if (window->SkipItems || window->DC.ColumnsSet == NULL)
- return;
-
ImGuiContext& g = *GImGui;
- PopItemWidth();
- PopClipRect();
+ if (g.LogEnabled)
+ return;
- ImGuiColumnsSet* columns = window->DC.ColumnsSet;
- columns->LineMaxY = ImMax(columns->LineMaxY, window->DC.CursorPos.y);
- if (++columns->Current < columns->Count)
- {
- // Columns 1+ cancel out IndentX
- window->DC.ColumnsOffset.x = GetColumnOffset(columns->Current) - window->DC.Indent.x + g.Style.ItemSpacing.x;
- window->DrawList->ChannelsSetCurrent(columns->Current);
- }
- else
+ // FIXME: We could probably open the file in text mode "at", however note that clipboard/buffer logging will still
+ // be subject to outputting OS-incompatible carriage return if within strings the user doesn't use IM_NEWLINE.
+ // By opening the file in binary mode "ab" we have consistent output everywhere.
+ if (!filename)
+ filename = g.IO.LogFilename;
+ if (!filename || !filename[0])
+ return;
+ FILE* f = ImFileOpen(filename, "ab");
+ if (f == NULL)
{
- window->DC.ColumnsOffset.x = 0.0f;
- window->DrawList->ChannelsSetCurrent(0);
- columns->Current = 0;
- columns->LineMinY = columns->LineMaxY;
+ IM_ASSERT(0);
+ return;
}
- window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x);
- window->DC.CursorPos.y = columns->LineMinY;
- window->DC.CurrentLineSize = ImVec2(0.0f, 0.0f);
- window->DC.CurrentLineTextBaseOffset = 0.0f;
- PushColumnClipRect();
- PushItemWidth(GetColumnWidth() * 0.65f); // FIXME: Move on columns setup
+ LogBegin(ImGuiLogType_File, auto_open_depth);
+ g.LogFile = f;
}
-int ImGui::GetColumnIndex()
+// Start logging/capturing text output to clipboard
+void ImGui::LogToClipboard(int auto_open_depth)
{
- ImGuiWindow* window = GetCurrentWindowRead();
- return window->DC.ColumnsSet ? window->DC.ColumnsSet->Current : 0;
+ ImGuiContext& g = *GImGui;
+ if (g.LogEnabled)
+ return;
+ LogBegin(ImGuiLogType_Clipboard, auto_open_depth);
}
-int ImGui::GetColumnsCount()
+void ImGui::LogToBuffer(int auto_open_depth)
{
- ImGuiWindow* window = GetCurrentWindowRead();
- return window->DC.ColumnsSet ? window->DC.ColumnsSet->Count : 1;
+ ImGuiContext& g = *GImGui;
+ if (g.LogEnabled)
+ return;
+ LogBegin(ImGuiLogType_Buffer, auto_open_depth);
}
-static float OffsetNormToPixels(const ImGuiColumnsSet* columns, float offset_norm)
+void ImGui::LogFinish()
{
- return offset_norm * (columns->MaxX - columns->MinX);
-}
+ ImGuiContext& g = *GImGui;
+ if (!g.LogEnabled)
+ return;
+
+ LogText(IM_NEWLINE);
+ switch (g.LogType)
+ {
+ case ImGuiLogType_TTY:
+ fflush(g.LogFile);
+ break;
+ case ImGuiLogType_File:
+ fclose(g.LogFile);
+ break;
+ case ImGuiLogType_Buffer:
+ break;
+ case ImGuiLogType_Clipboard:
+ if (!g.LogBuffer.empty())
+ SetClipboardText(g.LogBuffer.begin());
+ break;
+ case ImGuiLogType_None:
+ IM_ASSERT(0);
+ break;
+ }
-static float PixelsToOffsetNorm(const ImGuiColumnsSet* columns, float offset)
-{
- return offset / (columns->MaxX - columns->MinX);
+ g.LogEnabled = false;
+ g.LogType = ImGuiLogType_None;
+ g.LogFile = NULL;
+ g.LogBuffer.clear();
}
-static inline float GetColumnsRectHalfWidth() { return 4.0f; }
-
-static float GetDraggedColumnOffset(ImGuiColumnsSet* columns, int column_index)
+// Helper to display logging buttons
+// FIXME-OBSOLETE: We should probably obsolete this and let the user have their own helper (this is one of the oldest function alive!)
+void ImGui::LogButtons()
{
- // Active (dragged) column always follow mouse. The reason we need this is that dragging a column to the right edge of an auto-resizing
- // window creates a feedback loop because we store normalized positions. So while dragging we enforce absolute positioning.
ImGuiContext& g = *GImGui;
- ImGuiWindow* window = g.CurrentWindow;
- IM_ASSERT(column_index > 0); // We are not supposed to drag column 0.
- IM_ASSERT(g.ActiveId == columns->ID + ImGuiID(column_index));
- float x = g.IO.MousePos.x - g.ActiveIdClickOffset.x + GetColumnsRectHalfWidth() - window->Pos.x;
- x = ImMax(x, ImGui::GetColumnOffset(column_index - 1) + g.Style.ColumnsMinSpacing);
- if ((columns->Flags & ImGuiColumnsFlags_NoPreserveWidths))
- x = ImMin(x, ImGui::GetColumnOffset(column_index + 1) - g.Style.ColumnsMinSpacing);
+ PushID("LogButtons");
+ const bool log_to_tty = Button("Log To TTY"); SameLine();
+ const bool log_to_file = Button("Log To File"); SameLine();
+ const bool log_to_clipboard = Button("Log To Clipboard"); SameLine();
+ PushAllowKeyboardFocus(false);
+ SetNextItemWidth(80.0f);
+ SliderInt("Default Depth", &g.LogDepthToExpandDefault, 0, 9, NULL);
+ PopAllowKeyboardFocus();
+ PopID();
- return x;
+ // Start logging at the end of the function so that the buttons don't appear in the log
+ if (log_to_tty)
+ LogToTTY();
+ if (log_to_file)
+ LogToFile();
+ if (log_to_clipboard)
+ LogToClipboard();
}
-float ImGui::GetColumnOffset(int column_index)
-{
- ImGuiWindow* window = GetCurrentWindowRead();
- ImGuiColumnsSet* columns = window->DC.ColumnsSet;
- IM_ASSERT(columns != NULL);
- if (column_index < 0)
- column_index = columns->Current;
- IM_ASSERT(column_index < columns->Columns.Size);
+//-----------------------------------------------------------------------------
+// [SECTION] SETTINGS
+//-----------------------------------------------------------------------------
- const float t = columns->Columns[column_index].OffsetNorm;
- const float x_offset = ImLerp(columns->MinX, columns->MaxX, t);
- return x_offset;
+void ImGui::MarkIniSettingsDirty()
+{
+ ImGuiContext& g = *GImGui;
+ if (g.SettingsDirtyTimer <= 0.0f)
+ g.SettingsDirtyTimer = g.IO.IniSavingRate;
}
-static float GetColumnWidthEx(ImGuiColumnsSet* columns, int column_index, bool before_resize = false)
+void ImGui::MarkIniSettingsDirty(ImGuiWindow* window)
{
- if (column_index < 0)
- column_index = columns->Current;
-
- float offset_norm;
- if (before_resize)
- offset_norm = columns->Columns[column_index + 1].OffsetNormBeforeResize - columns->Columns[column_index].OffsetNormBeforeResize;
- else
- offset_norm = columns->Columns[column_index + 1].OffsetNorm - columns->Columns[column_index].OffsetNorm;
- return OffsetNormToPixels(columns, offset_norm);
+ ImGuiContext& g = *GImGui;
+ if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings))
+ if (g.SettingsDirtyTimer <= 0.0f)
+ g.SettingsDirtyTimer = g.IO.IniSavingRate;
}
-float ImGui::GetColumnWidth(int column_index)
+ImGuiWindowSettings* ImGui::CreateNewWindowSettings(const char* name)
{
- ImGuiWindow* window = GetCurrentWindowRead();
- ImGuiColumnsSet* columns = window->DC.ColumnsSet;
- IM_ASSERT(columns != NULL);
-
- if (column_index < 0)
- column_index = columns->Current;
- return OffsetNormToPixels(columns, columns->Columns[column_index + 1].OffsetNorm - columns->Columns[column_index].OffsetNorm);
+ ImGuiContext& g = *GImGui;
+ g.SettingsWindows.push_back(ImGuiWindowSettings());
+ ImGuiWindowSettings* settings = &g.SettingsWindows.back();
+#if !IMGUI_DEBUG_INI_SETTINGS
+ // Skip to the "###" marker if any. We don't skip past to match the behavior of GetID()
+ // Preserve the full string when IMGUI_DEBUG_INI_SETTINGS is set to make .ini inspection easier.
+ if (const char* p = strstr(name, "###"))
+ name = p;
+#endif
+ settings->Name = ImStrdup(name);
+ settings->ID = ImHashStr(name);
+ return settings;
}
-void ImGui::SetColumnOffset(int column_index, float offset)
+ImGuiWindowSettings* ImGui::FindWindowSettings(ImGuiID id)
{
ImGuiContext& g = *GImGui;
- ImGuiWindow* window = g.CurrentWindow;
- ImGuiColumnsSet* columns = window->DC.ColumnsSet;
- IM_ASSERT(columns != NULL);
-
- if (column_index < 0)
- column_index = columns->Current;
- IM_ASSERT(column_index < columns->Columns.Size);
-
- const bool preserve_width = !(columns->Flags & ImGuiColumnsFlags_NoPreserveWidths) && (column_index < columns->Count-1);
- const float width = preserve_width ? GetColumnWidthEx(columns, column_index, columns->IsBeingResized) : 0.0f;
-
- if (!(columns->Flags & ImGuiColumnsFlags_NoForceWithinWindow))
- offset = ImMin(offset, columns->MaxX - g.Style.ColumnsMinSpacing * (columns->Count - column_index));
- columns->Columns[column_index].OffsetNorm = PixelsToOffsetNorm(columns, offset - columns->MinX);
-
- if (preserve_width)
- SetColumnOffset(column_index + 1, offset + ImMax(g.Style.ColumnsMinSpacing, width));
+ for (int i = 0; i != g.SettingsWindows.Size; i++)
+ if (g.SettingsWindows[i].ID == id)
+ return &g.SettingsWindows[i];
+ return NULL;
}
-void ImGui::SetColumnWidth(int column_index, float width)
+ImGuiWindowSettings* ImGui::FindOrCreateWindowSettings(const char* name)
{
- ImGuiWindow* window = GetCurrentWindowRead();
- ImGuiColumnsSet* columns = window->DC.ColumnsSet;
- IM_ASSERT(columns != NULL);
-
- if (column_index < 0)
- column_index = columns->Current;
- SetColumnOffset(column_index + 1, GetColumnOffset(column_index) + width);
+ if (ImGuiWindowSettings* settings = FindWindowSettings(ImHashStr(name)))
+ return settings;
+ return CreateNewWindowSettings(name);
}
-void ImGui::PushColumnClipRect(int column_index)
+void ImGui::LoadIniSettingsFromDisk(const char* ini_filename)
{
- ImGuiWindow* window = GetCurrentWindowRead();
- ImGuiColumnsSet* columns = window->DC.ColumnsSet;
- if (column_index < 0)
- column_index = columns->Current;
-
- PushClipRect(columns->Columns[column_index].ClipRect.Min, columns->Columns[column_index].ClipRect.Max, false);
+ size_t file_data_size = 0;
+ char* file_data = (char*)ImFileLoadToMemory(ini_filename, "rb", &file_data_size);
+ if (!file_data)
+ return;
+ LoadIniSettingsFromMemory(file_data, (size_t)file_data_size);
+ IM_FREE(file_data);
}
-static ImGuiColumnsSet* FindOrAddColumnsSet(ImGuiWindow* window, ImGuiID id)
+ImGuiSettingsHandler* ImGui::FindSettingsHandler(const char* type_name)
{
- for (int n = 0; n < window->ColumnsStorage.Size; n++)
- if (window->ColumnsStorage[n].ID == id)
- return &window->ColumnsStorage[n];
-
- window->ColumnsStorage.push_back(ImGuiColumnsSet());
- ImGuiColumnsSet* columns = &window->ColumnsStorage.back();
- columns->ID = id;
- return columns;
+ ImGuiContext& g = *GImGui;
+ const ImGuiID type_hash = ImHashStr(type_name);
+ for (int handler_n = 0; handler_n < g.SettingsHandlers.Size; handler_n++)
+ if (g.SettingsHandlers[handler_n].TypeHash == type_hash)
+ return &g.SettingsHandlers[handler_n];
+ return NULL;
}
-void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlags flags)
+// Zero-tolerance, no error reporting, cheap .ini parsing
+void ImGui::LoadIniSettingsFromMemory(const char* ini_data, size_t ini_size)
{
ImGuiContext& g = *GImGui;
- ImGuiWindow* window = GetCurrentWindow();
-
- IM_ASSERT(columns_count > 1);
- IM_ASSERT(window->DC.ColumnsSet == NULL); // Nested columns are currently not supported
-
- // Differentiate column ID with an arbitrary prefix for cases where users name their columns set the same as another widget.
- // In addition, when an identifier isn't explicitly provided we include the number of columns in the hash to make it uniquer.
- PushID(0x11223347 + (str_id ? 0 : columns_count));
- ImGuiID id = window->GetID(str_id ? str_id : "columns");
- PopID();
+ IM_ASSERT(g.Initialized);
+ IM_ASSERT(g.SettingsLoaded == false && g.FrameCount == 0);
- // Acquire storage for the columns set
- ImGuiColumnsSet* columns = FindOrAddColumnsSet(window, id);
- IM_ASSERT(columns->ID == id);
- columns->Current = 0;
- columns->Count = columns_count;
- columns->Flags = flags;
- window->DC.ColumnsSet = columns;
-
- // Set state for first column
- const float content_region_width = (window->SizeContentsExplicit.x != 0.0f) ? (window->SizeContentsExplicit.x) : (window->InnerClipRect.Max.x - window->Pos.x);
- columns->MinX = window->DC.Indent.x - g.Style.ItemSpacing.x; // Lock our horizontal range
- columns->MaxX = ImMax(content_region_width - window->Scroll.x, columns->MinX + 1.0f);
- columns->StartPosY = window->DC.CursorPos.y;
- columns->StartMaxPosX = window->DC.CursorMaxPos.x;
- columns->LineMinY = columns->LineMaxY = window->DC.CursorPos.y;
- window->DC.ColumnsOffset.x = 0.0f;
- window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x);
+ // For user convenience, we allow passing a non zero-terminated string (hence the ini_size parameter).
+ // For our convenience and to make the code simpler, we'll also write zero-terminators within the buffer. So let's create a writable copy..
+ if (ini_size == 0)
+ ini_size = strlen(ini_data);
+ char* buf = (char*)IM_ALLOC(ini_size + 1);
+ char* buf_end = buf + ini_size;
+ memcpy(buf, ini_data, ini_size);
+ buf[ini_size] = 0;
- // Clear data if columns count changed
- if (columns->Columns.Size != 0 && columns->Columns.Size != columns_count + 1)
- columns->Columns.resize(0);
+ void* entry_data = NULL;
+ ImGuiSettingsHandler* entry_handler = NULL;
- // Initialize defaults
- columns->IsFirstFrame = (columns->Columns.Size == 0);
- if (columns->Columns.Size == 0)
+ char* line_end = NULL;
+ for (char* line = buf; line < buf_end; line = line_end + 1)
{
- columns->Columns.reserve(columns_count + 1);
- for (int n = 0; n < columns_count + 1; n++)
+ // Skip new lines markers, then find end of the line
+ while (*line == '\n' || *line == '\r')
+ line++;
+ line_end = line;
+ while (line_end < buf_end && *line_end != '\n' && *line_end != '\r')
+ line_end++;
+ line_end[0] = 0;
+ if (line[0] == ';')
+ continue;
+ if (line[0] == '[' && line_end > line && line_end[-1] == ']')
{
- ImGuiColumnData column;
- column.OffsetNorm = n / (float)columns_count;
- columns->Columns.push_back(column);
- }
- }
-
- for (int n = 0; n < columns_count; n++)
- {
- // Compute clipping rectangle
- ImGuiColumnData* column = &columns->Columns[n];
- float clip_x1 = ImFloor(0.5f + window->Pos.x + GetColumnOffset(n) - 1.0f);
- float clip_x2 = ImFloor(0.5f + window->Pos.x + GetColumnOffset(n + 1) - 1.0f);
- column->ClipRect = ImRect(clip_x1, -FLT_MAX, clip_x2, +FLT_MAX);
- column->ClipRect.ClipWith(window->ClipRect);
- }
-
- window->DrawList->ChannelsSplit(columns->Count);
- PushColumnClipRect();
- PushItemWidth(GetColumnWidth() * 0.65f);
-}
-
-void ImGui::EndColumns()
-{
- ImGuiContext& g = *GImGui;
- ImGuiWindow* window = GetCurrentWindow();
- ImGuiColumnsSet* columns = window->DC.ColumnsSet;
- IM_ASSERT(columns != NULL);
-
- PopItemWidth();
- PopClipRect();
- window->DrawList->ChannelsMerge();
-
- columns->LineMaxY = ImMax(columns->LineMaxY, window->DC.CursorPos.y);
- window->DC.CursorPos.y = columns->LineMaxY;
- if (!(columns->Flags & ImGuiColumnsFlags_GrowParentContentsSize))
- window->DC.CursorMaxPos.x = columns->StartMaxPosX; // Restore cursor max pos, as columns don't grow parent
-
- // Draw columns borders and handle resize
- bool is_being_resized = false;
- if (!(columns->Flags & ImGuiColumnsFlags_NoBorder) && !window->SkipItems)
- {
- const float y1 = columns->StartPosY;
- const float y2 = window->DC.CursorPos.y;
- int dragging_column = -1;
- for (int n = 1; n < columns->Count; n++)
- {
- float x = window->Pos.x + GetColumnOffset(n);
- const ImGuiID column_id = columns->ID + ImGuiID(n);
- const float column_hw = GetColumnsRectHalfWidth(); // Half-width for interaction
- const ImRect column_rect(ImVec2(x - column_hw, y1), ImVec2(x + column_hw, y2));
- KeepAliveID(column_id);
- if (IsClippedEx(column_rect, column_id, false))
- continue;
-
- bool hovered = false, held = false;
- if (!(columns->Flags & ImGuiColumnsFlags_NoResize))
+ // Parse "[Type][Name]". Note that 'Name' can itself contains [] characters, which is acceptable with the current format and parsing code.
+ line_end[-1] = 0;
+ const char* name_end = line_end - 1;
+ const char* type_start = line + 1;
+ char* type_end = (char*)(intptr_t)ImStrchrRange(type_start, name_end, ']');
+ const char* name_start = type_end ? ImStrchrRange(type_end + 1, name_end, '[') : NULL;
+ if (!type_end || !name_start)
{
- ButtonBehavior(column_rect, column_id, &hovered, &held);
- if (hovered || held)
- g.MouseCursor = ImGuiMouseCursor_ResizeEW;
- if (held && !(columns->Columns[n].Flags & ImGuiColumnsFlags_NoResize))
- dragging_column = n;
+ name_start = type_start; // Import legacy entries that have no type
+ type_start = "Window";
}
-
- // Draw column (we clip the Y boundaries CPU side because very long triangles are mishandled by some GPU drivers.)
- const ImU32 col = GetColorU32(held ? ImGuiCol_SeparatorActive : hovered ? ImGuiCol_SeparatorHovered : ImGuiCol_Separator);
- const float xi = (float)(int)x;
- window->DrawList->AddLine(ImVec2(xi, ImMax(y1 + 1.0f, window->ClipRect.Min.y)), ImVec2(xi, ImMin(y2, window->ClipRect.Max.y)), col);
+ else
+ {
+ *type_end = 0; // Overwrite first ']'
+ name_start++; // Skip second '['
+ }
+ entry_handler = FindSettingsHandler(type_start);
+ entry_data = entry_handler ? entry_handler->ReadOpenFn(&g, entry_handler, name_start) : NULL;
}
-
- // Apply dragging after drawing the column lines, so our rendered lines are in sync with how items were displayed during the frame.
- if (dragging_column != -1)
+ else if (entry_handler != NULL && entry_data != NULL)
{
- if (!columns->IsBeingResized)
- for (int n = 0; n < columns->Count + 1; n++)
- columns->Columns[n].OffsetNormBeforeResize = columns->Columns[n].OffsetNorm;
- columns->IsBeingResized = is_being_resized = true;
- float x = GetDraggedColumnOffset(columns, dragging_column);
- SetColumnOffset(dragging_column, x);
+ // Let type handler parse the line
+ entry_handler->ReadLineFn(&g, entry_handler, entry_data, line);
}
}
- columns->IsBeingResized = is_being_resized;
-
- window->DC.ColumnsSet = NULL;
- window->DC.ColumnsOffset.x = 0.0f;
- window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x);
+ IM_FREE(buf);
+ g.SettingsLoaded = true;
+ DockContextOnLoadSettings(&g);
}
-// [2018-03: This is currently the only public API, while we are working on making BeginColumns/EndColumns user-facing]
-void ImGui::Columns(int columns_count, const char* id, bool border)
+void ImGui::SaveIniSettingsToDisk(const char* ini_filename)
{
- ImGuiWindow* window = GetCurrentWindow();
- IM_ASSERT(columns_count >= 1);
-
- ImGuiColumnsFlags flags = (border ? 0 : ImGuiColumnsFlags_NoBorder);
- //flags |= ImGuiColumnsFlags_NoPreserveWidths; // NB: Legacy behavior
- if (window->DC.ColumnsSet != NULL && window->DC.ColumnsSet->Count == columns_count && window->DC.ColumnsSet->Flags == flags)
+ ImGuiContext& g = *GImGui;
+ g.SettingsDirtyTimer = 0.0f;
+ if (!ini_filename)
return;
- if (window->DC.ColumnsSet != NULL)
- EndColumns();
-
- if (columns_count != 1)
- BeginColumns(id, columns_count, flags);
+ size_t ini_data_size = 0;
+ const char* ini_data = SaveIniSettingsToMemory(&ini_data_size);
+ FILE* f = ImFileOpen(ini_filename, "wt");
+ if (!f)
+ return;
+ fwrite(ini_data, sizeof(char), ini_data_size, f);
+ fclose(f);
}
-//-----------------------------------------------------------------------------
-// [SECTION] DRAG AND DROP
-//-----------------------------------------------------------------------------
-
-void ImGui::ClearDragDrop()
+// Call registered handlers (e.g. SettingsHandlerWindow_WriteAll() + custom handlers) to write their stuff into a text buffer
+const char* ImGui::SaveIniSettingsToMemory(size_t* out_size)
{
ImGuiContext& g = *GImGui;
- g.DragDropActive = false;
- g.DragDropPayload.Clear();
- g.DragDropAcceptFlags = ImGuiDragDropFlags_None;
- g.DragDropAcceptIdCurr = g.DragDropAcceptIdPrev = 0;
- g.DragDropAcceptIdCurrRectSurface = FLT_MAX;
- g.DragDropAcceptFrameCount = -1;
+ g.SettingsDirtyTimer = 0.0f;
+ g.SettingsIniData.Buf.resize(0);
+ g.SettingsIniData.Buf.push_back(0);
+ for (int handler_n = 0; handler_n < g.SettingsHandlers.Size; handler_n++)
+ {
+ ImGuiSettingsHandler* handler = &g.SettingsHandlers[handler_n];
+ handler->WriteAllFn(&g, handler, &g.SettingsIniData);
+ }
+ if (out_size)
+ *out_size = (size_t)g.SettingsIniData.size();
+ return g.SettingsIniData.c_str();
+}
- g.DragDropPayloadBufHeap.clear();
- memset(&g.DragDropPayloadBufLocal, 0, sizeof(g.DragDropPayloadBufLocal));
+static void* SettingsHandlerWindow_ReadOpen(ImGuiContext*, ImGuiSettingsHandler*, const char* name)
+{
+ ImGuiWindowSettings* settings = ImGui::FindWindowSettings(ImHashStr(name));
+ if (!settings)
+ settings = ImGui::CreateNewWindowSettings(name);
+ return (void*)settings;
}
-// Call when current ID is active.
-// When this returns true you need to: a) call SetDragDropPayload() exactly once, b) you may render the payload visual/description, c) call EndDragDropSource()
-bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags)
+static void SettingsHandlerWindow_ReadLine(ImGuiContext*, ImGuiSettingsHandler*, void* entry, const char* line)
{
- ImGuiContext& g = *GImGui;
- ImGuiWindow* window = g.CurrentWindow;
+ ImGuiWindowSettings* settings = (ImGuiWindowSettings*)entry;
+ int x, y;
+ int i;
+ ImU32 u1;
+ if (sscanf(line, "Pos=%i,%i", &x, &y) == 2) { settings->Pos = ImVec2ih((short)x, (short)y); }
+ else if (sscanf(line, "Size=%i,%i", &x, &y) == 2) { settings->Size = ImVec2ih((short)x, (short)y); }
+ else if (sscanf(line, "ViewportId=0x%08X", &u1) == 1) { settings->ViewportId = u1; }
+ else if (sscanf(line, "ViewportPos=%i,%i", &x, &y) == 2) { settings->ViewportPos = ImVec2ih((short)x, (short)y); }
+ else if (sscanf(line, "Collapsed=%d", &i) == 1) { settings->Collapsed = (i != 0); }
+ else if (sscanf(line, "DockId=0x%X,%d", &u1, &i) == 2) { settings->DockId = u1; settings->DockOrder = (short)i; }
+ else if (sscanf(line, "DockId=0x%X", &u1) == 1) { settings->DockId = u1; settings->DockOrder = -1; }
+ else if (sscanf(line, "ClassId=0x%X", &u1) == 1) { settings->ClassId = u1; }
+}
- bool source_drag_active = false;
- ImGuiID source_id = 0;
- ImGuiID source_parent_id = 0;
- int mouse_button = 0;
- if (!(flags & ImGuiDragDropFlags_SourceExtern))
+static void SettingsHandlerWindow_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* buf)
+{
+ // Gather data from windows that were active during this session
+ // (if a window wasn't opened in this session we preserve its settings)
+ ImGuiContext& g = *ctx;
+ for (int i = 0; i != g.Windows.Size; i++)
{
- source_id = window->DC.LastItemId;
- if (source_id != 0 && g.ActiveId != source_id) // Early out for most common case
- return false;
- if (g.IO.MouseDown[mouse_button] == false)
- return false;
-
- if (source_id == 0)
- {
- // If you want to use BeginDragDropSource() on an item with no unique identifier for interaction, such as Text() or Image(), you need to:
- // A) Read the explanation below, B) Use the ImGuiDragDropFlags_SourceAllowNullID flag, C) Swallow your programmer pride.
- if (!(flags & ImGuiDragDropFlags_SourceAllowNullID))
- {
- IM_ASSERT(0);
- return false;
- }
+ ImGuiWindow* window = g.Windows[i];
+ if (window->Flags & ImGuiWindowFlags_NoSavedSettings)
+ continue;
- // Magic fallback (=somehow reprehensible) to handle items with no assigned ID, e.g. Text(), Image()
- // We build a throwaway ID based on current ID stack + relative AABB of items in window.
- // THE IDENTIFIER WON'T SURVIVE ANY REPOSITIONING OF THE WIDGET, so if your widget moves your dragging operation will be canceled.
- // We don't need to maintain/call ClearActiveID() as releasing the button will early out this function and trigger !ActiveIdIsAlive.
- bool is_hovered = (window->DC.LastItemStatusFlags & ImGuiItemStatusFlags_HoveredRect) != 0;
- if (!is_hovered && (g.ActiveId == 0 || g.ActiveIdWindow != window))
- return false;
- source_id = window->DC.LastItemId = window->GetIDFromRectangle(window->DC.LastItemRect);
- if (is_hovered)
- SetHoveredID(source_id);
- if (is_hovered && g.IO.MouseClicked[mouse_button])
- {
- SetActiveID(source_id, window);
- FocusWindow(window);
- }
- if (g.ActiveId == source_id) // Allow the underlying widget to display/return hovered during the mouse release frame, else we would get a flicker.
- g.ActiveIdAllowOverlap = is_hovered;
- }
- else
+ ImGuiWindowSettings* settings = (window->SettingsIdx != -1) ? &g.SettingsWindows[window->SettingsIdx] : ImGui::FindWindowSettings(window->ID);
+ if (!settings)
{
- g.ActiveIdAllowOverlap = false;
+ settings = ImGui::CreateNewWindowSettings(window->Name);
+ window->SettingsIdx = g.SettingsWindows.index_from_ptr(settings);
}
- if (g.ActiveId != source_id)
- return false;
- source_parent_id = window->IDStack.back();
- source_drag_active = IsMouseDragging(mouse_button);
- }
- else
- {
- window = NULL;
- source_id = ImHashStr("#SourceExtern", 0);
- source_drag_active = true;
+ IM_ASSERT(settings->ID == window->ID);
+ settings->Pos = ImVec2ih(window->Pos - window->ViewportPos);
+ settings->Size = ImVec2ih(window->SizeFull);
+ settings->ViewportId = window->ViewportId;
+ settings->ViewportPos = ImVec2ih(window->ViewportPos);
+ IM_ASSERT(window->DockNode == NULL || window->DockNode->ID == window->DockId);
+ settings->DockId = window->DockId;
+ settings->ClassId = window->WindowClass.ClassId;
+ settings->DockOrder = window->DockOrder;
+ settings->Collapsed = window->Collapsed;
}
- if (source_drag_active)
+ // Write to text buffer
+ buf->reserve(buf->size() + g.SettingsWindows.Size * 96); // ballpark reserve
+ for (int i = 0; i != g.SettingsWindows.Size; i++)
{
- if (!g.DragDropActive)
+ const ImGuiWindowSettings* settings = &g.SettingsWindows[i];
+ buf->appendf("[%s][%s]\n", handler->TypeName, settings->Name);
+ if (settings->ViewportId != 0 && settings->ViewportId != ImGui::IMGUI_VIEWPORT_DEFAULT_ID)
{
- IM_ASSERT(source_id != 0);
- ClearDragDrop();
- ImGuiPayload& payload = g.DragDropPayload;
- payload.SourceId = source_id;
- payload.SourceParentId = source_parent_id;
- g.DragDropActive = true;
- g.DragDropSourceFlags = flags;
- g.DragDropMouseButton = mouse_button;
+ buf->appendf("ViewportPos=%d,%d\n", settings->ViewportPos.x, settings->ViewportPos.y);
+ buf->appendf("ViewportId=0x%08X\n", settings->ViewportId);
}
- g.DragDropSourceFrameCount = g.FrameCount;
- g.DragDropWithinSourceOrTarget = true;
-
- if (!(flags & ImGuiDragDropFlags_SourceNoPreviewTooltip))
+ if (settings->Pos.x != 0 || settings->Pos.y != 0 || settings->ViewportId == ImGui::IMGUI_VIEWPORT_DEFAULT_ID)
+ buf->appendf("Pos=%d,%d\n", settings->Pos.x, settings->Pos.y);
+ if (settings->Size.x != 0 || settings->Size.y != 0)
+ buf->appendf("Size=%d,%d\n", settings->Size.x, settings->Size.y);
+ buf->appendf("Collapsed=%d\n", settings->Collapsed);
+ if (settings->DockId != 0)
{
- // Target can request the Source to not display its tooltip (we use a dedicated flag to make this request explicit)
- // We unfortunately can't just modify the source flags and skip the call to BeginTooltip, as caller may be emitting contents.
- BeginTooltip();
- if (g.DragDropAcceptIdPrev && (g.DragDropAcceptFlags & ImGuiDragDropFlags_AcceptNoPreviewTooltip))
- {
- ImGuiWindow* tooltip_window = g.CurrentWindow;
- tooltip_window->SkipItems = true;
- tooltip_window->HiddenFramesRegular = 1;
- }
+ // Write DockId as 4 digits if possible. Automatic DockId are small numbers, but full explicit DockSpace() are full ImGuiID range.
+ if (settings->DockOrder == -1)
+ buf->appendf("DockId=0x%08X\n", settings->DockId);
+ else
+ buf->appendf("DockId=0x%08X,%d\n", settings->DockId, settings->DockOrder);
+ if (settings->ClassId != 0)
+ buf->appendf("ClassId=0x%08X\n", settings->ClassId);
}
-
- if (!(flags & ImGuiDragDropFlags_SourceNoDisableHover) && !(flags & ImGuiDragDropFlags_SourceExtern))
- window->DC.LastItemStatusFlags &= ~ImGuiItemStatusFlags_HoveredRect;
-
- return true;
+ buf->appendf("\n");
}
- return false;
}
-void ImGui::EndDragDropSource()
+
+//-----------------------------------------------------------------------------
+// [SECTION] VIEWPORTS, PLATFORM WINDOWS
+//-----------------------------------------------------------------------------
+// - GetMainViewport()
+// - FindViewportByID()
+// - FindViewportByPlatformHandle()
+// - SetCurrentViewport() [Internal]
+// - SetWindowViewport() [Internal]
+// - GetWindowAlwaysWantOwnViewport() [Internal]
+// - UpdateTryMergeWindowIntoHostViewport() [Internal]
+// - UpdateTryMergeWindowIntoHostViewports() [Internal]
+// - TranslateWindowsInViewport() [Internal]
+// - ScaleWindowsInViewport() [Internal]
+// - FindHoveredViewportFromPlatformWindowStack() [Internal]
+// - UpdateViewportsNewFrame() [Internal]
+// - UpdateViewportsEndFrame() [Internal]
+// - AddUpdateViewport() [Internal]
+// - UpdateSelectWindowViewport() [Internal]
+// - UpdatePlatformWindows()
+// - RenderPlatformWindowsDefault()
+// - FindPlatformMonitorForPos() [Internal]
+// - FindPlatformMonitorForRect() [Internal]
+// - UpdateViewportPlatformMonitor() [Internal]
+// - DestroyPlatformWindow() [Internal]
+// - DestroyPlatformWindows()
+//-----------------------------------------------------------------------------
+
+ImGuiViewport* ImGui::GetMainViewport()
{
ImGuiContext& g = *GImGui;
- IM_ASSERT(g.DragDropActive);
- IM_ASSERT(g.DragDropWithinSourceOrTarget && "Not after a BeginDragDropSource()?");
+ return g.Viewports[0];
+}
- if (!(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoPreviewTooltip))
- EndTooltip();
+ImGuiViewport* ImGui::FindViewportByID(ImGuiID id)
+{
+ ImGuiContext& g = *GImGui;
+ for (int n = 0; n < g.Viewports.Size; n++)
+ if (g.Viewports[n]->ID == id)
+ return g.Viewports[n];
+ return NULL;
+}
- // Discard the drag if have not called SetDragDropPayload()
- if (g.DragDropPayload.DataFrameCount == -1)
- ClearDragDrop();
- g.DragDropWithinSourceOrTarget = false;
+ImGuiViewport* ImGui::FindViewportByPlatformHandle(void* platform_handle)
+{
+ ImGuiContext& g = *GImGui;
+ for (int i = 0; i != g.Viewports.Size; i++)
+ if (g.Viewports[i]->PlatformHandle == platform_handle)
+ return g.Viewports[i];
+ return NULL;
}
-// Use 'cond' to choose to submit payload on drag start or every frame
-bool ImGui::SetDragDropPayload(const char* type, const void* data, size_t data_size, ImGuiCond cond)
+void ImGui::SetCurrentViewport(ImGuiWindow* current_window, ImGuiViewportP* viewport)
{
ImGuiContext& g = *GImGui;
- ImGuiPayload& payload = g.DragDropPayload;
- if (cond == 0)
- cond = ImGuiCond_Always;
+ (void)current_window;
- IM_ASSERT(type != NULL);
- IM_ASSERT(strlen(type) < IM_ARRAYSIZE(payload.DataType) && "Payload type can be at most 32 characters long");
- IM_ASSERT((data != NULL && data_size > 0) || (data == NULL && data_size == 0));
- IM_ASSERT(cond == ImGuiCond_Always || cond == ImGuiCond_Once);
- IM_ASSERT(payload.SourceId != 0); // Not called between BeginDragDropSource() and EndDragDropSource()
+ if (viewport)
+ viewport->LastFrameActive = g.FrameCount;
+ if (g.CurrentViewport == viewport)
+ return;
+ g.CurrentViewport = viewport;
+ //IMGUI_DEBUG_LOG_VIEWPORT("SetCurrentViewport changed '%s' 0x%08X\n", current_window ? current_window->Name : NULL, viewport ? viewport->ID : 0);
- if (cond == ImGuiCond_Always || payload.DataFrameCount == -1)
- {
- // Copy payload
- ImStrncpy(payload.DataType, type, IM_ARRAYSIZE(payload.DataType));
- g.DragDropPayloadBufHeap.resize(0);
- if (data_size > sizeof(g.DragDropPayloadBufLocal))
- {
- // Store in heap
- g.DragDropPayloadBufHeap.resize((int)data_size);
- payload.Data = g.DragDropPayloadBufHeap.Data;
- memcpy(payload.Data, data, data_size);
- }
- else if (data_size > 0)
- {
- // Store locally
- memset(&g.DragDropPayloadBufLocal, 0, sizeof(g.DragDropPayloadBufLocal));
- payload.Data = g.DragDropPayloadBufLocal;
- memcpy(payload.Data, data, data_size);
- }
- else
- {
- payload.Data = NULL;
- }
- payload.DataSize = (int)data_size;
- }
- payload.DataFrameCount = g.FrameCount;
+ // Notify platform layer of viewport changes
+ // FIXME-DPI: This is only currently used for experimenting with handling of multiple DPI
+ if (g.CurrentViewport && g.PlatformIO.Platform_OnChangedViewport)
+ g.PlatformIO.Platform_OnChangedViewport(g.CurrentViewport);
+}
- return (g.DragDropAcceptFrameCount == g.FrameCount) || (g.DragDropAcceptFrameCount == g.FrameCount - 1);
+static void SetWindowViewport(ImGuiWindow* window, ImGuiViewportP* viewport)
+{
+ window->Viewport = viewport;
+ window->ViewportId = viewport->ID;
+ window->ViewportOwned = (viewport->Window == window);
}
-bool ImGui::BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id)
+static bool ImGui::GetWindowAlwaysWantOwnViewport(ImGuiWindow* window)
{
+ // Tooltips and menus are not automatically forced into their own viewport when the NoMerge flag is set, however the multiplication of viewports makes them more likely to protrude and create their own.
ImGuiContext& g = *GImGui;
- if (!g.DragDropActive)
- return false;
-
- ImGuiWindow* window = g.CurrentWindow;
- if (g.HoveredWindowUnderMovingWindow == NULL || window->RootWindow != g.HoveredWindowUnderMovingWindow->RootWindow)
- return false;
- IM_ASSERT(id != 0);
- if (!IsMouseHoveringRect(bb.Min, bb.Max) || (id == g.DragDropPayload.SourceId))
- return false;
- if (window->SkipItems)
- return false;
-
- IM_ASSERT(g.DragDropWithinSourceOrTarget == false);
- g.DragDropTargetRect = bb;
- g.DragDropTargetId = id;
- g.DragDropWithinSourceOrTarget = true;
- return true;
+ if (g.IO.ConfigViewportsNoAutoMerge || (window->WindowClass.ViewportFlagsOverrideSet & ImGuiViewportFlags_NoAutoMerge))
+ if (g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable)
+ if (!window->DockIsActive)
+ if ((window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_ChildMenu | ImGuiWindowFlags_Tooltip)) == 0)
+ if ((window->Flags & ImGuiWindowFlags_Popup) == 0 || (window->Flags & ImGuiWindowFlags_Modal) != 0)
+ return true;
+ return false;
}
-// We don't use BeginDragDropTargetCustom() and duplicate its code because:
-// 1) we use LastItemRectHoveredRect which handles items that pushes a temporarily clip rectangle in their code. Calling BeginDragDropTargetCustom(LastItemRect) would not handle them.
-// 2) and it's faster. as this code may be very frequently called, we want to early out as fast as we can.
-// Also note how the HoveredWindow test is positioned differently in both functions (in both functions we optimize for the cheapest early out case)
-bool ImGui::BeginDragDropTarget()
+static bool ImGui::UpdateTryMergeWindowIntoHostViewport(ImGuiWindow* window, ImGuiViewportP* viewport)
{
ImGuiContext& g = *GImGui;
- if (!g.DragDropActive)
+ if (!(viewport->Flags & (ImGuiViewportFlags_CanHostOtherWindows | ImGuiViewportFlags_Minimized)) || window->Viewport == viewport)
return false;
-
- ImGuiWindow* window = g.CurrentWindow;
- if (!(window->DC.LastItemStatusFlags & ImGuiItemStatusFlags_HoveredRect))
+ if (!viewport->GetRect().Contains(window->Rect()))
return false;
- if (g.HoveredWindowUnderMovingWindow == NULL || window->RootWindow != g.HoveredWindowUnderMovingWindow->RootWindow)
+ if (GetWindowAlwaysWantOwnViewport(window))
return false;
- const ImRect& display_rect = (window->DC.LastItemStatusFlags & ImGuiItemStatusFlags_HasDisplayRect) ? window->DC.LastItemDisplayRect : window->DC.LastItemRect;
- ImGuiID id = window->DC.LastItemId;
- if (id == 0)
- id = window->GetIDFromRectangle(display_rect);
- if (g.DragDropPayload.SourceId == id)
- return false;
+ for (int n = 0; n < g.Windows.Size; n++)
+ {
+ ImGuiWindow* window_behind = g.Windows[n];
+ if (window_behind == window)
+ break;
+ if (window_behind->WasActive && window_behind->ViewportOwned && !(window_behind->Flags & ImGuiWindowFlags_ChildWindow))
+ if (window_behind->Viewport->GetRect().Overlaps(window->Rect()))
+ return false;
+ }
+
+ // Move to the existing viewport, Move child/hosted windows as well (FIXME-OPT: iterate child)
+ ImGuiViewportP* old_viewport = window->Viewport;
+ if (window->ViewportOwned)
+ for (int n = 0; n < g.Windows.Size; n++)
+ if (g.Windows[n]->Viewport == old_viewport)
+ SetWindowViewport(g.Windows[n], viewport);
+ SetWindowViewport(window, viewport);
+ BringWindowToDisplayFront(window);
- IM_ASSERT(g.DragDropWithinSourceOrTarget == false);
- g.DragDropTargetRect = display_rect;
- g.DragDropTargetId = id;
- g.DragDropWithinSourceOrTarget = true;
return true;
}
-bool ImGui::IsDragDropPayloadBeingAccepted()
+static bool ImGui::UpdateTryMergeWindowIntoHostViewports(ImGuiWindow* window)
{
ImGuiContext& g = *GImGui;
- return g.DragDropActive && g.DragDropAcceptIdPrev != 0;
+ return UpdateTryMergeWindowIntoHostViewport(window, g.Viewports[0]);
}
-const ImGuiPayload* ImGui::AcceptDragDropPayload(const char* type, ImGuiDragDropFlags flags)
+// Translate imgui windows when a Host Viewport has been moved
+// (This additionally keeps windows at the same place when ImGuiConfigFlags_ViewportsEnable is toggled!)
+void ImGui::TranslateWindowsInViewport(ImGuiViewportP* viewport, const ImVec2& old_pos, const ImVec2& new_pos)
{
ImGuiContext& g = *GImGui;
- ImGuiWindow* window = g.CurrentWindow;
- ImGuiPayload& payload = g.DragDropPayload;
- IM_ASSERT(g.DragDropActive); // Not called between BeginDragDropTarget() and EndDragDropTarget() ?
- IM_ASSERT(payload.DataFrameCount != -1); // Forgot to call EndDragDropTarget() ?
- if (type != NULL && !payload.IsDataType(type))
- return NULL;
+ IM_ASSERT(viewport->Window == NULL && (viewport->Flags & ImGuiViewportFlags_CanHostOtherWindows));
- // Accept smallest drag target bounding box, this allows us to nest drag targets conveniently without ordering constraints.
- // NB: We currently accept NULL id as target. However, overlapping targets requires a unique ID to function!
- const bool was_accepted_previously = (g.DragDropAcceptIdPrev == g.DragDropTargetId);
- ImRect r = g.DragDropTargetRect;
- float r_surface = r.GetWidth() * r.GetHeight();
- if (r_surface < g.DragDropAcceptIdCurrRectSurface)
- {
- g.DragDropAcceptFlags = flags;
- g.DragDropAcceptIdCurr = g.DragDropTargetId;
- g.DragDropAcceptIdCurrRectSurface = r_surface;
- }
+ // 1) We test if ImGuiConfigFlags_ViewportsEnable was just toggled, which allows us to conveniently
+ // translate imgui windows from OS-window-local to absolute coordinates or vice-versa.
+ // 2) If it's not going to fit into the new size, keep it at same absolute position.
+ // One problem with this is that most Win32 applications doesn't update their render while dragging,
+ // and so the window will appear to teleport when releasing the mouse.
+ const bool translate_all_windows = (g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable) != (g.ConfigFlagsLastFrame & ImGuiConfigFlags_ViewportsEnable);
+ ImRect test_still_fit_rect(old_pos, old_pos + viewport->Size);
+ ImVec2 delta_pos = new_pos - old_pos;
+ for (int window_n = 0; window_n < g.Windows.Size; window_n++) // FIXME-OPT
+ if (translate_all_windows || (g.Windows[window_n]->Viewport == viewport && test_still_fit_rect.Contains(g.Windows[window_n]->Rect())))
+ TranslateWindow(g.Windows[window_n], delta_pos);
+}
- // Render default drop visuals
- payload.Preview = was_accepted_previously;
- flags |= (g.DragDropSourceFlags & ImGuiDragDropFlags_AcceptNoDrawDefaultRect); // Source can also inhibit the preview (useful for external sources that lives for 1 frame)
- if (!(flags & ImGuiDragDropFlags_AcceptNoDrawDefaultRect) && payload.Preview)
+// Scale all windows (position, size). Use when e.g. changing DPI. (This is a lossy operation!)
+void ImGui::ScaleWindowsInViewport(ImGuiViewportP* viewport, float scale)
+{
+ ImGuiContext& g = *GImGui;
+ if (viewport->Window)
{
- // FIXME-DRAG: Settle on a proper default visuals for drop target.
- r.Expand(3.5f);
- bool push_clip_rect = !window->ClipRect.Contains(r);
- if (push_clip_rect) window->DrawList->PushClipRect(r.Min-ImVec2(1,1), r.Max+ImVec2(1,1));
- window->DrawList->AddRect(r.Min, r.Max, GetColorU32(ImGuiCol_DragDropTarget), 0.0f, ~0, 2.0f);
- if (push_clip_rect) window->DrawList->PopClipRect();
+ ScaleWindow(viewport->Window, scale);
+ }
+ else
+ {
+ for (int i = 0; i != g.Windows.Size; i++)
+ if (g.Windows[i]->Viewport == viewport)
+ ScaleWindow(g.Windows[i], scale);
}
-
- g.DragDropAcceptFrameCount = g.FrameCount;
- payload.Delivery = was_accepted_previously && !IsMouseDown(g.DragDropMouseButton); // For extern drag sources affecting os window focus, it's easier to just test !IsMouseDown() instead of IsMouseReleased()
- if (!payload.Delivery && !(flags & ImGuiDragDropFlags_AcceptBeforeDelivery))
- return NULL;
-
- return &payload;
}
-const ImGuiPayload* ImGui::GetDragDropPayload()
+// If the back-end doesn't set MouseLastHoveredViewport or doesn't honor ImGuiViewportFlags_NoInputs, we do a search ourselves.
+// A) It won't take account of the possibility that non-imgui windows may be in-between our dragged window and our target window.
+// B) It requires Platform_GetWindowFocus to be implemented by back-end.
+static ImGuiViewportP* FindHoveredViewportFromPlatformWindowStack(const ImVec2 mouse_platform_pos)
{
ImGuiContext& g = *GImGui;
- return g.DragDropActive ? &g.DragDropPayload : NULL;
+ ImGuiViewportP* best_candidate = NULL;
+ for (int n = 0; n < g.Viewports.Size; n++)
+ {
+ ImGuiViewportP* viewport = g.Viewports[n];
+ if (!(viewport->Flags & (ImGuiViewportFlags_NoInputs | ImGuiViewportFlags_Minimized)) && viewport->GetRect().Contains(mouse_platform_pos))
+ if (best_candidate == NULL || best_candidate->LastFrontMostStampCount < viewport->LastFrontMostStampCount)
+ best_candidate = viewport;
+ }
+ return best_candidate;
}
-// We don't really use/need this now, but added it for the sake of consistency and because we might need it later.
-void ImGui::EndDragDropTarget()
+// Update viewports and monitor infos
+// Note that this is running even if 'ImGuiConfigFlags_ViewportsEnable' is not set, in order to clear unused viewports (if any) and update monitor info.
+static void ImGui::UpdateViewportsNewFrame()
{
ImGuiContext& g = *GImGui;
- IM_ASSERT(g.DragDropActive);
- IM_ASSERT(g.DragDropWithinSourceOrTarget);
- g.DragDropWithinSourceOrTarget = false;
-}
-
-//-----------------------------------------------------------------------------
-// [SECTION] DOCKING
-//-----------------------------------------------------------------------------
-// Docking: Internal Types
-// Docking: Forward Declarations
-// Docking: ImGuiDockContext
-// Docking: ImGuiDockContext Docking/Undocking functions
-// Docking: ImGuiDockNode
-// Docking: ImGuiDockNode Tree manipulation functions
-// Docking: Public Functions (SetWindowDock, DockSpace)
-// Docking: Builder Functions
-// Docking: Begin/End Functions (called from Begin/End)
-// Docking: Settings
-//-----------------------------------------------------------------------------
-
-//-----------------------------------------------------------------------------
-// Docking: Internal Types
-//-----------------------------------------------------------------------------
-
-static float IMGUI_DOCK_SPLITTER_SIZE = 2.0f;
-
-enum ImGuiDockRequestType
-{
- ImGuiDockRequestType_None = 0,
- ImGuiDockRequestType_Dock,
- ImGuiDockRequestType_Undock,
- ImGuiDockRequestType_Split // Split is the same as Dock but without a DockPayload
-};
-
-struct ImGuiDockRequest
-{
- ImGuiDockRequestType Type;
- ImGuiWindow* DockTargetWindow; // Destination/Target Window to dock into (may be a loose window or a DockNode, might be NULL in which case DockTargetNode cannot be NULL)
- ImGuiDockNode* DockTargetNode; // Destination/Target Node to dock into
- ImGuiWindow* DockPayload; // Source/Payload window to dock (may be a loose window or a DockNode), [Optional]
- ImGuiDir DockSplitDir;
- float DockSplitRatio;
- bool DockSplitOuter;
- ImGuiWindow* UndockTargetWindow;
- ImGuiDockNode* UndockTargetNode;
+ IM_ASSERT(g.PlatformIO.Viewports.Size <= g.Viewports.Size);
- ImGuiDockRequest()
+ // Update Minimized status (we need it first in order to decide if we'll apply Pos/Size of the main viewport)
+ if ((g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable))
{
- Type = ImGuiDockRequestType_None;
- DockTargetWindow = DockPayload = UndockTargetWindow = NULL;
- DockTargetNode = UndockTargetNode = NULL;
- DockSplitDir = ImGuiDir_None;
- DockSplitRatio = 0.5f;
- DockSplitOuter = false;
+ for (int n = 0; n < g.Viewports.Size; n++)
+ {
+ ImGuiViewportP* viewport = g.Viewports[n];
+ const bool platform_funcs_available = viewport->PlatformWindowCreated;
+ if (g.PlatformIO.Platform_GetWindowMinimized && platform_funcs_available)
+ {
+ bool minimized = g.PlatformIO.Platform_GetWindowMinimized(viewport);
+ if (minimized)
+ viewport->Flags |= ImGuiViewportFlags_Minimized;
+ else
+ viewport->Flags &= ~ImGuiViewportFlags_Minimized;
+ }
+ }
}
-};
-struct ImGuiDockPreviewData
-{
- ImGuiDockNode FutureNode;
- bool IsDropAllowed;
- bool IsCenterAvailable;
- bool IsSidesAvailable; // Hold your breath, grammar freaks..
- bool IsSplitDirExplicit; // Set when hovered the drop rect (vs. implicit SplitDir==None when hovered the window)
- ImGuiDockNode* SplitNode;
- ImGuiDir SplitDir;
- float SplitRatio;
- ImRect DropRectsDraw[ImGuiDir_COUNT + 1]; // May be slightly different from hit-testing drop rects used in DockNodeCalcDropRects()
+ // Create/update main viewport with current platform position and size
+ ImGuiViewportP* main_viewport = g.Viewports[0];
+ IM_ASSERT(main_viewport->ID == IMGUI_VIEWPORT_DEFAULT_ID);
+ IM_ASSERT(main_viewport->Window == NULL);
+ ImVec2 main_viewport_platform_pos = ImVec2(0.0f, 0.0f);
+ ImVec2 main_viewport_platform_size = g.IO.DisplaySize;
+ if (g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable)
+ main_viewport_platform_pos = (main_viewport->Flags & ImGuiViewportFlags_Minimized) ? main_viewport->Pos : g.PlatformIO.Platform_GetWindowPos(main_viewport);
+ AddUpdateViewport(NULL, IMGUI_VIEWPORT_DEFAULT_ID, main_viewport_platform_pos, main_viewport_platform_size, ImGuiViewportFlags_CanHostOtherWindows);
- ImGuiDockPreviewData() : FutureNode(0) { IsDropAllowed = IsCenterAvailable = IsSidesAvailable = IsSplitDirExplicit = false; SplitNode = NULL; SplitDir = ImGuiDir_None; SplitRatio = 0.f; }
-};
+ g.CurrentViewport = NULL;
+ g.MouseViewport = NULL;
+ for (int n = 0; n < g.Viewports.Size; n++)
+ {
+ ImGuiViewportP* viewport = g.Viewports[n];
+ viewport->Idx = n;
-// Persistent Settings data, stored contiguously in SettingsNodes (sizeof() ~32 bytes)
-struct ImGuiDockNodeSettings
-{
- ImGuiID ID;
- ImGuiID ParentID;
- ImGuiID SelectedTabID;
- char SplitAxis;
- char Depth;
- char IsDockSpace;
- char IsCentralNode;
- char IsHiddenTabBar;
- ImVec2ih Pos;
- ImVec2ih Size;
- ImVec2ih SizeRef;
- ImGuiDockNodeSettings() { ID = ParentID = SelectedTabID = 0; SplitAxis = ImGuiAxis_None; Depth = 0; IsDockSpace = IsCentralNode = IsHiddenTabBar = 0; }
-};
+ // Erase unused viewports
+ if (n > 0 && viewport->LastFrameActive < g.FrameCount - 2)
+ {
+ // Clear references to this viewport in windows (window->ViewportId becomes the master data)
+ for (int window_n = 0; window_n < g.Windows.Size; window_n++)
+ if (g.Windows[window_n]->Viewport == viewport)
+ {
+ g.Windows[window_n]->Viewport = NULL;
+ g.Windows[window_n]->ViewportOwned = false;
+ }
+ if (viewport == g.MouseLastHoveredViewport)
+ g.MouseLastHoveredViewport = NULL;
+ g.Viewports.erase(g.Viewports.Data + n);
-struct ImGuiDockContext
-{
- ImGuiStorage Nodes; // Map ID -> ImGuiDockNode*: Active nodes
- ImVector Requests;
- ImVector SettingsNodes;
- bool WantFullRebuild;
- ImGuiDockContext() { WantFullRebuild = false; }
-};
+ // Destroy
+ IMGUI_DEBUG_LOG_VIEWPORT("Delete Viewport %08X (%s)\n", viewport->ID, viewport->Window ? viewport->Window->Name : "n/a");
+ DestroyPlatformWindow(viewport); // In most circumstances the platform window will already be destroyed here.
+ IM_ASSERT(g.PlatformIO.Viewports.contains(viewport) == false);
+ IM_DELETE(viewport);
+ n--;
+ continue;
+ }
-//-----------------------------------------------------------------------------
-// Docking: Forward Declarations
-//-----------------------------------------------------------------------------
+ const bool platform_funcs_available = viewport->PlatformWindowCreated;
+ if ((g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable))
+ {
+ // Update Position and Size (from Platform Window to ImGui) if requested.
+ // We do it early in the frame instead of waiting for UpdatePlatformWindows() to avoid a frame of lag when moving/resizing using OS facilities.
+ if (!(viewport->Flags & ImGuiViewportFlags_Minimized) && platform_funcs_available)
+ {
+ if (viewport->PlatformRequestMove)
+ viewport->Pos = viewport->LastPlatformPos = g.PlatformIO.Platform_GetWindowPos(viewport);
+ if (viewport->PlatformRequestResize)
+ viewport->Size = viewport->LastPlatformSize = g.PlatformIO.Platform_GetWindowSize(viewport);
+ }
+ }
-namespace ImGui
-{
- // ImGuiDockContext
- static ImGuiDockNode* DockContextAddNode(ImGuiContext* ctx, ImGuiID id);
- static ImGuiID DockContextGenNodeID(ImGuiContext* ctx);
- static void DockContextRemoveNode(ImGuiContext* ctx, ImGuiDockNode* node, bool merge_sibling_into_parent_node);
- static void DockContextQueueDock(ImGuiContext* ctx, ImGuiWindow* target, ImGuiDockNode* target_node, ImGuiWindow* payload, ImGuiDir split_dir, float split_ratio, bool split_outer);
- static void DockContextQueueNotifyRemovedNode(ImGuiContext* ctx, ImGuiDockNode* node);
- static void DockContextProcessDock(ImGuiContext* ctx, ImGuiDockRequest* req);
- static void DockContextProcessUndockWindow(ImGuiContext* ctx, ImGuiWindow* window, bool clear_persistent_docking_ref = true);
- static void DockContextProcessUndockNode(ImGuiContext* ctx, ImGuiDockNode* node);
- static void DockContextPruneUnusedSettingsNodes(ImGuiContext* ctx);
- static ImGuiDockNode* DockContextFindNodeByID(ImGuiContext* ctx, ImGuiID id);
- static void DockContextClearNodes(ImGuiContext* ctx, ImGuiID root_id, bool clear_persistent_docking_refs); // Use root_id==0 to clear all
- static void DockContextBuildNodesFromSettings(ImGuiContext* ctx, ImGuiDockNodeSettings* node_settings_array, int node_settings_count);
- static void DockContextBuildAddWindowsToNodes(ImGuiContext* ctx, ImGuiID root_id); // Use root_id==0 to add all
+ // Update/copy monitor info
+ UpdateViewportPlatformMonitor(viewport);
- // ImGuiDockNode
- static void DockNodeAddWindow(ImGuiDockNode* node, ImGuiWindow* window, bool add_to_tab_bar);
- static void DockNodeMoveWindows(ImGuiDockNode* dst_node, ImGuiDockNode* src_node);
- static void DockNodeMoveChildNodes(ImGuiDockNode* dst_node, ImGuiDockNode* src_node);
- static void DockNodeApplyPosSizeToWindows(ImGuiDockNode* node);
- static void DockNodeRemoveWindow(ImGuiDockNode* node, ImGuiWindow* window, ImGuiID save_dock_id);
- static void DockNodeHideHostWindow(ImGuiDockNode* node);
- static void DockNodeUpdate(ImGuiDockNode* node);
- static void DockNodeUpdateVisibleFlagAndInactiveChilds(ImGuiDockNode* node);
- static void DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_window);
- static void DockNodeUpdateVisibleFlag(ImGuiDockNode* node);
- static void DockNodeStartMouseMovingWindow(ImGuiDockNode* node, ImGuiWindow* window);
- static bool DockNodeIsDropAllowed(ImGuiWindow* host_window, ImGuiWindow* payload_window);
- static bool DockNodePreviewDockCalc(ImGuiWindow* host_window, ImGuiDockNode* host_node, ImGuiWindow* payload_window, ImGuiDockPreviewData* preview_data, bool is_explicit_target, bool is_outer_docking);
- static void DockNodePreviewDockRender(ImGuiWindow* host_window, ImGuiDockNode* host_node, ImGuiWindow* payload_window, const ImGuiDockPreviewData* preview_data);
- static ImRect DockNodeCalcTabBarRect(const ImGuiDockNode* node);
- static void DockNodeCalcSplitRects(ImVec2& pos_old, ImVec2& size_old, ImVec2& pos_new, ImVec2& size_new, ImGuiDir dir, ImVec2 size_new_desired);
- static bool DockNodeCalcDropRects(const ImRect& parent, ImGuiDir dir, ImRect& out_draw, bool outer_docking);
- static const char* DockNodeGetHostWindowTitle(ImGuiDockNode* node, char* buf, int buf_size) { ImFormatString(buf, buf_size, "##DockNode_%02X", node->ID); return buf; }
- static int DockNodeGetDepth(const ImGuiDockNode* node) { int depth = 0; while (node->ParentNode) { node = node->ParentNode; depth++; } return depth; }
- static int DockNodeGetTabOrder(ImGuiWindow* window);
+ // Reset alpha every frame. Users of transparency (docking) needs to request a lower alpha back.
+ viewport->Alpha = 1.0f;
- // ImGuiDockNode tree manipulations
- static void DockNodeTreeSplit(ImGuiContext* ctx, ImGuiDockNode* parent_node, ImGuiAxis split_axis, int split_first_child, float split_ratio, ImGuiDockNode* new_node);
- static void DockNodeTreeMerge(ImGuiContext* ctx, ImGuiDockNode* parent_node, ImGuiDockNode* merge_lead_child);
- static void DockNodeTreeUpdatePosSize(ImGuiDockNode* node, ImVec2 pos, ImVec2 size);
- static void DockNodeTreeUpdateSplitter(ImGuiDockNode* node);
- static ImGuiDockNode* DockNodeTreeFindNodeByPos(ImGuiDockNode* node, ImVec2 pos);
- static ImGuiDockNode* DockNodeTreeFindFallbackLeafNode(ImGuiDockNode* node);
+ // Translate imgui windows when a Host Viewport has been moved
+ // (This additionally keeps windows at the same place when ImGuiConfigFlags_ViewportsEnable is toggled!)
+ const ImVec2 viewport_delta_pos = viewport->Pos - viewport->LastPos;
+ if ((viewport->Flags & ImGuiViewportFlags_CanHostOtherWindows) && (viewport_delta_pos.x != 0.0f || viewport_delta_pos.y != 0.0f))
+ TranslateWindowsInViewport(viewport, viewport->LastPos, viewport->Pos);
- // Settings
- static void DockSettingsRenameNodeReferences(ImGuiID old_node_id, ImGuiID new_node_id);
- static void DockSettingsRemoveNodeReferences(ImGuiID* node_ids, int node_ids_count);
- static ImGuiDockNodeSettings* DockSettingsFindNodeSettings(ImGuiContext* ctx, ImGuiID node_id);
- static void* DockSettingsHandler_ReadOpen(ImGuiContext*, ImGuiSettingsHandler*, const char* name);
- static void DockSettingsHandler_ReadLine(ImGuiContext*, ImGuiSettingsHandler*, void* entry, const char* line);
- static void DockSettingsHandler_WriteAll(ImGuiContext* imgui_ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* buf);
-}
+ // Update DPI scale
+ float new_dpi_scale;
+ if (g.PlatformIO.Platform_GetWindowDpiScale && platform_funcs_available)
+ new_dpi_scale = g.PlatformIO.Platform_GetWindowDpiScale(viewport);
+ else if (viewport->PlatformMonitor != -1)
+ new_dpi_scale = g.PlatformIO.Monitors[viewport->PlatformMonitor].DpiScale;
+ else
+ new_dpi_scale = (viewport->DpiScale != 0.0f) ? viewport->DpiScale : 1.0f;
+ if (viewport->DpiScale != 0.0f && new_dpi_scale != viewport->DpiScale)
+ {
+ float scale_factor = new_dpi_scale / viewport->DpiScale;
+ if (g.IO.ConfigFlags & ImGuiConfigFlags_DpiEnableScaleViewports)
+ ScaleWindowsInViewport(viewport, scale_factor);
+ //if (viewport == GetMainViewport())
+ // g.PlatformInterface.SetWindowSize(viewport, viewport->Size * scale_factor);
-//-----------------------------------------------------------------------------
-// Docking: ImGuiDockContext
-//-----------------------------------------------------------------------------
-// The lifetime model is different from the one of regular windows: we always create a ImGuiDockNode for each ImGuiDockNodeSettings,
-// or we always hold the entire docking node tree. Nodes are frequently hidden, e.g. if the window(s) or child nodes they host are not active.
-// At boot time only, we run a simple GC to remove nodes that have no references.
-// Because dock node settings (which are small, contiguous structures) are always mirrored by their corresponding dock nodes (more complete structures),
-// we can also very easily recreate the nodes from scratch given the settings data (this is what DockContextRebuild() does).
-// This is convenient as docking reconfiguration can be implemented by mostly poking at the simpler settings data.
-//-----------------------------------------------------------------------------
+ // Scale our window moving pivot so that the window will rescale roughly around the mouse position.
+ // FIXME-VIEWPORT: This currently creates a resizing feedback loop when a window is straddling a DPI transition border.
+ // (Minor: since our sizes do not perfectly linearly scale, deferring the click offset scale until we know the actual window scale ratio may get us slightly more precise mouse positioning.)
+ //if (g.MovingWindow != NULL && g.MovingWindow->Viewport == viewport)
+ // g.ActiveIdClickOffset = ImFloor(g.ActiveIdClickOffset * scale_factor);
+ }
+ viewport->DpiScale = new_dpi_scale;
+ }
-void ImGui::DockContextInitialize(ImGuiContext* ctx)
-{
- ImGuiContext& g = *ctx;
- IM_ASSERT(g.DockContext == NULL);
- g.DockContext = IM_NEW(ImGuiDockContext)();
+ if (!(g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable))
+ {
+ g.MouseViewport = main_viewport;
+ return;
+ }
+
+ // Mouse handling: decide on the actual mouse viewport for this frame between the active/focused viewport and the hovered viewport.
+ // Note that 'viewport_hovered' should skip over any viewport that has the ImGuiViewportFlags_NoInputs flags set.
+ ImGuiViewportP* viewport_hovered = NULL;
+ if (g.IO.BackendFlags & ImGuiBackendFlags_HasMouseHoveredViewport)
+ {
+ viewport_hovered = g.IO.MouseHoveredViewport ? (ImGuiViewportP*)FindViewportByID(g.IO.MouseHoveredViewport) : NULL;
+ if (viewport_hovered && (viewport_hovered->Flags & ImGuiViewportFlags_NoInputs))
+ {
+ // Back-end failed at honoring its contract if it returned a viewport with the _NoInputs flag.
+ IM_ASSERT(0);
+ viewport_hovered = FindHoveredViewportFromPlatformWindowStack(g.IO.MousePos);
+ }
+ }
+ else
+ {
+ // If the back-end doesn't know how to honor ImGuiViewportFlags_NoInputs, we do a search ourselves. Note that this search:
+ // A) won't take account of the possibility that non-imgui windows may be in-between our dragged window and our target window.
+ // B) uses LastFrameAsRefViewport as a flawed replacement for the last time a window was focused (we could/should fix that by introducing Focus functions in PlatformIO)
+ viewport_hovered = FindHoveredViewportFromPlatformWindowStack(g.IO.MousePos);
+ }
+ if (viewport_hovered != NULL)
+ g.MouseLastHoveredViewport = viewport_hovered;
+ else if (g.MouseLastHoveredViewport == NULL)
+ g.MouseLastHoveredViewport = g.Viewports[0];
- // Add .ini handle for persistent docking data
- ImGuiSettingsHandler ini_handler;
- ini_handler.TypeName = "Docking";
- ini_handler.TypeHash = ImHashStr("Docking", 0, 0);
- ini_handler.ReadOpenFn = DockSettingsHandler_ReadOpen;
- ini_handler.ReadLineFn = DockSettingsHandler_ReadLine;
- ini_handler.WriteAllFn = DockSettingsHandler_WriteAll;
- g.SettingsHandlers.push_back(ini_handler);
-}
+ // Update mouse reference viewport
+ // (when moving a window we aim at its viewport, but this will be overwritten below if we go in drag and drop mode)
+ if (g.MovingWindow)
+ g.MouseViewport = g.MovingWindow->Viewport;
+ else
+ g.MouseViewport = g.MouseLastHoveredViewport;
-void ImGui::DockContextShutdown(ImGuiContext* ctx)
-{
- ImGuiContext& g = *ctx;
- ImGuiDockContext* dc = ctx->DockContext;
- for (int n = 0; n < dc->Nodes.Data.Size; n++)
- if (ImGuiDockNode* node = (ImGuiDockNode*)dc->Nodes.Data[n].val_p)
- IM_DELETE(node);
- IM_DELETE(g.DockContext);
- g.DockContext = NULL;
-}
+ // When dragging something, always refer to the last hovered viewport.
+ // - when releasing a moving window we will revert to aiming behind (at viewport_hovered)
+ // - when we are between viewports, our dragged preview will tend to show in the last viewport _even_ if we don't have tooltips in their viewports (when lacking monitor info)
+ // - consider the case of holding on a menu item to browse child menus: even thou a mouse button is held, there's no active id because menu items only react on mouse release.
+ const bool is_mouse_dragging_with_an_expected_destination = g.DragDropActive;
+ if (is_mouse_dragging_with_an_expected_destination && viewport_hovered == NULL)
+ viewport_hovered = g.MouseLastHoveredViewport;
+ if (is_mouse_dragging_with_an_expected_destination || g.ActiveId == 0 || !IsAnyMouseDown())
+ if (viewport_hovered != NULL && viewport_hovered != g.MouseViewport && !(viewport_hovered->Flags & ImGuiViewportFlags_NoInputs))
+ g.MouseViewport = viewport_hovered;
-void ImGui::DockContextOnLoadSettings(ImGuiContext* ctx)
-{
- ImGuiDockContext* dc = ctx->DockContext;
- DockContextPruneUnusedSettingsNodes(ctx);
- DockContextBuildNodesFromSettings(ctx, dc->SettingsNodes.Data, dc->SettingsNodes.Size);
+ IM_ASSERT(g.MouseViewport != NULL);
}
-void ImGui::DockContextClearNodes(ImGuiContext* ctx, ImGuiID root_id, bool clear_persistent_docking_references)
+// Update user-facing viewport list (g.Viewports -> g.PlatformIO.Viewports after filtering out some)
+static void ImGui::UpdateViewportsEndFrame()
{
- IM_ASSERT(ctx == GImGui);
- DockBuilderRemoveNodeDockedWindows(root_id, clear_persistent_docking_references);
- DockBuilderRemoveNodeChildNodes(root_id);
+ ImGuiContext& g = *GImGui;
+ g.PlatformIO.MainViewport = g.Viewports[0];
+ g.PlatformIO.Viewports.resize(0);
+ for (int i = 0; i < g.Viewports.Size; i++)
+ {
+ ImGuiViewportP* viewport = g.Viewports[i];
+ viewport->LastPos = viewport->Pos;
+ if (viewport->LastFrameActive < g.FrameCount || viewport->Size.x <= 0.0f || viewport->Size.y <= 0.0f)
+ if (i > 0) // Always include main viewport in the list
+ continue;
+ if (viewport->Window && !IsWindowActiveAndVisible(viewport->Window))
+ continue;
+ if (i > 0)
+ IM_ASSERT(viewport->Window != NULL);
+ g.PlatformIO.Viewports.push_back(viewport);
+ }
+ g.Viewports[0]->ClearRequestFlags(); // Clear main viewport flags because UpdatePlatformWindows() won't do it and may not even be called
}
-// This function also acts as a defacto test to make sure we can rebuild from scratch without a glitch
-void ImGui::DockContextRebuild(ImGuiContext* ctx)
+// FIXME: We should ideally refactor the system to call this every frame (we currently don't)
+ImGuiViewportP* ImGui::AddUpdateViewport(ImGuiWindow* window, ImGuiID id, const ImVec2& pos, const ImVec2& size, ImGuiViewportFlags flags)
{
- //IMGUI_DEBUG_LOG("[docking] full rebuild\n");
- ImGuiDockContext* dc = ctx->DockContext;
- SaveIniSettingsToMemory();
- ImGuiID root_id = 0; // Rebuild all
- DockContextClearNodes(ctx, root_id, false);
- DockContextBuildNodesFromSettings(ctx, dc->SettingsNodes.Data, dc->SettingsNodes.Size);
- DockContextBuildAddWindowsToNodes(ctx, root_id);
-}
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(id != 0);
-// Docking context update function, called by NewFrame()
-void ImGui::DockContextNewFrameUpdateUndocking(ImGuiContext* ctx)
-{
- ImGuiContext& g = *ctx;
- ImGuiDockContext* dc = ctx->DockContext;
- if (!(g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable))
+ if (window != NULL)
{
- if (dc->Nodes.Data.Size > 0 || dc->Requests.Size > 0)
- DockContextClearNodes(ctx, 0, true);
- return;
+ if (g.MovingWindow && g.MovingWindow->RootWindow == window)
+ flags |= ImGuiViewportFlags_NoInputs | ImGuiViewportFlags_NoFocusOnAppearing;
+ if ((window->Flags & ImGuiWindowFlags_NoMouseInputs) && (window->Flags & ImGuiWindowFlags_NoNavInputs))
+ flags |= ImGuiViewportFlags_NoInputs;
+ if (window->Flags & ImGuiWindowFlags_NoFocusOnAppearing)
+ flags |= ImGuiViewportFlags_NoFocusOnAppearing;
}
- // Setting NoSplit at runtime merges all nodes
- if (g.IO.ConfigDockingNoSplit)
- for (int n = 0; n < dc->Nodes.Data.Size; n++)
- if (ImGuiDockNode* node = (ImGuiDockNode*)dc->Nodes.Data[n].val_p)
- if (node->IsRootNode() && node->IsSplitNode())
- {
- DockBuilderRemoveNodeChildNodes(node->ID);
- //dc->WantFullRebuild = true;
- }
-
- // Process full rebuild
-#if 0
- if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_C)))
- dc->WantFullRebuild = true;
-#endif
- if (dc->WantFullRebuild)
+ ImGuiViewportP* viewport = (ImGuiViewportP*)FindViewportByID(id);
+ if (viewport)
{
- DockContextRebuild(ctx);
- dc->WantFullRebuild = false;
+ if (!viewport->PlatformRequestMove)
+ viewport->Pos = pos;
+ if (!viewport->PlatformRequestResize)
+ viewport->Size = size;
+ viewport->Flags = flags | (viewport->Flags & ImGuiViewportFlags_Minimized); // Preserve existing flags
}
-
- // Process Undocking requests (we need to process them _before_ the UpdateMouseMovingWindowNewFrame call in NewFrame)
- for (int n = 0; n < dc->Requests.Size; n++)
+ else
{
- ImGuiDockRequest* req = &dc->Requests[n];
- if (req->Type == ImGuiDockRequestType_Undock && req->UndockTargetWindow)
- DockContextProcessUndockWindow(ctx, req->UndockTargetWindow);
- else if (req->Type == ImGuiDockRequestType_Undock && req->UndockTargetNode)
- DockContextProcessUndockNode(ctx, req->UndockTargetNode);
- }
-}
+ // New viewport
+ viewport = IM_NEW(ImGuiViewportP)();
+ viewport->ID = id;
+ viewport->Idx = g.Viewports.Size;
+ viewport->Pos = viewport->LastPos = pos;
+ viewport->Size = size;
+ viewport->Flags = flags;
+ UpdateViewportPlatformMonitor(viewport);
+ g.Viewports.push_back(viewport);
+ IMGUI_DEBUG_LOG_VIEWPORT("Add Viewport %08X (%s)\n", id, window->Name);
-// Docking context update function, called by NewFrame()
-void ImGui::DockContextNewFrameUpdateDocking(ImGuiContext* ctx)
-{
- ImGuiContext& g = *ctx;
- ImGuiDockContext* dc = ctx->DockContext;
- if (!(g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable))
- return;
+ // We normally setup for all viewports in NewFrame() but here need to handle the mid-frame creation of a new viewport.
+ // We need to extend the fullscreen clip rect so the OverlayDrawList clip is correct for that the first frame
+ g.DrawListSharedData.ClipRectFullscreen.x = ImMin(g.DrawListSharedData.ClipRectFullscreen.x, viewport->Pos.x);
+ g.DrawListSharedData.ClipRectFullscreen.y = ImMin(g.DrawListSharedData.ClipRectFullscreen.y, viewport->Pos.y);
+ g.DrawListSharedData.ClipRectFullscreen.z = ImMax(g.DrawListSharedData.ClipRectFullscreen.z, viewport->Pos.x + viewport->Size.x);
+ g.DrawListSharedData.ClipRectFullscreen.w = ImMax(g.DrawListSharedData.ClipRectFullscreen.w, viewport->Pos.y + viewport->Size.y);
- // Process Docking requests
- for (int n = 0; n < dc->Requests.Size; n++)
- if (dc->Requests[n].Type == ImGuiDockRequestType_Dock)
- DockContextProcessDock(ctx, &dc->Requests[n]);
- dc->Requests.resize(0);
+ // Store initial DpiScale before the OS platform window creation, based on expected monitor data.
+ // This is so we can select an appropriate font size on the first frame of our window lifetime
+ if (viewport->PlatformMonitor != -1)
+ viewport->DpiScale = g.PlatformIO.Monitors[viewport->PlatformMonitor].DpiScale;
+ }
- // Create windows for each automatic docking nodes
- // We can have NULL pointers when we delete nodes, but because ID are recycled this should amortize nicely (and our node count will never be very high)
- for (int n = 0; n < dc->Nodes.Data.Size; n++)
- if (ImGuiDockNode* node = (ImGuiDockNode*)dc->Nodes.Data[n].val_p)
- if (node->IsRootNode() && !node->IsDockSpace())
- DockNodeUpdate(node);
-}
+ viewport->Window = window;
+ viewport->LastFrameActive = g.FrameCount;
+ IM_ASSERT(window == NULL || viewport->ID == window->ID);
-static ImGuiDockNode* ImGui::DockContextFindNodeByID(ImGuiContext* ctx, ImGuiID id)
-{
- return (ImGuiDockNode*)ctx->DockContext->Nodes.GetVoidPtr(id);
-}
+ if (window != NULL)
+ window->ViewportOwned = true;
-static ImGuiID ImGui::DockContextGenNodeID(ImGuiContext* ctx)
-{
- // Generate an ID for new node (the exact ID value doesn't matter as long as it is not already used)
- // FIXME-OPT FIXME-DOCKING: This is suboptimal, even if the node count is small enough not to be a worry. We should poke in ctx->Nodes to find a suitable ID faster.
- ImGuiID id = 0x0001;
- while (DockContextFindNodeByID(ctx, id) != NULL)
- id++;
- return id;
+ return viewport;
}
-static ImGuiDockNode* ImGui::DockContextAddNode(ImGuiContext* ctx, ImGuiID id)
+// FIXME-VIEWPORT: This is all super messy and ought to be clarified or rewritten.
+static void ImGui::UpdateSelectWindowViewport(ImGuiWindow* window)
{
- // Generate an ID for the new node (the exact ID value doesn't matter as long as it is not already used) and add the first window.
- if (id == 0)
- id = DockContextGenNodeID(ctx);
- else
- IM_ASSERT(DockContextFindNodeByID(ctx, id) == NULL);
- ImGuiDockNode* node = IM_NEW(ImGuiDockNode)(id);
- ctx->DockContext->Nodes.SetVoidPtr(node->ID, node);
- return node;
-}
+ ImGuiContext& g = *GImGui;
+ ImGuiWindowFlags flags = window->Flags;
+ window->ViewportAllowPlatformMonitorExtend = -1;
-static void ImGui::DockContextRemoveNode(ImGuiContext* ctx, ImGuiDockNode* node, bool merge_sibling_into_parent_node)
-{
- ImGuiContext& g = *ctx;
- ImGuiDockContext* dc = ctx->DockContext;
+ // Restore main viewport if multi-viewport is not supported by the back-end
+ ImGuiViewportP* main_viewport = g.Viewports[0];
+ if (!(g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable))
+ {
+ SetWindowViewport(window, main_viewport);
+ return;
+ }
+ window->ViewportOwned = false;
- //printf("[%05d] RemoveNode 0x%04X\n", node->ID);
- IM_ASSERT(DockContextFindNodeByID(ctx, node->ID) == node);
- IM_ASSERT(node->ChildNodes[0] == NULL && node->ChildNodes[1] == NULL);
- IM_ASSERT(node->Windows.Size == 0);
+ // Appearing popups reset their viewport so they can inherit again
+ if ((flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_Tooltip)) && window->Appearing)
+ {
+ window->Viewport = NULL;
+ window->ViewportId = 0;
+ }
- if (node->HostWindow)
- node->HostWindow->DockNodeAsHost = NULL;
+ if ((g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasViewport) == 0)
+ {
+ // By default inherit from parent window
+ if (window->Viewport == NULL && window->ParentWindow && !window->ParentWindow->IsFallbackWindow)
+ window->Viewport = window->ParentWindow->Viewport;
- ImGuiDockNode* parent_node = node->ParentNode;
- const bool merge = (merge_sibling_into_parent_node && parent_node != NULL);
- if (merge)
+ // Attempt to restore saved viewport id (= window that hasn't been activated yet), try to restore the viewport based on saved 'window->ViewportPos' restored from .ini file
+ if (window->Viewport == NULL && window->ViewportId != 0)
+ {
+ window->Viewport = (ImGuiViewportP*)FindViewportByID(window->ViewportId);
+ if (window->Viewport == NULL && window->ViewportPos.x != FLT_MAX && window->ViewportPos.y != FLT_MAX)
+ window->Viewport = AddUpdateViewport(window, window->ID, window->ViewportPos, window->Size, ImGuiViewportFlags_None);
+ }
+ }
+
+ bool lock_viewport = false;
+ if (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasViewport)
{
- IM_ASSERT(parent_node->ChildNodes[0] == node || parent_node->ChildNodes[1] == node);
- ImGuiDockNode* sibling_node = (parent_node->ChildNodes[0] == node ? parent_node->ChildNodes[1] : parent_node->ChildNodes[0]);
- DockNodeTreeMerge(&g, parent_node, sibling_node);
+ // Code explicitly request a viewport
+ window->Viewport = (ImGuiViewportP*)FindViewportByID(g.NextWindowData.ViewportId);
+ window->ViewportId = g.NextWindowData.ViewportId; // Store ID even if Viewport isn't resolved yet.
+ lock_viewport = true;
+ }
+ else if ((flags & ImGuiWindowFlags_ChildWindow) || (flags & ImGuiWindowFlags_ChildMenu))
+ {
+ // Always inherit viewport from parent window
+ window->Viewport = window->ParentWindow->Viewport;
+ }
+ else if (flags & ImGuiWindowFlags_Tooltip)
+ {
+ window->Viewport = g.MouseViewport;
+ }
+ else if (GetWindowAlwaysWantOwnViewport(window))
+ {
+ window->Viewport = AddUpdateViewport(window, window->ID, window->Pos, window->Size, ImGuiViewportFlags_None);
+ }
+ else if (g.MovingWindow && g.MovingWindow->RootWindow == window && IsMousePosValid())
+ {
+ if (window->Viewport != NULL && window->Viewport->Window == window)
+ window->Viewport = AddUpdateViewport(window, window->ID, window->Pos, window->Size, ImGuiViewportFlags_None);
}
else
{
- for (int n = 0; parent_node && n < IM_ARRAYSIZE(parent_node->ChildNodes); n++)
- if (parent_node->ChildNodes[n] == node)
- node->ParentNode->ChildNodes[n] = NULL;
- dc->Nodes.SetVoidPtr(node->ID, NULL);
- IM_DELETE(node);
+ // Merge into host viewport?
+ // We cannot test window->ViewportOwned as it set lower in the function.
+ bool try_to_merge_into_host_viewport = (window->Viewport && window == window->Viewport->Window && g.ActiveId == 0);
+ if (try_to_merge_into_host_viewport)
+ UpdateTryMergeWindowIntoHostViewports(window);
}
-}
-static int IMGUI_CDECL DockNodeComparerDepthMostFirst(const void* lhs, const void* rhs)
-{
- const ImGuiDockNode* a = *(const ImGuiDockNode* const*)lhs;
- const ImGuiDockNode* b = *(const ImGuiDockNode* const*)rhs;
- return ImGui::DockNodeGetDepth(b) - ImGui::DockNodeGetDepth(a);
+ // Fallback to default viewport
+ if (window->Viewport == NULL)
+ window->Viewport = main_viewport;
+
+ // Mark window as allowed to protrude outside of its viewport and into the current monitor
+ if (!lock_viewport)
+ {
+ if (flags & (ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_Popup))
+ {
+ // We need to take account of the possibility that mouse may become invalid.
+ // Popups/Tooltip always set ViewportAllowPlatformMonitorExtend so GetWindowAllowedExtentRect() will return full monitor bounds.
+ ImVec2 mouse_ref = (flags & ImGuiWindowFlags_Tooltip) ? g.IO.MousePos : g.BeginPopupStack.back().OpenMousePos;
+ bool use_mouse_ref = (g.NavDisableHighlight || !g.NavDisableMouseHover || !g.NavWindow);
+ bool mouse_valid = IsMousePosValid(&mouse_ref);
+ if ((window->Appearing || (flags & ImGuiWindowFlags_Tooltip)) && (!use_mouse_ref || mouse_valid))
+ window->ViewportAllowPlatformMonitorExtend = FindPlatformMonitorForPos((use_mouse_ref && mouse_valid) ? mouse_ref : NavCalcPreferredRefPos());
+ else
+ window->ViewportAllowPlatformMonitorExtend = window->Viewport->PlatformMonitor;
+ }
+ else if (window->Viewport && window != window->Viewport->Window && window->Viewport->Window && !(flags & ImGuiWindowFlags_ChildWindow))
+ {
+ // When called from Begin() we don't have access to a proper version of the Hidden flag yet, so we replicate this code.
+ const bool will_be_visible = (window->DockIsActive && !window->DockTabIsVisible) ? false : true;
+ if ((window->Flags & ImGuiWindowFlags_DockNodeHost) && window->Viewport->LastFrameActive < g.FrameCount && will_be_visible)
+ {
+ // Steal/transfer ownership
+ IMGUI_DEBUG_LOG_VIEWPORT("Window '%s' steal Viewport %08X from Window '%s'\n", window->Name, window->Viewport->ID, window->Viewport->Window->Name);
+ window->Viewport->Window = window;
+ window->Viewport->ID = window->ID;
+ window->Viewport->LastNameHash = 0;
+ }
+ else if (!UpdateTryMergeWindowIntoHostViewports(window)) // Merge?
+ {
+ // New viewport
+ window->Viewport = AddUpdateViewport(window, window->ID, window->Pos, window->Size, ImGuiViewportFlags_NoFocusOnAppearing);
+ }
+ }
+ else if (window->ViewportAllowPlatformMonitorExtend < 0 && (flags & ImGuiWindowFlags_ChildWindow) == 0)
+ {
+ // Regular (non-child, non-popup) windows by default are also allowed to protrude
+ // Child windows are kept contained within their parent.
+ window->ViewportAllowPlatformMonitorExtend = window->Viewport->PlatformMonitor;
+ }
+ }
+
+ // Update flags
+ window->ViewportOwned = (window == window->Viewport->Window);
+ window->ViewportId = window->Viewport->ID;
+
+ // If the OS window has a title bar, hide our imgui title bar
+ //if (window->ViewportOwned && !(window->Viewport->Flags & ImGuiViewportFlags_NoDecoration))
+ // window->Flags |= ImGuiWindowFlags_NoTitleBar;
}
-// Pre C++0x doesn't allow us to use a function-local type (without linkage) as template parameter, so we moved this here.
-struct ImGuiDockContextPruneNodeData
+// Called by user at the end of the main loop, after EndFrame()
+// This will handle the creation/update of all OS windows via function defined in the ImGuiPlatformIO api.
+void ImGui::UpdatePlatformWindows()
{
- int CountWindows, CountChildWindows, CountChildNodes;
- ImGuiID RootID;
- ImGuiDockContextPruneNodeData() { CountWindows = CountChildWindows = CountChildNodes = 0; RootID = 0; }
-};
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(g.FrameCountEnded == g.FrameCount && "Forgot to call Render() or EndFrame() before UpdatePlatformWindows()?");
+ IM_ASSERT(g.FrameCountPlatformEnded < g.FrameCount);
+ g.FrameCountPlatformEnded = g.FrameCount;
+ if (!(g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable))
+ return;
-// Garbage collect unused nodes (run once at init time)
-static void ImGui::DockContextPruneUnusedSettingsNodes(ImGuiContext* ctx)
-{
- ImGuiContext& g = *ctx;
- ImGuiDockContext* dc = ctx->DockContext;
- IM_ASSERT(g.Windows.Size == 0);
+ // Create/resize/destroy platform windows to match each active viewport.
+ // Skip the main viewport (index 0), which is always fully handled by the application!
+ for (int i = 1; i < g.Viewports.Size; i++)
+ {
+ ImGuiViewportP* viewport = g.Viewports[i];
- ImPool pool;
- pool.Reserve(dc->SettingsNodes.Size);
+ // Destroy platform window if the viewport hasn't been submitted or if it is hosting a hidden window
+ // (the implicit/fallback Debug##Default window will be registering its viewport then be disabled, causing a dummy DestroyPlatformWindow to be made each frame)
+ bool destroy_platform_window = false;
+ destroy_platform_window |= (viewport->LastFrameActive < g.FrameCount - 1);
+ destroy_platform_window |= (viewport->Window && !IsWindowActiveAndVisible(viewport->Window));
+ if (destroy_platform_window)
+ {
+ DestroyPlatformWindow(viewport);
+ continue;
+ }
- // Count child nodes and compute RootID
- for (int settings_n = 0; settings_n < dc->SettingsNodes.Size; settings_n++)
- {
- ImGuiDockNodeSettings* settings = &dc->SettingsNodes[settings_n];
- ImGuiDockContextPruneNodeData* parent_data = settings->ParentID ? pool.GetByKey(settings->ParentID) : 0;
- pool.GetOrAddByKey(settings->ID)->RootID = parent_data ? parent_data->RootID : settings->ID;
- if (settings->ParentID)
- pool.GetOrAddByKey(settings->ParentID)->CountChildNodes++;
- }
+ // New windows that appears directly in a new viewport won't always have a size on their first frame
+ if (viewport->LastFrameActive < g.FrameCount || viewport->Size.x <= 0 || viewport->Size.y <= 0)
+ continue;
- // Count reference to dock ids from window settings
- for (int settings_n = 0; settings_n < g.SettingsWindows.Size; settings_n++)
- if (ImGuiID dock_id = g.SettingsWindows[settings_n].DockId)
- if (ImGuiDockContextPruneNodeData* data = pool.GetByKey(dock_id))
+ // Create window
+ bool is_new_platform_window = (viewport->PlatformWindowCreated == false);
+ if (is_new_platform_window)
+ {
+ IMGUI_DEBUG_LOG_VIEWPORT("Create Platform Window %08X (%s)\n", viewport->ID, viewport->Window ? viewport->Window->Name : "n/a");
+ g.PlatformIO.Platform_CreateWindow(viewport);
+ if (g.PlatformIO.Renderer_CreateWindow != NULL)
+ g.PlatformIO.Renderer_CreateWindow(viewport);
+ viewport->LastNameHash = 0;
+ viewport->LastPlatformPos = viewport->LastPlatformSize = ImVec2(FLT_MAX, FLT_MAX); // By clearing those we'll enforce a call to Platform_SetWindowPos/Size below, before Platform_ShowWindow (FIXME: Is that necessary?)
+ viewport->LastRendererSize = viewport->Size; // We don't need to call Renderer_SetWindowSize() as it is expected Renderer_CreateWindow() already did it.
+ viewport->PlatformWindowCreated = true;
+ }
+
+ // Apply Position and Size (from ImGui to Platform/Renderer back-ends)
+ if ((viewport->LastPlatformPos.x != viewport->Pos.x || viewport->LastPlatformPos.y != viewport->Pos.y) && !viewport->PlatformRequestMove)
+ g.PlatformIO.Platform_SetWindowPos(viewport, viewport->Pos);
+ if ((viewport->LastPlatformSize.x != viewport->Size.x || viewport->LastPlatformSize.y != viewport->Size.y) && !viewport->PlatformRequestResize)
+ g.PlatformIO.Platform_SetWindowSize(viewport, viewport->Size);
+ if ((viewport->LastRendererSize.x != viewport->Size.x || viewport->LastRendererSize.y != viewport->Size.y) && g.PlatformIO.Renderer_SetWindowSize)
+ g.PlatformIO.Renderer_SetWindowSize(viewport, viewport->Size);
+ viewport->LastPlatformPos = viewport->Pos;
+ viewport->LastPlatformSize = viewport->LastRendererSize = viewport->Size;
+
+ // Update title bar (if it changed)
+ if (ImGuiWindow* window_for_title = GetWindowForTitleDisplay(viewport->Window))
+ {
+ const char* title_begin = window_for_title->Name;
+ char* title_end = (char*)(intptr_t)FindRenderedTextEnd(title_begin);
+ const ImGuiID title_hash = ImHashStr(title_begin, title_end - title_begin);
+ if (viewport->LastNameHash != title_hash)
{
- ImGuiDockContextPruneNodeData* data_root = (data->RootID == dock_id) ? data : pool.GetByKey(data->RootID);
- data->CountWindows++;
- data_root->CountChildWindows++;
+ char title_end_backup_c = *title_end;
+ *title_end = 0; // Cut existing buffer short instead of doing an alloc/free, no small gain.
+ g.PlatformIO.Platform_SetWindowTitle(viewport, title_begin);
+ *title_end = title_end_backup_c;
+ viewport->LastNameHash = title_hash;
}
+ }
- // Prune
- for (int settings_n = 0; settings_n < dc->SettingsNodes.Size; settings_n++)
- {
- ImGuiDockNodeSettings* settings = &dc->SettingsNodes[settings_n];
- ImGuiDockContextPruneNodeData* data = pool.GetByKey(settings->ID);
- if (data->CountWindows > 1)
- continue;
- ImGuiDockContextPruneNodeData* data_root = (data->RootID == settings->ID) ? data : pool.GetByKey(data->RootID);
+ // Update alpha (if it changed)
+ if (viewport->LastAlpha != viewport->Alpha && g.PlatformIO.Platform_SetWindowAlpha)
+ g.PlatformIO.Platform_SetWindowAlpha(viewport, viewport->Alpha);
+ viewport->LastAlpha = viewport->Alpha;
- bool remove = false;
- remove |= (data->CountWindows == 1 && settings->ParentID == 0 && data->CountChildNodes == 0 && !settings->IsCentralNode); // Floating root node with only 1 window
- remove |= (data->CountWindows == 0 && settings->ParentID == 0 && data->CountChildNodes == 0); // Leaf nodes with 0 window
- remove |= (data_root->CountChildWindows == 0);
- if (remove)
+ // Optional, general purpose call to allow the back-end to perform general book-keeping even if things haven't changed.
+ if (g.PlatformIO.Platform_UpdateWindow)
+ g.PlatformIO.Platform_UpdateWindow(viewport);
+
+ if (is_new_platform_window)
{
- DockSettingsRemoveNodeReferences(&settings->ID, 1);
- settings->ID = 0;
+ // On startup ensure new platform window don't steal focus (give it a few frames, as nested contents may lead to viewport being created a few frames late)
+ if (g.FrameCount < 3)
+ viewport->Flags |= ImGuiViewportFlags_NoFocusOnAppearing;
+
+ // Show window
+ g.PlatformIO.Platform_ShowWindow(viewport);
+
+ // Even without focus, we assume the window becomes front-most.
+ // This is useful for our platform z-order heuristic when io.MouseHoveredViewport is not available.
+ if (viewport->LastFrontMostStampCount != g.ViewportFrontMostStampCount)
+ viewport->LastFrontMostStampCount = ++g.ViewportFrontMostStampCount;
+ }
+
+ // Clear request flags
+ viewport->ClearRequestFlags();
+ }
+
+ // Update our implicit z-order knowledge of platform windows, which is used when the back-end cannot provide io.MouseHoveredViewport.
+ // When setting Platform_GetWindowFocus, it is expected that the platform back-end can handle calls without crashing if it doesn't have data stored.
+ if (g.PlatformIO.Platform_GetWindowFocus != NULL)
+ {
+ ImGuiViewportP* focused_viewport = NULL;
+ for (int n = 0; n < g.Viewports.Size && focused_viewport == NULL; n++)
+ {
+ ImGuiViewportP* viewport = g.Viewports[n];
+ if (viewport->PlatformWindowCreated)
+ if (g.PlatformIO.Platform_GetWindowFocus(viewport))
+ focused_viewport = viewport;
+ }
+ if (focused_viewport && g.PlatformLastFocusedViewport != focused_viewport->ID)
+ {
+ if (focused_viewport->LastFrontMostStampCount != g.ViewportFrontMostStampCount)
+ focused_viewport->LastFrontMostStampCount = ++g.ViewportFrontMostStampCount;
+ g.PlatformLastFocusedViewport = focused_viewport->ID;
}
}
}
-static void ImGui::DockContextBuildNodesFromSettings(ImGuiContext* ctx, ImGuiDockNodeSettings* node_settings_array, int node_settings_count)
+// This is a default/basic function for performing the rendering/swap of multiple Platform Windows.
+// Custom renderers may prefer to not call this function at all, and instead iterate the publicly exposed platform data and handle rendering/sync themselves.
+// The Render/Swap functions stored in ImGuiPlatformIO are merely here to allow for this helper to exist, but you can do it yourself:
+//
+// ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
+// for (int i = 1; i < platform_io.Viewports.Size; i++)
+// if ((platform_io.Viewports[i]->Flags & ImGuiViewportFlags_Minimized) == 0)
+// MyRenderFunction(platform_io.Viewports[i], my_args);
+// for (int i = 1; i < platform_io.Viewports.Size; i++)
+// if ((platform_io.Viewports[i]->Flags & ImGuiViewportFlags_Minimized) == 0)
+// MySwapBufferFunction(platform_io.Viewports[i], my_args);
+//
+void ImGui::RenderPlatformWindowsDefault(void* platform_render_arg, void* renderer_render_arg)
{
- // Build nodes
- for (int node_n = 0; node_n < node_settings_count; node_n++)
+ // Skip the main viewport (index 0), which is always fully handled by the application!
+ ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
+ for (int i = 1; i < platform_io.Viewports.Size; i++)
{
- ImGuiDockNodeSettings* settings = &node_settings_array[node_n];
- if (settings->ID == 0)
+ ImGuiViewport* viewport = platform_io.Viewports[i];
+ if (viewport->Flags & ImGuiViewportFlags_Minimized)
continue;
- ImGuiDockNode* node = DockContextAddNode(ctx, settings->ID);
- node->ParentNode = settings->ParentID ? DockContextFindNodeByID(ctx, settings->ParentID) : NULL;
- node->Pos = ImVec2(settings->Pos.x, settings->Pos.y);
- node->Size = ImVec2(settings->Size.x, settings->Size.y);
- node->SizeRef = ImVec2(settings->SizeRef.x, settings->SizeRef.y);
- if (node->ParentNode && node->ParentNode->ChildNodes[0] == NULL)
- node->ParentNode->ChildNodes[0] = node;
- else if (node->ParentNode && node->ParentNode->ChildNodes[1] == NULL)
- node->ParentNode->ChildNodes[1] = node;
- node->SelectedTabID = settings->SelectedTabID;
- node->SplitAxis = settings->SplitAxis;
- if (settings->IsDockSpace)
- node->Flags |= ImGuiDockNodeFlags_Dockspace;
- node->IsCentralNode = settings->IsCentralNode != 0;
- node->IsHiddenTabBar = settings->IsHiddenTabBar != 0;
+ if (platform_io.Platform_RenderWindow) platform_io.Platform_RenderWindow(viewport, platform_render_arg);
+ if (platform_io.Renderer_RenderWindow) platform_io.Renderer_RenderWindow(viewport, renderer_render_arg);
+ }
+ for (int i = 1; i < platform_io.Viewports.Size; i++)
+ {
+ ImGuiViewport* viewport = platform_io.Viewports[i];
+ if (viewport->Flags & ImGuiViewportFlags_Minimized)
+ continue;
+ if (platform_io.Platform_SwapBuffers) platform_io.Platform_SwapBuffers(viewport, platform_render_arg);
+ if (platform_io.Renderer_SwapBuffers) platform_io.Renderer_SwapBuffers(viewport, renderer_render_arg);
+ }
+}
- // Bind host window immediately if it already exist (in case of a rebuild)
- // This is useful as the RootWindowForTitleBarHighlight links necessary to highlight the currently focused node requires node->HostWindow to be set.
- char host_window_title[20];
- ImGuiDockNode* root_node = DockNodeGetRootNode(node);
- node->HostWindow = FindWindowByName(DockNodeGetHostWindowTitle(root_node, host_window_title, IM_ARRAYSIZE(host_window_title)));
+static int ImGui::FindPlatformMonitorForPos(const ImVec2& pos)
+{
+ ImGuiContext& g = *GImGui;
+ for (int monitor_n = 0; monitor_n < g.PlatformIO.Monitors.Size; monitor_n++)
+ {
+ const ImGuiPlatformMonitor& monitor = g.PlatformIO.Monitors[monitor_n];
+ if (ImRect(monitor.MainPos, monitor.MainPos + monitor.MainSize).Contains(pos))
+ return monitor_n;
}
+ return -1;
}
-void ImGui::DockContextBuildAddWindowsToNodes(ImGuiContext* ctx, ImGuiID root_id)
+// Search for the monitor with the largest intersection area with the given rectangle
+// We generally try to avoid searching loops but the monitor count should be very small here
+// FIXME-OPT: We could test the last monitor used for that viewport first, and early
+static int ImGui::FindPlatformMonitorForRect(const ImRect& rect)
{
- // Rebind all windows to nodes (they can also lazily rebind but we'll have a visible glitch during the first frame)
- ImGuiContext& g = *ctx;
- for (int n = 0; n < g.Windows.Size; n++)
+ ImGuiContext& g = *GImGui;
+
+ const int monitor_count = g.PlatformIO.Monitors.Size;
+ if (monitor_count <= 1)
+ return monitor_count - 1;
+
+ // Use a minimum threshold of 1.0f so a zero-sized rect won't false positive, and will still find the correct monitor given its position.
+ // This is necessary for tooltips which always resize down to zero at first.
+ const float surface_threshold = ImMax(rect.GetWidth() * rect.GetHeight() * 0.5f, 1.0f);
+ int best_monitor_n = -1;
+ float best_monitor_surface = 0.001f;
+
+ for (int monitor_n = 0; monitor_n < g.PlatformIO.Monitors.Size && best_monitor_surface < surface_threshold; monitor_n++)
{
- ImGuiWindow* window = g.Windows[n];
- if (window->DockId == 0 || window->LastFrameActive < g.FrameCount - 1)
- continue;
- if (window->DockNode != NULL)
+ const ImGuiPlatformMonitor& monitor = g.PlatformIO.Monitors[monitor_n];
+ const ImRect monitor_rect = ImRect(monitor.MainPos, monitor.MainPos + monitor.MainSize);
+ if (monitor_rect.Contains(rect))
+ return monitor_n;
+ ImRect overlapping_rect = rect;
+ overlapping_rect.ClipWithFull(monitor_rect);
+ float overlapping_surface = overlapping_rect.GetWidth() * overlapping_rect.GetHeight();
+ if (overlapping_surface < best_monitor_surface)
continue;
-
- ImGuiDockNode* node = DockContextFindNodeByID(ctx, window->DockId);
- IM_ASSERT(node != NULL); // This should have been called after DockContextBuildNodesFromSettings()
- if (root_id == 0 || DockNodeGetRootNode(node)->ID == root_id)
- DockNodeAddWindow(node, window, true);
+ best_monitor_surface = overlapping_surface;
+ best_monitor_n = monitor_n;
}
+ return best_monitor_n;
}
-//-----------------------------------------------------------------------------
-// Docking: ImGuiDockContext Docking/Undocking functions
-//-----------------------------------------------------------------------------
-
-void ImGui::DockContextQueueDock(ImGuiContext* ctx, ImGuiWindow* target, ImGuiDockNode* target_node, ImGuiWindow* payload, ImGuiDir split_dir, float split_ratio, bool split_outer)
+// Update monitor from viewport rectangle (we'll use this info to clamp windows and save windows lost in a removed monitor)
+static void ImGui::UpdateViewportPlatformMonitor(ImGuiViewportP* viewport)
{
- IM_ASSERT(target != payload);
- ImGuiDockRequest req;
- req.Type = ImGuiDockRequestType_Dock;
- req.DockTargetWindow = target;
- req.DockTargetNode = target_node;
- req.DockPayload = payload;
- req.DockSplitDir = split_dir;
- req.DockSplitRatio = split_ratio;
- req.DockSplitOuter = split_outer;
- ctx->DockContext->Requests.push_back(req);
+ viewport->PlatformMonitor = (short)FindPlatformMonitorForRect(viewport->GetRect());
}
-void ImGui::DockContextQueueUndockWindow(ImGuiContext* ctx, ImGuiWindow* window)
+void ImGui::DestroyPlatformWindow(ImGuiViewportP* viewport)
{
- ImGuiDockRequest req;
- req.Type = ImGuiDockRequestType_Undock;
- req.UndockTargetWindow = window;
- ctx->DockContext->Requests.push_back(req);
+ ImGuiContext& g = *GImGui;
+ if (viewport->PlatformWindowCreated)
+ {
+ if (g.PlatformIO.Renderer_DestroyWindow)
+ g.PlatformIO.Renderer_DestroyWindow(viewport);
+ if (g.PlatformIO.Platform_DestroyWindow)
+ g.PlatformIO.Platform_DestroyWindow(viewport);
+ IM_ASSERT(viewport->RendererUserData == NULL && viewport->PlatformUserData == NULL);
+ viewport->PlatformWindowCreated = false;
+ }
+ else
+ {
+ IM_ASSERT(viewport->RendererUserData == NULL && viewport->PlatformUserData == NULL && viewport->PlatformHandle == NULL);
+ }
+ viewport->RendererUserData = viewport->PlatformUserData = viewport->PlatformHandle = NULL;
+ viewport->ClearRequestFlags();
}
-void ImGui::DockContextQueueUndockNode(ImGuiContext* ctx, ImGuiDockNode* node)
+void ImGui::DestroyPlatformWindows()
{
- ImGuiDockRequest req;
- req.Type = ImGuiDockRequestType_Undock;
- req.UndockTargetNode = node;
- ctx->DockContext->Requests.push_back(req);
+ // We call the destroy window on every viewport (including the main viewport, index 0) to give a chance to the back-end
+ // to clear any data they may have stored in e.g. PlatformUserData, RendererUserData.
+ // It is convenient for the platform back-end code to store something in the main viewport, in order for e.g. the mouse handling
+ // code to operator a consistent manner.
+ // It is expected that the back-end can handle calls to Renderer_DestroyWindow/Platform_DestroyWindow without
+ // crashing if it doesn't have data stored.
+ ImGuiContext& g = *GImGui;
+ for (int i = 0; i < g.Viewports.Size; i++)
+ DestroyPlatformWindow(g.Viewports[i]);
}
-void ImGui::DockContextQueueNotifyRemovedNode(ImGuiContext* ctx, ImGuiDockNode* node)
-{
- ImGuiDockContext* dc = ctx->DockContext;
- for (int n = 0; n < dc->Requests.Size; n++)
- if (dc->Requests[n].DockTargetNode == node)
- dc->Requests[n].Type = ImGuiDockRequestType_None;
-}
-void ImGui::DockContextProcessDock(ImGuiContext* ctx, ImGuiDockRequest* req)
-{
- IM_ASSERT((req->Type == ImGuiDockRequestType_Dock && req->DockPayload != NULL) || (req->Type == ImGuiDockRequestType_Split && req->DockPayload == NULL));
- IM_ASSERT(req->DockTargetWindow != NULL || req->DockTargetNode != NULL);
+//-----------------------------------------------------------------------------
+// [SECTION] DOCKING
+//-----------------------------------------------------------------------------
+// Docking: Internal Types
+// Docking: Forward Declarations
+// Docking: ImGuiDockContext
+// Docking: ImGuiDockContext Docking/Undocking functions
+// Docking: ImGuiDockNode
+// Docking: ImGuiDockNode Tree manipulation functions
+// Docking: Public Functions (SetWindowDock, DockSpace, DockSpaceOverViewport)
+// Docking: Builder Functions
+// Docking: Begin/End Support Functions (called from Begin/End)
+// Docking: Settings
+//-----------------------------------------------------------------------------
- ImGuiContext& g = *ctx;
- ImGuiWindow* payload_window = req->DockPayload; // Optional
- ImGuiWindow* target_window = req->DockTargetWindow;
- ImGuiDockNode* target_node = req->DockTargetNode;
+//-----------------------------------------------------------------------------
+// Docking: Internal Types
+//-----------------------------------------------------------------------------
+// - ImGuiDockRequestType
+// - ImGuiDockRequest
+// - ImGuiDockPreviewData
+// - ImGuiDockNodeSettings
+// - ImGuiDockContext
+//-----------------------------------------------------------------------------
- // Decide which Tab will be selected at the end of the operation
- ImGuiID next_selected_id = 0;
- ImGuiDockNode* payload_node = NULL;
- if (payload_window)
- {
- payload_node = payload_window->DockNodeAsHost;
- payload_window->DockNodeAsHost = NULL; // Important to clear this as the node will have its life as a child which might be merged/deleted later.
- if (payload_node && payload_node->IsLeafNode())
- next_selected_id = payload_node->TabBar->NextSelectedTabId ? payload_node->TabBar->NextSelectedTabId : payload_node->TabBar->SelectedTabId;
- if (payload_node == NULL)
- next_selected_id = payload_window->ID;
- }
+static float IMGUI_DOCK_SPLITTER_SIZE = 2.0f;
- // FIXME-DOCK: When we are trying to dock an existing single-window node into a loose window, transfer Node ID as well
- if (target_node)
- IM_ASSERT(target_node->LastFrameAlive < g.FrameCount);
- if (target_node && target_window && target_node == target_window->DockNodeAsHost)
- IM_ASSERT(target_node->Windows.Size > 0 || target_node->IsSplitNode() || target_node->IsCentralNode);
+enum ImGuiDockRequestType
+{
+ ImGuiDockRequestType_None = 0,
+ ImGuiDockRequestType_Dock,
+ ImGuiDockRequestType_Undock,
+ ImGuiDockRequestType_Split // Split is the same as Dock but without a DockPayload
+};
- // Create new node and add existing window to it
- if (target_node == NULL)
- {
- target_node = DockContextAddNode(ctx, 0);
- target_node->Pos = target_window->Pos;
- target_node->Size = target_window->Size;
- if (target_window->DockNodeAsHost == NULL)
- {
- DockNodeAddWindow(target_node, target_window, true);
- target_node->TabBar->Tabs[0].Flags &= ~ImGuiTabItemFlags_Unsorted;
- target_window->DockIsActive = true;
- }
- }
+struct ImGuiDockRequest
+{
+ ImGuiDockRequestType Type;
+ ImGuiWindow* DockTargetWindow; // Destination/Target Window to dock into (may be a loose window or a DockNode, might be NULL in which case DockTargetNode cannot be NULL)
+ ImGuiDockNode* DockTargetNode; // Destination/Target Node to dock into
+ ImGuiWindow* DockPayload; // Source/Payload window to dock (may be a loose window or a DockNode), [Optional]
+ ImGuiDir DockSplitDir;
+ float DockSplitRatio;
+ bool DockSplitOuter;
+ ImGuiWindow* UndockTargetWindow;
+ ImGuiDockNode* UndockTargetNode;
- ImGuiDir split_dir = req->DockSplitDir;
- if (split_dir != ImGuiDir_None)
+ ImGuiDockRequest()
{
- // Split into one, one side will be our payload node unless we are dropping a loose window
- const ImGuiAxis split_axis = (split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Right) ? ImGuiAxis_X : ImGuiAxis_Y;
- const int split_inheritor_child_idx = (split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Up) ? 1 : 0; // Current contents will be moved to the opposite side
- const float split_ratio = req->DockSplitRatio;
- DockNodeTreeSplit(ctx, target_node, split_axis, split_inheritor_child_idx, split_ratio, payload_node); // payload_node may be NULL here!
- ImGuiDockNode* new_node = target_node->ChildNodes[split_inheritor_child_idx ^ 1];
- new_node->HostWindow = target_node->HostWindow;
- target_node = new_node;
+ Type = ImGuiDockRequestType_None;
+ DockTargetWindow = DockPayload = UndockTargetWindow = NULL;
+ DockTargetNode = UndockTargetNode = NULL;
+ DockSplitDir = ImGuiDir_None;
+ DockSplitRatio = 0.5f;
+ DockSplitOuter = false;
}
- target_node->IsHiddenTabBar = false;
-
- if (target_node != payload_node)
- {
- // Create tab bar before we call DockNodeMoveWindows (which would attempt to move the old tab-bar, which would lead us to payload tabs wrongly appearing before target tabs!)
- if (target_node->Windows.Size > 0 && target_node->TabBar == NULL)
- {
- target_node->TabBar = IM_NEW(ImGuiTabBar)();
- for (int n = 0; n < target_node->Windows.Size; n++)
- TabBarAddTab(target_node->TabBar, ImGuiTabItemFlags_None, target_node->Windows[n]);
- }
+};
- if (payload_node != NULL)
- {
- // Transfer full payload node (with 1+ child windows or child nodes)
- if (payload_node->IsSplitNode())
- {
- if (target_node->Windows.Size > 0)
- {
- // We can dock into a node that already has windows _only_ if our payload is a node tree with a single visible node.
- // In this situation, we move the windows of the target node into the currently visible node of the payload.
- // This allows us to preserve some of the underlying dock tree settings nicely.
- IM_ASSERT(payload_node->OnlyNodeWithWindows != NULL); // The docking should have been blocked by DockNodePreviewDockCalc() early on and never submitted.
- ImGuiDockNode* visible_node = payload_node->OnlyNodeWithWindows;
- if (visible_node->TabBar)
- IM_ASSERT(visible_node->TabBar->Tabs.Size > 0);
- DockNodeMoveWindows(target_node, visible_node);
- DockNodeMoveWindows(visible_node, target_node);
- DockSettingsRenameNodeReferences(target_node->ID, visible_node->ID);
- }
- if (target_node->IsCentralNode)
- {
- // Central node property needs to be moved to a leaf node, pick the last focused one.
- ImGuiDockNode* last_focused_node = DockContextFindNodeByID(ctx, payload_node->LastFocusedNodeID);
- IM_ASSERT(last_focused_node != NULL && DockNodeGetRootNode(last_focused_node) == DockNodeGetRootNode(payload_node));
- last_focused_node->IsCentralNode = true;
- target_node->IsCentralNode = false;
- }
+struct ImGuiDockPreviewData
+{
+ ImGuiDockNode FutureNode;
+ bool IsDropAllowed;
+ bool IsCenterAvailable;
+ bool IsSidesAvailable; // Hold your breath, grammar freaks..
+ bool IsSplitDirExplicit; // Set when hovered the drop rect (vs. implicit SplitDir==None when hovered the window)
+ ImGuiDockNode* SplitNode;
+ ImGuiDir SplitDir;
+ float SplitRatio;
+ ImRect DropRectsDraw[ImGuiDir_COUNT + 1]; // May be slightly different from hit-testing drop rects used in DockNodeCalcDropRects()
- IM_ASSERT(target_node->Windows.Size == 0);
- DockNodeMoveChildNodes(target_node, payload_node);
- }
- else
- {
- const ImGuiID payload_dock_id = payload_node->ID;
- DockNodeMoveWindows(target_node, payload_node);
- DockSettingsRenameNodeReferences(payload_dock_id, target_node->ID);
- }
- DockContextRemoveNode(ctx, payload_node, true);
- }
- else if (payload_window)
- {
- // Transfer single window
- const ImGuiID payload_dock_id = payload_window->DockId;
- target_node->VisibleWindow = payload_window;
- DockNodeAddWindow(target_node, payload_window, true);
- if (payload_dock_id != 0)
- DockSettingsRenameNodeReferences(payload_dock_id, target_node->ID);
- }
- }
+ ImGuiDockPreviewData() : FutureNode(0) { IsDropAllowed = IsCenterAvailable = IsSidesAvailable = IsSplitDirExplicit = false; SplitNode = NULL; SplitDir = ImGuiDir_None; SplitRatio = 0.f; }
+};
- // Update selection immediately
- if (ImGuiTabBar* tab_bar = target_node->TabBar)
- tab_bar->NextSelectedTabId = next_selected_id;
- MarkIniSettingsDirty();
-}
+// Persistent Settings data, stored contiguously in SettingsNodes (sizeof() ~32 bytes)
+struct ImGuiDockNodeSettings
+{
+ ImGuiID ID;
+ ImGuiID ParentNodeID;
+ ImGuiID ParentWindowID;
+ ImGuiID SelectedWindowID;
+ signed char SplitAxis;
+ char Depth;
+ ImGuiDockNodeFlags Flags; // NB: We save individual flags one by one in ascii format (ImGuiDockNodeFlags_SavedFlagsMask_)
+ ImVec2ih Pos;
+ ImVec2ih Size;
+ ImVec2ih SizeRef;
+ ImGuiDockNodeSettings() { ID = ParentNodeID = ParentWindowID = SelectedWindowID = 0; SplitAxis = ImGuiAxis_None; Depth = 0; Flags = ImGuiDockNodeFlags_None; }
+};
-void ImGui::DockContextProcessUndockWindow(ImGuiContext* ctx, ImGuiWindow* window, bool clear_persistent_docking_ref)
+struct ImGuiDockContext
{
- (void)ctx;
- if (window->DockNode)
- DockNodeRemoveWindow(window->DockNode, window, clear_persistent_docking_ref ? 0 : window->DockId);
- else
- window->DockId = 0;
- window->Collapsed = false;
- window->DockIsActive = false;
- window->DockTabIsVisible = false;
- MarkIniSettingsDirty();
-}
+ ImGuiStorage Nodes; // Map ID -> ImGuiDockNode*: Active nodes
+ ImVector Requests;
+ ImVector SettingsNodes;
+ bool WantFullRebuild;
+ ImGuiDockContext() { WantFullRebuild = false; }
+};
-void ImGui::DockContextProcessUndockNode(ImGuiContext* ctx, ImGuiDockNode* node)
+//-----------------------------------------------------------------------------
+// Docking: Forward Declarations
+//-----------------------------------------------------------------------------
+
+namespace ImGui
{
- IM_ASSERT(node->IsLeafNode());
- IM_ASSERT(node->Windows.Size >= 1);
+ // ImGuiDockContext
+ static ImGuiDockNode* DockContextAddNode(ImGuiContext* ctx, ImGuiID id);
+ static void DockContextRemoveNode(ImGuiContext* ctx, ImGuiDockNode* node, bool merge_sibling_into_parent_node);
+ static void DockContextQueueNotifyRemovedNode(ImGuiContext* ctx, ImGuiDockNode* node);
+ static void DockContextProcessDock(ImGuiContext* ctx, ImGuiDockRequest* req);
+ static void DockContextProcessUndockWindow(ImGuiContext* ctx, ImGuiWindow* window, bool clear_persistent_docking_ref = true);
+ static void DockContextProcessUndockNode(ImGuiContext* ctx, ImGuiDockNode* node);
+ static void DockContextPruneUnusedSettingsNodes(ImGuiContext* ctx);
+ static ImGuiDockNode* DockContextFindNodeByID(ImGuiContext* ctx, ImGuiID id);
+ static ImGuiDockNode* DockContextBindNodeToWindow(ImGuiContext* ctx, ImGuiWindow* window);
+ static void DockContextClearNodes(ImGuiContext* ctx, ImGuiID root_id, bool clear_persistent_docking_refs); // Use root_id==0 to clear all
+ static void DockContextBuildNodesFromSettings(ImGuiContext* ctx, ImGuiDockNodeSettings* node_settings_array, int node_settings_count);
+ static void DockContextBuildAddWindowsToNodes(ImGuiContext* ctx, ImGuiID root_id); // Use root_id==0 to add all
+
+ // ImGuiDockNode
+ static void DockNodeAddWindow(ImGuiDockNode* node, ImGuiWindow* window, bool add_to_tab_bar);
+ static void DockNodeMoveWindows(ImGuiDockNode* dst_node, ImGuiDockNode* src_node);
+ static void DockNodeMoveChildNodes(ImGuiDockNode* dst_node, ImGuiDockNode* src_node);
+ static ImGuiWindow* DockNodeFindWindowByID(ImGuiDockNode* node, ImGuiID id);
+ static void DockNodeApplyPosSizeToWindows(ImGuiDockNode* node);
+ static void DockNodeRemoveWindow(ImGuiDockNode* node, ImGuiWindow* window, ImGuiID save_dock_id);
+ static void DockNodeHideHostWindow(ImGuiDockNode* node);
+ static void DockNodeUpdate(ImGuiDockNode* node);
+ static void DockNodeUpdateVisibleFlagAndInactiveChilds(ImGuiDockNode* node);
+ static void DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_window);
+ static void DockNodeAddTabBar(ImGuiDockNode* node);
+ static void DockNodeRemoveTabBar(ImGuiDockNode* node);
+ static ImGuiID DockNodeUpdateWindowMenu(ImGuiDockNode* node, ImGuiTabBar* tab_bar);
+ static void DockNodeUpdateVisibleFlag(ImGuiDockNode* node);
+ static void DockNodeStartMouseMovingWindow(ImGuiDockNode* node, ImGuiWindow* window);
+ static bool DockNodeIsDropAllowed(ImGuiWindow* host_window, ImGuiWindow* payload_window);
+ static void DockNodePreviewDockCalc(ImGuiWindow* host_window, ImGuiDockNode* host_node, ImGuiWindow* payload_window, ImGuiDockPreviewData* preview_data, bool is_explicit_target, bool is_outer_docking);
+ static void DockNodePreviewDockRender(ImGuiWindow* host_window, ImGuiDockNode* host_node, ImGuiWindow* payload_window, const ImGuiDockPreviewData* preview_data);
+ static void DockNodeCalcTabBarLayout(const ImGuiDockNode* node, ImRect* out_title_rect, ImRect* out_tab_bar_rect, ImVec2* out_window_menu_button_pos);
+ static void DockNodeCalcSplitRects(ImVec2& pos_old, ImVec2& size_old, ImVec2& pos_new, ImVec2& size_new, ImGuiDir dir, ImVec2 size_new_desired);
+ static bool DockNodeCalcDropRectsAndTestMousePos(const ImRect& parent, ImGuiDir dir, ImRect& out_draw, bool outer_docking, ImVec2* test_mouse_pos);
+ static const char* DockNodeGetHostWindowTitle(ImGuiDockNode* node, char* buf, int buf_size) { ImFormatString(buf, buf_size, "##DockNode_%02X", node->ID); return buf; }
+ static int DockNodeGetDepth(const ImGuiDockNode* node) { int depth = 0; while (node->ParentNode) { node = node->ParentNode; depth++; } return depth; }
+ static int DockNodeGetTabOrder(ImGuiWindow* window);
+
+ // ImGuiDockNode tree manipulations
+ static void DockNodeTreeSplit(ImGuiContext* ctx, ImGuiDockNode* parent_node, ImGuiAxis split_axis, int split_first_child, float split_ratio, ImGuiDockNode* new_node);
+ static void DockNodeTreeMerge(ImGuiContext* ctx, ImGuiDockNode* parent_node, ImGuiDockNode* merge_lead_child);
+ static void DockNodeTreeUpdatePosSize(ImGuiDockNode* node, ImVec2 pos, ImVec2 size, bool only_write_to_marked_nodes = false);
+ static void DockNodeTreeUpdateSplitter(ImGuiDockNode* node);
+ static ImGuiDockNode* DockNodeTreeFindNodeByPos(ImGuiDockNode* node, ImVec2 pos);
+ static ImGuiDockNode* DockNodeTreeFindFallbackLeafNode(ImGuiDockNode* node);
- if (node->IsRootNode() || node->IsCentralNode)
- {
- // In the case of a root node or central node, the node will have to stay in place. Create a new node to receive the payload.
- ImGuiDockNode* new_node = DockContextAddNode(ctx, 0);
- DockNodeMoveWindows(new_node, node);
- DockSettingsRenameNodeReferences(node->ID, new_node->ID);
- for (int n = 0; n < new_node->Windows.Size; n++)
- UpdateWindowParentAndRootLinks(new_node->Windows[n], new_node->Windows[n]->Flags, NULL);
- new_node->WantMouseMove = true;
- }
- else
- {
- // Otherwise delete the previous node by merging the other sibling back into the parent node.
- IM_ASSERT(node->ParentNode->ChildNodes[0] == node || node->ParentNode->ChildNodes[1] == node);
- int index_in_parent = (node->ParentNode->ChildNodes[0] == node) ? 0 : 1;
- node->ParentNode->ChildNodes[index_in_parent] = NULL;
- DockNodeTreeMerge(ctx, node->ParentNode, node->ParentNode->ChildNodes[index_in_parent ^ 1]);
- node->ParentNode->AutorityForViewport = ImGuiDataAutority_Window; // The node that stays in place keeps the viewport, so our newly dragged out node will create a new viewport
- node->ParentNode = NULL;
- node->AutorityForPos = node->AutorityForSize = ImGuiDataAutority_Window;
- node->WantMouseMove = true;
- }
- MarkIniSettingsDirty();
+ // Settings
+ static void DockSettingsRenameNodeReferences(ImGuiID old_node_id, ImGuiID new_node_id);
+ static void DockSettingsRemoveNodeReferences(ImGuiID* node_ids, int node_ids_count);
+ static ImGuiDockNodeSettings* DockSettingsFindNodeSettings(ImGuiContext* ctx, ImGuiID node_id);
+ static void* DockSettingsHandler_ReadOpen(ImGuiContext*, ImGuiSettingsHandler*, const char* name);
+ static void DockSettingsHandler_ReadLine(ImGuiContext*, ImGuiSettingsHandler*, void* entry, const char* line);
+ static void DockSettingsHandler_WriteAll(ImGuiContext* imgui_ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* buf);
}
//-----------------------------------------------------------------------------
-// Docking: ImGuiDockNode
+// Docking: ImGuiDockContext
+//-----------------------------------------------------------------------------
+// The lifetime model is different from the one of regular windows: we always create a ImGuiDockNode for each ImGuiDockNodeSettings,
+// or we always hold the entire docking node tree. Nodes are frequently hidden, e.g. if the window(s) or child nodes they host are not active.
+// At boot time only, we run a simple GC to remove nodes that have no references.
+// Because dock node settings (which are small, contiguous structures) are always mirrored by their corresponding dock nodes (more complete structures),
+// we can also very easily recreate the nodes from scratch given the settings data (this is what DockContextRebuild() does).
+// This is convenient as docking reconfiguration can be implemented by mostly poking at the simpler settings data.
+//-----------------------------------------------------------------------------
+// - DockContextInitialize()
+// - DockContextShutdown()
+// - DockContextOnLoadSettings()
+// - DockContextClearNodes()
+// - DockContextRebuildNodes()
+// - DockContextUpdateUndocking()
+// - DockContextUpdateDocking()
+// - DockContextFindNodeByID()
+// - DockContextBindNodeToWindow()
+// - DockContextGenNodeID()
+// - DockContextAddNode()
+// - DockContextRemoveNode()
+// - ImGuiDockContextPruneNodeData
+// - DockContextPruneUnusedSettingsNodes()
+// - DockContextBuildNodesFromSettings()
+// - DockContextBuildAddWindowsToNodes()
//-----------------------------------------------------------------------------
-ImGuiDockNode::ImGuiDockNode(ImGuiID id)
+void ImGui::DockContextInitialize(ImGuiContext* ctx)
{
- ID = id;
- Flags = 0;
- ParentNode = ChildNodes[0] = ChildNodes[1] = NULL;
- TabBar = NULL;
- SplitAxis = ImGuiAxis_None;
+ ImGuiContext& g = *ctx;
+ IM_ASSERT(g.DockContext == NULL);
+ g.DockContext = IM_NEW(ImGuiDockContext)();
- HostWindow = VisibleWindow = NULL;
- CentralNode = OnlyNodeWithWindows = NULL;
- LastFrameAlive = LastFrameActive = LastFrameFocused = -1;
- LastFocusedNodeID = 0;
- SelectedTabID = 0;
- WantCloseTabID = 0;
- AutorityForPos = AutorityForSize = AutorityForViewport = ImGuiDataAutority_Auto;
- IsVisible = true;
- IsFocused = IsCentralNode = IsHiddenTabBar = HasCloseButton = HasCollapseButton = false;
- WantCloseAll = WantLockSizeOnce = WantMouseMove = WantHiddenTabBarUpdate = WantHiddenTabBarToggle = false;
+ // Add .ini handle for persistent docking data
+ ImGuiSettingsHandler ini_handler;
+ ini_handler.TypeName = "Docking";
+ ini_handler.TypeHash = ImHashStr("Docking");
+ ini_handler.ReadOpenFn = DockSettingsHandler_ReadOpen;
+ ini_handler.ReadLineFn = DockSettingsHandler_ReadLine;
+ ini_handler.WriteAllFn = DockSettingsHandler_WriteAll;
+ g.SettingsHandlers.push_back(ini_handler);
}
-ImGuiDockNode::~ImGuiDockNode()
+void ImGui::DockContextShutdown(ImGuiContext* ctx)
{
- IM_DELETE(TabBar);
- TabBar = NULL;
- ChildNodes[0] = ChildNodes[1] = NULL;
+ ImGuiContext& g = *ctx;
+ ImGuiDockContext* dc = ctx->DockContext;
+ for (int n = 0; n < dc->Nodes.Data.Size; n++)
+ if (ImGuiDockNode* node = (ImGuiDockNode*)dc->Nodes.Data[n].val_p)
+ IM_DELETE(node);
+ IM_DELETE(g.DockContext);
+ g.DockContext = NULL;
}
-int ImGui::DockNodeGetTabOrder(ImGuiWindow* window)
+void ImGui::DockContextOnLoadSettings(ImGuiContext* ctx)
{
- ImGuiTabBar* tab_bar = window->DockNode->TabBar;
- if (tab_bar == NULL)
- return -1;
- ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, window->ID);
- return tab ? tab_bar->GetTabOrder(tab) : -1;
+ ImGuiDockContext* dc = ctx->DockContext;
+ DockContextPruneUnusedSettingsNodes(ctx);
+ DockContextBuildNodesFromSettings(ctx, dc->SettingsNodes.Data, dc->SettingsNodes.Size);
}
-static void ImGui::DockNodeAddWindow(ImGuiDockNode* node, ImGuiWindow* window, bool add_to_tab_bar)
+void ImGui::DockContextClearNodes(ImGuiContext* ctx, ImGuiID root_id, bool clear_persistent_docking_references)
{
- ImGuiContext& g = *GImGui; (void)g;
- if (window->DockNode)
- {
- // Can overwrite an existing window->DockNode (e.g. pointing to a disabled DockSpace node)
- IM_ASSERT(window->DockNode->ID != node->ID);
- DockNodeRemoveWindow(window->DockNode, window, 0);
- }
- IM_ASSERT(window->DockNode == NULL || window->DockNodeAsHost == NULL);
+ IM_UNUSED(ctx);
+ IM_ASSERT(ctx == GImGui);
+ DockBuilderRemoveNodeDockedWindows(root_id, clear_persistent_docking_references);
+ DockBuilderRemoveNodeChildNodes(root_id);
+}
- node->Windows.push_back(window);
- node->WantHiddenTabBarUpdate = true;
- window->DockNode = node;
- window->DockId = node->ID;
- window->DockIsActive = (node->Windows.Size > 1);
- window->DockTabWantClose = false;
+// This function also acts as a defacto test to make sure we can rebuild from scratch without a glitch
+void ImGui::DockContextRebuildNodes(ImGuiContext* ctx)
+{
+ IMGUI_DEBUG_LOG_DOCKING("DockContextRebuild()\n");
+ ImGuiDockContext* dc = ctx->DockContext;
+ SaveIniSettingsToMemory();
+ ImGuiID root_id = 0; // Rebuild all
+ DockContextClearNodes(ctx, root_id, false);
+ DockContextBuildNodesFromSettings(ctx, dc->SettingsNodes.Data, dc->SettingsNodes.Size);
+ DockContextBuildAddWindowsToNodes(ctx, root_id);
+}
- // If 2+ windows appeared on the same frame, creating a new DockNode+TabBar from the second window,
- // then we need to hide the first one after the fact otherwise it would be visible as a standalone window for one frame.
- if (node->HostWindow == NULL && node->Windows.Size == 2 && node->Windows[0]->WasActive == false)
+// Docking context update function, called by NewFrame()
+void ImGui::DockContextUpdateUndocking(ImGuiContext* ctx)
+{
+ ImGuiContext& g = *ctx;
+ ImGuiDockContext* dc = ctx->DockContext;
+ if (!(g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable))
{
- node->Windows[0]->Hidden = true;
- node->Windows[0]->HiddenFramesRegular = 1;
+ if (dc->Nodes.Data.Size > 0 || dc->Requests.Size > 0)
+ DockContextClearNodes(ctx, 0, true);
+ return;
}
- // When reactivating a node with one or two loose window, the window pos/size/viewport are authoritative over the node storage.
- // In particular it is important we init the viewport from the first window so we don't create two viewports and drop one.
- if (node->HostWindow == NULL && !node->IsDockSpace() && node->IsRootNode())
+ // Setting NoSplit at runtime merges all nodes
+ if (g.IO.ConfigDockingNoSplit)
+ for (int n = 0; n < dc->Nodes.Data.Size; n++)
+ if (ImGuiDockNode* node = (ImGuiDockNode*)dc->Nodes.Data[n].val_p)
+ if (node->IsRootNode() && node->IsSplitNode())
+ {
+ DockBuilderRemoveNodeChildNodes(node->ID);
+ //dc->WantFullRebuild = true;
+ }
+
+ // Process full rebuild
+#if 0
+ if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_C)))
+ dc->WantFullRebuild = true;
+#endif
+ if (dc->WantFullRebuild)
{
- if (node->AutorityForPos == ImGuiDataAutority_Auto)
- node->AutorityForPos = ImGuiDataAutority_Window;
- if (node->AutorityForSize == ImGuiDataAutority_Auto)
- node->AutorityForSize = ImGuiDataAutority_Window;
- if (node->AutorityForViewport == ImGuiDataAutority_Auto)
- node->AutorityForViewport = ImGuiDataAutority_Window;
+ DockContextRebuildNodes(ctx);
+ dc->WantFullRebuild = false;
}
- // Add to tab bar if requested
- if (add_to_tab_bar)
+ // Process Undocking requests (we need to process them _before_ the UpdateMouseMovingWindowNewFrame call in NewFrame)
+ for (int n = 0; n < dc->Requests.Size; n++)
{
- if (node->TabBar == NULL)
- {
- node->TabBar = IM_NEW(ImGuiTabBar)();
- node->TabBar->SelectedTabId = node->TabBar->NextSelectedTabId = node->SelectedTabID;
-
- // Add existing windows
- for (int n = 0; n < node->Windows.Size - 1; n++)
- TabBarAddTab(node->TabBar, ImGuiTabItemFlags_None, node->Windows[n]);
- }
- TabBarAddTab(node->TabBar, ImGuiTabItemFlags_Unsorted, window);
+ ImGuiDockRequest* req = &dc->Requests[n];
+ if (req->Type == ImGuiDockRequestType_Undock && req->UndockTargetWindow)
+ DockContextProcessUndockWindow(ctx, req->UndockTargetWindow);
+ else if (req->Type == ImGuiDockRequestType_Undock && req->UndockTargetNode)
+ DockContextProcessUndockNode(ctx, req->UndockTargetNode);
}
-
- DockNodeUpdateVisibleFlag(node);
-
- // Update this without waiting for the next time we Begin() in the window, so our host window will have the proper title bar color on its first frame.
- if (node->HostWindow)
- UpdateWindowParentAndRootLinks(window, window->Flags | ImGuiWindowFlags_ChildWindow, node->HostWindow);
}
-static void ImGui::DockNodeRemoveWindow(ImGuiDockNode* node, ImGuiWindow* window, ImGuiID save_dock_id)
+// Docking context update function, called by NewFrame()
+void ImGui::DockContextUpdateDocking(ImGuiContext* ctx)
{
- ImGuiContext& g = *GImGui;
- IM_ASSERT(window->DockNode == node);
- //IM_ASSERT(window->RootWindow == node->HostWindow);
- //IM_ASSERT(window->LastFrameActive < g.FrameCount); // We may call this from Begin()
- IM_ASSERT(save_dock_id == 0 || save_dock_id == node->ID);
-
- window->DockNode = NULL;
- window->DockIsActive = window->DockTabWantClose = false;
- window->DockId = save_dock_id;
- UpdateWindowParentAndRootLinks(window, window->Flags & ~ImGuiWindowFlags_ChildWindow, NULL); // Update immediately
-
- // Remove window
- bool erased = false;
- for (int n = 0; n < node->Windows.Size; n++)
- if (node->Windows[n] == window)
- {
- node->Windows.erase(node->Windows.Data + n);
- erased = true;
- break;
- }
- IM_ASSERT(erased);
- if (node->VisibleWindow == window)
- node->VisibleWindow = NULL;
+ ImGuiContext& g = *ctx;
+ ImGuiDockContext* dc = ctx->DockContext;
+ if (!(g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable))
+ return;
- // Remove tab and possibly tab bar
- node->WantHiddenTabBarUpdate = true;
- if (node->TabBar)
- {
- TabBarRemoveTab(node->TabBar, window->ID);
- const int tab_count_threshold_for_tab_bar = node->IsCentralNode ? 1 : 2;
- if (node->Windows.Size < tab_count_threshold_for_tab_bar)
- {
- IM_DELETE(node->TabBar);
- node->TabBar = NULL;
- }
- }
+ // Process Docking requests
+ for (int n = 0; n < dc->Requests.Size; n++)
+ if (dc->Requests[n].Type == ImGuiDockRequestType_Dock)
+ DockContextProcessDock(ctx, &dc->Requests[n]);
+ dc->Requests.resize(0);
- if (node->Windows.Size == 0 && !node->IsCentralNode && window->DockId != node->ID)
- {
- // Automatic dock node delete themselves if they are not holding at least one tab
- DockContextRemoveNode(&g, node, true);
- return;
- }
+ // Create windows for each automatic docking nodes
+ // We can have NULL pointers when we delete nodes, but because ID are recycled this should amortize nicely (and our node count will never be very high)
+ for (int n = 0; n < dc->Nodes.Data.Size; n++)
+ if (ImGuiDockNode* node = (ImGuiDockNode*)dc->Nodes.Data[n].val_p)
+ if (node->IsFloatingNode())
+ DockNodeUpdate(node);
+}
- if (node->Windows.Size == 1 && !node->IsCentralNode && node->HostWindow)
- {
- ImGuiWindow* remaining_window = node->Windows[0];
- if (node->HostWindow->ViewportOwned && node->IsRootNode())
- {
- // Transfer viewport back to the remaining loose window
- IM_ASSERT(node->HostWindow->Viewport->Window == node->HostWindow);
- node->HostWindow->Viewport->Window = remaining_window;
- node->HostWindow->Viewport->ID = remaining_window->ID;
- }
- remaining_window->Collapsed = node->HostWindow->Collapsed;
- }
+static ImGuiDockNode* ImGui::DockContextFindNodeByID(ImGuiContext* ctx, ImGuiID id)
+{
+ return (ImGuiDockNode*)ctx->DockContext->Nodes.GetVoidPtr(id);
+}
- // Update visibility immediately is required so the DockNodeUpdateRemoveInactiveChilds() processing can reflect changes up the tree
- DockNodeUpdateVisibleFlag(node);
+ImGuiID ImGui::DockContextGenNodeID(ImGuiContext* ctx)
+{
+ // Generate an ID for new node (the exact ID value doesn't matter as long as it is not already used)
+ // FIXME-OPT FIXME-DOCKING: This is suboptimal, even if the node count is small enough not to be a worry. We should poke in ctx->Nodes to find a suitable ID faster.
+ ImGuiID id = 0x0001;
+ while (DockContextFindNodeByID(ctx, id) != NULL)
+ id++;
+ return id;
}
-static void ImGui::DockNodeMoveChildNodes(ImGuiDockNode* dst_node, ImGuiDockNode* src_node)
-{
- IM_ASSERT(dst_node->Windows.Size == 0);
- dst_node->ChildNodes[0] = src_node->ChildNodes[0];
- dst_node->ChildNodes[1] = src_node->ChildNodes[1];
- if (dst_node->ChildNodes[0])
- dst_node->ChildNodes[0]->ParentNode = dst_node;
- if (dst_node->ChildNodes[1])
- dst_node->ChildNodes[1]->ParentNode = dst_node;
- dst_node->SplitAxis = src_node->SplitAxis;
- dst_node->SizeRef = src_node->SizeRef;
- src_node->ChildNodes[0] = src_node->ChildNodes[1] = NULL;
+static ImGuiDockNode* ImGui::DockContextAddNode(ImGuiContext* ctx, ImGuiID id)
+{
+ // Generate an ID for the new node (the exact ID value doesn't matter as long as it is not already used) and add the first window.
+ if (id == 0)
+ id = DockContextGenNodeID(ctx);
+ else
+ IM_ASSERT(DockContextFindNodeByID(ctx, id) == NULL);
+
+ // We don't set node->LastFrameAlive on construction. Nodes are always created at all time to reflect .ini settings!
+ IMGUI_DEBUG_LOG_DOCKING("DockContextAddNode 0x%08X\n", id);
+ ImGuiDockNode* node = IM_NEW(ImGuiDockNode)(id);
+ ctx->DockContext->Nodes.SetVoidPtr(node->ID, node);
+ return node;
}
-static void ImGui::DockNodeMoveWindows(ImGuiDockNode* dst_node, ImGuiDockNode* src_node)
+static void ImGui::DockContextRemoveNode(ImGuiContext* ctx, ImGuiDockNode* node, bool merge_sibling_into_parent_node)
{
- // Insert tabs in the same orders as currently ordered (node->Windows isn't ordered)
- IM_ASSERT(src_node && dst_node && dst_node != src_node);
- ImGuiTabBar* src_tab_bar = src_node->TabBar;
- if (src_tab_bar != NULL)
- IM_ASSERT(src_node->Windows.Size == src_node->TabBar->Tabs.Size);
+ ImGuiContext& g = *ctx;
+ ImGuiDockContext* dc = ctx->DockContext;
- // If the dst_node is empty we can just move the entire tab bar (to preserve selection, scrolling, etc.)
- bool move_tab_bar = (src_tab_bar != NULL) && (dst_node->TabBar == NULL);
- if (move_tab_bar)
- {
- dst_node->TabBar = src_node->TabBar;
- src_node->TabBar = NULL;
- }
+ IMGUI_DEBUG_LOG_DOCKING("DockContextRemoveNode 0x%08X\n", node->ID);
+ IM_ASSERT(DockContextFindNodeByID(ctx, node->ID) == node);
+ IM_ASSERT(node->ChildNodes[0] == NULL && node->ChildNodes[1] == NULL);
+ IM_ASSERT(node->Windows.Size == 0);
- for (int n = 0; n < src_node->Windows.Size; n++)
+ if (node->HostWindow)
+ node->HostWindow->DockNodeAsHost = NULL;
+
+ ImGuiDockNode* parent_node = node->ParentNode;
+ const bool merge = (merge_sibling_into_parent_node && parent_node != NULL);
+ if (merge)
{
- ImGuiWindow* window = src_tab_bar ? src_tab_bar->Tabs[n].Window : src_node->Windows[n];
- window->DockNode = NULL;
- window->DockIsActive = false;
- DockNodeAddWindow(dst_node, window, move_tab_bar ? false : true);
+ IM_ASSERT(parent_node->ChildNodes[0] == node || parent_node->ChildNodes[1] == node);
+ ImGuiDockNode* sibling_node = (parent_node->ChildNodes[0] == node ? parent_node->ChildNodes[1] : parent_node->ChildNodes[0]);
+ DockNodeTreeMerge(&g, parent_node, sibling_node);
}
- src_node->Windows.clear();
-
- if (!move_tab_bar && src_node->TabBar)
+ else
{
- if (dst_node->TabBar)
- dst_node->TabBar->SelectedTabId = src_node->TabBar->SelectedTabId;
- IM_DELETE(src_node->TabBar);
- src_node->TabBar = NULL;
+ for (int n = 0; parent_node && n < IM_ARRAYSIZE(parent_node->ChildNodes); n++)
+ if (parent_node->ChildNodes[n] == node)
+ node->ParentNode->ChildNodes[n] = NULL;
+ dc->Nodes.SetVoidPtr(node->ID, NULL);
+ IM_DELETE(node);
}
}
-static void ImGui::DockNodeApplyPosSizeToWindows(ImGuiDockNode* node)
+static int IMGUI_CDECL DockNodeComparerDepthMostFirst(const void* lhs, const void* rhs)
{
- for (int n = 0; n < node->Windows.Size; n++)
- {
- node->Windows[n]->Pos = node->Pos;
- node->Windows[n]->SizeFull = node->Size;
- }
+ const ImGuiDockNode* a = *(const ImGuiDockNode* const*)lhs;
+ const ImGuiDockNode* b = *(const ImGuiDockNode* const*)rhs;
+ return ImGui::DockNodeGetDepth(b) - ImGui::DockNodeGetDepth(a);
}
-static void ImGui::DockNodeHideHostWindow(ImGuiDockNode* node)
+// Pre C++0x doesn't allow us to use a function-local type (without linkage) as template parameter, so we moved this here.
+struct ImGuiDockContextPruneNodeData
{
- if (node->HostWindow)
+ int CountWindows, CountChildWindows, CountChildNodes;
+ ImGuiID RootID;
+ ImGuiDockContextPruneNodeData() { CountWindows = CountChildWindows = CountChildNodes = 0; RootID = 0; }
+};
+
+// Garbage collect unused nodes (run once at init time)
+static void ImGui::DockContextPruneUnusedSettingsNodes(ImGuiContext* ctx)
+{
+ ImGuiContext& g = *ctx;
+ ImGuiDockContext* dc = ctx->DockContext;
+ IM_ASSERT(g.Windows.Size == 0);
+
+ ImPool pool;
+ pool.Reserve(dc->SettingsNodes.Size);
+
+ // Count child nodes and compute RootID
+ for (int settings_n = 0; settings_n < dc->SettingsNodes.Size; settings_n++)
{
- if (node->HostWindow->DockNodeAsHost == node)
- node->HostWindow->DockNodeAsHost = NULL;
- node->HostWindow = NULL;
+ ImGuiDockNodeSettings* settings = &dc->SettingsNodes[settings_n];
+ ImGuiDockContextPruneNodeData* parent_data = settings->ParentNodeID ? pool.GetByKey(settings->ParentNodeID) : 0;
+ pool.GetOrAddByKey(settings->ID)->RootID = parent_data ? parent_data->RootID : settings->ID;
+ if (settings->ParentNodeID)
+ pool.GetOrAddByKey(settings->ParentNodeID)->CountChildNodes++;
}
- if (node->Windows.Size == 1)
+ // Count reference to dock ids from dockspaces
+ // We track the 'auto-DockNode <- manual-Window <- manual-DockSpace' in order to avoid 'auto-DockNode' being ditched by DockContextPruneUnusedSettingsNodes()
+ for (int settings_n = 0; settings_n < dc->SettingsNodes.Size; settings_n++)
{
- node->VisibleWindow = node->Windows[0];
- node->Windows[0]->DockIsActive = false;
+ ImGuiDockNodeSettings* settings = &dc->SettingsNodes[settings_n];
+ if (settings->ParentWindowID != 0)
+ if (ImGuiWindowSettings* window_settings = FindWindowSettings(settings->ParentWindowID))
+ if (window_settings->DockId)
+ if (ImGuiDockContextPruneNodeData* data = pool.GetByKey(window_settings->DockId))
+ data->CountChildNodes++;
}
- if (node->TabBar)
+ // Count reference to dock ids from window settings
+ // We guard against the possibility of an invalid .ini file (RootID may point to a missing node)
+ for (int settings_n = 0; settings_n < g.SettingsWindows.Size; settings_n++)
+ if (ImGuiID dock_id = g.SettingsWindows[settings_n].DockId)
+ if (ImGuiDockContextPruneNodeData* data = pool.GetByKey(dock_id))
+ {
+ data->CountWindows++;
+ if (ImGuiDockContextPruneNodeData* data_root = (data->RootID == dock_id) ? data : pool.GetByKey(data->RootID))
+ data_root->CountChildWindows++;
+ }
+
+ // Prune
+ for (int settings_n = 0; settings_n < dc->SettingsNodes.Size; settings_n++)
{
- IM_DELETE(node->TabBar);
- node->TabBar = NULL;
+ ImGuiDockNodeSettings* settings = &dc->SettingsNodes[settings_n];
+ ImGuiDockContextPruneNodeData* data = pool.GetByKey(settings->ID);
+ if (data->CountWindows > 1)
+ continue;
+ ImGuiDockContextPruneNodeData* data_root = (data->RootID == settings->ID) ? data : pool.GetByKey(data->RootID);
+
+ bool remove = false;
+ remove |= (data->CountWindows == 1 && settings->ParentNodeID == 0 && data->CountChildNodes == 0 && !(settings->Flags & ImGuiDockNodeFlags_CentralNode)); // Floating root node with only 1 window
+ remove |= (data->CountWindows == 0 && settings->ParentNodeID == 0 && data->CountChildNodes == 0); // Leaf nodes with 0 window
+ remove |= (data_root->CountChildWindows == 0);
+ if (remove)
+ {
+ IMGUI_DEBUG_LOG_DOCKING("DockContextPruneUnusedSettingsNodes: Prune 0x%08X\n", settings->ID);
+ DockSettingsRemoveNodeReferences(&settings->ID, 1);
+ settings->ID = 0;
+ }
}
}
-struct ImGuiDockNodeUpdateScanResults
-{
- ImGuiDockNode* CentralNode;
- ImGuiDockNode* FirstNodeWithWindows;
- int CountNodesWithWindows;
- //ImGuiWindowClass WindowClassForMerges;
-
- ImGuiDockNodeUpdateScanResults() { CentralNode = FirstNodeWithWindows = NULL; CountNodesWithWindows = 0; }
-};
-
-static void DockNodeUpdateScanRec(ImGuiDockNode* node, ImGuiDockNodeUpdateScanResults* results)
+static void ImGui::DockContextBuildNodesFromSettings(ImGuiContext* ctx, ImGuiDockNodeSettings* node_settings_array, int node_settings_count)
{
- if (node->Windows.Size > 0)
- {
- if (results->FirstNodeWithWindows == NULL)
- results->FirstNodeWithWindows = node;
- results->CountNodesWithWindows++;
- }
- if (node->IsCentralNode)
+ // Build nodes
+ for (int node_n = 0; node_n < node_settings_count; node_n++)
{
- IM_ASSERT(results->CentralNode == NULL); // Should be only one
- IM_ASSERT(node->IsLeafNode() && "If you get this assert: please submit .ini file + repro of actions leading to this.");
- results->CentralNode = node;
+ ImGuiDockNodeSettings* settings = &node_settings_array[node_n];
+ if (settings->ID == 0)
+ continue;
+ ImGuiDockNode* node = DockContextAddNode(ctx, settings->ID);
+ node->ParentNode = settings->ParentNodeID ? DockContextFindNodeByID(ctx, settings->ParentNodeID) : NULL;
+ node->Pos = ImVec2(settings->Pos.x, settings->Pos.y);
+ node->Size = ImVec2(settings->Size.x, settings->Size.y);
+ node->SizeRef = ImVec2(settings->SizeRef.x, settings->SizeRef.y);
+ node->AuthorityForPos = node->AuthorityForSize = node->AuthorityForViewport = ImGuiDataAuthority_DockNode;
+ if (node->ParentNode && node->ParentNode->ChildNodes[0] == NULL)
+ node->ParentNode->ChildNodes[0] = node;
+ else if (node->ParentNode && node->ParentNode->ChildNodes[1] == NULL)
+ node->ParentNode->ChildNodes[1] = node;
+ node->SelectedTabID = settings->SelectedWindowID;
+ node->SplitAxis = settings->SplitAxis;
+ node->LocalFlags |= (settings->Flags & ImGuiDockNodeFlags_SavedFlagsMask_);
+
+ // Bind host window immediately if it already exist (in case of a rebuild)
+ // This is useful as the RootWindowForTitleBarHighlight links necessary to highlight the currently focused node requires node->HostWindow to be set.
+ char host_window_title[20];
+ ImGuiDockNode* root_node = DockNodeGetRootNode(node);
+ node->HostWindow = FindWindowByName(DockNodeGetHostWindowTitle(root_node, host_window_title, IM_ARRAYSIZE(host_window_title)));
}
- if (results->CountNodesWithWindows > 1 && results->CentralNode != NULL)
- return;
- if (node->ChildNodes[0])
- DockNodeUpdateScanRec(node->ChildNodes[0], results);
- if (node->ChildNodes[1])
- DockNodeUpdateScanRec(node->ChildNodes[1], results);
}
-// - Remove inactive windows/nodes.
-// - Update visibility flag.
-static void ImGui::DockNodeUpdateVisibleFlagAndInactiveChilds(ImGuiDockNode* node)
+void ImGui::DockContextBuildAddWindowsToNodes(ImGuiContext* ctx, ImGuiID root_id)
{
- ImGuiContext& g = *GImGui;
-
- IM_ASSERT(node->ParentNode == NULL || node->ParentNode->ChildNodes[0] == node || node->ParentNode->ChildNodes[1] == node);
-
- // Inherit most flags
- ImGuiDockNodeFlags flags_to_inherit = ~0 & ~ImGuiDockNodeFlags_Dockspace;
- if (node->ParentNode)
- node->Flags = node->ParentNode->Flags & flags_to_inherit;
-
- // Recurse into children
- // There is the possibility that one of our child becoming empty will delete itself and moving its sibling contents into 'node'.
- // If 'node->ChildNode[0]' delete itself, then 'node->ChildNode[1]->Windows' will be moved into 'node'
- // If 'node->ChildNode[1]' delete itself, then 'node->ChildNode[0]->Windows' will be moved into 'node' and the "remove inactive windows" loop will have run twice on those windows (harmless)
- if (node->ChildNodes[0])
- DockNodeUpdateVisibleFlagAndInactiveChilds(node->ChildNodes[0]);
- if (node->ChildNodes[1])
- DockNodeUpdateVisibleFlagAndInactiveChilds(node->ChildNodes[1]);
-
- // Remove inactive windows
- for (int window_n = 0; window_n < node->Windows.Size; window_n++)
+ // Rebind all windows to nodes (they can also lazily rebind but we'll have a visible glitch during the first frame)
+ ImGuiContext& g = *ctx;
+ for (int n = 0; n < g.Windows.Size; n++)
{
- ImGuiWindow* window = node->Windows[window_n];
- IM_ASSERT(window->DockNode == node);
-
- bool node_was_active = (node->LastFrameActive + 1 == g.FrameCount);
- bool remove = false;
- remove |= node_was_active && (window->LastFrameActive + 1 < g.FrameCount);
- remove |= node_was_active && (node->WantCloseAll || node->WantCloseTabID == window->ID) && window->HasCloseButton && !(window->Flags & ImGuiWindowFlags_UnsavedDocument); // Submit all _expected_ closure from last frame
- remove |= (window->DockTabWantClose);
- if (!remove)
+ ImGuiWindow* window = g.Windows[n];
+ if (window->DockId == 0 || window->LastFrameActive < g.FrameCount - 1)
+ continue;
+ if (window->DockNode != NULL)
continue;
- window->DockTabWantClose = false;
- if (node->Windows.Size == 1 && !node->IsCentralNode)
- {
- DockNodeHideHostWindow(node);
- DockNodeRemoveWindow(node, window, node->ID); // Will delete the node so it'll be invalid on return
- return;
- }
- DockNodeRemoveWindow(node, window, node->ID);
- window_n--;
- }
- // Auto-hide tab bar option
- if (node->WantHiddenTabBarUpdate && node->Windows.Size == 1 && (node->Flags & ImGuiDockNodeFlags_AutoHideTabBar) && !node->IsHiddenTabBar)
- node->WantHiddenTabBarToggle = true;
- node->WantHiddenTabBarUpdate = false;
+ ImGuiDockNode* node = DockContextFindNodeByID(ctx, window->DockId);
+ IM_ASSERT(node != NULL); // This should have been called after DockContextBuildNodesFromSettings()
+ if (root_id == 0 || DockNodeGetRootNode(node)->ID == root_id)
+ DockNodeAddWindow(node, window, true);
+ }
+}
- // Apply toggles at a single point of the frame (here!)
- if (node->Windows.Size > 1)
- node->IsHiddenTabBar = false;
- else if (node->WantHiddenTabBarToggle)
- node->IsHiddenTabBar ^= 1;
- node->WantHiddenTabBarToggle = false;
+//-----------------------------------------------------------------------------
+// Docking: ImGuiDockContext Docking/Undocking functions
+//-----------------------------------------------------------------------------
+// - DockContextQueueDock()
+// - DockContextQueueUndockWindow()
+// - DockContextQueueUndockNode()
+// - DockContextQueueNotifyRemovedNode()
+// - DockContextProcessDock()
+// - DockContextProcessUndockWindow()
+// - DockContextProcessUndockNode()
+// - DockContextCalcDropPosForDocking()
+//-----------------------------------------------------------------------------
- DockNodeUpdateVisibleFlag(node);
+void ImGui::DockContextQueueDock(ImGuiContext* ctx, ImGuiWindow* target, ImGuiDockNode* target_node, ImGuiWindow* payload, ImGuiDir split_dir, float split_ratio, bool split_outer)
+{
+ IM_ASSERT(target != payload);
+ ImGuiDockRequest req;
+ req.Type = ImGuiDockRequestType_Dock;
+ req.DockTargetWindow = target;
+ req.DockTargetNode = target_node;
+ req.DockPayload = payload;
+ req.DockSplitDir = split_dir;
+ req.DockSplitRatio = split_ratio;
+ req.DockSplitOuter = split_outer;
+ ctx->DockContext->Requests.push_back(req);
}
-static void ImGui::DockNodeUpdateVisibleFlag(ImGuiDockNode* node)
+void ImGui::DockContextQueueUndockWindow(ImGuiContext* ctx, ImGuiWindow* window)
{
- // Update visibility flag
- bool is_visible = (node->ParentNode == 0) ? node->IsDockSpace() : node->IsCentralNode;
- is_visible |= (node->Windows.Size > 0);
- is_visible |= (node->ChildNodes[0] && node->ChildNodes[0]->IsVisible);
- is_visible |= (node->ChildNodes[1] && node->ChildNodes[1]->IsVisible);
- node->IsVisible = is_visible;
+ ImGuiDockRequest req;
+ req.Type = ImGuiDockRequestType_Undock;
+ req.UndockTargetWindow = window;
+ ctx->DockContext->Requests.push_back(req);
+}
+
+void ImGui::DockContextQueueUndockNode(ImGuiContext* ctx, ImGuiDockNode* node)
+{
+ ImGuiDockRequest req;
+ req.Type = ImGuiDockRequestType_Undock;
+ req.UndockTargetNode = node;
+ ctx->DockContext->Requests.push_back(req);
}
-static void ImGui::DockNodeStartMouseMovingWindow(ImGuiDockNode* node, ImGuiWindow* window)
+void ImGui::DockContextQueueNotifyRemovedNode(ImGuiContext* ctx, ImGuiDockNode* node)
{
- ImGuiContext& g = *GImGui;
- IM_ASSERT(node->WantMouseMove == true);
- ImVec2 backup_active_click_offset = g.ActiveIdClickOffset;
- StartMouseMovingWindow(window);
- g.MovingWindow = window; // If we are docked into a non moveable root window, StartMouseMovingWindow() won't set g.MovingWindow. Override that decision.
- node->WantMouseMove = false;
- g.ActiveIdClickOffset = backup_active_click_offset;
+ ImGuiDockContext* dc = ctx->DockContext;
+ for (int n = 0; n < dc->Requests.Size; n++)
+ if (dc->Requests[n].DockTargetNode == node)
+ dc->Requests[n].Type = ImGuiDockRequestType_None;
}
-static void ImGui::DockNodeUpdate(ImGuiDockNode* node)
+void ImGui::DockContextProcessDock(ImGuiContext* ctx, ImGuiDockRequest* req)
{
- ImGuiContext& g = *GImGui;
- IM_ASSERT(node->LastFrameActive != g.FrameCount);
- node->LastFrameAlive = g.FrameCount;
+ IM_ASSERT((req->Type == ImGuiDockRequestType_Dock && req->DockPayload != NULL) || (req->Type == ImGuiDockRequestType_Split && req->DockPayload == NULL));
+ IM_ASSERT(req->DockTargetWindow != NULL || req->DockTargetNode != NULL);
- node->CentralNode = node->OnlyNodeWithWindows = NULL;
- if (node->IsRootNode())
- {
- DockNodeUpdateVisibleFlagAndInactiveChilds(node);
+ ImGuiContext& g = *ctx;
+ IM_UNUSED(g);
- // FIXME-DOCK: Merge this scan into the one above.
- // - Setup central node pointers
- // - Find if there's only a single visible window in the hierarchy (in which case we need to display a regular title bar -> FIXME-DOCK: that last part is not done yet!)
- ImGuiDockNodeUpdateScanResults results;
- DockNodeUpdateScanRec(node, &results);
- node->CentralNode = results.CentralNode;
- node->OnlyNodeWithWindows = (results.CountNodesWithWindows == 1) ? results.FirstNodeWithWindows : NULL;
- if (node->LastFocusedNodeID == 0 && results.FirstNodeWithWindows != NULL)
- node->LastFocusedNodeID = results.FirstNodeWithWindows->ID;
+ ImGuiWindow* payload_window = req->DockPayload; // Optional
+ ImGuiWindow* target_window = req->DockTargetWindow;
+ ImGuiDockNode* node = req->DockTargetNode;
+ if (payload_window)
+ IMGUI_DEBUG_LOG_DOCKING("DockContextProcessDock node 0x%08X target '%s' dock window '%s', split_dir %d\n", node ? node->ID : 0, target_window ? target_window->Name : "NULL", payload_window ? payload_window->Name : "NULL", req->DockSplitDir);
+ else
+ IMGUI_DEBUG_LOG_DOCKING("DockContextProcessDock node 0x%08X, split_dir %d\n", node ? node->ID : 0, req->DockSplitDir);
- // Copy the window class from of our first window so it can be used for proper dock filtering.
- // When node has mixed windows, prioritize the class with the most constraint (CompatibleWithClassZero = false) as the reference to copy.
- // FIXME-DOCK: We don't recurse properly, this code could be reworked to work from DockNodeUpdateScanRec.
- if (ImGuiDockNode* first_node_with_windows = results.FirstNodeWithWindows)
- {
- node->WindowClass = first_node_with_windows->Windows[0]->WindowClass;
- for (int n = 1; n < first_node_with_windows->Windows.Size; n++)
- if (first_node_with_windows->Windows[n]->WindowClass.DockingAllowUnclassed == false)
- {
- node->WindowClass = first_node_with_windows->Windows[n]->WindowClass;
- break;
- }
- }
+ // Decide which Tab will be selected at the end of the operation
+ ImGuiID next_selected_id = 0;
+ ImGuiDockNode* payload_node = NULL;
+ if (payload_window)
+ {
+ payload_node = payload_window->DockNodeAsHost;
+ payload_window->DockNodeAsHost = NULL; // Important to clear this as the node will have its life as a child which might be merged/deleted later.
+ if (payload_node && payload_node->IsLeafNode())
+ next_selected_id = payload_node->TabBar->NextSelectedTabId ? payload_node->TabBar->NextSelectedTabId : payload_node->TabBar->SelectedTabId;
+ if (payload_node == NULL)
+ next_selected_id = payload_window->ID;
}
- // Early out for hidden root dock nodes (when all DockId references are in inactive windows, or there is only 1 floating window holding on the DockId)
- if (node->Windows.Size <= 1 && node->IsRootNode() && node->IsLeafNode() && !node->IsDockSpace() && !g.IO.ConfigDockingTabBarOnSingleWindows)
+ // FIXME-DOCK: When we are trying to dock an existing single-window node into a loose window, transfer Node ID as well
+ // When processing an interactive split, usually LastFrameAlive will be < g.FrameCount. But DockBuilder operations can make it ==.
+ if (node)
+ IM_ASSERT(node->LastFrameAlive <= g.FrameCount);
+ if (node && target_window && node == target_window->DockNodeAsHost)
+ IM_ASSERT(node->Windows.Size > 0 || node->IsSplitNode() || node->IsCentralNode());
+
+ // Create new node and add existing window to it
+ if (node == NULL)
{
- if (node->Windows.Size == 1)
+ node = DockContextAddNode(ctx, 0);
+ node->Pos = target_window->Pos;
+ node->Size = target_window->Size;
+ if (target_window->DockNodeAsHost == NULL)
{
- // Floating window pos/size is authoritative
- ImGuiWindow* single_window = node->Windows[0];
- node->Pos = single_window->Pos;
- node->Size = single_window->SizeFull;
-
- // Transfer focus immediately so when we revert to a regular window it is immediately selected
- if (node->HostWindow && g.NavWindow == node->HostWindow)
- FocusWindow(single_window);
- if (node->HostWindow)
- {
- single_window->Viewport = node->HostWindow->Viewport;
- single_window->ViewportId = node->HostWindow->ViewportId;
- if (node->HostWindow->ViewportOwned)
- {
- single_window->Viewport->Window = single_window;
- single_window->ViewportOwned = true;
- }
- }
+ DockNodeAddWindow(node, target_window, true);
+ node->TabBar->Tabs[0].Flags &= ~ImGuiTabItemFlags_Unsorted;
+ target_window->DockIsActive = true;
}
-
- DockNodeHideHostWindow(node);
- node->AutorityForPos = node->AutorityForSize = node->AutorityForViewport = ImGuiDataAutority_Auto;
- node->WantCloseAll = false;
- node->WantCloseTabID = 0;
- node->HasCloseButton = node->HasCollapseButton = false;
- node->LastFrameActive = g.FrameCount;
-
- if (node->WantMouseMove && node->Windows.Size == 1)
- DockNodeStartMouseMovingWindow(node, node->Windows[0]);
- return;
}
- ImGuiWindow* host_window = NULL;
- bool beginned_into_host_window = false;
- if (node->IsDockSpace())
+ ImGuiDir split_dir = req->DockSplitDir;
+ if (split_dir != ImGuiDir_None)
{
- // [Explicit root dockspace node]
- IM_ASSERT(node->HostWindow);
- node->HasCloseButton = false;
- node->HasCollapseButton = true;
- host_window = node->HostWindow;
+ // Split into one, one side will be our payload node unless we are dropping a loose window
+ const ImGuiAxis split_axis = (split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Right) ? ImGuiAxis_X : ImGuiAxis_Y;
+ const int split_inheritor_child_idx = (split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Up) ? 1 : 0; // Current contents will be moved to the opposite side
+ const float split_ratio = req->DockSplitRatio;
+ DockNodeTreeSplit(ctx, node, split_axis, split_inheritor_child_idx, split_ratio, payload_node); // payload_node may be NULL here!
+ ImGuiDockNode* new_node = node->ChildNodes[split_inheritor_child_idx ^ 1];
+ new_node->HostWindow = node->HostWindow;
+ node = new_node;
}
- else
+ node->LocalFlags &= ~ImGuiDockNodeFlags_HiddenTabBar;
+
+ if (node != payload_node)
{
- // [Automatic root or child nodes]
- node->HasCloseButton = false;
- node->HasCollapseButton = (node->Windows.Size > 0);
- for (int window_n = 0; window_n < node->Windows.Size; window_n++)
+ // Create tab bar before we call DockNodeMoveWindows (which would attempt to move the old tab-bar, which would lead us to payload tabs wrongly appearing before target tabs!)
+ if (node->Windows.Size > 0 && node->TabBar == NULL)
{
- // FIXME-DOCK: Setting DockIsActive here means that for single active window in a leaf node, DockIsActive will be cleared until the next Begin() call.
- ImGuiWindow* window = node->Windows[window_n];
- window->DockIsActive = (node->Windows.Size > 1);
- node->HasCloseButton |= window->HasCloseButton;
+ DockNodeAddTabBar(node);
+ for (int n = 0; n < node->Windows.Size; n++)
+ TabBarAddTab(node->TabBar, ImGuiTabItemFlags_None, node->Windows[n]);
}
- if (node->IsRootNode() && node->IsVisible)
+ if (payload_node != NULL)
{
- ImGuiWindow* ref_window = (node->Windows.Size > 0) ? node->Windows[0] : NULL;
-
- // Sync Pos
- if (node->AutorityForPos == ImGuiDataAutority_Window && ref_window)
- SetNextWindowPos(ref_window->Pos);
- else if (node->AutorityForPos == ImGuiDataAutority_DockNode)
- SetNextWindowPos(node->Pos);
-
- // Sync Size
- if (node->AutorityForSize == ImGuiDataAutority_Window && ref_window)
- SetNextWindowSize(ref_window->SizeFull);
- else if (node->AutorityForSize == ImGuiDataAutority_DockNode)
- SetNextWindowSize(node->Size);
-
- // Sync Collapsed
- if (node->AutorityForSize == ImGuiDataAutority_Window && ref_window)
- SetNextWindowCollapsed(ref_window->Collapsed);
-
- // Sync Viewport
- if (node->AutorityForViewport == ImGuiDataAutority_Window && ref_window)
- SetNextWindowViewport(ref_window->ViewportId);
-
- SetNextWindowClass(&node->WindowClass);
-
- // Begin into the host window
- char window_label[20];
- DockNodeGetHostWindowTitle(node, window_label, IM_ARRAYSIZE(window_label));
- ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_DockNodeHost;
- window_flags |= ImGuiWindowFlags_NoFocusOnAppearing;
- window_flags |= ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoCollapse;
- window_flags |= ImGuiWindowFlags_NoTitleBar;
-
- PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
- Begin(window_label, NULL, window_flags);
- PopStyleVar();
- beginned_into_host_window = true;
-
- node->HostWindow = host_window = g.CurrentWindow;
- host_window->DockNodeAsHost = node;
- host_window->DC.CursorPos = host_window->Pos;
- node->Pos = host_window->Pos;
- node->Size = host_window->Size;
+ // Transfer full payload node (with 1+ child windows or child nodes)
+ if (payload_node->IsSplitNode())
+ {
+ if (node->Windows.Size > 0)
+ {
+ // We can dock a split payload into a node that already has windows _only_ if our payload is a node tree with a single visible node.
+ // In this situation, we move the windows of the target node into the currently visible node of the payload.
+ // This allows us to preserve some of the underlying dock tree settings nicely.
+ IM_ASSERT(payload_node->OnlyNodeWithWindows != NULL); // The docking should have been blocked by DockNodePreviewDockCalc() early on and never submitted.
+ ImGuiDockNode* visible_node = payload_node->OnlyNodeWithWindows;
+ if (visible_node->TabBar)
+ IM_ASSERT(visible_node->TabBar->Tabs.Size > 0);
+ DockNodeMoveWindows(node, visible_node);
+ DockNodeMoveWindows(visible_node, node);
+ DockSettingsRenameNodeReferences(node->ID, visible_node->ID);
+ }
+ if (node->IsCentralNode())
+ {
+ // Central node property needs to be moved to a leaf node, pick the last focused one.
+ // FIXME-DOCKING: If we had to transfer other flags here, what would the policy be?
+ ImGuiDockNode* last_focused_node = DockContextFindNodeByID(ctx, payload_node->LastFocusedNodeID);
+ IM_ASSERT(last_focused_node != NULL);
+ ImGuiDockNode* last_focused_root_node = DockNodeGetRootNode(last_focused_node);
+ IM_ASSERT(last_focused_root_node == DockNodeGetRootNode(payload_node));
+ last_focused_node->LocalFlags |= ImGuiDockNodeFlags_CentralNode;
+ node->LocalFlags &= ~ImGuiDockNodeFlags_CentralNode;
+ last_focused_root_node->CentralNode = last_focused_node;
+ }
- // We set ImGuiWindowFlags_NoFocusOnAppearing because we don't want the host window to take full focus (e.g. steal NavWindow)
- // But we still it bring it to the front of display. There's no way to choose this precise behavior via window flags.
- // One simple case to ponder if: window A has a toggle to create windows B/C/D. Dock B/C/D together, clear the toggle and enable it again.
- // When reappearing B/C/D will request focus and be moved to the top of the display pile, but they are not linked to the dock host window
- // during the frame they appear. The dock host window would keep its old display order, and the sorting in EndFrame would move B/C/D back
- // after the dock host window, losing their top-most status.
- if (node->HostWindow->Appearing)
- BringWindowToDisplayFront(node->HostWindow);
+ IM_ASSERT(node->Windows.Size == 0);
+ DockNodeMoveChildNodes(node, payload_node);
+ }
+ else
+ {
+ const ImGuiID payload_dock_id = payload_node->ID;
+ DockNodeMoveWindows(node, payload_node);
+ DockSettingsRenameNodeReferences(payload_dock_id, node->ID);
+ }
+ DockContextRemoveNode(ctx, payload_node, true);
}
- else if (node->ParentNode)
+ else if (payload_window)
{
- node->HostWindow = host_window = node->ParentNode->HostWindow;
+ // Transfer single window
+ const ImGuiID payload_dock_id = payload_window->DockId;
+ node->VisibleWindow = payload_window;
+ DockNodeAddWindow(node, payload_window, true);
+ if (payload_dock_id != 0)
+ DockSettingsRenameNodeReferences(payload_dock_id, node->ID);
}
- node->AutorityForPos = node->AutorityForSize = node->AutorityForViewport = ImGuiDataAutority_Auto;
- if (node->WantMouseMove && node->HostWindow)
- DockNodeStartMouseMovingWindow(node, node->HostWindow);
+ }
+ else
+ {
+ // When docking a floating single window node we want to reevaluate auto-hiding of the tab bar
+ node->WantHiddenTabBarUpdate = true;
}
- // Update focused node (the one whose title bar is highlight) within a node tree
- if (node->IsSplitNode())
- IM_ASSERT(node->TabBar == NULL);
- if (node->IsRootNode())
- if (g.NavWindow && g.NavWindow->RootWindowDockStop->DockNode && g.NavWindow->RootWindowDockStop->ParentWindow == host_window)
- node->LastFocusedNodeID = g.NavWindow->RootWindowDockStop->DockNode->ID;
+ // Update selection immediately
+ if (ImGuiTabBar* tab_bar = node->TabBar)
+ tab_bar->NextSelectedTabId = next_selected_id;
+ MarkIniSettingsDirty();
+}
- // We need to draw a background if requested by ImGuiDockNodeFlags_PassthruDockspace, but we will only know the correct pos/size after
- // processing the resizing splitters. So we are using the DrawList channel splitting facility to submit drawing primitives out of order!
- const bool render_dockspace_bg = node->IsRootNode() && host_window && (node->Flags & ImGuiDockNodeFlags_PassthruDockspace) != 0;
- if (render_dockspace_bg)
+void ImGui::DockContextProcessUndockWindow(ImGuiContext* ctx, ImGuiWindow* window, bool clear_persistent_docking_ref)
+{
+ (void)ctx;
+ if (window->DockNode)
+ DockNodeRemoveWindow(window->DockNode, window, clear_persistent_docking_ref ? 0 : window->DockId);
+ else
+ window->DockId = 0;
+ window->Collapsed = false;
+ window->DockIsActive = false;
+ window->DockTabIsVisible = false;
+ MarkIniSettingsDirty();
+}
+
+void ImGui::DockContextProcessUndockNode(ImGuiContext* ctx, ImGuiDockNode* node)
+{
+ IM_ASSERT(node->IsLeafNode());
+ IM_ASSERT(node->Windows.Size >= 1);
+
+ if (node->IsRootNode() || node->IsCentralNode())
{
- host_window->DrawList->ChannelsSplit(2);
- host_window->DrawList->ChannelsSetCurrent(1);
+ // In the case of a root node or central node, the node will have to stay in place. Create a new node to receive the payload.
+ ImGuiDockNode* new_node = DockContextAddNode(ctx, 0);
+ DockNodeMoveWindows(new_node, node);
+ DockSettingsRenameNodeReferences(node->ID, new_node->ID);
+ for (int n = 0; n < new_node->Windows.Size; n++)
+ UpdateWindowParentAndRootLinks(new_node->Windows[n], new_node->Windows[n]->Flags, NULL);
+ new_node->AuthorityForPos = new_node->AuthorityForSize = ImGuiDataAuthority_Window;
+ new_node->WantMouseMove = true;
}
-
- // Register a hit-test hole in the window unless we are currently dragging a window that is compatible with our dockspace
- const ImGuiDockNode* central_node = node->CentralNode;
- const bool central_node_hole = node->IsRootNode() && host_window && (node->Flags & ImGuiDockNodeFlags_PassthruDockspace) != 0 && central_node != NULL && central_node->IsEmpty();
- bool central_node_hole_register_hit_test_hole = central_node_hole;
- if (central_node_hole)
- if (const ImGuiPayload* payload = ImGui::GetDragDropPayload())
- if (payload->IsDataType(IMGUI_PAYLOAD_TYPE_WINDOW) && DockNodeIsDropAllowed(host_window, *(ImGuiWindow**)payload->Data))
- central_node_hole_register_hit_test_hole = false;
- if (central_node_hole_register_hit_test_hole)
+ else
{
- // Add a little padding to match the "resize from edges" behavior and allow grabbing the splitter easily.
- IM_ASSERT(node->IsDockSpace()); // We cannot pass this flag without the DockSpace() api. Testing this because we also setup the hole in host_window->ParentNode
- ImRect central_hole(central_node->Pos, central_node->Pos + central_node->Size);
- central_hole.Expand(ImVec2(-WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS, -WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS));
- if (central_node_hole && !central_hole.IsInverted())
- {
- SetWindowHitTestHole(host_window, central_hole.Min, central_hole.Max - central_hole.Min);
- SetWindowHitTestHole(host_window->ParentWindow, central_hole.Min, central_hole.Max - central_hole.Min);
- }
+ // Otherwise extract our node and merging our sibling back into the parent node.
+ IM_ASSERT(node->ParentNode->ChildNodes[0] == node || node->ParentNode->ChildNodes[1] == node);
+ int index_in_parent = (node->ParentNode->ChildNodes[0] == node) ? 0 : 1;
+ node->ParentNode->ChildNodes[index_in_parent] = NULL;
+ DockNodeTreeMerge(ctx, node->ParentNode, node->ParentNode->ChildNodes[index_in_parent ^ 1]);
+ node->ParentNode->AuthorityForViewport = ImGuiDataAuthority_Window; // The node that stays in place keeps the viewport, so our newly dragged out node will create a new viewport
+ node->ParentNode = NULL;
+ node->AuthorityForPos = node->AuthorityForSize = ImGuiDataAuthority_Window;
+ node->WantMouseMove = true;
}
+ MarkIniSettingsDirty();
+}
- // Update position/size, process and draw resizing splitters
- if (node->IsRootNode() && host_window)
+// This is mostly used for automation.
+bool ImGui::DockContextCalcDropPosForDocking(ImGuiWindow* target, ImGuiDockNode* target_node, ImGuiWindow* payload, ImGuiDir split_dir, bool split_outer, ImVec2* out_pos)
+{
+ if (split_outer)
{
- DockNodeTreeUpdatePosSize(node, host_window->Pos, host_window->Size);
- DockNodeTreeUpdateSplitter(node);
+ IM_ASSERT(0);
+ }
+ else
+ {
+ ImGuiDockPreviewData split_data;
+ DockNodePreviewDockCalc(target, target_node, payload, &split_data, false, split_outer);
+ if (split_data.DropRectsDraw[split_dir+1].IsInverted())
+ return false;
+ *out_pos = split_data.DropRectsDraw[split_dir+1].GetCenter();
+ return true;
}
+ return false;
+}
- // Draw empty node background (currently can only be the Central Node)
- if (host_window && node->IsEmpty() && node->IsVisible && !(node->Flags & ImGuiDockNodeFlags_PassthruDockspace))
- host_window->DrawList->AddRectFilled(node->Pos, node->Pos + node->Size, GetColorU32(ImGuiCol_DockingEmptyBg));
+//-----------------------------------------------------------------------------
+// Docking: ImGuiDockNode
+//-----------------------------------------------------------------------------
+// - DockNodeGetTabOrder()
+// - DockNodeAddWindow()
+// - DockNodeRemoveWindow()
+// - DockNodeMoveChildNodes()
+// - DockNodeMoveWindows()
+// - DockNodeApplyPosSizeToWindows()
+// - DockNodeHideHostWindow()
+// - ImGuiDockNodeFindInfoResults
+// - DockNodeFindInfo()
+// - DockNodeFindWindowByID()
+// - DockNodeUpdateVisibleFlagAndInactiveChilds()
+// - DockNodeUpdateVisibleFlag()
+// - DockNodeStartMouseMovingWindow()
+// - DockNodeUpdate()
+// - DockNodeUpdateWindowMenu()
+// - DockNodeUpdateTabBar()
+// - DockNodeAddTabBar()
+// - DockNodeRemoveTabBar()
+// - DockNodeIsDropAllowedOne()
+// - DockNodeIsDropAllowed()
+// - DockNodeCalcTabBarLayout()
+// - DockNodeCalcSplitRects()
+// - DockNodeCalcDropRectsAndTestMousePos()
+// - DockNodePreviewDockCalc()
+// - DockNodePreviewDockRender()
+//-----------------------------------------------------------------------------
- // Draw whole dockspace background if ImGuiDockNodeFlags_PassthruDockspace if set.
- if (render_dockspace_bg && node->IsVisible)
+ImGuiDockNode::ImGuiDockNode(ImGuiID id)
+{
+ ID = id;
+ SharedFlags = LocalFlags = ImGuiDockNodeFlags_None;
+ ParentNode = ChildNodes[0] = ChildNodes[1] = NULL;
+ TabBar = NULL;
+ SplitAxis = ImGuiAxis_None;
+
+ State = ImGuiDockNodeState_Unknown;
+ HostWindow = VisibleWindow = NULL;
+ CentralNode = OnlyNodeWithWindows = NULL;
+ LastFrameAlive = LastFrameActive = LastFrameFocused = -1;
+ LastFocusedNodeID = 0;
+ SelectedTabID = 0;
+ WantCloseTabID = 0;
+ AuthorityForPos = AuthorityForSize = ImGuiDataAuthority_DockNode;
+ AuthorityForViewport = ImGuiDataAuthority_Auto;
+ IsVisible = true;
+ IsFocused = HasCloseButton = HasWindowMenuButton = EnableCloseButton = false;
+ WantCloseAll = WantLockSizeOnce = WantMouseMove = WantHiddenTabBarUpdate = WantHiddenTabBarToggle = false;
+ MarkedForPosSizeWrite = false;
+}
+
+ImGuiDockNode::~ImGuiDockNode()
+{
+ IM_DELETE(TabBar);
+ TabBar = NULL;
+ ChildNodes[0] = ChildNodes[1] = NULL;
+}
+
+int ImGui::DockNodeGetTabOrder(ImGuiWindow* window)
+{
+ ImGuiTabBar* tab_bar = window->DockNode->TabBar;
+ if (tab_bar == NULL)
+ return -1;
+ ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, window->ID);
+ return tab ? tab_bar->GetTabOrder(tab) : -1;
+}
+
+static void ImGui::DockNodeAddWindow(ImGuiDockNode* node, ImGuiWindow* window, bool add_to_tab_bar)
+{
+ ImGuiContext& g = *GImGui; (void)g;
+ if (window->DockNode)
{
- host_window->DrawList->ChannelsSetCurrent(0);
- if (central_node_hole)
- RenderRectFilledWithHole(host_window->DrawList, node->Rect(), central_node->Rect(), GetColorU32(ImGuiCol_WindowBg), 0.0f);
- else
- host_window->DrawList->AddRectFilled(node->Pos, node->Pos + node->Size, GetColorU32(ImGuiCol_WindowBg), 0.0f);
- host_window->DrawList->ChannelsMerge();
+ // Can overwrite an existing window->DockNode (e.g. pointing to a disabled DockSpace node)
+ IM_ASSERT(window->DockNode->ID != node->ID);
+ DockNodeRemoveWindow(window->DockNode, window, 0);
}
+ IM_ASSERT(window->DockNode == NULL || window->DockNodeAsHost == NULL);
+ IMGUI_DEBUG_LOG_DOCKING("DockNodeAddWindow node 0x%08X window '%s'\n", node->ID, window->Name);
- // Draw and populate Tab Bar
- if (host_window && node->Windows.Size > 0)
+ node->Windows.push_back(window);
+ node->WantHiddenTabBarUpdate = true;
+ window->DockNode = node;
+ window->DockId = node->ID;
+ window->DockIsActive = (node->Windows.Size > 1);
+ window->DockTabWantClose = false;
+
+ // If more than 2 windows appeared on the same frame, we'll create a new hosting DockNode from the point of the second window submission.
+ // Then we need to hide the first window (after its been output) otherwise it would be visible as a standalone window for one frame.
+ if (node->HostWindow == NULL && node->Windows.Size == 2 && node->Windows[0]->WasActive == false)
{
- DockNodeUpdateTabBar(node, host_window);
- if (node->TabBar->SelectedTabId)
- node->SelectedTabID = node->TabBar->SelectedTabId;
+ node->Windows[0]->Hidden = true;
+ node->Windows[0]->HiddenFramesCanSkipItems = 1;
}
- else
+
+ // When reactivating a node with one or two loose window, the window pos/size/viewport are authoritative over the node storage.
+ // In particular it is important we init the viewport from the first window so we don't create two viewports and drop one.
+ if (node->HostWindow == NULL && node->IsFloatingNode())
{
- node->WantCloseAll = false;
- node->WantCloseTabID = 0;
- node->IsFocused = false;
- if (node->Windows.Size > 0)
- node->SelectedTabID = node->Windows[0]->ID;
+ if (node->AuthorityForPos == ImGuiDataAuthority_Auto)
+ node->AuthorityForPos = ImGuiDataAuthority_Window;
+ if (node->AuthorityForSize == ImGuiDataAuthority_Auto)
+ node->AuthorityForSize = ImGuiDataAuthority_Window;
+ if (node->AuthorityForViewport == ImGuiDataAuthority_Auto)
+ node->AuthorityForViewport = ImGuiDataAuthority_Window;
}
- // Draw payload drop target
- if (host_window && node->IsVisible)
- if (node->IsRootNode() && (g.MovingWindow == NULL || g.MovingWindow->RootWindow != host_window))
- BeginAsDockableDragDropTarget(host_window);
-
- node->LastFrameActive = g.FrameCount;
-
- // Recurse into children
- if (host_window)
+ // Add to tab bar if requested
+ if (add_to_tab_bar)
{
- if (node->ChildNodes[0])
- DockNodeUpdate(node->ChildNodes[0]);
- if (node->ChildNodes[1])
- DockNodeUpdate(node->ChildNodes[1]);
-
- // End host window
- if (beginned_into_host_window)
- End();
+ if (node->TabBar == NULL)
+ {
+ DockNodeAddTabBar(node);
+ node->TabBar->SelectedTabId = node->TabBar->NextSelectedTabId = node->SelectedTabID;
+
+ // Add existing windows
+ for (int n = 0; n < node->Windows.Size - 1; n++)
+ TabBarAddTab(node->TabBar, ImGuiTabItemFlags_None, node->Windows[n]);
+ }
+ TabBarAddTab(node->TabBar, ImGuiTabItemFlags_Unsorted, window);
}
- // Render outer borders last (after the tab bar)
- if (node->IsRootNode() && host_window)
- RenderOuterBorders(host_window);
-}
+ DockNodeUpdateVisibleFlag(node);
-// Compare TabItem nodes given the last known DockOrder (will persist in .ini file as hint), used to sort tabs when multiple tabs are added on the same frame.
-static int IMGUI_CDECL TabItemComparerByDockOrder(const void* lhs, const void* rhs)
-{
- ImGuiWindow* a = ((const ImGuiTabItem*)lhs)->Window;
- ImGuiWindow* b = ((const ImGuiTabItem*)rhs)->Window;
- if (int d = ((a->DockOrder == -1) ? INT_MAX : a->DockOrder) - ((b->DockOrder == -1) ? INT_MAX : b->DockOrder))
- return d;
- return (a->BeginOrderWithinContext - b->BeginOrderWithinContext);
+ // Update this without waiting for the next time we Begin() in the window, so our host window will have the proper title bar color on its first frame.
+ if (node->HostWindow)
+ UpdateWindowParentAndRootLinks(window, window->Flags | ImGuiWindowFlags_ChildWindow, node->HostWindow);
}
-static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_window)
+static void ImGui::DockNodeRemoveWindow(ImGuiDockNode* node, ImGuiWindow* window, ImGuiID save_dock_id)
{
ImGuiContext& g = *GImGui;
- ImGuiStyle& style = g.Style;
+ IM_ASSERT(window->DockNode == node);
+ //IM_ASSERT(window->RootWindow == node->HostWindow);
+ //IM_ASSERT(window->LastFrameActive < g.FrameCount); // We may call this from Begin()
+ IM_ASSERT(save_dock_id == 0 || save_dock_id == node->ID);
+ IMGUI_DEBUG_LOG_DOCKING("DockNodeRemoveWindow node 0x%08X window '%s'\n", node->ID, window->Name);
- const bool node_was_active = (node->LastFrameActive + 1 == g.FrameCount);
- const bool closed_all = node->WantCloseAll && node_was_active;
- const ImGuiID closed_one = node->WantCloseTabID && node_was_active;
- node->WantCloseAll = false;
- node->WantCloseTabID = 0;
+ window->DockNode = NULL;
+ window->DockIsActive = window->DockTabWantClose = false;
+ window->DockId = save_dock_id;
+ UpdateWindowParentAndRootLinks(window, window->Flags & ~ImGuiWindowFlags_ChildWindow, NULL); // Update immediately
- // Decide if we should use a focused title bar color
- bool is_focused = false;
- ImGuiDockNode* root_node = DockNodeGetRootNode(node);
- if (g.NavWindowingTarget)
- is_focused = (g.NavWindowingTarget->DockNode == node);
- else if (g.NavWindow && g.NavWindow->RootWindowForTitleBarHighlight == host_window->RootWindow && root_node->LastFocusedNodeID == node->ID)
- is_focused = true;
+ // Remove window
+ bool erased = false;
+ for (int n = 0; n < node->Windows.Size; n++)
+ if (node->Windows[n] == window)
+ {
+ node->Windows.erase(node->Windows.Data + n);
+ erased = true;
+ break;
+ }
+ IM_ASSERT(erased);
+ if (node->VisibleWindow == window)
+ node->VisibleWindow = NULL;
- // Hidden tab bar will show a triangle on the upper-left (in Begin)
- if (node->IsHiddenTabBar)
+ // Remove tab and possibly tab bar
+ node->WantHiddenTabBarUpdate = true;
+ if (node->TabBar)
{
- node->VisibleWindow = (node->Windows.Size > 0) ? node->Windows[0] : NULL;
- node->IsFocused = is_focused;
- if (is_focused)
- node->LastFrameFocused = g.FrameCount;
+ TabBarRemoveTab(node->TabBar, window->ID);
+ const int tab_count_threshold_for_tab_bar = node->IsCentralNode() ? 1 : 2;
+ if (node->Windows.Size < tab_count_threshold_for_tab_bar)
+ DockNodeRemoveTabBar(node);
+ }
- // Notify root of visible window (used to display title in OS task bar)
- if (node->VisibleWindow)
- {
- if (is_focused || root_node->VisibleWindow == NULL)
- root_node->VisibleWindow = node->VisibleWindow;
- if (node->TabBar)
- node->TabBar->VisibleTabId = node->VisibleWindow->ID;
- }
+ if (node->Windows.Size == 0 && !node->IsCentralNode() && !node->IsDockSpace() && window->DockId != node->ID)
+ {
+ // Automatic dock node delete themselves if they are not holding at least one tab
+ DockContextRemoveNode(&g, node, true);
return;
}
- // Move ourselves to the Menu layer (so we can be accessed by tapping Alt) + undo SkipItems flag in order to draw over the title bar even if the window is collapsed
- bool backup_skip_item = host_window->SkipItems;
- if (!node->IsDockSpace())
+ if (node->Windows.Size == 1 && !node->IsCentralNode() && node->HostWindow)
{
- host_window->SkipItems = false;
- host_window->DC.NavLayerCurrent = ImGuiNavLayer_Menu;
- host_window->DC.NavLayerCurrentMask = (1 << ImGuiNavLayer_Menu);
+ ImGuiWindow* remaining_window = node->Windows[0];
+ if (node->HostWindow->ViewportOwned && node->IsRootNode())
+ {
+ // Transfer viewport back to the remaining loose window
+ IM_ASSERT(node->HostWindow->Viewport->Window == node->HostWindow);
+ node->HostWindow->Viewport->Window = remaining_window;
+ node->HostWindow->Viewport->ID = remaining_window->ID;
+ }
+ remaining_window->Collapsed = node->HostWindow->Collapsed;
}
- PushID(node->ID);
- ImGuiTabBar* tab_bar = node->TabBar;
- bool tab_bar_is_recreated = (tab_bar == NULL); // Tab bar are automatically destroyed when a node gets hidden
- if (tab_bar == NULL)
- tab_bar = node->TabBar = IM_NEW(ImGuiTabBar)();
+ // Update visibility immediately is required so the DockNodeUpdateRemoveInactiveChilds() processing can reflect changes up the tree
+ DockNodeUpdateVisibleFlag(node);
+}
- ImGuiID focus_tab_id = 0;
+static void ImGui::DockNodeMoveChildNodes(ImGuiDockNode* dst_node, ImGuiDockNode* src_node)
+{
+ IM_ASSERT(dst_node->Windows.Size == 0);
+ dst_node->ChildNodes[0] = src_node->ChildNodes[0];
+ dst_node->ChildNodes[1] = src_node->ChildNodes[1];
+ if (dst_node->ChildNodes[0])
+ dst_node->ChildNodes[0]->ParentNode = dst_node;
+ if (dst_node->ChildNodes[1])
+ dst_node->ChildNodes[1]->ParentNode = dst_node;
+ dst_node->SplitAxis = src_node->SplitAxis;
+ dst_node->SizeRef = src_node->SizeRef;
+ src_node->ChildNodes[0] = src_node->ChildNodes[1] = NULL;
+}
- // Collapse button changes shape and display a list
- if (IsPopupOpen("#TabListMenu"))
+static void ImGui::DockNodeMoveWindows(ImGuiDockNode* dst_node, ImGuiDockNode* src_node)
+{
+ // Insert tabs in the same orders as currently ordered (node->Windows isn't ordered)
+ IM_ASSERT(src_node && dst_node && dst_node != src_node);
+ ImGuiTabBar* src_tab_bar = src_node->TabBar;
+ if (src_tab_bar != NULL)
+ IM_ASSERT(src_node->Windows.Size == src_node->TabBar->Tabs.Size);
+
+ // If the dst_node is empty we can just move the entire tab bar (to preserve selection, scrolling, etc.)
+ bool move_tab_bar = (src_tab_bar != NULL) && (dst_node->TabBar == NULL);
+ if (move_tab_bar)
{
- // Try to position the menu so it is more likely to stays within the same viewport
- SetNextWindowPos(ImVec2(node->Pos.x, node->Pos.y + GetFrameHeight()));
- if (BeginPopup("#TabListMenu"))
- {
- is_focused = true;
- if (tab_bar->Tabs.Size == 1)
- {
- if (MenuItem("Hide tab bar", NULL, node->IsHiddenTabBar))
- node->WantHiddenTabBarToggle = true;
- }
- else
- {
- for (int tab_n = 0; tab_n < tab_bar->Tabs.Size; tab_n++)
- {
- ImGuiTabItem* tab = &tab_bar->Tabs[tab_n];
- IM_ASSERT(tab->Window != NULL);
- if (Selectable(tab->Window->Name, tab->ID == tab_bar->SelectedTabId))
- focus_tab_id = tab_bar->NextSelectedTabId = tab->ID;
- SameLine();
- Text(" ");
- }
- }
- EndPopup();
- }
+ dst_node->TabBar = src_node->TabBar;
+ src_node->TabBar = NULL;
+ }
+
+ for (int n = 0; n < src_node->Windows.Size; n++)
+ {
+ ImGuiWindow* window = src_tab_bar ? src_tab_bar->Tabs[n].Window : src_node->Windows[n];
+ window->DockNode = NULL;
+ window->DockIsActive = false;
+ DockNodeAddWindow(dst_node, window, move_tab_bar ? false : true);
}
+ src_node->Windows.clear();
- // Title bar
- node->IsFocused = is_focused;
- if (is_focused)
- node->LastFrameFocused = g.FrameCount;
- ImRect title_bar_rect = ImRect(node->Pos, node->Pos + ImVec2(node->Size.x, g.FontSize + style.FramePadding.y * 2.0f));
- ImU32 title_bar_col = GetColorU32(host_window->Collapsed ? ImGuiCol_TitleBgCollapsed : is_focused ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBg);
- host_window->DrawList->AddRectFilled(title_bar_rect.Min, title_bar_rect.Max, title_bar_col, host_window->WindowRounding, ImDrawCornerFlags_Top);
+ if (!move_tab_bar && src_node->TabBar)
+ {
+ if (dst_node->TabBar)
+ dst_node->TabBar->SelectedTabId = src_node->TabBar->SelectedTabId;
+ DockNodeRemoveTabBar(src_node);
+ }
+}
- // Collapse button
- if (CollapseButton(host_window->GetID("#COLLAPSE"), title_bar_rect.Min, node))
- OpenPopup("#TabListMenu");
- if (IsItemActive())
- focus_tab_id = tab_bar->SelectedTabId;
+static void ImGui::DockNodeApplyPosSizeToWindows(ImGuiDockNode* node)
+{
+ for (int n = 0; n < node->Windows.Size; n++)
+ {
+ SetWindowPos(node->Windows[n], node->Pos, ImGuiCond_Always); // We don't assign directly to Pos because it can break the calculation of SizeContents on next frame
+ SetWindowSize(node->Windows[n], node->Size, ImGuiCond_Always);
+ }
+}
- // Submit new tabs and apply NavWindow focus back to the tab bar. They will be added as Unsorted and sorted below based on relative DockOrder value.
- const int tabs_count_old = tab_bar->Tabs.Size;
- for (int window_n = 0; window_n < node->Windows.Size; window_n++)
+static void ImGui::DockNodeHideHostWindow(ImGuiDockNode* node)
+{
+ if (node->HostWindow)
{
- ImGuiWindow* window = node->Windows[window_n];
- if (g.NavWindow && g.NavWindow->RootWindowDockStop == window)
- tab_bar->SelectedTabId = window->ID;
- if (TabBarFindTabByID(tab_bar, window->ID) == NULL)
- TabBarAddTab(tab_bar, ImGuiTabItemFlags_Unsorted, window);
+ if (node->HostWindow->DockNodeAsHost == node)
+ node->HostWindow->DockNodeAsHost = NULL;
+ node->HostWindow = NULL;
}
- // If multiple tabs are appearing on the same frame, sort them based on their persistent DockOrder value
- int tabs_unsorted_start = tab_bar->Tabs.Size;
- for (int tab_n = tab_bar->Tabs.Size - 1; tab_n >= 0 && (tab_bar->Tabs[tab_n].Flags & ImGuiTabItemFlags_Unsorted); tab_n--)
+ if (node->Windows.Size == 1)
{
- tab_bar->Tabs[tab_n].Flags &= ~ImGuiTabItemFlags_Unsorted;
- tabs_unsorted_start = tab_n;
+ node->VisibleWindow = node->Windows[0];
+ node->Windows[0]->DockIsActive = false;
}
- //printf("[%05d] Sorting %d new appearing tabs\n", g.FrameCount, tab_bar->Tabs.Size - tabs_unsorted_start);
- if (tab_bar->Tabs.Size > tabs_unsorted_start + 1)
- ImQsort(tab_bar->Tabs.Data + tabs_unsorted_start, tab_bar->Tabs.Size - tabs_unsorted_start, sizeof(ImGuiTabItem), TabItemComparerByDockOrder);
- // Selected newly added tabs, or persistent tab ID if the tab bar was just recreated
- if (tab_bar_is_recreated && TabBarFindTabByID(tab_bar, node->SelectedTabID) != NULL)
- tab_bar->SelectedTabId = tab_bar->NextSelectedTabId = node->SelectedTabID;
- else if (tab_bar->Tabs.Size > tabs_count_old)
- tab_bar->SelectedTabId = tab_bar->NextSelectedTabId = tab_bar->Tabs.back().Window->ID;
+ if (node->TabBar)
+ DockNodeRemoveTabBar(node);
+}
- // Begin tab bar
- const ImRect tab_bar_rect = DockNodeCalcTabBarRect(node);
- ImGuiTabBarFlags tab_bar_flags = ImGuiTabBarFlags_Reorderable | ImGuiTabBarFlags_AutoSelectNewTabs | ImGuiTabBarFlags_NoTabListPopupButton;// | ImGuiTabBarFlags_NoTabListScrollingButtons);
- tab_bar_flags |= ImGuiTabBarFlags_SaveSettings | ImGuiTabBarFlags_DockNode;
- if (!host_window->Collapsed && is_focused)
- tab_bar_flags |= ImGuiTabBarFlags_IsFocused;
- BeginTabBarEx(tab_bar, tab_bar_rect, tab_bar_flags, node);
- //host_window->DrawList->AddRect(tab_bar_rect.Min, tab_bar_rect.Max, IM_COL32(255,0,255,255));
+// Search function called once by root node in DockNodeUpdate()
+struct ImGuiDockNodeFindInfoResults
+{
+ ImGuiDockNode* CentralNode;
+ ImGuiDockNode* FirstNodeWithWindows;
+ int CountNodesWithWindows;
+ //ImGuiWindowClass WindowClassForMerges;
- // Submit actual tabs
- node->VisibleWindow = NULL;
- for (int window_n = 0; window_n < node->Windows.Size; window_n++)
+ ImGuiDockNodeFindInfoResults() { CentralNode = FirstNodeWithWindows = NULL; CountNodesWithWindows = 0; }
+};
+
+static void DockNodeFindInfo(ImGuiDockNode* node, ImGuiDockNodeFindInfoResults* results)
+{
+ if (node->Windows.Size > 0)
{
- ImGuiWindow* window = node->Windows[window_n];
- if ((closed_all || closed_one == window->ID) && window->HasCloseButton && !(window->Flags & ImGuiWindowFlags_UnsavedDocument))
- continue;
- if (window->LastFrameActive + 1 >= g.FrameCount || !node_was_active)
- {
- ImGuiTabItemFlags tab_item_flags = 0;
- if (window->Flags & ImGuiWindowFlags_UnsavedDocument)
- tab_item_flags |= ImGuiTabItemFlags_UnsavedDocument;
- if (tab_bar->Flags & ImGuiTabBarFlags_NoCloseWithMiddleMouseButton)
- tab_item_flags |= ImGuiTabItemFlags_NoCloseWithMiddleMouseButton;
+ if (results->FirstNodeWithWindows == NULL)
+ results->FirstNodeWithWindows = node;
+ results->CountNodesWithWindows++;
+ }
+ if (node->IsCentralNode())
+ {
+ IM_ASSERT(results->CentralNode == NULL); // Should be only one
+ IM_ASSERT(node->IsLeafNode() && "If you get this assert: please submit .ini file + repro of actions leading to this.");
+ results->CentralNode = node;
+ }
+ if (results->CountNodesWithWindows > 1 && results->CentralNode != NULL)
+ return;
+ if (node->ChildNodes[0])
+ DockNodeFindInfo(node->ChildNodes[0], results);
+ if (node->ChildNodes[1])
+ DockNodeFindInfo(node->ChildNodes[1], results);
+}
- bool tab_open = true;
- TabItemEx(tab_bar, window->Name, window->HasCloseButton ? &tab_open : NULL, tab_item_flags, window);
- if (!tab_open)
- node->WantCloseTabID = window->ID;
- if (tab_bar->VisibleTabId == window->ID)
- node->VisibleWindow = window;
+static ImGuiWindow* ImGui::DockNodeFindWindowByID(ImGuiDockNode* node, ImGuiID id)
+{
+ IM_ASSERT(id != 0);
+ for (int n = 0; n < node->Windows.Size; n++)
+ if (node->Windows[n]->ID == id)
+ return node->Windows[n];
+ return NULL;
+}
- // Store last item data so it can be queried with IsItemXXX functions after the user Begin() call
- window->DockTabItemStatusFlags = host_window->DC.LastItemStatusFlags;
- window->DockTabItemRect = host_window->DC.LastItemRect;
+// - Remove inactive windows/nodes.
+// - Update visibility flag.
+static void ImGui::DockNodeUpdateVisibleFlagAndInactiveChilds(ImGuiDockNode* node)
+{
+ ImGuiContext& g = *GImGui;
- // Update navigation ID on menu layer
- if (g.NavWindow && g.NavWindow->RootWindowDockStop == window && (window->DC.NavLayerActiveMask & (1 << 1)) == 0)
- host_window->NavLastIds[1] = window->ID;
- }
- }
+ IM_ASSERT(node->ParentNode == NULL || node->ParentNode->ChildNodes[0] == node || node->ParentNode->ChildNodes[1] == node);
- // Notify root of visible window (used to display title in OS task bar)
- if (node->VisibleWindow)
- if (is_focused || root_node->VisibleWindow == NULL)
- root_node->VisibleWindow = node->VisibleWindow;
+ // Inherit most flags
+ if (node->ParentNode)
+ node->SharedFlags = node->ParentNode->SharedFlags & ImGuiDockNodeFlags_SharedFlagsInheritMask_;
- // Close button (after VisibleWindow was updated)
- // Note that VisibleWindow may have been overrided by CTRL+Tabbing, so VisibleWindow->ID may be != from tab_bar->SelectedTabId
- if (node->VisibleWindow)
- {
- if (!node->VisibleWindow->HasCloseButton)
- {
- PushItemFlag(ImGuiItemFlags_Disabled, true);
- PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_Text] * ImVec4(1.0f,1.0f,1.0f,0.5f));
- }
- const float rad = g.FontSize * 0.5f;
- if (CloseButton(host_window->GetID("#CLOSE"), title_bar_rect.GetTR() + ImVec2(-style.FramePadding.x - rad, style.FramePadding.y + rad), rad + 1))
- if (ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, tab_bar->VisibleTabId))
- {
- node->WantCloseTabID = tab->ID;
- TabBarCloseTab(tab_bar, tab);
- }
- //if (IsItemActive())
- // focus_tab_id = tab_bar->SelectedTabId;
- if (!node->VisibleWindow->HasCloseButton)
- {
- PopStyleColor();
- PopItemFlag();
- }
- }
+ // Recurse into children
+ // There is the possibility that one of our child becoming empty will delete itself and moving its sibling contents into 'node'.
+ // If 'node->ChildNode[0]' delete itself, then 'node->ChildNode[1]->Windows' will be moved into 'node'
+ // If 'node->ChildNode[1]' delete itself, then 'node->ChildNode[0]->Windows' will be moved into 'node' and the "remove inactive windows" loop will have run twice on those windows (harmless)
+ if (node->ChildNodes[0])
+ DockNodeUpdateVisibleFlagAndInactiveChilds(node->ChildNodes[0]);
+ if (node->ChildNodes[1])
+ DockNodeUpdateVisibleFlagAndInactiveChilds(node->ChildNodes[1]);
- // When clicking on the title bar outside of tabs, we still focus the selected tab for that node
- if (g.HoveredWindow == host_window && g.HoveredId == 0 && IsMouseHoveringRect(title_bar_rect.Min, title_bar_rect.Max))
+ // Remove inactive windows
+ for (int window_n = 0; window_n < node->Windows.Size; window_n++)
{
- if (IsMouseClicked(0))
- {
- focus_tab_id = tab_bar->SelectedTabId;
+ ImGuiWindow* window = node->Windows[window_n];
+ IM_ASSERT(window->DockNode == node);
- // Forward moving request to selected window
- if (ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, focus_tab_id))
- StartMouseMovingWindow(tab->Window);
+ bool node_was_active = (node->LastFrameActive + 1 == g.FrameCount);
+ bool remove = false;
+ remove |= node_was_active && (window->LastFrameActive + 1 < g.FrameCount);
+ remove |= node_was_active && (node->WantCloseAll || node->WantCloseTabID == window->ID) && window->HasCloseButton && !(window->Flags & ImGuiWindowFlags_UnsavedDocument); // Submit all _expected_ closure from last frame
+ remove |= (window->DockTabWantClose);
+ if (!remove)
+ continue;
+ window->DockTabWantClose = false;
+ if (node->Windows.Size == 1 && !node->IsCentralNode())
+ {
+ DockNodeHideHostWindow(node);
+ node->State = ImGuiDockNodeState_HostWindowHiddenBecauseSingleWindow;
+ DockNodeRemoveWindow(node, window, node->ID); // Will delete the node so it'll be invalid on return
+ return;
}
+ DockNodeRemoveWindow(node, window, node->ID);
+ window_n--;
}
- // Forward focus from host node to selected window
- //if (is_focused && g.NavWindow == host_window && !g.NavWindowingTarget)
- // focus_tab_id = tab_bar->SelectedTabId;
+ // Auto-hide tab bar option
+ ImGuiDockNodeFlags node_flags = node->GetMergedFlags();
+ if (node->WantHiddenTabBarUpdate && node->Windows.Size == 1 && (node_flags & ImGuiDockNodeFlags_AutoHideTabBar) && !node->IsHiddenTabBar())
+ node->WantHiddenTabBarToggle = true;
+ node->WantHiddenTabBarUpdate = false;
- // When clicked on a tab we requested focus to the docked child
- // This overrides the value set by "forward focus from host node to selected window".
- if (tab_bar->NextSelectedTabId)
- focus_tab_id = tab_bar->NextSelectedTabId;
+ // Apply toggles at a single point of the frame (here!)
+ if (node->Windows.Size > 1)
+ node->LocalFlags &= ~ImGuiDockNodeFlags_HiddenTabBar;
+ else if (node->WantHiddenTabBarToggle)
+ node->LocalFlags ^= ImGuiDockNodeFlags_HiddenTabBar;
+ node->WantHiddenTabBarToggle = false;
- // Apply navigation focus
- if (focus_tab_id != 0)
- if (ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, focus_tab_id))
- {
- FocusWindow(tab->Window);
- NavInitWindow(tab->Window, false);
- }
+ DockNodeUpdateVisibleFlag(node);
+}
- EndTabBar();
- PopID();
+static void ImGui::DockNodeUpdateVisibleFlag(ImGuiDockNode* node)
+{
+ // Update visibility flag
+ bool is_visible = (node->ParentNode == NULL) ? node->IsDockSpace() : node->IsCentralNode();
+ is_visible |= (node->Windows.Size > 0);
+ is_visible |= (node->ChildNodes[0] && node->ChildNodes[0]->IsVisible);
+ is_visible |= (node->ChildNodes[1] && node->ChildNodes[1]->IsVisible);
+ node->IsVisible = is_visible;
+}
- // Restore SkipItems flag
- if (!node->IsDockSpace())
- {
- host_window->DC.NavLayerCurrent = ImGuiNavLayer_Main;
- host_window->DC.NavLayerCurrentMask = (1 << ImGuiNavLayer_Main);
- host_window->SkipItems = backup_skip_item;
- }
+static void ImGui::DockNodeStartMouseMovingWindow(ImGuiDockNode* node, ImGuiWindow* window)
+{
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(node->WantMouseMove == true);
+ ImVec2 backup_active_click_offset = g.ActiveIdClickOffset;
+ StartMouseMovingWindow(window);
+ g.MovingWindow = window; // If we are docked into a non moveable root window, StartMouseMovingWindow() won't set g.MovingWindow. Override that decision.
+ node->WantMouseMove = false;
+ g.ActiveIdClickOffset = backup_active_click_offset;
}
-static bool DockNodeIsDropAllowedOne(ImGuiWindow* payload, ImGuiWindow* host_window)
+static void ImGui::DockNodeUpdate(ImGuiDockNode* node)
{
- if (host_window->DockNodeAsHost && host_window->DockNodeAsHost->IsDockSpace() && payload->BeginOrderWithinContext < host_window->BeginOrderWithinContext)
- return false;
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(node->LastFrameActive != g.FrameCount);
+ node->LastFrameAlive = g.FrameCount;
+ node->MarkedForPosSizeWrite = false;
- ImGuiWindowClass* host_class = host_window->DockNodeAsHost ? &host_window->DockNodeAsHost->WindowClass : &host_window->WindowClass;
- ImGuiWindowClass* payload_class = &payload->WindowClass;
- if (host_class->ClassId != payload_class->ClassId)
+ node->CentralNode = node->OnlyNodeWithWindows = NULL;
+ if (node->IsRootNode())
{
- if (host_class->ClassId != 0 && host_class->DockingAllowUnclassed && payload_class->ClassId == 0)
- return true;
- if (payload_class->ClassId != 0 && payload_class->DockingAllowUnclassed && host_class->ClassId == 0)
- return true;
- return false;
+ DockNodeUpdateVisibleFlagAndInactiveChilds(node);
+
+ // FIXME-DOCK: Merge this scan into the one above.
+ // - Setup central node pointers
+ // - Find if there's only a single visible window in the hierarchy (in which case we need to display a regular title bar -> FIXME-DOCK: that last part is not done yet!)
+ ImGuiDockNodeFindInfoResults results;
+ DockNodeFindInfo(node, &results);
+ node->CentralNode = results.CentralNode;
+ node->OnlyNodeWithWindows = (results.CountNodesWithWindows == 1) ? results.FirstNodeWithWindows : NULL;
+ if (node->LastFocusedNodeID == 0 && results.FirstNodeWithWindows != NULL)
+ node->LastFocusedNodeID = results.FirstNodeWithWindows->ID;
+
+ // Copy the window class from of our first window so it can be used for proper dock filtering.
+ // When node has mixed windows, prioritize the class with the most constraint (DockingAllowUnclassed = false) as the reference to copy.
+ // FIXME-DOCK: We don't recurse properly, this code could be reworked to work from DockNodeUpdateScanRec.
+ if (ImGuiDockNode* first_node_with_windows = results.FirstNodeWithWindows)
+ {
+ node->WindowClass = first_node_with_windows->Windows[0]->WindowClass;
+ for (int n = 1; n < first_node_with_windows->Windows.Size; n++)
+ if (first_node_with_windows->Windows[n]->WindowClass.DockingAllowUnclassed == false)
+ {
+ node->WindowClass = first_node_with_windows->Windows[n]->WindowClass;
+ break;
+ }
+ }
}
- return true;
-}
-
-static bool ImGui::DockNodeIsDropAllowed(ImGuiWindow* host_window, ImGuiWindow* root_payload)
-{
- if (root_payload->DockNodeAsHost && root_payload->DockNodeAsHost->IsSplitNode())
- return true;
+ // Remove tab bar if not needed
+ if (node->TabBar && node->IsNoTabBar())
+ DockNodeRemoveTabBar(node);
- const int payload_count = root_payload->DockNodeAsHost ? root_payload->DockNodeAsHost->Windows.Size : 1;
- for (int payload_n = 0; payload_n < payload_count; payload_n++)
+ // Early out for hidden root dock nodes (when all DockId references are in inactive windows, or there is only 1 floating window holding on the DockId)
+ bool want_to_hide_host_window = false;
+ if (node->Windows.Size <= 1 && node->IsFloatingNode() && node->IsLeafNode())
+ if (!g.IO.ConfigDockingAlwaysTabBar && (node->Windows.Size == 0 || !node->Windows[0]->WindowClass.DockingAlwaysTabBar))
+ want_to_hide_host_window = true;
+ if (want_to_hide_host_window)
{
- ImGuiWindow* payload = root_payload->DockNodeAsHost ? root_payload->DockNodeAsHost->Windows[payload_n] : root_payload;
- if (DockNodeIsDropAllowedOne(payload, host_window))
- return true;
- }
- return false;
-}
+ if (node->Windows.Size == 1)
+ {
+ // Floating window pos/size is authoritative
+ ImGuiWindow* single_window = node->Windows[0];
+ node->Pos = single_window->Pos;
+ node->Size = single_window->SizeFull;
+ node->AuthorityForPos = node->AuthorityForSize = node->AuthorityForViewport = ImGuiDataAuthority_Window;
-static ImRect ImGui::DockNodeCalcTabBarRect(const ImGuiDockNode* node)
-{
- ImGuiContext& g = *GImGui;
- ImRect r = ImRect(node->Pos.x, node->Pos.y, node->Pos.x + node->Size.x, node->Pos.y + (g.FontSize + g.Style.FramePadding.y * 2.0f));
- if (node->HasCollapseButton)
- r.Min.x += g.Style.FramePadding.x + g.FontSize; // + g.Style.ItemInnerSpacing.x; // <-- Adding ItemInnerSpacing makes the title text moves slightly when in a tab bar. Instead we adjusted RenderArrowDockMenu()
- // In DockNodeUpdateTabBar() we currently display a disabled close button even if there is none.
- r.Max.x -= g.Style.FramePadding.x + g.FontSize + 1.0f;
- return r;
-}
+ // Transfer focus immediately so when we revert to a regular window it is immediately selected
+ if (node->HostWindow && g.NavWindow == node->HostWindow)
+ FocusWindow(single_window);
+ if (node->HostWindow)
+ {
+ single_window->Viewport = node->HostWindow->Viewport;
+ single_window->ViewportId = node->HostWindow->ViewportId;
+ if (node->HostWindow->ViewportOwned)
+ {
+ single_window->Viewport->Window = single_window;
+ single_window->ViewportOwned = true;
+ }
+ }
+ }
-void ImGui::DockNodeCalcSplitRects(ImVec2& pos_old, ImVec2& size_old, ImVec2& pos_new, ImVec2& size_new, ImGuiDir dir, ImVec2 size_new_desired)
-{
- ImGuiContext& g = *GImGui;
- const float dock_spacing = g.Style.ItemInnerSpacing.x;
- const ImGuiAxis axis = (dir == ImGuiDir_Left || dir == ImGuiDir_Right) ? ImGuiAxis_X : ImGuiAxis_Y;
- pos_new[axis ^ 1] = pos_old[axis ^ 1];
- size_new[axis ^ 1] = size_old[axis ^ 1];
+ DockNodeHideHostWindow(node);
+ node->State = ImGuiDockNodeState_HostWindowHiddenBecauseSingleWindow;
+ node->WantCloseAll = false;
+ node->WantCloseTabID = 0;
+ node->HasCloseButton = node->HasWindowMenuButton = node->EnableCloseButton = false;
+ node->LastFrameActive = g.FrameCount;
- // Distribute size on given axis (with a desired size or equally)
- const float w_avail = size_old[axis] - dock_spacing;
- if (size_new_desired[axis] > 0.0f && size_new_desired[axis] <= w_avail * 0.5f)
- {
- size_new[axis] = size_new_desired[axis];
- size_old[axis] = (float)(int)(w_avail - size_new[axis]);
- }
- else
- {
- size_new[axis] = (float)(int)(w_avail * 0.5f);
- size_old[axis] = (float)(int)(w_avail - size_new[axis]);
+ if (node->WantMouseMove && node->Windows.Size == 1)
+ DockNodeStartMouseMovingWindow(node, node->Windows[0]);
+ return;
}
- // Position each node
- if (dir == ImGuiDir_Right || dir == ImGuiDir_Down)
- {
- pos_new[axis] = pos_old[axis] + size_old[axis] + dock_spacing;
- }
- else if (dir == ImGuiDir_Left || dir == ImGuiDir_Up)
- {
- pos_new[axis] = pos_old[axis];
- pos_old[axis] = pos_new[axis] + size_new[axis] + dock_spacing;
+ // In some circumstance we will defer creating the host window (so everything will be kept hidden),
+ // while the expected visible window is resizing itself.
+ // This is important for first-time (no ini settings restored) single window when io.ConfigDockingAlwaysTabBar is enabled,
+ // otherwise the node ends up using the minimum window size. Effectively those windows will take an extra frame to show up:
+ // N+0: Begin(): window created (with no known size), node is created
+ // N+1: DockNodeUpdate(): node skip creating host window / Begin(): window size applied, not visible
+ // N+2: DockNodeUpdate(): node can create host window / Begin(): window becomes visible
+ // We could remove this frame if we could reliably calculate the expected window size during node update, before the Begin() code.
+ // It would require a generalization of CalcWindowExpectedSize(), probably extracting code away from Begin().
+ // In reality it isn't very important as user quickly ends up with size data in .ini file.
+ if (node->IsVisible && node->HostWindow == NULL && node->IsFloatingNode() && node->IsLeafNode())
+ {
+ IM_ASSERT(node->Windows.Size > 0);
+ ImGuiWindow* ref_window = NULL;
+ if (node->SelectedTabID != 0) // Note that we prune single-window-node settings on .ini loading, so this is generally 0 for them!
+ ref_window = DockNodeFindWindowByID(node, node->SelectedTabID);
+ if (ref_window == NULL)
+ ref_window = node->Windows[0];
+ if (ref_window->AutoFitFramesX > 0 || ref_window->AutoFitFramesY > 0)
+ {
+ node->State = ImGuiDockNodeState_HostWindowHiddenBecauseWindowsAreResizing;
+ return;
+ }
}
-}
-// Retrieve the drop rectangles for a given direction or for the center + perform hit testing.
-bool ImGui::DockNodeCalcDropRects(const ImRect& parent, ImGuiDir dir, ImRect& out_r, bool outer_docking)
-{
- ImGuiContext& g = *GImGui;
+ const ImGuiDockNodeFlags node_flags = node->GetMergedFlags();
- const float parent_smaller_axis = ImMin(parent.GetWidth(), parent.GetHeight());
- const float hs_for_central_nodes = ImMin(g.FontSize * 1.5f, ImMax(g.FontSize * 0.5f, parent_smaller_axis / 8.0f));
- float hs_w; // Half-size, longer axis
- float hs_h; // Half-size, smaller axis
- ImVec2 off; // Distance from edge or center
- if (outer_docking)
+ // Bind or create host window
+ ImGuiWindow* host_window = NULL;
+ bool beginned_into_host_window = false;
+ if (node->IsDockSpace())
{
- //hs_w = ImFloor(ImClamp(parent_smaller_axis - hs_for_central_nodes * 4.0f, g.FontSize * 0.5f, g.FontSize * 8.0f));
- //hs_h = ImFloor(hs_w * 0.15f);
- //off = ImVec2(ImFloor(parent.GetWidth() * 0.5f - GetFrameHeightWithSpacing() * 1.4f - hs_h), ImFloor(parent.GetHeight() * 0.5f - GetFrameHeightWithSpacing() * 1.4f - hs_h));
- hs_w = ImFloor(hs_for_central_nodes * 1.50f);
- hs_h = ImFloor(hs_for_central_nodes * 0.80f);
- off = ImVec2(ImFloor(parent.GetWidth() * 0.5f - GetFrameHeightWithSpacing() * 0.0f - hs_h), ImFloor(parent.GetHeight() * 0.5f - GetFrameHeightWithSpacing() * 0.0f - hs_h));
+ // [Explicit root dockspace node]
+ IM_ASSERT(node->HostWindow);
+ node->EnableCloseButton = false;
+ node->HasCloseButton = (node_flags & ImGuiDockNodeFlags_NoCloseButton) == 0;
+ node->HasWindowMenuButton = (node_flags & ImGuiDockNodeFlags_NoWindowMenuButton) == 0;
+ host_window = node->HostWindow;
}
else
{
- hs_w = ImFloor(hs_for_central_nodes);
- hs_h = ImFloor(hs_for_central_nodes * 0.90f);
- off = ImVec2(ImFloor(hs_w * 2.40f), ImFloor(hs_w * 2.40f));
- }
+ // [Automatic root or child nodes]
+ node->EnableCloseButton = false;
+ node->HasCloseButton = (node->Windows.Size > 0) && (node_flags & ImGuiDockNodeFlags_NoWindowMenuButton) == 0;
+ node->HasWindowMenuButton = (node->Windows.Size > 0) && (node_flags & ImGuiDockNodeFlags_NoWindowMenuButton) == 0;
+ for (int window_n = 0; window_n < node->Windows.Size; window_n++)
+ {
+ // FIXME-DOCK: Setting DockIsActive here means that for single active window in a leaf node, DockIsActive will be cleared until the next Begin() call.
+ ImGuiWindow* window = node->Windows[window_n];
+ window->DockIsActive = (node->Windows.Size > 1);
+ node->EnableCloseButton |= window->HasCloseButton;
+ }
- ImVec2 c = ImFloor(parent.GetCenter());
- if (dir == ImGuiDir_None) { out_r = ImRect(c.x - hs_w, c.y - hs_w, c.x + hs_w, c.y + hs_w); }
- else if (dir == ImGuiDir_Up) { out_r = ImRect(c.x - hs_w, c.y - off.y - hs_h, c.x + hs_w, c.y - off.y + hs_h); }
- else if (dir == ImGuiDir_Down) { out_r = ImRect(c.x - hs_w, c.y + off.y - hs_h, c.x + hs_w, c.y + off.y + hs_h); }
- else if (dir == ImGuiDir_Left) { out_r = ImRect(c.x - off.x - hs_h, c.y - hs_w, c.x - off.x + hs_h, c.y + hs_w); }
- else if (dir == ImGuiDir_Right) { out_r = ImRect(c.x + off.x - hs_h, c.y - hs_w, c.x + off.x + hs_h, c.y + hs_w); }
+ if (node->IsRootNode() && node->IsVisible)
+ {
+ ImGuiWindow* ref_window = (node->Windows.Size > 0) ? node->Windows[0] : NULL;
- ImRect hit_r = out_r;
- if (!outer_docking)
- {
- // Custom hit testing for the 5-way selection, designed to reduce flickering when moving diagonally between sides
- hit_r.Expand(ImFloor(hs_w * 0.30f));
- ImVec2 mouse_delta = (g.IO.MousePos - c);
- float mouse_delta_len2 = ImLengthSqr(mouse_delta);
- float r_threshold_center = hs_w * 1.4f;
- float r_threshold_sides = hs_w * (1.4f + 1.2f);
- if (mouse_delta_len2 < r_threshold_center * r_threshold_center)
- return (dir == ImGuiDir_None);
- if (mouse_delta_len2 < r_threshold_sides * r_threshold_sides)
- return (dir == ImGetDirQuadrantFromDelta(mouse_delta.x, mouse_delta.y));
- }
- return hit_r.Contains(g.IO.MousePos);
-}
+ // Sync Pos
+ if (node->AuthorityForPos == ImGuiDataAuthority_Window && ref_window)
+ SetNextWindowPos(ref_window->Pos);
+ else if (node->AuthorityForPos == ImGuiDataAuthority_DockNode)
+ SetNextWindowPos(node->Pos);
-// host_node may be NULL if the window doesn't have a DockNode already.
-static bool ImGui::DockNodePreviewDockCalc(ImGuiWindow* host_window, ImGuiDockNode* host_node, ImGuiWindow* root_payload, ImGuiDockPreviewData* data, bool is_explicit_target, bool is_outer_docking)
-{
- ImGuiContext& g = *GImGui;
- IM_ASSERT(g.CurrentWindow == host_window); // Because we rely on font size to calculate tab sizes
+ // Sync Size
+ if (node->AuthorityForSize == ImGuiDataAuthority_Window && ref_window)
+ SetNextWindowSize(ref_window->SizeFull);
+ else if (node->AuthorityForSize == ImGuiDataAuthority_DockNode)
+ SetNextWindowSize(node->Size);
- // There is an edge case when docking into a dockspace which only has inactive nodes.
- // In this case DockNodeTreeFindNodeByPos() will have selected a leaf node which is inactive.
- // Because the inactive leaf node doesn't have proper pos/size yet, we'll use the root node as reference.
- ImGuiDockNode* ref_node_for_rect = (host_node && !host_node->IsVisible) ? DockNodeGetRootNode(host_node) : host_node;
- if (ref_node_for_rect)
- IM_ASSERT(ref_node_for_rect->IsVisible);
+ // Sync Collapsed
+ if (node->AuthorityForSize == ImGuiDataAuthority_Window && ref_window)
+ SetNextWindowCollapsed(ref_window->Collapsed);
- // Build a tentative future node (reuse same structure because it is practical)
- data->FutureNode.HasCloseButton = (host_node ? host_node->HasCloseButton : host_window->HasCloseButton) || (root_payload->HasCloseButton);
- data->FutureNode.HasCollapseButton = host_node ? true : ((host_window->Flags & ImGuiWindowFlags_NoCollapse) == 0);
- data->FutureNode.Pos = host_node ? ref_node_for_rect->Pos : host_window->Pos;
- data->FutureNode.Size = host_node ? ref_node_for_rect->Size : host_window->Size;
+ // Sync Viewport
+ if (node->AuthorityForViewport == ImGuiDataAuthority_Window && ref_window)
+ SetNextWindowViewport(ref_window->ViewportId);
- // Figure out here we are allowed to dock
- const bool src_is_visibly_splitted = root_payload->DockNodeAsHost && root_payload->DockNodeAsHost->IsSplitNode() && (root_payload->DockNodeAsHost->OnlyNodeWithWindows == NULL);
- data->IsCenterAvailable = !is_outer_docking;
- if (src_is_visibly_splitted && (!host_node || !host_node->IsEmpty()))
- data->IsCenterAvailable = false;
- if (host_node && (host_node->Flags & ImGuiDockNodeFlags_NoDockingInCentralNode) && host_node->IsCentralNode)
- data->IsCenterAvailable = false;
+ SetNextWindowClass(&node->WindowClass);
- data->IsSidesAvailable = true;
- if ((host_node && (host_node->Flags & ImGuiDockNodeFlags_NoSplit)) || g.IO.ConfigDockingNoSplit)
- data->IsSidesAvailable = false;
- if (!is_outer_docking && host_node && host_node->ParentNode == NULL && host_node->IsCentralNode)
- data->IsSidesAvailable = false;
+ // Begin into the host window
+ char window_label[20];
+ DockNodeGetHostWindowTitle(node, window_label, IM_ARRAYSIZE(window_label));
+ ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_DockNodeHost;
+ window_flags |= ImGuiWindowFlags_NoFocusOnAppearing;
+ window_flags |= ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoCollapse;
+ window_flags |= ImGuiWindowFlags_NoTitleBar;
- // Calculate drop shapes geometry for allowed splitting directions
- IM_ASSERT(ImGuiDir_None == -1);
- data->SplitNode = host_node;
- data->SplitDir = ImGuiDir_None;
- data->IsSplitDirExplicit = false;
- if (!host_window->Collapsed)
- for (int dir = ImGuiDir_None; dir < ImGuiDir_COUNT; dir++)
+ PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
+ Begin(window_label, NULL, window_flags);
+ PopStyleVar();
+ beginned_into_host_window = true;
+
+ node->HostWindow = host_window = g.CurrentWindow;
+ host_window->DockNodeAsHost = node;
+ host_window->DC.CursorPos = host_window->Pos;
+ node->Pos = host_window->Pos;
+ node->Size = host_window->Size;
+
+ // We set ImGuiWindowFlags_NoFocusOnAppearing because we don't want the host window to take full focus (e.g. steal NavWindow)
+ // But we still it bring it to the front of display. There's no way to choose this precise behavior via window flags.
+ // One simple case to ponder if: window A has a toggle to create windows B/C/D. Dock B/C/D together, clear the toggle and enable it again.
+ // When reappearing B/C/D will request focus and be moved to the top of the display pile, but they are not linked to the dock host window
+ // during the frame they appear. The dock host window would keep its old display order, and the sorting in EndFrame would move B/C/D back
+ // after the dock host window, losing their top-most status.
+ if (node->HostWindow->Appearing)
+ BringWindowToDisplayFront(node->HostWindow);
+
+ node->AuthorityForPos = node->AuthorityForSize = node->AuthorityForViewport = ImGuiDataAuthority_Auto;
+ }
+ else if (node->ParentNode)
{
- if (dir == ImGuiDir_None && !data->IsCenterAvailable)
- continue;
- if (dir != ImGuiDir_None && !data->IsSidesAvailable)
- continue;
- if (DockNodeCalcDropRects(data->FutureNode.Rect(), (ImGuiDir)dir, data->DropRectsDraw[dir+1], is_outer_docking))
- {
- data->SplitDir = (ImGuiDir)dir;
- data->IsSplitDirExplicit = true;
- }
+ node->HostWindow = host_window = node->ParentNode->HostWindow;
+ node->AuthorityForPos = node->AuthorityForSize = node->AuthorityForViewport = ImGuiDataAuthority_Auto;
}
+ if (node->WantMouseMove && node->HostWindow)
+ DockNodeStartMouseMovingWindow(node, node->HostWindow);
+ }
- // When docking without holding Shift, we only allow and preview docking when hovering over a drop rect or over the title bar
- data->IsDropAllowed = (data->SplitDir != ImGuiDir_None) || (data->IsCenterAvailable);
- if (!is_explicit_target && !data->IsSplitDirExplicit && !g.IO.ConfigDockingWithShift)
- data->IsDropAllowed = false;
+ // Update focused node (the one whose title bar is highlight) within a node tree
+ if (node->IsSplitNode())
+ IM_ASSERT(node->TabBar == NULL);
+ if (node->IsRootNode())
+ if (g.NavWindow && g.NavWindow->RootWindowDockStop->DockNode && g.NavWindow->RootWindowDockStop->ParentWindow == host_window)
+ node->LastFocusedNodeID = g.NavWindow->RootWindowDockStop->DockNode->ID;
+
+ // We need to draw a background at the root level if requested by ImGuiDockNodeFlags_PassthruCentralNode, but we will only know the correct pos/size after
+ // processing the resizing splitters. So we are using the DrawList channel splitting facility to submit drawing primitives out of order!
+ const bool render_dockspace_bg = node->IsRootNode() && host_window && (node_flags & ImGuiDockNodeFlags_PassthruCentralNode) != 0;
+ if (render_dockspace_bg)
+ {
+ host_window->DrawList->ChannelsSplit(2);
+ host_window->DrawList->ChannelsSetCurrent(1);
+ }
+
+ // Register a hit-test hole in the window unless we are currently dragging a window that is compatible with our dockspace
+ const ImGuiDockNode* central_node = node->CentralNode;
+ const bool central_node_hole = node->IsRootNode() && host_window && (node_flags & ImGuiDockNodeFlags_PassthruCentralNode) != 0 && central_node != NULL && central_node->IsEmpty();
+ bool central_node_hole_register_hit_test_hole = central_node_hole;
+ if (central_node_hole)
+ if (const ImGuiPayload* payload = ImGui::GetDragDropPayload())
+ if (payload->IsDataType(IMGUI_PAYLOAD_TYPE_WINDOW) && DockNodeIsDropAllowed(host_window, *(ImGuiWindow**)payload->Data))
+ central_node_hole_register_hit_test_hole = false;
+ if (central_node_hole_register_hit_test_hole)
+ {
+ // Add a little padding to match the "resize from edges" behavior and allow grabbing the splitter easily.
+ IM_ASSERT(node->IsDockSpace()); // We cannot pass this flag without the DockSpace() api. Testing this because we also setup the hole in host_window->ParentNode
+ ImRect central_hole(central_node->Pos, central_node->Pos + central_node->Size);
+ central_hole.Expand(ImVec2(-WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS, -WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS));
+ if (central_node_hole && !central_hole.IsInverted())
+ {
+ SetWindowHitTestHole(host_window, central_hole.Min, central_hole.Max - central_hole.Min);
+ SetWindowHitTestHole(host_window->ParentWindow, central_hole.Min, central_hole.Max - central_hole.Min);
+ }
+ }
- // Calculate split area
- data->SplitRatio = 0.0f;
- if (data->SplitDir != ImGuiDir_None)
+ // Update position/size, process and draw resizing splitters
+ if (node->IsRootNode() && host_window)
{
- ImGuiDir split_dir = data->SplitDir;
- ImGuiAxis split_axis = (split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Right) ? ImGuiAxis_X : ImGuiAxis_Y;
- ImVec2 pos_new, pos_old = data->FutureNode.Pos;
- ImVec2 size_new, size_old = data->FutureNode.Size;
- DockNodeCalcSplitRects(pos_old, size_old, pos_new, size_new, split_dir, root_payload->Size);
-
- // Calculate split ratio so we can pass it down the docking request
- float split_ratio = ImSaturate(size_new[split_axis] / data->FutureNode.Size[split_axis]);
- data->FutureNode.Pos = pos_new;
- data->FutureNode.Size = size_new;
- data->SplitRatio = (split_dir == ImGuiDir_Right || split_dir == ImGuiDir_Down) ? (1.0f - split_ratio) : (split_ratio);
+ DockNodeTreeUpdatePosSize(node, host_window->Pos, host_window->Size);
+ DockNodeTreeUpdateSplitter(node);
}
- return data->IsSplitDirExplicit;
-}
+ // Draw empty node background (currently can only be the Central Node)
+ if (host_window && node->IsEmpty() && node->IsVisible && !(node_flags & ImGuiDockNodeFlags_PassthruCentralNode))
+ host_window->DrawList->AddRectFilled(node->Pos, node->Pos + node->Size, GetColorU32(ImGuiCol_DockingEmptyBg));
-static void ImGui::DockNodePreviewDockRender(ImGuiWindow* host_window, ImGuiDockNode* host_node, ImGuiWindow* root_payload, const ImGuiDockPreviewData* data)
-{
- ImGuiContext& g = *GImGui;
+ // Draw whole dockspace background if ImGuiDockNodeFlags_PassthruCentralNode if set.
+ if (render_dockspace_bg && node->IsVisible)
+ {
+ host_window->DrawList->ChannelsSetCurrent(0);
+ if (central_node_hole)
+ RenderRectFilledWithHole(host_window->DrawList, node->Rect(), central_node->Rect(), GetColorU32(ImGuiCol_WindowBg), 0.0f);
+ else
+ host_window->DrawList->AddRectFilled(node->Pos, node->Pos + node->Size, GetColorU32(ImGuiCol_WindowBg), 0.0f);
+ host_window->DrawList->ChannelsMerge();
+ }
- // With this option, we only display the preview on the target viewport, and the payload viewport is made transparent.
- // To compensate for the single layer obstructed by the payload, we'll increase the alpha of the preview nodes.
- const bool is_transparent_payload = g.IO.ConfigDockingTransparentPayload;
+ // Draw and populate Tab Bar
+ if (host_window && node->Windows.Size > 0)
+ {
+ DockNodeUpdateTabBar(node, host_window);
+ }
+ else
+ {
+ node->WantCloseAll = false;
+ node->WantCloseTabID = 0;
+ node->IsFocused = false;
+ }
+ if (node->TabBar && node->TabBar->SelectedTabId)
+ node->SelectedTabID = node->TabBar->SelectedTabId;
+ else if (node->Windows.Size > 0)
+ node->SelectedTabID = node->Windows[0]->ID;
- // In case the two windows involved are on different viewports, we will draw the overlay on each of them.
- int overlay_draw_lists_count = 0;
- ImDrawList* overlay_draw_lists[2];
- overlay_draw_lists[overlay_draw_lists_count++] = GetOverlayDrawList(host_window->Viewport);
- if (host_window->Viewport != root_payload->Viewport && !is_transparent_payload)
- overlay_draw_lists[overlay_draw_lists_count++] = GetOverlayDrawList(root_payload->Viewport);
+ // Draw payload drop target
+ if (host_window && node->IsVisible)
+ if (node->IsRootNode() && (g.MovingWindow == NULL || g.MovingWindow->RootWindow != host_window))
+ BeginAsDockableDragDropTarget(host_window);
- // Draw main preview rectangle
- const ImU32 overlay_col_tabs = GetColorU32(ImGuiCol_TabActive);
- const ImU32 overlay_col_main = GetColorU32(ImGuiCol_DockingPreview, is_transparent_payload ? 0.60f : 0.40f);
- const ImU32 overlay_col_drop = GetColorU32(ImGuiCol_DockingPreview, is_transparent_payload ? 0.90f : 0.70f);
- const ImU32 overlay_col_drop_hovered = GetColorU32(ImGuiCol_DockingPreview, is_transparent_payload ? 1.20f : 1.00f);
- const ImU32 overlay_col_lines = GetColorU32(ImGuiCol_NavWindowingHighlight, is_transparent_payload ? 0.80f : 0.60f);
+ // We update this after DockNodeUpdateTabBar()
+ node->LastFrameActive = g.FrameCount;
- // Display area preview
- const bool can_preview_tabs = (root_payload->DockNodeAsHost == NULL || root_payload->DockNodeAsHost->Windows.Size > 0);
- if (data->IsDropAllowed)
+ // Recurse into children
+ // FIXME-DOCK FIXME-OPT: Should not need to recurse into children
+ if (host_window)
{
- ImRect overlay_rect = data->FutureNode.Rect();
- if (data->SplitDir == ImGuiDir_None && can_preview_tabs)
- overlay_rect.Min.y += GetFrameHeight();
- if (data->SplitDir != ImGuiDir_None || data->IsCenterAvailable)
- for (int overlay_n = 0; overlay_n < overlay_draw_lists_count; overlay_n++)
- overlay_draw_lists[overlay_n]->AddRectFilled(overlay_rect.Min, overlay_rect.Max, overlay_col_main, host_window->WindowRounding);
+ if (node->ChildNodes[0])
+ DockNodeUpdate(node->ChildNodes[0]);
+ if (node->ChildNodes[1])
+ DockNodeUpdate(node->ChildNodes[1]);
+
+ // Render outer borders last (after the tab bar)
+ if (node->IsRootNode())
+ RenderWindowOuterBorders(host_window);
}
- // Display tab shape/label preview unless we are splitting node (it generally makes the situation harder to read)
- if (data->IsDropAllowed && can_preview_tabs && data->SplitDir == ImGuiDir_None && data->IsCenterAvailable)
+ // End host window
+ if (beginned_into_host_window) //-V1020
+ End();
+}
+
+// Compare TabItem nodes given the last known DockOrder (will persist in .ini file as hint), used to sort tabs when multiple tabs are added on the same frame.
+static int IMGUI_CDECL TabItemComparerByDockOrder(const void* lhs, const void* rhs)
+{
+ ImGuiWindow* a = ((const ImGuiTabItem*)lhs)->Window;
+ ImGuiWindow* b = ((const ImGuiTabItem*)rhs)->Window;
+ if (int d = ((a->DockOrder == -1) ? INT_MAX : a->DockOrder) - ((b->DockOrder == -1) ? INT_MAX : b->DockOrder))
+ return d;
+ return (a->BeginOrderWithinContext - b->BeginOrderWithinContext);
+}
+
+static ImGuiID ImGui::DockNodeUpdateWindowMenu(ImGuiDockNode* node, ImGuiTabBar* tab_bar)
+{
+ // Try to position the menu so it is more likely to stays within the same viewport
+ ImGuiContext& g = *GImGui;
+ ImGuiID ret_tab_id = 0;
+ if (g.Style.WindowMenuButtonPosition == ImGuiDir_Left)
+ SetNextWindowPos(ImVec2(node->Pos.x, node->Pos.y + GetFrameHeight()), ImGuiCond_Always, ImVec2(0.0f, 0.0f));
+ else
+ SetNextWindowPos(ImVec2(node->Pos.x + node->Size.x, node->Pos.y + GetFrameHeight()), ImGuiCond_Always, ImVec2(1.0f, 0.0f));
+ if (BeginPopup("#WindowMenu"))
{
- // Compute target tab bar geometry so we can locate our preview tabs
- ImRect tab_bar_rect = DockNodeCalcTabBarRect(&data->FutureNode);
- ImVec2 tab_pos = tab_bar_rect.Min;
- if (host_node && host_node->TabBar)
- {
- if (!host_node->IsHiddenTabBar)
- tab_pos.x += host_node->TabBar->OffsetMax + g.Style.ItemInnerSpacing.x; // We don't use OffsetNewTab because when using non-persistent-order tab bar it is incremented with each Tab submission.
- else
- tab_pos.x += g.Style.ItemInnerSpacing.x + TabItemCalcSize(host_node->Windows[0]->Name, host_node->Windows[0]->HasCloseButton).x;
- }
- else if (!(host_window->Flags & ImGuiWindowFlags_DockNodeHost))
+ node->IsFocused = true;
+ if (tab_bar->Tabs.Size == 1)
{
- tab_pos.x += g.Style.ItemInnerSpacing.x + TabItemCalcSize(host_window->Name, host_window->HasCloseButton).x; // Account for slight offset which will be added when changing from title bar to tab bar
+ if (MenuItem("Hide tab bar", NULL, node->IsHiddenTabBar()))
+ node->WantHiddenTabBarToggle = true;
}
-
- // Draw tab shape/label preview (payload may be a loose window or a host window carrying multiple tabbed windows)
- if (root_payload->DockNodeAsHost)
- IM_ASSERT(root_payload->DockNodeAsHost->Windows.Size == root_payload->DockNodeAsHost->TabBar->Tabs.Size);
- const int payload_count = root_payload->DockNodeAsHost ? root_payload->DockNodeAsHost->TabBar->Tabs.Size : 1;
- for (int payload_n = 0; payload_n < payload_count; payload_n++)
+ else
{
- // Calculate the tab bounding box for each payload window
- ImGuiWindow* payload = root_payload->DockNodeAsHost ? root_payload->DockNodeAsHost->TabBar->Tabs[payload_n].Window : root_payload;
- if (!DockNodeIsDropAllowedOne(payload, host_window))
- continue;
-
- ImVec2 tab_size = TabItemCalcSize(payload->Name, payload->HasCloseButton);
- ImRect tab_bb(tab_pos.x, tab_pos.y, tab_pos.x + tab_size.x, tab_pos.y + tab_size.y);
- tab_pos.x += tab_size.x + g.Style.ItemInnerSpacing.x;
- for (int overlay_n = 0; overlay_n < overlay_draw_lists_count; overlay_n++)
+ for (int tab_n = 0; tab_n < tab_bar->Tabs.Size; tab_n++)
{
- ImGuiTabItemFlags tab_flags = ImGuiTabItemFlags_Preview | ((payload->Flags & ImGuiWindowFlags_UnsavedDocument) ? ImGuiTabItemFlags_UnsavedDocument : 0);
- if (!tab_bar_rect.Contains(tab_bb))
- overlay_draw_lists[overlay_n]->PushClipRect(tab_bar_rect.Min, tab_bar_rect.Max);
- TabItemBackground(overlay_draw_lists[overlay_n], tab_bb, tab_flags, overlay_col_tabs);
- TabItemLabelAndCloseButton(overlay_draw_lists[overlay_n], tab_bb, tab_flags, payload->Name, 0, 0);
- if (!tab_bar_rect.Contains(tab_bb))
- overlay_draw_lists[overlay_n]->PopClipRect();
+ ImGuiTabItem* tab = &tab_bar->Tabs[tab_n];
+ IM_ASSERT(tab->Window != NULL);
+ if (Selectable(tab->Window->Name, tab->ID == tab_bar->SelectedTabId))
+ ret_tab_id = tab->ID;
+ SameLine();
+ Text(" ");
}
}
+ EndPopup();
}
+ return ret_tab_id;
+}
- // Display drop boxes
- const float overlay_rounding = ImMax(3.0f, g.Style.FrameRounding);
- for (int dir = ImGuiDir_None; dir < ImGuiDir_COUNT; dir++)
+static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_window)
+{
+ ImGuiContext& g = *GImGui;
+ ImGuiStyle& style = g.Style;
+
+ const bool node_was_active = (node->LastFrameActive + 1 == g.FrameCount);
+ const bool closed_all = node->WantCloseAll && node_was_active;
+ const ImGuiID closed_one = node->WantCloseTabID && node_was_active;
+ node->WantCloseAll = false;
+ node->WantCloseTabID = 0;
+
+ // Decide if we should use a focused title bar color
+ bool is_focused = false;
+ ImGuiDockNode* root_node = DockNodeGetRootNode(node);
+ if (g.NavWindowingTarget)
+ is_focused = (g.NavWindowingTarget->DockNode == node);
+ else if (g.NavWindow && g.NavWindow->RootWindowForTitleBarHighlight == host_window->RootWindow && root_node->LastFocusedNodeID == node->ID)
+ is_focused = true;
+
+ // Hidden tab bar will show a triangle on the upper-left (in Begin)
+ if (node->IsHiddenTabBar() || node->IsNoTabBar())
{
- if (!data->DropRectsDraw[dir + 1].IsInverted())
+ node->VisibleWindow = (node->Windows.Size > 0) ? node->Windows[0] : NULL;
+ node->IsFocused = is_focused;
+ if (is_focused)
+ node->LastFrameFocused = g.FrameCount;
+ if (node->VisibleWindow)
{
- ImRect draw_r = data->DropRectsDraw[dir + 1];
- ImRect draw_r_in = draw_r;
- draw_r_in.Expand(-2.0f);
- ImU32 overlay_col = (data->SplitDir == (ImGuiDir)dir && data->IsSplitDirExplicit) ? overlay_col_drop_hovered : overlay_col_drop;
- for (int overlay_n = 0; overlay_n < overlay_draw_lists_count; overlay_n++)
- {
- ImVec2 center = ImFloor(draw_r_in.GetCenter());
- overlay_draw_lists[overlay_n]->AddRectFilled(draw_r.Min, draw_r.Max, overlay_col, overlay_rounding);
- overlay_draw_lists[overlay_n]->AddRect(draw_r_in.Min, draw_r_in.Max, overlay_col_lines, overlay_rounding);
- if (dir == ImGuiDir_Left || dir == ImGuiDir_Right)
- overlay_draw_lists[overlay_n]->AddLine(ImVec2(center.x, draw_r_in.Min.y), ImVec2(center.x, draw_r_in.Max.y), overlay_col_lines);
- if (dir == ImGuiDir_Up || dir == ImGuiDir_Down)
- overlay_draw_lists[overlay_n]->AddLine(ImVec2(draw_r_in.Min.x, center.y), ImVec2(draw_r_in.Max.x, center.y), overlay_col_lines);
- }
+ // Notify root of visible window (used to display title in OS task bar)
+ if (is_focused || root_node->VisibleWindow == NULL)
+ root_node->VisibleWindow = node->VisibleWindow;
+ if (node->TabBar)
+ node->TabBar->VisibleTabId = node->VisibleWindow->ID;
}
-
- // Stop after ImGuiDir_None
- if ((host_node && (host_node->Flags & ImGuiDockNodeFlags_NoSplit)) || g.IO.ConfigDockingNoSplit)
- return;
+ return;
}
-}
-
-//-----------------------------------------------------------------------------
-// Docking: ImGuiDockNode Tree manipulation functions
-//-----------------------------------------------------------------------------
-void ImGui::DockNodeTreeSplit(ImGuiContext* ctx, ImGuiDockNode* parent_node, ImGuiAxis split_axis, int split_inheritor_child_idx, float split_ratio, ImGuiDockNode* new_node)
-{
- IM_ASSERT(split_axis != ImGuiAxis_None);
+ // Move ourselves to the Menu layer (so we can be accessed by tapping Alt) + undo SkipItems flag in order to draw over the title bar even if the window is collapsed
+ bool backup_skip_item = host_window->SkipItems;
+ if (!node->IsDockSpace())
+ {
+ host_window->SkipItems = false;
+ host_window->DC.NavLayerCurrent = ImGuiNavLayer_Menu;
+ host_window->DC.NavLayerCurrentMask = (1 << ImGuiNavLayer_Menu);
+ }
- ImGuiDockNode* child_0 = (new_node && split_inheritor_child_idx != 0) ? new_node : DockContextAddNode(ctx, 0);
- child_0->ParentNode = parent_node;
+ // Use PushOverrideID() instead of PushID() to use the node id _without_ the host window ID.
+ // This is to facilitate computing those ID from the outside, and will affect more or less only the ID of the collapse button, popup and tabs,
+ // as docked windows themselves will override the stack with their own root ID.
+ PushOverrideID(node->ID);
+ ImGuiTabBar* tab_bar = node->TabBar;
+ bool tab_bar_is_recreated = (tab_bar == NULL); // Tab bar are automatically destroyed when a node gets hidden
+ if (tab_bar == NULL)
+ {
+ DockNodeAddTabBar(node);
+ tab_bar = node->TabBar;
+ }
- ImGuiDockNode* child_1 = (new_node && split_inheritor_child_idx != 1) ? new_node : DockContextAddNode(ctx, 0);
- child_1->ParentNode = parent_node;
+ ImGuiID focus_tab_id = 0;
+ node->IsFocused = is_focused;
- ImGuiDockNode* child_inheritor = (split_inheritor_child_idx == 0) ? child_0 : child_1;
- DockNodeMoveChildNodes(child_inheritor, parent_node);
- parent_node->ChildNodes[0] = child_0;
- parent_node->ChildNodes[1] = child_1;
- parent_node->ChildNodes[split_inheritor_child_idx]->VisibleWindow = parent_node->VisibleWindow;
- parent_node->SplitAxis = split_axis;
- parent_node->VisibleWindow = NULL;
+ const ImGuiDockNodeFlags node_flags = node->GetMergedFlags();
+ const bool has_window_menu_button = (node_flags & ImGuiDockNodeFlags_NoWindowMenuButton) == 0;
+ const bool has_close_button = (node_flags & ImGuiDockNodeFlags_NoCloseButton) == 0;
- float size_avail = (parent_node->Size[split_axis] - IMGUI_DOCK_SPLITTER_SIZE);
- IM_ASSERT(size_avail > 0.0f);
- child_0->SizeRef = child_1->SizeRef = parent_node->Size;
- child_0->SizeRef[split_axis] = ImFloor(size_avail * split_ratio);
- child_1->SizeRef[split_axis] = ImFloor(size_avail - child_0->SizeRef[split_axis]);
+ // In a dock node, the Collapse Button turns into the Window Menu button.
+ // FIXME-DOCK FIXME-OPT: Could we recycle popups id accross multiple dock nodes?
+ if (has_window_menu_button && IsPopupOpen("#WindowMenu"))
+ {
+ if (ImGuiID tab_id = DockNodeUpdateWindowMenu(node, tab_bar))
+ focus_tab_id = tab_bar->NextSelectedTabId = tab_id;
+ is_focused |= node->IsFocused;
+ }
- DockNodeMoveWindows(parent_node->ChildNodes[split_inheritor_child_idx], parent_node);
- DockNodeTreeUpdatePosSize(parent_node, parent_node->Pos, parent_node->Size);
+ // Layout
+ ImRect title_bar_rect, tab_bar_rect;
+ ImVec2 window_menu_button_pos;
+ DockNodeCalcTabBarLayout(node, &title_bar_rect, &tab_bar_rect, &window_menu_button_pos);
- child_inheritor->IsCentralNode = parent_node->IsCentralNode;
- child_inheritor->IsHiddenTabBar = parent_node->IsHiddenTabBar;
- parent_node->IsCentralNode = false;
-}
+ // Title bar
+ if (is_focused)
+ node->LastFrameFocused = g.FrameCount;
+ ImU32 title_bar_col = GetColorU32(host_window->Collapsed ? ImGuiCol_TitleBgCollapsed : is_focused ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBg);
+ host_window->DrawList->AddRectFilled(title_bar_rect.Min, title_bar_rect.Max, title_bar_col, host_window->WindowRounding, ImDrawCornerFlags_Top);
-void ImGui::DockNodeTreeMerge(ImGuiContext* ctx, ImGuiDockNode* parent_node, ImGuiDockNode* merge_lead_child)
-{
- // When called from DockContextProcessUndockNode() it is possible that one of the child is NULL.
- ImGuiDockNode* child_0 = parent_node->ChildNodes[0];
- ImGuiDockNode* child_1 = parent_node->ChildNodes[1];
- IM_ASSERT(child_0 || child_1);
- IM_ASSERT(merge_lead_child == child_0 || merge_lead_child == child_1);
- if ((child_0 && child_0->Windows.Size > 0) || (child_1 && child_1->Windows.Size > 0))
+ // Docking/Collapse button
+ if (has_window_menu_button)
{
- IM_ASSERT(parent_node->TabBar == NULL);
- IM_ASSERT(parent_node->Windows.Size == 0);
+ if (CollapseButton(host_window->GetID("#COLLAPSE"), window_menu_button_pos, node))
+ OpenPopup("#WindowMenu");
+ if (IsItemActive())
+ focus_tab_id = tab_bar->SelectedTabId;
}
- ImVec2 backup_last_explicit_size = parent_node->SizeRef;
- DockNodeMoveChildNodes(parent_node, merge_lead_child);
- if (child_0)
- {
- DockNodeMoveWindows(parent_node, child_0); // Generally only 1 of the 2 child node will have windows
- DockSettingsRenameNodeReferences(child_0->ID, parent_node->ID);
- }
- if (child_1)
+ // Submit new tabs and apply NavWindow focus back to the tab bar. They will be added as Unsorted and sorted below based on relative DockOrder value.
+ const int tabs_count_old = tab_bar->Tabs.Size;
+ for (int window_n = 0; window_n < node->Windows.Size; window_n++)
{
- DockNodeMoveWindows(parent_node, child_1);
- DockSettingsRenameNodeReferences(child_1->ID, parent_node->ID);
+ ImGuiWindow* window = node->Windows[window_n];
+ if (g.NavWindow && g.NavWindow->RootWindowDockStop == window)
+ tab_bar->SelectedTabId = window->ID;
+ if (TabBarFindTabByID(tab_bar, window->ID) == NULL)
+ TabBarAddTab(tab_bar, ImGuiTabItemFlags_Unsorted, window);
}
- DockNodeApplyPosSizeToWindows(parent_node);
- parent_node->AutorityForPos = parent_node->AutorityForSize = parent_node->AutorityForViewport = ImGuiDataAutority_Auto;
- parent_node->VisibleWindow = merge_lead_child->VisibleWindow;
- parent_node->IsCentralNode = (child_0 && child_0->IsCentralNode) || (child_1 && child_1->IsCentralNode);
- parent_node->IsHiddenTabBar = merge_lead_child->IsHiddenTabBar;
- parent_node->SizeRef = backup_last_explicit_size;
- if (child_0)
+ // If multiple tabs are appearing on the same frame, sort them based on their persistent DockOrder value
+ int tabs_unsorted_start = tab_bar->Tabs.Size;
+ for (int tab_n = tab_bar->Tabs.Size - 1; tab_n >= 0 && (tab_bar->Tabs[tab_n].Flags & ImGuiTabItemFlags_Unsorted); tab_n--)
{
- ctx->DockContext->Nodes.SetVoidPtr(child_0->ID, NULL);
- IM_DELETE(child_0);
+ // FIXME-DOCKING: Consider only clearing the flag after the tab has been alive for a few consecutive frames, allowing late comers to not break sorting?
+ tab_bar->Tabs[tab_n].Flags &= ~ImGuiTabItemFlags_Unsorted;
+ tabs_unsorted_start = tab_n;
}
- if (child_1)
+ if (tab_bar->Tabs.Size > tabs_unsorted_start)
{
- ctx->DockContext->Nodes.SetVoidPtr(child_1->ID, NULL);
- IM_DELETE(child_1);
+ IMGUI_DEBUG_LOG_DOCKING("In node 0x%08X: %d new appearing tabs:%s\n", node->ID, tab_bar->Tabs.Size - tabs_unsorted_start, (tab_bar->Tabs.Size > tabs_unsorted_start + 1) ? " (will sort)" : "");
+ for (int tab_n = tabs_unsorted_start; tab_n < tab_bar->Tabs.Size; tab_n++)
+ IMGUI_DEBUG_LOG_DOCKING(" - Tab '%s' Order %d\n", tab_bar->Tabs[tab_n].Window->Name, tab_bar->Tabs[tab_n].Window->DockOrder);
+ if (tab_bar->Tabs.Size > tabs_unsorted_start + 1)
+ ImQsort(tab_bar->Tabs.Data + tabs_unsorted_start, tab_bar->Tabs.Size - tabs_unsorted_start, sizeof(ImGuiTabItem), TabItemComparerByDockOrder);
}
-}
-// Update Pos/Size for a node hierarchy (don't affect child Windows yet)
-void ImGui::DockNodeTreeUpdatePosSize(ImGuiDockNode* node, ImVec2 pos, ImVec2 size)
-{
- node->Pos = pos;
- node->Size = size;
- if (node->IsLeafNode())
- return;
+ // Selected newly added tabs, or persistent tab ID if the tab bar was just recreated
+ if (tab_bar_is_recreated && TabBarFindTabByID(tab_bar, node->SelectedTabID) != NULL)
+ tab_bar->SelectedTabId = tab_bar->NextSelectedTabId = node->SelectedTabID;
+ else if (tab_bar->Tabs.Size > tabs_count_old)
+ tab_bar->SelectedTabId = tab_bar->NextSelectedTabId = tab_bar->Tabs.back().Window->ID;
- ImGuiDockNode* child_0 = node->ChildNodes[0];
- ImGuiDockNode* child_1 = node->ChildNodes[1];
- ImVec2 child_0_pos = pos, child_1_pos = pos;
- ImVec2 child_0_size = size, child_1_size = size;
- if (child_0->IsVisible && child_1->IsVisible)
+ // Begin tab bar
+ ImGuiTabBarFlags tab_bar_flags = ImGuiTabBarFlags_Reorderable | ImGuiTabBarFlags_AutoSelectNewTabs; // | ImGuiTabBarFlags_NoTabListScrollingButtons);
+ tab_bar_flags |= ImGuiTabBarFlags_SaveSettings | ImGuiTabBarFlags_DockNode;
+ if (!host_window->Collapsed && is_focused)
+ tab_bar_flags |= ImGuiTabBarFlags_IsFocused;
+ BeginTabBarEx(tab_bar, tab_bar_rect, tab_bar_flags, node);
+ //host_window->DrawList->AddRect(tab_bar_rect.Min, tab_bar_rect.Max, IM_COL32(255,0,255,255));
+
+ // Submit actual tabs
+ node->VisibleWindow = NULL;
+ for (int window_n = 0; window_n < node->Windows.Size; window_n++)
{
- const float spacing = IMGUI_DOCK_SPLITTER_SIZE;
- const ImGuiAxis axis = (ImGuiAxis)node->SplitAxis;
- const float size_avail = ImMax(size[axis] - spacing, 0.0f);
+ ImGuiWindow* window = node->Windows[window_n];
+ if ((closed_all || closed_one == window->ID) && window->HasCloseButton && !(window->Flags & ImGuiWindowFlags_UnsavedDocument))
+ continue;
+ if (window->LastFrameActive + 1 >= g.FrameCount || !node_was_active)
+ {
+ ImGuiTabItemFlags tab_item_flags = 0;
+ if (window->Flags & ImGuiWindowFlags_UnsavedDocument)
+ tab_item_flags |= ImGuiTabItemFlags_UnsavedDocument;
+ if (tab_bar->Flags & ImGuiTabBarFlags_NoCloseWithMiddleMouseButton)
+ tab_item_flags |= ImGuiTabItemFlags_NoCloseWithMiddleMouseButton;
- // Size allocation policy
- // 1) The first 0..WindowMinSize[axis]*2 are allocated evenly to both windows.
- ImGuiContext& g = *GImGui;
- const float size_min_each = ImFloor(ImMin(size_avail, g.Style.WindowMinSize[axis] * 2.0f) * 0.5f);
+ bool tab_open = true;
+ TabItemEx(tab_bar, window->Name, window->HasCloseButton ? &tab_open : NULL, tab_item_flags, window);
+ if (!tab_open)
+ node->WantCloseTabID = window->ID;
+ if (tab_bar->VisibleTabId == window->ID)
+ node->VisibleWindow = window;
- // 2) Process locked absolute size (during a splitter resize we preserve the child of nodes not touching the splitter edge)
- IM_ASSERT(!(child_0->WantLockSizeOnce && child_1->WantLockSizeOnce));
- if (child_0->WantLockSizeOnce)
- {
- child_0->WantLockSizeOnce = false;
- child_0_size[axis] = child_0->SizeRef[axis] = child_0->Size[axis];
- child_1_size[axis] = child_1->SizeRef[axis] = (size_avail - child_0_size[axis]);
+ // Store last item data so it can be queried with IsItemXXX functions after the user Begin() call
+ window->DockTabItemStatusFlags = host_window->DC.LastItemStatusFlags;
+ window->DockTabItemRect = host_window->DC.LastItemRect;
+ // Update navigation ID on menu layer
+ if (g.NavWindow && g.NavWindow->RootWindowDockStop == window && (window->DC.NavLayerActiveMask & (1 << 1)) == 0)
+ host_window->NavLastIds[1] = window->ID;
}
- else if (child_1->WantLockSizeOnce)
- {
- child_1->WantLockSizeOnce = false;
- child_1_size[axis] = child_1->SizeRef[axis] = child_1->Size[axis];
- child_0_size[axis] = child_0->SizeRef[axis] = (size_avail - child_1_size[axis]);
- }
+ }
- // 3) If one window is the central node (~ use remaining space, should be made explicit!), use explicit size from the other, and remainder for the central node
- else if (child_1->IsCentralNode && child_0->SizeRef[axis] != 0.0f)
- {
- child_0_size[axis] = ImMin(size_avail - size_min_each, child_0->SizeRef[axis]);
- child_1_size[axis] = (size_avail - child_0_size[axis]);
- }
- else if (child_0->IsCentralNode && child_1->SizeRef[axis] != 0.0f)
+ // Notify root of visible window (used to display title in OS task bar)
+ if (node->VisibleWindow)
+ if (is_focused || root_node->VisibleWindow == NULL)
+ root_node->VisibleWindow = node->VisibleWindow;
+
+ // Close button (after VisibleWindow was updated)
+ // Note that VisibleWindow may have been overrided by CTRL+Tabbing, so VisibleWindow->ID may be != from tab_bar->SelectedTabId
+ if (has_close_button && node->VisibleWindow)
+ {
+ if (!node->VisibleWindow->HasCloseButton)
{
- child_1_size[axis] = ImMin(size_avail - size_min_each, child_1->SizeRef[axis]);
- child_0_size[axis] = (size_avail - child_1_size[axis]);
+ PushItemFlag(ImGuiItemFlags_Disabled, true);
+ PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_Text] * ImVec4(1.0f,1.0f,1.0f,0.5f));
}
- else
+ const float button_sz = g.FontSize;
+ if (CloseButton(host_window->GetID("#CLOSE"), title_bar_rect.GetTR() + ImVec2(-style.FramePadding.x * 2.0f - button_sz, 0.0f)))
+ if (ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, tab_bar->VisibleTabId))
+ {
+ node->WantCloseTabID = tab->ID;
+ TabBarCloseTab(tab_bar, tab);
+ }
+ //if (IsItemActive())
+ // focus_tab_id = tab_bar->SelectedTabId;
+ if (!node->VisibleWindow->HasCloseButton)
{
- // 4) Otherwise distribute according to the relative ratio of each SizeRef value
- float split_ratio = child_0->SizeRef[axis] / (child_0->SizeRef[axis] + child_1->SizeRef[axis]);
- child_0_size[axis] = ImMax(size_min_each, ImFloor(size_avail * split_ratio + 0.5F));
- child_1_size[axis] = (size_avail - child_0_size[axis]);
+ PopStyleColor();
+ PopItemFlag();
}
- child_1_pos[axis] += spacing + child_0_size[axis];
}
- if (child_0->IsVisible)
- DockNodeTreeUpdatePosSize(child_0, child_0_pos, child_0_size);
- if (child_1->IsVisible)
- DockNodeTreeUpdatePosSize(child_1, child_1_pos, child_1_size);
-}
-static void DockNodeTreeUpdateSplitterFindTouchingNode(ImGuiDockNode* node, ImGuiAxis axis, int side, ImVector* touching_nodes)
-{
- if (node->IsLeafNode())
+ // When clicking on the title bar outside of tabs, we still focus the selected tab for that node
+ // FIXME: TabItem use AllowItemOverlap so we manually perform a more specific test for now (hovered || held)
+ ImGuiID title_bar_id = host_window->GetID("#TITLEBAR");
+ if (g.HoveredId == 0 || g.HoveredId == title_bar_id || g.ActiveId == title_bar_id)
{
- touching_nodes->push_back(node);
- return;
- }
- if (node->ChildNodes[0]->IsVisible)
- if (node->SplitAxis != axis || side == 0 || !node->ChildNodes[1]->IsVisible)
- DockNodeTreeUpdateSplitterFindTouchingNode(node->ChildNodes[0], axis, side, touching_nodes);
- if (node->ChildNodes[1]->IsVisible)
- if (node->SplitAxis != axis || side == 1 || !node->ChildNodes[0]->IsVisible)
- DockNodeTreeUpdateSplitterFindTouchingNode(node->ChildNodes[1], axis, side, touching_nodes);
-}
+ bool held;
+ ButtonBehavior(title_bar_rect, title_bar_id, NULL, &held);
+ if (held)
+ {
+ if (IsMouseClicked(0))
+ focus_tab_id = tab_bar->SelectedTabId;
-void ImGui::DockNodeTreeUpdateSplitter(ImGuiDockNode* node)
-{
- if (node->IsLeafNode())
- return;
+ // Forward moving request to selected window
+ if (ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, tab_bar->SelectedTabId))
+ StartMouseDragFromTitleBar(tab->Window, node, false);
+ }
+ }
- ImGuiContext& g = *GImGui;
+ // Forward focus from host node to selected window
+ //if (is_focused && g.NavWindow == host_window && !g.NavWindowingTarget)
+ // focus_tab_id = tab_bar->SelectedTabId;
- ImGuiDockNode* child_0 = node->ChildNodes[0];
- ImGuiDockNode* child_1 = node->ChildNodes[1];
- if (child_0->IsVisible && child_1->IsVisible)
- {
- // Bounding box of the splitter cover the space between both nodes (w = Spacing, h = Size[xy^1] for when splitting horizontally)
- const ImGuiAxis axis = (ImGuiAxis)node->SplitAxis;
- IM_ASSERT(axis != ImGuiAxis_None);
- ImRect bb;
- bb.Min = child_0->Pos;
- bb.Max = child_1->Pos;
- bb.Min[axis] += child_0->Size[axis];
- bb.Max[axis ^ 1] += child_1->Size[axis ^ 1];
- //if (g.IO.KeyCtrl) GetOverlayDrawList(g.CurrentWindow->Viewport)->AddRect(bb.Min, bb.Max, IM_COL32(255,0,255,255));
+ // When clicked on a tab we requested focus to the docked child
+ // This overrides the value set by "forward focus from host node to selected window".
+ if (tab_bar->NextSelectedTabId)
+ focus_tab_id = tab_bar->NextSelectedTabId;
- if (node->Flags & ImGuiDockNodeFlags_NoResize)
+ // Apply navigation focus
+ if (focus_tab_id != 0)
+ if (ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, focus_tab_id))
{
- ImGuiWindow* window = g.CurrentWindow;
- window->DrawList->AddRectFilled(bb.Min, bb.Max, GetColorU32(ImGuiCol_Separator), g.Style.FrameRounding);
+ FocusWindow(tab->Window);
+ NavInitWindow(tab->Window, false);
}
- else
- {
- //bb.Min[axis] += 1; // Display a little inward so highlight doesn't connect with nearby tabs on the neighbor node.
- //bb.Max[axis] -= 1;
- PushID(node->ID);
-
- // Gather list of nodes that are touching the splitter line. Find resizing limits based on those nodes.
- ImVector touching_nodes[2];
- float min_size = g.Style.WindowMinSize[axis];
- float resize_limits[2];
- resize_limits[0] = node->ChildNodes[0]->Pos[axis] + min_size;
- resize_limits[1] = node->ChildNodes[1]->Pos[axis] + node->ChildNodes[1]->Size[axis] - min_size;
-
- ImGuiID splitter_id = GetID("##Splitter");
- if (g.ActiveId == splitter_id)
- {
- // Only process when splitter is active
- DockNodeTreeUpdateSplitterFindTouchingNode(child_0, axis, 1, &touching_nodes[0]);
- DockNodeTreeUpdateSplitterFindTouchingNode(child_1, axis, 0, &touching_nodes[1]);
- for (int touching_node_n = 0; touching_node_n < touching_nodes[0].Size; touching_node_n++)
- resize_limits[0] = ImMax(resize_limits[0], touching_nodes[0][touching_node_n]->Rect().Min[axis] + min_size);
- for (int touching_node_n = 0; touching_node_n < touching_nodes[1].Size; touching_node_n++)
- resize_limits[1] = ImMin(resize_limits[1], touching_nodes[1][touching_node_n]->Rect().Max[axis] - min_size);
-
- /*
- // [DEBUG] Render limits
- ImDrawList* draw_list = node->HostWindow ? GetOverlayDrawList(node->HostWindow) : GetOverlayDrawList((ImGuiViewportP*)GetMainViewport());
- for (int n = 0; n < 2; n++)
- if (axis == ImGuiAxis_X)
- draw_list->AddLine(ImVec2(resize_limits[n], node->ChildNodes[n]->Pos.y), ImVec2(resize_limits[n], node->ChildNodes[n]->Pos.y + node->ChildNodes[n]->Size.y), IM_COL32(255, 0, 255, 255), 3.0f);
- else
- draw_list->AddLine(ImVec2(node->ChildNodes[n]->Pos.x, resize_limits[n]), ImVec2(node->ChildNodes[n]->Pos.x + node->ChildNodes[n]->Size.x, resize_limits[n]), IM_COL32(255, 0, 255, 255), 3.0f);
- */
- }
-
- // Use a short delay before highlighting the splitter (and changing the mouse cursor) in order for regular mouse movement to not highlight many splitters
- float cur_size_0 = child_0->Size[axis];
- float cur_size_1 = child_1->Size[axis];
- float min_size_0 = resize_limits[0] - child_0->Pos[axis];
- float min_size_1 = child_1->Pos[axis] + child_1->Size[axis] - resize_limits[1];
- if (SplitterBehavior(bb, GetID("##Splitter"), axis, &cur_size_0, &cur_size_1, min_size_0, min_size_1, WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS, WINDOWS_RESIZE_FROM_EDGES_FEEDBACK_TIMER))
- {
- if (touching_nodes[0].Size > 0 && touching_nodes[1].Size > 0)
- {
- child_0->Size[axis] = child_0->SizeRef[axis] = cur_size_0;
- child_1->Pos[axis] -= cur_size_1 - child_1->Size[axis];
- child_1->Size[axis] = child_1->SizeRef[axis] = cur_size_1;
- // Lock the size of every node that is a sibling of the node we are touching
- // This might be less desirable if we can merge sibling of a same axis into the same parental level.
-#if 1
- for (int side_n = 0; side_n < 2; side_n++)
- for (int touching_node_n = 0; touching_node_n < touching_nodes[side_n].Size; touching_node_n++)
- {
- ImGuiDockNode* touching_node = touching_nodes[side_n][touching_node_n];
- //ImDrawList* draw_list = node->HostWindow ? GetOverlayDrawList(node->HostWindow) : GetOverlayDrawList((ImGuiViewportP*)GetMainViewport());
- //draw_list->AddRect(touching_node->Pos, touching_node->Pos + touching_node->Size, IM_COL32(255, 128, 0, 255));
- while (touching_node->ParentNode != node)
- {
- if (touching_node->ParentNode->SplitAxis == axis)
- {
- // Mark other node so its size will be preserved during the upcoming call to DockNodeTreeUpdatePosSize().
- ImGuiDockNode* node_to_preserve = touching_node->ParentNode->ChildNodes[side_n];
- node_to_preserve->WantLockSizeOnce = true;
- //draw_list->AddRect(touching_node->Pos, touching_node->Rect().Max, IM_COL32(255, 0, 0, 255));
- //draw_list->AddRectFilled(node_to_preserve->Pos, node_to_preserve->Rect().Max, IM_COL32(0, 255, 0, 100));
- }
- touching_node = touching_node->ParentNode;
- }
- }
-#endif
+ EndTabBar();
+ PopID();
- DockNodeTreeUpdatePosSize(child_0, child_0->Pos, child_0->Size);
- DockNodeTreeUpdatePosSize(child_1, child_1->Pos, child_1->Size);
- MarkIniSettingsDirty();
- }
- }
- PopID();
- }
+ // Restore SkipItems flag
+ if (!node->IsDockSpace())
+ {
+ host_window->DC.NavLayerCurrent = ImGuiNavLayer_Main;
+ host_window->DC.NavLayerCurrentMask = (1 << ImGuiNavLayer_Main);
+ host_window->SkipItems = backup_skip_item;
}
+}
- if (child_0->IsVisible)
- DockNodeTreeUpdateSplitter(child_0);
- if (child_1->IsVisible)
- DockNodeTreeUpdateSplitter(child_1);
+static void ImGui::DockNodeAddTabBar(ImGuiDockNode* node)
+{
+ IM_ASSERT(node->TabBar == NULL);
+ node->TabBar = IM_NEW(ImGuiTabBar);
}
-ImGuiDockNode* ImGui::DockNodeTreeFindFallbackLeafNode(ImGuiDockNode* node)
+static void ImGui::DockNodeRemoveTabBar(ImGuiDockNode* node)
{
- if (node->IsLeafNode())
- return node;
- if (ImGuiDockNode* leaf_node = DockNodeTreeFindFallbackLeafNode(node->ChildNodes[0]))
- return leaf_node;
- if (ImGuiDockNode* leaf_node = DockNodeTreeFindFallbackLeafNode(node->ChildNodes[1]))
- return leaf_node;
- return NULL;
+ if (node->TabBar == NULL)
+ return;
+ IM_DELETE(node->TabBar);
+ node->TabBar = NULL;
}
-ImGuiDockNode* ImGui::DockNodeTreeFindNodeByPos(ImGuiDockNode* node, ImVec2 pos)
+static bool DockNodeIsDropAllowedOne(ImGuiWindow* payload, ImGuiWindow* host_window)
{
- if (!node->IsVisible)
- return NULL;
+ if (host_window->DockNodeAsHost && host_window->DockNodeAsHost->IsDockSpace() && payload->BeginOrderWithinContext < host_window->BeginOrderWithinContext)
+ return false;
- ImGuiContext& g = *GImGui;
- const float dock_spacing = g.Style.ItemInnerSpacing.x;
- ImRect r(node->Pos, node->Pos + node->Size);
- r.Expand(dock_spacing * 0.5f);
- bool inside = r.Contains(pos);
- if (!inside)
- return NULL;
+ ImGuiWindowClass* host_class = host_window->DockNodeAsHost ? &host_window->DockNodeAsHost->WindowClass : &host_window->WindowClass;
+ ImGuiWindowClass* payload_class = &payload->WindowClass;
+ if (host_class->ClassId != payload_class->ClassId)
+ {
+ if (host_class->ClassId != 0 && host_class->DockingAllowUnclassed && payload_class->ClassId == 0)
+ return true;
+ if (payload_class->ClassId != 0 && payload_class->DockingAllowUnclassed && host_class->ClassId == 0)
+ return true;
+ return false;
+ }
- if (node->IsLeafNode())
- return node;
- if (ImGuiDockNode* hovered_node = DockNodeTreeFindNodeByPos(node->ChildNodes[0], pos))
- return hovered_node;
- if (ImGuiDockNode* hovered_node = DockNodeTreeFindNodeByPos(node->ChildNodes[1], pos))
- return hovered_node;
+ return true;
+}
- // There is an edge case when docking into a dockspace which only has inactive nodes (because none of the windows are active)
- // In this case we need to fallback into any leaf mode, possibly the central node.
- if (node->IsDockSpace() && node->IsRootNode())
+static bool ImGui::DockNodeIsDropAllowed(ImGuiWindow* host_window, ImGuiWindow* root_payload)
+{
+ if (root_payload->DockNodeAsHost && root_payload->DockNodeAsHost->IsSplitNode())
+ return true;
+
+ const int payload_count = root_payload->DockNodeAsHost ? root_payload->DockNodeAsHost->Windows.Size : 1;
+ for (int payload_n = 0; payload_n < payload_count; payload_n++)
{
- if (node->CentralNode && node->IsLeafNode()) // FIXME-20181220: We should not have to test for IsLeafNode() here but we have another bug to fix first.
- return node->CentralNode;
- return DockNodeTreeFindFallbackLeafNode(node);
+ ImGuiWindow* payload = root_payload->DockNodeAsHost ? root_payload->DockNodeAsHost->Windows[payload_n] : root_payload;
+ if (DockNodeIsDropAllowedOne(payload, host_window))
+ return true;
}
-
- return NULL;
+ return false;
}
-//-----------------------------------------------------------------------------
-// Docking: Public Functions (SetWindowDock, DockSpace, DockSpaceOverViewport)
-//-----------------------------------------------------------------------------
-
-void ImGui::SetWindowDock(ImGuiWindow* window, ImGuiID dock_id, ImGuiCond cond)
+// window menu button == collapse button when not in a dock node.
+// FIXME: This is similar to RenderWindowTitleBarContents, may want to share code.
+static void ImGui::DockNodeCalcTabBarLayout(const ImGuiDockNode* node, ImRect* out_title_rect, ImRect* out_tab_bar_rect, ImVec2* out_window_menu_button_pos)
{
- // Test condition (NB: bit 0 is always true) and clear flags for next time
- if (cond && (window->SetWindowDockAllowFlags & cond) == 0)
- return;
- window->SetWindowDockAllowFlags &= ~(ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing);
+ ImGuiContext& g = *GImGui;
+ ImRect r = ImRect(node->Pos.x, node->Pos.y, node->Pos.x + node->Size.x, node->Pos.y + g.FontSize + g.Style.FramePadding.y * 2.0f);
+ if (out_title_rect) { *out_title_rect = r; }
- if (window->DockId == dock_id)
- return;
+ ImVec2 window_menu_button_pos = r.Min;
+ r.Min.x += g.Style.FramePadding.x;
+ r.Max.x -= g.Style.FramePadding.x;
+ if (node->HasCloseButton)
+ {
+ r.Max.x -= g.FontSize;// +1.0f; // In DockNodeUpdateTabBar() we currently display a disabled close button even if there is none.
+ }
+ if (node->HasWindowMenuButton && g.Style.WindowMenuButtonPosition == ImGuiDir_Left)
+ {
+ r.Min.x += g.FontSize; // + g.Style.ItemInnerSpacing.x; // <-- Adding ItemInnerSpacing makes the title text moves slightly when in a docking tab bar. Instead we adjusted RenderArrowDockMenu()
+ }
+ else if (node->HasWindowMenuButton && g.Style.WindowMenuButtonPosition == ImGuiDir_Right)
+ {
+ r.Max.x -= g.FontSize + g.Style.FramePadding.x;
+ window_menu_button_pos = ImVec2(r.Max.x, r.Min.y);
+ }
+ if (out_tab_bar_rect) { *out_tab_bar_rect = r; }
+ if (out_window_menu_button_pos) { *out_window_menu_button_pos = window_menu_button_pos; }
+}
- // If the user attempt to set a dock id that is a split node, we'll dig within to find a suitable docking spot
- ImGuiContext* ctx = GImGui;
- if (ImGuiDockNode* new_node = DockContextFindNodeByID(ctx, dock_id))
- if (new_node->IsSplitNode())
- {
- // Policy: Find central node or latest focused node. We first move back to our root node.
- new_node = DockNodeGetRootNode(new_node);
- if (new_node->CentralNode)
- dock_id = new_node->CentralNode->ID;
- else
- dock_id = new_node->LastFocusedNodeID;
- }
+void ImGui::DockNodeCalcSplitRects(ImVec2& pos_old, ImVec2& size_old, ImVec2& pos_new, ImVec2& size_new, ImGuiDir dir, ImVec2 size_new_desired)
+{
+ ImGuiContext& g = *GImGui;
+ const float dock_spacing = g.Style.ItemInnerSpacing.x;
+ const ImGuiAxis axis = (dir == ImGuiDir_Left || dir == ImGuiDir_Right) ? ImGuiAxis_X : ImGuiAxis_Y;
+ pos_new[axis ^ 1] = pos_old[axis ^ 1];
+ size_new[axis ^ 1] = size_old[axis ^ 1];
- if (window->DockId == dock_id)
- return;
+ // Distribute size on given axis (with a desired size or equally)
+ const float w_avail = size_old[axis] - dock_spacing;
+ if (size_new_desired[axis] > 0.0f && size_new_desired[axis] <= w_avail * 0.5f)
+ {
+ size_new[axis] = size_new_desired[axis];
+ size_old[axis] = (float)(int)(w_avail - size_new[axis]);
+ }
+ else
+ {
+ size_new[axis] = (float)(int)(w_avail * 0.5f);
+ size_old[axis] = (float)(int)(w_avail - size_new[axis]);
+ }
- if (window->DockNode)
- DockNodeRemoveWindow(window->DockNode, window, 0);
- window->DockId = dock_id;
+ // Position each node
+ if (dir == ImGuiDir_Right || dir == ImGuiDir_Down)
+ {
+ pos_new[axis] = pos_old[axis] + size_old[axis] + dock_spacing;
+ }
+ else if (dir == ImGuiDir_Left || dir == ImGuiDir_Up)
+ {
+ pos_new[axis] = pos_old[axis];
+ pos_old[axis] = pos_new[axis] + size_new[axis] + dock_spacing;
+ }
}
-// Create an explicit dockspace node within an existing window. Also expose dock node flags and creates a CentralNode by default.
-// The Central Node is always displayed even when empty and shrink/extend according to the requested size of its neighbors.
-void ImGui::DockSpace(ImGuiID id, const ImVec2& size_arg, ImGuiDockNodeFlags dockspace_flags, const ImGuiWindowClass* window_class)
+// Retrieve the drop rectangles for a given direction or for the center + perform hit testing.
+bool ImGui::DockNodeCalcDropRectsAndTestMousePos(const ImRect& parent, ImGuiDir dir, ImRect& out_r, bool outer_docking, ImVec2* test_mouse_pos)
{
- ImGuiContext* ctx = GImGui;
- ImGuiContext& g = *ctx;
- ImGuiWindow* window = GetCurrentWindow();
- if (!(g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable))
- return;
+ ImGuiContext& g = *GImGui;
- ImGuiDockNode* node = DockContextFindNodeByID(ctx, id);
- if (!node)
+ const float parent_smaller_axis = ImMin(parent.GetWidth(), parent.GetHeight());
+ const float hs_for_central_nodes = ImMin(g.FontSize * 1.5f, ImMax(g.FontSize * 0.5f, parent_smaller_axis / 8.0f));
+ float hs_w; // Half-size, longer axis
+ float hs_h; // Half-size, smaller axis
+ ImVec2 off; // Distance from edge or center
+ if (outer_docking)
{
- node = DockContextAddNode(ctx, id);
- node->IsCentralNode = true;
+ //hs_w = ImFloor(ImClamp(parent_smaller_axis - hs_for_central_nodes * 4.0f, g.FontSize * 0.5f, g.FontSize * 8.0f));
+ //hs_h = ImFloor(hs_w * 0.15f);
+ //off = ImVec2(ImFloor(parent.GetWidth() * 0.5f - GetFrameHeightWithSpacing() * 1.4f - hs_h), ImFloor(parent.GetHeight() * 0.5f - GetFrameHeightWithSpacing() * 1.4f - hs_h));
+ hs_w = ImFloor(hs_for_central_nodes * 1.50f);
+ hs_h = ImFloor(hs_for_central_nodes * 0.80f);
+ off = ImVec2(ImFloor(parent.GetWidth() * 0.5f - GetFrameHeightWithSpacing() * 0.0f - hs_h), ImFloor(parent.GetHeight() * 0.5f - GetFrameHeightWithSpacing() * 0.0f - hs_h));
}
- node->Flags = dockspace_flags;
- node->WindowClass = window_class ? *window_class : ImGuiWindowClass();
-
- // When a Dockspace transitioned form implicit to explicit this may be called a second time
- // It is possible that the node has already been claimed by a docked window which appeared before the DockSpace() node, so we overwrite IsDockSpace again.
- if (node->LastFrameActive == g.FrameCount && !(dockspace_flags & ImGuiDockNodeFlags_KeepAliveOnly))
+ else
{
- IM_ASSERT(node->IsDockSpace() == false && "Cannot call DockSpace() twice a frame with the same ID");
- node->Flags |= ImGuiDockNodeFlags_Dockspace;
- return;
+ hs_w = ImFloor(hs_for_central_nodes);
+ hs_h = ImFloor(hs_for_central_nodes * 0.90f);
+ off = ImVec2(ImFloor(hs_w * 2.40f), ImFloor(hs_w * 2.40f));
}
- node->Flags |= ImGuiDockNodeFlags_Dockspace;
- // Keep alive mode, this is allow windows docked into this node so stay docked even if they are not visible
- if (dockspace_flags & ImGuiDockNodeFlags_KeepAliveOnly)
+ ImVec2 c = ImFloor(parent.GetCenter());
+ if (dir == ImGuiDir_None) { out_r = ImRect(c.x - hs_w, c.y - hs_w, c.x + hs_w, c.y + hs_w); }
+ else if (dir == ImGuiDir_Up) { out_r = ImRect(c.x - hs_w, c.y - off.y - hs_h, c.x + hs_w, c.y - off.y + hs_h); }
+ else if (dir == ImGuiDir_Down) { out_r = ImRect(c.x - hs_w, c.y + off.y - hs_h, c.x + hs_w, c.y + off.y + hs_h); }
+ else if (dir == ImGuiDir_Left) { out_r = ImRect(c.x - off.x - hs_h, c.y - hs_w, c.x - off.x + hs_h, c.y + hs_w); }
+ else if (dir == ImGuiDir_Right) { out_r = ImRect(c.x + off.x - hs_h, c.y - hs_w, c.x + off.x + hs_h, c.y + hs_w); }
+
+ if (test_mouse_pos == NULL)
+ return false;
+
+ ImRect hit_r = out_r;
+ if (!outer_docking)
{
- node->LastFrameAlive = g.FrameCount;
- return;
+ // Custom hit testing for the 5-way selection, designed to reduce flickering when moving diagonally between sides
+ hit_r.Expand(ImFloor(hs_w * 0.30f));
+ ImVec2 mouse_delta = (*test_mouse_pos - c);
+ float mouse_delta_len2 = ImLengthSqr(mouse_delta);
+ float r_threshold_center = hs_w * 1.4f;
+ float r_threshold_sides = hs_w * (1.4f + 1.2f);
+ if (mouse_delta_len2 < r_threshold_center * r_threshold_center)
+ return (dir == ImGuiDir_None);
+ if (mouse_delta_len2 < r_threshold_sides * r_threshold_sides)
+ return (dir == ImGetDirQuadrantFromDelta(mouse_delta.x, mouse_delta.y));
}
+ return hit_r.Contains(*test_mouse_pos);
+}
- const ImVec2 content_avail = GetContentRegionAvail();
- ImVec2 size = ImFloor(size_arg);
- if (size.x <= 0.0f)
- size.x = ImMax(content_avail.x + size.x, 4.0f); // Arbitrary minimum child size (0.0f causing too much issues)
- if (size.y <= 0.0f)
- size.y = ImMax(content_avail.y + size.y, 4.0f);
+// host_node may be NULL if the window doesn't have a DockNode already.
+static void ImGui::DockNodePreviewDockCalc(ImGuiWindow* host_window, ImGuiDockNode* host_node, ImGuiWindow* root_payload, ImGuiDockPreviewData* data, bool is_explicit_target, bool is_outer_docking)
+{
+ ImGuiContext& g = *GImGui;
- node->Pos = window->DC.CursorPos;
- node->Size = node->SizeRef = size;
- SetNextWindowPos(node->Pos);
- SetNextWindowSize(node->Size);
- g.NextWindowData.PosUndock = false;
+ // There is an edge case when docking into a dockspace which only has inactive nodes.
+ // In this case DockNodeTreeFindNodeByPos() will have selected a leaf node which is inactive.
+ // Because the inactive leaf node doesn't have proper pos/size yet, we'll use the root node as reference.
+ ImGuiDockNode* ref_node_for_rect = (host_node && !host_node->IsVisible) ? DockNodeGetRootNode(host_node) : host_node;
+ if (ref_node_for_rect)
+ IM_ASSERT(ref_node_for_rect->IsVisible);
- ImGuiWindowFlags window_flags = ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_DockNodeHost;
- window_flags |= ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar;
- window_flags |= ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse;
+ // Build a tentative future node (reuse same structure because it is practical)
+ data->FutureNode.HasCloseButton = (host_node ? host_node->HasCloseButton : host_window->HasCloseButton) || (root_payload->HasCloseButton);
+ data->FutureNode.HasWindowMenuButton = host_node ? true : ((host_window->Flags & ImGuiWindowFlags_NoCollapse) == 0);
+ data->FutureNode.Pos = host_node ? ref_node_for_rect->Pos : host_window->Pos;
+ data->FutureNode.Size = host_node ? ref_node_for_rect->Size : host_window->Size;
- char title[256];
- ImFormatString(title, IM_ARRAYSIZE(title), "%s/DockSpace_%08X", window->Name, id);
+ // Figure out here we are allowed to dock
+ ImGuiDockNodeFlags host_node_flags = host_node ? host_node->GetMergedFlags() : 0;
+ const bool src_is_visibly_splitted = root_payload->DockNodeAsHost && root_payload->DockNodeAsHost->IsSplitNode() && (root_payload->DockNodeAsHost->OnlyNodeWithWindows == NULL);
+ data->IsCenterAvailable = !is_outer_docking;
+ if (src_is_visibly_splitted && (!host_node || !host_node->IsEmpty()))
+ data->IsCenterAvailable = false;
+ if (host_node && (host_node_flags & ImGuiDockNodeFlags_NoDockingInCentralNode) && host_node->IsCentralNode())
+ data->IsCenterAvailable = false;
- if (node->Windows.Size > 0 || node->IsSplitNode())
- PushStyleColor(ImGuiCol_ChildBg, IM_COL32(0, 0, 0, 0));
- PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0.0f);
- Begin(title, NULL, window_flags);
- PopStyleVar();
- if (node->Windows.Size > 0 || node->IsSplitNode())
- PopStyleColor();
+ data->IsSidesAvailable = true;
+ if ((host_node && (host_node_flags & ImGuiDockNodeFlags_NoSplit)) || g.IO.ConfigDockingNoSplit)
+ data->IsSidesAvailable = false;
+ if (!is_outer_docking && host_node && host_node->ParentNode == NULL && host_node->IsCentralNode())
+ data->IsSidesAvailable = false;
- ImGuiWindow* host_window = g.CurrentWindow;
- host_window->DockNodeAsHost = node;
- host_window->ChildId = window->GetID(title);
- node->HostWindow = host_window;
- node->OnlyNodeWithWindows = NULL;
+ // Calculate drop shapes geometry for allowed splitting directions
+ IM_ASSERT(ImGuiDir_None == -1);
+ data->SplitNode = host_node;
+ data->SplitDir = ImGuiDir_None;
+ data->IsSplitDirExplicit = false;
+ if (!host_window->Collapsed)
+ for (int dir = ImGuiDir_None; dir < ImGuiDir_COUNT; dir++)
+ {
+ if (dir == ImGuiDir_None && !data->IsCenterAvailable)
+ continue;
+ if (dir != ImGuiDir_None && !data->IsSidesAvailable)
+ continue;
+ if (DockNodeCalcDropRectsAndTestMousePos(data->FutureNode.Rect(), (ImGuiDir)dir, data->DropRectsDraw[dir+1], is_outer_docking, &g.IO.MousePos))
+ {
+ data->SplitDir = (ImGuiDir)dir;
+ data->IsSplitDirExplicit = true;
+ }
+ }
+
+ // When docking without holding Shift, we only allow and preview docking when hovering over a drop rect or over the title bar
+ data->IsDropAllowed = (data->SplitDir != ImGuiDir_None) || (data->IsCenterAvailable);
+ if (!is_explicit_target && !data->IsSplitDirExplicit && !g.IO.ConfigDockingWithShift)
+ data->IsDropAllowed = false;
- IM_ASSERT(node->IsRootNode());
- DockNodeUpdate(node);
+ // Calculate split area
+ data->SplitRatio = 0.0f;
+ if (data->SplitDir != ImGuiDir_None)
+ {
+ ImGuiDir split_dir = data->SplitDir;
+ ImGuiAxis split_axis = (split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Right) ? ImGuiAxis_X : ImGuiAxis_Y;
+ ImVec2 pos_new, pos_old = data->FutureNode.Pos;
+ ImVec2 size_new, size_old = data->FutureNode.Size;
+ DockNodeCalcSplitRects(pos_old, size_old, pos_new, size_new, split_dir, root_payload->Size);
- End();
+ // Calculate split ratio so we can pass it down the docking request
+ float split_ratio = ImSaturate(size_new[split_axis] / data->FutureNode.Size[split_axis]);
+ data->FutureNode.Pos = pos_new;
+ data->FutureNode.Size = size_new;
+ data->SplitRatio = (split_dir == ImGuiDir_Right || split_dir == ImGuiDir_Down) ? (1.0f - split_ratio) : (split_ratio);
+ }
}
-// Tips: Use with ImGuiDockNodeFlags_PassthruDockspace!
-// The limitation with this call is that your window won't have a menu bar.
-// Even though we could pass window flags, it would also require the user to be able to call BeginMenuBar() somehow meaning we can't Begin/End in a single function.
-// So if you want a menu bar you need to repeat this code manually ourselves. As with advanced other Docking API, we may change this function signature.
-ImGuiID ImGui::DockSpaceOverViewport(ImGuiViewport* viewport, ImGuiDockNodeFlags dockspace_flags, const ImGuiWindowClass* window_class)
+static void ImGui::DockNodePreviewDockRender(ImGuiWindow* host_window, ImGuiDockNode* host_node, ImGuiWindow* root_payload, const ImGuiDockPreviewData* data)
{
- if (viewport == NULL)
- viewport = GetMainViewport();
-
- SetNextWindowPos(viewport->Pos);
- SetNextWindowSize(viewport->Size);
- SetNextWindowViewport(viewport->ID);
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(g.CurrentWindow == host_window); // Because we rely on font size to calculate tab sizes
- ImGuiWindowFlags host_window_flags = 0;
- host_window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDocking;
- host_window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;
- if (dockspace_flags & ImGuiDockNodeFlags_PassthruDockspace)
- host_window_flags |= ImGuiWindowFlags_NoBackground;
+ // With this option, we only display the preview on the target viewport, and the payload viewport is made transparent.
+ // To compensate for the single layer obstructed by the payload, we'll increase the alpha of the preview nodes.
+ const bool is_transparent_payload = g.IO.ConfigDockingTransparentPayload;
- char label[32];
- ImFormatString(label, IM_ARRAYSIZE(label), "DockspaceViewport_%08X", viewport->ID);
+ // In case the two windows involved are on different viewports, we will draw the overlay on each of them.
+ int overlay_draw_lists_count = 0;
+ ImDrawList* overlay_draw_lists[2];
+ overlay_draw_lists[overlay_draw_lists_count++] = GetForegroundDrawList(host_window->Viewport);
+ if (host_window->Viewport != root_payload->Viewport && !is_transparent_payload)
+ overlay_draw_lists[overlay_draw_lists_count++] = GetForegroundDrawList(root_payload->Viewport);
- PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
- PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
- PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
- Begin(label, NULL, host_window_flags);
- PopStyleVar(3);
+ // Draw main preview rectangle
+ const ImU32 overlay_col_tabs = GetColorU32(ImGuiCol_TabActive);
+ const ImU32 overlay_col_main = GetColorU32(ImGuiCol_DockingPreview, is_transparent_payload ? 0.60f : 0.40f);
+ const ImU32 overlay_col_drop = GetColorU32(ImGuiCol_DockingPreview, is_transparent_payload ? 0.90f : 0.70f);
+ const ImU32 overlay_col_drop_hovered = GetColorU32(ImGuiCol_DockingPreview, is_transparent_payload ? 1.20f : 1.00f);
+ const ImU32 overlay_col_lines = GetColorU32(ImGuiCol_NavWindowingHighlight, is_transparent_payload ? 0.80f : 0.60f);
- ImGuiID dockspace_id = GetID("Dockspace");
- DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags, window_class);
- End();
+ // Display area preview
+ const bool can_preview_tabs = (root_payload->DockNodeAsHost == NULL || root_payload->DockNodeAsHost->Windows.Size > 0);
+ if (data->IsDropAllowed)
+ {
+ ImRect overlay_rect = data->FutureNode.Rect();
+ if (data->SplitDir == ImGuiDir_None && can_preview_tabs)
+ overlay_rect.Min.y += GetFrameHeight();
+ if (data->SplitDir != ImGuiDir_None || data->IsCenterAvailable)
+ for (int overlay_n = 0; overlay_n < overlay_draw_lists_count; overlay_n++)
+ overlay_draw_lists[overlay_n]->AddRectFilled(overlay_rect.Min, overlay_rect.Max, overlay_col_main, host_window->WindowRounding);
+ }
- return dockspace_id;
-}
+ // Display tab shape/label preview unless we are splitting node (it generally makes the situation harder to read)
+ if (data->IsDropAllowed && can_preview_tabs && data->SplitDir == ImGuiDir_None && data->IsCenterAvailable)
+ {
+ // Compute target tab bar geometry so we can locate our preview tabs
+ ImRect tab_bar_rect;
+ DockNodeCalcTabBarLayout(&data->FutureNode, NULL, &tab_bar_rect, NULL);
+ ImVec2 tab_pos = tab_bar_rect.Min;
+ if (host_node && host_node->TabBar)
+ {
+ if (!host_node->IsHiddenTabBar() && !host_node->IsNoTabBar())
+ tab_pos.x += host_node->TabBar->OffsetMax + g.Style.ItemInnerSpacing.x; // We don't use OffsetNewTab because when using non-persistent-order tab bar it is incremented with each Tab submission.
+ else
+ tab_pos.x += g.Style.ItemInnerSpacing.x + TabItemCalcSize(host_node->Windows[0]->Name, host_node->Windows[0]->HasCloseButton).x;
+ }
+ else if (!(host_window->Flags & ImGuiWindowFlags_DockNodeHost))
+ {
+ tab_pos.x += g.Style.ItemInnerSpacing.x + TabItemCalcSize(host_window->Name, host_window->HasCloseButton).x; // Account for slight offset which will be added when changing from title bar to tab bar
+ }
-//-----------------------------------------------------------------------------
-// Docking: Builder Functions
-//-----------------------------------------------------------------------------
-// Very early end-user API to manipulate dock nodes.
-// It is expected that those functions are all called _before_ the dockspace node submission.
-//-----------------------------------------------------------------------------
+ // Draw tab shape/label preview (payload may be a loose window or a host window carrying multiple tabbed windows)
+ if (root_payload->DockNodeAsHost)
+ IM_ASSERT(root_payload->DockNodeAsHost->Windows.Size == root_payload->DockNodeAsHost->TabBar->Tabs.Size);
+ const int payload_count = root_payload->DockNodeAsHost ? root_payload->DockNodeAsHost->TabBar->Tabs.Size : 1;
+ for (int payload_n = 0; payload_n < payload_count; payload_n++)
+ {
+ // Calculate the tab bounding box for each payload window
+ ImGuiWindow* payload = root_payload->DockNodeAsHost ? root_payload->DockNodeAsHost->TabBar->Tabs[payload_n].Window : root_payload;
+ if (!DockNodeIsDropAllowedOne(payload, host_window))
+ continue;
-void ImGui::DockBuilderDockWindow(const char* window_name, ImGuiID node_id)
-{
- // We don't preserve relative order of multiple docked windows (by clearing DockOrder back to -1)
- ImGuiID window_id = ImHashStr(window_name, 0);
- if (ImGuiWindow* window = FindWindowByID(window_id))
- {
- // Apply to created window
- SetWindowDock(window, node_id, ImGuiCond_Always);
- window->DockOrder = -1;
+ ImVec2 tab_size = TabItemCalcSize(payload->Name, payload->HasCloseButton);
+ ImRect tab_bb(tab_pos.x, tab_pos.y, tab_pos.x + tab_size.x, tab_pos.y + tab_size.y);
+ tab_pos.x += tab_size.x + g.Style.ItemInnerSpacing.x;
+ for (int overlay_n = 0; overlay_n < overlay_draw_lists_count; overlay_n++)
+ {
+ ImGuiTabItemFlags tab_flags = ImGuiTabItemFlags_Preview | ((payload->Flags & ImGuiWindowFlags_UnsavedDocument) ? ImGuiTabItemFlags_UnsavedDocument : 0);
+ if (!tab_bar_rect.Contains(tab_bb))
+ overlay_draw_lists[overlay_n]->PushClipRect(tab_bar_rect.Min, tab_bar_rect.Max);
+ TabItemBackground(overlay_draw_lists[overlay_n], tab_bb, tab_flags, overlay_col_tabs);
+ TabItemLabelAndCloseButton(overlay_draw_lists[overlay_n], tab_bb, tab_flags, g.Style.FramePadding, payload->Name, 0, 0);
+ if (!tab_bar_rect.Contains(tab_bb))
+ overlay_draw_lists[overlay_n]->PopClipRect();
+ }
+ }
}
- else
+
+ // Display drop boxes
+ const float overlay_rounding = ImMax(3.0f, g.Style.FrameRounding);
+ for (int dir = ImGuiDir_None; dir < ImGuiDir_COUNT; dir++)
{
- // Apply to settings
- ImGuiWindowSettings* settings = FindWindowSettings(window_id);
- if (settings == NULL)
- settings = CreateNewWindowSettings(window_name);
- settings->DockId = node_id;
- settings->DockOrder = -1;
+ if (!data->DropRectsDraw[dir + 1].IsInverted())
+ {
+ ImRect draw_r = data->DropRectsDraw[dir + 1];
+ ImRect draw_r_in = draw_r;
+ draw_r_in.Expand(-2.0f);
+ ImU32 overlay_col = (data->SplitDir == (ImGuiDir)dir && data->IsSplitDirExplicit) ? overlay_col_drop_hovered : overlay_col_drop;
+ for (int overlay_n = 0; overlay_n < overlay_draw_lists_count; overlay_n++)
+ {
+ ImVec2 center = ImFloor(draw_r_in.GetCenter());
+ overlay_draw_lists[overlay_n]->AddRectFilled(draw_r.Min, draw_r.Max, overlay_col, overlay_rounding);
+ overlay_draw_lists[overlay_n]->AddRect(draw_r_in.Min, draw_r_in.Max, overlay_col_lines, overlay_rounding);
+ if (dir == ImGuiDir_Left || dir == ImGuiDir_Right)
+ overlay_draw_lists[overlay_n]->AddLine(ImVec2(center.x, draw_r_in.Min.y), ImVec2(center.x, draw_r_in.Max.y), overlay_col_lines);
+ if (dir == ImGuiDir_Up || dir == ImGuiDir_Down)
+ overlay_draw_lists[overlay_n]->AddLine(ImVec2(draw_r_in.Min.x, center.y), ImVec2(draw_r_in.Max.x, center.y), overlay_col_lines);
+ }
+ }
+
+ // Stop after ImGuiDir_None
+ if ((host_node && (host_node->GetMergedFlags() & ImGuiDockNodeFlags_NoSplit)) || g.IO.ConfigDockingNoSplit)
+ return;
}
}
-ImGuiDockNode* ImGui::DockBuilderGetNode(ImGuiID node_id)
-{
- ImGuiContext* ctx = GImGui;
- return DockContextFindNodeByID(ctx, node_id);
-}
-
-void ImGui::DockBuilderSetNodePos(ImGuiID node_id, ImVec2 pos)
-{
- ImGuiContext* ctx = GImGui;
- ImGuiDockNode* node = DockContextFindNodeByID(ctx, node_id);
- if (node == NULL)
- return;
- node->Pos = pos;
- node->AutorityForPos = ImGuiDataAutority_DockNode;
-}
+//-----------------------------------------------------------------------------
+// Docking: ImGuiDockNode Tree manipulation functions
+//-----------------------------------------------------------------------------
+// - DockNodeTreeSplit()
+// - DockNodeTreeMerge()
+// - DockNodeTreeUpdatePosSize()
+// - DockNodeTreeUpdateSplitterFindTouchingNode()
+// - DockNodeTreeUpdateSplitter()
+// - DockNodeTreeFindFallbackLeafNode()
+// - DockNodeTreeFindNodeByPos()
+//-----------------------------------------------------------------------------
-void ImGui::DockBuilderSetNodeSize(ImGuiID node_id, ImVec2 size)
+void ImGui::DockNodeTreeSplit(ImGuiContext* ctx, ImGuiDockNode* parent_node, ImGuiAxis split_axis, int split_inheritor_child_idx, float split_ratio, ImGuiDockNode* new_node)
{
- ImGuiContext* ctx = GImGui;
- ImGuiDockNode* node = DockContextFindNodeByID(ctx, node_id);
- if (node == NULL)
- return;
- node->Size = node->SizeRef = size;
- node->AutorityForSize = ImGuiDataAutority_DockNode;
-}
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(split_axis != ImGuiAxis_None);
-// If you create a regular node, both ref_pos/ref_size will position the window.
-// If you create a dockspace node: ref_pos won't be used, ref_size is useful on the first frame to...
-ImGuiID ImGui::DockBuilderAddNode(ImGuiID id, ImGuiDockNodeFlags flags)
-{
- ImGuiContext* ctx = GImGui;
- ImGuiDockNode* node = NULL;
- if (flags & ImGuiDockNodeFlags_Dockspace)
- {
- DockSpace(id, ImVec2(0, 0), flags | ImGuiDockNodeFlags_KeepAliveOnly);
- node = DockContextFindNodeByID(ctx, id);
- node->LastFrameAlive = -1;
- }
- else
- {
- if (id != 0)
- node = DockContextFindNodeByID(ctx, id);
- if (!node)
- node = DockContextAddNode(ctx, id);
- node->LastFrameAlive = ctx->FrameCount;
- }
- return node->ID;
-}
+ ImGuiDockNode* child_0 = (new_node && split_inheritor_child_idx != 0) ? new_node : DockContextAddNode(ctx, 0);
+ child_0->ParentNode = parent_node;
-void ImGui::DockBuilderRemoveNode(ImGuiID node_id)
-{
- ImGuiContext* ctx = GImGui;
- ImGuiDockNode* node = DockContextFindNodeByID(ctx, node_id);
- if (node == NULL)
- return;
- DockBuilderRemoveNodeDockedWindows(node_id, true);
- DockBuilderRemoveNodeChildNodes(node_id);
- if (node->IsCentralNode && node->ParentNode)
- node->ParentNode->IsCentralNode = true;
- DockContextRemoveNode(ctx, node, true);
-}
+ ImGuiDockNode* child_1 = (new_node && split_inheritor_child_idx != 1) ? new_node : DockContextAddNode(ctx, 0);
+ child_1->ParentNode = parent_node;
-void ImGui::DockBuilderRemoveNodeChildNodes(ImGuiID root_id)
-{
- ImGuiContext* ctx = GImGui;
- ImGuiDockContext* dc = ctx->DockContext;
+ ImGuiDockNode* child_inheritor = (split_inheritor_child_idx == 0) ? child_0 : child_1;
+ DockNodeMoveChildNodes(child_inheritor, parent_node);
+ parent_node->ChildNodes[0] = child_0;
+ parent_node->ChildNodes[1] = child_1;
+ parent_node->ChildNodes[split_inheritor_child_idx]->VisibleWindow = parent_node->VisibleWindow;
+ parent_node->SplitAxis = split_axis;
+ parent_node->VisibleWindow = NULL;
+ parent_node->AuthorityForPos = parent_node->AuthorityForSize = ImGuiDataAuthority_DockNode;
- ImGuiDockNode* root_node = root_id ? DockContextFindNodeByID(ctx, root_id) : NULL;
- if (root_id && root_node == NULL)
- return;
- bool has_document_root = false;
+ float size_avail = (parent_node->Size[split_axis] - IMGUI_DOCK_SPLITTER_SIZE);
+ size_avail = ImMax(size_avail, g.Style.WindowMinSize[split_axis] * 2.0f);
+ IM_ASSERT(size_avail > 0.0f); // If you created a node manually with DockBuilderAddNode(), you need to also call DockBuilderSetNodeSize() before splitting.
+ child_0->SizeRef = child_1->SizeRef = parent_node->Size;
+ child_0->SizeRef[split_axis] = ImFloor(size_avail * split_ratio);
+ child_1->SizeRef[split_axis] = ImFloor(size_avail - child_0->SizeRef[split_axis]);
- ImGuiDataAutority backup_root_node_autority_for_pos = root_node ? root_node->AutorityForPos : ImGuiDataAutority_Auto;
- ImGuiDataAutority backup_root_node_autority_for_size = root_node ? root_node->AutorityForSize : ImGuiDataAutority_Auto;
+ DockNodeMoveWindows(parent_node->ChildNodes[split_inheritor_child_idx], parent_node);
+ DockNodeTreeUpdatePosSize(parent_node, parent_node->Pos, parent_node->Size);
- // Process active windows
- ImVector nodes_to_remove;
- for (int n = 0; n < dc->Nodes.Data.Size; n++)
- if (ImGuiDockNode* node = (ImGuiDockNode*)dc->Nodes.Data[n].val_p)
- {
- bool want_removal = (root_id == 0) || (node->ID != root_id && DockNodeGetRootNode(node)->ID == root_id);
- if (want_removal)
- {
- if (node->IsCentralNode)
- has_document_root = true;
- if (root_id != 0)
- DockContextQueueNotifyRemovedNode(ctx, node);
- if (root_node)
- DockNodeMoveWindows(root_node, node);
- nodes_to_remove.push_back(node);
- }
- }
+ // Flags transfer (e.g. this is where we transfer the ImGuiDockNodeFlags_CentralNode property)
+ child_0->SharedFlags = parent_node->SharedFlags & ImGuiDockNodeFlags_SharedFlagsInheritMask_;
+ child_1->SharedFlags = parent_node->SharedFlags & ImGuiDockNodeFlags_SharedFlagsInheritMask_;
+ child_inheritor->LocalFlags = parent_node->LocalFlags & ImGuiDockNodeFlags_LocalFlagsTransferMask_;
+ parent_node->LocalFlags &= ~ImGuiDockNodeFlags_LocalFlagsTransferMask_;
+ if (child_inheritor->IsCentralNode())
+ DockNodeGetRootNode(parent_node)->CentralNode = child_inheritor;
+}
- // DockNodeMoveWindows->DockNodeAddWindow will normally set those when reaching two windows (which is only adequate during interactive merge)
- // Make sure we don't lose our current pos/size. (FIXME-DOCK: Consider tidying up that code in DockNodeAddWindow instead)
- if (root_node)
+void ImGui::DockNodeTreeMerge(ImGuiContext* ctx, ImGuiDockNode* parent_node, ImGuiDockNode* merge_lead_child)
+{
+ // When called from DockContextProcessUndockNode() it is possible that one of the child is NULL.
+ ImGuiDockNode* child_0 = parent_node->ChildNodes[0];
+ ImGuiDockNode* child_1 = parent_node->ChildNodes[1];
+ IM_ASSERT(child_0 || child_1);
+ IM_ASSERT(merge_lead_child == child_0 || merge_lead_child == child_1);
+ if ((child_0 && child_0->Windows.Size > 0) || (child_1 && child_1->Windows.Size > 0))
{
- root_node->AutorityForPos = backup_root_node_autority_for_pos;
- root_node->AutorityForSize = backup_root_node_autority_for_size;
+ IM_ASSERT(parent_node->TabBar == NULL);
+ IM_ASSERT(parent_node->Windows.Size == 0);
}
+ IMGUI_DEBUG_LOG_DOCKING("DockNodeTreeMerge 0x%08X & 0x%08X back into parent 0x%08X\n", child_0 ? child_0->ID : 0, child_1 ? child_1->ID : 0, parent_node->ID);
- // Apply to settings
- for (int settings_n = 0; settings_n < ctx->SettingsWindows.Size; settings_n++)
- if (ImGuiID window_settings_dock_id = ctx->SettingsWindows[settings_n].DockId)
- for (int n = 0; n < nodes_to_remove.Size; n++)
- if (nodes_to_remove[n]->ID == window_settings_dock_id)
- {
- ctx->SettingsWindows[settings_n].DockId = root_id;
- break;
- }
+ ImVec2 backup_last_explicit_size = parent_node->SizeRef;
+ DockNodeMoveChildNodes(parent_node, merge_lead_child);
+ if (child_0)
+ {
+ DockNodeMoveWindows(parent_node, child_0); // Generally only 1 of the 2 child node will have windows
+ DockSettingsRenameNodeReferences(child_0->ID, parent_node->ID);
+ }
+ if (child_1)
+ {
+ DockNodeMoveWindows(parent_node, child_1);
+ DockSettingsRenameNodeReferences(child_1->ID, parent_node->ID);
+ }
+ DockNodeApplyPosSizeToWindows(parent_node);
+ parent_node->AuthorityForPos = parent_node->AuthorityForSize = parent_node->AuthorityForViewport = ImGuiDataAuthority_Auto;
+ parent_node->VisibleWindow = merge_lead_child->VisibleWindow;
+ parent_node->SizeRef = backup_last_explicit_size;
- // Not really efficient, but easier to destroy a whole hierarchy considering DockContextRemoveNode is attempting to merge nodes
- if (nodes_to_remove.Size > 1)
- ImQsort(nodes_to_remove.Data, nodes_to_remove.Size, sizeof(ImGuiDockNode*), DockNodeComparerDepthMostFirst);
- for (int n = 0; n < nodes_to_remove.Size; n++)
- DockContextRemoveNode(ctx, nodes_to_remove[n], false);
+ // Flags transfer
+ parent_node->LocalFlags &= ~ImGuiDockNodeFlags_LocalFlagsTransferMask_; // Preserve Dockspace flag
+ parent_node->LocalFlags |= (child_0 ? child_0->LocalFlags : 0) & ImGuiDockNodeFlags_LocalFlagsTransferMask_;
+ parent_node->LocalFlags |= (child_1 ? child_1->LocalFlags : 0) & ImGuiDockNodeFlags_LocalFlagsTransferMask_;
- if (root_id == 0)
+ if (child_0)
{
- dc->Nodes.Clear();
- dc->Requests.clear();
+ ctx->DockContext->Nodes.SetVoidPtr(child_0->ID, NULL);
+ IM_DELETE(child_0);
}
- else if (has_document_root)
+ if (child_1)
{
- root_node->IsCentralNode = true;
+ ctx->DockContext->Nodes.SetVoidPtr(child_1->ID, NULL);
+ IM_DELETE(child_1);
}
}
-void ImGui::DockBuilderRemoveNodeDockedWindows(ImGuiID root_id, bool clear_persistent_docking_references)
+// Update Pos/Size for a node hierarchy (don't affect child Windows yet)
+void ImGui::DockNodeTreeUpdatePosSize(ImGuiDockNode* node, ImVec2 pos, ImVec2 size, bool only_write_to_marked_nodes)
{
- // Clear references in settings
- ImGuiContext* ctx = GImGui;
- ImGuiContext& g = *ctx;
- if (clear_persistent_docking_references)
+ // During the regular dock node update we write to all nodes.
+ // 'only_write_to_marked_nodes' is only set when turning a node visible mid-frame and we need its size right-away.
+ IM_ASSERT(size.x > 0.0f && size.y > 0.0f);
+ const bool write_to_node = (only_write_to_marked_nodes == false) || (node->MarkedForPosSizeWrite);
+ if (write_to_node)
{
- for (int n = 0; n < g.SettingsWindows.Size; n++)
- {
- ImGuiWindowSettings* settings = &g.SettingsWindows[n];
- bool want_removal = (root_id == 0) || (settings->DockId == root_id);
- if (!want_removal && settings->DockId != 0)
- if (ImGuiDockNode* node = DockContextFindNodeByID(ctx, settings->DockId))
- if (DockNodeGetRootNode(node)->ID == root_id)
- want_removal = true;
- if (want_removal)
- settings->DockId = 0;
- }
+ node->Pos = pos;
+ node->Size = size;
}
- // Clear references in windows
- for (int n = 0; n < g.Windows.Size; n++)
+ if (node->IsLeafNode())
+ return;
+
+ ImGuiDockNode* child_0 = node->ChildNodes[0];
+ ImGuiDockNode* child_1 = node->ChildNodes[1];
+ ImVec2 child_0_pos = pos, child_1_pos = pos;
+ ImVec2 child_0_size = size, child_1_size = size;
+ if (child_0->IsVisible && child_1->IsVisible)
{
- ImGuiWindow* window = g.Windows[n];
- bool want_removal = (root_id == 0) || (window->DockNode && DockNodeGetRootNode(window->DockNode)->ID == root_id) || (window->DockNodeAsHost && window->DockNodeAsHost->ID == root_id);
- if (want_removal)
+ const float spacing = IMGUI_DOCK_SPLITTER_SIZE;
+ const ImGuiAxis axis = (ImGuiAxis)node->SplitAxis;
+ const float size_avail = ImMax(size[axis] - spacing, 0.0f);
+
+ // Size allocation policy
+ // 1) The first 0..WindowMinSize[axis]*2 are allocated evenly to both windows.
+ ImGuiContext& g = *GImGui;
+ const float size_min_each = ImFloor(ImMin(size_avail, g.Style.WindowMinSize[axis] * 2.0f) * 0.5f);
+
+ // 2) Process locked absolute size (during a splitter resize we preserve the child of nodes not touching the splitter edge)
+ IM_ASSERT(!(child_0->WantLockSizeOnce && child_1->WantLockSizeOnce));
+ if (child_0->WantLockSizeOnce)
{
- const ImGuiID backup_dock_id = window->DockId;
- DockContextProcessUndockWindow(ctx, window, clear_persistent_docking_references);
- if (!clear_persistent_docking_references)
- IM_ASSERT(window->DockId == backup_dock_id);
+ child_0->WantLockSizeOnce = false;
+ child_0_size[axis] = child_0->SizeRef[axis] = child_0->Size[axis];
+ child_1_size[axis] = child_1->SizeRef[axis] = (size_avail - child_0_size[axis]);
+ IM_ASSERT(child_0->SizeRef[axis] > 0.0f && child_1->SizeRef[axis] > 0.0f);
+
+ }
+ else if (child_1->WantLockSizeOnce)
+ {
+ child_1->WantLockSizeOnce = false;
+ child_1_size[axis] = child_1->SizeRef[axis] = child_1->Size[axis];
+ child_0_size[axis] = child_0->SizeRef[axis] = (size_avail - child_1_size[axis]);
+ IM_ASSERT(child_0->SizeRef[axis] > 0.0f && child_1->SizeRef[axis] > 0.0f);
+ }
+
+ // 3) If one window is the central node (~ use remaining space, should be made explicit!), use explicit size from the other, and remainder for the central node
+ else if (child_1->IsCentralNode() && child_0->SizeRef[axis] != 0.0f)
+ {
+ child_0_size[axis] = ImMin(size_avail - size_min_each, child_0->SizeRef[axis]);
+ child_1_size[axis] = (size_avail - child_0_size[axis]);
+ }
+ else if (child_0->IsCentralNode() && child_1->SizeRef[axis] != 0.0f)
+ {
+ child_1_size[axis] = ImMin(size_avail - size_min_each, child_1->SizeRef[axis]);
+ child_0_size[axis] = (size_avail - child_1_size[axis]);
+ }
+ else
+ {
+ // 4) Otherwise distribute according to the relative ratio of each SizeRef value
+ float split_ratio = child_0->SizeRef[axis] / (child_0->SizeRef[axis] + child_1->SizeRef[axis]);
+ child_0_size[axis] = ImMax(size_min_each, ImFloor(size_avail * split_ratio + 0.5F));
+ child_1_size[axis] = (size_avail - child_0_size[axis]);
}
+ child_1_pos[axis] += spacing + child_0_size[axis];
}
+ if (child_0->IsVisible)
+ DockNodeTreeUpdatePosSize(child_0, child_0_pos, child_0_size);
+ if (child_1->IsVisible)
+ DockNodeTreeUpdatePosSize(child_1, child_1_pos, child_1_size);
}
-ImGuiID ImGui::DockBuilderSplitNode(ImGuiID id, ImGuiDir split_dir, float size_ratio_for_node_at_dir, ImGuiID* out_id_at_dir, ImGuiID* out_id_other)
+static void DockNodeTreeUpdateSplitterFindTouchingNode(ImGuiDockNode* node, ImGuiAxis axis, int side, ImVector* touching_nodes)
{
- ImGuiContext* ctx = GImGui;
- IM_ASSERT(split_dir != ImGuiDir_None);
-
- ImGuiDockNode* node = DockContextFindNodeByID(ctx, id);
- if (node == NULL)
+ if (node->IsLeafNode())
{
- IM_ASSERT(node != NULL);
- return 0;
+ touching_nodes->push_back(node);
+ return;
}
-
- IM_ASSERT(!node->IsSplitNode()); // Assert if already Split
-
- ImGuiDockRequest req;
- req.Type = ImGuiDockRequestType_Split;
- req.DockTargetWindow = NULL;
- req.DockTargetNode = node;
- req.DockPayload = NULL;
- req.DockSplitDir = split_dir;
- req.DockSplitRatio = ImSaturate((split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Up) ? size_ratio_for_node_at_dir : 1.0f - size_ratio_for_node_at_dir);
- req.DockSplitOuter = false;
- DockContextProcessDock(ctx, &req);
-
- ImGuiID id_at_dir = node->ChildNodes[(split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Up) ? 0 : 1]->ID;
- ImGuiID id_other = node->ChildNodes[(split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Up) ? 1 : 0]->ID;
- if (out_id_at_dir)
- *out_id_at_dir = id_at_dir;
- if (out_id_other)
- *out_id_other = id_other;
- return id_at_dir;
+ if (node->ChildNodes[0]->IsVisible)
+ if (node->SplitAxis != axis || side == 0 || !node->ChildNodes[1]->IsVisible)
+ DockNodeTreeUpdateSplitterFindTouchingNode(node->ChildNodes[0], axis, side, touching_nodes);
+ if (node->ChildNodes[1]->IsVisible)
+ if (node->SplitAxis != axis || side == 1 || !node->ChildNodes[0]->IsVisible)
+ DockNodeTreeUpdateSplitterFindTouchingNode(node->ChildNodes[1], axis, side, touching_nodes);
}
-static ImGuiDockNode* DockBuilderCopyNodeRec(ImGuiDockNode* src_node, ImGuiID dst_node_id_if_known, ImVector* out_node_remap_pairs)
+void ImGui::DockNodeTreeUpdateSplitter(ImGuiDockNode* node)
{
- ImGuiContext* ctx = GImGui;
- ImGuiDockNode* dst_node = ImGui::DockContextAddNode(ctx, dst_node_id_if_known);
- dst_node->Flags = src_node->Flags;
- dst_node->Pos = src_node->Pos;
- dst_node->Size = src_node->Size;
- dst_node->SizeRef = src_node->SizeRef;
- dst_node->SplitAxis = src_node->SplitAxis;
- dst_node->IsCentralNode = src_node->IsCentralNode;
+ if (node->IsLeafNode())
+ return;
- out_node_remap_pairs->push_back(src_node->ID);
- out_node_remap_pairs->push_back(dst_node->ID);
+ ImGuiContext& g = *GImGui;
- for (int child_n = 0; child_n < IM_ARRAYSIZE(src_node->ChildNodes); child_n++)
- if (src_node->ChildNodes[child_n])
+ ImGuiDockNode* child_0 = node->ChildNodes[0];
+ ImGuiDockNode* child_1 = node->ChildNodes[1];
+ if (child_0->IsVisible && child_1->IsVisible)
+ {
+ // Bounding box of the splitter cover the space between both nodes (w = Spacing, h = Size[xy^1] for when splitting horizontally)
+ const ImGuiAxis axis = (ImGuiAxis)node->SplitAxis;
+ IM_ASSERT(axis != ImGuiAxis_None);
+ ImRect bb;
+ bb.Min = child_0->Pos;
+ bb.Max = child_1->Pos;
+ bb.Min[axis] += child_0->Size[axis];
+ bb.Max[axis ^ 1] += child_1->Size[axis ^ 1];
+ //if (g.IO.KeyCtrl) GetForegroundDrawList(g.CurrentWindow->Viewport)->AddRect(bb.Min, bb.Max, IM_COL32(255,0,255,255));
+
+ if ((child_0->GetMergedFlags() | child_1->GetMergedFlags()) & ImGuiDockNodeFlags_NoResize)
{
- dst_node->ChildNodes[child_n] = DockBuilderCopyNodeRec(src_node->ChildNodes[child_n], 0, out_node_remap_pairs);
- dst_node->ChildNodes[child_n]->ParentNode = dst_node;
+ ImGuiWindow* window = g.CurrentWindow;
+ window->DrawList->AddRectFilled(bb.Min, bb.Max, GetColorU32(ImGuiCol_Separator), g.Style.FrameRounding);
+ }
+ else
+ {
+ //bb.Min[axis] += 1; // Display a little inward so highlight doesn't connect with nearby tabs on the neighbor node.
+ //bb.Max[axis] -= 1;
+ PushID(node->ID);
+
+ // Gather list of nodes that are touching the splitter line. Find resizing limits based on those nodes.
+ ImVector touching_nodes[2];
+ float min_size = g.Style.WindowMinSize[axis];
+ float resize_limits[2];
+ resize_limits[0] = node->ChildNodes[0]->Pos[axis] + min_size;
+ resize_limits[1] = node->ChildNodes[1]->Pos[axis] + node->ChildNodes[1]->Size[axis] - min_size;
+
+ ImGuiID splitter_id = GetID("##Splitter");
+ if (g.ActiveId == splitter_id)
+ {
+ // Only process when splitter is active
+ DockNodeTreeUpdateSplitterFindTouchingNode(child_0, axis, 1, &touching_nodes[0]);
+ DockNodeTreeUpdateSplitterFindTouchingNode(child_1, axis, 0, &touching_nodes[1]);
+ for (int touching_node_n = 0; touching_node_n < touching_nodes[0].Size; touching_node_n++)
+ resize_limits[0] = ImMax(resize_limits[0], touching_nodes[0][touching_node_n]->Rect().Min[axis] + min_size);
+ for (int touching_node_n = 0; touching_node_n < touching_nodes[1].Size; touching_node_n++)
+ resize_limits[1] = ImMin(resize_limits[1], touching_nodes[1][touching_node_n]->Rect().Max[axis] - min_size);
+
+ /*
+ // [DEBUG] Render limits
+ ImDrawList* draw_list = node->HostWindow ? GetForegroundDrawList(node->HostWindow) : GetForegroundDrawList((ImGuiViewportP*)GetMainViewport());
+ for (int n = 0; n < 2; n++)
+ if (axis == ImGuiAxis_X)
+ draw_list->AddLine(ImVec2(resize_limits[n], node->ChildNodes[n]->Pos.y), ImVec2(resize_limits[n], node->ChildNodes[n]->Pos.y + node->ChildNodes[n]->Size.y), IM_COL32(255, 0, 255, 255), 3.0f);
+ else
+ draw_list->AddLine(ImVec2(node->ChildNodes[n]->Pos.x, resize_limits[n]), ImVec2(node->ChildNodes[n]->Pos.x + node->ChildNodes[n]->Size.x, resize_limits[n]), IM_COL32(255, 0, 255, 255), 3.0f);
+ */
+ }
+
+ // Use a short delay before highlighting the splitter (and changing the mouse cursor) in order for regular mouse movement to not highlight many splitters
+ float cur_size_0 = child_0->Size[axis];
+ float cur_size_1 = child_1->Size[axis];
+ float min_size_0 = resize_limits[0] - child_0->Pos[axis];
+ float min_size_1 = child_1->Pos[axis] + child_1->Size[axis] - resize_limits[1];
+ if (SplitterBehavior(bb, GetID("##Splitter"), axis, &cur_size_0, &cur_size_1, min_size_0, min_size_1, WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS, WINDOWS_RESIZE_FROM_EDGES_FEEDBACK_TIMER))
+ {
+ if (touching_nodes[0].Size > 0 && touching_nodes[1].Size > 0)
+ {
+ child_0->Size[axis] = child_0->SizeRef[axis] = cur_size_0;
+ child_1->Pos[axis] -= cur_size_1 - child_1->Size[axis];
+ child_1->Size[axis] = child_1->SizeRef[axis] = cur_size_1;
+
+ // Lock the size of every node that is a sibling of the node we are touching
+ // This might be less desirable if we can merge sibling of a same axis into the same parental level.
+ for (int side_n = 0; side_n < 2; side_n++)
+ for (int touching_node_n = 0; touching_node_n < touching_nodes[side_n].Size; touching_node_n++)
+ {
+ ImGuiDockNode* touching_node = touching_nodes[side_n][touching_node_n];
+ //ImDrawList* draw_list = node->HostWindow ? GetForegroundDrawList(node->HostWindow) : GetForegroundDrawList((ImGuiViewportP*)GetMainViewport());
+ //draw_list->AddRect(touching_node->Pos, touching_node->Pos + touching_node->Size, IM_COL32(255, 128, 0, 255));
+ while (touching_node->ParentNode != node)
+ {
+ if (touching_node->ParentNode->SplitAxis == axis)
+ {
+ // Mark other node so its size will be preserved during the upcoming call to DockNodeTreeUpdatePosSize().
+ ImGuiDockNode* node_to_preserve = touching_node->ParentNode->ChildNodes[side_n];
+ node_to_preserve->WantLockSizeOnce = true;
+ //draw_list->AddRect(touching_node->Pos, touching_node->Rect().Max, IM_COL32(255, 0, 0, 255));
+ //draw_list->AddRectFilled(node_to_preserve->Pos, node_to_preserve->Rect().Max, IM_COL32(0, 255, 0, 100));
+ }
+ touching_node = touching_node->ParentNode;
+ }
+ }
+
+ DockNodeTreeUpdatePosSize(child_0, child_0->Pos, child_0->Size);
+ DockNodeTreeUpdatePosSize(child_1, child_1->Pos, child_1->Size);
+ MarkIniSettingsDirty();
+ }
+ }
+ PopID();
}
+ }
- //IMGUI_DEBUG_LOG("Fork node %08X -> %08X (%d childs)\n", src_node->ID, dst_node->ID, dst_node->IsSplitNode() ? 2 : 0);
- return dst_node;
+ if (child_0->IsVisible)
+ DockNodeTreeUpdateSplitter(child_0);
+ if (child_1->IsVisible)
+ DockNodeTreeUpdateSplitter(child_1);
}
-void ImGui::DockBuilderCopyNode(ImGuiID src_node_id, ImGuiID dst_node_id, ImVector* out_node_remap_pairs)
+ImGuiDockNode* ImGui::DockNodeTreeFindFallbackLeafNode(ImGuiDockNode* node)
{
- ImGuiContext* ctx = GImGui;
- IM_ASSERT(src_node_id != 0);
- IM_ASSERT(dst_node_id != 0);
- IM_ASSERT(out_node_remap_pairs != NULL);
+ if (node->IsLeafNode())
+ return node;
+ if (ImGuiDockNode* leaf_node = DockNodeTreeFindFallbackLeafNode(node->ChildNodes[0]))
+ return leaf_node;
+ if (ImGuiDockNode* leaf_node = DockNodeTreeFindFallbackLeafNode(node->ChildNodes[1]))
+ return leaf_node;
+ return NULL;
+}
- ImGuiDockNode* src_node = DockContextFindNodeByID(ctx, src_node_id);
- IM_ASSERT(src_node != NULL);
+ImGuiDockNode* ImGui::DockNodeTreeFindNodeByPos(ImGuiDockNode* node, ImVec2 pos)
+{
+ if (!node->IsVisible)
+ return NULL;
- out_node_remap_pairs->clear();
- DockBuilderRemoveNode(dst_node_id);
- DockBuilderCopyNodeRec(src_node, dst_node_id, out_node_remap_pairs);
+ ImGuiContext& g = *GImGui;
+ const float dock_spacing = g.Style.ItemInnerSpacing.x;
+ ImRect r(node->Pos, node->Pos + node->Size);
+ r.Expand(dock_spacing * 0.5f);
+ bool inside = r.Contains(pos);
+ if (!inside)
+ return NULL;
- IM_ASSERT((out_node_remap_pairs->Size % 2) == 0);
-}
+ if (node->IsLeafNode())
+ return node;
+ if (ImGuiDockNode* hovered_node = DockNodeTreeFindNodeByPos(node->ChildNodes[0], pos))
+ return hovered_node;
+ if (ImGuiDockNode* hovered_node = DockNodeTreeFindNodeByPos(node->ChildNodes[1], pos))
+ return hovered_node;
-void ImGui::DockBuilderCopyWindowSettings(const char* src_name, const char* dst_name)
-{
- ImGuiWindow* src_window = FindWindowByName(src_name);
- if (src_window == NULL)
- return;
- if (ImGuiWindow* dst_window = FindWindowByName(dst_name))
- {
- dst_window->Pos = src_window->Pos;
- dst_window->Size = src_window->Size;
- dst_window->SizeFull = src_window->SizeFull;
- dst_window->Collapsed = src_window->Collapsed;
- }
- else if (ImGuiWindowSettings* dst_settings = FindOrCreateWindowSettings(dst_name))
+ // There is an edge case when docking into a dockspace which only has inactive nodes (because none of the windows are active)
+ // In this case we need to fallback into any leaf mode, possibly the central node.
+ if (node->IsDockSpace() && node->IsRootNode())
{
- if (src_window->ViewportId != 0 && src_window->ViewportId != IMGUI_VIEWPORT_DEFAULT_ID)
- {
- dst_settings->ViewportPos = src_window->Pos;
- dst_settings->ViewportId = src_window->ViewportId;
- dst_settings->Pos = ImVec2(0.0f, 0.0f);
- }
- else
- {
- dst_settings->Pos = src_window->Pos;
- }
- dst_settings->Size = src_window->SizeFull;
- dst_settings->Collapsed = src_window->Collapsed;
+ if (node->CentralNode && node->IsLeafNode()) // FIXME-20181220: We should not have to test for IsLeafNode() here but we have another bug to fix first.
+ return node->CentralNode;
+ return DockNodeTreeFindFallbackLeafNode(node);
}
+
+ return NULL;
}
-// FIXME: Will probably want to change this signature, in particular how the window remapping pairs are passed.
-void ImGui::DockBuilderCopyDockspace(ImGuiID src_dockspace_id, ImGuiID dst_dockspace_id, ImVector* in_window_remap_pairs)
-{
- IM_ASSERT(src_dockspace_id != 0);
- IM_ASSERT(dst_dockspace_id != 0);
- IM_ASSERT(in_window_remap_pairs != NULL);
- IM_ASSERT((in_window_remap_pairs->Size % 2) == 0);
+//-----------------------------------------------------------------------------
+// Docking: Public Functions (SetWindowDock, DockSpace, DockSpaceOverViewport)
+//-----------------------------------------------------------------------------
+// - SetWindowDock() [Internal]
+// - DockSpace()
+// - DockSpaceOverViewport()
+//-----------------------------------------------------------------------------
- // Duplicate entire dock
- // FIXME: When overwriting dst_dockspace_id, windows that aren't part of our dockspace window class but that are docked in a same node will be split apart,
- // whereas we could attempt to at least keep them together in a new, same floating node.
- ImVector node_remap_pairs;
- DockBuilderCopyNode(src_dockspace_id, dst_dockspace_id, &node_remap_pairs);
+// [Internal] Called via SetNextWindowDockID()
+void ImGui::SetWindowDock(ImGuiWindow* window, ImGuiID dock_id, ImGuiCond cond)
+{
+ // Test condition (NB: bit 0 is always true) and clear flags for next time
+ if (cond && (window->SetWindowDockAllowFlags & cond) == 0)
+ return;
+ window->SetWindowDockAllowFlags &= ~(ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing);
- // Attempt to transition all the upcoming windows associated to dst_dockspace_id into the newly created hierarchy of dock nodes
- // (The windows associated to src_dockspace_id are staying in place)
- ImVector src_windows;
- for (int remap_window_n = 0; remap_window_n < in_window_remap_pairs->Size; remap_window_n += 2)
- {
- const char* src_window_name = (*in_window_remap_pairs)[remap_window_n];
- const char* dst_window_name = (*in_window_remap_pairs)[remap_window_n + 1];
- ImGuiID src_window_id = ImHashStr(src_window_name, 0);
- src_windows.push_back(src_window_id);
+ if (window->DockId == dock_id)
+ return;
- // Search in the remapping tables
- ImGuiID src_dock_id = 0;
- if (ImGuiWindow* src_window = FindWindowByID(src_window_id))
- src_dock_id = src_window->DockId;
- else if (ImGuiWindowSettings* src_window_settings = FindWindowSettings(src_window_id))
- src_dock_id = src_window_settings->DockId;
- ImGuiID dst_dock_id = 0;
- for (int dock_remap_n = 0; dock_remap_n < node_remap_pairs.Size; dock_remap_n += 2)
- if (node_remap_pairs[dock_remap_n] == src_dock_id)
+ // If the user attempt to set a dock id that is a split node, we'll dig within to find a suitable docking spot
+ ImGuiContext* ctx = GImGui;
+ if (ImGuiDockNode* new_node = DockContextFindNodeByID(ctx, dock_id))
+ if (new_node->IsSplitNode())
+ {
+ // Policy: Find central node or latest focused node. We first move back to our root node.
+ new_node = DockNodeGetRootNode(new_node);
+ if (new_node->CentralNode)
{
- dst_dock_id = node_remap_pairs[dock_remap_n + 1];
- //node_remap_pairs[dock_remap_n] = node_remap_pairs[dock_remap_n + 1] = 0; // Clear
- break;
+ IM_ASSERT(new_node->CentralNode->IsCentralNode());
+ dock_id = new_node->CentralNode->ID;
}
-
- if (dst_dock_id != 0)
- {
- // Docked windows gets redocked into the new node hierarchy.
- //IMGUI_DEBUG_LOG("Remap window '%s' %08X -> %08X\n", dst_window_name, src_dock_id, dst_dock_id);
- DockBuilderDockWindow(dst_window_name, dst_dock_id);
- }
- else
- {
- // Floating windows gets their settings transferred (regardless of whether the new window already exist or not)
- // When this is leading to a Copy and not a Move, we would get two overlapping floating windows. Could we possibly dock them together?
- DockBuilderCopyWindowSettings(src_window_name, dst_window_name);
- }
- }
-
- // Anything else in the source nodes of 'node_remap_pairs' are windows that were docked in src_dockspace_id but are not owned by it (unaffiliated windows, e.g. "ImGui Demo")
- // Find those windows and move to them to the cloned dock node. This may be optional?
- for (int dock_remap_n = 0; dock_remap_n < node_remap_pairs.Size; dock_remap_n += 2)
- if (ImGuiID src_dock_id = node_remap_pairs[dock_remap_n])
- {
- ImGuiID dst_dock_id = node_remap_pairs[dock_remap_n + 1];
- ImGuiDockNode* node = DockBuilderGetNode(src_dock_id);
- for (int window_n = 0; window_n < node->Windows.Size; window_n++)
+ else
{
- ImGuiWindow* window = node->Windows[window_n];
- if (src_windows.contains(window->ID))
- continue;
-
- // Docked windows gets redocked into the new node hierarchy.
- //IMGUI_DEBUG_LOG("Remap window '%s' %08X -> %08X\n", window->Name, src_dock_id, dst_dock_id);
- DockBuilderDockWindow(window->Name, dst_dock_id);
+ dock_id = new_node->LastFocusedNodeID;
}
}
-}
-void ImGui::DockBuilderFinish(ImGuiID root_id)
-{
- ImGuiContext* ctx = GImGui;
- //DockContextRebuild(ctx);
- DockContextBuildAddWindowsToNodes(ctx, root_id);
-}
+ if (window->DockId == dock_id)
+ return;
-//-----------------------------------------------------------------------------
-// Docking: Begin/End Functions (called from Begin/End)
-//-----------------------------------------------------------------------------
+ if (window->DockNode)
+ DockNodeRemoveWindow(window->DockNode, window, 0);
+ window->DockId = dock_id;
+}
-void ImGui::BeginDocked(ImGuiWindow* window, bool* p_open)
+// Create an explicit dockspace node within an existing window. Also expose dock node flags and creates a CentralNode by default.
+// The Central Node is always displayed even when empty and shrink/extend according to the requested size of its neighbors.
+void ImGui::DockSpace(ImGuiID id, const ImVec2& size_arg, ImGuiDockNodeFlags flags, const ImGuiWindowClass* window_class)
{
ImGuiContext* ctx = GImGui;
ImGuiContext& g = *ctx;
+ ImGuiWindow* window = GetCurrentWindow();
+ if (!(g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable))
+ return;
- const bool auto_dock_node = (g.IO.ConfigDockingTabBarOnSingleWindows) && !(window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoDocking));
-
- if (auto_dock_node)
- {
- if (window->DockId == 0)
- {
- IM_ASSERT(window->DockNode == NULL);
- window->DockId = DockContextGenNodeID(ctx);
- }
- }
- else
- {
- // Calling SetNextWindowPos() undock windows by default (by setting PosUndock)
- bool want_undock = false;
- want_undock |= (window->Flags & ImGuiWindowFlags_NoDocking) != 0;
- want_undock |= (g.NextWindowData.PosCond && (window->SetWindowPosAllowFlags & g.NextWindowData.PosCond) && g.NextWindowData.PosUndock);
- g.NextWindowData.PosUndock = false;
- if (want_undock)
- {
- DockContextProcessUndockWindow(ctx, window);
- return;
- }
- }
-
- // Bind to our dock node
- ImGuiDockNode* node = window->DockNode;
- if (node != NULL)
- IM_ASSERT(window->DockId == node->ID);
- if (window->DockId != 0 && node == NULL)
+ IM_ASSERT((flags & ImGuiDockNodeFlags_DockSpace) == 0);
+ ImGuiDockNode* node = DockContextFindNodeByID(ctx, id);
+ if (!node)
{
- node = DockContextFindNodeByID(ctx, window->DockId);
-
- // We should not be docking into a split node (SetWindowDock should avoid this)
- if (node && node->IsSplitNode())
- {
- DockContextProcessUndockWindow(ctx, window);
- return;
- }
-
- // Create node
- if (node == NULL)
- {
- node = DockContextAddNode(ctx, window->DockId);
- if (auto_dock_node)
- node->LastFrameAlive = g.FrameCount;
- }
-
- DockNodeAddWindow(node, window, true);
- IM_ASSERT(node == window->DockNode);
-
- // Fix an edge case with auto-resizing windows: if they are created on the same frame they are creating their dock node,
- // we don't want their initial zero-size to spread to the DockNode. We preserve their size.
- SetNextWindowPos(window->Pos);
- SetNextWindowSize(window->SizeFull);
- g.NextWindowData.PosUndock = false;
+ IMGUI_DEBUG_LOG_DOCKING("DockSpace: dockspace node 0x%08X created\n", id);
+ node = DockContextAddNode(ctx, id);
+ node->LocalFlags |= ImGuiDockNodeFlags_CentralNode;
}
+ if (window_class && window_class->ClassId != node->WindowClass.ClassId)
+ IMGUI_DEBUG_LOG_DOCKING("DockSpace: dockspace node 0x%08X: setup WindowClass 0x%08X -> 0x%08X\n", id, node->WindowClass.ClassId, window_class->ClassId);
+ node->SharedFlags = flags;
+ node->WindowClass = window_class ? *window_class : ImGuiWindowClass();
- // Undock if the ImGuiDockNodeFlags_NoDockingInCentralNode got set
- if (node->IsCentralNode && (node->Flags & ImGuiDockNodeFlags_NoDockingInCentralNode))
+ // When a DockSpace transitioned form implicit to explicit this may be called a second time
+ // It is possible that the node has already been claimed by a docked window which appeared before the DockSpace() node, so we overwrite IsDockSpace again.
+ if (node->LastFrameActive == g.FrameCount && !(flags & ImGuiDockNodeFlags_KeepAliveOnly))
{
- DockContextProcessUndockWindow(ctx, window);
+ IM_ASSERT(node->IsDockSpace() == false && "Cannot call DockSpace() twice a frame with the same ID");
+ node->LocalFlags |= ImGuiDockNodeFlags_DockSpace;
return;
}
+ node->LocalFlags |= ImGuiDockNodeFlags_DockSpace;
- // Undock if our dockspace node disappeared
- // Note how we are testing for LastFrameAlive and NOT LastFrameActive. A DockSpace node can be maintained alive while being inactive with ImGuiDockNodeFlags_KeepAliveOnly.
- if (node->LastFrameAlive < g.FrameCount)
+ // Keep alive mode, this is allow windows docked into this node so stay docked even if they are not visible
+ if (flags & ImGuiDockNodeFlags_KeepAliveOnly)
{
- // If the window has been orphaned, transition the docknode to an implicit node processed in DockContextUpdateDocking()
- ImGuiDockNode* root_node = DockNodeGetRootNode(node);
- if (root_node->LastFrameAlive < g.FrameCount)
- {
- DockContextProcessUndockWindow(ctx, window);
- }
- else
- {
- window->DockIsActive = true;
- window->DockTabIsVisible = false;
- }
+ node->LastFrameAlive = g.FrameCount;
return;
}
- // Undock if we are submitted earlier than the host window
- if (node->HostWindow && window->BeginOrderWithinContext < node->HostWindow->BeginOrderWithinContext)
- {
- DockContextProcessUndockWindow(ctx, window);
- return;
- }
+ const ImVec2 content_avail = GetContentRegionAvail();
+ ImVec2 size = ImFloor(size_arg);
+ if (size.x <= 0.0f)
+ size.x = ImMax(content_avail.x + size.x, 4.0f); // Arbitrary minimum child size (0.0f causing too much issues)
+ if (size.y <= 0.0f)
+ size.y = ImMax(content_avail.y + size.y, 4.0f);
+ IM_ASSERT(size.x > 0.0f && size.y > 0.0f);
+
+ node->Pos = window->DC.CursorPos;
+ node->Size = node->SizeRef = size;
+ SetNextWindowPos(node->Pos);
+ SetNextWindowSize(node->Size);
+ g.NextWindowData.PosUndock = false;
+
+ // FIXME-DOCKING: Why do we need a child window to host a dockspace, could we host it in the existing window?
+ ImGuiWindowFlags window_flags = ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_DockNodeHost;
+ window_flags |= ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar;
+ window_flags |= ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse;
+
+ char title[256];
+ ImFormatString(title, IM_ARRAYSIZE(title), "%s/DockSpace_%08X", window->Name, id);
- // FIXME-DOCK: replace ->HostWindow NULL compare with something more explicit (~was initially intended as a first frame test)
- if (node->HostWindow == NULL)
- {
- window->DockTabIsVisible = false;
- return;
- }
+ if (node->Windows.Size > 0 || node->IsSplitNode())
+ PushStyleColor(ImGuiCol_ChildBg, IM_COL32(0, 0, 0, 0));
+ PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0.0f);
+ Begin(title, NULL, window_flags);
+ PopStyleVar();
+ if (node->Windows.Size > 0 || node->IsSplitNode())
+ PopStyleColor();
- IM_ASSERT(node->HostWindow);
- IM_ASSERT(node->IsLeafNode());
+ ImGuiWindow* host_window = g.CurrentWindow;
+ host_window->DockNodeAsHost = node;
+ host_window->ChildId = window->GetID(title);
+ node->HostWindow = host_window;
+ node->OnlyNodeWithWindows = NULL;
- // Position window
- SetNextWindowPos(node->Pos);
- SetNextWindowSize(node->Size);
- g.NextWindowData.PosUndock = false; // Cancel implicit undocking of SetNextWindowPos()
+ IM_ASSERT(node->IsRootNode());
+ DockNodeUpdate(node);
- window->DockIsActive = true;
- window->DockTabIsVisible = false;
- if (node->Flags & ImGuiDockNodeFlags_KeepAliveOnly)
- return;
+ End();
+}
- // When the window is selected we mark it as visible.
- if (node->TabBar && node->TabBar->VisibleTabId == window->ID)
- window->DockTabIsVisible = true;
+// Tips: Use with ImGuiDockNodeFlags_PassthruCentralNode!
+// The limitation with this call is that your window won't have a menu bar.
+// Even though we could pass window flags, it would also require the user to be able to call BeginMenuBar() somehow meaning we can't Begin/End in a single function.
+// So if you want a menu bar you need to repeat this code manually ourselves. As with advanced other Docking API, we may change this function signature.
+ImGuiID ImGui::DockSpaceOverViewport(ImGuiViewport* viewport, ImGuiDockNodeFlags dockspace_flags, const ImGuiWindowClass* window_class)
+{
+ if (viewport == NULL)
+ viewport = GetMainViewport();
- // When we are about to select this tab (which will only be visible on the _next frame_), flag it with a non-zero HiddenFramesForResize.
- // This will have the important effect of actually returning true in Begin() and not setting SkipItems, allowing an earlier submission of the window contents.
- // This is analogous to regular windows being hidden from one frame. It is especially important as nested TabBars would otherwise generate flicker in the form
- // of one empty frame.
- // Note that we set HiddenFramesForResize=2 because BeginDocked() is called just before Begin() has a chance to decrement the value. Effectively it'll be a 1 frame thing.
- if (!window->DockTabIsVisible && node->TabBar && node->TabBar->NextSelectedTabId == window->ID)
- window->HiddenFramesForResize = 2;
+ SetNextWindowPos(viewport->Pos);
+ SetNextWindowSize(viewport->Size);
+ SetNextWindowViewport(viewport->ID);
- // Update window flag
- IM_ASSERT((window->Flags & ImGuiWindowFlags_ChildWindow) == 0);
- window->Flags |= ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_AlwaysUseWindowPadding | ImGuiWindowFlags_NoResize;
- if (node->IsHiddenTabBar)
- window->Flags |= ImGuiWindowFlags_NoTitleBar;
- else
- window->Flags &= ~ImGuiWindowFlags_NoTitleBar; // Clear the NoTitleBar flag in case the user set it: confusingly enough we need a title bar height so we are correctly offset, but it won't be displayed!
+ ImGuiWindowFlags host_window_flags = 0;
+ host_window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDocking;
+ host_window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;
+ if (dockspace_flags & ImGuiDockNodeFlags_PassthruCentralNode)
+ host_window_flags |= ImGuiWindowFlags_NoBackground;
- // Save new dock order only if the tab bar is active
- if (node->TabBar)
- window->DockOrder = (short)DockNodeGetTabOrder(window);
+ char label[32];
+ ImFormatString(label, IM_ARRAYSIZE(label), "DockSpaceViewport_%08X", viewport->ID);
- if ((node->WantCloseAll || node->WantCloseTabID == window->ID) && p_open != NULL)
- *p_open = false;
+ PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
+ PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
+ PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
+ Begin(label, NULL, host_window_flags);
+ PopStyleVar(3);
- // Update ChildId to allow returning from Child to Parent with Escape
- ImGuiWindow* parent_window = window->DockNode->HostWindow;
- window->ChildId = parent_window->GetID(window->Name);
+ ImGuiID dockspace_id = GetID("DockSpace");
+ DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags, window_class);
+ End();
+
+ return dockspace_id;
}
-void ImGui::BeginAsDockableDragDropSource(ImGuiWindow* window)
-{
- ImGuiContext& g = *GImGui;
- IM_ASSERT(g.ActiveId == window->MoveId);
+//-----------------------------------------------------------------------------
+// Docking: Builder Functions
+//-----------------------------------------------------------------------------
+// Very early end-user API to manipulate dock nodes.
+// Only available in imgui_internal.h. Expect this API to change/break!
+// It is expected that those functions are all called _before_ the dockspace node submission.
+//-----------------------------------------------------------------------------
+// - DockBuilderDockWindow()
+// - DockBuilderGetNode()
+// - DockBuilderSetNodePos()
+// - DockBuilderSetNodeSize()
+// - DockBuilderAddNode()
+// - DockBuilderRemoveNode()
+// - DockBuilderRemoveNodeChildNodes()
+// - DockBuilderRemoveNodeDockedWindows()
+// - DockBuilderSplitNode()
+// - DockBuilderCopyNodeRec()
+// - DockBuilderCopyNode()
+// - DockBuilderCopyWindowSettings()
+// - DockBuilderCopyDockSpace()
+// - DockBuilderFinish()
+//-----------------------------------------------------------------------------
- window->DC.LastItemId = window->MoveId;
- window = window->RootWindow;
- IM_ASSERT((window->Flags & ImGuiWindowFlags_NoDocking) == 0);
- bool is_drag_docking = (g.IO.ConfigDockingWithShift) || ImRect(0, 0, window->SizeFull.x, GetFrameHeight()).Contains(g.ActiveIdClickOffset);
- if (is_drag_docking && BeginDragDropSource(ImGuiDragDropFlags_SourceNoPreviewTooltip | ImGuiDragDropFlags_SourceNoHoldToOpenOthers | ImGuiDragDropFlags_SourceAutoExpirePayload))
+void ImGui::DockBuilderDockWindow(const char* window_name, ImGuiID node_id)
+{
+ // We don't preserve relative order of multiple docked windows (by clearing DockOrder back to -1)
+ ImGuiID window_id = ImHashStr(window_name);
+ if (ImGuiWindow* window = FindWindowByID(window_id))
{
- SetDragDropPayload(IMGUI_PAYLOAD_TYPE_WINDOW, &window, sizeof(window));
- EndDragDropSource();
+ // Apply to created window
+ SetWindowDock(window, node_id, ImGuiCond_Always);
+ window->DockOrder = -1;
+ }
+ else
+ {
+ // Apply to settings
+ ImGuiWindowSettings* settings = FindWindowSettings(window_id);
+ if (settings == NULL)
+ settings = CreateNewWindowSettings(window_name);
+ settings->DockId = node_id;
+ settings->DockOrder = -1;
}
}
-void ImGui::BeginAsDockableDragDropTarget(ImGuiWindow* window)
+ImGuiDockNode* ImGui::DockBuilderGetNode(ImGuiID node_id)
{
ImGuiContext* ctx = GImGui;
- ImGuiContext& g = *ctx;
+ return DockContextFindNodeByID(ctx, node_id);
+}
- IM_ASSERT((window->Flags & ImGuiWindowFlags_NoDocking) == 0);
- if (!g.DragDropActive)
+void ImGui::DockBuilderSetNodePos(ImGuiID node_id, ImVec2 pos)
+{
+ ImGuiContext* ctx = GImGui;
+ ImGuiDockNode* node = DockContextFindNodeByID(ctx, node_id);
+ if (node == NULL)
return;
+ node->Pos = pos;
+ node->AuthorityForPos = ImGuiDataAuthority_DockNode;
+}
- if (!BeginDragDropTargetCustom(window->Rect(), window->ID))
+void ImGui::DockBuilderSetNodeSize(ImGuiID node_id, ImVec2 size)
+{
+ ImGuiContext* ctx = GImGui;
+ ImGuiDockNode* node = DockContextFindNodeByID(ctx, node_id);
+ if (node == NULL)
return;
+ IM_ASSERT(size.x > 0.0f && size.y > 0.0f);
+ node->Size = node->SizeRef = size;
+ node->AuthorityForSize = ImGuiDataAuthority_DockNode;
+}
- // Peek into the payload before calling AcceptDragDropPayload() so we can handle overlapping dock nodes with filtering
- // (this is a little unusual pattern, normally most code would call AcceptDragDropPayload directly)
- const ImGuiPayload* payload = &g.DragDropPayload;
- if (!payload->IsDataType(IMGUI_PAYLOAD_TYPE_WINDOW) || !DockNodeIsDropAllowed(window, *(ImGuiWindow**)payload->Data))
+// Make sure to use the ImGuiDockNodeFlags_DockSpace flag to create a dockspace node! Otherwise this will create a floating node!
+// - Floating node: you can then call DockBuilderSetNodePos()/DockBuilderSetNodeSize() to position and size the floating node.
+// - Dockspace node: calling DockBuilderSetNodePos() is unnecessary.
+// - If you intend to split a node immediately after creation using DockBuilderSplitNode(), make sure to call DockBuilderSetNodeSize() beforehand!
+// For various reason, the splitting code currently needs a base size otherwise space may not be allocated as precisely as you would expect.
+// - Use (id == 0) to let the system allocate a node identifier.
+ImGuiID ImGui::DockBuilderAddNode(ImGuiID id, ImGuiDockNodeFlags flags)
+{
+ ImGuiContext* ctx = GImGui;
+ ImGuiDockNode* node = NULL;
+ if (flags & ImGuiDockNodeFlags_DockSpace)
{
- EndDragDropTarget();
- return;
+ DockSpace(id, ImVec2(0, 0), (flags & ~ImGuiDockNodeFlags_DockSpace) | ImGuiDockNodeFlags_KeepAliveOnly);
+ node = DockContextFindNodeByID(ctx, id);
}
-
- ImGuiWindow* payload_window = *(ImGuiWindow**)payload->Data;
- if (AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_WINDOW, ImGuiDragDropFlags_AcceptBeforeDelivery | ImGuiDragDropFlags_AcceptNoDrawDefaultRect))
+ else
{
- bool allow_null_target_node = false;
- ImGuiDockNode* target_node = NULL;
- if (window->DockNodeAsHost)
- target_node = DockNodeTreeFindNodeByPos(window->DockNodeAsHost, g.IO.MousePos);
- else if (window->DockNode) // && window->DockIsActive)
- target_node = window->DockNode;
- else
- allow_null_target_node = true; // Dock into a regular window
+ if (id != 0)
+ node = DockContextFindNodeByID(ctx, id);
+ if (!node)
+ node = DockContextAddNode(ctx, id);
+ node->LocalFlags = flags;
+ }
+ node->LastFrameAlive = ctx->FrameCount; // Set this otherwise BeginDocked will undock during the same frame.
+ return node->ID;
+}
- const ImRect explicit_target_rect = (target_node && target_node->TabBar && !target_node->IsHiddenTabBar) ? target_node->TabBar->BarRect : ImRect(window->Pos, window->Pos + ImVec2(window->Size.x, GetFrameHeight()));
- const bool is_explicit_target = g.IO.ConfigDockingWithShift || IsMouseHoveringRect(explicit_target_rect.Min, explicit_target_rect.Max);
+void ImGui::DockBuilderRemoveNode(ImGuiID node_id)
+{
+ ImGuiContext* ctx = GImGui;
+ ImGuiDockNode* node = DockContextFindNodeByID(ctx, node_id);
+ if (node == NULL)
+ return;
+ DockBuilderRemoveNodeDockedWindows(node_id, true);
+ DockBuilderRemoveNodeChildNodes(node_id);
+ if (node->IsCentralNode() && node->ParentNode)
+ node->ParentNode->LocalFlags |= ImGuiDockNodeFlags_CentralNode;
+ DockContextRemoveNode(ctx, node, true);
+}
- // Preview docking request and find out split direction/ratio
- //const bool do_preview = true; // Ignore testing for payload->IsPreview() which removes one frame of delay, but breaks overlapping drop targets within the same window.
- const bool do_preview = payload->IsPreview() || payload->IsDelivery();
- if (do_preview && (target_node != NULL || allow_null_target_node))
- {
- ImGuiDockPreviewData split_inner, split_outer;
- ImGuiDockPreviewData* split_data = &split_inner;
- if (target_node && (target_node->ParentNode || target_node->IsCentralNode))
- if (ImGuiDockNode* root_node = DockNodeGetRootNode(target_node))
- if (DockNodePreviewDockCalc(window, root_node, payload_window, &split_outer, is_explicit_target, true))
- split_data = &split_outer;
- DockNodePreviewDockCalc(window, target_node, payload_window, &split_inner, is_explicit_target, false);
- if (split_data == &split_outer)
- split_inner.IsDropAllowed = false;
+void ImGui::DockBuilderRemoveNodeChildNodes(ImGuiID root_id)
+{
+ ImGuiContext* ctx = GImGui;
+ ImGuiDockContext* dc = ctx->DockContext;
- // Draw inner then outer, so that previewed tab (in inner data) will be behind the outer drop boxes
- DockNodePreviewDockRender(window, target_node, payload_window, &split_inner);
- DockNodePreviewDockRender(window, target_node, payload_window, &split_outer);
+ ImGuiDockNode* root_node = root_id ? DockContextFindNodeByID(ctx, root_id) : NULL;
+ if (root_id && root_node == NULL)
+ return;
+ bool has_central_node = false;
- // Queue docking request
- if (split_data->IsDropAllowed && payload->IsDelivery())
- DockContextQueueDock(ctx, window, split_data->SplitNode, payload_window, split_data->SplitDir, split_data->SplitRatio, split_data == &split_outer);
+ ImGuiDataAuthority backup_root_node_authority_for_pos = root_node ? root_node->AuthorityForPos : ImGuiDataAuthority_Auto;
+ ImGuiDataAuthority backup_root_node_authority_for_size = root_node ? root_node->AuthorityForSize : ImGuiDataAuthority_Auto;
+
+ // Process active windows
+ ImVector nodes_to_remove;
+ for (int n = 0; n < dc->Nodes.Data.Size; n++)
+ if (ImGuiDockNode* node = (ImGuiDockNode*)dc->Nodes.Data[n].val_p)
+ {
+ bool want_removal = (root_id == 0) || (node->ID != root_id && DockNodeGetRootNode(node)->ID == root_id);
+ if (want_removal)
+ {
+ if (node->IsCentralNode())
+ has_central_node = true;
+ if (root_id != 0)
+ DockContextQueueNotifyRemovedNode(ctx, node);
+ if (root_node)
+ DockNodeMoveWindows(root_node, node);
+ nodes_to_remove.push_back(node);
+ }
}
+
+ // DockNodeMoveWindows->DockNodeAddWindow will normally set those when reaching two windows (which is only adequate during interactive merge)
+ // Make sure we don't lose our current pos/size. (FIXME-DOCK: Consider tidying up that code in DockNodeAddWindow instead)
+ if (root_node)
+ {
+ root_node->AuthorityForPos = backup_root_node_authority_for_pos;
+ root_node->AuthorityForSize = backup_root_node_authority_for_size;
}
- EndDragDropTarget();
-}
-//-----------------------------------------------------------------------------
-// Docking: Settings
-//-----------------------------------------------------------------------------
+ // Apply to settings
+ for (int settings_n = 0; settings_n < ctx->SettingsWindows.Size; settings_n++)
+ if (ImGuiID window_settings_dock_id = ctx->SettingsWindows[settings_n].DockId)
+ for (int n = 0; n < nodes_to_remove.Size; n++)
+ if (nodes_to_remove[n]->ID == window_settings_dock_id)
+ {
+ ctx->SettingsWindows[settings_n].DockId = root_id;
+ break;
+ }
-static void ImGui::DockSettingsRenameNodeReferences(ImGuiID old_node_id, ImGuiID new_node_id)
+ // Not really efficient, but easier to destroy a whole hierarchy considering DockContextRemoveNode is attempting to merge nodes
+ if (nodes_to_remove.Size > 1)
+ ImQsort(nodes_to_remove.Data, nodes_to_remove.Size, sizeof(ImGuiDockNode*), DockNodeComparerDepthMostFirst);
+ for (int n = 0; n < nodes_to_remove.Size; n++)
+ DockContextRemoveNode(ctx, nodes_to_remove[n], false);
+
+ if (root_id == 0)
+ {
+ dc->Nodes.Clear();
+ dc->Requests.clear();
+ }
+ else if (has_central_node)
+ {
+ root_node->LocalFlags |= ImGuiDockNodeFlags_CentralNode;
+ root_node->CentralNode = root_node;
+ }
+}
+
+void ImGui::DockBuilderRemoveNodeDockedWindows(ImGuiID root_id, bool clear_persistent_docking_references)
{
- ImGuiContext& g = *GImGui;
- for (int window_n = 0; window_n < g.Windows.Size; window_n++)
+ // Clear references in settings
+ ImGuiContext* ctx = GImGui;
+ ImGuiContext& g = *ctx;
+ if (clear_persistent_docking_references)
{
- ImGuiWindow* window = g.Windows[window_n];
- if (window->DockId == old_node_id && window->DockNode == NULL)
- window->DockId = new_node_id;
+ for (int n = 0; n < g.SettingsWindows.Size; n++)
+ {
+ ImGuiWindowSettings* settings = &g.SettingsWindows[n];
+ bool want_removal = (root_id == 0) || (settings->DockId == root_id);
+ if (!want_removal && settings->DockId != 0)
+ if (ImGuiDockNode* node = DockContextFindNodeByID(ctx, settings->DockId))
+ if (DockNodeGetRootNode(node)->ID == root_id)
+ want_removal = true;
+ if (want_removal)
+ settings->DockId = 0;
+ }
}
- for (int settings_n = 0; settings_n < g.SettingsWindows.Size; settings_n++) // FIXME-OPT: We could remove this loop by storing the index in the map
+
+ // Clear references in windows
+ for (int n = 0; n < g.Windows.Size; n++)
{
- ImGuiWindowSettings* window_settings = &g.SettingsWindows[settings_n];
- if (window_settings->DockId == old_node_id)
- window_settings->DockId = new_node_id;
+ ImGuiWindow* window = g.Windows[n];
+ bool want_removal = (root_id == 0) || (window->DockNode && DockNodeGetRootNode(window->DockNode)->ID == root_id) || (window->DockNodeAsHost && window->DockNodeAsHost->ID == root_id);
+ if (want_removal)
+ {
+ const ImGuiID backup_dock_id = window->DockId;
+ DockContextProcessUndockWindow(ctx, window, clear_persistent_docking_references);
+ if (!clear_persistent_docking_references)
+ IM_ASSERT(window->DockId == backup_dock_id);
+ }
}
}
-// Remove references stored in ImGuiWindowSettings to the given ImGuiDockNodeSettings
-static void ImGui::DockSettingsRemoveNodeReferences(ImGuiID* node_ids, int node_ids_count)
+// If 'out_id_at_dir' or 'out_id_at_opposite_dir' are non NULL, the function will write out the ID of the two new nodes created.
+// Return value is ID of the node at the specified direction, so same as (*out_id_at_dir) if that pointer is set.
+// FIXME-DOCK: We are not exposing nor using split_outer.
+ImGuiID ImGui::DockBuilderSplitNode(ImGuiID id, ImGuiDir split_dir, float size_ratio_for_node_at_dir, ImGuiID* out_id_at_dir, ImGuiID* out_id_at_opposite_dir)
{
- ImGuiContext& g = *GImGui;
- int found = 0;
- for (int settings_n = 0; settings_n < g.SettingsWindows.Size; settings_n++) // FIXME-OPT: We could remove this loop by storing the index in the map
+ ImGuiContext* ctx = GImGui;
+ IM_ASSERT(split_dir != ImGuiDir_None);
+ IMGUI_DEBUG_LOG_DOCKING("DockBuilderSplitNode node 0x%08X, split_dir %d\n", id, split_dir);
+
+ ImGuiDockNode* node = DockContextFindNodeByID(ctx, id);
+ if (node == NULL)
{
- ImGuiWindowSettings* window_settings = &g.SettingsWindows[settings_n];
- for (int node_n = 0; node_n < node_ids_count; node_n++)
- if (window_settings->DockId == node_ids[node_n])
- {
- window_settings->DockId = 0;
- window_settings->DockOrder = -1;
- if (++found < node_ids_count)
- break;
- return;
- }
+ IM_ASSERT(node != NULL);
+ return 0;
}
+
+ IM_ASSERT(!node->IsSplitNode()); // Assert if already Split
+
+ ImGuiDockRequest req;
+ req.Type = ImGuiDockRequestType_Split;
+ req.DockTargetWindow = NULL;
+ req.DockTargetNode = node;
+ req.DockPayload = NULL;
+ req.DockSplitDir = split_dir;
+ req.DockSplitRatio = ImSaturate((split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Up) ? size_ratio_for_node_at_dir : 1.0f - size_ratio_for_node_at_dir);
+ req.DockSplitOuter = false;
+ DockContextProcessDock(ctx, &req);
+
+ ImGuiID id_at_dir = node->ChildNodes[(split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Up) ? 0 : 1]->ID;
+ ImGuiID id_at_opposite_dir = node->ChildNodes[(split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Up) ? 1 : 0]->ID;
+ if (out_id_at_dir)
+ *out_id_at_dir = id_at_dir;
+ if (out_id_at_opposite_dir)
+ *out_id_at_opposite_dir = id_at_opposite_dir;
+ return id_at_dir;
}
-static ImGuiDockNodeSettings* ImGui::DockSettingsFindNodeSettings(ImGuiContext* ctx, ImGuiID id)
+static ImGuiDockNode* DockBuilderCopyNodeRec(ImGuiDockNode* src_node, ImGuiID dst_node_id_if_known, ImVector* out_node_remap_pairs)
{
- // FIXME-OPT
- ImGuiDockContext* dc = ctx->DockContext;
- for (int n = 0; n < dc->SettingsNodes.Size; n++)
- if (dc->SettingsNodes[n].ID == id)
- return &dc->SettingsNodes[n];
- return NULL;
+ ImGuiContext* ctx = GImGui;
+ ImGuiDockNode* dst_node = ImGui::DockContextAddNode(ctx, dst_node_id_if_known);
+ dst_node->SharedFlags = src_node->SharedFlags;
+ dst_node->LocalFlags = src_node->LocalFlags;
+ dst_node->Pos = src_node->Pos;
+ dst_node->Size = src_node->Size;
+ dst_node->SizeRef = src_node->SizeRef;
+ dst_node->SplitAxis = src_node->SplitAxis;
+
+ out_node_remap_pairs->push_back(src_node->ID);
+ out_node_remap_pairs->push_back(dst_node->ID);
+
+ for (int child_n = 0; child_n < IM_ARRAYSIZE(src_node->ChildNodes); child_n++)
+ if (src_node->ChildNodes[child_n])
+ {
+ dst_node->ChildNodes[child_n] = DockBuilderCopyNodeRec(src_node->ChildNodes[child_n], 0, out_node_remap_pairs);
+ dst_node->ChildNodes[child_n]->ParentNode = dst_node;
+ }
+
+ IMGUI_DEBUG_LOG_DOCKING("Fork node %08X -> %08X (%d childs)\n", src_node->ID, dst_node->ID, dst_node->IsSplitNode() ? 2 : 0);
+ return dst_node;
}
-static void* ImGui::DockSettingsHandler_ReadOpen(ImGuiContext*, ImGuiSettingsHandler*, const char* name)
+void ImGui::DockBuilderCopyNode(ImGuiID src_node_id, ImGuiID dst_node_id, ImVector* out_node_remap_pairs)
{
- if (strcmp(name, "Data") != 0)
- return NULL;
- return (void*)1;
+ ImGuiContext* ctx = GImGui;
+ IM_ASSERT(src_node_id != 0);
+ IM_ASSERT(dst_node_id != 0);
+ IM_ASSERT(out_node_remap_pairs != NULL);
+
+ ImGuiDockNode* src_node = DockContextFindNodeByID(ctx, src_node_id);
+ IM_ASSERT(src_node != NULL);
+
+ out_node_remap_pairs->clear();
+ DockBuilderRemoveNode(dst_node_id);
+ DockBuilderCopyNodeRec(src_node, dst_node_id, out_node_remap_pairs);
+
+ IM_ASSERT((out_node_remap_pairs->Size % 2) == 0);
}
-static void ImGui::DockSettingsHandler_ReadLine(ImGuiContext* ctx, ImGuiSettingsHandler*, void*, const char* line)
+void ImGui::DockBuilderCopyWindowSettings(const char* src_name, const char* dst_name)
{
- char c = 0;
- int x = 0, y = 0;
- int r = 0;
-
- // Parsing, e.g.
- // " DockNode ID=0x00000001 Pos=383,193 Size=201,322 Split=Y,0.506 "
- // " DockNode ID=0x00000002 Parent=0x00000001 "
- ImGuiDockNodeSettings node;
- line = ImStrSkipBlank(line);
- if (strncmp(line, "DockNode", 8) == 0) { line = ImStrSkipBlank(line + strlen("DockNode")); }
- else if (strncmp(line, "DockSpace", 9) == 0) { line = ImStrSkipBlank(line + strlen("DockSpace")); node.IsDockSpace = true; }
- else return;
- if (sscanf(line, "ID=0x%08X%n", &node.ID, &r) == 1) { line += r; } else return;
- if (sscanf(line, " Parent=0x%08X%n", &node.ParentID, &r) == 1) { line += r; if (node.ParentID == 0) return; }
- if (node.ParentID == 0)
+ ImGuiWindow* src_window = FindWindowByName(src_name);
+ if (src_window == NULL)
+ return;
+ if (ImGuiWindow* dst_window = FindWindowByName(dst_name))
{
- if (sscanf(line, " Pos=%i,%i%n", &x, &y, &r) == 2) { line += r; node.Pos = ImVec2ih((short)x, (short)y); } else return;
- if (sscanf(line, " Size=%i,%i%n", &x, &y, &r) == 2) { line += r; node.Size = ImVec2ih((short)x, (short)y); } else return;
+ dst_window->Pos = src_window->Pos;
+ dst_window->Size = src_window->Size;
+ dst_window->SizeFull = src_window->SizeFull;
+ dst_window->Collapsed = src_window->Collapsed;
}
- else
+ else if (ImGuiWindowSettings* dst_settings = FindOrCreateWindowSettings(dst_name))
{
- if (sscanf(line, " SizeRef=%i,%i%n", &x, &y, &r) == 2) { line += r; node.SizeRef = ImVec2ih((short)x, (short)y); }
+ ImVec2ih window_pos_2ih = ImVec2ih(src_window->Pos);
+ if (src_window->ViewportId != 0 && src_window->ViewportId != IMGUI_VIEWPORT_DEFAULT_ID)
+ {
+ dst_settings->ViewportPos = window_pos_2ih;
+ dst_settings->ViewportId = src_window->ViewportId;
+ dst_settings->Pos = ImVec2ih(0, 0);
+ }
+ else
+ {
+ dst_settings->Pos = window_pos_2ih;
+ }
+ dst_settings->Size = ImVec2ih(src_window->SizeFull);
+ dst_settings->Collapsed = src_window->Collapsed;
}
- if (sscanf(line, " Split=%c%n", &c, &r) == 1) { line += r; if (c == 'X') node.SplitAxis = ImGuiAxis_X; else if (c == 'Y') node.SplitAxis = ImGuiAxis_Y; }
- if (sscanf(line, " CentralNode=%d%n", &x, &r) == 1) { line += r; node.IsCentralNode = (x != 0); }
- if (sscanf(line, " HiddenTabBar=%d%n", &x, &r) == 1) { line += r; node.IsHiddenTabBar = (x != 0); }
- if (sscanf(line, " SelectedTab=0x%08X%n", &node.SelectedTabID,&r) == 1) { line += r; }
- ImGuiDockContext* dc = ctx->DockContext;
- if (node.ParentID != 0)
- if (ImGuiDockNodeSettings* parent_settings = DockSettingsFindNodeSettings(ctx, node.ParentID))
- node.Depth = parent_settings->Depth + 1;
- dc->SettingsNodes.push_back(node);
}
-static void DockSettingsHandler_DockNodeToSettings(ImGuiDockContext* dc, ImGuiDockNode* node, int depth)
+// FIXME: Will probably want to change this signature, in particular how the window remapping pairs are passed.
+void ImGui::DockBuilderCopyDockSpace(ImGuiID src_dockspace_id, ImGuiID dst_dockspace_id, ImVector* in_window_remap_pairs)
{
- ImGuiDockNodeSettings node_settings;
- IM_ASSERT(depth < (1 << (sizeof(node_settings.Depth) << 3)));
- node_settings.ID = node->ID;
- node_settings.ParentID = node->ParentNode ? node->ParentNode->ID : 0;
- node_settings.SelectedTabID = node->SelectedTabID;
- node_settings.SplitAxis = node->IsSplitNode() ? (char)node->SplitAxis : ImGuiAxis_None;
- node_settings.Depth = (char)depth;
- node_settings.IsDockSpace = (char)node->IsDockSpace();
- node_settings.IsCentralNode = (char)node->IsCentralNode;
- node_settings.IsHiddenTabBar = (char)node->IsHiddenTabBar;
- node_settings.Pos = ImVec2ih((short)node->Pos.x, (short)node->Pos.y);
- node_settings.Size = ImVec2ih((short)node->Size.x, (short)node->Size.y);
- node_settings.SizeRef = ImVec2ih((short)node->SizeRef.x, (short)node->SizeRef.y);
- dc->SettingsNodes.push_back(node_settings);
- if (node->ChildNodes[0])
- DockSettingsHandler_DockNodeToSettings(dc, node->ChildNodes[0], depth + 1);
- if (node->ChildNodes[1])
- DockSettingsHandler_DockNodeToSettings(dc, node->ChildNodes[1], depth + 1);
-}
+ IM_ASSERT(src_dockspace_id != 0);
+ IM_ASSERT(dst_dockspace_id != 0);
+ IM_ASSERT(in_window_remap_pairs != NULL);
+ IM_ASSERT((in_window_remap_pairs->Size % 2) == 0);
-static void ImGui::DockSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* buf)
-{
- ImGuiContext& g = *ctx;
- ImGuiDockContext* dc = g.DockContext;
- if (!(g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable))
- return;
+ // Duplicate entire dock
+ // FIXME: When overwriting dst_dockspace_id, windows that aren't part of our dockspace window class but that are docked in a same node will be split apart,
+ // whereas we could attempt to at least keep them together in a new, same floating node.
+ ImVector node_remap_pairs;
+ DockBuilderCopyNode(src_dockspace_id, dst_dockspace_id, &node_remap_pairs);
- // Gather settings data
- // (unlike our windows settings, because nodes are always built we can do a full rewrite of the SettingsNode buffer)
- dc->SettingsNodes.resize(0);
- dc->SettingsNodes.reserve(dc->Nodes.Data.Size);
- for (int n = 0; n < dc->Nodes.Data.Size; n++)
- if (ImGuiDockNode* node = (ImGuiDockNode*)dc->Nodes.Data[n].val_p)
- if (node->IsRootNode())
- DockSettingsHandler_DockNodeToSettings(dc, node, 0);
+ // Attempt to transition all the upcoming windows associated to dst_dockspace_id into the newly created hierarchy of dock nodes
+ // (The windows associated to src_dockspace_id are staying in place)
+ ImVector src_windows;
+ for (int remap_window_n = 0; remap_window_n < in_window_remap_pairs->Size; remap_window_n += 2)
+ {
+ const char* src_window_name = (*in_window_remap_pairs)[remap_window_n];
+ const char* dst_window_name = (*in_window_remap_pairs)[remap_window_n + 1];
+ ImGuiID src_window_id = ImHashStr(src_window_name);
+ src_windows.push_back(src_window_id);
- int max_depth = 0;
- for (int node_n = 0; node_n < dc->SettingsNodes.Size; node_n++)
- max_depth = ImMax((int)dc->SettingsNodes[node_n].Depth, max_depth);
+ // Search in the remapping tables
+ ImGuiID src_dock_id = 0;
+ if (ImGuiWindow* src_window = FindWindowByID(src_window_id))
+ src_dock_id = src_window->DockId;
+ else if (ImGuiWindowSettings* src_window_settings = FindWindowSettings(src_window_id))
+ src_dock_id = src_window_settings->DockId;
+ ImGuiID dst_dock_id = 0;
+ for (int dock_remap_n = 0; dock_remap_n < node_remap_pairs.Size; dock_remap_n += 2)
+ if (node_remap_pairs[dock_remap_n] == src_dock_id)
+ {
+ dst_dock_id = node_remap_pairs[dock_remap_n + 1];
+ //node_remap_pairs[dock_remap_n] = node_remap_pairs[dock_remap_n + 1] = 0; // Clear
+ break;
+ }
- // Write to text buffer
- buf->appendf("[%s][Data]\n", handler->TypeName);
- for (int node_n = 0; node_n < dc->SettingsNodes.Size; node_n++)
- {
-#if IMGUI_DEBUG_DOCKING_INI
- const int line_start_pos = buf->size();
-#endif
- const ImGuiDockNodeSettings* node_settings = &dc->SettingsNodes[node_n];
- buf->appendf("%*s%s%*s", node_settings->Depth * 2, "", node_settings->IsDockSpace ? "DockSpace" : "DockNode ", (max_depth - node_settings->Depth) * 2, ""); // Text align nodes to facilitate looking at .ini file
- buf->appendf(" ID=0x%08X", node_settings->ID);
- if (node_settings->ParentID)
- buf->appendf(" Parent=0x%08X SizeRef=%d,%d", node_settings->ParentID, node_settings->SizeRef.x, node_settings->SizeRef.y);
+ if (dst_dock_id != 0)
+ {
+ // Docked windows gets redocked into the new node hierarchy.
+ IMGUI_DEBUG_LOG_DOCKING("Remap live window '%s' 0x%08X -> '%s' 0x%08X\n", src_window_name, src_dock_id, dst_window_name, dst_dock_id);
+ DockBuilderDockWindow(dst_window_name, dst_dock_id);
+ }
else
- buf->appendf(" Pos=%d,%d Size=%d,%d", node_settings->Pos.x, node_settings->Pos.y, node_settings->Size.x, node_settings->Size.y);
- if (node_settings->SplitAxis != ImGuiAxis_None)
- buf->appendf(" Split=%c", (node_settings->SplitAxis == ImGuiAxis_X) ? 'X' : 'Y');
- if (node_settings->IsCentralNode)
- buf->appendf(" CentralNode=1");
- if (node_settings->IsHiddenTabBar)
- buf->appendf(" HiddenTabBar=1");
- if (node_settings->SelectedTabID)
- buf->appendf(" SelectedTab=0x%08X", node_settings->SelectedTabID);
-
-#if IMGUI_DEBUG_DOCKING_INI
- // [DEBUG] Include comments in the .ini file to ease debugging
- if (ImGuiDockNode* node = DockContextFindNodeByID(ctx, node_settings->ID))
{
- buf->appendf("%*s", ImMax(2, (line_start_pos + 92) - buf->size()), ""); // Align everything
- if (node->IsDockSpace && node->HostWindow && node->HostWindow->ParentWindow)
- buf->appendf(" ; in '%s'", node->HostWindow->ParentWindow->Name);
- int contains_window = 0;
- for (int window_n = 0; window_n < ctx->SettingsWindows.Size; window_n++)
- if (ctx->SettingsWindows[window_n].DockId == node_settings->ID)
- {
- if (contains_window++ == 0)
- buf->appendf(" ; contains ");
- buf->appendf("'%s' ", ctx->SettingsWindows[window_n].Name);
- }
+ // Floating windows gets their settings transferred (regardless of whether the new window already exist or not)
+ // When this is leading to a Copy and not a Move, we would get two overlapping floating windows. Could we possibly dock them together?
+ IMGUI_DEBUG_LOG_DOCKING("Remap window settings '%s' -> '%s'\n", src_window_name, dst_window_name);
+ DockBuilderCopyWindowSettings(src_window_name, dst_window_name);
}
-#endif
- buf->appendf("\n");
}
- buf->appendf("\n");
+
+ // Anything else in the source nodes of 'node_remap_pairs' are windows that were docked in src_dockspace_id but are not owned by it (unaffiliated windows, e.g. "ImGui Demo")
+ // Find those windows and move to them to the cloned dock node. This may be optional?
+ for (int dock_remap_n = 0; dock_remap_n < node_remap_pairs.Size; dock_remap_n += 2)
+ if (ImGuiID src_dock_id = node_remap_pairs[dock_remap_n])
+ {
+ ImGuiID dst_dock_id = node_remap_pairs[dock_remap_n + 1];
+ ImGuiDockNode* node = DockBuilderGetNode(src_dock_id);
+ for (int window_n = 0; window_n < node->Windows.Size; window_n++)
+ {
+ ImGuiWindow* window = node->Windows[window_n];
+ if (src_windows.contains(window->ID))
+ continue;
+
+ // Docked windows gets redocked into the new node hierarchy.
+ IMGUI_DEBUG_LOG_DOCKING("Remap window '%s' %08X -> %08X\n", window->Name, src_dock_id, dst_dock_id);
+ DockBuilderDockWindow(window->Name, dst_dock_id);
+ }
+ }
+}
+
+void ImGui::DockBuilderFinish(ImGuiID root_id)
+{
+ ImGuiContext* ctx = GImGui;
+ //DockContextRebuild(ctx);
+ DockContextBuildAddWindowsToNodes(ctx, root_id);
}
//-----------------------------------------------------------------------------
-// [SECTION] LOGGING/CAPTURING
+// Docking: Begin/End Support Functions (called from Begin/End)
+//-----------------------------------------------------------------------------
+// - GetWindowAlwaysWantOwnTabBar()
+// - BeginDocked()
+// - BeginAsDockableDragDropSource()
+// - BeginAsDockableDragDropTarget()
//-----------------------------------------------------------------------------
-// Pass text data straight to log (without being displayed)
-void ImGui::LogText(const char* fmt, ...)
+bool ImGui::GetWindowAlwaysWantOwnTabBar(ImGuiWindow* window)
{
ImGuiContext& g = *GImGui;
- if (!g.LogEnabled)
- return;
-
- va_list args;
- va_start(args, fmt);
- if (g.LogFile)
- vfprintf(g.LogFile, fmt, args);
- else
- g.LogClipboard.appendfv(fmt, args);
- va_end(args);
+ if (g.IO.ConfigDockingAlwaysTabBar || window->WindowClass.DockingAlwaysTabBar)
+ if ((window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoDocking)) == 0)
+ if (!window->IsFallbackWindow) // We don't support AlwaysTabBar on the fallback/implicit window to avoid unused dock-node overhead/noise
+ return true;
+ return false;
}
-// Internal version that takes a position to decide on newline placement and pad items according to their depth.
-// We split text into individual lines to add current tree level padding
-void ImGui::LogRenderedText(const ImVec2* ref_pos, const char* text, const char* text_end)
+static ImGuiDockNode* ImGui::DockContextBindNodeToWindow(ImGuiContext* ctx, ImGuiWindow* window)
{
- ImGuiContext& g = *GImGui;
- ImGuiWindow* window = g.CurrentWindow;
+ ImGuiContext& g = *ctx;
+ ImGuiDockNode* node = DockContextFindNodeByID(ctx, window->DockId);
+ IM_ASSERT(window->DockNode == NULL);
- if (!text_end)
- text_end = FindRenderedTextEnd(text, text_end);
+ // We should not be docking into a split node (SetWindowDock should avoid this)
+ if (node && node->IsSplitNode())
+ {
+ DockContextProcessUndockWindow(ctx, window);
+ return NULL;
+ }
- const bool log_new_line = ref_pos && (ref_pos->y > window->DC.LogLinePosY + 1);
- if (ref_pos)
- window->DC.LogLinePosY = ref_pos->y;
+ // Create node
+ if (node == NULL)
+ {
+ node = DockContextAddNode(ctx, window->DockId);
+ node->AuthorityForPos = node->AuthorityForSize = node->AuthorityForViewport = ImGuiDataAuthority_Window;
+ node->LastFrameAlive = g.FrameCount;
+ }
- const char* text_remaining = text;
- if (g.LogStartDepth > window->DC.TreeDepth) // Re-adjust padding if we have popped out of our starting depth
- g.LogStartDepth = window->DC.TreeDepth;
- const int tree_depth = (window->DC.TreeDepth - g.LogStartDepth);
- for (;;)
+ // If the node just turned visible and is part of a hierarchy, it doesn't have a Size assigned by DockNodeTreeUpdatePosSize() yet,
+ // so we're forcing a Pos/Size update from the first ancestor that is already visible (often it will be the root node).
+ // If we don't do this, the window will be assigned a zero-size on its first frame, which won't ideally warm up the layout.
+ // This is a little wonky because we don't normally update the Pos/Size of visible node mid-frame.
+ if (!node->IsVisible)
{
- // Split the string. Each new line (after a '\n') is followed by spacing corresponding to the current depth of our log entry.
- const char* line_start = text_remaining;
- const char* line_end = ImStreolRange(line_start, text_end);
- const bool is_first_line = (line_start == text);
- const bool is_last_line = (line_end == text_end);
- if (!is_last_line || (line_start != line_end))
+ ImGuiDockNode* ancestor_node = node;
+ while (!ancestor_node->IsVisible)
{
- const int char_count = (int)(line_end - line_start);
- if (log_new_line || !is_first_line)
- LogText(IM_NEWLINE "%*s%.*s", tree_depth*4, "", char_count, line_start);
- else
- LogText(" %.*s", char_count, line_start);
+ ancestor_node->IsVisible = true;
+ ancestor_node->MarkedForPosSizeWrite = true;
+ if (ancestor_node->ParentNode)
+ ancestor_node = ancestor_node->ParentNode;
}
-
- if (is_last_line)
- break;
- text_remaining = line_end + 1;
+ IM_ASSERT(ancestor_node->Size.x > 0.0f && ancestor_node->Size.y > 0.0f);
+ DockNodeTreeUpdatePosSize(ancestor_node, ancestor_node->Pos, ancestor_node->Size, true);
}
-}
-
-// Start logging ImGui output to TTY
-void ImGui::LogToTTY(int max_depth)
-{
- ImGuiContext& g = *GImGui;
- if (g.LogEnabled)
- return;
- ImGuiWindow* window = g.CurrentWindow;
- IM_ASSERT(g.LogFile == NULL);
- g.LogFile = stdout;
- g.LogEnabled = true;
- g.LogStartDepth = window->DC.TreeDepth;
- if (max_depth >= 0)
- g.LogAutoExpandMaxDepth = max_depth;
+ // Add window to node
+ DockNodeAddWindow(node, window, true);
+ IM_ASSERT(node == window->DockNode);
+ return node;
}
-// Start logging ImGui output to given file
-void ImGui::LogToFile(int max_depth, const char* filename)
+void ImGui::BeginDocked(ImGuiWindow* window, bool* p_open)
{
- ImGuiContext& g = *GImGui;
- if (g.LogEnabled)
- return;
- ImGuiWindow* window = g.CurrentWindow;
+ ImGuiContext* ctx = GImGui;
+ ImGuiContext& g = *ctx;
- if (!filename)
+ const bool auto_dock_node = GetWindowAlwaysWantOwnTabBar(window);
+ if (auto_dock_node)
{
- filename = g.IO.LogFilename;
- if (!filename)
+ if (window->DockId == 0)
+ {
+ IM_ASSERT(window->DockNode == NULL);
+ window->DockId = DockContextGenNodeID(ctx);
+ }
+ }
+ else
+ {
+ // Calling SetNextWindowPos() undock windows by default (by setting PosUndock)
+ bool want_undock = false;
+ want_undock |= (window->Flags & ImGuiWindowFlags_NoDocking) != 0;
+ want_undock |= (g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasPos) && (window->SetWindowPosAllowFlags & g.NextWindowData.PosCond) && g.NextWindowData.PosUndock;
+ if (want_undock)
+ {
+ DockContextProcessUndockWindow(ctx, window);
return;
+ }
}
- IM_ASSERT(g.LogFile == NULL);
- g.LogFile = ImFileOpen(filename, "ab");
- if (g.LogFile == NULL)
+ // Bind to our dock node
+ ImGuiDockNode* node = window->DockNode;
+ if (node != NULL)
+ IM_ASSERT(window->DockId == node->ID);
+ if (window->DockId != 0 && node == NULL)
{
- IM_ASSERT(g.LogFile != NULL); // Consider this an error
- return;
+ node = DockContextBindNodeToWindow(ctx, window);
+ if (node == NULL)
+ return;
}
- g.LogEnabled = true;
- g.LogStartDepth = window->DC.TreeDepth;
- if (max_depth >= 0)
- g.LogAutoExpandMaxDepth = max_depth;
-}
-// Start logging ImGui output to clipboard
-void ImGui::LogToClipboard(int max_depth)
-{
- ImGuiContext& g = *GImGui;
- if (g.LogEnabled)
+#if 0
+ // Undock if the ImGuiDockNodeFlags_NoDockingInCentralNode got set
+ if (node->IsCentralNode && (node->Flags & ImGuiDockNodeFlags_NoDockingInCentralNode))
+ {
+ DockContextProcessUndockWindow(ctx, window);
return;
- ImGuiWindow* window = g.CurrentWindow;
-
- IM_ASSERT(g.LogFile == NULL);
- g.LogFile = NULL;
- g.LogEnabled = true;
- g.LogStartDepth = window->DC.TreeDepth;
- if (max_depth >= 0)
- g.LogAutoExpandMaxDepth = max_depth;
-}
+ }
+#endif
-void ImGui::LogFinish()
-{
- ImGuiContext& g = *GImGui;
- if (!g.LogEnabled)
+ // Undock if our dockspace node disappeared
+ // Note how we are testing for LastFrameAlive and NOT LastFrameActive. A DockSpace node can be maintained alive while being inactive with ImGuiDockNodeFlags_KeepAliveOnly.
+ if (node->LastFrameAlive < g.FrameCount)
+ {
+ // If the window has been orphaned, transition the docknode to an implicit node processed in DockContextUpdateDocking()
+ ImGuiDockNode* root_node = DockNodeGetRootNode(node);
+ if (root_node->LastFrameAlive < g.FrameCount)
+ {
+ DockContextProcessUndockWindow(ctx, window);
+ }
+ else
+ {
+ window->DockIsActive = true;
+ window->DockTabIsVisible = false;
+ }
return;
+ }
- LogText(IM_NEWLINE);
- if (g.LogFile != NULL)
+ // Fast path return. It is common for windows to hold on a persistent DockId but be the only visible window,
+ // and never create neither a host window neither a tab bar.
+ // FIXME-DOCK: replace ->HostWindow NULL compare with something more explicit (~was initially intended as a first frame test)
+ if (node->HostWindow == NULL)
{
- if (g.LogFile == stdout)
- fflush(g.LogFile);
- else
- fclose(g.LogFile);
- g.LogFile = NULL;
+ window->DockIsActive = (node->State == ImGuiDockNodeState_HostWindowHiddenBecauseWindowsAreResizing);
+ window->DockTabIsVisible = false;
+ return;
}
- if (g.LogClipboard.size() > 1)
+
+ IM_ASSERT(node->HostWindow);
+ IM_ASSERT(node->IsLeafNode());
+ IM_ASSERT(node->Size.x > 0.0f && node->Size.y > 0.0f);
+ node->State = ImGuiDockNodeState_HostWindowVisible;
+
+ // Undock if we are submitted earlier than the host window
+ if (window->BeginOrderWithinContext < node->HostWindow->BeginOrderWithinContext)
{
- SetClipboardText(g.LogClipboard.begin());
- g.LogClipboard.clear();
+ DockContextProcessUndockWindow(ctx, window);
+ return;
}
- g.LogEnabled = false;
-}
-// Helper to display logging buttons
-void ImGui::LogButtons()
-{
- ImGuiContext& g = *GImGui;
+ // Position window
+ SetNextWindowPos(node->Pos);
+ SetNextWindowSize(node->Size);
+ g.NextWindowData.PosUndock = false; // Cancel implicit undocking of SetNextWindowPos()
+ window->DockIsActive = true;
+ window->DockTabIsVisible = false;
+ if (node->SharedFlags & ImGuiDockNodeFlags_KeepAliveOnly)
+ return;
- PushID("LogButtons");
- const bool log_to_tty = Button("Log To TTY"); SameLine();
- const bool log_to_file = Button("Log To File"); SameLine();
- const bool log_to_clipboard = Button("Log To Clipboard"); SameLine();
- PushItemWidth(80.0f);
- PushAllowKeyboardFocus(false);
- SliderInt("Depth", &g.LogAutoExpandMaxDepth, 0, 9, NULL);
- PopAllowKeyboardFocus();
- PopItemWidth();
- PopID();
+ // When the window is selected we mark it as visible.
+ if (node->VisibleWindow == window)
+ window->DockTabIsVisible = true;
- // Start logging at the end of the function so that the buttons don't appear in the log
- if (log_to_tty)
- LogToTTY(g.LogAutoExpandMaxDepth);
- if (log_to_file)
- LogToFile(g.LogAutoExpandMaxDepth, g.IO.LogFilename);
- if (log_to_clipboard)
- LogToClipboard(g.LogAutoExpandMaxDepth);
-}
+ // Update window flag
+ IM_ASSERT((window->Flags & ImGuiWindowFlags_ChildWindow) == 0);
+ window->Flags |= ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_AlwaysUseWindowPadding | ImGuiWindowFlags_NoResize;
+ if (node->IsHiddenTabBar() || node->IsNoTabBar())
+ window->Flags |= ImGuiWindowFlags_NoTitleBar;
+ else
+ window->Flags &= ~ImGuiWindowFlags_NoTitleBar; // Clear the NoTitleBar flag in case the user set it: confusingly enough we need a title bar height so we are correctly offset, but it won't be displayed!
-//-----------------------------------------------------------------------------
-// [SECTION] SETTINGS
-//-----------------------------------------------------------------------------
+ // Save new dock order only if the tab bar has been visible once.
+ // This allows multiple windows to be created in the same frame and have their respective dock orders preserved.
+ if (node->TabBar && node->TabBar->CurrFrameVisible != -1)
+ window->DockOrder = (short)DockNodeGetTabOrder(window);
-void ImGui::MarkIniSettingsDirty()
-{
- ImGuiContext& g = *GImGui;
- if (g.SettingsDirtyTimer <= 0.0f)
- g.SettingsDirtyTimer = g.IO.IniSavingRate;
+ if ((node->WantCloseAll || node->WantCloseTabID == window->ID) && p_open != NULL)
+ *p_open = false;
+
+ // Update ChildId to allow returning from Child to Parent with Escape
+ ImGuiWindow* parent_window = window->DockNode->HostWindow;
+ window->ChildId = parent_window->GetID(window->Name);
}
-void ImGui::MarkIniSettingsDirty(ImGuiWindow* window)
+void ImGui::BeginAsDockableDragDropSource(ImGuiWindow* window)
{
ImGuiContext& g = *GImGui;
- if (!(window->Flags & ImGuiWindowFlags_NoSavedSettings))
- if (g.SettingsDirtyTimer <= 0.0f)
- g.SettingsDirtyTimer = g.IO.IniSavingRate;
+ IM_ASSERT(g.ActiveId == window->MoveId);
+
+ window->DC.LastItemId = window->MoveId;
+ window = window->RootWindow;
+ IM_ASSERT((window->Flags & ImGuiWindowFlags_NoDocking) == 0);
+ bool is_drag_docking = (g.IO.ConfigDockingWithShift) || ImRect(0, 0, window->SizeFull.x, GetFrameHeight()).Contains(g.ActiveIdClickOffset);
+ if (is_drag_docking && BeginDragDropSource(ImGuiDragDropFlags_SourceNoPreviewTooltip | ImGuiDragDropFlags_SourceNoHoldToOpenOthers | ImGuiDragDropFlags_SourceAutoExpirePayload))
+ {
+ SetDragDropPayload(IMGUI_PAYLOAD_TYPE_WINDOW, &window, sizeof(window));
+ EndDragDropSource();
+ }
}
-ImGuiWindowSettings* ImGui::CreateNewWindowSettings(const char* name)
+void ImGui::BeginAsDockableDragDropTarget(ImGuiWindow* window)
{
- ImGuiContext& g = *GImGui;
- g.SettingsWindows.push_back(ImGuiWindowSettings());
- ImGuiWindowSettings* settings = &g.SettingsWindows.back();
- settings->Name = ImStrdup(name);
- settings->ID = ImHashStr(name, 0);
- return settings;
-}
+ ImGuiContext* ctx = GImGui;
+ ImGuiContext& g = *ctx;
+
+ //IM_ASSERT(window->RootWindow == window); // May also be a DockSpace
+ IM_ASSERT((window->Flags & ImGuiWindowFlags_NoDocking) == 0);
+ if (!g.DragDropActive)
+ return;
+ if (!BeginDragDropTargetCustom(window->Rect(), window->ID))
+ return;
+
+ // Peek into the payload before calling AcceptDragDropPayload() so we can handle overlapping dock nodes with filtering
+ // (this is a little unusual pattern, normally most code would call AcceptDragDropPayload directly)
+ const ImGuiPayload* payload = &g.DragDropPayload;
+ if (!payload->IsDataType(IMGUI_PAYLOAD_TYPE_WINDOW) || !DockNodeIsDropAllowed(window, *(ImGuiWindow**)payload->Data))
+ {
+ EndDragDropTarget();
+ return;
+ }
+
+ ImGuiWindow* payload_window = *(ImGuiWindow**)payload->Data;
+ if (AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_WINDOW, ImGuiDragDropFlags_AcceptBeforeDelivery | ImGuiDragDropFlags_AcceptNoDrawDefaultRect))
+ {
+ // Select target node
+ ImGuiDockNode* node = NULL;
+ bool allow_null_target_node = false;
+ if (window->DockNodeAsHost)
+ node = DockNodeTreeFindNodeByPos(window->DockNodeAsHost, g.IO.MousePos);
+ else if (window->DockNode) // && window->DockIsActive)
+ node = window->DockNode;
+ else
+ allow_null_target_node = true; // Dock into a regular window
+
+ const ImRect explicit_target_rect = (node && node->TabBar && !node->IsHiddenTabBar() && !node->IsNoTabBar()) ? node->TabBar->BarRect : ImRect(window->Pos, window->Pos + ImVec2(window->Size.x, GetFrameHeight()));
+ const bool is_explicit_target = g.IO.ConfigDockingWithShift || IsMouseHoveringRect(explicit_target_rect.Min, explicit_target_rect.Max);
+
+ // Preview docking request and find out split direction/ratio
+ //const bool do_preview = true; // Ignore testing for payload->IsPreview() which removes one frame of delay, but breaks overlapping drop targets within the same window.
+ const bool do_preview = payload->IsPreview() || payload->IsDelivery();
+ if (do_preview && (node != NULL || allow_null_target_node))
+ {
+ ImGuiDockPreviewData split_inner, split_outer;
+ ImGuiDockPreviewData* split_data = &split_inner;
+ if (node && (node->ParentNode || node->IsCentralNode()))
+ if (ImGuiDockNode* root_node = DockNodeGetRootNode(node))
+ {
+ DockNodePreviewDockCalc(window, root_node, payload_window, &split_outer, is_explicit_target, true);
+ if (split_outer.IsSplitDirExplicit)
+ split_data = &split_outer;
+ }
+ DockNodePreviewDockCalc(window, node, payload_window, &split_inner, is_explicit_target, false);
+ if (split_data == &split_outer)
+ split_inner.IsDropAllowed = false;
-ImGuiWindowSettings* ImGui::FindWindowSettings(ImGuiID id)
-{
- ImGuiContext& g = *GImGui;
- for (int i = 0; i != g.SettingsWindows.Size; i++)
- if (g.SettingsWindows[i].ID == id)
- return &g.SettingsWindows[i];
- return NULL;
-}
+ // Draw inner then outer, so that previewed tab (in inner data) will be behind the outer drop boxes
+ DockNodePreviewDockRender(window, node, payload_window, &split_inner);
+ DockNodePreviewDockRender(window, node, payload_window, &split_outer);
-ImGuiWindowSettings* ImGui::FindOrCreateWindowSettings(const char* name)
-{
- if (ImGuiWindowSettings* settings = FindWindowSettings(ImHashStr(name, 0)))
- return settings;
- return CreateNewWindowSettings(name);
+ // Queue docking request
+ if (split_data->IsDropAllowed && payload->IsDelivery())
+ DockContextQueueDock(ctx, window, split_data->SplitNode, payload_window, split_data->SplitDir, split_data->SplitRatio, split_data == &split_outer);
+ }
+ }
+ EndDragDropTarget();
}
-void ImGui::LoadIniSettingsFromDisk(const char* ini_filename)
-{
- size_t file_data_size = 0;
- char* file_data = (char*)ImFileLoadToMemory(ini_filename, "rb", &file_data_size);
- if (!file_data)
- return;
- LoadIniSettingsFromMemory(file_data, (size_t)file_data_size);
- ImGui::MemFree(file_data);
-}
+//-----------------------------------------------------------------------------
+// Docking: Settings
+//-----------------------------------------------------------------------------
+// - DockSettingsRenameNodeReferences()
+// - DockSettingsRemoveNodeReferences()
+// - DockSettingsFindNodeSettings()
+// - DockSettingsHandler_ReadOpen()
+// - DockSettingsHandler_ReadLine()
+// - DockSettingsHandler_DockNodeToSettings()
+// - DockSettingsHandler_WriteAll()
+//-----------------------------------------------------------------------------
-ImGuiSettingsHandler* ImGui::FindSettingsHandler(const char* type_name)
+static void ImGui::DockSettingsRenameNodeReferences(ImGuiID old_node_id, ImGuiID new_node_id)
{
ImGuiContext& g = *GImGui;
- const ImGuiID type_hash = ImHashStr(type_name, 0);
- for (int handler_n = 0; handler_n < g.SettingsHandlers.Size; handler_n++)
- if (g.SettingsHandlers[handler_n].TypeHash == type_hash)
- return &g.SettingsHandlers[handler_n];
- return NULL;
+ IMGUI_DEBUG_LOG_DOCKING("DockSettingsRenameNodeReferences: from 0x%08X -> to 0x%08X\n", old_node_id, new_node_id);
+ for (int window_n = 0; window_n < g.Windows.Size; window_n++)
+ {
+ ImGuiWindow* window = g.Windows[window_n];
+ if (window->DockId == old_node_id && window->DockNode == NULL)
+ window->DockId = new_node_id;
+ }
+ for (int settings_n = 0; settings_n < g.SettingsWindows.Size; settings_n++) // FIXME-OPT: We could remove this loop by storing the index in the map
+ {
+ ImGuiWindowSettings* window_settings = &g.SettingsWindows[settings_n];
+ if (window_settings->DockId == old_node_id)
+ window_settings->DockId = new_node_id;
+ }
}
-// Zero-tolerance, no error reporting, cheap .ini parsing
-void ImGui::LoadIniSettingsFromMemory(const char* ini_data, size_t ini_size)
+// Remove references stored in ImGuiWindowSettings to the given ImGuiDockNodeSettings
+static void ImGui::DockSettingsRemoveNodeReferences(ImGuiID* node_ids, int node_ids_count)
{
ImGuiContext& g = *GImGui;
- IM_ASSERT(g.Initialized);
- IM_ASSERT(g.SettingsLoaded == false && g.FrameCount == 0);
-
- // For user convenience, we allow passing a non zero-terminated string (hence the ini_size parameter).
- // For our convenience and to make the code simpler, we'll also write zero-terminators within the buffer. So let's create a writable copy..
- if (ini_size == 0)
- ini_size = strlen(ini_data);
- char* buf = (char*)ImGui::MemAlloc(ini_size + 1);
- char* buf_end = buf + ini_size;
- memcpy(buf, ini_data, ini_size);
- buf[ini_size] = 0;
-
- void* entry_data = NULL;
- ImGuiSettingsHandler* entry_handler = NULL;
-
- char* line_end = NULL;
- for (char* line = buf; line < buf_end; line = line_end + 1)
+ int found = 0;
+ for (int settings_n = 0; settings_n < g.SettingsWindows.Size; settings_n++) // FIXME-OPT: We could remove this loop by storing the index in the map
{
- // Skip new lines markers, then find end of the line
- while (*line == '\n' || *line == '\r')
- line++;
- line_end = line;
- while (line_end < buf_end && *line_end != '\n' && *line_end != '\r')
- line_end++;
- line_end[0] = 0;
- if (line[0] == ';')
- continue;
- if (line[0] == '[' && line_end > line && line_end[-1] == ']')
- {
- // Parse "[Type][Name]". Note that 'Name' can itself contains [] characters, which is acceptable with the current format and parsing code.
- line_end[-1] = 0;
- const char* name_end = line_end - 1;
- const char* type_start = line + 1;
- char* type_end = (char*)(intptr_t)ImStrchrRange(type_start, name_end, ']');
- const char* name_start = type_end ? ImStrchrRange(type_end + 1, name_end, '[') : NULL;
- if (!type_end || !name_start)
- {
- name_start = type_start; // Import legacy entries that have no type
- type_start = "Window";
- }
- else
+ ImGuiWindowSettings* window_settings = &g.SettingsWindows[settings_n];
+ for (int node_n = 0; node_n < node_ids_count; node_n++)
+ if (window_settings->DockId == node_ids[node_n])
{
- *type_end = 0; // Overwrite first ']'
- name_start++; // Skip second '['
+ window_settings->DockId = 0;
+ window_settings->DockOrder = -1;
+ if (++found < node_ids_count)
+ break;
+ return;
}
- entry_handler = FindSettingsHandler(type_start);
- entry_data = entry_handler ? entry_handler->ReadOpenFn(&g, entry_handler, name_start) : NULL;
- }
- else if (entry_handler != NULL && entry_data != NULL)
- {
- // Let type handler parse the line
- entry_handler->ReadLineFn(&g, entry_handler, entry_data, line);
- }
}
- ImGui::MemFree(buf);
- g.SettingsLoaded = true;
- DockContextOnLoadSettings(&g);
}
-void ImGui::SaveIniSettingsToDisk(const char* ini_filename)
+static ImGuiDockNodeSettings* ImGui::DockSettingsFindNodeSettings(ImGuiContext* ctx, ImGuiID id)
{
- ImGuiContext& g = *GImGui;
- g.SettingsDirtyTimer = 0.0f;
- if (!ini_filename)
- return;
+ // FIXME-OPT
+ ImGuiDockContext* dc = ctx->DockContext;
+ for (int n = 0; n < dc->SettingsNodes.Size; n++)
+ if (dc->SettingsNodes[n].ID == id)
+ return &dc->SettingsNodes[n];
+ return NULL;
+}
- size_t ini_data_size = 0;
- const char* ini_data = SaveIniSettingsToMemory(&ini_data_size);
- FILE* f = ImFileOpen(ini_filename, "wt");
- if (!f)
- return;
- fwrite(ini_data, sizeof(char), ini_data_size, f);
- fclose(f);
+static void* ImGui::DockSettingsHandler_ReadOpen(ImGuiContext*, ImGuiSettingsHandler*, const char* name)
+{
+ if (strcmp(name, "Data") != 0)
+ return NULL;
+ return (void*)1;
}
-// Call registered handlers (e.g. SettingsHandlerWindow_WriteAll() + custom handlers) to write their stuff into a text buffer
-const char* ImGui::SaveIniSettingsToMemory(size_t* out_size)
+static void ImGui::DockSettingsHandler_ReadLine(ImGuiContext* ctx, ImGuiSettingsHandler*, void*, const char* line)
{
- ImGuiContext& g = *GImGui;
- g.SettingsDirtyTimer = 0.0f;
- g.SettingsIniData.Buf.resize(0);
- g.SettingsIniData.Buf.push_back(0);
- for (int handler_n = 0; handler_n < g.SettingsHandlers.Size; handler_n++)
+ char c = 0;
+ int x = 0, y = 0;
+ int r = 0;
+
+ // Parsing, e.g.
+ // " DockNode ID=0x00000001 Pos=383,193 Size=201,322 Split=Y,0.506 "
+ // " DockNode ID=0x00000002 Parent=0x00000001 "
+ // Important: this code expect currently fields in a fixed order.
+ ImGuiDockNodeSettings node;
+ line = ImStrSkipBlank(line);
+ if (strncmp(line, "DockNode", 8) == 0) { line = ImStrSkipBlank(line + strlen("DockNode")); }
+ else if (strncmp(line, "DockSpace", 9) == 0) { line = ImStrSkipBlank(line + strlen("DockSpace")); node.Flags |= ImGuiDockNodeFlags_DockSpace; }
+ else return;
+ if (sscanf(line, "ID=0x%08X%n", &node.ID, &r) == 1) { line += r; } else return;
+ if (sscanf(line, " Parent=0x%08X%n", &node.ParentNodeID, &r) == 1) { line += r; if (node.ParentNodeID == 0) return; }
+ if (sscanf(line, " Window=0x%08X%n", &node.ParentWindowID, &r) ==1) { line += r; if (node.ParentWindowID == 0) return; }
+ if (node.ParentNodeID == 0)
{
- ImGuiSettingsHandler* handler = &g.SettingsHandlers[handler_n];
- handler->WriteAllFn(&g, handler, &g.SettingsIniData);
+ if (sscanf(line, " Pos=%i,%i%n", &x, &y, &r) == 2) { line += r; node.Pos = ImVec2ih((short)x, (short)y); } else return;
+ if (sscanf(line, " Size=%i,%i%n", &x, &y, &r) == 2) { line += r; node.Size = ImVec2ih((short)x, (short)y); } else return;
}
- if (out_size)
- *out_size = (size_t)g.SettingsIniData.size();
- return g.SettingsIniData.c_str();
+ else
+ {
+ if (sscanf(line, " SizeRef=%i,%i%n", &x, &y, &r) == 2) { line += r; node.SizeRef = ImVec2ih((short)x, (short)y); }
+ }
+ if (sscanf(line, " Split=%c%n", &c, &r) == 1) { line += r; if (c == 'X') node.SplitAxis = ImGuiAxis_X; else if (c == 'Y') node.SplitAxis = ImGuiAxis_Y; }
+ if (sscanf(line, " NoResize=%d%n", &x, &r) == 1) { line += r; if (x != 0) node.Flags |= ImGuiDockNodeFlags_NoResize; }
+ if (sscanf(line, " CentralNode=%d%n", &x, &r) == 1) { line += r; if (x != 0) node.Flags |= ImGuiDockNodeFlags_CentralNode; }
+ if (sscanf(line, " NoTabBar=%d%n", &x, &r) == 1) { line += r; if (x != 0) node.Flags |= ImGuiDockNodeFlags_NoTabBar; }
+ if (sscanf(line, " HiddenTabBar=%d%n", &x, &r) == 1) { line += r; if (x != 0) node.Flags |= ImGuiDockNodeFlags_HiddenTabBar; }
+ if (sscanf(line, " NoWindowMenuButton=%d%n", &x, &r) == 1) { line += r; if (x != 0) node.Flags |= ImGuiDockNodeFlags_NoWindowMenuButton; }
+ if (sscanf(line, " NoCloseButton=%d%n", &x, &r) == 1) { line += r; if (x != 0) node.Flags |= ImGuiDockNodeFlags_NoCloseButton; }
+ if (sscanf(line, " Selected=0x%08X%n", &node.SelectedWindowID,&r) == 1) { line += r; }
+ ImGuiDockContext* dc = ctx->DockContext;
+ if (node.ParentNodeID != 0)
+ if (ImGuiDockNodeSettings* parent_settings = DockSettingsFindNodeSettings(ctx, node.ParentNodeID))
+ node.Depth = parent_settings->Depth + 1;
+ dc->SettingsNodes.push_back(node);
}
-static void* SettingsHandlerWindow_ReadOpen(ImGuiContext*, ImGuiSettingsHandler*, const char* name)
+static void DockSettingsHandler_DockNodeToSettings(ImGuiDockContext* dc, ImGuiDockNode* node, int depth)
{
- ImGuiWindowSettings* settings = ImGui::FindWindowSettings(ImHashStr(name, 0));
- if (!settings)
- settings = ImGui::CreateNewWindowSettings(name);
- return (void*)settings;
+ ImGuiDockNodeSettings node_settings;
+ IM_ASSERT(depth < (1 << (sizeof(node_settings.Depth) << 3)));
+ node_settings.ID = node->ID;
+ node_settings.ParentNodeID = node->ParentNode ? node->ParentNode->ID : 0;
+ node_settings.ParentWindowID = (node->IsDockSpace() && node->HostWindow && node->HostWindow->ParentWindow) ? node->HostWindow->ParentWindow->ID : 0;
+ node_settings.SelectedWindowID = node->SelectedTabID;
+ node_settings.SplitAxis = node->IsSplitNode() ? (char)node->SplitAxis : ImGuiAxis_None;
+ node_settings.Depth = (char)depth;
+ node_settings.Flags = (node->LocalFlags & ImGuiDockNodeFlags_SavedFlagsMask_);
+ node_settings.Pos = ImVec2ih(node->Pos);
+ node_settings.Size = ImVec2ih(node->Size);
+ node_settings.SizeRef = ImVec2ih(node->SizeRef);
+ dc->SettingsNodes.push_back(node_settings);
+ if (node->ChildNodes[0])
+ DockSettingsHandler_DockNodeToSettings(dc, node->ChildNodes[0], depth + 1);
+ if (node->ChildNodes[1])
+ DockSettingsHandler_DockNodeToSettings(dc, node->ChildNodes[1], depth + 1);
}
-static void SettingsHandlerWindow_ReadLine(ImGuiContext*, ImGuiSettingsHandler*, void* entry, const char* line)
+static void ImGui::DockSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* buf)
{
- ImGuiWindowSettings* settings = (ImGuiWindowSettings*)entry;
- float x, y;
- int i;
- ImU32 u1;
- if (sscanf(line, "Pos=%f,%f", &x, &y) == 2) { settings->Pos = ImVec2(x, y); }
- else if (sscanf(line, "Size=%f,%f", &x, &y) == 2) { settings->Size = ImMax(ImVec2(x, y), GImGui->Style.WindowMinSize); }
- else if (sscanf(line, "ViewportId=0x%08X", &u1) == 1) { settings->ViewportId = u1; }
- else if (sscanf(line, "ViewportPos=%f,%f", &x, &y) == 2) { settings->ViewportPos = ImVec2(x, y); }
- else if (sscanf(line, "Collapsed=%d", &i) == 1) { settings->Collapsed = (i != 0); }
- else if (sscanf(line, "DockId=0x%X,%d", &u1, &i) == 2) { settings->DockId = u1; settings->DockOrder = (short)i; }
- else if (sscanf(line, "DockId=0x%X", &u1) == 1) { settings->DockId = u1; settings->DockOrder = -1; }
- else if (sscanf(line, "ClassId=0x%X", &u1) == 1) { settings->ClassId = u1; }
-}
+ ImGuiContext& g = *ctx;
+ ImGuiDockContext* dc = g.DockContext;
+ if (!(g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable))
+ return;
-static void SettingsHandlerWindow_WriteAll(ImGuiContext* imgui_ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* buf)
-{
- // Gather data from windows that were active during this session
- // (if a window wasn't opened in this session we preserve its settings)
- ImGuiContext& g = *imgui_ctx;
- for (int i = 0; i != g.Windows.Size; i++)
- {
- ImGuiWindow* window = g.Windows[i];
- if (window->Flags & ImGuiWindowFlags_NoSavedSettings)
- continue;
+ // Gather settings data
+ // (unlike our windows settings, because nodes are always built we can do a full rewrite of the SettingsNode buffer)
+ dc->SettingsNodes.resize(0);
+ dc->SettingsNodes.reserve(dc->Nodes.Data.Size);
+ for (int n = 0; n < dc->Nodes.Data.Size; n++)
+ if (ImGuiDockNode* node = (ImGuiDockNode*)dc->Nodes.Data[n].val_p)
+ if (node->IsRootNode())
+ DockSettingsHandler_DockNodeToSettings(dc, node, 0);
- ImGuiWindowSettings* settings = (window->SettingsIdx != -1) ? &g.SettingsWindows[window->SettingsIdx] : ImGui::FindWindowSettings(window->ID);
- if (!settings)
- {
- settings = ImGui::CreateNewWindowSettings(window->Name);
- window->SettingsIdx = g.SettingsWindows.index_from_ptr(settings);
- }
- IM_ASSERT(settings->ID == window->ID);
- settings->Pos = window->Pos - window->ViewportPos;
- settings->Size = window->SizeFull;
- settings->ViewportId = window->ViewportId;
- settings->ViewportPos = window->ViewportPos;
- IM_ASSERT(window->DockNode == NULL || window->DockNode->ID == window->DockId);
- settings->DockId = window->DockId;
- settings->ClassId = window->WindowClass.ClassId;
- settings->DockOrder = window->DockOrder;
- settings->Collapsed = window->Collapsed;
- }
+ int max_depth = 0;
+ for (int node_n = 0; node_n < dc->SettingsNodes.Size; node_n++)
+ max_depth = ImMax((int)dc->SettingsNodes[node_n].Depth, max_depth);
// Write to text buffer
- buf->reserve(buf->size() + g.SettingsWindows.Size * 96); // ballpark reserve
- for (int i = 0; i != g.SettingsWindows.Size; i++)
+ buf->appendf("[%s][Data]\n", handler->TypeName);
+ for (int node_n = 0; node_n < dc->SettingsNodes.Size; node_n++)
{
- const ImGuiWindowSettings* settings = &g.SettingsWindows[i];
- const char* name = settings->Name;
- if (const char* p = strstr(name, "###")) // Skip to the "###" marker if any. We don't skip past to match the behavior of GetID()
- name = p;
- buf->appendf("[%s][%s]\n", handler->TypeName, name);
- if (settings->ViewportId != 0 && settings->ViewportId != ImGui::IMGUI_VIEWPORT_DEFAULT_ID)
+ const int line_start_pos = buf->size(); (void)line_start_pos;
+ const ImGuiDockNodeSettings* node_settings = &dc->SettingsNodes[node_n];
+ buf->appendf("%*s%s%*s", node_settings->Depth * 2, "", (node_settings->Flags & ImGuiDockNodeFlags_DockSpace) ? "DockSpace" : "DockNode ", (max_depth - node_settings->Depth) * 2, ""); // Text align nodes to facilitate looking at .ini file
+ buf->appendf(" ID=0x%08X", node_settings->ID);
+ if (node_settings->ParentNodeID)
+ {
+ buf->appendf(" Parent=0x%08X SizeRef=%d,%d", node_settings->ParentNodeID, node_settings->SizeRef.x, node_settings->SizeRef.y);
+ }
+ else
{
- buf->appendf("ViewportPos=%d,%d\n", (int)settings->ViewportPos.x, (int)settings->ViewportPos.y);
- buf->appendf("ViewportId=0x%08X\n", settings->ViewportId);
+ if (node_settings->ParentWindowID)
+ buf->appendf(" Window=0x%08X", node_settings->ParentWindowID);
+ buf->appendf(" Pos=%d,%d Size=%d,%d", node_settings->Pos.x, node_settings->Pos.y, node_settings->Size.x, node_settings->Size.y);
}
- if (settings->Pos.x != 0.0f || settings->Pos.y != 0.0f || settings->ViewportId == ImGui::IMGUI_VIEWPORT_DEFAULT_ID)
- buf->appendf("Pos=%d,%d\n", (int)settings->Pos.x, (int)settings->Pos.y);
- if (settings->Size.x != 0.0f || settings->Size.y != 0.0f)
- buf->appendf("Size=%d,%d\n", (int)settings->Size.x, (int)settings->Size.y);
- buf->appendf("Collapsed=%d\n", settings->Collapsed);
- if (settings->DockId != 0)
+ if (node_settings->SplitAxis != ImGuiAxis_None)
+ buf->appendf(" Split=%c", (node_settings->SplitAxis == ImGuiAxis_X) ? 'X' : 'Y');
+ if (node_settings->Flags & ImGuiDockNodeFlags_NoResize)
+ buf->appendf(" NoResize=1");
+ if (node_settings->Flags & ImGuiDockNodeFlags_CentralNode)
+ buf->appendf(" CentralNode=1");
+ if (node_settings->Flags & ImGuiDockNodeFlags_NoTabBar)
+ buf->appendf(" NoTabBar=1");
+ if (node_settings->Flags & ImGuiDockNodeFlags_HiddenTabBar)
+ buf->appendf(" HiddenTabBar=1");
+ if (node_settings->Flags & ImGuiDockNodeFlags_NoWindowMenuButton)
+ buf->appendf(" NoWindowMenuButton=1");
+ if (node_settings->Flags & ImGuiDockNodeFlags_NoCloseButton)
+ buf->appendf(" NoCloseButton=1");
+ if (node_settings->SelectedWindowID)
+ buf->appendf(" Selected=0x%08X", node_settings->SelectedWindowID);
+
+#if IMGUI_DEBUG_INI_SETTINGS
+ // [DEBUG] Include comments in the .ini file to ease debugging
+ if (ImGuiDockNode* node = DockContextFindNodeByID(ctx, node_settings->ID))
{
- // Write DockId as 4 digits if possible. Automatic DockId are small numbers, but full explicit DockSpace() are full ImGuiID range.
- if (settings->DockOrder == -1)
- buf->appendf("DockId=0x%08X\n", settings->DockId);
- else
- buf->appendf("DockId=0x%08X,%d\n", settings->DockId, settings->DockOrder);
- if (settings->ClassId != 0)
- buf->appendf("ClassId=0x%08X\n", settings->ClassId);
+ buf->appendf("%*s", ImMax(2, (line_start_pos + 92) - buf->size()), ""); // Align everything
+ if (node->IsDockSpace() && node->HostWindow && node->HostWindow->ParentWindow)
+ buf->appendf(" ; in '%s'", node->HostWindow->ParentWindow->Name);
+ int contains_window = 0;
+ for (int window_n = 0; window_n < ctx->SettingsWindows.Size; window_n++) // Iterate settings so we can give info about windows that didn't exist during the session.
+ if (ctx->SettingsWindows[window_n].DockId == node_settings->ID)
+ {
+ if (contains_window++ == 0)
+ buf->appendf(" ; contains ");
+ buf->appendf("'%s' ", ctx->SettingsWindows[window_n].Name);
+ }
}
+#endif
buf->appendf("\n");
}
+ buf->appendf("\n");
}
+
//-----------------------------------------------------------------------------
// [SECTION] PLATFORM DEPENDENT HELPERS
//-----------------------------------------------------------------------------
@@ -13598,15 +14610,17 @@ static void SettingsHandlerWindow_WriteAll(ImGuiContext* imgui_ctx, ImGuiSetting
#else
#include
#endif
+#elif defined(__APPLE__)
+#include
#endif
-// Win32 API clipboard implementation
#if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS)
#ifdef _MSC_VER
#pragma comment(lib, "user32")
#endif
+// Win32 clipboard implementation
static const char* GetClipboardTextFn_DefaultImpl(void*)
{
static ImVector buf_local;
@@ -13650,16 +14664,67 @@ static void SetClipboardTextFn_DefaultImpl(void*, const char* text)
::CloseClipboard();
}
+#elif defined(__APPLE__) && TARGET_OS_OSX && defined(IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS)
+
+#include // Use old API to avoid need for separate .mm file
+static PasteboardRef main_clipboard = 0;
+
+// OSX clipboard implementation
+// If you enable this you will need to add '-framework ApplicationServices' to your linker command-line!
+static void SetClipboardTextFn_DefaultImpl(void*, const char* text)
+{
+ if (!main_clipboard)
+ PasteboardCreate(kPasteboardClipboard, &main_clipboard);
+ PasteboardClear(main_clipboard);
+ CFDataRef cf_data = CFDataCreate(kCFAllocatorDefault, (const UInt8*)text, strlen(text));
+ if (cf_data)
+ {
+ PasteboardPutItemFlavor(main_clipboard, (PasteboardItemID)1, CFSTR("public.utf8-plain-text"), cf_data, 0);
+ CFRelease(cf_data);
+ }
+}
+
+static const char* GetClipboardTextFn_DefaultImpl(void*)
+{
+ if (!main_clipboard)
+ PasteboardCreate(kPasteboardClipboard, &main_clipboard);
+ PasteboardSynchronize(main_clipboard);
+
+ ItemCount item_count = 0;
+ PasteboardGetItemCount(main_clipboard, &item_count);
+ for (int i = 0; i < item_count; i++)
+ {
+ PasteboardItemID item_id = 0;
+ PasteboardGetItemIdentifier(main_clipboard, i + 1, &item_id);
+ CFArrayRef flavor_type_array = 0;
+ PasteboardCopyItemFlavors(main_clipboard, item_id, &flavor_type_array);
+ for (CFIndex j = 0, nj = CFArrayGetCount(flavor_type_array); j < nj; j++)
+ {
+ CFDataRef cf_data;
+ if (PasteboardCopyItemFlavorData(main_clipboard, item_id, CFSTR("public.utf8-plain-text"), &cf_data) == noErr)
+ {
+ static ImVector clipboard_text;
+ int length = (int)CFDataGetLength(cf_data);
+ clipboard_text.resize(length + 1);
+ CFDataGetBytes(cf_data, CFRangeMake(0, length), (UInt8*)clipboard_text.Data);
+ clipboard_text[length] = 0;
+ CFRelease(cf_data);
+ return clipboard_text.Data;
+ }
+ }
+ }
+ return NULL;
+}
+
#else
-// Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers
+// Local Dear ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers.
static const char* GetClipboardTextFn_DefaultImpl(void*)
{
ImGuiContext& g = *GImGui;
return g.PrivateClipboard.empty() ? NULL : g.PrivateClipboard.begin();
}
-// Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers
static void SetClipboardTextFn_DefaultImpl(void*, const char* text)
{
ImGuiContext& g = *GImGui;
@@ -13683,7 +14748,7 @@ static void RenderViewportThumbnail(ImDrawList* draw_list, ImGuiViewportP* viewp
ImVec2 scale = bb.GetSize() / viewport->Size;
ImVec2 off = bb.Min - viewport->Pos * scale;
- float alpha_mul = viewport->PlatformWindowMinimized ? 0.30f : 1.00f;
+ float alpha_mul = (viewport->Flags & ImGuiViewportFlags_Minimized) ? 0.30f : 1.00f;
window->DrawList->AddRectFilled(bb.Min, bb.Max, ImGui::GetColorU32(ImGuiCol_Border, alpha_mul * 0.40f));
for (int i = 0; i != g.Windows.Size; i++)
{
@@ -13736,45 +14801,77 @@ void ImGui::ShowViewportThumbnails()
ImGui::Dummy(bb_full.GetSize() * SCALE);
}
+#ifndef IMGUI_DISABLE_METRICS_WINDOW
void ImGui::ShowMetricsWindow(bool* p_open)
{
- if (!ImGui::Begin("ImGui Metrics", p_open))
+ if (!ImGui::Begin("Dear ImGui Metrics", p_open))
{
ImGui::End();
return;
}
- static bool show_draw_cmd_clip_rects = true;
- static bool show_window_begin_order = false;
+ // State
+ enum { WRT_OuterRect, WRT_OuterRectClipped, WRT_InnerRect, WRT_InnerClipRect, WRT_WorkRect, WRT_Contents, WRT_ContentsRegionRect, WRT_Count }; // Windows Rect Type
+ const char* wrt_rects_names[WRT_Count] = { "OuterRect", "OuterRectClipped", "InnerRect", "InnerClipRect", "WorkRect", "Contents", "ContentsRegionRect" };
+ static bool show_windows_rects = false;
+ static int show_windows_rect_type = WRT_WorkRect;
+ static bool show_windows_begin_order = false;
+ static bool show_drawcmd_clip_rects = true;
+ static bool show_docking_nodes = false;
+
+ // Basic info
+ ImGuiContext& g = *GImGui;
ImGuiIO& io = ImGui::GetIO();
ImGui::Text("Dear ImGui %s", ImGui::GetVersion());
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
ImGui::Text("%d vertices, %d indices (%d triangles)", io.MetricsRenderVertices, io.MetricsRenderIndices, io.MetricsRenderIndices / 3);
ImGui::Text("%d active windows (%d visible)", io.MetricsActiveWindows, io.MetricsRenderWindows);
- ImGui::Text("%d allocations", io.MetricsActiveAllocations);
- ImGui::Checkbox("Show clipping rectangles when hovering draw commands", &show_draw_cmd_clip_rects);
- ImGui::Checkbox("Ctrl shows window begin order", &show_window_begin_order);
+ ImGui::Text("%d active allocations", io.MetricsActiveAllocations);
ImGui::Separator();
+ // Helper functions to display common structures:
+ // - NodeDrawList
+ // - NodeColumns
+ // - NodeWindow
+ // - NodeWindows
+ // - NodeViewport
+ // - NodeDockNode
+ // - NodeTabBar
struct Funcs
{
+ static ImRect GetWindowRect(ImGuiWindow* window, int rect_type)
+ {
+ if (rect_type == WRT_OuterRect) { return window->Rect(); }
+ else if (rect_type == WRT_OuterRectClipped) { return window->OuterRectClipped; }
+ else if (rect_type == WRT_InnerRect) { return window->InnerRect; }
+ else if (rect_type == WRT_InnerClipRect) { return window->InnerClipRect; }
+ else if (rect_type == WRT_WorkRect) { return window->WorkRect; }
+ else if (rect_type == WRT_Contents) { ImVec2 min = window->InnerRect.Min - window->Scroll + window->WindowPadding; return ImRect(min, min + window->ContentSize); }
+ else if (rect_type == WRT_ContentsRegionRect) { return window->ContentsRegionRect; }
+ IM_ASSERT(0);
+ return ImRect();
+ }
+
static void NodeDrawList(ImGuiWindow* window, ImGuiViewportP* viewport, ImDrawList* draw_list, const char* label)
{
bool node_open = ImGui::TreeNode(draw_list, "%s: '%s' %d vtx, %d indices, %d cmds", label, draw_list->_OwnerName ? draw_list->_OwnerName : "", draw_list->VtxBuffer.Size, draw_list->IdxBuffer.Size, draw_list->CmdBuffer.Size);
if (draw_list == ImGui::GetWindowDrawList())
{
ImGui::SameLine();
- ImGui::TextColored(ImColor(255,100,100), "CURRENTLY APPENDING"); // Can't display stats for active draw list! (we don't have the data double-buffered)
+ ImGui::TextColored(ImVec4(1.0f,0.4f,0.4f,1.0f), "CURRENTLY APPENDING"); // Can't display stats for active draw list! (we don't have the data double-buffered)
if (node_open) ImGui::TreePop();
return;
}
- ImDrawList* overlay_draw_list = viewport ? GetOverlayDrawList(viewport) : NULL; // Render additional visuals into the top-most draw list
- if (window && overlay_draw_list && ImGui::IsItemHovered())
- overlay_draw_list->AddRect(window->Pos, window->Pos + window->Size, IM_COL32(255, 255, 0, 255));
+ ImDrawList* fg_draw_list = viewport ? GetForegroundDrawList(viewport) : NULL; // Render additional visuals into the top-most draw list
+ if (window && fg_draw_list && ImGui::IsItemHovered())
+ fg_draw_list->AddRect(window->Pos, window->Pos + window->Size, IM_COL32(255, 255, 0, 255));
if (!node_open)
return;
+ if (window && !window->WasActive)
+ ImGui::Text("(Note: owning Window is inactive: DrawList is not being rendered!)");
+
int elem_offset = 0;
for (const ImDrawCmd* pcmd = draw_list->CmdBuffer.begin(); pcmd < draw_list->CmdBuffer.end(); elem_offset += pcmd->ElemCount, pcmd++)
{
@@ -13786,40 +14883,45 @@ void ImGui::ShowMetricsWindow(bool* p_open)
continue;
}
ImDrawIdx* idx_buffer = (draw_list->IdxBuffer.Size > 0) ? draw_list->IdxBuffer.Data : NULL;
- bool pcmd_node_open = ImGui::TreeNode((void*)(pcmd - draw_list->CmdBuffer.begin()), "Draw %4d %s vtx, tex 0x%p, clip_rect (%4.0f,%4.0f)-(%4.0f,%4.0f)", pcmd->ElemCount, draw_list->IdxBuffer.Size > 0 ? "indexed" : "non-indexed", pcmd->TextureId, pcmd->ClipRect.x, pcmd->ClipRect.y, pcmd->ClipRect.z, pcmd->ClipRect.w);
- if (show_draw_cmd_clip_rects && overlay_draw_list && ImGui::IsItemHovered())
+ char buf[300];
+ ImFormatString(buf, IM_ARRAYSIZE(buf), "Draw %4d triangles, tex 0x%p, clip_rect (%4.0f,%4.0f)-(%4.0f,%4.0f)",
+ pcmd->ElemCount/3, (void*)(intptr_t)pcmd->TextureId, pcmd->ClipRect.x, pcmd->ClipRect.y, pcmd->ClipRect.z, pcmd->ClipRect.w);
+ bool pcmd_node_open = ImGui::TreeNode((void*)(pcmd - draw_list->CmdBuffer.begin()), "%s", buf);
+ if (show_drawcmd_clip_rects && fg_draw_list && ImGui::IsItemHovered())
{
ImRect clip_rect = pcmd->ClipRect;
ImRect vtxs_rect;
for (int i = elem_offset; i < elem_offset + (int)pcmd->ElemCount; i++)
vtxs_rect.Add(draw_list->VtxBuffer[idx_buffer ? idx_buffer[i] : i].pos);
- clip_rect.Floor(); overlay_draw_list->AddRect(clip_rect.Min, clip_rect.Max, IM_COL32(255,255,0,255));
- vtxs_rect.Floor(); overlay_draw_list->AddRect(vtxs_rect.Min, vtxs_rect.Max, IM_COL32(255,0,255,255));
+ clip_rect.Floor(); fg_draw_list->AddRect(clip_rect.Min, clip_rect.Max, IM_COL32(255,0,255,255));
+ vtxs_rect.Floor(); fg_draw_list->AddRect(vtxs_rect.Min, vtxs_rect.Max, IM_COL32(255,255,0,255));
}
if (!pcmd_node_open)
continue;
// Display individual triangles/vertices. Hover on to get the corresponding triangle highlighted.
+ ImGui::Text("ElemCount: %d, ElemCount/3: %d, VtxOffset: +%d, IdxOffset: +%d", pcmd->ElemCount, pcmd->ElemCount/3, pcmd->VtxOffset, pcmd->IdxOffset);
ImGuiListClipper clipper(pcmd->ElemCount/3); // Manually coarse clip our print out of individual vertices to save CPU, only items that may be visible.
while (clipper.Step())
- for (int prim = clipper.DisplayStart, vtx_i = elem_offset + clipper.DisplayStart*3; prim < clipper.DisplayEnd; prim++)
+ for (int prim = clipper.DisplayStart, idx_i = elem_offset + clipper.DisplayStart*3; prim < clipper.DisplayEnd; prim++)
{
- char buf[300];
char *buf_p = buf, *buf_end = buf + IM_ARRAYSIZE(buf);
ImVec2 triangles_pos[3];
- for (int n = 0; n < 3; n++, vtx_i++)
+ for (int n = 0; n < 3; n++, idx_i++)
{
- ImDrawVert& v = draw_list->VtxBuffer[idx_buffer ? idx_buffer[vtx_i] : vtx_i];
+ int vtx_i = idx_buffer ? idx_buffer[idx_i] : idx_i;
+ ImDrawVert& v = draw_list->VtxBuffer[vtx_i];
triangles_pos[n] = v.pos;
- buf_p += ImFormatString(buf_p, buf_end - buf_p, "%s %04d: pos (%8.2f,%8.2f), uv (%.6f,%.6f), col %08X\n", (n == 0) ? "vtx" : " ", vtx_i, v.pos.x, v.pos.y, v.uv.x, v.uv.y, v.col);
+ buf_p += ImFormatString(buf_p, buf_end - buf_p, "%s %04d: pos (%8.2f,%8.2f), uv (%.6f,%.6f), col %08X\n",
+ (n == 0) ? "elem" : " ", idx_i, v.pos.x, v.pos.y, v.uv.x, v.uv.y, v.col);
}
ImGui::Selectable(buf, false);
- if (overlay_draw_list && ImGui::IsItemHovered())
+ if (fg_draw_list && ImGui::IsItemHovered())
{
- ImDrawListFlags backup_flags = overlay_draw_list->Flags;
- overlay_draw_list->Flags &= ~ImDrawListFlags_AntiAliasedLines; // Disable AA on triangle outlines at is more readable for very large and thin triangles.
- overlay_draw_list->AddPolyline(triangles_pos, 3, IM_COL32(255,255,0,255), true, 1.0f);
- overlay_draw_list->Flags = backup_flags;
+ ImDrawListFlags backup_flags = fg_draw_list->Flags;
+ fg_draw_list->Flags &= ~ImDrawListFlags_AntiAliasedLines; // Disable AA on triangle outlines at is more readable for very large and thin triangles.
+ fg_draw_list->AddPolyline(triangles_pos, 3, IM_COL32(255,255,0,255), true, 1.0f);
+ fg_draw_list->Flags = backup_flags;
}
}
ImGui::TreePop();
@@ -13827,29 +14929,36 @@ void ImGui::ShowMetricsWindow(bool* p_open)
ImGui::TreePop();
}
- static void NodeWindows(ImVector& windows, const char* label)
+ static void NodeColumns(const ImGuiColumns* columns)
{
- if (!ImGui::TreeNode(label, "%s (%d)", label, windows.Size))
+ if (!ImGui::TreeNode((void*)(uintptr_t)columns->ID, "Columns Id: 0x%08X, Count: %d, Flags: 0x%04X", columns->ID, columns->Count, columns->Flags))
return;
- for (int i = 0; i < windows.Size; i++)
- Funcs::NodeWindow(windows[i], "Window");
+ ImGui::BulletText("Width: %.1f (MinX: %.1f, MaxX: %.1f)", columns->OffMaxX - columns->OffMinX, columns->OffMinX, columns->OffMaxX);
+ for (int column_n = 0; column_n < columns->Columns.Size; column_n++)
+ ImGui::BulletText("Column %02d: OffsetNorm %.3f (= %.1f px)", column_n, columns->Columns[column_n].OffsetNorm, GetColumnOffsetFromNorm(columns, columns->Columns[column_n].OffsetNorm));
ImGui::TreePop();
}
static void NodeWindow(ImGuiWindow* window, const char* label)
{
- if (!ImGui::TreeNode(window, "%s '%s', %d @ 0x%p", label, window->Name, window->Active || window->WasActive, window))
+ if (window == NULL)
+ {
+ ImGui::BulletText("%s: NULL", label);
+ return;
+ }
+ if (!ImGui::TreeNode(window, "%s '%s', %d @ 0x%p", label, window->Name, (window->Active || window->WasActive), window))
return;
ImGuiWindowFlags flags = window->Flags;
NodeDrawList(window, window->Viewport, window->DrawList, "DrawList");
- ImGui::BulletText("Pos: (%.1f,%.1f), Size: (%.1f,%.1f), SizeContents (%.1f,%.1f)", window->Pos.x, window->Pos.y, window->Size.x, window->Size.y, window->SizeContents.x, window->SizeContents.y);
+ ImGui::BulletText("Pos: (%.1f,%.1f), Size: (%.1f,%.1f), ContentSize (%.1f,%.1f)", window->Pos.x, window->Pos.y, window->Size.x, window->Size.y, window->ContentSize.x, window->ContentSize.y);
ImGui::BulletText("Flags: 0x%08X (%s%s%s%s%s%s%s%s%s..)", flags,
(flags & ImGuiWindowFlags_ChildWindow) ? "Child " : "", (flags & ImGuiWindowFlags_Tooltip) ? "Tooltip " : "", (flags & ImGuiWindowFlags_Popup) ? "Popup " : "",
(flags & ImGuiWindowFlags_Modal) ? "Modal " : "", (flags & ImGuiWindowFlags_ChildMenu) ? "ChildMenu " : "", (flags & ImGuiWindowFlags_NoSavedSettings) ? "NoSavedSettings " : "",
(flags & ImGuiWindowFlags_NoMouseInputs)? "NoMouseInputs":"", (flags & ImGuiWindowFlags_NoNavInputs) ? "NoNavInputs" : "", (flags & ImGuiWindowFlags_AlwaysAutoResize) ? "AlwaysAutoResize" : "");
- ImGui::BulletText("Scroll: (%.2f/%.2f,%.2f/%.2f)", window->Scroll.x, GetWindowScrollMaxX(window), window->Scroll.y, GetWindowScrollMaxY(window));
+ ImGui::BulletText("WindowClassId: 0x%08X", window->WindowClass.ClassId);
+ ImGui::BulletText("Scroll: (%.2f/%.2f,%.2f/%.2f)", window->Scroll.x, window->ScrollMax.x, window->Scroll.y, window->ScrollMax.y);
ImGui::BulletText("Active: %d/%d, WriteAccessed: %d, BeginOrderWithinContext: %d", window->Active, window->WasActive, window->WriteAccessed, (window->Active || window->WasActive) ? window->BeginOrderWithinContext : -1);
- ImGui::BulletText("Appearing: %d, Hidden: %d (Reg %d Resize %d), SkipItems: %d", window->Appearing, window->Hidden, window->HiddenFramesRegular, window->HiddenFramesForResize, window->SkipItems);
+ ImGui::BulletText("Appearing: %d, Hidden: %d (CanSkip %d Cannot %d), SkipItems: %d", window->Appearing, window->Hidden, window->HiddenFramesCanSkipItems, window->HiddenFramesCannotSkipItems, window->SkipItems);
ImGui::BulletText("NavLastIds: 0x%08X,0x%08X, NavLayerActiveMask: %X", window->NavLastIds[0], window->NavLastIds[1], window->DC.NavLayerActiveMask);
ImGui::BulletText("NavLastChildNavWindow: %s", window->NavLastChildNavWindow ? window->NavLastChildNavWindow->Name : "NULL");
if (!window->NavRectRel[0].IsInverted())
@@ -13858,7 +14967,9 @@ void ImGui::ShowMetricsWindow(bool* p_open)
ImGui::BulletText("NavRectRel[0]: ");
ImGui::BulletText("Viewport: %d%s, ViewportId: 0x%08X, ViewportPos: (%.1f,%.1f)", window->Viewport ? window->Viewport->Idx : -1, window->ViewportOwned ? " (Owned)" : "", window->ViewportId, window->ViewportPos.x, window->ViewportPos.y);
ImGui::BulletText("ViewportMonitor: %d", window->Viewport ? window->Viewport->PlatformMonitor : -1);
- ImGui::BulletText("DockId: 0x%04X, DockOrder: %d, %s: 0x%p, Act: %d, Vis: %d", window->DockId, window->DockOrder, window->DockNodeAsHost ? "DockNodeAsHost" : "DockNode", window->DockNodeAsHost ? window->DockNodeAsHost : window->DockNode, window->DockIsActive, window->DockTabIsVisible);
+ ImGui::BulletText("DockId: 0x%04X, DockOrder: %d, Act: %d, Vis: %d", window->DockId, window->DockOrder, window->DockIsActive, window->DockTabIsVisible);
+ if (window->DockNode || window->DockNodeAsHost)
+ NodeDockNode(window->DockNodeAsHost ? window->DockNodeAsHost : window->DockNode, window->DockNodeAsHost ? "DockNodeAsHost" : "DockNode");
if (window->RootWindow != window) NodeWindow(window->RootWindow, "RootWindow");
if (window->RootWindowDockStop != window->RootWindow) NodeWindow(window->RootWindowDockStop, "RootWindowDockStop");
if (window->ParentWindow != NULL) NodeWindow(window->ParentWindow, "ParentWindow");
@@ -13866,44 +14977,113 @@ void ImGui::ShowMetricsWindow(bool* p_open)
if (window->ColumnsStorage.Size > 0 && ImGui::TreeNode("Columns", "Columns sets (%d)", window->ColumnsStorage.Size))
{
for (int n = 0; n < window->ColumnsStorage.Size; n++)
- {
- const ImGuiColumnsSet* columns = &window->ColumnsStorage[n];
- if (ImGui::TreeNode((void*)(uintptr_t)columns->ID, "Columns Id: 0x%08X, Count: %d, Flags: 0x%04X", columns->ID, columns->Count, columns->Flags))
- {
- ImGui::BulletText("Width: %.1f (MinX: %.1f, MaxX: %.1f)", columns->MaxX - columns->MinX, columns->MinX, columns->MaxX);
- for (int column_n = 0; column_n < columns->Columns.Size; column_n++)
- ImGui::BulletText("Column %02d: OffsetNorm %.3f (= %.1f px)", column_n, columns->Columns[column_n].OffsetNorm, OffsetNormToPixels(columns, columns->Columns[column_n].OffsetNorm));
- ImGui::TreePop();
- }
- }
+ NodeColumns(&window->ColumnsStorage[n]);
ImGui::TreePop();
}
- ImGui::BulletText("Storage: %d bytes", window->StateStorage.Data.Size * (int)sizeof(ImGuiStorage::Pair));
+ ImGui::BulletText("Storage: %d bytes", window->StateStorage.Data.size_in_bytes());
+ ImGui::TreePop();
+ }
+
+ static void NodeWindows(ImVector& windows, const char* label)
+ {
+ if (!ImGui::TreeNode(label, "%s (%d)", label, windows.Size))
+ return;
+ for (int i = 0; i < windows.Size; i++)
+ Funcs::NodeWindow(windows[i], "Window");
ImGui::TreePop();
}
static void NodeViewport(ImGuiViewportP* viewport)
{
- ImGui::SetNextTreeNodeOpen(true, ImGuiCond_Once);
+ ImGui::SetNextItemOpen(true, ImGuiCond_Once);
if (ImGui::TreeNode((void*)(intptr_t)viewport->ID, "Viewport #%d, ID: 0x%08X, Parent: 0x%08X, Window: \"%s\"", viewport->Idx, viewport->ID, viewport->ParentViewportId, viewport->Window ? viewport->Window->Name : "N/A"))
{
ImGuiWindowFlags flags = viewport->Flags;
ImGui::BulletText("Pos: (%.0f,%.0f), Size: (%.0f,%.0f), Monitor: %d, DpiScale: %.0f%%", viewport->Pos.x, viewport->Pos.y, viewport->Size.x, viewport->Size.y, viewport->PlatformMonitor, viewport->DpiScale * 100.0f);
if (viewport->Idx > 0) { ImGui::SameLine(); if (ImGui::SmallButton("Reset Pos")) { viewport->Pos = ImVec2(200,200); if (viewport->Window) viewport->Window->Pos = ImVec2(200,200); } }
- ImGui::BulletText("Flags: 0x%04X =%s%s%s%s%s%s", viewport->Flags,
+ ImGui::BulletText("Flags: 0x%04X =%s%s%s%s%s%s%s", viewport->Flags,
(flags & ImGuiViewportFlags_CanHostOtherWindows) ? " CanHostOtherWindows" : "", (flags & ImGuiViewportFlags_NoDecoration) ? " NoDecoration" : "",
(flags & ImGuiViewportFlags_NoFocusOnAppearing) ? " NoFocusOnAppearing" : "", (flags & ImGuiViewportFlags_NoInputs) ? " NoInputs" : "",
- (flags & ImGuiViewportFlags_NoRendererClear) ? " NoRendererClear" : "", viewport->PlatformWindowMinimized ? ", PlatformWindowMinimized" : "");
+ (flags & ImGuiViewportFlags_NoRendererClear) ? " NoRendererClear" : "", (flags & ImGuiViewportFlags_Minimized) ? " Minimized" : "",
+ (flags & ImGuiViewportFlags_NoAutoMerge) ? " NoAutoMerge" : "");
for (int layer_i = 0; layer_i < IM_ARRAYSIZE(viewport->DrawDataBuilder.Layers); layer_i++)
for (int draw_list_i = 0; draw_list_i < viewport->DrawDataBuilder.Layers[layer_i].Size; draw_list_i++)
Funcs::NodeDrawList(NULL, viewport, viewport->DrawDataBuilder.Layers[layer_i][draw_list_i], "DrawList");
ImGui::TreePop();
}
}
+
+ static void NodeDockNode(ImGuiDockNode* node, const char* label)
+ {
+ ImGuiContext& g = *GImGui;
+ bool open;
+ if (node->Windows.Size > 0)
+ open = ImGui::TreeNode((void*)(intptr_t)node->ID, "%s 0x%04X%s: %d windows (vis: '%s')", label, node->ID, node->IsVisible ? "" : " (hidden)", node->Windows.Size, node->VisibleWindow ? node->VisibleWindow->Name : "NULL");
+ else
+ open = ImGui::TreeNode((void*)(intptr_t)node->ID, "%s 0x%04X%s: %s split (vis: '%s')", label, node->ID, node->IsVisible ? "" : " (hidden)", (node->SplitAxis == ImGuiAxis_X) ? "horizontal" : (node->SplitAxis == ImGuiAxis_Y) ? "vertical" : "n/a", node->VisibleWindow ? node->VisibleWindow->Name : "NULL");
+ if (open)
+ {
+ IM_ASSERT(node->ChildNodes[0] == NULL || node->ChildNodes[0]->ParentNode == node);
+ IM_ASSERT(node->ChildNodes[1] == NULL || node->ChildNodes[1]->ParentNode == node);
+ ImGui::BulletText("Pos (%.0f,%.0f), Size (%.0f, %.0f) Ref (%.0f, %.0f)",
+ node->Pos.x, node->Pos.y, node->Size.x, node->Size.y, node->SizeRef.x, node->SizeRef.y);
+ NodeWindow(node->HostWindow, "HostWindow");
+ NodeWindow(node->VisibleWindow, "VisibleWindow");
+ ImGui::BulletText("SelectedTabID: 0x%08X, LastFocusedNodeID: 0x%08X", node->SelectedTabID, node->LastFocusedNodeID);
+ ImGui::BulletText("Misc:%s%s%s%s", node->IsDockSpace() ? " IsDockSpace" : "", node->IsCentralNode() ? " IsCentralNode" : "", (g.FrameCount - node->LastFrameAlive < 2) ? " IsAlive" : "", (g.FrameCount - node->LastFrameActive < 2) ? " IsActive" : "");
+ if (ImGui::TreeNode("flags", "LocalFlags: 0x%04X SharedFlags: 0x%04X", node->LocalFlags, node->SharedFlags))
+ {
+ ImGui::CheckboxFlags("LocalFlags: NoSplit", (ImU32*)&node->LocalFlags, ImGuiDockNodeFlags_NoSplit);
+ ImGui::CheckboxFlags("LocalFlags: NoResize", (ImU32*)&node->LocalFlags, ImGuiDockNodeFlags_NoResize);
+ ImGui::CheckboxFlags("LocalFlags: NoTabBar", (ImU32*)&node->LocalFlags, ImGuiDockNodeFlags_NoTabBar);
+ ImGui::CheckboxFlags("LocalFlags: HiddenTabBar", (ImU32*)&node->LocalFlags, ImGuiDockNodeFlags_HiddenTabBar);
+ ImGui::CheckboxFlags("LocalFlags: NoWindowMenuButton", (ImU32*)&node->LocalFlags, ImGuiDockNodeFlags_NoWindowMenuButton);
+ ImGui::CheckboxFlags("LocalFlags: NoCloseButton", (ImU32*)&node->LocalFlags, ImGuiDockNodeFlags_NoCloseButton);
+ ImGui::TreePop();
+ }
+ if (node->ParentNode)
+ NodeDockNode(node->ParentNode, "ParentNode");
+ if (node->ChildNodes[0])
+ NodeDockNode(node->ChildNodes[0], "Child[0]");
+ if (node->ChildNodes[1])
+ NodeDockNode(node->ChildNodes[1], "Child[1]");
+ if (node->TabBar)
+ NodeTabBar(node->TabBar);
+ ImGui::TreePop();
+ }
+ }
+
+ static void NodeTabBar(ImGuiTabBar* tab_bar)
+ {
+ // Standalone tab bars (not associated to docking/windows functionality) currently hold no discernible strings.
+ char buf[256];
+ char* p = buf;
+ const char* buf_end = buf + IM_ARRAYSIZE(buf);
+ p += ImFormatString(p, buf_end - p, "TabBar (%d tabs)%s",
+ tab_bar->Tabs.Size, (tab_bar->PrevFrameVisible < ImGui::GetFrameCount() - 2) ? " *Inactive*" : "");
+ if (tab_bar->Flags & ImGuiTabBarFlags_DockNode)
+ {
+ p += ImFormatString(p, buf_end - p, " { ");
+ for (int tab_n = 0; tab_n < ImMin(tab_bar->Tabs.Size, 3); tab_n++)
+ p += ImFormatString(p, buf_end - p, "%s'%s'", tab_n > 0 ? ", " : "", tab_bar->Tabs[tab_n].Window->Name);
+ p += ImFormatString(p, buf_end - p, (tab_bar->Tabs.Size > 3) ? " ... }" : " } ");
+ }
+ if (ImGui::TreeNode(tab_bar, "%s", buf))
+ {
+ for (int tab_n = 0; tab_n < tab_bar->Tabs.Size; tab_n++)
+ {
+ const ImGuiTabItem* tab = &tab_bar->Tabs[tab_n];
+ ImGui::PushID(tab);
+ if (ImGui::SmallButton("<")) { TabBarQueueChangeTabOrder(tab_bar, tab, -1); } ImGui::SameLine(0, 2);
+ if (ImGui::SmallButton(">")) { TabBarQueueChangeTabOrder(tab_bar, tab, +1); } ImGui::SameLine();
+ ImGui::Text("%02d%c Tab 0x%08X '%s'", tab_n, (tab->ID == tab_bar->SelectedTabId) ? '*' : ' ', tab->ID, tab->Window ? tab->Window->Name : "N/A");
+ ImGui::PopID();
+ }
+ ImGui::TreePop();
+ }
+ }
};
- // Access private state, we are going to display the draw lists from last frame
- ImGuiContext& g = *GImGui;
Funcs::NodeWindows(g.Windows, "Windows");
if (ImGui::TreeNode("Viewport", "Viewports (%d)", g.Viewports.Size))
{
@@ -13927,6 +15107,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
Funcs::NodeViewport(g.Viewports[i]);
ImGui::TreePop();
}
+
if (ImGui::TreeNode("Popups", "Popups (%d)", g.OpenPopupStack.Size))
{
for (int i = 0; i < g.OpenPopupStack.Size; i++)
@@ -13936,11 +15117,71 @@ void ImGui::ShowMetricsWindow(bool* p_open)
}
ImGui::TreePop();
}
- if (ImGui::TreeNode("Docking & Tab Bars"))
+
+ if (ImGui::TreeNode("TabBars", "Tab Bars (%d)", g.TabBars.Data.Size))
+ {
+ for (int n = 0; n < g.TabBars.Data.Size; n++)
+ Funcs::NodeTabBar(g.TabBars.GetByIndex(n));
+ ImGui::TreePop();
+ }
+
+ if (ImGui::TreeNode("Docking"))
+ {
+ ImGuiDockContext* dc = g.DockContext;
+ ImGui::Checkbox("Ctrl shows window dock info", &show_docking_nodes);
+
+ if (ImGui::TreeNode("Dock nodes"))
+ {
+ if (ImGui::SmallButton("Clear settings")) { DockContextClearNodes(&g, 0, true); }
+ ImGui::SameLine();
+ if (ImGui::SmallButton("Rebuild all")) { dc->WantFullRebuild = true; }
+ for (int n = 0; n < dc->Nodes.Data.Size; n++)
+ if (ImGuiDockNode* node = (ImGuiDockNode*)dc->Nodes.Data[n].val_p)
+ if (node->IsRootNode())
+ Funcs::NodeDockNode(node, "Node");
+ ImGui::TreePop();
+ }
+
+ if (ImGui::TreeNode("Settings"))
+ {
+ if (ImGui::SmallButton("Refresh"))
+ SaveIniSettingsToMemory();
+ ImGui::SameLine();
+ if (ImGui::SmallButton("Save to disk"))
+ SaveIniSettingsToDisk(g.IO.IniFilename);
+ ImGui::Separator();
+ ImGui::Text("Docked Windows:");
+ for (int n = 0; n < g.SettingsWindows.Size; n++)
+ if (g.SettingsWindows[n].DockId != 0)
+ ImGui::BulletText("Window '%s' -> DockId %08X", g.SettingsWindows[n].Name, g.SettingsWindows[n].DockId);
+ ImGui::Separator();
+ ImGui::Text("Dock Nodes:");
+ for (int n = 0; n < dc->SettingsNodes.Size; n++)
+ {
+ ImGuiDockNodeSettings* settings = &dc->SettingsNodes[n];
+ const char* selected_tab_name = NULL;
+ if (settings->SelectedWindowID)
+ {
+ if (ImGuiWindow* window = FindWindowByID(settings->SelectedWindowID))
+ selected_tab_name = window->Name;
+ else if (ImGuiWindowSettings* window_settings = FindWindowSettings(settings->SelectedWindowID))
+ selected_tab_name = window_settings->Name;
+ }
+ ImGui::BulletText("Node %08X, Parent %08X, SelectedTab %08X ('%s')", settings->ID, settings->ParentNodeID, settings->SelectedWindowID, selected_tab_name ? selected_tab_name : settings->SelectedWindowID ? "N/A" : "");
+ }
+ ImGui::TreePop();
+ }
+
+ ImGui::TreePop();
+ }
+
+#if 0
+ if (ImGui::TreeNode("Tables", "Tables (%d)", g.Tables.Data.Size))
{
- ShowDockingDebug();
ImGui::TreePop();
}
+#endif
+
if (ImGui::TreeNode("Internal state"))
{
const char* input_source_names[] = { "None", "Mouse", "Nav", "NavKeyboard", "NavGamepad" }; IM_ASSERT(IM_ARRAYSIZE(input_source_names) == ImGuiInputSource_COUNT);
@@ -13963,150 +15204,61 @@ void ImGui::ShowMetricsWindow(bool* p_open)
ImGui::TreePop();
}
- if (g.IO.KeyCtrl && show_window_begin_order)
+ if (ImGui::TreeNode("Tools"))
{
- for (int n = 0; n < g.Windows.Size; n++)
- {
- ImGuiWindow* window = g.Windows[n];
- if (!window->WasActive || ((window->Flags & ImGuiWindowFlags_ChildWindow) && window->DockNode == NULL))
- continue;
-
- char buf[64] = "";
- char* p = buf;
- p += ImFormatString(p, buf + IM_ARRAYSIZE(buf) - p, "Order: %d\n", window->BeginOrderWithinContext);
- ImDrawList* overlay_draw_list = GetOverlayDrawList(window->Viewport);
- overlay_draw_list->AddRectFilled(window->Pos - ImVec2(1, 1), window->Pos + CalcTextSize(buf) + ImVec2(1, 1), IM_COL32(200, 100, 100, 255));
- overlay_draw_list->AddText(NULL, 0.0f, window->Pos, IM_COL32(255, 255, 255, 255), buf);
- }
- }
- ImGui::End();
-}
-
-void ImGui::ShowDockingDebug()
-{
- ImGuiContext* ctx = GImGui;
- ImGuiContext& g = *ctx;
- ImGuiDockContext* dc = ctx->DockContext;
-
- struct Funcs
- {
- static void NodeDockNode(ImGuiDockNode* node, const char* label)
- {
- ImGui::SetNextTreeNodeOpen(true, ImGuiCond_Once);
- bool open;
- if (node->Windows.Size > 0)
- open = ImGui::TreeNode((void*)(intptr_t)node->ID, "%s 0x%04X%s: %d windows (vis: '%s')", label, node->ID, node->IsVisible ? "" : " (hidden)", node->Windows.Size, node->VisibleWindow ? node->VisibleWindow->Name : "NULL");
- else
- open = ImGui::TreeNode((void*)(intptr_t)node->ID, "%s 0x%04X%s: %s split (vis: '%s')", label, node->ID, node->IsVisible ? "" : " (hidden)", (node->SplitAxis == ImGuiAxis_X) ? "horizontal" : (node->SplitAxis == ImGuiAxis_Y) ? "vertical" : "n/a", node->VisibleWindow ? node->VisibleWindow->Name : "NULL");
- if (open)
- {
- IM_ASSERT(node->ChildNodes[0] == NULL || node->ChildNodes[0]->ParentNode == node);
- IM_ASSERT(node->ChildNodes[1] == NULL || node->ChildNodes[1]->ParentNode == node);
- ImGui::BulletText("Pos (%.0f,%.0f), Size (%.0f, %.0f) Ref (%.0f, %.0f)",
- node->Pos.x, node->Pos.y, node->Size.x, node->Size.y, node->SizeRef.x, node->SizeRef.y);
- ImGui::BulletText("VisibleWindow: 0x%08X %s", node->VisibleWindow ? node->VisibleWindow->ID : 0, node->VisibleWindow ? node->VisibleWindow->Name : "NULL");
- ImGui::BulletText("SelectedTabID: 0x%08X", node->SelectedTabID);
- ImGui::BulletText("LastFocusedNodeID: 0x%08X", node->LastFocusedNodeID);
- ImGui::BulletText("Flags 0x%02X%s%s%s%s",
- node->Flags, node->IsDockSpace() ? ", IsDockSpace" : "", node->IsCentralNode ? ", IsCentralNode" : "",
- (GImGui->FrameCount - node->LastFrameAlive < 2) ? ", IsAlive" : "", (GImGui->FrameCount - node->LastFrameActive < 2) ? ", IsActive" : "");
- if (node->ChildNodes[0])
- NodeDockNode(node->ChildNodes[0], "Child[0]");
- if (node->ChildNodes[1])
- NodeDockNode(node->ChildNodes[1], "Child[1]");
- if (node->TabBar)
- NodeTabBar(node->TabBar);
- ImGui::TreePop();
- }
- }
+ // The Item Picker tool is super useful to visually select an item and break into the call-stack of where it was submitted.
+ if (ImGui::Button("Item Picker.."))
+ ImGui::DebugStartItemPicker();
- static void NodeTabBar(ImGuiTabBar* tab_bar)
+ ImGui::Checkbox("Show windows begin order", &show_windows_begin_order);
+ ImGui::Checkbox("Show windows rectangles", &show_windows_rects);
+ ImGui::SameLine();
+ ImGui::SetNextItemWidth(ImGui::GetFontSize() * 12);
+ show_windows_rects |= ImGui::Combo("##show_windows_rect_type", &show_windows_rect_type, wrt_rects_names, WRT_Count);
+ if (show_windows_rects && g.NavWindow)
{
- // Standalone tab bars (not associated to docking/windows functionality) currently hold no discernible strings.
- char buf[256];
- char* p = buf;
- const char* buf_end = buf + IM_ARRAYSIZE(buf);
- p += ImFormatString(p, buf_end - p, "TabBar (%d tabs)%s",
- tab_bar->Tabs.Size, (tab_bar->PrevFrameVisible < ImGui::GetFrameCount() - 2) ? " *Inactive*" : "");
- if (tab_bar->Flags & ImGuiTabBarFlags_DockNode)
- {
- p += ImFormatString(p, buf_end - p, " { ");
- for (int tab_n = 0; tab_n < ImMin(tab_bar->Tabs.Size, 3); tab_n++)
- p += ImFormatString(p, buf_end - p, "%s'%s'", tab_n > 0 ? ", " : "", tab_bar->Tabs[tab_n].Window->Name);
- p += ImFormatString(p, buf_end - p, (tab_bar->Tabs.Size > 3) ? " ... }" : " } ");
- }
- if (ImGui::TreeNode(tab_bar, "%s", buf))
+ ImGui::BulletText("'%s':", g.NavWindow->Name);
+ ImGui::Indent();
+ for (int rect_n = 0; rect_n < WRT_Count; rect_n++)
{
- for (int tab_n = 0; tab_n < tab_bar->Tabs.Size; tab_n++)
- {
- const ImGuiTabItem* tab = &tab_bar->Tabs[tab_n];
- ImGui::PushID(tab);
- if (ImGui::SmallButton("<")) { TabBarQueueChangeTabOrder(tab_bar, tab, -1); } ImGui::SameLine(0, 2);
- if (ImGui::SmallButton(">")) { TabBarQueueChangeTabOrder(tab_bar, tab, +1); } ImGui::SameLine();
- ImGui::Text("%02d%c Tab 0x%08X '%s'", tab_n, (tab->ID == tab_bar->SelectedTabId) ? '*' : ' ', tab->ID, tab->Window ? tab->Window->Name : "N/A");
- ImGui::PopID();
- }
- ImGui::TreePop();
+ ImRect r = Funcs::GetWindowRect(g.NavWindow, rect_n);
+ ImGui::Text("(%6.1f,%6.1f) (%6.1f,%6.1f) Size (%6.1f,%6.1f) %s", r.Min.x, r.Min.y, r.Max.x, r.Max.y, r.GetWidth(), r.GetHeight(), wrt_rects_names[rect_n]);
}
+ ImGui::Unindent();
}
- };
-
- static bool show_window_dock_info = false;
- ImGui::Checkbox("Ctrl shows window dock info", &show_window_dock_info);
-
- if (ImGui::TreeNode("Dock nodes"))
- {
- if (ImGui::SmallButton("Clear settings")) { DockContextClearNodes(&g, 0, true); }
- ImGui::SameLine();
- if (ImGui::SmallButton("Rebuild all")) { dc->WantFullRebuild = true; }
- for (int n = 0; n < dc->Nodes.Data.Size; n++)
- if (ImGuiDockNode* node = (ImGuiDockNode*)dc->Nodes.Data[n].val_p)
- if (node->IsRootNode())
- Funcs::NodeDockNode(node, "Node");
- ImGui::TreePop();
- }
-
- if (ImGui::TreeNode("TabBars", "Tab Bars (%d)", g.TabBars.Data.Size))
- {
- for (int n = 0; n < g.TabBars.Data.Size; n++)
- Funcs::NodeTabBar(g.TabBars.GetByIndex(n));
+ ImGui::Checkbox("Show clipping rectangle when hovering ImDrawCmd node", &show_drawcmd_clip_rects);
ImGui::TreePop();
}
- if (ImGui::TreeNode("Settings"))
+ // Tool: Display windows Rectangles and Begin Order
+ if (show_windows_rects || show_windows_begin_order)
{
- if (ImGui::SmallButton("Refresh"))
- SaveIniSettingsToMemory();
- ImGui::SameLine();
- if (ImGui::SmallButton("Save to disk"))
- SaveIniSettingsToDisk(g.IO.IniFilename);
- ImGui::Separator();
- ImGui::Text("Docked Windows:");
- for (int n = 0; n < g.SettingsWindows.Size; n++)
- if (g.SettingsWindows[n].DockId != 0)
- ImGui::BulletText("Window '%s' -> DockId %08X", g.SettingsWindows[n].Name, g.SettingsWindows[n].DockId);
- ImGui::Separator();
- ImGui::Text("Dock Nodes:");
- for (int n = 0; n < dc->SettingsNodes.Size; n++)
- {
- ImGuiDockNodeSettings* settings = &dc->SettingsNodes[n];
- const char* selected_tab_name = NULL;
- if (settings->SelectedTabID)
+ for (int n = 0; n < g.Windows.Size; n++)
+ {
+ ImGuiWindow* window = g.Windows[n];
+ if (!window->WasActive)
+ continue;
+ ImDrawList* draw_list = GetForegroundDrawList(window);
+ if (show_windows_rects)
{
- if (ImGuiWindow* window = FindWindowByID(settings->SelectedTabID))
- selected_tab_name = window->Name;
- else if (ImGuiWindowSettings* window_settings = FindWindowSettings(settings->SelectedTabID))
- selected_tab_name = window_settings->Name;
+ ImRect r = Funcs::GetWindowRect(window, show_windows_rect_type);
+ draw_list->AddRect(r.Min, r.Max, IM_COL32(255, 0, 128, 255));
+ }
+ if (show_windows_begin_order && !(window->Flags & ImGuiWindowFlags_ChildWindow))
+ {
+ char buf[32];
+ ImFormatString(buf, IM_ARRAYSIZE(buf), "%d", window->BeginOrderWithinContext);
+ float font_size = ImGui::GetFontSize();
+ draw_list->AddRectFilled(window->Pos, window->Pos + ImVec2(font_size, font_size), IM_COL32(200, 100, 100, 255));
+ draw_list->AddText(window->Pos, IM_COL32(255, 255, 255, 255), buf);
}
- ImGui::BulletText("Node %08X, Parent %08X, SelectedTab %08X ('%s')", settings->ID, settings->ParentID, settings->SelectedTabID, selected_tab_name ? selected_tab_name : settings->SelectedTabID ? "N/A" : "");
}
- ImGui::TreePop();
}
- if (g.IO.KeyCtrl && show_window_dock_info)
+ if (show_docking_nodes && g.IO.KeyCtrl)
{
- for (int n = 0; n < dc->Nodes.Data.Size; n++)
- if (ImGuiDockNode* node = (ImGuiDockNode*)dc->Nodes.Data[n].val_p)
+ for (int n = 0; n < g.DockContext->Nodes.Data.Size; n++)
+ if (ImGuiDockNode* node = (ImGuiDockNode*)g.DockContext->Nodes.Data[n].val_p)
{
ImGuiDockNode* root_node = DockNodeGetRootNode(node);
if (ImGuiDockNode* hovered_node = DockNodeTreeFindNodeByPos(root_node, g.IO.MousePos))
@@ -14114,19 +15266,28 @@ void ImGui::ShowDockingDebug()
continue;
char buf[64] = "";
char* p = buf;
- ImDrawList* overlay_draw_list = node->HostWindow ? GetOverlayDrawList(node->HostWindow) : GetOverlayDrawList((ImGuiViewportP*)GetMainViewport());
- p += ImFormatString(p, buf + IM_ARRAYSIZE(buf) - p, "DockId: %X%s\n", node->ID, node->IsCentralNode ? " *CentralNode*" : "");
+ ImDrawList* overlay_draw_list = node->HostWindow ? GetForegroundDrawList(node->HostWindow) : GetForegroundDrawList((ImGuiViewportP*)GetMainViewport());
+ p += ImFormatString(p, buf + IM_ARRAYSIZE(buf) - p, "DockId: %X%s\n", node->ID, node->IsCentralNode() ? " *CentralNode*" : "");
+ p += ImFormatString(p, buf + IM_ARRAYSIZE(buf) - p, "WindowClass: %08X\n", node->WindowClass.ClassId);
p += ImFormatString(p, buf + IM_ARRAYSIZE(buf) - p, "Size: (%.0f, %.0f)\n", node->Size.x, node->Size.y);
p += ImFormatString(p, buf + IM_ARRAYSIZE(buf) - p, "SizeRef: (%.0f, %.0f)\n", node->SizeRef.x, node->SizeRef.y);
int depth = DockNodeGetDepth(node);
- overlay_draw_list->AddRect(node->Pos + ImVec2(3,3) * (float)depth, node->Pos + node->Size - ImVec2(3,3) * (float)depth, IM_COL32(200, 100, 100, 255));
- ImVec2 pos = node->Pos + ImVec2(3,3) * (float)depth;
+ overlay_draw_list->AddRect(node->Pos + ImVec2(3, 3) * (float)depth, node->Pos + node->Size - ImVec2(3, 3) * (float)depth, IM_COL32(200, 100, 100, 255));
+ ImVec2 pos = node->Pos + ImVec2(3, 3) * (float)depth;
overlay_draw_list->AddRectFilled(pos - ImVec2(1, 1), pos + CalcTextSize(buf) + ImVec2(1, 1), IM_COL32(200, 100, 100, 255));
overlay_draw_list->AddText(NULL, 0.0f, pos, IM_COL32(255, 255, 255, 255), buf);
}
}
+
+ ImGui::End();
}
+#else
+
+void ImGui::ShowMetricsWindow(bool*) { }
+
+#endif
+
//-----------------------------------------------------------------------------
// Include imgui_user.inl at the end of imgui.cpp to access private data/functions that aren't exposed.
diff --git a/imgui.h b/imgui.h
index 91646ae6..72fbfe9e 100644
--- a/imgui.h
+++ b/imgui.h
@@ -1,9 +1,9 @@
-// dear imgui, v1.68 WIP
+// dear imgui, v1.73 WIP
// (headers)
// See imgui.cpp file for documentation.
// Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp for demo code.
-// Newcomers, read 'Programmer guide' below for notes on how to setup Dear ImGui in your codebase.
+// Newcomers, read 'Programmer guide' in imgui.cpp for notes on how to setup Dear ImGui in your codebase.
// Get latest version at https://github.com/ocornut/imgui
/*
@@ -13,13 +13,14 @@ Index of this file:
// Forward declarations and basic types
// ImGui API (Dear ImGui end-user API)
// Flags & Enumerations
+// Memory allocations macros
// ImVector<>
// ImGuiStyle
// ImGuiIO
-// Misc data structures (ImGuiInputTextCallbackData, ImGuiSizeCallbackData, ImGuiPayload, ImGuiWindowClass)
+// Misc data structures (ImGuiInputTextCallbackData, ImGuiSizeCallbackData, ImGuiWindowClass, ImGuiPayload)
// Obsolete functions
// Helpers (ImGuiOnceUponAFrame, ImGuiTextFilter, ImGuiTextBuffer, ImGuiStorage, ImGuiListClipper, ImColor)
-// Draw List API (ImDrawCmd, ImDrawIdx, ImDrawVert, ImDrawChannel, ImDrawListFlags, ImDrawList, ImDrawData)
+// Draw List API (ImDrawCallback, ImDrawCmd, ImDrawIdx, ImDrawVert, ImDrawChannel, ImDrawListSplitter, ImDrawListFlags, ImDrawList, ImDrawData)
// Font API (ImFontConfig, ImFontGlyph, ImFontGlyphRangesBuilder, ImFontAtlasFlags, ImFontAtlas, ImFont)
// Platform interface for multi-viewport support (ImGuiPlatformMonitor, ImGuiPlatformIO, ImGuiViewport)
@@ -27,7 +28,7 @@ Index of this file:
#pragma once
-// Configuration file (edit imconfig.h or define IMGUI_USER_CONFIG to your own filename)
+// Configuration file with compile-time options (edit imconfig.h or define IMGUI_USER_CONFIG to your own filename)
#ifdef IMGUI_USER_CONFIG
#include IMGUI_USER_CONFIG
#endif
@@ -45,15 +46,16 @@ Index of this file:
#include // memset, memmove, memcpy, strlen, strchr, strcpy, strcmp
// Version
-// (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY00 then bounced up to XYY01 when release tagging happens)
-#define IMGUI_VERSION "1.68 WIP"
-#define IMGUI_VERSION_NUM 16800
-#define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert))
+// (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens)
+#define IMGUI_VERSION "1.73 WIP"
+#define IMGUI_VERSION_NUM 17203
+#define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx))
#define IMGUI_HAS_VIEWPORT 1 // Viewport WIP branch
#define IMGUI_HAS_DOCK 1 // Docking WIP branch
// Define attributes of all API symbols declarations (e.g. for DLL under Windows)
// IMGUI_API is used for core imgui functions, IMGUI_IMPL_API is used for the default bindings files (imgui_impl_xxx.h)
+// Using dear imgui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.
#ifndef IMGUI_API
#define IMGUI_API
#endif
@@ -74,8 +76,12 @@ Index of this file:
#define IM_FMTLIST(FMT)
#endif
#define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR)/sizeof(*_ARR))) // Size of a static C-style array. Don't use on pointers!
-#define IM_OFFSETOF(_TYPE,_MEMBER) ((size_t)&(((_TYPE*)0)->_MEMBER)) // Offset of _MEMBER within _TYPE. Standardized as offsetof() in modern C++.
#define IM_UNUSED(_VAR) ((void)_VAR) // Used to silence "unused variable warnings". Often useful as asserts may be stripped out from final builds.
+#if (__cplusplus >= 201100)
+#define IM_OFFSETOF(_TYPE,_MEMBER) offsetof(_TYPE, _MEMBER) // Offset of _MEMBER within _TYPE. Standardized as offsetof() in C++11
+#else
+#define IM_OFFSETOF(_TYPE,_MEMBER) ((size_t)&(((_TYPE*)0)->_MEMBER)) // Offset of _MEMBER within _TYPE. Old style macro.
+#endif
// Warnings
#if defined(__clang__)
@@ -84,20 +90,22 @@ Index of this file:
#if __has_warning("-Wzero-as-null-pointer-constant")
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
#endif
-#elif defined(__GNUC__) && __GNUC__ >= 8
+#elif defined(__GNUC__)
#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wclass-memaccess"
+#pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind
+#pragma GCC diagnostic ignored "-Wclass-memaccess" // [__GNUC__ >= 8] warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead
#endif
//-----------------------------------------------------------------------------
// Forward declarations and basic types
//-----------------------------------------------------------------------------
-struct ImDrawChannel; // Temporary storage for ImDrawList ot output draw commands out of order, used by ImDrawList::ChannelsSplit()
+struct ImDrawChannel; // Temporary storage to output draw commands out of order, used by ImDrawListSplitter and ImDrawList::ChannelsSplit()
struct ImDrawCmd; // A single draw command within a parent ImDrawList (generally maps to 1 GPU draw call, unless it is a callback)
struct ImDrawData; // All draw command lists required to render the frame + pos/size coordinates to use for the projection matrix.
struct ImDrawList; // A single draw command list (generally one per window, conceptually you may see this as a dynamic "mesh" builder)
struct ImDrawListSharedData; // Data shared among multiple draw lists (typically owned by parent ImGui context, but you may create one yourself)
+struct ImDrawListSplitter; // Helper to split a draw list into different layers which can be drawn into out of order, then flattened back.
struct ImDrawVert; // A single vertex (pos + uv + col = 20 bytes by default. Override layout with IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT)
struct ImFont; // Runtime data for a single font within a parent ImFontAtlas
struct ImFontAtlas; // Runtime data for multiple fonts, bake multiple fonts into a single texture, TTF/OTF font loader
@@ -129,36 +137,39 @@ typedef void* ImTextureID; // User data to identify a texture (this is
typedef unsigned int ImGuiID; // Unique ID used by widgets (typically hashed from a stack of string)
typedef unsigned short ImWchar; // A single U16 character for keyboard input/display. We encode them as multi bytes UTF-8 when used in strings.
typedef int ImGuiCol; // -> enum ImGuiCol_ // Enum: A color identifier for styling
-typedef int ImGuiCond; // -> enum ImGuiCond_ // Enum: A condition for Set*()
+typedef int ImGuiCond; // -> enum ImGuiCond_ // Enum: A condition for many Set*() functions
typedef int ImGuiDataType; // -> enum ImGuiDataType_ // Enum: A primary data type
typedef int ImGuiDir; // -> enum ImGuiDir_ // Enum: A cardinal direction
typedef int ImGuiKey; // -> enum ImGuiKey_ // Enum: A key identifier (ImGui-side enum)
typedef int ImGuiNavInput; // -> enum ImGuiNavInput_ // Enum: An input identifier for navigation
typedef int ImGuiMouseCursor; // -> enum ImGuiMouseCursor_ // Enum: A mouse cursor identifier
typedef int ImGuiStyleVar; // -> enum ImGuiStyleVar_ // Enum: A variable identifier for styling
-typedef int ImDrawCornerFlags; // -> enum ImDrawCornerFlags_ // Flags: for ImDrawList::AddRect*() etc.
+typedef int ImDrawCornerFlags; // -> enum ImDrawCornerFlags_ // Flags: for ImDrawList::AddRect(), AddRectFilled() etc.
typedef int ImDrawListFlags; // -> enum ImDrawListFlags_ // Flags: for ImDrawList
typedef int ImFontAtlasFlags; // -> enum ImFontAtlasFlags_ // Flags: for ImFontAtlas
typedef int ImGuiBackendFlags; // -> enum ImGuiBackendFlags_ // Flags: for io.BackendFlags
-typedef int ImGuiColorEditFlags; // -> enum ImGuiColorEditFlags_ // Flags: for ColorEdit*(), ColorPicker*()
-typedef int ImGuiColumnsFlags; // -> enum ImGuiColumnsFlags_ // Flags: for Columns(), BeginColumns()
+typedef int ImGuiColorEditFlags; // -> enum ImGuiColorEditFlags_ // Flags: for ColorEdit4(), ColorPicker4() etc.
typedef int ImGuiConfigFlags; // -> enum ImGuiConfigFlags_ // Flags: for io.ConfigFlags
typedef int ImGuiComboFlags; // -> enum ImGuiComboFlags_ // Flags: for BeginCombo()
typedef int ImGuiDockNodeFlags; // -> enum ImGuiDockNodeFlags_ // Flags: for DockSpace()
-typedef int ImGuiDragDropFlags; // -> enum ImGuiDragDropFlags_ // Flags: for *DragDrop*()
+typedef int ImGuiDragDropFlags; // -> enum ImGuiDragDropFlags_ // Flags: for BeginDragDropSource(), AcceptDragDropPayload()
typedef int ImGuiFocusedFlags; // -> enum ImGuiFocusedFlags_ // Flags: for IsWindowFocused()
typedef int ImGuiHoveredFlags; // -> enum ImGuiHoveredFlags_ // Flags: for IsItemHovered(), IsWindowHovered() etc.
-typedef int ImGuiInputTextFlags; // -> enum ImGuiInputTextFlags_ // Flags: for InputText*()
+typedef int ImGuiInputTextFlags; // -> enum ImGuiInputTextFlags_ // Flags: for InputText(), InputTextMultiline()
typedef int ImGuiSelectableFlags; // -> enum ImGuiSelectableFlags_ // Flags: for Selectable()
typedef int ImGuiTabBarFlags; // -> enum ImGuiTabBarFlags_ // Flags: for BeginTabBar()
typedef int ImGuiTabItemFlags; // -> enum ImGuiTabItemFlags_ // Flags: for BeginTabItem()
-typedef int ImGuiTreeNodeFlags; // -> enum ImGuiTreeNodeFlags_ // Flags: for TreeNode*(),CollapsingHeader()
+typedef int ImGuiTreeNodeFlags; // -> enum ImGuiTreeNodeFlags_ // Flags: for TreeNode(), TreeNodeEx(), CollapsingHeader()
typedef int ImGuiViewportFlags; // -> enum ImGuiViewportFlags_ // Flags: for ImGuiViewport
-typedef int ImGuiWindowFlags; // -> enum ImGuiWindowFlags_ // Flags: for Begin*()
+typedef int ImGuiWindowFlags; // -> enum ImGuiWindowFlags_ // Flags: for Begin(), BeginChild()
typedef int (*ImGuiInputTextCallback)(ImGuiInputTextCallbackData *data);
typedef void (*ImGuiSizeCallback)(ImGuiSizeCallbackData* data);
// Scalar data types
+typedef signed char ImS8; // 8-bit signed integer == char
+typedef unsigned char ImU8; // 8-bit unsigned integer
+typedef signed short ImS16; // 16-bit signed integer
+typedef unsigned short ImU16; // 16-bit unsigned integer
typedef signed int ImS32; // 32-bit signed integer == int
typedef unsigned int ImU32; // 32-bit unsigned integer (often used to store packed colors)
#if defined(_MSC_VER) && !defined(__clang__)
@@ -211,25 +222,25 @@ namespace ImGui
IMGUI_API void DestroyContext(ImGuiContext* ctx = NULL); // NULL = destroy current context
IMGUI_API ImGuiContext* GetCurrentContext();
IMGUI_API void SetCurrentContext(ImGuiContext* ctx);
- IMGUI_API bool DebugCheckVersionAndDataLayout(const char* version_str, size_t sz_io, size_t sz_style, size_t sz_vec2, size_t sz_vec4, size_t sz_drawvert);
+ IMGUI_API bool DebugCheckVersionAndDataLayout(const char* version_str, size_t sz_io, size_t sz_style, size_t sz_vec2, size_t sz_vec4, size_t sz_drawvert, size_t sz_drawidx);
// Main
IMGUI_API ImGuiIO& GetIO(); // access the IO structure (mouse/keyboard/gamepad inputs, time, various configuration options/flags)
IMGUI_API ImGuiStyle& GetStyle(); // access the Style structure (colors, sizes). Always use PushStyleCol(), PushStyleVar() to modify style mid-frame.
- IMGUI_API void NewFrame(); // start a new ImGui frame, you can submit any command from this point until Render()/EndFrame().
- IMGUI_API void EndFrame(); // ends the ImGui frame. automatically called by Render(), you likely don't need to call that yourself directly. If you don't need to render data (skipping rendering) you may call EndFrame() but you'll have wasted CPU already! If you don't need to render, better to not create any imgui windows and not call NewFrame() at all!
- IMGUI_API void Render(); // ends the ImGui frame, finalize the draw data. (Obsolete: optionally call io.RenderDrawListsFn if set. Nowadays, prefer calling your render function yourself.)
- IMGUI_API ImDrawData* GetDrawData(); // valid after Render() and until the next call to NewFrame(). this is what you have to render. (Obsolete: this used to be passed to your io.RenderDrawListsFn() function.)
+ IMGUI_API void NewFrame(); // start a new Dear ImGui frame, you can submit any command from this point until Render()/EndFrame().
+ IMGUI_API void EndFrame(); // ends the Dear ImGui frame. automatically called by Render(), you likely don't need to call that yourself directly. If you don't need to render data (skipping rendering) you may call EndFrame() but you'll have wasted CPU already! If you don't need to render, better to not create any imgui windows and not call NewFrame() at all!
+ IMGUI_API void Render(); // ends the Dear ImGui frame, finalize the draw data. You can get call GetDrawData() to obtain it and run your rendering function. (Obsolete: this used to call io.RenderDrawListsFn(). Nowadays, we allow and prefer calling your render function yourself.)
+ IMGUI_API ImDrawData* GetDrawData(); // valid after Render() and until the next call to NewFrame(). this is what you have to render.
// Demo, Debug, Information
- IMGUI_API void ShowDemoWindow(bool* p_open = NULL); // create demo/test window (previously called ShowTestWindow). demonstrate most ImGui features. call this to learn about the library! try to make it always available in your application!
- IMGUI_API void ShowAboutWindow(bool* p_open = NULL); // create about window. display Dear ImGui version, credits and build/system information.
- IMGUI_API void ShowMetricsWindow(bool* p_open = NULL); // create metrics window. display Dear ImGui internals: draw commands (with individual draw calls and vertices), window list, basic internal state, etc.
+ IMGUI_API void ShowDemoWindow(bool* p_open = NULL); // create Demo window (previously called ShowTestWindow). demonstrate most ImGui features. call this to learn about the library! try to make it always available in your application!
+ IMGUI_API void ShowAboutWindow(bool* p_open = NULL); // create About window. display Dear ImGui version, credits and build/system information.
+ IMGUI_API void ShowMetricsWindow(bool* p_open = NULL); // create Metrics/Debug window. display Dear ImGui internals: draw commands (with individual draw calls and vertices), window list, basic internal state, etc.
IMGUI_API void ShowStyleEditor(ImGuiStyle* ref = NULL); // add style editor block (not a window). you can pass in a reference ImGuiStyle structure to compare to, revert to and save to (else it uses the default style)
IMGUI_API bool ShowStyleSelector(const char* label); // add style selector block (not a window), essentially a combo listing the default styles.
IMGUI_API void ShowFontSelector(const char* label); // add font selector block (not a window), essentially a combo listing the loaded fonts.
IMGUI_API void ShowUserGuide(); // add basic help/info block (not a window): how to manipulate ImGui as a end-user (mouse/keyboard controls).
- IMGUI_API const char* GetVersion(); // get the compiled version string e.g. "1.23"
+ IMGUI_API const char* GetVersion(); // get the compiled version string e.g. "1.23" (essentially the compiled value for IMGUI_VERSION)
// Styles
IMGUI_API void StyleColorsDark(ImGuiStyle* dst = NULL); // new, recommended style (default)
@@ -271,31 +282,33 @@ namespace ImGui
IMGUI_API ImVec2 GetWindowSize(); // get current window size
IMGUI_API float GetWindowWidth(); // get current window width (shortcut for GetWindowSize().x)
IMGUI_API float GetWindowHeight(); // get current window height (shortcut for GetWindowSize().y)
- IMGUI_API ImVec2 GetContentRegionMax(); // current content boundaries (typically window boundaries including scrolling, or current column boundaries), in windows coordinates
- IMGUI_API ImVec2 GetContentRegionAvail(); // == GetContentRegionMax() - GetCursorPos()
- IMGUI_API float GetContentRegionAvailWidth(); //
- IMGUI_API ImVec2 GetWindowContentRegionMin(); // content boundaries min (roughly (0,0)-Scroll), in window coordinates
- IMGUI_API ImVec2 GetWindowContentRegionMax(); // content boundaries max (roughly (0,0)+Size-Scroll) where Size can be override with SetNextWindowContentSize(), in window coordinates
- IMGUI_API float GetWindowContentRegionWidth(); //
+ // Prefer using SetNextXXX functions (before Begin) rather that SetXXX functions (after Begin).
IMGUI_API void SetNextWindowPos(const ImVec2& pos, ImGuiCond cond = 0, const ImVec2& pivot = ImVec2(0,0)); // set next window position. call before Begin(). use pivot=(0.5f,0.5f) to center on given point, etc.
IMGUI_API void SetNextWindowSize(const ImVec2& size, ImGuiCond cond = 0); // set next window size. set axis to 0.0f to force an auto-fit on this axis. call before Begin()
- IMGUI_API void SetNextWindowSizeConstraints(const ImVec2& size_min, const ImVec2& size_max, ImGuiSizeCallback custom_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_API void SetNextWindowContentSize(const ImVec2& size); // set next window content size (~ enforce the range of scrollbars). not including window decorations (title bar, menu bar, etc.). set an axis to 0.0f to leave it automatic. call before Begin()
+ IMGUI_API void SetNextWindowSizeConstraints(const ImVec2& size_min, const ImVec2& size_max, ImGuiSizeCallback custom_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. Sizes will be rounded down. Use callback to apply non-trivial programmatic constraints.
+ IMGUI_API void SetNextWindowContentSize(const ImVec2& size); // set next window content size (~ scrollable client area, which enforce the range of scrollbars). Not including window decorations (title bar, menu bar, etc.) nor WindowPadding. set an axis to 0.0f to leave it automatic. call before Begin()
IMGUI_API void SetNextWindowCollapsed(bool collapsed, ImGuiCond cond = 0); // set next window collapsed state. call before Begin()
- IMGUI_API void SetNextWindowFocus(); // set next window to be focused / front-most. call before Begin()
+ IMGUI_API void SetNextWindowFocus(); // set next window to be focused / top-most. call before Begin()
IMGUI_API void SetNextWindowBgAlpha(float alpha); // set next window background color alpha. helper to easily modify ImGuiCol_WindowBg/ChildBg/PopupBg. you may also use ImGuiWindowFlags_NoBackground.
IMGUI_API void SetNextWindowViewport(ImGuiID viewport_id); // set next window viewport
- IMGUI_API void SetNextWindowClass(const ImGuiWindowClass* window_class); // set next window class (rare/advanced uses: provide hints to the platform back-end via altered viewport flags and parent/child info)
IMGUI_API void SetWindowPos(const ImVec2& pos, ImGuiCond cond = 0); // (not recommended) set current window position - call within Begin()/End(). prefer using SetNextWindowPos(), as this may incur tearing and side-effects.
IMGUI_API void SetWindowSize(const ImVec2& size, ImGuiCond cond = 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_API void SetWindowCollapsed(bool collapsed, ImGuiCond cond = 0); // (not recommended) set current window collapsed state. prefer using SetNextWindowCollapsed().
- IMGUI_API void SetWindowFocus(); // (not recommended) set current window to be focused / front-most. prefer using SetNextWindowFocus().
- IMGUI_API void SetWindowFontScale(float scale); // set font scale. Adjust IO.FontGlobalScale if you want to scale all windows
+ IMGUI_API void SetWindowFocus(); // (not recommended) set current window to be focused / top-most. prefer using SetNextWindowFocus().
+ IMGUI_API void SetWindowFontScale(float scale); // set font scale. Adjust IO.FontGlobalScale if you want to scale all windows. This is an old API! For correct scaling, prefer to reload font + rebuild ImFontAtlas + call style.ScaleAllSizes().
IMGUI_API void SetWindowPos(const char* name, const ImVec2& pos, ImGuiCond cond = 0); // set named window position.
IMGUI_API void SetWindowSize(const char* name, const ImVec2& size, ImGuiCond cond = 0); // set named window size. set axis to 0.0f to force an auto-fit on this axis.
IMGUI_API void SetWindowCollapsed(const char* name, bool collapsed, ImGuiCond cond = 0); // set named window collapsed state
- IMGUI_API void SetWindowFocus(const char* name); // set named window to be focused / front-most. use NULL to remove focus.
+ IMGUI_API void SetWindowFocus(const char* name); // set named window to be focused / top-most. use NULL to remove focus.
+
+ // Content region
+ // - Those functions are bound to be redesigned soon (they are confusing, incomplete and return values in local window coordinates which increases confusion)
+ IMGUI_API ImVec2 GetContentRegionMax(); // current content boundaries (typically window boundaries including scrolling, or current column boundaries), in windows coordinates
+ IMGUI_API ImVec2 GetContentRegionAvail(); // == GetContentRegionMax() - GetCursorPos()
+ IMGUI_API ImVec2 GetWindowContentRegionMin(); // content boundaries min (roughly (0,0)-Scroll), in window coordinates
+ IMGUI_API ImVec2 GetWindowContentRegionMax(); // content boundaries max (roughly (0,0)+Size-Scroll) where Size can be override with SetNextWindowContentSize(), in window coordinates
+ IMGUI_API float GetWindowContentRegionWidth(); //
// Windows Scrolling
IMGUI_API float GetScrollX(); // get scrolling amount [0..GetScrollMaxX()]
@@ -304,8 +317,10 @@ namespace ImGui
IMGUI_API float GetScrollMaxY(); // get maximum scrolling amount ~~ ContentSize.Y - WindowSize.Y
IMGUI_API void SetScrollX(float scroll_x); // set scrolling amount [0..GetScrollMaxX()]
IMGUI_API void SetScrollY(float scroll_y); // set scrolling amount [0..GetScrollMaxY()]
+ IMGUI_API void SetScrollHereX(float center_x_ratio = 0.5f); // adjust scrolling amount to make current cursor position visible. center_x_ratio=0.0: left, 0.5: center, 1.0: right. When using to make a "default/current item" visible, consider using SetItemDefaultFocus() instead.
IMGUI_API void SetScrollHereY(float center_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. When using to make a "default/current item" visible, consider using SetItemDefaultFocus() instead.
- IMGUI_API void SetScrollFromPosY(float local_y, float center_y_ratio = 0.5f); // adjust scrolling amount to make given position valid. use GetCursorPos() or GetCursorStartPos()+offset to get valid positions.
+ IMGUI_API void SetScrollFromPosX(float local_x, float center_x_ratio = 0.5f); // adjust scrolling amount to make given position visible. Generally GetCursorStartPos() + offset to compute a valid position.
+ IMGUI_API void SetScrollFromPosY(float local_y, float center_y_ratio = 0.5f); // adjust scrolling amount to make given position visible. Generally GetCursorStartPos() + offset to compute a valid position.
// Parameters stacks (shared)
IMGUI_API void PushFont(ImFont* font); // use NULL as a shortcut to push default font
@@ -325,9 +340,10 @@ namespace ImGui
IMGUI_API ImU32 GetColorU32(ImU32 col); // retrieve given color with style alpha applied
// Parameters stacks (current window)
- IMGUI_API void PushItemWidth(float item_width); // width of items for the common item+label case, pixels. 0.0f = default to ~2/3 of windows width, >0.0f: width in pixels, <0.0f align xx pixels to the right of window (so -1.0f always align width to the right side)
+ IMGUI_API void PushItemWidth(float item_width); // set width of items for common large "item+label" widgets. >0.0f: width in pixels, <0.0f align xx pixels to the right of window (so -1.0f always align width to the right side). 0.0f = default to ~2/3 of windows width,
IMGUI_API void PopItemWidth();
- IMGUI_API float CalcItemWidth(); // width of item given pushed settings and current cursor position
+ IMGUI_API void SetNextItemWidth(float item_width); // set width of the _next_ common large "item+label" widget. >0.0f: width in pixels, <0.0f align xx pixels to the right of window (so -1.0f always align width to the right side)
+ IMGUI_API float CalcItemWidth(); // width of item given pushed settings and current cursor position. NOT necessarily the width of last item unlike most 'Item' functions.
IMGUI_API void PushTextWrapPos(float wrap_local_pos_x = 0.0f); // word-wrapping for Text*() commands. < 0.0f: no wrapping; 0.0f: wrap to end of window (or column); > 0.0f: wrap at 'wrap_pos_x' position in window local space
IMGUI_API void PopTextWrapPos();
IMGUI_API void PushAllowKeyboardFocus(bool allow_keyboard_focus); // allow focusing using TAB/Shift-TAB, enabled by default but you can disable it for certain widgets
@@ -339,7 +355,7 @@ namespace ImGui
// - By "cursor" we mean the current output position.
// - The typical widget behavior is to output themselves at the current cursor position, then move the cursor one line down.
IMGUI_API void Separator(); // separator, generally horizontal. inside a menu bar or in horizontal layout mode, this becomes a vertical separator.
- IMGUI_API void SameLine(float local_pos_x = 0.0f, float spacing_w = -1.0f); // call between widgets or groups to layout them horizontally. X position given in window coordinates.
+ IMGUI_API void SameLine(float offset_from_start_x=0.0f, float spacing=-1.0f); // call between widgets or groups to layout them horizontally. X position given in window coordinates.
IMGUI_API void NewLine(); // undo a SameLine() or force a new line when in an horizontal-layout context.
IMGUI_API void Spacing(); // add vertical spacing.
IMGUI_API void Dummy(const ImVec2& size); // add a dummy item of given size. unlike InvisibleButton(), Dummy() won't take the mouse click or be navigable into.
@@ -371,7 +387,7 @@ namespace ImGui
// whereas "str_id" denote a string that is only used as an ID and not normally displayed.
IMGUI_API void PushID(const char* str_id); // push string into the ID stack (will hash string).
IMGUI_API void PushID(const char* str_id_begin, const char* str_id_end); // push string into the ID stack (will hash string).
- IMGUI_API void PushID(const void* ptr_id); // push pointer into the ID stack (will hash pointer).
+ IMGUI_API void PushID(const void* ptr_id); // push pointer into the ID stack (will hash pointer).
IMGUI_API void PushID(int int_id); // push integer into the ID stack (will hash integer).
IMGUI_API void PopID(); // pop from the ID stack.
IMGUI_API ImGuiID GetID(const char* str_id); // calculate unique ID (hash of whole ID stack + given parameter). e.g. if you want to query into ImGuiStorage yourself
@@ -397,7 +413,7 @@ namespace ImGui
// - Most widgets return true when the value has been changed or when pressed/selected
IMGUI_API bool Button(const char* label, const ImVec2& size = ImVec2(0,0)); // button
IMGUI_API bool SmallButton(const char* label); // button with FramePadding=(0,0) to easily embed within text
- IMGUI_API bool InvisibleButton(const char* str_id, const ImVec2& size); // button behavior without the visuals, useful to build custom behaviors using the public api (along with IsItemActive, IsItemHovered, etc.)
+ IMGUI_API bool InvisibleButton(const char* str_id, const ImVec2& size); // button behavior without the visuals, frequently useful to build custom behaviors using the public api (along with IsItemActive, IsItemHovered, etc.)
IMGUI_API bool ArrowButton(const char* str_id, ImGuiDir dir); // square button with an arrow shape
IMGUI_API void Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), const ImVec4& tint_col = ImVec4(1,1,1,1), const ImVec4& border_col = ImVec4(0,0,0,0));
IMGUI_API bool ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0,0), const ImVec2& uv1 = ImVec2(1,1), int frame_padding = -1, const ImVec4& bg_col = ImVec4(0,0,0,0), const ImVec4& tint_col = ImVec4(1,1,1,1)); // <0 frame_padding uses default frame padding settings. 0 for no padding
@@ -422,6 +438,8 @@ namespace ImGui
// - For all the Float2/Float3/Float4/Int2/Int3/Int4 versions of every functions, note that a 'float v[X]' function argument is the same as 'float* v', the array syntax is just a way to document the number of elements that are expected to be accessible. You can pass address of your first element out of a contiguous set, e.g. &myvector.x
// - Adjust format string to decorate the value with a prefix, a suffix, or adapt the editing and display precision e.g. "%.3f" -> 1.234; "%5.2f secs" -> 01.23 secs; "Biscuit: %.0f" -> Biscuit: 1; etc.
// - Speed are per-pixel of mouse movement (v_speed=0.2f: mouse needs to move by 5 pixels to increase value by 1). For gamepad/keyboard navigation, minimum speed is Max(v_speed, minimum_step_at_given_precision).
+ // - Use v_min < v_max to clamp edits to given limits. Note that CTRL+Click manual input can override those limits.
+ // - Use v_min > v_max to lock edits.
IMGUI_API bool DragFloat(const char* label, float* v, float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* format = "%.3f", float power = 1.0f); // If v_min >= v_max we have no bound
IMGUI_API bool DragFloat2(const char* label, float v[2], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* format = "%.3f", float power = 1.0f);
IMGUI_API bool DragFloat3(const char* label, float v[3], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* format = "%.3f", float power = 1.0f);
@@ -458,6 +476,7 @@ namespace ImGui
// - Most of the ImGuiInputTextFlags flags are only useful for InputText() and not for InputFloatX, InputIntX, InputDouble etc.
IMGUI_API bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL);
IMGUI_API bool InputTextMultiline(const char* label, char* buf, size_t buf_size, const ImVec2& size = ImVec2(0,0), ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL);
+ IMGUI_API bool InputTextWithHint(const char* label, const char* hint, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL);
IMGUI_API bool InputFloat(const char* label, float* v, float step = 0.0f, float step_fast = 0.0f, const char* format = "%.3f", ImGuiInputTextFlags flags = 0);
IMGUI_API bool InputFloat2(const char* label, float v[2], const char* format = "%.3f", ImGuiInputTextFlags flags = 0);
IMGUI_API bool InputFloat3(const char* label, float v[3], const char* format = "%.3f", ImGuiInputTextFlags flags = 0);
@@ -471,7 +490,8 @@ namespace ImGui
IMGUI_API bool InputScalarN(const char* label, ImGuiDataType data_type, void* v, int components, const void* step = NULL, const void* step_fast = NULL, const char* format = NULL, ImGuiInputTextFlags flags = 0);
// Widgets: Color Editor/Picker (tip: the ColorEdit* functions have a little colored preview square that can be left-clicked to open a picker, and right-clicked to open an option menu.)
- // - Note that in C++ a 'float v[X]' function argument is the _same_ as 'float* v', the array syntax is just a way to document the number of elements that are expected to be accessible. You can the pass the address of a first float element out of a contiguous structure, e.g. &myvector.x
+ // - Note that in C++ a 'float v[X]' function argument is the _same_ as 'float* v', the array syntax is just a way to document the number of elements that are expected to be accessible.
+ // - You can pass the address of a first float element out of a contiguous structure, e.g. &myvector.x
IMGUI_API bool ColorEdit3(const char* label, float col[3], ImGuiColorEditFlags flags = 0);
IMGUI_API bool ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flags = 0);
IMGUI_API bool ColorPicker3(const char* label, float col[3], ImGuiColorEditFlags flags = 0);
@@ -482,7 +502,7 @@ namespace ImGui
// Widgets: Trees
// - TreeNode functions return true when the node is open, in which case you need to also call TreePop() when you are finished displaying the tree node contents.
IMGUI_API bool TreeNode(const char* label);
- IMGUI_API bool TreeNode(const char* str_id, const char* fmt, ...) IM_FMTARGS(2); // helper variation to completely decorelate the id from the displayed string. 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_API bool TreeNode(const char* str_id, const char* fmt, ...) IM_FMTARGS(2); // helper variation to easily decorelate the id from the displayed string. 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_API bool TreeNode(const void* ptr_id, const char* fmt, ...) IM_FMTARGS(2); // "
IMGUI_API bool TreeNodeV(const char* str_id, const char* fmt, va_list args) IM_FMTLIST(2);
IMGUI_API bool TreeNodeV(const void* ptr_id, const char* fmt, va_list args) IM_FMTLIST(2);
@@ -494,11 +514,10 @@ namespace ImGui
IMGUI_API void TreePush(const char* str_id); // ~ Indent()+PushId(). Already called by TreeNode() when returning true, but you can call TreePush/TreePop yourself if desired.
IMGUI_API void TreePush(const void* ptr_id = NULL); // "
IMGUI_API void TreePop(); // ~ Unindent()+PopId()
- IMGUI_API void TreeAdvanceToLabelPos(); // advance cursor x position by GetTreeNodeToLabelSpacing()
IMGUI_API float GetTreeNodeToLabelSpacing(); // horizontal distance preceding label when using TreeNode*() or Bullet() == (g.FontSize + style.FramePadding.x*2) for a regular unframed TreeNode
- IMGUI_API void SetNextTreeNodeOpen(bool is_open, ImGuiCond cond = 0); // set next TreeNode/CollapsingHeader open state.
IMGUI_API bool CollapsingHeader(const char* label, ImGuiTreeNodeFlags flags = 0); // if returning 'true' the header is open. doesn't indent nor push on ID stack. user doesn't have to call TreePop().
IMGUI_API bool CollapsingHeader(const char* label, bool* p_open, ImGuiTreeNodeFlags flags = 0); // when 'p_open' isn't NULL, display an additional small close button on upper right of the header
+ IMGUI_API void SetNextItemOpen(bool is_open, ImGuiCond cond = 0); // set next TreeNode/CollapsingHeader open state.
// Widgets: Selectables
// - A selectable highlights when hovered, and can display another color when selected.
@@ -540,7 +559,7 @@ namespace ImGui
// Tooltips
IMGUI_API void BeginTooltip(); // begin/append a tooltip window. to create full-featured tooltip (with any kind of items).
IMGUI_API void EndTooltip();
- IMGUI_API void SetTooltip(const char* fmt, ...) IM_FMTARGS(1); // set a text-only tooltip, typically use with ImGui::IsItemHovered(). overidde any previous call to SetTooltip().
+ IMGUI_API void SetTooltip(const char* fmt, ...) IM_FMTARGS(1); // set a text-only tooltip, typically use with ImGui::IsItemHovered(). override any previous call to SetTooltip().
IMGUI_API void SetTooltipV(const char* fmt, va_list args) IM_FMTLIST(1);
// Popups, Modals
@@ -586,20 +605,21 @@ namespace ImGui
// Docking
// [BETA API] Enable with io.ConfigFlags |= ImGuiConfigFlags_DockingEnable.
// Note: you DO NOT need to call DockSpace() to use most Docking facilities!
- // To dock windows: hold SHIFT anywhere while moving windows (if io.ConfigDockingWithShift == true) or drag windows from their title bar (if io.ConfigDockingWithShift = false)
- // Use DockSpace() to create an explicit dock node _within_ an existing window. See Docking demo for details.
+ // - To dock windows: if io.ConfigDockingWithShift == false (default) drag window from their title bar.
+ // - To dock windows: if io.ConfigDockingWithShift == true: hold SHIFT anywhere while moving windows.
+ // - Use DockSpace() to create an explicit dock node _within_ an existing window. See Docking demo for details.
IMGUI_API void DockSpace(ImGuiID id, const ImVec2& size = ImVec2(0, 0), ImGuiDockNodeFlags flags = 0, const ImGuiWindowClass* window_class = NULL);
- IMGUI_API ImGuiID DockSpaceOverViewport(ImGuiViewport* viewport = NULL, ImGuiDockNodeFlags dockspace_flags = 0, const ImGuiWindowClass* window_class = NULL);
+ IMGUI_API ImGuiID DockSpaceOverViewport(ImGuiViewport* viewport = NULL, ImGuiDockNodeFlags flags = 0, const ImGuiWindowClass* window_class = NULL);
IMGUI_API void SetNextWindowDockID(ImGuiID dock_id, ImGuiCond cond = 0); // set next window dock id (FIXME-DOCK)
- IMGUI_API void SetNextWindowClass(const ImGuiWindowClass* window_class); // set next window class / user type (docking filters by same user_type)
+ IMGUI_API void SetNextWindowClass(const ImGuiWindowClass* window_class); // set next window class (rare/advanced uses: provide hints to the platform back-end via altered viewport flags and parent/child info)
IMGUI_API ImGuiID GetWindowDockID();
IMGUI_API bool IsWindowDocked(); // is current window docked into another window?
// Logging/Capture
// - All text output from the interface can be captured into tty/file/clipboard. By default, tree nodes are automatically opened during logging.
- IMGUI_API void LogToTTY(int max_depth = -1); // start logging to tty (stdout)
- IMGUI_API void LogToFile(int max_depth = -1, const char* filename = NULL); // start logging to file
- IMGUI_API void LogToClipboard(int max_depth = -1); // start logging to OS clipboard
+ IMGUI_API void LogToTTY(int auto_open_depth = -1); // start logging to tty (stdout)
+ IMGUI_API void LogToFile(int auto_open_depth = -1, const char* filename = NULL); // start logging to file
+ IMGUI_API void LogToClipboard(int auto_open_depth = -1); // start logging to OS clipboard
IMGUI_API void LogFinish(); // stop logging (close file, etc.)
IMGUI_API void LogButtons(); // helper to display buttons for logging to tty/file/clipboard
IMGUI_API void LogText(const char* fmt, ...) IM_FMTARGS(1); // pass text data straight to log (without being displayed)
@@ -607,7 +627,7 @@ namespace ImGui
// Drag and Drop
// [BETA API] API may evolve!
IMGUI_API bool BeginDragDropSource(ImGuiDragDropFlags flags = 0); // call when the current item is active. If this return true, you can call SetDragDropPayload() + EndDragDropSource()
- IMGUI_API bool SetDragDropPayload(const char* type, const void* data, size_t size, ImGuiCond cond = 0);// type is a user defined string of maximum 32 characters. Strings starting with '_' are reserved for dear imgui internal types. Data is copied and held by imgui.
+ IMGUI_API bool SetDragDropPayload(const char* type, const void* data, size_t sz, ImGuiCond cond = 0); // type is a user defined string of maximum 32 characters. Strings starting with '_' are reserved for dear imgui internal types. Data is copied and held by imgui.
IMGUI_API void EndDragDropSource(); // only call EndDragDropSource() if BeginDragDropSource() returns true!
IMGUI_API bool BeginDragDropTarget(); // call after submitting an item that may receive a payload. If this returns true, you can call AcceptDragDropPayload() + EndDragDropTarget()
IMGUI_API const ImGuiPayload* AcceptDragDropPayload(const char* type, ImGuiDragDropFlags flags = 0); // accept contents of a given type. If ImGuiDragDropFlags_AcceptBeforeDelivery is set you can peek into the payload before the mouse button is released.
@@ -632,11 +652,12 @@ namespace ImGui
IMGUI_API bool IsItemClicked(int mouse_button = 0); // is the last item clicked? (e.g. button/node just clicked on) == IsMouseClicked(mouse_button) && IsItemHovered()
IMGUI_API bool IsItemVisible(); // is the last item visible? (items may be out of sight because of clipping/scrolling)
IMGUI_API bool IsItemEdited(); // did the last item modify its underlying value this frame? or was pressed? This is generally the same as the "bool" return value of many widgets.
+ IMGUI_API bool IsItemActivated(); // was the last item just made active (item was previously inactive).
IMGUI_API bool IsItemDeactivated(); // was the last item just made inactive (item was previously active). Useful for Undo/Redo patterns with widgets that requires continuous editing.
IMGUI_API bool IsItemDeactivatedAfterEdit(); // was the last item just made inactive and made a value change when it was active? (e.g. Slider/Drag moved). Useful for Undo/Redo patterns with widgets that requires continuous editing. Note that you may get false positives (some widgets such as Combo()/ListBox()/Selectable() will return true even when clicking an already selected item).
- IMGUI_API bool IsAnyItemHovered();
- IMGUI_API bool IsAnyItemActive();
- IMGUI_API bool IsAnyItemFocused();
+ IMGUI_API bool IsAnyItemHovered(); // is any item hovered?
+ IMGUI_API bool IsAnyItemActive(); // is any item active?
+ IMGUI_API bool IsAnyItemFocused(); // is any item focused?
IMGUI_API ImVec2 GetItemRectMin(); // get upper-left bounding rectangle of the last item (screen space)
IMGUI_API ImVec2 GetItemRectMax(); // get lower-right bounding rectangle of the last item (screen space)
IMGUI_API ImVec2 GetItemRectSize(); // get size of last item
@@ -647,10 +668,12 @@ namespace ImGui
IMGUI_API bool IsRectVisible(const ImVec2& rect_min, const ImVec2& rect_max); // test if rectangle (in screen space) is visible / not clipped. to perform coarse clipping on user's side.
IMGUI_API double GetTime(); // get global imgui time. incremented by io.DeltaTime every frame.
IMGUI_API int GetFrameCount(); // get global imgui frame count. incremented by 1 every frame.
- IMGUI_API ImDrawList* GetOverlayDrawList(); // get overlay draw list for the viewport associated to the current window. this draw list will be the last rendered. useful to quickly draw overlays shapes/text.
- IMGUI_API ImDrawList* GetOverlayDrawList(ImGuiViewport* viewport); // get overlay draw list for the given viewport.
- IMGUI_API ImDrawListSharedData* GetDrawListSharedData(); // you may use this when creating your own ImDrawList instances
- IMGUI_API const char* GetStyleColorName(ImGuiCol idx);
+ IMGUI_API ImDrawList* GetBackgroundDrawList(); // get background draw list for the viewport associated to the current window. this draw list will be the first rendering one. Useful to quickly draw shapes/text behind dear imgui contents.
+ IMGUI_API ImDrawList* GetForegroundDrawList(); // get foreground draw list for the viewport associated to the current window. this draw list will be the last rendered one. Useful to quickly draw shapes/text over dear imgui contents.
+ IMGUI_API ImDrawList* GetBackgroundDrawList(ImGuiViewport* viewport); // get background draw list for the given viewport. this draw list will be the first rendering one. Useful to quickly draw shapes/text behind dear imgui contents.
+ IMGUI_API ImDrawList* GetForegroundDrawList(ImGuiViewport* viewport); // get foreground draw list for the given viewport. this draw list will be the last rendered one. Useful to quickly draw shapes/text over dear imgui contents.
+ IMGUI_API ImDrawListSharedData* GetDrawListSharedData(); // you may use this when creating your own ImDrawList instances.
+ IMGUI_API const char* GetStyleColorName(ImGuiCol idx); // get a string corresponding to the enum value (for display, saving, etc.).
IMGUI_API void SetStateStorage(ImGuiStorage* storage); // replace current window storage with our own (if you want to manipulate it yourself, typically clear subsection of it)
IMGUI_API ImGuiStorage* GetStateStorage();
IMGUI_API ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, bool hide_text_after_double_hash = false, float wrap_width = -1.0f);
@@ -677,10 +700,10 @@ namespace ImGui
IMGUI_API bool IsMouseReleased(int button); // did mouse button released (went from Down to !Down)
IMGUI_API bool IsMouseDragging(int button = 0, float lock_threshold = -1.0f); // is mouse dragging. if lock_threshold < -1.0f uses io.MouseDraggingThreshold
IMGUI_API bool IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool clip = true); // is mouse hovering given bounding rect (in screen space). clipped by current clipping settings, but disregarding of other consideration of focus/window ordering/popup-block.
- IMGUI_API bool IsMousePosValid(const ImVec2* mouse_pos = NULL); //
+ IMGUI_API bool IsMousePosValid(const ImVec2* mouse_pos = NULL); // by convention we use (-FLT_MAX,-FLT_MAX) to denote that there is no mouse
IMGUI_API ImVec2 GetMousePos(); // shortcut to ImGui::GetIO().MousePos provided by user, to be consistent with other calls
IMGUI_API ImVec2 GetMousePosOnOpeningCurrentPopup(); // retrieve backup of mouse position at the time of opening popup we have BeginPopup() into
- IMGUI_API ImVec2 GetMouseDragDelta(int button = 0, float lock_threshold = -1.0f); // return the delta from the initial clicking position. This is locked and return 0.0f until the mouse moves past a distance threshold at least once. If lock_threshold < -1.0f uses io.MouseDraggingThreshold
+ IMGUI_API ImVec2 GetMouseDragDelta(int button = 0, float lock_threshold = -1.0f); // return the delta from the initial clicking position while the mouse button is pressed or was just released. This is locked and return 0.0f until the mouse moves past a distance threshold at least once. If lock_threshold < -1.0f uses io.MouseDraggingThreshold.
IMGUI_API void ResetMouseDragDelta(int button = 0); //
IMGUI_API ImGuiMouseCursor GetMouseCursor(); // get desired cursor type, reset in ImGui::NewFrame(), this is updated during the frame. valid before Render(). If you use software rendering by setting io.MouseDrawCursor ImGui will render those for you
IMGUI_API void SetMouseCursor(ImGuiMouseCursor type); // set desired cursor type
@@ -696,12 +719,12 @@ namespace ImGui
// - Set io.IniFilename to NULL to load/save manually. Read io.WantSaveIniSettings description about handling .ini saving manually.
IMGUI_API void LoadIniSettingsFromDisk(const char* ini_filename); // call after CreateContext() and before the first call to NewFrame(). NewFrame() automatically calls LoadIniSettingsFromDisk(io.IniFilename).
IMGUI_API void LoadIniSettingsFromMemory(const char* ini_data, size_t ini_size=0); // call after CreateContext() and before the first call to NewFrame() to provide .ini data from your own data source.
- IMGUI_API void SaveIniSettingsToDisk(const char* ini_filename);
+ IMGUI_API void SaveIniSettingsToDisk(const char* ini_filename); // this is automatically called (if io.IniFilename is not empty) a few seconds after any modification that should be reflected in the .ini file (and also by DestroyContext).
IMGUI_API const char* SaveIniSettingsToMemory(size_t* out_ini_size = NULL); // return a zero-terminated string with the .ini data which you can save by your own mean. call when io.WantSaveIniSettings is set, then save data by your own mean and clear io.WantSaveIniSettings.
- // Memory Utilities
+ // Memory Allocators
// - All those functions are not reliant on the current context.
- // - If you reload the contents of imgui.cpp at runtime, you may need to call SetCurrentContext() + SetAllocatorFunctions() again.
+ // - If you reload the contents of imgui.cpp at runtime, you may need to call SetCurrentContext() + SetAllocatorFunctions() again because we use global storage for those.
IMGUI_API void SetAllocatorFunctions(void* (*alloc_func)(size_t sz, void* user_data), void (*free_func)(void* ptr, void* user_data), void* user_data = NULL);
IMGUI_API void* MemAlloc(size_t size);
IMGUI_API void MemFree(void* ptr);
@@ -711,7 +734,7 @@ namespace ImGui
IMGUI_API ImGuiPlatformIO& GetPlatformIO(); // platform/renderer functions, for back-end to setup + viewports list.
IMGUI_API ImGuiViewport* GetMainViewport(); // main viewport. same as GetPlatformIO().MainViewport == GetPlatformIO().Viewports[0].
IMGUI_API void UpdatePlatformWindows(); // call in main loop. will call CreateWindow/ResizeWindow/etc. platform functions for each secondary viewport, and DestroyWindow for each inactive viewport.
- IMGUI_API void RenderPlatformWindowsDefault(void* platform_arg = NULL, void* renderer_arg = NULL); // call in main loop. will call RenderWindow/SwapBuffers platform functions for each secondary viewport. may be reimplemented by user for custom rendering needs.
+ IMGUI_API void RenderPlatformWindowsDefault(void* platform_arg = NULL, void* renderer_arg = NULL); // call in main loop. will call RenderWindow/SwapBuffers platform functions for each secondary viewport which doesn't have the ImGuiViewportFlags_Minimized flag set. May be reimplemented by user for custom rendering needs.
IMGUI_API void DestroyPlatformWindows(); // call DestroyWindow platform functions for all viewports. call from back-end Shutdown() if you need to close platform windows before imgui shutdown. otherwise will be called by DestroyContext().
IMGUI_API ImGuiViewport* FindViewportByID(ImGuiID id); // this is a helper for back-ends.
IMGUI_API ImGuiViewport* FindViewportByPlatformHandle(void* platform_handle); // this is a helper for back-ends. the type platform_handle is decided by the back-end (e.g. HWND, MyWindow*, GLFWwindow* etc.)
@@ -729,9 +752,9 @@ enum ImGuiWindowFlags_
ImGuiWindowFlags_NoTitleBar = 1 << 0, // Disable title-bar
ImGuiWindowFlags_NoResize = 1 << 1, // Disable user resizing with the lower-right grip
ImGuiWindowFlags_NoMove = 1 << 2, // Disable user moving the window
- ImGuiWindowFlags_NoScrollbar = 1 << 3, // Disable scrollbars (window can still scroll with mouse or programatically)
+ ImGuiWindowFlags_NoScrollbar = 1 << 3, // Disable scrollbars (window can still scroll with mouse or programmatically)
ImGuiWindowFlags_NoScrollWithMouse = 1 << 4, // Disable user vertically scrolling with mouse wheel. On child window, mouse wheel will be forwarded to the parent unless NoScrollbar is also set.
- ImGuiWindowFlags_NoCollapse = 1 << 5, // Disable user collapsing window by double-clicking on it
+ ImGuiWindowFlags_NoCollapse = 1 << 5, // Disable user collapsing window by double-clicking on it. Also referred to as "window menu button" within a docking node.
ImGuiWindowFlags_AlwaysAutoResize = 1 << 6, // Resize every window to its content every frame
ImGuiWindowFlags_NoBackground = 1 << 7, // Disable drawing background color (WindowBg, etc.) and outside border. Similar as using SetNextWindowBgAlpha(0.0f).
ImGuiWindowFlags_NoSavedSettings = 1 << 8, // Never load/save settings in .ini file
@@ -739,7 +762,7 @@ enum ImGuiWindowFlags_
ImGuiWindowFlags_MenuBar = 1 << 10, // Has a menu-bar
ImGuiWindowFlags_HorizontalScrollbar = 1 << 11, // Allow horizontal scrollbar to appear (off by default). You may use SetNextWindowContentSize(ImVec2(width,0.0f)); prior to calling Begin() to specify width. Read code in imgui_demo in the "Horizontal Scrolling" section.
ImGuiWindowFlags_NoFocusOnAppearing = 1 << 12, // Disable taking focus when transitioning from hidden to visible state
- ImGuiWindowFlags_NoBringToFrontOnFocus = 1 << 13, // Disable bringing window to front when taking focus (e.g. clicking on it or programatically giving it focus)
+ ImGuiWindowFlags_NoBringToFrontOnFocus = 1 << 13, // Disable bringing window to front when taking focus (e.g. clicking on it or programmatically giving it focus)
ImGuiWindowFlags_AlwaysVerticalScrollbar= 1 << 14, // Always show vertical scrollbar (even if ContentSize.y < Size.y)
ImGuiWindowFlags_AlwaysHorizontalScrollbar=1<< 15, // Always show horizontal scrollbar (even if ContentSize.x < Size.x)
ImGuiWindowFlags_AlwaysUseWindowPadding = 1 << 16, // Ensure child windows without border uses style.WindowPadding (ignored by default for non-bordered child windows, because more convenient)
@@ -775,7 +798,7 @@ enum ImGuiInputTextFlags_
ImGuiInputTextFlags_CharsUppercase = 1 << 2, // Turn a..z into A..Z
ImGuiInputTextFlags_CharsNoBlank = 1 << 3, // Filter out spaces, tabs
ImGuiInputTextFlags_AutoSelectAll = 1 << 4, // Select entire text when first taking mouse focus
- ImGuiInputTextFlags_EnterReturnsTrue = 1 << 5, // Return 'true' when Enter is pressed (as opposed to when the value was modified)
+ ImGuiInputTextFlags_EnterReturnsTrue = 1 << 5, // Return 'true' when Enter is pressed (as opposed to every time the value was modified). Consider looking at the IsItemDeactivatedAfterEdit() function.
ImGuiInputTextFlags_CallbackCompletion = 1 << 6, // Callback on pressing TAB (for completion handling)
ImGuiInputTextFlags_CallbackHistory = 1 << 7, // Callback on pressing Up/Down arrows (for history handling)
ImGuiInputTextFlags_CallbackAlways = 1 << 8, // Callback on each iteration. User code may query cursor position, modify text buffer.
@@ -790,7 +813,8 @@ enum ImGuiInputTextFlags_
ImGuiInputTextFlags_CharsScientific = 1 << 17, // Allow 0123456789.+-*/eE (Scientific notation input)
ImGuiInputTextFlags_CallbackResize = 1 << 18, // Callback on buffer capacity changes request (beyond 'buf_size' parameter value), allowing the string to grow. Notify when the string wants to be resized (for string types which hold a cache of their Size). You will be provided a new BufSize in the callback and NEED to honor it. (see misc/cpp/imgui_stdlib.h for an example of using this)
// [Internal]
- ImGuiInputTextFlags_Multiline = 1 << 20 // For internal use by InputTextMultiline()
+ ImGuiInputTextFlags_Multiline = 1 << 20, // For internal use by InputTextMultiline()
+ ImGuiInputTextFlags_NoMarkEdited = 1 << 21 // For internal use by functions using InputText() before reformatting data
};
// Flags for ImGui::TreeNodeEx(), ImGui::CollapsingHeader*()
@@ -808,14 +832,14 @@ enum ImGuiTreeNodeFlags_
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_FramePadding = 1 << 10, // Use FramePadding (even for an unframed text node) to vertically align text baseline to regular widget height. Equivalent to calling AlignTextToFramePadding().
- //ImGuITreeNodeFlags_SpanAllAvailWidth = 1 << 11, // FIXME: TODO: Extend hit box horizontally even if not framed
+ //ImGuiTreeNodeFlags_SpanAllAvailWidth = 1 << 11, // FIXME: TODO: Extend hit box horizontally even if not framed
//ImGuiTreeNodeFlags_NoScrollOnOpen = 1 << 12, // FIXME: TODO: Disable automatic scroll on TreePop() if node got just open and contents is not visible
ImGuiTreeNodeFlags_NavLeftJumpsBackHere = 1 << 13, // (WIP) Nav: left direction may move to this TreeNode() from any of its child (items submitted between TreeNode and TreePop)
ImGuiTreeNodeFlags_CollapsingHeader = ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_NoAutoOpenOnLog
// Obsolete names (will be removed)
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
- , ImGuiTreeNodeFlags_AllowOverlapMode = ImGuiTreeNodeFlags_AllowItemOverlap
+ , ImGuiTreeNodeFlags_AllowOverlapMode = ImGuiTreeNodeFlags_AllowItemOverlap // [renamed in 1.53]
#endif
};
@@ -826,7 +850,7 @@ enum ImGuiSelectableFlags_
ImGuiSelectableFlags_DontClosePopups = 1 << 0, // Clicking this don't close parent popup window
ImGuiSelectableFlags_SpanAllColumns = 1 << 1, // Selectable frame can span all columns (text will still fit in current column)
ImGuiSelectableFlags_AllowDoubleClick = 1 << 2, // Generate press events on double clicks too
- ImGuiSelectableFlags_Disabled = 1 << 3 // Cannot be selected, display greyed out text
+ ImGuiSelectableFlags_Disabled = 1 << 3 // Cannot be selected, display grayed out text
};
// Flags for ImGui::BeginCombo()
@@ -849,9 +873,9 @@ enum ImGuiTabBarFlags_
ImGuiTabBarFlags_None = 0,
ImGuiTabBarFlags_Reorderable = 1 << 0, // Allow manually dragging tabs to re-order them + New tabs are appended at the end of list
ImGuiTabBarFlags_AutoSelectNewTabs = 1 << 1, // Automatically select new tabs when they appear
- ImGuiTabBarFlags_NoCloseWithMiddleMouseButton = 1 << 2, // Disable behavior of closing tabs (that are submitted with p_open != NULL) with middle mouse button. You can still repro this behavior on user's side with if (IsItemHovered() && IsMouseClicked(2)) *p_open = false.
- ImGuiTabBarFlags_NoTabListPopupButton = 1 << 3,
- ImGuiTabBarFlags_NoTabListScrollingButtons = 1 << 4,
+ ImGuiTabBarFlags_TabListPopupButton = 1 << 2, // Disable buttons to open the tab list popup
+ ImGuiTabBarFlags_NoCloseWithMiddleMouseButton = 1 << 3, // Disable behavior of closing tabs (that are submitted with p_open != NULL) with middle mouse button. You can still repro this behavior on user's side with if (IsItemHovered() && IsMouseClicked(2)) *p_open = false.
+ ImGuiTabBarFlags_NoTabListScrollingButtons = 1 << 4, // Disable scrolling buttons (apply when fitting policy is ImGuiTabBarFlags_FittingPolicyScroll)
ImGuiTabBarFlags_NoTooltip = 1 << 5, // Disable tooltips when hovering a tab
ImGuiTabBarFlags_FittingPolicyResizeDown = 1 << 6, // Resize tabs when they don't fit
ImGuiTabBarFlags_FittingPolicyScroll = 1 << 7, // Add scroll buttons when tabs don't fit
@@ -864,25 +888,11 @@ enum ImGuiTabItemFlags_
{
ImGuiTabItemFlags_None = 0,
ImGuiTabItemFlags_UnsavedDocument = 1 << 0, // Append '*' to title without affecting the ID, as a convenience to avoid using the ### operator. Also: tab is selected on closure and closure is deferred by one frame to allow code to undo it without flicker.
- ImGuiTabItemFlags_SetSelected = 1 << 1, // Trigger flag to programatically make the tab selected when calling BeginTabItem()
+ ImGuiTabItemFlags_SetSelected = 1 << 1, // Trigger flag to programmatically make the tab selected when calling BeginTabItem()
ImGuiTabItemFlags_NoCloseWithMiddleMouseButton = 1 << 2, // Disable behavior of closing tabs (that are submitted with p_open != NULL) with middle mouse button. You can still repro this behavior on user's side with if (IsItemHovered() && IsMouseClicked(2)) *p_open = false.
ImGuiTabItemFlags_NoPushId = 1 << 3 // Don't call PushID(tab->ID)/PopID() on BeginTabItem()/EndTabItem()
};
-// Flags for ImGui::DockSpace(), inherited by child nodes.
-enum ImGuiDockNodeFlags_
-{
- ImGuiDockNodeFlags_None = 0,
- ImGuiDockNodeFlags_KeepAliveOnly = 1 << 0, // Don't display the dockspace node but keep it alive. Windows docked into this dockspace node won't be undocked.
- ImGuiDockNodeFlags_NoSplit = 1 << 1, // Disable splitting the node into smaller nodes. Useful e.g. when embedding dockspaces into a main root one (the root one may have splitting disabled to reduce confusion)
- //ImGuiDockNodeFlags_NoCentralNode = 1 << 2, // Disable Central Node (the node which can stay empty)
- ImGuiDockNodeFlags_NoDockingInCentralNode = 1 << 3, // Disable docking inside the Central Node, which will be always kept empty.
- //ImGuiDockNodeFlags_NoLayoutChanges = 1 << 4, // Disable adding/removing nodes interactively. Useful with programatically setup dockspaces.
- ImGuiDockNodeFlags_NoResize = 1 << 5, // Disable resizing child nodes using the splitter/separators. Useful with programatically setup dockspaces.
- ImGuiDockNodeFlags_PassthruDockspace = 1 << 6, // Enable passthru dockspace: 1) DockSpace() will render a ImGuiCol_WindowBg background covering everything excepted the Central Node when empty. Meaning the host window should probably use SetNextWindowBgAlpha(0.0f) prior to Begin() when using this. 2) When Central Node is empty: let inputs pass-through + won't display a DockingEmptyBg background.
- ImGuiDockNodeFlags_AutoHideTabBar = 1 << 7 // Tab bar will automatically hide when there is a single window in the dock node.
-};
-
// Flags for ImGui::IsWindowFocused()
enum ImGuiFocusedFlags_
{
@@ -905,12 +915,27 @@ enum ImGuiHoveredFlags_
ImGuiHoveredFlags_AllowWhenBlockedByPopup = 1 << 3, // Return true even if a popup window is normally blocking access to this item/window
//ImGuiHoveredFlags_AllowWhenBlockedByModal = 1 << 4, // Return true even if a modal popup window is normally blocking access to this item/window. FIXME-TODO: Unavailable yet.
ImGuiHoveredFlags_AllowWhenBlockedByActiveItem = 1 << 5, // Return true even if an active item is blocking access to this item/window. Useful for Drag and Drop patterns.
- ImGuiHoveredFlags_AllowWhenOverlapped = 1 << 6, // Return true even if the position is overlapped by another window
+ ImGuiHoveredFlags_AllowWhenOverlapped = 1 << 6, // Return true even if the position is obstructed or overlapped by another window
ImGuiHoveredFlags_AllowWhenDisabled = 1 << 7, // Return true even if the item is disabled
ImGuiHoveredFlags_RectOnly = ImGuiHoveredFlags_AllowWhenBlockedByPopup | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem | ImGuiHoveredFlags_AllowWhenOverlapped,
ImGuiHoveredFlags_RootAndChildWindows = ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows
};
+// Flags for ImGui::DockSpace(), shared/inherited by child nodes.
+// (Some flags can be applied to individual nodes directly)
+// FIXME-DOCK: Also see ImGuiDockNodeFlagsPrivate_ which may involve using the WIP and internal DockBuilder api.
+enum ImGuiDockNodeFlags_
+{
+ ImGuiDockNodeFlags_None = 0,
+ ImGuiDockNodeFlags_KeepAliveOnly = 1 << 0, // Shared // Don't display the dockspace node but keep it alive. Windows docked into this dockspace node won't be undocked.
+ //ImGuiDockNodeFlags_NoCentralNode = 1 << 1, // Shared // Disable Central Node (the node which can stay empty)
+ ImGuiDockNodeFlags_NoDockingInCentralNode = 1 << 2, // Shared // Disable docking inside the Central Node, which will be always kept empty.
+ ImGuiDockNodeFlags_PassthruCentralNode = 1 << 3, // Shared // Enable passthru dockspace: 1) DockSpace() will render a ImGuiCol_WindowBg background covering everything excepted the Central Node when empty. Meaning the host window should probably use SetNextWindowBgAlpha(0.0f) prior to Begin() when using this. 2) When Central Node is empty: let inputs pass-through + won't display a DockingEmptyBg background. See demo for details.
+ ImGuiDockNodeFlags_NoSplit = 1 << 4, // Shared/Local // Disable splitting the node into smaller nodes. Useful e.g. when embedding dockspaces into a main root one (the root one may have splitting disabled to reduce confusion). Note: when turned off, existing splits will be preserved.
+ ImGuiDockNodeFlags_NoResize = 1 << 5, // Shared/Local // Disable resizing node using the splitter/separators. Useful with programatically setup dockspaces.
+ ImGuiDockNodeFlags_AutoHideTabBar = 1 << 6 // Shared/Local // Tab bar will automatically hide when there is a single window in the dock node.
+};
+
// Flags for ImGui::BeginDragDropSource(), ImGui::AcceptDragDropPayload()
enum ImGuiDragDropFlags_
{
@@ -920,7 +945,7 @@ enum ImGuiDragDropFlags_
ImGuiDragDropFlags_SourceNoDisableHover = 1 << 1, // By default, when dragging we clear data so that IsItemHovered() will return false, to avoid subsequent user code submitting tooltips. This flag disable this behavior so you can still call IsItemHovered() on the source item.
ImGuiDragDropFlags_SourceNoHoldToOpenOthers = 1 << 2, // Disable the behavior that allows to open tree nodes and collapsing header by holding over them while dragging a source item.
ImGuiDragDropFlags_SourceAllowNullID = 1 << 3, // Allow items such as Text(), Image() that have no unique identifier to be used as drag source, by manufacturing a temporary identifier based on their window-relative position. This is extremely unusual within the dear imgui ecosystem and so we made it explicit.
- ImGuiDragDropFlags_SourceExtern = 1 << 4, // External source (from outside of imgui), won't attempt to read current item/window info. Will always return true. Only one Extern source can be active simultaneously.
+ ImGuiDragDropFlags_SourceExtern = 1 << 4, // External source (from outside of dear imgui), won't attempt to read current item/window info. Will always return true. Only one Extern source can be active simultaneously.
ImGuiDragDropFlags_SourceAutoExpirePayload = 1 << 5, // Automatically expire the payload if the source cease to be submitted (otherwise payloads are persisting while being dragged)
// AcceptDragDropPayload() flags
ImGuiDragDropFlags_AcceptBeforeDelivery = 1 << 10, // AcceptDragDropPayload() will returns true even before the mouse button is released. You can then call IsDelivery() to test if the payload needs to be delivered.
@@ -936,10 +961,14 @@ enum ImGuiDragDropFlags_
// A primary data type
enum ImGuiDataType_
{
+ ImGuiDataType_S8, // signed char / char (with sensible compilers)
+ ImGuiDataType_U8, // unsigned char
+ ImGuiDataType_S16, // short
+ ImGuiDataType_U16, // unsigned short
ImGuiDataType_S32, // int
ImGuiDataType_U32, // unsigned int
- ImGuiDataType_S64, // long long, __int64
- ImGuiDataType_U64, // unsigned long long, unsigned __int64
+ ImGuiDataType_S64, // long long / __int64
+ ImGuiDataType_U64, // unsigned long long / unsigned __int64
ImGuiDataType_Float, // float
ImGuiDataType_Double, // double
ImGuiDataType_COUNT
@@ -974,6 +1003,7 @@ enum ImGuiKey_
ImGuiKey_Space,
ImGuiKey_Enter,
ImGuiKey_Escape,
+ ImGuiKey_KeyPadEnter,
ImGuiKey_A, // for text edit CTRL+A: select all
ImGuiKey_C, // for text edit CTRL+C: copy
ImGuiKey_V, // for text edit CTRL+V: paste
@@ -1010,6 +1040,7 @@ enum ImGuiNavInput_
// [Internal] Don't use directly! This is used internally to differentiate keyboard from gamepad inputs for behaviors that require to differentiate them.
// Keyboard behavior that have no corresponding gamepad mapping (e.g. CTRL+TAB) will be directly reading from io.KeysDown[] instead of io.NavInputs[].
ImGuiNavInput_KeyMenu_, // toggle menu // = io.KeyAlt
+ ImGuiNavInput_KeyTab_, // tab // = Tab key
ImGuiNavInput_KeyLeft_, // move left // = Arrow keys
ImGuiNavInput_KeyRight_, // move right
ImGuiNavInput_KeyUp_, // move up
@@ -1030,7 +1061,7 @@ enum ImGuiConfigFlags_
ImGuiConfigFlags_NoMouseCursorChange = 1 << 5, // Instruct back-end to not alter mouse cursor shape and visibility. Use if the back-end cursor changes are interfering with yours and you don't want to use SetMouseCursor() to change mouse cursor. You may want to honor requests from imgui by reading GetMouseCursor() yourself instead.
// [BETA] Docking
- ImGuiConfigFlags_DockingEnable = 1 << 6, // Docking enable flags. Use SHIFT to dock window into another (or without SHIFT if io.ConfigDockingWithShift = false).
+ ImGuiConfigFlags_DockingEnable = 1 << 6, // Docking enable flags.
// [BETA] Viewports
// When using viewports it is recommended that your default value for ImGuiCol_WindowBg is opaque (Alpha=1.0) so transition to a viewport won't be noticeable.
@@ -1038,7 +1069,7 @@ enum ImGuiConfigFlags_
ImGuiConfigFlags_DpiEnableScaleViewports= 1 << 14, // [BETA: Don't use] FIXME-DPI: Reposition and resize imgui windows when the DpiScale of a viewport changed (mostly useful for the main viewport hosting other window). Note that resizing the main window itself is up to your application.
ImGuiConfigFlags_DpiEnableScaleFonts = 1 << 15, // [BETA: Don't use] FIXME-DPI: Request bitmap-scaled fonts to match DpiScale. This is a very low-quality workaround. The correct way to handle DPI is _currently_ to replace the atlas and/or fonts in the Platform_OnChangedViewport callback, but this is all early work in progress.
- // User storage (to allow your back-end/engine to communicate to code that may be shared between multiple projects. Those flags are not used by core ImGui)
+ // User storage (to allow your back-end/engine to communicate to code that may be shared between multiple projects. Those flags are not used by core Dear ImGui)
ImGuiConfigFlags_IsSRGB = 1 << 20, // Application is SRGB-aware.
ImGuiConfigFlags_IsTouchScreen = 1 << 21 // Application is using a touch screen instead of a mouse.
};
@@ -1047,9 +1078,10 @@ enum ImGuiConfigFlags_
enum ImGuiBackendFlags_
{
ImGuiBackendFlags_None = 0,
- ImGuiBackendFlags_HasGamepad = 1 << 0, // Back-end supports gamepad and currently has one connected.
- ImGuiBackendFlags_HasMouseCursors = 1 << 1, // Back-end supports honoring GetMouseCursor() value to change the OS cursor shape.
- ImGuiBackendFlags_HasSetMousePos = 1 << 2, // Back-end supports io.WantSetMousePos requests to reposition the OS mouse position (only used if ImGuiConfigFlags_NavEnableSetMousePos is set).
+ ImGuiBackendFlags_HasGamepad = 1 << 0, // Back-end Platform supports gamepad and currently has one connected.
+ ImGuiBackendFlags_HasMouseCursors = 1 << 1, // Back-end Platform supports honoring GetMouseCursor() value to change the OS cursor shape.
+ ImGuiBackendFlags_HasSetMousePos = 1 << 2, // Back-end Platform supports io.WantSetMousePos requests to reposition the OS mouse position (only used if ImGuiConfigFlags_NavEnableSetMousePos is set).
+ ImGuiBackendFlags_RendererHasVtxOffset = 1 << 3, // Back-end Renderer supports ImDrawCmd::VtxOffset. This enables output of large meshes (64K+ vertices) while still using 16-bits indices.
// [BETA] Viewports
ImGuiBackendFlags_PlatformHasViewports = 1 << 10, // Back-end Platform supports multiple viewports.
@@ -1084,7 +1116,7 @@ enum ImGuiCol_
ImGuiCol_Button,
ImGuiCol_ButtonHovered,
ImGuiCol_ButtonActive,
- ImGuiCol_Header,
+ ImGuiCol_Header, // Header* colors are used for CollapsingHeader, TreeNode, Selectable, MenuItem
ImGuiCol_HeaderHovered,
ImGuiCol_HeaderActive,
ImGuiCol_Separator,
@@ -1116,7 +1148,6 @@ enum ImGuiCol_
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
, ImGuiCol_ModalWindowDarkening = ImGuiCol_ModalWindowDimBg // [renamed in 1.63]
, ImGuiCol_ChildWindowBg = ImGuiCol_ChildBg // [renamed in 1.53]
- , ImGuiCol_Column = ImGuiCol_Separator, ImGuiCol_ColumnHovered = ImGuiCol_SeparatorHovered, ImGuiCol_ColumnActive = ImGuiCol_SeparatorActive // [renamed in 1.51]
//ImGuiCol_CloseButton, ImGuiCol_CloseButtonActive, ImGuiCol_CloseButtonHovered, // [unused since 1.60+] the close button now uses regular button colors.
//ImGuiCol_ComboBg, // [unused since 1.53+] ComboBg has been merged with PopupBg, so a redirect isn't accurate.
#endif
@@ -1127,7 +1158,7 @@ enum ImGuiCol_
// NB: if changing this enum, you need to update the associated internal table GStyleVarInfo[] accordingly. This is where we link enum values to members offset/type.
enum ImGuiStyleVar_
{
- // Enum name ......................// Member in ImGuiStyle structure (see ImGuiStyle for descriptions)
+ // Enum name --------------------- // Member in ImGuiStyle structure (see ImGuiStyle for descriptions)
ImGuiStyleVar_Alpha, // float Alpha
ImGuiStyleVar_WindowPadding, // ImVec2 WindowPadding
ImGuiStyleVar_WindowRounding, // float WindowRounding
@@ -1150,11 +1181,13 @@ enum ImGuiStyleVar_
ImGuiStyleVar_GrabRounding, // float GrabRounding
ImGuiStyleVar_TabRounding, // float TabRounding
ImGuiStyleVar_ButtonTextAlign, // ImVec2 ButtonTextAlign
+ ImGuiStyleVar_SelectableTextAlign, // ImVec2 SelectableTextAlign
ImGuiStyleVar_COUNT
// Obsolete names (will be removed)
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
- , ImGuiStyleVar_Count_ = ImGuiStyleVar_COUNT, ImGuiStyleVar_ChildWindowRounding = ImGuiStyleVar_ChildRounding
+ , ImGuiStyleVar_Count_ = ImGuiStyleVar_COUNT // [renamed in 1.60]
+ , ImGuiStyleVar_ChildWindowRounding = ImGuiStyleVar_ChildRounding // [renamed in 1.53]
#endif
};
@@ -1162,7 +1195,7 @@ enum ImGuiStyleVar_
enum ImGuiColorEditFlags_
{
ImGuiColorEditFlags_None = 0,
- ImGuiColorEditFlags_NoAlpha = 1 << 1, // // ColorEdit, ColorPicker, ColorButton: ignore Alpha component (read 3 components from the input pointer).
+ ImGuiColorEditFlags_NoAlpha = 1 << 1, // // ColorEdit, ColorPicker, ColorButton: ignore Alpha component (will only read 3 components from the input pointer).
ImGuiColorEditFlags_NoPicker = 1 << 2, // // ColorEdit: disable picker when clicking on colored square.
ImGuiColorEditFlags_NoOptions = 1 << 3, // // ColorEdit: disable toggling options menu when right-clicking on inputs/small preview.
ImGuiColorEditFlags_NoSmallPreview = 1 << 4, // // ColorEdit, ColorPicker: disable colored square preview next to the inputs. (e.g. to show only the inputs)
@@ -1172,24 +1205,35 @@ enum ImGuiColorEditFlags_
ImGuiColorEditFlags_NoSidePreview = 1 << 8, // // ColorPicker: disable bigger color preview on right side of the picker, use small colored square preview instead.
ImGuiColorEditFlags_NoDragDrop = 1 << 9, // // ColorEdit: disable drag and drop target. ColorButton: disable drag and drop source.
- // User Options (right-click on widget to change some of them). You can set application defaults using SetColorEditOptions(). The idea is that you probably don't want to override them in most of your calls, let the user choose and/or call SetColorEditOptions() during startup.
+ // User Options (right-click on widget to change some of them).
ImGuiColorEditFlags_AlphaBar = 1 << 16, // // ColorEdit, ColorPicker: show vertical alpha bar/gradient in picker.
ImGuiColorEditFlags_AlphaPreview = 1 << 17, // // ColorEdit, ColorPicker, ColorButton: display preview as a transparent color over a checkerboard, instead of opaque.
ImGuiColorEditFlags_AlphaPreviewHalf= 1 << 18, // // ColorEdit, ColorPicker, ColorButton: display half opaque / half checkerboard, instead of opaque.
ImGuiColorEditFlags_HDR = 1 << 19, // // (WIP) ColorEdit: Currently only disable 0.0f..1.0f limits in RGBA edition (note: you probably want to use ImGuiColorEditFlags_Float flag as well).
- ImGuiColorEditFlags_RGB = 1 << 20, // [Inputs] // ColorEdit: choose one among RGB/HSV/HEX. ColorPicker: choose any combination using RGB/HSV/HEX.
- ImGuiColorEditFlags_HSV = 1 << 21, // [Inputs] // "
- ImGuiColorEditFlags_HEX = 1 << 22, // [Inputs] // "
+ ImGuiColorEditFlags_DisplayRGB = 1 << 20, // [Display] // ColorEdit: override _display_ type among RGB/HSV/Hex. ColorPicker: select any combination using one or more of RGB/HSV/Hex.
+ ImGuiColorEditFlags_DisplayHSV = 1 << 21, // [Display] // "
+ ImGuiColorEditFlags_DisplayHex = 1 << 22, // [Display] // "
ImGuiColorEditFlags_Uint8 = 1 << 23, // [DataType] // ColorEdit, ColorPicker, ColorButton: _display_ values formatted as 0..255.
ImGuiColorEditFlags_Float = 1 << 24, // [DataType] // ColorEdit, ColorPicker, ColorButton: _display_ values formatted as 0.0f..1.0f floats instead of 0..255 integers. No round-trip of value via integers.
- ImGuiColorEditFlags_PickerHueBar = 1 << 25, // [PickerMode] // ColorPicker: bar for Hue, rectangle for Sat/Value.
- ImGuiColorEditFlags_PickerHueWheel = 1 << 26, // [PickerMode] // ColorPicker: wheel for Hue, triangle for Sat/Value.
+ ImGuiColorEditFlags_PickerHueBar = 1 << 25, // [Picker] // ColorPicker: bar for Hue, rectangle for Sat/Value.
+ ImGuiColorEditFlags_PickerHueWheel = 1 << 26, // [Picker] // ColorPicker: wheel for Hue, triangle for Sat/Value.
+ ImGuiColorEditFlags_InputRGB = 1 << 27, // [Input] // ColorEdit, ColorPicker: input and output data in RGB format.
+ ImGuiColorEditFlags_InputHSV = 1 << 28, // [Input] // ColorEdit, ColorPicker: input and output data in HSV format.
+
+ // Defaults Options. You can set application defaults using SetColorEditOptions(). The intent is that you probably don't want to
+ // override them in most of your calls. Let the user choose via the option menu and/or call SetColorEditOptions() once during startup.
+ ImGuiColorEditFlags__OptionsDefault = ImGuiColorEditFlags_Uint8|ImGuiColorEditFlags_DisplayRGB|ImGuiColorEditFlags_InputRGB|ImGuiColorEditFlags_PickerHueBar,
// [Internal] Masks
- ImGuiColorEditFlags__InputsMask = ImGuiColorEditFlags_RGB|ImGuiColorEditFlags_HSV|ImGuiColorEditFlags_HEX,
+ ImGuiColorEditFlags__DisplayMask = ImGuiColorEditFlags_DisplayRGB|ImGuiColorEditFlags_DisplayHSV|ImGuiColorEditFlags_DisplayHex,
ImGuiColorEditFlags__DataTypeMask = ImGuiColorEditFlags_Uint8|ImGuiColorEditFlags_Float,
ImGuiColorEditFlags__PickerMask = ImGuiColorEditFlags_PickerHueWheel|ImGuiColorEditFlags_PickerHueBar,
- ImGuiColorEditFlags__OptionsDefault = ImGuiColorEditFlags_Uint8|ImGuiColorEditFlags_RGB|ImGuiColorEditFlags_PickerHueBar // Change application default using SetColorEditOptions()
+ ImGuiColorEditFlags__InputMask = ImGuiColorEditFlags_InputRGB|ImGuiColorEditFlags_InputHSV
+
+ // Obsolete names (will be removed)
+#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
+ , ImGuiColorEditFlags_RGB = ImGuiColorEditFlags_DisplayRGB, ImGuiColorEditFlags_HSV = ImGuiColorEditFlags_DisplayHSV, ImGuiColorEditFlags_HEX = ImGuiColorEditFlags_DisplayHex // [renamed in 1.69]
+#endif
};
// Enumeration for GetMouseCursor()
@@ -1199,21 +1243,21 @@ enum ImGuiMouseCursor_
ImGuiMouseCursor_None = -1,
ImGuiMouseCursor_Arrow = 0,
ImGuiMouseCursor_TextInput, // When hovering over InputText, etc.
- ImGuiMouseCursor_ResizeAll, // (Unused by imgui functions)
+ ImGuiMouseCursor_ResizeAll, // (Unused by Dear ImGui functions)
ImGuiMouseCursor_ResizeNS, // When hovering over an horizontal border
ImGuiMouseCursor_ResizeEW, // When hovering over a vertical border or a column
ImGuiMouseCursor_ResizeNESW, // When hovering over the bottom-left corner of a window
ImGuiMouseCursor_ResizeNWSE, // When hovering over the bottom-right corner of a window
- ImGuiMouseCursor_Hand, // (Unused by imgui functions. Use for e.g. hyperlinks)
+ ImGuiMouseCursor_Hand, // (Unused by Dear ImGui functions. Use for e.g. hyperlinks)
ImGuiMouseCursor_COUNT
// Obsolete names (will be removed)
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
- , ImGuiMouseCursor_Count_ = ImGuiMouseCursor_COUNT
+ , ImGuiMouseCursor_Count_ = ImGuiMouseCursor_COUNT // [renamed in 1.60]
#endif
};
-// Enumateration for ImGui::SetWindow***(), SetNextWindow***(), SetNextTreeNode***() functions
+// Enumateration for ImGui::SetWindow***(), SetNextWindow***(), SetNextItem***() functions
// Represent a condition.
// Important: Treat as a regular enum! Do NOT combine multiple values using binary operators! All the functions above treat 0 as a shortcut to ImGuiCond_Always.
enum ImGuiCond_
@@ -1222,13 +1266,24 @@ enum ImGuiCond_
ImGuiCond_Once = 1 << 1, // Set the variable once per runtime session (only the first call with succeed)
ImGuiCond_FirstUseEver = 1 << 2, // Set the variable if the object/window has no persistently saved data (no entry in .ini file)
ImGuiCond_Appearing = 1 << 3 // Set the variable if the object/window is appearing after being hidden/inactive (or the first time)
-
- // Obsolete names (will be removed)
-#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
- , ImGuiSetCond_Always = ImGuiCond_Always, ImGuiSetCond_Once = ImGuiCond_Once, ImGuiSetCond_FirstUseEver = ImGuiCond_FirstUseEver, ImGuiSetCond_Appearing = ImGuiCond_Appearing
-#endif
};
+//-----------------------------------------------------------------------------
+// Helpers: Memory allocations macros
+// IM_MALLOC(), IM_FREE(), IM_NEW(), IM_PLACEMENT_NEW(), IM_DELETE()
+// We call C++ constructor on own allocated memory via the placement "new(ptr) Type()" syntax.
+// Defining a custom placement new() with a dummy parameter allows us to bypass including which on some platforms complains when user has disabled exceptions.
+//-----------------------------------------------------------------------------
+
+struct ImNewDummy {};
+inline void* operator new(size_t, ImNewDummy, void* ptr) { return ptr; }
+inline void operator delete(void*, ImNewDummy, void*) {} // This is only required so we can use the symmetrical new()
+#define IM_ALLOC(_SIZE) ImGui::MemAlloc(_SIZE)
+#define IM_FREE(_PTR) ImGui::MemFree(_PTR)
+#define IM_PLACEMENT_NEW(_PTR) new(ImNewDummy(), _PTR)
+#define IM_NEW(_TYPE) new(ImNewDummy(), ImGui::MemAlloc(sizeof(_TYPE))) _TYPE
+template void IM_DELETE(T* p) { if (p) { p->~T(); ImGui::MemFree(p); } }
+
//-----------------------------------------------------------------------------
// Helper: ImVector<>
// Lightweight std::vector<>-like class to avoid dragging dependencies (also, some implementations of STL with debug enabled are absurdly slow, we bypass it so our code runs fast in debug).
@@ -1254,7 +1309,7 @@ struct ImVector
inline ImVector() { Size = Capacity = 0; Data = NULL; }
inline ImVector(const ImVector& src) { Size = Capacity = 0; Data = NULL; operator=(src); }
inline ImVector& operator=(const ImVector& src) { clear(); resize(src.Size); memcpy(Data, src.Data, (size_t)Size * sizeof(T)); return *this; }
- inline ~ImVector() { if (Data) ImGui::MemFree(Data); }
+ inline ~ImVector() { if (Data) IM_FREE(Data); }
inline bool empty() const { return Size == 0; }
inline int size() const { return Size; }
@@ -1263,7 +1318,7 @@ struct ImVector
inline T& operator[](int i) { IM_ASSERT(i < Size); return Data[i]; }
inline const T& operator[](int i) const { IM_ASSERT(i < Size); return Data[i]; }
- inline void clear() { if (Data) { Size = Capacity = 0; ImGui::MemFree(Data); Data = NULL; } }
+ inline void clear() { if (Data) { Size = Capacity = 0; IM_FREE(Data); Data = NULL; } }
inline T* begin() { return Data; }
inline const T* begin() const { return Data; }
inline T* end() { return Data + Size; }
@@ -1277,7 +1332,7 @@ struct ImVector
inline int _grow_capacity(int sz) const { int new_capacity = Capacity ? (Capacity + Capacity/2) : 8; return new_capacity > sz ? new_capacity : sz; }
inline void resize(int new_size) { if (new_size > Capacity) reserve(_grow_capacity(new_size)); Size = new_size; }
inline void resize(int new_size, const T& v) { if (new_size > Capacity) reserve(_grow_capacity(new_size)); if (new_size > Size) for (int n = Size; n < new_size; n++) memcpy(&Data[n], &v, sizeof(v)); Size = new_size; }
- inline void reserve(int new_capacity) { if (new_capacity <= Capacity) return; T* new_data = (T*)ImGui::MemAlloc((size_t)new_capacity * sizeof(T)); if (Data) { memcpy(new_data, Data, (size_t)Size * sizeof(T)); ImGui::MemFree(Data); } Data = new_data; Capacity = new_capacity; }
+ inline void reserve(int new_capacity) { if (new_capacity <= Capacity) return; T* new_data = (T*)IM_ALLOC((size_t)new_capacity * sizeof(T)); if (Data) { memcpy(new_data, Data, (size_t)Size * sizeof(T)); IM_FREE(Data); } Data = new_data; Capacity = new_capacity; }
// NB: It is illegal to call push_back/push_front/insert with a reference pointing inside the ImVector data itself! e.g. v.push_back(v[10]) is forbidden.
inline void push_back(const T& v) { if (Size == Capacity) reserve(_grow_capacity(Size + 1)); memcpy(&Data[Size], &v, sizeof(v)); Size++; }
@@ -1300,12 +1355,13 @@ struct ImVector
struct ImGuiStyle
{
- float Alpha; // Global alpha applies to everything in ImGui.
+ float Alpha; // Global alpha applies to everything in Dear ImGui.
ImVec2 WindowPadding; // Padding within a window.
float WindowRounding; // Radius of window corners rounding. Set to 0.0f to have rectangular windows.
float WindowBorderSize; // Thickness of border around windows. Generally set to 0.0f or 1.0f. (Other values are not well tested and more CPU/GPU costly).
ImVec2 WindowMinSize; // Minimum window size. This is a global setting. If you want to constraint individual windows, use SetNextWindowSizeConstraints().
ImVec2 WindowTitleAlign; // Alignment for title bar text. Defaults to (0.0f,0.5f) for left-aligned,vertically centered.
+ ImGuiDir WindowMenuButtonPosition; // Side of the collapsing/docking button in the title bar (left/right). Defaults to ImGuiDir_Left.
float ChildRounding; // Radius of child window corners rounding. Set to 0.0f to have rectangular windows.
float ChildBorderSize; // Thickness of border around child windows. Generally set to 0.0f or 1.0f. (Other values are not well tested and more CPU/GPU costly).
float PopupRounding; // Radius of popup window corners rounding. (Note that tooltip windows use WindowRounding)
@@ -1317,14 +1373,16 @@ struct ImGuiStyle
ImVec2 ItemInnerSpacing; // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label).
ImVec2 TouchExtraPadding; // 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!
float IndentSpacing; // Horizontal indentation when e.g. entering a tree node. Generally == (FontSize + FramePadding.x*2).
- float ColumnsMinSpacing; // Minimum horizontal spacing between two columns.
+ float ColumnsMinSpacing; // Minimum horizontal spacing between two columns. Preferably > (FramePadding.x + 1).
float ScrollbarSize; // Width of the vertical scrollbar, Height of the horizontal scrollbar.
float ScrollbarRounding; // Radius of grab corners for scrollbar.
float GrabMinSize; // Minimum width/height of a grab box for slider/scrollbar.
float GrabRounding; // Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs.
float TabRounding; // Radius of upper corners of a tab. Set to 0.0f to have rectangular tabs.
float TabBorderSize; // Thickness of border around tabs.
- ImVec2 ButtonTextAlign; // Alignment of button text when button is larger than text. Defaults to (0.5f,0.5f) for horizontally+vertically centered.
+ ImGuiDir ColorButtonPosition; // Side of the color button in the ColorEdit4 widget (left/right). Defaults to ImGuiDir_Right.
+ ImVec2 ButtonTextAlign; // Alignment of button text when button is larger than text. Defaults to (0.5f, 0.5f) (centered).
+ ImVec2 SelectableTextAlign; // Alignment of selectable text when selectable is larger than text. Defaults to (0.0f, 0.0f) (top-left aligned).
ImVec2 DisplayWindowPadding; // Window position are clamped to be visible within the display area or monitors by at least this amount. Only applies to regular windows.
ImVec2 DisplaySafeAreaPadding; // If you cannot see the edges of your screen (e.g. on a TV) increase the safe area padding. Apply to popups/tooltips as well regular windows. NB: Prefer configuring your TV sets correctly!
float MouseCursorScale; // Scale software rendered mouse cursor (when io.MouseDrawCursor is enabled). May be removed later.
@@ -1351,7 +1409,7 @@ struct ImGuiIO
ImGuiConfigFlags ConfigFlags; // = 0 // See ImGuiConfigFlags_ enum. Set by user/application. Gamepad/keyboard navigation options, etc.
ImGuiBackendFlags BackendFlags; // = 0 // See ImGuiBackendFlags_ enum. Set by back-end (imgui_impl_xxx files or custom back-end) to communicate features supported by the back-end.
- ImVec2 DisplaySize; // // Main display size, in pixels. Used e.g. to clamp windows positions. This is for the default viewport. Use BeginViewport() for other viewports.
+ ImVec2 DisplaySize; // // Main display size, in pixels. This is for the default viewport. Use BeginViewport() for other viewports.
float DeltaTime; // = 1.0f/60.0f // Time elapsed since last frame, in seconds.
float IniSavingRate; // = 5.0f // Minimum time between saving positions/sizes to .ini file, in seconds.
const char* IniFilename; // = "imgui.ini" // Path to .ini file. Set NULL to disable automatic .ini loading/saving, if e.g. you want to manually load/save from memory.
@@ -1364,30 +1422,31 @@ struct ImGuiIO
float KeyRepeatRate; // = 0.050f // When holding a key/button, rate at which it repeats, in seconds.
void* UserData; // = NULL // Store your own data for retrieval by callbacks.
- ImFontAtlas*Fonts; // // Load, rasterize and pack one or more fonts into a single texture.
+ ImFontAtlas*Fonts; // // Font atlas: load, rasterize and pack one or more fonts into a single texture.
float FontGlobalScale; // = 1.0f // Global scale all fonts
bool FontAllowUserScaling; // = false // Allow user scaling text of individual window with CTRL+Wheel.
ImFont* FontDefault; // = NULL // Font to use on NewFrame(). Use NULL to uses Fonts->Fonts[0].
- ImVec2 DisplayFramebufferScale; // = (1.0f,1.0f) // For hi-dpi/retina display or other situations where window coordinates are different from framebuffer coordinates. User storage only, presently not used by ImGui.
+ ImVec2 DisplayFramebufferScale; // = (1, 1) // For retina display or other situations where window coordinates are different from framebuffer coordinates. This generally ends up in ImDrawData::FramebufferScale.
// Docking options (when ImGuiConfigFlags_DockingEnable is set)
bool ConfigDockingNoSplit; // = false // Simplified docking mode: disable window splitting, so docking is limited to merging multiple windows together into tab-bars.
bool ConfigDockingWithShift; // = false // Enable docking with holding Shift key (reduce visual noise, allows dropping in wider space)
- bool ConfigDockingTabBarOnSingleWindows; // = false // [BETA] Make every single floating window display within a docking node.
+ bool ConfigDockingAlwaysTabBar; // = false // [BETA] [FIXME: This currently creates regression with auto-sizing and general overhead] Make every single floating window display within a docking node.
bool ConfigDockingTransparentPayload;// = false // [BETA] Make window or viewport transparent when docking and only display docking boxes on the target viewport. Useful if rendering of multiple viewport cannot be synced. Best used with ConfigViewportsNoAutoMerge.
// Viewport options (when ImGuiConfigFlags_ViewportsEnable is set)
- bool ConfigViewportsNoAutoMerge; // = false; // Set to make all floating imgui windows always create their own viewport. Otherwise, they are merged into the main host viewports when overlapping it.
+ bool ConfigViewportsNoAutoMerge; // = false; // Set to make all floating imgui windows always create their own viewport. Otherwise, they are merged into the main host viewports when overlapping it. May also set ImGuiViewportFlags_NoAutoMerge on individual viewport.
bool ConfigViewportsNoTaskBarIcon; // = false // Disable default OS task bar icon flag for secondary viewports. When a viewport doesn't want a task bar icon, ImGuiViewportFlags_NoTaskBarIcon will be set on it.
bool ConfigViewportsNoDecoration; // = true // [BETA] Disable default OS window decoration flag for secondary viewports. When a viewport doesn't want window decorations, ImGuiViewportFlags_NoDecoration will be set on it. Enabling decoration can create subsequent issues at OS levels (e.g. minimum window size).
- bool ConfigViewportsNoParent; // = false // Disable default OS parenting to main viewport for secondary viewports. By default, viewports are marked with ParentViewportId = , expecting the platform back-end to setup a parent/child relationship between the OS windows (some back-end may ignore this). Set to true if you want the default to be 0, then all viewports will be top-level OS windows.
+ bool ConfigViewportsNoDefaultParent; // = false // Disable default OS parenting to main viewport for secondary viewports. By default, viewports are marked with ParentViewportId = , expecting the platform back-end to setup a parent/child relationship between the OS windows (some back-end may ignore this). Set to true if you want the default to be 0, then all viewports will be top-level OS windows.
// Miscellaneous options
bool MouseDrawCursor; // = false // Request ImGui to draw a mouse cursor for you (if you are on a platform without a mouse cursor). Cannot be easily renamed to 'io.ConfigXXX' because this is frequently used by back-end implementations.
bool ConfigMacOSXBehaviors; // = defined(__APPLE__) // OS X style: Text editing cursor movement using Alt instead of Ctrl, Shortcuts using Cmd/Super instead of Ctrl, Line/Text Start and End using Cmd+Arrows instead of Home/End, Double click selects by word instead of selecting whole text, Multi-selection in lists uses Cmd/Super instead of Ctrl (was called io.OptMacOSXBehaviors prior to 1.63)
bool ConfigInputTextCursorBlink; // = true // Set to false to disable blinking cursor, for users who consider it distracting. (was called: io.OptCursorBlink prior to 1.63)
- bool ConfigWindowsResizeFromEdges; // = true // Enable resizing of windows from their edges and from the lower-left corner. This requires (io.BackendFlags & ImGuiBackendFlags_HasMouseCursors) because it needs mouse cursor feedback. (This used to be the a per-window ImGuiWindowFlags_ResizeFromAnySide flag)
+ bool ConfigWindowsResizeFromEdges; // = true // Enable resizing of windows from their edges and from the lower-left corner. This requires (io.BackendFlags & ImGuiBackendFlags_HasMouseCursors) because it needs mouse cursor feedback. (This used to be a per-window ImGuiWindowFlags_ResizeFromAnySide flag)
bool ConfigWindowsMoveFromTitleBarOnly; // = false // [BETA] Set to true to only allow moving windows when clicked+dragged from the title bar. Windows without a title bar are not affected.
+ float ConfigWindowsMemoryCompactTimer;// = 60.0f // [BETA] Compact window memory usage when unused. Set to -1.0f to disable.
//------------------------------------------------------------------
// Platform Functions
@@ -1433,7 +1492,7 @@ struct ImGuiIO
float NavInputs[ImGuiNavInput_COUNT]; // Gamepad inputs. Cleared back to zero by EndFrame(). Keyboard keys will be auto-mapped and be written here by NewFrame().
// Functions
- IMGUI_API void AddInputCharacter(ImWchar c); // Queue new character input
+ IMGUI_API void AddInputCharacter(unsigned int c); // Queue new character input
IMGUI_API void AddInputCharactersUTF8(const char* str); // Queue new characters input from an UTF-8 string
IMGUI_API void ClearInputCharacters(); // Clear the text input buffer manually
@@ -1466,7 +1525,8 @@ struct ImGuiIO
bool MouseClicked[5]; // Mouse button went from !Down to Down
bool MouseDoubleClicked[5]; // Has mouse button been double-clicked?
bool MouseReleased[5]; // Mouse button went from Down to !Down
- bool MouseDownOwned[5]; // Track if button was clicked inside a window. We don't request mouse capture from the application if click started outside ImGui bounds.
+ bool MouseDownOwned[5]; // Track if button was clicked inside a dear imgui window. We don't request mouse capture from the application if click started outside ImGui bounds.
+ bool MouseDownWasDoubleClick[5]; // Track if button down was a double-click
float MouseDownDuration[5]; // Duration the mouse button has been down (0.0f == just clicked)
float MouseDownDurationPrev[5]; // Previous time the mouse button has been down
ImVec2 MouseDragMaxDistanceAbs[5]; // Maximum distance, absolute, on each axis, of how much mouse has traveled from the clicking point
@@ -1529,6 +1589,20 @@ struct ImGuiSizeCallbackData
ImVec2 DesiredSize; // Read-write. Desired size, based on user's mouse position. Write to this field to restrain resizing.
};
+// [BETA] Rarely used / very advanced uses only. Use with SetNextWindowClass() and DockSpace() functions.
+// Provide hints to the platform back-end via altered viewport flags (enable/disable OS decoration, OS task bar icons, etc.) and OS level parent/child relationships.
+struct ImGuiWindowClass
+{
+ ImGuiID ClassId; // User data. 0 = Default class (unclassed)
+ ImGuiID ParentViewportId; // Hint for the platform back-end. If non-zero, the platform back-end can create a parent<>child relationship between the platform windows. Not conforming back-ends are free to e.g. parent every viewport to the main viewport or not.
+ ImGuiViewportFlags ViewportFlagsOverrideSet; // Viewport flags to set when a window of this class owns a viewport. This allows you to enforce OS decoration or task bar icon, override the defaults on a per-window basis.
+ ImGuiViewportFlags ViewportFlagsOverrideClear; // Viewport flags to clear when a window of this class owns a viewport. This allows you to enforce OS decoration or task bar icon, override the defaults on a per-window basis.
+ bool DockingAlwaysTabBar; // Set to true to enforce windows of this class always having their own tab (equivalent of setting the global io.ConfigDockingAlwaysTabBar)
+ bool DockingAllowUnclassed; // Set to true to allow windows of this class to be docked/merged with an unclassed window.
+
+ ImGuiWindowClass() { ClassId = 0; ParentViewportId = 0; ViewportFlagsOverrideSet = ViewportFlagsOverrideClear = 0x00; DockingAlwaysTabBar = false; DockingAllowUnclassed = true; }
+};
+
// Data payload for Drag and Drop operations: AcceptDragDropPayload(), GetDragDropPayload()
struct ImGuiPayload
{
@@ -1551,19 +1625,6 @@ struct ImGuiPayload
bool IsDelivery() const { return Delivery; }
};
-// [BETA] Rarely used / very advanced uses only. Use with SetNextWindowClass() and DockSpace() functions.
-// Provide hints to the platform back-end via altered viewport flags (enable/disable OS decoration, OS task bar icons, etc.) and OS level parent/child relationships.
-struct ImGuiWindowClass
-{
- ImGuiID ClassId; // User data. 0 = Default class (unclassed)
- ImGuiID ParentViewportId; // Hint for the platform back-end. If non-zero, the platform back-end can create a parent<>child relationship between the platform windows. Not conforming back-ends are free to e.g. parent every viewport to the main viewport or not.
- ImGuiViewportFlags ViewportFlagsOverrideMask; // Viewport flags to override when a window of this class owns a viewport. This allows you to enforce OS decoration or task bar icon, override the defaults on a per-window basis.
- ImGuiViewportFlags ViewportFlagsOverrideValue; // Viewport flags values to override when a window of this class owns a viewport.
- bool DockingAllowUnclassed; // true = can be docked/merged with an unclassed window
-
- ImGuiWindowClass() { ClassId = 0; ParentViewportId = 0; ViewportFlagsOverrideMask = ViewportFlagsOverrideValue = 0x00; DockingAllowUnclassed = true; }
-};
-
//-----------------------------------------------------------------------------
// Obsolete functions (Will be removed! Read 'API BREAKING CHANGES' section in imgui.cpp for details)
// Please keep your copy of dear imgui up to date! Occasionally set '#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS' in imconfig.h to stay ahead.
@@ -1572,6 +1633,14 @@ struct ImGuiWindowClass
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
namespace ImGui
{
+ // OBSOLETED in 1.72 (from July 2019)
+ static inline void TreeAdvanceToLabelPos() { SetCursorPosX(GetCursorPosX() + GetTreeNodeToLabelSpacing()); }
+ // OBSOLETED in 1.71 (from June 2019)
+ static inline void SetNextTreeNodeOpen(bool open, ImGuiCond cond = 0) { SetNextItemOpen(open, cond); }
+ // OBSOLETED in 1.70 (from May 2019)
+ static inline float GetContentRegionAvailWidth() { return GetContentRegionAvail().x; }
+ // OBSOLETED in 1.69 (from Mar 2019)
+ static inline ImDrawList* GetOverlayDrawList() { return GetForegroundDrawList(); }
// OBSOLETED in 1.66 (from Sep 2018)
static inline void SetScrollHere(float center_ratio=0.5f){ SetScrollHereY(center_ratio); }
// OBSOLETED in 1.63 (between Aug 2018 and Sept 2018)
@@ -1596,13 +1665,8 @@ namespace ImGui
static inline bool IsRootWindowOrAnyChildHovered() { return IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows); }
static inline void AlignFirstTextHeightToWidgets() { AlignTextToFramePadding(); }
void SetNextWindowPosCenter(ImGuiCond cond);
- // OBSOLETED in 1.51 (between Jun 2017 and Aug 2017)
- static inline bool IsItemHoveredRect() { return IsItemHovered(ImGuiHoveredFlags_RectOnly); }
- static inline bool IsPosHoveringAnyWindow(const ImVec2&) { IM_ASSERT(0); return false; } // This was misleading and partly broken. You probably want to use the ImGui::GetIO().WantCaptureMouse flag instead.
- static inline bool IsMouseHoveringAnyWindow() { return IsWindowHovered(ImGuiHoveredFlags_AnyWindow); }
- static inline bool IsMouseHoveringWindow() { return IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem); }
}
-typedef ImGuiInputTextCallback ImGuiTextEditCallback; // OBSOLETE in 1.63 (from Aug 2018): made the names consistent
+typedef ImGuiInputTextCallback ImGuiTextEditCallback; // OBSOLETED in 1.63 (from Aug 2018): made the names consistent
typedef ImGuiInputTextCallbackData ImGuiTextEditCallbackData;
#endif
@@ -1610,16 +1674,6 @@ typedef ImGuiInputTextCallbackData ImGuiTextEditCallbackData;
// Helpers
//-----------------------------------------------------------------------------
-// Helper: IM_NEW(), IM_PLACEMENT_NEW(), IM_DELETE() macros to call MemAlloc + Placement New, Placement Delete + MemFree
-// We call C++ constructor on own allocated memory via the placement "new(ptr) Type()" syntax.
-// Defining a custom placement new() with a dummy parameter allows us to bypass including which on some platforms complains when user has disabled exceptions.
-struct ImNewDummy {};
-inline void* operator new(size_t, ImNewDummy, void* ptr) { return ptr; }
-inline void operator delete(void*, ImNewDummy, void*) {} // This is only required so we can use the symetrical new()
-#define IM_PLACEMENT_NEW(_PTR) new(ImNewDummy(), _PTR)
-#define IM_NEW(_TYPE) new(ImNewDummy(), ImGui::MemAlloc(sizeof(_TYPE))) _TYPE
-template void IM_DELETE(T* p) { if (p) { p->~T(); ImGui::MemFree(p); } }
-
// Helper: Execute a block of code at maximum once a frame. Convenient if you want to quickly create an UI within deep-nested code that runs multiple times every frame.
// Usage: static ImGuiOnceUponAFrame oaf; if (oaf) ImGui::Text("This will be called only once per frame");
struct ImGuiOnceUponAFrame
@@ -1629,11 +1683,6 @@ struct ImGuiOnceUponAFrame
operator bool() const { int current_frame = ImGui::GetFrameCount(); if (RefFrame == current_frame) return false; RefFrame = current_frame; return true; }
};
-// Helper: Macro for ImGuiOnceUponAFrame. Attention: The macro expands into 2 statement so make sure you don't use it within e.g. an if() statement without curly braces.
-#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
-#define IMGUI_ONCE_UPON_A_FRAME static ImGuiOnceUponAFrame imgui_oaf; if (imgui_oaf) // OBSOLETED in 1.51, will remove!
-#endif
-
// Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
struct ImGuiTextFilter
{
@@ -1645,21 +1694,19 @@ struct ImGuiTextFilter
bool IsActive() const { return !Filters.empty(); }
// [Internal]
- struct TextRange
+ struct ImGuiTextRange
{
- const char* b;
- const char* e;
-
- TextRange() { b = e = NULL; }
- TextRange(const char* _b, const char* _e) { b = _b; e = _e; }
- const char* begin() const { return b; }
- const char* end () const { return e; }
- bool empty() const { return b == e; }
- IMGUI_API void split(char separator, ImVector* out) const;
+ const char* b;
+ const char* e;
+
+ ImGuiTextRange() { b = e = NULL; }
+ ImGuiTextRange(const char* _b, const char* _e) { b = _b; e = _e; }
+ bool empty() const { return b == e; }
+ IMGUI_API void split(char separator, ImVector* out) const;
};
- char InputBuf[256];
- ImVector Filters;
- int CountGrep;
+ char InputBuf[256];
+ ImVectorFilters;
+ int CountGrep;
};
// Helper: Growable text buffer for logging/accumulating text
@@ -1667,13 +1714,13 @@ struct ImGuiTextFilter
struct ImGuiTextBuffer
{
ImVector Buf;
- static char EmptyString[1];
+ IMGUI_API static char EmptyString[1];
ImGuiTextBuffer() { }
inline char operator[](int i) { IM_ASSERT(Buf.Data != NULL); return Buf.Data[i]; }
const char* begin() const { return Buf.Data ? &Buf.front() : EmptyString; }
const char* end() const { return Buf.Data ? &Buf.back() : EmptyString; } // Buf is zero-terminated, so end() will point on the zero-terminator
- int size() const { return Buf.Data ? Buf.Size - 1 : 0; }
+ int size() const { return Buf.Size ? Buf.Size - 1 : 0; }
bool empty() { return Buf.Size <= 1; }
void clear() { Buf.clear(); }
void reserve(int capacity) { Buf.reserve(capacity); }
@@ -1693,15 +1740,17 @@ struct ImGuiTextBuffer
// Types are NOT stored, so it is up to you to make sure your Key don't collide with different types.
struct ImGuiStorage
{
- struct Pair
+ // [Internal]
+ struct ImGuiStoragePair
{
ImGuiID key;
union { int val_i; float val_f; void* val_p; };
- Pair(ImGuiID _key, int _val_i) { key = _key; val_i = _val_i; }
- Pair(ImGuiID _key, float _val_f) { key = _key; val_f = _val_f; }
- Pair(ImGuiID _key, void* _val_p) { key = _key; val_p = _val_p; }
+ ImGuiStoragePair(ImGuiID _key, int _val_i) { key = _key; val_i = _val_i; }
+ ImGuiStoragePair(ImGuiID _key, float _val_f) { key = _key; val_f = _val_f; }
+ ImGuiStoragePair(ImGuiID _key, void* _val_p) { key = _key; val_p = _val_p; }
};
- ImVector Data;
+
+ ImVector Data;
// - Get***() functions find pair, never add/allocate. Pairs are sorted so a query is O(log N)
// - Set***() functions find pair, insertion on demand if missing.
@@ -1781,7 +1830,7 @@ struct ImGuiListClipper
#define IM_COL32_BLACK IM_COL32(0,0,0,255) // Opaque black
#define IM_COL32_BLACK_TRANS IM_COL32(0,0,0,0) // Transparent black = 0x00000000
-// Helper: ImColor() implicity converts colors to either ImU32 (packed 4x1 byte) or ImVec4 (4x1 float)
+// Helper: ImColor() implicitly 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. MAY OBSOLETE.
// **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. Explicitly cast to ImU32 or ImVec4 if needed.
@@ -1803,30 +1852,46 @@ struct ImColor
};
//-----------------------------------------------------------------------------
-// Draw List API (ImDrawCmd, ImDrawIdx, ImDrawVert, ImDrawChannel, ImDrawListFlags, ImDrawList, ImDrawData)
+// Draw List API (ImDrawCmd, ImDrawIdx, ImDrawVert, ImDrawChannel, ImDrawListSplitter, ImDrawListFlags, ImDrawList, ImDrawData)
// Hold a series of drawing commands. The user provides a renderer for ImDrawData which essentially contains an array of ImDrawList.
//-----------------------------------------------------------------------------
// Draw callbacks for advanced uses.
// 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 to: A) Change your GPU render state,
-// B) render a complex 3D scene inside a UI element without an intermediate texture/render target, etc.
+// you can poke into the draw list for that! Draw callback may be useful for example to:
+// 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() }'
+// If you want to override the signature of ImDrawCallback, you can simply use e.g. '#define ImDrawCallback MyDrawCallback' (in imconfig.h) + update rendering back-end accordingly.
+#ifndef ImDrawCallback
typedef void (*ImDrawCallback)(const ImDrawList* parent_list, const ImDrawCmd* cmd);
+#endif
+
+// Special Draw callback value to request renderer back-end to reset the graphics/render state.
+// The renderer back-end needs to handle this special value, otherwise it will crash trying to call a function at this address.
+// This is useful for example if you submitted callbacks which you know have altered the render state and you want it to be restored.
+// It is not done by default because they are many perfectly useful way of altering render state for imgui contents (e.g. changing shader/blending settings before an Image call).
+#define ImDrawCallback_ResetRenderState (ImDrawCallback)(-1)
// Typically, 1 command = 1 GPU draw call (unless command is a callback)
+// Pre 1.71 back-ends will typically ignore the VtxOffset/IdxOffset fields. When 'io.BackendFlags & ImGuiBackendFlags_RendererHasVtxOffset'
+// is enabled, those fields allow us to render meshes larger than 64K vertices while keeping 16-bits indices.
struct ImDrawCmd
{
unsigned int ElemCount; // Number of indices (multiple of 3) to be rendered as triangles. Vertices are stored in the callee ImDrawList's vtx_buffer[] array, indices in idx_buffer[].
ImVec4 ClipRect; // Clipping rectangle (x1, y1, x2, y2). Subtract ImDrawData->DisplayPos to get clipping rectangle in "viewport" coordinates
ImTextureID TextureId; // User-provided texture ID. Set by user in ImfontAtlas::SetTexID() for fonts or passed to Image*() functions. Ignore if never using images or multiple fonts atlas.
+ unsigned int VtxOffset; // Start offset in vertex buffer. Pre-1.71 or without ImGuiBackendFlags_RendererHasVtxOffset: always 0. With ImGuiBackendFlags_RendererHasVtxOffset: may be >0 to support meshes larger than 64K vertices with 16-bits indices.
+ unsigned int IdxOffset; // Start offset in index buffer. Always equal to sum of ElemCount drawn so far.
ImDrawCallback UserCallback; // If != NULL, call the function instead of rendering the vertices. clip_rect and texture_id will be set normally.
void* UserCallbackData; // The draw callback code can access this.
- ImDrawCmd() { ElemCount = 0; ClipRect.x = ClipRect.y = ClipRect.z = ClipRect.w = 0.0f; TextureId = (ImTextureID)NULL; UserCallback = NULL; UserCallbackData = NULL; }
+ ImDrawCmd() { ElemCount = 0; TextureId = (ImTextureID)NULL; VtxOffset = IdxOffset = 0; UserCallback = NULL; UserCallbackData = NULL; }
};
-// Vertex index (override with '#define ImDrawIdx unsigned int' in imconfig.h)
+// Vertex index
+// (to allow large meshes with 16-bits indices: set 'io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset' and handle ImDrawCmd::VtxOffset in the renderer back-end)
+// (to use 32-bits indices: override with '#define ImDrawIdx unsigned int' in imconfig.h)
#ifndef ImDrawIdx
typedef unsigned short ImDrawIdx;
#endif
@@ -1842,21 +1907,38 @@ struct ImDrawVert
#else
// You can override the vertex format layout by defining IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT in imconfig.h
// The code expect ImVec2 pos (8 bytes), ImVec2 uv (8 bytes), ImU32 col (4 bytes), but you can re-order them or add other fields as needed to simplify integration in your engine.
-// The type has to be described within the macro (you can either declare the struct or use a typedef)
+// The type has to be described within the macro (you can either declare the struct or use a typedef). This is because ImVec2/ImU32 are likely not declared a the time you'd want to set your type up.
// NOTE: IMGUI DOESN'T CLEAR THE STRUCTURE AND DOESN'T CALL A CONSTRUCTOR SO ANY CUSTOM FIELD WILL BE UNINITIALIZED. IF YOU ADD EXTRA FIELDS (SUCH AS A 'Z' COORDINATES) YOU WILL NEED TO CLEAR THEM DURING RENDER OR TO IGNORE THEM.
IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT;
#endif
-// Draw channels are used by the Columns API to "split" the render list into different channels while building, so items of each column can be batched together.
-// You can also use them to simulate drawing layers and submit primitives in a different order than how they will be rendered.
+// For use by ImDrawListSplitter.
struct ImDrawChannel
{
- ImVector CmdBuffer;
- ImVector IdxBuffer;
+ ImVector _CmdBuffer;
+ ImVector _IdxBuffer;
+};
+
+// Split/Merge functions are used to split the draw list into different layers which can be drawn into out of order.
+// This is used by the Columns api, so items of each column can be batched together in a same draw call.
+struct ImDrawListSplitter
+{
+ int _Current; // Current channel number (0)
+ int _Count; // Number of active channels (1+)
+ ImVector _Channels; // Draw channels (not resized down so _Count might be < Channels.Size)
+
+ inline ImDrawListSplitter() { Clear(); }
+ inline ~ImDrawListSplitter() { ClearFreeMemory(); }
+ inline void Clear() { _Current = 0; _Count = 1; } // Do not clear Channels[] so our allocations are reused next frame
+ IMGUI_API void ClearFreeMemory();
+ IMGUI_API void Split(ImDrawList* draw_list, int count);
+ IMGUI_API void Merge(ImDrawList* draw_list);
+ IMGUI_API void SetCurrentChannel(ImDrawList* draw_list, int channel_idx);
};
enum ImDrawCornerFlags_
{
+ ImDrawCornerFlags_None = 0,
ImDrawCornerFlags_TopLeft = 1 << 0, // 0x1
ImDrawCornerFlags_TopRight = 1 << 1, // 0x2
ImDrawCornerFlags_BotLeft = 1 << 2, // 0x4
@@ -1872,12 +1954,15 @@ enum ImDrawListFlags_
{
ImDrawListFlags_None = 0,
ImDrawListFlags_AntiAliasedLines = 1 << 0, // Lines are anti-aliased (*2 the number of triangles for 1.0f wide line, otherwise *3 the number of triangles)
- ImDrawListFlags_AntiAliasedFill = 1 << 1 // Filled shapes have anti-aliased edges (*2 the number of vertices)
+ ImDrawListFlags_AntiAliasedFill = 1 << 1, // Filled shapes have anti-aliased edges (*2 the number of vertices)
+ ImDrawListFlags_AllowVtxOffset = 1 << 2 // Can emit 'VtxOffset > 0' to allow large meshes. Set when 'ImGuiBackendFlags_RendererHasVtxOffset' is enabled.
};
// Draw command list
-// This is the low-level list of polygons that ImGui functions are filling. At the end of the frame, all command lists are passed to your ImGuiIO::RenderDrawListFn function for rendering.
-// Each ImGui window contains its own ImDrawList. You can use ImGui::GetWindowDrawList() to access the current window draw list and draw custom primitives.
+// This is the low-level list of polygons that ImGui:: functions are filling. At the end of the frame,
+// all command lists are passed to your ImGuiIO::RenderDrawListFn function for rendering.
+// Each dear imgui window contains its own ImDrawList. You can use ImGui::GetWindowDrawList() to
+// access the current window draw list and draw custom primitives.
// You can interleave normal ImGui:: calls and adding primitives to the current draw list.
// All positions are generally in pixel coordinates (generally top-left at 0,0, bottom-right at io.DisplaySize, unless multiple viewports are used), but you are totally free to apply whatever transformation matrix to want to the data (if you apply such transformation you'll want to apply it to ClipRect as well)
// Important: Primitives are always added to the list and not culled (culling is done at higher-level by ImGui:: functions), if you use this API a lot consider coarse culling your drawn objects.
@@ -1892,15 +1977,14 @@ struct ImDrawList
// [Internal, used while building lists]
const ImDrawListSharedData* _Data; // Pointer to shared draw data (you can use ImGui::GetDrawListSharedData() to get the one from current ImGui context)
const char* _OwnerName; // Pointer to owner window's name for debugging
- unsigned int _VtxCurrentIdx; // [Internal] == VtxBuffer.Size
+ unsigned int _VtxCurrentOffset; // [Internal] Always 0 unless 'Flags & ImDrawListFlags_AllowVtxOffset'.
+ unsigned int _VtxCurrentIdx; // [Internal] Generally == VtxBuffer.Size unless we are past 64K vertices, in which case this gets reset to 0.
ImDrawVert* _VtxWritePtr; // [Internal] point within VtxBuffer.Data after each add command (to avoid using the ImVector<> operators too much)
ImDrawIdx* _IdxWritePtr; // [Internal] point within IdxBuffer.Data after each add command (to avoid using the ImVector<> operators too much)
ImVector _ClipRectStack; // [Internal]
ImVector _TextureIdStack; // [Internal]
ImVector _Path; // [Internal] current path building
- int _ChannelsCurrent; // [Internal] current channel number (0)
- int _ChannelsCount; // [Internal] number of active channels (1+)
- ImVector _Channels; // [Internal] draw channels for columns API (not resized down so _ChannelsCount may be smaller than _Channels.Size)
+ ImDrawListSplitter _Splitter; // [Internal] for channels api
// If you want to create ImDrawList instances, pass them ImGui::GetDrawListSharedData() or create and use your own ImDrawListSharedData (so you can use ImDrawList without ImGui)
ImDrawList(const ImDrawListSharedData* shared_data) { _Data = shared_data; _OwnerName = NULL; Clear(); }
@@ -1914,48 +1998,54 @@ struct ImDrawList
inline ImVec2 GetClipRectMax() const { const ImVec4& cr = _ClipRectStack.back(); return ImVec2(cr.z, cr.w); }
// Primitives
- IMGUI_API void AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness = 1.0f);
- IMGUI_API void AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners_flags = ImDrawCornerFlags_All, float thickness = 1.0f); // a: upper-left, b: lower-right, rounding_corners_flags: 4-bits corresponding to which corner to round
- IMGUI_API void AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners_flags = ImDrawCornerFlags_All); // a: upper-left, b: lower-right
- IMGUI_API void AddRectFilledMultiColor(const ImVec2& a, const ImVec2& b, ImU32 col_upr_left, ImU32 col_upr_right, ImU32 col_bot_right, ImU32 col_bot_left);
- IMGUI_API void AddQuad(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& d, ImU32 col, float thickness = 1.0f);
- IMGUI_API void AddQuadFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& d, ImU32 col);
- IMGUI_API void AddTriangle(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col, float thickness = 1.0f);
- IMGUI_API void AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col);
- IMGUI_API void AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12, float thickness = 1.0f);
- IMGUI_API void AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12);
+ // - For rectangular primitives, "p_min" and "p_max" represent the upper-left and lower-right corners.
+ IMGUI_API void AddLine(const ImVec2& p1, const ImVec2& p2, ImU32 col, float thickness = 1.0f);
+ IMGUI_API void AddRect(const ImVec2& p_min, const ImVec2& p_max, ImU32 col, float rounding = 0.0f, ImDrawCornerFlags rounding_corners = ImDrawCornerFlags_All, float thickness = 1.0f); // a: upper-left, b: lower-right (== upper-left + size), rounding_corners_flags: 4-bits corresponding to which corner to round
+ IMGUI_API void AddRectFilled(const ImVec2& p_min, const ImVec2& p_max, ImU32 col, float rounding = 0.0f, ImDrawCornerFlags rounding_corners = ImDrawCornerFlags_All); // a: upper-left, b: lower-right (== upper-left + size)
+ IMGUI_API void AddRectFilledMultiColor(const ImVec2& p_min, const ImVec2& p_max, ImU32 col_upr_left, ImU32 col_upr_right, ImU32 col_bot_right, ImU32 col_bot_left);
+ IMGUI_API void AddQuad(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, ImU32 col, float thickness = 1.0f);
+ IMGUI_API void AddQuadFilled(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, ImU32 col);
+ IMGUI_API void AddTriangle(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, ImU32 col, float thickness = 1.0f);
+ IMGUI_API void AddTriangleFilled(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, ImU32 col);
+ IMGUI_API void AddCircle(const ImVec2& center, float radius, ImU32 col, int num_segments = 12, float thickness = 1.0f);
+ IMGUI_API void AddCircleFilled(const ImVec2& center, float radius, ImU32 col, int num_segments = 12);
IMGUI_API void AddText(const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL);
IMGUI_API void AddText(const ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL, float wrap_width = 0.0f, const ImVec4* cpu_fine_clip_rect = NULL);
- IMGUI_API void AddImage(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv_a = ImVec2(0,0), const ImVec2& uv_b = ImVec2(1,1), ImU32 col = 0xFFFFFFFF);
- IMGUI_API void AddImageQuad(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& d, const ImVec2& uv_a = ImVec2(0,0), const ImVec2& uv_b = ImVec2(1,0), const ImVec2& uv_c = ImVec2(1,1), const ImVec2& uv_d = ImVec2(0,1), ImU32 col = 0xFFFFFFFF);
- IMGUI_API void AddImageRounded(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv_a, const ImVec2& uv_b, ImU32 col, float rounding, int rounding_corners = ImDrawCornerFlags_All);
- IMGUI_API void AddPolyline(const ImVec2* points, const int num_points, ImU32 col, bool closed, float thickness);
- IMGUI_API void AddConvexPolyFilled(const ImVec2* points, const int num_points, ImU32 col); // Note: Anti-aliased filling requires points to be in clockwise order.
+ IMGUI_API void AddPolyline(const ImVec2* points, int num_points, ImU32 col, bool closed, float thickness);
+ IMGUI_API void AddConvexPolyFilled(const ImVec2* points, int num_points, ImU32 col); // Note: Anti-aliased filling requires points to be in clockwise order.
IMGUI_API void AddBezierCurve(const ImVec2& pos0, const ImVec2& cp0, const ImVec2& cp1, const ImVec2& pos1, ImU32 col, float thickness, int num_segments = 0);
+ // Image primitives
+ // - Read FAQ to understand what ImTextureID is.
+ // - "p_min" and "p_max" represent the upper-left and lower-right corners of the rectangle.
+ // - "uv_min" and "uv_max" represent the normalized texture coordinates to use for those corners. Using (0,0)->(1,1) texture coordinates will generally display the entire texture.
+ IMGUI_API void AddImage(ImTextureID user_texture_id, const ImVec2& p_min, const ImVec2& p_max, const ImVec2& uv_min = ImVec2(0, 0), const ImVec2& uv_max = ImVec2(1, 1), ImU32 col = IM_COL32_WHITE);
+ IMGUI_API void AddImageQuad(ImTextureID user_texture_id, const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, const ImVec2& uv1 = ImVec2(0, 0), const ImVec2& uv2 = ImVec2(1, 0), const ImVec2& uv3 = ImVec2(1, 1), const ImVec2& uv4 = ImVec2(0, 1), ImU32 col = IM_COL32_WHITE);
+ IMGUI_API void AddImageRounded(ImTextureID user_texture_id, const ImVec2& p_min, const ImVec2& p_max, const ImVec2& uv_min, const ImVec2& uv_max, ImU32 col, float rounding, ImDrawCornerFlags rounding_corners = ImDrawCornerFlags_All);
+
// Stateful path API, add points then finish with PathFillConvex() or PathStroke()
inline void PathClear() { _Path.Size = 0; }
inline void PathLineTo(const ImVec2& pos) { _Path.push_back(pos); }
inline void PathLineToMergeDuplicate(const ImVec2& pos) { if (_Path.Size == 0 || memcmp(&_Path.Data[_Path.Size-1], &pos, 8) != 0) _Path.push_back(pos); }
inline void PathFillConvex(ImU32 col) { AddConvexPolyFilled(_Path.Data, _Path.Size, col); _Path.Size = 0; } // Note: Anti-aliased filling requires points to be in clockwise order.
inline void PathStroke(ImU32 col, bool closed, float thickness = 1.0f) { AddPolyline(_Path.Data, _Path.Size, col, closed, thickness); _Path.Size = 0; }
- IMGUI_API void PathArcTo(const ImVec2& centre, float radius, float a_min, float a_max, int num_segments = 10);
- IMGUI_API void PathArcToFast(const ImVec2& centre, float radius, int a_min_of_12, int a_max_of_12); // Use precomputed angles for a 12 steps circle
+ IMGUI_API void PathArcTo(const ImVec2& center, float radius, float a_min, float a_max, int num_segments = 10);
+ IMGUI_API void PathArcToFast(const ImVec2& center, float radius, int a_min_of_12, int a_max_of_12); // Use precomputed angles for a 12 steps circle
IMGUI_API void PathBezierCurveTo(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, int num_segments = 0);
- IMGUI_API void PathRect(const ImVec2& rect_min, const ImVec2& rect_max, float rounding = 0.0f, int rounding_corners_flags = ImDrawCornerFlags_All);
-
- // Channels
- // - Use to simulate layers. By switching channels to can render out-of-order (e.g. submit foreground primitives before background primitives)
- // - Use to minimize draw calls (e.g. if going back-and-forth between multiple non-overlapping clipping rectangles, prefer to append into separate channels then merge at the end)
- IMGUI_API void ChannelsSplit(int channels_count);
- IMGUI_API void ChannelsMerge();
- IMGUI_API void ChannelsSetCurrent(int channel_index);
+ IMGUI_API void PathRect(const ImVec2& rect_min, const ImVec2& rect_max, float rounding = 0.0f, ImDrawCornerFlags rounding_corners = ImDrawCornerFlags_All);
// Advanced
IMGUI_API void AddCallback(ImDrawCallback callback, void* callback_data); // Your rendering function must check for 'UserCallback' in ImDrawCmd and call the function instead of rendering triangles.
IMGUI_API void AddDrawCmd(); // This is useful if you need to forcefully create a new draw call (to allow for dependent rendering / blending). Otherwise primitives are merged into the same draw-call as much as possible
IMGUI_API ImDrawList* CloneOutput() const; // Create a clone of the CmdBuffer/IdxBuffer/VtxBuffer.
+ // Advanced: Channels
+ // - Use to split render into layers. By switching channels to can render out-of-order (e.g. submit foreground primitives before background primitives)
+ // - Use to minimize draw calls (e.g. if going back-and-forth between multiple non-overlapping clipping rectangles, prefer to append into separate channels then merge at the end)
+ inline void ChannelsSplit(int count) { _Splitter.Split(this, count); }
+ inline void ChannelsMerge() { _Splitter.Merge(this); }
+ inline void ChannelsSetCurrent(int n) { _Splitter.SetCurrentChannel(this, n); }
+
// Internal helpers
// NB: all primitives needs to be reserved via PrimReserve() beforehand!
IMGUI_API void Clear();
@@ -1971,8 +2061,9 @@ struct ImDrawList
IMGUI_API void UpdateTextureID();
};
-// All draw data to render an ImGui frame
-// (NB: the style and the naming convention here is a little inconsistent but we preserve them for backward compatibility purpose)
+// All draw data to render a Dear ImGui frame
+// (NB: the style and the naming convention here is a little inconsistent, we currently preserve them for backward compatibility purpose,
+// as this is one of the oldest structure exposed by the library! Basically, ImDrawList == CmdList)
struct ImDrawData
{
bool Valid; // Only valid after Render() is called and before the next NewFrame() is called.
@@ -1982,13 +2073,15 @@ struct ImDrawData
int TotalVtxCount; // For convenience, sum of all ImDrawList's VtxBuffer.Size
ImVec2 DisplayPos; // Upper-left position of the viewport to render (== upper-left of the orthogonal projection matrix to use)
ImVec2 DisplaySize; // Size of the viewport to render (== io.DisplaySize for the main viewport) (DisplayPos + DisplaySize == lower-right of the orthogonal projection matrix to use)
+ ImVec2 FramebufferScale; // Amount of pixels for each unit of DisplaySize. Based on io.DisplayFramebufferScale. Generally (1,1) on normal display, (2,2) on OSX with Retina display.
+ ImGuiViewport* OwnerViewport; // Viewport carrying the ImDrawData instance, might be of use to the renderer (generally not).
// Functions
ImDrawData() { Valid = false; Clear(); }
~ImDrawData() { Clear(); }
- void Clear() { Valid = false; CmdLists = NULL; CmdListsCount = TotalVtxCount = TotalIdxCount = 0; DisplayPos = DisplaySize = ImVec2(0.f, 0.f); } // The ImDrawList are owned by ImGuiContext!
- IMGUI_API void DeIndexAllBuffers(); // Helper to convert all buffers from indexed to non-indexed, in case you cannot render indexed. Note: this is slow and most likely a waste of resources. Always prefer indexed rendering!
- IMGUI_API void ScaleClipRects(const ImVec2& sc); // Helper to scale the ClipRect field of each ImDrawCmd. Use if your final output buffer is at a different scale than ImGui expects, or if there is a difference between your window resolution and framebuffer resolution.
+ void Clear() { Valid = false; CmdLists = NULL; CmdListsCount = TotalVtxCount = TotalIdxCount = 0; DisplayPos = DisplaySize = FramebufferScale = ImVec2(0.f, 0.f); OwnerViewport = NULL; } // The ImDrawList are owned by ImGuiContext!
+ IMGUI_API void DeIndexAllBuffers(); // Helper to convert all buffers from indexed to non-indexed, in case you cannot render indexed. Note: this is slow and most likely a waste of resources. Always prefer indexed rendering!
+ IMGUI_API void ScaleClipRects(const ImVec2& fb_scale); // Helper to scale the ClipRect field of each ImDrawCmd. Use if your final output buffer is at a different scale than Dear ImGui expects, or if there is a difference between your window resolution and framebuffer resolution.
};
//-----------------------------------------------------------------------------
@@ -2002,7 +2095,7 @@ struct ImFontConfig
bool FontDataOwnedByAtlas; // true // TTF/OTF data ownership taken by the container ImFontAtlas (will delete memory itself).
int FontNo; // 0 // Index of font within TTF/OTF file
float SizePixels; // // Size in pixels for rasterizer (more or less maps to the resulting font height).
- int OversampleH; // 3 // Rasterize at higher quality for sub-pixel positioning. We don't use sub-pixel positions on the Y axis.
+ int OversampleH; // 3 // Rasterize at higher quality for sub-pixel positioning. Read https://github.com/nothings/stb/blob/master/tests/oversample/README.md for details.
int OversampleV; // 1 // Rasterize at higher quality for sub-pixel positioning. We don't use sub-pixel positions on the Y axis.
bool PixelSnapH; // false // Align every glyph to pixel boundary. Useful e.g. if you are merging a non-pixel aligned font with the default font. If enabled, you can set OversampleH/V to 1.
ImVec2 GlyphExtraSpacing; // 0, 0 // Extra spacing (in pixels) between glyphs. Only X axis is supported for now.
@@ -2033,15 +2126,29 @@ struct ImFontGlyph
// This is essentially a tightly packed of vector of 64k booleans = 8KB storage.
struct ImFontGlyphRangesBuilder
{
- ImVector UsedChars; // Store 1-bit per Unicode code point (0=unused, 1=used)
-
- ImFontGlyphRangesBuilder() { UsedChars.resize(0x10000 / sizeof(int)); memset(UsedChars.Data, 0, 0x10000 / sizeof(int)); }
- bool GetBit(int n) const { int off = (n >> 5); int mask = 1 << (n & 31); return (UsedChars[off] & mask) != 0; } // Get bit n in the array
- void SetBit(int n) { int off = (n >> 5); int mask = 1 << (n & 31); UsedChars[off] |= mask; } // Set bit n in the array
- void AddChar(ImWchar c) { SetBit(c); } // Add character
- IMGUI_API void AddText(const char* text, const char* text_end = NULL); // Add string (each character of the UTF-8 string are added)
- IMGUI_API void AddRanges(const ImWchar* ranges); // Add ranges, e.g. builder.AddRanges(ImFontAtlas::GetGlyphRangesDefault()) to force add all of ASCII/Latin+Ext
- IMGUI_API void BuildRanges(ImVector* out_ranges); // Output new ranges
+ ImVector UsedChars; // Store 1-bit per Unicode code point (0=unused, 1=used)
+
+ ImFontGlyphRangesBuilder() { Clear(); }
+ inline void Clear() { int size_in_bytes = 0x10000 / 8; UsedChars.resize(size_in_bytes / (int)sizeof(ImU32)); memset(UsedChars.Data, 0, (size_t)size_in_bytes); }
+ inline bool GetBit(int n) const { int off = (n >> 5); ImU32 mask = 1u << (n & 31); return (UsedChars[off] & mask) != 0; } // Get bit n in the array
+ inline void SetBit(int n) { int off = (n >> 5); ImU32 mask = 1u << (n & 31); UsedChars[off] |= mask; } // Set bit n in the array
+ inline void AddChar(ImWchar c) { SetBit(c); } // Add character
+ IMGUI_API void AddText(const char* text, const char* text_end = NULL); // Add string (each character of the UTF-8 string are added)
+ IMGUI_API void AddRanges(const ImWchar* ranges); // Add ranges, e.g. builder.AddRanges(ImFontAtlas::GetGlyphRangesDefault()) to force add all of ASCII/Latin+Ext
+ IMGUI_API void BuildRanges(ImVector* out_ranges); // Output new ranges
+};
+
+// See ImFontAtlas::AddCustomRectXXX functions.
+struct ImFontAtlasCustomRect
+{
+ unsigned int ID; // Input // User ID. Use <0x10000 to map into a font glyph, >=0x10000 for other/internal/custom texture data.
+ unsigned short Width, Height; // Input // Desired rectangle dimension
+ unsigned short X, Y; // Output // Packed position in Atlas
+ float GlyphAdvanceX; // Input // For custom font glyphs only (ID<0x10000): glyph xadvance
+ ImVec2 GlyphOffset; // Input // For custom font glyphs only (ID<0x10000): glyph display offset
+ ImFont* Font; // Input // For custom font glyphs only (ID<0x10000): target font
+ ImFontAtlasCustomRect() { ID = 0xFFFFFFFF; Width = Height = 0; X = Y = 0xFFFF; GlyphAdvanceX = 0.0f; GlyphOffset = ImVec2(0,0); Font = NULL; }
+ bool IsPacked() const { return X != 0xFFFF; }
};
enum ImFontAtlasFlags_
@@ -2108,32 +2215,24 @@ struct ImFontAtlas
IMGUI_API const ImWchar* GetGlyphRangesChineseSimplifiedCommon();// Default + Half-Width + Japanese Hiragana/Katakana + set of 2500 CJK Unified Ideographs for common simplified Chinese
IMGUI_API const ImWchar* GetGlyphRangesCyrillic(); // Default + about 400 Cyrillic characters
IMGUI_API const ImWchar* GetGlyphRangesThai(); // Default + Thai characters
+ IMGUI_API const ImWchar* GetGlyphRangesVietnamese(); // Default + Vietnamese characters
//-------------------------------------------
- // Custom Rectangles/Glyphs API
+ // [BETA] Custom Rectangles/Glyphs API
//-------------------------------------------
- // You can request arbitrary rectangles to be packed into the atlas, for your own purposes. After calling Build(), you can query the rectangle position and render your pixels.
- // You can also request your rectangles to be mapped as font glyph (given a font + Unicode point), so you can render e.g. custom colorful icons and use them as regular glyphs.
- struct CustomRect
- {
- unsigned int ID; // Input // User ID. Use <0x10000 to map into a font glyph, >=0x10000 for other/internal/custom texture data.
- unsigned short Width, Height; // Input // Desired rectangle dimension
- unsigned short X, Y; // Output // Packed position in Atlas
- float GlyphAdvanceX; // Input // For custom font glyphs only (ID<0x10000): glyph xadvance
- ImVec2 GlyphOffset; // Input // For custom font glyphs only (ID<0x10000): glyph display offset
- ImFont* Font; // Input // For custom font glyphs only (ID<0x10000): target font
- CustomRect() { ID = 0xFFFFFFFF; Width = Height = 0; X = Y = 0xFFFF; GlyphAdvanceX = 0.0f; GlyphOffset = ImVec2(0,0); Font = NULL; }
- bool IsPacked() const { return X != 0xFFFF; }
- };
-
- IMGUI_API int AddCustomRectRegular(unsigned int id, int width, int height); // Id needs to be >= 0x10000. Id >= 0x80000000 are reserved for ImGui and ImDrawList
- IMGUI_API int AddCustomRectFontGlyph(ImFont* font, ImWchar id, int width, int height, float advance_x, const ImVec2& offset = ImVec2(0,0)); // Id needs to be < 0x10000 to register a rectangle to map into a specific font.
- const CustomRect* GetCustomRectByIndex(int index) const { if (index < 0) return NULL; return &CustomRects[index]; }
+ // You can request arbitrary rectangles to be packed into the atlas, for your own purposes.
+ // After calling Build(), you can query the rectangle position and render your pixels.
+ // You can also request your rectangles to be mapped as font glyph (given a font + Unicode point),
+ // so you can render e.g. custom colorful icons and use them as regular glyphs.
+ // Read misc/fonts/README.txt for more details about using colorful icons.
+ IMGUI_API int AddCustomRectRegular(unsigned int id, int width, int height); // Id needs to be >= 0x10000. Id >= 0x80000000 are reserved for ImGui and ImDrawList
+ IMGUI_API int AddCustomRectFontGlyph(ImFont* font, ImWchar id, int width, int height, float advance_x, const ImVec2& offset = ImVec2(0,0)); // Id needs to be < 0x10000 to register a rectangle to map into a specific font.
+ const ImFontAtlasCustomRect*GetCustomRectByIndex(int index) const { if (index < 0) return NULL; return &CustomRects[index]; }
// [Internal]
- IMGUI_API void CalcCustomRectUV(const CustomRect* rect, ImVec2* out_uv_min, ImVec2* out_uv_max);
- IMGUI_API bool GetMouseCursorTexData(ImGuiMouseCursor cursor, ImVec2* out_offset, ImVec2* out_size, ImVec2 out_uv_border[2], ImVec2 out_uv_fill[2]);
+ IMGUI_API void CalcCustomRectUV(const ImFontAtlasCustomRect* rect, ImVec2* out_uv_min, ImVec2* out_uv_max);
+ IMGUI_API bool GetMouseCursorTexData(ImGuiMouseCursor cursor, ImVec2* out_offset, ImVec2* out_size, ImVec2 out_uv_border[2], ImVec2 out_uv_fill[2]);
//-------------------------------------------
// Members
@@ -2154,12 +2253,13 @@ struct ImFontAtlas
ImVec2 TexUvScale; // = (1.0f/TexWidth, 1.0f/TexHeight)
ImVec2 TexUvWhitePixel; // Texture coordinates to a white pixel
ImVector Fonts; // Hold all the fonts returned by AddFont*. Fonts[0] is the default font upon calling ImGui::NewFrame(), use ImGui::PushFont()/PopFont() to change the current font.
- ImVector CustomRects; // Rectangles for packing custom texture data into the atlas.
+ ImVector CustomRects; // Rectangles for packing custom texture data into the atlas.
ImVector ConfigData; // Internal data
int CustomRectIds[1]; // Identifiers of custom texture rectangle used by ImFontAtlas/ImDrawList
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
- typedef ImFontGlyphRangesBuilder GlyphRangesBuilder; // OBSOLETE 1.67+
+ typedef ImFontAtlasCustomRect CustomRect; // OBSOLETED in 1.72+
+ typedef ImFontGlyphRangesBuilder GlyphRangesBuilder; // OBSOLETED in 1.67+
#endif
};
@@ -2167,33 +2267,32 @@ struct ImFontAtlas
// ImFontAtlas automatically loads a default embedded font for you when you call GetTexDataAsAlpha8() or GetTexDataAsRGBA32().
struct ImFont
{
- // Members: Hot ~62/78 bytes
- float FontSize; // // Height of characters, set during loading (don't change after loading)
- float Scale; // = 1.f // Base font scale, multiplied by the per-window font scale which you can adjust with SetWindowFontScale()
- ImVec2 DisplayOffset; // = (0.f,0.f) // Offset font rendering by xx pixels
- ImVector Glyphs; // // All glyphs.
- ImVector IndexAdvanceX; // // Sparse. Glyphs->AdvanceX in a directly indexable way (more cache-friendly, for CalcTextSize functions which are often bottleneck in large UI).
- ImVector IndexLookup; // // Sparse. Index glyphs by Unicode code-point.
- const ImFontGlyph* FallbackGlyph; // == FindGlyph(FontFallbackChar)
- float FallbackAdvanceX; // == FallbackGlyph->AdvanceX
- ImWchar FallbackChar; // = '?' // Replacement glyph if one isn't found. Only set via SetFallbackChar()
-
- // Members: Cold ~18/26 bytes
- short ConfigDataCount; // ~ 1 // Number of ImFontConfig involved in creating this font. Bigger than 1 when merging multiple font sources into one ImFont.
- ImFontConfig* ConfigData; // // Pointer within ContainerAtlas->ConfigData
- ImFontAtlas* ContainerAtlas; // // What we has been loaded into
- float Ascent, Descent; // // Ascent: distance from top to bottom of e.g. 'A' [0..FontSize]
- bool DirtyLookupTables;
- int MetricsTotalSurface;// // Total surface in pixels to get an idea of the font rasterization/texture cost (not exact, we approximate the cost of padding between glyphs)
+ // Members: Hot ~20/24 bytes (for CalcTextSize)
+ ImVector IndexAdvanceX; // 12-16 // out // // Sparse. Glyphs->AdvanceX in a directly indexable way (cache-friendly for CalcTextSize functions which only this this info, and are often bottleneck in large UI).
+ float FallbackAdvanceX; // 4 // out // = FallbackGlyph->AdvanceX
+ float FontSize; // 4 // in // // Height of characters/line, set during loading (don't change after loading)
+
+ // Members: Hot ~36/48 bytes (for CalcTextSize + render loop)
+ ImVector IndexLookup; // 12-16 // out // // Sparse. Index glyphs by Unicode code-point.
+ ImVector Glyphs; // 12-16 // out // // All glyphs.
+ const ImFontGlyph* FallbackGlyph; // 4-8 // out // = FindGlyph(FontFallbackChar)
+ ImVec2 DisplayOffset; // 8 // in // = (0,0) // Offset font rendering by xx pixels
+
+ // Members: Cold ~32/40 bytes
+ ImFontAtlas* ContainerAtlas; // 4-8 // out // // What we has been loaded into
+ const ImFontConfig* ConfigData; // 4-8 // in // // Pointer within ContainerAtlas->ConfigData
+ short ConfigDataCount; // 2 // in // ~ 1 // Number of ImFontConfig involved in creating this font. Bigger than 1 when merging multiple font sources into one ImFont.
+ ImWchar FallbackChar; // 2 // in // = '?' // Replacement glyph if one isn't found. Only set via SetFallbackChar()
+ float Scale; // 4 // in // = 1.f // Base font scale, multiplied by the per-window font scale which you can adjust with SetWindowFontScale()
+ float Ascent, Descent; // 4+4 // out // // Ascent: distance from top to bottom of e.g. 'A' [0..FontSize]
+ int MetricsTotalSurface;// 4 // out // // Total surface in pixels to get an idea of the font rasterization/texture cost (not exact, we approximate the cost of padding between glyphs)
+ bool DirtyLookupTables; // 1 // out //
// Methods
IMGUI_API ImFont();
IMGUI_API ~ImFont();
- IMGUI_API void ClearOutputData();
- IMGUI_API void BuildLookupTable();
IMGUI_API const ImFontGlyph*FindGlyph(ImWchar c) const;
IMGUI_API const ImFontGlyph*FindGlyphNoFallback(ImWchar c) const;
- IMGUI_API void SetFallbackChar(ImWchar c);
float GetCharAdvance(ImWchar c) const { return ((int)c < IndexAdvanceX.Size) ? IndexAdvanceX[(int)c] : FallbackAdvanceX; }
bool IsLoaded() const { return ContainerAtlas != NULL; }
const char* GetDebugName() const { return ConfigData ? ConfigData->Name : ""; }
@@ -2205,13 +2304,16 @@ struct ImFont
IMGUI_API void RenderChar(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col, ImWchar c) const;
IMGUI_API void RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, float wrap_width = 0.0f, bool cpu_fine_clip = false) const;
- // [Internal]
+ // [Internal] Don't use!
+ IMGUI_API void BuildLookupTable();
+ IMGUI_API void ClearOutputData();
IMGUI_API void GrowIndex(int new_size);
IMGUI_API void AddGlyph(ImWchar c, float x0, float y0, float x1, float y1, float u0, float v0, float u1, float v1, float advance_x);
IMGUI_API void AddRemapChar(ImWchar dst, ImWchar src, bool overwrite_dst = true); // Makes 'dst' character/glyph points to 'src' character/glyph. Currently needs to be called AFTER fonts have been built.
+ IMGUI_API void SetFallbackChar(ImWchar c);
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
- typedef ImFontGlyph Glyph; // OBSOLETE 1.52+
+ typedef ImFontGlyph Glyph; // OBSOLETED in 1.52+
#endif
};
@@ -2301,7 +2403,10 @@ enum ImGuiViewportFlags_
ImGuiViewportFlags_NoFocusOnClick = 1 << 3, // Platform Window: Don't take focus when clicked on.
ImGuiViewportFlags_NoInputs = 1 << 4, // Platform Window: Make mouse pass through so we can drag this window while peaking behind it.
ImGuiViewportFlags_NoRendererClear = 1 << 5, // Platform Window: Renderer doesn't need to clear the framebuffer ahead (because we will fill it entirely).
- ImGuiViewportFlags_TopMost = 1 << 6 // Platform Window: Display on top (for tooltips only)
+ ImGuiViewportFlags_TopMost = 1 << 6, // Platform Window: Display on top (for tooltips only).
+ ImGuiViewportFlags_Minimized = 1 << 7, // Platform Window: Window is minimized, can skip render. When minimized we tend to avoid using the viewport pos/size for clipping window or testing if they are contained in the viewport.
+ ImGuiViewportFlags_NoAutoMerge = 1 << 8, // Platform Window: Avoid merging this widow into another host window. This can only be set via ImGuiWindowClass viewport flags override (because we need to now ahead if we are going to create a viewport in the first place!).
+ ImGuiViewportFlags_CanHostOtherWindows = 1 << 9 // Main viewport: can host multiple imgui windows (secondary viewports are associated to a single window).
};
// The viewports created and managed by imgui. The role of the platform back-end is to create the platform/OS windows corresponding to each viewport.
@@ -2317,18 +2422,19 @@ struct ImGuiViewport
void* RendererUserData; // void* to hold custom data structure for the renderer (e.g. swap chain, frame-buffers etc.)
void* PlatformUserData; // void* to hold custom data structure for the OS / platform (e.g. windowing info, render context)
- void* PlatformHandle; // void* for FindViewportByPlatformHandle(). (e.g. suggested to use natural platform handle such as HWND, GlfwWindow*, SDL_Window*)
+ void* PlatformHandle; // void* for FindViewportByPlatformHandle(). (e.g. suggested to use natural platform handle such as HWND, GLFWWindow*, SDL_Window*)
+ void* PlatformHandleRaw; // void* to hold low-level, platform-native window handle (e.g. the HWND) when using an abstraction layer like GLFW or SDL (where PlatformHandle would be a SDL_Window*)
bool PlatformRequestClose; // Platform window requested closure (e.g. window was moved by the OS / host window manager, e.g. pressing ALT-F4)
bool PlatformRequestMove; // Platform window requested move (e.g. window was moved by the OS / host window manager, authoritative position will be OS window position)
bool PlatformRequestResize; // Platform window requested resize (e.g. window was resized by the OS / host window manager, authoritative size will be OS window size)
- ImGuiViewport() { ID = 0; Flags = 0; DpiScale = 0.0f; DrawData = NULL; ParentViewportId = 0; RendererUserData = PlatformUserData = PlatformHandle = NULL; PlatformRequestClose = PlatformRequestMove = PlatformRequestResize = false; }
+ ImGuiViewport() { ID = 0; Flags = 0; DpiScale = 0.0f; DrawData = NULL; ParentViewportId = 0; RendererUserData = PlatformUserData = PlatformHandle = PlatformHandleRaw = NULL; PlatformRequestClose = PlatformRequestMove = PlatformRequestResize = false; }
~ImGuiViewport() { IM_ASSERT(PlatformUserData == NULL && RendererUserData == NULL); }
};
#if defined(__clang__)
#pragma clang diagnostic pop
-#elif defined(__GNUC__) && __GNUC__ >= 8
+#elif defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
diff --git a/imgui_demo.cpp b/imgui_demo.cpp
index f001fff2..9dcc56a8 100644
--- a/imgui_demo.cpp
+++ b/imgui_demo.cpp
@@ -1,4 +1,4 @@
-// dear imgui, v1.68 WIP
+// dear imgui, v1.73 WIP
// (demo code)
// Message to the person tempted to delete this file when integrating Dear ImGui into their code base:
@@ -17,9 +17,18 @@
// In this demo code, we frequently we use 'static' variables inside functions. A static variable persist across calls, so it is
// essentially like a global variable but declared inside the scope of the function. We do this as a way to gather code and data
// in the same place, to make the demo source code faster to read, faster to write, and smaller in size.
-// It also happens to be a convenient way of storing simple UI related information as long as your function doesn't need to be reentrant
-// or used in threads. This might be a pattern you will want to use in your code, but most of the real data you would be editing is
-// likely going to be stored outside your functions.
+// It also happens to be a convenient way of storing simple UI related information as long as your function doesn't need to be
+// reentrant or used in multiple threads. This might be a pattern you will want to use in your code, but most of the real data
+// you would be editing is likely going to be stored outside your functions.
+
+// The Demo code is this file is designed to be easy to copy-and-paste in into your application!
+// Because of this:
+// - We never omit the ImGui:: namespace when calling functions, even though most of our code is already in the same namespace.
+// - We try to declare static variables in the local scope, as close as possible to the code using them.
+// - We never use any of the helpers/facilities used internally by dear imgui, unless it has been exposed in the public API (imgui.h).
+// - We never use maths operators on ImVec2/ImVec4. For other imgui sources files, they are provided by imgui_internal.h w/ IMGUI_DEFINE_MATH_OPERATORS,
+// for your own sources file they are optional and require you either enable those, either provide your own via IM_VEC2_CLASS_EXTRA in imconfig.h.
+// Because we don't want to assume anything about your support of maths operators, we don't use them in imgui_demo.cpp.
/*
@@ -50,7 +59,7 @@ Index of this file:
#endif
#include "imgui.h"
-#include // toupper, isprint
+#include // toupper
#include // INT_MIN, INT_MAX
#include // sqrtf, powf, cosf, sinf, floorf, ceilf
#include // vsnprintf, sscanf, printf
@@ -63,14 +72,14 @@ Index of this file:
#ifdef _MSC_VER
#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen
-#define vsnprintf _vsnprintf
#endif
-#ifdef __clang__
+#if defined(__clang__)
#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
#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 "-Wunused-macros" // warning : warning: macro is not used // we define snprintf/vsnprintf on Windows so they are available, but not always used.
#if __has_warning("-Wzero-as-null-pointer-constant")
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" // warning : zero as null pointer constant // some standard header variations use #define NULL 0
#endif
@@ -81,20 +90,21 @@ Index of this file:
#pragma clang diagnostic ignored "-Wreserved-id-macro" // warning : macro name is a reserved identifier //
#endif
#elif defined(__GNUC__)
+#pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind
#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
-#if (__GNUC__ >= 6)
-#pragma GCC diagnostic ignored "-Wmisleading-indentation" // warning: this 'if' clause does not guard this statement // GCC 6.0+ only. See #883 on GitHub.
-#endif
+#pragma GCC diagnostic ignored "-Wmisleading-indentation" // [__GNUC__ >= 6] warning: this 'if' clause does not guard this statement // GCC 6.0+ only. See #883 on GitHub.
#endif
// Play it nice with Windows users. Notepad in 2017 still doesn't display text data with Unix-style \n.
#ifdef _WIN32
-#define IM_NEWLINE "\r\n"
+#define IM_NEWLINE "\r\n"
+#define snprintf _snprintf
+#define vsnprintf _vsnprintf
#else
-#define IM_NEWLINE "\n"
+#define IM_NEWLINE "\n"
#endif
#define IM_MAX(_A,_B) (((_A) >= (_B)) ? (_A) : (_B))
@@ -126,7 +136,8 @@ static void ShowExampleAppCustomRendering(bool* p_open);
static void ShowExampleMenuFile();
// Helper to display a little (?) mark which shows a tooltip when hovered.
-static void ShowHelpMarker(const char* desc)
+// In your own code you may want to display an actual icon if you are using a merged icon fonts (see misc/fonts/README.txt)
+static void HelpMarker(const char* desc)
{
ImGui::TextDisabled("(?)");
if (ImGui::IsItemHovered())
@@ -152,12 +163,13 @@ static void ShowDockingDisabledMessage()
// Helper to display basic user controls.
void ImGui::ShowUserGuide()
{
+ ImGuiIO& io = ImGui::GetIO();
ImGui::BulletText("Double-click on title bar to collapse window.");
ImGui::BulletText("Click and drag on lower right corner to resize window\n(double-click to auto fit window to its contents).");
ImGui::BulletText("Click and drag on any empty space to move window.");
ImGui::BulletText("TAB/SHIFT+TAB to cycle through keyboard editable fields.");
ImGui::BulletText("CTRL+Click on a slider or drag box to input value as text.");
- if (ImGui::GetIO().FontAllowUserScaling)
+ if (io.FontAllowUserScaling)
ImGui::BulletText("CTRL+Mouse Wheel to zoom window contents.");
ImGui::BulletText("Mouse Wheel to scroll.");
ImGui::BulletText("While editing text:\n");
@@ -187,6 +199,8 @@ static void ShowDemoWindowMisc();
// You may execute this function to experiment with the UI and understand what it does. You may then search for keywords in the code when you are interested by a specific feature.
void ImGui::ShowDemoWindow(bool* p_open)
{
+ IM_ASSERT(ImGui::GetCurrentContext() != NULL && "Missing dear imgui context. Refer to examples app!"); // Exceptionally add an extra assert here for people confused with initial dear imgui setup
+
// Examples Apps (accessible from the "Examples" menu)
static bool show_app_dockspace = false;
static bool show_app_documents = false;
@@ -257,19 +271,18 @@ void ImGui::ShowDemoWindow(bool* p_open)
ImGui::SetNextWindowSize(ImVec2(550, 680), ImGuiCond_FirstUseEver);
// Main body of the Demo window starts here.
- if (!ImGui::Begin("ImGui Demo", p_open, window_flags))
+ if (!ImGui::Begin("Dear ImGui Demo", p_open, window_flags))
{
// Early out if the window is collapsed, as an optimization.
ImGui::End();
return;
}
- ImGui::Text("dear imgui says hello. (%s)", IMGUI_VERSION);
// Most "big" widgets share a common width settings by default.
//ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f); // Use 2/3 of the space for widgets and 1/3 for labels (default)
ImGui::PushItemWidth(ImGui::GetFontSize() * -12); // Use fixed width for labels (by passing a negative value), the rest goes to widgets. We choose a width proportional to our font size.
- // Menu
+ // Menu Bar
if (ImGui::BeginMenuBar())
{
if (ImGui::BeginMenu("Menu"))
@@ -304,7 +317,9 @@ void ImGui::ShowDemoWindow(bool* p_open)
ImGui::EndMenuBar();
}
+ ImGui::Text("dear imgui says hello. (%s)", IMGUI_VERSION);
ImGui::Spacing();
+
if (ImGui::CollapsingHeader("Help"))
{
ImGui::Text("PROGRAMMER GUIDE:");
@@ -327,9 +342,9 @@ void ImGui::ShowDemoWindow(bool* p_open)
{
ImGui::CheckboxFlags("io.ConfigFlags: NavEnableKeyboard", (unsigned int *)&io.ConfigFlags, ImGuiConfigFlags_NavEnableKeyboard);
ImGui::CheckboxFlags("io.ConfigFlags: NavEnableGamepad", (unsigned int *)&io.ConfigFlags, ImGuiConfigFlags_NavEnableGamepad);
- ImGui::SameLine(); ShowHelpMarker("Required back-end to feed in gamepad inputs in io.NavInputs[] and set io.BackendFlags |= ImGuiBackendFlags_HasGamepad.\n\nRead instructions in imgui.cpp for details.");
+ ImGui::SameLine(); HelpMarker("Required back-end to feed in gamepad inputs in io.NavInputs[] and set io.BackendFlags |= ImGuiBackendFlags_HasGamepad.\n\nRead instructions in imgui.cpp for details.");
ImGui::CheckboxFlags("io.ConfigFlags: NavEnableSetMousePos", (unsigned int *)&io.ConfigFlags, ImGuiConfigFlags_NavEnableSetMousePos);
- ImGui::SameLine(); ShowHelpMarker("Instruct navigation to move the mouse cursor. See comment for ImGuiConfigFlags_NavEnableSetMousePos.");
+ ImGui::SameLine(); HelpMarker("Instruct navigation to move the mouse cursor. See comment for ImGuiConfigFlags_NavEnableSetMousePos.");
ImGui::CheckboxFlags("io.ConfigFlags: NoMouse", (unsigned int *)&io.ConfigFlags, ImGuiConfigFlags_NoMouse);
if (io.ConfigFlags & ImGuiConfigFlags_NoMouse) // Create a way to restore this flag otherwise we could be stuck completely!
{
@@ -342,60 +357,61 @@ void ImGui::ShowDemoWindow(bool* p_open)
io.ConfigFlags &= ~ImGuiConfigFlags_NoMouse;
}
ImGui::CheckboxFlags("io.ConfigFlags: NoMouseCursorChange", (unsigned int *)&io.ConfigFlags, ImGuiConfigFlags_NoMouseCursorChange);
- ImGui::SameLine(); ShowHelpMarker("Instruct back-end to not alter mouse cursor shape and visibility.");
+ ImGui::SameLine(); HelpMarker("Instruct back-end to not alter mouse cursor shape and visibility.");
ImGui::CheckboxFlags("io.ConfigFlags: DockingEnable", (unsigned int *)&io.ConfigFlags, ImGuiConfigFlags_DockingEnable);
- ImGui::SameLine(); ShowHelpMarker(io.ConfigDockingWithShift ? "[beta] Use SHIFT to dock window into each others." : "[beta] Drag from title bar to dock windows into each others.");
+ ImGui::SameLine(); HelpMarker(io.ConfigDockingWithShift ? "[beta] Use SHIFT to dock window into each others." : "[beta] Drag from title bar to dock windows into each others.");
if (io.ConfigFlags & ImGuiConfigFlags_DockingEnable)
{
ImGui::Indent();
ImGui::Checkbox("io.ConfigDockingNoSplit", &io.ConfigDockingNoSplit);
- ImGui::SameLine(); ShowHelpMarker("Simplified docking mode: disable window splitting, so docking is limited to merging multiple windows together into tab-bars.");
+ ImGui::SameLine(); HelpMarker("Simplified docking mode: disable window splitting, so docking is limited to merging multiple windows together into tab-bars.");
ImGui::Checkbox("io.ConfigDockingWithShift", &io.ConfigDockingWithShift);
- ImGui::SameLine(); ShowHelpMarker("Enable docking when holding Shift only (allows to drop in wider space, reduce visual noise)");
- ImGui::Checkbox("io.ConfigDockingTabBarOnSingleWindows", &io.ConfigDockingTabBarOnSingleWindows);
- ImGui::SameLine(); ShowHelpMarker("Create a docking node and tab-bar on single floating windows.");
+ ImGui::SameLine(); HelpMarker("Enable docking when holding Shift only (allows to drop in wider space, reduce visual noise)");
+ ImGui::Checkbox("io.ConfigDockingAlwaysTabBar", &io.ConfigDockingAlwaysTabBar);
+ ImGui::SameLine(); HelpMarker("Create a docking node and tab-bar on single floating windows.");
ImGui::Checkbox("io.ConfigDockingTransparentPayload", &io.ConfigDockingTransparentPayload);
- ImGui::SameLine(); ShowHelpMarker("Make window or viewport transparent when docking and only display docking boxes on the target viewport. Useful if rendering of multiple viewport cannot be synced. Best used with ConfigViewportsNoAutoMerge.");
+ ImGui::SameLine(); HelpMarker("Make window or viewport transparent when docking and only display docking boxes on the target viewport. Useful if rendering of multiple viewport cannot be synced. Best used with ConfigViewportsNoAutoMerge.");
ImGui::Unindent();
}
ImGui::CheckboxFlags("io.ConfigFlags: ViewportsEnable", (unsigned int *)&io.ConfigFlags, ImGuiConfigFlags_ViewportsEnable);
- ImGui::SameLine(); ShowHelpMarker("[beta] Enable beta multi-viewports support. See ImGuiPlatformIO for details.");
+ ImGui::SameLine(); HelpMarker("[beta] Enable beta multi-viewports support. See ImGuiPlatformIO for details.");
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
ImGui::Indent();
ImGui::Checkbox("io.ConfigViewportsNoAutoMerge", &io.ConfigViewportsNoAutoMerge);
- ImGui::SameLine(); ShowHelpMarker("Set to make all floating imgui windows always create their own viewport. Otherwise, they are merged into the main host viewports when overlapping it.");
+ ImGui::SameLine(); HelpMarker("Set to make all floating imgui windows always create their own viewport. Otherwise, they are merged into the main host viewports when overlapping it.");
ImGui::Checkbox("io.ConfigViewportsNoTaskBarIcon", &io.ConfigViewportsNoTaskBarIcon);
- ImGui::SameLine(); ShowHelpMarker("Toggling this at runtime is normally unsupported (most platform back-ends won't refresh the task bar icon state right away).");
+ ImGui::SameLine(); HelpMarker("Toggling this at runtime is normally unsupported (most platform back-ends won't refresh the task bar icon state right away).");
ImGui::Checkbox("io.ConfigViewportsNoDecoration", &io.ConfigViewportsNoDecoration);
- ImGui::SameLine(); ShowHelpMarker("Toggling this at runtime is normally unsupported (most platform back-ends won't refresh the decoration right away).");
- ImGui::Checkbox("io.ConfigViewportsNoParent", &io.ConfigViewportsNoParent);
- ImGui::SameLine(); ShowHelpMarker("Toggling this at runtime is normally unsupported (most platform back-ends won't refresh the parenting right away).");
+ ImGui::SameLine(); HelpMarker("Toggling this at runtime is normally unsupported (most platform back-ends won't refresh the decoration right away).");
+ ImGui::Checkbox("io.ConfigViewportsNoDefaultParent", &io.ConfigViewportsNoDefaultParent);
+ ImGui::SameLine(); HelpMarker("Toggling this at runtime is normally unsupported (most platform back-ends won't refresh the parenting right away).");
ImGui::Unindent();
}
ImGui::Checkbox("io.ConfigInputTextCursorBlink", &io.ConfigInputTextCursorBlink);
- ImGui::SameLine(); ShowHelpMarker("Set to false to disable blinking cursor, for users who consider it distracting");
+ ImGui::SameLine(); HelpMarker("Set to false to disable blinking cursor, for users who consider it distracting");
ImGui::Checkbox("io.ConfigWindowsResizeFromEdges", &io.ConfigWindowsResizeFromEdges);
- ImGui::SameLine(); ShowHelpMarker("Enable resizing of windows from their edges and from the lower-left corner.\nThis requires (io.BackendFlags & ImGuiBackendFlags_HasMouseCursors) because it needs mouse cursor feedback.");
+ ImGui::SameLine(); HelpMarker("Enable resizing of windows from their edges and from the lower-left corner.\nThis requires (io.BackendFlags & ImGuiBackendFlags_HasMouseCursors) because it needs mouse cursor feedback.");
ImGui::Checkbox("io.ConfigWindowsMoveFromTitleBarOnly", &io.ConfigWindowsMoveFromTitleBarOnly);
ImGui::Checkbox("io.MouseDrawCursor", &io.MouseDrawCursor);
- ImGui::SameLine(); ShowHelpMarker("Instruct Dear ImGui to render a mouse cursor for you. Note that a mouse cursor rendered via your application GPU rendering path will feel more laggy than hardware cursor, but will be more in sync with your other visuals.\n\nSome desktop applications may use both kinds of cursors (e.g. enable software cursor only when resizing/dragging something).");
+ ImGui::SameLine(); HelpMarker("Instruct Dear ImGui to render a mouse cursor for you. Note that a mouse cursor rendered via your application GPU rendering path will feel more laggy than hardware cursor, but will be more in sync with your other visuals.\n\nSome desktop applications may use both kinds of cursors (e.g. enable software cursor only when resizing/dragging something).");
ImGui::TreePop();
ImGui::Separator();
}
if (ImGui::TreeNode("Backend Flags"))
{
- ShowHelpMarker("Those flags are set by the back-ends (imgui_impl_xxx files) to specify their capabilities.");
- ImGuiBackendFlags backend_flags = io.BackendFlags; // Make a local copy to avoid modifying the back-end flags.
+ HelpMarker("Those flags are set by the back-ends (imgui_impl_xxx files) to specify their capabilities.");
+ ImGuiBackendFlags backend_flags = io.BackendFlags; // Make a local copy to avoid modifying actual back-end flags.
ImGui::CheckboxFlags("io.BackendFlags: HasGamepad", (unsigned int *)&backend_flags, ImGuiBackendFlags_HasGamepad);
ImGui::CheckboxFlags("io.BackendFlags: HasMouseCursors", (unsigned int *)&backend_flags, ImGuiBackendFlags_HasMouseCursors);
ImGui::CheckboxFlags("io.BackendFlags: HasSetMousePos", (unsigned int *)&backend_flags, ImGuiBackendFlags_HasSetMousePos);
ImGui::CheckboxFlags("io.BackendFlags: PlatformHasViewports", (unsigned int *)&backend_flags, ImGuiBackendFlags_PlatformHasViewports);
ImGui::CheckboxFlags("io.BackendFlags: HasMouseHoveredViewport", (unsigned int *)&backend_flags, ImGuiBackendFlags_HasMouseHoveredViewport);
+ ImGui::CheckboxFlags("io.BackendFlags: RendererHasVtxOffset", (unsigned int *)&backend_flags, ImGuiBackendFlags_RendererHasVtxOffset);
ImGui::CheckboxFlags("io.BackendFlags: RendererHasViewports", (unsigned int *)&backend_flags, ImGuiBackendFlags_RendererHasViewports);
ImGui::TreePop();
ImGui::Separator();
@@ -411,7 +427,7 @@ void ImGui::ShowDemoWindow(bool* p_open)
if (ImGui::TreeNode("Capture/Logging"))
{
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.");
- ShowHelpMarker("Try opening any of the contents below in this window and then click one of the \"Log To\" button.");
+ HelpMarker("Try opening any of the contents below in this window and then click one of the \"Log To\" button.");
ImGui::LogButtons();
ImGui::TextWrapped("You can also call ImGui::LogText() to output directly to the log without a visual output.");
if (ImGui::Button("Copy \"Hello, world!\" to clipboard"))
@@ -529,17 +545,20 @@ static void ShowDemoWindowWidgets()
const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK", "LLLLLLL", "MMMM", "OOOOOOO" };
static int item_current = 0;
ImGui::Combo("combo", &item_current, items, IM_ARRAYSIZE(items));
- ImGui::SameLine(); ShowHelpMarker("Refer to the \"Combo\" section below for an explanation of the full BeginCombo/EndCombo API, and demonstration of various flags.\n");
+ ImGui::SameLine(); HelpMarker("Refer to the \"Combo\" section below for an explanation of the full BeginCombo/EndCombo API, and demonstration of various flags.\n");
}
{
static char str0[128] = "Hello, world!";
- static int i0 = 123;
ImGui::InputText("input text", str0, IM_ARRAYSIZE(str0));
- ImGui::SameLine(); ShowHelpMarker("USER:\nHold SHIFT or use mouse to select text.\n" "CTRL+Left/Right to word jump.\n" "CTRL+A or double-click to select all.\n" "CTRL+X,CTRL+C,CTRL+V clipboard.\n" "CTRL+Z,CTRL+Y undo/redo.\n" "ESCAPE to revert.\n\nPROGRAMMER:\nYou can use the ImGuiInputTextFlags_CallbackResize facility if you need to wire InputText() to a dynamic string type. See misc/cpp/imgui_stdlib.h for an example (this is not demonstrated in imgui_demo.cpp).");
+ ImGui::SameLine(); HelpMarker("USER:\nHold SHIFT or use mouse to select text.\n" "CTRL+Left/Right to word jump.\n" "CTRL+A or double-click to select all.\n" "CTRL+X,CTRL+C,CTRL+V clipboard.\n" "CTRL+Z,CTRL+Y undo/redo.\n" "ESCAPE to revert.\n\nPROGRAMMER:\nYou can use the ImGuiInputTextFlags_CallbackResize facility if you need to wire InputText() to a dynamic string type. See misc/cpp/imgui_stdlib.h for an example (this is not demonstrated in imgui_demo.cpp).");
+ static char str1[128] = "";
+ ImGui::InputTextWithHint("input text (w/ hint)", "enter text here", str1, IM_ARRAYSIZE(str1));
+
+ static int i0 = 123;
ImGui::InputInt("input int", &i0);
- ImGui::SameLine(); ShowHelpMarker("You can apply arithmetic operators +,*,/ on numerical values.\n e.g. [ 100 ], input \'*2\', result becomes [ 200 ]\nUse +- to subtract.\n");
+ ImGui::SameLine(); HelpMarker("You can apply arithmetic operators +,*,/ on numerical values.\n e.g. [ 100 ], input \'*2\', result becomes [ 200 ]\nUse +- to subtract.\n");
static float f0 = 0.001f;
ImGui::InputFloat("input float", &f0, 0.01f, 1.0f, "%.3f");
@@ -549,7 +568,7 @@ static void ShowDemoWindowWidgets()
static float f1 = 1.e10f;
ImGui::InputFloat("input scientific", &f1, 0.0f, 0.0f, "%e");
- ImGui::SameLine(); ShowHelpMarker("You can input value using the scientific notation,\n e.g. \"1e+8\" becomes \"100000000\".\n");
+ ImGui::SameLine(); HelpMarker("You can input value using the scientific notation,\n e.g. \"1e+8\" becomes \"100000000\".\n");
static float vec4a[4] = { 0.10f, 0.20f, 0.30f, 0.44f };
ImGui::InputFloat3("input float3", vec4a);
@@ -558,7 +577,7 @@ static void ShowDemoWindowWidgets()
{
static int i1 = 50, i2 = 42;
ImGui::DragInt("drag int", &i1, 1);
- ImGui::SameLine(); ShowHelpMarker("Click and drag to edit value.\nHold SHIFT/ALT for faster/slower edit.\nDouble-click or CTRL+click to input value.");
+ ImGui::SameLine(); HelpMarker("Click and drag to edit value.\nHold SHIFT/ALT for faster/slower edit.\nDouble-click or CTRL+click to input value.");
ImGui::DragInt("drag int 0..100", &i2, 1, 0, 100, "%d%%");
@@ -570,20 +589,31 @@ static void ShowDemoWindowWidgets()
{
static int i1=0;
ImGui::SliderInt("slider int", &i1, -1, 3);
- ImGui::SameLine(); ShowHelpMarker("CTRL+click to input value.");
+ ImGui::SameLine(); HelpMarker("CTRL+click to input value.");
static float f1=0.123f, f2=0.0f;
ImGui::SliderFloat("slider float", &f1, 0.0f, 1.0f, "ratio = %.3f");
ImGui::SliderFloat("slider float (curve)", &f2, -10.0f, 10.0f, "%.4f", 2.0f);
+
static float angle = 0.0f;
ImGui::SliderAngle("slider angle", &angle);
+
+ // Using the format string to display a name instead of an integer.
+ // Here we completely omit '%d' from the format string, so it'll only display a name.
+ // This technique can also be used with DragInt().
+ enum Element { Element_Fire, Element_Earth, Element_Air, Element_Water, Element_COUNT };
+ const char* element_names[Element_COUNT] = { "Fire", "Earth", "Air", "Water" };
+ static int current_element = Element_Fire;
+ const char* current_element_name = (current_element >= 0 && current_element < Element_COUNT) ? element_names[current_element] : "Unknown";
+ ImGui::SliderInt("slider enum", ¤t_element, 0, Element_COUNT - 1, current_element_name);
+ ImGui::SameLine(); HelpMarker("Using the format string parameter to display a name instead of the underlying integer.");
}
{
static float col1[3] = { 1.0f,0.0f,0.2f };
static float col2[4] = { 0.4f,0.7f,0.0f,0.5f };
ImGui::ColorEdit3("color 1", col1);
- ImGui::SameLine(); ShowHelpMarker("Click on the colored square to open a color picker.\nClick and hold to use drag and drop.\nRight-click on the colored square to show options.\nCTRL+click on individual component to input value.\n");
+ ImGui::SameLine(); HelpMarker("Click on the colored square to open a color picker.\nClick and hold to use drag and drop.\nRight-click on the colored square to show options.\nCTRL+click on individual component to input value.\n");
ImGui::ColorEdit4("color 2", col2);
}
@@ -595,9 +625,8 @@ static void ShowDemoWindowWidgets()
ImGui::ListBox("listbox\n(single select)", &listbox_item_current, listbox_items, IM_ARRAYSIZE(listbox_items), 4);
//static int listbox_item_current2 = 2;
- //ImGui::PushItemWidth(-1);
+ //ImGui::SetNextItemWidth(-1);
//ImGui::ListBox("##listbox2", &listbox_item_current2, listbox_items, IM_ARRAYSIZE(listbox_items), 4);
- //ImGui::PopItemWidth();
}
ImGui::TreePop();
@@ -614,19 +643,26 @@ static void ShowDemoWindowWidgets()
if (ImGui::TreeNode("Basic trees"))
{
for (int i = 0; i < 5; i++)
+ {
+ // Use SetNextItemOpen() so set the default state of a node to be open.
+ // We could also use TreeNodeEx() with the ImGuiTreeNodeFlags_DefaultOpen flag to achieve the same thing!
+ if (i == 0)
+ ImGui::SetNextItemOpen(true, ImGuiCond_Once);
+
if (ImGui::TreeNode((void*)(intptr_t)i, "Child %d", i))
{
ImGui::Text("blah blah");
ImGui::SameLine();
- if (ImGui::SmallButton("button")) { };
+ if (ImGui::SmallButton("button")) {};
ImGui::TreePop();
}
+ }
ImGui::TreePop();
}
if (ImGui::TreeNode("Advanced, with Selectable nodes"))
{
- 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.");
+ HelpMarker("This is a more typical looking tree with selectable nodes.\nClick to select, CTRL+Click to toggle, click on arrows or double-click to open.");
static bool align_label_with_current_x_position = false;
ImGui::Checkbox("Align label with current X position)", &align_label_with_current_x_position);
ImGui::Text("Hello!");
@@ -639,10 +675,12 @@ static void ShowDemoWindowWidgets()
for (int i = 0; i < 6; i++)
{
// Disable the default open on single-click behavior and pass in Selected flag according to our selection state.
- ImGuiTreeNodeFlags node_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ((selection_mask & (1 << i)) ? ImGuiTreeNodeFlags_Selected : 0);
+ ImGuiTreeNodeFlags node_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick;
+ if (selection_mask & (1 << i))
+ node_flags |= ImGuiTreeNodeFlags_Selected;
if (i < 3)
{
- // Node
+ // Items 0..2 are Tree Node
bool node_open = ImGui::TreeNodeEx((void*)(intptr_t)i, node_flags, "Selectable Node %d", i);
if (ImGui::IsItemClicked())
node_clicked = i;
@@ -654,7 +692,9 @@ static void ShowDemoWindowWidgets()
}
else
{
- // 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().
+ // Items 3..5 are Tree Leaves
+ // The only reason we use TreeNode at all is to allow selection of the leaf.
+ // Otherwise we can use BulletText() or advance the cursor by GetTreeNodeToLabelSpacing() and call Text().
node_flags |= ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen; // ImGuiTreeNodeFlags_Bullet
ImGui::TreeNodeEx((void*)(intptr_t)i, node_flags, "Selectable Leaf %d", i);
if (ImGui::IsItemClicked())
@@ -680,7 +720,7 @@ static void ShowDemoWindowWidgets()
if (ImGui::TreeNode("Collapsing Headers"))
{
static bool closable_group = true;
- ImGui::Checkbox("Enable extra group", &closable_group);
+ ImGui::Checkbox("Show 2nd header", &closable_group);
if (ImGui::CollapsingHeader("Header"))
{
ImGui::Text("IsItemHovered: %d", ImGui::IsItemHovered());
@@ -713,7 +753,7 @@ static void ShowDemoWindowWidgets()
ImGui::TextColored(ImVec4(1.0f,0.0f,1.0f,1.0f), "Pink");
ImGui::TextColored(ImVec4(1.0f,1.0f,0.0f,1.0f), "Yellow");
ImGui::TextDisabled("Disabled");
- ImGui::SameLine(); ShowHelpMarker("The TextDisabled color is stored in ImGuiStyle.");
+ ImGui::SameLine(); HelpMarker("The TextDisabled color is stored in ImGuiStyle.");
ImGui::TreePop();
}
@@ -774,7 +814,7 @@ static void ShowDemoWindowWidgets()
// Here we are grabbing the font texture because that's the only one we have access to inside the demo code.
// Remember that ImTextureID is just storage for whatever you want it to be, it is essentially a value that will be passed to the render function inside the ImDrawCmd structure.
// If you use one of the default imgui_impl_XXXX.cpp renderer, they all have comments at the top of their file to specify what they expect to be stored in ImTextureID.
- // (for example, the imgui_impl_dx11.cpp renderer expect a 'ID3D11ShaderResourceView*' pointer. The imgui_impl_glfw_gl3.cpp renderer expect a GLuint OpenGL texture identifier etc.)
+ // (for example, the imgui_impl_dx11.cpp renderer expect a 'ID3D11ShaderResourceView*' pointer. The imgui_impl_opengl3.cpp renderer expect a GLuint OpenGL texture identifier etc.)
// If you decided that ImTextureID = MyEngineTexture*, then you can pass your MyEngineTexture* pointers to ImGui::Image(), and gather width/height through your own functions, etc.
// Using ShowMetricsWindow() as a "debugger" to inspect the draw data that are being passed to your render will help you debug issues if you are confused about this.
// Consider using the lower-level ImDrawList::AddImage() API, via ImGui::GetWindowDrawList()->AddImage().
@@ -784,7 +824,7 @@ static void ShowDemoWindowWidgets()
ImGui::Text("%.0fx%.0f", my_tex_w, my_tex_h);
ImVec2 pos = ImGui::GetCursorScreenPos();
- ImGui::Image(my_tex_id, ImVec2(my_tex_w, my_tex_h), ImVec2(0,0), ImVec2(1,1), ImColor(255,255,255,255), ImColor(255,255,255,128));
+ ImGui::Image(my_tex_id, ImVec2(my_tex_w, my_tex_h), ImVec2(0,0), ImVec2(1,1), ImVec4(1.0f,1.0f,1.0f,1.0f), ImVec4(1.0f,1.0f,1.0f,0.5f));
if (ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
@@ -796,7 +836,7 @@ static void ShowDemoWindowWidgets()
ImGui::Text("Max: (%.2f, %.2f)", region_x + region_sz, region_y + region_sz);
ImVec2 uv0 = ImVec2((region_x) / my_tex_w, (region_y) / my_tex_h);
ImVec2 uv1 = ImVec2((region_x + region_sz) / my_tex_w, (region_y + region_sz) / my_tex_h);
- ImGui::Image(my_tex_id, ImVec2(region_sz * zoom, region_sz * zoom), uv0, uv1, ImColor(255,255,255,255), ImColor(255,255,255,128));
+ ImGui::Image(my_tex_id, ImVec2(region_sz * zoom, region_sz * zoom), uv0, uv1, ImVec4(1.0f, 1.0f, 1.0f, 1.0f), ImVec4(1.0f, 1.0f, 1.0f, 0.5f));
ImGui::EndTooltip();
}
ImGui::TextWrapped("And now some textured buttons..");
@@ -805,7 +845,7 @@ static void ShowDemoWindowWidgets()
{
ImGui::PushID(i);
int frame_padding = -1 + i; // -1 = uses default padding
- if (ImGui::ImageButton(my_tex_id, ImVec2(32,32), ImVec2(0,0), ImVec2(32.0f/my_tex_w,32/my_tex_h), frame_padding, ImColor(0,0,0,255)))
+ if (ImGui::ImageButton(my_tex_id, ImVec2(32,32), ImVec2(0,0), ImVec2(32.0f/my_tex_w,32/my_tex_h), frame_padding, ImVec4(0.0f,0.0f,0.0f,1.0f)))
pressed_count += 1;
ImGui::PopID();
ImGui::SameLine();
@@ -820,6 +860,7 @@ static void ShowDemoWindowWidgets()
// Expose flags as checkbox for the demo
static ImGuiComboFlags flags = 0;
ImGui::CheckboxFlags("ImGuiComboFlags_PopupAlignLeft", (unsigned int*)&flags, ImGuiComboFlags_PopupAlignLeft);
+ ImGui::SameLine(); HelpMarker("Only makes a difference if the popup is larger than the combo");
if (ImGui::CheckboxFlags("ImGuiComboFlags_NoArrowButton", (unsigned int*)&flags, ImGuiComboFlags_NoArrowButton))
flags &= ~ImGuiComboFlags_NoPreview; // Clear the other flag, as we cannot combine both
if (ImGui::CheckboxFlags("ImGuiComboFlags_NoPreview", (unsigned int*)&flags, ImGuiComboFlags_NoPreview))
@@ -890,7 +931,7 @@ static void ShowDemoWindowWidgets()
}
if (ImGui::TreeNode("Selection State: Multiple Selection"))
{
- ShowHelpMarker("Hold CTRL and click to select multiple items.");
+ HelpMarker("Hold CTRL and click to select multiple items.");
static bool selection[5] = { false, false, false, false, false };
for (int n = 0; n < 5; n++)
{
@@ -948,52 +989,117 @@ static void ShowDemoWindowWidgets()
}
ImGui::TreePop();
}
+ if (ImGui::TreeNode("Alignment"))
+ {
+ HelpMarker("Alignment applies when a selectable is larger than its text content.\nBy default, Selectables uses style.SelectableTextAlign but it can be overriden on a per-item basis using PushStyleVar().");
+ static bool selected[3*3] = { true, false, true, false, true, false, true, false, true };
+ for (int y = 0; y < 3; y++)
+ {
+ for (int x = 0; x < 3; x++)
+ {
+ ImVec2 alignment = ImVec2((float)x / 2.0f, (float)y / 2.0f);
+ char name[32];
+ sprintf(name, "(%.1f,%.1f)", alignment.x, alignment.y);
+ if (x > 0) ImGui::SameLine();
+ ImGui::PushStyleVar(ImGuiStyleVar_SelectableTextAlign, alignment);
+ ImGui::Selectable(name, &selected[3*y+x], ImGuiSelectableFlags_None, ImVec2(80,80));
+ ImGui::PopStyleVar();
+ }
+ }
+ ImGui::TreePop();
+ }
ImGui::TreePop();
}
- if (ImGui::TreeNode("Filtered Text Input"))
+ if (ImGui::TreeNode("Text Input"))
{
- static char buf1[64] = ""; ImGui::InputText("default", buf1, 64);
- static char buf2[64] = ""; ImGui::InputText("decimal", buf2, 64, ImGuiInputTextFlags_CharsDecimal);
- static char buf3[64] = ""; ImGui::InputText("hexadecimal", buf3, 64, ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase);
- static char buf4[64] = ""; ImGui::InputText("uppercase", buf4, 64, ImGuiInputTextFlags_CharsUppercase);
- static char buf5[64] = ""; ImGui::InputText("no blank", buf5, 64, ImGuiInputTextFlags_CharsNoBlank);
- struct TextFilters { static int FilterImGuiLetters(ImGuiInputTextCallbackData* data) { if (data->EventChar < 256 && strchr("imgui", (char)data->EventChar)) return 0; return 1; } };
- static char buf6[64] = ""; ImGui::InputText("\"imgui\" letters", buf6, 64, ImGuiInputTextFlags_CallbackCharFilter, TextFilters::FilterImGuiLetters);
-
- ImGui::Text("Password input");
- static char bufpass[64] = "password123";
- ImGui::InputText("password", bufpass, 64, ImGuiInputTextFlags_Password | ImGuiInputTextFlags_CharsNoBlank);
- ImGui::SameLine(); ShowHelpMarker("Display all characters as '*'.\nDisable clipboard cut and copy.\nDisable logging.\n");
- ImGui::InputText("password (clear)", bufpass, 64, ImGuiInputTextFlags_CharsNoBlank);
+ if (ImGui::TreeNode("Multi-line Text Input"))
+ {
+ // Note: we are using a fixed-sized buffer for simplicity here. See ImGuiInputTextFlags_CallbackResize
+ // and the code in misc/cpp/imgui_stdlib.h for how to setup InputText() for dynamically resizing strings.
+ static char text[1024 * 16] =
+ "/*\n"
+ " The Pentium F00F bug, shorthand for F0 0F C7 C8,\n"
+ " the hexadecimal encoding of one offending instruction,\n"
+ " more formally, the invalid operand with locked CMPXCHG8B\n"
+ " instruction bug, is a design flaw in the majority of\n"
+ " Intel Pentium, Pentium MMX, and Pentium OverDrive\n"
+ " processors (all in the P5 microarchitecture).\n"
+ "*/\n\n"
+ "label:\n"
+ "\tlock cmpxchg8b eax\n";
+
+ static ImGuiInputTextFlags flags = ImGuiInputTextFlags_AllowTabInput;
+ HelpMarker("You can use the ImGuiInputTextFlags_CallbackResize facility if you need to wire InputTextMultiline() to a dynamic string type. See misc/cpp/imgui_stdlib.h for an example. (This is not demonstrated in imgui_demo.cpp)");
+ ImGui::CheckboxFlags("ImGuiInputTextFlags_ReadOnly", (unsigned int*)&flags, ImGuiInputTextFlags_ReadOnly);
+ ImGui::CheckboxFlags("ImGuiInputTextFlags_AllowTabInput", (unsigned int*)&flags, ImGuiInputTextFlags_AllowTabInput);
+ ImGui::CheckboxFlags("ImGuiInputTextFlags_CtrlEnterForNewLine", (unsigned int*)&flags, ImGuiInputTextFlags_CtrlEnterForNewLine);
+ ImGui::InputTextMultiline("##source", text, IM_ARRAYSIZE(text), ImVec2(-FLT_MIN, ImGui::GetTextLineHeight() * 16), flags);
+ ImGui::TreePop();
+ }
- ImGui::TreePop();
- }
+ if (ImGui::TreeNode("Filtered Text Input"))
+ {
+ static char buf1[64] = ""; ImGui::InputText("default", buf1, 64);
+ static char buf2[64] = ""; ImGui::InputText("decimal", buf2, 64, ImGuiInputTextFlags_CharsDecimal);
+ static char buf3[64] = ""; ImGui::InputText("hexadecimal", buf3, 64, ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase);
+ static char buf4[64] = ""; ImGui::InputText("uppercase", buf4, 64, ImGuiInputTextFlags_CharsUppercase);
+ static char buf5[64] = ""; ImGui::InputText("no blank", buf5, 64, ImGuiInputTextFlags_CharsNoBlank);
+ struct TextFilters { static int FilterImGuiLetters(ImGuiInputTextCallbackData* data) { if (data->EventChar < 256 && strchr("imgui", (char)data->EventChar)) return 0; return 1; } };
+ static char buf6[64] = ""; ImGui::InputText("\"imgui\" letters", buf6, 64, ImGuiInputTextFlags_CallbackCharFilter, TextFilters::FilterImGuiLetters);
+
+ ImGui::Text("Password input");
+ static char bufpass[64] = "password123";
+ ImGui::InputText("password", bufpass, 64, ImGuiInputTextFlags_Password | ImGuiInputTextFlags_CharsNoBlank);
+ ImGui::SameLine(); HelpMarker("Display all characters as '*'.\nDisable clipboard cut and copy.\nDisable logging.\n");
+ ImGui::InputTextWithHint("password (w/ hint)", "", bufpass, 64, ImGuiInputTextFlags_Password | ImGuiInputTextFlags_CharsNoBlank);
+ ImGui::InputText("password (clear)", bufpass, 64, ImGuiInputTextFlags_CharsNoBlank);
+ ImGui::TreePop();
+ }
+
+ if (ImGui::TreeNode("Resize Callback"))
+ {
+ // If you have a custom string type you would typically create a ImGui::InputText() wrapper than takes your type as input.
+ // See misc/cpp/imgui_stdlib.h and .cpp for an implementation of this using std::string.
+ HelpMarker("Demonstrate using ImGuiInputTextFlags_CallbackResize to wire your resizable string type to InputText().\n\nSee misc/cpp/imgui_stdlib.h for an implementation of this for std::string.");
+ struct Funcs
+ {
+ static int MyResizeCallback(ImGuiInputTextCallbackData* data)
+ {
+ if (data->EventFlag == ImGuiInputTextFlags_CallbackResize)
+ {
+ ImVector* my_str = (ImVector*)data->UserData;
+ IM_ASSERT(my_str->begin() == data->Buf);
+ my_str->resize(data->BufSize); // NB: On resizing calls, generally data->BufSize == data->BufTextLen + 1
+ data->Buf = my_str->begin();
+ }
+ return 0;
+ }
+
+ // Tip: Because ImGui:: is a namespace you would typicall add your own function into the namespace in your own source files.
+ // For example, you may add a function called ImGui::InputText(const char* label, MyString* my_str).
+ static bool MyInputTextMultiline(const char* label, ImVector* my_str, const ImVec2& size = ImVec2(0, 0), ImGuiInputTextFlags flags = 0)
+ {
+ IM_ASSERT((flags & ImGuiInputTextFlags_CallbackResize) == 0);
+ return ImGui::InputTextMultiline(label, my_str->begin(), (size_t)my_str->size(), size, flags | ImGuiInputTextFlags_CallbackResize, Funcs::MyResizeCallback, (void*)my_str);
+ }
+ };
+
+ // For this demo we are using ImVector as a string container.
+ // Note that because we need to store a terminating zero character, our size/capacity are 1 more than usually reported by a typical string class.
+ static ImVector my_str;
+ if (my_str.empty())
+ my_str.push_back(0);
+ Funcs::MyInputTextMultiline("##MyStr", &my_str, ImVec2(-FLT_MIN, ImGui::GetTextLineHeight() * 16));
+ ImGui::Text("Data: %p\nSize: %d\nCapacity: %d", (void*)my_str.begin(), my_str.size(), my_str.capacity());
+ ImGui::TreePop();
+ }
- if (ImGui::TreeNode("Multi-line Text Input"))
- {
- // Note: we are using a fixed-sized buffer for simplicity here. See ImGuiInputTextFlags_CallbackResize
- // and the code in misc/cpp/imgui_stdlib.h for how to setup InputText() for dynamically resizing strings.
- static bool read_only = false;
- static char text[1024*16] =
- "/*\n"
- " The Pentium F00F bug, shorthand for F0 0F C7 C8,\n"
- " the hexadecimal encoding of one offending instruction,\n"
- " more formally, the invalid operand with locked CMPXCHG8B\n"
- " instruction bug, is a design flaw in the majority of\n"
- " Intel Pentium, Pentium MMX, and Pentium OverDrive\n"
- " processors (all in the P5 microarchitecture).\n"
- "*/\n\n"
- "label:\n"
- "\tlock cmpxchg8b eax\n";
-
- ShowHelpMarker("You can use the ImGuiInputTextFlags_CallbackResize facility if you need to wire InputTextMultiline() to a dynamic string type. See misc/cpp/imgui_stdlib.h for an example. (This is not demonstrated in imgui_demo.cpp)");
- ImGui::Checkbox("Read-only", &read_only);
- ImGuiInputTextFlags flags = ImGuiInputTextFlags_AllowTabInput | (read_only ? ImGuiInputTextFlags_ReadOnly : 0);
- ImGui::InputTextMultiline("##source", text, IM_ARRAYSIZE(text), ImVec2(-1.0f, ImGui::GetTextLineHeight() * 16), flags);
ImGui::TreePop();
}
+ // Plot/Graph widgets are currently fairly limited.
+ // Consider writing your own plotting widget, or using a third-party one (see "Wiki->Useful Widgets", or github.com/ocornut/imgui/issues/2747)
if (ImGui::TreeNode("Plots Widgets"))
{
static bool animate = true;
@@ -1017,7 +1123,18 @@ static void ShowDemoWindowWidgets()
phase += 0.10f*values_offset;
refresh_time += 1.0f/60.0f;
}
- ImGui::PlotLines("Lines", values, IM_ARRAYSIZE(values), values_offset, "avg 0.0", -1.0f, 1.0f, ImVec2(0,80));
+
+ // Plots can display overlay texts
+ // (in this example, we will display an average value)
+ {
+ float average = 0.0f;
+ for (int n = 0; n < IM_ARRAYSIZE(values); n++)
+ average += values[n];
+ average /= (float)IM_ARRAYSIZE(values);
+ char overlay[32];
+ sprintf(overlay, "avg %f", average);
+ ImGui::PlotLines("Lines", values, IM_ARRAYSIZE(values), values_offset, overlay, -1.0f, 1.0f, ImVec2(0,80));
+ }
ImGui::PlotHistogram("Histogram", arr, IM_ARRAYSIZE(arr), 0, NULL, 0.0f, 1.0f, ImVec2(0,80));
// Use functions to generate output
@@ -1029,7 +1146,8 @@ static void ShowDemoWindowWidgets()
};
static int func_type = 0, display_count = 70;
ImGui::Separator();
- ImGui::PushItemWidth(100); ImGui::Combo("func", &func_type, "Sin\0Saw\0"); ImGui::PopItemWidth();
+ ImGui::SetNextItemWidth(100);
+ ImGui::Combo("func", &func_type, "Sin\0Saw\0");
ImGui::SameLine();
ImGui::SliderInt("Sample count", &display_count, 1, 400);
float (*func)(void*, int) = (func_type == 0) ? Funcs::Sin : Funcs::Saw;
@@ -1046,7 +1164,8 @@ static void ShowDemoWindowWidgets()
if (progress <= -0.1f) { progress = -0.1f; progress_dir *= -1.0f; }
}
- // Typically we would use ImVec2(-1.0f,0.0f) to use all available width, or ImVec2(width,0.0f) for a specified width. ImVec2(0.0f,0.0f) uses ItemWidth.
+ // Typically we would use ImVec2(-1.0f,0.0f) or ImVec2(-FLT_MIN,0.0f) to use all available width,
+ // or ImVec2(width,0.0f) for a specified width. ImVec2(0.0f,0.0f) uses ItemWidth.
ImGui::ProgressBar(progress, ImVec2(0.0f,0.0f));
ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
ImGui::Text("Progress Bar");
@@ -1060,7 +1179,7 @@ static void ShowDemoWindowWidgets()
if (ImGui::TreeNode("Color/Picker Widgets"))
{
- static ImVec4 color = ImColor(114, 144, 154, 200);
+ static ImVec4 color = ImVec4(114.0f/255.0f, 144.0f/255.0f, 154.0f/255.0f, 200.0f/255.0f);
static bool alpha_preview = true;
static bool alpha_half_preview = false;
@@ -1070,22 +1189,22 @@ static void ShowDemoWindowWidgets()
ImGui::Checkbox("With Alpha Preview", &alpha_preview);
ImGui::Checkbox("With Half Alpha Preview", &alpha_half_preview);
ImGui::Checkbox("With Drag and Drop", &drag_and_drop);
- ImGui::Checkbox("With Options Menu", &options_menu); ImGui::SameLine(); ShowHelpMarker("Right-click on the individual color widget to show options.");
- ImGui::Checkbox("With HDR", &hdr); ImGui::SameLine(); ShowHelpMarker("Currently all this does is to lift the 0..1 limits on dragging widgets.");
- int misc_flags = (hdr ? ImGuiColorEditFlags_HDR : 0) | (drag_and_drop ? 0 : ImGuiColorEditFlags_NoDragDrop) | (alpha_half_preview ? ImGuiColorEditFlags_AlphaPreviewHalf : (alpha_preview ? ImGuiColorEditFlags_AlphaPreview : 0)) | (options_menu ? 0 : ImGuiColorEditFlags_NoOptions);
+ ImGui::Checkbox("With Options Menu", &options_menu); ImGui::SameLine(); HelpMarker("Right-click on the individual color widget to show options.");
+ ImGui::Checkbox("With HDR", &hdr); ImGui::SameLine(); HelpMarker("Currently all this does is to lift the 0..1 limits on dragging widgets.");
+ ImGuiColorEditFlags misc_flags = (hdr ? ImGuiColorEditFlags_HDR : 0) | (drag_and_drop ? 0 : ImGuiColorEditFlags_NoDragDrop) | (alpha_half_preview ? ImGuiColorEditFlags_AlphaPreviewHalf : (alpha_preview ? ImGuiColorEditFlags_AlphaPreview : 0)) | (options_menu ? 0 : ImGuiColorEditFlags_NoOptions);
ImGui::Text("Color widget:");
- ImGui::SameLine(); ShowHelpMarker("Click on the colored square to open a color picker.\nCTRL+click on individual component to input value.\n");
+ ImGui::SameLine(); HelpMarker("Click on the colored square to open a color picker.\nCTRL+click on individual component to input value.\n");
ImGui::ColorEdit3("MyColor##1", (float*)&color, misc_flags);
ImGui::Text("Color widget HSV with Alpha:");
- ImGui::ColorEdit4("MyColor##2", (float*)&color, ImGuiColorEditFlags_HSV | misc_flags);
+ ImGui::ColorEdit4("MyColor##2", (float*)&color, ImGuiColorEditFlags_DisplayHSV | misc_flags);
ImGui::Text("Color widget with Float Display:");
ImGui::ColorEdit4("MyColor##2f", (float*)&color, ImGuiColorEditFlags_Float | misc_flags);
ImGui::Text("Color button with Picker:");
- ImGui::SameLine(); ShowHelpMarker("With the ImGuiColorEditFlags_NoInputs flag you can hide all the slider/text inputs.\nWith the ImGuiColorEditFlags_NoLabel flag you can pass a non-empty label which will only be used for the tooltip and picker popup.");
+ ImGui::SameLine(); HelpMarker("With the ImGuiColorEditFlags_NoInputs flag you can hide all the slider/text inputs.\nWith the ImGuiColorEditFlags_NoLabel flag you can pass a non-empty label which will only be used for the tooltip and picker popup.");
ImGui::ColorEdit4("MyColor##3", (float*)&color, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel | misc_flags);
ImGui::Text("Color button with Custom Picker Popup:");
@@ -1105,7 +1224,7 @@ static void ShowDemoWindowWidgets()
static ImVec4 backup_color;
bool open_popup = ImGui::ColorButton("MyColor##3b", color, misc_flags);
- ImGui::SameLine();
+ ImGui::SameLine(0, ImGui::GetStyle().ItemInnerSpacing.x);
open_popup |= ImGui::Button("Palette");
if (open_popup)
{
@@ -1161,7 +1280,7 @@ static void ShowDemoWindowWidgets()
static bool side_preview = true;
static bool ref_color = false;
static ImVec4 ref_color_v(1.0f,0.0f,1.0f,0.5f);
- static int inputs_mode = 2;
+ static int display_mode = 0;
static int picker_mode = 0;
ImGui::Checkbox("With Alpha", &alpha);
ImGui::Checkbox("With Alpha Bar", &alpha_bar);
@@ -1176,28 +1295,39 @@ static void ShowDemoWindowWidgets()
ImGui::ColorEdit4("##RefColor", &ref_color_v.x, ImGuiColorEditFlags_NoInputs | misc_flags);
}
}
- ImGui::Combo("Inputs Mode", &inputs_mode, "All Inputs\0No Inputs\0RGB Input\0HSV Input\0HEX Input\0");
+ ImGui::Combo("Display Mode", &display_mode, "Auto/Current\0None\0RGB Only\0HSV Only\0Hex Only\0");
+ ImGui::SameLine(); HelpMarker("ColorEdit defaults to displaying RGB inputs if you don't specify a display mode, but the user can change it with a right-click.\n\nColorPicker defaults to displaying RGB+HSV+Hex if you don't specify a display mode.\n\nYou can change the defaults using SetColorEditOptions().");
ImGui::Combo("Picker Mode", &picker_mode, "Auto/Current\0Hue bar + SV rect\0Hue wheel + SV triangle\0");
- ImGui::SameLine(); ShowHelpMarker("User can right-click the picker to change mode.");
+ ImGui::SameLine(); HelpMarker("User can right-click the picker to change mode.");
ImGuiColorEditFlags flags = misc_flags;
- if (!alpha) flags |= ImGuiColorEditFlags_NoAlpha; // This is by default if you call ColorPicker3() instead of ColorPicker4()
- if (alpha_bar) flags |= ImGuiColorEditFlags_AlphaBar;
- if (!side_preview) flags |= ImGuiColorEditFlags_NoSidePreview;
- if (picker_mode == 1) flags |= ImGuiColorEditFlags_PickerHueBar;
- if (picker_mode == 2) flags |= ImGuiColorEditFlags_PickerHueWheel;
- if (inputs_mode == 1) flags |= ImGuiColorEditFlags_NoInputs;
- if (inputs_mode == 2) flags |= ImGuiColorEditFlags_RGB;
- if (inputs_mode == 3) flags |= ImGuiColorEditFlags_HSV;
- if (inputs_mode == 4) flags |= ImGuiColorEditFlags_HEX;
+ if (!alpha) flags |= ImGuiColorEditFlags_NoAlpha; // This is by default if you call ColorPicker3() instead of ColorPicker4()
+ if (alpha_bar) flags |= ImGuiColorEditFlags_AlphaBar;
+ if (!side_preview) flags |= ImGuiColorEditFlags_NoSidePreview;
+ if (picker_mode == 1) flags |= ImGuiColorEditFlags_PickerHueBar;
+ if (picker_mode == 2) flags |= ImGuiColorEditFlags_PickerHueWheel;
+ if (display_mode == 1) flags |= ImGuiColorEditFlags_NoInputs; // Disable all RGB/HSV/Hex displays
+ if (display_mode == 2) flags |= ImGuiColorEditFlags_DisplayRGB; // Override display mode
+ if (display_mode == 3) flags |= ImGuiColorEditFlags_DisplayHSV;
+ if (display_mode == 4) flags |= ImGuiColorEditFlags_DisplayHex;
ImGui::ColorPicker4("MyColor##4", (float*)&color, flags, ref_color ? &ref_color_v.x : NULL);
ImGui::Text("Programmatically set defaults:");
- ImGui::SameLine(); ShowHelpMarker("SetColorEditOptions() is designed to allow you to set boot-time default.\nWe don't have Push/Pop functions because you can force options on a per-widget basis if needed, and the user can change non-forced ones with the options menu.\nWe don't have a getter to avoid encouraging you to persistently save values that aren't forward-compatible.");
+ ImGui::SameLine(); HelpMarker("SetColorEditOptions() is designed to allow you to set boot-time default.\nWe don't have Push/Pop functions because you can force options on a per-widget basis if needed, and the user can change non-forced ones with the options menu.\nWe don't have a getter to avoid encouraging you to persistently save values that aren't forward-compatible.");
if (ImGui::Button("Default: Uint8 + HSV + Hue Bar"))
- ImGui::SetColorEditOptions(ImGuiColorEditFlags_Uint8 | ImGuiColorEditFlags_HSV | ImGuiColorEditFlags_PickerHueBar);
+ ImGui::SetColorEditOptions(ImGuiColorEditFlags_Uint8 | ImGuiColorEditFlags_DisplayHSV | ImGuiColorEditFlags_PickerHueBar);
if (ImGui::Button("Default: Float + HDR + Hue Wheel"))
ImGui::SetColorEditOptions(ImGuiColorEditFlags_Float | ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_PickerHueWheel);
+ // HSV encoded support (to avoid RGB<>HSV round trips and singularities when S==0 or V==0)
+ static ImVec4 color_stored_as_hsv(0.23f, 1.0f, 1.0f, 1.0f);
+ ImGui::Spacing();
+ ImGui::Text("HSV encoded colors");
+ ImGui::SameLine(); HelpMarker("By default, colors are given to ColorEdit and ColorPicker in RGB, but ImGuiColorEditFlags_InputHSV allows you to store colors as HSV and pass them to ColorEdit and ColorPicker as HSV. This comes with the added benefit that you can manipulate hue values with the picker even when saturation or value are zero.");
+ ImGui::Text("Color widget with InputHSV:");
+ ImGui::ColorEdit4("HSV shown as RGB##1", (float*)&color_stored_as_hsv, ImGuiColorEditFlags_DisplayRGB | ImGuiColorEditFlags_InputHSV | ImGuiColorEditFlags_Float);
+ ImGui::ColorEdit4("HSV shown as HSV##1", (float*)&color_stored_as_hsv, ImGuiColorEditFlags_DisplayHSV | ImGuiColorEditFlags_InputHSV | ImGuiColorEditFlags_Float);
+ ImGui::DragFloat4("Raw HSV values", (float*)&color_stored_as_hsv, 0.01f, 0.0f, 1.0f);
+
ImGui::TreePop();
}
@@ -1231,6 +1361,10 @@ static void ShowDemoWindowWidgets()
ImS64 LLONG_MAX = 9223372036854775807LL;
ImU64 ULLONG_MAX = (2ULL * 9223372036854775807LL + 1);
#endif
+ const char s8_zero = 0, s8_one = 1, s8_fifty = 50, s8_min = -128, s8_max = 127;
+ const ImU8 u8_zero = 0, u8_one = 1, u8_fifty = 50, u8_min = 0, u8_max = 255;
+ const short s16_zero = 0, s16_one = 1, s16_fifty = 50, s16_min = -32768, s16_max = 32767;
+ const ImU16 u16_zero = 0, u16_one = 1, u16_fifty = 50, u16_min = 0, u16_max = 65535;
const ImS32 s32_zero = 0, s32_one = 1, s32_fifty = 50, s32_min = INT_MIN/2, s32_max = INT_MAX/2, s32_hi_a = INT_MAX/2 - 100, s32_hi_b = INT_MAX/2;
const ImU32 u32_zero = 0, u32_one = 1, u32_fifty = 50, u32_min = 0, u32_max = UINT_MAX/2, u32_hi_a = UINT_MAX/2 - 100, u32_hi_b = UINT_MAX/2;
const ImS64 s64_zero = 0, s64_one = 1, s64_fifty = 50, s64_min = LLONG_MIN/2, s64_max = LLONG_MAX/2, s64_hi_a = LLONG_MAX/2 - 100, s64_hi_b = LLONG_MAX/2;
@@ -1239,6 +1373,10 @@ static void ShowDemoWindowWidgets()
const double f64_zero = 0., f64_one = 1., f64_lo_a = -1000000000000000.0, f64_hi_a = +1000000000000000.0;
// State
+ static char s8_v = 127;
+ static ImU8 u8_v = 255;
+ static short s16_v = 32767;
+ static ImU16 u16_v = 65535;
static ImS32 s32_v = -1;
static ImU32 u32_v = (ImU32)-1;
static ImS64 s64_v = -1;
@@ -1249,17 +1387,25 @@ static void ShowDemoWindowWidgets()
const float drag_speed = 0.2f;
static bool drag_clamp = false;
ImGui::Text("Drags:");
- ImGui::Checkbox("Clamp integers to 0..50", &drag_clamp); ImGui::SameLine(); ShowHelpMarker("As with every widgets in dear imgui, we never modify values unless there is a user interaction.\nYou can override the clamping limits by using CTRL+Click to input a value.");
+ ImGui::Checkbox("Clamp integers to 0..50", &drag_clamp); ImGui::SameLine(); HelpMarker("As with every widgets in dear imgui, we never modify values unless there is a user interaction.\nYou can override the clamping limits by using CTRL+Click to input a value.");
+ ImGui::DragScalar("drag s8", ImGuiDataType_S8, &s8_v, drag_speed, drag_clamp ? &s8_zero : NULL, drag_clamp ? &s8_fifty : NULL);
+ ImGui::DragScalar("drag u8", ImGuiDataType_U8, &u8_v, drag_speed, drag_clamp ? &u8_zero : NULL, drag_clamp ? &u8_fifty : NULL, "%u ms");
+ ImGui::DragScalar("drag s16", ImGuiDataType_S16, &s16_v, drag_speed, drag_clamp ? &s16_zero : NULL, drag_clamp ? &s16_fifty : NULL);
+ ImGui::DragScalar("drag u16", ImGuiDataType_U16, &u16_v, drag_speed, drag_clamp ? &u16_zero : NULL, drag_clamp ? &u16_fifty : NULL, "%u ms");
ImGui::DragScalar("drag s32", ImGuiDataType_S32, &s32_v, drag_speed, drag_clamp ? &s32_zero : NULL, drag_clamp ? &s32_fifty : NULL);
ImGui::DragScalar("drag u32", ImGuiDataType_U32, &u32_v, drag_speed, drag_clamp ? &u32_zero : NULL, drag_clamp ? &u32_fifty : NULL, "%u ms");
ImGui::DragScalar("drag s64", ImGuiDataType_S64, &s64_v, drag_speed, drag_clamp ? &s64_zero : NULL, drag_clamp ? &s64_fifty : NULL);
ImGui::DragScalar("drag u64", ImGuiDataType_U64, &u64_v, drag_speed, drag_clamp ? &u64_zero : NULL, drag_clamp ? &u64_fifty : NULL);
ImGui::DragScalar("drag float", ImGuiDataType_Float, &f32_v, 0.005f, &f32_zero, &f32_one, "%f", 1.0f);
- ImGui::DragScalar("drag float ^2", ImGuiDataType_Float, &f32_v, 0.005f, &f32_zero, &f32_one, "%f", 2.0f); ImGui::SameLine(); ShowHelpMarker("You can use the 'power' parameter to increase tweaking precision on one side of the range.");
+ ImGui::DragScalar("drag float ^2", ImGuiDataType_Float, &f32_v, 0.005f, &f32_zero, &f32_one, "%f", 2.0f); ImGui::SameLine(); HelpMarker("You can use the 'power' parameter to increase tweaking precision on one side of the range.");
ImGui::DragScalar("drag double", ImGuiDataType_Double, &f64_v, 0.0005f, &f64_zero, NULL, "%.10f grams", 1.0f);
ImGui::DragScalar("drag double ^2", ImGuiDataType_Double, &f64_v, 0.0005f, &f64_zero, &f64_one, "0 < %.10f < 1", 2.0f);
ImGui::Text("Sliders");
+ ImGui::SliderScalar("slider s8 full", ImGuiDataType_S8, &s8_v, &s8_min, &s8_max, "%d");
+ ImGui::SliderScalar("slider u8 full", ImGuiDataType_U8, &u8_v, &u8_min, &u8_max, "%u");
+ ImGui::SliderScalar("slider s16 full", ImGuiDataType_S16, &s16_v, &s16_min, &s16_max, "%d");
+ ImGui::SliderScalar("slider u16 full", ImGuiDataType_U16, &u16_v, &u16_min, &u16_max, "%u");
ImGui::SliderScalar("slider s32 low", ImGuiDataType_S32, &s32_v, &s32_zero, &s32_fifty,"%d");
ImGui::SliderScalar("slider s32 high", ImGuiDataType_S32, &s32_v, &s32_hi_a, &s32_hi_b, "%d");
ImGui::SliderScalar("slider s32 full", ImGuiDataType_S32, &s32_v, &s32_min, &s32_max, "%d");
@@ -1282,6 +1428,10 @@ static void ShowDemoWindowWidgets()
static bool inputs_step = true;
ImGui::Text("Inputs");
ImGui::Checkbox("Show step buttons", &inputs_step);
+ ImGui::InputScalar("input s8", ImGuiDataType_S8, &s8_v, inputs_step ? &s8_one : NULL, NULL, "%d");
+ ImGui::InputScalar("input u8", ImGuiDataType_U8, &u8_v, inputs_step ? &u8_one : NULL, NULL, "%u");
+ ImGui::InputScalar("input s16", ImGuiDataType_S16, &s16_v, inputs_step ? &s16_one : NULL, NULL, "%d");
+ ImGui::InputScalar("input u16", ImGuiDataType_U16, &u16_v, inputs_step ? &u16_one : NULL, NULL, "%u");
ImGui::InputScalar("input s32", ImGuiDataType_S32, &s32_v, inputs_step ? &s32_one : NULL, NULL, "%d");
ImGui::InputScalar("input s32 hex", ImGuiDataType_S32, &s32_v, inputs_step ? &s32_one : NULL, NULL, "%08X", ImGuiInputTextFlags_CharsHexadecimal);
ImGui::InputScalar("input u32", ImGuiDataType_U32, &u32_v, inputs_step ? &u32_one : NULL, NULL, "%u");
@@ -1473,20 +1623,23 @@ static void ShowDemoWindowWidgets()
static int item_type = 1;
static bool b = false;
static float col4f[4] = { 1.0f, 0.5, 0.0f, 1.0f };
- ImGui::RadioButton("Text", &item_type, 0);
- ImGui::RadioButton("Button", &item_type, 1);
- ImGui::RadioButton("CheckBox", &item_type, 2);
- ImGui::RadioButton("SliderFloat", &item_type, 3);
- ImGui::RadioButton("ColorEdit4", &item_type, 4);
- ImGui::RadioButton("ListBox", &item_type, 5);
- ImGui::Separator();
+ static char str[16] = {};
+ ImGui::Combo("Item Type", &item_type, "Text\0Button\0Button (w/ repeat)\0Checkbox\0SliderFloat\0InputText\0InputFloat\0InputFloat3\0ColorEdit4\0MenuItem\0TreeNode (w/ double-click)\0ListBox\0");
+ ImGui::SameLine();
+ HelpMarker("Testing how various types of items are interacting with the IsItemXXX functions.");
bool ret = false;
if (item_type == 0) { ImGui::Text("ITEM: Text"); } // Testing text items with no identifier/interaction
if (item_type == 1) { ret = ImGui::Button("ITEM: Button"); } // Testing button
- if (item_type == 2) { ret = ImGui::Checkbox("ITEM: CheckBox", &b); } // Testing checkbox
- if (item_type == 3) { ret = ImGui::SliderFloat("ITEM: SliderFloat", &col4f[0], 0.0f, 1.0f); } // Testing basic item
- if (item_type == 4) { ret = ImGui::ColorEdit4("ITEM: ColorEdit4", col4f); } // Testing multi-component items (IsItemXXX flags are reported merged)
- if (item_type == 5) { const char* items[] = { "Apple", "Banana", "Cherry", "Kiwi" }; static int current = 1; ret = ImGui::ListBox("ITEM: ListBox", ¤t, items, IM_ARRAYSIZE(items), IM_ARRAYSIZE(items)); }
+ if (item_type == 2) { ImGui::PushButtonRepeat(true); ret = ImGui::Button("ITEM: Button"); ImGui::PopButtonRepeat(); } // Testing button (with repeater)
+ if (item_type == 3) { ret = ImGui::Checkbox("ITEM: Checkbox", &b); } // Testing checkbox
+ if (item_type == 4) { ret = ImGui::SliderFloat("ITEM: SliderFloat", &col4f[0], 0.0f, 1.0f); } // Testing basic item
+ if (item_type == 5) { ret = ImGui::InputText("ITEM: InputText", &str[0], IM_ARRAYSIZE(str)); } // Testing input text (which handles tabbing)
+ if (item_type == 6) { ret = ImGui::InputFloat("ITEM: InputFloat", col4f, 1.0f); } // Testing +/- buttons on scalar input
+ if (item_type == 7) { ret = ImGui::InputFloat3("ITEM: InputFloat3", col4f); } // Testing multi-component items (IsItemXXX flags are reported merged)
+ if (item_type == 8) { ret = ImGui::ColorEdit4("ITEM: ColorEdit4", col4f); } // Testing multi-component items (IsItemXXX flags are reported merged)
+ if (item_type == 9) { ret = ImGui::MenuItem("ITEM: MenuItem"); } // Testing menu item (they use ImGuiButtonFlags_PressedOnRelease button policy)
+ if (item_type == 10){ ret = ImGui::TreeNodeEx("ITEM: TreeNode w/ ImGuiTreeNodeFlags_OpenOnDoubleClick", ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_NoTreePushOnOpen); } // Testing tree node with ImGuiButtonFlags_PressedOnDoubleClick button policy.
+ if (item_type == 11){ const char* items[] = { "Apple", "Banana", "Cherry", "Kiwi" }; static int current = 1; ret = ImGui::ListBox("ITEM: ListBox", ¤t, items, IM_ARRAYSIZE(items), IM_ARRAYSIZE(items)); }
ImGui::BulletText(
"Return value = %d\n"
"IsItemFocused() = %d\n"
@@ -1497,9 +1650,11 @@ static void ShowDemoWindowWidgets()
"IsItemHovered(_RectOnly) = %d\n"
"IsItemActive() = %d\n"
"IsItemEdited() = %d\n"
+ "IsItemActivated() = %d\n"
"IsItemDeactivated() = %d\n"
- "IsItemDeactivatedEdit() = %d\n"
+ "IsItemDeactivatedAfterEdit() = %d\n"
"IsItemVisible() = %d\n"
+ "IsItemClicked() = %d\n"
"GetItemRectMin() = (%.1f, %.1f)\n"
"GetItemRectMax() = (%.1f, %.1f)\n"
"GetItemRectSize() = (%.1f, %.1f)",
@@ -1512,9 +1667,11 @@ static void ShowDemoWindowWidgets()
ImGui::IsItemHovered(ImGuiHoveredFlags_RectOnly),
ImGui::IsItemActive(),
ImGui::IsItemEdited(),
+ ImGui::IsItemActivated(),
ImGui::IsItemDeactivated(),
ImGui::IsItemDeactivatedAfterEdit(),
ImGui::IsItemVisible(),
+ ImGui::IsItemClicked(),
ImGui::GetItemRectMin().x, ImGui::GetItemRectMin().y,
ImGui::GetItemRectMax().x, ImGui::GetItemRectMax().y,
ImGui::GetItemRectSize().x, ImGui::GetItemRectSize().y
@@ -1545,6 +1702,7 @@ static void ShowDemoWindowWidgets()
"IsWindowHovered(_AllowWhenBlockedByActiveItem) = %d\n"
"IsWindowHovered(_ChildWindows) = %d\n"
"IsWindowHovered(_ChildWindows|_RootWindow) = %d\n"
+ "IsWindowHovered(_ChildWindows|_AllowWhenBlockedByPopup) = %d\n"
"IsWindowHovered(_RootWindow) = %d\n"
"IsWindowHovered(_AnyWindow) = %d\n",
ImGui::IsWindowHovered(),
@@ -1552,6 +1710,7 @@ static void ShowDemoWindowWidgets()
ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem),
ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows),
ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows | ImGuiHoveredFlags_RootWindow),
+ ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows | ImGuiHoveredFlags_AllowWhenBlockedByPopup),
ImGui::IsWindowHovered(ImGuiHoveredFlags_RootWindow),
ImGui::IsWindowHovered(ImGuiHoveredFlags_AnyWindow));
@@ -1561,6 +1720,9 @@ static void ShowDemoWindowWidgets()
if (embed_all_inside_a_child_window)
ImGui::EndChild();
+ static char dummy_str[] = "This is a dummy field to be able to tab-out of the widgets above.";
+ ImGui::InputText("dummy", dummy_str, IM_ARRAYSIZE(dummy_str), ImGuiInputTextFlags_ReadOnly);
+
// Calling IsItemHovered() after begin returns the hovered status of the title bar.
// This is useful in particular if you want to create a context menu (with BeginPopupContextItem) associated to the title bar of a window.
// This will also work when docked into a Tab (the Tab replace the Title Bar and guarantee the same properties).
@@ -1576,7 +1738,6 @@ static void ShowDemoWindowWidgets()
if (ImGui::MenuItem("Close")) { test_window = false; }
ImGui::EndPopup();
}
- //if (IsItemHovered() || IsItemActive()) { printf("[%05d] Hovered %d Active %d\n", GetFrameCount(), IsItemHovered(), IsItemActive()); } // [DEBUG]
ImGui::Text(
"IsItemHovered() after begin = %d (== is title bar hovered)\n"
"IsItemActive() after begin = %d (== is window being clicked/moved)\n",
@@ -1595,7 +1756,7 @@ static void ShowDemoWindowLayout()
if (ImGui::TreeNode("Child windows"))
{
- ShowHelpMarker("Use child windows to begin into a self-contained independent scrolling/clipping regions within a host window.");
+ HelpMarker("Use child windows to begin into a self-contained independent scrolling/clipping regions within a host window.");
static bool disable_mouse_wheel = false;
static bool disable_menu = false;
ImGui::Checkbox("Disable Mouse Wheel", &disable_mouse_wheel);
@@ -1604,9 +1765,8 @@ static void ShowDemoWindowLayout()
static int line = 50;
bool goto_line = ImGui::Button("Goto");
ImGui::SameLine();
- ImGui::PushItemWidth(100);
+ ImGui::SetNextItemWidth(100);
goto_line |= ImGui::InputInt("##Line", &line, 0, 0, ImGuiInputTextFlags_EnterReturnsTrue);
- ImGui::PopItemWidth();
// Child 1: no border, enable horizontal scrollbar
{
@@ -1644,7 +1804,7 @@ static void ShowDemoWindowLayout()
{
char buf[32];
sprintf(buf, "%03d", i);
- ImGui::Button(buf, ImVec2(-1.0f, 0.0f));
+ ImGui::Button(buf, ImVec2(-FLT_MIN, 0.0f));
ImGui::NextColumn();
}
ImGui::EndChild();
@@ -1660,7 +1820,7 @@ static void ShowDemoWindowLayout()
// - Using ImGui::GetItemRectMin/Max() to query the "item" state (because the child window is an item from the POV of the parent window)
// See "Widgets" -> "Querying Status (Active/Focused/Hovered etc.)" section for more details about this.
{
- ImGui::SetCursorPosX(50);
+ ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 10);
ImGui::PushStyleColor(ImGuiCol_ChildBg, IM_COL32(255, 0, 0, 100));
ImGui::BeginChild("blah", ImVec2(200, 100), true, ImGuiWindowFlags_None);
for (int n = 0; n < 50; n++)
@@ -1677,35 +1837,36 @@ static void ShowDemoWindowLayout()
if (ImGui::TreeNode("Widgets Width"))
{
+ // Use SetNextItemWidth() to set the width of a single upcoming item.
+ // Use PushItemWidth()/PopItemWidth() to set the width of a group of items.
static float f = 0.0f;
- ImGui::Text("PushItemWidth(100)");
- ImGui::SameLine(); ShowHelpMarker("Fixed width.");
- ImGui::PushItemWidth(100);
+ ImGui::Text("SetNextItemWidth/PushItemWidth(100)");
+ ImGui::SameLine(); HelpMarker("Fixed width.");
+ ImGui::SetNextItemWidth(100);
ImGui::DragFloat("float##1", &f);
- ImGui::PopItemWidth();
- ImGui::Text("PushItemWidth(GetWindowWidth() * 0.5f)");
- ImGui::SameLine(); ShowHelpMarker("Half of window width.");
- ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
+ ImGui::Text("SetNextItemWidth/PushItemWidth(GetWindowWidth() * 0.5f)");
+ ImGui::SameLine(); HelpMarker("Half of window width.");
+ ImGui::SetNextItemWidth(ImGui::GetWindowWidth() * 0.5f);
ImGui::DragFloat("float##2", &f);
- ImGui::PopItemWidth();
- ImGui::Text("PushItemWidth(GetContentRegionAvailWidth() * 0.5f)");
- ImGui::SameLine(); ShowHelpMarker("Half of available width.\n(~ right-cursor_pos)\n(works within a column set)");
- ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth() * 0.5f);
+ ImGui::Text("SetNextItemWidth/PushItemWidth(GetContentRegionAvail().x * 0.5f)");
+ ImGui::SameLine(); HelpMarker("Half of available width.\n(~ right-cursor_pos)\n(works within a column set)");
+ ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x * 0.5f);
ImGui::DragFloat("float##3", &f);
- ImGui::PopItemWidth();
- ImGui::Text("PushItemWidth(-100)");
- ImGui::SameLine(); ShowHelpMarker("Align to right edge minus 100");
- ImGui::PushItemWidth(-100);
+ ImGui::Text("SetNextItemWidth/PushItemWidth(-100)");
+ ImGui::SameLine(); HelpMarker("Align to right edge minus 100");
+ ImGui::SetNextItemWidth(-100);
ImGui::DragFloat("float##4", &f);
- ImGui::PopItemWidth();
- ImGui::Text("PushItemWidth(-1)");
- ImGui::SameLine(); ShowHelpMarker("Align to right edge");
+ // Demonstrate using PushItemWidth to surround three items. Calling SetNextItemWidth() before each of them would have the same effect.
+ ImGui::Text("SetNextItemWidth/PushItemWidth(-1)");
+ ImGui::SameLine(); HelpMarker("Align to right edge");
ImGui::PushItemWidth(-1);
- ImGui::DragFloat("float##5", &f);
+ ImGui::DragFloat("##float5a", &f);
+ ImGui::DragFloat("##float5b", &f);
+ ImGui::DragFloat("##float5c", &f);
ImGui::PopItemWidth();
ImGui::TreePop();
@@ -1833,6 +1994,7 @@ static void ShowDemoWindowLayout()
static ImGuiTabBarFlags tab_bar_flags = ImGuiTabBarFlags_Reorderable;
ImGui::CheckboxFlags("ImGuiTabBarFlags_Reorderable", (unsigned int*)&tab_bar_flags, ImGuiTabBarFlags_Reorderable);
ImGui::CheckboxFlags("ImGuiTabBarFlags_AutoSelectNewTabs", (unsigned int*)&tab_bar_flags, ImGuiTabBarFlags_AutoSelectNewTabs);
+ ImGui::CheckboxFlags("ImGuiTabBarFlags_TabListPopupButton", (unsigned int*)&tab_bar_flags, ImGuiTabBarFlags_TabListPopupButton);
ImGui::CheckboxFlags("ImGuiTabBarFlags_NoCloseWithMiddleMouseButton", (unsigned int*)&tab_bar_flags, ImGuiTabBarFlags_NoCloseWithMiddleMouseButton);
if ((tab_bar_flags & ImGuiTabBarFlags_FittingPolicyMask_) == 0)
tab_bar_flags |= ImGuiTabBarFlags_FittingPolicyDefault_;
@@ -1871,7 +2033,7 @@ static void ShowDemoWindowLayout()
if (ImGui::TreeNode("Groups"))
{
- ShowHelpMarker("Using ImGui::BeginGroup()/EndGroup() to layout items. BeginGroup() basically locks the horizontal position. EndGroup() bundles the whole group so that you can use functions such as IsItemHovered() on it.");
+ HelpMarker("BeginGroup() basically locks the horizontal position for new line. EndGroup() bundles the whole group so that you can use \"item\" functions such as IsItemHovered()/IsItemActive() or SameLine() etc. on the whole group.");
ImGui::BeginGroup();
{
ImGui::BeginGroup();
@@ -1915,7 +2077,7 @@ static void ShowDemoWindowLayout()
if (ImGui::TreeNode("Text Baseline Alignment"))
{
- ShowHelpMarker("This is testing the vertical alignment that gets applied on text to keep it aligned with widgets. Lines only composed of text or \"small\" widgets fit in less vertical spaces than lines with normal widgets.");
+ HelpMarker("This is testing the vertical alignment that gets applied on text to keep it aligned with widgets. Lines only composed of text or \"small\" widgets fit in less vertical spaces than lines with normal widgets.");
ImGui::Text("One\nTwo\nThree"); ImGui::SameLine();
ImGui::Text("Hello\nWorld"); ImGui::SameLine();
@@ -1970,49 +2132,114 @@ static void ShowDemoWindowLayout()
if (ImGui::TreeNode("Scrolling"))
{
- ShowHelpMarker("Use SetScrollHereY() or SetScrollFromPosY() to scroll to a given position.");
+ // Vertical scroll functions
+ HelpMarker("Use SetScrollHereY() or SetScrollFromPosY() to scroll to a given vertical position.");
+
+ static int track_item = 50;
+ static bool enable_track = true;
+ static bool enable_extra_decorations = false;
+ static float scroll_to_off_px = 0.0f;
+ static float scroll_to_pos_px = 200.0f;
+
+ ImGui::Checkbox("Decoration", &enable_extra_decorations);
+ ImGui::SameLine();
+ HelpMarker("We expose this for testing because scrolling sometimes had issues with window decoration such as menu-bars.");
- static bool track = true;
- static int track_line = 50, scroll_to_px = 200;
- ImGui::Checkbox("Track", &track);
+ ImGui::Checkbox("Track", &enable_track);
ImGui::PushItemWidth(100);
- ImGui::SameLine(130); track |= ImGui::DragInt("##line", &track_line, 0.25f, 0, 99, "Line = %d");
- bool scroll_to = ImGui::Button("Scroll To Pos");
- ImGui::SameLine(130); scroll_to |= ImGui::DragInt("##pos_y", &scroll_to_px, 1.00f, 0, 9999, "Y = %d px");
+ ImGui::SameLine(140); enable_track |= ImGui::DragInt("##item", &track_item, 0.25f, 0, 99, "Item = %d");
+
+ bool scroll_to_off = ImGui::Button("Scroll Offset");
+ ImGui::SameLine(140); scroll_to_off |= ImGui::DragFloat("##off", &scroll_to_off_px, 1.00f, 0, 9999, "+%.0f px");
+
+ bool scroll_to_pos = ImGui::Button("Scroll To Pos");
+ ImGui::SameLine(140); scroll_to_pos |= ImGui::DragFloat("##pos", &scroll_to_pos_px, 1.00f, -10, 9999, "X/Y = %.0f px");
ImGui::PopItemWidth();
- if (scroll_to) track = false;
+ if (scroll_to_off || scroll_to_pos)
+ enable_track = false;
+
+ ImGuiStyle& style = ImGui::GetStyle();
+ float child_w = (ImGui::GetContentRegionAvail().x - 4 * style.ItemSpacing.x) / 5;
+ if (child_w < 1.0f)
+ child_w = 1.0f;
+ ImGui::PushID("##VerticalScrolling");
for (int i = 0; i < 5; i++)
{
if (i > 0) ImGui::SameLine();
ImGui::BeginGroup();
- ImGui::Text("%s", i == 0 ? "Top" : i == 1 ? "25%" : i == 2 ? "Center" : i == 3 ? "75%" : "Bottom");
- ImGui::BeginChild(ImGui::GetID((void*)(intptr_t)i), ImVec2(ImGui::GetWindowWidth() * 0.17f, 200.0f), true);
- if (scroll_to)
- ImGui::SetScrollFromPosY(ImGui::GetCursorStartPos().y + scroll_to_px, i * 0.25f);
- for (int line = 0; line < 100; line++)
+ const char* names[] = { "Top", "25%", "Center", "75%", "Bottom" };
+ ImGui::TextUnformatted(names[i]);
+
+ ImGuiWindowFlags child_flags = enable_extra_decorations ? ImGuiWindowFlags_MenuBar : 0;
+ ImGui::BeginChild(ImGui::GetID((void*)(intptr_t)i), ImVec2(child_w, 200.0f), true, child_flags);
+ if (ImGui::BeginMenuBar())
{
- if (track && line == track_line)
+ ImGui::TextUnformatted("abc");
+ ImGui::EndMenuBar();
+ }
+ if (scroll_to_off)
+ ImGui::SetScrollY(scroll_to_off_px);
+ if (scroll_to_pos)
+ ImGui::SetScrollFromPosY(ImGui::GetCursorStartPos().y + scroll_to_pos_px, i * 0.25f);
+ for (int item = 0; item < 100; item++)
+ {
+ if (enable_track && item == track_item)
{
- ImGui::TextColored(ImVec4(1,1,0,1), "Line %d", line);
+ ImGui::TextColored(ImVec4(1,1,0,1), "Item %d", item);
ImGui::SetScrollHereY(i * 0.25f); // 0.0f:top, 0.5f:center, 1.0f:bottom
}
else
{
- ImGui::Text("Line %d", line);
+ ImGui::Text("Item %d", item);
}
}
- float scroll_y = ImGui::GetScrollY(), scroll_max_y = ImGui::GetScrollMaxY();
+ float scroll_y = ImGui::GetScrollY();
+ float scroll_max_y = ImGui::GetScrollMaxY();
ImGui::EndChild();
- ImGui::Text("%.0f/%0.f", scroll_y, scroll_max_y);
+ ImGui::Text("%.0f/%.0f", scroll_y, scroll_max_y);
ImGui::EndGroup();
}
- ImGui::TreePop();
- }
+ ImGui::PopID();
- if (ImGui::TreeNode("Horizontal Scrolling"))
- {
- ShowHelpMarker("Horizontal scrolling for a window has to be enabled explicitly via the ImGuiWindowFlags_HorizontalScrollbar flag.\n\nYou may want to explicitly specify content width by calling SetNextWindowContentWidth() before Begin().");
+ // Horizontal scroll functions
+ ImGui::Spacing();
+ HelpMarker("Use SetScrollHereX() or SetScrollFromPosX() to scroll to a given horizontal position.\n\nUsing the \"Scroll To Pos\" button above will make the discontinuity at edges visible: scrolling to the top/bottom/left/right-most item will add an additional WindowPadding to reflect on reaching the edge of the list.\n\nBecause the clipping rectangle of most window hides half worth of WindowPadding on the left/right, using SetScrollFromPosX(+1) will usually result in clipped text whereas the equivalent SetScrollFromPosY(+1) wouldn't.");
+ ImGui::PushID("##HorizontalScrolling");
+ for (int i = 0; i < 5; i++)
+ {
+ float child_height = ImGui::GetTextLineHeight() + style.ScrollbarSize + style.WindowPadding.y * 2.0f;
+ ImGuiWindowFlags child_flags = ImGuiWindowFlags_HorizontalScrollbar | (enable_extra_decorations ? ImGuiWindowFlags_AlwaysVerticalScrollbar : 0);
+ ImGui::BeginChild(ImGui::GetID((void*)(intptr_t)i), ImVec2(-100, child_height), true, child_flags);
+ if (scroll_to_off)
+ ImGui::SetScrollX(scroll_to_off_px);
+ if (scroll_to_pos)
+ ImGui::SetScrollFromPosX(ImGui::GetCursorStartPos().x + scroll_to_pos_px, i * 0.25f);
+ for (int item = 0; item < 100; item++)
+ {
+ if (enable_track && item == track_item)
+ {
+ ImGui::TextColored(ImVec4(1, 1, 0, 1), "Item %d", item);
+ ImGui::SetScrollHereX(i * 0.25f); // 0.0f:left, 0.5f:center, 1.0f:right
+ }
+ else
+ {
+ ImGui::Text("Item %d", item);
+ }
+ ImGui::SameLine();
+ }
+ float scroll_x = ImGui::GetScrollX();
+ float scroll_max_x = ImGui::GetScrollMaxX();
+ ImGui::EndChild();
+ ImGui::SameLine();
+ const char* names[] = { "Left", "25%", "Center", "75%", "Right" };
+ ImGui::Text("%s\n%.0f/%.0f", names[i], scroll_x, scroll_max_x);
+ ImGui::Spacing();
+ }
+ ImGui::PopID();
+
+ // Miscellaneous Horizontal Scrolling Demo
+ HelpMarker("Horizontal scrolling for a window has to be enabled explicitly via the ImGuiWindowFlags_HorizontalScrollbar flag.\n\nYou may want to explicitly specify content width by calling SetNextWindowContentWidth() before Begin().");
static int lines = 7;
ImGui::SliderInt("Lines", &lines, 1, 15);
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
@@ -2039,7 +2266,8 @@ static void ShowDemoWindowLayout()
ImGui::PopID();
}
}
- float scroll_x = ImGui::GetScrollX(), scroll_max_x = ImGui::GetScrollMaxX();
+ float scroll_x = ImGui::GetScrollX();
+ float scroll_max_x = ImGui::GetScrollMaxX();
ImGui::EndChild();
ImGui::PopStyleVar(2);
float scroll_x_delta = 0.0f;
@@ -2053,6 +2281,97 @@ static void ShowDemoWindowLayout()
ImGui::SetScrollX(ImGui::GetScrollX() + scroll_x_delta);
ImGui::EndChild();
}
+ ImGui::Spacing();
+
+ static bool show_horizontal_contents_size_demo_window = false;
+ ImGui::Checkbox("Show Horizontal contents size demo window", &show_horizontal_contents_size_demo_window);
+
+ if (show_horizontal_contents_size_demo_window)
+ {
+ static bool show_h_scrollbar = true;
+ static bool show_button = true;
+ static bool show_tree_nodes = true;
+ static bool show_text_wrapped = false;
+ static bool show_columns = true;
+ static bool show_tab_bar = true;
+ static bool show_child = false;
+ static bool explicit_content_size = false;
+ static float contents_size_x = 300.0f;
+ if (explicit_content_size)
+ ImGui::SetNextWindowContentSize(ImVec2(contents_size_x, 0.0f));
+ ImGui::Begin("Horizontal contents size demo window", &show_horizontal_contents_size_demo_window, show_h_scrollbar ? ImGuiWindowFlags_HorizontalScrollbar : 0);
+ ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(2, 0));
+ ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2, 0));
+ HelpMarker("Test of different widgets react and impact the work rectangle growing when horizontal scrolling is enabled.\n\nUse 'Metrics->Tools->Show windows rectangles' to visualize rectangles.");
+ ImGui::Checkbox("H-scrollbar", &show_h_scrollbar);
+ ImGui::Checkbox("Button", &show_button); // Will grow contents size (unless explicitly overwritten)
+ ImGui::Checkbox("Tree nodes", &show_tree_nodes); // Will grow contents size and display highlight over full width
+ ImGui::Checkbox("Text wrapped", &show_text_wrapped);// Will grow and use contents size
+ ImGui::Checkbox("Columns", &show_columns); // Will use contents size
+ ImGui::Checkbox("Tab bar", &show_tab_bar); // Will use contents size
+ ImGui::Checkbox("Child", &show_child); // Will grow and use contents size
+ ImGui::Checkbox("Explicit content size", &explicit_content_size);
+ ImGui::Text("Scroll %.1f/%.1f %.1f/%.1f", ImGui::GetScrollX(), ImGui::GetScrollMaxX(), ImGui::GetScrollY(), ImGui::GetScrollMaxY());
+ if (explicit_content_size)
+ {
+ ImGui::SameLine();
+ ImGui::SetNextItemWidth(100);
+ ImGui::DragFloat("##csx", &contents_size_x);
+ ImVec2 p = ImGui::GetCursorScreenPos();
+ ImGui::GetWindowDrawList()->AddRectFilled(p, ImVec2(p.x + 10, p.y + 10), IM_COL32_WHITE);
+ ImGui::GetWindowDrawList()->AddRectFilled(ImVec2(p.x + contents_size_x - 10, p.y), ImVec2(p.x + contents_size_x, p.y + 10), IM_COL32_WHITE);
+ ImGui::Dummy(ImVec2(0, 10));
+ }
+ ImGui::PopStyleVar(2);
+ ImGui::Separator();
+ if (show_button)
+ {
+ ImGui::Button("this is a 300-wide button", ImVec2(300, 0));
+ }
+ if (show_tree_nodes)
+ {
+ bool open = true;
+ if (ImGui::TreeNode("this is a tree node"))
+ {
+ if (ImGui::TreeNode("another one of those tree node..."))
+ {
+ ImGui::Text("Some tree contents");
+ ImGui::TreePop();
+ }
+ ImGui::TreePop();
+ }
+ ImGui::CollapsingHeader("CollapsingHeader", &open);
+ }
+ if (show_text_wrapped)
+ {
+ ImGui::TextWrapped("This text should automatically wrap on the edge of the work rectangle.");
+ }
+ if (show_columns)
+ {
+ ImGui::Columns(4);
+ for (int n = 0; n < 4; n++)
+ {
+ ImGui::Text("Width %.2f", ImGui::GetColumnWidth());
+ ImGui::NextColumn();
+ }
+ ImGui::Columns(1);
+ }
+ if (show_tab_bar && ImGui::BeginTabBar("Hello"))
+ {
+ if (ImGui::BeginTabItem("OneOneOne")) { ImGui::EndTabItem(); }
+ if (ImGui::BeginTabItem("TwoTwoTwo")) { ImGui::EndTabItem(); }
+ if (ImGui::BeginTabItem("ThreeThreeThree")) { ImGui::EndTabItem(); }
+ if (ImGui::BeginTabItem("FourFourFour")) { ImGui::EndTabItem(); }
+ ImGui::EndTabBar();
+ }
+ if (show_child)
+ {
+ ImGui::BeginChild("child", ImVec2(0,0), true);
+ ImGui::EndChild();
+ }
+ ImGui::End();
+ }
+
ImGui::TreePop();
}
@@ -2080,7 +2399,7 @@ static void ShowDemoWindowPopups()
// The properties of popups windows are:
// - They block normal mouse hovering detection outside them. (*)
// - Unless modal, they can be closed by clicking anywhere outside them, or by pressing ESCAPE.
- // - Their visibility state (~bool) is held internally by imgui instead of being held by the programmer as we are used to with regular Begin() calls.
+ // - Their visibility state (~bool) is held internally by Dear ImGui instead of being held by the programmer as we are used to with regular Begin() calls.
// User can manipulate the visibility state by calling OpenPopup().
// (*) One can use IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup) to bypass it and detect hovering even when normally blocked by a popup.
// Those three properties are connected. The library needs to hold their visibility state because it can close popups at any time.
@@ -2144,6 +2463,13 @@ static void ShowDemoWindowPopups()
if (ImGui::BeginMenu("Sub-menu"))
{
ImGui::MenuItem("Click me");
+ if (ImGui::Button("Stacked Popup"))
+ ImGui::OpenPopup("another popup");
+ if (ImGui::BeginPopup("another popup"))
+ {
+ ImGui::Text("I am the last one here.");
+ ImGui::EndPopup();
+ }
ImGui::EndMenu();
}
ImGui::EndPopup();
@@ -2176,15 +2502,14 @@ static void ShowDemoWindowPopups()
{
if (ImGui::Selectable("Set to zero")) value = 0.0f;
if (ImGui::Selectable("Set to PI")) value = 3.1415f;
- ImGui::PushItemWidth(-1);
+ ImGui::SetNextItemWidth(-1);
ImGui::DragFloat("##Value", &value, 0.1f, 0.0f, 0.0f);
- ImGui::PopItemWidth();
ImGui::EndPopup();
}
// We can also use OpenPopupOnItemClick() which is the same as BeginPopupContextItem() but without the Begin call.
// So here we will make it that clicking on the text field with the right mouse button (1) will toggle the visibility of the popup above.
- ImGui::Text("(You can also right-click me to the same popup as above.)");
+ ImGui::Text("(You can also right-click me to open the same popup as above.)");
ImGui::OpenPopupOnItemClick("item context menu", 1);
// When used after an item that has an ID (here the Button), we can skip providing an ID to BeginPopupContextItem().
@@ -2303,6 +2628,13 @@ static void ShowDemoWindowColumns()
ImGui::PushID("Columns");
+ static bool disable_indent = false;
+ ImGui::Checkbox("Disable tree indentation", &disable_indent);
+ ImGui::SameLine();
+ HelpMarker("Disable the indenting of tree nodes so demo columns can use the full window width.");
+ if (disable_indent)
+ ImGui::PushStyleVar(ImGuiStyleVar_IndentSpacing, 0.0f);
+
// Basic columns
if (ImGui::TreeNode("Basic"))
{
@@ -2314,7 +2646,7 @@ static void ShowDemoWindowColumns()
char label[32];
sprintf(label, "Item %d", n);
if (ImGui::Selectable(label)) {}
- //if (ImGui::Button(label, ImVec2(-1,0))) {}
+ //if (ImGui::Button(label, ImVec2(-FLT_MIN,0.0f))) {}
ImGui::NextColumn();
}
ImGui::Columns(1);
@@ -2348,6 +2680,40 @@ static void ShowDemoWindowColumns()
ImGui::TreePop();
}
+ if (ImGui::TreeNode("Borders"))
+ {
+ // NB: Future columns API should allow automatic horizontal borders.
+ static bool h_borders = true;
+ static bool v_borders = true;
+ static int columns_count = 4;
+ const int lines_count = 3;
+ ImGui::SetNextItemWidth(ImGui::GetFontSize() * 8);
+ ImGui::DragInt("##columns_count", &columns_count, 0.1f, 2, 10, "%d columns");
+ if (columns_count < 2)
+ columns_count = 2;
+ ImGui::SameLine();
+ ImGui::Checkbox("horizontal", &h_borders);
+ ImGui::SameLine();
+ ImGui::Checkbox("vertical", &v_borders);
+ ImGui::Columns(columns_count, NULL, v_borders);
+ for (int i = 0; i < columns_count * lines_count; i++)
+ {
+ if (h_borders && ImGui::GetColumnIndex() == 0)
+ ImGui::Separator();
+ ImGui::Text("%c%c%c", 'a' + i, 'a' + i, 'a' + i);
+ ImGui::Text("Width %.2f", ImGui::GetColumnWidth());
+ ImGui::Text("Avail %.2f", ImGui::GetContentRegionAvail().x);
+ ImGui::Text("Offset %.2f", ImGui::GetColumnOffset());
+ ImGui::Text("Long text that is likely to clip");
+ ImGui::Button("Button", ImVec2(-FLT_MIN, 0.0f));
+ ImGui::NextColumn();
+ }
+ ImGui::Columns(1);
+ if (h_borders)
+ ImGui::Separator();
+ ImGui::TreePop();
+ }
+
// Create multiple items in a same cell before switching to next column
if (ImGui::TreeNode("Mixed items"))
{
@@ -2394,29 +2760,6 @@ static void ShowDemoWindowColumns()
ImGui::TreePop();
}
- if (ImGui::TreeNode("Borders"))
- {
- // NB: Future columns API should allow automatic horizontal borders.
- static bool h_borders = true;
- static bool v_borders = true;
- ImGui::Checkbox("horizontal", &h_borders);
- ImGui::SameLine();
- ImGui::Checkbox("vertical", &v_borders);
- ImGui::Columns(4, NULL, v_borders);
- for (int i = 0; i < 4*3; i++)
- {
- if (h_borders && ImGui::GetColumnIndex() == 0)
- ImGui::Separator();
- ImGui::Text("%c%c%c", 'a'+i, 'a'+i, 'a'+i);
- ImGui::Text("Width %.2f\nOffset %.2f", ImGui::GetColumnWidth(), ImGui::GetColumnOffset());
- ImGui::NextColumn();
- }
- ImGui::Columns(1);
- if (h_borders)
- ImGui::Separator();
- ImGui::TreePop();
- }
-
// Scrolling columns
/*
if (ImGui::TreeNode("Vertical Scrolling"))
@@ -2464,18 +2807,44 @@ static void ShowDemoWindowColumns()
ImGui::TreePop();
}
- bool node_open = ImGui::TreeNode("Tree within single cell");
- ImGui::SameLine(); ShowHelpMarker("NB: Tree node must be poped before ending the cell. There's no storage of state per-cell.");
- if (node_open)
+ if (ImGui::TreeNode("Tree"))
{
- ImGui::Columns(2, "tree items");
- ImGui::Separator();
- if (ImGui::TreeNode("Hello")) { ImGui::BulletText("Sailor"); ImGui::TreePop(); } ImGui::NextColumn();
- if (ImGui::TreeNode("Bonjour")) { ImGui::BulletText("Marin"); ImGui::TreePop(); } ImGui::NextColumn();
+ ImGui::Columns(2, "tree", true);
+ for (int x = 0; x < 3; x++)
+ {
+ bool open1 = ImGui::TreeNode((void*)(intptr_t)x, "Node%d", x);
+ ImGui::NextColumn();
+ ImGui::Text("Node contents");
+ ImGui::NextColumn();
+ if (open1)
+ {
+ for (int y = 0; y < 3; y++)
+ {
+ bool open2 = ImGui::TreeNode((void*)(intptr_t)y, "Node%d.%d", x, y);
+ ImGui::NextColumn();
+ ImGui::Text("Node contents");
+ if (open2)
+ {
+ ImGui::Text("Even more contents");
+ if (ImGui::TreeNode("Tree in column"))
+ {
+ ImGui::Text("The quick brown fox jumps over the lazy dog");
+ ImGui::TreePop();
+ }
+ }
+ ImGui::NextColumn();
+ if (open2)
+ ImGui::TreePop();
+ }
+ ImGui::TreePop();
+ }
+ }
ImGui::Columns(1);
- ImGui::Separator();
ImGui::TreePop();
}
+
+ if (disable_indent)
+ ImGui::PopStyleVar();
ImGui::PopID();
}
@@ -2519,10 +2888,11 @@ static void ShowDemoWindowMisc()
ImGui::Text("Mouse released:"); for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) if (ImGui::IsMouseReleased(i)) { ImGui::SameLine(); ImGui::Text("b%d", i); }
ImGui::Text("Mouse wheel: %.1f", io.MouseWheel);
- ImGui::Text("Keys down:"); for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); i++) if (io.KeysDownDuration[i] >= 0.0f) { ImGui::SameLine(); ImGui::Text("%d (%.02f secs)", i, io.KeysDownDuration[i]); }
- ImGui::Text("Keys pressed:"); for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); i++) if (ImGui::IsKeyPressed(i)) { ImGui::SameLine(); ImGui::Text("%d", i); }
- ImGui::Text("Keys release:"); for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); i++) if (ImGui::IsKeyReleased(i)) { ImGui::SameLine(); ImGui::Text("%d", i); }
+ ImGui::Text("Keys down:"); for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); i++) if (io.KeysDownDuration[i] >= 0.0f) { ImGui::SameLine(); ImGui::Text("%d (0x%X) (%.02f secs)", i, i, io.KeysDownDuration[i]); }
+ ImGui::Text("Keys pressed:"); for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); i++) if (ImGui::IsKeyPressed(i)) { ImGui::SameLine(); ImGui::Text("%d (0x%X)", i, i); }
+ ImGui::Text("Keys release:"); for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); i++) if (ImGui::IsKeyReleased(i)) { ImGui::SameLine(); ImGui::Text("%d (0x%X)", i, i); }
ImGui::Text("Keys mods: %s%s%s%s", io.KeyCtrl ? "CTRL " : "", io.KeyShift ? "SHIFT " : "", io.KeyAlt ? "ALT " : "", io.KeySuper ? "SUPER " : "");
+ ImGui::Text("Chars queue:"); for (int i = 0; i < io.InputQueueCharacters.Size; i++) { ImWchar c = io.InputQueueCharacters[i]; ImGui::SameLine(); ImGui::Text("\'%c\' (0x%04X)", (c > ' ' && c <= 255) ? (char)c : '?', c); } // FIXME: We should convert 'c' to UTF-8 here but the functions are not public.
ImGui::Text("NavInputs down:"); for (int i = 0; i < IM_ARRAYSIZE(io.NavInputs); i++) if (io.NavInputs[i] > 0.0f) { ImGui::SameLine(); ImGui::Text("[%d] %.2f", i, io.NavInputs[i]); }
ImGui::Text("NavInputs pressed:"); for (int i = 0; i < IM_ARRAYSIZE(io.NavInputs); i++) if (io.NavInputsDownDuration[i] == 0.0f) { ImGui::SameLine(); ImGui::Text("[%d]", i); }
@@ -2548,7 +2918,7 @@ static void ShowDemoWindowMisc()
ImGui::InputText("3", buf, IM_ARRAYSIZE(buf));
ImGui::PushAllowKeyboardFocus(false);
ImGui::InputText("4 (tab skip)", buf, IM_ARRAYSIZE(buf));
- //ImGui::SameLine(); ShowHelperMarker("Use ImGui::PushAllowKeyboardFocus(bool)\nto disable tabbing through certain widgets.");
+ //ImGui::SameLine(); HelpMarker("Use ImGui::PushAllowKeyboardFocus(bool)\nto disable tabbing through certain widgets.");
ImGui::PopAllowKeyboardFocus();
ImGui::InputText("5", buf, IM_ARRAYSIZE(buf));
ImGui::TreePop();
@@ -2600,22 +2970,17 @@ static void ShowDemoWindowMisc()
for (int button = 0; button < 3; button++)
ImGui::Text("IsMouseDragging(%d):\n w/ default threshold: %d,\n w/ zero threshold: %d\n w/ large threshold: %d",
button, ImGui::IsMouseDragging(button), ImGui::IsMouseDragging(button, 0.0f), ImGui::IsMouseDragging(button, 20.0f));
+
ImGui::Button("Drag Me");
if (ImGui::IsItemActive())
- {
- // Draw a line between the button and the mouse cursor
- ImDrawList* draw_list = ImGui::GetWindowDrawList();
- draw_list->PushClipRectFullScreen();
- draw_list->AddLine(io.MouseClickedPos[0], io.MousePos, ImGui::GetColorU32(ImGuiCol_Button), 4.0f);
- draw_list->PopClipRect();
-
- // Drag operations gets "unlocked" when the mouse has moved past a certain threshold (the default threshold is stored in io.MouseDragThreshold)
- // You can request a lower or higher threshold using the second parameter of IsMouseDragging() and GetMouseDragDelta()
- ImVec2 value_raw = ImGui::GetMouseDragDelta(0, 0.0f);
- ImVec2 value_with_lock_threshold = ImGui::GetMouseDragDelta(0);
- ImVec2 mouse_delta = io.MouseDelta;
- ImGui::SameLine(); ImGui::Text("Raw (%.1f, %.1f), WithLockThresold (%.1f, %.1f), MouseDelta (%.1f, %.1f)", value_raw.x, value_raw.y, value_with_lock_threshold.x, value_with_lock_threshold.y, mouse_delta.x, mouse_delta.y);
- }
+ ImGui::GetForegroundDrawList()->AddLine(io.MouseClickedPos[0], io.MousePos, ImGui::GetColorU32(ImGuiCol_Button), 4.0f); // Draw a line between the button and the mouse cursor
+
+ // Drag operations gets "unlocked" when the mouse has moved past a certain threshold (the default threshold is stored in io.MouseDragThreshold)
+ // You can request a lower or higher threshold using the second parameter of IsMouseDragging() and GetMouseDragDelta()
+ ImVec2 value_raw = ImGui::GetMouseDragDelta(0, 0.0f);
+ ImVec2 value_with_lock_threshold = ImGui::GetMouseDragDelta(0);
+ ImVec2 mouse_delta = io.MouseDelta;
+ ImGui::Text("GetMouseDragDelta(0):\n w/ default threshold: (%.1f, %.1f),\n w/ zero threshold: (%.1f, %.1f)\nMouseDelta: (%.1f, %.1f)", value_with_lock_threshold.x, value_with_lock_threshold.y, value_raw.x, value_raw.y, mouse_delta.x, mouse_delta.y);
ImGui::TreePop();
}
@@ -2626,7 +2991,7 @@ static void ShowDemoWindowMisc()
ImGui::Text("Current mouse cursor = %d: %s", ImGui::GetMouseCursor(), mouse_cursors_names[ImGui::GetMouseCursor()]);
ImGui::Text("Hover to see mouse cursors:");
- ImGui::SameLine(); ShowHelpMarker("Your application can render a different mouse cursor based on what ImGui::GetMouseCursor() returns. If software cursor rendering (io.MouseDrawCursor) is set ImGui will draw the right cursor for you, otherwise your backend needs to handle it.");
+ ImGui::SameLine(); HelpMarker("Your application can render a different mouse cursor based on what ImGui::GetMouseCursor() returns. If software cursor rendering (io.MouseDrawCursor) is set ImGui will draw the right cursor for you, otherwise your backend needs to handle it.");
for (int i = 0; i < ImGuiMouseCursor_COUNT; i++)
{
char label[32];
@@ -2642,7 +3007,7 @@ static void ShowDemoWindowMisc()
//-----------------------------------------------------------------------------
// [SECTION] About Window / ShowAboutWindow()
-// Access from ImGui Demo -> Help -> About
+// Access from Dear ImGui Demo -> Help -> About
//-----------------------------------------------------------------------------
void ImGui::ShowAboutWindow(bool* p_open)
@@ -2667,7 +3032,10 @@ void ImGui::ShowAboutWindow(bool* p_open)
bool copy_to_clipboard = ImGui::Button("Copy to clipboard");
ImGui::BeginChildFrame(ImGui::GetID("cfginfos"), ImVec2(0, ImGui::GetTextLineHeightWithSpacing() * 18), ImGuiWindowFlags_NoMove);
if (copy_to_clipboard)
+ {
ImGui::LogToClipboard();
+ ImGui::LogText("```\n"); // Back quotes will make the text appears without formatting when pasting to GitHub
+ }
ImGui::Text("Dear ImGui %s (%d)", IMGUI_VERSION, IMGUI_VERSION_NUM);
ImGui::Separator();
@@ -2729,9 +3097,6 @@ void ImGui::ShowAboutWindow(bool* p_open)
#endif
#ifdef IMGUI_HAS_DOCK
ImGui::Text("define: IMGUI_HAS_DOCK");
-#endif
-#ifdef IMGUI_HAS_TABS
- ImGui::Text("define: IMGUI_HAS_TABS");
#endif
ImGui::Separator();
ImGui::Text("io.BackendPlatformName: %s", io.BackendPlatformName ? io.BackendPlatformName : "NULL");
@@ -2751,29 +3116,28 @@ void ImGui::ShowAboutWindow(bool* p_open)
if (io.ConfigViewportsNoAutoMerge) ImGui::Text("io.ConfigViewportsNoAutoMerge");
if (io.ConfigViewportsNoTaskBarIcon) ImGui::Text("io.ConfigViewportsNoTaskBarIcon");
if (io.ConfigViewportsNoDecoration) ImGui::Text("io.ConfigViewportsNoDecoration");
- if (io.ConfigViewportsNoParent) ImGui::Text("io.ConfigViewportsNoParent");
+ if (io.ConfigViewportsNoDefaultParent) ImGui::Text("io.ConfigViewportsNoDefaultParent");
if (io.ConfigDockingNoSplit) ImGui::Text("io.ConfigDockingNoSplit");
if (io.ConfigDockingWithShift) ImGui::Text("io.ConfigDockingWithShift");
- if (io.ConfigDockingTabBarOnSingleWindows) ImGui::Text("io.ConfigDockingTabBarOnSingleWindows");
+ if (io.ConfigDockingAlwaysTabBar) ImGui::Text("io.ConfigDockingAlwaysTabBar");
if (io.ConfigDockingTransparentPayload) ImGui::Text("io.ConfigDockingTransparentPayload");
- if (io.ConfigViewportsNoAutoMerge) ImGui::Text("io.ConfigViewportsNoAutoMerge");
- if (io.ConfigViewportsNoTaskBarIcon) ImGui::Text("io.ConfigViewportsNoTaskBarIcon");
- if (io.ConfigViewportsNoDecoration) ImGui::Text("io.ConfigViewportsNoDecoration");
- if (io.ConfigViewportsNoParent) ImGui::Text("io.ConfigViewportsNoParent");
if (io.ConfigMacOSXBehaviors) ImGui::Text("io.ConfigMacOSXBehaviors");
if (io.ConfigInputTextCursorBlink) ImGui::Text("io.ConfigInputTextCursorBlink");
if (io.ConfigWindowsResizeFromEdges) ImGui::Text("io.ConfigWindowsResizeFromEdges");
if (io.ConfigWindowsMoveFromTitleBarOnly) ImGui::Text("io.ConfigWindowsMoveFromTitleBarOnly");
+ if (io.ConfigWindowsMemoryCompactTimer >= 0.0f) ImGui::Text("io.ConfigWindowsMemoryCompactTimer = %.1ff", io.ConfigWindowsMemoryCompactTimer);
ImGui::Text("io.BackendFlags: 0x%08X", io.BackendFlags);
if (io.BackendFlags & ImGuiBackendFlags_HasGamepad) ImGui::Text(" HasGamepad");
if (io.BackendFlags & ImGuiBackendFlags_HasMouseCursors) ImGui::Text(" HasMouseCursors");
if (io.BackendFlags & ImGuiBackendFlags_HasSetMousePos) ImGui::Text(" HasSetMousePos");
if (io.BackendFlags & ImGuiBackendFlags_PlatformHasViewports) ImGui::Text(" PlatformHasViewports");
if (io.BackendFlags & ImGuiBackendFlags_HasMouseHoveredViewport)ImGui::Text(" HasMouseHoveredViewport");
+ if (io.BackendFlags & ImGuiBackendFlags_RendererHasVtxOffset) ImGui::Text(" RendererHasVtxOffset");
if (io.BackendFlags & ImGuiBackendFlags_RendererHasViewports) ImGui::Text(" RendererHasViewports");
ImGui::Separator();
ImGui::Text("io.Fonts: %d fonts, Flags: 0x%08X, TexSize: %d,%d", io.Fonts->Fonts.Size, io.Fonts->Flags, io.Fonts->TexWidth, io.Fonts->TexHeight);
ImGui::Text("io.DisplaySize: %.2f,%.2f", io.DisplaySize.x, io.DisplaySize.y);
+ ImGui::Text("io.DisplayFramebufferScale: %.2f,%.2f", io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y);
ImGui::Separator();
ImGui::Text("style.WindowPadding: %.2f,%.2f", style.WindowPadding.x, style.WindowPadding.y);
ImGui::Text("style.WindowBorderSize: %.2f", style.WindowBorderSize);
@@ -2784,7 +3148,10 @@ void ImGui::ShowAboutWindow(bool* p_open)
ImGui::Text("style.ItemInnerSpacing: %.2f,%.2f", style.ItemInnerSpacing.x, style.ItemInnerSpacing.y);
if (copy_to_clipboard)
+ {
+ ImGui::LogText("\n```\n");
ImGui::LogFinish();
+ }
ImGui::EndChildFrame();
}
ImGui::End();
@@ -2821,12 +3188,17 @@ void ImGui::ShowFontSelector(const char* label)
if (ImGui::BeginCombo(label, font_current->GetDebugName()))
{
for (int n = 0; n < io.Fonts->Fonts.Size; n++)
- if (ImGui::Selectable(io.Fonts->Fonts[n]->GetDebugName(), io.Fonts->Fonts[n] == font_current))
- io.FontDefault = io.Fonts->Fonts[n];
+ {
+ ImFont* font = io.Fonts->Fonts[n];
+ ImGui::PushID((void*)font);
+ if (ImGui::Selectable(font->GetDebugName(), font == font_current))
+ io.FontDefault = font;
+ ImGui::PopID();
+ }
ImGui::EndCombo();
}
ImGui::SameLine();
- ShowHelpMarker(
+ HelpMarker(
"- Load additional fonts with io.Fonts->AddFontFromFileTTF().\n"
"- The font atlas is built when calling io.Fonts->GetTexDataAsXXXX() or io.Fonts->Build().\n"
"- Read FAQ and documentation in misc/fonts/ for more details.\n"
@@ -2869,7 +3241,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
if (ImGui::Button("Revert Ref"))
style = *ref;
ImGui::SameLine();
- ShowHelpMarker("Save/Revert in local non-persistent storage. Default Colors definition are not affected. Use \"Export Colors\" below to save them somewhere.");
+ HelpMarker("Save/Revert in local non-persistent storage. Default Colors definition are not affected. Use \"Export Colors\" below to save them somewhere.");
ImGui::Separator();
@@ -2879,7 +3251,6 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
{
ImGui::Text("Main");
ImGui::SliderFloat2("WindowPadding", (float*)&style.WindowPadding, 0.0f, 20.0f, "%.0f");
- ImGui::SliderFloat("PopupRounding", &style.PopupRounding, 0.0f, 16.0f, "%.0f");
ImGui::SliderFloat2("FramePadding", (float*)&style.FramePadding, 0.0f, 20.0f, "%.0f");
ImGui::SliderFloat2("ItemSpacing", (float*)&style.ItemSpacing, 0.0f, 20.0f, "%.0f");
ImGui::SliderFloat2("ItemInnerSpacing", (float*)&style.ItemInnerSpacing, 0.0f, 20.0f, "%.0f");
@@ -2897,13 +3268,17 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
ImGui::SliderFloat("WindowRounding", &style.WindowRounding, 0.0f, 12.0f, "%.0f");
ImGui::SliderFloat("ChildRounding", &style.ChildRounding, 0.0f, 12.0f, "%.0f");
ImGui::SliderFloat("FrameRounding", &style.FrameRounding, 0.0f, 12.0f, "%.0f");
+ ImGui::SliderFloat("PopupRounding", &style.PopupRounding, 0.0f, 12.0f, "%.0f");
ImGui::SliderFloat("ScrollbarRounding", &style.ScrollbarRounding, 0.0f, 12.0f, "%.0f");
ImGui::SliderFloat("GrabRounding", &style.GrabRounding, 0.0f, 12.0f, "%.0f");
ImGui::SliderFloat("TabRounding", &style.TabRounding, 0.0f, 12.0f, "%.0f");
ImGui::Text("Alignment");
ImGui::SliderFloat2("WindowTitleAlign", (float*)&style.WindowTitleAlign, 0.0f, 1.0f, "%.2f");
- ImGui::SliderFloat2("ButtonTextAlign", (float*)&style.ButtonTextAlign, 0.0f, 1.0f, "%.2f"); ImGui::SameLine(); ShowHelpMarker("Alignment applies when a button is larger than its text content.");
- ImGui::Text("Safe Area Padding"); ImGui::SameLine(); ShowHelpMarker("Adjust if you cannot see the edges of your screen (e.g. on a TV where scaling has not been configured).");
+ ImGui::Combo("WindowMenuButtonPosition", (int*)&style.WindowMenuButtonPosition, "Left\0Right\0");
+ ImGui::Combo("ColorButtonPosition", (int*)&style.ColorButtonPosition, "Left\0Right\0");
+ ImGui::SliderFloat2("ButtonTextAlign", (float*)&style.ButtonTextAlign, 0.0f, 1.0f, "%.2f"); ImGui::SameLine(); HelpMarker("Alignment applies when a button is larger than its text content.");
+ ImGui::SliderFloat2("SelectableTextAlign", (float*)&style.SelectableTextAlign, 0.0f, 1.0f, "%.2f"); ImGui::SameLine(); HelpMarker("Alignment applies when a selectable is larger than its text content.");
+ ImGui::Text("Safe Area Padding"); ImGui::SameLine(); HelpMarker("Adjust if you cannot see the edges of your screen (e.g. on a TV where scaling has not been configured).");
ImGui::SliderFloat2("DisplaySafeAreaPadding", (float*)&style.DisplaySafeAreaPadding, 0.0f, 30.0f, "%.0f");
ImGui::EndTabItem();
}
@@ -2928,7 +3303,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
}
ImGui::LogFinish();
}
- ImGui::SameLine(); ImGui::PushItemWidth(120); ImGui::Combo("##output_type", &output_dest, "To Clipboard\0To TTY\0"); ImGui::PopItemWidth();
+ ImGui::SameLine(); ImGui::SetNextItemWidth(120); ImGui::Combo("##output_type", &output_dest, "To Clipboard\0To TTY\0");
ImGui::SameLine(); ImGui::Checkbox("Only Modified Colors", &output_only_modified);
static ImGuiTextFilter filter;
@@ -2938,7 +3313,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
ImGui::RadioButton("Opaque", &alpha_flags, 0); ImGui::SameLine();
ImGui::RadioButton("Alpha", &alpha_flags, ImGuiColorEditFlags_AlphaPreview); ImGui::SameLine();
ImGui::RadioButton("Both", &alpha_flags, ImGuiColorEditFlags_AlphaPreviewHalf); ImGui::SameLine();
- ShowHelpMarker("In the color list:\nLeft-click on colored square to open color picker,\nRight-click to open edit options menu.");
+ HelpMarker("In the color list:\nLeft-click on colored square to open color picker,\nRight-click to open edit options menu.");
ImGui::BeginChild("##colors", ImVec2(0, 0), true, ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_AlwaysHorizontalScrollbar | ImGuiWindowFlags_NavFlattened);
ImGui::PushItemWidth(-160);
@@ -2968,28 +3343,30 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
if (ImGui::BeginTabItem("Fonts"))
{
- ImFontAtlas* atlas = ImGui::GetIO().Fonts;
- ShowHelpMarker("Read FAQ and misc/fonts/README.txt for details on font loading.");
+ ImGuiIO& io = ImGui::GetIO();
+ ImFontAtlas* atlas = io.Fonts;
+ HelpMarker("Read FAQ and misc/fonts/README.txt for details on font loading.");
ImGui::PushItemWidth(120);
for (int i = 0; i < atlas->Fonts.Size; i++)
{
ImFont* font = atlas->Fonts[i];
ImGui::PushID(font);
bool font_details_opened = ImGui::TreeNode(font, "Font %d: \"%s\"\n%.2f px, %d glyphs, %d file(s)", i, font->ConfigData ? font->ConfigData[0].Name : "", font->FontSize, font->Glyphs.Size, font->ConfigDataCount);
- ImGui::SameLine(); if (ImGui::SmallButton("Set as default")) ImGui::GetIO().FontDefault = font;
+ ImGui::SameLine(); if (ImGui::SmallButton("Set as default")) { io.FontDefault = font; }
if (font_details_opened)
{
ImGui::PushFont(font);
ImGui::Text("The quick brown fox jumps over the lazy dog");
ImGui::PopFont();
ImGui::DragFloat("Font scale", &font->Scale, 0.005f, 0.3f, 2.0f, "%.1f"); // Scale only this font
- ImGui::SameLine(); ShowHelpMarker("Note than the default embedded font is NOT meant to be scaled.\n\nFont are currently rendered into bitmaps at a given size at the time of building the atlas. You may oversample them to get some flexibility with scaling. You can also render at multiple sizes and select which one to use at runtime.\n\n(Glimmer of hope: the atlas system should hopefully be rewritten in the future to make scaling more natural and automatic.)");
+ ImGui::SameLine(); HelpMarker("Note than the default embedded font is NOT meant to be scaled.\n\nFont are currently rendered into bitmaps at a given size at the time of building the atlas. You may oversample them to get some flexibility with scaling. You can also render at multiple sizes and select which one to use at runtime.\n\n(Glimmer of hope: the atlas system should hopefully be rewritten in the future to make scaling more natural and automatic.)");
ImGui::InputFloat("Font offset", &font->DisplayOffset.y, 1, 1, "%.0f");
ImGui::Text("Ascent: %f, Descent: %f, Height: %f", font->Ascent, font->Descent, font->Ascent - font->Descent);
ImGui::Text("Fallback character: '%c' (%d)", font->FallbackChar, font->FallbackChar);
- ImGui::Text("Texture surface: %d pixels (approx) ~ %dx%d", font->MetricsTotalSurface, (int)sqrtf((float)font->MetricsTotalSurface), (int)sqrtf((float)font->MetricsTotalSurface));
+ const float surface_sqrt = sqrtf((float)font->MetricsTotalSurface);
+ ImGui::Text("Texture surface: %d pixels (approx) ~ %dx%d", font->MetricsTotalSurface, (int)surface_sqrt, (int)surface_sqrt);
for (int config_i = 0; config_i < font->ConfigDataCount; config_i++)
- if (ImFontConfig* cfg = &font->ConfigData[config_i])
+ if (const ImFontConfig* cfg = &font->ConfigData[config_i])
ImGui::BulletText("Input %d: \'%s\', Oversample: (%d,%d), PixelSnapH: %d", config_i, cfg->Name, cfg->OversampleH, cfg->OversampleV, cfg->PixelSnapH);
if (ImGui::TreeNode("Glyphs", "Glyphs (%d)", font->Glyphs.Size))
{
@@ -3036,14 +3413,17 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
}
if (ImGui::TreeNode("Atlas texture", "Atlas texture (%dx%d pixels)", atlas->TexWidth, atlas->TexHeight))
{
- ImGui::Image(atlas->TexID, ImVec2((float)atlas->TexWidth, (float)atlas->TexHeight), ImVec2(0, 0), ImVec2(1, 1), ImColor(255, 255, 255, 255), ImColor(255, 255, 255, 128));
+ ImVec4 tint_col = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
+ ImVec4 border_col = ImVec4(1.0f, 1.0f, 1.0f, 0.5f);
+ ImGui::Image(atlas->TexID, ImVec2((float)atlas->TexWidth, (float)atlas->TexHeight), ImVec2(0, 0), ImVec2(1, 1), tint_col, border_col);
ImGui::TreePop();
}
+ HelpMarker("Those are old settings provided for convenience.\nHowever, the _correct_ way of scaling your UI is currently to reload your font at the designed size, rebuild the font atlas, and call style.ScaleAllSizes() on a reference ImGuiStyle structure.");
static float window_scale = 1.0f;
- if (ImGui::DragFloat("this window scale", &window_scale, 0.005f, 0.3f, 2.0f, "%.1f")) // scale only this window
+ if (ImGui::DragFloat("window scale", &window_scale, 0.005f, 0.3f, 2.0f, "%.2f")) // scale only this window
ImGui::SetWindowFontScale(window_scale);
- ImGui::DragFloat("global scale", &ImGui::GetIO().FontGlobalScale, 0.005f, 0.3f, 2.0f, "%.1f"); // scale everything
+ ImGui::DragFloat("global scale", &io.FontGlobalScale, 0.005f, 0.3f, 2.0f, "%.2f"); // scale everything
ImGui::PopItemWidth();
ImGui::EndTabItem();
@@ -3051,7 +3431,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
if (ImGui::BeginTabItem("Rendering"))
{
- ImGui::Checkbox("Anti-aliased lines", &style.AntiAliasedLines); ImGui::SameLine(); ShowHelpMarker("When disabling anti-aliasing lines, you'll probably want to disable borders in your style as well.");
+ ImGui::Checkbox("Anti-aliased lines", &style.AntiAliasedLines); ImGui::SameLine(); HelpMarker("When disabling anti-aliasing lines, you'll probably want to disable borders in your style as well.");
ImGui::Checkbox("Anti-aliased fill", &style.AntiAliasedFill);
ImGui::PushItemWidth(100);
ImGui::DragFloat("Curve Tessellation Tolerance", &style.CurveTessellationTol, 0.02f, 0.10f, FLT_MAX, "%.2f", 2.0f);
@@ -3072,7 +3452,10 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
// [SECTION] Example App: Main Menu Bar / ShowExampleAppMainMenuBar()
//-----------------------------------------------------------------------------
-// Demonstrate creating a fullscreen menu bar and populating it.
+// Demonstrate creating a "main" fullscreen menu bar and populating it.
+// Note the difference between BeginMainMenuBar() and BeginMenuBar():
+// - BeginMenuBar() = menu-bar inside current window we Begin()-ed into (the window needs the ImGuiWindowFlags_MenuBar flag)
+// - BeginMainMenuBar() = helper to create menu-bar-sized window at the top of the main viewport + call BeginMenuBar() into it.
static void ShowExampleAppMainMenuBar()
{
if (ImGui::BeginMainMenuBar())
@@ -3096,6 +3479,7 @@ static void ShowExampleAppMainMenuBar()
}
}
+// Note that shortcuts are currently provided for display only (future version will add flags to BeginMenu to process shortcuts)
static void ShowExampleMenuFile()
{
ImGui::MenuItem("(dummy menu)", NULL, false, false);
@@ -3171,10 +3555,12 @@ struct ExampleAppConsole
{
char InputBuf[256];
ImVector Items;
- bool ScrollToBottom;
+ ImVector Commands;
ImVector History;
int HistoryPos; // -1: new line, 0..History.Size-1 browsing history.
- ImVector Commands;
+ ImGuiTextFilter Filter;
+ bool AutoScroll;
+ bool ScrollToBottom;
ExampleAppConsole()
{
@@ -3185,6 +3571,8 @@ struct ExampleAppConsole
Commands.push_back("HISTORY");
Commands.push_back("CLEAR");
Commands.push_back("CLASSIFY"); // "classify" is only here to provide an example of "C"+[tab] completing to "CL" and displaying matches.
+ AutoScroll = true;
+ ScrollToBottom = false;
AddLog("Welcome to Dear ImGui!");
}
~ExampleAppConsole()
@@ -3205,7 +3593,6 @@ struct ExampleAppConsole
for (int i = 0; i < Items.Size; i++)
free(Items[i]);
Items.clear();
- ScrollToBottom = true;
}
void AddLog(const char* fmt, ...) IM_FMTARGS(2)
@@ -3218,7 +3605,6 @@ struct ExampleAppConsole
buf[IM_ARRAYSIZE(buf)-1] = 0;
va_end(args);
Items.push_back(Strdup(buf));
- ScrollToBottom = true;
}
void Draw(const char* title, bool* p_open)
@@ -3244,19 +3630,26 @@ struct ExampleAppConsole
// TODO: display items starting from the bottom
- 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 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("Clear")) { ClearLog(); } ImGui::SameLine();
- bool copy_to_clipboard = ImGui::SmallButton("Copy"); ImGui::SameLine();
- if (ImGui::SmallButton("Scroll to bottom")) ScrollToBottom = true;
+ bool copy_to_clipboard = ImGui::SmallButton("Copy");
//static float t = 0.0f; if (ImGui::GetTime() - t > 0.02f) { t = ImGui::GetTime(); AddLog("Spam %f", t); }
ImGui::Separator();
- ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0,0));
- static ImGuiTextFilter filter;
- filter.Draw("Filter (\"incl,-excl\") (\"error\")", 180);
- ImGui::PopStyleVar();
+ // Options menu
+ if (ImGui::BeginPopup("Options"))
+ {
+ ImGui::Checkbox("Auto-scroll", &AutoScroll);
+ ImGui::EndPopup();
+ }
+
+ // Options, Filter
+ if (ImGui::Button("Options"))
+ ImGui::OpenPopup("Options");
+ ImGui::SameLine();
+ Filter.Draw("Filter (\"incl,-excl\") (\"error\")", 180);
ImGui::Separator();
const float footer_height_to_reserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing(); // 1 separator, 1 input text
@@ -3281,24 +3674,27 @@ struct ExampleAppConsole
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4,1)); // Tighten spacing
if (copy_to_clipboard)
ImGui::LogToClipboard();
- ImVec4 col_default_text = ImGui::GetStyleColorVec4(ImGuiCol_Text);
for (int i = 0; i < Items.Size; i++)
{
const char* item = Items[i];
- if (!filter.PassFilter(item))
+ if (!Filter.PassFilter(item))
continue;
- ImVec4 col = col_default_text;
- if (strstr(item, "[error]")) col = ImColor(1.0f,0.4f,0.4f,1.0f);
- else if (strncmp(item, "# ", 2) == 0) col = ImColor(1.0f,0.78f,0.58f,1.0f);
- ImGui::PushStyleColor(ImGuiCol_Text, col);
+
+ // Normally you would store more information in your item (e.g. make Items[] an array of structure, store color/type etc.)
+ bool pop_color = false;
+ if (strstr(item, "[error]")) { ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.4f, 0.4f, 1.0f)); pop_color = true; }
+ else if (strncmp(item, "# ", 2) == 0) { ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.8f, 0.6f, 1.0f)); pop_color = true; }
ImGui::TextUnformatted(item);
- ImGui::PopStyleColor();
+ if (pop_color)
+ ImGui::PopStyleColor();
}
if (copy_to_clipboard)
ImGui::LogFinish();
- if (ScrollToBottom)
+
+ if (ScrollToBottom || (AutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY()))
ImGui::SetScrollHereY(1.0f);
ScrollToBottom = false;
+
ImGui::PopStyleVar();
ImGui::EndChild();
ImGui::Separator();
@@ -3359,6 +3755,9 @@ struct ExampleAppConsole
{
AddLog("Unknown command: '%s'\n", command_line);
}
+
+ // On commad input, we scroll to bottom even if AutoScroll==false
+ ScrollToBottom = true;
}
static int TextEditCallbackStub(ImGuiInputTextCallbackData* data) // In C++11 you are better off using lambdas for this sort of forwarding callbacks
@@ -3487,11 +3886,11 @@ struct ExampleAppLog
ImGuiTextBuffer Buf;
ImGuiTextFilter Filter;
ImVector LineOffsets; // Index to lines offset. We maintain this with AddLog() calls, allowing us to have a random access on lines
- bool ScrollToBottom;
+ bool AutoScroll; // Keep scrolling if already at the bottom
ExampleAppLog()
{
- ScrollToBottom = false;
+ AutoScroll = true;
Clear();
}
@@ -3512,7 +3911,6 @@ struct ExampleAppLog
for (int new_size = Buf.size(); old_size < new_size; old_size++)
if (Buf[old_size] == '\n')
LineOffsets.push_back(old_size + 1);
- ScrollToBottom = true;
}
void Draw(const char* title, bool* p_open = NULL)
@@ -3522,13 +3920,29 @@ struct ExampleAppLog
ImGui::End();
return;
}
- if (ImGui::Button("Clear")) Clear();
+
+ // Options menu
+ if (ImGui::BeginPopup("Options"))
+ {
+ ImGui::Checkbox("Auto-scroll", &AutoScroll);
+ ImGui::EndPopup();
+ }
+
+ // Main window
+ if (ImGui::Button("Options"))
+ ImGui::OpenPopup("Options");
+ ImGui::SameLine();
+ bool clear = ImGui::Button("Clear");
ImGui::SameLine();
bool copy = ImGui::Button("Copy");
ImGui::SameLine();
Filter.Draw("Filter", -100.0f);
+
ImGui::Separator();
ImGui::BeginChild("scrolling", ImVec2(0,0), false, ImGuiWindowFlags_HorizontalScrollbar);
+
+ if (clear)
+ Clear();
if (copy)
ImGui::LogToClipboard();
@@ -3537,6 +3951,10 @@ struct ExampleAppLog
const char* buf_end = Buf.end();
if (Filter.IsActive())
{
+ // In this example we don't use the clipper when Filter is enabled.
+ // This is because we don't have a random access on the result on our filter.
+ // A real application processing logs with ten of thousands of entries may want to store the result of search/filter.
+ // especially if the filtering function is not trivial (e.g. reg-exp).
for (int line_no = 0; line_no < LineOffsets.Size; line_no++)
{
const char* line_start = buf + LineOffsets[line_no];
@@ -3571,9 +3989,9 @@ struct ExampleAppLog
}
ImGui::PopStyleVar();
- if (ScrollToBottom)
+ if (AutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY())
ImGui::SetScrollHereY(1.0f);
- ScrollToBottom = false;
+
ImGui::EndChild();
ImGui::End();
}
@@ -3584,11 +4002,12 @@ static void ShowExampleAppLog(bool* p_open)
{
static ExampleAppLog log;
- // For the demo: add a debug button before the normal log window contents
- // We take advantage of the fact that multiple calls to Begin()/End() are appending to the same window.
+ // For the demo: add a debug button _BEFORE_ the normal log window contents
+ // We take advantage of a rarely used feature: multiple calls to Begin()/End() are appending to the _same_ window.
+ // Most of the contents of the window will be added by the log.Draw() call.
ImGui::SetNextWindowSize(ImVec2(500, 400), ImGuiCond_FirstUseEver);
ImGui::Begin("Example: Log", p_open);
- if (ImGui::SmallButton("Add 5 entries"))
+ if (ImGui::SmallButton("[Debug] Add 5 entries"))
{
static int counter = 0;
for (int n = 0; n < 5; n++)
@@ -3602,6 +4021,7 @@ static void ShowExampleAppLog(bool* p_open)
}
ImGui::End();
+ // Actually call in the regular Log helper (which will Begin() into the same window as we just did)
log.Draw("Example: Log", p_open);
}
@@ -3680,7 +4100,7 @@ static void ShowExampleAppPropertyEditor(bool* p_open)
return;
}
- ShowHelpMarker("This example shows how you may implement a property editor using two columns.\nAll objects/fields data are dummies here.\nRemember that in many simple cases, you can use ImGui::SameLine(xxx) to position\nyour cursor horizontally instead of using the Columns() API.");
+ HelpMarker("This example shows how you may implement a property editor using two columns.\nAll objects/fields data are dummies here.\nRemember that in many simple cases, you can use ImGui::SameLine(xxx) to position\nyour cursor horizontally instead of using the Columns() API.");
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2,2));
ImGui::Columns(2);
@@ -3713,12 +4133,11 @@ static void ShowExampleAppPropertyEditor(bool* p_open)
ImGui::AlignTextToFramePadding();
ImGui::TreeNodeEx("Field", ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_Bullet, "Field_%d", i);
ImGui::NextColumn();
- ImGui::PushItemWidth(-1);
+ ImGui::SetNextItemWidth(-1);
if (i >= 5)
ImGui::InputFloat("##value", &dummy_members[i], 1.0f);
else
ImGui::DragFloat("##value", &dummy_members[i], 0.01f);
- ImGui::PopItemWidth();
ImGui::NextColumn();
}
ImGui::PopID();
@@ -3757,7 +4176,7 @@ static void ShowExampleAppLongText(bool* p_open)
static ImGuiTextBuffer log;
static int lines = 0;
ImGui::Text("Printing unusually long amount of text.");
- ImGui::Combo("Test type", &test_type, "Single call to TextUnformatted()\0Multiple calls to Text(), clipped manually\0Multiple calls to Text(), not clipped (slow)\0");
+ ImGui::Combo("Test type", &test_type, "Single call to TextUnformatted()\0Multiple calls to Text(), clipped\0Multiple calls to Text(), not clipped (slow)\0");
ImGui::Text("Buffer contents: %d lines, %d bytes", lines, log.size());
if (ImGui::Button("Clear")) { log.clear(); lines = 0; }
ImGui::SameLine();
@@ -3860,10 +4279,10 @@ static void ShowExampleAppConstrainedResize(bool* p_open)
if (ImGui::Button("200x200")) { ImGui::SetWindowSize(ImVec2(200, 200)); } ImGui::SameLine();
if (ImGui::Button("500x500")) { ImGui::SetWindowSize(ImVec2(500, 500)); } ImGui::SameLine();
if (ImGui::Button("800x200")) { ImGui::SetWindowSize(ImVec2(800, 200)); }
- ImGui::PushItemWidth(200);
+ ImGui::SetNextItemWidth(200);
ImGui::Combo("Constraint", &type, desc, IM_ARRAYSIZE(desc));
+ ImGui::SetNextItemWidth(200);
ImGui::DragInt("Lines", &display_lines, 0.2f, 1, 100);
- ImGui::PopItemWidth();
ImGui::Checkbox("Auto-resize", &auto_resize);
for (int i = 0; i < display_lines; i++)
ImGui::Text("%*sHello, sailor! Making this line long enough for the example.", i * 4, "");
@@ -3878,7 +4297,7 @@ static void ShowExampleAppConstrainedResize(bool* p_open)
// Demonstrate creating a simple static window with no decoration + a context-menu to choose which corner of the screen to use.
static void ShowExampleAppSimpleOverlay(bool* p_open)
{
- // FIXME-VIEWPORT-ABS: Select a default viewport
+ // FIXME-VIEWPORT: Select a default viewport
const float DISTANCE = 10.0f;
static int corner = 0;
ImGuiIO& io = ImGui::GetIO();
@@ -3890,7 +4309,7 @@ static void ShowExampleAppSimpleOverlay(bool* p_open)
ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot);
ImGui::SetNextWindowViewport(viewport->ID);
}
- ImGui::SetNextWindowBgAlpha(0.3f); // Transparent background
+ ImGui::SetNextWindowBgAlpha(0.35f); // Transparent background
if (ImGui::Begin("Example: Simple overlay", p_open, (corner != -1 ? ImGuiWindowFlags_NoMove : 0) | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav))
{
ImGui::Text("Simple overlay\n" "in the corner of the screen.\n" "(right-click to change position)");
@@ -3951,7 +4370,6 @@ static void ShowExampleAppWindowTitles(bool*)
// Demonstrate using the low-level ImDrawList to draw custom shapes.
static void ShowExampleAppCustomRendering(bool* p_open)
{
- ImGui::SetNextWindowSize(ImVec2(350, 560), ImGuiCond_FirstUseEver);
if (!ImGui::Begin("Example: Custom rendering", p_open))
{
ImGui::End();
@@ -3964,97 +4382,129 @@ static void ShowExampleAppCustomRendering(bool* p_open)
// In this example we are not using the maths operators!
ImDrawList* draw_list = ImGui::GetWindowDrawList();
- // Primitives
- ImGui::Text("Primitives");
- static float sz = 36.0f;
- static float thickness = 4.0f;
- static ImVec4 col = ImVec4(1.0f, 1.0f, 0.4f, 1.0f);
- ImGui::DragFloat("Size", &sz, 0.2f, 2.0f, 72.0f, "%.0f");
- ImGui::DragFloat("Thickness", &thickness, 0.05f, 1.0f, 8.0f, "%.02f");
- ImGui::ColorEdit4("Color", &col.x);
+ if (ImGui::BeginTabBar("##TabBar"))
{
- const ImVec2 p = ImGui::GetCursorScreenPos();
- const ImU32 col32 = ImColor(col);
- float x = p.x + 4.0f, y = p.y + 4.0f, spacing = 8.0f;
- for (int n = 0; n < 2; n++)
- {
- // First line uses a thickness of 1.0, second line uses the configurable thickness
- float th = (n == 0) ? 1.0f : thickness;
- draw_list->AddCircle(ImVec2(x+sz*0.5f, y+sz*0.5f), sz*0.5f, col32, 6, th); x += sz+spacing; // Hexagon
- draw_list->AddCircle(ImVec2(x+sz*0.5f, y+sz*0.5f), sz*0.5f, col32, 20, th); x += sz+spacing; // Circle
- draw_list->AddRect(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, 0.0f, ImDrawCornerFlags_All, th); x += sz+spacing;
- draw_list->AddRect(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, 10.0f, ImDrawCornerFlags_All, th); x += sz+spacing;
- draw_list->AddRect(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, 10.0f, ImDrawCornerFlags_TopLeft|ImDrawCornerFlags_BotRight, th); x += sz+spacing;
- draw_list->AddTriangle(ImVec2(x+sz*0.5f, y), ImVec2(x+sz,y+sz-0.5f), ImVec2(x,y+sz-0.5f), col32, th); x += sz+spacing;
- draw_list->AddLine(ImVec2(x, y), ImVec2(x+sz, y ), col32, th); x += sz+spacing; // Horizontal line (note: drawing a filled rectangle will be faster!)
- draw_list->AddLine(ImVec2(x, y), ImVec2(x, y+sz), col32, th); x += spacing; // Vertical line (note: drawing a filled rectangle will be faster!)
- draw_list->AddLine(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, th); x += sz+spacing; // Diagonal line
- draw_list->AddBezierCurve(ImVec2(x, y), ImVec2(x+sz*1.3f,y+sz*0.3f), ImVec2(x+sz-sz*1.3f,y+sz-sz*0.3f), ImVec2(x+sz, y+sz), col32, th);
- x = p.x + 4;
- y += sz+spacing;
- }
- draw_list->AddCircleFilled(ImVec2(x+sz*0.5f, y+sz*0.5f), sz*0.5f, col32, 6); x += sz+spacing; // Hexagon
- draw_list->AddCircleFilled(ImVec2(x+sz*0.5f, y+sz*0.5f), sz*0.5f, col32, 32); x += sz+spacing; // Circle
- draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x+sz, y+sz), col32); x += sz+spacing;
- draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, 10.0f); x += sz+spacing;
- draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x+sz, y+sz), col32, 10.0f, ImDrawCornerFlags_TopLeft|ImDrawCornerFlags_BotRight); x += sz+spacing;
- draw_list->AddTriangleFilled(ImVec2(x+sz*0.5f, y), ImVec2(x+sz,y+sz-0.5f), ImVec2(x,y+sz-0.5f), col32); x += sz+spacing;
- draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x+sz, y+thickness), col32); x += sz+spacing; // Horizontal line (faster than AddLine, but only handle integer thickness)
- draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x+thickness, y+sz), col32); x += spacing+spacing; // Vertical line (faster than AddLine, but only handle integer thickness)
- draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x+1, y+1), col32); x += sz; // Pixel (faster than AddLine)
- draw_list->AddRectFilledMultiColor(ImVec2(x, y), ImVec2(x+sz, y+sz), IM_COL32(0,0,0,255), IM_COL32(255,0,0,255), IM_COL32(255,255,0,255), IM_COL32(0,255,0,255));
- ImGui::Dummy(ImVec2((sz+spacing)*8, (sz+spacing)*3));
- }
- ImGui::Separator();
- {
- static ImVector points;
- static bool adding_line = false;
- ImGui::Text("Canvas example");
- if (ImGui::Button("Clear")) points.clear();
- if (points.Size >= 2) { ImGui::SameLine(); if (ImGui::Button("Undo")) { points.pop_back(); points.pop_back(); } }
- ImGui::Text("Left-click and drag to add lines,\nRight-click to undo");
-
- // Here we are using InvisibleButton() as a convenience to 1) advance the cursor and 2) allows us to use IsItemHovered()
- // But you can also draw directly and poll mouse/keyboard by yourself. You can manipulate the cursor using GetCursorPos() and SetCursorPos().
- // If you only use the ImDrawList API, you can notify the owner window of its extends by using SetCursorPos(max).
- ImVec2 canvas_pos = ImGui::GetCursorScreenPos(); // ImDrawList API uses screen coordinates!
- ImVec2 canvas_size = ImGui::GetContentRegionAvail(); // Resize canvas to what's available
- if (canvas_size.x < 50.0f) canvas_size.x = 50.0f;
- if (canvas_size.y < 50.0f) canvas_size.y = 50.0f;
- draw_list->AddRectFilledMultiColor(canvas_pos, ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y), IM_COL32(50, 50, 50, 255), IM_COL32(50, 50, 60, 255), IM_COL32(60, 60, 70, 255), IM_COL32(50, 50, 60, 255));
- draw_list->AddRect(canvas_pos, ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y), IM_COL32(255, 255, 255, 255));
-
- bool adding_preview = false;
- ImGui::InvisibleButton("canvas", canvas_size);
- ImVec2 mouse_pos_in_canvas = ImVec2(ImGui::GetIO().MousePos.x - canvas_pos.x, ImGui::GetIO().MousePos.y - canvas_pos.y);
- if (adding_line)
- {
- adding_preview = true;
- points.push_back(mouse_pos_in_canvas);
- if (!ImGui::IsMouseDown(0))
- adding_line = adding_preview = false;
+ // Primitives
+ if (ImGui::BeginTabItem("Primitives"))
+ {
+ static float sz = 36.0f;
+ static float thickness = 3.0f;
+ static ImVec4 colf = ImVec4(1.0f, 1.0f, 0.4f, 1.0f);
+ ImGui::DragFloat("Size", &sz, 0.2f, 2.0f, 72.0f, "%.0f");
+ ImGui::DragFloat("Thickness", &thickness, 0.05f, 1.0f, 8.0f, "%.02f");
+ ImGui::ColorEdit4("Color", &colf.x);
+ const ImVec2 p = ImGui::GetCursorScreenPos();
+ const ImU32 col = ImColor(colf);
+ float x = p.x + 4.0f, y = p.y + 4.0f;
+ float spacing = 10.0f;
+ ImDrawCornerFlags corners_none = 0;
+ ImDrawCornerFlags corners_all = ImDrawCornerFlags_All;
+ ImDrawCornerFlags corners_tl_br = ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_BotRight;
+ for (int n = 0; n < 2; n++)
+ {
+ // First line uses a thickness of 1.0f, second line uses the configurable thickness
+ float th = (n == 0) ? 1.0f : thickness;
+ draw_list->AddCircle(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, 6, th); x += sz + spacing; // Hexagon
+ draw_list->AddCircle(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, 20, th); x += sz + spacing; // Circle
+ draw_list->AddRect(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 0.0f, corners_none, th); x += sz + spacing; // Square
+ draw_list->AddRect(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f, corners_all, th); x += sz + spacing; // Square with all rounded corners
+ draw_list->AddRect(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f, corners_tl_br, th); x += sz + spacing; // Square with two rounded corners
+ draw_list->AddTriangle(ImVec2(x+sz*0.5f,y), ImVec2(x+sz, y+sz-0.5f), ImVec2(x, y+sz-0.5f), col, th); x += sz + spacing; // Triangle
+ draw_list->AddTriangle(ImVec2(x+sz*0.2f,y), ImVec2(x, y+sz-0.5f), ImVec2(x+sz*0.4f, y+sz-0.5f), col, th); x += sz*0.4f + spacing; // Thin triangle
+ draw_list->AddLine(ImVec2(x, y), ImVec2(x + sz, y), col, th); x += sz + spacing; // Horizontal line (note: drawing a filled rectangle will be faster!)
+ draw_list->AddLine(ImVec2(x, y), ImVec2(x, y + sz), col, th); x += spacing; // Vertical line (note: drawing a filled rectangle will be faster!)
+ draw_list->AddLine(ImVec2(x, y), ImVec2(x + sz, y + sz), col, th); x += sz + spacing; // Diagonal line
+ draw_list->AddBezierCurve(ImVec2(x, y), ImVec2(x + sz*1.3f, y + sz*0.3f), ImVec2(x + sz - sz*1.3f, y + sz - sz*0.3f), ImVec2(x + sz, y + sz), col, th);
+ x = p.x + 4;
+ y += sz + spacing;
+ }
+ draw_list->AddCircleFilled(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, 6); x += sz + spacing; // Hexagon
+ draw_list->AddCircleFilled(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, 32); x += sz + spacing; // Circle
+ draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + sz), col); x += sz + spacing; // Square
+ draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f); x += sz + spacing; // Square with all rounded corners
+ draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f, corners_tl_br); x += sz + spacing; // Square with two rounded corners
+ draw_list->AddTriangleFilled(ImVec2(x+sz*0.5f,y), ImVec2(x+sz, y+sz-0.5f), ImVec2(x, y+sz-0.5f), col); x += sz + spacing; // Triangle
+ draw_list->AddTriangleFilled(ImVec2(x+sz*0.2f,y), ImVec2(x, y+sz-0.5f), ImVec2(x+sz*0.4f, y+sz-0.5f), col); x += sz*0.4f + spacing; // Thin triangle
+ draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + thickness), col); x += sz + spacing; // Horizontal line (faster than AddLine, but only handle integer thickness)
+ draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + thickness, y + sz), col); x += spacing*2.0f; // Vertical line (faster than AddLine, but only handle integer thickness)
+ draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + 1, y + 1), col); x += sz; // Pixel (faster than AddLine)
+ draw_list->AddRectFilledMultiColor(ImVec2(x, y), ImVec2(x + sz, y + sz), IM_COL32(0, 0, 0, 255), IM_COL32(255, 0, 0, 255), IM_COL32(255, 255, 0, 255), IM_COL32(0, 255, 0, 255));
+ ImGui::Dummy(ImVec2((sz + spacing) * 9.8f, (sz + spacing) * 3));
+ ImGui::EndTabItem();
}
- if (ImGui::IsItemHovered())
+
+ if (ImGui::BeginTabItem("Canvas"))
{
- if (!adding_line && ImGui::IsMouseClicked(0))
+ static ImVector points;
+ static bool adding_line = false;
+ if (ImGui::Button("Clear")) points.clear();
+ if (points.Size >= 2) { ImGui::SameLine(); if (ImGui::Button("Undo")) { points.pop_back(); points.pop_back(); } }
+ ImGui::Text("Left-click and drag to add lines,\nRight-click to undo");
+
+ // Here we are using InvisibleButton() as a convenience to 1) advance the cursor and 2) allows us to use IsItemHovered()
+ // But you can also draw directly and poll mouse/keyboard by yourself. You can manipulate the cursor using GetCursorPos() and SetCursorPos().
+ // If you only use the ImDrawList API, you can notify the owner window of its extends by using SetCursorPos(max).
+ ImVec2 canvas_pos = ImGui::GetCursorScreenPos(); // ImDrawList API uses screen coordinates!
+ ImVec2 canvas_size = ImGui::GetContentRegionAvail(); // Resize canvas to what's available
+ if (canvas_size.x < 50.0f) canvas_size.x = 50.0f;
+ if (canvas_size.y < 50.0f) canvas_size.y = 50.0f;
+ draw_list->AddRectFilledMultiColor(canvas_pos, ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y), IM_COL32(50, 50, 50, 255), IM_COL32(50, 50, 60, 255), IM_COL32(60, 60, 70, 255), IM_COL32(50, 50, 60, 255));
+ draw_list->AddRect(canvas_pos, ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y), IM_COL32(255, 255, 255, 255));
+
+ bool adding_preview = false;
+ ImGui::InvisibleButton("canvas", canvas_size);
+ ImVec2 mouse_pos_in_canvas = ImVec2(ImGui::GetIO().MousePos.x - canvas_pos.x, ImGui::GetIO().MousePos.y - canvas_pos.y);
+ if (adding_line)
{
+ adding_preview = true;
points.push_back(mouse_pos_in_canvas);
- adding_line = true;
+ if (!ImGui::IsMouseDown(0))
+ adding_line = adding_preview = false;
}
- if (ImGui::IsMouseClicked(1) && !points.empty())
+ if (ImGui::IsItemHovered())
{
- adding_line = adding_preview = false;
- points.pop_back();
- points.pop_back();
+ if (!adding_line && ImGui::IsMouseClicked(0))
+ {
+ points.push_back(mouse_pos_in_canvas);
+ adding_line = true;
+ }
+ if (ImGui::IsMouseClicked(1) && !points.empty())
+ {
+ adding_line = adding_preview = false;
+ points.pop_back();
+ points.pop_back();
+ }
}
+ draw_list->PushClipRect(canvas_pos, ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y), true); // clip lines within the canvas (if we resize it, etc.)
+ for (int i = 0; i < points.Size - 1; i += 2)
+ draw_list->AddLine(ImVec2(canvas_pos.x + points[i].x, canvas_pos.y + points[i].y), ImVec2(canvas_pos.x + points[i + 1].x, canvas_pos.y + points[i + 1].y), IM_COL32(255, 255, 0, 255), 2.0f);
+ draw_list->PopClipRect();
+ if (adding_preview)
+ points.pop_back();
+ ImGui::EndTabItem();
}
- draw_list->PushClipRect(canvas_pos, ImVec2(canvas_pos.x + canvas_size.x, canvas_pos.y + canvas_size.y), true); // clip lines within the canvas (if we resize it, etc.)
- for (int i = 0; i < points.Size - 1; i += 2)
- draw_list->AddLine(ImVec2(canvas_pos.x + points[i].x, canvas_pos.y + points[i].y), ImVec2(canvas_pos.x + points[i + 1].x, canvas_pos.y + points[i + 1].y), IM_COL32(255, 255, 0, 255), 2.0f);
- draw_list->PopClipRect();
- if (adding_preview)
- points.pop_back();
+
+ if (ImGui::BeginTabItem("BG/FG draw lists"))
+ {
+ static bool draw_bg = true;
+ static bool draw_fg = true;
+ ImGui::Checkbox("Draw in Background draw list", &draw_bg);
+ ImGui::SameLine(); HelpMarker("The Background draw list will be rendered below every Dear ImGui windows.");
+ ImGui::Checkbox("Draw in Foreground draw list", &draw_fg);
+ ImGui::SameLine(); HelpMarker("The Foreground draw list will be rendered over every Dear ImGui windows.");
+ ImVec2 window_pos = ImGui::GetWindowPos();
+ ImVec2 window_size = ImGui::GetWindowSize();
+ ImVec2 window_center = ImVec2(window_pos.x + window_size.x * 0.5f, window_pos.y + window_size.y * 0.5f);
+ if (draw_bg)
+ ImGui::GetBackgroundDrawList()->AddCircle(window_center, window_size.x * 0.6f, IM_COL32(255, 0, 0, 200), 48, 10+4);
+ if (draw_fg)
+ ImGui::GetForegroundDrawList()->AddCircle(window_center, window_size.y * 0.6f, IM_COL32(0, 255, 0, 200), 48, 10);
+ ImGui::EndTabItem();
+ }
+
+ ImGui::EndTabBar();
}
+
ImGui::End();
}
@@ -4063,13 +4513,14 @@ static void ShowExampleAppCustomRendering(bool* p_open)
//-----------------------------------------------------------------------------
// Demonstrate using DockSpace() to create an explicit docking node within an existing window.
-// Note that you already dock windows into each others _without_ a DockSpace() by just holding SHIFT when moving a window.
+// Note that you already dock windows into each others _without_ a DockSpace() by just moving windows
+// from their title bar (or by holding SHIFT if io.ConfigDockingWithShift is set).
// DockSpace() is only useful to construct to a central location for your application.
void ShowExampleAppDockSpace(bool* p_open)
{
static bool opt_fullscreen_persistant = true;
- static ImGuiDockNodeFlags opt_flags = ImGuiDockNodeFlags_None;
bool opt_fullscreen = opt_fullscreen_persistant;
+ static ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_None;
// We are using the ImGuiWindowFlags_NoDocking flag to make the parent window not dockable into,
// because it would be confusing to have two docking targets within each others.
@@ -4086,10 +4537,15 @@ void ShowExampleAppDockSpace(bool* p_open)
window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;
}
- // When using ImGuiDockNodeFlags_PassthruDockspace, DockSpace() will render our background and handle the pass-thru hole, so we ask Begin() to not render a background.
- if (opt_flags & ImGuiDockNodeFlags_PassthruDockspace)
+ // When using ImGuiDockNodeFlags_PassthruCentralNode, DockSpace() will render our background and handle the pass-thru hole, so we ask Begin() to not render a background.
+ if (dockspace_flags & ImGuiDockNodeFlags_PassthruCentralNode)
window_flags |= ImGuiWindowFlags_NoBackground;
+ // Important: note that we proceed even if Begin() returns false (aka window is collapsed).
+ // This is because we want to keep our DockSpace() active. If a DockSpace() is inactive,
+ // all active windows docked into it will lose their parent and become undocked.
+ // We cannot preserve the docking relationship between an active window and an inactive docking, otherwise
+ // any change of dockspace/settings would lead to windows being stuck in limbo and never being visible.
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
ImGui::Begin("DockSpace Demo", p_open, window_flags);
ImGui::PopStyleVar();
@@ -4097,12 +4553,12 @@ void ShowExampleAppDockSpace(bool* p_open)
if (opt_fullscreen)
ImGui::PopStyleVar(2);
- // Dockspace
+ // DockSpace
ImGuiIO& io = ImGui::GetIO();
if (io.ConfigFlags & ImGuiConfigFlags_DockingEnable)
{
- ImGuiID dockspace_id = ImGui::GetID("MyDockspace");
- ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), opt_flags);
+ ImGuiID dockspace_id = ImGui::GetID("MyDockSpace");
+ ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags);
}
else
{
@@ -4117,18 +4573,22 @@ void ShowExampleAppDockSpace(bool* p_open)
// which we can't undo at the moment without finer window depth/z control.
//ImGui::MenuItem("Fullscreen", NULL, &opt_fullscreen_persistant);
- if (ImGui::MenuItem("Flag: NoSplit", "", (opt_flags & ImGuiDockNodeFlags_NoSplit) != 0)) opt_flags ^= ImGuiDockNodeFlags_NoSplit;
- if (ImGui::MenuItem("Flag: NoDockingInCentralNode", "", (opt_flags & ImGuiDockNodeFlags_NoDockingInCentralNode) != 0)) opt_flags ^= ImGuiDockNodeFlags_NoDockingInCentralNode;
- if (ImGui::MenuItem("Flag: NoResize", "", (opt_flags & ImGuiDockNodeFlags_NoResize) != 0)) opt_flags ^= ImGuiDockNodeFlags_NoResize;
- if (ImGui::MenuItem("Flag: PassthruDockspace", "", (opt_flags & ImGuiDockNodeFlags_PassthruDockspace) != 0)) opt_flags ^= ImGuiDockNodeFlags_PassthruDockspace;
- if (ImGui::MenuItem("Flag: AutoHideTabBar", "", (opt_flags & ImGuiDockNodeFlags_AutoHideTabBar) != 0)) opt_flags ^= ImGuiDockNodeFlags_AutoHideTabBar;
+ if (ImGui::MenuItem("Flag: NoSplit", "", (dockspace_flags & ImGuiDockNodeFlags_NoSplit) != 0)) dockspace_flags ^= ImGuiDockNodeFlags_NoSplit;
+ if (ImGui::MenuItem("Flag: NoResize", "", (dockspace_flags & ImGuiDockNodeFlags_NoResize) != 0)) dockspace_flags ^= ImGuiDockNodeFlags_NoResize;
+ if (ImGui::MenuItem("Flag: NoDockingInCentralNode", "", (dockspace_flags & ImGuiDockNodeFlags_NoDockingInCentralNode) != 0)) dockspace_flags ^= ImGuiDockNodeFlags_NoDockingInCentralNode;
+ if (ImGui::MenuItem("Flag: PassthruCentralNode", "", (dockspace_flags & ImGuiDockNodeFlags_PassthruCentralNode) != 0)) dockspace_flags ^= ImGuiDockNodeFlags_PassthruCentralNode;
+ if (ImGui::MenuItem("Flag: AutoHideTabBar", "", (dockspace_flags & ImGuiDockNodeFlags_AutoHideTabBar) != 0)) dockspace_flags ^= ImGuiDockNodeFlags_AutoHideTabBar;
ImGui::Separator();
if (ImGui::MenuItem("Close DockSpace", NULL, false, p_open != NULL))
*p_open = false;
ImGui::EndMenu();
}
- ShowHelpMarker(
- "You can _always_ dock _any_ window into another by holding the SHIFT key while moving a window. Try it now!" "\n"
+ HelpMarker(
+ "When docking is enabled, you can ALWAYS dock MOST window into another! Try it now!" "\n\n"
+ " > if io.ConfigDockingWithShift==false (default):" "\n"
+ " drag windows from title bar to dock" "\n"
+ " > if io.ConfigDockingWithShift==true:" "\n"
+ " drag windows from anywhere and hold Shift to dock" "\n\n"
"This demo app has nothing to do with it!" "\n\n"
"This demo app only demonstrate the use of ImGui::DockSpace() which allows you to manually create a docking node _within_ another window. This is useful so you can decorate your main application window (e.g. with a menu bar)." "\n\n"
"ImGui::DockSpace() comes with one hard constraint: it needs to be submitted _before_ any window which may be docked into it. Therefore, if you use a dock spot as the central point of your application, you'll probably want it to be part of the very first window you are submitting to imgui every frame." "\n\n"
@@ -4243,13 +4703,13 @@ void ShowExampleAppDocuments(bool* p_open)
{
Target_None,
Target_Tab, // Create documents as local tab into a local tab bar
- Target_DockspaceAndWindow // Create documents as regular windows, and create an embedded dockspace
+ Target_DockSpaceAndWindow // Create documents as regular windows, and create an embedded dockspace
};
static Target opt_target = Target_Tab;
static bool opt_reorderable = true;
static ImGuiTabBarFlags opt_fitting_flags = ImGuiTabBarFlags_FittingPolicyDefault_;
- // When (opt_target == Target_DockspaceAndWindow) there is the possibily that one of our child Document window (e.g. "Eggplant")
+ // When (opt_target == Target_DockSpaceAndWindow) there is the possibily that one of our child Document window (e.g. "Eggplant")
// that we emit gets docked into the same spot as the parent window ("Example: Documents").
// This would create a problematic feedback loop because selecting the "Eggplant" tab would make the "Example: Documents" tab
// not visible, which in turn would stop submitting the "Eggplant" window.
@@ -4257,13 +4717,13 @@ void ShowExampleAppDocuments(bool* p_open)
// Another solution may be to make the "Example: Documents" window use the ImGuiWindowFlags_NoDocking.
bool window_contents_visible = ImGui::Begin("Example: Documents", p_open, ImGuiWindowFlags_MenuBar);
- if (!window_contents_visible && opt_target != Target_DockspaceAndWindow)
+ if (!window_contents_visible && opt_target != Target_DockSpaceAndWindow)
{
ImGui::End();
return;
}
- // Menu Bar
+ // Menu
if (ImGui::BeginMenuBar())
{
if (ImGui::BeginMenu("File"))
@@ -4309,7 +4769,7 @@ void ShowExampleAppDocuments(bool* p_open)
ImGui::PopItemWidth();
bool redock_all = false;
if (opt_target == Target_Tab) { ImGui::SameLine(); ImGui::Checkbox("Reorderable Tabs", &opt_reorderable); }
- if (opt_target == Target_DockspaceAndWindow) { ImGui::SameLine(); redock_all = ImGui::Button("Redock all"); }
+ if (opt_target == Target_DockSpaceAndWindow) { ImGui::SameLine(); redock_all = ImGui::Button("Redock all"); }
ImGui::Separator();
@@ -4354,7 +4814,7 @@ void ShowExampleAppDocuments(bool* p_open)
ImGui::EndTabBar();
}
}
- else if (opt_target == Target_DockspaceAndWindow)
+ else if (opt_target == Target_DockSpaceAndWindow)
{
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_DockingEnable)
{
@@ -4371,9 +4831,6 @@ void ShowExampleAppDocuments(bool* p_open)
if (!doc->Open)
continue;
- // FIXME-DOCK: SetNextWindowDock()
- //ImGuiID default_dock_id = GetDockspaceRootDocumentDockID();
- //ImGuiID default_dock_id = GetDockspacePreferedDocumentDockID();
ImGui::SetNextWindowDockID(dockspace_id, redock_all ? ImGuiCond_Always : ImGuiCond_FirstUseEver);
ImGuiWindowFlags window_flags = (doc->Dirty ? ImGuiWindowFlags_UnsavedDocument : 0);
bool visible = ImGui::Begin(doc->Name, &doc->Open, window_flags);
@@ -4443,12 +4900,14 @@ void ShowExampleAppDocuments(bool* p_open)
if (ImGui::BeginPopupModal("Save?"))
{
ImGui::Text("Save change to the following items?");
- ImGui::PushItemWidth(-1.0f);
- ImGui::ListBoxHeader("##", close_queue_unsaved_documents, 6);
- for (int n = 0; n < close_queue.Size; n++)
- if (close_queue[n]->Dirty)
- ImGui::Text("%s", close_queue[n]->Name);
- ImGui::ListBoxFooter();
+ ImGui::SetNextItemWidth(-1.0f);
+ if (ImGui::ListBoxHeader("##", close_queue_unsaved_documents, 6))
+ {
+ for (int n = 0; n < close_queue.Size; n++)
+ if (close_queue[n]->Dirty)
+ ImGui::Text("%s", close_queue[n]->Name);
+ ImGui::ListBoxFooter();
+ }
if (ImGui::Button("Yes", ImVec2(80, 0)))
{
diff --git a/imgui_draw.cpp b/imgui_draw.cpp
index bcafa0b3..70618bf2 100644
--- a/imgui_draw.cpp
+++ b/imgui_draw.cpp
@@ -1,4 +1,4 @@
-// dear imgui, v1.68 WIP
+// dear imgui, v1.73 WIP
// (drawing and font code)
/*
@@ -8,6 +8,7 @@ Index of this file:
// [SECTION] STB libraries implementation
// [SECTION] Style functions
// [SECTION] ImDrawList
+// [SECTION] ImDrawListSplitter
// [SECTION] ImDrawData
// [SECTION] Helpers ShadeVertsXXX functions
// [SECTION] ImFontConfig
@@ -33,7 +34,7 @@ Index of this file:
#include // vsnprintf, sscanf, printf
#if !defined(alloca)
-#if defined(__GLIBC__) || defined(__sun) || defined(__CYGWIN__) || defined(__APPLE__)
+#if defined(__GLIBC__) || defined(__sun) || defined(__CYGWIN__) || defined(__APPLE__) || defined(__SWITCH__)
#include // alloca (glibc uses . Note that Cygwin may have _WIN32 defined, so the order matters here)
#elif defined(_WIN32)
#include // alloca
@@ -47,15 +48,16 @@ Index of this file:
// Visual Studio warnings
#ifdef _MSC_VER
+#pragma warning (disable: 4127) // condition expression is constant
#pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff)
#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen
#endif
// Clang/GCC warnings with -Weverything
-#ifdef __clang__
+#if defined(__clang__)
#pragma clang diagnostic ignored "-Wold-style-cast" // warning : use of old-style cast // yes, they are more terse.
#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.
+#pragma clang diagnostic ignored "-Wglobal-constructors" // warning : declaration requires a global destructor // similar to above, not sure what the exact difference is.
#pragma clang diagnostic ignored "-Wsign-conversion" // warning : implicit conversion changes signedness //
#if __has_warning("-Wzero-as-null-pointer-constant")
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" // warning : zero as null pointer constant // some standard header variations use #define NULL 0
@@ -70,12 +72,12 @@ Index of this file:
#pragma clang diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function // using printf() is a misery with this as C++ va_arg ellipsis changes float to double.
#endif
#elif defined(__GNUC__)
+#pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind
#pragma GCC diagnostic ignored "-Wunused-function" // warning: 'xxxx' defined but not used
#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
-#if __GNUC__ >= 8
-#pragma GCC diagnostic ignored "-Wclass-memaccess" // warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead
-#endif
+#pragma GCC diagnostic ignored "-Wstack-protector" // warning: stack protector not protecting local variables: variable length buffer
+#pragma GCC diagnostic ignored "-Wclass-memaccess" // [__GNUC__ >= 8] warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead
#endif
//-------------------------------------------------------------------------
@@ -83,7 +85,7 @@ Index of this file:
//-------------------------------------------------------------------------
// Compile time options:
-//#define IMGUI_STB_NAMESPACE ImGuiStb
+//#define IMGUI_STB_NAMESPACE ImStb
//#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h"
//#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h"
//#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
@@ -99,7 +101,7 @@ namespace IMGUI_STB_NAMESPACE
#pragma warning (disable: 4456) // declaration of 'xx' hides previous local declaration
#endif
-#ifdef __clang__
+#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-function"
#pragma clang diagnostic ignored "-Wmissing-prototypes"
@@ -107,7 +109,7 @@ namespace IMGUI_STB_NAMESPACE
#pragma clang diagnostic ignored "-Wcast-qual" // warning : cast from 'const xxxx *' to 'xxx *' drops const qualifier //
#endif
-#ifdef __GNUC__
+#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtype-limits" // warning: comparison is always true due to limited range of data type [-Wtype-limits]
#pragma GCC diagnostic ignored "-Wcast-qual" // warning: cast from type 'const xxxx *' to type 'xxxx *' casts away qualifiers
@@ -129,8 +131,8 @@ namespace IMGUI_STB_NAMESPACE
#ifndef STB_TRUETYPE_IMPLEMENTATION // in case the user already have an implementation in the _same_ compilation unit (e.g. unity builds)
#ifndef IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
-#define STBTT_malloc(x,u) ((void)(u), ImGui::MemAlloc(x))
-#define STBTT_free(x,u) ((void)(u), ImGui::MemFree(x))
+#define STBTT_malloc(x,u) ((void)(u), IM_ALLOC(x))
+#define STBTT_free(x,u) ((void)(u), IM_FREE(x))
#define STBTT_assert(x) IM_ASSERT(x)
#define STBTT_fmod(x,y) ImFmod(x,y)
#define STBTT_sqrt(x) ImSqrt(x)
@@ -150,20 +152,20 @@ namespace IMGUI_STB_NAMESPACE
#endif
#endif
-#ifdef __GNUC__
+#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
-#ifdef __clang__
+#if defined(__clang__)
#pragma clang diagnostic pop
#endif
-#ifdef _MSC_VER
+#if defined(_MSC_VER)
#pragma warning (pop)
#endif
#ifdef IMGUI_STB_NAMESPACE
-} // namespace ImGuiStb
+} // namespace ImStb
using namespace IMGUI_STB_NAMESPACE;
#endif
@@ -260,7 +262,7 @@ void ImGui::StyleColorsClassic(ImGuiStyle* dst)
colors[ImGuiCol_Header] = ImVec4(0.40f, 0.40f, 0.90f, 0.45f);
colors[ImGuiCol_HeaderHovered] = ImVec4(0.45f, 0.45f, 0.90f, 0.80f);
colors[ImGuiCol_HeaderActive] = ImVec4(0.53f, 0.53f, 0.87f, 0.80f);
- colors[ImGuiCol_Separator] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
+ colors[ImGuiCol_Separator] = ImVec4(0.50f, 0.50f, 0.50f, 0.60f);
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.60f, 0.60f, 0.70f, 1.00f);
colors[ImGuiCol_SeparatorActive] = ImVec4(0.70f, 0.70f, 0.90f, 1.00f);
colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.16f);
@@ -318,7 +320,7 @@ void ImGui::StyleColorsLight(ImGuiStyle* dst)
colors[ImGuiCol_Header] = ImVec4(0.26f, 0.59f, 0.98f, 0.31f);
colors[ImGuiCol_HeaderHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.80f);
colors[ImGuiCol_HeaderActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
- colors[ImGuiCol_Separator] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f);
+ colors[ImGuiCol_Separator] = ImVec4(0.39f, 0.39f, 0.39f, 0.62f);
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.14f, 0.44f, 0.80f, 0.78f);
colors[ImGuiCol_SeparatorActive] = ImVec4(0.14f, 0.44f, 0.80f, 1.00f);
colors[ImGuiCol_ResizeGrip] = ImVec4(0.80f, 0.80f, 0.80f, 0.56f);
@@ -353,6 +355,7 @@ ImDrawListSharedData::ImDrawListSharedData()
FontSize = 0.0f;
CurveTessellationTol = 0.0f;
ClipRectFullscreen = ImVec4(-8192.0f, -8192.0f, +8192.0f, +8192.0f);
+ InitialFlags = ImDrawListFlags_None;
// Const data
for (int i = 0; i < IM_ARRAYSIZE(CircleVtx12); i++)
@@ -367,16 +370,15 @@ void ImDrawList::Clear()
CmdBuffer.resize(0);
IdxBuffer.resize(0);
VtxBuffer.resize(0);
- Flags = ImDrawListFlags_AntiAliasedLines | ImDrawListFlags_AntiAliasedFill;
+ Flags = _Data ? _Data->InitialFlags : ImDrawListFlags_None;
+ _VtxCurrentOffset = 0;
_VtxCurrentIdx = 0;
_VtxWritePtr = NULL;
_IdxWritePtr = NULL;
_ClipRectStack.resize(0);
_TextureIdStack.resize(0);
_Path.resize(0);
- _ChannelsCurrent = 0;
- _ChannelsCount = 1;
- // NB: Do not clear channels so our allocations are re-used after the first frame.
+ _Splitter.Clear();
}
void ImDrawList::ClearFreeMemory()
@@ -390,20 +392,12 @@ void ImDrawList::ClearFreeMemory()
_ClipRectStack.clear();
_TextureIdStack.clear();
_Path.clear();
- _ChannelsCurrent = 0;
- _ChannelsCount = 1;
- for (int i = 0; i < _Channels.Size; i++)
- {
- if (i == 0) memset(&_Channels[0], 0, sizeof(_Channels[0])); // channel 0 is a copy of CmdBuffer/IdxBuffer, don't destruct again
- _Channels[i].CmdBuffer.clear();
- _Channels[i].IdxBuffer.clear();
- }
- _Channels.clear();
+ _Splitter.ClearFreeMemory();
}
ImDrawList* ImDrawList::CloneOutput() const
{
- ImDrawList* dst = IM_NEW(ImDrawList(NULL));
+ ImDrawList* dst = IM_NEW(ImDrawList(_Data));
dst->CmdBuffer = CmdBuffer;
dst->IdxBuffer = IdxBuffer;
dst->VtxBuffer = VtxBuffer;
@@ -413,13 +407,15 @@ ImDrawList* ImDrawList::CloneOutput() const
// Using macros because C++ is a terrible language, we want guaranteed inline, no code in header, and no overhead in Debug builds
#define GetCurrentClipRect() (_ClipRectStack.Size ? _ClipRectStack.Data[_ClipRectStack.Size-1] : _Data->ClipRectFullscreen)
-#define GetCurrentTextureId() (_TextureIdStack.Size ? _TextureIdStack.Data[_TextureIdStack.Size-1] : NULL)
+#define GetCurrentTextureId() (_TextureIdStack.Size ? _TextureIdStack.Data[_TextureIdStack.Size-1] : (ImTextureID)NULL)
void ImDrawList::AddDrawCmd()
{
ImDrawCmd draw_cmd;
draw_cmd.ClipRect = GetCurrentClipRect();
draw_cmd.TextureId = GetCurrentTextureId();
+ draw_cmd.VtxOffset = _VtxCurrentOffset;
+ draw_cmd.IdxOffset = IdxBuffer.Size;
IM_ASSERT(draw_cmd.ClipRect.x <= draw_cmd.ClipRect.z && draw_cmd.ClipRect.y <= draw_cmd.ClipRect.w);
CmdBuffer.push_back(draw_cmd);
@@ -526,88 +522,17 @@ void ImDrawList::PopTextureID()
UpdateTextureID();
}
-void ImDrawList::ChannelsSplit(int channels_count)
-{
- IM_ASSERT(_ChannelsCurrent == 0 && _ChannelsCount == 1);
- int old_channels_count = _Channels.Size;
- if (old_channels_count < channels_count)
- _Channels.resize(channels_count);
- _ChannelsCount = channels_count;
-
- // _Channels[] (24/32 bytes each) hold storage that we'll swap with this->_CmdBuffer/_IdxBuffer
- // The content of _Channels[0] at this point doesn't matter. We clear it to make state tidy in a debugger but we don't strictly need to.
- // When we switch to the next channel, we'll copy _CmdBuffer/_IdxBuffer into _Channels[0] and then _Channels[1] into _CmdBuffer/_IdxBuffer
- memset(&_Channels[0], 0, sizeof(ImDrawChannel));
- for (int i = 1; i < channels_count; i++)
- {
- if (i >= old_channels_count)
- {
- IM_PLACEMENT_NEW(&_Channels[i]) ImDrawChannel();
- }
- else
- {
- _Channels[i].CmdBuffer.resize(0);
- _Channels[i].IdxBuffer.resize(0);
- }
- if (_Channels[i].CmdBuffer.Size == 0)
- {
- ImDrawCmd draw_cmd;
- draw_cmd.ClipRect = _ClipRectStack.back();
- draw_cmd.TextureId = _TextureIdStack.back();
- _Channels[i].CmdBuffer.push_back(draw_cmd);
- }
- }
-}
-
-void ImDrawList::ChannelsMerge()
+// NB: this can be called with negative count for removing primitives (as long as the result does not underflow)
+void ImDrawList::PrimReserve(int idx_count, int vtx_count)
{
- // Note that we never use or rely on channels.Size because it is merely a buffer that we never shrink back to 0 to keep all sub-buffers ready for use.
- if (_ChannelsCount <= 1)
- return;
-
- ChannelsSetCurrent(0);
- if (CmdBuffer.Size && CmdBuffer.back().ElemCount == 0)
- CmdBuffer.pop_back();
-
- int new_cmd_buffer_count = 0, new_idx_buffer_count = 0;
- for (int i = 1; i < _ChannelsCount; i++)
+ // Large mesh support (when enabled)
+ if (sizeof(ImDrawIdx) == 2 && (_VtxCurrentIdx + vtx_count >= (1 << 16)) && (Flags & ImDrawListFlags_AllowVtxOffset))
{
- ImDrawChannel& ch = _Channels[i];
- if (ch.CmdBuffer.Size && ch.CmdBuffer.back().ElemCount == 0)
- ch.CmdBuffer.pop_back();
- new_cmd_buffer_count += ch.CmdBuffer.Size;
- new_idx_buffer_count += ch.IdxBuffer.Size;
- }
- CmdBuffer.resize(CmdBuffer.Size + new_cmd_buffer_count);
- IdxBuffer.resize(IdxBuffer.Size + new_idx_buffer_count);
-
- ImDrawCmd* cmd_write = CmdBuffer.Data + CmdBuffer.Size - new_cmd_buffer_count;
- _IdxWritePtr = IdxBuffer.Data + IdxBuffer.Size - new_idx_buffer_count;
- for (int i = 1; i < _ChannelsCount; i++)
- {
- ImDrawChannel& ch = _Channels[i];
- if (int sz = ch.CmdBuffer.Size) { memcpy(cmd_write, ch.CmdBuffer.Data, sz * sizeof(ImDrawCmd)); cmd_write += sz; }
- if (int sz = ch.IdxBuffer.Size) { memcpy(_IdxWritePtr, ch.IdxBuffer.Data, sz * sizeof(ImDrawIdx)); _IdxWritePtr += sz; }
+ _VtxCurrentOffset = VtxBuffer.Size;
+ _VtxCurrentIdx = 0;
+ AddDrawCmd();
}
- UpdateClipRect(); // We call this instead of AddDrawCmd(), so that empty channels won't produce an extra draw call.
- _ChannelsCount = 1;
-}
-void ImDrawList::ChannelsSetCurrent(int idx)
-{
- IM_ASSERT(idx < _ChannelsCount);
- if (_ChannelsCurrent == idx) return;
- memcpy(&_Channels.Data[_ChannelsCurrent].CmdBuffer, &CmdBuffer, sizeof(CmdBuffer)); // copy 12 bytes, four times
- memcpy(&_Channels.Data[_ChannelsCurrent].IdxBuffer, &IdxBuffer, sizeof(IdxBuffer));
- _ChannelsCurrent = idx;
- memcpy(&CmdBuffer, &_Channels.Data[_ChannelsCurrent].CmdBuffer, sizeof(CmdBuffer));
- memcpy(&IdxBuffer, &_Channels.Data[_ChannelsCurrent].IdxBuffer, sizeof(IdxBuffer));
- _IdxWritePtr = IdxBuffer.Data + IdxBuffer.Size;
-}
-
-// NB: this can be called with negative count for removing primitives (as long as the result does not underflow)
-void ImDrawList::PrimReserve(int idx_count, int vtx_count)
-{
ImDrawCmd& draw_cmd = CmdBuffer.Data[CmdBuffer.Size-1];
draw_cmd.ElemCount += idx_count;
@@ -667,8 +592,8 @@ void ImDrawList::PrimQuadUV(const ImVec2& a, const ImVec2& b, const ImVec2& c, c
// On AddPolyline() and AddConvexPolyFilled() we intentionally avoid using ImVec2 and superflous function calls to optimize debug/non-inlined builds.
// Those macros expects l-values.
-#define IM_NORMALIZE2F_OVER_ZERO(VX,VY) { float d2 = VX*VX + VY*VY; if (d2 > 0.0f) { float inv_len = 1.0f / ImSqrt(d2); VX *= inv_len; VY *= inv_len; } }
-#define IM_NORMALIZE2F_OVER_EPSILON_CLAMP(VX,VY,EPS,INVLENMAX) { float d2 = VX*VX + VY*VY; if (d2 > EPS) { float inv_len = 1.0f / ImSqrt(d2); if (inv_len > INVLENMAX) inv_len = INVLENMAX; VX *= inv_len; VY *= inv_len; } }
+#define IM_NORMALIZE2F_OVER_ZERO(VX,VY) { float d2 = VX*VX + VY*VY; if (d2 > 0.0f) { float inv_len = 1.0f / ImSqrt(d2); VX *= inv_len; VY *= inv_len; } }
+#define IM_FIXNORMAL2F(VX,VY) { float d2 = VX*VX + VY*VY; if (d2 < 0.5f) d2 = 0.5f; float inv_lensq = 1.0f / d2; VX *= inv_lensq; VY *= inv_lensq; }
// TODO: Thickness anti-aliased lines cap are missing their AA fringe.
// We avoid using the ImVec2 math operators here to reduce cost to a minimum for debug/non-inlined builds.
@@ -730,7 +655,7 @@ void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32
// Average normals
float dm_x = (temp_normals[i1].x + temp_normals[i2].x) * 0.5f;
float dm_y = (temp_normals[i1].y + temp_normals[i2].y) * 0.5f;
- IM_NORMALIZE2F_OVER_EPSILON_CLAMP(dm_x, dm_y, 0.000001f, 100.0f)
+ IM_FIXNORMAL2F(dm_x, dm_y)
dm_x *= AA_SIZE;
dm_y *= AA_SIZE;
@@ -785,7 +710,7 @@ void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32
// Average normals
float dm_x = (temp_normals[i1].x + temp_normals[i2].x) * 0.5f;
float dm_y = (temp_normals[i1].y + temp_normals[i2].y) * 0.5f;
- IM_NORMALIZE2F_OVER_EPSILON_CLAMP(dm_x, dm_y, 0.000001f, 100.0f);
+ IM_FIXNORMAL2F(dm_x, dm_y);
float dm_out_x = dm_x * (half_inner_thickness + AA_SIZE);
float dm_out_y = dm_y * (half_inner_thickness + AA_SIZE);
float dm_in_x = dm_x * half_inner_thickness;
@@ -905,7 +830,7 @@ void ImDrawList::AddConvexPolyFilled(const ImVec2* points, const int points_coun
const ImVec2& n1 = temp_normals[i1];
float dm_x = (n0.x + n1.x) * 0.5f;
float dm_y = (n0.y + n1.y) * 0.5f;
- IM_NORMALIZE2F_OVER_EPSILON_CLAMP(dm_x, dm_y, 0.000001f, 100.0f);
+ IM_FIXNORMAL2F(dm_x, dm_y);
dm_x *= AA_SIZE * 0.5f;
dm_y *= AA_SIZE * 0.5f;
@@ -941,26 +866,26 @@ void ImDrawList::AddConvexPolyFilled(const ImVec2* points, const int points_coun
}
}
-void ImDrawList::PathArcToFast(const ImVec2& centre, float radius, int a_min_of_12, int a_max_of_12)
+void ImDrawList::PathArcToFast(const ImVec2& center, float radius, int a_min_of_12, int a_max_of_12)
{
if (radius == 0.0f || a_min_of_12 > a_max_of_12)
{
- _Path.push_back(centre);
+ _Path.push_back(center);
return;
}
_Path.reserve(_Path.Size + (a_max_of_12 - a_min_of_12 + 1));
for (int a = a_min_of_12; a <= a_max_of_12; a++)
{
const ImVec2& c = _Data->CircleVtx12[a % IM_ARRAYSIZE(_Data->CircleVtx12)];
- _Path.push_back(ImVec2(centre.x + c.x * radius, centre.y + c.y * radius));
+ _Path.push_back(ImVec2(center.x + c.x * radius, center.y + c.y * radius));
}
}
-void ImDrawList::PathArcTo(const ImVec2& centre, float radius, float a_min, float a_max, int num_segments)
+void ImDrawList::PathArcTo(const ImVec2& center, float radius, float a_min, float a_max, int num_segments)
{
if (radius == 0.0f)
{
- _Path.push_back(centre);
+ _Path.push_back(center);
return;
}
@@ -970,7 +895,7 @@ void ImDrawList::PathArcTo(const ImVec2& centre, float radius, float a_min, floa
for (int i = 0; i <= num_segments; i++)
{
const float a = a_min + ((float)i / (float)num_segments) * (a_max - a_min);
- _Path.push_back(ImVec2(centre.x + ImCos(a) * radius, centre.y + ImSin(a) * radius));
+ _Path.push_back(ImVec2(center.x + ImCos(a) * radius, center.y + ImSin(a) * radius));
}
}
@@ -1024,7 +949,7 @@ void ImDrawList::PathBezierCurveTo(const ImVec2& p2, const ImVec2& p3, const ImV
}
}
-void ImDrawList::PathRect(const ImVec2& a, const ImVec2& b, float rounding, int rounding_corners)
+void ImDrawList::PathRect(const ImVec2& a, const ImVec2& b, float rounding, ImDrawCornerFlags rounding_corners)
{
rounding = ImMin(rounding, ImFabs(b.x - a.x) * ( ((rounding_corners & ImDrawCornerFlags_Top) == ImDrawCornerFlags_Top) || ((rounding_corners & ImDrawCornerFlags_Bot) == ImDrawCornerFlags_Bot) ? 0.5f : 1.0f ) - 1.0f);
rounding = ImMin(rounding, ImFabs(b.y - a.y) * ( ((rounding_corners & ImDrawCornerFlags_Left) == ImDrawCornerFlags_Left) || ((rounding_corners & ImDrawCornerFlags_Right) == ImDrawCornerFlags_Right) ? 0.5f : 1.0f ) - 1.0f);
@@ -1049,44 +974,46 @@ void ImDrawList::PathRect(const ImVec2& a, const ImVec2& b, float rounding, int
}
}
-void ImDrawList::AddLine(const ImVec2& a, const ImVec2& b, ImU32 col, float thickness)
+void ImDrawList::AddLine(const ImVec2& p1, const ImVec2& p2, ImU32 col, float thickness)
{
if ((col & IM_COL32_A_MASK) == 0)
return;
- PathLineTo(a + ImVec2(0.5f,0.5f));
- PathLineTo(b + ImVec2(0.5f,0.5f));
+ PathLineTo(p1 + ImVec2(0.5f, 0.5f));
+ PathLineTo(p2 + ImVec2(0.5f, 0.5f));
PathStroke(col, false, thickness);
}
-// a: upper-left, b: lower-right. we don't render 1 px sized rectangles properly.
-void ImDrawList::AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners_flags, float thickness)
+// p_min = upper-left, p_max = lower-right
+// Note we don't render 1 pixels sized rectangles properly.
+void ImDrawList::AddRect(const ImVec2& p_min, const ImVec2& p_max, ImU32 col, float rounding, ImDrawCornerFlags rounding_corners, float thickness)
{
if ((col & IM_COL32_A_MASK) == 0)
return;
if (Flags & ImDrawListFlags_AntiAliasedLines)
- PathRect(a + ImVec2(0.5f,0.5f), b - ImVec2(0.50f,0.50f), rounding, rounding_corners_flags);
+ PathRect(p_min + ImVec2(0.50f,0.50f), p_max - ImVec2(0.50f,0.50f), rounding, rounding_corners);
else
- PathRect(a + ImVec2(0.5f,0.5f), b - ImVec2(0.49f,0.49f), rounding, rounding_corners_flags); // Better looking lower-right corner and rounded non-AA shapes.
+ PathRect(p_min + ImVec2(0.50f,0.50f), p_max - ImVec2(0.49f,0.49f), rounding, rounding_corners); // Better looking lower-right corner and rounded non-AA shapes.
PathStroke(col, true, thickness);
}
-void ImDrawList::AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners_flags)
+void ImDrawList::AddRectFilled(const ImVec2& p_min, const ImVec2& p_max, ImU32 col, float rounding, ImDrawCornerFlags rounding_corners)
{
if ((col & IM_COL32_A_MASK) == 0)
return;
if (rounding > 0.0f)
{
- PathRect(a, b, rounding, rounding_corners_flags);
+ PathRect(p_min, p_max, rounding, rounding_corners);
PathFillConvex(col);
}
else
{
PrimReserve(6, 4);
- PrimRect(a, b, col);
+ PrimRect(p_min, p_max, col);
}
}
-void ImDrawList::AddRectFilledMultiColor(const ImVec2& a, const ImVec2& c, ImU32 col_upr_left, ImU32 col_upr_right, ImU32 col_bot_right, ImU32 col_bot_left)
+// p_min = upper-left, p_max = lower-right
+void ImDrawList::AddRectFilledMultiColor(const ImVec2& p_min, const ImVec2& p_max, ImU32 col_upr_left, ImU32 col_upr_right, ImU32 col_bot_right, ImU32 col_bot_left)
{
if (((col_upr_left | col_upr_right | col_bot_right | col_bot_left) & IM_COL32_A_MASK) == 0)
return;
@@ -1095,77 +1022,77 @@ void ImDrawList::AddRectFilledMultiColor(const ImVec2& a, const ImVec2& c, ImU32
PrimReserve(6, 4);
PrimWriteIdx((ImDrawIdx)(_VtxCurrentIdx)); PrimWriteIdx((ImDrawIdx)(_VtxCurrentIdx+1)); PrimWriteIdx((ImDrawIdx)(_VtxCurrentIdx+2));
PrimWriteIdx((ImDrawIdx)(_VtxCurrentIdx)); PrimWriteIdx((ImDrawIdx)(_VtxCurrentIdx+2)); PrimWriteIdx((ImDrawIdx)(_VtxCurrentIdx+3));
- PrimWriteVtx(a, uv, col_upr_left);
- PrimWriteVtx(ImVec2(c.x, a.y), uv, col_upr_right);
- PrimWriteVtx(c, uv, col_bot_right);
- PrimWriteVtx(ImVec2(a.x, c.y), uv, col_bot_left);
+ PrimWriteVtx(p_min, uv, col_upr_left);
+ PrimWriteVtx(ImVec2(p_max.x, p_min.y), uv, col_upr_right);
+ PrimWriteVtx(p_max, uv, col_bot_right);
+ PrimWriteVtx(ImVec2(p_min.x, p_max.y), uv, col_bot_left);
}
-void ImDrawList::AddQuad(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& d, ImU32 col, float thickness)
+void ImDrawList::AddQuad(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, ImU32 col, float thickness)
{
if ((col & IM_COL32_A_MASK) == 0)
return;
- PathLineTo(a);
- PathLineTo(b);
- PathLineTo(c);
- PathLineTo(d);
+ PathLineTo(p1);
+ PathLineTo(p2);
+ PathLineTo(p3);
+ PathLineTo(p4);
PathStroke(col, true, thickness);
}
-void ImDrawList::AddQuadFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& d, ImU32 col)
+void ImDrawList::AddQuadFilled(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, ImU32 col)
{
if ((col & IM_COL32_A_MASK) == 0)
return;
- PathLineTo(a);
- PathLineTo(b);
- PathLineTo(c);
- PathLineTo(d);
+ PathLineTo(p1);
+ PathLineTo(p2);
+ PathLineTo(p3);
+ PathLineTo(p4);
PathFillConvex(col);
}
-void ImDrawList::AddTriangle(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col, float thickness)
+void ImDrawList::AddTriangle(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, ImU32 col, float thickness)
{
if ((col & IM_COL32_A_MASK) == 0)
return;
- PathLineTo(a);
- PathLineTo(b);
- PathLineTo(c);
+ PathLineTo(p1);
+ PathLineTo(p2);
+ PathLineTo(p3);
PathStroke(col, true, thickness);
}
-void ImDrawList::AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col)
+void ImDrawList::AddTriangleFilled(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, ImU32 col)
{
if ((col & IM_COL32_A_MASK) == 0)
return;
- PathLineTo(a);
- PathLineTo(b);
- PathLineTo(c);
+ PathLineTo(p1);
+ PathLineTo(p2);
+ PathLineTo(p3);
PathFillConvex(col);
}
-void ImDrawList::AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments, float thickness)
+void ImDrawList::AddCircle(const ImVec2& center, float radius, ImU32 col, int num_segments, float thickness)
{
if ((col & IM_COL32_A_MASK) == 0 || num_segments <= 2)
return;
// Because we are filling a closed shape we remove 1 from the count of segments/points
- const float a_max = IM_PI*2.0f * ((float)num_segments - 1.0f) / (float)num_segments;
- PathArcTo(centre, radius-0.5f, 0.0f, a_max, num_segments - 1);
+ const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments;
+ PathArcTo(center, radius - 0.5f, 0.0f, a_max, num_segments - 1);
PathStroke(col, true, thickness);
}
-void ImDrawList::AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments)
+void ImDrawList::AddCircleFilled(const ImVec2& center, float radius, ImU32 col, int num_segments)
{
if ((col & IM_COL32_A_MASK) == 0 || num_segments <= 2)
return;
// Because we are filling a closed shape we remove 1 from the count of segments/points
- const float a_max = IM_PI*2.0f * ((float)num_segments - 1.0f) / (float)num_segments;
- PathArcTo(centre, radius, 0.0f, a_max, num_segments - 1);
+ const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments;
+ PathArcTo(center, radius, 0.0f, a_max, num_segments - 1);
PathFillConvex(col);
}
@@ -1213,7 +1140,7 @@ void ImDrawList::AddText(const ImVec2& pos, ImU32 col, const char* text_begin, c
AddText(NULL, 0.0f, pos, col, text_begin, text_end);
}
-void ImDrawList::AddImage(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv_a, const ImVec2& uv_b, ImU32 col)
+void ImDrawList::AddImage(ImTextureID user_texture_id, const ImVec2& p_min, const ImVec2& p_max, const ImVec2& uv_min, const ImVec2& uv_max, ImU32 col)
{
if ((col & IM_COL32_A_MASK) == 0)
return;
@@ -1223,13 +1150,13 @@ void ImDrawList::AddImage(ImTextureID user_texture_id, const ImVec2& a, const Im
PushTextureID(user_texture_id);
PrimReserve(6, 4);
- PrimRectUV(a, b, uv_a, uv_b, col);
+ PrimRectUV(p_min, p_max, uv_min, uv_max, col);
if (push_texture_id)
PopTextureID();
}
-void ImDrawList::AddImageQuad(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& d, const ImVec2& uv_a, const ImVec2& uv_b, const ImVec2& uv_c, const ImVec2& uv_d, ImU32 col)
+void ImDrawList::AddImageQuad(ImTextureID user_texture_id, const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, const ImVec2& uv1, const ImVec2& uv2, const ImVec2& uv3, const ImVec2& uv4, ImU32 col)
{
if ((col & IM_COL32_A_MASK) == 0)
return;
@@ -1239,20 +1166,20 @@ void ImDrawList::AddImageQuad(ImTextureID user_texture_id, const ImVec2& a, cons
PushTextureID(user_texture_id);
PrimReserve(6, 4);
- PrimQuadUV(a, b, c, d, uv_a, uv_b, uv_c, uv_d, col);
+ PrimQuadUV(p1, p2, p3, p4, uv1, uv2, uv3, uv4, col);
if (push_texture_id)
PopTextureID();
}
-void ImDrawList::AddImageRounded(ImTextureID user_texture_id, const ImVec2& a, const ImVec2& b, const ImVec2& uv_a, const ImVec2& uv_b, ImU32 col, float rounding, int rounding_corners)
+void ImDrawList::AddImageRounded(ImTextureID user_texture_id, const ImVec2& p_min, const ImVec2& p_max, const ImVec2& uv_min, const ImVec2& uv_max, ImU32 col, float rounding, ImDrawCornerFlags rounding_corners)
{
if ((col & IM_COL32_A_MASK) == 0)
return;
if (rounding <= 0.0f || (rounding_corners & ImDrawCornerFlags_All) == 0)
{
- AddImage(user_texture_id, a, b, uv_a, uv_b, col);
+ AddImage(user_texture_id, p_min, p_max, uv_min, uv_max, col);
return;
}
@@ -1261,15 +1188,142 @@ void ImDrawList::AddImageRounded(ImTextureID user_texture_id, const ImVec2& a, c
PushTextureID(user_texture_id);
int vert_start_idx = VtxBuffer.Size;
- PathRect(a, b, rounding, rounding_corners);
+ PathRect(p_min, p_max, rounding, rounding_corners);
PathFillConvex(col);
int vert_end_idx = VtxBuffer.Size;
- ImGui::ShadeVertsLinearUV(this, vert_start_idx, vert_end_idx, a, b, uv_a, uv_b, true);
+ ImGui::ShadeVertsLinearUV(this, vert_start_idx, vert_end_idx, p_min, p_max, uv_min, uv_max, true);
if (push_texture_id)
PopTextureID();
}
+
+//-----------------------------------------------------------------------------
+// ImDrawListSplitter
+//-----------------------------------------------------------------------------
+// FIXME: This may be a little confusing, trying to be a little too low-level/optimal instead of just doing vector swap..
+//-----------------------------------------------------------------------------
+
+void ImDrawListSplitter::ClearFreeMemory()
+{
+ for (int i = 0; i < _Channels.Size; i++)
+ {
+ if (i == _Current)
+ memset(&_Channels[i], 0, sizeof(_Channels[i])); // Current channel is a copy of CmdBuffer/IdxBuffer, don't destruct again
+ _Channels[i]._CmdBuffer.clear();
+ _Channels[i]._IdxBuffer.clear();
+ }
+ _Current = 0;
+ _Count = 1;
+ _Channels.clear();
+}
+
+void ImDrawListSplitter::Split(ImDrawList* draw_list, int channels_count)
+{
+ IM_ASSERT(_Current == 0 && _Count <= 1);
+ int old_channels_count = _Channels.Size;
+ if (old_channels_count < channels_count)
+ _Channels.resize(channels_count);
+ _Count = channels_count;
+
+ // Channels[] (24/32 bytes each) hold storage that we'll swap with draw_list->_CmdBuffer/_IdxBuffer
+ // The content of Channels[0] at this point doesn't matter. We clear it to make state tidy in a debugger but we don't strictly need to.
+ // When we switch to the next channel, we'll copy draw_list->_CmdBuffer/_IdxBuffer into Channels[0] and then Channels[1] into draw_list->CmdBuffer/_IdxBuffer
+ memset(&_Channels[0], 0, sizeof(ImDrawChannel));
+ for (int i = 1; i < channels_count; i++)
+ {
+ if (i >= old_channels_count)
+ {
+ IM_PLACEMENT_NEW(&_Channels[i]) ImDrawChannel();
+ }
+ else
+ {
+ _Channels[i]._CmdBuffer.resize(0);
+ _Channels[i]._IdxBuffer.resize(0);
+ }
+ if (_Channels[i]._CmdBuffer.Size == 0)
+ {
+ ImDrawCmd draw_cmd;
+ draw_cmd.ClipRect = draw_list->_ClipRectStack.back();
+ draw_cmd.TextureId = draw_list->_TextureIdStack.back();
+ _Channels[i]._CmdBuffer.push_back(draw_cmd);
+ }
+ }
+}
+
+static inline bool CanMergeDrawCommands(ImDrawCmd* a, ImDrawCmd* b)
+{
+ return memcmp(&a->ClipRect, &b->ClipRect, sizeof(a->ClipRect)) == 0 && a->TextureId == b->TextureId && a->VtxOffset == b->VtxOffset && !a->UserCallback && !b->UserCallback;
+}
+
+void ImDrawListSplitter::Merge(ImDrawList* draw_list)
+{
+ // Note that we never use or rely on channels.Size because it is merely a buffer that we never shrink back to 0 to keep all sub-buffers ready for use.
+ if (_Count <= 1)
+ return;
+
+ SetCurrentChannel(draw_list, 0);
+ if (draw_list->CmdBuffer.Size != 0 && draw_list->CmdBuffer.back().ElemCount == 0)
+ draw_list->CmdBuffer.pop_back();
+
+ // Calculate our final buffer sizes. Also fix the incorrect IdxOffset values in each command.
+ int new_cmd_buffer_count = 0;
+ int new_idx_buffer_count = 0;
+ ImDrawCmd* last_cmd = (_Count > 0 && draw_list->CmdBuffer.Size > 0) ? &draw_list->CmdBuffer.back() : NULL;
+ int idx_offset = last_cmd ? last_cmd->IdxOffset + last_cmd->ElemCount : 0;
+ for (int i = 1; i < _Count; i++)
+ {
+ ImDrawChannel& ch = _Channels[i];
+ if (ch._CmdBuffer.Size > 0 && ch._CmdBuffer.back().ElemCount == 0)
+ ch._CmdBuffer.pop_back();
+ if (ch._CmdBuffer.Size > 0 && last_cmd != NULL && CanMergeDrawCommands(last_cmd, &ch._CmdBuffer[0]))
+ {
+ // Merge previous channel last draw command with current channel first draw command if matching.
+ last_cmd->ElemCount += ch._CmdBuffer[0].ElemCount;
+ idx_offset += ch._CmdBuffer[0].ElemCount;
+ ch._CmdBuffer.erase(ch._CmdBuffer.Data);
+ }
+ if (ch._CmdBuffer.Size > 0)
+ last_cmd = &ch._CmdBuffer.back();
+ new_cmd_buffer_count += ch._CmdBuffer.Size;
+ new_idx_buffer_count += ch._IdxBuffer.Size;
+ for (int cmd_n = 0; cmd_n < ch._CmdBuffer.Size; cmd_n++)
+ {
+ ch._CmdBuffer.Data[cmd_n].IdxOffset = idx_offset;
+ idx_offset += ch._CmdBuffer.Data[cmd_n].ElemCount;
+ }
+ }
+ draw_list->CmdBuffer.resize(draw_list->CmdBuffer.Size + new_cmd_buffer_count);
+ draw_list->IdxBuffer.resize(draw_list->IdxBuffer.Size + new_idx_buffer_count);
+
+ // Write commands and indices in order (they are fairly small structures, we don't copy vertices only indices)
+ ImDrawCmd* cmd_write = draw_list->CmdBuffer.Data + draw_list->CmdBuffer.Size - new_cmd_buffer_count;
+ ImDrawIdx* idx_write = draw_list->IdxBuffer.Data + draw_list->IdxBuffer.Size - new_idx_buffer_count;
+ for (int i = 1; i < _Count; i++)
+ {
+ ImDrawChannel& ch = _Channels[i];
+ if (int sz = ch._CmdBuffer.Size) { memcpy(cmd_write, ch._CmdBuffer.Data, sz * sizeof(ImDrawCmd)); cmd_write += sz; }
+ if (int sz = ch._IdxBuffer.Size) { memcpy(idx_write, ch._IdxBuffer.Data, sz * sizeof(ImDrawIdx)); idx_write += sz; }
+ }
+ draw_list->_IdxWritePtr = idx_write;
+ draw_list->UpdateClipRect(); // We call this instead of AddDrawCmd(), so that empty channels won't produce an extra draw call.
+ _Count = 1;
+}
+
+void ImDrawListSplitter::SetCurrentChannel(ImDrawList* draw_list, int idx)
+{
+ IM_ASSERT(idx >= 0 && idx < _Count);
+ if (_Current == idx)
+ return;
+ // Overwrite ImVector (12/16 bytes), four times. This is merely a silly optimization instead of doing .swap()
+ memcpy(&_Channels.Data[_Current]._CmdBuffer, &draw_list->CmdBuffer, sizeof(draw_list->CmdBuffer));
+ memcpy(&_Channels.Data[_Current]._IdxBuffer, &draw_list->IdxBuffer, sizeof(draw_list->IdxBuffer));
+ _Current = idx;
+ memcpy(&draw_list->CmdBuffer, &_Channels.Data[idx]._CmdBuffer, sizeof(draw_list->CmdBuffer));
+ memcpy(&draw_list->IdxBuffer, &_Channels.Data[idx]._IdxBuffer, sizeof(draw_list->IdxBuffer));
+ draw_list->_IdxWritePtr = draw_list->IdxBuffer.Data + draw_list->IdxBuffer.Size;
+}
+
//-----------------------------------------------------------------------------
// [SECTION] ImDrawData
//-----------------------------------------------------------------------------
@@ -1293,8 +1347,10 @@ void ImDrawData::DeIndexAllBuffers()
}
}
-// Helper to scale the ClipRect field of each ImDrawCmd. Use if your final output buffer is at a different scale than ImGui expects, or if there is a difference between your window resolution and framebuffer resolution.
-void ImDrawData::ScaleClipRects(const ImVec2& scale)
+// Helper to scale the ClipRect field of each ImDrawCmd.
+// Use if your final output buffer is at a different scale than draw_data->DisplaySize,
+// or if there is a difference between your window resolution and framebuffer resolution.
+void ImDrawData::ScaleClipRects(const ImVec2& fb_scale)
{
for (int i = 0; i < CmdListsCount; i++)
{
@@ -1302,7 +1358,7 @@ void ImDrawData::ScaleClipRects(const ImVec2& scale)
for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
{
ImDrawCmd* cmd = &cmd_list->CmdBuffer[cmd_i];
- cmd->ClipRect = ImVec4(cmd->ClipRect.x * scale.x, cmd->ClipRect.y * scale.y, cmd->ClipRect.z * scale.x, cmd->ClipRect.w * scale.y);
+ cmd->ClipRect = ImVec4(cmd->ClipRect.x * fb_scale.x, cmd->ClipRect.y * fb_scale.y, cmd->ClipRect.z * fb_scale.x, cmd->ClipRect.w * fb_scale.y);
}
}
}
@@ -1365,7 +1421,7 @@ ImFontConfig::ImFontConfig()
FontDataOwnedByAtlas = true;
FontNo = 0;
SizePixels = 0.0f;
- OversampleH = 3;
+ OversampleH = 3; // FIXME: 2 may be a better default?
OversampleV = 1;
PixelSnapH = false;
GlyphExtraSpacing = ImVec2(0.0f, 0.0f);
@@ -1385,7 +1441,7 @@ ImFontConfig::ImFontConfig()
//-----------------------------------------------------------------------------
// A work of art lies ahead! (. = white layer, X = black layer, others are blank)
-// The white texels on the top left are the ones we'll use everywhere in ImGui to render filled shapes.
+// The white texels on the top left are the ones we'll use everywhere in Dear ImGui to render filled shapes.
const int FONT_ATLAS_DEFAULT_TEX_DATA_W_HALF = 108;
const int FONT_ATLAS_DEFAULT_TEX_DATA_H = 27;
const unsigned int FONT_ATLAS_DEFAULT_TEX_DATA_ID = 0x80000000;
@@ -1462,7 +1518,7 @@ void ImFontAtlas::ClearInputData()
for (int i = 0; i < ConfigData.Size; i++)
if (ConfigData[i].FontData && ConfigData[i].FontDataOwnedByAtlas)
{
- ImGui::MemFree(ConfigData[i].FontData);
+ IM_FREE(ConfigData[i].FontData);
ConfigData[i].FontData = NULL;
}
@@ -1483,9 +1539,9 @@ void ImFontAtlas::ClearTexData()
{
IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas between NewFrame() and EndFrame/Render()!");
if (TexPixelsAlpha8)
- ImGui::MemFree(TexPixelsAlpha8);
+ IM_FREE(TexPixelsAlpha8);
if (TexPixelsRGBA32)
- ImGui::MemFree(TexPixelsRGBA32);
+ IM_FREE(TexPixelsRGBA32);
TexPixelsAlpha8 = NULL;
TexPixelsRGBA32 = NULL;
}
@@ -1531,7 +1587,7 @@ void ImFontAtlas::GetTexDataAsRGBA32(unsigned char** out_pixels, int* out_wid
GetTexDataAsAlpha8(&pixels, NULL, NULL);
if (pixels)
{
- TexPixelsRGBA32 = (unsigned int*)ImGui::MemAlloc((size_t)TexWidth * (size_t)TexHeight * 4);
+ TexPixelsRGBA32 = (unsigned int*)IM_ALLOC((size_t)TexWidth * (size_t)TexHeight * 4);
const unsigned char* src = pixels;
unsigned int* dst = TexPixelsRGBA32;
for (int n = TexWidth * TexHeight; n > 0; n--)
@@ -1563,7 +1619,7 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg)
new_font_cfg.DstFont = Fonts.back();
if (!new_font_cfg.FontDataOwnedByAtlas)
{
- new_font_cfg.FontData = ImGui::MemAlloc(new_font_cfg.FontDataSize);
+ new_font_cfg.FontData = IM_ALLOC(new_font_cfg.FontDataSize);
new_font_cfg.FontDataOwnedByAtlas = true;
memcpy(new_font_cfg.FontData, font_cfg->FontData, (size_t)new_font_cfg.FontDataSize);
}
@@ -1598,8 +1654,10 @@ ImFont* ImFontAtlas::AddFontDefault(const ImFontConfig* font_cfg_template)
font_cfg.OversampleH = font_cfg.OversampleV = 1;
font_cfg.PixelSnapH = true;
}
- if (font_cfg.Name[0] == '\0') strcpy(font_cfg.Name, "ProggyClean.ttf, 13px");
- if (font_cfg.SizePixels <= 0.0f) font_cfg.SizePixels = 13.0f;
+ if (font_cfg.SizePixels <= 0.0f)
+ font_cfg.SizePixels = 13.0f * 1.0f;
+ if (font_cfg.Name[0] == '\0')
+ ImFormatString(font_cfg.Name, IM_ARRAYSIZE(font_cfg.Name), "ProggyClean.ttf, %dpx", (int)font_cfg.SizePixels);
const char* ttf_compressed_base85 = GetDefaultCompressedFontDataTTFBase85();
const ImWchar* glyph_ranges = font_cfg.GlyphRanges != NULL ? font_cfg.GlyphRanges : GetGlyphRangesDefault();
@@ -1646,7 +1704,7 @@ ImFont* ImFontAtlas::AddFontFromMemoryTTF(void* ttf_data, int ttf_size, float si
ImFont* ImFontAtlas::AddFontFromMemoryCompressedTTF(const void* compressed_ttf_data, int compressed_ttf_size, float size_pixels, const ImFontConfig* font_cfg_template, const ImWchar* glyph_ranges)
{
const unsigned int buf_decompressed_size = stb_decompress_length((const unsigned char*)compressed_ttf_data);
- unsigned char* buf_decompressed_data = (unsigned char *)ImGui::MemAlloc(buf_decompressed_size);
+ unsigned char* buf_decompressed_data = (unsigned char *)IM_ALLOC(buf_decompressed_size);
stb_decompress(buf_decompressed_data, (const unsigned char*)compressed_ttf_data, (unsigned int)compressed_ttf_size);
ImFontConfig font_cfg = font_cfg_template ? *font_cfg_template : ImFontConfig();
@@ -1658,10 +1716,10 @@ ImFont* ImFontAtlas::AddFontFromMemoryCompressedTTF(const void* compressed_ttf_d
ImFont* ImFontAtlas::AddFontFromMemoryCompressedBase85TTF(const char* compressed_ttf_data_base85, float size_pixels, const ImFontConfig* font_cfg, const ImWchar* glyph_ranges)
{
int compressed_ttf_size = (((int)strlen(compressed_ttf_data_base85) + 4) / 5) * 4;
- void* compressed_ttf = ImGui::MemAlloc((size_t)compressed_ttf_size);
+ void* compressed_ttf = IM_ALLOC((size_t)compressed_ttf_size);
Decode85((const unsigned char*)compressed_ttf_data_base85, (unsigned char*)compressed_ttf);
ImFont* font = AddFontFromMemoryCompressedTTF(compressed_ttf, compressed_ttf_size, size_pixels, font_cfg, glyph_ranges);
- ImGui::MemFree(compressed_ttf);
+ IM_FREE(compressed_ttf);
return font;
}
@@ -1670,7 +1728,7 @@ int ImFontAtlas::AddCustomRectRegular(unsigned int id, int width, int height)
IM_ASSERT(id >= 0x10000);
IM_ASSERT(width > 0 && width <= 0xFFFF);
IM_ASSERT(height > 0 && height <= 0xFFFF);
- CustomRect r;
+ ImFontAtlasCustomRect r;
r.ID = id;
r.Width = (unsigned short)width;
r.Height = (unsigned short)height;
@@ -1683,7 +1741,7 @@ int ImFontAtlas::AddCustomRectFontGlyph(ImFont* font, ImWchar id, int width, int
IM_ASSERT(font != NULL);
IM_ASSERT(width > 0 && width <= 0xFFFF);
IM_ASSERT(height > 0 && height <= 0xFFFF);
- CustomRect r;
+ ImFontAtlasCustomRect r;
r.ID = id;
r.Width = (unsigned short)width;
r.Height = (unsigned short)height;
@@ -1694,7 +1752,7 @@ int ImFontAtlas::AddCustomRectFontGlyph(ImFont* font, ImWchar id, int width, int
return CustomRects.Size - 1; // Return index
}
-void ImFontAtlas::CalcCustomRectUV(const CustomRect* rect, ImVec2* out_uv_min, ImVec2* out_uv_max)
+void ImFontAtlas::CalcCustomRectUV(const ImFontAtlasCustomRect* rect, ImVec2* out_uv_min, ImVec2* out_uv_max)
{
IM_ASSERT(TexWidth > 0 && TexHeight > 0); // Font atlas needs to be built before we can calculate UV coordinates
IM_ASSERT(rect->IsPacked()); // Make sure the rectangle has been packed
@@ -1710,7 +1768,7 @@ bool ImFontAtlas::GetMouseCursorTexData(ImGuiMouseCursor cursor_type, ImVec2* ou
return false;
IM_ASSERT(CustomRectIds[0] != -1);
- ImFontAtlas::CustomRect& r = CustomRects[CustomRectIds[0]];
+ ImFontAtlasCustomRect& r = CustomRects[CustomRectIds[0]];
IM_ASSERT(r.ID == FONT_ATLAS_DEFAULT_TEX_DATA_ID);
ImVec2 pos = FONT_ATLAS_DEFAULT_TEX_CURSOR_DATA[cursor_type][0] + ImVec2((float)r.X, (float)r.Y);
ImVec2 size = FONT_ATLAS_DEFAULT_TEX_CURSOR_DATA[cursor_type][1];
@@ -1780,7 +1838,7 @@ static void UnpackBoolVectorToFlatIndexList(const ImBoolVector* in, ImVectorpush_back((int)((it - it_begin) << 5) + bit_n);
}
@@ -1842,15 +1900,14 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
{
ImFontBuildSrcData& src_tmp = src_tmp_array[src_i];
ImFontBuildDstData& dst_tmp = dst_tmp_array[src_tmp.DstIndex];
- ImFontConfig& cfg = atlas->ConfigData[src_i];
src_tmp.GlyphsSet.Resize(src_tmp.GlyphsHighest + 1);
- if (dst_tmp.SrcCount > 1 && dst_tmp.GlyphsSet.Storage.empty())
+ if (dst_tmp.GlyphsSet.Storage.empty())
dst_tmp.GlyphsSet.Resize(dst_tmp.GlyphsHighest + 1);
for (const ImWchar* src_range = src_tmp.SrcRanges; src_range[0] && src_range[1]; src_range += 2)
for (int codepoint = src_range[0]; codepoint <= src_range[1]; codepoint++)
{
- if (cfg.MergeMode && dst_tmp.GlyphsSet.GetBit(codepoint)) // Don't overwrite existing glyphs. We could make this an option (e.g. MergeOverwrite)
+ if (dst_tmp.GlyphsSet.GetBit(codepoint)) // Don't overwrite existing glyphs. We could make this an option for MergeMode (e.g. MergeOverwrite==true)
continue;
if (!stbtt_FindGlyphIndex(&src_tmp.FontInfo, codepoint)) // It is actually in the font?
continue;
@@ -1859,8 +1916,7 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
src_tmp.GlyphsCount++;
dst_tmp.GlyphsCount++;
src_tmp.GlyphsSet.SetBit(codepoint, true);
- if (dst_tmp.SrcCount > 1)
- dst_tmp.GlyphsSet.SetBit(codepoint, true);
+ dst_tmp.GlyphsSet.SetBit(codepoint, true);
total_glyphs_count++;
}
}
@@ -1963,7 +2019,7 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
// 7. Allocate texture
atlas->TexHeight = (atlas->Flags & ImFontAtlasFlags_NoPowerOfTwoHeight) ? (atlas->TexHeight + 1) : ImUpperPowerOfTwo(atlas->TexHeight);
atlas->TexUvScale = ImVec2(1.0f / atlas->TexWidth, 1.0f / atlas->TexHeight);
- atlas->TexPixelsAlpha8 = (unsigned char*)ImGui::MemAlloc(atlas->TexWidth * atlas->TexHeight);
+ atlas->TexPixelsAlpha8 = (unsigned char*)IM_ALLOC(atlas->TexWidth * atlas->TexHeight);
memset(atlas->TexPixelsAlpha8, 0, atlas->TexWidth * atlas->TexHeight);
spc.pixels = atlas->TexPixelsAlpha8;
spc.height = atlas->TexHeight;
@@ -2071,7 +2127,7 @@ void ImFontAtlasBuildPackCustomRects(ImFontAtlas* atlas, void* stbrp_context_opa
stbrp_context* pack_context = (stbrp_context*)stbrp_context_opaque;
IM_ASSERT(pack_context != NULL);
- ImVector& user_rects = atlas->CustomRects;
+ ImVector& user_rects = atlas->CustomRects;
IM_ASSERT(user_rects.Size >= 1); // We expect at least the default custom rects to be registered, else something went wrong.
ImVector pack_rects;
@@ -2097,7 +2153,7 @@ static void ImFontAtlasBuildRenderDefaultTexData(ImFontAtlas* atlas)
{
IM_ASSERT(atlas->CustomRectIds[0] >= 0);
IM_ASSERT(atlas->TexPixelsAlpha8 != NULL);
- ImFontAtlas::CustomRect& r = atlas->CustomRects[atlas->CustomRectIds[0]];
+ ImFontAtlasCustomRect& r = atlas->CustomRects[atlas->CustomRectIds[0]];
IM_ASSERT(r.ID == FONT_ATLAS_DEFAULT_TEX_DATA_ID);
IM_ASSERT(r.IsPacked());
@@ -2132,7 +2188,7 @@ void ImFontAtlasBuildFinish(ImFontAtlas* atlas)
// Register custom rectangle glyphs
for (int i = 0; i < atlas->CustomRects.Size; i++)
{
- const ImFontAtlas::CustomRect& r = atlas->CustomRects[i];
+ const ImFontAtlasCustomRect& r = atlas->CustomRects[i];
if (r.Font == NULL || r.ID > 0x10000)
continue;
@@ -2350,6 +2406,23 @@ const ImWchar* ImFontAtlas::GetGlyphRangesThai()
return &ranges[0];
}
+const ImWchar* ImFontAtlas::GetGlyphRangesVietnamese()
+{
+ static const ImWchar ranges[] =
+ {
+ 0x0020, 0x00FF, // Basic Latin
+ 0x0102, 0x0103,
+ 0x0110, 0x0111,
+ 0x0128, 0x0129,
+ 0x0168, 0x0169,
+ 0x01A0, 0x01A1,
+ 0x01AF, 0x01B0,
+ 0x1EA0, 0x1EF9,
+ 0,
+ };
+ return &ranges[0];
+}
+
//-----------------------------------------------------------------------------
// [SECTION] ImFontGlyphRangesBuilder
//-----------------------------------------------------------------------------
@@ -2377,11 +2450,12 @@ void ImFontGlyphRangesBuilder::AddRanges(const ImWchar* ranges)
void ImFontGlyphRangesBuilder::BuildRanges(ImVector* out_ranges)
{
- for (int n = 0; n < 0x10000; n++)
+ int max_codepoint = 0x10000;
+ for (int n = 0; n < max_codepoint; n++)
if (GetBit(n))
{
out_ranges->push_back((ImWchar)n);
- while (n < 0x10000 && GetBit(n + 1))
+ while (n < max_codepoint - 1 && GetBit(n + 1))
n++;
out_ranges->push_back((ImWchar)n);
}
@@ -2394,38 +2468,36 @@ void ImFontGlyphRangesBuilder::BuildRanges(ImVector* out_ranges)
ImFont::ImFont()
{
- Scale = 1.0f;
+ FontSize = 0.0f;
+ FallbackAdvanceX = 0.0f;
FallbackChar = (ImWchar)'?';
DisplayOffset = ImVec2(0.0f, 0.0f);
- ClearOutputData();
+ FallbackGlyph = NULL;
+ ContainerAtlas = NULL;
+ ConfigData = NULL;
+ ConfigDataCount = 0;
+ DirtyLookupTables = false;
+ Scale = 1.0f;
+ Ascent = Descent = 0.0f;
+ MetricsTotalSurface = 0;
}
ImFont::~ImFont()
{
- // Invalidate active font so that the user gets a clear crash instead of a dangling pointer.
- // If you want to delete fonts you need to do it between Render() and NewFrame().
- // FIXME-CLEANUP
- /*
- ImGuiContext& g = *GImGui;
- if (g.Font == this)
- g.Font = NULL;
- */
ClearOutputData();
}
void ImFont::ClearOutputData()
{
FontSize = 0.0f;
+ FallbackAdvanceX = 0.0f;
Glyphs.clear();
IndexAdvanceX.clear();
IndexLookup.clear();
FallbackGlyph = NULL;
- FallbackAdvanceX = 0.0f;
- ConfigDataCount = 0;
- ConfigData = NULL;
ContainerAtlas = NULL;
- Ascent = Descent = 0.0f;
DirtyLookupTables = true;
+ Ascent = Descent = 0.0f;
MetricsTotalSurface = 0;
}
@@ -2456,7 +2528,7 @@ void ImFont::BuildLookupTable()
ImFontGlyph& tab_glyph = Glyphs.back();
tab_glyph = *FindGlyph((ImWchar)' ');
tab_glyph.Codepoint = '\t';
- tab_glyph.AdvanceX *= 4;
+ tab_glyph.AdvanceX *= IM_TABSIZE;
IndexAdvanceX[(int)tab_glyph.Codepoint] = (float)tab_glyph.AdvanceX;
IndexLookup[(int)tab_glyph.Codepoint] = (ImWchar)(Glyphs.Size-1);
}
@@ -2628,7 +2700,7 @@ const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, const c
}
// We ignore blank width at the end of the line (they can be skipped)
- if (line_width + word_width >= wrap_width)
+ if (line_width + word_width > wrap_width)
{
// Words that cannot possibly fit within an entire line will be cut anywhere.
if (word_width < wrap_width)
@@ -2753,7 +2825,7 @@ void ImFont::RenderChar(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col
void ImFont::RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, float wrap_width, bool cpu_fine_clip) const
{
if (!text_end)
- text_end = text_begin + strlen(text_begin); // ImGui functions generally already provides a valid text_end, so this is merely to handle direct calls.
+ text_end = text_begin + strlen(text_begin); // ImGui:: functions generally already provides a valid text_end, so this is merely to handle direct calls.
// Align to be pixel perfect
pos.x = (float)(int)pos.x + DisplayOffset.x;
@@ -2936,7 +3008,7 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col
draw_list->CmdBuffer[draw_list->CmdBuffer.Size-1].ElemCount -= (idx_expected_size - draw_list->IdxBuffer.Size);
draw_list->_VtxWritePtr = vtx_write;
draw_list->_IdxWritePtr = idx_write;
- draw_list->_VtxCurrentIdx = (unsigned int)draw_list->VtxBuffer.Size;
+ draw_list->_VtxCurrentIdx = vtx_current_idx;
}
//-----------------------------------------------------------------------------
@@ -2976,7 +3048,7 @@ void ImGui::RenderMouseCursor(ImVec2 pos, float scale, ImGuiMouseCursor mouse_cu
if (!viewport->GetRect().Overlaps(ImRect(pos, pos + ImVec2(size.x + 2, size.y + 2) * scale)))
continue;
- ImDrawList* draw_list = GetOverlayDrawList(viewport);
+ ImDrawList* draw_list = GetForegroundDrawList(viewport);
draw_list->PushTextureID(tex_id);
draw_list->AddImage(tex_id, pos + ImVec2(1,0)*scale, pos + ImVec2(1,0)*scale + size*scale, uv[2], uv[3], col_shadow);
draw_list->AddImage(tex_id, pos + ImVec2(2,0)*scale, pos + ImVec2(2,0)*scale + size*scale, uv[2], uv[3], col_shadow);
@@ -3098,10 +3170,11 @@ void ImGui::RenderRectFilledWithHole(ImDrawList* draw_list, ImRect outer, ImRect
// FIXME: Rendering an ellipsis "..." is a surprisingly tricky problem for us... we cannot rely on font glyph having it,
// and regular dot are typically too wide. If we render a dot/shape ourselves it comes with the risk that it wouldn't match
// the boldness or positioning of what the font uses...
-void ImGui::RenderPixelEllipsis(ImDrawList* draw_list, ImVec2 pos, int count, ImU32 col)
+void ImGui::RenderPixelEllipsis(ImDrawList* draw_list, ImVec2 pos, ImU32 col, int count)
{
ImFont* font = draw_list->_Data->Font;
- pos.y += (float)(int)(font->DisplayOffset.y + font->Ascent + 0.5f - 1.0f);
+ const float font_scale = draw_list->_Data->FontSize / font->FontSize;
+ pos.y += (float)(int)(font->DisplayOffset.y + font->Ascent * font_scale + 0.5f - 1.0f);
for (int dot_n = 0; dot_n < count; dot_n++)
draw_list->AddRectFilled(ImVec2(pos.x + dot_n * 2.0f, pos.y), ImVec2(pos.x + dot_n * 2.0f + 1.0f, pos.y + 1.0f), col);
}
diff --git a/imgui_internal.h b/imgui_internal.h
index 2f6600af..9d13563a 100644
--- a/imgui_internal.h
+++ b/imgui_internal.h
@@ -1,4 +1,4 @@
-// dear imgui, v1.68 WIP
+// dear imgui, v1.73 WIP
// (internal structures/api)
// You may use this file to debug, understand or extend ImGui features but we don't provide any guarantee of forward compatibility!
@@ -36,15 +36,17 @@ Index of this file:
#include // sqrtf, fabsf, fmodf, powf, floorf, ceilf, cosf, sinf
#include // INT_MIN, INT_MAX
+// Visual Studio warnings
#ifdef _MSC_VER
#pragma warning (push)
#pragma warning (disable: 4251) // class 'xxx' needs to have dll-interface to be used by clients of struct 'xxx' // when IMGUI_API is set to__declspec(dllexport)
#endif
-#ifdef __clang__
+// Clang/GCC warnings with -Weverything
+#if defined(__clang__)
#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wunused-function" // for stb_textedit.h
-#pragma clang diagnostic ignored "-Wmissing-prototypes" // for stb_textedit.h
+#pragma clang diagnostic ignored "-Wunused-function" // for stb_textedit.h
+#pragma clang diagnostic ignored "-Wmissing-prototypes" // for stb_textedit.h
#pragma clang diagnostic ignored "-Wold-style-cast"
#if __has_warning("-Wzero-as-null-pointer-constant")
#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
@@ -52,6 +54,10 @@ Index of this file:
#if __has_warning("-Wdouble-promotion")
#pragma clang diagnostic ignored "-Wdouble-promotion"
#endif
+#elif defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind
+#pragma GCC diagnostic ignored "-Wclass-memaccess" // [__GNUC__ >= 8] warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead
#endif
//-----------------------------------------------------------------------------
@@ -63,8 +69,9 @@ struct ImDrawDataBuilder; // Helper to build a ImDrawData instance
struct ImDrawListSharedData; // Data shared between all ImDrawList instances
struct ImGuiColorMod; // Stacked color modifier, backup of modified data so we can restore it
struct ImGuiColumnData; // Storage data for a single column
-struct ImGuiColumnsSet; // Storage data for a columns set
-struct ImGuiContext; // Main imgui context
+struct ImGuiColumns; // Storage data for a columns set
+struct ImGuiContext; // Main Dear ImGui context
+struct ImGuiDataTypeInfo; // Type information associated to a ImGuiDataType enum
struct ImGuiDockContext; // Docking system context
struct ImGuiDockNode; // Docking system node (hold a list of Windows OR two child dock nodes)
struct ImGuiDockNodeSettings; // Storage for a dock node in .ini file (we preserve those even if the associated dock node isn't active during the session)
@@ -73,8 +80,9 @@ struct ImGuiInputTextState; // Internal state of the currently focused/e
struct ImGuiItemHoveredDataBackup; // Backup and restore IsItemHovered() internal data
struct ImGuiMenuColumns; // Simple column measurement, currently used for MenuItem() only
struct ImGuiNavMoveResult; // Result of a directional navigation move query result
-struct ImGuiNextWindowData; // Storage for SetNexWindow** functions
-struct ImGuiPopupRef; // Storage for current popup stack
+struct ImGuiNextWindowData; // Storage for SetNextWindow** functions
+struct ImGuiNextItemData; // Storage for SetNextItem** functions
+struct ImGuiPopupData; // Storage for current popup stack
struct ImGuiSettingsHandler; // Storage for one type registered in the .ini file
struct ImGuiStyleMod; // Stacked style modifier, backup of modified data so we can restore it
struct ImGuiTabBar; // Storage for a tab bar
@@ -84,22 +92,27 @@ struct ImGuiWindowTempData; // Temporary storage for one window (that's
struct ImGuiWindowSettings; // Storage for window settings stored in .ini file (we keep one of those even if the actual window wasn't instanced during this session)
// Use your programming IDE "Go to definition" facility on the names of the center columns to find the actual flags/enum lists.
-typedef int ImGuiLayoutType; // -> enum ImGuiLayoutType_ // Enum: Horizontal or vertical
-typedef int ImGuiButtonFlags; // -> enum ImGuiButtonFlags_ // Flags: for ButtonEx(), ButtonBehavior()
-typedef int ImGuiItemFlags; // -> enum ImGuiItemFlags_ // Flags: for PushItemFlag()
-typedef int ImGuiItemStatusFlags; // -> enum ImGuiItemStatusFlags_ // Flags: for DC.LastItemStatusFlags
-typedef int ImGuiNavHighlightFlags; // -> enum ImGuiNavHighlightFlags_ // Flags: for RenderNavHighlight()
-typedef int ImGuiNavDirSourceFlags; // -> enum ImGuiNavDirSourceFlags_ // Flags: for GetNavInputAmount2d()
-typedef int ImGuiNavMoveFlags; // -> enum ImGuiNavMoveFlags_ // Flags: for navigation requests
-typedef int ImGuiSeparatorFlags; // -> enum ImGuiSeparatorFlags_ // Flags: for Separator() - internal
-typedef int ImGuiSliderFlags; // -> enum ImGuiSliderFlags_ // Flags: for SliderBehavior()
-typedef int ImGuiDragFlags; // -> enum ImGuiDragFlags_ // Flags: for DragBehavior()
+typedef int ImGuiDataAuthority; // -> enum ImGuiDataAuthority_ // Enum: for storing the source authority (dock node vs window) of a field
+typedef int ImGuiLayoutType; // -> enum ImGuiLayoutType_ // Enum: Horizontal or vertical
+typedef int ImGuiButtonFlags; // -> enum ImGuiButtonFlags_ // Flags: for ButtonEx(), ButtonBehavior()
+typedef int ImGuiColumnsFlags; // -> enum ImGuiColumnsFlags_ // Flags: BeginColumns()
+typedef int ImGuiDragFlags; // -> enum ImGuiDragFlags_ // Flags: for DragBehavior()
+typedef int ImGuiItemFlags; // -> enum ImGuiItemFlags_ // Flags: for PushItemFlag()
+typedef int ImGuiItemStatusFlags; // -> enum ImGuiItemStatusFlags_ // Flags: for DC.LastItemStatusFlags
+typedef int ImGuiNavHighlightFlags; // -> enum ImGuiNavHighlightFlags_ // Flags: for RenderNavHighlight()
+typedef int ImGuiNavDirSourceFlags; // -> enum ImGuiNavDirSourceFlags_ // Flags: for GetNavInputAmount2d()
+typedef int ImGuiNavMoveFlags; // -> enum ImGuiNavMoveFlags_ // Flags: for navigation requests
+typedef int ImGuiNextItemDataFlags; // -> enum ImGuiNextItemDataFlags_ // Flags: for SetNextItemXXX() functions
+typedef int ImGuiNextWindowDataFlags; // -> enum ImGuiNextWindowDataFlags_// Flags: for SetNextWindowXXX() functions
+typedef int ImGuiSeparatorFlags; // -> enum ImGuiSeparatorFlags_ // Flags: for SeparatorEx()
+typedef int ImGuiSliderFlags; // -> enum ImGuiSliderFlags_ // Flags: for SliderBehavior()
+typedef int ImGuiTextFlags; // -> enum ImGuiTextFlags_ // Flags: for TextEx()
//-------------------------------------------------------------------------
// STB libraries includes
//-------------------------------------------------------------------------
-namespace ImGuiStb
+namespace ImStb
{
#undef STB_TEXTEDIT_STRING
@@ -107,16 +120,18 @@ namespace ImGuiStb
#define STB_TEXTEDIT_STRING ImGuiInputTextState
#define STB_TEXTEDIT_CHARTYPE ImWchar
#define STB_TEXTEDIT_GETWIDTH_NEWLINE -1.0f
+#define STB_TEXTEDIT_UNDOSTATECOUNT 99
+#define STB_TEXTEDIT_UNDOCHARCOUNT 999
#include "imstb_textedit.h"
-} // namespace ImGuiStb
+} // namespace ImStb
//-----------------------------------------------------------------------------
// Context pointer
//-----------------------------------------------------------------------------
#ifndef GImGui
-extern IMGUI_API ImGuiContext* GImGui; // Current implicit ImGui context pointer
+extern IMGUI_API ImGuiContext* GImGui; // Current implicit context pointer
#endif
// Internal Drag and Drop payload types. String starting with '_' are reserved for Dear ImGui.
@@ -132,12 +147,20 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit ImGui context pointe
#else
#define IM_NEWLINE "\n"
#endif
-
-#define IMGUI_DEBUG_LOG(_FMT,...) printf("[%05d] " _FMT, GImGui->FrameCount, __VA_ARGS__)
+#define IM_TABSIZE (4)
#define IM_STATIC_ASSERT(_COND) typedef char static_assertion_##__line__[(_COND)?1:-1]
#define IM_F32_TO_INT8_UNBOUND(_VAL) ((int)((_VAL) * 255.0f + ((_VAL)>=0 ? 0.5f : -0.5f))) // Unsaturated, for display purpose
#define IM_F32_TO_INT8_SAT(_VAL) ((int)(ImSaturate(_VAL) * 255.0f + 0.5f)) // Saturated, always output 0..255
+// Debug Logging
+#ifndef IMGUI_DEBUG_LOG
+#define IMGUI_DEBUG_LOG(_FMT,...) printf("[%05d] " _FMT, GImGui->FrameCount, __VA_ARGS__)
+#endif
+#define IMGUI_DEBUG_LOG_VIEWPORT(...) ((void)0) // Disable log
+#define IMGUI_DEBUG_LOG_DOCKING(...) ((void)0) // Disable log
+//#define IMGUI_DEBUG_LOG_VIEWPORT IMGUI_DEBUG_LOG // Enable log
+//#define IMGUI_DEBUG_LOG_DOCKING IMGUI_DEBUG_LOG // Enable log
+
// Enforce cdecl calling convention for functions called by the standard library, in case compilation settings changed the default to e.g. __vectorcall
#ifdef _MSC_VER
#define IMGUI_CDECL __cdecl
@@ -155,7 +178,7 @@ IMGUI_API int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, cons
// Helpers: Misc
IMGUI_API ImU32 ImHashData(const void* data, size_t data_size, ImU32 seed = 0);
-IMGUI_API ImU32 ImHashStr(const char* data, size_t data_size, ImU32 seed = 0);
+IMGUI_API ImU32 ImHashStr(const char* data, size_t data_size = 0, ImU32 seed = 0);
IMGUI_API void* ImFileLoadToMemory(const char* filename, const char* file_open_mode, size_t* out_file_size = NULL, int padding_bytes = 0);
IMGUI_API FILE* ImFileOpen(const char* filename, const char* file_open_mode);
static inline bool ImCharIsBlankA(char c) { return c == ' ' || c == '\t'; }
@@ -230,12 +253,15 @@ static inline double ImAtof(const char* s)
static inline float ImFloorStd(float x) { return floorf(x); } // we already uses our own ImFloor() { return (float)(int)v } internally so the standard one wrapper is named differently (it's used by stb_truetype)
static inline float ImCeil(float x) { return ceilf(x); }
#endif
-// - ImMin/ImMax/ImClamp/ImLerp/ImSwap are used by widgets which support for variety of types: signed/unsigned int/long long float/double, using templates here but we could also redefine them 6 times
+// - ImMin/ImMax/ImClamp/ImLerp/ImSwap are used by widgets which support for variety of types: signed/unsigned int/long long float/double
+// (Exceptionally using templates here but we could also redefine them for variety of types)
template static inline T ImMin(T lhs, T rhs) { return lhs < rhs ? lhs : rhs; }
template static inline T ImMax(T lhs, T rhs) { return lhs >= rhs ? lhs : rhs; }
template static inline T ImClamp(T v, T mn, T mx) { return (v < mn) ? mn : (v > mx) ? mx : v; }
template static inline T ImLerp(T a, T b, float t) { return (T)(a + (b - a) * t); }
template static inline void ImSwap(T& a, T& b) { T tmp = a; a = b; b = tmp; }
+template static inline T ImAddClampOverflow(T a, T b, T mn, T mx) { if (b < 0 && (a < mn - b)) return mn; if (b > 0 && (a > mx - b)) return mx; return a + b; }
+template static inline T ImSubClampOverflow(T a, T b, T mn, T mx) { if (b > 0 && (a < mn + b)) return mn; if (b < 0 && (a > mx + b)) return mx; return a - b; }
// - Misc maths helpers
static inline ImVec2 ImMin(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x < rhs.x ? lhs.x : rhs.x, lhs.y < rhs.y ? lhs.y : rhs.y); }
static inline ImVec2 ImMax(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x >= rhs.x ? lhs.x : rhs.x, lhs.y >= rhs.y ? lhs.y : rhs.y); }
@@ -249,6 +275,7 @@ static inline float ImLengthSqr(const ImVec4& lhs)
static inline float ImInvLength(const ImVec2& lhs, float fail_value) { float d = lhs.x*lhs.x + lhs.y*lhs.y; if (d > 0.0f) return 1.0f / ImSqrt(d); return fail_value; }
static inline float ImFloor(float f) { return (float)(int)f; }
static inline ImVec2 ImFloor(const ImVec2& v) { return ImVec2((float)(int)v.x, (float)(int)v.y); }
+static inline int ImModPositive(int a, int b) { return (a + b) % b; }
static inline float ImDot(const ImVec2& a, const ImVec2& b) { return a.x * b.x + a.y * b.y; }
static inline ImVec2 ImRotate(const ImVec2& v, float cos_a, float sin_a) { return ImVec2(v.x * cos_a - v.y * sin_a, v.x * sin_a + v.y * cos_a); }
static inline float ImLinearSweep(float current, float target, float speed) { if (current < target) return ImMin(current + speed, target); if (current > target) return ImMax(current - speed, target); return current; }
@@ -282,7 +309,8 @@ struct IMGUI_API ImPool
T* GetByIndex(ImPoolIdx n) { return &Data[n]; }
ImPoolIdx GetIndex(const T* p) const { IM_ASSERT(p >= Data.Data && p < Data.Data + Data.Size); return (ImPoolIdx)(p - Data.Data); }
T* GetOrAddByKey(ImGuiID key) { int* p_idx = Map.GetIntRef(key, -1); if (*p_idx != -1) return &Data[*p_idx]; *p_idx = FreeIdx; return Add(); }
- void Clear() { for (int n = 0; n < Map.Data.Size; n++) { int idx = Map.Data[n].val_i; if (idx != -1) Data[idx].~T(); } Map.Clear(); Data.clear(); FreeIdx = 0; }
+ bool Contains(const T* p) const { return (p >= Data.Data && p < Data.Data + Data.Size); }
+ void Clear() { for (int n = 0; n < Map.Data.Size; n++) { int idx = Map.Data[n].val_i; if (idx != -1) Data[idx].~T(); } Map.Clear(); Data.clear(); FreeIdx = 0; }
T* Add() { int idx = FreeIdx; if (idx == Data.Size) { Data.resize(Data.Size + 1); FreeIdx++; } else { FreeIdx = *(int*)&Data[idx]; } IM_PLACEMENT_NEW(&Data[idx]) T(); return &Data[idx]; }
void Remove(ImGuiID key, const T* p) { Remove(key, GetIndex(p)); }
void Remove(ImGuiID key, ImPoolIdx idx) { Data[idx].~T(); *(int*)&Data[idx] = FreeIdx; FreeIdx = idx; Map.SetInt(key, -1); }
@@ -298,7 +326,7 @@ enum ImGuiButtonFlags_
{
ImGuiButtonFlags_None = 0,
ImGuiButtonFlags_Repeat = 1 << 0, // hold to repeat
- ImGuiButtonFlags_PressedOnClickRelease = 1 << 1, // return true on click + release on same item [DEFAULT if no PressedOn* flag is set]
+ ImGuiButtonFlags_PressedOnClickRelease = 1 << 1, // [Default] return true on click + release on same item
ImGuiButtonFlags_PressedOnClick = 1 << 2, // return true on click (default requires click+release)
ImGuiButtonFlags_PressedOnRelease = 1 << 3, // return true on release (default requires click+release)
ImGuiButtonFlags_PressedOnDoubleClick = 1 << 4, // return true on double-click (default requires click+release)
@@ -310,7 +338,8 @@ enum ImGuiButtonFlags_
ImGuiButtonFlags_NoKeyModifiers = 1 << 10, // disable interaction if a key modifier is held
ImGuiButtonFlags_NoHoldingActiveID = 1 << 11, // don't set ActiveId while holding the mouse (ImGuiButtonFlags_PressedOnClick only)
ImGuiButtonFlags_PressedOnDragDropHold = 1 << 12, // press when held into while we are drag and dropping another item (used by e.g. tree nodes, collapsing headers)
- ImGuiButtonFlags_NoNavFocus = 1 << 13 // don't override navigation focus when activated
+ ImGuiButtonFlags_NoNavFocus = 1 << 13, // don't override navigation focus when activated
+ ImGuiButtonFlags_NoHoveredOnNav = 1 << 14 // don't report as hovered when navigated on
};
enum ImGuiSliderFlags_
@@ -336,33 +365,45 @@ enum ImGuiColumnsFlags_
ImGuiColumnsFlags_GrowParentContentsSize= 1 << 4 // (WIP) Restore pre-1.51 behavior of extending the parent window contents size but _without affecting the columns width at all_. Will eventually remove.
};
+// Extend ImGuiSelectableFlags_
enum ImGuiSelectableFlagsPrivate_
{
// NB: need to be in sync with last value of ImGuiSelectableFlags_
- ImGuiSelectableFlags_NoHoldingActiveID = 1 << 10,
- ImGuiSelectableFlags_PressedOnClick = 1 << 11,
- ImGuiSelectableFlags_PressedOnRelease = 1 << 12,
- ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 13
+ ImGuiSelectableFlags_NoHoldingActiveID = 1 << 20,
+ ImGuiSelectableFlags_PressedOnClick = 1 << 21,
+ ImGuiSelectableFlags_PressedOnRelease = 1 << 22,
+ ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 23, // FIXME: We may be able to remove this (added in 6251d379 for menus)
+ ImGuiSelectableFlags_AllowItemOverlap = 1 << 24,
+ ImGuiSelectableFlags_DrawHoveredWhenHeld= 1 << 25, // Always show active when held, even is not hovered. This concept could probably be renamed/formalized somehow.
+ ImGuiSelectableFlags_SetNavIdOnHover = 1 << 26
+};
+
+// Extend ImGuiTreeNodeFlags_
+enum ImGuiTreeNodeFlagsPrivate_
+{
+ ImGuiTreeNodeFlags_ClipLabelForTrailingButton = 1 << 20
};
enum ImGuiSeparatorFlags_
{
ImGuiSeparatorFlags_None = 0,
ImGuiSeparatorFlags_Horizontal = 1 << 0, // Axis default to current layout type, so generally Horizontal unless e.g. in a menu bar
- ImGuiSeparatorFlags_Vertical = 1 << 1
+ ImGuiSeparatorFlags_Vertical = 1 << 1,
+ ImGuiSeparatorFlags_SpanAllColumns = 1 << 2
};
-// Transient per-window ItemFlags, reset at the beginning of the frame. For child windows: inherited from parent on first Begin().
+// Transient per-window flags, reset at the beginning of the frame. For child window, inherited from parent on first Begin().
// This is going to be exposed in imgui.h when stabilized enough.
enum ImGuiItemFlags_
{
- ImGuiItemFlags_NoTabStop = 1 << 0, // false
- ImGuiItemFlags_ButtonRepeat = 1 << 1, // false // Button() will return true multiple times based on io.KeyRepeatDelay and io.KeyRepeatRate settings.
- ImGuiItemFlags_Disabled = 1 << 2, // false // [BETA] Disable interactions but doesn't affect visuals yet. See github.com/ocornut/imgui/issues/211
- ImGuiItemFlags_NoNav = 1 << 3, // false
- ImGuiItemFlags_NoNavDefaultFocus = 1 << 4, // false
- ImGuiItemFlags_SelectableDontClosePopup = 1 << 5, // false // MenuItem/Selectable() automatically closes current Popup window
- ImGuiItemFlags_Default_ = 0
+ ImGuiItemFlags_NoTabStop = 1 << 0, // false
+ ImGuiItemFlags_ButtonRepeat = 1 << 1, // false // Button() will return true multiple times based on io.KeyRepeatDelay and io.KeyRepeatRate settings.
+ ImGuiItemFlags_Disabled = 1 << 2, // false // [BETA] Disable interactions but doesn't affect visuals yet. See github.com/ocornut/imgui/issues/211
+ ImGuiItemFlags_NoNav = 1 << 3, // false
+ ImGuiItemFlags_NoNavDefaultFocus = 1 << 4, // false
+ ImGuiItemFlags_SelectableDontClosePopup = 1 << 5, // false // MenuItem/Selectable() automatically closes current Popup window
+ ImGuiItemFlags_MixedValue = 1 << 6, // false // [BETA] Represent a mixed/indeterminate value, generally multi-selection where values differ. Currently only supported by Checkbox() (later should support all sorts of widgets)
+ ImGuiItemFlags_Default_ = 0
};
// Storage for LastItem data
@@ -371,10 +412,13 @@ enum ImGuiItemStatusFlags_
ImGuiItemStatusFlags_None = 0,
ImGuiItemStatusFlags_HoveredRect = 1 << 0,
ImGuiItemStatusFlags_HasDisplayRect = 1 << 1,
- ImGuiItemStatusFlags_Edited = 1 << 2 // Value exposed by item was edited in the current frame (should match the bool return value of most widgets)
+ ImGuiItemStatusFlags_Edited = 1 << 2, // Value exposed by item was edited in the current frame (should match the bool return value of most widgets)
+ ImGuiItemStatusFlags_ToggledSelection = 1 << 3, // Set when Selectable(), TreeNode() reports toggling a selection. We can't report "Selected" because reporting the change allows us to handle clipping with less issues.
+ ImGuiItemStatusFlags_HasDeactivated = 1 << 4, // Set if the widget/group is able to provide data for the ImGuiItemStatusFlags_Deactivated flag.
+ ImGuiItemStatusFlags_Deactivated = 1 << 5 // Only valid if ImGuiItemStatusFlags_HasDeactivated is set.
#ifdef IMGUI_ENABLE_TEST_ENGINE
- , // [imgui-test only]
+ , // [imgui_tests only]
ImGuiItemStatusFlags_Openable = 1 << 10, //
ImGuiItemStatusFlags_Opened = 1 << 11, //
ImGuiItemStatusFlags_Checkable = 1 << 12, //
@@ -382,6 +426,12 @@ enum ImGuiItemStatusFlags_
#endif
};
+enum ImGuiTextFlags_
+{
+ ImGuiTextFlags_None = 0,
+ ImGuiTextFlags_NoWidthForLargeClippedText = 1 << 0
+};
+
// FIXME: this is in development, not exposed/functional as a generic feature yet.
// Horizontal/Vertical enums are fixed to 0/1 so they may be used to index ImVec2
enum ImGuiLayoutType_
@@ -390,6 +440,15 @@ enum ImGuiLayoutType_
ImGuiLayoutType_Vertical = 1
};
+enum ImGuiLogType
+{
+ ImGuiLogType_None = 0,
+ ImGuiLogType_TTY,
+ ImGuiLogType_File,
+ ImGuiLogType_Buffer,
+ ImGuiLogType_Clipboard
+};
+
// X/Y enums are fixed to 0/1 so they may be used to index ImVec2
enum ImGuiAxis
{
@@ -430,7 +489,7 @@ enum ImGuiNavHighlightFlags_
ImGuiNavHighlightFlags_None = 0,
ImGuiNavHighlightFlags_TypeDefault = 1 << 0,
ImGuiNavHighlightFlags_TypeThin = 1 << 1,
- ImGuiNavHighlightFlags_AlwaysDraw = 1 << 2,
+ ImGuiNavHighlightFlags_AlwaysDraw = 1 << 2, // Draw rectangular highlight if (g.NavId == id) _even_ when using the mouse.
ImGuiNavHighlightFlags_NoRounding = 1 << 3
};
@@ -485,8 +544,9 @@ struct ImVec1
struct ImVec2ih
{
short x, y;
- ImVec2ih() { x = y = 0; }
- ImVec2ih(short _x, short _y) { x = _x; y = _y; }
+ ImVec2ih() { x = y = 0; }
+ ImVec2ih(short _x, short _y) { x = _x; y = _y; }
+ explicit ImVec2ih(const ImVec2& rhs) { x = (short)rhs.x; y = (short)rhs.y; }
};
// 2D axis aligned bounding-box
@@ -525,6 +585,14 @@ struct IMGUI_API ImRect
bool IsInverted() const { return Min.x > Max.x || Min.y > Max.y; }
};
+// Type information associated to one ImGuiDataType. Retrieve with DataTypeGetInfo().
+struct ImGuiDataTypeInfo
+{
+ size_t Size; // Size in byte
+ const char* PrintFmt; // Default printf format for the type
+ const char* ScanFmt; // Default scanf format for the type
+};
+
// Stacked color modifier, backup of modified data so we can restore it
struct ImGuiColorMod
{
@@ -549,21 +617,19 @@ struct ImGuiGroupData
ImVec2 BackupCursorMaxPos;
ImVec1 BackupIndent;
ImVec1 BackupGroupOffset;
- ImVec2 BackupCurrentLineSize;
- float BackupCurrentLineTextBaseOffset;
- float BackupLogLinePosY;
+ ImVec2 BackupCurrLineSize;
+ float BackupCurrLineTextBaseOffset;
ImGuiID BackupActiveIdIsAlive;
bool BackupActiveIdPreviousFrameIsAlive;
- bool AdvanceCursor;
+ bool EmitItem;
};
// Simple column measurement, currently used for MenuItem() only.. This is very short-sighted/throw-away code and NOT a generic helper.
struct IMGUI_API ImGuiMenuColumns
{
- int Count;
float Spacing;
float Width, NextWidth;
- float Pos[4], NextWidths[4];
+ float Pos[3], NextWidths[3];
ImGuiMenuColumns();
void Update(int count, float spacing, bool clear);
@@ -575,29 +641,34 @@ struct IMGUI_API ImGuiMenuColumns
struct IMGUI_API ImGuiInputTextState
{
ImGuiID ID; // widget id owning the text state
+ int CurLenW, CurLenA; // we need to maintain our buffer length in both UTF-8 and wchar format. UTF-8 len is valid even if TextA is not.
ImVector TextW; // edit buffer, we need to persist but can't guarantee the persistence of the user-provided buffer. so we copy into own buffer.
- ImVector InitialText; // backup of end-user buffer at the time of focus (in UTF-8, unaltered)
- ImVector TempBuffer; // temporary buffer for callback and other other operations. size=capacity.
- int CurLenA, CurLenW; // we need to maintain our buffer length in both UTF-8 and wchar format.
+ ImVector TextA; // temporary UTF8 buffer for callbacks and other operations. this is not updated in every code-path! size=capacity.
+ ImVector InitialTextA; // backup of end-user buffer at the time of focus (in UTF-8, unaltered)
+ bool TextAIsValid; // temporary UTF8 buffer is not initially valid before we make the widget active (until then we pull the data from user argument)
int BufCapacityA; // end-user buffer capacity
- float ScrollX;
- ImGuiStb::STB_TexteditState StbState;
- float CursorAnim;
- bool CursorFollow;
- bool SelectedAllMouseLock;
-
- // Temporarily set when active
- ImGuiInputTextFlags UserFlags;
- ImGuiInputTextCallback UserCallback;
- void* UserCallbackData;
-
- ImGuiInputTextState() { memset(this, 0, sizeof(*this)); }
- void CursorAnimReset() { CursorAnim = -0.30f; } // After a user-input the cursor stays on for a while without blinking
- void CursorClamp() { StbState.cursor = ImMin(StbState.cursor, CurLenW); StbState.select_start = ImMin(StbState.select_start, CurLenW); StbState.select_end = ImMin(StbState.select_end, CurLenW); }
- bool HasSelection() const { return StbState.select_start != StbState.select_end; }
- void ClearSelection() { StbState.select_start = StbState.select_end = StbState.cursor; }
- void SelectAll() { StbState.select_start = 0; StbState.cursor = StbState.select_end = CurLenW; StbState.has_preferred_x = false; }
- void OnKeyPressed(int key); // Cannot be inline because we call in code in stb_textedit.h implementation
+ float ScrollX; // horizontal scrolling/offset
+ ImStb::STB_TexteditState Stb; // state for stb_textedit.h
+ float CursorAnim; // timer for cursor blink, reset on every user action so the cursor reappears immediately
+ bool CursorFollow; // set when we want scrolling to follow the current cursor position (not always!)
+ bool SelectedAllMouseLock; // after a double-click to select all, we ignore further mouse drags to update selection
+ ImGuiInputTextFlags UserFlags; // Temporarily set while we call user's callback
+ ImGuiInputTextCallback UserCallback; // "
+ void* UserCallbackData; // "
+
+ ImGuiInputTextState() { memset(this, 0, sizeof(*this)); }
+ void ClearText() { CurLenW = CurLenA = 0; TextW[0] = 0; TextA[0] = 0; CursorClamp(); }
+ void ClearFreeMemory() { TextW.clear(); TextA.clear(); InitialTextA.clear(); }
+ int GetUndoAvailCount() const { return Stb.undostate.undo_point; }
+ int GetRedoAvailCount() const { return STB_TEXTEDIT_UNDOSTATECOUNT - Stb.undostate.redo_point; }
+ void OnKeyPressed(int key); // Cannot be inline because we call in code in stb_textedit.h implementation
+
+ // Cursor & Selection
+ void CursorAnimReset() { CursorAnim = -0.30f; } // After a user-input the cursor stays on for a while without blinking
+ void CursorClamp() { Stb.cursor = ImMin(Stb.cursor, CurLenW); Stb.select_start = ImMin(Stb.select_start, CurLenW); Stb.select_end = ImMin(Stb.select_end, CurLenW); }
+ bool HasSelection() const { return Stb.select_start != Stb.select_end; }
+ void ClearSelection() { Stb.select_start = Stb.select_end = Stb.cursor; }
+ void SelectAll() { Stb.select_start = 0; Stb.cursor = Stb.select_end = CurLenW; Stb.has_preferred_x = 0; }
};
// Windows data saved in imgui.ini file
@@ -605,22 +676,22 @@ struct ImGuiWindowSettings
{
char* Name;
ImGuiID ID;
- ImVec2 Pos; // NB: Settings position are stored RELATIVE to the viewport! Whereas runtime ones are absolute positions.
- ImVec2 Size;
- ImVec2 ViewportPos;
+ ImVec2ih Pos; // NB: Settings position are stored RELATIVE to the viewport! Whereas runtime ones are absolute positions.
+ ImVec2ih Size;
+ ImVec2ih ViewportPos;
ImGuiID ViewportId;
ImGuiID DockId; // ID of last known DockNode (even if the DockNode is invisible because it has only 1 active window), or 0 if none.
ImGuiID ClassId; // ID of window class if specified
short DockOrder; // Order of the last time the window was visible within its DockNode. This is used to reorder windows that are reappearing on the same frame. Same value between windows that were active and windows that were none are possible.
bool Collapsed;
- ImGuiWindowSettings() { Name = NULL; ID = 0; Pos = Size = ViewportPos = ImVec2(0, 0); ViewportId = DockId = ClassId = 0; DockOrder = -1; Collapsed = false; }
+ ImGuiWindowSettings() { Name = NULL; ID = 0; Pos = Size = ViewportPos = ImVec2ih(0, 0); ViewportId = DockId = ClassId = 0; DockOrder = -1; Collapsed = false; }
};
struct ImGuiSettingsHandler
{
const char* TypeName; // Short description stored in .ini file. Disallowed characters: '[' ']'
- ImGuiID TypeHash; // == ImHashStr(TypeName, 0, 0)
+ ImGuiID TypeHash; // == ImHashStr(TypeName)
void* (*ReadOpenFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler, const char* name); // Read: Called when entering into a new ini entry e.g. "[Window][Name]"
void (*ReadLineFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler, void* entry, const char* line); // Read: Called for every line of text within an ini entry
void (*WriteAllFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* out_buf); // Write: Output every entries into 'out_buf'
@@ -630,15 +701,17 @@ struct ImGuiSettingsHandler
};
// Storage for current popup stack
-struct ImGuiPopupRef
+struct ImGuiPopupData
{
ImGuiID PopupId; // Set on OpenPopup()
ImGuiWindow* Window; // Resolved on BeginPopup() - may stay unresolved if user never calls OpenPopup()
- ImGuiWindow* ParentWindow; // Set on OpenPopup()
+ ImGuiWindow* SourceWindow; // Set on OpenPopup() copy of NavWindow at the time of opening the popup
int OpenFrameCount; // Set on OpenPopup()
- ImGuiID OpenParentId; // Set on OpenPopup(), we need this to differenciate multiple menu sets from each others (e.g. inside menu bar vs loose menu items)
+ ImGuiID OpenParentId; // Set on OpenPopup(), we need this to differentiate multiple menu sets from each others (e.g. inside menu bar vs loose menu items)
ImVec2 OpenPopupPos; // Set on OpenPopup(), preferred popup position (typically == OpenMousePos when using mouse)
ImVec2 OpenMousePos; // Set on OpenPopup(), copy of mouse position at the time of opening popup
+
+ ImGuiPopupData() { PopupId = 0; Window = SourceWindow = NULL; OpenFrameCount = -1; OpenParentId = 0; }
};
struct ImGuiColumnData
@@ -648,10 +721,10 @@ struct ImGuiColumnData
ImGuiColumnsFlags Flags; // Not exposed
ImRect ClipRect;
- ImGuiColumnData() { OffsetNorm = OffsetNormBeforeResize = 0.0f; Flags = 0; }
+ ImGuiColumnData() { OffsetNorm = OffsetNormBeforeResize = 0.0f; Flags = ImGuiColumnsFlags_None; }
};
-struct ImGuiColumnsSet
+struct ImGuiColumns
{
ImGuiID ID;
ImGuiColumnsFlags Flags;
@@ -659,25 +732,27 @@ struct ImGuiColumnsSet
bool IsBeingResized;
int Current;
int Count;
- float MinX, MaxX;
+ float OffMinX, OffMaxX; // Offsets from HostWorkRect.Min.x
float LineMinY, LineMaxY;
- float StartPosY; // Copy of CursorPos
- float StartMaxPosX; // Copy of CursorMaxPos
+ float HostCursorPosY; // Backup of CursorPos at the time of BeginColumns()
+ float HostCursorMaxPosX; // Backup of CursorMaxPos at the time of BeginColumns()
+ ImRect HostClipRect; // Backup of ClipRect at the time of BeginColumns()
+ ImRect HostWorkRect; // Backup of WorkRect at the time of BeginColumns()
ImVector Columns;
- ImGuiColumnsSet() { Clear(); }
+ ImGuiColumns() { Clear(); }
void Clear()
{
ID = 0;
- Flags = 0;
+ Flags = ImGuiColumnsFlags_None;
IsFirstFrame = false;
IsBeingResized = false;
Current = 0;
Count = 1;
- MinX = MaxX = 0.0f;
+ OffMinX = OffMaxX = 0.0f;
LineMinY = LineMaxY = 0.0f;
- StartPosY = 0.0f;
- StartMaxPosX = 0.0f;
+ HostCursorPosY = 0.0f;
+ HostCursorMaxPosX = 0.0f;
Columns.clear();
}
};
@@ -690,6 +765,7 @@ struct IMGUI_API ImDrawListSharedData
float FontSize; // Current/default font size (optional, for simplified AddText overload)
float CurveTessellationTol;
ImVec4 ClipRectFullscreen; // Value for PushClipRectFullscreen()
+ ImDrawListFlags InitialFlags; // Initial flags at the beginning of the frame (it is possible to alter flags on a per-drawlist basis afterwards)
// Const data
// FIXME: Bake rounded corners fill/borders in atlas
@@ -707,18 +783,13 @@ struct ImDrawDataBuilder
IMGUI_API void FlattenIntoSingleLayer();
};
-enum ImGuiViewportFlagsPrivate_
-{
- ImGuiViewportFlags_CanHostOtherWindows = 1 << 10 // Normal viewports are associated to a single window. The main viewport can host multiple windows.
-};
-
// ImGuiViewport Private/Internals fields (cardinal sin: we are using inheritance!)
// Note that every instance of ImGuiViewport is in fact a ImGuiViewportP.
struct ImGuiViewportP : public ImGuiViewport
{
int Idx;
int LastFrameActive; // Last frame number this viewport was activated by a window
- int LastFrameOverlayDrawList;
+ int LastFrameDrawLists[2]; // Last frame number the background (0) and foreground (1) draw lists were used
int LastFrontMostStampCount; // Last stamp number from when a window hosted by this viewport was made front-most (by comparing this value between two viewport we have an implicit viewport z-order
ImGuiID LastNameHash;
ImVec2 LastPos;
@@ -726,17 +797,16 @@ struct ImGuiViewportP : public ImGuiViewport
float LastAlpha;
short PlatformMonitor;
bool PlatformWindowCreated;
- bool PlatformWindowMinimized; // When minimized we tend to avoid using the viewport pos/size for clipping window or testing if they are contained in the viewport
ImGuiWindow* Window; // Set when the viewport is owned by a window (and ImGuiViewportFlags_CanHostOtherWindows is NOT set)
- ImDrawList* OverlayDrawList; // For convenience, a draw list we can render to that's always rendered last (we use it to draw software mouse cursor when io.MouseDrawCursor is set)
+ ImDrawList* DrawLists[2]; // Convenience background (0) and foreground (1) draw lists. We use them to draw software mouser cursor when io.MouseDrawCursor is set and to draw most debug overlays.
ImDrawData DrawDataP;
ImDrawDataBuilder DrawDataBuilder;
ImVec2 LastPlatformPos;
ImVec2 LastPlatformSize;
ImVec2 LastRendererSize;
- ImGuiViewportP() { Idx = -1; LastFrameActive = LastFrameOverlayDrawList = LastFrontMostStampCount = -1; LastNameHash = 0; Alpha = LastAlpha = 1.0f; PlatformMonitor = -1; PlatformWindowCreated = PlatformWindowMinimized = false; Window = NULL; OverlayDrawList = NULL; LastPlatformPos = LastPlatformSize = LastRendererSize = ImVec2(FLT_MAX, FLT_MAX); }
- ~ImGuiViewportP() { if (OverlayDrawList) IM_DELETE(OverlayDrawList); }
+ ImGuiViewportP() { Idx = -1; LastFrameActive = LastFrameDrawLists[0] = LastFrameDrawLists[1] = LastFrontMostStampCount = -1; LastNameHash = 0; Alpha = LastAlpha = 1.0f; PlatformMonitor = -1; PlatformWindowCreated = false; Window = NULL; DrawLists[0] = DrawLists[1] = NULL; LastPlatformPos = LastPlatformSize = LastRendererSize = ImVec2(FLT_MAX, FLT_MAX); }
+ ~ImGuiViewportP() { if (DrawLists[0]) IM_DELETE(DrawLists[0]); if (DrawLists[1]) IM_DELETE(DrawLists[1]); }
ImRect GetRect() const { return ImRect(Pos.x, Pos.y, Pos.x + Size.x, Pos.y + Size.y); }
ImVec2 GetCenter() const { return ImVec2(Pos.x + Size.x * 0.5f, Pos.y + Size.y * 0.5f); }
void ClearRequestFlags() { PlatformRequestClose = PlatformRequestMove = PlatformRequestResize = false; }
@@ -745,6 +815,7 @@ struct ImGuiViewportP : public ImGuiViewport
struct ImGuiNavMoveResult
{
ImGuiID ID; // Best candidate
+ ImGuiID SelectScopeId;// Best candidate window current selectable group ID
ImGuiWindow* Window; // Best candidate window
float DistBox; // Best candidate box distance to current NavId
float DistCenter; // Best candidate center distance to current NavId
@@ -752,84 +823,126 @@ struct ImGuiNavMoveResult
ImRect RectRel; // Best candidate bounding box in window relative space
ImGuiNavMoveResult() { Clear(); }
- void Clear() { ID = 0; Window = NULL; DistBox = DistCenter = DistAxial = FLT_MAX; RectRel = ImRect(); }
+ void Clear() { ID = SelectScopeId = 0; Window = NULL; DistBox = DistCenter = DistAxial = FLT_MAX; RectRel = ImRect(); }
+};
+
+enum ImGuiNextWindowDataFlags_
+{
+ ImGuiNextWindowDataFlags_None = 0,
+ ImGuiNextWindowDataFlags_HasPos = 1 << 0,
+ ImGuiNextWindowDataFlags_HasSize = 1 << 1,
+ ImGuiNextWindowDataFlags_HasContentSize = 1 << 2,
+ ImGuiNextWindowDataFlags_HasCollapsed = 1 << 3,
+ ImGuiNextWindowDataFlags_HasSizeConstraint = 1 << 4,
+ ImGuiNextWindowDataFlags_HasFocus = 1 << 5,
+ ImGuiNextWindowDataFlags_HasBgAlpha = 1 << 6,
+ ImGuiNextWindowDataFlags_HasViewport = 1 << 7,
+ ImGuiNextWindowDataFlags_HasDock = 1 << 8,
+ ImGuiNextWindowDataFlags_HasWindowClass = 1 << 9
};
// Storage for SetNexWindow** functions
struct ImGuiNextWindowData
{
- ImGuiCond PosCond;
- ImGuiCond SizeCond;
- ImGuiCond ContentSizeCond;
- ImGuiCond CollapsedCond;
- ImGuiCond SizeConstraintCond;
- ImGuiCond FocusCond;
- ImGuiCond BgAlphaCond;
- ImGuiCond ViewportCond;
- ImGuiCond DockCond;
- ImVec2 PosVal;
- ImVec2 PosPivotVal;
- ImVec2 SizeVal;
- ImVec2 ContentSizeVal;
- bool PosUndock;
- bool CollapsedVal;
- ImRect SizeConstraintRect;
- ImGuiSizeCallback SizeCallback;
- void* SizeCallbackUserData;
- float BgAlphaVal;
- ImGuiID ViewportId;
- ImGuiID DockId;
- ImGuiWindowClass WindowClass;
- ImVec2 MenuBarOffsetMinVal; // This is not exposed publicly, so we don't clear it.
+ ImGuiNextWindowDataFlags Flags;
+ ImGuiCond PosCond;
+ ImGuiCond SizeCond;
+ ImGuiCond CollapsedCond;
+ ImGuiCond DockCond;
+ ImVec2 PosVal;
+ ImVec2 PosPivotVal;
+ ImVec2 SizeVal;
+ ImVec2 ContentSizeVal;
+ bool PosUndock;
+ bool CollapsedVal;
+ ImRect SizeConstraintRect;
+ ImGuiSizeCallback SizeCallback;
+ void* SizeCallbackUserData;
+ float BgAlphaVal;
+ ImGuiID ViewportId;
+ ImGuiID DockId;
+ ImGuiWindowClass WindowClass;
+ ImVec2 MenuBarOffsetMinVal; // *Always on* This is not exposed publicly, so we don't clear it.
+
+ ImGuiNextWindowData() { memset(this, 0, sizeof(*this)); }
+ inline void ClearFlags() { Flags = ImGuiNextWindowDataFlags_None; }
+};
- ImGuiNextWindowData()
- {
- PosCond = SizeCond = ContentSizeCond = CollapsedCond = SizeConstraintCond = FocusCond = BgAlphaCond = ViewportCond = DockCond = 0;
- PosVal = PosPivotVal = SizeVal = ImVec2(0.0f, 0.0f);
- ContentSizeVal = ImVec2(0.0f, 0.0f);
- PosUndock = CollapsedVal = false;
- SizeConstraintRect = ImRect();
- SizeCallback = NULL;
- SizeCallbackUserData = NULL;
- BgAlphaVal = FLT_MAX;
- ViewportId = DockId = 0;
- MenuBarOffsetMinVal = ImVec2(0.0f, 0.0f);
- }
+enum ImGuiNextItemDataFlags_
+{
+ ImGuiNextItemDataFlags_None = 0,
+ ImGuiNextItemDataFlags_HasWidth = 1 << 0,
+ ImGuiNextItemDataFlags_HasOpen = 1 << 1
+};
- void Clear()
- {
- PosCond = SizeCond = ContentSizeCond = CollapsedCond = SizeConstraintCond = FocusCond = BgAlphaCond = ViewportCond = DockCond = 0;
- WindowClass = ImGuiWindowClass();
- }
+struct ImGuiNextItemData
+{
+ ImGuiNextItemDataFlags Flags;
+ float Width; // Set by SetNextItemWidth().
+ bool OpenVal; // Set by SetNextItemOpen() function.
+ ImGuiCond OpenCond;
+
+ ImGuiNextItemData() { memset(this, 0, sizeof(*this)); }
+ inline void ClearFlags() { Flags = ImGuiNextItemDataFlags_None; }
};
//-----------------------------------------------------------------------------
// Docking, Tabs
//-----------------------------------------------------------------------------
-struct ImGuiTabBarSortItem
+struct ImGuiShrinkWidthItem
+{
+ int Index;
+ float Width;
+};
+
+struct ImGuiPtrOrIndex
{
- int Index;
- float Width;
+ void* Ptr; // Either field can be set, not both. e.g. Dock node tab bars are loose while BeginTabBar() ones are in a pool.
+ int Index; // Usually index in a main pool.
+
+ ImGuiPtrOrIndex(void* ptr) { Ptr = ptr; Index = -1; }
+ ImGuiPtrOrIndex(int index) { Ptr = NULL; Index = index; }
};
+// Extend ImGuiDockNodeFlags_
enum ImGuiDockNodeFlagsPrivate_
{
- ImGuiDockNodeFlags_Dockspace = 1 << 10
+ // [Internal]
+ ImGuiDockNodeFlags_DockSpace = 1 << 10, // Local, Saved // A dockspace is a node that occupy space within an existing user window. Otherwise the node is floating and create its own window.
+ ImGuiDockNodeFlags_CentralNode = 1 << 11, // Local, Saved //
+ ImGuiDockNodeFlags_NoTabBar = 1 << 12, // Local, Saved // Tab bar is completely unavailable. No triangle in the corner to enable it back.
+ ImGuiDockNodeFlags_HiddenTabBar = 1 << 13, // Local, Saved // Tab bar is hidden, with a triangle in the corner to show it again (NB: actual tab-bar instance may be destroyed as this is only used for single-window tab bar)
+ ImGuiDockNodeFlags_NoWindowMenuButton = 1 << 14, // Local, Saved // Disable window/docking menu (that one that appears instead of the collapse button)
+ ImGuiDockNodeFlags_NoCloseButton = 1 << 15, // Local, Saved //
+ ImGuiDockNodeFlags_SharedFlagsInheritMask_ = ~0,
+ ImGuiDockNodeFlags_LocalFlagsMask_ = ImGuiDockNodeFlags_NoSplit | ImGuiDockNodeFlags_NoResize | ImGuiDockNodeFlags_AutoHideTabBar | ImGuiDockNodeFlags_DockSpace | ImGuiDockNodeFlags_CentralNode | ImGuiDockNodeFlags_NoTabBar | ImGuiDockNodeFlags_HiddenTabBar | ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton,
+ ImGuiDockNodeFlags_LocalFlagsTransferMask_ = ImGuiDockNodeFlags_LocalFlagsMask_ & ~ImGuiDockNodeFlags_DockSpace, // When splitting those flags are moved to the inheriting child, never duplicated
+ ImGuiDockNodeFlags_SavedFlagsMask_ = ImGuiDockNodeFlags_NoResize | ImGuiDockNodeFlags_DockSpace | ImGuiDockNodeFlags_CentralNode | ImGuiDockNodeFlags_NoTabBar | ImGuiDockNodeFlags_HiddenTabBar | ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton
};
-enum ImGuiDataAutority
+// Store the source authority (dock node vs window) of a field
+enum ImGuiDataAuthority_
{
- ImGuiDataAutority_Auto,
- ImGuiDataAutority_DockNode,
- ImGuiDataAutority_Window
+ ImGuiDataAuthority_Auto,
+ ImGuiDataAuthority_DockNode,
+ ImGuiDataAuthority_Window
+};
+
+enum ImGuiDockNodeState
+{
+ ImGuiDockNodeState_Unknown,
+ ImGuiDockNodeState_HostWindowHiddenBecauseSingleWindow,
+ ImGuiDockNodeState_HostWindowHiddenBecauseWindowsAreResizing,
+ ImGuiDockNodeState_HostWindowVisible
};
// sizeof() 116~160
struct ImGuiDockNode
{
ImGuiID ID;
- ImGuiDockNodeFlags Flags;
+ ImGuiDockNodeFlags SharedFlags; // Flags shared by all nodes of a same dockspace hierarchy (inherited from the root node)
+ ImGuiDockNodeFlags LocalFlags; // Flags specific to this node
ImGuiDockNode* ParentNode;
ImGuiDockNode* ChildNodes[2]; // [Split node only] Child nodes (left/right or top/bottom). Consider switching to an array.
ImVector Windows; // Note: unordered list! Iterate TabBar->Tabs for user-order.
@@ -840,6 +953,7 @@ struct ImGuiDockNode
int SplitAxis; // [Split node only] Split axis (X or Y)
ImGuiWindowClass WindowClass;
+ ImGuiDockNodeState State;
ImGuiWindow* HostWindow;
ImGuiWindow* VisibleWindow; // Generally point to window which is ID is == SelectedTabID, but when CTRL+Tabbing this can be a different window.
ImGuiDockNode* CentralNode; // [Root node only] Pointer to central node.
@@ -848,31 +962,36 @@ struct ImGuiDockNode
int LastFrameActive; // Last frame number the node was updated.
int LastFrameFocused; // Last frame number the node was focused.
ImGuiID LastFocusedNodeID; // [Root node only] Which of our child docking node (any ancestor in the hierarchy) was last focused.
- ImGuiID SelectedTabID; // [Tab node only] Which of our tab is selected.
- ImGuiID WantCloseTabID; // [Tab node only] Set when closing a specific tab.
- ImGuiDataAutority AutorityForPos :3;
- ImGuiDataAutority AutorityForSize :3;
- ImGuiDataAutority AutorityForViewport :3;
+ ImGuiID SelectedTabID; // [Leaf node only] Which of our tab/window is selected.
+ ImGuiID WantCloseTabID; // [Leaf node only] Set when closing a specific tab/window.
+ ImGuiDataAuthority AuthorityForPos :3;
+ ImGuiDataAuthority AuthorityForSize :3;
+ ImGuiDataAuthority AuthorityForViewport :3;
bool IsVisible :1; // Set to false when the node is hidden (usually disabled as it has no active window)
bool IsFocused :1;
- bool IsCentralNode :1;
- bool IsHiddenTabBar :1;
bool HasCloseButton :1;
- bool HasCollapseButton :1;
+ bool HasWindowMenuButton :1;
+ bool EnableCloseButton :1;
bool WantCloseAll :1; // Set when closing all tabs at once.
bool WantLockSizeOnce :1;
bool WantMouseMove :1; // After a node extraction we need to transition toward moving the newly created host window
bool WantHiddenTabBarUpdate :1;
bool WantHiddenTabBarToggle :1;
+ bool MarkedForPosSizeWrite :1; // Update by DockNodeTreeUpdatePosSize() write-filtering
ImGuiDockNode(ImGuiID id);
~ImGuiDockNode();
- bool IsRootNode() const { return ParentNode == NULL; }
- bool IsDockSpace() const { return (Flags & ImGuiDockNodeFlags_Dockspace) != 0; }
- bool IsSplitNode() const { return ChildNodes[0] != NULL; }
- bool IsLeafNode() const { return ChildNodes[0] == NULL; }
- bool IsEmpty() const { return ChildNodes[0] == NULL && Windows.Size == 0; }
- ImRect Rect() const { return ImRect(Pos.x, Pos.y, Pos.x + Size.x, Pos.y + Size.y); }
+ bool IsRootNode() const { return ParentNode == NULL; }
+ bool IsDockSpace() const { return (LocalFlags & ImGuiDockNodeFlags_DockSpace) != 0; }
+ bool IsFloatingNode() const { return ParentNode == NULL && (LocalFlags & ImGuiDockNodeFlags_DockSpace) == 0; }
+ bool IsCentralNode() const { return (LocalFlags & ImGuiDockNodeFlags_CentralNode) != 0; }
+ bool IsHiddenTabBar() const { return (LocalFlags & ImGuiDockNodeFlags_HiddenTabBar) != 0; } // Hidden tab bar can be shown back by clicking the small triangle
+ bool IsNoTabBar() const { return (LocalFlags & ImGuiDockNodeFlags_NoTabBar) != 0; } // Never show a tab bar
+ bool IsSplitNode() const { return ChildNodes[0] != NULL; }
+ bool IsLeafNode() const { return ChildNodes[0] == NULL; }
+ bool IsEmpty() const { return ChildNodes[0] == NULL && Windows.Size == 0; }
+ ImGuiDockNodeFlags GetMergedFlags() const { return SharedFlags | LocalFlags; }
+ ImRect Rect() const { return ImRect(Pos.x, Pos.y, Pos.x + Size.x, Pos.y + Size.y); }
};
//-----------------------------------------------------------------------------
@@ -883,65 +1002,76 @@ struct ImGuiContext
{
bool Initialized;
bool FrameScopeActive; // Set by NewFrame(), cleared by EndFrame()
- bool FrameScopePushedImplicitWindow; // Set by NewFrame(), cleared by EndFrame()
+ bool FrameScopePushedFallbackWindow; // Set by NewFrame(), cleared by EndFrame()
bool FontAtlasOwnedByContext; // Io.Fonts-> is owned by the ImGuiContext and will be destructed along with it.
ImGuiIO IO;
ImGuiPlatformIO PlatformIO;
ImGuiStyle Style;
- ImGuiConfigFlags ConfigFlagsForFrame; // = g.IO.ConfigFlags at the time of NewFrame()
+ ImGuiConfigFlags ConfigFlagsCurrFrame; // = g.IO.ConfigFlags at the time of NewFrame()
+ ImGuiConfigFlags ConfigFlagsLastFrame;
ImFont* Font; // (Shortcut) == FontStack.empty() ? IO.Font : FontStack.back()
float FontSize; // (Shortcut) == FontBaseSize * g.CurrentWindow->FontWindowScale == window->FontSize(). Text height for current window.
float FontBaseSize; // (Shortcut) == IO.FontGlobalScale * Font->Scale * Font->FontSize. Base text height.
ImDrawListSharedData DrawListSharedData;
-
double Time;
int FrameCount;
int FrameCountEnded;
int FrameCountPlatformEnded;
int FrameCountRendered;
+
+ // Windows state
ImVector Windows; // Windows, sorted in display order, back to front
ImVector WindowsFocusOrder; // Windows, sorted in focus order, back to front
ImVector WindowsSortBuffer;
ImVector CurrentWindowStack;
ImGuiStorage WindowsById;
int WindowsActiveCount;
- int WindowsFrontMostStampCount; // Every time the front-most window changes, we stamp its viewport with an incrementing counter
ImGuiWindow* CurrentWindow; // Being drawn into
ImGuiWindow* HoveredWindow; // Will catch mouse inputs
ImGuiWindow* HoveredRootWindow; // Will catch mouse inputs (for focus/move only)
ImGuiWindow* HoveredWindowUnderMovingWindow; // Hovered window ignoring MovingWindow. Only set if MovingWindow is set.
+ ImGuiWindow* MovingWindow; // Track the window we clicked on (in order to preserve focus). The actually window that is moved is generally MovingWindow->RootWindow.
+ ImGuiWindow* WheelingWindow;
+ ImVec2 WheelingWindowRefMousePos;
+ float WheelingWindowTimer;
+
+ // Item/widgets state and tracking information
ImGuiID HoveredId; // Hovered widget
bool HoveredIdAllowOverlap;
ImGuiID HoveredIdPreviousFrame;
float HoveredIdTimer; // Measure contiguous hovering time
float HoveredIdNotActiveTimer; // Measure contiguous hovering time where the item has not been active
ImGuiID ActiveId; // Active widget
- ImGuiID ActiveIdPreviousFrame;
ImGuiID ActiveIdIsAlive; // Active widget has been seen this frame (we can't use a bool as the ActiveId may change within the frame)
float ActiveIdTimer;
bool ActiveIdIsJustActivated; // Set at the time of activation for one frame
bool ActiveIdAllowOverlap; // Active widget allows another widget to steal active id (generally for overlapping widgets, but not always)
- bool ActiveIdHasBeenEdited; // Was the value associated to the widget Edited over the course of the Active state.
- bool ActiveIdPreviousFrameIsAlive;
- bool ActiveIdPreviousFrameHasBeenEdited;
+ bool ActiveIdHasBeenPressedBefore; // Track whether the active id led to a press (this is to allow changing between PressOnClick and PressOnRelease without pressing twice). Used by range_select branch.
+ bool ActiveIdHasBeenEditedBefore; // Was the value associated to the widget Edited over the course of the Active state.
+ bool ActiveIdHasBeenEditedThisFrame;
int ActiveIdAllowNavDirFlags; // Active widget allows using directional navigation (e.g. can activate a button and move away from it)
int ActiveIdBlockNavInputFlags;
ImVec2 ActiveIdClickOffset; // Clicked offset from upper-left corner, if applicable (currently only set by ButtonBehavior)
ImGuiWindow* ActiveIdWindow;
- ImGuiWindow* ActiveIdPreviousFrameWindow;
ImGuiInputSource ActiveIdSource; // Activating with mouse or nav (gamepad/keyboard)
+ ImGuiID ActiveIdPreviousFrame;
+ bool ActiveIdPreviousFrameIsAlive;
+ bool ActiveIdPreviousFrameHasBeenEditedBefore;
+ ImGuiWindow* ActiveIdPreviousFrameWindow;
+
ImGuiID LastActiveId; // Store the last non-zero ActiveId, useful for animation.
float LastActiveIdTimer; // Store the last non-zero ActiveId timer since the beginning of activation, useful for animation.
- ImVec2 LastValidMousePos;
- ImGuiWindow* MovingWindow; // Track the window we clicked on (in order to preserve focus). The actually window that is moved is generally MovingWindow->RootWindow.
+
+ // Next window/item data
+ ImGuiNextWindowData NextWindowData; // Storage for SetNextWindow** functions
+ ImGuiNextItemData NextItemData; // Storage for SetNextItem** functions
+
+ // Shared stacks
ImVector ColorModifiers; // Stack for PushStyleColor()/PopStyleColor()
ImVector StyleModifiers; // Stack for PushStyleVar()/PopStyleVar()
ImVector FontStack; // Stack for PushFont()/PopFont()
- ImVector OpenPopupStack; // Which popups are open (persistent)
- ImVector BeginPopupStack; // Which level of BeginPopup() we are in (reset every frame)
- ImGuiNextWindowData NextWindowData; // Storage for SetNextWindow** functions
- bool NextTreeNodeOpenVal; // Storage for SetNextTreeNode** functions
- ImGuiCond NextTreeNodeOpenCond;
+ ImVectorOpenPopupStack; // Which popups are open (persistent)
+ ImVectorBeginPopupStack; // Which level of BeginPopup() we are in (reset every frame)
// Viewports
ImVector Viewports; // Active viewports (always 1+, and generally 1 unless multi-viewports are enabled). Each viewports hold their copy of ImDrawData.
@@ -949,6 +1079,7 @@ struct ImGuiContext
ImGuiViewportP* MouseViewport;
ImGuiViewportP* MouseLastHoveredViewport; // Last known viewport that was hovered by mouse (even if we are not hovering any viewport any more) + honoring the _NoInputs flag.
ImGuiID PlatformLastFocusedViewport; // Record of last focused platform window/viewport, when this changes we stamp the viewport as front-most
+ int ViewportFrontMostStampCount; // Every time the front-most window changes, we stamp its viewport with an incrementing counter
// Navigation data (for gamepad/keyboard)
ImGuiWindow* NavWindow; // Focused window for navigation. Could be called 'FocusWindow'
@@ -958,12 +1089,13 @@ struct ImGuiContext
ImGuiID NavActivatePressedId; // ~~ IsNavInputPressed(ImGuiNavInput_Activate) ? NavId : 0
ImGuiID NavInputId; // ~~ IsNavInputPressed(ImGuiNavInput_Input) ? NavId : 0
ImGuiID NavJustTabbedId; // Just tabbed to this id.
- ImGuiID NavJustMovedToId; // Just navigated to this id (result of a successfully MoveRequest)
- ImGuiID NavNextActivateId; // Set by ActivateItem(), queued until next frame
+ ImGuiID NavJustMovedToId; // Just navigated to this id (result of a successfully MoveRequest).
+ ImGuiID NavJustMovedToMultiSelectScopeId; // Just navigated to this select scope id (result of a successfully MoveRequest).
+ ImGuiID NavNextActivateId; // Set by ActivateItem(), queued until next frame.
ImGuiInputSource NavInputSource; // Keyboard or Gamepad mode? THIS WILL ONLY BE None or NavGamepad or NavKeyboard.
ImRect NavScoringRectScreen; // Rectangle used for scoring, in screen space. Based of window->DC.NavRefRectRel[], modified for directional navigation scoring.
int NavScoringCount; // Metrics for debugging
- ImGuiWindow* NavWindowingTarget; // When selecting a window (holding Menu+FocusPrev/Next, or equivalent of CTRL-TAB) this window is temporarily displayed front-most.
+ ImGuiWindow* NavWindowingTarget; // When selecting a window (holding Menu+FocusPrev/Next, or equivalent of CTRL-TAB) this window is temporarily displayed top-most.
ImGuiWindow* NavWindowingTargetAnim; // Record of last valid NavWindowingTarget until DimBgRatio and NavWindowingHighlightAlpha becomes 0.0f
ImGuiWindow* NavWindowingList;
float NavWindowingTimer;
@@ -990,6 +1122,15 @@ struct ImGuiContext
ImGuiNavMoveResult NavMoveResultLocalVisibleSet; // Best move request candidate within NavWindow that are mostly visible (when using ImGuiNavMoveFlags_AlsoScoreVisibleSet flag)
ImGuiNavMoveResult NavMoveResultOther; // Best move request candidate within NavWindow's flattened hierarchy (when using ImGuiWindowFlags_NavFlattened flag)
+ // Tabbing system (older than Nav, active even if Nav is disabled. FIXME-NAV: This needs a redesign!)
+ ImGuiWindow* FocusRequestCurrWindow; //
+ ImGuiWindow* FocusRequestNextWindow; //
+ int FocusRequestCurrCounterAll; // Any item being requested for focus, stored as an index (we on layout to be stable between the frame pressing TAB and the next frame, semi-ouch)
+ int FocusRequestCurrCounterTab; // Tab item being requested for focus, stored as an index
+ int FocusRequestNextCounterAll; // Stored for next frame
+ int FocusRequestNextCounterTab; // "
+ bool FocusTabPressed; //
+
// Render
float DimBgRatio; // 0.0..1.0 animation when fading in a dimming background (for modal window and CTRL+TAB list)
ImGuiMouseCursor MouseCursor;
@@ -1012,25 +1153,32 @@ struct ImGuiContext
unsigned char DragDropPayloadBufLocal[8]; // Local buffer for small payloads
// Tab bars
- ImPool TabBars;
- ImVector CurrentTabBar;
- ImVector