mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 09:27:00 +00:00
Merge branch 'master' into viewport
This commit is contained in:
commit
99c32ed4a5
@ -1085,8 +1085,8 @@ ImGuiIO::ImGuiIO()
|
||||
memset(this, 0, sizeof(*this));
|
||||
|
||||
// Settings
|
||||
ConfigFlags = 0x00;
|
||||
BackendFlags = 0x00;
|
||||
ConfigFlags = ImGuiConfigFlags_None;
|
||||
BackendFlags = ImGuiBackendFlags_None;
|
||||
DisplaySize = ImVec2(-1.0f, -1.0f);
|
||||
DeltaTime = 1.0f/60.0f;
|
||||
IniSavingRate = 5.0f;
|
||||
|
265
imgui.h
265
imgui.h
@ -6,9 +6,26 @@
|
||||
// Read 'Programmer guide' in imgui.cpp for notes on how to setup ImGui in your codebase.
|
||||
// Get latest version at https://github.com/ocornut/imgui
|
||||
|
||||
/*
|
||||
|
||||
Index of this file:
|
||||
// Header mess
|
||||
// Forward declarations and basic types
|
||||
// ImGui API (Dear ImGui end-user API)
|
||||
// Flags & Enumerations
|
||||
// ImGuiStyle
|
||||
// ImGuiIO
|
||||
// Misc data structures (ImGuiInputTextCallbackData, ImGuiSizeCallbackData, ImGuiPayload)
|
||||
// Obsolete functions
|
||||
// Helpers (ImVector, ImGuiOnceUponAFrame, ImGuiTextFilter, ImGuiTextBuffer, ImGuiStorage, ImGuiListClipper, ImColor)
|
||||
// Draw List API (ImDrawCmd, ImDrawIdx, ImDrawVert, ImDrawChannel, ImDrawListFlags, ImDrawList, ImDrawData)
|
||||
// Font API (ImFontConfig, ImFontGlyph, ImFontAtlasFlags, ImFontAtlas, ImFont)
|
||||
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
// Configuration file (edit imconfig.h or define IMGUI_USER_CONFIG to set your own filename)
|
||||
// Configuration file (edit imconfig.h or define IMGUI_USER_CONFIG to your own filename)
|
||||
#ifdef IMGUI_USER_CONFIG
|
||||
#include IMGUI_USER_CONFIG
|
||||
#endif
|
||||
@ -16,6 +33,10 @@
|
||||
#include "imconfig.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Header mess
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <float.h> // FLT_MAX
|
||||
#include <stdarg.h> // va_list
|
||||
#include <stddef.h> // ptrdiff_t, NULL
|
||||
@ -37,7 +58,7 @@
|
||||
#define IMGUI_IMPL_API IMGUI_API
|
||||
#endif
|
||||
|
||||
// Helpers
|
||||
// Helper Macros
|
||||
#ifndef IM_ASSERT
|
||||
#include <assert.h>
|
||||
#define IM_ASSERT(_EXPR) assert(_EXPR) // You can override the default assert handler by editing imconfig.h
|
||||
@ -52,6 +73,7 @@
|
||||
#define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR)/sizeof(*_ARR))) // Size of a static C-style array. Don't use on pointers!
|
||||
#define IM_OFFSETOF(_TYPE,_MEMBER) ((size_t)&(((_TYPE*)0)->_MEMBER)) // Offset of _MEMBER within _TYPE. Standardized as offsetof() in modern C++.
|
||||
|
||||
// Warnings
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wold-style-cast"
|
||||
@ -60,7 +82,10 @@
|
||||
#pragma GCC diagnostic ignored "-Wclass-memaccess"
|
||||
#endif
|
||||
|
||||
// Forward declarations
|
||||
//-----------------------------------------------------------------------------
|
||||
// Forward declarations and basic types
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct ImDrawChannel; // Temporary storage for outputting drawing commands out of order, used by ImDrawList::ChannelsSplit()
|
||||
struct ImDrawCmd; // A single draw command within a parent ImDrawList (generally maps to 1 GPU draw call)
|
||||
struct ImDrawData; // All draw command lists required to render the frame
|
||||
@ -159,8 +184,11 @@ struct ImVec4
|
||||
#endif
|
||||
};
|
||||
|
||||
// Dear ImGui end-user API
|
||||
// (In a namespace so you can add extra functions in your own separate file. Please don't modify imgui.cpp/.h!)
|
||||
//-----------------------------------------------------------------------------
|
||||
// ImGui: Dear ImGui end-user API
|
||||
// (Inside a namespace so you can add extra functions in your own separate file. Please don't modify imgui.cpp/.h!)
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
namespace ImGui
|
||||
{
|
||||
// Context creation and access
|
||||
@ -628,6 +656,10 @@ namespace ImGui
|
||||
|
||||
} // namespace ImGui
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Flags & Enumerations
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Flags for ImGui::Begin()
|
||||
enum ImGuiWindowFlags_
|
||||
{
|
||||
@ -883,6 +915,7 @@ enum ImGuiNavInput_
|
||||
// Configuration flags stored in io.ConfigFlags. Set by user/application.
|
||||
enum ImGuiConfigFlags_
|
||||
{
|
||||
ImGuiConfigFlags_None = 0,
|
||||
ImGuiConfigFlags_NavEnableKeyboard = 1 << 0, // Master keyboard navigation enable flag. NewFrame() will automatically fill io.NavInputs[] based on io.KeysDown[].
|
||||
ImGuiConfigFlags_NavEnableGamepad = 1 << 1, // Master gamepad navigation enable flag. This is mostly to instruct your imgui back-end to fill io.NavInputs[]. Back-end also needs to set ImGuiBackendFlags_HasGamepad.
|
||||
ImGuiConfigFlags_NavEnableSetMousePos = 1 << 2, // Instruct navigation to move the mouse cursor. May be useful on TV/console systems where moving a virtual mouse is awkward. Will update io.MousePos and set io.WantSetMousePos=true. If enabled you MUST honor io.WantSetMousePos requests in your binding, otherwise ImGui will react as if the mouse is jumping around back and forth.
|
||||
@ -907,6 +940,7 @@ enum ImGuiConfigFlags_
|
||||
// Back-end capabilities flags stored in io.BackendFlags. Set by imgui_impl_xxx or custom back-end.
|
||||
enum ImGuiBackendFlags_
|
||||
{
|
||||
ImGuiBackendFlags_None = 0,
|
||||
ImGuiBackendFlags_HasGamepad = 1 << 0, // Back-end supports gamepad and currently has one connected.
|
||||
ImGuiBackendFlags_HasMouseCursors = 1 << 1, // Back-end supports honoring GetMouseCursor() value to change the OS cursor shape.
|
||||
ImGuiBackendFlags_HasSetMousePos = 1 << 2, // Back-end supports io.WantSetMousePos requests to reposition the OS mouse position (only used if ImGuiConfigFlags_NavEnableSetMousePos is set).
|
||||
@ -1009,7 +1043,7 @@ enum ImGuiStyleVar_
|
||||
#endif
|
||||
};
|
||||
|
||||
// Enumeration for ColorEdit3() / ColorEdit4() / ColorPicker3() / ColorPicker4() / ColorButton()
|
||||
// Flags for ColorEdit3() / ColorEdit4() / ColorPicker3() / ColorPicker4() / ColorButton()
|
||||
enum ImGuiColorEditFlags_
|
||||
{
|
||||
ImGuiColorEditFlags_None = 0,
|
||||
@ -1064,7 +1098,8 @@ enum ImGuiMouseCursor_
|
||||
#endif
|
||||
};
|
||||
|
||||
// Condition for ImGui::SetWindow***(), SetNextWindow***(), SetNextTreeNode***() functions
|
||||
// Enumateration for ImGui::SetWindow***(), SetNextWindow***(), SetNextTreeNode***() functions
|
||||
// Represent a condition.
|
||||
// Important: Treat as a regular enum! Do NOT combine multiple values using binary operators! All the functions above treat 0 as a shortcut to ImGuiCond_Always.
|
||||
enum ImGuiCond_
|
||||
{
|
||||
@ -1079,8 +1114,13 @@ enum ImGuiCond_
|
||||
#endif
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// ImGuiStyle
|
||||
// You may modify the ImGui::GetStyle() main instance during initialization and before NewFrame().
|
||||
// During the frame, use ImGui::PushStyleVar(ImGuiStyleVar_XXXX)/PopStyleVar() to alter the main style values, and ImGui::PushStyleColor(ImGuiCol_XXX)/PopStyleColor() for colors.
|
||||
// During the frame, use ImGui::PushStyleVar(ImGuiStyleVar_XXXX)/PopStyleVar() to alter the main style values,
|
||||
// and ImGui::PushStyleColor(ImGuiCol_XXX)/PopStyleColor() for colors.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct ImGuiStyle
|
||||
{
|
||||
float Alpha; // Global alpha applies to everything in ImGui.
|
||||
@ -1118,8 +1158,12 @@ struct ImGuiStyle
|
||||
IMGUI_API void ScaleAllSizes(float scale_factor);
|
||||
};
|
||||
|
||||
// This is where your app communicate with Dear ImGui. Access via ImGui::GetIO().
|
||||
// Read 'Programmer guide' section in .cpp file for general usage.
|
||||
//-----------------------------------------------------------------------------
|
||||
// ImGuiIO
|
||||
// Communicate most settings and inputs/outputs to Dear ImGui using this structure.
|
||||
// Access via ImGui::GetIO(). Read 'Programmer guide' section in .cpp file for general usage.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct ImGuiIO
|
||||
{
|
||||
//------------------------------------------------------------------
|
||||
@ -1236,6 +1280,77 @@ struct ImGuiIO
|
||||
IMGUI_API ImGuiIO();
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Misc data structures
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Shared state of InputText(), passed as an argument to your callback when a ImGuiInputTextFlags_Callback* flag is used.
|
||||
// The callback function should return 0 by default.
|
||||
// Callbacks (follow a flag name and see comments in ImGuiInputTextFlags_ declarations for more details)
|
||||
// - ImGuiInputTextFlags_CallbackCompletion: Callback on pressing TAB
|
||||
// - ImGuiInputTextFlags_CallbackHistory: Callback on pressing Up/Down arrows
|
||||
// - ImGuiInputTextFlags_CallbackAlways: Callback on each iteration
|
||||
// - ImGuiInputTextFlags_CallbackCharFilter: Callback on character inputs to replace or discard them. Modify 'EventChar' to replace or discard, or return 1 in callback to discard.
|
||||
// - ImGuiInputTextFlags_CallbackResize: Callback on buffer capacity changes request (beyond 'buf_size' parameter value), allowing the string to grow.
|
||||
struct ImGuiInputTextCallbackData
|
||||
{
|
||||
ImGuiInputTextFlags EventFlag; // One ImGuiInputTextFlags_Callback* // Read-only
|
||||
ImGuiInputTextFlags Flags; // What user passed to InputText() // Read-only
|
||||
void* UserData; // What user passed to InputText() // Read-only
|
||||
|
||||
// Arguments for the different callback events
|
||||
// - To modify the text buffer in a callback, prefer using the InsertChars() / DeleteChars() function. InsertChars() will take care of calling the resize callback if necessary.
|
||||
// - If you know your edits are not going to resize the underlying buffer allocation, you may modify the contents of 'Buf[]' directly. You need to update 'BufTextLen' accordingly (0 <= BufTextLen < BufSize) and set 'BufDirty'' to true so InputText can update its internal state.
|
||||
ImWchar EventChar; // Character input // Read-write // [CharFilter] Replace character with another one, or set to zero to drop. return 1 is equivalent to setting EventChar=0;
|
||||
ImGuiKey EventKey; // Key pressed (Up/Down/TAB) // Read-only // [Completion,History]
|
||||
char* Buf; // Text buffer // Read-write // [Resize] Can replace pointer / [Completion,History,Always] Only write to pointed data, don't replace the actual pointer!
|
||||
int BufTextLen; // Text length (in bytes) // Read-write // [Resize,Completion,History,Always] Exclude zero-terminator storage. In C land: == strlen(some_text), in C++ land: string.length()
|
||||
int BufSize; // Buffer size (in bytes) = capacity+1 // Read-only // [Resize,Completion,History,Always] Include zero-terminator storage. In C land == ARRAYSIZE(my_char_array), in C++ land: string.capacity()+1
|
||||
bool BufDirty; // Set if you modify Buf/BufTextLen! // Write // [Completion,History,Always]
|
||||
int CursorPos; // // Read-write // [Completion,History,Always]
|
||||
int SelectionStart; // // Read-write // [Completion,History,Always] == to SelectionEnd when no selection)
|
||||
int SelectionEnd; // // Read-write // [Completion,History,Always]
|
||||
|
||||
// Helper functions for text manipulation.
|
||||
// Use those function to benefit from the CallbackResize behaviors. Calling those function reset the selection.
|
||||
IMGUI_API ImGuiInputTextCallbackData();
|
||||
IMGUI_API void DeleteChars(int pos, int bytes_count);
|
||||
IMGUI_API void InsertChars(int pos, const char* text, const char* text_end = NULL);
|
||||
bool HasSelection() const { return SelectionStart != SelectionEnd; }
|
||||
};
|
||||
|
||||
// Resizing callback data to apply custom constraint. As enabled by SetNextWindowSizeConstraints(). Callback is called during the next Begin().
|
||||
// NB: For basic min/max size constraint on each axis you don't need to use the callback! The SetNextWindowSizeConstraints() parameters are enough.
|
||||
struct ImGuiSizeCallbackData
|
||||
{
|
||||
void* UserData; // Read-only. What user passed to SetNextWindowSizeConstraints()
|
||||
ImVec2 Pos; // Read-only. Window position, for reference.
|
||||
ImVec2 CurrentSize; // Read-only. Current window size.
|
||||
ImVec2 DesiredSize; // Read-write. Desired size, based on user's mouse position. Write to this field to restrain resizing.
|
||||
};
|
||||
|
||||
// Data payload for Drag and Drop operations: AcceptDragDropPayload(), GetDragDropPayload()
|
||||
struct ImGuiPayload
|
||||
{
|
||||
// Members
|
||||
void* Data; // Data (copied and owned by dear imgui)
|
||||
int DataSize; // Data size
|
||||
|
||||
// [Internal]
|
||||
ImGuiID SourceId; // Source item id
|
||||
ImGuiID SourceParentId; // Source parent id (if available)
|
||||
int DataFrameCount; // Data timestamp
|
||||
char DataType[32+1]; // Data type tag (short user-supplied string, 32 characters max)
|
||||
bool Preview; // Set when AcceptDragDropPayload() was called and mouse has been hovering the target item (nb: handle overlapping drag targets)
|
||||
bool Delivery; // Set when AcceptDragDropPayload() was called and mouse button is released over the target item.
|
||||
|
||||
ImGuiPayload() { Clear(); }
|
||||
void Clear() { SourceId = SourceParentId = 0; Data = NULL; DataSize = 0; memset(DataType, 0, sizeof(DataType)); DataFrameCount = -1; Preview = Delivery = false; }
|
||||
bool IsDataType(const char* type) const { return DataFrameCount != -1 && strcmp(type, DataType) == 0; }
|
||||
bool IsPreview() const { return Preview; }
|
||||
bool IsDelivery() const { return Delivery; }
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Obsolete functions (Will be removed! Read 'API BREAKING CHANGES' section in imgui.cpp for details)
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -1273,6 +1388,8 @@ namespace ImGui
|
||||
static inline bool IsMouseHoveringAnyWindow() { return IsWindowHovered(ImGuiHoveredFlags_AnyWindow); }
|
||||
static inline bool IsMouseHoveringWindow() { return IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem); }
|
||||
}
|
||||
typedef ImGuiInputTextCallback ImGuiTextEditCallback; // [OBSOLETE 1.63+] Made the names consistent
|
||||
typedef ImGuiInputTextCallbackData ImGuiTextEditCallbackData;
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -1465,76 +1582,34 @@ struct ImGuiStorage
|
||||
IMGUI_API void BuildSortByKey();
|
||||
};
|
||||
|
||||
// Shared state of InputText(), passed as an argument to your callback when a ImGuiInputTextFlags_Callback* flag is used.
|
||||
// The callback function should return 0 by default.
|
||||
// Callbacks (follow a flag name and see comments in ImGuiInputTextFlags_ declarations for more details)
|
||||
// - ImGuiInputTextFlags_CallbackCompletion: Callback on pressing TAB
|
||||
// - ImGuiInputTextFlags_CallbackHistory: Callback on pressing Up/Down arrows
|
||||
// - ImGuiInputTextFlags_CallbackAlways: Callback on each iteration
|
||||
// - ImGuiInputTextFlags_CallbackCharFilter: Callback on character inputs to replace or discard them. Modify 'EventChar' to replace or discard, or return 1 in callback to discard.
|
||||
// - ImGuiInputTextFlags_CallbackResize: Callback on buffer capacity changes request (beyond 'buf_size' parameter value), allowing the string to grow.
|
||||
struct ImGuiInputTextCallbackData
|
||||
// Helper: Manually clip large list of items.
|
||||
// If you are submitting lots of evenly spaced items and you have a random access to the list, you can perform coarse clipping based on visibility to save yourself from processing those items at all.
|
||||
// The clipper calculates the range of visible items and advance the cursor to compensate for the non-visible items we have skipped.
|
||||
// ImGui already clip items based on their bounds but it needs to measure text size to do so. Coarse clipping before submission makes this cost and your own data fetching/submission cost null.
|
||||
// Usage:
|
||||
// ImGuiListClipper clipper(1000); // we have 1000 elements, evenly spaced.
|
||||
// while (clipper.Step())
|
||||
// for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
|
||||
// ImGui::Text("line number %d", i);
|
||||
// - Step 0: the clipper let you process the first element, regardless of it being visible or not, so we can measure the element height (step skipped if we passed a known height as second arg to constructor).
|
||||
// - Step 1: the clipper infer height from first element, calculate the actual range of elements to display, and position the cursor before the first element.
|
||||
// - (Step 2: dummy step only required if an explicit items_height was passed to constructor or Begin() and user call Step(). Does nothing and switch to Step 3.)
|
||||
// - Step 3: the clipper validate that we have reached the expected Y position (corresponding to element DisplayEnd), advance the cursor to the end of the list and then returns 'false' to end the loop.
|
||||
struct ImGuiListClipper
|
||||
{
|
||||
ImGuiInputTextFlags EventFlag; // One ImGuiInputTextFlags_Callback* // Read-only
|
||||
ImGuiInputTextFlags Flags; // What user passed to InputText() // Read-only
|
||||
void* UserData; // What user passed to InputText() // Read-only
|
||||
float StartPosY;
|
||||
float ItemsHeight;
|
||||
int ItemsCount, StepNo, DisplayStart, DisplayEnd;
|
||||
|
||||
// Arguments for the different callback events
|
||||
// - To modify the text buffer in a callback, prefer using the InsertChars() / DeleteChars() function. InsertChars() will take care of calling the resize callback if necessary.
|
||||
// - If you know your edits are not going to resize the underlying buffer allocation, you may modify the contents of 'Buf[]' directly. You need to update 'BufTextLen' accordingly (0 <= BufTextLen < BufSize) and set 'BufDirty'' to true so InputText can update its internal state.
|
||||
ImWchar EventChar; // Character input // Read-write // [CharFilter] Replace character with another one, or set to zero to drop. return 1 is equivalent to setting EventChar=0;
|
||||
ImGuiKey EventKey; // Key pressed (Up/Down/TAB) // Read-only // [Completion,History]
|
||||
char* Buf; // Text buffer // Read-write // [Resize] Can replace pointer / [Completion,History,Always] Only write to pointed data, don't replace the actual pointer!
|
||||
int BufTextLen; // Text length (in bytes) // Read-write // [Resize,Completion,History,Always] Exclude zero-terminator storage. In C land: == strlen(some_text), in C++ land: string.length()
|
||||
int BufSize; // Buffer size (in bytes) = capacity+1 // Read-only // [Resize,Completion,History,Always] Include zero-terminator storage. In C land == ARRAYSIZE(my_char_array), in C++ land: string.capacity()+1
|
||||
bool BufDirty; // Set if you modify Buf/BufTextLen! // Write // [Completion,History,Always]
|
||||
int CursorPos; // // Read-write // [Completion,History,Always]
|
||||
int SelectionStart; // // Read-write // [Completion,History,Always] == to SelectionEnd when no selection)
|
||||
int SelectionEnd; // // Read-write // [Completion,History,Always]
|
||||
// items_count: Use -1 to ignore (you can call Begin later). Use INT_MAX if you don't know how many items you have (in which case the cursor won't be advanced in the final step).
|
||||
// items_height: Use -1.0f to be calculated automatically on first step. Otherwise pass in the distance between your items, typically GetTextLineHeightWithSpacing() or GetFrameHeightWithSpacing().
|
||||
// If you don't specify an items_height, you NEED to call Step(). If you specify items_height you may call the old Begin()/End() api directly, but prefer calling Step().
|
||||
ImGuiListClipper(int items_count = -1, float items_height = -1.0f) { Begin(items_count, items_height); } // NB: Begin() initialize every fields (as we allow user to call Begin/End multiple times on a same instance if they want).
|
||||
~ImGuiListClipper() { IM_ASSERT(ItemsCount == -1); } // Assert if user forgot to call End() or Step() until false.
|
||||
|
||||
// Helper functions for text manipulation.
|
||||
// Use those function to benefit from the CallbackResize behaviors. Calling those function reset the selection.
|
||||
IMGUI_API ImGuiInputTextCallbackData();
|
||||
IMGUI_API void DeleteChars(int pos, int bytes_count);
|
||||
IMGUI_API void InsertChars(int pos, const char* text, const char* text_end = NULL);
|
||||
bool HasSelection() const { return SelectionStart != SelectionEnd; }
|
||||
};
|
||||
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||
typedef ImGuiInputTextCallback ImGuiTextEditCallback; // [OBSOLETE 1.63+] Made the names consistent
|
||||
typedef ImGuiInputTextCallbackData ImGuiTextEditCallbackData;
|
||||
#endif
|
||||
|
||||
// Resizing callback data to apply custom constraint. As enabled by SetNextWindowSizeConstraints(). Callback is called during the next Begin().
|
||||
// NB: For basic min/max size constraint on each axis you don't need to use the callback! The SetNextWindowSizeConstraints() parameters are enough.
|
||||
struct ImGuiSizeCallbackData
|
||||
{
|
||||
void* UserData; // Read-only. What user passed to SetNextWindowSizeConstraints()
|
||||
ImVec2 Pos; // Read-only. Window position, for reference.
|
||||
ImVec2 CurrentSize; // Read-only. Current window size.
|
||||
ImVec2 DesiredSize; // Read-write. Desired size, based on user's mouse position. Write to this field to restrain resizing.
|
||||
};
|
||||
|
||||
// Data payload for Drag and Drop operations
|
||||
struct ImGuiPayload
|
||||
{
|
||||
// Members
|
||||
void* Data; // Data (copied and owned by dear imgui)
|
||||
int DataSize; // Data size
|
||||
|
||||
// [Internal]
|
||||
ImGuiID SourceId; // Source item id
|
||||
ImGuiID SourceParentId; // Source parent id (if available)
|
||||
int DataFrameCount; // Data timestamp
|
||||
char DataType[32+1]; // Data type tag (short user-supplied string, 32 characters max)
|
||||
bool Preview; // Set when AcceptDragDropPayload() was called and mouse has been hovering the target item (nb: handle overlapping drag targets)
|
||||
bool Delivery; // Set when AcceptDragDropPayload() was called and mouse button is released over the target item.
|
||||
|
||||
ImGuiPayload() { Clear(); }
|
||||
void Clear() { SourceId = SourceParentId = 0; Data = NULL; DataSize = 0; memset(DataType, 0, sizeof(DataType)); DataFrameCount = -1; Preview = Delivery = false; }
|
||||
bool IsDataType(const char* type) const { return DataFrameCount != -1 && strcmp(type, DataType) == 0; }
|
||||
bool IsPreview() const { return Preview; }
|
||||
bool IsDelivery() const { return Delivery; }
|
||||
IMGUI_API bool Step(); // Call until it returns false. The DisplayStart/DisplayEnd fields will be set and you can process/draw those items.
|
||||
IMGUI_API void Begin(int items_count, float items_height = -1.0f); // Automatically called by constructor if you passed 'items_count' or by Step() in Step 1.
|
||||
IMGUI_API void End(); // Automatically called on the last call of Step() that returns false.
|
||||
};
|
||||
|
||||
// Helpers macros to generate 32-bits encoded colors
|
||||
@ -1577,38 +1652,8 @@ struct ImColor
|
||||
static ImColor HSV(float h, float s, float v, float a = 1.0f) { float r,g,b; ImGui::ColorConvertHSVtoRGB(h, s, v, r, g, b); return ImColor(r,g,b,a); }
|
||||
};
|
||||
|
||||
// Helper: Manually clip large list of items.
|
||||
// If you are submitting lots of evenly spaced items and you have a random access to the list, you can perform coarse clipping based on visibility to save yourself from processing those items at all.
|
||||
// The clipper calculates the range of visible items and advance the cursor to compensate for the non-visible items we have skipped.
|
||||
// ImGui already clip items based on their bounds but it needs to measure text size to do so. Coarse clipping before submission makes this cost and your own data fetching/submission cost null.
|
||||
// Usage:
|
||||
// ImGuiListClipper clipper(1000); // we have 1000 elements, evenly spaced.
|
||||
// while (clipper.Step())
|
||||
// for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
|
||||
// ImGui::Text("line number %d", i);
|
||||
// - Step 0: the clipper let you process the first element, regardless of it being visible or not, so we can measure the element height (step skipped if we passed a known height as second arg to constructor).
|
||||
// - Step 1: the clipper infer height from first element, calculate the actual range of elements to display, and position the cursor before the first element.
|
||||
// - (Step 2: dummy step only required if an explicit items_height was passed to constructor or Begin() and user call Step(). Does nothing and switch to Step 3.)
|
||||
// - Step 3: the clipper validate that we have reached the expected Y position (corresponding to element DisplayEnd), advance the cursor to the end of the list and then returns 'false' to end the loop.
|
||||
struct ImGuiListClipper
|
||||
{
|
||||
float StartPosY;
|
||||
float ItemsHeight;
|
||||
int ItemsCount, StepNo, DisplayStart, DisplayEnd;
|
||||
|
||||
// items_count: Use -1 to ignore (you can call Begin later). Use INT_MAX if you don't know how many items you have (in which case the cursor won't be advanced in the final step).
|
||||
// items_height: Use -1.0f to be calculated automatically on first step. Otherwise pass in the distance between your items, typically GetTextLineHeightWithSpacing() or GetFrameHeightWithSpacing().
|
||||
// If you don't specify an items_height, you NEED to call Step(). If you specify items_height you may call the old Begin()/End() api directly, but prefer calling Step().
|
||||
ImGuiListClipper(int items_count = -1, float items_height = -1.0f) { Begin(items_count, items_height); } // NB: Begin() initialize every fields (as we allow user to call Begin/End multiple times on a same instance if they want).
|
||||
~ImGuiListClipper() { IM_ASSERT(ItemsCount == -1); } // Assert if user forgot to call End() or Step() until false.
|
||||
|
||||
IMGUI_API bool Step(); // Call until it returns false. The DisplayStart/DisplayEnd fields will be set and you can process/draw those items.
|
||||
IMGUI_API void Begin(int items_count, float items_height = -1.0f); // Automatically called by constructor if you passed 'items_count' or by Step() in Step 1.
|
||||
IMGUI_API void End(); // Automatically called on the last call of Step() that returns false.
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Draw List
|
||||
// Draw List API (ImDrawCmd, ImDrawIdx, ImDrawVert, ImDrawChannel, ImDrawListFlags, ImDrawList, ImDrawData)
|
||||
// Hold a series of drawing commands. The user provides a renderer for ImDrawData which essentially contains an array of ImDrawList.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@ -1794,6 +1839,10 @@ struct ImDrawData
|
||||
IMGUI_API void ScaleClipRects(const ImVec2& sc); // Helper to scale the ClipRect field of each ImDrawCmd. Use if your final output buffer is at a different scale than ImGui expects, or if there is a difference between your window resolution and framebuffer resolution.
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Font API (ImFontConfig, ImFontGlyph, ImFontAtlasFlags, ImFontAtlas, ImFont)
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct ImFontConfig
|
||||
{
|
||||
void* FontData; // // TTF/OTF data
|
||||
|
Loading…
Reference in New Issue
Block a user