2019-11-28 19:58:16 +00:00
// dear imgui, v1.75 WIP
2015-12-24 18:56:47 +00:00
// (main code and documentation)
2015-07-21 23:00:28 +00:00
2017-12-24 17:16:22 +00:00
// Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp for demo code.
2017-09-14 23:31:41 +00:00
// Newcomers, read 'Programmer guide' below for notes on how to setup Dear ImGui in your codebase.
2014-08-10 20:58:11 +00:00
// Get latest version at https://github.com/ocornut/imgui
2015-08-05 17:04:13 +00:00
// Releases change-log at https://github.com/ocornut/imgui/releases
2019-10-25 13:33:10 +00:00
// Technical Support for Getting Started https://github.com/ocornut/imgui/wiki
2019-10-15 11:00:04 +00:00
// Gallery (please post your screenshots/video there!): https://github.com/ocornut/imgui/issues/2847
2019-01-02 09:57:57 +00:00
2015-09-05 19:03:05 +00:00
// Developed by Omar Cornut and every direct or indirect contributors to the GitHub.
2019-01-02 09:57:57 +00:00
// See LICENSE.txt for copyright and licensing details (standard MIT License).
2015-09-05 19:03:05 +00:00
// This library is free but I need your support to sustain development and maintenance.
2019-01-02 09:57:57 +00:00
// Businesses: you can support continued maintenance and development via support contracts or sponsoring, see docs/README.
// Individuals: you can support continued maintenance and development via donations or Patreon https://www.patreon.com/imgui.
2018-03-25 12:45:40 +00:00
// It is recommended that you don't modify imgui.cpp! It will become difficult for you to update the library.
2018-05-17 12:12:37 +00:00
// Note that 'ImGui::' being a namespace, you can add functions into the namespace from your own source files, without
// modifying imgui.h or imgui.cpp. You may include imgui_internal.h to access internal data structures, but it doesn't
// come with any guarantee of forward compatibility. Discussing your changes on the GitHub Issue Tracker may lead you
2018-04-03 18:22:44 +00:00
// to a better solution or official support for them.
2014-08-10 20:58:11 +00:00
/*
2014-11-10 01:29:01 +00:00
2018-08-31 07:50:14 +00:00
Index of this file :
DOCUMENTATION
2018-09-06 09:35:13 +00:00
2018-08-31 07:50:14 +00:00
- MISSION STATEMENT
- END - USER GUIDE
2019-10-16 09:03:41 +00:00
- PROGRAMMER GUIDE
2019-11-19 14:22:42 +00:00
- READ FIRST
- HOW TO UPDATE TO A NEWER VERSION OF DEAR IMGUI
- GETTING STARTED WITH INTEGRATING DEAR IMGUI IN YOUR CODE / ENGINE
- HOW A SIMPLE APPLICATION MAY LOOK LIKE ( 2 variations )
- HOW A SIMPLE RENDERING FUNCTION MAY LOOK LIKE
- USING GAMEPAD / KEYBOARD NAVIGATION CONTROLS
2018-08-31 07:50:14 +00:00
- API BREAKING CHANGES ( read me when you update ! )
2019-10-15 11:00:04 +00:00
- FREQUENTLY ASKED QUESTIONS ( FAQ )
2019-10-16 09:03:41 +00:00
- Read all answers online : https : //www.dearimgui.org/faq, or in docs/FAQ.md (with a Markdown viewer)
2018-08-31 07:50:14 +00:00
2019-01-20 16:56:17 +00:00
CODE
2018-09-06 09:35:13 +00:00
( search for " [SECTION] " in the code to find them )
// [SECTION] FORWARD DECLARATIONS
// [SECTION] CONTEXT AND MEMORY ALLOCATORS
// [SECTION] MAIN USER FACING STRUCTURES (ImGuiStyle, ImGuiIO)
2019-12-17 15:24:50 +00:00
// [SECTION] MISC HELPERS/UTILITIES (Geometry functions)
// [SECTION] MISC HELPERS/UTILITIES (String, Format, Hash functions)
2019-11-19 20:14:44 +00:00
// [SECTION] MISC HELPERS/UTILITIES (File functions)
2019-02-21 11:35:21 +00:00
// [SECTION] MISC HELPERS/UTILITIES (ImText* functions)
// [SECTION] MISC HELPERS/UTILITIES (Color functions)
2018-09-06 09:35:13 +00:00
// [SECTION] ImGuiStorage
// [SECTION] ImGuiTextFilter
// [SECTION] ImGuiTextBuffer
// [SECTION] ImGuiListClipper
// [SECTION] RENDER HELPERS
// [SECTION] MAIN CODE (most of the code! lots of stuff, needs tidying up!)
2019-11-13 20:35:42 +00:00
// [SECTION] ERROR CHECKING
2019-07-31 03:04:02 +00:00
// [SECTION] SCROLLING
2018-09-06 09:35:13 +00:00
// [SECTION] TOOLTIPS
// [SECTION] POPUPS
// [SECTION] KEYBOARD/GAMEPAD NAVIGATION
// [SECTION] DRAG AND DROP
// [SECTION] LOGGING/CAPTURING
// [SECTION] SETTINGS
// [SECTION] PLATFORM DEPENDENT HELPERS
// [SECTION] METRICS/DEBUG WINDOW
2014-11-10 01:29:01 +00:00
2018-08-31 07:50:14 +00:00
*/
//-----------------------------------------------------------------------------
2018-09-06 09:35:13 +00:00
// DOCUMENTATION
2018-08-31 07:50:14 +00:00
//-----------------------------------------------------------------------------
/*
2015-08-24 11:50:18 +00:00
2014-08-10 20:58:11 +00:00
MISSION STATEMENT
2014-09-24 13:06:34 +00:00
= = = = = = = = = = = = = = = = =
2014-08-10 20:58:11 +00:00
2019-01-02 09:57:57 +00:00
- Easy to use to create code - driven and data - driven tools .
- Easy to use to create ad hoc short - lived tools and long - lived , more elaborate tools .
- Easy to hack and improve .
- Minimize screen real - estate usage .
- Minimize setup and maintenance .
- Minimize state storage on user side .
- Portable , minimize dependencies , run on target ( consoles , phones , etc . ) .
- Efficient runtime and memory consumption ( NB - we do allocate when " growing " content e . g . creating a window , .
opening a tree node for the first time , etc . but a typical frame should not allocate anything ) .
2014-08-10 20:58:11 +00:00
Designed for developers and content - creators , not the typical end - user ! Some of the weaknesses includes :
2019-01-02 09:57:57 +00:00
- Doesn ' t look fancy , doesn ' t animate .
- Limited layout features , intricate layouts are typically crafted in code .
2015-03-07 21:54:46 +00:00
2014-12-04 11:42:13 +00:00
2014-09-24 13:06:34 +00:00
END - USER GUIDE
= = = = = = = = = = = = = =
2014-08-10 20:58:11 +00:00
2017-11-01 11:33:38 +00:00
- Double - click on title bar to collapse window .
- Click upper right corner to close a window , available when ' bool * p_open ' is passed to ImGui : : Begin ( ) .
- Click and drag on lower right corner to resize window ( double - click to auto fit window to its contents ) .
- Click and drag on any empty space to move window .
- TAB / SHIFT + TAB to cycle through keyboard editable fields .
- CTRL + Click on a slider or drag box to input value as text .
- Use mouse wheel to scroll .
2016-07-31 13:41:51 +00:00
- Text editor :
2014-08-10 20:58:11 +00:00
- Hold SHIFT or use mouse to select text .
2017-11-01 11:33:38 +00:00
- CTRL + Left / Right to word jump .
- CTRL + Shift + Left / Right to select words .
- CTRL + A our Double - Click to select all .
- CTRL + X , CTRL + C , CTRL + V to use OS clipboard /
- CTRL + Z , CTRL + Y to undo / redo .
- ESCAPE to revert text to its original value .
2014-08-10 20:58:11 +00:00
- You can apply arithmetic operators + , * , / on numerical values . Use + - to subtract ( because - would set a negative value ! )
2016-07-31 13:41:51 +00:00
- Controls are automatically adjusted for OSX to match standard OSX text editing operations .
2018-03-08 10:15:27 +00:00
- General Keyboard controls : enable with ImGuiConfigFlags_NavEnableKeyboard .
2018-04-07 21:07:23 +00:00
- General Gamepad controls : enable with ImGuiConfigFlags_NavEnableGamepad . See suggested mappings in imgui . h ImGuiNavInput_ + download PNG / PSD at http : //goo.gl/9LgVZW
2014-08-10 20:58:11 +00:00
2014-12-04 11:42:13 +00:00
2014-08-10 20:58:11 +00:00
PROGRAMMER GUIDE
2014-09-24 13:06:34 +00:00
= = = = = = = = = = = = = = = =
2014-08-10 20:58:11 +00:00
2019-11-19 14:22:42 +00:00
READ FIRST
- - - - - - - - - -
2019-10-16 09:03:41 +00:00
- Remember to read the FAQ ( https : //www.dearimgui.org/faq)
2018-04-03 18:22:44 +00:00
- Your code creates the UI , if your code doesn ' t run the UI is gone ! The UI can be highly dynamic , there are no construction
2018-10-25 17:02:24 +00:00
or destruction steps , less superfluous data retention on your side , less state duplication , less state synchronization , less bugs .
2017-12-24 17:16:22 +00:00
- Call and read ImGui : : ShowDemoWindow ( ) for demo code demonstrating most features .
2019-01-02 09:57:57 +00:00
- The library is designed to be built from sources . Avoid pre - compiled binaries and packaged versions . See imconfig . h to configure your build .
- Dear ImGui is an implementation of the IMGUI paradigm ( immediate - mode graphical user interface , a term coined by Casey Muratori ) .
You can learn about IMGUI principles at http : //www.johno.se/book/imgui.html, http://mollyrocket.com/861 & more links docs/README.md.
- Dear ImGui is a " single pass " rasterizing implementation of the IMGUI paradigm , aimed at ease of use and high - performances .
For every application frame your UI code will be called only once . This is in contrast to e . g . Unity ' s own implementation of an IMGUI ,
where the UI code is called multiple times ( " multiple passes " ) from a single entry point . There are pros and cons to both approaches .
- Our origin are on the top - left . In axis aligned bounding boxes , Min = top - left , Max = bottom - right .
- This codebase is also optimized to yield decent performances with typical " Debug " builds settings .
- Please make sure you have asserts enabled ( IM_ASSERT redirects to assert ( ) by default , but can be redirected ) .
If you get an assert , read the messages and comments around the assert .
- C + + : this is a very C - ish codebase : we don ' t rely on C + + 11 , we don ' t include any C + + headers , and ImGui : : is a namespace .
- C + + : ImVec2 / ImVec4 do not expose math operators by default , because it is expected that you use your own math types .
See FAQ " How can I use my own math types instead of ImVec2/ImVec4? " for details about setting up imconfig . h for that .
However , imgui_internal . h can optionally export math operators for ImVec2 / ImVec4 , which we use in this codebase .
- C + + : pay attention that ImVector < > manipulates plain - old - data and does not honor construction / destruction ( avoid using it in your code ! ) .
2019-11-19 14:22:42 +00:00
HOW TO UPDATE TO A NEWER VERSION OF DEAR IMGUI
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2017-08-11 06:29:27 +00:00
- Overwrite all the sources files except for imconfig . h ( if you have made modification to your copy of imconfig . h )
2018-10-25 17:02:24 +00:00
- Or maintain your own branch where you have imconfig . h modified .
2018-05-17 12:12:37 +00:00
- Read the " API BREAKING CHANGES " section ( below ) . This is where we list occasional API breaking changes .
If a function / type has been renamed / or marked obsolete , try to fix the name in your code before it is permanently removed
from the public API . If you have a problem with a missing function / symbols , search for its name in the code , there will
2018-04-03 18:22:44 +00:00
likely be a comment about it . Please report any issue to the GitHub page !
2017-08-11 06:29:27 +00:00
- Try to keep your copy of dear imgui reasonably up to date .
2016-07-31 13:41:51 +00:00
2019-11-19 14:22:42 +00:00
GETTING STARTED WITH INTEGRATING DEAR IMGUI IN YOUR CODE / ENGINE
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2018-10-25 17:02:24 +00:00
- Run and study the examples and demo in imgui_demo . cpp to get acquainted with the library .
2018-06-11 17:52:40 +00:00
- Add the Dear ImGui source files to your projects or using your preferred build system .
2018-10-25 17:02:24 +00:00
It is recommended you build and statically link the . cpp files as part of your project and not as shared library ( DLL ) .
2019-06-11 14:11:19 +00:00
- 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 .
2017-10-04 09:09:21 +00:00
- When using Dear ImGui , your programming IDE is your friend : follow the declaration of variables , functions and types to find comments about them .
2018-06-11 17:52:40 +00:00
- 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 "
2019-08-22 14:55:42 +00:00
phases of your own application . All rendering information are stored into command - lists that you will retrieve after calling ImGui : : Render ( ) .
2018-06-11 17:52:40 +00:00
- Refer to the bindings and demo applications in the examples / folder for instruction on how to setup your code .
2018-10-25 17:02:24 +00:00
- 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 .
2017-08-11 06:29:27 +00:00
2019-11-19 14:22:42 +00:00
HOW A SIMPLE APPLICATION MAY LOOK LIKE
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2019-01-02 09:57:57 +00:00
EXHIBIT 1 : USING THE EXAMPLE BINDINGS ( imgui_impl_XXX . cpp files from the examples / folder ) .
2016-07-31 13:41:51 +00:00
2018-07-04 17:06:28 +00:00
// Application init: create a dear imgui context, setup some options, load fonts
Reorganized context handling to be more explicit,
- YOU NOW NEED TO CALL ImGui::CreateContext() AT THE BEGINNING OF YOUR APP, AND CALL ImGui::DestroyContext() AT THE END.
- removed Shutdown() function, as DestroyContext() serve this purpose.
- you may pass a ImFontAtlas* pointer to CreateContext() to share a font atlas between contexts. Otherwhise CreateContext() will create its own font atlas instance.
- removed allocator parameters from CreateContext(), they are now setup with SetAllocatorFunctions(), and shared by all contexts.
- removed the default global context and font atlas instance, which were confusing for users of DLL reloading and users of multiple contexts
(#1565, #586, #992, #1007, #1558)
2018-01-21 18:58:32 +00:00
ImGui : : CreateContext ( ) ;
2016-07-31 13:41:51 +00:00
ImGuiIO & io = ImGui : : GetIO ( ) ;
2018-10-25 17:02:24 +00:00
// TODO: Set optional io.ConfigFlags values, e.g. 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard' to enable keyboard controls.
2018-09-05 15:14:37 +00:00
// TODO: Fill optional fields of the io structure later.
2018-07-04 17:06:28 +00:00
// TODO: Load TTF/OTF fonts if you don't want to use the default font.
// Initialize helper Platform and Renderer bindings (here we are using imgui_impl_win32 and imgui_impl_dx11)
ImGui_ImplWin32_Init ( hwnd ) ;
ImGui_ImplDX11_Init ( g_pd3dDevice , g_pd3dDeviceContext ) ;
// Application main loop
while ( true )
{
// Feed inputs to dear imgui, start new frame
ImGui_ImplDX11_NewFrame ( ) ;
ImGui_ImplWin32_NewFrame ( ) ;
ImGui : : NewFrame ( ) ;
// Any application code here
ImGui : : Text ( " Hello, world! " ) ;
// Render dear imgui into screen
ImGui : : Render ( ) ;
ImGui_ImplDX11_RenderDrawData ( ImGui : : GetDrawData ( ) ) ;
g_pSwapChain - > Present ( 1 , 0 ) ;
}
2019-01-20 16:56:17 +00:00
2018-07-04 17:06:28 +00:00
// Shutdown
ImGui_ImplDX11_Shutdown ( ) ;
ImGui_ImplWin32_Shutdown ( ) ;
ImGui : : DestroyContext ( ) ;
2019-11-19 14:22:42 +00:00
EXHIBIT 2 : IMPLEMENTING CUSTOM BINDING / CUSTOM ENGINE
2018-07-04 17:06:28 +00:00
// Application init: create a dear imgui context, setup some options, load fonts
ImGui : : CreateContext ( ) ;
ImGuiIO & io = ImGui : : GetIO ( ) ;
2018-10-25 17:02:24 +00:00
// TODO: Set optional io.ConfigFlags values, e.g. 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard' to enable keyboard controls.
2018-09-05 15:14:37 +00:00
// TODO: Fill optional fields of the io structure later.
2018-07-04 17:06:28 +00:00
// TODO: Load TTF/OTF fonts if you don't want to use the default font.
2016-07-31 13:41:51 +00:00
2018-06-11 17:52:40 +00:00
// Build and load the texture atlas into a texture
2018-07-04 17:06:28 +00:00
// (In the examples/ app this is usually done within the ImGui_ImplXXX_Init() function from one of the demo Renderer)
2016-07-31 13:41:51 +00:00
int width , height ;
2018-07-04 17:06:28 +00:00
unsigned char * pixels = NULL ;
2018-04-12 11:11:49 +00:00
io . Fonts - > GetTexDataAsRGBA32 ( & pixels , & width , & height ) ;
2018-07-04 17:06:28 +00:00
2018-06-11 17:52:40 +00:00
// At this point you've got the texture data and you need to upload that your your graphic system:
2018-07-04 17:06:28 +00:00
// After we have created the texture, store its pointer/identifier (_in whichever format your engine uses_) in 'io.Fonts->TexID'.
2019-10-16 09:03:41 +00:00
// This will be passed back to your via the renderer. Basically ImTextureID == void*. Read FAQ for details about ImTextureID.
2018-06-11 17:52:40 +00:00
MyTexture * texture = MyEngine : : CreateTextureFromMemoryPixels ( pixels , width , height , TEXTURE_TYPE_RGBA32 )
2017-08-11 06:29:27 +00:00
io . Fonts - > TexID = ( void * ) texture ;
2016-07-31 13:41:51 +00:00
// Application main loop
while ( true )
{
2018-07-04 17:06:28 +00:00
// Setup low-level inputs, e.g. on Win32: calling GetKeyboardState(), or write to those fields from your Windows message handlers, etc.
// (In the examples/ app this is usually done within the ImGui_ImplXXX_NewFrame() function from one of the demo Platform bindings)
io . DeltaTime = 1.0f / 60.0f ; // set the time elapsed since the previous frame (in seconds)
io . DisplaySize . x = 1920.0f ; // set the current display width
io . DisplaySize . y = 1280.0f ; // set the current display height here
io . MousePos = my_mouse_pos ; // set the mouse position
io . MouseDown [ 0 ] = my_mouse_buttons [ 0 ] ; // set the mouse button states
2018-06-11 17:52:40 +00:00
io . MouseDown [ 1 ] = my_mouse_buttons [ 1 ] ;
2017-08-11 06:29:27 +00:00
// Call NewFrame(), after this point you can use ImGui::* functions anytime
2019-06-11 14:11:19 +00:00
// (So you want to try calling NewFrame() as early as you can in your mainloop to be able to use Dear ImGui everywhere)
2017-08-11 06:29:27 +00:00
ImGui : : NewFrame ( ) ;
// Most of your application code here
2018-06-11 17:52:40 +00:00
ImGui : : Text ( " Hello, world! " ) ;
2019-06-11 14:11:19 +00:00
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!
2018-05-17 12:12:37 +00:00
2019-06-11 14:11:19 +00:00
// 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)
2018-06-11 17:52:40 +00:00
ImGui : : EndFrame ( ) ;
2017-08-11 06:29:27 +00:00
ImGui : : Render ( ) ;
2018-07-04 17:06:28 +00:00
ImDrawData * draw_data = ImGui : : GetDrawData ( ) ;
MyImGuiRenderFunction ( draw_data ) ;
2017-08-11 06:29:27 +00:00
SwapBuffers ( ) ;
2016-07-31 13:41:51 +00:00
}
Reorganized context handling to be more explicit,
- YOU NOW NEED TO CALL ImGui::CreateContext() AT THE BEGINNING OF YOUR APP, AND CALL ImGui::DestroyContext() AT THE END.
- removed Shutdown() function, as DestroyContext() serve this purpose.
- you may pass a ImFontAtlas* pointer to CreateContext() to share a font atlas between contexts. Otherwhise CreateContext() will create its own font atlas instance.
- removed allocator parameters from CreateContext(), they are now setup with SetAllocatorFunctions(), and shared by all contexts.
- removed the default global context and font atlas instance, which were confusing for users of DLL reloading and users of multiple contexts
(#1565, #586, #992, #1007, #1558)
2018-01-21 18:58:32 +00:00
// Shutdown
ImGui : : DestroyContext ( ) ;
2019-11-19 14:22:42 +00:00
HOW A SIMPLE RENDERING FUNCTION MAY LOOK LIKE
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2018-06-11 17:52:40 +00:00
void void MyImGuiRenderFunction ( ImDrawData * draw_data )
2017-08-11 06:29:27 +00:00
{
// TODO: Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled
2019-01-02 09:57:57 +00:00
// TODO: Setup viewport covering draw_data->DisplayPos to draw_data->DisplayPos + draw_data->DisplaySize
2018-06-11 17:52:40 +00:00
// TODO: Setup orthographic projection matrix cover draw_data->DisplayPos to draw_data->DisplayPos + draw_data->DisplaySize
2017-08-11 06:29:27 +00:00
// TODO: Setup shader: vertex { float2 pos, float2 uv, u32 color }, fragment shader sample color from 1 texture, multiply by vertex color.
for ( int n = 0 ; n < draw_data - > CmdListsCount ; n + + )
{
2019-01-20 16:56:17 +00:00
const ImDrawList * cmd_list = draw_data - > CmdLists [ n ] ;
2019-06-11 14:11:19 +00:00
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
2017-08-11 06:29:27 +00:00
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 ) ;
}
else
{
2018-05-17 12:12:37 +00:00
// The texture for the draw call is specified by pcmd->TextureId.
2019-06-11 14:11:19 +00:00
// The vast majority of draw calls will use the Dear ImGui texture atlas, which value you have set yourself during initialization.
2018-10-25 17:02:24 +00:00
MyEngineBindTexture ( ( MyTexture * ) pcmd - > TextureId ) ;
2017-10-19 17:30:46 +00:00
2018-06-11 17:52:40 +00:00
// We are using scissoring to clip some objects. All low-level graphics API should supports it.
// - If your engine doesn't support scissoring yet, you may ignore this at first. You will get some small glitches
2018-10-25 17:02:24 +00:00
// (some elements visible outside their bounds) but you can fix that once everything else works!
2018-06-11 17:52:40 +00:00
// - Clipping coordinates are provided in imgui coordinates space (from draw_data->DisplayPos to draw_data->DisplayPos + draw_data->DisplaySize)
// In a single viewport application, draw_data->DisplayPos will always be (0,0) and draw_data->DisplaySize will always be == io.DisplaySize.
2019-01-20 16:56:17 +00:00
// However, in the interest of supporting multi-viewport applications in the future (see 'viewport' branch on github),
2018-10-25 17:02:24 +00:00
// always subtract draw_data->DisplayPos from clipping bounds to convert them to your viewport space.
2018-06-11 17:52:40 +00:00
// - Note that pcmd->ClipRect contains Min+Max bounds. Some graphics API may use Min+Max, other may use Min+Size (size being Max-Min)
ImVec2 pos = draw_data - > DisplayPos ;
MyEngineScissor ( ( int ) ( pcmd - > ClipRect . x - pos . x ) , ( int ) ( pcmd - > ClipRect . y - pos . y ) , ( int ) ( pcmd - > ClipRect . z - pos . x ) , ( int ) ( pcmd - > ClipRect . w - pos . y ) ) ;
2017-10-19 17:30:46 +00:00
// Render 'pcmd->ElemCount/3' indexed triangles.
2019-11-20 10:58:25 +00:00
// By default the indices ImDrawIdx are 16-bit, you can change them to 32-bit in imconfig.h if your engine doesn't support 16-bit indices.
2017-08-11 06:29:27 +00:00
MyEngineDrawIndexedTriangles ( pcmd - > ElemCount , sizeof ( ImDrawIdx ) = = 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT , idx_buffer , vtx_buffer ) ;
}
idx_buffer + = pcmd - > ElemCount ;
}
}
}
2018-10-25 17:02:24 +00:00
- The examples / folders contains many actual implementation of the pseudo - codes above .
2018-05-17 12:12:37 +00:00
- When calling NewFrame ( ) , the ' io . WantCaptureMouse ' , ' io . WantCaptureKeyboard ' and ' io . WantTextInput ' flags are updated .
2019-06-11 14:11:19 +00:00
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
2019-10-17 09:36:26 +00:00
rest of your application . In every cases you need to pass on the inputs to Dear ImGui .
2019-10-16 09:03:41 +00:00
- Refer to the FAQ for more information . Amusingly , it is called a FAQ because people frequently run into the same issues !
2016-07-31 13:41:51 +00:00
2018-09-05 15:33:00 +00:00
USING GAMEPAD / KEYBOARD NAVIGATION CONTROLS
2019-11-19 14:22:42 +00:00
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2019-01-20 16:56:17 +00:00
- The gamepad / keyboard navigation is fairly functional and keeps being improved .
2019-12-10 12:37:29 +00:00
- Gamepad support is particularly useful to use Dear ImGui on a console system ( e . g . PS4 , Switch , XB1 ) without a mouse !
2018-09-05 15:33:00 +00:00
- You can ask questions and report issues at https : //github.com/ocornut/imgui/issues/787
2018-02-01 21:43:37 +00:00
- The initial focus was to support game controllers , but keyboard is becoming increasingly and decently usable .
2019-12-10 12:37:29 +00:00
- Keyboard :
- Set io . ConfigFlags | = ImGuiConfigFlags_NavEnableKeyboard to enable .
NewFrame ( ) will automatically fill io . NavInputs [ ] based on your io . KeysDown [ ] + io . KeyMap [ ] arrays .
- When keyboard navigation is active ( io . NavActive + ImGuiConfigFlags_NavEnableKeyboard ) , the io . WantCaptureKeyboard flag
will be set . For more advanced uses , you may want to read from :
- io . NavActive : true when a window is focused and it doesn ' t have the ImGuiWindowFlags_NoNavInputs flag set .
- io . NavVisible : true when the navigation cursor is visible ( and usually goes false when mouse is used ) .
- or query focus information with e . g . IsWindowFocused ( ImGuiFocusedFlags_AnyWindow ) , IsItemFocused ( ) etc . functions .
Please reach out if you think the game vs navigation input sharing could be improved .
2018-02-06 19:05:21 +00:00
- Gamepad :
2018-03-20 19:39:44 +00:00
- Set io . ConfigFlags | = ImGuiConfigFlags_NavEnableGamepad to enable .
2018-05-17 12:12:37 +00:00
- Backend : Set io . BackendFlags | = ImGuiBackendFlags_HasGamepad + fill the io . NavInputs [ ] fields before calling NewFrame ( ) .
2018-04-03 18:22:44 +00:00
Note that io . NavInputs [ ] is cleared by EndFrame ( ) .
2018-02-06 19:05:21 +00:00
- See ' enum ImGuiNavInput_ ' in imgui . h for a description of inputs . For each entry of io . NavInputs [ ] , set the following values :
0.0f = not held . 1.0f = fully held . Pass intermediate 0.0f . .1 .0f values for analog triggers / sticks .
- We uses a simple > 0.0f test for activation testing , and won ' t attempt to test for a dead - zone .
2018-03-08 10:15:27 +00:00
Your code will probably need to transform your raw inputs ( such as e . g . remapping your 0.2 . .0 .9 raw input range to 0.0 . .1 .0 imgui range , etc . ) .
2018-09-05 09:52:48 +00:00
- You can download PNG / PSD files depicting the gamepad controls for common controllers at : http : //goo.gl/9LgVZW.
2018-05-17 12:12:37 +00:00
- If you need to share inputs between your game and the imgui parts , the easiest approach is to go all - or - nothing , with a buttons combo
2018-04-07 21:07:23 +00:00
to toggle the target . Please reach out if you think the game vs navigation input sharing could be improved .
2018-02-06 19:05:21 +00:00
- Mouse :
- PS4 users : Consider emulating a mouse cursor with DualShock4 touch pad or a spare analog stick as a mouse - emulation fallback .
2018-03-08 10:15:27 +00:00
- Consoles / Tablet / Phone users : Consider using a Synergy 1. x server ( on your PC ) + uSynergy . c ( on your console / tablet / phone app ) to share your PC mouse / keyboard .
2018-03-20 19:12:34 +00:00
- On a TV / console system where readability may be lower or mouse inputs may be awkward , you may want to set the ImGuiConfigFlags_NavEnableSetMousePos flag .
2018-03-20 20:19:23 +00:00
Enabling ImGuiConfigFlags_NavEnableSetMousePos + ImGuiBackendFlags_HasSetMousePos instructs dear imgui to move your mouse cursor along with navigation movements .
2018-03-20 19:12:34 +00:00
When enabled , the NewFrame ( ) function may alter ' io . MousePos ' and set ' io . W antSetMousePos ' to notify you that it wants the mouse cursor to be moved .
2018-02-06 19:05:21 +00:00
When that happens your back - end NEEDS to move the OS or underlying mouse cursor on the next frame . Some of the binding in examples / do that .
2018-03-20 19:12:34 +00:00
( If you set the NavEnableSetMousePos flag but don ' t honor ' io . WantSetMousePos ' properly , imgui will misbehave as it will see your mouse as moving back and forth ! )
2018-02-06 19:05:21 +00:00
( In a setup when you may not have easy control over the mouse cursor , e . g . uSynergy . c doesn ' t expose moving remote mouse cursor , you may want
to set a boolean to ignore your other external mouse positions until the external source is moved again . )
2015-08-23 19:52:47 +00:00
2014-12-04 11:42:13 +00:00
2014-11-26 22:27:48 +00:00
API BREAKING CHANGES
= = = = = = = = = = = = = = = = = = = =
2018-05-11 14:54:50 +00:00
Occasionally introducing changes that are breaking the API . We try to make the breakage minor and easy to fix .
Below is a change - log of API breaking changes only . If you are using one of the functions listed , expect to have to fix some code .
2018-05-17 12:12:37 +00:00
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 .
2018-05-11 14:54:50 +00:00
You can read releases logs https : //github.com/ocornut/imgui/releases for more details.
2015-08-24 11:50:18 +00:00
2019-12-17 12:25:46 +00:00
- 2019 / 12 / 17 ( 1.75 ) - made Columns ( ) limited to 64 columns by asserting above that limit . While the current code technically supports it , future code may not so we ' re putting the restriction ahead .
2019-12-12 18:56:29 +00:00
- 2019 / 12 / 13 ( 1.75 ) - [ imgui_internal . h ] changed ImRect ( ) default constructor initializes all fields to 0.0f instead of ( FLT_MAX , FLT_MAX , - FLT_MAX , - FLT_MAX ) . If you used ImRect : : Add ( ) to create bounding boxes by adding multiple points into it , you may need to fix your initial value .
2019-12-08 15:26:47 +00:00
- 2019 / 12 / 08 ( 1.75 ) - removed redirecting functions / enums that were marked obsolete in 1.53 ( December 2017 ) :
- ShowTestWindow ( ) - > use ShowDemoWindow ( )
- IsRootWindowFocused ( ) - > use IsWindowFocused ( ImGuiFocusedFlags_RootWindow )
- IsRootWindowOrAnyChildFocused ( ) - > use IsWindowFocused ( ImGuiFocusedFlags_RootAndChildWindows )
- SetNextWindowContentWidth ( w ) - > use SetNextWindowContentSize ( ImVec2 ( w , 0.0f )
- GetItemsLineHeightWithSpacing ( ) - > use GetFrameHeightWithSpacing ( )
- ImGuiCol_ChildWindowBg - > use ImGuiCol_ChildBg
- ImGuiStyleVar_ChildWindowRounding - > use ImGuiStyleVar_ChildRounding
- ImGuiTreeNodeFlags_AllowOverlapMode - > use ImGuiTreeNodeFlags_AllowItemOverlap
- IMGUI_DISABLE_TEST_WINDOWS - > use IMGUI_DISABLE_DEMO_WINDOWS
2019-11-22 13:06:44 +00:00
- 2019 / 12 / 08 ( 1.75 ) - obsoleted calling ImDrawList : : PrimReserve ( ) with a negative count ( which was the vaguely documented and rarely if ever used ) . Instead we added an explicit PrimUnreserve ( ) API .
2019-12-05 17:30:27 +00:00
- 2019 / 12 / 06 ( 1.75 ) - removed implicit default parameter to IsMouseDragging ( int button = 0 ) to be consistent with other mouse functions ( none of the other functions have it ) .
2019-10-29 21:50:34 +00:00
- 2019 / 11 / 21 ( 1.74 ) - ImFontAtlas : : AddCustomRectRegular ( ) now requires an ID larger than 0x110000 ( instead of 0x10000 ) to conform with supporting Unicode planes 1 - 16 in a future update . ID below 0x110000 will now assert .
2019-11-19 20:20:46 +00:00
- 2019 / 11 / 19 ( 1.74 ) - renamed IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS to IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS for consistency .
2019-11-19 19:48:11 +00:00
- 2019 / 11 / 19 ( 1.74 ) - renamed IMGUI_DISABLE_MATH_FUNCTIONS to IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS for consistency .
2019-12-08 15:26:47 +00:00
- 2019 / 10 / 22 ( 1.74 ) - removed redirecting functions / enums that were marked obsolete in 1.52 ( October 2017 ) :
- Begin ( ) [ old 5 args version ] - > use Begin ( ) [ 3 args ] , use SetNextWindowSize ( ) SetNextWindowBgAlpha ( ) if needed
- IsRootWindowOrAnyChildHovered ( ) - > use IsWindowHovered ( ImGuiHoveredFlags_RootAndChildWindows )
- AlignFirstTextHeightToWidgets ( ) - > use AlignTextToFramePadding ( )
- SetNextWindowPosCenter ( ) - > use SetNextWindowPos ( ) with a pivot of ( 0.5f , 0.5f )
- ImFont : : Glyph - > use ImFontGlyph
2019-10-14 21:07:06 +00:00
- 2019 / 10 / 14 ( 1.74 ) - inputs : Fixed a miscalculation in the keyboard / mouse " typematic " repeat delay / rate calculation , used by keys and e . g . repeating mouse buttons as well as the GetKeyPressedAmount ( ) function .
if you were using a non - default value for io . KeyRepeatRate ( previous default was 0.250 ) , you can add + io . KeyRepeatDelay to it to compensate for the fix .
The function was triggering on : 0.0 and ( delay + rate * N ) where ( N > = 1 ) . Fixed formula responds to ( N > = 0 ) . Effectively it made io . KeyRepeatRate behave like it was set to ( io . KeyRepeatRate + io . KeyRepeatDelay ) .
If you never altered io . KeyRepeatRate nor used GetKeyPressedAmount ( ) this won ' t affect you .
2019-07-16 01:14:14 +00:00
- 2019 / 07 / 15 ( 1.72 ) - removed TreeAdvanceToLabelPos ( ) which is rarely used and only does SetCursorPosX ( GetCursorPosX ( ) + GetTreeNodeToLabelSpacing ( ) ) . Kept redirection function ( will obsolete ) .
2019-07-15 01:01:06 +00:00
- 2019 / 07 / 12 ( 1.72 ) - renamed ImFontAtlas : : CustomRect to ImFontAtlasCustomRect . Kept redirection typedef ( will obsolete ) .
2019-10-22 12:43:04 +00:00
- 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 , or see how they were implemented until 1.71 .
2019-05-10 15:24:22 +00:00
- 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 13:11:25 +00:00
- 2019 / 05 / 13 ( 1.71 ) - renamed SetNextTreeNodeOpen ( ) to SetNextItemOpen ( ) . Kept inline redirection function ( will obsolete ) .
2019-05-11 08:33:56 +00:00
- 2019 / 05 / 11 ( 1.71 ) - changed io . AddInputCharacter ( unsigned short c ) signature to io . AddInputCharacter ( unsigned int c ) .
2019-05-06 08:02:59 +00:00
- 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 16:31:51 +00:00
- 2019 / 04 / 29 ( 1.70 ) - removed GetContentRegionAvailWidth ( ) , use GetContentRegionAvail ( ) . x instead . Kept inline redirection function ( will obsolete ) .
2019-03-04 15:20:32 +00:00
- 2019 / 03 / 04 ( 1.69 ) - renamed GetOverlayDrawList ( ) to GetForegroundDrawList ( ) . Kept redirection function ( will obsolete ) .
2019-02-27 15:45:58 +00:00
- 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 16:14:29 +00:00
- 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 15:37:07 +00:00
- 2019 / 02 / 01 ( 1.68 ) - removed io . DisplayVisibleMin / DisplayVisibleMax ( which were marked obsolete and removed from viewport / docking branch already ) .
2019-01-06 15:50:23 +00:00
- 2019 / 01 / 06 ( 1.67 ) - renamed io . InputCharacters [ ] , marked internal as was always intended . Please don ' t access directly , and use AddInputCharacter ( ) instead !
2019-07-15 01:01:06 +00:00
- 2019 / 01 / 06 ( 1.67 ) - renamed ImFontAtlas : : GlyphRangesBuilder to ImFontGlyphRangesBuilder . Kept redirection typedef ( will obsolete ) .
2019-01-14 16:41:44 +00:00
- 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 14:36:07 +00:00
- 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 .
2018-09-26 19:30:37 +00:00
- 2018 / 09 / 28 ( 1.66 ) - renamed SetScrollHere ( ) to SetScrollHereY ( ) . Kept redirection function ( will obsolete ) .
2019-01-20 16:56:17 +00:00
- 2018 / 09 / 06 ( 1.65 ) - renamed stb_truetype . h to imstb_truetype . h , stb_textedit . h to imstb_textedit . h , and stb_rect_pack . h to imstb_rectpack . h .
2018-09-06 13:58:25 +00:00
If you were conveniently using the imgui copy of those STB headers in your project you will have to update your include paths .
2018-09-05 15:20:27 +00:00
- 2018 / 09 / 05 ( 1.65 ) - renamed io . OptCursorBlink / io . ConfigCursorBlink to io . ConfigInputTextCursorBlink . ( # 1427 )
2018-08-31 09:33:12 +00:00
- 2018 / 08 / 31 ( 1.64 ) - added imgui_widgets . cpp file , extracted and moved widgets code out of imgui . cpp into imgui_widgets . cpp . Re - ordered some of the code remaining in imgui . cpp .
NONE OF THE FUNCTIONS HAVE CHANGED . THE CODE IS SEMANTICALLY 100 % IDENTICAL , BUT _EVERY_ FUNCTION HAS BEEN MOVED .
Because of this , any local modifications to imgui . cpp will likely conflict when you update . Read docs / CHANGELOG . txt for suggestions .
2018-08-23 11:26:14 +00:00
- 2018 / 08 / 22 ( 1.63 ) - renamed IsItemDeactivatedAfterChange ( ) to IsItemDeactivatedAfterEdit ( ) for consistency with new IsItemEdited ( ) API . Kept redirection function ( will obsolete soonish as IsItemDeactivatedAfterChange ( ) is very recent ) .
2018-08-21 13:46:22 +00:00
- 2018 / 08 / 21 ( 1.63 ) - renamed ImGuiTextEditCallback to ImGuiInputTextCallback , ImGuiTextEditCallbackData to ImGuiInputTextCallbackData for consistency . Kept redirection types ( will obsolete ) .
- 2018 / 08 / 21 ( 1.63 ) - removed ImGuiInputTextCallbackData : : ReadOnly since it is a duplication of ( ImGuiInputTextCallbackData : : Flags & ImGuiInputTextFlags_ReadOnly ) .
2018-12-10 14:36:07 +00:00
- 2018 / 08 / 01 ( 1.63 ) - removed per - window ImGuiWindowFlags_ResizeFromAnySide beta flag in favor of a global io . ConfigResizeWindowsFromEdges [ update 1.67 renamed to ConfigWindowsResizeFromEdges ] to enable the feature .
2018-09-05 15:20:27 +00:00
- 2018 / 08 / 01 ( 1.63 ) - renamed io . OptCursorBlink to io . ConfigCursorBlink [ - > io . ConfigInputTextCursorBlink in 1.65 ] , io . OptMacOSXBehaviors to ConfigMacOSXBehaviors for consistency .
2018-07-10 09:14:38 +00:00
- 2018 / 07 / 22 ( 1.63 ) - changed ImGui : : GetTime ( ) return value from float to double to avoid accumulating floating point imprecisions over time .
2018-07-09 17:16:48 +00:00
- 2018 / 07 / 08 ( 1.63 ) - style : renamed ImGuiCol_ModalWindowDarkening to ImGuiCol_ModalWindowDimBg for consistency with other features . Kept redirection enum ( will obsolete ) .
2019-01-04 14:27:52 +00:00
- 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 . ) .
2019-04-24 15:04:20 +00:00
old bindings will still work as is , however prefer using the separated bindings as they will be updated to support multi - viewports .
2019-01-04 14:27:52 +00:00
when adopting new bindings follow the main . cpp code of your preferred examples / folder to know which functions to call .
2019-04-24 15:04:20 +00:00
in particular , note that old bindings called ImGui : : NewFrame ( ) at the end of their ImGui_ImplXXXX_NewFrame ( ) function .
2018-06-06 10:35:36 +00:00
- 2018 / 06 / 06 ( 1.62 ) - renamed GetGlyphRangesChinese ( ) to GetGlyphRangesChineseFull ( ) to distinguish other variants and discourage using the full set .
2019-01-20 16:56:17 +00:00
- 2018 / 06 / 06 ( 1.62 ) - TreeNodeEx ( ) / TreeNodeBehavior ( ) : the ImGuiTreeNodeFlags_CollapsingHeader helper now include the ImGuiTreeNodeFlags_NoTreePushOnOpen flag . See Changelog for details .
2018-06-06 10:35:36 +00:00
- 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 .
2018-05-03 19:28:59 +00:00
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 .
2018-05-17 12:12:37 +00:00
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 help you find them .
- 2018 / 04 / 28 ( 1.61 ) - obsoleted InputFloat ( ) functions taking an optional " int decimal_precision " in favor of an equivalent and more flexible " const char* format " ,
2018-05-14 09:58:11 +00:00
consistent with other functions . Kept redirection functions ( will obsolete ) .
2018-04-09 18:42:49 +00:00
- 2018 / 04 / 09 ( 1.61 ) - IM_DELETE ( ) helper function added in 1.60 doesn ' t clear the input _pointer_ reference , more consistent with expectation and allows passing r - value .
2018-05-14 09:58:11 +00:00
- 2018 / 03 / 20 ( 1.60 ) - renamed io . WantMoveMouse to io . WantSetMousePos for consistency and ease of understanding ( was added in 1.52 , _not_ used by core and only honored by some binding ahead of merging the Nav branch ) .
- 2018 / 03 / 12 ( 1.60 ) - removed ImGuiCol_CloseButton , ImGuiCol_CloseButtonActive , ImGuiCol_CloseButtonHovered as the closing cross uses regular button colors now .
- 2018 / 03 / 08 ( 1.60 ) - changed ImFont : : DisplayOffset . y to default to 0 instead of + 1. Fixed rounding of Ascent / Descent to match TrueType renderer . If you were adding or subtracting to ImFont : : DisplayOffset check if your fonts are correctly aligned vertically .
- 2018 / 03 / 03 ( 1.60 ) - renamed ImGuiStyleVar_Count_ to ImGuiStyleVar_COUNT and ImGuiMouseCursor_Count_ to ImGuiMouseCursor_COUNT for consistency with other public enums .
2018-05-17 12:12:37 +00:00
- 2018 / 02 / 18 ( 1.60 ) - BeginDragDropSource ( ) : temporarily removed the optional mouse_button = 0 parameter because it is not really usable in many situations at the moment .
2018-02-16 18:18:16 +00:00
- 2018 / 02 / 16 ( 1.60 ) - obsoleted the io . RenderDrawListsFn callback , you can call your graphics engine render function after ImGui : : Render ( ) . Use ImGui : : GetDrawData ( ) to retrieve the ImDrawData * to display .
2018-02-06 19:20:34 +00:00
- 2018 / 02 / 07 ( 1.60 ) - reorganized context handling to be more explicit ,
Reorganized context handling to be more explicit,
- YOU NOW NEED TO CALL ImGui::CreateContext() AT THE BEGINNING OF YOUR APP, AND CALL ImGui::DestroyContext() AT THE END.
- removed Shutdown() function, as DestroyContext() serve this purpose.
- you may pass a ImFontAtlas* pointer to CreateContext() to share a font atlas between contexts. Otherwhise CreateContext() will create its own font atlas instance.
- removed allocator parameters from CreateContext(), they are now setup with SetAllocatorFunctions(), and shared by all contexts.
- removed the default global context and font atlas instance, which were confusing for users of DLL reloading and users of multiple contexts
(#1565, #586, #992, #1007, #1558)
2018-01-21 18:58:32 +00:00
- YOU NOW NEED TO CALL ImGui : : CreateContext ( ) AT THE BEGINNING OF YOUR APP , AND CALL ImGui : : DestroyContext ( ) AT THE END .
- removed Shutdown ( ) function , as DestroyContext ( ) serve this purpose .
2018-04-25 07:34:26 +00:00
- you may pass a ImFontAtlas * pointer to CreateContext ( ) to share a font atlas between contexts . Otherwise CreateContext ( ) will create its own font atlas instance .
Reorganized context handling to be more explicit,
- YOU NOW NEED TO CALL ImGui::CreateContext() AT THE BEGINNING OF YOUR APP, AND CALL ImGui::DestroyContext() AT THE END.
- removed Shutdown() function, as DestroyContext() serve this purpose.
- you may pass a ImFontAtlas* pointer to CreateContext() to share a font atlas between contexts. Otherwhise CreateContext() will create its own font atlas instance.
- removed allocator parameters from CreateContext(), they are now setup with SetAllocatorFunctions(), and shared by all contexts.
- removed the default global context and font atlas instance, which were confusing for users of DLL reloading and users of multiple contexts
(#1565, #586, #992, #1007, #1558)
2018-01-21 18:58:32 +00:00
- removed allocator parameters from CreateContext ( ) , they are now setup with SetAllocatorFunctions ( ) , and shared by all contexts .
- removed the default global context and font atlas instance , which were confusing for users of DLL reloading and users of multiple contexts .
2018-02-20 11:08:37 +00:00
- 2018 / 01 / 31 ( 1.60 ) - moved sample TTF files from extra_fonts / to misc / fonts / . If you loaded files directly from the imgui repo you may need to update your paths .
2018-02-06 19:20:34 +00:00
- 2018 / 01 / 11 ( 1.60 ) - obsoleted IsAnyWindowHovered ( ) in favor of IsWindowHovered ( ImGuiHoveredFlags_AnyWindow ) . Kept redirection function ( will obsolete ) .
- 2018 / 01 / 11 ( 1.60 ) - obsoleted IsAnyWindowFocused ( ) in favor of IsWindowFocused ( ImGuiFocusedFlags_AnyWindow ) . Kept redirection function ( will obsolete ) .
- 2018 / 01 / 03 ( 1.60 ) - renamed ImGuiSizeConstraintCallback to ImGuiSizeCallback , ImGuiSizeConstraintCallbackData to ImGuiSizeCallbackData .
- 2017 / 12 / 29 ( 1.60 ) - removed CalcItemRectClosestPoint ( ) which was weird and not really used by anyone except demo code . If you need it it ' s easy to replicate on your side .
2017-12-24 17:16:22 +00:00
- 2017 / 12 / 24 ( 1.53 ) - renamed the emblematic ShowTestWindow ( ) function to ShowDemoWindow ( ) . Kept redirection function ( will obsolete ) .
2017-12-24 16:58:41 +00:00
- 2017 / 12 / 21 ( 1.53 ) - ImDrawList : renamed style . AntiAliasedShapes to style . AntiAliasedFill for consistency and as a way to explicitly break code that manipulate those flag at runtime . You can now manipulate ImDrawList : : Flags
- 2017 / 12 / 21 ( 1.53 ) - ImDrawList : removed ' bool anti_aliased = true ' final parameter of ImDrawList : : AddPolyline ( ) and ImDrawList : : AddConvexPolyFilled ( ) . Prefer manipulating ImDrawList : : Flags if you need to toggle them during the frame .
2017-12-14 17:42:41 +00:00
- 2017 / 12 / 14 ( 1.53 ) - using the ImGuiWindowFlags_NoScrollWithMouse flag on a child window forwards the mouse wheel event to the parent window , unless either ImGuiWindowFlags_NoInputs or ImGuiWindowFlags_NoScrollbar are also set .
2017-12-12 13:14:58 +00:00
- 2017 / 12 / 13 ( 1.53 ) - renamed GetItemsLineHeightWithSpacing ( ) to GetFrameHeightWithSpacing ( ) . Kept redirection function ( will obsolete ) .
2017-12-13 21:30:16 +00:00
- 2017 / 12 / 13 ( 1.53 ) - obsoleted IsRootWindowFocused ( ) in favor of using IsWindowFocused ( ImGuiFocusedFlags_RootWindow ) . Kept redirection function ( will obsolete ) .
- obsoleted IsRootWindowOrAnyChildFocused ( ) in favor of using IsWindowFocused ( ImGuiFocusedFlags_RootAndChildWindows ) . Kept redirection function ( will obsolete ) .
2017-12-11 21:41:33 +00:00
- 2017 / 12 / 12 ( 1.53 ) - renamed ImGuiTreeNodeFlags_AllowOverlapMode to ImGuiTreeNodeFlags_AllowItemOverlap . Kept redirection enum ( will obsolete ) .
2017-12-10 15:05:47 +00:00
- 2017 / 12 / 10 ( 1.53 ) - removed SetNextWindowContentWidth ( ) , prefer using SetNextWindowContentSize ( ) . Kept redirection function ( will obsolete ) .
2017-11-27 15:55:06 +00:00
- 2017 / 11 / 27 ( 1.53 ) - renamed ImGuiTextBuffer : : append ( ) helper to appendf ( ) , appendv ( ) to appendfv ( ) . If you copied the ' Log ' demo in your code , it uses appendv ( ) so that needs to be renamed .
2017-11-19 14:56:51 +00:00
- 2017 / 11 / 18 ( 1.53 ) - Style , Begin : removed ImGuiWindowFlags_ShowBorders window flag . Borders are now fully set up in the ImGuiStyle structure ( see e . g . style . FrameBorderSize , style . WindowBorderSize ) . Use ImGui : : ShowStyleEditor ( ) to look them up .
Please note that the style system will keep evolving ( hopefully stabilizing in Q1 2018 ) , and so custom styles will probably subtly break over time . It is recommended you use the StyleColorsClassic ( ) , StyleColorsDark ( ) , StyleColorsLight ( ) functions .
2017-11-18 22:16:40 +00:00
- 2017 / 11 / 18 ( 1.53 ) - Style : removed ImGuiCol_ComboBg in favor of combo boxes using ImGuiCol_PopupBg for consistency .
2017-11-19 12:52:40 +00:00
- 2017 / 11 / 18 ( 1.53 ) - Style : renamed ImGuiCol_ChildWindowBg to ImGuiCol_ChildBg .
2017-11-18 22:16:40 +00:00
- 2017 / 11 / 18 ( 1.53 ) - Style : renamed style . ChildWindowRounding to style . ChildRounding , ImGuiStyleVar_ChildWindowRounding to ImGuiStyleVar_ChildRounding .
2017-12-13 21:30:16 +00:00
- 2017 / 11 / 02 ( 1.53 ) - obsoleted IsRootWindowOrAnyChildHovered ( ) in favor of using IsWindowHovered ( ImGuiHoveredFlags_RootAndChildWindows ) ;
2017-10-24 18:23:42 +00:00
- 2017 / 10 / 24 ( 1.52 ) - renamed 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 .
2017-10-24 13:26:04 +00:00
- 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 .
2019-06-14 09:57:33 +00:00
IsItemHoveredRect ( ) - - > IsItemHovered ( ImGuiHoveredFlags_RectOnly )
IsMouseHoveringAnyWindow ( ) - - > IsWindowHovered ( ImGuiHoveredFlags_AnyWindow )
IsMouseHoveringWindow ( ) - - > IsWindowHovered ( ImGuiHoveredFlags_AllowWhenBlockedByPopup | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem ) [ weird , old behavior ]
2017-10-17 14:19:21 +00:00
- 2017 / 10 / 17 ( 1.52 ) - marked the old 5 - parameters version of Begin ( ) as obsolete ( still available ) . Use SetNextWindowSize ( ) + Begin ( ) instead !
2017-10-11 13:36:57 +00:00
- 2017 / 10 / 11 ( 1.52 ) - renamed AlignFirstTextHeightToWidgets ( ) to AlignTextToFramePadding ( ) . Kept inline redirection function ( will obsolete ) .
2019-07-15 01:01:06 +00:00
- 2017 / 09 / 26 ( 1.52 ) - renamed ImFont : : Glyph to ImFontGlyph . Kept redirection typedef ( will obsolete ) .
2018-05-17 12:12:37 +00:00
- 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 08:43:25 +00:00
- 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) " .
2018-05-17 12:12:37 +00:00
- 2017 / 08 / 22 ( 1.51 ) - renamed IsItemHoveredRect ( ) to IsItemRectHovered ( ) . Kept inline redirection function ( will obsolete ) . - > ( 1.52 ) use IsItemHovered ( ImGuiHoveredFlags_RectOnly ) !
2017-08-22 12:25:27 +00:00
- renamed IsMouseHoveringAnyWindow ( ) to IsAnyWindowHovered ( ) for consistency . Kept inline redirection function ( will obsolete ) .
- renamed IsMouseHoveringWindow ( ) to IsWindowRectHovered ( ) for consistency . Kept inline redirection function ( will obsolete ) .
2017-08-22 12:10:02 +00:00
- 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 .
2019-06-14 09:57:33 +00:00
- 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-20 09:53:09 +00:00
- 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 .
2019-06-14 09:57:33 +00:00
- 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 15:04:26 +00:00
- 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 .
2017-07-30 10:09:34 +00:00
- 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 .
2017-07-22 10:01:16 +00:00
- changed prototype of rarely used ' ColorButton ( ImVec4 col , bool small_height = false , bool outline_border = true ) ' to ' ColorButton ( const char * desc_id , ImVec4 col , ImGuiColorEditFlags flags = 0 , ImVec2 size = ImVec2 ( 0 , 0 ) ) '
- 2017 / 07 / 20 ( 1.51 ) - removed IsPosHoveringAnyWindow ( ImVec2 ) , which was partly broken and misleading . ASSERT + redirect user to io . WantCaptureMouse
- 2017 / 05 / 26 ( 1.50 ) - removed ImFontConfig : : MergeGlyphCenterV in favor of a more multipurpose ImFontConfig : : GlyphOffset .
- 2017 / 05 / 01 ( 1.50 ) - renamed ImDrawList : : PathFill ( ) ( rarely used directly ) to ImDrawList : : PathFillConvex ( ) for clarity .
2016-11-06 14:12:45 +00:00
- 2016 / 11 / 06 ( 1.50 ) - BeginChild ( const char * ) now applies the stack id to the provided label , consistently with other functions as it should always have been . It shouldn ' t affect you unless ( extremely unlikely ) you were appending multiple times to a same child from different locations of the stack id . If that ' s the case , generate an id with GetId ( ) and use it instead of passing string to BeginChild ( ) .
2016-10-15 09:36:43 +00:00
- 2016 / 10 / 15 ( 1.50 ) - avoid ' void * user_data ' parameter to io . SetClipboardTextFn / io . GetClipboardTextFn pointers . We pass io . ClipboardUserData to it .
2016-09-25 10:19:15 +00:00
- 2016 / 09 / 25 ( 1.50 ) - style . WindowTitleAlign is now a ImVec2 ( ImGuiAlign enum was removed ) . set to ( 0.5f , 0.5f ) for horizontal + vertical centering , ( 0.0f , 0.0f ) for upper - left , etc .
2016-07-30 21:41:44 +00:00
- 2016 / 07 / 30 ( 1.50 ) - SameLine ( x ) with x > 0.0f is now relative to left of column / group if any , and not always to left of window . This was sort of always the intent and hopefully breakage should be minimal .
2018-05-17 12:12:37 +00:00
- 2016 / 05 / 12 ( 1.49 ) - title bar ( using ImGuiCol_TitleBg / ImGuiCol_TitleBgActive colors ) isn ' t rendered over a window background ( ImGuiCol_WindowBg color ) anymore .
2019-11-19 14:22:42 +00:00
If your TitleBg / TitleBgActive alpha was 1.0f or you are using the default theme it will not affect you , otherwise if < 1.0f you need tweak your custom theme to readjust for the fact that we don ' t draw a WindowBg background behind the title bar .
This helper function will convert an old TitleBg / TitleBgActive color into a new one with the same visual output , given the OLD color and the OLD WindowBg color :
ImVec4 ConvertTitleBgCol ( const ImVec4 & win_bg_col , const ImVec4 & title_bg_col ) { float new_a = 1.0f - ( ( 1.0f - win_bg_col . w ) * ( 1.0f - title_bg_col . w ) ) , k = title_bg_col . w / new_a ; return ImVec4 ( ( win_bg_col . x * win_bg_col . w + title_bg_col . x ) * k , ( win_bg_col . y * win_bg_col . w + title_bg_col . y ) * k , ( win_bg_col . z * win_bg_col . w + title_bg_col . z ) * k , new_a ) ; }
2016-05-29 12:00:35 +00:00
If this is confusing , pick the RGB value from title bar from an old screenshot and apply this as TitleBg / TitleBgActive . Or you may just create TitleBgActive from a tweaked TitleBg color .
2016-05-07 17:54:27 +00:00
- 2016 / 05 / 07 ( 1.49 ) - removed confusing set of GetInternalState ( ) , GetInternalStateSize ( ) , SetInternalState ( ) functions . Now using CreateContext ( ) , DestroyContext ( ) , GetCurrentContext ( ) , SetCurrentContext ( ) .
2016-05-02 10:32:16 +00:00
- 2016 / 05 / 02 ( 1.49 ) - renamed SetNextTreeNodeOpened ( ) to SetNextTreeNodeOpen ( ) , no redirection .
2016-05-01 12:34:55 +00:00
- 2016 / 05 / 01 ( 1.49 ) - obsoleted old signature of CollapsingHeader ( const char * label , const char * str_id = NULL , bool display_frame = true , bool default_open = false ) as extra parameters were badly designed and rarely used . You can replace the " default_open = true " flag in new API with CollapsingHeader ( label , ImGuiTreeNodeFlags_DefaultOpen ) .
2018-07-09 19:06:46 +00:00
- 2016 / 04 / 26 ( 1.49 ) - changed ImDrawList : : PushClipRect ( ImVec4 rect ) to ImDrawList : : PushClipRect ( Imvec2 min , ImVec2 max , bool intersect_with_current_clip_rect = false ) . Note that higher - level ImGui : : PushClipRect ( ) is preferable because it will clip at logic / widget level , whereas ImDrawList : : PushClipRect ( ) only affect your renderer .
2016-04-03 23:37:02 +00:00
- 2016 / 04 / 03 ( 1.48 ) - removed style . WindowFillAlphaDefault setting which was redundant . Bake default BG alpha inside style . Colors [ ImGuiCol_WindowBg ] and all other Bg color values . ( ref github issue # 337 ) .
- 2016 / 04 / 03 ( 1.48 ) - renamed ImGuiCol_TooltipBg to ImGuiCol_PopupBg , used by popups / menus and tooltips . popups / menus were previously using ImGuiCol_WindowBg . ( ref github issue # 337 )
2016-03-21 21:29:11 +00:00
- 2016 / 03 / 21 ( 1.48 ) - renamed GetWindowFont ( ) to GetFont ( ) , GetWindowFontSize ( ) to GetFontSize ( ) . Kept inline redirection function ( will obsolete ) .
2016-03-02 22:34:29 +00:00
- 2016 / 03 / 02 ( 1.48 ) - InputText ( ) completion / history / always callbacks : if you modify the text buffer manually ( without using DeleteChars ( ) / InsertChars ( ) helper ) you need to maintain the BufTextLen field . added an assert .
2016-01-23 12:07:26 +00:00
- 2016 / 01 / 23 ( 1.48 ) - fixed not honoring exact width passed to PushItemWidth ( ) , previously it would add extra FramePadding . x * 2 over that width . if you had manual pixel - perfect alignment in place it might affect you .
2015-12-27 20:31:43 +00:00
- 2015 / 12 / 27 ( 1.48 ) - fixed ImDrawList : : AddRect ( ) which used to render a rectangle 1 px too large on each axis .
2015-12-04 23:39:54 +00:00
- 2015 / 12 / 04 ( 1.47 ) - renamed Color ( ) helpers to ValueColor ( ) - dangerously named , rarely used and probably to be made obsolete .
2015-09-09 13:15:17 +00:00
- 2015 / 08 / 29 ( 1.45 ) - with the addition of horizontal scrollbar we made various fixes to inconsistencies with dealing with cursor position .
2015-08-30 15:37:56 +00:00
GetCursorPos ( ) / SetCursorPos ( ) functions now include the scrolled amount . It shouldn ' t affect the majority of users , but take note that SetCursorPosX ( 100.0f ) puts you at + 100 from the starting x position which may include scrolling , not at + 100 from the window left side .
GetContentRegionMax ( ) / GetWindowContentRegionMin ( ) / GetWindowContentRegionMax ( ) functions allow include the scrolled amount . Typically those were used in cases where no scrolling would happen so it may not be a problem , but watch out !
2015-08-29 22:47:47 +00:00
- 2015 / 08 / 29 ( 1.45 ) - renamed style . ScrollbarWidth to style . ScrollbarSize
2015-08-05 15:34:07 +00:00
- 2015 / 08 / 05 ( 1.44 ) - split imgui . cpp into extra files : imgui_demo . cpp imgui_draw . cpp imgui_internal . h that you need to add to your project .
2015-07-19 00:45:37 +00:00
- 2015 / 07 / 18 ( 1.44 ) - fixed angles in ImDrawList : : PathArcTo ( ) , PathArcToFast ( ) ( introduced in 1.43 ) being off by an extra PI for no justifiable reason
2015-07-15 13:01:21 +00:00
- 2015 / 07 / 14 ( 1.43 ) - add new ImFontAtlas : : AddFont ( ) API . For the old AddFont * * * , moved the ' font_no ' parameter of ImFontAtlas : : AddFont * * functions to the ImFontConfig structure .
2015-07-19 00:45:37 +00:00
you need to render your textured triangles with bilinear filtering to benefit from sub - pixel positioning of text .
2015-07-08 23:10:14 +00:00
- 2015 / 07 / 08 ( 1.43 ) - switched rendering data to use indexed rendering . this is saving a fair amount of CPU / GPU and enables us to get anti - aliasing for a marginal cost .
2015-07-08 00:31:41 +00:00
this necessary change will break your rendering function ! the fix should be very easy . sorry for that : (
2015-07-06 04:26:01 +00:00
- 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 .
2015-08-24 11:50:18 +00:00
- the signature of the io . RenderDrawListsFn handler has changed !
2018-02-25 18:05:31 +00:00
old : ImGui_XXXX_RenderDrawLists ( ImDrawList * * const cmd_lists , int cmd_lists_count )
new : ImGui_XXXX_RenderDrawLists ( ImDrawData * draw_data ) .
2019-01-02 09:57:57 +00:00
parameters : ' cmd_lists ' becomes ' draw_data - > CmdLists ' , ' cmd_lists_count ' becomes ' draw_data - > CmdListsCount '
2018-02-25 18:05:31 +00:00
ImDrawList : ' commands ' becomes ' CmdBuffer ' , ' vtx_buffer ' becomes ' VtxBuffer ' , ' IdxBuffer ' is new .
ImDrawCmd : ' vtx_count ' becomes ' ElemCount ' , ' clip_rect ' becomes ' ClipRect ' , ' user_callback ' becomes ' UserCallback ' , ' texture_id ' becomes ' TextureId ' .
2015-07-08 02:17:07 +00:00
- 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 .
2015-07-15 14:45:10 +00:00
- 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 !
2015-07-08 02:17:07 +00:00
- refer to code in the examples / folder or ask on the GitHub if you are unsure of how to upgrade . please upgrade !
2015-07-11 01:36:34 +00:00
- 2015 / 07 / 10 ( 1.43 ) - changed SameLine ( ) parameters from int to float .
2015-07-03 02:53:45 +00:00
- 2015 / 07 / 02 ( 1.42 ) - renamed SetScrollPosHere ( ) to SetScrollFromCursorPos ( ) . Kept inline redirection function ( will obsolete ) .
- 2015 / 07 / 02 ( 1.42 ) - renamed GetScrollPosY ( ) to GetScrollY ( ) . Necessary to reduce confusion along with other scrolling functions , because positions ( e . g . cursor position ) are not equivalent to scrolling amount .
2015-06-14 22:18:22 +00:00
- 2015 / 06 / 14 ( 1.41 ) - changed ImageButton ( ) default bg_col parameter from ( 0 , 0 , 0 , 1 ) ( black ) to ( 0 , 0 , 0 , 0 ) ( transparent ) - makes a difference when texture have transparence
- 2015 / 06 / 14 ( 1.41 ) - changed Selectable ( ) API from ( label , selected , size ) to ( label , selected , flags , size ) . Size override should have been rarely be used . Sorry !
2015-06-14 21:19:47 +00:00
- 2015 / 05 / 31 ( 1.40 ) - renamed GetWindowCollapsed ( ) to IsWindowCollapsed ( ) for consistency . Kept inline redirection function ( will obsolete ) .
- 2015 / 05 / 31 ( 1.40 ) - renamed IsRectClipped ( ) to IsRectVisible ( ) for consistency . Note that return value is opposite ! Kept inline redirection function ( will obsolete ) .
- 2015 / 05 / 27 ( 1.40 ) - removed the third ' repeat_if_held ' parameter from Button ( ) - sorry ! it was rarely used and inconsistent . Use PushButtonRepeat ( true ) / PopButtonRepeat ( ) to enable repeat on desired buttons .
2016-05-02 10:32:16 +00:00
- 2015 / 05 / 11 ( 1.40 ) - changed BeginPopup ( ) API , takes a string identifier instead of a bool . ImGui needs to manage the open / closed state of popups . Call OpenPopup ( ) to actually set the " open " state of a popup . BeginPopup ( ) returns true if the popup is opened .
2015-06-14 21:19:47 +00:00
- 2015 / 05 / 03 ( 1.40 ) - removed style . AutoFitPadding , using style . WindowPadding makes more sense ( the default values were already the same ) .
2016-08-06 07:48:04 +00:00
- 2015 / 04 / 13 ( 1.38 ) - renamed IsClipped ( ) to IsRectClipped ( ) . Kept inline redirection function until 1.50 .
2015-04-09 15:45:14 +00:00
- 2015 / 04 / 09 ( 1.38 ) - renamed ImDrawList : : AddArc ( ) to ImDrawList : : AddArcFast ( ) for compatibility with future API
2015-04-03 13:07:52 +00:00
- 2015 / 04 / 03 ( 1.38 ) - removed ImGuiCol_CheckHovered , ImGuiCol_CheckActive , replaced with the more general ImGuiCol_FrameBgHovered , ImGuiCol_FrameBgActive .
2015-04-03 14:10:07 +00:00
- 2014 / 04 / 03 ( 1.38 ) - removed support for passing - FLT_MAX . . + FLT_MAX as the range for a SliderFloat ( ) . Use DragFloat ( ) or Inputfloat ( ) instead .
2016-08-06 07:48:04 +00:00
- 2015 / 03 / 17 ( 1.36 ) - renamed GetItemBoxMin ( ) / GetItemBoxMax ( ) / IsMouseHoveringBox ( ) to GetItemRectMin ( ) / GetItemRectMax ( ) / IsMouseHoveringRect ( ) . Kept inline redirection function until 1.50 .
2015-03-15 11:10:48 +00:00
- 2015 / 03 / 15 ( 1.36 ) - renamed style . TreeNodeSpacing to style . IndentSpacing , ImGuiStyleVar_TreeNodeSpacing to ImGuiStyleVar_IndentSpacing
2016-08-06 07:48:04 +00:00
- 2015 / 03 / 13 ( 1.36 ) - renamed GetWindowIsFocused ( ) to IsWindowFocused ( ) . Kept inline redirection function until 1.50 .
2015-09-30 19:47:44 +00:00
- 2015 / 03 / 08 ( 1.35 ) - renamed style . ScrollBarWidth to style . ScrollbarWidth ( casing )
2016-08-06 07:48:04 +00:00
- 2015 / 02 / 27 ( 1.34 ) - renamed OpenNextNode ( bool ) to SetNextTreeNodeOpened ( bool , ImGuiSetCond ) . Kept inline redirection function until 1.50 .
2015-02-27 09:51:11 +00:00
- 2015 / 02 / 27 ( 1.34 ) - renamed ImGuiSetCondition_ * * * to ImGuiSetCond_ * * * , and _FirstUseThisSession becomes _Once .
2015-02-11 17:39:13 +00:00
- 2015 / 02 / 11 ( 1.32 ) - changed text input callback ImGuiTextEditCallback return type from void - - > int . reserved for future use , return 0 for now .
2015-02-10 21:07:26 +00:00
- 2015 / 02 / 10 ( 1.32 ) - renamed GetItemWidth ( ) to CalcItemWidth ( ) to clarify its evolving behavior
2015-02-08 13:37:20 +00:00
- 2015 / 02 / 08 ( 1.31 ) - renamed GetTextLineSpacing ( ) to GetTextLineHeightWithSpacing ( )
2015-02-01 14:39:13 +00:00
- 2015 / 02 / 01 ( 1.31 ) - removed IO . MemReallocFn ( unused )
2015-01-29 09:22:32 +00:00
- 2015 / 01 / 19 ( 1.30 ) - renamed ImGuiStorage : : GetIntPtr ( ) / GetFloatPtr ( ) to GetIntRef ( ) / GetIntRef ( ) because Ptr was conflicting with actual pointer storage functions .
2015-01-17 22:38:10 +00:00
- 2015 / 01 / 11 ( 1.30 ) - big font / image API change ! now loads TTF file . allow for multiple fonts . no need for a PNG loader .
2019-12-08 15:26:47 +00:00
- 2015 / 01 / 11 ( 1.30 ) - removed GetDefaultFontData ( ) . uses io . Fonts - > GetTextureData * ( ) API to retrieve uncompressed pixels .
- old : const void * png_data ; unsigned int png_size ; ImGui : : GetDefaultFontData ( NULL , NULL , & png_data , & png_size ) ; [ . . Upload texture to GPU . . ] ;
- new : unsigned char * pixels ; int width , height ; io . Fonts - > GetTexDataAsRGBA32 ( & pixels , & width , & height ) ; [ . . Upload texture to GPU . . ] ; io . Fonts - > TexId = YourTexIdentifier ;
you now have more flexibility to load multiple TTF fonts and manage the texture buffer for internal needs . It is now recommended that you sample the font texture with bilinear interpolation .
- 2015 / 01 / 11 ( 1.30 ) - added texture identifier in ImDrawCmd passed to your render function ( we can now render images ) . make sure to set io . Fonts - > TexID .
- 2015 / 01 / 11 ( 1.30 ) - removed IO . PixelCenterOffset ( unnecessary , can be handled in user projection matrix )
- 2015 / 01 / 11 ( 1.30 ) - removed ImGui : : IsItemFocused ( ) in favor of ImGui : : IsItemActive ( ) which handles all widgets
2015-01-17 22:38:10 +00:00
- 2014 / 12 / 10 ( 1.18 ) - removed SetNewWindowDefaultPos ( ) in favor of new generic API SetNextWindowPos ( pos , ImGuiSetCondition_FirstUseEver )
2015-01-20 21:37:18 +00:00
- 2014 / 11 / 28 ( 1.17 ) - moved IO . Font * * * options to inside the IO . Font - > structure ( FontYOffset , FontTexUvForWhite , FontBaseScale , FontFallbackGlyph )
2015-01-17 22:38:10 +00:00
- 2014 / 11 / 26 ( 1.17 ) - reworked syntax of IMGUI_ONCE_UPON_A_FRAME helper macro to increase compiler compatibility
- 2014 / 11 / 07 ( 1.15 ) - renamed IsHovered ( ) to IsItemHovered ( )
- 2014 / 10 / 02 ( 1.14 ) - renamed IMGUI_INCLUDE_IMGUI_USER_CPP to IMGUI_INCLUDE_IMGUI_USER_INL and imgui_user . cpp to imgui_user . inl ( more IDE friendly )
- 2014 / 09 / 25 ( 1.13 ) - removed ' text_end ' parameter from IO . SetClipboardTextFn ( the string is now always zero - terminated for simplicity )
- 2014 / 09 / 24 ( 1.12 ) - renamed SetFontScale ( ) to SetWindowFontScale ( )
- 2014 / 09 / 24 ( 1.12 ) - moved IM_MALLOC / IM_REALLOC / IM_FREE preprocessor defines to IO . MemAllocFn / IO . MemReallocFn / IO . MemFreeFn
- 2014 / 08 / 30 ( 1.09 ) - removed IO . FontHeight ( now computed automatically )
- 2014 / 08 / 30 ( 1.09 ) - moved IMGUI_FONT_TEX_UV_FOR_WHITE preprocessor define to IO . FontTexUvForWhite
- 2014 / 08 / 28 ( 1.09 ) - changed the behavior of IO . PixelCenterOffset following various rendering fixes
2014-11-26 22:27:48 +00:00
2014-12-04 11:42:13 +00:00
2019-10-16 09:03:41 +00:00
FREQUENTLY ASKED QUESTIONS ( FAQ )
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
2014-08-31 07:23:55 +00:00
2019-10-16 09:03:41 +00:00
Read all answers online : https : //www.dearimgui.org/faq, or in docs/FAQ.md (with a Markdown viewer)
Some answers are copied down here to facilitate searching in code .
2019-10-15 11:00:04 +00:00
Q & A : Basics
= = = = = = = = = = =
2019-04-07 14:22:41 +00:00
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 .
2019-09-17 09:33:18 +00:00
- 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 .
2019-04-07 14:22:41 +00:00
- See documentation and comments at the top of imgui . cpp + effectively imgui . h .
2019-12-10 12:37:29 +00:00
- 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 .
- The Wiki ( https : //github.com/ocornut/imgui/wiki) has many resources and links.
- The Glossary ( https : //github.com/ocornut/imgui/wiki/Glossary) page also may be useful.
2019-09-17 09:33:18 +00:00
- Your programming IDE is your friend , find the type or function declaration to find comments
2019-04-07 14:22:41 +00:00
associated to it .
Q : Which version should I get ?
2019-10-15 11:00:04 +00:00
Q : Why the names " Dear ImGui " vs " ImGui " ?
2019-12-10 12:37:29 +00:00
> > This library is called " Dear ImGui " , please don ' t call it " ImGui " : )
2019-10-16 09:03:41 +00:00
> > See https : //www.dearimgui.org/faq
2019-10-15 11:00:04 +00:00
Q & A : Concerns
= = = = = = = = = = = = =
2019-04-07 14:22:41 +00:00
Q : Who uses Dear ImGui ?
2019-10-15 11:00:04 +00:00
Q : Can you create elaborate / serious tools with Dear ImGui ?
Q : Can you reskin the look of Dear ImGui ?
Q : Why using C + + ( as opposed to C ) ?
2019-10-16 09:03:41 +00:00
> > See https : //www.dearimgui.org/faq
2019-10-15 11:00:04 +00:00
Q & A : Integration
= = = = = = = = = = = = = = = =
2019-04-07 14:22:41 +00:00
2019-06-11 14:11:19 +00:00
Q : How can I tell whether to dispatch mouse / keyboard to Dear ImGui or to my application ?
2018-05-30 14:31:34 +00:00
A : You can read the ' io . WantCaptureMouse ' , ' io . WantCaptureKeyboard ' and ' io . WantTextInput ' flags from the ImGuiIO structure ( e . g . if ( ImGui : : GetIO ( ) . WantCaptureMouse ) { . . . } )
2018-03-05 10:30:23 +00:00
- 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 .
- When ' io . WantTextInput ' is set to may want to notify your OS to popup an on - screen keyboard , if available ( e . g . on a mobile phone , or console OS ) .
2018-04-06 17:28:00 +00:00
Note : you should always pass your mouse / keyboard inputs to imgui , even when the io . WantCaptureXXX flag are set false .
2018-10-25 17:02:24 +00:00
This is because imgui needs to detect that you clicked in the void to unfocus its own windows .
2018-04-06 17:28:00 +00:00
Note : The ' io . WantCaptureMouse ' is more accurate that any attempt to " check if the mouse is hovering a window " ( don ' t do that ! ) .
It handle mouse dragging correctly ( both dragging that started over your application or over an imgui window ) and handle e . g . modal windows blocking inputs .
2018-05-17 12:12:37 +00:00
Those flags are updated by ImGui : : NewFrame ( ) . Preferably read the flags after calling NewFrame ( ) if you can afford it , but reading them before is also
2018-06-23 18:08:19 +00:00
perfectly fine , as the bool toggle fairly rarely . If you have on a touch device , you might find use for an early call to UpdateHoveredWindowAndCaptureFlags ( ) .
2018-05-17 12:12:37 +00:00
Note : Text input widget releases focus on " Return KeyDown " , so the subsequent " Return KeyUp " event that your application receive will typically
2018-03-05 10:30:23 +00:00
have ' io . WantCaptureKeyboard = false ' . Depending on your application logic it may or not be inconvenient . You might want to track which key - downs
2018-04-25 14:38:13 +00:00
were targeted for Dear ImGui , e . g . with an array of bool , and filter out the corresponding key - ups . )
2019-10-17 09:36:26 +00:00
2019-12-10 12:37:29 +00:00
Q . How can I enable keyboard controls ?
2019-10-15 11:00:04 +00:00
Q : How can I use this without a mouse , without a keyboard or without a screen ? ( gamepad , input share , remote display )
Q : I integrated Dear ImGui in my engine and the text or lines are blurry . .
Q : I integrated Dear ImGui in my engine and some elements are clipping or disappearing when I move windows around . .
2019-10-16 09:03:41 +00:00
> > See https : //www.dearimgui.org/faq
2018-01-22 10:59:40 +00:00
2019-10-15 11:00:04 +00:00
Q & A : Usage
- - - - - - - - - -
2016-03-24 10:00:47 +00:00
2019-04-07 14:22:41 +00:00
Q : Why are multiple widgets reacting when I interact with a single one ?
2019-01-02 09:57:57 +00:00
Q : How can I have multiple widgets with the same label or with an empty label ?
2018-04-03 18:05:59 +00:00
A : A primer on labels and the ID Stack . . .
2015-08-24 11:50:18 +00:00
2018-05-27 20:32:46 +00:00
Dear ImGui internally need to uniquely identify UI elements .
Elements that are typically not clickable ( such as calls to the Text functions ) don ' t need an ID .
2019-01-20 16:56:17 +00:00
Interactive widgets ( such as calls to Button buttons ) need a unique ID .
2018-05-27 20:32:46 +00:00
Unique ID are used internally to track active widgets and occasionally associate state to widgets .
Unique ID are implicitly built from the hash of multiple elements that identify the " path " to the UI element .
2015-05-19 22:33:55 +00:00
2018-05-27 20:32:46 +00:00
- Unique ID are often derived from a string label :
2015-08-24 11:50:18 +00:00
2018-05-27 20:32:46 +00:00
Button ( " OK " ) ; // Label = "OK", ID = hash of (..., "OK")
Button ( " Cancel " ) ; // Label = "Cancel", ID = hash of (..., "Cancel")
2015-03-07 21:54:46 +00:00
2018-04-03 18:22:44 +00:00
- ID are uniquely scoped within windows , tree nodes , etc . which all pushes to the ID stack . Having
two buttons labeled " OK " in different windows or different tree locations is fine .
2018-05-27 20:32:46 +00:00
We used " ... " above to signify whatever was already pushed to the ID stack previously :
Begin ( " MyWindow " ) ;
Button ( " OK " ) ; // Label = "OK", ID = hash of ("MyWindow", "OK")
End ( ) ;
2019-01-02 09:57:57 +00:00
Begin ( " MyOtherWindow " ) ;
Button ( " OK " ) ; // Label = "OK", ID = hash of ("MyOtherWindow", "OK")
End ( ) ;
2015-03-21 23:14:21 +00:00
2015-09-09 13:15:17 +00:00
- If you have a same ID twice in the same location , you ' ll have a conflict :
2015-03-18 19:00:03 +00:00
2015-03-21 23:14:21 +00:00
Button ( " OK " ) ;
2018-04-03 18:05:59 +00:00
Button ( " OK " ) ; // ID collision! Interacting with either button will trigger the first one.
2015-03-18 19:00:03 +00:00
2015-03-21 23:14:21 +00:00
Fear not ! this is easy to solve and there are many ways to solve it !
2015-03-07 21:54:46 +00:00
2018-04-03 18:05:59 +00:00
- Solving ID conflict in a simple / local context :
2018-04-03 18:22:44 +00:00
When passing a label you can optionally specify extra ID information within string itself .
2018-01-22 10:59:40 +00:00
Use " ## " to pass a complement to the ID that won ' t be visible to the end - user .
2018-04-03 18:22:44 +00:00
This helps solving the simple collision cases when you know e . g . at compilation time which items
are going to be created :
2015-03-07 21:54:46 +00:00
2018-05-27 20:32:46 +00:00
Begin ( " MyWindow " ) ;
Button ( " Play " ) ; // Label = "Play", ID = hash of ("MyWindow", "Play")
Button ( " Play##foo1 " ) ; // Label = "Play", ID = hash of ("MyWindow", "Play##foo1") // Different from above
Button ( " Play##foo2 " ) ; // Label = "Play", ID = hash of ("MyWindow", "Play##foo2") // Different from above
End ( ) ;
2015-05-19 22:33:55 +00:00
2015-09-09 13:15:17 +00:00
- If you want to completely hide the label , but still need an ID :
2015-05-19 22:33:55 +00:00
2018-10-25 17:02:24 +00:00
Checkbox ( " ##On " , & b ) ; // Label = "", ID = hash of (..., "##On") // No visible label, just a checkbox!
2015-03-07 21:54:46 +00:00
2018-04-03 18:22:44 +00:00
- Occasionally / rarely you might want change a label while preserving a constant ID . This allows
2018-05-17 12:12:37 +00:00
you to animate labels . For example you may want to include varying information in a window title bar ,
2018-04-03 18:22:44 +00:00
but windows are uniquely identified by their ID . Use " ### " to pass a label that isn ' t part of ID :
2015-03-07 21:54:46 +00:00
2019-01-21 15:05:41 +00:00
Button ( " Hello###ID " ) ; // Label = "Hello", ID = hash of (..., "###ID")
Button ( " World###ID " ) ; // Label = "World", ID = hash of (..., "###ID") // Same as above, even though the label looks different
2016-03-26 14:38:52 +00:00
2018-01-22 10:59:40 +00:00
sprintf ( buf , " My game (%f FPS)###MyGame " , fps ) ;
2018-10-25 17:02:24 +00:00
Begin ( buf ) ; // Variable title, ID = hash of "MyGame"
2015-03-07 21:54:46 +00:00
2018-04-03 18:05:59 +00:00
- Solving ID conflict in a more general manner :
2018-05-17 12:12:37 +00:00
Use PushID ( ) / PopID ( ) to create scopes and manipulate the ID stack , as to avoid ID conflicts
2018-04-03 18:22:44 +00:00
within the same window . This is the most convenient way of distinguishing ID when iterating and
2018-05-17 12:12:37 +00:00
creating many UI elements programmatically .
You can push a pointer , a string or an integer value into the ID stack .
2019-01-02 09:57:57 +00:00
Remember that ID are formed from the concatenation of _everything_ pushed into the ID stack .
At each level of the stack we store the seed used for items at this level of the ID stack .
2015-03-21 23:14:21 +00:00
2019-01-02 09:57:57 +00:00
Begin ( " Window " ) ;
2015-03-21 23:14:21 +00:00
for ( int i = 0 ; i < 100 ; i + + )
{
2019-01-02 09:57:57 +00:00
PushID ( i ) ; // Push i to the id tack
Button ( " Click " ) ; // Label = "Click", ID = hash of ("Window", i, "Click")
2015-03-21 23:14:21 +00:00
PopID ( ) ;
}
for ( int i = 0 ; i < 100 ; i + + )
{
MyObject * obj = Objects [ i ] ;
PushID ( obj ) ;
2019-01-02 09:57:57 +00:00
Button ( " Click " ) ; // Label = "Click", ID = hash of ("Window", obj pointer, "Click")
2015-03-21 23:14:21 +00:00
PopID ( ) ;
}
for ( int i = 0 ; i < 100 ; i + + )
{
MyObject * obj = Objects [ i ] ;
PushID ( obj - > Name ) ;
2019-01-02 09:57:57 +00:00
Button ( " Click " ) ; // Label = "Click", ID = hash of ("Window", obj->Name, "Click")
2015-03-21 23:14:21 +00:00
PopID ( ) ;
}
2018-05-27 20:32:46 +00:00
End ( ) ;
2015-03-21 23:14:21 +00:00
2019-01-02 09:57:57 +00:00
- You can stack multiple prefixes into the ID stack :
2015-03-07 21:54:46 +00:00
2019-01-02 09:57:57 +00:00
Button ( " Click " ) ; // Label = "Click", ID = hash of (..., "Click")
2015-03-07 21:54:46 +00:00
PushID ( " node " ) ;
2019-01-02 09:57:57 +00:00
Button ( " Click " ) ; // Label = "Click", ID = hash of (..., "node", "Click")
2015-03-21 23:14:21 +00:00
PushID ( my_ptr ) ;
2019-01-02 09:57:57 +00:00
Button ( " Click " ) ; // Label = "Click", ID = hash of (..., "node", my_ptr, "Click")
2015-03-21 23:14:21 +00:00
PopID ( ) ;
PopID ( ) ;
2015-09-09 13:15:17 +00:00
- Tree nodes implicitly creates a scope for you by calling PushID ( ) .
2015-03-21 23:14:21 +00:00
2019-01-02 09:57:57 +00:00
Button ( " Click " ) ; // Label = "Click", ID = hash of (..., "Click")
if ( TreeNode ( " node " ) ) // <-- this function call will do a PushID() for you (unless instructed not to, with a special flag)
2015-03-07 21:54:46 +00:00
{
2019-01-02 09:57:57 +00:00
Button ( " Click " ) ; // Label = "Click", ID = hash of (..., "node", "Click")
2015-03-21 23:14:21 +00:00
TreePop ( ) ;
2015-03-07 21:54:46 +00:00
}
2016-05-02 10:32:16 +00:00
- When working with trees , ID are used to preserve the open / close state of each tree node .
2015-09-09 13:15:17 +00:00
Depending on your use cases you may want to use strings , indices or pointers as ID .
2018-04-03 18:22:44 +00:00
e . g . when following a single pointer that may change over time , using a static string as ID
will preserve your node open / closed state when the targeted object change .
2018-05-17 12:12:37 +00:00
e . g . when displaying a list of objects , using indices or pointers as ID will preserve the
2018-04-03 18:22:44 +00:00
node open / closed state differently . See what makes more sense in your situation !
2014-08-10 20:58:11 +00:00
2019-10-15 11:00:04 +00:00
Q : How can I display an image ? What is ImTextureID , how does it works ?
2019-10-16 09:03:41 +00:00
> > See https : //www.dearimgui.org/faq and https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples
2019-10-15 11:00:04 +00:00
2019-01-20 16:56:17 +00:00
Q : How can I use my own math types instead of ImVec2 / ImVec4 ?
2019-10-15 11:00:04 +00:00
Q : How can I interact with standard C + + types ( such as std : : string and std : : vector ) ?
2019-10-18 10:54:30 +00:00
Q : How can I display custom shapes ? ( using low - level ImDrawList API )
2019-10-16 09:03:41 +00:00
> > See https : //www.dearimgui.org/faq
2018-07-26 10:55:40 +00:00
2019-10-15 11:00:04 +00:00
Q & A : Fonts , Text
= = = = = = = = = = = = = = = =
2018-02-20 09:24:31 +00:00
2019-10-15 11:00:04 +00:00
Q : How can I load a different font than the default ?
2016-11-06 21:53:36 +00:00
Q : How can I easily use icons in my application ?
2015-03-21 23:14:21 +00:00
Q : How can I load multiple fonts ?
2015-09-09 13:15:17 +00:00
Q : How can I display and input non - Latin characters such as Chinese , Japanese , Korean , Cyrillic ?
2019-11-25 17:29:28 +00:00
> > See https : //www.dearimgui.org/faq and docs/FONTS.txt
2014-11-30 15:54:58 +00:00
2019-10-15 11:00:04 +00:00
Q & A : Community
= = = = = = = = = = = = = =
2018-01-22 10:59:40 +00:00
2018-03-05 10:30:23 +00:00
Q : How can I help ?
2019-01-20 16:56:17 +00:00
A : - If you are experienced with Dear ImGui and C + + , look at the github issues , look at the Wiki , read docs / TODO . txt
2019-01-02 09:57:57 +00:00
and see how you want to help and can help !
- Businesses : convince your company to fund development via support contracts / sponsoring ! This is among the most useful thing you can do for dear imgui .
- Individuals : you can also become a Patron ( http : //www.patreon.com/imgui) or donate on PayPal! See README.
2018-05-17 12:12:37 +00:00
- Disclose your usage of dear imgui via a dev blog post , a tweet , a screenshot , a mention somewhere etc .
2019-10-15 11:00:04 +00:00
You may post screenshot or links in the gallery threads ( github . com / ocornut / imgui / issues / 2847 ) . Visuals are ideal as they inspire other programmers .
2018-03-05 10:30:23 +00:00
But even without visuals , disclosing your use of dear imgui help the library grow credibility , and help other teams and programmers with taking decisions .
- If you have issues or if you need to hack into the library , even if you don ' t expect any support it is useful that you share your issues ( on github or privately ) .
2017-10-19 17:30:46 +00:00
2014-08-10 20:58:11 +00:00
*/
2014-11-18 09:55:31 +00:00
# if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
2014-11-12 07:56:42 +00:00
# define _CRT_SECURE_NO_WARNINGS
# endif
2014-08-10 20:58:11 +00:00
# include "imgui.h"
2018-07-17 15:17:56 +00:00
# ifndef IMGUI_DEFINE_MATH_OPERATORS
2015-07-21 23:00:28 +00:00
# define IMGUI_DEFINE_MATH_OPERATORS
2018-07-17 15:17:56 +00:00
# endif
2015-07-21 23:00:28 +00:00
# include "imgui_internal.h"
2019-04-03 08:40:14 +00:00
# include <ctype.h> // toupper
2015-06-29 16:39:17 +00:00
# include <stdio.h> // vsnprintf, sscanf, printf
2015-04-24 07:22:29 +00:00
# if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier
# include <stddef.h> // intptr_t
# else
# include <stdint.h> // intptr_t
# endif
2014-08-10 20:58:11 +00:00
2018-10-12 11:38:52 +00:00
// Debug options
2019-02-01 09:26:08 +00:00
# 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
2019-07-24 04:26:15 +00:00
# define IMGUI_DEBUG_INI_SETTINGS 0 // Save additional comments in .ini file
2017-09-28 21:48:30 +00:00
2018-02-12 14:38:04 +00:00
// Visual Studio warnings
2014-11-18 09:55:31 +00:00
# ifdef _MSC_VER
2018-10-12 11:38:52 +00:00
# pragma warning (disable: 4127) // condition expression is constant
# pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen
2014-11-18 09:55:31 +00:00
# endif
2018-08-28 20:52:51 +00:00
// Clang/GCC warnings with -Weverything
2019-05-19 15:15:14 +00:00
# if defined(__clang__)
2017-07-15 05:27:44 +00:00
# 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!
2014-12-29 11:23:03 +00:00
# pragma clang diagnostic ignored "-Wold-style-cast" // warning : use of old-style cast // yes, they are more terse.
2017-05-01 10:55:47 +00:00
# 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.
2014-12-29 11:23:03 +00:00
# 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.
2014-11-18 09:55:31 +00:00
# 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.
2019-03-09 09:10:17 +00:00
# pragma clang diagnostic ignored "-Wglobal-constructors" // warning : declaration requires a global destructor // similar to above, not sure what the exact difference is.
2015-08-24 11:50:18 +00:00
# pragma clang diagnostic ignored "-Wsign-conversion" // warning : implicit conversion changes signedness //
2018-05-17 12:12:37 +00:00
# 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.
2019-01-13 17:57:46 +00:00
# pragma clang diagnostic ignored "-Wint-to-void-pointer-cast" // warning : cast to 'void *' from smaller integer type 'int'
2019-01-20 16:45:36 +00:00
# if __has_warning("-Wzero-as-null-pointer-constant")
2019-01-13 17:57:46 +00:00
# pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" // warning : zero as null pointer constant // some standard header variations use #define NULL 0
2019-01-20 16:45:36 +00:00
# endif
2019-01-13 17:57:46 +00:00
# if __has_warning("-Wdouble-promotion")
# 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
2016-05-09 20:27:44 +00:00
# elif defined(__GNUC__)
2019-06-17 09:32:00 +00:00
// 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
2015-01-24 10:30:40 +00:00
# pragma GCC diagnostic ignored "-Wunused-function" // warning: 'xxxx' defined but not used
2015-07-08 03:47:33 +00:00
# pragma GCC diagnostic ignored "-Wint-to-pointer-cast" // warning: cast to pointer from integer of different size
2016-05-04 21:28:16 +00:00
# pragma GCC diagnostic ignored "-Wformat" // warning: format '%p' expects argument of type 'void*', but argument 6 has type 'ImGuiWindow*'
2016-05-07 15:57:13 +00:00
# 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
2017-08-20 08:39:43 +00:00
# pragma GCC diagnostic ignored "-Wformat-nonliteral" // warning: format not a string literal, format string not checked
2018-02-16 14:43:28 +00:00
# pragma GCC diagnostic ignored "-Wstrict-overflow" // warning: assuming signed overflow does not occur when assuming that (X - c) > X is always false
2019-06-17 09:32:00 +00:00
# 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
2015-01-24 10:30:40 +00:00
# endif
2014-11-18 09:55:31 +00:00
2018-07-26 17:00:17 +00:00
// 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.
2018-10-02 16:43:10 +00:00
static const float NAV_WINDOWING_HIGHLIGHT_DELAY = 0.20f ; // Time before the highlight and screen dimming starts fading in
static const float NAV_WINDOWING_LIST_APPEAR_DELAY = 0.15f ; // Time before the window list starts to appear
2018-12-10 14:36:07 +00:00
// 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.
2019-07-23 01:48:39 +00:00
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.
2018-07-26 17:00:17 +00:00
2014-08-10 20:58:11 +00:00
//-------------------------------------------------------------------------
2018-09-06 09:35:13 +00:00
// [SECTION] FORWARD DECLARATIONS
2014-08-10 20:58:11 +00:00
//-------------------------------------------------------------------------
2015-07-22 02:06:34 +00:00
static void SetCurrentWindow ( ImGuiWindow * window ) ;
2018-07-09 19:06:46 +00:00
static void FindHoveredWindow ( ) ;
2015-07-21 23:00:28 +00:00
static ImGuiWindow * CreateNewWindow ( const char * name , ImVec2 size , ImGuiWindowFlags flags ) ;
2018-05-10 12:02:28 +00:00
static ImVec2 CalcNextScrollFromScrollTargetAndClamp ( ImGuiWindow * window , bool snap_on_edges ) ;
2015-07-21 23:00:28 +00:00
2018-02-16 23:49:57 +00:00
static void AddDrawListToDrawData ( ImVector < ImDrawList * > * out_list , ImDrawList * draw_list ) ;
2018-09-10 18:30:14 +00:00
static void AddWindowToSortBuffer ( ImVector < ImGuiWindow * > * out_sorted_windows , ImGuiWindow * window ) ;
2015-07-21 23:00:28 +00:00
2018-01-30 14:07:20 +00:00
static ImRect GetViewportRect ( ) ;
2015-07-21 23:00:28 +00:00
2018-08-30 13:48:57 +00:00
// Settings
2019-11-06 21:52:48 +00:00
static void * WindowSettingsHandler_ReadOpen ( ImGuiContext * , ImGuiSettingsHandler * , const char * name ) ;
static void WindowSettingsHandler_ReadLine ( ImGuiContext * , ImGuiSettingsHandler * , void * entry , const char * line ) ;
static void WindowSettingsHandler_WriteAll ( ImGuiContext * , ImGuiSettingsHandler * , ImGuiTextBuffer * buf ) ;
2018-08-30 13:48:57 +00:00
2018-08-31 07:50:14 +00:00
// Platform Dependents default implementation for IO functions
static const char * GetClipboardTextFn_DefaultImpl ( void * user_data ) ;
static void SetClipboardTextFn_DefaultImpl ( void * user_data , const char * text ) ;
static void ImeSetInputScreenPosFn_DefaultImpl ( int x , int y ) ;
2017-10-15 22:46:23 +00:00
namespace ImGui
{
2018-07-05 07:17:16 +00:00
static bool BeginChildEx ( const char * name , ImGuiID id , const ImVec2 & size_arg , bool border , ImGuiWindowFlags flags ) ;
2018-09-05 09:52:48 +00:00
// Navigation
2017-10-15 22:46:23 +00:00
static void NavUpdate ( ) ;
static void NavUpdateWindowing ( ) ;
2019-09-09 09:09:41 +00:00
static void NavUpdateWindowingOverlay ( ) ;
2018-08-30 16:01:19 +00:00
static void NavUpdateMoveResult ( ) ;
2019-10-02 09:38:30 +00:00
static float NavUpdatePageUpPageDown ( ) ;
2018-08-30 16:01:19 +00:00
static inline void NavUpdateAnyRequestFlag ( ) ;
2019-09-18 11:21:12 +00:00
static bool NavScoreItem ( ImGuiNavMoveResult * result , ImRect cand ) ;
2019-03-08 17:05:20 +00:00
static void NavProcessItem ( ImGuiWindow * window , const ImRect & nav_bb , ImGuiID id ) ;
2018-08-30 16:01:19 +00:00
static ImVec2 NavCalcPreferredRefPos ( ) ;
2019-04-16 11:07:43 +00:00
static void NavSaveLastChildNavWindowIntoParent ( ImGuiWindow * nav_window ) ;
2018-08-30 16:24:33 +00:00
static ImGuiWindow * NavRestoreLastChildNavWindow ( ImGuiWindow * window ) ;
2019-04-28 15:05:23 +00:00
static int FindWindowFocusIndex ( ImGuiWindow * window ) ;
2018-01-12 18:21:12 +00:00
2019-11-13 20:35:42 +00:00
// Error Checking
static void ErrorCheckEndFrame ( ) ;
static void ErrorCheckBeginEndCompareStacksSize ( ImGuiWindow * window , bool write ) ;
2018-09-05 09:52:48 +00:00
// Misc
2018-04-25 14:38:13 +00:00
static void UpdateMouseInputs ( ) ;
2018-07-22 16:57:28 +00:00
static void UpdateMouseWheel ( ) ;
2019-06-05 13:33:41 +00:00
static bool UpdateManualResize ( ImGuiWindow * window , const ImVec2 & size_auto_fit , int * border_held , int resize_grip_count , ImU32 resize_grip_col [ 4 ] ) ;
2019-07-21 19:13:44 +00:00
static void UpdateDebugToolItemPicker ( ) ;
2019-05-10 20:38:10 +00:00
static void RenderWindowOuterBorders ( ImGuiWindow * window ) ;
2019-05-10 20:45:52 +00:00
static void RenderWindowDecorations ( ImGuiWindow * window , const ImRect & title_bar_rect , bool title_bar_is_highlight , int resize_grip_count , const ImU32 resize_grip_col [ 4 ] , float resize_grip_draw_size ) ;
2019-05-10 20:38:10 +00:00
static void RenderWindowTitleBarContents ( ImGuiWindow * window , const ImRect & title_bar_rect , const char * name , bool * p_open ) ;
2019-01-23 16:31:32 +00:00
2017-10-15 22:46:23 +00:00
}
2015-07-21 23:00:28 +00:00
//-----------------------------------------------------------------------------
2018-09-06 09:35:13 +00:00
// [SECTION] CONTEXT AND MEMORY ALLOCATORS
2015-07-21 23:00:28 +00:00
//-----------------------------------------------------------------------------
2018-10-25 17:02:24 +00:00
// Current context pointer. Implicitly used by all Dear ImGui functions. Always assumed to be != NULL.
2019-01-18 22:02:58 +00:00
// ImGui::CreateContext() will automatically set this pointer if it is NULL. Change to a different context by calling ImGui::SetCurrentContext().
// 1) Important: globals are not shared across DLL boundaries! If you use DLLs or any form of hot-reloading: you will need to call
// SetCurrentContext() (with the pointer you got from CreateContext) from each unique static/DLL boundary, and after each hot-reloading.
// In your debugger, add GImGui to your watch window and notice how its value changes depending on which location you are currently stepping into.
2019-01-20 16:56:17 +00:00
// 2) Important: Dear ImGui functions are not thread-safe because of this pointer.
2019-01-18 22:02:58 +00:00
// If you want thread-safety to allow N threads to access N different contexts, you can:
// - Change this variable to use thread local storage so each thread can refer to a different context, in imconfig.h:
// struct ImGuiContext;
// extern thread_local ImGuiContext* MyImGuiTLS;
// #define GImGui MyImGuiTLS
// And then define MyImGuiTLS in one of your cpp file. Note that thread_local is a C++11 keyword, earlier C++ uses compiler-specific keyword.
// - Future development aim to make this context pointer explicit to all calls. Also read https://github.com/ocornut/imgui/issues/586
// - If you need a finite number of contexts, you may compile and use multiple instances of the ImGui code from different namespace.
2016-11-12 16:08:31 +00:00
# ifndef GImGui
Reorganized context handling to be more explicit,
- YOU NOW NEED TO CALL ImGui::CreateContext() AT THE BEGINNING OF YOUR APP, AND CALL ImGui::DestroyContext() AT THE END.
- removed Shutdown() function, as DestroyContext() serve this purpose.
- you may pass a ImFontAtlas* pointer to CreateContext() to share a font atlas between contexts. Otherwhise CreateContext() will create its own font atlas instance.
- removed allocator parameters from CreateContext(), they are now setup with SetAllocatorFunctions(), and shared by all contexts.
- removed the default global context and font atlas instance, which were confusing for users of DLL reloading and users of multiple contexts
(#1565, #586, #992, #1007, #1558)
2018-01-21 18:58:32 +00:00
ImGuiContext * GImGui = NULL ;
2016-11-12 16:08:31 +00:00
# endif
2016-05-08 15:12:54 +00:00
2018-01-21 18:44:48 +00:00
// Memory Allocator functions. Use SetAllocatorFunctions() to change them.
2018-05-17 12:12:37 +00:00
// If you use DLL hotreloading you might need to call SetAllocatorFunctions() after reloading code from this file.
2018-01-20 20:41:46 +00:00
// Otherwise, you probably don't want to modify them mid-program, and if you use global/static e.g. ImVector<> instances you may need to keep them accessible during program destruction.
2018-01-21 17:54:22 +00:00
# ifndef IMGUI_DISABLE_DEFAULT_ALLOCATORS
2019-01-27 15:23:23 +00:00
static void * MallocWrapper ( size_t size , void * user_data ) { IM_UNUSED ( user_data ) ; return malloc ( size ) ; }
static void FreeWrapper ( void * ptr , void * user_data ) { IM_UNUSED ( user_data ) ; free ( ptr ) ; }
2018-01-21 17:54:22 +00:00
# else
2019-01-27 15:23:23 +00:00
static void * MallocWrapper ( size_t size , void * user_data ) { IM_UNUSED ( user_data ) ; IM_UNUSED ( size ) ; IM_ASSERT ( 0 ) ; return NULL ; }
static void FreeWrapper ( void * ptr , void * user_data ) { IM_UNUSED ( user_data ) ; IM_UNUSED ( ptr ) ; IM_ASSERT ( 0 ) ; }
2016-11-12 16:08:31 +00:00
# endif
2016-05-08 15:12:54 +00:00
2018-01-20 20:41:46 +00:00
static void * ( * GImAllocatorAllocFunc ) ( size_t size , void * user_data ) = MallocWrapper ;
static void ( * GImAllocatorFreeFunc ) ( void * ptr , void * user_data ) = FreeWrapper ;
static void * GImAllocatorUserData = NULL ;
2014-08-10 20:58:11 +00:00
//-----------------------------------------------------------------------------
2018-09-06 09:35:13 +00:00
// [SECTION] MAIN USER FACING STRUCTURES (ImGuiStyle, ImGuiIO)
2014-08-10 20:58:11 +00:00
//-----------------------------------------------------------------------------
ImGuiStyle : : ImGuiStyle ( )
{
2014-08-19 11:09:13 +00:00
Alpha = 1.0f ; // Global alpha applies to everything in ImGui
WindowPadding = ImVec2 ( 8 , 8 ) ; // Padding within a window
2017-11-30 18:06:09 +00:00
WindowRounding = 7.0f ; // Radius of window corners rounding. Set to 0.0f to have rectangular windows
2018-01-30 23:03:11 +00:00
WindowBorderSize = 1.0f ; // Thickness of border around windows. Generally set to 0.0f or 1.0f. Other values not well tested.
2017-11-19 13:58:10 +00:00
WindowMinSize = ImVec2 ( 32 , 32 ) ; // Minimum window size
2016-09-25 10:19:15 +00:00
WindowTitleAlign = ImVec2 ( 0.0f , 0.5f ) ; // Alignment for title bar text
2019-05-24 18:59:41 +00:00
WindowMenuButtonPosition = ImGuiDir_Left ; // Position of the collapsing/docking button in the title bar (left/right). Defaults to ImGuiDir_Left.
2017-11-18 17:28:21 +00:00
ChildRounding = 0.0f ; // Radius of child window corners rounding. Set to 0.0f to have rectangular child windows
2017-11-19 14:56:51 +00:00
ChildBorderSize = 1.0f ; // Thickness of border around child windows. Generally set to 0.0f or 1.0f. Other values not well tested.
2017-11-18 23:28:10 +00:00
PopupRounding = 0.0f ; // Radius of popup window corners rounding. Set to 0.0f to have rectangular child windows
2017-11-19 14:56:51 +00:00
PopupBorderSize = 1.0f ; // Thickness of border around popup or tooltip windows. Generally set to 0.0f or 1.0f. Other values not well tested.
2014-12-30 10:00:00 +00:00
FramePadding = ImVec2 ( 4 , 3 ) ; // Padding within a framed rectangle (used by most widgets)
2015-01-15 09:14:44 +00:00
FrameRounding = 0.0f ; // Radius of frame corners rounding. Set to 0.0f to have rectangular frames (used by most widgets).
2017-11-19 14:56:51 +00:00
FrameBorderSize = 0.0f ; // Thickness of border around frames. Generally set to 0.0f or 1.0f. Other values not well tested.
2014-12-30 10:00:00 +00:00
ItemSpacing = ImVec2 ( 8 , 4 ) ; // Horizontal and vertical spacing between widgets/lines
ItemInnerSpacing = ImVec2 ( 4 , 4 ) ; // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label)
2015-03-17 23:41:20 +00:00
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!
2016-05-01 21:49:10 +00:00
IndentSpacing = 21.0f ; // Horizontal spacing when e.g. entering a tree node. Generally == (FontSize + FramePadding.x*2).
2019-05-09 10:56:03 +00:00
ColumnsMinSpacing = 6.0f ; // Minimum horizontal spacing between two columns. Preferably > (FramePadding.x + 1).
2019-06-05 13:23:01 +00:00
ScrollbarSize = 14.0f ; // Width of the vertical scrollbar, Height of the horizontal scrollbar
2015-08-30 15:43:08 +00:00
ScrollbarRounding = 9.0f ; // Radius of grab corners rounding for scrollbar
2015-05-09 09:13:56 +00:00
GrabMinSize = 10.0f ; // Minimum width/height of a grab box for slider/scrollbar
2015-06-30 21:02:59 +00:00
GrabRounding = 0.0f ; // Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs.
2018-12-11 11:36:47 +00:00
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.
2019-07-16 23:43:21 +00:00
ColorButtonPosition = ImGuiDir_Right ; // Side of the color button in the ColorEdit4 widget (left/right). Defaults to ImGuiDir_Right.
2016-09-25 10:53:13 +00:00
ButtonTextAlign = ImVec2 ( 0.5f , 0.5f ) ; // Alignment of button text when button is larger than text.
2019-02-14 19:29:50 +00:00
SelectableTextAlign = ImVec2 ( 0.0f , 0.0f ) ; // Alignment of selectable text when button is larger than text.
2018-12-10 15:05:30 +00:00
DisplayWindowPadding = ImVec2 ( 19 , 19 ) ; // Window position are clamped to be visible within the display area by at least this amount. Only applies to regular windows.
2018-04-18 13:38:04 +00:00
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.
2018-02-05 14:07:25 +00:00
MouseCursorScale = 1.0f ; // Scale software rendered mouse cursor (when io.MouseDrawCursor is enabled). May be removed later.
2015-07-06 01:09:53 +00:00
AntiAliasedLines = true ; // Enable anti-aliasing on lines/borders. Disable if you are really short on CPU/GPU.
2017-12-21 18:48:51 +00:00
AntiAliasedFill = true ; // Enable anti-aliasing on filled shapes (rounded rectangles, circles, etc.)
2017-12-21 13:50:58 +00:00
CurveTessellationTol = 1.25f ; // Tessellation tolerance when using PathBezierCurveTo() without a specific number of segments. Decrease for highly tessellated curves (higher quality, more polygons), increase to reduce quality.
2014-08-19 11:09:13 +00:00
2018-04-06 21:25:25 +00:00
// Default theme
ImGui : : StyleColorsDark ( this ) ;
2017-08-14 07:14:46 +00:00
}
2017-10-05 01:13:57 +00:00
// To scale your entire UI (e.g. if you want your app to use High DPI or generally be DPI aware) you may use this helper function. Scaling the fonts is done separately and is up to you.
2017-11-17 20:29:37 +00:00
// Important: This operation is lossy because we round all sizes to integer. If you need to change your scale multiples, call this over a freshly initialized ImGuiStyle structure rather than scaling multiple times.
2017-10-05 01:13:57 +00:00
void ImGuiStyle : : ScaleAllSizes ( float scale_factor )
{
2017-11-17 20:29:37 +00:00
WindowPadding = ImFloor ( WindowPadding * scale_factor ) ;
WindowRounding = ImFloor ( WindowRounding * scale_factor ) ;
2017-11-19 13:58:10 +00:00
WindowMinSize = ImFloor ( WindowMinSize * scale_factor ) ;
2017-11-18 17:28:21 +00:00
ChildRounding = ImFloor ( ChildRounding * scale_factor ) ;
2017-11-18 23:28:10 +00:00
PopupRounding = ImFloor ( PopupRounding * scale_factor ) ;
2017-11-17 20:29:37 +00:00
FramePadding = ImFloor ( FramePadding * scale_factor ) ;
FrameRounding = ImFloor ( FrameRounding * scale_factor ) ;
ItemSpacing = ImFloor ( ItemSpacing * scale_factor ) ;
ItemInnerSpacing = ImFloor ( ItemInnerSpacing * scale_factor ) ;
TouchExtraPadding = ImFloor ( TouchExtraPadding * scale_factor ) ;
IndentSpacing = ImFloor ( IndentSpacing * scale_factor ) ;
ColumnsMinSpacing = ImFloor ( ColumnsMinSpacing * scale_factor ) ;
ScrollbarSize = ImFloor ( ScrollbarSize * scale_factor ) ;
ScrollbarRounding = ImFloor ( ScrollbarRounding * scale_factor ) ;
GrabMinSize = ImFloor ( GrabMinSize * scale_factor ) ;
GrabRounding = ImFloor ( GrabRounding * scale_factor ) ;
2019-02-04 13:38:35 +00:00
TabRounding = ImFloor ( TabRounding * scale_factor ) ;
2017-11-17 20:29:37 +00:00
DisplayWindowPadding = ImFloor ( DisplayWindowPadding * scale_factor ) ;
DisplaySafeAreaPadding = ImFloor ( DisplaySafeAreaPadding * scale_factor ) ;
2018-02-04 11:17:35 +00:00
MouseCursorScale = ImFloor ( MouseCursorScale * scale_factor ) ;
2017-10-05 01:13:57 +00:00
}
2014-08-10 20:58:11 +00:00
ImGuiIO : : ImGuiIO ( )
{
2015-01-31 18:55:05 +00:00
// Most fields are initialized with zero
2014-08-19 11:09:13 +00:00
memset ( this , 0 , sizeof ( * this ) ) ;
2019-12-08 15:26:47 +00:00
IM_ASSERT ( IM_ARRAYSIZE ( ImGuiIO : : MouseDown ) = = ImGuiMouseButton_COUNT & & IM_ARRAYSIZE ( ImGuiIO : : MouseClicked ) = = ImGuiMouseButton_COUNT ) ; // Our pre-C++11 IM_STATIC_ASSERT() macros triggers warning on modern compilers so we don't use it here.
2015-01-31 18:55:05 +00:00
2016-07-17 08:26:48 +00:00
// Settings
2018-11-27 18:32:47 +00:00
ConfigFlags = ImGuiConfigFlags_None ;
BackendFlags = ImGuiBackendFlags_None ;
2014-12-22 01:45:13 +00:00
DisplaySize = ImVec2 ( - 1.0f , - 1.0f ) ;
2014-08-19 11:09:13 +00:00
DeltaTime = 1.0f / 60.0f ;
IniSavingRate = 5.0f ;
IniFilename = " imgui.ini " ;
LogFilename = " imgui_log.txt " ;
MouseDoubleClickTime = 0.30f ;
MouseDoubleClickMaxDist = 6.0f ;
2015-07-03 03:32:29 +00:00
for ( int i = 0 ; i < ImGuiKey_COUNT ; i + + )
KeyMap [ i ] = - 1 ;
2019-10-14 21:07:06 +00:00
KeyRepeatDelay = 0.275f ;
2015-06-17 22:02:50 +00:00
KeyRepeatRate = 0.050f ;
2014-10-05 08:11:02 +00:00
UserData = NULL ;
2014-08-13 18:53:26 +00:00
Reorganized context handling to be more explicit,
- YOU NOW NEED TO CALL ImGui::CreateContext() AT THE BEGINNING OF YOUR APP, AND CALL ImGui::DestroyContext() AT THE END.
- removed Shutdown() function, as DestroyContext() serve this purpose.
- you may pass a ImFontAtlas* pointer to CreateContext() to share a font atlas between contexts. Otherwhise CreateContext() will create its own font atlas instance.
- removed allocator parameters from CreateContext(), they are now setup with SetAllocatorFunctions(), and shared by all contexts.
- removed the default global context and font atlas instance, which were confusing for users of DLL reloading and users of multiple contexts
(#1565, #586, #992, #1007, #1558)
2018-01-21 18:58:32 +00:00
Fonts = NULL ;
2016-07-17 08:26:48 +00:00
FontGlobalScale = 1.0f ;
2016-11-09 14:21:36 +00:00
FontDefault = NULL ;
2016-07-17 08:26:48 +00:00
FontAllowUserScaling = false ;
DisplayFramebufferScale = ImVec2 ( 1.0f , 1.0f ) ;
2019-02-01 09:26:08 +00:00
// Miscellaneous options
MouseDrawCursor = false ;
2017-11-12 15:03:09 +00:00
# ifdef __APPLE__
2018-08-01 09:50:57 +00:00
ConfigMacOSXBehaviors = true ; // Set Mac OS X style defaults based on __APPLE__ compile time flag
2017-11-12 15:03:09 +00:00
# else
2018-08-01 09:50:57 +00:00
ConfigMacOSXBehaviors = false ;
2017-11-12 15:03:09 +00:00
# endif
2018-09-05 15:20:27 +00:00
ConfigInputTextCursorBlink = true ;
2018-12-10 14:36:07 +00:00
ConfigWindowsResizeFromEdges = true ;
2018-12-10 15:05:30 +00:00
ConfigWindowsMoveFromTitleBarOnly = false ;
2019-06-30 10:48:19 +00:00
ConfigWindowsMemoryCompactTimer = 60.0f ;
2018-02-16 18:18:16 +00:00
2018-11-30 16:15:03 +00:00
// Platform Functions
2018-11-30 17:18:15 +00:00
BackendPlatformName = BackendRendererName = NULL ;
2018-12-20 10:41:24 +00:00
BackendPlatformUserData = BackendRendererUserData = BackendLanguageUserData = NULL ;
2014-12-29 11:23:03 +00:00
GetClipboardTextFn = GetClipboardTextFn_DefaultImpl ; // Platform dependent default implementations
2014-08-19 11:09:13 +00:00
SetClipboardTextFn = SetClipboardTextFn_DefaultImpl ;
2016-10-15 09:36:43 +00:00
ClipboardUserData = NULL ;
2015-03-06 21:11:14 +00:00
ImeSetInputScreenPosFn = ImeSetInputScreenPosFn_DefaultImpl ;
2016-07-17 08:26:48 +00:00
ImeWindowHandle = NULL ;
2016-04-02 16:57:08 +00:00
2018-02-16 18:18:16 +00:00
# ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
RenderDrawListsFn = NULL ;
# endif
2018-11-30 16:15:03 +00:00
// Input (NB: we already have memset zero the entire structure!)
2017-09-20 21:02:06 +00:00
MousePos = ImVec2 ( - FLT_MAX , - FLT_MAX ) ;
MousePosPrev = ImVec2 ( - FLT_MAX , - FLT_MAX ) ;
2016-07-17 08:26:48 +00:00
MouseDragThreshold = 6.0f ;
2016-08-03 21:23:04 +00:00
for ( int i = 0 ; i < IM_ARRAYSIZE ( MouseDownDuration ) ; i + + ) MouseDownDuration [ i ] = MouseDownDurationPrev [ i ] = - 1.0f ;
for ( int i = 0 ; i < IM_ARRAYSIZE ( KeysDownDuration ) ; i + + ) KeysDownDuration [ i ] = KeysDownDurationPrev [ i ] = - 1.0f ;
for ( int i = 0 ; i < IM_ARRAYSIZE ( NavInputsDownDuration ) ; i + + ) NavInputsDownDuration [ i ] = - 1.0f ;
2014-08-10 20:58:11 +00:00
}
2015-07-07 18:09:25 +00:00
// 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
2019-05-11 08:33:56 +00:00
void ImGuiIO : : AddInputCharacter ( unsigned int c )
2015-07-07 18:09:25 +00:00
{
2019-10-29 21:50:34 +00:00
if ( c > 0 & & c < = IM_UNICODE_CODEPOINT_MAX )
2019-05-11 08:33:56 +00:00
InputQueueCharacters . push_back ( ( ImWchar ) c ) ;
2019-01-06 15:37:42 +00:00
}
void ImGuiIO : : AddInputCharactersUTF8 ( const char * utf8_chars )
{
while ( * utf8_chars ! = 0 )
2015-07-07 18:09:25 +00:00
{
2019-01-06 15:37:42 +00:00
unsigned int c = 0 ;
utf8_chars + = ImTextCharFromUtf8 ( & c , utf8_chars , NULL ) ;
2019-10-29 21:50:34 +00:00
if ( c > 0 & & c < = IM_UNICODE_CODEPOINT_MAX )
2019-01-06 15:37:42 +00:00
InputQueueCharacters . push_back ( ( ImWchar ) c ) ;
2015-07-07 18:09:25 +00:00
}
}
2019-01-06 15:37:42 +00:00
void ImGuiIO : : ClearInputCharacters ( )
2015-07-16 03:15:03 +00:00
{
2019-01-06 15:37:42 +00:00
InputQueueCharacters . resize ( 0 ) ;
2015-07-16 03:15:03 +00:00
}
2015-07-21 23:00:28 +00:00
//-----------------------------------------------------------------------------
2019-12-17 15:24:50 +00:00
// [SECTION] MISC HELPERS/UTILITIES (Geometry functions)
2015-07-21 23:00:28 +00:00
//-----------------------------------------------------------------------------
2019-12-17 15:24:50 +00:00
ImVec2 ImBezierClosestPoint ( const ImVec2 & p1 , const ImVec2 & p2 , const ImVec2 & p3 , const ImVec2 & p4 , const ImVec2 & p , int num_segments )
2019-12-17 14:29:12 +00:00
{
2019-12-17 15:24:50 +00:00
IM_ASSERT ( num_segments > 0 ) ; // Use ImBezierClosestPointCasteljau()
2019-12-17 14:29:12 +00:00
ImVec2 p_last = p1 ;
ImVec2 p_closest ;
float p_closest_dist2 = FLT_MAX ;
float t_step = 1.0f / ( float ) num_segments ;
for ( int i_step = 1 ; i_step < = num_segments ; i_step + + )
{
ImVec2 p_current = ImBezierCalc ( p1 , p2 , p3 , p4 , t_step * i_step ) ;
ImVec2 p_line = ImLineClosestPoint ( p_last , p_current , p ) ;
float dist2 = ImLengthSqr ( p - p_line ) ;
if ( dist2 < p_closest_dist2 )
{
p_closest = p_line ;
p_closest_dist2 = dist2 ;
}
p_last = p_current ;
}
return p_closest ;
}
// Closely mimics PathBezierToCasteljau() in imgui_draw.cpp
2019-12-17 15:24:50 +00:00
static void BezierClosestPointCasteljauStep ( const ImVec2 & p , ImVec2 & p_closest , ImVec2 & p_last , float & p_closest_dist2 , float x1 , float y1 , float x2 , float y2 , float x3 , float y3 , float x4 , float y4 , float tess_tol , int level )
2019-12-17 14:29:12 +00:00
{
float dx = x4 - x1 ;
float dy = y4 - y1 ;
float d2 = ( ( x2 - x4 ) * dy - ( y2 - y4 ) * dx ) ;
float d3 = ( ( x3 - x4 ) * dy - ( y3 - y4 ) * dx ) ;
d2 = ( d2 > = 0 ) ? d2 : - d2 ;
d3 = ( d3 > = 0 ) ? d3 : - d3 ;
if ( ( d2 + d3 ) * ( d2 + d3 ) < tess_tol * ( dx * dx + dy * dy ) )
{
ImVec2 p_current ( x4 , y4 ) ;
ImVec2 p_line = ImLineClosestPoint ( p_last , p_current , p ) ;
float dist2 = ImLengthSqr ( p - p_line ) ;
if ( dist2 < p_closest_dist2 )
{
p_closest = p_line ;
p_closest_dist2 = dist2 ;
}
p_last = p_current ;
}
else if ( level < 10 )
{
float x12 = ( x1 + x2 ) * 0.5f , y12 = ( y1 + y2 ) * 0.5f ;
float x23 = ( x2 + x3 ) * 0.5f , y23 = ( y2 + y3 ) * 0.5f ;
float x34 = ( x3 + x4 ) * 0.5f , y34 = ( y3 + y4 ) * 0.5f ;
float x123 = ( x12 + x23 ) * 0.5f , y123 = ( y12 + y23 ) * 0.5f ;
float x234 = ( x23 + x34 ) * 0.5f , y234 = ( y23 + y34 ) * 0.5f ;
float x1234 = ( x123 + x234 ) * 0.5f , y1234 = ( y123 + y234 ) * 0.5f ;
2019-12-17 15:24:50 +00:00
BezierClosestPointCasteljauStep ( p , p_closest , p_last , p_closest_dist2 , x1 , y1 , x12 , y12 , x123 , y123 , x1234 , y1234 , tess_tol , level + 1 ) ;
BezierClosestPointCasteljauStep ( p , p_closest , p_last , p_closest_dist2 , x1234 , y1234 , x234 , y234 , x34 , y34 , x4 , y4 , tess_tol , level + 1 ) ;
2019-12-17 14:29:12 +00:00
}
}
2019-12-17 15:24:50 +00:00
// tess_tol is generally the same value you would find in ImGui::GetStyle().CurveTessellationTol
// Because those ImXXX functions are lower-level than ImGui:: we cannot access this value automatically.
ImVec2 ImBezierClosestPointCasteljau ( const ImVec2 & p1 , const ImVec2 & p2 , const ImVec2 & p3 , const ImVec2 & p4 , const ImVec2 & p , float tess_tol )
2019-12-17 14:29:12 +00:00
{
IM_ASSERT ( tess_tol > 0.0f ) ;
ImVec2 p_last = p1 ;
ImVec2 p_closest ;
float p_closest_dist2 = FLT_MAX ;
2019-12-17 15:24:50 +00:00
BezierClosestPointCasteljauStep ( p , p_closest , p_last , p_closest_dist2 , p1 . x , p1 . y , p2 . x , p2 . y , p3 . x , p3 . y , p4 . x , p4 . y , tess_tol , 0 ) ;
2019-12-17 14:29:12 +00:00
return p_closest ;
}
2017-07-31 13:11:41 +00:00
ImVec2 ImLineClosestPoint ( const ImVec2 & a , const ImVec2 & b , const ImVec2 & p )
{
ImVec2 ap = p - a ;
ImVec2 ab_dir = b - a ;
float dot = ap . x * ab_dir . x + ap . y * ab_dir . y ;
if ( dot < 0.0f )
return a ;
2018-02-22 04:18:25 +00:00
float ab_len_sqr = ab_dir . x * ab_dir . x + ab_dir . y * ab_dir . y ;
if ( dot > ab_len_sqr )
2017-07-31 13:11:41 +00:00
return b ;
2018-02-22 04:18:25 +00:00
return a + ab_dir * dot / ab_len_sqr ;
2017-07-31 13:11:41 +00:00
}
bool ImTriangleContainsPoint ( const ImVec2 & a , const ImVec2 & b , const ImVec2 & c , const ImVec2 & p )
2015-05-26 16:09:21 +00:00
{
bool b1 = ( ( p . x - b . x ) * ( a . y - b . y ) - ( p . y - b . y ) * ( a . x - b . x ) ) < 0.0f ;
bool b2 = ( ( p . x - c . x ) * ( b . y - c . y ) - ( p . y - c . y ) * ( b . x - c . x ) ) < 0.0f ;
bool b3 = ( ( p . x - a . x ) * ( c . y - a . y ) - ( p . y - a . y ) * ( c . x - a . x ) ) < 0.0f ;
return ( ( b1 = = b2 ) & & ( b2 = = b3 ) ) ;
}
2017-07-31 13:11:41 +00:00
void ImTriangleBarycentricCoords ( const ImVec2 & a , const ImVec2 & b , const ImVec2 & c , const ImVec2 & p , float & out_u , float & out_v , float & out_w )
2017-07-31 09:54:40 +00:00
{
ImVec2 v0 = b - a ;
ImVec2 v1 = c - a ;
ImVec2 v2 = p - a ;
const float denom = v0 . x * v1 . y - v1 . x * v0 . y ;
out_v = ( v2 . x * v1 . y - v1 . x * v2 . y ) / denom ;
out_w = ( v0 . x * v2 . y - v2 . x * v0 . y ) / denom ;
out_u = 1.0f - out_v - out_w ;
}
2017-07-31 13:11:41 +00:00
ImVec2 ImTriangleClosestPoint ( const ImVec2 & a , const ImVec2 & b , const ImVec2 & c , const ImVec2 & p )
{
ImVec2 proj_ab = ImLineClosestPoint ( a , b , p ) ;
ImVec2 proj_bc = ImLineClosestPoint ( b , c , p ) ;
ImVec2 proj_ca = ImLineClosestPoint ( c , a , p ) ;
float dist2_ab = ImLengthSqr ( p - proj_ab ) ;
float dist2_bc = ImLengthSqr ( p - proj_bc ) ;
float dist2_ca = ImLengthSqr ( p - proj_ca ) ;
float m = ImMin ( dist2_ab , ImMin ( dist2_bc , dist2_ca ) ) ;
if ( m = = dist2_ab )
return proj_ab ;
if ( m = = dist2_bc )
return proj_bc ;
return proj_ca ;
}
2019-12-17 15:24:50 +00:00
//-----------------------------------------------------------------------------
// [SECTION] MISC HELPERS/UTILITIES (String, Format, Hash functions)
//-----------------------------------------------------------------------------
2019-01-30 09:52:13 +00:00
// Consider using _stricmp/_strnicmp under Windows or strcasecmp/strncasecmp. We don't actually use either ImStricmp/ImStrnicmp in the codebase any more.
2015-07-21 23:00:28 +00:00
int ImStricmp ( const char * str1 , const char * str2 )
2014-08-10 20:58:11 +00:00
{
2014-08-19 11:09:13 +00:00
int d ;
while ( ( d = toupper ( * str2 ) - toupper ( * str1 ) ) = = 0 & & * str1 ) { str1 + + ; str2 + + ; }
return d ;
2014-08-10 20:58:11 +00:00
}
2017-12-21 12:43:09 +00:00
int ImStrnicmp ( const char * str1 , const char * str2 , size_t count )
2014-11-23 23:35:26 +00:00
{
2014-11-30 12:21:50 +00:00
int d = 0 ;
2014-11-23 23:35:26 +00:00
while ( count > 0 & & ( d = toupper ( * str2 ) - toupper ( * str1 ) ) = = 0 & & * str1 ) { str1 + + ; str2 + + ; count - - ; }
2014-11-30 12:31:43 +00:00
return d ;
2014-11-23 23:35:26 +00:00
}
2017-12-21 12:43:09 +00:00
void ImStrncpy ( char * dst , const char * src , size_t count )
2016-06-25 11:54:34 +00:00
{
2019-03-16 14:48:21 +00:00
if ( count < 1 )
2019-01-30 09:52:13 +00:00
return ;
2019-01-30 09:19:40 +00:00
if ( count > 1 )
2019-01-30 09:52:13 +00:00
strncpy ( dst , src , count - 1 ) ;
dst [ count - 1 ] = 0 ;
2016-06-25 11:54:34 +00:00
}
2019-01-07 21:46:42 +00:00
char * ImStrdup ( const char * str )
2014-08-31 10:28:21 +00:00
{
2019-01-07 21:46:42 +00:00
size_t len = strlen ( str ) ;
2019-04-05 18:20:08 +00:00
void * buf = IM_ALLOC ( len + 1 ) ;
2019-01-07 21:46:42 +00:00
return ( char * ) memcpy ( buf , ( const void * ) str , len + 1 ) ;
}
char * ImStrdupcpy ( char * dst , size_t * p_dst_size , const char * src )
{
size_t dst_buf_size = p_dst_size ? * p_dst_size : strlen ( dst ) + 1 ;
size_t src_size = strlen ( src ) + 1 ;
if ( dst_buf_size < src_size )
{
2019-04-05 18:20:08 +00:00
IM_FREE ( dst ) ;
dst = ( char * ) IM_ALLOC ( src_size ) ;
2019-01-07 21:46:42 +00:00
if ( p_dst_size )
* p_dst_size = src_size ;
}
return ( char * ) memcpy ( dst , ( const void * ) src , src_size ) ;
2017-11-27 22:55:42 +00:00
}
2018-04-03 18:55:30 +00:00
const char * ImStrchrRange ( const char * str , const char * str_end , char c )
2017-11-27 22:55:42 +00:00
{
2018-10-11 09:48:40 +00:00
const char * p = ( const char * ) memchr ( str , ( int ) c , str_end - str ) ;
return p ;
2014-08-10 20:58:11 +00:00
}
2015-07-21 23:00:28 +00:00
int ImStrlenW ( const ImWchar * str )
2014-09-25 13:51:06 +00:00
{
2019-11-20 10:58:25 +00:00
//return (int)wcslen((const wchar_t*)str); // FIXME-OPT: Could use this when wchar_t are 16-bit
2018-10-12 13:48:38 +00:00
int n = 0 ;
while ( * str + + ) n + + ;
return n ;
2014-09-25 13:51:06 +00:00
}
2018-10-11 09:48:40 +00:00
// Find end-of-line. Return pointer will point to either first \n, either str_end.
const char * ImStreolRange ( const char * str , const char * str_end )
{
const char * p = ( const char * ) memchr ( str , ' \n ' , str_end - str ) ;
return p ? p : str_end ;
}
2015-07-21 23:00:28 +00:00
const ImWchar * ImStrbolW ( const ImWchar * buf_mid_line , const ImWchar * buf_begin ) // find beginning-of-line
2015-06-19 05:23:20 +00:00
{
while ( buf_mid_line > buf_begin & & buf_mid_line [ - 1 ] ! = ' \n ' )
buf_mid_line - - ;
return buf_mid_line ;
}
2015-08-14 03:25:32 +00:00
const char * ImStristr ( const char * haystack , const char * haystack_end , const char * needle , const char * needle_end )
2014-08-10 20:58:11 +00:00
{
2014-08-19 11:09:13 +00:00
if ( ! needle_end )
needle_end = needle + strlen ( needle ) ;
const char un0 = ( char ) toupper ( * needle ) ;
2015-08-14 03:25:32 +00:00
while ( ( ! haystack_end & & * haystack ) | | ( haystack_end & & haystack < haystack_end ) )
2014-08-19 11:09:13 +00:00
{
if ( toupper ( * haystack ) = = un0 )
{
const char * b = needle + 1 ;
for ( const char * a = haystack + 1 ; b < needle_end ; a + + , b + + )
if ( toupper ( * a ) ! = toupper ( * b ) )
break ;
if ( b = = needle_end )
return haystack ;
}
haystack + + ;
}
return NULL ;
2014-08-10 20:58:11 +00:00
}
2018-05-03 09:59:20 +00:00
// Trim str by offsetting contents when there's leading data + writing a \0 at the trailing position. We use this in situation where the cost is negligible.
void ImStrTrimBlanks ( char * buf )
{
char * p = buf ;
while ( p [ 0 ] = = ' ' | | p [ 0 ] = = ' \t ' ) // Leading blanks
p + + ;
char * p_start = p ;
while ( * p ! = 0 ) // Find end of string
p + + ;
while ( p > p_start & & ( p [ - 1 ] = = ' ' | | p [ - 1 ] = = ' \t ' ) ) // Trailing blanks
p - - ;
if ( p_start ! = buf ) // Copy memory if we had leading blanks
memmove ( buf , p_start , p - p_start ) ;
buf [ p - p_start ] = 0 ; // Zero terminate
}
2019-11-06 21:52:48 +00:00
const char * ImStrSkipBlank ( const char * str )
{
while ( str [ 0 ] = = ' ' | | str [ 0 ] = = ' \t ' )
str + + ;
return str ;
}
2018-05-17 12:12:37 +00:00
// A) MSVC version appears to return -1 on overflow, whereas glibc appears to return total count (which may be >= buf_size).
2016-08-23 14:55:06 +00:00
// Ideally we would test for only one of those limits at runtime depending on the behavior the vsnprintf(), but trying to deduct it at compile time sounds like a pandora can of worm.
2017-10-24 18:48:29 +00:00
// B) When buf==NULL vsnprintf() will return the output size.
2019-11-19 20:20:46 +00:00
# ifndef IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS
2018-07-30 13:27:09 +00:00
2019-11-19 20:20:46 +00:00
// We support stb_sprintf which is much faster (see: https://github.com/nothings/stb/blob/master/stb_sprintf.h)
// You may set IMGUI_USE_STB_SPRINTF to use our default wrapper, or set IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS
// and setup the wrapper yourself. (FIXME-OPT: Some of our high-level operations such as ImGuiTextBuffer::appendfv() are
// designed using two-passes worst case, which probably could be improved using the stbsp_vsprintfcb() function.)
2019-01-08 17:23:28 +00:00
//#define IMGUI_USE_STB_SPRINTF
2019-01-08 14:28:33 +00:00
# ifdef IMGUI_USE_STB_SPRINTF
# define STB_SPRINTF_IMPLEMENTATION
2019-11-19 20:20:46 +00:00
# include "stb_sprintf.h"
2019-01-08 14:28:33 +00:00
# endif
2018-07-30 13:27:09 +00:00
# if defined(_MSC_VER) && !defined(vsnprintf)
# define vsnprintf _vsnprintf
# endif
2017-12-21 12:43:09 +00:00
int ImFormatString ( char * buf , size_t buf_size , const char * fmt , . . . )
2015-07-21 23:00:28 +00:00
{
va_list args ;
va_start ( args , fmt ) ;
2019-01-08 14:28:33 +00:00
# ifdef IMGUI_USE_STB_SPRINTF
int w = stbsp_vsnprintf ( buf , ( int ) buf_size , fmt , args ) ;
# else
2015-07-21 23:00:28 +00:00
int w = vsnprintf ( buf , buf_size , fmt , args ) ;
2019-01-08 14:28:33 +00:00
# endif
2015-07-21 23:00:28 +00:00
va_end ( args ) ;
2017-10-24 18:48:29 +00:00
if ( buf = = NULL )
return w ;
2017-12-21 12:43:09 +00:00
if ( w = = - 1 | | w > = ( int ) buf_size )
w = ( int ) buf_size - 1 ;
2016-08-23 14:55:06 +00:00
buf [ w ] = 0 ;
return w ;
2015-07-21 23:00:28 +00:00
}
2017-12-21 12:43:09 +00:00
int ImFormatStringV ( char * buf , size_t buf_size , const char * fmt , va_list args )
2015-07-21 23:00:28 +00:00
{
2019-01-08 14:28:33 +00:00
# ifdef IMGUI_USE_STB_SPRINTF
int w = stbsp_vsnprintf ( buf , ( int ) buf_size , fmt , args ) ;
# else
2015-07-21 23:00:28 +00:00
int w = vsnprintf ( buf , buf_size , fmt , args ) ;
2019-01-08 14:28:33 +00:00
# endif
2017-10-24 18:48:29 +00:00
if ( buf = = NULL )
return w ;
2017-12-21 12:43:09 +00:00
if ( w = = - 1 | | w > = ( int ) buf_size )
w = ( int ) buf_size - 1 ;
2016-08-23 14:55:06 +00:00
buf [ w ] = 0 ;
return w ;
2015-07-21 23:00:28 +00:00
}
2019-11-19 20:20:46 +00:00
# endif // #ifdef IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS
2015-07-21 23:00:28 +00:00
2019-01-21 14:13:54 +00:00
// 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:
2019-01-21 15:05:41 +00:00
// - avoid an unnecessary branch/memory tap, - keep the ImHashXXX functions usable by static constructors, - make it thread-safe.
2019-03-16 14:48:21 +00:00
static const ImU32 GCrc32LookupTable [ 256 ] =
2019-01-21 14:13:54 +00:00
{
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 ,
0x3B6E20C8 , 0x4C69105E , 0xD56041E4 , 0xA2677172 , 0x3C03E4D1 , 0x4B04D447 , 0xD20D85FD , 0xA50AB56B , 0x35B5A8FA , 0x42B2986C , 0xDBBBC9D6 , 0xACBCF940 , 0x32D86CE3 , 0x45DF5C75 , 0xDCD60DCF , 0xABD13D59 ,
0x26D930AC , 0x51DE003A , 0xC8D75180 , 0xBFD06116 , 0x21B4F4B5 , 0x56B3C423 , 0xCFBA9599 , 0xB8BDA50F , 0x2802B89E , 0x5F058808 , 0xC60CD9B2 , 0xB10BE924 , 0x2F6F7C87 , 0x58684C11 , 0xC1611DAB , 0xB6662D3D ,
0x76DC4190 , 0x01DB7106 , 0x98D220BC , 0xEFD5102A , 0x71B18589 , 0x06B6B51F , 0x9FBFE4A5 , 0xE8B8D433 , 0x7807C9A2 , 0x0F00F934 , 0x9609A88E , 0xE10E9818 , 0x7F6A0DBB , 0x086D3D2D , 0x91646C97 , 0xE6635C01 ,
0x6B6B51F4 , 0x1C6C6162 , 0x856530D8 , 0xF262004E , 0x6C0695ED , 0x1B01A57B , 0x8208F4C1 , 0xF50FC457 , 0x65B0D9C6 , 0x12B7E950 , 0x8BBEB8EA , 0xFCB9887C , 0x62DD1DDF , 0x15DA2D49 , 0x8CD37CF3 , 0xFBD44C65 ,
0x4DB26158 , 0x3AB551CE , 0xA3BC0074 , 0xD4BB30E2 , 0x4ADFA541 , 0x3DD895D7 , 0xA4D1C46D , 0xD3D6F4FB , 0x4369E96A , 0x346ED9FC , 0xAD678846 , 0xDA60B8D0 , 0x44042D73 , 0x33031DE5 , 0xAA0A4C5F , 0xDD0D7CC9 ,
0x5005713C , 0x270241AA , 0xBE0B1010 , 0xC90C2086 , 0x5768B525 , 0x206F85B3 , 0xB966D409 , 0xCE61E49F , 0x5EDEF90E , 0x29D9C998 , 0xB0D09822 , 0xC7D7A8B4 , 0x59B33D17 , 0x2EB40D81 , 0xB7BD5C3B , 0xC0BA6CAD ,
0xEDB88320 , 0x9ABFB3B6 , 0x03B6E20C , 0x74B1D29A , 0xEAD54739 , 0x9DD277AF , 0x04DB2615 , 0x73DC1683 , 0xE3630B12 , 0x94643B84 , 0x0D6D6A3E , 0x7A6A5AA8 , 0xE40ECF0B , 0x9309FF9D , 0x0A00AE27 , 0x7D079EB1 ,
0xF00F9344 , 0x8708A3D2 , 0x1E01F268 , 0x6906C2FE , 0xF762575D , 0x806567CB , 0x196C3671 , 0x6E6B06E7 , 0xFED41B76 , 0x89D32BE0 , 0x10DA7A5A , 0x67DD4ACC , 0xF9B9DF6F , 0x8EBEEFF9 , 0x17B7BE43 , 0x60B08ED5 ,
0xD6D6A3E8 , 0xA1D1937E , 0x38D8C2C4 , 0x4FDFF252 , 0xD1BB67F1 , 0xA6BC5767 , 0x3FB506DD , 0x48B2364B , 0xD80D2BDA , 0xAF0A1B4C , 0x36034AF6 , 0x41047A60 , 0xDF60EFC3 , 0xA867DF55 , 0x316E8EEF , 0x4669BE79 ,
0xCB61B38C , 0xBC66831A , 0x256FD2A0 , 0x5268E236 , 0xCC0C7795 , 0xBB0B4703 , 0x220216B9 , 0x5505262F , 0xC5BA3BBE , 0xB2BD0B28 , 0x2BB45A92 , 0x5CB36A04 , 0xC2D7FFA7 , 0xB5D0CF31 , 0x2CD99E8B , 0x5BDEAE1D ,
0x9B64C2B0 , 0xEC63F226 , 0x756AA39C , 0x026D930A , 0x9C0906A9 , 0xEB0E363F , 0x72076785 , 0x05005713 , 0x95BF4A82 , 0xE2B87A14 , 0x7BB12BAE , 0x0CB61B38 , 0x92D28E9B , 0xE5D5BE0D , 0x7CDCEFB7 , 0x0BDBDF21 ,
0x86D3D2D4 , 0xF1D4E242 , 0x68DDB3F8 , 0x1FDA836E , 0x81BE16CD , 0xF6B9265B , 0x6FB077E1 , 0x18B74777 , 0x88085AE6 , 0xFF0F6A70 , 0x66063BCA , 0x11010B5C , 0x8F659EFF , 0xF862AE69 , 0x616BFFD3 , 0x166CCF45 ,
0xA00AE278 , 0xD70DD2EE , 0x4E048354 , 0x3903B3C2 , 0xA7672661 , 0xD06016F7 , 0x4969474D , 0x3E6E77DB , 0xAED16A4A , 0xD9D65ADC , 0x40DF0B66 , 0x37D83BF0 , 0xA9BCAE53 , 0xDEBB9EC5 , 0x47B2CF7F , 0x30B5FFE9 ,
0xBDBDF21C , 0xCABAC28A , 0x53B39330 , 0x24B4A3A6 , 0xBAD03605 , 0xCDD70693 , 0x54DE5729 , 0x23D967BF , 0xB3667A2E , 0xC4614AB8 , 0x5D681B02 , 0x2A6F2B94 , 0xB40BBE37 , 0xC30C8EA1 , 0x5A05DF1B , 0x2D02EF8D ,
} ;
2019-01-21 15:05:41 +00:00
// Known size hash
// It is ok to call ImHashData on a string with known length but the ### operator won't be supported.
2015-07-21 23:00:28 +00:00
// FIXME-OPT: Replace with e.g. FNV1a hash? CRC32 pretty much randomly access 1KB. Need to do proper measurements.
2019-01-21 15:05:41 +00:00
ImU32 ImHashData ( const void * data_p , size_t data_size , ImU32 seed )
{
ImU32 crc = ~ seed ;
const unsigned char * data = ( const unsigned char * ) data_p ;
const ImU32 * crc32_lut = GCrc32LookupTable ;
while ( data_size - - ! = 0 )
crc = ( crc > > 8 ) ^ crc32_lut [ ( crc & 0xFF ) ^ * data + + ] ;
return ~ crc ;
}
// Zero-terminated string hash, with support for ### to reset back to seed value
// We support a syntax of "label###id" where only "###id" is included in the hash, and only "label" gets displayed.
// Because this syntax is rarely used we are optimizing for the common case.
// - 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.
2019-02-28 15:59:01 +00:00
ImU32 ImHashStr ( const char * data_p , size_t data_size , ImU32 seed )
2015-08-24 11:50:18 +00:00
{
2015-03-07 21:53:33 +00:00
seed = ~ seed ;
2015-08-24 11:50:18 +00:00
ImU32 crc = seed ;
2019-02-28 15:59:01 +00:00
const unsigned char * data = ( const unsigned char * ) data_p ;
2019-01-21 14:13:54 +00:00
const ImU32 * crc32_lut = GCrc32LookupTable ;
2019-01-21 15:05:41 +00:00
if ( data_size ! = 0 )
2014-12-30 15:38:28 +00:00
{
2019-01-21 15:05:41 +00:00
while ( data_size - - ! = 0 )
{
2019-02-28 15:59:01 +00:00
unsigned char c = * data + + ;
if ( c = = ' # ' & & data_size > = 2 & & data [ 0 ] = = ' # ' & & data [ 1 ] = = ' # ' )
2019-01-21 15:05:41 +00:00
crc = seed ;
crc = ( crc > > 8 ) ^ crc32_lut [ ( crc & 0xFF ) ^ c ] ;
}
2014-12-30 15:38:28 +00:00
}
else
{
2019-02-28 15:59:01 +00:00
while ( unsigned char c = * data + + )
2015-03-07 21:53:33 +00:00
{
2019-02-28 15:59:01 +00:00
if ( c = = ' # ' & & data [ 0 ] = = ' # ' & & data [ 1 ] = = ' # ' )
2015-03-07 21:53:33 +00:00
crc = seed ;
crc = ( crc > > 8 ) ^ crc32_lut [ ( crc & 0xFF ) ^ c ] ;
}
2014-12-30 15:38:28 +00:00
}
2015-08-24 11:50:18 +00:00
return ~ crc ;
}
2014-08-10 20:58:11 +00:00
2019-11-19 20:14:44 +00:00
//-----------------------------------------------------------------------------
// [SECTION] MISC HELPERS/UTILITIES (File functions)
//-----------------------------------------------------------------------------
// Default file functions
# ifndef IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS
ImFileHandle ImFileOpen ( const char * filename , const char * mode )
2018-09-06 09:09:55 +00:00
{
2019-10-29 20:47:43 +00:00
# if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) && !defined(__CYGWIN__) && !defined(__GNUC__)
2019-11-19 20:14:44 +00:00
// We need a fopen() wrapper because MSVC/Windows fopen doesn't handle UTF-8 filenames.
2018-09-06 09:09:55 +00:00
const int filename_wsize = ImTextCountCharsFromUtf8 ( filename , NULL ) + 1 ;
const int mode_wsize = ImTextCountCharsFromUtf8 ( mode , NULL ) + 1 ;
ImVector < ImWchar > buf ;
buf . resize ( filename_wsize + mode_wsize ) ;
ImTextStrFromUtf8 ( & buf [ 0 ] , filename_wsize , filename , NULL ) ;
ImTextStrFromUtf8 ( & buf [ filename_wsize ] , mode_wsize , mode , NULL ) ;
return _wfopen ( ( wchar_t * ) & buf [ 0 ] , ( wchar_t * ) & buf [ filename_wsize ] ) ;
# else
return fopen ( filename , mode ) ;
# endif
}
2019-11-20 09:40:14 +00:00
// We should in theory be using fseeko()/ftello() with off_t and _fseeki64()/_ftelli64() with __int64, waiting for the PR that does that in a very portable pre-C++11 zero-warnings way.
bool ImFileClose ( ImFileHandle f ) { return fclose ( f ) = = 0 ; }
ImU64 ImFileGetSize ( ImFileHandle f ) { long off = 0 , sz = 0 ; return ( ( off = ftell ( f ) ) ! = - 1 & & ! fseek ( f , 0 , SEEK_END ) & & ( sz = ftell ( f ) ) ! = - 1 & & ! fseek ( f , off , SEEK_SET ) ) ? ( ImU64 ) sz : ( ImU64 ) - 1 ; }
ImU64 ImFileRead ( void * data , ImU64 sz , ImU64 count , ImFileHandle f ) { return fread ( data , ( size_t ) sz , ( size_t ) count , f ) ; }
ImU64 ImFileWrite ( const void * data , ImU64 sz , ImU64 count , ImFileHandle f ) { return fwrite ( data , ( size_t ) sz , ( size_t ) count , f ) ; }
2019-11-19 20:14:44 +00:00
# endif // #ifndef IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS
2018-09-06 09:09:55 +00:00
2019-11-19 20:14:44 +00:00
// Helper: Load file content into memory
2019-04-05 18:20:08 +00:00
// Memory allocated with IM_ALLOC(), must be freed by user using IM_FREE() == ImGui::MemFree()
2019-11-19 20:14:44 +00:00
void * ImFileLoadToMemory ( const char * filename , const char * mode , size_t * out_file_size , int padding_bytes )
2018-09-06 09:09:55 +00:00
{
2019-11-19 20:14:44 +00:00
IM_ASSERT ( filename & & mode ) ;
2018-09-06 09:09:55 +00:00
if ( out_file_size )
* out_file_size = 0 ;
2019-11-19 20:14:44 +00:00
ImFileHandle f ;
if ( ( f = ImFileOpen ( filename , mode ) ) = = NULL )
2018-09-06 09:09:55 +00:00
return NULL ;
2019-11-20 09:40:14 +00:00
size_t file_size = ( size_t ) ImFileGetSize ( f ) ;
2019-11-19 20:14:44 +00:00
if ( file_size = = ( size_t ) - 1 )
2018-09-06 09:09:55 +00:00
{
2019-11-19 20:14:44 +00:00
ImFileClose ( f ) ;
2018-09-06 09:09:55 +00:00
return NULL ;
}
2019-04-05 18:20:08 +00:00
void * file_data = IM_ALLOC ( file_size + padding_bytes ) ;
2018-09-06 09:09:55 +00:00
if ( file_data = = NULL )
{
2019-11-19 20:14:44 +00:00
ImFileClose ( f ) ;
2018-09-06 09:09:55 +00:00
return NULL ;
}
2019-11-19 20:14:44 +00:00
if ( ImFileRead ( file_data , 1 , file_size , f ) ! = file_size )
2018-09-06 09:09:55 +00:00
{
2019-11-19 20:14:44 +00:00
ImFileClose ( f ) ;
2019-04-05 18:20:08 +00:00
IM_FREE ( file_data ) ;
2018-09-06 09:09:55 +00:00
return NULL ;
}
if ( padding_bytes > 0 )
memset ( ( void * ) ( ( ( char * ) file_data ) + file_size ) , 0 , ( size_t ) padding_bytes ) ;
2019-11-19 20:14:44 +00:00
ImFileClose ( f ) ;
2018-09-06 09:09:55 +00:00
if ( out_file_size )
* out_file_size = file_size ;
return file_data ;
}
2015-07-21 23:00:28 +00:00
//-----------------------------------------------------------------------------
2018-09-06 09:35:13 +00:00
// [SECTION] MISC HELPERS/UTILITIES (ImText* functions)
2015-07-21 23:00:28 +00:00
//-----------------------------------------------------------------------------
2019-11-20 10:58:25 +00:00
// Convert UTF-8 to 32-bit character, process single character input.
2015-07-21 23:00:28 +00:00
// Based on stb_from_utf8() from github.com/nothings/stb/
// We handle UTF-8 decoding error by skipping forward.
int ImTextCharFromUtf8 ( unsigned int * out_char , const char * in_text , const char * in_text_end )
2014-08-10 20:58:11 +00:00
{
2015-07-21 23:00:28 +00:00
unsigned int c = ( unsigned int ) - 1 ;
const unsigned char * str = ( const unsigned char * ) in_text ;
if ( ! ( * str & 0x80 ) )
{
c = ( unsigned int ) ( * str + + ) ;
* out_char = c ;
return 1 ;
}
2015-08-24 11:50:18 +00:00
if ( ( * str & 0xe0 ) = = 0xc0 )
2015-07-21 23:00:28 +00:00
{
2019-10-29 21:50:34 +00:00
* out_char = IM_UNICODE_CODEPOINT_INVALID ; // will be invalid but not end of string
2015-10-09 19:47:41 +00:00
if ( in_text_end & & in_text_end - ( const char * ) str < 2 ) return 1 ;
2015-08-27 12:44:31 +00:00
if ( * str < 0xc2 ) return 2 ;
2015-07-21 23:00:28 +00:00
c = ( unsigned int ) ( ( * str + + & 0x1f ) < < 6 ) ;
2015-08-27 12:44:31 +00:00
if ( ( * str & 0xc0 ) ! = 0x80 ) return 2 ;
2015-07-21 23:00:28 +00:00
c + = ( * str + + & 0x3f ) ;
* out_char = c ;
return 2 ;
}
2015-08-24 11:50:18 +00:00
if ( ( * str & 0xf0 ) = = 0xe0 )
2015-07-21 23:00:28 +00:00
{
2019-10-29 21:50:34 +00:00
* out_char = IM_UNICODE_CODEPOINT_INVALID ; // will be invalid but not end of string
2016-03-26 14:38:52 +00:00
if ( in_text_end & & in_text_end - ( const char * ) str < 3 ) return 1 ;
2015-08-27 12:44:31 +00:00
if ( * str = = 0xe0 & & ( str [ 1 ] < 0xa0 | | str [ 1 ] > 0xbf ) ) return 3 ;
if ( * str = = 0xed & & str [ 1 ] > 0x9f ) return 3 ; // str[1] < 0x80 is checked below
2015-07-21 23:00:28 +00:00
c = ( unsigned int ) ( ( * str + + & 0x0f ) < < 12 ) ;
2015-08-27 12:44:31 +00:00
if ( ( * str & 0xc0 ) ! = 0x80 ) return 3 ;
2015-07-21 23:00:28 +00:00
c + = ( unsigned int ) ( ( * str + + & 0x3f ) < < 6 ) ;
2015-08-27 12:44:31 +00:00
if ( ( * str & 0xc0 ) ! = 0x80 ) return 3 ;
2015-07-21 23:00:28 +00:00
c + = ( * str + + & 0x3f ) ;
* out_char = c ;
return 3 ;
}
2015-08-24 11:50:18 +00:00
if ( ( * str & 0xf8 ) = = 0xf0 )
2015-07-21 23:00:28 +00:00
{
2019-10-29 21:50:34 +00:00
* out_char = IM_UNICODE_CODEPOINT_INVALID ; // will be invalid but not end of string
2015-10-09 19:47:41 +00:00
if ( in_text_end & & in_text_end - ( const char * ) str < 4 ) return 1 ;
2015-08-27 12:44:31 +00:00
if ( * str > 0xf4 ) return 4 ;
if ( * str = = 0xf0 & & ( str [ 1 ] < 0x90 | | str [ 1 ] > 0xbf ) ) return 4 ;
if ( * str = = 0xf4 & & str [ 1 ] > 0x8f ) return 4 ; // str[1] < 0x80 is checked below
2015-07-21 23:00:28 +00:00
c = ( unsigned int ) ( ( * str + + & 0x07 ) < < 18 ) ;
2015-08-27 12:44:31 +00:00
if ( ( * str & 0xc0 ) ! = 0x80 ) return 4 ;
2015-07-21 23:00:28 +00:00
c + = ( unsigned int ) ( ( * str + + & 0x3f ) < < 12 ) ;
2015-08-27 12:44:31 +00:00
if ( ( * str & 0xc0 ) ! = 0x80 ) return 4 ;
2015-07-21 23:00:28 +00:00
c + = ( unsigned int ) ( ( * str + + & 0x3f ) < < 6 ) ;
2015-08-27 12:44:31 +00:00
if ( ( * str & 0xc0 ) ! = 0x80 ) return 4 ;
2015-07-21 23:00:28 +00:00
c + = ( * str + + & 0x3f ) ;
// utf-8 encodings of values used in surrogate pairs are invalid
2015-08-27 12:44:31 +00:00
if ( ( c & 0xFFFFF800 ) = = 0xD800 ) return 4 ;
2015-07-21 23:00:28 +00:00
* out_char = c ;
return 4 ;
}
* out_char = 0 ;
return 0 ;
2014-08-10 20:58:11 +00:00
}
2015-07-21 23:00:28 +00:00
int ImTextStrFromUtf8 ( ImWchar * buf , int buf_size , const char * in_text , const char * in_text_end , const char * * in_text_remaining )
2014-08-10 20:58:11 +00:00
{
2015-07-21 23:00:28 +00:00
ImWchar * buf_out = buf ;
ImWchar * buf_end = buf + buf_size ;
while ( buf_out < buf_end - 1 & & ( ! in_text_end | | in_text < in_text_end ) & & * in_text )
{
unsigned int c ;
in_text + = ImTextCharFromUtf8 ( & c , in_text , in_text_end ) ;
if ( c = = 0 )
break ;
2019-10-29 21:50:34 +00:00
if ( c < = IM_UNICODE_CODEPOINT_MAX ) // FIXME: Losing characters that don't fit in 2 bytes
2015-07-21 23:00:28 +00:00
* buf_out + + = ( ImWchar ) c ;
}
* buf_out = 0 ;
if ( in_text_remaining )
* in_text_remaining = in_text ;
return ( int ) ( buf_out - buf ) ;
}
int ImTextCountCharsFromUtf8 ( const char * in_text , const char * in_text_end )
{
int char_count = 0 ;
while ( ( ! in_text_end | | in_text < in_text_end ) & & * in_text )
{
unsigned int c ;
in_text + = ImTextCharFromUtf8 ( & c , in_text , in_text_end ) ;
if ( c = = 0 )
break ;
2019-10-29 21:50:34 +00:00
if ( c < = IM_UNICODE_CODEPOINT_MAX )
2015-07-21 23:00:28 +00:00
char_count + + ;
}
return char_count ;
}
// Based on stb_to_utf8() from github.com/nothings/stb/
static inline int ImTextCharToUtf8 ( char * buf , int buf_size , unsigned int c )
{
2015-08-24 11:50:18 +00:00
if ( c < 0x80 )
2015-07-21 23:00:28 +00:00
{
buf [ 0 ] = ( char ) c ;
return 1 ;
2015-08-24 11:50:18 +00:00
}
if ( c < 0x800 )
2015-07-21 23:00:28 +00:00
{
if ( buf_size < 2 ) return 0 ;
buf [ 0 ] = ( char ) ( 0xc0 + ( c > > 6 ) ) ;
buf [ 1 ] = ( char ) ( 0x80 + ( c & 0x3f ) ) ;
return 2 ;
}
if ( c > = 0xdc00 & & c < 0xe000 )
{
return 0 ;
2015-08-24 11:50:18 +00:00
}
if ( c > = 0xd800 & & c < 0xdc00 )
2015-07-21 23:00:28 +00:00
{
if ( buf_size < 4 ) return 0 ;
buf [ 0 ] = ( char ) ( 0xf0 + ( c > > 18 ) ) ;
buf [ 1 ] = ( char ) ( 0x80 + ( ( c > > 12 ) & 0x3f ) ) ;
buf [ 2 ] = ( char ) ( 0x80 + ( ( c > > 6 ) & 0x3f ) ) ;
buf [ 3 ] = ( char ) ( 0x80 + ( ( c ) & 0x3f ) ) ;
return 4 ;
}
//else if (c < 0x10000)
{
if ( buf_size < 3 ) return 0 ;
buf [ 0 ] = ( char ) ( 0xe0 + ( c > > 12 ) ) ;
buf [ 1 ] = ( char ) ( 0x80 + ( ( c > > 6 ) & 0x3f ) ) ;
buf [ 2 ] = ( char ) ( 0x80 + ( ( c ) & 0x3f ) ) ;
return 3 ;
}
}
2018-07-16 21:31:27 +00:00
// Not optimal but we very rarely use this function.
int ImTextCountUtf8BytesFromChar ( const char * in_text , const char * in_text_end )
{
unsigned int dummy = 0 ;
return ImTextCharFromUtf8 ( & dummy , in_text , in_text_end ) ;
}
2015-07-21 23:00:28 +00:00
static inline int ImTextCountUtf8BytesFromChar ( unsigned int c )
{
if ( c < 0x80 ) return 1 ;
if ( c < 0x800 ) return 2 ;
if ( c > = 0xdc00 & & c < 0xe000 ) return 0 ;
if ( c > = 0xd800 & & c < 0xdc00 ) return 4 ;
return 3 ;
}
int ImTextStrToUtf8 ( char * buf , int buf_size , const ImWchar * in_text , const ImWchar * in_text_end )
{
char * buf_out = buf ;
const char * buf_end = buf + buf_size ;
while ( buf_out < buf_end - 1 & & ( ! in_text_end | | in_text < in_text_end ) & & * in_text )
{
unsigned int c = ( unsigned int ) ( * in_text + + ) ;
if ( c < 0x80 )
* buf_out + + = ( char ) c ;
else
buf_out + = ImTextCharToUtf8 ( buf_out , ( int ) ( buf_end - buf_out - 1 ) , c ) ;
}
* buf_out = 0 ;
return ( int ) ( buf_out - buf ) ;
}
int ImTextCountUtf8BytesFromStr ( const ImWchar * in_text , const ImWchar * in_text_end )
{
int bytes_count = 0 ;
while ( ( ! in_text_end | | in_text < in_text_end ) & & * in_text )
{
unsigned int c = ( unsigned int ) ( * in_text + + ) ;
if ( c < 0x80 )
bytes_count + + ;
else
bytes_count + = ImTextCountUtf8BytesFromChar ( c ) ;
}
return bytes_count ;
2014-08-10 20:58:11 +00:00
}
2018-08-30 13:38:55 +00:00
//-----------------------------------------------------------------------------
2019-02-21 11:35:21 +00:00
// [SECTION] MISC HELPERS/UTILTIES (Color functions)
2018-09-06 09:35:13 +00:00
// Note: The Convert functions are early design which are not consistent with other API.
2018-08-30 13:38:55 +00:00
//-----------------------------------------------------------------------------
2015-08-26 20:18:08 +00:00
ImVec4 ImGui : : ColorConvertU32ToFloat4 ( ImU32 in )
{
float s = 1.0f / 255.0f ;
2016-08-05 09:04:05 +00:00
return ImVec4 (
( ( in > > IM_COL32_R_SHIFT ) & 0xFF ) * s ,
( ( in > > IM_COL32_G_SHIFT ) & 0xFF ) * s ,
( ( in > > IM_COL32_B_SHIFT ) & 0xFF ) * s ,
( ( in > > IM_COL32_A_SHIFT ) & 0xFF ) * s ) ;
2015-08-26 20:18:08 +00:00
}
2015-01-31 16:36:12 +00:00
ImU32 ImGui : : ColorConvertFloat4ToU32 ( const ImVec4 & in )
2014-08-10 20:58:11 +00:00
{
2015-10-18 15:24:44 +00:00
ImU32 out ;
2016-08-05 09:04:05 +00:00
out = ( ( ImU32 ) IM_F32_TO_INT8_SAT ( in . x ) ) < < IM_COL32_R_SHIFT ;
out | = ( ( ImU32 ) IM_F32_TO_INT8_SAT ( in . y ) ) < < IM_COL32_G_SHIFT ;
out | = ( ( ImU32 ) IM_F32_TO_INT8_SAT ( in . z ) ) < < IM_COL32_B_SHIFT ;
out | = ( ( ImU32 ) IM_F32_TO_INT8_SAT ( in . w ) ) < < IM_COL32_A_SHIFT ;
2014-08-19 11:09:13 +00:00
return out ;
2014-08-10 20:58:11 +00:00
}
// Convert rgb floats ([0-1],[0-1],[0-1]) to hsv floats ([0-1],[0-1],[0-1]), from Foley & van Dam p592
// Optimized http://lolengine.net/blog/2013/01/13/fast-rgb-to-hsv
2015-01-31 16:36:12 +00:00
void ImGui : : ColorConvertRGBtoHSV ( float r , float g , float b , float & out_h , float & out_s , float & out_v )
2014-08-10 20:58:11 +00:00
{
2014-08-19 11:09:13 +00:00
float K = 0.f ;
if ( g < b )
{
2017-08-28 11:27:12 +00:00
ImSwap ( g , b ) ;
2014-08-19 11:09:13 +00:00
K = - 1.f ;
}
if ( r < g )
{
2017-08-28 11:27:12 +00:00
ImSwap ( r , g ) ;
2014-08-19 11:09:13 +00:00
K = - 2.f / 6.f - K ;
}
2014-08-10 20:58:11 +00:00
2014-08-19 11:09:13 +00:00
const float chroma = r - ( g < b ? g : b ) ;
2018-05-13 18:02:47 +00:00
out_h = ImFabs ( K + ( g - b ) / ( 6.f * chroma + 1e-20 f ) ) ;
2014-08-19 11:09:13 +00:00
out_s = chroma / ( r + 1e-20 f ) ;
out_v = r ;
2014-08-10 20:58:11 +00:00
}
// Convert hsv floats ([0-1],[0-1],[0-1]) to rgb floats ([0-1],[0-1],[0-1]), from Foley & van Dam p593
// also http://en.wikipedia.org/wiki/HSL_and_HSV
2015-01-31 16:36:12 +00:00
void ImGui : : ColorConvertHSVtoRGB ( float h , float s , float v , float & out_r , float & out_g , float & out_b )
2015-08-24 11:50:18 +00:00
{
2014-08-19 11:09:13 +00:00
if ( s = = 0.0f )
{
// gray
out_r = out_g = out_b = v ;
return ;
}
2018-05-13 18:02:47 +00:00
h = ImFmod ( h , 1.0f ) / ( 60.0f / 360.0f ) ;
2014-08-19 11:09:13 +00:00
int i = ( int ) h ;
float f = h - ( float ) i ;
float p = v * ( 1.0f - s ) ;
float q = v * ( 1.0f - s * f ) ;
float t = v * ( 1.0f - s * ( 1.0f - f ) ) ;
switch ( i )
{
case 0 : out_r = v ; out_g = t ; out_b = p ; break ;
case 1 : out_r = q ; out_g = v ; out_b = p ; break ;
case 2 : out_r = p ; out_g = v ; out_b = t ; break ;
case 3 : out_r = p ; out_g = q ; out_b = v ; break ;
case 4 : out_r = t ; out_g = p ; out_b = v ; break ;
case 5 : default : out_r = v ; out_g = p ; out_b = q ; break ;
}
2014-08-10 20:58:11 +00:00
}
2015-07-21 23:00:28 +00:00
//-----------------------------------------------------------------------------
2018-09-06 09:35:13 +00:00
// [SECTION] ImGuiStorage
2015-07-21 23:00:28 +00:00
// Helper: Key->value storage
2017-11-15 21:37:43 +00:00
//-----------------------------------------------------------------------------
2014-08-10 20:58:11 +00:00
// std::lower_bound but without the bullshit
2019-07-12 09:54:22 +00:00
static ImGuiStorage : : ImGuiStoragePair * LowerBound ( ImVector < ImGuiStorage : : ImGuiStoragePair > & data , ImGuiID key )
2014-08-10 20:58:11 +00:00
{
2019-07-12 09:54:22 +00:00
ImGuiStorage : : ImGuiStoragePair * first = data . Data ;
ImGuiStorage : : ImGuiStoragePair * last = data . Data + data . Size ;
2017-11-07 13:05:48 +00:00
size_t count = ( size_t ) ( last - first ) ;
2014-08-19 11:09:13 +00:00
while ( count > 0 )
{
2017-11-07 13:05:48 +00:00
size_t count2 = count > > 1 ;
2019-07-12 09:54:22 +00:00
ImGuiStorage : : ImGuiStoragePair * mid = first + count2 ;
2014-08-19 11:09:13 +00:00
if ( mid - > key < key )
{
first = + + mid ;
count - = count2 + 1 ;
}
else
{
count = count2 ;
}
}
return first ;
2014-08-10 20:58:11 +00:00
}
2017-11-24 10:26:42 +00:00
// For quicker full rebuild of a storage (instead of an incremental one), you may add all your contents and then sort once.
void ImGuiStorage : : BuildSortByKey ( )
{
2018-05-17 12:12:37 +00:00
struct StaticFunc
{
static int IMGUI_CDECL PairCompareByID ( const void * lhs , const void * rhs )
2017-11-24 10:26:42 +00:00
{
// We can't just do a subtraction because qsort uses signed integers and subtracting our ID doesn't play well with that.
2019-07-12 09:54:22 +00:00
if ( ( ( const ImGuiStoragePair * ) lhs ) - > key > ( ( const ImGuiStoragePair * ) rhs ) - > key ) return + 1 ;
if ( ( ( const ImGuiStoragePair * ) lhs ) - > key < ( ( const ImGuiStoragePair * ) rhs ) - > key ) return - 1 ;
2017-11-24 10:26:42 +00:00
return 0 ;
}
} ;
if ( Data . Size > 1 )
2019-07-12 09:54:22 +00:00
ImQsort ( Data . Data , ( size_t ) Data . Size , sizeof ( ImGuiStoragePair ) , StaticFunc : : PairCompareByID ) ;
2017-11-24 10:26:42 +00:00
}
2016-07-31 14:48:06 +00:00
int ImGuiStorage : : GetInt ( ImGuiID key , int default_val ) const
2014-08-10 20:58:11 +00:00
{
2019-07-12 09:54:22 +00:00
ImGuiStoragePair * it = LowerBound ( const_cast < ImVector < ImGuiStoragePair > & > ( Data ) , key ) ;
2014-12-08 17:14:54 +00:00
if ( it = = Data . end ( ) | | it - > key ! = key )
return default_val ;
return it - > val_i ;
2014-08-10 20:58:11 +00:00
}
2016-07-31 14:48:06 +00:00
bool ImGuiStorage : : GetBool ( ImGuiID key , bool default_val ) const
2016-05-07 16:18:37 +00:00
{
return GetInt ( key , default_val ? 1 : 0 ) ! = 0 ;
}
2016-07-31 14:48:06 +00:00
float ImGuiStorage : : GetFloat ( ImGuiID key , float default_val ) const
2014-08-10 20:58:11 +00:00
{
2019-07-12 09:54:22 +00:00
ImGuiStoragePair * it = LowerBound ( const_cast < ImVector < ImGuiStoragePair > & > ( Data ) , key ) ;
2014-12-08 17:14:54 +00:00
if ( it = = Data . end ( ) | | it - > key ! = key )
2014-08-19 11:09:13 +00:00
return default_val ;
2014-12-08 17:14:54 +00:00
return it - > val_f ;
2014-08-10 20:58:11 +00:00
}
2015-01-29 09:22:32 +00:00
void * ImGuiStorage : : GetVoidPtr ( ImGuiID key ) const
2014-12-08 17:14:54 +00:00
{
2019-07-12 09:54:22 +00:00
ImGuiStoragePair * it = LowerBound ( const_cast < ImVector < ImGuiStoragePair > & > ( Data ) , key ) ;
2014-12-08 17:14:54 +00:00
if ( it = = Data . end ( ) | | it - > key ! = key )
2015-01-29 09:22:32 +00:00
return NULL ;
return it - > val_p ;
2014-12-08 17:14:54 +00:00
}
2015-01-29 09:22:32 +00:00
// 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 )
2014-12-08 17:14:54 +00:00
{
2019-07-12 09:54:22 +00:00
ImGuiStoragePair * it = LowerBound ( Data , key ) ;
2014-12-08 17:14:54 +00:00
if ( it = = Data . end ( ) | | it - > key ! = key )
2019-07-12 09:54:22 +00:00
it = Data . insert ( it , ImGuiStoragePair ( key , default_val ) ) ;
2015-01-29 09:22:32 +00:00
return & it - > val_i ;
2014-12-08 17:14:54 +00:00
}
2016-05-07 16:18:37 +00:00
bool * ImGuiStorage : : GetBoolRef ( ImGuiID key , bool default_val )
{
return ( bool * ) GetIntRef ( key , default_val ? 1 : 0 ) ;
}
2015-01-29 09:22:32 +00:00
float * ImGuiStorage : : GetFloatRef ( ImGuiID key , float default_val )
2015-01-28 20:31:22 +00:00
{
2019-07-12 09:54:22 +00:00
ImGuiStoragePair * it = LowerBound ( Data , key ) ;
2015-01-28 20:31:22 +00:00
if ( it = = Data . end ( ) | | it - > key ! = key )
2019-07-12 09:54:22 +00:00
it = Data . insert ( it , ImGuiStoragePair ( key , default_val ) ) ;
2015-01-29 09:22:32 +00:00
return & it - > val_f ;
2015-01-28 20:31:22 +00:00
}
2015-04-21 09:12:17 +00:00
void * * ImGuiStorage : : GetVoidPtrRef ( ImGuiID key , void * default_val )
{
2019-07-12 09:54:22 +00:00
ImGuiStoragePair * it = LowerBound ( Data , key ) ;
2015-04-21 09:12:17 +00:00
if ( it = = Data . end ( ) | | it - > key ! = key )
2019-07-12 09:54:22 +00:00
it = Data . insert ( it , ImGuiStoragePair ( key , default_val ) ) ;
2015-04-21 09:12:17 +00:00
return & it - > val_p ;
}
2015-05-11 14:57:02 +00:00
// 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)
2016-07-31 14:48:06 +00:00
void ImGuiStorage : : SetInt ( ImGuiID key , int val )
2014-08-10 20:58:11 +00:00
{
2019-07-12 09:54:22 +00:00
ImGuiStoragePair * it = LowerBound ( Data , key ) ;
2014-12-08 17:14:54 +00:00
if ( it = = Data . end ( ) | | it - > key ! = key )
2014-08-19 11:09:13 +00:00
{
2019-07-12 09:54:22 +00:00
Data . insert ( it , ImGuiStoragePair ( key , val ) ) ;
2014-12-08 17:14:54 +00:00
return ;
2014-08-19 11:09:13 +00:00
}
2014-12-08 17:14:54 +00:00
it - > val_i = val ;
}
2016-07-31 14:48:06 +00:00
void ImGuiStorage : : SetBool ( ImGuiID key , bool val )
2016-05-07 16:18:37 +00:00
{
SetInt ( key , val ? 1 : 0 ) ;
}
2016-07-31 14:48:06 +00:00
void ImGuiStorage : : SetFloat ( ImGuiID key , float val )
2014-12-08 17:14:54 +00:00
{
2019-07-12 09:54:22 +00:00
ImGuiStoragePair * it = LowerBound ( Data , key ) ;
2014-12-08 17:14:54 +00:00
if ( it = = Data . end ( ) | | it - > key ! = key )
2014-08-19 11:09:13 +00:00
{
2019-07-12 09:54:22 +00:00
Data . insert ( it , ImGuiStoragePair ( key , val ) ) ;
2014-12-08 17:14:54 +00:00
return ;
2014-08-19 11:09:13 +00:00
}
2014-12-08 17:14:54 +00:00
it - > val_f = val ;
2014-08-10 20:58:11 +00:00
}
2016-07-31 14:48:06 +00:00
void ImGuiStorage : : SetVoidPtr ( ImGuiID key , void * val )
2015-01-28 20:31:22 +00:00
{
2019-07-12 09:54:22 +00:00
ImGuiStoragePair * it = LowerBound ( Data , key ) ;
2015-01-28 20:31:22 +00:00
if ( it = = Data . end ( ) | | it - > key ! = key )
{
2019-07-12 09:54:22 +00:00
Data . insert ( it , ImGuiStoragePair ( key , val ) ) ;
2015-01-28 20:31:22 +00:00
return ;
}
it - > val_p = val ;
}
2014-08-10 20:58:11 +00:00
void ImGuiStorage : : SetAllInt ( int v )
{
2015-07-07 18:39:08 +00:00
for ( int i = 0 ; i < Data . Size ; i + + )
2014-12-08 17:14:54 +00:00
Data [ i ] . val_i = v ;
2014-08-10 20:58:11 +00:00
}
2015-07-21 23:00:28 +00:00
//-----------------------------------------------------------------------------
2018-09-06 09:35:13 +00:00
// [SECTION] ImGuiTextFilter
2014-08-10 20:58:11 +00:00
//-----------------------------------------------------------------------------
2014-08-25 16:19:04 +00:00
// Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
2015-02-15 13:50:04 +00:00
ImGuiTextFilter : : ImGuiTextFilter ( const char * default_filter )
2014-08-10 20:58:11 +00:00
{
2015-02-15 13:50:04 +00:00
if ( default_filter )
{
2016-06-25 11:54:34 +00:00
ImStrncpy ( InputBuf , default_filter , IM_ARRAYSIZE ( InputBuf ) ) ;
2015-02-15 13:50:04 +00:00
Build ( ) ;
}
else
{
InputBuf [ 0 ] = 0 ;
CountGrep = 0 ;
}
2014-08-10 20:58:11 +00:00
}
2015-09-14 12:03:20 +00:00
bool ImGuiTextFilter : : Draw ( const char * label , float width )
2014-08-10 20:58:11 +00:00
{
2015-08-14 03:51:34 +00:00
if ( width ! = 0.0f )
2019-04-18 16:29:28 +00:00
ImGui : : SetNextItemWidth ( width ) ;
2015-09-14 12:03:20 +00:00
bool value_changed = ImGui : : InputText ( label , InputBuf , IM_ARRAYSIZE ( InputBuf ) ) ;
if ( value_changed )
Build ( ) ;
return value_changed ;
2014-08-10 20:58:11 +00:00
}
2019-07-12 09:54:22 +00:00
void ImGuiTextFilter : : ImGuiTextRange : : split ( char separator , ImVector < ImGuiTextRange > * out ) const
2014-08-10 20:58:11 +00:00
{
2018-07-19 13:22:18 +00:00
out - > resize ( 0 ) ;
2014-08-19 11:09:13 +00:00
const char * wb = b ;
const char * we = wb ;
while ( we < e )
{
if ( * we = = separator )
{
2019-07-12 09:54:22 +00:00
out - > push_back ( ImGuiTextRange ( wb , we ) ) ;
2014-08-19 11:09:13 +00:00
wb = we + 1 ;
}
we + + ;
}
if ( wb ! = we )
2019-07-12 09:54:22 +00:00
out - > push_back ( ImGuiTextRange ( wb , we ) ) ;
2014-08-10 20:58:11 +00:00
}
void ImGuiTextFilter : : Build ( )
{
2014-08-19 11:09:13 +00:00
Filters . resize ( 0 ) ;
2019-07-12 09:54:22 +00:00
ImGuiTextRange input_range ( InputBuf , InputBuf + strlen ( InputBuf ) ) ;
2018-07-19 13:22:18 +00:00
input_range . split ( ' , ' , & Filters ) ;
2014-08-10 20:58:11 +00:00
2014-08-19 11:09:13 +00:00
CountGrep = 0 ;
2015-07-07 18:39:08 +00:00
for ( int i = 0 ; i ! = Filters . Size ; i + + )
2014-08-19 11:09:13 +00:00
{
2019-07-12 09:54:22 +00:00
ImGuiTextRange & f = Filters [ i ] ;
2018-07-19 13:22:18 +00:00
while ( f . b < f . e & & ImCharIsBlankA ( f . b [ 0 ] ) )
f . b + + ;
while ( f . e > f . b & & ImCharIsBlankA ( f . e [ - 1 ] ) )
f . e - - ;
if ( f . empty ( ) )
2014-08-19 11:09:13 +00:00
continue ;
2018-07-19 13:22:18 +00:00
if ( Filters [ i ] . b [ 0 ] ! = ' - ' )
2014-08-19 11:09:13 +00:00
CountGrep + = 1 ;
}
2014-08-10 20:58:11 +00:00
}
2015-08-14 03:25:32 +00:00
bool ImGuiTextFilter : : PassFilter ( const char * text , const char * text_end ) const
2014-08-10 20:58:11 +00:00
{
2014-08-19 11:09:13 +00:00
if ( Filters . empty ( ) )
return true ;
2015-08-14 03:25:32 +00:00
if ( text = = NULL )
text = " " ;
2014-08-19 11:09:13 +00:00
2015-07-07 18:39:08 +00:00
for ( int i = 0 ; i ! = Filters . Size ; i + + )
2014-08-19 11:09:13 +00:00
{
2019-07-12 09:54:22 +00:00
const ImGuiTextRange & f = Filters [ i ] ;
2014-08-19 11:09:13 +00:00
if ( f . empty ( ) )
continue ;
2018-07-19 13:22:18 +00:00
if ( f . b [ 0 ] = = ' - ' )
2014-08-19 11:09:13 +00:00
{
// Subtract
2019-07-12 09:54:22 +00:00
if ( ImStristr ( text , text_end , f . b + 1 , f . e ) ! = NULL )
2014-08-19 11:09:13 +00:00
return false ;
}
else
{
// Grep
2019-07-12 09:54:22 +00:00
if ( ImStristr ( text , text_end , f . b , f . e ) ! = NULL )
2014-08-19 11:09:13 +00:00
return true ;
}
}
// Implicit * grep
if ( CountGrep = = 0 )
return true ;
return false ;
2014-08-10 20:58:11 +00:00
}
2015-07-21 23:00:28 +00:00
//-----------------------------------------------------------------------------
2018-09-06 09:35:13 +00:00
// [SECTION] ImGuiTextBuffer
2015-07-21 23:00:28 +00:00
//-----------------------------------------------------------------------------
2015-08-24 11:50:18 +00:00
// On some platform vsnprintf() takes va_list by reference and modifies it.
2015-01-14 13:01:53 +00:00
// va_copy is the 'correct' way to copy a va_list but Visual Studio prior to 2013 doesn't have it.
# ifndef va_copy
2018-07-30 14:00:47 +00:00
# if defined(__GNUC__) || defined(__clang__)
# define va_copy(dest, src) __builtin_va_copy(dest, src)
# else
2015-01-14 13:01:53 +00:00
# define va_copy(dest, src) (dest = src)
# endif
2018-07-30 14:00:47 +00:00
# endif
2015-01-14 13:01:53 +00:00
2018-10-10 15:02:14 +00:00
char ImGuiTextBuffer : : EmptyString [ 1 ] = { 0 } ;
2019-01-20 21:21:26 +00:00
void ImGuiTextBuffer : : append ( const char * str , const char * str_end )
{
int len = str_end ? ( int ) ( str_end - str ) : ( int ) strlen ( str ) ;
// Add zero-terminator the first time
const int write_off = ( Buf . Size ! = 0 ) ? Buf . Size : 1 ;
const int needed_sz = write_off + len ;
if ( write_off + len > = Buf . Capacity )
{
int new_capacity = Buf . Capacity * 2 ;
Buf . reserve ( needed_sz > new_capacity ? needed_sz : new_capacity ) ;
}
Buf . resize ( needed_sz ) ;
memcpy ( & Buf [ write_off - 1 ] , str , ( size_t ) len ) ;
Buf [ write_off - 1 + len ] = 0 ;
}
void ImGuiTextBuffer : : appendf ( const char * fmt , . . . )
{
va_list args ;
va_start ( args , fmt ) ;
appendfv ( fmt , args ) ;
va_end ( args ) ;
}
2014-08-25 16:19:04 +00:00
// Helper: Text buffer for logging/accumulating text
2017-11-27 15:55:06 +00:00
void ImGuiTextBuffer : : appendfv ( const char * fmt , va_list args )
2014-08-10 20:58:11 +00:00
{
2015-01-14 13:01:53 +00:00
va_list args_copy ;
va_copy ( args_copy , args ) ;
2017-10-24 18:48:29 +00:00
int len = ImFormatStringV ( NULL , 0 , fmt , args ) ; // FIXME-OPT: could do a first pass write attempt, likely successful on first pass.
2014-08-19 11:09:13 +00:00
if ( len < = 0 )
2018-04-25 15:32:24 +00:00
{
va_end ( args_copy ) ;
2014-08-19 11:09:13 +00:00
return ;
2018-04-25 15:32:24 +00:00
}
2015-01-14 13:04:33 +00:00
2018-10-10 15:02:14 +00:00
// Add zero-terminator the first time
const int write_off = ( Buf . Size ! = 0 ) ? Buf . Size : 1 ;
2015-07-07 18:09:25 +00:00
const int needed_sz = write_off + len ;
2015-07-07 18:39:08 +00:00
if ( write_off + len > = Buf . Capacity )
2015-01-14 13:04:33 +00:00
{
2019-01-20 21:21:26 +00:00
int new_capacity = Buf . Capacity * 2 ;
Buf . reserve ( needed_sz > new_capacity ? needed_sz : new_capacity ) ;
2015-01-14 13:04:33 +00:00
}
2014-08-10 20:58:11 +00:00
2015-01-14 13:04:33 +00:00
Buf . resize ( needed_sz ) ;
2018-04-07 08:38:01 +00:00
ImFormatStringV ( & Buf [ write_off - 1 ] , ( size_t ) len + 1 , fmt , args_copy ) ;
2018-04-25 15:32:24 +00:00
va_end ( args_copy ) ;
2014-12-29 20:18:52 +00:00
}
2014-08-10 20:58:11 +00:00
2016-05-16 17:22:51 +00:00
//-----------------------------------------------------------------------------
2018-09-06 09:35:13 +00:00
// [SECTION] ImGuiListClipper
2019-06-27 16:03:19 +00:00
// 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)
2016-05-16 17:22:51 +00:00
//-----------------------------------------------------------------------------
2019-06-29 16:55:06 +00:00
// 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 ;
}
2016-05-16 17:22:51 +00:00
static void SetCursorPosYAndSetupDummyPrevLine ( float pos_y , float line_height )
{
2018-09-26 19:30:37 +00:00
// Set cursor position and a few other things so that SetScrollHereY() and Columns() can work when seeking cursor.
2018-05-17 12:12:37 +00:00
// FIXME: It is problematic that we have to do that here, because custom/equivalent end-user code would stumble on the same issue.
2018-03-12 10:03:27 +00:00
// The clipper should probably have a 4th step to display the last item in a regular manner.
2019-06-27 16:03:19 +00:00
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.
2019-06-10 19:43:05 +00:00
if ( ImGuiColumns * columns = window - > DC . CurrentColumns )
2019-06-27 16:03:19 +00:00
columns - > LineMinY = window - > DC . CursorPos . y ; // Setting this so that cell Y position are set properly
2016-05-16 17:22:51 +00:00
}
// Use case A: Begin() called from constructor with items_height<0, then called again from Sync() in StepNo 1
// Use case B: Begin() called from constructor with items_height>0
// 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 )
{
2019-06-27 16:03:19 +00:00
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = g . CurrentWindow ;
StartPosY = window - > DC . CursorPos . y ;
2016-05-16 17:22:51 +00:00
ItemsHeight = items_height ;
ItemsCount = count ;
StepNo = 0 ;
DisplayEnd = DisplayStart = - 1 ;
if ( ItemsHeight > 0.0f )
{
ImGui : : CalcListClipping ( ItemsCount , ItemsHeight , & DisplayStart , & DisplayEnd ) ; // calculate how many to clip/display
if ( DisplayStart > 0 )
SetCursorPosYAndSetupDummyPrevLine ( StartPosY + DisplayStart * ItemsHeight , ItemsHeight ) ; // advance cursor
StepNo = 2 ;
}
}
void ImGuiListClipper : : End ( )
{
if ( ItemsCount < 0 )
return ;
2016-05-16 17:25:42 +00:00
// In theory here we should assert that ImGui::GetCursorPosY() == StartPosY + DisplayEnd * ItemsHeight, but it feels saner to just seek at the end and not assert/crash the user.
2016-05-16 18:27:52 +00:00
if ( ItemsCount < INT_MAX )
2016-05-16 17:22:51 +00:00
SetCursorPosYAndSetupDummyPrevLine ( StartPosY + ItemsCount * ItemsHeight , ItemsHeight ) ; // advance cursor
ItemsCount = - 1 ;
StepNo = 3 ;
}
bool ImGuiListClipper : : Step ( )
{
2019-06-27 16:03:19 +00:00
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = g . CurrentWindow ;
if ( ItemsCount = = 0 | | window - > SkipItems )
2016-05-16 17:22:51 +00:00
{
2018-05-17 12:12:37 +00:00
ItemsCount = - 1 ;
return false ;
2016-05-16 17:22:51 +00:00
}
if ( StepNo = = 0 ) // Step 0: the clipper let you process the first element, regardless of it being visible or not, so we can measure the element height.
{
DisplayStart = 0 ;
DisplayEnd = 1 ;
2019-06-27 16:03:19 +00:00
StartPosY = window - > DC . CursorPos . y ;
2016-05-16 17:22:51 +00:00
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 ; }
2019-06-27 16:03:19 +00:00
float items_height = window - > DC . CursorPos . y - StartPosY ;
2016-05-16 17:22:51 +00:00
IM_ASSERT ( items_height > 0.0f ) ; // If this triggers, it means Item 0 hasn't moved the cursor vertically
2019-06-27 16:03:19 +00:00
Begin ( ItemsCount - 1 , items_height ) ;
2016-06-29 08:07:36 +00:00
DisplayStart + + ;
DisplayEnd + + ;
2016-05-16 17:22:51 +00:00
StepNo = 3 ;
return true ;
}
if ( StepNo = = 2 ) // Step 2: dummy step only required if an explicit items_height was passed to constructor or Begin() and user still call Step(). Does nothing and switch to Step 3.
{
IM_ASSERT ( DisplayStart > = 0 & & DisplayEnd > = 0 ) ;
StepNo = 3 ;
return true ;
}
if ( StepNo = = 3 ) // Step 3: the clipper validate that we have reached the expected Y position (corresponding to element DisplayEnd), advance the cursor to the end of the list and then returns 'false' to end the loop.
End ( ) ;
return false ;
}
2018-09-05 18:36:36 +00:00
//-----------------------------------------------------------------------------
2018-09-06 09:35:13 +00:00
// [SECTION] RENDER HELPERS
2019-12-17 12:19:36 +00:00
// Some of those (internal) functions are currently quite a legacy mess - their signature and behavior will change.
2018-09-05 18:36:36 +00:00
// Also see imgui_draw.cpp for some more which have been reworked to not rely on ImGui:: state.
//-----------------------------------------------------------------------------
2019-12-17 12:19:36 +00:00
ImU32 ImGui : : GetColorU32 ( ImGuiCol idx , float alpha_mul )
{
ImGuiStyle & style = GImGui - > Style ;
ImVec4 c = style . Colors [ idx ] ;
c . w * = style . Alpha * alpha_mul ;
return ColorConvertFloat4ToU32 ( c ) ;
}
ImU32 ImGui : : GetColorU32 ( const ImVec4 & col )
{
ImGuiStyle & style = GImGui - > Style ;
ImVec4 c = col ;
c . w * = style . Alpha ;
return ColorConvertFloat4ToU32 ( c ) ;
}
const ImVec4 & ImGui : : GetStyleColorVec4 ( ImGuiCol idx )
{
ImGuiStyle & style = GImGui - > Style ;
return style . Colors [ idx ] ;
}
ImU32 ImGui : : GetColorU32 ( ImU32 col )
{
ImGuiStyle & style = GImGui - > Style ;
if ( style . Alpha > = 1.0f )
return col ;
ImU32 a = ( col & IM_COL32_A_MASK ) > > IM_COL32_A_SHIFT ;
a = ( ImU32 ) ( a * style . Alpha ) ; // We don't need to clamp 0..255 because Style.Alpha is in 0..1 range.
return ( col & ~ IM_COL32_A_MASK ) | ( a < < IM_COL32_A_SHIFT ) ;
}
2018-09-05 18:36:36 +00:00
const char * ImGui : : FindRenderedTextEnd ( const char * text , const char * text_end )
{
const char * text_display_end = text ;
if ( ! text_end )
text_end = ( const char * ) - 1 ;
while ( text_display_end < text_end & & * text_display_end ! = ' \0 ' & & ( text_display_end [ 0 ] ! = ' # ' | | text_display_end [ 1 ] ! = ' # ' ) )
text_display_end + + ;
return text_display_end ;
}
// Internal ImGui functions to render text
// RenderText***() functions calls ImDrawList::AddText() calls ImBitmapFont::RenderText()
void ImGui : : RenderText ( ImVec2 pos , const char * text , const char * text_end , bool hide_text_after_hash )
{
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = g . CurrentWindow ;
// Hide anything after a '##' string
const char * text_display_end ;
if ( hide_text_after_hash )
{
text_display_end = FindRenderedTextEnd ( text , text_end ) ;
}
else
{
if ( ! text_end )
text_end = text + strlen ( text ) ; // FIXME-OPT
text_display_end = text_end ;
}
if ( text ! = text_display_end )
{
window - > DrawList - > AddText ( g . Font , g . FontSize , pos , GetColorU32 ( ImGuiCol_Text ) , text , text_display_end ) ;
if ( g . LogEnabled )
LogRenderedText ( & pos , text , text_display_end ) ;
}
}
void ImGui : : RenderTextWrapped ( ImVec2 pos , const char * text , const char * text_end , float wrap_width )
{
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = g . CurrentWindow ;
if ( ! text_end )
text_end = text + strlen ( text ) ; // FIXME-OPT
if ( text ! = text_end )
{
window - > DrawList - > AddText ( g . Font , g . FontSize , pos , GetColorU32 ( ImGuiCol_Text ) , text , text_end , wrap_width ) ;
if ( g . LogEnabled )
LogRenderedText ( & pos , text , text_end ) ;
}
}
// Default clip_rect uses (pos_min,pos_max)
// Handle clipping on CPU immediately (vs typically let the GPU clip the triangles that are overlapping the clipping rectangle edges)
2018-12-11 11:36:47 +00:00
void ImGui : : RenderTextClippedEx ( ImDrawList * draw_list , const ImVec2 & pos_min , const ImVec2 & pos_max , const char * text , const char * text_display_end , const ImVec2 * text_size_if_known , const ImVec2 & align , const ImRect * clip_rect )
2018-09-05 18:36:36 +00:00
{
// Perform CPU side clipping for single clipped element to avoid using scissor state
ImVec2 pos = pos_min ;
const ImVec2 text_size = text_size_if_known ? * text_size_if_known : CalcTextSize ( text , text_display_end , false , 0.0f ) ;
const ImVec2 * clip_min = clip_rect ? & clip_rect - > Min : & pos_min ;
const ImVec2 * clip_max = clip_rect ? & clip_rect - > Max : & pos_max ;
bool need_clipping = ( pos . x + text_size . x > = clip_max - > x ) | | ( pos . y + text_size . y > = clip_max - > y ) ;
if ( clip_rect ) // If we had no explicit clipping rectangle then pos==clip_min
need_clipping | = ( pos . x < clip_min - > x ) | | ( pos . y < clip_min - > y ) ;
// Align whole block. We should defer that to the better rendering function when we'll have support for individual line alignment.
if ( align . x > 0.0f ) pos . x = ImMax ( pos . x , pos . x + ( pos_max . x - pos . x - text_size . x ) * align . x ) ;
if ( align . y > 0.0f ) pos . y = ImMax ( pos . y , pos . y + ( pos_max . y - pos . y - text_size . y ) * align . y ) ;
// Render
if ( need_clipping )
{
ImVec4 fine_clip_rect ( clip_min - > x , clip_min - > y , clip_max - > x , clip_max - > y ) ;
2018-12-11 11:36:47 +00:00
draw_list - > AddText ( NULL , 0.0f , pos , GetColorU32 ( ImGuiCol_Text ) , text , text_display_end , 0.0f , & fine_clip_rect ) ;
2018-09-05 18:36:36 +00:00
}
else
{
2018-12-11 11:36:47 +00:00
draw_list - > AddText ( NULL , 0.0f , pos , GetColorU32 ( ImGuiCol_Text ) , text , text_display_end , 0.0f , NULL ) ;
2018-09-05 18:36:36 +00:00
}
2018-12-11 11:36:47 +00:00
}
void ImGui : : RenderTextClipped ( const ImVec2 & pos_min , const ImVec2 & pos_max , const char * text , const char * text_end , const ImVec2 * text_size_if_known , const ImVec2 & align , const ImRect * clip_rect )
{
// Hide anything after a '##' string
const char * text_display_end = FindRenderedTextEnd ( text , text_end ) ;
const int text_len = ( int ) ( text_display_end - text ) ;
if ( text_len = = 0 )
return ;
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = g . CurrentWindow ;
RenderTextClippedEx ( window - > DrawList , pos_min , pos_max , text , text_display_end , text_size_if_known , align , clip_rect ) ;
2018-09-05 18:36:36 +00:00
if ( g . LogEnabled )
2018-12-11 11:36:47 +00:00
LogRenderedText ( & pos_min , text , text_display_end ) ;
2018-09-05 18:36:36 +00:00
}
2019-06-11 12:02:46 +00:00
// Another overly complex function until we reorganize everything into a nice all-in-one helper.
2019-06-11 14:12:00 +00:00
// 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.
2019-09-17 09:33:18 +00:00
// 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.
2019-09-05 09:59:43 +00:00
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 )
2019-06-11 12:02:46 +00:00
{
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 ) ;
2019-09-17 09:11:14 +00:00
//draw_list->AddLine(ImVec2(pos_max.x, pos_min.y - 4), ImVec2(pos_max.x, pos_max.y + 4), IM_COL32(0, 0, 255, 255));
//draw_list->AddLine(ImVec2(ellipsis_max_x, pos_min.y-2), ImVec2(ellipsis_max_x, pos_max.y+2), IM_COL32(0, 255, 0, 255));
//draw_list->AddLine(ImVec2(clip_max_x, pos_min.y), ImVec2(clip_max_x, pos_max.y), IM_COL32(255, 0, 0, 255));
// FIXME: We could technically remove (last_glyph->AdvanceX - last_glyph->X1) from text_size.x here and save a few pixels.
2019-06-11 12:02:46 +00:00
if ( text_size . x > pos_max . x - pos_min . x )
{
2019-06-11 14:12:00 +00:00
// Hello wo...
// | | |
// min max ellipsis_max
// <-> this is generally some padding value
2019-06-11 12:02:46 +00:00
const ImFont * font = draw_list - > _Data - > Font ;
const float font_size = draw_list - > _Data - > FontSize ;
const char * text_end_ellipsis = NULL ;
2019-06-11 14:12:00 +00:00
2019-09-17 08:00:28 +00:00
ImWchar ellipsis_char = font - > EllipsisChar ;
int ellipsis_char_count = 1 ;
if ( ellipsis_char = = ( ImWchar ) - 1 )
2019-09-05 09:59:43 +00:00
{
2019-09-17 08:00:28 +00:00
ellipsis_char = ( ImWchar ) ' . ' ;
ellipsis_char_count = 3 ;
2019-09-05 09:59:43 +00:00
}
2019-09-17 08:00:28 +00:00
const ImFontGlyph * glyph = font - > FindGlyph ( ellipsis_char ) ;
2019-09-05 09:59:43 +00:00
2019-09-17 08:00:28 +00:00
float ellipsis_glyph_width = glyph - > X1 ; // Width of the glyph with no padding on either side
float ellipsis_total_width = ellipsis_glyph_width ; // Full width of entire ellipsis
2019-10-15 13:20:27 +00:00
2019-09-17 08:00:28 +00:00
if ( ellipsis_char_count > 1 )
2019-09-05 09:59:43 +00:00
{
// Full ellipsis size without free spacing after it.
2019-09-17 08:00:28 +00:00
const float spacing_between_dots = 1.0f * ( draw_list - > _Data - > FontSize / font - > FontSize ) ;
ellipsis_glyph_width = glyph - > X1 - glyph - > X0 + spacing_between_dots ;
ellipsis_total_width = ellipsis_glyph_width * ( float ) ellipsis_char_count - spacing_between_dots ;
2019-09-05 09:59:43 +00:00
}
2019-10-15 13:20:27 +00:00
2019-09-17 09:11:14 +00:00
// We can now claim the space between pos_max.x and ellipsis_max.x
const float text_avail_width = ImMax ( ( ImMax ( pos_max . x , ellipsis_max_x ) - ellipsis_total_width ) - pos_min . x , 1.0f ) ;
2019-09-17 08:00:28 +00:00
float text_size_clipped_x = font - > CalcTextSizeA ( font_size , text_avail_width , 0.0f , text , text_end_full , & text_end_ellipsis ) . x ;
2019-06-11 14:12:00 +00:00
if ( text = = text_end_ellipsis & & text_end_ellipsis < text_end_full )
2019-06-11 12:02:46 +00:00
{
2019-06-11 14:12:00 +00:00
// Always display at least 1 character if there's no room for character + ellipsis
2019-06-11 12:02:46 +00:00
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 ;
}
2019-06-11 14:12:00 +00:00
while ( text_end_ellipsis > text & & ImCharIsBlankA ( text_end_ellipsis [ - 1 ] ) )
2019-06-11 12:02:46 +00:00
{
2019-09-17 08:00:28 +00:00
// Trim trailing space before ellipsis (FIXME: Supporting non-ascii blanks would be nice, for this we need a function to backtrack in UTF-8 text)
2019-06-11 12:02:46 +00:00
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
}
2019-09-17 09:11:14 +00:00
// Render text, render ellipsis
2019-06-11 12:02:46 +00:00
RenderTextClippedEx ( draw_list , pos_min , ImVec2 ( clip_max_x , pos_max . y ) , text , text_end_ellipsis , & text_size , ImVec2 ( 0.0f , 0.0f ) ) ;
2019-09-17 09:11:14 +00:00
float ellipsis_x = pos_min . x + text_size_clipped_x ;
if ( ellipsis_x + ellipsis_total_width < = ellipsis_max_x )
2019-09-17 08:00:28 +00:00
for ( int i = 0 ; i < ellipsis_char_count ; i + + )
2019-09-05 09:59:43 +00:00
{
2019-09-17 08:00:28 +00:00
font - > RenderChar ( draw_list , font_size , ImVec2 ( ellipsis_x , pos_min . y ) , GetColorU32 ( ImGuiCol_Text ) , ellipsis_char ) ;
2019-09-05 09:59:43 +00:00
ellipsis_x + = ellipsis_glyph_width ;
}
2019-06-11 12:02:46 +00:00
}
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 ) ;
}
2018-09-05 18:36:36 +00:00
// 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 )
{
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = g . CurrentWindow ;
window - > DrawList - > AddRectFilled ( p_min , p_max , fill_col , rounding ) ;
const float border_size = g . Style . FrameBorderSize ;
if ( border & & border_size > 0.0f )
{
window - > DrawList - > AddRect ( p_min + ImVec2 ( 1 , 1 ) , p_max + ImVec2 ( 1 , 1 ) , GetColorU32 ( ImGuiCol_BorderShadow ) , rounding , ImDrawCornerFlags_All , border_size ) ;
window - > DrawList - > AddRect ( p_min , p_max , GetColorU32 ( ImGuiCol_Border ) , rounding , ImDrawCornerFlags_All , border_size ) ;
}
}
void ImGui : : RenderFrameBorder ( ImVec2 p_min , ImVec2 p_max , float rounding )
{
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = g . CurrentWindow ;
const float border_size = g . Style . FrameBorderSize ;
if ( border_size > 0.0f )
{
window - > DrawList - > AddRect ( p_min + ImVec2 ( 1 , 1 ) , p_max + ImVec2 ( 1 , 1 ) , GetColorU32 ( ImGuiCol_BorderShadow ) , rounding , ImDrawCornerFlags_All , border_size ) ;
window - > DrawList - > AddRect ( p_min , p_max , GetColorU32 ( ImGuiCol_Border ) , rounding , ImDrawCornerFlags_All , border_size ) ;
}
}
// 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
2019-05-20 09:45:32 +00:00
void ImGui : : RenderArrow ( ImDrawList * draw_list , ImVec2 pos , ImU32 col , ImGuiDir dir , float scale )
2018-09-05 18:36:36 +00:00
{
2019-05-20 09:45:32 +00:00
const float h = draw_list - > _Data - > FontSize * 1.00f ;
2018-09-05 18:36:36 +00:00
float r = h * 0.40f * scale ;
2019-05-20 09:45:32 +00:00
ImVec2 center = pos + ImVec2 ( h * 0.50f , h * 0.50f * scale ) ;
2018-09-05 18:36:36 +00:00
ImVec2 a , b , c ;
switch ( dir )
{
case ImGuiDir_Up :
case ImGuiDir_Down :
if ( dir = = ImGuiDir_Up ) r = - r ;
a = ImVec2 ( + 0.000f , + 0.750f ) * r ;
b = ImVec2 ( - 0.866f , - 0.750f ) * r ;
c = ImVec2 ( + 0.866f , - 0.750f ) * r ;
break ;
case ImGuiDir_Left :
case ImGuiDir_Right :
if ( dir = = ImGuiDir_Left ) r = - r ;
a = ImVec2 ( + 0.750f , + 0.000f ) * r ;
b = ImVec2 ( - 0.750f , + 0.866f ) * r ;
c = ImVec2 ( - 0.750f , - 0.866f ) * r ;
break ;
case ImGuiDir_None :
case ImGuiDir_COUNT :
IM_ASSERT ( 0 ) ;
break ;
}
2019-05-20 09:45:32 +00:00
draw_list - > AddTriangleFilled ( center + a , center + b , center + c , col ) ;
2018-09-05 18:36:36 +00:00
}
2019-05-20 09:45:32 +00:00
void ImGui : : RenderBullet ( ImDrawList * draw_list , ImVec2 pos , ImU32 col )
2018-09-05 18:36:36 +00:00
{
2019-05-20 09:45:32 +00:00
draw_list - > AddCircleFilled ( pos , draw_list - > _Data - > FontSize * 0.20f , col , 8 ) ;
2018-09-05 18:36:36 +00:00
}
void ImGui : : RenderCheckMark ( ImVec2 pos , ImU32 col , float sz )
{
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = g . CurrentWindow ;
float thickness = ImMax ( sz / 5.0f , 1.0f ) ;
sz - = thickness * 0.5f ;
pos + = ImVec2 ( thickness * 0.25f , thickness * 0.25f ) ;
float third = sz / 3.0f ;
float bx = pos . x + third ;
float by = pos . y + sz - third * 0.5f ;
window - > DrawList - > PathLineTo ( ImVec2 ( bx - third , by - third ) ) ;
window - > DrawList - > PathLineTo ( ImVec2 ( bx , by ) ) ;
window - > DrawList - > PathLineTo ( ImVec2 ( bx + third * 2 , by - third * 2 ) ) ;
window - > DrawList - > PathStroke ( col , false , thickness ) ;
}
void ImGui : : RenderNavHighlight ( const ImRect & bb , ImGuiID id , ImGuiNavHighlightFlags flags )
{
ImGuiContext & g = * GImGui ;
if ( id ! = g . NavId )
return ;
if ( g . NavDisableHighlight & & ! ( flags & ImGuiNavHighlightFlags_AlwaysDraw ) )
return ;
2018-11-15 15:43:05 +00:00
ImGuiWindow * window = g . CurrentWindow ;
2018-09-05 18:36:36 +00:00
if ( window - > DC . NavHideHighlightOneFrame )
return ;
float rounding = ( flags & ImGuiNavHighlightFlags_NoRounding ) ? 0.0f : g . Style . FrameRounding ;
ImRect display_rect = bb ;
display_rect . ClipWith ( window - > ClipRect ) ;
if ( flags & ImGuiNavHighlightFlags_TypeDefault )
{
const float THICKNESS = 2.0f ;
const float DISTANCE = 3.0f + THICKNESS * 0.5f ;
display_rect . Expand ( ImVec2 ( DISTANCE , DISTANCE ) ) ;
bool fully_visible = window - > ClipRect . Contains ( display_rect ) ;
if ( ! fully_visible )
window - > DrawList - > PushClipRect ( display_rect . Min , display_rect . Max ) ;
window - > DrawList - > AddRect ( display_rect . Min + ImVec2 ( THICKNESS * 0.5f , THICKNESS * 0.5f ) , display_rect . Max - ImVec2 ( THICKNESS * 0.5f , THICKNESS * 0.5f ) , GetColorU32 ( ImGuiCol_NavHighlight ) , rounding , ImDrawCornerFlags_All , THICKNESS ) ;
if ( ! fully_visible )
window - > DrawList - > PopClipRect ( ) ;
}
if ( flags & ImGuiNavHighlightFlags_TypeThin )
{
window - > DrawList - > AddRect ( display_rect . Min , display_rect . Max , GetColorU32 ( ImGuiCol_NavHighlight ) , rounding , ~ 0 , 1.0f ) ;
}
}
2015-07-21 23:00:28 +00:00
//-----------------------------------------------------------------------------
2018-09-06 09:35:13 +00:00
// [SECTION] MAIN CODE (most of the code! lots of stuff, needs tidying up!)
2014-08-10 20:58:11 +00:00
//-----------------------------------------------------------------------------
2018-08-31 07:50:14 +00:00
// ImGuiWindow is mostly a dumb struct. It merely has a constructor and a few helper methods
2017-12-21 17:50:27 +00:00
ImGuiWindow : : ImGuiWindow ( ImGuiContext * context , const char * name )
2018-04-11 10:43:38 +00:00
: DrawListInst ( & context - > DrawListSharedData )
2014-08-10 20:58:11 +00:00
{
2014-08-31 10:28:21 +00:00
Name = ImStrdup ( name ) ;
2019-04-19 17:48:51 +00:00
ID = ImHashStr ( name ) ;
2015-03-07 23:52:26 +00:00
IDStack . push_back ( ID ) ;
2018-12-11 10:58:15 +00:00
Flags = ImGuiWindowFlags_None ;
2018-04-25 13:24:26 +00:00
Pos = ImVec2 ( 0.0f , 0.0f ) ;
2014-12-10 19:22:30 +00:00
Size = SizeFull = ImVec2 ( 0.0f , 0.0f ) ;
2019-06-03 14:55:48 +00:00
ContentSize = ContentSizeExplicit = ImVec2 ( 0.0f , 0.0f ) ;
2015-07-02 00:55:42 +00:00
WindowPadding = ImVec2 ( 0.0f , 0.0f ) ;
2017-11-18 18:02:02 +00:00
WindowRounding = 0.0f ;
WindowBorderSize = 0.0f ;
2019-01-07 21:46:42 +00:00
NameBufLen = ( int ) strlen ( name ) + 1 ;
2016-07-30 08:56:52 +00:00
MoveId = GetID ( " #MOVE " ) ;
2017-08-22 11:26:21 +00:00
ChildId = 0 ;
2015-08-30 14:08:13 +00:00
Scroll = ImVec2 ( 0.0f , 0.0f ) ;
2015-08-30 17:33:38 +00:00
ScrollTarget = ImVec2 ( FLT_MAX , FLT_MAX ) ;
ScrollTargetCenterRatio = ImVec2 ( 0.5f , 0.5f ) ;
2015-08-30 15:37:56 +00:00
ScrollbarSizes = ImVec2 ( 0.0f , 0.0f ) ;
2018-04-25 14:38:13 +00:00
ScrollbarX = ScrollbarY = false ;
2015-05-02 12:20:50 +00:00
Active = WasActive = false ;
2017-11-18 23:07:38 +00:00
WriteAccessed = false ;
2014-08-19 11:09:13 +00:00
Collapsed = false ;
2018-08-05 16:13:24 +00:00
WantCollapseToggle = false ;
2014-08-19 11:09:13 +00:00
SkipItems = false ;
2017-09-01 19:55:59 +00:00
Appearing = false ;
2018-06-27 15:21:59 +00:00
Hidden = false ;
2018-06-23 18:08:19 +00:00
HasCloseButton = false ;
2019-02-01 09:26:08 +00:00
ResizeBorderHeld = - 1 ;
2018-09-05 09:52:48 +00:00
BeginCount = 0 ;
2017-12-12 22:36:25 +00:00
BeginOrderWithinParent = - 1 ;
BeginOrderWithinContext = - 1 ;
2016-06-12 20:27:15 +00:00
PopupId = 0 ;
2015-06-25 02:08:08 +00:00
AutoFitFramesX = AutoFitFramesY = - 1 ;
2016-07-31 11:05:13 +00:00
AutoFitChildAxises = 0x00 ;
2019-09-23 13:31:05 +00:00
AutoFitOnlyGrows = false ;
2017-12-07 12:26:56 +00:00
AutoPosLastDirection = ImGuiDir_None ;
2019-03-28 14:41:49 +00:00
HiddenFramesCanSkipItems = HiddenFramesCannotSkipItems = 0 ;
2017-08-11 05:36:28 +00:00
SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = ImGuiCond_Always | ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing ;
2017-09-25 16:25:43 +00:00
SetWindowPosVal = SetWindowPosPivot = ImVec2 ( FLT_MAX , FLT_MAX ) ;
2014-12-10 19:22:30 +00:00
2019-09-30 13:16:30 +00:00
InnerRect = ImRect ( 0.0f , 0.0f , 0.0f , 0.0f ) ; // Clear so the InnerRect.GetSize() code in Begin() doesn't lead to overflow even if the result isn't used.
2015-10-18 15:57:10 +00:00
LastFrameActive = - 1 ;
2019-06-30 10:48:19 +00:00
LastTimeActive = - 1.0f ;
2014-08-19 11:09:13 +00:00
ItemWidthDefault = 0.0f ;
2014-09-24 13:03:42 +00:00
FontWindowScale = 1.0f ;
2019-11-07 15:05:03 +00:00
SettingsOffset = - 1 ;
2014-08-10 20:58:11 +00:00
2018-04-11 10:43:38 +00:00
DrawList = & DrawListInst ;
2015-07-08 02:17:07 +00:00
DrawList - > _OwnerName = Name ;
2016-07-31 10:55:23 +00:00
ParentWindow = NULL ;
2015-02-22 12:05:38 +00:00
RootWindow = NULL ;
2018-02-08 22:11:51 +00:00
RootWindowForTitleBarHighlight = NULL ;
RootWindowForNav = NULL ;
2018-01-29 21:15:55 +00:00
NavLastIds [ 0 ] = NavLastIds [ 1 ] = 0 ;
NavRectRel [ 0 ] = NavRectRel [ 1 ] = ImRect ( ) ;
2018-01-31 23:50:42 +00:00
NavLastChildNavWindow = NULL ;
2019-06-30 10:48:19 +00:00
MemoryCompacted = false ;
MemoryDrawListIdxCapacity = MemoryDrawListVtxCapacity = 0 ;
2014-08-10 20:58:11 +00:00
}
ImGuiWindow : : ~ ImGuiWindow ( )
{
2018-04-11 10:43:38 +00:00
IM_ASSERT ( DrawList = = & DrawListInst ) ;
2017-12-23 15:24:33 +00:00
IM_DELETE ( Name ) ;
2018-01-02 15:46:20 +00:00
for ( int i = 0 ; i ! = ColumnsStorage . Size ; i + + )
2019-04-16 09:58:17 +00:00
ColumnsStorage [ i ] . ~ ImGuiColumns ( ) ;
2014-08-10 20:58:11 +00:00
}
2015-04-13 13:45:27 +00:00
ImGuiID ImGuiWindow : : GetID ( const char * str , const char * str_end )
2014-08-10 20:58:11 +00:00
{
2015-03-07 23:52:26 +00:00
ImGuiID seed = IDStack . back ( ) ;
2019-01-21 15:05:41 +00:00
ImGuiID id = ImHashStr ( str , str_end ? ( str_end - str ) : 0 , seed ) ;
2015-08-02 03:57:24 +00:00
ImGui : : KeepAliveID ( id ) ;
2014-08-19 11:09:13 +00:00
return id ;
2014-08-10 20:58:11 +00:00
}
ImGuiID ImGuiWindow : : GetID ( const void * ptr )
{
2015-03-07 23:52:26 +00:00
ImGuiID seed = IDStack . back ( ) ;
2019-01-21 15:05:41 +00:00
ImGuiID id = ImHashData ( & ptr , sizeof ( void * ) , seed ) ;
2015-08-02 03:57:24 +00:00
ImGui : : KeepAliveID ( id ) ;
2014-08-19 11:09:13 +00:00
return id ;
2014-08-10 20:58:11 +00:00
}
2019-06-06 14:36:26 +00:00
ImGuiID ImGuiWindow : : GetID ( int n )
{
ImGuiID seed = IDStack . back ( ) ;
ImGuiID id = ImHashData ( & n , sizeof ( n ) , seed ) ;
ImGui : : KeepAliveID ( id ) ;
return id ;
}
2016-07-12 23:18:59 +00:00
ImGuiID ImGuiWindow : : GetIDNoKeepAlive ( const char * str , const char * str_end )
{
ImGuiID seed = IDStack . back ( ) ;
2019-01-21 15:05:41 +00:00
return ImHashStr ( str , str_end ? ( str_end - str ) : 0 , seed ) ;
2016-07-12 23:18:59 +00:00
}
2018-07-31 15:26:42 +00:00
ImGuiID ImGuiWindow : : GetIDNoKeepAlive ( const void * ptr )
{
ImGuiID seed = IDStack . back ( ) ;
2019-01-21 15:05:41 +00:00
return ImHashData ( & ptr , sizeof ( void * ) , seed ) ;
2018-07-31 15:26:42 +00:00
}
2019-06-06 14:36:26 +00:00
ImGuiID ImGuiWindow : : GetIDNoKeepAlive ( int n )
{
ImGuiID seed = IDStack . back ( ) ;
return ImHashData ( & n , sizeof ( n ) , seed ) ;
}
2017-10-29 22:14:17 +00:00
// This is only used in rare/specific situations to manufacture an ID out of nowhere.
2017-10-29 22:10:44 +00:00
ImGuiID ImGuiWindow : : GetIDFromRectangle ( const ImRect & r_abs )
{
ImGuiID seed = IDStack . back ( ) ;
const int r_rel [ 4 ] = { ( int ) ( r_abs . Min . x - Pos . x ) , ( int ) ( r_abs . Min . y - Pos . y ) , ( int ) ( r_abs . Max . x - Pos . x ) , ( int ) ( r_abs . Max . y - Pos . y ) } ;
2019-01-21 15:05:41 +00:00
ImGuiID id = ImHashData ( & r_rel , sizeof ( r_rel ) , seed ) ;
2017-10-29 22:10:44 +00:00
ImGui : : KeepAliveID ( id ) ;
return id ;
}
2015-07-22 02:06:34 +00:00
static void SetCurrentWindow ( ImGuiWindow * window )
2015-07-21 23:00:28 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2015-07-21 23:00:28 +00:00
g . CurrentWindow = window ;
if ( window )
2017-12-22 19:19:48 +00:00
g . FontSize = g . DrawListSharedData . FontSize = window - > CalcFontSize ( ) ;
2015-07-21 23:00:28 +00:00
}
2019-06-30 10:48:19 +00:00
// 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 ;
}
2018-08-28 20:52:51 +00:00
void ImGui : : SetNavID ( ImGuiID id , int nav_layer )
2017-10-13 11:07:45 +00:00
{
ImGuiContext & g = * GImGui ;
IM_ASSERT ( g . NavWindow ) ;
IM_ASSERT ( nav_layer = = 0 | | nav_layer = = 1 ) ;
g . NavId = id ;
2018-01-31 23:50:42 +00:00
g . NavWindow - > NavLastIds [ nav_layer ] = id ;
2017-10-13 11:07:45 +00:00
}
2018-08-28 20:52:51 +00:00
void ImGui : : SetNavIDWithRectRel ( ImGuiID id , int nav_layer , const ImRect & rect_rel )
2017-10-13 11:07:45 +00:00
{
ImGuiContext & g = * GImGui ;
SetNavID ( id , nav_layer ) ;
g . NavWindow - > NavRectRel [ nav_layer ] = rect_rel ;
g . NavMousePosDirty = true ;
g . NavDisableHighlight = false ;
g . NavDisableMouseHover = true ;
}
2017-10-13 11:23:21 +00:00
void ImGui : : SetActiveID ( ImGuiID id , ImGuiWindow * window )
2015-08-06 14:11:33 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2016-07-16 08:36:09 +00:00
g . ActiveIdIsJustActivated = ( g . ActiveId ! = id ) ;
2017-10-29 22:46:32 +00:00
if ( g . ActiveIdIsJustActivated )
2018-01-05 14:33:24 +00:00
{
2017-10-29 22:46:32 +00:00
g . ActiveIdTimer = 0.0f ;
2019-05-13 16:15:39 +00:00
g . ActiveIdHasBeenPressedBefore = false ;
g . ActiveIdHasBeenEditedBefore = false ;
2018-01-05 14:33:24 +00:00
if ( id ! = 0 )
{
g . LastActiveId = id ;
g . LastActiveIdTimer = 0.0f ;
}
}
2015-08-24 11:50:18 +00:00
g . ActiveId = id ;
2015-12-03 21:30:17 +00:00
g . ActiveIdAllowOverlap = false ;
2015-08-06 14:11:33 +00:00
g . ActiveIdWindow = window ;
2019-05-13 17:05:41 +00:00
g . ActiveIdHasBeenEditedThisFrame = false ;
2016-07-19 22:02:59 +00:00
if ( id )
{
2018-08-16 20:33:16 +00:00
g . ActiveIdIsAlive = id ;
2017-10-13 20:33:06 +00:00
g . ActiveIdSource = ( g . NavActivateId = = id | | g . NavInputId = = id | | g . NavJustTabbedId = = id | | g . NavJustMovedToId = = id ) ? ImGuiInputSource_Nav : ImGuiInputSource_Mouse ;
2017-10-11 18:29:53 +00:00
}
2019-10-02 09:38:30 +00:00
// Clear declaration of inputs claimed by the widget
// (Please note that this is WIP and not all keys/inputs are thoroughly declared by all widgets yet)
g . ActiveIdUsingNavDirMask = 0x00 ;
g . ActiveIdUsingNavInputMask = 0x00 ;
g . ActiveIdUsingKeyInputMask = 0x00 ;
2017-10-11 18:29:53 +00:00
}
2019-01-04 18:03:56 +00:00
// FIXME-NAV: The existence of SetNavID/SetNavIDWithRectRel/SetFocusID is incredibly messy and confusing and needs some explanation or refactoring.
2017-10-13 11:23:21 +00:00
void ImGui : : SetFocusID ( ImGuiID id , ImGuiWindow * window )
2017-10-11 18:29:53 +00:00
{
ImGuiContext & g = * GImGui ;
2018-01-23 15:45:46 +00:00
IM_ASSERT ( id ! = 0 ) ;
// Assume that SetFocusID() is called in the context where its NavLayer is the current layer, which is the case everywhere we call it.
2018-12-04 13:30:11 +00:00
const ImGuiNavLayer nav_layer = window - > DC . NavLayerCurrent ;
2018-02-01 17:19:36 +00:00
if ( g . NavWindow ! = window )
g . NavInitRequest = false ;
2017-10-13 11:23:21 +00:00
g . NavId = id ;
2017-10-15 22:33:30 +00:00
g . NavWindow = window ;
g . NavLayer = nav_layer ;
window - > NavLastIds [ nav_layer ] = id ;
if ( window - > DC . LastItemId = = id )
window - > NavRectRel [ nav_layer ] = ImRect ( window - > DC . LastItemRect . Min - window - > Pos , window - > DC . LastItemRect . Max - window - > Pos ) ;
2017-10-13 11:23:21 +00:00
if ( g . ActiveIdSource = = ImGuiInputSource_Nav )
g . NavDisableMouseHover = true ;
else
g . NavDisableHighlight = true ;
2016-07-19 22:02:59 +00:00
}
2017-01-11 19:56:55 +00:00
void ImGui : : ClearActiveID ( )
{
SetActiveID ( 0 , NULL ) ;
}
2015-10-06 17:27:24 +00:00
void ImGui : : SetHoveredID ( ImGuiID id )
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2015-10-06 17:27:24 +00:00
g . HoveredId = id ;
2015-12-03 21:30:17 +00:00
g . HoveredIdAllowOverlap = false ;
2018-07-30 12:36:08 +00:00
if ( id ! = 0 & & g . HoveredIdPreviousFrame ! = id )
2018-10-25 15:31:16 +00:00
g . HoveredIdTimer = g . HoveredIdNotActiveTimer = 0.0f ;
2015-10-06 17:27:24 +00:00
}
2017-10-13 14:48:14 +00:00
ImGuiID ImGui : : GetHoveredID ( )
{
ImGuiContext & g = * GImGui ;
return g . HoveredId ? g . HoveredId : g . HoveredIdPreviousFrame ;
}
2015-08-06 14:11:33 +00:00
void ImGui : : KeepAliveID ( ImGuiID id )
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2015-08-06 14:11:33 +00:00
if ( g . ActiveId = = id )
2018-08-16 20:33:16 +00:00
g . ActiveIdIsAlive = id ;
2018-06-12 16:44:33 +00:00
if ( g . ActiveIdPreviousFrame = = id )
g . ActiveIdPreviousFrameIsAlive = true ;
2015-08-06 14:11:33 +00:00
}
2018-08-23 11:47:37 +00:00
void ImGui : : MarkItemEdited ( ImGuiID id )
2018-06-12 22:10:33 +00:00
{
2018-08-23 11:26:14 +00:00
// This marking is solely to be able to provide info for IsItemDeactivatedAfterEdit().
2018-06-12 22:10:33 +00:00
// ActiveId might have been released by the time we call this (as in the typical press/release button behavior) but still need need to fill the data.
ImGuiContext & g = * GImGui ;
2018-07-08 11:03:39 +00:00
IM_ASSERT ( g . ActiveId = = id | | g . ActiveId = = 0 | | g . DragDropActive ) ;
2019-01-27 15:23:23 +00:00
IM_UNUSED ( id ) ; // Avoid unused variable warnings when asserts are compiled out.
2018-08-22 20:31:51 +00:00
//IM_ASSERT(g.CurrentWindow->DC.LastItemId == id);
2019-05-13 17:05:41 +00:00
g . ActiveIdHasBeenEditedThisFrame = true ;
2019-05-13 16:15:39 +00:00
g . ActiveIdHasBeenEditedBefore = true ;
2018-08-23 11:47:37 +00:00
g . CurrentWindow - > DC . LastItemStatusFlags | = ImGuiItemStatusFlags_Edited ;
2018-06-12 22:10:33 +00:00
}
2017-10-20 15:52:22 +00:00
static inline bool IsWindowContentHoverable ( ImGuiWindow * window , ImGuiHoveredFlags flags )
2017-09-27 21:31:03 +00:00
{
// An active popup disable hovering on other windows (apart from its own children)
// FIXME-OPT: This could be cached/stored within the window.
ImGuiContext & g = * GImGui ;
if ( g . NavWindow )
if ( ImGuiWindow * focused_root_window = g . NavWindow - > RootWindow )
2017-10-20 15:52:22 +00:00
if ( focused_root_window - > WasActive & & focused_root_window ! = window - > RootWindow )
{
// For the purpose of those flags we differentiate "standard popup" from "modal popup"
// NB: The order of those two tests is important because Modal windows are also Popups.
if ( focused_root_window - > Flags & ImGuiWindowFlags_Modal )
return false ;
if ( ( focused_root_window - > Flags & ImGuiWindowFlags_Popup ) & & ! ( flags & ImGuiHoveredFlags_AllowWhenBlockedByPopup ) )
return false ;
}
2017-09-27 21:31:03 +00:00
return true ;
}
2015-08-06 14:11:33 +00:00
// Advance cursor given item size for layout.
2019-10-03 13:59:36 +00:00
void ImGui : : ItemSize ( const ImVec2 & size , float text_baseline_y )
2015-08-06 14:11:33 +00:00
{
2017-10-06 18:48:07 +00:00
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = g . CurrentWindow ;
2015-08-06 14:11:33 +00:00
if ( window - > SkipItems )
return ;
2019-10-06 21:17:36 +00:00
// We increase the height in this function to accommodate for baseline offset.
// In theory we should be offsetting the starting position (window->DC.CursorPos), that will be the topic of a larger refactor,
// but since ItemSize() is not yet an API that moves the cursor (to handle e.g. wrapping) enlarging the height has the same effect.
const float offset_to_match_baseline_y = ( text_baseline_y > = 0 ) ? ImMax ( 0.0f , window - > DC . CurrLineTextBaseOffset - text_baseline_y ) : 0.0f ;
const float line_height = ImMax ( window - > DC . CurrLineSize . y , size . y + offset_to_match_baseline_y ) ;
2015-08-06 14:11:33 +00:00
// Always align ourselves on pixel boundaries
2017-09-26 13:33:57 +00:00
//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]
2019-05-13 16:15:39 +00:00
window - > DC . CursorPosPrevLine . x = window - > DC . CursorPos . x + size . x ;
window - > DC . CursorPosPrevLine . y = window - > DC . CursorPos . y ;
2019-10-17 09:36:26 +00:00
window - > DC . CursorPos . x = IM_FLOOR ( window - > Pos . x + window - > DC . Indent . x + window - > DC . ColumnsOffset . x ) ; // Next line
window - > DC . CursorPos . y = IM_FLOOR ( window - > DC . CursorPos . y + line_height + g . Style . ItemSpacing . y ) ; // Next line
2015-08-06 14:11:33 +00:00
window - > DC . CursorMaxPos . x = ImMax ( window - > DC . CursorMaxPos . x , window - > DC . CursorPosPrevLine . x ) ;
2017-11-29 22:39:23 +00:00
window - > DC . CursorMaxPos . y = ImMax ( window - > DC . CursorMaxPos . y , window - > DC . CursorPos . y - g . Style . ItemSpacing . y ) ;
2017-09-26 13:33:57 +00:00
//if (g.IO.KeyAlt) window->DrawList->AddCircle(window->DC.CursorMaxPos, 3.0f, IM_COL32(255,0,0,255), 4); // [DEBUG]
2015-08-06 14:11:33 +00:00
2018-08-28 17:03:08 +00:00
window - > DC . PrevLineSize . y = line_height ;
2019-10-03 13:59:36 +00:00
window - > DC . CurrLineSize . y = 0.0f ;
window - > DC . PrevLineTextBaseOffset = ImMax ( window - > DC . CurrLineTextBaseOffset , text_baseline_y ) ;
window - > DC . CurrLineTextBaseOffset = 0.0f ;
2017-09-26 13:42:55 +00:00
// Horizontal layout mode
if ( window - > DC . LayoutType = = ImGuiLayoutType_Horizontal )
SameLine ( ) ;
2015-08-06 14:11:33 +00:00
}
2019-10-03 13:59:36 +00:00
void ImGui : : ItemSize ( const ImRect & bb , float text_baseline_y )
2015-08-24 11:50:18 +00:00
{
2019-10-03 13:59:36 +00:00
ItemSize ( bb . GetSize ( ) , text_baseline_y ) ;
2015-08-06 14:11:33 +00:00
}
// Declare item bounding box for clipping and interaction.
// Note that the size can be different than the one provided to ItemSize(). Typically, widgets that spread over available surface
2017-09-29 18:03:02 +00:00
// declare their minimum size requirement to ItemSize() and then use a larger region for drawing/interaction, which is passed to ItemAdd().
2017-10-06 21:27:29 +00:00
bool ImGui : : ItemAdd ( const ImRect & bb , ImGuiID id , const ImRect * nav_bb_arg )
2015-08-06 14:11:33 +00:00
{
2016-07-19 22:02:59 +00:00
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = g . CurrentWindow ;
2017-10-06 21:27:29 +00:00
if ( id ! = 0 )
2017-10-06 16:44:50 +00:00
{
2017-10-06 21:40:53 +00:00
// Navigation processing runs prior to clipping early-out
2017-10-06 22:54:29 +00:00
// (a) So that NavInitRequest can be honored, for newly opened windows to select a default widget
2019-09-17 09:33:18 +00:00
// (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
2019-05-21 10:18:34 +00:00
// 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.
2017-10-06 21:51:15 +00:00
window - > DC . NavLayerActiveMaskNext | = window - > DC . NavLayerCurrentMask ;
2018-01-29 22:06:55 +00:00
if ( g . NavId = = id | | g . NavAnyRequest )
2018-02-08 22:11:51 +00:00
if ( g . NavWindow - > RootWindowForNav = = window - > RootWindowForNav )
2018-01-29 22:06:55 +00:00
if ( window = = g . NavWindow | | ( ( window - > Flags | g . NavWindow - > Flags ) & ImGuiWindowFlags_NavFlattened ) )
NavProcessItem ( window , nav_bb_arg ? * nav_bb_arg : bb , id ) ;
2019-07-19 17:48:22 +00:00
// [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
2017-10-06 16:44:50 +00:00
}
2016-07-19 22:02:59 +00:00
2017-10-06 21:23:18 +00:00
window - > DC . LastItemId = id ;
2017-10-06 17:17:01 +00:00
window - > DC . LastItemRect = bb ;
2018-12-11 10:58:15 +00:00
window - > DC . LastItemStatusFlags = ImGuiItemStatusFlags_None ;
2019-05-13 13:11:25 +00:00
g . NextItemData . Flags = ImGuiNextItemDataFlags_None ;
2017-10-06 21:40:53 +00:00
2018-12-06 17:18:54 +00:00
# ifdef IMGUI_ENABLE_TEST_ENGINE
2019-01-07 22:59:05 +00:00
if ( id ! = 0 )
2019-04-12 17:44:29 +00:00
IMGUI_TEST_ENGINE_ITEM_ADD ( nav_bb_arg ? * nav_bb_arg : bb , id ) ;
2018-12-06 17:18:54 +00:00
# endif
2017-10-06 21:40:53 +00:00
// Clipping test
const bool is_clipped = IsClippedEx ( bb , id , false ) ;
2016-07-19 22:02:59 +00:00
if ( is_clipped )
2015-08-06 14:11:33 +00:00
return false ;
2017-09-26 13:33:57 +00:00
//if (g.IO.KeyAlt) window->DrawList->AddRect(bb.Min, bb.Max, IM_COL32(255,255,0,120)); // [DEBUG]
2015-08-06 14:11:33 +00:00
2017-09-28 13:43:26 +00:00
// We need to calculate this now to take account of the current clipping rectangle (as items like Selectable may change them)
2018-02-06 12:34:41 +00:00
if ( IsMouseHoveringRect ( bb . Min , bb . Max ) )
window - > DC . LastItemStatusFlags | = ImGuiItemStatusFlags_HoveredRect ;
2015-08-06 14:11:33 +00:00
return true ;
}
2017-10-16 14:41:09 +00:00
// This is roughly matching the behavior of internal-facing ItemHoverable()
2017-10-30 08:35:42 +00:00
// - we allow hovering to be true when ActiveId==window->MoveID, so that clicking on non-interactive items such as a Text() item still returns true with IsItemHovered()
2017-10-16 14:41:09 +00:00
// - this should work even for non-interactive items that have no ID, so we cannot use LastItemId
2017-10-20 15:52:22 +00:00
bool ImGui : : IsItemHovered ( ImGuiHoveredFlags flags )
2015-08-06 14:11:33 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2017-09-27 15:21:50 +00:00
ImGuiWindow * window = g . CurrentWindow ;
2018-01-24 09:24:41 +00:00
if ( g . NavDisableMouseHover & & ! g . NavDisableHighlight )
2017-09-27 15:25:50 +00:00
return IsItemFocused ( ) ;
2017-09-28 13:45:35 +00:00
2017-12-08 08:34:05 +00:00
// Test for bounding box overlap, as updated as ItemAdd()
2018-02-06 12:34:41 +00:00
if ( ! ( window - > DC . LastItemStatusFlags & ImGuiItemStatusFlags_HoveredRect ) )
2017-09-28 13:43:26 +00:00
return false ;
2017-12-11 22:16:27 +00:00
IM_ASSERT ( ( flags & ( ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows ) ) = = 0 ) ; // Flags not supported by this function
2017-11-02 15:44:24 +00:00
2017-12-08 08:34:05 +00:00
// Test if we are hovering the right window (our window could be behind another window)
2017-10-16 14:41:09 +00:00
// [2017/10/16] Reverted commit 344d48be3 and testing RootWindow instead. I believe it is correct to NOT test for RootWindow but this leaves us unable to use IsItemHovered() after EndChild() itself.
// Until a solution is found I believe reverting to the test from 2017/09/27 is safe since this was the test that has been running for a long while.
//if (g.HoveredWindow != window)
// return false;
2017-10-20 15:52:22 +00:00
if ( g . HoveredRootWindow ! = window - > RootWindow & & ! ( flags & ImGuiHoveredFlags_AllowWhenOverlapped ) )
2017-09-27 22:05:18 +00:00
return false ;
2017-12-08 08:34:05 +00:00
// Test if another item is active (e.g. being dragged)
2017-10-20 15:52:22 +00:00
if ( ! ( flags & ImGuiHoveredFlags_AllowWhenBlockedByActiveItem ) )
if ( g . ActiveId ! = 0 & & g . ActiveId ! = window - > DC . LastItemId & & ! g . ActiveIdAllowOverlap & & g . ActiveId ! = window - > MoveId )
return false ;
2017-12-08 08:34:05 +00:00
2019-04-28 20:21:23 +00:00
// Test if interactions on this window are blocked by an active popup or modal.
// The ImGuiHoveredFlags_AllowWhenBlockedByPopup flag will be tested here.
2017-10-20 15:52:22 +00:00
if ( ! IsWindowContentHoverable ( window , flags ) )
2017-09-27 22:05:18 +00:00
return false ;
2017-12-08 08:34:05 +00:00
// Test if the item is disabled
2018-07-10 17:16:57 +00:00
if ( ( window - > DC . ItemFlags & ImGuiItemFlags_Disabled ) & & ! ( flags & ImGuiHoveredFlags_AllowWhenDisabled ) )
2017-10-25 07:28:54 +00:00
return false ;
2018-05-17 12:12:37 +00:00
2019-03-16 14:48:21 +00:00
// Special handling for the dummy item after Begin() which represent the title bar or tab.
2019-02-01 09:26:08 +00:00
// When the window is collapsed (SkipItems==true) that last item will never be overwritten so we need to detect the case.
2017-11-18 23:11:18 +00:00
if ( window - > DC . LastItemId = = window - > MoveId & & window - > WriteAccessed )
return false ;
2017-09-27 22:05:18 +00:00
return true ;
2015-08-06 14:11:33 +00:00
}
2017-09-27 22:21:47 +00:00
// Internal facing ItemHoverable() used when submitting widgets. Differs slightly from IsItemHovered().
bool ImGui : : ItemHoverable ( const ImRect & bb , ImGuiID id )
2015-08-06 14:11:33 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2017-09-27 21:10:46 +00:00
if ( g . HoveredId ! = 0 & & g . HoveredId ! = id & & ! g . HoveredIdAllowOverlap )
return false ;
ImGuiWindow * window = g . CurrentWindow ;
if ( g . HoveredWindow ! = window )
return false ;
2017-09-27 22:05:18 +00:00
if ( g . ActiveId ! = 0 & & g . ActiveId ! = id & & ! g . ActiveIdAllowOverlap )
return false ;
if ( ! IsMouseHoveringRect ( bb . Min , bb . Max ) )
return false ;
2018-06-13 21:20:09 +00:00
if ( g . NavDisableMouseHover | | ! IsWindowContentHoverable ( window , ImGuiHoveredFlags_None ) )
2017-09-27 22:05:18 +00:00
return false ;
2017-10-25 07:28:54 +00:00
if ( window - > DC . ItemFlags & ImGuiItemFlags_Disabled )
return false ;
2017-09-27 22:21:47 +00:00
SetHoveredID ( id ) ;
2019-07-19 17:48:22 +00:00
// [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 ( ) ;
2017-09-27 22:05:18 +00:00
return true ;
2015-08-06 14:11:33 +00:00
}
2017-10-06 21:23:18 +00:00
bool ImGui : : IsClippedEx ( const ImRect & bb , ImGuiID id , bool clip_even_when_logged )
2017-09-27 14:07:47 +00:00
{
ImGuiContext & g = * GImGui ;
2017-10-06 18:48:07 +00:00
ImGuiWindow * window = g . CurrentWindow ;
2017-09-27 14:07:47 +00:00
if ( ! bb . Overlaps ( window - > ClipRect ) )
2017-10-06 21:23:18 +00:00
if ( id = = 0 | | id ! = g . ActiveId )
2017-09-27 14:07:47 +00:00
if ( clip_even_when_logged | | ! g . LogEnabled )
return true ;
return false ;
}
2019-03-05 21:09:25 +00:00
// Process TAB/Shift+TAB. Be mindful that this function may _clear_ the ActiveID when tabbing out.
2019-03-05 16:38:36 +00:00
bool ImGui : : FocusableItemRegister ( ImGuiWindow * window , ImGuiID id )
2014-08-10 20:58:11 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2014-09-30 10:57:37 +00:00
2019-03-05 16:38:36 +00:00
// Increment counters
2018-10-10 10:01:40 +00:00
const bool is_tab_stop = ( window - > DC . ItemFlags & ( ImGuiItemFlags_NoTabStop | ImGuiItemFlags_Disabled ) ) = = 0 ;
2019-03-05 18:37:20 +00:00
window - > DC . FocusCounterAll + + ;
2018-10-10 10:01:40 +00:00
if ( is_tab_stop )
2019-03-05 18:37:20 +00:00
window - > DC . FocusCounterTab + + ;
2014-08-10 20:58:11 +00:00
2019-03-05 16:38:36 +00:00
// 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)
2019-10-02 09:38:30 +00:00
if ( g . ActiveId = = id & & g . FocusTabPressed & & ! IsActiveIdUsingKey ( ImGuiKey_Tab ) & & g . FocusRequestNextWindow = = NULL )
2019-03-05 18:37:20 +00:00
{
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.
}
2014-08-10 20:58:11 +00:00
2019-03-05 18:37:20 +00:00
// Handle focus requests
if ( g . FocusRequestCurrWindow = = window )
2016-07-19 22:02:59 +00:00
{
2019-03-05 18:37:20 +00:00
if ( window - > DC . FocusCounterAll = = g . FocusRequestCurrCounterAll )
return true ;
if ( is_tab_stop & & window - > DC . FocusCounterTab = = g . FocusRequestCurrCounterTab )
{
g . NavJustTabbedId = id ;
return true ;
}
2019-03-05 21:09:25 +00:00
// If another item is about to be focused, we clear our own active id
if ( g . ActiveId = = id )
ClearActiveID ( ) ;
2016-07-19 22:02:59 +00:00
}
2014-09-30 10:57:37 +00:00
2014-09-30 11:22:58 +00:00
return false ;
2014-08-10 20:58:11 +00:00
}
2015-08-02 03:57:24 +00:00
void ImGui : : FocusableItemUnregister ( ImGuiWindow * window )
2015-03-20 20:50:55 +00:00
{
2019-03-05 18:37:20 +00:00
window - > DC . FocusCounterAll - - ;
window - > DC . FocusCounterTab - - ;
2014-08-10 20:58:11 +00:00
}
2015-08-06 14:11:33 +00:00
float ImGui : : CalcWrapWidthForPos ( const ImVec2 & pos , float wrap_pos_x )
2014-08-10 20:58:11 +00:00
{
2015-08-06 14:11:33 +00:00
if ( wrap_pos_x < 0.0f )
return 0.0f ;
2014-08-19 11:09:13 +00:00
2019-04-18 12:10:01 +00:00
ImGuiWindow * window = GImGui - > CurrentWindow ;
2015-08-06 14:11:33 +00:00
if ( wrap_pos_x = = 0.0f )
2019-06-03 15:07:43 +00:00
wrap_pos_x = window - > WorkRect . Max . x ;
2015-08-30 15:37:56 +00:00
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
2014-08-10 20:58:11 +00:00
2016-06-19 10:50:22 +00:00
return ImMax ( wrap_pos_x - pos . x , 1.0f ) ;
2014-08-10 20:58:11 +00:00
}
2019-04-05 18:20:08 +00:00
// IM_ALLOC() == ImGui::MemAlloc()
2018-05-08 09:02:38 +00:00
void * ImGui : : MemAlloc ( size_t size )
2015-08-06 14:11:33 +00:00
{
2018-08-15 23:28:39 +00:00
if ( ImGuiContext * ctx = GImGui )
ctx - > IO . MetricsActiveAllocations + + ;
2018-05-08 09:02:38 +00:00
return GImAllocatorAllocFunc ( size , GImAllocatorUserData ) ;
2014-08-10 20:58:11 +00:00
}
2019-04-05 18:20:08 +00:00
// IM_FREE() == ImGui::MemFree()
2015-08-06 14:11:33 +00:00
void ImGui : : MemFree ( void * ptr )
2014-08-10 20:58:11 +00:00
{
2019-01-20 16:56:17 +00:00
if ( ptr )
2018-08-15 23:28:39 +00:00
if ( ImGuiContext * ctx = GImGui )
ctx - > IO . MetricsActiveAllocations - - ;
2018-01-20 20:41:46 +00:00
return GImAllocatorFreeFunc ( ptr , GImAllocatorUserData ) ;
2014-08-10 20:58:11 +00:00
}
2015-10-12 10:20:01 +00:00
const char * ImGui : : GetClipboardText ( )
{
2019-07-30 23:48:15 +00:00
ImGuiContext & g = * GImGui ;
return g . IO . GetClipboardTextFn ? g . IO . GetClipboardTextFn ( g . IO . ClipboardUserData ) : " " ;
2015-10-12 10:20:01 +00:00
}
void ImGui : : SetClipboardText ( const char * text )
{
2019-07-30 23:48:15 +00:00
ImGuiContext & g = * GImGui ;
if ( g . IO . SetClipboardTextFn )
g . IO . SetClipboardTextFn ( g . IO . ClipboardUserData , text ) ;
2015-10-12 10:20:01 +00:00
}
2015-03-11 16:44:54 +00:00
const char * ImGui : : GetVersion ( )
{
return IMGUI_VERSION ;
2014-08-10 20:58:11 +00:00
}
2019-06-11 14:11:19 +00:00
// Internal state access - if you want to share Dear ImGui state between modules (e.g. DLL) or allocate it yourself
2015-02-04 08:43:11 +00:00
// 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
2016-05-07 17:55:51 +00:00
ImGuiContext * ImGui : : GetCurrentContext ( )
2015-02-01 04:28:24 +00:00
{
2015-02-04 08:30:03 +00:00
return GImGui ;
2015-02-01 04:28:24 +00:00
}
2016-05-07 17:55:51 +00:00
void ImGui : : SetCurrentContext ( ImGuiContext * ctx )
2015-02-01 04:28:24 +00:00
{
2016-11-12 16:08:31 +00:00
# ifdef IMGUI_SET_CURRENT_CONTEXT_FUNC
IMGUI_SET_CURRENT_CONTEXT_FUNC ( ctx ) ; // For custom thread-based hackery you may want to have control over this.
# else
2016-05-07 17:54:27 +00:00
GImGui = ctx ;
2016-11-12 16:08:31 +00:00
# endif
2015-02-01 05:55:19 +00:00
}
2019-05-03 16:40:36 +00:00
// 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
2019-05-27 20:41:17 +00:00
// may see different structures than what imgui.cpp sees, which is problematic.
2019-05-03 16:40:36 +00:00
// 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 )
2018-04-25 20:07:14 +00:00
{
bool error = false ;
2018-08-21 09:59:03 +00:00
if ( strcmp ( version , IMGUI_VERSION ) ! = 0 ) { error = true ; IM_ASSERT ( strcmp ( version , IMGUI_VERSION ) = = 0 & & " Mismatched version string! " ) ; }
2018-04-25 20:07:14 +00:00
if ( sz_io ! = sizeof ( ImGuiIO ) ) { error = true ; IM_ASSERT ( sz_io = = sizeof ( ImGuiIO ) & & " Mismatched struct layout! " ) ; }
if ( sz_style ! = sizeof ( ImGuiStyle ) ) { error = true ; IM_ASSERT ( sz_style = = sizeof ( ImGuiStyle ) & & " Mismatched struct layout! " ) ; }
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! " ) ; }
2019-05-03 16:40:36 +00:00
if ( sz_idx ! = sizeof ( ImDrawIdx ) ) { error = true ; IM_ASSERT ( sz_idx = = sizeof ( ImDrawIdx ) & & " Mismatched struct layout! " ) ; }
2018-04-25 20:07:14 +00:00
return ! error ;
}
2019-01-15 20:50:43 +00:00
void ImGui : : SetAllocatorFunctions ( void * ( * alloc_func ) ( size_t sz , void * user_data ) , void ( * free_func ) ( void * ptr , void * user_data ) , void * user_data )
2018-01-20 20:41:46 +00:00
{
2018-01-21 18:44:48 +00:00
GImAllocatorAllocFunc = alloc_func ;
GImAllocatorFreeFunc = free_func ;
2018-01-20 20:41:46 +00:00
GImAllocatorUserData = user_data ;
}
Reorganized context handling to be more explicit,
- YOU NOW NEED TO CALL ImGui::CreateContext() AT THE BEGINNING OF YOUR APP, AND CALL ImGui::DestroyContext() AT THE END.
- removed Shutdown() function, as DestroyContext() serve this purpose.
- you may pass a ImFontAtlas* pointer to CreateContext() to share a font atlas between contexts. Otherwhise CreateContext() will create its own font atlas instance.
- removed allocator parameters from CreateContext(), they are now setup with SetAllocatorFunctions(), and shared by all contexts.
- removed the default global context and font atlas instance, which were confusing for users of DLL reloading and users of multiple contexts
(#1565, #586, #992, #1007, #1558)
2018-01-21 18:58:32 +00:00
ImGuiContext * ImGui : : CreateContext ( ImFontAtlas * shared_font_atlas )
2015-02-01 05:55:19 +00:00
{
Reorganized context handling to be more explicit,
- YOU NOW NEED TO CALL ImGui::CreateContext() AT THE BEGINNING OF YOUR APP, AND CALL ImGui::DestroyContext() AT THE END.
- removed Shutdown() function, as DestroyContext() serve this purpose.
- you may pass a ImFontAtlas* pointer to CreateContext() to share a font atlas between contexts. Otherwhise CreateContext() will create its own font atlas instance.
- removed allocator parameters from CreateContext(), they are now setup with SetAllocatorFunctions(), and shared by all contexts.
- removed the default global context and font atlas instance, which were confusing for users of DLL reloading and users of multiple contexts
(#1565, #586, #992, #1007, #1558)
2018-01-21 18:58:32 +00:00
ImGuiContext * ctx = IM_NEW ( ImGuiContext ) ( shared_font_atlas ) ;
if ( GImGui = = NULL )
SetCurrentContext ( ctx ) ;
2018-02-18 22:25:48 +00:00
Initialize ( ctx ) ;
2016-05-07 17:54:27 +00:00
return ctx ;
}
2016-05-07 17:55:51 +00:00
void ImGui : : DestroyContext ( ImGuiContext * ctx )
2016-05-07 17:54:27 +00:00
{
Reorganized context handling to be more explicit,
- YOU NOW NEED TO CALL ImGui::CreateContext() AT THE BEGINNING OF YOUR APP, AND CALL ImGui::DestroyContext() AT THE END.
- removed Shutdown() function, as DestroyContext() serve this purpose.
- you may pass a ImFontAtlas* pointer to CreateContext() to share a font atlas between contexts. Otherwhise CreateContext() will create its own font atlas instance.
- removed allocator parameters from CreateContext(), they are now setup with SetAllocatorFunctions(), and shared by all contexts.
- removed the default global context and font atlas instance, which were confusing for users of DLL reloading and users of multiple contexts
(#1565, #586, #992, #1007, #1558)
2018-01-21 18:58:32 +00:00
if ( ctx = = NULL )
ctx = GImGui ;
Shutdown ( ctx ) ;
2016-05-07 17:54:27 +00:00
if ( GImGui = = ctx )
2016-11-12 16:08:31 +00:00
SetCurrentContext ( NULL ) ;
2018-01-20 20:41:46 +00:00
IM_DELETE ( ctx ) ;
2015-02-01 04:28:24 +00:00
}
2014-11-10 01:29:01 +00:00
ImGuiIO & ImGui : : GetIO ( )
2014-08-10 20:58:11 +00:00
{
2019-04-17 07:59:03 +00:00
IM_ASSERT ( GImGui ! = NULL & & " No current context. Did you call ImGui::CreateContext() and ImGui::SetCurrentContext() ? " ) ;
2015-08-06 14:11:33 +00:00
return GImGui - > IO ;
}
ImGuiStyle & ImGui : : GetStyle ( )
{
2019-04-17 07:59:03 +00:00
IM_ASSERT ( GImGui ! = NULL & & " No current context. Did you call ImGui::CreateContext() and ImGui::SetCurrentContext() ? " ) ;
2015-08-06 14:11:33 +00:00
return GImGui - > Style ;
}
2018-02-16 18:18:16 +00:00
// Same value as passed to the old io.RenderDrawListsFn function. Valid after Render() and until the next call to NewFrame()
2015-09-07 13:56:39 +00:00
ImDrawData * ImGui : : GetDrawData ( )
{
2018-02-16 23:49:57 +00:00
ImGuiContext & g = * GImGui ;
return g . DrawData . Valid ? & g . DrawData : NULL ;
2015-09-07 13:56:39 +00:00
}
2018-07-22 16:46:41 +00:00
double ImGui : : GetTime ( )
2015-08-06 14:11:33 +00:00
{
return GImGui - > Time ;
2014-08-10 20:58:11 +00:00
}
2015-08-06 14:11:33 +00:00
int ImGui : : GetFrameCount ( )
2014-08-10 20:58:11 +00:00
{
2015-08-06 14:11:33 +00:00
return GImGui - > FrameCount ;
2014-08-10 20:58:11 +00:00
}
2019-03-04 15:10:51 +00:00
ImDrawList * ImGui : : GetBackgroundDrawList ( )
{
return & GImGui - > BackgroundDrawList ;
}
2019-03-04 15:20:32 +00:00
ImDrawList * ImGui : : GetForegroundDrawList ( )
2017-12-07 11:49:52 +00:00
{
2019-03-04 15:20:32 +00:00
return & GImGui - > ForegroundDrawList ;
2017-12-07 11:49:52 +00:00
}
2017-12-21 17:50:27 +00:00
ImDrawListSharedData * ImGui : : GetDrawListSharedData ( )
{
return & GImGui - > DrawListSharedData ;
}
2018-07-10 09:05:14 +00:00
void ImGui : : StartMouseMovingWindow ( ImGuiWindow * window )
{
// Set ActiveId even if the _NoMove flag is set. Without it, dragging away from a window with _NoMove would activate hover on other windows.
2018-12-10 15:05:30 +00:00
// We _also_ call this when clicking in a window empty space when io.ConfigWindowsMoveFromTitleBarOnly is set, but clear g.MovingWindow afterward.
2019-02-01 09:26:08 +00:00
// This is because we want ActiveId to be set even when the window is not permitted to move.
2018-07-10 09:05:14 +00:00
ImGuiContext & g = * GImGui ;
FocusWindow ( window ) ;
SetActiveID ( window - > MoveId , window ) ;
g . NavDisableHighlight = true ;
g . ActiveIdClickOffset = g . IO . MousePos - window - > RootWindow - > Pos ;
2019-02-01 09:26:08 +00:00
bool can_move_window = true ;
if ( ( window - > Flags & ImGuiWindowFlags_NoMove ) | | ( window - > RootWindow - > Flags & ImGuiWindowFlags_NoMove ) )
can_move_window = false ;
if ( can_move_window )
2018-07-10 09:05:14 +00:00
g . MovingWindow = window ;
}
// Handle mouse moving window
// Note: moving window with the navigation keys (Square + d-pad / CTRL+TAB + Arrows) are processed in NavUpdateWindowing()
2019-01-02 22:05:59 +00:00
void ImGui : : UpdateMouseMovingWindowNewFrame ( )
2018-02-11 21:48:30 +00:00
{
ImGuiContext & g = * GImGui ;
2018-04-24 14:48:26 +00:00
if ( g . MovingWindow ! = NULL )
2018-02-11 21:48:30 +00:00
{
2018-05-17 12:12:37 +00:00
// We actually want to move the root window. g.MovingWindow == window we clicked on (could be a child window).
2018-04-24 14:48:26 +00:00
// We track it to preserve Focus and so that generally ActiveIdWindow == MovingWindow and ActiveId == MovingWindow->MoveId for consistency.
2018-02-11 21:48:30 +00:00
KeepAliveID ( g . ActiveId ) ;
IM_ASSERT ( g . MovingWindow & & g . MovingWindow - > RootWindow ) ;
ImGuiWindow * moving_window = g . MovingWindow - > RootWindow ;
2018-04-25 15:55:26 +00:00
if ( g . IO . MouseDown [ 0 ] & & IsMousePosValid ( & g . IO . MousePos ) )
2018-02-11 21:48:30 +00:00
{
ImVec2 pos = g . IO . MousePos - g . ActiveIdClickOffset ;
2018-04-25 13:24:26 +00:00
if ( moving_window - > Pos . x ! = pos . x | | moving_window - > Pos . y ! = pos . y )
2018-02-11 21:48:30 +00:00
{
MarkIniSettingsDirty ( moving_window ) ;
2018-04-25 15:55:26 +00:00
SetWindowPos ( moving_window , pos , ImGuiCond_Always ) ;
2018-02-11 21:48:30 +00:00
}
FocusWindow ( g . MovingWindow ) ;
}
else
{
ClearActiveID ( ) ;
g . MovingWindow = NULL ;
}
}
else
{
// When clicking/dragging from a window that has the _NoMove flag, we still set the ActiveId in order to prevent hovering others.
if ( g . ActiveIdWindow & & g . ActiveIdWindow - > MoveId = = g . ActiveId )
{
KeepAliveID ( g . ActiveId ) ;
if ( ! g . IO . MouseDown [ 0 ] )
ClearActiveID ( ) ;
}
}
}
2019-01-02 22:05:59 +00:00
// Initiate moving window, handle left-click and right-click focus
void ImGui : : UpdateMouseMovingWindowEndFrame ( )
{
// Initiate moving window
ImGuiContext & g = * GImGui ;
if ( g . ActiveId ! = 0 | | g . HoveredId ! = 0 )
return ;
// Unless we just made a window/popup appear
if ( g . NavWindow & & g . NavWindow - > Appearing )
return ;
// Click to focus window and start moving (after we're done with all our widgets)
if ( g . IO . MouseClicked [ 0 ] )
{
if ( g . HoveredRootWindow ! = NULL )
{
StartMouseMovingWindow ( g . HoveredWindow ) ;
if ( g . IO . ConfigWindowsMoveFromTitleBarOnly & & ! ( g . HoveredRootWindow - > Flags & ImGuiWindowFlags_NoTitleBar ) )
if ( ! g . HoveredRootWindow - > TitleBarRect ( ) . Contains ( g . IO . MouseClickedPos [ 0 ] ) )
g . MovingWindow = NULL ;
}
2019-06-19 16:14:24 +00:00
else if ( g . NavWindow ! = NULL & & GetTopMostPopupModal ( ) = = NULL )
2019-01-02 22:05:59 +00:00
{
2019-02-01 09:26:08 +00:00
// Clicking on void disable focus
FocusWindow ( NULL ) ;
2019-01-02 22:05:59 +00:00
}
}
2019-04-28 20:21:23 +00:00
// 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)
2019-01-02 22:05:59 +00:00
if ( g . IO . MouseClicked [ 1 ] )
{
2019-06-19 16:14:24 +00:00
// Find the top-most window between HoveredWindow and the top-most Modal Window.
2019-01-02 22:05:59 +00:00
// This is where we can trim the popup stack.
2019-06-19 16:14:24 +00:00
ImGuiWindow * modal = GetTopMostPopupModal ( ) ;
2019-01-02 22:05:59 +00:00
bool hovered_window_above_modal = false ;
if ( modal = = NULL )
hovered_window_above_modal = true ;
for ( int i = g . Windows . Size - 1 ; i > = 0 & & hovered_window_above_modal = = false ; i - - )
{
ImGuiWindow * window = g . Windows [ i ] ;
if ( window = = modal )
break ;
if ( window = = g . HoveredWindow )
hovered_window_above_modal = true ;
}
2019-04-28 20:21:23 +00:00
ClosePopupsOverWindow ( hovered_window_above_modal ? g . HoveredWindow : modal , true ) ;
2019-01-02 22:05:59 +00:00
}
}
2018-07-09 17:16:48 +00:00
static bool IsWindowActiveAndVisible ( ImGuiWindow * window )
{
2018-06-27 15:21:59 +00:00
return ( window - > Active ) & & ( ! window - > Hidden ) ;
2018-07-09 17:16:48 +00:00
}
2018-04-25 14:38:13 +00:00
static void ImGui : : UpdateMouseInputs ( )
2018-04-06 16:43:31 +00:00
{
ImGuiContext & g = * GImGui ;
2018-10-02 16:49:55 +00:00
// Round mouse position to avoid spreading non-rounded position (e.g. UpdateManualResize doesn't support them well)
if ( IsMousePosValid ( & g . IO . MousePos ) )
2018-11-15 12:53:53 +00:00
g . IO . MousePos = g . LastValidMousePos = ImFloor ( g . IO . MousePos ) ;
2018-10-02 16:49:55 +00:00
2018-09-05 09:52:48 +00:00
// If mouse just appeared or disappeared (usually denoted by -FLT_MAX components) we cancel out movement in MouseDelta
2018-04-25 14:38:13 +00:00
if ( IsMousePosValid ( & g . IO . MousePos ) & & IsMousePosValid ( & g . IO . MousePosPrev ) )
2018-04-06 16:43:31 +00:00
g . IO . MouseDelta = g . IO . MousePos - g . IO . MousePosPrev ;
else
g . IO . MouseDelta = ImVec2 ( 0.0f , 0.0f ) ;
if ( g . IO . MouseDelta . x ! = 0.0f | | g . IO . MouseDelta . y ! = 0.0f )
g . NavDisableMouseHover = false ;
g . IO . MousePosPrev = g . IO . MousePos ;
for ( int i = 0 ; i < IM_ARRAYSIZE ( g . IO . MouseDown ) ; i + + )
{
g . IO . MouseClicked [ i ] = g . IO . MouseDown [ i ] & & g . IO . MouseDownDuration [ i ] < 0.0f ;
g . IO . MouseReleased [ i ] = ! g . IO . MouseDown [ i ] & & g . IO . MouseDownDuration [ i ] > = 0.0f ;
g . IO . MouseDownDurationPrev [ i ] = g . IO . MouseDownDuration [ i ] ;
g . IO . MouseDownDuration [ i ] = g . IO . MouseDown [ i ] ? ( g . IO . MouseDownDuration [ i ] < 0.0f ? 0.0f : g . IO . MouseDownDuration [ i ] + g . IO . DeltaTime ) : - 1.0f ;
g . IO . MouseDoubleClicked [ i ] = false ;
if ( g . IO . MouseClicked [ i ] )
{
2018-07-22 16:46:41 +00:00
if ( ( float ) ( g . Time - g . IO . MouseClickedTime [ i ] ) < g . IO . MouseDoubleClickTime )
2018-04-06 16:43:31 +00:00
{
2018-05-29 08:47:18 +00:00
ImVec2 delta_from_click_pos = IsMousePosValid ( & g . IO . MousePos ) ? ( g . IO . MousePos - g . IO . MouseClickedPos [ i ] ) : ImVec2 ( 0.0f , 0.0f ) ;
if ( ImLengthSqr ( delta_from_click_pos ) < g . IO . MouseDoubleClickMaxDist * g . IO . MouseDoubleClickMaxDist )
2018-04-06 16:43:31 +00:00
g . IO . MouseDoubleClicked [ i ] = true ;
g . IO . MouseClickedTime [ i ] = - FLT_MAX ; // so the third click isn't turned into a double-click
}
else
{
g . IO . MouseClickedTime [ i ] = g . Time ;
}
g . IO . MouseClickedPos [ i ] = g . IO . MousePos ;
2019-05-03 12:28:57 +00:00
g . IO . MouseDownWasDoubleClick [ i ] = g . IO . MouseDoubleClicked [ i ] ;
2018-04-06 16:43:31 +00:00
g . IO . MouseDragMaxDistanceAbs [ i ] = ImVec2 ( 0.0f , 0.0f ) ;
g . IO . MouseDragMaxDistanceSqr [ i ] = 0.0f ;
}
else if ( g . IO . MouseDown [ i ] )
{
2018-05-29 08:47:18 +00:00
// Maintain the maximum distance we reaching from the initial click position, which is used with dragging threshold
ImVec2 delta_from_click_pos = IsMousePosValid ( & g . IO . MousePos ) ? ( g . IO . MousePos - g . IO . MouseClickedPos [ i ] ) : ImVec2 ( 0.0f , 0.0f ) ;
g . IO . MouseDragMaxDistanceSqr [ i ] = ImMax ( g . IO . MouseDragMaxDistanceSqr [ i ] , ImLengthSqr ( delta_from_click_pos ) ) ;
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 ) ;
2018-04-06 16:43:31 +00:00
}
2019-05-03 12:28:57 +00:00
if ( ! g . IO . MouseDown [ i ] & & ! g . IO . MouseReleased [ i ] )
g . IO . MouseDownWasDoubleClick [ i ] = false ;
2018-04-06 16:43:31 +00:00
if ( g . IO . MouseClicked [ i ] ) // Clicking any mouse button reactivate mouse hovering which may have been deactivated by gamepad/keyboard navigation
g . NavDisableMouseHover = false ;
}
}
2019-07-23 01:48:39 +00:00
static void StartLockWheelingWindow ( ImGuiWindow * window )
2018-07-22 16:57:28 +00:00
{
ImGuiContext & g = * GImGui ;
2019-07-23 01:48:39 +00:00
if ( g . WheelingWindow = = window )
2018-07-22 16:57:28 +00:00
return ;
2019-07-23 01:48:39 +00:00
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 ;
}
}
2018-07-22 16:57:28 +00:00
if ( g . IO . MouseWheel = = 0.0f & & g . IO . MouseWheelH = = 0.0f )
return ;
2019-07-23 01:48:39 +00:00
ImGuiWindow * window = g . WheelingWindow ? g . WheelingWindow : g . HoveredWindow ;
if ( ! window | | window - > Collapsed )
return ;
2019-03-25 18:40:19 +00:00
// 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.
2019-07-15 01:01:06 +00:00
if ( g . IO . MouseWheel ! = 0.0f & & g . IO . KeyCtrl & & g . IO . FontAllowUserScaling )
2018-07-22 16:57:28 +00:00
{
2019-07-23 01:48:39 +00:00
StartLockWheelingWindow ( window ) ;
2019-03-25 18:40:19 +00:00
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 ) )
2018-07-22 16:57:28 +00:00
{
const ImVec2 offset = window - > Size * ( 1.0f - scale ) * ( g . IO . MousePos - window - > Pos ) / window - > Size ;
2019-05-31 18:48:52 +00:00
SetWindowPos ( window , window - > Pos + offset , 0 ) ;
2019-03-25 18:40:19 +00:00
window - > Size = ImFloor ( window - > Size * scale ) ;
window - > SizeFull = ImFloor ( window - > SizeFull * scale ) ;
}
return ;
}
// Mouse wheel scrolling
2019-07-02 16:28:53 +00:00
// If a child window has the ImGuiWindowFlags_NoScrollWithMouse flag, we give a chance to scroll its parent
2019-03-25 18:40:19 +00:00
2019-07-02 16:28:53 +00:00
// 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 )
{
2019-07-23 01:48:39 +00:00
StartLockWheelingWindow ( window ) ;
2019-07-02 16:28:53 +00:00
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 ) )
2019-03-16 18:55:42 +00:00
{
2019-07-02 16:28:53 +00:00
float max_step = window - > InnerRect . GetHeight ( ) * 0.67f ;
float scroll_step = ImFloor ( ImMin ( 5 * window - > CalcFontSize ( ) , max_step ) ) ;
2019-07-23 01:24:23 +00:00
SetScrollY ( window , window - > Scroll . y - wheel_y * scroll_step ) ;
2019-03-16 18:55:42 +00:00
}
2019-07-02 16:28:53 +00:00
}
2019-03-25 18:40:19 +00:00
2019-07-02 16:28:53 +00:00
// 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 )
{
2019-07-23 01:48:39 +00:00
StartLockWheelingWindow ( window ) ;
2019-07-02 16:28:53 +00:00
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 ) )
2018-07-22 16:57:28 +00:00
{
2019-07-02 16:28:53 +00:00
float max_step = window - > InnerRect . GetWidth ( ) * 0.67f ;
float scroll_step = ImFloor ( ImMin ( 2 * window - > CalcFontSize ( ) , max_step ) ) ;
2019-07-23 01:24:23 +00:00
SetScrollX ( window , window - > Scroll . x - wheel_x * scroll_step ) ;
2018-07-22 16:57:28 +00:00
}
}
}
2018-04-06 17:29:00 +00:00
// The reason this is exposed in imgui_internal.h is: on touch-based system that don't have hovering, we want to dispatch inputs to the right target (imgui vs imgui+app)
2018-06-23 18:08:19 +00:00
void ImGui : : UpdateHoveredWindowAndCaptureFlags ( )
2018-04-06 17:29:00 +00:00
{
ImGuiContext & g = * GImGui ;
// Find the window hovered by mouse:
// - Child windows can extend beyond the limit of their parent so we need to derive HoveredRootWindow from HoveredWindow.
// - When moving a window we can skip the search, which also conveniently bypasses the fact that window->WindowRectClipped is lagging as this point of the frame.
// - We also support the moved window toggling the NoInputs flag after moving has started in order to be able to detect windows below it, which is useful for e.g. docking mechanisms.
2018-07-09 19:06:46 +00:00
FindHoveredWindow ( ) ;
2018-04-06 17:29:00 +00:00
// Modal windows prevents cursor from hovering behind them.
2019-06-19 16:14:24 +00:00
ImGuiWindow * modal_window = GetTopMostPopupModal ( ) ;
2018-04-06 17:29:00 +00:00
if ( modal_window )
if ( g . HoveredRootWindow & & ! IsWindowChildOf ( g . HoveredRootWindow , modal_window ) )
g . HoveredRootWindow = g . HoveredWindow = NULL ;
2018-04-06 21:05:53 +00:00
// Disabled mouse?
if ( g . IO . ConfigFlags & ImGuiConfigFlags_NoMouse )
g . HoveredWindow = g . HoveredRootWindow = NULL ;
2018-04-06 17:29:00 +00:00
// We track click ownership. When clicked outside of a window the click is owned by the application and won't report hovering nor request capture even while dragging over our windows afterward.
int mouse_earliest_button_down = - 1 ;
bool mouse_any_down = false ;
for ( int i = 0 ; i < IM_ARRAYSIZE ( g . IO . MouseDown ) ; i + + )
{
if ( g . IO . MouseClicked [ i ] )
g . IO . MouseDownOwned [ i ] = ( g . HoveredWindow ! = NULL ) | | ( ! g . OpenPopupStack . empty ( ) ) ;
mouse_any_down | = g . IO . MouseDown [ i ] ;
if ( g . IO . MouseDown [ i ] )
if ( mouse_earliest_button_down = = - 1 | | g . IO . MouseClickedTime [ i ] < g . IO . MouseClickedTime [ mouse_earliest_button_down ] )
mouse_earliest_button_down = i ;
}
const bool mouse_avail_to_imgui = ( mouse_earliest_button_down = = - 1 ) | | g . IO . MouseDownOwned [ mouse_earliest_button_down ] ;
// If mouse was first clicked outside of ImGui bounds we also cancel out hovering.
// FIXME: For patterns of drag and drop across OS windows, we may need to rework/remove this test (first committed 311c0ca9 on 2015/02)
const bool mouse_dragging_extern_payload = g . DragDropActive & & ( g . DragDropSourceFlags & ImGuiDragDropFlags_SourceExtern ) ! = 0 ;
if ( ! mouse_avail_to_imgui & & ! mouse_dragging_extern_payload )
g . HoveredWindow = g . HoveredRootWindow = NULL ;
2019-06-11 14:11:19 +00:00
// Update io.WantCaptureMouse for the user application (true = dispatch mouse info to imgui, false = dispatch mouse info to Dear ImGui + app)
2018-04-06 17:29:00 +00:00
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 ( ) ) ;
2019-06-11 14:11:19 +00:00
// Update io.WantCaptureKeyboard for the user application (true = dispatch keyboard info to imgui, false = dispatch keyboard info to Dear ImGui + app)
2018-04-06 17:29:00 +00:00
if ( g . WantCaptureKeyboardNextFrame ! = - 1 )
g . IO . WantCaptureKeyboard = ( g . WantCaptureKeyboardNextFrame ! = 0 ) ;
else
g . IO . WantCaptureKeyboard = ( g . ActiveId ! = 0 ) | | ( modal_window ! = NULL ) ;
if ( g . IO . NavActive & & ( g . IO . ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard ) & & ! ( g . IO . ConfigFlags & ImGuiConfigFlags_NavNoCaptureKeyboard ) )
g . IO . WantCaptureKeyboard = true ;
// Update io.WantTextInput flag, this is to allow systems without a keyboard (e.g. mobile, hand-held) to show a software keyboard if possible
2018-04-26 07:51:46 +00:00
g . IO . WantTextInput = ( g . WantTextInputNextFrame ! = - 1 ) ? ( g . WantTextInputNextFrame ! = 0 ) : false ;
2018-04-06 17:29:00 +00:00
}
2019-07-21 19:13:44 +00:00
static void NewFrameSanityChecks ( )
2014-08-10 20:58:11 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2014-08-10 20:58:11 +00:00
2015-01-08 23:35:01 +00:00
// Check user data
2018-04-25 14:38:13 +00:00
// (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)
2018-02-18 22:25:48 +00:00
IM_ASSERT ( g . Initialized ) ;
2019-02-14 16:14:29 +00:00
IM_ASSERT ( ( g . IO . DeltaTime > 0.0f | | g . FrameCount = = 0 ) & & " Need a positive DeltaTime! " ) ;
2019-02-28 15:59:01 +00:00
IM_ASSERT ( ( g . FrameCount = = 0 | | g . FrameCountEnded = = g . FrameCount ) & & " Forgot to call Render() or EndFrame() at the end of the previous frame? " ) ;
2019-02-14 16:14:29 +00:00
IM_ASSERT ( g . IO . DisplaySize . x > = 0.0f & & g . IO . DisplaySize . y > = 0.0f & & " Invalid DisplaySize value! " ) ;
2018-01-21 18:53:02 +00:00
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() ? " ) ;
2019-02-14 16:14:29 +00:00
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)! " ) ;
2019-02-28 15:59:01 +00:00
IM_ASSERT ( g . Style . WindowMinSize . x > = 1.0f & & g . Style . WindowMinSize . y > = 1.0f & & " Invalid style setting. " ) ;
2019-09-17 14:16:38 +00:00
IM_ASSERT ( g . Style . WindowMenuButtonPosition = = ImGuiDir_None | | g . Style . WindowMenuButtonPosition = = ImGuiDir_Left | | g . Style . WindowMenuButtonPosition = = ImGuiDir_Right ) ;
2018-01-18 09:06:58 +00:00
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) " ) ;
2014-08-10 20:58:11 +00:00
2018-09-05 09:52:48 +00:00
// Perform simple check: required key mapping (we intentionally do NOT check all keys to not pressure user into setting up everything, but Space is required and was only recently added in 1.60 WIP)
2018-02-28 17:51:40 +00:00
if ( g . IO . ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard )
2018-02-06 18:54:30 +00:00
IM_ASSERT ( g . IO . KeyMap [ ImGuiKey_Space ] ! = - 1 & & " ImGuiKey_Space is not mapped, required for keyboard navigation. " ) ;
2018-12-10 14:36:07 +00:00
// 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 ;
2019-07-21 19:13:44 +00:00
}
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 ( ) ;
2018-07-06 13:30:21 +00:00
2018-05-07 20:18:45 +00:00
// Load settings on first frame (if not explicitly loaded manually before)
2018-02-18 22:25:48 +00:00
if ( ! g . SettingsLoaded )
{
IM_ASSERT ( g . SettingsWindows . empty ( ) ) ;
2018-05-07 20:18:45 +00:00
if ( g . IO . IniFilename )
LoadIniSettingsFromDisk ( g . IO . IniFilename ) ;
2018-02-18 22:25:48 +00:00
g . SettingsLoaded = true ;
}
2014-11-29 00:02:46 +00:00
2018-05-07 20:18:45 +00:00
// Save settings (with a delay after the last modification, so we don't spam disk too much)
2018-04-06 16:43:31 +00:00
if ( g . SettingsDirtyTimer > 0.0f )
{
g . SettingsDirtyTimer - = g . IO . DeltaTime ;
if ( g . SettingsDirtyTimer < = 0.0f )
2018-05-07 20:18:45 +00:00
{
if ( g . IO . IniFilename ! = NULL )
SaveIniSettingsToDisk ( g . IO . IniFilename ) ;
else
g . IO . WantSaveIniSettings = true ; // Let user know they can call SaveIniSettingsToMemory(). user will need to clear io.WantSaveIniSettings themselves.
g . SettingsDirtyTimer = 0.0f ;
}
2018-04-06 16:43:31 +00:00
}
2017-12-29 19:56:52 +00:00
g . Time + = g . IO . DeltaTime ;
2019-11-13 20:35:42 +00:00
g . WithinFrameScope = true ;
2017-12-29 19:56:52 +00:00
g . FrameCount + = 1 ;
g . TooltipOverrideCount = 0 ;
g . WindowsActiveCount = 0 ;
2019-02-01 09:26:08 +00:00
// Setup current font and draw list shared data
2018-07-22 16:53:27 +00:00
g . IO . Fonts - > Locked = true ;
2016-11-06 20:50:18 +00:00
SetCurrentFont ( GetDefaultFont ( ) ) ;
IM_ASSERT ( g . Font - > IsLoaded ( ) ) ;
2017-12-21 17:50:27 +00:00
g . DrawListSharedData . ClipRectFullscreen = ImVec4 ( 0.0f , 0.0f , g . IO . DisplaySize . x , g . IO . DisplaySize . y ) ;
g . DrawListSharedData . CurveTessellationTol = g . Style . CurveTessellationTol ;
2019-05-29 13:25:53 +00:00
g . DrawListSharedData . InitialFlags = ImDrawListFlags_None ;
if ( g . Style . AntiAliasedLines )
g . DrawListSharedData . InitialFlags | = ImDrawListFlags_AntiAliasedLines ;
if ( g . Style . AntiAliasedFill )
g . DrawListSharedData . InitialFlags | = ImDrawListFlags_AntiAliasedFill ;
2019-05-29 14:29:17 +00:00
if ( g . IO . BackendFlags & ImGuiBackendFlags_RendererHasVtxOffset )
2019-05-29 13:25:53 +00:00
g . DrawListSharedData . InitialFlags | = ImDrawListFlags_AllowVtxOffset ;
2014-08-19 11:09:13 +00:00
2019-03-04 15:10:51 +00:00
g . BackgroundDrawList . Clear ( ) ;
g . BackgroundDrawList . PushTextureID ( g . IO . Fonts - > TexID ) ;
g . BackgroundDrawList . PushClipRectFullScreen ( ) ;
2019-03-04 15:20:32 +00:00
g . ForegroundDrawList . Clear ( ) ;
g . ForegroundDrawList . PushTextureID ( g . IO . Fonts - > TexID ) ;
g . ForegroundDrawList . PushClipRectFullScreen ( ) ;
2014-08-19 11:09:13 +00:00
2019-02-01 09:26:08 +00:00
// Mark rendering data as invalid to prevent user who may have a handle on it to use it.
2018-01-15 18:09:10 +00:00
g . DrawData . Clear ( ) ;
2015-09-07 13:56:39 +00:00
2018-07-30 16:06:41 +00:00
// Drag and drop keep the source ID alive so even if the source disappear our state is consistent
if ( g . DragDropActive & & g . DragDropPayload . SourceId = = g . ActiveId )
KeepAliveID ( g . DragDropPayload . SourceId ) ;
2016-07-17 08:35:17 +00:00
// Clear reference to active widget if the widget isn't alive anymore
2017-10-29 22:46:32 +00:00
if ( ! g . HoveredIdPreviousFrame )
g . HoveredIdTimer = 0.0f ;
2018-10-25 15:31:16 +00:00
if ( ! g . HoveredIdPreviousFrame | | ( g . HoveredId & & g . ActiveId = = g . HoveredId ) )
g . HoveredIdNotActiveTimer = 0.0f ;
2018-07-30 12:36:08 +00:00
if ( g . HoveredId )
g . HoveredIdTimer + = g . IO . DeltaTime ;
2018-10-25 15:31:16 +00:00
if ( g . HoveredId & & g . ActiveId ! = g . HoveredId )
g . HoveredIdNotActiveTimer + = g . IO . DeltaTime ;
2016-07-17 08:35:17 +00:00
g . HoveredIdPreviousFrame = g . HoveredId ;
g . HoveredId = 0 ;
g . HoveredIdAllowOverlap = false ;
2018-08-16 20:33:16 +00:00
if ( g . ActiveIdIsAlive ! = g . ActiveId & & g . ActiveIdPreviousFrame = = g . ActiveId & & g . ActiveId ! = 0 )
2017-01-11 20:03:25 +00:00
ClearActiveID ( ) ;
2017-10-29 22:46:32 +00:00
if ( g . ActiveId )
g . ActiveIdTimer + = g . IO . DeltaTime ;
2018-01-05 14:33:24 +00:00
g . LastActiveIdTimer + = g . IO . DeltaTime ;
2016-07-17 08:35:17 +00:00
g . ActiveIdPreviousFrame = g . ActiveId ;
2018-06-12 16:44:33 +00:00
g . ActiveIdPreviousFrameWindow = g . ActiveIdWindow ;
2019-05-13 16:15:39 +00:00
g . ActiveIdPreviousFrameHasBeenEditedBefore = g . ActiveIdHasBeenEditedBefore ;
2018-08-16 20:33:16 +00:00
g . ActiveIdIsAlive = 0 ;
2019-05-13 17:05:41 +00:00
g . ActiveIdHasBeenEditedThisFrame = false ;
2018-08-16 20:33:16 +00:00
g . ActiveIdPreviousFrameIsAlive = false ;
2016-07-17 08:35:17 +00:00
g . ActiveIdIsJustActivated = false ;
2019-04-25 13:46:10 +00:00
if ( g . TempInputTextId ! = 0 & & g . ActiveId ! = g . TempInputTextId )
g . TempInputTextId = 0 ;
2019-10-02 09:38:30 +00:00
if ( g . ActiveId = = 0 )
{
g . ActiveIdUsingNavDirMask = g . ActiveIdUsingNavInputMask = 0 ;
g . ActiveIdUsingKeyInputMask = 0 ;
}
2016-07-17 08:35:17 +00:00
2018-07-30 16:06:41 +00:00
// Drag and drop
2017-11-06 19:02:56 +00:00
g . DragDropAcceptIdPrev = g . DragDropAcceptIdCurr ;
g . DragDropAcceptIdCurr = 0 ;
2017-11-08 14:47:52 +00:00
g . DragDropAcceptIdCurrRectSurface = FLT_MAX ;
2018-07-08 18:04:49 +00:00
g . DragDropWithinSourceOrTarget = false ;
2017-10-29 20:15:02 +00:00
2016-07-17 08:35:17 +00:00
// Update keyboard input state
memcpy ( g . IO . KeysDownDurationPrev , g . IO . KeysDownDuration , sizeof ( g . IO . KeysDownDuration ) ) ;
for ( int i = 0 ; i < IM_ARRAYSIZE ( g . IO . KeysDown ) ; i + + )
g . IO . KeysDownDuration [ i ] = g . IO . KeysDown [ i ] ? ( g . IO . KeysDownDuration [ i ] < 0.0f ? 0.0f : g . IO . KeysDownDuration [ i ] + g . IO . DeltaTime ) : - 1.0f ;
2018-02-06 18:54:30 +00:00
// Update gamepad/keyboard directional navigation
2016-07-19 22:02:59 +00:00
NavUpdate ( ) ;
2016-07-17 08:35:17 +00:00
// Update mouse input state
2018-04-25 14:38:13 +00:00
UpdateMouseInputs ( ) ;
2014-08-19 11:09:13 +00:00
2015-02-11 18:28:17 +00:00
// Calculate frame-rate for the user, as a purely luxurious feature
g . FramerateSecPerFrameAccum + = g . IO . DeltaTime - g . FramerateSecPerFrame [ g . FramerateSecPerFrameIdx ] ;
g . FramerateSecPerFrame [ g . FramerateSecPerFrameIdx ] = g . IO . DeltaTime ;
g . FramerateSecPerFrameIdx = ( g . FramerateSecPerFrameIdx + 1 ) % IM_ARRAYSIZE ( g . FramerateSecPerFrame ) ;
2018-04-10 21:48:27 +00:00
g . IO . Framerate = ( g . FramerateSecPerFrameAccum > 0.0f ) ? ( 1.0f / ( g . FramerateSecPerFrameAccum / ( float ) IM_ARRAYSIZE ( g . FramerateSecPerFrame ) ) ) : FLT_MAX ;
2015-02-11 18:28:17 +00:00
2019-06-06 14:13:30 +00:00
// Find hovered window
// (needs to be before UpdateMouseMovingWindowNewFrame so we fill g.HoveredWindowUnderMovingWindow on the mouse release frame)
UpdateHoveredWindowAndCaptureFlags ( ) ;
2018-02-11 21:48:30 +00:00
// Handle user moving window with mouse (at the beginning of the frame to avoid input lag or sheering)
2019-01-02 22:05:59 +00:00
UpdateMouseMovingWindowNewFrame ( ) ;
2018-05-17 12:12:37 +00:00
2018-07-09 13:04:27 +00:00
// Background darkening/whitening
2019-06-19 16:14:24 +00:00
if ( GetTopMostPopupModal ( ) ! = NULL | | ( g . NavWindowingTarget ! = NULL & & g . NavWindowingHighlightAlpha > 0.0f ) )
2018-07-09 17:16:48 +00:00
g . DimBgRatio = ImMin ( g . DimBgRatio + g . IO . DeltaTime * 6.0f , 1.0f ) ;
2015-06-23 18:34:15 +00:00
else
2018-07-26 17:00:17 +00:00
g . DimBgRatio = ImMax ( g . DimBgRatio - g . IO . DeltaTime * 10.0f , 0.0f ) ;
2014-08-19 11:09:13 +00:00
2015-03-21 13:59:19 +00:00
g . MouseCursor = ImGuiMouseCursor_Arrow ;
2017-09-06 15:25:36 +00:00
g . WantCaptureMouseNextFrame = g . WantCaptureKeyboardNextFrame = g . WantTextInputNextFrame = - 1 ;
2018-04-25 14:38:13 +00:00
g . PlatformImePos = ImVec2 ( 1.0f , 1.0f ) ; // OS Input Method Editor showing on top-left of our window by default
2014-08-19 11:09:13 +00:00
2018-01-20 11:36:16 +00:00
// Mouse wheel scrolling, scale
2018-07-22 16:57:28 +00:00
UpdateMouseWheel ( ) ;
2014-08-19 11:09:13 +00:00
// Pressing TAB activate widget focus
2019-03-05 16:38:36 +00:00
g . FocusTabPressed = ( g . NavWindow & & g . NavWindow - > Active & & ! ( g . NavWindow - > Flags & ImGuiWindowFlags_NoNavInputs ) & & ! g . IO . KeyCtrl & & IsKeyPressedMap ( ImGuiKey_Tab ) ) ;
if ( g . ActiveId = = 0 & & g . FocusTabPressed )
2016-08-23 06:58:51 +00:00
{
2019-03-05 18:37:20 +00:00
// 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 ;
2016-07-19 22:02:59 +00:00
if ( g . NavId ! = 0 & & g . NavIdTabCounter ! = INT_MAX )
2019-03-05 18:37:20 +00:00
g . FocusRequestNextCounterTab = g . NavIdTabCounter + 1 + ( g . IO . KeyShift ? - 1 : 1 ) ;
2016-07-19 22:02:59 +00:00
else
2019-03-05 18:37:20 +00:00
g . FocusRequestNextCounterTab = g . IO . KeyShift ? - 1 : 0 ;
2016-08-23 06:58:51 +00:00
}
2019-03-05 18:37:20 +00:00
// 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 ;
}
2016-07-19 22:02:59 +00:00
g . NavIdTabCounter = INT_MAX ;
2014-08-19 11:09:13 +00:00
2019-06-30 10:48:19 +00:00
// Mark all windows as not visible and compact unused memory.
2018-09-10 18:30:14 +00:00
IM_ASSERT ( g . WindowsFocusOrder . Size = = g . Windows . Size ) ;
2019-08-28 18:30:36 +00:00
const float memory_compact_start_time = ( g . IO . ConfigWindowsMemoryCompactTimer > = 0.0f ) ? ( float ) g . Time - g . IO . ConfigWindowsMemoryCompactTimer : FLT_MAX ;
2015-07-07 18:39:08 +00:00
for ( int i = 0 ; i ! = g . Windows . Size ; i + + )
2014-08-19 11:09:13 +00:00
{
ImGuiWindow * window = g . Windows [ i ] ;
2015-05-02 12:20:50 +00:00
window - > WasActive = window - > Active ;
2019-04-16 11:07:43 +00:00
window - > BeginCount = 0 ;
2015-05-02 12:20:50 +00:00
window - > Active = false ;
2017-11-18 23:07:38 +00:00
window - > WriteAccessed = false ;
2019-06-30 10:48:19 +00:00
// 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 ) ;
2014-08-19 11:09:13 +00:00
}
2016-07-17 17:17:49 +00:00
// Closing the focused window restore focus to the first active root window in descending z-order
2016-07-31 11:38:57 +00:00
if ( g . NavWindow & & ! g . NavWindow - > WasActive )
2019-04-28 19:52:12 +00:00
FocusTopMostWindowUnderOne ( NULL , NULL ) ;
2016-07-17 17:17:49 +00:00
2014-08-19 11:09:13 +00:00
// 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.
2015-02-01 14:39:13 +00:00
g . CurrentWindowStack . resize ( 0 ) ;
2018-12-14 17:44:17 +00:00
g . BeginPopupStack . resize ( 0 ) ;
2019-04-28 20:21:23 +00:00
ClosePopupsOverWindow ( g . NavWindow , false ) ;
2014-08-19 11:09:13 +00:00
2019-07-19 17:48:22 +00:00
// [DEBUG] Item picker tool - start with DebugStartItemPicker() - useful to visually select an item and break into its call-stack.
2019-07-21 19:13:44 +00:00
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.
SetNextWindowSize ( ImVec2 ( 400 , 400 ) , ImGuiCond_FirstUseEver ) ;
Begin ( " Debug##Default " ) ;
2019-11-13 20:35:42 +00:00
g . WithinFrameScopeWithImplicitWindow = true ;
2019-07-21 19:13:44 +00:00
# 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 ;
2019-07-19 17:48:22 +00:00
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 ( ) ;
}
2014-08-10 20:58:11 +00:00
}
Reorganized context handling to be more explicit,
- YOU NOW NEED TO CALL ImGui::CreateContext() AT THE BEGINNING OF YOUR APP, AND CALL ImGui::DestroyContext() AT THE END.
- removed Shutdown() function, as DestroyContext() serve this purpose.
- you may pass a ImFontAtlas* pointer to CreateContext() to share a font atlas between contexts. Otherwhise CreateContext() will create its own font atlas instance.
- removed allocator parameters from CreateContext(), they are now setup with SetAllocatorFunctions(), and shared by all contexts.
- removed the default global context and font atlas instance, which were confusing for users of DLL reloading and users of multiple contexts
(#1565, #586, #992, #1007, #1558)
2018-01-21 18:58:32 +00:00
void ImGui : : Initialize ( ImGuiContext * context )
2017-08-26 08:35:39 +00:00
{
Reorganized context handling to be more explicit,
- YOU NOW NEED TO CALL ImGui::CreateContext() AT THE BEGINNING OF YOUR APP, AND CALL ImGui::DestroyContext() AT THE END.
- removed Shutdown() function, as DestroyContext() serve this purpose.
- you may pass a ImFontAtlas* pointer to CreateContext() to share a font atlas between contexts. Otherwhise CreateContext() will create its own font atlas instance.
- removed allocator parameters from CreateContext(), they are now setup with SetAllocatorFunctions(), and shared by all contexts.
- removed the default global context and font atlas instance, which were confusing for users of DLL reloading and users of multiple contexts
(#1565, #586, #992, #1007, #1558)
2018-01-21 18:58:32 +00:00
ImGuiContext & g = * context ;
2018-02-18 22:25:48 +00:00
IM_ASSERT ( ! g . Initialized & & ! g . SettingsLoaded ) ;
2017-08-26 08:35:39 +00:00
2017-11-27 22:55:42 +00:00
// Add .ini handle for ImGuiWindow type
2019-11-06 21:52:48 +00:00
{
ImGuiSettingsHandler ini_handler ;
ini_handler . TypeName = " Window " ;
ini_handler . TypeHash = ImHashStr ( " Window " ) ;
ini_handler . ReadOpenFn = WindowSettingsHandler_ReadOpen ;
ini_handler . ReadLineFn = WindowSettingsHandler_ReadLine ;
ini_handler . WriteAllFn = WindowSettingsHandler_WriteAll ;
g . SettingsHandlers . push_back ( ini_handler ) ;
}
2017-11-27 22:55:42 +00:00
2017-08-26 08:35:39 +00:00
g . Initialized = true ;
}
// This function is merely here to free heap allocations.
Reorganized context handling to be more explicit,
- YOU NOW NEED TO CALL ImGui::CreateContext() AT THE BEGINNING OF YOUR APP, AND CALL ImGui::DestroyContext() AT THE END.
- removed Shutdown() function, as DestroyContext() serve this purpose.
- you may pass a ImFontAtlas* pointer to CreateContext() to share a font atlas between contexts. Otherwhise CreateContext() will create its own font atlas instance.
- removed allocator parameters from CreateContext(), they are now setup with SetAllocatorFunctions(), and shared by all contexts.
- removed the default global context and font atlas instance, which were confusing for users of DLL reloading and users of multiple contexts
(#1565, #586, #992, #1007, #1558)
2018-01-21 18:58:32 +00:00
void ImGui : : Shutdown ( ImGuiContext * context )
2014-08-10 20:58:11 +00:00
{
2015-11-07 23:10:01 +00:00
// The fonts atlas can be used prior to calling NewFrame(), so we clear it even if g.Initialized is FALSE (which would happen if we never called NewFrame)
2018-05-07 20:18:45 +00:00
ImGuiContext & g = * context ;
Reorganized context handling to be more explicit,
- YOU NOW NEED TO CALL ImGui::CreateContext() AT THE BEGINNING OF YOUR APP, AND CALL ImGui::DestroyContext() AT THE END.
- removed Shutdown() function, as DestroyContext() serve this purpose.
- you may pass a ImFontAtlas* pointer to CreateContext() to share a font atlas between contexts. Otherwhise CreateContext() will create its own font atlas instance.
- removed allocator parameters from CreateContext(), they are now setup with SetAllocatorFunctions(), and shared by all contexts.
- removed the default global context and font atlas instance, which were confusing for users of DLL reloading and users of multiple contexts
(#1565, #586, #992, #1007, #1558)
2018-01-21 18:58:32 +00:00
if ( g . IO . Fonts & & g . FontAtlasOwnedByContext )
2018-10-11 15:11:27 +00:00
{
g . IO . Fonts - > Locked = false ;
Reorganized context handling to be more explicit,
- YOU NOW NEED TO CALL ImGui::CreateContext() AT THE BEGINNING OF YOUR APP, AND CALL ImGui::DestroyContext() AT THE END.
- removed Shutdown() function, as DestroyContext() serve this purpose.
- you may pass a ImFontAtlas* pointer to CreateContext() to share a font atlas between contexts. Otherwhise CreateContext() will create its own font atlas instance.
- removed allocator parameters from CreateContext(), they are now setup with SetAllocatorFunctions(), and shared by all contexts.
- removed the default global context and font atlas instance, which were confusing for users of DLL reloading and users of multiple contexts
(#1565, #586, #992, #1007, #1558)
2018-01-21 18:58:32 +00:00
IM_DELETE ( g . IO . Fonts ) ;
2018-10-11 15:11:27 +00:00
}
2018-04-09 18:42:49 +00:00
g . IO . Fonts = NULL ;
2015-11-07 23:10:01 +00:00
2019-06-11 14:11:19 +00:00
// Cleanup of other data are conditional on actually having initialized Dear ImGui.
2014-08-19 11:09:13 +00:00
if ( ! g . Initialized )
return ;
2014-08-10 20:58:11 +00:00
2018-04-11 08:08:23 +00:00
// Save settings (unless we haven't attempted to load them: CreateContext/DestroyContext without a call to NewFrame shouldn't save an empty file)
2018-05-07 20:18:45 +00:00
if ( g . SettingsLoaded & & g . IO . IniFilename ! = NULL )
2018-09-07 15:23:55 +00:00
{
ImGuiContext * backup_context = GImGui ;
SetCurrentContext ( context ) ;
2018-04-11 08:08:23 +00:00
SaveIniSettingsToDisk ( g . IO . IniFilename ) ;
2018-09-07 15:23:55 +00:00
SetCurrentContext ( backup_context ) ;
}
2014-08-10 20:58:11 +00:00
2018-02-16 23:49:57 +00:00
// Clear everything else
2015-07-07 18:39:08 +00:00
for ( int i = 0 ; i < g . Windows . Size ; i + + )
2017-12-23 15:24:33 +00:00
IM_DELETE ( g . Windows [ i ] ) ;
2014-08-19 11:09:13 +00:00
g . Windows . clear ( ) ;
2018-09-10 18:30:14 +00:00
g . WindowsFocusOrder . clear ( ) ;
2015-03-26 18:51:45 +00:00
g . WindowsSortBuffer . clear ( ) ;
2016-09-20 10:41:21 +00:00
g . CurrentWindow = NULL ;
2014-08-19 11:09:13 +00:00
g . CurrentWindowStack . clear ( ) ;
2017-11-11 06:59:06 +00:00
g . WindowsById . Clear ( ) ;
2016-07-31 11:38:57 +00:00
g . NavWindow = NULL ;
2019-02-01 09:26:08 +00:00
g . HoveredWindow = g . HoveredRootWindow = NULL ;
2018-06-12 16:44:33 +00:00
g . ActiveIdWindow = g . ActiveIdPreviousFrameWindow = NULL ;
2017-10-27 10:01:52 +00:00
g . MovingWindow = NULL ;
2015-01-07 14:55:35 +00:00
g . ColorModifiers . clear ( ) ;
g . StyleModifiers . clear ( ) ;
2015-01-17 14:13:08 +00:00
g . FontStack . clear ( ) ;
2016-05-02 10:32:16 +00:00
g . OpenPopupStack . clear ( ) ;
2018-12-14 17:44:17 +00:00
g . BeginPopupStack . clear ( ) ;
2018-01-15 16:48:07 +00:00
g . DrawDataBuilder . ClearFreeMemory ( ) ;
2019-03-04 15:10:51 +00:00
g . BackgroundDrawList . ClearFreeMemory ( ) ;
2019-03-04 15:20:32 +00:00
g . ForegroundDrawList . ClearFreeMemory ( ) ;
2019-07-23 18:50:41 +00:00
g . TabBars . Clear ( ) ;
g . CurrentTabBarStack . clear ( ) ;
g . ShrinkWidthBuffer . clear ( ) ;
2016-07-30 08:02:46 +00:00
g . PrivateClipboard . clear ( ) ;
2019-02-21 11:35:21 +00:00
g . InputTextState . ClearFreeMemory ( ) ;
2014-08-14 14:03:10 +00:00
2017-11-27 22:55:42 +00:00
g . SettingsWindows . clear ( ) ;
g . SettingsHandlers . clear ( ) ;
2019-11-19 20:14:44 +00:00
if ( g . LogFile )
2015-03-21 00:41:34 +00:00
{
2019-11-19 20:14:44 +00:00
# ifndef IMGUI_DISABLE_TTY_FUNCTIONS
if ( g . LogFile ! = stdout )
# endif
ImFileClose ( g . LogFile ) ;
2015-03-21 00:41:34 +00:00
g . LogFile = NULL ;
}
2019-02-23 14:24:01 +00:00
g . LogBuffer . clear ( ) ;
2014-08-16 08:28:29 +00:00
2014-08-19 11:09:13 +00:00
g . Initialized = false ;
2014-08-10 20:58:11 +00:00
}
2015-02-08 17:21:51 +00:00
// FIXME: Add a more explicit sort order in the window structure.
2018-02-12 08:50:40 +00:00
static int IMGUI_CDECL ChildWindowComparer ( const void * lhs , const void * rhs )
2015-02-08 17:21:51 +00:00
{
2018-04-03 21:18:43 +00:00
const ImGuiWindow * const a = * ( const ImGuiWindow * const * ) lhs ;
const ImGuiWindow * const b = * ( const ImGuiWindow * const * ) rhs ;
2015-03-26 17:09:17 +00:00
if ( int d = ( a - > Flags & ImGuiWindowFlags_Popup ) - ( b - > Flags & ImGuiWindowFlags_Popup ) )
return d ;
2015-02-08 17:21:51 +00:00
if ( int d = ( a - > Flags & ImGuiWindowFlags_Tooltip ) - ( b - > Flags & ImGuiWindowFlags_Tooltip ) )
return d ;
2017-12-12 22:36:25 +00:00
return ( a - > BeginOrderWithinParent - b - > BeginOrderWithinParent ) ;
2015-02-08 17:21:51 +00:00
}
2018-09-10 18:30:14 +00:00
static void AddWindowToSortBuffer ( ImVector < ImGuiWindow * > * out_sorted_windows , ImGuiWindow * window )
2014-08-10 20:58:11 +00:00
{
2018-01-25 18:07:35 +00:00
out_sorted_windows - > push_back ( window ) ;
2015-05-02 12:20:50 +00:00
if ( window - > Active )
2014-08-19 11:09:13 +00:00
{
2015-07-07 18:39:08 +00:00
int count = window - > DC . ChildWindows . Size ;
2015-02-08 17:21:51 +00:00
if ( count > 1 )
2019-05-10 15:24:22 +00:00
ImQsort ( window - > DC . ChildWindows . Data , ( size_t ) count , sizeof ( ImGuiWindow * ) , ChildWindowComparer ) ;
2015-07-07 18:09:25 +00:00
for ( int i = 0 ; i < count ; i + + )
2014-08-19 11:09:13 +00:00
{
ImGuiWindow * child = window - > DC . ChildWindows [ i ] ;
2015-05-02 12:20:50 +00:00
if ( child - > Active )
2018-09-10 18:30:14 +00:00
AddWindowToSortBuffer ( out_sorted_windows , child ) ;
2014-08-19 11:09:13 +00:00
}
}
2014-08-10 20:58:11 +00:00
}
2018-04-25 14:38:13 +00:00
static void AddDrawListToDrawData ( ImVector < ImDrawList * > * out_list , ImDrawList * draw_list )
2015-07-21 23:00:28 +00:00
{
2016-02-14 09:33:56 +00:00
if ( draw_list - > CmdBuffer . empty ( ) )
return ;
// Remove trailing command if unused
ImDrawCmd & last_cmd = draw_list - > CmdBuffer . back ( ) ;
if ( last_cmd . ElemCount = = 0 & & last_cmd . UserCallback = = NULL )
2015-07-21 23:00:28 +00:00
{
2016-02-14 09:33:56 +00:00
draw_list - > CmdBuffer . pop_back ( ) ;
if ( draw_list - > CmdBuffer . empty ( ) )
return ;
2015-07-21 23:00:28 +00:00
}
2016-02-14 09:33:56 +00:00
2019-09-17 09:33:18 +00:00
// Draw list sanity check. Detect mismatch between PrimReserve() calls and incrementing _VtxCurrentIdx, _VtxWritePtr etc.
2019-05-29 13:25:53 +00:00
// May trigger for you if you are using PrimXXX functions incorrectly.
2016-09-03 17:02:57 +00:00
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 ) ;
2019-05-29 13:25:53 +00:00
if ( ! ( draw_list - > Flags & ImDrawListFlags_AllowVtxOffset ) )
IM_ASSERT ( ( int ) draw_list - > _VtxCurrentIdx = = draw_list - > VtxBuffer . Size ) ;
2016-04-23 09:09:56 +00:00
2018-01-15 16:48:07 +00:00
// Check that draw_list doesn't use more vertices than indexable (default ImDrawIdx = unsigned short = 2 bytes = 64K vertices per ImDrawList = per window)
2017-12-23 14:02:36 +00:00
// If this assert triggers because you are drawing lots of stuff manually:
2019-09-17 09:33:18 +00:00
// - First, make sure you are coarse clipping yourself and not trying to draw many things outside visible bounds.
2019-05-29 13:25:53 +00:00
// 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:
2019-05-29 14:29:17 +00:00
// (A) Handle the ImDrawCmd::VtxOffset value in your renderer back-end, and set 'io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset'.
2019-05-29 13:25:53 +00:00
// 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.
2019-11-20 10:58:25 +00:00
// (B) Or handle 32-bit indices in your renderer back-end, and uncomment '#define ImDrawIdx unsigned int' line in imconfig.h.
2019-05-29 13:25:53 +00:00
// 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);
2019-09-17 09:33:18 +00:00
// Your own engine or render API may use different parameters or function calls to specify index sizes.
2019-05-29 13:25:53 +00:00
// 2 and 4 bytes indices are generally supported by most graphics API.
2019-09-17 09:33:18 +00:00
// - If for some reason neither of those solutions works for you, a workaround is to call BeginChild()/EndChild() before reaching
2019-05-29 13:25:53 +00:00
// the 64K limit to split your draw commands in multiple draw lists.
2017-12-23 14:02:36 +00:00
if ( sizeof ( ImDrawIdx ) = = 2 )
IM_ASSERT ( draw_list - > _VtxCurrentIdx < ( 1 < < 16 ) & & " Too many vertices in ImDrawList using 16-bit indices. Read comment above " ) ;
2018-04-25 14:38:13 +00:00
out_list - > push_back ( draw_list ) ;
2015-07-21 23:00:28 +00:00
}
2018-01-15 18:09:10 +00:00
static void AddWindowToDrawData ( ImVector < ImDrawList * > * out_render_list , ImGuiWindow * window )
2015-07-21 23:00:28 +00:00
{
2018-08-03 16:12:36 +00:00
ImGuiContext & g = * GImGui ;
g . IO . MetricsRenderWindows + + ;
2018-01-15 18:09:10 +00:00
AddDrawListToDrawData ( out_render_list , window - > DrawList ) ;
2015-07-21 23:00:28 +00:00
for ( int i = 0 ; i < window - > DC . ChildWindows . Size ; i + + )
{
ImGuiWindow * child = window - > DC . ChildWindows [ i ] ;
2018-06-27 15:21:59 +00:00
if ( IsWindowActiveAndVisible ( child ) ) // clipped children may have been marked not active
2018-01-15 18:09:10 +00:00
AddWindowToDrawData ( out_render_list , child ) ;
2015-07-21 23:00:28 +00:00
}
}
2019-04-16 11:07:43 +00:00
// Layer is locked for the root window, however child windows may use a different viewport (e.g. extruding menu)
2019-02-01 09:26:08 +00:00
static void AddRootWindowToDrawData ( ImGuiWindow * window )
2016-07-19 22:02:59 +00:00
{
ImGuiContext & g = * GImGui ;
2018-01-15 16:48:07 +00:00
if ( window - > Flags & ImGuiWindowFlags_Tooltip )
2018-01-15 18:09:10 +00:00
AddWindowToDrawData ( & g . DrawDataBuilder . Layers [ 1 ] , window ) ;
2016-07-19 22:02:59 +00:00
else
2018-01-15 18:09:10 +00:00
AddWindowToDrawData ( & g . DrawDataBuilder . Layers [ 0 ] , window ) ;
2018-01-15 16:48:07 +00:00
}
void ImDrawDataBuilder : : FlattenIntoSingleLayer ( )
{
int n = Layers [ 0 ] . Size ;
int size = n ;
for ( int i = 1 ; i < IM_ARRAYSIZE ( Layers ) ; i + + )
size + = Layers [ i ] . Size ;
Layers [ 0 ] . resize ( size ) ;
for ( int layer_n = 1 ; layer_n < IM_ARRAYSIZE ( Layers ) ; layer_n + + )
{
ImVector < ImDrawList * > & layer = Layers [ layer_n ] ;
if ( layer . empty ( ) )
continue ;
memcpy ( & Layers [ 0 ] [ n ] , & layer [ 0 ] , layer . Size * sizeof ( ImDrawList * ) ) ;
n + = layer . Size ;
layer . resize ( 0 ) ;
}
}
2018-09-05 09:52:48 +00:00
static void SetupDrawData ( ImVector < ImDrawList * > * draw_lists , ImDrawData * draw_data )
2018-01-15 16:48:07 +00:00
{
2018-06-08 17:37:33 +00:00
ImGuiIO & io = ImGui : : GetIO ( ) ;
2018-09-05 09:52:48 +00:00
draw_data - > Valid = true ;
draw_data - > CmdLists = ( draw_lists - > Size > 0 ) ? draw_lists - > Data : NULL ;
draw_data - > CmdListsCount = draw_lists - > Size ;
draw_data - > TotalVtxCount = draw_data - > TotalIdxCount = 0 ;
draw_data - > DisplayPos = ImVec2 ( 0.0f , 0.0f ) ;
draw_data - > DisplaySize = io . DisplaySize ;
2019-02-11 17:38:07 +00:00
draw_data - > FramebufferScale = io . DisplayFramebufferScale ;
2018-01-15 18:09:10 +00:00
for ( int n = 0 ; n < draw_lists - > Size ; n + + )
2018-01-15 16:48:07 +00:00
{
2018-09-05 09:52:48 +00:00
draw_data - > TotalVtxCount + = draw_lists - > Data [ n ] - > VtxBuffer . Size ;
draw_data - > TotalIdxCount + = draw_lists - > Data [ n ] - > IdxBuffer . Size ;
2018-01-15 16:48:07 +00:00
}
2016-07-19 22:02:59 +00:00
}
2016-04-30 16:55:23 +00:00
// When using this function it is sane to ensure that float are perfectly rounded to integer values, to that e.g. (int)(max.x-min.x) in user's render produce correct result.
2016-04-26 09:03:51 +00:00
void ImGui : : PushClipRect ( const ImVec2 & clip_rect_min , const ImVec2 & clip_rect_max , bool intersect_with_current_clip_rect )
2014-08-10 20:58:11 +00:00
{
2015-12-24 13:47:11 +00:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2016-04-26 09:03:51 +00:00
window - > DrawList - > PushClipRect ( clip_rect_min , clip_rect_max , intersect_with_current_clip_rect ) ;
window - > ClipRect = window - > DrawList - > _ClipRectStack . back ( ) ;
2014-08-10 20:58:11 +00:00
}
2015-12-24 13:47:11 +00:00
void ImGui : : PopClipRect ( )
2014-08-10 20:58:11 +00:00
{
2015-12-24 13:47:11 +00:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2014-08-19 11:09:13 +00:00
window - > DrawList - > PopClipRect ( ) ;
2015-07-08 02:17:07 +00:00
window - > ClipRect = window - > DrawList - > _ClipRectStack . back ( ) ;
2014-08-10 20:58:11 +00:00
}
2015-09-16 22:48:42 +00:00
// This is normally called by Render(). You may want to call it directly if you want to avoid calling Render() but the gain will be very minimal.
void ImGui : : EndFrame ( )
2014-08-10 20:58:11 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2018-07-30 16:20:25 +00:00
IM_ASSERT ( g . Initialized ) ;
2017-11-19 11:04:54 +00:00
if ( g . FrameCountEnded = = g . FrameCount ) // Don't process EndFrame() multiple times.
return ;
2019-11-13 20:35:42 +00:00
IM_ASSERT ( g . WithinFrameScope & & " Forgot to call ImGui::NewFrame()? " ) ;
2014-08-19 11:09:13 +00:00
2015-11-29 14:15:07 +00:00
// Notify OS when our Input Method Editor cursor has moved (e.g. CJK inputs using Microsoft IME)
2019-01-21 15:43:07 +00:00
if ( g . IO . ImeSetInputScreenPosFn & & ( g . PlatformImeLastPos . x = = FLT_MAX | | ImLengthSqr ( g . PlatformImeLastPos - g . PlatformImePos ) > 0.0001f ) )
2015-11-29 14:15:07 +00:00
{
2018-04-25 14:38:13 +00:00
g . IO . ImeSetInputScreenPosFn ( ( int ) g . PlatformImePos . x , ( int ) g . PlatformImePos . y ) ;
g . PlatformImeLastPos = g . PlatformImePos ;
2015-11-29 14:15:07 +00:00
}
2019-11-13 20:35:42 +00:00
ErrorCheckEndFrame ( ) ;
2018-12-23 16:39:04 +00:00
// Hide implicit/fallback "Debug" window if it hasn't been used
2019-11-13 20:35:42 +00:00
g . WithinFrameScopeWithImplicitWindow = false ;
2017-11-18 23:07:38 +00:00
if ( g . CurrentWindow & & ! g . CurrentWindow - > WriteAccessed )
2015-09-16 22:48:42 +00:00
g . CurrentWindow - > Active = false ;
2017-12-28 22:50:37 +00:00
End ( ) ;
2014-08-19 11:09:13 +00:00
2019-01-02 21:52:09 +00:00
// Show CTRL+TAB list window
2019-09-09 09:09:41 +00:00
if ( g . NavWindowingTarget ! = NULL )
NavUpdateWindowingOverlay ( ) ;
2019-01-02 21:56:17 +00:00
// Drag and Drop: Elapse payload (if delivered, or if source stops being submitted)
if ( g . DragDropActive )
{
bool is_delivered = g . DragDropPayload . Delivery ;
bool is_elapsed = ( g . DragDropPayload . DataFrameCount + 1 < g . FrameCount ) & & ( ( g . DragDropSourceFlags & ImGuiDragDropFlags_SourceAutoExpirePayload ) | | ! IsMouseDown ( g . DragDropMouseButton ) ) ;
if ( is_delivered | | is_elapsed )
ClearDragDrop ( ) ;
}
// Drag and Drop: Fallback for source tooltip. This is not ideal but better than nothing.
if ( g . DragDropActive & & g . DragDropSourceFrameCount < g . FrameCount )
{
g . DragDropWithinSourceOrTarget = true ;
SetTooltip ( " ... " ) ;
g . DragDropWithinSourceOrTarget = false ;
}
2019-01-02 21:52:09 +00:00
// End frame
2019-11-13 20:35:42 +00:00
g . WithinFrameScope = false ;
2019-01-02 21:52:09 +00:00
g . FrameCountEnded = g . FrameCount ;
2019-01-02 22:05:59 +00:00
// Initiate moving window + handle left-click and right-click focus
UpdateMouseMovingWindowEndFrame ( ) ;
2015-01-16 10:55:49 +00:00
2015-09-16 22:48:42 +00:00
// Sort the window list so that all child windows are after their parent
// We cannot do that on FocusWindow() because childs may not exist yet
g . WindowsSortBuffer . resize ( 0 ) ;
g . WindowsSortBuffer . reserve ( g . Windows . Size ) ;
for ( int i = 0 ; i ! = g . Windows . Size ; i + + )
{
ImGuiWindow * window = g . Windows [ i ] ;
2015-11-29 14:15:07 +00:00
if ( window - > Active & & ( window - > Flags & ImGuiWindowFlags_ChildWindow ) ) // if a child is active its parent will add it
continue ;
2018-09-10 18:30:14 +00:00
AddWindowToSortBuffer ( & g . WindowsSortBuffer , window ) ;
2014-08-19 11:09:13 +00:00
}
2016-07-19 22:02:59 +00:00
2019-02-01 09:26:08 +00:00
// This usually assert if there is a mismatch between the ImGuiWindowFlags_ChildWindow / ParentWindow values and DC.ChildWindows[] in parents, aka we've done something wrong.
IM_ASSERT ( g . Windows . Size = = g . WindowsSortBuffer . Size ) ;
2015-09-16 22:48:42 +00:00
g . Windows . swap ( g . WindowsSortBuffer ) ;
2018-08-03 16:12:36 +00:00
g . IO . MetricsActiveWindows = g . WindowsActiveCount ;
2015-09-16 22:48:42 +00:00
2018-07-22 16:53:27 +00:00
// Unlock font atlas
g . IO . Fonts - > Locked = false ;
2015-09-16 22:48:42 +00:00
// Clear Input data for next frame
2018-01-20 11:36:16 +00:00
g . IO . MouseWheel = g . IO . MouseWheelH = 0.0f ;
2019-01-06 15:37:42 +00:00
g . IO . InputQueueCharacters . resize ( 0 ) ;
2018-02-06 18:54:30 +00:00
memset ( g . IO . NavInputs , 0 , sizeof ( g . IO . NavInputs ) ) ;
2015-09-16 22:48:42 +00:00
}
void ImGui : : Render ( )
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2018-07-30 16:20:25 +00:00
IM_ASSERT ( g . Initialized ) ;
2015-09-16 22:48:42 +00:00
if ( g . FrameCountEnded ! = g . FrameCount )
2018-11-15 15:43:05 +00:00
EndFrame ( ) ;
2015-09-16 22:48:42 +00:00
g . FrameCountRendered = g . FrameCount ;
2014-08-19 11:09:13 +00:00
2018-08-09 16:07:49 +00:00
// Gather ImDrawList to render (for each active window)
2018-08-03 16:12:36 +00:00
g . IO . MetricsRenderVertices = g . IO . MetricsRenderIndices = g . IO . MetricsRenderWindows = 0 ;
2018-03-05 21:47:53 +00:00
g . DrawDataBuilder . Clear ( ) ;
2019-03-04 15:10:51 +00:00
if ( ! g . BackgroundDrawList . VtxBuffer . empty ( ) )
AddDrawListToDrawData ( & g . DrawDataBuilder . Layers [ 0 ] , & g . BackgroundDrawList ) ;
2019-06-19 16:14:24 +00:00
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 ;
2018-03-05 21:47:53 +00:00
for ( int n = 0 ; n ! = g . Windows . Size ; n + + )
{
ImGuiWindow * window = g . Windows [ n ] ;
2019-06-19 16:14:24 +00:00
if ( IsWindowActiveAndVisible ( window ) & & ( window - > Flags & ImGuiWindowFlags_ChildWindow ) = = 0 & & window ! = windows_to_render_top_most [ 0 ] & & window ! = windows_to_render_top_most [ 1 ] )
2019-02-01 09:26:08 +00:00
AddRootWindowToDrawData ( window ) ;
2018-03-05 21:47:53 +00:00
}
2019-06-19 16:14:24 +00:00
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 top-most window
AddRootWindowToDrawData ( windows_to_render_top_most [ n ] ) ;
2018-03-05 21:47:53 +00:00
g . DrawDataBuilder . FlattenIntoSingleLayer ( ) ;
// Draw software mouse cursor if requested
2018-08-09 16:07:49 +00:00
if ( g . IO . MouseDrawCursor )
2019-09-23 12:53:49 +00:00
RenderMouseCursor ( & g . ForegroundDrawList , g . IO . MousePos , g . Style . MouseCursorScale , g . MouseCursor , IM_COL32_WHITE , IM_COL32_BLACK , IM_COL32 ( 0 , 0 , 0 , 48 ) ) ;
2018-08-09 16:07:49 +00:00
2019-03-04 15:20:32 +00:00
if ( ! g . ForegroundDrawList . VtxBuffer . empty ( ) )
AddDrawListToDrawData ( & g . DrawDataBuilder . Layers [ 0 ] , & g . ForegroundDrawList ) ;
2018-03-05 21:47:53 +00:00
// Setup ImDrawData structure for end-user
SetupDrawData ( & g . DrawDataBuilder . Layers [ 0 ] , & g . DrawData ) ;
g . IO . MetricsRenderVertices = g . DrawData . TotalVtxCount ;
g . IO . MetricsRenderIndices = g . DrawData . TotalIdxCount ;
2018-12-23 16:39:04 +00:00
// (Legacy) Call the Render callback function. The current prefer way is to let the user retrieve GetDrawData() and call the render function themselves.
2018-02-16 18:18:16 +00:00
# ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
2018-03-05 21:47:53 +00:00
if ( g . DrawData . CmdListsCount > 0 & & g . IO . RenderDrawListsFn ! = NULL )
g . IO . RenderDrawListsFn ( & g . DrawData ) ;
2018-02-16 18:18:16 +00:00
# endif
2014-08-10 20:58:11 +00:00
}
2014-09-02 13:35:06 +00:00
// Calculate text size. Text can be multi-line. Optionally ignore text after a ## marker.
2019-10-05 14:53:28 +00:00
// CalcTextSize("") should return ImVec2(0.0f, g.FontSize)
2014-11-30 12:21:50 +00:00
ImVec2 ImGui : : CalcTextSize ( const char * text , const char * text_end , bool hide_text_after_double_hash , float wrap_width )
2014-08-10 20:58:11 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2014-08-10 20:58:11 +00:00
2014-08-19 11:09:13 +00:00
const char * text_display_end ;
2014-11-30 12:21:50 +00:00
if ( hide_text_after_double_hash )
2016-03-21 19:33:48 +00:00
text_display_end = FindRenderedTextEnd ( text , text_end ) ; // Hide anything after a '##' string
2014-08-19 11:09:13 +00:00
else
text_display_end = text_end ;
2014-08-10 20:58:11 +00:00
2015-03-29 18:45:03 +00:00
ImFont * font = g . Font ;
const float font_size = g . FontSize ;
2016-01-16 12:11:57 +00:00
if ( text = = text_display_end )
return ImVec2 ( 0.0f , font_size ) ;
2015-01-22 23:02:44 +00:00
ImVec2 text_size = font - > CalcTextSizeA ( font_size , FLT_MAX , wrap_width , text , text_display_end , NULL ) ;
2019-02-12 21:43:56 +00:00
// Round
2019-10-17 09:36:26 +00:00
text_size . x = IM_FLOOR ( text_size . x + 0.95f ) ;
2015-01-22 23:02:44 +00:00
2014-11-07 05:45:56 +00:00
return text_size ;
2014-08-10 20:58:11 +00:00
}
2014-09-02 13:35:06 +00:00
// Find window given position, search front-to-back
2019-01-20 16:56:17 +00:00
// 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
2018-09-05 09:52:48 +00:00
// called, aka before the next Begin(). Moving window isn't affected.
2018-07-09 19:06:46 +00:00
static void FindHoveredWindow ( )
2014-08-10 20:58:11 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2018-07-09 19:06:46 +00:00
ImGuiWindow * hovered_window = NULL ;
2018-10-15 16:23:18 +00:00
if ( g . MovingWindow & & ! ( g . MovingWindow - > Flags & ImGuiWindowFlags_NoMouseInputs ) )
2018-07-09 19:06:46 +00:00
hovered_window = g . MovingWindow ;
2018-10-02 16:43:10 +00:00
ImVec2 padding_regular = g . Style . TouchExtraPadding ;
2018-12-10 14:36:07 +00:00
ImVec2 padding_for_resize_from_edges = g . IO . ConfigWindowsResizeFromEdges ? ImMax ( g . Style . TouchExtraPadding , ImVec2 ( WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS , WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS ) ) : padding_regular ;
for ( int i = g . Windows . Size - 1 ; i > = 0 ; i - - )
2014-08-19 11:09:13 +00:00
{
2015-07-07 18:09:25 +00:00
ImGuiWindow * window = g . Windows [ i ] ;
2018-06-27 15:21:59 +00:00
if ( ! window - > Active | | window - > Hidden )
2014-08-19 11:09:13 +00:00
continue ;
2018-10-15 16:23:18 +00:00
if ( window - > Flags & ImGuiWindowFlags_NoMouseInputs )
2015-07-17 22:36:04 +00:00
continue ;
2015-02-22 12:05:38 +00:00
2017-10-25 20:02:06 +00:00
// Using the clipped AABB, a child window will typically be clipped by its parent (not always)
2018-10-02 16:43:10 +00:00
ImRect bb ( window - > OuterRectClipped ) ;
2019-04-25 09:46:55 +00:00
if ( window - > Flags & ( ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize ) )
2018-10-02 16:43:10 +00:00
bb . Expand ( padding_regular ) ;
else
bb . Expand ( padding_for_resize_from_edges ) ;
if ( ! bb . Contains ( g . IO . MousePos ) )
continue ;
// Those seemingly unnecessary extra tests are because the code here is a little different in viewport/docking branches.
if ( hovered_window = = NULL )
hovered_window = window ;
if ( hovered_window )
break ;
2014-08-19 11:09:13 +00:00
}
2018-07-09 19:06:46 +00:00
g . HoveredWindow = hovered_window ;
g . HoveredRootWindow = g . HoveredWindow ? g . HoveredWindow - > RootWindow : NULL ;
2014-08-10 20:58:11 +00:00
}
2015-03-17 23:35:12 +00:00
// Test if mouse cursor is hovering given rectangle
2015-03-17 23:41:20 +00:00
// NB- Rectangle is clipped by our current clip setting
// NB- Expand the rectangle to be generous on imprecise inputs systems (g.Style.TouchExtraPadding)
2016-03-21 21:11:43 +00:00
bool ImGui : : IsMouseHoveringRect ( const ImVec2 & r_min , const ImVec2 & r_max , bool clip )
2014-08-10 20:58:11 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2014-08-10 20:58:11 +00:00
2014-08-19 11:09:13 +00:00
// Clip
2016-03-21 21:11:43 +00:00
ImRect rect_clipped ( r_min , r_max ) ;
2015-09-03 12:13:13 +00:00
if ( clip )
2018-04-13 14:54:40 +00:00
rect_clipped . ClipWith ( g . CurrentWindow - > ClipRect ) ;
2014-08-10 20:58:11 +00:00
2014-08-19 11:09:13 +00:00
// Expand for touch input
2015-03-17 23:41:20 +00:00
const ImRect rect_for_touch ( rect_clipped . Min - g . Style . TouchExtraPadding , rect_clipped . Max + g . Style . TouchExtraPadding ) ;
2018-09-05 09:52:48 +00:00
if ( ! rect_for_touch . Contains ( g . IO . MousePos ) )
return false ;
return true ;
2014-08-10 20:58:11 +00:00
}
2017-05-27 15:55:48 +00:00
int ImGui : : GetKeyIndex ( ImGuiKey imgui_key )
2015-07-03 03:32:29 +00:00
{
2017-05-27 15:55:48 +00:00
IM_ASSERT ( imgui_key > = 0 & & imgui_key < ImGuiKey_COUNT ) ;
2019-07-30 23:48:15 +00:00
ImGuiContext & g = * GImGui ;
return g . IO . KeyMap [ imgui_key ] ;
2015-07-03 03:32:29 +00:00
}
2019-12-06 15:06:29 +00:00
// Note that dear 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[]!
2017-05-27 15:55:48 +00:00
bool ImGui : : IsKeyDown ( int user_key_index )
2015-04-28 16:12:24 +00:00
{
2019-09-17 09:33:18 +00:00
if ( user_key_index < 0 )
2019-07-30 23:48:15 +00:00
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 ] ;
2015-04-28 16:12:24 +00:00
}
2019-10-14 21:07:06 +00:00
// t0 = previous time (e.g.: g.Time - g.IO.DeltaTime)
// t1 = current time (e.g.: g.Time)
// An event is triggered at:
// t = 0.0f t = repeat_delay, t = repeat_delay + repeat_rate*N
int ImGui : : CalcTypematicRepeatAmount ( float t0 , float t1 , float repeat_delay , float repeat_rate )
2016-08-03 21:23:04 +00:00
{
2019-10-14 21:07:06 +00:00
if ( t1 = = 0.0f )
2016-08-03 21:23:04 +00:00
return 1 ;
2019-10-14 21:07:06 +00:00
if ( t0 > = t1 )
2016-08-03 21:23:04 +00:00
return 0 ;
2019-10-14 21:07:06 +00:00
if ( repeat_rate < = 0.0f )
return ( t0 < repeat_delay ) & & ( t1 > = repeat_delay ) ;
const int count_t0 = ( t0 < repeat_delay ) ? - 1 : ( int ) ( ( t0 - repeat_delay ) / repeat_rate ) ;
const int count_t1 = ( t1 < repeat_delay ) ? - 1 : ( int ) ( ( t1 - repeat_delay ) / repeat_rate ) ;
const int count = count_t1 - count_t0 ;
return count ;
2016-08-03 21:23:04 +00:00
}
2016-07-19 19:26:36 +00:00
int ImGui : : GetKeyPressedAmount ( int key_index , float repeat_delay , float repeat_rate )
2014-08-10 20:58:11 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2019-03-16 14:48:21 +00:00
if ( key_index < 0 )
2019-01-27 14:27:49 +00:00
return 0 ;
2014-08-19 11:09:13 +00:00
IM_ASSERT ( key_index > = 0 & & key_index < IM_ARRAYSIZE ( g . IO . KeysDown ) ) ;
2015-06-22 01:04:43 +00:00
const float t = g . IO . KeysDownDuration [ key_index ] ;
2019-10-14 21:07:06 +00:00
return CalcTypematicRepeatAmount ( t - g . IO . DeltaTime , t , repeat_delay , repeat_rate ) ;
2015-06-22 01:04:43 +00:00
}
2017-08-07 14:51:18 +00:00
bool ImGui : : IsKeyPressed ( int user_key_index , bool repeat )
2016-07-16 08:46:22 +00:00
{
ImGuiContext & g = * GImGui ;
2019-03-16 14:48:21 +00:00
if ( user_key_index < 0 )
2019-01-27 14:27:49 +00:00
return false ;
2017-05-27 15:55:48 +00:00
IM_ASSERT ( user_key_index > = 0 & & user_key_index < IM_ARRAYSIZE ( g . IO . KeysDown ) ) ;
const float t = g . IO . KeysDownDuration [ user_key_index ] ;
2014-08-19 11:09:13 +00:00
if ( t = = 0.0f )
return true ;
2015-05-27 14:17:44 +00:00
if ( repeat & & t > g . IO . KeyRepeatDelay )
2017-08-07 14:51:18 +00:00
return GetKeyPressedAmount ( user_key_index , g . IO . KeyRepeatDelay , g . IO . KeyRepeatRate ) > 0 ;
2015-06-22 01:04:43 +00:00
return false ;
2016-07-16 08:46:22 +00:00
}
2017-05-27 15:55:48 +00:00
bool ImGui : : IsKeyReleased ( int user_key_index )
2015-06-22 01:04:43 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2017-05-27 15:55:48 +00:00
if ( user_key_index < 0 ) return false ;
IM_ASSERT ( user_key_index > = 0 & & user_key_index < IM_ARRAYSIZE ( g . IO . KeysDown ) ) ;
2018-01-21 16:02:09 +00:00
return g . IO . KeysDownDurationPrev [ user_key_index ] > = 0.0f & & ! g . IO . KeysDown [ user_key_index ] ;
2014-08-10 20:58:11 +00:00
}
2019-12-06 15:29:22 +00:00
bool ImGui : : IsMouseDown ( ImGuiMouseButton button )
2015-04-28 16:12:24 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2015-04-28 16:12:24 +00:00
IM_ASSERT ( button > = 0 & & button < IM_ARRAYSIZE ( g . IO . MouseDown ) ) ;
return g . IO . MouseDown [ button ] ;
}
2019-12-06 15:29:22 +00:00
bool ImGui : : IsMouseClicked ( ImGuiMouseButton button , bool repeat )
2014-08-10 20:58:11 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2014-08-19 11:09:13 +00:00
IM_ASSERT ( button > = 0 & & button < IM_ARRAYSIZE ( g . IO . MouseDown ) ) ;
2015-06-22 00:15:31 +00:00
const float t = g . IO . MouseDownDuration [ button ] ;
2014-08-19 11:09:13 +00:00
if ( t = = 0.0f )
return true ;
2014-08-10 20:58:11 +00:00
2015-05-27 14:17:44 +00:00
if ( repeat & & t > g . IO . KeyRepeatDelay )
{
2019-05-03 13:06:06 +00:00
// 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.
2019-10-14 21:07:06 +00:00
int amount = CalcTypematicRepeatAmount ( t - g . IO . DeltaTime , t , g . IO . KeyRepeatDelay , g . IO . KeyRepeatRate * 0.50f ) ;
2019-05-03 13:06:06 +00:00
if ( amount > 0 )
2014-08-19 11:09:13 +00:00
return true ;
2015-05-27 14:17:44 +00:00
}
2014-08-19 11:09:13 +00:00
return false ;
2014-08-10 20:58:11 +00:00
}
2019-12-06 15:29:22 +00:00
bool ImGui : : IsMouseReleased ( ImGuiMouseButton button )
2015-06-22 00:15:31 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2015-06-22 00:15:31 +00:00
IM_ASSERT ( button > = 0 & & button < IM_ARRAYSIZE ( g . IO . MouseDown ) ) ;
return g . IO . MouseReleased [ button ] ;
}
2019-12-06 15:29:22 +00:00
bool ImGui : : IsMouseDoubleClicked ( ImGuiMouseButton button )
2014-08-12 18:57:46 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2014-08-19 11:09:13 +00:00
IM_ASSERT ( button > = 0 & & button < IM_ARRAYSIZE ( g . IO . MouseDown ) ) ;
return g . IO . MouseDoubleClicked [ button ] ;
2014-08-12 18:57:46 +00:00
}
2019-08-15 17:03:07 +00:00
// [Internal] This doesn't test if the button is pressed
2019-12-06 15:29:22 +00:00
bool ImGui : : IsMouseDragPastThreshold ( ImGuiMouseButton button , float lock_threshold )
2015-03-20 11:13:18 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2015-03-20 11:13:18 +00:00
IM_ASSERT ( button > = 0 & & button < IM_ARRAYSIZE ( g . IO . MouseDown ) ) ;
if ( lock_threshold < 0.0f )
lock_threshold = g . IO . MouseDragThreshold ;
return g . IO . MouseDragMaxDistanceSqr [ button ] > = lock_threshold * lock_threshold ;
}
2019-12-06 15:29:22 +00:00
bool ImGui : : IsMouseDragging ( ImGuiMouseButton button , float lock_threshold )
2019-07-26 19:08:29 +00:00
{
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 ) ;
}
2014-11-10 01:29:01 +00:00
ImVec2 ImGui : : GetMousePos ( )
2014-08-10 20:58:11 +00:00
{
2019-12-06 15:06:29 +00:00
ImGuiContext & g = * GImGui ;
return g . IO . MousePos ;
2014-08-10 20:58:11 +00:00
}
2015-08-25 12:35:25 +00:00
// NB: prefer to call right after BeginPopup(). At the time Selectable/MenuItem is activated, the popup is already closed!
2015-08-15 21:10:07 +00:00
ImVec2 ImGui : : GetMousePosOnOpeningCurrentPopup ( )
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2018-12-14 17:44:17 +00:00
if ( g . BeginPopupStack . Size > 0 )
return g . OpenPopupStack [ g . BeginPopupStack . Size - 1 ] . OpenMousePos ;
2015-08-25 11:40:40 +00:00
return g . IO . MousePos ;
2015-08-15 21:10:07 +00:00
}
2019-01-27 14:27:49 +00:00
// We typically use ImVec2(-FLT_MAX,-FLT_MAX) to denote an invalid mouse position.
2017-08-26 07:18:06 +00:00
bool ImGui : : IsMousePosValid ( const ImVec2 * mouse_pos )
{
2019-01-27 22:30:44 +00:00
// The assert is only to silence a false-positive in XCode Static Analysis.
// Because GImGui is not dereferenced in every code path, the static analyzer assume that it may be NULL (which it doesn't for other functions).
IM_ASSERT ( GImGui ! = NULL ) ;
2017-08-26 07:18:06 +00:00
const float MOUSE_INVALID = - 256000.0f ;
2019-01-27 14:27:49 +00:00
ImVec2 p = mouse_pos ? * mouse_pos : GImGui - > IO . MousePos ;
return p . x > = MOUSE_INVALID & & p . y > = MOUSE_INVALID ;
2017-08-26 07:18:06 +00:00
}
2019-12-06 15:06:29 +00:00
bool ImGui : : IsAnyMouseDown ( )
{
ImGuiContext & g = * GImGui ;
for ( int n = 0 ; n < IM_ARRAYSIZE ( g . IO . MouseDown ) ; n + + )
if ( g . IO . MouseDown [ n ] )
return true ;
return false ;
}
2019-03-15 14:03:37 +00:00
// Return the delta from the initial clicking position while the mouse button is clicked or was just released.
2018-12-19 10:12:02 +00:00
// This is locked and return 0.0f until the mouse moves past a distance threshold at least once.
2018-02-06 17:26:42 +00:00
// NB: This is only valid if IsMousePosValid(). Back-ends in theory should always keep mouse position valid when dragging even outside the client window.
2019-12-06 15:29:22 +00:00
ImVec2 ImGui : : GetMouseDragDelta ( ImGuiMouseButton button , float lock_threshold )
2015-03-20 10:49:17 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2015-03-20 11:13:18 +00:00
IM_ASSERT ( button > = 0 & & button < IM_ARRAYSIZE ( g . IO . MouseDown ) ) ;
if ( lock_threshold < 0.0f )
lock_threshold = g . IO . MouseDragThreshold ;
2019-03-15 14:03:37 +00:00
if ( g . IO . MouseDown [ button ] | | g . IO . MouseReleased [ button ] )
2015-03-20 11:13:18 +00:00
if ( g . IO . MouseDragMaxDistanceSqr [ button ] > = lock_threshold * lock_threshold )
2019-03-15 14:03:37 +00:00
if ( IsMousePosValid ( & g . IO . MousePos ) & & IsMousePosValid ( & g . IO . MouseClickedPos [ button ] ) )
return g . IO . MousePos - g . IO . MouseClickedPos [ button ] ;
2015-03-20 10:49:17 +00:00
return ImVec2 ( 0.0f , 0.0f ) ;
}
2019-12-06 15:29:22 +00:00
void ImGui : : ResetMouseDragDelta ( ImGuiMouseButton button )
2015-04-13 18:54:40 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2015-04-13 18:54:40 +00:00
IM_ASSERT ( button > = 0 & & button < IM_ARRAYSIZE ( g . IO . MouseDown ) ) ;
// NB: We don't need to reset g.IO.MouseDragMaxDistanceSqr
g . IO . MouseClickedPos [ button ] = g . IO . MousePos ;
}
2015-03-21 13:59:19 +00:00
ImGuiMouseCursor ImGui : : GetMouseCursor ( )
{
return GImGui - > MouseCursor ;
}
void ImGui : : SetMouseCursor ( ImGuiMouseCursor cursor_type )
{
GImGui - > MouseCursor = cursor_type ;
}
2016-03-02 23:09:41 +00:00
void ImGui : : CaptureKeyboardFromApp ( bool capture )
2015-07-02 15:10:31 +00:00
{
2017-09-06 15:20:54 +00:00
GImGui - > WantCaptureKeyboardNextFrame = capture ? 1 : 0 ;
2015-07-02 15:20:15 +00:00
}
2016-03-02 23:09:41 +00:00
void ImGui : : CaptureMouseFromApp ( bool capture )
2015-07-02 15:20:15 +00:00
{
2017-09-06 15:20:54 +00:00
GImGui - > WantCaptureMouseNextFrame = capture ? 1 : 0 ;
2015-07-02 15:10:31 +00:00
}
2015-01-22 22:54:05 +00:00
bool ImGui : : IsItemActive ( )
2014-11-07 05:45:56 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2015-01-22 22:54:05 +00:00
if ( g . ActiveId )
{
2017-10-06 18:48:07 +00:00
ImGuiWindow * window = g . CurrentWindow ;
2016-06-12 20:27:15 +00:00
return g . ActiveId = = window - > DC . LastItemId ;
2015-01-22 22:54:05 +00:00
}
return false ;
2014-11-07 05:45:56 +00:00
}
2019-02-06 10:52:42 +00:00
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 ;
}
2018-06-12 16:44:33 +00:00
bool ImGui : : IsItemDeactivated ( )
{
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = g . CurrentWindow ;
2019-05-13 17:05:41 +00:00
if ( window - > DC . LastItemStatusFlags & ImGuiItemStatusFlags_HasDeactivated )
return ( window - > DC . LastItemStatusFlags & ImGuiItemStatusFlags_Deactivated ) ! = 0 ;
2018-06-12 16:44:33 +00:00
return ( g . ActiveIdPreviousFrame = = window - > DC . LastItemId & & g . ActiveIdPreviousFrame ! = 0 & & g . ActiveId ! = window - > DC . LastItemId ) ;
}
2018-08-23 11:26:14 +00:00
bool ImGui : : IsItemDeactivatedAfterEdit ( )
2018-06-12 22:10:33 +00:00
{
ImGuiContext & g = * GImGui ;
2019-05-13 16:15:39 +00:00
return IsItemDeactivated ( ) & & ( g . ActiveIdPreviousFrameHasBeenEditedBefore | | ( g . ActiveId = = 0 & & g . ActiveIdHasBeenEditedBefore ) ) ;
2018-06-12 22:10:33 +00:00
}
2016-07-19 22:02:59 +00:00
bool ImGui : : IsItemFocused ( )
{
ImGuiContext & g = * GImGui ;
2018-12-11 10:58:15 +00:00
ImGuiWindow * window = g . CurrentWindow ;
2019-02-01 09:26:08 +00:00
if ( g . NavId = = 0 | | g . NavDisableHighlight | | g . NavId ! = window - > DC . LastItemId )
return false ;
return true ;
2016-07-19 22:02:59 +00:00
}
2019-12-06 15:29:22 +00:00
bool ImGui : : IsItemClicked ( ImGuiMouseButton mouse_button )
2016-05-01 15:43:17 +00:00
{
2018-06-13 21:20:09 +00:00
return IsMouseClicked ( mouse_button ) & & IsItemHovered ( ImGuiHoveredFlags_None ) ;
2016-05-01 15:43:17 +00:00
}
2019-11-08 14:23:34 +00:00
bool ImGui : : IsItemToggledOpen ( )
{
ImGuiContext & g = * GImGui ;
return ( g . CurrentWindow - > DC . LastItemStatusFlags & ImGuiItemStatusFlags_ToggledOpen ) ? true : false ;
}
2019-04-11 13:40:36 +00:00
bool ImGui : : IsItemToggledSelection ( )
{
ImGuiContext & g = * GImGui ;
return ( g . CurrentWindow - > DC . LastItemStatusFlags & ImGuiItemStatusFlags_ToggledSelection ) ? true : false ;
}
2015-05-27 21:02:12 +00:00
bool ImGui : : IsAnyItemHovered ( )
{
2017-09-20 21:02:06 +00:00
ImGuiContext & g = * GImGui ;
return g . HoveredId ! = 0 | | g . HoveredIdPreviousFrame ! = 0 ;
2015-05-27 21:02:12 +00:00
}
2015-02-18 17:17:06 +00:00
bool ImGui : : IsAnyItemActive ( )
{
2017-09-20 21:02:06 +00:00
ImGuiContext & g = * GImGui ;
return g . ActiveId ! = 0 ;
2015-02-18 17:17:06 +00:00
}
2016-07-19 22:02:59 +00:00
bool ImGui : : IsAnyItemFocused ( )
{
2017-09-20 21:02:06 +00:00
ImGuiContext & g = * GImGui ;
return g . NavId ! = 0 & & ! g . NavDisableHighlight ;
2016-07-19 22:02:59 +00:00
}
2015-04-13 20:52:38 +00:00
bool ImGui : : IsItemVisible ( )
{
2015-08-30 10:56:04 +00:00
ImGuiWindow * window = GetCurrentWindowRead ( ) ;
2016-07-17 08:35:17 +00:00
return window - > ClipRect . Overlaps ( window - > DC . LastItemRect ) ;
2015-04-13 20:52:38 +00:00
}
2018-08-23 11:21:01 +00:00
bool ImGui : : IsItemEdited ( )
{
ImGuiWindow * window = GetCurrentWindowRead ( ) ;
2018-08-23 11:47:37 +00:00
return ( window - > DC . LastItemStatusFlags & ImGuiItemStatusFlags_Edited ) ! = 0 ;
2018-08-23 11:21:01 +00:00
}
2015-12-03 21:30:17 +00:00
// Allow last item to be overlapped by a subsequent item. Both may be activated during the same frame before the later one takes priority.
void ImGui : : SetItemAllowOverlap ( )
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2016-06-12 20:27:15 +00:00
if ( g . HoveredId = = g . CurrentWindow - > DC . LastItemId )
2015-12-03 21:30:17 +00:00
g . HoveredIdAllowOverlap = true ;
2016-06-12 20:27:15 +00:00
if ( g . ActiveId = = g . CurrentWindow - > DC . LastItemId )
2015-12-03 21:30:17 +00:00
g . ActiveIdAllowOverlap = true ;
}
2015-03-17 22:36:54 +00:00
ImVec2 ImGui : : GetItemRectMin ( )
2014-08-14 11:43:30 +00:00
{
2015-08-30 10:56:04 +00:00
ImGuiWindow * window = GetCurrentWindowRead ( ) ;
2015-03-17 23:35:12 +00:00
return window - > DC . LastItemRect . Min ;
2014-08-14 11:43:30 +00:00
}
2015-03-17 22:36:54 +00:00
ImVec2 ImGui : : GetItemRectMax ( )
2014-08-14 11:43:30 +00:00
{
2015-08-30 10:56:04 +00:00
ImGuiWindow * window = GetCurrentWindowRead ( ) ;
2015-03-17 23:35:12 +00:00
return window - > DC . LastItemRect . Max ;
2014-08-14 11:43:30 +00:00
}
2015-03-17 22:36:54 +00:00
ImVec2 ImGui : : GetItemRectSize ( )
2014-08-14 11:43:30 +00:00
{
2015-08-30 10:56:04 +00:00
ImGuiWindow * window = GetCurrentWindowRead ( ) ;
2015-03-17 23:35:12 +00:00
return window - > DC . LastItemRect . GetSize ( ) ;
2014-08-14 11:43:30 +00:00
}
2018-01-30 14:07:20 +00:00
static ImRect GetViewportRect ( )
2014-08-10 20:58:11 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2017-07-20 14:30:56 +00:00
return ImRect ( 0.0f , 0.0f , g . IO . DisplaySize . x , g . IO . DisplaySize . y ) ;
}
2018-07-05 07:17:16 +00:00
static bool ImGui : : BeginChildEx ( const char * name , ImGuiID id , const ImVec2 & size_arg , bool border , ImGuiWindowFlags flags )
2014-08-10 20:58:11 +00:00
{
2017-09-20 21:02:06 +00:00
ImGuiContext & g = * GImGui ;
2018-07-05 07:17:16 +00:00
ImGuiWindow * parent_window = g . CurrentWindow ;
flags | = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_ChildWindow ;
2017-10-20 14:13:13 +00:00
flags | = ( parent_window - > Flags & ImGuiWindowFlags_NoMove ) ; // Inherit the NoMove flag
2014-08-10 20:58:11 +00:00
2018-07-05 07:17:16 +00:00
// Size
const ImVec2 content_avail = GetContentRegionAvail ( ) ;
2016-04-23 12:10:36 +00:00
ImVec2 size = ImFloor ( size_arg ) ;
2017-12-07 16:11:51 +00:00
const int auto_fit_axises = ( ( size . x = = 0.0f ) ? ( 1 < < ImGuiAxis_X ) : 0x00 ) | ( ( size . y = = 0.0f ) ? ( 1 < < ImGuiAxis_Y ) : 0x00 ) ;
2014-08-19 11:09:13 +00:00
if ( size . x < = 0.0f )
2017-12-13 18:44:54 +00:00
size . x = ImMax ( content_avail . x + size . x , 4.0f ) ; // Arbitrary minimum child size (0.0f causing too much issues)
2014-08-19 11:09:13 +00:00
if ( size . y < = 0.0f )
2017-12-13 18:44:54 +00:00
size . y = ImMax ( content_avail . y + size . y , 4.0f ) ;
2018-07-05 07:17:16 +00:00
SetNextWindowSize ( size ) ;
2017-11-19 14:56:51 +00:00
2018-09-26 19:23:42 +00:00
// Build up name. If you need to append to a same child from multiple location in the ID stack, use BeginChild(ImGuiID id) with a stable value.
2014-08-19 11:09:13 +00:00
char title [ 256 ] ;
2016-11-06 14:12:45 +00:00
if ( name )
2018-09-26 19:23:42 +00:00
ImFormatString ( title , IM_ARRAYSIZE ( title ) , " %s/%s_%08X " , parent_window - > Name , name , id ) ;
2016-11-06 14:12:45 +00:00
else
2017-10-02 22:46:00 +00:00
ImFormatString ( title , IM_ARRAYSIZE ( title ) , " %s/%08X " , parent_window - > Name , id ) ;
2014-08-10 20:58:11 +00:00
2018-07-05 07:17:16 +00:00
const float backup_border_size = g . Style . ChildBorderSize ;
if ( ! border )
g . Style . ChildBorderSize = 0.0f ;
bool ret = Begin ( title , NULL , flags ) ;
g . Style . ChildBorderSize = backup_border_size ;
ImGuiWindow * child_window = g . CurrentWindow ;
2017-08-22 11:26:21 +00:00
child_window - > ChildId = id ;
2019-09-23 13:31:05 +00:00
child_window - > AutoFitChildAxises = ( ImS8 ) auto_fit_axises ;
2014-08-10 20:58:11 +00:00
2018-12-19 14:19:31 +00:00
// Set the cursor to handle case where the user called SetNextWindowPos()+BeginChild() manually.
// While this is not really documented/defined, it seems that the expected thing to do.
2019-01-15 14:05:56 +00:00
if ( child_window - > BeginCount = = 1 )
parent_window - > DC . CursorPos = child_window - > Pos ;
2018-12-19 14:19:31 +00:00
2016-07-19 22:02:59 +00:00
// Process navigation-in immediately so NavInit can run on first frame
2018-07-05 07:17:16 +00:00
if ( g . NavActivateId = = id & & ! ( flags & ImGuiWindowFlags_NavFlattened ) & & ( child_window - > DC . NavLayerActiveMask ! = 0 | | child_window - > DC . NavHasScroll ) )
2016-07-19 22:02:59 +00:00
{
2018-07-05 07:17:16 +00:00
FocusWindow ( child_window ) ;
NavInitWindow ( child_window , false ) ;
SetActiveID ( id + 1 , child_window ) ; // Steal ActiveId with a dummy id so that key-press won't activate child item
2017-09-20 21:02:06 +00:00
g . ActiveIdSource = ImGuiInputSource_Nav ;
2016-07-19 22:02:59 +00:00
}
2015-02-21 10:30:05 +00:00
return ret ;
2014-08-10 20:58:11 +00:00
}
2016-11-06 14:12:45 +00:00
bool ImGui : : BeginChild ( const char * str_id , const ImVec2 & size_arg , bool border , ImGuiWindowFlags extra_flags )
2015-02-21 10:10:21 +00:00
{
2016-11-06 14:12:45 +00:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
return BeginChildEx ( str_id , window - > GetID ( str_id ) , size_arg , border , extra_flags ) ;
}
bool ImGui : : BeginChild ( ImGuiID id , const ImVec2 & size_arg , bool border , ImGuiWindowFlags extra_flags )
2015-02-21 10:10:21 +00:00
{
2018-02-05 11:46:13 +00:00
IM_ASSERT ( id ! = 0 ) ;
2016-11-06 14:12:45 +00:00
return BeginChildEx ( NULL , id , size_arg , border , extra_flags ) ;
2015-02-21 10:10:21 +00:00
}
2014-11-10 01:29:01 +00:00
void ImGui : : EndChild ( )
2014-08-10 20:58:11 +00:00
{
2018-01-31 20:25:52 +00:00
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = g . CurrentWindow ;
2014-08-19 11:09:13 +00:00
2019-11-13 20:35:42 +00:00
IM_ASSERT ( g . WithinEndChild = = false ) ;
2019-12-10 12:37:29 +00:00
IM_ASSERT ( window - > Flags & ImGuiWindowFlags_ChildWindow ) ; // Mismatched BeginChild()/EndChild() calls
2019-11-13 20:35:42 +00:00
g . WithinEndChild = true ;
2017-12-08 16:16:33 +00:00
if ( window - > BeginCount > 1 )
2014-08-19 11:09:13 +00:00
{
2017-12-28 22:50:37 +00:00
End ( ) ;
2014-08-19 11:09:13 +00:00
}
else
{
2018-05-09 16:59:16 +00:00
ImVec2 sz = window - > Size ;
2017-12-07 16:11:51 +00:00
if ( window - > AutoFitChildAxises & ( 1 < < ImGuiAxis_X ) ) // Arbitrary minimum zero-ish child size of 4.0f causes less trouble than a 0.0f
2016-03-02 20:46:23 +00:00
sz . x = ImMax ( 4.0f , sz . x ) ;
2017-12-07 16:11:51 +00:00
if ( window - > AutoFitChildAxises & ( 1 < < ImGuiAxis_Y ) )
2016-03-02 20:46:23 +00:00
sz . y = ImMax ( 4.0f , sz . y ) ;
2017-12-28 22:50:37 +00:00
End ( ) ;
2015-03-06 22:05:01 +00:00
2018-01-31 20:25:52 +00:00
ImGuiWindow * parent_window = g . CurrentWindow ;
2016-07-19 22:02:59 +00:00
ImRect bb ( parent_window - > DC . CursorPos , parent_window - > DC . CursorPos + sz ) ;
2014-11-10 01:29:01 +00:00
ItemSize ( sz ) ;
2018-01-31 20:25:52 +00:00
if ( ( window - > DC . NavLayerActiveMask ! = 0 | | window - > DC . NavHasScroll ) & & ! ( window - > Flags & ImGuiWindowFlags_NavFlattened ) )
2016-07-19 22:02:59 +00:00
{
2017-10-06 21:27:29 +00:00
ItemAdd ( bb , window - > ChildId ) ;
2017-08-22 11:26:21 +00:00
RenderNavHighlight ( bb , window - > ChildId ) ;
2018-01-31 20:25:52 +00:00
// When browsing a window that has no activable items (scroll only) we keep a highlight on the child
if ( window - > DC . NavLayerActiveMask = = 0 & & window = = g . NavWindow )
RenderNavHighlight ( ImRect ( bb . Min - ImVec2 ( 2 , 2 ) , bb . Max + ImVec2 ( 2 , 2 ) ) , g . NavId , ImGuiNavHighlightFlags_TypeThin ) ;
2016-07-19 22:02:59 +00:00
}
2016-07-31 10:55:23 +00:00
else
{
2017-10-16 00:30:59 +00:00
// Not navigable into
2017-10-06 21:27:29 +00:00
ItemAdd ( bb , 0 ) ;
2016-07-31 10:55:23 +00:00
}
2014-08-19 11:09:13 +00:00
}
2019-11-13 20:35:42 +00:00
g . WithinEndChild = false ;
2014-08-10 20:58:11 +00:00
}
2015-02-10 21:21:23 +00:00
// Helper to create a child window / scrolling region that looks like a normal widget frame.
2015-10-06 22:22:44 +00:00
bool ImGui : : BeginChildFrame ( ImGuiID id , const ImVec2 & size , ImGuiWindowFlags extra_flags )
2015-02-10 21:21:23 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2015-02-10 21:21:23 +00:00
const ImGuiStyle & style = g . Style ;
2017-11-19 12:52:40 +00:00
PushStyleColor ( ImGuiCol_ChildBg , style . Colors [ ImGuiCol_FrameBg ] ) ;
2017-11-18 17:28:21 +00:00
PushStyleVar ( ImGuiStyleVar_ChildRounding , style . FrameRounding ) ;
2017-11-19 14:56:51 +00:00
PushStyleVar ( ImGuiStyleVar_ChildBorderSize , style . FrameBorderSize ) ;
2017-09-27 09:39:13 +00:00
PushStyleVar ( ImGuiStyleVar_WindowPadding , style . FramePadding ) ;
2018-05-23 20:57:54 +00:00
bool ret = BeginChild ( id , size , true , ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysUseWindowPadding | extra_flags ) ;
PopStyleVar ( 3 ) ;
PopStyleColor ( ) ;
return ret ;
2015-02-10 21:21:23 +00:00
}
void ImGui : : EndChildFrame ( )
{
2017-09-27 09:39:13 +00:00
EndChild ( ) ;
2015-02-10 21:21:23 +00:00
}
2017-11-13 21:15:50 +00:00
static void SetWindowConditionAllowFlags ( ImGuiWindow * window , ImGuiCond flags , bool enabled )
{
window - > SetWindowPosAllowFlags = enabled ? ( window - > SetWindowPosAllowFlags | flags ) : ( window - > SetWindowPosAllowFlags & ~ flags ) ;
window - > SetWindowSizeAllowFlags = enabled ? ( window - > SetWindowSizeAllowFlags | flags ) : ( window - > SetWindowSizeAllowFlags & ~ flags ) ;
window - > SetWindowCollapsedAllowFlags = enabled ? ( window - > SetWindowCollapsedAllowFlags | flags ) : ( window - > SetWindowCollapsedAllowFlags & ~ flags ) ;
}
2018-11-15 15:41:48 +00:00
ImGuiWindow * ImGui : : FindWindowByID ( ImGuiID id )
2014-12-28 17:54:02 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2017-11-07 12:59:55 +00:00
return ( ImGuiWindow * ) g . WindowsById . GetVoidPtr ( id ) ;
2014-12-28 17:54:02 +00:00
}
2018-11-15 15:41:48 +00:00
ImGuiWindow * ImGui : : FindWindowByName ( const char * name )
{
2019-04-19 17:48:51 +00:00
ImGuiID id = ImHashStr ( name ) ;
2018-11-15 15:41:48 +00:00
return FindWindowByID ( id ) ;
}
2014-12-28 17:54:02 +00:00
static ImGuiWindow * CreateNewWindow ( const char * name , ImVec2 size , ImGuiWindowFlags flags )
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2019-07-24 04:26:15 +00:00
//IMGUI_DEBUG_LOG("CreateNewWindow '%s', flags = 0x%08X\n", name, flags);
2014-12-28 17:54:02 +00:00
// Create window the first time
2017-12-23 15:24:33 +00:00
ImGuiWindow * window = IM_NEW ( ImGuiWindow ) ( & g , name ) ;
2014-12-28 17:54:02 +00:00
window - > Flags = flags ;
2017-11-07 12:59:55 +00:00
g . WindowsById . SetVoidPtr ( window - > ID , window ) ;
2014-12-28 17:54:02 +00:00
2018-04-20 13:40:12 +00:00
// Default/arbitrary window position. Use SetNextWindowPos() with the appropriate condition flag to change the initial position of a window.
2018-04-25 13:24:26 +00:00
window - > Pos = ImVec2 ( 60 , 60 ) ;
2018-04-20 13:40:12 +00:00
2017-12-06 14:13:23 +00:00
// User can disable loading and saving of settings. Tooltip and child windows also don't store settings.
if ( ! ( flags & ImGuiWindowFlags_NoSavedSettings ) )
2017-11-28 20:04:13 +00:00
if ( ImGuiWindowSettings * settings = ImGui : : FindWindowSettings ( window - > ID ) )
2014-12-28 17:54:02 +00:00
{
2018-07-09 19:06:46 +00:00
// Retrieve settings from .ini file
2019-11-07 15:05:03 +00:00
window - > SettingsOffset = g . SettingsWindows . offset_from_ptr ( settings ) ;
2017-11-28 20:04:13 +00:00
SetWindowConditionAllowFlags ( window , ImGuiCond_FirstUseEver , false ) ;
2019-08-23 09:08:30 +00:00
window - > Pos = ImVec2 ( settings - > Pos . x , settings - > Pos . y ) ;
2014-12-28 17:54:02 +00:00
window - > Collapsed = settings - > Collapsed ;
2019-08-23 09:08:30 +00:00
if ( settings - > Size . x > 0 & & settings - > Size . y > 0 )
size = ImVec2 ( settings - > Size . x , settings - > Size . y ) ;
2014-12-28 17:54:02 +00:00
}
2019-06-03 13:35:55 +00:00
window - > Size = window - > SizeFull = ImFloor ( size ) ;
2019-06-03 14:55:48 +00:00
window - > DC . CursorStartPos = window - > DC . CursorMaxPos = window - > Pos ; // So first call to CalcContentSize() doesn't return crazy values
2015-03-22 17:22:39 +00:00
2015-03-27 15:18:45 +00:00
if ( ( flags & ImGuiWindowFlags_AlwaysAutoResize ) ! = 0 )
{
2015-06-25 02:08:08 +00:00
window - > AutoFitFramesX = window - > AutoFitFramesY = 2 ;
2015-03-27 15:18:45 +00:00
window - > AutoFitOnlyGrows = false ;
}
2015-06-25 02:08:08 +00:00
else
2015-03-22 17:22:39 +00:00
{
2015-06-25 02:08:08 +00:00
if ( window - > Size . x < = 0.0f )
window - > AutoFitFramesX = 2 ;
if ( window - > Size . y < = 0.0f )
window - > AutoFitFramesY = 2 ;
window - > AutoFitOnlyGrows = ( window - > AutoFitFramesX > 0 ) | | ( window - > AutoFitFramesY > 0 ) ;
2015-03-22 17:22:39 +00:00
}
2018-09-10 18:30:14 +00:00
g . WindowsFocusOrder . push_back ( window ) ;
2015-12-24 13:55:42 +00:00
if ( flags & ImGuiWindowFlags_NoBringToFrontOnFocus )
2018-09-10 18:30:14 +00:00
g . Windows . push_front ( window ) ; // Quite slow but rare and only once
2015-12-24 13:55:42 +00:00
else
g . Windows . push_back ( window ) ;
2014-12-28 17:54:02 +00:00
return window ;
}
2019-08-19 19:48:03 +00:00
static ImVec2 CalcWindowSizeAfterConstraint ( ImGuiWindow * window , ImVec2 new_size )
2016-05-21 20:53:08 +00:00
{
ImGuiContext & g = * GImGui ;
2019-05-13 12:45:41 +00:00
if ( g . NextWindowData . Flags & ImGuiNextWindowDataFlags_HasSizeConstraint )
2016-05-21 20:53:08 +00:00
{
// Using -1,-1 on either X/Y axis to preserve the current size.
2018-01-03 11:28:16 +00:00
ImRect cr = g . NextWindowData . SizeConstraintRect ;
2016-05-21 20:53:08 +00:00
new_size . x = ( cr . Min . x > = 0 & & cr . Max . x > = 0 ) ? ImClamp ( new_size . x , cr . Min . x , cr . Max . x ) : window - > SizeFull . x ;
new_size . y = ( cr . Min . y > = 0 & & cr . Max . y > = 0 ) ? ImClamp ( new_size . y , cr . Min . y , cr . Max . y ) : window - > SizeFull . y ;
2018-01-03 11:31:56 +00:00
if ( g . NextWindowData . SizeCallback )
2016-05-21 20:53:08 +00:00
{
2018-01-03 11:31:56 +00:00
ImGuiSizeCallbackData data ;
data . UserData = g . NextWindowData . SizeCallbackUserData ;
2016-05-21 20:53:08 +00:00
data . Pos = window - > Pos ;
data . CurrentSize = window - > SizeFull ;
data . DesiredSize = new_size ;
2018-01-03 11:31:56 +00:00
g . NextWindowData . SizeCallback ( & data ) ;
2016-05-21 20:53:08 +00:00
new_size = data . DesiredSize ;
}
2019-10-29 16:04:13 +00:00
new_size . x = IM_FLOOR ( new_size . x ) ;
new_size . y = IM_FLOOR ( new_size . y ) ;
2016-05-21 20:53:08 +00:00
}
2017-12-07 21:22:53 +00:00
// Minimum size
2016-05-21 20:53:08 +00:00
if ( ! ( window - > Flags & ( ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_AlwaysAutoResize ) ) )
2017-11-15 22:42:18 +00:00
{
2016-05-21 20:53:08 +00:00
new_size = ImMax ( new_size , g . Style . WindowMinSize ) ;
2017-11-15 22:42:18 +00:00
new_size . y = ImMax ( new_size . y , window - > TitleBarHeight ( ) + window - > MenuBarHeight ( ) + ImMax ( 0.0f , g . Style . WindowRounding - 1.0f ) ) ; // Reduce artifacts with very small windows
}
2017-09-25 11:23:25 +00:00
return new_size ;
2016-05-21 20:53:08 +00:00
}
2019-08-19 19:48:03 +00:00
static ImVec2 CalcWindowContentSize ( ImGuiWindow * window )
2017-12-07 19:47:57 +00:00
{
2018-12-11 18:08:06 +00:00
if ( window - > Collapsed )
2019-02-08 13:34:42 +00:00
if ( window - > AutoFitFramesX < = 0 & & window - > AutoFitFramesY < = 0 )
2019-06-03 14:55:48 +00:00
return window - > ContentSize ;
2019-03-28 14:41:49 +00:00
if ( window - > Hidden & & window - > HiddenFramesCannotSkipItems = = 0 & & window - > HiddenFramesCanSkipItems > 0 )
2019-06-03 14:55:48 +00:00
return window - > ContentSize ;
2018-12-11 18:08:06 +00:00
2017-12-07 19:47:57 +00:00
ImVec2 sz ;
2019-10-17 09:36:26 +00:00
sz . x = IM_FLOOR ( ( window - > ContentSizeExplicit . x ! = 0.0f ) ? window - > ContentSizeExplicit . x : window - > DC . CursorMaxPos . x - window - > DC . CursorStartPos . x ) ;
sz . y = IM_FLOOR ( ( window - > ContentSizeExplicit . y ! = 0.0f ) ? window - > ContentSizeExplicit . y : window - > DC . CursorMaxPos . y - window - > DC . CursorStartPos . y ) ;
2019-06-03 13:35:55 +00:00
return sz ;
2017-12-07 19:47:57 +00:00
}
2019-08-19 19:48:03 +00:00
static ImVec2 CalcWindowAutoFitSize ( ImGuiWindow * window , const ImVec2 & size_contents )
2017-09-25 19:57:42 +00:00
{
ImGuiContext & g = * GImGui ;
ImGuiStyle & style = g . Style ;
2019-06-03 13:35:55 +00:00
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 ;
2018-04-25 14:38:13 +00:00
if ( window - > Flags & ImGuiWindowFlags_Tooltip )
2017-09-25 19:57:42 +00:00
{
2018-04-25 14:38:13 +00:00
// Tooltip always resize
2019-06-03 13:35:55 +00:00
return size_desired ;
2017-09-25 19:57:42 +00:00
}
else
{
2019-06-06 14:13:30 +00:00
// Maximum window size is determined by the viewport size or monitor size
2018-07-08 11:27:16 +00:00
const bool is_popup = ( window - > Flags & ImGuiWindowFlags_Popup ) ! = 0 ;
2018-07-06 16:28:12 +00:00
const bool is_menu = ( window - > Flags & ImGuiWindowFlags_ChildMenu ) ! = 0 ;
2018-07-08 11:27:16 +00:00
ImVec2 size_min = style . WindowMinSize ;
if ( is_popup | | is_menu ) // Popups and menus bypass style.WindowMinSize by default, but we give then a non-zero minimum size to facilitate understanding problematic cases (e.g. empty popups)
size_min = ImMin ( size_min , ImVec2 ( 4.0f , 4.0f ) ) ;
2019-06-03 13:35:55 +00:00
ImVec2 size_auto_fit = ImClamp ( size_desired , size_min , ImMax ( size_min , g . IO . DisplaySize - style . DisplaySafeAreaPadding * 2.0f ) ) ;
2019-02-01 09:26:08 +00:00
// 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.
2019-08-19 19:48:03 +00:00
ImVec2 size_auto_fit_after_constraint = CalcWindowSizeAfterConstraint ( window , size_auto_fit ) ;
2019-06-03 17:25:03 +00:00
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 )
2017-09-25 19:57:42 +00:00
size_auto_fit . y + = style . ScrollbarSize ;
2019-06-03 17:25:03 +00:00
if ( will_have_scrollbar_y )
2017-11-07 10:37:38 +00:00
size_auto_fit . x + = style . ScrollbarSize ;
2018-04-25 14:38:13 +00:00
return size_auto_fit ;
2017-09-25 19:57:42 +00:00
}
2016-05-21 20:53:08 +00:00
}
2018-08-28 20:52:51 +00:00
ImVec2 ImGui : : CalcWindowExpectedSize ( ImGuiWindow * window )
{
2019-08-19 19:48:03 +00:00
ImVec2 size_contents = CalcWindowContentSize ( window ) ;
ImVec2 size_auto_fit = CalcWindowAutoFitSize ( window , size_contents ) ;
ImVec2 size_final = CalcWindowSizeAfterConstraint ( window , size_auto_fit ) ;
return size_final ;
2018-08-28 20:52:51 +00:00
}
2017-10-17 13:47:55 +00:00
static ImGuiCol GetWindowBgColorIdxFromFlags ( ImGuiWindowFlags flags )
{
if ( flags & ( ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_Popup ) )
return ImGuiCol_PopupBg ;
if ( flags & ImGuiWindowFlags_ChildWindow )
2017-11-19 12:52:40 +00:00
return ImGuiCol_ChildBg ;
2017-10-17 13:47:55 +00:00
return ImGuiCol_WindowBg ;
}
2017-12-05 19:36:35 +00:00
static void CalcResizePosSizeFromAnyCorner ( ImGuiWindow * window , const ImVec2 & corner_target , const ImVec2 & corner_norm , ImVec2 * out_pos , ImVec2 * out_size )
{
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 ;
2019-08-19 19:48:03 +00:00
ImVec2 size_constrained = CalcWindowSizeAfterConstraint ( window , size_expected ) ;
2017-12-05 19:36:35 +00:00
* out_pos = pos_min ;
if ( corner_norm . x = = 0.0f )
out_pos - > x - = ( size_constrained . x - size_expected . x ) ;
if ( corner_norm . y = = 0.0f )
out_pos - > y - = ( size_constrained . y - size_expected . y ) ;
* out_size = size_constrained ;
}
struct ImGuiResizeGripDef
{
2019-01-23 16:31:32 +00:00
ImVec2 CornerPosN ;
2018-04-10 14:51:16 +00:00
ImVec2 InnerDir ;
int AngleMin12 , AngleMax12 ;
2017-12-05 19:36:35 +00:00
} ;
2019-01-23 16:31:32 +00:00
static const ImGuiResizeGripDef resize_grip_def [ 4 ] =
2017-12-05 19:36:35 +00:00
{
2019-11-15 15:44:16 +00:00
{ ImVec2 ( 1 , 1 ) , ImVec2 ( - 1 , - 1 ) , 0 , 3 } , // Lower-right
{ ImVec2 ( 0 , 1 ) , ImVec2 ( + 1 , - 1 ) , 3 , 6 } , // Lower-left
{ ImVec2 ( 0 , 0 ) , ImVec2 ( + 1 , + 1 ) , 6 , 9 } , // Upper-left (Unused)
{ ImVec2 ( 1 , 0 ) , ImVec2 ( - 1 , + 1 ) , 9 , 12 } , // Upper-right (Unused)
2017-12-05 19:36:35 +00:00
} ;
2018-09-05 18:36:36 +00:00
static ImRect GetResizeBorderRect ( ImGuiWindow * window , int border_n , float perp_padding , float thickness )
2017-12-05 21:38:02 +00:00
{
ImRect rect = window - > Rect ( ) ;
if ( thickness = = 0.0f ) rect . Max - = ImVec2 ( 1 , 1 ) ;
2019-01-23 16:31:32 +00:00
if ( border_n = = 0 ) return ImRect ( rect . Min . x + perp_padding , rect . Min . y - thickness , rect . Max . x - perp_padding , rect . Min . y + thickness ) ; // Top
if ( border_n = = 1 ) return ImRect ( rect . Max . x - thickness , rect . Min . y + perp_padding , rect . Max . x + thickness , rect . Max . y - perp_padding ) ; // Right
if ( border_n = = 2 ) return ImRect ( rect . Min . x + perp_padding , rect . Max . y - thickness , rect . Max . x - perp_padding , rect . Max . y + thickness ) ; // Bottom
if ( border_n = = 3 ) return ImRect ( rect . Min . x - thickness , rect . Min . y + perp_padding , rect . Min . x + thickness , rect . Max . y - perp_padding ) ; // Left
2017-12-05 21:38:02 +00:00
IM_ASSERT ( 0 ) ;
return ImRect ( ) ;
}
2019-11-15 15:44:16 +00:00
// 0..3: corners (Lower-right, Lower-left, Unused, Unused)
// 4..7: borders (Top, Right, Bottom, Left)
ImGuiID ImGui : : GetWindowResizeID ( ImGuiWindow * window , int n )
{
IM_ASSERT ( n > = 0 & & n < = 7 ) ;
ImGuiID id = window - > ID ;
id = ImHashStr ( " #RESIZE " , 0 , id ) ;
id = ImHashData ( & n , sizeof ( int ) , id ) ;
return id ;
}
2018-01-10 22:06:51 +00:00
// Handle resize for: Resize Grips, Borders, Gamepad
2019-06-05 13:33:41 +00:00
// 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 ] )
2018-01-10 22:06:51 +00:00
{
ImGuiContext & g = * GImGui ;
ImGuiWindowFlags flags = window - > Flags ;
2019-06-05 13:33:41 +00:00
2018-01-10 22:06:51 +00:00
if ( ( flags & ImGuiWindowFlags_NoResize ) | | ( flags & ImGuiWindowFlags_AlwaysAutoResize ) | | window - > AutoFitFramesX > 0 | | window - > AutoFitFramesY > 0 )
2019-06-05 13:33:41 +00:00
return false ;
2018-12-03 17:17:50 +00:00
if ( window - > WasActive = = false ) // Early out to avoid running this code for e.g. an hidden implicit/fallback Debug window.
2019-06-05 13:33:41 +00:00
return false ;
2018-01-10 22:06:51 +00:00
2019-06-05 13:33:41 +00:00
bool ret_auto_fit = false ;
2018-12-10 14:36:07 +00:00
const int resize_border_count = g . IO . ConfigWindowsResizeFromEdges ? 4 : 0 ;
2019-10-17 09:36:26 +00:00
const float grip_draw_size = IM_FLOOR ( ImMax ( g . FontSize * 1.35f , window - > WindowRounding + 1.0f + g . FontSize * 0.2f ) ) ;
const float grip_hover_inner_size = IM_FLOOR ( grip_draw_size * 0.75f ) ;
2018-12-10 14:36:07 +00:00
const float grip_hover_outer_size = g . IO . ConfigWindowsResizeFromEdges ? WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS : 0.0f ;
2018-01-10 22:06:51 +00:00
ImVec2 pos_target ( FLT_MAX , FLT_MAX ) ;
ImVec2 size_target ( FLT_MAX , FLT_MAX ) ;
2019-04-13 16:51:18 +00:00
// Resize grips and borders are on layer 1
window - > DC . NavLayerCurrent = ImGuiNavLayer_Menu ;
window - > DC . NavLayerCurrentMask = ( 1 < < ImGuiNavLayer_Menu ) ;
2018-01-10 22:06:51 +00:00
// Manual resize grips
PushID ( " #RESIZE " ) ;
for ( int resize_grip_n = 0 ; resize_grip_n < resize_grip_count ; resize_grip_n + + )
{
const ImGuiResizeGripDef & grip = resize_grip_def [ resize_grip_n ] ;
2019-01-23 16:31:32 +00:00
const ImVec2 corner = ImLerp ( window - > Pos , window - > Pos + window - > Size , grip . CornerPosN ) ;
2018-01-10 22:06:51 +00:00
// Using the FlattenChilds button flag we make the resize button accessible even if we are hovering over a child window
2018-10-02 16:43:10 +00:00
ImRect resize_rect ( corner - grip . InnerDir * grip_hover_outer_size , corner + grip . InnerDir * grip_hover_inner_size ) ;
2018-04-23 19:38:53 +00:00
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 ) ;
2018-01-10 22:06:51 +00:00
bool hovered , held ;
2019-11-15 15:44:16 +00:00
ButtonBehavior ( resize_rect , window - > GetID ( resize_grip_n ) , & hovered , & held , ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus ) ;
2019-03-04 15:20:32 +00:00
//GetForegroundDrawList(window)->AddRect(resize_rect.Min, resize_rect.Max, IM_COL32(255, 255, 0, 255));
2018-01-10 22:06:51 +00:00
if ( hovered | | held )
g . MouseCursor = ( resize_grip_n & 1 ) ? ImGuiMouseCursor_ResizeNESW : ImGuiMouseCursor_ResizeNWSE ;
2018-06-23 10:00:12 +00:00
if ( held & & g . IO . MouseDoubleClicked [ 0 ] & & resize_grip_n = = 0 )
2018-01-10 22:06:51 +00:00
{
// Manual auto-fit when double-clicking
2019-08-19 19:48:03 +00:00
size_target = CalcWindowSizeAfterConstraint ( window , size_auto_fit ) ;
2019-06-05 13:33:41 +00:00
ret_auto_fit = true ;
2018-01-10 22:06:51 +00:00
ClearActiveID ( ) ;
}
else if ( held )
{
// Resize from any of the four corners
// We don't use an incremental MouseDelta but rather compute an absolute target size based on mouse position
2019-01-23 16:31:32 +00:00
ImVec2 corner_target = g . IO . MousePos - g . ActiveIdClickOffset + ImLerp ( grip . InnerDir * grip_hover_outer_size , grip . InnerDir * - grip_hover_inner_size , grip . CornerPosN ) ; // Corner of the window corresponding to our corner grip
CalcResizePosSizeFromAnyCorner ( window , corner_target , grip . CornerPosN , & pos_target , & size_target ) ;
2018-01-10 22:06:51 +00:00
}
if ( resize_grip_n = = 0 | | held | | hovered )
resize_grip_col [ resize_grip_n ] = GetColorU32 ( held ? ImGuiCol_ResizeGripActive : hovered ? ImGuiCol_ResizeGripHovered : ImGuiCol_ResizeGrip ) ;
}
for ( int border_n = 0 ; border_n < resize_border_count ; border_n + + )
{
bool hovered , held ;
2018-12-10 14:36:07 +00:00
ImRect border_rect = GetResizeBorderRect ( window , border_n , grip_hover_inner_size , WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS ) ;
2019-11-15 15:44:16 +00:00
ButtonBehavior ( border_rect , window - > GetID ( border_n + 4 ) , & hovered , & held , ImGuiButtonFlags_FlattenChildren ) ;
2019-03-04 15:20:32 +00:00
//GetForegroundDrawLists(window)->AddRect(border_rect.Min, border_rect.Max, IM_COL32(255, 255, 0, 255));
2018-12-10 14:36:07 +00:00
if ( ( hovered & & g . HoveredIdTimer > WINDOWS_RESIZE_FROM_EDGES_FEEDBACK_TIMER ) | | held )
2018-01-10 22:06:51 +00:00
{
g . MouseCursor = ( border_n & 1 ) ? ImGuiMouseCursor_ResizeEW : ImGuiMouseCursor_ResizeNS ;
2019-03-16 14:48:21 +00:00
if ( held )
2019-01-23 16:31:32 +00:00
* border_held = border_n ;
2018-01-10 22:06:51 +00:00
}
if ( held )
{
ImVec2 border_target = window - > Pos ;
ImVec2 border_posn ;
2019-01-23 16:31:32 +00:00
if ( border_n = = 0 ) { border_posn = ImVec2 ( 0 , 0 ) ; border_target . y = ( g . IO . MousePos . y - g . ActiveIdClickOffset . y + WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS ) ; } // Top
if ( border_n = = 1 ) { border_posn = ImVec2 ( 1 , 0 ) ; border_target . x = ( g . IO . MousePos . x - g . ActiveIdClickOffset . x + WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS ) ; } // Right
if ( border_n = = 2 ) { border_posn = ImVec2 ( 0 , 1 ) ; border_target . y = ( g . IO . MousePos . y - g . ActiveIdClickOffset . y + WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS ) ; } // Bottom
if ( border_n = = 3 ) { border_posn = ImVec2 ( 0 , 0 ) ; border_target . x = ( g . IO . MousePos . x - g . ActiveIdClickOffset . x + WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS ) ; } // Left
2018-01-10 22:06:51 +00:00
CalcResizePosSizeFromAnyCorner ( window , border_target , border_posn , & pos_target , & size_target ) ;
}
}
PopID ( ) ;
2018-03-19 11:13:22 +00:00
// Navigation resize (keyboard/gamepad)
2018-07-09 17:16:48 +00:00
if ( g . NavWindowingTarget & & g . NavWindowingTarget - > RootWindow = = window )
2018-01-10 22:11:26 +00:00
{
2018-01-25 18:23:13 +00:00
ImVec2 nav_resize_delta ;
2018-03-19 11:13:22 +00:00
if ( g . NavInputSource = = ImGuiInputSource_NavKeyboard & & g . IO . KeyShift )
2018-01-25 18:34:08 +00:00
nav_resize_delta = GetNavInputAmount2d ( ImGuiNavDirSourceFlags_Keyboard , ImGuiInputReadMode_Down ) ;
2018-03-19 11:13:22 +00:00
if ( g . NavInputSource = = ImGuiInputSource_NavGamepad )
2018-01-25 18:34:08 +00:00
nav_resize_delta = GetNavInputAmount2d ( ImGuiNavDirSourceFlags_PadDPad , ImGuiInputReadMode_Down ) ;
2018-01-10 22:11:26 +00:00
if ( nav_resize_delta . x ! = 0.0f | | nav_resize_delta . y ! = 0.0f )
{
2018-01-25 18:23:13 +00:00
const float NAV_RESIZE_SPEED = 600.0f ;
nav_resize_delta * = ImFloor ( NAV_RESIZE_SPEED * g . IO . DeltaTime * ImMin ( g . IO . DisplayFramebufferScale . x , g . IO . DisplayFramebufferScale . y ) ) ;
g . NavWindowingToggleLayer = false ;
2018-01-10 22:11:26 +00:00
g . NavDisableMouseHover = true ;
resize_grip_col [ 0 ] = GetColorU32 ( ImGuiCol_ResizeGripActive ) ;
2018-01-25 18:23:13 +00:00
// FIXME-NAV: Should store and accumulate into a separate size buffer to handle sizing constraints properly, right now a constraint will make us stuck.
2019-08-19 19:48:03 +00:00
size_target = CalcWindowSizeAfterConstraint ( window , window - > SizeFull + nav_resize_delta ) ;
2018-01-10 22:11:26 +00:00
}
}
2018-01-10 22:06:51 +00:00
// Apply back modified position/size to window
if ( size_target . x ! = FLT_MAX )
{
window - > SizeFull = size_target ;
MarkIniSettingsDirty ( window ) ;
}
if ( pos_target . x ! = FLT_MAX )
{
2018-04-25 13:24:26 +00:00
window - > Pos = ImFloor ( pos_target ) ;
2018-01-10 22:06:51 +00:00
MarkIniSettingsDirty ( window ) ;
}
2019-04-13 16:51:18 +00:00
// Resize nav layer
window - > DC . NavLayerCurrent = ImGuiNavLayer_Main ;
window - > DC . NavLayerCurrentMask = ( 1 < < ImGuiNavLayer_Main ) ;
2018-01-10 22:06:51 +00:00
window - > Size = window - > SizeFull ;
2019-06-05 13:33:41 +00:00
return ret_auto_fit ;
2018-01-10 22:06:51 +00:00
}
2019-04-16 11:07:43 +00:00
static inline void ClampWindowRect ( ImGuiWindow * window , const ImRect & rect , const ImVec2 & padding )
{
ImGuiContext & g = * GImGui ;
ImVec2 size_for_clamping = ( g . IO . ConfigWindowsMoveFromTitleBarOnly & & ! ( window - > Flags & ImGuiWindowFlags_NoTitleBar ) ) ? ImVec2 ( window - > Size . x , window - > TitleBarHeight ( ) ) : window - > Size ;
window - > Pos = ImMin ( rect . Max - padding , ImMax ( window - > Pos + size_for_clamping , rect . Min + padding ) - size_for_clamping ) ;
}
2019-05-10 20:38:10 +00:00
static void ImGui : : RenderWindowOuterBorders ( ImGuiWindow * window )
2019-01-23 16:31:32 +00:00
{
ImGuiContext & g = * GImGui ;
float rounding = window - > WindowRounding ;
float border_size = window - > WindowBorderSize ;
if ( border_size > 0.0f & & ! ( window - > Flags & ImGuiWindowFlags_NoBackground ) )
window - > DrawList - > AddRect ( window - > Pos , window - > Pos + window - > Size , GetColorU32 ( ImGuiCol_Border ) , rounding , ImDrawCornerFlags_All , border_size ) ;
2019-02-01 09:26:08 +00:00
int border_held = window - > ResizeBorderHeld ;
2019-01-23 16:31:32 +00:00
if ( border_held ! = - 1 )
{
struct ImGuiResizeBorderDef
{
ImVec2 InnerDir ;
ImVec2 CornerPosN1 , CornerPosN2 ;
float OuterAngle ;
} ;
static const ImGuiResizeBorderDef resize_border_def [ 4 ] =
{
{ ImVec2 ( 0 , + 1 ) , ImVec2 ( 0 , 0 ) , ImVec2 ( 1 , 0 ) , IM_PI * 1.50f } , // Top
{ ImVec2 ( - 1 , 0 ) , ImVec2 ( 1 , 0 ) , ImVec2 ( 1 , 1 ) , IM_PI * 0.00f } , // Right
{ ImVec2 ( 0 , - 1 ) , ImVec2 ( 1 , 1 ) , ImVec2 ( 0 , 1 ) , IM_PI * 0.50f } , // Bottom
{ ImVec2 ( + 1 , 0 ) , ImVec2 ( 0 , 1 ) , ImVec2 ( 0 , 0 ) , IM_PI * 1.00f } // Left
} ;
const ImGuiResizeBorderDef & def = resize_border_def [ border_held ] ;
ImRect border_r = GetResizeBorderRect ( window , border_held , rounding , 0.0f ) ;
window - > DrawList - > PathArcTo ( ImLerp ( border_r . Min , border_r . Max , def . CornerPosN1 ) + ImVec2 ( 0.5f , 0.5f ) + def . InnerDir * rounding , rounding , def . OuterAngle - IM_PI * 0.25f , def . OuterAngle ) ;
window - > DrawList - > PathArcTo ( ImLerp ( border_r . Min , border_r . Max , def . CornerPosN2 ) + ImVec2 ( 0.5f , 0.5f ) + def . InnerDir * rounding , rounding , def . OuterAngle , def . OuterAngle + IM_PI * 0.25f ) ;
window - > DrawList - > PathStroke ( GetColorU32 ( ImGuiCol_SeparatorActive ) , false , ImMax ( 2.0f , border_size ) ) ; // Thicker than usual
}
if ( g . Style . FrameBorderSize > 0 & & ! ( window - > Flags & ImGuiWindowFlags_NoTitleBar ) )
{
float y = window - > Pos . y + window - > TitleBarHeight ( ) - 1 ;
window - > DrawList - > AddLine ( ImVec2 ( window - > Pos . x + border_size , y ) , ImVec2 ( window - > Pos . x + window - > Size . x - border_size , y ) , GetColorU32 ( ImGuiCol_Border ) , g . Style . FrameBorderSize ) ;
}
}
2019-05-10 20:45:52 +00:00
void ImGui : : RenderWindowDecorations ( ImGuiWindow * window , const ImRect & title_bar_rect , bool title_bar_is_highlight , 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 ;
2019-11-08 18:00:49 +00:00
// Ensure that ScrollBar doesn't read last frame's SkipItems
window - > SkipItems = false ;
2019-05-10 20:45:52 +00:00
// 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 ) )
{
ImU32 bg_col = GetColorU32 ( GetWindowBgColorIdxFromFlags ( flags ) ) ;
float alpha = 1.0f ;
2019-05-13 12:45:41 +00:00
if ( g . NextWindowData . Flags & ImGuiNextWindowDataFlags_HasBgAlpha )
2019-05-10 20:45:52 +00:00
alpha = g . NextWindowData . BgAlphaVal ;
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
if ( ! ( flags & ImGuiWindowFlags_NoTitleBar ) )
{
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 ) ;
}
// 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 ( ! ( 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
RenderWindowOuterBorders ( window ) ;
}
}
2019-05-24 18:59:41 +00:00
// Render title text, collapse button, close button
2019-05-10 20:38:10 +00:00
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 ;
2019-05-24 18:59:41 +00:00
const bool has_close_button = ( p_open ! = NULL ) ;
2019-09-17 14:16:38 +00:00
const bool has_collapse_button = ! ( flags & ImGuiWindowFlags_NoCollapse ) & & ( style . WindowMenuButtonPosition ! = ImGuiDir_None ) ;
2019-05-24 18:59:41 +00:00
2019-06-06 14:13:30 +00:00
// Close & Collapse button are on the Menu NavLayer and don't default focus (unless there's nothing else on that layer)
2019-05-10 20:38:10 +00:00
const ImGuiItemFlags item_flags_backup = window - > DC . ItemFlags ;
window - > DC . ItemFlags | = ImGuiItemFlags_NoNavDefaultFocus ;
window - > DC . NavLayerCurrent = ImGuiNavLayer_Menu ;
window - > DC . NavLayerCurrentMask = ( 1 < < ImGuiNavLayer_Menu ) ;
2019-05-24 18:59:41 +00:00
// 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 ) )
window - > WantCollapseToggle = true ; // Defer actual collapsing to next frame as we are too far in the Begin() function
2019-05-10 20:38:10 +00:00
// Close button
2019-05-24 18:59:41 +00:00
if ( has_close_button )
if ( CloseButton ( window - > GetID ( " #CLOSE " ) , close_button_pos ) )
2019-05-10 20:38:10 +00:00
* 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 ) ;
2019-05-24 18:59:41 +00:00
// 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 ) ;
2019-05-10 20:38:10 +00:00
if ( flags & ImGuiWindowFlags_UnsavedDocument )
{
2019-05-24 18:59:41 +00:00
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 ) ;
2019-10-17 09:36:26 +00:00
ImVec2 off = ImVec2 ( 0.0f , IM_FLOOR ( - g . FontSize * 0.25f ) ) ;
2019-05-24 18:59:41 +00:00
RenderTextClipped ( marker_pos + off , layout_r . Max + off , UNSAVED_DOCUMENT_MARKER , NULL , NULL , ImVec2 ( 0 , style . WindowTitleAlign . y ) , & clip_r ) ;
2019-05-10 20:38:10 +00:00
}
}
2018-07-26 21:45:48 +00:00
void ImGui : : UpdateWindowParentAndRootLinks ( ImGuiWindow * window , ImGuiWindowFlags flags , ImGuiWindow * parent_window )
{
window - > ParentWindow = parent_window ;
window - > RootWindow = window - > RootWindowForTitleBarHighlight = window - > RootWindowForNav = window ;
if ( parent_window & & ( flags & ImGuiWindowFlags_ChildWindow ) & & ! ( flags & ImGuiWindowFlags_Tooltip ) )
window - > RootWindow = parent_window - > RootWindow ;
if ( parent_window & & ! ( flags & ImGuiWindowFlags_Modal ) & & ( flags & ( ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Popup ) ) )
window - > RootWindowForTitleBarHighlight = parent_window - > RootWindowForTitleBarHighlight ;
while ( window - > RootWindowForNav - > Flags & ImGuiWindowFlags_NavFlattened )
2019-01-27 14:27:49 +00:00
{
IM_ASSERT ( window - > RootWindowForNav - > ParentWindow ! = NULL ) ;
2018-07-26 21:45:48 +00:00
window - > RootWindowForNav = window - > RootWindowForNav - > ParentWindow ;
2019-01-27 14:27:49 +00:00
}
2018-07-26 21:45:48 +00:00
}
2019-05-10 20:38:10 +00:00
// Push a new Dear ImGui window to add widgets to.
2015-02-22 12:38:46 +00:00
// - 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.
2015-08-24 11:50:18 +00:00
// - The window name is used as a unique identifier to preserve window information across frames (and save rudimentary information to the .ini file).
2015-03-07 22:01:06 +00:00
// You can use the "##" or "###" markers to use the same label with different id, or same id with different label. See documentation at the top of this file.
2014-12-22 13:29:39 +00:00
// - Return false when window is collapsed, so you can early out in your code. You always need to call ImGui::End() even if false is returned.
2016-05-02 10:32:16 +00:00
// - Passing 'bool* p_open' displays a Close button on the upper-right corner of the window, the pointed value will be set to false when the button is pressed.
bool ImGui : : Begin ( const char * name , bool * p_open , ImGuiWindowFlags flags )
2014-08-10 20:58:11 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2014-08-19 11:09:13 +00:00
const ImGuiStyle & style = g . Style ;
2018-12-20 19:01:02 +00:00
IM_ASSERT ( name ! = NULL & & name [ 0 ] ! = ' \0 ' ) ; // Window name required
2019-11-13 20:35:42 +00:00
IM_ASSERT ( g . WithinFrameScope ) ; // Forgot to call ImGui::NewFrame()
2015-09-16 22:48:42 +00:00
IM_ASSERT ( g . FrameCountEnded ! = g . FrameCount ) ; // Called ImGui::Render() or ImGui::EndFrame() and haven't called ImGui::NewFrame() again yet
2014-08-19 11:09:13 +00:00
2014-12-28 17:54:02 +00:00
// Find or create
ImGuiWindow * window = FindWindowByName ( name ) ;
2018-04-04 17:35:08 +00:00
const bool window_just_created = ( window = = NULL ) ;
if ( window_just_created )
2015-03-22 15:58:44 +00:00
{
2019-05-13 12:45:41 +00:00
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.
2015-03-23 22:50:17 +00:00
window = CreateNewWindow ( name , size_on_first_use , flags ) ;
2015-03-22 15:58:44 +00:00
}
2015-08-30 17:30:54 +00:00
2018-01-03 19:45:06 +00:00
// Automatically disable manual moving/resizing when NoInputs is set
2018-10-15 16:23:18 +00:00
if ( ( flags & ImGuiWindowFlags_NoInputs ) = = ImGuiWindowFlags_NoInputs )
2018-01-03 19:45:06 +00:00
flags | = ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ;
2018-05-17 12:12:37 +00:00
2018-01-29 22:06:55 +00:00
if ( flags & ImGuiWindowFlags_NavFlattened )
IM_ASSERT ( flags & ImGuiWindowFlags_ChildWindow ) ;
2018-01-03 19:45:06 +00:00
2017-09-04 11:29:57 +00:00
const int current_frame = g . FrameCount ;
2015-10-18 15:57:10 +00:00
const bool first_begin_of_the_frame = ( window - > LastFrameActive ! = current_frame ) ;
2018-12-11 10:58:15 +00:00
2017-12-06 16:42:28 +00:00
// 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
2019-03-28 14:41:49 +00:00
const bool window_just_appearing_after_hidden_for_resize = ( window - > HiddenFramesCannotSkipItems > 0 ) ;
2017-12-06 16:42:28 +00:00
if ( flags & ImGuiWindowFlags_Popup )
{
2019-04-28 15:05:23 +00:00
ImGuiPopupData & popup_ref = g . OpenPopupStack [ g . BeginPopupStack . Size ] ;
2017-12-06 16:42:28 +00:00
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 ) ;
}
window - > Appearing = ( window_just_activated_by_user | | window_just_appearing_after_hidden_for_resize ) ;
if ( window - > Appearing )
SetWindowConditionAllowFlags ( window , ImGuiCond_Appearing , true ) ;
2019-04-16 11:07:43 +00:00
// Update Flags, LastFrameActive, BeginOrderXXX fields
if ( first_begin_of_the_frame )
{
window - > Flags = ( ImGuiWindowFlags ) flags ;
window - > LastFrameActive = current_frame ;
2019-06-30 10:48:19 +00:00
window - > LastTimeActive = ( float ) g . Time ;
2019-04-16 11:07:43 +00:00
window - > BeginOrderWithinParent = 0 ;
window - > BeginOrderWithinContext = ( short ) ( g . WindowsActiveCount + + ) ;
}
else
{
flags = window - > Flags ;
}
// Parent window is latched only on the first call to Begin() of the frame, so further append-calls can be done from a different window stack
ImGuiWindow * parent_window_in_stack = g . CurrentWindowStack . empty ( ) ? NULL : g . CurrentWindowStack . back ( ) ;
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 ) ) ;
2019-06-30 10:48:19 +00:00
// 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 ) ;
2014-12-28 17:54:02 +00:00
// Add to stack
2019-04-16 11:07:43 +00:00
// We intentionally set g.CurrentWindow to NULL to prevent usage until when the viewport is set, then will call SetCurrentWindow()
2014-08-19 11:09:13 +00:00
g . CurrentWindowStack . push_back ( window ) ;
2019-04-16 11:07:43 +00:00
g . CurrentWindow = NULL ;
2019-11-13 20:35:42 +00:00
ErrorCheckBeginEndCompareStacksSize ( window , true ) ;
2015-05-11 14:57:02 +00:00
if ( flags & ImGuiWindowFlags_Popup )
{
2019-04-28 15:05:23 +00:00
ImGuiPopupData & popup_ref = g . OpenPopupStack [ g . BeginPopupStack . Size ] ;
2015-05-15 10:30:51 +00:00
popup_ref . Window = window ;
2018-12-14 17:44:17 +00:00
g . BeginPopupStack . push_back ( popup_ref ) ;
2016-06-12 20:27:15 +00:00
window - > PopupId = popup_ref . PopupId ;
2015-05-11 14:57:02 +00:00
}
2016-03-26 14:38:52 +00:00
2017-11-24 15:54:03 +00:00
if ( window_just_appearing_after_hidden_for_resize & & ! ( flags & ImGuiWindowFlags_ChildWindow ) )
2017-09-29 15:58:25 +00:00
window - > NavLastIds [ 0 ] = 0 ;
2014-08-19 11:09:13 +00:00
2014-12-10 19:22:30 +00:00
// Process SetNextWindow***() calls
2017-12-07 17:07:42 +00:00
bool window_pos_set_by_api = false ;
bool window_size_x_set_by_api = false , window_size_y_set_by_api = false ;
2019-05-13 12:45:41 +00:00
if ( g . NextWindowData . Flags & ImGuiNextWindowDataFlags_HasPos )
2014-12-10 19:22:30 +00:00
{
2018-01-03 11:28:16 +00:00
window_pos_set_by_api = ( window - > SetWindowPosAllowFlags & g . NextWindowData . PosCond ) ! = 0 ;
if ( window_pos_set_by_api & & ImLengthSqr ( g . NextWindowData . PosPivotVal ) > 0.00001f )
2015-06-23 21:45:34 +00:00
{
2017-09-25 16:25:43 +00:00
// May be processed on the next frame if this is our first frame and we are measuring size
2017-09-25 19:57:42 +00:00
// FIXME: Look into removing the branch so everything can go through this same code path for consistency.
2018-01-03 11:28:16 +00:00
window - > SetWindowPosVal = g . NextWindowData . PosVal ;
window - > SetWindowPosPivot = g . NextWindowData . PosPivotVal ;
2017-08-11 05:36:28 +00:00
window - > SetWindowPosAllowFlags & = ~ ( ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing ) ;
2015-06-23 21:45:34 +00:00
}
2015-06-23 21:34:44 +00:00
else
2015-06-23 21:45:34 +00:00
{
2018-01-03 11:28:16 +00:00
SetWindowPos ( window , g . NextWindowData . PosVal , g . NextWindowData . PosCond ) ;
2015-06-23 21:45:34 +00:00
}
2014-12-10 19:22:30 +00:00
}
2019-05-13 12:45:41 +00:00
if ( g . NextWindowData . Flags & ImGuiNextWindowDataFlags_HasSize )
2014-12-10 19:22:30 +00:00
{
2018-01-03 11:28:16 +00:00
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 ) ;
2014-12-10 19:22:30 +00:00
}
2019-05-13 12:45:41 +00:00
if ( g . NextWindowData . Flags & ImGuiNextWindowDataFlags_HasContentSize )
2019-06-03 14:55:48 +00:00
window - > ContentSizeExplicit = g . NextWindowData . ContentSizeVal ;
2015-08-30 15:37:56 +00:00
else if ( first_begin_of_the_frame )
2019-06-03 14:55:48 +00:00
window - > ContentSizeExplicit = ImVec2 ( 0.0f , 0.0f ) ;
2019-05-13 12:45:41 +00:00
if ( g . NextWindowData . Flags & ImGuiNextWindowDataFlags_HasCollapsed )
2018-01-03 11:28:16 +00:00
SetWindowCollapsed ( window , g . NextWindowData . CollapsedVal , g . NextWindowData . CollapsedCond ) ;
2019-05-13 12:45:41 +00:00
if ( g . NextWindowData . Flags & ImGuiNextWindowDataFlags_HasFocus )
2018-04-25 15:48:46 +00:00
FocusWindow ( window ) ;
2017-11-13 21:15:50 +00:00
if ( window - > Appearing )
SetWindowConditionAllowFlags ( window , ImGuiCond_Appearing , false ) ;
2014-12-10 19:22:30 +00:00
2014-08-19 11:09:13 +00:00
// When reusing window again multiple times a frame, just append content (don't need to setup again)
if ( first_begin_of_the_frame )
{
2017-11-06 22:55:40 +00:00
// Initialize
2018-07-26 21:45:48 +00:00
const bool window_is_child_tooltip = ( flags & ImGuiWindowFlags_ChildWindow ) & & ( flags & ImGuiWindowFlags_Tooltip ) ; // FIXME-WIP: Undocumented behavior of Child+Tooltip for pinned tooltip (#1345)
UpdateWindowParentAndRootLinks ( window , flags , parent_window ) ;
2017-11-06 22:55:40 +00:00
2015-05-02 12:20:50 +00:00
window - > Active = true ;
2019-04-16 11:07:43 +00:00
window - > HasCloseButton = ( p_open ! = NULL ) ;
2015-07-07 03:46:12 +00:00
window - > ClipRect = ImVec4 ( - FLT_MAX , - FLT_MAX , + FLT_MAX , + FLT_MAX ) ;
2015-05-02 16:54:25 +00:00
window - > IDStack . resize ( 1 ) ;
2015-05-02 09:32:32 +00:00
2019-06-30 10:48:19 +00:00
// Restore buffer capacity when woken from a compacted state, to avoid
if ( window - > MemoryCompacted )
GcAwakeTransientWindowBuffers ( window ) ;
2019-01-07 21:46:42 +00:00
// 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 ;
if ( g . NavWindowingList ! = NULL & & ( window - > Flags & ImGuiWindowFlags_NoNavFocus ) = = 0 ) // Window titles visible when using CTRL+TAB
window_title_visible_elsewhere = true ;
if ( window_title_visible_elsewhere & & ! window_just_created & & strcmp ( name , window - > Name ) ! = 0 )
{
size_t buf_len = ( size_t ) window - > NameBufLen ;
window - > Name = ImStrdupcpy ( window - > Name , & buf_len , name ) ;
window - > NameBufLen = ( int ) buf_len ;
}
2018-04-25 15:48:46 +00:00
// UPDATE CONTENTS SIZE, UPDATE HIDDEN STATUS
// Update contents size from last frame for auto-fitting (or use explicit size)
2019-08-19 19:48:03 +00:00
window - > ContentSize = CalcWindowContentSize ( window ) ;
2019-03-28 14:41:49 +00:00
if ( window - > HiddenFramesCanSkipItems > 0 )
window - > HiddenFramesCanSkipItems - - ;
if ( window - > HiddenFramesCannotSkipItems > 0 )
window - > HiddenFramesCannotSkipItems - - ;
2018-04-25 15:48:46 +00:00
// 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 ) )
2019-03-28 14:41:49 +00:00
window - > HiddenFramesCannotSkipItems = 1 ;
2018-04-25 15:48:46 +00:00
// Hide popup/tooltip window when re-opening while we measure size (because we recycle the windows)
2019-06-03 14:55:48 +00:00
// We reset Size/ContentSize for reappearing popups/tooltips early in this function, so further code won't be tempted to use the old size.
2018-04-25 15:48:46 +00:00
if ( window_just_activated_by_user & & ( flags & ( ImGuiWindowFlags_Popup | ImGuiWindowFlags_Tooltip ) ) ! = 0 )
{
2019-03-28 14:41:49 +00:00
window - > HiddenFramesCannotSkipItems = 1 ;
2018-04-25 15:48:46 +00:00
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 ;
2019-06-03 14:55:48 +00:00
window - > ContentSize = ImVec2 ( 0.f , 0.f ) ;
2018-04-25 15:48:46 +00:00
}
}
2019-06-03 13:35:55 +00:00
// FIXME-VIEWPORT: In the docking/viewport branch, this is the point where we select the current viewport (which may affect the style)
2018-04-25 15:48:46 +00:00
SetCurrentWindow ( window ) ;
2019-06-03 13:35:55 +00:00
// LOCK BORDER SIZE AND PADDING FOR THE FRAME (so that altering them doesn't cause inconsistencies)
2019-04-16 11:07:43 +00:00
if ( flags & ImGuiWindowFlags_ChildWindow )
window - > WindowBorderSize = style . ChildBorderSize ;
else
window - > WindowBorderSize = ( ( flags & ( ImGuiWindowFlags_Popup | ImGuiWindowFlags_Tooltip ) ) & & ! ( flags & ImGuiWindowFlags_Modal ) ) ? style . PopupBorderSize : style . WindowBorderSize ;
2018-01-10 17:56:51 +00:00
window - > WindowPadding = style . WindowPadding ;
if ( ( flags & ImGuiWindowFlags_ChildWindow ) & & ! ( flags & ( ImGuiWindowFlags_AlwaysUseWindowPadding | ImGuiWindowFlags_Popup ) ) & & window - > WindowBorderSize = = 0.0f )
window - > WindowPadding = ImVec2 ( 0.0f , ( flags & ImGuiWindowFlags_MenuBar ) ? style . WindowPadding . y : 0.0f ) ;
2018-04-18 13:38:04 +00:00
window - > DC . MenuBarOffset . x = ImMax ( ImMax ( window - > WindowPadding . x , style . ItemSpacing . x ) , g . NextWindowData . MenuBarOffsetMinVal . x ) ;
window - > DC . MenuBarOffset . y = g . NextWindowData . MenuBarOffsetMinVal . y ;
2018-01-10 17:56:51 +00:00
2015-05-02 17:22:46 +00:00
// Collapse window by double-clicking on title bar
// At this point we don't have a clipping rectangle setup yet, so we can use the title bar area for hit detection and drawing
if ( ! ( flags & ImGuiWindowFlags_NoTitleBar ) & & ! ( flags & ImGuiWindowFlags_NoCollapse ) )
{
2018-06-23 10:00:12 +00:00
// We don't use a regular button+id to test for double-click on title bar (mostly due to legacy reason, could be fixed), so verify that we don't have items over the title bar.
2015-07-31 05:48:59 +00:00
ImRect title_bar_rect = window - > TitleBarRect ( ) ;
2018-06-23 10:00:12 +00:00
if ( g . HoveredWindow = = window & & g . HoveredId = = 0 & & g . HoveredIdPreviousFrame = = 0 & & IsMouseHoveringRect ( title_bar_rect . Min , title_bar_rect . Max ) & & g . IO . MouseDoubleClicked [ 0 ] )
2018-08-05 16:13:24 +00:00
window - > WantCollapseToggle = true ;
if ( window - > WantCollapseToggle )
2015-05-02 17:22:46 +00:00
{
window - > Collapsed = ! window - > Collapsed ;
2016-12-23 11:13:52 +00:00
MarkIniSettingsDirty ( window ) ;
2015-05-02 17:22:46 +00:00
FocusWindow ( window ) ;
2015-03-26 17:09:17 +00:00
}
2015-03-26 18:17:55 +00:00
}
2015-05-02 17:22:46 +00:00
else
{
window - > Collapsed = false ;
}
2018-08-05 16:13:24 +00:00
window - > WantCollapseToggle = false ;
2015-03-26 17:09:17 +00:00
2015-05-02 17:22:46 +00:00
// SIZE
2017-09-25 19:57:42 +00:00
// Calculate auto-fit size, handle automatic resize
2019-08-19 19:48:03 +00:00
const ImVec2 size_auto_fit = CalcWindowAutoFitSize ( window , window - > ContentSize ) ;
2019-06-05 13:23:01 +00:00
bool use_current_size_for_scrollbar_x = window_just_created ;
bool use_current_size_for_scrollbar_y = window_just_created ;
2018-04-04 15:21:36 +00:00
if ( ( flags & ImGuiWindowFlags_AlwaysAutoResize ) & & ! window - > Collapsed )
2015-05-02 17:22:46 +00:00
{
2017-12-07 17:10:37 +00:00
// Using SetNextWindowSize() overrides ImGuiWindowFlags_AlwaysAutoResize, so it can be used on tooltips/popups, etc.
if ( ! window_size_x_set_by_api )
2019-06-05 13:23:01 +00:00
{
window - > SizeFull . x = size_auto_fit . x ;
use_current_size_for_scrollbar_x = true ;
}
2017-12-07 17:10:37 +00:00
if ( ! window_size_y_set_by_api )
2019-06-05 13:23:01 +00:00
{
window - > SizeFull . y = size_auto_fit . y ;
use_current_size_for_scrollbar_y = true ;
}
2015-05-02 17:22:46 +00:00
}
2017-12-07 17:10:37 +00:00
else if ( window - > AutoFitFramesX > 0 | | window - > AutoFitFramesY > 0 )
2015-05-02 17:22:46 +00:00
{
2018-04-04 15:21:36 +00:00
// Auto-fit may only grow window during the first few frames
2017-12-08 13:52:33 +00:00
// We still process initial auto-fit on collapsed windows to get a window width, but otherwise don't honor ImGuiWindowFlags_AlwaysAutoResize when collapsed.
2017-12-07 17:10:37 +00:00
if ( ! window_size_x_set_by_api & & window - > AutoFitFramesX > 0 )
2019-06-05 13:23:01 +00:00
{
window - > SizeFull . x = window - > AutoFitOnlyGrows ? ImMax ( window - > SizeFull . x , size_auto_fit . x ) : size_auto_fit . x ;
use_current_size_for_scrollbar_x = true ;
}
2017-12-07 17:10:37 +00:00
if ( ! window_size_y_set_by_api & & window - > AutoFitFramesY > 0 )
2019-06-05 13:23:01 +00:00
{
window - > SizeFull . y = window - > AutoFitOnlyGrows ? ImMax ( window - > SizeFull . y , size_auto_fit . y ) : size_auto_fit . y ;
use_current_size_for_scrollbar_y = true ;
}
2017-12-07 17:10:37 +00:00
if ( ! window - > Collapsed )
2016-12-23 11:13:52 +00:00
MarkIniSettingsDirty ( window ) ;
2015-05-02 17:22:46 +00:00
}
2016-05-21 20:53:08 +00:00
// Apply minimum/maximum window size constraints and final size
2019-08-19 19:48:03 +00:00
window - > SizeFull = CalcWindowSizeAfterConstraint ( window , window - > SizeFull ) ;
2018-01-19 14:33:35 +00:00
window - > Size = window - > Collapsed & & ! ( flags & ImGuiWindowFlags_ChildWindow ) ? window - > TitleBarRect ( ) . GetSize ( ) : window - > SizeFull ;
2017-11-14 22:17:28 +00:00
2019-06-04 14:22:47 +00:00
// Decoration size
const float decoration_up_height = window - > TitleBarHeight ( ) + window - > MenuBarHeight ( ) ;
2015-05-02 17:22:46 +00:00
// POSITION
2018-01-11 16:33:37 +00:00
// Popup latch its initial position, will position itself when it appears next frame
if ( window_just_activated_by_user )
{
window - > AutoPosLastDirection = ImGuiDir_None ;
if ( ( flags & ImGuiWindowFlags_Popup ) ! = 0 & & ! window_pos_set_by_api )
2018-12-14 17:44:17 +00:00
window - > Pos = g . BeginPopupStack . back ( ) . OpenPopupPos ;
2018-01-11 16:33:37 +00:00
}
2015-05-02 17:22:46 +00:00
// Position child window
2014-08-19 11:09:13 +00:00
if ( flags & ImGuiWindowFlags_ChildWindow )
2016-04-19 16:31:25 +00:00
{
2019-01-27 14:27:49 +00:00
IM_ASSERT ( parent_window & & parent_window - > Active ) ;
2018-12-04 13:30:11 +00:00
window - > BeginOrderWithinParent = ( short ) parent_window - > DC . ChildWindows . Size ;
2014-08-19 11:09:13 +00:00
parent_window - > DC . ChildWindows . push_back ( window ) ;
2018-01-19 14:47:10 +00:00
if ( ! ( flags & ImGuiWindowFlags_Popup ) & & ! window_pos_set_by_api & & ! window_is_child_tooltip )
2018-04-25 13:24:26 +00:00
window - > Pos = parent_window - > DC . CursorPos ;
2016-04-19 16:31:25 +00:00
}
2015-01-29 13:20:25 +00:00
2019-03-28 14:41:49 +00:00
const bool window_pos_with_pivot = ( window - > SetWindowPosVal . x ! = FLT_MAX & & window - > HiddenFramesCannotSkipItems = = 0 ) ;
2017-09-25 16:25:43 +00:00
if ( window_pos_with_pivot )
2019-07-22 01:19:56 +00:00
SetWindowPos ( window , window - > SetWindowPosVal - window - > SizeFull * window - > SetWindowPosPivot , 0 ) ; // Position given a pivot (e.g. for centering)
2018-04-11 13:33:11 +00:00
else if ( ( flags & ImGuiWindowFlags_ChildMenu ) ! = 0 )
2018-04-25 13:24:26 +00:00
window - > Pos = FindBestWindowPosForPopup ( window ) ;
2017-09-04 11:26:46 +00:00
else if ( ( flags & ImGuiWindowFlags_Popup ) ! = 0 & & ! window_pos_set_by_api & & window_just_appearing_after_hidden_for_resize )
2018-04-25 13:24:26 +00:00
window - > Pos = FindBestWindowPosForPopup ( window ) ;
2018-04-11 13:33:11 +00:00
else if ( ( flags & ImGuiWindowFlags_Tooltip ) ! = 0 & & ! window_pos_set_by_api & & ! window_is_child_tooltip )
2018-04-25 13:24:26 +00:00
window - > Pos = FindBestWindowPosForPopup ( window ) ;
2014-08-19 11:09:13 +00:00
2019-06-06 14:13:30 +00:00
// Clamp position/size so window stays visible within its viewport or monitor
2019-02-01 09:26:08 +00:00
// Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing.
2019-04-16 11:07:43 +00:00
ImRect viewport_rect ( GetViewportRect ( ) ) ;
2019-02-01 09:26:08 +00:00
if ( ! window_pos_set_by_api & & ! ( flags & ImGuiWindowFlags_ChildWindow ) & & window - > AutoFitFramesX < = 0 & & window - > AutoFitFramesY < = 0 )
2014-08-19 11:09:13 +00:00
{
2019-02-01 09:26:08 +00:00
if ( g . IO . DisplaySize . x > 0.0f & & g . IO . DisplaySize . y > 0.0f ) // Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing.
2014-12-22 02:14:25 +00:00
{
2019-04-16 11:07:43 +00:00
ImVec2 clamp_padding = ImMax ( style . DisplayWindowPadding , style . DisplaySafeAreaPadding ) ;
ClampWindowRect ( window , viewport_rect , clamp_padding ) ;
2014-12-22 02:14:25 +00:00
}
2014-08-19 11:09:13 +00:00
}
2018-04-25 13:24:26 +00:00
window - > Pos = ImFloor ( window - > Pos ) ;
2014-08-19 11:09:13 +00:00
2018-04-25 15:48:46 +00:00
// Lock window rounding for the frame (so that altering them doesn't cause inconsistencies)
window - > WindowRounding = ( flags & ImGuiWindowFlags_ChildWindow ) ? style . ChildRounding : ( ( flags & ImGuiWindowFlags_Popup ) & & ! ( flags & ImGuiWindowFlags_Modal ) ) ? style . PopupRounding : style . WindowRounding ;
2018-07-09 19:06:46 +00:00
// Apply window focus (new and reactivated windows are moved to front)
2017-12-05 15:12:45 +00:00
bool want_focus = false ;
if ( window_just_activated_by_user & & ! ( flags & ImGuiWindowFlags_NoFocusOnAppearing ) )
2019-02-01 09:26:08 +00:00
{
if ( flags & ImGuiWindowFlags_Popup )
2017-12-05 15:12:45 +00:00
want_focus = true ;
2019-02-01 09:26:08 +00:00
else if ( ( flags & ( ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Tooltip ) ) = = 0 )
want_focus = true ;
}
2015-06-23 18:34:15 +00:00
2018-01-11 22:17:34 +00:00
// Handle manual resize: Resize Grips, Borders, Gamepad
int border_held = - 1 ;
2019-10-18 10:54:30 +00:00
ImU32 resize_grip_col [ 4 ] = { } ;
2019-11-19 14:22:42 +00:00
const int resize_grip_count = g . IO . ConfigWindowsResizeFromEdges ? 2 : 1 ; // Allow resize from lower-left if we have the mouse cursor feedback for it.
2019-10-17 09:36:26 +00:00
const float resize_grip_draw_size = IM_FLOOR ( ImMax ( g . FontSize * 1.35f , window - > WindowRounding + 1.0f + g . FontSize * 0.2f ) ) ;
2018-01-11 22:21:24 +00:00
if ( ! window - > Collapsed )
2019-06-05 13:33:41 +00:00
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 ;
2019-02-01 09:26:08 +00:00
window - > ResizeBorderHeld = ( signed char ) border_held ;
2018-01-11 22:17:34 +00:00
2019-06-05 13:32:37 +00:00
// 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 ) ;
}
2018-04-16 17:37:00 +00:00
2019-05-28 14:00:34 +00:00
// 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.
2019-05-10 20:30:33 +00:00
2019-05-28 14:00:34 +00:00
// 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
2019-06-04 14:22:47 +00:00
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 ( ) ;
2019-05-28 19:49:22 +00:00
window - > OuterRectClipped = outer_rect ;
2019-05-28 14:00:34 +00:00
window - > OuterRectClipped . ClipWith ( host_rect ) ;
2019-05-10 20:30:33 +00:00
// Inner rectangle
2019-09-17 09:33:18 +00:00
// Not affected by window border size. Used by:
2019-06-04 14:22:47 +00:00
// - InnerClipRect
2019-07-31 17:26:10 +00:00
// - ScrollToBringRectIntoView()
2019-05-28 14:00:34 +00:00
// - NavUpdatePageUpPageDown()
// - Scrollbar()
2019-06-04 14:22:47 +00:00
window - > InnerRect . Min . x = window - > Pos . x ;
window - > InnerRect . Min . y = window - > Pos . y + decoration_up_height ;
2019-05-28 14:18:30 +00:00
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 ;
2019-05-10 20:30:33 +00:00
2019-05-28 14:00:34 +00:00
// 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
2019-05-28 19:49:22 +00:00
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 ) ;
2019-06-17 15:03:54 +00:00
window - > InnerClipRect . Max . x = ImFloor ( 0.5f + window - > InnerRect . Max . x - ImMax ( ImFloor ( window - > WindowPadding . x * 0.5f ) , window - > WindowBorderSize ) ) ;
2019-05-28 19:49:22 +00:00
window - > InnerClipRect . Max . y = ImFloor ( 0.5f + window - > InnerRect . Max . y - window - > WindowBorderSize ) ;
2019-05-28 13:54:55 +00:00
window - > InnerClipRect . ClipWithFull ( host_rect ) ;
2019-05-10 20:30:33 +00:00
2019-06-05 13:32:37 +00:00
// 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 ) )
2019-10-17 09:36:26 +00:00
window - > ItemWidthDefault = ImFloor ( window - > Size . x * 0.65f ) ;
2019-06-05 13:32:37 +00:00
else
2019-10-17 09:36:26 +00:00
window - > ItemWidthDefault = ImFloor ( g . FontSize * 16.0f ) ;
2019-06-05 13:32:37 +00:00
2019-06-03 16:51:12 +00:00
// 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 ) ;
2018-01-10 21:55:29 +00:00
// DRAWING
// Setup draw list and outer clipping rectangle
window - > DrawList - > Clear ( ) ;
window - > DrawList - > PushTextureID ( g . Font - > ContainerAtlas - > TexID ) ;
2019-05-22 19:43:42 +00:00
PushClipRect ( host_rect . Min , host_rect . Max , false ) ;
2018-01-10 21:55:29 +00:00
2018-07-09 17:16:48 +00:00
// Draw modal window background (darkens what is behind them, all viewports)
2019-06-19 16:14:24 +00:00
const bool dim_bg_for_modal = ( flags & ImGuiWindowFlags_Modal ) & & window = = GetTopMostPopupModal ( ) & & window - > HiddenFramesCannotSkipItems < = 0 ;
2018-07-26 17:00:17 +00:00
const bool dim_bg_for_window_list = g . NavWindowingTargetAnim & & ( window = = g . NavWindowingTargetAnim - > RootWindow ) ;
2018-07-09 17:16:48 +00:00
if ( dim_bg_for_modal | | dim_bg_for_window_list )
{
2018-07-12 07:53:10 +00:00
const ImU32 dim_bg_col = GetColorU32 ( dim_bg_for_modal ? ImGuiCol_ModalWindowDimBg : ImGuiCol_NavWindowingDimBg , g . DimBgRatio ) ;
2018-07-09 17:16:48 +00:00
window - > DrawList - > AddRectFilled ( viewport_rect . Min , viewport_rect . Max , dim_bg_col ) ;
}
2017-12-21 18:27:06 +00:00
2018-01-30 14:01:52 +00:00
// Draw navigation selection/windowing rectangle background
2018-07-26 17:00:17 +00:00
if ( dim_bg_for_window_list & & window = = g . NavWindowingTargetAnim )
2016-07-19 22:02:59 +00:00
{
ImRect bb = window - > Rect ( ) ;
bb . Expand ( g . FontSize ) ;
2018-01-30 14:01:52 +00:00
if ( ! bb . Contains ( viewport_rect ) ) // Avoid drawing if the window covers all the viewport anyway
2018-07-12 07:53:10 +00:00
window - > DrawList - > AddRectFilled ( bb . Min , bb . Max , GetColorU32 ( ImGuiCol_NavWindowingHighlight , g . NavWindowingHighlightAlpha * 0.25f ) , g . Style . WindowRounding ) ;
2016-07-19 22:02:59 +00:00
}
2019-05-10 15:24:22 +00:00
// 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.
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 ;
2019-09-17 09:33:18 +00:00
2019-07-23 00:27:41 +00:00
// Handle title bar, scrollbar, resize grips and resize borders
2018-07-09 17:16:48 +00:00
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 ) ;
2019-05-10 20:45:52 +00:00
RenderWindowDecorations ( window , title_bar_rect , title_bar_is_highlight , resize_grip_count , resize_grip_col , resize_grip_draw_size ) ;
2014-08-19 11:09:13 +00:00
2019-05-10 15:24:22 +00:00
if ( render_decorations_in_parent )
window - > DrawList = & window - > DrawListInst ;
2018-01-30 14:01:52 +00:00
// Draw navigation selection/windowing rectangle border
2018-07-26 17:00:17 +00:00
if ( g . NavWindowingTargetAnim = = window )
2018-01-30 14:01:52 +00:00
{
2018-02-16 23:19:04 +00:00
float rounding = ImMax ( window - > WindowRounding , g . Style . WindowRounding ) ;
2018-01-30 14:01:52 +00:00
ImRect bb = window - > Rect ( ) ;
bb . Expand ( g . FontSize ) ;
2018-02-16 23:19:04 +00:00
if ( bb . Contains ( viewport_rect ) ) // If a window fits the entire viewport, adjust its highlight inward
{
bb . Expand ( - g . FontSize - 1.0f ) ;
rounding = window - > WindowRounding ;
}
2018-07-12 07:53:10 +00:00
window - > DrawList - > AddRect ( bb . Min , bb . Max , GetColorU32 ( ImGuiCol_NavWindowingHighlight , g . NavWindowingHighlightAlpha ) , rounding , ~ 0 , 3.0f ) ;
2018-01-30 14:01:52 +00:00
}
2019-05-28 14:00:34 +00:00
// UPDATE RECTANGLES (2- THOSE AFFECTED BY SCROLLING)
2019-05-28 19:49:22 +00:00
// 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 ) ;
2019-06-05 13:23:01 +00:00
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 ) ) ;
2019-05-28 19:49:22 +00:00
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 ;
2019-10-31 10:15:40 +00:00
// [LEGACY] Content Region
// FIXME-OBSOLETE: window->ContentRegionRect.Max is currently very misleading / partly faulty, but some BeginChild() patterns relies on it.
2019-05-28 14:00:34 +00:00
// Used by:
2019-05-28 19:49:22 +00:00
// - Mouse wheel scrolling + many other things
2019-10-31 10:15:40 +00:00
window - > ContentRegionRect . Min . x = window - > Pos . x - window - > Scroll . x + window - > WindowPadding . x ;
window - > ContentRegionRect . Min . y = window - > Pos . y - window - > Scroll . y + window - > WindowPadding . y + decoration_up_height ;
window - > ContentRegionRect . Max . x = window - > ContentRegionRect . Min . x + ( window - > ContentSizeExplicit . x ! = 0.0f ? window - > ContentSizeExplicit . x : ( window - > Size . x - window - > WindowPadding . x * 2.0f - window - > ScrollbarSizes . x ) ) ;
window - > ContentRegionRect . Max . y = window - > ContentRegionRect . Min . y + ( window - > ContentSizeExplicit . y ! = 0.0f ? window - > ContentSizeExplicit . y : ( window - > Size . y - window - > WindowPadding . y * 2.0f - decoration_up_height - window - > ScrollbarSizes . y ) ) ;
2019-05-28 14:00:34 +00:00
2014-08-19 11:09:13 +00:00
// Setup drawing context
2017-11-14 22:17:28 +00:00
// (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.)
2018-08-28 17:03:08 +00:00
window - > DC . Indent . x = 0.0f + window - > WindowPadding . x - window - > Scroll . x ;
window - > DC . GroupOffset . x = 0.0f ;
window - > DC . ColumnsOffset . x = 0.0f ;
2019-06-04 14:22:47 +00:00
window - > DC . CursorStartPos = window - > Pos + ImVec2 ( window - > DC . Indent . x + window - > DC . ColumnsOffset . x , decoration_up_height + window - > WindowPadding . y - window - > Scroll . y ) ;
2014-08-19 11:09:13 +00:00
window - > DC . CursorPos = window - > DC . CursorStartPos ;
window - > DC . CursorPosPrevLine = window - > DC . CursorPos ;
2015-03-17 22:03:02 +00:00
window - > DC . CursorMaxPos = window - > DC . CursorStartPos ;
2019-05-13 16:15:39 +00:00
window - > DC . CurrLineSize = window - > DC . PrevLineSize = ImVec2 ( 0.0f , 0.0f ) ;
window - > DC . CurrLineTextBaseOffset = window - > DC . PrevLineTextBaseOffset = 0.0f ;
2018-02-01 21:28:58 +00:00
window - > DC . NavHideHighlightOneFrame = false ;
2019-06-03 16:51:12 +00:00
window - > DC . NavHasScroll = ( window - > ScrollMax . y > 0.0f ) ;
2017-09-28 17:41:30 +00:00
window - > DC . NavLayerActiveMask = window - > DC . NavLayerActiveMaskNext ;
window - > DC . NavLayerActiveMaskNext = 0x00 ;
2015-05-17 16:13:45 +00:00
window - > DC . MenuBarAppending = false ;
2014-08-19 11:09:13 +00:00
window - > DC . ChildWindows . resize ( 0 ) ;
2015-05-25 22:08:22 +00:00
window - > DC . LayoutType = ImGuiLayoutType_Vertical ;
2017-09-29 21:36:41 +00:00
window - > DC . ParentLayoutType = parent_window ? parent_window - > DC . LayoutType : ImGuiLayoutType_Vertical ;
2019-03-05 18:37:20 +00:00
window - > DC . FocusCounterAll = window - > DC . FocusCounterTab = - 1 ;
2018-05-28 13:30:42 +00:00
window - > DC . ItemFlags = parent_window ? parent_window - > DC . ItemFlags : ImGuiItemFlags_Default_ ;
2015-05-27 14:35:49 +00:00
window - > DC . ItemWidth = window - > ItemWidthDefault ;
window - > DC . TextWrapPos = - 1.0f ; // disabled
2016-08-07 18:05:24 +00:00
window - > DC . ItemFlagsStack . resize ( 0 ) ;
2015-09-07 22:39:36 +00:00
window - > DC . ItemWidthStack . resize ( 0 ) ;
2015-05-27 14:35:49 +00:00
window - > DC . TextWrapPosStack . resize ( 0 ) ;
2019-04-16 09:58:17 +00:00
window - > DC . CurrentColumns = NULL ;
2014-08-19 11:09:13 +00:00
window - > DC . TreeDepth = 0 ;
2019-09-23 10:45:52 +00:00
window - > DC . TreeMayJumpToParentOnPopMask = 0x00 ;
2014-08-19 11:09:13 +00:00
window - > DC . StateStorage = & window - > StateStorage ;
2015-03-17 23:28:57 +00:00
window - > DC . GroupStack . resize ( 0 ) ;
2017-09-04 11:26:46 +00:00
window - > MenuColumns . Update ( 3 , style . ItemSpacing . x , window_just_activated_by_user ) ;
2014-08-19 11:09:13 +00:00
2016-08-07 18:05:24 +00:00
if ( ( flags & ImGuiWindowFlags_ChildWindow ) & & ( window - > DC . ItemFlags ! = parent_window - > DC . ItemFlags ) )
{
window - > DC . ItemFlags = parent_window - > DC . ItemFlags ;
window - > DC . ItemFlagsStack . push_back ( window - > DC . ItemFlags ) ;
}
2015-06-25 02:08:08 +00:00
if ( window - > AutoFitFramesX > 0 )
window - > AutoFitFramesX - - ;
if ( window - > AutoFitFramesY > 0 )
window - > AutoFitFramesY - - ;
2014-08-19 11:09:13 +00:00
2017-12-05 15:12:45 +00:00
// Apply focus (we need to call FocusWindow() AFTER setting DC.CursorStartPos so our initial navigation reference rectangle can start around there)
if ( want_focus )
2017-12-05 15:15:05 +00:00
{
2017-12-05 15:12:45 +00:00
FocusWindow ( window ) ;
2017-12-05 15:15:05 +00:00
NavInitWindow ( window , false ) ;
}
2016-07-18 13:25:44 +00:00
2014-08-19 11:09:13 +00:00
// Title bar
2015-05-02 16:45:54 +00:00
if ( ! ( flags & ImGuiWindowFlags_NoTitleBar ) )
2019-05-10 20:38:10 +00:00
RenderWindowTitleBarContents ( window , title_bar_rect , name , p_open ) ;
2015-02-22 12:05:38 +00:00
2015-03-13 13:04:10 +00:00
// 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?
/*
if ( g . ActiveId = = move_id )
if ( g . IO . KeyCtrl & & IsKeyPressedMap ( ImGuiKey_C ) )
2018-11-15 15:43:05 +00:00
LogToClipboard ( ) ;
2015-03-13 13:04:10 +00:00
*/
2014-08-19 11:09:13 +00:00
2019-04-16 11:07:43 +00:00
// We fill last item data based on Title Bar/Tab, in order for IsItemHovered() and IsItemActive() to be usable after Begin().
2019-02-01 09:26:08 +00:00
// This is useful to allow creating context menus on title bar only, etc.
2017-11-15 13:35:45 +00:00
window - > DC . LastItemId = window - > MoveId ;
2018-02-06 12:34:41 +00:00
window - > DC . LastItemStatusFlags = IsMouseHoveringRect ( title_bar_rect . Min , title_bar_rect . Max , false ) ? ImGuiItemStatusFlags_HoveredRect : 0 ;
2017-11-15 13:35:45 +00:00
window - > DC . LastItemRect = title_bar_rect ;
2019-04-12 17:44:29 +00:00
# ifdef IMGUI_ENABLE_TEST_ENGINE
if ( ! ( window - > Flags & ImGuiWindowFlags_NoTitleBar ) )
IMGUI_TEST_ENGINE_ITEM_ADD ( window - > DC . LastItemRect , window - > DC . LastItemId ) ;
# endif
2017-10-27 11:16:37 +00:00
}
2019-04-16 11:07:43 +00:00
else
{
// Append
SetCurrentWindow ( window ) ;
}
2016-07-19 22:02:59 +00:00
2019-05-28 13:54:55 +00:00
PushClipRect ( window - > InnerClipRect . Min , window - > InnerClipRect . Max , true ) ;
2014-08-19 11:09:13 +00:00
2017-10-27 14:45:56 +00:00
// Clear 'accessed' flag last thing (After PushClipRect which will set the flag. We want the flag to stay false when the default "Debug" window is unused)
if ( first_begin_of_the_frame )
2017-11-18 23:07:38 +00:00
window - > WriteAccessed = false ;
2017-10-27 14:45:56 +00:00
2015-08-30 09:49:47 +00:00
window - > BeginCount + + ;
2019-05-13 12:45:41 +00:00
g . NextWindowData . ClearFlags ( ) ;
2015-03-20 10:54:21 +00:00
2014-08-19 11:09:13 +00:00
if ( flags & ImGuiWindowFlags_ChildWindow )
{
2018-07-09 19:06:46 +00:00
// Child window can be out of sight and have "negative" clip windows.
// Mark them as collapsed so commands are skipped earlier (we can't manually collapse them because they have no title bar).
2014-08-19 11:09:13 +00:00
IM_ASSERT ( ( flags & ImGuiWindowFlags_NoTitleBar ) ! = 0 ) ;
2015-06-25 02:08:08 +00:00
if ( ! ( flags & ImGuiWindowFlags_AlwaysAutoResize ) & & window - > AutoFitFramesX < = 0 & & window - > AutoFitFramesY < = 0 )
2018-06-27 15:21:59 +00:00
if ( window - > OuterRectClipped . Min . x > = window - > OuterRectClipped . Max . x | | window - > OuterRectClipped . Min . y > = window - > OuterRectClipped . Max . y )
2019-03-28 14:41:49 +00:00
window - > HiddenFramesCanSkipItems = 1 ;
2014-08-19 11:09:13 +00:00
2019-06-27 14:35:56 +00:00
// Hide along with parent or if parent is collapsed
if ( parent_window & & ( parent_window - > Collapsed | | parent_window - > HiddenFramesCanSkipItems > 0 ) )
2019-03-28 14:41:49 +00:00
window - > HiddenFramesCanSkipItems = 1 ;
2019-06-27 14:35:56 +00:00
if ( parent_window & & ( parent_window - > Collapsed | | parent_window - > HiddenFramesCannotSkipItems > 0 ) )
window - > HiddenFramesCannotSkipItems = 1 ;
2014-08-19 11:09:13 +00:00
}
2018-07-09 19:06:46 +00:00
// 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)
2014-12-30 15:38:28 +00:00
if ( style . Alpha < = 0.0f )
2019-03-28 14:41:49 +00:00
window - > HiddenFramesCanSkipItems = 1 ;
2018-06-27 15:21:59 +00:00
// Update the Hidden flag
2019-03-28 14:41:49 +00:00
window - > Hidden = ( window - > HiddenFramesCanSkipItems > 0 ) | | ( window - > HiddenFramesCannotSkipItems > 0 ) ;
2014-08-19 11:09:13 +00:00
2019-03-28 14:41:49 +00:00
// 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 ;
2018-06-27 15:21:59 +00:00
2019-03-28 14:41:49 +00:00
return ! skip_items ;
2014-08-10 20:58:11 +00:00
}
2014-11-10 01:29:01 +00:00
void ImGui : : End ( )
2014-08-10 20:58:11 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2019-11-13 20:35:42 +00:00
ImGuiWindow * window = g . CurrentWindow ;
2018-12-23 16:54:20 +00:00
2019-11-13 20:35:42 +00:00
// Error checking: verify that user hasn't called End() too many times!
if ( g . CurrentWindowStack . Size < = 1 & & g . WithinFrameScopeWithImplicitWindow )
2018-12-23 16:54:20 +00:00
{
2019-11-15 15:44:16 +00:00
IM_ASSERT_USER_ERROR ( g . CurrentWindowStack . Size > 1 , " Calling End() too many times! " ) ;
2019-11-13 20:35:42 +00:00
return ;
2018-12-23 16:54:20 +00:00
}
2019-01-02 21:52:09 +00:00
IM_ASSERT ( g . CurrentWindowStack . Size > 0 ) ;
2018-12-23 16:54:20 +00:00
2019-11-13 20:35:42 +00:00
// Error checking: verify that user doesn't directly call End() on a child window.
if ( window - > Flags & ImGuiWindowFlags_ChildWindow )
2019-11-15 15:44:16 +00:00
IM_ASSERT_USER_ERROR ( g . WithinEndChild , " Must call EndChild() and not End()! " ) ;
2014-08-19 11:09:13 +00:00
2019-11-13 20:35:42 +00:00
// Close anything that is open
2019-06-10 19:43:05 +00:00
if ( window - > DC . CurrentColumns )
2017-08-20 11:25:29 +00:00
EndColumns ( ) ;
2018-02-16 23:49:57 +00:00
PopClipRect ( ) ; // Inner window clip rectangle
2014-08-19 11:09:13 +00:00
// Stop logging
2014-09-02 13:35:06 +00:00
if ( ! ( window - > Flags & ImGuiWindowFlags_ChildWindow ) ) // FIXME: add more options for scope of logging
2016-05-29 16:58:41 +00:00
LogFinish ( ) ;
2014-08-10 20:58:11 +00:00
2018-02-16 23:49:57 +00:00
// Pop from window stack
2014-08-19 11:09:13 +00:00
g . CurrentWindowStack . pop_back ( ) ;
2015-05-11 14:57:02 +00:00
if ( window - > Flags & ImGuiWindowFlags_Popup )
2018-12-14 17:44:17 +00:00
g . BeginPopupStack . pop_back ( ) ;
2019-11-13 20:35:42 +00:00
ErrorCheckBeginEndCompareStacksSize ( window , false ) ;
2015-03-29 18:45:03 +00:00
SetCurrentWindow ( g . CurrentWindowStack . empty ( ) ? NULL : g . CurrentWindowStack . back ( ) ) ;
2014-08-10 20:58:11 +00:00
}
2018-09-10 18:30:14 +00:00
void ImGui : : BringWindowToFocusFront ( ImGuiWindow * window )
{
ImGuiContext & g = * GImGui ;
if ( g . WindowsFocusOrder . back ( ) = = window )
return ;
2019-06-19 16:14:24 +00:00
for ( int i = g . WindowsFocusOrder . Size - 2 ; i > = 0 ; i - - ) // We can ignore the top-most window
2018-09-10 18:30:14 +00:00
if ( g . WindowsFocusOrder [ i ] = = window )
{
memmove ( & g . WindowsFocusOrder [ i ] , & g . WindowsFocusOrder [ i + 1 ] , ( size_t ) ( g . WindowsFocusOrder . Size - i - 1 ) * sizeof ( ImGuiWindow * ) ) ;
g . WindowsFocusOrder [ g . WindowsFocusOrder . Size - 1 ] = window ;
break ;
}
}
void ImGui : : BringWindowToDisplayFront ( ImGuiWindow * window )
2017-11-16 12:11:16 +00:00
{
ImGuiContext & g = * GImGui ;
2018-01-31 21:14:33 +00:00
ImGuiWindow * current_front_window = g . Windows . back ( ) ;
if ( current_front_window = = window | | current_front_window - > RootWindow = = window )
2017-11-16 12:11:16 +00:00
return ;
2019-06-19 16:14:24 +00:00
for ( int i = g . Windows . Size - 2 ; i > = 0 ; i - - ) // We can ignore the top-most window
2017-11-16 12:11:16 +00:00
if ( g . Windows [ i ] = = window )
{
2018-09-10 18:30:14 +00:00
memmove ( & g . Windows [ i ] , & g . Windows [ i + 1 ] , ( size_t ) ( g . Windows . Size - i - 1 ) * sizeof ( ImGuiWindow * ) ) ;
g . Windows [ g . Windows . Size - 1 ] = window ;
2017-11-16 12:11:16 +00:00
break ;
}
}
2018-09-10 18:30:14 +00:00
void ImGui : : BringWindowToDisplayBack ( ImGuiWindow * window )
2017-11-16 12:11:16 +00:00
{
ImGuiContext & g = * GImGui ;
if ( g . Windows [ 0 ] = = window )
return ;
for ( int i = 0 ; i < g . Windows . Size ; i + + )
if ( g . Windows [ i ] = = window )
{
memmove ( & g . Windows [ 1 ] , & g . Windows [ 0 ] , ( size_t ) i * sizeof ( ImGuiWindow * ) ) ;
g . Windows [ 0 ] = window ;
break ;
}
}
// Moving window to front of display and set focus (which happens to be back of our sorted list)
2015-08-02 03:57:24 +00:00
void ImGui : : FocusWindow ( ImGuiWindow * window )
2014-08-10 20:58:11 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2015-02-28 09:54:14 +00:00
2016-07-31 11:38:57 +00:00
if ( g . NavWindow ! = window )
2016-07-19 22:02:59 +00:00
{
2018-01-31 23:50:42 +00:00
g . NavWindow = window ;
2016-07-19 22:02:59 +00:00
if ( window & & g . NavDisableMouseHover )
g . NavMousePosDirty = true ;
2018-02-01 17:19:36 +00:00
g . NavInitRequest = false ;
2018-02-05 13:53:07 +00:00
g . NavId = window ? window - > NavLastIds [ 0 ] : 0 ; // Restore NavId
g . NavIdIsAlive = false ;
2018-12-04 13:30:11 +00:00
g . NavLayer = ImGuiNavLayer_Main ;
2019-02-01 09:26:08 +00:00
//IMGUI_DEBUG_LOG("FocusWindow(\"%s\")\n", window ? window->Name : NULL);
2016-07-19 22:02:59 +00:00
}
2019-04-28 20:21:23 +00:00
// Close popups if any
ClosePopupsOverWindow ( window , false ) ;
2015-04-06 10:19:31 +00:00
// Passing NULL allow to disable keyboard focus
if ( ! window )
return ;
2017-11-16 12:11:16 +00:00
// Move the root window to the top of the pile
2015-02-28 09:54:14 +00:00
if ( window - > RootWindow )
window = window - > RootWindow ;
2015-05-27 21:58:49 +00:00
// Steal focus on active widgets
if ( window - > Flags & ImGuiWindowFlags_Popup ) // FIXME: This statement should be unnecessary. Need further testing before removing it..
if ( g . ActiveId ! = 0 & & g . ActiveIdWindow & & g . ActiveIdWindow - > RootWindow ! = window )
2017-01-11 19:56:55 +00:00
ClearActiveID ( ) ;
2015-05-27 21:58:49 +00:00
2015-10-02 17:07:04 +00:00
// Bring to front
2018-09-10 18:30:14 +00:00
BringWindowToFocusFront ( window ) ;
2017-11-16 12:11:16 +00:00
if ( ! ( window - > Flags & ImGuiWindowFlags_NoBringToFrontOnFocus ) )
2018-09-10 18:30:14 +00:00
BringWindowToDisplayFront ( window ) ;
2014-08-10 20:58:11 +00:00
}
2019-04-28 19:52:12 +00:00
void ImGui : : FocusTopMostWindowUnderOne ( ImGuiWindow * under_this_window , ImGuiWindow * ignore_window )
2017-10-23 10:34:15 +00:00
{
ImGuiContext & g = * GImGui ;
2019-04-28 19:52:12 +00:00
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 - - )
2018-09-10 18:30:14 +00:00
{
2018-11-29 22:24:22 +00:00
// 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.
2018-09-10 18:30:14 +00:00
ImGuiWindow * window = g . WindowsFocusOrder [ i ] ;
if ( window ! = ignore_window & & window - > WasActive & & ! ( window - > Flags & ImGuiWindowFlags_ChildWindow ) )
2018-11-29 22:24:22 +00:00
if ( ( window - > Flags & ( ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs ) ) ! = ( ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs ) )
{
ImGuiWindow * focus_window = NavRestoreLastChildNavWindow ( window ) ;
FocusWindow ( focus_window ) ;
return ;
}
2018-09-10 18:30:14 +00:00
}
2019-04-28 19:52:12 +00:00
FocusWindow ( NULL ) ;
2017-10-23 10:34:15 +00:00
}
2019-04-18 16:29:28 +00:00
void ImGui : : SetNextItemWidth ( float item_width )
{
2019-05-13 13:11:25 +00:00
ImGuiContext & g = * GImGui ;
g . NextItemData . Flags | = ImGuiNextItemDataFlags_HasWidth ;
g . NextItemData . Width = item_width ;
2019-04-18 16:29:28 +00:00
}
2014-11-10 01:29:01 +00:00
void ImGui : : PushItemWidth ( float item_width )
2014-08-10 20:58:11 +00:00
{
2019-05-13 13:29:00 +00:00
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = g . CurrentWindow ;
2015-05-27 14:35:49 +00:00
window - > DC . ItemWidth = ( item_width = = 0.0f ? window - > ItemWidthDefault : item_width ) ;
window - > DC . ItemWidthStack . push_back ( window - > DC . ItemWidth ) ;
2019-05-13 13:29:00 +00:00
g . NextItemData . Flags & = ~ ImGuiNextItemDataFlags_HasWidth ;
2014-08-10 20:58:11 +00:00
}
2017-09-25 20:45:10 +00:00
void ImGui : : PushMultiItemsWidths ( int components , float w_full )
2015-05-11 20:44:50 +00:00
{
2019-05-13 13:29:00 +00:00
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = g . CurrentWindow ;
2019-07-30 23:48:15 +00:00
const ImGuiStyle & style = g . Style ;
2019-10-17 09:36:26 +00:00
const float w_item_one = ImMax ( 1.0f , IM_FLOOR ( ( w_full - ( style . ItemInnerSpacing . x ) * ( components - 1 ) ) / ( float ) components ) ) ;
const float w_item_last = ImMax ( 1.0f , IM_FLOOR ( w_full - ( w_item_one + style . ItemInnerSpacing . x ) * ( components - 1 ) ) ) ;
2015-05-27 14:35:49 +00:00
window - > DC . ItemWidthStack . push_back ( w_item_last ) ;
2015-05-11 20:44:50 +00:00
for ( int i = 0 ; i < components - 1 ; i + + )
2015-05-27 14:35:49 +00:00
window - > DC . ItemWidthStack . push_back ( w_item_one ) ;
window - > DC . ItemWidth = window - > DC . ItemWidthStack . back ( ) ;
2019-05-13 13:29:00 +00:00
g . NextItemData . Flags & = ~ ImGuiNextItemDataFlags_HasWidth ;
2015-05-11 20:44:50 +00:00
}
2014-11-10 01:29:01 +00:00
void ImGui : : PopItemWidth ( )
2014-08-10 20:58:11 +00:00
{
2014-08-19 11:09:13 +00:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2015-05-27 14:35:49 +00:00
window - > DC . ItemWidthStack . pop_back ( ) ;
2015-05-27 14:42:29 +00:00
window - > DC . ItemWidth = window - > DC . ItemWidthStack . empty ( ) ? window - > ItemWidthDefault : window - > DC . ItemWidthStack . back ( ) ;
2014-08-10 20:58:11 +00:00
}
2019-05-13 13:29:00 +00:00
// 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 ( )
2014-08-11 23:04:13 +00:00
{
2019-05-13 13:11:25 +00:00
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = g . CurrentWindow ;
2019-04-18 16:29:28 +00:00
float w ;
2019-05-13 13:11:25 +00:00
if ( g . NextItemData . Flags & ImGuiNextItemDataFlags_HasWidth )
w = g . NextItemData . Width ;
2019-04-18 16:29:28 +00:00
else
w = window - > DC . ItemWidth ;
2015-02-10 21:07:26 +00:00
if ( w < 0.0f )
{
2019-05-28 13:54:55 +00:00
float region_max_x = GetContentRegionMaxAbs ( ) . x ;
2019-04-18 12:48:36 +00:00
w = ImMax ( 1.0f , region_max_x - window - > DC . CursorPos . x + w ) ;
2015-02-10 21:07:26 +00:00
}
2019-10-17 09:36:26 +00:00
w = IM_FLOOR ( w ) ;
2015-02-10 21:07:26 +00:00
return w ;
2014-08-11 23:04:13 +00:00
}
2019-05-13 13:29:00 +00:00
// [Internal] Calculate full item size given user provided 'size' parameter and default width/height. Default width is often == CalcItemWidth().
2019-04-18 11:46:45 +00:00
// Those two functions CalcItemWidth vs CalcItemSize are awkwardly named because they are not fully symmetrical.
// Note that only CalcItemWidth() is publicly exposed.
2019-05-13 13:29:00 +00:00
// The 4.0f here may be changed to match CalcItemWidth() and/or BeginChild() (right now we have a mismatch which is harmless but undesirable)
2019-04-18 11:46:45 +00:00
ImVec2 ImGui : : CalcItemSize ( ImVec2 size , float default_w , float default_h )
{
2019-04-18 12:10:01 +00:00
ImGuiWindow * window = GImGui - > CurrentWindow ;
2019-04-18 12:48:36 +00:00
ImVec2 region_max ;
2019-04-18 11:46:45 +00:00
if ( size . x < 0.0f | | size . y < 0.0f )
2019-05-28 13:54:55 +00:00
region_max = GetContentRegionMaxAbs ( ) ;
2019-04-18 12:48:36 +00:00
if ( size . x = = 0.0f )
size . x = default_w ;
else if ( size . x < 0.0f )
2019-04-18 13:35:20 +00:00
size . x = ImMax ( 4.0f , region_max . x - window - > DC . CursorPos . x + size . x ) ;
2019-04-18 12:48:36 +00:00
if ( size . y = = 0.0f )
size . y = default_h ;
else if ( size . y < 0.0f )
2019-04-18 13:35:20 +00:00
size . y = ImMax ( 4.0f , region_max . y - window - > DC . CursorPos . y + size . y ) ;
2019-04-18 12:48:36 +00:00
2019-04-18 11:46:45 +00:00
return size ;
}
2018-01-12 19:07:01 +00:00
void ImGui : : SetCurrentFont ( ImFont * font )
2015-01-17 13:40:56 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2015-11-29 21:33:51 +00:00
IM_ASSERT ( font & & font - > IsLoaded ( ) ) ; // Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ?
2015-01-17 13:40:56 +00:00
IM_ASSERT ( font - > Scale > 0.0f ) ;
g . Font = font ;
2019-02-04 13:38:35 +00:00
g . FontBaseSize = ImMax ( 1.0f , g . IO . FontGlobalScale * g . Font - > FontSize * g . Font - > Scale ) ;
2015-03-29 18:45:03 +00:00
g . FontSize = g . CurrentWindow ? g . CurrentWindow - > CalcFontSize ( ) : 0.0f ;
2017-12-21 17:50:27 +00:00
ImFontAtlas * atlas = g . Font - > ContainerAtlas ;
g . DrawListSharedData . TexUvWhitePixel = atlas - > TexUvWhitePixel ;
g . DrawListSharedData . Font = g . Font ;
g . DrawListSharedData . FontSize = g . FontSize ;
2015-01-17 13:40:56 +00:00
}
void ImGui : : PushFont ( ImFont * font )
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2015-01-17 22:15:29 +00:00
if ( ! font )
2016-11-06 20:50:18 +00:00
font = GetDefaultFont ( ) ;
2015-07-21 23:00:28 +00:00
SetCurrentFont ( font ) ;
2015-01-17 14:13:08 +00:00
g . FontStack . push_back ( font ) ;
2015-01-17 22:15:29 +00:00
g . CurrentWindow - > DrawList - > PushTextureID ( font - > ContainerAtlas - > TexID ) ;
2015-01-17 13:40:56 +00:00
}
void ImGui : : PopFont ( )
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2015-01-17 14:13:08 +00:00
g . CurrentWindow - > DrawList - > PopTextureID ( ) ;
2015-01-17 13:40:56 +00:00
g . FontStack . pop_back ( ) ;
2016-11-06 20:50:18 +00:00
SetCurrentFont ( g . FontStack . empty ( ) ? GetDefaultFont ( ) : g . FontStack . back ( ) ) ;
2015-01-17 13:40:56 +00:00
}
2016-08-07 18:05:24 +00:00
void ImGui : : PushItemFlag ( ImGuiItemFlags option , bool enabled )
2014-08-10 20:58:11 +00:00
{
2014-08-19 11:09:13 +00:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2016-08-07 18:05:24 +00:00
if ( enabled )
window - > DC . ItemFlags | = option ;
else
window - > DC . ItemFlags & = ~ option ;
window - > DC . ItemFlagsStack . push_back ( window - > DC . ItemFlags ) ;
2014-08-10 20:58:11 +00:00
}
2016-08-07 18:05:24 +00:00
void ImGui : : PopItemFlag ( )
2014-08-10 20:58:11 +00:00
{
2014-08-19 11:09:13 +00:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2016-08-07 18:05:24 +00:00
window - > DC . ItemFlagsStack . pop_back ( ) ;
window - > DC . ItemFlags = window - > DC . ItemFlagsStack . empty ( ) ? ImGuiItemFlags_Default_ : window - > DC . ItemFlagsStack . back ( ) ;
}
2018-10-10 10:01:40 +00:00
// FIXME: Look into renaming this once we have settled the new Focus/Activation/TabStop system.
2016-08-07 18:05:24 +00:00
void ImGui : : PushAllowKeyboardFocus ( bool allow_keyboard_focus )
{
2018-10-10 10:01:40 +00:00
PushItemFlag ( ImGuiItemFlags_NoTabStop , ! allow_keyboard_focus ) ;
2016-08-07 18:05:24 +00:00
}
void ImGui : : PopAllowKeyboardFocus ( )
{
PopItemFlag ( ) ;
2014-08-10 20:58:11 +00:00
}
2015-05-27 14:22:09 +00:00
void ImGui : : PushButtonRepeat ( bool repeat )
{
2016-08-07 18:05:24 +00:00
PushItemFlag ( ImGuiItemFlags_ButtonRepeat , repeat ) ;
2015-05-27 14:22:09 +00:00
}
void ImGui : : PopButtonRepeat ( )
{
2016-08-07 18:05:24 +00:00
PopItemFlag ( ) ;
2014-08-10 20:58:11 +00:00
}
2015-05-27 14:35:49 +00:00
void ImGui : : PushTextWrapPos ( float wrap_pos_x )
2014-11-07 05:45:56 +00:00
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
2015-05-27 14:35:49 +00:00
window - > DC . TextWrapPos = wrap_pos_x ;
window - > DC . TextWrapPosStack . push_back ( wrap_pos_x ) ;
2014-11-07 05:45:56 +00:00
}
2014-11-10 01:29:01 +00:00
void ImGui : : PopTextWrapPos ( )
2014-11-07 05:45:56 +00:00
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
2015-05-27 14:35:49 +00:00
window - > DC . TextWrapPosStack . pop_back ( ) ;
2015-05-27 14:44:07 +00:00
window - > DC . TextWrapPos = window - > DC . TextWrapPosStack . empty ( ) ? - 1.0f : window - > DC . TextWrapPosStack . back ( ) ;
2014-11-07 05:45:56 +00:00
}
2017-08-20 07:28:12 +00:00
// FIXME: This may incur a round-trip (if the end user got their data from a float4) but eventually we aim to store the in-flight colors as ImU32
void ImGui : : PushStyleColor ( ImGuiCol idx , ImU32 col )
{
ImGuiContext & g = * GImGui ;
2018-08-22 20:13:05 +00:00
ImGuiColorMod backup ;
2017-08-20 07:28:12 +00:00
backup . Col = idx ;
backup . BackupValue = g . Style . Colors [ idx ] ;
g . ColorModifiers . push_back ( backup ) ;
g . Style . Colors [ idx ] = ColorConvertU32ToFloat4 ( col ) ;
}
2014-11-10 01:29:01 +00:00
void ImGui : : PushStyleColor ( ImGuiCol idx , const ImVec4 & col )
2014-08-10 20:58:11 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2018-08-22 20:13:05 +00:00
ImGuiColorMod backup ;
2014-08-19 11:09:13 +00:00
backup . Col = idx ;
2016-09-25 09:06:14 +00:00
backup . BackupValue = g . Style . Colors [ idx ] ;
2014-11-21 13:23:22 +00:00
g . ColorModifiers . push_back ( backup ) ;
2014-08-19 11:09:13 +00:00
g . Style . Colors [ idx ] = col ;
2014-08-10 20:58:11 +00:00
}
2014-11-21 13:23:22 +00:00
void ImGui : : PopStyleColor ( int count )
2014-08-10 20:58:11 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2014-11-21 13:23:22 +00:00
while ( count > 0 )
{
2018-08-22 20:13:05 +00:00
ImGuiColorMod & backup = g . ColorModifiers . back ( ) ;
2016-09-25 09:06:14 +00:00
g . Style . Colors [ backup . Col ] = backup . BackupValue ;
2014-11-21 13:23:22 +00:00
g . ColorModifiers . pop_back ( ) ;
count - - ;
}
2014-08-10 20:58:11 +00:00
}
2016-09-25 09:06:14 +00:00
struct ImGuiStyleVarInfo
2014-11-07 08:22:38 +00:00
{
2016-09-25 09:06:14 +00:00
ImGuiDataType Type ;
2018-03-22 19:14:31 +00:00
ImU32 Count ;
2016-09-25 09:06:14 +00:00
ImU32 Offset ;
2017-08-15 11:19:00 +00:00
void * GetVarPtr ( ImGuiStyle * style ) const { return ( void * ) ( ( unsigned char * ) style + Offset ) ; }
2016-09-25 09:06:14 +00:00
} ;
2014-11-07 08:22:38 +00:00
2018-01-23 08:57:49 +00:00
static const ImGuiStyleVarInfo GStyleVarInfo [ ] =
2016-09-25 09:06:14 +00:00
{
2019-02-13 22:56:21 +00:00
{ 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
2016-09-25 09:06:14 +00:00
} ;
2016-09-25 09:14:10 +00:00
static const ImGuiStyleVarInfo * GetStyleVarInfo ( ImGuiStyleVar idx )
2014-11-07 08:22:38 +00:00
{
2018-03-03 19:15:10 +00:00
IM_ASSERT ( idx > = 0 & & idx < ImGuiStyleVar_COUNT ) ;
IM_ASSERT ( IM_ARRAYSIZE ( GStyleVarInfo ) = = ImGuiStyleVar_COUNT ) ;
2016-09-25 09:14:10 +00:00
return & GStyleVarInfo [ idx ] ;
2014-11-07 08:22:38 +00:00
}
2014-11-10 01:29:01 +00:00
void ImGui : : PushStyleVar ( ImGuiStyleVar idx , float val )
2014-11-07 08:22:38 +00:00
{
2016-09-25 09:14:10 +00:00
const ImGuiStyleVarInfo * var_info = GetStyleVarInfo ( idx ) ;
2018-03-22 19:14:31 +00:00
if ( var_info - > Type = = ImGuiDataType_Float & & var_info - > Count = = 1 )
2016-09-25 09:06:14 +00:00
{
2017-08-15 11:19:00 +00:00
ImGuiContext & g = * GImGui ;
float * pvar = ( float * ) var_info - > GetVarPtr ( & g . Style ) ;
g . StyleModifiers . push_back ( ImGuiStyleMod ( idx , * pvar ) ) ;
2016-09-25 09:06:14 +00:00
* pvar = val ;
return ;
}
2019-04-25 09:34:07 +00:00
IM_ASSERT ( 0 & & " Called PushStyleVar() float variant but variable is not a float! " ) ;
2014-11-07 08:22:38 +00:00
}
2014-11-10 01:29:01 +00:00
void ImGui : : PushStyleVar ( ImGuiStyleVar idx , const ImVec2 & val )
2014-11-07 08:22:38 +00:00
{
2016-09-25 09:14:10 +00:00
const ImGuiStyleVarInfo * var_info = GetStyleVarInfo ( idx ) ;
2018-03-22 19:14:31 +00:00
if ( var_info - > Type = = ImGuiDataType_Float & & var_info - > Count = = 2 )
2016-09-25 09:06:14 +00:00
{
2017-08-15 11:19:00 +00:00
ImGuiContext & g = * GImGui ;
ImVec2 * pvar = ( ImVec2 * ) var_info - > GetVarPtr ( & g . Style ) ;
g . StyleModifiers . push_back ( ImGuiStyleMod ( idx , * pvar ) ) ;
2016-09-25 09:06:14 +00:00
* pvar = val ;
return ;
}
2019-04-25 09:34:07 +00:00
IM_ASSERT ( 0 & & " Called PushStyleVar() ImVec2 variant but variable is not a ImVec2! " ) ;
2014-11-07 08:22:38 +00:00
}
2014-11-21 13:23:22 +00:00
void ImGui : : PopStyleVar ( int count )
2014-11-07 08:22:38 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2014-11-21 13:23:22 +00:00
while ( count > 0 )
{
2018-03-22 19:14:31 +00:00
// We avoid a generic memcpy(data, &backup.Backup.., GDataTypeSize[info->Type] * info->Count), the overhead in Debug is not worth it.
2014-11-21 13:23:22 +00:00
ImGuiStyleMod & backup = g . StyleModifiers . back ( ) ;
2016-09-25 09:14:10 +00:00
const ImGuiStyleVarInfo * info = GetStyleVarInfo ( backup . VarIdx ) ;
2018-03-22 19:14:31 +00:00
void * data = info - > GetVarPtr ( & g . Style ) ;
if ( info - > Type = = ImGuiDataType_Float & & info - > Count = = 1 ) { ( ( float * ) data ) [ 0 ] = backup . BackupFloat [ 0 ] ; }
else if ( info - > Type = = ImGuiDataType_Float & & info - > Count = = 2 ) { ( ( float * ) data ) [ 0 ] = backup . BackupFloat [ 0 ] ; ( ( float * ) data ) [ 1 ] = backup . BackupFloat [ 1 ] ; }
2014-11-21 13:23:22 +00:00
g . StyleModifiers . pop_back ( ) ;
2014-11-21 16:29:56 +00:00
count - - ;
2014-11-21 13:23:22 +00:00
}
2014-11-07 08:22:38 +00:00
}
2017-08-20 09:53:09 +00:00
const char * ImGui : : GetStyleColorName ( ImGuiCol idx )
2014-08-10 20:58:11 +00:00
{
2014-09-02 13:35:06 +00:00
// Create switch-case from enum with regexp: ImGuiCol_{.*}, --> case ImGuiCol_\1: return "\1";
2014-08-19 11:09:13 +00:00
switch ( idx )
{
case ImGuiCol_Text : return " Text " ;
2015-05-11 18:36:32 +00:00
case ImGuiCol_TextDisabled : return " TextDisabled " ;
2014-08-19 11:09:13 +00:00
case ImGuiCol_WindowBg : return " WindowBg " ;
2017-11-19 12:52:40 +00:00
case ImGuiCol_ChildBg : return " ChildBg " ;
2016-04-03 23:37:02 +00:00
case ImGuiCol_PopupBg : return " PopupBg " ;
2014-08-19 11:09:13 +00:00
case ImGuiCol_Border : return " Border " ;
case ImGuiCol_BorderShadow : return " BorderShadow " ;
case ImGuiCol_FrameBg : return " FrameBg " ;
2015-04-03 13:07:52 +00:00
case ImGuiCol_FrameBgHovered : return " FrameBgHovered " ;
case ImGuiCol_FrameBgActive : return " FrameBgActive " ;
2014-08-19 11:09:13 +00:00
case ImGuiCol_TitleBg : return " TitleBg " ;
2015-06-30 19:40:13 +00:00
case ImGuiCol_TitleBgActive : return " TitleBgActive " ;
2017-08-15 11:06:02 +00:00
case ImGuiCol_TitleBgCollapsed : return " TitleBgCollapsed " ;
2015-05-17 16:13:45 +00:00
case ImGuiCol_MenuBarBg : return " MenuBarBg " ;
2014-08-19 11:09:13 +00:00
case ImGuiCol_ScrollbarBg : return " ScrollbarBg " ;
case ImGuiCol_ScrollbarGrab : return " ScrollbarGrab " ;
case ImGuiCol_ScrollbarGrabHovered : return " ScrollbarGrabHovered " ;
case ImGuiCol_ScrollbarGrabActive : return " ScrollbarGrabActive " ;
2015-01-09 17:19:24 +00:00
case ImGuiCol_CheckMark : return " CheckMark " ;
2014-08-19 11:09:13 +00:00
case ImGuiCol_SliderGrab : return " SliderGrab " ;
case ImGuiCol_SliderGrabActive : return " SliderGrabActive " ;
case ImGuiCol_Button : return " Button " ;
case ImGuiCol_ButtonHovered : return " ButtonHovered " ;
case ImGuiCol_ButtonActive : return " ButtonActive " ;
case ImGuiCol_Header : return " Header " ;
case ImGuiCol_HeaderHovered : return " HeaderHovered " ;
case ImGuiCol_HeaderActive : return " HeaderActive " ;
2017-08-14 05:04:32 +00:00
case ImGuiCol_Separator : return " Separator " ;
case ImGuiCol_SeparatorHovered : return " SeparatorHovered " ;
case ImGuiCol_SeparatorActive : return " SeparatorActive " ;
2014-08-19 11:09:13 +00:00
case ImGuiCol_ResizeGrip : return " ResizeGrip " ;
case ImGuiCol_ResizeGripHovered : return " ResizeGripHovered " ;
case ImGuiCol_ResizeGripActive : return " ResizeGripActive " ;
2018-12-11 11:36:47 +00:00
case ImGuiCol_Tab : return " Tab " ;
case ImGuiCol_TabHovered : return " TabHovered " ;
case ImGuiCol_TabActive : return " TabActive " ;
case ImGuiCol_TabUnfocused : return " TabUnfocused " ;
case ImGuiCol_TabUnfocusedActive : return " TabUnfocusedActive " ;
2014-08-19 11:09:13 +00:00
case ImGuiCol_PlotLines : return " PlotLines " ;
case ImGuiCol_PlotLinesHovered : return " PlotLinesHovered " ;
case ImGuiCol_PlotHistogram : return " PlotHistogram " ;
2014-08-20 16:42:53 +00:00
case ImGuiCol_PlotHistogramHovered : return " PlotHistogramHovered " ;
2014-08-19 11:09:13 +00:00
case ImGuiCol_TextSelectedBg : return " TextSelectedBg " ;
2017-12-12 14:44:22 +00:00
case ImGuiCol_DragDropTarget : return " DragDropTarget " ;
2016-08-15 11:07:39 +00:00
case ImGuiCol_NavHighlight : return " NavHighlight " ;
2018-07-12 07:53:10 +00:00
case ImGuiCol_NavWindowingHighlight : return " NavWindowingHighlight " ;
case ImGuiCol_NavWindowingDimBg : return " NavWindowingDimBg " ;
2018-07-09 17:16:48 +00:00
case ImGuiCol_ModalWindowDimBg : return " ModalWindowDimBg " ;
2014-08-19 11:09:13 +00:00
}
IM_ASSERT ( 0 ) ;
return " Unknown " ;
2014-08-10 20:58:11 +00:00
}
2017-12-11 22:16:27 +00:00
bool ImGui : : IsWindowChildOf ( ImGuiWindow * window , ImGuiWindow * potential_parent )
{
if ( window - > RootWindow = = potential_parent )
return true ;
while ( window ! = NULL )
{
if ( window = = potential_parent )
return true ;
window = window - > ParentWindow ;
}
return false ;
}
2017-10-20 15:52:22 +00:00
bool ImGui : : IsWindowHovered ( ImGuiHoveredFlags flags )
2015-06-02 19:57:29 +00:00
{
2017-10-20 15:59:48 +00:00
IM_ASSERT ( ( flags & ImGuiHoveredFlags_AllowWhenOverlapped ) = = 0 ) ; // Flags not supported by this function
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2018-01-11 12:49:32 +00:00
if ( flags & ImGuiHoveredFlags_AnyWindow )
2017-11-02 15:44:24 +00:00
{
2018-01-11 12:49:32 +00:00
if ( g . HoveredWindow = = NULL )
2017-12-11 22:16:27 +00:00
return false ;
2018-01-11 12:49:32 +00:00
}
else
{
switch ( flags & ( ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows ) )
{
case ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows :
if ( g . HoveredRootWindow ! = g . CurrentWindow - > RootWindow )
return false ;
break ;
case ImGuiHoveredFlags_RootWindow :
if ( g . HoveredWindow ! = g . CurrentWindow - > RootWindow )
return false ;
break ;
case ImGuiHoveredFlags_ChildWindows :
if ( g . HoveredWindow = = NULL | | ! IsWindowChildOf ( g . HoveredWindow , g . CurrentWindow ) )
return false ;
break ;
default :
if ( g . HoveredWindow ! = g . CurrentWindow )
return false ;
break ;
}
2017-11-02 15:44:24 +00:00
}
2017-12-11 22:16:27 +00:00
2019-03-25 14:39:11 +00:00
if ( ! IsWindowContentHoverable ( g . HoveredWindow , flags ) )
2017-10-20 15:59:48 +00:00
return false ;
if ( ! ( flags & ImGuiHoveredFlags_AllowWhenBlockedByActiveItem ) )
2017-11-02 15:44:32 +00:00
if ( g . ActiveId ! = 0 & & ! g . ActiveIdAllowOverlap & & g . ActiveId ! = g . HoveredWindow - > MoveId )
2017-10-20 15:59:48 +00:00
return false ;
return true ;
2017-08-22 12:27:39 +00:00
}
2017-12-12 13:06:24 +00:00
bool ImGui : : IsWindowFocused ( ImGuiFocusedFlags flags )
2015-03-13 12:25:43 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2015-03-13 12:25:43 +00:00
2018-01-11 12:49:32 +00:00
if ( flags & ImGuiFocusedFlags_AnyWindow )
return g . NavWindow ! = NULL ;
2018-11-13 10:23:15 +00:00
IM_ASSERT ( g . CurrentWindow ) ; // Not inside a Begin()/End()
2017-12-12 22:49:04 +00:00
switch ( flags & ( ImGuiFocusedFlags_RootWindow | ImGuiFocusedFlags_ChildWindows ) )
2017-12-12 13:06:24 +00:00
{
2017-12-12 22:49:04 +00:00
case ImGuiFocusedFlags_RootWindow | ImGuiFocusedFlags_ChildWindows :
2018-01-11 12:49:32 +00:00
return g . NavWindow & & g . NavWindow - > RootWindow = = g . CurrentWindow - > RootWindow ;
2017-12-12 13:06:24 +00:00
case ImGuiFocusedFlags_RootWindow :
2018-01-11 12:49:32 +00:00
return g . NavWindow = = g . CurrentWindow - > RootWindow ;
2017-12-12 22:49:04 +00:00
case ImGuiFocusedFlags_ChildWindows :
2017-12-12 13:06:24 +00:00
return g . NavWindow & & IsWindowChildOf ( g . NavWindow , g . CurrentWindow ) ;
default :
2018-01-11 12:49:32 +00:00
return g . NavWindow = = g . CurrentWindow ;
2017-12-12 13:06:24 +00:00
}
2016-05-01 10:14:07 +00:00
}
2018-02-01 13:56:56 +00:00
// Can we focus this window with CTRL+TAB (or PadMenu + PadFocusPrev/PadFocusNext)
2018-11-29 22:24:22 +00:00
// Note that NoNavFocus makes the window not reachable with CTRL+TAB but it can still be focused with mouse or programmaticaly.
// If you want a window to never be focused, you may use the e.g. NoInputs flag.
2018-02-01 13:56:56 +00:00
bool ImGui : : IsWindowNavFocusable ( ImGuiWindow * window )
{
2018-08-08 14:03:13 +00:00
return window - > Active & & window = = window - > RootWindow & & ! ( window - > Flags & ImGuiWindowFlags_NoNavFocus ) ;
2018-02-01 13:56:56 +00:00
}
2014-11-10 01:29:01 +00:00
float ImGui : : GetWindowWidth ( )
2014-08-10 20:58:11 +00:00
{
2015-07-03 02:53:45 +00:00
ImGuiWindow * window = GImGui - > CurrentWindow ;
2014-08-19 11:09:13 +00:00
return window - > Size . x ;
2014-08-10 20:58:11 +00:00
}
2015-08-25 15:55:14 +00:00
float ImGui : : GetWindowHeight ( )
{
ImGuiWindow * window = GImGui - > CurrentWindow ;
return window - > Size . y ;
}
2014-11-10 01:29:01 +00:00
ImVec2 ImGui : : GetWindowPos ( )
2014-08-10 20:58:11 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2015-06-02 19:57:29 +00:00
ImGuiWindow * window = g . CurrentWindow ;
2014-08-19 11:09:13 +00:00
return window - > Pos ;
2014-08-10 20:58:11 +00:00
}
2019-02-03 16:29:51 +00:00
void ImGui : : SetWindowPos ( ImGuiWindow * window , const ImVec2 & pos , ImGuiCond cond )
2014-08-10 20:58:11 +00:00
{
2014-12-10 19:22:30 +00:00
// Test condition (NB: bit 0 is always true) and clear flags for next time
if ( cond & & ( window - > SetWindowPosAllowFlags & cond ) = = 0 )
return ;
2018-04-04 13:01:01 +00:00
IM_ASSERT ( cond = = 0 | | ImIsPowerOfTwo ( cond ) ) ; // Make sure the user doesn't attempt to combine multiple condition flags.
2017-08-11 05:36:28 +00:00
window - > SetWindowPosAllowFlags & = ~ ( ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing ) ;
2017-09-25 16:25:43 +00:00
window - > SetWindowPosVal = ImVec2 ( FLT_MAX , FLT_MAX ) ;
2014-12-10 19:22:30 +00:00
// Set
2014-08-19 11:09:13 +00:00
const ImVec2 old_pos = window - > Pos ;
2018-01-10 15:11:29 +00:00
window - > Pos = ImFloor ( pos ) ;
2019-06-03 13:35:55 +00:00
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
2019-06-03 14:55:48 +00:00
window - > DC . CursorMaxPos + = offset ; // And more importantly we need to offset CursorMaxPos/CursorStartPos this so ContentSize calculation doesn't get affected.
2019-06-03 13:35:55 +00:00
window - > DC . CursorStartPos + = offset ;
2014-08-10 20:58:11 +00:00
}
2017-08-11 05:36:28 +00:00
void ImGui : : SetWindowPos ( const ImVec2 & pos , ImGuiCond cond )
2014-08-10 20:58:11 +00:00
{
2016-10-01 13:16:17 +00:00
ImGuiWindow * window = GetCurrentWindowRead ( ) ;
2015-02-27 09:07:25 +00:00
SetWindowPos ( window , pos , cond ) ;
2014-08-10 20:58:11 +00:00
}
2017-08-11 05:36:28 +00:00
void ImGui : : SetWindowPos ( const char * name , const ImVec2 & pos , ImGuiCond cond )
2015-02-27 09:07:25 +00:00
{
2016-10-01 13:16:17 +00:00
if ( ImGuiWindow * window = FindWindowByName ( name ) )
2015-02-27 09:07:25 +00:00
SetWindowPos ( window , pos , cond ) ;
}
ImVec2 ImGui : : GetWindowSize ( )
2014-10-26 20:07:15 +00:00
{
2015-08-30 10:56:04 +00:00
ImGuiWindow * window = GetCurrentWindowRead ( ) ;
2015-02-27 09:07:25 +00:00
return window - > Size ;
}
2014-12-10 19:22:30 +00:00
2019-02-03 16:29:51 +00:00
void ImGui : : SetWindowSize ( ImGuiWindow * window , const ImVec2 & size , ImGuiCond cond )
2015-02-27 09:07:25 +00:00
{
2014-12-10 19:22:30 +00:00
// Test condition (NB: bit 0 is always true) and clear flags for next time
if ( cond & & ( window - > SetWindowSizeAllowFlags & cond ) = = 0 )
return ;
2018-04-04 13:01:01 +00:00
IM_ASSERT ( cond = = 0 | | ImIsPowerOfTwo ( cond ) ) ; // Make sure the user doesn't attempt to combine multiple condition flags.
2017-08-11 05:36:28 +00:00
window - > SetWindowSizeAllowFlags & = ~ ( ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing ) ;
2014-12-10 19:22:30 +00:00
// Set
2015-06-25 02:08:08 +00:00
if ( size . x > 0.0f )
2014-11-21 16:29:56 +00:00
{
2015-08-25 11:40:40 +00:00
window - > AutoFitFramesX = 0 ;
2019-10-29 16:04:13 +00:00
window - > SizeFull . x = IM_FLOOR ( size . x ) ;
2014-11-21 16:29:56 +00:00
}
else
{
2015-06-25 02:08:08 +00:00
window - > AutoFitFramesX = 2 ;
window - > AutoFitOnlyGrows = false ;
}
if ( size . y > 0.0f )
2014-11-21 16:29:56 +00:00
{
2015-08-25 11:40:40 +00:00
window - > AutoFitFramesY = 0 ;
2019-10-29 16:04:13 +00:00
window - > SizeFull . y = IM_FLOOR ( size . y ) ;
2014-11-21 16:29:56 +00:00
}
else
{
2015-06-25 02:08:08 +00:00
window - > AutoFitFramesY = 2 ;
2014-12-29 11:23:03 +00:00
window - > AutoFitOnlyGrows = false ;
2014-11-21 16:29:56 +00:00
}
2014-10-26 20:07:15 +00:00
}
2017-08-11 05:36:28 +00:00
void ImGui : : SetWindowSize ( const ImVec2 & size , ImGuiCond cond )
2014-12-10 19:22:30 +00:00
{
2015-08-30 09:49:47 +00:00
SetWindowSize ( GImGui - > CurrentWindow , size , cond ) ;
2015-02-27 09:07:25 +00:00
}
2014-12-10 19:22:30 +00:00
2017-08-11 05:36:28 +00:00
void ImGui : : SetWindowSize ( const char * name , const ImVec2 & size , ImGuiCond cond )
2015-02-27 09:07:25 +00:00
{
2017-10-17 13:47:55 +00:00
if ( ImGuiWindow * window = FindWindowByName ( name ) )
2015-02-27 09:07:25 +00:00
SetWindowSize ( window , size , cond ) ;
}
2019-02-03 16:29:51 +00:00
void ImGui : : SetWindowCollapsed ( ImGuiWindow * window , bool collapsed , ImGuiCond cond )
2015-02-27 09:07:25 +00:00
{
2014-12-10 19:22:30 +00:00
// Test condition (NB: bit 0 is always true) and clear flags for next time
if ( cond & & ( window - > SetWindowCollapsedAllowFlags & cond ) = = 0 )
return ;
2017-08-11 05:36:28 +00:00
window - > SetWindowCollapsedAllowFlags & = ~ ( ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing ) ;
2014-12-10 19:22:30 +00:00
// Set
window - > Collapsed = collapsed ;
}
2017-08-11 05:36:28 +00:00
void ImGui : : SetWindowCollapsed ( bool collapsed , ImGuiCond cond )
2015-02-27 09:07:25 +00:00
{
2015-08-30 09:49:47 +00:00
SetWindowCollapsed ( GImGui - > CurrentWindow , collapsed , cond ) ;
2015-02-27 09:07:25 +00:00
}
2015-05-31 10:52:57 +00:00
bool ImGui : : IsWindowCollapsed ( )
2015-02-28 20:47:59 +00:00
{
2017-09-01 19:55:59 +00:00
ImGuiWindow * window = GetCurrentWindowRead ( ) ;
return window - > Collapsed ;
}
bool ImGui : : IsWindowAppearing ( )
{
ImGuiWindow * window = GetCurrentWindowRead ( ) ;
return window - > Appearing ;
2015-02-28 20:47:59 +00:00
}
2017-08-11 05:36:28 +00:00
void ImGui : : SetWindowCollapsed ( const char * name , bool collapsed , ImGuiCond cond )
2015-02-27 09:07:25 +00:00
{
2017-11-07 12:59:55 +00:00
if ( ImGuiWindow * window = FindWindowByName ( name ) )
2015-02-27 09:13:23 +00:00
SetWindowCollapsed ( window , collapsed , cond ) ;
2015-02-27 09:07:25 +00:00
}
2015-02-27 09:01:12 +00:00
void ImGui : : SetWindowFocus ( )
{
2015-08-30 09:49:47 +00:00
FocusWindow ( GImGui - > CurrentWindow ) ;
2015-02-27 09:01:12 +00:00
}
void ImGui : : SetWindowFocus ( const char * name )
{
2015-04-06 10:19:31 +00:00
if ( name )
{
2016-06-25 15:03:49 +00:00
if ( ImGuiWindow * window = FindWindowByName ( name ) )
2015-04-06 10:19:31 +00:00
FocusWindow ( window ) ;
}
else
{
FocusWindow ( NULL ) ;
}
2015-02-27 09:01:12 +00:00
}
2017-09-25 16:25:43 +00:00
void ImGui : : SetNextWindowPos ( const ImVec2 & pos , ImGuiCond cond , const ImVec2 & pivot )
2014-12-10 19:22:30 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2018-04-04 13:01:01 +00:00
IM_ASSERT ( cond = = 0 | | ImIsPowerOfTwo ( cond ) ) ; // Make sure the user doesn't attempt to combine multiple condition flags.
2019-05-13 12:45:41 +00:00
g . NextWindowData . Flags | = ImGuiNextWindowDataFlags_HasPos ;
2018-01-03 11:28:16 +00:00
g . NextWindowData . PosVal = pos ;
g . NextWindowData . PosPivotVal = pivot ;
g . NextWindowData . PosCond = cond ? cond : ImGuiCond_Always ;
2014-12-10 19:22:30 +00:00
}
2017-08-11 05:36:28 +00:00
void ImGui : : SetNextWindowSize ( const ImVec2 & size , ImGuiCond cond )
2014-12-10 19:22:30 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2018-04-04 13:01:01 +00:00
IM_ASSERT ( cond = = 0 | | ImIsPowerOfTwo ( cond ) ) ; // Make sure the user doesn't attempt to combine multiple condition flags.
2019-05-13 12:45:41 +00:00
g . NextWindowData . Flags | = ImGuiNextWindowDataFlags_HasSize ;
2018-01-03 11:28:16 +00:00
g . NextWindowData . SizeVal = size ;
g . NextWindowData . SizeCond = cond ? cond : ImGuiCond_Always ;
2014-12-10 19:22:30 +00:00
}
2018-01-03 11:31:56 +00:00
void ImGui : : SetNextWindowSizeConstraints ( const ImVec2 & size_min , const ImVec2 & size_max , ImGuiSizeCallback custom_callback , void * custom_callback_user_data )
2016-05-21 20:53:08 +00:00
{
ImGuiContext & g = * GImGui ;
2019-05-13 12:45:41 +00:00
g . NextWindowData . Flags | = ImGuiNextWindowDataFlags_HasSizeConstraint ;
2018-01-03 11:28:16 +00:00
g . NextWindowData . SizeConstraintRect = ImRect ( size_min , size_max ) ;
2018-01-03 11:31:56 +00:00
g . NextWindowData . SizeCallback = custom_callback ;
g . NextWindowData . SizeCallbackUserData = custom_callback_user_data ;
2016-05-21 20:53:08 +00:00
}
2019-06-03 13:35:55 +00:00
// Content size = inner scrollable rectangle, padded with WindowPadding.
// SetNextWindowContentSize(ImVec2(100,100) + ImGuiWindowFlags_AlwaysAutoResize will always allow submitting a 100x100 item.
2015-08-30 15:37:56 +00:00
void ImGui : : SetNextWindowContentSize ( const ImVec2 & size )
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2019-05-13 12:45:41 +00:00
g . NextWindowData . Flags | = ImGuiNextWindowDataFlags_HasContentSize ;
2019-06-03 13:35:55 +00:00
g . NextWindowData . ContentSizeVal = size ;
2015-08-30 15:37:56 +00:00
}
2017-08-11 05:36:28 +00:00
void ImGui : : SetNextWindowCollapsed ( bool collapsed , ImGuiCond cond )
2014-12-10 19:22:30 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2018-04-04 13:01:01 +00:00
IM_ASSERT ( cond = = 0 | | ImIsPowerOfTwo ( cond ) ) ; // Make sure the user doesn't attempt to combine multiple condition flags.
2019-05-13 12:45:41 +00:00
g . NextWindowData . Flags | = ImGuiNextWindowDataFlags_HasCollapsed ;
2018-01-03 11:28:16 +00:00
g . NextWindowData . CollapsedVal = collapsed ;
g . NextWindowData . CollapsedCond = cond ? cond : ImGuiCond_Always ;
2014-12-10 19:22:30 +00:00
}
2015-02-27 09:01:12 +00:00
void ImGui : : SetNextWindowFocus ( )
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2019-05-13 12:45:41 +00:00
g . NextWindowData . Flags | = ImGuiNextWindowDataFlags_HasFocus ;
2018-01-23 18:13:49 +00:00
}
void ImGui : : SetNextWindowBgAlpha ( float alpha )
{
ImGuiContext & g = * GImGui ;
2019-05-13 12:45:41 +00:00
g . NextWindowData . Flags | = ImGuiNextWindowDataFlags_HasBgAlpha ;
2018-01-23 18:13:49 +00:00
g . NextWindowData . BgAlphaVal = alpha ;
2015-02-27 09:01:12 +00:00
}
2019-04-24 15:04:20 +00:00
// FIXME: This is in window space (not screen space!). We should try to obsolete all those functions.
2014-11-10 01:29:01 +00:00
ImVec2 ImGui : : GetContentRegionMax ( )
2014-11-07 06:17:04 +00:00
{
2019-07-23 18:50:41 +00:00
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = g . CurrentWindow ;
2019-10-31 10:15:40 +00:00
ImVec2 mx = window - > ContentRegionRect . Max - window - > Pos ;
2019-04-16 09:58:17 +00:00
if ( window - > DC . CurrentColumns )
2019-06-10 19:43:05 +00:00
mx . x = window - > WorkRect . Max . x - window - > Pos . x ;
2015-02-10 21:07:26 +00:00
return mx ;
2014-11-07 06:17:04 +00:00
}
2019-04-18 12:10:01 +00:00
// [Internal] Absolute coordinate. Saner. This is not exposed until we finishing refactoring work rect features.
2019-05-28 13:54:55 +00:00
ImVec2 ImGui : : GetContentRegionMaxAbs ( )
2019-04-18 12:10:01 +00:00
{
2019-07-23 18:50:41 +00:00
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = g . CurrentWindow ;
2019-10-31 10:15:40 +00:00
ImVec2 mx = window - > ContentRegionRect . Max ;
2019-04-18 12:10:01 +00:00
if ( window - > DC . CurrentColumns )
2019-06-10 19:43:05 +00:00
mx . x = window - > WorkRect . Max . x ;
2019-04-18 12:10:01 +00:00
return mx ;
}
2015-08-07 22:41:22 +00:00
ImVec2 ImGui : : GetContentRegionAvail ( )
2015-08-05 16:43:12 +00:00
{
2019-04-18 12:10:01 +00:00
ImGuiWindow * window = GImGui - > CurrentWindow ;
2019-05-28 13:54:55 +00:00
return GetContentRegionMaxAbs ( ) - window - > DC . CursorPos ;
2015-08-05 16:43:12 +00:00
}
// In window space (not screen space!)
2014-11-10 01:29:01 +00:00
ImVec2 ImGui : : GetWindowContentRegionMin ( )
2014-08-10 20:58:11 +00:00
{
2019-06-10 19:43:05 +00:00
ImGuiWindow * window = GImGui - > CurrentWindow ;
2019-10-31 10:15:40 +00:00
return window - > ContentRegionRect . Min - window - > Pos ;
2014-08-10 20:58:11 +00:00
}
2014-11-10 01:29:01 +00:00
ImVec2 ImGui : : GetWindowContentRegionMax ( )
2014-08-10 20:58:11 +00:00
{
2019-06-10 19:43:05 +00:00
ImGuiWindow * window = GImGui - > CurrentWindow ;
2019-10-31 10:15:40 +00:00
return window - > ContentRegionRect . Max - window - > Pos ;
2014-08-10 20:58:11 +00:00
}
2015-08-30 15:37:56 +00:00
float ImGui : : GetWindowContentRegionWidth ( )
{
2019-06-10 19:43:05 +00:00
ImGuiWindow * window = GImGui - > CurrentWindow ;
2019-10-31 10:15:40 +00:00
return window - > ContentRegionRect . GetWidth ( ) ;
2015-08-30 15:37:56 +00:00
}
2014-11-10 01:29:01 +00:00
float ImGui : : GetTextLineHeight ( )
2014-08-10 20:58:11 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2015-03-29 18:45:03 +00:00
return g . FontSize ;
2014-08-10 20:58:11 +00:00
}
2015-02-08 13:37:20 +00:00
float ImGui : : GetTextLineHeightWithSpacing ( )
2014-08-10 20:58:11 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2015-03-29 18:45:03 +00:00
return g . FontSize + g . Style . ItemSpacing . y ;
2014-08-10 20:58:11 +00:00
}
2017-12-12 13:12:49 +00:00
float ImGui : : GetFrameHeight ( )
{
ImGuiContext & g = * GImGui ;
return g . FontSize + g . Style . FramePadding . y * 2.0f ;
}
2017-12-12 13:14:58 +00:00
float ImGui : : GetFrameHeightWithSpacing ( )
2015-05-29 08:00:34 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2015-05-29 08:00:34 +00:00
return g . FontSize + g . Style . FramePadding . y * 2.0f + g . Style . ItemSpacing . y ;
}
2014-11-10 01:29:01 +00:00
ImDrawList * ImGui : : GetWindowDrawList ( )
2014-08-10 20:58:11 +00:00
{
2014-08-19 11:09:13 +00:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
return window - > DrawList ;
2014-08-10 20:58:11 +00:00
}
2016-03-21 21:29:11 +00:00
ImFont * ImGui : : GetFont ( )
2014-10-25 10:00:24 +00:00
{
2016-03-21 21:29:11 +00:00
return GImGui - > Font ;
2014-10-25 10:00:24 +00:00
}
2016-03-21 21:29:11 +00:00
float ImGui : : GetFontSize ( )
2014-10-25 10:00:24 +00:00
{
2016-03-21 21:29:11 +00:00
return GImGui - > FontSize ;
2014-10-25 10:00:24 +00:00
}
2016-03-21 21:30:32 +00:00
ImVec2 ImGui : : GetFontTexUvWhitePixel ( )
{
2017-12-21 17:50:27 +00:00
return GImGui - > DrawListSharedData . TexUvWhitePixel ;
2016-03-21 21:30:32 +00:00
}
2014-11-10 01:29:01 +00:00
void ImGui : : SetWindowFontScale ( float scale )
2014-08-10 20:58:11 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2014-08-19 11:09:13 +00:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2014-09-24 13:03:42 +00:00
window - > FontWindowScale = scale ;
2017-12-22 19:19:48 +00:00
g . FontSize = g . DrawListSharedData . FontSize = window - > CalcFontSize ( ) ;
2014-08-10 20:58:11 +00:00
}
2015-07-02 17:26:35 +00:00
// User generally sees positions in window coordinates. Internally we store CursorPos in absolute screen coordinates because it is more convenient.
// Conversion happens as we pass the value to user, but it makes our naming convention confusing because GetCursorPos() == (DC.CursorPos - window.Pos). May want to rename 'DC.CursorPos'.
2014-11-10 01:29:01 +00:00
ImVec2 ImGui : : GetCursorPos ( )
2014-08-10 20:58:11 +00:00
{
2015-08-30 10:56:04 +00:00
ImGuiWindow * window = GetCurrentWindowRead ( ) ;
2015-08-30 15:37:56 +00:00
return window - > DC . CursorPos - window - > Pos + window - > Scroll ;
2014-08-10 20:58:11 +00:00
}
2015-02-08 13:37:20 +00:00
float ImGui : : GetCursorPosX ( )
{
2016-06-29 08:30:42 +00:00
ImGuiWindow * window = GetCurrentWindowRead ( ) ;
2015-08-30 15:37:56 +00:00
return window - > DC . CursorPos . x - window - > Pos . x + window - > Scroll . x ;
2015-02-08 13:37:20 +00:00
}
float ImGui : : GetCursorPosY ( )
{
2016-06-29 08:30:42 +00:00
ImGuiWindow * window = GetCurrentWindowRead ( ) ;
2015-08-30 15:37:56 +00:00
return window - > DC . CursorPos . y - window - > Pos . y + window - > Scroll . y ;
2015-02-08 13:37:20 +00:00
}
2015-08-13 04:46:39 +00:00
void ImGui : : SetCursorPos ( const ImVec2 & local_pos )
2014-08-10 20:58:11 +00:00
{
2014-08-19 11:09:13 +00:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2015-08-30 15:37:56 +00:00
window - > DC . CursorPos = window - > Pos - window - > Scroll + local_pos ;
2015-03-17 22:03:02 +00:00
window - > DC . CursorMaxPos = ImMax ( window - > DC . CursorMaxPos , window - > DC . CursorPos ) ;
2014-08-10 20:58:11 +00:00
}
2014-11-10 01:29:01 +00:00
void ImGui : : SetCursorPosX ( float x )
2014-08-29 12:36:31 +00:00
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
2015-08-30 15:37:56 +00:00
window - > DC . CursorPos . x = window - > Pos . x - window - > Scroll . x + x ;
2015-03-17 22:03:02 +00:00
window - > DC . CursorMaxPos . x = ImMax ( window - > DC . CursorMaxPos . x , window - > DC . CursorPos . x ) ;
2014-08-29 12:36:31 +00:00
}
2014-11-10 01:29:01 +00:00
void ImGui : : SetCursorPosY ( float y )
2014-08-29 12:36:31 +00:00
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
2015-08-30 15:37:56 +00:00
window - > DC . CursorPos . y = window - > Pos . y - window - > Scroll . y + y ;
2015-03-17 22:03:02 +00:00
window - > DC . CursorMaxPos . y = ImMax ( window - > DC . CursorMaxPos . y , window - > DC . CursorPos . y ) ;
2014-08-29 12:36:31 +00:00
}
2015-07-02 20:46:49 +00:00
ImVec2 ImGui : : GetCursorStartPos ( )
{
2015-08-30 10:56:04 +00:00
ImGuiWindow * window = GetCurrentWindowRead ( ) ;
2015-07-02 20:46:49 +00:00
return window - > DC . CursorStartPos - window - > Pos ;
}
2014-11-10 01:29:01 +00:00
ImVec2 ImGui : : GetCursorScreenPos ( )
2014-08-19 11:39:30 +00:00
{
2015-08-30 10:56:04 +00:00
ImGuiWindow * window = GetCurrentWindowRead ( ) ;
2014-08-19 11:45:34 +00:00
return window - > DC . CursorPos ;
2014-08-10 20:58:11 +00:00
}
2018-12-19 10:12:02 +00:00
void ImGui : : SetCursorScreenPos ( const ImVec2 & pos )
2015-01-15 14:41:22 +00:00
{
ImGuiWindow * window = GetCurrentWindow ( ) ;
2018-12-19 10:12:02 +00:00
window - > DC . CursorPos = pos ;
2016-06-29 08:25:47 +00:00
window - > DC . CursorMaxPos = ImMax ( window - > DC . CursorMaxPos , window - > DC . CursorPos ) ;
2015-01-15 14:41:22 +00:00
}
2017-10-06 04:25:20 +00:00
void ImGui : : ActivateItem ( ImGuiID id )
{
ImGuiContext & g = * GImGui ;
g . NavNextActivateId = id ;
}
2014-11-10 01:29:01 +00:00
void ImGui : : SetKeyboardFocusHere ( int offset )
2014-09-30 10:57:37 +00:00
{
2017-10-05 16:53:07 +00:00
IM_ASSERT ( offset > = - 1 ) ; // -1 is allowed but not below
2019-03-05 18:37:20 +00:00
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = g . CurrentWindow ;
g . FocusRequestNextWindow = window ;
g . FocusRequestNextCounterAll = window - > DC . FocusCounterAll + 1 + offset ;
g . FocusRequestNextCounterTab = INT_MAX ;
2014-09-30 10:57:37 +00:00
}
2017-10-06 22:50:32 +00:00
void ImGui : : SetItemDefaultFocus ( )
{
ImGuiContext & g = * GImGui ;
2017-12-11 15:28:47 +00:00
ImGuiWindow * window = g . CurrentWindow ;
if ( ! window - > Appearing )
return ;
2018-02-08 22:11:51 +00:00
if ( g . NavWindow = = window - > RootWindowForNav & & ( g . NavInitRequest | | g . NavInitResultId ! = 0 ) & & g . NavLayer = = g . NavWindow - > DC . NavLayerCurrent )
2017-10-06 22:50:32 +00:00
{
2017-10-06 22:54:29 +00:00
g . NavInitRequest = false ;
g . NavInitResultId = g . NavWindow - > DC . LastItemId ;
g . NavInitResultRectRel = ImRect ( g . NavWindow - > DC . LastItemRect . Min - g . NavWindow - > Pos , g . NavWindow - > DC . LastItemRect . Max - g . NavWindow - > Pos ) ;
2017-10-06 22:50:32 +00:00
NavUpdateAnyRequestFlag ( ) ;
if ( ! IsItemVisible ( ) )
2018-09-26 19:30:37 +00:00
SetScrollHereY ( ) ;
2017-10-06 22:50:32 +00:00
}
}
2014-12-29 18:17:54 +00:00
void ImGui : : SetStateStorage ( ImGuiStorage * tree )
2014-08-10 20:58:11 +00:00
{
2019-01-21 14:39:43 +00:00
ImGuiWindow * window = GImGui - > CurrentWindow ;
2014-08-19 11:09:13 +00:00
window - > DC . StateStorage = tree ? tree : & window - > StateStorage ;
2014-08-10 20:58:11 +00:00
}
2014-12-29 18:17:54 +00:00
ImGuiStorage * ImGui : : GetStateStorage ( )
2014-08-12 18:57:46 +00:00
{
2019-01-21 14:39:43 +00:00
ImGuiWindow * window = GImGui - > CurrentWindow ;
2014-08-19 11:09:13 +00:00
return window - > DC . StateStorage ;
2014-08-12 18:57:46 +00:00
}
2014-11-10 01:29:01 +00:00
void ImGui : : PushID ( const char * str_id )
2014-08-10 20:58:11 +00:00
{
2019-01-21 14:39:43 +00:00
ImGuiWindow * window = GImGui - > CurrentWindow ;
2018-07-31 15:26:42 +00:00
window - > IDStack . push_back ( window - > GetIDNoKeepAlive ( str_id ) ) ;
2014-08-10 20:58:11 +00:00
}
2015-04-13 13:45:27 +00:00
void ImGui : : PushID ( const char * str_id_begin , const char * str_id_end )
{
2019-01-21 14:39:43 +00:00
ImGuiWindow * window = GImGui - > CurrentWindow ;
2018-07-31 15:26:42 +00:00
window - > IDStack . push_back ( window - > GetIDNoKeepAlive ( str_id_begin , str_id_end ) ) ;
2015-04-13 13:45:27 +00:00
}
2014-11-10 01:29:01 +00:00
void ImGui : : PushID ( const void * ptr_id )
2014-08-10 20:58:11 +00:00
{
2019-01-21 14:39:43 +00:00
ImGuiWindow * window = GImGui - > CurrentWindow ;
2018-07-31 15:26:42 +00:00
window - > IDStack . push_back ( window - > GetIDNoKeepAlive ( ptr_id ) ) ;
2014-08-10 20:58:11 +00:00
}
2015-07-08 23:08:37 +00:00
void ImGui : : PushID ( int int_id )
2014-08-10 20:58:11 +00:00
{
2019-01-21 14:39:43 +00:00
ImGuiWindow * window = GImGui - > CurrentWindow ;
2019-06-06 14:36:26 +00:00
window - > IDStack . push_back ( window - > GetIDNoKeepAlive ( int_id ) ) ;
2014-08-10 20:58:11 +00:00
}
2019-04-25 13:21:22 +00:00
// 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 ) ;
}
2014-11-10 01:29:01 +00:00
void ImGui : : PopID ( )
2014-08-10 20:58:11 +00:00
{
2019-01-21 14:39:43 +00:00
ImGuiWindow * window = GImGui - > CurrentWindow ;
2014-08-19 11:09:13 +00:00
window - > IDStack . pop_back ( ) ;
2014-08-10 20:58:11 +00:00
}
2014-12-08 17:14:54 +00:00
ImGuiID ImGui : : GetID ( const char * str_id )
{
2019-01-21 14:39:43 +00:00
ImGuiWindow * window = GImGui - > CurrentWindow ;
return window - > GetID ( str_id ) ;
2014-12-08 17:14:54 +00:00
}
2015-04-13 13:45:27 +00:00
ImGuiID ImGui : : GetID ( const char * str_id_begin , const char * str_id_end )
{
2019-01-21 14:39:43 +00:00
ImGuiWindow * window = GImGui - > CurrentWindow ;
return window - > GetID ( str_id_begin , str_id_end ) ;
2015-04-13 13:45:27 +00:00
}
2014-12-08 17:14:54 +00:00
ImGuiID ImGui : : GetID ( const void * ptr_id )
{
2019-01-21 14:39:43 +00:00
ImGuiWindow * window = GImGui - > CurrentWindow ;
return window - > GetID ( ptr_id ) ;
2014-12-08 17:14:54 +00:00
}
2015-05-31 08:12:07 +00:00
bool ImGui : : IsRectVisible ( const ImVec2 & size )
2014-08-10 20:58:11 +00:00
{
2019-02-19 22:39:44 +00:00
ImGuiWindow * window = GImGui - > CurrentWindow ;
2015-08-06 14:23:05 +00:00
return window - > ClipRect . Overlaps ( ImRect ( window - > DC . CursorPos , window - > DC . CursorPos + size ) ) ;
2014-08-10 20:58:11 +00:00
}
2016-08-06 07:40:26 +00:00
bool ImGui : : IsRectVisible ( const ImVec2 & rect_min , const ImVec2 & rect_max )
2016-08-05 09:47:16 +00:00
{
2019-02-19 22:39:44 +00:00
ImGuiWindow * window = GImGui - > CurrentWindow ;
2016-08-06 07:40:26 +00:00
return window - > ClipRect . Overlaps ( ImRect ( rect_min , rect_max ) ) ;
2016-08-05 09:47:16 +00:00
}
2016-04-25 06:45:32 +00:00
// Lock horizontal starting position + capture group bounding box into one "item" (so you can use IsItemHovered() or layout primitives such as SameLine() on whole group, etc.)
2015-03-17 23:28:57 +00:00
void ImGui : : BeginGroup ( )
{
2018-06-12 15:24:46 +00:00
ImGuiContext & g = * GImGui ;
2015-03-17 23:28:57 +00:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2015-07-07 18:39:08 +00:00
window - > DC . GroupStack . resize ( window - > DC . GroupStack . Size + 1 ) ;
2015-03-17 23:28:57 +00:00
ImGuiGroupData & group_data = window - > DC . GroupStack . back ( ) ;
group_data . BackupCursorPos = window - > DC . CursorPos ;
group_data . BackupCursorMaxPos = window - > DC . CursorMaxPos ;
2018-08-28 17:03:08 +00:00
group_data . BackupIndent = window - > DC . Indent ;
group_data . BackupGroupOffset = window - > DC . GroupOffset ;
2019-05-13 16:15:39 +00:00
group_data . BackupCurrLineSize = window - > DC . CurrLineSize ;
group_data . BackupCurrLineTextBaseOffset = window - > DC . CurrLineTextBaseOffset ;
2018-06-12 15:24:46 +00:00
group_data . BackupActiveIdIsAlive = g . ActiveIdIsAlive ;
2018-06-12 16:44:33 +00:00
group_data . BackupActiveIdPreviousFrameIsAlive = g . ActiveIdPreviousFrameIsAlive ;
2019-05-13 09:25:38 +00:00
group_data . EmitItem = true ;
2015-03-17 23:28:57 +00:00
2018-08-28 17:03:08 +00:00
window - > DC . GroupOffset . x = window - > DC . CursorPos . x - window - > Pos . x - window - > DC . ColumnsOffset . x ;
window - > DC . Indent = window - > DC . GroupOffset ;
2015-03-17 23:28:57 +00:00
window - > DC . CursorMaxPos = window - > DC . CursorPos ;
2019-05-13 16:15:39 +00:00
window - > DC . CurrLineSize = ImVec2 ( 0.0f , 0.0f ) ;
2019-02-23 15:22:55 +00:00
if ( g . LogEnabled )
g . LogLinePosY = - FLT_MAX ; // To enforce Log carriage return
2015-03-17 23:28:57 +00:00
}
void ImGui : : EndGroup ( )
{
2016-09-25 12:18:10 +00:00
ImGuiContext & g = * GImGui ;
2015-03-17 23:28:57 +00:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
2019-02-23 15:22:55 +00:00
IM_ASSERT ( ! window - > DC . GroupStack . empty ( ) ) ; // Mismatched BeginGroup()/EndGroup() calls
2015-03-17 23:28:57 +00:00
ImGuiGroupData & group_data = window - > DC . GroupStack . back ( ) ;
2019-05-13 09:25:38 +00:00
ImRect group_bb ( group_data . BackupCursorPos , ImMax ( window - > DC . CursorMaxPos , group_data . BackupCursorPos ) ) ;
2015-03-17 23:28:57 +00:00
window - > DC . CursorPos = group_data . BackupCursorPos ;
window - > DC . CursorMaxPos = ImMax ( group_data . BackupCursorMaxPos , window - > DC . CursorMaxPos ) ;
2018-08-28 17:03:08 +00:00
window - > DC . Indent = group_data . BackupIndent ;
window - > DC . GroupOffset = group_data . BackupGroupOffset ;
2019-05-13 16:15:39 +00:00
window - > DC . CurrLineSize = group_data . BackupCurrLineSize ;
window - > DC . CurrLineTextBaseOffset = group_data . BackupCurrLineTextBaseOffset ;
2019-02-23 15:22:55 +00:00
if ( g . LogEnabled )
g . LogLinePosY = - FLT_MAX ; // To enforce Log carriage return
2015-03-17 23:28:57 +00:00
2019-05-13 09:25:38 +00:00
if ( ! group_data . EmitItem )
2015-05-25 22:08:22 +00:00
{
2019-05-13 09:25:38 +00:00
window - > DC . GroupStack . pop_back ( ) ;
return ;
2015-05-25 22:08:22 +00:00
}
2015-03-17 23:28:57 +00:00
2019-05-13 16:15:39 +00:00
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.
2019-10-06 21:17:36 +00:00
ItemSize ( group_bb . GetSize ( ) ) ;
2019-05-13 09:25:38 +00:00
ItemAdd ( group_bb , 0 ) ;
2018-06-12 16:44:33 +00:00
// 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.
2018-08-23 11:21:01 +00:00
// 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.
2019-05-12 19:35:05 +00:00
// 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 )
2016-09-25 12:18:10 +00:00
window - > DC . LastItemId = g . ActiveId ;
2019-05-12 19:35:05 +00:00
else if ( group_contains_prev_active_id )
2018-06-12 16:44:33 +00:00
window - > DC . LastItemId = g . ActiveIdPreviousFrame ;
2017-09-27 15:21:50 +00:00
window - > DC . LastItemRect = group_bb ;
2016-09-25 12:18:10 +00:00
2019-05-13 17:05:41 +00:00
// 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 ;
2015-03-17 23:28:57 +00:00
window - > DC . GroupStack . pop_back ( ) ;
2017-07-22 08:58:28 +00:00
//window->DrawList->AddRect(group_bb.Min, group_bb.Max, IM_COL32(255,0,255,255)); // [Debug]
2015-03-17 23:28:57 +00:00
}
2014-08-10 20:58:11 +00:00
// Gets back to previous line and continue with horizontal layout
2019-04-17 10:26:51 +00:00
// 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 )
2014-08-10 20:58:11 +00:00
{
2014-08-19 11:09:13 +00:00
ImGuiWindow * window = GetCurrentWindow ( ) ;
if ( window - > SkipItems )
return ;
2015-08-24 11:50:18 +00:00
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2019-04-17 10:26:51 +00:00
if ( offset_from_start_x ! = 0.0f )
2014-08-19 11:09:13 +00:00
{
2015-07-11 01:36:34 +00:00
if ( spacing_w < 0.0f ) spacing_w = 0.0f ;
2019-04-17 10:26:51 +00:00
window - > DC . CursorPos . x = window - > Pos . x - window - > Scroll . x + offset_from_start_x + spacing_w + window - > DC . GroupOffset . x + window - > DC . ColumnsOffset . x ;
2016-03-21 21:11:43 +00:00
window - > DC . CursorPos . y = window - > DC . CursorPosPrevLine . y ;
2014-08-19 11:09:13 +00:00
}
else
{
2015-07-11 01:36:34 +00:00
if ( spacing_w < 0.0f ) spacing_w = g . Style . ItemSpacing . x ;
2016-03-21 21:11:43 +00:00
window - > DC . CursorPos . x = window - > DC . CursorPosPrevLine . x + spacing_w ;
window - > DC . CursorPos . y = window - > DC . CursorPosPrevLine . y ;
2014-08-19 11:09:13 +00:00
}
2019-05-13 16:15:39 +00:00
window - > DC . CurrLineSize = window - > DC . PrevLineSize ;
window - > DC . CurrLineTextBaseOffset = window - > DC . PrevLineTextBaseOffset ;
2014-08-10 20:58:11 +00:00
}
2018-08-30 13:38:55 +00:00
void ImGui : : Indent ( float indent_w )
{
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = GetCurrentWindow ( ) ;
window - > DC . Indent . x + = ( indent_w ! = 0.0f ) ? indent_w : g . Style . IndentSpacing ;
window - > DC . CursorPos . x = window - > Pos . x + window - > DC . Indent . x + window - > DC . ColumnsOffset . x ;
}
void ImGui : : Unindent ( float indent_w )
{
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = GetCurrentWindow ( ) ;
window - > DC . Indent . x - = ( indent_w ! = 0.0f ) ? indent_w : g . Style . IndentSpacing ;
window - > DC . CursorPos . x = window - > Pos . x + window - > DC . Indent . x + window - > DC . ColumnsOffset . x ;
}
2019-07-31 03:04:02 +00:00
2019-11-13 20:35:42 +00:00
//-----------------------------------------------------------------------------
// [SECTION] ERROR CHECKING
//-----------------------------------------------------------------------------
static void ImGui : : ErrorCheckEndFrame ( )
{
// Report when there is a mismatch of Begin/BeginChild vs End/EndChild calls. Important: Remember that the Begin/BeginChild API requires you
// to always call End/EndChild even if Begin/BeginChild returns false! (this is unfortunately inconsistent with most other Begin* API).
ImGuiContext & g = * GImGui ;
if ( g . CurrentWindowStack . Size ! = 1 )
{
if ( g . CurrentWindowStack . Size > 1 )
{
2019-11-15 15:44:16 +00:00
IM_ASSERT_USER_ERROR ( g . CurrentWindowStack . Size = = 1 , " Mismatched Begin/BeginChild vs End/EndChild calls: did you forget to call End/EndChild? " ) ;
2019-11-13 20:58:18 +00:00
while ( g . CurrentWindowStack . Size > 1 )
2019-11-13 20:35:42 +00:00
End ( ) ;
}
else
{
2019-11-15 15:44:16 +00:00
IM_ASSERT_USER_ERROR ( g . CurrentWindowStack . Size = = 1 , " Mismatched Begin/BeginChild vs End/EndChild calls: did you call End/EndChild too much? " ) ;
2019-11-13 20:35:42 +00:00
}
}
}
// Save and compare stack sizes on Begin()/End() to detect usage errors
// Begin() calls this with write=true
// End() calls this with write=false
static void ImGui : : ErrorCheckBeginEndCompareStacksSize ( ImGuiWindow * window , bool write )
{
ImGuiContext & g = * GImGui ;
short * p = & window - > DC . StackSizesBackup [ 0 ] ;
// Window stacks
// NOT checking: DC.ItemWidth, DC.AllowKeyboardFocus, DC.ButtonRepeat, DC.TextWrapPos (per window) to allow user to conveniently push once and not pop (they are cleared on Begin)
{ int n = window - > IDStack . Size ; if ( write ) * p = ( short ) n ; else IM_ASSERT ( * p = = n & & " PushID/PopID or TreeNode/TreePop Mismatch! " ) ; p + + ; } // Too few or too many PopID()/TreePop()
{ int n = window - > DC . GroupStack . Size ; if ( write ) * p = ( short ) n ; else IM_ASSERT ( * p = = n & & " BeginGroup/EndGroup Mismatch! " ) ; p + + ; } // Too few or too many EndGroup()
// Global stacks
// For color, style and font stacks there is an incentive to use Push/Begin/Pop/.../End patterns, so we relax our checks a little to allow them.
{ int n = g . BeginPopupStack . Size ; if ( write ) * p = ( short ) n ; else IM_ASSERT ( * p = = n & & " BeginMenu/EndMenu or BeginPopup/EndPopup Mismatch! " ) ; p + + ; } // Too few or too many EndMenu()/EndPopup()
{ int n = g . ColorModifiers . Size ; if ( write ) * p = ( short ) n ; else IM_ASSERT ( * p > = n & & " PushStyleColor/PopStyleColor Mismatch! " ) ; p + + ; } // Too few or too many PopStyleColor()
{ int n = g . StyleModifiers . Size ; if ( write ) * p = ( short ) n ; else IM_ASSERT ( * p > = n & & " PushStyleVar/PopStyleVar Mismatch! " ) ; p + + ; } // Too few or too many PopStyleVar()
{ int n = g . FontStack . Size ; if ( write ) * p = ( short ) n ; else IM_ASSERT ( * p > = n & & " PushFont/PopFont Mismatch! " ) ; p + + ; } // Too few or too many PopFont()
IM_ASSERT ( p = = window - > DC . StackSizesBackup + IM_ARRAYSIZE ( window - > DC . StackSizesBackup ) ) ;
}
2019-07-31 03:04:02 +00:00
//-----------------------------------------------------------------------------
// [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 ;
2019-07-31 17:26:10 +00:00
scroll . x = target_x - cr_x * ( window - > SizeFull . x - window - > ScrollbarSizes . x ) ;
2019-07-31 03:04:02 +00:00
}
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.
2019-07-31 17:26:10 +00:00
float decoration_up_height = window - > TitleBarHeight ( ) + window - > MenuBarHeight ( ) ;
2019-07-31 03:04:02 +00:00
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 ;
2019-07-31 17:26:10 +00:00
scroll . y = target_y - cr_y * ( window - > SizeFull . y - window - > ScrollbarSizes . y - decoration_up_height ) ;
2019-07-31 03:04:02 +00:00
}
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
2019-08-01 01:37:55 +00:00
ImVec2 ImGui : : ScrollToBringRectIntoView ( ImGuiWindow * window , const ImRect & item_rect )
2019-07-31 03:04:02 +00:00
{
2019-08-01 01:37:55 +00:00
ImGuiContext & g = * GImGui ;
2019-07-31 03:04:02 +00:00
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]
2019-08-01 01:37:55 +00:00
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 ;
2019-07-31 03:04:02 +00:00
}
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 ;
}
2019-07-31 17:26:10 +00:00
void ImGui : : SetScrollFromPosX ( ImGuiWindow * window , float local_x , float center_x_ratio )
2019-07-31 03:04:02 +00:00
{
// 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 ) ;
2019-10-17 09:36:26 +00:00
window - > ScrollTarget . x = IM_FLOOR ( local_x + window - > Scroll . x ) ;
2019-07-31 03:04:02 +00:00
window - > ScrollTargetCenterRatio . x = center_x_ratio ;
}
2019-07-31 17:26:10 +00:00
void ImGui : : SetScrollFromPosY ( ImGuiWindow * window , float local_y , float center_y_ratio )
2019-07-31 03:04:02 +00:00
{
// 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 ) ;
2019-07-31 17:26:10 +00:00
const float decoration_up_height = window - > TitleBarHeight ( ) + window - > MenuBarHeight ( ) ;
local_y - = decoration_up_height ;
2019-10-17 09:36:26 +00:00
window - > ScrollTarget . y = IM_FLOOR ( local_y + window - > Scroll . y ) ;
2019-07-31 03:04:02 +00:00
window - > ScrollTargetCenterRatio . y = center_y_ratio ;
}
2019-07-31 17:26:10 +00:00
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 ) ;
}
2019-07-31 03:04:02 +00:00
// 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 ) ;
}
2018-08-30 19:03:51 +00:00
//-----------------------------------------------------------------------------
2018-09-06 09:35:13 +00:00
// [SECTION] TOOLTIPS
2018-08-30 19:03:51 +00:00
//-----------------------------------------------------------------------------
void ImGui : : BeginTooltip ( )
{
ImGuiContext & g = * GImGui ;
if ( g . DragDropWithinSourceOrTarget )
{
// The default tooltip position is a little offset to give space to see the context menu (it's also clamped within the current viewport/monitor)
// In the context of a dragging tooltip we try to reduce that offset and we enforce following the cursor.
// Whatever we do we want to call SetNextWindowPos() to enforce a tooltip position and disable clipping the tooltip without our display area, like regular tooltip do.
//ImVec2 tooltip_pos = g.IO.MousePos - g.ActiveIdClickOffset - g.Style.WindowPadding;
ImVec2 tooltip_pos = g . IO . MousePos + ImVec2 ( 16 * g . Style . MouseCursorScale , 8 * g . Style . MouseCursorScale ) ;
SetNextWindowPos ( tooltip_pos ) ;
SetNextWindowBgAlpha ( g . Style . Colors [ ImGuiCol_PopupBg ] . w * 0.60f ) ;
//PushStyleVar(ImGuiStyleVar_Alpha, g.Style.Alpha * 0.60f); // This would be nice but e.g ColorButton with checkboard has issue with transparent colors :(
BeginTooltipEx ( 0 , true ) ;
}
else
{
BeginTooltipEx ( 0 , false ) ;
}
}
// Not exposed publicly as BeginTooltip() because bool parameters are evil. Let's see if other needs arise first.
void ImGui : : BeginTooltipEx ( ImGuiWindowFlags extra_flags , bool override_previous_tooltip )
{
ImGuiContext & g = * GImGui ;
char window_name [ 16 ] ;
ImFormatString ( window_name , IM_ARRAYSIZE ( window_name ) , " ##Tooltip_%02d " , g . TooltipOverrideCount ) ;
if ( override_previous_tooltip )
if ( ImGuiWindow * window = FindWindowByName ( window_name ) )
if ( window - > Active )
{
// 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 ;
2019-03-28 14:41:49 +00:00
window - > HiddenFramesCanSkipItems = 1 ;
2018-08-30 19:03:51 +00:00
ImFormatString ( window_name , IM_ARRAYSIZE ( window_name ) , " ##Tooltip_%02d " , + + g . TooltipOverrideCount ) ;
}
2018-10-15 16:23:18 +00:00
ImGuiWindowFlags flags = ImGuiWindowFlags_Tooltip | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize ;
2018-08-30 19:03:51 +00:00
Begin ( window_name , NULL , flags | extra_flags ) ;
}
void ImGui : : EndTooltip ( )
{
IM_ASSERT ( GetCurrentWindowRead ( ) - > Flags & ImGuiWindowFlags_Tooltip ) ; // Mismatched BeginTooltip()/EndTooltip() calls
End ( ) ;
}
void ImGui : : SetTooltipV ( const char * fmt , va_list args )
{
ImGuiContext & g = * GImGui ;
if ( g . DragDropWithinSourceOrTarget )
BeginTooltip ( ) ;
else
BeginTooltipEx ( 0 , true ) ;
TextV ( fmt , args ) ;
EndTooltip ( ) ;
}
void ImGui : : SetTooltip ( const char * fmt , . . . )
{
va_list args ;
va_start ( args , fmt ) ;
SetTooltipV ( fmt , args ) ;
va_end ( args ) ;
}
2018-08-30 18:58:04 +00:00
//-----------------------------------------------------------------------------
2018-09-06 09:35:13 +00:00
// [SECTION] POPUPS
2018-08-30 18:58:04 +00:00
//-----------------------------------------------------------------------------
bool ImGui : : IsPopupOpen ( ImGuiID id )
{
ImGuiContext & g = * GImGui ;
2018-12-14 17:44:17 +00:00
return g . OpenPopupStack . Size > g . BeginPopupStack . Size & & g . OpenPopupStack [ g . BeginPopupStack . Size ] . PopupId = = id ;
2018-08-30 18:58:04 +00:00
}
bool ImGui : : IsPopupOpen ( const char * str_id )
{
ImGuiContext & g = * GImGui ;
2018-12-14 17:44:17 +00:00
return g . OpenPopupStack . Size > g . BeginPopupStack . Size & & g . OpenPopupStack [ g . BeginPopupStack . Size ] . PopupId = = g . CurrentWindow - > GetID ( str_id ) ;
2018-08-30 18:58:04 +00:00
}
2019-06-19 16:14:24 +00:00
ImGuiWindow * ImGui : : GetTopMostPopupModal ( )
2018-08-30 18:58:04 +00:00
{
ImGuiContext & g = * GImGui ;
for ( int n = g . OpenPopupStack . Size - 1 ; n > = 0 ; n - - )
if ( ImGuiWindow * popup = g . OpenPopupStack . Data [ n ] . Window )
if ( popup - > Flags & ImGuiWindowFlags_Modal )
return popup ;
return NULL ;
}
void ImGui : : OpenPopup ( const char * str_id )
{
ImGuiContext & g = * GImGui ;
OpenPopupEx ( g . CurrentWindow - > GetID ( str_id ) ) ;
}
// Mark popup as open (toggle toward open state).
// Popups are closed when user click outside, or activate a pressable item, or CloseCurrentPopup() is called within a BeginPopup()/EndPopup() block.
// Popup identifiers are relative to the current ID-stack (so OpenPopup and BeginPopup needs to be at the same level).
// One open popup per level of the popup hierarchy (NB: when assigning we reset the Window member of ImGuiPopupRef to NULL)
void ImGui : : OpenPopupEx ( ImGuiID id )
{
ImGuiContext & g = * GImGui ;
ImGuiWindow * parent_window = g . CurrentWindow ;
2018-12-14 17:44:17 +00:00
int current_stack_size = g . BeginPopupStack . Size ;
2019-04-28 15:05:23 +00:00
ImGuiPopupData popup_ref ; // Tagged as new ref as Window will be set back to NULL if we write this into OpenPopupStack.
2018-08-30 18:58:04 +00:00
popup_ref . PopupId = id ;
popup_ref . Window = NULL ;
2019-04-28 19:52:12 +00:00
popup_ref . SourceWindow = g . NavWindow ;
2018-08-30 18:58:04 +00:00
popup_ref . OpenFrameCount = g . FrameCount ;
popup_ref . OpenParentId = parent_window - > IDStack . back ( ) ;
popup_ref . OpenPopupPos = NavCalcPreferredRefPos ( ) ;
2018-11-15 12:53:53 +00:00
popup_ref . OpenMousePos = IsMousePosValid ( & g . IO . MousePos ) ? g . IO . MousePos : popup_ref . OpenPopupPos ;
2018-08-30 18:58:04 +00:00
2019-01-04 14:27:52 +00:00
//IMGUI_DEBUG_LOG("OpenPopupEx(0x%08X)\n", g.FrameCount, id);
2018-08-30 18:58:04 +00:00
if ( g . OpenPopupStack . Size < current_stack_size + 1 )
{
g . OpenPopupStack . push_back ( popup_ref ) ;
}
else
{
// Gently handle the user mistakenly calling OpenPopup() every frame. It is a programming mistake! However, if we were to run the regular code path, the ui
// would become completely unusable because the popup will always be in hidden-while-calculating-size state _while_ claiming focus. Which would be a very confusing
// situation for the programmer. Instead, we silently allow the popup to proceed, it will keep reappearing and the programming error will be more obvious to understand.
if ( g . OpenPopupStack [ current_stack_size ] . PopupId = = id & & g . OpenPopupStack [ current_stack_size ] . OpenFrameCount = = g . FrameCount - 1 )
{
g . OpenPopupStack [ current_stack_size ] . OpenFrameCount = popup_ref . OpenFrameCount ;
}
else
{
// Close child popups if any, then flag popup for open/reopen
g . OpenPopupStack . resize ( current_stack_size + 1 ) ;
g . OpenPopupStack [ current_stack_size ] = popup_ref ;
}
// When reopening a popup we first refocus its parent, otherwise if its parent is itself a popup it would get closed by ClosePopupsOverWindow().
// This is equivalent to what ClosePopupToLevel() does.
//if (g.OpenPopupStack[current_stack_size].PopupId == id)
// FocusWindow(parent_window);
}
}
2019-04-28 20:21:23 +00:00
void ImGui : : ClosePopupsOverWindow ( ImGuiWindow * ref_window , bool restore_focus_to_window_under_popup )
2018-08-30 18:58:04 +00:00
{
ImGuiContext & g = * GImGui ;
if ( g . OpenPopupStack . empty ( ) )
return ;
// When popups are stacked, clicking on a lower level popups puts focus back to it and close popups above it.
// Don't close our own child popup windows.
2018-12-14 15:24:59 +00:00
int popup_count_to_keep = 0 ;
2018-08-30 18:58:04 +00:00
if ( ref_window )
{
2018-12-14 15:24:59 +00:00
// 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 + + )
2018-08-30 18:58:04 +00:00
{
2019-04-28 15:05:23 +00:00
ImGuiPopupData & popup = g . OpenPopupStack [ popup_count_to_keep ] ;
2018-08-30 18:58:04 +00:00
if ( ! popup . Window )
continue ;
IM_ASSERT ( ( popup . Window - > Flags & ImGuiWindowFlags_Popup ) ! = 0 ) ;
if ( popup . Window - > Flags & ImGuiWindowFlags_ChildWindow )
continue ;
2019-04-28 20:21:23 +00:00
// 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 + + )
2019-04-28 21:49:57 +00:00
if ( ImGuiWindow * popup_window = g . OpenPopupStack [ m ] . Window )
if ( popup_window - > RootWindow = = ref_window - > RootWindow )
popup_or_descendent_is_ref_window = true ;
2019-04-28 20:21:23 +00:00
if ( ! popup_or_descendent_is_ref_window )
2018-08-30 18:58:04 +00:00
break ;
}
}
2018-12-14 15:24:59 +00:00
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);
2019-04-28 20:21:23 +00:00
ClosePopupToLevel ( popup_count_to_keep , restore_focus_to_window_under_popup ) ;
2018-12-14 15:24:59 +00:00
}
2018-08-30 18:58:04 +00:00
}
2019-04-28 20:21:23 +00:00
void ImGui : : ClosePopupToLevel ( int remaining , bool restore_focus_to_window_under_popup )
2018-08-30 18:58:04 +00:00
{
ImGuiContext & g = * GImGui ;
2019-04-28 19:52:12 +00:00
IM_ASSERT ( remaining > = 0 & & remaining < g . OpenPopupStack . Size ) ;
ImGuiWindow * focus_window = g . OpenPopupStack [ remaining ] . SourceWindow ;
ImGuiWindow * popup_window = g . OpenPopupStack [ remaining ] . Window ;
2018-08-30 18:58:04 +00:00
g . OpenPopupStack . resize ( remaining ) ;
2018-12-18 13:58:35 +00:00
2019-04-28 20:21:23 +00:00
if ( restore_focus_to_window_under_popup )
2018-12-18 13:58:35 +00:00
{
2019-04-28 19:52:12 +00:00
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 ) ;
}
2018-12-18 13:58:35 +00:00
}
2018-08-30 18:58:04 +00:00
}
// Close the popup we have begin-ed into.
void ImGui : : CloseCurrentPopup ( )
{
ImGuiContext & g = * GImGui ;
2018-12-14 17:44:17 +00:00
int popup_idx = g . BeginPopupStack . Size - 1 ;
if ( popup_idx < 0 | | popup_idx > = g . OpenPopupStack . Size | | g . BeginPopupStack [ popup_idx ] . PopupId ! = g . OpenPopupStack [ popup_idx ] . PopupId )
2018-08-30 18:58:04 +00:00
return ;
2019-01-27 22:54:17 +00:00
// Closing a menu closes its top-most parent popup (unless a modal)
while ( popup_idx > 0 )
{
ImGuiWindow * popup_window = g . OpenPopupStack [ popup_idx ] . Window ;
ImGuiWindow * parent_popup_window = g . OpenPopupStack [ popup_idx - 1 ] . Window ;
bool close_parent = false ;
if ( popup_window & & ( popup_window - > Flags & ImGuiWindowFlags_ChildMenu ) )
if ( parent_popup_window = = NULL | | ! ( parent_popup_window - > Flags & ImGuiWindowFlags_Modal ) )
close_parent = true ;
if ( ! close_parent )
break ;
2018-08-30 18:58:04 +00:00
popup_idx - - ;
2019-01-27 22:54:17 +00:00
}
//IMGUI_DEBUG_LOG("CloseCurrentPopup %d -> %d\n", g.BeginPopupStack.Size - 1, popup_idx);
2018-12-18 13:58:35 +00:00
ClosePopupToLevel ( popup_idx , true ) ;
2018-12-18 13:21:10 +00:00
// A common pattern is to close a popup when selecting a menu item/selectable that will open another window.
// To improve this usage pattern, we avoid nav highlight for a single frame in the parent window.
// Similarly, we could avoid mouse hover highlight in this window but it is less visually problematic.
if ( ImGuiWindow * window = g . NavWindow )
window - > DC . NavHideHighlightOneFrame = true ;
2018-08-30 18:58:04 +00:00
}
2018-08-30 18:59:24 +00:00
bool ImGui : : BeginPopupEx ( ImGuiID id , ImGuiWindowFlags extra_flags )
{
ImGuiContext & g = * GImGui ;
if ( ! IsPopupOpen ( id ) )
{
2019-05-13 12:45:41 +00:00
g . NextWindowData . ClearFlags ( ) ; // We behave like Begin() and need to consume those values
2018-08-30 18:59:24 +00:00
return false ;
}
char name [ 20 ] ;
if ( extra_flags & ImGuiWindowFlags_ChildMenu )
2018-12-14 17:44:17 +00:00
ImFormatString ( name , IM_ARRAYSIZE ( name ) , " ##Menu_%02d " , g . BeginPopupStack . Size ) ; // Recycle windows based on depth
2018-08-30 18:59:24 +00:00
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 ) ;
if ( ! is_open ) // NB: Begin can return false when the popup is completely clipped (e.g. zero size display)
EndPopup ( ) ;
return is_open ;
}
bool ImGui : : BeginPopup ( const char * str_id , ImGuiWindowFlags flags )
{
ImGuiContext & g = * GImGui ;
2018-12-14 17:44:17 +00:00
if ( g . OpenPopupStack . Size < = g . BeginPopupStack . Size ) // Early out for performance
2018-08-30 18:59:24 +00:00
{
2019-05-13 12:45:41 +00:00
g . NextWindowData . ClearFlags ( ) ; // We behave like Begin() and need to consume those values
2018-08-30 18:59:24 +00:00
return false ;
}
2018-12-11 10:58:15 +00:00
flags | = ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings ;
return BeginPopupEx ( g . CurrentWindow - > GetID ( str_id ) , flags ) ;
2018-08-30 18:59:24 +00:00
}
2018-12-14 15:24:59 +00:00
// If 'p_open' is specified for a modal popup window, the popup will have a regular close button which will close the popup.
2019-06-11 14:11:19 +00:00
// 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.
2018-08-30 18:59:24 +00:00
bool ImGui : : BeginPopupModal ( const char * name , bool * p_open , ImGuiWindowFlags flags )
{
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = g . CurrentWindow ;
const ImGuiID id = window - > GetID ( name ) ;
if ( ! IsPopupOpen ( id ) )
{
2019-05-13 12:45:41 +00:00
g . NextWindowData . ClearFlags ( ) ; // We behave like Begin() and need to consume those values
2018-08-30 18:59:24 +00:00
return false ;
}
// Center modal windows by default
// FIXME: Should test for (PosCond & window->SetWindowPosAllowFlags) with the upcoming window.
2019-05-13 12:45:41 +00:00
if ( ( g . NextWindowData . Flags & ImGuiNextWindowDataFlags_HasPos ) = = 0 )
2018-08-30 18:59:24 +00:00
SetNextWindowPos ( g . IO . DisplaySize * 0.5f , ImGuiCond_Appearing , ImVec2 ( 0.5f , 0.5f ) ) ;
2018-12-11 10:58:15 +00:00
flags | = ImGuiWindowFlags_Popup | ImGuiWindowFlags_Modal | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings ;
const bool is_open = Begin ( name , p_open , flags ) ;
2018-08-30 18:59:24 +00:00
if ( ! is_open | | ( p_open & & ! * p_open ) ) // NB: is_open can be 'false' when the popup is completely clipped (e.g. zero size display)
{
EndPopup ( ) ;
if ( is_open )
2018-12-18 13:58:35 +00:00
ClosePopupToLevel ( g . BeginPopupStack . Size , true ) ;
2018-08-30 18:59:24 +00:00
return false ;
}
return is_open ;
}
void ImGui : : EndPopup ( )
{
2019-03-16 14:48:21 +00:00
ImGuiContext & g = * GImGui ;
2019-11-14 15:06:39 +00:00
ImGuiWindow * window = g . CurrentWindow ;
IM_ASSERT ( window - > Flags & ImGuiWindowFlags_Popup ) ; // Mismatched BeginPopup()/EndPopup() calls
2018-12-14 17:44:17 +00:00
IM_ASSERT ( g . BeginPopupStack . Size > 0 ) ;
2018-08-30 18:59:24 +00:00
// Make all menus and popups wrap around for now, may need to expose that policy.
2019-11-14 15:06:39 +00:00
NavMoveRequestTryWrapping ( window , ImGuiNavMoveFlags_LoopY ) ;
2018-08-30 18:59:24 +00:00
2019-11-14 15:06:39 +00:00
// Child-popups don't need to be layed out
IM_ASSERT ( g . WithinEndChild = = false ) ;
if ( window - > Flags & ImGuiWindowFlags_ChildWindow )
g . WithinEndChild = true ;
2018-08-30 18:59:24 +00:00
End ( ) ;
2019-11-14 15:06:39 +00:00
g . WithinEndChild = false ;
2018-08-30 18:59:24 +00:00
}
2019-12-06 15:29:22 +00:00
bool ImGui : : OpenPopupOnItemClick ( const char * str_id , ImGuiMouseButton mouse_button )
2019-10-14 12:08:56 +00:00
{
ImGuiWindow * window = GImGui - > CurrentWindow ;
if ( IsMouseReleased ( mouse_button ) & & IsItemHovered ( ImGuiHoveredFlags_AllowWhenBlockedByPopup ) )
{
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)
OpenPopupEx ( id ) ;
return true ;
}
return false ;
}
2018-08-30 18:59:24 +00:00
// This is a helper to handle the simplest case of associating one named popup to one given widget.
// You may want to handle this on user side if you have specific needs (e.g. tweaking IsItemHovered() parameters).
// You can pass a NULL str_id to use the identifier of the last item.
2019-12-06 15:29:22 +00:00
bool ImGui : : BeginPopupContextItem ( const char * str_id , ImGuiMouseButton mouse_button )
2018-08-30 18:59:24 +00:00
{
ImGuiWindow * window = GImGui - > CurrentWindow ;
2019-05-20 14:46:26 +00:00
if ( window - > SkipItems )
return false ;
2018-08-30 18:59:24 +00:00
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 ) )
OpenPopupEx ( id ) ;
return BeginPopupEx ( id , ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings ) ;
}
2019-12-06 15:29:22 +00:00
bool ImGui : : BeginPopupContextWindow ( const char * str_id , ImGuiMouseButton mouse_button , bool also_over_items )
2018-08-30 18:59:24 +00:00
{
if ( ! str_id )
str_id = " window_context " ;
ImGuiID id = GImGui - > CurrentWindow - > GetID ( str_id ) ;
if ( IsMouseReleased ( mouse_button ) & & IsWindowHovered ( ImGuiHoveredFlags_AllowWhenBlockedByPopup ) )
if ( also_over_items | | ! IsAnyItemHovered ( ) )
OpenPopupEx ( id ) ;
return BeginPopupEx ( id , ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings ) ;
}
2019-12-06 15:29:22 +00:00
bool ImGui : : BeginPopupContextVoid ( const char * str_id , ImGuiMouseButton mouse_button )
2018-08-30 18:59:24 +00:00
{
if ( ! str_id )
str_id = " void_context " ;
ImGuiID id = GImGui - > CurrentWindow - > GetID ( str_id ) ;
if ( IsMouseReleased ( mouse_button ) & & ! IsWindowHovered ( ImGuiHoveredFlags_AnyWindow ) )
OpenPopupEx ( id ) ;
return BeginPopupEx ( id , ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings ) ;
}
2018-08-30 19:00:51 +00:00
// r_avoid = the rectangle to avoid (e.g. for tooltip it is a rectangle around the mouse cursor which we want to avoid. for popups it's a small point around the cursor.)
// r_outer = the visible area rectangle, minus safe area padding. If our popup size won't fit because of safe area padding we ignore it.
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 ) ;
2019-03-04 15:20:32 +00:00
//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));
2018-08-30 19:00:51 +00:00
// Combo Box policy (we want a connecting edge)
if ( policy = = ImGuiPopupPositionPolicy_ComboBox )
{
const ImGuiDir dir_prefered_order [ ImGuiDir_COUNT ] = { ImGuiDir_Down , ImGuiDir_Right , ImGuiDir_Left , ImGuiDir_Up } ;
for ( int n = ( * last_dir ! = ImGuiDir_None ) ? - 1 : 0 ; n < ImGuiDir_COUNT ; n + + )
{
const ImGuiDir dir = ( n = = - 1 ) ? * last_dir : dir_prefered_order [ n ] ;
if ( n ! = - 1 & & dir = = * last_dir ) // Already tried this direction?
continue ;
ImVec2 pos ;
if ( dir = = ImGuiDir_Down ) pos = ImVec2 ( r_avoid . Min . x , r_avoid . Max . y ) ; // Below, Toward Right (default)
if ( dir = = ImGuiDir_Right ) pos = ImVec2 ( r_avoid . Min . x , r_avoid . Min . y - size . y ) ; // Above, Toward Right
if ( dir = = ImGuiDir_Left ) pos = ImVec2 ( r_avoid . Max . x - size . x , r_avoid . Max . y ) ; // Below, Toward Left
if ( dir = = ImGuiDir_Up ) pos = ImVec2 ( r_avoid . Max . x - size . x , r_avoid . Min . y - size . y ) ; // Above, Toward Left
if ( ! r_outer . Contains ( ImRect ( pos , pos + size ) ) )
continue ;
* last_dir = dir ;
return pos ;
}
}
// Default popup policy
const ImGuiDir dir_prefered_order [ ImGuiDir_COUNT ] = { ImGuiDir_Right , ImGuiDir_Down , ImGuiDir_Up , ImGuiDir_Left } ;
for ( int n = ( * last_dir ! = ImGuiDir_None ) ? - 1 : 0 ; n < ImGuiDir_COUNT ; n + + )
{
const ImGuiDir dir = ( n = = - 1 ) ? * last_dir : dir_prefered_order [ n ] ;
if ( n ! = - 1 & & dir = = * last_dir ) // Already tried this direction?
continue ;
float avail_w = ( dir = = ImGuiDir_Left ? r_avoid . Min . x : r_outer . Max . x ) - ( dir = = ImGuiDir_Right ? r_avoid . Max . x : r_outer . Min . x ) ;
float avail_h = ( dir = = ImGuiDir_Up ? r_avoid . Min . y : r_outer . Max . y ) - ( dir = = ImGuiDir_Down ? r_avoid . Max . y : r_outer . Min . y ) ;
if ( avail_w < size . x | | avail_h < size . y )
continue ;
ImVec2 pos ;
pos . x = ( dir = = ImGuiDir_Left ) ? r_avoid . Min . x - size . x : ( dir = = ImGuiDir_Right ) ? r_avoid . Max . x : base_pos_clamped . x ;
pos . y = ( dir = = ImGuiDir_Up ) ? r_avoid . Min . y - size . y : ( dir = = ImGuiDir_Down ) ? r_avoid . Max . y : base_pos_clamped . y ;
* last_dir = dir ;
return pos ;
}
// Fallback, try to keep within display
* last_dir = ImGuiDir_None ;
ImVec2 pos = ref_pos ;
pos . x = ImMax ( ImMin ( pos . x + size . x , r_outer . Max . x ) - size . x , r_outer . Min . x ) ;
pos . y = ImMax ( ImMin ( pos . y + size . y , r_outer . Max . y ) - size . y , r_outer . Min . y ) ;
return pos ;
}
2019-04-16 11:07:43 +00:00
ImRect ImGui : : GetWindowAllowedExtentRect ( ImGuiWindow * window )
{
IM_UNUSED ( window ) ;
ImVec2 padding = GImGui - > Style . DisplaySafeAreaPadding ;
ImRect r_screen = GetViewportRect ( ) ;
r_screen . Expand ( ImVec2 ( ( r_screen . GetWidth ( ) > padding . x * 2 ) ? - padding . x : 0.0f , ( r_screen . GetHeight ( ) > padding . y * 2 ) ? - padding . y : 0.0f ) ) ;
return r_screen ;
}
2018-08-30 19:00:51 +00:00
ImVec2 ImGui : : FindBestWindowPosForPopup ( ImGuiWindow * window )
{
ImGuiContext & g = * GImGui ;
ImRect r_outer = GetWindowAllowedExtentRect ( window ) ;
if ( window - > Flags & ImGuiWindowFlags_ChildMenu )
{
2019-02-06 11:32:10 +00:00
// Child menus typically request _any_ position within the parent menu item, and then we move the new menu outside the parent bounds.
2018-08-30 19:00:51 +00:00
// This is how we end up with child menus appearing (most-commonly) on the right of the parent menu.
IM_ASSERT ( g . CurrentWindow = = window ) ;
ImGuiWindow * parent_window = g . CurrentWindowStack [ g . CurrentWindowStack . Size - 2 ] ;
2019-02-06 11:32:10 +00:00
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).
2018-08-30 19:00:51 +00:00
ImRect r_avoid ;
if ( parent_window - > DC . MenuBarAppending )
r_avoid = ImRect ( - FLT_MAX , parent_window - > Pos . y + parent_window - > TitleBarHeight ( ) , FLT_MAX , parent_window - > Pos . y + parent_window - > TitleBarHeight ( ) + parent_window - > MenuBarHeight ( ) ) ;
else
r_avoid = ImRect ( parent_window - > Pos . x + horizontal_overlap , - FLT_MAX , parent_window - > Pos . x + parent_window - > Size . x - horizontal_overlap - parent_window - > ScrollbarSizes . x , FLT_MAX ) ;
return FindBestWindowPosForPopupEx ( window - > Pos , window - > Size , & window - > AutoPosLastDirection , r_outer , r_avoid ) ;
}
if ( window - > Flags & ImGuiWindowFlags_Popup )
{
ImRect r_avoid = ImRect ( window - > Pos . x - 1 , window - > Pos . y - 1 , window - > Pos . x + 1 , window - > Pos . y + 1 ) ;
return FindBestWindowPosForPopupEx ( window - > Pos , window - > Size , & window - > AutoPosLastDirection , r_outer , r_avoid ) ;
}
if ( window - > Flags & ImGuiWindowFlags_Tooltip )
{
// Position tooltip (always follows mouse)
float sc = g . Style . MouseCursorScale ;
ImVec2 ref_pos = NavCalcPreferredRefPos ( ) ;
ImRect r_avoid ;
if ( ! g . NavDisableHighlight & & g . NavDisableMouseHover & & ! ( g . IO . ConfigFlags & ImGuiConfigFlags_NavEnableSetMousePos ) )
r_avoid = ImRect ( ref_pos . x - 16 , ref_pos . y - 8 , ref_pos . x + 16 , ref_pos . y + 8 ) ;
else
r_avoid = ImRect ( ref_pos . x - 16 , ref_pos . y - 8 , ref_pos . x + 24 * sc , ref_pos . y + 24 * sc ) ; // FIXME: Hard-coded based on mouse cursor shape expectation. Exact dimension not very important.
ImVec2 pos = FindBestWindowPosForPopupEx ( ref_pos , window - > Size , & window - > AutoPosLastDirection , r_outer , r_avoid ) ;
if ( window - > AutoPosLastDirection = = ImGuiDir_None )
pos = ref_pos + ImVec2 ( 2 , 2 ) ; // If there's not enough room, for tooltip we prefer avoiding the cursor at all cost even if it means that part of the tooltip won't be visible.
return pos ;
}
IM_ASSERT ( 0 ) ;
return window - > Pos ;
}
2018-12-11 10:58:15 +00:00
2018-08-30 14:11:49 +00:00
//-----------------------------------------------------------------------------
2018-09-06 09:35:13 +00:00
// [SECTION] KEYBOARD/GAMEPAD NAVIGATION
2018-08-30 14:11:49 +00:00
//-----------------------------------------------------------------------------
2018-09-05 09:52:48 +00:00
ImGuiDir ImGetDirQuadrantFromDelta ( float dx , float dy )
2018-08-30 14:11:49 +00:00
{
if ( ImFabs ( dx ) > ImFabs ( dy ) )
return ( dx > 0.0f ) ? ImGuiDir_Right : ImGuiDir_Left ;
return ( dy > 0.0f ) ? ImGuiDir_Down : ImGuiDir_Up ;
}
static float inline NavScoreItemDistInterval ( float a0 , float a1 , float b0 , float b1 )
{
if ( a1 < b0 )
return a1 - b0 ;
if ( b1 < a0 )
return a0 - b1 ;
return 0.0f ;
}
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 ) ;
}
}
// Scoring function for directional navigation. Based on https://gist.github.com/rygorous/6981057
2019-09-18 11:21:12 +00:00
static bool ImGui : : NavScoreItem ( ImGuiNavMoveResult * result , ImRect cand )
2018-08-30 14:11:49 +00:00
{
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = g . CurrentWindow ;
if ( g . NavLayer ! = window - > DC . NavLayerCurrent )
return 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 + + ;
// When entering through a NavFlattened border, we consider child window items as fully clipped for scoring
if ( window - > ParentWindow = = g . NavWindow )
{
IM_ASSERT ( ( window - > Flags | g . NavWindow - > Flags ) & ImGuiWindowFlags_NavFlattened ) ;
2019-07-30 21:26:02 +00:00
if ( ! window - > ClipRect . Overlaps ( cand ) )
2018-08-30 14:11:49 +00:00
return false ;
cand . ClipWithFull ( window - > ClipRect ) ; // This allows the scored item to not overlap other candidates in the parent 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 ) ;
// 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 ) ;
// 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 )
{
// For non-overlapping boxes, use distance between boxes
dax = dbx ;
day = dby ;
dist_axial = dist_box ;
2018-09-05 09:52:48 +00:00
quadrant = ImGetDirQuadrantFromDelta ( dbx , dby ) ;
2018-08-30 14:11:49 +00:00
}
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 ;
2018-09-05 09:52:48 +00:00
quadrant = ImGetDirQuadrantFromDelta ( dcx , dcy ) ;
2018-08-30 14:11:49 +00:00
}
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 ;
}
# if IMGUI_DEBUG_NAV_SCORING
char buf [ 128 ] ;
2019-09-18 11:21:12 +00:00
if ( IsMouseHoveringRect ( cand . Min , cand . Max ) )
2018-08-30 14:11:49 +00:00
{
ImFormatString ( buf , IM_ARRAYSIZE ( buf ) , " dbox (%.2f,%.2f->%.4f) \n dcen (%.2f,%.2f->%.4f) \n d (%.2f,%.2f->%.4f) \n nav %c, quadrant %c " , dbx , dby , dist_box , dcx , dcy , dist_center , dax , day , dist_axial , " WENS " [ g . NavMoveDir ] , " WENS " [ quadrant ] ) ;
2019-09-18 11:21:12 +00:00
ImDrawList * draw_list = GetForegroundDrawList ( window ) ;
2018-08-30 14:11:49 +00:00
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 ) ) ;
2019-09-18 11:21:12 +00:00
draw_list - > AddRectFilled ( cand . Max - ImVec2 ( 4 , 4 ) , cand . Max + CalcTextSize ( buf ) + ImVec2 ( 4 , 4 ) , IM_COL32 ( 40 , 0 , 0 , 150 ) ) ;
2018-08-30 14:11:49 +00:00
draw_list - > AddText ( g . IO . FontDefault , 13.0f , cand . Max , ~ 0U , buf ) ;
}
else if ( g . IO . KeyCtrl ) // Hold to preview score in matching quadrant. Press C to rotate.
{
2019-09-18 11:21:12 +00:00
if ( IsKeyPressedMap ( ImGuiKey_C ) ) { g . NavMoveDirLast = ( ImGuiDir ) ( ( g . NavMoveDirLast + 1 ) & 3 ) ; g . IO . KeysDownDuration [ g . IO . KeyMap [ ImGuiKey_C ] ] = 0.01f ; }
2018-08-30 14:11:49 +00:00
if ( quadrant = = g . NavMoveDir )
{
ImFormatString ( buf , IM_ARRAYSIZE ( buf ) , " %.0f/%.0f " , dist_box , dist_center ) ;
2019-09-18 11:21:12 +00:00
ImDrawList * draw_list = GetForegroundDrawList ( window ) ;
2018-08-30 14:11:49 +00:00
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
// Is it in the quadrant we're interesting in moving to?
bool new_best = false ;
if ( quadrant = = g . NavMoveDir )
{
// 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;
const ImGuiItemFlags item_flags = window - > DC . ItemFlags ;
const ImRect nav_bb_rel ( nav_bb . Min - window - > Pos , nav_bb . Max - window - > Pos ) ;
// 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 ( ) ;
}
}
// 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)
2019-03-12 21:23:56 +00:00
if ( ( g . NavId ! = id | | ( g . NavMoveRequestFlags & ImGuiNavMoveFlags_AllowCurrentNavId ) ) & & ! ( item_flags & ( ImGuiItemFlags_Disabled | ImGuiItemFlags_NoNav ) ) )
2018-08-30 14:11:49 +00:00
{
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 )
{
result - > ID = id ;
2019-02-01 11:14:12 +00:00
result - > SelectScopeId = g . MultiSelectScopeId ;
2018-08-30 14:11:49 +00:00
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 ;
2019-02-01 11:14:12 +00:00
result - > SelectScopeId = g . MultiSelectScopeId ;
2018-08-30 14:11:49 +00:00
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 ;
2019-03-05 18:37:20 +00:00
g . NavIdTabCounter = window - > DC . FocusCounterTab ;
2018-08-30 14:11:49 +00:00
window - > NavRectRel [ window - > DC . NavLayerCurrent ] = nav_bb_rel ; // Store item bounding box (relative to window position)
}
}
2018-08-30 14:18:13 +00:00
bool ImGui : : NavMoveRequestButNoResultYet ( )
{
ImGuiContext & g = * GImGui ;
return g . NavMoveRequest & & g . NavMoveResultLocal . ID = = 0 & & g . NavMoveResultOther . ID = = 0 ;
}
void ImGui : : NavMoveRequestCancel ( )
{
ImGuiContext & g = * GImGui ;
g . NavMoveRequest = false ;
NavUpdateAnyRequestFlag ( ) ;
}
void ImGui : : NavMoveRequestForward ( ImGuiDir move_dir , ImGuiDir clip_dir , const ImRect & bb_rel , ImGuiNavMoveFlags move_flags )
{
ImGuiContext & g = * GImGui ;
IM_ASSERT ( g . NavMoveRequestForward = = ImGuiNavForward_None ) ;
2019-09-09 09:09:41 +00:00
NavMoveRequestCancel ( ) ;
2018-08-30 14:18:13 +00:00
g . NavMoveDir = move_dir ;
g . NavMoveClipDir = clip_dir ;
g . NavMoveRequestForward = ImGuiNavForward_ForwardQueued ;
g . NavMoveRequestFlags = move_flags ;
g . NavWindow - > NavRectRel [ g . NavLayer ] = bb_rel ;
}
void ImGui : : NavMoveRequestTryWrapping ( ImGuiWindow * window , ImGuiNavMoveFlags move_flags )
{
ImGuiContext & g = * GImGui ;
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 ] ;
ImGuiDir clip_dir = g . NavMoveDir ;
if ( g . NavMoveDir = = ImGuiDir_Left & & ( move_flags & ( ImGuiNavMoveFlags_WrapX | ImGuiNavMoveFlags_LoopX ) ) )
{
2019-06-03 14:55:48 +00:00
bb_rel . Min . x = bb_rel . Max . x = ImMax ( window - > SizeFull . x , window - > ContentSize . x + window - > WindowPadding . x * 2.0f ) - window - > Scroll . x ;
2018-08-30 14:18:13 +00:00
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 ) ) )
{
2019-06-03 14:55:48 +00:00
bb_rel . Min . y = bb_rel . Max . y = ImMax ( window - > SizeFull . y , window - > ContentSize . y + window - > WindowPadding . y * 2.0f ) - window - > Scroll . y ;
2018-08-30 14:18:13 +00:00
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 ) ;
}
}
2019-04-16 11:07:43 +00:00
// 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 )
2018-08-30 16:24:33 +00:00
{
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 ;
}
2019-04-16 11:07:43 +00:00
// Restore the last focused child.
// Call when we are expected to land on the Main Layer (0) after FocusWindow()
2018-08-30 16:24:33 +00:00
static ImGuiWindow * ImGui : : NavRestoreLastChildNavWindow ( ImGuiWindow * window )
{
return window - > NavLastChildNavWindow ? window - > NavLastChildNavWindow : window ;
}
2018-12-04 13:30:11 +00:00
static void NavRestoreLayer ( ImGuiNavLayer layer )
2018-08-30 16:24:33 +00:00
{
ImGuiContext & g = * GImGui ;
g . NavLayer = layer ;
if ( layer = = 0 )
g . NavWindow = ImGui : : NavRestoreLastChildNavWindow ( g . NavWindow ) ;
if ( layer = = 0 & & g . NavWindow - > NavLastIds [ 0 ] ! = 0 )
ImGui : : SetNavIDWithRectRel ( g . NavWindow - > NavLastIds [ 0 ] , layer , g . NavWindow - > NavRectRel [ 0 ] ) ;
else
ImGui : : NavInitWindow ( g . NavWindow , true ) ;
}
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 ) ;
}
2018-08-30 16:20:19 +00:00
// 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 ;
2019-10-14 12:08:56 +00:00
//IMGUI_DEBUG_LOG("[Nav] NavInitWindow() init_for_nav=%d, window=\"%s\", layer=%d\n", init_for_nav, window->Name, g.NavLayer);
2018-08-30 16:20:19 +00:00
if ( init_for_nav )
{
SetNavID ( 0 , g . NavLayer ) ;
g . NavInitRequest = true ;
g . NavInitRequestFromMove = false ;
g . NavInitResultId = 0 ;
g . NavInitResultRectRel = ImRect ( ) ;
NavUpdateAnyRequestFlag ( ) ;
}
else
{
g . NavId = window - > NavLastIds [ 0 ] ;
}
}
static ImVec2 ImGui : : NavCalcPreferredRefPos ( )
{
ImGuiContext & g = * GImGui ;
if ( g . NavDisableHighlight | | ! g . NavDisableMouseHover | | ! g . NavWindow )
2018-11-15 12:53:53 +00:00
{
// 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
{
// 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 = GetViewportRect ( ) ;
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.
}
2018-08-30 16:20:19 +00:00
}
2018-08-30 16:18:24 +00:00
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 )
2019-10-14 21:07:06 +00:00
return ( float ) CalcTypematicRepeatAmount ( t - g . IO . DeltaTime , t , g . IO . KeyRepeatDelay * 0.72f , g . IO . KeyRepeatRate * 0.80f ) ;
2018-08-30 16:18:24 +00:00
if ( mode = = ImGuiInputReadMode_RepeatSlow )
2019-10-14 21:07:06 +00:00
return ( float ) CalcTypematicRepeatAmount ( t - g . IO . DeltaTime , t , g . IO . KeyRepeatDelay * 1.25f , g . IO . KeyRepeatRate * 2.00f ) ;
2018-08-30 16:18:24 +00:00
if ( mode = = ImGuiInputReadMode_RepeatFast )
2019-10-14 21:07:06 +00:00
return ( float ) CalcTypematicRepeatAmount ( t - g . IO . DeltaTime , t , g . IO . KeyRepeatDelay * 0.72f , g . IO . KeyRepeatRate * 0.30f ) ;
2018-08-30 16:18:24 +00:00
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 ;
}
2018-08-30 16:10:15 +00:00
static void ImGui : : NavUpdate ( )
{
ImGuiContext & g = * GImGui ;
g . IO . WantSetMousePos = false ;
#if 0
2019-01-04 14:27:52 +00:00
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 ) ;
2018-08-30 16:10:15 +00:00
# endif
2018-08-30 16:13:34 +00:00
2018-08-30 16:10:15 +00:00
// 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 ;
2018-08-30 16:13:34 +00:00
2018-08-30 16:10:15 +00:00
// Update Keyboard->Nav inputs mapping
if ( nav_keyboard_active )
{
2019-07-24 16:48:34 +00:00
# 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)
2018-08-30 16:10:15 +00:00
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_ ) ;
2019-02-23 13:49:36 +00:00
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 ;
2018-08-30 16:10:15 +00:00
# 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 ;
2018-08-30 16:13:34 +00:00
2018-08-30 16:10:15 +00:00
// Process navigation init request (select first/default focus)
2019-06-04 22:25:21 +00:00
// 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 )
2018-08-30 16:10:15 +00:00
{
// Apply result from previous navigation init request (will typically select the first item, unless SetItemDefaultFocus() has been called)
2019-10-14 12:08:56 +00:00
//IMGUI_DEBUG_LOG("[Nav] Apply NavInitRequest result: 0x%08X Layer %d in \"%s\"\n", g.NavInitResultId, g.NavLayer, g.NavWindow->Name);
2018-08-30 16:10:15 +00:00
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 ;
2018-08-30 16:13:34 +00:00
2018-08-30 16:10:15 +00:00
// Process navigation move request
2018-11-21 15:07:04 +00:00
if ( g . NavMoveRequest )
2018-08-30 16:10:15 +00:00
NavUpdateMoveResult ( ) ;
2018-08-30 16:13:34 +00:00
2018-08-30 16:10:15 +00:00
// 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 ;
}
2018-08-30 16:13:34 +00:00
2018-08-30 16:10:15 +00:00
// 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 ) ;
2018-08-30 16:13:34 +00:00
2018-08-30 16:10:15 +00:00
// 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 )
2019-04-16 11:07:43 +00:00
NavSaveLastChildNavWindowIntoParent ( g . NavWindow ) ;
2018-08-30 16:10:15 +00:00
if ( g . NavWindow & & g . NavWindow - > NavLastChildNavWindow ! = NULL & & g . NavLayer = = 0 )
g . NavWindow - > NavLastChildNavWindow = NULL ;
2018-08-30 16:13:34 +00:00
2018-08-30 16:10:15 +00:00
// Update CTRL+TAB and Windowing features (hold Square to move/resize/etc.)
NavUpdateWindowing ( ) ;
2018-08-30 16:13:34 +00:00
2018-08-30 16:10:15 +00:00
// Set output flags for user application
g . IO . NavActive = ( nav_keyboard_active | | nav_gamepad_active ) & & g . NavWindow & & ! ( g . NavWindow - > Flags & ImGuiWindowFlags_NoNavInputs ) ;
2019-01-27 15:37:02 +00:00
g . IO . NavVisible = ( g . IO . NavActive & & g . NavId ! = 0 & & ! g . NavDisableHighlight ) | | ( g . NavWindowingTarget ! = NULL ) ;
2018-08-30 16:13:34 +00:00
2018-08-30 16:10:15 +00:00
// Process NavCancel input (to close a popup, get back to parent, clear focus)
2019-11-12 22:54:22 +00:00
if ( IsNavInputTest ( ImGuiNavInput_Cancel , ImGuiInputReadMode_Pressed ) )
2018-08-30 16:10:15 +00:00
{
if ( g . ActiveId ! = 0 )
{
2019-10-02 09:38:30 +00:00
if ( ! IsActiveIdUsingNavInput ( ImGuiNavInput_Cancel ) )
2019-01-30 14:16:09 +00:00
ClearActiveID ( ) ;
2018-08-30 16:10:15 +00:00
}
else if ( g . NavWindow & & ( g . NavWindow - > Flags & ImGuiWindowFlags_ChildWindow ) & & ! ( g . NavWindow - > Flags & ImGuiWindowFlags_Popup ) & & g . NavWindow - > ParentWindow )
{
// 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 ) )
2018-12-18 14:11:11 +00:00
ClosePopupToLevel ( g . OpenPopupStack . Size - 1 , true ) ;
2018-08-30 16:10:15 +00:00
}
else if ( g . NavLayer ! = 0 )
{
// Leave the "menu" layer
2018-12-04 13:30:11 +00:00
NavRestoreLayer ( ImGuiNavLayer_Main ) ;
2018-08-30 16:10:15 +00:00
}
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 ;
}
}
2018-08-30 16:13:34 +00:00
2018-08-30 16:10:15 +00:00
// 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 ) ;
2019-11-12 22:54:22 +00:00
bool activate_pressed = activate_down & & IsNavInputTest ( ImGuiNavInput_Activate , ImGuiInputReadMode_Pressed ) ;
2018-08-30 16:10:15 +00:00
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 ;
2019-11-12 22:54:22 +00:00
if ( ( g . ActiveId = = 0 | | g . ActiveId = = g . NavId ) & & IsNavInputTest ( ImGuiNavInput_Input , ImGuiInputReadMode_Pressed ) )
2018-08-30 16:10:15 +00:00
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 ;
2018-08-30 16:13:34 +00:00
2018-08-30 16:10:15 +00:00
// Process programmatic activation request
if ( g . NavNextActivateId ! = 0 )
g . NavActivateId = g . NavActivateDownId = g . NavActivatePressedId = g . NavInputId = g . NavNextActivateId ;
g . NavNextActivateId = 0 ;
2018-08-30 16:13:34 +00:00
2018-08-30 16:10:15 +00:00
// Initiate directional inputs request
if ( g . NavMoveRequestForward = = ImGuiNavForward_None )
{
g . NavMoveDir = ImGuiDir_None ;
2018-12-11 10:58:15 +00:00
g . NavMoveRequestFlags = ImGuiNavMoveFlags_None ;
2019-10-02 09:38:30 +00:00
if ( g . NavWindow & & ! g . NavWindowingTarget & & ! ( g . NavWindow - > Flags & ImGuiWindowFlags_NoNavInputs ) )
2018-08-30 16:10:15 +00:00
{
2019-11-12 22:54:22 +00:00
const ImGuiInputReadMode read_mode = ImGuiInputReadMode_Repeat ;
if ( ! IsActiveIdUsingNavDir ( ImGuiDir_Left ) & & ( IsNavInputTest ( ImGuiNavInput_DpadLeft , read_mode ) | | IsNavInputTest ( ImGuiNavInput_KeyLeft_ , read_mode ) ) ) { g . NavMoveDir = ImGuiDir_Left ; }
if ( ! IsActiveIdUsingNavDir ( ImGuiDir_Right ) & & ( IsNavInputTest ( ImGuiNavInput_DpadRight , read_mode ) | | IsNavInputTest ( ImGuiNavInput_KeyRight_ , read_mode ) ) ) { g . NavMoveDir = ImGuiDir_Right ; }
if ( ! IsActiveIdUsingNavDir ( ImGuiDir_Up ) & & ( IsNavInputTest ( ImGuiNavInput_DpadUp , read_mode ) | | IsNavInputTest ( ImGuiNavInput_KeyUp_ , read_mode ) ) ) { g . NavMoveDir = ImGuiDir_Up ; }
if ( ! IsActiveIdUsingNavDir ( ImGuiDir_Down ) & & ( IsNavInputTest ( ImGuiNavInput_DpadDown , read_mode ) | | IsNavInputTest ( ImGuiNavInput_KeyDown_ , read_mode ) ) ) { g . NavMoveDir = ImGuiDir_Down ; }
2018-08-30 16:10:15 +00:00
}
g . NavMoveClipDir = g . NavMoveDir ;
}
else
{
// Forwarding previous request (which has been modified, e.g. wrap around menus rewrite the requests with a starting rectangle at the other side of the window)
// (Preserve g.NavMoveRequestFlags, g.NavMoveClipDir which were set by the NavMoveRequestForward() function)
IM_ASSERT ( g . NavMoveDir ! = ImGuiDir_None & & g . NavMoveClipDir ! = ImGuiDir_None ) ;
IM_ASSERT ( g . NavMoveRequestForward = = ImGuiNavForward_ForwardQueued ) ;
g . NavMoveRequestForward = ImGuiNavForward_ForwardActive ;
}
2018-08-30 16:13:34 +00:00
2019-09-09 09:09:41 +00:00
// Update PageUp/PageDown/Home/End scroll
// FIXME-NAV: Consider enabling those keys even without the master ImGuiConfigFlags_NavEnableKeyboard flag?
2018-08-30 16:10:15 +00:00
float nav_scoring_rect_offset_y = 0.0f ;
if ( nav_keyboard_active )
2019-10-02 09:38:30 +00:00
nav_scoring_rect_offset_y = NavUpdatePageUpPageDown ( ) ;
2018-08-30 16:13:34 +00:00
2018-08-30 16:10:15 +00:00
// 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 )
{
2019-10-14 12:08:56 +00:00
//IMGUI_DEBUG_LOG("[Nav] NavInitRequest from move, window \"%s\", layer=%d\n", g.NavWindow->Name, g.NavLayer);
2018-08-30 16:10:15 +00:00
g . NavInitRequest = g . NavInitRequestFromMove = true ;
g . NavInitResultId = 0 ;
g . NavDisableHighlight = false ;
}
NavUpdateAnyRequestFlag ( ) ;
2018-08-30 16:13:34 +00:00
2018-08-30 16:10:15 +00:00
// Scrolling
if ( g . NavWindow & & ! ( g . NavWindow - > Flags & ImGuiWindowFlags_NoNavInputs ) & & ! g . NavWindowingTarget )
{
// *Fallback* manual-scroll with Nav directional keys when window has no navigable item
ImGuiWindow * window = g . NavWindow ;
2019-10-29 16:04:13 +00:00
const float scroll_speed = IM_ROUND ( window - > CalcFontSize ( ) * 100 * g . IO . DeltaTime ) ; // We need round the scrolling speed because sub-pixel scroll isn't reliably supported.
2018-08-30 16:10:15 +00:00
if ( window - > DC . NavLayerActiveMask = = 0x00 & & window - > DC . NavHasScroll & & g . NavMoveRequest )
{
if ( g . NavMoveDir = = ImGuiDir_Left | | g . NavMoveDir = = ImGuiDir_Right )
2019-07-23 01:24:23 +00:00
SetScrollX ( window , ImFloor ( window - > Scroll . x + ( ( g . NavMoveDir = = ImGuiDir_Left ) ? - 1.0f : + 1.0f ) * scroll_speed ) ) ;
2018-08-30 16:10:15 +00:00
if ( g . NavMoveDir = = ImGuiDir_Up | | g . NavMoveDir = = ImGuiDir_Down )
2019-07-23 01:24:23 +00:00
SetScrollY ( window , ImFloor ( window - > Scroll . y + ( ( g . NavMoveDir = = ImGuiDir_Up ) ? - 1.0f : + 1.0f ) * scroll_speed ) ) ;
2018-08-30 16:10:15 +00:00
}
// *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 )
{
2019-07-23 01:24:23 +00:00
SetScrollX ( window , ImFloor ( window - > Scroll . x + scroll_dir . x * scroll_speed ) ) ;
2018-08-30 16:10:15 +00:00
g . NavMoveFromClampedRefRect = true ;
}
if ( scroll_dir . y ! = 0.0f )
{
2019-07-23 01:24:23 +00:00
SetScrollY ( window , ImFloor ( window - > Scroll . y + scroll_dir . y * scroll_speed ) ) ;
2018-08-30 16:10:15 +00:00
g . NavMoveFromClampedRefRect = true ;
}
}
2018-08-30 16:13:34 +00:00
2018-08-30 16:10:15 +00:00
// Reset search results
g . NavMoveResultLocal . Clear ( ) ;
g . NavMoveResultLocalVisibleSet . Clear ( ) ;
g . NavMoveResultOther . Clear ( ) ;
2018-08-30 16:13:34 +00:00
2018-08-30 16:10:15 +00:00
// 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 ;
2019-05-28 13:54:55 +00:00
ImRect window_rect_rel ( window - > InnerRect . Min - window - > Pos - ImVec2 ( 1 , 1 ) , window - > InnerRect . Max - window - > Pos + ImVec2 ( 1 , 1 ) ) ;
2018-08-30 16:10:15 +00:00
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 ;
}
2018-08-30 16:13:34 +00:00
2018-08-30 16:10:15 +00:00
// 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 ) : GetViewportRect ( ) ;
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().
2019-03-04 15:20:32 +00:00
//GetForegroundDrawList()->AddRect(g.NavScoringRectScreen.Min, g.NavScoringRectScreen.Max, IM_COL32(255,200,0,255)); // [DEBUG]
2018-08-30 16:10:15 +00:00
g . NavScoringCount = 0 ;
# if IMGUI_DEBUG_NAV_RECTS
2019-03-04 15:20:32 +00:00
if ( g . NavWindow )
{
ImDrawList * draw_list = GetForegroundDrawList ( g . NavWindow ) ;
2019-03-16 14:48:21 +00:00
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]
2019-03-04 15:20:32 +00:00
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 ) ; }
}
2018-08-30 16:10:15 +00:00
# endif
}
2018-08-30 16:01:19 +00:00
2018-11-21 15:07:04 +00:00
// Apply result from previous frame navigation directional move request
2018-08-30 16:01:19 +00:00
static void ImGui : : NavUpdateMoveResult ( )
{
ImGuiContext & g = * GImGui ;
2018-11-21 15:07:04 +00:00
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
2018-08-30 16:01:19 +00:00
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 )
{
2019-09-09 09:09:41 +00:00
ImVec2 delta_scroll ;
if ( g . NavMoveRequestFlags & ImGuiNavMoveFlags_ScrollToEdge )
{
float scroll_target = ( g . NavMoveDir = = ImGuiDir_Up ) ? result - > Window - > ScrollMax . y : 0.0f ;
delta_scroll . y = result - > Window - > Scroll . y - scroll_target ;
SetScrollY ( result - > Window , scroll_target ) ;
}
else
{
ImRect rect_abs = ImRect ( result - > RectRel . Min + result - > Window - > Pos , result - > RectRel . Max + result - > Window - > Pos ) ;
delta_scroll = ScrollToBringRectIntoView ( result - > Window , rect_abs ) ;
}
2018-08-30 16:01:19 +00:00
2019-08-01 01:37:55 +00:00
// 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 ) ;
2018-08-30 16:01:19 +00:00
}
ClearActiveID ( ) ;
g . NavWindow = result - > Window ;
2019-02-01 11:14:12 +00:00
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 ;
2019-04-11 13:40:36 +00:00
g . NavJustMovedToMultiSelectScopeId = result - > SelectScopeId ;
2019-02-01 11:14:12 +00:00
}
2018-08-30 16:01:19 +00:00
SetNavIDWithRectRel ( result - > ID , g . NavLayer , result - > RectRel ) ;
g . NavMoveFromClampedRefRect = false ;
}
2019-09-09 09:09:41 +00:00
// Handle PageUp/PageDown/Home/End keys
2019-10-02 09:38:30 +00:00
static float ImGui : : NavUpdatePageUpPageDown ( )
2018-08-30 16:01:19 +00:00
{
ImGuiContext & g = * GImGui ;
2019-07-23 00:27:41 +00:00
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 ;
2019-10-02 09:38:30 +00:00
const bool page_up_held = IsKeyDown ( g . IO . KeyMap [ ImGuiKey_PageUp ] ) & & ! IsActiveIdUsingKey ( ImGuiKey_PageUp ) ;
const bool page_down_held = IsKeyDown ( g . IO . KeyMap [ ImGuiKey_PageDown ] ) & & ! IsActiveIdUsingKey ( ImGuiKey_PageDown ) ;
const bool home_pressed = IsKeyPressed ( g . IO . KeyMap [ ImGuiKey_Home ] ) & & ! IsActiveIdUsingKey ( ImGuiKey_Home ) ;
const bool end_pressed = IsKeyPressed ( g . IO . KeyMap [ ImGuiKey_End ] ) & & ! IsActiveIdUsingKey ( ImGuiKey_End ) ;
2019-09-09 09:09:41 +00:00
if ( page_up_held ! = page_down_held | | home_pressed ! = end_pressed ) // If either (not both) are pressed
2018-08-30 16:01:19 +00:00
{
2019-07-23 00:27:41 +00:00
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 ) )
2019-07-23 01:24:23 +00:00
SetScrollY ( window , window - > Scroll . y - window - > InnerRect . GetHeight ( ) ) ;
2019-07-23 00:27:41 +00:00
else if ( IsKeyPressed ( g . IO . KeyMap [ ImGuiKey_PageDown ] , true ) )
2019-07-23 01:24:23 +00:00
SetScrollY ( window , window - > Scroll . y + window - > InnerRect . GetHeight ( ) ) ;
2019-09-09 09:09:41 +00:00
else if ( home_pressed )
SetScrollY ( window , 0.0f ) ;
else if ( end_pressed )
SetScrollY ( window , window - > ScrollMax . y ) ;
2019-07-23 00:27:41 +00:00
}
else
2018-08-30 16:01:19 +00:00
{
2019-09-09 09:09:41 +00:00
ImRect & nav_rect_rel = window - > NavRectRel [ g . NavLayer ] ;
2019-07-23 00:27:41 +00:00
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 ) )
2018-08-30 16:01:19 +00:00
{
2019-07-23 00:27:41 +00:00
nav_scoring_rect_offset_y = - page_offset_y ;
2019-09-09 09:09:41 +00:00
g . NavMoveDir = ImGuiDir_Down ; // Because our scoring rect is offset up, we request the down direction (so we can always land on the last item)
2019-07-23 00:27:41 +00:00
g . NavMoveClipDir = ImGuiDir_Up ;
g . NavMoveRequestFlags = ImGuiNavMoveFlags_AllowCurrentNavId | ImGuiNavMoveFlags_AlsoScoreVisibleSet ;
2018-08-30 16:01:19 +00:00
}
2019-07-23 00:27:41 +00:00
else if ( IsKeyPressed ( g . IO . KeyMap [ ImGuiKey_PageDown ] , true ) )
2018-08-30 16:01:19 +00:00
{
2019-07-23 00:27:41 +00:00
nav_scoring_rect_offset_y = + page_offset_y ;
2019-09-09 09:09:41 +00:00
g . NavMoveDir = ImGuiDir_Up ; // Because our scoring rect is offset down, we request the up direction (so we can always land on the last item)
2019-07-23 00:27:41 +00:00
g . NavMoveClipDir = ImGuiDir_Down ;
g . NavMoveRequestFlags = ImGuiNavMoveFlags_AllowCurrentNavId | ImGuiNavMoveFlags_AlsoScoreVisibleSet ;
2018-08-30 16:01:19 +00:00
}
2019-09-09 09:09:41 +00:00
else if ( home_pressed )
{
// FIXME-NAV: handling of Home/End is assuming that the top/bottom most item will be visible with Scroll.y == 0/ScrollMax.y
// Scrolling will be handled via the ImGuiNavMoveFlags_ScrollToEdge flag, we don't scroll immediately to avoid scrolling happening before nav result.
// Preserve current horizontal position if we have any.
nav_rect_rel . Min . y = nav_rect_rel . Max . y = - window - > Scroll . y ;
if ( nav_rect_rel . IsInverted ( ) )
nav_rect_rel . Min . x = nav_rect_rel . Max . x = 0.0f ;
g . NavMoveDir = ImGuiDir_Down ;
g . NavMoveRequestFlags = ImGuiNavMoveFlags_AllowCurrentNavId | ImGuiNavMoveFlags_ScrollToEdge ;
}
else if ( end_pressed )
{
nav_rect_rel . Min . y = nav_rect_rel . Max . y = window - > ScrollMax . y + window - > SizeFull . y - window - > Scroll . y ;
if ( nav_rect_rel . IsInverted ( ) )
nav_rect_rel . Min . x = nav_rect_rel . Max . x = 0.0f ;
g . NavMoveDir = ImGuiDir_Up ;
g . NavMoveRequestFlags = ImGuiNavMoveFlags_AllowCurrentNavId | ImGuiNavMoveFlags_ScrollToEdge ;
}
2019-07-23 00:27:41 +00:00
return nav_scoring_rect_offset_y ;
2018-08-30 16:01:19 +00:00
}
}
return 0.0f ;
}
2019-04-28 15:05:23 +00:00
static int ImGui : : FindWindowFocusIndex ( ImGuiWindow * window ) // FIXME-OPT O(N)
2018-08-30 16:20:19 +00:00
{
ImGuiContext & g = * GImGui ;
2018-09-10 18:30:14 +00:00
for ( int i = g . WindowsFocusOrder . Size - 1 ; i > = 0 ; i - - )
if ( g . WindowsFocusOrder [ i ] = = window )
2018-08-30 16:20:19 +00:00
return i ;
return - 1 ;
}
static ImGuiWindow * FindWindowNavFocusable ( int i_start , int i_stop , int dir ) // FIXME-OPT O(N)
{
ImGuiContext & g = * GImGui ;
2018-09-10 18:30:14 +00:00
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 ] ;
2018-08-30 16:20:19 +00:00
return NULL ;
}
static void NavUpdateWindowingHighlightWindow ( int focus_change_dir )
{
ImGuiContext & g = * GImGui ;
IM_ASSERT ( g . NavWindowingTarget ) ;
if ( g . NavWindowingTarget - > Flags & ImGuiWindowFlags_Modal )
return ;
2019-04-28 15:05:23 +00:00
const int i_current = ImGui : : FindWindowFocusIndex ( g . NavWindowingTarget ) ;
2018-08-30 16:20:19 +00:00
ImGuiWindow * window_target = FindWindowNavFocusable ( i_current + focus_change_dir , - INT_MAX , focus_change_dir ) ;
if ( ! window_target )
2018-09-10 18:30:14 +00:00
window_target = FindWindowNavFocusable ( ( focus_change_dir < 0 ) ? ( g . WindowsFocusOrder . Size - 1 ) : 0 , i_current , focus_change_dir ) ;
2018-08-30 16:20:19 +00:00
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 ;
}
2019-03-05 11:03:54 +00:00
// 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)
2018-08-30 16:20:19 +00:00
static void ImGui : : NavUpdateWindowing ( )
{
ImGuiContext & g = * GImGui ;
ImGuiWindow * apply_focus_window = NULL ;
bool apply_toggle_layer = false ;
2019-06-19 16:14:24 +00:00
ImGuiWindow * modal_window = GetTopMostPopupModal ( ) ;
2018-08-30 16:20:19 +00:00
if ( modal_window ! = NULL )
{
g . NavWindowingTarget = NULL ;
return ;
}
// 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
2019-11-12 22:54:22 +00:00
bool start_windowing_with_gamepad = ! g . NavWindowingTarget & & IsNavInputTest ( ImGuiNavInput_Menu , ImGuiInputReadMode_Pressed ) ;
2018-08-30 16:20:19 +00:00
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 )
2018-09-10 18:30:14 +00:00
if ( ImGuiWindow * window = g . NavWindow ? g . NavWindow : FindWindowNavFocusable ( g . WindowsFocusOrder . Size - 1 , - INT_MAX , - 1 ) )
2018-08-30 16:20:19 +00:00
{
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 ;
}
// 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 ) ) ;
// Select window to focus
2019-11-12 22:54:22 +00:00
const int focus_change_dir = ( int ) IsNavInputTest ( ImGuiNavInput_FocusPrev , ImGuiInputReadMode_RepeatSlow ) - ( int ) IsNavInputTest ( ImGuiNavInput_FocusNext , ImGuiInputReadMode_RepeatSlow ) ;
2018-08-30 16:20:19 +00:00
if ( focus_change_dir ! = 0 )
{
NavUpdateWindowingHighlightWindow ( focus_change_dir ) ;
g . NavWindowingHighlightAlpha = 1.0f ;
}
2019-06-19 16:14:24 +00:00
// Single press toggles NavLayer, long press with L/R apply actual focus on release (until then the window was merely rendered top-most)
2018-08-30 16:20:19 +00:00
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 ;
}
}
// 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 ;
}
// 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
2019-11-12 22:54:22 +00:00
if ( IsNavInputTest ( ImGuiNavInput_KeyMenu_ , ImGuiInputReadMode_Pressed ) )
2019-04-16 11:07:43 +00:00
g . NavWindowingToggleLayer = true ;
2019-11-12 22:54:22 +00:00
if ( ( g . ActiveId = = 0 | | g . ActiveIdAllowOverlap ) & & g . NavWindowingToggleLayer & & IsNavInputTest ( ImGuiNavInput_KeyMenu_ , ImGuiInputReadMode_Released ) )
2018-08-30 16:20:19 +00:00
if ( IsMousePosValid ( & g . IO . MousePos ) = = IsMousePosValid ( & g . IO . MousePosPrev ) )
apply_toggle_layer = true ;
// Move window
if ( g . NavWindowingTarget & & ! ( g . NavWindowingTarget - > Flags & ImGuiWindowFlags_NoMove ) )
{
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 )
{
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
2019-05-31 18:48:52 +00:00
SetWindowPos ( g . NavWindowingTarget - > RootWindow , g . NavWindowingTarget - > RootWindow - > Pos + move_delta * move_speed , ImGuiCond_Always ) ;
2018-08-30 16:20:19 +00:00
g . NavDisableMouseHover = true ;
MarkIniSettingsDirty ( g . NavWindowingTarget ) ;
}
}
// Apply final focus
if ( apply_focus_window & & ( g . NavWindow = = NULL | | apply_focus_window ! = g . NavWindow - > RootWindow ) )
{
2019-04-28 20:21:23 +00:00
ClearActiveID ( ) ;
2018-08-30 16:20:19 +00:00
g . NavDisableHighlight = false ;
g . NavDisableMouseHover = true ;
apply_focus_window = NavRestoreLastChildNavWindow ( apply_focus_window ) ;
2019-04-28 20:21:23 +00:00
ClosePopupsOverWindow ( apply_focus_window , false ) ;
2018-08-30 16:20:19 +00:00
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
2018-12-04 13:30:11 +00:00
if ( apply_focus_window - > DC . NavLayerActiveMask = = ( 1 < < ImGuiNavLayer_Menu ) )
g . NavLayer = ImGuiNavLayer_Menu ;
2018-08-30 16:20:19 +00:00
}
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 ;
2019-04-16 11:07:43 +00:00
while ( new_nav_window - > ParentWindow
& & ( new_nav_window - > DC . NavLayerActiveMask & ( 1 < < ImGuiNavLayer_Menu ) ) = = 0
2018-12-11 10:58:15 +00:00
& & ( new_nav_window - > Flags & ImGuiWindowFlags_ChildWindow ) ! = 0
& & ( new_nav_window - > Flags & ( ImGuiWindowFlags_Popup | ImGuiWindowFlags_ChildMenu ) ) = = 0 )
2018-08-30 16:20:19 +00:00
new_nav_window = new_nav_window - > ParentWindow ;
if ( new_nav_window ! = g . NavWindow )
{
ImGuiWindow * old_nav_window = g . NavWindow ;
FocusWindow ( new_nav_window ) ;
new_nav_window - > NavLastChildNavWindow = old_nav_window ;
}
g . NavDisableHighlight = false ;
g . NavDisableMouseHover = true ;
2019-04-16 11:07:43 +00:00
// When entering a regular menu bar with the Alt key, we always reinitialize the navigation ID.
const ImGuiNavLayer new_nav_layer = ( g . NavWindow - > DC . NavLayerActiveMask & ( 1 < < ImGuiNavLayer_Menu ) ) ? ( ImGuiNavLayer ) ( ( int ) g . NavLayer ^ 1 ) : ImGuiNavLayer_Main ;
NavRestoreLayer ( new_nav_layer ) ;
2018-08-30 16:20:19 +00:00
}
}
2018-08-30 16:18:24 +00:00
// Window has already passed the IsWindowNavFocusable()
static const char * GetFallbackWindowNameForWindowingList ( ImGuiWindow * window )
{
if ( window - > Flags & ImGuiWindowFlags_Popup )
return " (Popup) " ;
if ( ( window - > Flags & ImGuiWindowFlags_MenuBar ) & & strcmp ( window - > Name , " ##MainMenuBar " ) = = 0 )
return " (Main menu bar) " ;
return " (Untitled) " ;
}
// Overlay displayed when using CTRL+TAB. Called by EndFrame().
2019-09-09 09:09:41 +00:00
void ImGui : : NavUpdateWindowingOverlay ( )
2018-08-30 16:18:24 +00:00
{
ImGuiContext & g = * GImGui ;
IM_ASSERT ( g . NavWindowingTarget ! = NULL ) ;
if ( g . NavWindowingTimer < NAV_WINDOWING_LIST_APPEAR_DELAY )
return ;
if ( g . NavWindowingList = = NULL )
g . NavWindowingList = FindWindowByName ( " ###NavWindowingList " ) ;
SetNextWindowSizeConstraints ( ImVec2 ( g . IO . DisplaySize . x * 0.20f , g . IO . DisplaySize . y * 0.20f ) , ImVec2 ( FLT_MAX , FLT_MAX ) ) ;
SetNextWindowPos ( g . IO . DisplaySize * 0.5f , ImGuiCond_Always , ImVec2 ( 0.5f , 0.5f ) ) ;
PushStyleVar ( ImGuiStyleVar_WindowPadding , g . Style . WindowPadding * 2.0f ) ;
2018-10-15 16:23:18 +00:00
Begin ( " ###NavWindowingList " , NULL , ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings ) ;
2018-09-10 18:30:14 +00:00
for ( int n = g . WindowsFocusOrder . Size - 1 ; n > = 0 ; n - - )
2018-08-30 16:18:24 +00:00
{
2018-09-10 18:30:14 +00:00
ImGuiWindow * window = g . WindowsFocusOrder [ n ] ;
2018-08-30 16:18:24 +00:00
if ( ! IsWindowNavFocusable ( window ) )
continue ;
const char * label = window - > Name ;
if ( label = = FindRenderedTextEnd ( label ) )
label = GetFallbackWindowNameForWindowingList ( window ) ;
Selectable ( label , g . NavWindowingTarget = = window ) ;
}
End ( ) ;
PopStyleVar ( ) ;
}
2019-05-09 10:56:03 +00:00
2017-10-29 20:15:02 +00:00
//-----------------------------------------------------------------------------
2018-09-06 09:35:13 +00:00
// [SECTION] DRAG AND DROP
2017-10-29 20:15:02 +00:00
//-----------------------------------------------------------------------------
2017-12-12 22:37:27 +00:00
void ImGui : : ClearDragDrop ( )
2017-11-06 19:02:56 +00:00
{
ImGuiContext & g = * GImGui ;
g . DragDropActive = false ;
g . DragDropPayload . Clear ( ) ;
2018-12-11 10:58:15 +00:00
g . DragDropAcceptFlags = ImGuiDragDropFlags_None ;
2017-11-06 19:02:56 +00:00
g . DragDropAcceptIdCurr = g . DragDropAcceptIdPrev = 0 ;
2017-11-08 14:47:52 +00:00
g . DragDropAcceptIdCurrRectSurface = FLT_MAX ;
2017-11-06 19:02:56 +00:00
g . DragDropAcceptFrameCount = - 1 ;
2018-07-31 11:36:06 +00:00
g . DragDropPayloadBufHeap . clear ( ) ;
memset ( & g . DragDropPayloadBufLocal , 0 , sizeof ( g . DragDropPayloadBufLocal ) ) ;
2017-11-06 19:02:56 +00:00
}
2018-05-17 12:12:37 +00:00
// Call when current ID is active.
2017-10-29 20:15:02 +00:00
// When this returns true you need to: a) call SetDragDropPayload() exactly once, b) you may render the payload visual/description, c) call EndDragDropSource()
2018-02-21 20:33:58 +00:00
bool ImGui : : BeginDragDropSource ( ImGuiDragDropFlags flags )
2017-10-29 20:15:02 +00:00
{
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = g . CurrentWindow ;
2017-10-29 22:10:44 +00:00
2017-12-15 10:16:10 +00:00
bool source_drag_active = false ;
ImGuiID source_id = 0 ;
ImGuiID source_parent_id = 0 ;
2019-12-06 15:29:22 +00:00
ImGuiMouseButton mouse_button = ImGuiMouseButton_Left ;
2017-12-15 10:16:10 +00:00
if ( ! ( flags & ImGuiDragDropFlags_SourceExtern ) )
2017-10-29 22:10:44 +00:00
{
2017-12-15 10:16:10 +00:00
source_id = window - > DC . LastItemId ;
if ( source_id ! = 0 & & g . ActiveId ! = source_id ) // Early out for most common case
2017-10-29 22:10:44 +00:00
return false ;
2017-12-15 10:16:10 +00:00
if ( g . IO . MouseDown [ mouse_button ] = = false )
2017-10-29 22:10:44 +00:00
return false ;
2017-12-15 10:16:10 +00:00
if ( source_id = = 0 )
2017-10-29 22:10:44 +00:00
{
2017-12-15 10:16:10 +00:00
// 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 ;
}
2019-04-29 14:34:02 +00:00
// Early out
if ( ( window - > DC . LastItemStatusFlags & ImGuiItemStatusFlags_HoveredRect ) = = 0 & & ( g . ActiveId = = 0 | | g . ActiveIdWindow ! = window ) )
return false ;
2017-12-15 10:16:10 +00:00
// Magic fallback (=somehow reprehensible) to handle items with no assigned ID, e.g. Text(), Image()
2018-05-17 12:12:37 +00:00
// 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.
2017-12-15 10:16:10 +00:00
// 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 ) ;
2019-04-29 14:34:02 +00:00
bool is_hovered = ItemHoverable ( window - > DC . LastItemRect , source_id ) ;
2017-12-15 10:16:10 +00:00
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 ;
2017-10-29 22:10:44 +00:00
}
2018-05-24 16:05:27 +00:00
else
{
g . ActiveIdAllowOverlap = false ;
}
2017-12-15 10:16:10 +00:00
if ( g . ActiveId ! = source_id )
return false ;
source_parent_id = window - > IDStack . back ( ) ;
source_drag_active = IsMouseDragging ( mouse_button ) ;
}
else
{
window = NULL ;
2019-04-19 17:48:51 +00:00
source_id = ImHashStr ( " #SourceExtern " ) ;
2017-12-15 10:16:10 +00:00
source_drag_active = true ;
2017-10-29 22:10:44 +00:00
}
2017-10-29 20:15:02 +00:00
2017-12-15 10:16:10 +00:00
if ( source_drag_active )
2017-10-29 20:15:02 +00:00
{
if ( ! g . DragDropActive )
{
2017-12-15 10:16:10 +00:00
IM_ASSERT ( source_id ! = 0 ) ;
2017-11-06 19:02:56 +00:00
ClearDragDrop ( ) ;
2017-10-29 20:15:02 +00:00
ImGuiPayload & payload = g . DragDropPayload ;
2017-12-15 10:16:10 +00:00
payload . SourceId = source_id ;
payload . SourceParentId = source_parent_id ;
2017-10-29 20:15:02 +00:00
g . DragDropActive = true ;
g . DragDropSourceFlags = flags ;
g . DragDropMouseButton = mouse_button ;
}
2018-07-30 16:06:41 +00:00
g . DragDropSourceFrameCount = g . FrameCount ;
2018-07-08 18:04:49 +00:00
g . DragDropWithinSourceOrTarget = true ;
2017-10-29 20:15:02 +00:00
2017-12-15 09:15:51 +00:00
if ( ! ( flags & ImGuiDragDropFlags_SourceNoPreviewTooltip ) )
2017-10-29 20:15:02 +00:00
{
2018-05-28 18:50:52 +00:00
// Target can request the Source to not display its tooltip (we use a dedicated flag to make this request explicit)
2019-01-20 16:56:17 +00:00
// We unfortunately can't just modify the source flags and skip the call to BeginTooltip, as caller may be emitting contents.
2018-07-08 18:04:49 +00:00
BeginTooltip ( ) ;
2019-01-16 15:10:51 +00:00
if ( g . DragDropAcceptIdPrev & & ( g . DragDropAcceptFlags & ImGuiDragDropFlags_AcceptNoPreviewTooltip ) )
2018-05-28 18:50:52 +00:00
{
ImGuiWindow * tooltip_window = g . CurrentWindow ;
tooltip_window - > SkipItems = true ;
2019-03-28 14:41:49 +00:00
tooltip_window - > HiddenFramesCanSkipItems = 1 ;
2018-05-28 18:50:52 +00:00
}
2017-10-29 20:15:02 +00:00
}
2017-10-29 20:31:49 +00:00
2017-12-15 10:16:10 +00:00
if ( ! ( flags & ImGuiDragDropFlags_SourceNoDisableHover ) & & ! ( flags & ImGuiDragDropFlags_SourceExtern ) )
2018-02-06 12:34:41 +00:00
window - > DC . LastItemStatusFlags & = ~ ImGuiItemStatusFlags_HoveredRect ;
2017-10-29 20:31:49 +00:00
2017-10-29 20:15:02 +00:00
return true ;
}
return false ;
}
void ImGui : : EndDragDropSource ( )
{
ImGuiContext & g = * GImGui ;
IM_ASSERT ( g . DragDropActive ) ;
2018-07-08 18:04:49 +00:00
IM_ASSERT ( g . DragDropWithinSourceOrTarget & & " Not after a BeginDragDropSource()? " ) ;
2017-10-29 20:15:02 +00:00
2017-12-15 09:15:51 +00:00
if ( ! ( g . DragDropSourceFlags & ImGuiDragDropFlags_SourceNoPreviewTooltip ) )
2018-07-08 18:04:49 +00:00
EndTooltip ( ) ;
2017-11-02 17:30:46 +00:00
// Discard the drag if have not called SetDragDropPayload()
if ( g . DragDropPayload . DataFrameCount = = - 1 )
2017-11-06 19:02:56 +00:00
ClearDragDrop ( ) ;
2018-07-08 18:04:49 +00:00
g . DragDropWithinSourceOrTarget = false ;
2018-05-28 19:34:32 +00:00
}
2017-11-02 17:30:46 +00:00
// Use 'cond' to choose to submit payload on drag start or every frame
2017-10-29 20:15:02 +00:00
bool ImGui : : SetDragDropPayload ( const char * type , const void * data , size_t data_size , ImGuiCond cond )
{
ImGuiContext & g = * GImGui ;
ImGuiPayload & payload = g . DragDropPayload ;
if ( cond = = 0 )
cond = ImGuiCond_Always ;
IM_ASSERT ( type ! = NULL ) ;
2018-06-05 11:39:42 +00:00
IM_ASSERT ( strlen ( type ) < IM_ARRAYSIZE ( payload . DataType ) & & " Payload type can be at most 32 characters long " ) ;
2017-11-09 19:09:09 +00:00
IM_ASSERT ( ( data ! = NULL & & data_size > 0 ) | | ( data = = NULL & & data_size = = 0 ) ) ;
2017-10-29 20:15:02 +00:00
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 )
{
// 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 ;
2018-04-28 08:43:15 +00:00
memcpy ( payload . Data , data , data_size ) ;
2017-10-29 20:15:02 +00:00
}
else if ( data_size > 0 )
{
// Store locally
memset ( & g . DragDropPayloadBufLocal , 0 , sizeof ( g . DragDropPayloadBufLocal ) ) ;
payload . Data = g . DragDropPayloadBufLocal ;
2018-04-28 08:43:15 +00:00
memcpy ( payload . Data , data , data_size ) ;
2017-10-29 20:15:02 +00:00
}
else
{
payload . Data = NULL ;
}
payload . DataSize = ( int ) data_size ;
}
payload . DataFrameCount = g . FrameCount ;
2017-11-06 19:02:56 +00:00
return ( g . DragDropAcceptFrameCount = = g . FrameCount ) | | ( g . DragDropAcceptFrameCount = = g . FrameCount - 1 ) ;
2017-10-29 20:15:02 +00:00
}
2017-11-10 12:13:28 +00:00
bool ImGui : : BeginDragDropTargetCustom ( const ImRect & bb , ImGuiID id )
{
ImGuiContext & g = * GImGui ;
if ( ! g . DragDropActive )
return false ;
ImGuiWindow * window = g . CurrentWindow ;
if ( g . HoveredWindow = = NULL | | window - > RootWindow ! = g . HoveredWindow - > RootWindow )
return false ;
2017-12-12 17:17:18 +00:00
IM_ASSERT ( id ! = 0 ) ;
if ( ! IsMouseHoveringRect ( bb . Min , bb . Max ) | | ( id = = g . DragDropPayload . SourceId ) )
2017-11-10 12:13:28 +00:00
return false ;
2018-07-31 11:36:06 +00:00
if ( window - > SkipItems )
return false ;
2017-11-10 12:13:28 +00:00
2018-07-08 18:04:49 +00:00
IM_ASSERT ( g . DragDropWithinSourceOrTarget = = false ) ;
2017-11-10 12:13:28 +00:00
g . DragDropTargetRect = bb ;
g . DragDropTargetId = id ;
2018-07-08 18:04:49 +00:00
g . DragDropWithinSourceOrTarget = true ;
2017-11-10 12:13:28 +00:00
return true ;
}
// We don't use BeginDragDropTargetCustom() and duplicate its code because:
2017-12-12 17:17:18 +00:00
// 1) we use LastItemRectHoveredRect which handles items that pushes a temporarily clip rectangle in their code. Calling BeginDragDropTargetCustom(LastItemRect) would not handle them.
2017-11-10 12:13:28 +00:00
// 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)
2017-10-29 20:15:02 +00:00
bool ImGui : : BeginDragDropTarget ( )
{
ImGuiContext & g = * GImGui ;
if ( ! g . DragDropActive )
return false ;
ImGuiWindow * window = g . CurrentWindow ;
2018-02-06 12:34:41 +00:00
if ( ! ( window - > DC . LastItemStatusFlags & ImGuiItemStatusFlags_HoveredRect ) )
2017-10-29 20:15:02 +00:00
return false ;
2017-11-10 12:13:28 +00:00
if ( g . HoveredWindow = = NULL | | window - > RootWindow ! = g . HoveredWindow - > RootWindow )
2017-10-29 20:15:02 +00:00
return false ;
2018-02-06 12:46:14 +00:00
const ImRect & display_rect = ( window - > DC . LastItemStatusFlags & ImGuiItemStatusFlags_HasDisplayRect ) ? window - > DC . LastItemDisplayRect : window - > DC . LastItemRect ;
2017-12-12 17:17:18 +00:00
ImGuiID id = window - > DC . LastItemId ;
if ( id = = 0 )
2018-02-06 12:46:14 +00:00
id = window - > GetIDFromRectangle ( display_rect ) ;
2017-12-12 17:17:18 +00:00
if ( g . DragDropPayload . SourceId = = id )
return false ;
2018-07-08 18:04:49 +00:00
IM_ASSERT ( g . DragDropWithinSourceOrTarget = = false ) ;
2018-02-06 12:46:14 +00:00
g . DragDropTargetRect = display_rect ;
2017-12-12 17:17:18 +00:00
g . DragDropTargetId = id ;
2018-07-08 18:04:49 +00:00
g . DragDropWithinSourceOrTarget = true ;
2017-10-29 20:15:02 +00:00
return true ;
}
2017-12-12 22:37:27 +00:00
bool ImGui : : IsDragDropPayloadBeingAccepted ( )
{
ImGuiContext & g = * GImGui ;
return g . DragDropActive & & g . DragDropAcceptIdPrev ! = 0 ;
}
2017-10-29 20:15:02 +00:00
const ImGuiPayload * ImGui : : AcceptDragDropPayload ( const char * type , ImGuiDragDropFlags flags )
{
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = g . CurrentWindow ;
ImGuiPayload & payload = g . DragDropPayload ;
IM_ASSERT ( g . DragDropActive ) ; // Not called between BeginDragDropTarget() and EndDragDropTarget() ?
2018-05-17 12:12:37 +00:00
IM_ASSERT ( payload . DataFrameCount ! = - 1 ) ; // Forgot to call EndDragDropTarget() ?
2017-10-29 20:15:02 +00:00
if ( type ! = NULL & & ! payload . IsDataType ( type ) )
return NULL ;
2017-11-08 14:47:52 +00:00
// Accept smallest drag target bounding box, this allows us to nest drag targets conveniently without ordering constraints.
2017-11-10 12:13:28 +00:00
// 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 ;
2017-11-08 14:47:52 +00:00
float r_surface = r . GetWidth ( ) * r . GetHeight ( ) ;
if ( r_surface < g . DragDropAcceptIdCurrRectSurface )
{
2018-05-28 18:50:52 +00:00
g . DragDropAcceptFlags = flags ;
2017-11-10 12:13:28 +00:00
g . DragDropAcceptIdCurr = g . DragDropTargetId ;
2017-11-08 14:47:52 +00:00
g . DragDropAcceptIdCurrRectSurface = r_surface ;
}
2017-11-10 12:13:28 +00:00
// Render default drop visuals
2017-11-14 21:11:43 +00:00
payload . Preview = was_accepted_previously ;
2017-12-15 10:09:18 +00:00
flags | = ( g . DragDropSourceFlags & ImGuiDragDropFlags_AcceptNoDrawDefaultRect ) ; // Source can also inhibit the preview (useful for external sources that lives for 1 frame)
2017-11-14 21:11:43 +00:00
if ( ! ( flags & ImGuiDragDropFlags_AcceptNoDrawDefaultRect ) & & payload . Preview )
2017-10-29 20:15:02 +00:00
{
2017-12-12 14:44:22 +00:00
// FIXME-DRAG: Settle on a proper default visuals for drop target.
r . Expand ( 3.5f ) ;
2017-11-09 19:17:10 +00:00
bool push_clip_rect = ! window - > ClipRect . Contains ( r ) ;
2018-07-27 10:29:33 +00:00
if ( push_clip_rect ) window - > DrawList - > PushClipRect ( r . Min - ImVec2 ( 1 , 1 ) , r . Max + ImVec2 ( 1 , 1 ) ) ;
2017-12-12 14:44:22 +00:00
window - > DrawList - > AddRect ( r . Min , r . Max , GetColorU32 ( ImGuiCol_DragDropTarget ) , 0.0f , ~ 0 , 2.0f ) ;
2017-11-09 19:17:10 +00:00
if ( push_clip_rect ) window - > DrawList - > PopClipRect ( ) ;
2017-10-29 20:15:02 +00:00
}
2017-11-10 12:13:28 +00:00
2017-11-06 19:02:56 +00:00
g . DragDropAcceptFrameCount = g . FrameCount ;
2017-12-15 10:16:10 +00:00
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()
2017-10-29 20:15:02 +00:00
if ( ! payload . Delivery & & ! ( flags & ImGuiDragDropFlags_AcceptBeforeDelivery ) )
return NULL ;
return & payload ;
}
2018-10-01 13:53:18 +00:00
const ImGuiPayload * ImGui : : GetDragDropPayload ( )
{
ImGuiContext & g = * GImGui ;
return g . DragDropActive ? & g . DragDropPayload : NULL ;
}
2017-10-29 20:15:02 +00:00
// 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 ( )
{
2018-07-08 18:04:49 +00:00
ImGuiContext & g = * GImGui ;
2017-10-29 20:15:02 +00:00
IM_ASSERT ( g . DragDropActive ) ;
2018-07-08 18:04:49 +00:00
IM_ASSERT ( g . DragDropWithinSourceOrTarget ) ;
g . DragDropWithinSourceOrTarget = false ;
2017-10-29 20:15:02 +00:00
}
2018-12-11 10:58:15 +00:00
2018-08-30 13:51:14 +00:00
//-----------------------------------------------------------------------------
2018-09-06 09:35:13 +00:00
// [SECTION] LOGGING/CAPTURING
2018-08-30 13:51:14 +00:00
//-----------------------------------------------------------------------------
2019-03-16 14:48:21 +00:00
// All text output from the interface can be captured into tty/file/clipboard.
2019-02-01 09:26:08 +00:00
// By default, tree nodes are automatically opened during logging.
//-----------------------------------------------------------------------------
2018-08-30 13:51:14 +00:00
// Pass text data straight to log (without being displayed)
void ImGui : : LogText ( const char * fmt , . . . )
{
ImGuiContext & g = * GImGui ;
if ( ! g . LogEnabled )
return ;
va_list args ;
va_start ( args , fmt ) ;
if ( g . LogFile )
2019-11-19 20:14:44 +00:00
{
g . LogBuffer . Buf . resize ( 0 ) ;
g . LogBuffer . appendfv ( fmt , args ) ;
2019-11-20 09:40:14 +00:00
ImFileWrite ( g . LogBuffer . c_str ( ) , sizeof ( char ) , ( ImU64 ) g . LogBuffer . size ( ) , g . LogFile ) ;
2019-11-19 20:14:44 +00:00
}
2018-08-30 13:51:14 +00:00
else
2019-11-19 20:14:44 +00:00
{
2019-02-23 14:24:01 +00:00
g . LogBuffer . appendfv ( fmt , args ) ;
2019-11-19 20:14:44 +00:00
}
2018-08-30 13:51:14 +00:00
va_end ( args ) ;
}
// 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 ;
if ( ! text_end )
text_end = FindRenderedTextEnd ( text , text_end ) ;
2019-02-23 15:22:55 +00:00
const bool log_new_line = ref_pos & & ( ref_pos - > y > g . LogLinePosY + 1 ) ;
2018-08-30 13:51:14 +00:00
if ( ref_pos )
2019-02-23 15:22:55 +00:00
g . LogLinePosY = ref_pos - > y ;
if ( log_new_line )
g . LogLineFirstItem = true ;
2018-08-30 13:51:14 +00:00
const char * text_remaining = text ;
2019-02-23 14:39:18 +00:00
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 ) ;
2018-08-30 13:51:14 +00:00
for ( ; ; )
{
// Split the string. Each new line (after a '\n') is followed by spacing corresponding to the current depth of our log entry.
2019-02-23 15:22:55 +00:00
// We don't add a trailing \n to allow a subsequent item on the same line to be captured.
2018-10-11 09:48:40 +00:00
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 ) )
2018-08-30 13:51:14 +00:00
{
2018-10-11 09:48:40 +00:00
const int char_count = ( int ) ( line_end - line_start ) ;
2018-08-30 13:51:14 +00:00
if ( log_new_line | | ! is_first_line )
2019-02-23 15:22:55 +00:00
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 ) ;
2019-03-16 14:48:21 +00:00
else
2018-10-11 09:48:40 +00:00
LogText ( " %.*s " , char_count , line_start ) ;
2019-02-23 15:22:55 +00:00
g . LogLineFirstItem = false ;
}
else if ( log_new_line )
{
// An empty "" string at a different Y position should output a carriage return.
LogText ( IM_NEWLINE ) ;
break ;
2018-08-30 13:51:14 +00:00
}
if ( is_last_line )
break ;
text_remaining = line_end + 1 ;
}
}
2019-02-23 15:22:55 +00:00
// Start logging/capturing text output
void ImGui : : LogBegin ( ImGuiLogType type , int auto_open_depth )
2018-08-30 13:51:14 +00:00
{
ImGuiContext & g = * GImGui ;
ImGuiWindow * window = g . CurrentWindow ;
2019-02-23 15:22:55 +00:00
IM_ASSERT ( g . LogEnabled = = false ) ;
2018-08-30 13:51:14 +00:00
IM_ASSERT ( g . LogFile = = NULL ) ;
2019-02-23 15:22:55 +00:00
IM_ASSERT ( g . LogBuffer . empty ( ) ) ;
2018-08-30 13:51:14 +00:00
g . LogEnabled = true ;
2019-02-23 15:22:55 +00:00
g . LogType = type ;
2019-02-23 14:39:18 +00:00
g . LogDepthRef = window - > DC . TreeDepth ;
g . LogDepthToExpand = ( ( auto_open_depth > = 0 ) ? auto_open_depth : g . LogDepthToExpandDefault ) ;
2019-02-23 15:22:55 +00:00
g . LogLinePosY = FLT_MAX ;
g . LogLineFirstItem = true ;
}
void ImGui : : LogToTTY ( int auto_open_depth )
{
ImGuiContext & g = * GImGui ;
if ( g . LogEnabled )
return ;
2019-11-19 20:14:44 +00:00
IM_UNUSED ( auto_open_depth ) ;
# ifndef IMGUI_DISABLE_TTY_FUNCTIONS
2019-02-23 15:22:55 +00:00
LogBegin ( ImGuiLogType_TTY , auto_open_depth ) ;
g . LogFile = stdout ;
2019-11-19 20:14:44 +00:00
# endif
2018-08-30 13:51:14 +00:00
}
2019-02-23 14:24:01 +00:00
// Start logging/capturing text output to given file
2019-02-23 14:39:18 +00:00
void ImGui : : LogToFile ( int auto_open_depth , const char * filename )
2018-08-30 13:51:14 +00:00
{
ImGuiContext & g = * GImGui ;
if ( g . LogEnabled )
return ;
2019-03-16 14:48:21 +00:00
// FIXME: We could probably open the file in text mode "at", however note that clipboard/buffer logging will still
2019-02-23 15:22:55 +00:00
// 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.
2018-08-30 13:51:14 +00:00
if ( ! filename )
filename = g . IO . LogFilename ;
2019-02-23 14:24:01 +00:00
if ( ! filename | | ! filename [ 0 ] )
return ;
2019-11-19 20:14:44 +00:00
ImFileHandle f = ImFileOpen ( filename , " ab " ) ;
if ( ! f )
2018-08-30 13:51:14 +00:00
{
2019-02-06 12:08:30 +00:00
IM_ASSERT ( 0 ) ;
2018-08-30 13:51:14 +00:00
return ;
}
2019-02-23 15:22:55 +00:00
LogBegin ( ImGuiLogType_File , auto_open_depth ) ;
g . LogFile = f ;
2018-08-30 13:51:14 +00:00
}
2019-02-23 14:24:01 +00:00
// Start logging/capturing text output to clipboard
2019-02-23 14:39:18 +00:00
void ImGui : : LogToClipboard ( int auto_open_depth )
2018-08-30 13:51:14 +00:00
{
ImGuiContext & g = * GImGui ;
if ( g . LogEnabled )
return ;
2019-02-23 15:22:55 +00:00
LogBegin ( ImGuiLogType_Clipboard , auto_open_depth ) ;
2019-02-23 14:24:01 +00:00
}
2019-02-23 14:39:18 +00:00
void ImGui : : LogToBuffer ( int auto_open_depth )
2019-02-23 14:24:01 +00:00
{
ImGuiContext & g = * GImGui ;
if ( g . LogEnabled )
return ;
2019-02-23 15:22:55 +00:00
LogBegin ( ImGuiLogType_Buffer , auto_open_depth ) ;
2018-08-30 13:51:14 +00:00
}
void ImGui : : LogFinish ( )
{
ImGuiContext & g = * GImGui ;
if ( ! g . LogEnabled )
return ;
LogText ( IM_NEWLINE ) ;
2019-02-23 14:24:01 +00:00
switch ( g . LogType )
2018-08-30 13:51:14 +00:00
{
2019-02-23 14:24:01 +00:00
case ImGuiLogType_TTY :
2019-11-19 20:14:44 +00:00
# ifndef IMGUI_DISABLE_TTY_FUNCTIONS
2019-02-23 14:24:01 +00:00
fflush ( g . LogFile ) ;
2019-11-19 20:14:44 +00:00
# endif
2019-02-23 14:24:01 +00:00
break ;
case ImGuiLogType_File :
2019-11-19 20:14:44 +00:00
ImFileClose ( g . LogFile ) ;
2019-02-23 14:24:01 +00:00
break ;
case ImGuiLogType_Buffer :
break ;
case ImGuiLogType_Clipboard :
if ( ! g . LogBuffer . empty ( ) )
SetClipboardText ( g . LogBuffer . begin ( ) ) ;
break ;
2019-02-24 22:19:36 +00:00
case ImGuiLogType_None :
IM_ASSERT ( 0 ) ;
break ;
2018-08-30 13:51:14 +00:00
}
2019-02-23 14:24:01 +00:00
2018-08-30 13:51:14 +00:00
g . LogEnabled = false ;
2019-02-23 14:24:01 +00:00
g . LogType = ImGuiLogType_None ;
g . LogFile = NULL ;
g . LogBuffer . clear ( ) ;
2018-08-30 13:51:14 +00:00
}
// Helper to display logging buttons
2019-02-23 14:24:01 +00:00
// FIXME-OBSOLETE: We should probably obsolete this and let the user have their own helper (this is one of the oldest function alive!)
2018-08-30 13:51:14 +00:00
void ImGui : : LogButtons ( )
{
ImGuiContext & g = * GImGui ;
PushID ( " LogButtons " ) ;
2019-11-19 20:14:44 +00:00
# ifndef IMGUI_DISABLE_TTY_FUNCTIONS
2018-08-30 13:51:14 +00:00
const bool log_to_tty = Button ( " Log To TTY " ) ; SameLine ( ) ;
2019-11-19 20:14:44 +00:00
# else
const bool log_to_tty = false ;
# endif
2018-08-30 13:51:14 +00:00
const bool log_to_file = Button ( " Log To File " ) ; SameLine ( ) ;
const bool log_to_clipboard = Button ( " Log To Clipboard " ) ; SameLine ( ) ;
PushAllowKeyboardFocus ( false ) ;
2019-04-18 16:29:28 +00:00
SetNextItemWidth ( 80.0f ) ;
2019-02-23 14:39:18 +00:00
SliderInt ( " Default Depth " , & g . LogDepthToExpandDefault , 0 , 9 , NULL ) ;
2018-08-30 13:51:14 +00:00
PopAllowKeyboardFocus ( ) ;
PopID ( ) ;
// Start logging at the end of the function so that the buttons don't appear in the log
if ( log_to_tty )
2019-02-23 14:39:18 +00:00
LogToTTY ( ) ;
2018-08-30 13:51:14 +00:00
if ( log_to_file )
2019-02-23 14:39:18 +00:00
LogToFile ( ) ;
2018-08-30 13:51:14 +00:00
if ( log_to_clipboard )
2019-02-23 14:39:18 +00:00
LogToClipboard ( ) ;
2018-08-30 13:51:14 +00:00
}
2018-08-30 13:48:57 +00:00
//-----------------------------------------------------------------------------
2018-09-06 09:35:13 +00:00
// [SECTION] SETTINGS
2018-08-30 13:48:57 +00:00
//-----------------------------------------------------------------------------
void ImGui : : MarkIniSettingsDirty ( )
{
ImGuiContext & g = * GImGui ;
if ( g . SettingsDirtyTimer < = 0.0f )
g . SettingsDirtyTimer = g . IO . IniSavingRate ;
}
void ImGui : : MarkIniSettingsDirty ( ImGuiWindow * window )
{
ImGuiContext & g = * GImGui ;
if ( ! ( window - > Flags & ImGuiWindowFlags_NoSavedSettings ) )
if ( g . SettingsDirtyTimer < = 0.0f )
g . SettingsDirtyTimer = g . IO . IniSavingRate ;
}
2018-09-27 11:01:51 +00:00
ImGuiWindowSettings * ImGui : : CreateNewWindowSettings ( const char * name )
2018-08-30 13:48:57 +00:00
{
ImGuiContext & g = * GImGui ;
2019-11-07 15:05:03 +00:00
2019-07-24 04:26:15 +00:00
# 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 , " ### " ) )
2019-07-12 11:33:24 +00:00
name = p ;
2019-07-24 04:26:15 +00:00
# endif
2019-11-07 15:05:03 +00:00
const size_t name_len = strlen ( name ) ;
// Allocate chunk
const size_t chunk_size = sizeof ( ImGuiWindowSettings ) + name_len + 1 ;
ImGuiWindowSettings * settings = g . SettingsWindows . alloc_chunk ( chunk_size ) ;
IM_PLACEMENT_NEW ( settings ) ImGuiWindowSettings ( ) ;
2019-11-05 21:43:53 +00:00
settings - > ID = ImHashStr ( name , name_len ) ;
2019-11-07 15:05:03 +00:00
memcpy ( settings - > GetName ( ) , name , name_len + 1 ) ; // Store with zero terminator
2018-08-30 13:48:57 +00:00
return settings ;
}
ImGuiWindowSettings * ImGui : : FindWindowSettings ( ImGuiID id )
{
ImGuiContext & g = * GImGui ;
2019-11-07 15:05:03 +00:00
for ( ImGuiWindowSettings * settings = g . SettingsWindows . begin ( ) ; settings ! = NULL ; settings = g . SettingsWindows . next_chunk ( settings ) )
if ( settings - > ID = = id )
return settings ;
2018-08-30 13:48:57 +00:00
return NULL ;
}
2019-02-01 09:26:08 +00:00
ImGuiWindowSettings * ImGui : : FindOrCreateWindowSettings ( const char * name )
{
2019-04-19 17:48:51 +00:00
if ( ImGuiWindowSettings * settings = FindWindowSettings ( ImHashStr ( name ) ) )
2019-02-01 09:26:08 +00:00
return settings ;
return CreateNewWindowSettings ( name ) ;
}
2018-08-30 13:48:57 +00:00
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 ) ;
2019-04-05 18:20:08 +00:00
IM_FREE ( file_data ) ;
2018-08-30 13:48:57 +00:00
}
ImGuiSettingsHandler * ImGui : : FindSettingsHandler ( const char * type_name )
{
ImGuiContext & g = * GImGui ;
2019-04-19 17:48:51 +00:00
const ImGuiID type_hash = ImHashStr ( type_name ) ;
2018-08-30 13:48:57 +00:00
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 ;
}
// Zero-tolerance, no error reporting, cheap .ini parsing
void ImGui : : LoadIniSettingsFromMemory ( const char * ini_data , size_t ini_size )
{
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 ) ;
2019-04-05 18:20:08 +00:00
char * buf = ( char * ) IM_ALLOC ( ini_size + 1 ) ;
2018-08-30 13:48:57 +00:00
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 )
{
// 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 ;
2018-09-05 09:52:48 +00:00
if ( line [ 0 ] = = ' ; ' )
continue ;
2018-08-30 13:48:57 +00:00
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 ;
2019-11-19 14:22:42 +00:00
char * type_end = ( char * ) ( void * ) ImStrchrRange ( type_start , name_end , ' ] ' ) ;
2018-08-30 13:48:57 +00:00
const char * name_start = type_end ? ImStrchrRange ( type_end + 1 , name_end , ' [ ' ) : NULL ;
if ( ! type_end | | ! name_start )
2019-11-19 14:22:42 +00:00
continue ;
* type_end = 0 ; // Overwrite first ']'
name_start + + ; // Skip second '['
2018-08-30 13:48:57 +00:00
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 ) ;
}
}
2019-04-05 18:20:08 +00:00
IM_FREE ( buf ) ;
2018-08-30 13:48:57 +00:00
g . SettingsLoaded = true ;
}
void ImGui : : SaveIniSettingsToDisk ( const char * ini_filename )
{
ImGuiContext & g = * GImGui ;
g . SettingsDirtyTimer = 0.0f ;
if ( ! ini_filename )
return ;
size_t ini_data_size = 0 ;
const char * ini_data = SaveIniSettingsToMemory ( & ini_data_size ) ;
2019-11-19 20:14:44 +00:00
ImFileHandle f = ImFileOpen ( ini_filename , " wt " ) ;
2018-08-30 13:48:57 +00:00
if ( ! f )
return ;
2019-11-19 20:14:44 +00:00
ImFileWrite ( ini_data , sizeof ( char ) , ini_data_size , f ) ;
ImFileClose ( f ) ;
2018-08-30 13:48:57 +00:00
}
// 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 . 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 ( ) ;
}
2019-11-06 21:52:48 +00:00
static void * WindowSettingsHandler_ReadOpen ( ImGuiContext * , ImGuiSettingsHandler * , const char * name )
2018-08-30 13:48:57 +00:00
{
2019-04-19 17:48:51 +00:00
ImGuiWindowSettings * settings = ImGui : : FindWindowSettings ( ImHashStr ( name ) ) ;
2018-08-30 13:48:57 +00:00
if ( ! settings )
2018-09-27 10:59:22 +00:00
settings = ImGui : : CreateNewWindowSettings ( name ) ;
2018-08-30 13:48:57 +00:00
return ( void * ) settings ;
}
2019-11-06 21:52:48 +00:00
static void WindowSettingsHandler_ReadLine ( ImGuiContext * , ImGuiSettingsHandler * , void * entry , const char * line )
2018-08-30 13:48:57 +00:00
{
ImGuiWindowSettings * settings = ( ImGuiWindowSettings * ) entry ;
2019-08-23 09:08:30 +00:00
int x , y ;
2018-08-30 13:48:57 +00:00
int i ;
2019-08-23 09:08:30 +00:00
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 ) ;
2018-08-30 13:48:57 +00:00
else if ( sscanf ( line , " Collapsed=%d " , & i ) = = 1 ) settings - > Collapsed = ( i ! = 0 ) ;
}
2019-11-06 21:52:48 +00:00
static void WindowSettingsHandler_WriteAll ( ImGuiContext * ctx , ImGuiSettingsHandler * handler , ImGuiTextBuffer * buf )
2018-08-30 13:48:57 +00:00
{
// Gather data from windows that were active during this session
2018-09-05 09:52:48 +00:00
// (if a window wasn't opened in this session we preserve its settings)
2019-04-27 15:11:06 +00:00
ImGuiContext & g = * ctx ;
2018-08-30 13:48:57 +00:00
for ( int i = 0 ; i ! = g . Windows . Size ; i + + )
{
ImGuiWindow * window = g . Windows [ i ] ;
if ( window - > Flags & ImGuiWindowFlags_NoSavedSettings )
continue ;
2019-11-07 15:05:03 +00:00
ImGuiWindowSettings * settings = ( window - > SettingsOffset ! = - 1 ) ? g . SettingsWindows . ptr_from_offset ( window - > SettingsOffset ) : ImGui : : FindWindowSettings ( window - > ID ) ;
2018-08-30 13:48:57 +00:00
if ( ! settings )
{
2018-09-27 10:59:22 +00:00
settings = ImGui : : CreateNewWindowSettings ( window - > Name ) ;
2019-11-07 15:05:03 +00:00
window - > SettingsOffset = g . SettingsWindows . offset_from_ptr ( settings ) ;
2018-08-30 13:48:57 +00:00
}
IM_ASSERT ( settings - > ID = = window - > ID ) ;
2019-08-23 09:08:30 +00:00
settings - > Pos = ImVec2ih ( ( short ) window - > Pos . x , ( short ) window - > Pos . y ) ;
settings - > Size = ImVec2ih ( ( short ) window - > SizeFull . x , ( short ) window - > SizeFull . y ) ;
2018-08-30 13:48:57 +00:00
settings - > Collapsed = window - > Collapsed ;
}
2018-09-05 09:52:48 +00:00
// Write to text buffer
2019-11-07 15:05:03 +00:00
buf - > reserve ( buf - > size ( ) + g . SettingsWindows . size ( ) * 6 ) ; // ballpark reserve
for ( ImGuiWindowSettings * settings = g . SettingsWindows . begin ( ) ; settings ! = NULL ; settings = g . SettingsWindows . next_chunk ( settings ) )
2018-08-30 13:48:57 +00:00
{
2019-11-07 15:05:03 +00:00
const char * settings_name = settings - > GetName ( ) ;
2019-11-05 21:43:53 +00:00
buf - > appendf ( " [%s][%s] \n " , handler - > TypeName , settings_name ) ;
2019-08-23 09:08:30 +00:00
buf - > appendf ( " Pos=%d,%d \n " , settings - > Pos . x , settings - > Pos . y ) ;
buf - > appendf ( " Size=%d,%d \n " , settings - > Size . x , settings - > Size . y ) ;
2018-08-30 13:48:57 +00:00
buf - > appendf ( " Collapsed=%d \n " , settings - > Collapsed ) ;
2019-11-06 21:52:48 +00:00
buf - > append ( " \n " ) ;
2018-08-30 13:48:57 +00:00
}
}
2019-03-08 16:33:44 +00:00
//-----------------------------------------------------------------------------
// [SECTION] VIEWPORTS, PLATFORM WINDOWS
//-----------------------------------------------------------------------------
// (this section is filled in the 'docking' branch)
//-----------------------------------------------------------------------------
// [SECTION] DOCKING
//-----------------------------------------------------------------------------
// (this section is filled in the 'docking' branch)
2014-08-10 20:58:11 +00:00
//-----------------------------------------------------------------------------
2018-09-06 09:35:13 +00:00
// [SECTION] PLATFORM DEPENDENT HELPERS
2014-08-10 20:58:11 +00:00
//-----------------------------------------------------------------------------
2018-11-05 16:12:13 +00:00
# if defined(_WIN32) && !defined(_WINDOWS_) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) && (!defined(IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS) || !defined(IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS))
2018-08-09 15:42:53 +00:00
# ifndef WIN32_LEAN_AND_MEAN
2015-07-21 23:00:28 +00:00
# define WIN32_LEAN_AND_MEAN
2018-08-09 15:42:53 +00:00
# endif
2018-01-14 03:31:22 +00:00
# ifndef __MINGW32__
2017-12-23 13:07:03 +00:00
# include <Windows.h>
2018-01-14 03:31:22 +00:00
# else
# include <windows.h>
# endif
2019-11-15 08:51:48 +00:00
# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) // UWP doesn't have Win32 functions
# define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS
# define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS
# endif
2019-05-18 15:34:58 +00:00
# elif defined(__APPLE__)
# include <TargetConditionals.h>
2015-07-21 23:00:28 +00:00
# endif
2015-08-09 16:54:28 +00:00
2018-11-05 16:12:13 +00:00
# if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS)
2015-08-09 16:54:28 +00:00
2015-08-09 15:24:10 +00:00
# ifdef _MSC_VER
2015-07-21 23:00:28 +00:00
# pragma comment(lib, "user32")
2015-08-09 15:24:10 +00:00
# endif
2014-08-10 20:58:11 +00:00
2019-05-18 15:44:09 +00:00
// Win32 clipboard implementation
2016-10-15 09:36:43 +00:00
static const char * GetClipboardTextFn_DefaultImpl ( void * )
2015-03-21 00:41:34 +00:00
{
2016-06-26 11:24:30 +00:00
static ImVector < char > buf_local ;
buf_local . clear ( ) ;
2018-06-13 20:22:52 +00:00
if ( ! : : OpenClipboard ( NULL ) )
2015-07-21 23:00:28 +00:00
return NULL ;
2018-06-13 20:22:52 +00:00
HANDLE wbuf_handle = : : GetClipboardData ( CF_UNICODETEXT ) ;
2015-07-21 23:00:28 +00:00
if ( wbuf_handle = = NULL )
2017-08-05 08:05:48 +00:00
{
2018-06-13 20:22:52 +00:00
: : CloseClipboard ( ) ;
2015-07-21 23:00:28 +00:00
return NULL ;
2017-08-05 08:05:48 +00:00
}
2018-06-13 20:22:52 +00:00
if ( ImWchar * wbuf_global = ( ImWchar * ) : : GlobalLock ( wbuf_handle ) )
2014-08-19 11:09:13 +00:00
{
2015-07-21 23:00:28 +00:00
int buf_len = ImTextCountUtf8BytesFromStr ( wbuf_global , NULL ) + 1 ;
2016-06-26 11:24:30 +00:00
buf_local . resize ( buf_len ) ;
ImTextStrToUtf8 ( buf_local . Data , buf_len , wbuf_global , NULL ) ;
2015-01-31 15:24:55 +00:00
}
2018-06-13 20:22:52 +00:00
: : GlobalUnlock ( wbuf_handle ) ;
: : CloseClipboard ( ) ;
2016-06-26 11:24:30 +00:00
return buf_local . Data ;
2015-07-08 00:19:01 +00:00
}
2016-10-15 09:36:43 +00:00
static void SetClipboardTextFn_DefaultImpl ( void * , const char * text )
2015-07-08 00:19:01 +00:00
{
2018-06-13 20:22:52 +00:00
if ( ! : : OpenClipboard ( NULL ) )
2015-07-08 00:19:01 +00:00
return ;
2015-07-21 23:00:28 +00:00
const int wbuf_length = ImTextCountCharsFromUtf8 ( text , NULL ) + 1 ;
2018-06-13 20:22:52 +00:00
HGLOBAL wbuf_handle = : : GlobalAlloc ( GMEM_MOVEABLE , ( SIZE_T ) wbuf_length * sizeof ( ImWchar ) ) ;
2015-07-21 23:00:28 +00:00
if ( wbuf_handle = = NULL )
2017-10-24 17:25:02 +00:00
{
2018-06-13 20:22:52 +00:00
: : CloseClipboard ( ) ;
2015-01-23 00:38:04 +00:00
return ;
2017-10-24 17:25:02 +00:00
}
2018-06-13 20:22:52 +00:00
ImWchar * wbuf_global = ( ImWchar * ) : : GlobalLock ( wbuf_handle ) ;
2015-07-21 23:00:28 +00:00
ImTextStrFromUtf8 ( wbuf_global , wbuf_length , text , NULL ) ;
2018-06-13 20:22:52 +00:00
: : GlobalUnlock ( wbuf_handle ) ;
: : EmptyClipboard ( ) ;
if ( : : SetClipboardData ( CF_UNICODETEXT , wbuf_handle ) = = NULL )
: : GlobalFree ( wbuf_handle ) ;
: : CloseClipboard ( ) ;
2015-01-23 00:38:04 +00:00
}
2019-07-22 02:06:07 +00:00
# elif defined(__APPLE__) && TARGET_OS_OSX && defined(IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS)
2019-05-18 15:44:09 +00:00
# include <Carbon/Carbon.h> // Use old API to avoid need for separate .mm file
2019-05-18 15:34:58 +00:00
static PasteboardRef main_clipboard = 0 ;
2019-05-18 15:44:09 +00:00
// OSX clipboard implementation
2019-07-22 02:06:07 +00:00
// If you enable this you will need to add '-framework ApplicationServices' to your linker command-line!
2019-05-18 15:34:58 +00:00
static void SetClipboardTextFn_DefaultImpl ( void * , const char * text )
{
if ( ! main_clipboard )
PasteboardCreate ( kPasteboardClipboard , & main_clipboard ) ;
PasteboardClear ( main_clipboard ) ;
2019-05-18 15:44:09 +00:00
CFDataRef cf_data = CFDataCreate ( kCFAllocatorDefault , ( const UInt8 * ) text , strlen ( text ) ) ;
2019-05-18 15:34:58 +00:00
if ( cf_data )
{
2019-05-18 15:44:09 +00:00
PasteboardPutItemFlavor ( main_clipboard , ( PasteboardItemID ) 1 , CFSTR ( " public.utf8-plain-text " ) , cf_data , 0 ) ;
2019-05-18 15:34:58 +00:00
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 ) ;
2019-09-17 07:21:09 +00:00
for ( ItemCount i = 0 ; i < item_count ; i + + )
2019-05-18 15:34:58 +00:00
{
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 < char > clipboard_text ;
2019-05-18 15:44:09 +00:00
int length = ( int ) CFDataGetLength ( cf_data ) ;
2019-05-18 15:34:58 +00:00
clipboard_text . resize ( length + 1 ) ;
2019-05-18 15:44:09 +00:00
CFDataGetBytes ( cf_data , CFRangeMake ( 0 , length ) , ( UInt8 * ) clipboard_text . Data ) ;
2019-05-18 15:34:58 +00:00
clipboard_text [ length ] = 0 ;
CFRelease ( cf_data ) ;
return clipboard_text . Data ;
}
}
}
2019-05-18 15:44:09 +00:00
return NULL ;
2019-05-18 15:34:58 +00:00
}
2015-07-21 23:00:28 +00:00
# else
2014-12-30 16:49:39 +00:00
2019-05-18 15:44:09 +00:00
// Local Dear ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers.
2016-10-15 09:36:43 +00:00
static const char * GetClipboardTextFn_DefaultImpl ( void * )
2015-07-21 23:00:28 +00:00
{
2016-07-30 08:02:46 +00:00
ImGuiContext & g = * GImGui ;
return g . PrivateClipboard . empty ( ) ? NULL : g . PrivateClipboard . begin ( ) ;
2015-07-21 23:00:28 +00:00
}
2014-11-23 23:35:26 +00:00
2016-10-15 09:36:43 +00:00
static void SetClipboardTextFn_DefaultImpl ( void * , const char * text )
2015-07-21 23:00:28 +00:00
{
2016-05-07 17:55:51 +00:00
ImGuiContext & g = * GImGui ;
2016-07-30 08:02:46 +00:00
g . PrivateClipboard . clear ( ) ;
2015-07-21 23:00:28 +00:00
const char * text_end = text + strlen ( text ) ;
2017-08-31 20:04:40 +00:00
g . PrivateClipboard . resize ( ( int ) ( text_end - text ) + 1 ) ;
2016-07-30 08:02:46 +00:00
memcpy ( & g . PrivateClipboard [ 0 ] , text , ( size_t ) ( text_end - text ) ) ;
2015-07-21 23:00:28 +00:00
g . PrivateClipboard [ ( int ) ( text_end - text ) ] = 0 ;
}
2014-12-30 16:49:39 +00:00
2015-07-21 23:00:28 +00:00
# endif
2014-12-30 16:49:39 +00:00
2015-08-09 16:54:28 +00:00
// Win32 API IME support (for Asian languages, etc.)
2019-05-18 15:44:09 +00:00
# if defined(_WIN32) && !defined(__GNUC__) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS)
2014-12-30 16:49:39 +00:00
2015-08-09 15:24:10 +00:00
# include <imm.h>
# ifdef _MSC_VER
2015-07-21 23:00:28 +00:00
# pragma comment(lib, "imm32")
2015-08-09 15:24:10 +00:00
# endif
2014-12-30 16:49:39 +00:00
2015-07-21 23:00:28 +00:00
static void ImeSetInputScreenPosFn_DefaultImpl ( int x , int y )
{
// Notify OS Input Method Editor of text input position
2019-07-30 23:48:15 +00:00
ImGuiIO & io = ImGui : : GetIO ( ) ;
if ( HWND hwnd = ( HWND ) io . ImeWindowHandle )
2018-06-13 20:22:52 +00:00
if ( HIMC himc = : : ImmGetContext ( hwnd ) )
2014-12-30 16:49:39 +00:00
{
2015-07-21 23:00:28 +00:00
COMPOSITIONFORM cf ;
cf . ptCurrentPos . x = x ;
cf . ptCurrentPos . y = y ;
cf . dwStyle = CFS_FORCE_POSITION ;
2018-06-13 20:22:52 +00:00
: : ImmSetCompositionWindow ( himc , & cf ) ;
2018-07-08 13:24:12 +00:00
: : ImmReleaseContext ( hwnd , himc ) ;
2014-12-30 16:49:39 +00:00
}
2015-07-21 23:00:28 +00:00
}
2014-12-30 16:49:39 +00:00
2015-07-21 23:00:28 +00:00
# else
2014-12-30 16:49:39 +00:00
2015-07-21 23:00:28 +00:00
static void ImeSetInputScreenPosFn_DefaultImpl ( int , int ) { }
2014-12-30 16:49:39 +00:00
2015-07-21 23:00:28 +00:00
# endif
2014-12-30 16:49:39 +00:00
2015-07-21 23:00:28 +00:00
//-----------------------------------------------------------------------------
2018-09-06 09:35:13 +00:00
// [SECTION] METRICS/DEBUG WINDOW
2015-07-21 23:00:28 +00:00
//-----------------------------------------------------------------------------
2014-12-30 16:49:39 +00:00
2019-07-01 16:48:21 +00:00
# ifndef IMGUI_DISABLE_METRICS_WINDOW
2019-11-13 21:04:16 +00:00
// Avoid naming collision with imgui_demo.cpp's HelpMarker() for unity builds.
static void MetricsHelpMarker ( const char * desc )
2019-11-11 13:47:39 +00:00
{
ImGui : : TextDisabled ( " (?) " ) ;
if ( ImGui : : IsItemHovered ( ) )
{
ImGui : : BeginTooltip ( ) ;
ImGui : : PushTextWrapPos ( ImGui : : GetFontSize ( ) * 35.0f ) ;
ImGui : : TextUnformatted ( desc ) ;
ImGui : : PopTextWrapPos ( ) ;
ImGui : : EndTooltip ( ) ;
}
}
2016-05-02 10:32:16 +00:00
void ImGui : : ShowMetricsWindow ( bool * p_open )
2015-07-21 23:00:28 +00:00
{
2019-05-27 15:28:18 +00:00
if ( ! ImGui : : Begin ( " Dear ImGui Metrics " , p_open ) )
2018-09-06 09:05:23 +00:00
{
ImGui : : End ( ) ;
return ;
}
2018-12-11 10:58:15 +00:00
2019-07-23 18:50:41 +00:00
// State
2019-10-31 10:15:40 +00:00
enum { WRT_OuterRect , WRT_OuterRectClipped , WRT_InnerRect , WRT_InnerClipRect , WRT_WorkRect , WRT_Content , WRT_ContentRegionRect , WRT_Count } ; // Windows Rect Type
const char * wrt_rects_names [ WRT_Count ] = { " OuterRect " , " OuterRectClipped " , " InnerRect " , " InnerClipRect " , " WorkRect " , " Content " , " ContentRegionRect " } ;
2019-04-16 20:02:30 +00:00
static bool show_windows_rects = false ;
2019-07-01 16:48:21 +00:00
static int show_windows_rect_type = WRT_WorkRect ;
2019-07-23 18:50:41 +00:00
static bool show_windows_begin_order = false ;
2019-11-25 11:01:04 +00:00
static bool show_drawcmd_details = true ;
2019-04-16 20:02:30 +00:00
2019-07-23 18:50:41 +00:00
// Basic info
ImGuiContext & g = * GImGui ;
2018-09-06 09:05:23 +00:00
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 ) ;
2019-04-16 20:02:30 +00:00
ImGui : : Text ( " %d active allocations " , io . MetricsActiveAllocations ) ;
2018-09-06 09:05:23 +00:00
ImGui : : Separator ( ) ;
2014-12-30 16:49:39 +00:00
2019-07-23 18:50:41 +00:00
// Helper functions to display common structures:
// - NodeDrawList
// - NodeColumns
// - NodeWindow
// - NodeWindows
// - NodeTabBar
2018-09-06 09:05:23 +00:00
struct Funcs
{
2019-07-01 16:48:21 +00:00
static ImRect GetWindowRect ( ImGuiWindow * window , int rect_type )
2019-05-27 20:41:17 +00:00
{
2019-07-01 16:48:21 +00:00
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 ; }
2019-10-31 10:15:40 +00:00
else if ( rect_type = = WRT_Content ) { ImVec2 min = window - > InnerRect . Min - window - > Scroll + window - > WindowPadding ; return ImRect ( min , min + window - > ContentSize ) ; }
else if ( rect_type = = WRT_ContentRegionRect ) { return window - > ContentRegionRect ; }
2019-05-27 20:41:17 +00:00
IM_ASSERT ( 0 ) ;
return ImRect ( ) ;
}
2018-09-06 09:05:23 +00:00
static void NodeDrawList ( ImGuiWindow * window , 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 ( ) )
2015-07-21 23:00:28 +00:00
{
2018-09-06 09:05:23 +00:00
ImGui : : SameLine ( ) ;
2019-02-14 13:00:30 +00:00
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)
2018-09-06 09:05:23 +00:00
if ( node_open ) ImGui : : TreePop ( ) ;
return ;
2014-12-30 16:49:39 +00:00
}
2014-11-07 08:22:38 +00:00
2019-03-04 15:20:32 +00:00
ImDrawList * fg_draw_list = GetForegroundDrawList ( window ) ; // Render additional visuals into the top-most draw list
2018-09-06 09:05:23 +00:00
if ( window & & IsItemHovered ( ) )
2019-03-04 15:20:32 +00:00
fg_draw_list - > AddRect ( window - > Pos , window - > Pos + window - > Size , IM_COL32 ( 255 , 255 , 0 , 255 ) ) ;
2018-09-06 09:05:23 +00:00
if ( ! node_open )
return ;
2019-07-26 19:08:29 +00:00
if ( window & & ! window - > WasActive )
2019-11-25 11:01:04 +00:00
ImGui : : TextDisabled ( " Warning: owning Window is inactive. This DrawList is not being rendered! " ) ;
2019-07-26 19:08:29 +00:00
2019-11-22 11:22:03 +00:00
unsigned int elem_offset = 0 ;
2018-09-06 09:05:23 +00:00
for ( const ImDrawCmd * pcmd = draw_list - > CmdBuffer . begin ( ) ; pcmd < draw_list - > CmdBuffer . end ( ) ; elem_offset + = pcmd - > ElemCount , pcmd + + )
2015-05-29 09:29:26 +00:00
{
2018-09-06 09:05:23 +00:00
if ( pcmd - > UserCallback = = NULL & & pcmd - > ElemCount = = 0 )
continue ;
if ( pcmd - > UserCallback )
2018-03-04 15:06:43 +00:00
{
2018-09-06 09:05:23 +00:00
ImGui : : BulletText ( " Callback %p, user_data %p " , pcmd - > UserCallback , pcmd - > UserCallbackData ) ;
continue ;
}
2019-11-22 11:22:03 +00:00
2018-09-06 09:05:23 +00:00
ImDrawIdx * idx_buffer = ( draw_list - > IdxBuffer . Size > 0 ) ? draw_list - > IdxBuffer . Data : NULL ;
2019-05-29 13:25:53 +00:00
char buf [ 300 ] ;
2019-11-25 11:01:04 +00:00
ImFormatString ( buf , IM_ARRAYSIZE ( buf ) , " DrawCmd: %4d triangles, Tex 0x%p, ClipRect (%4.0f,%4.0f)-(%4.0f,%4.0f) " ,
pcmd - > ElemCount / 3 , ( void * ) ( intptr_t ) pcmd - > TextureId ,
2019-11-22 11:22:03 +00:00
pcmd - > ClipRect . x , pcmd - > ClipRect . y , pcmd - > ClipRect . z , pcmd - > ClipRect . w ) ;
2019-05-29 13:25:53 +00:00
bool pcmd_node_open = ImGui : : TreeNode ( ( void * ) ( pcmd - draw_list - > CmdBuffer . begin ( ) ) , " %s " , buf ) ;
2019-11-25 11:01:04 +00:00
if ( show_drawcmd_details & & fg_draw_list & & ImGui : : IsItemHovered ( ) )
2018-09-06 09:05:23 +00:00
{
ImRect clip_rect = pcmd - > ClipRect ;
2019-12-12 18:56:29 +00:00
ImRect vtxs_rect ( FLT_MAX , FLT_MAX , - FLT_MAX , - FLT_MAX ) ;
2019-11-22 11:22:03 +00:00
for ( unsigned int i = elem_offset ; i < elem_offset + ( int ) pcmd - > ElemCount ; i + + )
2018-09-06 09:05:23 +00:00
vtxs_rect . Add ( draw_list - > VtxBuffer [ idx_buffer ? idx_buffer [ i ] : i ] . pos ) ;
2019-11-25 11:01:04 +00:00
fg_draw_list - > AddRect ( ImFloor ( clip_rect . Min ) , ImFloor ( clip_rect . Max ) , IM_COL32 ( 255 , 0 , 255 , 255 ) ) ;
fg_draw_list - > AddRect ( ImFloor ( vtxs_rect . Min ) , ImFloor ( vtxs_rect . Max ) , IM_COL32 ( 255 , 255 , 0 , 255 ) ) ;
2018-09-06 09:05:23 +00:00
}
if ( ! pcmd_node_open )
continue ;
2019-11-25 11:01:04 +00:00
// Calculate approximate coverage area (touched pixel count)
// This will be in pixels squared as long there's no post-scaling happening to the renderer output.
float total_area = 0.0f ;
for ( unsigned int base_idx = elem_offset ; base_idx < ( elem_offset + pcmd - > ElemCount ) ; base_idx + = 3 )
2019-11-22 11:22:03 +00:00
{
2019-11-25 11:01:04 +00:00
ImVec2 triangle [ 3 ] ;
for ( int n = 0 ; n < 3 ; n + + )
triangle [ n ] = draw_list - > VtxBuffer [ idx_buffer ? idx_buffer [ base_idx + n ] : ( base_idx + n ) ] . pos ;
total_area + = ImTriangleArea ( triangle [ 0 ] , triangle [ 1 ] , triangle [ 2 ] ) ;
}
2019-11-22 11:22:03 +00:00
2019-11-25 11:01:04 +00:00
// Display vertex information summary. Hover to get all triangles drawn in wire-frame
ImFormatString ( buf , IM_ARRAYSIZE ( buf ) , " Mesh: ElemCount: %d, VtxOffset: +%d, IdxOffset: +%d, Area: ~%0.f px " , pcmd - > ElemCount , pcmd - > VtxOffset , pcmd - > IdxOffset , total_area ) ;
ImGui : : Selectable ( buf ) ;
if ( fg_draw_list & & ImGui : : IsItemHovered ( ) & & show_drawcmd_details )
{
// Draw wire-frame version of everything
2019-11-22 11:22:03 +00:00
ImDrawListFlags backup_flags = fg_draw_list - > Flags ;
2019-11-25 11:01:04 +00:00
fg_draw_list - > Flags & = ~ ImDrawListFlags_AntiAliasedLines ; // Disable AA on triangle outlines is more readable for very large and thin triangles.
ImRect clip_rect = pcmd - > ClipRect ;
fg_draw_list - > AddRect ( ImFloor ( clip_rect . Min ) , ImFloor ( clip_rect . Max ) , IM_COL32 ( 255 , 0 , 255 , 255 ) ) ;
2019-11-22 11:22:03 +00:00
for ( unsigned int base_idx = elem_offset ; base_idx < ( elem_offset + pcmd - > ElemCount ) ; base_idx + = 3 )
{
2019-11-25 11:01:04 +00:00
ImVec2 triangle [ 3 ] ;
2019-11-22 11:22:03 +00:00
for ( int n = 0 ; n < 3 ; n + + )
2019-11-25 11:01:04 +00:00
triangle [ n ] = draw_list - > VtxBuffer [ idx_buffer ? idx_buffer [ base_idx + n ] : ( base_idx + n ) ] . pos ;
fg_draw_list - > AddPolyline ( triangle , 3 , IM_COL32 ( 255 , 255 , 0 , 255 ) , true , 1.0f ) ;
2019-11-22 11:22:03 +00:00
}
fg_draw_list - > Flags = backup_flags ;
}
2018-09-06 09:05:23 +00:00
// Display individual triangles/vertices. Hover on to get the corresponding triangle highlighted.
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 ( ) )
2019-02-04 13:38:35 +00:00
for ( int prim = clipper . DisplayStart , idx_i = elem_offset + clipper . DisplayStart * 3 ; prim < clipper . DisplayEnd ; prim + + )
2018-03-04 15:06:43 +00:00
{
2018-09-06 09:05:23 +00:00
char * buf_p = buf , * buf_end = buf + IM_ARRAYSIZE ( buf ) ;
2019-11-25 11:01:04 +00:00
ImVec2 triangle [ 3 ] ;
2019-02-04 13:38:35 +00:00
for ( int n = 0 ; n < 3 ; n + + , idx_i + + )
2018-09-06 09:05:23 +00:00
{
2019-11-25 11:01:04 +00:00
ImDrawVert & v = draw_list - > VtxBuffer [ idx_buffer ? idx_buffer [ idx_i ] : idx_i ] ;
triangle [ n ] = v . pos ;
2019-02-04 13:38:35 +00:00
buf_p + = ImFormatString ( buf_p , buf_end - buf_p , " %s %04d: pos (%8.2f,%8.2f), uv (%.6f,%.6f), col %08X \n " ,
2019-11-25 11:01:04 +00:00
( n = = 0 ) ? " Vert: " : " " , idx_i , v . pos . x , v . pos . y , v . uv . x , v . uv . y , v . col ) ;
2018-09-06 09:05:23 +00:00
}
2019-11-22 11:22:03 +00:00
2018-09-06 09:05:23 +00:00
ImGui : : Selectable ( buf , false ) ;
2019-04-16 11:07:43 +00:00
if ( fg_draw_list & & ImGui : : IsItemHovered ( ) )
2018-03-04 15:06:43 +00:00
{
2019-03-04 15:20:32 +00:00
ImDrawListFlags backup_flags = fg_draw_list - > Flags ;
2019-11-25 11:01:04 +00:00
fg_draw_list - > Flags & = ~ ImDrawListFlags_AntiAliasedLines ; // Disable AA on triangle outlines is more readable for very large and thin triangles.
fg_draw_list - > AddPolyline ( triangle , 3 , IM_COL32 ( 255 , 255 , 0 , 255 ) , true , 1.0f ) ;
2019-03-04 15:20:32 +00:00
fg_draw_list - > Flags = backup_flags ;
2018-03-04 15:06:43 +00:00
}
}
2015-07-21 23:00:28 +00:00
ImGui : : TreePop ( ) ;
2015-05-29 09:29:26 +00:00
}
2018-09-06 09:05:23 +00:00
ImGui : : TreePop ( ) ;
}
2015-05-29 09:29:26 +00:00
2019-04-16 20:02:30 +00:00
static void NodeColumns ( const ImGuiColumns * columns )
{
if ( ! ImGui : : TreeNode ( ( void * ) ( uintptr_t ) columns - > ID , " Columns Id: 0x%08X, Count: %d, Flags: 0x%04X " , columns - > ID , columns - > Count , columns - > Flags ) )
return ;
2019-05-09 10:56:03 +00:00
ImGui : : BulletText ( " Width: %.1f (MinX: %.1f, MaxX: %.1f) " , columns - > OffMaxX - columns - > OffMinX , columns - > OffMinX , columns - > OffMaxX ) ;
2019-04-16 20:02:30 +00:00
for ( int column_n = 0 ; column_n < columns - > Columns . Size ; column_n + + )
2019-07-17 21:02:45 +00:00
ImGui : : BulletText ( " Column %02d: OffsetNorm %.3f (= %.1f px) " , column_n , columns - > Columns [ column_n ] . OffsetNorm , GetColumnOffsetFromNorm ( columns , columns - > Columns [ column_n ] . OffsetNorm ) ) ;
2019-04-16 20:02:30 +00:00
ImGui : : TreePop ( ) ;
}
2018-09-06 09:05:23 +00:00
static void NodeWindows ( ImVector < ImGuiWindow * > & windows , const char * label )
2015-05-29 09:29:26 +00:00
{
2018-09-06 09:05:23 +00:00
if ( ! ImGui : : TreeNode ( label , " %s (%d) " , label , windows . Size ) )
return ;
for ( int i = 0 ; i < windows . Size ; i + + )
Funcs : : NodeWindow ( windows [ i ] , " Window " ) ;
2015-07-21 23:00:28 +00:00
ImGui : : TreePop ( ) ;
2015-01-08 23:35:01 +00:00
}
2018-09-06 09:05:23 +00:00
static void NodeWindow ( ImGuiWindow * window , const char * label )
2015-07-21 23:00:28 +00:00
{
2019-07-24 04:26:15 +00:00
if ( window = = NULL )
{
ImGui : : BulletText ( " %s: NULL " , label ) ;
return ;
}
2019-11-08 18:00:49 +00:00
bool open = ImGui : : TreeNode ( window , " %s '%s', %d @ 0x%p " , label , window - > Name , ( window - > Active | | window - > WasActive ) , window ) ;
if ( ImGui : : IsItemHovered ( ) & & window - > WasActive )
ImGui : : GetForegroundDrawList ( ) - > AddRect ( window - > Pos , window - > Pos + window - > Size , IM_COL32 ( 255 , 255 , 0 , 255 ) ) ;
if ( ! open )
2018-09-06 09:05:23 +00:00
return ;
ImGuiWindowFlags flags = window - > Flags ;
NodeDrawList ( window , window - > DrawList , " DrawList " ) ;
2019-06-03 14:55:48 +00:00
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 ) ;
2018-10-15 16:23:18 +00:00
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 " : " " ) ;
2019-11-08 18:00:49 +00:00
ImGui : : BulletText ( " Scroll: (%.2f/%.2f,%.2f/%.2f) Scrollbar:%s%s " , window - > Scroll . x , window - > ScrollMax . x , window - > Scroll . y , window - > ScrollMax . y , window - > ScrollbarX ? " X " : " " , window - > ScrollbarY ? " Y " : " " ) ;
2018-09-06 09:05:23 +00:00
ImGui : : BulletText ( " Active: %d/%d, WriteAccessed: %d, BeginOrderWithinContext: %d " , window - > Active , window - > WasActive , window - > WriteAccessed , ( window - > Active | | window - > WasActive ) ? window - > BeginOrderWithinContext : - 1 ) ;
2019-03-28 14:41:49 +00:00
ImGui : : BulletText ( " Appearing: %d, Hidden: %d (CanSkip %d Cannot %d), SkipItems: %d " , window - > Appearing , window - > Hidden , window - > HiddenFramesCanSkipItems , window - > HiddenFramesCannotSkipItems , window - > SkipItems ) ;
2018-09-06 09:05:23 +00:00
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 ( ) )
ImGui : : BulletText ( " NavRectRel[0]: (%.1f,%.1f)(%.1f,%.1f) " , window - > NavRectRel [ 0 ] . Min . x , window - > NavRectRel [ 0 ] . Min . y , window - > NavRectRel [ 0 ] . Max . x , window - > NavRectRel [ 0 ] . Max . y ) ;
else
ImGui : : BulletText ( " NavRectRel[0]: <None> " ) ;
if ( window - > RootWindow ! = window ) NodeWindow ( window - > RootWindow , " RootWindow " ) ;
if ( window - > ParentWindow ! = NULL ) NodeWindow ( window - > ParentWindow , " ParentWindow " ) ;
if ( window - > DC . ChildWindows . Size > 0 ) NodeWindows ( window - > DC . ChildWindows , " ChildWindows " ) ;
if ( window - > ColumnsStorage . Size > 0 & & ImGui : : TreeNode ( " Columns " , " Columns sets (%d) " , window - > ColumnsStorage . Size ) )
2015-07-21 23:00:28 +00:00
{
2018-09-06 09:05:23 +00:00
for ( int n = 0 ; n < window - > ColumnsStorage . Size ; n + + )
2019-04-16 20:02:30 +00:00
NodeColumns ( & window - > ColumnsStorage [ n ] ) ;
2018-09-06 09:05:23 +00:00
ImGui : : TreePop ( ) ;
2015-01-08 23:35:01 +00:00
}
2019-10-31 13:01:35 +00:00
NodeStorage ( & window - > StateStorage , " Storage " ) ;
2015-07-21 23:00:28 +00:00
ImGui : : TreePop ( ) ;
2015-08-25 11:22:30 +00:00
}
2018-12-11 11:36:47 +00:00
static void NodeTabBar ( ImGuiTabBar * tab_bar )
{
2019-01-27 14:27:49 +00:00
// Standalone tab bars (not associated to docking/windows functionality) currently hold no discernible strings.
2018-12-11 11:36:47 +00:00
char buf [ 256 ] ;
char * p = buf ;
const char * buf_end = buf + IM_ARRAYSIZE ( buf ) ;
2019-01-27 14:27:49 +00:00
ImFormatString ( p , buf_end - p , " TabBar (%d tabs)%s " , tab_bar - > Tabs . Size , ( tab_bar - > PrevFrameVisible < ImGui : : GetFrameCount ( ) - 2 ) ? " *Inactive* " : " " ) ;
2018-12-11 11:36:47 +00:00
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 ( ) ;
2019-11-22 09:56:23 +00:00
ImGui : : Text ( " %02d%c Tab 0x%08X '%s' " , tab_n , ( tab - > ID = = tab_bar - > SelectedTabId ) ? ' * ' : ' ' , tab - > ID , ( tab - > NameOffset ! = - 1 ) ? tab_bar - > GetTabName ( tab ) : " " ) ;
2018-12-11 11:36:47 +00:00
ImGui : : PopID ( ) ;
}
ImGui : : TreePop ( ) ;
}
}
2019-10-31 13:01:35 +00:00
static void NodeStorage ( ImGuiStorage * storage , const char * label )
{
if ( ! ImGui : : TreeNode ( label , " %s: %d entries, %d bytes " , label , storage - > Data . Size , storage - > Data . size_in_bytes ( ) ) )
return ;
for ( int n = 0 ; n < storage - > Data . Size ; n + + )
{
const ImGuiStorage : : ImGuiStoragePair & p = storage - > Data [ n ] ;
ImGui : : BulletText ( " Key 0x%08X Value { i: %d } " , p . key , p . val_i ) ; // Important: we currently don't store a type, real value may not be integer.
}
ImGui : : TreePop ( ) ;
}
2018-09-06 09:05:23 +00:00
} ;
Funcs : : NodeWindows ( g . Windows , " Windows " ) ;
2019-11-08 18:00:49 +00:00
if ( ImGui : : TreeNode ( " DrawLists " , " Active DrawLists (%d) " , g . DrawDataBuilder . Layers [ 0 ] . Size ) )
2018-09-06 09:05:23 +00:00
{
for ( int i = 0 ; i < g . DrawDataBuilder . Layers [ 0 ] . Size ; i + + )
Funcs : : NodeDrawList ( NULL , g . DrawDataBuilder . Layers [ 0 ] [ i ] , " DrawList " ) ;
ImGui : : TreePop ( ) ;
}
2019-04-16 20:02:30 +00:00
2018-09-06 09:05:23 +00:00
if ( ImGui : : TreeNode ( " Popups " , " Popups (%d) " , g . OpenPopupStack . Size ) )
{
for ( int i = 0 ; i < g . OpenPopupStack . Size ; i + + )
2015-08-25 11:40:40 +00:00
{
2018-09-06 09:05:23 +00:00
ImGuiWindow * window = g . OpenPopupStack [ i ] . Window ;
ImGui : : BulletText ( " PopupID: %08x, Window: '%s'%s%s " , g . OpenPopupStack [ i ] . PopupId , window ? window - > Name : " NULL " , window & & ( window - > Flags & ImGuiWindowFlags_ChildWindow ) ? " ChildWindow " : " " , window & & ( window - > Flags & ImGuiWindowFlags_ChildMenu ) ? " ChildMenu " : " " ) ;
2015-01-08 23:35:01 +00:00
}
2018-09-06 09:05:23 +00:00
ImGui : : TreePop ( ) ;
}
2019-04-16 20:02:30 +00:00
2019-11-07 14:01:19 +00:00
if ( ImGui : : TreeNode ( " TabBars " , " Tab Bars (%d) " , g . TabBars . GetSize ( ) ) )
2018-12-11 11:36:47 +00:00
{
2019-11-07 14:01:19 +00:00
for ( int n = 0 ; n < g . TabBars . GetSize ( ) ; n + + )
2018-12-11 11:36:47 +00:00
Funcs : : NodeTabBar ( g . TabBars . GetByIndex ( n ) ) ;
ImGui : : TreePop ( ) ;
}
2019-04-16 20:02:30 +00:00
2019-07-23 18:50:41 +00:00
#if 0
if ( ImGui : : TreeNode ( " Docking " ) )
{
ImGui : : TreePop ( ) ;
}
# endif
#if 0
2019-11-07 14:01:19 +00:00
if ( ImGui : : TreeNode ( " Tables " , " Tables (%d) " , g . Tables . GetSize ( ) ) )
2019-07-23 18:50:41 +00:00
{
ImGui : : TreePop ( ) ;
}
# endif
2018-09-06 09:05:23 +00:00
if ( ImGui : : TreeNode ( " Internal state " ) )
{
const char * input_source_names [ ] = { " None " , " Mouse " , " Nav " , " NavKeyboard " , " NavGamepad " } ; IM_ASSERT ( IM_ARRAYSIZE ( input_source_names ) = = ImGuiInputSource_COUNT ) ;
ImGui : : Text ( " HoveredWindow: '%s' " , g . HoveredWindow ? g . HoveredWindow - > Name : " NULL " ) ;
ImGui : : Text ( " HoveredRootWindow: '%s' " , g . HoveredRootWindow ? g . HoveredRootWindow - > Name : " NULL " ) ;
ImGui : : Text ( " HoveredId: 0x%08X/0x%08X (%.2f sec), AllowOverlap: %d " , g . HoveredId , g . HoveredIdPreviousFrame , g . HoveredIdTimer , g . HoveredIdAllowOverlap ) ; // Data is "in-flight" so depending on when the Metrics window is called we may see current frame information or not
ImGui : : Text ( " ActiveId: 0x%08X/0x%08X (%.2f sec), AllowOverlap: %d, Source: %s " , g . ActiveId , g . ActiveIdPreviousFrame , g . ActiveIdTimer , g . ActiveIdAllowOverlap , input_source_names [ g . ActiveIdSource ] ) ;
ImGui : : Text ( " ActiveIdWindow: '%s' " , g . ActiveIdWindow ? g . ActiveIdWindow - > Name : " NULL " ) ;
ImGui : : Text ( " MovingWindow: '%s' " , g . MovingWindow ? g . MovingWindow - > Name : " NULL " ) ;
ImGui : : Text ( " NavWindow: '%s' " , g . NavWindow ? g . NavWindow - > Name : " NULL " ) ;
ImGui : : Text ( " NavId: 0x%08X, NavLayer: %d " , g . NavId , g . NavLayer ) ;
ImGui : : Text ( " NavInputSource: %s " , input_source_names [ g . NavInputSource ] ) ;
ImGui : : Text ( " NavActive: %d, NavVisible: %d " , g . IO . NavActive , g . IO . NavVisible ) ;
ImGui : : Text ( " NavActivateId: 0x%08X, NavInputId: 0x%08X " , g . NavActivateId , g . NavInputId ) ;
ImGui : : Text ( " NavDisableHighlight: %d, NavDisableMouseHover: %d " , g . NavDisableHighlight , g . NavDisableMouseHover ) ;
ImGui : : Text ( " NavWindowingTarget: '%s' " , g . NavWindowingTarget ? g . NavWindowingTarget - > Name : " NULL " ) ;
ImGui : : Text ( " DragDrop: %d, SourceId = 0x%08X, Payload \" %s \" (%d bytes) " , g . DragDropActive , g . DragDropPayload . SourceId , g . DragDropPayload . DataType , g . DragDropPayload . DataSize ) ;
ImGui : : TreePop ( ) ;
}
2018-07-09 19:06:46 +00:00
2019-04-16 20:02:30 +00:00
if ( ImGui : : TreeNode ( " Tools " ) )
{
2019-07-19 17:48:22 +00:00
// The Item Picker tool is super useful to visually select an item and break into the call-stack of where it was submitted.
2019-07-17 01:25:49 +00:00
if ( ImGui : : Button ( " Item Picker.. " ) )
2019-07-19 17:48:22 +00:00
ImGui : : DebugStartItemPicker ( ) ;
2019-11-11 13:47:39 +00:00
ImGui : : SameLine ( ) ;
2019-11-13 21:04:16 +00:00
MetricsHelpMarker ( " Will call the IM_DEBUG_BREAK() macro to break in debugger. \n Warning: If you don't have a debugger attached, this will probably crash. " ) ;
2019-07-17 01:25:49 +00:00
2019-04-16 20:02:30 +00:00
ImGui : : Checkbox ( " Show windows begin order " , & show_windows_begin_order ) ;
ImGui : : Checkbox ( " Show windows rectangles " , & show_windows_rects ) ;
ImGui : : SameLine ( ) ;
2019-04-18 16:29:28 +00:00
ImGui : : SetNextItemWidth ( ImGui : : GetFontSize ( ) * 12 ) ;
2019-07-01 16:48:21 +00:00
show_windows_rects | = ImGui : : Combo ( " ##show_windows_rect_type " , & show_windows_rect_type , wrt_rects_names , WRT_Count ) ;
2019-05-27 20:41:17 +00:00
if ( show_windows_rects & & g . NavWindow )
{
2019-06-03 14:55:48 +00:00
ImGui : : BulletText ( " '%s': " , g . NavWindow - > Name ) ;
ImGui : : Indent ( ) ;
2019-07-01 16:48:21 +00:00
for ( int rect_n = 0 ; rect_n < WRT_Count ; rect_n + + )
2019-06-03 14:55:48 +00:00
{
2019-07-01 16:48:21 +00:00
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 ] ) ;
2019-06-03 14:55:48 +00:00
}
ImGui : : Unindent ( ) ;
2019-05-27 20:41:17 +00:00
}
2019-11-25 11:01:04 +00:00
ImGui : : Checkbox ( " Show details when hovering ImDrawCmd node " , & show_drawcmd_details ) ;
2019-04-16 20:02:30 +00:00
ImGui : : TreePop ( ) ;
}
2018-07-09 19:06:46 +00:00
2019-07-23 18:50:41 +00:00
// Tool: Display windows Rectangles and Begin Order
2019-04-16 20:02:30 +00:00
if ( show_windows_rects | | show_windows_begin_order )
2018-09-06 09:05:23 +00:00
{
for ( int n = 0 ; n < g . Windows . Size ; n + + )
2018-07-09 19:06:46 +00:00
{
2018-09-06 09:05:23 +00:00
ImGuiWindow * window = g . Windows [ n ] ;
2019-04-17 10:26:51 +00:00
if ( ! window - > WasActive )
2018-09-06 09:05:23 +00:00
continue ;
2019-04-16 20:02:30 +00:00
ImDrawList * draw_list = GetForegroundDrawList ( window ) ;
if ( show_windows_rects )
{
2019-07-01 16:48:21 +00:00
ImRect r = Funcs : : GetWindowRect ( window , show_windows_rect_type ) ;
2019-04-16 20:02:30 +00:00
draw_list - > AddRect ( r . Min , r . Max , IM_COL32 ( 255 , 0 , 128 , 255 ) ) ;
}
2019-04-17 10:26:51 +00:00
if ( show_windows_begin_order & & ! ( window - > Flags & ImGuiWindowFlags_ChildWindow ) )
2019-04-16 20:02:30 +00:00
{
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 ) ;
}
2018-07-09 19:06:46 +00:00
}
2015-01-08 23:35:01 +00:00
}
2015-07-21 23:00:28 +00:00
ImGui : : End ( ) ;
2015-01-08 23:35:01 +00:00
}
2019-07-17 01:25:49 +00:00
2019-07-01 16:48:21 +00:00
# else
2019-07-17 01:25:49 +00:00
void ImGui : : ShowMetricsWindow ( bool * ) { }
2019-07-01 16:48:21 +00:00
# endif
2015-01-08 23:35:01 +00:00
2014-08-10 20:58:11 +00:00
//-----------------------------------------------------------------------------
2014-09-10 10:22:01 +00:00
2015-12-24 15:19:50 +00:00
// Include imgui_user.inl at the end of imgui.cpp to access private data/functions that aren't exposed.
// Prefer just including imgui_internal.h from your code rather than using this define. If a declaration is missing from imgui_internal.h add it or request it on the github.
2014-10-02 10:56:40 +00:00
# ifdef IMGUI_INCLUDE_IMGUI_USER_INL
# include "imgui_user.inl"
2014-09-10 10:22:01 +00:00
# endif
//-----------------------------------------------------------------------------