@ -22,12 +22,15 @@
Index of this file :
Index of this file :
DOCUMENTATION
DOCUMENTATION
- MISSION STATEMENT
- MISSION STATEMENT
- END - USER GUIDE
- END - USER GUIDE
- PROGRAMMER GUIDE ( read me ! )
- PROGRAMMER GUIDE ( read me ! )
- Read first
- Read first
- How to update to a newer version of Dear ImGui
- How to update to a newer version of Dear ImGui
- Getting started with integrating Dear ImGui in your code / engine
- Getting started with integrating Dear ImGui in your code / engine
- This is how a simple application may look like ( 2 variations )
- This is how a simple rendering function may look like
- Using gamepad / keyboard navigation controls
- Using gamepad / keyboard navigation controls
- API BREAKING CHANGES ( read me when you update ! )
- API BREAKING CHANGES ( read me when you update ! )
- FREQUENTLY ASKED QUESTIONS ( FAQ ) , TIPS
- FREQUENTLY ASKED QUESTIONS ( FAQ ) , TIPS
@ -45,31 +48,35 @@ DOCUMENTATION
- How can I help ?
- How can I help ?
CODE
CODE
- Forward Declarations
( search for " [SECTION] " in the code to find them )
- Context and Memory Allocators
- User facing structures ( ImGuiStyle , ImGuiIO )
// [SECTION] FORWARD DECLARATIONS
- Helper / Utilities ( ImXXX functions , Color functions )
// [SECTION] CONTEXT AND MEMORY ALLOCATORS
- ImGuiStorage
// [SECTION] MAIN USER FACING STRUCTURES (ImGuiStyle, ImGuiIO)
- ImGuiTextFilter
// [SECTION] MISC HELPER/UTILITIES (Maths, String, Format, Hash, File functions)
- ImGuiTextBuffer
// [SECTION] MISC HELPER/UTILITIES (ImText* functions)
- ImGuiListClipper
// [SECTION] MISC HELPER/UTILITIES (Color functions)
- Render Helpers
// [SECTION] ImGuiStorage
- Main Code ( most of the code ! lots of stuff , needs tidying up )
// [SECTION] ImGuiTextFilter
- Tooltips
// [SECTION] ImGuiTextBuffer
- Popups
// [SECTION] ImGuiListClipper
- Viewports , Platform Windows
// [SECTION] RENDER HELPERS
- Navigation
// [SECTION] MAIN CODE (most of the code! lots of stuff, needs tidying up!)
- Columns
// [SECTION] TOOLTIPS
- Drag and Drop
// [SECTION] POPUPS
- Logging
// [SECTION] VIEWPORTS, PLATFORM WINDOWS
- Settings
// [SECTION] KEYBOARD/GAMEPAD NAVIGATION
- Platform Dependent Helpers
// [SECTION] COLUMNS
- Metrics / Debug window
// [SECTION] DRAG AND DROP
// [SECTION] LOGGING/CAPTURING
// [SECTION] SETTINGS
// [SECTION] PLATFORM DEPENDENT HELPERS
// [SECTION] METRICS/DEBUG WINDOW
*/
*/
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// D ocumentation
// D OCUMENTATION
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
/*
/*
@ -895,7 +902,7 @@ static const float NAV_WINDOWING_HIGHLIGHT_DELAY = 0.20f; // Time before the h
static const float NAV_WINDOWING_LIST_APPEAR_DELAY = 0.15f ; // Time before the window list starts to appear
static const float NAV_WINDOWING_LIST_APPEAR_DELAY = 0.15f ; // Time before the window list starts to appear
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
// Forward Declarations
// [SECTION] FORWARD DECLARATIONS
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
static void SetCurrentWindow ( ImGuiWindow * window ) ;
static void SetCurrentWindow ( ImGuiWindow * window ) ;
@ -954,7 +961,7 @@ static int FindPlatformMonitorForRect(const ImRect& r);
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Context and Memory Allocators
// [SECTION] CONTEXT AND MEMORY ALLOCATORS
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Current context pointer. Implicitly used by all ImGui functions. Always assumed to be != NULL.
// Current context pointer. Implicitly used by all ImGui functions. Always assumed to be != NULL.
@ -983,7 +990,7 @@ static void (*GImAllocatorFreeFunc)(void* ptr, void* user_data) = FreeWrapper;
static void * GImAllocatorUserData = NULL ;
static void * GImAllocatorUserData = NULL ;
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// User facing main structures
// [SECTION] MAIN USER FACING STRUCTURES (ImGuiStyle, ImGuiIO)
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
ImGuiStyle : : ImGuiStyle ( )
ImGuiStyle : : ImGuiStyle ( )
@ -1125,7 +1132,7 @@ void ImGuiIO::AddInputCharactersUTF8(const char* utf8_chars)
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// HELPERS /UTILITIES
// [SECTION] MISC HELPER/UTILITIES (Maths, String, Format, Hash, File functions)
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
ImVec2 ImLineClosestPoint ( const ImVec2 & a , const ImVec2 & b , const ImVec2 & p )
ImVec2 ImLineClosestPoint ( const ImVec2 & a , const ImVec2 & b , const ImVec2 & p )
@ -1343,8 +1350,66 @@ ImU32 ImHash(const void* data, int data_size, ImU32 seed)
return ~ crc ;
return ~ crc ;
}
}
FILE * ImFileOpen ( const char * filename , const char * mode )
{
# if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__GNUC__)
// We need a fopen() wrapper because MSVC/Windows fopen doesn't handle UTF-8 filenames. Converting both strings from UTF-8 to wchar format (using a single allocation, because we can)
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
}
// Load file content into memory
// Memory allocated with ImGui::MemAlloc(), must be freed by user using ImGui::MemFree()
void * ImFileLoadToMemory ( const char * filename , const char * file_open_mode , size_t * out_file_size , int padding_bytes )
{
IM_ASSERT ( filename & & file_open_mode ) ;
if ( out_file_size )
* out_file_size = 0 ;
FILE * f ;
if ( ( f = ImFileOpen ( filename , file_open_mode ) ) = = NULL )
return NULL ;
long file_size_signed ;
if ( fseek ( f , 0 , SEEK_END ) | | ( file_size_signed = ftell ( f ) ) = = - 1 | | fseek ( f , 0 , SEEK_SET ) )
{
fclose ( f ) ;
return NULL ;
}
size_t file_size = ( size_t ) file_size_signed ;
void * file_data = ImGui : : MemAlloc ( file_size + padding_bytes ) ;
if ( file_data = = NULL )
{
fclose ( f ) ;
return NULL ;
}
if ( fread ( file_data , 1 , file_size , f ) ! = file_size )
{
fclose ( f ) ;
ImGui : : MemFree ( file_data ) ;
return NULL ;
}
if ( padding_bytes > 0 )
memset ( ( void * ) ( ( ( char * ) file_data ) + file_size ) , 0 , ( size_t ) padding_bytes ) ;
fclose ( f ) ;
if ( out_file_size )
* out_file_size = file_size ;
return file_data ;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// HELPERS/UTILITIES (ImText* helpers)
// [SECTION] MISC HELPERS/UTILITIES (ImText* function s)
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Convert UTF-8 to 32-bits character, process single character input.
// Convert UTF-8 to 32-bits character, process single character input.
@ -1526,66 +1591,9 @@ int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_e
return bytes_count ;
return bytes_count ;
}
}
FILE * ImFileOpen ( const char * filename , const char * mode )
{
# if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__GNUC__)
// We need a fopen() wrapper because MSVC/Windows fopen doesn't handle UTF-8 filenames. Converting both strings from UTF-8 to wchar format (using a single allocation, because we can)
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
}
// Load file content into memory
// Memory allocated with ImGui::MemAlloc(), must be freed by user using ImGui::MemFree()
void * ImFileLoadToMemory ( const char * filename , const char * file_open_mode , size_t * out_file_size , int padding_bytes )
{
IM_ASSERT ( filename & & file_open_mode ) ;
if ( out_file_size )
* out_file_size = 0 ;
FILE * f ;
if ( ( f = ImFileOpen ( filename , file_open_mode ) ) = = NULL )
return NULL ;
long file_size_signed ;
if ( fseek ( f , 0 , SEEK_END ) | | ( file_size_signed = ftell ( f ) ) = = - 1 | | fseek ( f , 0 , SEEK_SET ) )
{
fclose ( f ) ;
return NULL ;
}
size_t file_size = ( size_t ) file_size_signed ;
void * file_data = ImGui : : MemAlloc ( file_size + padding_bytes ) ;
if ( file_data = = NULL )
{
fclose ( f ) ;
return NULL ;
}
if ( fread ( file_data , 1 , file_size , f ) ! = file_size )
{
fclose ( f ) ;
ImGui : : MemFree ( file_data ) ;
return NULL ;
}
if ( padding_bytes > 0 )
memset ( ( void * ) ( ( ( char * ) file_data ) + file_size ) , 0 , ( size_t ) padding_bytes ) ;
fclose ( f ) ;
if ( out_file_size )
* out_file_size = file_size ;
return file_data ;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// COLOR FUNCTIONS
// [SECTION] MISC HELPER/UTILTIES (Color functions)
// Note: The Convert functions are early design which are not consistent with other API.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
ImVec4 ImGui : : ColorConvertU32ToFloat4 ( ImU32 in )
ImVec4 ImGui : : ColorConvertU32ToFloat4 ( ImU32 in )
@ -1692,7 +1700,7 @@ ImU32 ImGui::GetColorU32(ImU32 col)
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// ImGuiStorage
// [SECTION] ImGuiStorage
// Helper: Key->value storage
// Helper: Key->value storage
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
@ -1841,7 +1849,7 @@ void ImGuiStorage::SetAllInt(int v)
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// ImGuiTextFilter
// [SECTION] ImGuiTextFilter
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
// Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]"
@ -1945,7 +1953,7 @@ bool ImGuiTextFilter::PassFilter(const char* text, const char* text_end) const
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// ImGuiTextBuffer
// [SECTION] ImGuiTextBuffer
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// On some platform vsnprintf() takes va_list by reference and modifies it.
// On some platform vsnprintf() takes va_list by reference and modifies it.
@ -1993,7 +2001,8 @@ void ImGuiTextBuffer::appendf(const char* fmt, ...)
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// ImGuiListClipper
// [SECTION] ImGuiListClipper
// This is currently not as flexible/powerful as it should be, needs some rework (see TODO)
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
static void SetCursorPosYAndSetupDummyPrevLine ( float pos_y , float line_height )
static void SetCursorPosYAndSetupDummyPrevLine ( float pos_y , float line_height )
@ -2077,8 +2086,8 @@ bool ImGuiListClipper::Step()
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// RENDER HELPERS
// [SECTION] RENDER HELPERS
// Those [Internal] functions are a terrible mess - their signature and behavior will change.
// Those (internal) functions are currently quite a legacy mess - their signature and behavior will change.
// Also see imgui_draw.cpp for some more which have been reworked to not rely on ImGui:: state.
// Also see imgui_draw.cpp for some more which have been reworked to not rely on ImGui:: state.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
@ -2297,8 +2306,7 @@ void ImGui::RenderNavHighlight(const ImRect& bb, ImGuiID id, ImGuiNavHighlightFl
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// MAIN CODE
// [SECTION] MAIN CODE (most of the code! lots of stuff, needs tidying up!)
// (this category is still too large and badly ordered, needs some tidying up)
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// ImGuiWindow is mostly a dumb struct. It merely has a constructor and a few helper methods
// ImGuiWindow is mostly a dumb struct. It merely has a constructor and a few helper methods
@ -2759,8 +2767,6 @@ float ImGui::CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x)
return ImMax ( wrap_pos_x - pos . x , 1.0f ) ;
return ImMax ( wrap_pos_x - pos . x , 1.0f ) ;
}
}
//-----------------------------------------------------------------------------
void * ImGui : : MemAlloc ( size_t size )
void * ImGui : : MemAlloc ( size_t size )
{
{
if ( ImGuiContext * ctx = GImGui )
if ( ImGuiContext * ctx = GImGui )
@ -6559,7 +6565,7 @@ void ImGui::Unindent(float indent_w)
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// TOOLTIPS
// [SECTION] TOOLTIPS
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void ImGui : : BeginTooltip ( )
void ImGui : : BeginTooltip ( )
@ -6628,7 +6634,7 @@ void ImGui::SetTooltip(const char* fmt, ...)
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// POPUPS
// [SECTION] POPUPS
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
bool ImGui : : IsPopupOpen ( ImGuiID id )
bool ImGui : : IsPopupOpen ( ImGuiID id )
@ -7011,7 +7017,7 @@ ImVec2 ImGui::FindBestWindowPosForPopup(ImGuiWindow* window)
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// VIEWPORTS / PLATFORM WINDOWS
// [SECTION] VIEWPORTS / PLATFORM WINDOWS
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
ImGuiViewport * ImGui : : GetMainViewport ( )
ImGuiViewport * ImGui : : GetMainViewport ( )
@ -7639,7 +7645,7 @@ void ImGui::DestroyPlatformWindows()
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// NAVIGATION
// [SECTION] KEYBOARD/GAMEPAD NAVIGATION
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
ImGuiDir ImGetDirQuadrantFromDelta ( float dx , float dy )
ImGuiDir ImGetDirQuadrantFromDelta ( float dx , float dy )
@ -8638,7 +8644,8 @@ void ImGui::NavUpdateWindowingList()
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// COLUMNS
// [SECTION] COLUMNS
// In the current version, Columns are very weak. Needs to be replaced with a more full-featured system.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void ImGui : : NextColumn ( )
void ImGui : : NextColumn ( )
@ -8960,7 +8967,7 @@ void ImGui::Columns(int columns_count, const char* id, bool border)
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// DRAG AND DROP
// [SECTION] DRAG AND DROP
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void ImGui : : ClearDragDrop ( )
void ImGui : : ClearDragDrop ( )
@ -9247,7 +9254,7 @@ void ImGui::EndDragDropTarget()
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// LOGGING
// [SECTION] LOGGING/CAPTUR ING
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Pass text data straight to log (without being displayed)
// Pass text data straight to log (without being displayed)
@ -9427,7 +9434,7 @@ void ImGui::LogButtons()
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// SETTINGS
// [SECTION] SETTINGS
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void ImGui : : MarkIniSettingsDirty ( )
void ImGui : : MarkIniSettingsDirty ( )
@ -9648,7 +9655,7 @@ static void SettingsHandlerWindow_WriteAll(ImGuiContext* imgui_ctx, ImGuiSetting
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// PLATFORM DEPENDENT HELPERS
// [SECTION] PLATFORM DEPENDENT HELPERS
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
# if defined(_WIN32) && !defined(_WINDOWS_) && (!defined(IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS) || !defined(IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS))
# if defined(_WIN32) && !defined(_WINDOWS_) && (!defined(IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS) || !defined(IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS))
@ -9735,7 +9742,7 @@ static void SetClipboardTextFn_DefaultImpl(void*, const char* text)
# endif
# endif
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// METRICS/DEBUG WINDOW
// [SECTION] METRICS/DEBUG WINDOW
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
static void RenderViewportThumbnail ( ImDrawList * draw_list , ImGuiViewportP * viewport , const ImRect & bb )
static void RenderViewportThumbnail ( ImDrawList * draw_list , ImGuiViewportP * viewport , const ImRect & bb )
@ -9794,8 +9801,12 @@ void ImGui::ShowViewportThumbnails()
void ImGui : : ShowMetricsWindow ( bool * p_open )
void ImGui : : ShowMetricsWindow ( bool * p_open )
{
{
if ( ImGui : : Begin ( " ImGui Metrics " , p_open ) )
if ( ! ImGui : : Begin ( " ImGui Metrics " , p_open ) )
{
{
ImGui : : End ( ) ;
return ;
}
static bool show_draw_cmd_clip_rects = true ;
static bool show_draw_cmd_clip_rects = true ;
static bool show_window_begin_order = false ;
static bool show_window_begin_order = false ;
ImGuiIO & io = ImGui : : GetIO ( ) ;
ImGuiIO & io = ImGui : : GetIO ( ) ;
@ -10023,7 +10034,6 @@ void ImGui::ShowMetricsWindow(bool* p_open)
overlay_draw_list - > AddText ( NULL , font_size , window - > Pos , IM_COL32 ( 255 , 255 , 255 , 255 ) , buf ) ;
overlay_draw_list - > AddText ( NULL , font_size , window - > Pos , IM_COL32 ( 255 , 255 , 255 , 255 ) , buf ) ;
}
}
}
}
}
ImGui : : End ( ) ;
ImGui : : End ( ) ;
}
}