2024-10-23 12:16:00 +02:00
// dear imgui, v1.91.5 WIP
2015-12-24 19:56:47 +01:00
// (demo code)
2015-07-22 01:00:28 +02:00
2020-01-12 21:51:40 +01:00
// Help:
2023-04-03 15:07:20 +02:00
// - Read FAQ at http://dearimgui.com/faq
2020-05-05 19:39:24 +02:00
// - Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp. All applications in examples/ are doing that.
2023-07-04 14:13:35 +02:00
// - Need help integrating Dear ImGui in your codebase?
// - Read Getting Started https://github.com/ocornut/imgui/wiki/Getting-Started
// - Read 'Programmer guide' in imgui.cpp for notes on how to setup Dear ImGui in your codebase.
2024-02-29 15:17:08 +01:00
// Read top of imgui.cpp and imgui.h for many details, documentation, comments, links.
2021-03-16 12:30:55 +01:00
// Get the latest version at https://github.com/ocornut/imgui
2020-01-12 21:51:40 +01:00
Windows, Internal: added experimental SkipRefresh mode. (#3515, #4763, #7556, #5116 , #4076, #2749, #2268)
currently: ImGui::SetNextWindowRefreshPolicy(ImGuiWindowRefreshFlags_TryToAvoidRefresh);
- This is NOT meant to replace frame-wide/app-wide idle mode.
- This is another tool: the idea that a given window could avoid refresh and reuse last frame contents.
- I think it needs to be backed by a careful and smart design overall (refresh policy, load balancing, making it easy and obvious to user).
- It's not there yet, this is currently a toy for experimenting.
My other issues with this:
- It appears to be very simple, but skipping most of Begin() logic will inevitably lead to tricky/confusing bugs. Let's see how it goes.
- I don't like very much that this opens a door to varying inconsistencies
- I don't like very much that it can lead us to situation where the lazy refresh gets disabled in bulk due to some reason (e.g. resizing a dock space) and we get sucked in the temptation to update for idle rather than update for dynamism.
2024-05-03 18:04:07 +02:00
// How to easily locate code?
2024-07-19 12:35:57 +02:00
// - Use Tools->Item Picker to debug break in code by clicking any widgets: https://github.com/ocornut/imgui/wiki/Debug-Tools
Windows, Internal: added experimental SkipRefresh mode. (#3515, #4763, #7556, #5116 , #4076, #2749, #2268)
currently: ImGui::SetNextWindowRefreshPolicy(ImGuiWindowRefreshFlags_TryToAvoidRefresh);
- This is NOT meant to replace frame-wide/app-wide idle mode.
- This is another tool: the idea that a given window could avoid refresh and reuse last frame contents.
- I think it needs to be backed by a careful and smart design overall (refresh policy, load balancing, making it easy and obvious to user).
- It's not there yet, this is currently a toy for experimenting.
My other issues with this:
- It appears to be very simple, but skipping most of Begin() logic will inevitably lead to tricky/confusing bugs. Let's see how it goes.
- I don't like very much that this opens a door to varying inconsistencies
- I don't like very much that it can lead us to situation where the lazy refresh gets disabled in bulk due to some reason (e.g. resizing a dock space) and we get sucked in the temptation to update for idle rather than update for dynamism.
2024-05-03 18:04:07 +02:00
// - Browse an online version the demo with code linked to hovered widgets: https://pthom.github.io/imgui_manual_online/manual/imgui_manual.html
// - Find a visible string and search for it in the code!
2023-08-14 16:55:03 +02:00
//---------------------------------------------------
2022-09-20 15:57:58 +02:00
// PLEASE DO NOT REMOVE THIS FILE FROM YOUR PROJECT!
2023-08-14 16:55:03 +02:00
//---------------------------------------------------
2021-03-16 12:30:55 +01:00
// Message to the person tempted to delete this file when integrating Dear ImGui into their codebase:
2022-09-20 15:57:58 +02:00
// Think again! It is the most useful reference code that you and other coders will want to refer to and call.
// Have the ImGui::ShowDemoWindow() function wired in an always-available debug menu of your game/app!
// Also include Metrics! ItemPicker! DebugLog! and other debug features.
// Removing this file from your project is hindering access to documentation for everyone in your team,
// likely leading you to poorer usage of the library.
2017-12-24 18:16:22 +01:00
// Everything in this file will be stripped out by the linker if you don't call ImGui::ShowDemoWindow().
2020-05-05 19:39:24 +02:00
// If you want to link core Dear ImGui in your shipped builds but want a thorough guarantee that the demo will not be
// linked, you can setup your imconfig.h with #define IMGUI_DISABLE_DEMO_WINDOWS and those functions will be empty.
2021-03-16 12:30:55 +01:00
// In another situation, whenever you have Dear ImGui available you probably want this to be available for reference.
2017-07-20 17:12:58 +02:00
// Thank you,
2020-01-11 15:35:39 +01:00
// -Your beloved friend, imgui_demo.cpp (which you won't delete)
2015-07-22 01:00:28 +02:00
2023-08-14 16:55:03 +02:00
//--------------------------------------------
// ABOUT THE MEANING OF THE 'static' KEYWORD:
//--------------------------------------------
// In this demo code, we frequently use 'static' variables inside functions.
// A static variable persists across calls. It is essentially a global variable but declared inside the scope of the function.
// Think of "static int n = 0;" as "global int n = 0;" !
// We do this IN THE DEMO because we want:
// - to gather code and data in the same place.
// - to make the demo source code faster to read, faster to change, smaller in size.
// - it is also a convenient way of storing simple UI related information as long as your function
// doesn't need to be reentrant or used in multiple threads.
// This might be a pattern you will want to use in your code, but most of the data you would be working
// with in a complex codebase is likely going to be stored outside your functions.
2019-05-28 21:49:22 +02:00
2023-08-14 16:55:03 +02:00
//-----------------------------------------
// ABOUT THE CODING STYLE OF OUR DEMO CODE
//-----------------------------------------
2021-03-16 12:30:55 +01:00
// The Demo code in this file is designed to be easy to copy-and-paste into your application!
2019-05-28 21:49:22 +02:00
// Because of this:
2020-05-05 19:39:24 +02:00
// - We never omit the ImGui:: prefix when calling functions, even though most code here is in the same namespace.
2019-05-28 21:49:22 +02:00
// - We try to declare static variables in the local scope, as close as possible to the code using them.
2020-05-05 19:39:24 +02:00
// - We never use any of the helpers/facilities used internally by Dear ImGui, unless available in the public API.
// - We never use maths operators on ImVec2/ImVec4. For our other sources files we use them, and they are provided
2023-02-15 19:14:22 +01:00
// by imgui.h using the IMGUI_DEFINE_MATH_OPERATORS define. For your own sources file they are optional
2020-05-05 19:39:24 +02:00
// and require you either enable those, either provide your own via IM_VEC2_CLASS_EXTRA in imconfig.h.
// Because we can't assume anything about your support of maths operators, we cannot use them in imgui_demo.cpp.
2015-07-22 01:00:28 +02:00
2020-12-04 17:54:40 +01:00
// Navigating this file:
2024-03-26 06:15:35 +01:00
// - In Visual Studio: CTRL+comma ("Edit.GoToAll") can follow symbols inside comments, whereas CTRL+F12 ("Edit.GoToImplementation") cannot.
// - In Visual Studio w/ Visual Assist installed: ALT+G ("VAssistX.GoToImplementation") can also follow symbols inside comments.
2024-03-27 02:50:55 +01:00
// - In VS Code, CLion, etc.: CTRL+click can follow symbols inside comments.
2024-07-19 12:35:57 +02:00
// - You can search/grep for all sections listed in the index to find the section.
2020-12-04 17:54:40 +01:00
2018-09-06 11:35:13 +02:00
/*
Index of this file :
2022-09-26 14:50:46 +02:00
// [SECTION] Forward Declarations
// [SECTION] Helpers
2024-07-19 12:35:57 +02:00
// [SECTION] Helpers: ExampleTreeNode, ExampleMemberInfo (for use by Property Editor & Multi-Select demos)
2018-09-06 11:35:13 +02:00
// [SECTION] Demo Window / ShowDemoWindow()
2024-07-19 15:46:51 +02:00
// [SECTION] ShowDemoWindowMenuBar()
2024-07-19 12:35:57 +02:00
// [SECTION] ShowDemoWindowWidgets()
// [SECTION] ShowDemoWindowMultiSelect()
// [SECTION] ShowDemoWindowLayout()
// [SECTION] ShowDemoWindowPopups()
// [SECTION] ShowDemoWindowTables()
// [SECTION] ShowDemoWindowInputs()
2018-11-30 17:15:03 +01:00
// [SECTION] About Window / ShowAboutWindow()
2018-09-06 11:35:13 +02:00
// [SECTION] Style Editor / ShowStyleEditor()
2022-09-26 14:50:46 +02:00
// [SECTION] User Guide / ShowUserGuide()
2018-09-06 11:35:13 +02:00
// [SECTION] Example App: Main Menu Bar / ShowExampleAppMainMenuBar()
// [SECTION] Example App: Debug Console / ShowExampleAppConsole()
// [SECTION] Example App: Debug Log / ShowExampleAppLog()
// [SECTION] Example App: Simple Layout / ShowExampleAppLayout()
// [SECTION] Example App: Property Editor / ShowExampleAppPropertyEditor()
// [SECTION] Example App: Long Text / ShowExampleAppLongText()
// [SECTION] Example App: Auto Resize / ShowExampleAppAutoResize()
// [SECTION] Example App: Constrained Resize / ShowExampleAppConstrainedResize()
2021-02-05 12:24:23 +01:00
// [SECTION] Example App: Simple overlay / ShowExampleAppSimpleOverlay()
// [SECTION] Example App: Fullscreen window / ShowExampleAppFullscreen()
// [SECTION] Example App: Manipulating window titles / ShowExampleAppWindowTitles()
2018-09-06 11:35:13 +02:00
// [SECTION] Example App: Custom Rendering using ImDrawList API / ShowExampleAppCustomRendering()
2018-12-11 12:36:47 +01:00
// [SECTION] Example App: Documents Handling / ShowExampleAppDocuments()
2023-08-31 20:06:22 +02:00
// [SECTION] Example App: Assets Browser / ShowExampleAppAssetsBrowser()
2018-09-06 11:35:13 +02:00
*/
2015-07-22 01:00:28 +02:00
# if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
# define _CRT_SECURE_NO_WARNINGS
# endif
# include "imgui.h"
2020-02-09 17:06:58 +01:00
# ifndef IMGUI_DISABLE
2020-12-01 16:46:35 +01:00
// System includes
2019-04-03 10:40:14 +02:00
# include <ctype.h> // toupper
2018-05-12 18:58:59 +02:00
# include <limits.h> // INT_MIN, INT_MAX
2016-05-31 00:00:44 +02:00
# include <math.h> // sqrtf, powf, cosf, sinf, floorf, ceilf
2015-11-13 17:08:54 +01:00
# include <stdio.h> // vsnprintf, sscanf, printf
2017-07-15 11:11:53 +02:00
# include <stdlib.h> // NULL, malloc, free, atoi
2015-11-29 11:20:50 +01:00
# include <stdint.h> // intptr_t
2023-08-07 15:23:59 +02:00
# if !defined(_MSC_VER) || _MSC_VER >= 1800
2023-08-07 18:25:56 +02:00
# include <inttypes.h> // PRId64/PRIu64, not avail in some MinGW headers.
2023-08-07 15:23:59 +02:00
# endif
2024-08-23 19:05:38 +02:00
# ifdef __EMSCRIPTEN__
# include <emscripten/version.h> // __EMSCRIPTEN_major__ etc.
# endif
2023-08-07 15:23:59 +02:00
2020-06-18 16:33:23 +02:00
// Visual Studio warnings
2015-07-22 01:00:28 +02:00
# ifdef _MSC_VER
2022-01-17 11:53:03 +01:00
# pragma warning (disable: 4127) // condition expression is constant
2021-04-29 16:20:47 +02:00
# pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen
2022-09-14 18:19:50 +02:00
# pragma warning (disable: 26451) // [Static Analyzer] Arithmetic overflow : Using operator 'xxx' on a 4 byte value and then casting the result to an 8 byte value. Cast the value to the wider type before calling operator 'xxx' to avoid overflow(io.2).
2015-07-22 01:00:28 +02:00
# endif
2020-06-18 16:33:23 +02:00
// Clang/GCC warnings with -Weverything
2019-05-19 17:15:14 +02:00
# if defined(__clang__)
2020-06-18 16:33:23 +02:00
# if __has_warning("-Wunknown-warning-option")
# pragma clang diagnostic ignored "-Wunknown-warning-option" // warning: unknown warning group 'xxx' // not all warnings are known by all Clang versions and they tend to be rename-happy.. so ignoring warnings triggers new warnings on some configuration. Great!
2020-06-18 16:19:51 +02:00
# endif
2020-06-18 16:33:23 +02:00
# pragma clang diagnostic ignored "-Wunknown-pragmas" // warning: unknown warning group 'xxx'
# pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast // yes, they are more terse.
# pragma clang diagnostic ignored "-Wdeprecated-declarations" // warning: 'xx' is deprecated: The POSIX name for this.. // for strdup used in demo code (so user can copy & paste the code)
# pragma clang diagnostic ignored "-Wint-to-void-pointer-cast" // warning: cast to 'void *' from smaller integer type
# pragma clang diagnostic ignored "-Wformat-security" // warning: format string is not a string literal
# pragma clang diagnostic ignored "-Wexit-time-destructors" // warning: declaration requires an exit-time destructor // exit-time destruction order is undefined. if MemFree() leads to users code that has been disabled before exit it might cause problems. ImGui coding style welcomes static/globals.
# pragma clang diagnostic ignored "-Wunused-macros" // warning: macro is not used // we define snprintf/vsnprintf on Windows so they are available, but not always used.
# pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" // warning: zero as null pointer constant // some standard header variations use #define NULL 0
# 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.
# pragma clang diagnostic ignored "-Wreserved-id-macro" // warning: macro name is a reserved identifier
# pragma clang diagnostic ignored "-Wimplicit-int-float-conversion" // warning: implicit conversion from 'xxx' to 'float' may lose precision
2024-04-12 16:55:32 +02:00
# pragma clang diagnostic ignored "-Wunsafe-buffer-usage" // warning: 'xxx' is an unsafe pointer used for buffer access
2016-05-09 22:27:44 +02:00
# elif defined(__GNUC__)
2020-06-18 16:33:23 +02:00
# pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind
# pragma GCC diagnostic ignored "-Wint-to-pointer-cast" // warning: cast to pointer from integer of different size
# pragma GCC diagnostic ignored "-Wformat-security" // warning: format string is not a string literal (potentially insecure)
# pragma GCC diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function
# pragma GCC diagnostic ignored "-Wconversion" // warning: conversion to 'xxxx' from 'xxxx' may alter its value
# pragma GCC diagnostic ignored "-Wmisleading-indentation" // [__GNUC__ >= 6] warning: this 'if' clause does not guard this statement // GCC 6.0+ only. See #883 on GitHub.
2015-07-22 01:13:56 +02:00
# endif
2015-07-22 01:00:28 +02:00
2020-05-05 19:39:24 +02:00
// Play it nice with Windows users (Update: May 2018, Notepad now supports Unix-style carriage returns!)
2015-08-09 17:24:10 +02:00
# ifdef _WIN32
2019-02-14 20:29:50 +01:00
# define IM_NEWLINE "\r\n"
2015-07-22 01:00:28 +02:00
# else
2019-02-14 20:29:50 +01:00
# define IM_NEWLINE "\n"
2015-07-22 01:00:28 +02:00
# endif
2020-05-07 11:38:45 +02:00
// Helpers
2019-10-28 12:46:45 +01:00
# if defined(_MSC_VER) && !defined(snprintf)
# define snprintf _snprintf
# endif
# if defined(_MSC_VER) && !defined(vsnprintf)
# define vsnprintf _vsnprintf
# endif
2023-08-07 18:25:56 +02:00
// Format specifiers for 64-bit values (hasn't been decently standardized before VS2013)
# if !defined(PRId64) && defined(_MSC_VER)
# define PRId64 "I64d"
# define PRIu64 "I64u"
# elif !defined(PRId64)
# define PRId64 "lld"
# define PRIu64 "llu"
# endif
2020-05-07 11:38:45 +02:00
// Helpers macros
// We normally try to not use many helpers in imgui_demo.cpp in order to make code easier to copy and paste,
// but making an exception here as those are largely simplifying code...
// In other imgui sources we can use nicer internal functions from imgui_internal.h (ImMin/ImMax) but not in the demo.
# define IM_MIN(A, B) (((A) < (B)) ? (A) : (B))
# define IM_MAX(A, B) (((A) >= (B)) ? (A) : (B))
# define IM_CLAMP(V, MN, MX) ((V) < (MN) ? (MN) : (V) > (MX) ? (MX) : (V))
2024-01-04 11:50:38 +01:00
// Enforce cdecl calling convention for functions called by the standard library,
// in case compilation settings changed the default to e.g. __vectorcall
2019-12-19 14:52:18 +01:00
# ifndef IMGUI_CDECL
# ifdef _MSC_VER
# define IMGUI_CDECL __cdecl
# else
# define IMGUI_CDECL
# endif
# endif
2015-07-22 01:00:28 +02:00
//-----------------------------------------------------------------------------
2024-07-19 12:35:57 +02:00
// [SECTION] Forward Declarations
2015-07-22 01:00:28 +02:00
//-----------------------------------------------------------------------------
2017-12-24 18:16:22 +01:00
# if !defined(IMGUI_DISABLE_DEMO_WINDOWS)
2015-07-22 01:00:28 +02:00
2018-06-26 12:37:10 +02:00
// Forward Declarations
2024-07-30 11:44:13 +02:00
struct ImGuiDemoWindowData ;
2018-07-12 11:40:23 +02:00
static void ShowExampleAppMainMenuBar ( ) ;
2023-08-31 20:06:22 +02:00
static void ShowExampleAppAssetsBrowser ( bool * p_open ) ;
2016-05-02 12:32:16 +02:00
static void ShowExampleAppConsole ( bool * p_open ) ;
2023-08-31 19:49:39 +02:00
static void ShowExampleAppCustomRendering ( bool * p_open ) ;
static void ShowExampleAppDocuments ( bool * p_open ) ;
2016-05-02 12:32:16 +02:00
static void ShowExampleAppLog ( bool * p_open ) ;
static void ShowExampleAppLayout ( bool * p_open ) ;
2024-07-30 11:44:13 +02:00
static void ShowExampleAppPropertyEditor ( bool * p_open , ImGuiDemoWindowData * demo_data ) ;
2023-08-31 19:49:39 +02:00
static void ShowExampleAppSimpleOverlay ( bool * p_open ) ;
2016-05-02 12:32:16 +02:00
static void ShowExampleAppAutoResize ( bool * p_open ) ;
2016-05-21 22:53:08 +02:00
static void ShowExampleAppConstrainedResize ( bool * p_open ) ;
2021-02-05 12:24:23 +01:00
static void ShowExampleAppFullscreen ( bool * p_open ) ;
2023-08-31 19:49:39 +02:00
static void ShowExampleAppLongText ( bool * p_open ) ;
2017-12-10 18:49:47 +01:00
static void ShowExampleAppWindowTitles ( bool * p_open ) ;
2015-07-22 01:00:28 +02:00
static void ShowExampleMenuFile ( ) ;
2022-09-26 14:50:46 +02:00
// We split the contents of the big ShowDemoWindow() function into smaller functions
2024-07-19 12:35:57 +02:00
// (because the link time of very large functions tends to grow non-linearly)
2024-07-30 11:44:13 +02:00
static void ShowDemoWindowMenuBar ( ImGuiDemoWindowData * demo_data ) ;
static void ShowDemoWindowWidgets ( ImGuiDemoWindowData * demo_data ) ;
static void ShowDemoWindowMultiSelect ( ImGuiDemoWindowData * demo_data ) ;
2022-09-26 14:50:46 +02:00
static void ShowDemoWindowLayout ( ) ;
static void ShowDemoWindowPopups ( ) ;
static void ShowDemoWindowTables ( ) ;
static void ShowDemoWindowColumns ( ) ;
static void ShowDemoWindowInputs ( ) ;
//-----------------------------------------------------------------------------
// [SECTION] Helpers
//-----------------------------------------------------------------------------
2018-06-26 12:37:10 +02:00
// Helper to display a little (?) mark which shows a tooltip when hovered.
2020-06-09 16:29:00 +02:00
// In your own code you may want to display an actual icon if you are using a merged icon fonts (see docs/FONTS.md)
2019-03-06 18:19:28 +01:00
static void HelpMarker ( const char * desc )
2015-07-22 01:00:28 +02:00
{
2015-08-24 13:50:18 +02:00
ImGui : : TextDisabled ( " (?) " ) ;
2023-06-16 16:42:56 +02:00
if ( ImGui : : BeginItemTooltip ( ) )
2016-07-18 14:31:15 +02:00
{
2018-01-30 21:17:27 +01:00
ImGui : : PushTextWrapPos ( ImGui : : GetFontSize ( ) * 35.0f ) ;
2016-07-18 14:31:15 +02:00
ImGui : : TextUnformatted ( desc ) ;
ImGui : : PopTextWrapPos ( ) ;
ImGui : : EndTooltip ( ) ;
}
2015-07-22 01:00:28 +02:00
}
2022-09-11 07:35:59 +02:00
// Helper to wire demo markers located in code to an interactive browser
2021-02-21 22:12:48 +01:00
typedef void ( * ImGuiDemoMarkerCallback ) ( const char * file , int line , const char * section , void * user_data ) ;
2022-09-26 14:50:46 +02:00
extern ImGuiDemoMarkerCallback GImGuiDemoMarkerCallback ;
extern void * GImGuiDemoMarkerCallbackUserData ;
ImGuiDemoMarkerCallback GImGuiDemoMarkerCallback = NULL ;
void * GImGuiDemoMarkerCallbackUserData = NULL ;
2021-02-21 22:12:48 +01:00
# define IMGUI_DEMO_MARKER(section) do { if (GImGuiDemoMarkerCallback != NULL) GImGuiDemoMarkerCallback(__FILE__, __LINE__, section, GImGuiDemoMarkerCallbackUserData); } while (0)
2018-09-06 11:35:13 +02:00
//-----------------------------------------------------------------------------
2024-07-19 12:35:57 +02:00
// [SECTION] Helpers: ExampleTreeNode, ExampleMemberInfo (for use by Property Editor etc.)
//-----------------------------------------------------------------------------
// Simple representation for a tree
// (this is designed to be simple to understand for our demos, not to be fancy or efficient etc.)
struct ExampleTreeNode
{
// Tree structure
2023-08-21 11:26:19 +02:00
char Name [ 28 ] = " " ;
2024-07-19 12:35:57 +02:00
int UID = 0 ;
ExampleTreeNode * Parent = NULL ;
ImVector < ExampleTreeNode * > Childs ;
2023-08-21 11:26:19 +02:00
unsigned short IndexInParent = 0 ; // Maintaining this allows us to implement linear traversal more easily
2024-07-19 12:35:57 +02:00
// Leaf Data
2023-08-21 11:26:19 +02:00
bool HasData = false ; // All leaves have data
2024-07-22 14:06:14 +02:00
bool DataMyBool = true ;
2024-07-19 12:35:57 +02:00
int DataMyInt = 128 ;
ImVec2 DataMyVec2 = ImVec2 ( 0.0f , 3.141592f ) ;
} ;
// Simple representation of struct metadata/serialization data.
// (this is a minimal version of what a typical advanced application may provide)
struct ExampleMemberInfo
{
const char * Name ; // Member name
ImGuiDataType DataType ; // Member type
int DataCount ; // Member count (1 when scalar)
int Offset ; // Offset inside parent structure
} ;
// Metadata description of ExampleTreeNode struct.
static const ExampleMemberInfo ExampleTreeNodeMemberInfos [ ]
{
{ " MyBool " , ImGuiDataType_Bool , 1 , offsetof ( ExampleTreeNode , DataMyBool ) } ,
{ " MyInt " , ImGuiDataType_S32 , 1 , offsetof ( ExampleTreeNode , DataMyInt ) } ,
{ " MyVec2 " , ImGuiDataType_Float , 2 , offsetof ( ExampleTreeNode , DataMyVec2 ) } ,
} ;
static ExampleTreeNode * ExampleTree_CreateNode ( const char * name , int uid , ExampleTreeNode * parent )
{
ExampleTreeNode * node = IM_NEW ( ExampleTreeNode ) ;
snprintf ( node - > Name , IM_ARRAYSIZE ( node - > Name ) , " %s " , name ) ;
node - > UID = uid ;
node - > Parent = parent ;
2023-08-21 11:26:19 +02:00
node - > IndexInParent = parent ? ( unsigned short ) parent - > Childs . Size : 0 ;
2024-07-19 12:35:57 +02:00
if ( parent )
parent - > Childs . push_back ( node ) ;
return node ;
}
// Create example tree data
2024-07-22 14:06:14 +02:00
// (this allocates _many_ more times than most other code in either Dear ImGui or others demo)
2024-07-19 12:35:57 +02:00
static ExampleTreeNode * ExampleTree_CreateDemoTree ( )
{
2024-07-30 11:44:13 +02:00
static const char * root_names [ ] = { " Apple " , " Banana " , " Cherry " , " Kiwi " , " Mango " , " Orange " , " Pear " , " Pineapple " , " Strawberry " , " Watermelon " } ;
2024-08-07 12:47:03 +02:00
const size_t NAME_MAX_LEN = sizeof ( ExampleTreeNode : : Name ) ;
char name_buf [ NAME_MAX_LEN ] ;
2024-07-19 12:35:57 +02:00
int uid = 0 ;
ExampleTreeNode * node_L0 = ExampleTree_CreateNode ( " <ROOT> " , + + uid , NULL ) ;
2024-07-30 11:44:13 +02:00
const int root_items_multiplier = 2 ;
for ( int idx_L0 = 0 ; idx_L0 < IM_ARRAYSIZE ( root_names ) * root_items_multiplier ; idx_L0 + + )
2024-07-19 12:35:57 +02:00
{
2024-08-07 12:47:03 +02:00
snprintf ( name_buf , IM_ARRAYSIZE ( name_buf ) , " %s %d " , root_names [ idx_L0 / root_items_multiplier ] , idx_L0 % root_items_multiplier ) ;
2024-07-19 12:35:57 +02:00
ExampleTreeNode * node_L1 = ExampleTree_CreateNode ( name_buf , + + uid , node_L0 ) ;
const int number_of_childs = ( int ) strlen ( node_L1 - > Name ) ;
for ( int idx_L1 = 0 ; idx_L1 < number_of_childs ; idx_L1 + + )
{
2024-08-07 12:47:03 +02:00
snprintf ( name_buf , IM_ARRAYSIZE ( name_buf ) , " Child %d " , idx_L1 ) ;
2024-07-19 12:35:57 +02:00
ExampleTreeNode * node_L2 = ExampleTree_CreateNode ( name_buf , + + uid , node_L1 ) ;
node_L2 - > HasData = true ;
if ( idx_L1 = = 0 )
{
2024-08-07 12:47:03 +02:00
snprintf ( name_buf , IM_ARRAYSIZE ( name_buf ) , " Sub-child %d " , 0 ) ;
2024-07-19 12:35:57 +02:00
ExampleTreeNode * node_L3 = ExampleTree_CreateNode ( name_buf , + + uid , node_L2 ) ;
node_L3 - > HasData = true ;
}
}
}
return node_L0 ;
}
2018-09-06 11:35:13 +02:00
//-----------------------------------------------------------------------------
2024-07-19 12:35:57 +02:00
// [SECTION] Demo Window / ShowDemoWindow()
2019-09-23 15:31:05 +02:00
//-----------------------------------------------------------------------------
2018-09-06 11:35:13 +02:00
2024-07-30 11:44:13 +02:00
// Data to be shared accross different functions of the demo.
struct ImGuiDemoWindowData
2024-07-19 15:34:48 +02:00
{
// Examples Apps (accessible from the "Examples" menu)
bool ShowMainMenuBar = false ;
bool ShowAppAssetsBrowser = false ;
bool ShowAppConsole = false ;
bool ShowAppCustomRendering = false ;
bool ShowAppDocuments = false ;
bool ShowAppLog = false ;
bool ShowAppLayout = false ;
bool ShowAppPropertyEditor = false ;
bool ShowAppSimpleOverlay = false ;
bool ShowAppAutoResize = false ;
bool ShowAppConstrainedResize = false ;
bool ShowAppFullscreen = false ;
bool ShowAppLongText = false ;
bool ShowAppWindowTitles = false ;
// Dear ImGui Tools (accessible from the "Tools" menu)
bool ShowMetrics = false ;
bool ShowDebugLog = false ;
bool ShowIDStackTool = false ;
bool ShowStyleEditor = false ;
bool ShowAbout = false ;
2024-07-30 11:44:13 +02:00
// Other data
ExampleTreeNode * DemoTree = NULL ;
2024-07-19 15:34:48 +02:00
} ;
2018-06-26 12:37:10 +02:00
// Demonstrate most Dear ImGui features (this is big function!)
2020-05-05 19:39:24 +02:00
// You may execute this function to experiment with the UI and understand what it does.
// You may then search for keywords in the code when you are interested by a specific feature.
2017-12-24 18:16:22 +01:00
void ImGui : : ShowDemoWindow ( bool * p_open )
2015-07-22 01:00:28 +02:00
{
2020-05-05 19:39:24 +02:00
// Exceptionally add an extra assert here for people confused about initial Dear ImGui setup
2023-08-31 19:49:39 +02:00
// Most functions would normally just assert/crash if the context is missing.
IM_ASSERT ( ImGui : : GetCurrentContext ( ) ! = NULL & & " Missing Dear ImGui context. Refer to examples app! " ) ;
2019-04-12 17:43:50 +02:00
2024-05-13 15:07:13 +02:00
// Verify ABI compatibility between caller code and compiled version of Dear ImGui. This helps detects some build issues.
IMGUI_CHECKVERSION ( ) ;
2024-07-19 15:34:48 +02:00
// Stored data
2024-07-30 11:44:13 +02:00
static ImGuiDemoWindowData demo_data ;
2024-07-19 15:34:48 +02:00
2018-06-26 12:37:10 +02:00
// Examples Apps (accessible from the "Examples" menu)
2024-07-30 11:44:13 +02:00
if ( demo_data . ShowMainMenuBar ) { ShowExampleAppMainMenuBar ( ) ; }
if ( demo_data . ShowAppDocuments ) { ShowExampleAppDocuments ( & demo_data . ShowAppDocuments ) ; }
if ( demo_data . ShowAppAssetsBrowser ) { ShowExampleAppAssetsBrowser ( & demo_data . ShowAppAssetsBrowser ) ; }
if ( demo_data . ShowAppConsole ) { ShowExampleAppConsole ( & demo_data . ShowAppConsole ) ; }
if ( demo_data . ShowAppCustomRendering ) { ShowExampleAppCustomRendering ( & demo_data . ShowAppCustomRendering ) ; }
if ( demo_data . ShowAppLog ) { ShowExampleAppLog ( & demo_data . ShowAppLog ) ; }
if ( demo_data . ShowAppLayout ) { ShowExampleAppLayout ( & demo_data . ShowAppLayout ) ; }
if ( demo_data . ShowAppPropertyEditor ) { ShowExampleAppPropertyEditor ( & demo_data . ShowAppPropertyEditor , & demo_data ) ; }
if ( demo_data . ShowAppSimpleOverlay ) { ShowExampleAppSimpleOverlay ( & demo_data . ShowAppSimpleOverlay ) ; }
if ( demo_data . ShowAppAutoResize ) { ShowExampleAppAutoResize ( & demo_data . ShowAppAutoResize ) ; }
if ( demo_data . ShowAppConstrainedResize ) { ShowExampleAppConstrainedResize ( & demo_data . ShowAppConstrainedResize ) ; }
if ( demo_data . ShowAppFullscreen ) { ShowExampleAppFullscreen ( & demo_data . ShowAppFullscreen ) ; }
if ( demo_data . ShowAppLongText ) { ShowExampleAppLongText ( & demo_data . ShowAppLongText ) ; }
if ( demo_data . ShowAppWindowTitles ) { ShowExampleAppWindowTitles ( & demo_data . ShowAppWindowTitles ) ; }
2017-12-10 18:49:47 +01:00
2023-08-31 19:49:39 +02:00
// Dear ImGui Tools (accessible from the "Tools" menu)
2024-07-30 11:44:13 +02:00
if ( demo_data . ShowMetrics ) { ImGui : : ShowMetricsWindow ( & demo_data . ShowMetrics ) ; }
if ( demo_data . ShowDebugLog ) { ImGui : : ShowDebugLogWindow ( & demo_data . ShowDebugLog ) ; }
if ( demo_data . ShowIDStackTool ) { ImGui : : ShowIDStackToolWindow ( & demo_data . ShowIDStackTool ) ; }
if ( demo_data . ShowAbout ) { ImGui : : ShowAboutWindow ( & demo_data . ShowAbout ) ; }
if ( demo_data . ShowStyleEditor )
2020-05-05 19:39:24 +02:00
{
2024-07-30 11:44:13 +02:00
ImGui : : Begin ( " Dear ImGui Style Editor " , & demo_data . ShowStyleEditor ) ;
2020-05-05 19:39:24 +02:00
ImGui : : ShowStyleEditor ( ) ;
ImGui : : End ( ) ;
}
2015-07-22 01:00:28 +02:00
2018-06-26 12:37:10 +02:00
// Demonstrate the various window flags. Typically you would just use the default!
2015-07-22 01:00:28 +02:00
static bool no_titlebar = false ;
static bool no_scrollbar = false ;
static bool no_menu = false ;
2017-11-19 15:56:51 +01:00
static bool no_move = false ;
static bool no_resize = false ;
static bool no_collapse = false ;
2017-12-10 17:02:41 +01:00
static bool no_close = false ;
2016-07-20 00:02:59 +02:00
static bool no_nav = false ;
2018-10-15 18:00:04 +02:00
static bool no_background = false ;
2018-09-10 20:30:14 +02:00
static bool no_bring_to_front = false ;
2021-06-24 14:30:32 +02:00
static bool unsaved_document = false ;
2018-10-25 23:34:05 +02:00
2015-08-30 19:07:51 +02:00
ImGuiWindowFlags window_flags = 0 ;
2018-09-10 20:30:14 +02:00
if ( no_titlebar ) window_flags | = ImGuiWindowFlags_NoTitleBar ;
if ( no_scrollbar ) window_flags | = ImGuiWindowFlags_NoScrollbar ;
if ( ! no_menu ) window_flags | = ImGuiWindowFlags_MenuBar ;
if ( no_move ) window_flags | = ImGuiWindowFlags_NoMove ;
if ( no_resize ) window_flags | = ImGuiWindowFlags_NoResize ;
if ( no_collapse ) window_flags | = ImGuiWindowFlags_NoCollapse ;
if ( no_nav ) window_flags | = ImGuiWindowFlags_NoNav ;
2018-10-15 18:00:04 +02:00
if ( no_background ) window_flags | = ImGuiWindowFlags_NoBackground ;
2018-09-10 20:30:14 +02:00
if ( no_bring_to_front ) window_flags | = ImGuiWindowFlags_NoBringToFrontOnFocus ;
2021-06-24 14:30:32 +02:00
if ( unsaved_document ) window_flags | = ImGuiWindowFlags_UnsavedDocument ;
2018-09-10 20:30:14 +02:00
if ( no_close ) p_open = NULL ; // Don't pass our bool* to Begin
2017-12-10 17:02:41 +01:00
2020-05-05 19:39:24 +02:00
// We specify a default position/size in case there's no data in the .ini file.
// We only do it to make the demo applications a little more welcoming, but typically this isn't required.
2021-02-10 14:54:59 +01:00
const ImGuiViewport * main_viewport = ImGui : : GetMainViewport ( ) ;
ImGui : : SetNextWindowPos ( ImVec2 ( main_viewport - > WorkPos . x + 650 , main_viewport - > WorkPos . y + 20 ) , ImGuiCond_FirstUseEver ) ;
2018-07-16 22:17:34 +02:00
ImGui : : SetNextWindowSize ( ImVec2 ( 550 , 680 ) , ImGuiCond_FirstUseEver ) ;
2018-06-26 12:37:10 +02:00
// Main body of the Demo window starts here.
2019-05-27 17:28:18 +02:00
if ( ! ImGui : : Begin ( " Dear ImGui Demo " , p_open , window_flags ) )
2015-07-22 01:00:28 +02:00
{
// Early out if the window is collapsed, as an optimization.
ImGui : : End ( ) ;
return ;
}
2020-05-05 19:39:24 +02:00
// Most "big" widgets share a common width settings by default. See 'Demo->Layout->Widgets Width' for details.
2024-07-19 15:46:51 +02:00
ImGui : : PushItemWidth ( ImGui : : GetFontSize ( ) * - 12 ) ; // e.g. Leave a fixed amount of width for labels (by passing a negative value), the rest goes to widgets.
//ImGui::PushItemWidth(-ImGui::GetWindowWidth() * 0.35f); // e.g. Use 2/3 of the space for widgets and 1/3 for labels (right align)
2018-06-26 12:37:10 +02:00
2019-04-11 15:12:18 +02:00
// Menu Bar
2024-07-30 11:44:13 +02:00
ShowDemoWindowMenuBar ( & demo_data ) ;
2015-07-22 01:00:28 +02:00
2022-05-23 14:29:34 +02:00
ImGui : : Text ( " dear imgui says hello! (%s) (%d) " , IMGUI_VERSION , IMGUI_VERSION_NUM ) ;
2015-07-22 01:00:28 +02:00
ImGui : : Spacing ( ) ;
2019-04-17 12:26:51 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Help " ) ;
2015-07-22 01:00:28 +02:00
if ( ImGui : : CollapsingHeader ( " Help " ) )
{
2023-05-20 16:25:14 +02:00
ImGui : : SeparatorText ( " ABOUT THIS DEMO: " ) ;
2019-11-24 23:11:53 +01:00
ImGui : : BulletText ( " Sections below are demonstrating many aspects of the library. " ) ;
ImGui : : BulletText ( " The \" Examples \" menu above leads to more demo contents. " ) ;
ImGui : : BulletText ( " The \" Tools \" menu above gives access to: About Box, Style Editor, \n "
2020-11-13 21:17:46 +01:00
" and Metrics/Debugger (general purpose Dear ImGui debugging tool). " ) ;
2019-11-24 23:11:53 +01:00
2023-05-20 16:25:14 +02:00
ImGui : : SeparatorText ( " PROGRAMMER GUIDE: " ) ;
2019-11-24 23:11:53 +01:00
ImGui : : BulletText ( " See the ShowDemoWindow() code in imgui_demo.cpp. <- you are here! " ) ;
ImGui : : BulletText ( " See comments in imgui.cpp. " ) ;
ImGui : : BulletText ( " See example applications in the examples/ folder. " ) ;
2024-07-02 16:58:07 +02:00
ImGui : : BulletText ( " Read the FAQ at " ) ;
ImGui : : SameLine ( 0 , 0 ) ;
ImGui : : TextLinkOpenURL ( " https://www.dearimgui.com/faq/ " ) ;
2019-11-24 23:11:53 +01:00
ImGui : : BulletText ( " Set 'io.ConfigFlags |= NavEnableKeyboard' for keyboard controls. " ) ;
ImGui : : BulletText ( " Set 'io.ConfigFlags |= NavEnableGamepad' for gamepad controls. " ) ;
2018-09-05 17:14:37 +02:00
2023-05-20 16:25:14 +02:00
ImGui : : SeparatorText ( " USER GUIDE: " ) ;
2015-07-22 01:00:28 +02:00
ImGui : : ShowUserGuide ( ) ;
}
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Configuration " ) ;
2018-09-05 17:14:37 +02:00
if ( ImGui : : CollapsingHeader ( " Configuration " ) )
2015-07-22 01:00:28 +02:00
{
2018-09-05 17:14:37 +02:00
ImGuiIO & io = ImGui : : GetIO ( ) ;
if ( ImGui : : TreeNode ( " Configuration##2 " ) )
{
2023-02-10 12:16:23 +01:00
ImGui : : SeparatorText ( " General " ) ;
2020-11-05 21:23:02 +01:00
ImGui : : CheckboxFlags ( " io.ConfigFlags: NavEnableKeyboard " , & io . ConfigFlags , ImGuiConfigFlags_NavEnableKeyboard ) ;
2020-11-13 20:59:59 +01:00
ImGui : : SameLine ( ) ; HelpMarker ( " Enable keyboard controls. " ) ;
2020-11-05 21:23:02 +01:00
ImGui : : CheckboxFlags ( " io.ConfigFlags: NavEnableGamepad " , & io . ConfigFlags , ImGuiConfigFlags_NavEnableGamepad ) ;
2020-11-13 20:59:59 +01:00
ImGui : : SameLine ( ) ; HelpMarker ( " Enable gamepad controls. Require backend to set io.BackendFlags |= ImGuiBackendFlags_HasGamepad. \n \n Read instructions in imgui.cpp for details. " ) ;
2020-11-05 21:23:02 +01:00
ImGui : : CheckboxFlags ( " io.ConfigFlags: NoMouse " , & io . ConfigFlags , ImGuiConfigFlags_NoMouse ) ;
2024-06-21 19:08:07 +02:00
ImGui : : SameLine ( ) ; HelpMarker ( " Instruct dear imgui to disable mouse inputs and interactions. " ) ;
// The "NoMouse" option can get us stuck with a disabled mouse! Let's provide an alternative way to fix it:
2020-05-05 19:39:24 +02:00
if ( io . ConfigFlags & ImGuiConfigFlags_NoMouse )
2018-09-05 17:14:37 +02:00
{
if ( fmodf ( ( float ) ImGui : : GetTime ( ) , 0.40f ) < 0.20f )
{
ImGui : : SameLine ( ) ;
ImGui : : Text ( " <<PRESS SPACE TO DISABLE>> " ) ;
}
2024-06-21 19:08:07 +02:00
// Prevent both being checked
if ( ImGui : : IsKeyPressed ( ImGuiKey_Space ) | | ( io . ConfigFlags & ImGuiConfigFlags_NoKeyboard ) )
2018-09-05 17:14:37 +02:00
io . ConfigFlags & = ~ ImGuiConfigFlags_NoMouse ;
}
2024-06-21 19:08:07 +02:00
ImGui : : CheckboxFlags ( " io.ConfigFlags: NoMouseCursorChange " , & io . ConfigFlags , ImGuiConfigFlags_NoMouseCursorChange ) ;
2020-10-12 17:34:22 +02:00
ImGui : : SameLine ( ) ; HelpMarker ( " Instruct backend to not alter mouse cursor shape and visibility. " ) ;
2024-06-21 19:08:07 +02:00
ImGui : : CheckboxFlags ( " io.ConfigFlags: NoKeyboard " , & io . ConfigFlags , ImGuiConfigFlags_NoKeyboard ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Instruct dear imgui to disable keyboard inputs and interactions. " ) ;
2022-01-19 18:45:57 +01:00
ImGui : : Checkbox ( " io.ConfigInputTrickleEventQueue " , & io . ConfigInputTrickleEventQueue ) ;
2022-01-17 17:32:25 +01:00
ImGui : : SameLine ( ) ; HelpMarker ( " Enable input queue trickling: some types of events submitted during the same frame (e.g. button down + up) will be spread over multiple frames, improving interactions with low framerates. " ) ;
2023-02-10 12:16:23 +01:00
ImGui : : Checkbox ( " io.MouseDrawCursor " , & io . MouseDrawCursor ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Instruct Dear ImGui to render a mouse cursor itself. Note that a mouse cursor rendered via your application GPU rendering path will feel more laggy than hardware cursor, but will be more in sync with your other visuals. \n \n Some desktop applications may use both kinds of cursors (e.g. enable software cursor only when resizing/dragging something). " ) ;
2024-10-18 18:28:27 +02:00
ImGui : : SeparatorText ( " Keyboard/Gamepad Navigation " ) ;
2024-10-14 15:28:00 +02:00
ImGui : : Checkbox ( " io.ConfigNavSwapGamepadButtons " , & io . ConfigNavSwapGamepadButtons ) ;
ImGui : : Checkbox ( " io.ConfigNavMoveSetMousePos " , & io . ConfigNavMoveSetMousePos ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Directional/tabbing navigation teleports the mouse cursor. May be useful on TV/console systems where moving a virtual mouse is difficult " ) ;
ImGui : : Checkbox ( " io.ConfigNavCaptureKeyboard " , & io . ConfigNavCaptureKeyboard ) ;
2024-10-17 19:57:18 +02:00
ImGui : : Checkbox ( " io.ConfigNavEscapeClearFocusItem " , & io . ConfigNavEscapeClearFocusItem ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Pressing Escape clears focused item. " ) ;
2024-10-14 16:57:34 +02:00
ImGui : : Checkbox ( " io.ConfigNavEscapeClearFocusWindow " , & io . ConfigNavEscapeClearFocusWindow ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Pressing Escape clears focused window. " ) ;
2024-10-18 18:28:27 +02:00
ImGui : : Checkbox ( " io.ConfigNavCursorVisibleAuto " , & io . ConfigNavCursorVisibleAuto ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Using directional navigation key makes the cursor visible. Mouse click hides the cursor. " ) ;
ImGui : : Checkbox ( " io.ConfigNavCursorVisibleAlways " , & io . ConfigNavCursorVisibleAlways ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Navigation cursor is always visible. " ) ;
2024-10-14 15:28:00 +02:00
2024-10-30 15:41:45 +01:00
ImGui : : SeparatorText ( " Windows " ) ;
2018-12-10 15:36:07 +01:00
ImGui : : Checkbox ( " io.ConfigWindowsResizeFromEdges " , & io . ConfigWindowsResizeFromEdges ) ;
2024-10-30 15:14:02 +01:00
ImGui : : SameLine ( ) ; HelpMarker ( " Enable resizing of windows from their edges and from the lower-left corner. \n This requires ImGuiBackendFlags_HasMouseCursors for better mouse cursor feedback. " ) ;
2018-12-10 16:05:30 +01:00
ImGui : : Checkbox ( " io.ConfigWindowsMoveFromTitleBarOnly " , & io . ConfigWindowsMoveFromTitleBarOnly ) ;
2024-10-30 15:14:02 +01:00
ImGui : : Checkbox ( " io.ConfigWindowsCopyContentsWithCtrlC " , & io . ConfigWindowsCopyContentsWithCtrlC ) ; // [EXPERIMENTAL]
ImGui : : SameLine ( ) ; HelpMarker ( " *EXPERIMENTAL* CTRL+C copy the contents of focused window into the clipboard. \n \n Experimental because: \n - (1) has known issues with nested Begin/End pairs. \n - (2) text output quality varies. \n - (3) text output is in submission order rather than spatial order. " ) ;
2024-09-20 18:40:32 +02:00
ImGui : : Checkbox ( " io.ConfigScrollbarScrollByPage " , & io . ConfigScrollbarScrollByPage ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Enable scrolling page by page when clicking outside the scrollbar grab. \n When disabled, always scroll to clicked location. \n When enabled, Shift+Click scrolls to clicked location. " ) ;
2024-10-30 15:41:45 +01:00
ImGui : : SeparatorText ( " Widgets " ) ;
ImGui : : Checkbox ( " io.ConfigInputTextCursorBlink " , & io . ConfigInputTextCursorBlink ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Enable blinking cursor (optional as some users consider it to be distracting). " ) ;
ImGui : : Checkbox ( " io.ConfigInputTextEnterKeepActive " , & io . ConfigInputTextEnterKeepActive ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Pressing Enter will keep item active and select contents (single-line only). " ) ;
ImGui : : Checkbox ( " io.ConfigDragClickToInputText " , & io . ConfigDragClickToInputText ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Enable turning DragXXX widgets into text input with a simple mouse click-release (without moving). " ) ;
2023-02-01 20:50:45 +01:00
ImGui : : Checkbox ( " io.ConfigMacOSXBehaviors " , & io . ConfigMacOSXBehaviors ) ;
2024-05-15 18:34:21 +02:00
ImGui : : SameLine ( ) ; HelpMarker ( " Swap Cmd<>Ctrl keys, enable various MacOS style behaviors. " ) ;
2020-07-08 17:17:52 +02:00
ImGui : : Text ( " Also see Style->Rendering for rendering options. " ) ;
2023-03-14 15:24:16 +01:00
2024-09-27 19:23:41 +02:00
// Also read: https://github.com/ocornut/imgui/wiki/Error-Handling
2024-09-24 20:51:51 +02:00
ImGui : : SeparatorText ( " Error Handling " ) ;
2024-09-27 19:23:41 +02:00
2024-09-24 20:51:51 +02:00
ImGui : : Checkbox ( " io.ConfigErrorRecovery " , & io . ConfigErrorRecovery ) ;
ImGui : : SameLine ( ) ; HelpMarker (
" Options to configure how we handle recoverable errors. \n "
" - Error recovery is not perfect nor guaranteed! It is a feature to ease development. \n "
" - You not are not supposed to rely on it in the course of a normal application run. \n "
" - Possible usage: facilitate recovery from errors triggered from a scripting language or after specific exceptions handlers. \n "
" - Always ensure that on programmers seat you have at minimum Asserts or Tooltips enabled when making direct imgui API call! "
" Otherwise it would severely hinder your ability to catch and correct mistakes! " ) ;
ImGui : : Checkbox ( " io.ConfigErrorRecoveryEnableAssert " , & io . ConfigErrorRecoveryEnableAssert ) ;
ImGui : : Checkbox ( " io.ConfigErrorRecoveryEnableDebugLog " , & io . ConfigErrorRecoveryEnableDebugLog ) ;
ImGui : : Checkbox ( " io.ConfigErrorRecoveryEnableTooltip " , & io . ConfigErrorRecoveryEnableTooltip ) ;
if ( ! io . ConfigErrorRecoveryEnableAssert & & ! io . ConfigErrorRecoveryEnableDebugLog & & ! io . ConfigErrorRecoveryEnableTooltip )
io . ConfigErrorRecoveryEnableAssert = io . ConfigErrorRecoveryEnableDebugLog = io . ConfigErrorRecoveryEnableTooltip = true ;
2024-09-27 19:23:41 +02:00
// Also read: https://github.com/ocornut/imgui/wiki/Debug-Tools
2023-03-14 15:24:16 +01:00
ImGui : : SeparatorText ( " Debug " ) ;
2024-01-10 15:35:35 +01:00
ImGui : : Checkbox ( " io.ConfigDebugIsDebuggerPresent " , & io . ConfigDebugIsDebuggerPresent ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Enable various tools calling IM_DEBUG_BREAK(). \n \n Requires a debugger being attached, otherwise IM_DEBUG_BREAK() options will appear to crash your application. " ) ;
Added io.ConfigDebugHighlightIdConflicts debug feature! (#7961, #7669)
Also #74, #96, #480, #501, #647, #654, #719, #843, #894, #1057, #1173, #1390, #1414, #1556, #1768, #2041, #2116, #2330, #2475, #2562, #2667, #2807, #2885, #3102, #3375, #3526, #3964, #4008, #4070, #4158, #4172, #4199, #4375, #4395, #4471, #4548, #4612, #4631, #4657, #4796, #5210, #5303, #5360, #5393, #5533, #5692, #5707, #5729, #5773, #5787, #5884, #6046, #6093, #6186, #6223, #6364, #6387, #6567, #6692, #6724, #6939, #6984, #7246, #7270, #7375, #7421, #7434, #7472, #7581, #7724, #7926, #7937 and probably more.. Tagging to increase visibility!
2024-09-10 15:28:40 +02:00
ImGui : : Checkbox ( " io.ConfigDebugHighlightIdConflicts " , & io . ConfigDebugHighlightIdConflicts ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Highlight and show an error message when multiple items have conflicting identifiers. " ) ;
2023-03-14 15:24:16 +01:00
ImGui : : BeginDisabled ( ) ;
2024-09-09 21:07:10 +02:00
ImGui : : Checkbox ( " io.ConfigDebugBeginReturnValueOnce " , & io . ConfigDebugBeginReturnValueOnce ) ;
2023-03-14 15:24:16 +01:00
ImGui : : EndDisabled ( ) ;
2024-01-10 15:35:35 +01:00
ImGui : : SameLine ( ) ; HelpMarker ( " First calls to Begin()/BeginChild() will return false. \n \n THIS OPTION IS DISABLED because it needs to be set at application boot-time to make sense. Showing the disabled option is a way to make this feature easier to discover. " ) ;
2023-03-14 15:24:16 +01:00
ImGui : : Checkbox ( " io.ConfigDebugBeginReturnValueLoop " , & io . ConfigDebugBeginReturnValueLoop ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Some calls to Begin()/BeginChild() will return false. \n \n Will cycle through window depths then repeat. Windows should be flickering while running. " ) ;
2023-05-09 20:28:08 +02:00
ImGui : : Checkbox ( " io.ConfigDebugIgnoreFocusLoss " , & io . ConfigDebugIgnoreFocusLoss ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Option to deactivate io.AddFocusEvent(false) handling. May facilitate interactions with a debugger when focus loss leads to clearing inputs data. " ) ;
2023-06-13 11:47:22 +02:00
ImGui : : Checkbox ( " io.ConfigDebugIniSettings " , & io . ConfigDebugIniSettings ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Option to save .ini data with extra comments (particularly helpful for Docking, but makes saving slower). " ) ;
2023-03-14 15:24:16 +01:00
2018-09-05 17:14:37 +02:00
ImGui : : TreePop ( ) ;
2023-02-10 12:16:23 +01:00
ImGui : : Spacing ( ) ;
2018-09-05 17:14:37 +02:00
}
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Configuration/Backend Flags " ) ;
2018-09-05 17:14:37 +02:00
if ( ImGui : : TreeNode ( " Backend Flags " ) )
{
2020-05-05 19:39:24 +02:00
HelpMarker (
2020-10-12 17:34:22 +02:00
" Those flags are set by the backends (imgui_impl_xxx files) to specify their capabilities. \n "
2021-08-17 13:48:34 +02:00
" Here we expose them as read-only fields to avoid breaking interactions with your backend. " ) ;
2020-05-05 19:39:24 +02:00
2023-04-04 21:43:48 +02:00
// FIXME: Maybe we need a BeginReadonly() equivalent to keep label bright?
ImGui : : BeginDisabled ( ) ;
ImGui : : CheckboxFlags ( " io.BackendFlags: HasGamepad " , & io . BackendFlags , ImGuiBackendFlags_HasGamepad ) ;
ImGui : : CheckboxFlags ( " io.BackendFlags: HasMouseCursors " , & io . BackendFlags , ImGuiBackendFlags_HasMouseCursors ) ;
ImGui : : CheckboxFlags ( " io.BackendFlags: HasSetMousePos " , & io . BackendFlags , ImGuiBackendFlags_HasSetMousePos ) ;
ImGui : : CheckboxFlags ( " io.BackendFlags: RendererHasVtxOffset " , & io . BackendFlags , ImGuiBackendFlags_RendererHasVtxOffset ) ;
ImGui : : EndDisabled ( ) ;
2024-09-27 19:23:41 +02:00
2018-09-05 17:14:37 +02:00
ImGui : : TreePop ( ) ;
2023-02-10 12:16:23 +01:00
ImGui : : Spacing ( ) ;
2018-09-05 17:14:37 +02:00
}
2015-12-13 15:03:26 +01:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Configuration/Style " ) ;
2015-07-22 01:00:28 +02:00
if ( ImGui : : TreeNode ( " Style " ) )
{
2024-07-30 11:44:13 +02:00
ImGui : : Checkbox ( " Style Editor " , & demo_data . ShowStyleEditor ) ;
2024-07-02 14:38:44 +02:00
ImGui : : SameLine ( ) ;
2019-11-24 23:11:53 +01:00
HelpMarker ( " The same contents can be accessed in 'Tools->Style Editor' or by calling the ShowStyleEditor() function. " ) ;
2015-07-22 01:00:28 +02:00
ImGui : : TreePop ( ) ;
2023-02-10 12:16:23 +01:00
ImGui : : Spacing ( ) ;
2015-07-22 01:00:28 +02:00
}
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Configuration/Capture, Logging " ) ;
2017-12-10 17:02:41 +01:00
if ( ImGui : : TreeNode ( " Capture/Logging " ) )
2015-07-22 01:00:28 +02:00
{
2020-05-05 19:39:24 +02:00
HelpMarker (
" The logging API redirects all text output so you can easily capture the content of "
" a window or a block. Tree nodes can be automatically expanded. \n "
" Try opening any of the contents below in this window and then click one of the \" Log To \" button. " ) ;
2015-07-22 01:00:28 +02:00
ImGui : : LogButtons ( ) ;
2020-05-05 19:39:24 +02:00
HelpMarker ( " You can also call ImGui::LogText() to output directly to the log without a visual output. " ) ;
2018-09-05 17:14:37 +02:00
if ( ImGui : : Button ( " Copy \" Hello, world! \" to clipboard " ) )
{
ImGui : : LogToClipboard ( ) ;
ImGui : : LogText ( " Hello, world! " ) ;
ImGui : : LogFinish ( ) ;
}
2015-07-22 01:00:28 +02:00
ImGui : : TreePop ( ) ;
}
}
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Window options " ) ;
2018-09-05 17:14:37 +02:00
if ( ImGui : : CollapsingHeader ( " Window options " ) )
{
2020-11-18 17:28:18 +01:00
if ( ImGui : : BeginTable ( " split " , 3 ) )
{
ImGui : : TableNextColumn ( ) ; ImGui : : Checkbox ( " No titlebar " , & no_titlebar ) ;
ImGui : : TableNextColumn ( ) ; ImGui : : Checkbox ( " No scrollbar " , & no_scrollbar ) ;
ImGui : : TableNextColumn ( ) ; ImGui : : Checkbox ( " No menu " , & no_menu ) ;
ImGui : : TableNextColumn ( ) ; ImGui : : Checkbox ( " No move " , & no_move ) ;
ImGui : : TableNextColumn ( ) ; ImGui : : Checkbox ( " No resize " , & no_resize ) ;
ImGui : : TableNextColumn ( ) ; ImGui : : Checkbox ( " No collapse " , & no_collapse ) ;
ImGui : : TableNextColumn ( ) ; ImGui : : Checkbox ( " No close " , & no_close ) ;
ImGui : : TableNextColumn ( ) ; ImGui : : Checkbox ( " No nav " , & no_nav ) ;
ImGui : : TableNextColumn ( ) ; ImGui : : Checkbox ( " No background " , & no_background ) ;
ImGui : : TableNextColumn ( ) ; ImGui : : Checkbox ( " No bring to front " , & no_bring_to_front ) ;
2021-06-24 14:30:32 +02:00
ImGui : : TableNextColumn ( ) ; ImGui : : Checkbox ( " Unsaved document " , & unsaved_document ) ;
2020-11-18 17:28:18 +01:00
ImGui : : EndTable ( ) ;
}
2018-09-05 17:14:37 +02:00
}
2018-10-25 23:34:05 +02:00
// All demo contents
2024-07-30 11:44:13 +02:00
ShowDemoWindowWidgets ( & demo_data ) ;
2018-10-25 23:34:05 +02:00
ShowDemoWindowLayout ( ) ;
ShowDemoWindowPopups ( ) ;
2019-12-19 14:52:18 +01:00
ShowDemoWindowTables ( ) ;
2022-09-14 20:13:15 +02:00
ShowDemoWindowInputs ( ) ;
2018-10-25 23:34:05 +02:00
// End of ShowDemoWindow()
2020-11-20 17:24:18 +01:00
ImGui : : PopItemWidth ( ) ;
2018-10-25 23:34:05 +02:00
ImGui : : End ( ) ;
}
2024-07-19 15:46:51 +02:00
//-----------------------------------------------------------------------------
// [SECTION] ShowDemoWindowMenuBar()
//-----------------------------------------------------------------------------
2024-07-30 11:44:13 +02:00
static void ShowDemoWindowMenuBar ( ImGuiDemoWindowData * demo_data )
2024-07-19 15:46:51 +02:00
{
IMGUI_DEMO_MARKER ( " Menu " ) ;
if ( ImGui : : BeginMenuBar ( ) )
{
if ( ImGui : : BeginMenu ( " Menu " ) )
{
IMGUI_DEMO_MARKER ( " Menu/File " ) ;
ShowExampleMenuFile ( ) ;
ImGui : : EndMenu ( ) ;
}
if ( ImGui : : BeginMenu ( " Examples " ) )
{
IMGUI_DEMO_MARKER ( " Menu/Examples " ) ;
ImGui : : MenuItem ( " Main menu bar " , NULL , & demo_data - > ShowMainMenuBar ) ;
ImGui : : SeparatorText ( " Mini apps " ) ;
ImGui : : MenuItem ( " Assets Browser " , NULL , & demo_data - > ShowAppAssetsBrowser ) ;
ImGui : : MenuItem ( " Console " , NULL , & demo_data - > ShowAppConsole ) ;
ImGui : : MenuItem ( " Custom rendering " , NULL , & demo_data - > ShowAppCustomRendering ) ;
ImGui : : MenuItem ( " Documents " , NULL , & demo_data - > ShowAppDocuments ) ;
ImGui : : MenuItem ( " Log " , NULL , & demo_data - > ShowAppLog ) ;
ImGui : : MenuItem ( " Property editor " , NULL , & demo_data - > ShowAppPropertyEditor ) ;
ImGui : : MenuItem ( " Simple layout " , NULL , & demo_data - > ShowAppLayout ) ;
ImGui : : MenuItem ( " Simple overlay " , NULL , & demo_data - > ShowAppSimpleOverlay ) ;
ImGui : : SeparatorText ( " Concepts " ) ;
ImGui : : MenuItem ( " Auto-resizing window " , NULL , & demo_data - > ShowAppAutoResize ) ;
ImGui : : MenuItem ( " Constrained-resizing window " , NULL , & demo_data - > ShowAppConstrainedResize ) ;
ImGui : : MenuItem ( " Fullscreen window " , NULL , & demo_data - > ShowAppFullscreen ) ;
ImGui : : MenuItem ( " Long text display " , NULL , & demo_data - > ShowAppLongText ) ;
ImGui : : MenuItem ( " Manipulating window titles " , NULL , & demo_data - > ShowAppWindowTitles ) ;
ImGui : : EndMenu ( ) ;
}
//if (ImGui::MenuItem("MenuItem")) {} // You can also use MenuItem() inside a menu bar!
if ( ImGui : : BeginMenu ( " Tools " ) )
{
IMGUI_DEMO_MARKER ( " Menu/Tools " ) ;
Added io.ConfigDebugHighlightIdConflicts debug feature! (#7961, #7669)
Also #74, #96, #480, #501, #647, #654, #719, #843, #894, #1057, #1173, #1390, #1414, #1556, #1768, #2041, #2116, #2330, #2475, #2562, #2667, #2807, #2885, #3102, #3375, #3526, #3964, #4008, #4070, #4158, #4172, #4199, #4375, #4395, #4471, #4548, #4612, #4631, #4657, #4796, #5210, #5303, #5360, #5393, #5533, #5692, #5707, #5729, #5773, #5787, #5884, #6046, #6093, #6186, #6223, #6364, #6387, #6567, #6692, #6724, #6939, #6984, #7246, #7270, #7375, #7421, #7434, #7472, #7581, #7724, #7926, #7937 and probably more.. Tagging to increase visibility!
2024-09-10 15:28:40 +02:00
ImGuiIO & io = ImGui : : GetIO ( ) ;
2024-07-19 15:46:51 +02:00
# ifndef IMGUI_DISABLE_DEBUG_TOOLS
const bool has_debug_tools = true ;
# else
const bool has_debug_tools = false ;
# endif
ImGui : : MenuItem ( " Metrics/Debugger " , NULL , & demo_data - > ShowMetrics , has_debug_tools ) ;
ImGui : : MenuItem ( " Debug Log " , NULL , & demo_data - > ShowDebugLog , has_debug_tools ) ;
ImGui : : MenuItem ( " ID Stack Tool " , NULL , & demo_data - > ShowIDStackTool , has_debug_tools ) ;
Added io.ConfigDebugHighlightIdConflicts debug feature! (#7961, #7669)
Also #74, #96, #480, #501, #647, #654, #719, #843, #894, #1057, #1173, #1390, #1414, #1556, #1768, #2041, #2116, #2330, #2475, #2562, #2667, #2807, #2885, #3102, #3375, #3526, #3964, #4008, #4070, #4158, #4172, #4199, #4375, #4395, #4471, #4548, #4612, #4631, #4657, #4796, #5210, #5303, #5360, #5393, #5533, #5692, #5707, #5729, #5773, #5787, #5884, #6046, #6093, #6186, #6223, #6364, #6387, #6567, #6692, #6724, #6939, #6984, #7246, #7270, #7375, #7421, #7434, #7472, #7581, #7724, #7926, #7937 and probably more.. Tagging to increase visibility!
2024-09-10 15:28:40 +02:00
bool is_debugger_present = io . ConfigDebugIsDebuggerPresent ;
2024-07-19 15:46:51 +02:00
if ( ImGui : : MenuItem ( " Item Picker " , NULL , false , has_debug_tools & & is_debugger_present ) )
ImGui : : DebugStartItemPicker ( ) ;
if ( ! is_debugger_present )
ImGui : : SetItemTooltip ( " Requires io.ConfigDebugIsDebuggerPresent=true to be set. \n \n We otherwise disable the menu option to avoid casual users crashing the application. \n \n You can however always access the Item Picker in Metrics->Tools. " ) ;
Added io.ConfigDebugHighlightIdConflicts debug feature! (#7961, #7669)
Also #74, #96, #480, #501, #647, #654, #719, #843, #894, #1057, #1173, #1390, #1414, #1556, #1768, #2041, #2116, #2330, #2475, #2562, #2667, #2807, #2885, #3102, #3375, #3526, #3964, #4008, #4070, #4158, #4172, #4199, #4375, #4395, #4471, #4548, #4612, #4631, #4657, #4796, #5210, #5303, #5360, #5393, #5533, #5692, #5707, #5729, #5773, #5787, #5884, #6046, #6093, #6186, #6223, #6364, #6387, #6567, #6692, #6724, #6939, #6984, #7246, #7270, #7375, #7421, #7434, #7472, #7581, #7724, #7926, #7937 and probably more.. Tagging to increase visibility!
2024-09-10 15:28:40 +02:00
ImGui : : MenuItem ( " Style Editor " , NULL , & demo_data - > ShowStyleEditor ) ;
2024-07-19 15:46:51 +02:00
ImGui : : MenuItem ( " About Dear ImGui " , NULL , & demo_data - > ShowAbout ) ;
Added io.ConfigDebugHighlightIdConflicts debug feature! (#7961, #7669)
Also #74, #96, #480, #501, #647, #654, #719, #843, #894, #1057, #1173, #1390, #1414, #1556, #1768, #2041, #2116, #2330, #2475, #2562, #2667, #2807, #2885, #3102, #3375, #3526, #3964, #4008, #4070, #4158, #4172, #4199, #4375, #4395, #4471, #4548, #4612, #4631, #4657, #4796, #5210, #5303, #5360, #5393, #5533, #5692, #5707, #5729, #5773, #5787, #5884, #6046, #6093, #6186, #6223, #6364, #6387, #6567, #6692, #6724, #6939, #6984, #7246, #7270, #7375, #7421, #7434, #7472, #7581, #7724, #7926, #7937 and probably more.. Tagging to increase visibility!
2024-09-10 15:28:40 +02:00
ImGui : : SeparatorText ( " Debug Options " ) ;
ImGui : : MenuItem ( " Highlight ID Conflicts " , NULL , & io . ConfigDebugHighlightIdConflicts , has_debug_tools ) ;
2024-07-19 15:46:51 +02:00
ImGui : : EndMenu ( ) ;
}
ImGui : : EndMenuBar ( ) ;
}
}
2024-07-19 12:35:57 +02:00
//-----------------------------------------------------------------------------
// [SECTION] ShowDemoWindowWidgets()
//-----------------------------------------------------------------------------
2024-07-30 11:44:13 +02:00
static void ShowDemoWindowWidgets ( ImGuiDemoWindowData * demo_data )
2018-10-25 23:34:05 +02:00
{
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets " ) ;
2023-04-12 19:48:58 +02:00
//ImGui::SetNextItemOpen(true, ImGuiCond_Once);
2018-10-25 23:40:33 +02:00
if ( ! ImGui : : CollapsingHeader ( " Widgets " ) )
return ;
2021-07-19 19:21:18 +02:00
static bool disable_all = false ; // The Checkbox for that is inside the "Disabled" section at the bottom
if ( disable_all )
ImGui : : BeginDisabled ( ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Basic " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Basic " ) )
2015-07-22 01:00:28 +02:00
{
2023-02-10 12:16:23 +01:00
ImGui : : SeparatorText ( " General " ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Basic/Button " ) ;
2018-10-25 23:40:33 +02:00
static int clicked = 0 ;
if ( ImGui : : Button ( " Button " ) )
clicked + + ;
if ( clicked & 1 )
2017-08-08 12:04:31 +02:00
{
2018-10-25 23:40:33 +02:00
ImGui : : SameLine ( ) ;
ImGui : : Text ( " Thanks for clicking me! " ) ;
}
2017-08-08 12:04:31 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Basic/Checkbox " ) ;
2018-10-25 23:40:33 +02:00
static bool check = true ;
ImGui : : Checkbox ( " checkbox " , & check ) ;
2017-08-08 12:04:31 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Basic/RadioButton " ) ;
2018-10-25 23:40:33 +02:00
static int e = 0 ;
ImGui : : RadioButton ( " radio a " , & e , 0 ) ; ImGui : : SameLine ( ) ;
ImGui : : RadioButton ( " radio b " , & e , 1 ) ; ImGui : : SameLine ( ) ;
ImGui : : RadioButton ( " radio c " , & e , 2 ) ;
2017-08-08 12:04:31 +02:00
2018-10-25 23:40:33 +02:00
// Color buttons, demonstrate using PushID() to add unique identifier in the ID stack, and changing style.
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Basic/Buttons (Colored) " ) ;
2018-10-25 23:40:33 +02:00
for ( int i = 0 ; i < 7 ; i + + )
{
2019-01-20 17:56:17 +01:00
if ( i > 0 )
2018-10-25 23:40:33 +02:00
ImGui : : SameLine ( ) ;
ImGui : : PushID ( i ) ;
2020-06-30 15:31:54 +02:00
ImGui : : PushStyleColor ( ImGuiCol_Button , ( ImVec4 ) ImColor : : HSV ( i / 7.0f , 0.6f , 0.6f ) ) ;
ImGui : : PushStyleColor ( ImGuiCol_ButtonHovered , ( ImVec4 ) ImColor : : HSV ( i / 7.0f , 0.7f , 0.7f ) ) ;
ImGui : : PushStyleColor ( ImGuiCol_ButtonActive , ( ImVec4 ) ImColor : : HSV ( i / 7.0f , 0.8f , 0.8f ) ) ;
2018-10-25 23:40:33 +02:00
ImGui : : Button ( " Click " ) ;
ImGui : : PopStyleColor ( 3 ) ;
ImGui : : PopID ( ) ;
}
2018-09-20 10:24:29 +02:00
2020-05-05 19:39:24 +02:00
// Use AlignTextToFramePadding() to align text baseline to the baseline of framed widgets elements
// (otherwise a Text+SameLine+Button sequence will have the text a little too high by default!)
// See 'Demo->Layout->Text Baseline Alignment' for details.
2018-10-25 23:40:33 +02:00
ImGui : : AlignTextToFramePadding ( ) ;
ImGui : : Text ( " Hold to repeat: " ) ;
ImGui : : SameLine ( ) ;
// Arrow buttons with Repeater
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Basic/Buttons (Repeating) " ) ;
2018-10-25 23:40:33 +02:00
static int counter = 0 ;
float spacing = ImGui : : GetStyle ( ) . ItemInnerSpacing . x ;
2024-07-15 17:46:32 +02:00
ImGui : : PushItemFlag ( ImGuiItemFlags_ButtonRepeat , true ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : ArrowButton ( " ##left " , ImGuiDir_Left ) ) { counter - - ; }
ImGui : : SameLine ( 0.0f , spacing ) ;
if ( ImGui : : ArrowButton ( " ##right " , ImGuiDir_Right ) ) { counter + + ; }
2024-07-15 17:46:32 +02:00
ImGui : : PopItemFlag ( ) ;
2018-10-25 23:40:33 +02:00
ImGui : : SameLine ( ) ;
ImGui : : Text ( " %d " , counter ) ;
2023-06-16 16:42:56 +02:00
ImGui : : Button ( " Tooltip " ) ;
ImGui : : SetItemTooltip ( " I am a tooltip " ) ;
2017-08-08 12:04:31 +02:00
2023-01-27 19:01:30 +01:00
ImGui : : LabelText ( " label " , " Value " ) ;
2023-02-10 12:16:23 +01:00
ImGui : : SeparatorText ( " Inputs " ) ;
2018-10-25 23:40:33 +02:00
{
2020-01-06 15:21:33 +01:00
// To wire InputText() with std::string or any other custom string type,
2019-12-25 17:46:35 +01:00
// see the "Text Input > Resize Callback" section of this demo, and the misc/cpp/imgui_stdlib.h file.
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Basic/InputText " ) ;
2018-10-25 23:40:33 +02:00
static char str0 [ 128 ] = " Hello, world! " ;
ImGui : : InputText ( " input text " , str0 , IM_ARRAYSIZE ( str0 ) ) ;
2020-05-05 19:39:24 +02:00
ImGui : : SameLine ( ) ; HelpMarker (
" USER: \n "
" Hold SHIFT or use mouse to select text. \n "
" CTRL+Left/Right to word jump. \n "
2022-09-11 07:35:59 +02:00
" CTRL+A or Double-Click to select all. \n "
2020-05-05 19:39:24 +02:00
" CTRL+X,CTRL+C,CTRL+V clipboard. \n "
" CTRL+Z,CTRL+Y undo/redo. \n "
" ESCAPE to revert. \n \n "
" PROGRAMMER: \n "
" You can use the ImGuiInputTextFlags_CallbackResize facility if you need to wire InputText() "
" to a dynamic string type. See misc/cpp/imgui_stdlib.h for an example (this is not demonstrated "
" in imgui_demo.cpp). " ) ;
2017-08-08 12:04:31 +02:00
2019-03-06 14:31:19 +01:00
static char str1 [ 128 ] = " " ;
ImGui : : InputTextWithHint ( " input text (w/ hint) " , " enter text here " , str1 , IM_ARRAYSIZE ( str1 ) ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Basic/InputInt, InputFloat " ) ;
2019-03-06 14:31:19 +01:00
static int i0 = 123 ;
2018-10-25 23:40:33 +02:00
ImGui : : InputInt ( " input int " , & i0 ) ;
2017-08-08 12:04:31 +02:00
2018-10-25 23:40:33 +02:00
static float f0 = 0.001f ;
2019-01-02 11:03:56 +01:00
ImGui : : InputFloat ( " input float " , & f0 , 0.01f , 1.0f , " %.3f " ) ;
2017-08-08 12:04:31 +02:00
2018-10-25 23:40:33 +02:00
static double d0 = 999999.00000001 ;
ImGui : : InputDouble ( " input double " , & d0 , 0.01f , 1.0f , " %.8f " ) ;
2017-08-08 12:04:31 +02:00
2018-10-25 23:40:33 +02:00
static float f1 = 1.e10 f ;
ImGui : : InputFloat ( " input scientific " , & f1 , 0.0f , 0.0f , " %e " ) ;
2020-05-05 19:39:24 +02:00
ImGui : : SameLine ( ) ; HelpMarker (
" You can input value using the scientific notation, \n "
" e.g. \" 1e+8 \" becomes \" 100000000 \" . " ) ;
2017-08-08 12:04:31 +02:00
2018-10-25 23:40:33 +02:00
static float vec4a [ 4 ] = { 0.10f , 0.20f , 0.30f , 0.44f } ;
ImGui : : InputFloat3 ( " input float3 " , vec4a ) ;
}
2018-04-28 00:11:40 +02:00
2023-02-10 12:16:23 +01:00
ImGui : : SeparatorText ( " Drags " ) ;
2018-10-25 23:40:33 +02:00
{
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Basic/DragInt, DragFloat " ) ;
2024-06-28 15:54:40 +02:00
static int i1 = 50 , i2 = 42 , i3 = 128 ;
2018-10-25 23:40:33 +02:00
ImGui : : DragInt ( " drag int " , & i1 , 1 ) ;
2020-05-05 19:39:24 +02:00
ImGui : : SameLine ( ) ; HelpMarker (
" Click and drag to edit value. \n "
" Hold SHIFT/ALT for faster/slower edit. \n "
" Double-click or CTRL+click to input value. " ) ;
2020-09-25 13:34:31 +02:00
ImGui : : DragInt ( " drag int 0..100 " , & i2 , 1 , 0 , 100 , " %d%% " , ImGuiSliderFlags_AlwaysClamp ) ;
2024-06-28 18:06:16 +02:00
ImGui : : DragInt ( " drag int wrap 100..200 " , & i3 , 1 , 100 , 200 , " %d " , ImGuiSliderFlags_WrapAround ) ;
2017-08-08 12:04:31 +02:00
2020-06-30 15:31:54 +02:00
static float f1 = 1.00f , f2 = 0.0067f ;
2018-10-25 23:40:33 +02:00
ImGui : : DragFloat ( " drag float " , & f1 , 0.005f ) ;
ImGui : : DragFloat ( " drag small float " , & f2 , 0.0001f , 0.0f , 0.0f , " %.06f ns " ) ;
2024-06-28 18:06:16 +02:00
//ImGui::DragFloat("drag wrap -1..1", &f3, 0.005f, -1.0f, 1.0f, NULL, ImGuiSliderFlags_WrapAround);
2018-10-25 23:40:33 +02:00
}
2017-08-08 12:04:31 +02:00
2023-02-10 12:16:23 +01:00
ImGui : : SeparatorText ( " Sliders " ) ;
2018-10-25 23:40:33 +02:00
{
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Basic/SliderInt, SliderFloat " ) ;
2020-06-30 15:31:54 +02:00
static int i1 = 0 ;
2018-10-25 23:40:33 +02:00
ImGui : : SliderInt ( " slider int " , & i1 , - 1 , 3 ) ;
2019-03-06 18:19:28 +01:00
ImGui : : SameLine ( ) ; HelpMarker ( " CTRL+click to input value. " ) ;
2018-10-25 23:40:33 +02:00
2020-06-30 15:31:54 +02:00
static float f1 = 0.123f , f2 = 0.0f ;
2018-10-25 23:40:33 +02:00
ImGui : : SliderFloat ( " slider float " , & f1 , 0.0f , 1.0f , " ratio = %.3f " ) ;
2020-07-22 18:00:50 +02:00
ImGui : : SliderFloat ( " slider float (log) " , & f2 , - 10.0f , 10.0f , " %.4f " , ImGuiSliderFlags_Logarithmic ) ;
2019-07-26 21:08:29 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Basic/SliderAngle " ) ;
2018-10-25 23:40:33 +02:00
static float angle = 0.0f ;
ImGui : : SliderAngle ( " slider angle " , & angle ) ;
2019-07-26 21:08:29 +02:00
// Using the format string to display a name instead of an integer.
// Here we completely omit '%d' from the format string, so it'll only display a name.
// This technique can also be used with DragInt().
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Basic/Slider (enum) " ) ;
2019-07-26 21:08:29 +02:00
enum Element { Element_Fire , Element_Earth , Element_Air , Element_Water , Element_COUNT } ;
2020-05-05 19:39:24 +02:00
static int elem = Element_Fire ;
const char * elems_names [ Element_COUNT ] = { " Fire " , " Earth " , " Air " , " Water " } ;
const char * elem_name = ( elem > = 0 & & elem < Element_COUNT ) ? elems_names [ elem ] : " Unknown " ;
2023-05-09 12:04:04 +02:00
ImGui : : SliderInt ( " slider enum " , & elem , 0 , Element_COUNT - 1 , elem_name ) ; // Use ImGuiSliderFlags_NoInput flag to disable CTRL+Click here.
2019-07-26 21:08:29 +02:00
ImGui : : SameLine ( ) ; HelpMarker ( " Using the format string parameter to display a name instead of the underlying integer. " ) ;
2018-10-25 23:40:33 +02:00
}
2017-08-08 12:04:31 +02:00
2023-02-10 12:16:23 +01:00
ImGui : : SeparatorText ( " Selectors/Pickers " ) ;
2018-10-25 23:40:33 +02:00
{
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Basic/ColorEdit3, ColorEdit4 " ) ;
2020-06-30 15:31:54 +02:00
static float col1 [ 3 ] = { 1.0f , 0.0f , 0.2f } ;
static float col2 [ 4 ] = { 0.4f , 0.7f , 0.0f , 0.5f } ;
2018-10-25 23:40:33 +02:00
ImGui : : ColorEdit3 ( " color 1 " , col1 ) ;
2020-05-05 19:39:24 +02:00
ImGui : : SameLine ( ) ; HelpMarker (
2020-10-15 20:05:35 +02:00
" Click on the color square to open a color picker. \n "
2020-05-05 19:39:24 +02:00
" Click and hold to use drag and drop. \n "
2020-10-15 20:05:35 +02:00
" Right-click on the color square to show options. \n "
2020-05-05 19:39:24 +02:00
" CTRL+click on individual component to input value. \n " ) ;
2017-08-08 12:04:31 +02:00
2018-10-25 23:40:33 +02:00
ImGui : : ColorEdit4 ( " color 2 " , col2 ) ;
}
2017-08-08 12:04:31 +02:00
2023-01-27 19:01:30 +01:00
{
// Using the _simplified_ one-liner Combo() api here
// See "Combo" section for examples of how to use the more flexible BeginCombo()/EndCombo() api.
IMGUI_DEMO_MARKER ( " Widgets/Basic/Combo " ) ;
const char * items [ ] = { " AAAA " , " BBBB " , " CCCC " , " DDDD " , " EEEE " , " FFFF " , " GGGG " , " HHHH " , " IIIIIII " , " JJJJ " , " KKKKKKK " } ;
static int item_current = 0 ;
ImGui : : Combo ( " combo " , & item_current , items , IM_ARRAYSIZE ( items ) ) ;
ImGui : : SameLine ( ) ; HelpMarker (
2024-01-04 11:50:38 +01:00
" Using the simplified one-liner Combo API here. \n "
" Refer to the \" Combo \" section below for an explanation of how to use the more flexible and general BeginCombo/EndCombo API. " ) ;
2023-01-27 19:01:30 +01:00
}
2018-10-25 23:40:33 +02:00
{
2021-02-03 16:30:23 +01:00
// Using the _simplified_ one-liner ListBox() api here
// See "List boxes" section for examples of how to use the more flexible BeginListBox()/EndListBox() api.
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Basic/ListBox " ) ;
2020-05-05 19:39:24 +02:00
const char * items [ ] = { " Apple " , " Banana " , " Cherry " , " Kiwi " , " Mango " , " Orange " , " Pineapple " , " Strawberry " , " Watermelon " } ;
static int item_current = 1 ;
2021-02-03 16:30:23 +01:00
ImGui : : ListBox ( " listbox " , & item_current , items , IM_ARRAYSIZE ( items ) , 4 ) ;
ImGui : : SameLine ( ) ; HelpMarker (
2024-01-04 11:50:38 +01:00
" Using the simplified one-liner ListBox API here. \n "
" Refer to the \" List boxes \" section below for an explanation of how to use the more flexible and general BeginListBox/EndListBox API. " ) ;
2018-10-25 23:40:33 +02:00
}
2017-08-08 12:04:31 +02:00
2018-10-25 23:40:33 +02:00
ImGui : : TreePop ( ) ;
}
2017-08-08 12:04:31 +02:00
2023-06-16 16:42:56 +02:00
IMGUI_DEMO_MARKER ( " Widgets/Tooltips " ) ;
if ( ImGui : : TreeNode ( " Tooltips " ) )
{
// Tooltips are windows following the mouse. They do not take focus away.
ImGui : : SeparatorText ( " General " ) ;
// Typical use cases:
// - Short-form (text only): SetItemTooltip("Hello");
// - Short-form (any contents): if (BeginItemTooltip()) { Text("Hello"); EndTooltip(); }
// - Full-form (text only): if (IsItemHovered(...)) { SetTooltip("Hello"); }
// - Full-form (any contents): if (IsItemHovered(...) && BeginTooltip()) { Text("Hello"); EndTooltip(); }
HelpMarker (
2023-06-28 16:01:01 +02:00
" Tooltip are typically created by using a IsItemHovered() + SetTooltip() sequence. \n \n "
2023-06-16 16:42:56 +02:00
" We provide a helper SetItemTooltip() function to perform the two with standards flags. " ) ;
ImVec2 sz = ImVec2 ( - FLT_MIN , 0.0f ) ;
ImGui : : Button ( " Basic " , sz ) ;
ImGui : : SetItemTooltip ( " I am a tooltip " ) ;
ImGui : : Button ( " Fancy " , sz ) ;
if ( ImGui : : BeginItemTooltip ( ) )
{
ImGui : : Text ( " I am a fancy tooltip " ) ;
static float arr [ ] = { 0.6f , 0.1f , 1.0f , 0.5f , 0.92f , 0.1f , 0.2f } ;
ImGui : : PlotLines ( " Curve " , arr , IM_ARRAYSIZE ( arr ) ) ;
ImGui : : Text ( " Sin(time) = %f " , sinf ( ( float ) ImGui : : GetTime ( ) ) ) ;
ImGui : : EndTooltip ( ) ;
}
2023-06-28 16:01:01 +02:00
ImGui : : SeparatorText ( " Always On " ) ;
2023-06-16 16:42:56 +02:00
// Showcase NOT relying on a IsItemHovered() to emit a tooltip.
2023-06-28 16:01:01 +02:00
// Here the tooltip is always emitted when 'always_on == true'.
static int always_on = 0 ;
ImGui : : RadioButton ( " Off " , & always_on , 0 ) ;
ImGui : : SameLine ( ) ;
ImGui : : RadioButton ( " Always On (Simple) " , & always_on , 1 ) ;
ImGui : : SameLine ( ) ;
ImGui : : RadioButton ( " Always On (Advanced) " , & always_on , 2 ) ;
if ( always_on = = 1 )
2023-06-16 16:42:56 +02:00
ImGui : : SetTooltip ( " I am following you around. " ) ;
2023-06-28 16:01:01 +02:00
else if ( always_on = = 2 & & ImGui : : BeginTooltip ( ) )
{
ImGui : : ProgressBar ( sinf ( ( float ) ImGui : : GetTime ( ) ) * 0.5f + 0.5f , ImVec2 ( ImGui : : GetFontSize ( ) * 25 , 0.0f ) ) ;
ImGui : : EndTooltip ( ) ;
}
ImGui : : SeparatorText ( " Custom " ) ;
2023-06-16 16:42:56 +02:00
2023-09-12 11:55:34 +02:00
HelpMarker (
" Passing ImGuiHoveredFlags_ForTooltip to IsItemHovered() is the preferred way to standardize "
" tooltip activation details across your application. You may however decide to use custom "
" flags for a specific tooltip instance. " ) ;
2023-06-16 16:42:56 +02:00
// The following examples are passed for documentation purpose but may not be useful to most users.
2023-09-22 17:52:50 +02:00
// Passing ImGuiHoveredFlags_ForTooltip to IsItemHovered() will pull ImGuiHoveredFlags flags values from
2024-10-18 17:26:20 +02:00
// 'style.HoverFlagsForTooltipMouse' or 'style.HoverFlagsForTooltipNav' depending on whether mouse or keyboard/gamepad is being used.
2023-09-22 17:52:50 +02:00
// With default settings, ImGuiHoveredFlags_ForTooltip is equivalent to ImGuiHoveredFlags_DelayShort + ImGuiHoveredFlags_Stationary.
2023-06-16 16:42:56 +02:00
ImGui : : Button ( " Manual " , sz ) ;
if ( ImGui : : IsItemHovered ( ImGuiHoveredFlags_ForTooltip ) )
2023-09-12 11:55:34 +02:00
ImGui : : SetTooltip ( " I am a manually emitted tooltip. " ) ;
2023-06-16 16:42:56 +02:00
ImGui : : Button ( " DelayNone " , sz ) ;
if ( ImGui : : IsItemHovered ( ImGuiHoveredFlags_DelayNone ) )
ImGui : : SetTooltip ( " I am a tooltip with no delay. " ) ;
ImGui : : Button ( " DelayShort " , sz ) ;
if ( ImGui : : IsItemHovered ( ImGuiHoveredFlags_DelayShort | ImGuiHoveredFlags_NoSharedDelay ) )
ImGui : : SetTooltip ( " I am a tooltip with a short delay (%0.2f sec). " , ImGui : : GetStyle ( ) . HoverDelayShort ) ;
ImGui : : Button ( " DelayLong " , sz ) ;
if ( ImGui : : IsItemHovered ( ImGuiHoveredFlags_DelayNormal | ImGuiHoveredFlags_NoSharedDelay ) )
2023-09-12 11:55:34 +02:00
ImGui : : SetTooltip ( " I am a tooltip with a long delay (%0.2f sec). " , ImGui : : GetStyle ( ) . HoverDelayNormal ) ;
2023-06-16 16:42:56 +02:00
ImGui : : Button ( " Stationary " , sz ) ;
if ( ImGui : : IsItemHovered ( ImGuiHoveredFlags_Stationary ) )
ImGui : : SetTooltip ( " I am a tooltip requiring mouse to be stationary before activating. " ) ;
2023-09-12 11:55:34 +02:00
// Using ImGuiHoveredFlags_ForTooltip will pull flags from 'style.HoverFlagsForTooltipMouse' or 'style.HoverFlagsForTooltipNav',
// which default value include the ImGuiHoveredFlags_AllowWhenDisabled flag.
ImGui : : BeginDisabled ( ) ;
ImGui : : Button ( " Disabled item " , sz ) ;
if ( ImGui : : IsItemHovered ( ImGuiHoveredFlags_ForTooltip ) )
ImGui : : SetTooltip ( " I am a a tooltip for a disabled item. " ) ;
2024-07-01 14:32:11 +02:00
ImGui : : EndDisabled ( ) ;
2023-09-12 11:55:34 +02:00
2023-06-16 16:42:56 +02:00
ImGui : : TreePop ( ) ;
}
2018-10-25 23:40:33 +02:00
// Testing ImGuiOnceUponAFrame helper.
//static ImGuiOnceUponAFrame once;
//for (int i = 0; i < 5; i++)
// if (once)
// ImGui::Text("This will be displayed only once.");
2017-08-08 12:04:31 +02:00
2023-10-05 14:53:33 +02:00
IMGUI_DEMO_MARKER ( " Widgets/Tree Nodes " ) ;
if ( ImGui : : TreeNode ( " Tree Nodes " ) )
2018-10-25 23:40:33 +02:00
{
2023-10-05 14:53:33 +02:00
IMGUI_DEMO_MARKER ( " Widgets/Tree Nodes/Basic trees " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Basic trees " ) )
{
for ( int i = 0 ; i < 5 ; i + + )
2019-05-13 15:11:25 +02:00
{
2020-05-05 19:39:24 +02:00
// Use SetNextItemOpen() so set the default state of a node to be open. We could
// also use TreeNodeEx() with the ImGuiTreeNodeFlags_DefaultOpen flag to achieve the same thing!
2019-05-13 15:11:25 +02:00
if ( i = = 0 )
ImGui : : SetNextItemOpen ( true , ImGuiCond_Once ) ;
2024-04-24 18:20:02 +02:00
// Here we use PushID() to generate a unique base ID, and then the "" used as TreeNode id won't conflict.
// An alternative to using 'PushID() + TreeNode("", ...)' to generate a unique ID is to use 'TreeNode((void*)(intptr_t)i, ...)',
// aka generate a dummy pointer-sized value to be hashed. The demo below uses that technique. Both are fine.
ImGui : : PushID ( i ) ;
if ( ImGui : : TreeNode ( " " , " Child %d " , i ) )
2018-10-25 23:40:33 +02:00
{
ImGui : : Text ( " blah blah " ) ;
ImGui : : SameLine ( ) ;
2020-02-17 15:29:59 +01:00
if ( ImGui : : SmallButton ( " button " ) ) { }
2018-10-25 23:40:33 +02:00
ImGui : : TreePop ( ) ;
}
2024-04-24 18:20:02 +02:00
ImGui : : PopID ( ) ;
2019-05-13 15:11:25 +02:00
}
2017-08-08 12:04:31 +02:00
ImGui : : TreePop ( ) ;
}
2023-10-05 14:53:33 +02:00
IMGUI_DEMO_MARKER ( " Widgets/Tree Nodes/Advanced, with Selectable nodes " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Advanced, with Selectable nodes " ) )
2015-07-22 01:00:28 +02:00
{
2020-05-05 19:39:24 +02:00
HelpMarker (
" This is a more typical looking tree with selectable nodes. \n "
" Click to select, CTRL+Click to toggle, click on arrows or double-click to open. " ) ;
2019-09-18 17:13:41 +02:00
static ImGuiTreeNodeFlags base_flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_SpanAvailWidth ;
2018-10-25 23:40:33 +02:00
static bool align_label_with_current_x_position = false ;
2020-04-15 12:31:51 +02:00
static bool test_drag_and_drop = false ;
2020-11-05 21:23:02 +01:00
ImGui : : CheckboxFlags ( " ImGuiTreeNodeFlags_OpenOnArrow " , & base_flags , ImGuiTreeNodeFlags_OpenOnArrow ) ;
ImGui : : CheckboxFlags ( " ImGuiTreeNodeFlags_OpenOnDoubleClick " , & base_flags , ImGuiTreeNodeFlags_OpenOnDoubleClick ) ;
ImGui : : CheckboxFlags ( " ImGuiTreeNodeFlags_SpanAvailWidth " , & base_flags , ImGuiTreeNodeFlags_SpanAvailWidth ) ; ImGui : : SameLine ( ) ; HelpMarker ( " Extend hit area to all available width instead of allowing more items to be laid out after the node. " ) ;
ImGui : : CheckboxFlags ( " ImGuiTreeNodeFlags_SpanFullWidth " , & base_flags , ImGuiTreeNodeFlags_SpanFullWidth ) ;
2023-10-17 12:21:21 +02:00
ImGui : : CheckboxFlags ( " ImGuiTreeNodeFlags_SpanTextWidth " , & base_flags , ImGuiTreeNodeFlags_SpanTextWidth ) ; ImGui : : SameLine ( ) ; HelpMarker ( " Reduce hit area to the text label and a bit of margin. " ) ;
2023-10-05 14:53:33 +02:00
ImGui : : CheckboxFlags ( " ImGuiTreeNodeFlags_SpanAllColumns " , & base_flags , ImGuiTreeNodeFlags_SpanAllColumns ) ; ImGui : : SameLine ( ) ; HelpMarker ( " For use in Tables only. " ) ;
2023-10-17 12:21:21 +02:00
ImGui : : CheckboxFlags ( " ImGuiTreeNodeFlags_AllowOverlap " , & base_flags , ImGuiTreeNodeFlags_AllowOverlap ) ;
ImGui : : CheckboxFlags ( " ImGuiTreeNodeFlags_Framed " , & base_flags , ImGuiTreeNodeFlags_Framed ) ; ImGui : : SameLine ( ) ; HelpMarker ( " Draw frame with background (e.g. for CollapsingHeader) " ) ;
2024-07-03 18:25:01 +02:00
ImGui : : CheckboxFlags ( " ImGuiTreeNodeFlags_NavLeftJumpsBackHere " , & base_flags , ImGuiTreeNodeFlags_NavLeftJumpsBackHere ) ;
2020-03-26 20:15:44 +01:00
ImGui : : Checkbox ( " Align label with current X position " , & align_label_with_current_x_position ) ;
2020-04-15 12:31:51 +02:00
ImGui : : Checkbox ( " Test tree node as drag source " , & test_drag_and_drop ) ;
2018-10-25 23:40:33 +02:00
ImGui : : Text ( " Hello! " ) ;
if ( align_label_with_current_x_position )
ImGui : : Unindent ( ImGui : : GetTreeNodeToLabelSpacing ( ) ) ;
2020-05-05 19:39:24 +02:00
// 'selection_mask' is dumb representation of what may be user-side selection state.
// You may retain selection state inside or outside your objects in whatever format you see fit.
// 'node_clicked' is temporary storage of what node we have clicked to process selection at the end
/// of the loop. May be a pointer to your own node type, etc.
2020-05-07 11:38:45 +02:00
static int selection_mask = ( 1 < < 2 ) ;
2020-05-05 19:39:24 +02:00
int node_clicked = - 1 ;
2018-10-25 23:40:33 +02:00
for ( int i = 0 ; i < 6 ; i + + )
2015-07-22 01:00:28 +02:00
{
2020-05-05 19:39:24 +02:00
// Disable the default "open on single-click behavior" + set Selected flag according to our selection.
2021-10-25 18:31:16 +02:00
// To alter selection we use IsItemClicked() && !IsItemToggledOpen(), so clicking on an arrow doesn't alter selection.
2019-09-18 17:13:41 +02:00
ImGuiTreeNodeFlags node_flags = base_flags ;
2019-09-18 17:21:04 +02:00
const bool is_selected = ( selection_mask & ( 1 < < i ) ) ! = 0 ;
2019-09-18 17:13:41 +02:00
if ( is_selected )
2019-04-11 15:12:18 +02:00
node_flags | = ImGuiTreeNodeFlags_Selected ;
2018-10-25 23:40:33 +02:00
if ( i < 3 )
2015-07-22 01:00:28 +02:00
{
2019-04-11 15:12:18 +02:00
// Items 0..2 are Tree Node
2018-10-25 23:40:33 +02:00
bool node_open = ImGui : : TreeNodeEx ( ( void * ) ( intptr_t ) i , node_flags , " Selectable Node %d " , i ) ;
2021-10-25 18:31:16 +02:00
if ( ImGui : : IsItemClicked ( ) & & ! ImGui : : IsItemToggledOpen ( ) )
2018-10-25 23:40:33 +02:00
node_clicked = i ;
2020-04-15 12:31:51 +02:00
if ( test_drag_and_drop & & ImGui : : BeginDragDropSource ( ) )
{
ImGui : : SetDragDropPayload ( " _TREENODE " , NULL , 0 ) ;
ImGui : : Text ( " This is a drag and drop source " ) ;
ImGui : : EndDragDropSource ( ) ;
}
2024-07-03 18:25:01 +02:00
if ( i = = 2 & & ( base_flags & ImGuiTreeNodeFlags_SpanTextWidth ) )
2023-10-17 12:21:21 +02:00
{
// Item 2 has an additional inline button to help demonstrate SpanTextWidth.
ImGui : : SameLine ( ) ;
if ( ImGui : : SmallButton ( " button " ) ) { }
}
2018-10-25 23:40:33 +02:00
if ( node_open )
2016-05-28 17:12:13 +02:00
{
2019-09-18 17:13:41 +02:00
ImGui : : BulletText ( " Blah blah \n Blah Blah " ) ;
2024-07-03 18:25:01 +02:00
ImGui : : SameLine ( ) ;
ImGui : : SmallButton ( " Button " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : TreePop ( ) ;
2016-05-01 17:55:04 +02:00
}
2015-07-22 01:00:28 +02:00
}
2018-10-25 23:40:33 +02:00
else
2016-05-01 17:55:04 +02:00
{
2019-04-11 15:12:18 +02:00
// Items 3..5 are Tree Leaves
2020-05-05 19:39:24 +02:00
// The only reason we use TreeNode at all is to allow selection of the leaf. Otherwise we can
// use BulletText() or advance the cursor by GetTreeNodeToLabelSpacing() and call Text().
2018-10-25 23:40:33 +02:00
node_flags | = ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen ; // ImGuiTreeNodeFlags_Bullet
ImGui : : TreeNodeEx ( ( void * ) ( intptr_t ) i , node_flags , " Selectable Leaf %d " , i ) ;
2021-10-25 18:31:16 +02:00
if ( ImGui : : IsItemClicked ( ) & & ! ImGui : : IsItemToggledOpen ( ) )
2018-10-25 23:40:33 +02:00
node_clicked = i ;
2020-04-15 12:31:51 +02:00
if ( test_drag_and_drop & & ImGui : : BeginDragDropSource ( ) )
{
ImGui : : SetDragDropPayload ( " _TREENODE " , NULL , 0 ) ;
ImGui : : Text ( " This is a drag and drop source " ) ;
ImGui : : EndDragDropSource ( ) ;
}
2016-05-01 17:55:04 +02:00
}
2016-05-01 14:34:55 +02:00
}
2018-10-25 23:40:33 +02:00
if ( node_clicked ! = - 1 )
2016-05-01 14:34:55 +02:00
{
2020-05-05 19:39:24 +02:00
// Update selection state
// (process outside of tree loop to avoid visual inconsistencies during the clicking frame)
2018-10-25 23:40:33 +02:00
if ( ImGui : : GetIO ( ) . KeyCtrl )
selection_mask ^ = ( 1 < < node_clicked ) ; // CTRL+click to toggle
2020-05-05 19:39:24 +02:00
else //if (!(selection_mask & (1 << node_clicked))) // Depending on selection behavior you want, may want to preserve selection when clicking on item that is part of the selection
2018-10-25 23:40:33 +02:00
selection_mask = ( 1 < < node_clicked ) ; // Click to single-select
2016-05-01 14:34:55 +02:00
}
2018-10-25 23:40:33 +02:00
if ( align_label_with_current_x_position )
ImGui : : Indent ( ImGui : : GetTreeNodeToLabelSpacing ( ) ) ;
2016-05-01 14:34:55 +02:00
ImGui : : TreePop ( ) ;
}
2018-10-25 23:40:33 +02:00
ImGui : : TreePop ( ) ;
}
2016-05-01 14:34:55 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Collapsing Headers " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Collapsing Headers " ) )
{
static bool closable_group = true ;
2019-04-11 15:12:18 +02:00
ImGui : : Checkbox ( " Show 2nd header " , & closable_group ) ;
2018-10-30 15:52:27 +01:00
if ( ImGui : : CollapsingHeader ( " Header " , ImGuiTreeNodeFlags_None ) )
2015-07-22 01:00:28 +02:00
{
2018-10-25 23:40:33 +02:00
ImGui : : Text ( " IsItemHovered: %d " , ImGui : : IsItemHovered ( ) ) ;
for ( int i = 0 ; i < 5 ; i + + )
ImGui : : Text ( " Some content %d " , i ) ;
2015-07-22 01:00:28 +02:00
}
2018-10-25 23:40:33 +02:00
if ( ImGui : : CollapsingHeader ( " Header with a close button " , & closable_group ) )
2015-07-22 01:00:28 +02:00
{
2018-10-25 23:40:33 +02:00
ImGui : : Text ( " IsItemHovered: %d " , ImGui : : IsItemHovered ( ) ) ;
for ( int i = 0 ; i < 5 ; i + + )
ImGui : : Text ( " More content %d " , i ) ;
}
2018-10-30 15:52:27 +01:00
/*
if ( ImGui : : CollapsingHeader ( " Header with a bullet " , ImGuiTreeNodeFlags_Bullet ) )
ImGui : : Text ( " IsItemHovered: %d " , ImGui : : IsItemHovered ( ) ) ;
*/
2018-10-25 23:40:33 +02:00
ImGui : : TreePop ( ) ;
}
2015-07-22 01:00:28 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Bullets " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Bullets " ) )
{
ImGui : : BulletText ( " Bullet point 1 " ) ;
ImGui : : BulletText ( " Bullet point 2 \n On multiple lines " ) ;
2018-10-30 15:52:27 +01:00
if ( ImGui : : TreeNode ( " Tree node " ) )
{
ImGui : : BulletText ( " Another bullet point " ) ;
ImGui : : TreePop ( ) ;
}
2018-10-25 23:40:33 +02:00
ImGui : : Bullet ( ) ; ImGui : : Text ( " Bullet point 3 (two calls) " ) ;
ImGui : : Bullet ( ) ; ImGui : : SmallButton ( " Button " ) ;
ImGui : : TreePop ( ) ;
}
2015-07-22 01:00:28 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Text " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Text " ) )
{
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Text/Colored Text " ) ;
2020-10-15 20:05:35 +02:00
if ( ImGui : : TreeNode ( " Colorful Text " ) )
2018-10-25 23:40:33 +02:00
{
// Using shortcut. You can use PushStyleColor()/PopStyleColor() for more flexibility.
2020-06-30 15:31:54 +02:00
ImGui : : TextColored ( ImVec4 ( 1.0f , 0.0f , 1.0f , 1.0f ) , " Pink " ) ;
ImGui : : TextColored ( ImVec4 ( 1.0f , 1.0f , 0.0f , 1.0f ) , " Yellow " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : TextDisabled ( " Disabled " ) ;
2019-03-06 18:19:28 +01:00
ImGui : : SameLine ( ) ; HelpMarker ( " The TextDisabled color is stored in ImGuiStyle. " ) ;
2015-07-22 01:00:28 +02:00
ImGui : : TreePop ( ) ;
}
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Text/Word Wrapping " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Word Wrapping " ) )
2015-07-22 01:00:28 +02:00
{
2018-10-25 23:40:33 +02:00
// Using shortcut. You can use PushTextWrapPos()/PopTextWrapPos() for more flexibility.
2020-08-28 16:49:46 +02:00
ImGui : : TextWrapped (
" This text should automatically wrap on the edge of the window. The current implementation "
" for text wrapping follows simple rules suitable for English and possibly other languages. " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : Spacing ( ) ;
2017-11-01 12:55:15 +01:00
2018-10-25 23:40:33 +02:00
static float wrap_width = 200.0f ;
ImGui : : SliderFloat ( " Wrap width " , & wrap_width , - 20 , 600 , " %.0f " ) ;
2017-11-01 12:55:15 +01:00
2020-05-05 19:39:24 +02:00
ImDrawList * draw_list = ImGui : : GetWindowDrawList ( ) ;
for ( int n = 0 ; n < 2 ; n + + )
{
ImGui : : Text ( " Test paragraph %d: " , n ) ;
ImVec2 pos = ImGui : : GetCursorScreenPos ( ) ;
ImVec2 marker_min = ImVec2 ( pos . x + wrap_width , pos . y ) ;
ImVec2 marker_max = ImVec2 ( pos . x + wrap_width + 10 , pos . y + ImGui : : GetTextLineHeight ( ) ) ;
ImGui : : PushTextWrapPos ( ImGui : : GetCursorPos ( ) . x + wrap_width ) ;
if ( n = = 0 )
ImGui : : Text ( " The lazy dog is a good dog. This paragraph should fit within %.0f pixels. Testing a 1 character word. The quick brown fox jumps over the lazy dog. " , wrap_width ) ;
2020-09-16 10:28:58 +02:00
else
2020-05-05 19:39:24 +02:00
ImGui : : Text ( " aaaaaaaa bbbbbbbb, c cccccccc,dddddddd. d eeeeeeee ffffffff. gggggggg!hhhhhhhh " ) ;
// Draw actual text bounding box, following by marker of our expected limit (should not overlap!)
draw_list - > AddRect ( ImGui : : GetItemRectMin ( ) , ImGui : : GetItemRectMax ( ) , IM_COL32 ( 255 , 255 , 0 , 255 ) ) ;
draw_list - > AddRectFilled ( marker_min , marker_max , IM_COL32 ( 255 , 0 , 255 , 255 ) ) ;
ImGui : : PopTextWrapPos ( ) ;
}
2018-10-25 23:40:33 +02:00
ImGui : : TreePop ( ) ;
}
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Text/UTF-8 Text " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " UTF-8 Text " ) )
{
// UTF-8 test with Japanese characters
2020-06-09 16:29:00 +02:00
// (Needs a suitable font? Try "Google Noto" or "Arial Unicode". See docs/FONTS.md for details.)
2018-10-25 23:40:33 +02:00
// - From C++11 you can use the u8"my text" syntax to encode literal strings as UTF-8
2020-05-05 19:39:24 +02:00
// - For earlier compiler, you may be able to encode your sources as UTF-8 (e.g. in Visual Studio, you
// can save your source files as 'UTF-8 without signature').
// - FOR THIS DEMO FILE ONLY, BECAUSE WE WANT TO SUPPORT OLD COMPILERS, WE ARE *NOT* INCLUDING RAW UTF-8
// CHARACTERS IN THIS SOURCE FILE. Instead we are encoding a few strings with hexadecimal constants.
// Don't do this in your application! Please use u8"text in any language" in your application!
// Note that characters values are preserved even by InputText() if the font cannot be displayed,
// so you can safely copy & paste garbled characters into another application.
ImGui : : TextWrapped (
2022-09-14 18:19:50 +02:00
" CJK text will only appear if the font was loaded with the appropriate CJK character ranges. "
2021-02-25 13:33:47 +01:00
" Call io.Fonts->AddFontFromFileTTF() manually to load extra character ranges. "
2020-06-09 16:29:00 +02:00
" Read docs/FONTS.md for details. " ) ;
2024-01-04 11:50:38 +01:00
ImGui : : Text ( " Hiragana: \xe3 \x81 \x8b \xe3 \x81 \x8d \xe3 \x81 \x8f \xe3 \x81 \x91 \xe3 \x81 \x93 (kakikukeko) " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : Text ( " Kanjis: \xe6 \x97 \xa5 \xe6 \x9c \xac \xe8 \xaa \x9e (nihongo) " ) ;
static char buf [ 32 ] = " \xe6 \x97 \xa5 \xe6 \x9c \xac \xe8 \xaa \x9e " ;
//static char buf[32] = u8"NIHONGO"; // <- this is how you would write it with C++11, using real kanjis
ImGui : : InputText ( " UTF-8 input " , buf , IM_ARRAYSIZE ( buf ) ) ;
2015-07-22 01:00:28 +02:00
ImGui : : TreePop ( ) ;
}
2018-10-25 23:40:33 +02:00
ImGui : : TreePop ( ) ;
}
2015-07-22 01:00:28 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Images " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Images " ) )
{
ImGuiIO & io = ImGui : : GetIO ( ) ;
2020-08-28 16:49:46 +02:00
ImGui : : TextWrapped (
" Below we are displaying the font texture (which is the only texture we have access to in this demo). "
" Use the 'ImTextureID' type as storage to pass pointers or identifier to your own texture data. "
" Hover the texture for a zoomed view! " ) ;
2018-10-25 23:40:33 +02:00
2020-05-05 19:39:24 +02:00
// Below we are displaying the font texture because it is the only texture we have access to inside the demo!
// Remember that ImTextureID is just storage for whatever you want it to be. It is essentially a value that
2020-10-12 17:34:22 +02:00
// will be passed to the rendering backend via the ImDrawCmd structure.
// If you use one of the default imgui_impl_XXXX.cpp rendering backend, they all have comments at the top
2020-05-05 19:39:24 +02:00
// of their respective source file to specify what they expect to be stored in ImTextureID, for example:
// - The imgui_impl_dx11.cpp renderer expect a 'ID3D11ShaderResourceView*' pointer
// - The imgui_impl_opengl3.cpp renderer expect a GLuint OpenGL texture identifier, etc.
// More:
// - If you decided that ImTextureID = MyEngineTexture*, then you can pass your MyEngineTexture* pointers
// to ImGui::Image(), and gather width/height through your own functions, etc.
// - You can use ShowMetricsWindow() to inspect the draw data that are being passed to your renderer,
// it will help you debug issues if you are confused about it.
// - Consider using the lower-level ImDrawList::AddImage() API, via ImGui::GetWindowDrawList()->AddImage().
// - Read https://github.com/ocornut/imgui/blob/master/docs/FAQ.md
// - Read https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples
2018-10-25 23:40:33 +02:00
ImTextureID my_tex_id = io . Fonts - > TexID ;
float my_tex_w = ( float ) io . Fonts - > TexWidth ;
float my_tex_h = ( float ) io . Fonts - > TexHeight ;
{
2023-01-31 18:05:30 +01:00
static bool use_text_color_for_tint = false ;
ImGui : : Checkbox ( " Use Text Color for Tint " , & use_text_color_for_tint ) ;
2020-05-05 19:39:24 +02:00
ImGui : : Text ( " %.0fx%.0f " , my_tex_w , my_tex_h ) ;
ImVec2 pos = ImGui : : GetCursorScreenPos ( ) ;
ImVec2 uv_min = ImVec2 ( 0.0f , 0.0f ) ; // Top-left
ImVec2 uv_max = ImVec2 ( 1.0f , 1.0f ) ; // Lower-right
2024-01-04 11:50:38 +01:00
ImVec4 tint_col = use_text_color_for_tint ? ImGui : : GetStyleColorVec4 ( ImGuiCol_Text ) : ImVec4 ( 1.0f , 1.0f , 1.0f , 1.0f ) ; // No tint
2023-01-31 18:05:30 +01:00
ImVec4 border_col = ImGui : : GetStyleColorVec4 ( ImGuiCol_Border ) ;
2020-05-05 19:39:24 +02:00
ImGui : : Image ( my_tex_id , ImVec2 ( my_tex_w , my_tex_h ) , uv_min , uv_max , tint_col , border_col ) ;
2023-06-16 16:42:56 +02:00
if ( ImGui : : BeginItemTooltip ( ) )
2020-05-05 19:39:24 +02:00
{
float region_sz = 32.0f ;
float region_x = io . MousePos . x - pos . x - region_sz * 0.5f ;
float region_y = io . MousePos . y - pos . y - region_sz * 0.5f ;
float zoom = 4.0f ;
if ( region_x < 0.0f ) { region_x = 0.0f ; }
else if ( region_x > my_tex_w - region_sz ) { region_x = my_tex_w - region_sz ; }
if ( region_y < 0.0f ) { region_y = 0.0f ; }
else if ( region_y > my_tex_h - region_sz ) { region_y = my_tex_h - region_sz ; }
ImGui : : Text ( " Min: (%.2f, %.2f) " , region_x , region_y ) ;
ImGui : : Text ( " Max: (%.2f, %.2f) " , region_x + region_sz , region_y + region_sz ) ;
ImVec2 uv0 = ImVec2 ( ( region_x ) / my_tex_w , ( region_y ) / my_tex_h ) ;
ImVec2 uv1 = ImVec2 ( ( region_x + region_sz ) / my_tex_w , ( region_y + region_sz ) / my_tex_h ) ;
ImGui : : Image ( my_tex_id , ImVec2 ( region_sz * zoom , region_sz * zoom ) , uv0 , uv1 , tint_col , border_col ) ;
ImGui : : EndTooltip ( ) ;
}
2018-10-25 23:40:33 +02:00
}
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Images/Textured buttons " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : TextWrapped ( " And now some textured buttons.. " ) ;
static int pressed_count = 0 ;
for ( int i = 0 ; i < 8 ; i + + )
2018-03-19 14:44:37 +01:00
{
2022-08-03 21:04:33 +02:00
// UV coordinates are often (0.0f, 0.0f) and (1.0f, 1.0f) to display an entire textures.
// Here are trying to display only a 32x32 pixels area of the texture, hence the UV computation.
// Read about UV coordinates here: https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples
2018-10-25 23:40:33 +02:00
ImGui : : PushID ( i ) ;
2022-08-03 21:04:33 +02:00
if ( i > 0 )
ImGui : : PushStyleVar ( ImGuiStyleVar_FramePadding , ImVec2 ( i - 1.0f , i - 1.0f ) ) ;
ImVec2 size = ImVec2 ( 32.0f , 32.0f ) ; // Size of the image we want to make visible
ImVec2 uv0 = ImVec2 ( 0.0f , 0.0f ) ; // UV coordinates for lower-left
ImVec2 uv1 = ImVec2 ( 32.0f / my_tex_w , 32.0f / my_tex_h ) ; // UV coordinates for (32,32) in our texture
ImVec4 bg_col = ImVec4 ( 0.0f , 0.0f , 0.0f , 1.0f ) ; // Black background
ImVec4 tint_col = ImVec4 ( 1.0f , 1.0f , 1.0f , 1.0f ) ; // No tint
if ( ImGui : : ImageButton ( " " , my_tex_id , size , uv0 , uv1 , bg_col , tint_col ) )
2018-10-25 23:40:33 +02:00
pressed_count + = 1 ;
2022-08-03 21:04:33 +02:00
if ( i > 0 )
ImGui : : PopStyleVar ( ) ;
2018-10-25 23:40:33 +02:00
ImGui : : PopID ( ) ;
ImGui : : SameLine ( ) ;
}
ImGui : : NewLine ( ) ;
ImGui : : Text ( " Pressed %d times. " , pressed_count ) ;
ImGui : : TreePop ( ) ;
}
2018-03-19 14:44:37 +01:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Combo " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Combo " ) )
{
2022-10-19 12:07:56 +02:00
// Combo Boxes are also called "Dropdown" in other systems
2018-10-25 23:40:33 +02:00
// Expose flags as checkbox for the demo
static ImGuiComboFlags flags = 0 ;
2020-11-05 21:23:02 +01:00
ImGui : : CheckboxFlags ( " ImGuiComboFlags_PopupAlignLeft " , & flags , ImGuiComboFlags_PopupAlignLeft ) ;
2019-03-06 18:19:28 +01:00
ImGui : : SameLine ( ) ; HelpMarker ( " Only makes a difference if the popup is larger than the combo " ) ;
2020-11-05 21:23:02 +01:00
if ( ImGui : : CheckboxFlags ( " ImGuiComboFlags_NoArrowButton " , & flags , ImGuiComboFlags_NoArrowButton ) )
2024-01-04 11:50:38 +01:00
flags & = ~ ImGuiComboFlags_NoPreview ; // Clear incompatible flags
2020-11-05 21:23:02 +01:00
if ( ImGui : : CheckboxFlags ( " ImGuiComboFlags_NoPreview " , & flags , ImGuiComboFlags_NoPreview ) )
2024-01-04 11:50:38 +01:00
flags & = ~ ( ImGuiComboFlags_NoArrowButton | ImGuiComboFlags_WidthFitPreview ) ; // Clear incompatible flags
2023-10-09 11:34:05 +02:00
if ( ImGui : : CheckboxFlags ( " ImGuiComboFlags_WidthFitPreview " , & flags , ImGuiComboFlags_WidthFitPreview ) )
flags & = ~ ImGuiComboFlags_NoPreview ;
2018-10-25 23:40:33 +02:00
2023-10-17 17:39:50 +02:00
// Override default popup height
if ( ImGui : : CheckboxFlags ( " ImGuiComboFlags_HeightSmall " , & flags , ImGuiComboFlags_HeightSmall ) )
flags & = ~ ( ImGuiComboFlags_HeightMask_ & ~ ImGuiComboFlags_HeightSmall ) ;
if ( ImGui : : CheckboxFlags ( " ImGuiComboFlags_HeightRegular " , & flags , ImGuiComboFlags_HeightRegular ) )
flags & = ~ ( ImGuiComboFlags_HeightMask_ & ~ ImGuiComboFlags_HeightRegular ) ;
if ( ImGui : : CheckboxFlags ( " ImGuiComboFlags_HeightLargest " , & flags , ImGuiComboFlags_HeightLargest ) )
flags & = ~ ( ImGuiComboFlags_HeightMask_ & ~ ImGuiComboFlags_HeightLargest ) ;
2020-05-05 19:39:24 +02:00
// Using the generic BeginCombo() API, you have full control over how to display the combo contents.
// (your selection data could be an index, a pointer to the object, an id for the object, a flag intrusively
// stored in the object itself, etc.)
2018-10-25 23:40:33 +02:00
const char * items [ ] = { " AAAA " , " BBBB " , " CCCC " , " DDDD " , " EEEE " , " FFFF " , " GGGG " , " HHHH " , " IIII " , " JJJJ " , " KKKK " , " LLLLLLL " , " MMMM " , " OOOOOOO " } ;
2024-07-26 13:19:22 +02:00
static int item_selected_idx = 0 ; // Here we store our selection data as an index.
2024-01-04 11:50:38 +01:00
// Pass in the preview value visible before opening the combo (it could technically be different contents or not pulled from items[])
2024-07-26 13:19:22 +02:00
const char * combo_preview_value = items [ item_selected_idx ] ;
2024-01-04 11:50:38 +01:00
2021-06-15 15:16:39 +02:00
if ( ImGui : : BeginCombo ( " combo 1 " , combo_preview_value , flags ) )
2018-10-25 23:40:33 +02:00
{
for ( int n = 0 ; n < IM_ARRAYSIZE ( items ) ; n + + )
2018-03-19 14:44:37 +01:00
{
2024-07-26 13:19:22 +02:00
const bool is_selected = ( item_selected_idx = = n ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : Selectable ( items [ n ] , is_selected ) )
2024-07-26 13:19:22 +02:00
item_selected_idx = n ;
2020-05-05 19:39:24 +02:00
// Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
2018-10-25 23:40:33 +02:00
if ( is_selected )
2020-05-05 19:39:24 +02:00
ImGui : : SetItemDefaultFocus ( ) ;
2018-03-19 14:44:37 +01:00
}
2018-10-25 23:40:33 +02:00
ImGui : : EndCombo ( ) ;
}
2023-10-17 17:39:50 +02:00
ImGui : : Spacing ( ) ;
ImGui : : SeparatorText ( " One-liner variants " ) ;
HelpMarker ( " Flags above don't apply to this section. " ) ;
2018-10-25 23:40:33 +02:00
// Simplified one-liner Combo() API, using values packed in a single constant string
2021-06-15 15:16:39 +02:00
// This is a convenience for when the selection set is small and known at compile-time.
2018-10-25 23:40:33 +02:00
static int item_current_2 = 0 ;
ImGui : : Combo ( " combo 2 (one-liner) " , & item_current_2 , " aaaa \0 bbbb \0 cccc \0 dddd \0 eeee \0 \0 " ) ;
2018-03-19 14:44:37 +01:00
2018-10-25 23:40:33 +02:00
// Simplified one-liner Combo() using an array of const char*
2021-06-15 15:16:39 +02:00
// This is not very useful (may obsolete): prefer using BeginCombo()/EndCombo() for full control.
2018-10-25 23:40:33 +02:00
static int item_current_3 = - 1 ; // If the selection isn't within 0..count, Combo won't display a preview
ImGui : : Combo ( " combo 3 (array) " , & item_current_3 , items , IM_ARRAYSIZE ( items ) ) ;
2018-03-19 14:44:37 +01:00
2018-10-25 23:40:33 +02:00
// Simplified one-liner Combo() using an accessor function
static int item_current_4 = 0 ;
2023-09-15 18:43:04 +02:00
ImGui : : Combo ( " combo 4 (function) " , & item_current_4 , [ ] ( void * data , int n ) { return ( ( const char * * ) data ) [ n ] ; } , items , IM_ARRAYSIZE ( items ) ) ;
2018-03-19 14:44:37 +01:00
2018-10-25 23:40:33 +02:00
ImGui : : TreePop ( ) ;
}
2018-03-19 14:44:37 +01:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/List Boxes " ) ;
2021-02-03 16:30:23 +01:00
if ( ImGui : : TreeNode ( " List boxes " ) )
{
2024-01-04 11:50:38 +01:00
// BeginListBox() is essentially a thin wrapper to using BeginChild()/EndChild()
// using the ImGuiChildFlags_FrameStyle flag for stylistic changes + displaying a label.
// You may be tempted to simply use BeginChild() directly. However note that BeginChild() requires EndChild()
// to always be called (inconsistent with BeginListBox()/EndListBox()).
2023-11-07 20:14:54 +01:00
2021-02-03 16:30:23 +01:00
// Using the generic BeginListBox() API, you have full control over how to display the combo contents.
// (your selection data could be an index, a pointer to the object, an id for the object, a flag intrusively
// stored in the object itself, etc.)
const char * items [ ] = { " AAAA " , " BBBB " , " CCCC " , " DDDD " , " EEEE " , " FFFF " , " GGGG " , " HHHH " , " IIII " , " JJJJ " , " KKKK " , " LLLLLLL " , " MMMM " , " OOOOOOO " } ;
2024-07-26 13:19:22 +02:00
static int item_selected_idx = 0 ; // Here we store our selected data as an index.
static bool item_highlight = false ;
int item_highlighted_idx = - 1 ; // Here we store our highlighted data as an index.
ImGui : : Checkbox ( " Highlight hovered item in second listbox " , & item_highlight ) ;
2021-02-03 16:30:23 +01:00
if ( ImGui : : BeginListBox ( " listbox 1 " ) )
{
for ( int n = 0 ; n < IM_ARRAYSIZE ( items ) ; n + + )
{
2024-07-26 13:19:22 +02:00
const bool is_selected = ( item_selected_idx = = n ) ;
2021-02-03 16:30:23 +01:00
if ( ImGui : : Selectable ( items [ n ] , is_selected ) )
2024-07-26 13:19:22 +02:00
item_selected_idx = n ;
if ( item_highlight & & ImGui : : IsItemHovered ( ) )
item_highlighted_idx = n ;
2021-02-03 16:30:23 +01:00
// Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
if ( is_selected )
ImGui : : SetItemDefaultFocus ( ) ;
}
ImGui : : EndListBox ( ) ;
}
2024-04-03 03:18:49 +02:00
ImGui : : SameLine ( ) ; HelpMarker ( " Here we are sharing selection state between both boxes. " ) ;
2021-02-03 16:30:23 +01:00
// Custom size: use all width, 5 items tall
ImGui : : Text ( " Full-width: " ) ;
if ( ImGui : : BeginListBox ( " ##listbox 2 " , ImVec2 ( - FLT_MIN , 5 * ImGui : : GetTextLineHeightWithSpacing ( ) ) ) )
{
for ( int n = 0 ; n < IM_ARRAYSIZE ( items ) ; n + + )
{
2024-07-26 13:19:22 +02:00
bool is_selected = ( item_selected_idx = = n ) ;
ImGuiSelectableFlags flags = ( item_highlighted_idx = = n ) ? ImGuiSelectableFlags_Highlight : 0 ;
if ( ImGui : : Selectable ( items [ n ] , is_selected , flags ) )
item_selected_idx = n ;
2021-02-03 16:30:23 +01:00
// Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
if ( is_selected )
ImGui : : SetItemDefaultFocus ( ) ;
}
ImGui : : EndListBox ( ) ;
}
ImGui : : TreePop ( ) ;
}
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Selectables " ) ;
2023-04-12 19:48:58 +02:00
//ImGui::SetNextItemOpen(true, ImGuiCond_Once);
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Selectables " ) )
{
// Selectable() has 2 overloads:
2020-05-05 19:39:24 +02:00
// - The one taking "bool selected" as a read-only selection information.
// When Selectable() has been clicked it returns true and you can alter selection state accordingly.
2018-10-25 23:40:33 +02:00
// - The one taking "bool* p_selected" as a read-write selection information (convenient in some cases)
2020-05-05 19:39:24 +02:00
// The earlier is more flexible, as in real application your selection may be stored in many different ways
// and not necessarily inside a bool value (e.g. in flags within objects, as an external list, etc).
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Selectables/Basic " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Basic " ) )
{
2023-07-05 14:19:01 +02:00
static bool selection [ 5 ] = { false , true , false , false } ;
2018-10-25 23:40:33 +02:00
ImGui : : Selectable ( " 1. I am selectable " , & selection [ 0 ] ) ;
ImGui : : Selectable ( " 2. I am selectable " , & selection [ 1 ] ) ;
2023-07-05 14:19:01 +02:00
ImGui : : Selectable ( " 3. I am selectable " , & selection [ 2 ] ) ;
if ( ImGui : : Selectable ( " 4. I am double clickable " , selection [ 3 ] , ImGuiSelectableFlags_AllowDoubleClick ) )
2018-10-25 23:40:33 +02:00
if ( ImGui : : IsMouseDoubleClicked ( 0 ) )
2023-07-05 14:19:01 +02:00
selection [ 3 ] = ! selection [ 3 ] ;
2018-03-19 14:44:37 +01:00
ImGui : : TreePop ( ) ;
}
2023-07-05 14:19:01 +02:00
IMGUI_DEMO_MARKER ( " Widgets/Selectables/Rendering more items on the same line " ) ;
if ( ImGui : : TreeNode ( " Rendering more items on the same line " ) )
2018-10-25 23:40:33 +02:00
{
2023-07-05 14:19:01 +02:00
// (1) Using SetNextItemAllowOverlap()
// (2) Using the Selectable() override that takes "bool* p_selected" parameter, the bool value is toggled automatically.
2018-10-25 23:40:33 +02:00
static bool selected [ 3 ] = { false , false , false } ;
2023-07-05 14:19:01 +02:00
ImGui : : SetNextItemAllowOverlap ( ) ; ImGui : : Selectable ( " main.c " , & selected [ 0 ] ) ; ImGui : : SameLine ( ) ; ImGui : : SmallButton ( " Link 1 " ) ;
ImGui : : SetNextItemAllowOverlap ( ) ; ImGui : : Selectable ( " Hello.cpp " , & selected [ 1 ] ) ; ImGui : : SameLine ( ) ; ImGui : : SmallButton ( " Link 2 " ) ;
ImGui : : SetNextItemAllowOverlap ( ) ; ImGui : : Selectable ( " Hello.h " , & selected [ 2 ] ) ; ImGui : : SameLine ( ) ; ImGui : : SmallButton ( " Link 3 " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : TreePop ( ) ;
}
2023-07-05 14:19:01 +02:00
2024-07-26 13:19:22 +02:00
IMGUI_DEMO_MARKER ( " Widgets/Selectables/In Tables " ) ;
if ( ImGui : : TreeNode ( " In Tables " ) )
2018-10-25 23:40:33 +02:00
{
2020-10-26 18:28:49 +01:00
static bool selected [ 10 ] = { } ;
2021-07-07 19:03:10 +02:00
if ( ImGui : : BeginTable ( " split1 " , 3 , ImGuiTableFlags_Resizable | ImGuiTableFlags_NoSavedSettings | ImGuiTableFlags_Borders ) )
2016-06-07 09:05:36 +02:00
{
2020-10-26 18:28:49 +01:00
for ( int i = 0 ; i < 10 ; i + + )
{
char label [ 32 ] ;
sprintf ( label , " Item %d " , i ) ;
ImGui : : TableNextColumn ( ) ;
ImGui : : Selectable ( label , & selected [ i ] ) ; // FIXME-TABLE: Selection overlap
}
2020-11-03 18:47:05 +01:00
ImGui : : EndTable ( ) ;
2020-10-26 18:28:49 +01:00
}
2021-07-07 19:03:10 +02:00
ImGui : : Spacing ( ) ;
if ( ImGui : : BeginTable ( " split2 " , 3 , ImGuiTableFlags_Resizable | ImGuiTableFlags_NoSavedSettings | ImGuiTableFlags_Borders ) )
2020-10-26 18:28:49 +01:00
{
for ( int i = 0 ; i < 10 ; i + + )
{
char label [ 32 ] ;
sprintf ( label , " Item %d " , i ) ;
ImGui : : TableNextRow ( ) ;
ImGui : : TableNextColumn ( ) ;
ImGui : : Selectable ( label , & selected [ i ] , ImGuiSelectableFlags_SpanAllColumns ) ;
ImGui : : TableNextColumn ( ) ;
ImGui : : Text ( " Some other contents " ) ;
ImGui : : TableNextColumn ( ) ;
ImGui : : Text ( " 123456 " ) ;
}
ImGui : : EndTable ( ) ;
2016-06-07 09:05:36 +02:00
}
2018-10-25 23:40:33 +02:00
ImGui : : TreePop ( ) ;
}
2023-07-05 14:19:01 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Selectables/Grid " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Grid " ) )
{
2020-10-05 12:57:05 +02:00
static char selected [ 4 ] [ 4 ] = { { 1 , 0 , 0 , 0 } , { 0 , 1 , 0 , 0 } , { 0 , 0 , 1 , 0 } , { 0 , 0 , 0 , 1 } } ;
// Add in a bit of silly fun...
const float time = ( float ) ImGui : : GetTime ( ) ;
const bool winning_state = memchr ( selected , 0 , sizeof ( selected ) ) = = NULL ; // If all cells are selected...
if ( winning_state )
ImGui : : PushStyleVar ( ImGuiStyleVar_SelectableTextAlign , ImVec2 ( 0.5f + 0.5f * cosf ( time * 2.0f ) , 0.5f + 0.5f * sinf ( time * 3.0f ) ) ) ;
for ( int y = 0 ; y < 4 ; y + + )
for ( int x = 0 ; x < 4 ; x + + )
2015-07-22 01:00:28 +02:00
{
2020-10-05 12:57:05 +02:00
if ( x > 0 )
ImGui : : SameLine ( ) ;
ImGui : : PushID ( y * 4 + x ) ;
if ( ImGui : : Selectable ( " Sailor " , selected [ y ] [ x ] ! = 0 , 0 , ImVec2 ( 50 , 50 ) ) )
{
// Toggle clicked cell + toggle neighbors
selected [ y ] [ x ] ^ = 1 ;
if ( x > 0 ) { selected [ y ] [ x - 1 ] ^ = 1 ; }
if ( x < 3 ) { selected [ y ] [ x + 1 ] ^ = 1 ; }
if ( y > 0 ) { selected [ y - 1 ] [ x ] ^ = 1 ; }
if ( y < 3 ) { selected [ y + 1 ] [ x ] ^ = 1 ; }
}
ImGui : : PopID ( ) ;
2015-07-22 01:00:28 +02:00
}
2020-10-05 12:57:05 +02:00
if ( winning_state )
ImGui : : PopStyleVar ( ) ;
2015-07-22 01:00:28 +02:00
ImGui : : TreePop ( ) ;
}
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Selectables/Alignment " ) ;
2019-02-13 23:56:21 +01:00
if ( ImGui : : TreeNode ( " Alignment " ) )
{
2020-05-05 19:39:24 +02:00
HelpMarker (
" By default, Selectables uses style.SelectableTextAlign but it can be overridden on a per-item "
" basis using PushStyleVar(). You'll probably want to always keep your default situation to "
" left-align otherwise it becomes difficult to layout multiple items on a same line " ) ;
static bool selected [ 3 * 3 ] = { true , false , true , false , true , false , true , false , true } ;
2019-02-14 20:29:50 +01:00
for ( int y = 0 ; y < 3 ; y + + )
2019-02-13 23:56:21 +01:00
{
2019-02-14 20:29:50 +01:00
for ( int x = 0 ; x < 3 ; x + + )
2019-02-13 23:56:21 +01:00
{
2019-02-14 20:29:50 +01:00
ImVec2 alignment = ImVec2 ( ( float ) x / 2.0f , ( float ) y / 2.0f ) ;
char name [ 32 ] ;
sprintf ( name , " (%.1f,%.1f) " , alignment . x , alignment . y ) ;
if ( x > 0 ) ImGui : : SameLine ( ) ;
ImGui : : PushStyleVar ( ImGuiStyleVar_SelectableTextAlign , alignment ) ;
2020-06-30 15:31:54 +02:00
ImGui : : Selectable ( name , & selected [ 3 * y + x ] , ImGuiSelectableFlags_None , ImVec2 ( 80 , 80 ) ) ;
2019-02-13 23:56:21 +01:00
ImGui : : PopStyleVar ( ) ;
}
}
ImGui : : TreePop ( ) ;
}
2018-10-25 23:40:33 +02:00
ImGui : : TreePop ( ) ;
}
2015-07-22 01:00:28 +02:00
2024-07-19 15:34:48 +02:00
ShowDemoWindowMultiSelect ( demo_data ) ;
2019-02-01 12:22:57 +01:00
2020-01-06 15:21:33 +01:00
// To wire InputText() with std::string or any other custom string type,
2019-12-25 17:46:35 +01:00
// see the "Text Input > Resize Callback" section of this demo, and the misc/cpp/imgui_stdlib.h file.
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Text Input " ) ;
2019-03-12 11:24:49 +01:00
if ( ImGui : : TreeNode ( " Text Input " ) )
2018-10-25 23:40:33 +02:00
{
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Text Input/Multi-line Text Input " ) ;
2019-03-12 11:24:49 +01:00
if ( ImGui : : TreeNode ( " Multi-line Text Input " ) )
{
// Note: we are using a fixed-sized buffer for simplicity here. See ImGuiInputTextFlags_CallbackResize
// and the code in misc/cpp/imgui_stdlib.h for how to setup InputText() for dynamically resizing strings.
static char text [ 1024 * 16 ] =
" /* \n "
" The Pentium F00F bug, shorthand for F0 0F C7 C8, \n "
" the hexadecimal encoding of one offending instruction, \n "
" more formally, the invalid operand with locked CMPXCHG8B \n "
" instruction bug, is a design flaw in the majority of \n "
" Intel Pentium, Pentium MMX, and Pentium OverDrive \n "
" processors (all in the P5 microarchitecture). \n "
" */ \n \n "
" label: \n "
" \t lock cmpxchg8b eax \n " ;
static ImGuiInputTextFlags flags = ImGuiInputTextFlags_AllowTabInput ;
2019-12-25 17:46:35 +01:00
HelpMarker ( " You can use the ImGuiInputTextFlags_CallbackResize facility if you need to wire InputTextMultiline() to a dynamic string type. See misc/cpp/imgui_stdlib.h for an example. (This is not demonstrated in imgui_demo.cpp because we don't want to include <string> in here) " ) ;
2020-11-05 21:23:02 +01:00
ImGui : : CheckboxFlags ( " ImGuiInputTextFlags_ReadOnly " , & flags , ImGuiInputTextFlags_ReadOnly ) ;
ImGui : : CheckboxFlags ( " ImGuiInputTextFlags_AllowTabInput " , & flags , ImGuiInputTextFlags_AllowTabInput ) ;
2023-12-14 17:02:23 +01:00
ImGui : : SameLine ( ) ; HelpMarker ( " When _AllowTabInput is set, passing through the widget with Tabbing doesn't automatically activate it, in order to also cycling through subsequent widgets. " ) ;
2020-11-05 21:23:02 +01:00
ImGui : : CheckboxFlags ( " ImGuiInputTextFlags_CtrlEnterForNewLine " , & flags , ImGuiInputTextFlags_CtrlEnterForNewLine ) ;
2019-06-21 19:38:33 +02:00
ImGui : : InputTextMultiline ( " ##source " , text , IM_ARRAYSIZE ( text ) , ImVec2 ( - FLT_MIN , ImGui : : GetTextLineHeight ( ) * 16 ) , flags ) ;
2019-03-12 11:24:49 +01:00
ImGui : : TreePop ( ) ;
}
2018-10-25 23:40:33 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Text Input/Filtered Text Input " ) ;
2019-03-12 11:24:49 +01:00
if ( ImGui : : TreeNode ( " Filtered Text Input " ) )
{
2020-05-05 19:39:24 +02:00
struct TextFilters
{
2023-05-23 20:10:00 +02:00
// Modify character input by altering 'data->Eventchar' (ImGuiInputTextFlags_CallbackCharFilter callback)
static int FilterCasingSwap ( ImGuiInputTextCallbackData * data )
{
2023-06-01 10:17:32 +02:00
if ( data - > EventChar > = ' a ' & & data - > EventChar < = ' z ' ) { data - > EventChar - = ' a ' - ' A ' ; } // Lowercase becomes uppercase
else if ( data - > EventChar > = ' A ' & & data - > EventChar < = ' Z ' ) { data - > EventChar + = ' a ' - ' A ' ; } // Uppercase becomes lowercase
2023-05-23 20:10:00 +02:00
return 0 ;
}
// Return 0 (pass) if the character is 'i' or 'm' or 'g' or 'u' or 'i', otherwise return 1 (filter out)
2020-05-05 19:39:24 +02:00
static int FilterImGuiLetters ( ImGuiInputTextCallbackData * data )
{
if ( data - > EventChar < 256 & & strchr ( " imgui " , ( char ) data - > EventChar ) )
return 0 ;
return 1 ;
}
} ;
2023-05-23 20:10:00 +02:00
static char buf1 [ 32 ] = " " ; ImGui : : InputText ( " default " , buf1 , 32 ) ;
static char buf2 [ 32 ] = " " ; ImGui : : InputText ( " decimal " , buf2 , 32 , ImGuiInputTextFlags_CharsDecimal ) ;
static char buf3 [ 32 ] = " " ; ImGui : : InputText ( " hexadecimal " , buf3 , 32 , ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase ) ;
static char buf4 [ 32 ] = " " ; ImGui : : InputText ( " uppercase " , buf4 , 32 , ImGuiInputTextFlags_CharsUppercase ) ;
static char buf5 [ 32 ] = " " ; ImGui : : InputText ( " no blank " , buf5 , 32 , ImGuiInputTextFlags_CharsNoBlank ) ;
static char buf6 [ 32 ] = " " ; ImGui : : InputText ( " casing swap " , buf6 , 32 , ImGuiInputTextFlags_CallbackCharFilter , TextFilters : : FilterCasingSwap ) ; // Use CharFilter callback to replace characters.
static char buf7 [ 32 ] = " " ; ImGui : : InputText ( " \" imgui \" " , buf7 , 32 , ImGuiInputTextFlags_CallbackCharFilter , TextFilters : : FilterImGuiLetters ) ; // Use CharFilter callback to disable some characters.
2020-08-20 11:25:39 +02:00
ImGui : : TreePop ( ) ;
}
2019-03-12 11:24:49 +01:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Text Input/Password input " ) ;
2020-08-20 11:25:39 +02:00
if ( ImGui : : TreeNode ( " Password Input " ) )
{
2020-02-11 18:53:57 +01:00
static char password [ 64 ] = " password123 " ;
ImGui : : InputText ( " password " , password , IM_ARRAYSIZE ( password ) , ImGuiInputTextFlags_Password ) ;
2019-03-12 11:24:49 +01:00
ImGui : : SameLine ( ) ; HelpMarker ( " Display all characters as '*'. \n Disable clipboard cut and copy. \n Disable logging. \n " ) ;
2020-02-11 19:31:33 +01:00
ImGui : : InputTextWithHint ( " password (w/ hint) " , " <password> " , password , IM_ARRAYSIZE ( password ) , ImGuiInputTextFlags_Password ) ;
ImGui : : InputText ( " password (clear) " , password , IM_ARRAYSIZE ( password ) ) ;
2019-03-12 11:24:49 +01:00
ImGui : : TreePop ( ) ;
}
2023-07-06 19:27:23 +02:00
IMGUI_DEMO_MARKER ( " Widgets/Text Input/Completion, History, Edit Callbacks " ) ;
2020-08-20 11:25:39 +02:00
if ( ImGui : : TreeNode ( " Completion, History, Edit Callbacks " ) )
{
struct Funcs
{
static int MyCallback ( ImGuiInputTextCallbackData * data )
{
if ( data - > EventFlag = = ImGuiInputTextFlags_CallbackCompletion )
{
data - > InsertChars ( data - > CursorPos , " .. " ) ;
}
else if ( data - > EventFlag = = ImGuiInputTextFlags_CallbackHistory )
{
if ( data - > EventKey = = ImGuiKey_UpArrow )
{
data - > DeleteChars ( 0 , data - > BufTextLen ) ;
data - > InsertChars ( 0 , " Pressed Up! " ) ;
data - > SelectAll ( ) ;
}
else if ( data - > EventKey = = ImGuiKey_DownArrow )
{
data - > DeleteChars ( 0 , data - > BufTextLen ) ;
data - > InsertChars ( 0 , " Pressed Down! " ) ;
data - > SelectAll ( ) ;
}
}
else if ( data - > EventFlag = = ImGuiInputTextFlags_CallbackEdit )
{
// Toggle casing of first character
char c = data - > Buf [ 0 ] ;
if ( ( c > = ' a ' & & c < = ' z ' ) | | ( c > = ' A ' & & c < = ' Z ' ) ) data - > Buf [ 0 ] ^ = 32 ;
data - > BufDirty = true ;
// Increment a counter
int * p_int = ( int * ) data - > UserData ;
* p_int = * p_int + 1 ;
}
return 0 ;
}
} ;
static char buf1 [ 64 ] ;
ImGui : : InputText ( " Completion " , buf1 , 64 , ImGuiInputTextFlags_CallbackCompletion , Funcs : : MyCallback ) ;
2024-01-04 11:50:38 +01:00
ImGui : : SameLine ( ) ; HelpMarker (
" Here we append \" .. \" each time Tab is pressed. "
" See 'Examples>Console' for a more meaningful demonstration of using this callback. " ) ;
2020-08-20 11:25:39 +02:00
static char buf2 [ 64 ] ;
ImGui : : InputText ( " History " , buf2 , 64 , ImGuiInputTextFlags_CallbackHistory , Funcs : : MyCallback ) ;
2024-01-04 11:50:38 +01:00
ImGui : : SameLine ( ) ; HelpMarker (
" Here we replace and select text each time Up/Down are pressed. "
" See 'Examples>Console' for a more meaningful demonstration of using this callback. " ) ;
2020-08-20 11:25:39 +02:00
static char buf3 [ 64 ] ;
static int edit_count = 0 ;
ImGui : : InputText ( " Edit " , buf3 , 64 , ImGuiInputTextFlags_CallbackEdit , Funcs : : MyCallback , ( void * ) & edit_count ) ;
2024-01-04 11:50:38 +01:00
ImGui : : SameLine ( ) ; HelpMarker (
" Here we toggle the casing of the first character on every edit + count edits. " ) ;
2020-08-20 11:25:39 +02:00
ImGui : : SameLine ( ) ; ImGui : : Text ( " (%d) " , edit_count ) ;
ImGui : : TreePop ( ) ;
}
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Text Input/Resize Callback " ) ;
2019-03-12 11:24:49 +01:00
if ( ImGui : : TreeNode ( " Resize Callback " ) )
{
2020-01-06 15:21:33 +01:00
// To wire InputText() with std::string or any other custom string type,
2020-05-05 19:39:24 +02:00
// you can use the ImGuiInputTextFlags_CallbackResize flag + create a custom ImGui::InputText() wrapper
// using your preferred type. See misc/cpp/imgui_stdlib.h for an implementation of this using std::string.
HelpMarker (
" Using ImGuiInputTextFlags_CallbackResize to wire your custom string type to InputText(). \n \n "
" See misc/cpp/imgui_stdlib.h for an implementation of this for std::string. " ) ;
2019-03-12 11:24:49 +01:00
struct Funcs
{
static int MyResizeCallback ( ImGuiInputTextCallbackData * data )
{
if ( data - > EventFlag = = ImGuiInputTextFlags_CallbackResize )
{
ImVector < char > * my_str = ( ImVector < char > * ) data - > UserData ;
IM_ASSERT ( my_str - > begin ( ) = = data - > Buf ) ;
2020-05-05 19:39:24 +02:00
my_str - > resize ( data - > BufSize ) ; // NB: On resizing calls, generally data->BufSize == data->BufTextLen + 1
2019-03-12 11:24:49 +01:00
data - > Buf = my_str - > begin ( ) ;
}
return 0 ;
}
2020-05-05 19:39:24 +02:00
// Note: Because ImGui:: is a namespace you would typically add your own function into the namespace.
// For example, you code may declare a function 'ImGui::InputText(const char* label, MyString* my_str)'
2019-03-12 11:24:49 +01:00
static bool MyInputTextMultiline ( const char * label , ImVector < char > * my_str , const ImVec2 & size = ImVec2 ( 0 , 0 ) , ImGuiInputTextFlags flags = 0 )
{
IM_ASSERT ( ( flags & ImGuiInputTextFlags_CallbackResize ) = = 0 ) ;
2019-03-12 12:08:51 +01:00
return ImGui : : InputTextMultiline ( label , my_str - > begin ( ) , ( size_t ) my_str - > size ( ) , size , flags | ImGuiInputTextFlags_CallbackResize , Funcs : : MyResizeCallback , ( void * ) my_str ) ;
2019-03-12 11:24:49 +01:00
}
} ;
// For this demo we are using ImVector as a string container.
2020-05-05 19:39:24 +02:00
// Note that because we need to store a terminating zero character, our size/capacity are 1 more
// than usually reported by a typical string class.
2019-03-12 11:24:49 +01:00
static ImVector < char > my_str ;
if ( my_str . empty ( ) )
my_str . push_back ( 0 ) ;
2019-06-21 19:38:33 +02:00
Funcs : : MyInputTextMultiline ( " ##MyStr " , & my_str , ImVec2 ( - FLT_MIN , ImGui : : GetTextLineHeight ( ) * 16 ) ) ;
2019-03-12 12:08:51 +01:00
ImGui : : Text ( " Data: %p \n Size: %d \n Capacity: %d " , ( void * ) my_str . begin ( ) , my_str . size ( ) , my_str . capacity ( ) ) ;
2019-03-12 11:24:49 +01:00
ImGui : : TreePop ( ) ;
2023-07-06 19:27:23 +02:00
}
IMGUI_DEMO_MARKER ( " Widgets/Text Input/Miscellaneous " ) ;
if ( ImGui : : TreeNode ( " Miscellaneous " ) )
{
static char buf1 [ 16 ] ;
static ImGuiInputTextFlags flags = ImGuiInputTextFlags_EscapeClearsAll ;
ImGui : : CheckboxFlags ( " ImGuiInputTextFlags_EscapeClearsAll " , & flags , ImGuiInputTextFlags_EscapeClearsAll ) ;
ImGui : : CheckboxFlags ( " ImGuiInputTextFlags_ReadOnly " , & flags , ImGuiInputTextFlags_ReadOnly ) ;
ImGui : : CheckboxFlags ( " ImGuiInputTextFlags_NoUndoRedo " , & flags , ImGuiInputTextFlags_NoUndoRedo ) ;
ImGui : : InputText ( " Hello " , buf1 , IM_ARRAYSIZE ( buf1 ) , flags ) ;
ImGui : : TreePop ( ) ;
2019-03-12 11:24:49 +01:00
}
2015-11-19 23:09:59 +01:00
2018-10-25 23:40:33 +02:00
ImGui : : TreePop ( ) ;
}
2015-11-19 23:09:59 +01:00
2021-01-14 11:21:13 +01:00
// Tabs
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Tabs " ) ;
2021-01-14 11:21:13 +01:00
if ( ImGui : : TreeNode ( " Tabs " ) )
{
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Tabs/Basic " ) ;
2021-01-14 11:21:13 +01:00
if ( ImGui : : TreeNode ( " Basic " ) )
{
ImGuiTabBarFlags tab_bar_flags = ImGuiTabBarFlags_None ;
if ( ImGui : : BeginTabBar ( " MyTabBar " , tab_bar_flags ) )
{
if ( ImGui : : BeginTabItem ( " Avocado " ) )
{
ImGui : : Text ( " This is the Avocado tab! \n blah blah blah blah blah " ) ;
ImGui : : EndTabItem ( ) ;
}
if ( ImGui : : BeginTabItem ( " Broccoli " ) )
{
ImGui : : Text ( " This is the Broccoli tab! \n blah blah blah blah blah " ) ;
ImGui : : EndTabItem ( ) ;
}
if ( ImGui : : BeginTabItem ( " Cucumber " ) )
{
ImGui : : Text ( " This is the Cucumber tab! \n blah blah blah blah blah " ) ;
ImGui : : EndTabItem ( ) ;
}
ImGui : : EndTabBar ( ) ;
}
ImGui : : Separator ( ) ;
ImGui : : TreePop ( ) ;
}
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Tabs/Advanced & Close Button " ) ;
2021-01-14 11:21:13 +01:00
if ( ImGui : : TreeNode ( " Advanced & Close Button " ) )
{
// Expose a couple of the available flags. In most cases you may just call BeginTabBar() with no flags (0).
static ImGuiTabBarFlags tab_bar_flags = ImGuiTabBarFlags_Reorderable ;
ImGui : : CheckboxFlags ( " ImGuiTabBarFlags_Reorderable " , & tab_bar_flags , ImGuiTabBarFlags_Reorderable ) ;
ImGui : : CheckboxFlags ( " ImGuiTabBarFlags_AutoSelectNewTabs " , & tab_bar_flags , ImGuiTabBarFlags_AutoSelectNewTabs ) ;
ImGui : : CheckboxFlags ( " ImGuiTabBarFlags_TabListPopupButton " , & tab_bar_flags , ImGuiTabBarFlags_TabListPopupButton ) ;
ImGui : : CheckboxFlags ( " ImGuiTabBarFlags_NoCloseWithMiddleMouseButton " , & tab_bar_flags , ImGuiTabBarFlags_NoCloseWithMiddleMouseButton ) ;
2024-06-19 01:52:56 +02:00
ImGui : : CheckboxFlags ( " ImGuiTabBarFlags_DrawSelectedOverline " , & tab_bar_flags , ImGuiTabBarFlags_DrawSelectedOverline ) ;
2021-01-14 11:21:13 +01:00
if ( ( tab_bar_flags & ImGuiTabBarFlags_FittingPolicyMask_ ) = = 0 )
tab_bar_flags | = ImGuiTabBarFlags_FittingPolicyDefault_ ;
if ( ImGui : : CheckboxFlags ( " ImGuiTabBarFlags_FittingPolicyResizeDown " , & tab_bar_flags , ImGuiTabBarFlags_FittingPolicyResizeDown ) )
tab_bar_flags & = ~ ( ImGuiTabBarFlags_FittingPolicyMask_ ^ ImGuiTabBarFlags_FittingPolicyResizeDown ) ;
if ( ImGui : : CheckboxFlags ( " ImGuiTabBarFlags_FittingPolicyScroll " , & tab_bar_flags , ImGuiTabBarFlags_FittingPolicyScroll ) )
tab_bar_flags & = ~ ( ImGuiTabBarFlags_FittingPolicyMask_ ^ ImGuiTabBarFlags_FittingPolicyScroll ) ;
// Tab Bar
2024-06-19 01:52:56 +02:00
ImGui : : AlignTextToFramePadding ( ) ;
ImGui : : Text ( " Opened: " ) ;
2021-01-14 11:21:13 +01:00
const char * names [ 4 ] = { " Artichoke " , " Beetroot " , " Celery " , " Daikon " } ;
static bool opened [ 4 ] = { true , true , true , true } ; // Persistent user state
for ( int n = 0 ; n < IM_ARRAYSIZE ( opened ) ; n + + )
{
2024-06-19 01:52:56 +02:00
ImGui : : SameLine ( ) ;
2021-01-14 11:21:13 +01:00
ImGui : : Checkbox ( names [ n ] , & opened [ n ] ) ;
}
// Passing a bool* to BeginTabItem() is similar to passing one to Begin():
// the underlying bool will be set to false when the tab is closed.
if ( ImGui : : BeginTabBar ( " MyTabBar " , tab_bar_flags ) )
{
for ( int n = 0 ; n < IM_ARRAYSIZE ( opened ) ; n + + )
if ( opened [ n ] & & ImGui : : BeginTabItem ( names [ n ] , & opened [ n ] , ImGuiTabItemFlags_None ) )
{
ImGui : : Text ( " This is the %s tab! " , names [ n ] ) ;
if ( n & 1 )
ImGui : : Text ( " I am an odd tab. " ) ;
ImGui : : EndTabItem ( ) ;
}
ImGui : : EndTabBar ( ) ;
}
ImGui : : Separator ( ) ;
ImGui : : TreePop ( ) ;
}
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Tabs/TabItemButton & Leading-Trailing flags " ) ;
2021-01-14 11:21:13 +01:00
if ( ImGui : : TreeNode ( " TabItemButton & Leading/Trailing flags " ) )
{
static ImVector < int > active_tabs ;
static int next_tab_id = 0 ;
if ( next_tab_id = = 0 ) // Initialize with some default tabs
for ( int i = 0 ; i < 3 ; i + + )
active_tabs . push_back ( next_tab_id + + ) ;
// TabItemButton() and Leading/Trailing flags are distinct features which we will demo together.
// (It is possible to submit regular tabs with Leading/Trailing flags, or TabItemButton tabs without Leading/Trailing flags...
// but they tend to make more sense together)
static bool show_leading_button = true ;
static bool show_trailing_button = true ;
ImGui : : Checkbox ( " Show Leading TabItemButton() " , & show_leading_button ) ;
ImGui : : Checkbox ( " Show Trailing TabItemButton() " , & show_trailing_button ) ;
// Expose some other flags which are useful to showcase how they interact with Leading/Trailing tabs
static ImGuiTabBarFlags tab_bar_flags = ImGuiTabBarFlags_AutoSelectNewTabs | ImGuiTabBarFlags_Reorderable | ImGuiTabBarFlags_FittingPolicyResizeDown ;
ImGui : : CheckboxFlags ( " ImGuiTabBarFlags_TabListPopupButton " , & tab_bar_flags , ImGuiTabBarFlags_TabListPopupButton ) ;
if ( ImGui : : CheckboxFlags ( " ImGuiTabBarFlags_FittingPolicyResizeDown " , & tab_bar_flags , ImGuiTabBarFlags_FittingPolicyResizeDown ) )
tab_bar_flags & = ~ ( ImGuiTabBarFlags_FittingPolicyMask_ ^ ImGuiTabBarFlags_FittingPolicyResizeDown ) ;
if ( ImGui : : CheckboxFlags ( " ImGuiTabBarFlags_FittingPolicyScroll " , & tab_bar_flags , ImGuiTabBarFlags_FittingPolicyScroll ) )
tab_bar_flags & = ~ ( ImGuiTabBarFlags_FittingPolicyMask_ ^ ImGuiTabBarFlags_FittingPolicyScroll ) ;
if ( ImGui : : BeginTabBar ( " MyTabBar " , tab_bar_flags ) )
{
// Demo a Leading TabItemButton(): click the "?" button to open a menu
if ( show_leading_button )
if ( ImGui : : TabItemButton ( " ? " , ImGuiTabItemFlags_Leading | ImGuiTabItemFlags_NoTooltip ) )
ImGui : : OpenPopup ( " MyHelpMenu " ) ;
if ( ImGui : : BeginPopup ( " MyHelpMenu " ) )
{
ImGui : : Selectable ( " Hello! " ) ;
ImGui : : EndPopup ( ) ;
}
2024-01-04 11:50:38 +01:00
// Demo Trailing Tabs: click the "+" button to add a new tab.
// (In your app you may want to use a font icon instead of the "+")
// We submit it before the regular tabs, but thanks to the ImGuiTabItemFlags_Trailing flag it will always appear at the end.
2021-01-14 11:21:13 +01:00
if ( show_trailing_button )
if ( ImGui : : TabItemButton ( " + " , ImGuiTabItemFlags_Trailing | ImGuiTabItemFlags_NoTooltip ) )
active_tabs . push_back ( next_tab_id + + ) ; // Add new tab
// Submit our regular tabs
for ( int n = 0 ; n < active_tabs . Size ; )
{
bool open = true ;
char name [ 16 ] ;
snprintf ( name , IM_ARRAYSIZE ( name ) , " %04d " , active_tabs [ n ] ) ;
if ( ImGui : : BeginTabItem ( name , & open , ImGuiTabItemFlags_None ) )
{
ImGui : : Text ( " This is the %s tab! " , name ) ;
ImGui : : EndTabItem ( ) ;
}
if ( ! open )
active_tabs . erase ( active_tabs . Data + n ) ;
else
n + + ;
}
ImGui : : EndTabBar ( ) ;
}
ImGui : : Separator ( ) ;
ImGui : : TreePop ( ) ;
}
ImGui : : TreePop ( ) ;
}
// Plot/Graph widgets are not very good.
2021-07-22 00:29:42 +02:00
// Consider using a third-party library such as ImPlot: https://github.com/epezent/implot
// (see others https://github.com/ocornut/imgui/wiki/Useful-Extensions)
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Plotting " ) ;
if ( ImGui : : TreeNode ( " Plotting " ) )
2018-10-25 23:40:33 +02:00
{
static bool animate = true ;
ImGui : : Checkbox ( " Animate " , & animate ) ;
2021-07-22 00:29:42 +02:00
// Plot as lines and plot as histogram
2018-10-25 23:40:33 +02:00
static float arr [ ] = { 0.6f , 0.1f , 1.0f , 0.5f , 0.92f , 0.1f , 0.2f } ;
ImGui : : PlotLines ( " Frame Times " , arr , IM_ARRAYSIZE ( arr ) ) ;
2021-07-22 00:29:42 +02:00
ImGui : : PlotHistogram ( " Histogram " , arr , IM_ARRAYSIZE ( arr ) , 0 , NULL , 0.0f , 1.0f , ImVec2 ( 0 , 80.0f ) ) ;
2024-04-03 03:18:49 +02:00
//ImGui::SameLine(); HelpMarker("Consider using ImPlot instead!");
2018-10-25 23:40:33 +02:00
2020-08-03 21:19:12 +02:00
// Fill an array of contiguous float values to plot
2020-05-05 19:39:24 +02:00
// Tip: If your float aren't contiguous but part of a structure, you can pass a pointer to your first float
// and the sizeof() of your structure in the "stride" parameter.
2019-10-18 12:54:30 +02:00
static float values [ 90 ] = { } ;
2018-10-25 23:40:33 +02:00
static int values_offset = 0 ;
static double refresh_time = 0.0 ;
2019-01-16 16:10:51 +01:00
if ( ! animate | | refresh_time = = 0.0 )
2018-10-25 23:40:33 +02:00
refresh_time = ImGui : : GetTime ( ) ;
2020-08-03 21:19:12 +02:00
while ( refresh_time < ImGui : : GetTime ( ) ) // Create data at fixed 60 Hz rate for the demo
2018-10-25 23:40:33 +02:00
{
static float phase = 0.0f ;
values [ values_offset ] = cosf ( phase ) ;
2020-06-30 15:31:54 +02:00
values_offset = ( values_offset + 1 ) % IM_ARRAYSIZE ( values ) ;
phase + = 0.10f * values_offset ;
refresh_time + = 1.0f / 60.0f ;
2015-07-22 01:00:28 +02:00
}
2019-08-27 01:52:08 +02:00
// Plots can display overlay texts
// (in this example, we will display an average value)
{
float average = 0.0f ;
for ( int n = 0 ; n < IM_ARRAYSIZE ( values ) ; n + + )
average + = values [ n ] ;
average / = ( float ) IM_ARRAYSIZE ( values ) ;
char overlay [ 32 ] ;
sprintf ( overlay , " avg %f " , average ) ;
2020-05-05 19:39:24 +02:00
ImGui : : PlotLines ( " Lines " , values , IM_ARRAYSIZE ( values ) , values_offset , overlay , - 1.0f , 1.0f , ImVec2 ( 0 , 80.0f ) ) ;
2019-08-27 01:52:08 +02:00
}
2015-07-22 01:00:28 +02:00
2018-10-25 23:40:33 +02:00
// Use functions to generate output
2023-02-10 12:16:23 +01:00
// FIXME: This is actually VERY awkward because current plot API only pass in indices.
2020-05-05 19:39:24 +02:00
// We probably want an API passing floats and user provide sample rate/count.
2018-10-25 23:40:33 +02:00
struct Funcs
{
static float Sin ( void * , int i ) { return sinf ( i * 0.1f ) ; }
static float Saw ( void * , int i ) { return ( i & 1 ) ? 1.0f : - 1.0f ; }
} ;
static int func_type = 0 , display_count = 70 ;
2023-02-10 12:16:23 +01:00
ImGui : : SeparatorText ( " Functions " ) ;
2021-05-24 12:49:58 +02:00
ImGui : : SetNextItemWidth ( ImGui : : GetFontSize ( ) * 8 ) ;
2019-04-18 18:29:28 +02:00
ImGui : : Combo ( " func " , & func_type , " Sin \0 Saw \0 " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : SameLine ( ) ;
ImGui : : SliderInt ( " Sample count " , & display_count , 1 , 400 ) ;
float ( * func ) ( void * , int ) = ( func_type = = 0 ) ? Funcs : : Sin : Funcs : : Saw ;
2024-09-09 21:07:10 +02:00
ImGui : : PlotLines ( " Lines##2 " , func , NULL , display_count , 0 , NULL , - 1.0f , 1.0f , ImVec2 ( 0 , 80 ) ) ;
ImGui : : PlotHistogram ( " Histogram##2 " , func , NULL , display_count , 0 , NULL , - 1.0f , 1.0f , ImVec2 ( 0 , 80 ) ) ;
2018-10-25 23:40:33 +02:00
ImGui : : Separator ( ) ;
2015-07-22 01:00:28 +02:00
2024-09-03 21:49:35 +02:00
ImGui : : Text ( " Need better plotting and graphing? Consider using ImPlot: " ) ;
ImGui : : TextLinkOpenURL ( " https://github.com/epezent/implot " ) ;
ImGui : : Separator ( ) ;
2024-04-24 19:39:03 +02:00
ImGui : : TreePop ( ) ;
}
IMGUI_DEMO_MARKER ( " Widgets/Progress Bars " ) ;
if ( ImGui : : TreeNode ( " Progress Bars " ) )
{
2018-10-25 23:40:33 +02:00
// Animate a simple progress bar
static float progress = 0.0f , progress_dir = 1.0f ;
2024-04-24 19:39:03 +02:00
progress + = progress_dir * 0.4f * ImGui : : GetIO ( ) . DeltaTime ;
if ( progress > = + 1.1f ) { progress = + 1.1f ; progress_dir * = - 1.0f ; }
if ( progress < = - 0.1f ) { progress = - 0.1f ; progress_dir * = - 1.0f ; }
2015-07-22 01:00:28 +02:00
2019-09-17 11:33:18 +02:00
// Typically we would use ImVec2(-1.0f,0.0f) or ImVec2(-FLT_MIN,0.0f) to use all available width,
2019-06-21 19:38:33 +02:00
// or ImVec2(width,0.0f) for a specified width. ImVec2(0.0f,0.0f) uses ItemWidth.
2020-06-30 15:31:54 +02:00
ImGui : : ProgressBar ( progress , ImVec2 ( 0.0f , 0.0f ) ) ;
2018-10-25 23:40:33 +02:00
ImGui : : SameLine ( 0.0f , ImGui : : GetStyle ( ) . ItemInnerSpacing . x ) ;
ImGui : : Text ( " Progress Bar " ) ;
2015-07-22 01:00:28 +02:00
2020-05-07 11:38:45 +02:00
float progress_saturated = IM_CLAMP ( progress , 0.0f , 1.0f ) ;
2018-10-25 23:40:33 +02:00
char buf [ 32 ] ;
2020-06-30 15:31:54 +02:00
sprintf ( buf , " %d/%d " , ( int ) ( progress_saturated * 1753 ) , 1753 ) ;
ImGui : : ProgressBar ( progress , ImVec2 ( 0.f , 0.f ) , buf ) ;
2024-04-24 19:32:36 +02:00
2024-04-24 19:39:03 +02:00
// Pass an animated negative value, e.g. -1.0f * (float)ImGui::GetTime() is the recommended value.
// Adjust the factor if you want to adjust the animation speed.
2024-04-24 19:32:36 +02:00
ImGui : : ProgressBar ( - 1.0f * ( float ) ImGui : : GetTime ( ) , ImVec2 ( 0.0f , 0.0f ) , " Searching.. " ) ;
ImGui : : SameLine ( 0.0f , ImGui : : GetStyle ( ) . ItemInnerSpacing . x ) ;
ImGui : : Text ( " Indeterminate " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : TreePop ( ) ;
}
2017-08-08 12:04:31 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Color " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Color/Picker Widgets " ) )
{
2020-06-30 15:31:54 +02:00
static ImVec4 color = ImVec4 ( 114.0f / 255.0f , 144.0f / 255.0f , 154.0f / 255.0f , 200.0f / 255.0f ) ;
2018-10-25 23:40:33 +02:00
static bool alpha_preview = true ;
static bool alpha_half_preview = false ;
static bool drag_and_drop = true ;
static bool options_menu = true ;
static bool hdr = false ;
2023-02-10 12:16:23 +01:00
ImGui : : SeparatorText ( " Options " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : Checkbox ( " With Alpha Preview " , & alpha_preview ) ;
ImGui : : Checkbox ( " With Half Alpha Preview " , & alpha_half_preview ) ;
ImGui : : Checkbox ( " With Drag and Drop " , & drag_and_drop ) ;
2019-03-06 18:19:28 +01:00
ImGui : : Checkbox ( " With Options Menu " , & options_menu ) ; ImGui : : SameLine ( ) ; HelpMarker ( " Right-click on the individual color widget to show options. " ) ;
ImGui : : Checkbox ( " With HDR " , & hdr ) ; ImGui : : SameLine ( ) ; HelpMarker ( " Currently all this does is to lift the 0..1 limits on dragging widgets. " ) ;
2019-07-23 18:49:17 +02:00
ImGuiColorEditFlags misc_flags = ( hdr ? ImGuiColorEditFlags_HDR : 0 ) | ( drag_and_drop ? 0 : ImGuiColorEditFlags_NoDragDrop ) | ( alpha_half_preview ? ImGuiColorEditFlags_AlphaPreviewHalf : ( alpha_preview ? ImGuiColorEditFlags_AlphaPreview : 0 ) ) | ( options_menu ? 0 : ImGuiColorEditFlags_NoOptions ) ;
2018-10-25 23:40:33 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Color/ColorEdit " ) ;
2023-02-10 12:16:23 +01:00
ImGui : : SeparatorText ( " Inline color editor " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : Text ( " Color widget: " ) ;
2020-05-05 19:39:24 +02:00
ImGui : : SameLine ( ) ; HelpMarker (
2020-10-15 20:05:35 +02:00
" Click on the color square to open a color picker. \n "
2020-05-05 19:39:24 +02:00
" CTRL+click on individual component to input value. \n " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : ColorEdit3 ( " MyColor##1 " , ( float * ) & color , misc_flags ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Color/ColorEdit (HSV, with Alpha) " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : Text ( " Color widget HSV with Alpha: " ) ;
2019-02-27 16:45:58 +01:00
ImGui : : ColorEdit4 ( " MyColor##2 " , ( float * ) & color , ImGuiColorEditFlags_DisplayHSV | misc_flags ) ;
2018-10-25 23:40:33 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Color/ColorEdit (float display) " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : Text ( " Color widget with Float Display: " ) ;
ImGui : : ColorEdit4 ( " MyColor##2f " , ( float * ) & color , ImGuiColorEditFlags_Float | misc_flags ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Color/ColorButton (with Picker) " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : Text ( " Color button with Picker: " ) ;
2020-05-05 19:39:24 +02:00
ImGui : : SameLine ( ) ; HelpMarker (
" With the ImGuiColorEditFlags_NoInputs flag you can hide all the slider/text inputs. \n "
" With the ImGuiColorEditFlags_NoLabel flag you can pass a non-empty label which will only "
" be used for the tooltip and picker popup. " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : ColorEdit4 ( " MyColor##3 " , ( float * ) & color , ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel | misc_flags ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Color/ColorButton (with custom Picker popup) " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : Text ( " Color button with Custom Picker Popup: " ) ;
2020-08-03 21:19:12 +02:00
// Generate a default palette. The palette will persist and can be edited.
2019-01-30 10:52:13 +01:00
static bool saved_palette_init = true ;
2019-10-18 12:54:30 +02:00
static ImVec4 saved_palette [ 32 ] = { } ;
2019-01-30 10:52:13 +01:00
if ( saved_palette_init )
{
2018-10-25 23:40:33 +02:00
for ( int n = 0 ; n < IM_ARRAYSIZE ( saved_palette ) ; n + + )
2017-08-08 12:04:31 +02:00
{
2020-05-05 19:39:24 +02:00
ImGui : : ColorConvertHSVtoRGB ( n / 31.0f , 0.8f , 0.8f ,
saved_palette [ n ] . x , saved_palette [ n ] . y , saved_palette [ n ] . z ) ;
2018-10-25 23:40:33 +02:00
saved_palette [ n ] . w = 1.0f ; // Alpha
2017-08-08 12:04:31 +02:00
}
2019-01-30 10:52:13 +01:00
saved_palette_init = false ;
}
2015-07-22 01:00:28 +02:00
2018-10-25 23:40:33 +02:00
static ImVec4 backup_color ;
bool open_popup = ImGui : : ColorButton ( " MyColor##3b " , color , misc_flags ) ;
2019-07-17 01:43:21 +02:00
ImGui : : SameLine ( 0 , ImGui : : GetStyle ( ) . ItemInnerSpacing . x ) ;
2018-10-25 23:40:33 +02:00
open_popup | = ImGui : : Button ( " Palette " ) ;
if ( open_popup )
{
ImGui : : OpenPopup ( " mypicker " ) ;
backup_color = color ;
2015-07-22 01:00:28 +02:00
}
2018-10-25 23:40:33 +02:00
if ( ImGui : : BeginPopup ( " mypicker " ) )
2017-07-22 12:01:29 +02:00
{
2018-10-25 23:40:33 +02:00
ImGui : : Text ( " MY CUSTOM COLOR PICKER WITH AN AMAZING PALETTE! " ) ;
ImGui : : Separator ( ) ;
ImGui : : ColorPicker4 ( " ##picker " , ( float * ) & color , misc_flags | ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_NoSmallPreview ) ;
2017-07-30 11:37:28 +02:00
ImGui : : SameLine ( ) ;
2019-01-30 10:52:13 +01:00
ImGui : : BeginGroup ( ) ; // Lock X position
2018-10-25 23:40:33 +02:00
ImGui : : Text ( " Current " ) ;
2020-06-30 15:31:54 +02:00
ImGui : : ColorButton ( " ##current " , color , ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_AlphaPreviewHalf , ImVec2 ( 60 , 40 ) ) ;
2018-10-25 23:40:33 +02:00
ImGui : : Text ( " Previous " ) ;
2020-06-30 15:31:54 +02:00
if ( ImGui : : ColorButton ( " ##previous " , backup_color , ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_AlphaPreviewHalf , ImVec2 ( 60 , 40 ) ) )
2018-10-25 23:40:33 +02:00
color = backup_color ;
ImGui : : Separator ( ) ;
ImGui : : Text ( " Palette " ) ;
for ( int n = 0 ; n < IM_ARRAYSIZE ( saved_palette ) ; n + + )
2017-07-30 11:37:28 +02:00
{
2018-10-25 23:40:33 +02:00
ImGui : : PushID ( n ) ;
if ( ( n % 8 ) ! = 0 )
ImGui : : SameLine ( 0.0f , ImGui : : GetStyle ( ) . ItemSpacing . y ) ;
2020-05-05 19:39:24 +02:00
ImGuiColorEditFlags palette_button_flags = ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_NoTooltip ;
2020-06-30 15:31:54 +02:00
if ( ImGui : : ColorButton ( " ##palette " , saved_palette [ n ] , palette_button_flags , ImVec2 ( 20 , 20 ) ) )
2018-10-25 23:40:33 +02:00
color = ImVec4 ( saved_palette [ n ] . x , saved_palette [ n ] . y , saved_palette [ n ] . z , color . w ) ; // Preserve alpha!
2017-07-30 11:37:28 +02:00
2020-05-05 19:39:24 +02:00
// Allow user to drop colors into each palette entry. Note that ColorButton() is already a
// drag source by default, unless specifying the ImGuiColorEditFlags_NoDragDrop flag.
2018-10-25 23:40:33 +02:00
if ( ImGui : : BeginDragDropTarget ( ) )
2017-07-29 11:23:32 +02:00
{
2018-10-25 23:40:33 +02:00
if ( const ImGuiPayload * payload = ImGui : : AcceptDragDropPayload ( IMGUI_PAYLOAD_TYPE_COLOR_3F ) )
memcpy ( ( float * ) & saved_palette [ n ] , payload - > Data , sizeof ( float ) * 3 ) ;
if ( const ImGuiPayload * payload = ImGui : : AcceptDragDropPayload ( IMGUI_PAYLOAD_TYPE_COLOR_4F ) )
memcpy ( ( float * ) & saved_palette [ n ] , payload - > Data , sizeof ( float ) * 4 ) ;
ImGui : : EndDragDropTarget ( ) ;
2017-07-29 11:23:32 +02:00
}
2017-08-08 09:54:20 +02:00
2018-10-25 23:40:33 +02:00
ImGui : : PopID ( ) ;
}
ImGui : : EndGroup ( ) ;
ImGui : : EndPopup ( ) ;
2017-07-22 12:01:29 +02:00
}
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Color/ColorButton (simple) " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : Text ( " Color button only: " ) ;
2020-02-10 21:23:34 +01:00
static bool no_border = false ;
ImGui : : Checkbox ( " ImGuiColorEditFlags_NoBorder " , & no_border ) ;
2020-06-30 15:31:54 +02:00
ImGui : : ColorButton ( " MyColor##3c " , * ( ImVec4 * ) & color , misc_flags | ( no_border ? ImGuiColorEditFlags_NoBorder : 0 ) , ImVec2 ( 80 , 80 ) ) ;
2018-10-25 23:40:33 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Color/ColorPicker " ) ;
2023-02-10 12:16:23 +01:00
ImGui : : SeparatorText ( " Color picker " ) ;
2018-10-25 23:40:33 +02:00
static bool alpha = true ;
static bool alpha_bar = true ;
static bool side_preview = true ;
static bool ref_color = false ;
2020-06-30 15:31:54 +02:00
static ImVec4 ref_color_v ( 1.0f , 0.0f , 1.0f , 0.5f ) ;
2019-02-27 16:45:58 +01:00
static int display_mode = 0 ;
2018-10-25 23:40:33 +02:00
static int picker_mode = 0 ;
ImGui : : Checkbox ( " With Alpha " , & alpha ) ;
ImGui : : Checkbox ( " With Alpha Bar " , & alpha_bar ) ;
ImGui : : Checkbox ( " With Side Preview " , & side_preview ) ;
if ( side_preview )
2015-07-22 01:00:28 +02:00
{
2018-10-25 23:40:33 +02:00
ImGui : : SameLine ( ) ;
ImGui : : Checkbox ( " With Ref Color " , & ref_color ) ;
if ( ref_color )
{
ImGui : : SameLine ( ) ;
ImGui : : ColorEdit4 ( " ##RefColor " , & ref_color_v . x , ImGuiColorEditFlags_NoInputs | misc_flags ) ;
}
2015-07-22 01:00:28 +02:00
}
2019-02-27 16:45:58 +01:00
ImGui : : Combo ( " Display Mode " , & display_mode , " Auto/Current \0 None \0 RGB Only \0 HSV Only \0 Hex Only \0 " ) ;
2020-05-05 19:39:24 +02:00
ImGui : : SameLine ( ) ; HelpMarker (
" ColorEdit defaults to displaying RGB inputs if you don't specify a display mode, "
2022-04-22 17:15:09 +02:00
" but the user can change it with a right-click on those inputs. \n \n ColorPicker defaults to displaying RGB+HSV+Hex "
2020-05-05 19:39:24 +02:00
" if you don't specify a display mode. \n \n You can change the defaults using SetColorEditOptions(). " ) ;
2022-04-22 17:15:09 +02:00
ImGui : : SameLine ( ) ; HelpMarker ( " When not specified explicitly (Auto/Current mode), user can right-click the picker to change mode. " ) ;
2018-10-25 23:40:33 +02:00
ImGuiColorEditFlags flags = misc_flags ;
2019-02-27 16:45:58 +01:00
if ( ! alpha ) flags | = ImGuiColorEditFlags_NoAlpha ; // This is by default if you call ColorPicker3() instead of ColorPicker4()
if ( alpha_bar ) flags | = ImGuiColorEditFlags_AlphaBar ;
if ( ! side_preview ) flags | = ImGuiColorEditFlags_NoSidePreview ;
if ( picker_mode = = 1 ) flags | = ImGuiColorEditFlags_PickerHueBar ;
if ( picker_mode = = 2 ) flags | = ImGuiColorEditFlags_PickerHueWheel ;
if ( display_mode = = 1 ) flags | = ImGuiColorEditFlags_NoInputs ; // Disable all RGB/HSV/Hex displays
if ( display_mode = = 2 ) flags | = ImGuiColorEditFlags_DisplayRGB ; // Override display mode
if ( display_mode = = 3 ) flags | = ImGuiColorEditFlags_DisplayHSV ;
if ( display_mode = = 4 ) flags | = ImGuiColorEditFlags_DisplayHex ;
2018-10-25 23:40:33 +02:00
ImGui : : ColorPicker4 ( " MyColor##4 " , ( float * ) & color , flags , ref_color ? & ref_color_v . x : NULL ) ;
2020-05-05 19:39:24 +02:00
ImGui : : Text ( " Set defaults in code: " ) ;
ImGui : : SameLine ( ) ; HelpMarker (
" SetColorEditOptions() is designed to allow you to set boot-time default. \n "
" We don't have Push/Pop functions because you can force options on a per-widget basis if needed, "
" and the user can change non-forced ones with the options menu. \n We don't have a getter to avoid "
" encouraging you to persistently save values that aren't forward-compatible. " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : Button ( " Default: Uint8 + HSV + Hue Bar " ) )
2019-02-27 16:45:58 +01:00
ImGui : : SetColorEditOptions ( ImGuiColorEditFlags_Uint8 | ImGuiColorEditFlags_DisplayHSV | ImGuiColorEditFlags_PickerHueBar ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : Button ( " Default: Float + HDR + Hue Wheel " ) )
ImGui : : SetColorEditOptions ( ImGuiColorEditFlags_Float | ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_PickerHueWheel ) ;
2024-01-04 11:50:38 +01:00
// Always display a small version of both types of pickers
// (that's in order to make it more visible in the demo to people who are skimming quickly through it)
2022-04-14 15:09:56 +02:00
ImGui : : Text ( " Both types: " ) ;
float w = ( ImGui : : GetContentRegionAvail ( ) . x - ImGui : : GetStyle ( ) . ItemSpacing . y ) * 0.40f ;
ImGui : : SetNextItemWidth ( w ) ;
ImGui : : ColorPicker3 ( " ##MyColor##5 " , ( float * ) & color , ImGuiColorEditFlags_PickerHueBar | ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoAlpha ) ;
ImGui : : SameLine ( ) ;
ImGui : : SetNextItemWidth ( w ) ;
ImGui : : ColorPicker3 ( " ##MyColor##6 " , ( float * ) & color , ImGuiColorEditFlags_PickerHueWheel | ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoAlpha ) ;
2019-03-07 15:31:29 +01:00
// HSV encoded support (to avoid RGB<>HSV round trips and singularities when S==0 or V==0)
2020-05-05 19:39:24 +02:00
static ImVec4 color_hsv ( 0.23f , 1.0f , 1.0f , 1.0f ) ; // Stored as HSV!
2019-03-07 15:31:29 +01:00
ImGui : : Spacing ( ) ;
ImGui : : Text ( " HSV encoded colors " ) ;
2020-05-05 19:39:24 +02:00
ImGui : : SameLine ( ) ; HelpMarker (
" By default, colors are given to ColorEdit and ColorPicker in RGB, but ImGuiColorEditFlags_InputHSV "
" allows you to store colors as HSV and pass them to ColorEdit and ColorPicker as HSV. This comes with the "
" added benefit that you can manipulate hue values with the picker even when saturation or value are zero. " ) ;
2019-03-07 15:31:29 +01:00
ImGui : : Text ( " Color widget with InputHSV: " ) ;
2020-05-05 19:39:24 +02:00
ImGui : : ColorEdit4 ( " HSV shown as RGB##1 " , ( float * ) & color_hsv , ImGuiColorEditFlags_DisplayRGB | ImGuiColorEditFlags_InputHSV | ImGuiColorEditFlags_Float ) ;
ImGui : : ColorEdit4 ( " HSV shown as HSV##1 " , ( float * ) & color_hsv , ImGuiColorEditFlags_DisplayHSV | ImGuiColorEditFlags_InputHSV | ImGuiColorEditFlags_Float ) ;
ImGui : : DragFloat4 ( " Raw HSV values " , ( float * ) & color_hsv , 0.01f , 0.0f , 1.0f ) ;
2019-03-07 15:31:29 +01:00
2018-10-25 23:40:33 +02:00
ImGui : : TreePop ( ) ;
}
2015-07-22 01:00:28 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Drag and Slider Flags " ) ;
2020-07-23 17:39:22 +02:00
if ( ImGui : : TreeNode ( " Drag/Slider Flags " ) )
{
2020-08-18 17:02:58 +02:00
// Demonstrate using advanced flags for DragXXX and SliderXXX functions. Note that the flags are the same!
static ImGuiSliderFlags flags = ImGuiSliderFlags_None ;
2020-11-05 21:23:02 +01:00
ImGui : : CheckboxFlags ( " ImGuiSliderFlags_AlwaysClamp " , & flags , ImGuiSliderFlags_AlwaysClamp ) ;
2024-10-03 16:17:45 +02:00
ImGui : : CheckboxFlags ( " ImGuiSliderFlags_ClampOnInput " , & flags , ImGuiSliderFlags_ClampOnInput ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Clamp value to min/max bounds when input manually with CTRL+Click. By default CTRL+Click allows going out of bounds. " ) ;
ImGui : : CheckboxFlags ( " ImGuiSliderFlags_ClampZeroRange " , & flags , ImGuiSliderFlags_ClampZeroRange ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Clamp even if min==max==0.0f. Otherwise DragXXX functions don't clamp. " ) ;
2020-11-05 21:23:02 +01:00
ImGui : : CheckboxFlags ( " ImGuiSliderFlags_Logarithmic " , & flags , ImGuiSliderFlags_Logarithmic ) ;
2020-07-23 17:39:22 +02:00
ImGui : : SameLine ( ) ; HelpMarker ( " Enable logarithmic editing (more precision for small values). " ) ;
2020-11-05 21:23:02 +01:00
ImGui : : CheckboxFlags ( " ImGuiSliderFlags_NoRoundToFormat " , & flags , ImGuiSliderFlags_NoRoundToFormat ) ;
2020-07-23 23:01:10 +02:00
ImGui : : SameLine ( ) ; HelpMarker ( " Disable rounding underlying value to match precision of the format string (e.g. %.3f values are rounded to those 3 digits). " ) ;
2020-11-05 21:23:02 +01:00
ImGui : : CheckboxFlags ( " ImGuiSliderFlags_NoInput " , & flags , ImGuiSliderFlags_NoInput ) ;
2020-07-24 13:41:14 +02:00
ImGui : : SameLine ( ) ; HelpMarker ( " Disable CTRL+Click or Enter key allowing to input text directly into the widget. " ) ;
2024-06-28 18:06:16 +02:00
ImGui : : CheckboxFlags ( " ImGuiSliderFlags_WrapAround " , & flags , ImGuiSliderFlags_WrapAround ) ;
2024-06-28 15:54:40 +02:00
ImGui : : SameLine ( ) ; HelpMarker ( " Enable wrapping around from max to min and from min to max (only supported by DragXXX() functions) " ) ;
2020-07-23 17:39:22 +02:00
2020-08-18 17:02:58 +02:00
// Drags
2020-07-23 17:39:22 +02:00
static float drag_f = 0.5f ;
static int drag_i = 50 ;
2020-07-23 23:01:10 +02:00
ImGui : : Text ( " Underlying float value: %f " , drag_f ) ;
2020-08-18 17:02:58 +02:00
ImGui : : DragFloat ( " DragFloat (0 -> 1) " , & drag_f , 0.005f , 0.0f , 1.0f , " %.3f " , flags ) ;
ImGui : : DragFloat ( " DragFloat (0 -> +inf) " , & drag_f , 0.005f , 0.0f , FLT_MAX , " %.3f " , flags ) ;
ImGui : : DragFloat ( " DragFloat (-inf -> 1) " , & drag_f , 0.005f , - FLT_MAX , 1.0f , " %.3f " , flags ) ;
ImGui : : DragFloat ( " DragFloat (-inf -> +inf) " , & drag_f , 0.005f , - FLT_MAX , + FLT_MAX , " %.3f " , flags ) ;
2024-10-03 16:17:45 +02:00
//ImGui::DragFloat("DragFloat (0 -> 0)", &drag_f, 0.005f, 0.0f, 0.0f, "%.3f", flags); // To test ClampZeroRange
//ImGui::DragFloat("DragFloat (100 -> 100)", &drag_f, 0.005f, 100.0f, 100.0f, "%.3f", flags);
2020-08-18 17:02:58 +02:00
ImGui : : DragInt ( " DragInt (0 -> 100) " , & drag_i , 0.5f , 0 , 100 , " %d " , flags ) ;
2020-07-23 17:39:22 +02:00
2020-08-18 17:02:58 +02:00
// Sliders
2020-07-23 17:39:22 +02:00
static float slider_f = 0.5f ;
static int slider_i = 50 ;
2024-06-28 18:06:16 +02:00
const ImGuiSliderFlags flags_for_sliders = flags & ~ ImGuiSliderFlags_WrapAround ;
2020-07-23 23:01:10 +02:00
ImGui : : Text ( " Underlying float value: %f " , slider_f ) ;
2024-06-28 15:54:40 +02:00
ImGui : : SliderFloat ( " SliderFloat (0 -> 1) " , & slider_f , 0.0f , 1.0f , " %.3f " , flags_for_sliders ) ;
ImGui : : SliderInt ( " SliderInt (0 -> 100) " , & slider_i , 0 , 100 , " %d " , flags_for_sliders ) ;
2020-07-23 17:39:22 +02:00
ImGui : : TreePop ( ) ;
}
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Range Widgets " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Range Widgets " ) )
{
static float begin = 10 , end = 90 ;
static int begin_i = 100 , end_i = 1000 ;
2020-09-25 13:34:31 +02:00
ImGui : : DragFloatRange2 ( " range float " , & begin , & end , 0.25f , 0.0f , 100.0f , " Min: %.1f %% " , " Max: %.1f %% " , ImGuiSliderFlags_AlwaysClamp ) ;
2020-07-23 19:03:48 +02:00
ImGui : : DragIntRange2 ( " range int " , & begin_i , & end_i , 5 , 0 , 1000 , " Min: %d units " , " Max: %d units " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : DragIntRange2 ( " range int (no bounds) " , & begin_i , & end_i , 5 , 0 , 0 , " Min: %d units " , " Max: %d units " ) ;
ImGui : : TreePop ( ) ;
}
2018-05-12 17:53:34 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Data Types " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Data Types " ) )
{
2020-05-05 19:39:24 +02:00
// DragScalar/InputScalar/SliderScalar functions allow various data types
// - signed/unsigned
// - 8/16/32/64-bits
// - integer/float/double
// To avoid polluting the public API with all possible combinations, we use the ImGuiDataType enum
// to pass the type, and passing all arguments by pointer.
2022-09-11 07:35:59 +02:00
// This is the reason the test code below creates local variables to hold "zero" "one" etc. for each type.
2020-05-05 19:39:24 +02:00
// In practice, if you frequently use a given type that is not covered by the normal API entry points,
// you can wrap it yourself inside a 1 line function which can take typed argument as value instead of void*,
// and then pass their address to the generic function. For example:
2019-01-20 17:56:17 +01:00
// bool MySliderU64(const char *label, u64* value, u64 min = 0, u64 max = 0, const char* format = "%lld")
// {
// return SliderScalar(label, ImGuiDataType_U64, value, &min, &max, format);
2018-10-25 23:40:33 +02:00
// }
2020-05-05 19:39:24 +02:00
// Setup limits (as helper variables so we can take their address, as explained above)
// Note: SliderScalar() functions have a maximum usable range of half the natural type maximum, hence the /2.
2018-10-25 23:40:33 +02:00
# ifndef LLONG_MIN
ImS64 LLONG_MIN = - 9223372036854775807LL - 1 ;
ImS64 LLONG_MAX = 9223372036854775807LL ;
ImU64 ULLONG_MAX = ( 2ULL * 9223372036854775807LL + 1 ) ;
# endif
2019-02-27 18:16:03 +01:00
const char s8_zero = 0 , s8_one = 1 , s8_fifty = 50 , s8_min = - 128 , s8_max = 127 ;
const ImU8 u8_zero = 0 , u8_one = 1 , u8_fifty = 50 , u8_min = 0 , u8_max = 255 ;
const short s16_zero = 0 , s16_one = 1 , s16_fifty = 50 , s16_min = - 32768 , s16_max = 32767 ;
const ImU16 u16_zero = 0 , u16_one = 1 , u16_fifty = 50 , u16_min = 0 , u16_max = 65535 ;
2018-10-25 23:40:33 +02:00
const ImS32 s32_zero = 0 , s32_one = 1 , s32_fifty = 50 , s32_min = INT_MIN / 2 , s32_max = INT_MAX / 2 , s32_hi_a = INT_MAX / 2 - 100 , s32_hi_b = INT_MAX / 2 ;
const ImU32 u32_zero = 0 , u32_one = 1 , u32_fifty = 50 , u32_min = 0 , u32_max = UINT_MAX / 2 , u32_hi_a = UINT_MAX / 2 - 100 , u32_hi_b = UINT_MAX / 2 ;
const ImS64 s64_zero = 0 , s64_one = 1 , s64_fifty = 50 , s64_min = LLONG_MIN / 2 , s64_max = LLONG_MAX / 2 , s64_hi_a = LLONG_MAX / 2 - 100 , s64_hi_b = LLONG_MAX / 2 ;
const ImU64 u64_zero = 0 , u64_one = 1 , u64_fifty = 50 , u64_min = 0 , u64_max = ULLONG_MAX / 2 , u64_hi_a = ULLONG_MAX / 2 - 100 , u64_hi_b = ULLONG_MAX / 2 ;
const float f32_zero = 0.f , f32_one = 1.f , f32_lo_a = - 10000000000.0f , f32_hi_a = + 10000000000.0f ;
const double f64_zero = 0. , f64_one = 1. , f64_lo_a = - 1000000000000000.0 , f64_hi_a = + 1000000000000000.0 ;
// State
2019-02-27 18:16:03 +01:00
static char s8_v = 127 ;
static ImU8 u8_v = 255 ;
static short s16_v = 32767 ;
static ImU16 u16_v = 65535 ;
2018-10-25 23:40:33 +02:00
static ImS32 s32_v = - 1 ;
static ImU32 u32_v = ( ImU32 ) - 1 ;
static ImS64 s64_v = - 1 ;
static ImU64 u64_v = ( ImU64 ) - 1 ;
static float f32_v = 0.123f ;
static double f64_v = 90000.01234567890123456789 ;
const float drag_speed = 0.2f ;
static bool drag_clamp = false ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Data Types/Drags " ) ;
2023-02-10 12:16:23 +01:00
ImGui : : SeparatorText ( " Drags " ) ;
2020-08-28 16:49:46 +02:00
ImGui : : Checkbox ( " Clamp integers to 0..50 " , & drag_clamp ) ;
ImGui : : SameLine ( ) ; HelpMarker (
2022-09-14 18:19:50 +02:00
" As with every widget in dear imgui, we never modify values unless there is a user interaction. \n "
2020-08-28 16:49:46 +02:00
" You can override the clamping limits by using CTRL+Click to input a value. " ) ;
2019-02-27 18:16:03 +01:00
ImGui : : DragScalar ( " drag s8 " , ImGuiDataType_S8 , & s8_v , drag_speed , drag_clamp ? & s8_zero : NULL , drag_clamp ? & s8_fifty : NULL ) ;
ImGui : : DragScalar ( " drag u8 " , ImGuiDataType_U8 , & u8_v , drag_speed , drag_clamp ? & u8_zero : NULL , drag_clamp ? & u8_fifty : NULL , " %u ms " ) ;
ImGui : : DragScalar ( " drag s16 " , ImGuiDataType_S16 , & s16_v , drag_speed , drag_clamp ? & s16_zero : NULL , drag_clamp ? & s16_fifty : NULL ) ;
ImGui : : DragScalar ( " drag u16 " , ImGuiDataType_U16 , & u16_v , drag_speed , drag_clamp ? & u16_zero : NULL , drag_clamp ? & u16_fifty : NULL , " %u ms " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : DragScalar ( " drag s32 " , ImGuiDataType_S32 , & s32_v , drag_speed , drag_clamp ? & s32_zero : NULL , drag_clamp ? & s32_fifty : NULL ) ;
2022-04-05 15:13:37 +02:00
ImGui : : DragScalar ( " drag s32 hex " , ImGuiDataType_S32 , & s32_v , drag_speed , drag_clamp ? & s32_zero : NULL , drag_clamp ? & s32_fifty : NULL , " 0x%08X " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : DragScalar ( " drag u32 " , ImGuiDataType_U32 , & u32_v , drag_speed , drag_clamp ? & u32_zero : NULL , drag_clamp ? & u32_fifty : NULL , " %u ms " ) ;
ImGui : : DragScalar ( " drag s64 " , ImGuiDataType_S64 , & s64_v , drag_speed , drag_clamp ? & s64_zero : NULL , drag_clamp ? & s64_fifty : NULL ) ;
ImGui : : DragScalar ( " drag u64 " , ImGuiDataType_U64 , & u64_v , drag_speed , drag_clamp ? & u64_zero : NULL , drag_clamp ? & u64_fifty : NULL ) ;
2020-07-22 18:00:50 +02:00
ImGui : : DragScalar ( " drag float " , ImGuiDataType_Float , & f32_v , 0.005f , & f32_zero , & f32_one , " %f " ) ;
2020-08-18 17:02:58 +02:00
ImGui : : DragScalar ( " drag float log " , ImGuiDataType_Float , & f32_v , 0.005f , & f32_zero , & f32_one , " %f " , ImGuiSliderFlags_Logarithmic ) ;
2020-07-22 18:00:50 +02:00
ImGui : : DragScalar ( " drag double " , ImGuiDataType_Double , & f64_v , 0.0005f , & f64_zero , NULL , " %.10f grams " ) ;
2020-08-18 17:02:58 +02:00
ImGui : : DragScalar ( " drag double log " , ImGuiDataType_Double , & f64_v , 0.0005f , & f64_zero , & f64_one , " 0 < %.10f < 1 " , ImGuiSliderFlags_Logarithmic ) ;
2018-10-25 23:40:33 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Data Types/Sliders " ) ;
2023-02-10 12:16:23 +01:00
ImGui : : SeparatorText ( " Sliders " ) ;
2020-07-22 18:00:50 +02:00
ImGui : : SliderScalar ( " slider s8 full " , ImGuiDataType_S8 , & s8_v , & s8_min , & s8_max , " %d " ) ;
ImGui : : SliderScalar ( " slider u8 full " , ImGuiDataType_U8 , & u8_v , & u8_min , & u8_max , " %u " ) ;
ImGui : : SliderScalar ( " slider s16 full " , ImGuiDataType_S16 , & s16_v , & s16_min , & s16_max , " %d " ) ;
ImGui : : SliderScalar ( " slider u16 full " , ImGuiDataType_U16 , & u16_v , & u16_min , & u16_max , " %u " ) ;
ImGui : : SliderScalar ( " slider s32 low " , ImGuiDataType_S32 , & s32_v , & s32_zero , & s32_fifty , " %d " ) ;
ImGui : : SliderScalar ( " slider s32 high " , ImGuiDataType_S32 , & s32_v , & s32_hi_a , & s32_hi_b , " %d " ) ;
ImGui : : SliderScalar ( " slider s32 full " , ImGuiDataType_S32 , & s32_v , & s32_min , & s32_max , " %d " ) ;
2022-04-05 15:13:37 +02:00
ImGui : : SliderScalar ( " slider s32 hex " , ImGuiDataType_S32 , & s32_v , & s32_zero , & s32_fifty , " 0x%04X " ) ;
2020-07-22 18:00:50 +02:00
ImGui : : SliderScalar ( " slider u32 low " , ImGuiDataType_U32 , & u32_v , & u32_zero , & u32_fifty , " %u " ) ;
ImGui : : SliderScalar ( " slider u32 high " , ImGuiDataType_U32 , & u32_v , & u32_hi_a , & u32_hi_b , " %u " ) ;
ImGui : : SliderScalar ( " slider u32 full " , ImGuiDataType_U32 , & u32_v , & u32_min , & u32_max , " %u " ) ;
2023-08-07 15:23:59 +02:00
ImGui : : SliderScalar ( " slider s64 low " , ImGuiDataType_S64 , & s64_v , & s64_zero , & s64_fifty , " % " PRId64 ) ;
ImGui : : SliderScalar ( " slider s64 high " , ImGuiDataType_S64 , & s64_v , & s64_hi_a , & s64_hi_b , " % " PRId64 ) ;
ImGui : : SliderScalar ( " slider s64 full " , ImGuiDataType_S64 , & s64_v , & s64_min , & s64_max , " % " PRId64 ) ;
ImGui : : SliderScalar ( " slider u64 low " , ImGuiDataType_U64 , & u64_v , & u64_zero , & u64_fifty , " % " PRIu64 " ms " ) ;
ImGui : : SliderScalar ( " slider u64 high " , ImGuiDataType_U64 , & u64_v , & u64_hi_a , & u64_hi_b , " % " PRIu64 " ms " ) ;
ImGui : : SliderScalar ( " slider u64 full " , ImGuiDataType_U64 , & u64_v , & u64_min , & u64_max , " % " PRIu64 " ms " ) ;
2020-07-22 18:00:50 +02:00
ImGui : : SliderScalar ( " slider float low " , ImGuiDataType_Float , & f32_v , & f32_zero , & f32_one ) ;
2020-08-18 17:02:58 +02:00
ImGui : : SliderScalar ( " slider float low log " , ImGuiDataType_Float , & f32_v , & f32_zero , & f32_one , " %.10f " , ImGuiSliderFlags_Logarithmic ) ;
2020-07-22 18:00:50 +02:00
ImGui : : SliderScalar ( " slider float high " , ImGuiDataType_Float , & f32_v , & f32_lo_a , & f32_hi_a , " %e " ) ;
ImGui : : SliderScalar ( " slider double low " , ImGuiDataType_Double , & f64_v , & f64_zero , & f64_one , " %.10f grams " ) ;
2020-08-18 17:02:58 +02:00
ImGui : : SliderScalar ( " slider double low log " , ImGuiDataType_Double , & f64_v , & f64_zero , & f64_one , " %.10f " , ImGuiSliderFlags_Logarithmic ) ;
2020-07-22 18:00:50 +02:00
ImGui : : SliderScalar ( " slider double high " , ImGuiDataType_Double , & f64_v , & f64_lo_a , & f64_hi_a , " %e grams " ) ;
2018-10-25 23:40:33 +02:00
2023-02-10 12:16:23 +01:00
ImGui : : SeparatorText ( " Sliders (reverse) " ) ;
2021-03-04 15:27:43 +01:00
ImGui : : SliderScalar ( " slider s8 reverse " , ImGuiDataType_S8 , & s8_v , & s8_max , & s8_min , " %d " ) ;
ImGui : : SliderScalar ( " slider u8 reverse " , ImGuiDataType_U8 , & u8_v , & u8_max , & u8_min , " %u " ) ;
2020-09-07 17:38:56 +02:00
ImGui : : SliderScalar ( " slider s32 reverse " , ImGuiDataType_S32 , & s32_v , & s32_fifty , & s32_zero , " %d " ) ;
ImGui : : SliderScalar ( " slider u32 reverse " , ImGuiDataType_U32 , & u32_v , & u32_fifty , & u32_zero , " %u " ) ;
2023-08-07 15:23:59 +02:00
ImGui : : SliderScalar ( " slider s64 reverse " , ImGuiDataType_S64 , & s64_v , & s64_fifty , & s64_zero , " % " PRId64 ) ;
ImGui : : SliderScalar ( " slider u64 reverse " , ImGuiDataType_U64 , & u64_v , & u64_fifty , & u64_zero , " % " PRIu64 " ms " ) ;
2020-09-07 17:38:56 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Data Types/Inputs " ) ;
2018-10-25 23:40:33 +02:00
static bool inputs_step = true ;
2024-06-06 16:39:25 +02:00
static ImGuiInputTextFlags flags = ImGuiInputTextFlags_None ;
2023-02-10 12:16:23 +01:00
ImGui : : SeparatorText ( " Inputs " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : Checkbox ( " Show step buttons " , & inputs_step ) ;
2024-06-06 16:39:25 +02:00
ImGui : : CheckboxFlags ( " ImGuiInputTextFlags_ReadOnly " , & flags , ImGuiInputTextFlags_ReadOnly ) ;
ImGui : : CheckboxFlags ( " ImGuiInputTextFlags_ParseEmptyRefVal " , & flags , ImGuiInputTextFlags_ParseEmptyRefVal ) ;
ImGui : : CheckboxFlags ( " ImGuiInputTextFlags_DisplayEmptyRefVal " , & flags , ImGuiInputTextFlags_DisplayEmptyRefVal ) ;
ImGui : : InputScalar ( " input s8 " , ImGuiDataType_S8 , & s8_v , inputs_step ? & s8_one : NULL , NULL , " %d " , flags ) ;
ImGui : : InputScalar ( " input u8 " , ImGuiDataType_U8 , & u8_v , inputs_step ? & u8_one : NULL , NULL , " %u " , flags ) ;
ImGui : : InputScalar ( " input s16 " , ImGuiDataType_S16 , & s16_v , inputs_step ? & s16_one : NULL , NULL , " %d " , flags ) ;
ImGui : : InputScalar ( " input u16 " , ImGuiDataType_U16 , & u16_v , inputs_step ? & u16_one : NULL , NULL , " %u " , flags ) ;
ImGui : : InputScalar ( " input s32 " , ImGuiDataType_S32 , & s32_v , inputs_step ? & s32_one : NULL , NULL , " %d " , flags ) ;
ImGui : : InputScalar ( " input s32 hex " , ImGuiDataType_S32 , & s32_v , inputs_step ? & s32_one : NULL , NULL , " %04X " , flags ) ;
ImGui : : InputScalar ( " input u32 " , ImGuiDataType_U32 , & u32_v , inputs_step ? & u32_one : NULL , NULL , " %u " , flags ) ;
ImGui : : InputScalar ( " input u32 hex " , ImGuiDataType_U32 , & u32_v , inputs_step ? & u32_one : NULL , NULL , " %08X " , flags ) ;
ImGui : : InputScalar ( " input s64 " , ImGuiDataType_S64 , & s64_v , inputs_step ? & s64_one : NULL , NULL , NULL , flags ) ;
ImGui : : InputScalar ( " input u64 " , ImGuiDataType_U64 , & u64_v , inputs_step ? & u64_one : NULL , NULL , NULL , flags ) ;
ImGui : : InputScalar ( " input float " , ImGuiDataType_Float , & f32_v , inputs_step ? & f32_one : NULL , NULL , NULL , flags ) ;
ImGui : : InputScalar ( " input double " , ImGuiDataType_Double , & f64_v , inputs_step ? & f64_one : NULL , NULL , NULL , flags ) ;
2018-10-25 23:40:33 +02:00
ImGui : : TreePop ( ) ;
}
2015-07-22 01:00:28 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Multi-component Widgets " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Multi-component Widgets " ) )
{
static float vec4f [ 4 ] = { 0.10f , 0.20f , 0.30f , 0.44f } ;
static int vec4i [ 4 ] = { 1 , 5 , 100 , 255 } ;
2023-02-10 12:16:23 +01:00
ImGui : : SeparatorText ( " 2-wide " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : InputFloat2 ( " input float2 " , vec4f ) ;
ImGui : : DragFloat2 ( " drag float2 " , vec4f , 0.01f , 0.0f , 1.0f ) ;
ImGui : : SliderFloat2 ( " slider float2 " , vec4f , 0.0f , 1.0f ) ;
ImGui : : InputInt2 ( " input int2 " , vec4i ) ;
ImGui : : DragInt2 ( " drag int2 " , vec4i , 1 , 0 , 255 ) ;
ImGui : : SliderInt2 ( " slider int2 " , vec4i , 0 , 255 ) ;
2023-02-10 12:16:23 +01:00
ImGui : : SeparatorText ( " 3-wide " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : InputFloat3 ( " input float3 " , vec4f ) ;
ImGui : : DragFloat3 ( " drag float3 " , vec4f , 0.01f , 0.0f , 1.0f ) ;
ImGui : : SliderFloat3 ( " slider float3 " , vec4f , 0.0f , 1.0f ) ;
ImGui : : InputInt3 ( " input int3 " , vec4i ) ;
ImGui : : DragInt3 ( " drag int3 " , vec4i , 1 , 0 , 255 ) ;
ImGui : : SliderInt3 ( " slider int3 " , vec4i , 0 , 255 ) ;
2023-02-10 12:16:23 +01:00
ImGui : : SeparatorText ( " 4-wide " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : InputFloat4 ( " input float4 " , vec4f ) ;
ImGui : : DragFloat4 ( " drag float4 " , vec4f , 0.01f , 0.0f , 1.0f ) ;
ImGui : : SliderFloat4 ( " slider float4 " , vec4f , 0.0f , 1.0f ) ;
ImGui : : InputInt4 ( " input int4 " , vec4i ) ;
ImGui : : DragInt4 ( " drag int4 " , vec4i , 1 , 0 , 255 ) ;
ImGui : : SliderInt4 ( " slider int4 " , vec4i , 0 , 255 ) ;
ImGui : : TreePop ( ) ;
}
2015-07-22 01:00:28 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Vertical Sliders " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Vertical Sliders " ) )
{
const float spacing = 4 ;
ImGui : : PushStyleVar ( ImGuiStyleVar_ItemSpacing , ImVec2 ( spacing , spacing ) ) ;
2015-07-22 01:00:28 +02:00
2018-10-25 23:40:33 +02:00
static int int_value = 0 ;
2020-06-30 15:31:54 +02:00
ImGui : : VSliderInt ( " ##int " , ImVec2 ( 18 , 160 ) , & int_value , 0 , 5 ) ;
2018-10-25 23:40:33 +02:00
ImGui : : SameLine ( ) ;
2015-07-22 01:00:28 +02:00
2018-10-25 23:40:33 +02:00
static float values [ 7 ] = { 0.0f , 0.60f , 0.35f , 0.9f , 0.70f , 0.20f , 0.0f } ;
ImGui : : PushID ( " set1 " ) ;
for ( int i = 0 ; i < 7 ; i + + )
{
if ( i > 0 ) ImGui : : SameLine ( ) ;
ImGui : : PushID ( i ) ;
2020-06-30 15:31:54 +02:00
ImGui : : PushStyleColor ( ImGuiCol_FrameBg , ( ImVec4 ) ImColor : : HSV ( i / 7.0f , 0.5f , 0.5f ) ) ;
ImGui : : PushStyleColor ( ImGuiCol_FrameBgHovered , ( ImVec4 ) ImColor : : HSV ( i / 7.0f , 0.6f , 0.5f ) ) ;
ImGui : : PushStyleColor ( ImGuiCol_FrameBgActive , ( ImVec4 ) ImColor : : HSV ( i / 7.0f , 0.7f , 0.5f ) ) ;
ImGui : : PushStyleColor ( ImGuiCol_SliderGrab , ( ImVec4 ) ImColor : : HSV ( i / 7.0f , 0.9f , 0.9f ) ) ;
ImGui : : VSliderFloat ( " ##v " , ImVec2 ( 18 , 160 ) , & values [ i ] , 0.0f , 1.0f , " " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : IsItemActive ( ) | | ImGui : : IsItemHovered ( ) )
ImGui : : SetTooltip ( " %.3f " , values [ i ] ) ;
ImGui : : PopStyleColor ( 4 ) ;
ImGui : : PopID ( ) ;
2015-07-22 01:00:28 +02:00
}
2018-10-25 23:40:33 +02:00
ImGui : : PopID ( ) ;
2015-07-22 01:00:28 +02:00
2018-10-25 23:40:33 +02:00
ImGui : : SameLine ( ) ;
ImGui : : PushID ( " set2 " ) ;
static float values2 [ 4 ] = { 0.20f , 0.80f , 0.40f , 0.25f } ;
const int rows = 3 ;
2019-09-16 19:03:20 +02:00
const ImVec2 small_slider_size ( 18 , ( float ) ( int ) ( ( 160.0f - ( rows - 1 ) * spacing ) / rows ) ) ;
2018-10-25 23:40:33 +02:00
for ( int nx = 0 ; nx < 4 ; nx + + )
2015-07-22 01:00:28 +02:00
{
2018-10-25 23:40:33 +02:00
if ( nx > 0 ) ImGui : : SameLine ( ) ;
ImGui : : BeginGroup ( ) ;
for ( int ny = 0 ; ny < rows ; ny + + )
2015-07-22 01:00:28 +02:00
{
2020-06-30 15:31:54 +02:00
ImGui : : PushID ( nx * rows + ny ) ;
2018-10-25 23:40:33 +02:00
ImGui : : VSliderFloat ( " ##v " , small_slider_size , & values2 [ nx ] , 0.0f , 1.0f , " " ) ;
2015-07-22 01:00:28 +02:00
if ( ImGui : : IsItemActive ( ) | | ImGui : : IsItemHovered ( ) )
2018-10-25 23:40:33 +02:00
ImGui : : SetTooltip ( " %.3f " , values2 [ nx ] ) ;
2015-07-22 01:00:28 +02:00
ImGui : : PopID ( ) ;
}
2018-10-25 23:40:33 +02:00
ImGui : : EndGroup ( ) ;
}
ImGui : : PopID ( ) ;
2015-07-22 01:00:28 +02:00
2018-10-25 23:40:33 +02:00
ImGui : : SameLine ( ) ;
ImGui : : PushID ( " set3 " ) ;
for ( int i = 0 ; i < 4 ; i + + )
{
if ( i > 0 ) ImGui : : SameLine ( ) ;
ImGui : : PushID ( i ) ;
ImGui : : PushStyleVar ( ImGuiStyleVar_GrabMinSize , 40 ) ;
2020-06-30 15:31:54 +02:00
ImGui : : VSliderFloat ( " ##v " , ImVec2 ( 40 , 160 ) , & values [ i ] , 0.0f , 1.0f , " %.2f \n sec " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : PopStyleVar ( ) ;
2015-07-22 01:00:28 +02:00
ImGui : : PopID ( ) ;
2018-10-25 23:40:33 +02:00
}
ImGui : : PopID ( ) ;
ImGui : : PopStyleVar ( ) ;
ImGui : : TreePop ( ) ;
}
2015-07-22 01:00:28 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Drag and drop " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Drag and Drop " ) )
{
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Drag and drop/Standard widgets " ) ;
2019-10-07 17:52:31 +02:00
if ( ImGui : : TreeNode ( " Drag and drop in standard widgets " ) )
2018-10-25 23:40:33 +02:00
{
// ColorEdit widgets automatically act as drag source and drag target.
2020-05-05 19:39:24 +02:00
// They are using standardized payload strings IMGUI_PAYLOAD_TYPE_COLOR_3F and IMGUI_PAYLOAD_TYPE_COLOR_4F
// to allow your own widgets to use colors in their drag and drop interaction.
// Also see 'Demo->Widgets->Color/Picker Widgets->Palette' demo.
2020-10-15 20:05:35 +02:00
HelpMarker ( " You can drag from the color squares. " ) ;
2019-10-07 17:52:31 +02:00
static float col1 [ 3 ] = { 1.0f , 0.0f , 0.2f } ;
static float col2 [ 4 ] = { 0.4f , 0.7f , 0.0f , 0.5f } ;
2018-10-25 23:40:33 +02:00
ImGui : : ColorEdit3 ( " color 1 " , col1 ) ;
ImGui : : ColorEdit4 ( " color 2 " , col2 ) ;
2019-10-07 17:52:31 +02:00
ImGui : : TreePop ( ) ;
2015-07-22 01:00:28 +02:00
}
2018-06-12 18:51:23 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Drag and drop/Copy-swap items " ) ;
2019-10-07 17:52:31 +02:00
if ( ImGui : : TreeNode ( " Drag and drop to copy/swap items " ) )
2018-07-08 19:55:57 +02:00
{
2018-10-25 23:40:33 +02:00
enum Mode
2018-07-08 19:55:57 +02:00
{
2018-10-25 23:40:33 +02:00
Mode_Copy ,
Mode_Move ,
Mode_Swap
} ;
static int mode = 0 ;
if ( ImGui : : RadioButton ( " Copy " , mode = = Mode_Copy ) ) { mode = Mode_Copy ; } ImGui : : SameLine ( ) ;
if ( ImGui : : RadioButton ( " Move " , mode = = Mode_Move ) ) { mode = Mode_Move ; } ImGui : : SameLine ( ) ;
2019-01-20 17:56:17 +01:00
if ( ImGui : : RadioButton ( " Swap " , mode = = Mode_Swap ) ) { mode = Mode_Swap ; }
2020-08-24 14:13:18 +02:00
static const char * names [ 9 ] =
2020-05-05 19:39:24 +02:00
{
" Bobby " , " Beatrice " , " Betty " ,
" Brianna " , " Barry " , " Bernard " ,
" Bibi " , " Blaine " , " Bryn "
} ;
2018-10-25 23:40:33 +02:00
for ( int n = 0 ; n < IM_ARRAYSIZE ( names ) ; n + + )
2018-07-08 19:55:57 +02:00
{
2018-10-25 23:40:33 +02:00
ImGui : : PushID ( n ) ;
if ( ( n % 3 ) ! = 0 )
ImGui : : SameLine ( ) ;
2020-06-30 15:31:54 +02:00
ImGui : : Button ( names [ n ] , ImVec2 ( 60 , 60 ) ) ;
2018-10-25 23:40:33 +02:00
// Our buttons are both drag sources and drag targets here!
if ( ImGui : : BeginDragDropSource ( ImGuiDragDropFlags_None ) )
2018-07-08 19:55:57 +02:00
{
2020-05-05 19:39:24 +02:00
// Set payload to carry the index of our item (could be anything)
ImGui : : SetDragDropPayload ( " DND_DEMO_CELL " , & n , sizeof ( int ) ) ;
// Display preview (could be anything, e.g. when dragging an image we could decide to display
// the filename and a small preview of the image, etc.)
if ( mode = = Mode_Copy ) { ImGui : : Text ( " Copy %s " , names [ n ] ) ; }
2018-10-25 23:40:33 +02:00
if ( mode = = Mode_Move ) { ImGui : : Text ( " Move %s " , names [ n ] ) ; }
if ( mode = = Mode_Swap ) { ImGui : : Text ( " Swap %s " , names [ n ] ) ; }
ImGui : : EndDragDropSource ( ) ;
}
if ( ImGui : : BeginDragDropTarget ( ) )
2018-07-08 19:55:57 +02:00
{
2018-10-25 23:40:33 +02:00
if ( const ImGuiPayload * payload = ImGui : : AcceptDragDropPayload ( " DND_DEMO_CELL " ) )
2018-07-08 19:55:57 +02:00
{
2018-10-25 23:40:33 +02:00
IM_ASSERT ( payload - > DataSize = = sizeof ( int ) ) ;
int payload_n = * ( const int * ) payload - > Data ;
if ( mode = = Mode_Copy )
{
names [ n ] = names [ payload_n ] ;
}
if ( mode = = Mode_Move )
2018-07-08 19:55:57 +02:00
{
2018-10-25 23:40:33 +02:00
names [ n ] = names [ payload_n ] ;
names [ payload_n ] = " " ;
}
if ( mode = = Mode_Swap )
{
const char * tmp = names [ n ] ;
names [ n ] = names [ payload_n ] ;
names [ payload_n ] = tmp ;
2018-07-08 19:55:57 +02:00
}
}
2018-10-25 23:40:33 +02:00
ImGui : : EndDragDropTarget ( ) ;
2018-07-08 19:55:57 +02:00
}
2018-10-25 23:40:33 +02:00
ImGui : : PopID ( ) ;
2018-07-08 19:55:57 +02:00
}
2019-10-07 17:52:31 +02:00
ImGui : : TreePop ( ) ;
}
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Drag and Drop/Drag to reorder items (simple) " ) ;
2019-10-07 17:52:31 +02:00
if ( ImGui : : TreeNode ( " Drag to reorder items (simple) " ) )
{
Added io.ConfigDebugHighlightIdConflicts debug feature! (#7961, #7669)
Also #74, #96, #480, #501, #647, #654, #719, #843, #894, #1057, #1173, #1390, #1414, #1556, #1768, #2041, #2116, #2330, #2475, #2562, #2667, #2807, #2885, #3102, #3375, #3526, #3964, #4008, #4070, #4158, #4172, #4199, #4375, #4395, #4471, #4548, #4612, #4631, #4657, #4796, #5210, #5303, #5360, #5393, #5533, #5692, #5707, #5729, #5773, #5787, #5884, #6046, #6093, #6186, #6223, #6364, #6387, #6567, #6692, #6724, #6939, #6984, #7246, #7270, #7375, #7421, #7434, #7472, #7581, #7724, #7926, #7937 and probably more.. Tagging to increase visibility!
2024-09-10 15:28:40 +02:00
// FIXME: there is temporary (usually single-frame) ID Conflict during reordering as a same item may be submitting twice.
// This code was always slightly faulty but in a way which was not easily noticeable.
// Until we fix this, enable ImGuiItemFlags_AllowDuplicateId to disable detecting the issue.
ImGui : : PushItemFlag ( ImGuiItemFlags_AllowDuplicateId , true ) ;
2024-09-09 21:07:10 +02:00
2019-10-07 17:52:31 +02:00
// Simple reordering
2020-05-05 19:39:24 +02:00
HelpMarker (
" We don't use the drag and drop api at all here! "
" Instead we query when the item is held but not hovered, and order items accordingly. " ) ;
2019-10-07 17:52:31 +02:00
static const char * item_names [ ] = { " Item One " , " Item Two " , " Item Three " , " Item Four " , " Item Five " } ;
for ( int n = 0 ; n < IM_ARRAYSIZE ( item_names ) ; n + + )
{
const char * item = item_names [ n ] ;
ImGui : : Selectable ( item ) ;
if ( ImGui : : IsItemActive ( ) & & ! ImGui : : IsItemHovered ( ) )
{
int n_next = n + ( ImGui : : GetMouseDragDelta ( 0 ) . y < 0.f ? - 1 : 1 ) ;
if ( n_next > = 0 & & n_next < IM_ARRAYSIZE ( item_names ) )
{
item_names [ n ] = item_names [ n_next ] ;
item_names [ n_next ] = item ;
ImGui : : ResetMouseDragDelta ( ) ;
}
}
}
Added io.ConfigDebugHighlightIdConflicts debug feature! (#7961, #7669)
Also #74, #96, #480, #501, #647, #654, #719, #843, #894, #1057, #1173, #1390, #1414, #1556, #1768, #2041, #2116, #2330, #2475, #2562, #2667, #2807, #2885, #3102, #3375, #3526, #3964, #4008, #4070, #4158, #4172, #4199, #4375, #4395, #4471, #4548, #4612, #4631, #4657, #4796, #5210, #5303, #5360, #5393, #5533, #5692, #5707, #5729, #5773, #5787, #5884, #6046, #6093, #6186, #6223, #6364, #6387, #6567, #6692, #6724, #6939, #6984, #7246, #7270, #7375, #7421, #7434, #7472, #7581, #7724, #7926, #7937 and probably more.. Tagging to increase visibility!
2024-09-10 15:28:40 +02:00
ImGui : : PopItemFlag ( ) ;
2019-10-07 17:52:31 +02:00
ImGui : : TreePop ( ) ;
2018-07-08 19:55:57 +02:00
}
2023-10-05 12:06:40 +02:00
IMGUI_DEMO_MARKER ( " Widgets/Drag and Drop/Tooltip at target location " ) ;
if ( ImGui : : TreeNode ( " Tooltip at target location " ) )
{
for ( int n = 0 ; n < 2 ; n + + )
{
// Drop targets
ImGui : : Button ( n ? " drop here##1 " : " drop here##0 " ) ;
if ( ImGui : : BeginDragDropTarget ( ) )
{
ImGuiDragDropFlags drop_target_flags = ImGuiDragDropFlags_AcceptBeforeDelivery | ImGuiDragDropFlags_AcceptNoPreviewTooltip ;
if ( const ImGuiPayload * payload = ImGui : : AcceptDragDropPayload ( IMGUI_PAYLOAD_TYPE_COLOR_4F , drop_target_flags ) )
{
2023-10-05 14:13:27 +02:00
IM_UNUSED ( payload ) ;
2023-10-05 12:06:40 +02:00
ImGui : : SetMouseCursor ( ImGuiMouseCursor_NotAllowed ) ;
2024-03-18 07:29:10 +01:00
ImGui : : SetTooltip ( " Cannot drop here! " ) ;
2023-10-05 12:06:40 +02:00
}
ImGui : : EndDragDropTarget ( ) ;
}
// Drop source
static ImVec4 col4 = { 1.0f , 0.0f , 0.2f , 1.0f } ;
if ( n = = 0 )
ImGui : : ColorButton ( " drag me " , col4 ) ;
}
ImGui : : TreePop ( ) ;
}
2018-10-25 23:40:33 +02:00
ImGui : : TreePop ( ) ;
}
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Querying Item Status (Edited,Active,Hovered etc.) " ) ;
2021-09-24 14:51:14 +02:00
if ( ImGui : : TreeNode ( " Querying Item Status (Edited/Active/Hovered etc.) " ) )
2018-10-25 23:40:33 +02:00
{
2020-05-05 19:39:24 +02:00
// Select an item type
const char * item_names [ ] =
{
2021-11-30 15:17:18 +01:00
" Text " , " Button " , " Button (w/ repeat) " , " Checkbox " , " SliderFloat " , " InputText " , " InputTextMultiline " , " InputFloat " ,
2021-07-09 19:04:41 +02:00
" InputFloat3 " , " ColorEdit4 " , " Selectable " , " MenuItem " , " TreeNode " , " TreeNode (w/ double-click) " , " Combo " , " ListBox "
2020-05-05 19:39:24 +02:00
} ;
2021-07-19 19:21:18 +02:00
static int item_type = 4 ;
static bool item_disabled = false ;
2020-05-05 19:39:24 +02:00
ImGui : : Combo ( " Item Type " , & item_type , item_names , IM_ARRAYSIZE ( item_names ) , IM_ARRAYSIZE ( item_names ) ) ;
2019-07-18 00:11:52 +02:00
ImGui : : SameLine ( ) ;
2021-01-04 19:12:35 +01:00
HelpMarker ( " Testing how various types of items are interacting with the IsItemXXX functions. Note that the bool return value of most ImGui function is generally equivalent to calling ImGui::IsItemHovered(). " ) ;
2021-07-19 19:21:18 +02:00
ImGui : : Checkbox ( " Item Disabled " , & item_disabled ) ;
2020-05-05 19:39:24 +02:00
2022-09-11 07:35:59 +02:00
// Submit selected items so we can query their status in the code following it.
2018-10-25 23:40:33 +02:00
bool ret = false ;
2019-09-23 15:31:05 +02:00
static bool b = false ;
static float col4f [ 4 ] = { 1.0f , 0.5 , 0.0f , 1.0f } ;
static char str [ 16 ] = { } ;
2021-07-19 19:21:18 +02:00
if ( item_disabled )
ImGui : : BeginDisabled ( true ) ;
2018-10-25 23:40:33 +02:00
if ( item_type = = 0 ) { ImGui : : Text ( " ITEM: Text " ) ; } // Testing text items with no identifier/interaction
if ( item_type = = 1 ) { ret = ImGui : : Button ( " ITEM: Button " ) ; } // Testing button
2024-07-15 17:46:32 +02:00
if ( item_type = = 2 ) { ImGui : : PushItemFlag ( ImGuiItemFlags_ButtonRepeat , true ) ; ret = ImGui : : Button ( " ITEM: Button " ) ; ImGui : : PopItemFlag ( ) ; } // Testing button (with repeater)
2019-07-18 00:11:52 +02:00
if ( item_type = = 3 ) { ret = ImGui : : Checkbox ( " ITEM: Checkbox " , & b ) ; } // Testing checkbox
if ( item_type = = 4 ) { ret = ImGui : : SliderFloat ( " ITEM: SliderFloat " , & col4f [ 0 ] , 0.0f , 1.0f ) ; } // Testing basic item
if ( item_type = = 5 ) { ret = ImGui : : InputText ( " ITEM: InputText " , & str [ 0 ] , IM_ARRAYSIZE ( str ) ) ; } // Testing input text (which handles tabbing)
2021-11-30 15:17:18 +01:00
if ( item_type = = 6 ) { ret = ImGui : : InputTextMultiline ( " ITEM: InputTextMultiline " , & str [ 0 ] , IM_ARRAYSIZE ( str ) ) ; } // Testing input text (which uses a child window)
if ( item_type = = 7 ) { ret = ImGui : : InputFloat ( " ITEM: InputFloat " , col4f , 1.0f ) ; } // Testing +/- buttons on scalar input
if ( item_type = = 8 ) { ret = ImGui : : InputFloat3 ( " ITEM: InputFloat3 " , col4f ) ; } // Testing multi-component items (IsItemXXX flags are reported merged)
if ( item_type = = 9 ) { ret = ImGui : : ColorEdit4 ( " ITEM: ColorEdit4 " , col4f ) ; } // Testing multi-component items (IsItemXXX flags are reported merged)
if ( item_type = = 10 ) { ret = ImGui : : Selectable ( " ITEM: Selectable " ) ; } // Testing selectable item
if ( item_type = = 11 ) { ret = ImGui : : MenuItem ( " ITEM: MenuItem " ) ; } // Testing menu item (they use ImGuiButtonFlags_PressedOnRelease button policy)
if ( item_type = = 12 ) { ret = ImGui : : TreeNode ( " ITEM: TreeNode " ) ; if ( ret ) ImGui : : TreePop ( ) ; } // Testing tree node
if ( item_type = = 13 ) { ret = ImGui : : TreeNodeEx ( " ITEM: TreeNode w/ ImGuiTreeNodeFlags_OpenOnDoubleClick " , ImGuiTreeNodeFlags_OpenOnDoubleClick | ImGuiTreeNodeFlags_NoTreePushOnOpen ) ; } // Testing tree node with ImGuiButtonFlags_PressedOnDoubleClick button policy.
if ( item_type = = 14 ) { const char * items [ ] = { " Apple " , " Banana " , " Cherry " , " Kiwi " } ; static int current = 1 ; ret = ImGui : : Combo ( " ITEM: Combo " , & current , items , IM_ARRAYSIZE ( items ) ) ; }
if ( item_type = = 15 ) { const char * items [ ] = { " Apple " , " Banana " , " Cherry " , " Kiwi " } ; static int current = 1 ; ret = ImGui : : ListBox ( " ITEM: ListBox " , & current , items , IM_ARRAYSIZE ( items ) , IM_ARRAYSIZE ( items ) ) ; }
2019-09-23 15:31:05 +02:00
2021-11-10 21:02:19 +01:00
bool hovered_delay_none = ImGui : : IsItemHovered ( ) ;
2023-06-15 15:51:00 +02:00
bool hovered_delay_stationary = ImGui : : IsItemHovered ( ImGuiHoveredFlags_Stationary ) ;
2021-11-10 21:02:19 +01:00
bool hovered_delay_short = ImGui : : IsItemHovered ( ImGuiHoveredFlags_DelayShort ) ;
bool hovered_delay_normal = ImGui : : IsItemHovered ( ImGuiHoveredFlags_DelayNormal ) ;
2023-06-15 15:51:00 +02:00
bool hovered_delay_tooltip = ImGui : : IsItemHovered ( ImGuiHoveredFlags_ForTooltip ) ; // = Normal + Stationary
2021-11-10 21:02:19 +01:00
2020-05-05 19:39:24 +02:00
// Display the values of IsItemHovered() and other common item state functions.
2019-09-23 15:31:05 +02:00
// Note that the ImGuiHoveredFlags_XXX flags can be combined.
2019-10-07 17:52:31 +02:00
// Because BulletText is an item itself and that would affect the output of IsItemXXX functions,
2020-05-05 19:39:24 +02:00
// we query every state in a single call to avoid storing them and to simplify the code.
2018-10-25 23:40:33 +02:00
ImGui : : BulletText (
" Return value = %d \n "
" IsItemFocused() = %d \n "
" IsItemHovered() = %d \n "
" IsItemHovered(_AllowWhenBlockedByPopup) = %d \n "
" IsItemHovered(_AllowWhenBlockedByActiveItem) = %d \n "
2023-06-27 14:58:40 +02:00
" IsItemHovered(_AllowWhenOverlappedByItem) = %d \n "
" IsItemHovered(_AllowWhenOverlappedByWindow) = %d \n "
2021-07-19 19:21:18 +02:00
" IsItemHovered(_AllowWhenDisabled) = %d \n "
2018-10-25 23:40:33 +02:00
" IsItemHovered(_RectOnly) = %d \n "
" IsItemActive() = %d \n "
" IsItemEdited() = %d \n "
2019-02-06 11:52:42 +01:00
" IsItemActivated() = %d \n "
2018-10-25 23:40:33 +02:00
" IsItemDeactivated() = %d \n "
2019-04-01 17:32:14 +02:00
" IsItemDeactivatedAfterEdit() = %d \n "
2018-10-25 23:40:33 +02:00
" IsItemVisible() = %d \n "
2019-04-12 17:43:50 +02:00
" IsItemClicked() = %d \n "
2019-11-08 15:23:34 +01:00
" IsItemToggledOpen() = %d \n "
2018-10-25 23:40:33 +02:00
" GetItemRectMin() = (%.1f, %.1f) \n "
" GetItemRectMax() = (%.1f, %.1f) \n "
" GetItemRectSize() = (%.1f, %.1f) " ,
ret ,
ImGui : : IsItemFocused ( ) ,
ImGui : : IsItemHovered ( ) ,
ImGui : : IsItemHovered ( ImGuiHoveredFlags_AllowWhenBlockedByPopup ) ,
ImGui : : IsItemHovered ( ImGuiHoveredFlags_AllowWhenBlockedByActiveItem ) ,
2023-06-27 14:58:40 +02:00
ImGui : : IsItemHovered ( ImGuiHoveredFlags_AllowWhenOverlappedByItem ) ,
ImGui : : IsItemHovered ( ImGuiHoveredFlags_AllowWhenOverlappedByWindow ) ,
2021-07-19 19:21:18 +02:00
ImGui : : IsItemHovered ( ImGuiHoveredFlags_AllowWhenDisabled ) ,
2018-10-25 23:40:33 +02:00
ImGui : : IsItemHovered ( ImGuiHoveredFlags_RectOnly ) ,
ImGui : : IsItemActive ( ) ,
ImGui : : IsItemEdited ( ) ,
2019-02-06 11:52:42 +01:00
ImGui : : IsItemActivated ( ) ,
2018-10-25 23:40:33 +02:00
ImGui : : IsItemDeactivated ( ) ,
ImGui : : IsItemDeactivatedAfterEdit ( ) ,
ImGui : : IsItemVisible ( ) ,
2019-04-12 17:43:50 +02:00
ImGui : : IsItemClicked ( ) ,
2019-11-08 15:23:34 +01:00
ImGui : : IsItemToggledOpen ( ) ,
2018-10-25 23:40:33 +02:00
ImGui : : GetItemRectMin ( ) . x , ImGui : : GetItemRectMin ( ) . y ,
ImGui : : GetItemRectMax ( ) . x , ImGui : : GetItemRectMax ( ) . y ,
ImGui : : GetItemRectSize ( ) . x , ImGui : : GetItemRectSize ( ) . y
) ;
2021-11-10 21:02:19 +01:00
ImGui : : BulletText (
2023-06-15 15:51:00 +02:00
" with Hovering Delay or Stationary test: \n "
" IsItemHovered() = = %d \n "
" IsItemHovered(_Stationary) = %d \n "
" IsItemHovered(_DelayShort) = %d \n "
" IsItemHovered(_DelayNormal) = %d \n "
" IsItemHovered(_Tooltip) = %d " ,
hovered_delay_none , hovered_delay_stationary , hovered_delay_short , hovered_delay_normal , hovered_delay_tooltip ) ;
2018-10-25 23:40:33 +02:00
2021-07-19 19:21:18 +02:00
if ( item_disabled )
ImGui : : EndDisabled ( ) ;
2021-09-24 14:51:14 +02:00
char buf [ 1 ] = " " ;
ImGui : : InputText ( " unused " , buf , IM_ARRAYSIZE ( buf ) , ImGuiInputTextFlags_ReadOnly ) ;
ImGui : : SameLine ( ) ;
HelpMarker ( " This widget is only here to be able to tab-out of the widgets above and see e.g. Deactivated() status. " ) ;
ImGui : : TreePop ( ) ;
}
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Querying Window Status (Focused,Hovered etc.) " ) ;
2021-09-24 14:51:14 +02:00
if ( ImGui : : TreeNode ( " Querying Window Status (Focused/Hovered etc.) " ) )
{
2018-10-25 23:40:33 +02:00
static bool embed_all_inside_a_child_window = false ;
2021-09-24 14:51:14 +02:00
ImGui : : Checkbox ( " Embed everything inside a child window for testing _RootWindow flag. " , & embed_all_inside_a_child_window ) ;
2018-10-25 23:40:33 +02:00
if ( embed_all_inside_a_child_window )
2024-08-23 15:24:22 +02:00
ImGui : : BeginChild ( " outer_child " , ImVec2 ( 0 , ImGui : : GetFontSize ( ) * 20.0f ) , ImGuiChildFlags_Borders ) ;
2018-10-25 23:40:33 +02:00
2019-10-07 17:52:31 +02:00
// Testing IsWindowFocused() function with its various flags.
2018-10-25 23:40:33 +02:00
ImGui : : BulletText (
" IsWindowFocused() = %d \n "
" IsWindowFocused(_ChildWindows) = %d \n "
2021-09-24 14:51:14 +02:00
" IsWindowFocused(_ChildWindows|_NoPopupHierarchy) = %d \n "
2018-10-25 23:40:33 +02:00
" IsWindowFocused(_ChildWindows|_RootWindow) = %d \n "
2021-09-24 14:51:14 +02:00
" IsWindowFocused(_ChildWindows|_RootWindow|_NoPopupHierarchy) = %d \n "
2018-10-25 23:40:33 +02:00
" IsWindowFocused(_RootWindow) = %d \n "
2021-09-24 14:51:14 +02:00
" IsWindowFocused(_RootWindow|_NoPopupHierarchy) = %d \n "
2018-10-25 23:40:33 +02:00
" IsWindowFocused(_AnyWindow) = %d \n " ,
ImGui : : IsWindowFocused ( ) ,
ImGui : : IsWindowFocused ( ImGuiFocusedFlags_ChildWindows ) ,
2021-09-24 14:51:14 +02:00
ImGui : : IsWindowFocused ( ImGuiFocusedFlags_ChildWindows | ImGuiFocusedFlags_NoPopupHierarchy ) ,
2018-10-25 23:40:33 +02:00
ImGui : : IsWindowFocused ( ImGuiFocusedFlags_ChildWindows | ImGuiFocusedFlags_RootWindow ) ,
2021-09-24 14:51:14 +02:00
ImGui : : IsWindowFocused ( ImGuiFocusedFlags_ChildWindows | ImGuiFocusedFlags_RootWindow | ImGuiFocusedFlags_NoPopupHierarchy ) ,
2018-10-25 23:40:33 +02:00
ImGui : : IsWindowFocused ( ImGuiFocusedFlags_RootWindow ) ,
2021-09-24 14:51:14 +02:00
ImGui : : IsWindowFocused ( ImGuiFocusedFlags_RootWindow | ImGuiFocusedFlags_NoPopupHierarchy ) ,
2018-10-25 23:40:33 +02:00
ImGui : : IsWindowFocused ( ImGuiFocusedFlags_AnyWindow ) ) ;
2019-09-23 15:31:05 +02:00
// Testing IsWindowHovered() function with its various flags.
2018-10-25 23:40:33 +02:00
ImGui : : BulletText (
" IsWindowHovered() = %d \n "
" IsWindowHovered(_AllowWhenBlockedByPopup) = %d \n "
" IsWindowHovered(_AllowWhenBlockedByActiveItem) = %d \n "
" IsWindowHovered(_ChildWindows) = %d \n "
2021-09-24 14:51:14 +02:00
" IsWindowHovered(_ChildWindows|_NoPopupHierarchy) = %d \n "
2018-10-25 23:40:33 +02:00
" IsWindowHovered(_ChildWindows|_RootWindow) = %d \n "
2021-09-24 14:51:14 +02:00
" IsWindowHovered(_ChildWindows|_RootWindow|_NoPopupHierarchy) = %d \n "
2018-10-25 23:40:33 +02:00
" IsWindowHovered(_RootWindow) = %d \n "
2021-09-24 14:51:14 +02:00
" IsWindowHovered(_RootWindow|_NoPopupHierarchy) = %d \n "
" IsWindowHovered(_ChildWindows|_AllowWhenBlockedByPopup) = %d \n "
2023-06-19 13:41:52 +02:00
" IsWindowHovered(_AnyWindow) = %d \n "
" IsWindowHovered(_Stationary) = %d \n " ,
2018-10-25 23:40:33 +02:00
ImGui : : IsWindowHovered ( ) ,
ImGui : : IsWindowHovered ( ImGuiHoveredFlags_AllowWhenBlockedByPopup ) ,
ImGui : : IsWindowHovered ( ImGuiHoveredFlags_AllowWhenBlockedByActiveItem ) ,
ImGui : : IsWindowHovered ( ImGuiHoveredFlags_ChildWindows ) ,
2021-09-24 14:51:14 +02:00
ImGui : : IsWindowHovered ( ImGuiHoveredFlags_ChildWindows | ImGuiHoveredFlags_NoPopupHierarchy ) ,
2018-10-25 23:40:33 +02:00
ImGui : : IsWindowHovered ( ImGuiHoveredFlags_ChildWindows | ImGuiHoveredFlags_RootWindow ) ,
2021-09-24 14:51:14 +02:00
ImGui : : IsWindowHovered ( ImGuiHoveredFlags_ChildWindows | ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_NoPopupHierarchy ) ,
2018-10-25 23:40:33 +02:00
ImGui : : IsWindowHovered ( ImGuiHoveredFlags_RootWindow ) ,
2021-09-24 14:51:14 +02:00
ImGui : : IsWindowHovered ( ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_NoPopupHierarchy ) ,
ImGui : : IsWindowHovered ( ImGuiHoveredFlags_ChildWindows | ImGuiHoveredFlags_AllowWhenBlockedByPopup ) ,
2023-06-19 13:41:52 +02:00
ImGui : : IsWindowHovered ( ImGuiHoveredFlags_AnyWindow ) ,
ImGui : : IsWindowHovered ( ImGuiHoveredFlags_Stationary ) ) ;
2018-10-25 23:40:33 +02:00
2024-08-23 15:24:22 +02:00
ImGui : : BeginChild ( " child " , ImVec2 ( 0 , 50 ) , ImGuiChildFlags_Borders ) ;
2018-12-19 15:19:31 +01:00
ImGui : : Text ( " This is another child window for testing the _ChildWindows flag. " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : EndChild ( ) ;
if ( embed_all_inside_a_child_window )
2018-06-12 18:51:23 +02:00
ImGui : : EndChild ( ) ;
2018-10-25 23:40:33 +02:00
2019-01-20 17:56:17 +01:00
// Calling IsItemHovered() after begin returns the hovered status of the title bar.
2020-05-05 19:39:24 +02:00
// This is useful in particular if you want to create a context menu associated to the title bar of a window.
2018-10-25 23:40:33 +02:00
static bool test_window = false ;
ImGui : : Checkbox ( " Hovered/Active tests after Begin() for title bar testing " , & test_window ) ;
if ( test_window )
{
ImGui : : Begin ( " Title bar Hovered/Active tests " , & test_window ) ;
if ( ImGui : : BeginPopupContextItem ( ) ) // <-- This is using IsItemHovered()
2018-07-17 11:33:31 +02:00
{
2018-10-25 23:40:33 +02:00
if ( ImGui : : MenuItem ( " Close " ) ) { test_window = false ; }
ImGui : : EndPopup ( ) ;
2018-07-17 11:33:31 +02:00
}
2018-10-25 23:40:33 +02:00
ImGui : : Text (
" IsItemHovered() after begin = %d (== is title bar hovered) \n "
" IsItemActive() after begin = %d (== is window being clicked/moved) \n " ,
ImGui : : IsItemHovered ( ) , ImGui : : IsItemActive ( ) ) ;
ImGui : : End ( ) ;
2018-06-12 18:51:23 +02:00
}
2018-10-25 23:40:33 +02:00
ImGui : : TreePop ( ) ;
2015-07-22 01:00:28 +02:00
}
2021-07-19 19:21:18 +02:00
// Demonstrate BeginDisabled/EndDisabled using a checkbox located at the bottom of the section (which is a bit odd:
// logically we'd have this checkbox at the top of the section, but we don't want this feature to steal that space)
if ( disable_all )
ImGui : : EndDisabled ( ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Disable Block " ) ;
2021-07-19 19:21:18 +02:00
if ( ImGui : : TreeNode ( " Disable block " ) )
{
ImGui : : Checkbox ( " Disable entire section above " , & disable_all ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Demonstrate using BeginDisabled()/EndDisabled() across this section. " ) ;
ImGui : : TreePop ( ) ;
}
2022-09-14 20:13:15 +02:00
IMGUI_DEMO_MARKER ( " Widgets/Text Filter " ) ;
if ( ImGui : : TreeNode ( " Text Filter " ) )
{
// Helper class to easy setup a text filter.
// You may want to implement a more feature-full filtering scheme in your own application.
HelpMarker ( " Not a widget per-se, but ImGuiTextFilter is a helper to perform simple filtering on text strings. " ) ;
static ImGuiTextFilter filter ;
ImGui : : Text ( " Filter usage: \n "
" \" \" display all lines \n "
" \" xxx \" display lines containing \" xxx \" \n "
" \" xxx,yyy \" display lines containing \" xxx \" or \" yyy \" \n "
" \" -xxx \" hide lines containing \" xxx \" " ) ;
filter . Draw ( ) ;
const char * lines [ ] = { " aaa1.c " , " bbb1.c " , " ccc1.c " , " aaa2.cpp " , " bbb2.cpp " , " ccc2.cpp " , " abc.h " , " hello, world " } ;
for ( int i = 0 ; i < IM_ARRAYSIZE ( lines ) ; i + + )
if ( filter . PassFilter ( lines [ i ] ) )
ImGui : : BulletText ( " %s " , lines [ i ] ) ;
ImGui : : TreePop ( ) ;
}
2018-10-25 23:34:05 +02:00
}
2015-07-22 01:00:28 +02:00
2023-08-23 15:53:50 +02:00
static const char * ExampleNames [ ] =
{
" Artichoke " , " Arugula " , " Asparagus " , " Avocado " , " Bamboo Shoots " , " Bean Sprouts " , " Beans " , " Beet " , " Belgian Endive " , " Bell Pepper " ,
" Bitter Gourd " , " Bok Choy " , " Broccoli " , " Brussels Sprouts " , " Burdock Root " , " Cabbage " , " Calabash " , " Capers " , " Carrot " , " Cassava " ,
2023-09-01 14:54:28 +02:00
" Cauliflower " , " Celery " , " Celery Root " , " Celcuce " , " Chayote " , " Chinese Broccoli " , " Corn " , " Cucumber "
2023-08-23 15:53:50 +02:00
} ;
2023-12-06 16:55:55 +01:00
// Extra functions to add deletion support to ImGuiSelectionBasicStorage
struct ExampleSelectionWithDeletion : ImGuiSelectionBasicStorage
2019-12-21 23:21:23 +01:00
{
2023-08-28 16:33:30 +02:00
// Find which item should be Focused after deletion.
2023-10-06 17:10:52 +02:00
// Call _before_ item submission. Retunr an index in the before-deletion item list, your item loop should call SetKeyboardFocusHere() on it.
2023-08-28 16:33:30 +02:00
// The subsequent ApplyDeletionPostLoop() code will use it to apply Selection.
2023-06-02 15:29:55 +02:00
// - We cannot provide this logic in core Dear ImGui because we don't have access to selection data.
2023-08-28 16:33:30 +02:00
// - We don't actually manipulate the ImVector<> here, only in ApplyDeletionPostLoop(), but using similar API for consistency and flexibility.
// - Important: Deletion only works if the underlying ImGuiID for your items are stable: aka not depend on their index, but on e.g. item id/ptr.
2023-12-05 18:36:00 +01:00
// FIXME-MULTISELECT: Doesn't take account of the possibility focus target will be moved during deletion. Need refocus or scroll offset.
2023-10-06 17:10:52 +02:00
int ApplyDeletionPreLoop ( ImGuiMultiSelectIO * ms_io , int items_count )
2023-06-02 14:22:13 +02:00
{
2023-12-01 17:49:47 +01:00
if ( Size = = 0 )
return - 1 ;
2023-06-07 17:28:22 +02:00
2023-08-28 16:33:30 +02:00
// If focused item is not selected...
2023-08-23 15:53:50 +02:00
const int focused_idx = ( int ) ms_io - > NavIdItem ; // Index of currently focused item
2023-08-28 16:33:30 +02:00
if ( ms_io - > NavIdSelected = = false ) // This is merely a shortcut, == Contains(adapter->IndexToStorage(items, focused_idx))
2023-06-02 15:29:55 +02:00
{
2023-08-28 16:33:30 +02:00
ms_io - > RangeSrcReset = true ; // Request to recover RangeSrc from NavId next frame. Would be ok to reset even when NavIdSelected==true, but it would take an extra frame to recover RangeSrc when deleting a selected item.
return focused_idx ; // Request to focus same item after deletion.
2023-06-02 15:29:55 +02:00
}
2023-06-02 14:34:22 +02:00
2023-08-28 16:33:30 +02:00
// If focused item is selected: land on first unselected item after focused item.
2023-10-06 17:10:52 +02:00
for ( int idx = focused_idx + 1 ; idx < items_count ; idx + + )
2024-06-05 17:16:06 +02:00
if ( ! Contains ( GetStorageIdFromIndex ( idx ) ) )
2023-08-23 16:48:04 +02:00
return idx ;
2023-06-02 14:22:13 +02:00
2023-08-28 16:33:30 +02:00
// If focused item is selected: otherwise return last unselected item before focused item.
2023-10-06 17:10:52 +02:00
for ( int idx = IM_MIN ( focused_idx , items_count ) - 1 ; idx > = 0 ; idx - - )
2024-06-05 17:16:06 +02:00
if ( ! Contains ( GetStorageIdFromIndex ( idx ) ) )
2023-08-23 16:48:04 +02:00
return idx ;
2023-06-02 15:29:55 +02:00
2023-06-02 14:22:13 +02:00
return - 1 ;
}
2023-08-28 16:33:30 +02:00
// Rewrite item list (delete items) + update selection.
// - Call after EndMultiSelect()
// - We cannot provide this logic in core Dear ImGui because we don't have access to your items, nor to selection data.
2023-06-02 14:22:13 +02:00
template < typename ITEM_TYPE >
2023-10-06 17:10:52 +02:00
void ApplyDeletionPostLoop ( ImGuiMultiSelectIO * ms_io , ImVector < ITEM_TYPE > & items , int item_curr_idx_to_select )
2023-06-02 14:22:13 +02:00
{
2023-08-28 16:33:30 +02:00
// Rewrite item list (delete items) + convert old selection index (before deletion) to new selection index (after selection).
// If NavId was not part of selection, we will stay on same item.
2023-06-02 14:22:13 +02:00
ImVector < ITEM_TYPE > new_items ;
2023-08-22 17:46:19 +02:00
new_items . reserve ( items . Size - Size ) ;
2023-08-28 16:33:30 +02:00
int item_next_idx_to_select = - 1 ;
for ( int idx = 0 ; idx < items . Size ; idx + + )
2023-06-02 14:22:13 +02:00
{
2024-06-05 17:16:06 +02:00
if ( ! Contains ( GetStorageIdFromIndex ( idx ) ) )
2023-08-28 16:33:30 +02:00
new_items . push_back ( items [ idx ] ) ;
if ( item_curr_idx_to_select = = idx )
item_next_idx_to_select = new_items . Size - 1 ;
2023-06-02 14:22:13 +02:00
}
items . swap ( new_items ) ;
// Update selection
Clear ( ) ;
2023-08-28 16:33:30 +02:00
if ( item_next_idx_to_select ! = - 1 & & ms_io - > NavIdSelected )
2024-06-05 17:16:06 +02:00
SetItemSelected ( GetStorageIdFromIndex ( item_next_idx_to_select ) , true ) ;
2023-06-02 14:22:13 +02:00
}
2019-12-21 23:21:23 +01:00
} ;
2023-08-23 15:53:50 +02:00
// Example: Implement dual list box storage and interface
struct ExampleDualListBox
{
2023-12-01 17:49:47 +01:00
ImVector < ImGuiID > Items [ 2 ] ; // ID is index into ExampleName[]
ImGuiSelectionBasicStorage Selections [ 2 ] ; // Store ExampleItemId into selection
bool OptKeepSorted = true ;
2023-08-23 15:53:50 +02:00
void MoveAll ( int src , int dst )
{
IM_ASSERT ( ( src = = 0 & & dst = = 1 ) | | ( src = = 1 & & dst = = 0 ) ) ;
for ( ImGuiID item_id : Items [ src ] )
Items [ dst ] . push_back ( item_id ) ;
Items [ src ] . clear ( ) ;
SortItems ( dst ) ;
Selections [ src ] . Swap ( Selections [ dst ] ) ;
Selections [ src ] . Clear ( ) ;
}
void MoveSelected ( int src , int dst )
{
for ( int src_n = 0 ; src_n < Items [ src ] . Size ; src_n + + )
{
ImGuiID item_id = Items [ src ] [ src_n ] ;
if ( ! Selections [ src ] . Contains ( item_id ) )
continue ;
Items [ src ] . erase ( & Items [ src ] [ src_n ] ) ; // FIXME-OPT: Could be implemented more optimally (rebuild src items and swap)
Items [ dst ] . push_back ( item_id ) ;
src_n - - ;
}
if ( OptKeepSorted )
SortItems ( dst ) ;
Selections [ src ] . Swap ( Selections [ dst ] ) ;
Selections [ src ] . Clear ( ) ;
}
void ApplySelectionRequests ( ImGuiMultiSelectIO * ms_io , int side )
{
// In this example we store item id in selection (instead of item index)
2024-05-30 18:44:57 +02:00
Selections [ side ] . UserData = Items [ side ] . Data ;
Selections [ side ] . AdapterIndexToStorageId = [ ] ( ImGuiSelectionBasicStorage * self , int idx ) { ImGuiID * items = ( ImGuiID * ) self - > UserData ; return items [ idx ] ; } ;
2024-06-05 17:04:55 +02:00
Selections [ side ] . ApplyRequests ( ms_io ) ;
2023-08-23 15:53:50 +02:00
}
static int IMGUI_CDECL CompareItemsByValue ( const void * lhs , const void * rhs )
{
const int * a = ( const int * ) lhs ;
const int * b = ( const int * ) rhs ;
return ( * a - * b ) > 0 ? + 1 : - 1 ;
}
void SortItems ( int n )
{
qsort ( Items [ n ] . Data , ( size_t ) Items [ n ] . Size , sizeof ( Items [ n ] [ 0 ] ) , CompareItemsByValue ) ;
}
void Show ( )
{
2023-12-05 18:36:00 +01:00
//ImGui::Checkbox("Sorted", &OptKeepSorted);
2023-08-23 15:53:50 +02:00
if ( ImGui : : BeginTable ( " split " , 3 , ImGuiTableFlags_None ) )
{
ImGui : : TableSetupColumn ( " " , ImGuiTableColumnFlags_WidthStretch ) ; // Left side
ImGui : : TableSetupColumn ( " " , ImGuiTableColumnFlags_WidthFixed ) ; // Buttons
ImGui : : TableSetupColumn ( " " , ImGuiTableColumnFlags_WidthStretch ) ; // Right side
ImGui : : TableNextRow ( ) ;
int request_move_selected = - 1 ;
int request_move_all = - 1 ;
2024-03-07 15:52:30 +01:00
float child_height_0 = 0.0f ;
2023-08-23 15:53:50 +02:00
for ( int side = 0 ; side < 2 ; side + + )
{
// FIXME-MULTISELECT: Dual List Box: Add context menus
// FIXME-NAV: Using ImGuiWindowFlags_NavFlattened exhibit many issues.
ImVector < ImGuiID > & items = Items [ side ] ;
2023-12-01 17:49:47 +01:00
ImGuiSelectionBasicStorage & selection = Selections [ side ] ;
2023-08-23 15:53:50 +02:00
ImGui : : TableSetColumnIndex ( ( side = = 0 ) ? 0 : 2 ) ;
ImGui : : Text ( " %s (%d) " , ( side = = 0 ) ? " Available " : " Basket " , items . Size ) ;
// Submit scrolling range to avoid glitches on moving/deletion
const float items_height = ImGui : : GetTextLineHeightWithSpacing ( ) ;
ImGui : : SetNextWindowContentSize ( ImVec2 ( 0.0f , items . Size * items_height ) ) ;
2024-03-07 15:52:30 +01:00
bool child_visible ;
if ( side = = 0 )
{
// Left child is resizable
ImGui : : SetNextWindowSizeConstraints ( ImVec2 ( 0.0f , ImGui : : GetFrameHeightWithSpacing ( ) * 4 ) , ImVec2 ( FLT_MAX , FLT_MAX ) ) ;
child_visible = ImGui : : BeginChild ( " 0 " , ImVec2 ( - FLT_MIN , ImGui : : GetFontSize ( ) * 20 ) , ImGuiChildFlags_FrameStyle | ImGuiChildFlags_ResizeY ) ;
child_height_0 = ImGui : : GetWindowSize ( ) . y ;
}
else
{
// Right child use same height as left one
child_visible = ImGui : : BeginChild ( " 1 " , ImVec2 ( - FLT_MIN , child_height_0 ) , ImGuiChildFlags_FrameStyle ) ;
}
if ( child_visible )
2023-08-23 15:53:50 +02:00
{
ImGuiMultiSelectFlags flags = ImGuiMultiSelectFlags_None ;
2024-06-05 17:04:55 +02:00
ImGuiMultiSelectIO * ms_io = ImGui : : BeginMultiSelect ( flags , selection . Size , items . Size ) ;
2023-08-23 15:53:50 +02:00
ApplySelectionRequests ( ms_io , side ) ;
for ( int item_n = 0 ; item_n < items . Size ; item_n + + )
{
ImGuiID item_id = items [ item_n ] ;
bool item_is_selected = selection . Contains ( item_id ) ;
ImGui : : SetNextItemSelectionUserData ( item_n ) ;
ImGui : : Selectable ( ExampleNames [ item_id ] , item_is_selected , ImGuiSelectableFlags_AllowDoubleClick ) ;
if ( ImGui : : IsItemFocused ( ) )
{
// FIXME-MULTISELECT: Dual List Box: Transfer focus
if ( ImGui : : IsKeyPressed ( ImGuiKey_Enter ) | | ImGui : : IsKeyPressed ( ImGuiKey_KeypadEnter ) )
request_move_selected = side ;
if ( ImGui : : IsMouseDoubleClicked ( 0 ) ) // FIXME-MULTISELECT: Double-click on multi-selection?
request_move_selected = side ;
}
}
ms_io = ImGui : : EndMultiSelect ( ) ;
ApplySelectionRequests ( ms_io , side ) ;
}
ImGui : : EndChild ( ) ;
}
// Buttons columns
ImGui : : TableSetColumnIndex ( 1 ) ;
ImGui : : NewLine ( ) ;
//ImVec2 button_sz = { ImGui::CalcTextSize(">>").x + ImGui::GetStyle().FramePadding.x * 2.0f, ImGui::GetFrameHeight() + padding.y * 2.0f };
ImVec2 button_sz = { ImGui : : GetFrameHeight ( ) , ImGui : : GetFrameHeight ( ) } ;
// (Using BeginDisabled()/EndDisabled() works but feels distracting given how it is currently visualized)
if ( ImGui : : Button ( " >> " , button_sz ) )
request_move_all = 0 ;
if ( ImGui : : Button ( " > " , button_sz ) )
request_move_selected = 0 ;
if ( ImGui : : Button ( " < " , button_sz ) )
request_move_selected = 1 ;
if ( ImGui : : Button ( " << " , button_sz ) )
request_move_all = 1 ;
// Process requests
if ( request_move_all ! = - 1 )
MoveAll ( request_move_all , request_move_all ^ 1 ) ;
if ( request_move_selected ! = - 1 )
MoveSelected ( request_move_selected , request_move_selected ^ 1 ) ;
2023-12-05 18:36:00 +01:00
// FIXME-MULTISELECT: Support action from outside
/*
2023-08-23 15:53:50 +02:00
if ( OptKeepSorted = = false )
{
ImGui : : NewLine ( ) ;
if ( ImGui : : ArrowButton ( " MoveUp " , ImGuiDir_Up ) ) { }
if ( ImGui : : ArrowButton ( " MoveDown " , ImGuiDir_Down ) ) { }
}
2023-12-05 18:36:00 +01:00
*/
2023-08-23 15:53:50 +02:00
ImGui : : EndTable ( ) ;
}
}
} ;
2024-07-19 12:35:57 +02:00
//-----------------------------------------------------------------------------
// [SECTION] ShowDemoWindowMultiSelect()
//-----------------------------------------------------------------------------
2023-12-21 15:12:17 +01:00
// Multi-selection demos
// Also read: https://github.com/ocornut/imgui/wiki/Multi-Select
2024-07-19 12:35:57 +02:00
//-----------------------------------------------------------------------------
2024-07-30 11:44:13 +02:00
static void ShowDemoWindowMultiSelect ( ImGuiDemoWindowData * demo_data )
2019-02-01 12:22:57 +01:00
{
2023-08-22 17:46:19 +02:00
IMGUI_DEMO_MARKER ( " Widgets/Selection State & Multi-Select " ) ;
if ( ImGui : : TreeNode ( " Selection State & Multi-Select " ) )
2019-02-01 12:22:57 +01:00
{
2023-12-21 15:12:17 +01:00
HelpMarker ( " Selections can be built using Selectable(), TreeNode() or other widgets. Selection state is owned by application code/data. " ) ;
2019-02-01 12:22:57 +01:00
2023-12-21 15:12:17 +01:00
// Without any fancy API: manage single-selection yourself.
2023-08-22 17:46:19 +02:00
IMGUI_DEMO_MARKER ( " Widgets/Selection State/Single-Select " ) ;
if ( ImGui : : TreeNode ( " Single-Select " ) )
2019-02-01 12:22:57 +01:00
{
static int selected = - 1 ;
for ( int n = 0 ; n < 5 ; n + + )
{
char buf [ 32 ] ;
sprintf ( buf , " Object %d " , n ) ;
if ( ImGui : : Selectable ( buf , selected = = n ) )
selected = n ;
}
ImGui : : TreePop ( ) ;
}
2023-05-20 15:51:39 +02:00
// Demonstrate implementation a most-basic form of multi-selection manually
2023-08-22 17:46:19 +02:00
// This doesn't support the SHIFT modifier which requires BeginMultiSelect()!
IMGUI_DEMO_MARKER ( " Widgets/Selection State/Multi-Select (manual/simplified, without BeginMultiSelect) " ) ;
if ( ImGui : : TreeNode ( " Multi-Select (manual/simplified, without BeginMultiSelect) " ) )
2019-02-01 12:22:57 +01:00
{
HelpMarker ( " Hold CTRL and click to select multiple items. " ) ;
static bool selection [ 5 ] = { false , false , false , false , false } ;
for ( int n = 0 ; n < 5 ; n + + )
{
char buf [ 32 ] ;
sprintf ( buf , " Object %d " , n ) ;
if ( ImGui : : Selectable ( buf , selection [ n ] ) )
{
2023-05-20 15:51:39 +02:00
if ( ! ImGui : : GetIO ( ) . KeyCtrl ) // Clear selection when CTRL is not held
2019-02-01 12:22:57 +01:00
memset ( selection , 0 , sizeof ( selection ) ) ;
2023-05-20 15:51:39 +02:00
selection [ n ] ^ = 1 ; // Toggle current item
2019-02-01 12:22:57 +01:00
}
}
ImGui : : TreePop ( ) ;
}
2023-12-21 15:12:17 +01:00
// Demonstrate handling proper multi-selection using the BeginMultiSelect/EndMultiSelect API.
2023-04-11 17:38:23 +02:00
// SHIFT+Click w/ CTRL and other standard features are supported.
2023-12-21 15:12:17 +01:00
// We use the ImGuiSelectionBasicStorage helper which you may freely reimplement.
2023-08-22 17:46:19 +02:00
IMGUI_DEMO_MARKER ( " Widgets/Selection State/Multi-Select " ) ;
if ( ImGui : : TreeNode ( " Multi-Select " ) )
2019-02-01 12:22:57 +01:00
{
2023-04-11 17:38:23 +02:00
ImGui : : Text ( " Supported features: " ) ;
ImGui : : BulletText ( " Keyboard navigation (arrows, page up/down, home/end, space). " ) ;
ImGui : : BulletText ( " Ctrl modifier to preserve and toggle selection. " ) ;
ImGui : : BulletText ( " Shift modifier for range selection. " ) ;
ImGui : : BulletText ( " CTRL+A to select all. " ) ;
2023-12-06 16:55:55 +01:00
ImGui : : BulletText ( " Escape to clear selection. " ) ;
2023-12-20 11:34:25 +01:00
ImGui : : BulletText ( " Click and drag to box-select. " ) ;
2023-12-06 16:55:55 +01:00
ImGui : : Text ( " Tip: Use 'Demo->Tools->Debug Log->Selection' to see selection requests as they happen. " ) ;
2023-04-11 17:38:23 +02:00
2023-12-05 18:36:00 +01:00
// Use default selection.Adapter: Pass index to SetNextItemSelectionUserData(), store index in Selection
2023-04-11 17:38:23 +02:00
const int ITEMS_COUNT = 50 ;
2023-12-05 18:36:00 +01:00
static ImGuiSelectionBasicStorage selection ;
2023-12-06 16:55:55 +01:00
ImGui : : Text ( " Selection: %d/%d " , selection . Size , ITEMS_COUNT ) ;
2023-12-05 18:36:00 +01:00
2024-03-07 15:52:30 +01:00
// The BeginChild() has no purpose for selection logic, other that offering a scrolling region.
if ( ImGui : : BeginChild ( " ##Basket " , ImVec2 ( - FLT_MIN , ImGui : : GetFontSize ( ) * 20 ) , ImGuiChildFlags_FrameStyle | ImGuiChildFlags_ResizeY ) )
2019-02-01 12:22:57 +01:00
{
2024-05-31 21:57:10 +02:00
ImGuiMultiSelectFlags flags = ImGuiMultiSelectFlags_ClearOnEscape | ImGuiMultiSelectFlags_BoxSelect1d ;
2024-06-05 17:04:55 +02:00
ImGuiMultiSelectIO * ms_io = ImGui : : BeginMultiSelect ( flags , selection . Size , ITEMS_COUNT ) ;
selection . ApplyRequests ( ms_io ) ;
2023-04-11 17:38:23 +02:00
for ( int n = 0 ; n < ITEMS_COUNT ; n + + )
{
char label [ 64 ] ;
2023-08-23 15:53:50 +02:00
sprintf ( label , " Object %05d: %s " , n , ExampleNames [ n % IM_ARRAYSIZE ( ExampleNames ) ] ) ;
2023-08-28 17:36:59 +02:00
bool item_is_selected = selection . Contains ( ( ImGuiID ) n ) ;
2023-04-11 17:59:06 +02:00
ImGui : : SetNextItemSelectionUserData ( n ) ;
2023-04-11 17:38:23 +02:00
ImGui : : Selectable ( label , item_is_selected ) ;
}
2023-08-23 19:47:24 +02:00
ms_io = ImGui : : EndMultiSelect ( ) ;
2024-06-05 17:04:55 +02:00
selection . ApplyRequests ( ms_io ) ;
2023-08-23 19:47:24 +02:00
}
2024-03-07 15:52:30 +01:00
ImGui : : EndChild ( ) ;
2023-08-23 19:47:24 +02:00
ImGui : : TreePop ( ) ;
}
// Demonstrate using the clipper with BeginMultiSelect()/EndMultiSelect()
IMGUI_DEMO_MARKER ( " Widgets/Selection State/Multi-Select (with clipper) " ) ;
if ( ImGui : : TreeNode ( " Multi-Select (with clipper) " ) )
{
2023-10-06 17:10:52 +02:00
// Use default selection.Adapter: Pass index to SetNextItemSelectionUserData(), store index in Selection
2023-12-01 17:49:47 +01:00
static ImGuiSelectionBasicStorage selection ;
2023-08-23 19:47:24 +02:00
ImGui : : Text ( " Added features: " ) ;
ImGui : : BulletText ( " Using ImGuiListClipper. " ) ;
const int ITEMS_COUNT = 10000 ;
2023-12-06 16:55:55 +01:00
ImGui : : Text ( " Selection: %d/%d " , selection . Size , ITEMS_COUNT ) ;
2024-03-07 15:52:30 +01:00
if ( ImGui : : BeginChild ( " ##Basket " , ImVec2 ( - FLT_MIN , ImGui : : GetFontSize ( ) * 20 ) , ImGuiChildFlags_FrameStyle | ImGuiChildFlags_ResizeY ) )
2023-08-23 19:47:24 +02:00
{
2024-05-31 21:57:10 +02:00
ImGuiMultiSelectFlags flags = ImGuiMultiSelectFlags_ClearOnEscape | ImGuiMultiSelectFlags_BoxSelect1d ;
2024-06-05 17:04:55 +02:00
ImGuiMultiSelectIO * ms_io = ImGui : : BeginMultiSelect ( flags , selection . Size , ITEMS_COUNT ) ;
selection . ApplyRequests ( ms_io ) ;
2023-08-23 19:47:24 +02:00
ImGuiListClipper clipper ;
clipper . Begin ( ITEMS_COUNT ) ;
2024-01-04 20:05:05 +01:00
if ( ms_io - > RangeSrcItem ! = - 1 )
2023-08-23 20:45:02 +02:00
clipper . IncludeItemByIndex ( ( int ) ms_io - > RangeSrcItem ) ; // Ensure RangeSrc item is not clipped.
2023-08-23 19:47:24 +02:00
while ( clipper . Step ( ) )
{
for ( int n = clipper . DisplayStart ; n < clipper . DisplayEnd ; n + + )
{
char label [ 64 ] ;
2023-08-23 15:53:50 +02:00
sprintf ( label , " Object %05d: %s " , n , ExampleNames [ n % IM_ARRAYSIZE ( ExampleNames ) ] ) ;
2023-08-28 17:36:59 +02:00
bool item_is_selected = selection . Contains ( ( ImGuiID ) n ) ;
2023-08-23 19:47:24 +02:00
ImGui : : SetNextItemSelectionUserData ( n ) ;
ImGui : : Selectable ( label , item_is_selected ) ;
}
}
2023-05-24 15:16:17 +02:00
ms_io = ImGui : : EndMultiSelect ( ) ;
2024-06-05 17:04:55 +02:00
selection . ApplyRequests ( ms_io ) ;
2023-04-11 17:38:23 +02:00
}
2024-03-07 15:52:30 +01:00
ImGui : : EndChild ( ) ;
2023-06-02 14:22:13 +02:00
ImGui : : TreePop ( ) ;
}
2023-04-11 17:38:23 +02:00
2023-12-21 15:12:17 +01:00
// Demonstrate dynamic item list + deletion support using the BeginMultiSelect/EndMultiSelect API.
2023-06-02 15:29:55 +02:00
// In order to support Deletion without any glitches you need to:
// - (1) If items are submitted in their own scrolling area, submit contents size SetNextWindowContentSize() ahead of time to prevent one-frame readjustment of scrolling.
// - (2) Items needs to have persistent ID Stack identifier = ID needs to not depends on their index. PushID(index) = KO. PushID(item_id) = OK. This is in order to focus items reliably after a selection.
// - (3) BeginXXXX process
// - (4) Focus process
// - (5) EndXXXX process
2023-08-22 17:46:19 +02:00
IMGUI_DEMO_MARKER ( " Widgets/Selection State/Multi-Select (with deletion) " ) ;
if ( ImGui : : TreeNode ( " Multi-Select (with deletion) " ) )
2023-06-02 14:22:13 +02:00
{
2023-12-06 16:55:55 +01:00
// Storing items data separately from selection data.
// (you may decide to store selection data inside your item (aka intrusive storage) if you don't need multiple views over same items)
// Use a custom selection.Adapter: store item identifier in Selection (instead of index)
static ImVector < ImGuiID > items ;
static ExampleSelectionWithDeletion selection ;
2024-05-30 18:44:57 +02:00
selection . UserData = ( void * ) & items ;
selection . AdapterIndexToStorageId = [ ] ( ImGuiSelectionBasicStorage * self , int idx ) { ImVector < ImGuiID > * p_items = ( ImVector < ImGuiID > * ) self - > UserData ; return ( * p_items ) [ idx ] ; } ; // Index -> ID
2023-06-02 14:22:13 +02:00
2023-12-06 16:55:55 +01:00
ImGui : : Text ( " Added features: " ) ;
2023-06-02 14:22:13 +02:00
ImGui : : BulletText ( " Dynamic list with Delete key support. " ) ;
2023-12-06 16:55:55 +01:00
ImGui : : Text ( " Selection size: %d/%d " , selection . Size , items . Size ) ;
2023-06-02 14:22:13 +02:00
2023-06-02 15:29:55 +02:00
// Initialize default list with 50 items + button to add/remove items.
2023-12-06 16:55:55 +01:00
static ImGuiID items_next_id = 0 ;
2023-06-02 14:22:13 +02:00
if ( items_next_id = = 0 )
2023-12-06 16:55:55 +01:00
for ( ImGuiID n = 0 ; n < 50 ; n + + )
2023-06-02 14:22:13 +02:00
items . push_back ( items_next_id + + ) ;
2023-06-02 14:34:22 +02:00
if ( ImGui : : SmallButton ( " Add 20 items " ) ) { for ( int n = 0 ; n < 20 ; n + + ) { items . push_back ( items_next_id + + ) ; } }
2023-06-02 14:22:13 +02:00
ImGui : : SameLine ( ) ;
2024-03-06 15:04:03 +01:00
if ( ImGui : : SmallButton ( " Remove 20 items " ) ) { for ( int n = IM_MIN ( 20 , items . Size ) ; n > 0 ; n - - ) { selection . SetItemSelected ( items . back ( ) , false ) ; items . pop_back ( ) ; } }
2023-06-02 14:22:13 +02:00
2023-06-02 15:29:55 +02:00
// (1) Extra to support deletion: Submit scrolling range to avoid glitches on deletion
2023-06-02 14:22:13 +02:00
const float items_height = ImGui : : GetTextLineHeightWithSpacing ( ) ;
ImGui : : SetNextWindowContentSize ( ImVec2 ( 0.0f , items . Size * items_height ) ) ;
2023-06-02 15:29:55 +02:00
2024-03-07 15:52:30 +01:00
if ( ImGui : : BeginChild ( " ##Basket " , ImVec2 ( - FLT_MIN , ImGui : : GetFontSize ( ) * 20 ) , ImGuiChildFlags_FrameStyle | ImGuiChildFlags_ResizeY ) )
2023-06-02 14:22:13 +02:00
{
2024-05-31 21:57:10 +02:00
ImGuiMultiSelectFlags flags = ImGuiMultiSelectFlags_ClearOnEscape | ImGuiMultiSelectFlags_BoxSelect1d ;
2024-06-05 17:04:55 +02:00
ImGuiMultiSelectIO * ms_io = ImGui : : BeginMultiSelect ( flags , selection . Size , items . Size ) ;
selection . ApplyRequests ( ms_io ) ;
2023-06-02 14:22:13 +02:00
2024-05-23 18:56:31 +02:00
const bool want_delete = ImGui : : Shortcut ( ImGuiKey_Delete , ImGuiInputFlags_Repeat ) & & ( selection . Size > 0 ) ;
2023-12-06 16:55:55 +01:00
const int item_curr_idx_to_focus = want_delete ? selection . ApplyDeletionPreLoop ( ms_io , items . Size ) : - 1 ;
2023-06-02 14:22:13 +02:00
for ( int n = 0 ; n < items . Size ; n + + )
{
2023-12-06 16:55:55 +01:00
const ImGuiID item_id = items [ n ] ;
2023-06-02 14:22:13 +02:00
char label [ 64 ] ;
2023-12-06 16:55:55 +01:00
sprintf ( label , " Object %05u: %s " , item_id , ExampleNames [ item_id % IM_ARRAYSIZE ( ExampleNames ) ] ) ;
2023-06-02 14:22:13 +02:00
2023-12-06 16:55:55 +01:00
bool item_is_selected = selection . Contains ( item_id ) ;
2023-06-02 14:34:22 +02:00
ImGui : : SetNextItemSelectionUserData ( n ) ;
2023-06-02 14:22:13 +02:00
ImGui : : Selectable ( label , item_is_selected ) ;
2023-08-28 16:33:30 +02:00
if ( item_curr_idx_to_focus = = n )
2023-06-02 15:29:55 +02:00
ImGui : : SetKeyboardFocusHere ( - 1 ) ;
2023-06-02 14:22:13 +02:00
}
2023-06-02 15:17:01 +02:00
// Apply multi-select requests
2023-06-02 14:22:13 +02:00
ms_io = ImGui : : EndMultiSelect ( ) ;
2024-06-05 17:04:55 +02:00
selection . ApplyRequests ( ms_io ) ;
2023-06-02 14:22:13 +02:00
if ( want_delete )
2023-10-06 17:10:52 +02:00
selection . ApplyDeletionPostLoop ( ms_io , items , item_curr_idx_to_focus ) ;
2023-06-02 14:22:13 +02:00
}
2024-03-07 15:52:30 +01:00
ImGui : : EndChild ( ) ;
2023-04-11 17:38:23 +02:00
ImGui : : TreePop ( ) ;
}
2023-08-23 15:53:50 +02:00
// Implement a Dual List Box (#6648)
IMGUI_DEMO_MARKER ( " Widgets/Selection State/Multi-Select (dual list box) " ) ;
if ( ImGui : : TreeNode ( " Multi-Select (dual list box) " ) )
{
// Init default state
static ExampleDualListBox dlb ;
if ( dlb . Items [ 0 ] . Size = = 0 & & dlb . Items [ 1 ] . Size = = 0 )
for ( int item_id = 0 ; item_id < IM_ARRAYSIZE ( ExampleNames ) ; item_id + + )
dlb . Items [ 0 ] . push_back ( ( ImGuiID ) item_id ) ;
// Show
dlb . Show ( ) ;
ImGui : : TreePop ( ) ;
}
2024-07-29 15:23:24 +02:00
// Demonstrate using the clipper with BeginMultiSelect()/EndMultiSelect()
IMGUI_DEMO_MARKER ( " Widgets/Selection State/Multi-Select (in a table) " ) ;
if ( ImGui : : TreeNode ( " Multi-Select (in a table) " ) )
{
static ImGuiSelectionBasicStorage selection ;
const int ITEMS_COUNT = 10000 ;
ImGui : : Text ( " Selection: %d/%d " , selection . Size , ITEMS_COUNT ) ;
if ( ImGui : : BeginTable ( " ##Basket " , 2 , ImGuiTableFlags_ScrollY | ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersOuter ) )
{
ImGui : : TableSetupColumn ( " Object " ) ;
ImGui : : TableSetupColumn ( " Action " ) ;
ImGui : : TableSetupScrollFreeze ( 0 , 1 ) ;
ImGui : : TableHeadersRow ( ) ;
ImGuiMultiSelectFlags flags = ImGuiMultiSelectFlags_ClearOnEscape | ImGuiMultiSelectFlags_BoxSelect1d ;
ImGuiMultiSelectIO * ms_io = ImGui : : BeginMultiSelect ( flags , selection . Size , ITEMS_COUNT ) ;
selection . ApplyRequests ( ms_io ) ;
ImGuiListClipper clipper ;
clipper . Begin ( ITEMS_COUNT ) ;
if ( ms_io - > RangeSrcItem ! = - 1 )
clipper . IncludeItemByIndex ( ( int ) ms_io - > RangeSrcItem ) ; // Ensure RangeSrc item is not clipped.
while ( clipper . Step ( ) )
{
for ( int n = clipper . DisplayStart ; n < clipper . DisplayEnd ; n + + )
{
ImGui : : TableNextRow ( ) ;
ImGui : : TableNextColumn ( ) ;
char label [ 64 ] ;
sprintf ( label , " Object %05d: %s " , n , ExampleNames [ n % IM_ARRAYSIZE ( ExampleNames ) ] ) ;
bool item_is_selected = selection . Contains ( ( ImGuiID ) n ) ;
ImGui : : SetNextItemSelectionUserData ( n ) ;
ImGui : : Selectable ( label , item_is_selected , ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowOverlap ) ;
ImGui : : TableNextColumn ( ) ;
ImGui : : SmallButton ( " hello " ) ;
}
}
ms_io = ImGui : : EndMultiSelect ( ) ;
selection . ApplyRequests ( ms_io ) ;
ImGui : : EndTable ( ) ;
}
ImGui : : TreePop ( ) ;
}
2024-03-07 16:26:22 +01:00
IMGUI_DEMO_MARKER ( " Widgets/Selection State/Multi-Select (checkboxes) " ) ;
if ( ImGui : : TreeNode ( " Multi-Select (checkboxes) " ) )
{
ImGui : : Text ( " In a list of checkboxes (not selectable): " ) ;
ImGui : : BulletText ( " Using _NoAutoSelect + _NoAutoClear flags. " ) ;
ImGui : : BulletText ( " Shift+Click to check multiple boxes. " ) ;
ImGui : : BulletText ( " Shift+Keyboard to copy current value to other boxes. " ) ;
2024-06-04 15:10:07 +02:00
// If you have an array of checkboxes, you may want to use NoAutoSelect + NoAutoClear and the ImGuiSelectionExternalStorage helper.
2024-06-05 19:00:13 +02:00
static bool items [ 20 ] = { } ;
2024-03-07 16:26:22 +01:00
static ImGuiMultiSelectFlags flags = ImGuiMultiSelectFlags_NoAutoSelect | ImGuiMultiSelectFlags_NoAutoClear | ImGuiMultiSelectFlags_ClearOnEscape ;
ImGui : : CheckboxFlags ( " ImGuiMultiSelectFlags_NoAutoSelect " , & flags , ImGuiMultiSelectFlags_NoAutoSelect ) ;
ImGui : : CheckboxFlags ( " ImGuiMultiSelectFlags_NoAutoClear " , & flags , ImGuiMultiSelectFlags_NoAutoClear ) ;
2024-06-26 20:26:06 +02:00
ImGui : : CheckboxFlags ( " ImGuiMultiSelectFlags_BoxSelect2d " , & flags , ImGuiMultiSelectFlags_BoxSelect2d ) ; // Cannot use ImGuiMultiSelectFlags_BoxSelect1d as checkboxes are varying width.
2024-03-07 16:26:22 +01:00
2024-08-23 15:24:22 +02:00
if ( ImGui : : BeginChild ( " ##Basket " , ImVec2 ( - FLT_MIN , ImGui : : GetFontSize ( ) * 20 ) , ImGuiChildFlags_Borders | ImGuiChildFlags_ResizeY ) )
2024-03-07 16:26:22 +01:00
{
2024-06-05 19:00:13 +02:00
ImGuiMultiSelectIO * ms_io = ImGui : : BeginMultiSelect ( flags , - 1 , IM_ARRAYSIZE ( items ) ) ;
ImGuiSelectionExternalStorage storage_wrapper ;
storage_wrapper . UserData = ( void * ) items ;
storage_wrapper . AdapterSetItemSelected = [ ] ( ImGuiSelectionExternalStorage * self , int n , bool selected ) { bool * array = ( bool * ) self - > UserData ; array [ n ] = selected ; } ;
storage_wrapper . ApplyRequests ( ms_io ) ;
2024-03-07 16:26:22 +01:00
for ( int n = 0 ; n < 20 ; n + + )
{
char label [ 32 ] ;
sprintf ( label , " Item %d " , n ) ;
ImGui : : SetNextItemSelectionUserData ( n ) ;
2024-06-05 19:00:13 +02:00
ImGui : : Checkbox ( label , & items [ n ] ) ;
2024-03-07 16:26:22 +01:00
}
ms_io = ImGui : : EndMultiSelect ( ) ;
2024-06-05 19:00:13 +02:00
storage_wrapper . ApplyRequests ( ms_io ) ;
2024-03-07 16:26:22 +01:00
}
ImGui : : EndChild ( ) ;
ImGui : : TreePop ( ) ;
}
2023-05-24 16:31:00 +02:00
// Demonstrate individual selection scopes in same window
2023-08-22 17:46:19 +02:00
IMGUI_DEMO_MARKER ( " Widgets/Selection State/Multi-Select (multiple scopes) " ) ;
if ( ImGui : : TreeNode ( " Multi-Select (multiple scopes) " ) )
2023-05-24 16:31:00 +02:00
{
2023-10-06 17:10:52 +02:00
// Use default select: Pass index to SetNextItemSelectionUserData(), store index in Selection
2023-05-24 16:31:00 +02:00
const int SCOPES_COUNT = 3 ;
const int ITEMS_COUNT = 8 ; // Per scope
2023-12-01 17:49:47 +01:00
static ImGuiSelectionBasicStorage selections_data [ SCOPES_COUNT ] ;
2023-05-24 16:31:00 +02:00
2023-09-25 19:53:02 +02:00
// Use ImGuiMultiSelectFlags_ScopeRect to not affect other selections in same window.
static ImGuiMultiSelectFlags flags = ImGuiMultiSelectFlags_ScopeRect | ImGuiMultiSelectFlags_ClearOnEscape ; // | ImGuiMultiSelectFlags_ClearOnClickVoid;
if ( ImGui : : CheckboxFlags ( " ImGuiMultiSelectFlags_ScopeWindow " , & flags , ImGuiMultiSelectFlags_ScopeWindow ) & & ( flags & ImGuiMultiSelectFlags_ScopeWindow ) )
flags & = ~ ImGuiMultiSelectFlags_ScopeRect ;
if ( ImGui : : CheckboxFlags ( " ImGuiMultiSelectFlags_ScopeRect " , & flags , ImGuiMultiSelectFlags_ScopeRect ) & & ( flags & ImGuiMultiSelectFlags_ScopeRect ) )
flags & = ~ ImGuiMultiSelectFlags_ScopeWindow ;
ImGui : : CheckboxFlags ( " ImGuiMultiSelectFlags_ClearOnClickVoid " , & flags , ImGuiMultiSelectFlags_ClearOnClickVoid ) ;
2024-05-31 21:57:10 +02:00
ImGui : : CheckboxFlags ( " ImGuiMultiSelectFlags_BoxSelect1d " , & flags , ImGuiMultiSelectFlags_BoxSelect1d ) ;
2023-09-25 19:53:02 +02:00
2023-05-24 16:31:00 +02:00
for ( int selection_scope_n = 0 ; selection_scope_n < SCOPES_COUNT ; selection_scope_n + + )
{
2023-08-29 16:27:31 +02:00
ImGui : : PushID ( selection_scope_n ) ;
2023-12-01 17:49:47 +01:00
ImGuiSelectionBasicStorage * selection = & selections_data [ selection_scope_n ] ;
2024-06-05 17:04:55 +02:00
ImGuiMultiSelectIO * ms_io = ImGui : : BeginMultiSelect ( flags , selection - > Size , ITEMS_COUNT ) ;
selection - > ApplyRequests ( ms_io ) ;
2023-05-24 16:31:00 +02:00
2023-09-25 19:53:02 +02:00
ImGui : : SeparatorText ( " Selection scope " ) ;
2023-12-06 16:55:55 +01:00
ImGui : : Text ( " Selection size: %d/%d " , selection - > Size , ITEMS_COUNT ) ;
2023-09-25 19:53:02 +02:00
2023-05-24 16:31:00 +02:00
for ( int n = 0 ; n < ITEMS_COUNT ; n + + )
{
char label [ 64 ] ;
2023-08-23 15:53:50 +02:00
sprintf ( label , " Object %05d: %s " , n , ExampleNames [ n % IM_ARRAYSIZE ( ExampleNames ) ] ) ;
2023-08-28 17:36:59 +02:00
bool item_is_selected = selection - > Contains ( ( ImGuiID ) n ) ;
2023-05-24 16:31:00 +02:00
ImGui : : SetNextItemSelectionUserData ( n ) ;
ImGui : : Selectable ( label , item_is_selected ) ;
}
// Apply multi-select requests
ms_io = ImGui : : EndMultiSelect ( ) ;
2024-06-05 17:04:55 +02:00
selection - > ApplyRequests ( ms_io ) ;
2023-05-24 16:31:00 +02:00
ImGui : : PopID ( ) ;
}
ImGui : : TreePop ( ) ;
}
2023-08-29 16:27:31 +02:00
// See ShowExampleAppAssetsBrowser()
2023-08-31 20:06:22 +02:00
if ( ImGui : : TreeNode ( " Multi-Select (tiled assets browser) " ) )
{
2024-07-19 15:34:48 +02:00
ImGui : : Checkbox ( " Assets Browser " , & demo_data - > ShowAppAssetsBrowser ) ;
ImGui : : Text ( " (also access from 'Examples->Assets Browser' in menu) " ) ;
2023-08-31 20:06:22 +02:00
ImGui : : TreePop ( ) ;
}
2023-08-21 11:26:19 +02:00
// Demonstrate supporting multiple-selection in a tree.
// - We don't use linear indices for selection user data, but our ExampleTreeNode* pointer directly!
// This showcase how SetNextItemSelectionUserData() never assume indices!
// - The difficulty here is to "interpolate" from RangeSrcItem to RangeDstItem in the SetAll/SetRange request.
// We want this interpolation to match what the user sees: in visible order, skipping closed nodes.
// This is implemented by our TreeGetNextNodeInVisibleOrder() user-space helper.
// - Important: In a real codebase aiming to implement full-featured selectable tree with custom filtering, you
// are more likely to build an array mapping sequential indices to visible tree nodes, since your
// filtering/search + clipping process will benefit from it. Having this will make this interpolation much easier.
// - Consider this a prototype: we are working toward simplifying some of it.
IMGUI_DEMO_MARKER ( " Widgets/Selection State/Multi-Select (trees) " ) ;
if ( ImGui : : TreeNode ( " Multi-Select (trees) " ) )
{
HelpMarker (
" This is rather advanced and experimental. If you are getting started with multi-select, "
" please don't start by looking at how to use it for a tree! \n \n "
" Future versions will try to simplify and formalize some of this. " ) ;
struct ExampleTreeFuncs
{
static void DrawNode ( ExampleTreeNode * node , ImGuiSelectionBasicStorage * selection )
{
ImGuiTreeNodeFlags tree_node_flags = ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick ;
tree_node_flags | = ImGuiTreeNodeFlags_NavLeftJumpsBackHere ; // Enable pressing left to jump to parent
if ( node - > Childs . Size = = 0 )
tree_node_flags | = ImGuiTreeNodeFlags_Bullet | ImGuiTreeNodeFlags_Leaf ;
if ( selection - > Contains ( ( ImGuiID ) node - > UID ) )
tree_node_flags | = ImGuiTreeNodeFlags_Selected ;
// Using SetNextItemStorageID() to specify storage id, so we can easily peek into
// the storage holding open/close stage, using our TreeNodeGetOpen/TreeNodeSetOpen() functions.
ImGui : : SetNextItemSelectionUserData ( ( ImGuiSelectionUserData ) ( intptr_t ) node ) ;
ImGui : : SetNextItemStorageID ( ( ImGuiID ) node - > UID ) ;
if ( ImGui : : TreeNodeEx ( node - > Name , tree_node_flags ) )
{
for ( ExampleTreeNode * child : node - > Childs )
DrawNode ( child , selection ) ;
ImGui : : TreePop ( ) ;
}
else if ( ImGui : : IsItemToggledOpen ( ) )
{
TreeCloseAndUnselectChildNodes ( node , selection ) ;
}
}
static bool TreeNodeGetOpen ( ExampleTreeNode * node )
{
return ImGui : : GetStateStorage ( ) - > GetBool ( ( ImGuiID ) node - > UID ) ;
}
static void TreeNodeSetOpen ( ExampleTreeNode * node , bool open )
{
ImGui : : GetStateStorage ( ) - > SetBool ( ( ImGuiID ) node - > UID , open ) ;
}
// When closing a node: 1) close and unselect all child nodes, 2) select parent if any child was selected.
// FIXME: This is currently handled by user logic but I'm hoping to eventually provide tree node
// features to do this automatically, e.g. a ImGuiTreeNodeFlags_AutoCloseChildNodes etc.
static int TreeCloseAndUnselectChildNodes ( ExampleTreeNode * node , ImGuiSelectionBasicStorage * selection , int depth = 0 )
{
// Recursive close (the test for depth == 0 is because we call this on a node that was just closed!)
int unselected_count = selection - > Contains ( ( ImGuiID ) node - > UID ) ? 1 : 0 ;
if ( depth = = 0 | | TreeNodeGetOpen ( node ) )
{
for ( ExampleTreeNode * child : node - > Childs )
unselected_count + = TreeCloseAndUnselectChildNodes ( child , selection , depth + 1 ) ;
TreeNodeSetOpen ( node , false ) ;
}
// Select root node if any of its child was selected, otherwise unselect
selection - > SetItemSelected ( ( ImGuiID ) node - > UID , ( depth = = 0 & & unselected_count > 0 ) ) ;
return unselected_count ;
}
// Apply multi-selection requests
static void ApplySelectionRequests ( ImGuiMultiSelectIO * ms_io , ExampleTreeNode * tree , ImGuiSelectionBasicStorage * selection )
{
for ( ImGuiSelectionRequest & req : ms_io - > Requests )
{
if ( req . Type = = ImGuiSelectionRequestType_SetAll )
{
if ( req . Selected )
TreeSetAllInOpenNodes ( tree , selection , req . Selected ) ;
else
selection - > Clear ( ) ;
}
else if ( req . Type = = ImGuiSelectionRequestType_SetRange )
{
ExampleTreeNode * first_node = ( ExampleTreeNode * ) ( intptr_t ) req . RangeFirstItem ;
ExampleTreeNode * last_node = ( ExampleTreeNode * ) ( intptr_t ) req . RangeLastItem ;
for ( ExampleTreeNode * node = first_node ; node ! = NULL ; node = TreeGetNextNodeInVisibleOrder ( node , last_node ) )
selection - > SetItemSelected ( ( ImGuiID ) node - > UID , req . Selected ) ;
}
}
}
static void TreeSetAllInOpenNodes ( ExampleTreeNode * node , ImGuiSelectionBasicStorage * selection , bool selected )
{
if ( node - > Parent ! = NULL ) // Root node isn't visible nor selectable in our scheme
selection - > SetItemSelected ( ( ImGuiID ) node - > UID , selected ) ;
if ( node - > Parent = = NULL | | TreeNodeGetOpen ( node ) )
for ( ExampleTreeNode * child : node - > Childs )
TreeSetAllInOpenNodes ( child , selection , selected ) ;
}
// Interpolate in *user-visible order* AND only *over opened nodes*.
// If you have a sequential mapping tables (e.g. generated after a filter/search pass) this would be simpler.
// Here the tricks are that:
// - we store/maintain ExampleTreeNode::IndexInParent which allows implementing a linear iterator easily, without searches, without recursion.
// this could be replaced by a search in parent, aka 'int index_in_parent = curr_node->Parent->Childs.find_index(curr_node)'
// which would only be called when crossing from child to a parent, aka not too much.
// - we call SetNextItemStorageID() before our TreeNode() calls with an ID which doesn't relate to UI stack,
// making it easier to call TreeNodeGetOpen()/TreeNodeSetOpen() from any location.
static ExampleTreeNode * TreeGetNextNodeInVisibleOrder ( ExampleTreeNode * curr_node , ExampleTreeNode * last_node )
{
// Reached last node
if ( curr_node = = last_node )
return NULL ;
// Recurse into childs. Query storage to tell if the node is open.
if ( curr_node - > Childs . Size > 0 & & TreeNodeGetOpen ( curr_node ) )
return curr_node - > Childs [ 0 ] ;
// Next sibling, then into our own parent
while ( curr_node - > Parent ! = NULL )
{
if ( curr_node - > IndexInParent + 1 < curr_node - > Parent - > Childs . Size )
return curr_node - > Parent - > Childs [ curr_node - > IndexInParent + 1 ] ;
curr_node = curr_node - > Parent ;
}
return NULL ;
}
} ; // ExampleTreeFuncs
static ImGuiSelectionBasicStorage selection ;
2024-07-30 11:44:13 +02:00
if ( demo_data - > DemoTree = = NULL )
demo_data - > DemoTree = ExampleTree_CreateDemoTree ( ) ; // Create tree once
2023-08-21 11:26:19 +02:00
ImGui : : Text ( " Selection size: %d " , selection . Size ) ;
if ( ImGui : : BeginChild ( " ##Tree " , ImVec2 ( - FLT_MIN , ImGui : : GetFontSize ( ) * 20 ) , ImGuiChildFlags_FrameStyle | ImGuiChildFlags_ResizeY ) )
{
2024-07-30 11:44:13 +02:00
ExampleTreeNode * tree = demo_data - > DemoTree ;
2023-08-21 11:26:19 +02:00
ImGuiMultiSelectFlags ms_flags = ImGuiMultiSelectFlags_ClearOnEscape | ImGuiMultiSelectFlags_BoxSelect2d ;
ImGuiMultiSelectIO * ms_io = ImGui : : BeginMultiSelect ( ms_flags , selection . Size , - 1 ) ;
ExampleTreeFuncs : : ApplySelectionRequests ( ms_io , tree , & selection ) ;
for ( ExampleTreeNode * node : tree - > Childs )
ExampleTreeFuncs : : DrawNode ( node , & selection ) ;
ms_io = ImGui : : EndMultiSelect ( ) ;
ExampleTreeFuncs : : ApplySelectionRequests ( ms_io , tree , & selection ) ;
}
ImGui : : EndChild ( ) ;
ImGui : : TreePop ( ) ;
}
2023-04-11 17:38:23 +02:00
// Advanced demonstration of BeginMultiSelect()
// - Showcase clipping.
2023-06-02 14:22:13 +02:00
// - Showcase deletion.
2023-04-11 17:38:23 +02:00
// - Showcase basic drag and drop.
// - Showcase TreeNode variant (note that tree node don't expand in the demo: supporting expanding tree nodes + clipping a separate thing).
// - Showcase using inside a table.
2023-08-22 17:46:19 +02:00
IMGUI_DEMO_MARKER ( " Widgets/Selection State/Multi-Select (advanced) " ) ;
2023-04-12 19:48:58 +02:00
//ImGui::SetNextItemOpen(true, ImGuiCond_Once);
2023-08-22 17:46:19 +02:00
if ( ImGui : : TreeNode ( " Multi-Select (advanced) " ) )
2023-04-11 17:38:23 +02:00
{
2023-04-11 19:33:38 +02:00
// Options
2020-03-11 21:57:18 +01:00
enum WidgetType { WidgetType_Selectable , WidgetType_TreeNode } ;
2023-05-24 16:31:00 +02:00
static bool use_clipper = true ;
2023-06-02 14:22:13 +02:00
static bool use_deletion = true ;
2022-06-17 15:55:59 +02:00
static bool use_drag_drop = true ;
2023-05-24 16:31:00 +02:00
static bool show_in_table = false ;
2024-07-30 14:49:07 +02:00
static bool show_color_button = true ;
2024-05-31 21:57:10 +02:00
static ImGuiMultiSelectFlags flags = ImGuiMultiSelectFlags_ClearOnEscape | ImGuiMultiSelectFlags_BoxSelect1d ;
2023-05-22 10:28:40 +02:00
static WidgetType widget_type = WidgetType_Selectable ;
2023-12-21 15:12:17 +01:00
if ( ImGui : : TreeNode ( " Options " ) )
{
if ( ImGui : : RadioButton ( " Selectables " , widget_type = = WidgetType_Selectable ) ) { widget_type = WidgetType_Selectable ; }
ImGui : : SameLine ( ) ;
if ( ImGui : : RadioButton ( " Tree nodes " , widget_type = = WidgetType_TreeNode ) ) { widget_type = WidgetType_TreeNode ; }
2024-07-18 18:05:45 +02:00
ImGui : : SameLine ( ) ;
HelpMarker ( " TreeNode() is technically supported but... using this correctly is more complicated (you need some sort of linear/random access to your tree, which is suited to advanced trees setups already implementing filters and clipper. We will work toward simplifying and demoing this. \n \n For now the tree demo is actually a little bit meaningless because it is an empty tree with only root nodes. " ) ;
2023-12-21 15:12:17 +01:00
ImGui : : Checkbox ( " Enable clipper " , & use_clipper ) ;
ImGui : : Checkbox ( " Enable deletion " , & use_deletion ) ;
ImGui : : Checkbox ( " Enable drag & drop " , & use_drag_drop ) ;
ImGui : : Checkbox ( " Show in a table " , & show_in_table ) ;
ImGui : : Checkbox ( " Show color button " , & show_color_button ) ;
ImGui : : CheckboxFlags ( " ImGuiMultiSelectFlags_SingleSelect " , & flags , ImGuiMultiSelectFlags_SingleSelect ) ;
ImGui : : CheckboxFlags ( " ImGuiMultiSelectFlags_NoSelectAll " , & flags , ImGuiMultiSelectFlags_NoSelectAll ) ;
2024-01-04 18:41:20 +01:00
ImGui : : CheckboxFlags ( " ImGuiMultiSelectFlags_NoRangeSelect " , & flags , ImGuiMultiSelectFlags_NoRangeSelect ) ;
2024-03-07 16:26:22 +01:00
ImGui : : CheckboxFlags ( " ImGuiMultiSelectFlags_NoAutoSelect " , & flags , ImGuiMultiSelectFlags_NoAutoSelect ) ;
ImGui : : CheckboxFlags ( " ImGuiMultiSelectFlags_NoAutoClear " , & flags , ImGuiMultiSelectFlags_NoAutoClear ) ;
2024-06-28 11:55:22 +02:00
ImGui : : CheckboxFlags ( " ImGuiMultiSelectFlags_NoAutoClearOnReselect " , & flags , ImGuiMultiSelectFlags_NoAutoClearOnReselect ) ;
2024-05-31 21:57:10 +02:00
ImGui : : CheckboxFlags ( " ImGuiMultiSelectFlags_BoxSelect1d " , & flags , ImGuiMultiSelectFlags_BoxSelect1d ) ;
2024-06-26 20:26:06 +02:00
ImGui : : CheckboxFlags ( " ImGuiMultiSelectFlags_BoxSelect2d " , & flags , ImGuiMultiSelectFlags_BoxSelect2d ) ;
2023-12-21 15:12:17 +01:00
ImGui : : CheckboxFlags ( " ImGuiMultiSelectFlags_BoxSelectNoScroll " , & flags , ImGuiMultiSelectFlags_BoxSelectNoScroll ) ;
ImGui : : CheckboxFlags ( " ImGuiMultiSelectFlags_ClearOnEscape " , & flags , ImGuiMultiSelectFlags_ClearOnEscape ) ;
ImGui : : CheckboxFlags ( " ImGuiMultiSelectFlags_ClearOnClickVoid " , & flags , ImGuiMultiSelectFlags_ClearOnClickVoid ) ;
if ( ImGui : : CheckboxFlags ( " ImGuiMultiSelectFlags_ScopeWindow " , & flags , ImGuiMultiSelectFlags_ScopeWindow ) & & ( flags & ImGuiMultiSelectFlags_ScopeWindow ) )
flags & = ~ ImGuiMultiSelectFlags_ScopeRect ;
if ( ImGui : : CheckboxFlags ( " ImGuiMultiSelectFlags_ScopeRect " , & flags , ImGuiMultiSelectFlags_ScopeRect ) & & ( flags & ImGuiMultiSelectFlags_ScopeRect ) )
flags & = ~ ImGuiMultiSelectFlags_ScopeWindow ;
if ( ImGui : : CheckboxFlags ( " ImGuiMultiSelectFlags_SelectOnClick " , & flags , ImGuiMultiSelectFlags_SelectOnClick ) & & ( flags & ImGuiMultiSelectFlags_SelectOnClick ) )
flags & = ~ ImGuiMultiSelectFlags_SelectOnClickRelease ;
if ( ImGui : : CheckboxFlags ( " ImGuiMultiSelectFlags_SelectOnClickRelease " , & flags , ImGuiMultiSelectFlags_SelectOnClickRelease ) & & ( flags & ImGuiMultiSelectFlags_SelectOnClickRelease ) )
flags & = ~ ImGuiMultiSelectFlags_SelectOnClick ;
ImGui : : SameLine ( ) ; HelpMarker ( " Allow dragging an unselected item without altering selection. " ) ;
ImGui : : TreePop ( ) ;
}
2023-04-11 17:38:23 +02:00
2023-06-02 14:22:13 +02:00
// Initialize default list with 1000 items.
2023-10-06 17:10:52 +02:00
// Use default selection.Adapter: Pass index to SetNextItemSelectionUserData(), store index in Selection
2023-06-02 14:22:13 +02:00
static ImVector < int > items ;
static int items_next_id = 0 ;
if ( items_next_id = = 0 ) { for ( int n = 0 ; n < 1000 ; n + + ) { items . push_back ( items_next_id + + ) ; } }
2023-12-06 16:55:55 +01:00
static ExampleSelectionWithDeletion selection ;
static bool request_deletion_from_menu = false ; // Queue deletion triggered from context menu
2023-05-24 16:31:00 +02:00
2023-12-06 16:55:55 +01:00
ImGui : : Text ( " Selection size: %d/%d " , selection . Size , items . Size ) ;
2023-06-02 14:22:13 +02:00
const float items_height = ( widget_type = = WidgetType_TreeNode ) ? ImGui : : GetTextLineHeight ( ) : ImGui : : GetTextLineHeightWithSpacing ( ) ;
ImGui : : SetNextWindowContentSize ( ImVec2 ( 0.0f , items . Size * items_height ) ) ;
2024-03-07 15:52:30 +01:00
if ( ImGui : : BeginChild ( " ##Basket " , ImVec2 ( - FLT_MIN , ImGui : : GetFontSize ( ) * 20 ) , ImGuiChildFlags_FrameStyle | ImGuiChildFlags_ResizeY ) )
2019-02-01 12:22:57 +01:00
{
2023-05-24 16:31:00 +02:00
ImVec2 color_button_sz ( ImGui : : GetFontSize ( ) , ImGui : : GetFontSize ( ) ) ;
if ( widget_type = = WidgetType_TreeNode )
2024-08-22 13:46:54 +02:00
ImGui : : PushStyleVarY ( ImGuiStyleVar_ItemSpacing , 0.0f ) ;
2023-04-11 19:40:02 +02:00
2024-06-05 17:04:55 +02:00
ImGuiMultiSelectIO * ms_io = ImGui : : BeginMultiSelect ( flags , selection . Size , items . Size ) ;
selection . ApplyRequests ( ms_io ) ;
2023-06-02 14:22:13 +02:00
2024-05-23 18:56:31 +02:00
const bool want_delete = ( ImGui : : Shortcut ( ImGuiKey_Delete , ImGuiInputFlags_Repeat ) & & ( selection . Size > 0 ) ) | | request_deletion_from_menu ;
2023-12-06 16:55:55 +01:00
const int item_curr_idx_to_focus = want_delete ? selection . ApplyDeletionPreLoop ( ms_io , items . Size ) : - 1 ;
request_deletion_from_menu = false ;
2020-03-11 21:57:18 +01:00
2023-05-24 16:31:00 +02:00
if ( show_in_table )
2023-04-11 19:40:02 +02:00
{
2023-04-11 19:33:38 +02:00
if ( widget_type = = WidgetType_TreeNode )
ImGui : : PushStyleVar ( ImGuiStyleVar_CellPadding , ImVec2 ( 0.0f , 0.0f ) ) ;
2023-05-24 16:31:00 +02:00
ImGui : : BeginTable ( " ##Split " , 2 , ImGuiTableFlags_Resizable | ImGuiTableFlags_NoSavedSettings | ImGuiTableFlags_NoPadOuterX ) ;
ImGui : : TableSetupColumn ( " " , ImGuiTableColumnFlags_WidthStretch , 0.70f ) ;
ImGui : : TableSetupColumn ( " " , ImGuiTableColumnFlags_WidthStretch , 0.30f ) ;
2024-08-22 13:46:54 +02:00
//ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacingY, 0.0f);
2023-05-24 16:31:00 +02:00
}
2023-04-11 19:33:38 +02:00
2023-05-24 16:31:00 +02:00
ImGuiListClipper clipper ;
if ( use_clipper )
2023-06-02 14:34:22 +02:00
{
2023-06-02 14:22:13 +02:00
clipper . Begin ( items . Size ) ;
2023-08-28 16:33:30 +02:00
if ( item_curr_idx_to_focus ! = - 1 )
2023-12-06 16:55:55 +01:00
clipper . IncludeItemByIndex ( item_curr_idx_to_focus ) ; // Ensure focused item is not clipped.
2024-01-04 20:05:05 +01:00
if ( ms_io - > RangeSrcItem ! = - 1 )
2023-08-23 20:45:02 +02:00
clipper . IncludeItemByIndex ( ( int ) ms_io - > RangeSrcItem ) ; // Ensure RangeSrc item is not clipped.
2023-06-02 14:34:22 +02:00
}
2023-05-24 16:31:00 +02:00
while ( ! use_clipper | | clipper . Step ( ) )
{
const int item_begin = use_clipper ? clipper . DisplayStart : 0 ;
2023-06-02 14:22:13 +02:00
const int item_end = use_clipper ? clipper . DisplayEnd : items . Size ;
2023-05-24 16:31:00 +02:00
for ( int n = item_begin ; n < item_end ; n + + )
{
if ( show_in_table )
ImGui : : TableNextColumn ( ) ;
2023-04-11 19:33:38 +02:00
2023-06-02 14:22:13 +02:00
const int item_id = items [ n ] ;
2023-08-23 15:53:50 +02:00
const char * item_category = ExampleNames [ item_id % IM_ARRAYSIZE ( ExampleNames ) ] ;
2023-05-24 16:31:00 +02:00
char label [ 64 ] ;
2023-06-02 14:22:13 +02:00
sprintf ( label , " Object %05d: %s " , item_id , item_category ) ;
// IMPORTANT: for deletion refocus to work we need object ID to be stable,
// aka not depend on their index in the list. Here we use our persistent item_id
// instead of index to build a unique ID that will persist.
2023-08-31 15:50:01 +02:00
// (If we used PushID(index) instead, focus wouldn't be restored correctly after deletion).
2023-06-02 14:22:13 +02:00
ImGui : : PushID ( item_id ) ;
2023-04-11 19:33:38 +02:00
2023-05-24 16:31:00 +02:00
// Emit a color button, to test that Shift+LeftArrow landing on an item that is not part
2023-08-31 15:50:01 +02:00
// of the selection scope doesn't erroneously alter our selection.
2023-05-24 16:31:00 +02:00
if ( show_color_button )
{
2023-04-11 19:33:38 +02:00
ImU32 dummy_col = ( ImU32 ) ( ( unsigned int ) n * 0xC250B74B ) | IM_COL32_A_MASK ;
ImGui : : ColorButton ( " ## " , ImColor ( dummy_col ) , ImGuiColorEditFlags_NoTooltip , color_button_sz ) ;
ImGui : : SameLine ( ) ;
2023-05-24 16:31:00 +02:00
}
2023-04-11 19:33:38 +02:00
2023-08-31 15:50:01 +02:00
// Submit item
2023-08-28 17:36:59 +02:00
bool item_is_selected = selection . Contains ( ( ImGuiID ) n ) ;
2023-08-31 15:50:01 +02:00
bool item_is_open = false ;
2023-05-24 16:31:00 +02:00
ImGui : : SetNextItemSelectionUserData ( n ) ;
if ( widget_type = = WidgetType_Selectable )
{
2023-08-31 15:50:01 +02:00
ImGui : : Selectable ( label , item_is_selected , ImGuiSelectableFlags_None ) ;
2023-05-24 16:31:00 +02:00
}
else if ( widget_type = = WidgetType_TreeNode )
{
2023-08-31 15:50:01 +02:00
ImGuiTreeNodeFlags tree_node_flags = ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick ;
2023-05-24 16:31:00 +02:00
if ( item_is_selected )
tree_node_flags | = ImGuiTreeNodeFlags_Selected ;
2023-08-31 15:50:01 +02:00
item_is_open = ImGui : : TreeNodeEx ( label , tree_node_flags ) ;
}
// Focus (for after deletion)
if ( item_curr_idx_to_focus = = n )
ImGui : : SetKeyboardFocusHere ( - 1 ) ;
// Drag and Drop
if ( use_drag_drop & & ImGui : : BeginDragDropSource ( ) )
{
2024-06-11 17:14:00 +02:00
// Create payload with full selection OR single unselected item.
2023-09-25 17:21:19 +02:00
// (the later is only possible when using ImGuiMultiSelectFlags_SelectOnClickRelease)
2023-08-31 15:50:01 +02:00
if ( ImGui : : GetDragDropPayload ( ) = = NULL )
2023-04-11 19:33:38 +02:00
{
2023-08-31 15:50:01 +02:00
ImVector < int > payload_items ;
2024-06-11 17:14:00 +02:00
void * it = NULL ;
2024-06-26 17:00:52 +02:00
ImGuiID id = 0 ;
2023-08-31 15:50:01 +02:00
if ( ! item_is_selected )
payload_items . push_back ( item_id ) ;
else
2024-06-26 17:00:52 +02:00
while ( selection . GetNextSelectedItem ( & it , & id ) )
payload_items . push_back ( ( int ) id ) ;
2023-08-31 15:50:01 +02:00
ImGui : : SetDragDropPayload ( " MULTISELECT_DEMO_ITEMS " , payload_items . Data , ( size_t ) payload_items . size_in_bytes ( ) ) ;
2023-04-11 19:33:38 +02:00
}
2023-08-31 15:50:01 +02:00
// Display payload content in tooltip
const ImGuiPayload * payload = ImGui : : GetDragDropPayload ( ) ;
const int * payload_items = ( int * ) payload - > Data ;
2024-06-11 17:14:00 +02:00
const int payload_count = ( int ) payload - > DataSize / ( int ) sizeof ( int ) ;
2023-08-31 15:50:01 +02:00
if ( payload_count = = 1 )
ImGui : : Text ( " Object %05d: %s " , payload_items [ 0 ] , ExampleNames [ payload_items [ 0 ] % IM_ARRAYSIZE ( ExampleNames ) ] ) ;
else
ImGui : : Text ( " Dragging %d objects " , payload_count ) ;
ImGui : : EndDragDropSource ( ) ;
2023-05-24 16:31:00 +02:00
}
2020-08-20 20:46:57 +02:00
2023-08-31 15:50:01 +02:00
if ( widget_type = = WidgetType_TreeNode & & item_is_open )
ImGui : : TreePop ( ) ;
2023-05-24 16:31:00 +02:00
// Right-click: context menu
if ( ImGui : : BeginPopupContextItem ( ) )
{
2023-12-06 16:55:55 +01:00
ImGui : : BeginDisabled ( ! use_deletion | | selection . Size = = 0 ) ;
sprintf ( label , " Delete %d item(s)###DeleteSelected " , selection . Size ) ;
if ( ImGui : : Selectable ( label ) )
request_deletion_from_menu = true ;
2023-06-07 17:28:22 +02:00
ImGui : : EndDisabled ( ) ;
2023-05-24 16:31:00 +02:00
ImGui : : Selectable ( " Close " ) ;
ImGui : : EndPopup ( ) ;
}
2023-04-11 19:33:38 +02:00
2023-05-24 16:31:00 +02:00
// Demo content within a table
if ( show_in_table )
{
ImGui : : TableNextColumn ( ) ;
ImGui : : SetNextItemWidth ( - FLT_MIN ) ;
ImGui : : PushStyleVar ( ImGuiStyleVar_FramePadding , ImVec2 ( 0 , 0 ) ) ;
2023-06-02 14:22:13 +02:00
ImGui : : InputText ( " ###NoLabel " , ( char * ) ( void * ) item_category , strlen ( item_category ) , ImGuiInputTextFlags_ReadOnly ) ;
2023-05-24 16:31:00 +02:00
ImGui : : PopStyleVar ( ) ;
2020-03-20 12:34:52 +01:00
}
2023-05-24 16:31:00 +02:00
ImGui : : PopID ( ) ;
2019-02-01 12:22:57 +01:00
}
2023-05-24 16:31:00 +02:00
if ( ! use_clipper )
break ;
}
2023-04-11 19:33:38 +02:00
2023-05-24 16:31:00 +02:00
if ( show_in_table )
{
ImGui : : EndTable ( ) ;
2023-04-11 19:33:38 +02:00
if ( widget_type = = WidgetType_TreeNode )
ImGui : : PopStyleVar ( ) ;
2019-02-01 12:22:57 +01:00
}
2023-05-24 16:31:00 +02:00
// Apply multi-select requests
ms_io = ImGui : : EndMultiSelect ( ) ;
2024-06-05 17:04:55 +02:00
selection . ApplyRequests ( ms_io ) ;
2023-06-02 14:22:13 +02:00
if ( want_delete )
2023-10-06 17:10:52 +02:00
selection . ApplyDeletionPostLoop ( ms_io , items , item_curr_idx_to_focus ) ;
2023-05-24 16:31:00 +02:00
if ( widget_type = = WidgetType_TreeNode )
ImGui : : PopStyleVar ( ) ;
}
2024-03-07 15:52:30 +01:00
ImGui : : EndChild ( ) ;
2019-02-01 12:22:57 +01:00
ImGui : : TreePop ( ) ;
}
ImGui : : TreePop ( ) ;
}
}
2024-07-19 12:35:57 +02:00
//-----------------------------------------------------------------------------
// [SECTION] ShowDemoWindowLayout()
//-----------------------------------------------------------------------------
2018-10-25 23:34:05 +02:00
static void ShowDemoWindowLayout ( )
{
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Layout " ) ;
2020-08-05 17:10:06 +02:00
if ( ! ImGui : : CollapsingHeader ( " Layout & Scrolling " ) )
2018-10-25 23:40:33 +02:00
return ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Layout/Child windows " ) ;
2018-12-19 15:19:31 +01:00
if ( ImGui : : TreeNode ( " Child windows " ) )
2015-07-22 01:00:28 +02:00
{
2023-02-10 12:16:23 +01:00
ImGui : : SeparatorText ( " Child windows " ) ;
2019-03-06 18:19:28 +01:00
HelpMarker ( " Use child windows to begin into a self-contained independent scrolling/clipping regions within a host window. " ) ;
2018-10-25 23:40:33 +02:00
static bool disable_mouse_wheel = false ;
static bool disable_menu = false ;
ImGui : : Checkbox ( " Disable Mouse Wheel " , & disable_mouse_wheel ) ;
ImGui : : Checkbox ( " Disable Menu " , & disable_menu ) ;
// Child 1: no border, enable horizontal scrollbar
2015-07-22 01:00:28 +02:00
{
2020-05-05 19:39:24 +02:00
ImGuiWindowFlags window_flags = ImGuiWindowFlags_HorizontalScrollbar ;
if ( disable_mouse_wheel )
window_flags | = ImGuiWindowFlags_NoScrollWithMouse ;
2023-10-18 18:50:19 +02:00
ImGui : : BeginChild ( " ChildL " , ImVec2 ( ImGui : : GetContentRegionAvail ( ) . x * 0.5f , 260 ) , ImGuiChildFlags_None , window_flags ) ;
2018-10-25 23:40:33 +02:00
for ( int i = 0 ; i < 100 ; i + + )
ImGui : : Text ( " %04d: scrollable region " , i ) ;
ImGui : : EndChild ( ) ;
}
2015-07-22 01:00:28 +02:00
2018-10-25 23:40:33 +02:00
ImGui : : SameLine ( ) ;
2015-07-22 01:00:28 +02:00
2018-10-25 23:40:33 +02:00
// Child 2: rounded border
{
2020-05-05 19:39:24 +02:00
ImGuiWindowFlags window_flags = ImGuiWindowFlags_None ;
if ( disable_mouse_wheel )
window_flags | = ImGuiWindowFlags_NoScrollWithMouse ;
if ( ! disable_menu )
window_flags | = ImGuiWindowFlags_MenuBar ;
2018-10-25 23:40:33 +02:00
ImGui : : PushStyleVar ( ImGuiStyleVar_ChildRounding , 5.0f ) ;
2024-08-23 15:24:22 +02:00
ImGui : : BeginChild ( " ChildR " , ImVec2 ( 0 , 260 ) , ImGuiChildFlags_Borders , window_flags ) ;
2018-10-25 23:40:33 +02:00
if ( ! disable_menu & & ImGui : : BeginMenuBar ( ) )
2015-07-22 01:00:28 +02:00
{
2018-10-25 23:40:33 +02:00
if ( ImGui : : BeginMenu ( " Menu " ) )
2018-01-31 19:13:20 +01:00
{
2018-10-25 23:40:33 +02:00
ShowExampleMenuFile ( ) ;
ImGui : : EndMenu ( ) ;
2018-01-11 15:22:33 +01:00
}
2018-10-25 23:40:33 +02:00
ImGui : : EndMenuBar ( ) ;
2015-07-22 01:00:28 +02:00
}
2020-10-26 18:28:49 +01:00
if ( ImGui : : BeginTable ( " split " , 2 , ImGuiTableFlags_Resizable | ImGuiTableFlags_NoSavedSettings ) )
2018-10-25 23:40:33 +02:00
{
2020-10-26 18:28:49 +01:00
for ( int i = 0 ; i < 100 ; i + + )
{
char buf [ 32 ] ;
sprintf ( buf , " %03d " , i ) ;
ImGui : : TableNextColumn ( ) ;
ImGui : : Button ( buf , ImVec2 ( - FLT_MIN , 0.0f ) ) ;
}
ImGui : : EndTable ( ) ;
2018-10-25 23:40:33 +02:00
}
ImGui : : EndChild ( ) ;
ImGui : : PopStyleVar ( ) ;
2015-07-22 01:00:28 +02:00
}
2023-10-19 18:36:57 +02:00
// Child 3: manual-resize
ImGui : : SeparatorText ( " Manual-resize " ) ;
{
HelpMarker ( " Drag bottom border to resize. Double-click bottom border to auto-fit to vertical contents. " ) ;
2024-09-26 14:58:56 +02:00
//if (ImGui::Button("Set Height to 200"))
// ImGui::SetNextWindowSize(ImVec2(-FLT_MIN, 200.0f));
2023-10-19 18:36:57 +02:00
ImGui : : PushStyleColor ( ImGuiCol_ChildBg , ImGui : : GetStyleColorVec4 ( ImGuiCol_FrameBg ) ) ;
2024-08-23 15:24:22 +02:00
if ( ImGui : : BeginChild ( " ResizableChild " , ImVec2 ( - FLT_MIN , ImGui : : GetTextLineHeightWithSpacing ( ) * 8 ) , ImGuiChildFlags_Borders | ImGuiChildFlags_ResizeY ) )
2023-11-06 15:35:31 +01:00
for ( int n = 0 ; n < 10 ; n + + )
ImGui : : Text ( " Line %04d " , n ) ;
2023-10-19 18:36:57 +02:00
ImGui : : PopStyleColor ( ) ;
ImGui : : EndChild ( ) ;
}
2023-10-17 17:39:56 +02:00
// Child 4: auto-resizing height with a limit
ImGui : : SeparatorText ( " Auto-resize with constraints " ) ;
{
static int draw_lines = 3 ;
static int max_height_in_lines = 10 ;
ImGui : : SetNextItemWidth ( ImGui : : GetFontSize ( ) * 8 ) ;
ImGui : : DragInt ( " Lines Count " , & draw_lines , 0.2f ) ;
ImGui : : SetNextItemWidth ( ImGui : : GetFontSize ( ) * 8 ) ;
ImGui : : DragInt ( " Max Height (in Lines) " , & max_height_in_lines , 0.2f ) ;
ImGui : : SetNextWindowSizeConstraints ( ImVec2 ( 0.0f , ImGui : : GetTextLineHeightWithSpacing ( ) * 1 ) , ImVec2 ( FLT_MAX , ImGui : : GetTextLineHeightWithSpacing ( ) * max_height_in_lines ) ) ;
2024-08-23 15:24:22 +02:00
if ( ImGui : : BeginChild ( " ConstrainedChild " , ImVec2 ( - FLT_MIN , 0.0f ) , ImGuiChildFlags_Borders | ImGuiChildFlags_AutoResizeY ) )
2023-10-17 17:39:56 +02:00
for ( int n = 0 ; n < draw_lines ; n + + )
ImGui : : Text ( " Line %04d " , n ) ;
ImGui : : EndChild ( ) ;
}
2023-02-10 12:16:23 +01:00
ImGui : : SeparatorText ( " Misc/Advanced " ) ;
2018-12-19 15:19:31 +01:00
// Demonstrate a few extra things
// - Changing ImGuiCol_ChildBg (which is transparent black in default styles)
2020-05-05 19:39:24 +02:00
// - Using SetCursorPos() to position child window (the child window is an item from the POV of parent window)
// You can also call SetNextWindowPos() to position the child window. The parent window will effectively
// layout from this position.
// - Using ImGui::GetItemRectMin/Max() to query the "item" state (because the child window is an item from
2021-07-19 19:21:18 +02:00
// the POV of the parent window). See 'Demo->Querying Status (Edited/Active/Hovered etc.)' for details.
2018-12-19 15:19:31 +01:00
{
2020-07-16 17:20:24 +02:00
static int offset_x = 0 ;
2023-10-19 18:36:57 +02:00
static bool override_bg_color = true ;
2024-08-23 15:24:22 +02:00
static ImGuiChildFlags child_flags = ImGuiChildFlags_Borders | ImGuiChildFlags_ResizeX | ImGuiChildFlags_ResizeY ;
2021-05-24 12:49:58 +02:00
ImGui : : SetNextItemWidth ( ImGui : : GetFontSize ( ) * 8 ) ;
2020-07-16 17:20:24 +02:00
ImGui : : DragInt ( " Offset X " , & offset_x , 1.0f , - 1000 , 1000 ) ;
2023-10-19 18:36:57 +02:00
ImGui : : Checkbox ( " Override ChildBg color " , & override_bg_color ) ;
2024-08-23 15:24:22 +02:00
ImGui : : CheckboxFlags ( " ImGuiChildFlags_Borders " , & child_flags , ImGuiChildFlags_Borders ) ;
2023-10-19 18:36:57 +02:00
ImGui : : CheckboxFlags ( " ImGuiChildFlags_AlwaysUseWindowPadding " , & child_flags , ImGuiChildFlags_AlwaysUseWindowPadding ) ;
ImGui : : CheckboxFlags ( " ImGuiChildFlags_ResizeX " , & child_flags , ImGuiChildFlags_ResizeX ) ;
ImGui : : CheckboxFlags ( " ImGuiChildFlags_ResizeY " , & child_flags , ImGuiChildFlags_ResizeY ) ;
2023-11-07 18:28:03 +01:00
ImGui : : CheckboxFlags ( " ImGuiChildFlags_FrameStyle " , & child_flags , ImGuiChildFlags_FrameStyle ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Style the child window like a framed item: use FrameBg, FrameRounding, FrameBorderSize, FramePadding instead of ChildBg, ChildRounding, ChildBorderSize, WindowPadding. " ) ;
if ( child_flags & ImGuiChildFlags_FrameStyle )
override_bg_color = false ;
2020-07-16 17:20:24 +02:00
ImGui : : SetCursorPosX ( ImGui : : GetCursorPosX ( ) + ( float ) offset_x ) ;
2023-10-19 18:36:57 +02:00
if ( override_bg_color )
ImGui : : PushStyleColor ( ImGuiCol_ChildBg , IM_COL32 ( 255 , 0 , 0 , 100 ) ) ;
ImGui : : BeginChild ( " Red " , ImVec2 ( 200 , 100 ) , child_flags , ImGuiWindowFlags_None ) ;
if ( override_bg_color )
ImGui : : PopStyleColor ( ) ;
2023-10-18 18:50:19 +02:00
2018-12-19 15:19:31 +01:00
for ( int n = 0 ; n < 50 ; n + + )
ImGui : : Text ( " Some test %d " , n ) ;
ImGui : : EndChild ( ) ;
2020-07-16 17:20:24 +02:00
bool child_is_hovered = ImGui : : IsItemHovered ( ) ;
2018-12-19 15:19:31 +01:00
ImVec2 child_rect_min = ImGui : : GetItemRectMin ( ) ;
ImVec2 child_rect_max = ImGui : : GetItemRectMax ( ) ;
2020-07-16 17:20:24 +02:00
ImGui : : Text ( " Hovered: %d " , child_is_hovered ) ;
2018-12-19 15:19:31 +01:00
ImGui : : Text ( " Rect of child window is: (%.0f,%.0f) (%.0f,%.0f) " , child_rect_min . x , child_rect_min . y , child_rect_max . x , child_rect_max . y ) ;
}
2018-10-25 23:40:33 +02:00
ImGui : : TreePop ( ) ;
}
2015-08-30 16:35:59 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Layout/Widgets Width " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Widgets Width " ) )
{
2021-05-24 12:49:58 +02:00
static float f = 0.0f ;
static bool show_indented_items = true ;
ImGui : : Checkbox ( " Show indented items " , & show_indented_items ) ;
2019-04-18 18:29:28 +02:00
// Use SetNextItemWidth() to set the width of a single upcoming item.
// Use PushItemWidth()/PopItemWidth() to set the width of a group of items.
2020-05-05 19:39:24 +02:00
// In real code use you'll probably want to choose width values that are proportional to your font size
// e.g. Using '20.0f * GetFontSize()' as width instead of '200.0f', etc.
2019-04-18 18:29:28 +02:00
ImGui : : Text ( " SetNextItemWidth/PushItemWidth(100) " ) ;
2019-03-06 18:19:28 +01:00
ImGui : : SameLine ( ) ; HelpMarker ( " Fixed width. " ) ;
2020-11-20 17:24:18 +01:00
ImGui : : PushItemWidth ( 100 ) ;
ImGui : : DragFloat ( " float##1b " , & f ) ;
if ( show_indented_items )
{
ImGui : : Indent ( ) ;
ImGui : : DragFloat ( " float (indented)##1b " , & f ) ;
ImGui : : Unindent ( ) ;
}
ImGui : : PopItemWidth ( ) ;
2018-10-25 23:40:33 +02:00
2020-11-20 17:24:18 +01:00
ImGui : : Text ( " SetNextItemWidth/PushItemWidth(-100) " ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Align to right edge minus 100 " ) ;
ImGui : : PushItemWidth ( - 100 ) ;
ImGui : : DragFloat ( " float##2a " , & f ) ;
if ( show_indented_items )
{
ImGui : : Indent ( ) ;
ImGui : : DragFloat ( " float (indented)##2b " , & f ) ;
ImGui : : Unindent ( ) ;
}
ImGui : : PopItemWidth ( ) ;
2018-10-25 23:40:33 +02:00
2019-04-29 18:31:51 +02:00
ImGui : : Text ( " SetNextItemWidth/PushItemWidth(GetContentRegionAvail().x * 0.5f) " ) ;
2019-03-06 18:19:28 +01:00
ImGui : : SameLine ( ) ; HelpMarker ( " Half of available width. \n (~ right-cursor_pos) \n (works within a column set) " ) ;
2020-11-20 17:24:18 +01:00
ImGui : : PushItemWidth ( ImGui : : GetContentRegionAvail ( ) . x * 0.5f ) ;
ImGui : : DragFloat ( " float##3a " , & f ) ;
if ( show_indented_items )
{
ImGui : : Indent ( ) ;
ImGui : : DragFloat ( " float (indented)##3b " , & f ) ;
ImGui : : Unindent ( ) ;
}
ImGui : : PopItemWidth ( ) ;
2018-10-25 23:40:33 +02:00
2020-11-20 17:24:18 +01:00
ImGui : : Text ( " SetNextItemWidth/PushItemWidth(-GetContentRegionAvail().x * 0.5f) " ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Align to right edge minus half " ) ;
ImGui : : PushItemWidth ( - ImGui : : GetContentRegionAvail ( ) . x * 0.5f ) ;
ImGui : : DragFloat ( " float##4a " , & f ) ;
if ( show_indented_items )
{
ImGui : : Indent ( ) ;
ImGui : : DragFloat ( " float (indented)##4b " , & f ) ;
ImGui : : Unindent ( ) ;
}
ImGui : : PopItemWidth ( ) ;
2018-10-25 23:40:33 +02:00
2020-05-05 19:39:24 +02:00
// Demonstrate using PushItemWidth to surround three items.
// Calling SetNextItemWidth() before each of them would have the same effect.
2020-11-20 17:24:18 +01:00
ImGui : : Text ( " SetNextItemWidth/PushItemWidth(-FLT_MIN) " ) ;
2019-03-06 18:19:28 +01:00
ImGui : : SameLine ( ) ; HelpMarker ( " Align to right edge " ) ;
2020-11-20 17:24:18 +01:00
ImGui : : PushItemWidth ( - FLT_MIN ) ;
2019-07-26 21:08:29 +02:00
ImGui : : DragFloat ( " ##float5a " , & f ) ;
2020-11-20 17:24:18 +01:00
if ( show_indented_items )
{
ImGui : : Indent ( ) ;
ImGui : : DragFloat ( " float (indented)##5b " , & f ) ;
ImGui : : Unindent ( ) ;
}
2018-10-25 23:40:33 +02:00
ImGui : : PopItemWidth ( ) ;
ImGui : : TreePop ( ) ;
}
2016-01-06 01:24:49 +01:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Layout/Basic Horizontal Layout " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Basic Horizontal Layout " ) )
{
ImGui : : TextWrapped ( " (Use ImGui::SameLine() to keep adding items to the right of the preceding item) " ) ;
// Text
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Layout/Basic Horizontal Layout/SameLine " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : Text ( " Two items: Hello " ) ; ImGui : : SameLine ( ) ;
2023-07-05 14:19:01 +02:00
ImGui : : TextColored ( ImVec4 ( 1 , 1 , 0 , 1 ) , " Sailor " ) ;
2018-10-25 23:40:33 +02:00
// Adjust spacing
ImGui : : Text ( " More spacing: Hello " ) ; ImGui : : SameLine ( 0 , 20 ) ;
2023-07-05 14:19:01 +02:00
ImGui : : TextColored ( ImVec4 ( 1 , 1 , 0 , 1 ) , " Sailor " ) ;
2018-10-25 23:40:33 +02:00
// Button
ImGui : : AlignTextToFramePadding ( ) ;
ImGui : : Text ( " Normal buttons " ) ; ImGui : : SameLine ( ) ;
ImGui : : Button ( " Banana " ) ; ImGui : : SameLine ( ) ;
ImGui : : Button ( " Apple " ) ; ImGui : : SameLine ( ) ;
ImGui : : Button ( " Corniflower " ) ;
// Button
ImGui : : Text ( " Small buttons " ) ; ImGui : : SameLine ( ) ;
ImGui : : SmallButton ( " Like this one " ) ; ImGui : : SameLine ( ) ;
ImGui : : Text ( " can fit within a text block. " ) ;
// Aligned to arbitrary position. Easy/cheap column.
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Layout/Basic Horizontal Layout/SameLine (with offset) " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : Text ( " Aligned " ) ;
ImGui : : SameLine ( 150 ) ; ImGui : : Text ( " x=150 " ) ;
ImGui : : SameLine ( 300 ) ; ImGui : : Text ( " x=300 " ) ;
ImGui : : Text ( " Aligned " ) ;
ImGui : : SameLine ( 150 ) ; ImGui : : SmallButton ( " x=150 " ) ;
ImGui : : SameLine ( 300 ) ; ImGui : : SmallButton ( " x=300 " ) ;
// Checkbox
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Layout/Basic Horizontal Layout/SameLine (more) " ) ;
2018-10-25 23:40:33 +02:00
static bool c1 = false , c2 = false , c3 = false , c4 = false ;
ImGui : : Checkbox ( " My " , & c1 ) ; ImGui : : SameLine ( ) ;
ImGui : : Checkbox ( " Tailor " , & c2 ) ; ImGui : : SameLine ( ) ;
ImGui : : Checkbox ( " Is " , & c3 ) ; ImGui : : SameLine ( ) ;
ImGui : : Checkbox ( " Rich " , & c4 ) ;
// Various
static float f0 = 1.0f , f1 = 2.0f , f2 = 3.0f ;
ImGui : : PushItemWidth ( 80 ) ;
const char * items [ ] = { " AAAA " , " BBBB " , " CCCC " , " DDDD " } ;
static int item = - 1 ;
ImGui : : Combo ( " Combo " , & item , items , IM_ARRAYSIZE ( items ) ) ; ImGui : : SameLine ( ) ;
ImGui : : SliderFloat ( " X " , & f0 , 0.0f , 5.0f ) ; ImGui : : SameLine ( ) ;
ImGui : : SliderFloat ( " Y " , & f1 , 0.0f , 5.0f ) ; ImGui : : SameLine ( ) ;
ImGui : : SliderFloat ( " Z " , & f2 , 0.0f , 5.0f ) ;
ImGui : : PopItemWidth ( ) ;
ImGui : : PushItemWidth ( 80 ) ;
ImGui : : Text ( " Lists: " ) ;
static int selection [ 4 ] = { 0 , 1 , 2 , 3 } ;
for ( int i = 0 ; i < 4 ; i + + )
{
if ( i > 0 ) ImGui : : SameLine ( ) ;
ImGui : : PushID ( i ) ;
ImGui : : ListBox ( " " , & selection [ i ] , items , IM_ARRAYSIZE ( items ) ) ;
ImGui : : PopID ( ) ;
2023-06-16 16:42:56 +02:00
//ImGui::SetItemTooltip("ListBox %d hovered", i);
2015-07-22 01:00:28 +02:00
}
2018-10-25 23:40:33 +02:00
ImGui : : PopItemWidth ( ) ;
// Dummy
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Layout/Basic Horizontal Layout/Dummy " ) ;
2018-10-25 23:40:33 +02:00
ImVec2 button_sz ( 40 , 40 ) ;
ImGui : : Button ( " A " , button_sz ) ; ImGui : : SameLine ( ) ;
ImGui : : Dummy ( button_sz ) ; ImGui : : SameLine ( ) ;
ImGui : : Button ( " B " , button_sz ) ;
2020-05-05 19:39:24 +02:00
// Manually wrapping
// (we should eventually provide this as an automatic layout feature, but for now you can do it manually)
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Layout/Basic Horizontal Layout/Manual wrapping " ) ;
ImGui : : Text ( " Manual wrapping: " ) ;
2018-10-25 23:40:33 +02:00
ImGuiStyle & style = ImGui : : GetStyle ( ) ;
int buttons_count = 20 ;
2024-07-25 15:50:30 +02:00
float window_visible_x2 = ImGui : : GetCursorScreenPos ( ) . x + ImGui : : GetContentRegionAvail ( ) . x ;
2018-10-25 23:40:33 +02:00
for ( int n = 0 ; n < buttons_count ; n + + )
{
ImGui : : PushID ( n ) ;
ImGui : : Button ( " Box " , button_sz ) ;
float last_button_x2 = ImGui : : GetItemRectMax ( ) . x ;
float next_button_x2 = last_button_x2 + style . ItemSpacing . x + button_sz . x ; // Expected position if next button was on same line
if ( n + 1 < buttons_count & & next_button_x2 < window_visible_x2 )
ImGui : : SameLine ( ) ;
ImGui : : PopID ( ) ;
2015-07-22 01:00:28 +02:00
}
2018-10-25 23:40:33 +02:00
ImGui : : TreePop ( ) ;
}
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Layout/Groups " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Groups " ) )
{
2020-05-05 19:39:24 +02:00
HelpMarker (
" BeginGroup() basically locks the horizontal position for new line. "
" EndGroup() bundles the whole group so that you can use \" item \" functions such as "
" IsItemHovered()/IsItemActive() or SameLine() etc. on the whole group. " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : BeginGroup ( ) ;
2015-07-22 01:00:28 +02:00
{
ImGui : : BeginGroup ( ) ;
2018-10-25 23:40:33 +02:00
ImGui : : Button ( " AAA " ) ;
2015-07-22 01:00:28 +02:00
ImGui : : SameLine ( ) ;
2018-10-25 23:40:33 +02:00
ImGui : : Button ( " BBB " ) ;
2015-07-22 01:00:28 +02:00
ImGui : : SameLine ( ) ;
2018-10-25 23:40:33 +02:00
ImGui : : BeginGroup ( ) ;
ImGui : : Button ( " CCC " ) ;
ImGui : : Button ( " DDD " ) ;
ImGui : : EndGroup ( ) ;
2015-07-22 01:00:28 +02:00
ImGui : : SameLine ( ) ;
2018-10-25 23:40:33 +02:00
ImGui : : Button ( " EEE " ) ;
ImGui : : EndGroup ( ) ;
2023-06-16 16:42:56 +02:00
ImGui : : SetItemTooltip ( " First group hovered " ) ;
2015-07-22 01:00:28 +02:00
}
2018-10-25 23:40:33 +02:00
// Capture the group size and create widgets using the same size
ImVec2 size = ImGui : : GetItemRectSize ( ) ;
const float values [ 5 ] = { 0.5f , 0.20f , 0.80f , 0.60f , 0.25f } ;
ImGui : : PlotHistogram ( " ##values " , values , IM_ARRAYSIZE ( values ) , 0 , NULL , 0.0f , 1.0f , size ) ;
2015-07-22 01:00:28 +02:00
2020-05-05 19:39:24 +02:00
ImGui : : Button ( " ACTION " , ImVec2 ( ( size . x - ImGui : : GetStyle ( ) . ItemSpacing . x ) * 0.5f , size . y ) ) ;
2018-10-25 23:40:33 +02:00
ImGui : : SameLine ( ) ;
2020-05-05 19:39:24 +02:00
ImGui : : Button ( " REACTION " , ImVec2 ( ( size . x - ImGui : : GetStyle ( ) . ItemSpacing . x ) * 0.5f , size . y ) ) ;
2018-10-25 23:40:33 +02:00
ImGui : : EndGroup ( ) ;
ImGui : : SameLine ( ) ;
2015-07-22 01:00:28 +02:00
2018-10-25 23:40:33 +02:00
ImGui : : Button ( " LEVERAGE \n BUZZWORD " , size ) ;
ImGui : : SameLine ( ) ;
2015-07-22 01:00:28 +02:00
2021-02-03 16:30:23 +01:00
if ( ImGui : : BeginListBox ( " List " , size ) )
2018-10-25 23:40:33 +02:00
{
ImGui : : Selectable ( " Selected " , true ) ;
ImGui : : Selectable ( " Not Selected " , false ) ;
2021-02-03 16:30:23 +01:00
ImGui : : EndListBox ( ) ;
2018-10-25 23:40:33 +02:00
}
2015-12-14 00:41:02 +01:00
2018-10-25 23:40:33 +02:00
ImGui : : TreePop ( ) ;
}
2015-12-14 00:41:02 +01:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Layout/Text Baseline Alignment " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Text Baseline Alignment " ) )
{
2019-10-03 16:57:14 +02:00
{
ImGui : : BulletText ( " Text baseline: " ) ;
2020-05-05 19:39:24 +02:00
ImGui : : SameLine ( ) ; HelpMarker (
" This is testing the vertical alignment that gets applied on text to keep it aligned with widgets. "
" Lines only composed of text or \" small \" widgets use less vertical space than lines with framed widgets. " ) ;
2019-10-03 16:57:14 +02:00
ImGui : : Indent ( ) ;
2018-10-25 23:40:33 +02:00
2019-10-03 16:57:14 +02:00
ImGui : : Text ( " KO Blahblah " ) ; ImGui : : SameLine ( ) ;
ImGui : : Button ( " Some framed item " ) ; ImGui : : SameLine ( ) ;
HelpMarker ( " Baseline of button will look misaligned with text.. " ) ;
// If your line starts with text, call AlignTextToFramePadding() to align text to upcoming widgets.
2020-05-05 19:39:24 +02:00
// (because we don't know what's coming after the Text() statement, we need to move the text baseline
// down by FramePadding.y ahead of time)
2019-10-03 16:57:14 +02:00
ImGui : : AlignTextToFramePadding ( ) ;
ImGui : : Text ( " OK Blahblah " ) ; ImGui : : SameLine ( ) ;
2024-09-09 21:07:10 +02:00
ImGui : : Button ( " Some framed item##2 " ) ; ImGui : : SameLine ( ) ;
2019-10-03 16:57:14 +02:00
HelpMarker ( " We call AlignTextToFramePadding() to vertically align the text baseline by +FramePadding.y " ) ;
// SmallButton() uses the same vertical padding as Text
ImGui : : Button ( " TEST##1 " ) ; ImGui : : SameLine ( ) ;
ImGui : : Text ( " TEST " ) ; ImGui : : SameLine ( ) ;
ImGui : : SmallButton ( " TEST##2 " ) ;
// If your line starts with text, call AlignTextToFramePadding() to align text to upcoming widgets.
ImGui : : AlignTextToFramePadding ( ) ;
ImGui : : Text ( " Text aligned to framed item " ) ; ImGui : : SameLine ( ) ;
ImGui : : Button ( " Item##1 " ) ; ImGui : : SameLine ( ) ;
ImGui : : Text ( " Item " ) ; ImGui : : SameLine ( ) ;
ImGui : : SmallButton ( " Item##2 " ) ; ImGui : : SameLine ( ) ;
ImGui : : Button ( " Item##3 " ) ;
2018-10-25 23:40:33 +02:00
2019-10-03 16:57:14 +02:00
ImGui : : Unindent ( ) ;
}
2018-10-25 23:40:33 +02:00
2019-10-03 16:57:14 +02:00
ImGui : : Spacing ( ) ;
{
ImGui : : BulletText ( " Multi-line text: " ) ;
ImGui : : Indent ( ) ;
ImGui : : Text ( " One \n Two \n Three " ) ; ImGui : : SameLine ( ) ;
ImGui : : Text ( " Hello \n World " ) ; ImGui : : SameLine ( ) ;
ImGui : : Text ( " Banana " ) ;
ImGui : : Text ( " Banana " ) ; ImGui : : SameLine ( ) ;
ImGui : : Text ( " Hello \n World " ) ; ImGui : : SameLine ( ) ;
ImGui : : Text ( " One \n Two \n Three " ) ;
ImGui : : Button ( " HOP##1 " ) ; ImGui : : SameLine ( ) ;
ImGui : : Text ( " Banana " ) ; ImGui : : SameLine ( ) ;
ImGui : : Text ( " Hello \n World " ) ; ImGui : : SameLine ( ) ;
ImGui : : Text ( " Banana " ) ;
ImGui : : Button ( " HOP##2 " ) ; ImGui : : SameLine ( ) ;
ImGui : : Text ( " Hello \n World " ) ; ImGui : : SameLine ( ) ;
ImGui : : Text ( " Banana " ) ;
ImGui : : Unindent ( ) ;
}
ImGui : : Spacing ( ) ;
{
ImGui : : BulletText ( " Misc items: " ) ;
ImGui : : Indent ( ) ;
2020-05-05 19:39:24 +02:00
// SmallButton() sets FramePadding to zero. Text baseline is aligned to match baseline of previous Button.
2019-10-03 16:57:14 +02:00
ImGui : : Button ( " 80x80 " , ImVec2 ( 80 , 80 ) ) ;
ImGui : : SameLine ( ) ;
ImGui : : Button ( " 50x50 " , ImVec2 ( 50 , 50 ) ) ;
ImGui : : SameLine ( ) ;
ImGui : : Button ( " Button() " ) ;
ImGui : : SameLine ( ) ;
ImGui : : SmallButton ( " SmallButton() " ) ;
// Tree
const float spacing = ImGui : : GetStyle ( ) . ItemInnerSpacing . x ;
ImGui : : Button ( " Button##1 " ) ;
ImGui : : SameLine ( 0.0f , spacing ) ;
2020-05-05 19:39:24 +02:00
if ( ImGui : : TreeNode ( " Node##1 " ) )
{
2020-08-03 21:19:12 +02:00
// Placeholder tree data
2020-05-05 19:39:24 +02:00
for ( int i = 0 ; i < 6 ; i + + )
ImGui : : BulletText ( " Item %d.. " , i ) ;
ImGui : : TreePop ( ) ;
}
// Vertically align text node a bit lower so it'll be vertically centered with upcoming widget.
// Otherwise you can use SmallButton() (smaller fit).
ImGui : : AlignTextToFramePadding ( ) ;
2019-10-03 16:57:14 +02:00
2020-05-05 19:39:24 +02:00
// Common mistake to avoid: if we want to SameLine after TreeNode we need to do it before we add
2020-05-07 11:38:45 +02:00
// other contents below the node.
2020-05-05 19:39:24 +02:00
bool node_open = ImGui : : TreeNode ( " Node##2 " ) ;
2019-10-03 16:57:14 +02:00
ImGui : : SameLine ( 0.0f , spacing ) ; ImGui : : Button ( " Button##2 " ) ;
2020-05-05 19:39:24 +02:00
if ( node_open )
{
2020-08-03 21:19:12 +02:00
// Placeholder tree data
2020-05-05 19:39:24 +02:00
for ( int i = 0 ; i < 6 ; i + + )
ImGui : : BulletText ( " Item %d.. " , i ) ;
ImGui : : TreePop ( ) ;
}
2019-10-03 16:57:14 +02:00
// Bullet
ImGui : : Button ( " Button##3 " ) ;
ImGui : : SameLine ( 0.0f , spacing ) ;
ImGui : : BulletText ( " Bullet text " ) ;
ImGui : : AlignTextToFramePadding ( ) ;
ImGui : : BulletText ( " Node " ) ;
ImGui : : SameLine ( 0.0f , spacing ) ; ImGui : : Button ( " Button##4 " ) ;
ImGui : : Unindent ( ) ;
}
2018-10-25 23:40:33 +02:00
ImGui : : TreePop ( ) ;
}
2015-07-22 01:00:28 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Layout/Scrolling " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Scrolling " ) )
{
2019-07-01 12:15:36 +02:00
// Vertical scroll functions
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Layout/Scrolling/Vertical " ) ;
2019-07-01 12:15:36 +02:00
HelpMarker ( " Use SetScrollHereY() or SetScrollFromPosY() to scroll to a given vertical position. " ) ;
2018-12-19 15:19:31 +01:00
2019-07-01 12:15:36 +02:00
static int track_item = 50 ;
2019-07-31 03:21:44 +02:00
static bool enable_track = true ;
2019-07-31 19:26:10 +02:00
static bool enable_extra_decorations = false ;
2019-06-04 16:22:47 +02:00
static float scroll_to_off_px = 0.0f ;
static float scroll_to_pos_px = 200.0f ;
2019-07-31 19:26:10 +02:00
ImGui : : Checkbox ( " Decoration " , & enable_extra_decorations ) ;
2019-07-31 03:21:44 +02:00
ImGui : : Checkbox ( " Track " , & enable_track ) ;
2018-10-25 23:40:33 +02:00
ImGui : : PushItemWidth ( 100 ) ;
2019-07-31 03:21:44 +02:00
ImGui : : SameLine ( 140 ) ; enable_track | = ImGui : : DragInt ( " ##item " , & track_item , 0.25f , 0 , 99 , " Item = %d " ) ;
2019-06-04 16:22:47 +02:00
bool scroll_to_off = ImGui : : Button ( " Scroll Offset " ) ;
2019-12-13 11:56:51 +01:00
ImGui : : SameLine ( 140 ) ; scroll_to_off | = ImGui : : DragFloat ( " ##off " , & scroll_to_off_px , 1.00f , 0 , FLT_MAX , " +%.0f px " ) ;
2019-06-04 16:22:47 +02:00
bool scroll_to_pos = ImGui : : Button ( " Scroll To Pos " ) ;
2019-12-13 11:56:51 +01:00
ImGui : : SameLine ( 140 ) ; scroll_to_pos | = ImGui : : DragFloat ( " ##pos " , & scroll_to_pos_px , 1.00f , - 10 , FLT_MAX , " X/Y = %.0f px " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : PopItemWidth ( ) ;
2019-07-31 03:21:44 +02:00
2019-06-04 16:22:47 +02:00
if ( scroll_to_off | | scroll_to_pos )
2019-07-31 03:21:44 +02:00
enable_track = false ;
2018-10-25 23:40:33 +02:00
2019-05-22 21:43:42 +02:00
ImGuiStyle & style = ImGui : : GetStyle ( ) ;
float child_w = ( ImGui : : GetContentRegionAvail ( ) . x - 4 * style . ItemSpacing . x ) / 5 ;
2019-07-01 20:57:15 +02:00
if ( child_w < 1.0f )
child_w = 1.0f ;
2019-07-01 12:15:36 +02:00
ImGui : : PushID ( " ##VerticalScrolling " ) ;
2018-10-25 23:40:33 +02:00
for ( int i = 0 ; i < 5 ; i + + )
2015-07-22 01:00:28 +02:00
{
2018-10-25 23:40:33 +02:00
if ( i > 0 ) ImGui : : SameLine ( ) ;
ImGui : : BeginGroup ( ) ;
2019-07-01 12:15:36 +02:00
const char * names [ ] = { " Top " , " 25% " , " Center " , " 75% " , " Bottom " } ;
ImGui : : TextUnformatted ( names [ i ] ) ;
2019-06-04 16:22:47 +02:00
2020-05-05 19:39:24 +02:00
const ImGuiWindowFlags child_flags = enable_extra_decorations ? ImGuiWindowFlags_MenuBar : 0 ;
const ImGuiID child_id = ImGui : : GetID ( ( void * ) ( intptr_t ) i ) ;
2024-08-23 15:24:22 +02:00
const bool child_is_visible = ImGui : : BeginChild ( child_id , ImVec2 ( child_w , 200.0f ) , ImGuiChildFlags_Borders , child_flags ) ;
2019-07-31 19:26:10 +02:00
if ( ImGui : : BeginMenuBar ( ) )
{
ImGui : : TextUnformatted ( " abc " ) ;
ImGui : : EndMenuBar ( ) ;
}
2019-06-04 16:22:47 +02:00
if ( scroll_to_off )
ImGui : : SetScrollY ( scroll_to_off_px ) ;
if ( scroll_to_pos )
ImGui : : SetScrollFromPosY ( ImGui : : GetCursorStartPos ( ) . y + scroll_to_pos_px , i * 0.25f ) ;
2020-05-05 19:39:24 +02:00
if ( child_is_visible ) // Avoid calling SetScrollHereY when running with culled items
2015-07-22 01:00:28 +02:00
{
2019-11-08 19:00:49 +01:00
for ( int item = 0 ; item < 100 ; item + + )
2015-07-22 01:00:28 +02:00
{
2019-11-08 19:00:49 +01:00
if ( enable_track & & item = = track_item )
{
ImGui : : TextColored ( ImVec4 ( 1 , 1 , 0 , 1 ) , " Item %d " , item ) ;
ImGui : : SetScrollHereY ( i * 0.25f ) ; // 0.0f:top, 0.5f:center, 1.0f:bottom
}
else
{
ImGui : : Text ( " Item %d " , item ) ;
}
2015-08-30 17:38:55 +02:00
}
}
2019-05-22 21:43:42 +02:00
float scroll_y = ImGui : : GetScrollY ( ) ;
float scroll_max_y = ImGui : : GetScrollMaxY ( ) ;
2015-08-30 17:38:55 +02:00
ImGui : : EndChild ( ) ;
2019-06-04 16:22:47 +02:00
ImGui : : Text ( " %.0f/%.0f " , scroll_y , scroll_max_y ) ;
2018-10-25 23:40:33 +02:00
ImGui : : EndGroup ( ) ;
}
2019-07-01 12:15:36 +02:00
ImGui : : PopID ( ) ;
2018-10-25 23:40:33 +02:00
2019-07-01 12:15:36 +02:00
// Horizontal scroll functions
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Layout/Scrolling/Horizontal " ) ;
2019-07-01 12:15:36 +02:00
ImGui : : Spacing ( ) ;
2020-05-05 19:39:24 +02:00
HelpMarker (
" Use SetScrollHereX() or SetScrollFromPosX() to scroll to a given horizontal position. \n \n "
2020-08-05 17:09:40 +02:00
" Because the clipping rectangle of most window hides half worth of WindowPadding on the "
" left/right, using SetScrollFromPosX(+1) will usually result in clipped text whereas the "
" equivalent SetScrollFromPosY(+1) wouldn't. " ) ;
2019-07-01 12:15:36 +02:00
ImGui : : PushID ( " ##HorizontalScrolling " ) ;
for ( int i = 0 ; i < 5 ; i + + )
{
float child_height = ImGui : : GetTextLineHeight ( ) + style . ScrollbarSize + style . WindowPadding . y * 2.0f ;
2019-07-31 19:26:10 +02:00
ImGuiWindowFlags child_flags = ImGuiWindowFlags_HorizontalScrollbar | ( enable_extra_decorations ? ImGuiWindowFlags_AlwaysVerticalScrollbar : 0 ) ;
2020-05-05 19:39:24 +02:00
ImGuiID child_id = ImGui : : GetID ( ( void * ) ( intptr_t ) i ) ;
2024-08-23 15:24:22 +02:00
bool child_is_visible = ImGui : : BeginChild ( child_id , ImVec2 ( - 100 , child_height ) , ImGuiChildFlags_Borders , child_flags ) ;
2019-07-01 12:15:36 +02:00
if ( scroll_to_off )
ImGui : : SetScrollX ( scroll_to_off_px ) ;
if ( scroll_to_pos )
ImGui : : SetScrollFromPosX ( ImGui : : GetCursorStartPos ( ) . x + scroll_to_pos_px , i * 0.25f ) ;
2020-05-05 19:39:24 +02:00
if ( child_is_visible ) // Avoid calling SetScrollHereY when running with culled items
2019-07-01 12:15:36 +02:00
{
2019-11-08 19:00:49 +01:00
for ( int item = 0 ; item < 100 ; item + + )
2019-07-01 12:15:36 +02:00
{
2021-03-19 15:25:43 +01:00
if ( item > 0 )
ImGui : : SameLine ( ) ;
2019-11-08 19:00:49 +01:00
if ( enable_track & & item = = track_item )
{
ImGui : : TextColored ( ImVec4 ( 1 , 1 , 0 , 1 ) , " Item %d " , item ) ;
ImGui : : SetScrollHereX ( i * 0.25f ) ; // 0.0f:left, 0.5f:center, 1.0f:right
}
else
{
ImGui : : Text ( " Item %d " , item ) ;
}
2019-07-01 12:15:36 +02:00
}
}
float scroll_x = ImGui : : GetScrollX ( ) ;
float scroll_max_x = ImGui : : GetScrollMaxX ( ) ;
ImGui : : EndChild ( ) ;
ImGui : : SameLine ( ) ;
const char * names [ ] = { " Left " , " 25% " , " Center " , " 75% " , " Right " } ;
ImGui : : Text ( " %s \n %.0f/%.0f " , names [ i ] , scroll_x , scroll_max_x ) ;
ImGui : : Spacing ( ) ;
}
ImGui : : PopID ( ) ;
// Miscellaneous Horizontal Scrolling Demo
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Layout/Scrolling/Horizontal (more) " ) ;
2020-05-05 19:39:24 +02:00
HelpMarker (
" Horizontal scrolling for a window is enabled via the ImGuiWindowFlags_HorizontalScrollbar flag. \n \n "
" You may want to also explicitly specify content width by using SetNextWindowContentWidth() before Begin(). " ) ;
2018-10-25 23:40:33 +02:00
static int lines = 7 ;
ImGui : : SliderInt ( " Lines " , & lines , 1 , 15 ) ;
ImGui : : PushStyleVar ( ImGuiStyleVar_FrameRounding , 3.0f ) ;
ImGui : : PushStyleVar ( ImGuiStyleVar_FramePadding , ImVec2 ( 2.0f , 1.0f ) ) ;
2020-05-05 19:39:24 +02:00
ImVec2 scrolling_child_size = ImVec2 ( 0 , ImGui : : GetFrameHeightWithSpacing ( ) * 7 + 30 ) ;
2024-08-23 15:24:22 +02:00
ImGui : : BeginChild ( " scrolling " , scrolling_child_size , ImGuiChildFlags_Borders , ImGuiWindowFlags_HorizontalScrollbar ) ;
2018-10-25 23:40:33 +02:00
for ( int line = 0 ; line < lines ; line + + )
{
2020-05-05 19:39:24 +02:00
// Display random stuff. For the sake of this trivial demo we are using basic Button() + SameLine()
// If you want to create your own time line for a real application you may be better off manipulating
// the cursor position yourself, aka using SetCursorPos/SetCursorScreenPos to position the widgets
// yourself. You may also want to use the lower-level ImDrawList API.
2018-10-25 23:40:33 +02:00
int num_buttons = 10 + ( ( line & 1 ) ? line * 9 : line * 3 ) ;
for ( int n = 0 ; n < num_buttons ; n + + )
2015-08-30 19:33:38 +02:00
{
2018-10-25 23:40:33 +02:00
if ( n > 0 ) ImGui : : SameLine ( ) ;
ImGui : : PushID ( n + line * 1000 ) ;
char num_buf [ 16 ] ;
sprintf ( num_buf , " %d " , n ) ;
2020-06-30 15:31:54 +02:00
const char * label = ( ! ( n % 15 ) ) ? " FizzBuzz " : ( ! ( n % 3 ) ) ? " Fizz " : ( ! ( n % 5 ) ) ? " Buzz " : num_buf ;
float hue = n * 0.05f ;
2018-10-25 23:40:33 +02:00
ImGui : : PushStyleColor ( ImGuiCol_Button , ( ImVec4 ) ImColor : : HSV ( hue , 0.6f , 0.6f ) ) ;
ImGui : : PushStyleColor ( ImGuiCol_ButtonHovered , ( ImVec4 ) ImColor : : HSV ( hue , 0.7f , 0.7f ) ) ;
ImGui : : PushStyleColor ( ImGuiCol_ButtonActive , ( ImVec4 ) ImColor : : HSV ( hue , 0.8f , 0.8f ) ) ;
ImGui : : Button ( label , ImVec2 ( 40.0f + sinf ( ( float ) ( line + n ) ) * 20.0f , 0.0f ) ) ;
ImGui : : PopStyleColor ( 3 ) ;
ImGui : : PopID ( ) ;
2015-08-30 19:33:38 +02:00
}
2015-08-30 17:38:55 +02:00
}
2019-04-11 15:12:18 +02:00
float scroll_x = ImGui : : GetScrollX ( ) ;
float scroll_max_x = ImGui : : GetScrollMaxX ( ) ;
2018-10-25 23:40:33 +02:00
ImGui : : EndChild ( ) ;
ImGui : : PopStyleVar ( 2 ) ;
float scroll_x_delta = 0.0f ;
2020-05-05 19:39:24 +02:00
ImGui : : SmallButton ( " << " ) ;
if ( ImGui : : IsItemActive ( ) )
scroll_x_delta = - ImGui : : GetIO ( ) . DeltaTime * 1000.0f ;
ImGui : : SameLine ( ) ;
2018-10-25 23:40:33 +02:00
ImGui : : Text ( " Scroll from code " ) ; ImGui : : SameLine ( ) ;
2020-05-05 19:39:24 +02:00
ImGui : : SmallButton ( " >> " ) ;
if ( ImGui : : IsItemActive ( ) )
scroll_x_delta = + ImGui : : GetIO ( ) . DeltaTime * 1000.0f ;
ImGui : : SameLine ( ) ;
2018-10-25 23:40:33 +02:00
ImGui : : Text ( " %.0f/%.0f " , scroll_x , scroll_max_x ) ;
if ( scroll_x_delta ! = 0.0f )
2015-07-22 01:00:28 +02:00
{
2020-05-05 19:39:24 +02:00
// Demonstrate a trick: you can use Begin to set yourself in the context of another window
// (here we are already out of your child window)
ImGui : : BeginChild ( " scrolling " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : SetScrollX ( ImGui : : GetScrollX ( ) + scroll_x_delta ) ;
2019-01-15 15:05:56 +01:00
ImGui : : EndChild ( ) ;
2015-07-22 01:00:28 +02:00
}
2019-05-28 21:49:22 +02:00
ImGui : : Spacing ( ) ;
static bool show_horizontal_contents_size_demo_window = false ;
ImGui : : Checkbox ( " Show Horizontal contents size demo window " , & show_horizontal_contents_size_demo_window ) ;
if ( show_horizontal_contents_size_demo_window )
{
static bool show_h_scrollbar = true ;
static bool show_button = true ;
static bool show_tree_nodes = true ;
2019-06-03 17:07:43 +02:00
static bool show_text_wrapped = false ;
2019-05-28 21:49:22 +02:00
static bool show_columns = true ;
static bool show_tab_bar = true ;
2019-06-05 15:23:01 +02:00
static bool show_child = false ;
2019-05-28 21:49:22 +02:00
static bool explicit_content_size = false ;
static float contents_size_x = 300.0f ;
if ( explicit_content_size )
ImGui : : SetNextWindowContentSize ( ImVec2 ( contents_size_x , 0.0f ) ) ;
ImGui : : Begin ( " Horizontal contents size demo window " , & show_horizontal_contents_size_demo_window , show_h_scrollbar ? ImGuiWindowFlags_HorizontalScrollbar : 0 ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Layout/Scrolling/Horizontal contents size demo window " ) ;
2019-05-28 21:49:22 +02:00
ImGui : : PushStyleVar ( ImGuiStyleVar_ItemSpacing , ImVec2 ( 2 , 0 ) ) ;
ImGui : : PushStyleVar ( ImGuiStyleVar_FramePadding , ImVec2 ( 2 , 0 ) ) ;
2024-01-04 11:50:38 +01:00
HelpMarker (
" Test how different widgets react and impact the work rectangle growing when horizontal scrolling is enabled. \n \n "
" Use 'Metrics->Tools->Show windows rectangles' to visualize rectangles. " ) ;
2019-05-28 21:49:22 +02:00
ImGui : : Checkbox ( " H-scrollbar " , & show_h_scrollbar ) ;
ImGui : : Checkbox ( " Button " , & show_button ) ; // Will grow contents size (unless explicitly overwritten)
ImGui : : Checkbox ( " Tree nodes " , & show_tree_nodes ) ; // Will grow contents size and display highlight over full width
2019-06-03 17:07:43 +02:00
ImGui : : Checkbox ( " Text wrapped " , & show_text_wrapped ) ; // Will grow and use contents size
2019-05-28 21:49:22 +02:00
ImGui : : Checkbox ( " Columns " , & show_columns ) ; // Will use contents size
ImGui : : Checkbox ( " Tab bar " , & show_tab_bar ) ; // Will use contents size
2019-06-05 15:23:01 +02:00
ImGui : : Checkbox ( " Child " , & show_child ) ; // Will grow and use contents size
2019-05-28 21:49:22 +02:00
ImGui : : Checkbox ( " Explicit content size " , & explicit_content_size ) ;
2019-06-05 15:23:01 +02:00
ImGui : : Text ( " Scroll %.1f/%.1f %.1f/%.1f " , ImGui : : GetScrollX ( ) , ImGui : : GetScrollMaxX ( ) , ImGui : : GetScrollY ( ) , ImGui : : GetScrollMaxY ( ) ) ;
2019-05-28 21:49:22 +02:00
if ( explicit_content_size )
{
ImGui : : SameLine ( ) ;
ImGui : : SetNextItemWidth ( 100 ) ;
ImGui : : DragFloat ( " ##csx " , & contents_size_x ) ;
2019-09-17 11:33:18 +02:00
ImVec2 p = ImGui : : GetCursorScreenPos ( ) ;
2019-05-28 21:49:22 +02:00
ImGui : : GetWindowDrawList ( ) - > AddRectFilled ( p , ImVec2 ( p . x + 10 , p . y + 10 ) , IM_COL32_WHITE ) ;
ImGui : : GetWindowDrawList ( ) - > AddRectFilled ( ImVec2 ( p . x + contents_size_x - 10 , p . y ) , ImVec2 ( p . x + contents_size_x , p . y + 10 ) , IM_COL32_WHITE ) ;
ImGui : : Dummy ( ImVec2 ( 0 , 10 ) ) ;
}
ImGui : : PopStyleVar ( 2 ) ;
ImGui : : Separator ( ) ;
if ( show_button )
{
ImGui : : Button ( " this is a 300-wide button " , ImVec2 ( 300 , 0 ) ) ;
}
if ( show_tree_nodes )
{
bool open = true ;
if ( ImGui : : TreeNode ( " this is a tree node " ) )
{
if ( ImGui : : TreeNode ( " another one of those tree node... " ) )
{
ImGui : : Text ( " Some tree contents " ) ;
ImGui : : TreePop ( ) ;
}
ImGui : : TreePop ( ) ;
}
ImGui : : CollapsingHeader ( " CollapsingHeader " , & open ) ;
}
2019-06-03 17:07:43 +02:00
if ( show_text_wrapped )
{
ImGui : : TextWrapped ( " This text should automatically wrap on the edge of the work rectangle. " ) ;
}
2019-05-28 21:49:22 +02:00
if ( show_columns )
{
2020-10-26 18:28:49 +01:00
ImGui : : Text ( " Tables: " ) ;
if ( ImGui : : BeginTable ( " table " , 4 , ImGuiTableFlags_Borders ) )
{
for ( int n = 0 ; n < 4 ; n + + )
{
ImGui : : TableNextColumn ( ) ;
ImGui : : Text ( " Width %.2f " , ImGui : : GetContentRegionAvail ( ) . x ) ;
}
ImGui : : EndTable ( ) ;
}
ImGui : : Text ( " Columns: " ) ;
2019-05-28 21:49:22 +02:00
ImGui : : Columns ( 4 ) ;
for ( int n = 0 ; n < 4 ; n + + )
{
ImGui : : Text ( " Width %.2f " , ImGui : : GetColumnWidth ( ) ) ;
ImGui : : NextColumn ( ) ;
}
ImGui : : Columns ( 1 ) ;
}
if ( show_tab_bar & & ImGui : : BeginTabBar ( " Hello " ) )
{
if ( ImGui : : BeginTabItem ( " OneOneOne " ) ) { ImGui : : EndTabItem ( ) ; }
if ( ImGui : : BeginTabItem ( " TwoTwoTwo " ) ) { ImGui : : EndTabItem ( ) ; }
if ( ImGui : : BeginTabItem ( " ThreeThreeThree " ) ) { ImGui : : EndTabItem ( ) ; }
if ( ImGui : : BeginTabItem ( " FourFourFour " ) ) { ImGui : : EndTabItem ( ) ; }
ImGui : : EndTabBar ( ) ;
}
2019-06-05 15:23:01 +02:00
if ( show_child )
{
2024-08-23 15:24:22 +02:00
ImGui : : BeginChild ( " child " , ImVec2 ( 0 , 0 ) , ImGuiChildFlags_Borders ) ;
2019-06-05 15:23:01 +02:00
ImGui : : EndChild ( ) ;
}
2019-05-28 21:49:22 +02:00
ImGui : : End ( ) ;
}
2018-10-25 23:40:33 +02:00
ImGui : : TreePop ( ) ;
}
2024-07-30 11:44:13 +02:00
IMGUI_DEMO_MARKER ( " Layout/Text Clipping " ) ;
if ( ImGui : : TreeNode ( " Text Clipping " ) )
2018-10-25 23:40:33 +02:00
{
2020-08-04 12:05:15 +02:00
static ImVec2 size ( 100.0f , 100.0f ) ;
static ImVec2 offset ( 30.0f , 30.0f ) ;
2019-01-12 19:46:35 +01:00
ImGui : : DragFloat2 ( " size " , ( float * ) & size , 0.5f , 1.0f , 200.0f , " %.0f " ) ;
2020-08-04 12:05:15 +02:00
ImGui : : TextWrapped ( " (Click and drag to scroll) " ) ;
2022-06-07 11:38:43 +02:00
HelpMarker (
" (Left) Using ImGui::PushClipRect(): \n "
" Will alter ImGui hit-testing logic + ImDrawList rendering. \n "
" (use this if you want your clipping rectangle to affect interactions) \n \n "
" (Center) Using ImDrawList::PushClipRect(): \n "
" Will alter ImDrawList rendering only. \n "
" (use this as a shortcut if you are only using ImDrawList calls) \n \n "
" (Right) Using ImDrawList::AddText() with a fine ClipRect: \n "
" Will alter only this specific ImDrawList::AddText() rendering. \n "
" This is often used internally to avoid altering the clipping rectangle and minimize draw calls. " ) ;
2020-08-04 12:05:15 +02:00
for ( int n = 0 ; n < 3 ; n + + )
2020-05-05 19:39:24 +02:00
{
2020-08-04 12:05:15 +02:00
if ( n > 0 )
ImGui : : SameLine ( ) ;
2022-06-07 11:38:43 +02:00
ImGui : : PushID ( n ) ;
ImGui : : InvisibleButton ( " ##canvas " , size ) ;
2020-08-04 12:05:15 +02:00
if ( ImGui : : IsItemActive ( ) & & ImGui : : IsMouseDragging ( ImGuiMouseButton_Left ) )
{
offset . x + = ImGui : : GetIO ( ) . MouseDelta . x ;
offset . y + = ImGui : : GetIO ( ) . MouseDelta . y ;
}
2022-06-07 11:38:43 +02:00
ImGui : : PopID ( ) ;
if ( ! ImGui : : IsItemVisible ( ) ) // Skip rendering as ImDrawList elements are not clipped.
continue ;
2020-08-04 12:05:15 +02:00
const ImVec2 p0 = ImGui : : GetItemRectMin ( ) ;
const ImVec2 p1 = ImGui : : GetItemRectMax ( ) ;
const char * text_str = " Line 1 hello \n Line 2 clip me! " ;
const ImVec2 text_pos = ImVec2 ( p0 . x + offset . x , p0 . y + offset . y ) ;
ImDrawList * draw_list = ImGui : : GetWindowDrawList ( ) ;
switch ( n )
{
case 0 :
ImGui : : PushClipRect ( p0 , p1 , true ) ;
draw_list - > AddRectFilled ( p0 , p1 , IM_COL32 ( 90 , 90 , 120 , 255 ) ) ;
draw_list - > AddText ( text_pos , IM_COL32_WHITE , text_str ) ;
ImGui : : PopClipRect ( ) ;
break ;
case 1 :
draw_list - > PushClipRect ( p0 , p1 , true ) ;
draw_list - > AddRectFilled ( p0 , p1 , IM_COL32 ( 90 , 90 , 120 , 255 ) ) ;
draw_list - > AddText ( text_pos , IM_COL32_WHITE , text_str ) ;
draw_list - > PopClipRect ( ) ;
break ;
case 2 :
ImVec4 clip_rect ( p0 . x , p0 . y , p1 . x , p1 . y ) ; // AddText() takes a ImVec4* here so let's convert.
draw_list - > AddRectFilled ( p0 , p1 , IM_COL32 ( 90 , 90 , 120 , 255 ) ) ;
draw_list - > AddText ( ImGui : : GetFont ( ) , ImGui : : GetFontSize ( ) , text_pos , IM_COL32_WHITE , text_str , NULL , 0.0f , & clip_rect ) ;
break ;
}
2020-05-05 19:39:24 +02:00
}
2020-08-04 12:05:15 +02:00
2018-10-25 23:40:33 +02:00
ImGui : : TreePop ( ) ;
2015-07-22 01:00:28 +02:00
}
2023-07-05 14:19:01 +02:00
IMGUI_DEMO_MARKER ( " Layout/Overlap Mode " ) ;
if ( ImGui : : TreeNode ( " Overlap Mode " ) )
{
static bool enable_allow_overlap = true ;
HelpMarker (
" Hit-testing is by default performed in item submission order, which generally is perceived as 'back-to-front'. \n \n "
2024-01-04 11:50:38 +01:00
" By using SetNextItemAllowOverlap() you can notify that an item may be overlapped by another. "
" Doing so alters the hovering logic: items using AllowOverlap mode requires an extra frame to accept hovered state. " ) ;
2023-07-05 14:19:01 +02:00
ImGui : : Checkbox ( " Enable AllowOverlap " , & enable_allow_overlap ) ;
ImVec2 button1_pos = ImGui : : GetCursorScreenPos ( ) ;
ImVec2 button2_pos = ImVec2 ( button1_pos . x + 50.0f , button1_pos . y + 50.0f ) ;
if ( enable_allow_overlap )
ImGui : : SetNextItemAllowOverlap ( ) ;
ImGui : : Button ( " Button 1 " , ImVec2 ( 80 , 80 ) ) ;
ImGui : : SetCursorScreenPos ( button2_pos ) ;
ImGui : : Button ( " Button 2 " , ImVec2 ( 80 , 80 ) ) ;
// This is typically used with width-spanning items.
// (note that Selectable() has a dedicated flag ImGuiSelectableFlags_AllowOverlap, which is a shortcut
// for using SetNextItemAllowOverlap(). For demo purpose we use SetNextItemAllowOverlap() here.)
if ( enable_allow_overlap )
ImGui : : SetNextItemAllowOverlap ( ) ;
ImGui : : Selectable ( " Some Selectable " , false ) ;
ImGui : : SameLine ( ) ;
ImGui : : SmallButton ( " ++ " ) ;
ImGui : : TreePop ( ) ;
}
2018-10-25 23:34:05 +02:00
}
2015-07-22 01:00:28 +02:00
2024-07-19 12:35:57 +02:00
//-----------------------------------------------------------------------------
// [SECTION] ShowDemoWindowPopups()
//-----------------------------------------------------------------------------
2018-10-25 23:34:05 +02:00
static void ShowDemoWindowPopups ( )
{
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Popups " ) ;
2018-10-25 23:40:33 +02:00
if ( ! ImGui : : CollapsingHeader ( " Popups & Modal windows " ) )
return ;
2018-10-25 23:34:05 +02:00
2018-12-14 16:24:59 +01:00
// The properties of popups windows are:
2018-10-25 23:40:33 +02:00
// - They block normal mouse hovering detection outside them. (*)
// - Unless modal, they can be closed by clicking anywhere outside them, or by pressing ESCAPE.
2020-05-05 19:39:24 +02:00
// - Their visibility state (~bool) is held internally by Dear ImGui instead of being held by the programmer as
// we are used to with regular Begin() calls. User can manipulate the visibility state by calling OpenPopup().
// (*) One can use IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup) to bypass it and detect hovering even
// when normally blocked by a popup.
// Those three properties are connected. The library needs to hold their visibility state BECAUSE it can close
// popups at any time.
2018-10-16 10:25:32 +02:00
2018-10-25 23:40:33 +02:00
// Typical use for regular windows:
// bool my_tool_is_active = false; if (ImGui::Button("Open")) my_tool_is_active = true; [...] if (my_tool_is_active) Begin("My Tool", &my_tool_is_active) { [...] } End();
// Typical use for popups:
// if (ImGui::Button("Open")) ImGui::OpenPopup("MyPopup"); if (ImGui::BeginPopup("MyPopup") { [...] EndPopup(); }
2018-10-16 10:25:32 +02:00
2018-10-25 23:40:33 +02:00
// With popups we have to go through a library call (here OpenPopup) to manipulate the visibility state.
2019-01-20 17:56:17 +01:00
// This may be a bit confusing at first but it should quickly make sense. Follow on the examples below.
2015-07-22 01:00:28 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Popups/Popups " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Popups " ) )
{
2020-05-05 19:39:24 +02:00
ImGui : : TextWrapped (
" When a popup is active, it inhibits interacting with windows that are behind the popup. "
" Clicking outside the popup closes it. " ) ;
2018-10-25 23:40:33 +02:00
static int selected_fish = - 1 ;
const char * names [ ] = { " Bream " , " Haddock " , " Mackerel " , " Pollock " , " Tilefish " } ;
static bool toggles [ ] = { true , false , false , false , false } ;
2020-05-05 19:39:24 +02:00
// Simple selection popup (if you want to show the current selection inside the Button itself,
// you may want to build a string using the "###" operator to preserve a constant ID with a variable label)
2018-10-25 23:40:33 +02:00
if ( ImGui : : Button ( " Select.. " ) )
ImGui : : OpenPopup ( " my_select_popup " ) ;
ImGui : : SameLine ( ) ;
ImGui : : TextUnformatted ( selected_fish = = - 1 ? " <None> " : names [ selected_fish ] ) ;
if ( ImGui : : BeginPopup ( " my_select_popup " ) )
{
2023-02-10 12:16:23 +01:00
ImGui : : SeparatorText ( " Aquarium " ) ;
2018-10-25 23:40:33 +02:00
for ( int i = 0 ; i < IM_ARRAYSIZE ( names ) ; i + + )
if ( ImGui : : Selectable ( names [ i ] ) )
selected_fish = i ;
ImGui : : EndPopup ( ) ;
}
2015-07-22 01:00:28 +02:00
2018-10-25 23:40:33 +02:00
// Showing a menu with toggles
if ( ImGui : : Button ( " Toggle.. " ) )
ImGui : : OpenPopup ( " my_toggle_popup " ) ;
if ( ImGui : : BeginPopup ( " my_toggle_popup " ) )
{
for ( int i = 0 ; i < IM_ARRAYSIZE ( names ) ; i + + )
ImGui : : MenuItem ( names [ i ] , " " , & toggles [ i ] ) ;
if ( ImGui : : BeginMenu ( " Sub-menu " ) )
2015-07-22 01:00:28 +02:00
{
2018-10-25 23:40:33 +02:00
ImGui : : MenuItem ( " Click me " ) ;
ImGui : : EndMenu ( ) ;
2015-07-22 01:00:28 +02:00
}
2018-10-25 23:40:33 +02:00
ImGui : : Separator ( ) ;
ImGui : : Text ( " Tooltip here " ) ;
2023-06-16 16:42:56 +02:00
ImGui : : SetItemTooltip ( " I am a tooltip over a popup " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : Button ( " Stacked Popup " ) )
ImGui : : OpenPopup ( " another popup " ) ;
if ( ImGui : : BeginPopup ( " another popup " ) )
2015-07-22 01:00:28 +02:00
{
for ( int i = 0 ; i < IM_ARRAYSIZE ( names ) ; i + + )
ImGui : : MenuItem ( names [ i ] , " " , & toggles [ i ] ) ;
if ( ImGui : : BeginMenu ( " Sub-menu " ) )
{
ImGui : : MenuItem ( " Click me " ) ;
2019-04-28 22:21:23 +02:00
if ( ImGui : : Button ( " Stacked Popup " ) )
ImGui : : OpenPopup ( " another popup " ) ;
if ( ImGui : : BeginPopup ( " another popup " ) )
{
ImGui : : Text ( " I am the last one here. " ) ;
ImGui : : EndPopup ( ) ;
}
2015-07-22 01:00:28 +02:00
ImGui : : EndMenu ( ) ;
}
ImGui : : EndPopup ( ) ;
}
2018-10-25 23:40:33 +02:00
ImGui : : EndPopup ( ) ;
2015-07-22 01:00:28 +02:00
}
2018-10-25 23:40:33 +02:00
// Call the more complete ShowExampleMenuFile which we use in various places of this demo
2021-12-13 19:46:01 +01:00
if ( ImGui : : Button ( " With a menu.. " ) )
2018-10-25 23:40:33 +02:00
ImGui : : OpenPopup ( " my_file_popup " ) ;
2021-12-13 19:46:01 +01:00
if ( ImGui : : BeginPopup ( " my_file_popup " , ImGuiWindowFlags_MenuBar ) )
2015-07-22 01:00:28 +02:00
{
2021-12-13 19:46:01 +01:00
if ( ImGui : : BeginMenuBar ( ) )
{
if ( ImGui : : BeginMenu ( " File " ) )
{
ShowExampleMenuFile ( ) ;
ImGui : : EndMenu ( ) ;
}
if ( ImGui : : BeginMenu ( " Edit " ) )
{
ImGui : : MenuItem ( " Dummy " ) ;
ImGui : : EndMenu ( ) ;
}
ImGui : : EndMenuBar ( ) ;
}
ImGui : : Text ( " Hello from popup! " ) ;
ImGui : : Button ( " This is a dummy button.. " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : EndPopup ( ) ;
}
2015-07-22 01:00:28 +02:00
2018-10-25 23:40:33 +02:00
ImGui : : TreePop ( ) ;
}
2015-07-22 01:00:28 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Popups/Context menus " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Context menus " ) )
{
2021-04-15 15:53:50 +02:00
HelpMarker ( " \" Context \" functions are simple helpers to associate a Popup to a given Item or Window identifier. " ) ;
2018-10-25 23:40:33 +02:00
// BeginPopupContextItem() is a helper to provide common/simple popup behavior of essentially doing:
2021-04-15 15:53:50 +02:00
// if (id == 0)
// id = GetItemID(); // Use last item id
// if (IsItemHovered() && IsMouseReleased(ImGuiMouseButton_Right))
// OpenPopup(id);
// return BeginPopup(id);
2022-09-11 07:35:59 +02:00
// For advanced uses you may want to replicate and customize this code.
2021-04-15 15:53:50 +02:00
// See more details in BeginPopupContextItem().
// Example 1
// When used after an item that has an ID (e.g. Button), we can skip providing an ID to BeginPopupContextItem(),
// and BeginPopupContextItem() will use the last item ID as the popup ID.
{
const char * names [ 5 ] = { " Label1 " , " Label2 " , " Label3 " , " Label4 " , " Label5 " } ;
2023-01-02 18:01:57 +01:00
static int selected = - 1 ;
2021-04-15 15:53:50 +02:00
for ( int n = 0 ; n < 5 ; n + + )
{
2023-01-02 18:01:57 +01:00
if ( ImGui : : Selectable ( names [ n ] , selected = = n ) )
selected = n ;
2021-04-15 15:53:50 +02:00
if ( ImGui : : BeginPopupContextItem ( ) ) // <-- use last item id as popup id
{
2023-01-02 18:01:57 +01:00
selected = n ;
2021-04-15 15:53:50 +02:00
ImGui : : Text ( " This a popup for \" %s \" ! " , names [ n ] ) ;
if ( ImGui : : Button ( " Close " ) )
ImGui : : CloseCurrentPopup ( ) ;
ImGui : : EndPopup ( ) ;
}
2023-06-16 16:42:56 +02:00
ImGui : : SetItemTooltip ( " Right-click to open popup " ) ;
2021-04-15 15:53:50 +02:00
}
2015-07-22 01:00:28 +02:00
}
2021-04-15 15:53:50 +02:00
// Example 2
// Popup on a Text() element which doesn't have an identifier: we need to provide an identifier to BeginPopupContextItem().
// Using an explicit identifier is also convenient if you want to activate the popups from different locations.
{
HelpMarker ( " Text() elements don't have stable identifiers so we need to provide one. " ) ;
static float value = 0.5f ;
2022-04-22 17:15:09 +02:00
ImGui : : Text ( " Value = %.3f <-- (1) right-click this text " , value ) ;
2021-04-15 15:53:50 +02:00
if ( ImGui : : BeginPopupContextItem ( " my popup " ) )
{
if ( ImGui : : Selectable ( " Set to zero " ) ) value = 0.0f ;
if ( ImGui : : Selectable ( " Set to PI " ) ) value = 3.1415f ;
ImGui : : SetNextItemWidth ( - FLT_MIN ) ;
ImGui : : DragFloat ( " ##Value " , & value , 0.1f , 0.0f , 0.0f ) ;
ImGui : : EndPopup ( ) ;
}
// We can also use OpenPopupOnItemClick() to toggle the visibility of a given popup.
// Here we make it that right-clicking this other text element opens the same popup as above.
// The popup itself will be submitted by the code above.
ImGui : : Text ( " (2) Or right-click this text " ) ;
ImGui : : OpenPopupOnItemClick ( " my popup " , ImGuiPopupFlags_MouseButtonRight ) ;
// Back to square one: manually open the same popup.
if ( ImGui : : Button ( " (3) Or click this button " ) )
ImGui : : OpenPopup ( " my popup " ) ;
}
// Example 3
// When using BeginPopupContextItem() with an implicit identifier (NULL == use last item ID),
// we need to make sure your item identifier is stable.
// In this example we showcase altering the item label while preserving its identifier, using the ### operator (see FAQ).
{
HelpMarker ( " Showcase using a popup ID linked to item ID, with the item having a changing label + stable ID using the ### operator. " ) ;
static char name [ 32 ] = " Label1 " ;
char buf [ 64 ] ;
sprintf ( buf , " Button: %s###Button " , name ) ; // ### operator override ID ignoring the preceding label
ImGui : : Button ( buf ) ;
if ( ImGui : : BeginPopupContextItem ( ) )
{
ImGui : : Text ( " Edit name: " ) ;
ImGui : : InputText ( " ##edit " , name , IM_ARRAYSIZE ( name ) ) ;
if ( ImGui : : Button ( " Close " ) )
ImGui : : CloseCurrentPopup ( ) ;
ImGui : : EndPopup ( ) ;
}
ImGui : : SameLine ( ) ; ImGui : : Text ( " (<-- right-click here) " ) ;
2018-10-25 23:40:33 +02:00
}
2015-07-22 01:00:28 +02:00
2018-10-25 23:40:33 +02:00
ImGui : : TreePop ( ) ;
}
2015-08-24 13:50:18 +02:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Popups/Modals " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Modals " ) )
{
2020-05-05 19:39:24 +02:00
ImGui : : TextWrapped ( " Modal windows are like popups but the user cannot close them by clicking outside. " ) ;
2016-05-10 17:02:10 +02:00
2018-10-25 23:40:33 +02:00
if ( ImGui : : Button ( " Delete.. " ) )
ImGui : : OpenPopup ( " Delete? " ) ;
2018-12-14 16:24:59 +01:00
2020-06-23 17:52:13 +02:00
// Always center this window when appearing
2021-02-10 14:54:59 +01:00
ImVec2 center = ImGui : : GetMainViewport ( ) - > GetCenter ( ) ;
2020-06-23 17:52:13 +02:00
ImGui : : SetNextWindowPos ( center , ImGuiCond_Appearing , ImVec2 ( 0.5f , 0.5f ) ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : BeginPopupModal ( " Delete? " , NULL , ImGuiWindowFlags_AlwaysAutoResize ) )
{
2023-02-10 12:16:23 +01:00
ImGui : : Text ( " All those beautiful files will be deleted. \n This operation cannot be undone! " ) ;
2018-10-25 23:40:33 +02:00
ImGui : : Separator ( ) ;
2015-07-22 01:00:28 +02:00
2020-08-03 21:19:12 +02:00
//static int unused_i = 0;
//ImGui::Combo("Combo", &unused_i, "Delete\0Delete harder\0");
2015-07-22 01:00:28 +02:00
2018-10-25 23:40:33 +02:00
static bool dont_ask_me_next_time = false ;
ImGui : : PushStyleVar ( ImGuiStyleVar_FramePadding , ImVec2 ( 0 , 0 ) ) ;
ImGui : : Checkbox ( " Don't ask me next time " , & dont_ask_me_next_time ) ;
ImGui : : PopStyleVar ( ) ;
2015-07-22 01:00:28 +02:00
2018-10-25 23:40:33 +02:00
if ( ImGui : : Button ( " OK " , ImVec2 ( 120 , 0 ) ) ) { ImGui : : CloseCurrentPopup ( ) ; }
ImGui : : SetItemDefaultFocus ( ) ;
ImGui : : SameLine ( ) ;
if ( ImGui : : Button ( " Cancel " , ImVec2 ( 120 , 0 ) ) ) { ImGui : : CloseCurrentPopup ( ) ; }
ImGui : : EndPopup ( ) ;
}
if ( ImGui : : Button ( " Stacked modals.. " ) )
ImGui : : OpenPopup ( " Stacked 1 " ) ;
2019-01-27 23:54:17 +01:00
if ( ImGui : : BeginPopupModal ( " Stacked 1 " , NULL , ImGuiWindowFlags_MenuBar ) )
2018-10-25 23:40:33 +02:00
{
2019-01-27 23:54:17 +01:00
if ( ImGui : : BeginMenuBar ( ) )
{
if ( ImGui : : BeginMenu ( " File " ) )
{
2020-08-03 21:19:12 +02:00
if ( ImGui : : MenuItem ( " Some menu item " ) ) { }
2019-01-27 23:54:17 +01:00
ImGui : : EndMenu ( ) ;
}
ImGui : : EndMenuBar ( ) ;
}
2018-10-25 23:40:33 +02:00
ImGui : : Text ( " Hello from Stacked The First \n Using style.Colors[ImGuiCol_ModalWindowDimBg] behind it. " ) ;
2019-01-27 23:54:17 +01:00
// Testing behavior of widgets stacking their own regular popups over the modal.
2018-10-25 23:40:33 +02:00
static int item = 1 ;
2020-06-30 15:31:54 +02:00
static float color [ 4 ] = { 0.4f , 0.7f , 0.0f , 0.5f } ;
2019-01-27 23:54:17 +01:00
ImGui : : Combo ( " Combo " , & item , " aaaa \0 bbbb \0 cccc \0 dddd \0 eeee \0 \0 " ) ;
2024-06-05 15:47:21 +02:00
ImGui : : ColorEdit4 ( " Color " , color ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : Button ( " Add another modal.. " ) )
ImGui : : OpenPopup ( " Stacked 2 " ) ;
2018-12-14 16:24:59 +01:00
2020-05-05 19:39:24 +02:00
// Also demonstrate passing a bool* to BeginPopupModal(), this will create a regular close button which
// will close the popup. Note that the visibility state of popups is owned by imgui, so the input value
// of the bool actually doesn't matter here.
2020-08-03 21:19:12 +02:00
bool unused_open = true ;
if ( ImGui : : BeginPopupModal ( " Stacked 2 " , & unused_open ) )
2018-10-25 23:40:33 +02:00
{
ImGui : : Text ( " Hello from Stacked The Second! " ) ;
2024-06-05 15:47:21 +02:00
ImGui : : ColorEdit4 ( " Color " , color ) ; // Allow opening another nested popup
2015-07-22 01:00:28 +02:00
if ( ImGui : : Button ( " Close " ) )
ImGui : : CloseCurrentPopup ( ) ;
ImGui : : EndPopup ( ) ;
}
2018-10-25 23:40:33 +02:00
if ( ImGui : : Button ( " Close " ) )
ImGui : : CloseCurrentPopup ( ) ;
ImGui : : EndPopup ( ) ;
2015-07-22 01:00:28 +02:00
}
2017-10-20 12:38:48 +02:00
2018-10-25 23:40:33 +02:00
ImGui : : TreePop ( ) ;
}
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Popups/Menus inside a regular window " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Menus inside a regular window " ) )
{
ImGui : : TextWrapped ( " Below we are testing adding menu items to a regular window. It's rather unusual but should work! " ) ;
ImGui : : Separator ( ) ;
2020-05-05 19:39:24 +02:00
2018-10-25 23:40:33 +02:00
ImGui : : MenuItem ( " Menu item " , " CTRL+M " ) ;
if ( ImGui : : BeginMenu ( " Menu inside a regular window " ) )
2017-10-20 12:38:48 +02:00
{
2018-10-25 23:40:33 +02:00
ShowExampleMenuFile ( ) ;
ImGui : : EndMenu ( ) ;
2017-10-20 12:38:48 +02:00
}
2018-10-25 23:40:33 +02:00
ImGui : : Separator ( ) ;
ImGui : : TreePop ( ) ;
2015-07-22 01:00:28 +02:00
}
2018-10-25 23:34:05 +02:00
}
2015-07-22 01:00:28 +02:00
2019-12-19 14:52:18 +01:00
// Dummy data structure that we use for the Table demo.
2022-09-11 07:35:59 +02:00
// (pre-C++11 doesn't allow us to instantiate ImVector<MyItem> template if this structure is defined inside the demo function)
2019-12-19 14:52:18 +01:00
namespace
{
// We are passing our own identifier to TableSetupColumn() to facilitate identifying columns in the sorting code.
// This identifier will be passed down into ImGuiTableSortSpec::ColumnUserID.
// But it is possible to omit the user id parameter of TableSetupColumn() and just use the column index instead! (ImGuiTableSortSpec::ColumnIndex)
// If you don't use sorting, you will generally never care about giving column an ID!
enum MyItemColumnID
{
MyItemColumnID_ID ,
MyItemColumnID_Name ,
MyItemColumnID_Action ,
MyItemColumnID_Quantity ,
MyItemColumnID_Description
} ;
struct MyItem
{
int ID ;
const char * Name ;
int Quantity ;
// We have a problem which is affecting _only this demo_ and should not affect your code:
2020-05-22 15:27:53 +02:00
// As we don't rely on std:: or other third-party library to compile dear imgui, we only have reliable access to qsort(),
2019-12-19 14:52:18 +01:00
// however qsort doesn't allow passing user data to comparing function.
// As a workaround, we are storing the sort specs in a static/global for the comparing function to access.
// In your own use case you would probably pass the sort specs to your sorting/comparing functions directly and not use a global.
2020-09-23 12:53:10 +02:00
// We could technically call ImGui::TableGetSortSpecs() in CompareWithSortSpecs(), but considering that this function is called
// very often by the sorting algorithm it would be a little wasteful.
2019-12-19 14:52:18 +01:00
static const ImGuiTableSortSpecs * s_current_sort_specs ;
2023-09-01 14:35:57 +02:00
static void SortWithSortSpecs ( ImGuiTableSortSpecs * sort_specs , MyItem * items , int items_count )
{
s_current_sort_specs = sort_specs ; // Store in variable accessible by the sort function.
if ( items_count > 1 )
qsort ( items , ( size_t ) items_count , sizeof ( items [ 0 ] ) , MyItem : : CompareWithSortSpecs ) ;
s_current_sort_specs = NULL ;
}
2019-12-19 14:52:18 +01:00
// Compare function to be used by qsort()
static int IMGUI_CDECL CompareWithSortSpecs ( const void * lhs , const void * rhs )
{
const MyItem * a = ( const MyItem * ) lhs ;
const MyItem * b = ( const MyItem * ) rhs ;
for ( int n = 0 ; n < s_current_sort_specs - > SpecsCount ; n + + )
{
// Here we identify columns using the ColumnUserID value that we ourselves passed to TableSetupColumn()
// We could also choose to identify columns based on their index (sort_spec->ColumnIndex), which is simpler!
2020-12-04 17:54:40 +01:00
const ImGuiTableColumnSortSpecs * sort_spec = & s_current_sort_specs - > Specs [ n ] ;
2019-12-19 14:52:18 +01:00
int delta = 0 ;
switch ( sort_spec - > ColumnUserID )
{
case MyItemColumnID_ID : delta = ( a - > ID - b - > ID ) ; break ;
case MyItemColumnID_Name : delta = ( strcmp ( a - > Name , b - > Name ) ) ; break ;
case MyItemColumnID_Quantity : delta = ( a - > Quantity - b - > Quantity ) ; break ;
case MyItemColumnID_Description : delta = ( strcmp ( a - > Name , b - > Name ) ) ; break ;
default : IM_ASSERT ( 0 ) ; break ;
}
if ( delta > 0 )
2020-02-17 15:09:50 +01:00
return ( sort_spec - > SortDirection = = ImGuiSortDirection_Ascending ) ? + 1 : - 1 ;
if ( delta < 0 )
return ( sort_spec - > SortDirection = = ImGuiSortDirection_Ascending ) ? - 1 : + 1 ;
2019-12-19 14:52:18 +01:00
}
// qsort() is instable so always return a way to differenciate items.
2024-01-04 11:50:38 +01:00
// Your own compare function may want to avoid fallback on implicit sort specs.
// e.g. a Name compare if it wasn't already part of the sort specs.
2019-12-19 14:52:18 +01:00
return ( a - > ID - b - > ID ) ;
}
} ;
const ImGuiTableSortSpecs * MyItem : : s_current_sort_specs = NULL ;
}
2020-10-07 16:33:33 +02:00
// Make the UI compact because there are so many fields
static void PushStyleCompact ( )
{
ImGuiStyle & style = ImGui : : GetStyle ( ) ;
2024-08-22 13:46:54 +02:00
ImGui : : PushStyleVarY ( ImGuiStyleVar_FramePadding , ( float ) ( int ) ( style . FramePadding . y * 0.60f ) ) ;
ImGui : : PushStyleVarY ( ImGuiStyleVar_ItemSpacing , ( float ) ( int ) ( style . ItemSpacing . y * 0.60f ) ) ;
2020-10-07 16:33:33 +02:00
}
static void PopStyleCompact ( )
{
ImGui : : PopStyleVar ( 2 ) ;
}
2021-01-08 18:38:55 +01:00
// Show a combo box with a choice of sizing policies
static void EditTableSizingFlags ( ImGuiTableFlags * p_flags )
{
struct EnumDesc { ImGuiTableFlags Value ; const char * Name ; const char * Tooltip ; } ;
static const EnumDesc policies [ ] =
{
{ ImGuiTableFlags_None , " Default " , " Use default sizing policy: \n - ImGuiTableFlags_SizingFixedFit if ScrollX is on or if host window has ImGuiWindowFlags_AlwaysAutoResize. \n - ImGuiTableFlags_SizingStretchSame otherwise. " } ,
{ ImGuiTableFlags_SizingFixedFit , " ImGuiTableFlags_SizingFixedFit " , " Columns default to _WidthFixed (if resizable) or _WidthAuto (if not resizable), matching contents width. " } ,
{ ImGuiTableFlags_SizingFixedSame , " ImGuiTableFlags_SizingFixedSame " , " Columns are all the same width, matching the maximum contents width. \n Implicitly disable ImGuiTableFlags_Resizable and enable ImGuiTableFlags_NoKeepColumnsVisible. " } ,
{ ImGuiTableFlags_SizingStretchProp , " ImGuiTableFlags_SizingStretchProp " , " Columns default to _WidthStretch with weights proportional to their widths. " } ,
{ ImGuiTableFlags_SizingStretchSame , " ImGuiTableFlags_SizingStretchSame " , " Columns default to _WidthStretch with same weights. " }
} ;
int idx ;
for ( idx = 0 ; idx < IM_ARRAYSIZE ( policies ) ; idx + + )
if ( policies [ idx ] . Value = = ( * p_flags & ImGuiTableFlags_SizingMask_ ) )
break ;
const char * preview_text = ( idx < IM_ARRAYSIZE ( policies ) ) ? policies [ idx ] . Name + ( idx > 0 ? strlen ( " ImGuiTableFlags " ) : 0 ) : " " ;
if ( ImGui : : BeginCombo ( " Sizing Policy " , preview_text ) )
{
for ( int n = 0 ; n < IM_ARRAYSIZE ( policies ) ; n + + )
if ( ImGui : : Selectable ( policies [ n ] . Name , idx = = n ) )
* p_flags = ( * p_flags & ~ ImGuiTableFlags_SizingMask_ ) | policies [ n ] . Value ;
ImGui : : EndCombo ( ) ;
}
ImGui : : SameLine ( ) ;
ImGui : : TextDisabled ( " (?) " ) ;
2023-06-16 16:42:56 +02:00
if ( ImGui : : BeginItemTooltip ( ) )
2021-01-08 18:38:55 +01:00
{
ImGui : : PushTextWrapPos ( ImGui : : GetFontSize ( ) * 50.0f ) ;
for ( int m = 0 ; m < IM_ARRAYSIZE ( policies ) ; m + + )
{
ImGui : : Separator ( ) ;
ImGui : : Text ( " %s: " , policies [ m ] . Name ) ;
ImGui : : Separator ( ) ;
ImGui : : SetCursorPosX ( ImGui : : GetCursorPosX ( ) + ImGui : : GetStyle ( ) . IndentSpacing * 0.5f ) ;
ImGui : : TextUnformatted ( policies [ m ] . Tooltip ) ;
}
ImGui : : PopTextWrapPos ( ) ;
ImGui : : EndTooltip ( ) ;
}
}
2020-11-18 17:28:18 +01:00
static void EditTableColumnsFlags ( ImGuiTableColumnFlags * p_flags )
{
2021-06-07 13:03:13 +02:00
ImGui : : CheckboxFlags ( " _Disabled " , p_flags , ImGuiTableColumnFlags_Disabled ) ; ImGui : : SameLine ( ) ; HelpMarker ( " Master disable flag (also hide from context menu) " ) ;
2020-11-18 17:28:18 +01:00
ImGui : : CheckboxFlags ( " _DefaultHide " , p_flags , ImGuiTableColumnFlags_DefaultHide ) ;
ImGui : : CheckboxFlags ( " _DefaultSort " , p_flags , ImGuiTableColumnFlags_DefaultSort ) ;
2020-12-03 18:45:15 +01:00
if ( ImGui : : CheckboxFlags ( " _WidthStretch " , p_flags , ImGuiTableColumnFlags_WidthStretch ) )
* p_flags & = ~ ( ImGuiTableColumnFlags_WidthMask_ ^ ImGuiTableColumnFlags_WidthStretch ) ;
if ( ImGui : : CheckboxFlags ( " _WidthFixed " , p_flags , ImGuiTableColumnFlags_WidthFixed ) )
* p_flags & = ~ ( ImGuiTableColumnFlags_WidthMask_ ^ ImGuiTableColumnFlags_WidthFixed ) ;
2020-11-18 17:28:18 +01:00
ImGui : : CheckboxFlags ( " _NoResize " , p_flags , ImGuiTableColumnFlags_NoResize ) ;
ImGui : : CheckboxFlags ( " _NoReorder " , p_flags , ImGuiTableColumnFlags_NoReorder ) ;
ImGui : : CheckboxFlags ( " _NoHide " , p_flags , ImGuiTableColumnFlags_NoHide ) ;
ImGui : : CheckboxFlags ( " _NoClip " , p_flags , ImGuiTableColumnFlags_NoClip ) ;
ImGui : : CheckboxFlags ( " _NoSort " , p_flags , ImGuiTableColumnFlags_NoSort ) ;
ImGui : : CheckboxFlags ( " _NoSortAscending " , p_flags , ImGuiTableColumnFlags_NoSortAscending ) ;
ImGui : : CheckboxFlags ( " _NoSortDescending " , p_flags , ImGuiTableColumnFlags_NoSortDescending ) ;
2021-06-07 09:11:53 +02:00
ImGui : : CheckboxFlags ( " _NoHeaderLabel " , p_flags , ImGuiTableColumnFlags_NoHeaderLabel ) ;
2020-12-03 18:45:15 +01:00
ImGui : : CheckboxFlags ( " _NoHeaderWidth " , p_flags , ImGuiTableColumnFlags_NoHeaderWidth ) ;
2020-11-18 17:28:18 +01:00
ImGui : : CheckboxFlags ( " _PreferSortAscending " , p_flags , ImGuiTableColumnFlags_PreferSortAscending ) ;
ImGui : : CheckboxFlags ( " _PreferSortDescending " , p_flags , ImGuiTableColumnFlags_PreferSortDescending ) ;
ImGui : : CheckboxFlags ( " _IndentEnable " , p_flags , ImGuiTableColumnFlags_IndentEnable ) ; ImGui : : SameLine ( ) ; HelpMarker ( " Default for column 0 " ) ;
ImGui : : CheckboxFlags ( " _IndentDisable " , p_flags , ImGuiTableColumnFlags_IndentDisable ) ; ImGui : : SameLine ( ) ; HelpMarker ( " Default for column >0 " ) ;
2023-10-12 17:01:42 +02:00
ImGui : : CheckboxFlags ( " _AngledHeader " , p_flags , ImGuiTableColumnFlags_AngledHeader ) ;
2020-11-18 17:28:18 +01:00
}
2020-12-03 18:45:15 +01:00
static void ShowTableColumnsStatusFlags ( ImGuiTableColumnFlags flags )
{
ImGui : : CheckboxFlags ( " _IsEnabled " , & flags , ImGuiTableColumnFlags_IsEnabled ) ;
ImGui : : CheckboxFlags ( " _IsVisible " , & flags , ImGuiTableColumnFlags_IsVisible ) ;
ImGui : : CheckboxFlags ( " _IsSorted " , & flags , ImGuiTableColumnFlags_IsSorted ) ;
ImGui : : CheckboxFlags ( " _IsHovered " , & flags , ImGuiTableColumnFlags_IsHovered ) ;
}
2024-07-19 12:35:57 +02:00
//-----------------------------------------------------------------------------
// [SECTION] ShowDemoWindowTables()
//-----------------------------------------------------------------------------
2019-12-19 14:52:18 +01:00
static void ShowDemoWindowTables ( )
{
//ImGui::SetNextItemOpen(true, ImGuiCond_Once);
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Tables " ) ;
2019-12-29 19:48:10 +01:00
if ( ! ImGui : : CollapsingHeader ( " Tables & Columns " ) )
2019-12-19 14:52:18 +01:00
return ;
2020-10-07 16:33:33 +02:00
// Using those as a base value to create width/height that are factor of the size of our font
const float TEXT_BASE_WIDTH = ImGui : : CalcTextSize ( " A " ) . x ;
const float TEXT_BASE_HEIGHT = ImGui : : GetTextLineHeightWithSpacing ( ) ;
2019-12-19 14:52:18 +01:00
ImGui : : PushID ( " Tables " ) ;
int open_action = - 1 ;
2023-10-12 14:43:34 +02:00
if ( ImGui : : Button ( " Expand all " ) )
2019-12-19 14:52:18 +01:00
open_action = 1 ;
ImGui : : SameLine ( ) ;
2023-10-12 14:43:34 +02:00
if ( ImGui : : Button ( " Collapse all " ) )
2019-12-19 14:52:18 +01:00
open_action = 0 ;
ImGui : : SameLine ( ) ;
// Options
static bool disable_indent = false ;
ImGui : : Checkbox ( " Disable tree indentation " , & disable_indent ) ;
ImGui : : SameLine ( ) ;
HelpMarker ( " Disable the indenting of tree nodes so demo tables can use the full window width. " ) ;
ImGui : : Separator ( ) ;
if ( disable_indent )
ImGui : : PushStyleVar ( ImGuiStyleVar_IndentSpacing , 0.0f ) ;
// About Styling of tables
// Most settings are configured on a per-table basis via the flags passed to BeginTable() and TableSetupColumns APIs.
// There are however a few settings that a shared and part of the ImGuiStyle structure:
2019-12-30 16:31:18 +01:00
// style.CellPadding // Padding within each cell
// style.Colors[ImGuiCol_TableHeaderBg] // Table header background
// style.Colors[ImGuiCol_TableBorderStrong] // Table outer and header borders
// style.Colors[ImGuiCol_TableBorderLight] // Table inner borders
// style.Colors[ImGuiCol_TableRowBg] // Table row background when ImGuiTableFlags_RowBg is enabled (even rows)
// style.Colors[ImGuiCol_TableRowBgAlt] // Table row background when ImGuiTableFlags_RowBg is enabled (odds rows)
2019-12-19 14:52:18 +01:00
// Demos
if ( open_action ! = - 1 )
ImGui : : SetNextItemOpen ( open_action ! = 0 ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Tables/Basic " ) ;
2019-12-19 14:52:18 +01:00
if ( ImGui : : TreeNode ( " Basic " ) )
{
2020-11-05 17:30:30 +01:00
// Here we will showcase three different ways to output a table.
// They are very simple variations of a same thing!
2020-05-22 15:27:53 +02:00
2020-11-05 17:30:30 +01:00
// [Method 1] Using TableNextRow() to create a new row, and TableSetColumnIndex() to select the column.
2020-05-22 15:27:53 +02:00
// In many situations, this is the most flexible and easy to use pattern.
2019-12-19 14:52:18 +01:00
HelpMarker ( " Using TableNextRow() + calling TableSetColumnIndex() _before_ each cell, in a loop. " ) ;
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table1 " , 3 ) )
2019-12-19 14:52:18 +01:00
{
for ( int row = 0 ; row < 4 ; row + + )
{
ImGui : : TableNextRow ( ) ;
for ( int column = 0 ; column < 3 ; column + + )
{
ImGui : : TableSetColumnIndex ( column ) ;
ImGui : : Text ( " Row %d Column %d " , row , column ) ;
}
}
ImGui : : EndTable ( ) ;
}
2020-11-05 17:30:30 +01:00
// [Method 2] Using TableNextColumn() called multiple times, instead of using a for loop + TableSetColumnIndex().
2022-09-11 07:35:59 +02:00
// This is generally more convenient when you have code manually submitting the contents of each column.
2020-10-01 14:03:25 +02:00
HelpMarker ( " Using TableNextRow() + calling TableNextColumn() _before_ each cell, manually. " ) ;
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table2 " , 3 ) )
2019-12-19 14:52:18 +01:00
{
for ( int row = 0 ; row < 4 ; row + + )
{
ImGui : : TableNextRow ( ) ;
2020-10-01 14:03:25 +02:00
ImGui : : TableNextColumn ( ) ;
2019-12-19 14:52:18 +01:00
ImGui : : Text ( " Row %d " , row ) ;
2020-10-01 14:03:25 +02:00
ImGui : : TableNextColumn ( ) ;
2019-12-19 14:52:18 +01:00
ImGui : : Text ( " Some contents " ) ;
2020-10-01 14:03:25 +02:00
ImGui : : TableNextColumn ( ) ;
2019-12-19 14:52:18 +01:00
ImGui : : Text ( " 123.456 " ) ;
}
ImGui : : EndTable ( ) ;
}
2020-11-05 17:30:30 +01:00
// [Method 3] We call TableNextColumn() _before_ each cell. We never call TableNextRow(),
2022-08-20 19:54:57 +02:00
// as TableNextColumn() will automatically wrap around and create new rows as needed.
2020-11-05 17:30:30 +01:00
// This is generally more convenient when your cells all contains the same type of data.
2020-10-07 16:33:33 +02:00
HelpMarker (
2024-01-04 11:50:38 +01:00
" Only using TableNextColumn(), which tends to be convenient for tables where every cell contains "
" the same type of contents. \n This is also more similar to the old NextColumn() function of the "
" Columns API, and provided to facilitate the Columns->Tables API transition. " ) ;
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table3 " , 3 ) )
2019-12-19 14:52:18 +01:00
{
for ( int item = 0 ; item < 14 ; item + + )
{
2020-10-01 14:03:25 +02:00
ImGui : : TableNextColumn ( ) ;
2019-12-19 14:52:18 +01:00
ImGui : : Text ( " Item %d " , item ) ;
}
ImGui : : EndTable ( ) ;
}
ImGui : : TreePop ( ) ;
}
if ( open_action ! = - 1 )
ImGui : : SetNextItemOpen ( open_action ! = 0 ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Tables/Borders, background " ) ;
2019-12-30 15:14:15 +01:00
if ( ImGui : : TreeNode ( " Borders, background " ) )
2019-12-19 14:52:18 +01:00
{
// Expose a few Borders related flags interactively
2020-10-06 15:08:27 +02:00
enum ContentsType { CT_Text , CT_FillButton } ;
2020-10-07 22:44:02 +02:00
static ImGuiTableFlags flags = ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg ;
2020-10-06 15:08:27 +02:00
static bool display_headers = false ;
static int contents_type = CT_Text ;
2020-10-07 16:33:33 +02:00
PushStyleCompact ( ) ;
2020-11-05 17:30:30 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_RowBg " , & flags , ImGuiTableFlags_RowBg ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_Borders " , & flags , ImGuiTableFlags_Borders ) ;
2024-07-08 11:43:09 +02:00
ImGui : : SameLine ( ) ; HelpMarker ( " ImGuiTableFlags_Borders \n = ImGuiTableFlags_BordersInnerV \n | ImGuiTableFlags_BordersOuterV \n | ImGuiTableFlags_BordersInnerH \n | ImGuiTableFlags_BordersOuterH " ) ;
2019-12-30 15:14:15 +01:00
ImGui : : Indent ( ) ;
2020-11-05 17:30:30 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_BordersH " , & flags , ImGuiTableFlags_BordersH ) ;
2019-12-30 15:14:15 +01:00
ImGui : : Indent ( ) ;
2020-11-05 17:30:30 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_BordersOuterH " , & flags , ImGuiTableFlags_BordersOuterH ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_BordersInnerH " , & flags , ImGuiTableFlags_BordersInnerH ) ;
2019-12-30 15:14:15 +01:00
ImGui : : Unindent ( ) ;
2020-11-05 17:30:30 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_BordersV " , & flags , ImGuiTableFlags_BordersV ) ;
2019-12-30 15:14:15 +01:00
ImGui : : Indent ( ) ;
2020-11-05 17:30:30 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_BordersOuterV " , & flags , ImGuiTableFlags_BordersOuterV ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_BordersInnerV " , & flags , ImGuiTableFlags_BordersInnerV ) ;
2019-12-30 15:14:15 +01:00
ImGui : : Unindent ( ) ;
2020-11-05 17:30:30 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_BordersOuter " , & flags , ImGuiTableFlags_BordersOuter ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_BordersInner " , & flags , ImGuiTableFlags_BordersInner ) ;
2019-12-30 15:14:15 +01:00
ImGui : : Unindent ( ) ;
2020-10-06 17:53:59 +02:00
2020-10-06 15:08:27 +02:00
ImGui : : AlignTextToFramePadding ( ) ; ImGui : : Text ( " Cell contents: " ) ;
ImGui : : SameLine ( ) ; ImGui : : RadioButton ( " Text " , & contents_type , CT_Text ) ;
ImGui : : SameLine ( ) ; ImGui : : RadioButton ( " FillButton " , & contents_type , CT_FillButton ) ;
ImGui : : Checkbox ( " Display headers " , & display_headers ) ;
2022-09-14 18:19:50 +02:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_NoBordersInBody " , & flags , ImGuiTableFlags_NoBordersInBody ) ; ImGui : : SameLine ( ) ; HelpMarker ( " Disable vertical borders in columns Body (borders will always appear in Headers " ) ;
2020-10-07 16:33:33 +02:00
PopStyleCompact ( ) ;
2019-12-19 14:52:18 +01:00
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table1 " , 3 , flags ) )
2019-12-19 14:52:18 +01:00
{
2024-01-04 11:50:38 +01:00
// Display headers so we can inspect their interaction with borders
// (Headers are not the main purpose of this section of the demo, so we are not elaborating on them now. See other sections for details)
2020-10-06 15:08:27 +02:00
if ( display_headers )
{
ImGui : : TableSetupColumn ( " One " ) ;
ImGui : : TableSetupColumn ( " Two " ) ;
ImGui : : TableSetupColumn ( " Three " ) ;
ImGui : : TableHeadersRow ( ) ;
}
2019-12-19 14:52:18 +01:00
for ( int row = 0 ; row < 5 ; row + + )
{
ImGui : : TableNextRow ( ) ;
for ( int column = 0 ; column < 3 ; column + + )
{
2020-12-03 16:29:08 +01:00
ImGui : : TableSetColumnIndex ( column ) ;
2020-10-07 22:44:02 +02:00
char buf [ 32 ] ;
2020-11-18 14:15:38 +01:00
sprintf ( buf , " Hello %d,%d " , column , row ) ;
2020-10-06 15:08:27 +02:00
if ( contents_type = = CT_Text )
ImGui : : TextUnformatted ( buf ) ;
2022-03-13 07:15:32 +01:00
else if ( contents_type = = CT_FillButton )
2020-10-06 15:08:27 +02:00
ImGui : : Button ( buf , ImVec2 ( - FLT_MIN , 0.0f ) ) ;
2019-12-19 14:52:18 +01:00
}
}
ImGui : : EndTable ( ) ;
}
ImGui : : TreePop ( ) ;
}
if ( open_action ! = - 1 )
ImGui : : SetNextItemOpen ( open_action ! = 0 ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Tables/Resizable, stretch " ) ;
2019-12-19 14:52:18 +01:00
if ( ImGui : : TreeNode ( " Resizable, stretch " ) )
{
2022-09-11 07:35:59 +02:00
// By default, if we don't enable ScrollX the sizing policy for each column is "Stretch"
// All columns maintain a sizing weight, and they will occupy all available width.
2021-01-08 18:07:16 +01:00
static ImGuiTableFlags flags = ImGuiTableFlags_SizingStretchSame | ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_ContextMenuInBody ;
2020-10-07 16:33:33 +02:00
PushStyleCompact ( ) ;
2020-11-05 17:30:30 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_Resizable " , & flags , ImGuiTableFlags_Resizable ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_BordersV " , & flags , ImGuiTableFlags_BordersV ) ;
2024-01-04 11:50:38 +01:00
ImGui : : SameLine ( ) ; HelpMarker (
" Using the _Resizable flag automatically enables the _BordersInnerV flag as well, "
" this is why the resize borders are still showing when unchecking this. " ) ;
2020-10-07 16:33:33 +02:00
PopStyleCompact ( ) ;
2020-05-22 15:27:53 +02:00
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table1 " , 3 , flags ) )
2019-12-19 14:52:18 +01:00
{
for ( int row = 0 ; row < 5 ; row + + )
{
ImGui : : TableNextRow ( ) ;
for ( int column = 0 ; column < 3 ; column + + )
{
ImGui : : TableSetColumnIndex ( column ) ;
2020-11-18 14:15:38 +01:00
ImGui : : Text ( " Hello %d,%d " , column , row ) ;
2019-12-19 14:52:18 +01:00
}
}
ImGui : : EndTable ( ) ;
}
ImGui : : TreePop ( ) ;
}
if ( open_action ! = - 1 )
ImGui : : SetNextItemOpen ( open_action ! = 0 ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Tables/Resizable, fixed " ) ;
2019-12-19 14:52:18 +01:00
if ( ImGui : : TreeNode ( " Resizable, fixed " ) )
{
2021-01-08 18:07:16 +01:00
// Here we use ImGuiTableFlags_SizingFixedFit (even though _ScrollX is not set)
2020-07-27 21:45:38 +02:00
// So columns will adopt the "Fixed" policy and will maintain a fixed width regardless of the whole available width (unless table is small)
2019-12-19 14:52:18 +01:00
// If there is not enough available width to fit all columns, they will however be resized down.
// FIXME-TABLE: Providing a stretch-on-init would make sense especially for tables which don't have saved settings
2020-10-26 18:28:49 +01:00
HelpMarker (
2021-01-08 18:07:16 +01:00
" Using _Resizable + _SizingFixedFit flags. \n "
2020-10-26 18:28:49 +01:00
" Fixed-width columns generally makes more sense if you want to use horizontal scrolling. \n \n "
" Double-click a column border to auto-fit the column to its contents. " ) ;
2021-01-06 17:39:41 +01:00
PushStyleCompact ( ) ;
2021-01-08 18:07:16 +01:00
static ImGuiTableFlags flags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_ContextMenuInBody ;
2021-01-21 16:59:34 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_NoHostExtendX " , & flags , ImGuiTableFlags_NoHostExtendX ) ;
2021-01-06 17:39:41 +01:00
PopStyleCompact ( ) ;
2020-12-21 19:09:11 +01:00
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table1 " , 3 , flags ) )
2019-12-19 14:52:18 +01:00
{
for ( int row = 0 ; row < 5 ; row + + )
{
ImGui : : TableNextRow ( ) ;
for ( int column = 0 ; column < 3 ; column + + )
{
ImGui : : TableSetColumnIndex ( column ) ;
2020-11-18 14:15:38 +01:00
ImGui : : Text ( " Hello %d,%d " , column , row ) ;
2019-12-19 14:52:18 +01:00
}
}
ImGui : : EndTable ( ) ;
}
ImGui : : TreePop ( ) ;
}
if ( open_action ! = - 1 )
ImGui : : SetNextItemOpen ( open_action ! = 0 ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Tables/Resizable, mixed " ) ;
2019-12-19 14:52:18 +01:00
if ( ImGui : : TreeNode ( " Resizable, mixed " ) )
{
2021-01-08 18:07:16 +01:00
HelpMarker (
" Using TableSetupColumn() to alter resizing policy on a per-column basis. \n \n "
" When combining Fixed and Stretch columns, generally you only want one, maybe two trailing columns to use _WidthStretch. " ) ;
static ImGuiTableFlags flags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_RowBg | ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable ;
2019-12-19 14:52:18 +01:00
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table1 " , 3 , flags ) )
2019-12-19 14:52:18 +01:00
{
2020-11-18 17:28:18 +01:00
ImGui : : TableSetupColumn ( " AAA " , ImGuiTableColumnFlags_WidthFixed ) ;
2019-12-19 14:52:18 +01:00
ImGui : : TableSetupColumn ( " BBB " , ImGuiTableColumnFlags_WidthFixed ) ;
ImGui : : TableSetupColumn ( " CCC " , ImGuiTableColumnFlags_WidthStretch ) ;
2020-09-24 14:33:40 +02:00
ImGui : : TableHeadersRow ( ) ;
2019-12-19 14:52:18 +01:00
for ( int row = 0 ; row < 5 ; row + + )
{
ImGui : : TableNextRow ( ) ;
for ( int column = 0 ; column < 3 ; column + + )
{
ImGui : : TableSetColumnIndex ( column ) ;
2020-11-18 14:15:38 +01:00
ImGui : : Text ( " %s %d,%d " , ( column = = 2 ) ? " Stretch " : " Fixed " , column , row ) ;
2019-12-19 14:52:18 +01:00
}
}
ImGui : : EndTable ( ) ;
}
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table2 " , 6 , flags ) )
2019-12-19 14:52:18 +01:00
{
ImGui : : TableSetupColumn ( " AAA " , ImGuiTableColumnFlags_WidthFixed ) ;
ImGui : : TableSetupColumn ( " BBB " , ImGuiTableColumnFlags_WidthFixed ) ;
ImGui : : TableSetupColumn ( " CCC " , ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_DefaultHide ) ;
ImGui : : TableSetupColumn ( " DDD " , ImGuiTableColumnFlags_WidthStretch ) ;
ImGui : : TableSetupColumn ( " EEE " , ImGuiTableColumnFlags_WidthStretch ) ;
ImGui : : TableSetupColumn ( " FFF " , ImGuiTableColumnFlags_WidthStretch | ImGuiTableColumnFlags_DefaultHide ) ;
2020-09-24 14:33:40 +02:00
ImGui : : TableHeadersRow ( ) ;
2019-12-19 14:52:18 +01:00
for ( int row = 0 ; row < 5 ; row + + )
{
ImGui : : TableNextRow ( ) ;
for ( int column = 0 ; column < 6 ; column + + )
{
ImGui : : TableSetColumnIndex ( column ) ;
2020-11-18 14:15:38 +01:00
ImGui : : Text ( " %s %d,%d " , ( column > = 3 ) ? " Stretch " : " Fixed " , column , row ) ;
2019-12-19 14:52:18 +01:00
}
}
ImGui : : EndTable ( ) ;
}
ImGui : : TreePop ( ) ;
}
if ( open_action ! = - 1 )
ImGui : : SetNextItemOpen ( open_action ! = 0 ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Tables/Reorderable, hideable, with headers " ) ;
2019-12-19 14:52:18 +01:00
if ( ImGui : : TreeNode ( " Reorderable, hideable, with headers " ) )
{
2021-01-08 18:08:35 +01:00
HelpMarker (
" Click and drag column headers to reorder columns. \n \n "
" Right-click on a header to open a context menu. " ) ;
2020-12-21 19:09:11 +01:00
static ImGuiTableFlags flags = ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV ;
2020-10-07 16:33:33 +02:00
PushStyleCompact ( ) ;
2020-11-05 17:30:30 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_Resizable " , & flags , ImGuiTableFlags_Resizable ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_Reorderable " , & flags , ImGuiTableFlags_Reorderable ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_Hideable " , & flags , ImGuiTableFlags_Hideable ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_NoBordersInBody " , & flags , ImGuiTableFlags_NoBordersInBody ) ;
2022-09-14 18:19:50 +02:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_NoBordersInBodyUntilResize " , & flags , ImGuiTableFlags_NoBordersInBodyUntilResize ) ; ImGui : : SameLine ( ) ; HelpMarker ( " Disable vertical borders in columns Body until hovered for resize (borders will always appear in Headers) " ) ;
2023-10-12 14:43:34 +02:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_HighlightHoveredColumn " , & flags , ImGuiTableFlags_HighlightHoveredColumn ) ;
2020-10-07 16:33:33 +02:00
PopStyleCompact ( ) ;
2020-05-22 15:27:53 +02:00
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table1 " , 3 , flags ) )
2019-12-19 14:52:18 +01:00
{
2020-09-24 14:33:40 +02:00
// Submit columns name with TableSetupColumn() and call TableHeadersRow() to create a row with a header in each column.
2019-12-19 14:52:18 +01:00
// (Later we will show how TableSetupColumn() has other uses, optional flags, sizing weight etc.)
ImGui : : TableSetupColumn ( " One " ) ;
ImGui : : TableSetupColumn ( " Two " ) ;
ImGui : : TableSetupColumn ( " Three " ) ;
2020-09-24 14:33:40 +02:00
ImGui : : TableHeadersRow ( ) ;
2019-12-19 14:52:18 +01:00
for ( int row = 0 ; row < 6 ; row + + )
{
ImGui : : TableNextRow ( ) ;
for ( int column = 0 ; column < 3 ; column + + )
{
ImGui : : TableSetColumnIndex ( column ) ;
2020-11-18 14:15:38 +01:00
ImGui : : Text ( " Hello %d,%d " , column , row ) ;
2019-12-19 14:52:18 +01:00
}
}
ImGui : : EndTable ( ) ;
}
2020-05-13 23:42:22 +02:00
2024-01-04 11:50:38 +01:00
// Use outer_size.x == 0.0f instead of default to make the table as tight as possible
// (only valid when no scrolling and no stretch column)
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table2 " , 3 , flags | ImGuiTableFlags_SizingFixedFit , ImVec2 ( 0.0f , 0.0f ) ) )
2020-05-13 23:42:22 +02:00
{
ImGui : : TableSetupColumn ( " One " ) ;
ImGui : : TableSetupColumn ( " Two " ) ;
ImGui : : TableSetupColumn ( " Three " ) ;
2020-09-24 14:33:40 +02:00
ImGui : : TableHeadersRow ( ) ;
2020-05-13 23:42:22 +02:00
for ( int row = 0 ; row < 6 ; row + + )
{
ImGui : : TableNextRow ( ) ;
for ( int column = 0 ; column < 3 ; column + + )
{
ImGui : : TableSetColumnIndex ( column ) ;
2020-11-18 14:15:38 +01:00
ImGui : : Text ( " Fixed %d,%d " , column , row ) ;
2020-05-13 23:42:22 +02:00
}
}
ImGui : : EndTable ( ) ;
}
2019-12-19 14:52:18 +01:00
ImGui : : TreePop ( ) ;
}
2020-10-07 22:44:02 +02:00
if ( open_action ! = - 1 )
ImGui : : SetNextItemOpen ( open_action ! = 0 ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Tables/Padding " ) ;
2020-10-07 22:44:02 +02:00
if ( ImGui : : TreeNode ( " Padding " ) )
{
2020-12-18 17:27:41 +01:00
// First example: showcase use of padding flags and effect of BorderOuterV/BorderInnerV on X padding.
// We don't expose BorderOuterH/BorderInnerH here because they have no effect on X padding.
2020-10-07 22:44:02 +02:00
HelpMarker (
" We often want outer padding activated when any using features which makes the edges of a column visible: \n "
" e.g.: \n "
" - BorderOuterV \n "
" - any form of row selection \n "
2024-01-04 11:50:38 +01:00
" Because of this, activating BorderOuterV sets the default to PadOuterX. "
" Using PadOuterX or NoPadOuterX you can override the default. \n \n "
2021-01-08 18:08:35 +01:00
" Actual padding values are using style.CellPadding. \n \n "
2022-09-14 18:19:50 +02:00
" In this demo we don't show horizontal borders to emphasize how they don't affect default horizontal padding. " ) ;
2020-10-07 22:44:02 +02:00
2020-12-18 17:27:41 +01:00
static ImGuiTableFlags flags1 = ImGuiTableFlags_BordersV ;
2020-10-07 22:44:02 +02:00
PushStyleCompact ( ) ;
2020-12-18 17:27:41 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_PadOuterX " , & flags1 , ImGuiTableFlags_PadOuterX ) ;
2020-10-07 22:44:02 +02:00
ImGui : : SameLine ( ) ; HelpMarker ( " Enable outer-most padding (default if ImGuiTableFlags_BordersOuterV is set) " ) ;
2020-12-18 17:27:41 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_NoPadOuterX " , & flags1 , ImGuiTableFlags_NoPadOuterX ) ;
2020-10-07 22:44:02 +02:00
ImGui : : SameLine ( ) ; HelpMarker ( " Disable outer-most padding (default if ImGuiTableFlags_BordersOuterV is not set) " ) ;
2020-12-18 17:27:41 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_NoPadInnerX " , & flags1 , ImGuiTableFlags_NoPadInnerX ) ;
2020-10-07 22:44:02 +02:00
ImGui : : SameLine ( ) ; HelpMarker ( " Disable inner padding between columns (double inner padding if BordersOuterV is on, single inner padding if BordersOuterV is off) " ) ;
2020-12-18 17:27:41 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_BordersOuterV " , & flags1 , ImGuiTableFlags_BordersOuterV ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_BordersInnerV " , & flags1 , ImGuiTableFlags_BordersInnerV ) ;
2020-11-16 12:30:17 +01:00
static bool show_headers = false ;
ImGui : : Checkbox ( " show_headers " , & show_headers ) ;
2020-10-07 22:44:02 +02:00
PopStyleCompact ( ) ;
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table_padding " , 3 , flags1 ) )
2020-10-07 22:44:02 +02:00
{
2020-11-16 12:30:17 +01:00
if ( show_headers )
{
ImGui : : TableSetupColumn ( " One " ) ;
ImGui : : TableSetupColumn ( " Two " ) ;
ImGui : : TableSetupColumn ( " Three " ) ;
ImGui : : TableHeadersRow ( ) ;
}
2020-10-07 22:44:02 +02:00
for ( int row = 0 ; row < 5 ; row + + )
{
ImGui : : TableNextRow ( ) ;
for ( int column = 0 ; column < 3 ; column + + )
{
ImGui : : TableSetColumnIndex ( column ) ;
if ( row = = 0 )
{
ImGui : : Text ( " Avail %.2f " , ImGui : : GetContentRegionAvail ( ) . x ) ;
}
else
{
char buf [ 32 ] ;
2020-11-18 14:15:38 +01:00
sprintf ( buf , " Hello %d,%d " , column , row ) ;
2020-10-07 22:44:02 +02:00
ImGui : : Button ( buf , ImVec2 ( - FLT_MIN , 0.0f ) ) ;
}
2020-12-04 17:54:40 +01:00
//if (ImGui::TableGetColumnFlags() & ImGuiTableColumnFlags_IsHovered)
2020-11-16 12:30:17 +01:00
// ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, IM_COL32(0, 100, 0, 255));
2020-10-07 22:44:02 +02:00
}
}
ImGui : : EndTable ( ) ;
}
2020-12-18 17:27:41 +01:00
// Second example: set style.CellPadding to (0.0) or a custom value.
// FIXME-TABLE: Vertical border effectively not displayed the same way as horizontal one...
HelpMarker ( " Setting style.CellPadding to (0,0) or a custom value. " ) ;
static ImGuiTableFlags flags2 = ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg ;
static ImVec2 cell_padding ( 0.0f , 0.0f ) ;
2021-01-08 18:08:35 +01:00
static bool show_widget_frame_bg = true ;
2020-12-18 17:27:41 +01:00
PushStyleCompact ( ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_Borders " , & flags2 , ImGuiTableFlags_Borders ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_BordersH " , & flags2 , ImGuiTableFlags_BordersH ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_BordersV " , & flags2 , ImGuiTableFlags_BordersV ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_BordersInner " , & flags2 , ImGuiTableFlags_BordersInner ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_BordersOuter " , & flags2 , ImGuiTableFlags_BordersOuter ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_RowBg " , & flags2 , ImGuiTableFlags_RowBg ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_Resizable " , & flags2 , ImGuiTableFlags_Resizable ) ;
ImGui : : Checkbox ( " show_widget_frame_bg " , & show_widget_frame_bg ) ;
ImGui : : SliderFloat2 ( " CellPadding " , & cell_padding . x , 0.0f , 10.0f , " %.0f " ) ;
PopStyleCompact ( ) ;
ImGui : : PushStyleVar ( ImGuiStyleVar_CellPadding , cell_padding ) ;
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table_padding_2 " , 3 , flags2 ) )
2020-12-18 17:27:41 +01:00
{
static char text_bufs [ 3 * 5 ] [ 16 ] ; // Mini text storage for 3x5 cells
static bool init = true ;
if ( ! show_widget_frame_bg )
ImGui : : PushStyleColor ( ImGuiCol_FrameBg , 0 ) ;
for ( int cell = 0 ; cell < 3 * 5 ; cell + + )
{
ImGui : : TableNextColumn ( ) ;
if ( init )
strcpy ( text_bufs [ cell ] , " edit me " ) ;
ImGui : : SetNextItemWidth ( - FLT_MIN ) ;
ImGui : : PushID ( cell ) ;
ImGui : : InputText ( " ##cell " , text_bufs [ cell ] , IM_ARRAYSIZE ( text_bufs [ cell ] ) ) ;
ImGui : : PopID ( ) ;
}
if ( ! show_widget_frame_bg )
ImGui : : PopStyleColor ( ) ;
init = false ;
ImGui : : EndTable ( ) ;
}
ImGui : : PopStyleVar ( ) ;
2020-10-07 22:44:02 +02:00
ImGui : : TreePop ( ) ;
}
2020-07-17 23:23:04 +02:00
if ( open_action ! = - 1 )
ImGui : : SetNextItemOpen ( open_action ! = 0 ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Tables/Explicit widths " ) ;
2021-01-06 17:39:41 +01:00
if ( ImGui : : TreeNode ( " Sizing policies " ) )
2020-07-17 23:23:04 +02:00
{
2021-01-08 18:38:55 +01:00
static ImGuiTableFlags flags1 = ImGuiTableFlags_BordersV | ImGuiTableFlags_BordersOuterH | ImGuiTableFlags_RowBg | ImGuiTableFlags_ContextMenuInBody ;
PushStyleCompact ( ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_Resizable " , & flags1 , ImGuiTableFlags_Resizable ) ;
2021-01-21 16:59:34 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_NoHostExtendX " , & flags1 , ImGuiTableFlags_NoHostExtendX ) ;
2021-01-08 18:38:55 +01:00
PopStyleCompact ( ) ;
static ImGuiTableFlags sizing_policy_flags [ 4 ] = { ImGuiTableFlags_SizingFixedFit , ImGuiTableFlags_SizingFixedSame , ImGuiTableFlags_SizingStretchProp , ImGuiTableFlags_SizingStretchSame } ;
for ( int table_n = 0 ; table_n < 4 ; table_n + + )
{
ImGui : : PushID ( table_n ) ;
ImGui : : SetNextItemWidth ( TEXT_BASE_WIDTH * 30 ) ;
EditTableSizingFlags ( & sizing_policy_flags [ table_n ] ) ;
// To make it easier to understand the different sizing policy,
2024-01-04 11:50:38 +01:00
// For each policy: we display one table where the columns have equal contents width,
// and one where the columns have different contents width.
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table1 " , 3 , sizing_policy_flags [ table_n ] | flags1 ) )
2021-01-08 18:38:55 +01:00
{
for ( int row = 0 ; row < 3 ; row + + )
{
ImGui : : TableNextRow ( ) ;
ImGui : : TableNextColumn ( ) ; ImGui : : Text ( " Oh dear " ) ;
ImGui : : TableNextColumn ( ) ; ImGui : : Text ( " Oh dear " ) ;
ImGui : : TableNextColumn ( ) ; ImGui : : Text ( " Oh dear " ) ;
}
ImGui : : EndTable ( ) ;
}
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table2 " , 3 , sizing_policy_flags [ table_n ] | flags1 ) )
2021-01-08 18:38:55 +01:00
{
for ( int row = 0 ; row < 3 ; row + + )
{
ImGui : : TableNextRow ( ) ;
ImGui : : TableNextColumn ( ) ; ImGui : : Text ( " AAAA " ) ;
ImGui : : TableNextColumn ( ) ; ImGui : : Text ( " BBBBBBBB " ) ;
ImGui : : TableNextColumn ( ) ; ImGui : : Text ( " CCCCCCCCCCCC " ) ;
}
ImGui : : EndTable ( ) ;
}
ImGui : : PopID ( ) ;
}
ImGui : : Spacing ( ) ;
ImGui : : TextUnformatted ( " Advanced " ) ;
ImGui : : SameLine ( ) ;
2024-01-04 11:50:38 +01:00
HelpMarker (
" This section allows you to interact and see the effect of various sizing policies "
" depending on whether Scroll is enabled and the contents of your columns. " ) ;
2021-01-08 18:08:35 +01:00
enum ContentsType { CT_ShowWidth , CT_ShortText , CT_LongText , CT_Button , CT_FillButton , CT_InputText } ;
static ImGuiTableFlags flags = ImGuiTableFlags_ScrollY | ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_Resizable ;
static int contents_type = CT_ShowWidth ;
2021-01-06 17:39:41 +01:00
static int column_count = 3 ;
2020-10-07 16:33:33 +02:00
PushStyleCompact ( ) ;
2021-01-08 18:38:55 +01:00
ImGui : : PushID ( " Advanced " ) ;
2021-01-06 17:39:41 +01:00
ImGui : : PushItemWidth ( TEXT_BASE_WIDTH * 30 ) ;
2021-01-08 18:38:55 +01:00
EditTableSizingFlags ( & flags ) ;
2021-01-08 18:08:35 +01:00
ImGui : : Combo ( " Contents " , & contents_type , " Show width \0 Short Text \0 Long Text \0 Button \0 Fill Button \0 InputText \0 " ) ;
2021-01-06 17:39:41 +01:00
if ( contents_type = = CT_FillButton )
{
ImGui : : SameLine ( ) ;
2024-01-04 11:50:38 +01:00
HelpMarker (
" Be mindful that using right-alignment (e.g. size.x = -FLT_MIN) creates a feedback loop "
" where contents width can feed into auto-column width can feed into contents width. " ) ;
2021-01-06 17:39:41 +01:00
}
ImGui : : DragInt ( " Columns " , & column_count , 0.1f , 1 , 64 , " %d " , ImGuiSliderFlags_AlwaysClamp ) ;
2021-01-08 18:07:16 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_Resizable " , & flags , ImGuiTableFlags_Resizable ) ;
2021-01-06 17:39:41 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_PreciseWidths " , & flags , ImGuiTableFlags_PreciseWidths ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Disable distributing remainder width to stretched columns (width allocation on a 100-wide table with 3 columns: Without this flag: 33,33,34. With this flag: 33,33,33). With larger number of columns, resizing will appear to be less smooth. " ) ;
2021-01-08 18:07:16 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_ScrollX " , & flags , ImGuiTableFlags_ScrollX ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_ScrollY " , & flags , ImGuiTableFlags_ScrollY ) ;
2021-01-06 17:39:41 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_NoClip " , & flags , ImGuiTableFlags_NoClip ) ;
2021-01-08 18:07:16 +01:00
ImGui : : PopItemWidth ( ) ;
2021-01-08 18:38:55 +01:00
ImGui : : PopID ( ) ;
2020-10-07 16:33:33 +02:00
PopStyleCompact ( ) ;
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table2 " , column_count , flags , ImVec2 ( 0.0f , TEXT_BASE_HEIGHT * 7 ) ) )
2020-07-17 23:23:04 +02:00
{
2021-01-06 17:39:41 +01:00
for ( int cell = 0 ; cell < 10 * column_count ; cell + + )
2020-07-17 23:23:04 +02:00
{
2021-01-06 17:39:41 +01:00
ImGui : : TableNextColumn ( ) ;
int column = ImGui : : TableGetColumnIndex ( ) ;
int row = ImGui : : TableGetRowIndex ( ) ;
ImGui : : PushID ( cell ) ;
char label [ 32 ] ;
static char text_buf [ 32 ] = " " ;
sprintf ( label , " Hello %d,%d " , column , row ) ;
switch ( contents_type )
2020-07-17 23:23:04 +02:00
{
2021-01-06 17:39:41 +01:00
case CT_ShortText : ImGui : : TextUnformatted ( label ) ; break ;
2021-01-08 18:08:35 +01:00
case CT_LongText : ImGui : : Text ( " Some %s text %d,%d \n Over two lines.. " , column = = 0 ? " long " : " longeeer " , column , row ) ; break ;
case CT_ShowWidth : ImGui : : Text ( " W: %.1f " , ImGui : : GetContentRegionAvail ( ) . x ) ; break ;
2021-01-06 17:39:41 +01:00
case CT_Button : ImGui : : Button ( label ) ; break ;
case CT_FillButton : ImGui : : Button ( label , ImVec2 ( - FLT_MIN , 0.0f ) ) ; break ;
case CT_InputText : ImGui : : SetNextItemWidth ( - FLT_MIN ) ; ImGui : : InputText ( " ## " , text_buf , IM_ARRAYSIZE ( text_buf ) ) ; break ;
2020-07-17 23:23:04 +02:00
}
2021-01-06 17:39:41 +01:00
ImGui : : PopID ( ) ;
2020-07-17 23:23:04 +02:00
}
ImGui : : EndTable ( ) ;
}
ImGui : : TreePop ( ) ;
}
2019-12-19 14:52:18 +01:00
if ( open_action ! = - 1 )
ImGui : : SetNextItemOpen ( open_action ! = 0 ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Tables/Vertical scrolling, with clipping " ) ;
2020-11-03 18:47:05 +01:00
if ( ImGui : : TreeNode ( " Vertical scrolling, with clipping " ) )
2019-12-19 14:52:18 +01:00
{
2024-01-04 11:50:38 +01:00
HelpMarker (
" Here we activate ScrollY, which will create a child window container to allow hosting scrollable contents. \n \n "
" We also demonstrate using ImGuiListClipper to virtualize the submission of many items. " ) ;
2020-09-23 17:53:52 +02:00
static ImGuiTableFlags flags = ImGuiTableFlags_ScrollY | ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable ;
2020-10-07 16:33:33 +02:00
PushStyleCompact ( ) ;
2020-11-05 17:30:30 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_ScrollY " , & flags , ImGuiTableFlags_ScrollY ) ;
2020-10-07 16:33:33 +02:00
PopStyleCompact ( ) ;
2020-05-22 15:27:53 +02:00
2020-10-07 16:33:33 +02:00
// When using ScrollX or ScrollY we need to specify a size for our table container!
// Otherwise by default the table will fit all available space, like a BeginChild() call.
2021-01-21 16:20:31 +01:00
ImVec2 outer_size = ImVec2 ( 0.0f , TEXT_BASE_HEIGHT * 8 ) ;
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table_scrolly " , 3 , flags , outer_size ) )
2019-12-19 14:52:18 +01:00
{
2020-09-23 17:53:52 +02:00
ImGui : : TableSetupScrollFreeze ( 0 , 1 ) ; // Make top row always visible
2019-12-19 14:52:18 +01:00
ImGui : : TableSetupColumn ( " One " , ImGuiTableColumnFlags_None ) ;
ImGui : : TableSetupColumn ( " Two " , ImGuiTableColumnFlags_None ) ;
ImGui : : TableSetupColumn ( " Three " , ImGuiTableColumnFlags_None ) ;
2020-09-24 14:33:40 +02:00
ImGui : : TableHeadersRow ( ) ;
2020-11-03 18:47:05 +01:00
// Demonstrate using clipper for large vertical lists
2019-12-19 14:52:18 +01:00
ImGuiListClipper clipper ;
clipper . Begin ( 1000 ) ;
while ( clipper . Step ( ) )
{
for ( int row = clipper . DisplayStart ; row < clipper . DisplayEnd ; row + + )
{
ImGui : : TableNextRow ( ) ;
for ( int column = 0 ; column < 3 ; column + + )
{
ImGui : : TableSetColumnIndex ( column ) ;
2020-11-18 14:15:38 +01:00
ImGui : : Text ( " Hello %d,%d " , column , row ) ;
2019-12-19 14:52:18 +01:00
}
}
}
ImGui : : EndTable ( ) ;
}
ImGui : : TreePop ( ) ;
}
if ( open_action ! = - 1 )
ImGui : : SetNextItemOpen ( open_action ! = 0 ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Tables/Horizontal scrolling " ) ;
2019-12-19 14:52:18 +01:00
if ( ImGui : : TreeNode ( " Horizontal scrolling " ) )
{
2020-11-18 20:55:01 +01:00
HelpMarker (
2021-01-08 18:07:16 +01:00
" When ScrollX is enabled, the default sizing policy becomes ImGuiTableFlags_SizingFixedFit, "
2020-11-18 20:55:01 +01:00
" as automatically stretching columns doesn't make much sense with horizontal scrolling. \n \n "
2024-01-04 11:50:38 +01:00
" Also note that as of the current version, you will almost always want to enable ScrollY along with ScrollX, "
" because the container window won't automatically extend vertically to fix contents "
" (this may be improved in future versions). " ) ;
2020-09-23 17:53:52 +02:00
static ImGuiTableFlags flags = ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY | ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable ;
static int freeze_cols = 1 ;
static int freeze_rows = 1 ;
2020-10-07 16:33:33 +02:00
PushStyleCompact ( ) ;
2020-12-23 12:11:39 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_Resizable " , & flags , ImGuiTableFlags_Resizable ) ;
2020-11-05 17:30:30 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_ScrollX " , & flags , ImGuiTableFlags_ScrollX ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_ScrollY " , & flags , ImGuiTableFlags_ScrollY ) ;
2020-09-23 17:53:52 +02:00
ImGui : : SetNextItemWidth ( ImGui : : GetFrameHeight ( ) ) ;
ImGui : : DragInt ( " freeze_cols " , & freeze_cols , 0.2f , 0 , 9 , NULL , ImGuiSliderFlags_NoInput ) ;
ImGui : : SetNextItemWidth ( ImGui : : GetFrameHeight ( ) ) ;
ImGui : : DragInt ( " freeze_rows " , & freeze_rows , 0.2f , 0 , 9 , NULL , ImGuiSliderFlags_NoInput ) ;
2020-10-07 16:33:33 +02:00
PopStyleCompact ( ) ;
2020-01-09 17:31:26 +01:00
2020-10-07 16:33:33 +02:00
// When using ScrollX or ScrollY we need to specify a size for our table container!
// Otherwise by default the table will fit all available space, like a BeginChild() call.
2021-01-21 16:20:31 +01:00
ImVec2 outer_size = ImVec2 ( 0.0f , TEXT_BASE_HEIGHT * 8 ) ;
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table_scrollx " , 7 , flags , outer_size ) )
2019-12-19 14:52:18 +01:00
{
2020-09-23 17:53:52 +02:00
ImGui : : TableSetupScrollFreeze ( freeze_cols , freeze_rows ) ;
ImGui : : TableSetupColumn ( " Line # " , ImGuiTableColumnFlags_NoHide ) ; // Make the first column not hideable to match our use of TableSetupScrollFreeze()
2020-12-03 16:29:08 +01:00
ImGui : : TableSetupColumn ( " One " ) ;
ImGui : : TableSetupColumn ( " Two " ) ;
ImGui : : TableSetupColumn ( " Three " ) ;
ImGui : : TableSetupColumn ( " Four " ) ;
ImGui : : TableSetupColumn ( " Five " ) ;
ImGui : : TableSetupColumn ( " Six " ) ;
2020-09-24 14:33:40 +02:00
ImGui : : TableHeadersRow ( ) ;
2019-12-19 14:52:18 +01:00
for ( int row = 0 ; row < 20 ; row + + )
{
ImGui : : TableNextRow ( ) ;
for ( int column = 0 ; column < 7 ; column + + )
{
2020-12-03 18:45:15 +01:00
// Both TableNextColumn() and TableSetColumnIndex() return true when a column is visible or performing width measurement.
// Because here we know that:
// - A) all our columns are contributing the same to row height
// - B) column 0 is always visible,
// We only always submit this one column and can skip others.
// More advanced per-column clipping behaviors may benefit from polling the status flags via TableGetColumnFlags().
2020-12-03 16:29:08 +01:00
if ( ! ImGui : : TableSetColumnIndex ( column ) & & column > 0 )
2019-12-28 19:17:59 +01:00
continue ;
2019-12-19 14:52:18 +01:00
if ( column = = 0 )
ImGui : : Text ( " Line %d " , row ) ;
else
2020-11-18 14:15:38 +01:00
ImGui : : Text ( " Hello world %d,%d " , column , row ) ;
2019-12-19 14:52:18 +01:00
}
}
ImGui : : EndTable ( ) ;
}
2021-01-06 17:39:41 +01:00
ImGui : : Spacing ( ) ;
ImGui : : TextUnformatted ( " Stretch + ScrollX " ) ;
ImGui : : SameLine ( ) ;
HelpMarker (
" Showcase using Stretch columns + ScrollX together: "
" this is rather unusual and only makes sense when specifying an 'inner_width' for the table! \n "
2024-01-04 11:50:38 +01:00
" Without an explicit value, inner_width is == outer_size.x and therefore using Stretch columns "
" along with ScrollX doesn't make sense. " ) ;
2021-01-08 18:07:16 +01:00
static ImGuiTableFlags flags2 = ImGuiTableFlags_SizingStretchSame | ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_RowBg | ImGuiTableFlags_ContextMenuInBody ;
2021-01-06 17:39:41 +01:00
static float inner_width = 1000.0f ;
PushStyleCompact ( ) ;
ImGui : : PushID ( " flags3 " ) ;
ImGui : : PushItemWidth ( TEXT_BASE_WIDTH * 30 ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_ScrollX " , & flags2 , ImGuiTableFlags_ScrollX ) ;
ImGui : : DragFloat ( " inner_width " , & inner_width , 1.0f , 0.0f , FLT_MAX , " %.1f " ) ;
ImGui : : PopItemWidth ( ) ;
ImGui : : PopID ( ) ;
PopStyleCompact ( ) ;
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table2 " , 7 , flags2 , outer_size , inner_width ) )
2021-01-06 17:39:41 +01:00
{
for ( int cell = 0 ; cell < 20 * 7 ; cell + + )
{
ImGui : : TableNextColumn ( ) ;
ImGui : : Text ( " Hello world %d,%d " , ImGui : : TableGetColumnIndex ( ) , ImGui : : TableGetRowIndex ( ) ) ;
}
ImGui : : EndTable ( ) ;
}
2019-12-19 14:52:18 +01:00
ImGui : : TreePop ( ) ;
}
if ( open_action ! = - 1 )
ImGui : : SetNextItemOpen ( open_action ! = 0 ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Tables/Columns flags " ) ;
2019-12-19 14:52:18 +01:00
if ( ImGui : : TreeNode ( " Columns flags " ) )
{
// Create a first table just to show all the options/flags we want to make visible in our example!
const int column_count = 3 ;
const char * column_names [ column_count ] = { " One " , " Two " , " Three " } ;
static ImGuiTableColumnFlags column_flags [ column_count ] = { ImGuiTableColumnFlags_DefaultSort , ImGuiTableColumnFlags_None , ImGuiTableColumnFlags_DefaultHide } ;
2020-12-03 18:45:15 +01:00
static ImGuiTableColumnFlags column_flags_out [ column_count ] = { 0 , 0 , 0 } ; // Output from TableGetColumnFlags()
2019-12-19 14:52:18 +01:00
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table_columns_flags_checkboxes " , column_count , ImGuiTableFlags_None ) )
2019-12-19 14:52:18 +01:00
{
2020-10-07 16:33:33 +02:00
PushStyleCompact ( ) ;
2019-12-19 14:52:18 +01:00
for ( int column = 0 ; column < column_count ; column + + )
{
2020-10-01 14:03:25 +02:00
ImGui : : TableNextColumn ( ) ;
2019-12-19 14:52:18 +01:00
ImGui : : PushID ( column ) ;
2022-04-14 15:09:56 +02:00
ImGui : : AlignTextToFramePadding ( ) ; // FIXME-TABLE: Workaround for wrong text baseline propagation across columns
2020-12-03 18:45:15 +01:00
ImGui : : Text ( " '%s' " , column_names [ column ] ) ;
ImGui : : Spacing ( ) ;
ImGui : : Text ( " Input flags: " ) ;
2020-11-18 17:28:18 +01:00
EditTableColumnsFlags ( & column_flags [ column ] ) ;
2020-12-03 18:45:15 +01:00
ImGui : : Spacing ( ) ;
ImGui : : Text ( " Output flags: " ) ;
2022-04-14 15:09:56 +02:00
ImGui : : BeginDisabled ( ) ;
2020-12-03 18:45:15 +01:00
ShowTableColumnsStatusFlags ( column_flags_out [ column ] ) ;
2022-04-14 15:09:56 +02:00
ImGui : : EndDisabled ( ) ;
2019-12-19 14:52:18 +01:00
ImGui : : PopID ( ) ;
}
2020-10-07 16:33:33 +02:00
PopStyleCompact ( ) ;
2019-12-19 14:52:18 +01:00
ImGui : : EndTable ( ) ;
}
// Create the real table we care about for the example!
2024-01-04 11:50:38 +01:00
// We use a scrolling table to be able to showcase the difference between the _IsEnabled and _IsVisible flags above,
// otherwise in a non-scrolling table columns are always visible (unless using ImGuiTableFlags_NoKeepColumnsVisible
// + resizing the parent window down).
2020-12-03 18:45:15 +01:00
const ImGuiTableFlags flags
2021-01-08 18:07:16 +01:00
= ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY
2020-12-03 18:45:15 +01:00
| ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV
| ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Sortable ;
2021-01-21 16:20:31 +01:00
ImVec2 outer_size = ImVec2 ( 0.0f , TEXT_BASE_HEIGHT * 9 ) ;
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table_columns_flags " , column_count , flags , outer_size ) )
2019-12-19 14:52:18 +01:00
{
2023-10-12 17:01:42 +02:00
bool has_angled_header = false ;
2019-12-19 14:52:18 +01:00
for ( int column = 0 ; column < column_count ; column + + )
2023-10-12 17:01:42 +02:00
{
has_angled_header | = ( column_flags [ column ] & ImGuiTableColumnFlags_AngledHeader ) ! = 0 ;
2019-12-19 14:52:18 +01:00
ImGui : : TableSetupColumn ( column_names [ column ] , column_flags [ column ] ) ;
2023-10-12 17:01:42 +02:00
}
if ( has_angled_header )
ImGui : : TableAngledHeadersRow ( ) ;
2020-09-24 14:33:40 +02:00
ImGui : : TableHeadersRow ( ) ;
2020-12-03 18:45:15 +01:00
for ( int column = 0 ; column < column_count ; column + + )
column_flags_out [ column ] = ImGui : : TableGetColumnFlags ( column ) ;
2020-10-07 16:33:33 +02:00
float indent_step = ( float ) ( ( int ) TEXT_BASE_WIDTH / 2 ) ;
2019-12-19 14:52:18 +01:00
for ( int row = 0 ; row < 8 ; row + + )
{
2024-01-04 11:50:38 +01:00
// Add some indentation to demonstrate usage of per-column IndentEnable/IndentDisable flags.
ImGui : : Indent ( indent_step ) ;
2019-12-19 14:52:18 +01:00
ImGui : : TableNextRow ( ) ;
for ( int column = 0 ; column < column_count ; column + + )
{
ImGui : : TableSetColumnIndex ( column ) ;
2020-01-09 21:10:45 +01:00
ImGui : : Text ( " %s %s " , ( column = = 0 ) ? " Indented " : " Hello " , ImGui : : TableGetColumnName ( column ) ) ;
2019-12-19 14:52:18 +01:00
}
}
2020-10-07 16:33:33 +02:00
ImGui : : Unindent ( indent_step * 8.0f ) ;
2020-01-09 21:10:45 +01:00
2019-12-19 14:52:18 +01:00
ImGui : : EndTable ( ) ;
}
ImGui : : TreePop ( ) ;
}
if ( open_action ! = - 1 )
ImGui : : SetNextItemOpen ( open_action ! = 0 ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Tables/Columns widths " ) ;
2021-01-06 17:39:41 +01:00
if ( ImGui : : TreeNode ( " Columns widths " ) )
{
2021-01-14 11:21:13 +01:00
HelpMarker ( " Using TableSetupColumn() to setup default width. " ) ;
2021-01-06 17:39:41 +01:00
2021-01-14 11:21:13 +01:00
static ImGuiTableFlags flags1 = ImGuiTableFlags_Borders | ImGuiTableFlags_NoBordersInBodyUntilResize ;
2021-01-06 17:39:41 +01:00
PushStyleCompact ( ) ;
2021-01-14 11:21:13 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_Resizable " , & flags1 , ImGuiTableFlags_Resizable ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_NoBordersInBodyUntilResize " , & flags1 , ImGuiTableFlags_NoBordersInBodyUntilResize ) ;
2021-01-06 17:39:41 +01:00
PopStyleCompact ( ) ;
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table1 " , 3 , flags1 ) )
2021-01-14 11:21:13 +01:00
{
// We could also set ImGuiTableFlags_SizingFixedFit on the table and all columns will default to ImGuiTableColumnFlags_WidthFixed.
ImGui : : TableSetupColumn ( " one " , ImGuiTableColumnFlags_WidthFixed , 100.0f ) ; // Default to 100.0f
ImGui : : TableSetupColumn ( " two " , ImGuiTableColumnFlags_WidthFixed , 200.0f ) ; // Default to 200.0f
ImGui : : TableSetupColumn ( " three " , ImGuiTableColumnFlags_WidthFixed ) ; // Default to auto
ImGui : : TableHeadersRow ( ) ;
for ( int row = 0 ; row < 4 ; row + + )
{
ImGui : : TableNextRow ( ) ;
for ( int column = 0 ; column < 3 ; column + + )
{
ImGui : : TableSetColumnIndex ( column ) ;
if ( row = = 0 )
ImGui : : Text ( " (w: %5.1f) " , ImGui : : GetContentRegionAvail ( ) . x ) ;
else
ImGui : : Text ( " Hello %d,%d " , column , row ) ;
}
}
ImGui : : EndTable ( ) ;
}
2021-01-06 17:39:41 +01:00
2024-01-04 11:50:38 +01:00
HelpMarker (
" Using TableSetupColumn() to setup explicit width. \n \n Unless _NoKeepColumnsVisible is set, "
" fixed columns with set width may still be shrunk down if there's not enough space in the host. " ) ;
2021-01-14 11:21:13 +01:00
static ImGuiTableFlags flags2 = ImGuiTableFlags_None ;
PushStyleCompact ( ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_NoKeepColumnsVisible " , & flags2 , ImGuiTableFlags_NoKeepColumnsVisible ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_BordersInnerV " , & flags2 , ImGuiTableFlags_BordersInnerV ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_BordersOuterV " , & flags2 , ImGuiTableFlags_BordersOuterV ) ;
PopStyleCompact ( ) ;
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table2 " , 4 , flags2 ) )
2021-01-06 17:39:41 +01:00
{
2024-01-04 11:50:38 +01:00
// We could also set ImGuiTableFlags_SizingFixedFit on the table and then all columns
// will default to ImGuiTableColumnFlags_WidthFixed.
2021-01-06 17:39:41 +01:00
ImGui : : TableSetupColumn ( " " , ImGuiTableColumnFlags_WidthFixed , 100.0f ) ;
ImGui : : TableSetupColumn ( " " , ImGuiTableColumnFlags_WidthFixed , TEXT_BASE_WIDTH * 15.0f ) ;
ImGui : : TableSetupColumn ( " " , ImGuiTableColumnFlags_WidthFixed , TEXT_BASE_WIDTH * 30.0f ) ;
ImGui : : TableSetupColumn ( " " , ImGuiTableColumnFlags_WidthFixed , TEXT_BASE_WIDTH * 15.0f ) ;
for ( int row = 0 ; row < 5 ; row + + )
{
ImGui : : TableNextRow ( ) ;
for ( int column = 0 ; column < 4 ; column + + )
{
ImGui : : TableSetColumnIndex ( column ) ;
if ( row = = 0 )
2021-01-14 11:21:13 +01:00
ImGui : : Text ( " (w: %5.1f) " , ImGui : : GetContentRegionAvail ( ) . x ) ;
else
ImGui : : Text ( " Hello %d,%d " , column , row ) ;
2021-01-06 17:39:41 +01:00
}
}
ImGui : : EndTable ( ) ;
}
ImGui : : TreePop ( ) ;
}
if ( open_action ! = - 1 )
ImGui : : SetNextItemOpen ( open_action ! = 0 ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Tables/Nested tables " ) ;
2021-01-06 17:39:41 +01:00
if ( ImGui : : TreeNode ( " Nested tables " ) )
2019-12-19 14:52:18 +01:00
{
2022-09-14 18:19:50 +02:00
HelpMarker ( " This demonstrates embedding a table into another table cell. " ) ;
2020-05-22 15:27:53 +02:00
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table_nested1 " , 2 , ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable ) )
2019-12-19 14:52:18 +01:00
{
ImGui : : TableSetupColumn ( " A0 " ) ;
ImGui : : TableSetupColumn ( " A1 " ) ;
2020-09-24 14:33:40 +02:00
ImGui : : TableHeadersRow ( ) ;
2019-12-19 14:52:18 +01:00
2020-10-01 14:03:25 +02:00
ImGui : : TableNextColumn ( ) ;
2021-01-28 20:52:26 +01:00
ImGui : : Text ( " A0 Row 0 " ) ;
2019-12-19 14:52:18 +01:00
{
2020-10-07 16:33:33 +02:00
float rows_height = TEXT_BASE_HEIGHT * 2 ;
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table_nested2 " , 2 , ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable ) )
2019-12-19 14:52:18 +01:00
{
ImGui : : TableSetupColumn ( " B0 " ) ;
ImGui : : TableSetupColumn ( " B1 " ) ;
2020-09-24 14:33:40 +02:00
ImGui : : TableHeadersRow ( ) ;
2019-12-19 14:52:18 +01:00
ImGui : : TableNextRow ( ImGuiTableRowFlags_None , rows_height ) ;
2020-10-01 14:03:25 +02:00
ImGui : : TableNextColumn ( ) ;
2021-01-28 20:52:26 +01:00
ImGui : : Text ( " B0 Row 0 " ) ;
2020-10-01 14:03:25 +02:00
ImGui : : TableNextColumn ( ) ;
2021-01-28 20:52:26 +01:00
ImGui : : Text ( " B1 Row 0 " ) ;
2019-12-19 14:52:18 +01:00
ImGui : : TableNextRow ( ImGuiTableRowFlags_None , rows_height ) ;
2020-10-01 14:03:25 +02:00
ImGui : : TableNextColumn ( ) ;
2021-01-28 20:52:26 +01:00
ImGui : : Text ( " B0 Row 1 " ) ;
2020-10-01 14:03:25 +02:00
ImGui : : TableNextColumn ( ) ;
2021-01-28 20:52:26 +01:00
ImGui : : Text ( " B1 Row 1 " ) ;
2019-12-19 14:52:18 +01:00
ImGui : : EndTable ( ) ;
}
}
2021-01-28 20:52:26 +01:00
ImGui : : TableNextColumn ( ) ; ImGui : : Text ( " A1 Row 0 " ) ;
ImGui : : TableNextColumn ( ) ; ImGui : : Text ( " A0 Row 1 " ) ;
ImGui : : TableNextColumn ( ) ; ImGui : : Text ( " A1 Row 1 " ) ;
2019-12-19 14:52:18 +01:00
ImGui : : EndTable ( ) ;
}
ImGui : : TreePop ( ) ;
}
2020-01-03 00:31:06 +01:00
if ( open_action ! = - 1 )
ImGui : : SetNextItemOpen ( open_action ! = 0 ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Tables/Row height " ) ;
2020-01-03 00:31:06 +01:00
if ( ImGui : : TreeNode ( " Row height " ) )
{
2024-01-04 11:50:38 +01:00
HelpMarker (
" You can pass a 'min_row_height' to TableNextRow(). \n \n Rows are padded with 'style.CellPadding.y' on top and bottom, "
" so effectively the minimum row height will always be >= 'style.CellPadding.y * 2.0f'. \n \n "
" We cannot honor a _maximum_ row height as that would require a unique clipping rectangle per row. " ) ;
2023-08-14 13:02:44 +02:00
if ( ImGui : : BeginTable ( " table_row_height " , 1 , ImGuiTableFlags_Borders ) )
2020-01-03 00:31:06 +01:00
{
2023-09-04 11:20:20 +02:00
for ( int row = 0 ; row < 8 ; row + + )
2020-01-03 00:31:06 +01:00
{
2020-10-07 16:33:33 +02:00
float min_row_height = ( float ) ( int ) ( TEXT_BASE_HEIGHT * 0.30f * row ) ;
2020-01-03 00:31:06 +01:00
ImGui : : TableNextRow ( ImGuiTableRowFlags_None , min_row_height ) ;
2020-10-01 14:03:25 +02:00
ImGui : : TableNextColumn ( ) ;
2020-01-03 00:31:06 +01:00
ImGui : : Text ( " min_row_height = %.2f " , min_row_height ) ;
}
ImGui : : EndTable ( ) ;
}
2023-08-14 13:02:44 +02:00
2024-01-04 11:50:38 +01:00
HelpMarker (
" Showcase using SameLine(0,0) to share Current Line Height between cells. \n \n "
" Please note that Tables Row Height is not the same thing as Current Line Height, "
" as a table cell may contains multiple lines. " ) ;
2023-08-14 13:02:44 +02:00
if ( ImGui : : BeginTable ( " table_share_lineheight " , 2 , ImGuiTableFlags_Borders ) )
{
ImGui : : TableNextRow ( ) ;
ImGui : : TableNextColumn ( ) ;
ImGui : : ColorButton ( " ##1 " , ImVec4 ( 0.13f , 0.26f , 0.40f , 1.0f ) , ImGuiColorEditFlags_None , ImVec2 ( 40 , 40 ) ) ;
ImGui : : TableNextColumn ( ) ;
ImGui : : Text ( " Line 1 " ) ;
ImGui : : Text ( " Line 2 " ) ;
ImGui : : TableNextRow ( ) ;
ImGui : : TableNextColumn ( ) ;
ImGui : : ColorButton ( " ##2 " , ImVec4 ( 0.13f , 0.26f , 0.40f , 1.0f ) , ImGuiColorEditFlags_None , ImVec2 ( 40 , 40 ) ) ;
ImGui : : TableNextColumn ( ) ;
ImGui : : SameLine ( 0.0f , 0.0f ) ; // Reuse line height from previous column
ImGui : : Text ( " Line 1, with SameLine(0,0) " ) ;
ImGui : : Text ( " Line 2 " ) ;
ImGui : : EndTable ( ) ;
}
2023-09-04 11:20:20 +02:00
HelpMarker ( " Showcase altering CellPadding.y between rows. Note that CellPadding.x is locked for the entire table. " ) ;
if ( ImGui : : BeginTable ( " table_changing_cellpadding_y " , 1 , ImGuiTableFlags_Borders ) )
{
ImGuiStyle & style = ImGui : : GetStyle ( ) ;
for ( int row = 0 ; row < 8 ; row + + )
{
if ( ( row % 3 ) = = 2 )
2024-08-22 13:46:54 +02:00
ImGui : : PushStyleVarY ( ImGuiStyleVar_CellPadding , 20.0f ) ;
2023-09-04 11:20:20 +02:00
ImGui : : TableNextRow ( ImGuiTableRowFlags_None ) ;
ImGui : : TableNextColumn ( ) ;
ImGui : : Text ( " CellPadding.y = %.2f " , style . CellPadding . y ) ;
if ( ( row % 3 ) = = 2 )
2023-09-04 15:16:55 +02:00
ImGui : : PopStyleVar ( ) ;
2023-09-04 11:20:20 +02:00
}
ImGui : : EndTable ( ) ;
}
2020-01-03 00:31:06 +01:00
ImGui : : TreePop ( ) ;
}
2020-12-04 19:02:35 +01:00
if ( open_action ! = - 1 )
ImGui : : SetNextItemOpen ( open_action ! = 0 ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Tables/Outer size " ) ;
2020-12-04 19:02:35 +01:00
if ( ImGui : : TreeNode ( " Outer size " ) )
{
2021-01-21 16:20:31 +01:00
// Showcasing use of ImGuiTableFlags_NoHostExtendX and ImGuiTableFlags_NoHostExtendY
// Important to that note how the two flags have slightly different behaviors!
ImGui : : Text ( " Using NoHostExtendX and NoHostExtendY: " ) ;
2021-01-06 17:39:41 +01:00
PushStyleCompact ( ) ;
2021-01-21 16:20:31 +01:00
static ImGuiTableFlags flags = ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_ContextMenuInBody | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_NoHostExtendX ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_NoHostExtendX " , & flags , ImGuiTableFlags_NoHostExtendX ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Make outer width auto-fit to columns, overriding outer_size.x value. \n \n Only available when ScrollX/ScrollY are disabled and Stretch columns are not used. " ) ;
2020-12-18 17:27:41 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_NoHostExtendY " , & flags , ImGuiTableFlags_NoHostExtendY ) ;
2021-01-21 16:20:31 +01:00
ImGui : : SameLine ( ) ; HelpMarker ( " Make outer height stop exactly at outer_size.y (prevent auto-extending table past the limit). \n \n Only available when ScrollX/ScrollY are disabled. Data below the limit will be clipped and not visible. " ) ;
2021-01-06 17:39:41 +01:00
PopStyleCompact ( ) ;
2021-01-21 16:20:31 +01:00
ImVec2 outer_size = ImVec2 ( 0.0f , TEXT_BASE_HEIGHT * 5.5f ) ;
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table1 " , 3 , flags , outer_size ) )
2020-12-04 19:02:35 +01:00
{
2020-12-18 17:27:41 +01:00
for ( int row = 0 ; row < 10 ; row + + )
2020-12-04 19:02:35 +01:00
{
ImGui : : TableNextRow ( ) ;
for ( int column = 0 ; column < 3 ; column + + )
{
ImGui : : TableNextColumn ( ) ;
ImGui : : Text ( " Cell %d,%d " , column , row ) ;
}
}
ImGui : : EndTable ( ) ;
}
ImGui : : SameLine ( ) ;
2020-12-18 17:27:41 +01:00
ImGui : : Text ( " Hello! " ) ;
ImGui : : Spacing ( ) ;
ImGui : : Text ( " Using explicit size: " ) ;
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table2 " , 3 , ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg , ImVec2 ( TEXT_BASE_WIDTH * 30 , 0.0f ) ) )
2020-12-04 19:02:35 +01:00
{
2020-12-18 17:27:41 +01:00
for ( int row = 0 ; row < 5 ; row + + )
2020-12-04 19:02:35 +01:00
{
2020-12-18 17:27:41 +01:00
ImGui : : TableNextRow ( ) ;
2020-12-04 19:02:35 +01:00
for ( int column = 0 ; column < 3 ; column + + )
{
ImGui : : TableNextColumn ( ) ;
ImGui : : Text ( " Cell %d,%d " , column , row ) ;
}
}
ImGui : : EndTable ( ) ;
}
2020-12-18 17:27:41 +01:00
ImGui : : SameLine ( ) ;
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table3 " , 3 , ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg , ImVec2 ( TEXT_BASE_WIDTH * 30 , 0.0f ) ) )
2020-12-17 22:29:11 +01:00
{
2020-12-18 17:27:41 +01:00
for ( int row = 0 ; row < 3 ; row + + )
2020-12-17 22:29:11 +01:00
{
2020-12-18 17:27:41 +01:00
ImGui : : TableNextRow ( 0 , TEXT_BASE_HEIGHT * 1.5f ) ;
2020-12-17 22:29:11 +01:00
for ( int column = 0 ; column < 3 ; column + + )
{
ImGui : : TableNextColumn ( ) ;
ImGui : : Text ( " Cell %d,%d " , column , row ) ;
}
}
ImGui : : EndTable ( ) ;
}
2020-12-04 19:02:35 +01:00
ImGui : : TreePop ( ) ;
}
2020-07-28 15:53:14 +02:00
if ( open_action ! = - 1 )
ImGui : : SetNextItemOpen ( open_action ! = 0 ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Tables/Background color " ) ;
2020-07-28 15:53:14 +02:00
if ( ImGui : : TreeNode ( " Background color " ) )
{
2020-10-30 20:30:53 +01:00
static ImGuiTableFlags flags = ImGuiTableFlags_RowBg ;
2020-07-28 15:53:14 +02:00
static int row_bg_type = 1 ;
static int row_bg_target = 1 ;
static int cell_bg_type = 1 ;
2020-10-07 16:33:33 +02:00
PushStyleCompact ( ) ;
2020-11-05 17:30:30 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_Borders " , & flags , ImGuiTableFlags_Borders ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_RowBg " , & flags , ImGuiTableFlags_RowBg ) ;
2020-10-07 16:33:33 +02:00
ImGui : : SameLine ( ) ; HelpMarker ( " ImGuiTableFlags_RowBg automatically sets RowBg0 to alternative colors pulled from the Style. " ) ;
2020-07-28 15:53:14 +02:00
ImGui : : Combo ( " row bg type " , ( int * ) & row_bg_type , " None \0 Red \0 Gradient \0 " ) ;
ImGui : : Combo ( " row bg target " , ( int * ) & row_bg_target , " RowBg0 \0 RowBg1 \0 " ) ; ImGui : : SameLine ( ) ; HelpMarker ( " Target RowBg0 to override the alternating odd/even colors, \n Target RowBg1 to blend with them. " ) ;
ImGui : : Combo ( " cell bg type " , ( int * ) & cell_bg_type , " None \0 Blue \0 " ) ; ImGui : : SameLine ( ) ; HelpMarker ( " We are colorizing cells to B1->C2 here. " ) ;
IM_ASSERT ( row_bg_type > = 0 & & row_bg_type < = 2 ) ;
IM_ASSERT ( row_bg_target > = 0 & & row_bg_target < = 1 ) ;
IM_ASSERT ( cell_bg_type > = 0 & & cell_bg_type < = 1 ) ;
2020-10-07 16:33:33 +02:00
PopStyleCompact ( ) ;
2020-07-28 15:53:14 +02:00
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table1 " , 5 , flags ) )
2020-07-28 15:53:14 +02:00
{
for ( int row = 0 ; row < 6 ; row + + )
{
ImGui : : TableNextRow ( ) ;
// Demonstrate setting a row background color with 'ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBgX, ...)'
// We use a transparent color so we can see the one behind in case our target is RowBg1 and RowBg0 was already targeted by the ImGuiTableFlags_RowBg flag.
if ( row_bg_type ! = 0 )
{
ImU32 row_bg_color = ImGui : : GetColorU32 ( row_bg_type = = 1 ? ImVec4 ( 0.7f , 0.3f , 0.3f , 0.65f ) : ImVec4 ( 0.2f + row * 0.1f , 0.2f , 0.2f , 0.65f ) ) ; // Flat or Gradient?
ImGui : : TableSetBgColor ( ImGuiTableBgTarget_RowBg0 + row_bg_target , row_bg_color ) ;
}
// Fill cells
for ( int column = 0 ; column < 5 ; column + + )
{
ImGui : : TableSetColumnIndex ( column ) ;
ImGui : : Text ( " %c%c " , ' A ' + row , ' 0 ' + column ) ;
// Change background of Cells B1->C2
// Demonstrate setting a cell background color with 'ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, ...)'
// (the CellBg color will be blended over the RowBg and ColumnBg colors)
// We can also pass a column number as a third parameter to TableSetBgColor() and do this outside the column loop.
if ( row > = 1 & & row < = 2 & & column > = 1 & & column < = 2 & & cell_bg_type = = 1 )
{
ImU32 cell_bg_color = ImGui : : GetColorU32 ( ImVec4 ( 0.3f , 0.3f , 0.7f , 0.65f ) ) ;
ImGui : : TableSetBgColor ( ImGuiTableBgTarget_CellBg , cell_bg_color ) ;
}
}
}
ImGui : : EndTable ( ) ;
}
ImGui : : TreePop ( ) ;
}
2020-01-09 21:10:45 +01:00
if ( open_action ! = - 1 )
ImGui : : SetNextItemOpen ( open_action ! = 0 ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Tables/Tree view " ) ;
2020-01-09 21:10:45 +01:00
if ( ImGui : : TreeNode ( " Tree view " ) )
{
2020-10-06 17:53:59 +02:00
static ImGuiTableFlags flags = ImGuiTableFlags_BordersV | ImGuiTableFlags_BordersOuterH | ImGuiTableFlags_Resizable | ImGuiTableFlags_RowBg | ImGuiTableFlags_NoBordersInBody ;
2020-01-09 21:10:45 +01:00
2023-10-05 14:53:33 +02:00
static ImGuiTreeNodeFlags tree_node_flags = ImGuiTreeNodeFlags_SpanAllColumns ;
2023-10-17 12:21:21 +02:00
ImGui : : CheckboxFlags ( " ImGuiTreeNodeFlags_SpanFullWidth " , & tree_node_flags , ImGuiTreeNodeFlags_SpanFullWidth ) ;
ImGui : : CheckboxFlags ( " ImGuiTreeNodeFlags_SpanTextWidth " , & tree_node_flags , ImGuiTreeNodeFlags_SpanTextWidth ) ;
2023-10-05 14:53:33 +02:00
ImGui : : CheckboxFlags ( " ImGuiTreeNodeFlags_SpanAllColumns " , & tree_node_flags , ImGuiTreeNodeFlags_SpanAllColumns ) ;
2023-11-06 15:35:31 +01:00
HelpMarker ( " See \" Columns flags \" section to configure how indentation is applied to individual columns. " ) ;
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " 3ways " , 3 , flags ) )
2020-01-09 21:10:45 +01:00
{
// The first column will use the default _WidthStretch when ScrollX is Off and _WidthFixed when ScrollX is On
ImGui : : TableSetupColumn ( " Name " , ImGuiTableColumnFlags_NoHide ) ;
2020-10-07 16:33:33 +02:00
ImGui : : TableSetupColumn ( " Size " , ImGuiTableColumnFlags_WidthFixed , TEXT_BASE_WIDTH * 12.0f ) ;
ImGui : : TableSetupColumn ( " Type " , ImGuiTableColumnFlags_WidthFixed , TEXT_BASE_WIDTH * 18.0f ) ;
2020-09-24 14:33:40 +02:00
ImGui : : TableHeadersRow ( ) ;
2020-01-09 21:10:45 +01:00
// Simple storage to output a dummy file-system.
2020-05-22 15:27:53 +02:00
struct MyTreeNode
{
const char * Name ;
const char * Type ;
int Size ;
int ChildIdx ;
int ChildCount ;
2020-01-09 21:10:45 +01:00
static void DisplayNode ( const MyTreeNode * node , const MyTreeNode * all_nodes )
{
ImGui : : TableNextRow ( ) ;
2020-10-01 14:03:25 +02:00
ImGui : : TableNextColumn ( ) ;
2020-01-09 21:10:45 +01:00
const bool is_folder = ( node - > ChildCount > 0 ) ;
if ( is_folder )
{
2023-10-05 14:53:33 +02:00
bool open = ImGui : : TreeNodeEx ( node - > Name , tree_node_flags ) ;
2020-10-01 14:03:25 +02:00
ImGui : : TableNextColumn ( ) ;
2020-01-09 21:10:45 +01:00
ImGui : : TextDisabled ( " -- " ) ;
2020-10-01 14:03:25 +02:00
ImGui : : TableNextColumn ( ) ;
2020-01-09 21:10:45 +01:00
ImGui : : TextUnformatted ( node - > Type ) ;
if ( open )
{
for ( int child_n = 0 ; child_n < node - > ChildCount ; child_n + + )
DisplayNode ( & all_nodes [ node - > ChildIdx + child_n ] , all_nodes ) ;
ImGui : : TreePop ( ) ;
}
}
else
{
2023-10-05 14:53:33 +02:00
ImGui : : TreeNodeEx ( node - > Name , tree_node_flags | ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_Bullet | ImGuiTreeNodeFlags_NoTreePushOnOpen ) ;
2020-10-01 14:03:25 +02:00
ImGui : : TableNextColumn ( ) ;
2020-01-09 21:10:45 +01:00
ImGui : : Text ( " %d " , node - > Size ) ;
2020-10-01 14:03:25 +02:00
ImGui : : TableNextColumn ( ) ;
2020-01-09 21:10:45 +01:00
ImGui : : TextUnformatted ( node - > Type ) ;
}
}
} ;
static const MyTreeNode nodes [ ] =
{
{ " Root " , " Folder " , - 1 , 1 , 3 } , // 0
{ " Music " , " Folder " , - 1 , 4 , 2 } , // 1
{ " Textures " , " Folder " , - 1 , 6 , 3 } , // 2
{ " desktop.ini " , " System file " , 1024 , - 1 , - 1 } , // 3
{ " File1_a.wav " , " Audio file " , 123000 , - 1 , - 1 } , // 4
{ " File1_b.wav " , " Audio file " , 456000 , - 1 , - 1 } , // 5
{ " Image001.png " , " Image file " , 203128 , - 1 , - 1 } , // 6
{ " Copy of Image001.png " , " Image file " , 203256 , - 1 , - 1 } , // 7
{ " Copy of Image001 (Final2).png " , " Image file " , 203512 , - 1 , - 1 } , // 8
} ;
MyTreeNode : : DisplayNode ( & nodes [ 0 ] , nodes ) ;
ImGui : : EndTable ( ) ;
}
ImGui : : TreePop ( ) ;
}
2021-01-06 17:39:41 +01:00
if ( open_action ! = - 1 )
ImGui : : SetNextItemOpen ( open_action ! = 0 ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Tables/Item width " ) ;
2021-01-06 17:39:41 +01:00
if ( ImGui : : TreeNode ( " Item width " ) )
{
HelpMarker (
" Showcase using PushItemWidth() and how it is preserved on a per-column basis. \n \n "
2024-01-04 11:50:38 +01:00
" Note that on auto-resizing non-resizable fixed columns, querying the content width for "
" e.g. right-alignment doesn't make sense. " ) ;
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table_item_width " , 3 , ImGuiTableFlags_Borders ) )
2021-01-06 17:39:41 +01:00
{
ImGui : : TableSetupColumn ( " small " ) ;
ImGui : : TableSetupColumn ( " half " ) ;
ImGui : : TableSetupColumn ( " right-align " ) ;
ImGui : : TableHeadersRow ( ) ;
for ( int row = 0 ; row < 3 ; row + + )
{
ImGui : : TableNextRow ( ) ;
if ( row = = 0 )
{
// Setup ItemWidth once (instead of setting up every time, which is also possible but less efficient)
ImGui : : TableSetColumnIndex ( 0 ) ;
ImGui : : PushItemWidth ( TEXT_BASE_WIDTH * 3.0f ) ; // Small
ImGui : : TableSetColumnIndex ( 1 ) ;
ImGui : : PushItemWidth ( - ImGui : : GetContentRegionAvail ( ) . x * 0.5f ) ;
ImGui : : TableSetColumnIndex ( 2 ) ;
ImGui : : PushItemWidth ( - FLT_MIN ) ; // Right-aligned
}
// Draw our contents
static float dummy_f = 0.0f ;
ImGui : : PushID ( row ) ;
ImGui : : TableSetColumnIndex ( 0 ) ;
ImGui : : SliderFloat ( " float0 " , & dummy_f , 0.0f , 1.0f ) ;
ImGui : : TableSetColumnIndex ( 1 ) ;
ImGui : : SliderFloat ( " float1 " , & dummy_f , 0.0f , 1.0f ) ;
ImGui : : TableSetColumnIndex ( 2 ) ;
2022-06-07 11:38:43 +02:00
ImGui : : SliderFloat ( " ##float2 " , & dummy_f , 0.0f , 1.0f ) ; // No visible label since right-aligned
2021-01-06 17:39:41 +01:00
ImGui : : PopID ( ) ;
}
ImGui : : EndTable ( ) ;
}
ImGui : : TreePop ( ) ;
}
2020-09-24 14:33:40 +02:00
// Demonstrate using TableHeader() calls instead of TableHeadersRow()
2020-01-20 12:41:23 +01:00
if ( open_action ! = - 1 )
ImGui : : SetNextItemOpen ( open_action ! = 0 ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Tables/Custom headers " ) ;
2020-01-20 12:41:23 +01:00
if ( ImGui : : TreeNode ( " Custom headers " ) )
{
const int COLUMNS_COUNT = 3 ;
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table_custom_headers " , COLUMNS_COUNT , ImGuiTableFlags_Borders | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable ) )
2020-01-20 12:41:23 +01:00
{
ImGui : : TableSetupColumn ( " Apricot " ) ;
ImGui : : TableSetupColumn ( " Banana " ) ;
ImGui : : TableSetupColumn ( " Cherry " ) ;
// Dummy entire-column selection storage
// FIXME: It would be nice to actually demonstrate full-featured selection using those checkbox.
static bool column_selected [ 3 ] = { } ;
2024-09-04 14:41:22 +02:00
// Instead of calling TableHeadersRow() we'll submit custom headers ourselves.
// (A different approach is also possible:
// - Specify ImGuiTableColumnFlags_NoHeaderLabel in some TableSetupColumn() call.
// - Call TableHeadersRow() normally. This will submit TableHeader() with no name.
// - Then call TableSetColumnIndex() to position yourself in the column and submit your stuff e.g. Checkbox().)
2020-01-20 12:41:23 +01:00
ImGui : : TableNextRow ( ImGuiTableRowFlags_Headers ) ;
for ( int column = 0 ; column < COLUMNS_COUNT ; column + + )
{
ImGui : : TableSetColumnIndex ( column ) ;
const char * column_name = ImGui : : TableGetColumnName ( column ) ; // Retrieve name passed to TableSetupColumn()
ImGui : : PushID ( column ) ;
ImGui : : PushStyleVar ( ImGuiStyleVar_FramePadding , ImVec2 ( 0 , 0 ) ) ;
ImGui : : Checkbox ( " ##checkall " , & column_selected [ column ] ) ;
ImGui : : PopStyleVar ( ) ;
ImGui : : SameLine ( 0.0f , ImGui : : GetStyle ( ) . ItemInnerSpacing . x ) ;
ImGui : : TableHeader ( column_name ) ;
ImGui : : PopID ( ) ;
}
2024-09-04 14:41:22 +02:00
// Submit table contents
2020-01-20 12:41:23 +01:00
for ( int row = 0 ; row < 5 ; row + + )
{
ImGui : : TableNextRow ( ) ;
for ( int column = 0 ; column < 3 ; column + + )
{
char buf [ 32 ] ;
2020-11-18 14:15:38 +01:00
sprintf ( buf , " Cell %d,%d " , column , row ) ;
2020-01-20 12:41:23 +01:00
ImGui : : TableSetColumnIndex ( column ) ;
ImGui : : Selectable ( buf , column_selected [ column ] ) ;
}
}
ImGui : : EndTable ( ) ;
}
ImGui : : TreePop ( ) ;
}
2023-10-12 17:01:42 +02:00
// Demonstrate using ImGuiTableColumnFlags_AngledHeader flag to create angled headers
if ( open_action ! = - 1 )
ImGui : : SetNextItemOpen ( open_action ! = 0 ) ;
IMGUI_DEMO_MARKER ( " Tables/Angled headers " ) ;
if ( ImGui : : TreeNode ( " Angled headers " ) )
{
const char * column_names [ ] = { " Track " , " cabasa " , " ride " , " smash " , " tom-hi " , " tom-mid " , " tom-low " , " hihat-o " , " hihat-c " , " snare-s " , " snare-c " , " clap " , " rim " , " kick " } ;
const int columns_count = IM_ARRAYSIZE ( column_names ) ;
const int rows_count = 12 ;
static ImGuiTableFlags table_flags = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersInnerH | ImGuiTableFlags_Hideable | ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_HighlightHoveredColumn ;
2024-02-19 20:24:07 +01:00
static ImGuiTableColumnFlags column_flags = ImGuiTableColumnFlags_AngledHeader | ImGuiTableColumnFlags_WidthFixed ;
2023-10-12 17:01:42 +02:00
static bool bools [ columns_count * rows_count ] = { } ; // Dummy storage selection storage
2023-10-12 19:47:37 +02:00
static int frozen_cols = 1 ;
2023-10-12 17:01:42 +02:00
static int frozen_rows = 2 ;
ImGui : : CheckboxFlags ( " _ScrollX " , & table_flags , ImGuiTableFlags_ScrollX ) ;
ImGui : : CheckboxFlags ( " _ScrollY " , & table_flags , ImGuiTableFlags_ScrollY ) ;
2024-02-19 20:24:07 +01:00
ImGui : : CheckboxFlags ( " _Resizable " , & table_flags , ImGuiTableFlags_Resizable ) ;
2024-09-03 21:49:35 +02:00
ImGui : : CheckboxFlags ( " _Sortable " , & table_flags , ImGuiTableFlags_Sortable ) ;
2023-10-12 17:01:42 +02:00
ImGui : : CheckboxFlags ( " _NoBordersInBody " , & table_flags , ImGuiTableFlags_NoBordersInBody ) ;
ImGui : : CheckboxFlags ( " _HighlightHoveredColumn " , & table_flags , ImGuiTableFlags_HighlightHoveredColumn ) ;
ImGui : : SetNextItemWidth ( ImGui : : GetFontSize ( ) * 8 ) ;
2023-10-12 19:47:37 +02:00
ImGui : : SliderInt ( " Frozen columns " , & frozen_cols , 0 , 2 ) ;
2023-10-12 20:00:34 +02:00
ImGui : : SetNextItemWidth ( ImGui : : GetFontSize ( ) * 8 ) ;
2023-10-12 17:01:42 +02:00
ImGui : : SliderInt ( " Frozen rows " , & frozen_rows , 0 , 2 ) ;
2024-02-19 20:24:07 +01:00
ImGui : : CheckboxFlags ( " Disable header contributing to column width " , & column_flags , ImGuiTableColumnFlags_NoHeaderWidth ) ;
2023-10-12 17:01:42 +02:00
2024-04-30 16:08:48 +02:00
if ( ImGui : : TreeNode ( " Style settings " ) )
{
ImGui : : SameLine ( ) ;
HelpMarker ( " Giving access to some ImGuiStyle value in this demo for convenience. " ) ;
ImGui : : SetNextItemWidth ( ImGui : : GetFontSize ( ) * 8 ) ;
ImGui : : SliderAngle ( " style.TableAngledHeadersAngle " , & ImGui : : GetStyle ( ) . TableAngledHeadersAngle , - 50.0f , + 50.0f ) ;
ImGui : : SetNextItemWidth ( ImGui : : GetFontSize ( ) * 8 ) ;
ImGui : : SliderFloat2 ( " style.TableAngledHeadersTextAlign " , ( float * ) & ImGui : : GetStyle ( ) . TableAngledHeadersTextAlign , 0.0f , 1.0f , " %.2f " ) ;
ImGui : : TreePop ( ) ;
}
2023-10-12 17:01:42 +02:00
if ( ImGui : : BeginTable ( " table_angled_headers " , columns_count , table_flags , ImVec2 ( 0.0f , TEXT_BASE_HEIGHT * 12 ) ) )
{
ImGui : : TableSetupColumn ( column_names [ 0 ] , ImGuiTableColumnFlags_NoHide | ImGuiTableColumnFlags_NoReorder ) ;
for ( int n = 1 ; n < columns_count ; n + + )
2024-02-19 20:24:07 +01:00
ImGui : : TableSetupColumn ( column_names [ n ] , column_flags ) ;
2023-10-12 19:47:37 +02:00
ImGui : : TableSetupScrollFreeze ( frozen_cols , frozen_rows ) ;
2023-10-12 17:01:42 +02:00
ImGui : : TableAngledHeadersRow ( ) ; // Draw angled headers for all columns with the ImGuiTableColumnFlags_AngledHeader flag.
ImGui : : TableHeadersRow ( ) ; // Draw remaining headers and allow access to context-menu and other functions.
for ( int row = 0 ; row < rows_count ; row + + )
{
ImGui : : PushID ( row ) ;
ImGui : : TableNextRow ( ) ;
ImGui : : TableSetColumnIndex ( 0 ) ;
ImGui : : AlignTextToFramePadding ( ) ;
ImGui : : Text ( " Track %d " , row ) ;
for ( int column = 1 ; column < columns_count ; column + + )
if ( ImGui : : TableSetColumnIndex ( column ) )
{
ImGui : : PushID ( column ) ;
ImGui : : Checkbox ( " " , & bools [ row * columns_count + column ] ) ;
ImGui : : PopID ( ) ;
}
ImGui : : PopID ( ) ;
}
ImGui : : EndTable ( ) ;
}
ImGui : : TreePop ( ) ;
}
2024-01-04 11:50:38 +01:00
// Demonstrate creating custom context menus inside columns,
// while playing it nice with context menus provided by TableHeadersRow()/TableHeader()
2020-06-19 15:39:56 +02:00
if ( open_action ! = - 1 )
ImGui : : SetNextItemOpen ( open_action ! = 0 ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Tables/Context menus " ) ;
2020-06-19 15:39:56 +02:00
if ( ImGui : : TreeNode ( " Context menus " ) )
{
2024-01-04 11:50:38 +01:00
HelpMarker (
" By default, right-clicking over a TableHeadersRow()/TableHeader() line will open the default context-menu. \n "
" Using ImGuiTableFlags_ContextMenuInBody we also allow right-clicking over columns body. " ) ;
2020-10-01 19:54:10 +02:00
static ImGuiTableFlags flags1 = ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Borders | ImGuiTableFlags_ContextMenuInBody ;
2020-10-07 16:33:33 +02:00
PushStyleCompact ( ) ;
2021-01-15 17:48:15 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_ContextMenuInBody " , & flags1 , ImGuiTableFlags_ContextMenuInBody ) ;
2020-10-07 16:33:33 +02:00
PopStyleCompact ( ) ;
2020-10-01 19:54:10 +02:00
// Context Menus: first example
// [1.1] Right-click on the TableHeadersRow() line to open the default table context menu.
// [1.2] Right-click in columns also open the default table context menu (if ImGuiTableFlags_ContextMenuInBody is set)
2020-06-19 15:39:56 +02:00
const int COLUMNS_COUNT = 3 ;
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table_context_menu " , COLUMNS_COUNT , flags1 ) )
2020-06-19 15:39:56 +02:00
{
ImGui : : TableSetupColumn ( " One " ) ;
ImGui : : TableSetupColumn ( " Two " ) ;
ImGui : : TableSetupColumn ( " Three " ) ;
2020-10-01 19:54:10 +02:00
// [1.1]] Right-click on the TableHeadersRow() line to open the default table context menu.
2020-09-24 14:33:40 +02:00
ImGui : : TableHeadersRow ( ) ;
2020-10-01 19:54:10 +02:00
// Submit dummy contents
2020-06-19 15:39:56 +02:00
for ( int row = 0 ; row < 4 ; row + + )
{
ImGui : : TableNextRow ( ) ;
for ( int column = 0 ; column < COLUMNS_COUNT ; column + + )
{
ImGui : : TableSetColumnIndex ( column ) ;
2020-12-14 11:59:01 +01:00
ImGui : : Text ( " Cell %d,%d " , column , row ) ;
2020-10-01 19:54:10 +02:00
}
}
ImGui : : EndTable ( ) ;
}
// Context Menus: second example
// [2.1] Right-click on the TableHeadersRow() line to open the default table context menu.
// [2.2] Right-click on the ".." to open a custom popup
// [2.3] Right-click in columns to open another custom popup
2024-01-04 11:50:38 +01:00
HelpMarker (
" Demonstrate mixing table context menu (over header), item context button (over button) "
" and custom per-colunm context menu (over column body). " ) ;
2021-01-08 18:07:16 +01:00
ImGuiTableFlags flags2 = ImGuiTableFlags_Resizable | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Borders ;
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table_context_menu_2 " , COLUMNS_COUNT , flags2 ) )
2020-10-01 19:54:10 +02:00
{
ImGui : : TableSetupColumn ( " One " ) ;
ImGui : : TableSetupColumn ( " Two " ) ;
ImGui : : TableSetupColumn ( " Three " ) ;
// [2.1] Right-click on the TableHeadersRow() line to open the default table context menu.
ImGui : : TableHeadersRow ( ) ;
for ( int row = 0 ; row < 4 ; row + + )
{
ImGui : : TableNextRow ( ) ;
for ( int column = 0 ; column < COLUMNS_COUNT ; column + + )
{
// Submit dummy contents
ImGui : : TableSetColumnIndex ( column ) ;
2020-06-19 15:39:56 +02:00
ImGui : : Text ( " Cell %d,%d " , column , row ) ;
ImGui : : SameLine ( ) ;
2020-10-01 19:54:10 +02:00
// [2.2] Right-click on the ".." to open a custom popup
ImGui : : PushID ( row * COLUMNS_COUNT + column ) ;
2020-06-19 15:39:56 +02:00
ImGui : : SmallButton ( " .. " ) ;
if ( ImGui : : BeginPopupContextItem ( ) )
{
2020-10-01 19:54:10 +02:00
ImGui : : Text ( " This is the popup for Button( \" .. \" ) in Cell %d,%d " , column , row ) ;
if ( ImGui : : Button ( " Close " ) )
ImGui : : CloseCurrentPopup ( ) ;
2020-06-19 15:39:56 +02:00
ImGui : : EndPopup ( ) ;
}
ImGui : : PopID ( ) ;
}
}
2020-10-01 19:54:10 +02:00
// [2.3] Right-click anywhere in columns to open another custom popup
// (instead of testing for !IsAnyItemHovered() we could also call OpenPopup() with ImGuiPopupFlags_NoOpenOverExistingPopup
// to manage popup priority as the popups triggers, here "are we hovering a column" are overlapping)
2020-12-04 17:54:40 +01:00
int hovered_column = - 1 ;
2020-06-19 15:39:56 +02:00
for ( int column = 0 ; column < COLUMNS_COUNT + 1 ; column + + )
{
ImGui : : PushID ( column ) ;
2020-12-04 17:54:40 +01:00
if ( ImGui : : TableGetColumnFlags ( column ) & ImGuiTableColumnFlags_IsHovered )
hovered_column = column ;
2020-10-01 19:54:10 +02:00
if ( hovered_column = = column & & ! ImGui : : IsAnyItemHovered ( ) & & ImGui : : IsMouseReleased ( 1 ) )
ImGui : : OpenPopup ( " MyPopup " ) ;
2020-06-19 15:39:56 +02:00
if ( ImGui : : BeginPopup ( " MyPopup " ) )
{
if ( column = = COLUMNS_COUNT )
2020-10-01 19:54:10 +02:00
ImGui : : Text ( " This is a custom popup for unused space after the last column. " ) ;
2020-06-19 15:39:56 +02:00
else
2020-10-01 19:54:10 +02:00
ImGui : : Text ( " This is a custom popup for Column %d " , column ) ;
if ( ImGui : : Button ( " Close " ) )
ImGui : : CloseCurrentPopup ( ) ;
2020-06-19 15:39:56 +02:00
ImGui : : EndPopup ( ) ;
}
ImGui : : PopID ( ) ;
}
ImGui : : EndTable ( ) ;
2020-12-04 17:54:40 +01:00
ImGui : : Text ( " Hovered column: %d " , hovered_column ) ;
2020-06-19 15:39:56 +02:00
}
ImGui : : TreePop ( ) ;
}
2020-11-20 19:11:33 +01:00
// Demonstrate creating multiple tables with the same ID
if ( open_action ! = - 1 )
ImGui : : SetNextItemOpen ( open_action ! = 0 ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Tables/Synced instances " ) ;
2020-11-20 19:11:33 +01:00
if ( ImGui : : TreeNode ( " Synced instances " ) )
{
HelpMarker ( " Multiple tables with the same identifier will share their settings, width, visibility, order etc. " ) ;
2022-12-08 19:53:57 +01:00
static ImGuiTableFlags flags = ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Borders | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_NoSavedSettings ;
2024-03-29 11:39:05 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_Resizable " , & flags , ImGuiTableFlags_Resizable ) ;
2022-12-08 19:53:57 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_ScrollY " , & flags , ImGuiTableFlags_ScrollY ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_SizingFixedFit " , & flags , ImGuiTableFlags_SizingFixedFit ) ;
2023-10-12 14:43:34 +02:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_HighlightHoveredColumn " , & flags , ImGuiTableFlags_HighlightHoveredColumn ) ;
2020-11-20 19:11:33 +01:00
for ( int n = 0 ; n < 3 ; n + + )
{
char buf [ 32 ] ;
sprintf ( buf , " Synced Table %d " , n ) ;
bool open = ImGui : : CollapsingHeader ( buf , ImGuiTreeNodeFlags_DefaultOpen ) ;
2022-12-08 19:53:57 +01:00
if ( open & & ImGui : : BeginTable ( " Table " , 3 , flags , ImVec2 ( 0.0f , ImGui : : GetTextLineHeightWithSpacing ( ) * 5 ) ) )
2020-11-20 19:11:33 +01:00
{
ImGui : : TableSetupColumn ( " One " ) ;
ImGui : : TableSetupColumn ( " Two " ) ;
ImGui : : TableSetupColumn ( " Three " ) ;
ImGui : : TableHeadersRow ( ) ;
2022-12-08 19:53:57 +01:00
const int cell_count = ( n = = 1 ) ? 27 : 9 ; // Make second table have a scrollbar to verify that additional decoration is not affecting column positions.
for ( int cell = 0 ; cell < cell_count ; cell + + )
2020-11-20 19:11:33 +01:00
{
ImGui : : TableNextColumn ( ) ;
ImGui : : Text ( " this cell %d " , cell ) ;
}
ImGui : : EndTable ( ) ;
}
}
ImGui : : TreePop ( ) ;
}
// Demonstrate using Sorting facilities
// This is a simplified version of the "Advanced" example, where we mostly focus on the code necessary to handle sorting.
// Note that the "Advanced" example also showcase manually triggering a sort (e.g. if item quantities have been modified)
2019-12-19 14:52:18 +01:00
static const char * template_items_names [ ] =
{
" Banana " , " Apple " , " Cherry " , " Watermelon " , " Grapefruit " , " Strawberry " , " Mango " ,
" Kiwi " , " Orange " , " Pineapple " , " Blueberry " , " Plum " , " Coconut " , " Pear " , " Apricot "
} ;
if ( open_action ! = - 1 )
ImGui : : SetNextItemOpen ( open_action ! = 0 ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Tables/Sorting " ) ;
2019-12-19 14:52:18 +01:00
if ( ImGui : : TreeNode ( " Sorting " ) )
{
// Create item list
static ImVector < MyItem > items ;
if ( items . Size = = 0 )
{
items . resize ( 50 , MyItem ( ) ) ;
for ( int n = 0 ; n < items . Size ; n + + )
{
const int template_n = n % IM_ARRAYSIZE ( template_items_names ) ;
MyItem & item = items [ n ] ;
item . ID = n ;
item . Name = template_items_names [ template_n ] ;
item . Quantity = ( n * n - n ) % 20 ; // Assign default quantities
}
}
2020-12-11 21:33:37 +01:00
// Options
static ImGuiTableFlags flags =
ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Sortable | ImGuiTableFlags_SortMulti
2020-10-06 17:53:59 +02:00
| ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_NoBordersInBody
2020-09-23 17:53:52 +02:00
| ImGuiTableFlags_ScrollY ;
2021-01-06 17:39:41 +01:00
PushStyleCompact ( ) ;
2020-12-11 21:33:37 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_SortMulti " , & flags , ImGuiTableFlags_SortMulti ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " When sorting is enabled: hold shift when clicking headers to sort on multiple column. TableGetSortSpecs() may return specs where (SpecsCount > 1). " ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_SortTristate " , & flags , ImGuiTableFlags_SortTristate ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " When sorting is enabled: allow no sorting, disable default sorting. TableGetSortSpecs() may return specs where (SpecsCount == 0). " ) ;
2021-01-06 17:39:41 +01:00
PopStyleCompact ( ) ;
2020-12-11 21:33:37 +01:00
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table_sorting " , 4 , flags , ImVec2 ( 0.0f , TEXT_BASE_HEIGHT * 15 ) , 0.0f ) )
2019-12-19 14:52:18 +01:00
{
// Declare columns
// We use the "user_id" parameter of TableSetupColumn() to specify a user id that will be stored in the sort specifications.
// This is so our sort function can identify a column given our own identifier. We could also identify them based on their index!
// Demonstrate using a mixture of flags among available sort-related flags:
// - ImGuiTableColumnFlags_DefaultSort
// - ImGuiTableColumnFlags_NoSort / ImGuiTableColumnFlags_NoSortAscending / ImGuiTableColumnFlags_NoSortDescending
// - ImGuiTableColumnFlags_PreferSortAscending / ImGuiTableColumnFlags_PreferSortDescending
2021-01-14 11:21:13 +01:00
ImGui : : TableSetupColumn ( " ID " , ImGuiTableColumnFlags_DefaultSort | ImGuiTableColumnFlags_WidthFixed , 0.0f , MyItemColumnID_ID ) ;
ImGui : : TableSetupColumn ( " Name " , ImGuiTableColumnFlags_WidthFixed , 0.0f , MyItemColumnID_Name ) ;
ImGui : : TableSetupColumn ( " Action " , ImGuiTableColumnFlags_NoSort | ImGuiTableColumnFlags_WidthFixed , 0.0f , MyItemColumnID_Action ) ;
ImGui : : TableSetupColumn ( " Quantity " , ImGuiTableColumnFlags_PreferSortDescending | ImGuiTableColumnFlags_WidthStretch , 0.0f , MyItemColumnID_Quantity ) ;
2020-09-23 17:53:52 +02:00
ImGui : : TableSetupScrollFreeze ( 0 , 1 ) ; // Make row always visible
2020-11-03 18:47:05 +01:00
ImGui : : TableHeadersRow ( ) ;
2019-12-19 14:52:18 +01:00
// Sort our data if sort specs have been changed!
2023-09-01 14:35:57 +02:00
if ( ImGuiTableSortSpecs * sort_specs = ImGui : : TableGetSortSpecs ( ) )
if ( sort_specs - > SpecsDirty )
2019-12-19 14:52:18 +01:00
{
2023-09-01 14:35:57 +02:00
MyItem : : SortWithSortSpecs ( sort_specs , items . Data , items . Size ) ;
sort_specs - > SpecsDirty = false ;
2019-12-19 14:52:18 +01:00
}
2020-11-03 18:47:05 +01:00
// Demonstrate using clipper for large vertical lists
2019-12-19 14:52:18 +01:00
ImGuiListClipper clipper ;
clipper . Begin ( items . Size ) ;
while ( clipper . Step ( ) )
for ( int row_n = clipper . DisplayStart ; row_n < clipper . DisplayEnd ; row_n + + )
{
2020-11-03 18:47:05 +01:00
// Display a data item
2019-12-19 14:52:18 +01:00
MyItem * item = & items [ row_n ] ;
ImGui : : PushID ( item - > ID ) ;
ImGui : : TableNextRow ( ) ;
2020-10-01 14:03:25 +02:00
ImGui : : TableNextColumn ( ) ;
2019-12-19 14:52:18 +01:00
ImGui : : Text ( " %04d " , item - > ID ) ;
2020-10-01 14:03:25 +02:00
ImGui : : TableNextColumn ( ) ;
2019-12-19 14:52:18 +01:00
ImGui : : TextUnformatted ( item - > Name ) ;
2020-10-01 14:03:25 +02:00
ImGui : : TableNextColumn ( ) ;
2019-12-19 14:52:18 +01:00
ImGui : : SmallButton ( " None " ) ;
2020-10-01 14:03:25 +02:00
ImGui : : TableNextColumn ( ) ;
2019-12-19 14:52:18 +01:00
ImGui : : Text ( " %d " , item - > Quantity ) ;
ImGui : : PopID ( ) ;
}
ImGui : : EndTable ( ) ;
}
ImGui : : TreePop ( ) ;
}
2021-02-16 16:53:56 +01:00
// In this example we'll expose most table flags and settings.
// For specific flags and settings refer to the corresponding section for more detailed explanation.
// This section is mostly useful to experiment with combining certain flags or settings with each others.
2020-10-07 22:44:02 +02:00
//ImGui::SetNextItemOpen(true, ImGuiCond_Once); // [DEBUG]
2019-12-19 14:52:18 +01:00
if ( open_action ! = - 1 )
ImGui : : SetNextItemOpen ( open_action ! = 0 ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Tables/Advanced " ) ;
2019-12-19 14:52:18 +01:00
if ( ImGui : : TreeNode ( " Advanced " ) )
{
static ImGuiTableFlags flags =
2020-12-11 21:33:37 +01:00
ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable
| ImGuiTableFlags_Sortable | ImGuiTableFlags_SortMulti
2020-10-06 17:53:59 +02:00
| ImGuiTableFlags_RowBg | ImGuiTableFlags_Borders | ImGuiTableFlags_NoBordersInBody
2019-12-19 14:52:18 +01:00
| ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY
2021-01-08 18:07:16 +01:00
| ImGuiTableFlags_SizingFixedFit ;
2023-10-12 17:01:42 +02:00
static ImGuiTableColumnFlags columns_base_flags = ImGuiTableColumnFlags_None ;
2019-12-19 14:52:18 +01:00
2020-11-11 18:54:39 +01:00
enum ContentsType { CT_Text , CT_Button , CT_SmallButton , CT_FillButton , CT_Selectable , CT_SelectableSpanRow } ;
2020-12-18 12:18:34 +01:00
static int contents_type = CT_SelectableSpanRow ;
2020-11-11 18:54:39 +01:00
const char * contents_type_names [ ] = { " Text " , " Button " , " SmallButton " , " FillButton " , " Selectable " , " Selectable (span row) " } ;
2020-09-23 17:53:52 +02:00
static int freeze_cols = 1 ;
static int freeze_rows = 1 ;
2020-12-18 12:18:34 +01:00
static int items_count = IM_ARRAYSIZE ( template_items_names ) * 2 ;
2021-01-21 16:20:31 +01:00
static ImVec2 outer_size_value = ImVec2 ( 0.0f , TEXT_BASE_HEIGHT * 12 ) ;
2019-12-19 14:52:18 +01:00
static float row_min_height = 0.0f ; // Auto
static float inner_width_with_scroll = 0.0f ; // Auto-extend
static bool outer_size_enabled = true ;
static bool show_headers = true ;
static bool show_wrapped_text = false ;
2020-01-09 22:02:16 +01:00
//static ImGuiTextFilter filter;
2022-09-14 18:19:50 +02:00
//ImGui::SetNextItemOpen(true, ImGuiCond_Once); // FIXME-TABLE: Enabling this results in initial clipped first pass on table which tend to affect column sizing
2020-10-07 16:33:33 +02:00
if ( ImGui : : TreeNode ( " Options " ) )
2019-12-19 14:52:18 +01:00
{
// Make the UI compact because there are so many fields
2020-10-07 16:33:33 +02:00
PushStyleCompact ( ) ;
ImGui : : PushItemWidth ( TEXT_BASE_WIDTH * 28.0f ) ;
2019-12-19 14:52:18 +01:00
2020-10-07 16:33:33 +02:00
if ( ImGui : : TreeNodeEx ( " Features: " , ImGuiTreeNodeFlags_DefaultOpen ) )
{
2020-11-05 17:30:30 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_Resizable " , & flags , ImGuiTableFlags_Resizable ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_Reorderable " , & flags , ImGuiTableFlags_Reorderable ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_Hideable " , & flags , ImGuiTableFlags_Hideable ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_Sortable " , & flags , ImGuiTableFlags_Sortable ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_NoSavedSettings " , & flags , ImGuiTableFlags_NoSavedSettings ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_ContextMenuInBody " , & flags , ImGuiTableFlags_ContextMenuInBody ) ;
2020-10-07 16:33:33 +02:00
ImGui : : TreePop ( ) ;
}
2019-12-19 14:52:18 +01:00
2020-11-18 14:15:38 +01:00
if ( ImGui : : TreeNodeEx ( " Decorations: " , ImGuiTreeNodeFlags_DefaultOpen ) )
2020-10-07 16:33:33 +02:00
{
2020-11-05 17:30:30 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_RowBg " , & flags , ImGuiTableFlags_RowBg ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_BordersV " , & flags , ImGuiTableFlags_BordersV ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_BordersOuterV " , & flags , ImGuiTableFlags_BordersOuterV ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_BordersInnerV " , & flags , ImGuiTableFlags_BordersInnerV ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_BordersH " , & flags , ImGuiTableFlags_BordersH ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_BordersOuterH " , & flags , ImGuiTableFlags_BordersOuterH ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_BordersInnerH " , & flags , ImGuiTableFlags_BordersInnerH ) ;
2022-09-14 18:19:50 +02:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_NoBordersInBody " , & flags , ImGuiTableFlags_NoBordersInBody ) ; ImGui : : SameLine ( ) ; HelpMarker ( " Disable vertical borders in columns Body (borders will always appear in Headers " ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_NoBordersInBodyUntilResize " , & flags , ImGuiTableFlags_NoBordersInBodyUntilResize ) ; ImGui : : SameLine ( ) ; HelpMarker ( " Disable vertical borders in columns Body until hovered for resize (borders will always appear in Headers) " ) ;
2020-10-07 16:33:33 +02:00
ImGui : : TreePop ( ) ;
}
2019-12-19 14:52:18 +01:00
2020-11-06 14:28:43 +01:00
if ( ImGui : : TreeNodeEx ( " Sizing: " , ImGuiTreeNodeFlags_DefaultOpen ) )
2020-10-07 16:33:33 +02:00
{
2021-01-08 18:38:55 +01:00
EditTableSizingFlags ( & flags ) ;
2021-01-06 17:39:41 +01:00
ImGui : : SameLine ( ) ; HelpMarker ( " In the Advanced demo we override the policy of each column so those table-wide settings have less effect that typical. " ) ;
2021-01-21 16:20:31 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_NoHostExtendX " , & flags , ImGuiTableFlags_NoHostExtendX ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Make outer width auto-fit to columns, overriding outer_size.x value. \n \n Only available when ScrollX/ScrollY are disabled and Stretch columns are not used. " ) ;
2020-11-05 17:30:30 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_NoHostExtendY " , & flags , ImGuiTableFlags_NoHostExtendY ) ;
2021-01-21 16:20:31 +01:00
ImGui : : SameLine ( ) ; HelpMarker ( " Make outer height stop exactly at outer_size.y (prevent auto-extending table past the limit). \n \n Only available when ScrollX/ScrollY are disabled. Data below the limit will be clipped and not visible. " ) ;
2020-11-05 17:30:30 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_NoKeepColumnsVisible " , & flags , ImGuiTableFlags_NoKeepColumnsVisible ) ;
2020-10-07 16:33:33 +02:00
ImGui : : SameLine ( ) ; HelpMarker ( " Only available if ScrollX is disabled. " ) ;
2020-11-18 17:28:18 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_PreciseWidths " , & flags , ImGuiTableFlags_PreciseWidths ) ;
2020-11-06 14:28:43 +01:00
ImGui : : SameLine ( ) ; HelpMarker ( " Disable distributing remainder width to stretched columns (width allocation on a 100-wide table with 3 columns: Without this flag: 33,33,34. With this flag: 33,33,33). With larger number of columns, resizing will appear to be less smooth. " ) ;
2020-11-05 17:30:30 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_NoClip " , & flags , ImGuiTableFlags_NoClip ) ;
2020-10-07 16:33:33 +02:00
ImGui : : SameLine ( ) ; HelpMarker ( " Disable clipping rectangle for every individual columns (reduce draw command count, items will be able to overflow into other columns). Generally incompatible with ScrollFreeze options. " ) ;
ImGui : : TreePop ( ) ;
}
2019-12-19 14:52:18 +01:00
2020-11-06 14:44:44 +01:00
if ( ImGui : : TreeNodeEx ( " Padding: " , ImGuiTreeNodeFlags_DefaultOpen ) )
2020-11-06 14:28:43 +01:00
{
ImGui : : CheckboxFlags ( " ImGuiTableFlags_PadOuterX " , & flags , ImGuiTableFlags_PadOuterX ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_NoPadOuterX " , & flags , ImGuiTableFlags_NoPadOuterX ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_NoPadInnerX " , & flags , ImGuiTableFlags_NoPadInnerX ) ;
ImGui : : TreePop ( ) ;
}
2020-10-07 16:33:33 +02:00
if ( ImGui : : TreeNodeEx ( " Scrolling: " , ImGuiTreeNodeFlags_DefaultOpen ) )
{
2020-11-05 17:30:30 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_ScrollX " , & flags , ImGuiTableFlags_ScrollX ) ;
2020-10-07 16:33:33 +02:00
ImGui : : SameLine ( ) ;
ImGui : : SetNextItemWidth ( ImGui : : GetFrameHeight ( ) ) ;
ImGui : : DragInt ( " freeze_cols " , & freeze_cols , 0.2f , 0 , 9 , NULL , ImGuiSliderFlags_NoInput ) ;
2020-11-05 17:30:30 +01:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_ScrollY " , & flags , ImGuiTableFlags_ScrollY ) ;
2020-10-07 16:33:33 +02:00
ImGui : : SameLine ( ) ;
ImGui : : SetNextItemWidth ( ImGui : : GetFrameHeight ( ) ) ;
ImGui : : DragInt ( " freeze_rows " , & freeze_rows , 0.2f , 0 , 9 , NULL , ImGuiSliderFlags_NoInput ) ;
ImGui : : TreePop ( ) ;
}
2019-12-19 14:52:18 +01:00
2020-12-11 21:33:37 +01:00
if ( ImGui : : TreeNodeEx ( " Sorting: " , ImGuiTreeNodeFlags_DefaultOpen ) )
{
ImGui : : CheckboxFlags ( " ImGuiTableFlags_SortMulti " , & flags , ImGuiTableFlags_SortMulti ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " When sorting is enabled: hold shift when clicking headers to sort on multiple column. TableGetSortSpecs() may return specs where (SpecsCount > 1). " ) ;
ImGui : : CheckboxFlags ( " ImGuiTableFlags_SortTristate " , & flags , ImGuiTableFlags_SortTristate ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " When sorting is enabled: allow no sorting, disable default sorting. TableGetSortSpecs() may return specs where (SpecsCount == 0). " ) ;
ImGui : : TreePop ( ) ;
}
2023-10-12 14:43:34 +02:00
if ( ImGui : : TreeNodeEx ( " Headers: " , ImGuiTreeNodeFlags_DefaultOpen ) )
2020-10-07 16:33:33 +02:00
{
ImGui : : Checkbox ( " show_headers " , & show_headers ) ;
2023-10-12 14:43:34 +02:00
ImGui : : CheckboxFlags ( " ImGuiTableFlags_HighlightHoveredColumn " , & flags , ImGuiTableFlags_HighlightHoveredColumn ) ;
2023-10-12 17:01:42 +02:00
ImGui : : CheckboxFlags ( " ImGuiTableColumnFlags_AngledHeader " , & columns_base_flags , ImGuiTableColumnFlags_AngledHeader ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Enable AngledHeader on all columns. Best enabled on selected narrow columns (see \" Angled headers \" section of the demo). " ) ;
2023-10-12 14:43:34 +02:00
ImGui : : TreePop ( ) ;
}
if ( ImGui : : TreeNodeEx ( " Other: " , ImGuiTreeNodeFlags_DefaultOpen ) )
{
2020-10-07 16:33:33 +02:00
ImGui : : Checkbox ( " show_wrapped_text " , & show_wrapped_text ) ;
2020-12-24 18:32:27 +01:00
2020-10-07 16:33:33 +02:00
ImGui : : DragFloat2 ( " ##OuterSize " , & outer_size_value . x ) ;
ImGui : : SameLine ( 0.0f , ImGui : : GetStyle ( ) . ItemInnerSpacing . x ) ;
ImGui : : Checkbox ( " outer_size " , & outer_size_enabled ) ;
ImGui : : SameLine ( ) ;
2020-12-18 17:27:41 +01:00
HelpMarker ( " If scrolling is disabled (ScrollX and ScrollY not set): \n "
" - The table is output directly in the parent window. \n "
" - OuterSize.x < 0.0f will right-align the table. \n "
2022-09-14 18:19:50 +02:00
" - OuterSize.x = 0.0f will narrow fit the table unless there are any Stretch columns. \n "
2020-12-18 17:27:41 +01:00
" - OuterSize.y then becomes the minimum size for the table, which will extend vertically if there are more rows (unless NoHostExtendY is set). " ) ;
2020-10-07 16:33:33 +02:00
// From a user point of view we will tend to use 'inner_width' differently depending on whether our table is embedding scrolling.
2020-12-24 18:32:27 +01:00
// To facilitate toying with this demo we will actually pass 0.0f to the BeginTable() when ScrollX is disabled.
2020-10-07 16:33:33 +02:00
ImGui : : DragFloat ( " inner_width (when ScrollX active) " , & inner_width_with_scroll , 1.0f , 0.0f , FLT_MAX ) ;
2020-12-24 18:32:27 +01:00
2020-10-07 16:33:33 +02:00
ImGui : : DragFloat ( " row_min_height " , & row_min_height , 1.0f , 0.0f , FLT_MAX ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Specify height of the Selectable item. " ) ;
2020-12-24 18:32:27 +01:00
2020-10-07 16:33:33 +02:00
ImGui : : DragInt ( " items_count " , & items_count , 0.1f , 0 , 9999 ) ;
2020-12-24 18:32:27 +01:00
ImGui : : Combo ( " items_type (first column) " , & contents_type , contents_type_names , IM_ARRAYSIZE ( contents_type_names ) ) ;
2020-10-07 16:33:33 +02:00
//filter.Draw("filter");
ImGui : : TreePop ( ) ;
}
2019-12-19 14:52:18 +01:00
ImGui : : PopItemWidth ( ) ;
2020-10-07 16:33:33 +02:00
PopStyleCompact ( ) ;
2019-12-19 14:52:18 +01:00
ImGui : : Spacing ( ) ;
ImGui : : TreePop ( ) ;
}
2021-02-16 16:53:56 +01:00
// Update item list if we changed the number of items
2019-12-19 14:52:18 +01:00
static ImVector < MyItem > items ;
static ImVector < int > selection ;
static bool items_need_sort = false ;
if ( items . Size ! = items_count )
{
items . resize ( items_count , MyItem ( ) ) ;
for ( int n = 0 ; n < items_count ; n + + )
{
const int template_n = n % IM_ARRAYSIZE ( template_items_names ) ;
MyItem & item = items [ n ] ;
item . ID = n ;
item . Name = template_items_names [ template_n ] ;
item . Quantity = ( template_n = = 3 ) ? 10 : ( template_n = = 4 ) ? 20 : 0 ; // Assign default quantities
}
}
const ImDrawList * parent_draw_list = ImGui : : GetWindowDrawList ( ) ;
const int parent_draw_list_draw_cmd_count = parent_draw_list - > CmdBuffer . Size ;
2020-03-09 11:09:54 +01:00
ImVec2 table_scroll_cur , table_scroll_max ; // For debug display
const ImDrawList * table_draw_list = NULL ; // "
2019-12-19 14:52:18 +01:00
2021-02-16 16:53:56 +01:00
// Submit table
2020-05-12 17:23:10 +02:00
const float inner_width_to_use = ( flags & ImGuiTableFlags_ScrollX ) ? inner_width_with_scroll : 0.0f ;
2021-01-21 16:59:34 +01:00
if ( ImGui : : BeginTable ( " table_advanced " , 6 , flags , outer_size_enabled ? outer_size_value : ImVec2 ( 0 , 0 ) , inner_width_to_use ) )
2019-12-19 14:52:18 +01:00
{
// Declare columns
// We use the "user_id" parameter of TableSetupColumn() to specify a user id that will be stored in the sort specifications.
// This is so our sort function can identify a column given our own identifier. We could also identify them based on their index!
2023-10-12 17:01:42 +02:00
ImGui : : TableSetupColumn ( " ID " , columns_base_flags | ImGuiTableColumnFlags_DefaultSort | ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_NoHide , 0.0f , MyItemColumnID_ID ) ;
ImGui : : TableSetupColumn ( " Name " , columns_base_flags | ImGuiTableColumnFlags_WidthFixed , 0.0f , MyItemColumnID_Name ) ;
ImGui : : TableSetupColumn ( " Action " , columns_base_flags | ImGuiTableColumnFlags_NoSort | ImGuiTableColumnFlags_WidthFixed , 0.0f , MyItemColumnID_Action ) ;
ImGui : : TableSetupColumn ( " Quantity " , columns_base_flags | ImGuiTableColumnFlags_PreferSortDescending , 0.0f , MyItemColumnID_Quantity ) ;
ImGui : : TableSetupColumn ( " Description " , columns_base_flags | ( ( flags & ImGuiTableFlags_NoHostExtendX ) ? 0 : ImGuiTableColumnFlags_WidthStretch ) , 0.0f , MyItemColumnID_Description ) ;
ImGui : : TableSetupColumn ( " Hidden " , columns_base_flags | ImGuiTableColumnFlags_DefaultHide | ImGuiTableColumnFlags_NoSort ) ;
2020-12-11 21:33:37 +01:00
ImGui : : TableSetupScrollFreeze ( freeze_cols , freeze_rows ) ;
2019-12-19 14:52:18 +01:00
// Sort our data if sort specs have been changed!
2023-09-01 14:35:57 +02:00
ImGuiTableSortSpecs * sort_specs = ImGui : : TableGetSortSpecs ( ) ;
if ( sort_specs & & sort_specs - > SpecsDirty )
2019-12-19 14:52:18 +01:00
items_need_sort = true ;
2023-09-01 14:35:57 +02:00
if ( sort_specs & & items_need_sort & & items . Size > 1 )
2019-12-19 14:52:18 +01:00
{
2023-09-01 14:35:57 +02:00
MyItem : : SortWithSortSpecs ( sort_specs , items . Data , items . Size ) ;
sort_specs - > SpecsDirty = false ;
2019-12-19 14:52:18 +01:00
}
items_need_sort = false ;
// Take note of whether we are currently sorting based on the Quantity field,
// we will use this to trigger sorting when we know the data of this column has been modified.
2020-12-03 18:45:15 +01:00
const bool sorts_specs_using_quantity = ( ImGui : : TableGetColumnFlags ( 3 ) & ImGuiTableColumnFlags_IsSorted ) ! = 0 ;
2019-12-19 14:52:18 +01:00
// Show headers
2023-10-12 17:01:42 +02:00
if ( show_headers & & ( columns_base_flags & ImGuiTableColumnFlags_AngledHeader ) ! = 0 )
ImGui : : TableAngledHeadersRow ( ) ;
2019-12-19 14:52:18 +01:00
if ( show_headers )
2020-09-24 14:33:40 +02:00
ImGui : : TableHeadersRow ( ) ;
2019-12-19 14:52:18 +01:00
// Show data
// FIXME-TABLE FIXME-NAV: How we can get decent up/down even though we have the buttons here?
# if 1
2020-11-03 18:47:05 +01:00
// Demonstrate using clipper for large vertical lists
2019-12-19 14:52:18 +01:00
ImGuiListClipper clipper ;
clipper . Begin ( items . Size ) ;
while ( clipper . Step ( ) )
{
for ( int row_n = clipper . DisplayStart ; row_n < clipper . DisplayEnd ; row_n + + )
# else
2020-11-03 18:47:05 +01:00
// Without clipper
2019-12-19 14:52:18 +01:00
{
2020-11-03 18:47:05 +01:00
for ( int row_n = 0 ; row_n < items . Size ; row_n + + )
2019-12-19 14:52:18 +01:00
# endif
{
MyItem * item = & items [ row_n ] ;
2020-01-09 22:02:16 +01:00
//if (!filter.PassFilter(item->Name))
// continue;
2019-12-19 14:52:18 +01:00
const bool item_is_selected = selection . contains ( item - > ID ) ;
ImGui : : PushID ( item - > ID ) ;
ImGui : : TableNextRow ( ImGuiTableRowFlags_None , row_min_height ) ;
// For the demo purpose we can select among different type of items submitted in the first column
2021-02-16 16:53:56 +01:00
ImGui : : TableSetColumnIndex ( 0 ) ;
2019-12-19 14:52:18 +01:00
char label [ 32 ] ;
sprintf ( label , " %04d " , item - > ID ) ;
if ( contents_type = = CT_Text )
ImGui : : TextUnformatted ( label ) ;
else if ( contents_type = = CT_Button )
ImGui : : Button ( label ) ;
else if ( contents_type = = CT_SmallButton )
ImGui : : SmallButton ( label ) ;
2020-07-02 13:59:30 +02:00
else if ( contents_type = = CT_FillButton )
ImGui : : Button ( label , ImVec2 ( - FLT_MIN , 0.0f ) ) ;
2020-11-11 18:54:39 +01:00
else if ( contents_type = = CT_Selectable | | contents_type = = CT_SelectableSpanRow )
2019-12-19 14:52:18 +01:00
{
2023-06-26 14:00:00 +02:00
ImGuiSelectableFlags selectable_flags = ( contents_type = = CT_SelectableSpanRow ) ? ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowOverlap : ImGuiSelectableFlags_None ;
2020-11-11 18:54:39 +01:00
if ( ImGui : : Selectable ( label , item_is_selected , selectable_flags , ImVec2 ( 0 , row_min_height ) ) )
2019-12-19 14:52:18 +01:00
{
if ( ImGui : : GetIO ( ) . KeyCtrl )
{
if ( item_is_selected )
selection . find_erase_unsorted ( item - > ID ) ;
else
selection . push_back ( item - > ID ) ;
}
else
{
selection . clear ( ) ;
selection . push_back ( item - > ID ) ;
}
}
}
2021-02-16 16:53:56 +01:00
if ( ImGui : : TableSetColumnIndex ( 1 ) )
2020-12-03 16:29:08 +01:00
ImGui : : TextUnformatted ( item - > Name ) ;
2019-12-19 14:52:18 +01:00
// Here we demonstrate marking our data set as needing to be sorted again if we modified a quantity,
// and we are currently sorting on the column showing the Quantity.
// To avoid triggering a sort while holding the button, we only trigger it when the button has been released.
2024-01-04 11:50:38 +01:00
// You will probably need some extra logic if you want to automatically sort when a specific entry changes.
2021-02-16 16:53:56 +01:00
if ( ImGui : : TableSetColumnIndex ( 2 ) )
2019-12-19 14:52:18 +01:00
{
if ( ImGui : : SmallButton ( " Chop " ) ) { item - > Quantity + = 1 ; }
if ( sorts_specs_using_quantity & & ImGui : : IsItemDeactivated ( ) ) { items_need_sort = true ; }
ImGui : : SameLine ( ) ;
if ( ImGui : : SmallButton ( " Eat " ) ) { item - > Quantity - = 1 ; }
if ( sorts_specs_using_quantity & & ImGui : : IsItemDeactivated ( ) ) { items_need_sort = true ; }
}
2021-02-16 16:53:56 +01:00
if ( ImGui : : TableSetColumnIndex ( 3 ) )
2020-12-03 16:29:08 +01:00
ImGui : : Text ( " %d " , item - > Quantity ) ;
2019-12-19 14:52:18 +01:00
2021-02-16 16:53:56 +01:00
ImGui : : TableSetColumnIndex ( 4 ) ;
2019-12-19 14:52:18 +01:00
if ( show_wrapped_text )
ImGui : : TextWrapped ( " Lorem ipsum dolor sit amet " ) ;
else
ImGui : : Text ( " Lorem ipsum dolor sit amet " ) ;
2021-02-16 16:53:56 +01:00
if ( ImGui : : TableSetColumnIndex ( 5 ) )
2020-12-03 16:29:08 +01:00
ImGui : : Text ( " 1234 " ) ;
2020-03-20 18:53:44 +01:00
2019-12-19 14:52:18 +01:00
ImGui : : PopID ( ) ;
}
}
2020-11-03 18:47:05 +01:00
// Store some info to display debug details below
2020-03-09 11:09:54 +01:00
table_scroll_cur = ImVec2 ( ImGui : : GetScrollX ( ) , ImGui : : GetScrollY ( ) ) ;
table_scroll_max = ImVec2 ( ImGui : : GetScrollMaxX ( ) , ImGui : : GetScrollMaxY ( ) ) ;
table_draw_list = ImGui : : GetWindowDrawList ( ) ;
2019-12-19 14:52:18 +01:00
ImGui : : EndTable ( ) ;
2020-03-09 11:09:54 +01:00
}
static bool show_debug_details = false ;
ImGui : : Checkbox ( " Debug details " , & show_debug_details ) ;
if ( show_debug_details & & table_draw_list )
{
ImGui : : SameLine ( 0.0f , 0.0f ) ;
const int table_draw_list_draw_cmd_count = table_draw_list - > CmdBuffer . Size ;
if ( table_draw_list = = parent_draw_list )
2020-11-03 18:47:05 +01:00
ImGui : : Text ( " : DrawCmd: +%d (in same window) " ,
table_draw_list_draw_cmd_count - parent_draw_list_draw_cmd_count ) ;
2020-03-09 11:09:54 +01:00
else
ImGui : : Text ( " : DrawCmd: +%d (in child window), Scroll: (%.f/%.f) (%.f/%.f) " ,
table_draw_list_draw_cmd_count - 1 , table_scroll_cur . x , table_scroll_max . x , table_scroll_cur . y , table_scroll_max . y ) ;
2019-12-19 14:52:18 +01:00
}
ImGui : : TreePop ( ) ;
}
2019-12-29 19:48:10 +01:00
ImGui : : PopID ( ) ;
ShowDemoWindowColumns ( ) ;
2019-12-19 14:52:18 +01:00
if ( disable_indent )
ImGui : : PopStyleVar ( ) ;
}
2019-12-29 19:48:10 +01:00
// Demonstrate old/legacy Columns API!
// [2020: Columns are under-featured and not maintained. Prefer using the more flexible and powerful BeginTable() API!]
2018-10-25 23:34:05 +02:00
static void ShowDemoWindowColumns ( )
{
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Columns (legacy API) " ) ;
2019-12-29 19:48:10 +01:00
bool open = ImGui : : TreeNode ( " Legacy Columns API " ) ;
2019-04-24 17:04:20 +02:00
ImGui : : SameLine ( ) ;
2019-12-29 19:48:10 +01:00
HelpMarker ( " Columns() is an old API! Prefer using the more flexible and powerful BeginTable() API! " ) ;
if ( ! open )
return ;
2019-12-19 14:52:18 +01:00
2018-10-25 23:40:33 +02:00
// Basic columns
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Columns (legacy API)/Basic " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Basic " ) )
{
ImGui : : Text ( " Without border: " ) ;
ImGui : : Columns ( 3 , " mycolumns3 " , false ) ; // 3-ways, no border
ImGui : : Separator ( ) ;
for ( int n = 0 ; n < 14 ; n + + )
2015-11-28 17:44:09 +01:00
{
2018-10-25 23:40:33 +02:00
char label [ 32 ] ;
sprintf ( label , " Item %d " , n ) ;
if ( ImGui : : Selectable ( label ) ) { }
2019-06-21 19:38:33 +02:00
//if (ImGui::Button(label, ImVec2(-FLT_MIN,0.0f))) {}
2015-11-28 17:44:09 +01:00
ImGui : : NextColumn ( ) ;
}
2018-10-25 23:40:33 +02:00
ImGui : : Columns ( 1 ) ;
ImGui : : Separator ( ) ;
2015-07-22 01:00:28 +02:00
2018-10-25 23:40:33 +02:00
ImGui : : Text ( " With border: " ) ;
ImGui : : Columns ( 4 , " mycolumns " ) ; // 4-ways, with border
ImGui : : Separator ( ) ;
ImGui : : Text ( " ID " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " Name " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " Path " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " Hovered " ) ; ImGui : : NextColumn ( ) ;
ImGui : : Separator ( ) ;
const char * names [ 3 ] = { " One " , " Two " , " Three " } ;
const char * paths [ 3 ] = { " /path/one " , " /path/two " , " /path/three " } ;
static int selected = - 1 ;
for ( int i = 0 ; i < 3 ; i + + )
2015-11-28 17:44:09 +01:00
{
2018-10-25 23:40:33 +02:00
char label [ 32 ] ;
sprintf ( label , " %04d " , i ) ;
if ( ImGui : : Selectable ( label , selected = = i , ImGuiSelectableFlags_SpanAllColumns ) )
selected = i ;
bool hovered = ImGui : : IsItemHovered ( ) ;
2015-11-28 17:44:09 +01:00
ImGui : : NextColumn ( ) ;
2018-10-25 23:40:33 +02:00
ImGui : : Text ( names [ i ] ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( paths [ i ] ) ; ImGui : : NextColumn ( ) ;
ImGui : : Text ( " %d " , hovered ) ; ImGui : : NextColumn ( ) ;
2015-11-28 17:44:09 +01:00
}
2018-10-25 23:40:33 +02:00
ImGui : : Columns ( 1 ) ;
ImGui : : Separator ( ) ;
ImGui : : TreePop ( ) ;
}
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Columns (legacy API)/Borders " ) ;
2019-05-09 12:56:03 +02:00
if ( ImGui : : TreeNode ( " Borders " ) )
{
// NB: Future columns API should allow automatic horizontal borders.
static bool h_borders = true ;
static bool v_borders = true ;
2019-07-19 21:11:00 +02:00
static int columns_count = 4 ;
const int lines_count = 3 ;
ImGui : : SetNextItemWidth ( ImGui : : GetFontSize ( ) * 8 ) ;
2019-07-21 20:23:15 +02:00
ImGui : : DragInt ( " ##columns_count " , & columns_count , 0.1f , 2 , 10 , " %d columns " ) ;
if ( columns_count < 2 )
columns_count = 2 ;
2019-07-19 21:11:00 +02:00
ImGui : : SameLine ( ) ;
2019-05-09 12:56:03 +02:00
ImGui : : Checkbox ( " horizontal " , & h_borders ) ;
ImGui : : SameLine ( ) ;
ImGui : : Checkbox ( " vertical " , & v_borders ) ;
2019-07-19 21:11:00 +02:00
ImGui : : Columns ( columns_count , NULL , v_borders ) ;
for ( int i = 0 ; i < columns_count * lines_count ; i + + )
2019-05-09 12:56:03 +02:00
{
if ( h_borders & & ImGui : : GetColumnIndex ( ) = = 0 )
ImGui : : Separator ( ) ;
2024-09-09 21:07:10 +02:00
ImGui : : PushID ( i ) ;
2019-05-09 12:56:03 +02:00
ImGui : : Text ( " %c%c%c " , ' a ' + i , ' a ' + i , ' a ' + i ) ;
ImGui : : Text ( " Width %.2f " , ImGui : : GetColumnWidth ( ) ) ;
2019-07-14 21:28:42 +02:00
ImGui : : Text ( " Avail %.2f " , ImGui : : GetContentRegionAvail ( ) . x ) ;
2019-05-09 12:56:03 +02:00
ImGui : : Text ( " Offset %.2f " , ImGui : : GetColumnOffset ( ) ) ;
ImGui : : Text ( " Long text that is likely to clip " ) ;
2019-06-21 19:38:33 +02:00
ImGui : : Button ( " Button " , ImVec2 ( - FLT_MIN , 0.0f ) ) ;
2024-09-09 21:07:10 +02:00
ImGui : : PopID ( ) ;
2019-05-09 12:56:03 +02:00
ImGui : : NextColumn ( ) ;
}
ImGui : : Columns ( 1 ) ;
if ( h_borders )
ImGui : : Separator ( ) ;
ImGui : : TreePop ( ) ;
}
2018-10-25 23:40:33 +02:00
// Create multiple items in a same cell before switching to next column
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Columns (legacy API)/Mixed items " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Mixed items " ) )
{
ImGui : : Columns ( 3 , " mixed " ) ;
ImGui : : Separator ( ) ;
2015-07-22 01:00:28 +02:00
2018-10-25 23:40:33 +02:00
ImGui : : Text ( " Hello " ) ;
ImGui : : Button ( " Banana " ) ;
ImGui : : NextColumn ( ) ;
ImGui : : Text ( " ImGui " ) ;
ImGui : : Button ( " Apple " ) ;
static float foo = 1.0f ;
ImGui : : InputFloat ( " red " , & foo , 0.05f , 0 , " %.3f " ) ;
ImGui : : Text ( " An extra line here. " ) ;
ImGui : : NextColumn ( ) ;
ImGui : : Text ( " Sailor " ) ;
ImGui : : Button ( " Corniflower " ) ;
static float bar = 1.0f ;
ImGui : : InputFloat ( " blue " , & bar , 0.05f , 0 , " %.3f " ) ;
ImGui : : NextColumn ( ) ;
if ( ImGui : : CollapsingHeader ( " Category A " ) ) { ImGui : : Text ( " Blah blah blah " ) ; } ImGui : : NextColumn ( ) ;
if ( ImGui : : CollapsingHeader ( " Category B " ) ) { ImGui : : Text ( " Blah blah blah " ) ; } ImGui : : NextColumn ( ) ;
if ( ImGui : : CollapsingHeader ( " Category C " ) ) { ImGui : : Text ( " Blah blah blah " ) ; } ImGui : : NextColumn ( ) ;
ImGui : : Columns ( 1 ) ;
ImGui : : Separator ( ) ;
ImGui : : TreePop ( ) ;
}
// Word wrapping
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Columns (legacy API)/Word-wrapping " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Word-wrapping " ) )
{
ImGui : : Columns ( 2 , " word-wrapping " ) ;
ImGui : : Separator ( ) ;
ImGui : : TextWrapped ( " The quick brown fox jumps over the lazy dog. " ) ;
ImGui : : TextWrapped ( " Hello Left " ) ;
ImGui : : NextColumn ( ) ;
ImGui : : TextWrapped ( " The quick brown fox jumps over the lazy dog. " ) ;
ImGui : : TextWrapped ( " Hello Right " ) ;
ImGui : : Columns ( 1 ) ;
ImGui : : Separator ( ) ;
ImGui : : TreePop ( ) ;
}
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Columns (legacy API)/Horizontal Scrolling " ) ;
2018-10-25 23:40:33 +02:00
if ( ImGui : : TreeNode ( " Horizontal Scrolling " ) )
{
ImGui : : SetNextWindowContentSize ( ImVec2 ( 1500.0f , 0.0f ) ) ;
2020-05-05 19:39:24 +02:00
ImVec2 child_size = ImVec2 ( 0 , ImGui : : GetFontSize ( ) * 20.0f ) ;
2023-10-18 18:50:19 +02:00
ImGui : : BeginChild ( " ##ScrollingRegion " , child_size , ImGuiChildFlags_None , ImGuiWindowFlags_HorizontalScrollbar ) ;
2018-10-25 23:40:33 +02:00
ImGui : : Columns ( 10 ) ;
2020-11-03 18:47:05 +01:00
// Also demonstrate using clipper for large vertical lists
2018-10-25 23:40:33 +02:00
int ITEMS_COUNT = 2000 ;
2020-11-03 18:47:05 +01:00
ImGuiListClipper clipper ;
2020-09-24 18:08:01 +02:00
clipper . Begin ( ITEMS_COUNT ) ;
2018-10-25 23:40:33 +02:00
while ( clipper . Step ( ) )
2015-11-28 17:44:09 +01:00
{
2018-10-25 23:40:33 +02:00
for ( int i = clipper . DisplayStart ; i < clipper . DisplayEnd ; i + + )
for ( int j = 0 ; j < 10 ; j + + )
{
ImGui : : Text ( " Line %d Column %d... " , i , j ) ;
ImGui : : NextColumn ( ) ;
}
2015-07-22 01:00:28 +02:00
}
2018-10-25 23:40:33 +02:00
ImGui : : Columns ( 1 ) ;
ImGui : : EndChild ( ) ;
ImGui : : TreePop ( ) ;
}
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Columns (legacy API)/Tree " ) ;
2019-05-02 20:19:53 +02:00
if ( ImGui : : TreeNode ( " Tree " ) )
2018-10-25 23:40:33 +02:00
{
2019-05-02 20:19:53 +02:00
ImGui : : Columns ( 2 , " tree " , true ) ;
for ( int x = 0 ; x < 3 ; x + + )
{
bool open1 = ImGui : : TreeNode ( ( void * ) ( intptr_t ) x , " Node%d " , x ) ;
ImGui : : NextColumn ( ) ;
ImGui : : Text ( " Node contents " ) ;
ImGui : : NextColumn ( ) ;
if ( open1 )
{
2019-05-27 17:28:18 +02:00
for ( int y = 0 ; y < 3 ; y + + )
2019-05-02 20:19:53 +02:00
{
bool open2 = ImGui : : TreeNode ( ( void * ) ( intptr_t ) y , " Node%d.%d " , x , y ) ;
ImGui : : NextColumn ( ) ;
ImGui : : Text ( " Node contents " ) ;
if ( open2 )
{
ImGui : : Text ( " Even more contents " ) ;
if ( ImGui : : TreeNode ( " Tree in column " ) )
{
ImGui : : Text ( " The quick brown fox jumps over the lazy dog " ) ;
ImGui : : TreePop ( ) ;
}
}
ImGui : : NextColumn ( ) ;
if ( open2 )
ImGui : : TreePop ( ) ;
}
ImGui : : TreePop ( ) ;
}
}
2018-10-25 23:40:33 +02:00
ImGui : : Columns ( 1 ) ;
ImGui : : TreePop ( ) ;
2015-07-22 01:00:28 +02:00
}
2019-04-24 17:04:20 +02:00
2019-12-29 19:48:10 +01:00
ImGui : : TreePop ( ) ;
2018-10-25 23:34:05 +02:00
}
2015-07-22 01:00:28 +02:00
2024-07-19 12:35:57 +02:00
//-----------------------------------------------------------------------------
// [SECTION] ShowDemoWindowInputs()
//-----------------------------------------------------------------------------
2022-09-14 20:13:15 +02:00
static void ShowDemoWindowInputs ( )
2018-10-25 23:34:05 +02:00
{
2022-11-30 20:08:57 +01:00
IMGUI_DEMO_MARKER ( " Inputs & Focus " ) ;
if ( ImGui : : CollapsingHeader ( " Inputs & Focus " ) )
2015-07-22 01:00:28 +02:00
{
2016-07-18 14:31:15 +02:00
ImGuiIO & io = ImGui : : GetIO ( ) ;
2022-11-30 20:08:57 +01:00
// Display inputs submitted to ImGuiIO
IMGUI_DEMO_MARKER ( " Inputs & Focus/Inputs " ) ;
2022-02-18 18:39:29 +01:00
ImGui : : SetNextItemOpen ( true , ImGuiCond_Once ) ;
2024-05-23 18:07:43 +02:00
bool inputs_opened = ImGui : : TreeNode ( " Inputs " ) ;
ImGui : : SameLine ( ) ;
HelpMarker (
" This is a simplified view. See more detailed input state: \n "
" - in 'Tools->Metrics/Debugger->Inputs'. \n "
" - in 'Tools->Debug Log->IO'. " ) ;
if ( inputs_opened )
2016-08-03 20:55:54 +02:00
{
2017-12-22 13:41:41 +01:00
if ( ImGui : : IsMousePosValid ( ) )
ImGui : : Text ( " Mouse pos: (%g, %g) " , io . MousePos . x , io . MousePos . y ) ;
else
ImGui : : Text ( " Mouse pos: <INVALID> " ) ;
2018-04-25 16:38:13 +02:00
ImGui : : Text ( " Mouse delta: (%g, %g) " , io . MouseDelta . x , io . MouseDelta . y ) ;
2022-11-30 20:08:57 +01:00
ImGui : : Text ( " Mouse down: " ) ;
for ( int i = 0 ; i < IM_ARRAYSIZE ( io . MouseDown ) ; i + + ) if ( ImGui : : IsMouseDown ( i ) ) { ImGui : : SameLine ( ) ; ImGui : : Text ( " b%d (%.02f secs) " , i , io . MouseDownDuration [ i ] ) ; }
2016-08-03 20:55:54 +02:00
ImGui : : Text ( " Mouse wheel: %.1f " , io . MouseWheel ) ;
2022-09-14 20:13:15 +02:00
2024-01-04 11:50:38 +01:00
// We iterate both legacy native range and named ImGuiKey ranges. This is a little unusual/odd but this allows
// displaying the data for old/new backends.
// User code should never have to go through such hoops!
// You can generally iterate between ImGuiKey_NamedKey_BEGIN and ImGuiKey_NamedKey_END.
2022-01-03 20:52:52 +01:00
# ifdef IMGUI_DISABLE_OBSOLETE_KEYIO
2022-01-25 12:23:26 +01:00
struct funcs { static bool IsLegacyNativeDupe ( ImGuiKey ) { return false ; } } ;
2023-02-24 12:34:44 +01:00
ImGuiKey start_key = ImGuiKey_NamedKey_BEGIN ;
2022-01-03 20:52:52 +01:00
# else
2023-12-18 18:36:01 +01:00
struct funcs { static bool IsLegacyNativeDupe ( ImGuiKey key ) { return key > = 0 & & key < 512 & & ImGui : : GetIO ( ) . KeyMap [ key ] ! = - 1 ; } } ; // Hide Native<>ImGuiKey duplicates when both exists in the array
2023-02-24 12:34:44 +01:00
ImGuiKey start_key = ( ImGuiKey ) 0 ;
2022-01-03 20:52:52 +01:00
# endif
2023-03-21 16:50:02 +01:00
ImGui : : Text ( " Keys down: " ) ; for ( ImGuiKey key = start_key ; key < ImGuiKey_NamedKey_END ; key = ( ImGuiKey ) ( key + 1 ) ) { if ( funcs : : IsLegacyNativeDupe ( key ) | | ! ImGui : : IsKeyDown ( key ) ) continue ; ImGui : : SameLine ( ) ; ImGui : : Text ( ( key < ImGuiKey_NamedKey_BEGIN ) ? " \" %s \" " : " \" %s \" %d " , ImGui : : GetKeyName ( key ) , key ) ; }
2016-08-03 20:55:54 +02:00
ImGui : : Text ( " Keys mods: %s%s%s%s " , io . KeyCtrl ? " CTRL " : " " , io . KeyShift ? " SHIFT " : " " , io . KeyAlt ? " ALT " : " " , io . KeySuper ? " SUPER " : " " ) ;
2022-11-30 20:08:57 +01:00
ImGui : : Text ( " Chars queue: " ) ; for ( int i = 0 ; i < io . InputQueueCharacters . Size ; i + + ) { ImWchar c = io . InputQueueCharacters [ i ] ; ImGui : : SameLine ( ) ; ImGui : : Text ( " \' %c \' (0x%04X) " , ( c > ' ' & & c < = 255 ) ? ( char ) c : ' ? ' , c ) ; } // FIXME: We should convert 'c' to UTF-8 here but the functions are not public.
2022-01-21 15:24:54 +01:00
2022-01-03 20:52:52 +01:00
ImGui : : TreePop ( ) ;
}
2016-08-03 20:55:54 +02:00
2022-11-30 20:08:57 +01:00
// Display ImGuiIO output flags
IMGUI_DEMO_MARKER ( " Inputs & Focus/Outputs " ) ;
ImGui : : SetNextItemOpen ( true , ImGuiCond_Once ) ;
2024-05-23 18:07:43 +02:00
bool outputs_opened = ImGui : : TreeNode ( " Outputs " ) ;
ImGui : : SameLine ( ) ;
HelpMarker (
" The value of io.WantCaptureMouse and io.WantCaptureKeyboard are normally set by Dear ImGui "
" to instruct your application of how to route inputs. Typically, when a value is true, it means "
" Dear ImGui wants the corresponding inputs and we expect the underlying application to ignore them. \n \n "
" The most typical case is: when hovering a window, Dear ImGui set io.WantCaptureMouse to true, "
" and underlying application should ignore mouse inputs (in practice there are many and more subtle "
" rules leading to how those flags are set). " ) ;
if ( outputs_opened )
2022-01-03 20:52:52 +01:00
{
2022-05-23 11:22:46 +02:00
ImGui : : Text ( " io.WantCaptureMouse: %d " , io . WantCaptureMouse ) ;
ImGui : : Text ( " io.WantCaptureMouseUnlessPopupClose: %d " , io . WantCaptureMouseUnlessPopupClose ) ;
ImGui : : Text ( " io.WantCaptureKeyboard: %d " , io . WantCaptureKeyboard ) ;
2022-12-08 16:47:53 +01:00
ImGui : : Text ( " io.WantTextInput: %d " , io . WantTextInput ) ;
ImGui : : Text ( " io.WantSetMousePos: %d " , io . WantSetMousePos ) ;
ImGui : : Text ( " io.NavActive: %d, io.NavVisible: %d " , io . NavActive , io . NavVisible ) ;
2022-05-23 11:22:46 +02:00
2022-12-08 18:15:00 +01:00
IMGUI_DEMO_MARKER ( " Inputs & Focus/Outputs/WantCapture override " ) ;
2022-12-08 16:47:53 +01:00
if ( ImGui : : TreeNode ( " WantCapture override " ) )
{
HelpMarker (
" Hovering the colored canvas will override io.WantCaptureXXX fields. \n "
2024-01-04 11:50:38 +01:00
" Notice how normally (when set to none), the value of io.WantCaptureKeyboard would be false when hovering "
" and true when clicking. " ) ;
2022-12-08 16:47:53 +01:00
static int capture_override_mouse = - 1 ;
static int capture_override_keyboard = - 1 ;
const char * capture_override_desc [ ] = { " None " , " Set to false " , " Set to true " } ;
ImGui : : SetNextItemWidth ( ImGui : : GetFontSize ( ) * 15 ) ;
ImGui : : SliderInt ( " SetNextFrameWantCaptureMouse() on hover " , & capture_override_mouse , - 1 , + 1 , capture_override_desc [ capture_override_mouse + 1 ] , ImGuiSliderFlags_AlwaysClamp ) ;
ImGui : : SetNextItemWidth ( ImGui : : GetFontSize ( ) * 15 ) ;
ImGui : : SliderInt ( " SetNextFrameWantCaptureKeyboard() on hover " , & capture_override_keyboard , - 1 , + 1 , capture_override_desc [ capture_override_keyboard + 1 ] , ImGuiSliderFlags_AlwaysClamp ) ;
ImGui : : ColorButton ( " ##panel " , ImVec4 ( 0.7f , 0.1f , 0.7f , 1.0f ) , ImGuiColorEditFlags_NoTooltip | ImGuiColorEditFlags_NoDragDrop , ImVec2 ( 128.0f , 96.0f ) ) ; // Dummy item
if ( ImGui : : IsItemHovered ( ) & & capture_override_mouse ! = - 1 )
ImGui : : SetNextFrameWantCaptureMouse ( capture_override_mouse = = 1 ) ;
if ( ImGui : : IsItemHovered ( ) & & capture_override_keyboard ! = - 1 )
ImGui : : SetNextFrameWantCaptureKeyboard ( capture_override_keyboard = = 1 ) ;
2022-07-06 20:58:20 +02:00
2022-12-08 16:47:53 +01:00
ImGui : : TreePop ( ) ;
}
2016-08-03 20:55:54 +02:00
ImGui : : TreePop ( ) ;
}
2023-03-07 17:37:15 +01:00
// Demonstrate using Shortcut() and Routing Policies.
// The general flow is:
// - Code interested in a chord (e.g. "Ctrl+A") declares their intent.
// - Multiple locations may be interested in same chord! Routing helps find a winner.
// - Every frame, we resolve all claims and assign one owner if the modifiers are matching.
// - The lower-level function is 'bool SetShortcutRouting()', returns true when caller got the route.
// - Most of the times, SetShortcutRouting() is not called directly. User mostly calls Shortcut() with routing flags.
// - If you call Shortcut() WITHOUT any routing option, it uses ImGuiInputFlags_RouteFocused.
// TL;DR: Most uses will simply be:
// - Shortcut(ImGuiMod_Ctrl | ImGuiKey_A); // Use ImGuiInputFlags_RouteFocused policy.
IMGUI_DEMO_MARKER ( " Inputs & Focus/Shortcuts " ) ;
if ( ImGui : : TreeNode ( " Shortcuts " ) )
{
2024-05-24 15:44:59 +02:00
static ImGuiInputFlags route_options = ImGuiInputFlags_Repeat ;
static ImGuiInputFlags route_type = ImGuiInputFlags_RouteFocused ;
ImGui : : CheckboxFlags ( " ImGuiInputFlags_Repeat " , & route_options , ImGuiInputFlags_Repeat ) ;
ImGui : : RadioButton ( " ImGuiInputFlags_RouteActive " , & route_type , ImGuiInputFlags_RouteActive ) ;
ImGui : : RadioButton ( " ImGuiInputFlags_RouteFocused (default) " , & route_type , ImGuiInputFlags_RouteFocused ) ;
ImGui : : RadioButton ( " ImGuiInputFlags_RouteGlobal " , & route_type , ImGuiInputFlags_RouteGlobal ) ;
2024-05-24 16:07:58 +02:00
ImGui : : Indent ( ) ;
2024-05-24 15:44:59 +02:00
ImGui : : BeginDisabled ( route_type ! = ImGuiInputFlags_RouteGlobal ) ;
2024-05-24 16:07:58 +02:00
ImGui : : CheckboxFlags ( " ImGuiInputFlags_RouteOverFocused " , & route_options , ImGuiInputFlags_RouteOverFocused ) ;
ImGui : : CheckboxFlags ( " ImGuiInputFlags_RouteOverActive " , & route_options , ImGuiInputFlags_RouteOverActive ) ;
2024-05-24 15:44:59 +02:00
ImGui : : CheckboxFlags ( " ImGuiInputFlags_RouteUnlessBgFocused " , & route_options , ImGuiInputFlags_RouteUnlessBgFocused ) ;
ImGui : : EndDisabled ( ) ;
2024-05-24 16:07:58 +02:00
ImGui : : Unindent ( ) ;
ImGui : : RadioButton ( " ImGuiInputFlags_RouteAlways " , & route_type , ImGuiInputFlags_RouteAlways ) ;
2024-05-24 15:44:59 +02:00
ImGuiInputFlags flags = route_type | route_options ; // Merged flags
if ( route_type ! = ImGuiInputFlags_RouteGlobal )
2024-05-30 19:53:12 +02:00
flags & = ~ ( ImGuiInputFlags_RouteOverFocused | ImGuiInputFlags_RouteOverActive | ImGuiInputFlags_RouteUnlessBgFocused ) ;
2023-03-07 17:37:15 +01:00
2024-05-23 18:07:43 +02:00
ImGui : : SeparatorText ( " Using SetNextItemShortcut() " ) ;
ImGui : : Text ( " Ctrl+S " ) ;
ImGui : : SetNextItemShortcut ( ImGuiMod_Ctrl | ImGuiKey_S , flags | ImGuiInputFlags_Tooltip ) ;
ImGui : : Button ( " Save " ) ;
ImGui : : Text ( " Alt+F " ) ;
ImGui : : SetNextItemShortcut ( ImGuiMod_Alt | ImGuiKey_F , flags | ImGuiInputFlags_Tooltip ) ;
static float f = 0.5f ;
ImGui : : SliderFloat ( " Factor " , & f , 0.0f , 1.0f ) ;
ImGui : : SeparatorText ( " Using Shortcut() " ) ;
const float line_height = ImGui : : GetTextLineHeightWithSpacing ( ) ;
const ImGuiKeyChord key_chord = ImGuiMod_Ctrl | ImGuiKey_A ;
ImGui : : Text ( " Ctrl+A " ) ;
2023-03-07 17:37:15 +01:00
ImGui : : Text ( " IsWindowFocused: %d, Shortcut: %s " , ImGui : : IsWindowFocused ( ) , ImGui : : Shortcut ( key_chord , flags ) ? " PRESSED " : " ... " ) ;
2024-05-23 18:07:43 +02:00
ImGui : : PushStyleColor ( ImGuiCol_ChildBg , ImVec4 ( 1.0f , 0.0f , 1.0f , 0.1f ) ) ;
2023-03-07 17:37:15 +01:00
ImGui : : BeginChild ( " WindowA " , ImVec2 ( - FLT_MIN , line_height * 14 ) , true ) ;
ImGui : : Text ( " Press CTRL+A and see who receives it! " ) ;
ImGui : : Separator ( ) ;
// 1: Window polling for CTRL+A
ImGui : : Text ( " (in WindowA) " ) ;
ImGui : : Text ( " IsWindowFocused: %d, Shortcut: %s " , ImGui : : IsWindowFocused ( ) , ImGui : : Shortcut ( key_chord , flags ) ? " PRESSED " : " ... " ) ;
// 2: InputText also polling for CTRL+A: it always uses _RouteFocused internally (gets priority when active)
// (Commmented because the owner-aware version of Shortcut() is still in imgui_internal.h)
//char str[16] = "Press CTRL+A";
//ImGui::Spacing();
//ImGui::InputText("InputTextB", str, IM_ARRAYSIZE(str), ImGuiInputTextFlags_ReadOnly);
//ImGuiID item_id = ImGui::GetItemID();
//ImGui::SameLine(); HelpMarker("Internal widgets always use _RouteFocused");
//ImGui::Text("IsWindowFocused: %d, Shortcut: %s", ImGui::IsWindowFocused(), ImGui::Shortcut(key_chord, flags, item_id) ? "PRESSED" : "...");
// 3: Dummy child is not claiming the route: focusing them shouldn't steal route away from WindowA
ImGui : : BeginChild ( " ChildD " , ImVec2 ( - FLT_MIN , line_height * 4 ) , true ) ;
ImGui : : Text ( " (in ChildD: not using same Shortcut) " ) ;
ImGui : : Text ( " IsWindowFocused: %d " , ImGui : : IsWindowFocused ( ) ) ;
ImGui : : EndChild ( ) ;
// 4: Child window polling for CTRL+A. It is deeper than WindowA and gets priority when focused.
ImGui : : BeginChild ( " ChildE " , ImVec2 ( - FLT_MIN , line_height * 4 ) , true ) ;
ImGui : : Text ( " (in ChildE: using same Shortcut) " ) ;
ImGui : : Text ( " IsWindowFocused: %d, Shortcut: %s " , ImGui : : IsWindowFocused ( ) , ImGui : : Shortcut ( key_chord , flags ) ? " PRESSED " : " ... " ) ;
ImGui : : EndChild ( ) ;
// 5: In a popup
if ( ImGui : : Button ( " Open Popup " ) )
ImGui : : OpenPopup ( " PopupF " ) ;
if ( ImGui : : BeginPopup ( " PopupF " ) )
{
ImGui : : Text ( " (in PopupF) " ) ;
ImGui : : Text ( " IsWindowFocused: %d, Shortcut: %s " , ImGui : : IsWindowFocused ( ) , ImGui : : Shortcut ( key_chord , flags ) ? " PRESSED " : " ... " ) ;
// (Commmented because the owner-aware version of Shortcut() is still in imgui_internal.h)
//ImGui::InputText("InputTextG", str, IM_ARRAYSIZE(str), ImGuiInputTextFlags_ReadOnly);
//ImGui::Text("IsWindowFocused: %d, Shortcut: %s", ImGui::IsWindowFocused(), ImGui::Shortcut(key_chord, flags, ImGui::GetItemID()) ? "PRESSED" : "...");
ImGui : : EndPopup ( ) ;
}
ImGui : : EndChild ( ) ;
2024-05-23 18:07:43 +02:00
ImGui : : PopStyleColor ( ) ;
2023-03-07 17:37:15 +01:00
ImGui : : TreePop ( ) ;
}
2022-11-30 20:08:57 +01:00
// Display mouse cursors
IMGUI_DEMO_MARKER ( " Inputs & Focus/Mouse Cursors " ) ;
if ( ImGui : : TreeNode ( " Mouse Cursors " ) )
{
const char * mouse_cursors_names [ ] = { " Arrow " , " TextInput " , " ResizeAll " , " ResizeNS " , " ResizeEW " , " ResizeNESW " , " ResizeNWSE " , " Hand " , " NotAllowed " } ;
IM_ASSERT ( IM_ARRAYSIZE ( mouse_cursors_names ) = = ImGuiMouseCursor_COUNT ) ;
ImGuiMouseCursor current = ImGui : : GetMouseCursor ( ) ;
2024-09-16 11:19:05 +02:00
const char * cursor_name = ( current > = ImGuiMouseCursor_Arrow ) & & ( current < ImGuiMouseCursor_COUNT ) ? mouse_cursors_names [ current ] : " N/A " ;
ImGui : : Text ( " Current mouse cursor = %d: %s " , current , cursor_name ) ;
2022-11-30 20:08:57 +01:00
ImGui : : BeginDisabled ( true ) ;
ImGui : : CheckboxFlags ( " io.BackendFlags: HasMouseCursors " , & io . BackendFlags , ImGuiBackendFlags_HasMouseCursors ) ;
ImGui : : EndDisabled ( ) ;
ImGui : : Text ( " Hover to see mouse cursors: " ) ;
ImGui : : SameLine ( ) ; HelpMarker (
" Your application can render a different mouse cursor based on what ImGui::GetMouseCursor() returns. "
" If software cursor rendering (io.MouseDrawCursor) is set ImGui will draw the right cursor for you, "
" otherwise your backend needs to handle it. " ) ;
for ( int i = 0 ; i < ImGuiMouseCursor_COUNT ; i + + )
{
char label [ 32 ] ;
sprintf ( label , " Mouse cursor %d: %s " , i , mouse_cursors_names [ i ] ) ;
ImGui : : Bullet ( ) ; ImGui : : Selectable ( label , false ) ;
if ( ImGui : : IsItemHovered ( ) )
ImGui : : SetMouseCursor ( i ) ;
}
ImGui : : TreePop ( ) ;
}
IMGUI_DEMO_MARKER ( " Inputs & Focus/Tabbing " ) ;
2015-07-22 01:00:28 +02:00
if ( ImGui : : TreeNode ( " Tabbing " ) )
{
ImGui : : Text ( " Use TAB/SHIFT+TAB to cycle through keyboard editable fields. " ) ;
2020-08-03 21:19:12 +02:00
static char buf [ 32 ] = " hello " ;
2015-07-22 01:00:28 +02:00
ImGui : : InputText ( " 1 " , buf , IM_ARRAYSIZE ( buf ) ) ;
ImGui : : InputText ( " 2 " , buf , IM_ARRAYSIZE ( buf ) ) ;
ImGui : : InputText ( " 3 " , buf , IM_ARRAYSIZE ( buf ) ) ;
2024-07-15 18:41:06 +02:00
ImGui : : PushItemFlag ( ImGuiItemFlags_NoTabStop , true ) ;
2015-07-22 01:00:28 +02:00
ImGui : : InputText ( " 4 (tab skip) " , buf , IM_ARRAYSIZE ( buf ) ) ;
2021-04-30 21:40:42 +02:00
ImGui : : SameLine ( ) ; HelpMarker ( " Item won't be cycled through when using TAB or Shift+Tab. " ) ;
2024-07-15 18:41:06 +02:00
ImGui : : PopItemFlag ( ) ;
2015-07-22 01:00:28 +02:00
ImGui : : InputText ( " 5 " , buf , IM_ARRAYSIZE ( buf ) ) ;
ImGui : : TreePop ( ) ;
}
2022-11-30 20:08:57 +01:00
IMGUI_DEMO_MARKER ( " Inputs & Focus/Focus from code " ) ;
2015-07-22 01:00:28 +02:00
if ( ImGui : : TreeNode ( " Focus from code " ) )
{
bool focus_1 = ImGui : : Button ( " Focus on 1 " ) ; ImGui : : SameLine ( ) ;
bool focus_2 = ImGui : : Button ( " Focus on 2 " ) ; ImGui : : SameLine ( ) ;
bool focus_3 = ImGui : : Button ( " Focus on 3 " ) ;
int has_focus = 0 ;
static char buf [ 128 ] = " click on a button to set focus " ;
2015-08-24 13:50:18 +02:00
2015-07-22 01:00:28 +02:00
if ( focus_1 ) ImGui : : SetKeyboardFocusHere ( ) ;
ImGui : : InputText ( " 1 " , buf , IM_ARRAYSIZE ( buf ) ) ;
if ( ImGui : : IsItemActive ( ) ) has_focus = 1 ;
2015-08-24 13:50:18 +02:00
2015-07-22 01:00:28 +02:00
if ( focus_2 ) ImGui : : SetKeyboardFocusHere ( ) ;
ImGui : : InputText ( " 2 " , buf , IM_ARRAYSIZE ( buf ) ) ;
if ( ImGui : : IsItemActive ( ) ) has_focus = 2 ;
2024-07-15 18:41:06 +02:00
ImGui : : PushItemFlag ( ImGuiItemFlags_NoTabStop , true ) ;
2015-07-22 01:00:28 +02:00
if ( focus_3 ) ImGui : : SetKeyboardFocusHere ( ) ;
ImGui : : InputText ( " 3 (tab skip) " , buf , IM_ARRAYSIZE ( buf ) ) ;
if ( ImGui : : IsItemActive ( ) ) has_focus = 3 ;
2021-04-30 21:40:42 +02:00
ImGui : : SameLine ( ) ; HelpMarker ( " Item won't be cycled through when using TAB or Shift+Tab. " ) ;
2024-07-15 18:41:06 +02:00
ImGui : : PopItemFlag ( ) ;
2017-10-06 03:10:59 +02:00
2017-10-06 06:25:20 +02:00
if ( has_focus )
ImGui : : Text ( " Item with focus: %d " , has_focus ) ;
else
ImGui : : Text ( " Item with focus: <none> " ) ;
2017-10-06 03:10:59 +02:00
// Use >= 0 parameter to SetKeyboardFocusHere() to focus an upcoming item
static float f3 [ 3 ] = { 0.0f , 0.0f , 0.0f } ;
int focus_ahead = - 1 ;
2019-01-16 16:10:51 +01:00
if ( ImGui : : Button ( " Focus on X " ) ) { focus_ahead = 0 ; } ImGui : : SameLine ( ) ;
if ( ImGui : : Button ( " Focus on Y " ) ) { focus_ahead = 1 ; } ImGui : : SameLine ( ) ;
if ( ImGui : : Button ( " Focus on Z " ) ) { focus_ahead = 2 ; }
2017-10-06 03:10:59 +02:00
if ( focus_ahead ! = - 1 ) ImGui : : SetKeyboardFocusHere ( focus_ahead ) ;
ImGui : : SliderFloat3 ( " Float3 " , & f3 [ 0 ] , 0.0f , 1.0f ) ;
2017-10-06 06:25:20 +02:00
ImGui : : TextWrapped ( " NB: Cursor & selection are preserved when refocusing last used item in code. " ) ;
2015-07-22 01:00:28 +02:00
ImGui : : TreePop ( ) ;
}
2022-11-30 20:08:57 +01:00
IMGUI_DEMO_MARKER ( " Inputs & Focus/Dragging " ) ;
2015-07-22 01:00:28 +02:00
if ( ImGui : : TreeNode ( " Dragging " ) )
{
2016-10-16 18:21:38 +02:00
ImGui : : TextWrapped ( " You can use ImGui::GetMouseDragDelta(0) to query for the dragged amount on any widget. " ) ;
2017-12-06 23:38:33 +01:00
for ( int button = 0 ; button < 3 ; button + + )
2020-05-05 19:39:24 +02:00
{
ImGui : : Text ( " IsMouseDragging(%d): " , button ) ;
ImGui : : Text ( " w/ default threshold: %d, " , ImGui : : IsMouseDragging ( button ) ) ;
ImGui : : Text ( " w/ zero threshold: %d, " , ImGui : : IsMouseDragging ( button , 0.0f ) ) ;
ImGui : : Text ( " w/ large threshold: %d, " , ImGui : : IsMouseDragging ( button , 20.0f ) ) ;
}
2019-03-16 15:48:21 +01:00
2015-07-22 01:00:28 +02:00
ImGui : : Button ( " Drag Me " ) ;
if ( ImGui : : IsItemActive ( ) )
2019-03-15 15:03:37 +01:00
ImGui : : GetForegroundDrawList ( ) - > AddLine ( io . MouseClickedPos [ 0 ] , io . MousePos , ImGui : : GetColorU32 ( ImGuiCol_Button ) , 4.0f ) ; // Draw a line between the button and the mouse cursor
2020-05-05 19:39:24 +02:00
// Drag operations gets "unlocked" when the mouse has moved past a certain threshold
// (the default threshold is stored in io.MouseDragThreshold). You can request a lower or higher
// threshold using the second parameter of IsMouseDragging() and GetMouseDragDelta().
2019-03-15 15:03:37 +01:00
ImVec2 value_raw = ImGui : : GetMouseDragDelta ( 0 , 0.0f ) ;
ImVec2 value_with_lock_threshold = ImGui : : GetMouseDragDelta ( 0 ) ;
ImVec2 mouse_delta = io . MouseDelta ;
2020-05-05 19:39:24 +02:00
ImGui : : Text ( " GetMouseDragDelta(0): " ) ;
ImGui : : Text ( " w/ default threshold: (%.1f, %.1f) " , value_with_lock_threshold . x , value_with_lock_threshold . y ) ;
ImGui : : Text ( " w/ zero threshold: (%.1f, %.1f) " , value_raw . x , value_raw . y ) ;
ImGui : : Text ( " io.MouseDelta: (%.1f, %.1f) " , mouse_delta . x , mouse_delta . y ) ;
2015-07-22 01:00:28 +02:00
ImGui : : TreePop ( ) ;
}
}
}
2018-11-30 17:15:03 +01:00
//-----------------------------------------------------------------------------
// [SECTION] About Window / ShowAboutWindow()
2019-09-23 15:31:05 +02:00
// Access from Dear ImGui Demo -> Tools -> About
2018-11-30 17:15:03 +01:00
//-----------------------------------------------------------------------------
void ImGui : : ShowAboutWindow ( bool * p_open )
{
2018-12-11 16:59:17 +01:00
if ( ! ImGui : : Begin ( " About Dear ImGui " , p_open , ImGuiWindowFlags_AlwaysAutoResize ) )
{
ImGui : : End ( ) ;
return ;
}
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Tools/About Dear ImGui " ) ;
2023-06-14 16:13:01 +02:00
ImGui : : Text ( " Dear ImGui %s (%d) " , IMGUI_VERSION , IMGUI_VERSION_NUM ) ;
2024-07-02 16:58:07 +02:00
ImGui : : TextLinkOpenURL ( " Homepage " , " https://github.com/ocornut/imgui " ) ;
ImGui : : SameLine ( ) ;
ImGui : : TextLinkOpenURL ( " FAQ " , " https://github.com/ocornut/imgui/blob/master/docs/FAQ.md " ) ;
ImGui : : SameLine ( ) ;
ImGui : : TextLinkOpenURL ( " Wiki " , " https://github.com/ocornut/imgui/wiki " ) ;
ImGui : : SameLine ( ) ;
ImGui : : TextLinkOpenURL ( " Releases " , " https://github.com/ocornut/imgui/releases " ) ;
ImGui : : SameLine ( ) ;
ImGui : : TextLinkOpenURL ( " Funding " , " https://github.com/ocornut/imgui/wiki/Funding " ) ;
2018-11-30 17:15:03 +01:00
ImGui : : Separator ( ) ;
2019-09-23 15:31:05 +02:00
ImGui : : Text ( " By Omar Cornut and all Dear ImGui contributors. " ) ;
2018-11-30 17:15:03 +01:00
ImGui : : Text ( " Dear ImGui is licensed under the MIT License, see LICENSE for more information. " ) ;
2024-03-17 11:46:12 +01:00
ImGui : : Text ( " If your company uses this, please consider funding the project. " ) ;
2018-11-30 17:15:03 +01:00
static bool show_config_info = false ;
ImGui : : Checkbox ( " Config/Build Information " , & show_config_info ) ;
if ( show_config_info )
{
ImGuiIO & io = ImGui : : GetIO ( ) ;
ImGuiStyle & style = ImGui : : GetStyle ( ) ;
bool copy_to_clipboard = ImGui : : Button ( " Copy to clipboard " ) ;
2020-05-05 19:39:24 +02:00
ImVec2 child_size = ImVec2 ( 0 , ImGui : : GetTextLineHeightWithSpacing ( ) * 18 ) ;
2023-11-07 18:28:03 +01:00
ImGui : : BeginChild ( ImGui : : GetID ( " cfg_infos " ) , child_size , ImGuiChildFlags_FrameStyle ) ;
2018-11-30 17:15:03 +01:00
if ( copy_to_clipboard )
2019-08-23 11:08:30 +02:00
{
2018-11-30 17:15:03 +01:00
ImGui : : LogToClipboard ( ) ;
2020-05-05 19:39:24 +02:00
ImGui : : LogText ( " ``` \n " ) ; // Back quotes will make text appears without formatting when pasting on GitHub
2019-08-23 11:08:30 +02:00
}
2018-11-30 17:15:03 +01:00
ImGui : : Text ( " Dear ImGui %s (%d) " , IMGUI_VERSION , IMGUI_VERSION_NUM ) ;
ImGui : : Separator ( ) ;
ImGui : : Text ( " sizeof(size_t): %d, sizeof(ImDrawIdx): %d, sizeof(ImDrawVert): %d " , ( int ) sizeof ( size_t ) , ( int ) sizeof ( ImDrawIdx ) , ( int ) sizeof ( ImDrawVert ) ) ;
ImGui : : Text ( " define: __cplusplus=%d " , ( int ) __cplusplus ) ;
# ifdef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
ImGui : : Text ( " define: IMGUI_DISABLE_OBSOLETE_FUNCTIONS " ) ;
# endif
2021-12-11 23:53:38 +01:00
# ifdef IMGUI_DISABLE_OBSOLETE_KEYIO
ImGui : : Text ( " define: IMGUI_DISABLE_OBSOLETE_KEYIO " ) ;
# endif
2018-11-30 17:15:03 +01:00
# ifdef IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS
ImGui : : Text ( " define: IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS " ) ;
# endif
# ifdef IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS
ImGui : : Text ( " define: IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS " ) ;
# endif
# ifdef IMGUI_DISABLE_WIN32_FUNCTIONS
ImGui : : Text ( " define: IMGUI_DISABLE_WIN32_FUNCTIONS " ) ;
# endif
2019-11-19 21:20:46 +01:00
# ifdef IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS
ImGui : : Text ( " define: IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS " ) ;
2018-11-30 17:15:03 +01:00
# endif
2019-11-19 20:48:11 +01:00
# ifdef IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS
ImGui : : Text ( " define: IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS " ) ;
2018-11-30 17:15:03 +01:00
# endif
2019-11-19 21:14:44 +01:00
# ifdef IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS
ImGui : : Text ( " define: IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS " ) ;
# endif
# ifdef IMGUI_DISABLE_FILE_FUNCTIONS
ImGui : : Text ( " define: IMGUI_DISABLE_FILE_FUNCTIONS " ) ;
# endif
2018-11-30 17:15:03 +01:00
# ifdef IMGUI_DISABLE_DEFAULT_ALLOCATORS
ImGui : : Text ( " define: IMGUI_DISABLE_DEFAULT_ALLOCATORS " ) ;
# endif
# ifdef IMGUI_USE_BGRA_PACKED_COLOR
ImGui : : Text ( " define: IMGUI_USE_BGRA_PACKED_COLOR " ) ;
# endif
# ifdef _WIN32
ImGui : : Text ( " define: _WIN32 " ) ;
# endif
# ifdef _WIN64
ImGui : : Text ( " define: _WIN64 " ) ;
# endif
# ifdef __linux__
ImGui : : Text ( " define: __linux__ " ) ;
# endif
# ifdef __APPLE__
ImGui : : Text ( " define: __APPLE__ " ) ;
# endif
# ifdef _MSC_VER
ImGui : : Text ( " define: _MSC_VER=%d " , _MSC_VER ) ;
# endif
2021-01-11 10:26:17 +01:00
# ifdef _MSVC_LANG
ImGui : : Text ( " define: _MSVC_LANG=%d " , ( int ) _MSVC_LANG ) ;
# endif
2018-11-30 17:15:03 +01:00
# ifdef __MINGW32__
ImGui : : Text ( " define: __MINGW32__ " ) ;
# endif
# ifdef __MINGW64__
ImGui : : Text ( " define: __MINGW64__ " ) ;
# endif
# ifdef __GNUC__
ImGui : : Text ( " define: __GNUC__=%d " , ( int ) __GNUC__ ) ;
# endif
# ifdef __clang_version__
ImGui : : Text ( " define: __clang_version__=%s " , __clang_version__ ) ;
2023-02-02 18:08:17 +01:00
# endif
# ifdef __EMSCRIPTEN__
ImGui : : Text ( " define: __EMSCRIPTEN__ " ) ;
2024-08-23 19:05:38 +02:00
ImGui : : Text ( " Emscripten: %d.%d.%d " , __EMSCRIPTEN_major__ , __EMSCRIPTEN_minor__ , __EMSCRIPTEN_tiny__ ) ;
2018-11-30 17:15:03 +01:00
# endif
ImGui : : Separator ( ) ;
2018-11-30 18:18:15 +01:00
ImGui : : Text ( " io.BackendPlatformName: %s " , io . BackendPlatformName ? io . BackendPlatformName : " NULL " ) ;
ImGui : : Text ( " io.BackendRendererName: %s " , io . BackendRendererName ? io . BackendRendererName : " NULL " ) ;
2018-12-10 15:36:07 +01:00
ImGui : : Text ( " io.ConfigFlags: 0x%08X " , io . ConfigFlags ) ;
if ( io . ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard ) ImGui : : Text ( " NavEnableKeyboard " ) ;
if ( io . ConfigFlags & ImGuiConfigFlags_NavEnableGamepad ) ImGui : : Text ( " NavEnableGamepad " ) ;
if ( io . ConfigFlags & ImGuiConfigFlags_NoMouse ) ImGui : : Text ( " NoMouse " ) ;
if ( io . ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange ) ImGui : : Text ( " NoMouseCursorChange " ) ;
2024-10-14 16:52:25 +02:00
if ( io . ConfigFlags & ImGuiConfigFlags_NoKeyboard ) ImGui : : Text ( " NoKeyboard " ) ;
2018-12-10 15:36:07 +01:00
if ( io . MouseDrawCursor ) ImGui : : Text ( " io.MouseDrawCursor " ) ;
if ( io . ConfigMacOSXBehaviors ) ImGui : : Text ( " io.ConfigMacOSXBehaviors " ) ;
2024-10-14 15:28:00 +02:00
if ( io . ConfigNavMoveSetMousePos ) ImGui : : Text ( " io.ConfigNavMoveSetMousePos " ) ;
if ( io . ConfigNavCaptureKeyboard ) ImGui : : Text ( " io.ConfigNavCaptureKeyboard " ) ;
2018-12-10 15:36:07 +01:00
if ( io . ConfigInputTextCursorBlink ) ImGui : : Text ( " io.ConfigInputTextCursorBlink " ) ;
if ( io . ConfigWindowsResizeFromEdges ) ImGui : : Text ( " io.ConfigWindowsResizeFromEdges " ) ;
2018-12-10 16:05:30 +01:00
if ( io . ConfigWindowsMoveFromTitleBarOnly ) ImGui : : Text ( " io.ConfigWindowsMoveFromTitleBarOnly " ) ;
2020-11-03 14:28:41 +01:00
if ( io . ConfigMemoryCompactTimer > = 0.0f ) ImGui : : Text ( " io.ConfigMemoryCompactTimer = %.1f " , io . ConfigMemoryCompactTimer ) ;
2018-12-10 15:36:07 +01:00
ImGui : : Text ( " io.BackendFlags: 0x%08X " , io . BackendFlags ) ;
if ( io . BackendFlags & ImGuiBackendFlags_HasGamepad ) ImGui : : Text ( " HasGamepad " ) ;
if ( io . BackendFlags & ImGuiBackendFlags_HasMouseCursors ) ImGui : : Text ( " HasMouseCursors " ) ;
if ( io . BackendFlags & ImGuiBackendFlags_HasSetMousePos ) ImGui : : Text ( " HasSetMousePos " ) ;
2019-05-29 16:29:17 +02:00
if ( io . BackendFlags & ImGuiBackendFlags_RendererHasVtxOffset ) ImGui : : Text ( " RendererHasVtxOffset " ) ;
2018-11-30 17:15:03 +01:00
ImGui : : Separator ( ) ;
ImGui : : Text ( " io.Fonts: %d fonts, Flags: 0x%08X, TexSize: %d,%d " , io . Fonts - > Fonts . Size , io . Fonts - > Flags , io . Fonts - > TexWidth , io . Fonts - > TexHeight ) ;
ImGui : : Text ( " io.DisplaySize: %.2f,%.2f " , io . DisplaySize . x , io . DisplaySize . y ) ;
2019-02-01 16:37:07 +01:00
ImGui : : Text ( " io.DisplayFramebufferScale: %.2f,%.2f " , io . DisplayFramebufferScale . x , io . DisplayFramebufferScale . y ) ;
2018-11-30 17:15:03 +01:00
ImGui : : Separator ( ) ;
ImGui : : Text ( " style.WindowPadding: %.2f,%.2f " , style . WindowPadding . x , style . WindowPadding . y ) ;
ImGui : : Text ( " style.WindowBorderSize: %.2f " , style . WindowBorderSize ) ;
ImGui : : Text ( " style.FramePadding: %.2f,%.2f " , style . FramePadding . x , style . FramePadding . y ) ;
ImGui : : Text ( " style.FrameRounding: %.2f " , style . FrameRounding ) ;
ImGui : : Text ( " style.FrameBorderSize: %.2f " , style . FrameBorderSize ) ;
ImGui : : Text ( " style.ItemSpacing: %.2f,%.2f " , style . ItemSpacing . x , style . ItemSpacing . y ) ;
ImGui : : Text ( " style.ItemInnerSpacing: %.2f,%.2f " , style . ItemInnerSpacing . x , style . ItemInnerSpacing . y ) ;
if ( copy_to_clipboard )
2019-08-23 11:08:30 +02:00
{
ImGui : : LogText ( " \n ``` \n " ) ;
2018-11-30 17:15:03 +01:00
ImGui : : LogFinish ( ) ;
2019-08-23 11:08:30 +02:00
}
2023-11-07 18:28:03 +01:00
ImGui : : EndChild ( ) ;
2018-11-30 17:15:03 +01:00
}
ImGui : : End ( ) ;
}
2018-09-06 11:35:13 +02:00
//-----------------------------------------------------------------------------
2021-05-25 13:23:00 +02:00
// [SECTION] Style Editor / ShowStyleEditor()
2018-09-06 11:35:13 +02:00
//-----------------------------------------------------------------------------
2019-09-23 15:31:05 +02:00
// - ShowFontSelector()
2021-05-25 13:23:00 +02:00
// - ShowStyleSelector()
// - ShowStyleEditor()
2019-09-23 15:31:05 +02:00
//-----------------------------------------------------------------------------
2018-09-06 11:35:13 +02:00
2021-05-25 13:23:00 +02:00
// Forward declare ShowFontAtlas() which isn't worth putting in public API yet
namespace ImGui { IMGUI_API void ShowFontAtlas ( ImFontAtlas * atlas ) ; }
2017-12-13 21:59:16 +01:00
2017-12-24 17:58:41 +01:00
// Demo helper function to select among loaded fonts.
2022-01-12 14:12:25 +01:00
// Here we use the regular BeginCombo()/EndCombo() api which is the more flexible one.
2017-12-13 21:59:16 +01:00
void ImGui : : ShowFontSelector ( const char * label )
{
ImGuiIO & io = ImGui : : GetIO ( ) ;
ImFont * font_current = ImGui : : GetFont ( ) ;
if ( ImGui : : BeginCombo ( label , font_current - > GetDebugName ( ) ) )
{
2023-08-28 12:21:16 +02:00
for ( ImFont * font : io . Fonts - > Fonts )
2019-02-08 14:50:36 +01:00
{
ImGui : : PushID ( ( void * ) font ) ;
if ( ImGui : : Selectable ( font - > GetDebugName ( ) , font = = font_current ) )
io . FontDefault = font ;
ImGui : : PopID ( ) ;
}
2017-12-13 21:59:16 +01:00
ImGui : : EndCombo ( ) ;
}
2018-05-17 14:12:37 +02:00
ImGui : : SameLine ( ) ;
2019-03-06 18:19:28 +01:00
HelpMarker (
2017-12-13 21:59:16 +01:00
" - Load additional fonts with io.Fonts->AddFontFromFileTTF(). \n "
" - The font atlas is built when calling io.Fonts->GetTexDataAsXXXX() or io.Fonts->Build(). \n "
2020-06-09 16:29:00 +02:00
" - Read FAQ and docs/FONTS.md for more details. \n "
2017-12-13 21:59:16 +01:00
" - If you need to add/remove fonts at runtime (e.g. for DPI change), do it before calling NewFrame(). " ) ;
}
2021-05-24 12:49:58 +02:00
// Demo helper function to select among default colors. See ShowStyleEditor() for more advanced options.
// Here we use the simplified Combo() api that packs items into a single literal string.
// Useful for quick combo boxes where the choices are known locally.
bool ImGui : : ShowStyleSelector ( const char * label )
{
static int style_idx = - 1 ;
if ( ImGui : : Combo ( label , & style_idx , " Dark \0 Light \0 Classic \0 " ) )
{
switch ( style_idx )
{
case 0 : ImGui : : StyleColorsDark ( ) ; break ;
case 1 : ImGui : : StyleColorsLight ( ) ; break ;
case 2 : ImGui : : StyleColorsClassic ( ) ; break ;
}
return true ;
}
return false ;
}
2015-08-05 17:31:03 +02:00
void ImGui : : ShowStyleEditor ( ImGuiStyle * ref )
{
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Tools/Style Editor " ) ;
2020-05-05 19:39:24 +02:00
// You can pass in a reference ImGuiStyle structure to compare to, revert to and save to
// (without a reference style pointer, we will use one compared locally as a reference)
2015-08-05 17:31:03 +02:00
ImGuiStyle & style = ImGui : : GetStyle ( ) ;
2017-11-18 21:59:50 +01:00
static ImGuiStyle ref_saved_style ;
2015-08-05 17:31:03 +02:00
2017-11-18 21:59:50 +01:00
// Default to using internal storage as reference
static bool init = true ;
if ( init & & ref = = NULL )
ref_saved_style = style ;
init = false ;
if ( ref = = NULL )
ref = & ref_saved_style ;
2016-05-12 20:59:20 +02:00
2017-11-18 21:59:50 +01:00
ImGui : : PushItemWidth ( ImGui : : GetWindowWidth ( ) * 0.50f ) ;
2017-12-13 21:59:16 +01:00
if ( ImGui : : ShowStyleSelector ( " Colors##Selector " ) )
2017-11-18 21:59:50 +01:00
ref_saved_style = style ;
2017-12-13 21:59:16 +01:00
ImGui : : ShowFontSelector ( " Fonts##Selector " ) ;
2015-08-05 17:31:03 +02:00
2020-05-05 19:39:24 +02:00
// Simplified Settings (expose floating-pointer border sizes as boolean representing 0.0f or 1.0f)
2018-05-17 14:12:37 +02:00
if ( ImGui : : SliderFloat ( " FrameRounding " , & style . FrameRounding , 0.0f , 12.0f , " %.0f " ) )
2017-11-19 15:56:51 +01:00
style . GrabRounding = style . FrameRounding ; // Make GrabRounding always the same value as FrameRounding
2020-05-05 19:39:24 +02:00
{ bool border = ( style . WindowBorderSize > 0.0f ) ; if ( ImGui : : Checkbox ( " WindowBorder " , & border ) ) { style . WindowBorderSize = border ? 1.0f : 0.0f ; } }
2017-11-19 15:56:51 +01:00
ImGui : : SameLine ( ) ;
2020-05-05 19:39:24 +02:00
{ bool border = ( style . FrameBorderSize > 0.0f ) ; if ( ImGui : : Checkbox ( " FrameBorder " , & border ) ) { style . FrameBorderSize = border ? 1.0f : 0.0f ; } }
2017-11-19 16:03:42 +01:00
ImGui : : SameLine ( ) ;
2020-05-05 19:39:24 +02:00
{ bool border = ( style . PopupBorderSize > 0.0f ) ; if ( ImGui : : Checkbox ( " PopupBorder " , & border ) ) { style . PopupBorderSize = border ? 1.0f : 0.0f ; } }
2017-11-19 15:56:51 +01:00
2017-11-18 21:59:50 +01:00
// Save/Revert button
if ( ImGui : : Button ( " Save Ref " ) )
* ref = ref_saved_style = style ;
ImGui : : SameLine ( ) ;
if ( ImGui : : Button ( " Revert Ref " ) )
style = * ref ;
ImGui : : SameLine ( ) ;
2020-05-05 19:39:24 +02:00
HelpMarker (
" Save/Revert in local non-persistent storage. Default Colors definition are not affected. "
" Use \" Export \" below to save them somewhere. " ) ;
2015-08-05 17:31:03 +02:00
2018-12-11 16:59:17 +01:00
ImGui : : Separator ( ) ;
2015-08-05 17:31:03 +02:00
2018-12-11 16:59:17 +01:00
if ( ImGui : : BeginTabBar ( " ##tabs " , ImGuiTabBarFlags_None ) )
{
if ( ImGui : : BeginTabItem ( " Sizes " ) )
{
2023-02-10 12:16:23 +01:00
ImGui : : SeparatorText ( " Main " ) ;
2018-12-11 16:59:17 +01:00
ImGui : : SliderFloat2 ( " WindowPadding " , ( float * ) & style . WindowPadding , 0.0f , 20.0f , " %.0f " ) ;
ImGui : : SliderFloat2 ( " FramePadding " , ( float * ) & style . FramePadding , 0.0f , 20.0f , " %.0f " ) ;
ImGui : : SliderFloat2 ( " ItemSpacing " , ( float * ) & style . ItemSpacing , 0.0f , 20.0f , " %.0f " ) ;
ImGui : : SliderFloat2 ( " ItemInnerSpacing " , ( float * ) & style . ItemInnerSpacing , 0.0f , 20.0f , " %.0f " ) ;
ImGui : : SliderFloat2 ( " TouchExtraPadding " , ( float * ) & style . TouchExtraPadding , 0.0f , 10.0f , " %.0f " ) ;
ImGui : : SliderFloat ( " IndentSpacing " , & style . IndentSpacing , 0.0f , 30.0f , " %.0f " ) ;
ImGui : : SliderFloat ( " ScrollbarSize " , & style . ScrollbarSize , 1.0f , 20.0f , " %.0f " ) ;
ImGui : : SliderFloat ( " GrabMinSize " , & style . GrabMinSize , 1.0f , 20.0f , " %.0f " ) ;
2023-02-10 12:16:23 +01:00
ImGui : : SeparatorText ( " Borders " ) ;
2018-12-11 16:59:17 +01:00
ImGui : : SliderFloat ( " WindowBorderSize " , & style . WindowBorderSize , 0.0f , 1.0f , " %.0f " ) ;
ImGui : : SliderFloat ( " ChildBorderSize " , & style . ChildBorderSize , 0.0f , 1.0f , " %.0f " ) ;
ImGui : : SliderFloat ( " PopupBorderSize " , & style . PopupBorderSize , 0.0f , 1.0f , " %.0f " ) ;
2020-05-16 16:55:05 +02:00
ImGui : : SliderFloat ( " FrameBorderSize " , & style . FrameBorderSize , 0.0f , 1.0f , " %.0f " ) ;
2018-12-11 16:59:17 +01:00
ImGui : : SliderFloat ( " TabBorderSize " , & style . TabBorderSize , 0.0f , 1.0f , " %.0f " ) ;
2023-09-18 15:22:10 +02:00
ImGui : : SliderFloat ( " TabBarBorderSize " , & style . TabBarBorderSize , 0.0f , 2.0f , " %.0f " ) ;
2024-07-22 10:52:53 +02:00
ImGui : : SliderFloat ( " TabBarOverlineSize " , & style . TabBarOverlineSize , 0.0f , 2.0f , " %.0f " ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Overline is only drawn over the selected tab when ImGuiTabBarFlags_DrawSelectedOverline is set. " ) ;
2023-02-10 12:16:23 +01:00
ImGui : : SeparatorText ( " Rounding " ) ;
2019-02-01 10:26:08 +01:00
ImGui : : SliderFloat ( " WindowRounding " , & style . WindowRounding , 0.0f , 12.0f , " %.0f " ) ;
ImGui : : SliderFloat ( " ChildRounding " , & style . ChildRounding , 0.0f , 12.0f , " %.0f " ) ;
2018-12-11 16:59:17 +01:00
ImGui : : SliderFloat ( " FrameRounding " , & style . FrameRounding , 0.0f , 12.0f , " %.0f " ) ;
2019-02-04 14:38:35 +01:00
ImGui : : SliderFloat ( " PopupRounding " , & style . PopupRounding , 0.0f , 12.0f , " %.0f " ) ;
2018-12-11 16:59:17 +01:00
ImGui : : SliderFloat ( " ScrollbarRounding " , & style . ScrollbarRounding , 0.0f , 12.0f , " %.0f " ) ;
ImGui : : SliderFloat ( " GrabRounding " , & style . GrabRounding , 0.0f , 12.0f , " %.0f " ) ;
ImGui : : SliderFloat ( " TabRounding " , & style . TabRounding , 0.0f , 12.0f , " %.0f " ) ;
2023-02-10 12:16:23 +01:00
2023-10-12 17:01:42 +02:00
ImGui : : SeparatorText ( " Tables " ) ;
ImGui : : SliderFloat2 ( " CellPadding " , ( float * ) & style . CellPadding , 0.0f , 20.0f , " %.0f " ) ;
ImGui : : SliderAngle ( " TableAngledHeadersAngle " , & style . TableAngledHeadersAngle , - 50.0f , + 50.0f ) ;
2024-04-30 16:08:48 +02:00
ImGui : : SliderFloat2 ( " TableAngledHeadersTextAlign " , ( float * ) & style . TableAngledHeadersTextAlign , 0.0f , 1.0f , " %.2f " ) ;
2023-10-12 17:01:42 +02:00
2023-02-10 12:16:23 +01:00
ImGui : : SeparatorText ( " Widgets " ) ;
2018-12-11 16:59:17 +01:00
ImGui : : SliderFloat2 ( " WindowTitleAlign " , ( float * ) & style . WindowTitleAlign , 0.0f , 1.0f , " %.2f " ) ;
2019-09-17 16:16:38 +02:00
int window_menu_button_position = style . WindowMenuButtonPosition + 1 ;
if ( ImGui : : Combo ( " WindowMenuButtonPosition " , ( int * ) & window_menu_button_position , " None \0 Left \0 Right \0 " ) )
2024-05-28 17:46:00 +02:00
style . WindowMenuButtonPosition = ( ImGuiDir ) ( window_menu_button_position - 1 ) ;
2019-07-17 01:43:21 +02:00
ImGui : : Combo ( " ColorButtonPosition " , ( int * ) & style . ColorButtonPosition , " Left \0 Right \0 " ) ;
2020-05-05 19:39:24 +02:00
ImGui : : SliderFloat2 ( " ButtonTextAlign " , ( float * ) & style . ButtonTextAlign , 0.0f , 1.0f , " %.2f " ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Alignment applies when a button is larger than its text content. " ) ;
ImGui : : SliderFloat2 ( " SelectableTextAlign " , ( float * ) & style . SelectableTextAlign , 0.0f , 1.0f , " %.2f " ) ;
ImGui : : SameLine ( ) ; HelpMarker ( " Alignment applies when a selectable is larger than its text content. " ) ;
2023-02-10 12:16:23 +01:00
ImGui : : SliderFloat ( " SeparatorTextBorderSize " , & style . SeparatorTextBorderSize , 0.0f , 10.0f , " %.0f " ) ;
ImGui : : SliderFloat2 ( " SeparatorTextAlign " , ( float * ) & style . SeparatorTextAlign , 0.0f , 1.0f , " %.2f " ) ;
2023-06-20 15:18:37 +02:00
ImGui : : SliderFloat2 ( " SeparatorTextPadding " , ( float * ) & style . SeparatorTextPadding , 0.0f , 40.0f , " %.0f " ) ;
2023-01-27 19:01:30 +01:00
ImGui : : SliderFloat ( " LogSliderDeadzone " , & style . LogSliderDeadzone , 0.0f , 12.0f , " %.0f " ) ;
2023-02-10 12:16:23 +01:00
2023-06-16 14:42:38 +02:00
ImGui : : SeparatorText ( " Tooltips " ) ;
for ( int n = 0 ; n < 2 ; n + + )
if ( ImGui : : TreeNodeEx ( n = = 0 ? " HoverFlagsForTooltipMouse " : " HoverFlagsForTooltipNav " ) )
{
ImGuiHoveredFlags * p = ( n = = 0 ) ? & style . HoverFlagsForTooltipMouse : & style . HoverFlagsForTooltipNav ;
ImGui : : CheckboxFlags ( " ImGuiHoveredFlags_DelayNone " , p , ImGuiHoveredFlags_DelayNone ) ;
ImGui : : CheckboxFlags ( " ImGuiHoveredFlags_DelayShort " , p , ImGuiHoveredFlags_DelayShort ) ;
ImGui : : CheckboxFlags ( " ImGuiHoveredFlags_DelayNormal " , p , ImGuiHoveredFlags_DelayNormal ) ;
ImGui : : CheckboxFlags ( " ImGuiHoveredFlags_Stationary " , p , ImGuiHoveredFlags_Stationary ) ;
ImGui : : CheckboxFlags ( " ImGuiHoveredFlags_NoSharedDelay " , p , ImGuiHoveredFlags_NoSharedDelay ) ;
ImGui : : TreePop ( ) ;
}
2023-02-10 12:16:23 +01:00
ImGui : : SeparatorText ( " Misc " ) ;
2024-05-28 15:44:27 +02:00
ImGui : : SliderFloat2 ( " DisplayWindowPadding " , ( float * ) & style . DisplayWindowPadding , 0.0f , 30.0f , " %.0f " ) ; ImGui : : SameLine ( ) ; HelpMarker ( " Apply to regular windows: amount which we enforce to keep visible when moving near edges of your screen. " ) ;
ImGui : : SliderFloat2 ( " DisplaySafeAreaPadding " , ( float * ) & style . DisplaySafeAreaPadding , 0.0f , 30.0f , " %.0f " ) ; ImGui : : SameLine ( ) ; HelpMarker ( " Apply to every windows, menus, popups, tooltips: amount where we avoid displaying contents. Adjust if you cannot see the edges of your screen (e.g. on a TV where scaling has not been configured). " ) ;
2023-06-20 14:38:48 +02:00
2018-12-11 16:59:17 +01:00
ImGui : : EndTabItem ( ) ;
}
if ( ImGui : : BeginTabItem ( " Colors " ) )
{
static int output_dest = 0 ;
static bool output_only_modified = true ;
2019-10-21 16:12:46 +02:00
if ( ImGui : : Button ( " Export " ) )
2015-08-05 17:31:03 +02:00
{
2018-12-11 16:59:17 +01:00
if ( output_dest = = 0 )
ImGui : : LogToClipboard ( ) ;
else
ImGui : : LogToTTY ( ) ;
ImGui : : LogText ( " ImVec4* colors = ImGui::GetStyle().Colors; " IM_NEWLINE ) ;
for ( int i = 0 ; i < ImGuiCol_COUNT ; i + + )
{
const ImVec4 & col = style . Colors [ i ] ;
const char * name = ImGui : : GetStyleColorName ( i ) ;
if ( ! output_only_modified | | memcmp ( & col , & ref - > Colors [ i ] , sizeof ( ImVec4 ) ) ! = 0 )
2020-05-05 19:39:24 +02:00
ImGui : : LogText ( " colors[ImGuiCol_%s]%*s= ImVec4(%.2ff, %.2ff, %.2ff, %.2ff); " IM_NEWLINE ,
name , 23 - ( int ) strlen ( name ) , " " , col . x , col . y , col . z , col . w ) ;
2018-12-11 16:59:17 +01:00
}
ImGui : : LogFinish ( ) ;
2015-08-05 17:31:03 +02:00
}
2019-04-18 18:29:28 +02:00
ImGui : : SameLine ( ) ; ImGui : : SetNextItemWidth ( 120 ) ; ImGui : : Combo ( " ##output_type " , & output_dest , " To Clipboard \0 To TTY \0 " ) ;
2018-12-11 16:59:17 +01:00
ImGui : : SameLine ( ) ; ImGui : : Checkbox ( " Only Modified Colors " , & output_only_modified ) ;
2015-08-05 17:31:03 +02:00
2018-12-11 16:59:17 +01:00
static ImGuiTextFilter filter ;
filter . Draw ( " Filter colors " , ImGui : : GetFontSize ( ) * 16 ) ;
2015-08-05 17:31:03 +02:00
2018-12-11 16:59:17 +01:00
static ImGuiColorEditFlags alpha_flags = 0 ;
2020-05-05 19:39:24 +02:00
if ( ImGui : : RadioButton ( " Opaque " , alpha_flags = = ImGuiColorEditFlags_None ) ) { alpha_flags = ImGuiColorEditFlags_None ; } ImGui : : SameLine ( ) ;
if ( ImGui : : RadioButton ( " Alpha " , alpha_flags = = ImGuiColorEditFlags_AlphaPreview ) ) { alpha_flags = ImGuiColorEditFlags_AlphaPreview ; } ImGui : : SameLine ( ) ;
if ( ImGui : : RadioButton ( " Both " , alpha_flags = = ImGuiColorEditFlags_AlphaPreviewHalf ) ) { alpha_flags = ImGuiColorEditFlags_AlphaPreviewHalf ; } ImGui : : SameLine ( ) ;
HelpMarker (
" In the color list: \n "
2020-10-15 20:05:35 +02:00
" Left-click on color square to open color picker, \n "
2020-05-05 19:39:24 +02:00
" Right-click to open edit options menu. " ) ;
2015-08-05 17:31:03 +02:00
2023-10-17 17:39:56 +02:00
ImGui : : SetNextWindowSizeConstraints ( ImVec2 ( 0.0f , ImGui : : GetTextLineHeightWithSpacing ( ) * 10 ) , ImVec2 ( FLT_MAX , FLT_MAX ) ) ;
2024-08-23 15:24:22 +02:00
ImGui : : BeginChild ( " ##colors " , ImVec2 ( 0 , 0 ) , ImGuiChildFlags_Borders | ImGuiChildFlags_NavFlattened , ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_AlwaysHorizontalScrollbar ) ;
2023-10-17 17:39:50 +02:00
ImGui : : PushItemWidth ( ImGui : : GetFontSize ( ) * - 12 ) ;
2018-12-11 16:59:17 +01:00
for ( int i = 0 ; i < ImGuiCol_COUNT ; i + + )
2015-08-05 17:31:03 +02:00
{
2018-12-11 16:59:17 +01:00
const char * name = ImGui : : GetStyleColorName ( i ) ;
if ( ! filter . PassFilter ( name ) )
continue ;
ImGui : : PushID ( i ) ;
2024-01-10 12:56:16 +01:00
# ifndef IMGUI_DISABLE_DEBUG_TOOLS
2023-11-28 19:33:19 +01:00
if ( ImGui : : Button ( " ? " ) )
ImGui : : DebugFlashStyleColor ( ( ImGuiCol ) i ) ;
ImGui : : SetItemTooltip ( " Flash given color to identify places where it is used. " ) ;
ImGui : : SameLine ( ) ;
2024-01-10 12:56:16 +01:00
# endif
2018-12-11 16:59:17 +01:00
ImGui : : ColorEdit4 ( " ##color " , ( float * ) & style . Colors [ i ] , ImGuiColorEditFlags_AlphaBar | alpha_flags ) ;
if ( memcmp ( & style . Colors [ i ] , & ref - > Colors [ i ] , sizeof ( ImVec4 ) ) ! = 0 )
{
2020-05-05 19:39:24 +02:00
// Tips: in a real user application, you may want to merge and use an icon font into the main font,
// so instead of "Save"/"Revert" you'd use icons!
2020-06-09 16:29:00 +02:00
// Read the FAQ and docs/FONTS.md about using icon fonts. It's really easy and super convenient!
2020-05-05 19:39:24 +02:00
ImGui : : SameLine ( 0.0f , style . ItemInnerSpacing . x ) ; if ( ImGui : : Button ( " Save " ) ) { ref - > Colors [ i ] = style . Colors [ i ] ; }
ImGui : : SameLine ( 0.0f , style . ItemInnerSpacing . x ) ; if ( ImGui : : Button ( " Revert " ) ) { style . Colors [ i ] = ref - > Colors [ i ] ; }
2018-12-11 16:59:17 +01:00
}
ImGui : : SameLine ( 0.0f , style . ItemInnerSpacing . x ) ;
ImGui : : TextUnformatted ( name ) ;
ImGui : : PopID ( ) ;
2015-08-05 17:31:03 +02:00
}
2018-12-11 16:59:17 +01:00
ImGui : : PopItemWidth ( ) ;
ImGui : : EndChild ( ) ;
2015-08-05 17:31:03 +02:00
2018-12-11 16:59:17 +01:00
ImGui : : EndTabItem ( ) ;
2016-05-03 20:22:35 +02:00
}
2018-12-11 16:59:17 +01:00
if ( ImGui : : BeginTabItem ( " Fonts " ) )
2016-05-03 20:22:35 +02:00
{
2019-02-04 14:38:35 +01:00
ImGuiIO & io = ImGui : : GetIO ( ) ;
ImFontAtlas * atlas = io . Fonts ;
2020-06-09 16:29:00 +02:00
HelpMarker ( " Read FAQ and docs/FONTS.md for details on font loading. " ) ;
2021-05-24 12:49:58 +02:00
ImGui : : ShowFontAtlas ( atlas ) ;
2018-12-11 16:59:17 +01:00
2020-05-07 11:38:45 +02:00
// Post-baking font scaling. Note that this is NOT the nice way of scaling fonts, read below.
// (we enforce hard clamping manually as by default DragFloat/SliderFloat allows CTRL+Click text to get out of bounds).
const float MIN_SCALE = 0.3f ;
const float MAX_SCALE = 2.0f ;
HelpMarker (
" Those are old settings provided for convenience. \n "
" However, the _correct_ way of scaling your UI is currently to reload your font at the designed size, "
" rebuild the font atlas, and call style.ScaleAllSizes() on a reference ImGuiStyle structure. \n "
" Using those settings here will give you poor quality results. " ) ;
2018-12-11 16:59:17 +01:00
static float window_scale = 1.0f ;
2021-05-24 12:49:58 +02:00
ImGui : : PushItemWidth ( ImGui : : GetFontSize ( ) * 8 ) ;
2020-09-25 13:34:31 +02:00
if ( ImGui : : DragFloat ( " window scale " , & window_scale , 0.005f , MIN_SCALE , MAX_SCALE , " %.2f " , ImGuiSliderFlags_AlwaysClamp ) ) // Scale only this window
2020-07-23 17:39:22 +02:00
ImGui : : SetWindowFontScale ( window_scale ) ;
2020-09-25 13:34:31 +02:00
ImGui : : DragFloat ( " global scale " , & io . FontGlobalScale , 0.005f , MIN_SCALE , MAX_SCALE , " %.2f " , ImGuiSliderFlags_AlwaysClamp ) ; // Scale everything
2018-12-11 16:59:17 +01:00
ImGui : : PopItemWidth ( ) ;
ImGui : : EndTabItem ( ) ;
2016-05-03 20:22:35 +02:00
}
2018-12-11 16:59:17 +01:00
if ( ImGui : : BeginTabItem ( " Rendering " ) )
{
2020-05-05 19:39:24 +02:00
ImGui : : Checkbox ( " Anti-aliased lines " , & style . AntiAliasedLines ) ;
2020-08-28 16:49:46 +02:00
ImGui : : SameLine ( ) ;
HelpMarker ( " When disabling anti-aliasing lines, you'll probably want to disable borders in your style as well. " ) ;
2020-05-16 16:55:05 +02:00
ImGui : : Checkbox ( " Anti-aliased lines use texture " , & style . AntiAliasedLinesUseTex ) ;
2020-08-28 16:49:46 +02:00
ImGui : : SameLine ( ) ;
2020-10-12 17:34:22 +02:00
HelpMarker ( " Faster lines using texture data. Require backend to render with bilinear filtering (not point/nearest filtering). " ) ;
2020-08-28 16:49:46 +02:00
2018-12-11 16:59:17 +01:00
ImGui : : Checkbox ( " Anti-aliased fill " , & style . AntiAliasedFill ) ;
2021-05-24 12:49:58 +02:00
ImGui : : PushItemWidth ( ImGui : : GetFontSize ( ) * 8 ) ;
2020-01-08 00:10:18 +01:00
ImGui : : DragFloat ( " Curve Tessellation Tolerance " , & style . CurveTessellationTol , 0.02f , 0.10f , 10.0f , " %.2f " ) ;
2018-12-11 16:59:17 +01:00
if ( style . CurveTessellationTol < 0.10f ) style . CurveTessellationTol = 0.10f ;
2020-07-16 21:51:49 +02:00
// When editing the "Circle Segment Max Error" value, draw a preview of its effect on auto-tessellated circles.
2021-02-17 13:06:26 +01:00
ImGui : : DragFloat ( " Circle Tessellation Max Error " , & style . CircleTessellationMaxError , 0.005f , 0.10f , 5.0f , " %.2f " , ImGuiSliderFlags_AlwaysClamp ) ;
2023-03-09 14:59:19 +01:00
const bool show_samples = ImGui : : IsItemActive ( ) ;
if ( show_samples )
2020-07-16 21:51:49 +02:00
ImGui : : SetNextWindowPos ( ImGui : : GetCursorScreenPos ( ) ) ;
2023-03-09 14:59:19 +01:00
if ( show_samples & & ImGui : : BeginTooltip ( ) )
{
2024-06-24 21:57:39 +02:00
ImGui : : TextUnformatted ( " (R = radius, N = approx number of segments) " ) ;
2021-02-17 12:55:25 +01:00
ImGui : : Spacing ( ) ;
2020-08-28 16:49:46 +02:00
ImDrawList * draw_list = ImGui : : GetWindowDrawList ( ) ;
2024-06-24 21:57:39 +02:00
const float min_widget_width = ImGui : : CalcTextSize ( " R: MMM \n N: MMM " ) . x ;
2021-02-17 13:06:26 +01:00
for ( int n = 0 ; n < 8 ; n + + )
2020-07-16 21:51:49 +02:00
{
2021-02-17 13:06:26 +01:00
const float RAD_MIN = 5.0f ;
const float RAD_MAX = 70.0f ;
const float rad = RAD_MIN + ( RAD_MAX - RAD_MIN ) * ( float ) n / ( 8.0f - 1.0f ) ;
2021-02-17 12:55:25 +01:00
ImGui : : BeginGroup ( ) ;
2024-06-24 21:57:39 +02:00
// N is not always exact here due to how PathArcTo() function work internally
2021-02-17 13:06:26 +01:00
ImGui : : Text ( " R: %.f \n N: %d " , rad , draw_list - > _CalcCircleAutoSegmentCount ( rad ) ) ;
const float canvas_width = IM_MAX ( min_widget_width , rad * 2.0f ) ;
const float offset_x = floorf ( canvas_width * 0.5f ) ;
const float offset_y = floorf ( RAD_MAX ) ;
2021-02-17 12:55:25 +01:00
2021-02-17 13:06:26 +01:00
const ImVec2 p1 = ImGui : : GetCursorScreenPos ( ) ;
draw_list - > AddCircle ( ImVec2 ( p1 . x + offset_x , p1 . y + offset_y ) , rad , ImGui : : GetColorU32 ( ImGuiCol_Text ) ) ;
2021-02-17 12:55:25 +01:00
ImGui : : Dummy ( ImVec2 ( canvas_width , RAD_MAX * 2 ) ) ;
2021-02-17 13:06:26 +01:00
/*
const ImVec2 p2 = ImGui : : GetCursorScreenPos ( ) ;
2021-02-17 12:55:25 +01:00
draw_list - > AddCircleFilled ( ImVec2 ( p2 . x + offset_x , p2 . y + offset_y ) , rad , ImGui : : GetColorU32 ( ImGuiCol_Text ) ) ;
ImGui : : Dummy ( ImVec2 ( canvas_width , RAD_MAX * 2 ) ) ;
2021-02-17 13:06:26 +01:00
*/
2021-02-17 12:55:25 +01:00
ImGui : : EndGroup ( ) ;
ImGui : : SameLine ( ) ;
2020-07-16 21:51:49 +02:00
}
ImGui : : EndTooltip ( ) ;
}
ImGui : : SameLine ( ) ;
HelpMarker ( " When drawing circle primitives with \" num_segments == 0 \" tesselation will be calculated automatically. " ) ;
2018-12-11 16:59:17 +01:00
ImGui : : DragFloat ( " Global Alpha " , & style . Alpha , 0.005f , 0.20f , 1.0f , " %.2f " ) ; // Not exposing zero here so user doesn't "lose" the UI (zero alpha clips all widgets). But application code could have a toggle to switch between zero and non-zero.
2021-07-19 19:21:18 +02:00
ImGui : : DragFloat ( " Disabled Alpha " , & style . DisabledAlpha , 0.005f , 0.0f , 1.0f , " %.2f " ) ; ImGui : : SameLine ( ) ; HelpMarker ( " Additional alpha multiplier for disabled items (multiply over current value of Alpha). " ) ;
2018-12-11 16:59:17 +01:00
ImGui : : PopItemWidth ( ) ;
ImGui : : EndTabItem ( ) ;
}
ImGui : : EndTabBar ( ) ;
2016-05-03 20:22:35 +02:00
}
2015-08-05 17:31:03 +02:00
ImGui : : PopItemWidth ( ) ;
}
2022-09-26 14:50:46 +02:00
//-----------------------------------------------------------------------------
// [SECTION] User Guide / ShowUserGuide()
//-----------------------------------------------------------------------------
void ImGui : : ShowUserGuide ( )
{
ImGuiIO & io = ImGui : : GetIO ( ) ;
ImGui : : BulletText ( " Double-click on title bar to collapse window. " ) ;
ImGui : : BulletText (
" Click and drag on lower corner to resize window \n "
" (double-click to auto fit window to its contents). " ) ;
ImGui : : BulletText ( " CTRL+Click on a slider or drag box to input value as text. " ) ;
ImGui : : BulletText ( " TAB/SHIFT+TAB to cycle through keyboard editable fields. " ) ;
ImGui : : BulletText ( " CTRL+Tab to select a window. " ) ;
if ( io . FontAllowUserScaling )
ImGui : : BulletText ( " CTRL+Mouse Wheel to zoom window contents. " ) ;
ImGui : : BulletText ( " While inputing text: \n " ) ;
ImGui : : Indent ( ) ;
ImGui : : BulletText ( " CTRL+Left/Right to word jump. " ) ;
ImGui : : BulletText ( " CTRL+A or double-click to select all. " ) ;
ImGui : : BulletText ( " CTRL+X/C/V to use clipboard cut/copy/paste. " ) ;
ImGui : : BulletText ( " CTRL+Z,CTRL+Y to undo/redo. " ) ;
ImGui : : BulletText ( " ESCAPE to revert. " ) ;
ImGui : : Unindent ( ) ;
ImGui : : BulletText ( " With keyboard navigation enabled: " ) ;
ImGui : : Indent ( ) ;
ImGui : : BulletText ( " Arrow keys to navigate. " ) ;
ImGui : : BulletText ( " Space to activate a widget. " ) ;
ImGui : : BulletText ( " Return to input text into a widget. " ) ;
ImGui : : BulletText ( " Escape to deactivate a widget, close popup, exit child window. " ) ;
ImGui : : BulletText ( " Alt to jump to the menu layer of a window. " ) ;
ImGui : : Unindent ( ) ;
}
2018-07-12 11:40:23 +02:00
//-----------------------------------------------------------------------------
2018-09-06 11:35:13 +02:00
// [SECTION] Example App: Main Menu Bar / ShowExampleAppMainMenuBar()
2018-07-12 11:40:23 +02:00
//-----------------------------------------------------------------------------
2019-09-23 15:31:05 +02:00
// - ShowExampleAppMainMenuBar()
// - ShowExampleMenuFile()
//-----------------------------------------------------------------------------
2018-07-12 11:40:23 +02:00
2019-04-11 15:12:18 +02:00
// Demonstrate creating a "main" fullscreen menu bar and populating it.
// Note the difference between BeginMainMenuBar() and BeginMenuBar():
2020-05-05 19:39:24 +02:00
// - BeginMenuBar() = menu-bar inside current window (which needs the ImGuiWindowFlags_MenuBar flag!)
2019-04-11 15:12:18 +02:00
// - BeginMainMenuBar() = helper to create menu-bar-sized window at the top of the main viewport + call BeginMenuBar() into it.
2015-07-22 01:00:28 +02:00
static void ShowExampleAppMainMenuBar ( )
{
if ( ImGui : : BeginMainMenuBar ( ) )
{
if ( ImGui : : BeginMenu ( " File " ) )
{
ShowExampleMenuFile ( ) ;
ImGui : : EndMenu ( ) ;
}
if ( ImGui : : BeginMenu ( " Edit " ) )
{
if ( ImGui : : MenuItem ( " Undo " , " CTRL+Z " ) ) { }
if ( ImGui : : MenuItem ( " Redo " , " CTRL+Y " , false , false ) ) { } // Disabled item
ImGui : : Separator ( ) ;
if ( ImGui : : MenuItem ( " Cut " , " CTRL+X " ) ) { }
if ( ImGui : : MenuItem ( " Copy " , " CTRL+C " ) ) { }
if ( ImGui : : MenuItem ( " Paste " , " CTRL+V " ) ) { }
ImGui : : EndMenu ( ) ;
}
ImGui : : EndMainMenuBar ( ) ;
}
}
2020-05-05 19:39:24 +02:00
// Note that shortcuts are currently provided for display only
// (future version will add explicit flags to BeginMenu() to request processing shortcuts)
2015-07-22 01:00:28 +02:00
static void ShowExampleMenuFile ( )
{
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Examples/Menu " ) ;
2020-08-03 21:19:12 +02:00
ImGui : : MenuItem ( " (demo menu) " , NULL , false , false ) ;
2015-07-22 01:00:28 +02:00
if ( ImGui : : MenuItem ( " New " ) ) { }
if ( ImGui : : MenuItem ( " Open " , " Ctrl+O " ) ) { }
if ( ImGui : : BeginMenu ( " Open Recent " ) )
{
ImGui : : MenuItem ( " fish_hat.c " ) ;
ImGui : : MenuItem ( " fish_hat.inl " ) ;
ImGui : : MenuItem ( " fish_hat.h " ) ;
if ( ImGui : : BeginMenu ( " More.. " ) )
{
ImGui : : MenuItem ( " Hello " ) ;
ImGui : : MenuItem ( " Sailor " ) ;
if ( ImGui : : BeginMenu ( " Recurse.. " ) )
{
ShowExampleMenuFile ( ) ;
ImGui : : EndMenu ( ) ;
}
ImGui : : EndMenu ( ) ;
}
ImGui : : EndMenu ( ) ;
}
if ( ImGui : : MenuItem ( " Save " , " Ctrl+S " ) ) { }
if ( ImGui : : MenuItem ( " Save As.. " ) ) { }
2020-02-28 16:42:24 +01:00
2015-07-22 01:00:28 +02:00
ImGui : : Separator ( ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Examples/Menu/Options " ) ;
2015-07-22 01:00:28 +02:00
if ( ImGui : : BeginMenu ( " Options " ) )
{
static bool enabled = true ;
ImGui : : MenuItem ( " Enabled " , " " , & enabled ) ;
2024-08-23 15:24:22 +02:00
ImGui : : BeginChild ( " child " , ImVec2 ( 0 , 60 ) , ImGuiChildFlags_Borders ) ;
2015-07-22 01:00:28 +02:00
for ( int i = 0 ; i < 10 ; i + + )
ImGui : : Text ( " Scrolling Text %d " , i ) ;
ImGui : : EndChild ( ) ;
static float f = 0.5f ;
static int n = 0 ;
ImGui : : SliderFloat ( " Value " , & f , 0.0f , 1.0f ) ;
ImGui : : InputFloat ( " Input " , & f , 0.1f ) ;
ImGui : : Combo ( " Combo " , & n , " Yes \0 No \0 Maybe \0 \0 " ) ;
ImGui : : EndMenu ( ) ;
}
2020-02-28 16:42:24 +01:00
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Examples/Menu/Colors " ) ;
2015-07-22 01:00:28 +02:00
if ( ImGui : : BeginMenu ( " Colors " ) )
{
2018-01-24 17:08:37 +01:00
float sz = ImGui : : GetTextLineHeight ( ) ;
2015-07-22 01:00:28 +02:00
for ( int i = 0 ; i < ImGuiCol_COUNT ; i + + )
2017-11-18 23:36:37 +01:00
{
const char * name = ImGui : : GetStyleColorName ( ( ImGuiCol ) i ) ;
2018-01-24 17:08:37 +01:00
ImVec2 p = ImGui : : GetCursorScreenPos ( ) ;
2020-06-30 15:31:54 +02:00
ImGui : : GetWindowDrawList ( ) - > AddRectFilled ( p , ImVec2 ( p . x + sz , p . y + sz ) , ImGui : : GetColorU32 ( ( ImGuiCol ) i ) ) ;
2018-01-24 17:08:37 +01:00
ImGui : : Dummy ( ImVec2 ( sz , sz ) ) ;
2017-11-18 23:36:37 +01:00
ImGui : : SameLine ( ) ;
ImGui : : MenuItem ( name ) ;
}
2015-07-22 01:00:28 +02:00
ImGui : : EndMenu ( ) ;
}
2020-02-28 16:42:24 +01:00
// Here we demonstrate appending again to the "Options" menu (which we already created above)
// Of course in this demo it is a little bit silly that this function calls BeginMenu("Options") twice.
// In a real code-base using it would make senses to use this feature from very different code locations.
if ( ImGui : : BeginMenu ( " Options " ) ) // <-- Append!
{
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Examples/Menu/Append to an existing menu " ) ;
2020-02-28 16:42:24 +01:00
static bool b = true ;
ImGui : : Checkbox ( " SomeOption " , & b ) ;
ImGui : : EndMenu ( ) ;
}
2015-07-22 01:00:28 +02:00
if ( ImGui : : BeginMenu ( " Disabled " , false ) ) // Disabled
{
IM_ASSERT ( 0 ) ;
}
if ( ImGui : : MenuItem ( " Checked " , NULL , true ) ) { }
2023-02-10 12:16:23 +01:00
ImGui : : Separator ( ) ;
2015-07-22 01:00:28 +02:00
if ( ImGui : : MenuItem ( " Quit " , " Alt+F4 " ) ) { }
}
2018-07-12 11:40:23 +02:00
//-----------------------------------------------------------------------------
2018-09-06 11:35:13 +02:00
// [SECTION] Example App: Debug Console / ShowExampleAppConsole()
2018-07-12 11:40:23 +02:00
//-----------------------------------------------------------------------------
2015-07-22 01:00:28 +02:00
2018-09-06 11:35:13 +02:00
// Demonstrate creating a simple console window, with scrolling, filtering, completion and history.
2020-05-05 19:39:24 +02:00
// For the console example, we are using a more C++ like approach of declaring a class to hold both data and functions.
2015-07-22 01:00:28 +02:00
struct ExampleAppConsole
{
char InputBuf [ 256 ] ;
ImVector < char * > Items ;
2019-02-14 14:00:30 +01:00
ImVector < const char * > Commands ;
2015-07-22 01:00:28 +02:00
ImVector < char * > History ;
int HistoryPos ; // -1: new line, 0..History.Size-1 browsing history.
2019-02-14 14:00:30 +01:00
ImGuiTextFilter Filter ;
bool AutoScroll ;
bool ScrollToBottom ;
2015-07-22 01:00:28 +02:00
ExampleAppConsole ( )
{
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Examples/Console " ) ;
2015-07-22 01:00:28 +02:00
ClearLog ( ) ;
2015-12-30 11:55:37 +01:00
memset ( InputBuf , 0 , sizeof ( InputBuf ) ) ;
2015-07-22 01:00:28 +02:00
HistoryPos = - 1 ;
2020-05-05 19:39:24 +02:00
// "CLASSIFY" is here to provide the test case where "C"+[tab] completes to "CL" and display multiple matches.
2015-07-22 01:00:28 +02:00
Commands . push_back ( " HELP " ) ;
Commands . push_back ( " HISTORY " ) ;
Commands . push_back ( " CLEAR " ) ;
2020-05-05 19:39:24 +02:00
Commands . push_back ( " CLASSIFY " ) ;
2019-02-14 14:00:30 +01:00
AutoScroll = true ;
2019-07-23 03:24:23 +02:00
ScrollToBottom = false ;
2018-05-10 14:02:28 +02:00
AddLog ( " Welcome to Dear ImGui! " ) ;
2015-07-22 01:00:28 +02:00
}
~ ExampleAppConsole ( )
{
ClearLog ( ) ;
2016-02-24 11:50:21 +01:00
for ( int i = 0 ; i < History . Size ; i + + )
2024-02-09 14:20:12 +01:00
ImGui : : MemFree ( History [ i ] ) ;
2015-07-22 01:00:28 +02:00
}
2016-02-08 08:44:45 +01:00
// Portable helpers
2020-05-05 19:39:24 +02:00
static int Stricmp ( const char * s1 , const char * s2 ) { int d ; while ( ( d = toupper ( * s2 ) - toupper ( * s1 ) ) = = 0 & & * s1 ) { s1 + + ; s2 + + ; } return d ; }
static int Strnicmp ( const char * s1 , const char * s2 , int n ) { int d = 0 ; while ( n > 0 & & ( d = toupper ( * s2 ) - toupper ( * s1 ) ) = = 0 & & * s1 ) { s1 + + ; s2 + + ; n - - ; } return d ; }
2024-02-09 14:20:12 +01:00
static char * Strdup ( const char * s ) { IM_ASSERT ( s ) ; size_t len = strlen ( s ) + 1 ; void * buf = ImGui : : MemAlloc ( len ) ; IM_ASSERT ( buf ) ; return ( char * ) memcpy ( buf , ( const void * ) s , len ) ; }
2020-05-05 19:39:24 +02:00
static void Strtrim ( char * s ) { char * str_end = s + strlen ( s ) ; while ( str_end > s & & str_end [ - 1 ] = = ' ' ) str_end - - ; * str_end = 0 ; }
2016-02-08 08:44:45 +01:00
2015-07-22 01:00:28 +02:00
void ClearLog ( )
{
2015-08-24 13:50:18 +02:00
for ( int i = 0 ; i < Items . Size ; i + + )
2024-02-09 14:20:12 +01:00
ImGui : : MemFree ( Items [ i ] ) ;
2015-07-22 01:00:28 +02:00
Items . clear ( ) ;
}
2017-08-25 10:10:14 +02:00
void AddLog ( const char * fmt , . . . ) IM_FMTARGS ( 2 )
2015-07-22 01:00:28 +02:00
{
2017-10-24 20:48:29 +02:00
// FIXME-OPT
2015-07-22 01:00:28 +02:00
char buf [ 1024 ] ;
va_list args ;
va_start ( args , fmt ) ;
vsnprintf ( buf , IM_ARRAYSIZE ( buf ) , fmt , args ) ;
buf [ IM_ARRAYSIZE ( buf ) - 1 ] = 0 ;
va_end ( args ) ;
2016-02-08 08:44:45 +01:00
Items . push_back ( Strdup ( buf ) ) ;
2015-07-22 01:00:28 +02:00
}
2016-05-02 12:32:16 +02:00
void Draw ( const char * title , bool * p_open )
2015-07-22 01:00:28 +02:00
{
2020-06-30 15:31:54 +02:00
ImGui : : SetNextWindowSize ( ImVec2 ( 520 , 600 ) , ImGuiCond_FirstUseEver ) ;
2016-05-02 12:32:16 +02:00
if ( ! ImGui : : Begin ( title , p_open ) )
2015-07-22 01:00:28 +02:00
{
ImGui : : End ( ) ;
return ;
}
2020-05-05 19:39:24 +02:00
// As a specific feature guaranteed by the library, after calling Begin() the last Item represent the title bar.
// So e.g. IsItemHovered() will return true when hovering the title bar.
2017-11-15 14:35:45 +01:00
// Here we create a context menu only available from the title bar.
if ( ImGui : : BeginPopupContextItem ( ) )
{
2018-07-09 11:32:20 +02:00
if ( ImGui : : MenuItem ( " Close Console " ) )
2017-11-15 14:35:45 +01:00
* p_open = false ;
ImGui : : EndPopup ( ) ;
}
2020-05-05 19:39:24 +02:00
ImGui : : TextWrapped (
2020-09-03 19:09:57 +02:00
" This example implements a console with basic coloring, completion (TAB key) and history (Up/Down keys). A more elaborate "
2020-05-05 19:39:24 +02:00
" implementation may want to store entries along with extra data such as timestamp, emitter, etc. " ) ;
2020-09-03 19:09:57 +02:00
ImGui : : TextWrapped ( " Enter 'HELP' for help. " ) ;
2015-07-22 01:00:28 +02:00
// TODO: display items starting from the bottom
2020-08-28 16:49:46 +02:00
if ( ImGui : : SmallButton ( " Add Debug Text " ) ) { AddLog ( " %d some text " , Items . Size ) ; AddLog ( " some more text " ) ; AddLog ( " display very important message here! " ) ; }
ImGui : : SameLine ( ) ;
if ( ImGui : : SmallButton ( " Add Debug Error " ) ) { AddLog ( " [error] something went wrong " ) ; }
ImGui : : SameLine ( ) ;
if ( ImGui : : SmallButton ( " Clear " ) ) { ClearLog ( ) ; }
ImGui : : SameLine ( ) ;
2019-07-23 03:24:23 +02:00
bool copy_to_clipboard = ImGui : : SmallButton ( " Copy " ) ;
2015-07-22 01:00:28 +02:00
//static float t = 0.0f; if (ImGui::GetTime() - t > 0.02f) { t = ImGui::GetTime(); AddLog("Spam %f", t); }
ImGui : : Separator ( ) ;
2019-02-14 14:00:30 +01:00
// Options menu
if ( ImGui : : BeginPopup ( " Options " ) )
{
2019-07-23 03:24:23 +02:00
ImGui : : Checkbox ( " Auto-scroll " , & AutoScroll ) ;
2019-02-14 14:00:30 +01:00
ImGui : : EndPopup ( ) ;
}
// Options, Filter
2024-05-23 16:39:39 +02:00
ImGui : : SetNextItemShortcut ( ImGuiMod_Ctrl | ImGuiKey_O , ImGuiInputFlags_Tooltip ) ;
2019-02-14 14:00:30 +01:00
if ( ImGui : : Button ( " Options " ) )
ImGui : : OpenPopup ( " Options " ) ;
ImGui : : SameLine ( ) ;
Filter . Draw ( " Filter ( \" incl,-excl \" ) ( \" error \" ) " , 180 ) ;
2015-07-22 01:00:28 +02:00
ImGui : : Separator ( ) ;
2020-05-05 19:39:24 +02:00
// Reserve enough left-over height for 1 separator + 1 input text
const float footer_height_to_reserve = ImGui : : GetStyle ( ) . ItemSpacing . y + ImGui : : GetFrameHeightWithSpacing ( ) ;
2024-06-13 00:28:24 +02:00
if ( ImGui : : BeginChild ( " ScrollingRegion " , ImVec2 ( 0 , - footer_height_to_reserve ) , ImGuiChildFlags_NavFlattened , ImGuiWindowFlags_HorizontalScrollbar ) )
2015-07-22 01:00:28 +02:00
{
2022-09-28 12:22:34 +02:00
if ( ImGui : : BeginPopupContextWindow ( ) )
{
if ( ImGui : : Selectable ( " Clear " ) ) ClearLog ( ) ;
ImGui : : EndPopup ( ) ;
}
2016-05-16 19:22:51 +02:00
2022-09-28 12:22:34 +02:00
// Display every line as a separate entry so we can change their color or add custom widgets.
// If you only want raw text you can use ImGui::TextUnformatted(log.begin(), log.end());
// NB- if you have thousands of entries this approach may be too inefficient and may require user-side clipping
// to only process visible items. The clipper will automatically measure the height of your first item and then
// "seek" to display only items in the visible area.
// To use the clipper we can replace your standard loop:
// for (int i = 0; i < Items.Size; i++)
// With:
// ImGuiListClipper clipper;
// clipper.Begin(Items.Size);
// while (clipper.Step())
// for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
// - That your items are evenly spaced (same height)
// - That you have cheap random access to your elements (you can access them given their index,
// without processing all the ones before)
// You cannot this code as-is if a filter is active because it breaks the 'cheap random-access' property.
// We would need random-access on the post-filtered list.
// A typical application wanting coarse clipping and filtering may want to pre-compute an array of indices
// or offsets of items that passed the filtering test, recomputing this array when user changes the filter,
// and appending newly elements as they are inserted. This is left as a task to the user until we can manage
// to improve this example code!
// If your items are of variable height:
// - Split them into same height items would be simpler and facilitate random-seeking into your list.
// - Consider using manual call to IsRectVisible() and skipping extraneous decoration from your items.
ImGui : : PushStyleVar ( ImGuiStyleVar_ItemSpacing , ImVec2 ( 4 , 1 ) ) ; // Tighten spacing
if ( copy_to_clipboard )
ImGui : : LogToClipboard ( ) ;
2023-08-28 12:21:16 +02:00
for ( const char * item : Items )
2022-09-28 12:22:34 +02:00
{
if ( ! Filter . PassFilter ( item ) )
continue ;
2019-02-14 14:00:30 +01:00
2022-09-28 12:22:34 +02:00
// Normally you would store more information in your item than just a string.
// (e.g. make Items[] an array of structure, store color/type etc.)
ImVec4 color ;
bool has_color = false ;
if ( strstr ( item , " [error] " ) ) { color = ImVec4 ( 1.0f , 0.4f , 0.4f , 1.0f ) ; has_color = true ; }
else if ( strncmp ( item , " # " , 2 ) = = 0 ) { color = ImVec4 ( 1.0f , 0.8f , 0.6f , 1.0f ) ; has_color = true ; }
if ( has_color )
ImGui : : PushStyleColor ( ImGuiCol_Text , color ) ;
ImGui : : TextUnformatted ( item ) ;
if ( has_color )
ImGui : : PopStyleColor ( ) ;
}
if ( copy_to_clipboard )
ImGui : : LogFinish ( ) ;
2019-07-23 03:24:23 +02:00
2022-11-09 17:03:07 +01:00
// Keep up at the bottom of the scroll region if we were already at the bottom at the beginning of the frame.
// Using a scrollbar or mouse-wheel will take away from the bottom edge.
2022-09-28 12:22:34 +02:00
if ( ScrollToBottom | | ( AutoScroll & & ImGui : : GetScrollY ( ) > = ImGui : : GetScrollMaxY ( ) ) )
ImGui : : SetScrollHereY ( 1.0f ) ;
ScrollToBottom = false ;
2019-07-23 03:24:23 +02:00
2022-09-28 12:22:34 +02:00
ImGui : : PopStyleVar ( ) ;
}
2015-07-22 01:00:28 +02:00
ImGui : : EndChild ( ) ;
ImGui : : Separator ( ) ;
// Command-line
2016-07-30 19:17:26 +02:00
bool reclaim_focus = false ;
2022-09-20 15:57:58 +02:00
ImGuiInputTextFlags input_text_flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_EscapeClearsAll | ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory ;
2020-05-05 19:39:24 +02:00
if ( ImGui : : InputText ( " Input " , InputBuf , IM_ARRAYSIZE ( InputBuf ) , input_text_flags , & TextEditCallbackStub , ( void * ) this ) )
2015-07-22 01:00:28 +02:00
{
2018-08-22 12:33:54 +02:00
char * s = InputBuf ;
Strtrim ( s ) ;
if ( s [ 0 ] )
ExecCommand ( s ) ;
strcpy ( s , " " ) ;
2016-07-30 19:17:26 +02:00
reclaim_focus = true ;
2015-07-22 01:00:28 +02:00
}
2018-08-22 12:33:54 +02:00
// Auto-focus on window apparition
2016-07-30 19:17:26 +02:00
ImGui : : SetItemDefaultFocus ( ) ;
2018-02-05 14:53:07 +01:00
if ( reclaim_focus )
2015-12-27 21:41:01 +01:00
ImGui : : SetKeyboardFocusHere ( - 1 ) ; // Auto focus previous widget
2015-07-22 01:00:28 +02:00
ImGui : : End ( ) ;
}
void ExecCommand ( const char * command_line )
{
AddLog ( " # %s \n " , command_line ) ;
2020-05-05 19:39:24 +02:00
// Insert into history. First find match and delete it so it can be pushed to the back.
// This isn't trying to be smart or optimal.
2015-07-22 01:00:28 +02:00
HistoryPos = - 1 ;
2020-06-30 15:31:54 +02:00
for ( int i = History . Size - 1 ; i > = 0 ; i - - )
2015-08-05 17:28:19 +02:00
if ( Stricmp ( History [ i ] , command_line ) = = 0 )
2015-07-22 01:00:28 +02:00
{
2024-02-09 14:20:12 +01:00
ImGui : : MemFree ( History [ i ] ) ;
2015-07-22 01:00:28 +02:00
History . erase ( History . begin ( ) + i ) ;
break ;
}
2016-02-08 08:44:45 +01:00
History . push_back ( Strdup ( command_line ) ) ;
2015-07-22 01:00:28 +02:00
// Process command
2015-08-05 17:28:19 +02:00
if ( Stricmp ( command_line , " CLEAR " ) = = 0 )
2015-07-22 01:00:28 +02:00
{
ClearLog ( ) ;
}
2015-08-05 17:28:19 +02:00
else if ( Stricmp ( command_line , " HELP " ) = = 0 )
2015-07-22 01:00:28 +02:00
{
AddLog ( " Commands: " ) ;
for ( int i = 0 ; i < Commands . Size ; i + + )
AddLog ( " - %s " , Commands [ i ] ) ;
}
2015-08-05 17:28:19 +02:00
else if ( Stricmp ( command_line , " HISTORY " ) = = 0 )
2015-07-22 01:00:28 +02:00
{
2017-08-29 13:05:56 +02:00
int first = History . Size - 10 ;
for ( int i = first > 0 ? first : 0 ; i < History . Size ; i + + )
2015-07-22 01:00:28 +02:00
AddLog ( " %3d: %s \n " , i , History [ i ] ) ;
}
else
{
AddLog ( " Unknown command: '%s' \n " , command_line ) ;
}
2019-02-14 14:00:30 +01:00
2020-04-24 22:50:27 +02:00
// On command input, we scroll to bottom even if AutoScroll==false
2019-02-14 14:00:30 +01:00
ScrollToBottom = true ;
2015-07-22 01:00:28 +02:00
}
2020-05-05 19:39:24 +02:00
// In C++11 you'd be better off using lambdas for this sort of forwarding callbacks
static int TextEditCallbackStub ( ImGuiInputTextCallbackData * data )
2015-07-22 01:00:28 +02:00
{
ExampleAppConsole * console = ( ExampleAppConsole * ) data - > UserData ;
return console - > TextEditCallback ( data ) ;
}
2018-08-21 15:46:22 +02:00
int TextEditCallback ( ImGuiInputTextCallbackData * data )
2015-07-22 01:00:28 +02:00
{
//AddLog("cursor: %d, selection: %d-%d", data->CursorPos, data->SelectionStart, data->SelectionEnd);
switch ( data - > EventFlag )
{
case ImGuiInputTextFlags_CallbackCompletion :
{
// Example of TEXT COMPLETION
// Locate beginning of current word
const char * word_end = data - > Buf + data - > CursorPos ;
const char * word_start = word_end ;
while ( word_start > data - > Buf )
{
const char c = word_start [ - 1 ] ;
2015-07-22 01:13:56 +02:00
if ( c = = ' ' | | c = = ' \t ' | | c = = ' , ' | | c = = ' ; ' )
2015-07-22 01:00:28 +02:00
break ;
word_start - - ;
}
// Build a list of candidates
ImVector < const char * > candidates ;
for ( int i = 0 ; i < Commands . Size ; i + + )
2020-06-30 15:31:54 +02:00
if ( Strnicmp ( Commands [ i ] , word_start , ( int ) ( word_end - word_start ) ) = = 0 )
2015-07-22 01:00:28 +02:00
candidates . push_back ( Commands [ i ] ) ;
if ( candidates . Size = = 0 )
{
// No match
2020-06-30 15:31:54 +02:00
AddLog ( " No match for \" %.*s \" ! \n " , ( int ) ( word_end - word_start ) , word_start ) ;
2015-07-22 01:00:28 +02:00
}
else if ( candidates . Size = = 1 )
{
2020-05-05 19:39:24 +02:00
// Single match. Delete the beginning of the word and replace it entirely so we've got nice casing.
2020-06-30 15:31:54 +02:00
data - > DeleteChars ( ( int ) ( word_start - data - > Buf ) , ( int ) ( word_end - word_start ) ) ;
2015-07-22 01:00:28 +02:00
data - > InsertChars ( data - > CursorPos , candidates [ 0 ] ) ;
data - > InsertChars ( data - > CursorPos , " " ) ;
}
else
{
2020-05-05 19:39:24 +02:00
// Multiple matches. Complete as much as we can..
// So inputing "C"+Tab will complete to "CL" then display "CLEAR" and "CLASSIFY" as matches.
2015-07-22 01:00:28 +02:00
int match_len = ( int ) ( word_end - word_start ) ;
for ( ; ; )
{
int c = 0 ;
bool all_candidates_matches = true ;
for ( int i = 0 ; i < candidates . Size & & all_candidates_matches ; i + + )
if ( i = = 0 )
c = toupper ( candidates [ i ] [ match_len ] ) ;
2017-01-07 20:18:45 +01:00
else if ( c = = 0 | | c ! = toupper ( candidates [ i ] [ match_len ] ) )
2015-07-22 01:00:28 +02:00
all_candidates_matches = false ;
if ( ! all_candidates_matches )
break ;
match_len + + ;
}
if ( match_len > 0 )
{
2020-06-30 15:31:54 +02:00
data - > DeleteChars ( ( int ) ( word_start - data - > Buf ) , ( int ) ( word_end - word_start ) ) ;
2015-07-22 01:00:28 +02:00
data - > InsertChars ( data - > CursorPos , candidates [ 0 ] , candidates [ 0 ] + match_len ) ;
}
// List matches
AddLog ( " Possible matches: \n " ) ;
for ( int i = 0 ; i < candidates . Size ; i + + )
AddLog ( " - %s \n " , candidates [ i ] ) ;
}
break ;
}
case ImGuiInputTextFlags_CallbackHistory :
{
// Example of HISTORY
const int prev_history_pos = HistoryPos ;
if ( data - > EventKey = = ImGuiKey_UpArrow )
{
if ( HistoryPos = = - 1 )
HistoryPos = History . Size - 1 ;
else if ( HistoryPos > 0 )
HistoryPos - - ;
}
else if ( data - > EventKey = = ImGuiKey_DownArrow )
{
if ( HistoryPos ! = - 1 )
if ( + + HistoryPos > = History . Size )
HistoryPos = - 1 ;
}
// A better implementation would preserve the data on the current input line along with cursor position.
if ( prev_history_pos ! = HistoryPos )
{
2018-08-22 12:33:54 +02:00
const char * history_str = ( HistoryPos > = 0 ) ? History [ HistoryPos ] : " " ;
data - > DeleteChars ( 0 , data - > BufTextLen ) ;
data - > InsertChars ( 0 , history_str ) ;
2015-07-22 01:00:28 +02:00
}
}
}
return 0 ;
}
} ;
2016-05-02 12:32:16 +02:00
static void ShowExampleAppConsole ( bool * p_open )
2015-07-22 01:00:28 +02:00
{
static ExampleAppConsole console ;
2016-05-02 12:32:16 +02:00
console . Draw ( " Example: Console " , p_open ) ;
2015-08-14 04:59:37 +02:00
}
2018-07-12 11:40:23 +02:00
//-----------------------------------------------------------------------------
2018-09-06 11:35:13 +02:00
// [SECTION] Example App: Debug Log / ShowExampleAppLog()
2018-07-12 11:40:23 +02:00
//-----------------------------------------------------------------------------
2015-08-14 04:59:37 +02:00
// Usage:
// static ExampleAppLog my_log;
// my_log.AddLog("Hello %d world\n", 123);
// my_log.Draw("title");
struct ExampleAppLog
{
ImGuiTextBuffer Buf ;
2015-08-14 05:47:50 +02:00
ImGuiTextFilter Filter ;
2020-05-05 19:39:24 +02:00
ImVector < int > LineOffsets ; // Index to lines offset. We maintain this with AddLog() calls.
bool AutoScroll ; // Keep scrolling if already at the bottom.
2015-08-14 04:59:37 +02:00
2019-01-29 14:36:55 +01:00
ExampleAppLog ( )
{
2019-02-14 14:00:30 +01:00
AutoScroll = true ;
2019-01-29 14:36:55 +01:00
Clear ( ) ;
}
2019-01-20 17:56:17 +01:00
void Clear ( )
{
Buf . clear ( ) ;
LineOffsets . clear ( ) ;
2019-01-07 17:33:02 +01:00
LineOffsets . push_back ( 0 ) ;
}
2015-08-14 04:59:37 +02:00
2017-08-25 10:10:14 +02:00
void AddLog ( const char * fmt , . . . ) IM_FMTARGS ( 2 )
2015-08-14 04:59:37 +02:00
{
2015-08-14 05:47:50 +02:00
int old_size = Buf . size ( ) ;
2015-08-14 04:59:37 +02:00
va_list args ;
va_start ( args , fmt ) ;
2017-11-27 16:55:06 +01:00
Buf . appendfv ( fmt , args ) ;
2015-08-14 04:59:37 +02:00
va_end ( args ) ;
2015-08-14 05:47:50 +02:00
for ( int new_size = Buf . size ( ) ; old_size < new_size ; old_size + + )
if ( Buf [ old_size ] = = ' \n ' )
2019-01-07 17:33:02 +01:00
LineOffsets . push_back ( old_size + 1 ) ;
2015-08-14 04:59:37 +02:00
}
2016-05-02 12:32:16 +02:00
void Draw ( const char * title , bool * p_open = NULL )
2015-08-14 04:59:37 +02:00
{
2018-07-09 11:32:20 +02:00
if ( ! ImGui : : Begin ( title , p_open ) )
{
ImGui : : End ( ) ;
return ;
}
2019-02-14 14:00:30 +01:00
// Options menu
if ( ImGui : : BeginPopup ( " Options " ) )
{
2019-07-23 03:24:23 +02:00
ImGui : : Checkbox ( " Auto-scroll " , & AutoScroll ) ;
2019-02-14 14:00:30 +01:00
ImGui : : EndPopup ( ) ;
}
// Main window
if ( ImGui : : Button ( " Options " ) )
ImGui : : OpenPopup ( " Options " ) ;
ImGui : : SameLine ( ) ;
bool clear = ImGui : : Button ( " Clear " ) ;
2015-08-14 04:59:37 +02:00
ImGui : : SameLine ( ) ;
bool copy = ImGui : : Button ( " Copy " ) ;
2015-08-14 05:47:50 +02:00
ImGui : : SameLine ( ) ;
2015-08-14 05:51:34 +02:00
Filter . Draw ( " Filter " , - 100.0f ) ;
2019-02-14 14:00:30 +01:00
2015-08-14 04:59:37 +02:00
ImGui : : Separator ( ) ;
2019-02-14 14:00:30 +01:00
2023-10-18 18:50:19 +02:00
if ( ImGui : : BeginChild ( " scrolling " , ImVec2 ( 0 , 0 ) , ImGuiChildFlags_None , ImGuiWindowFlags_HorizontalScrollbar ) )
2015-08-14 05:47:50 +02:00
{
2022-09-28 12:22:34 +02:00
if ( clear )
Clear ( ) ;
if ( copy )
ImGui : : LogToClipboard ( ) ;
ImGui : : PushStyleVar ( ImGuiStyleVar_ItemSpacing , ImVec2 ( 0 , 0 ) ) ;
const char * buf = Buf . begin ( ) ;
const char * buf_end = Buf . end ( ) ;
if ( Filter . IsActive ( ) )
2019-01-07 17:33:02 +01:00
{
2022-09-28 12:22:34 +02:00
// In this example we don't use the clipper when Filter is enabled.
// This is because we don't have random access to the result of our filter.
// A real application processing logs with ten of thousands of entries may want to store the result of
// search/filter.. especially if the filtering function is not trivial (e.g. reg-exp).
for ( int line_no = 0 ; line_no < LineOffsets . Size ; line_no + + )
2019-01-07 17:33:02 +01:00
{
const char * line_start = buf + LineOffsets [ line_no ] ;
const char * line_end = ( line_no + 1 < LineOffsets . Size ) ? ( buf + LineOffsets [ line_no + 1 ] - 1 ) : buf_end ;
2022-09-28 12:22:34 +02:00
if ( Filter . PassFilter ( line_start , line_end ) )
ImGui : : TextUnformatted ( line_start , line_end ) ;
2019-01-07 17:33:02 +01:00
}
}
2022-09-28 12:22:34 +02:00
else
{
// The simplest and easy way to display the entire buffer:
// ImGui::TextUnformatted(buf_begin, buf_end);
// And it'll just work. TextUnformatted() has specialization for large blob of text and will fast-forward
// to skip non-visible lines. Here we instead demonstrate using the clipper to only process lines that are
// within the visible area.
// If you have tens of thousands of items and their processing cost is non-negligible, coarse clipping them
// on your side is recommended. Using ImGuiListClipper requires
// - A) random access into your data
// - B) items all being the same height,
// both of which we can handle since we have an array pointing to the beginning of each line of text.
// When using the filter (in the block of code above) we don't have random access into the data to display
// anymore, which is why we don't use the clipper. Storing or skimming through the search result would make
// it possible (and would be recommended if you want to search through tens of thousands of entries).
ImGuiListClipper clipper ;
clipper . Begin ( LineOffsets . Size ) ;
while ( clipper . Step ( ) )
{
for ( int line_no = clipper . DisplayStart ; line_no < clipper . DisplayEnd ; line_no + + )
{
const char * line_start = buf + LineOffsets [ line_no ] ;
const char * line_end = ( line_no + 1 < LineOffsets . Size ) ? ( buf + LineOffsets [ line_no + 1 ] - 1 ) : buf_end ;
ImGui : : TextUnformatted ( line_start , line_end ) ;
}
}
clipper . End ( ) ;
}
ImGui : : PopStyleVar ( ) ;
2019-07-23 03:24:23 +02:00
2022-11-09 17:03:07 +01:00
// Keep up at the bottom of the scroll region if we were already at the bottom at the beginning of the frame.
// Using a scrollbar or mouse-wheel will take away from the bottom edge.
2022-09-28 12:22:34 +02:00
if ( AutoScroll & & ImGui : : GetScrollY ( ) > = ImGui : : GetScrollMaxY ( ) )
ImGui : : SetScrollHereY ( 1.0f ) ;
}
2015-08-14 04:59:37 +02:00
ImGui : : EndChild ( ) ;
ImGui : : End ( ) ;
}
} ;
2016-11-07 17:33:46 +01:00
// Demonstrate creating a simple log window with basic filtering.
2016-05-02 12:32:16 +02:00
static void ShowExampleAppLog ( bool * p_open )
2015-08-14 04:59:37 +02:00
{
static ExampleAppLog log ;
2019-02-14 14:00:30 +01:00
// For the demo: add a debug button _BEFORE_ the normal log window contents
2019-04-11 15:12:18 +02:00
// We take advantage of a rarely used feature: multiple calls to Begin()/End() are appending to the _same_ window.
2019-02-14 14:00:30 +01:00
// Most of the contents of the window will be added by the log.Draw() call.
2019-01-07 17:33:02 +01:00
ImGui : : SetNextWindowSize ( ImVec2 ( 500 , 400 ) , ImGuiCond_FirstUseEver ) ;
ImGui : : Begin ( " Example: Log " , p_open ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Examples/Log " ) ;
2019-02-14 14:00:30 +01:00
if ( ImGui : : SmallButton ( " [Debug] Add 5 entries " ) )
2015-08-14 04:59:37 +02:00
{
2019-01-07 17:33:02 +01:00
static int counter = 0 ;
2020-05-05 19:39:24 +02:00
const char * categories [ 3 ] = { " info " , " warn " , " error " } ;
const char * words [ ] = { " Bumfuzzled " , " Cattywampus " , " Snickersnee " , " Abibliophobia " , " Absquatulate " , " Nincompoop " , " Pauciloquent " } ;
2019-01-07 17:33:02 +01:00
for ( int n = 0 ; n < 5 ; n + + )
{
2020-05-05 19:39:24 +02:00
const char * category = categories [ counter % IM_ARRAYSIZE ( categories ) ] ;
const char * word = words [ counter % IM_ARRAYSIZE ( words ) ] ;
2019-01-20 17:56:17 +01:00
log . AddLog ( " [%05d] [%s] Hello, current time is %.1f, here's a word: '%s' \n " ,
2020-05-05 19:39:24 +02:00
ImGui : : GetFrameCount ( ) , category , ImGui : : GetTime ( ) , word ) ;
2019-01-07 17:33:02 +01:00
counter + + ;
}
2015-08-14 04:59:37 +02:00
}
2019-01-07 17:33:02 +01:00
ImGui : : End ( ) ;
2015-08-14 04:59:37 +02:00
2019-04-11 15:12:18 +02:00
// Actually call in the regular Log helper (which will Begin() into the same window as we just did)
2016-05-02 12:32:16 +02:00
log . Draw ( " Example: Log " , p_open ) ;
2015-07-22 01:00:28 +02:00
}
2018-07-12 11:40:23 +02:00
//-----------------------------------------------------------------------------
2018-09-06 11:35:13 +02:00
// [SECTION] Example App: Simple Layout / ShowExampleAppLayout()
2018-07-12 11:40:23 +02:00
//-----------------------------------------------------------------------------
2016-11-07 17:33:46 +01:00
// Demonstrate create a window with multiple child windows.
2016-05-02 12:32:16 +02:00
static void ShowExampleAppLayout ( bool * p_open )
2015-07-22 01:00:28 +02:00
{
2017-08-11 07:36:28 +02:00
ImGui : : SetNextWindowSize ( ImVec2 ( 500 , 440 ) , ImGuiCond_FirstUseEver ) ;
2018-12-13 13:22:10 +01:00
if ( ImGui : : Begin ( " Example: Simple layout " , p_open , ImGuiWindowFlags_MenuBar ) )
2015-07-22 01:00:28 +02:00
{
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Examples/Simple layout " ) ;
2015-07-22 01:00:28 +02:00
if ( ImGui : : BeginMenuBar ( ) )
{
if ( ImGui : : BeginMenu ( " File " ) )
{
2022-12-08 18:15:00 +01:00
if ( ImGui : : MenuItem ( " Close " , " Ctrl+W " ) ) { * p_open = false ; }
2015-07-22 01:00:28 +02:00
ImGui : : EndMenu ( ) ;
}
ImGui : : EndMenuBar ( ) ;
}
2020-05-05 19:39:24 +02:00
// Left
2015-07-22 01:00:28 +02:00
static int selected = 0 ;
{
2024-08-23 15:24:22 +02:00
ImGui : : BeginChild ( " left pane " , ImVec2 ( 150 , 0 ) , ImGuiChildFlags_Borders | ImGuiChildFlags_ResizeX ) ;
2020-05-05 19:39:24 +02:00
for ( int i = 0 ; i < 100 ; i + + )
{
2021-06-21 17:37:37 +02:00
// FIXME: Good candidate to use ImGuiSelectableFlags_SelectOnNav
2020-05-05 19:39:24 +02:00
char label [ 128 ] ;
sprintf ( label , " MyObject %d " , i ) ;
if ( ImGui : : Selectable ( label , selected = = i ) )
selected = i ;
}
ImGui : : EndChild ( ) ;
2015-07-22 01:00:28 +02:00
}
ImGui : : SameLine ( ) ;
2015-08-24 13:50:18 +02:00
2020-05-05 19:39:24 +02:00
// Right
{
ImGui : : BeginGroup ( ) ;
2017-12-12 14:14:58 +01:00
ImGui : : BeginChild ( " item view " , ImVec2 ( 0 , - ImGui : : GetFrameHeightWithSpacing ( ) ) ) ; // Leave room for 1 line below us
2020-05-05 19:39:24 +02:00
ImGui : : Text ( " MyObject: %d " , selected ) ;
ImGui : : Separator ( ) ;
if ( ImGui : : BeginTabBar ( " ##Tabs " , ImGuiTabBarFlags_None ) )
{
if ( ImGui : : BeginTabItem ( " Description " ) )
2018-12-11 16:59:17 +01:00
{
2020-05-05 19:39:24 +02:00
ImGui : : TextWrapped ( " Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " ) ;
ImGui : : EndTabItem ( ) ;
2018-12-11 16:59:17 +01:00
}
2020-05-05 19:39:24 +02:00
if ( ImGui : : BeginTabItem ( " Details " ) )
{
ImGui : : Text ( " ID: 0123456789 " ) ;
ImGui : : EndTabItem ( ) ;
}
ImGui : : EndTabBar ( ) ;
}
2015-07-22 01:00:28 +02:00
ImGui : : EndChild ( ) ;
2017-11-29 23:47:59 +01:00
if ( ImGui : : Button ( " Revert " ) ) { }
ImGui : : SameLine ( ) ;
if ( ImGui : : Button ( " Save " ) ) { }
2020-05-05 19:39:24 +02:00
ImGui : : EndGroup ( ) ;
}
2015-07-22 01:00:28 +02:00
}
ImGui : : End ( ) ;
}
2024-07-17 13:41:59 +02:00
//-----------------------------------------------------------------------------
// [SECTION] Example App: Property Editor / ShowExampleAppPropertyEditor()
//-----------------------------------------------------------------------------
2024-07-17 14:01:02 +02:00
// Some of the interactions are a bit lack-luster:
// - We would want pressing validating or leaving the filter to somehow restore focus.
2024-07-17 15:56:45 +02:00
// - We may want more advanced filtering (child nodes) and clipper support: both will need extra work.
2024-07-22 14:06:14 +02:00
// - We would want to customize some keyboard interactions to easily keyboard navigate between the tree and the properties.
2024-07-17 14:01:02 +02:00
//-----------------------------------------------------------------------------
2024-07-17 13:41:59 +02:00
struct ExampleAppPropertyEditor
2024-07-15 17:12:11 +02:00
{
2024-07-17 14:01:02 +02:00
ImGuiTextFilter Filter ;
2024-07-22 14:06:14 +02:00
ExampleTreeNode * VisibleNode = NULL ;
2024-07-17 14:01:02 +02:00
2024-07-17 13:41:59 +02:00
void Draw ( ExampleTreeNode * root_node )
2020-05-05 19:39:24 +02:00
{
2024-07-22 14:06:14 +02:00
// Left side: draw tree
// - Currently using a table to benefit from RowBg feature
2024-08-23 15:24:22 +02:00
if ( ImGui : : BeginChild ( " ##tree " , ImVec2 ( 300 , 0 ) , ImGuiChildFlags_ResizeX | ImGuiChildFlags_Borders | ImGuiChildFlags_NavFlattened ) )
2024-07-22 14:06:14 +02:00
{
ImGui : : SetNextItemWidth ( - FLT_MIN ) ;
ImGui : : SetNextItemShortcut ( ImGuiMod_Ctrl | ImGuiKey_F , ImGuiInputFlags_Tooltip ) ;
ImGui : : PushItemFlag ( ImGuiItemFlags_NoNavDefaultFocus , true ) ;
if ( ImGui : : InputTextWithHint ( " ##Filter " , " incl,-excl " , Filter . InputBuf , IM_ARRAYSIZE ( Filter . InputBuf ) , ImGuiInputTextFlags_EscapeClearsAll ) )
Filter . Build ( ) ;
ImGui : : PopItemFlag ( ) ;
if ( ImGui : : BeginTable ( " ##bg " , 1 , ImGuiTableFlags_RowBg ) )
{
for ( ExampleTreeNode * node : root_node - > Childs )
if ( Filter . PassFilter ( node - > Name ) ) // Filter root node
DrawTreeNode ( node ) ;
ImGui : : EndTable ( ) ;
}
}
ImGui : : EndChild ( ) ;
2024-07-17 14:01:02 +02:00
2024-07-22 14:06:14 +02:00
// Right side: draw properties
ImGui : : SameLine ( ) ;
ImGui : : BeginGroup ( ) ; // Lock X position
if ( ExampleTreeNode * node = VisibleNode )
2020-05-05 19:39:24 +02:00
{
2024-07-22 14:06:14 +02:00
ImGui : : Text ( " %s " , node - > Name ) ;
ImGui : : TextDisabled ( " UID: 0x%08X " , node - > UID ) ;
ImGui : : Separator ( ) ;
if ( ImGui : : BeginTable ( " ##properties " , 2 , ImGuiTableFlags_Resizable | ImGuiTableFlags_ScrollY ) )
{
ImGui : : TableSetupColumn ( " " , ImGuiTableColumnFlags_WidthFixed ) ;
ImGui : : TableSetupColumn ( " " , ImGuiTableColumnFlags_WidthStretch , 2.0f ) ; // Default twice larger
2024-07-22 15:05:15 +02:00
if ( node - > HasData )
2024-07-22 14:06:14 +02:00
{
// In a typical application, the structure description would be derived from a data-driven system.
// - We try to mimic this with our ExampleMemberInfo structure and the ExampleTreeNodeMemberInfos[] array.
// - Limits and some details are hard-coded to simplify the demo.
for ( const ExampleMemberInfo & field_desc : ExampleTreeNodeMemberInfos )
{
ImGui : : TableNextRow ( ) ;
ImGui : : PushID ( field_desc . Name ) ;
ImGui : : TableNextColumn ( ) ;
2024-07-30 11:44:13 +02:00
ImGui : : AlignTextToFramePadding ( ) ;
2024-07-22 14:06:14 +02:00
ImGui : : TextUnformatted ( field_desc . Name ) ;
ImGui : : TableNextColumn ( ) ;
void * field_ptr = ( void * ) ( ( ( unsigned char * ) node ) + field_desc . Offset ) ;
switch ( field_desc . DataType )
{
case ImGuiDataType_Bool :
{
IM_ASSERT ( field_desc . DataCount = = 1 ) ;
ImGui : : Checkbox ( " ##Editor " , ( bool * ) field_ptr ) ;
break ;
}
case ImGuiDataType_S32 :
{
int v_min = INT_MIN , v_max = INT_MAX ;
ImGui : : SetNextItemWidth ( - FLT_MIN ) ;
ImGui : : DragScalarN ( " ##Editor " , field_desc . DataType , field_ptr , field_desc . DataCount , 1.0f , & v_min , & v_max ) ;
break ;
}
case ImGuiDataType_Float :
{
float v_min = 0.0f , v_max = 1.0f ;
ImGui : : SetNextItemWidth ( - FLT_MIN ) ;
ImGui : : SliderScalarN ( " ##Editor " , field_desc . DataType , field_ptr , field_desc . DataCount , & v_min , & v_max ) ;
break ;
}
}
ImGui : : PopID ( ) ;
}
}
ImGui : : EndTable ( ) ;
}
2020-05-05 19:39:24 +02:00
}
2024-07-22 14:06:14 +02:00
ImGui : : EndGroup ( ) ;
2020-05-05 19:39:24 +02:00
}
2024-07-17 13:41:59 +02:00
void DrawTreeNode ( ExampleTreeNode * node )
2024-07-15 17:12:11 +02:00
{
2024-07-17 13:41:59 +02:00
ImGui : : TableNextRow ( ) ;
2024-07-22 14:06:14 +02:00
ImGui : : TableNextColumn ( ) ;
ImGui : : PushID ( node - > UID ) ;
2024-07-17 13:41:59 +02:00
ImGuiTreeNodeFlags tree_flags = ImGuiTreeNodeFlags_None ;
tree_flags | = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick ; // Standard opening mode as we are likely to want to add selection afterwards
tree_flags | = ImGuiTreeNodeFlags_NavLeftJumpsBackHere ; // Left arrow support
2024-07-22 14:06:14 +02:00
if ( node = = VisibleNode )
tree_flags | = ImGuiTreeNodeFlags_Selected ;
if ( node - > Childs . Size = = 0 )
tree_flags | = ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_Bullet ;
if ( node - > DataMyBool = = false )
ImGui : : PushStyleColor ( ImGuiCol_Text , ImGui : : GetStyle ( ) . Colors [ ImGuiCol_TextDisabled ] ) ;
bool node_open = ImGui : : TreeNodeEx ( " " , tree_flags , " %s " , node - > Name ) ;
if ( node - > DataMyBool = = false )
ImGui : : PopStyleColor ( ) ;
if ( ImGui : : IsItemFocused ( ) )
VisibleNode = node ;
2024-07-17 13:41:59 +02:00
if ( node_open )
2024-07-22 15:05:15 +02:00
{
2024-07-17 13:41:59 +02:00
for ( ExampleTreeNode * child : node - > Childs )
DrawTreeNode ( child ) ;
ImGui : : TreePop ( ) ;
2024-07-22 15:05:15 +02:00
}
2024-07-17 13:41:59 +02:00
ImGui : : PopID ( ) ;
2024-07-15 17:12:11 +02:00
}
2024-07-17 13:41:59 +02:00
} ;
2024-07-15 17:12:11 +02:00
2024-07-17 13:41:59 +02:00
// Demonstrate creating a simple property editor.
2024-07-30 11:44:13 +02:00
static void ShowExampleAppPropertyEditor ( bool * p_open , ImGuiDemoWindowData * demo_data )
2015-11-28 18:16:59 +01:00
{
2020-06-30 15:31:54 +02:00
ImGui : : SetNextWindowSize ( ImVec2 ( 430 , 450 ) , ImGuiCond_FirstUseEver ) ;
2016-05-02 12:32:16 +02:00
if ( ! ImGui : : Begin ( " Example: Property editor " , p_open ) )
2015-11-28 18:16:59 +01:00
{
ImGui : : End ( ) ;
return ;
}
2023-08-31 19:49:39 +02:00
IMGUI_DEMO_MARKER ( " Examples/Property Editor " ) ;
2024-07-17 13:41:59 +02:00
static ExampleAppPropertyEditor property_editor ;
2024-07-30 11:44:13 +02:00
if ( demo_data - > DemoTree = = NULL )
demo_data - > DemoTree = ExampleTree_CreateDemoTree ( ) ;
property_editor . Draw ( demo_data - > DemoTree ) ;
2023-08-31 19:49:39 +02:00
2015-11-28 18:16:59 +01:00
ImGui : : End ( ) ;
}
2018-07-12 11:40:23 +02:00
//-----------------------------------------------------------------------------
2018-09-06 11:35:13 +02:00
// [SECTION] Example App: Long Text / ShowExampleAppLongText()
2018-07-12 11:40:23 +02:00
//-----------------------------------------------------------------------------
2016-11-07 17:33:46 +01:00
// Demonstrate/test rendering huge amount of text, and the incidence of clipping.
2016-05-02 12:32:16 +02:00
static void ShowExampleAppLongText ( bool * p_open )
2015-07-22 01:00:28 +02:00
{
2020-06-30 15:31:54 +02:00
ImGui : : SetNextWindowSize ( ImVec2 ( 520 , 600 ) , ImGuiCond_FirstUseEver ) ;
2016-05-02 12:32:16 +02:00
if ( ! ImGui : : Begin ( " Example: Long text display " , p_open ) )
2015-07-22 01:00:28 +02:00
{
ImGui : : End ( ) ;
return ;
}
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Examples/Long text display " ) ;
2015-07-22 01:00:28 +02:00
static int test_type = 0 ;
static ImGuiTextBuffer log ;
static int lines = 0 ;
ImGui : : Text ( " Printing unusually long amount of text. " ) ;
2020-05-05 19:39:24 +02:00
ImGui : : Combo ( " Test type " , & test_type ,
" Single call to TextUnformatted() \0 "
" Multiple calls to Text(), clipped \0 "
" Multiple calls to Text(), not clipped (slow) \0 " ) ;
2015-07-22 01:00:28 +02:00
ImGui : : Text ( " Buffer contents: %d lines, %d bytes " , lines , log . size ( ) ) ;
if ( ImGui : : Button ( " Clear " ) ) { log . clear ( ) ; lines = 0 ; }
ImGui : : SameLine ( ) ;
if ( ImGui : : Button ( " Add 1000 lines " ) )
{
for ( int i = 0 ; i < 1000 ; i + + )
2020-06-30 15:31:54 +02:00
log . appendf ( " %i The quick brown fox jumps over the lazy dog \n " , lines + i ) ;
2015-07-22 01:00:28 +02:00
lines + = 1000 ;
}
ImGui : : BeginChild ( " Log " ) ;
switch ( test_type )
{
case 0 :
// Single call to TextUnformatted() with a big buffer
ImGui : : TextUnformatted ( log . begin ( ) , log . end ( ) ) ;
break ;
case 1 :
2015-08-30 01:03:08 +02:00
{
// Multiple calls to Text(), manually coarsely clipped - demonstrate how to use the ImGuiListClipper helper.
2020-06-02 18:13:54 +02:00
ImGui : : PushStyleVar ( ImGuiStyleVar_ItemSpacing , ImVec2 ( 0 , 0 ) ) ;
2020-09-24 18:08:01 +02:00
ImGuiListClipper clipper ;
clipper . Begin ( lines ) ;
2016-05-16 19:22:51 +02:00
while ( clipper . Step ( ) )
for ( int i = clipper . DisplayStart ; i < clipper . DisplayEnd ; i + + )
ImGui : : Text ( " %i The quick brown fox jumps over the lazy dog " , i ) ;
2015-08-30 01:03:08 +02:00
ImGui : : PopStyleVar ( ) ;
break ;
}
2015-07-22 01:00:28 +02:00
case 2 :
// Multiple calls to Text(), not clipped (slow)
2020-06-02 18:13:54 +02:00
ImGui : : PushStyleVar ( ImGuiStyleVar_ItemSpacing , ImVec2 ( 0 , 0 ) ) ;
2015-07-22 01:00:28 +02:00
for ( int i = 0 ; i < lines ; i + + )
2016-05-16 19:22:51 +02:00
ImGui : : Text ( " %i The quick brown fox jumps over the lazy dog " , i ) ;
2015-07-22 01:00:28 +02:00
ImGui : : PopStyleVar ( ) ;
break ;
}
ImGui : : EndChild ( ) ;
ImGui : : End ( ) ;
}
2018-07-12 11:40:23 +02:00
//-----------------------------------------------------------------------------
2018-09-06 11:35:13 +02:00
// [SECTION] Example App: Auto Resize / ShowExampleAppAutoResize()
2018-07-12 11:40:23 +02:00
//-----------------------------------------------------------------------------
// Demonstrate creating a window which gets auto-resized according to its content.
static void ShowExampleAppAutoResize ( bool * p_open )
{
if ( ! ImGui : : Begin ( " Example: Auto-resizing window " , p_open , ImGuiWindowFlags_AlwaysAutoResize ) )
{
ImGui : : End ( ) ;
return ;
}
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Examples/Auto-resizing window " ) ;
2018-07-12 11:40:23 +02:00
static int lines = 10 ;
2020-05-05 19:39:24 +02:00
ImGui : : TextUnformatted (
" Window will resize every-frame to the size of its content. \n "
" Note that you probably don't want to query the window size to \n "
" output your content because that would create a feedback loop. " ) ;
2018-07-12 11:40:23 +02:00
ImGui : : SliderInt ( " Number of lines " , & lines , 1 , 20 ) ;
for ( int i = 0 ; i < lines ; i + + )
ImGui : : Text ( " %*sThis is line %d " , i * 4 , " " , i ) ; // Pad with space to extend size horizontally
ImGui : : End ( ) ;
}
//-----------------------------------------------------------------------------
2018-09-06 11:35:13 +02:00
// [SECTION] Example App: Constrained Resize / ShowExampleAppConstrainedResize()
2018-07-12 11:40:23 +02:00
//-----------------------------------------------------------------------------
// Demonstrate creating a window with custom resize constraints.
2022-09-01 10:51:15 +02:00
// Note that size constraints currently don't work on a docked window (when in 'docking' branch)
2018-07-12 11:40:23 +02:00
static void ShowExampleAppConstrainedResize ( bool * p_open )
{
2020-05-05 19:39:24 +02:00
struct CustomConstraints
2018-07-12 11:40:23 +02:00
{
2020-05-05 19:39:24 +02:00
// Helper functions to demonstrate programmatic constraints
2022-09-01 10:51:15 +02:00
// FIXME: This doesn't take account of decoration size (e.g. title bar), library should make this easier.
2023-11-13 14:53:14 +01:00
// FIXME: None of the three demos works consistently when resizing from borders.
static void AspectRatio ( ImGuiSizeCallbackData * data )
{
float aspect_ratio = * ( float * ) data - > UserData ;
data - > DesiredSize . y = ( float ) ( int ) ( data - > DesiredSize . x / aspect_ratio ) ;
}
static void Square ( ImGuiSizeCallbackData * data )
{
data - > DesiredSize . x = data - > DesiredSize . y = IM_MAX ( data - > DesiredSize . x , data - > DesiredSize . y ) ;
}
static void Step ( ImGuiSizeCallbackData * data )
{
float step = * ( float * ) data - > UserData ;
data - > DesiredSize = ImVec2 ( ( int ) ( data - > DesiredSize . x / step + 0.5f ) * step , ( int ) ( data - > DesiredSize . y / step + 0.5f ) * step ) ;
}
2018-07-12 11:40:23 +02:00
} ;
2020-05-05 19:39:24 +02:00
const char * test_desc [ ] =
{
2022-09-01 10:51:15 +02:00
" Between 100x100 and 500x500 " ,
" At least 100x100 " ,
2023-11-13 14:13:17 +01:00
" Resize vertical + lock current width " ,
" Resize horizontal + lock current height " ,
2022-09-01 10:51:15 +02:00
" Width Between 400 and 500 " ,
2023-11-13 14:13:17 +01:00
" Height at least 400 " ,
2022-09-01 10:51:15 +02:00
" Custom: Aspect Ratio 16:9 " ,
2020-05-05 19:39:24 +02:00
" Custom: Always Square " ,
" Custom: Fixed Steps (100) " ,
} ;
2022-09-01 10:51:15 +02:00
// Options
2018-07-12 11:40:23 +02:00
static bool auto_resize = false ;
2022-09-01 10:51:15 +02:00
static bool window_padding = true ;
2023-11-13 14:13:17 +01:00
static int type = 6 ; // Aspect Ratio
2018-07-12 11:40:23 +02:00
static int display_lines = 10 ;
2022-09-01 10:51:15 +02:00
// Submit constraint
float aspect_ratio = 16.0f / 9.0f ;
float fixed_step = 100.0f ;
if ( type = = 0 ) ImGui : : SetNextWindowSizeConstraints ( ImVec2 ( 100 , 100 ) , ImVec2 ( 500 , 500 ) ) ; // Between 100x100 and 500x500
if ( type = = 1 ) ImGui : : SetNextWindowSizeConstraints ( ImVec2 ( 100 , 100 ) , ImVec2 ( FLT_MAX , FLT_MAX ) ) ; // Width > 100, Height > 100
2023-11-13 14:13:17 +01:00
if ( type = = 2 ) ImGui : : SetNextWindowSizeConstraints ( ImVec2 ( - 1 , 0 ) , ImVec2 ( - 1 , FLT_MAX ) ) ; // Resize vertical + lock current width
if ( type = = 3 ) ImGui : : SetNextWindowSizeConstraints ( ImVec2 ( 0 , - 1 ) , ImVec2 ( FLT_MAX , - 1 ) ) ; // Resize horizontal + lock current height
2022-09-01 10:51:15 +02:00
if ( type = = 4 ) ImGui : : SetNextWindowSizeConstraints ( ImVec2 ( 400 , - 1 ) , ImVec2 ( 500 , - 1 ) ) ; // Width Between and 400 and 500
2024-03-18 07:29:10 +01:00
if ( type = = 5 ) ImGui : : SetNextWindowSizeConstraints ( ImVec2 ( - 1 , 400 ) , ImVec2 ( - 1 , FLT_MAX ) ) ; // Height at least 400
2023-11-13 14:13:17 +01:00
if ( type = = 6 ) ImGui : : SetNextWindowSizeConstraints ( ImVec2 ( 0 , 0 ) , ImVec2 ( FLT_MAX , FLT_MAX ) , CustomConstraints : : AspectRatio , ( void * ) & aspect_ratio ) ; // Aspect ratio
if ( type = = 7 ) ImGui : : SetNextWindowSizeConstraints ( ImVec2 ( 0 , 0 ) , ImVec2 ( FLT_MAX , FLT_MAX ) , CustomConstraints : : Square ) ; // Always Square
if ( type = = 8 ) ImGui : : SetNextWindowSizeConstraints ( ImVec2 ( 0 , 0 ) , ImVec2 ( FLT_MAX , FLT_MAX ) , CustomConstraints : : Step , ( void * ) & fixed_step ) ; // Fixed Step
2022-09-01 10:51:15 +02:00
// Submit window
if ( ! window_padding )
ImGui : : PushStyleVar ( ImGuiStyleVar_WindowPadding , ImVec2 ( 0.0f , 0.0f ) ) ;
const ImGuiWindowFlags window_flags = auto_resize ? ImGuiWindowFlags_AlwaysAutoResize : 0 ;
const bool window_open = ImGui : : Begin ( " Example: Constrained Resize " , p_open , window_flags ) ;
if ( ! window_padding )
ImGui : : PopStyleVar ( ) ;
if ( window_open )
2018-07-12 11:40:23 +02:00
{
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Examples/Constrained Resizing window " ) ;
2022-09-01 10:51:15 +02:00
if ( ImGui : : GetIO ( ) . KeyShift )
{
// Display a dummy viewport (in your real app you would likely use ImageButton() to display a texture.
ImVec2 avail_size = ImGui : : GetContentRegionAvail ( ) ;
ImVec2 pos = ImGui : : GetCursorScreenPos ( ) ;
ImGui : : ColorButton ( " viewport " , ImVec4 ( 0.5f , 0.2f , 0.5f , 1.0f ) , ImGuiColorEditFlags_NoTooltip | ImGuiColorEditFlags_NoDragDrop , avail_size ) ;
ImGui : : SetCursorScreenPos ( ImVec2 ( pos . x + 10 , pos . y + 10 ) ) ;
ImGui : : Text ( " %.2f x %.2f " , avail_size . x , avail_size . y ) ;
}
else
{
ImGui : : Text ( " (Hold SHIFT to display a dummy viewport) " ) ;
if ( ImGui : : Button ( " Set 200x200 " ) ) { ImGui : : SetWindowSize ( ImVec2 ( 200 , 200 ) ) ; } ImGui : : SameLine ( ) ;
if ( ImGui : : Button ( " Set 500x500 " ) ) { ImGui : : SetWindowSize ( ImVec2 ( 500 , 500 ) ) ; } ImGui : : SameLine ( ) ;
if ( ImGui : : Button ( " Set 800x200 " ) ) { ImGui : : SetWindowSize ( ImVec2 ( 800 , 200 ) ) ; }
ImGui : : SetNextItemWidth ( ImGui : : GetFontSize ( ) * 20 ) ;
ImGui : : Combo ( " Constraint " , & type , test_desc , IM_ARRAYSIZE ( test_desc ) ) ;
ImGui : : SetNextItemWidth ( ImGui : : GetFontSize ( ) * 20 ) ;
ImGui : : DragInt ( " Lines " , & display_lines , 0.2f , 1 , 100 ) ;
ImGui : : Checkbox ( " Auto-resize " , & auto_resize ) ;
ImGui : : Checkbox ( " Window padding " , & window_padding ) ;
for ( int i = 0 ; i < display_lines ; i + + )
ImGui : : Text ( " %*sHello, sailor! Making this line long enough for the example. " , i * 4 , " " ) ;
}
2018-07-12 11:40:23 +02:00
}
ImGui : : End ( ) ;
}
//-----------------------------------------------------------------------------
2021-02-05 12:24:23 +01:00
// [SECTION] Example App: Simple overlay / ShowExampleAppSimpleOverlay()
2018-07-12 11:40:23 +02:00
//-----------------------------------------------------------------------------
2020-05-05 19:39:24 +02:00
// Demonstrate creating a simple static window with no decoration
// + a context-menu to choose which corner of the screen to use.
2018-07-12 11:40:23 +02:00
static void ShowExampleAppSimpleOverlay ( bool * p_open )
{
2022-09-01 10:51:15 +02:00
static int location = 0 ;
2019-01-16 16:10:51 +01:00
ImGuiIO & io = ImGui : : GetIO ( ) ;
2020-09-16 10:28:58 +02:00
ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav ;
2022-09-01 10:51:15 +02:00
if ( location > = 0 )
2019-02-06 13:08:30 +01:00
{
2021-06-29 14:35:30 +02:00
const float PAD = 10.0f ;
2021-02-10 14:54:59 +01:00
const ImGuiViewport * viewport = ImGui : : GetMainViewport ( ) ;
ImVec2 work_pos = viewport - > WorkPos ; // Use work area to avoid menu-bar/task-bar, if any!
ImVec2 work_size = viewport - > WorkSize ;
ImVec2 window_pos , window_pos_pivot ;
2022-09-01 10:51:15 +02:00
window_pos . x = ( location & 1 ) ? ( work_pos . x + work_size . x - PAD ) : ( work_pos . x + PAD ) ;
window_pos . y = ( location & 2 ) ? ( work_pos . y + work_size . y - PAD ) : ( work_pos . y + PAD ) ;
window_pos_pivot . x = ( location & 1 ) ? 1.0f : 0.0f ;
window_pos_pivot . y = ( location & 2 ) ? 1.0f : 0.0f ;
2018-07-12 11:40:23 +02:00
ImGui : : SetNextWindowPos ( window_pos , ImGuiCond_Always , window_pos_pivot ) ;
2021-02-10 14:54:59 +01:00
window_flags | = ImGuiWindowFlags_NoMove ;
2019-02-06 13:08:30 +01:00
}
2022-09-01 10:51:15 +02:00
else if ( location = = - 2 )
{
// Center window
ImGui : : SetNextWindowPos ( ImGui : : GetMainViewport ( ) - > GetCenter ( ) , ImGuiCond_Always , ImVec2 ( 0.5f , 0.5f ) ) ;
window_flags | = ImGuiWindowFlags_NoMove ;
}
2019-04-11 15:12:18 +02:00
ImGui : : SetNextWindowBgAlpha ( 0.35f ) ; // Transparent background
2020-05-05 19:39:24 +02:00
if ( ImGui : : Begin ( " Example: Simple overlay " , p_open , window_flags ) )
2018-07-12 11:40:23 +02:00
{
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Examples/Simple Overlay " ) ;
2022-09-01 10:51:15 +02:00
ImGui : : Text ( " Simple overlay \n " " (right-click to change position) " ) ;
2018-07-12 11:40:23 +02:00
ImGui : : Separator ( ) ;
if ( ImGui : : IsMousePosValid ( ) )
2019-01-16 16:10:51 +01:00
ImGui : : Text ( " Mouse Position: (%.1f,%.1f) " , io . MousePos . x , io . MousePos . y ) ;
2018-07-12 11:40:23 +02:00
else
ImGui : : Text ( " Mouse Position: <invalid> " ) ;
if ( ImGui : : BeginPopupContextWindow ( ) )
{
2022-09-01 10:51:15 +02:00
if ( ImGui : : MenuItem ( " Custom " , NULL , location = = - 1 ) ) location = - 1 ;
if ( ImGui : : MenuItem ( " Center " , NULL , location = = - 2 ) ) location = - 2 ;
if ( ImGui : : MenuItem ( " Top-left " , NULL , location = = 0 ) ) location = 0 ;
if ( ImGui : : MenuItem ( " Top-right " , NULL , location = = 1 ) ) location = 1 ;
if ( ImGui : : MenuItem ( " Bottom-left " , NULL , location = = 2 ) ) location = 2 ;
if ( ImGui : : MenuItem ( " Bottom-right " , NULL , location = = 3 ) ) location = 3 ;
2018-07-12 11:40:23 +02:00
if ( p_open & & ImGui : : MenuItem ( " Close " ) ) * p_open = false ;
ImGui : : EndPopup ( ) ;
}
}
ImGui : : End ( ) ;
}
2021-02-05 12:24:23 +01:00
//-----------------------------------------------------------------------------
// [SECTION] Example App: Fullscreen window / ShowExampleAppFullscreen()
//-----------------------------------------------------------------------------
// Demonstrate creating a window covering the entire screen/viewport
static void ShowExampleAppFullscreen ( bool * p_open )
{
2021-02-10 14:54:59 +01:00
static bool use_work_area = true ;
2022-06-02 14:32:43 +02:00
static ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings ;
2021-02-10 14:54:59 +01:00
// We demonstrate using the full viewport area or the work area (without menu-bars, task-bars etc.)
2023-03-15 15:55:47 +01:00
// Based on your use case you may want one or the other.
2021-02-10 14:54:59 +01:00
const ImGuiViewport * viewport = ImGui : : GetMainViewport ( ) ;
ImGui : : SetNextWindowPos ( use_work_area ? viewport - > WorkPos : viewport - > Pos ) ;
ImGui : : SetNextWindowSize ( use_work_area ? viewport - > WorkSize : viewport - > Size ) ;
2021-02-05 12:24:23 +01:00
if ( ImGui : : Begin ( " Example: Fullscreen window " , p_open , flags ) )
{
2021-02-10 14:54:59 +01:00
ImGui : : Checkbox ( " Use work area instead of main area " , & use_work_area ) ;
ImGui : : SameLine ( ) ;
HelpMarker ( " Main Area = entire viewport, \n Work Area = entire viewport minus sections used by the main menu bars, task bars etc. \n \n Enable the main-menu bar in Examples menu to see the difference. " ) ;
2021-02-05 12:24:23 +01:00
ImGui : : CheckboxFlags ( " ImGuiWindowFlags_NoBackground " , & flags , ImGuiWindowFlags_NoBackground ) ;
ImGui : : CheckboxFlags ( " ImGuiWindowFlags_NoDecoration " , & flags , ImGuiWindowFlags_NoDecoration ) ;
ImGui : : Indent ( ) ;
ImGui : : CheckboxFlags ( " ImGuiWindowFlags_NoTitleBar " , & flags , ImGuiWindowFlags_NoTitleBar ) ;
ImGui : : CheckboxFlags ( " ImGuiWindowFlags_NoCollapse " , & flags , ImGuiWindowFlags_NoCollapse ) ;
ImGui : : CheckboxFlags ( " ImGuiWindowFlags_NoScrollbar " , & flags , ImGuiWindowFlags_NoScrollbar ) ;
ImGui : : Unindent ( ) ;
2021-02-10 14:54:59 +01:00
if ( p_open & & ImGui : : Button ( " Close this window " ) )
* p_open = false ;
2021-02-05 12:24:23 +01:00
}
ImGui : : End ( ) ;
}
2018-07-12 11:40:23 +02:00
//-----------------------------------------------------------------------------
2018-09-06 11:35:13 +02:00
// [SECTION] Example App: Manipulating Window Titles / ShowExampleAppWindowTitles()
2018-07-12 11:40:23 +02:00
//-----------------------------------------------------------------------------
2022-09-14 18:19:50 +02:00
// Demonstrate the use of "##" and "###" in identifiers to manipulate ID generation.
2022-09-11 07:35:59 +02:00
// This applies to all regular items as well.
2020-05-05 19:39:24 +02:00
// Read FAQ section "How can I have multiple widgets with the same label?" for details.
2018-07-12 11:40:23 +02:00
static void ShowExampleAppWindowTitles ( bool * )
{
2021-02-10 14:54:59 +01:00
const ImGuiViewport * viewport = ImGui : : GetMainViewport ( ) ;
const ImVec2 base_pos = viewport - > Pos ;
2018-07-12 11:40:23 +02:00
// By default, Windows are uniquely identified by their title.
// You can use the "##" and "###" markers to manipulate the display/ID.
// Using "##" to display same title but have unique identifier.
2021-02-10 14:54:59 +01:00
ImGui : : SetNextWindowPos ( ImVec2 ( base_pos . x + 100 , base_pos . y + 100 ) , ImGuiCond_FirstUseEver ) ;
2018-07-12 11:40:23 +02:00
ImGui : : Begin ( " Same title as another window##1 " ) ;
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Examples/Manipulating window titles " ) ;
2018-07-12 11:40:23 +02:00
ImGui : : Text ( " This is window 1. \n My title is the same as window 2, but my identifier is unique. " ) ;
ImGui : : End ( ) ;
2021-02-10 14:54:59 +01:00
ImGui : : SetNextWindowPos ( ImVec2 ( base_pos . x + 100 , base_pos . y + 200 ) , ImGuiCond_FirstUseEver ) ;
2018-07-12 11:40:23 +02:00
ImGui : : Begin ( " Same title as another window##2 " ) ;
ImGui : : Text ( " This is window 2. \n My title is the same as window 1, but my identifier is unique. " ) ;
ImGui : : End ( ) ;
// Using "###" to display a changing title but keep a static identifier "AnimatedTitle"
char buf [ 128 ] ;
sprintf ( buf , " Animated title %c %d###AnimatedTitle " , " |/- \\ " [ ( int ) ( ImGui : : GetTime ( ) / 0.25f ) & 3 ] , ImGui : : GetFrameCount ( ) ) ;
2021-02-10 14:54:59 +01:00
ImGui : : SetNextWindowPos ( ImVec2 ( base_pos . x + 100 , base_pos . y + 300 ) , ImGuiCond_FirstUseEver ) ;
2018-07-12 11:40:23 +02:00
ImGui : : Begin ( buf ) ;
ImGui : : Text ( " This window has a changing title. " ) ;
ImGui : : End ( ) ;
}
//-----------------------------------------------------------------------------
2018-09-06 11:35:13 +02:00
// [SECTION] Example App: Custom Rendering using ImDrawList API / ShowExampleAppCustomRendering()
2018-07-12 11:40:23 +02:00
//-----------------------------------------------------------------------------
2024-01-09 23:36:26 +01:00
// Add a |_| looking shape
static void PathConcaveShape ( ImDrawList * draw_list , float x , float y , float sz )
{
const ImVec2 pos_norms [ ] = { { 0.0f , 0.0f } , { 0.3f , 0.0f } , { 0.3f , 0.7f } , { 0.7f , 0.7f } , { 0.7f , 0.0f } , { 1.0f , 0.0f } , { 1.0f , 1.0f } , { 0.0f , 1.0f } } ;
for ( const ImVec2 & p : pos_norms )
draw_list - > PathLineTo ( ImVec2 ( x + 0.5f + ( int ) ( sz * p . x ) , y + 0.5f + ( int ) ( sz * p . y ) ) ) ;
}
2018-07-12 11:40:23 +02:00
// Demonstrate using the low-level ImDrawList to draw custom shapes.
static void ShowExampleAppCustomRendering ( bool * p_open )
{
if ( ! ImGui : : Begin ( " Example: Custom rendering " , p_open ) )
{
ImGui : : End ( ) ;
return ;
}
2021-02-21 22:12:48 +01:00
IMGUI_DEMO_MARKER ( " Examples/Custom Rendering " ) ;
2018-07-12 11:40:23 +02:00
2020-05-05 19:39:24 +02:00
// Tip: If you do a lot of custom rendering, you probably want to use your own geometrical types and benefit of
// overloaded operators, etc. Define IM_VEC2_CLASS_EXTRA in imconfig.h to create implicit conversions between your
// types and ImVec2/ImVec4. Dear ImGui defines overloaded operators but they are internal to imgui.cpp and not
// exposed outside (to avoid messing with your types) In this example we are not using the maths operators!
2018-07-12 11:40:23 +02:00
2019-03-04 16:20:32 +01:00
if ( ImGui : : BeginTabBar ( " ##TabBar " ) )
2018-07-12 11:40:23 +02:00
{
2019-03-04 16:20:32 +01:00
if ( ImGui : : BeginTabItem ( " Primitives " ) )
{
2021-01-21 16:59:34 +01:00
ImGui : : PushItemWidth ( - ImGui : : GetFontSize ( ) * 15 ) ;
2020-08-03 19:13:42 +02:00
ImDrawList * draw_list = ImGui : : GetWindowDrawList ( ) ;
2020-02-24 12:44:19 +01:00
// Draw gradients
// (note that those are currently exacerbating our sRGB/Linear issues)
2020-08-03 19:25:41 +02:00
// Calling ImGui::GetColorU32() multiplies the given colors by the current Style Alpha, but you may pass the IM_COL32() directly as well..
2020-02-24 12:44:19 +01:00
ImGui : : Text ( " Gradients " ) ;
ImVec2 gradient_size = ImVec2 ( ImGui : : CalcItemWidth ( ) , ImGui : : GetFrameHeight ( ) ) ;
{
2020-05-05 19:39:24 +02:00
ImVec2 p0 = ImGui : : GetCursorScreenPos ( ) ;
ImVec2 p1 = ImVec2 ( p0 . x + gradient_size . x , p0 . y + gradient_size . y ) ;
2020-08-03 19:25:41 +02:00
ImU32 col_a = ImGui : : GetColorU32 ( IM_COL32 ( 0 , 0 , 0 , 255 ) ) ;
ImU32 col_b = ImGui : : GetColorU32 ( IM_COL32 ( 255 , 255 , 255 , 255 ) ) ;
2020-05-05 19:39:24 +02:00
draw_list - > AddRectFilledMultiColor ( p0 , p1 , col_a , col_b , col_b , col_a ) ;
2020-02-24 12:44:19 +01:00
ImGui : : InvisibleButton ( " ##gradient1 " , gradient_size ) ;
}
{
2020-05-05 19:39:24 +02:00
ImVec2 p0 = ImGui : : GetCursorScreenPos ( ) ;
ImVec2 p1 = ImVec2 ( p0 . x + gradient_size . x , p0 . y + gradient_size . y ) ;
2020-08-03 19:25:41 +02:00
ImU32 col_a = ImGui : : GetColorU32 ( IM_COL32 ( 0 , 255 , 0 , 255 ) ) ;
ImU32 col_b = ImGui : : GetColorU32 ( IM_COL32 ( 255 , 0 , 0 , 255 ) ) ;
2020-05-05 19:39:24 +02:00
draw_list - > AddRectFilledMultiColor ( p0 , p1 , col_a , col_b , col_b , col_a ) ;
2020-02-24 12:44:19 +01:00
ImGui : : InvisibleButton ( " ##gradient2 " , gradient_size ) ;
}
// Draw a bunch of primitives
ImGui : : Text ( " All primitives " ) ;
2020-12-21 16:25:56 +01:00
static float sz = 36.0f ;
2019-04-29 12:44:17 +02:00
static float thickness = 3.0f ;
2019-12-09 07:13:24 +01:00
static int ngon_sides = 6 ;
2020-01-08 00:10:18 +01:00
static bool circle_segments_override = false ;
static int circle_segments_override_v = 12 ;
2020-12-20 20:04:48 +01:00
static bool curve_segments_override = false ;
static int curve_segments_override_v = 8 ;
2019-04-29 12:44:17 +02:00
static ImVec4 colf = ImVec4 ( 1.0f , 1.0f , 0.4f , 1.0f ) ;
2021-02-08 16:37:51 +01:00
ImGui : : DragFloat ( " Size " , & sz , 0.2f , 2.0f , 100.0f , " %.0f " ) ;
2019-03-04 16:20:32 +01:00
ImGui : : DragFloat ( " Thickness " , & thickness , 0.05f , 1.0f , 8.0f , " %.02f " ) ;
2020-01-08 00:10:18 +01:00
ImGui : : SliderInt ( " N-gon sides " , & ngon_sides , 3 , 12 ) ;
ImGui : : Checkbox ( " ##circlesegmentoverride " , & circle_segments_override ) ;
ImGui : : SameLine ( 0.0f , ImGui : : GetStyle ( ) . ItemInnerSpacing . x ) ;
2020-12-21 16:25:56 +01:00
circle_segments_override | = ImGui : : SliderInt ( " Circle segments override " , & circle_segments_override_v , 3 , 40 ) ;
2020-12-20 20:04:48 +01:00
ImGui : : Checkbox ( " ##curvessegmentoverride " , & curve_segments_override ) ;
ImGui : : SameLine ( 0.0f , ImGui : : GetStyle ( ) . ItemInnerSpacing . x ) ;
2020-12-21 16:25:56 +01:00
curve_segments_override | = ImGui : : SliderInt ( " Curves segments override " , & curve_segments_override_v , 3 , 40 ) ;
2019-04-29 12:44:17 +02:00
ImGui : : ColorEdit4 ( " Color " , & colf . x ) ;
2020-08-03 19:25:41 +02:00
2019-03-04 16:20:32 +01:00
const ImVec2 p = ImGui : : GetCursorScreenPos ( ) ;
2019-04-29 12:44:17 +02:00
const ImU32 col = ImColor ( colf ) ;
2020-01-08 00:10:18 +01:00
const float spacing = 10.0f ;
2021-03-12 14:04:40 +01:00
const ImDrawFlags corners_tl_br = ImDrawFlags_RoundCornersTopLeft | ImDrawFlags_RoundCornersBottomRight ;
2021-02-08 16:37:51 +01:00
const float rounding = sz / 5.0f ;
2020-01-08 00:10:18 +01:00
const int circle_segments = circle_segments_override ? circle_segments_override_v : 0 ;
2020-12-20 20:04:48 +01:00
const int curve_segments = curve_segments_override ? curve_segments_override_v : 0 ;
2024-02-20 16:33:54 +01:00
const ImVec2 cp3 [ 3 ] = { ImVec2 ( 0.0f , sz * 0.6f ) , ImVec2 ( sz * 0.5f , - sz * 0.4f ) , ImVec2 ( sz , sz ) } ; // Control points for curves
const ImVec2 cp4 [ 4 ] = { ImVec2 ( 0.0f , 0.0f ) , ImVec2 ( sz * 1.3f , sz * 0.3f ) , ImVec2 ( sz - sz * 1.3f , sz - sz * 0.3f ) , ImVec2 ( sz , sz ) } ;
2020-08-03 19:25:41 +02:00
float x = p . x + 4.0f ;
float y = p . y + 4.0f ;
2019-03-04 16:20:32 +01:00
for ( int n = 0 ; n < 2 ; n + + )
{
2019-04-29 12:44:17 +02:00
// First line uses a thickness of 1.0f, second line uses the configurable thickness
2019-03-04 16:20:32 +01:00
float th = ( n = = 0 ) ? 1.0f : thickness ;
2020-08-03 19:25:41 +02:00
draw_list - > AddNgon ( ImVec2 ( x + sz * 0.5f , y + sz * 0.5f ) , sz * 0.5f , col , ngon_sides , th ) ; x + = sz + spacing ; // N-gon
draw_list - > AddCircle ( ImVec2 ( x + sz * 0.5f , y + sz * 0.5f ) , sz * 0.5f , col , circle_segments , th ) ; x + = sz + spacing ; // Circle
2024-03-18 09:55:33 +01:00
draw_list - > AddEllipse ( ImVec2 ( x + sz * 0.5f , y + sz * 0.5f ) , ImVec2 ( sz * 0.5f , sz * 0.3f ) , col , - 0.3f , circle_segments , th ) ; x + = sz + spacing ; // Ellipse
2021-03-11 12:25:24 +01:00
draw_list - > AddRect ( ImVec2 ( x , y ) , ImVec2 ( x + sz , y + sz ) , col , 0.0f , ImDrawFlags_None , th ) ; x + = sz + spacing ; // Square
draw_list - > AddRect ( ImVec2 ( x , y ) , ImVec2 ( x + sz , y + sz ) , col , rounding , ImDrawFlags_None , th ) ; x + = sz + spacing ; // Square with all rounded corners
2021-02-08 16:37:51 +01:00
draw_list - > AddRect ( ImVec2 ( x , y ) , ImVec2 ( x + sz , y + sz ) , col , rounding , corners_tl_br , th ) ; x + = sz + spacing ; // Square with two rounded corners
2020-08-03 19:25:41 +02:00
draw_list - > AddTriangle ( ImVec2 ( x + sz * 0.5f , y ) , ImVec2 ( x + sz , y + sz - 0.5f ) , ImVec2 ( x , y + sz - 0.5f ) , col , th ) ; x + = sz + spacing ; // Triangle
//draw_list->AddTriangle(ImVec2(x+sz*0.2f,y), ImVec2(x, y+sz-0.5f), ImVec2(x+sz*0.4f, y+sz-0.5f), col, th);x+= sz*0.4f + spacing; // Thin triangle
2024-01-09 23:36:26 +01:00
PathConcaveShape ( draw_list , x , y , sz ) ; draw_list - > PathStroke ( col , ImDrawFlags_Closed , th ) ; x + = sz + spacing ; // Concave Shape
//draw_list->AddPolyline(concave_shape, IM_ARRAYSIZE(concave_shape), col, ImDrawFlags_Closed, th);
2020-08-03 19:25:41 +02:00
draw_list - > AddLine ( ImVec2 ( x , y ) , ImVec2 ( x + sz , y ) , col , th ) ; x + = sz + spacing ; // Horizontal line (note: drawing a filled rectangle will be faster!)
draw_list - > AddLine ( ImVec2 ( x , y ) , ImVec2 ( x , y + sz ) , col , th ) ; x + = spacing ; // Vertical line (note: drawing a filled rectangle will be faster!)
draw_list - > AddLine ( ImVec2 ( x , y ) , ImVec2 ( x + sz , y + sz ) , col , th ) ; x + = sz + spacing ; // Diagonal line
2020-12-21 16:25:56 +01:00
2024-02-20 16:33:54 +01:00
// Path
draw_list - > PathArcTo ( ImVec2 ( x + sz * 0.5f , y + sz * 0.5f ) , sz * 0.5f , 3.141592f , 3.141592f * - 0.5f ) ;
draw_list - > PathStroke ( col , ImDrawFlags_None , th ) ;
x + = sz + spacing ;
2020-12-21 16:25:56 +01:00
// Quadratic Bezier Curve (3 control points)
2024-02-20 16:33:54 +01:00
draw_list - > AddBezierQuadratic ( ImVec2 ( x + cp3 [ 0 ] . x , y + cp3 [ 0 ] . y ) , ImVec2 ( x + cp3 [ 1 ] . x , y + cp3 [ 1 ] . y ) , ImVec2 ( x + cp3 [ 2 ] . x , y + cp3 [ 2 ] . y ) , col , th , curve_segments ) ;
x + = sz + spacing ;
2020-12-21 16:25:56 +01:00
// Cubic Bezier Curve (4 control points)
2024-02-20 16:33:54 +01:00
draw_list - > AddBezierCubic ( ImVec2 ( x + cp4 [ 0 ] . x , y + cp4 [ 0 ] . y ) , ImVec2 ( x + cp4 [ 1 ] . x , y + cp4 [ 1 ] . y ) , ImVec2 ( x + cp4 [ 2 ] . x , y + cp4 [ 2 ] . y ) , ImVec2 ( x + cp4 [ 3 ] . x , y + cp4 [ 3 ] . y ) , col , th , curve_segments ) ;
2020-12-21 16:25:56 +01:00
2019-03-04 16:20:32 +01:00
x = p . x + 4 ;
y + = sz + spacing ;
}
2024-02-20 16:33:54 +01:00
// Filled shapes
2019-08-23 06:50:02 +02:00
draw_list - > AddNgonFilled ( ImVec2 ( x + sz * 0.5f , y + sz * 0.5f ) , sz * 0.5f , col , ngon_sides ) ; x + = sz + spacing ; // N-gon
draw_list - > AddCircleFilled ( ImVec2 ( x + sz * 0.5f , y + sz * 0.5f ) , sz * 0.5f , col , circle_segments ) ; x + = sz + spacing ; // Circle
2024-03-18 09:55:33 +01:00
draw_list - > AddEllipseFilled ( ImVec2 ( x + sz * 0.5f , y + sz * 0.5f ) , ImVec2 ( sz * 0.5f , sz * 0.3f ) , col , - 0.3f , circle_segments ) ; x + = sz + spacing ; // Ellipse
2020-08-03 19:25:41 +02:00
draw_list - > AddRectFilled ( ImVec2 ( x , y ) , ImVec2 ( x + sz , y + sz ) , col ) ; x + = sz + spacing ; // Square
draw_list - > AddRectFilled ( ImVec2 ( x , y ) , ImVec2 ( x + sz , y + sz ) , col , 10.0f ) ; x + = sz + spacing ; // Square with all rounded corners
draw_list - > AddRectFilled ( ImVec2 ( x , y ) , ImVec2 ( x + sz , y + sz ) , col , 10.0f , corners_tl_br ) ; x + = sz + spacing ; // Square with two rounded corners
draw_list - > AddTriangleFilled ( ImVec2 ( x + sz * 0.5f , y ) , ImVec2 ( x + sz , y + sz - 0.5f ) , ImVec2 ( x , y + sz - 0.5f ) , col ) ; x + = sz + spacing ; // Triangle
//draw_list->AddTriangleFilled(ImVec2(x+sz*0.2f,y), ImVec2(x, y+sz-0.5f), ImVec2(x+sz*0.4f, y+sz-0.5f), col); x += sz*0.4f + spacing; // Thin triangle
2024-01-09 23:36:26 +01:00
PathConcaveShape ( draw_list , x , y , sz ) ; draw_list - > PathFillConcave ( col ) ; x + = sz + spacing ; // Concave shape
2020-08-03 19:25:41 +02:00
draw_list - > AddRectFilled ( ImVec2 ( x , y ) , ImVec2 ( x + sz , y + thickness ) , col ) ; x + = sz + spacing ; // Horizontal line (faster than AddLine, but only handle integer thickness)
draw_list - > AddRectFilled ( ImVec2 ( x , y ) , ImVec2 ( x + thickness , y + sz ) , col ) ; x + = spacing * 2.0f ; // Vertical line (faster than AddLine, but only handle integer thickness)
draw_list - > AddRectFilled ( ImVec2 ( x , y ) , ImVec2 ( x + 1 , y + 1 ) , col ) ; x + = sz ; // Pixel (faster than AddLine)
2024-02-20 16:33:54 +01:00
// Path
draw_list - > PathArcTo ( ImVec2 ( x + sz * 0.5f , y + sz * 0.5f ) , sz * 0.5f , 3.141592f * - 0.5f , 3.141592f ) ;
draw_list - > PathFillConvex ( col ) ;
x + = sz + spacing ;
// Quadratic Bezier Curve (3 control points)
draw_list - > PathLineTo ( ImVec2 ( x + cp3 [ 0 ] . x , y + cp3 [ 0 ] . y ) ) ;
draw_list - > PathBezierQuadraticCurveTo ( ImVec2 ( x + cp3 [ 1 ] . x , y + cp3 [ 1 ] . y ) , ImVec2 ( x + cp3 [ 2 ] . x , y + cp3 [ 2 ] . y ) , curve_segments ) ;
draw_list - > PathFillConvex ( col ) ;
x + = sz + spacing ;
2019-03-04 16:20:32 +01:00
draw_list - > AddRectFilledMultiColor ( ImVec2 ( x , y ) , ImVec2 ( x + sz , y + sz ) , IM_COL32 ( 0 , 0 , 0 , 255 ) , IM_COL32 ( 255 , 0 , 0 , 255 ) , IM_COL32 ( 255 , 255 , 0 , 255 ) , IM_COL32 ( 0 , 255 , 0 , 255 ) ) ;
2024-01-09 23:36:26 +01:00
x + = sz + spacing ;
2020-02-10 22:08:52 +01:00
2024-01-09 23:36:26 +01:00
ImGui : : Dummy ( ImVec2 ( ( sz + spacing ) * 13.2f , ( sz + spacing ) * 3.0f ) ) ;
2020-02-10 22:08:52 +01:00
ImGui : : PopItemWidth ( ) ;
2019-03-04 16:20:32 +01:00
ImGui : : EndTabItem ( ) ;
2018-07-12 11:40:23 +02:00
}
2019-03-04 16:20:32 +01:00
if ( ImGui : : BeginTabItem ( " Canvas " ) )
2018-07-12 11:40:23 +02:00
{
2020-08-05 17:10:06 +02:00
static ImVector < ImVec2 > points ;
2020-08-03 19:13:42 +02:00
static ImVec2 scrolling ( 0.0f , 0.0f ) ;
2020-08-03 21:19:12 +02:00
static bool opt_enable_grid = true ;
static bool opt_enable_context_menu = true ;
2019-03-04 16:20:32 +01:00
static bool adding_line = false ;
2020-08-03 19:13:42 +02:00
2020-08-03 21:19:12 +02:00
ImGui : : Checkbox ( " Enable grid " , & opt_enable_grid ) ;
ImGui : : Checkbox ( " Enable context menu " , & opt_enable_context_menu ) ;
2020-08-03 19:13:42 +02:00
ImGui : : Text ( " Mouse Left: drag to add lines, \n Mouse Right: drag to scroll, click for context menu. " ) ;
// Typically you would use a BeginChild()/EndChild() pair to benefit from a clipping region + own scrolling.
// Here we demonstrate that this can be replaced by simple offsetting + custom drawing + PushClipRect/PopClipRect() calls.
// To use a child window instead we could use, e.g:
// ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); // Disable padding
// ImGui::PushStyleColor(ImGuiCol_ChildBg, IM_COL32(50, 50, 50, 255)); // Set a background color
2024-08-23 15:24:22 +02:00
// ImGui::BeginChild("canvas", ImVec2(0.0f, 0.0f), ImGuiChildFlags_Borders, ImGuiWindowFlags_NoMove);
2020-08-03 19:13:42 +02:00
// ImGui::PopStyleColor();
// ImGui::PopStyleVar();
// [...]
// ImGui::EndChild();
// Using InvisibleButton() as a convenience 1) it will advance the layout cursor and 2) allows us to use IsItemHovered()/IsItemActive()
ImVec2 canvas_p0 = ImGui : : GetCursorScreenPos ( ) ; // ImDrawList API uses screen coordinates!
2020-05-05 19:39:24 +02:00
ImVec2 canvas_sz = ImGui : : GetContentRegionAvail ( ) ; // Resize canvas to what's available
if ( canvas_sz . x < 50.0f ) canvas_sz . x = 50.0f ;
if ( canvas_sz . y < 50.0f ) canvas_sz . y = 50.0f ;
2020-08-03 19:13:42 +02:00
ImVec2 canvas_p1 = ImVec2 ( canvas_p0 . x + canvas_sz . x , canvas_p0 . y + canvas_sz . y ) ;
2019-03-04 16:20:32 +01:00
2020-08-03 19:13:42 +02:00
// Draw border and background color
ImGuiIO & io = ImGui : : GetIO ( ) ;
ImDrawList * draw_list = ImGui : : GetWindowDrawList ( ) ;
draw_list - > AddRectFilled ( canvas_p0 , canvas_p1 , IM_COL32 ( 50 , 50 , 50 , 255 ) ) ;
draw_list - > AddRect ( canvas_p0 , canvas_p1 , IM_COL32 ( 255 , 255 , 255 , 255 ) ) ;
// This will catch our interactions
ImGui : : InvisibleButton ( " canvas " , canvas_sz , ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight ) ;
const bool is_hovered = ImGui : : IsItemHovered ( ) ; // Hovered
const bool is_active = ImGui : : IsItemActive ( ) ; // Held
const ImVec2 origin ( canvas_p0 . x + scrolling . x , canvas_p0 . y + scrolling . y ) ; // Lock scrolled origin
const ImVec2 mouse_pos_in_canvas ( io . MousePos . x - origin . x , io . MousePos . y - origin . y ) ;
// Add first and second point
if ( is_hovered & & ! adding_line & & ImGui : : IsMouseClicked ( ImGuiMouseButton_Left ) )
{
2020-08-05 17:10:06 +02:00
points . push_back ( mouse_pos_in_canvas ) ;
points . push_back ( mouse_pos_in_canvas ) ;
2020-08-03 19:13:42 +02:00
adding_line = true ;
}
2019-03-04 16:20:32 +01:00
if ( adding_line )
2018-07-12 11:40:23 +02:00
{
2020-08-05 17:10:06 +02:00
points . back ( ) = mouse_pos_in_canvas ;
2020-08-03 19:13:42 +02:00
if ( ! ImGui : : IsMouseDown ( ImGuiMouseButton_Left ) )
adding_line = false ;
2018-07-12 11:40:23 +02:00
}
2020-08-03 19:13:42 +02:00
2020-08-03 21:19:12 +02:00
// Pan (we use a zero mouse threshold when there's no context menu)
// You may decide to make that threshold dynamic based on whether the mouse is hovering something etc.
const float mouse_threshold_for_pan = opt_enable_context_menu ? - 1.0f : 0.0f ;
if ( is_active & & ImGui : : IsMouseDragging ( ImGuiMouseButton_Right , mouse_threshold_for_pan ) )
2018-07-12 11:40:23 +02:00
{
2020-08-03 19:13:42 +02:00
scrolling . x + = io . MouseDelta . x ;
scrolling . y + = io . MouseDelta . y ;
2018-07-12 11:40:23 +02:00
}
2020-05-05 19:39:24 +02:00
2020-08-03 19:13:42 +02:00
// Context menu (under default mouse threshold)
ImVec2 drag_delta = ImGui : : GetMouseDragDelta ( ImGuiMouseButton_Right ) ;
2022-01-24 13:13:38 +01:00
if ( opt_enable_context_menu & & drag_delta . x = = 0.0f & & drag_delta . y = = 0.0f )
ImGui : : OpenPopupOnItemClick ( " context " , ImGuiPopupFlags_MouseButtonRight ) ;
2020-08-03 19:13:42 +02:00
if ( ImGui : : BeginPopup ( " context " ) )
{
if ( adding_line )
2020-08-05 17:10:06 +02:00
points . resize ( points . size ( ) - 2 ) ;
2020-08-03 19:13:42 +02:00
adding_line = false ;
2020-08-05 17:10:06 +02:00
if ( ImGui : : MenuItem ( " Remove one " , NULL , false , points . Size > 0 ) ) { points . resize ( points . size ( ) - 2 ) ; }
if ( ImGui : : MenuItem ( " Remove all " , NULL , false , points . Size > 0 ) ) { points . clear ( ) ; }
2020-08-03 19:13:42 +02:00
ImGui : : EndPopup ( ) ;
}
// Draw grid + all lines in the canvas
draw_list - > PushClipRect ( canvas_p0 , canvas_p1 , true ) ;
2020-08-03 21:19:12 +02:00
if ( opt_enable_grid )
2020-08-03 19:13:42 +02:00
{
const float GRID_STEP = 64.0f ;
for ( float x = fmodf ( scrolling . x , GRID_STEP ) ; x < canvas_sz . x ; x + = GRID_STEP )
draw_list - > AddLine ( ImVec2 ( canvas_p0 . x + x , canvas_p0 . y ) , ImVec2 ( canvas_p0 . x + x , canvas_p1 . y ) , IM_COL32 ( 200 , 200 , 200 , 40 ) ) ;
for ( float y = fmodf ( scrolling . y , GRID_STEP ) ; y < canvas_sz . y ; y + = GRID_STEP )
draw_list - > AddLine ( ImVec2 ( canvas_p0 . x , canvas_p0 . y + y ) , ImVec2 ( canvas_p1 . x , canvas_p0 . y + y ) , IM_COL32 ( 200 , 200 , 200 , 40 ) ) ;
}
2020-08-05 17:10:06 +02:00
for ( int n = 0 ; n < points . Size ; n + = 2 )
draw_list - > AddLine ( ImVec2 ( origin . x + points [ n ] . x , origin . y + points [ n ] . y ) , ImVec2 ( origin . x + points [ n + 1 ] . x , origin . y + points [ n + 1 ] . y ) , IM_COL32 ( 255 , 255 , 0 , 255 ) , 2.0f ) ;
2019-03-04 16:20:32 +01:00
draw_list - > PopClipRect ( ) ;
2020-08-03 19:13:42 +02:00
2019-03-04 16:20:32 +01:00
ImGui : : EndTabItem ( ) ;
}
if ( ImGui : : BeginTabItem ( " BG/FG draw lists " ) )
{
static bool draw_bg = true ;
static bool draw_fg = true ;
ImGui : : Checkbox ( " Draw in Background draw list " , & draw_bg ) ;
2019-08-29 14:46:02 +02:00
ImGui : : SameLine ( ) ; HelpMarker ( " The Background draw list will be rendered below every Dear ImGui windows. " ) ;
2019-03-04 16:20:32 +01:00
ImGui : : Checkbox ( " Draw in Foreground draw list " , & draw_fg ) ;
2019-08-29 14:46:02 +02:00
ImGui : : SameLine ( ) ; HelpMarker ( " The Foreground draw list will be rendered over every Dear ImGui windows. " ) ;
2019-03-04 16:20:32 +01:00
ImVec2 window_pos = ImGui : : GetWindowPos ( ) ;
ImVec2 window_size = ImGui : : GetWindowSize ( ) ;
ImVec2 window_center = ImVec2 ( window_pos . x + window_size . x * 0.5f , window_pos . y + window_size . y * 0.5f ) ;
if ( draw_bg )
2020-06-30 15:31:54 +02:00
ImGui : : GetBackgroundDrawList ( ) - > AddCircle ( window_center , window_size . x * 0.6f , IM_COL32 ( 255 , 0 , 0 , 200 ) , 0 , 10 + 4 ) ;
2019-03-04 16:20:32 +01:00
if ( draw_fg )
2020-02-24 12:44:19 +01:00
ImGui : : GetForegroundDrawList ( ) - > AddCircle ( window_center , window_size . y * 0.6f , IM_COL32 ( 0 , 255 , 0 , 200 ) , 0 , 10 ) ;
2019-03-04 16:20:32 +01:00
ImGui : : EndTabItem ( ) ;
2018-07-12 11:40:23 +02:00
}
2019-03-04 16:20:32 +01:00
2023-08-06 20:13:05 +02:00
// Demonstrate out-of-order rendering via channels splitting
// We use functions in ImDrawList as each draw list contains a convenience splitter,
// but you can also instantiate your own ImDrawListSplitter if you need to nest them.
if ( ImGui : : BeginTabItem ( " Draw Channels " ) )
{
ImDrawList * draw_list = ImGui : : GetWindowDrawList ( ) ;
{
ImGui : : Text ( " Blue shape is drawn first: appears in back " ) ;
ImGui : : Text ( " Red shape is drawn after: appears in front " ) ;
ImVec2 p0 = ImGui : : GetCursorScreenPos ( ) ;
draw_list - > AddRectFilled ( ImVec2 ( p0 . x , p0 . y ) , ImVec2 ( p0 . x + 50 , p0 . y + 50 ) , IM_COL32 ( 0 , 0 , 255 , 255 ) ) ; // Blue
draw_list - > AddRectFilled ( ImVec2 ( p0 . x + 25 , p0 . y + 25 ) , ImVec2 ( p0 . x + 75 , p0 . y + 75 ) , IM_COL32 ( 255 , 0 , 0 , 255 ) ) ; // Red
ImGui : : Dummy ( ImVec2 ( 75 , 75 ) ) ;
}
ImGui : : Separator ( ) ;
{
ImGui : : Text ( " Blue shape is drawn first, into channel 1: appears in front " ) ;
ImGui : : Text ( " Red shape is drawn after, into channel 0: appears in back " ) ;
ImVec2 p1 = ImGui : : GetCursorScreenPos ( ) ;
// Create 2 channels and draw a Blue shape THEN a Red shape.
// You can create any number of channels. Tables API use 1 channel per column in order to better batch draw calls.
draw_list - > ChannelsSplit ( 2 ) ;
draw_list - > ChannelsSetCurrent ( 1 ) ;
draw_list - > AddRectFilled ( ImVec2 ( p1 . x , p1 . y ) , ImVec2 ( p1 . x + 50 , p1 . y + 50 ) , IM_COL32 ( 0 , 0 , 255 , 255 ) ) ; // Blue
draw_list - > ChannelsSetCurrent ( 0 ) ;
draw_list - > AddRectFilled ( ImVec2 ( p1 . x + 25 , p1 . y + 25 ) , ImVec2 ( p1 . x + 75 , p1 . y + 75 ) , IM_COL32 ( 255 , 0 , 0 , 255 ) ) ; // Red
// Flatten/reorder channels. Red shape is in channel 0 and it appears below the Blue shape in channel 1.
// This works by copying draw indices only (vertices are not copied).
draw_list - > ChannelsMerge ( ) ;
ImGui : : Dummy ( ImVec2 ( 75 , 75 ) ) ;
ImGui : : Text ( " After reordering, contents of channel 0 appears below channel 1. " ) ;
}
ImGui : : EndTabItem ( ) ;
}
2019-03-04 16:20:32 +01:00
ImGui : : EndTabBar ( ) ;
2018-07-12 11:40:23 +02:00
}
2019-03-04 16:20:32 +01:00
2018-12-11 13:25:16 +01:00
ImGui : : End ( ) ;
2018-12-11 12:36:47 +01:00
}
//-----------------------------------------------------------------------------
// [SECTION] Example App: Documents Handling / ShowExampleAppDocuments()
//-----------------------------------------------------------------------------
// Simplified structure to mimic a Document model
struct MyDocument
{
2024-05-23 21:15:01 +02:00
char Name [ 32 ] ; // Document title
int UID ; // Unique ID (necessary as we can change title)
2020-05-05 19:39:24 +02:00
bool Open ; // Set when open (we keep an array of all available documents to simplify demo code!)
bool OpenPrev ; // Copy of Open from last update.
bool Dirty ; // Set when the document has been modified
ImVec4 Color ; // An arbitrary variable associated to the document
2018-12-11 12:36:47 +01:00
2024-05-23 21:15:01 +02:00
MyDocument ( int uid , const char * name , bool open = true , const ImVec4 & color = ImVec4 ( 1.0f , 1.0f , 1.0f , 1.0f ) )
2019-01-20 17:56:17 +01:00
{
2024-05-23 21:15:01 +02:00
UID = uid ;
snprintf ( Name , sizeof ( Name ) , " %s " , name ) ;
2019-01-20 17:56:17 +01:00
Open = OpenPrev = open ;
Dirty = false ;
Color = color ;
2018-12-11 12:36:47 +01:00
}
void DoOpen ( ) { Open = true ; }
void DoForceClose ( ) { Open = false ; Dirty = false ; }
void DoSave ( ) { Dirty = false ; }
2024-05-23 21:15:01 +02:00
} ;
struct ExampleAppDocuments
{
ImVector < MyDocument > Documents ;
ImVector < MyDocument * > CloseQueue ;
MyDocument * RenamingDoc = NULL ;
bool RenamingStarted = false ;
ExampleAppDocuments ( )
{
Documents . push_back ( MyDocument ( 0 , " Lettuce " , true , ImVec4 ( 0.4f , 0.8f , 0.4f , 1.0f ) ) ) ;
Documents . push_back ( MyDocument ( 1 , " Eggplant " , true , ImVec4 ( 0.8f , 0.5f , 1.0f , 1.0f ) ) ) ;
Documents . push_back ( MyDocument ( 2 , " Carrot " , true , ImVec4 ( 1.0f , 0.8f , 0.5f , 1.0f ) ) ) ;
Documents . push_back ( MyDocument ( 3 , " Tomato " , false , ImVec4 ( 1.0f , 0.3f , 0.4f , 1.0f ) ) ) ;
Documents . push_back ( MyDocument ( 4 , " A Rather Long Title " , false , ImVec4 ( 0.4f , 0.8f , 0.8f , 1.0f ) ) ) ;
Documents . push_back ( MyDocument ( 5 , " Some Document " , false , ImVec4 ( 0.8f , 0.8f , 1.0f , 1.0f ) ) ) ;
}
// As we allow to change document name, we append a never-changing document ID so tabs are stable
void GetTabName ( MyDocument * doc , char * out_buf , size_t out_buf_size )
{
snprintf ( out_buf , out_buf_size , " %s###doc%d " , doc - > Name , doc - > UID ) ;
}
2018-12-11 12:36:47 +01:00
2020-08-03 21:19:12 +02:00
// Display placeholder contents for the Document
2024-05-23 21:15:01 +02:00
void DisplayDocContents ( MyDocument * doc )
2018-12-11 12:36:47 +01:00
{
ImGui : : PushID ( doc ) ;
ImGui : : Text ( " Document \" %s \" " , doc - > Name ) ;
ImGui : : PushStyleColor ( ImGuiCol_Text , doc - > Color ) ;
ImGui : : TextWrapped ( " Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " ) ;
ImGui : : PopStyleColor ( ) ;
2024-05-23 21:15:01 +02:00
ImGui : : SetNextItemShortcut ( ImGuiMod_Ctrl | ImGuiKey_R , ImGuiInputFlags_Tooltip ) ;
if ( ImGui : : Button ( " Rename.. " ) )
{
RenamingDoc = doc ;
RenamingStarted = true ;
}
ImGui : : SameLine ( ) ;
2024-05-23 16:39:39 +02:00
ImGui : : SetNextItemShortcut ( ImGuiMod_Ctrl | ImGuiKey_M , ImGuiInputFlags_Tooltip ) ;
if ( ImGui : : Button ( " Modify " ) )
2018-12-11 12:36:47 +01:00
doc - > Dirty = true ;
2024-05-23 21:15:01 +02:00
2018-12-11 12:36:47 +01:00
ImGui : : SameLine ( ) ;
2024-05-23 16:39:39 +02:00
ImGui : : SetNextItemShortcut ( ImGuiMod_Ctrl | ImGuiKey_S , ImGuiInputFlags_Tooltip ) ;
if ( ImGui : : Button ( " Save " ) )
2018-12-11 12:36:47 +01:00
doc - > DoSave ( ) ;
2024-05-23 21:15:01 +02:00
2023-03-07 17:37:15 +01:00
ImGui : : SameLine ( ) ;
2024-05-23 16:39:39 +02:00
ImGui : : SetNextItemShortcut ( ImGuiMod_Ctrl | ImGuiKey_W , ImGuiInputFlags_Tooltip ) ;
if ( ImGui : : Button ( " Close " ) )
2024-05-23 21:15:01 +02:00
CloseQueue . push_back ( doc ) ;
2018-12-11 12:36:47 +01:00
ImGui : : ColorEdit3 ( " color " , & doc - > Color . x ) ; // Useful to test drag and drop and hold-dragged-to-open-tab behavior.
ImGui : : PopID ( ) ;
}
// Display context menu for the Document
2024-05-23 21:15:01 +02:00
void DisplayDocContextMenu ( MyDocument * doc )
2018-12-11 12:36:47 +01:00
{
if ( ! ImGui : : BeginPopupContextItem ( ) )
return ;
char buf [ 256 ] ;
sprintf ( buf , " Save %s " , doc - > Name ) ;
2023-03-07 17:37:15 +01:00
if ( ImGui : : MenuItem ( buf , " Ctrl+S " , false , doc - > Open ) )
2018-12-11 12:36:47 +01:00
doc - > DoSave ( ) ;
2024-05-23 21:15:01 +02:00
if ( ImGui : : MenuItem ( " Rename... " , " Ctrl+R " , false , doc - > Open ) )
RenamingDoc = doc ;
2023-03-07 17:37:15 +01:00
if ( ImGui : : MenuItem ( " Close " , " Ctrl+W " , false , doc - > Open ) )
2024-05-23 21:15:01 +02:00
CloseQueue . push_back ( doc ) ;
2018-12-11 12:36:47 +01:00
ImGui : : EndPopup ( ) ;
}
2024-05-23 21:15:01 +02:00
// [Optional] Notify the system of Tabs/Windows closure that happened outside the regular tab interface.
// If a tab has been closed programmatically (aka closed from another source such as the Checkbox() in the demo,
// as opposed to clicking on the regular tab closing button) and stops being submitted, it will take a frame for
// the tab bar to notice its absence. During this frame there will be a gap in the tab bar, and if the tab that has
// disappeared was the selected one, the tab bar will report no selected tab during the frame. This will effectively
// give the impression of a flicker for one frame.
// We call SetTabItemClosed() to manually notify the Tab Bar or Docking system of removed tabs to avoid this glitch.
// Note that this completely optional, and only affect tab bars with the ImGuiTabBarFlags_Reorderable flag.
void NotifyOfDocumentsClosedElsewhere ( )
2018-12-11 12:36:47 +01:00
{
2024-05-23 21:15:01 +02:00
for ( MyDocument & doc : Documents )
{
if ( ! doc . Open & & doc . OpenPrev )
ImGui : : SetTabItemClosed ( doc . Name ) ;
doc . OpenPrev = doc . Open ;
}
2018-12-11 12:36:47 +01:00
}
} ;
void ShowExampleAppDocuments ( bool * p_open )
{
static ExampleAppDocuments app ;
2019-04-16 13:07:43 +02:00
// Options
static bool opt_reorderable = true ;
static ImGuiTabBarFlags opt_fitting_flags = ImGuiTabBarFlags_FittingPolicyDefault_ ;
2020-01-28 20:06:34 +01:00
bool window_contents_visible = ImGui : : Begin ( " Example: Documents " , p_open , ImGuiWindowFlags_MenuBar ) ;
if ( ! window_contents_visible )
2018-12-11 16:59:17 +01:00
{
ImGui : : End ( ) ;
return ;
}
2018-12-11 12:36:47 +01:00
// Menu
if ( ImGui : : BeginMenuBar ( ) )
{
if ( ImGui : : BeginMenu ( " File " ) )
{
int open_count = 0 ;
2023-08-28 12:21:16 +02:00
for ( MyDocument & doc : app . Documents )
open_count + = doc . Open ? 1 : 0 ;
2018-12-11 12:36:47 +01:00
if ( ImGui : : BeginMenu ( " Open " , open_count < app . Documents . Size ) )
{
2023-08-28 12:21:16 +02:00
for ( MyDocument & doc : app . Documents )
if ( ! doc . Open & & ImGui : : MenuItem ( doc . Name ) )
doc . DoOpen ( ) ;
2018-12-11 12:36:47 +01:00
ImGui : : EndMenu ( ) ;
}
if ( ImGui : : MenuItem ( " Close All Documents " , NULL , false , open_count > 0 ) )
2023-08-28 12:21:16 +02:00
for ( MyDocument & doc : app . Documents )
2024-05-23 21:15:01 +02:00
app . CloseQueue . push_back ( & doc ) ;
2023-03-07 17:37:15 +01:00
if ( ImGui : : MenuItem ( " Exit " ) & & p_open )
2022-07-07 14:12:15 +02:00
* p_open = false ;
2018-12-11 12:36:47 +01:00
ImGui : : EndMenu ( ) ;
}
ImGui : : EndMenuBar ( ) ;
}
// [Debug] List documents with one checkbox for each
for ( int doc_n = 0 ; doc_n < app . Documents . Size ; doc_n + + )
{
2023-08-28 12:21:16 +02:00
MyDocument & doc = app . Documents [ doc_n ] ;
2018-12-11 12:36:47 +01:00
if ( doc_n > 0 )
ImGui : : SameLine ( ) ;
2023-08-28 12:21:16 +02:00
ImGui : : PushID ( & doc ) ;
if ( ImGui : : Checkbox ( doc . Name , & doc . Open ) )
if ( ! doc . Open )
doc . DoForceClose ( ) ;
2018-12-11 12:36:47 +01:00
ImGui : : PopID ( ) ;
}
ImGui : : Separator ( ) ;
2021-06-24 14:30:32 +02:00
// About the ImGuiWindowFlags_UnsavedDocument / ImGuiTabItemFlags_UnsavedDocument flags.
// They have multiple effects:
// - Display a dot next to the title.
// - Tab is selected when clicking the X close button.
// - Closure is not assumed (will wait for user to stop submitting the tab).
// Otherwise closure is assumed when pressing the X, so if you keep submitting the tab may reappear at end of tab bar.
// We need to assume closure by default otherwise waiting for "lack of submission" on the next frame would leave an empty
// hole for one-frame, both in the tab-bar and in tab-contents when closing a tab/window.
// The rarely used SetTabItemClosed() function is a way to notify of programmatic closure to avoid the one-frame hole.
2018-12-11 12:36:47 +01:00
// Submit Tab Bar and Tabs
{
ImGuiTabBarFlags tab_bar_flags = ( opt_fitting_flags ) | ( opt_reorderable ? ImGuiTabBarFlags_Reorderable : 0 ) ;
2024-06-19 01:52:56 +02:00
tab_bar_flags | = ImGuiTabBarFlags_DrawSelectedOverline ;
2018-12-11 12:36:47 +01:00
if ( ImGui : : BeginTabBar ( " ##tabs " , tab_bar_flags ) )
{
if ( opt_reorderable )
2024-05-23 21:15:01 +02:00
app . NotifyOfDocumentsClosedElsewhere ( ) ;
2018-12-11 12:36:47 +01:00
// [DEBUG] Stress tests
//if ((ImGui::GetFrameCount() % 30) == 0) docs[1].Open ^= 1; // [DEBUG] Automatically show/hide a tab. Test various interactions e.g. dragging with this on.
//if (ImGui::GetIO().KeyCtrl) ImGui::SetTabItemSelected(docs[1].Name); // [DEBUG] Test SetTabItemSelected(), probably not very useful as-is anyway..
// Submit Tabs
2023-08-28 12:21:16 +02:00
for ( MyDocument & doc : app . Documents )
2018-12-11 12:36:47 +01:00
{
2023-08-28 12:21:16 +02:00
if ( ! doc . Open )
2018-12-11 12:36:47 +01:00
continue ;
2024-05-23 21:15:01 +02:00
// As we allow to change document name, we append a never-changing document id so tabs are stable
char doc_name_buf [ 64 ] ;
app . GetTabName ( & doc , doc_name_buf , sizeof ( doc_name_buf ) ) ;
2023-08-28 12:21:16 +02:00
ImGuiTabItemFlags tab_flags = ( doc . Dirty ? ImGuiTabItemFlags_UnsavedDocument : 0 ) ;
2024-05-23 21:15:01 +02:00
bool visible = ImGui : : BeginTabItem ( doc_name_buf , & doc . Open , tab_flags ) ;
2018-12-11 12:36:47 +01:00
// Cancel attempt to close when unsaved add to save queue so we can display a popup.
2023-08-28 12:21:16 +02:00
if ( ! doc . Open & & doc . Dirty )
2018-12-11 12:36:47 +01:00
{
2023-08-28 12:21:16 +02:00
doc . Open = true ;
2024-05-23 21:15:01 +02:00
app . CloseQueue . push_back ( & doc ) ;
2018-12-11 12:36:47 +01:00
}
2024-05-23 21:15:01 +02:00
app . DisplayDocContextMenu ( & doc ) ;
2018-12-11 12:36:47 +01:00
if ( visible )
{
2024-05-23 21:15:01 +02:00
app . DisplayDocContents ( & doc ) ;
2018-12-11 12:36:47 +01:00
ImGui : : EndTabItem ( ) ;
}
}
ImGui : : EndTabBar ( ) ;
}
}
2024-05-23 21:15:01 +02:00
// Display renaming UI
if ( app . RenamingDoc ! = NULL )
2018-12-11 12:36:47 +01:00
{
2024-05-23 21:15:01 +02:00
if ( app . RenamingStarted )
ImGui : : OpenPopup ( " Rename " ) ;
if ( ImGui : : BeginPopup ( " Rename " ) )
{
ImGui : : SetNextItemWidth ( ImGui : : GetFontSize ( ) * 30 ) ;
if ( ImGui : : InputText ( " ###Name " , app . RenamingDoc - > Name , IM_ARRAYSIZE ( app . RenamingDoc - > Name ) , ImGuiInputTextFlags_EnterReturnsTrue ) )
2018-12-11 12:36:47 +01:00
{
2024-05-23 21:15:01 +02:00
ImGui : : CloseCurrentPopup ( ) ;
app . RenamingDoc = NULL ;
2018-12-11 12:36:47 +01:00
}
2024-05-23 21:15:01 +02:00
if ( app . RenamingStarted )
ImGui : : SetKeyboardFocusHere ( - 1 ) ;
ImGui : : EndPopup ( ) ;
}
else
{
app . RenamingDoc = NULL ;
}
app . RenamingStarted = false ;
2018-12-11 12:36:47 +01:00
}
// Display closing confirmation UI
2024-05-23 21:15:01 +02:00
if ( ! app . CloseQueue . empty ( ) )
2018-12-11 12:36:47 +01:00
{
int close_queue_unsaved_documents = 0 ;
2024-05-23 21:15:01 +02:00
for ( int n = 0 ; n < app . CloseQueue . Size ; n + + )
if ( app . CloseQueue [ n ] - > Dirty )
2018-12-11 12:36:47 +01:00
close_queue_unsaved_documents + + ;
if ( close_queue_unsaved_documents = = 0 )
{
// Close documents when all are unsaved
2024-05-23 21:15:01 +02:00
for ( int n = 0 ; n < app . CloseQueue . Size ; n + + )
app . CloseQueue [ n ] - > DoForceClose ( ) ;
app . CloseQueue . clear ( ) ;
2018-12-11 12:36:47 +01:00
}
else
{
if ( ! ImGui : : IsPopupOpen ( " Save? " ) )
ImGui : : OpenPopup ( " Save? " ) ;
2021-02-03 14:55:17 +01:00
if ( ImGui : : BeginPopupModal ( " Save? " , NULL , ImGuiWindowFlags_AlwaysAutoResize ) )
2018-12-11 12:36:47 +01:00
{
ImGui : : Text ( " Save change to the following items? " ) ;
2021-02-03 14:55:17 +01:00
float item_height = ImGui : : GetTextLineHeightWithSpacing ( ) ;
2023-11-07 18:28:03 +01:00
if ( ImGui : : BeginChild ( ImGui : : GetID ( " frame " ) , ImVec2 ( - FLT_MIN , 6.25f * item_height ) , ImGuiChildFlags_FrameStyle ) )
2024-05-23 21:15:01 +02:00
for ( MyDocument * doc : app . CloseQueue )
if ( doc - > Dirty )
ImGui : : Text ( " %s " , doc - > Name ) ;
2023-11-07 18:28:03 +01:00
ImGui : : EndChild ( ) ;
2018-12-11 12:36:47 +01:00
2021-02-03 14:55:17 +01:00
ImVec2 button_size ( ImGui : : GetFontSize ( ) * 7.0f , 0.0f ) ;
if ( ImGui : : Button ( " Yes " , button_size ) )
2018-12-11 12:36:47 +01:00
{
2024-05-23 21:15:01 +02:00
for ( MyDocument * doc : app . CloseQueue )
2018-12-11 12:36:47 +01:00
{
2024-05-23 21:15:01 +02:00
if ( doc - > Dirty )
doc - > DoSave ( ) ;
doc - > DoForceClose ( ) ;
2018-12-11 12:36:47 +01:00
}
2024-05-23 21:15:01 +02:00
app . CloseQueue . clear ( ) ;
2018-12-11 12:36:47 +01:00
ImGui : : CloseCurrentPopup ( ) ;
}
ImGui : : SameLine ( ) ;
2021-02-03 14:55:17 +01:00
if ( ImGui : : Button ( " No " , button_size ) )
2018-12-11 12:36:47 +01:00
{
2024-05-23 21:15:01 +02:00
for ( MyDocument * doc : app . CloseQueue )
doc - > DoForceClose ( ) ;
app . CloseQueue . clear ( ) ;
2018-12-11 12:36:47 +01:00
ImGui : : CloseCurrentPopup ( ) ;
}
ImGui : : SameLine ( ) ;
2021-02-03 14:55:17 +01:00
if ( ImGui : : Button ( " Cancel " , button_size ) )
2018-12-11 12:36:47 +01:00
{
2024-05-23 21:15:01 +02:00
app . CloseQueue . clear ( ) ;
2018-12-11 12:36:47 +01:00
ImGui : : CloseCurrentPopup ( ) ;
}
ImGui : : EndPopup ( ) ;
}
}
}
2018-07-12 11:40:23 +02:00
ImGui : : End ( ) ;
}
2023-08-31 20:06:22 +02:00
//-----------------------------------------------------------------------------
// [SECTION] Example App: Assets Browser / ShowExampleAppAssetsBrowser()
//-----------------------------------------------------------------------------
//#include "imgui_internal.h" // NavMoveRequestTryWrapping()
2023-09-01 14:54:28 +02:00
struct ExampleAsset
{
2023-10-06 17:10:52 +02:00
ImGuiID ID ;
2023-09-01 14:54:28 +02:00
int Type ;
2023-10-06 17:10:52 +02:00
ExampleAsset ( ImGuiID id , int type ) { ID = id ; Type = type ; }
2023-09-01 14:54:28 +02:00
static const ImGuiTableSortSpecs * s_current_sort_specs ;
static void SortWithSortSpecs ( ImGuiTableSortSpecs * sort_specs , ExampleAsset * items , int items_count )
{
s_current_sort_specs = sort_specs ; // Store in variable accessible by the sort function.
if ( items_count > 1 )
qsort ( items , ( size_t ) items_count , sizeof ( items [ 0 ] ) , ExampleAsset : : CompareWithSortSpecs ) ;
s_current_sort_specs = NULL ;
}
// Compare function to be used by qsort()
static int IMGUI_CDECL CompareWithSortSpecs ( const void * lhs , const void * rhs )
{
const ExampleAsset * a = ( const ExampleAsset * ) lhs ;
const ExampleAsset * b = ( const ExampleAsset * ) rhs ;
for ( int n = 0 ; n < s_current_sort_specs - > SpecsCount ; n + + )
{
const ImGuiTableColumnSortSpecs * sort_spec = & s_current_sort_specs - > Specs [ n ] ;
int delta = 0 ;
if ( sort_spec - > ColumnIndex = = 0 )
2023-10-06 17:10:52 +02:00
delta = ( ( int ) a - > ID - ( int ) b - > ID ) ;
2023-09-01 14:54:28 +02:00
else if ( sort_spec - > ColumnIndex = = 1 )
delta = ( a - > Type - b - > Type ) ;
if ( delta > 0 )
return ( sort_spec - > SortDirection = = ImGuiSortDirection_Ascending ) ? + 1 : - 1 ;
if ( delta < 0 )
return ( sort_spec - > SortDirection = = ImGuiSortDirection_Ascending ) ? - 1 : + 1 ;
}
2023-10-06 17:10:52 +02:00
return ( ( int ) a - > ID - ( int ) b - > ID ) ;
2023-09-01 14:54:28 +02:00
}
} ;
const ImGuiTableSortSpecs * ExampleAsset : : s_current_sort_specs = NULL ;
2023-08-31 20:06:22 +02:00
struct ExampleAssetsBrowser
{
2023-09-01 14:54:28 +02:00
// Options
2023-12-06 16:55:55 +01:00
bool ShowTypeOverlay = true ;
2024-06-11 20:56:41 +02:00
bool AllowSorting = true ;
2023-12-06 16:55:55 +01:00
bool AllowDragUnselected = false ;
2023-12-20 21:14:09 +01:00
bool AllowBoxSelect = true ;
2023-12-06 16:55:55 +01:00
float IconSize = 32.0f ;
int IconSpacing = 10 ;
int IconHitSpacing = 4 ; // Increase hit-spacing if you want to make it possible to clear or box-select from gaps. Some spacing is required to able to amend with Shift+box-select. Value is small in Explorer.
bool StretchSpacing = true ;
2023-09-01 14:54:28 +02:00
2023-08-31 20:06:22 +02:00
// State
2023-12-06 16:55:55 +01:00
ImVector < ExampleAsset > Items ; // Our items
ExampleSelectionWithDeletion Selection ; // Our selection (ImGuiSelectionBasicStorage + helper funcs to handle deletion)
ImGuiID NextItemId = 0 ; // Unique identifier when creating new items
bool RequestDelete = false ; // Deferred deletion request
bool RequestSort = false ; // Deferred sort request
float ZoomWheelAccum = 0.0f ; // Mouse wheel accumulator to handle smooth wheels better
2023-08-31 20:06:22 +02:00
2023-12-12 17:26:02 +01:00
// Calculated sizes for layout, output of UpdateLayoutSizes(). Could be locals but our code is simpler this way.
ImVec2 LayoutItemSize ;
ImVec2 LayoutItemStep ; // == LayoutItemSize + LayoutItemSpacing
float LayoutItemSpacing = 0.0f ;
float LayoutSelectableSpacing = 0.0f ;
float LayoutOuterPadding = 0.0f ;
int LayoutColumnCount = 0 ;
int LayoutLineCount = 0 ;
2023-08-31 20:06:22 +02:00
// Functions
2023-09-01 14:54:28 +02:00
ExampleAssetsBrowser ( )
{
AddItems ( 10000 ) ;
}
void AddItems ( int count )
{
if ( Items . Size = = 0 )
NextItemId = 0 ;
Items . reserve ( Items . Size + count ) ;
for ( int n = 0 ; n < count ; n + + , NextItemId + + )
Items . push_back ( ExampleAsset ( NextItemId , ( NextItemId % 20 ) < 15 ? 0 : ( NextItemId % 20 ) < 18 ? 1 : 2 ) ) ;
2023-12-06 16:55:55 +01:00
RequestSort = true ;
2023-09-01 14:54:28 +02:00
}
void ClearItems ( )
{
Items . clear ( ) ;
Selection . Clear ( ) ;
}
2023-12-12 17:26:02 +01:00
// Logic would be written in the main code BeginChild() and outputing to local variables.
// We extracted it into a function so we can call it easily from multiple places.
void UpdateLayoutSizes ( float avail_width )
{
// Layout: when not stretching: allow extending into right-most spacing.
LayoutItemSpacing = ( float ) IconSpacing ;
if ( StretchSpacing = = false )
avail_width + = floorf ( LayoutItemSpacing * 0.5f ) ;
// Layout: calculate number of icon per line and number of lines
LayoutItemSize = ImVec2 ( floorf ( IconSize ) , floorf ( IconSize ) ) ;
LayoutColumnCount = IM_MAX ( ( int ) ( avail_width / ( LayoutItemSize . x + LayoutItemSpacing ) ) , 1 ) ;
LayoutLineCount = ( Items . Size + LayoutColumnCount - 1 ) / LayoutColumnCount ;
// Layout: when stretching: allocate remaining space to more spacing. Round before division, so item_spacing may be non-integer.
if ( StretchSpacing & & LayoutColumnCount > 1 )
LayoutItemSpacing = floorf ( avail_width - LayoutItemSize . x * LayoutColumnCount ) / LayoutColumnCount ;
LayoutItemStep = ImVec2 ( LayoutItemSize . x + LayoutItemSpacing , LayoutItemSize . y + LayoutItemSpacing ) ;
LayoutSelectableSpacing = IM_MAX ( floorf ( LayoutItemSpacing ) - IconHitSpacing , 0.0f ) ;
LayoutOuterPadding = floorf ( LayoutItemSpacing * 0.5f ) ;
}
2023-08-31 20:06:22 +02:00
void Draw ( const char * title , bool * p_open )
{
2023-09-01 14:54:28 +02:00
ImGui : : SetNextWindowSize ( ImVec2 ( IconSize * 25 , IconSize * 15 ) , ImGuiCond_FirstUseEver ) ;
2023-08-31 20:06:22 +02:00
if ( ! ImGui : : Begin ( title , p_open , ImGuiWindowFlags_MenuBar ) )
{
ImGui : : End ( ) ;
return ;
}
// Menu bar
if ( ImGui : : BeginMenuBar ( ) )
{
if ( ImGui : : BeginMenu ( " File " ) )
{
2023-09-01 14:54:28 +02:00
if ( ImGui : : MenuItem ( " Add 10000 items " ) )
AddItems ( 10000 ) ;
if ( ImGui : : MenuItem ( " Clear items " ) )
ClearItems ( ) ;
ImGui : : Separator ( ) ;
2023-08-31 20:06:22 +02:00
if ( ImGui : : MenuItem ( " Close " , NULL , false , p_open ! = NULL ) )
* p_open = false ;
ImGui : : EndMenu ( ) ;
}
2023-12-06 16:55:55 +01:00
if ( ImGui : : BeginMenu ( " Edit " ) )
{
if ( ImGui : : MenuItem ( " Delete " , " Del " , false , Selection . Size > 0 ) )
RequestDelete = true ;
ImGui : : EndMenu ( ) ;
}
2023-08-31 20:06:22 +02:00
if ( ImGui : : BeginMenu ( " Options " ) )
{
ImGui : : PushItemWidth ( ImGui : : GetFontSize ( ) * 10 ) ;
2023-09-01 14:54:28 +02:00
ImGui : : SeparatorText ( " Contents " ) ;
ImGui : : Checkbox ( " Show Type Overlay " , & ShowTypeOverlay ) ;
2024-06-11 20:56:41 +02:00
ImGui : : Checkbox ( " Allow Sorting " , & AllowSorting ) ;
2023-09-01 14:54:28 +02:00
2023-09-25 17:21:19 +02:00
ImGui : : SeparatorText ( " Selection Behavior " ) ;
ImGui : : Checkbox ( " Allow dragging unselected item " , & AllowDragUnselected ) ;
2023-12-20 11:34:25 +01:00
ImGui : : Checkbox ( " Allow box-selection " , & AllowBoxSelect ) ;
2023-09-25 17:21:19 +02:00
2023-09-01 14:54:28 +02:00
ImGui : : SeparatorText ( " Layout " ) ;
2023-08-31 20:06:22 +02:00
ImGui : : SliderFloat ( " Icon Size " , & IconSize , 16.0f , 128.0f , " %.0f " ) ;
2024-01-04 19:13:42 +01:00
ImGui : : SameLine ( ) ; HelpMarker ( " Use CTRL+Wheel to zoom " ) ;
2023-08-31 20:06:22 +02:00
ImGui : : SliderInt ( " Icon Spacing " , & IconSpacing , 0 , 32 ) ;
2023-09-25 17:21:19 +02:00
ImGui : : SliderInt ( " Icon Hit Spacing " , & IconHitSpacing , 0 , 32 ) ;
2023-08-31 20:06:22 +02:00
ImGui : : Checkbox ( " Stretch Spacing " , & StretchSpacing ) ;
ImGui : : PopItemWidth ( ) ;
ImGui : : EndMenu ( ) ;
}
ImGui : : EndMenuBar ( ) ;
}
// Show a table with ONLY one header row to showcase the idea/possibility of using this to provide a sorting UI
2024-06-11 20:56:41 +02:00
if ( AllowSorting )
2023-08-31 20:06:22 +02:00
{
2024-06-11 20:56:41 +02:00
ImGui : : PushStyleVar ( ImGuiStyleVar_ItemSpacing , ImVec2 ( 0 , 0 ) ) ;
ImGuiTableFlags table_flags_for_sort_specs = ImGuiTableFlags_Sortable | ImGuiTableFlags_SortMulti | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Borders ;
if ( ImGui : : BeginTable ( " for_sort_specs_only " , 2 , table_flags_for_sort_specs , ImVec2 ( 0.0f , ImGui : : GetFrameHeight ( ) ) ) )
{
ImGui : : TableSetupColumn ( " Index " ) ;
ImGui : : TableSetupColumn ( " Type " ) ;
ImGui : : TableHeadersRow ( ) ;
if ( ImGuiTableSortSpecs * sort_specs = ImGui : : TableGetSortSpecs ( ) )
if ( sort_specs - > SpecsDirty | | RequestSort )
{
ExampleAsset : : SortWithSortSpecs ( sort_specs , Items . Data , Items . Size ) ;
sort_specs - > SpecsDirty = RequestSort = false ;
}
ImGui : : EndTable ( ) ;
}
ImGui : : PopStyleVar ( ) ;
2023-08-31 20:06:22 +02:00
}
2023-12-12 17:26:02 +01:00
ImGuiIO & io = ImGui : : GetIO ( ) ;
ImGui : : SetNextWindowContentSize ( ImVec2 ( 0.0f , LayoutOuterPadding + LayoutLineCount * ( LayoutItemSize . x + LayoutItemSpacing ) ) ) ;
2024-08-23 15:24:22 +02:00
if ( ImGui : : BeginChild ( " Assets " , ImVec2 ( 0.0f , - ImGui : : GetTextLineHeightWithSpacing ( ) ) , ImGuiChildFlags_Borders , ImGuiWindowFlags_NoMove ) )
2023-08-31 20:06:22 +02:00
{
ImDrawList * draw_list = ImGui : : GetWindowDrawList ( ) ;
2023-12-12 17:26:02 +01:00
const float avail_width = ImGui : : GetContentRegionAvail ( ) . x ;
UpdateLayoutSizes ( avail_width ) ;
2023-08-31 20:06:22 +02:00
// Calculate and store start position.
ImVec2 start_pos = ImGui : : GetCursorScreenPos ( ) ;
2023-12-12 17:26:02 +01:00
start_pos = ImVec2 ( start_pos . x + LayoutOuterPadding , start_pos . y + LayoutOuterPadding ) ;
2023-08-31 20:06:22 +02:00
ImGui : : SetCursorScreenPos ( start_pos ) ;
// Multi-select
2023-09-25 19:53:02 +02:00
ImGuiMultiSelectFlags ms_flags = ImGuiMultiSelectFlags_ClearOnEscape | ImGuiMultiSelectFlags_ClearOnClickVoid ;
2024-06-28 19:01:18 +02:00
// - Enable box-select (in 2D mode, so that changing box-select rectangle X1/X2 boundaries will affect clipped items)
2023-12-20 11:34:25 +01:00
if ( AllowBoxSelect )
2024-06-28 19:01:18 +02:00
ms_flags | = ImGuiMultiSelectFlags_BoxSelect2d ;
// - This feature allows dragging an unselected item without selecting it (rarely used)
if ( AllowDragUnselected )
ms_flags | = ImGuiMultiSelectFlags_SelectOnClickRelease ;
// - Enable keyboard wrapping on X axis
// (FIXME-MULTISELECT: We haven't designed/exposed a general nav wrapping api yet, so this flag is provided as a courtesy to avoid doing:
// ImGui::NavMoveRequestTryWrapping(ImGui::GetCurrentWindow(), ImGuiNavMoveFlags_WrapX);
// When we finish implementing a more general API for this, we will obsolete this flag in favor of the new system)
ms_flags | = ImGuiMultiSelectFlags_NavWrapX ;
2024-06-05 17:04:55 +02:00
ImGuiMultiSelectIO * ms_io = ImGui : : BeginMultiSelect ( ms_flags , Selection . Size , Items . Size ) ;
2023-10-06 17:10:52 +02:00
// Use custom selection adapter: store ID in selection (recommended)
2024-05-30 18:44:57 +02:00
Selection . UserData = this ;
Selection . AdapterIndexToStorageId = [ ] ( ImGuiSelectionBasicStorage * self_ , int idx ) { ExampleAssetsBrowser * self = ( ExampleAssetsBrowser * ) self_ - > UserData ; return self - > Items [ idx ] . ID ; } ;
2024-06-05 17:04:55 +02:00
Selection . ApplyRequests ( ms_io ) ;
2023-08-31 20:06:22 +02:00
2024-05-23 18:56:31 +02:00
const bool want_delete = ( ImGui : : Shortcut ( ImGuiKey_Delete , ImGuiInputFlags_Repeat ) & & ( Selection . Size > 0 ) ) | | RequestDelete ;
2023-12-06 16:55:55 +01:00
const int item_curr_idx_to_focus = want_delete ? Selection . ApplyDeletionPreLoop ( ms_io , Items . Size ) : - 1 ;
RequestDelete = false ;
2023-12-12 17:26:02 +01:00
// Push LayoutSelectableSpacing (which is LayoutItemSpacing minus hit-spacing, if we decide to have hit gaps between items)
// Altering style ItemSpacing may seem unnecessary as we position every items using SetCursorScreenPos()...
2023-08-31 20:06:22 +02:00
// But it is necessary for two reasons:
// - Selectables uses it by default to visually fill the space between two items.
// - The vertical spacing would be measured by Clipper to calculate line height if we didn't provide it explicitly (here we do).
2023-12-12 17:26:02 +01:00
ImGui : : PushStyleVar ( ImGuiStyleVar_ItemSpacing , ImVec2 ( LayoutSelectableSpacing , LayoutSelectableSpacing ) ) ;
2023-08-31 20:06:22 +02:00
2023-09-01 14:54:28 +02:00
// Rendering parameters
const ImU32 icon_type_overlay_colors [ 3 ] = { 0 , IM_COL32 ( 200 , 70 , 70 , 255 ) , IM_COL32 ( 70 , 170 , 70 , 255 ) } ;
2024-10-28 15:44:44 +01:00
const ImU32 icon_bg_color = ImGui : : GetColorU32 ( IM_COL32 ( 35 , 35 , 35 , 220 ) ) ;
2023-09-01 14:54:28 +02:00
const ImVec2 icon_type_overlay_size = ImVec2 ( 4.0f , 4.0f ) ;
2023-12-12 17:26:02 +01:00
const bool display_label = ( LayoutItemSize . x > = ImGui : : CalcTextSize ( " 999 " ) . x ) ;
2023-09-01 14:54:28 +02:00
2023-12-12 17:26:02 +01:00
const int column_count = LayoutColumnCount ;
2023-08-31 20:06:22 +02:00
ImGuiListClipper clipper ;
2023-12-12 17:26:02 +01:00
clipper . Begin ( LayoutLineCount , LayoutItemStep . y ) ;
2023-12-06 16:55:55 +01:00
if ( item_curr_idx_to_focus ! = - 1 )
clipper . IncludeItemByIndex ( item_curr_idx_to_focus / column_count ) ; // Ensure focused item line is not clipped.
2023-08-31 20:06:22 +02:00
if ( ms_io - > RangeSrcItem ! = - 1 )
2023-12-06 16:55:55 +01:00
clipper . IncludeItemByIndex ( ( int ) ms_io - > RangeSrcItem / column_count ) ; // Ensure RangeSrc item line is not clipped.
2023-08-31 20:06:22 +02:00
while ( clipper . Step ( ) )
{
for ( int line_idx = clipper . DisplayStart ; line_idx < clipper . DisplayEnd ; line_idx + + )
{
const int item_min_idx_for_current_line = line_idx * column_count ;
2023-09-01 14:54:28 +02:00
const int item_max_idx_for_current_line = IM_MIN ( ( line_idx + 1 ) * column_count , Items . Size ) ;
2023-08-31 20:06:22 +02:00
for ( int item_idx = item_min_idx_for_current_line ; item_idx < item_max_idx_for_current_line ; + + item_idx )
{
2023-09-01 14:54:28 +02:00
ExampleAsset * item_data = & Items [ item_idx ] ;
2023-10-06 17:10:52 +02:00
ImGui : : PushID ( ( int ) item_data - > ID ) ;
2023-08-31 20:06:22 +02:00
// Position item
2023-12-12 17:26:02 +01:00
ImVec2 pos = ImVec2 ( start_pos . x + ( item_idx % column_count ) * LayoutItemStep . x , start_pos . y + line_idx * LayoutItemStep . y ) ;
2023-08-31 20:06:22 +02:00
ImGui : : SetCursorScreenPos ( pos ) ;
ImGui : : SetNextItemSelectionUserData ( item_idx ) ;
2023-09-01 14:54:28 +02:00
bool item_is_selected = Selection . Contains ( ( ImGuiID ) item_data - > ID ) ;
2023-12-20 21:14:09 +01:00
bool item_is_visible = ImGui : : IsRectVisible ( LayoutItemSize ) ;
2023-12-12 17:26:02 +01:00
ImGui : : Selectable ( " " , item_is_selected , ImGuiSelectableFlags_None , LayoutItemSize ) ;
2023-08-31 20:06:22 +02:00
// Update our selection state immediately (without waiting for EndMultiSelect() requests)
// because we use this to alter the color of our text/icon.
if ( ImGui : : IsItemToggledSelection ( ) )
item_is_selected = ! item_is_selected ;
2023-12-06 16:55:55 +01:00
// Focus (for after deletion)
if ( item_curr_idx_to_focus = = item_idx )
ImGui : : SetKeyboardFocusHere ( - 1 ) ;
2023-08-31 20:06:22 +02:00
// Drag and drop
if ( ImGui : : BeginDragDropSource ( ) )
{
2024-06-11 17:14:00 +02:00
// Create payload with full selection OR single unselected item.
2023-09-25 17:21:19 +02:00
// (the later is only possible when using ImGuiMultiSelectFlags_SelectOnClickRelease)
if ( ImGui : : GetDragDropPayload ( ) = = NULL )
2024-06-11 17:14:00 +02:00
{
ImVector < ImGuiID > payload_items ;
void * it = NULL ;
2024-06-26 17:00:52 +02:00
ImGuiID id = 0 ;
2024-06-11 17:14:00 +02:00
if ( ! item_is_selected )
payload_items . push_back ( item_data - > ID ) ;
else
2024-06-26 17:00:52 +02:00
while ( Selection . GetNextSelectedItem ( & it , & id ) )
2024-06-11 17:14:00 +02:00
payload_items . push_back ( id ) ;
ImGui : : SetDragDropPayload ( " ASSETS_BROWSER_ITEMS " , payload_items . Data , ( size_t ) payload_items . size_in_bytes ( ) ) ;
}
// Display payload content in tooltip, by extracting it from the payload data
// (we could read from selection, but it is more correct and reusable to read from payload)
const ImGuiPayload * payload = ImGui : : GetDragDropPayload ( ) ;
const int payload_count = ( int ) payload - > DataSize / ( int ) sizeof ( ImGuiID ) ;
ImGui : : Text ( " %d assets " , payload_count ) ;
2023-09-25 17:21:19 +02:00
2023-08-31 20:06:22 +02:00
ImGui : : EndDragDropSource ( ) ;
}
2023-12-20 21:14:09 +01:00
// Render icon (a real app would likely display an image/thumbnail here)
2024-06-26 20:26:06 +02:00
// Because we use ImGuiMultiSelectFlags_BoxSelect2d, clipping vertical may occasionally be larger, so we coarse-clip our rendering as well.
2023-12-20 21:14:09 +01:00
if ( item_is_visible )
2023-09-01 14:54:28 +02:00
{
2023-12-20 21:14:09 +01:00
ImVec2 box_min ( pos . x - 1 , pos . y - 1 ) ;
ImVec2 box_max ( box_min . x + LayoutItemSize . x + 2 , box_min . y + LayoutItemSize . y + 2 ) ; // Dubious
2023-12-21 15:12:17 +01:00
draw_list - > AddRectFilled ( box_min , box_max , icon_bg_color ) ; // Background color
2023-12-20 21:14:09 +01:00
if ( ShowTypeOverlay & & item_data - > Type ! = 0 )
{
ImU32 type_col = icon_type_overlay_colors [ item_data - > Type % IM_ARRAYSIZE ( icon_type_overlay_colors ) ] ;
draw_list - > AddRectFilled ( ImVec2 ( box_max . x - 2 - icon_type_overlay_size . x , box_min . y + 2 ) , ImVec2 ( box_max . x - 2 , box_min . y + 2 + icon_type_overlay_size . y ) , type_col ) ;
}
if ( display_label )
{
2023-12-21 15:12:17 +01:00
ImU32 label_col = ImGui : : GetColorU32 ( item_is_selected ? ImGuiCol_Text : ImGuiCol_TextDisabled ) ;
2023-12-20 21:14:09 +01:00
char label [ 32 ] ;
sprintf ( label , " %d " , item_data - > ID ) ;
draw_list - > AddText ( ImVec2 ( box_min . x , box_max . y - ImGui : : GetFontSize ( ) ) , label_col , label ) ;
}
2023-09-01 14:54:28 +02:00
}
2023-08-31 20:06:22 +02:00
ImGui : : PopID ( ) ;
}
}
}
clipper . End ( ) ;
ImGui : : PopStyleVar ( ) ; // ImGuiStyleVar_ItemSpacing
2023-12-06 16:55:55 +01:00
// Context menu
if ( ImGui : : BeginPopupContextWindow ( ) )
{
ImGui : : Text ( " Selection: %d items " , Selection . Size ) ;
ImGui : : Separator ( ) ;
if ( ImGui : : MenuItem ( " Delete " , " Del " , false , Selection . Size > 0 ) )
RequestDelete = true ;
ImGui : : EndPopup ( ) ;
}
2023-08-31 20:06:22 +02:00
ms_io = ImGui : : EndMultiSelect ( ) ;
2024-06-05 17:04:55 +02:00
Selection . ApplyRequests ( ms_io ) ;
2023-12-06 16:55:55 +01:00
if ( want_delete )
Selection . ApplyDeletionPostLoop ( ms_io , Items , item_curr_idx_to_focus ) ;
2023-08-31 20:06:22 +02:00
2023-12-12 17:26:02 +01:00
// Zooming with CTRL+Wheel
if ( ImGui : : IsWindowAppearing ( ) )
ZoomWheelAccum = 0.0f ;
if ( ImGui : : IsWindowHovered ( ) & & io . MouseWheel ! = 0.0f & & ImGui : : IsKeyDown ( ImGuiMod_Ctrl ) & & ImGui : : IsAnyItemActive ( ) = = false )
2023-12-06 16:55:55 +01:00
{
2023-12-12 17:26:02 +01:00
ZoomWheelAccum + = io . MouseWheel ;
if ( fabsf ( ZoomWheelAccum ) > = 1.0f )
{
// Calculate hovered item index from mouse location
// FIXME: Locking aiming on 'hovered_item_idx' (with a cool-down timer) would ensure zoom keeps on it.
const float hovered_item_nx = ( io . MousePos . x - start_pos . x + LayoutItemSpacing * 0.5f ) / LayoutItemStep . x ;
const float hovered_item_ny = ( io . MousePos . y - start_pos . y + LayoutItemSpacing * 0.5f ) / LayoutItemStep . y ;
const int hovered_item_idx = ( ( int ) hovered_item_ny * LayoutColumnCount ) + ( int ) hovered_item_nx ;
//ImGui::SetTooltip("%f,%f -> item %d", hovered_item_nx, hovered_item_ny, hovered_item_idx); // Move those 4 lines in block above for easy debugging
// Zoom
IconSize * = powf ( 1.1f , ( float ) ( int ) ZoomWheelAccum ) ;
IconSize = IM_CLAMP ( IconSize , 16.0f , 128.0f ) ;
ZoomWheelAccum - = ( int ) ZoomWheelAccum ;
UpdateLayoutSizes ( avail_width ) ;
// Manipulate scroll to that we will land at the same Y location of currently hovered item.
// - Calculate next frame position of item under mouse
// - Set new scroll position to be used in next ImGui::BeginChild() call.
float hovered_item_rel_pos_y = ( ( float ) ( hovered_item_idx / LayoutColumnCount ) + fmodf ( hovered_item_ny , 1.0f ) ) * LayoutItemStep . y ;
hovered_item_rel_pos_y + = ImGui : : GetStyle ( ) . WindowPadding . y ;
float mouse_local_y = io . MousePos . y - ImGui : : GetWindowPos ( ) . y ;
ImGui : : SetScrollY ( hovered_item_rel_pos_y - mouse_local_y ) ;
}
2023-12-06 16:55:55 +01:00
}
}
2023-08-31 20:06:22 +02:00
ImGui : : EndChild ( ) ;
2023-12-12 17:26:02 +01:00
2023-09-01 14:54:28 +02:00
ImGui : : Text ( " Selected: %d/%d items " , Selection . Size , Items . Size ) ;
2023-08-31 20:06:22 +02:00
ImGui : : End ( ) ;
}
} ;
void ShowExampleAppAssetsBrowser ( bool * p_open )
{
IMGUI_DEMO_MARKER ( " Examples/Assets Browser " ) ;
static ExampleAssetsBrowser assets_browser ;
assets_browser . Draw ( " Example: Assets Browser " , p_open ) ;
}
2015-07-22 01:00:28 +02:00
// End of Demo code
# else
2018-11-30 17:15:03 +01:00
void ImGui : : ShowAboutWindow ( bool * ) { }
2017-12-24 18:16:22 +01:00
void ImGui : : ShowDemoWindow ( bool * ) { }
2016-05-09 00:21:05 +02:00
void ImGui : : ShowUserGuide ( ) { }
void ImGui : : ShowStyleEditor ( ImGuiStyle * ) { }
2015-07-22 01:00:28 +02:00
# endif
2020-02-09 17:06:58 +01:00
# endif // #ifndef IMGUI_DISABLE