diff --git a/lib/external/imgui/include/cimgui.h b/lib/external/imgui/include/cimgui.h index 4bb21ee25..13bc228e9 100644 --- a/lib/external/imgui/include/cimgui.h +++ b/lib/external/imgui/include/cimgui.h @@ -1,6 +1,5 @@ //This file is automatically generated by generator.lua from https://github.com/cimgui/cimgui -//based on imgui.h file version "1.86" from Dear ImGui https://github.com/ocornut/imgui -//with imgui_internal.h api +//based on imgui.h file version "1.89 WIP" from Dear ImGui https://github.com/ocornut/imgui //docking branch #ifndef CIMGUI_INCLUDED #define CIMGUI_INCLUDED @@ -40,97 +39,40 @@ typedef unsigned __int64 ImU64; #ifdef CIMGUI_DEFINE_ENUMS_AND_STRUCTS -typedef struct ImGuiTableColumnSettings ImGuiTableColumnSettings; -typedef struct ImGuiTableCellData ImGuiTableCellData; -typedef struct ImGuiStackTool ImGuiStackTool; -typedef struct ImGuiStackLevelInfo ImGuiStackLevelInfo; -typedef struct ImGuiViewportP ImGuiViewportP; -typedef struct ImGuiWindowDockStyle ImGuiWindowDockStyle; -typedef struct ImGuiListClipperData ImGuiListClipperData; -typedef struct ImGuiListClipperRange ImGuiListClipperRange; -typedef struct ImGuiPtrOrIndex ImGuiPtrOrIndex; -typedef struct ImGuiShrinkWidthItem ImGuiShrinkWidthItem; -typedef struct ImGuiWindowStackData ImGuiWindowStackData; -typedef struct ImGuiComboPreviewData ImGuiComboPreviewData; -typedef struct ImGuiDataTypeTempStorage ImGuiDataTypeTempStorage; -typedef struct ImVec2ih ImVec2ih; -typedef struct ImVec1 ImVec1; -typedef struct StbTexteditRow StbTexteditRow; -typedef struct STB_TexteditState STB_TexteditState; -typedef struct StbUndoState StbUndoState; -typedef struct StbUndoRecord StbUndoRecord; -typedef struct ImGuiWindowSettings ImGuiWindowSettings; -typedef struct ImGuiWindowTempData ImGuiWindowTempData; -typedef struct ImGuiWindow ImGuiWindow; -typedef struct ImGuiTableColumnsSettings ImGuiTableColumnsSettings; -typedef struct ImGuiTableSettings ImGuiTableSettings; -typedef struct ImGuiTableTempData ImGuiTableTempData; -typedef struct ImGuiTableColumn ImGuiTableColumn; -typedef struct ImGuiTable ImGuiTable; -typedef struct ImGuiTabItem ImGuiTabItem; -typedef struct ImGuiTabBar ImGuiTabBar; -typedef struct ImGuiStyleMod ImGuiStyleMod; -typedef struct ImGuiStackSizes ImGuiStackSizes; -typedef struct ImGuiSettingsHandler ImGuiSettingsHandler; -typedef struct ImGuiPopupData ImGuiPopupData; -typedef struct ImGuiOldColumns ImGuiOldColumns; -typedef struct ImGuiOldColumnData ImGuiOldColumnData; -typedef struct ImGuiNextItemData ImGuiNextItemData; -typedef struct ImGuiNextWindowData ImGuiNextWindowData; -typedef struct ImGuiMetricsConfig ImGuiMetricsConfig; -typedef struct ImGuiNavItemData ImGuiNavItemData; -typedef struct ImGuiMenuColumns ImGuiMenuColumns; -typedef struct ImGuiLastItemData ImGuiLastItemData; -typedef struct ImGuiInputTextState ImGuiInputTextState; -typedef struct ImGuiGroupData ImGuiGroupData; -typedef struct ImGuiDockNodeSettings ImGuiDockNodeSettings; -typedef struct ImGuiDockNode ImGuiDockNode; -typedef struct ImGuiDockRequest ImGuiDockRequest; -typedef struct ImGuiDockContext ImGuiDockContext; -typedef struct ImGuiDataTypeInfo ImGuiDataTypeInfo; -typedef struct ImGuiContextHook ImGuiContextHook; -typedef struct ImGuiColorMod ImGuiColorMod; -typedef struct ImDrawDataBuilder ImDrawDataBuilder; -typedef struct ImRect ImRect; -typedef struct ImBitVector ImBitVector; -typedef struct ImFontAtlasCustomRect ImFontAtlasCustomRect; -typedef struct ImDrawCmdHeader ImDrawCmdHeader; -typedef struct ImGuiStoragePair ImGuiStoragePair; -typedef struct ImGuiTextRange ImGuiTextRange; -typedef struct ImVec4 ImVec4; -typedef struct ImVec2 ImVec2; -typedef struct ImGuiWindowClass ImGuiWindowClass; -typedef struct ImGuiViewport ImGuiViewport; -typedef struct ImGuiTextFilter ImGuiTextFilter; -typedef struct ImGuiTextBuffer ImGuiTextBuffer; -typedef struct ImGuiTableColumnSortSpecs ImGuiTableColumnSortSpecs; -typedef struct ImGuiTableSortSpecs ImGuiTableSortSpecs; -typedef struct ImGuiStyle ImGuiStyle; -typedef struct ImGuiStorage ImGuiStorage; -typedef struct ImGuiSizeCallbackData ImGuiSizeCallbackData; -typedef struct ImGuiPlatformMonitor ImGuiPlatformMonitor; -typedef struct ImGuiPlatformIO ImGuiPlatformIO; -typedef struct ImGuiPayload ImGuiPayload; -typedef struct ImGuiOnceUponAFrame ImGuiOnceUponAFrame; -typedef struct ImGuiListClipper ImGuiListClipper; -typedef struct ImGuiInputTextCallbackData ImGuiInputTextCallbackData; -typedef struct ImGuiIO ImGuiIO; -typedef struct ImGuiContext ImGuiContext; -typedef struct ImColor ImColor; -typedef struct ImFontGlyphRangesBuilder ImFontGlyphRangesBuilder; -typedef struct ImFontGlyph ImFontGlyph; -typedef struct ImFontConfig ImFontConfig; -typedef struct ImFontBuilderIO ImFontBuilderIO; -typedef struct ImFontAtlas ImFontAtlas; -typedef struct ImFont ImFont; -typedef struct ImDrawVert ImDrawVert; -typedef struct ImDrawListSplitter ImDrawListSplitter; -typedef struct ImDrawListSharedData ImDrawListSharedData; -typedef struct ImDrawList ImDrawList; -typedef struct ImDrawData ImDrawData; -typedef struct ImDrawCmd ImDrawCmd; -typedef struct ImDrawChannel ImDrawChannel; +typedef struct ImDrawChannel ImDrawChannel; +typedef struct ImDrawCmd ImDrawCmd; +typedef struct ImDrawData ImDrawData; +typedef struct ImDrawList ImDrawList; +typedef struct ImDrawListSharedData ImDrawListSharedData; +typedef struct ImDrawListSplitter ImDrawListSplitter; +typedef struct ImDrawVert ImDrawVert; +typedef struct ImFont ImFont; +typedef struct ImFontAtlas ImFontAtlas; +typedef struct ImFontBuilderIO ImFontBuilderIO; +typedef struct ImFontConfig ImFontConfig; +typedef struct ImFontGlyph ImFontGlyph; +typedef struct ImFontGlyphRangesBuilder ImFontGlyphRangesBuilder; +typedef struct ImColor ImColor; +typedef struct ImGuiContext ImGuiContext; +typedef struct ImGuiIO ImGuiIO; +typedef struct ImGuiInputTextCallbackData ImGuiInputTextCallbackData; +typedef struct ImGuiKeyData ImGuiKeyData; +typedef struct ImGuiListClipper ImGuiListClipper; +typedef struct ImGuiOnceUponAFrame ImGuiOnceUponAFrame; +typedef struct ImGuiPayload ImGuiPayload; +typedef struct ImGuiPlatformIO ImGuiPlatformIO; +typedef struct ImGuiPlatformMonitor ImGuiPlatformMonitor; +typedef struct ImGuiPlatformImeData ImGuiPlatformImeData; +typedef struct ImGuiSizeCallbackData ImGuiSizeCallbackData; +typedef struct ImGuiStorage ImGuiStorage; +typedef struct ImGuiStyle ImGuiStyle; +typedef struct ImGuiTableSortSpecs ImGuiTableSortSpecs; +typedef struct ImGuiTableColumnSortSpecs ImGuiTableColumnSortSpecs; +typedef struct ImGuiTextBuffer ImGuiTextBuffer; +typedef struct ImGuiTextFilter ImGuiTextFilter; +typedef struct ImGuiViewport ImGuiViewport; +typedef struct ImGuiWindowClass ImGuiWindowClass; struct ImDrawChannel; struct ImDrawCmd; struct ImDrawData; @@ -148,11 +90,13 @@ struct ImColor; struct ImGuiContext; struct ImGuiIO; struct ImGuiInputTextCallbackData; +struct ImGuiKeyData; struct ImGuiListClipper; struct ImGuiOnceUponAFrame; struct ImGuiPayload; struct ImGuiPlatformIO; struct ImGuiPlatformMonitor; +struct ImGuiPlatformImeData; struct ImGuiSizeCallbackData; struct ImGuiStorage; struct ImGuiStyle; @@ -167,7 +111,6 @@ typedef int ImGuiCond; typedef int ImGuiDataType; typedef int ImGuiDir; typedef int ImGuiKey; -typedef int ImGuiNavInput; typedef int ImGuiMouseButton; typedef int ImGuiMouseCursor; typedef int ImGuiSortDirection; @@ -186,7 +129,7 @@ typedef int ImGuiDragDropFlags; typedef int ImGuiFocusedFlags; typedef int ImGuiHoveredFlags; typedef int ImGuiInputTextFlags; -typedef int ImGuiKeyModFlags; +typedef int ImGuiModFlags; typedef int ImGuiPopupFlags; typedef int ImGuiSelectableFlags; typedef int ImGuiSliderFlags; @@ -207,8 +150,8 @@ typedef signed short ImS16; typedef unsigned short ImU16; typedef signed int ImS32; typedef unsigned int ImU32; -typedef int64_t ImS64; -typedef uint64_t ImU64; +typedef signed long long ImS64; +typedef unsigned long long ImU64; typedef unsigned short ImWchar16; typedef unsigned int ImWchar32; typedef ImWchar16 ImWchar; @@ -216,123 +159,12 @@ typedef int (*ImGuiInputTextCallback)(ImGuiInputTextCallbackData* data); typedef void (*ImGuiSizeCallback)(ImGuiSizeCallbackData* data); typedef void* (*ImGuiMemAllocFunc)(size_t sz, void* user_data); typedef void (*ImGuiMemFreeFunc)(void* ptr, void* user_data); -typedef void (*ImDrawCallback)(const ImDrawList* parent_list, const ImDrawCmd* cmd); -struct ImBitVector; -struct ImRect; -struct ImDrawDataBuilder; -struct ImDrawListSharedData; -struct ImGuiColorMod; -struct ImGuiContext; -struct ImGuiContextHook; -struct ImGuiDataTypeInfo; -struct ImGuiDockContext; -struct ImGuiDockRequest; -struct ImGuiDockNode; -struct ImGuiDockNodeSettings; -struct ImGuiGroupData; -struct ImGuiInputTextState; -struct ImGuiLastItemData; -struct ImGuiMenuColumns; -struct ImGuiNavItemData; -struct ImGuiMetricsConfig; -struct ImGuiNextWindowData; -struct ImGuiNextItemData; -struct ImGuiOldColumnData; -struct ImGuiOldColumns; -struct ImGuiPopupData; -struct ImGuiSettingsHandler; -struct ImGuiStackSizes; -struct ImGuiStyleMod; -struct ImGuiTabBar; -struct ImGuiTabItem; -struct ImGuiTable; -struct ImGuiTableColumn; -struct ImGuiTableTempData; -struct ImGuiTableSettings; -struct ImGuiTableColumnsSettings; -struct ImGuiWindow; -struct ImGuiWindowTempData; -struct ImGuiWindowSettings; -typedef int ImGuiDataAuthority; -typedef int ImGuiLayoutType; -typedef int ImGuiActivateFlags; -typedef int ImGuiItemFlags; -typedef int ImGuiItemStatusFlags; -typedef int ImGuiOldColumnFlags; -typedef int ImGuiNavHighlightFlags; -typedef int ImGuiNavDirSourceFlags; -typedef int ImGuiNavMoveFlags; -typedef int ImGuiNextItemDataFlags; -typedef int ImGuiNextWindowDataFlags; -typedef int ImGuiScrollFlags; -typedef int ImGuiSeparatorFlags; -typedef int ImGuiTextFlags; -typedef int ImGuiTooltipFlags; -typedef void (*ImGuiErrorLogCallback)(void* user_data, const char* fmt, ...); -extern ImGuiContext* GImGui; -typedef FILE* ImFileHandle; -typedef int ImPoolIdx; -typedef void (*ImGuiContextHookCallback)(ImGuiContext* ctx, ImGuiContextHook* hook); -typedef ImS8 ImGuiTableColumnIdx; -typedef ImU8 ImGuiTableDrawChannelIdx; -typedef struct ImVector{int Size;int Capacity;void* Data;} ImVector; -typedef struct ImVector_ImGuiTableSettings {int Size;int Capacity;ImGuiTableSettings* Data;} ImVector_ImGuiTableSettings; -typedef struct ImChunkStream_ImGuiTableSettings {ImVector_ImGuiTableSettings Buf;} ImChunkStream_ImGuiTableSettings; -typedef struct ImVector_ImGuiWindowSettings {int Size;int Capacity;ImGuiWindowSettings* Data;} ImVector_ImGuiWindowSettings; -typedef struct ImChunkStream_ImGuiWindowSettings {ImVector_ImGuiWindowSettings Buf;} ImChunkStream_ImGuiWindowSettings; -typedef struct ImSpan_ImGuiTableCellData {ImGuiTableCellData* Data;ImGuiTableCellData* DataEnd;} ImSpan_ImGuiTableCellData; -typedef struct ImSpan_ImGuiTableColumn {ImGuiTableColumn* Data;ImGuiTableColumn* DataEnd;} ImSpan_ImGuiTableColumn; -typedef struct ImSpan_ImGuiTableColumnIdx {ImGuiTableColumnIdx* Data;ImGuiTableColumnIdx* DataEnd;} ImSpan_ImGuiTableColumnIdx; -typedef struct ImVector_ImDrawChannel {int Size;int Capacity;ImDrawChannel* Data;} ImVector_ImDrawChannel; -typedef struct ImVector_ImDrawCmd {int Size;int Capacity;ImDrawCmd* Data;} ImVector_ImDrawCmd; -typedef struct ImVector_ImDrawIdx {int Size;int Capacity;ImDrawIdx* Data;} ImVector_ImDrawIdx; -typedef struct ImVector_ImDrawListPtr {int Size;int Capacity;ImDrawList** Data;} ImVector_ImDrawListPtr; -typedef struct ImVector_ImDrawVert {int Size;int Capacity;ImDrawVert* Data;} ImVector_ImDrawVert; -typedef struct ImVector_ImFontPtr {int Size;int Capacity;ImFont** Data;} ImVector_ImFontPtr; -typedef struct ImVector_ImFontAtlasCustomRect {int Size;int Capacity;ImFontAtlasCustomRect* Data;} ImVector_ImFontAtlasCustomRect; -typedef struct ImVector_ImFontConfig {int Size;int Capacity;ImFontConfig* Data;} ImVector_ImFontConfig; -typedef struct ImVector_ImFontGlyph {int Size;int Capacity;ImFontGlyph* Data;} ImVector_ImFontGlyph; -typedef struct ImVector_ImGuiColorMod {int Size;int Capacity;ImGuiColorMod* Data;} ImVector_ImGuiColorMod; -typedef struct ImVector_ImGuiContextHook {int Size;int Capacity;ImGuiContextHook* Data;} ImVector_ImGuiContextHook; -typedef struct ImVector_ImGuiDockNodeSettings {int Size;int Capacity;ImGuiDockNodeSettings* Data;} ImVector_ImGuiDockNodeSettings; -typedef struct ImVector_ImGuiDockRequest {int Size;int Capacity;ImGuiDockRequest* Data;} ImVector_ImGuiDockRequest; -typedef struct ImVector_ImGuiGroupData {int Size;int Capacity;ImGuiGroupData* Data;} ImVector_ImGuiGroupData; -typedef struct ImVector_ImGuiID {int Size;int Capacity;ImGuiID* Data;} ImVector_ImGuiID; -typedef struct ImVector_ImGuiItemFlags {int Size;int Capacity;ImGuiItemFlags* Data;} ImVector_ImGuiItemFlags; -typedef struct ImVector_ImGuiListClipperData {int Size;int Capacity;ImGuiListClipperData* Data;} ImVector_ImGuiListClipperData; -typedef struct ImVector_ImGuiListClipperRange {int Size;int Capacity;ImGuiListClipperRange* Data;} ImVector_ImGuiListClipperRange; -typedef struct ImVector_ImGuiOldColumnData {int Size;int Capacity;ImGuiOldColumnData* Data;} ImVector_ImGuiOldColumnData; -typedef struct ImVector_ImGuiOldColumns {int Size;int Capacity;ImGuiOldColumns* Data;} ImVector_ImGuiOldColumns; -typedef struct ImVector_ImGuiPlatformMonitor {int Size;int Capacity;ImGuiPlatformMonitor* Data;} ImVector_ImGuiPlatformMonitor; -typedef struct ImVector_ImGuiPopupData {int Size;int Capacity;ImGuiPopupData* Data;} ImVector_ImGuiPopupData; -typedef struct ImVector_ImGuiPtrOrIndex {int Size;int Capacity;ImGuiPtrOrIndex* Data;} ImVector_ImGuiPtrOrIndex; -typedef struct ImVector_ImGuiSettingsHandler {int Size;int Capacity;ImGuiSettingsHandler* Data;} ImVector_ImGuiSettingsHandler; -typedef struct ImVector_ImGuiShrinkWidthItem {int Size;int Capacity;ImGuiShrinkWidthItem* Data;} ImVector_ImGuiShrinkWidthItem; -typedef struct ImVector_ImGuiStackLevelInfo {int Size;int Capacity;ImGuiStackLevelInfo* Data;} ImVector_ImGuiStackLevelInfo; -typedef struct ImVector_ImGuiStoragePair {int Size;int Capacity;ImGuiStoragePair* Data;} ImVector_ImGuiStoragePair; -typedef struct ImVector_ImGuiStyleMod {int Size;int Capacity;ImGuiStyleMod* Data;} ImVector_ImGuiStyleMod; -typedef struct ImVector_ImGuiTabItem {int Size;int Capacity;ImGuiTabItem* Data;} ImVector_ImGuiTabItem; -typedef struct ImVector_ImGuiTableColumnSortSpecs {int Size;int Capacity;ImGuiTableColumnSortSpecs* Data;} ImVector_ImGuiTableColumnSortSpecs; -typedef struct ImVector_ImGuiTableTempData {int Size;int Capacity;ImGuiTableTempData* Data;} ImVector_ImGuiTableTempData; -typedef struct ImVector_ImGuiTextRange {int Size;int Capacity;ImGuiTextRange* Data;} ImVector_ImGuiTextRange; -typedef struct ImVector_ImGuiViewportPtr {int Size;int Capacity;ImGuiViewport** Data;} ImVector_ImGuiViewportPtr; -typedef struct ImVector_ImGuiViewportPPtr {int Size;int Capacity;ImGuiViewportP** Data;} ImVector_ImGuiViewportPPtr; -typedef struct ImVector_ImGuiWindowPtr {int Size;int Capacity;ImGuiWindow** Data;} ImVector_ImGuiWindowPtr; -typedef struct ImVector_ImGuiWindowStackData {int Size;int Capacity;ImGuiWindowStackData* Data;} ImVector_ImGuiWindowStackData; -typedef struct ImVector_ImTextureID {int Size;int Capacity;ImTextureID* Data;} ImVector_ImTextureID; -typedef struct ImVector_ImU32 {int Size;int Capacity;ImU32* Data;} ImVector_ImU32; -typedef struct ImVector_ImVec2 {int Size;int Capacity;ImVec2* Data;} ImVector_ImVec2; -typedef struct ImVector_ImVec4 {int Size;int Capacity;ImVec4* Data;} ImVector_ImVec4; -typedef struct ImVector_ImWchar {int Size;int Capacity;ImWchar* Data;} ImVector_ImWchar; -typedef struct ImVector_char {int Size;int Capacity;char* Data;} ImVector_char; -typedef struct ImVector_const_charPtr {int Size;int Capacity;const char** Data;} ImVector_const_charPtr; -typedef struct ImVector_float {int Size;int Capacity;float* Data;} ImVector_float; -typedef struct ImVector_unsigned_char {int Size;int Capacity;unsigned char* Data;} ImVector_unsigned_char; - +typedef struct ImVec2 ImVec2; struct ImVec2 { float x, y; }; +typedef struct ImVec4 ImVec4; struct ImVec4 { float x, y, z, w; @@ -369,7 +201,7 @@ typedef enum { ImGuiWindowFlags_Popup = 1 << 26, ImGuiWindowFlags_Modal = 1 << 27, ImGuiWindowFlags_ChildMenu = 1 << 28, - ImGuiWindowFlags_DockNodeHost = 1 << 29 + ImGuiWindowFlags_DockNodeHost = 1 << 29, }ImGuiWindowFlags_; typedef enum { ImGuiInputTextFlags_None = 0, @@ -392,7 +224,7 @@ typedef enum { ImGuiInputTextFlags_NoUndoRedo = 1 << 16, ImGuiInputTextFlags_CharsScientific = 1 << 17, ImGuiInputTextFlags_CallbackResize = 1 << 18, - ImGuiInputTextFlags_CallbackEdit = 1 << 19 + ImGuiInputTextFlags_CallbackEdit = 1 << 19, }ImGuiInputTextFlags_; typedef enum { ImGuiTreeNodeFlags_None = 0, @@ -410,7 +242,7 @@ typedef enum { ImGuiTreeNodeFlags_SpanAvailWidth = 1 << 11, ImGuiTreeNodeFlags_SpanFullWidth = 1 << 12, ImGuiTreeNodeFlags_NavLeftJumpsBackHere = 1 << 13, - ImGuiTreeNodeFlags_CollapsingHeader = ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_NoAutoOpenOnLog + ImGuiTreeNodeFlags_CollapsingHeader = ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_NoAutoOpenOnLog, }ImGuiTreeNodeFlags_; typedef enum { ImGuiPopupFlags_None = 0, @@ -423,7 +255,7 @@ typedef enum { ImGuiPopupFlags_NoOpenOverItems = 1 << 6, ImGuiPopupFlags_AnyPopupId = 1 << 7, ImGuiPopupFlags_AnyPopupLevel = 1 << 8, - ImGuiPopupFlags_AnyPopup = ImGuiPopupFlags_AnyPopupId | ImGuiPopupFlags_AnyPopupLevel + ImGuiPopupFlags_AnyPopup = ImGuiPopupFlags_AnyPopupId | ImGuiPopupFlags_AnyPopupLevel, }ImGuiPopupFlags_; typedef enum { ImGuiSelectableFlags_None = 0, @@ -431,7 +263,7 @@ typedef enum { ImGuiSelectableFlags_SpanAllColumns = 1 << 1, ImGuiSelectableFlags_AllowDoubleClick = 1 << 2, ImGuiSelectableFlags_Disabled = 1 << 3, - ImGuiSelectableFlags_AllowItemOverlap = 1 << 4 + ImGuiSelectableFlags_AllowItemOverlap = 1 << 4, }ImGuiSelectableFlags_; typedef enum { ImGuiComboFlags_None = 0, @@ -442,7 +274,7 @@ typedef enum { ImGuiComboFlags_HeightLargest = 1 << 4, ImGuiComboFlags_NoArrowButton = 1 << 5, ImGuiComboFlags_NoPreview = 1 << 6, - ImGuiComboFlags_HeightMask_ = ImGuiComboFlags_HeightSmall | ImGuiComboFlags_HeightRegular | ImGuiComboFlags_HeightLarge | ImGuiComboFlags_HeightLargest + ImGuiComboFlags_HeightMask_ = ImGuiComboFlags_HeightSmall | ImGuiComboFlags_HeightRegular | ImGuiComboFlags_HeightLarge | ImGuiComboFlags_HeightLargest, }ImGuiComboFlags_; typedef enum { ImGuiTabBarFlags_None = 0, @@ -455,7 +287,7 @@ typedef enum { ImGuiTabBarFlags_FittingPolicyResizeDown = 1 << 6, ImGuiTabBarFlags_FittingPolicyScroll = 1 << 7, ImGuiTabBarFlags_FittingPolicyMask_ = ImGuiTabBarFlags_FittingPolicyResizeDown | ImGuiTabBarFlags_FittingPolicyScroll, - ImGuiTabBarFlags_FittingPolicyDefault_ = ImGuiTabBarFlags_FittingPolicyResizeDown + ImGuiTabBarFlags_FittingPolicyDefault_ = ImGuiTabBarFlags_FittingPolicyResizeDown, }ImGuiTabBarFlags_; typedef enum { ImGuiTabItemFlags_None = 0, @@ -466,7 +298,7 @@ typedef enum { ImGuiTabItemFlags_NoTooltip = 1 << 4, ImGuiTabItemFlags_NoReorder = 1 << 5, ImGuiTabItemFlags_Leading = 1 << 6, - ImGuiTabItemFlags_Trailing = 1 << 7 + ImGuiTabItemFlags_Trailing = 1 << 7, }ImGuiTabItemFlags_; typedef enum { ImGuiTableFlags_None = 0, @@ -504,7 +336,7 @@ typedef enum { ImGuiTableFlags_ScrollY = 1 << 25, ImGuiTableFlags_SortMulti = 1 << 26, ImGuiTableFlags_SortTristate = 1 << 27, - ImGuiTableFlags_SizingMask_ = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_SizingFixedSame | ImGuiTableFlags_SizingStretchProp | ImGuiTableFlags_SizingStretchSame + ImGuiTableFlags_SizingMask_ = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_SizingFixedSame | ImGuiTableFlags_SizingStretchProp | ImGuiTableFlags_SizingStretchSame, }ImGuiTableFlags_; typedef enum { ImGuiTableColumnFlags_None = 0, @@ -533,17 +365,17 @@ typedef enum { ImGuiTableColumnFlags_WidthMask_ = ImGuiTableColumnFlags_WidthStretch | ImGuiTableColumnFlags_WidthFixed, ImGuiTableColumnFlags_IndentMask_ = ImGuiTableColumnFlags_IndentEnable | ImGuiTableColumnFlags_IndentDisable, ImGuiTableColumnFlags_StatusMask_ = ImGuiTableColumnFlags_IsEnabled | ImGuiTableColumnFlags_IsVisible | ImGuiTableColumnFlags_IsSorted | ImGuiTableColumnFlags_IsHovered, - ImGuiTableColumnFlags_NoDirectResize_ = 1 << 30 + ImGuiTableColumnFlags_NoDirectResize_ = 1 << 30, }ImGuiTableColumnFlags_; typedef enum { ImGuiTableRowFlags_None = 0, - ImGuiTableRowFlags_Headers = 1 << 0 + ImGuiTableRowFlags_Headers = 1 << 0, }ImGuiTableRowFlags_; typedef enum { ImGuiTableBgTarget_None = 0, ImGuiTableBgTarget_RowBg0 = 1, ImGuiTableBgTarget_RowBg1 = 2, - ImGuiTableBgTarget_CellBg = 3 + ImGuiTableBgTarget_CellBg = 3, }ImGuiTableBgTarget_; typedef enum { ImGuiFocusedFlags_None = 0, @@ -552,7 +384,7 @@ typedef enum { ImGuiFocusedFlags_AnyWindow = 1 << 2, ImGuiFocusedFlags_NoPopupHierarchy = 1 << 3, ImGuiFocusedFlags_DockHierarchy = 1 << 4, - ImGuiFocusedFlags_RootAndChildWindows = ImGuiFocusedFlags_RootWindow | ImGuiFocusedFlags_ChildWindows + ImGuiFocusedFlags_RootAndChildWindows = ImGuiFocusedFlags_RootWindow | ImGuiFocusedFlags_ChildWindows, }ImGuiFocusedFlags_; typedef enum { ImGuiHoveredFlags_None = 0, @@ -565,8 +397,9 @@ typedef enum { ImGuiHoveredFlags_AllowWhenBlockedByActiveItem = 1 << 7, ImGuiHoveredFlags_AllowWhenOverlapped = 1 << 8, ImGuiHoveredFlags_AllowWhenDisabled = 1 << 9, + ImGuiHoveredFlags_NoNavOverride = 1 << 10, ImGuiHoveredFlags_RectOnly = ImGuiHoveredFlags_AllowWhenBlockedByPopup | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem | ImGuiHoveredFlags_AllowWhenOverlapped, - ImGuiHoveredFlags_RootAndChildWindows = ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows + ImGuiHoveredFlags_RootAndChildWindows = ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows, }ImGuiHoveredFlags_; typedef enum { ImGuiDockNodeFlags_None = 0, @@ -575,7 +408,7 @@ typedef enum { ImGuiDockNodeFlags_PassthruCentralNode = 1 << 3, ImGuiDockNodeFlags_NoSplit = 1 << 4, ImGuiDockNodeFlags_NoResize = 1 << 5, - ImGuiDockNodeFlags_AutoHideTabBar = 1 << 6 + ImGuiDockNodeFlags_AutoHideTabBar = 1 << 6, }ImGuiDockNodeFlags_; typedef enum { ImGuiDragDropFlags_None = 0, @@ -588,7 +421,7 @@ typedef enum { ImGuiDragDropFlags_AcceptBeforeDelivery = 1 << 10, ImGuiDragDropFlags_AcceptNoDrawDefaultRect = 1 << 11, ImGuiDragDropFlags_AcceptNoPreviewTooltip = 1 << 12, - ImGuiDragDropFlags_AcceptPeekOnly = ImGuiDragDropFlags_AcceptBeforeDelivery | ImGuiDragDropFlags_AcceptNoDrawDefaultRect + ImGuiDragDropFlags_AcceptPeekOnly = ImGuiDragDropFlags_AcceptBeforeDelivery | ImGuiDragDropFlags_AcceptNoDrawDefaultRect, }ImGuiDragDropFlags_; typedef enum { ImGuiDataType_S8, @@ -617,7 +450,8 @@ typedef enum { ImGuiSortDirection_Descending = 2 }ImGuiSortDirection_; typedef enum { - ImGuiKey_Tab, + ImGuiKey_None = 0, + ImGuiKey_Tab = 512, ImGuiKey_LeftArrow, ImGuiKey_RightArrow, ImGuiKey_UpArrow, @@ -632,46 +466,86 @@ typedef enum { ImGuiKey_Space, ImGuiKey_Enter, ImGuiKey_Escape, - ImGuiKey_KeyPadEnter, - ImGuiKey_A, - ImGuiKey_C, - ImGuiKey_V, - ImGuiKey_X, - ImGuiKey_Y, - ImGuiKey_Z, - ImGuiKey_COUNT + ImGuiKey_LeftCtrl, ImGuiKey_LeftShift, ImGuiKey_LeftAlt, ImGuiKey_LeftSuper, + ImGuiKey_RightCtrl, ImGuiKey_RightShift, ImGuiKey_RightAlt, ImGuiKey_RightSuper, + ImGuiKey_Menu, + ImGuiKey_0, ImGuiKey_1, ImGuiKey_2, ImGuiKey_3, ImGuiKey_4, ImGuiKey_5, ImGuiKey_6, ImGuiKey_7, ImGuiKey_8, ImGuiKey_9, + ImGuiKey_A, ImGuiKey_B, ImGuiKey_C, ImGuiKey_D, ImGuiKey_E, ImGuiKey_F, ImGuiKey_G, ImGuiKey_H, ImGuiKey_I, ImGuiKey_J, + ImGuiKey_K, ImGuiKey_L, ImGuiKey_M, ImGuiKey_N, ImGuiKey_O, ImGuiKey_P, ImGuiKey_Q, ImGuiKey_R, ImGuiKey_S, ImGuiKey_T, + ImGuiKey_U, ImGuiKey_V, ImGuiKey_W, ImGuiKey_X, ImGuiKey_Y, ImGuiKey_Z, + ImGuiKey_F1, ImGuiKey_F2, ImGuiKey_F3, ImGuiKey_F4, ImGuiKey_F5, ImGuiKey_F6, + ImGuiKey_F7, ImGuiKey_F8, ImGuiKey_F9, ImGuiKey_F10, ImGuiKey_F11, ImGuiKey_F12, + ImGuiKey_Apostrophe, + ImGuiKey_Comma, + ImGuiKey_Minus, + ImGuiKey_Period, + ImGuiKey_Slash, + ImGuiKey_Semicolon, + ImGuiKey_Equal, + ImGuiKey_LeftBracket, + ImGuiKey_Backslash, + ImGuiKey_RightBracket, + ImGuiKey_GraveAccent, + ImGuiKey_CapsLock, + ImGuiKey_ScrollLock, + ImGuiKey_NumLock, + ImGuiKey_PrintScreen, + ImGuiKey_Pause, + ImGuiKey_Keypad0, ImGuiKey_Keypad1, ImGuiKey_Keypad2, ImGuiKey_Keypad3, ImGuiKey_Keypad4, + ImGuiKey_Keypad5, ImGuiKey_Keypad6, ImGuiKey_Keypad7, ImGuiKey_Keypad8, ImGuiKey_Keypad9, + ImGuiKey_KeypadDecimal, + ImGuiKey_KeypadDivide, + ImGuiKey_KeypadMultiply, + ImGuiKey_KeypadSubtract, + ImGuiKey_KeypadAdd, + ImGuiKey_KeypadEnter, + ImGuiKey_KeypadEqual, + ImGuiKey_GamepadStart, + ImGuiKey_GamepadBack, + ImGuiKey_GamepadFaceLeft, + ImGuiKey_GamepadFaceRight, + ImGuiKey_GamepadFaceUp, + ImGuiKey_GamepadFaceDown, + ImGuiKey_GamepadDpadLeft, + ImGuiKey_GamepadDpadRight, + ImGuiKey_GamepadDpadUp, + ImGuiKey_GamepadDpadDown, + ImGuiKey_GamepadL1, + ImGuiKey_GamepadR1, + ImGuiKey_GamepadL2, + ImGuiKey_GamepadR2, + ImGuiKey_GamepadL3, + ImGuiKey_GamepadR3, + ImGuiKey_GamepadLStickLeft, + ImGuiKey_GamepadLStickRight, + ImGuiKey_GamepadLStickUp, + ImGuiKey_GamepadLStickDown, + ImGuiKey_GamepadRStickLeft, + ImGuiKey_GamepadRStickRight, + ImGuiKey_GamepadRStickUp, + ImGuiKey_GamepadRStickDown, + ImGuiKey_ModCtrl, ImGuiKey_ModShift, ImGuiKey_ModAlt, ImGuiKey_ModSuper, + ImGuiKey_MouseLeft, ImGuiKey_MouseRight, ImGuiKey_MouseMiddle, ImGuiKey_MouseX1, ImGuiKey_MouseX2, ImGuiKey_MouseWheelX, ImGuiKey_MouseWheelY, + ImGuiKey_COUNT, + ImGuiKey_NamedKey_BEGIN = 512, + ImGuiKey_NamedKey_END = ImGuiKey_COUNT, + ImGuiKey_NamedKey_COUNT = ImGuiKey_NamedKey_END - ImGuiKey_NamedKey_BEGIN, + ImGuiKey_KeysData_SIZE = ImGuiKey_COUNT, + ImGuiKey_KeysData_OFFSET = 0, }ImGuiKey_; typedef enum { - ImGuiKeyModFlags_None = 0, - ImGuiKeyModFlags_Ctrl = 1 << 0, - ImGuiKeyModFlags_Shift = 1 << 1, - ImGuiKeyModFlags_Alt = 1 << 2, - ImGuiKeyModFlags_Super = 1 << 3 -}ImGuiKeyModFlags_; + ImGuiModFlags_None = 0, + ImGuiModFlags_Ctrl = 1 << 0, + ImGuiModFlags_Shift = 1 << 1, + ImGuiModFlags_Alt = 1 << 2, + ImGuiModFlags_Super = 1 << 3, + ImGuiModFlags_All = 0x0F +}ImGuiModFlags_; typedef enum { - ImGuiNavInput_Activate, - ImGuiNavInput_Cancel, - ImGuiNavInput_Input, - ImGuiNavInput_Menu, - ImGuiNavInput_DpadLeft, - ImGuiNavInput_DpadRight, - ImGuiNavInput_DpadUp, - ImGuiNavInput_DpadDown, - ImGuiNavInput_LStickLeft, - ImGuiNavInput_LStickRight, - ImGuiNavInput_LStickUp, - ImGuiNavInput_LStickDown, - ImGuiNavInput_FocusPrev, - ImGuiNavInput_FocusNext, - ImGuiNavInput_TweakSlow, - ImGuiNavInput_TweakFast, - ImGuiNavInput_KeyLeft_, - ImGuiNavInput_KeyRight_, - ImGuiNavInput_KeyUp_, - ImGuiNavInput_KeyDown_, + ImGuiNavInput_Activate, ImGuiNavInput_Cancel, ImGuiNavInput_Input, ImGuiNavInput_Menu, ImGuiNavInput_DpadLeft, ImGuiNavInput_DpadRight, ImGuiNavInput_DpadUp, ImGuiNavInput_DpadDown, + ImGuiNavInput_LStickLeft, ImGuiNavInput_LStickRight, ImGuiNavInput_LStickUp, ImGuiNavInput_LStickDown, ImGuiNavInput_FocusPrev, ImGuiNavInput_FocusNext, ImGuiNavInput_TweakSlow, ImGuiNavInput_TweakFast, ImGuiNavInput_COUNT, - ImGuiNavInput_InternalStart_ = ImGuiNavInput_KeyLeft_ -}ImGuiNavInput_; +}ImGuiNavInput; typedef enum { ImGuiConfigFlags_None = 0, ImGuiConfigFlags_NavEnableKeyboard = 1 << 0, @@ -685,7 +559,7 @@ typedef enum { ImGuiConfigFlags_DpiEnableScaleViewports= 1 << 14, ImGuiConfigFlags_DpiEnableScaleFonts = 1 << 15, ImGuiConfigFlags_IsSRGB = 1 << 20, - ImGuiConfigFlags_IsTouchScreen = 1 << 21 + ImGuiConfigFlags_IsTouchScreen = 1 << 21, }ImGuiConfigFlags_; typedef enum { ImGuiBackendFlags_None = 0, @@ -695,7 +569,7 @@ typedef enum { ImGuiBackendFlags_RendererHasVtxOffset = 1 << 3, ImGuiBackendFlags_PlatformHasViewports = 1 << 10, ImGuiBackendFlags_HasMouseHoveredViewport=1 << 11, - ImGuiBackendFlags_RendererHasViewports = 1 << 12 + ImGuiBackendFlags_RendererHasViewports = 1 << 12, }ImGuiBackendFlags_; typedef enum { ImGuiCol_Text, @@ -789,7 +663,7 @@ typedef enum { ImGuiButtonFlags_MouseButtonRight = 1 << 1, ImGuiButtonFlags_MouseButtonMiddle = 1 << 2, ImGuiButtonFlags_MouseButtonMask_ = ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight | ImGuiButtonFlags_MouseButtonMiddle, - ImGuiButtonFlags_MouseButtonDefault_ = ImGuiButtonFlags_MouseButtonLeft + ImGuiButtonFlags_MouseButtonDefault_ = ImGuiButtonFlags_MouseButtonLeft, }ImGuiButtonFlags_; typedef enum { ImGuiColorEditFlags_None = 0, @@ -820,7 +694,7 @@ typedef enum { ImGuiColorEditFlags_DisplayMask_ = ImGuiColorEditFlags_DisplayRGB | ImGuiColorEditFlags_DisplayHSV | ImGuiColorEditFlags_DisplayHex, ImGuiColorEditFlags_DataTypeMask_ = ImGuiColorEditFlags_Uint8 | ImGuiColorEditFlags_Float, ImGuiColorEditFlags_PickerMask_ = ImGuiColorEditFlags_PickerHueWheel | ImGuiColorEditFlags_PickerHueBar, - ImGuiColorEditFlags_InputMask_ = ImGuiColorEditFlags_InputRGB | ImGuiColorEditFlags_InputHSV + ImGuiColorEditFlags_InputMask_ = ImGuiColorEditFlags_InputRGB | ImGuiColorEditFlags_InputHSV, }ImGuiColorEditFlags_; typedef enum { ImGuiSliderFlags_None = 0, @@ -828,7 +702,7 @@ typedef enum { ImGuiSliderFlags_Logarithmic = 1 << 5, ImGuiSliderFlags_NoRoundToFormat = 1 << 6, ImGuiSliderFlags_NoInput = 1 << 7, - ImGuiSliderFlags_InvalidMask_ = 0x7000000F + ImGuiSliderFlags_InvalidMask_ = 0x7000000F, }ImGuiSliderFlags_; typedef enum { ImGuiMouseButton_Left = 0, @@ -854,7 +728,7 @@ typedef enum { ImGuiCond_Always = 1 << 0, ImGuiCond_Once = 1 << 1, ImGuiCond_FirstUseEver = 1 << 2, - ImGuiCond_Appearing = 1 << 3 + ImGuiCond_Appearing = 1 << 3, }ImGuiCond_; struct ImGuiStyle { @@ -900,6 +774,15 @@ struct ImGuiStyle float CircleTessellationMaxError; ImVec4 Colors[ImGuiCol_COUNT]; }; +struct ImGuiKeyData +{ + bool Down; + float DownDuration; + float DownDurationPrev; + float AnalogValue; +}; +typedef struct ImVector_ImWchar {int Size;int Capacity;ImWchar* Data;} ImVector_ImWchar; + struct ImGuiIO { ImGuiConfigFlags ConfigFlags; @@ -912,7 +795,6 @@ struct ImGuiIO float MouseDoubleClickTime; float MouseDoubleClickMaxDist; float MouseDragThreshold; - int KeyMap[ImGuiKey_COUNT]; float KeyRepeatDelay; float KeyRepeatRate; void* UserData; @@ -931,7 +813,9 @@ struct ImGuiIO bool ConfigViewportsNoDefaultParent; bool MouseDrawCursor; bool ConfigMacOSXBehaviors; + bool ConfigInputTrickleEventQueue; bool ConfigInputTextCursorBlink; + bool ConfigInputTextEnterKeepActive; bool ConfigDragClickToInputText; bool ConfigWindowsResizeFromEdges; bool ConfigWindowsMoveFromTitleBarOnly; @@ -944,17 +828,8 @@ struct ImGuiIO const char* (*GetClipboardTextFn)(void* user_data); void (*SetClipboardTextFn)(void* user_data, const char* text); void* ClipboardUserData; - ImVec2 MousePos; - bool MouseDown[5]; - float MouseWheel; - float MouseWheelH; - ImGuiID MouseHoveredViewport; - bool KeyCtrl; - bool KeyShift; - bool KeyAlt; - bool KeySuper; - bool KeysDown[512]; - float NavInputs[ImGuiNavInput_COUNT]; + void (*SetPlatformImeDataFn)(ImGuiViewport* viewport, ImGuiPlatformImeData* data); + void* _UnusedPadding; bool WantCaptureMouse; bool WantCaptureKeyboard; bool WantTextInput; @@ -969,9 +844,21 @@ struct ImGuiIO int MetricsActiveWindows; int MetricsActiveAllocations; ImVec2 MouseDelta; + int KeyMap[ImGuiKey_COUNT]; + bool KeysDown[ImGuiKey_COUNT]; + float NavInputs[ImGuiNavInput_COUNT]; + ImVec2 MousePos; + bool MouseDown[5]; + float MouseWheel; + float MouseWheelH; + ImGuiID MouseHoveredViewport; + bool KeyCtrl; + bool KeyShift; + bool KeyAlt; + bool KeySuper; + ImGuiModFlags KeyMods; + ImGuiKeyData KeysData[ImGuiKey_KeysData_SIZE]; bool WantCaptureMouseUnlessPopupClose; - ImGuiKeyModFlags KeyMods; - ImGuiKeyModFlags KeyModsPrev; ImVec2 MousePosPrev; ImVec2 MouseClickedPos[5]; double MouseClickedTime[5]; @@ -986,12 +873,11 @@ struct ImGuiIO float MouseDownDurationPrev[5]; ImVec2 MouseDragMaxDistanceAbs[5]; float MouseDragMaxDistanceSqr[5]; - float KeysDownDuration[512]; - float KeysDownDurationPrev[512]; - float NavInputsDownDuration[ImGuiNavInput_COUNT]; - float NavInputsDownDurationPrev[ImGuiNavInput_COUNT]; float PenPressure; bool AppFocusLost; + bool AppAcceptingEvents; + ImS8 BackendUsingLegacyKeyArrays; + bool BackendUsingLegacyNavInputArray; ImWchar16 InputQueueSurrogate; ImVector_ImWchar InputQueueCharacters; }; @@ -1061,12 +947,19 @@ struct ImGuiTextRange const char* b; const char* e; }; +typedef struct ImGuiTextRange ImGuiTextRange; + +typedef struct ImVector_ImGuiTextRange {int Size;int Capacity;ImGuiTextRange* Data;} ImVector_ImGuiTextRange; + struct ImGuiTextFilter { char InputBuf[256]; ImVector_ImGuiTextRange Filters; int CountGrep; }; +typedef struct ImGuiTextRange ImGuiTextRange; +typedef struct ImVector_char {int Size;int Capacity;char* Data;} ImVector_char; + struct ImGuiTextBuffer { ImVector_char Buf; @@ -1076,14 +969,15 @@ struct ImGuiStoragePair ImGuiID key; union { int val_i; float val_f; void* val_p; }; }; +typedef struct ImGuiStoragePair ImGuiStoragePair; + +typedef struct ImVector_ImGuiStoragePair {int Size;int Capacity;ImGuiStoragePair* Data;} ImVector_ImGuiStoragePair; + struct ImGuiStorage { ImVector_ImGuiStoragePair Data; }; -typedef struct ImVector_ImGuiTabBar {int Size;int Capacity;ImGuiTabBar* Data;} ImVector_ImGuiTabBar; -typedef struct ImPool_ImGuiTabBar {ImVector_ImGuiTabBar Buf;ImGuiStorage Map;ImPoolIdx FreeIdx;} ImPool_ImGuiTabBar; -typedef struct ImVector_ImGuiTable {int Size;int Capacity;ImGuiTable* Data;} ImVector_ImGuiTable; -typedef struct ImPool_ImGuiTable {ImVector_ImGuiTable Buf;ImGuiStorage Map;ImPoolIdx FreeIdx;} ImPool_ImGuiTable; +typedef struct ImGuiStoragePair ImGuiStoragePair; struct ImGuiListClipper { int DisplayStart; @@ -1097,6 +991,7 @@ struct ImColor { ImVec4 Value; }; +typedef void (*ImDrawCallback)(const ImDrawList* parent_list, const ImDrawCmd* cmd); struct ImDrawCmd { ImVec4 ClipRect; @@ -1113,17 +1008,24 @@ struct ImDrawVert ImVec2 uv; ImU32 col; }; +typedef struct ImDrawCmdHeader ImDrawCmdHeader; struct ImDrawCmdHeader { ImVec4 ClipRect; ImTextureID TextureId; unsigned int VtxOffset; }; +typedef struct ImVector_ImDrawCmd {int Size;int Capacity;ImDrawCmd* Data;} ImVector_ImDrawCmd; + +typedef struct ImVector_ImDrawIdx {int Size;int Capacity;ImDrawIdx* Data;} ImVector_ImDrawIdx; + struct ImDrawChannel { ImVector_ImDrawCmd _CmdBuffer; ImVector_ImDrawIdx _IdxBuffer; }; +typedef struct ImVector_ImDrawChannel {int Size;int Capacity;ImDrawChannel* Data;} ImVector_ImDrawChannel; + struct ImDrawListSplitter { int _Current; @@ -1144,15 +1046,23 @@ typedef enum { ImDrawFlags_RoundCornersRight = ImDrawFlags_RoundCornersBottomRight | ImDrawFlags_RoundCornersTopRight, ImDrawFlags_RoundCornersAll = ImDrawFlags_RoundCornersTopLeft | ImDrawFlags_RoundCornersTopRight | ImDrawFlags_RoundCornersBottomLeft | ImDrawFlags_RoundCornersBottomRight, ImDrawFlags_RoundCornersDefault_ = ImDrawFlags_RoundCornersAll, - ImDrawFlags_RoundCornersMask_ = ImDrawFlags_RoundCornersAll | ImDrawFlags_RoundCornersNone + ImDrawFlags_RoundCornersMask_ = ImDrawFlags_RoundCornersAll | ImDrawFlags_RoundCornersNone, }ImDrawFlags_; typedef enum { ImDrawListFlags_None = 0, ImDrawListFlags_AntiAliasedLines = 1 << 0, ImDrawListFlags_AntiAliasedLinesUseTex = 1 << 1, ImDrawListFlags_AntiAliasedFill = 1 << 2, - ImDrawListFlags_AllowVtxOffset = 1 << 3 + ImDrawListFlags_AllowVtxOffset = 1 << 3, }ImDrawListFlags_; +typedef struct ImVector_ImDrawVert {int Size;int Capacity;ImDrawVert* Data;} ImVector_ImDrawVert; + +typedef struct ImVector_ImVec4 {int Size;int Capacity;ImVec4* Data;} ImVector_ImVec4; + +typedef struct ImVector_ImTextureID {int Size;int Capacity;ImTextureID* Data;} ImVector_ImTextureID; + +typedef struct ImVector_ImVec2 {int Size;int Capacity;ImVec2* Data;} ImVector_ImVec2; + struct ImDrawList { ImVector_ImDrawCmd CmdBuffer; @@ -1214,10 +1124,13 @@ struct ImFontGlyph float X0, Y0, X1, Y1; float U0, V0, U1, V1; }; +typedef struct ImVector_ImU32 {int Size;int Capacity;ImU32* Data;} ImVector_ImU32; + struct ImFontGlyphRangesBuilder { ImVector_ImU32 UsedChars; }; +typedef struct ImFontAtlasCustomRect ImFontAtlasCustomRect; struct ImFontAtlasCustomRect { unsigned short Width, Height; @@ -1231,8 +1144,14 @@ typedef enum { ImFontAtlasFlags_None = 0, ImFontAtlasFlags_NoPowerOfTwoHeight = 1 << 0, ImFontAtlasFlags_NoMouseCursors = 1 << 1, - ImFontAtlasFlags_NoBakedLines = 1 << 2 + ImFontAtlasFlags_NoBakedLines = 1 << 2, }ImFontAtlasFlags_; +typedef struct ImVector_ImFontPtr {int Size;int Capacity;ImFont** Data;} ImVector_ImFontPtr; + +typedef struct ImVector_ImFontAtlasCustomRect {int Size;int Capacity;ImFontAtlasCustomRect* Data;} ImVector_ImFontAtlasCustomRect; + +typedef struct ImVector_ImFontConfig {int Size;int Capacity;ImFontConfig* Data;} ImVector_ImFontConfig; + struct ImFontAtlas { ImFontAtlasFlags Flags; @@ -1257,6 +1176,10 @@ struct ImFontAtlas int PackIdMouseCursors; int PackIdLines; }; +typedef struct ImVector_float {int Size;int Capacity;float* Data;} ImVector_float; + +typedef struct ImVector_ImFontGlyph {int Size;int Capacity;ImFontGlyph* Data;} ImVector_ImFontGlyph; + struct ImFont { ImVector_float IndexAdvanceX; @@ -1291,7 +1214,7 @@ typedef enum { ImGuiViewportFlags_TopMost = 1 << 9, ImGuiViewportFlags_Minimized = 1 << 10, ImGuiViewportFlags_NoAutoMerge = 1 << 11, - ImGuiViewportFlags_CanHostOtherWindows = 1 << 12 + ImGuiViewportFlags_CanHostOtherWindows = 1 << 12, }ImGuiViewportFlags_; struct ImGuiViewport { @@ -1312,6 +1235,10 @@ struct ImGuiViewport bool PlatformRequestResize; bool PlatformRequestClose; }; +typedef struct ImVector_ImGuiPlatformMonitor {int Size;int Capacity;ImGuiPlatformMonitor* Data;} ImVector_ImGuiPlatformMonitor; + +typedef struct ImVector_ImGuiViewportPtr {int Size;int Capacity;ImGuiViewport** Data;} ImVector_ImGuiViewportPtr; + struct ImGuiPlatformIO { void (*Platform_CreateWindow)(ImGuiViewport* vp); @@ -1331,7 +1258,6 @@ struct ImGuiPlatformIO void (*Platform_SwapBuffers)(ImGuiViewport* vp, void* render_arg); float (*Platform_GetWindowDpiScale)(ImGuiViewport* vp); void (*Platform_OnChangedViewport)(ImGuiViewport* vp); - void (*Platform_SetImeInputPos)(ImGuiViewport* vp, ImVec2 pos); int (*Platform_CreateVkSurface)(ImGuiViewport* vp, ImU64 vk_inst, const void* vk_allocators, ImU64* out_vk_surface); void (*Renderer_CreateWindow)(ImGuiViewport* vp); void (*Renderer_DestroyWindow)(ImGuiViewport* vp); @@ -1347,1298 +1273,11 @@ struct ImGuiPlatformMonitor ImVec2 WorkPos, WorkSize; float DpiScale; }; -struct StbUndoRecord +struct ImGuiPlatformImeData { - int where; - int insert_length; - int delete_length; - int char_storage; -}; -struct StbUndoState -{ - StbUndoRecord undo_rec [99]; - ImWchar undo_char[999]; - short undo_point, redo_point; - int undo_char_point, redo_char_point; -}; -struct STB_TexteditState -{ - int cursor; - int select_start; - int select_end; - unsigned char insert_mode; - int row_count_per_page; - unsigned char cursor_at_end_of_line; - unsigned char initialized; - unsigned char has_preferred_x; - unsigned char single_line; - unsigned char padding1, padding2, padding3; - float preferred_x; - StbUndoState undostate; -}; -struct StbTexteditRow -{ - float x0,x1; - float baseline_y_delta; - float ymin,ymax; - int num_chars; -}; -struct ImVec1 -{ - float x; -}; -struct ImVec2ih -{ - short x, y; -}; -struct ImRect -{ - ImVec2 Min; - ImVec2 Max; -}; -struct ImBitVector -{ - ImVector_ImU32 Storage; -}; -struct ImDrawListSharedData -{ - ImVec2 TexUvWhitePixel; - ImFont* Font; - float FontSize; - float CurveTessellationTol; - float CircleSegmentMaxError; - ImVec4 ClipRectFullscreen; - ImDrawListFlags InitialFlags; - ImVec2 ArcFastVtx[48]; - float ArcFastRadiusCutoff; - ImU8 CircleSegmentCounts[64]; - const ImVec4* TexUvLines; -}; -struct ImDrawDataBuilder -{ - ImVector_ImDrawListPtr Layers[2]; -}; -typedef enum { - ImGuiItemFlags_None = 0, - ImGuiItemFlags_NoTabStop = 1 << 0, - ImGuiItemFlags_ButtonRepeat = 1 << 1, - ImGuiItemFlags_Disabled = 1 << 2, - ImGuiItemFlags_NoNav = 1 << 3, - ImGuiItemFlags_NoNavDefaultFocus = 1 << 4, - ImGuiItemFlags_SelectableDontClosePopup = 1 << 5, - ImGuiItemFlags_MixedValue = 1 << 6, - ImGuiItemFlags_ReadOnly = 1 << 7, - ImGuiItemFlags_Inputable = 1 << 8 -}ImGuiItemFlags_; -typedef enum { - ImGuiItemStatusFlags_None = 0, - ImGuiItemStatusFlags_HoveredRect = 1 << 0, - ImGuiItemStatusFlags_HasDisplayRect = 1 << 1, - ImGuiItemStatusFlags_Edited = 1 << 2, - ImGuiItemStatusFlags_ToggledSelection = 1 << 3, - ImGuiItemStatusFlags_ToggledOpen = 1 << 4, - ImGuiItemStatusFlags_HasDeactivated = 1 << 5, - ImGuiItemStatusFlags_Deactivated = 1 << 6, - ImGuiItemStatusFlags_HoveredWindow = 1 << 7, - ImGuiItemStatusFlags_FocusedByTabbing = 1 << 8 -}ImGuiItemStatusFlags_; -typedef enum { - ImGuiInputTextFlags_Multiline = 1 << 26, - ImGuiInputTextFlags_NoMarkEdited = 1 << 27, - ImGuiInputTextFlags_MergedItem = 1 << 28 -}ImGuiInputTextFlagsPrivate_; -typedef enum { - ImGuiButtonFlags_PressedOnClick = 1 << 4, - ImGuiButtonFlags_PressedOnClickRelease = 1 << 5, - ImGuiButtonFlags_PressedOnClickReleaseAnywhere = 1 << 6, - ImGuiButtonFlags_PressedOnRelease = 1 << 7, - ImGuiButtonFlags_PressedOnDoubleClick = 1 << 8, - ImGuiButtonFlags_PressedOnDragDropHold = 1 << 9, - ImGuiButtonFlags_Repeat = 1 << 10, - ImGuiButtonFlags_FlattenChildren = 1 << 11, - ImGuiButtonFlags_AllowItemOverlap = 1 << 12, - ImGuiButtonFlags_DontClosePopups = 1 << 13, - ImGuiButtonFlags_AlignTextBaseLine = 1 << 15, - ImGuiButtonFlags_NoKeyModifiers = 1 << 16, - ImGuiButtonFlags_NoHoldingActiveId = 1 << 17, - ImGuiButtonFlags_NoNavFocus = 1 << 18, - ImGuiButtonFlags_NoHoveredOnFocus = 1 << 19, - ImGuiButtonFlags_PressedOnMask_ = ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnClickReleaseAnywhere | ImGuiButtonFlags_PressedOnRelease | ImGuiButtonFlags_PressedOnDoubleClick | ImGuiButtonFlags_PressedOnDragDropHold, - ImGuiButtonFlags_PressedOnDefault_ = ImGuiButtonFlags_PressedOnClickRelease -}ImGuiButtonFlagsPrivate_; -typedef enum { - ImGuiComboFlags_CustomPreview = 1 << 20 -}ImGuiComboFlagsPrivate_; -typedef enum { - ImGuiSliderFlags_Vertical = 1 << 20, - ImGuiSliderFlags_ReadOnly = 1 << 21 -}ImGuiSliderFlagsPrivate_; -typedef enum { - ImGuiSelectableFlags_NoHoldingActiveID = 1 << 20, - ImGuiSelectableFlags_SelectOnNav = 1 << 21, - ImGuiSelectableFlags_SelectOnClick = 1 << 22, - ImGuiSelectableFlags_SelectOnRelease = 1 << 23, - ImGuiSelectableFlags_SpanAvailWidth = 1 << 24, - ImGuiSelectableFlags_DrawHoveredWhenHeld = 1 << 25, - ImGuiSelectableFlags_SetNavIdOnHover = 1 << 26, - ImGuiSelectableFlags_NoPadWithHalfSpacing = 1 << 27 -}ImGuiSelectableFlagsPrivate_; -typedef enum { - ImGuiTreeNodeFlags_ClipLabelForTrailingButton = 1 << 20 -}ImGuiTreeNodeFlagsPrivate_; -typedef enum { - ImGuiSeparatorFlags_None = 0, - ImGuiSeparatorFlags_Horizontal = 1 << 0, - ImGuiSeparatorFlags_Vertical = 1 << 1, - ImGuiSeparatorFlags_SpanAllColumns = 1 << 2 -}ImGuiSeparatorFlags_; -typedef enum { - ImGuiTextFlags_None = 0, - ImGuiTextFlags_NoWidthForLargeClippedText = 1 << 0 -}ImGuiTextFlags_; -typedef enum { - ImGuiTooltipFlags_None = 0, - ImGuiTooltipFlags_OverridePreviousTooltip = 1 << 0 -}ImGuiTooltipFlags_; -typedef enum { - ImGuiLayoutType_Horizontal = 0, - ImGuiLayoutType_Vertical = 1 -}ImGuiLayoutType_; -typedef enum { - ImGuiLogType_None = 0, - ImGuiLogType_TTY, - ImGuiLogType_File, - ImGuiLogType_Buffer, - ImGuiLogType_Clipboard -}ImGuiLogType; -typedef enum { - ImGuiAxis_None = -1, - ImGuiAxis_X = 0, - ImGuiAxis_Y = 1 -}ImGuiAxis; -typedef enum { - ImGuiPlotType_Lines, - ImGuiPlotType_Histogram -}ImGuiPlotType; -typedef enum { - ImGuiInputSource_None = 0, - ImGuiInputSource_Mouse, - ImGuiInputSource_Keyboard, - ImGuiInputSource_Gamepad, - ImGuiInputSource_Nav, - ImGuiInputSource_Clipboard, - ImGuiInputSource_COUNT -}ImGuiInputSource; -typedef enum { - ImGuiInputReadMode_Down, - ImGuiInputReadMode_Pressed, - ImGuiInputReadMode_Released, - ImGuiInputReadMode_Repeat, - ImGuiInputReadMode_RepeatSlow, - ImGuiInputReadMode_RepeatFast -}ImGuiInputReadMode; -typedef enum { - ImGuiPopupPositionPolicy_Default, - ImGuiPopupPositionPolicy_ComboBox, - ImGuiPopupPositionPolicy_Tooltip -}ImGuiPopupPositionPolicy; -struct ImGuiDataTypeTempStorage -{ - ImU8 Data[8]; -}; -struct ImGuiDataTypeInfo -{ - size_t Size; - const char* Name; - const char* PrintFmt; - const char* ScanFmt; -}; -typedef enum { - ImGuiDataType_String = ImGuiDataType_COUNT + 1, - ImGuiDataType_Pointer, - ImGuiDataType_ID -}ImGuiDataTypePrivate_; -struct ImGuiColorMod -{ - ImGuiCol Col; - ImVec4 BackupValue; -}; -struct ImGuiStyleMod -{ - ImGuiStyleVar VarIdx; - union { int BackupInt[2]; float BackupFloat[2]; }; -}; -struct ImGuiComboPreviewData -{ - ImRect PreviewRect; - ImVec2 BackupCursorPos; - ImVec2 BackupCursorMaxPos; - ImVec2 BackupCursorPosPrevLine; - float BackupPrevLineTextBaseOffset; - ImGuiLayoutType BackupLayout; -}; -struct ImGuiGroupData -{ - ImGuiID WindowID; - ImVec2 BackupCursorPos; - ImVec2 BackupCursorMaxPos; - ImVec1 BackupIndent; - ImVec1 BackupGroupOffset; - ImVec2 BackupCurrLineSize; - float BackupCurrLineTextBaseOffset; - ImGuiID BackupActiveIdIsAlive; - bool BackupActiveIdPreviousFrameIsAlive; - bool BackupHoveredIdIsAlive; - bool EmitItem; -}; -struct ImGuiMenuColumns -{ - ImU32 TotalWidth; - ImU32 NextTotalWidth; - ImU16 Spacing; - ImU16 OffsetIcon; - ImU16 OffsetLabel; - ImU16 OffsetShortcut; - ImU16 OffsetMark; - ImU16 Widths[4]; -}; -struct ImGuiInputTextState -{ - ImGuiID ID; - int CurLenW, CurLenA; - ImVector_ImWchar TextW; - ImVector_char TextA; - ImVector_char InitialTextA; - bool TextAIsValid; - int BufCapacityA; - float ScrollX; - STB_TexteditState Stb; - float CursorAnim; - bool CursorFollow; - bool SelectedAllMouseLock; - bool Edited; - ImGuiInputTextFlags Flags; -}; -struct ImGuiPopupData -{ - ImGuiID PopupId; - ImGuiWindow* Window; - ImGuiWindow* SourceWindow; - int OpenFrameCount; - ImGuiID OpenParentId; - ImVec2 OpenPopupPos; - ImVec2 OpenMousePos; -}; -typedef enum { - ImGuiNextWindowDataFlags_None = 0, - ImGuiNextWindowDataFlags_HasPos = 1 << 0, - ImGuiNextWindowDataFlags_HasSize = 1 << 1, - ImGuiNextWindowDataFlags_HasContentSize = 1 << 2, - ImGuiNextWindowDataFlags_HasCollapsed = 1 << 3, - ImGuiNextWindowDataFlags_HasSizeConstraint = 1 << 4, - ImGuiNextWindowDataFlags_HasFocus = 1 << 5, - ImGuiNextWindowDataFlags_HasBgAlpha = 1 << 6, - ImGuiNextWindowDataFlags_HasScroll = 1 << 7, - ImGuiNextWindowDataFlags_HasViewport = 1 << 8, - ImGuiNextWindowDataFlags_HasDock = 1 << 9, - ImGuiNextWindowDataFlags_HasWindowClass = 1 << 10 -}ImGuiNextWindowDataFlags_; -struct ImGuiNextWindowData -{ - ImGuiNextWindowDataFlags Flags; - ImGuiCond PosCond; - ImGuiCond SizeCond; - ImGuiCond CollapsedCond; - ImGuiCond DockCond; - ImVec2 PosVal; - ImVec2 PosPivotVal; - ImVec2 SizeVal; - ImVec2 ContentSizeVal; - ImVec2 ScrollVal; - bool PosUndock; - bool CollapsedVal; - ImRect SizeConstraintRect; - ImGuiSizeCallback SizeCallback; - void* SizeCallbackUserData; - float BgAlphaVal; - ImGuiID ViewportId; - ImGuiID DockId; - ImGuiWindowClass WindowClass; - ImVec2 MenuBarOffsetMinVal; -}; -typedef enum { - ImGuiNextItemDataFlags_None = 0, - ImGuiNextItemDataFlags_HasWidth = 1 << 0, - ImGuiNextItemDataFlags_HasOpen = 1 << 1 -}ImGuiNextItemDataFlags_; -struct ImGuiNextItemData -{ - ImGuiNextItemDataFlags Flags; - float Width; - ImGuiID FocusScopeId; - ImGuiCond OpenCond; - bool OpenVal; -}; -struct ImGuiLastItemData -{ - ImGuiID ID; - ImGuiItemFlags InFlags; - ImGuiItemStatusFlags StatusFlags; - ImRect Rect; - ImRect NavRect; - ImRect DisplayRect; -}; -struct ImGuiStackSizes -{ - short SizeOfIDStack; - short SizeOfColorStack; - short SizeOfStyleVarStack; - short SizeOfFontStack; - short SizeOfFocusScopeStack; - short SizeOfGroupStack; - short SizeOfItemFlagsStack; - short SizeOfBeginPopupStack; - short SizeOfDisabledStack; -}; -struct ImGuiWindowStackData -{ - ImGuiWindow* Window; - ImGuiLastItemData ParentLastItemDataBackup; - ImGuiStackSizes StackSizesOnBegin; -}; -struct ImGuiShrinkWidthItem -{ - int Index; - float Width; -}; -struct ImGuiPtrOrIndex -{ - void* Ptr; - int Index; -}; -struct ImGuiListClipperRange -{ - int Min; - int Max; - bool PosToIndexConvert; - ImS8 PosToIndexOffsetMin; - ImS8 PosToIndexOffsetMax; -}; -struct ImGuiListClipperData -{ - ImGuiListClipper* ListClipper; - float LossynessOffset; - int StepNo; - int ItemsFrozen; - ImVector_ImGuiListClipperRange Ranges; -}; -typedef enum { - ImGuiActivateFlags_None = 0, - ImGuiActivateFlags_PreferInput = 1 << 0, - ImGuiActivateFlags_PreferTweak = 1 << 1, - ImGuiActivateFlags_TryToPreserveState = 1 << 2 -}ImGuiActivateFlags_; -typedef enum { - ImGuiScrollFlags_None = 0, - ImGuiScrollFlags_KeepVisibleEdgeX = 1 << 0, - ImGuiScrollFlags_KeepVisibleEdgeY = 1 << 1, - ImGuiScrollFlags_KeepVisibleCenterX = 1 << 2, - ImGuiScrollFlags_KeepVisibleCenterY = 1 << 3, - ImGuiScrollFlags_AlwaysCenterX = 1 << 4, - ImGuiScrollFlags_AlwaysCenterY = 1 << 5, - ImGuiScrollFlags_NoScrollParent = 1 << 6, - ImGuiScrollFlags_MaskX_ = ImGuiScrollFlags_KeepVisibleEdgeX | ImGuiScrollFlags_KeepVisibleCenterX | ImGuiScrollFlags_AlwaysCenterX, - ImGuiScrollFlags_MaskY_ = ImGuiScrollFlags_KeepVisibleEdgeY | ImGuiScrollFlags_KeepVisibleCenterY | ImGuiScrollFlags_AlwaysCenterY -}ImGuiScrollFlags_; -typedef enum { - ImGuiNavHighlightFlags_None = 0, - ImGuiNavHighlightFlags_TypeDefault = 1 << 0, - ImGuiNavHighlightFlags_TypeThin = 1 << 1, - ImGuiNavHighlightFlags_AlwaysDraw = 1 << 2, - ImGuiNavHighlightFlags_NoRounding = 1 << 3 -}ImGuiNavHighlightFlags_; -typedef enum { - ImGuiNavDirSourceFlags_None = 0, - ImGuiNavDirSourceFlags_RawKeyboard = 1 << 0, - ImGuiNavDirSourceFlags_Keyboard = 1 << 1, - ImGuiNavDirSourceFlags_PadDPad = 1 << 2, - ImGuiNavDirSourceFlags_PadLStick = 1 << 3 -}ImGuiNavDirSourceFlags_; -typedef enum { - ImGuiNavMoveFlags_None = 0, - ImGuiNavMoveFlags_LoopX = 1 << 0, - ImGuiNavMoveFlags_LoopY = 1 << 1, - ImGuiNavMoveFlags_WrapX = 1 << 2, - ImGuiNavMoveFlags_WrapY = 1 << 3, - ImGuiNavMoveFlags_AllowCurrentNavId = 1 << 4, - ImGuiNavMoveFlags_AlsoScoreVisibleSet = 1 << 5, - ImGuiNavMoveFlags_ScrollToEdgeY = 1 << 6, - ImGuiNavMoveFlags_Forwarded = 1 << 7, - ImGuiNavMoveFlags_DebugNoResult = 1 << 8, - ImGuiNavMoveFlags_FocusApi = 1 << 9, - ImGuiNavMoveFlags_Tabbing = 1 << 10, - ImGuiNavMoveFlags_Activate = 1 << 11, - ImGuiNavMoveFlags_DontSetNavHighlight = 1 << 12 -}ImGuiNavMoveFlags_; -typedef enum { - ImGuiNavLayer_Main = 0, - ImGuiNavLayer_Menu = 1, - ImGuiNavLayer_COUNT -}ImGuiNavLayer; -struct ImGuiNavItemData -{ - ImGuiWindow* Window; - ImGuiID ID; - ImGuiID FocusScopeId; - ImRect RectRel; - ImGuiItemFlags InFlags; - float DistBox; - float DistCenter; - float DistAxial; -}; -typedef enum { - ImGuiOldColumnFlags_None = 0, - ImGuiOldColumnFlags_NoBorder = 1 << 0, - ImGuiOldColumnFlags_NoResize = 1 << 1, - ImGuiOldColumnFlags_NoPreserveWidths = 1 << 2, - ImGuiOldColumnFlags_NoForceWithinWindow = 1 << 3, - ImGuiOldColumnFlags_GrowParentContentsSize = 1 << 4 -}ImGuiOldColumnFlags_; -struct ImGuiOldColumnData -{ - float OffsetNorm; - float OffsetNormBeforeResize; - ImGuiOldColumnFlags Flags; - ImRect ClipRect; -}; -struct ImGuiOldColumns -{ - ImGuiID ID; - ImGuiOldColumnFlags Flags; - bool IsFirstFrame; - bool IsBeingResized; - int Current; - int Count; - float OffMinX, OffMaxX; - float LineMinY, LineMaxY; - float HostCursorPosY; - float HostCursorMaxPosX; - ImRect HostInitialClipRect; - ImRect HostBackupClipRect; - ImRect HostBackupParentWorkRect; - ImVector_ImGuiOldColumnData Columns; - ImDrawListSplitter Splitter; -}; -typedef enum { - ImGuiDockNodeFlags_DockSpace = 1 << 10, - ImGuiDockNodeFlags_CentralNode = 1 << 11, - ImGuiDockNodeFlags_NoTabBar = 1 << 12, - ImGuiDockNodeFlags_HiddenTabBar = 1 << 13, - ImGuiDockNodeFlags_NoWindowMenuButton = 1 << 14, - ImGuiDockNodeFlags_NoCloseButton = 1 << 15, - ImGuiDockNodeFlags_NoDocking = 1 << 16, - ImGuiDockNodeFlags_NoDockingSplitMe = 1 << 17, - ImGuiDockNodeFlags_NoDockingSplitOther = 1 << 18, - ImGuiDockNodeFlags_NoDockingOverMe = 1 << 19, - ImGuiDockNodeFlags_NoDockingOverOther = 1 << 20, - ImGuiDockNodeFlags_NoDockingOverEmpty = 1 << 21, - ImGuiDockNodeFlags_NoResizeX = 1 << 22, - ImGuiDockNodeFlags_NoResizeY = 1 << 23, - ImGuiDockNodeFlags_SharedFlagsInheritMask_ = ~0, - ImGuiDockNodeFlags_NoResizeFlagsMask_ = ImGuiDockNodeFlags_NoResize | ImGuiDockNodeFlags_NoResizeX | ImGuiDockNodeFlags_NoResizeY, - ImGuiDockNodeFlags_LocalFlagsMask_ = ImGuiDockNodeFlags_NoSplit | ImGuiDockNodeFlags_NoResizeFlagsMask_ | ImGuiDockNodeFlags_AutoHideTabBar | ImGuiDockNodeFlags_DockSpace | ImGuiDockNodeFlags_CentralNode | ImGuiDockNodeFlags_NoTabBar | ImGuiDockNodeFlags_HiddenTabBar | ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton | ImGuiDockNodeFlags_NoDocking, - ImGuiDockNodeFlags_LocalFlagsTransferMask_ = ImGuiDockNodeFlags_LocalFlagsMask_ & ~ImGuiDockNodeFlags_DockSpace, - ImGuiDockNodeFlags_SavedFlagsMask_ = ImGuiDockNodeFlags_NoResizeFlagsMask_ | ImGuiDockNodeFlags_DockSpace | ImGuiDockNodeFlags_CentralNode | ImGuiDockNodeFlags_NoTabBar | ImGuiDockNodeFlags_HiddenTabBar | ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_NoCloseButton | ImGuiDockNodeFlags_NoDocking -}ImGuiDockNodeFlagsPrivate_; -typedef enum { - ImGuiDataAuthority_Auto, - ImGuiDataAuthority_DockNode, - ImGuiDataAuthority_Window -}ImGuiDataAuthority_; -typedef enum { - ImGuiDockNodeState_Unknown, - ImGuiDockNodeState_HostWindowHiddenBecauseSingleWindow, - ImGuiDockNodeState_HostWindowHiddenBecauseWindowsAreResizing, - ImGuiDockNodeState_HostWindowVisible -}ImGuiDockNodeState; -struct ImGuiDockNode -{ - ImGuiID ID; - ImGuiDockNodeFlags SharedFlags; - ImGuiDockNodeFlags LocalFlags; - ImGuiDockNodeFlags LocalFlagsInWindows; - ImGuiDockNodeFlags MergedFlags; - ImGuiDockNodeState State; - ImGuiDockNode* ParentNode; - ImGuiDockNode* ChildNodes[2]; - ImVector_ImGuiWindowPtr Windows; - ImGuiTabBar* TabBar; - ImVec2 Pos; - ImVec2 Size; - ImVec2 SizeRef; - ImGuiAxis SplitAxis; - ImGuiWindowClass WindowClass; - ImU32 LastBgColor; - ImGuiWindow* HostWindow; - ImGuiWindow* VisibleWindow; - ImGuiDockNode* CentralNode; - ImGuiDockNode* OnlyNodeWithWindows; - int CountNodeWithWindows; - int LastFrameAlive; - int LastFrameActive; - int LastFrameFocused; - ImGuiID LastFocusedNodeId; - ImGuiID SelectedTabId; - ImGuiID WantCloseTabId; - ImGuiDataAuthority AuthorityForPos :3; - ImGuiDataAuthority AuthorityForSize :3; - ImGuiDataAuthority AuthorityForViewport :3; - bool IsVisible :1; - bool IsFocused :1; - bool IsBgDrawnThisFrame :1; - bool HasCloseButton :1; - bool HasWindowMenuButton :1; - bool HasCentralNodeChild :1; - bool WantCloseAll :1; - bool WantLockSizeOnce :1; - bool WantMouseMove :1; - bool WantHiddenTabBarUpdate :1; - bool WantHiddenTabBarToggle :1; -}; -typedef enum { - ImGuiWindowDockStyleCol_Text, - ImGuiWindowDockStyleCol_Tab, - ImGuiWindowDockStyleCol_TabHovered, - ImGuiWindowDockStyleCol_TabActive, - ImGuiWindowDockStyleCol_TabUnfocused, - ImGuiWindowDockStyleCol_TabUnfocusedActive, - ImGuiWindowDockStyleCol_COUNT -}ImGuiWindowDockStyleCol; -struct ImGuiWindowDockStyle -{ - ImU32 Colors[ImGuiWindowDockStyleCol_COUNT]; -}; -struct ImGuiDockContext -{ - ImGuiStorage Nodes; - ImVector_ImGuiDockRequest Requests; - ImVector_ImGuiDockNodeSettings NodesSettings; - bool WantFullRebuild; -}; -struct ImGuiViewportP -{ - ImGuiViewport _ImGuiViewport; - int Idx; - int LastFrameActive; - int LastFrontMostStampCount; - ImGuiID LastNameHash; - ImVec2 LastPos; - float Alpha; - float LastAlpha; - short PlatformMonitor; - bool PlatformWindowCreated; - ImGuiWindow* Window; - int DrawListsLastFrame[2]; - ImDrawList* DrawLists[2]; - ImDrawData DrawDataP; - ImDrawDataBuilder DrawDataBuilder; - ImVec2 LastPlatformPos; - ImVec2 LastPlatformSize; - ImVec2 LastRendererSize; - ImVec2 WorkOffsetMin; - ImVec2 WorkOffsetMax; - ImVec2 BuildWorkOffsetMin; - ImVec2 BuildWorkOffsetMax; -}; -struct ImGuiWindowSettings -{ - ImGuiID ID; - ImVec2ih Pos; - ImVec2ih Size; - ImVec2ih ViewportPos; - ImGuiID ViewportId; - ImGuiID DockId; - ImGuiID ClassId; - short DockOrder; - bool Collapsed; - bool WantApply; -}; -struct ImGuiSettingsHandler -{ - const char* TypeName; - ImGuiID TypeHash; - void (*ClearAllFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler); - void (*ReadInitFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler); - void* (*ReadOpenFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler, const char* name); - void (*ReadLineFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler, void* entry, const char* line); - void (*ApplyAllFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler); - void (*WriteAllFn)(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* out_buf); - void* UserData; -}; -struct ImGuiMetricsConfig -{ - bool ShowStackTool; - bool ShowWindowsRects; - bool ShowWindowsBeginOrder; - bool ShowTablesRects; - bool ShowDrawCmdMesh; - bool ShowDrawCmdBoundingBoxes; - bool ShowDockingNodes; - int ShowWindowsRectsType; - int ShowTablesRectsType; -}; -struct ImGuiStackLevelInfo -{ - ImGuiID ID; - ImS8 QueryFrameCount; - bool QuerySuccess; - char Desc[58]; -}; -struct ImGuiStackTool -{ - int LastActiveFrame; - int StackLevel; - ImGuiID QueryId; - ImVector_ImGuiStackLevelInfo Results; -}; -typedef enum { ImGuiContextHookType_NewFramePre, ImGuiContextHookType_NewFramePost, ImGuiContextHookType_EndFramePre, ImGuiContextHookType_EndFramePost, ImGuiContextHookType_RenderPre, ImGuiContextHookType_RenderPost, ImGuiContextHookType_Shutdown, ImGuiContextHookType_PendingRemoval_ }ImGuiContextHookType; -struct ImGuiContextHook -{ - ImGuiID HookId; - ImGuiContextHookType Type; - ImGuiID Owner; - ImGuiContextHookCallback Callback; - void* UserData; -}; -struct ImGuiContext -{ - bool Initialized; - bool FontAtlasOwnedByContext; - ImGuiIO IO; - ImGuiPlatformIO PlatformIO; - ImGuiStyle Style; - ImGuiConfigFlags ConfigFlagsCurrFrame; - ImGuiConfigFlags ConfigFlagsLastFrame; - ImFont* Font; - float FontSize; - float FontBaseSize; - ImDrawListSharedData DrawListSharedData; - double Time; - int FrameCount; - int FrameCountEnded; - int FrameCountPlatformEnded; - int FrameCountRendered; - bool WithinFrameScope; - bool WithinFrameScopeWithImplicitWindow; - bool WithinEndChild; - bool GcCompactAll; - bool TestEngineHookItems; - void* TestEngine; - ImVector_ImGuiWindowPtr Windows; - ImVector_ImGuiWindowPtr WindowsFocusOrder; - ImVector_ImGuiWindowPtr WindowsTempSortBuffer; - ImVector_ImGuiWindowStackData CurrentWindowStack; - ImGuiStorage WindowsById; - int WindowsActiveCount; - ImVec2 WindowsHoverPadding; - ImGuiWindow* CurrentWindow; - ImGuiWindow* HoveredWindow; - ImGuiWindow* HoveredWindowUnderMovingWindow; - ImGuiDockNode* HoveredDockNode; - ImGuiWindow* MovingWindow; - ImGuiWindow* WheelingWindow; - ImVec2 WheelingWindowRefMousePos; - float WheelingWindowTimer; - ImGuiID DebugHookIdInfo; - ImGuiID HoveredId; - ImGuiID HoveredIdPreviousFrame; - bool HoveredIdAllowOverlap; - bool HoveredIdUsingMouseWheel; - bool HoveredIdPreviousFrameUsingMouseWheel; - bool HoveredIdDisabled; - float HoveredIdTimer; - float HoveredIdNotActiveTimer; - ImGuiID ActiveId; - ImGuiID ActiveIdIsAlive; - float ActiveIdTimer; - bool ActiveIdIsJustActivated; - bool ActiveIdAllowOverlap; - bool ActiveIdNoClearOnFocusLoss; - bool ActiveIdHasBeenPressedBefore; - bool ActiveIdHasBeenEditedBefore; - bool ActiveIdHasBeenEditedThisFrame; - bool ActiveIdUsingMouseWheel; - ImU32 ActiveIdUsingNavDirMask; - ImU32 ActiveIdUsingNavInputMask; - ImU64 ActiveIdUsingKeyInputMask; - ImVec2 ActiveIdClickOffset; - ImGuiWindow* ActiveIdWindow; - ImGuiInputSource ActiveIdSource; - int ActiveIdMouseButton; - ImGuiID ActiveIdPreviousFrame; - bool ActiveIdPreviousFrameIsAlive; - bool ActiveIdPreviousFrameHasBeenEditedBefore; - ImGuiWindow* ActiveIdPreviousFrameWindow; - ImGuiID LastActiveId; - float LastActiveIdTimer; - ImGuiItemFlags CurrentItemFlags; - ImGuiNextItemData NextItemData; - ImGuiLastItemData LastItemData; - ImGuiNextWindowData NextWindowData; - ImVector_ImGuiColorMod ColorStack; - ImVector_ImGuiStyleMod StyleVarStack; - ImVector_ImFontPtr FontStack; - ImVector_ImGuiID FocusScopeStack; - ImVector_ImGuiItemFlags ItemFlagsStack; - ImVector_ImGuiGroupData GroupStack; - ImVector_ImGuiPopupData OpenPopupStack; - ImVector_ImGuiPopupData BeginPopupStack; - int BeginMenuCount; - ImVector_ImGuiViewportPPtr Viewports; - float CurrentDpiScale; - ImGuiViewportP* CurrentViewport; - ImGuiViewportP* MouseViewport; - ImGuiViewportP* MouseLastHoveredViewport; - ImGuiID PlatformLastFocusedViewportId; - ImGuiPlatformMonitor FallbackMonitor; - int ViewportFrontMostStampCount; - ImGuiWindow* NavWindow; - ImGuiID NavId; - ImGuiID NavFocusScopeId; - ImGuiID NavActivateId; - ImGuiID NavActivateDownId; - ImGuiID NavActivatePressedId; - ImGuiID NavActivateInputId; - ImGuiActivateFlags NavActivateFlags; - ImGuiID NavJustMovedToId; - ImGuiID NavJustMovedToFocusScopeId; - ImGuiKeyModFlags NavJustMovedToKeyMods; - ImGuiID NavNextActivateId; - ImGuiActivateFlags NavNextActivateFlags; - ImGuiInputSource NavInputSource; - ImGuiNavLayer NavLayer; - bool NavIdIsAlive; - bool NavMousePosDirty; - bool NavDisableHighlight; - bool NavDisableMouseHover; - bool NavAnyRequest; - bool NavInitRequest; - bool NavInitRequestFromMove; - ImGuiID NavInitResultId; - ImRect NavInitResultRectRel; - bool NavMoveSubmitted; - bool NavMoveScoringItems; - bool NavMoveForwardToNextFrame; - ImGuiNavMoveFlags NavMoveFlags; - ImGuiScrollFlags NavMoveScrollFlags; - ImGuiKeyModFlags NavMoveKeyMods; - ImGuiDir NavMoveDir; - ImGuiDir NavMoveDirForDebug; - ImGuiDir NavMoveClipDir; - ImRect NavScoringRect; - ImRect NavScoringNoClipRect; - int NavScoringDebugCount; - int NavTabbingDir; - int NavTabbingCounter; - ImGuiNavItemData NavMoveResultLocal; - ImGuiNavItemData NavMoveResultLocalVisible; - ImGuiNavItemData NavMoveResultOther; - ImGuiNavItemData NavTabbingResultFirst; - ImGuiWindow* NavWindowingTarget; - ImGuiWindow* NavWindowingTargetAnim; - ImGuiWindow* NavWindowingListWindow; - float NavWindowingTimer; - float NavWindowingHighlightAlpha; - bool NavWindowingToggleLayer; - float DimBgRatio; - ImGuiMouseCursor MouseCursor; - bool DragDropActive; - bool DragDropWithinSource; - bool DragDropWithinTarget; - ImGuiDragDropFlags DragDropSourceFlags; - int DragDropSourceFrameCount; - int DragDropMouseButton; - ImGuiPayload DragDropPayload; - ImRect DragDropTargetRect; - ImGuiID DragDropTargetId; - ImGuiDragDropFlags DragDropAcceptFlags; - float DragDropAcceptIdCurrRectSurface; - ImGuiID DragDropAcceptIdCurr; - ImGuiID DragDropAcceptIdPrev; - int DragDropAcceptFrameCount; - ImGuiID DragDropHoldJustPressedId; - ImVector_unsigned_char DragDropPayloadBufHeap; - unsigned char DragDropPayloadBufLocal[16]; - int ClipperTempDataStacked; - ImVector_ImGuiListClipperData ClipperTempData; - ImGuiTable* CurrentTable; - int TablesTempDataStacked; - ImVector_ImGuiTableTempData TablesTempData; - ImPool_ImGuiTable Tables; - ImVector_float TablesLastTimeActive; - ImVector_ImDrawChannel DrawChannelsTempMergeBuffer; - ImGuiTabBar* CurrentTabBar; - ImPool_ImGuiTabBar TabBars; - ImVector_ImGuiPtrOrIndex CurrentTabBarStack; - ImVector_ImGuiShrinkWidthItem ShrinkWidthBuffer; - ImVec2 MouseLastValidPos; - ImGuiInputTextState InputTextState; - ImFont InputTextPasswordFont; - ImGuiID TempInputId; - ImGuiColorEditFlags ColorEditOptions; - float ColorEditLastHue; - float ColorEditLastSat; - ImU32 ColorEditLastColor; - ImVec4 ColorPickerRef; - ImGuiComboPreviewData ComboPreviewData; - float SliderCurrentAccum; - bool SliderCurrentAccumDirty; - bool DragCurrentAccumDirty; - float DragCurrentAccum; - float DragSpeedDefaultRatio; - float ScrollbarClickDeltaToGrabCenter; - float DisabledAlphaBackup; - short DisabledStackSize; - short TooltipOverrideCount; - float TooltipSlowDelay; - ImVector_char ClipboardHandlerData; - ImVector_ImGuiID MenusIdSubmittedThisFrame; - ImVec2 PlatformImePos; - ImVec2 PlatformImeLastPos; - ImGuiViewportP* PlatformImePosViewport; - char PlatformLocaleDecimalPoint; - ImGuiDockContext DockContext; - bool SettingsLoaded; - float SettingsDirtyTimer; - ImGuiTextBuffer SettingsIniData; - ImVector_ImGuiSettingsHandler SettingsHandlers; - ImChunkStream_ImGuiWindowSettings SettingsWindows; - ImChunkStream_ImGuiTableSettings SettingsTables; - ImVector_ImGuiContextHook Hooks; - ImGuiID HookIdNext; - bool LogEnabled; - ImGuiLogType LogType; - ImFileHandle LogFile; - ImGuiTextBuffer LogBuffer; - const char* LogNextPrefix; - const char* LogNextSuffix; - float LogLinePosY; - bool LogLineFirstItem; - int LogDepthRef; - int LogDepthToExpand; - int LogDepthToExpandDefault; - bool DebugItemPickerActive; - ImGuiID DebugItemPickerBreakId; - ImGuiMetricsConfig DebugMetricsConfig; - ImGuiStackTool DebugStackTool; - float FramerateSecPerFrame[120]; - int FramerateSecPerFrameIdx; - int FramerateSecPerFrameCount; - float FramerateSecPerFrameAccum; - int WantCaptureMouseNextFrame; - int WantCaptureKeyboardNextFrame; - int WantTextInputNextFrame; - char TempBuffer[1024 * 3 + 1]; -}; -struct ImGuiWindowTempData -{ - ImVec2 CursorPos; - ImVec2 CursorPosPrevLine; - ImVec2 CursorStartPos; - ImVec2 CursorMaxPos; - ImVec2 IdealMaxPos; - ImVec2 CurrLineSize; - ImVec2 PrevLineSize; - float CurrLineTextBaseOffset; - float PrevLineTextBaseOffset; - ImVec1 Indent; - ImVec1 ColumnsOffset; - ImVec1 GroupOffset; - ImVec2 CursorStartPosLossyness; - ImGuiNavLayer NavLayerCurrent; - short NavLayersActiveMask; - short NavLayersActiveMaskNext; - ImGuiID NavFocusScopeIdCurrent; - bool NavHideHighlightOneFrame; - bool NavHasScroll; - bool MenuBarAppending; - ImVec2 MenuBarOffset; - ImGuiMenuColumns MenuColumns; - int TreeDepth; - ImU32 TreeJumpToParentOnPopMask; - ImVector_ImGuiWindowPtr ChildWindows; - ImGuiStorage* StateStorage; - ImGuiOldColumns* CurrentColumns; - int CurrentTableIdx; - ImGuiLayoutType LayoutType; - ImGuiLayoutType ParentLayoutType; - float ItemWidth; - float TextWrapPos; - ImVector_float ItemWidthStack; - ImVector_float TextWrapPosStack; -}; -struct ImGuiWindow -{ - char* Name; - ImGuiID ID; - ImGuiWindowFlags Flags, FlagsPreviousFrame; - ImGuiWindowClass WindowClass; - ImGuiViewportP* Viewport; - ImGuiID ViewportId; - ImVec2 ViewportPos; - int ViewportAllowPlatformMonitorExtend; - ImVec2 Pos; - ImVec2 Size; - ImVec2 SizeFull; - ImVec2 ContentSize; - ImVec2 ContentSizeIdeal; - ImVec2 ContentSizeExplicit; - ImVec2 WindowPadding; - float WindowRounding; - float WindowBorderSize; - int NameBufLen; - ImGuiID MoveId; - ImGuiID ChildId; - ImVec2 Scroll; - ImVec2 ScrollMax; - ImVec2 ScrollTarget; - ImVec2 ScrollTargetCenterRatio; - ImVec2 ScrollTargetEdgeSnapDist; - ImVec2 ScrollbarSizes; - bool ScrollbarX, ScrollbarY; - bool ViewportOwned; - bool Active; - bool WasActive; - bool WriteAccessed; - bool Collapsed; - bool WantCollapseToggle; - bool SkipItems; - bool Appearing; - bool Hidden; - bool IsFallbackWindow; - bool IsExplicitChild; - bool HasCloseButton; - signed char ResizeBorderHeld; - short BeginCount; - short BeginOrderWithinParent; - short BeginOrderWithinContext; - short FocusOrder; - ImGuiID PopupId; - ImS8 AutoFitFramesX, AutoFitFramesY; - ImS8 AutoFitChildAxises; - bool AutoFitOnlyGrows; - ImGuiDir AutoPosLastDirection; - ImS8 HiddenFramesCanSkipItems; - ImS8 HiddenFramesCannotSkipItems; - ImS8 HiddenFramesForRenderOnly; - ImS8 DisableInputsFrames; - ImGuiCond SetWindowPosAllowFlags : 8; - ImGuiCond SetWindowSizeAllowFlags : 8; - ImGuiCond SetWindowCollapsedAllowFlags : 8; - ImGuiCond SetWindowDockAllowFlags : 8; - ImVec2 SetWindowPosVal; - ImVec2 SetWindowPosPivot; - ImVector_ImGuiID IDStack; - ImGuiWindowTempData DC; - ImRect OuterRectClipped; - ImRect InnerRect; - ImRect InnerClipRect; - ImRect WorkRect; - ImRect ParentWorkRect; - ImRect ClipRect; - ImRect ContentRegionRect; - ImVec2ih HitTestHoleSize; - ImVec2ih HitTestHoleOffset; - int LastFrameActive; - int LastFrameJustFocused; - float LastTimeActive; - float ItemWidthDefault; - ImGuiStorage StateStorage; - ImVector_ImGuiOldColumns ColumnsStorage; - float FontWindowScale; - float FontDpiScale; - int SettingsOffset; - ImDrawList* DrawList; - ImDrawList DrawListInst; - ImGuiWindow* ParentWindow; - ImGuiWindow* ParentWindowInBeginStack; - ImGuiWindow* RootWindow; - ImGuiWindow* RootWindowPopupTree; - ImGuiWindow* RootWindowDockTree; - ImGuiWindow* RootWindowForTitleBarHighlight; - ImGuiWindow* RootWindowForNav; - ImGuiWindow* NavLastChildNavWindow; - ImGuiID NavLastIds[ImGuiNavLayer_COUNT]; - ImRect NavRectRel[ImGuiNavLayer_COUNT]; - int MemoryDrawListIdxCapacity; - int MemoryDrawListVtxCapacity; - bool MemoryCompacted; - bool DockIsActive :1; - bool DockNodeIsVisible :1; - bool DockTabIsVisible :1; - bool DockTabWantClose :1; - short DockOrder; - ImGuiWindowDockStyle DockStyle; - ImGuiDockNode* DockNode; - ImGuiDockNode* DockNodeAsHost; - ImGuiID DockId; - ImGuiItemStatusFlags DockTabItemStatusFlags; - ImRect DockTabItemRect; -}; -typedef enum { - ImGuiTabBarFlags_DockNode = 1 << 20, - ImGuiTabBarFlags_IsFocused = 1 << 21, - ImGuiTabBarFlags_SaveSettings = 1 << 22 -}ImGuiTabBarFlagsPrivate_; -typedef enum { - ImGuiTabItemFlags_SectionMask_ = ImGuiTabItemFlags_Leading | ImGuiTabItemFlags_Trailing, - ImGuiTabItemFlags_NoCloseButton = 1 << 20, - ImGuiTabItemFlags_Button = 1 << 21, - ImGuiTabItemFlags_Unsorted = 1 << 22, - ImGuiTabItemFlags_Preview = 1 << 23 -}ImGuiTabItemFlagsPrivate_; -struct ImGuiTabItem -{ - ImGuiID ID; - ImGuiTabItemFlags Flags; - ImGuiWindow* Window; - int LastFrameVisible; - int LastFrameSelected; - float Offset; - float Width; - float ContentWidth; - ImS32 NameOffset; - ImS16 BeginOrder; - ImS16 IndexDuringLayout; - bool WantClose; -}; -struct ImGuiTabBar -{ - ImVector_ImGuiTabItem Tabs; - ImGuiTabBarFlags Flags; - ImGuiID ID; - ImGuiID SelectedTabId; - ImGuiID NextSelectedTabId; - ImGuiID VisibleTabId; - int CurrFrameVisible; - int PrevFrameVisible; - ImRect BarRect; - float CurrTabsContentsHeight; - float PrevTabsContentsHeight; - float WidthAllTabs; - float WidthAllTabsIdeal; - float ScrollingAnim; - float ScrollingTarget; - float ScrollingTargetDistToVisibility; - float ScrollingSpeed; - float ScrollingRectMinX; - float ScrollingRectMaxX; - ImGuiID ReorderRequestTabId; - ImS16 ReorderRequestOffset; - ImS8 BeginCount; - bool WantLayout; - bool VisibleTabWasSubmitted; - bool TabsAddedNew; - ImS16 TabsActiveCount; - ImS16 LastTabItemIdx; - float ItemSpacingY; - ImVec2 FramePadding; - ImVec2 BackupCursorPos; - ImGuiTextBuffer TabsNames; -}; -struct ImGuiTableColumn -{ - ImGuiTableColumnFlags Flags; - float WidthGiven; - float MinX; - float MaxX; - float WidthRequest; - float WidthAuto; - float StretchWeight; - float InitStretchWeightOrWidth; - ImRect ClipRect; - ImGuiID UserID; - float WorkMinX; - float WorkMaxX; - float ItemWidth; - float ContentMaxXFrozen; - float ContentMaxXUnfrozen; - float ContentMaxXHeadersUsed; - float ContentMaxXHeadersIdeal; - ImS16 NameOffset; - ImGuiTableColumnIdx DisplayOrder; - ImGuiTableColumnIdx IndexWithinEnabledSet; - ImGuiTableColumnIdx PrevEnabledColumn; - ImGuiTableColumnIdx NextEnabledColumn; - ImGuiTableColumnIdx SortOrder; - ImGuiTableDrawChannelIdx DrawChannelCurrent; - ImGuiTableDrawChannelIdx DrawChannelFrozen; - ImGuiTableDrawChannelIdx DrawChannelUnfrozen; - bool IsEnabled; - bool IsUserEnabled; - bool IsUserEnabledNextFrame; - bool IsVisibleX; - bool IsVisibleY; - bool IsRequestOutput; - bool IsSkipItems; - bool IsPreserveWidthAuto; - ImS8 NavLayerCurrent; - ImU8 AutoFitQueue; - ImU8 CannotSkipItemsQueue; - ImU8 SortDirection : 2; - ImU8 SortDirectionsAvailCount : 2; - ImU8 SortDirectionsAvailMask : 4; - ImU8 SortDirectionsAvailList; -}; -struct ImGuiTableCellData -{ - ImU32 BgColor; - ImGuiTableColumnIdx Column; -}; -struct ImGuiTable -{ - ImGuiID ID; - ImGuiTableFlags Flags; - void* RawData; - ImGuiTableTempData* TempData; - ImSpan_ImGuiTableColumn Columns; - ImSpan_ImGuiTableColumnIdx DisplayOrderToIndex; - ImSpan_ImGuiTableCellData RowCellData; - ImU64 EnabledMaskByDisplayOrder; - ImU64 EnabledMaskByIndex; - ImU64 VisibleMaskByIndex; - ImU64 RequestOutputMaskByIndex; - ImGuiTableFlags SettingsLoadedFlags; - int SettingsOffset; - int LastFrameActive; - int ColumnsCount; - int CurrentRow; - int CurrentColumn; - ImS16 InstanceCurrent; - ImS16 InstanceInteracted; - float RowPosY1; - float RowPosY2; - float RowMinHeight; - float RowTextBaseline; - float RowIndentOffsetX; - ImGuiTableRowFlags RowFlags : 16; - ImGuiTableRowFlags LastRowFlags : 16; - int RowBgColorCounter; - ImU32 RowBgColor[2]; - ImU32 BorderColorStrong; - ImU32 BorderColorLight; - float BorderX1; - float BorderX2; - float HostIndentX; - float MinColumnWidth; - float OuterPaddingX; - float CellPaddingX; - float CellPaddingY; - float CellSpacingX1; - float CellSpacingX2; - float LastOuterHeight; - float LastFirstRowHeight; - float InnerWidth; - float ColumnsGivenWidth; - float ColumnsAutoFitWidth; - float ResizedColumnNextWidth; - float ResizeLockMinContentsX2; - float RefScale; - ImRect OuterRect; - ImRect InnerRect; - ImRect WorkRect; - ImRect InnerClipRect; - ImRect BgClipRect; - ImRect Bg0ClipRectForDrawCmd; - ImRect Bg2ClipRectForDrawCmd; - ImRect HostClipRect; - ImRect HostBackupInnerClipRect; - ImGuiWindow* OuterWindow; - ImGuiWindow* InnerWindow; - ImGuiTextBuffer ColumnsNames; - ImDrawListSplitter* DrawSplitter; - ImGuiTableColumnSortSpecs SortSpecsSingle; - ImVector_ImGuiTableColumnSortSpecs SortSpecsMulti; - ImGuiTableSortSpecs SortSpecs; - ImGuiTableColumnIdx SortSpecsCount; - ImGuiTableColumnIdx ColumnsEnabledCount; - ImGuiTableColumnIdx ColumnsEnabledFixedCount; - ImGuiTableColumnIdx DeclColumnsCount; - ImGuiTableColumnIdx HoveredColumnBody; - ImGuiTableColumnIdx HoveredColumnBorder; - ImGuiTableColumnIdx AutoFitSingleColumn; - ImGuiTableColumnIdx ResizedColumn; - ImGuiTableColumnIdx LastResizedColumn; - ImGuiTableColumnIdx HeldHeaderColumn; - ImGuiTableColumnIdx ReorderColumn; - ImGuiTableColumnIdx ReorderColumnDir; - ImGuiTableColumnIdx LeftMostEnabledColumn; - ImGuiTableColumnIdx RightMostEnabledColumn; - ImGuiTableColumnIdx LeftMostStretchedColumn; - ImGuiTableColumnIdx RightMostStretchedColumn; - ImGuiTableColumnIdx ContextPopupColumn; - ImGuiTableColumnIdx FreezeRowsRequest; - ImGuiTableColumnIdx FreezeRowsCount; - ImGuiTableColumnIdx FreezeColumnsRequest; - ImGuiTableColumnIdx FreezeColumnsCount; - ImGuiTableColumnIdx RowCellDataCurrent; - ImGuiTableDrawChannelIdx DummyDrawChannel; - ImGuiTableDrawChannelIdx Bg2DrawChannelCurrent; - ImGuiTableDrawChannelIdx Bg2DrawChannelUnfrozen; - bool IsLayoutLocked; - bool IsInsideRow; - bool IsInitializing; - bool IsSortSpecsDirty; - bool IsUsingHeaders; - bool IsContextPopupOpen; - bool IsSettingsRequestLoad; - bool IsSettingsDirty; - bool IsDefaultDisplayOrder; - bool IsResetAllRequest; - bool IsResetDisplayOrderRequest; - bool IsUnfrozenRows; - bool IsDefaultSizingPolicy; - bool MemoryCompacted; - bool HostSkipItems; -}; -struct ImGuiTableTempData -{ - int TableIndex; - float LastTimeActive; - ImVec2 UserOuterSize; - ImDrawListSplitter DrawSplitter; - ImRect HostBackupWorkRect; - ImRect HostBackupParentWorkRect; - ImVec2 HostBackupPrevLineSize; - ImVec2 HostBackupCurrLineSize; - ImVec2 HostBackupCursorMaxPos; - ImVec1 HostBackupColumnsOffset; - float HostBackupItemWidth; - int HostBackupItemWidthStackSize; -}; -struct ImGuiTableColumnSettings -{ - float WidthOrWeight; - ImGuiID UserID; - ImGuiTableColumnIdx Index; - ImGuiTableColumnIdx DisplayOrder; - ImGuiTableColumnIdx SortOrder; - ImU8 SortDirection : 2; - ImU8 IsEnabled : 1; - ImU8 IsStretch : 1; -}; -struct ImGuiTableSettings -{ - ImGuiID ID; - ImGuiTableFlags SaveFlags; - float RefScale; - ImGuiTableColumnIdx ColumnsCount; - ImGuiTableColumnIdx ColumnsCountMax; - bool WantApply; -}; -struct ImFontBuilderIO -{ - bool (*FontBuilder_Build)(ImFontAtlas* atlas); + bool WantVisible; + ImVec2 InputPos; + float InputLineHeight; }; #define IMGUI_HAS_DOCK 1 @@ -2651,62 +1290,25 @@ typedef union SDL_Event SDL_Event; #ifndef CIMGUI_DEFINE_ENUMS_AND_STRUCTS typedef struct ImGuiStorage::ImGuiStoragePair ImGuiStoragePair; typedef struct ImGuiTextFilter::ImGuiTextRange ImGuiTextRange; -typedef ImStb::STB_TexteditState STB_TexteditState; -typedef ImStb::StbTexteditRow StbTexteditRow; -typedef ImStb::StbUndoRecord StbUndoRecord; -typedef ImStb::StbUndoState StbUndoState; -typedef ImChunkStream ImChunkStream_ImGuiTableSettings; -typedef ImChunkStream ImChunkStream_ImGuiWindowSettings; -typedef ImPool ImPool_ImGuiTabBar; -typedef ImPool ImPool_ImGuiTable; -typedef ImSpan ImSpan_ImGuiTableCellData; -typedef ImSpan ImSpan_ImGuiTableColumn; -typedef ImSpan ImSpan_ImGuiTableColumnIdx; typedef ImVector ImVector_ImDrawChannel; typedef ImVector ImVector_ImDrawCmd; typedef ImVector ImVector_ImDrawIdx; -typedef ImVector ImVector_ImDrawListPtr; typedef ImVector ImVector_ImDrawVert; typedef ImVector ImVector_ImFontPtr; typedef ImVector ImVector_ImFontAtlasCustomRect; typedef ImVector ImVector_ImFontConfig; typedef ImVector ImVector_ImFontGlyph; -typedef ImVector ImVector_ImGuiColorMod; -typedef ImVector ImVector_ImGuiContextHook; -typedef ImVector ImVector_ImGuiDockNodeSettings; -typedef ImVector ImVector_ImGuiDockRequest; -typedef ImVector ImVector_ImGuiGroupData; -typedef ImVector ImVector_ImGuiID; -typedef ImVector ImVector_ImGuiItemFlags; -typedef ImVector ImVector_ImGuiListClipperData; -typedef ImVector ImVector_ImGuiListClipperRange; -typedef ImVector ImVector_ImGuiOldColumnData; -typedef ImVector ImVector_ImGuiOldColumns; typedef ImVector ImVector_ImGuiPlatformMonitor; -typedef ImVector ImVector_ImGuiPopupData; -typedef ImVector ImVector_ImGuiPtrOrIndex; -typedef ImVector ImVector_ImGuiSettingsHandler; -typedef ImVector ImVector_ImGuiShrinkWidthItem; -typedef ImVector ImVector_ImGuiStackLevelInfo; typedef ImVector ImVector_ImGuiStoragePair; -typedef ImVector ImVector_ImGuiStyleMod; -typedef ImVector ImVector_ImGuiTabItem; -typedef ImVector ImVector_ImGuiTableColumnSortSpecs; -typedef ImVector ImVector_ImGuiTableTempData; typedef ImVector ImVector_ImGuiTextRange; typedef ImVector ImVector_ImGuiViewportPtr; -typedef ImVector ImVector_ImGuiViewportPPtr; -typedef ImVector ImVector_ImGuiWindowPtr; -typedef ImVector ImVector_ImGuiWindowStackData; typedef ImVector ImVector_ImTextureID; typedef ImVector ImVector_ImU32; typedef ImVector ImVector_ImVec2; typedef ImVector ImVector_ImVec4; typedef ImVector ImVector_ImWchar; typedef ImVector ImVector_char; -typedef ImVector ImVector_const_charPtr; typedef ImVector ImVector_float; -typedef ImVector ImVector_unsigned_char; #endif //CIMGUI_DEFINE_ENUMS_AND_STRUCTS CIMGUI_API ImVec2* ImVec2_ImVec2_Nil(void); CIMGUI_API void ImVec2_destroy(ImVec2* self); @@ -2726,6 +1328,7 @@ CIMGUI_API void igRender(void); CIMGUI_API ImDrawData* igGetDrawData(void); CIMGUI_API void igShowDemoWindow(bool* p_open); CIMGUI_API void igShowMetricsWindow(bool* p_open); +CIMGUI_API void igShowDebugLogWindow(bool* p_open); CIMGUI_API void igShowStackToolWindow(bool* p_open); CIMGUI_API void igShowAboutWindow(bool* p_open); CIMGUI_API void igShowStyleEditor(ImGuiStyle* ref); @@ -2775,14 +1378,14 @@ CIMGUI_API void igGetWindowContentRegionMin(ImVec2 *pOut); CIMGUI_API void igGetWindowContentRegionMax(ImVec2 *pOut); CIMGUI_API float igGetScrollX(void); CIMGUI_API float igGetScrollY(void); -CIMGUI_API void igSetScrollX_Float(float scroll_x); -CIMGUI_API void igSetScrollY_Float(float scroll_y); +CIMGUI_API void igSetScrollX(float scroll_x); +CIMGUI_API void igSetScrollY(float scroll_y); CIMGUI_API float igGetScrollMaxX(void); CIMGUI_API float igGetScrollMaxY(void); CIMGUI_API void igSetScrollHereX(float center_x_ratio); CIMGUI_API void igSetScrollHereY(float center_y_ratio); -CIMGUI_API void igSetScrollFromPosX_Float(float local_x,float center_x_ratio); -CIMGUI_API void igSetScrollFromPosY_Float(float local_y,float center_y_ratio); +CIMGUI_API void igSetScrollFromPosX(float local_x,float center_x_ratio); +CIMGUI_API void igSetScrollFromPosY(float local_y,float center_y_ratio); CIMGUI_API void igPushFont(ImFont* font); CIMGUI_API void igPopFont(void); CIMGUI_API void igPushStyleColor_U32(ImGuiCol idx,ImU32 col); @@ -2856,8 +1459,6 @@ CIMGUI_API bool igButton(const char* label,const ImVec2 size); CIMGUI_API bool igSmallButton(const char* label); CIMGUI_API bool igInvisibleButton(const char* str_id,const ImVec2 size,ImGuiButtonFlags flags); CIMGUI_API bool igArrowButton(const char* str_id,ImGuiDir dir); -CIMGUI_API void igImage(ImTextureID user_texture_id,const ImVec2 size,const ImVec2 uv0,const ImVec2 uv1,const ImVec4 tint_col,const ImVec4 border_col); -CIMGUI_API bool igImageButton(ImTextureID user_texture_id,const ImVec2 size,const ImVec2 uv0,const ImVec2 uv1,int frame_padding,const ImVec4 bg_col,const ImVec4 tint_col); CIMGUI_API bool igCheckbox(const char* label,bool* v); CIMGUI_API bool igCheckboxFlags_IntPtr(const char* label,int* flags,int flags_value); CIMGUI_API bool igCheckboxFlags_UintPtr(const char* label,unsigned int* flags,unsigned int flags_value); @@ -2865,6 +1466,8 @@ CIMGUI_API bool igRadioButton_Bool(const char* label,bool active); CIMGUI_API bool igRadioButton_IntPtr(const char* label,int* v,int v_button); CIMGUI_API void igProgressBar(float fraction,const ImVec2 size_arg,const char* overlay); CIMGUI_API void igBullet(void); +CIMGUI_API void igImage(ImTextureID user_texture_id,const ImVec2 size,const ImVec2 uv0,const ImVec2 uv1,const ImVec4 tint_col,const ImVec4 border_col); +CIMGUI_API bool igImageButton(ImTextureID user_texture_id,const ImVec2 size,const ImVec2 uv0,const ImVec2 uv1,int frame_padding,const ImVec4 bg_col,const ImVec4 tint_col); CIMGUI_API bool igBeginCombo(const char* label,const char* preview_value,ImGuiComboFlags flags); CIMGUI_API void igEndCombo(void); CIMGUI_API bool igCombo_Str_arr(const char* label,int* current_item,const char* const items[],int items_count,int popup_max_height_in_items); @@ -2914,7 +1517,7 @@ CIMGUI_API bool igColorEdit3(const char* label,float col[3],ImGuiColorEditFlags CIMGUI_API bool igColorEdit4(const char* label,float col[4],ImGuiColorEditFlags flags); CIMGUI_API bool igColorPicker3(const char* label,float col[3],ImGuiColorEditFlags flags); CIMGUI_API bool igColorPicker4(const char* label,float col[4],ImGuiColorEditFlags flags,const float* ref_col); -CIMGUI_API bool igColorButton(const char* desc_id,const ImVec4 col,ImGuiColorEditFlags flags,ImVec2 size); +CIMGUI_API bool igColorButton(const char* desc_id,const ImVec4 col,ImGuiColorEditFlags flags,const ImVec2 size); CIMGUI_API void igSetColorEditOptions(ImGuiColorEditFlags flags); CIMGUI_API bool igTreeNode_Str(const char* label); CIMGUI_API bool igTreeNode_StrStr(const char* str_id,const char* fmt,...); @@ -2969,7 +1572,7 @@ CIMGUI_API void igCloseCurrentPopup(void); CIMGUI_API bool igBeginPopupContextItem(const char* str_id,ImGuiPopupFlags popup_flags); CIMGUI_API bool igBeginPopupContextWindow(const char* str_id,ImGuiPopupFlags popup_flags); CIMGUI_API bool igBeginPopupContextVoid(const char* str_id,ImGuiPopupFlags popup_flags); -CIMGUI_API bool igIsPopupOpen_Str(const char* str_id,ImGuiPopupFlags flags); +CIMGUI_API bool igIsPopupOpen(const char* str_id,ImGuiPopupFlags flags); CIMGUI_API bool igBeginTable(const char* str_id,int column,ImGuiTableFlags flags,const ImVec2 outer_size,float inner_width); CIMGUI_API void igEndTable(void); CIMGUI_API void igTableNextRow(ImGuiTableRowFlags row_flags,float min_row_height); @@ -2983,7 +1586,7 @@ CIMGUI_API ImGuiTableSortSpecs* igTableGetSortSpecs(void); CIMGUI_API int igTableGetColumnCount(void); CIMGUI_API int igTableGetColumnIndex(void); CIMGUI_API int igTableGetRowIndex(void); -CIMGUI_API const char* igTableGetColumnName_Int(int column_n); +CIMGUI_API const char* igTableGetColumnName(int column_n); CIMGUI_API ImGuiTableColumnFlags igTableGetColumnFlags(int column_n); CIMGUI_API void igTableSetColumnEnabled(int column_n,bool v); CIMGUI_API void igTableSetBgColor(ImGuiTableBgTarget target,ImU32 color,int column_n); @@ -3044,14 +1647,14 @@ CIMGUI_API void igGetItemRectMax(ImVec2 *pOut); CIMGUI_API void igGetItemRectSize(ImVec2 *pOut); CIMGUI_API void igSetItemAllowOverlap(void); CIMGUI_API ImGuiViewport* igGetMainViewport(void); -CIMGUI_API bool igIsRectVisible_Nil(const ImVec2 size); -CIMGUI_API bool igIsRectVisible_Vec2(const ImVec2 rect_min,const ImVec2 rect_max); -CIMGUI_API double igGetTime(void); -CIMGUI_API int igGetFrameCount(void); CIMGUI_API ImDrawList* igGetBackgroundDrawList_Nil(void); CIMGUI_API ImDrawList* igGetForegroundDrawList_Nil(void); CIMGUI_API ImDrawList* igGetBackgroundDrawList_ViewportPtr(ImGuiViewport* viewport); CIMGUI_API ImDrawList* igGetForegroundDrawList_ViewportPtr(ImGuiViewport* viewport); +CIMGUI_API bool igIsRectVisible_Nil(const ImVec2 size); +CIMGUI_API bool igIsRectVisible_Vec2(const ImVec2 rect_min,const ImVec2 rect_max); +CIMGUI_API double igGetTime(void); +CIMGUI_API int igGetFrameCount(void); CIMGUI_API ImDrawListSharedData* igGetDrawListSharedData(void); CIMGUI_API const char* igGetStyleColorName(ImGuiCol idx); CIMGUI_API void igSetStateStorage(ImGuiStorage* storage); @@ -3063,12 +1666,12 @@ CIMGUI_API void igColorConvertU32ToFloat4(ImVec4 *pOut,ImU32 in); CIMGUI_API ImU32 igColorConvertFloat4ToU32(const ImVec4 in); CIMGUI_API void igColorConvertRGBtoHSV(float r,float g,float b,float* out_h,float* out_s,float* out_v); CIMGUI_API void igColorConvertHSVtoRGB(float h,float s,float v,float* out_r,float* out_g,float* out_b); -CIMGUI_API int igGetKeyIndex(ImGuiKey imgui_key); -CIMGUI_API bool igIsKeyDown(int user_key_index); -CIMGUI_API bool igIsKeyPressed(int user_key_index,bool repeat); -CIMGUI_API bool igIsKeyReleased(int user_key_index); -CIMGUI_API int igGetKeyPressedAmount(int key_index,float repeat_delay,float rate); -CIMGUI_API void igCaptureKeyboardFromApp(bool want_capture_keyboard_value); +CIMGUI_API bool igIsKeyDown(ImGuiKey key); +CIMGUI_API bool igIsKeyPressed(ImGuiKey key,bool repeat); +CIMGUI_API bool igIsKeyReleased(ImGuiKey key); +CIMGUI_API int igGetKeyPressedAmount(ImGuiKey key,float repeat_delay,float rate); +CIMGUI_API const char* igGetKeyName(ImGuiKey key); +CIMGUI_API void igSetNextFrameWantCaptureKeyboard(bool want_capture_keyboard); CIMGUI_API bool igIsMouseDown(ImGuiMouseButton button); CIMGUI_API bool igIsMouseClicked(ImGuiMouseButton button,bool repeat); CIMGUI_API bool igIsMouseReleased(ImGuiMouseButton button); @@ -3084,13 +1687,14 @@ CIMGUI_API void igGetMouseDragDelta(ImVec2 *pOut,ImGuiMouseButton button,float l CIMGUI_API void igResetMouseDragDelta(ImGuiMouseButton button); CIMGUI_API ImGuiMouseCursor igGetMouseCursor(void); CIMGUI_API void igSetMouseCursor(ImGuiMouseCursor cursor_type); -CIMGUI_API void igCaptureMouseFromApp(bool want_capture_mouse_value); +CIMGUI_API void igSetNextFrameWantCaptureMouse(bool want_capture_mouse); CIMGUI_API const char* igGetClipboardText(void); CIMGUI_API void igSetClipboardText(const char* text); CIMGUI_API void igLoadIniSettingsFromDisk(const char* ini_filename); CIMGUI_API void igLoadIniSettingsFromMemory(const char* ini_data,size_t ini_size); CIMGUI_API void igSaveIniSettingsToDisk(const char* ini_filename); CIMGUI_API const char* igSaveIniSettingsToMemory(size_t* out_ini_size); +CIMGUI_API void igDebugTextEncoding(const char* text); CIMGUI_API bool igDebugCheckVersionAndDataLayout(const char* version_str,size_t sz_io,size_t sz_style,size_t sz_vec2,size_t sz_vec4,size_t sz_drawvert,size_t sz_drawidx); CIMGUI_API void igSetAllocatorFunctions(ImGuiMemAllocFunc alloc_func,ImGuiMemFreeFunc free_func,void* user_data); CIMGUI_API void igGetAllocatorFunctions(ImGuiMemAllocFunc* p_alloc_func,ImGuiMemFreeFunc* p_free_func,void** p_user_data); @@ -3105,10 +1709,18 @@ CIMGUI_API ImGuiViewport* igFindViewportByPlatformHandle(void* platform_handle); CIMGUI_API ImGuiStyle* ImGuiStyle_ImGuiStyle(void); CIMGUI_API void ImGuiStyle_destroy(ImGuiStyle* self); CIMGUI_API void ImGuiStyle_ScaleAllSizes(ImGuiStyle* self,float scale_factor); +CIMGUI_API void ImGuiIO_AddKeyEvent(ImGuiIO* self,ImGuiKey key,bool down); +CIMGUI_API void ImGuiIO_AddKeyAnalogEvent(ImGuiIO* self,ImGuiKey key,bool down,float v); +CIMGUI_API void ImGuiIO_AddMousePosEvent(ImGuiIO* self,float x,float y); +CIMGUI_API void ImGuiIO_AddMouseButtonEvent(ImGuiIO* self,int button,bool down); +CIMGUI_API void ImGuiIO_AddMouseWheelEvent(ImGuiIO* self,float wh_x,float wh_y); +CIMGUI_API void ImGuiIO_AddMouseViewportEvent(ImGuiIO* self,ImGuiID id); +CIMGUI_API void ImGuiIO_AddFocusEvent(ImGuiIO* self,bool focused); CIMGUI_API void ImGuiIO_AddInputCharacter(ImGuiIO* self,unsigned int c); CIMGUI_API void ImGuiIO_AddInputCharacterUTF16(ImGuiIO* self,ImWchar16 c); CIMGUI_API void ImGuiIO_AddInputCharactersUTF8(ImGuiIO* self,const char* str); -CIMGUI_API void ImGuiIO_AddFocusEvent(ImGuiIO* self,bool focused); +CIMGUI_API void ImGuiIO_SetKeyEventNativeData(ImGuiIO* self,ImGuiKey key,int native_keycode,int native_scancode,int native_legacy_index); +CIMGUI_API void ImGuiIO_SetAppAcceptingEvents(ImGuiIO* self,bool accepting_events); CIMGUI_API void ImGuiIO_ClearInputCharacters(ImGuiIO* self); CIMGUI_API void ImGuiIO_ClearInputKeys(ImGuiIO* self); CIMGUI_API ImGuiIO* ImGuiIO_ImGuiIO(void); @@ -3184,10 +1796,10 @@ CIMGUI_API bool ImGuiListClipper_Step(ImGuiListClipper* self); CIMGUI_API void ImGuiListClipper_ForceDisplayRangeByIndices(ImGuiListClipper* self,int item_min,int item_max); CIMGUI_API ImColor* ImColor_ImColor_Nil(void); CIMGUI_API void ImColor_destroy(ImColor* self); -CIMGUI_API ImColor* ImColor_ImColor_Int(int r,int g,int b,int a); -CIMGUI_API ImColor* ImColor_ImColor_U32(ImU32 rgba); CIMGUI_API ImColor* ImColor_ImColor_Float(float r,float g,float b,float a); CIMGUI_API ImColor* ImColor_ImColor_Vec4(const ImVec4 col); +CIMGUI_API ImColor* ImColor_ImColor_Int(int r,int g,int b,int a); +CIMGUI_API ImColor* ImColor_ImColor_U32(ImU32 rgba); CIMGUI_API void ImColor_SetHSV(ImColor* self,float h,float s,float v,float a); CIMGUI_API void ImColor_HSV(ImColor *pOut,float h,float s,float v,float a); CIMGUI_API ImDrawCmd* ImDrawCmd_ImDrawCmd(void); @@ -3202,7 +1814,7 @@ CIMGUI_API void ImDrawListSplitter_Merge(ImDrawListSplitter* self,ImDrawList* dr CIMGUI_API void ImDrawListSplitter_SetCurrentChannel(ImDrawListSplitter* self,ImDrawList* draw_list,int channel_idx); CIMGUI_API ImDrawList* ImDrawList_ImDrawList(const ImDrawListSharedData* shared_data); CIMGUI_API void ImDrawList_destroy(ImDrawList* self); -CIMGUI_API void ImDrawList_PushClipRect(ImDrawList* self,ImVec2 clip_rect_min,ImVec2 clip_rect_max,bool intersect_with_current_clip_rect); +CIMGUI_API void ImDrawList_PushClipRect(ImDrawList* self,const ImVec2 clip_rect_min,const ImVec2 clip_rect_max,bool intersect_with_current_clip_rect); CIMGUI_API void ImDrawList_PushClipRectFullScreen(ImDrawList* self); CIMGUI_API void ImDrawList_PopClipRect(ImDrawList* self); CIMGUI_API void ImDrawList_PushTextureID(ImDrawList* self,ImTextureID texture_id); @@ -3322,8 +1934,8 @@ CIMGUI_API bool ImFont_IsLoaded(ImFont* self); CIMGUI_API const char* ImFont_GetDebugName(ImFont* self); CIMGUI_API void ImFont_CalcTextSizeA(ImVec2 *pOut,ImFont* self,float size,float max_width,float wrap_width,const char* text_begin,const char* text_end,const char** remaining); CIMGUI_API const char* ImFont_CalcWordWrapPositionA(ImFont* self,float scale,const char* text,const char* text_end,float wrap_width); -CIMGUI_API void ImFont_RenderChar(ImFont* self,ImDrawList* draw_list,float size,ImVec2 pos,ImU32 col,ImWchar c); -CIMGUI_API void ImFont_RenderText(ImFont* self,ImDrawList* draw_list,float size,ImVec2 pos,ImU32 col,const ImVec4 clip_rect,const char* text_begin,const char* text_end,float wrap_width,bool cpu_fine_clip); +CIMGUI_API void ImFont_RenderChar(ImFont* self,ImDrawList* draw_list,float size,const ImVec2 pos,ImU32 col,ImWchar c); +CIMGUI_API void ImFont_RenderText(ImFont* self,ImDrawList* draw_list,float size,const ImVec2 pos,ImU32 col,const ImVec4 clip_rect,const char* text_begin,const char* text_end,float wrap_width,bool cpu_fine_clip); CIMGUI_API void ImFont_BuildLookupTable(ImFont* self); CIMGUI_API void ImFont_ClearOutputData(ImFont* self); CIMGUI_API void ImFont_GrowIndex(ImFont* self,int new_size); @@ -3339,602 +1951,9 @@ CIMGUI_API ImGuiPlatformIO* ImGuiPlatformIO_ImGuiPlatformIO(void); CIMGUI_API void ImGuiPlatformIO_destroy(ImGuiPlatformIO* self); CIMGUI_API ImGuiPlatformMonitor* ImGuiPlatformMonitor_ImGuiPlatformMonitor(void); CIMGUI_API void ImGuiPlatformMonitor_destroy(ImGuiPlatformMonitor* self); -CIMGUI_API ImGuiID igImHashData(const void* data,size_t data_size,ImU32 seed); -CIMGUI_API ImGuiID igImHashStr(const char* data,size_t data_size,ImU32 seed); -CIMGUI_API void igImQsort(void* base,size_t count,size_t size_of_element,int(*compare_func)(void const*,void const*)); -CIMGUI_API ImU32 igImAlphaBlendColors(ImU32 col_a,ImU32 col_b); -CIMGUI_API bool igImIsPowerOfTwo_Int(int v); -CIMGUI_API bool igImIsPowerOfTwo_U64(ImU64 v); -CIMGUI_API int igImUpperPowerOfTwo(int v); -CIMGUI_API int igImStricmp(const char* str1,const char* str2); -CIMGUI_API int igImStrnicmp(const char* str1,const char* str2,size_t count); -CIMGUI_API void igImStrncpy(char* dst,const char* src,size_t count); -CIMGUI_API char* igImStrdup(const char* str); -CIMGUI_API char* igImStrdupcpy(char* dst,size_t* p_dst_size,const char* str); -CIMGUI_API const char* igImStrchrRange(const char* str_begin,const char* str_end,char c); -CIMGUI_API int igImStrlenW(const ImWchar* str); -CIMGUI_API const char* igImStreolRange(const char* str,const char* str_end); -CIMGUI_API const ImWchar* igImStrbolW(const ImWchar* buf_mid_line,const ImWchar* buf_begin); -CIMGUI_API const char* igImStristr(const char* haystack,const char* haystack_end,const char* needle,const char* needle_end); -CIMGUI_API void igImStrTrimBlanks(char* str); -CIMGUI_API const char* igImStrSkipBlank(const char* str); -CIMGUI_API int igImFormatString(char* buf,size_t buf_size,const char* fmt,...); -CIMGUI_API int igImFormatStringV(char* buf,size_t buf_size,const char* fmt,va_list args); -CIMGUI_API const char* igImParseFormatFindStart(const char* format); -CIMGUI_API const char* igImParseFormatFindEnd(const char* format); -CIMGUI_API const char* igImParseFormatTrimDecorations(const char* format,char* buf,size_t buf_size); -CIMGUI_API int igImParseFormatPrecision(const char* format,int default_value); -CIMGUI_API bool igImCharIsBlankA(char c); -CIMGUI_API bool igImCharIsBlankW(unsigned int c); -CIMGUI_API const char* igImTextCharToUtf8(char out_buf[5],unsigned int c); -CIMGUI_API int igImTextStrToUtf8(char* out_buf,int out_buf_size,const ImWchar* in_text,const ImWchar* in_text_end); -CIMGUI_API int igImTextCharFromUtf8(unsigned int* out_char,const char* in_text,const char* in_text_end); -CIMGUI_API int igImTextStrFromUtf8(ImWchar* out_buf,int out_buf_size,const char* in_text,const char* in_text_end,const char** in_remaining); -CIMGUI_API int igImTextCountCharsFromUtf8(const char* in_text,const char* in_text_end); -CIMGUI_API int igImTextCountUtf8BytesFromChar(const char* in_text,const char* in_text_end); -CIMGUI_API int igImTextCountUtf8BytesFromStr(const ImWchar* in_text,const ImWchar* in_text_end); -CIMGUI_API ImFileHandle igImFileOpen(const char* filename,const char* mode); -CIMGUI_API bool igImFileClose(ImFileHandle file); -CIMGUI_API ImU64 igImFileGetSize(ImFileHandle file); -CIMGUI_API ImU64 igImFileRead(void* data,ImU64 size,ImU64 count,ImFileHandle file); -CIMGUI_API ImU64 igImFileWrite(const void* data,ImU64 size,ImU64 count,ImFileHandle file); -CIMGUI_API void* igImFileLoadToMemory(const char* filename,const char* mode,size_t* out_file_size,int padding_bytes); -CIMGUI_API float igImPow_Float(float x,float y); -CIMGUI_API double igImPow_double(double x,double y); -CIMGUI_API float igImLog_Float(float x); -CIMGUI_API double igImLog_double(double x); -CIMGUI_API int igImAbs_Int(int x); -CIMGUI_API float igImAbs_Float(float x); -CIMGUI_API double igImAbs_double(double x); -CIMGUI_API float igImSign_Float(float x); -CIMGUI_API double igImSign_double(double x); -CIMGUI_API float igImRsqrt_Float(float x); -CIMGUI_API double igImRsqrt_double(double x); -CIMGUI_API void igImMin(ImVec2 *pOut,const ImVec2 lhs,const ImVec2 rhs); -CIMGUI_API void igImMax(ImVec2 *pOut,const ImVec2 lhs,const ImVec2 rhs); -CIMGUI_API void igImClamp(ImVec2 *pOut,const ImVec2 v,const ImVec2 mn,ImVec2 mx); -CIMGUI_API void igImLerp_Vec2Float(ImVec2 *pOut,const ImVec2 a,const ImVec2 b,float t); -CIMGUI_API void igImLerp_Vec2Vec2(ImVec2 *pOut,const ImVec2 a,const ImVec2 b,const ImVec2 t); -CIMGUI_API void igImLerp_Vec4(ImVec4 *pOut,const ImVec4 a,const ImVec4 b,float t); -CIMGUI_API float igImSaturate(float f); -CIMGUI_API float igImLengthSqr_Vec2(const ImVec2 lhs); -CIMGUI_API float igImLengthSqr_Vec4(const ImVec4 lhs); -CIMGUI_API float igImInvLength(const ImVec2 lhs,float fail_value); -CIMGUI_API float igImFloor_Float(float f); -CIMGUI_API float igImFloorSigned(float f); -CIMGUI_API void igImFloor_Vec2(ImVec2 *pOut,const ImVec2 v); -CIMGUI_API int igImModPositive(int a,int b); -CIMGUI_API float igImDot(const ImVec2 a,const ImVec2 b); -CIMGUI_API void igImRotate(ImVec2 *pOut,const ImVec2 v,float cos_a,float sin_a); -CIMGUI_API float igImLinearSweep(float current,float target,float speed); -CIMGUI_API void igImMul(ImVec2 *pOut,const ImVec2 lhs,const ImVec2 rhs); -CIMGUI_API bool igImIsFloatAboveGuaranteedIntegerPrecision(float f); -CIMGUI_API void igImBezierCubicCalc(ImVec2 *pOut,const ImVec2 p1,const ImVec2 p2,const ImVec2 p3,const ImVec2 p4,float t); -CIMGUI_API void igImBezierCubicClosestPoint(ImVec2 *pOut,const ImVec2 p1,const ImVec2 p2,const ImVec2 p3,const ImVec2 p4,const ImVec2 p,int num_segments); -CIMGUI_API void igImBezierCubicClosestPointCasteljau(ImVec2 *pOut,const ImVec2 p1,const ImVec2 p2,const ImVec2 p3,const ImVec2 p4,const ImVec2 p,float tess_tol); -CIMGUI_API void igImBezierQuadraticCalc(ImVec2 *pOut,const ImVec2 p1,const ImVec2 p2,const ImVec2 p3,float t); -CIMGUI_API void igImLineClosestPoint(ImVec2 *pOut,const ImVec2 a,const ImVec2 b,const ImVec2 p); -CIMGUI_API bool igImTriangleContainsPoint(const ImVec2 a,const ImVec2 b,const ImVec2 c,const ImVec2 p); -CIMGUI_API void igImTriangleClosestPoint(ImVec2 *pOut,const ImVec2 a,const ImVec2 b,const ImVec2 c,const ImVec2 p); -CIMGUI_API void igImTriangleBarycentricCoords(const ImVec2 a,const ImVec2 b,const ImVec2 c,const ImVec2 p,float* out_u,float* out_v,float* out_w); -CIMGUI_API float igImTriangleArea(const ImVec2 a,const ImVec2 b,const ImVec2 c); -CIMGUI_API ImGuiDir igImGetDirQuadrantFromDelta(float dx,float dy); -CIMGUI_API ImVec1* ImVec1_ImVec1_Nil(void); -CIMGUI_API void ImVec1_destroy(ImVec1* self); -CIMGUI_API ImVec1* ImVec1_ImVec1_Float(float _x); -CIMGUI_API ImVec2ih* ImVec2ih_ImVec2ih_Nil(void); -CIMGUI_API void ImVec2ih_destroy(ImVec2ih* self); -CIMGUI_API ImVec2ih* ImVec2ih_ImVec2ih_short(short _x,short _y); -CIMGUI_API ImVec2ih* ImVec2ih_ImVec2ih_Vec2(const ImVec2 rhs); -CIMGUI_API ImRect* ImRect_ImRect_Nil(void); -CIMGUI_API void ImRect_destroy(ImRect* self); -CIMGUI_API ImRect* ImRect_ImRect_Vec2(const ImVec2 min,const ImVec2 max); -CIMGUI_API ImRect* ImRect_ImRect_Vec4(const ImVec4 v); -CIMGUI_API ImRect* ImRect_ImRect_Float(float x1,float y1,float x2,float y2); -CIMGUI_API void ImRect_GetCenter(ImVec2 *pOut,ImRect* self); -CIMGUI_API void ImRect_GetSize(ImVec2 *pOut,ImRect* self); -CIMGUI_API float ImRect_GetWidth(ImRect* self); -CIMGUI_API float ImRect_GetHeight(ImRect* self); -CIMGUI_API float ImRect_GetArea(ImRect* self); -CIMGUI_API void ImRect_GetTL(ImVec2 *pOut,ImRect* self); -CIMGUI_API void ImRect_GetTR(ImVec2 *pOut,ImRect* self); -CIMGUI_API void ImRect_GetBL(ImVec2 *pOut,ImRect* self); -CIMGUI_API void ImRect_GetBR(ImVec2 *pOut,ImRect* self); -CIMGUI_API bool ImRect_Contains_Vec2(ImRect* self,const ImVec2 p); -CIMGUI_API bool ImRect_Contains_Rect(ImRect* self,const ImRect r); -CIMGUI_API bool ImRect_Overlaps(ImRect* self,const ImRect r); -CIMGUI_API void ImRect_Add_Vec2(ImRect* self,const ImVec2 p); -CIMGUI_API void ImRect_Add_Rect(ImRect* self,const ImRect r); -CIMGUI_API void ImRect_Expand_Float(ImRect* self,const float amount); -CIMGUI_API void ImRect_Expand_Vec2(ImRect* self,const ImVec2 amount); -CIMGUI_API void ImRect_Translate(ImRect* self,const ImVec2 d); -CIMGUI_API void ImRect_TranslateX(ImRect* self,float dx); -CIMGUI_API void ImRect_TranslateY(ImRect* self,float dy); -CIMGUI_API void ImRect_ClipWith(ImRect* self,const ImRect r); -CIMGUI_API void ImRect_ClipWithFull(ImRect* self,const ImRect r); -CIMGUI_API void ImRect_Floor(ImRect* self); -CIMGUI_API bool ImRect_IsInverted(ImRect* self); -CIMGUI_API void ImRect_ToVec4(ImVec4 *pOut,ImRect* self); -CIMGUI_API bool igImBitArrayTestBit(const ImU32* arr,int n); -CIMGUI_API void igImBitArrayClearBit(ImU32* arr,int n); -CIMGUI_API void igImBitArraySetBit(ImU32* arr,int n); -CIMGUI_API void igImBitArraySetBitRange(ImU32* arr,int n,int n2); -CIMGUI_API void ImBitVector_Create(ImBitVector* self,int sz); -CIMGUI_API void ImBitVector_Clear(ImBitVector* self); -CIMGUI_API bool ImBitVector_TestBit(ImBitVector* self,int n); -CIMGUI_API void ImBitVector_SetBit(ImBitVector* self,int n); -CIMGUI_API void ImBitVector_ClearBit(ImBitVector* self,int n); -CIMGUI_API ImDrawListSharedData* ImDrawListSharedData_ImDrawListSharedData(void); -CIMGUI_API void ImDrawListSharedData_destroy(ImDrawListSharedData* self); -CIMGUI_API void ImDrawListSharedData_SetCircleTessellationMaxError(ImDrawListSharedData* self,float max_error); -CIMGUI_API void ImDrawDataBuilder_Clear(ImDrawDataBuilder* self); -CIMGUI_API void ImDrawDataBuilder_ClearFreeMemory(ImDrawDataBuilder* self); -CIMGUI_API int ImDrawDataBuilder_GetDrawListCount(ImDrawDataBuilder* self); -CIMGUI_API void ImDrawDataBuilder_FlattenIntoSingleLayer(ImDrawDataBuilder* self); -CIMGUI_API ImGuiStyleMod* ImGuiStyleMod_ImGuiStyleMod_Int(ImGuiStyleVar idx,int v); -CIMGUI_API void ImGuiStyleMod_destroy(ImGuiStyleMod* self); -CIMGUI_API ImGuiStyleMod* ImGuiStyleMod_ImGuiStyleMod_Float(ImGuiStyleVar idx,float v); -CIMGUI_API ImGuiStyleMod* ImGuiStyleMod_ImGuiStyleMod_Vec2(ImGuiStyleVar idx,ImVec2 v); -CIMGUI_API ImGuiComboPreviewData* ImGuiComboPreviewData_ImGuiComboPreviewData(void); -CIMGUI_API void ImGuiComboPreviewData_destroy(ImGuiComboPreviewData* self); -CIMGUI_API ImGuiMenuColumns* ImGuiMenuColumns_ImGuiMenuColumns(void); -CIMGUI_API void ImGuiMenuColumns_destroy(ImGuiMenuColumns* self); -CIMGUI_API void ImGuiMenuColumns_Update(ImGuiMenuColumns* self,float spacing,bool window_reappearing); -CIMGUI_API float ImGuiMenuColumns_DeclColumns(ImGuiMenuColumns* self,float w_icon,float w_label,float w_shortcut,float w_mark); -CIMGUI_API void ImGuiMenuColumns_CalcNextTotalWidth(ImGuiMenuColumns* self,bool update_offsets); -CIMGUI_API ImGuiInputTextState* ImGuiInputTextState_ImGuiInputTextState(void); -CIMGUI_API void ImGuiInputTextState_destroy(ImGuiInputTextState* self); -CIMGUI_API void ImGuiInputTextState_ClearText(ImGuiInputTextState* self); -CIMGUI_API void ImGuiInputTextState_ClearFreeMemory(ImGuiInputTextState* self); -CIMGUI_API int ImGuiInputTextState_GetUndoAvailCount(ImGuiInputTextState* self); -CIMGUI_API int ImGuiInputTextState_GetRedoAvailCount(ImGuiInputTextState* self); -CIMGUI_API void ImGuiInputTextState_OnKeyPressed(ImGuiInputTextState* self,int key); -CIMGUI_API void ImGuiInputTextState_CursorAnimReset(ImGuiInputTextState* self); -CIMGUI_API void ImGuiInputTextState_CursorClamp(ImGuiInputTextState* self); -CIMGUI_API bool ImGuiInputTextState_HasSelection(ImGuiInputTextState* self); -CIMGUI_API void ImGuiInputTextState_ClearSelection(ImGuiInputTextState* self); -CIMGUI_API int ImGuiInputTextState_GetCursorPos(ImGuiInputTextState* self); -CIMGUI_API int ImGuiInputTextState_GetSelectionStart(ImGuiInputTextState* self); -CIMGUI_API int ImGuiInputTextState_GetSelectionEnd(ImGuiInputTextState* self); -CIMGUI_API void ImGuiInputTextState_SelectAll(ImGuiInputTextState* self); -CIMGUI_API ImGuiPopupData* ImGuiPopupData_ImGuiPopupData(void); -CIMGUI_API void ImGuiPopupData_destroy(ImGuiPopupData* self); -CIMGUI_API ImGuiNextWindowData* ImGuiNextWindowData_ImGuiNextWindowData(void); -CIMGUI_API void ImGuiNextWindowData_destroy(ImGuiNextWindowData* self); -CIMGUI_API void ImGuiNextWindowData_ClearFlags(ImGuiNextWindowData* self); -CIMGUI_API ImGuiNextItemData* ImGuiNextItemData_ImGuiNextItemData(void); -CIMGUI_API void ImGuiNextItemData_destroy(ImGuiNextItemData* self); -CIMGUI_API void ImGuiNextItemData_ClearFlags(ImGuiNextItemData* self); -CIMGUI_API ImGuiLastItemData* ImGuiLastItemData_ImGuiLastItemData(void); -CIMGUI_API void ImGuiLastItemData_destroy(ImGuiLastItemData* self); -CIMGUI_API ImGuiStackSizes* ImGuiStackSizes_ImGuiStackSizes(void); -CIMGUI_API void ImGuiStackSizes_destroy(ImGuiStackSizes* self); -CIMGUI_API void ImGuiStackSizes_SetToCurrentState(ImGuiStackSizes* self); -CIMGUI_API void ImGuiStackSizes_CompareWithCurrentState(ImGuiStackSizes* self); -CIMGUI_API ImGuiPtrOrIndex* ImGuiPtrOrIndex_ImGuiPtrOrIndex_Ptr(void* ptr); -CIMGUI_API void ImGuiPtrOrIndex_destroy(ImGuiPtrOrIndex* self); -CIMGUI_API ImGuiPtrOrIndex* ImGuiPtrOrIndex_ImGuiPtrOrIndex_Int(int index); -CIMGUI_API ImGuiListClipperRange ImGuiListClipperRange_FromIndices(int min,int max); -CIMGUI_API ImGuiListClipperRange ImGuiListClipperRange_FromPositions(float y1,float y2,int off_min,int off_max); -CIMGUI_API ImGuiListClipperData* ImGuiListClipperData_ImGuiListClipperData(void); -CIMGUI_API void ImGuiListClipperData_destroy(ImGuiListClipperData* self); -CIMGUI_API void ImGuiListClipperData_Reset(ImGuiListClipperData* self,ImGuiListClipper* clipper); -CIMGUI_API ImGuiNavItemData* ImGuiNavItemData_ImGuiNavItemData(void); -CIMGUI_API void ImGuiNavItemData_destroy(ImGuiNavItemData* self); -CIMGUI_API void ImGuiNavItemData_Clear(ImGuiNavItemData* self); -CIMGUI_API ImGuiOldColumnData* ImGuiOldColumnData_ImGuiOldColumnData(void); -CIMGUI_API void ImGuiOldColumnData_destroy(ImGuiOldColumnData* self); -CIMGUI_API ImGuiOldColumns* ImGuiOldColumns_ImGuiOldColumns(void); -CIMGUI_API void ImGuiOldColumns_destroy(ImGuiOldColumns* self); -CIMGUI_API ImGuiDockNode* ImGuiDockNode_ImGuiDockNode(ImGuiID id); -CIMGUI_API void ImGuiDockNode_destroy(ImGuiDockNode* self); -CIMGUI_API bool ImGuiDockNode_IsRootNode(ImGuiDockNode* self); -CIMGUI_API bool ImGuiDockNode_IsDockSpace(ImGuiDockNode* self); -CIMGUI_API bool ImGuiDockNode_IsFloatingNode(ImGuiDockNode* self); -CIMGUI_API bool ImGuiDockNode_IsCentralNode(ImGuiDockNode* self); -CIMGUI_API bool ImGuiDockNode_IsHiddenTabBar(ImGuiDockNode* self); -CIMGUI_API bool ImGuiDockNode_IsNoTabBar(ImGuiDockNode* self); -CIMGUI_API bool ImGuiDockNode_IsSplitNode(ImGuiDockNode* self); -CIMGUI_API bool ImGuiDockNode_IsLeafNode(ImGuiDockNode* self); -CIMGUI_API bool ImGuiDockNode_IsEmpty(ImGuiDockNode* self); -CIMGUI_API void ImGuiDockNode_Rect(ImRect *pOut,ImGuiDockNode* self); -CIMGUI_API void ImGuiDockNode_SetLocalFlags(ImGuiDockNode* self,ImGuiDockNodeFlags flags); -CIMGUI_API void ImGuiDockNode_UpdateMergedFlags(ImGuiDockNode* self); -CIMGUI_API ImGuiDockContext* ImGuiDockContext_ImGuiDockContext(void); -CIMGUI_API void ImGuiDockContext_destroy(ImGuiDockContext* self); -CIMGUI_API ImGuiViewportP* ImGuiViewportP_ImGuiViewportP(void); -CIMGUI_API void ImGuiViewportP_destroy(ImGuiViewportP* self); -CIMGUI_API void ImGuiViewportP_ClearRequestFlags(ImGuiViewportP* self); -CIMGUI_API void ImGuiViewportP_CalcWorkRectPos(ImVec2 *pOut,ImGuiViewportP* self,const ImVec2 off_min); -CIMGUI_API void ImGuiViewportP_CalcWorkRectSize(ImVec2 *pOut,ImGuiViewportP* self,const ImVec2 off_min,const ImVec2 off_max); -CIMGUI_API void ImGuiViewportP_UpdateWorkRect(ImGuiViewportP* self); -CIMGUI_API void ImGuiViewportP_GetMainRect(ImRect *pOut,ImGuiViewportP* self); -CIMGUI_API void ImGuiViewportP_GetWorkRect(ImRect *pOut,ImGuiViewportP* self); -CIMGUI_API void ImGuiViewportP_GetBuildWorkRect(ImRect *pOut,ImGuiViewportP* self); -CIMGUI_API ImGuiWindowSettings* ImGuiWindowSettings_ImGuiWindowSettings(void); -CIMGUI_API void ImGuiWindowSettings_destroy(ImGuiWindowSettings* self); -CIMGUI_API char* ImGuiWindowSettings_GetName(ImGuiWindowSettings* self); -CIMGUI_API ImGuiSettingsHandler* ImGuiSettingsHandler_ImGuiSettingsHandler(void); -CIMGUI_API void ImGuiSettingsHandler_destroy(ImGuiSettingsHandler* self); -CIMGUI_API ImGuiMetricsConfig* ImGuiMetricsConfig_ImGuiMetricsConfig(void); -CIMGUI_API void ImGuiMetricsConfig_destroy(ImGuiMetricsConfig* self); -CIMGUI_API ImGuiStackLevelInfo* ImGuiStackLevelInfo_ImGuiStackLevelInfo(void); -CIMGUI_API void ImGuiStackLevelInfo_destroy(ImGuiStackLevelInfo* self); -CIMGUI_API ImGuiStackTool* ImGuiStackTool_ImGuiStackTool(void); -CIMGUI_API void ImGuiStackTool_destroy(ImGuiStackTool* self); -CIMGUI_API ImGuiContextHook* ImGuiContextHook_ImGuiContextHook(void); -CIMGUI_API void ImGuiContextHook_destroy(ImGuiContextHook* self); -CIMGUI_API ImGuiContext* ImGuiContext_ImGuiContext(ImFontAtlas* shared_font_atlas); -CIMGUI_API void ImGuiContext_destroy(ImGuiContext* self); -CIMGUI_API ImGuiWindow* ImGuiWindow_ImGuiWindow(ImGuiContext* context,const char* name); -CIMGUI_API void ImGuiWindow_destroy(ImGuiWindow* self); -CIMGUI_API ImGuiID ImGuiWindow_GetID_Str(ImGuiWindow* self,const char* str,const char* str_end); -CIMGUI_API ImGuiID ImGuiWindow_GetID_Ptr(ImGuiWindow* self,const void* ptr); -CIMGUI_API ImGuiID ImGuiWindow_GetID_Int(ImGuiWindow* self,int n); -CIMGUI_API ImGuiID ImGuiWindow_GetIDNoKeepAlive_Str(ImGuiWindow* self,const char* str,const char* str_end); -CIMGUI_API ImGuiID ImGuiWindow_GetIDNoKeepAlive_Ptr(ImGuiWindow* self,const void* ptr); -CIMGUI_API ImGuiID ImGuiWindow_GetIDNoKeepAlive_Int(ImGuiWindow* self,int n); -CIMGUI_API ImGuiID ImGuiWindow_GetIDFromRectangle(ImGuiWindow* self,const ImRect r_abs); -CIMGUI_API void ImGuiWindow_Rect(ImRect *pOut,ImGuiWindow* self); -CIMGUI_API float ImGuiWindow_CalcFontSize(ImGuiWindow* self); -CIMGUI_API float ImGuiWindow_TitleBarHeight(ImGuiWindow* self); -CIMGUI_API void ImGuiWindow_TitleBarRect(ImRect *pOut,ImGuiWindow* self); -CIMGUI_API float ImGuiWindow_MenuBarHeight(ImGuiWindow* self); -CIMGUI_API void ImGuiWindow_MenuBarRect(ImRect *pOut,ImGuiWindow* self); -CIMGUI_API ImGuiTabItem* ImGuiTabItem_ImGuiTabItem(void); -CIMGUI_API void ImGuiTabItem_destroy(ImGuiTabItem* self); -CIMGUI_API ImGuiTabBar* ImGuiTabBar_ImGuiTabBar(void); -CIMGUI_API void ImGuiTabBar_destroy(ImGuiTabBar* self); -CIMGUI_API int ImGuiTabBar_GetTabOrder(ImGuiTabBar* self,const ImGuiTabItem* tab); -CIMGUI_API const char* ImGuiTabBar_GetTabName(ImGuiTabBar* self,const ImGuiTabItem* tab); -CIMGUI_API ImGuiTableColumn* ImGuiTableColumn_ImGuiTableColumn(void); -CIMGUI_API void ImGuiTableColumn_destroy(ImGuiTableColumn* self); -CIMGUI_API ImGuiTable* ImGuiTable_ImGuiTable(void); -CIMGUI_API void ImGuiTable_destroy(ImGuiTable* self); -CIMGUI_API ImGuiTableTempData* ImGuiTableTempData_ImGuiTableTempData(void); -CIMGUI_API void ImGuiTableTempData_destroy(ImGuiTableTempData* self); -CIMGUI_API ImGuiTableColumnSettings* ImGuiTableColumnSettings_ImGuiTableColumnSettings(void); -CIMGUI_API void ImGuiTableColumnSettings_destroy(ImGuiTableColumnSettings* self); -CIMGUI_API ImGuiTableSettings* ImGuiTableSettings_ImGuiTableSettings(void); -CIMGUI_API void ImGuiTableSettings_destroy(ImGuiTableSettings* self); -CIMGUI_API ImGuiTableColumnSettings* ImGuiTableSettings_GetColumnSettings(ImGuiTableSettings* self); -CIMGUI_API ImGuiWindow* igGetCurrentWindowRead(void); -CIMGUI_API ImGuiWindow* igGetCurrentWindow(void); -CIMGUI_API ImGuiWindow* igFindWindowByID(ImGuiID id); -CIMGUI_API ImGuiWindow* igFindWindowByName(const char* name); -CIMGUI_API void igUpdateWindowParentAndRootLinks(ImGuiWindow* window,ImGuiWindowFlags flags,ImGuiWindow* parent_window); -CIMGUI_API void igCalcWindowNextAutoFitSize(ImVec2 *pOut,ImGuiWindow* window); -CIMGUI_API bool igIsWindowChildOf(ImGuiWindow* window,ImGuiWindow* potential_parent,bool popup_hierarchy,bool dock_hierarchy); -CIMGUI_API bool igIsWindowWithinBeginStackOf(ImGuiWindow* window,ImGuiWindow* potential_parent); -CIMGUI_API bool igIsWindowAbove(ImGuiWindow* potential_above,ImGuiWindow* potential_below); -CIMGUI_API bool igIsWindowNavFocusable(ImGuiWindow* window); -CIMGUI_API void igSetWindowPos_WindowPtr(ImGuiWindow* window,const ImVec2 pos,ImGuiCond cond); -CIMGUI_API void igSetWindowSize_WindowPtr(ImGuiWindow* window,const ImVec2 size,ImGuiCond cond); -CIMGUI_API void igSetWindowCollapsed_WindowPtr(ImGuiWindow* window,bool collapsed,ImGuiCond cond); -CIMGUI_API void igSetWindowHitTestHole(ImGuiWindow* window,const ImVec2 pos,const ImVec2 size); -CIMGUI_API void igWindowRectAbsToRel(ImRect *pOut,ImGuiWindow* window,const ImRect r); -CIMGUI_API void igWindowRectRelToAbs(ImRect *pOut,ImGuiWindow* window,const ImRect r); -CIMGUI_API void igFocusWindow(ImGuiWindow* window); -CIMGUI_API void igFocusTopMostWindowUnderOne(ImGuiWindow* under_this_window,ImGuiWindow* ignore_window); -CIMGUI_API void igBringWindowToFocusFront(ImGuiWindow* window); -CIMGUI_API void igBringWindowToDisplayFront(ImGuiWindow* window); -CIMGUI_API void igBringWindowToDisplayBack(ImGuiWindow* window); -CIMGUI_API void igBringWindowToDisplayBehind(ImGuiWindow* window,ImGuiWindow* above_window); -CIMGUI_API int igFindWindowDisplayIndex(ImGuiWindow* window); -CIMGUI_API ImGuiWindow* igFindBottomMostVisibleWindowWithinBeginStack(ImGuiWindow* window); -CIMGUI_API void igSetCurrentFont(ImFont* font); -CIMGUI_API ImFont* igGetDefaultFont(void); -CIMGUI_API ImDrawList* igGetForegroundDrawList_WindowPtr(ImGuiWindow* window); -CIMGUI_API void igInitialize(ImGuiContext* context); -CIMGUI_API void igShutdown(ImGuiContext* context); -CIMGUI_API void igUpdateHoveredWindowAndCaptureFlags(void); -CIMGUI_API void igStartMouseMovingWindow(ImGuiWindow* window); -CIMGUI_API void igStartMouseMovingWindowOrNode(ImGuiWindow* window,ImGuiDockNode* node,bool undock_floating_node); -CIMGUI_API void igUpdateMouseMovingWindowNewFrame(void); -CIMGUI_API void igUpdateMouseMovingWindowEndFrame(void); -CIMGUI_API ImGuiID igAddContextHook(ImGuiContext* context,const ImGuiContextHook* hook); -CIMGUI_API void igRemoveContextHook(ImGuiContext* context,ImGuiID hook_to_remove); -CIMGUI_API void igCallContextHooks(ImGuiContext* context,ImGuiContextHookType type); -CIMGUI_API void igTranslateWindowsInViewport(ImGuiViewportP* viewport,const ImVec2 old_pos,const ImVec2 new_pos); -CIMGUI_API void igScaleWindowsInViewport(ImGuiViewportP* viewport,float scale); -CIMGUI_API void igDestroyPlatformWindow(ImGuiViewportP* viewport); -CIMGUI_API void igSetCurrentViewport(ImGuiWindow* window,ImGuiViewportP* viewport); -CIMGUI_API const ImGuiPlatformMonitor* igGetViewportPlatformMonitor(ImGuiViewport* viewport); -CIMGUI_API void igMarkIniSettingsDirty_Nil(void); -CIMGUI_API void igMarkIniSettingsDirty_WindowPtr(ImGuiWindow* window); -CIMGUI_API void igClearIniSettings(void); -CIMGUI_API ImGuiWindowSettings* igCreateNewWindowSettings(const char* name); -CIMGUI_API ImGuiWindowSettings* igFindWindowSettings(ImGuiID id); -CIMGUI_API ImGuiWindowSettings* igFindOrCreateWindowSettings(const char* name); -CIMGUI_API ImGuiSettingsHandler* igFindSettingsHandler(const char* type_name); -CIMGUI_API void igSetNextWindowScroll(const ImVec2 scroll); -CIMGUI_API void igSetScrollX_WindowPtr(ImGuiWindow* window,float scroll_x); -CIMGUI_API void igSetScrollY_WindowPtr(ImGuiWindow* window,float scroll_y); -CIMGUI_API void igSetScrollFromPosX_WindowPtr(ImGuiWindow* window,float local_x,float center_x_ratio); -CIMGUI_API void igSetScrollFromPosY_WindowPtr(ImGuiWindow* window,float local_y,float center_y_ratio); -CIMGUI_API void igScrollToItem(ImGuiScrollFlags flags); -CIMGUI_API void igScrollToRect(ImGuiWindow* window,const ImRect rect,ImGuiScrollFlags flags); -CIMGUI_API void igScrollToRectEx(ImVec2 *pOut,ImGuiWindow* window,const ImRect rect,ImGuiScrollFlags flags); -CIMGUI_API void igScrollToBringRectIntoView(ImGuiWindow* window,const ImRect rect); -CIMGUI_API ImGuiID igGetItemID(void); -CIMGUI_API ImGuiItemStatusFlags igGetItemStatusFlags(void); -CIMGUI_API ImGuiItemFlags igGetItemFlags(void); -CIMGUI_API ImGuiID igGetActiveID(void); -CIMGUI_API ImGuiID igGetFocusID(void); -CIMGUI_API void igSetActiveID(ImGuiID id,ImGuiWindow* window); -CIMGUI_API void igSetFocusID(ImGuiID id,ImGuiWindow* window); -CIMGUI_API void igClearActiveID(void); -CIMGUI_API ImGuiID igGetHoveredID(void); -CIMGUI_API void igSetHoveredID(ImGuiID id); -CIMGUI_API void igKeepAliveID(ImGuiID id); -CIMGUI_API void igMarkItemEdited(ImGuiID id); -CIMGUI_API void igPushOverrideID(ImGuiID id); -CIMGUI_API ImGuiID igGetIDWithSeed(const char* str_id_begin,const char* str_id_end,ImGuiID seed); -CIMGUI_API void igItemSize_Vec2(const ImVec2 size,float text_baseline_y); -CIMGUI_API void igItemSize_Rect(const ImRect bb,float text_baseline_y); -CIMGUI_API bool igItemAdd(const ImRect bb,ImGuiID id,const ImRect* nav_bb,ImGuiItemFlags extra_flags); -CIMGUI_API bool igItemHoverable(const ImRect bb,ImGuiID id); -CIMGUI_API bool igIsClippedEx(const ImRect bb,ImGuiID id); -CIMGUI_API void igSetLastItemData(ImGuiID item_id,ImGuiItemFlags in_flags,ImGuiItemStatusFlags status_flags,const ImRect item_rect); -CIMGUI_API void igCalcItemSize(ImVec2 *pOut,ImVec2 size,float default_w,float default_h); -CIMGUI_API float igCalcWrapWidthForPos(const ImVec2 pos,float wrap_pos_x); -CIMGUI_API void igPushMultiItemsWidths(int components,float width_full); -CIMGUI_API bool igIsItemToggledSelection(void); -CIMGUI_API void igGetContentRegionMaxAbs(ImVec2 *pOut); -CIMGUI_API void igShrinkWidths(ImGuiShrinkWidthItem* items,int count,float width_excess); -CIMGUI_API void igPushItemFlag(ImGuiItemFlags option,bool enabled); -CIMGUI_API void igPopItemFlag(void); -CIMGUI_API void igLogBegin(ImGuiLogType type,int auto_open_depth); -CIMGUI_API void igLogToBuffer(int auto_open_depth); -CIMGUI_API void igLogRenderedText(const ImVec2* ref_pos,const char* text,const char* text_end); -CIMGUI_API void igLogSetNextTextDecoration(const char* prefix,const char* suffix); -CIMGUI_API bool igBeginChildEx(const char* name,ImGuiID id,const ImVec2 size_arg,bool border,ImGuiWindowFlags flags); -CIMGUI_API void igOpenPopupEx(ImGuiID id,ImGuiPopupFlags popup_flags); -CIMGUI_API void igClosePopupToLevel(int remaining,bool restore_focus_to_window_under_popup); -CIMGUI_API void igClosePopupsOverWindow(ImGuiWindow* ref_window,bool restore_focus_to_window_under_popup); -CIMGUI_API void igClosePopupsExceptModals(void); -CIMGUI_API bool igIsPopupOpen_ID(ImGuiID id,ImGuiPopupFlags popup_flags); -CIMGUI_API bool igBeginPopupEx(ImGuiID id,ImGuiWindowFlags extra_flags); -CIMGUI_API void igBeginTooltipEx(ImGuiTooltipFlags tooltip_flags,ImGuiWindowFlags extra_window_flags); -CIMGUI_API void igGetPopupAllowedExtentRect(ImRect *pOut,ImGuiWindow* window); -CIMGUI_API ImGuiWindow* igGetTopMostPopupModal(void); -CIMGUI_API ImGuiWindow* igGetTopMostAndVisiblePopupModal(void); -CIMGUI_API void igFindBestWindowPosForPopup(ImVec2 *pOut,ImGuiWindow* window); -CIMGUI_API void igFindBestWindowPosForPopupEx(ImVec2 *pOut,const ImVec2 ref_pos,const ImVec2 size,ImGuiDir* last_dir,const ImRect r_outer,const ImRect r_avoid,ImGuiPopupPositionPolicy policy); -CIMGUI_API bool igBeginViewportSideBar(const char* name,ImGuiViewport* viewport,ImGuiDir dir,float size,ImGuiWindowFlags window_flags); -CIMGUI_API bool igBeginMenuEx(const char* label,const char* icon,bool enabled); -CIMGUI_API bool igMenuItemEx(const char* label,const char* icon,const char* shortcut,bool selected,bool enabled); -CIMGUI_API bool igBeginComboPopup(ImGuiID popup_id,const ImRect bb,ImGuiComboFlags flags); -CIMGUI_API bool igBeginComboPreview(void); -CIMGUI_API void igEndComboPreview(void); -CIMGUI_API void igNavInitWindow(ImGuiWindow* window,bool force_reinit); -CIMGUI_API void igNavInitRequestApplyResult(void); -CIMGUI_API bool igNavMoveRequestButNoResultYet(void); -CIMGUI_API void igNavMoveRequestSubmit(ImGuiDir move_dir,ImGuiDir clip_dir,ImGuiNavMoveFlags move_flags,ImGuiScrollFlags scroll_flags); -CIMGUI_API void igNavMoveRequestForward(ImGuiDir move_dir,ImGuiDir clip_dir,ImGuiNavMoveFlags move_flags,ImGuiScrollFlags scroll_flags); -CIMGUI_API void igNavMoveRequestResolveWithLastItem(ImGuiNavItemData* result); -CIMGUI_API void igNavMoveRequestCancel(void); -CIMGUI_API void igNavMoveRequestApplyResult(void); -CIMGUI_API void igNavMoveRequestTryWrapping(ImGuiWindow* window,ImGuiNavMoveFlags move_flags); -CIMGUI_API float igGetNavInputAmount(ImGuiNavInput n,ImGuiInputReadMode mode); -CIMGUI_API void igGetNavInputAmount2d(ImVec2 *pOut,ImGuiNavDirSourceFlags dir_sources,ImGuiInputReadMode mode,float slow_factor,float fast_factor); -CIMGUI_API int igCalcTypematicRepeatAmount(float t0,float t1,float repeat_delay,float repeat_rate); -CIMGUI_API void igActivateItem(ImGuiID id); -CIMGUI_API void igSetNavID(ImGuiID id,ImGuiNavLayer nav_layer,ImGuiID focus_scope_id,const ImRect rect_rel); -CIMGUI_API void igPushFocusScope(ImGuiID id); -CIMGUI_API void igPopFocusScope(void); -CIMGUI_API ImGuiID igGetFocusedFocusScope(void); -CIMGUI_API ImGuiID igGetFocusScope(void); -CIMGUI_API void igSetItemUsingMouseWheel(void); -CIMGUI_API void igSetActiveIdUsingNavAndKeys(void); -CIMGUI_API bool igIsActiveIdUsingNavDir(ImGuiDir dir); -CIMGUI_API bool igIsActiveIdUsingNavInput(ImGuiNavInput input); -CIMGUI_API bool igIsActiveIdUsingKey(ImGuiKey key); -CIMGUI_API bool igIsMouseDragPastThreshold(ImGuiMouseButton button,float lock_threshold); -CIMGUI_API bool igIsKeyPressedMap(ImGuiKey key,bool repeat); -CIMGUI_API bool igIsNavInputDown(ImGuiNavInput n); -CIMGUI_API bool igIsNavInputTest(ImGuiNavInput n,ImGuiInputReadMode rm); -CIMGUI_API ImGuiKeyModFlags igGetMergedKeyModFlags(void); -CIMGUI_API void igDockContextInitialize(ImGuiContext* ctx); -CIMGUI_API void igDockContextShutdown(ImGuiContext* ctx); -CIMGUI_API void igDockContextClearNodes(ImGuiContext* ctx,ImGuiID root_id,bool clear_settings_refs); -CIMGUI_API void igDockContextRebuildNodes(ImGuiContext* ctx); -CIMGUI_API void igDockContextNewFrameUpdateUndocking(ImGuiContext* ctx); -CIMGUI_API void igDockContextNewFrameUpdateDocking(ImGuiContext* ctx); -CIMGUI_API void igDockContextEndFrame(ImGuiContext* ctx); -CIMGUI_API ImGuiID igDockContextGenNodeID(ImGuiContext* ctx); -CIMGUI_API void igDockContextQueueDock(ImGuiContext* ctx,ImGuiWindow* target,ImGuiDockNode* target_node,ImGuiWindow* payload,ImGuiDir split_dir,float split_ratio,bool split_outer); -CIMGUI_API void igDockContextQueueUndockWindow(ImGuiContext* ctx,ImGuiWindow* window); -CIMGUI_API void igDockContextQueueUndockNode(ImGuiContext* ctx,ImGuiDockNode* node); -CIMGUI_API bool igDockContextCalcDropPosForDocking(ImGuiWindow* target,ImGuiDockNode* target_node,ImGuiWindow* payload,ImGuiDir split_dir,bool split_outer,ImVec2* out_pos); -CIMGUI_API bool igDockNodeBeginAmendTabBar(ImGuiDockNode* node); -CIMGUI_API void igDockNodeEndAmendTabBar(void); -CIMGUI_API ImGuiDockNode* igDockNodeGetRootNode(ImGuiDockNode* node); -CIMGUI_API bool igDockNodeIsInHierarchyOf(ImGuiDockNode* node,ImGuiDockNode* parent); -CIMGUI_API int igDockNodeGetDepth(const ImGuiDockNode* node); -CIMGUI_API ImGuiID igDockNodeGetWindowMenuButtonId(const ImGuiDockNode* node); -CIMGUI_API ImGuiDockNode* igGetWindowDockNode(void); -CIMGUI_API bool igGetWindowAlwaysWantOwnTabBar(ImGuiWindow* window); -CIMGUI_API void igBeginDocked(ImGuiWindow* window,bool* p_open); -CIMGUI_API void igBeginDockableDragDropSource(ImGuiWindow* window); -CIMGUI_API void igBeginDockableDragDropTarget(ImGuiWindow* window); -CIMGUI_API void igSetWindowDock(ImGuiWindow* window,ImGuiID dock_id,ImGuiCond cond); -CIMGUI_API void igDockBuilderDockWindow(const char* window_name,ImGuiID node_id); -CIMGUI_API ImGuiDockNode* igDockBuilderGetNode(ImGuiID node_id); -CIMGUI_API ImGuiDockNode* igDockBuilderGetCentralNode(ImGuiID node_id); -CIMGUI_API ImGuiID igDockBuilderAddNode(ImGuiID node_id,ImGuiDockNodeFlags flags); -CIMGUI_API void igDockBuilderRemoveNode(ImGuiID node_id); -CIMGUI_API void igDockBuilderRemoveNodeDockedWindows(ImGuiID node_id,bool clear_settings_refs); -CIMGUI_API void igDockBuilderRemoveNodeChildNodes(ImGuiID node_id); -CIMGUI_API void igDockBuilderSetNodePos(ImGuiID node_id,ImVec2 pos); -CIMGUI_API void igDockBuilderSetNodeSize(ImGuiID node_id,ImVec2 size); -CIMGUI_API ImGuiID igDockBuilderSplitNode(ImGuiID node_id,ImGuiDir split_dir,float size_ratio_for_node_at_dir,ImGuiID* out_id_at_dir,ImGuiID* out_id_at_opposite_dir); -CIMGUI_API void igDockBuilderCopyDockSpace(ImGuiID src_dockspace_id,ImGuiID dst_dockspace_id,ImVector_const_charPtr* in_window_remap_pairs); -CIMGUI_API void igDockBuilderCopyNode(ImGuiID src_node_id,ImGuiID dst_node_id,ImVector_ImGuiID* out_node_remap_pairs); -CIMGUI_API void igDockBuilderCopyWindowSettings(const char* src_name,const char* dst_name); -CIMGUI_API void igDockBuilderFinish(ImGuiID node_id); -CIMGUI_API bool igBeginDragDropTargetCustom(const ImRect bb,ImGuiID id); -CIMGUI_API void igClearDragDrop(void); -CIMGUI_API bool igIsDragDropPayloadBeingAccepted(void); -CIMGUI_API void igSetWindowClipRectBeforeSetChannel(ImGuiWindow* window,const ImRect clip_rect); -CIMGUI_API void igBeginColumns(const char* str_id,int count,ImGuiOldColumnFlags flags); -CIMGUI_API void igEndColumns(void); -CIMGUI_API void igPushColumnClipRect(int column_index); -CIMGUI_API void igPushColumnsBackground(void); -CIMGUI_API void igPopColumnsBackground(void); -CIMGUI_API ImGuiID igGetColumnsID(const char* str_id,int count); -CIMGUI_API ImGuiOldColumns* igFindOrCreateColumns(ImGuiWindow* window,ImGuiID id); -CIMGUI_API float igGetColumnOffsetFromNorm(const ImGuiOldColumns* columns,float offset_norm); -CIMGUI_API float igGetColumnNormFromOffset(const ImGuiOldColumns* columns,float offset); -CIMGUI_API void igTableOpenContextMenu(int column_n); -CIMGUI_API void igTableSetColumnWidth(int column_n,float width); -CIMGUI_API void igTableSetColumnSortDirection(int column_n,ImGuiSortDirection sort_direction,bool append_to_sort_specs); -CIMGUI_API int igTableGetHoveredColumn(void); -CIMGUI_API float igTableGetHeaderRowHeight(void); -CIMGUI_API void igTablePushBackgroundChannel(void); -CIMGUI_API void igTablePopBackgroundChannel(void); -CIMGUI_API ImGuiTable* igGetCurrentTable(void); -CIMGUI_API ImGuiTable* igTableFindByID(ImGuiID id); -CIMGUI_API bool igBeginTableEx(const char* name,ImGuiID id,int columns_count,ImGuiTableFlags flags,const ImVec2 outer_size,float inner_width); -CIMGUI_API void igTableBeginInitMemory(ImGuiTable* table,int columns_count); -CIMGUI_API void igTableBeginApplyRequests(ImGuiTable* table); -CIMGUI_API void igTableSetupDrawChannels(ImGuiTable* table); -CIMGUI_API void igTableUpdateLayout(ImGuiTable* table); -CIMGUI_API void igTableUpdateBorders(ImGuiTable* table); -CIMGUI_API void igTableUpdateColumnsWeightFromWidth(ImGuiTable* table); -CIMGUI_API void igTableDrawBorders(ImGuiTable* table); -CIMGUI_API void igTableDrawContextMenu(ImGuiTable* table); -CIMGUI_API void igTableMergeDrawChannels(ImGuiTable* table); -CIMGUI_API void igTableSortSpecsSanitize(ImGuiTable* table); -CIMGUI_API void igTableSortSpecsBuild(ImGuiTable* table); -CIMGUI_API ImGuiSortDirection igTableGetColumnNextSortDirection(ImGuiTableColumn* column); -CIMGUI_API void igTableFixColumnSortDirection(ImGuiTable* table,ImGuiTableColumn* column); -CIMGUI_API float igTableGetColumnWidthAuto(ImGuiTable* table,ImGuiTableColumn* column); -CIMGUI_API void igTableBeginRow(ImGuiTable* table); -CIMGUI_API void igTableEndRow(ImGuiTable* table); -CIMGUI_API void igTableBeginCell(ImGuiTable* table,int column_n); -CIMGUI_API void igTableEndCell(ImGuiTable* table); -CIMGUI_API void igTableGetCellBgRect(ImRect *pOut,const ImGuiTable* table,int column_n); -CIMGUI_API const char* igTableGetColumnName_TablePtr(const ImGuiTable* table,int column_n); -CIMGUI_API ImGuiID igTableGetColumnResizeID(const ImGuiTable* table,int column_n,int instance_no); -CIMGUI_API float igTableGetMaxColumnWidth(const ImGuiTable* table,int column_n); -CIMGUI_API void igTableSetColumnWidthAutoSingle(ImGuiTable* table,int column_n); -CIMGUI_API void igTableSetColumnWidthAutoAll(ImGuiTable* table); -CIMGUI_API void igTableRemove(ImGuiTable* table); -CIMGUI_API void igTableGcCompactTransientBuffers_TablePtr(ImGuiTable* table); -CIMGUI_API void igTableGcCompactTransientBuffers_TableTempDataPtr(ImGuiTableTempData* table); -CIMGUI_API void igTableGcCompactSettings(void); -CIMGUI_API void igTableLoadSettings(ImGuiTable* table); -CIMGUI_API void igTableSaveSettings(ImGuiTable* table); -CIMGUI_API void igTableResetSettings(ImGuiTable* table); -CIMGUI_API ImGuiTableSettings* igTableGetBoundSettings(ImGuiTable* table); -CIMGUI_API void igTableSettingsInstallHandler(ImGuiContext* context); -CIMGUI_API ImGuiTableSettings* igTableSettingsCreate(ImGuiID id,int columns_count); -CIMGUI_API ImGuiTableSettings* igTableSettingsFindByID(ImGuiID id); -CIMGUI_API bool igBeginTabBarEx(ImGuiTabBar* tab_bar,const ImRect bb,ImGuiTabBarFlags flags,ImGuiDockNode* dock_node); -CIMGUI_API ImGuiTabItem* igTabBarFindTabByID(ImGuiTabBar* tab_bar,ImGuiID tab_id); -CIMGUI_API ImGuiTabItem* igTabBarFindMostRecentlySelectedTabForActiveWindow(ImGuiTabBar* tab_bar); -CIMGUI_API void igTabBarAddTab(ImGuiTabBar* tab_bar,ImGuiTabItemFlags tab_flags,ImGuiWindow* window); -CIMGUI_API void igTabBarRemoveTab(ImGuiTabBar* tab_bar,ImGuiID tab_id); -CIMGUI_API void igTabBarCloseTab(ImGuiTabBar* tab_bar,ImGuiTabItem* tab); -CIMGUI_API void igTabBarQueueReorder(ImGuiTabBar* tab_bar,const ImGuiTabItem* tab,int offset); -CIMGUI_API void igTabBarQueueReorderFromMousePos(ImGuiTabBar* tab_bar,const ImGuiTabItem* tab,ImVec2 mouse_pos); -CIMGUI_API bool igTabBarProcessReorder(ImGuiTabBar* tab_bar); -CIMGUI_API bool igTabItemEx(ImGuiTabBar* tab_bar,const char* label,bool* p_open,ImGuiTabItemFlags flags,ImGuiWindow* docked_window); -CIMGUI_API void igTabItemCalcSize(ImVec2 *pOut,const char* label,bool has_close_button); -CIMGUI_API void igTabItemBackground(ImDrawList* draw_list,const ImRect bb,ImGuiTabItemFlags flags,ImU32 col); -CIMGUI_API void igTabItemLabelAndCloseButton(ImDrawList* draw_list,const ImRect bb,ImGuiTabItemFlags flags,ImVec2 frame_padding,const char* label,ImGuiID tab_id,ImGuiID close_button_id,bool is_contents_visible,bool* out_just_closed,bool* out_text_clipped); -CIMGUI_API void igRenderText(ImVec2 pos,const char* text,const char* text_end,bool hide_text_after_hash); -CIMGUI_API void igRenderTextWrapped(ImVec2 pos,const char* text,const char* text_end,float wrap_width); -CIMGUI_API void igRenderTextClipped(const ImVec2 pos_min,const ImVec2 pos_max,const char* text,const char* text_end,const ImVec2* text_size_if_known,const ImVec2 align,const ImRect* clip_rect); -CIMGUI_API void igRenderTextClippedEx(ImDrawList* draw_list,const ImVec2 pos_min,const ImVec2 pos_max,const char* text,const char* text_end,const ImVec2* text_size_if_known,const ImVec2 align,const ImRect* clip_rect); -CIMGUI_API void igRenderTextEllipsis(ImDrawList* draw_list,const ImVec2 pos_min,const ImVec2 pos_max,float clip_max_x,float ellipsis_max_x,const char* text,const char* text_end,const ImVec2* text_size_if_known); -CIMGUI_API void igRenderFrame(ImVec2 p_min,ImVec2 p_max,ImU32 fill_col,bool border,float rounding); -CIMGUI_API void igRenderFrameBorder(ImVec2 p_min,ImVec2 p_max,float rounding); -CIMGUI_API void igRenderColorRectWithAlphaCheckerboard(ImDrawList* draw_list,ImVec2 p_min,ImVec2 p_max,ImU32 fill_col,float grid_step,ImVec2 grid_off,float rounding,ImDrawFlags flags); -CIMGUI_API void igRenderNavHighlight(const ImRect bb,ImGuiID id,ImGuiNavHighlightFlags flags); -CIMGUI_API const char* igFindRenderedTextEnd(const char* text,const char* text_end); -CIMGUI_API void igRenderArrow(ImDrawList* draw_list,ImVec2 pos,ImU32 col,ImGuiDir dir,float scale); -CIMGUI_API void igRenderBullet(ImDrawList* draw_list,ImVec2 pos,ImU32 col); -CIMGUI_API void igRenderCheckMark(ImDrawList* draw_list,ImVec2 pos,ImU32 col,float sz); -CIMGUI_API void igRenderMouseCursor(ImDrawList* draw_list,ImVec2 pos,float scale,ImGuiMouseCursor mouse_cursor,ImU32 col_fill,ImU32 col_border,ImU32 col_shadow); -CIMGUI_API void igRenderArrowPointingAt(ImDrawList* draw_list,ImVec2 pos,ImVec2 half_sz,ImGuiDir direction,ImU32 col); -CIMGUI_API void igRenderArrowDockMenu(ImDrawList* draw_list,ImVec2 p_min,float sz,ImU32 col); -CIMGUI_API void igRenderRectFilledRangeH(ImDrawList* draw_list,const ImRect rect,ImU32 col,float x_start_norm,float x_end_norm,float rounding); -CIMGUI_API void igRenderRectFilledWithHole(ImDrawList* draw_list,ImRect outer,ImRect inner,ImU32 col,float rounding); -CIMGUI_API ImDrawFlags igCalcRoundingFlagsForRectInRect(const ImRect r_in,const ImRect r_outer,float threshold); -CIMGUI_API void igTextEx(const char* text,const char* text_end,ImGuiTextFlags flags); -CIMGUI_API bool igButtonEx(const char* label,const ImVec2 size_arg,ImGuiButtonFlags flags); -CIMGUI_API bool igCloseButton(ImGuiID id,const ImVec2 pos); -CIMGUI_API bool igCollapseButton(ImGuiID id,const ImVec2 pos,ImGuiDockNode* dock_node); -CIMGUI_API bool igArrowButtonEx(const char* str_id,ImGuiDir dir,ImVec2 size_arg,ImGuiButtonFlags flags); -CIMGUI_API void igScrollbar(ImGuiAxis axis); -CIMGUI_API bool igScrollbarEx(const ImRect bb,ImGuiID id,ImGuiAxis axis,ImS64* p_scroll_v,ImS64 avail_v,ImS64 contents_v,ImDrawFlags flags); -CIMGUI_API bool igImageButtonEx(ImGuiID id,ImTextureID texture_id,const ImVec2 size,const ImVec2 uv0,const ImVec2 uv1,const ImVec2 padding,const ImVec4 bg_col,const ImVec4 tint_col); -CIMGUI_API void igGetWindowScrollbarRect(ImRect *pOut,ImGuiWindow* window,ImGuiAxis axis); -CIMGUI_API ImGuiID igGetWindowScrollbarID(ImGuiWindow* window,ImGuiAxis axis); -CIMGUI_API ImGuiID igGetWindowResizeCornerID(ImGuiWindow* window,int n); -CIMGUI_API ImGuiID igGetWindowResizeBorderID(ImGuiWindow* window,ImGuiDir dir); -CIMGUI_API void igSeparatorEx(ImGuiSeparatorFlags flags); -CIMGUI_API bool igCheckboxFlags_S64Ptr(const char* label,ImS64* flags,ImS64 flags_value); -CIMGUI_API bool igCheckboxFlags_U64Ptr(const char* label,ImU64* flags,ImU64 flags_value); -CIMGUI_API bool igButtonBehavior(const ImRect bb,ImGuiID id,bool* out_hovered,bool* out_held,ImGuiButtonFlags flags); -CIMGUI_API bool igDragBehavior(ImGuiID id,ImGuiDataType data_type,void* p_v,float v_speed,const void* p_min,const void* p_max,const char* format,ImGuiSliderFlags flags); -CIMGUI_API bool igSliderBehavior(const ImRect bb,ImGuiID id,ImGuiDataType data_type,void* p_v,const void* p_min,const void* p_max,const char* format,ImGuiSliderFlags flags,ImRect* out_grab_bb); -CIMGUI_API bool igSplitterBehavior(const ImRect bb,ImGuiID id,ImGuiAxis axis,float* size1,float* size2,float min_size1,float min_size2,float hover_extend,float hover_visibility_delay,ImU32 bg_col); -CIMGUI_API bool igTreeNodeBehavior(ImGuiID id,ImGuiTreeNodeFlags flags,const char* label,const char* label_end); -CIMGUI_API bool igTreeNodeBehaviorIsOpen(ImGuiID id,ImGuiTreeNodeFlags flags); -CIMGUI_API void igTreePushOverrideID(ImGuiID id); -CIMGUI_API const ImGuiDataTypeInfo* igDataTypeGetInfo(ImGuiDataType data_type); -CIMGUI_API int igDataTypeFormatString(char* buf,int buf_size,ImGuiDataType data_type,const void* p_data,const char* format); -CIMGUI_API void igDataTypeApplyOp(ImGuiDataType data_type,int op,void* output,const void* arg_1,const void* arg_2); -CIMGUI_API bool igDataTypeApplyOpFromText(const char* buf,const char* initial_value_buf,ImGuiDataType data_type,void* p_data,const char* format); -CIMGUI_API int igDataTypeCompare(ImGuiDataType data_type,const void* arg_1,const void* arg_2); -CIMGUI_API bool igDataTypeClamp(ImGuiDataType data_type,void* p_data,const void* p_min,const void* p_max); -CIMGUI_API bool igInputTextEx(const char* label,const char* hint,char* buf,int buf_size,const ImVec2 size_arg,ImGuiInputTextFlags flags,ImGuiInputTextCallback callback,void* user_data); -CIMGUI_API bool igTempInputText(const ImRect bb,ImGuiID id,const char* label,char* buf,int buf_size,ImGuiInputTextFlags flags); -CIMGUI_API bool igTempInputScalar(const ImRect bb,ImGuiID id,const char* label,ImGuiDataType data_type,void* p_data,const char* format,const void* p_clamp_min,const void* p_clamp_max); -CIMGUI_API bool igTempInputIsActive(ImGuiID id); -CIMGUI_API ImGuiInputTextState* igGetInputTextState(ImGuiID id); -CIMGUI_API void igColorTooltip(const char* text,const float* col,ImGuiColorEditFlags flags); -CIMGUI_API void igColorEditOptionsPopup(const float* col,ImGuiColorEditFlags flags); -CIMGUI_API void igColorPickerOptionsPopup(const float* ref_col,ImGuiColorEditFlags flags); -CIMGUI_API int igPlotEx(ImGuiPlotType plot_type,const char* label,float(*values_getter)(void* data,int idx),void* data,int values_count,int values_offset,const char* overlay_text,float scale_min,float scale_max,ImVec2 frame_size); -CIMGUI_API void igShadeVertsLinearColorGradientKeepAlpha(ImDrawList* draw_list,int vert_start_idx,int vert_end_idx,ImVec2 gradient_p0,ImVec2 gradient_p1,ImU32 col0,ImU32 col1); -CIMGUI_API void igShadeVertsLinearUV(ImDrawList* draw_list,int vert_start_idx,int vert_end_idx,const ImVec2 a,const ImVec2 b,const ImVec2 uv_a,const ImVec2 uv_b,bool clamp); -CIMGUI_API void igGcCompactTransientMiscBuffers(void); -CIMGUI_API void igGcCompactTransientWindowBuffers(ImGuiWindow* window); -CIMGUI_API void igGcAwakeTransientWindowBuffers(ImGuiWindow* window); -CIMGUI_API void igErrorCheckEndFrameRecover(ImGuiErrorLogCallback log_callback,void* user_data); -CIMGUI_API void igErrorCheckEndWindowRecover(ImGuiErrorLogCallback log_callback,void* user_data); -CIMGUI_API void igDebugDrawItemRect(ImU32 col); -CIMGUI_API void igDebugStartItemPicker(void); -CIMGUI_API void igShowFontAtlas(ImFontAtlas* atlas); -CIMGUI_API void igDebugHookIdInfo(ImGuiID id,ImGuiDataType data_type,const void* data_id,const void* data_id_end); -CIMGUI_API void igDebugNodeColumns(ImGuiOldColumns* columns); -CIMGUI_API void igDebugNodeDockNode(ImGuiDockNode* node,const char* label); -CIMGUI_API void igDebugNodeDrawList(ImGuiWindow* window,ImGuiViewportP* viewport,const ImDrawList* draw_list,const char* label); -CIMGUI_API void igDebugNodeDrawCmdShowMeshAndBoundingBox(ImDrawList* out_draw_list,const ImDrawList* draw_list,const ImDrawCmd* draw_cmd,bool show_mesh,bool show_aabb); -CIMGUI_API void igDebugNodeFont(ImFont* font); -CIMGUI_API void igDebugNodeStorage(ImGuiStorage* storage,const char* label); -CIMGUI_API void igDebugNodeTabBar(ImGuiTabBar* tab_bar,const char* label); -CIMGUI_API void igDebugNodeTable(ImGuiTable* table); -CIMGUI_API void igDebugNodeTableSettings(ImGuiTableSettings* settings); -CIMGUI_API void igDebugNodeWindow(ImGuiWindow* window,const char* label); -CIMGUI_API void igDebugNodeWindowSettings(ImGuiWindowSettings* settings); -CIMGUI_API void igDebugNodeWindowsList(ImVector_ImGuiWindowPtr* windows,const char* label); -CIMGUI_API void igDebugNodeWindowsListByBeginStackParent(ImGuiWindow** windows,int windows_size,ImGuiWindow* parent_in_begin_stack); -CIMGUI_API void igDebugNodeViewport(ImGuiViewportP* viewport); -CIMGUI_API void igDebugRenderViewportThumbnail(ImDrawList* draw_list,ImGuiViewportP* viewport,const ImRect bb); -CIMGUI_API const ImFontBuilderIO* igImFontAtlasGetBuilderForStbTruetype(void); -CIMGUI_API void igImFontAtlasBuildInit(ImFontAtlas* atlas); -CIMGUI_API void igImFontAtlasBuildSetupFont(ImFontAtlas* atlas,ImFont* font,ImFontConfig* font_config,float ascent,float descent); -CIMGUI_API void igImFontAtlasBuildPackCustomRects(ImFontAtlas* atlas,void* stbrp_context_opaque); -CIMGUI_API void igImFontAtlasBuildFinish(ImFontAtlas* atlas); -CIMGUI_API void igImFontAtlasBuildRender8bppRectFromString(ImFontAtlas* atlas,int x,int y,int w,int h,const char* in_str,char in_marker_char,unsigned char in_marker_pixel_value); -CIMGUI_API void igImFontAtlasBuildRender32bppRectFromString(ImFontAtlas* atlas,int x,int y,int w,int h,const char* in_str,char in_marker_char,unsigned int in_marker_pixel_value); -CIMGUI_API void igImFontAtlasBuildMultiplyCalcLookupTable(unsigned char out_table[256],float in_multiply_factor); -CIMGUI_API void igImFontAtlasBuildMultiplyRectAlpha8(const unsigned char table[256],unsigned char* pixels,int x,int y,int w,int h,int stride); +CIMGUI_API ImGuiPlatformImeData* ImGuiPlatformImeData_ImGuiPlatformImeData(void); +CIMGUI_API void ImGuiPlatformImeData_destroy(ImGuiPlatformImeData* self); +CIMGUI_API int igGetKeyIndex(ImGuiKey key); /////////////////////////hand written functions @@ -3943,12 +1962,12 @@ CIMGUI_API void igLogText(CONST char *fmt, ...); //no appendfV CIMGUI_API void ImGuiTextBuffer_appendf(struct ImGuiTextBuffer *buffer, const char *fmt, ...); //for getting FLT_MAX in bindings -CIMGUI_API float igGET_FLT_MAX(); +CIMGUI_API float igGET_FLT_MAX(void); //for getting FLT_MIN in bindings -CIMGUI_API float igGET_FLT_MIN(); +CIMGUI_API float igGET_FLT_MIN(void); -CIMGUI_API ImVector_ImWchar* ImVector_ImWchar_create(); +CIMGUI_API ImVector_ImWchar* ImVector_ImWchar_create(void); CIMGUI_API void ImVector_ImWchar_destroy(ImVector_ImWchar* self); CIMGUI_API void ImVector_ImWchar_Init(ImVector_ImWchar* p); CIMGUI_API void ImVector_ImWchar_UnInit(ImVector_ImWchar* p); diff --git a/lib/external/imgui/include/imconfig.h b/lib/external/imgui/include/imconfig.h index b4801ec23..2f620c982 100644 --- a/lib/external/imgui/include/imconfig.h +++ b/lib/external/imgui/include/imconfig.h @@ -27,18 +27,21 @@ //#define IMGUI_API __declspec( dllimport ) //---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names. -//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS +// IMHEX PATCH BEGIN +#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS +#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87: disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions. +// IMHEX PATCH END -//---- Disable all of Dear ImGui or don't implement standard windows. -// It is very strongly recommended to NOT disable the demo windows during development. Please read comments in imgui_demo.cpp. +//---- Disable all of Dear ImGui or don't implement standard windows/tools. +// It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp. //#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty. -//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. Not recommended. -//#define IMGUI_DISABLE_METRICS_WINDOW // Disable metrics/debugger and other debug tools: ShowMetricsWindow() and ShowStackToolWindow() will be empty. +//#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. +//#define IMGUI_DISABLE_DEBUG_TOOLS // Disable metrics/debugger and other debug tools: ShowMetricsWindow(), ShowDebugLogWindow() and ShowStackToolWindow() will be empty (this was called IMGUI_DISABLE_METRICS_WINDOW before 1.88). //---- Don't implement some functions to reduce linkage requirements. //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a) //#define IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with Visual Studio] Implement default IME handler (require imm32.lib/.a, auto-link for Visual Studio, -limm32 on command-line for MinGW) -#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a) +//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a) //#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, ime). //#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default). //#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf) @@ -47,7 +50,6 @@ //#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function. //#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions(). //#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available -#define IMGUI_DEFINE_MATH_OPERATORS //---- Include imgui_user.h at the end of imgui.h as a convenience //#define IMGUI_INCLUDE_IMGUI_USER_H @@ -62,17 +64,20 @@ // By default the embedded implementations are declared static and not available outside of Dear ImGui sources files. //#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h" //#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h" +//#define IMGUI_STB_SPRINTF_FILENAME "my_folder/stb_sprintf.h" // only used if enabled //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION -//---- Use stb_printf's faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined) -// Requires 'stb_sprintf.h' to be available in the include path. Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by STB sprintf. -// #define IMGUI_USE_STB_SPRINTF +//---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined) +// Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by stb_sprintf.h. +//#define IMGUI_USE_STB_SPRINTF //---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui) // Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided). // On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'. -//#define IMGUI_ENABLE_FREETYPE +// IMHEX PATCH BEGIN +#define IMGUI_ENABLE_FREETYPE +// IMHEX PATCH END //---- Use stb_truetype to build and rasterize the font atlas (default) // The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend. @@ -81,12 +86,12 @@ //---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4. // This will be inlined as part of ImVec2 and ImVec4 class declarations. /* -#define IM_VEC2_CLASS_EXTRA \ - ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \ +#define IM_VEC2_CLASS_EXTRA \ + constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \ operator MyVec2() const { return MyVec2(x,y); } -#define IM_VEC4_CLASS_EXTRA \ - ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \ +#define IM_VEC4_CLASS_EXTRA \ + constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \ operator MyVec4() const { return MyVec4(x,y,z,w); } */ diff --git a/lib/external/imgui/include/imgui.h b/lib/external/imgui/include/imgui.h index ceb3b086d..aca8303a6 100644 --- a/lib/external/imgui/include/imgui.h +++ b/lib/external/imgui/include/imgui.h @@ -1,4 +1,4 @@ -// dear imgui, v1.86 +// dear imgui, v1.89 WIP // (headers) // Help: @@ -11,7 +11,7 @@ // - FAQ http://dearimgui.org/faq // - Homepage & latest https://github.com/ocornut/imgui // - Releases & changelog https://github.com/ocornut/imgui/releases -// - Gallery https://github.com/ocornut/imgui/issues/4451 (please post your screenshots/video there!) +// - Gallery https://github.com/ocornut/imgui/issues/5243 (please post your screenshots/video there!) // - Wiki https://github.com/ocornut/imgui/wiki (lots of good stuff there) // - Glossary https://github.com/ocornut/imgui/wiki/Glossary // - Issues & support https://github.com/ocornut/imgui/issues @@ -35,7 +35,7 @@ Index of this file: // [SECTION] Drawing API (ImDrawCallback, ImDrawCmd, ImDrawIdx, ImDrawVert, ImDrawChannel, ImDrawListSplitter, ImDrawFlags, ImDrawListFlags, ImDrawList, ImDrawData) // [SECTION] Font API (ImFontConfig, ImFontGlyph, ImFontGlyphRangesBuilder, ImFontAtlasFlags, ImFontAtlas, ImFont) // [SECTION] Viewports (ImGuiViewportFlags, ImGuiViewport) -// [SECTION] Platform interface for multi-viewport support (ImGuiPlatformIO, ImGuiPlatformMonitor) +// [SECTION] Platform Dependent Interfaces (ImGuiPlatformIO, ImGuiPlatformMonitor, ImGuiPlatformImeData) // [SECTION] Obsolete functions and types */ @@ -64,8 +64,8 @@ Index of this file: // Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens) -#define IMGUI_VERSION "1.86" -#define IMGUI_VERSION_NUM 18600 +#define IMGUI_VERSION "1.89 WIP" +#define IMGUI_VERSION_NUM 18806 #define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx)) #define IMGUI_HAS_TABLE #define IMGUI_HAS_VIEWPORT // Viewport WIP branch @@ -88,11 +88,7 @@ Index of this file: #endif #define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR) / sizeof(*(_ARR)))) // Size of a static C-style array. Don't use on pointers! #define IM_UNUSED(_VAR) ((void)(_VAR)) // Used to silence "unused variable warnings". Often useful as asserts may be stripped out from final builds. -#if (__cplusplus >= 201100) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201100) #define IM_OFFSETOF(_TYPE,_MEMBER) offsetof(_TYPE, _MEMBER) // Offset of _MEMBER within _TYPE. Standardized as offsetof() in C++11 -#else -#define IM_OFFSETOF(_TYPE,_MEMBER) ((size_t)&(((_TYPE*)0)->_MEMBER)) // Offset of _MEMBER within _TYPE. Old style macro. -#endif // Helper Macros - IM_FMTARGS, IM_FMTLIST: Apply printf-style warnings to our formatting functions. #if !defined(IMGUI_USE_STB_SPRINTF) && defined(__MINGW32__) && !defined(__clang__) @@ -107,7 +103,7 @@ Index of this file: #endif // Disable some of MSVC most aggressive Debug runtime checks in function header/footer (used in some simple/low-level functions) -#if defined(_MSC_VER) && !defined(__clang__) && !defined(IMGUI_DEBUG_PARANOID) +#if defined(_MSC_VER) && !defined(__clang__) && !defined(__INTEL_COMPILER) && !defined(IMGUI_DEBUG_PARANOID) #define IM_MSVC_RUNTIME_CHECKS_OFF __pragma(runtime_checks("",off)) __pragma(check_stack(off)) __pragma(strict_gs_check(push,off)) #define IM_MSVC_RUNTIME_CHECKS_RESTORE __pragma(runtime_checks("",restore)) __pragma(check_stack()) __pragma(strict_gs_check(pop)) #else @@ -154,11 +150,13 @@ struct ImColor; // Helper functions to create a color that c struct ImGuiContext; // Dear ImGui context (opaque structure, unless including imgui_internal.h) struct ImGuiIO; // Main configuration and I/O between your application and ImGui struct ImGuiInputTextCallbackData; // Shared state of InputText() when using custom ImGuiInputTextCallback (rare/advanced use) +struct ImGuiKeyData; // Storage for ImGuiIO and IsKeyDown(), IsKeyPressed() etc functions. struct ImGuiListClipper; // Helper to manually clip large list of items struct ImGuiOnceUponAFrame; // Helper for running a block of code not more than once a frame struct ImGuiPayload; // User data payload for drag and drop operations struct ImGuiPlatformIO; // Multi-viewport support: interface for Platform/Renderer backends + viewports to render struct ImGuiPlatformMonitor; // Multi-viewport support: user-provided bounds for each connected monitor/display. Used when positioning popups and tooltips to avoid them straddling monitors +struct ImGuiPlatformImeData; // Platform IME data for io.SetPlatformImeDataFn() function. struct ImGuiSizeCallbackData; // Callback data when using SetNextWindowSizeConstraints() (rare/advanced use) struct ImGuiStorage; // Helper for key->value storage struct ImGuiStyle; // Runtime data for styling/colors @@ -171,14 +169,13 @@ struct ImGuiWindowClass; // Window class (rare/advanced uses: provide // Enums/Flags (declared as int for compatibility with old C++, to allow using as flags without overhead, and to not pollute the top of this file) // - Tip: Use your programming IDE navigation facilities on the names in the _central column_ below to find the actual flags/enum lists! -// In Visual Studio IDE: CTRL+comma ("Edit.NavigateTo") can follow symbols in comments, whereas CTRL+F12 ("Edit.GoToImplementation") cannot. +// In Visual Studio IDE: CTRL+comma ("Edit.GoToAll") can follow symbols in comments, whereas CTRL+F12 ("Edit.GoToImplementation") cannot. // With Visual Assist installed: ALT+G ("VAssistX.GoToImplementation") can also follow symbols in comments. typedef int ImGuiCol; // -> enum ImGuiCol_ // Enum: A color identifier for styling typedef int ImGuiCond; // -> enum ImGuiCond_ // Enum: A condition for many Set*() functions typedef int ImGuiDataType; // -> enum ImGuiDataType_ // Enum: A primary data type typedef int ImGuiDir; // -> enum ImGuiDir_ // Enum: A cardinal direction -typedef int ImGuiKey; // -> enum ImGuiKey_ // Enum: A key identifier (ImGui-side enum) -typedef int ImGuiNavInput; // -> enum ImGuiNavInput_ // Enum: An input identifier for navigation +typedef int ImGuiKey; // -> enum ImGuiKey_ // Enum: A key identifier typedef int ImGuiMouseButton; // -> enum ImGuiMouseButton_ // Enum: A mouse button identifier (0=left, 1=right, 2=middle) typedef int ImGuiMouseCursor; // -> enum ImGuiMouseCursor_ // Enum: A mouse cursor identifier typedef int ImGuiSortDirection; // -> enum ImGuiSortDirection_ // Enum: A sorting direction (ascending or descending) @@ -197,7 +194,7 @@ typedef int ImGuiDragDropFlags; // -> enum ImGuiDragDropFlags_ // Flags: f typedef int ImGuiFocusedFlags; // -> enum ImGuiFocusedFlags_ // Flags: for IsWindowFocused() typedef int ImGuiHoveredFlags; // -> enum ImGuiHoveredFlags_ // Flags: for IsItemHovered(), IsWindowHovered() etc. typedef int ImGuiInputTextFlags; // -> enum ImGuiInputTextFlags_ // Flags: for InputText(), InputTextMultiline() -typedef int ImGuiKeyModFlags; // -> enum ImGuiKeyModFlags_ // Flags: for io.KeyMods (Ctrl/Shift/Alt/Super) +typedef int ImGuiModFlags; // -> enum ImGuiModFlags_ // Flags: for io.KeyMods (Ctrl/Shift/Alt/Super) typedef int ImGuiPopupFlags; // -> enum ImGuiPopupFlags_ // Flags: for OpenPopup*(), BeginPopupContext*(), IsPopupOpen() typedef int ImGuiSelectableFlags; // -> enum ImGuiSelectableFlags_ // Flags: for Selectable() typedef int ImGuiSliderFlags; // -> enum ImGuiSliderFlags_ // Flags: for DragFloat(), DragInt(), SliderFloat(), SliderInt() etc. @@ -232,17 +229,8 @@ typedef signed short ImS16; // 16-bit signed integer typedef unsigned short ImU16; // 16-bit unsigned integer typedef signed int ImS32; // 32-bit signed integer == int typedef unsigned int ImU32; // 32-bit unsigned integer (often used to store packed colors) -#if defined(_MSC_VER) && !defined(__clang__) -typedef signed __int64 ImS64; // 64-bit signed integer (pre and post C++11 with Visual Studio) -typedef unsigned __int64 ImU64; // 64-bit unsigned integer (pre and post C++11 with Visual Studio) -#elif (defined(__clang__) || defined(__GNUC__)) && (__cplusplus < 201100) -#include -typedef int64_t ImS64; // 64-bit signed integer (pre C++11) -typedef uint64_t ImU64; // 64-bit unsigned integer (pre C++11) -#else -typedef signed long long ImS64; // 64-bit signed integer (post C++11) -typedef unsigned long long ImU64; // 64-bit unsigned integer (post C++11) -#endif +typedef signed long long ImS64; // 64-bit signed integer +typedef unsigned long long ImU64; // 64-bit unsigned integer // Character types // (we generally use UTF-8 encoded string in the API. This is storage specifically for a decoded character used for keyboard input and display) @@ -266,8 +254,8 @@ IM_MSVC_RUNTIME_CHECKS_OFF struct ImVec2 { float x, y; - ImVec2() { x = y = 0.0f; } - ImVec2(float _x, float _y) { x = _x; y = _y; } + constexpr ImVec2() : x(0.0f), y(0.0f) { } + constexpr ImVec2(float _x, float _y) : x(_x), y(_y) { } float operator[] (size_t idx) const { IM_ASSERT(idx <= 1); return (&x)[idx]; } // We very rarely use this [] operator, the assert overhead is fine. float& operator[] (size_t idx) { IM_ASSERT(idx <= 1); return (&x)[idx]; } // We very rarely use this [] operator, the assert overhead is fine. #ifdef IM_VEC2_CLASS_EXTRA @@ -278,9 +266,9 @@ struct ImVec2 // ImVec4: 4D vector used to store clipping rectangles, colors etc. [Compile-time configurable type] struct ImVec4 { - float x, y, z, w; - ImVec4() { x = y = z = w = 0.0f; } - ImVec4(float _x, float _y, float _z, float _w) { x = _x; y = _y; z = _z; w = _w; } + float x, y, z, w; + constexpr ImVec4() : x(0.0f), y(0.0f), z(0.0f), w(0.0f) { } + constexpr ImVec4(float _x, float _y, float _z, float _w) : x(_x), y(_y), z(_z), w(_w) { } #ifdef IM_VEC4_CLASS_EXTRA IM_VEC4_CLASS_EXTRA // Define additional constructors and implicit cast operators in imconfig.h to convert back and forth between your math types and ImVec4. #endif @@ -314,6 +302,7 @@ namespace ImGui // Demo, Debug, Information IMGUI_API void ShowDemoWindow(bool* p_open = NULL); // create Demo window. demonstrate most ImGui features. call this to learn about the library! try to make it always available in your application! IMGUI_API void ShowMetricsWindow(bool* p_open = NULL); // create Metrics/Debugger window. display Dear ImGui internals: windows, draw commands, various internal state, etc. + IMGUI_API void ShowDebugLogWindow(bool* p_open = NULL); // create Debug Log window. display a simplified log of important dear imgui events. IMGUI_API void ShowStackToolWindow(bool* p_open = NULL); // create Stack Tool window. hover items with mouse to query information about the source of their unique ID. IMGUI_API void ShowAboutWindow(bool* p_open = NULL); // create About window. display Dear ImGui version, credits and build/system information. IMGUI_API void ShowStyleEditor(ImGuiStyle* ref = NULL); // add style editor block (not a window). you can pass in a reference ImGuiStyle structure to compare to, revert to and save to (else it uses the default style) @@ -534,7 +523,8 @@ namespace ImGui // Widgets: Drag Sliders // - CTRL+Click on any drag box to turn them into an input box. Manually input values aren't clamped by default and can go off-bounds. Use ImGuiSliderFlags_AlwaysClamp to always clamp. - // - For all the Float2/Float3/Float4/Int2/Int3/Int4 versions of every functions, note that a 'float v[X]' function argument is the same as 'float* v', the array syntax is just a way to document the number of elements that are expected to be accessible. You can pass address of your first element out of a contiguous set, e.g. &myvector.x + // - For all the Float2/Float3/Float4/Int2/Int3/Int4 versions of every functions, note that a 'float v[X]' function argument is the same as 'float* v', + // the array syntax is just a way to document the number of elements that are expected to be accessible. You can pass address of your first element out of a contiguous set, e.g. &myvector.x // - Adjust format string to decorate the value with a prefix, a suffix, or adapt the editing and display precision e.g. "%.3f" -> 1.234; "%5.2f secs" -> 01.23 secs; "Biscuit: %.0f" -> Biscuit: 1; etc. // - Format string may also be set to NULL or use the default format ("%f" or "%d"). // - Speed are per-pixel of mouse movement (v_speed=0.2f: mouse needs to move by 5 pixels to increase value by 1). For gamepad/keyboard navigation, minimum speed is Max(v_speed, minimum_step_at_given_precision). @@ -602,7 +592,7 @@ namespace ImGui IMGUI_API bool ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flags = 0); IMGUI_API bool ColorPicker3(const char* label, float col[3], ImGuiColorEditFlags flags = 0); IMGUI_API bool ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags flags = 0, const float* ref_col = NULL); - IMGUI_API bool ColorButton(const char* desc_id, const ImVec4& col, ImGuiColorEditFlags flags = 0, ImVec2 size = ImVec2(0, 0)); // display a color square/button, hover for details, return true when pressed. + IMGUI_API bool ColorButton(const char* desc_id, const ImVec4& col, ImGuiColorEditFlags flags = 0, const ImVec2& size = ImVec2(0, 0)); // display a color square/button, hover for details, return true when pressed. IMGUI_API void SetColorEditOptions(ImGuiColorEditFlags flags); // initialize current options (generally on application startup) if you want to select a default format, picker type, etc. User will be able to change many settings, unless you pass the _NoOptions flag to your calls. // Widgets: Trees @@ -700,6 +690,7 @@ namespace ImGui // - CloseCurrentPopup() is called by default by Selectable()/MenuItem() when activated (FIXME: need some options). // - Use ImGuiPopupFlags_NoOpenOverExistingPopup to avoid opening a popup if there's already one at the same level. This is equivalent to e.g. testing for !IsAnyPopupOpen() prior to OpenPopup(). // - Use IsWindowAppearing() after BeginPopup() to tell if a window just opened. + // - IMPORTANT: Notice that for OpenPopupOnItemClick() we exceptionally default flags to 1 (== ImGuiPopupFlags_MouseButtonRight) for backward compatibility with older API taking 'int mouse_button = 1' parameter IMGUI_API void OpenPopup(const char* str_id, ImGuiPopupFlags popup_flags = 0); // call to mark popup as open (don't call every frame!). IMGUI_API void OpenPopup(ImGuiID id, ImGuiPopupFlags popup_flags = 0); // id overload to facilitate calling from nested stacks IMGUI_API void OpenPopupOnItemClick(const char* str_id = NULL, ImGuiPopupFlags popup_flags = 1); // helper to open popup when clicked on last item. Default to ImGuiPopupFlags_MouseButtonRight == 1. (note: actually triggers on the mouse _released_ event to be consistent with popup behaviors) @@ -709,7 +700,7 @@ namespace ImGui // - Helpers to do OpenPopup+BeginPopup where the Open action is triggered by e.g. hovering an item and right-clicking. // - They are convenient to easily create context menus, hence the name. // - IMPORTANT: Notice that BeginPopupContextXXX takes ImGuiPopupFlags just like OpenPopup() and unlike BeginPopup(). For full consistency, we may add ImGuiWindowFlags to the BeginPopupContextXXX functions in the future. - // - IMPORTANT: we exceptionally default their flags to 1 (== ImGuiPopupFlags_MouseButtonRight) for backward compatibility with older API taking 'int mouse_button = 1' parameter, so if you add other flags remember to re-add the ImGuiPopupFlags_MouseButtonRight. + // - IMPORTANT: Notice that we exceptionally default their flags to 1 (== ImGuiPopupFlags_MouseButtonRight) for backward compatibility with older API taking 'int mouse_button = 1' parameter, so if you add other flags remember to re-add the ImGuiPopupFlags_MouseButtonRight. IMGUI_API bool BeginPopupContextItem(const char* str_id = NULL, ImGuiPopupFlags popup_flags = 1); // open+begin popup when clicked on last item. Use str_id==NULL to associate the popup to previous item. If you want to use that on a non-interactive item such as Text() you need to pass in an explicit ID here. read comments in .cpp! IMGUI_API bool BeginPopupContextWindow(const char* str_id = NULL, ImGuiPopupFlags popup_flags = 1);// open+begin popup when clicked on current window. IMGUI_API bool BeginPopupContextVoid(const char* str_id = NULL, ImGuiPopupFlags popup_flags = 1); // open+begin popup when clicked in void (where there are no windows). @@ -721,13 +712,11 @@ namespace ImGui IMGUI_API bool IsPopupOpen(const char* str_id, ImGuiPopupFlags flags = 0); // return true if the popup is open. // Tables - // [BETA API] API may evolve slightly! If you use this, please update to the next version when it comes out! // - Full-featured replacement for old Columns API. - // - See Demo->Tables for demo code. - // - See top of imgui_tables.cpp for general commentary. + // - See Demo->Tables for demo code. See top of imgui_tables.cpp for general commentary. // - See ImGuiTableFlags_ and ImGuiTableColumnFlags_ enums for a description of available flags. // The typical call flow is: - // - 1. Call BeginTable(). + // - 1. Call BeginTable(), early out if returning false. // - 2. Optionally call TableSetupColumn() to submit column name/flags/defaults. // - 3. Optionally call TableSetupScrollFreeze() to request scroll freezing of columns/rows. // - 4. Optionally call TableHeadersRow() to submit a header row. Names are pulled from TableSetupColumn() data. @@ -746,10 +735,10 @@ namespace ImGui // -------------------------------------------------------------------------------------------------------- // - 5. Call EndTable() IMGUI_API bool BeginTable(const char* str_id, int column, ImGuiTableFlags flags = 0, const ImVec2& outer_size = ImVec2(0.0f, 0.0f), float inner_width = 0.0f); - IMGUI_API void EndTable(); // only call EndTable() if BeginTable() returns true! + IMGUI_API void EndTable(); // only call EndTable() if BeginTable() returns true! IMGUI_API void TableNextRow(ImGuiTableRowFlags row_flags = 0, float min_row_height = 0.0f); // append into the first cell of a new row. - IMGUI_API bool TableNextColumn(); // append into the next column (or first column of next row if currently in last column). Return true when column is visible. - IMGUI_API bool TableSetColumnIndex(int column_n); // append into the specified column. Return true when column is visible. + IMGUI_API bool TableNextColumn(); // append into the next column (or first column of next row if currently in last column). Return true when column is visible. + IMGUI_API bool TableSetColumnIndex(int column_n); // append into the specified column. Return true when column is visible. // Tables: Headers & Columns declaration // - Use TableSetupColumn() to specify label, resizing policy, default width/weight, id, various other flags etc. @@ -760,20 +749,17 @@ namespace ImGui // some advanced use cases (e.g. adding custom widgets in header row). // - Use TableSetupScrollFreeze() to lock columns/rows so they stay visible when scrolled. IMGUI_API void TableSetupColumn(const char* label, ImGuiTableColumnFlags flags = 0, float init_width_or_weight = 0.0f, ImGuiID user_id = 0); - IMGUI_API void TableSetupScrollFreeze(int cols, int rows); // lock columns/rows so they stay visible when scrolled. - IMGUI_API void TableHeadersRow(); // submit all headers cells based on data provided to TableSetupColumn() + submit context menu - IMGUI_API void TableHeader(const char* label); // submit one header cell manually (rarely used) + IMGUI_API void TableSetupScrollFreeze(int cols, int rows); // lock columns/rows so they stay visible when scrolled. + IMGUI_API void TableHeadersRow(); // submit all headers cells based on data provided to TableSetupColumn() + submit context menu + IMGUI_API void TableHeader(const char* label); // submit one header cell manually (rarely used) - // Tables: Sorting - // - Call TableGetSortSpecs() to retrieve latest sort specs for the table. NULL when not sorting. - // - When 'SpecsDirty == true' you should sort your data. It will be true when sorting specs have changed - // since last call, or the first time. Make sure to set 'SpecsDirty = false' after sorting, else you may - // wastefully sort your data every frame! - // - Lifetime: don't hold on this pointer over multiple frames or past any subsequent call to BeginTable(). - IMGUI_API ImGuiTableSortSpecs* TableGetSortSpecs(); // get latest sort specs for the table (NULL if not sorting). - - // Tables: Miscellaneous functions + // Tables: Sorting & Miscellaneous functions + // - Sorting: call TableGetSortSpecs() to retrieve latest sort specs for the table. NULL when not sorting. + // When 'sort_specs->SpecsDirty == true' you should sort your data. It will be true when sorting specs have + // changed since last call, or the first time. Make sure to set 'SpecsDirty = false' after sorting, + // else you may wastefully sort your data every frame! // - Functions args 'int column_n' treat the default value of -1 as the same as passing the current column index. + IMGUI_API ImGuiTableSortSpecs* TableGetSortSpecs(); // get latest sort specs for the table (NULL if not sorting). Lifetime: don't hold on this pointer over multiple frames or past any subsequent call to BeginTable(). IMGUI_API int TableGetColumnCount(); // return number of columns (value passed to BeginTable) IMGUI_API int TableGetColumnIndex(); // return current column index. IMGUI_API int TableGetRowIndex(); // return current row index. @@ -838,7 +824,7 @@ namespace ImGui // - If you stop calling BeginDragDropSource() the payload is preserved however it won't have a preview tooltip (we currently display a fallback "..." tooltip, see #1725) // - An item can be both drag source and drop target. IMGUI_API bool BeginDragDropSource(ImGuiDragDropFlags flags = 0); // call after submitting an item which may be dragged. when this return true, you can call SetDragDropPayload() + EndDragDropSource() - IMGUI_API bool SetDragDropPayload(const char* type, const void* data, size_t sz, ImGuiCond cond = 0); // type is a user defined string of maximum 32 characters. Strings starting with '_' are reserved for dear imgui internal types. Data is copied and held by imgui. + IMGUI_API bool SetDragDropPayload(const char* type, const void* data, size_t sz, ImGuiCond cond = 0); // type is a user defined string of maximum 32 characters. Strings starting with '_' are reserved for dear imgui internal types. Data is copied and held by imgui. Return true when payload has been accepted. IMGUI_API void EndDragDropSource(); // only call EndDragDropSource() if BeginDragDropSource() returns true! IMGUI_API bool BeginDragDropTarget(); // call after submitting an item that may receive a payload. If this returns true, you can call AcceptDragDropPayload() + EndDragDropTarget() IMGUI_API const ImGuiPayload* AcceptDragDropPayload(const char* type, ImGuiDragDropFlags flags = 0); // accept contents of a given type. If ImGuiDragDropFlags_AcceptBeforeDelivery is set you can peek into the payload before the mouse button is released. @@ -889,15 +875,17 @@ namespace ImGui // - In the future we will extend this concept further to also represent Platform Monitor and support a "no main platform window" operation mode. IMGUI_API ImGuiViewport* GetMainViewport(); // return primary/default viewport. This can never be NULL. + // Background/Foreground Draw Lists + IMGUI_API ImDrawList* GetBackgroundDrawList(); // get background draw list for the viewport associated to the current window. this draw list will be the first rendering one. Useful to quickly draw shapes/text behind dear imgui contents. + IMGUI_API ImDrawList* GetForegroundDrawList(); // get foreground draw list for the viewport associated to the current window. this draw list will be the last rendered one. Useful to quickly draw shapes/text over dear imgui contents. + IMGUI_API ImDrawList* GetBackgroundDrawList(ImGuiViewport* viewport); // get background draw list for the given viewport. this draw list will be the first rendering one. Useful to quickly draw shapes/text behind dear imgui contents. + IMGUI_API ImDrawList* GetForegroundDrawList(ImGuiViewport* viewport); // get foreground draw list for the given viewport. this draw list will be the last rendered one. Useful to quickly draw shapes/text over dear imgui contents. + // Miscellaneous Utilities IMGUI_API bool IsRectVisible(const ImVec2& size); // test if rectangle (of given size, starting from cursor position) is visible / not clipped. IMGUI_API bool IsRectVisible(const ImVec2& rect_min, const ImVec2& rect_max); // test if rectangle (in screen space) is visible / not clipped. to perform coarse clipping on user's side. IMGUI_API double GetTime(); // get global imgui time. incremented by io.DeltaTime every frame. IMGUI_API int GetFrameCount(); // get global imgui frame count. incremented by 1 every frame. - IMGUI_API ImDrawList* GetBackgroundDrawList(); // get background draw list for the viewport associated to the current window. this draw list will be the first rendering one. Useful to quickly draw shapes/text behind dear imgui contents. - IMGUI_API ImDrawList* GetForegroundDrawList(); // get foreground draw list for the viewport associated to the current window. this draw list will be the last rendered one. Useful to quickly draw shapes/text over dear imgui contents. - IMGUI_API ImDrawList* GetBackgroundDrawList(ImGuiViewport* viewport); // get background draw list for the given viewport. this draw list will be the first rendering one. Useful to quickly draw shapes/text behind dear imgui contents. - IMGUI_API ImDrawList* GetForegroundDrawList(ImGuiViewport* viewport); // get foreground draw list for the given viewport. this draw list will be the last rendered one. Useful to quickly draw shapes/text over dear imgui contents. IMGUI_API ImDrawListSharedData* GetDrawListSharedData(); // you may use this when creating your own ImDrawList instances. IMGUI_API const char* GetStyleColorName(ImGuiCol idx); // get a string corresponding to the enum value (for display, saving, etc.). IMGUI_API void SetStateStorage(ImGuiStorage* storage); // replace current window storage with our own (if you want to manipulate it yourself, typically clear subsection of it) @@ -915,14 +903,17 @@ namespace ImGui IMGUI_API void ColorConvertHSVtoRGB(float h, float s, float v, float& out_r, float& out_g, float& out_b); // Inputs Utilities: Keyboard - // - For 'int user_key_index' you can use your own indices/enums according to how your backend/engine stored them in io.KeysDown[]. - // - We don't know the meaning of those value. You can use GetKeyIndex() to map a ImGuiKey_ value into the user index. - IMGUI_API int GetKeyIndex(ImGuiKey imgui_key); // map ImGuiKey_* values into user's key index. == io.KeyMap[key] - IMGUI_API bool IsKeyDown(int user_key_index); // is key being held. == io.KeysDown[user_key_index]. - IMGUI_API bool IsKeyPressed(int user_key_index, bool repeat = true); // was key pressed (went from !Down to Down)? if repeat=true, uses io.KeyRepeatDelay / KeyRepeatRate - IMGUI_API bool IsKeyReleased(int user_key_index); // was key released (went from Down to !Down)? - IMGUI_API int GetKeyPressedAmount(int key_index, float repeat_delay, float rate); // uses provided repeat rate/delay. return a count, most often 0 or 1 but might be >1 if RepeatRate is small enough that DeltaTime > RepeatRate - IMGUI_API void CaptureKeyboardFromApp(bool want_capture_keyboard_value = true); // attention: misleading name! manually override io.WantCaptureKeyboard flag next frame (said flag is entirely left for your application to handle). e.g. force capture keyboard when your widget is being hovered. This is equivalent to setting "io.WantCaptureKeyboard = want_capture_keyboard_value"; after the next NewFrame() call. + // Without IMGUI_DISABLE_OBSOLETE_KEYIO: (legacy support) + // - For 'ImGuiKey key' you can still use your legacy native/user indices according to how your backend/engine stored them in io.KeysDown[]. + // With IMGUI_DISABLE_OBSOLETE_KEYIO: (this is the way forward) + // - Any use of 'ImGuiKey' will assert when key < 512 will be passed, previously reserved as native/user keys indices + // - GetKeyIndex() is pass-through and therefore deprecated (gone if IMGUI_DISABLE_OBSOLETE_KEYIO is defined) + IMGUI_API bool IsKeyDown(ImGuiKey key); // is key being held. + IMGUI_API bool IsKeyPressed(ImGuiKey key, bool repeat = true); // was key pressed (went from !Down to Down)? if repeat=true, uses io.KeyRepeatDelay / KeyRepeatRate + IMGUI_API bool IsKeyReleased(ImGuiKey key); // was key released (went from Down to !Down)? + IMGUI_API int GetKeyPressedAmount(ImGuiKey key, float repeat_delay, float rate); // uses provided repeat rate/delay. return a count, most often 0 or 1 but might be >1 if RepeatRate is small enough that DeltaTime > RepeatRate + IMGUI_API const char* GetKeyName(ImGuiKey key); // [DEBUG] returns English name of the key. Those names a provided for debugging purpose and are not meant to be saved persistently not compared. + IMGUI_API void SetNextFrameWantCaptureKeyboard(bool want_capture_keyboard); // Override io.WantCaptureKeyboard flag next frame (said flag is left for your application to handle, typically when true it instructs your app to ignore inputs). e.g. force capture keyboard when your widget is being hovered. This is equivalent to setting "io.WantCaptureKeyboard = want_capture_keyboard"; after the next NewFrame() call. // Inputs Utilities: Mouse // - To refer to a mouse button, you may use named enums in your code e.g. ImGuiMouseButton_Left, ImGuiMouseButton_Right. @@ -935,7 +926,7 @@ namespace ImGui IMGUI_API int GetMouseClickedCount(ImGuiMouseButton button); // return the number of successive mouse-clicks at the time where a click happen (otherwise 0). IMGUI_API bool IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool clip = true);// is mouse hovering given bounding rect (in screen space). clipped by current clipping settings, but disregarding of other consideration of focus/window ordering/popup-block. IMGUI_API bool IsMousePosValid(const ImVec2* mouse_pos = NULL); // by convention we use (-FLT_MAX,-FLT_MAX) to denote that there is no mouse available - IMGUI_API bool IsAnyMouseDown(); // is any mouse button held? + IMGUI_API bool IsAnyMouseDown(); // [WILL OBSOLETE] is any mouse button held? This was designed for backends, but prefer having backend maintain a mask of held mouse buttons, because upcoming input queue system will make this invalid. IMGUI_API ImVec2 GetMousePos(); // shortcut to ImGui::GetIO().MousePos provided by user, to be consistent with other calls IMGUI_API ImVec2 GetMousePosOnOpeningCurrentPopup(); // retrieve mouse position at the time of opening popup we have BeginPopup() into (helper to avoid user backing that value themselves) IMGUI_API bool IsMouseDragging(ImGuiMouseButton button, float lock_threshold = -1.0f); // is mouse dragging? (if lock_threshold < -1.0f, uses io.MouseDraggingThreshold) @@ -943,7 +934,7 @@ namespace ImGui IMGUI_API void ResetMouseDragDelta(ImGuiMouseButton button = 0); // IMGUI_API ImGuiMouseCursor GetMouseCursor(); // get desired cursor type, reset in ImGui::NewFrame(), this is updated during the frame. valid before Render(). If you use software rendering by setting io.MouseDrawCursor ImGui will render those for you IMGUI_API void SetMouseCursor(ImGuiMouseCursor cursor_type); // set desired cursor type - IMGUI_API void CaptureMouseFromApp(bool want_capture_mouse_value = true); // attention: misleading name! manually override io.WantCaptureMouse flag next frame (said flag is entirely left for your application to handle). This is equivalent to setting "io.WantCaptureMouse = want_capture_mouse_value;" after the next NewFrame() call. + IMGUI_API void SetNextFrameWantCaptureMouse(bool want_capture_mouse); // Override io.WantCaptureMouse flag next frame (said flag is left for your application to handle, typical when true it instucts your app to ignore inputs). This is equivalent to setting "io.WantCaptureMouse = want_capture_mouse;" after the next NewFrame() call. // Clipboard Utilities // - Also see the LogToClipboard() function to capture GUI into clipboard, or easily output text data to the clipboard. @@ -960,7 +951,7 @@ namespace ImGui IMGUI_API const char* SaveIniSettingsToMemory(size_t* out_ini_size = NULL); // return a zero-terminated string with the .ini data which you can save by your own mean. call when io.WantSaveIniSettings is set, then save data by your own mean and clear io.WantSaveIniSettings. // Debug Utilities - // - This is used by the IMGUI_CHECKVERSION() macro. + IMGUI_API void DebugTextEncoding(const char* text); IMGUI_API bool DebugCheckVersionAndDataLayout(const char* version_str, size_t sz_io, size_t sz_style, size_t sz_vec2, size_t sz_vec4, size_t sz_drawvert, size_t sz_drawidx); // This is called by IMGUI_CHECKVERSION() macro. // Memory Allocators @@ -1025,10 +1016,7 @@ enum ImGuiWindowFlags_ ImGuiWindowFlags_Popup = 1 << 26, // Don't use! For internal use by BeginPopup() ImGuiWindowFlags_Modal = 1 << 27, // Don't use! For internal use by BeginPopupModal() ImGuiWindowFlags_ChildMenu = 1 << 28, // Don't use! For internal use by BeginMenu() - ImGuiWindowFlags_DockNodeHost = 1 << 29 // Don't use! For internal use by Begin()/NewFrame() - - // [Obsolete] - //ImGuiWindowFlags_ResizeFromAnySide = 1 << 17, // --> Set io.ConfigWindowsResizeFromEdges=true and make sure mouse cursors are supported by backend (io.BackendFlags & ImGuiBackendFlags_HasMouseCursors) + ImGuiWindowFlags_DockNodeHost = 1 << 29, // Don't use! For internal use by Begin()/NewFrame() }; // Flags for ImGui::InputText() @@ -1054,11 +1042,11 @@ enum ImGuiInputTextFlags_ ImGuiInputTextFlags_NoUndoRedo = 1 << 16, // Disable undo/redo. Note that input text owns the text data while active, if you want to provide your own undo/redo stack you need e.g. to call ClearActiveID(). ImGuiInputTextFlags_CharsScientific = 1 << 17, // Allow 0123456789.+-*/eE (Scientific notation input) ImGuiInputTextFlags_CallbackResize = 1 << 18, // Callback on buffer capacity changes request (beyond 'buf_size' parameter value), allowing the string to grow. Notify when the string wants to be resized (for string types which hold a cache of their Size). You will be provided a new BufSize in the callback and NEED to honor it. (see misc/cpp/imgui_stdlib.h for an example of using this) - ImGuiInputTextFlags_CallbackEdit = 1 << 19 // Callback on any edit (note that InputText() already returns true on edit, the callback is useful mainly to manipulate the underlying buffer while focus is active) + ImGuiInputTextFlags_CallbackEdit = 1 << 19, // Callback on any edit (note that InputText() already returns true on edit, the callback is useful mainly to manipulate the underlying buffer while focus is active) // Obsolete names (will be removed soon) #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - , ImGuiInputTextFlags_AlwaysInsertMode = ImGuiInputTextFlags_AlwaysOverwrite // [renamed in 1.82] name was not matching behavior + ImGuiInputTextFlags_AlwaysInsertMode = ImGuiInputTextFlags_AlwaysOverwrite // [renamed in 1.82] name was not matching behavior #endif }; @@ -1081,7 +1069,7 @@ enum ImGuiTreeNodeFlags_ ImGuiTreeNodeFlags_SpanFullWidth = 1 << 12, // Extend hit box to the left-most and right-most edges (bypass the indented area). ImGuiTreeNodeFlags_NavLeftJumpsBackHere = 1 << 13, // (WIP) Nav: left direction may move to this TreeNode() from any of its child (items submitted between TreeNode and TreePop) //ImGuiTreeNodeFlags_NoScrollOnOpen = 1 << 14, // FIXME: TODO: Disable automatic scroll on TreePop() if node got just open and contents is not visible - ImGuiTreeNodeFlags_CollapsingHeader = ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_NoAutoOpenOnLog + ImGuiTreeNodeFlags_CollapsingHeader = ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_NoAutoOpenOnLog, }; // Flags for OpenPopup*(), BeginPopupContext*(), IsPopupOpen() functions. @@ -1104,7 +1092,7 @@ enum ImGuiPopupFlags_ ImGuiPopupFlags_NoOpenOverItems = 1 << 6, // For BeginPopupContextWindow(): don't return true when hovering items, only when hovering empty space ImGuiPopupFlags_AnyPopupId = 1 << 7, // For IsPopupOpen(): ignore the ImGuiID parameter and test for any popup. ImGuiPopupFlags_AnyPopupLevel = 1 << 8, // For IsPopupOpen(): search/test at any level of the popup stack (default test in the current level) - ImGuiPopupFlags_AnyPopup = ImGuiPopupFlags_AnyPopupId | ImGuiPopupFlags_AnyPopupLevel + ImGuiPopupFlags_AnyPopup = ImGuiPopupFlags_AnyPopupId | ImGuiPopupFlags_AnyPopupLevel, }; // Flags for ImGui::Selectable() @@ -1115,7 +1103,7 @@ enum ImGuiSelectableFlags_ ImGuiSelectableFlags_SpanAllColumns = 1 << 1, // Selectable frame can span all columns (text will still fit in current column) ImGuiSelectableFlags_AllowDoubleClick = 1 << 2, // Generate press events on double clicks too ImGuiSelectableFlags_Disabled = 1 << 3, // Cannot be selected, display grayed out text - ImGuiSelectableFlags_AllowItemOverlap = 1 << 4 // (WIP) Hit testing to allow subsequent widgets to overlap this one + ImGuiSelectableFlags_AllowItemOverlap = 1 << 4, // (WIP) Hit testing to allow subsequent widgets to overlap this one }; // Flags for ImGui::BeginCombo() @@ -1129,7 +1117,7 @@ enum ImGuiComboFlags_ ImGuiComboFlags_HeightLargest = 1 << 4, // As many fitting items as possible ImGuiComboFlags_NoArrowButton = 1 << 5, // Display on the preview box without the square arrow button ImGuiComboFlags_NoPreview = 1 << 6, // Display only a square arrow button - ImGuiComboFlags_HeightMask_ = ImGuiComboFlags_HeightSmall | ImGuiComboFlags_HeightRegular | ImGuiComboFlags_HeightLarge | ImGuiComboFlags_HeightLargest + ImGuiComboFlags_HeightMask_ = ImGuiComboFlags_HeightSmall | ImGuiComboFlags_HeightRegular | ImGuiComboFlags_HeightLarge | ImGuiComboFlags_HeightLargest, }; // Flags for ImGui::BeginTabBar() @@ -1145,7 +1133,7 @@ enum ImGuiTabBarFlags_ ImGuiTabBarFlags_FittingPolicyResizeDown = 1 << 6, // Resize tabs when they don't fit ImGuiTabBarFlags_FittingPolicyScroll = 1 << 7, // Add scroll buttons when tabs don't fit ImGuiTabBarFlags_FittingPolicyMask_ = ImGuiTabBarFlags_FittingPolicyResizeDown | ImGuiTabBarFlags_FittingPolicyScroll, - ImGuiTabBarFlags_FittingPolicyDefault_ = ImGuiTabBarFlags_FittingPolicyResizeDown + ImGuiTabBarFlags_FittingPolicyDefault_ = ImGuiTabBarFlags_FittingPolicyResizeDown, }; // Flags for ImGui::BeginTabItem() @@ -1159,12 +1147,11 @@ enum ImGuiTabItemFlags_ ImGuiTabItemFlags_NoTooltip = 1 << 4, // Disable tooltip for the given tab ImGuiTabItemFlags_NoReorder = 1 << 5, // Disable reordering this tab or having another tab cross over this tab ImGuiTabItemFlags_Leading = 1 << 6, // Enforce the tab position to the left of the tab bar (after the tab list popup button) - ImGuiTabItemFlags_Trailing = 1 << 7 // Enforce the tab position to the right of the tab bar (before the scrolling buttons) + ImGuiTabItemFlags_Trailing = 1 << 7, // Enforce the tab position to the right of the tab bar (before the scrolling buttons) }; // Flags for ImGui::BeginTable() -// [BETA API] API may evolve slightly! If you use this, please update to the next version when it comes out! -// - Important! Sizing policies have complex and subtle side effects, more so than you would expect. +// - Important! Sizing policies have complex and subtle side effects, much more so than you would expect. // Read comments/demos carefully + experiment with live demos to get acquainted with them. // - The DEFAULT sizing policies are: // - Default to ImGuiTableFlags_SizingFixedFit if ScrollX is on, or if host window has ImGuiWindowFlags_AlwaysAutoResize. @@ -1172,8 +1159,8 @@ enum ImGuiTabItemFlags_ // - When ScrollX is off: // - Table defaults to ImGuiTableFlags_SizingStretchSame -> all Columns defaults to ImGuiTableColumnFlags_WidthStretch with same weight. // - Columns sizing policy allowed: Stretch (default), Fixed/Auto. -// - Fixed Columns will generally obtain their requested width (unless the table cannot fit them all). -// - Stretch Columns will share the remaining width. +// - Fixed Columns (if any) will generally obtain their requested width (unless the table cannot fit them all). +// - Stretch Columns will share the remaining width according to their respective weight. // - Mixed Fixed/Stretch columns is possible but has various side-effects on resizing behaviors. // The typical use of mixing sizing policies is: any number of LEADING Fixed columns, followed by one or two TRAILING Stretch columns. // (this is because the visible order of columns have subtle but necessary effects on how they react to manual resizing). @@ -1232,7 +1219,7 @@ enum ImGuiTableFlags_ ImGuiTableFlags_SortTristate = 1 << 27, // Allow no sorting, disable default sorting. TableGetSortSpecs() may return specs where (SpecsCount == 0). // [Internal] Combinations and masks - ImGuiTableFlags_SizingMask_ = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_SizingFixedSame | ImGuiTableFlags_SizingStretchProp | ImGuiTableFlags_SizingStretchSame + ImGuiTableFlags_SizingMask_ = ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_SizingFixedSame | ImGuiTableFlags_SizingStretchProp | ImGuiTableFlags_SizingStretchSame, // Obsolete names (will be removed soon) #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS @@ -1275,7 +1262,7 @@ enum ImGuiTableColumnFlags_ ImGuiTableColumnFlags_WidthMask_ = ImGuiTableColumnFlags_WidthStretch | ImGuiTableColumnFlags_WidthFixed, ImGuiTableColumnFlags_IndentMask_ = ImGuiTableColumnFlags_IndentEnable | ImGuiTableColumnFlags_IndentDisable, ImGuiTableColumnFlags_StatusMask_ = ImGuiTableColumnFlags_IsEnabled | ImGuiTableColumnFlags_IsVisible | ImGuiTableColumnFlags_IsSorted | ImGuiTableColumnFlags_IsHovered, - ImGuiTableColumnFlags_NoDirectResize_ = 1 << 30 // [Internal] Disable user resizing this column directly (it may however we resized indirectly from its left edge) + ImGuiTableColumnFlags_NoDirectResize_ = 1 << 30, // [Internal] Disable user resizing this column directly (it may however we resized indirectly from its left edge) // Obsolete names (will be removed soon) #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS @@ -1286,8 +1273,8 @@ enum ImGuiTableColumnFlags_ // Flags for ImGui::TableNextRow() enum ImGuiTableRowFlags_ { - ImGuiTableRowFlags_None = 0, - ImGuiTableRowFlags_Headers = 1 << 0 // Identify header row (set default background color + width of its contents accounted different for auto column width) + ImGuiTableRowFlags_None = 0, + ImGuiTableRowFlags_Headers = 1 << 0, // Identify header row (set default background color + width of its contents accounted differently for auto column width) }; // Enum for ImGui::TableSetBgColor() @@ -1301,10 +1288,10 @@ enum ImGuiTableRowFlags_ // If you set the color of RowBg1 or ColumnBg1 target, your color will blend over the RowBg0 color. enum ImGuiTableBgTarget_ { - ImGuiTableBgTarget_None = 0, - ImGuiTableBgTarget_RowBg0 = 1, // Set row background color 0 (generally used for background, automatically set when ImGuiTableFlags_RowBg is used) - ImGuiTableBgTarget_RowBg1 = 2, // Set row background color 1 (generally used for selection marking) - ImGuiTableBgTarget_CellBg = 3 // Set cell background color (top-most color) + ImGuiTableBgTarget_None = 0, + ImGuiTableBgTarget_RowBg0 = 1, // Set row background color 0 (generally used for background, automatically set when ImGuiTableFlags_RowBg is used) + ImGuiTableBgTarget_RowBg1 = 2, // Set row background color 1 (generally used for selection marking) + ImGuiTableBgTarget_CellBg = 3, // Set cell background color (top-most color) }; // Flags for ImGui::IsWindowFocused() @@ -1316,7 +1303,7 @@ enum ImGuiFocusedFlags_ ImGuiFocusedFlags_AnyWindow = 1 << 2, // Return true if any window is focused. Important: If you are trying to tell how to dispatch your low-level inputs, do NOT use this. Use 'io.WantCaptureMouse' instead! Please read the FAQ! ImGuiFocusedFlags_NoPopupHierarchy = 1 << 3, // Do not consider popup hierarchy (do not treat popup emitter as parent of popup) (when used with _ChildWindows or _RootWindow) ImGuiFocusedFlags_DockHierarchy = 1 << 4, // Consider docking hierarchy (treat dockspace host as parent of docked window) (when used with _ChildWindows or _RootWindow) - ImGuiFocusedFlags_RootAndChildWindows = ImGuiFocusedFlags_RootWindow | ImGuiFocusedFlags_ChildWindows + ImGuiFocusedFlags_RootAndChildWindows = ImGuiFocusedFlags_RootWindow | ImGuiFocusedFlags_ChildWindows, }; // Flags for ImGui::IsItemHovered(), ImGui::IsWindowHovered() @@ -1335,8 +1322,9 @@ enum ImGuiHoveredFlags_ ImGuiHoveredFlags_AllowWhenBlockedByActiveItem = 1 << 7, // Return true even if an active item is blocking access to this item/window. Useful for Drag and Drop patterns. ImGuiHoveredFlags_AllowWhenOverlapped = 1 << 8, // IsItemHovered() only: Return true even if the position is obstructed or overlapped by another window ImGuiHoveredFlags_AllowWhenDisabled = 1 << 9, // IsItemHovered() only: Return true even if the item is disabled + ImGuiHoveredFlags_NoNavOverride = 1 << 10, // Disable using gamepad/keyboard navigation state when active, always query mouse. ImGuiHoveredFlags_RectOnly = ImGuiHoveredFlags_AllowWhenBlockedByPopup | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem | ImGuiHoveredFlags_AllowWhenOverlapped, - ImGuiHoveredFlags_RootAndChildWindows = ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows + ImGuiHoveredFlags_RootAndChildWindows = ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows, }; // Flags for ImGui::DockSpace(), shared/inherited by child nodes. @@ -1351,7 +1339,7 @@ enum ImGuiDockNodeFlags_ ImGuiDockNodeFlags_PassthruCentralNode = 1 << 3, // Shared // Enable passthru dockspace: 1) DockSpace() will render a ImGuiCol_WindowBg background covering everything excepted the Central Node when empty. Meaning the host window should probably use SetNextWindowBgAlpha(0.0f) prior to Begin() when using this. 2) When Central Node is empty: let inputs pass-through + won't display a DockingEmptyBg background. See demo for details. ImGuiDockNodeFlags_NoSplit = 1 << 4, // Shared/Local // Disable splitting the node into smaller nodes. Useful e.g. when embedding dockspaces into a main root one (the root one may have splitting disabled to reduce confusion). Note: when turned off, existing splits will be preserved. ImGuiDockNodeFlags_NoResize = 1 << 5, // Shared/Local // Disable resizing node using the splitter/separators. Useful with programmatically setup dockspaces. - ImGuiDockNodeFlags_AutoHideTabBar = 1 << 6 // Shared/Local // Tab bar will automatically hide when there is a single window in the dock node. + ImGuiDockNodeFlags_AutoHideTabBar = 1 << 6, // Shared/Local // Tab bar will automatically hide when there is a single window in the dock node. }; // Flags for ImGui::BeginDragDropSource(), ImGui::AcceptDragDropPayload() @@ -1369,7 +1357,7 @@ enum ImGuiDragDropFlags_ ImGuiDragDropFlags_AcceptBeforeDelivery = 1 << 10, // AcceptDragDropPayload() will returns true even before the mouse button is released. You can then call IsDelivery() to test if the payload needs to be delivered. ImGuiDragDropFlags_AcceptNoDrawDefaultRect = 1 << 11, // Do not draw the default highlight rectangle when hovering over target. ImGuiDragDropFlags_AcceptNoPreviewTooltip = 1 << 12, // Request hiding the BeginDragDropSource tooltip from the BeginDragDropTarget site. - ImGuiDragDropFlags_AcceptPeekOnly = ImGuiDragDropFlags_AcceptBeforeDelivery | ImGuiDragDropFlags_AcceptNoDrawDefaultRect // For peeking ahead and inspecting the payload before delivery. + ImGuiDragDropFlags_AcceptPeekOnly = ImGuiDragDropFlags_AcceptBeforeDelivery | ImGuiDragDropFlags_AcceptNoDrawDefaultRect, // For peeking ahead and inspecting the payload before delivery. }; // Standard Drag and Drop payload types. You can define you own payload types using short strings. Types starting with '_' are defined by Dear ImGui. @@ -1411,10 +1399,13 @@ enum ImGuiSortDirection_ ImGuiSortDirection_Descending = 2 // Descending = 9->0, Z->A etc. }; -// User fill ImGuiIO.KeyMap[] array with indices into the ImGuiIO.KeysDown[512] array +// Keys value 0 to 511 are left unused as legacy native/opaque key values (< 1.87) +// Keys value >= 512 are named keys (>= 1.87) enum ImGuiKey_ { - ImGuiKey_Tab, + // Keyboard + ImGuiKey_None = 0, + ImGuiKey_Tab = 512, // == ImGuiKey_NamedKey_BEGIN ImGuiKey_LeftArrow, ImGuiKey_RightArrow, ImGuiKey_UpArrow, @@ -1429,66 +1420,132 @@ enum ImGuiKey_ ImGuiKey_Space, ImGuiKey_Enter, ImGuiKey_Escape, - ImGuiKey_KeyPadEnter, - ImGuiKey_A, // for text edit CTRL+A: select all - ImGuiKey_C, // for text edit CTRL+C: copy - ImGuiKey_V, // for text edit CTRL+V: paste - ImGuiKey_X, // for text edit CTRL+X: cut - ImGuiKey_Y, // for text edit CTRL+Y: redo - ImGuiKey_Z, // for text edit CTRL+Z: undo - ImGuiKey_COUNT + ImGuiKey_LeftCtrl, ImGuiKey_LeftShift, ImGuiKey_LeftAlt, ImGuiKey_LeftSuper, + ImGuiKey_RightCtrl, ImGuiKey_RightShift, ImGuiKey_RightAlt, ImGuiKey_RightSuper, + ImGuiKey_Menu, + ImGuiKey_0, ImGuiKey_1, ImGuiKey_2, ImGuiKey_3, ImGuiKey_4, ImGuiKey_5, ImGuiKey_6, ImGuiKey_7, ImGuiKey_8, ImGuiKey_9, + ImGuiKey_A, ImGuiKey_B, ImGuiKey_C, ImGuiKey_D, ImGuiKey_E, ImGuiKey_F, ImGuiKey_G, ImGuiKey_H, ImGuiKey_I, ImGuiKey_J, + ImGuiKey_K, ImGuiKey_L, ImGuiKey_M, ImGuiKey_N, ImGuiKey_O, ImGuiKey_P, ImGuiKey_Q, ImGuiKey_R, ImGuiKey_S, ImGuiKey_T, + ImGuiKey_U, ImGuiKey_V, ImGuiKey_W, ImGuiKey_X, ImGuiKey_Y, ImGuiKey_Z, + ImGuiKey_F1, ImGuiKey_F2, ImGuiKey_F3, ImGuiKey_F4, ImGuiKey_F5, ImGuiKey_F6, + ImGuiKey_F7, ImGuiKey_F8, ImGuiKey_F9, ImGuiKey_F10, ImGuiKey_F11, ImGuiKey_F12, + ImGuiKey_Apostrophe, // ' + ImGuiKey_Comma, // , + ImGuiKey_Minus, // - + ImGuiKey_Period, // . + ImGuiKey_Slash, // / + ImGuiKey_Semicolon, // ; + ImGuiKey_Equal, // = + ImGuiKey_LeftBracket, // [ + ImGuiKey_Backslash, // \ (this text inhibit multiline comment caused by backslash) + ImGuiKey_RightBracket, // ] + ImGuiKey_GraveAccent, // ` + ImGuiKey_CapsLock, + ImGuiKey_ScrollLock, + ImGuiKey_NumLock, + ImGuiKey_PrintScreen, + ImGuiKey_Pause, + ImGuiKey_Keypad0, ImGuiKey_Keypad1, ImGuiKey_Keypad2, ImGuiKey_Keypad3, ImGuiKey_Keypad4, + ImGuiKey_Keypad5, ImGuiKey_Keypad6, ImGuiKey_Keypad7, ImGuiKey_Keypad8, ImGuiKey_Keypad9, + ImGuiKey_KeypadDecimal, + ImGuiKey_KeypadDivide, + ImGuiKey_KeypadMultiply, + ImGuiKey_KeypadSubtract, + ImGuiKey_KeypadAdd, + ImGuiKey_KeypadEnter, + ImGuiKey_KeypadEqual, + + // Gamepad (some of those are analog values, 0.0f to 1.0f) // GAME NAVIGATION ACTION + // (download controller mapping PNG/PSD at http://dearimgui.org/controls_sheets) + ImGuiKey_GamepadStart, // Menu (Xbox) + (Switch) Start/Options (PS) + ImGuiKey_GamepadBack, // View (Xbox) - (Switch) Share (PS) + ImGuiKey_GamepadFaceLeft, // X (Xbox) Y (Switch) Square (PS) // Tap: Toggle Menu. Hold: Windowing mode (Focus/Move/Resize windows) + ImGuiKey_GamepadFaceRight, // B (Xbox) A (Switch) Circle (PS) // Cancel / Close / Exit + ImGuiKey_GamepadFaceUp, // Y (Xbox) X (Switch) Triangle (PS) // Text Input / On-screen Keyboard + ImGuiKey_GamepadFaceDown, // A (Xbox) B (Switch) Cross (PS) // Activate / Open / Toggle / Tweak + ImGuiKey_GamepadDpadLeft, // D-pad Left // Move / Tweak / Resize Window (in Windowing mode) + ImGuiKey_GamepadDpadRight, // D-pad Right // Move / Tweak / Resize Window (in Windowing mode) + ImGuiKey_GamepadDpadUp, // D-pad Up // Move / Tweak / Resize Window (in Windowing mode) + ImGuiKey_GamepadDpadDown, // D-pad Down // Move / Tweak / Resize Window (in Windowing mode) + ImGuiKey_GamepadL1, // L Bumper (Xbox) L (Switch) L1 (PS) // Tweak Slower / Focus Previous (in Windowing mode) + ImGuiKey_GamepadR1, // R Bumper (Xbox) R (Switch) R1 (PS) // Tweak Faster / Focus Next (in Windowing mode) + ImGuiKey_GamepadL2, // L Trig. (Xbox) ZL (Switch) L2 (PS) [Analog] + ImGuiKey_GamepadR2, // R Trig. (Xbox) ZR (Switch) R2 (PS) [Analog] + ImGuiKey_GamepadL3, // L Stick (Xbox) L3 (Switch) L3 (PS) + ImGuiKey_GamepadR3, // R Stick (Xbox) R3 (Switch) R3 (PS) + ImGuiKey_GamepadLStickLeft, // [Analog] // Move Window (in Windowing mode) + ImGuiKey_GamepadLStickRight, // [Analog] // Move Window (in Windowing mode) + ImGuiKey_GamepadLStickUp, // [Analog] // Move Window (in Windowing mode) + ImGuiKey_GamepadLStickDown, // [Analog] // Move Window (in Windowing mode) + ImGuiKey_GamepadRStickLeft, // [Analog] + ImGuiKey_GamepadRStickRight, // [Analog] + ImGuiKey_GamepadRStickUp, // [Analog] + ImGuiKey_GamepadRStickDown, // [Analog] + + // Keyboard Modifiers (explicitly submitted by backend via AddKeyEvent() calls) + // - This is mirroring the data also written to io.KeyCtrl, io.KeyShift, io.KeyAlt, io.KeySuper, in a format allowing + // them to be accessed via standard key API, allowing calls such as IsKeyPressed(), IsKeyReleased(), querying duration etc. + // - Code polling every keys (e.g. an interface to detect a key press for input mapping) might want to ignore those + // and prefer using the real keys (e.g. ImGuiKey_LeftCtrl, ImGuiKey_RightCtrl instead of ImGuiKey_ModCtrl). + // - In theory the value of keyboard modifiers should be roughly equivalent to a logical or of the equivalent left/right keys. + // In practice: it's complicated; mods are often provided from different sources. Keyboard layout, IME, sticky keys and + // backends tend to interfere and break that equivalence. The safer decision is to relay that ambiguity down to the end-user... + ImGuiKey_ModCtrl, ImGuiKey_ModShift, ImGuiKey_ModAlt, ImGuiKey_ModSuper, + + // Mouse Buttons (auto-submitted from AddMouseButtonEvent() calls) + // - This is mirroring the data also written to io.MouseDown[], io.MouseWheel, in a format allowing them to be accessed via standard key API. + ImGuiKey_MouseLeft, ImGuiKey_MouseRight, ImGuiKey_MouseMiddle, ImGuiKey_MouseX1, ImGuiKey_MouseX2, ImGuiKey_MouseWheelX, ImGuiKey_MouseWheelY, + + // End of list + ImGuiKey_COUNT, // No valid ImGuiKey is ever greater than this value + + // [Internal] Prior to 1.87 we required user to fill io.KeysDown[512] using their own native index + a io.KeyMap[] array. + // We are ditching this method but keeping a legacy path for user code doing e.g. IsKeyPressed(MY_NATIVE_KEY_CODE) + ImGuiKey_NamedKey_BEGIN = 512, + ImGuiKey_NamedKey_END = ImGuiKey_COUNT, + ImGuiKey_NamedKey_COUNT = ImGuiKey_NamedKey_END - ImGuiKey_NamedKey_BEGIN, +#ifdef IMGUI_DISABLE_OBSOLETE_KEYIO + ImGuiKey_KeysData_SIZE = ImGuiKey_NamedKey_COUNT, // Size of KeysData[]: only hold named keys + ImGuiKey_KeysData_OFFSET = ImGuiKey_NamedKey_BEGIN, // First key stored in io.KeysData[0]. Accesses to io.KeysData[] must use (key - ImGuiKey_KeysData_OFFSET). +#else + ImGuiKey_KeysData_SIZE = ImGuiKey_COUNT, // Size of KeysData[]: hold legacy 0..512 keycodes + named keys + ImGuiKey_KeysData_OFFSET = 0, // First key stored in io.KeysData[0]. Accesses to io.KeysData[] must use (key - ImGuiKey_KeysData_OFFSET). +#endif + +#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS + ImGuiKey_KeyPadEnter = ImGuiKey_KeypadEnter, // Renamed in 1.87 +#endif }; -// To test io.KeyMods (which is a combination of individual fields io.KeyCtrl, io.KeyShift, io.KeyAlt set by user/backend) -enum ImGuiKeyModFlags_ +// Helper "flags" version of key-mods to store and compare multiple key-mods easily. Sometimes used for storage (e.g. io.KeyMods) but otherwise not much used in public API. +enum ImGuiModFlags_ { - ImGuiKeyModFlags_None = 0, - ImGuiKeyModFlags_Ctrl = 1 << 0, - ImGuiKeyModFlags_Shift = 1 << 1, - ImGuiKeyModFlags_Alt = 1 << 2, - ImGuiKeyModFlags_Super = 1 << 3 + ImGuiModFlags_None = 0, + ImGuiModFlags_Ctrl = 1 << 0, + ImGuiModFlags_Shift = 1 << 1, + ImGuiModFlags_Alt = 1 << 2, // Option/Menu key + ImGuiModFlags_Super = 1 << 3, // Cmd/Super/Windows key + ImGuiModFlags_All = 0x0F }; -// Gamepad/Keyboard navigation -// Keyboard: Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard to enable. NewFrame() will automatically fill io.NavInputs[] based on your io.KeysDown[] + io.KeyMap[] arrays. -// Gamepad: Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad to enable. Backend: set ImGuiBackendFlags_HasGamepad and fill the io.NavInputs[] fields before calling NewFrame(). Note that io.NavInputs[] is cleared by EndFrame(). -// Read instructions in imgui.cpp for more details. Download PNG/PSD at http://dearimgui.org/controls_sheets. -enum ImGuiNavInput_ +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO +// OBSOLETED in 1.88 (from July 2022): ImGuiNavInput and io.NavInputs[]. +// Official backends between 1.60 and 1.86: will keep working and feed gamepad inputs as long as IMGUI_DISABLE_OBSOLETE_KEYIO is not set. +// Custom backends: feed gamepad inputs via io.AddKeyEvent() and ImGuiKey_GamepadXXX enums. +enum ImGuiNavInput { - // Gamepad Mapping - ImGuiNavInput_Activate, // activate / open / toggle / tweak value // e.g. Cross (PS4), A (Xbox), A (Switch), Space (Keyboard) - ImGuiNavInput_Cancel, // cancel / close / exit // e.g. Circle (PS4), B (Xbox), B (Switch), Escape (Keyboard) - ImGuiNavInput_Input, // text input / on-screen keyboard // e.g. Triang.(PS4), Y (Xbox), X (Switch), Return (Keyboard) - ImGuiNavInput_Menu, // tap: toggle menu / hold: focus, move, resize // e.g. Square (PS4), X (Xbox), Y (Switch), Alt (Keyboard) - ImGuiNavInput_DpadLeft, // move / tweak / resize window (w/ PadMenu) // e.g. D-pad Left/Right/Up/Down (Gamepads), Arrow keys (Keyboard) - ImGuiNavInput_DpadRight, // - ImGuiNavInput_DpadUp, // - ImGuiNavInput_DpadDown, // - ImGuiNavInput_LStickLeft, // scroll / move window (w/ PadMenu) // e.g. Left Analog Stick Left/Right/Up/Down - ImGuiNavInput_LStickRight, // - ImGuiNavInput_LStickUp, // - ImGuiNavInput_LStickDown, // - ImGuiNavInput_FocusPrev, // next window (w/ PadMenu) // e.g. L1 or L2 (PS4), LB or LT (Xbox), L or ZL (Switch) - ImGuiNavInput_FocusNext, // prev window (w/ PadMenu) // e.g. R1 or R2 (PS4), RB or RT (Xbox), R or ZL (Switch) - ImGuiNavInput_TweakSlow, // slower tweaks // e.g. L1 or L2 (PS4), LB or LT (Xbox), L or ZL (Switch) - ImGuiNavInput_TweakFast, // faster tweaks // e.g. R1 or R2 (PS4), RB or RT (Xbox), R or ZL (Switch) - - // [Internal] Don't use directly! This is used internally to differentiate keyboard from gamepad inputs for behaviors that require to differentiate them. - // Keyboard behavior that have no corresponding gamepad mapping (e.g. CTRL+TAB) will be directly reading from io.KeysDown[] instead of io.NavInputs[]. - ImGuiNavInput_KeyLeft_, // move left // = Arrow keys - ImGuiNavInput_KeyRight_, // move right - ImGuiNavInput_KeyUp_, // move up - ImGuiNavInput_KeyDown_, // move down + ImGuiNavInput_Activate, ImGuiNavInput_Cancel, ImGuiNavInput_Input, ImGuiNavInput_Menu, ImGuiNavInput_DpadLeft, ImGuiNavInput_DpadRight, ImGuiNavInput_DpadUp, ImGuiNavInput_DpadDown, + ImGuiNavInput_LStickLeft, ImGuiNavInput_LStickRight, ImGuiNavInput_LStickUp, ImGuiNavInput_LStickDown, ImGuiNavInput_FocusPrev, ImGuiNavInput_FocusNext, ImGuiNavInput_TweakSlow, ImGuiNavInput_TweakFast, ImGuiNavInput_COUNT, - ImGuiNavInput_InternalStart_ = ImGuiNavInput_KeyLeft_ }; +#endif // 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 backend to fill io.NavInputs[]. Backend also needs to set ImGuiBackendFlags_HasGamepad. + ImGuiConfigFlags_NavEnableKeyboard = 1 << 0, // Master keyboard navigation enable flag. + ImGuiConfigFlags_NavEnableGamepad = 1 << 1, // Master gamepad navigation enable flag. Backend 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 backend, otherwise ImGui will react as if the mouse is jumping around back and forth. ImGuiConfigFlags_NavNoCaptureKeyboard = 1 << 3, // Instruct navigation to not set the io.WantCaptureKeyboard flag when io.NavActive is set. ImGuiConfigFlags_NoMouse = 1 << 4, // Instruct imgui to clear mouse position/buttons in NewFrame(). This allows ignoring the mouse information set by the backend. @@ -1503,9 +1560,9 @@ enum ImGuiConfigFlags_ ImGuiConfigFlags_DpiEnableScaleViewports= 1 << 14, // [BETA: Don't use] FIXME-DPI: Reposition and resize imgui windows when the DpiScale of a viewport changed (mostly useful for the main viewport hosting other window). Note that resizing the main window itself is up to your application. ImGuiConfigFlags_DpiEnableScaleFonts = 1 << 15, // [BETA: Don't use] FIXME-DPI: Request bitmap-scaled fonts to match DpiScale. This is a very low-quality workaround. The correct way to handle DPI is _currently_ to replace the atlas and/or fonts in the Platform_OnChangedViewport callback, but this is all early work in progress. - // User storage (to allow your backend/engine to communicate to code that may be shared between multiple projects. Those flags are not used by core Dear ImGui) + // User storage (to allow your backend/engine to communicate to code that may be shared between multiple projects. Those flags are NOT used by core Dear ImGui) ImGuiConfigFlags_IsSRGB = 1 << 20, // Application is SRGB-aware. - ImGuiConfigFlags_IsTouchScreen = 1 << 21 // Application is using a touch screen instead of a mouse. + ImGuiConfigFlags_IsTouchScreen = 1 << 21, // Application is using a touch screen instead of a mouse. }; // Backend capabilities flags stored in io.BackendFlags. Set by imgui_impl_xxx or custom backend. @@ -1519,8 +1576,8 @@ enum ImGuiBackendFlags_ // [BETA] Viewports ImGuiBackendFlags_PlatformHasViewports = 1 << 10, // Backend Platform supports multiple viewports. - ImGuiBackendFlags_HasMouseHoveredViewport=1 << 11, // Backend Platform supports setting io.MouseHoveredViewport to the viewport directly under the mouse _IGNORING_ viewports with the ImGuiViewportFlags_NoInputs flag and _REGARDLESS_ of whether another viewport is focused and may be capturing the mouse. This information is _NOT EASY_ to provide correctly with most high-level engines! Don't set this without studying _carefully_ how the backends handle ImGuiViewportFlags_NoInputs! - ImGuiBackendFlags_RendererHasViewports = 1 << 12 // Backend Renderer supports multiple viewports. + ImGuiBackendFlags_HasMouseHoveredViewport=1 << 11, // Backend Platform supports calling io.AddMouseViewportEvent() with the viewport under the mouse. IF POSSIBLE, ignore viewports with the ImGuiViewportFlags_NoInputs flag (Win32 backend, GLFW 3.30+ backend can do this, SDL backend cannot). If this cannot be done, Dear ImGui needs to use a flawed heuristic to find the viewport under. + ImGuiBackendFlags_RendererHasViewports = 1 << 12, // Backend Renderer supports multiple viewports. }; // Enumeration for PushStyleColor() / PopStyleColor() @@ -1556,10 +1613,10 @@ enum ImGuiCol_ ImGuiCol_Separator, ImGuiCol_SeparatorHovered, ImGuiCol_SeparatorActive, - ImGuiCol_ResizeGrip, + ImGuiCol_ResizeGrip, // Resize grip in lower-right and lower-left corners of windows. ImGuiCol_ResizeGripHovered, ImGuiCol_ResizeGripActive, - ImGuiCol_Tab, + ImGuiCol_Tab, // TabItem in a TabBar ImGuiCol_TabHovered, ImGuiCol_TabActive, ImGuiCol_TabUnfocused, @@ -1576,7 +1633,7 @@ enum ImGuiCol_ ImGuiCol_TableRowBg, // Table row background (even rows) ImGuiCol_TableRowBgAlt, // Table row background (odd rows) ImGuiCol_TextSelectedBg, - ImGuiCol_DragDropTarget, + ImGuiCol_DragDropTarget, // Rectangle highlighting a drop target ImGuiCol_NavHighlight, // Gamepad/keyboard: current highlighted item ImGuiCol_NavWindowingHighlight, // Highlight window when using CTRL+TAB ImGuiCol_NavWindowingDimBg, // Darken/colorize entire screen behind the CTRL+TAB window list, when active @@ -1588,7 +1645,7 @@ enum ImGuiCol_ // - The enum only refers to fields of ImGuiStyle which makes sense to be pushed/popped inside UI code. // During initialization or between frames, feel free to just poke into ImGuiStyle directly. // - Tip: Use your programming IDE navigation facilities on the names in the _second column_ below to find the actual members and their description. -// In Visual Studio IDE: CTRL+comma ("Edit.NavigateTo") can follow symbols in comments, whereas CTRL+F12 ("Edit.GoToImplementation") cannot. +// In Visual Studio IDE: CTRL+comma ("Edit.GoToAll") can follow symbols in comments, whereas CTRL+F12 ("Edit.GoToImplementation") cannot. // With Visual Assist installed: ALT+G ("VAssistX.GoToImplementation") can also follow symbols in comments. // - When changing this enum, you need to update the associated internal table GStyleVarInfo[] accordingly. This is where we link enum values to members offset/type. enum ImGuiStyleVar_ @@ -1632,7 +1689,7 @@ enum ImGuiButtonFlags_ // [Internal] ImGuiButtonFlags_MouseButtonMask_ = ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight | ImGuiButtonFlags_MouseButtonMiddle, - ImGuiButtonFlags_MouseButtonDefault_ = ImGuiButtonFlags_MouseButtonLeft + ImGuiButtonFlags_MouseButtonDefault_ = ImGuiButtonFlags_MouseButtonLeft, }; // Flags for ColorEdit3() / ColorEdit4() / ColorPicker3() / ColorPicker4() / ColorButton() @@ -1673,12 +1730,10 @@ enum ImGuiColorEditFlags_ ImGuiColorEditFlags_DisplayMask_ = ImGuiColorEditFlags_DisplayRGB | ImGuiColorEditFlags_DisplayHSV | ImGuiColorEditFlags_DisplayHex, ImGuiColorEditFlags_DataTypeMask_ = ImGuiColorEditFlags_Uint8 | ImGuiColorEditFlags_Float, ImGuiColorEditFlags_PickerMask_ = ImGuiColorEditFlags_PickerHueWheel | ImGuiColorEditFlags_PickerHueBar, - ImGuiColorEditFlags_InputMask_ = ImGuiColorEditFlags_InputRGB | ImGuiColorEditFlags_InputHSV + ImGuiColorEditFlags_InputMask_ = ImGuiColorEditFlags_InputRGB | ImGuiColorEditFlags_InputHSV, // Obsolete names (will be removed) -#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - , ImGuiColorEditFlags_RGB = ImGuiColorEditFlags_DisplayRGB, ImGuiColorEditFlags_HSV = ImGuiColorEditFlags_DisplayHSV, ImGuiColorEditFlags_HEX = ImGuiColorEditFlags_DisplayHex // [renamed in 1.69] -#endif + // ImGuiColorEditFlags_RGB = ImGuiColorEditFlags_DisplayRGB, ImGuiColorEditFlags_HSV = ImGuiColorEditFlags_DisplayHSV, ImGuiColorEditFlags_HEX = ImGuiColorEditFlags_DisplayHex // [renamed in 1.69] }; // Flags for DragFloat(), DragInt(), SliderFloat(), SliderInt() etc. @@ -1690,11 +1745,11 @@ enum ImGuiSliderFlags_ ImGuiSliderFlags_Logarithmic = 1 << 5, // Make the widget logarithmic (linear otherwise). Consider using ImGuiSliderFlags_NoRoundToFormat with this if using a format-string with small amount of digits. ImGuiSliderFlags_NoRoundToFormat = 1 << 6, // Disable rounding underlying value to match precision of the display format string (e.g. %.3f values are rounded to those 3 digits) ImGuiSliderFlags_NoInput = 1 << 7, // Disable CTRL+Click or Enter key allowing to input text directly into the widget - ImGuiSliderFlags_InvalidMask_ = 0x7000000F // [Internal] We treat using those bits as being potentially a 'float power' argument from the previous API that has got miscast to this enum, and will trigger an assert if needed. + ImGuiSliderFlags_InvalidMask_ = 0x7000000F, // [Internal] We treat using those bits as being potentially a 'float power' argument from the previous API that has got miscast to this enum, and will trigger an assert if needed. // Obsolete names (will be removed) #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - , ImGuiSliderFlags_ClampOnInput = ImGuiSliderFlags_AlwaysClamp // [renamed in 1.79] + ImGuiSliderFlags_ClampOnInput = ImGuiSliderFlags_AlwaysClamp, // [renamed in 1.79] #endif }; @@ -1734,7 +1789,7 @@ enum ImGuiCond_ ImGuiCond_Always = 1 << 0, // No condition (always set the variable) ImGuiCond_Once = 1 << 1, // Set the variable once per runtime session (only the first call will succeed) ImGuiCond_FirstUseEver = 1 << 2, // Set the variable if the object/window has no persistently saved data (no entry in .ini file) - ImGuiCond_Appearing = 1 << 3 // Set the variable if the object/window is appearing after being hidden/inactive (or the first time) + ImGuiCond_Appearing = 1 << 3, // Set the variable if the object/window is appearing after being hidden/inactive (or the first time) }; //----------------------------------------------------------------------------- @@ -1813,13 +1868,14 @@ struct ImVector inline void resize(int new_size, const T& v) { if (new_size > Capacity) reserve(_grow_capacity(new_size)); if (new_size > Size) for (int n = Size; n < new_size; n++) memcpy(&Data[n], &v, sizeof(v)); Size = new_size; } inline void shrink(int new_size) { IM_ASSERT(new_size <= Size); Size = new_size; } // Resize a vector to a smaller size, guaranteed not to cause a reallocation inline void reserve(int new_capacity) { if (new_capacity <= Capacity) return; T* new_data = (T*)IM_ALLOC((size_t)new_capacity * sizeof(T)); if (Data) { memcpy(new_data, Data, (size_t)Size * sizeof(T)); IM_FREE(Data); } Data = new_data; Capacity = new_capacity; } + inline void reserve_discard(int new_capacity) { if (new_capacity <= Capacity) return; if (Data) IM_FREE(Data); Data = (T*)IM_ALLOC((size_t)new_capacity * sizeof(T)); Capacity = new_capacity; } // NB: It is illegal to call push_back/push_front/insert with a reference pointing inside the ImVector data itself! e.g. v.push_back(v[10]) is forbidden. inline void push_back(const T& v) { if (Size == Capacity) reserve(_grow_capacity(Size + 1)); memcpy(&Data[Size], &v, sizeof(v)); Size++; } inline void pop_back() { IM_ASSERT(Size > 0); Size--; } inline void push_front(const T& v) { if (Size == 0) push_back(v); else insert(Data, v); } inline T* erase(const T* it) { IM_ASSERT(it >= Data && it < Data + Size); const ptrdiff_t off = it - Data; memmove(Data + off, Data + off + 1, ((size_t)Size - (size_t)off - 1) * sizeof(T)); Size--; return Data + off; } - inline T* erase(const T* it, const T* it_last){ IM_ASSERT(it >= Data && it < Data + Size && it_last > it && it_last <= Data + Size); const ptrdiff_t count = it_last - it; const ptrdiff_t off = it - Data; memmove(Data + off, Data + off + count, ((size_t)Size - (size_t)off - (size_t)count) * sizeof(T)); Size -= (int)count; return Data + off; } + inline T* erase(const T* it, const T* it_last){ IM_ASSERT(it >= Data && it < Data + Size && it_last >= it && it_last <= Data + Size); const ptrdiff_t count = it_last - it; const ptrdiff_t off = it - Data; memmove(Data + off, Data + off + count, ((size_t)Size - (size_t)off - (size_t)count) * sizeof(T)); Size -= (int)count; return Data + off; } inline T* erase_unsorted(const T* it) { IM_ASSERT(it >= Data && it < Data + Size); const ptrdiff_t off = it - Data; if (it < Data + Size - 1) memcpy(Data + off, Data + Size - 1, sizeof(T)); Size--; return Data + off; } inline T* insert(const T* it, const T& v) { IM_ASSERT(it >= Data && it <= Data + Size); const ptrdiff_t off = it - Data; if (Size == Capacity) reserve(_grow_capacity(Size + 1)); if (off < (int)Size) memmove(Data + off + 1, Data + off, ((size_t)Size - (size_t)off) * sizeof(T)); memcpy(&Data[off], &v, sizeof(v)); Size++; return Data + off; } inline bool contains(const T& v) const { const T* data = Data; const T* data_end = Data + Size; while (data < data_end) if (*data++ == v) return true; return false; } @@ -1877,7 +1933,7 @@ struct ImGuiStyle ImVec2 DisplaySafeAreaPadding; // If you cannot see the edges of your screen (e.g. on a TV) increase the safe area padding. Apply to popups/tooltips as well regular windows. NB: Prefer configuring your TV sets correctly! float MouseCursorScale; // Scale software rendered mouse cursor (when io.MouseDrawCursor is enabled). We apply per-monitor DPI scaling over this scale. May be removed later. bool AntiAliasedLines; // Enable anti-aliased lines/borders. Disable if you are really tight on CPU/GPU. Latched at the beginning of the frame (copied to ImDrawList). - bool AntiAliasedLinesUseTex; // Enable anti-aliased lines/borders using textures where possible. Require backend to render with bilinear filtering. Latched at the beginning of the frame (copied to ImDrawList). + bool AntiAliasedLinesUseTex; // Enable anti-aliased lines/borders using textures where possible. Require backend to render with bilinear filtering (NOT point/nearest filtering). Latched at the beginning of the frame (copied to ImDrawList). bool AntiAliasedFill; // Enable anti-aliased edges around filled shapes (rounded rectangles, circles, etc.). Disable if you are really tight on CPU/GPU. Latched at the beginning of the frame (copied to ImDrawList). float CurveTessellationTol; // Tessellation tolerance when using PathBezierCurveTo() without a specific number of segments. Decrease for highly tessellated curves (higher quality, more polygons), increase to reduce quality. float CircleTessellationMaxError; // Maximum error (in pixels) allowed when using AddCircle()/AddCircleFilled() or drawing rounded corner rectangles with no explicit segment count specified. Decrease for higher quality but more geometry. @@ -1894,23 +1950,32 @@ struct ImGuiStyle // Access via ImGui::GetIO(). Read 'Programmer guide' section in .cpp file for general usage. //----------------------------------------------------------------------------- +// [Internal] Storage used by IsKeyDown(), IsKeyPressed() etc functions. +// If prior to 1.87 you used io.KeysDownDuration[] (which was marked as internal), you should use GetKeyData(key)->DownDuration and not io.KeysData[key]->DownDuration. +struct ImGuiKeyData +{ + bool Down; // True for if key is down + float DownDuration; // Duration the key has been down (<0.0f: not pressed, 0.0f: just pressed, >0.0f: time held) + float DownDurationPrev; // Last frame duration the key has been down + float AnalogValue; // 0.0f..1.0f for gamepad values +}; + struct ImGuiIO { //------------------------------------------------------------------ - // Configuration (fill once) // Default value + // Configuration // Default value //------------------------------------------------------------------ ImGuiConfigFlags ConfigFlags; // = 0 // See ImGuiConfigFlags_ enum. Set by user/application. Gamepad/keyboard navigation options, etc. ImGuiBackendFlags BackendFlags; // = 0 // See ImGuiBackendFlags_ enum. Set by backend (imgui_impl_xxx files or custom backend) to communicate features supported by the backend. - ImVec2 DisplaySize; // // Main display size, in pixels (generally == GetMainViewport()->Size) - float DeltaTime; // = 1.0f/60.0f // Time elapsed since last frame, in seconds. + ImVec2 DisplaySize; // // Main display size, in pixels (generally == GetMainViewport()->Size). May change every frame. + float DeltaTime; // = 1.0f/60.0f // Time elapsed since last frame, in seconds. May change every frame. float IniSavingRate; // = 5.0f // Minimum time between saving positions/sizes to .ini file, in seconds. const char* IniFilename; // = "imgui.ini" // Path to .ini file (important: default "imgui.ini" is relative to current working dir!). Set NULL to disable automatic .ini loading/saving or if you want to manually call LoadIniSettingsXXX() / SaveIniSettingsXXX() functions. const char* LogFilename; // = "imgui_log.txt"// Path to .log file (default parameter to ImGui::LogToFile when no file is specified). float MouseDoubleClickTime; // = 0.30f // Time for a double-click, in seconds. float MouseDoubleClickMaxDist; // = 6.0f // Distance threshold to stay in to validate a double-click, in pixels. float MouseDragThreshold; // = 6.0f // Distance threshold before considering we are dragging. - int KeyMap[ImGuiKey_COUNT]; // // Map of indices into the KeysDown[512] entries array which represent your "native" keyboard state. float KeyRepeatDelay; // = 0.250f // When holding a key/button, time before it starts repeating, in seconds (for buttons in Repeat mode, etc.). float KeyRepeatRate; // = 0.050f // When holding a key/button, rate at which it repeats, in seconds. void* UserData; // = NULL // Store your own data for retrieval by callbacks. @@ -1936,7 +2001,9 @@ struct ImGuiIO // Miscellaneous options bool MouseDrawCursor; // = false // Request ImGui to draw a mouse cursor for you (if you are on a platform without a mouse cursor). Cannot be easily renamed to 'io.ConfigXXX' because this is frequently used by backend implementations. bool ConfigMacOSXBehaviors; // = defined(__APPLE__) // OS X style: Text editing cursor movement using Alt instead of Ctrl, Shortcuts using Cmd/Super instead of Ctrl, Line/Text Start and End using Cmd+Arrows instead of Home/End, Double click selects by word instead of selecting whole text, Multi-selection in lists uses Cmd/Super instead of Ctrl. + bool ConfigInputTrickleEventQueue; // = true // 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. bool ConfigInputTextCursorBlink; // = true // Enable blinking cursor (optional as some users consider it to be distracting). + bool ConfigInputTextEnterKeepActive; // = false // [BETA] Pressing Enter will keep item active and select contents (single-line only). bool ConfigDragClickToInputText; // = false // [BETA] Enable turning DragXXX widgets into text input with a simple mouse click-release (without moving). Not desirable on devices without a keyboard. bool ConfigWindowsResizeFromEdges; // = true // Enable resizing of windows from their edges and from the lower-left corner. This requires (io.BackendFlags & ImGuiBackendFlags_HasMouseCursors) because it needs mouse cursor feedback. (This used to be a per-window ImGuiWindowFlags_ResizeFromAnySide flag) bool ConfigWindowsMoveFromTitleBarOnly; // = false // Enable allowing to move windows only when clicking on their title bar. Does not apply to windows without a title bar. @@ -1960,29 +2027,35 @@ struct ImGuiIO void (*SetClipboardTextFn)(void* user_data, const char* text); void* ClipboardUserData; + // Optional: Notify OS Input Method Editor of the screen position of your cursor for text input position (e.g. when using Japanese/Chinese IME on Windows) + // (default to use native imm32 api on Windows) + void (*SetPlatformImeDataFn)(ImGuiViewport* viewport, ImGuiPlatformImeData* data); +#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS + void* ImeWindowHandle; // = NULL // [Obsolete] Set ImGuiViewport::PlatformHandleRaw instead. Set this to your HWND to get automatic IME cursor positioning. +#else + void* _UnusedPadding; // Unused field to keep data structure the same size. +#endif + //------------------------------------------------------------------ - // Input - Fill before calling NewFrame() + // Input - Call before calling NewFrame() //------------------------------------------------------------------ - ImVec2 MousePos; // Mouse position, in pixels. Set to ImVec2(-FLT_MAX, -FLT_MAX) if mouse is unavailable (on another screen, etc.) - bool MouseDown[5]; // Mouse buttons: 0=left, 1=right, 2=middle + extras (ImGuiMouseButton_COUNT == 5). Dear ImGui mostly uses left and right buttons. Others buttons allows us to track if the mouse is being used by your application + available to user as a convenience via IsMouse** API. - float MouseWheel; // Mouse wheel Vertical: 1 unit scrolls about 5 lines text. - float MouseWheelH; // Mouse wheel Horizontal. Most users don't have a mouse with an horizontal wheel, may not be filled by all backends. - ImGuiID MouseHoveredViewport; // (Optional) When using multiple viewports: viewport the OS mouse cursor is hovering _IGNORING_ viewports with the ImGuiViewportFlags_NoInputs flag, and _REGARDLESS_ of whether another viewport is focused. Set io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport if you can provide this info. If you don't imgui will infer the value using the rectangles and last focused time of the viewports it knows about (ignoring other OS windows). - bool KeyCtrl; // Keyboard modifier pressed: Control - bool KeyShift; // Keyboard modifier pressed: Shift - bool KeyAlt; // Keyboard modifier pressed: Alt - bool KeySuper; // Keyboard modifier pressed: Cmd/Super/Windows - bool KeysDown[512]; // Keyboard keys that are pressed (ideally left in the "native" order your engine has access to keyboard keys, so you can use your own defines/enums for keys). - float NavInputs[ImGuiNavInput_COUNT]; // Gamepad inputs. Cleared back to zero by EndFrame(). Keyboard keys will be auto-mapped and be written here by NewFrame(). + // Input Functions + IMGUI_API void AddKeyEvent(ImGuiKey key, bool down); // Queue a new key down/up event. Key should be "translated" (as in, generally ImGuiKey_A matches the key end-user would use to emit an 'A' character) + IMGUI_API void AddKeyAnalogEvent(ImGuiKey key, bool down, float v); // Queue a new key down/up event for analog values (e.g. ImGuiKey_Gamepad_ values). Dead-zones should be handled by the backend. + IMGUI_API void AddMousePosEvent(float x, float y); // Queue a mouse position update. Use -FLT_MAX,-FLT_MAX to signify no mouse (e.g. app not focused and not hovered) + IMGUI_API void AddMouseButtonEvent(int button, bool down); // Queue a mouse button change + IMGUI_API void AddMouseWheelEvent(float wh_x, float wh_y); // Queue a mouse wheel update + IMGUI_API void AddMouseViewportEvent(ImGuiID id); // Queue a mouse hovered viewport. Requires backend to set ImGuiBackendFlags_HasMouseHoveredViewport to call this (for multi-viewport support). + IMGUI_API void AddFocusEvent(bool focused); // Queue a gain/loss of focus for the application (generally based on OS/platform focus of your window) + IMGUI_API void AddInputCharacter(unsigned int c); // Queue a new character input + IMGUI_API void AddInputCharacterUTF16(ImWchar16 c); // Queue a new character input from an UTF-16 character, it can be a surrogate + IMGUI_API void AddInputCharactersUTF8(const char* str); // Queue a new characters input from an UTF-8 string - // Functions - IMGUI_API void AddInputCharacter(unsigned int c); // Queue new character input - IMGUI_API void AddInputCharacterUTF16(ImWchar16 c); // Queue new character input from an UTF-16 character, it can be a surrogate - IMGUI_API void AddInputCharactersUTF8(const char* str); // Queue new characters input from an UTF-8 string - IMGUI_API void AddFocusEvent(bool focused); // Notifies Dear ImGui when hosting platform windows lose or gain input focus - IMGUI_API void ClearInputCharacters(); // [Internal] Clear the text input buffer manually - IMGUI_API void ClearInputKeys(); // [Internal] Release all keys + IMGUI_API void SetKeyEventNativeData(ImGuiKey key, int native_keycode, int native_scancode, int native_legacy_index = -1); // [Optional] Specify index for legacy <1.87 IsKeyXXX() functions with native indices + specify native keycode, scancode. + IMGUI_API void SetAppAcceptingEvents(bool accepting_events); // Set master flag for accepting key/mouse/text events (default to true). Useful if you have native dialog boxes that are interrupting your application loop/refresh, and you want to disable events being queued while your app is frozen. + IMGUI_API void ClearInputCharacters(); // [Internal] Clear the text input buffer manually + IMGUI_API void ClearInputKeys(); // [Internal] Release all keys //------------------------------------------------------------------ // Output - Updated by NewFrame() or EndFrame()/Render() @@ -1990,50 +2063,71 @@ struct ImGuiIO // generally easier and more correct to use their state BEFORE calling NewFrame(). See FAQ for details!) //------------------------------------------------------------------ - bool WantCaptureMouse; // Set when Dear ImGui will use mouse inputs, in this case do not dispatch them to your main game/application (either way, always pass on mouse inputs to imgui). (e.g. unclicked mouse is hovering over an imgui window, widget is active, mouse was clicked over an imgui window, etc.). - bool WantCaptureKeyboard; // Set when Dear ImGui will use keyboard inputs, in this case do not dispatch them to your main game/application (either way, always pass keyboard inputs to imgui). (e.g. InputText active, or an imgui window is focused and navigation is enabled, etc.). - bool WantTextInput; // Mobile/console: when set, you may display an on-screen keyboard. This is set by Dear ImGui when it wants textual keyboard input to happen (e.g. when a InputText widget is active). - bool WantSetMousePos; // MousePos has been altered, backend should reposition mouse on next frame. Rarely used! Set only when ImGuiConfigFlags_NavEnableSetMousePos flag is enabled. - bool WantSaveIniSettings; // When manual .ini load/save is active (io.IniFilename == NULL), this will be set to notify your application that you can call SaveIniSettingsToMemory() and save yourself. Important: clear io.WantSaveIniSettings yourself after saving! - bool NavActive; // Keyboard/Gamepad navigation is currently allowed (will handle ImGuiKey_NavXXX events) = a window is focused and it doesn't use the ImGuiWindowFlags_NoNavInputs flag. - bool NavVisible; // Keyboard/Gamepad navigation is visible and allowed (will handle ImGuiKey_NavXXX events). - float Framerate; // Rough estimate of application framerate, in frame per second. Solely for convenience. Rolling average estimation based on io.DeltaTime over 120 frames. - int MetricsRenderVertices; // Vertices output during last call to Render() - int MetricsRenderIndices; // Indices output during last call to Render() = number of triangles * 3 - int MetricsRenderWindows; // Number of visible windows - int MetricsActiveWindows; // Number of active windows - int MetricsActiveAllocations; // Number of active allocations, updated by MemAlloc/MemFree based on current context. May be off if you have multiple imgui contexts. - ImVec2 MouseDelta; // Mouse delta. Note that this is zero if either current or previous position are invalid (-FLT_MAX,-FLT_MAX), so a disappearing/reappearing mouse won't have a huge delta. + bool WantCaptureMouse; // Set when Dear ImGui will use mouse inputs, in this case do not dispatch them to your main game/application (either way, always pass on mouse inputs to imgui). (e.g. unclicked mouse is hovering over an imgui window, widget is active, mouse was clicked over an imgui window, etc.). + bool WantCaptureKeyboard; // Set when Dear ImGui will use keyboard inputs, in this case do not dispatch them to your main game/application (either way, always pass keyboard inputs to imgui). (e.g. InputText active, or an imgui window is focused and navigation is enabled, etc.). + bool WantTextInput; // Mobile/console: when set, you may display an on-screen keyboard. This is set by Dear ImGui when it wants textual keyboard input to happen (e.g. when a InputText widget is active). + bool WantSetMousePos; // MousePos has been altered, backend should reposition mouse on next frame. Rarely used! Set only when ImGuiConfigFlags_NavEnableSetMousePos flag is enabled. + bool WantSaveIniSettings; // When manual .ini load/save is active (io.IniFilename == NULL), this will be set to notify your application that you can call SaveIniSettingsToMemory() and save yourself. Important: clear io.WantSaveIniSettings yourself after saving! + bool NavActive; // Keyboard/Gamepad navigation is currently allowed (will handle ImGuiKey_NavXXX events) = a window is focused and it doesn't use the ImGuiWindowFlags_NoNavInputs flag. + bool NavVisible; // Keyboard/Gamepad navigation is visible and allowed (will handle ImGuiKey_NavXXX events). + float Framerate; // Estimate of application framerate (rolling average over 60 frames, based on io.DeltaTime), in frame per second. Solely for convenience. Slow applications may not want to use a moving average or may want to reset underlying buffers occasionally. + int MetricsRenderVertices; // Vertices output during last call to Render() + int MetricsRenderIndices; // Indices output during last call to Render() = number of triangles * 3 + int MetricsRenderWindows; // Number of visible windows + int MetricsActiveWindows; // Number of active windows + int MetricsActiveAllocations; // Number of active allocations, updated by MemAlloc/MemFree based on current context. May be off if you have multiple imgui contexts. + ImVec2 MouseDelta; // Mouse delta. Note that this is zero if either current or previous position are invalid (-FLT_MAX,-FLT_MAX), so a disappearing/reappearing mouse won't have a huge delta. + + // Legacy: before 1.87, we required backend to fill io.KeyMap[] (imgui->native map) during initialization and io.KeysDown[] (native indices) every frame. + // This is still temporarily supported as a legacy feature. However the new preferred scheme is for backend to call io.AddKeyEvent(). +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO + int KeyMap[ImGuiKey_COUNT]; // [LEGACY] Input: map of indices into the KeysDown[512] entries array which represent your "native" keyboard state. The first 512 are now unused and should be kept zero. Legacy backend will write into KeyMap[] using ImGuiKey_ indices which are always >512. + bool KeysDown[ImGuiKey_COUNT]; // [LEGACY] Input: Keyboard keys that are pressed (ideally left in the "native" order your engine has access to keyboard keys, so you can use your own defines/enums for keys). This used to be [512] sized. It is now ImGuiKey_COUNT to allow legacy io.KeysDown[GetKeyIndex(...)] to work without an overflow. + float NavInputs[ImGuiNavInput_COUNT]; // [LEGACY] Since 1.88, NavInputs[] was removed. Backends from 1.60 to 1.86 won't build. Feed gamepad inputs via io.AddKeyEvent() and ImGuiKey_GamepadXXX enums. +#endif //------------------------------------------------------------------ // [Internal] Dear ImGui will maintain those fields. Forward compatibility not guaranteed! //------------------------------------------------------------------ - bool WantCaptureMouseUnlessPopupClose;// Alternative to WantCaptureMouse: (WantCaptureMouse == true && WantCaptureMouseUnlessPopupClose == false) when a click over void is expected to close a popup. - ImGuiKeyModFlags KeyMods; // Key mods flags (same as io.KeyCtrl/KeyShift/KeyAlt/KeySuper but merged into flags), updated by NewFrame() - ImGuiKeyModFlags KeyModsPrev; // Previous key mods - ImVec2 MousePosPrev; // Previous mouse position (note that MouseDelta is not necessary == MousePos-MousePosPrev, in case either position is invalid) - ImVec2 MouseClickedPos[5]; // Position at time of clicking - double MouseClickedTime[5]; // Time of last click (used to figure out double-click) - bool MouseClicked[5]; // Mouse button went from !Down to Down (same as MouseClickedCount[x] != 0) - bool MouseDoubleClicked[5]; // Has mouse button been double-clicked? (same as MouseClickedCount[x] == 2) - ImU16 MouseClickedCount[5]; // == 0 (not clicked), == 1 (same as MouseClicked[]), == 2 (double-clicked), == 3 (triple-clicked) etc. when going from !Down to Down - ImU16 MouseClickedLastCount[5]; // Count successive number of clicks. Stays valid after mouse release. Reset after another click is done. - bool MouseReleased[5]; // Mouse button went from Down to !Down - bool MouseDownOwned[5]; // Track if button was clicked inside a dear imgui window or over void blocked by a popup. We don't request mouse capture from the application if click started outside ImGui bounds. - bool MouseDownOwnedUnlessPopupClose[5];//Track if button was clicked inside a dear imgui window. - float MouseDownDuration[5]; // Duration the mouse button has been down (0.0f == just clicked) - float MouseDownDurationPrev[5]; // Previous time the mouse button has been down - ImVec2 MouseDragMaxDistanceAbs[5]; // Maximum distance, absolute, on each axis, of how much mouse has traveled from the clicking point - float MouseDragMaxDistanceSqr[5]; // Squared maximum distance of how much mouse has traveled from the clicking point - float KeysDownDuration[512]; // Duration the keyboard key has been down (0.0f == just pressed) - float KeysDownDurationPrev[512]; // Previous duration the key has been down - float NavInputsDownDuration[ImGuiNavInput_COUNT]; - float NavInputsDownDurationPrev[ImGuiNavInput_COUNT]; - float PenPressure; // Touch/Pen pressure (0.0f to 1.0f, should be >0.0f only when MouseDown[0] == true). Helper storage currently unused by Dear ImGui. - bool AppFocusLost; - ImWchar16 InputQueueSurrogate; // For AddInputCharacterUTF16 - ImVector InputQueueCharacters; // Queue of _characters_ input (obtained by platform backend). Fill using AddInputCharacter() helper. + // Main Input State + // (this block used to be written by backend, since 1.87 it is best to NOT write to those directly, call the AddXXX functions above instead) + // (reading from those variables is fair game, as they are extremely unlikely to be moving anywhere) + ImVec2 MousePos; // Mouse position, in pixels. Set to ImVec2(-FLT_MAX, -FLT_MAX) if mouse is unavailable (on another screen, etc.) + bool MouseDown[5]; // Mouse buttons: 0=left, 1=right, 2=middle + extras (ImGuiMouseButton_COUNT == 5). Dear ImGui mostly uses left and right buttons. Others buttons allows us to track if the mouse is being used by your application + available to user as a convenience via IsMouse** API. + float MouseWheel; // Mouse wheel Vertical: 1 unit scrolls about 5 lines text. + float MouseWheelH; // Mouse wheel Horizontal. Most users don't have a mouse with an horizontal wheel, may not be filled by all backends. + ImGuiID MouseHoveredViewport; // (Optional) Modify using io.AddMouseViewportEvent(). With multi-viewports: viewport the OS mouse is hovering. If possible _IGNORING_ viewports with the ImGuiViewportFlags_NoInputs flag is much better (few backends can handle that). Set io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport if you can provide this info. If you don't imgui will infer the value using the rectangles and last focused time of the viewports it knows about (ignoring other OS windows). + bool KeyCtrl; // Keyboard modifier down: Control + bool KeyShift; // Keyboard modifier down: Shift + bool KeyAlt; // Keyboard modifier down: Alt + bool KeySuper; // Keyboard modifier down: Cmd/Super/Windows + + // Other state maintained from data above + IO function calls + ImGuiModFlags KeyMods; // Key mods flags (same as io.KeyCtrl/KeyShift/KeyAlt/KeySuper but merged into flags), updated by NewFrame() + ImGuiKeyData KeysData[ImGuiKey_KeysData_SIZE]; // Key state for all known keys. Use IsKeyXXX() functions to access this. + bool WantCaptureMouseUnlessPopupClose; // Alternative to WantCaptureMouse: (WantCaptureMouse == true && WantCaptureMouseUnlessPopupClose == false) when a click over void is expected to close a popup. + ImVec2 MousePosPrev; // Previous mouse position (note that MouseDelta is not necessary == MousePos-MousePosPrev, in case either position is invalid) + ImVec2 MouseClickedPos[5]; // Position at time of clicking + double MouseClickedTime[5]; // Time of last click (used to figure out double-click) + bool MouseClicked[5]; // Mouse button went from !Down to Down (same as MouseClickedCount[x] != 0) + bool MouseDoubleClicked[5]; // Has mouse button been double-clicked? (same as MouseClickedCount[x] == 2) + ImU16 MouseClickedCount[5]; // == 0 (not clicked), == 1 (same as MouseClicked[]), == 2 (double-clicked), == 3 (triple-clicked) etc. when going from !Down to Down + ImU16 MouseClickedLastCount[5]; // Count successive number of clicks. Stays valid after mouse release. Reset after another click is done. + bool MouseReleased[5]; // Mouse button went from Down to !Down + bool MouseDownOwned[5]; // Track if button was clicked inside a dear imgui window or over void blocked by a popup. We don't request mouse capture from the application if click started outside ImGui bounds. + bool MouseDownOwnedUnlessPopupClose[5]; // Track if button was clicked inside a dear imgui window. + float MouseDownDuration[5]; // Duration the mouse button has been down (0.0f == just clicked) + float MouseDownDurationPrev[5]; // Previous time the mouse button has been down + ImVec2 MouseDragMaxDistanceAbs[5]; // Maximum distance, absolute, on each axis, of how much mouse has traveled from the clicking point + float MouseDragMaxDistanceSqr[5]; // Squared maximum distance of how much mouse has traveled from the clicking point (used for moving thresholds) + float PenPressure; // Touch/Pen pressure (0.0f to 1.0f, should be >0.0f only when MouseDown[0] == true). Helper storage currently unused by Dear ImGui. + bool AppFocusLost; // Only modify via AddFocusEvent() + bool AppAcceptingEvents; // Only modify via SetAppAcceptingEvents() + ImS8 BackendUsingLegacyKeyArrays; // -1: unknown, 0: using AddKeyEvent(), 1: using legacy io.KeysDown[] + bool BackendUsingLegacyNavInputArray; // 0: using AddKeyAnalogEvent(), 1: writing to legacy io.NavInputs[] directly + ImWchar16 InputQueueSurrogate; // For AddInputCharacterUTF16() + ImVector InputQueueCharacters; // Queue of _characters_ input (obtained by platform backend). Fill using AddInputCharacter() helper. IMGUI_API ImGuiIO(); }; @@ -2322,6 +2416,8 @@ struct ImGuiListClipper }; // Helpers macros to generate 32-bit encoded colors +// User can declare their own format by #defining the 5 _SHIFT/_MASK macros in their imconfig file. +#ifndef IM_COL32_R_SHIFT #ifdef IMGUI_USE_BGRA_PACKED_COLOR #define IM_COL32_R_SHIFT 16 #define IM_COL32_G_SHIFT 8 @@ -2335,6 +2431,7 @@ struct ImGuiListClipper #define IM_COL32_A_SHIFT 24 #define IM_COL32_A_MASK 0xFF000000 #endif +#endif #define IM_COL32(R,G,B,A) (((ImU32)(A)<> IM_COL32_R_SHIFT) & 0xFF) * sc; Value.y = (float)((rgba >> IM_COL32_G_SHIFT) & 0xFF) * sc; Value.z = (float)((rgba >> IM_COL32_B_SHIFT) & 0xFF) * sc; Value.w = (float)((rgba >> IM_COL32_A_SHIFT) & 0xFF) * sc; } - ImColor(float r, float g, float b, float a = 1.0f) { Value.x = r; Value.y = g; Value.z = b; Value.w = a; } - ImColor(const ImVec4& col) { Value = col; } inline operator ImU32() const { return ImGui::ColorConvertFloat4ToU32(Value); } inline operator ImVec4() const { return Value; } @@ -2389,16 +2486,16 @@ typedef void (*ImDrawCallback)(const ImDrawList* parent_list, const ImDrawCmd* c #define ImDrawCallback_ResetRenderState (ImDrawCallback)(-1) // Typically, 1 command = 1 GPU draw call (unless command is a callback) -// - VtxOffset/IdxOffset: When 'io.BackendFlags & ImGuiBackendFlags_RendererHasVtxOffset' is enabled, -// those fields allow us to render meshes larger than 64K vertices while keeping 16-bit indices. -// Pre-1.71 backends will typically ignore the VtxOffset/IdxOffset fields. +// - VtxOffset: When 'io.BackendFlags & ImGuiBackendFlags_RendererHasVtxOffset' is enabled, +// this fields allow us to render meshes larger than 64K vertices while keeping 16-bit indices. +// Backends made for <1.71. will typically ignore the VtxOffset fields. // - The ClipRect/TextureId/VtxOffset fields must be contiguous as we memcmp() them together (this is asserted for). struct ImDrawCmd { ImVec4 ClipRect; // 4*4 // Clipping rectangle (x1, y1, x2, y2). Subtract ImDrawData->DisplayPos to get clipping rectangle in "viewport" coordinates ImTextureID TextureId; // 4-8 // User-provided texture ID. Set by user in ImfontAtlas::SetTexID() for fonts or passed to Image*() functions. Ignore if never using images or multiple fonts atlas. unsigned int VtxOffset; // 4 // Start offset in vertex buffer. ImGuiBackendFlags_RendererHasVtxOffset: always 0, otherwise may be >0 to support meshes larger than 64K vertices with 16-bit indices. - unsigned int IdxOffset; // 4 // Start offset in index buffer. Always equal to sum of ElemCount drawn so far. + unsigned int IdxOffset; // 4 // Start offset in index buffer. unsigned int ElemCount; // 4 // Number of indices (multiple of 3) to be rendered as triangles. Vertices are stored in the callee ImDrawList's vtx_buffer[] array, indices in idx_buffer[]. ImDrawCallback UserCallback; // 4-8 // If != NULL, call the function instead of rendering the vertices. clip_rect and texture_id will be set normally. void* UserCallbackData; // 4-8 // The draw callback code can access this. @@ -2475,7 +2572,7 @@ enum ImDrawFlags_ ImDrawFlags_RoundCornersRight = ImDrawFlags_RoundCornersBottomRight | ImDrawFlags_RoundCornersTopRight, ImDrawFlags_RoundCornersAll = ImDrawFlags_RoundCornersTopLeft | ImDrawFlags_RoundCornersTopRight | ImDrawFlags_RoundCornersBottomLeft | ImDrawFlags_RoundCornersBottomRight, ImDrawFlags_RoundCornersDefault_ = ImDrawFlags_RoundCornersAll, // Default to ALL corners if none of the _RoundCornersXX flags are specified. - ImDrawFlags_RoundCornersMask_ = ImDrawFlags_RoundCornersAll | ImDrawFlags_RoundCornersNone + ImDrawFlags_RoundCornersMask_ = ImDrawFlags_RoundCornersAll | ImDrawFlags_RoundCornersNone, }; // Flags for ImDrawList instance. Those are set automatically by ImGui:: functions from ImGuiIO settings, and generally not manipulated directly. @@ -2484,9 +2581,9 @@ enum ImDrawListFlags_ { ImDrawListFlags_None = 0, ImDrawListFlags_AntiAliasedLines = 1 << 0, // Enable anti-aliased lines/borders (*2 the number of triangles for 1.0f wide line or lines thin enough to be drawn using textures, otherwise *3 the number of triangles) - ImDrawListFlags_AntiAliasedLinesUseTex = 1 << 1, // Enable anti-aliased lines/borders using textures when possible. Require backend to render with bilinear filtering. + ImDrawListFlags_AntiAliasedLinesUseTex = 1 << 1, // Enable anti-aliased lines/borders using textures when possible. Require backend to render with bilinear filtering (NOT point/nearest filtering). ImDrawListFlags_AntiAliasedFill = 1 << 2, // Enable anti-aliased edge around filled shapes (rounded rectangles, circles). - ImDrawListFlags_AllowVtxOffset = 1 << 3 // Can emit 'VtxOffset > 0' to allow large meshes. Set when 'ImGuiBackendFlags_RendererHasVtxOffset' is enabled. + ImDrawListFlags_AllowVtxOffset = 1 << 3, // Can emit 'VtxOffset > 0' to allow large meshes. Set when 'ImGuiBackendFlags_RendererHasVtxOffset' is enabled. }; // Draw command list @@ -2523,7 +2620,7 @@ struct ImDrawList ImDrawList(const ImDrawListSharedData* shared_data) { memset(this, 0, sizeof(*this)); _Data = shared_data; } ~ImDrawList() { _ClearFreeMemory(); } - IMGUI_API void PushClipRect(ImVec2 clip_rect_min, ImVec2 clip_rect_max, bool intersect_with_current_clip_rect = false); // Render-level scissoring. This is passed down to your render function but not used for CPU-side coarse clipping. Prefer using higher-level ImGui::PushClipRect() to affect logic (hit-testing and widget culling) + IMGUI_API void PushClipRect(const ImVec2& clip_rect_min, const ImVec2& clip_rect_max, bool intersect_with_current_clip_rect = false); // Render-level scissoring. This is passed down to your render function but not used for CPU-side coarse clipping. Prefer using higher-level ImGui::PushClipRect() to affect logic (hit-testing and widget culling) IMGUI_API void PushClipRectFullScreen(); IMGUI_API void PopClipRect(); IMGUI_API void PushTextureID(ImTextureID texture_id); @@ -2532,6 +2629,7 @@ struct ImDrawList inline ImVec2 GetClipRectMax() const { const ImVec4& cr = _ClipRectStack.back(); return ImVec2(cr.z, cr.w); } // Primitives + // - Filled shapes must always use clockwise winding order. The anti-aliasing fringe depends on it. Counter-clockwise shapes will have "inward" anti-aliasing. // - For rectangular primitives, "p_min" and "p_max" represent the upper-left and lower-right corners. // - For circle primitives, use "num_segments == 0" to automatically calculate tessellation (preferred). // In older versions (until Dear ImGui 1.77) the AddCircle functions defaulted to num_segments == 12. @@ -2552,7 +2650,7 @@ struct ImDrawList IMGUI_API void AddText(const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL); IMGUI_API void AddText(const ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end = NULL, float wrap_width = 0.0f, const ImVec4* cpu_fine_clip_rect = NULL); IMGUI_API void AddPolyline(const ImVec2* points, int num_points, ImU32 col, ImDrawFlags flags, float thickness); - IMGUI_API void AddConvexPolyFilled(const ImVec2* points, int num_points, ImU32 col); // Note: Anti-aliased filling requires points to be in clockwise order. + IMGUI_API void AddConvexPolyFilled(const ImVec2* points, int num_points, ImU32 col); IMGUI_API void AddBezierCubic(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, ImU32 col, float thickness, int num_segments = 0); // Cubic Bezier (4 control points) IMGUI_API void AddBezierQuadratic(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, ImU32 col, float thickness, int num_segments = 0); // Quadratic Bezier (3 control points) @@ -2565,10 +2663,11 @@ struct ImDrawList IMGUI_API void AddImageRounded(ImTextureID user_texture_id, const ImVec2& p_min, const ImVec2& p_max, const ImVec2& uv_min, const ImVec2& uv_max, ImU32 col, float rounding, ImDrawFlags flags = 0); // Stateful path API, add points then finish with PathFillConvex() or PathStroke() + // - Filled shapes must always use clockwise winding order. The anti-aliasing fringe depends on it. Counter-clockwise shapes will have "inward" anti-aliasing. inline void PathClear() { _Path.Size = 0; } inline void PathLineTo(const ImVec2& pos) { _Path.push_back(pos); } inline void PathLineToMergeDuplicate(const ImVec2& pos) { if (_Path.Size == 0 || memcmp(&_Path.Data[_Path.Size - 1], &pos, 8) != 0) _Path.push_back(pos); } - inline void PathFillConvex(ImU32 col) { AddConvexPolyFilled(_Path.Data, _Path.Size, col); _Path.Size = 0; } // Note: Anti-aliased filling requires points to be in clockwise order. + inline void PathFillConvex(ImU32 col) { AddConvexPolyFilled(_Path.Data, _Path.Size, col); _Path.Size = 0; } inline void PathStroke(ImU32 col, ImDrawFlags flags = 0, float thickness = 1.0f) { AddPolyline(_Path.Data, _Path.Size, col, flags, thickness); _Path.Size = 0; } IMGUI_API void PathArcTo(const ImVec2& center, float radius, float a_min, float a_max, int num_segments = 0); IMGUI_API void PathArcToFast(const ImVec2& center, float radius, int a_min_of_12, int a_max_of_12); // Use precomputed angles for a 12 steps circle @@ -2604,8 +2703,8 @@ struct ImDrawList inline void PrimVtx(const ImVec2& pos, const ImVec2& uv, ImU32 col) { PrimWriteIdx((ImDrawIdx)_VtxCurrentIdx); PrimWriteVtx(pos, uv, col); } // Write vertex with unique index #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - inline void AddBezierCurve(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, ImU32 col, float thickness, int num_segments = 0) { AddBezierCubic(p1, p2, p3, p4, col, thickness, num_segments); } - inline void PathBezierCurveTo(const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, int num_segments = 0) { PathBezierCubicCurveTo(p2, p3, p4, num_segments); } + inline void AddBezierCurve(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, ImU32 col, float thickness, int num_segments = 0) { AddBezierCubic(p1, p2, p3, p4, col, thickness, num_segments); } // OBSOLETED in 1.80 (Jan 2021) + inline void PathBezierCurveTo(const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, int num_segments = 0) { PathBezierCubicCurveTo(p2, p3, p4, num_segments); } // OBSOLETED in 1.80 (Jan 2021) #endif // [Internal helpers] @@ -2721,7 +2820,7 @@ enum ImFontAtlasFlags_ ImFontAtlasFlags_None = 0, ImFontAtlasFlags_NoPowerOfTwoHeight = 1 << 0, // Don't round the height to next power of two ImFontAtlasFlags_NoMouseCursors = 1 << 1, // Don't build software mouse cursors into the atlas (save a little texture memory) - ImFontAtlasFlags_NoBakedLines = 1 << 2 // Don't build thick line textures into the atlas (save a little texture memory). The AntiAliasedLinesUseTex features uses them, otherwise they will be rendered using polygons (more expensive for CPU/GPU). + ImFontAtlasFlags_NoBakedLines = 1 << 2, // Don't build thick line textures into the atlas (save a little texture memory, allow support for point/nearest filtering). The AntiAliasedLinesUseTex features uses them, otherwise they will be rendered using polygons (more expensive for CPU/GPU). }; // Load and rasterize multiple TTF/OTF fonts into a same texture. The font atlas will build a single texture holding: @@ -2809,7 +2908,7 @@ struct ImFontAtlas ImFontAtlasFlags Flags; // Build flags (see ImFontAtlasFlags_) ImTextureID TexID; // User data to refer to the texture once it has been uploaded to user's graphic systems. It is passed back to you during rendering via the ImDrawCmd structure. int TexDesiredWidth; // Texture width desired by user before Build(). Must be a power-of-two. If have many glyphs your graphics API have texture size restrictions you may want to increase texture width to decrease height. - int TexGlyphPadding; // Padding between glyphs within texture in pixels. Defaults to 1. If your rendering method doesn't rely on bilinear filtering you may set this to 0. + int TexGlyphPadding; // Padding between glyphs within texture in pixels. Defaults to 1. If your rendering method doesn't rely on bilinear filtering you may set this to 0 (will also need to set AntiAliasedLinesUseTex = false). bool Locked; // Marked as Locked by ImGui::NewFrame() so attempt to modify the atlas will assert. // [Internal] @@ -2835,10 +2934,9 @@ struct ImFontAtlas int PackIdMouseCursors; // Custom texture rectangle ID for white pixel and mouse cursors int PackIdLines; // Custom texture rectangle ID for baked anti-aliased lines -#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - typedef ImFontAtlasCustomRect CustomRect; // OBSOLETED in 1.72+ + // [Obsolete] + //typedef ImFontAtlasCustomRect CustomRect; // OBSOLETED in 1.72+ //typedef ImFontGlyphRangesBuilder GlyphRangesBuilder; // OBSOLETED in 1.67+ -#endif }; // Font runtime data and rendering @@ -2881,8 +2979,8 @@ struct ImFont // 'wrap_width' enable automatic word-wrapping across multiple lines to fit into given width. 0.0f to disable. IMGUI_API ImVec2 CalcTextSizeA(float size, float max_width, float wrap_width, const char* text_begin, const char* text_end = NULL, const char** remaining = NULL) const; // utf8 IMGUI_API const char* CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width) const; - IMGUI_API void RenderChar(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col, ImWchar c) const; - IMGUI_API void RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, float wrap_width = 0.0f, bool cpu_fine_clip = false) const; + IMGUI_API void RenderChar(ImDrawList* draw_list, float size, const ImVec2& pos, ImU32 col, ImWchar c) const; + IMGUI_API void RenderText(ImDrawList* draw_list, float size, const ImVec2& pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, float wrap_width = 0.0f, bool cpu_fine_clip = false) const; // [Internal] Don't use! IMGUI_API void BuildLookupTable(); @@ -2914,7 +3012,7 @@ enum ImGuiViewportFlags_ ImGuiViewportFlags_TopMost = 1 << 9, // Platform Window: Display on top (for tooltips only). ImGuiViewportFlags_Minimized = 1 << 10, // Platform Window: Window is minimized, can skip render. When minimized we tend to avoid using the viewport pos/size for clipping window or testing if they are contained in the viewport. ImGuiViewportFlags_NoAutoMerge = 1 << 11, // Platform Window: Avoid merging this window into another host window. This can only be set via ImGuiWindowClass viewport flags override (because we need to now ahead if we are going to create a viewport in the first place!). - ImGuiViewportFlags_CanHostOtherWindows = 1 << 12 // Main viewport: can host multiple imgui windows (secondary viewports are associated to a single window). + ImGuiViewportFlags_CanHostOtherWindows = 1 << 12, // Main viewport: can host multiple imgui windows (secondary viewports are associated to a single window). }; // - Currently represents the Platform Window created by the application which is hosting our Dear ImGui windows. @@ -2936,6 +3034,7 @@ struct ImGuiViewport ImGuiID ParentViewportId; // (Advanced) 0: no parent. Instruct the platform backend to setup a parent/child relationship between platform windows. ImDrawData* DrawData; // The ImDrawData corresponding to this viewport. Valid after Render() and until the next call to NewFrame(). + // Platform/Backend Dependent Data // Our design separate the Renderer and Platform backends to facilitate combining default backends with each others. // When our create your own backend for a custom engine, it is possible that both Renderer and Platform will be handled // by the same system and you may not need to use all the UserData/Handle fields. @@ -2943,7 +3042,7 @@ struct ImGuiViewport void* RendererUserData; // void* to hold custom data structure for the renderer (e.g. swap chain, framebuffers etc.). generally set by your Renderer_CreateWindow function. void* PlatformUserData; // void* to hold custom data structure for the OS / platform (e.g. windowing info, render context). generally set by your Platform_CreateWindow function. void* PlatformHandle; // void* for FindViewportByPlatformHandle(). (e.g. suggested to use natural platform handle such as HWND, GLFWWindow*, SDL_Window*) - void* PlatformHandleRaw; // void* to hold lower-level, platform-native window handle (e.g. the HWND) when using an abstraction layer like GLFW or SDL (where PlatformHandle would be a SDL_Window*) + void* PlatformHandleRaw; // void* to hold lower-level, platform-native window handle (under Win32 this is expected to be a HWND, unused for other platforms), when using an abstraction layer like GLFW or SDL (where PlatformHandle would be a SDL_Window*) bool PlatformRequestMove; // Platform window requested move (e.g. window was moved by the OS / host window manager, authoritative position will be OS window position) bool PlatformRequestResize; // Platform window requested resize (e.g. window was resized by the OS / host window manager, authoritative size will be OS window size) bool PlatformRequestClose; // Platform window requested closure (e.g. window was moved by the OS / host window manager, e.g. pressing ALT-F4) @@ -2957,7 +3056,7 @@ struct ImGuiViewport }; //----------------------------------------------------------------------------- -// [SECTION] Platform interface for multi-viewport support +// [SECTION] Platform Dependent Interfaces (for e.g. multi-viewport support) //----------------------------------------------------------------------------- // [BETA] (Optional) This is completely optional, for advanced users! // If you are new to Dear ImGui and trying to integrate it into your engine, you can probably ignore this for now. @@ -3043,7 +3142,6 @@ struct ImGuiPlatformIO void (*Platform_SwapBuffers)(ImGuiViewport* vp, void* render_arg); // . . . R . // (Optional) Call Present/SwapBuffers (platform side! This is often unused!). 'render_arg' is the value passed to RenderPlatformWindowsDefault(). float (*Platform_GetWindowDpiScale)(ImGuiViewport* vp); // N . . . . // (Optional) [BETA] FIXME-DPI: DPI handling: Return DPI scale for this viewport. 1.0f = 96 DPI. void (*Platform_OnChangedViewport)(ImGuiViewport* vp); // . F . . . // (Optional) [BETA] FIXME-DPI: DPI handling: Called during Begin() every time the viewport we are outputting into changes, so backend has a chance to swap fonts to adjust style. - void (*Platform_SetImeInputPos)(ImGuiViewport* vp, ImVec2 pos); // . F . . . // (Optional) Set IME (Input Method Editor, e.g. for Asian languages) input position, so text preview appears over the imgui input box. FIXME: The call timing of this is inconsistent because we want to support without multi-viewports. int (*Platform_CreateVkSurface)(ImGuiViewport* vp, ImU64 vk_inst, const void* vk_allocators, ImU64* out_vk_surface); // (Optional) For a Vulkan Renderer to call into Platform code (since the surface creation needs to tie them both). // (Optional) Renderer functions (e.g. DirectX, OpenGL, Vulkan) @@ -3078,25 +3176,47 @@ struct ImGuiPlatformMonitor ImGuiPlatformMonitor() { MainPos = MainSize = WorkPos = WorkSize = ImVec2(0, 0); DpiScale = 1.0f; } }; +// (Optional) Support for IME (Input Method Editor) via the io.SetPlatformImeDataFn() function. +struct ImGuiPlatformImeData +{ + bool WantVisible; // A widget wants the IME to be visible + ImVec2 InputPos; // Position of the input cursor + float InputLineHeight; // Line height + + ImGuiPlatformImeData() { memset(this, 0, sizeof(*this)); } +}; + //----------------------------------------------------------------------------- // [SECTION] Obsolete functions and types // (Will be removed! Read 'API BREAKING CHANGES' section in imgui.cpp for details) // Please keep your copy of dear imgui up to date! Occasionally set '#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS' in imconfig.h to stay ahead. //----------------------------------------------------------------------------- +namespace ImGui +{ +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO + IMGUI_API int GetKeyIndex(ImGuiKey key); // map ImGuiKey_* values into legacy native key index. == io.KeyMap[key] +#else + static inline int GetKeyIndex(ImGuiKey key) { IM_ASSERT(key >= ImGuiKey_NamedKey_BEGIN && key < ImGuiKey_NamedKey_END && "ImGuiKey and native_index was merged together and native_index is disabled by IMGUI_DISABLE_OBSOLETE_KEYIO. Please switch to ImGuiKey."); return key; } +#endif +} + #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS namespace ImGui { + // OBSOLETED in 1.88 (from May 2022) + static inline void CaptureKeyboardFromApp(bool want_capture_keyboard = true) { SetNextFrameWantCaptureKeyboard(want_capture_keyboard); } // Renamed as name was misleading + removed default value. + static inline void CaptureMouseFromApp(bool want_capture_mouse = true) { SetNextFrameWantCaptureMouse(want_capture_mouse); } // Renamed as name was misleading + removed default value. // OBSOLETED in 1.86 (from November 2021) IMGUI_API void CalcListClipping(int items_count, float items_height, int* out_items_display_start, int* out_items_display_end); // Calculate coarse clipping for large list of evenly sized items. Prefer using ImGuiListClipper. // OBSOLETED in 1.85 (from August 2021) - static inline float GetWindowContentRegionWidth() { return GetWindowContentRegionMax().x - GetWindowContentRegionMin().x; } + static inline float GetWindowContentRegionWidth() { return GetWindowContentRegionMax().x - GetWindowContentRegionMin().x; } // OBSOLETED in 1.81 (from February 2021) IMGUI_API bool ListBoxHeader(const char* label, int items_count, int height_in_items = -1); // Helper to calculate size from items_count and height_in_items - static inline bool ListBoxHeader(const char* label, const ImVec2& size = ImVec2(0, 0)) { return BeginListBox(label, size); } + static inline bool ListBoxHeader(const char* label, const ImVec2& size = ImVec2(0, 0)) { return BeginListBox(label, size); } static inline void ListBoxFooter() { EndListBox(); } // OBSOLETED in 1.79 (from August 2020) - static inline void OpenPopupContextItem(const char* str_id = NULL, ImGuiMouseButton mb = 1) { OpenPopupOnItemClick(str_id, mb); } // Bool return value removed. Use IsWindowAppearing() in BeginPopup() instead. Renamed in 1.77, renamed back in 1.79. Sorry! + static inline void OpenPopupContextItem(const char* str_id = NULL, ImGuiMouseButton mb = 1) { OpenPopupOnItemClick(str_id, mb); } // Bool return value removed. Use IsWindowAppearing() in BeginPopup() instead. Renamed in 1.77, renamed back in 1.79. Sorry! // OBSOLETED in 1.78 (from June 2020) // Old drag/sliders functions that took a 'float power = 1.0' argument instead of flags. // For shared code, you can version check at compile-time with `#if IMGUI_VERSION_NUM >= 17704`. @@ -3114,24 +3234,21 @@ namespace ImGui static inline bool SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* format, float power) { return SliderScalarN(label, ImGuiDataType_Float, v, 4, &v_min, &v_max, format, power); } // OBSOLETED in 1.77 (from June 2020) static inline bool BeginPopupContextWindow(const char* str_id, ImGuiMouseButton mb, bool over_items) { return BeginPopupContextWindow(str_id, mb | (over_items ? 0 : ImGuiPopupFlags_NoOpenOverItems)); } - // OBSOLETED in 1.72 (from April 2019) - static inline void TreeAdvanceToLabelPos() { SetCursorPosX(GetCursorPosX() + GetTreeNodeToLabelSpacing()); } - // OBSOLETED in 1.71 (from June 2019) - static inline void SetNextTreeNodeOpen(bool open, ImGuiCond cond = 0) { SetNextItemOpen(open, cond); } - // OBSOLETED in 1.70 (from May 2019) - static inline float GetContentRegionAvailWidth() { return GetContentRegionAvail().x; } // Some of the older obsolete names along with their replacement (commented out so they are not reported in IDE) - //static inline ImDrawList* GetOverlayDrawList() { return GetForegroundDrawList(); } // OBSOLETED in 1.69 (from Mar 2019) - //static inline void SetScrollHere(float ratio = 0.5f) { SetScrollHereY(ratio); } // OBSOLETED in 1.66 (from Nov 2018) - //static inline bool IsItemDeactivatedAfterChange() { return IsItemDeactivatedAfterEdit(); } // OBSOLETED in 1.63 (from Aug 2018) - //static inline bool IsAnyWindowFocused() { return IsWindowFocused(ImGuiFocusedFlags_AnyWindow); } // OBSOLETED in 1.60 (from Apr 2018) - //static inline bool IsAnyWindowHovered() { return IsWindowHovered(ImGuiHoveredFlags_AnyWindow); } // OBSOLETED in 1.60 (between Dec 2017 and Apr 2018) - //static inline void ShowTestWindow() { return ShowDemoWindow(); } // OBSOLETED in 1.53 (between Oct 2017 and Dec 2017) - //static inline bool IsRootWindowFocused() { return IsWindowFocused(ImGuiFocusedFlags_RootWindow); } // OBSOLETED in 1.53 (between Oct 2017 and Dec 2017) - //static inline bool IsRootWindowOrAnyChildFocused() { return IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows); } // OBSOLETED in 1.53 (between Oct 2017 and Dec 2017) - //static inline void SetNextWindowContentWidth(float w) { SetNextWindowContentSize(ImVec2(w, 0.0f)); } // OBSOLETED in 1.53 (between Oct 2017 and Dec 2017) - //static inline float GetItemsLineHeightWithSpacing() { return GetFrameHeightWithSpacing(); } // OBSOLETED in 1.53 (between Oct 2017 and Dec 2017) + //static inline void TreeAdvanceToLabelPos() { SetCursorPosX(GetCursorPosX() + GetTreeNodeToLabelSpacing()); } // OBSOLETED in 1.72 (from July 2019) + //static inline void SetNextTreeNodeOpen(bool open, ImGuiCond cond = 0) { SetNextItemOpen(open, cond); } // OBSOLETED in 1.71 (from June 2019) + //static inline float GetContentRegionAvailWidth() { return GetContentRegionAvail().x; } // OBSOLETED in 1.70 (from May 2019) + //static inline ImDrawList* GetOverlayDrawList() { return GetForegroundDrawList(); } // OBSOLETED in 1.69 (from Mar 2019) + //static inline void SetScrollHere(float ratio = 0.5f) { SetScrollHereY(ratio); } // OBSOLETED in 1.66 (from Nov 2018) + //static inline bool IsItemDeactivatedAfterChange() { return IsItemDeactivatedAfterEdit(); } // OBSOLETED in 1.63 (from Aug 2018) + //static inline bool IsAnyWindowFocused() { return IsWindowFocused(ImGuiFocusedFlags_AnyWindow); } // OBSOLETED in 1.60 (from Apr 2018) + //static inline bool IsAnyWindowHovered() { return IsWindowHovered(ImGuiHoveredFlags_AnyWindow); } // OBSOLETED in 1.60 (between Dec 2017 and Apr 2018) + //static inline void ShowTestWindow() { return ShowDemoWindow(); } // OBSOLETED in 1.53 (between Oct 2017 and Dec 2017) + //static inline bool IsRootWindowFocused() { return IsWindowFocused(ImGuiFocusedFlags_RootWindow); } // OBSOLETED in 1.53 (between Oct 2017 and Dec 2017) + //static inline bool IsRootWindowOrAnyChildFocused() { return IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows); } // OBSOLETED in 1.53 (between Oct 2017 and Dec 2017) + //static inline void SetNextWindowContentWidth(float w) { SetNextWindowContentSize(ImVec2(w, 0.0f)); } // OBSOLETED in 1.53 (between Oct 2017 and Dec 2017) + //static inline float GetItemsLineHeightWithSpacing() { return GetFrameHeightWithSpacing(); } // OBSOLETED in 1.53 (between Oct 2017 and Dec 2017) } // OBSOLETED in 1.82 (from Mars 2021): flags for AddRect(), AddRectFilled(), AddImageRounded(), PathRect() @@ -3147,11 +3264,23 @@ enum ImDrawCornerFlags_ ImDrawCornerFlags_Top = ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_TopRight, ImDrawCornerFlags_Bot = ImDrawCornerFlags_BotLeft | ImDrawCornerFlags_BotRight, ImDrawCornerFlags_Left = ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_BotLeft, - ImDrawCornerFlags_Right = ImDrawCornerFlags_TopRight | ImDrawCornerFlags_BotRight + ImDrawCornerFlags_Right = ImDrawCornerFlags_TopRight | ImDrawCornerFlags_BotRight, }; +// RENAMED ImGuiKeyModFlags -> ImGuiModFlags in 1.88 (from April 2022) +typedef int ImGuiKeyModFlags; +enum ImGuiKeyModFlags_ { ImGuiKeyModFlags_None = ImGuiModFlags_None, ImGuiKeyModFlags_Ctrl = ImGuiModFlags_Ctrl, ImGuiKeyModFlags_Shift = ImGuiModFlags_Shift, ImGuiKeyModFlags_Alt = ImGuiModFlags_Alt, ImGuiKeyModFlags_Super = ImGuiModFlags_Super }; + #endif // #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS +// RENAMED IMGUI_DISABLE_METRICS_WINDOW > IMGUI_DISABLE_DEBUG_TOOLS in 1.88 (from June 2022) +#if defined(IMGUI_DISABLE_METRICS_WINDOW) && !defined(IMGUI_DISABLE_OBSOLETE_FUNCTIONS) && !defined(IMGUI_DISABLE_DEBUG_TOOLS) +#define IMGUI_DISABLE_DEBUG_TOOLS +#endif +#if defined(IMGUI_DISABLE_METRICS_WINDOW) && defined(IMGUI_DISABLE_OBSOLETE_FUNCTIONS) +#error IMGUI_DISABLE_METRICS_WINDOW was renamed to IMGUI_DISABLE_DEBUG_TOOLS, please use new name. +#endif + //----------------------------------------------------------------------------- #if defined(__clang__) diff --git a/lib/external/imgui/include/imgui_impl_glfw.h b/lib/external/imgui/include/imgui_impl_glfw.h index bb0ddf36c..b96f3ee2c 100644 --- a/lib/external/imgui/include/imgui_impl_glfw.h +++ b/lib/external/imgui/include/imgui_impl_glfw.h @@ -1,12 +1,13 @@ // dear imgui: Platform Backend for GLFW // This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan, WebGPU..) // (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) +// (Requires: GLFW 3.1+. Prefer GLFW 3.3+ for full feature support.) // Implemented features: // [X] Platform: Clipboard support. +// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy GLFW_KEY_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] // [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. -// [x] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. FIXME: 3 cursors types are missing from GLFW. -// [X] Platform: Keyboard arrays indexed using GLFW_KEY_* codes, e.g. ImGui::IsKeyPressed(GLFW_KEY_SPACE). +// [x] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange' (note: the resizing cursors requires GLFW 3.4+). // [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. // Issues: @@ -33,11 +34,16 @@ IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool ins IMGUI_IMPL_API void ImGui_ImplGlfw_Shutdown(); IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame(); -// GLFW callbacks -// - When calling Init with 'install_callbacks=true': GLFW callbacks will be installed for you. They will call user's previously installed callbacks, if any. -// - When calling Init with 'install_callbacks=false': GLFW callbacks won't be installed. You will need to call those function yourself from your own GLFW callbacks. -IMGUI_IMPL_API void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused); -IMGUI_IMPL_API void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered); +// GLFW callbacks (installer) +// - When calling Init with 'install_callbacks=true': ImGui_ImplGlfw_InstallCallbacks() is called. GLFW callbacks will be installed for you. They will chain-call user's previously installed callbacks, if any. +// - When calling Init with 'install_callbacks=false': GLFW callbacks won't be installed. You will need to call individual function yourself from your own GLFW callbacks. +IMGUI_IMPL_API void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window); +IMGUI_IMPL_API void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window); + +// GLFW callbacks (individual callbacks to call if you didn't install callbacks) +IMGUI_IMPL_API void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused); // Since 1.84 +IMGUI_IMPL_API void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered); // Since 1.84 +IMGUI_IMPL_API void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y); // Since 1.87 IMGUI_IMPL_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods); IMGUI_IMPL_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset); IMGUI_IMPL_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); diff --git a/lib/external/imgui/include/imgui_impl_opengl3.h b/lib/external/imgui/include/imgui_impl_opengl3.h index d8de7d672..81722bdf0 100644 --- a/lib/external/imgui/include/imgui_impl_opengl3.h +++ b/lib/external/imgui/include/imgui_impl_opengl3.h @@ -5,8 +5,8 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID! -// [X] Renderer: Multi-viewport support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. -// [x] Renderer: Desktop GL only: Support for large meshes (64k+ vertices) with 16-bit indices. +// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. +// [x] Renderer: Large meshes support (64k+ vertices) with 16-bit indices (Desktop OpenGL only). // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. @@ -43,11 +43,11 @@ IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects(); // Try to detect GLES on matching platforms #if defined(__APPLE__) -#include "TargetConditionals.h" +#include #endif #if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__)) #define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es" -#elif defined(__EMSCRIPTEN__) +#elif defined(__EMSCRIPTEN__) || defined(__amigaos4__) #define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100" #else // Otherwise imgui_impl_opengl3_loader.h will be used. diff --git a/lib/external/imgui/include/imgui_impl_opengl3_loader.h b/lib/external/imgui/include/imgui_impl_opengl3_loader.h index cc06fb0a5..f98574a8c 100644 --- a/lib/external/imgui/include/imgui_impl_opengl3_loader.h +++ b/lib/external/imgui/include/imgui_impl_opengl3_loader.h @@ -1,3 +1,22 @@ +//----------------------------------------------------------------------------- +// About imgui_impl_opengl3_loader.h: +// +// We embed our own OpenGL loader to not require user to provide their own or to have to use ours, +// which proved to be endless problems for users. +// Our loader is custom-generated, based on gl3w but automatically filtered to only include +// enums/functions that we use in our imgui_impl_opengl3.cpp source file in order to be small. +// +// YOU SHOULD NOT NEED TO INCLUDE/USE THIS DIRECTLY. THIS IS USED BY imgui_impl_opengl3.cpp ONLY. +// THE REST OF YOUR APP SHOULD USE A DIFFERENT GL LOADER: ANY GL LOADER OF YOUR CHOICE. +// +// Regenerate with: +// python gl3w_gen.py --output ../imgui/backends/imgui_impl_opengl3_loader.h --ref ../imgui/backends/imgui_impl_opengl3.cpp ./extra_symbols.txt +// +// More info: +// https://github.com/dearimgui/gl3w_stripped +// https://github.com/ocornut/imgui/issues/4445 +//----------------------------------------------------------------------------- + /* * This file was generated with gl3w_gen.py, part of imgl3w * (hosted at https://github.com/dearimgui/gl3w_stripped) @@ -26,14 +45,11 @@ * OTHER DEALINGS IN THE SOFTWARE. */ -// We embed our own OpenGL loader to not require user to provide their own or to have to use ours, which proved to be endless problems for users. -// Our loader is custom-generated, based on gl3w but automatically filtered to only include enums/functions that we use in this source file. -// Regenerate with: python gl3w_gen.py --imgui-dir /path/to/imgui/ -// see https://github.com/dearimgui/gl3w_stripped for more info. #ifndef __gl3w_h_ #define __gl3w_h_ // Adapted from KHR/khrplatform.h to avoid including entire file. +#ifndef __khrplatform_h_ typedef float khronos_float_t; typedef signed char khronos_int8_t; typedef unsigned char khronos_uint8_t; @@ -58,6 +74,7 @@ typedef uint64_t khronos_uint64_t; typedef signed long long khronos_int64_t; typedef unsigned long long khronos_uint64_t; #endif +#endif // __khrplatform_h_ #ifndef __gl_glcorearb_h_ #define __gl_glcorearb_h_ 1 @@ -147,9 +164,11 @@ typedef khronos_uint8_t GLubyte; #define GL_FLOAT 0x1406 #define GL_RGBA 0x1908 #define GL_FILL 0x1B02 +#define GL_VENDOR 0x1F00 +#define GL_RENDERER 0x1F01 #define GL_VERSION 0x1F02 #define GL_EXTENSIONS 0x1F03 -#define GL_NEAREST 0x2600 +#define GL_NEAREST 0x2600 // IMHEX PATCH #define GL_LINEAR 0x2601 #define GL_TEXTURE_MAG_FILTER 0x2800 #define GL_TEXTURE_MIN_FILTER 0x2801 @@ -161,8 +180,10 @@ typedef void (APIENTRYP PFNGLCLEARPROC) (GLbitfield mask); typedef void (APIENTRYP PFNGLCLEARCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); typedef void (APIENTRYP PFNGLDISABLEPROC) (GLenum cap); typedef void (APIENTRYP PFNGLENABLEPROC) (GLenum cap); +typedef void (APIENTRYP PFNGLFLUSHPROC) (void); typedef void (APIENTRYP PFNGLPIXELSTOREIPROC) (GLenum pname, GLint param); typedef void (APIENTRYP PFNGLREADPIXELSPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels); +typedef GLenum (APIENTRYP PFNGLGETERRORPROC) (void); typedef void (APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *data); typedef const GLubyte *(APIENTRYP PFNGLGETSTRINGPROC) (GLenum name); typedef GLboolean (APIENTRYP PFNGLISENABLEDPROC) (GLenum cap); @@ -176,8 +197,10 @@ GLAPI void APIENTRY glClear (GLbitfield mask); GLAPI void APIENTRY glClearColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); GLAPI void APIENTRY glDisable (GLenum cap); GLAPI void APIENTRY glEnable (GLenum cap); +GLAPI void APIENTRY glFlush (void); GLAPI void APIENTRY glPixelStorei (GLenum pname, GLint param); GLAPI void APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels); +GLAPI GLenum APIENTRY glGetError (void); GLAPI void APIENTRY glGetIntegerv (GLenum pname, GLint *data); GLAPI const GLubyte *APIENTRY glGetString (GLenum name); GLAPI GLboolean APIENTRY glIsEnabled (GLenum cap); @@ -226,16 +249,19 @@ typedef khronos_intptr_t GLintptr; #define GL_ARRAY_BUFFER 0x8892 #define GL_ELEMENT_ARRAY_BUFFER 0x8893 #define GL_ARRAY_BUFFER_BINDING 0x8894 +#define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895 #define GL_STREAM_DRAW 0x88E0 typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer); typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers); typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers); typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const void *data, GLenum usage); +typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const void *data); #ifdef GL_GLEXT_PROTOTYPES GLAPI void APIENTRY glBindBuffer (GLenum target, GLuint buffer); GLAPI void APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers); GLAPI void APIENTRY glGenBuffers (GLsizei n, GLuint *buffers); GLAPI void APIENTRY glBufferData (GLenum target, GLsizeiptr size, const void *data, GLenum usage); +GLAPI void APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const void *data); #endif #endif /* GL_VERSION_1_5 */ #ifndef GL_VERSION_2_0 @@ -244,7 +270,13 @@ typedef khronos_int16_t GLshort; typedef khronos_int8_t GLbyte; typedef khronos_uint16_t GLushort; #define GL_BLEND_EQUATION_RGB 0x8009 +#define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622 +#define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623 +#define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624 +#define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625 +#define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645 #define GL_BLEND_EQUATION_ALPHA 0x883D +#define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A #define GL_FRAGMENT_SHADER 0x8B30 #define GL_VERTEX_SHADER 0x8B31 #define GL_COMPILE_STATUS 0x8B81 @@ -260,6 +292,7 @@ typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC) (GLenum type); typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program); typedef void (APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader); typedef void (APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader); +typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint index); typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index); typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name); typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params); @@ -267,6 +300,8 @@ typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei buf typedef void (APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params); typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, GLenum pname, GLint *params); +typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, GLenum pname, void **pointer); typedef void (APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program); typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length); typedef void (APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program); @@ -282,6 +317,7 @@ GLAPI GLuint APIENTRY glCreateShader (GLenum type); GLAPI void APIENTRY glDeleteProgram (GLuint program); GLAPI void APIENTRY glDeleteShader (GLuint shader); GLAPI void APIENTRY glDetachShader (GLuint program, GLuint shader); +GLAPI void APIENTRY glDisableVertexAttribArray (GLuint index); GLAPI void APIENTRY glEnableVertexAttribArray (GLuint index); GLAPI GLint APIENTRY glGetAttribLocation (GLuint program, const GLchar *name); GLAPI void APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint *params); @@ -289,6 +325,8 @@ GLAPI void APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufSize, GLsize GLAPI void APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint *params); GLAPI void APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog); GLAPI GLint APIENTRY glGetUniformLocation (GLuint program, const GLchar *name); +GLAPI void APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint *params); +GLAPI void APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, void **pointer); GLAPI void APIENTRY glLinkProgram (GLuint program); GLAPI void APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length); GLAPI void APIENTRY glUseProgram (GLuint program); @@ -417,118 +455,130 @@ GL3W_API GL3WglProc imgl3wGetProcAddress(const char *proc); /* gl3w internal state */ union GL3WProcs { - GL3WglProc ptr[52]; + GL3WglProc ptr[58]; struct { - PFNGLACTIVETEXTUREPROC ActiveTexture; - PFNGLATTACHSHADERPROC AttachShader; - PFNGLBINDBUFFERPROC BindBuffer; - PFNGLBINDSAMPLERPROC BindSampler; - PFNGLBINDTEXTUREPROC BindTexture; - PFNGLBINDVERTEXARRAYPROC BindVertexArray; - PFNGLBLENDEQUATIONPROC BlendEquation; - PFNGLBLENDEQUATIONSEPARATEPROC BlendEquationSeparate; - PFNGLBLENDFUNCSEPARATEPROC BlendFuncSeparate; - PFNGLBUFFERDATAPROC BufferData; - PFNGLCLEARPROC Clear; - PFNGLCLEARCOLORPROC ClearColor; - PFNGLCOMPILESHADERPROC CompileShader; - PFNGLCREATEPROGRAMPROC CreateProgram; - PFNGLCREATESHADERPROC CreateShader; - PFNGLDELETEBUFFERSPROC DeleteBuffers; - PFNGLDELETEPROGRAMPROC DeleteProgram; - PFNGLDELETESHADERPROC DeleteShader; - PFNGLDELETETEXTURESPROC DeleteTextures; - PFNGLDELETEVERTEXARRAYSPROC DeleteVertexArrays; - PFNGLDETACHSHADERPROC DetachShader; - PFNGLDISABLEPROC Disable; - PFNGLDRAWELEMENTSPROC DrawElements; - PFNGLDRAWELEMENTSBASEVERTEXPROC DrawElementsBaseVertex; - PFNGLENABLEPROC Enable; - PFNGLENABLEVERTEXATTRIBARRAYPROC EnableVertexAttribArray; - PFNGLGENBUFFERSPROC GenBuffers; - PFNGLGENTEXTURESPROC GenTextures; - PFNGLGENVERTEXARRAYSPROC GenVertexArrays; - PFNGLGETATTRIBLOCATIONPROC GetAttribLocation; - PFNGLGETINTEGERVPROC GetIntegerv; - PFNGLGETPROGRAMINFOLOGPROC GetProgramInfoLog; - PFNGLGETPROGRAMIVPROC GetProgramiv; - PFNGLGETSHADERINFOLOGPROC GetShaderInfoLog; - PFNGLGETSHADERIVPROC GetShaderiv; - PFNGLGETSTRINGPROC GetString; - PFNGLGETSTRINGIPROC GetStringi; - PFNGLGETUNIFORMLOCATIONPROC GetUniformLocation; - PFNGLISENABLEDPROC IsEnabled; - PFNGLLINKPROGRAMPROC LinkProgram; - PFNGLPIXELSTOREIPROC PixelStorei; - PFNGLPOLYGONMODEPROC PolygonMode; - PFNGLREADPIXELSPROC ReadPixels; - PFNGLSCISSORPROC Scissor; - PFNGLSHADERSOURCEPROC ShaderSource; - PFNGLTEXIMAGE2DPROC TexImage2D; - PFNGLTEXPARAMETERIPROC TexParameteri; - PFNGLUNIFORM1IPROC Uniform1i; - PFNGLUNIFORMMATRIX4FVPROC UniformMatrix4fv; - PFNGLUSEPROGRAMPROC UseProgram; - PFNGLVERTEXATTRIBPOINTERPROC VertexAttribPointer; - PFNGLVIEWPORTPROC Viewport; + PFNGLACTIVETEXTUREPROC ActiveTexture; + PFNGLATTACHSHADERPROC AttachShader; + PFNGLBINDBUFFERPROC BindBuffer; + PFNGLBINDSAMPLERPROC BindSampler; + PFNGLBINDTEXTUREPROC BindTexture; + PFNGLBINDVERTEXARRAYPROC BindVertexArray; + PFNGLBLENDEQUATIONPROC BlendEquation; + PFNGLBLENDEQUATIONSEPARATEPROC BlendEquationSeparate; + PFNGLBLENDFUNCSEPARATEPROC BlendFuncSeparate; + PFNGLBUFFERDATAPROC BufferData; + PFNGLBUFFERSUBDATAPROC BufferSubData; + PFNGLCLEARPROC Clear; + PFNGLCLEARCOLORPROC ClearColor; + PFNGLCOMPILESHADERPROC CompileShader; + PFNGLCREATEPROGRAMPROC CreateProgram; + PFNGLCREATESHADERPROC CreateShader; + PFNGLDELETEBUFFERSPROC DeleteBuffers; + PFNGLDELETEPROGRAMPROC DeleteProgram; + PFNGLDELETESHADERPROC DeleteShader; + PFNGLDELETETEXTURESPROC DeleteTextures; + PFNGLDELETEVERTEXARRAYSPROC DeleteVertexArrays; + PFNGLDETACHSHADERPROC DetachShader; + PFNGLDISABLEPROC Disable; + PFNGLDISABLEVERTEXATTRIBARRAYPROC DisableVertexAttribArray; + PFNGLDRAWELEMENTSPROC DrawElements; + PFNGLDRAWELEMENTSBASEVERTEXPROC DrawElementsBaseVertex; + PFNGLENABLEPROC Enable; + PFNGLENABLEVERTEXATTRIBARRAYPROC EnableVertexAttribArray; + PFNGLFLUSHPROC Flush; + PFNGLGENBUFFERSPROC GenBuffers; + PFNGLGENTEXTURESPROC GenTextures; + PFNGLGENVERTEXARRAYSPROC GenVertexArrays; + PFNGLGETATTRIBLOCATIONPROC GetAttribLocation; + PFNGLGETERRORPROC GetError; + PFNGLGETINTEGERVPROC GetIntegerv; + PFNGLGETPROGRAMINFOLOGPROC GetProgramInfoLog; + PFNGLGETPROGRAMIVPROC GetProgramiv; + PFNGLGETSHADERINFOLOGPROC GetShaderInfoLog; + PFNGLGETSHADERIVPROC GetShaderiv; + PFNGLGETSTRINGPROC GetString; + PFNGLGETSTRINGIPROC GetStringi; + PFNGLGETUNIFORMLOCATIONPROC GetUniformLocation; + PFNGLGETVERTEXATTRIBPOINTERVPROC GetVertexAttribPointerv; + PFNGLGETVERTEXATTRIBIVPROC GetVertexAttribiv; + PFNGLISENABLEDPROC IsEnabled; + PFNGLLINKPROGRAMPROC LinkProgram; + PFNGLPIXELSTOREIPROC PixelStorei; + PFNGLPOLYGONMODEPROC PolygonMode; + PFNGLREADPIXELSPROC ReadPixels; + PFNGLSCISSORPROC Scissor; + PFNGLSHADERSOURCEPROC ShaderSource; + PFNGLTEXIMAGE2DPROC TexImage2D; + PFNGLTEXPARAMETERIPROC TexParameteri; + PFNGLUNIFORM1IPROC Uniform1i; + PFNGLUNIFORMMATRIX4FVPROC UniformMatrix4fv; + PFNGLUSEPROGRAMPROC UseProgram; + PFNGLVERTEXATTRIBPOINTERPROC VertexAttribPointer; + PFNGLVIEWPORTPROC Viewport; } gl; }; -GL3W_API extern union GL3WProcs gl3wProcs; +GL3W_API extern union GL3WProcs imgl3wProcs; /* OpenGL functions */ -#define glActiveTexture gl3wProcs.gl.ActiveTexture -#define glAttachShader gl3wProcs.gl.AttachShader -#define glBindBuffer gl3wProcs.gl.BindBuffer -#define glBindSampler gl3wProcs.gl.BindSampler -#define glBindTexture gl3wProcs.gl.BindTexture -#define glBindVertexArray gl3wProcs.gl.BindVertexArray -#define glBlendEquation gl3wProcs.gl.BlendEquation -#define glBlendEquationSeparate gl3wProcs.gl.BlendEquationSeparate -#define glBlendFuncSeparate gl3wProcs.gl.BlendFuncSeparate -#define glBufferData gl3wProcs.gl.BufferData -#define glClear gl3wProcs.gl.Clear -#define glClearColor gl3wProcs.gl.ClearColor -#define glCompileShader gl3wProcs.gl.CompileShader -#define glCreateProgram gl3wProcs.gl.CreateProgram -#define glCreateShader gl3wProcs.gl.CreateShader -#define glDeleteBuffers gl3wProcs.gl.DeleteBuffers -#define glDeleteProgram gl3wProcs.gl.DeleteProgram -#define glDeleteShader gl3wProcs.gl.DeleteShader -#define glDeleteTextures gl3wProcs.gl.DeleteTextures -#define glDeleteVertexArrays gl3wProcs.gl.DeleteVertexArrays -#define glDetachShader gl3wProcs.gl.DetachShader -#define glDisable gl3wProcs.gl.Disable -#define glDrawElements gl3wProcs.gl.DrawElements -#define glDrawElementsBaseVertex gl3wProcs.gl.DrawElementsBaseVertex -#define glEnable gl3wProcs.gl.Enable -#define glEnableVertexAttribArray gl3wProcs.gl.EnableVertexAttribArray -#define glGenBuffers gl3wProcs.gl.GenBuffers -#define glGenTextures gl3wProcs.gl.GenTextures -#define glGenVertexArrays gl3wProcs.gl.GenVertexArrays -#define glGetAttribLocation gl3wProcs.gl.GetAttribLocation -#define glGetIntegerv gl3wProcs.gl.GetIntegerv -#define glGetProgramInfoLog gl3wProcs.gl.GetProgramInfoLog -#define glGetProgramiv gl3wProcs.gl.GetProgramiv -#define glGetShaderInfoLog gl3wProcs.gl.GetShaderInfoLog -#define glGetShaderiv gl3wProcs.gl.GetShaderiv -#define glGetString gl3wProcs.gl.GetString -#define glGetStringi gl3wProcs.gl.GetStringi -#define glGetUniformLocation gl3wProcs.gl.GetUniformLocation -#define glIsEnabled gl3wProcs.gl.IsEnabled -#define glLinkProgram gl3wProcs.gl.LinkProgram -#define glPixelStorei gl3wProcs.gl.PixelStorei -#define glPolygonMode gl3wProcs.gl.PolygonMode -#define glReadPixels gl3wProcs.gl.ReadPixels -#define glScissor gl3wProcs.gl.Scissor -#define glShaderSource gl3wProcs.gl.ShaderSource -#define glTexImage2D gl3wProcs.gl.TexImage2D -#define glTexParameteri gl3wProcs.gl.TexParameteri -#define glUniform1i gl3wProcs.gl.Uniform1i -#define glUniformMatrix4fv gl3wProcs.gl.UniformMatrix4fv -#define glUseProgram gl3wProcs.gl.UseProgram -#define glVertexAttribPointer gl3wProcs.gl.VertexAttribPointer -#define glViewport gl3wProcs.gl.Viewport +#define glActiveTexture imgl3wProcs.gl.ActiveTexture +#define glAttachShader imgl3wProcs.gl.AttachShader +#define glBindBuffer imgl3wProcs.gl.BindBuffer +#define glBindSampler imgl3wProcs.gl.BindSampler +#define glBindTexture imgl3wProcs.gl.BindTexture +#define glBindVertexArray imgl3wProcs.gl.BindVertexArray +#define glBlendEquation imgl3wProcs.gl.BlendEquation +#define glBlendEquationSeparate imgl3wProcs.gl.BlendEquationSeparate +#define glBlendFuncSeparate imgl3wProcs.gl.BlendFuncSeparate +#define glBufferData imgl3wProcs.gl.BufferData +#define glBufferSubData imgl3wProcs.gl.BufferSubData +#define glClear imgl3wProcs.gl.Clear +#define glClearColor imgl3wProcs.gl.ClearColor +#define glCompileShader imgl3wProcs.gl.CompileShader +#define glCreateProgram imgl3wProcs.gl.CreateProgram +#define glCreateShader imgl3wProcs.gl.CreateShader +#define glDeleteBuffers imgl3wProcs.gl.DeleteBuffers +#define glDeleteProgram imgl3wProcs.gl.DeleteProgram +#define glDeleteShader imgl3wProcs.gl.DeleteShader +#define glDeleteTextures imgl3wProcs.gl.DeleteTextures +#define glDeleteVertexArrays imgl3wProcs.gl.DeleteVertexArrays +#define glDetachShader imgl3wProcs.gl.DetachShader +#define glDisable imgl3wProcs.gl.Disable +#define glDisableVertexAttribArray imgl3wProcs.gl.DisableVertexAttribArray +#define glDrawElements imgl3wProcs.gl.DrawElements +#define glDrawElementsBaseVertex imgl3wProcs.gl.DrawElementsBaseVertex +#define glEnable imgl3wProcs.gl.Enable +#define glEnableVertexAttribArray imgl3wProcs.gl.EnableVertexAttribArray +#define glFlush imgl3wProcs.gl.Flush +#define glGenBuffers imgl3wProcs.gl.GenBuffers +#define glGenTextures imgl3wProcs.gl.GenTextures +#define glGenVertexArrays imgl3wProcs.gl.GenVertexArrays +#define glGetAttribLocation imgl3wProcs.gl.GetAttribLocation +#define glGetError imgl3wProcs.gl.GetError +#define glGetIntegerv imgl3wProcs.gl.GetIntegerv +#define glGetProgramInfoLog imgl3wProcs.gl.GetProgramInfoLog +#define glGetProgramiv imgl3wProcs.gl.GetProgramiv +#define glGetShaderInfoLog imgl3wProcs.gl.GetShaderInfoLog +#define glGetShaderiv imgl3wProcs.gl.GetShaderiv +#define glGetString imgl3wProcs.gl.GetString +#define glGetStringi imgl3wProcs.gl.GetStringi +#define glGetUniformLocation imgl3wProcs.gl.GetUniformLocation +#define glGetVertexAttribPointerv imgl3wProcs.gl.GetVertexAttribPointerv +#define glGetVertexAttribiv imgl3wProcs.gl.GetVertexAttribiv +#define glIsEnabled imgl3wProcs.gl.IsEnabled +#define glLinkProgram imgl3wProcs.gl.LinkProgram +#define glPixelStorei imgl3wProcs.gl.PixelStorei +#define glPolygonMode imgl3wProcs.gl.PolygonMode +#define glReadPixels imgl3wProcs.gl.ReadPixels +#define glScissor imgl3wProcs.gl.Scissor +#define glShaderSource imgl3wProcs.gl.ShaderSource +#define glTexImage2D imgl3wProcs.gl.TexImage2D +#define glTexParameteri imgl3wProcs.gl.TexParameteri +#define glUniform1i imgl3wProcs.gl.Uniform1i +#define glUniformMatrix4fv imgl3wProcs.gl.UniformMatrix4fv +#define glUseProgram imgl3wProcs.gl.UseProgram +#define glVertexAttribPointer imgl3wProcs.gl.VertexAttribPointer +#define glViewport imgl3wProcs.gl.Viewport #ifdef __cplusplus } @@ -672,6 +722,7 @@ static const char *proc_names[] = { "glBlendEquationSeparate", "glBlendFuncSeparate", "glBufferData", + "glBufferSubData", "glClear", "glClearColor", "glCompileShader", @@ -684,14 +735,17 @@ static const char *proc_names[] = { "glDeleteVertexArrays", "glDetachShader", "glDisable", + "glDisableVertexAttribArray", "glDrawElements", "glDrawElementsBaseVertex", "glEnable", "glEnableVertexAttribArray", + "glFlush", "glGenBuffers", "glGenTextures", "glGenVertexArrays", "glGetAttribLocation", + "glGetError", "glGetIntegerv", "glGetProgramInfoLog", "glGetProgramiv", @@ -700,6 +754,8 @@ static const char *proc_names[] = { "glGetString", "glGetStringi", "glGetUniformLocation", + "glGetVertexAttribPointerv", + "glGetVertexAttribiv", "glIsEnabled", "glLinkProgram", "glPixelStorei", @@ -716,13 +772,13 @@ static const char *proc_names[] = { "glViewport", }; -GL3W_API union GL3WProcs gl3wProcs; +GL3W_API union GL3WProcs imgl3wProcs; static void load_procs(GL3WGetProcAddressProc proc) { size_t i; for (i = 0; i < ARRAY_SIZE(proc_names); i++) - gl3wProcs.ptr[i] = proc(proc_names[i]); + imgl3wProcs.ptr[i] = proc(proc_names[i]); } #ifdef __cplusplus diff --git a/lib/external/imgui/include/imgui_internal.h b/lib/external/imgui/include/imgui_internal.h index 398c69dc2..e44ca29ef 100644 --- a/lib/external/imgui/include/imgui_internal.h +++ b/lib/external/imgui/include/imgui_internal.h @@ -1,4 +1,4 @@ -// dear imgui, v1.86 +// dear imgui, v1.89 WIP // (internal structures/api) // You may use this file to debug, understand or extend ImGui features but we don't provide any guarantee of forward compatibility! @@ -18,6 +18,7 @@ Index of this file: // [SECTION] Generic helpers // [SECTION] ImDrawList support // [SECTION] Widgets support: flags, enums, data structures +// [SECTION] Inputs support // [SECTION] Clipper support // [SECTION] Navigation support // [SECTION] Columns support @@ -139,6 +140,7 @@ struct ImGuiTabBar; // Storage for a tab bar struct ImGuiTabItem; // Storage for a tab item (within a tab bar) struct ImGuiTable; // Storage for a table struct ImGuiTableColumn; // Storage for one column of a table +struct ImGuiTableInstanceData; // Storage for one instance of a same table struct ImGuiTableTempData; // Temporary storage for one table (one per table in the stack), shared between tables. struct ImGuiTableSettings; // Storage for a table .ini settings struct ImGuiTableColumnsSettings; // Storage for a column .ini settings @@ -150,11 +152,12 @@ struct ImGuiWindowSettings; // Storage for a window .ini settings (we ke typedef int ImGuiDataAuthority; // -> enum ImGuiDataAuthority_ // Enum: for storing the source authority (dock node vs window) of a field typedef int ImGuiLayoutType; // -> enum ImGuiLayoutType_ // Enum: Horizontal or vertical typedef int ImGuiActivateFlags; // -> enum ImGuiActivateFlags_ // Flags: for navigation/focus function (will be for ActivateItem() later) +typedef int ImGuiDebugLogFlags; // -> enum ImGuiDebugLogFlags_ // Flags: for ShowDebugLogWindow(), g.DebugLogFlags +typedef int ImGuiInputFlags; // -> enum ImGuiInputFlags_ // Flags: for IsKeyPressedEx() typedef int ImGuiItemFlags; // -> enum ImGuiItemFlags_ // Flags: for PushItemFlag() typedef int ImGuiItemStatusFlags; // -> enum ImGuiItemStatusFlags_ // Flags: for DC.LastItemStatusFlags typedef int ImGuiOldColumnFlags; // -> enum ImGuiOldColumnFlags_ // Flags: for BeginColumns() typedef int ImGuiNavHighlightFlags; // -> enum ImGuiNavHighlightFlags_ // Flags: for RenderNavHighlight() -typedef int ImGuiNavDirSourceFlags; // -> enum ImGuiNavDirSourceFlags_ // Flags: for GetNavInputAmount2d() typedef int ImGuiNavMoveFlags; // -> enum ImGuiNavMoveFlags_ // Flags: for navigation requests typedef int ImGuiNextItemDataFlags; // -> enum ImGuiNextItemDataFlags_ // Flags: for SetNextItemXXX() functions typedef int ImGuiNextWindowDataFlags; // -> enum ImGuiNextWindowDataFlags_// Flags: for SetNextWindowXXX() functions @@ -199,27 +202,28 @@ namespace ImStb // Internal Drag and Drop payload types. String starting with '_' are reserved for Dear ImGui. #define IMGUI_PAYLOAD_TYPE_WINDOW "_IMWINDOW" // Payload == ImGuiWindow* -// Debug Logging -#ifndef IMGUI_DEBUG_LOG -#define IMGUI_DEBUG_LOG(_FMT,...) printf("[%05d] " _FMT, GImGui->FrameCount, __VA_ARGS__) +// Debug Printing Into TTY +// (since IMGUI_VERSION_NUM >= 18729: IMGUI_DEBUG_LOG was reworked into IMGUI_DEBUG_PRINTF (and removed framecount from it). If you were using a #define IMGUI_DEBUG_LOG please rename) +#ifndef IMGUI_DEBUG_PRINTF +#ifndef IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS +#define IMGUI_DEBUG_PRINTF(_FMT,...) printf(_FMT, __VA_ARGS__) +#else +#define IMGUI_DEBUG_PRINTF(_FMT,...) +#endif #endif -// Debug Logging for selected systems. Remove the '((void)0) //' to enable. -//#define IMGUI_DEBUG_LOG_POPUP IMGUI_DEBUG_LOG // Enable log -//#define IMGUI_DEBUG_LOG_NAV IMGUI_DEBUG_LOG // Enable log -//#define IMGUI_DEBUG_LOG_VIEWPORT IMGUI_DEBUG_LOG // Enable log -//#define IMGUI_DEBUG_LOG_DOCKING IMGUI_DEBUG_LOG // Enable log -#define IMGUI_DEBUG_LOG_POPUP(...) ((void)0) // Disable log -#define IMGUI_DEBUG_LOG_NAV(...) ((void)0) // Disable log -#define IMGUI_DEBUG_LOG_VIEWPORT(...) ((void)0) // Disable log -#define IMGUI_DEBUG_LOG_DOCKING(...) ((void)0) // Disable log +// Debug Logging for ShowDebugLogWindow(). This is designed for relatively rare events so please don't spam. +#define IMGUI_DEBUG_LOG(...) ImGui::DebugLog(__VA_ARGS__); +#define IMGUI_DEBUG_LOG_ACTIVEID(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventActiveId) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0) +#define IMGUI_DEBUG_LOG_FOCUS(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventFocus) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0) +#define IMGUI_DEBUG_LOG_POPUP(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventPopup) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0) +#define IMGUI_DEBUG_LOG_NAV(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventNav) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0) +#define IMGUI_DEBUG_LOG_IO(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventIO) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0) +#define IMGUI_DEBUG_LOG_DOCKING(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventDocking) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0) +#define IMGUI_DEBUG_LOG_VIEWPORT(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventViewport) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0) // Static Asserts -#if (__cplusplus >= 201100) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201100) #define IM_STATIC_ASSERT(_COND) static_assert(_COND, "") -#else -#define IM_STATIC_ASSERT(_COND) typedef char static_assertion_##__line__[(_COND)?1:-1] -#endif // "Paranoid" Debug Asserts are meant to only be enabled during specific debugging/work, otherwise would slow down the code too much. // We currently don't have many of those so the effect is currently negligible, but onward intent to add more aggressive ones in the code. @@ -244,7 +248,7 @@ namespace ImStb #define IM_NEWLINE "\n" #endif #define IM_TABSIZE (4) -#define IM_MEMALIGN(_OFF,_ALIGN) (((_OFF) + (_ALIGN - 1)) & ~(_ALIGN - 1)) // Memory align e.g. IM_ALIGN(0,4)=0, IM_ALIGN(1,4)=4, IM_ALIGN(4,4)=4, IM_ALIGN(5,4)=8 +#define IM_MEMALIGN(_OFF,_ALIGN) (((_OFF) + ((_ALIGN) - 1)) & ~((_ALIGN) - 1)) // Memory align e.g. IM_ALIGN(0,4)=0, IM_ALIGN(1,4)=4, IM_ALIGN(4,4)=4, IM_ALIGN(5,4)=8 #define IM_F32_TO_INT8_UNBOUND(_VAL) ((int)((_VAL) * 255.0f + ((_VAL)>=0 ? 0.5f : -0.5f))) // Unsaturated, for display purpose #define IM_F32_TO_INT8_SAT(_VAL) ((int)(ImSaturate(_VAL) * 255.0f + 0.5f)) // Saturated, always output 0..255 #define IM_FLOOR(_VAL) ((float)(int)(_VAL)) // ImFloor() is not inlined in MSVC debug builds @@ -291,7 +295,8 @@ namespace ImStb // - Helpers: Hashing // - Helpers: Sorting // - Helpers: Bit manipulation -// - Helpers: String, Formatting +// - Helpers: String +// - Helpers: Formatting // - Helpers: UTF-8 <> wchar conversions // - Helpers: ImVec2/ImVec4 operators // - Helpers: Maths @@ -309,9 +314,6 @@ namespace ImStb // Helpers: Hashing IMGUI_API ImGuiID ImHashData(const void* data, size_t data_size, ImU32 seed = 0); IMGUI_API ImGuiID ImHashStr(const char* data, size_t data_size = 0, ImU32 seed = 0); -#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS -static inline ImGuiID ImHash(const void* data, int size, ImU32 seed = 0) { return size ? ImHashData(data, (size_t)size, seed) : ImHashStr((const char*)data, 0, seed); } // [moved to ImHashStr/ImHashData in 1.68] -#endif // Helpers: Sorting #ifndef ImQsort @@ -326,7 +328,7 @@ static inline bool ImIsPowerOfTwo(int v) { return v != 0 && (v & static inline bool ImIsPowerOfTwo(ImU64 v) { return v != 0 && (v & (v - 1)) == 0; } static inline int ImUpperPowerOfTwo(int v) { v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; return v; } -// Helpers: String, Formatting +// Helpers: String IMGUI_API int ImStricmp(const char* str1, const char* str2); IMGUI_API int ImStrnicmp(const char* str1, const char* str2, size_t count); IMGUI_API void ImStrncpy(char* dst, const char* src, size_t count); @@ -339,14 +341,20 @@ IMGUI_API const ImWchar*ImStrbolW(const ImWchar* buf_mid_line, const ImWchar* bu IMGUI_API const char* ImStristr(const char* haystack, const char* haystack_end, const char* needle, const char* needle_end); IMGUI_API void ImStrTrimBlanks(char* str); IMGUI_API const char* ImStrSkipBlank(const char* str); +static inline bool ImCharIsBlankA(char c) { return c == ' ' || c == '\t'; } +static inline bool ImCharIsBlankW(unsigned int c) { return c == ' ' || c == '\t' || c == 0x3000; } + +// Helpers: Formatting IMGUI_API int ImFormatString(char* buf, size_t buf_size, const char* fmt, ...) IM_FMTARGS(3); IMGUI_API int ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args) IM_FMTLIST(3); +IMGUI_API void ImFormatStringToTempBuffer(const char** out_buf, const char** out_buf_end, const char* fmt, ...) IM_FMTARGS(3); +IMGUI_API void ImFormatStringToTempBufferV(const char** out_buf, const char** out_buf_end, const char* fmt, va_list args) IM_FMTLIST(3); IMGUI_API const char* ImParseFormatFindStart(const char* format); IMGUI_API const char* ImParseFormatFindEnd(const char* format); IMGUI_API const char* ImParseFormatTrimDecorations(const char* format, char* buf, size_t buf_size); +IMGUI_API void ImParseFormatSanitizeForPrinting(const char* fmt_in, char* fmt_out, size_t fmt_out_size); +IMGUI_API const char* ImParseFormatSanitizeForScanning(const char* fmt_in, char* fmt_out, size_t fmt_out_size); IMGUI_API int ImParseFormatPrecision(const char* format, int default_value); -static inline bool ImCharIsBlankA(char c) { return c == ' ' || c == '\t'; } -static inline bool ImCharIsBlankW(unsigned int c) { return c == ' ' || c == '\t' || c == 0x3000; } // Helpers: UTF-8 <> wchar conversions IMGUI_API const char* ImTextCharToUtf8(char out_buf[5], unsigned int c); // return out_buf @@ -453,8 +461,9 @@ static inline float ImLengthSqr(const ImVec2& lhs) static inline float ImLengthSqr(const ImVec4& lhs) { return (lhs.x * lhs.x) + (lhs.y * lhs.y) + (lhs.z * lhs.z) + (lhs.w * lhs.w); } static inline float ImInvLength(const ImVec2& lhs, float fail_value) { float d = (lhs.x * lhs.x) + (lhs.y * lhs.y); if (d > 0.0f) return ImRsqrt(d); return fail_value; } static inline float ImFloor(float f) { return (float)(int)(f); } -static inline float ImFloorSigned(float f) { return (float)((f >= 0 || (int)f == f) ? (int)f : (int)f - 1); } // Decent replacement for floorf() +static inline float ImFloorSigned(float f) { return (float)((f >= 0 || (float)(int)f == f) ? (int)f : (int)f - 1); } // Decent replacement for floorf() static inline ImVec2 ImFloor(const ImVec2& v) { return ImVec2((float)(int)(v.x), (float)(int)(v.y)); } +static inline ImVec2 ImFloorSigned(const ImVec2& v) { return ImVec2(ImFloorSigned(v.x), ImFloorSigned(v.y)); } static inline int ImModPositive(int a, int b) { return (a + b) % b; } static inline float ImDot(const ImVec2& a, const ImVec2& b) { return a.x * b.x + a.y * b.y; } static inline ImVec2 ImRotate(const ImVec2& v, float cos_a, float sin_a) { return ImVec2(v.x * cos_a - v.y * sin_a, v.x * sin_a + v.y * cos_a); } @@ -481,17 +490,17 @@ IM_MSVC_RUNTIME_CHECKS_OFF struct ImVec1 { float x; - ImVec1() { x = 0.0f; } - ImVec1(float _x) { x = _x; } + constexpr ImVec1() : x(0.0f) { } + constexpr ImVec1(float _x) : x(_x) { } }; // Helper: ImVec2ih (2D vector, half-size integer, for long-term packed storage) struct ImVec2ih { short x, y; - ImVec2ih() { x = y = 0; } - ImVec2ih(short _x, short _y) { x = _x; y = _y; } - explicit ImVec2ih(const ImVec2& rhs) { x = (short)rhs.x; y = (short)rhs.y; } + constexpr ImVec2ih() : x(0), y(0) {} + constexpr ImVec2ih(short _x, short _y) : x(_x), y(_y) {} + constexpr explicit ImVec2ih(const ImVec2& rhs) : x((short)rhs.x), y((short)rhs.y) {} }; // Helper: ImRect (2D axis aligned bounding-box) @@ -501,10 +510,10 @@ struct IMGUI_API ImRect ImVec2 Min; // Upper-left ImVec2 Max; // Lower-right - ImRect() : Min(0.0f, 0.0f), Max(0.0f, 0.0f) {} - ImRect(const ImVec2& min, const ImVec2& max) : Min(min), Max(max) {} - ImRect(const ImVec4& v) : Min(v.x, v.y), Max(v.z, v.w) {} - ImRect(float x1, float y1, float x2, float y2) : Min(x1, y1), Max(x2, y2) {} + constexpr ImRect() : Min(0.0f, 0.0f), Max(0.0f, 0.0f) {} + constexpr ImRect(const ImVec2& min, const ImVec2& max) : Min(min), Max(max) {} + constexpr ImRect(const ImVec4& v) : Min(v.x, v.y), Max(v.z, v.w) {} + constexpr ImRect(float x1, float y1, float x2, float y2) : Min(x1, y1), Max(x2, y2) {} ImVec2 GetCenter() const { return ImVec2((Min.x + Max.x) * 0.5f, (Min.y + Max.y) * 0.5f); } ImVec2 GetSize() const { return ImVec2(Max.x - Min.x, Max.y - Min.y); } @@ -552,17 +561,18 @@ inline void ImBitArraySetBitRange(ImU32* arr, int n, int n2) // Works on ran // Helper: ImBitArray class (wrapper over ImBitArray functions) // Store 1-bit per value. -template -struct IMGUI_API ImBitArray +template +struct ImBitArray { ImU32 Storage[(BITCOUNT + 31) >> 5]; ImBitArray() { ClearAllBits(); } void ClearAllBits() { memset(Storage, 0, sizeof(Storage)); } void SetAllBits() { memset(Storage, 255, sizeof(Storage)); } - bool TestBit(int n) const { IM_ASSERT(n < BITCOUNT); return ImBitArrayTestBit(Storage, n); } - void SetBit(int n) { IM_ASSERT(n < BITCOUNT); ImBitArraySetBit(Storage, n); } - void ClearBit(int n) { IM_ASSERT(n < BITCOUNT); ImBitArrayClearBit(Storage, n); } - void SetBitRange(int n, int n2) { ImBitArraySetBitRange(Storage, n, n2); } // Works on range [n..n2) + bool TestBit(int n) const { n += OFFSET; IM_ASSERT(n >= 0 && n < BITCOUNT); return ImBitArrayTestBit(Storage, n); } + void SetBit(int n) { n += OFFSET; IM_ASSERT(n >= 0 && n < BITCOUNT); ImBitArraySetBit(Storage, n); } + void ClearBit(int n) { n += OFFSET; IM_ASSERT(n >= 0 && n < BITCOUNT); ImBitArrayClearBit(Storage, n); } + void SetBitRange(int n, int n2) { n += OFFSET; n2 += OFFSET; IM_ASSERT(n >= 0 && n < BITCOUNT && n2 > n && n2 <= BITCOUNT); ImBitArraySetBitRange(Storage, n, n2); } // Works on range [n..n2) + bool operator[](int n) const { n += OFFSET; IM_ASSERT(n >= 0 && n < BITCOUNT); return ImBitArrayTestBit(Storage, n); } }; // Helper: ImBitVector @@ -633,7 +643,7 @@ struct ImSpanAllocator // Honor constructor/destructor. Add/remove invalidate all pointers. Indexes have the same lifetime as the associated object. typedef int ImPoolIdx; template -struct IMGUI_API ImPool +struct ImPool { ImVector Buf; // Contiguous data ImGuiStorage Map; // ID->Index @@ -670,7 +680,7 @@ struct IMGUI_API ImPool // We store the chunk size first, and align the final size on 4 bytes boundaries. // The tedious/zealous amount of casting is to avoid -Wcast-align warnings. template -struct IMGUI_API ImChunkStream +struct ImChunkStream { ImVector Buf; @@ -702,7 +712,6 @@ struct IMGUI_API ImChunkStream // // Rendering circles with an odd number of segments, while mathematically correct will produce // asymmetrical results on the raster grid. Therefore we're rounding N to next even number (7->8, 8->8, 9->10 etc.) -// #define IM_ROUNDUP_TO_EVEN(_V) ((((_V) + 1) / 2) * 2) #define IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MIN 4 #define IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MAX 512 @@ -758,6 +767,7 @@ struct ImDrawDataBuilder // This is going to be exposed in imgui.h when stabilized enough. enum ImGuiItemFlags_ { + // Controlled by user ImGuiItemFlags_None = 0, ImGuiItemFlags_NoTabStop = 1 << 0, // false // Disable keyboard tabbing (FIXME: should merge with _NoNav) ImGuiItemFlags_ButtonRepeat = 1 << 1, // false // Button() will return true multiple times based on io.KeyRepeatDelay and io.KeyRepeatRate settings. @@ -767,7 +777,9 @@ enum ImGuiItemFlags_ ImGuiItemFlags_SelectableDontClosePopup = 1 << 5, // false // Disable MenuItem/Selectable() automatically closing their popup window ImGuiItemFlags_MixedValue = 1 << 6, // false // [BETA] Represent a mixed/indeterminate value, generally multi-selection where values differ. Currently only supported by Checkbox() (later should support all sorts of widgets) ImGuiItemFlags_ReadOnly = 1 << 7, // false // [ALPHA] Allow hovering interactions but underlying value is not changed. - ImGuiItemFlags_Inputable = 1 << 8 // false // [WIP] Auto-activate input mode when tab focused. Currently only used and supported by a few items before it becomes a generic feature. + + // Controlled by widget code + ImGuiItemFlags_Inputable = 1 << 8, // false // [WIP] Auto-activate input mode when tab focused. Currently only used and supported by a few items before it becomes a generic feature. }; // Storage for LastItem data @@ -782,14 +794,13 @@ enum ImGuiItemStatusFlags_ ImGuiItemStatusFlags_HasDeactivated = 1 << 5, // Set if the widget/group is able to provide data for the ImGuiItemStatusFlags_Deactivated flag. ImGuiItemStatusFlags_Deactivated = 1 << 6, // Only valid if ImGuiItemStatusFlags_HasDeactivated is set. ImGuiItemStatusFlags_HoveredWindow = 1 << 7, // Override the HoveredWindow test to allow cross-window hover testing. - ImGuiItemStatusFlags_FocusedByTabbing = 1 << 8 // Set when the Focusable item just got focused by Tabbing (FIXME: to be removed soon) + ImGuiItemStatusFlags_FocusedByTabbing = 1 << 8, // Set when the Focusable item just got focused by Tabbing (FIXME: to be removed soon) #ifdef IMGUI_ENABLE_TEST_ENGINE - , // [imgui_tests only] - ImGuiItemStatusFlags_Openable = 1 << 20, // + ImGuiItemStatusFlags_Openable = 1 << 20, // Item is an openable (e.g. TreeNode) ImGuiItemStatusFlags_Opened = 1 << 21, // - ImGuiItemStatusFlags_Checkable = 1 << 22, // - ImGuiItemStatusFlags_Checked = 1 << 23 // + ImGuiItemStatusFlags_Checkable = 1 << 22, // Item is a checkable (e.g. CheckBox, MenuItem) + ImGuiItemStatusFlags_Checked = 1 << 23, // #endif }; @@ -799,7 +810,7 @@ enum ImGuiInputTextFlagsPrivate_ // [Internal] ImGuiInputTextFlags_Multiline = 1 << 26, // For internal use by InputTextMultiline() ImGuiInputTextFlags_NoMarkEdited = 1 << 27, // For internal use by functions using InputText() before reformatting data - ImGuiInputTextFlags_MergedItem = 1 << 28 // For internal use by TempInputText(), will skip calling ItemAdd(). Require bounding-box to strictly match. + ImGuiInputTextFlags_MergedItem = 1 << 28, // For internal use by TempInputText(), will skip calling ItemAdd(). Require bounding-box to strictly match. }; // Extend ImGuiButtonFlags_ @@ -822,20 +833,20 @@ enum ImGuiButtonFlagsPrivate_ ImGuiButtonFlags_NoNavFocus = 1 << 18, // don't override navigation focus when activated ImGuiButtonFlags_NoHoveredOnFocus = 1 << 19, // don't report as hovered when nav focus is on this item ImGuiButtonFlags_PressedOnMask_ = ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnClickReleaseAnywhere | ImGuiButtonFlags_PressedOnRelease | ImGuiButtonFlags_PressedOnDoubleClick | ImGuiButtonFlags_PressedOnDragDropHold, - ImGuiButtonFlags_PressedOnDefault_ = ImGuiButtonFlags_PressedOnClickRelease + ImGuiButtonFlags_PressedOnDefault_ = ImGuiButtonFlags_PressedOnClickRelease, }; // Extend ImGuiComboFlags_ enum ImGuiComboFlagsPrivate_ { - ImGuiComboFlags_CustomPreview = 1 << 20 // enable BeginComboPreview() + ImGuiComboFlags_CustomPreview = 1 << 20, // enable BeginComboPreview() }; // Extend ImGuiSliderFlags_ enum ImGuiSliderFlagsPrivate_ { ImGuiSliderFlags_Vertical = 1 << 20, // Should this slider be orientated vertically? - ImGuiSliderFlags_ReadOnly = 1 << 21 + ImGuiSliderFlags_ReadOnly = 1 << 21, }; // Extend ImGuiSelectableFlags_ @@ -849,33 +860,33 @@ enum ImGuiSelectableFlagsPrivate_ ImGuiSelectableFlags_SpanAvailWidth = 1 << 24, // Span all avail width even if we declared less for layout purpose. FIXME: We may be able to remove this (added in 6251d379, 2bcafc86 for menus) ImGuiSelectableFlags_DrawHoveredWhenHeld = 1 << 25, // Always show active when held, even is not hovered. This concept could probably be renamed/formalized somehow. ImGuiSelectableFlags_SetNavIdOnHover = 1 << 26, // Set Nav/Focus ID on mouse hover (used by MenuItem) - ImGuiSelectableFlags_NoPadWithHalfSpacing = 1 << 27 // Disable padding each side with ItemSpacing * 0.5f + ImGuiSelectableFlags_NoPadWithHalfSpacing = 1 << 27, // Disable padding each side with ItemSpacing * 0.5f }; // Extend ImGuiTreeNodeFlags_ enum ImGuiTreeNodeFlagsPrivate_ { - ImGuiTreeNodeFlags_ClipLabelForTrailingButton = 1 << 20 + ImGuiTreeNodeFlags_ClipLabelForTrailingButton = 1 << 20, }; enum ImGuiSeparatorFlags_ { - ImGuiSeparatorFlags_None = 0, - ImGuiSeparatorFlags_Horizontal = 1 << 0, // Axis default to current layout type, so generally Horizontal unless e.g. in a menu bar - ImGuiSeparatorFlags_Vertical = 1 << 1, - ImGuiSeparatorFlags_SpanAllColumns = 1 << 2 + ImGuiSeparatorFlags_None = 0, + ImGuiSeparatorFlags_Horizontal = 1 << 0, // Axis default to current layout type, so generally Horizontal unless e.g. in a menu bar + ImGuiSeparatorFlags_Vertical = 1 << 1, + ImGuiSeparatorFlags_SpanAllColumns = 1 << 2, }; enum ImGuiTextFlags_ { - ImGuiTextFlags_None = 0, - ImGuiTextFlags_NoWidthForLargeClippedText = 1 << 0 + ImGuiTextFlags_None = 0, + ImGuiTextFlags_NoWidthForLargeClippedText = 1 << 0, }; enum ImGuiTooltipFlags_ { - ImGuiTooltipFlags_None = 0, - ImGuiTooltipFlags_OverridePreviousTooltip = 1 << 0 // Override will clear/ignore previously submitted tooltip (defaults to append) + ImGuiTooltipFlags_None = 0, + ImGuiTooltipFlags_OverridePreviousTooltip = 1 << 0, // Override will clear/ignore previously submitted tooltip (defaults to append) }; // FIXME: this is in development, not exposed/functional as a generic feature yet. @@ -892,7 +903,7 @@ enum ImGuiLogType ImGuiLogType_TTY, ImGuiLogType_File, ImGuiLogType_Buffer, - ImGuiLogType_Clipboard + ImGuiLogType_Clipboard, }; // X/Y enums are fixed to 0/1 so they may be used to index ImVec2 @@ -906,36 +917,14 @@ enum ImGuiAxis enum ImGuiPlotType { ImGuiPlotType_Lines, - ImGuiPlotType_Histogram -}; - -enum ImGuiInputSource -{ - ImGuiInputSource_None = 0, - ImGuiInputSource_Mouse, - ImGuiInputSource_Keyboard, - ImGuiInputSource_Gamepad, - ImGuiInputSource_Nav, // Stored in g.ActiveIdSource only - ImGuiInputSource_Clipboard, // Currently only used by InputText() - ImGuiInputSource_COUNT -}; - -// FIXME-NAV: Clarify/expose various repeat delay/rate -enum ImGuiInputReadMode -{ - ImGuiInputReadMode_Down, - ImGuiInputReadMode_Pressed, - ImGuiInputReadMode_Released, - ImGuiInputReadMode_Repeat, - ImGuiInputReadMode_RepeatSlow, - ImGuiInputReadMode_RepeatFast + ImGuiPlotType_Histogram, }; enum ImGuiPopupPositionPolicy { ImGuiPopupPositionPolicy_Default, ImGuiPopupPositionPolicy_ComboBox, - ImGuiPopupPositionPolicy_Tooltip + ImGuiPopupPositionPolicy_Tooltip, }; struct ImGuiDataTypeTempStorage @@ -957,14 +946,14 @@ enum ImGuiDataTypePrivate_ { ImGuiDataType_String = ImGuiDataType_COUNT + 1, ImGuiDataType_Pointer, - ImGuiDataType_ID + ImGuiDataType_ID, }; // Stacked color modifier, backup of modified data so we can restore it struct ImGuiColorMod { - ImGuiCol Col; - ImVec4 BackupValue; + ImGuiCol Col; + ImVec4 BackupValue; }; // Stacked style modifier, backup of modified data so we can restore it. Data type inferred from the variable. @@ -1067,12 +1056,13 @@ struct ImGuiPopupData ImGuiID PopupId; // Set on OpenPopup() ImGuiWindow* Window; // Resolved on BeginPopup() - may stay unresolved if user never calls OpenPopup() ImGuiWindow* SourceWindow; // Set on OpenPopup() copy of NavWindow at the time of opening the popup + int ParentNavLayer; // Resolved on BeginPopup(). Actually a ImGuiNavLayer type (declared down below), initialized to -1 which is not part of an enum, but serves well-enough as "not any of layers" value int OpenFrameCount; // Set on OpenPopup() ImGuiID OpenParentId; // Set on OpenPopup(), we need this to differentiate multiple menu sets from each others (e.g. inside menu bar vs loose menu items) ImVec2 OpenPopupPos; // Set on OpenPopup(), preferred popup position (typically == OpenMousePos when using mouse) ImVec2 OpenMousePos; // Set on OpenPopup(), copy of mouse position at the time of opening popup - ImGuiPopupData() { memset(this, 0, sizeof(*this)); OpenFrameCount = -1; } + ImGuiPopupData() { memset(this, 0, sizeof(*this)); ParentNavLayer = OpenFrameCount = -1; } }; enum ImGuiNextWindowDataFlags_ @@ -1088,7 +1078,7 @@ enum ImGuiNextWindowDataFlags_ ImGuiNextWindowDataFlags_HasScroll = 1 << 7, ImGuiNextWindowDataFlags_HasViewport = 1 << 8, ImGuiNextWindowDataFlags_HasDock = 1 << 9, - ImGuiNextWindowDataFlags_HasWindowClass = 1 << 10 + ImGuiNextWindowDataFlags_HasWindowClass = 1 << 10, }; // Storage for SetNexWindow** functions @@ -1123,7 +1113,7 @@ enum ImGuiNextItemDataFlags_ { ImGuiNextItemDataFlags_None = 0, ImGuiNextItemDataFlags_HasWidth = 1 << 0, - ImGuiNextItemDataFlags_HasOpen = 1 << 1 + ImGuiNextItemDataFlags_HasOpen = 1 << 1, }; struct ImGuiNextItemData @@ -1180,6 +1170,7 @@ struct ImGuiShrinkWidthItem { int Index; float Width; + float InitialWidth; }; struct ImGuiPtrOrIndex @@ -1191,6 +1182,99 @@ struct ImGuiPtrOrIndex ImGuiPtrOrIndex(int index) { Ptr = NULL; Index = index; } }; +//----------------------------------------------------------------------------- +// [SECTION] Inputs support +//----------------------------------------------------------------------------- + +typedef ImBitArray ImBitArrayForNamedKeys; + +// Extend ImGuiKey_ +enum ImGuiKeyPrivate_ +{ + ImGuiKey_LegacyNativeKey_BEGIN = 0, + ImGuiKey_LegacyNativeKey_END = 512, + ImGuiKey_Gamepad_BEGIN = ImGuiKey_GamepadStart, + ImGuiKey_Gamepad_END = ImGuiKey_GamepadRStickDown + 1, + ImGuiKey_Aliases_BEGIN = ImGuiKey_MouseLeft, + ImGuiKey_Aliases_END = ImGuiKey_COUNT, + + // [Internal] Named shortcuts for Navigation + ImGuiKey_NavKeyboardTweakSlow = ImGuiKey_ModCtrl, + ImGuiKey_NavKeyboardTweakFast = ImGuiKey_ModShift, + ImGuiKey_NavGamepadTweakSlow = ImGuiKey_GamepadL1, + ImGuiKey_NavGamepadTweakFast = ImGuiKey_GamepadR1, + ImGuiKey_NavGamepadActivate = ImGuiKey_GamepadFaceDown, + ImGuiKey_NavGamepadCancel = ImGuiKey_GamepadFaceRight, + ImGuiKey_NavGamepadMenu = ImGuiKey_GamepadFaceLeft, + ImGuiKey_NavGamepadInput = ImGuiKey_GamepadFaceUp, +}; + +enum ImGuiInputEventType +{ + ImGuiInputEventType_None = 0, + ImGuiInputEventType_MousePos, + ImGuiInputEventType_MouseWheel, + ImGuiInputEventType_MouseButton, + ImGuiInputEventType_MouseViewport, + ImGuiInputEventType_Key, + ImGuiInputEventType_Text, + ImGuiInputEventType_Focus, + ImGuiInputEventType_COUNT +}; + +enum ImGuiInputSource +{ + ImGuiInputSource_None = 0, + ImGuiInputSource_Mouse, + ImGuiInputSource_Keyboard, + ImGuiInputSource_Gamepad, + ImGuiInputSource_Clipboard, // Currently only used by InputText() + ImGuiInputSource_Nav, // Stored in g.ActiveIdSource only + ImGuiInputSource_COUNT +}; + +// FIXME: Structures in the union below need to be declared as anonymous unions appears to be an extension? +// Using ImVec2() would fail on Clang 'union member 'MousePos' has a non-trivial default constructor' +struct ImGuiInputEventMousePos { float PosX, PosY; }; +struct ImGuiInputEventMouseWheel { float WheelX, WheelY; }; +struct ImGuiInputEventMouseButton { int Button; bool Down; }; +struct ImGuiInputEventMouseViewport { ImGuiID HoveredViewportID; }; +struct ImGuiInputEventKey { ImGuiKey Key; bool Down; float AnalogValue; }; +struct ImGuiInputEventText { unsigned int Char; }; +struct ImGuiInputEventAppFocused { bool Focused; }; + +struct ImGuiInputEvent +{ + ImGuiInputEventType Type; + ImGuiInputSource Source; + union + { + ImGuiInputEventMousePos MousePos; // if Type == ImGuiInputEventType_MousePos + ImGuiInputEventMouseWheel MouseWheel; // if Type == ImGuiInputEventType_MouseWheel + ImGuiInputEventMouseButton MouseButton; // if Type == ImGuiInputEventType_MouseButton + ImGuiInputEventMouseViewport MouseViewport; // if Type == ImGuiInputEventType_MouseViewport + ImGuiInputEventKey Key; // if Type == ImGuiInputEventType_Key + ImGuiInputEventText Text; // if Type == ImGuiInputEventType_Text + ImGuiInputEventAppFocused AppFocused; // if Type == ImGuiInputEventType_Focus + }; + bool AddedByTestEngine; + + ImGuiInputEvent() { memset(this, 0, sizeof(*this)); } +}; + +// Flags for IsKeyPressedEx(). In upcoming feature this will be used more (and IsKeyPressedEx() renamed) +// Don't mistake with ImGuiInputTextFlags! (for ImGui::InputText() function) +enum ImGuiInputFlags_ +{ + // Flags for IsKeyPressedEx() + ImGuiInputFlags_None = 0, + ImGuiInputFlags_Repeat = 1 << 0, // Return true on successive repeats. Default for legacy IsKeyPressed(). NOT Default for legacy IsMouseClicked(). MUST BE == 1. + ImGuiInputFlags_RepeatRateDefault = 1 << 1, // Repeat rate: Regular (default) + ImGuiInputFlags_RepeatRateNavMove = 1 << 2, // Repeat rate: Fast + ImGuiInputFlags_RepeatRateNavTweak = 1 << 3, // Repeat rate: Faster + ImGuiInputFlags_RepeatRateMask_ = ImGuiInputFlags_RepeatRateDefault | ImGuiInputFlags_RepeatRateNavMove | ImGuiInputFlags_RepeatRateNavTweak, +}; + //----------------------------------------------------------------------------- // [SECTION] Clipper support //----------------------------------------------------------------------------- @@ -1229,7 +1313,7 @@ enum ImGuiActivateFlags_ ImGuiActivateFlags_None = 0, ImGuiActivateFlags_PreferInput = 1 << 0, // Favor activation that requires keyboard text input (e.g. for Slider/Drag). Default if keyboard is available. ImGuiActivateFlags_PreferTweak = 1 << 1, // Favor activation for tweaking with arrows or gamepad (e.g. for Slider/Drag). Default if keyboard is not available. - ImGuiActivateFlags_TryToPreserveState = 1 << 2 // Request widget to preserve state if it can (e.g. InputText will try to preserve cursor/selection) + ImGuiActivateFlags_TryToPreserveState = 1 << 2, // Request widget to preserve state if it can (e.g. InputText will try to preserve cursor/selection) }; // Early work-in-progress API for ScrollToItem() @@ -1244,7 +1328,7 @@ enum ImGuiScrollFlags_ ImGuiScrollFlags_AlwaysCenterY = 1 << 5, // Always center the result item on Y axis [default for Y axis for appearing window) ImGuiScrollFlags_NoScrollParent = 1 << 6, // Disable forwarding scrolling to parent window if required to keep item/rect visible (only scroll window the function was applied to). ImGuiScrollFlags_MaskX_ = ImGuiScrollFlags_KeepVisibleEdgeX | ImGuiScrollFlags_KeepVisibleCenterX | ImGuiScrollFlags_AlwaysCenterX, - ImGuiScrollFlags_MaskY_ = ImGuiScrollFlags_KeepVisibleEdgeY | ImGuiScrollFlags_KeepVisibleCenterY | ImGuiScrollFlags_AlwaysCenterY + ImGuiScrollFlags_MaskY_ = ImGuiScrollFlags_KeepVisibleEdgeY | ImGuiScrollFlags_KeepVisibleCenterY | ImGuiScrollFlags_AlwaysCenterY, }; enum ImGuiNavHighlightFlags_ @@ -1253,16 +1337,7 @@ enum ImGuiNavHighlightFlags_ ImGuiNavHighlightFlags_TypeDefault = 1 << 0, ImGuiNavHighlightFlags_TypeThin = 1 << 1, ImGuiNavHighlightFlags_AlwaysDraw = 1 << 2, // Draw rectangular highlight if (g.NavId == id) _even_ when using the mouse. - ImGuiNavHighlightFlags_NoRounding = 1 << 3 -}; - -enum ImGuiNavDirSourceFlags_ -{ - ImGuiNavDirSourceFlags_None = 0, - ImGuiNavDirSourceFlags_RawKeyboard = 1 << 0, // Raw keyboard (not pulled from nav), faciliate use of some functions before we can unify nav and keys - ImGuiNavDirSourceFlags_Keyboard = 1 << 1, - ImGuiNavDirSourceFlags_PadDPad = 1 << 2, - ImGuiNavDirSourceFlags_PadLStick = 1 << 3 + ImGuiNavHighlightFlags_NoRounding = 1 << 3, }; enum ImGuiNavMoveFlags_ @@ -1280,13 +1355,13 @@ enum ImGuiNavMoveFlags_ ImGuiNavMoveFlags_FocusApi = 1 << 9, ImGuiNavMoveFlags_Tabbing = 1 << 10, // == Focus + Activate if item is Inputable + DontChangeNavHighlight ImGuiNavMoveFlags_Activate = 1 << 11, - ImGuiNavMoveFlags_DontSetNavHighlight = 1 << 12 // Do not alter the visible state of keyboard vs mouse nav highlight + ImGuiNavMoveFlags_DontSetNavHighlight = 1 << 12, // Do not alter the visible state of keyboard vs mouse nav highlight }; enum ImGuiNavLayer { ImGuiNavLayer_Main = 0, // Main scrolling layer - ImGuiNavLayer_Menu = 1, // Menu layer (access with Alt/ImGuiNavInput_Menu) + ImGuiNavLayer_Menu = 1, // Menu layer (access with Alt) ImGuiNavLayer_COUNT }; @@ -1317,24 +1392,24 @@ enum ImGuiOldColumnFlags_ ImGuiOldColumnFlags_NoResize = 1 << 1, // Disable resizing columns when clicking on the dividers ImGuiOldColumnFlags_NoPreserveWidths = 1 << 2, // Disable column width preservation when adjusting columns ImGuiOldColumnFlags_NoForceWithinWindow = 1 << 3, // Disable forcing columns to fit within window - ImGuiOldColumnFlags_GrowParentContentsSize = 1 << 4 // (WIP) Restore pre-1.51 behavior of extending the parent window contents size but _without affecting the columns width at all_. Will eventually remove. + ImGuiOldColumnFlags_GrowParentContentsSize = 1 << 4, // (WIP) Restore pre-1.51 behavior of extending the parent window contents size but _without affecting the columns width at all_. Will eventually remove. // Obsolete names (will be removed) #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - , ImGuiColumnsFlags_None = ImGuiOldColumnFlags_None, + ImGuiColumnsFlags_None = ImGuiOldColumnFlags_None, ImGuiColumnsFlags_NoBorder = ImGuiOldColumnFlags_NoBorder, ImGuiColumnsFlags_NoResize = ImGuiOldColumnFlags_NoResize, ImGuiColumnsFlags_NoPreserveWidths = ImGuiOldColumnFlags_NoPreserveWidths, ImGuiColumnsFlags_NoForceWithinWindow = ImGuiOldColumnFlags_NoForceWithinWindow, - ImGuiColumnsFlags_GrowParentContentsSize = ImGuiOldColumnFlags_GrowParentContentsSize + ImGuiColumnsFlags_GrowParentContentsSize = ImGuiOldColumnFlags_GrowParentContentsSize, #endif }; struct ImGuiOldColumnData { - float OffsetNorm; // Column start offset, normalized 0.0 (far left) -> 1.0 (far right) + float OffsetNorm; // Column start offset, normalized 0.0 (far left) -> 1.0 (far right) float OffsetNormBeforeResize; - ImGuiOldColumnFlags Flags; // Not exposed + ImGuiOldColumnFlags Flags; // Not exposed ImRect ClipRect; ImGuiOldColumnData() { memset(this, 0, sizeof(*this)); } @@ -1373,6 +1448,9 @@ struct ImGuiOldColumns // [SECTION] Docking support //----------------------------------------------------------------------------- +#define DOCKING_HOST_DRAW_CHANNEL_BG 0 // Dock host: background fill +#define DOCKING_HOST_DRAW_CHANNEL_FG 1 // Dock host: decorations and contents + #ifdef IMGUI_HAS_DOCK // Extend ImGuiDockNodeFlags_ @@ -1405,7 +1483,7 @@ enum ImGuiDataAuthority_ { ImGuiDataAuthority_Auto, ImGuiDataAuthority_DockNode, - ImGuiDataAuthority_Window + ImGuiDataAuthority_Window, }; enum ImGuiDockNodeState @@ -1413,7 +1491,7 @@ enum ImGuiDockNodeState ImGuiDockNodeState_Unknown, ImGuiDockNodeState_HostWindowHiddenBecauseSingleWindow, ImGuiDockNodeState_HostWindowHiddenBecauseWindowsAreResizing, - ImGuiDockNodeState_HostWindowVisible + ImGuiDockNodeState_HostWindowVisible, }; // sizeof() 156~192 @@ -1598,8 +1676,24 @@ struct ImGuiSettingsHandler // [SECTION] Metrics, Debug Tools //----------------------------------------------------------------------------- +enum ImGuiDebugLogFlags_ +{ + // Event types + ImGuiDebugLogFlags_None = 0, + ImGuiDebugLogFlags_EventActiveId = 1 << 0, + ImGuiDebugLogFlags_EventFocus = 1 << 1, + ImGuiDebugLogFlags_EventPopup = 1 << 2, + ImGuiDebugLogFlags_EventNav = 1 << 3, + ImGuiDebugLogFlags_EventIO = 1 << 4, + ImGuiDebugLogFlags_EventDocking = 1 << 5, + ImGuiDebugLogFlags_EventViewport = 1 << 6, + ImGuiDebugLogFlags_EventMask_ = ImGuiDebugLogFlags_EventActiveId | ImGuiDebugLogFlags_EventFocus | ImGuiDebugLogFlags_EventPopup | ImGuiDebugLogFlags_EventNav | ImGuiDebugLogFlags_EventIO | ImGuiDebugLogFlags_EventDocking | ImGuiDebugLogFlags_EventViewport, + ImGuiDebugLogFlags_OutputToTTY = 1 << 10, // Also send output to TTY +}; + struct ImGuiMetricsConfig { + bool ShowDebugLog; bool ShowStackTool; bool ShowWindowsRects; bool ShowWindowsBeginOrder; @@ -1612,15 +1706,11 @@ struct ImGuiMetricsConfig ImGuiMetricsConfig() { - ShowStackTool = false; - ShowWindowsRects = false; - ShowWindowsBeginOrder = false; - ShowTablesRects = false; + ShowDebugLog = ShowStackTool = ShowWindowsRects = ShowWindowsBeginOrder = ShowTablesRects = false; ShowDrawCmdMesh = true; ShowDrawCmdBoundingBoxes = true; ShowDockingNodes = false; - ShowWindowsRectsType = -1; - ShowTablesRectsType = -1; + ShowWindowsRectsType = ShowTablesRectsType = -1; } }; @@ -1629,7 +1719,8 @@ struct ImGuiStackLevelInfo ImGuiID ID; ImS8 QueryFrameCount; // >= 1: Query in progress bool QuerySuccess; // Obtained result from DebugHookIdInfo() - char Desc[58]; // Arbitrarily sized buffer to hold a result (FIXME: could replace Results[] with a chunk stream?) + ImGuiDataType DataType : 8; + char Desc[57]; // Arbitrarily sized buffer to hold a result (FIXME: could replace Results[] with a chunk stream?) FIXME: Now that we added CTRL+C this should be fixed. ImGuiStackLevelInfo() { memset(this, 0, sizeof(*this)); } }; @@ -1641,8 +1732,10 @@ struct ImGuiStackTool int StackLevel; // -1: query stack and resize Results, >= 0: individual stack level ImGuiID QueryId; // ID to query details for ImVector Results; + bool CopyToClipboardOnCtrlC; + float CopyToClipboardLastTime; - ImGuiStackTool() { memset(this, 0, sizeof(*this)); } + ImGuiStackTool() { memset(this, 0, sizeof(*this)); CopyToClipboardLastTime = -FLT_MAX; } }; //----------------------------------------------------------------------------- @@ -1664,7 +1757,7 @@ struct ImGuiContextHook }; //----------------------------------------------------------------------------- -// [SECTION] ImGuiContext (main imgui context) +// [SECTION] ImGuiContext (main Dear ImGui context) //----------------------------------------------------------------------------- struct ImGuiContext @@ -1673,6 +1766,8 @@ struct ImGuiContext bool FontAtlasOwnedByContext; // IO.Fonts-> is owned by the ImGuiContext and will be destructed along with it. ImGuiIO IO; ImGuiPlatformIO PlatformIO; + ImVector InputEventsQueue; // Input events which will be tricked/written into IO structure. + ImVector InputEventsTrail; // Past input events processed in NewFrame(). This is to allow domain-specific application to access e.g mouse/pen trail. ImGuiStyle Style; ImGuiConfigFlags ConfigFlagsCurrFrame; // = g.IO.ConfigFlags at the time of NewFrame() ImGuiConfigFlags ConfigFlagsLastFrame; @@ -1728,10 +1823,6 @@ struct ImGuiContext bool ActiveIdHasBeenPressedBefore; // Track whether the active id led to a press (this is to allow changing between PressOnClick and PressOnRelease without pressing twice). Used by range_select branch. bool ActiveIdHasBeenEditedBefore; // Was the value associated to the widget Edited over the course of the Active state. bool ActiveIdHasBeenEditedThisFrame; - bool ActiveIdUsingMouseWheel; // Active widget will want to read mouse wheel. Blocks scrolling the underlying window. - ImU32 ActiveIdUsingNavDirMask; // Active widget will want to read those nav move requests (e.g. can activate a button and move away from it) - ImU32 ActiveIdUsingNavInputMask; // Active widget will want to read those nav inputs. - ImU64 ActiveIdUsingKeyInputMask; // Active widget will want to read those key inputs. When we grow the ImGuiKey enum we'll need to either to order the enum to make useful keys come first, either redesign this into e.g. a small array. ImVec2 ActiveIdClickOffset; // Clicked offset from upper-left corner, if applicable (currently only set by ButtonBehavior) ImGuiWindow* ActiveIdWindow; ImGuiInputSource ActiveIdSource; // Activating with mouse or nav (gamepad/keyboard) @@ -1743,8 +1834,15 @@ struct ImGuiContext ImGuiID LastActiveId; // Store the last non-zero ActiveId, useful for animation. float LastActiveIdTimer; // Store the last non-zero ActiveId timer since the beginning of activation, useful for animation. + // Input Ownership + ImU32 ActiveIdUsingNavDirMask; // Active widget will want to read those nav move requests (e.g. can activate a button and move away from it) + ImBitArrayForNamedKeys ActiveIdUsingKeyInputMask; // Active widget will want to read those key inputs. When we grow the ImGuiKey enum we'll need to either to order the enum to make useful keys come first, either redesign this into e.g. a small array. +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO + ImU32 ActiveIdUsingNavInputMask; // If you used this. Since (IMGUI_VERSION_NUM >= 18804) : 'g.ActiveIdUsingNavInputMask |= (1 << ImGuiNavInput_Cancel);' becomes 'SetActiveIdUsingKey(ImGuiKey_Escape); SetActiveIdUsingKey(ImGuiKey_NavGamepadCancel);' +#endif + // Next window/item data - ImGuiItemFlags CurrentItemFlags; // == g.ItemFlagsStack.back() + ImGuiItemFlags CurrentItemFlags; // == g.ItemFlagsStack.back() ImGuiNextItemData NextItemData; // Storage for SetNextItem** functions ImGuiLastItemData LastItemData; // Storage for last submitted item (setup by ItemAdd) ImGuiNextWindowData NextWindowData; // Storage for SetNextWindow** functions @@ -1771,17 +1869,17 @@ struct ImGuiContext int ViewportFrontMostStampCount; // Every time the front-most window changes, we stamp its viewport with an incrementing counter // Gamepad/keyboard Navigation - ImGuiWindow* NavWindow; // Focused window for navigation. Could be called 'FocusWindow' + ImGuiWindow* NavWindow; // Focused window for navigation. Could be called 'FocusedWindow' ImGuiID NavId; // Focused item for navigation ImGuiID NavFocusScopeId; // Identify a selection scope (selection code often wants to "clear other items" when landing on an item of the selection set) - ImGuiID NavActivateId; // ~~ (g.ActiveId == 0) && IsNavInputPressed(ImGuiNavInput_Activate) ? NavId : 0, also set when calling ActivateItem() - ImGuiID NavActivateDownId; // ~~ IsNavInputDown(ImGuiNavInput_Activate) ? NavId : 0 - ImGuiID NavActivatePressedId; // ~~ IsNavInputPressed(ImGuiNavInput_Activate) ? NavId : 0 - ImGuiID NavActivateInputId; // ~~ IsNavInputPressed(ImGuiNavInput_Input) ? NavId : 0; ImGuiActivateFlags_PreferInput will be set and NavActivateId will be 0. + ImGuiID NavActivateId; // ~~ (g.ActiveId == 0) && (IsKeyPressed(ImGuiKey_Space) || IsKeyPressed(ImGuiKey_NavGamepadActivate)) ? NavId : 0, also set when calling ActivateItem() + ImGuiID NavActivateDownId; // ~~ IsKeyDown(ImGuiKey_Space) || IsKeyDown(ImGuiKey_NavGamepadActivate) ? NavId : 0 + ImGuiID NavActivatePressedId; // ~~ IsKeyPressed(ImGuiKey_Space) || IsKeyPressed(ImGuiKey_NavGamepadActivate) ? NavId : 0 (no repeat) + ImGuiID NavActivateInputId; // ~~ IsKeyPressed(ImGuiKey_Enter) || IsKeyPressed(ImGuiKey_NavGamepadInput) ? NavId : 0; ImGuiActivateFlags_PreferInput will be set and NavActivateId will be 0. ImGuiActivateFlags NavActivateFlags; ImGuiID NavJustMovedToId; // Just navigated to this id (result of a successfully MoveRequest). ImGuiID NavJustMovedToFocusScopeId; // Just navigated to this focus scope id (result of a successfully MoveRequest). - ImGuiKeyModFlags NavJustMovedToKeyMods; + ImGuiModFlags NavJustMovedToKeyMods; ImGuiID NavNextActivateId; // Set by ActivateItem(), queued until next frame. ImGuiActivateFlags NavNextActivateFlags; ImGuiInputSource NavInputSource; // Keyboard or Gamepad mode? THIS WILL ONLY BE None or NavGamepad or NavKeyboard. @@ -1802,7 +1900,7 @@ struct ImGuiContext bool NavMoveForwardToNextFrame; ImGuiNavMoveFlags NavMoveFlags; ImGuiScrollFlags NavMoveScrollFlags; - ImGuiKeyModFlags NavMoveKeyMods; + ImGuiModFlags NavMoveKeyMods; ImGuiDir NavMoveDir; // Direction of the move request (left/right/up/down) ImGuiDir NavMoveDirForDebug; ImGuiDir NavMoveClipDir; // FIXME-NAV: Describe the purpose of this better. Might want to rename? @@ -1823,6 +1921,8 @@ struct ImGuiContext float NavWindowingTimer; float NavWindowingHighlightAlpha; bool NavWindowingToggleLayer; + ImVec2 NavWindowingAccumDeltaPos; + ImVec2 NavWindowingAccumDeltaSize; // Render float DimBgRatio; // 0.0..1.0 animation when fading in a dimming background (for modal window and CTRL+TAB list) @@ -1851,7 +1951,7 @@ struct ImGuiContext int ClipperTempDataStacked; ImVector ClipperTempData; - // Table + // Tables ImGuiTable* CurrentTable; int TablesTempDataStacked; // Temporary table data size (because we leave previous instances undestructed, we generally don't use TablesTempData.Size) ImVector TablesTempData; // Temporary table data (buffers reused/shared across instances, support nesting) @@ -1876,6 +1976,7 @@ struct ImGuiContext ImU32 ColorEditLastColor; // RGB value with alpha set to 0. ImVec4 ColorPickerRef; // Initial/reference color at the time of opening the color picker. ImGuiComboPreviewData ComboPreviewData; + float SliderGrabClickOffset; float SliderCurrentAccum; // Accumulated slider delta when using navigation controls. bool SliderCurrentAccumDirty; // Has the accumulated slider delta changed since last time we tried to apply it? bool DragCurrentAccumDirty; @@ -1890,9 +1991,9 @@ struct ImGuiContext ImVector MenusIdSubmittedThisFrame; // A list of menu IDs that were rendered at least once // Platform support - ImVec2 PlatformImePos; // Cursor position request & last passed to the OS Input Method Editor - ImVec2 PlatformImeLastPos; - ImGuiViewportP* PlatformImePosViewport; + ImGuiPlatformImeData PlatformImeData; // Data updated by current frame + ImGuiPlatformImeData PlatformImeDataPrev; // Previous frame data (when changing we will call io.SetPlatformImeDataFn + ImGuiID PlatformImeViewport; char PlatformLocaleDecimalPoint; // '.' or *localeconv()->decimal_point // Extensions @@ -1923,20 +2024,23 @@ struct ImGuiContext int LogDepthToExpandDefault; // Default/stored value for LogDepthMaxExpand if not specified in the LogXXX function call. // Debug Tools + ImGuiDebugLogFlags DebugLogFlags; + ImGuiTextBuffer DebugLogBuf; bool DebugItemPickerActive; // Item picker is active (started with DebugStartItemPicker()) + ImU8 DebugItemPickerMouseButton; ImGuiID DebugItemPickerBreakId; // Will call IM_DEBUG_BREAK() when encountering this ID ImGuiMetricsConfig DebugMetricsConfig; ImGuiStackTool DebugStackTool; // Misc - float FramerateSecPerFrame[120]; // Calculate estimate of framerate for user over the last 2 seconds. + float FramerateSecPerFrame[60]; // Calculate estimate of framerate for user over the last 60 frames.. int FramerateSecPerFrameIdx; int FramerateSecPerFrameCount; float FramerateSecPerFrameAccum; - int WantCaptureMouseNextFrame; // Explicit capture via CaptureKeyboardFromApp()/CaptureMouseFromApp() sets those flags - int WantCaptureKeyboardNextFrame; + int WantCaptureMouseNextFrame; // Explicit capture override via SetNextFrameWantCaptureMouse()/SetNextFrameWantCaptureKeyboard(). Default to -1. + int WantCaptureKeyboardNextFrame; // " int WantTextInputNextFrame; - char TempBuffer[1024 * 3 + 1]; // Temporary text buffer + ImVector TempBuffer; // Temporary text buffer ImGuiContext(ImFontAtlas* shared_font_atlas) { @@ -1978,10 +2082,6 @@ struct ImGuiContext ActiveIdHasBeenPressedBefore = false; ActiveIdHasBeenEditedBefore = false; ActiveIdHasBeenEditedThisFrame = false; - ActiveIdUsingMouseWheel = false; - ActiveIdUsingNavDirMask = 0x00; - ActiveIdUsingNavInputMask = 0x00; - ActiveIdUsingKeyInputMask = 0x00; ActiveIdClickOffset = ImVec2(-1, -1); ActiveIdWindow = NULL; ActiveIdSource = ImGuiInputSource_None; @@ -1993,6 +2093,12 @@ struct ImGuiContext LastActiveId = 0; LastActiveIdTimer = 0.0f; + ActiveIdUsingNavDirMask = 0x00; + ActiveIdUsingKeyInputMask.ClearAllBits(); +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO + ActiveIdUsingNavInputMask = 0x00; +#endif + CurrentItemFlags = ImGuiItemFlags_None; BeginMenuCount = 0; @@ -2006,7 +2112,7 @@ struct ImGuiContext NavId = NavFocusScopeId = NavActivateId = NavActivateDownId = NavActivatePressedId = NavActivateInputId = 0; NavJustMovedToId = NavJustMovedToFocusScopeId = NavNextActivateId = 0; NavActivateFlags = NavNextActivateFlags = ImGuiActivateFlags_None; - NavJustMovedToKeyMods = ImGuiKeyModFlags_None; + NavJustMovedToKeyMods = ImGuiModFlags_None; NavInputSource = ImGuiInputSource_None; NavLayer = ImGuiNavLayer_Main; NavIdIsAlive = false; @@ -2022,7 +2128,7 @@ struct ImGuiContext NavMoveForwardToNextFrame = false; NavMoveFlags = ImGuiNavMoveFlags_None; NavMoveScrollFlags = ImGuiScrollFlags_None; - NavMoveKeyMods = ImGuiKeyModFlags_None; + NavMoveKeyMods = ImGuiModFlags_None; NavMoveDir = NavMoveDirForDebug = NavMoveClipDir = ImGuiDir_None; NavScoringDebugCount = 0; NavTabbingDir = 0; @@ -2057,6 +2163,7 @@ struct ImGuiContext ColorEditOptions = ImGuiColorEditFlags_DefaultOptions_; ColorEditLastHue = ColorEditLastSat = 0.0f; ColorEditLastColor = 0; + SliderGrabClickOffset = 0.0f; SliderCurrentAccum = 0.0f; SliderCurrentAccumDirty = false; DragCurrentAccumDirty = false; @@ -2068,8 +2175,9 @@ struct ImGuiContext TooltipOverrideCount = 0; TooltipSlowDelay = 0.50f; - PlatformImePos = PlatformImeLastPos = ImVec2(FLT_MAX, FLT_MAX); - PlatformImePosViewport = 0; + PlatformImeData.InputPos = ImVec2(0.0f, 0.0f); + PlatformImeDataPrev.InputPos = ImVec2(-1.0f, -1.0f); // Different to ensure initial submission + PlatformImeViewport = 0; PlatformLocaleDecimalPoint = '.'; SettingsLoaded = false; @@ -2085,14 +2193,15 @@ struct ImGuiContext LogDepthRef = 0; LogDepthToExpand = LogDepthToExpandDefault = 2; + DebugLogFlags = ImGuiDebugLogFlags_OutputToTTY; DebugItemPickerActive = false; + DebugItemPickerMouseButton = ImGuiMouseButton_Left; DebugItemPickerBreakId = 0; memset(FramerateSecPerFrame, 0, sizeof(FramerateSecPerFrame)); FramerateSecPerFrameIdx = FramerateSecPerFrameCount = 0; FramerateSecPerFrameAccum = 0.0f; WantCaptureMouseNextFrame = WantCaptureKeyboardNextFrame = WantTextInputNextFrame = -1; - memset(TempBuffer, 0, sizeof(TempBuffer)); } }; @@ -2115,6 +2224,7 @@ struct IMGUI_API ImGuiWindowTempData ImVec2 PrevLineSize; float CurrLineTextBaseOffset; // Baseline offset (0.0f by default on a new line, generally == style.FramePadding.y when a framed item has been added). float PrevLineTextBaseOffset; + bool IsSameLine; ImVec1 Indent; // Indentation / start position from left of window (increased by TreePush/TreePop, etc.) ImVec1 ColumnsOffset; // Offset to the current column (if ColumnsCurrent > 0). FIXME: This and the above should be a stack to allow use cases like Tree->Column->Tree. Need revamp columns API. ImVec1 GroupOffset; @@ -2156,7 +2266,7 @@ struct IMGUI_API ImGuiWindow ImGuiID ID; // == ImHashStr(Name) ImGuiWindowFlags Flags, FlagsPreviousFrame; // See enum ImGuiWindowFlags_ ImGuiWindowClass WindowClass; // Advanced users only. Set with SetNextWindowClass() - ImGuiViewportP* Viewport; // Always set in Begin(), only inactive windows may have a NULL value here + ImGuiViewportP* Viewport; // Always set in Begin(). Inactive windows may have a NULL value here if their viewport was discarded. ImGuiID ViewportId; // We backup the viewport id (since the viewport may disappear or never be created if the window is inactive) ImVec2 ViewportPos; // We backup the viewport position (since the viewport may disappear or never be created if the window is inactive) int ViewportAllowPlatformMonitorExtend; // Reset to -1 every frame (index is guaranteed to be valid between NewFrame..EndFrame), only used in the Appearing frame of a tooltip/popup to enforce clamping to a given monitor @@ -2171,6 +2281,7 @@ struct IMGUI_API ImGuiWindow float WindowBorderSize; // Window border size at the time of Begin(). int NameBufLen; // Size of buffer storing Name. May be larger than strlen(Name)! ImGuiID MoveId; // == window->GetID("#MOVE") + ImGuiID TabId; // == window->GetID("#TAB") ImGuiID ChildId; // ID of corresponding item in parent window (for navigation to return from child window to parent window) ImVec2 Scroll; ImVec2 ScrollMax; @@ -2275,9 +2386,6 @@ public: ImGuiID GetID(const char* str, const char* str_end = NULL); ImGuiID GetID(const void* ptr); ImGuiID GetID(int n); - ImGuiID GetIDNoKeepAlive(const char* str, const char* str_end = NULL); - ImGuiID GetIDNoKeepAlive(const void* ptr); - ImGuiID GetIDNoKeepAlive(int n); ImGuiID GetIDFromRectangle(const ImRect& r_abs); // We don't use g.FontSize because the window may be != g.CurrentWidow. @@ -2298,7 +2406,7 @@ enum ImGuiTabBarFlagsPrivate_ { ImGuiTabBarFlags_DockNode = 1 << 20, // Part of a dock node [we don't use this in the master branch but it facilitate branch syncing to keep this around] ImGuiTabBarFlags_IsFocused = 1 << 21, - ImGuiTabBarFlags_SaveSettings = 1 << 22 // FIXME: Settings are handled by the docking system, this only request the tab bar to mark settings dirty when reordering tabs + ImGuiTabBarFlags_SaveSettings = 1 << 22, // FIXME: Settings are handled by the docking system, this only request the tab bar to mark settings dirty when reordering tabs }; // Extend ImGuiTabItemFlags_ @@ -2308,7 +2416,7 @@ enum ImGuiTabItemFlagsPrivate_ ImGuiTabItemFlags_NoCloseButton = 1 << 20, // Track whether p_open was set or not (we'll need this info on the next frame to recompute ContentWidth during layout) ImGuiTabItemFlags_Button = 1 << 21, // Used by TabItemButton, change the tab item behavior to mimic a button ImGuiTabItemFlags_Unsorted = 1 << 22, // [Docking] Trailing tabs with the _Unsorted flag will be sorted based on the DockOrder of their Window. - ImGuiTabItemFlags_Preview = 1 << 23 // [Docking] Display tab shape for docking preview (height is adjusted slightly to compensate for the yet missing tab bar) + ImGuiTabItemFlags_Preview = 1 << 23, // [Docking] Display tab shape for docking preview (height is adjusted slightly to compensate for the yet missing tab bar) }; // Storage for one active tab item (sizeof() 48 bytes) @@ -2322,6 +2430,7 @@ struct ImGuiTabItem float Offset; // Position relative to beginning of tab float Width; // Width currently displayed float ContentWidth; // Width of label, stored during BeginTabItem() call + float RequestedWidth; // Width optionally requested by caller, -1.0f is unused ImS32 NameOffset; // When Window==NULL, offset to name within parent ImGuiTabBar::TabsNames ImS16 BeginOrder; // BeginTabItem() order, used to re-order tabs after toggling ImGuiTabBarFlags_Reorderable ImS16 IndexDuringLayout; // Index only used during TabBarLayout() @@ -2457,6 +2566,15 @@ struct ImGuiTableCellData ImGuiTableColumnIdx Column; // Column number }; +// Per-instance data that needs preserving across frames (seemingly most others do not need to be preserved aside from debug needs, does that needs they could be moved to ImGuiTableTempData ?) +struct ImGuiTableInstanceData +{ + float LastOuterHeight; // Outer height from last frame // FIXME: multi-instance issue (#3955) + float LastFirstRowHeight; // Height of first row from last frame // FIXME: possible multi-instance issue? + + ImGuiTableInstanceData() { LastOuterHeight = LastFirstRowHeight = 0.0f; } +}; + // FIXME-TABLE: more transient data could be stored in a per-stacked table structure: DrawSplitter, SortSpecs, incoming RowData struct IMGUI_API ImGuiTable { @@ -2499,11 +2617,10 @@ struct IMGUI_API ImGuiTable float CellPaddingY; float CellSpacingX1; // Spacing between non-bordered cells float CellSpacingX2; - float LastOuterHeight; // Outer height from last frame - float LastFirstRowHeight; // Height of first row from last frame float InnerWidth; // User value passed to BeginTable(), see comments at the top of BeginTable() for details. float ColumnsGivenWidth; // Sum of current column width float ColumnsAutoFitWidth; // Sum of ideal column width in order nothing to be clipped, used for auto-fitting and content width submission in outer window + float ColumnsStretchSumWeights; // Sum of weight of all enabled stretching columns float ResizedColumnNextWidth; float ResizeLockMinContentsX2; // Lock minimum contents width while resizing down in order to not create feedback loops. But we allow growing the table. float RefScale; // Reference scale to be able to rescale columns on font/dpi changes. @@ -2511,7 +2628,7 @@ struct IMGUI_API ImGuiTable ImRect InnerRect; // InnerRect but without decoration. As with OuterRect, for non-scrolling tables, InnerRect.Max.y is ImRect WorkRect; ImRect InnerClipRect; - ImRect BgClipRect; // We use this to cpu-clip cell background color fill + ImRect BgClipRect; // We use this to cpu-clip cell background color fill, evolve during the frame as we cross frozen rows boundaries ImRect Bg0ClipRectForDrawCmd; // Actual ImDrawCmd clip rect for BG0/1 channel. This tends to be == OuterWindow->ClipRect at BeginTable() because output in BG0/BG1 is cpu-clipped ImRect Bg2ClipRectForDrawCmd; // Actual ImDrawCmd clip rect for BG2 channel. This tends to be a correct, tight-fit, because output to BG2 are done by widgets relying on regular ClipRect. ImRect HostClipRect; // This is used to check if we can eventually merge our columns draw calls into the current draw call of the current window. @@ -2520,6 +2637,8 @@ struct IMGUI_API ImGuiTable ImGuiWindow* InnerWindow; // Window holding the table data (== OuterWindow or a child window) ImGuiTextBuffer ColumnsNames; // Contiguous buffer holding columns names ImDrawListSplitter* DrawSplitter; // Shortcut to TempData->DrawSplitter while in table. Isolate draw commands per columns to avoid switching clip rect constantly + ImGuiTableInstanceData InstanceDataFirst; + ImVector InstanceDataExtra; // FIXME-OPT: Using a small-vector pattern would be good. ImGuiTableColumnSortSpecs SortSpecsSingle; ImVector SortSpecsMulti; // FIXME-OPT: Using a small-vector pattern would be good. ImGuiTableSortSpecs SortSpecs; // Public facing sorts specs, this is what we return in TableGetSortSpecs() @@ -2674,10 +2793,11 @@ namespace ImGui inline ImDrawList* GetForegroundDrawList(ImGuiWindow* window) { return GetForegroundDrawList(window->Viewport); } // Init - IMGUI_API void Initialize(ImGuiContext* context); - IMGUI_API void Shutdown(ImGuiContext* context); // Since 1.60 this is a _private_ function. You can call DestroyContext() to destroy the context created by CreateContext(). + IMGUI_API void Initialize(); + IMGUI_API void Shutdown(); // Since 1.60 this is a _private_ function. You can call DestroyContext() to destroy the context created by CreateContext(). // NewFrame + IMGUI_API void UpdateInputEvents(bool trickle_fast_inputs); IMGUI_API void UpdateHoveredWindowAndCaptureFlags(); IMGUI_API void StartMouseMovingWindow(ImGuiWindow* window); IMGUI_API void StartMouseMovingWindowOrNode(ImGuiWindow* window, ImGuiDockNode* node, bool undock_floating_node); @@ -2693,8 +2813,10 @@ namespace ImGui IMGUI_API void TranslateWindowsInViewport(ImGuiViewportP* viewport, const ImVec2& old_pos, const ImVec2& new_pos); IMGUI_API void ScaleWindowsInViewport(ImGuiViewportP* viewport, float scale); IMGUI_API void DestroyPlatformWindow(ImGuiViewportP* viewport); + IMGUI_API void SetWindowViewport(ImGuiWindow* window, ImGuiViewportP* viewport); IMGUI_API void SetCurrentViewport(ImGuiWindow* window, ImGuiViewportP* viewport); - IMGUI_API const ImGuiPlatformMonitor* GetViewportPlatformMonitor(ImGuiViewport* viewport); + IMGUI_API const ImGuiPlatformMonitor* GetViewportPlatformMonitor(ImGuiViewport* viewport); + IMGUI_API ImGuiViewportP* FindHoveredViewportFromPlatformWindowStack(const ImVec2& mouse_platform_pos); // Settings IMGUI_API void MarkIniSettingsDirty(); @@ -2703,6 +2825,8 @@ namespace ImGui IMGUI_API ImGuiWindowSettings* CreateNewWindowSettings(const char* name); IMGUI_API ImGuiWindowSettings* FindWindowSettings(ImGuiID id); IMGUI_API ImGuiWindowSettings* FindOrCreateWindowSettings(const char* name); + IMGUI_API void AddSettingsHandler(const ImGuiSettingsHandler* handler); + IMGUI_API void RemoveSettingsHandler(const char* type_name); IMGUI_API ImGuiSettingsHandler* FindSettingsHandler(const char* type_name); // Scrolling @@ -2738,7 +2862,7 @@ namespace ImGui // Basic Helpers for widget code IMGUI_API void ItemSize(const ImVec2& size, float text_baseline_y = -1.0f); - IMGUI_API void ItemSize(const ImRect& bb, float text_baseline_y = -1.0f); + inline void ItemSize(const ImRect& bb, float text_baseline_y = -1.0f) { ItemSize(bb.GetSize(), text_baseline_y); } // FIXME: This is a misleading API since we expect CursorPos to be bb.Min. IMGUI_API bool ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb = NULL, ImGuiItemFlags extra_flags = 0); IMGUI_API bool ItemHoverable(const ImRect& bb, ImGuiID id); IMGUI_API bool IsClippedEx(const ImRect& bb, ImGuiID id); @@ -2754,17 +2878,6 @@ namespace ImGui IMGUI_API void PushItemFlag(ImGuiItemFlags option, bool enabled); IMGUI_API void PopItemFlag(); -#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - // Currently refactoring focus/nav/tabbing system - // If you have old/custom copy-and-pasted widgets that used FocusableItemRegister(): - // (Old) IMGUI_VERSION_NUM < 18209: using 'ItemAdd(....)' and 'bool tab_focused = FocusableItemRegister(...)' - // (Old) IMGUI_VERSION_NUM >= 18209: using 'ItemAdd(..., ImGuiItemAddFlags_Focusable)' and 'bool tab_focused = (GetItemStatusFlags() & ImGuiItemStatusFlags_Focused) != 0' - // (New) IMGUI_VERSION_NUM >= 18413: using 'ItemAdd(..., ImGuiItemFlags_Inputable)' and 'bool tab_focused = (GetItemStatusFlags() & ImGuiItemStatusFlags_FocusedTabbing) != 0 || g.NavActivateInputId == id' (WIP) - // Widget code are simplified as there's no need to call FocusableItemUnregister() while managing the transition from regular widget to TempInputText() - inline bool FocusableItemRegister(ImGuiWindow* window, ImGuiID id) { IM_ASSERT(0); IM_UNUSED(window); IM_UNUSED(id); return false; } // -> pass ImGuiItemAddFlags_Inputable flag to ItemAdd() - inline void FocusableItemUnregister(ImGuiWindow* window) { IM_ASSERT(0); IM_UNUSED(window); } // -> unnecessary: TempInputText() uses ImGuiInputTextFlags_MergedItem -#endif - // Logging/Capture IMGUI_API void LogBegin(ImGuiLogType type, int auto_open_depth); // -> BeginCapture() when we design v2 api, for now stay under the radar by using the old name. IMGUI_API void LogToBuffer(int auto_open_depth = -1); // Start logging/capturing to internal buffer @@ -2806,10 +2919,8 @@ namespace ImGui IMGUI_API void NavMoveRequestCancel(); IMGUI_API void NavMoveRequestApplyResult(); IMGUI_API void NavMoveRequestTryWrapping(ImGuiWindow* window, ImGuiNavMoveFlags move_flags); - IMGUI_API float GetNavInputAmount(ImGuiNavInput n, ImGuiInputReadMode mode); - IMGUI_API ImVec2 GetNavInputAmount2d(ImGuiNavDirSourceFlags dir_sources, ImGuiInputReadMode mode, float slow_factor = 0.0f, float fast_factor = 0.0f); - IMGUI_API int CalcTypematicRepeatAmount(float t0, float t1, float repeat_delay, float repeat_rate); IMGUI_API void ActivateItem(ImGuiID id); // Remotely activate a button, checkbox, tree node etc. given its unique ID. activation is queued and processed on the next frame when the item is encountered again. + IMGUI_API void SetNavWindow(ImGuiWindow* window); IMGUI_API void SetNavID(ImGuiID id, ImGuiNavLayer nav_layer, ImGuiID focus_scope_id, const ImRect& rect_rel); // Focus Scope (WIP) @@ -2822,16 +2933,28 @@ namespace ImGui // Inputs // FIXME: Eventually we should aim to move e.g. IsActiveIdUsingKey() into IsKeyXXX functions. + inline bool IsNamedKey(ImGuiKey key) { return key >= ImGuiKey_NamedKey_BEGIN && key < ImGuiKey_NamedKey_END; } + inline bool IsLegacyKey(ImGuiKey key) { return key >= ImGuiKey_LegacyNativeKey_BEGIN && key < ImGuiKey_LegacyNativeKey_END; } + inline bool IsGamepadKey(ImGuiKey key) { return key >= ImGuiKey_Gamepad_BEGIN && key < ImGuiKey_Gamepad_END; } + inline bool IsAliasKey(ImGuiKey key) { return key >= ImGuiKey_Aliases_BEGIN && key < ImGuiKey_Aliases_END; } + IMGUI_API ImGuiKeyData* GetKeyData(ImGuiKey key); + IMGUI_API void GetKeyChordName(ImGuiModFlags mods, ImGuiKey key, char* out_buf, int out_buf_size); IMGUI_API void SetItemUsingMouseWheel(); IMGUI_API void SetActiveIdUsingNavAndKeys(); inline bool IsActiveIdUsingNavDir(ImGuiDir dir) { ImGuiContext& g = *GImGui; return (g.ActiveIdUsingNavDirMask & (1 << dir)) != 0; } - inline bool IsActiveIdUsingNavInput(ImGuiNavInput input) { ImGuiContext& g = *GImGui; return (g.ActiveIdUsingNavInputMask & (1 << input)) != 0; } - inline bool IsActiveIdUsingKey(ImGuiKey key) { ImGuiContext& g = *GImGui; IM_ASSERT(key < 64); return (g.ActiveIdUsingKeyInputMask & ((ImU64)1 << key)) != 0; } + inline bool IsActiveIdUsingKey(ImGuiKey key) { ImGuiContext& g = *GImGui; return g.ActiveIdUsingKeyInputMask[key]; } + inline void SetActiveIdUsingKey(ImGuiKey key) { ImGuiContext& g = *GImGui; g.ActiveIdUsingKeyInputMask.SetBit(key); } + inline ImGuiKey MouseButtonToKey(ImGuiMouseButton button) { IM_ASSERT(button >= 0 && button < ImGuiMouseButton_COUNT); return ImGuiKey_MouseLeft + button; } IMGUI_API bool IsMouseDragPastThreshold(ImGuiMouseButton button, float lock_threshold = -1.0f); - inline bool IsKeyPressedMap(ImGuiKey key, bool repeat = true) { ImGuiContext& g = *GImGui; const int key_index = g.IO.KeyMap[key]; return (key_index >= 0) ? IsKeyPressed(key_index, repeat) : false; } - inline bool IsNavInputDown(ImGuiNavInput n) { ImGuiContext& g = *GImGui; return g.IO.NavInputs[n] > 0.0f; } - inline bool IsNavInputTest(ImGuiNavInput n, ImGuiInputReadMode rm) { return (GetNavInputAmount(n, rm) > 0.0f); } - IMGUI_API ImGuiKeyModFlags GetMergedKeyModFlags(); + IMGUI_API ImGuiModFlags GetMergedModFlags(); + IMGUI_API ImVec2 GetKeyVector2d(ImGuiKey key_left, ImGuiKey key_right, ImGuiKey key_up, ImGuiKey key_down); + IMGUI_API float GetNavTweakPressedAmount(ImGuiAxis axis); + IMGUI_API int CalcTypematicRepeatAmount(float t0, float t1, float repeat_delay, float repeat_rate); + IMGUI_API void GetTypematicRepeatRate(ImGuiInputFlags flags, float* repeat_delay, float* repeat_rate); + IMGUI_API bool IsKeyPressedEx(ImGuiKey key, ImGuiInputFlags flags = 0); +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO + inline bool IsKeyPressedMap(ImGuiKey key, bool repeat = true) { IM_ASSERT(IsNamedKey(key)); return IsKeyPressed(key, repeat); } // [removed in 1.87] +#endif // Docking // (some functions are only declared in imgui.cpp, see Docking section) @@ -2847,6 +2970,7 @@ namespace ImGui IMGUI_API void DockContextQueueUndockWindow(ImGuiContext* ctx, ImGuiWindow* window); IMGUI_API void DockContextQueueUndockNode(ImGuiContext* ctx, ImGuiDockNode* node); IMGUI_API bool DockContextCalcDropPosForDocking(ImGuiWindow* target, ImGuiDockNode* target_node, ImGuiWindow* payload, ImGuiDir split_dir, bool split_outer, ImVec2* out_pos); + IMGUI_API ImGuiDockNode*DockContextFindNodeByID(ImGuiContext* ctx, ImGuiID id); IMGUI_API bool DockNodeBeginAmendTabBar(ImGuiDockNode* node); IMGUI_API void DockNodeEndAmendTabBar(); inline ImGuiDockNode* DockNodeGetRootNode(ImGuiDockNode* node) { while (node->ParentNode) node = node->ParentNode; return node; } @@ -2885,6 +3009,7 @@ namespace ImGui IMGUI_API void DockBuilderFinish(ImGuiID node_id); // Drag and Drop + IMGUI_API bool IsDragDropActive(); IMGUI_API bool BeginDragDropTargetCustom(const ImRect& bb, ImGuiID id); IMGUI_API void ClearDragDrop(); IMGUI_API bool IsDragDropPayloadBeingAccepted(); @@ -2922,7 +3047,9 @@ namespace ImGui IMGUI_API void TableUpdateColumnsWeightFromWidth(ImGuiTable* table); IMGUI_API void TableDrawBorders(ImGuiTable* table); IMGUI_API void TableDrawContextMenu(ImGuiTable* table); + IMGUI_API bool TableBeginContextMenuPopup(ImGuiTable* table); IMGUI_API void TableMergeDrawChannels(ImGuiTable* table); + inline ImGuiTableInstanceData* TableGetInstanceData(ImGuiTable* table, int instance_no) { if (instance_no == 0) return &table->InstanceDataFirst; return &table->InstanceDataExtra[instance_no - 1]; } IMGUI_API void TableSortSpecsSanitize(ImGuiTable* table); IMGUI_API void TableSortSpecsBuild(ImGuiTable* table); IMGUI_API ImGuiSortDirection TableGetColumnNextSortDirection(ImGuiTableColumn* column); @@ -2948,7 +3075,7 @@ namespace ImGui IMGUI_API void TableSaveSettings(ImGuiTable* table); IMGUI_API void TableResetSettings(ImGuiTable* table); IMGUI_API ImGuiTableSettings* TableGetBoundSettings(ImGuiTable* table); - IMGUI_API void TableSettingsInstallHandler(ImGuiContext* context); + IMGUI_API void TableSettingsAddSettingsHandler(); IMGUI_API ImGuiTableSettings* TableSettingsCreate(ImGuiID id, int columns_count); IMGUI_API ImGuiTableSettings* TableSettingsFindByID(ImGuiID id); @@ -2980,24 +3107,18 @@ namespace ImGui IMGUI_API void RenderColorRectWithAlphaCheckerboard(ImDrawList* draw_list, ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, float grid_step, ImVec2 grid_off, float rounding = 0.0f, ImDrawFlags flags = 0); IMGUI_API void RenderNavHighlight(const ImRect& bb, ImGuiID id, ImGuiNavHighlightFlags flags = ImGuiNavHighlightFlags_TypeDefault); // Navigation highlight IMGUI_API const char* FindRenderedTextEnd(const char* text, const char* text_end = NULL); // Find the optional ## from which we stop displaying text. + IMGUI_API void RenderMouseCursor(ImVec2 pos, float scale, ImGuiMouseCursor mouse_cursor, ImU32 col_fill, ImU32 col_border, ImU32 col_shadow); // Render helpers (those functions don't access any ImGui state!) IMGUI_API void RenderArrow(ImDrawList* draw_list, ImVec2 pos, ImU32 col, ImGuiDir dir, float scale = 1.0f); IMGUI_API void RenderBullet(ImDrawList* draw_list, ImVec2 pos, ImU32 col); IMGUI_API void RenderCheckMark(ImDrawList* draw_list, ImVec2 pos, ImU32 col, float sz); - IMGUI_API void RenderMouseCursor(ImDrawList* draw_list, ImVec2 pos, float scale, ImGuiMouseCursor mouse_cursor, ImU32 col_fill, ImU32 col_border, ImU32 col_shadow); IMGUI_API void RenderArrowPointingAt(ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, ImGuiDir direction, ImU32 col); IMGUI_API void RenderArrowDockMenu(ImDrawList* draw_list, ImVec2 p_min, float sz, ImU32 col); IMGUI_API void RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, ImU32 col, float x_start_norm, float x_end_norm, float rounding); - IMGUI_API void RenderRectFilledWithHole(ImDrawList* draw_list, ImRect outer, ImRect inner, ImU32 col, float rounding); + IMGUI_API void RenderRectFilledWithHole(ImDrawList* draw_list, const ImRect& outer, const ImRect& inner, ImU32 col, float rounding); IMGUI_API ImDrawFlags CalcRoundingFlagsForRectInRect(const ImRect& r_in, const ImRect& r_outer, float threshold); -#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS - // [1.71: 2019/06/07: Updating prototypes of some of the internal functions. Leaving those for reference for a short while] - inline void RenderArrow(ImVec2 pos, ImGuiDir dir, float scale=1.0f) { ImGuiWindow* window = GetCurrentWindow(); RenderArrow(window->DrawList, pos, GetColorU32(ImGuiCol_Text), dir, scale); } - inline void RenderBullet(ImVec2 pos) { ImGuiWindow* window = GetCurrentWindow(); RenderBullet(window->DrawList, pos, GetColorU32(ImGuiCol_Text)); } -#endif - // Widgets IMGUI_API void TextEx(const char* text, const char* text_end = NULL, ImGuiTextFlags flags = 0); IMGUI_API bool ButtonEx(const char* label, const ImVec2& size_arg = ImVec2(0, 0), ImGuiButtonFlags flags = 0); @@ -3021,8 +3142,9 @@ namespace ImGui IMGUI_API bool SliderBehavior(const ImRect& bb, ImGuiID id, ImGuiDataType data_type, void* p_v, const void* p_min, const void* p_max, const char* format, ImGuiSliderFlags flags, ImRect* out_grab_bb); IMGUI_API bool SplitterBehavior(const ImRect& bb, ImGuiID id, ImGuiAxis axis, float* size1, float* size2, float min_size1, float min_size2, float hover_extend = 0.0f, float hover_visibility_delay = 0.0f, ImU32 bg_col = 0); IMGUI_API bool TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* label, const char* label_end = NULL); - IMGUI_API bool TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags = 0); // Consume previous SetNextItemOpen() data, if any. May return true when logging IMGUI_API void TreePushOverrideID(ImGuiID id); + IMGUI_API void TreeNodeSetOpen(ImGuiID id, bool open); + IMGUI_API bool TreeNodeUpdateNextOpen(ImGuiID id, ImGuiTreeNodeFlags flags); // Return open state. Consume previous SetNextItemOpen() data, if any. May return true when logging. // Template functions are instantiated in imgui_widgets.cpp for a finite number of types. // To use them externally (for custom widget) you may need an "extern template" statement in your code in order to link to existing instances and silence Clang warnings (see #2036). @@ -3031,14 +3153,14 @@ namespace ImGui template IMGUI_API T ScaleValueFromRatioT(ImGuiDataType data_type, float t, T v_min, T v_max, bool is_logarithmic, float logarithmic_zero_epsilon, float zero_deadzone_size); template IMGUI_API bool DragBehaviorT(ImGuiDataType data_type, T* v, float v_speed, T v_min, T v_max, const char* format, ImGuiSliderFlags flags); template IMGUI_API bool SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_type, T* v, T v_min, T v_max, const char* format, ImGuiSliderFlags flags, ImRect* out_grab_bb); - template IMGUI_API T RoundScalarWithFormatT(const char* format, ImGuiDataType data_type, T v); + template IMGUI_API T RoundScalarWithFormatT(const char* format, ImGuiDataType data_type, T v); template IMGUI_API bool CheckboxFlagsT(const char* label, T* flags, T flags_value); // Data type helpers IMGUI_API const ImGuiDataTypeInfo* DataTypeGetInfo(ImGuiDataType data_type); IMGUI_API int DataTypeFormatString(char* buf, int buf_size, ImGuiDataType data_type, const void* p_data, const char* format); IMGUI_API void DataTypeApplyOp(ImGuiDataType data_type, int op, void* output, const void* arg_1, const void* arg_2); - IMGUI_API bool DataTypeApplyOpFromText(const char* buf, const char* initial_value_buf, ImGuiDataType data_type, void* p_data, const char* format); + IMGUI_API bool DataTypeApplyFromText(const char* buf, ImGuiDataType data_type, void* p_data, const char* format); IMGUI_API int DataTypeCompare(ImGuiDataType data_type, const void* arg_1, const void* arg_2); IMGUI_API bool DataTypeClamp(ImGuiDataType data_type, void* p_data, const void* p_min, const void* p_max); @@ -3047,7 +3169,7 @@ namespace ImGui IMGUI_API bool TempInputText(const ImRect& bb, ImGuiID id, const char* label, char* buf, int buf_size, ImGuiInputTextFlags flags); IMGUI_API bool TempInputScalar(const ImRect& bb, ImGuiID id, const char* label, ImGuiDataType data_type, void* p_data, const char* format, const void* p_clamp_min = NULL, const void* p_clamp_max = NULL); inline bool TempInputIsActive(ImGuiID id) { ImGuiContext& g = *GImGui; return (g.ActiveId == id && g.TempInputId == id); } - inline ImGuiInputTextState* GetInputTextState(ImGuiID id) { ImGuiContext& g = *GImGui; return (g.InputTextState.ID == id) ? &g.InputTextState : NULL; } // Get input text state if active + inline ImGuiInputTextState* GetInputTextState(ImGuiID id) { ImGuiContext& g = *GImGui; return (id != 0 && g.InputTextState.ID == id) ? &g.InputTextState : NULL; } // Get input text state if active // Color IMGUI_API void ColorTooltip(const char* text, const float* col, ImGuiColorEditFlags flags); @@ -3066,12 +3188,15 @@ namespace ImGui IMGUI_API void GcCompactTransientWindowBuffers(ImGuiWindow* window); IMGUI_API void GcAwakeTransientWindowBuffers(ImGuiWindow* window); + // Debug Log + IMGUI_API void DebugLog(const char* fmt, ...) IM_FMTARGS(1); + IMGUI_API void DebugLogV(const char* fmt, va_list args) IM_FMTLIST(1); + // Debug Tools IMGUI_API void ErrorCheckEndFrameRecover(ImGuiErrorLogCallback log_callback, void* user_data = NULL); IMGUI_API void ErrorCheckEndWindowRecover(ImGuiErrorLogCallback log_callback, void* user_data = NULL); inline void DebugDrawItemRect(ImU32 col = IM_COL32(255,0,0,255)) { ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; GetForegroundDrawList(window)->AddRect(g.LastItemData.Rect.Min, g.LastItemData.Rect.Max, col); } inline void DebugStartItemPicker() { ImGuiContext& g = *GImGui; g.DebugItemPickerActive = true; } - IMGUI_API void ShowFontAtlas(ImFontAtlas* atlas); IMGUI_API void DebugHookIdInfo(ImGuiID id, ImGuiDataType data_type, const void* data_id, const void* data_id_end); IMGUI_API void DebugNodeColumns(ImGuiOldColumns* columns); @@ -3079,10 +3204,12 @@ namespace ImGui IMGUI_API void DebugNodeDrawList(ImGuiWindow* window, ImGuiViewportP* viewport, const ImDrawList* draw_list, const char* label); IMGUI_API void DebugNodeDrawCmdShowMeshAndBoundingBox(ImDrawList* out_draw_list, const ImDrawList* draw_list, const ImDrawCmd* draw_cmd, bool show_mesh, bool show_aabb); IMGUI_API void DebugNodeFont(ImFont* font); + IMGUI_API void DebugNodeFontGlyph(ImFont* font, const ImFontGlyph* glyph); IMGUI_API void DebugNodeStorage(ImGuiStorage* storage, const char* label); IMGUI_API void DebugNodeTabBar(ImGuiTabBar* tab_bar, const char* label); IMGUI_API void DebugNodeTable(ImGuiTable* table); IMGUI_API void DebugNodeTableSettings(ImGuiTableSettings* settings); + IMGUI_API void DebugNodeInputTextState(ImGuiInputTextState* state); IMGUI_API void DebugNodeWindow(ImGuiWindow* window, const char* label); IMGUI_API void DebugNodeWindowSettings(ImGuiWindowSettings* settings); IMGUI_API void DebugNodeWindowsList(ImVector* windows, const char* label); @@ -3090,6 +3217,19 @@ namespace ImGui IMGUI_API void DebugNodeViewport(ImGuiViewportP* viewport); IMGUI_API void DebugRenderViewportThumbnail(ImDrawList* draw_list, ImGuiViewportP* viewport, const ImRect& bb); + // Obsolete functions +#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS + inline bool TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags = 0) { return TreeNodeUpdateNextOpen(id, flags); } // Renamed in 1.89 + + // Refactored focus/nav/tabbing system in 1.82 and 1.84. If you have old/custom copy-and-pasted widgets that used FocusableItemRegister(): + // (Old) IMGUI_VERSION_NUM < 18209: using 'ItemAdd(....)' and 'bool tab_focused = FocusableItemRegister(...)' + // (Old) IMGUI_VERSION_NUM >= 18209: using 'ItemAdd(..., ImGuiItemAddFlags_Focusable)' and 'bool tab_focused = (GetItemStatusFlags() & ImGuiItemStatusFlags_Focused) != 0' + // (New) IMGUI_VERSION_NUM >= 18413: using 'ItemAdd(..., ImGuiItemFlags_Inputable)' and 'bool tab_focused = (GetItemStatusFlags() & ImGuiItemStatusFlags_FocusedTabbing) != 0 || g.NavActivateInputId == id' (WIP) + // Widget code are simplified as there's no need to call FocusableItemUnregister() while managing the transition from regular widget to TempInputText() + inline bool FocusableItemRegister(ImGuiWindow* window, ImGuiID id) { IM_ASSERT(0); IM_UNUSED(window); IM_UNUSED(id); return false; } // -> pass ImGuiItemAddFlags_Inputable flag to ItemAdd() + inline void FocusableItemUnregister(ImGuiWindow* window) { IM_ASSERT(0); IM_UNUSED(window); } // -> unnecessary: TempInputText() uses ImGuiInputTextFlags_MergedItem +#endif + } // namespace ImGui @@ -3104,7 +3244,9 @@ struct ImFontBuilderIO }; // Helper for font builder +#ifdef IMGUI_ENABLE_STB_TRUETYPE IMGUI_API const ImFontBuilderIO* ImFontAtlasGetBuilderForStbTruetype(); +#endif IMGUI_API void ImFontAtlasBuildInit(ImFontAtlas* atlas); IMGUI_API void ImFontAtlasBuildSetupFont(ImFontAtlas* atlas, ImFont* font, ImFontConfig* font_config, float ascent, float descent); IMGUI_API void ImFontAtlasBuildPackCustomRects(ImFontAtlas* atlas, void* stbrp_context_opaque); @@ -3128,7 +3270,8 @@ extern const char* ImGuiTestEngine_FindItemDebugLabel(ImGuiContext* ctx, ImGuiI #define IMGUI_TEST_ENGINE_ITEM_INFO(_ID,_LABEL,_FLAGS) if (g.TestEngineHookItems) ImGuiTestEngineHook_ItemInfo(&g, _ID, _LABEL, _FLAGS) // Register item label and status flags (optional) #define IMGUI_TEST_ENGINE_LOG(_FMT,...) if (g.TestEngineHookItems) ImGuiTestEngineHook_Log(&g, _FMT, __VA_ARGS__) // Custom log entry from user land into test log #else -#define IMGUI_TEST_ENGINE_ITEM_INFO(_ID,_LABEL,_FLAGS) ((void)0) +#define IMGUI_TEST_ENGINE_ITEM_ADD(_BB,_ID) ((void)0) +#define IMGUI_TEST_ENGINE_ITEM_INFO(_ID,_LABEL,_FLAGS) ((void)g) #endif //----------------------------------------------------------------------------- diff --git a/lib/external/imgui/include/imnodes.h b/lib/external/imgui/include/imnodes.h index edabdbf2d..15ad5ed96 100644 --- a/lib/external/imgui/include/imnodes.h +++ b/lib/external/imgui/include/imnodes.h @@ -1,6 +1,15 @@ #pragma once #include +#include + +#ifdef IMNODES_USER_CONFIG +#include IMNODES_USER_CONFIG +#endif + +#ifndef IMNODES_NAMESPACE +#define IMNODES_NAMESPACE ImNodes +#endif typedef int ImNodesCol; // -> enum ImNodesCol_ typedef int ImNodesStyleVar; // -> enum ImNodesStyleVar_ @@ -27,6 +36,7 @@ enum ImNodesCol_ ImNodesCol_BoxSelectorOutline, ImNodesCol_GridBackground, ImNodesCol_GridLine, + ImNodesCol_GridLinePrimary, ImNodesCol_MiniMapBackground, ImNodesCol_MiniMapBackgroundHovered, ImNodesCol_MiniMapOutline, @@ -37,6 +47,8 @@ enum ImNodesCol_ ImNodesCol_MiniMapNodeOutline, ImNodesCol_MiniMapLink, ImNodesCol_MiniMapLinkSelected, + ImNodesCol_MiniMapCanvas, + ImNodesCol_MiniMapCanvasOutline, ImNodesCol_COUNT }; @@ -44,8 +56,7 @@ enum ImNodesStyleVar_ { ImNodesStyleVar_GridSpacing = 0, ImNodesStyleVar_NodeCornerRounding, - ImNodesStyleVar_NodePaddingHorizontal, - ImNodesStyleVar_NodePaddingVertical, + ImNodesStyleVar_NodePadding, ImNodesStyleVar_NodeBorderThickness, ImNodesStyleVar_LinkThickness, ImNodesStyleVar_LinkLineSegmentsPerLength, @@ -55,14 +66,19 @@ enum ImNodesStyleVar_ ImNodesStyleVar_PinTriangleSideLength, ImNodesStyleVar_PinLineThickness, ImNodesStyleVar_PinHoverRadius, - ImNodesStyleVar_PinOffset + ImNodesStyleVar_PinOffset, + ImNodesStyleVar_MiniMapPadding, + ImNodesStyleVar_MiniMapOffset, + ImNodesStyleVar_COUNT }; enum ImNodesStyleFlags_ { ImNodesStyleFlags_None = 0, ImNodesStyleFlags_NodeOutline = 1 << 0, - ImNodesStyleFlags_GridLines = 1 << 2 + ImNodesStyleFlags_GridLines = 1 << 2, + ImNodesStyleFlags_GridLinesPrimary = 1 << 3, + ImNodesStyleFlags_GridSnapping = 1 << 4 }; enum ImNodesPinShape_ @@ -121,10 +137,28 @@ struct ImNodesIO const bool* Modifier; } LinkDetachWithModifierClick; + struct MultipleSelectModifier + { + MultipleSelectModifier(); + + // Pointer to a boolean value indicating when the desired modifier is pressed. Set to NULL + // by default. To enable the feature, set the modifier to point to a boolean indicating the + // state of a modifier. For example, + // + // ImNodes::GetIO().MultipleSelectModifier.Modifier = &ImGui::GetIO().KeyCtrl; + // + // Left-clicking a node with this modifier pressed will add the node to the list of + // currently selected nodes. If this value is NULL, the Ctrl key will be used. + const bool* Modifier; + } MultipleSelectModifier; + // Holding alt mouse button pans the node area, by default middle mouse button will be used // Set based on ImGuiMouseButton values int AltMouseButton; + // Panning speed when dragging an element and mouse is outside the main editor view. + float AutoPanningSpeed; + ImNodesIO(); }; @@ -132,10 +166,9 @@ struct ImNodesStyle { float GridSpacing; - float NodeCornerRounding; - float NodePaddingHorizontal; - float NodePaddingVertical; - float NodeBorderThickness; + float NodeCornerRounding; + ImVec2 NodePadding; + float NodeBorderThickness; float LinkThickness; float LinkLineSegmentsPerLength; @@ -161,6 +194,11 @@ struct ImNodesStyle // Offsets the pins' positions from the edge of the node to the outside of the node. float PinOffset; + // Mini-map padding size between mini-map edge and mini-map content. + ImVec2 MiniMapPadding; + // Mini-map offset from the screen side. + ImVec2 MiniMapOffset; + // By default, ImNodesStyleFlags_NodeOutline and ImNodesStyleFlags_Gridlines are enabled. ImNodesStyleFlags Flags; // Set these mid-frame using Push/PopColorStyle. You can index this color array with with a @@ -191,9 +229,15 @@ struct ImNodesContext; struct ImNodesEditorContext; // Callback type used to specify special behavior when hovering a node in the minimap +#ifndef ImNodesMiniMapNodeHoveringCallback typedef void (*ImNodesMiniMapNodeHoveringCallback)(int, void*); +#endif -namespace ImNodes +#ifndef ImNodesMiniMapNodeHoveringCallbackUserData +typedef void* ImNodesMiniMapNodeHoveringCallbackUserData; +#endif + +namespace IMNODES_NAMESPACE { // Call this function if you are compiling imnodes in to a dll, separate from ImGui. Calling this // function sets the GImGui global variable, which is not shared across dll boundaries. @@ -215,10 +259,11 @@ ImNodesIO& GetIO(); // Returns the global style struct. See the struct declaration for default values. ImNodesStyle& GetStyle(); -// Style presets matching the dear imgui styles of the same name. -void StyleColorsDark(); // on by default -void StyleColorsClassic(); -void StyleColorsLight(); +// Style presets matching the dear imgui styles of the same name. If dest is NULL, the active +// context's ImNodesStyle instance will be used as the destination. +void StyleColorsDark(ImNodesStyle* dest = NULL); // on by default +void StyleColorsClassic(ImNodesStyle* dest = NULL); +void StyleColorsLight(ImNodesStyle* dest = NULL); // The top-level function call. Call this before calling BeginNode/EndNode. Calling this function // will result the node editor grid workspace being rendered. @@ -228,16 +273,17 @@ void EndNodeEditor(); // Add a navigable minimap to the editor; call before EndNodeEditor after all // nodes and links have been specified void MiniMap( - const float minimap_size_fraction = 0.2f, - const ImNodesMiniMapLocation location = ImNodesMiniMapLocation_TopLeft, - const ImNodesMiniMapNodeHoveringCallback node_hovering_callback = NULL, - void* node_hovering_callback_data = NULL); + const float minimap_size_fraction = 0.2f, + const ImNodesMiniMapLocation location = ImNodesMiniMapLocation_TopLeft, + const ImNodesMiniMapNodeHoveringCallback node_hovering_callback = NULL, + const ImNodesMiniMapNodeHoveringCallbackUserData node_hovering_callback_data = NULL); // Use PushColorStyle and PopColorStyle to modify ImNodesStyle::Colors mid-frame. void PushColorStyle(ImNodesCol item, unsigned int color); void PopColorStyle(); void PushStyleVar(ImNodesStyleVar style_item, float value); -void PopStyleVar(); +void PushStyleVar(ImNodesStyleVar style_item, const ImVec2& value); +void PopStyleVar(int count = 1); // id can be any positive or negative integer, but INT_MIN is currently reserved for internal use. void BeginNode(int id); @@ -301,6 +347,9 @@ ImVec2 GetNodeScreenSpacePos(const int node_id); ImVec2 GetNodeEditorSpacePos(const int node_id); ImVec2 GetNodeGridSpacePos(const int node_id); +// If ImNodesStyleFlags_GridSnapping is enabled, snap the specified node's origin to the grid. +void SnapNodeToGrid(int node_id); + // Returns true if the current node editor canvas is being hovered over by the mouse, and is not // blocked by any other windows. bool IsEditorHovered(); @@ -386,4 +435,4 @@ void SaveEditorStateToIniFile(const ImNodesEditorContext* editor, const char* fi void LoadCurrentEditorStateFromIniFile(const char* file_name); void LoadEditorStateFromIniFile(ImNodesEditorContext* editor, const char* file_name); -} // namespace ImNodes +} // namespace IMNODES_NAMESPACE diff --git a/lib/external/imgui/include/imnodes_internal.h b/lib/external/imgui/include/imnodes_internal.h index 6a2162820..593ab4997 100644 --- a/lib/external/imgui/include/imnodes_internal.h +++ b/lib/external/imgui/include/imnodes_internal.h @@ -1,10 +1,11 @@ #pragma once +#include "imnodes.h" + #include #define IMGUI_DEFINE_MATH_OPERATORS #include -#include #include // the structure of this file: @@ -56,9 +57,6 @@ enum ImNodesClickInteractionType_ ImNodesClickInteractionType_LinkCreation, ImNodesClickInteractionType_Panning, ImNodesClickInteractionType_BoxSelection, - ImNodesClickInteractionType_MiniMapPanning, - ImNodesClickInteractionType_MiniMapZooming, - ImNodesClickInteractionType_MiniMapSnapping, ImNodesClickInteractionType_ImGuiItem, ImNodesClickInteractionType_None }; @@ -69,9 +67,6 @@ enum ImNodesLinkCreationType_ ImNodesLinkCreationType_FromDetach }; -// Callback type used to specify special behavior when hovering a node in the minimap -typedef void (*ImNodesMiniMapNodeHoveringCallback)(int, void*); - // [SECTION] internal data structures // The object T must have the following interface: @@ -105,7 +100,7 @@ struct ImOptionalIndex inline int Value() const { - assert(HasValue()); + IM_ASSERT(HasValue()); return _Index; } @@ -157,7 +152,7 @@ struct ImNodeData bool Draggable; ImNodeData(const int node_id) - : Id(node_id), Origin(100.0f, 100.0f), TitleBarContentRect(), + : Id(node_id), Origin(0.0f, 0.0f), TitleBarContentRect(), Rect(ImVec2(0.0f, 0.0f), ImVec2(0.0f, 0.0f)), ColorStyle(), LayoutStyle(), PinIndices(), Draggable(true) { @@ -215,7 +210,7 @@ struct ImClickInteractionState struct { - ImRect Rect; + ImRect Rect; // Coordinates in grid space } BoxSelector; ImClickInteractionState() : Type(ImNodesClickInteractionType_None) {} @@ -232,11 +227,17 @@ struct ImNodesColElement struct ImNodesStyleVarElement { ImNodesStyleVar Item; - float Value; + float FloatValue[2]; - ImNodesStyleVarElement(const float value, const ImNodesStyleVar variable) - : Item(variable), Value(value) + ImNodesStyleVarElement(const ImNodesStyleVar variable, const float value) : Item(variable) { + FloatValue[0] = value; + } + + ImNodesStyleVarElement(const ImNodesStyleVar variable, const ImVec2 value) : Item(variable) + { + FloatValue[0] = value.x; + FloatValue[1] = value.y; } }; @@ -252,15 +253,41 @@ struct ImNodesEditorContext // ui related fields ImVec2 Panning; + ImVec2 AutoPanningDelta; + // Minimum and maximum extents of all content in grid space. Valid after final + // ImNodes::EndNode() call. + ImRect GridContentBounds; ImVector SelectedNodeIndices; ImVector SelectedLinkIndices; + // Relative origins of selected nodes for snapping of dragged nodes + ImVector SelectedNodeOffsets; + // Offset of the primary node origin relative to the mouse cursor. + ImVec2 PrimaryNodeOffset; + ImClickInteractionState ClickInteraction; + // Mini-map state set by MiniMap() + + bool MiniMapEnabled; + ImNodesMiniMapLocation MiniMapLocation; + float MiniMapSizeFraction; + ImNodesMiniMapNodeHoveringCallback MiniMapNodeHoveringCallback; + ImNodesMiniMapNodeHoveringCallbackUserData MiniMapNodeHoveringCallbackUserData; + + // Mini-map state set during EndNodeEditor() call + + ImRect MiniMapRectScreenSpace; + ImRect MiniMapContentScreenSpace; + float MiniMapScaling; + ImNodesEditorContext() : Nodes(), Pins(), Links(), Panning(0.f, 0.f), SelectedNodeIndices(), SelectedLinkIndices(), - ClickInteraction() + SelectedNodeOffsets(), PrimaryNodeOffset(0.f, 0.f), ClickInteraction(), + MiniMapEnabled(false), MiniMapSizeFraction(0.0f), + MiniMapNodeHoveringCallback(NULL), MiniMapNodeHoveringCallbackUserData(NULL), + MiniMapScaling(0.0f) { } }; @@ -281,13 +308,6 @@ struct ImNodesContext ImVec2 CanvasOriginScreenSpace; ImRect CanvasRectScreenSpace; - // MiniMap state - ImRect MiniMapRectScreenSpace; - ImVec2 MiniMapRectSnappingOffset; - float MiniMapZoom; - ImNodesMiniMapNodeHoveringCallback MiniMapNodeHoveringCallback; - void* MiniMapNodeHoveringCallbackUserData; - // Debug helpers ImNodesScope CurrentScope; @@ -331,14 +351,15 @@ struct ImNodesContext bool LeftMouseDragging; bool AltMouseDragging; float AltMouseScrollDelta; + bool MultipleSelectModifier; }; -namespace ImNodes +namespace IMNODES_NAMESPACE { static inline ImNodesEditorContext& EditorContextGet() { // No editor context was set! Did you forget to call ImNodes::CreateContext()? - assert(GImNodes->EditorCtx != NULL); + IM_ASSERT(GImNodes->EditorCtx != NULL); return *GImNodes->EditorCtx; } @@ -354,12 +375,13 @@ static inline int ObjectPoolFind(const ImObjectPool& objects, const int id) template static inline void ObjectPoolUpdate(ImObjectPool& objects) { - objects.FreeList.clear(); for (int i = 0; i < objects.InUse.size(); ++i) { - if (!objects.InUse[i]) + const int id = objects.Pool[i].Id; + + if (!objects.InUse[i] && objects.IdMap.GetInt(id, -1) == i) { - objects.IdMap.SetInt(objects.Pool[i].Id, -1); + objects.IdMap.SetInt(id, -1); objects.FreeList.push_back(i); (objects.Pool.Data + i)->~T(); } @@ -369,7 +391,6 @@ static inline void ObjectPoolUpdate(ImObjectPool& objects) template<> inline void ObjectPoolUpdate(ImObjectPool& nodes) { - nodes.FreeList.clear(); for (int i = 0; i < nodes.InUse.size(); ++i) { if (nodes.InUse[i]) @@ -378,23 +399,21 @@ inline void ObjectPoolUpdate(ImObjectPool& nodes) } else { - const int previous_id = nodes.Pool[i].Id; - const int previous_idx = nodes.IdMap.GetInt(previous_id, -1); + const int id = nodes.Pool[i].Id; - if (previous_idx != -1) + if (nodes.IdMap.GetInt(id, -1) == i) { - assert(previous_idx == i); // Remove node idx form depth stack the first time we detect that this idx slot is // unused ImVector& depth_stack = EditorContextGet().NodeDepthOrder; const int* const elem = depth_stack.find(i); - assert(elem != depth_stack.end()); + IM_ASSERT(elem != depth_stack.end()); depth_stack.erase(elem); - } - nodes.IdMap.SetInt(previous_id, -1); - nodes.FreeList.push_back(i); - (nodes.Pool.Data + i)->~ImNodeData(); + nodes.IdMap.SetInt(id, -1); + nodes.FreeList.push_back(i); + (nodes.Pool.Data + i)->~ImNodeData(); + } } } } @@ -479,4 +498,4 @@ static inline T& ObjectPoolFindOrCreateObject(ImObjectPool& objects, const in const int index = ObjectPoolFindOrCreateIndex(objects, id); return objects.Pool[index]; } -} // namespace ImNodes +} // namespace IMNODES_NAMESPACE diff --git a/lib/external/imgui/include/implot.h b/lib/external/imgui/include/implot.h index 316915bbf..07f13af1c 100644 --- a/lib/external/imgui/include/implot.h +++ b/lib/external/imgui/include/implot.h @@ -20,13 +20,35 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -// ImPlot v0.11 WIP +// ImPlot v0.13 WIP + +// Table of Contents: +// +// [SECTION] Macros and Defines +// [SECTION] Enums and Types +// [SECTION] Callbacks +// [SECTION] Contexts +// [SECTION] Begin/End Plot +// [SECTION] Begin/End Subplot +// [SECTION] Setup +// [SECTION] SetNext +// [SECTION] Plot Items +// [SECTION] Plot Tools +// [SECTION] Plot Utils +// [SECTION] Legend Utils +// [SECTION] Drag and Drop +// [SECTION] Styling +// [SECTION] Colormaps +// [SECTION] Input Mapping +// [SECTION] Miscellaneous +// [SECTION] Demo +// [SECTION] Obsolete API #pragma once #include "imgui.h" //----------------------------------------------------------------------------- -// Macros and Defines +// [SECTION] Macros and Defines //----------------------------------------------------------------------------- // Define attributes of all API symbols declarations (e.g. for DLL under Windows) @@ -37,70 +59,92 @@ #define IMPLOT_API #endif -// ImPlot version string -#define IMPLOT_VERSION "0.11 WIP" +// ImPlot version string. +#define IMPLOT_VERSION "0.13 WIP" // Indicates variable should deduced automatically. #define IMPLOT_AUTO -1 // Special color used to indicate that a color should be deduced automatically. #define IMPLOT_AUTO_COL ImVec4(0,0,0,-1) +// Macro for templated plotting functions; keeps header clean. +#define IMPLOT_TMP template IMPLOT_API //----------------------------------------------------------------------------- -// Forward Declarations and Basic Types +// [SECTION] Enums and Types //----------------------------------------------------------------------------- // Forward declarations -struct ImPlotContext; // ImPlot context (opaque struct, see implot_internal.h) +struct ImPlotContext; // ImPlot context (opaque struct, see implot_internal.h) // Enums/Flags -typedef int ImPlotFlags; // -> enum ImPlotFlags_ -typedef int ImPlotAxisFlags; // -> enum ImPlotAxisFlags_ -typedef int ImPlotSubplotFlags; // -> enum ImPlotSubplotFlags_ -typedef int ImPlotCol; // -> enum ImPlotCol_ -typedef int ImPlotStyleVar; // -> enum ImPlotStyleVar_ -typedef int ImPlotMarker; // -> enum ImPlotMarker_ -typedef int ImPlotColormap; // -> enum ImPlotColormap_ -typedef int ImPlotLocation; // -> enum ImPlotLocation_ -typedef int ImPlotOrientation; // -> enum ImPlotOrientation_ -typedef int ImPlotYAxis; // -> enum ImPlotYAxis_; -typedef int ImPlotBin; // -> enum ImPlotBin_ +typedef int ImAxis; // -> enum ImAxis_ +typedef int ImPlotFlags; // -> enum ImPlotFlags_ +typedef int ImPlotAxisFlags; // -> enum ImPlotAxisFlags_ +typedef int ImPlotSubplotFlags; // -> enum ImPlotSubplotFlags_ +typedef int ImPlotLegendFlags; // -> enum ImPlotLegendFlags_ +typedef int ImPlotMouseTextFlags; // -> enum ImPlotMouseTextFlags_ +typedef int ImPlotDragToolFlags; // -> ImPlotDragToolFlags_ +typedef int ImPlotBarGroupsFlags; // -> ImPlotBarGroupsFlags_ + +typedef int ImPlotCond; // -> enum ImPlotCond_ +typedef int ImPlotCol; // -> enum ImPlotCol_ +typedef int ImPlotStyleVar; // -> enum ImPlotStyleVar_ +typedef int ImPlotMarker; // -> enum ImPlotMarker_ +typedef int ImPlotColormap; // -> enum ImPlotColormap_ +typedef int ImPlotLocation; // -> enum ImPlotLocation_ +typedef int ImPlotBin; // -> enum ImPlotBin_ + +// Axis indices. The values assigned may change; NEVER hardcode these. +enum ImAxis_ { + // horizontal axes + ImAxis_X1 = 0, // enabled by default + ImAxis_X2, // disabled by default + ImAxis_X3, // disabled by default + // vertical axes + ImAxis_Y1, // enabled by default + ImAxis_Y2, // disabled by default + ImAxis_Y3, // disabled by default + // bookeeping + ImAxis_COUNT +}; // Options for plots (see BeginPlot). enum ImPlotFlags_ { ImPlotFlags_None = 0, // default ImPlotFlags_NoTitle = 1 << 0, // the plot title will not be displayed (titles are also hidden if preceeded by double hashes, e.g. "##MyPlot") ImPlotFlags_NoLegend = 1 << 1, // the legend will not be displayed - ImPlotFlags_NoMenus = 1 << 2, // the user will not be able to open context menus with right-click - ImPlotFlags_NoBoxSelect = 1 << 3, // the user will not be able to box-select with right-click drag - ImPlotFlags_NoMousePos = 1 << 4, // the mouse position, in plot coordinates, will not be displayed inside of the plot - ImPlotFlags_NoHighlight = 1 << 5, // plot items will not be highlighted when their legend entry is hovered + ImPlotFlags_NoMouseText = 1 << 2, // the mouse position, in plot coordinates, will not be displayed inside of the plot + ImPlotFlags_NoInputs = 1 << 3, // the user will not be able to interact with the plot + ImPlotFlags_NoMenus = 1 << 4, // the user will not be able to open context menus + ImPlotFlags_NoBoxSelect = 1 << 5, // the user will not be able to box-select ImPlotFlags_NoChild = 1 << 6, // a child window region will not be used to capture mouse scroll (can boost performance for single ImGui window applications) - ImPlotFlags_Equal = 1 << 7, // primary x and y axes will be constrained to have the same units/pixel (does not apply to auxiliary y-axes) - ImPlotFlags_YAxis2 = 1 << 8, // enable a 2nd y-axis on the right side - ImPlotFlags_YAxis3 = 1 << 9, // enable a 3rd y-axis on the right side - ImPlotFlags_Query = 1 << 10, // the user will be able to draw query rects with middle-mouse or CTRL + right-click drag - ImPlotFlags_Crosshairs = 1 << 11, // the default mouse cursor will be replaced with a crosshair when hovered - ImPlotFlags_AntiAliased = 1 << 12, // plot lines will be software anti-aliased (not recommended for high density plots, prefer MSAA) - ImPlotFlags_CanvasOnly = ImPlotFlags_NoTitle | ImPlotFlags_NoLegend | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect | ImPlotFlags_NoMousePos + ImPlotFlags_NoFrame = 1 << 7, // the ImGui frame will not be rendered + ImPlotFlags_Equal = 1 << 8, // x and y axes pairs will be constrained to have the same units/pixel + ImPlotFlags_Crosshairs = 1 << 9, // the default mouse cursor will be replaced with a crosshair when hovered + ImPlotFlags_AntiAliased = 1 << 10, // plot items will be software anti-aliased (not recommended for high density plots, prefer MSAA) + ImPlotFlags_CanvasOnly = ImPlotFlags_NoTitle | ImPlotFlags_NoLegend | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect | ImPlotFlags_NoMouseText }; -// Options for plot axes (see BeginPlot). +// Options for plot axes (see SetupAxis). enum ImPlotAxisFlags_ { ImPlotAxisFlags_None = 0, // default ImPlotAxisFlags_NoLabel = 1 << 0, // the axis label will not be displayed (axis labels also hidden if the supplied string name is NULL) ImPlotAxisFlags_NoGridLines = 1 << 1, // no grid lines will be displayed ImPlotAxisFlags_NoTickMarks = 1 << 2, // no tick marks will be displayed ImPlotAxisFlags_NoTickLabels = 1 << 3, // no text labels will be displayed - ImPlotAxisFlags_Foreground = 1 << 4, // grid lines will be displayed in the foreground (i.e. on top of data) in stead of the background - ImPlotAxisFlags_LogScale = 1 << 5, // a logartithmic (base 10) axis scale will be used (mutually exclusive with ImPlotAxisFlags_Time) - ImPlotAxisFlags_Time = 1 << 6, // axis will display date/time formatted labels (mutually exclusive with ImPlotAxisFlags_LogScale) - ImPlotAxisFlags_Invert = 1 << 7, // the axis will be inverted - ImPlotAxisFlags_NoInitialFit = 1 << 8, // axis will not be initially fit to data extents on the first rendered frame (also the case if SetNextPlotLimits explicitly called) - ImPlotAxisFlags_AutoFit = 1 << 9, // axis will be auto-fitting to data extents - ImPlotAxisFlags_RangeFit = 1 << 10, // axis will only fit points if the point is in the visible range of the **orthoganol** axis - ImPlotAxisFlags_LockMin = 1 << 11, // the axis minimum value will be locked when panning/zooming - ImPlotAxisFlags_LockMax = 1 << 12, // the axis maximum value will be locked when panning/zooming + ImPlotAxisFlags_NoInitialFit = 1 << 4, // axis will not be initially fit to data extents on the first rendered frame + ImPlotAxisFlags_NoMenus = 1 << 5, // the user will not be able to open context menus with right-click + ImPlotAxisFlags_Opposite = 1 << 6, // axis ticks and labels will be rendered on conventionally opposite side (i.e, right or top) + ImPlotAxisFlags_Foreground = 1 << 7, // grid lines will be displayed in the foreground (i.e. on top of data) in stead of the background + ImPlotAxisFlags_LogScale = 1 << 8, // a logartithmic (base 10) axis scale will be used (mutually exclusive with ImPlotAxisFlags_Time) + ImPlotAxisFlags_Time = 1 << 9, // axis will display date/time formatted labels (mutually exclusive with ImPlotAxisFlags_LogScale) + ImPlotAxisFlags_Invert = 1 << 10, // the axis will be inverted + ImPlotAxisFlags_AutoFit = 1 << 11, // axis will be auto-fitting to data extents + ImPlotAxisFlags_RangeFit = 1 << 12, // axis will only fit points if the point is in the visible range of the **orthogonal** axis + ImPlotAxisFlags_LockMin = 1 << 13, // the axis minimum value will be locked when panning/zooming + ImPlotAxisFlags_LockMax = 1 << 14, // the axis maximum value will be locked when panning/zooming ImPlotAxisFlags_Lock = ImPlotAxisFlags_LockMin | ImPlotAxisFlags_LockMax, - ImPlotAxisFlags_NoDecorations = ImPlotAxisFlags_NoLabel | ImPlotAxisFlags_NoGridLines | ImPlotAxisFlags_NoTickMarks | ImPlotAxisFlags_NoTickLabels + ImPlotAxisFlags_NoDecorations = ImPlotAxisFlags_NoLabel | ImPlotAxisFlags_NoGridLines | ImPlotAxisFlags_NoTickMarks | ImPlotAxisFlags_NoTickLabels, + ImPlotAxisFlags_AuxDefault = ImPlotAxisFlags_NoGridLines | ImPlotAxisFlags_Opposite }; // Options for subplots (see BeginSubplot). @@ -112,13 +156,55 @@ enum ImPlotSubplotFlags_ { ImPlotSubplotFlags_NoResize = 1 << 3, // resize splitters between subplot cells will be not be provided ImPlotSubplotFlags_NoAlign = 1 << 4, // subplot edges will not be aligned vertically or horizontally ImPlotSubplotFlags_ShareItems = 1 << 5, // items across all subplots will be shared and rendered into a single legend entry - ImPlotSubplotFlags_LinkRows = 1 << 6, // link the y-axis limits of all plots in each row (does not apply auxiliary y-axes) - ImPlotSubplotFlags_LinkCols = 1 << 7, // link the x-axis limits of all plots in each column - ImPlotSubplotFlags_LinkAllX = 1 << 8, // link the x-axis limits in every plot in the subplot - ImPlotSubplotFlags_LinkAllY = 1 << 9 , // link the y-axis limits in every plot in the subplot (does not apply to auxiliary y-axes) + ImPlotSubplotFlags_LinkRows = 1 << 6, // link the y-axis limits of all plots in each row (does not apply to auxiliary axes) + ImPlotSubplotFlags_LinkCols = 1 << 7, // link the x-axis limits of all plots in each column (does not apply to auxiliary axes) + ImPlotSubplotFlags_LinkAllX = 1 << 8, // link the x-axis limits in every plot in the subplot (does not apply to auxiliary axes) + ImPlotSubplotFlags_LinkAllY = 1 << 9, // link the y-axis limits in every plot in the subplot (does not apply to auxiliary axes) ImPlotSubplotFlags_ColMajor = 1 << 10 // subplots are added in column major order instead of the default row major order }; +// Options for legends (see SetupLegend) +enum ImPlotLegendFlags_ { + ImPlotLegendFlags_None = 0, // default + ImPlotLegendFlags_NoButtons = 1 << 0, // legend icons will not function as hide/show buttons + ImPlotLegendFlags_NoHighlightItem = 1 << 1, // plot items will not be highlighted when their legend entry is hovered + ImPlotLegendFlags_NoHighlightAxis = 1 << 2, // axes will not be highlighted when legend entries are hovered (only relevant if x/y-axis count > 1) + ImPlotLegendFlags_NoMenus = 1 << 3, // the user will not be able to open context menus with right-click + ImPlotLegendFlags_Outside = 1 << 4, // legend will be rendered outside of the plot area + ImPlotLegendFlags_Horizontal = 1 << 5, // legend entries will be displayed horizontally +}; + +// Options for mouse hover text (see SetupMouseText) +enum ImPlotMouseTextFlags_ { + ImPlotMouseTextFlags_None = 0, // default + ImPlotMouseTextFlags_NoAuxAxes = 1 << 0, // only show the mouse position for primary axes + ImPlotMouseTextFlags_NoFormat = 1 << 1, // axes label formatters won't be used to render text + ImPlotMouseTextFlags_ShowAlways = 1 << 2, // always display mouse position even if plot not hovered +}; + +// Options for DragPoint, DragLine, DragRect +enum ImPlotDragToolFlags_ { + ImPlotDragToolFlags_None = 0, // default + ImPlotDragToolFlags_NoCursors = 1 << 0, // drag tools won't change cursor icons when hovered or held + ImPlotDragToolFlags_NoFit = 1 << 1, // the drag tool won't be considered for plot fits + ImPlotDragToolFlags_NoInputs = 1 << 2, // lock the tool from user inputs + ImPlotDragToolFlags_Delayed = 1 << 3, // tool rendering will be delayed one frame; useful when applying position-constraints +}; + +// Flags for ImPlot::PlotBarGroups +enum ImPlotBarGroupsFlags_ { + ImPlotBarGroupsFlags_None = 0, // default + ImPlotBarGroupsFlags_Stacked = 1 << 0, // items in a group will be stacked on top of each other +}; + +// Represents a condition for SetupAxisLimits etc. (same as ImGuiCond, but we only support a subset of those enums) +enum ImPlotCond_ +{ + ImPlotCond_None = ImGuiCond_None, // No condition (always set the variable), same as _Always + ImPlotCond_Always = ImGuiCond_Always, // No condition (always set the variable) + ImPlotCond_Once = ImGuiCond_Once, // Set the variable once per runtime session (only the first call will succeed) +}; + // Plot styling colors. enum ImPlotCol_ { // item styling colors @@ -136,16 +222,13 @@ enum ImPlotCol_ { ImPlotCol_LegendText, // legend text color (defaults to ImPlotCol_InlayText) ImPlotCol_TitleText, // plot title text color (defaults to ImGuiCol_Text) ImPlotCol_InlayText, // color of text appearing inside of plots (defaults to ImGuiCol_Text) - ImPlotCol_XAxis, // x-axis label and tick lables color (defaults to ImGuiCol_Text) - ImPlotCol_XAxisGrid, // x-axis grid color (defaults to 25% ImPlotCol_XAxis) - ImPlotCol_YAxis, // y-axis label and tick labels color (defaults to ImGuiCol_Text) - ImPlotCol_YAxisGrid, // y-axis grid color (defaults to 25% ImPlotCol_YAxis) - ImPlotCol_YAxis2, // 2nd y-axis label and tick labels color (defaults to ImGuiCol_Text) - ImPlotCol_YAxisGrid2, // 2nd y-axis grid/label color (defaults to 25% ImPlotCol_YAxis2) - ImPlotCol_YAxis3, // 3rd y-axis label and tick labels color (defaults to ImGuiCol_Text) - ImPlotCol_YAxisGrid3, // 3rd y-axis grid/label color (defaults to 25% ImPlotCol_YAxis3) + ImPlotCol_AxisText, // axis label and tick lables color (defaults to ImGuiCol_Text) + ImPlotCol_AxisGrid, // axis grid color (defaults to 25% ImPlotCol_AxisText) + ImPlotCol_AxisTick, // axis tick color (defaults to AxisGrid) + ImPlotCol_AxisBg, // background color of axis hover region (defaults to transparent) + ImPlotCol_AxisBgHovered, // axis hover color (defaults to ImGuiCol_ButtonHovered) + ImPlotCol_AxisBgActive, // axis active color (defaults to ImGuiCol_ButtonActive) ImPlotCol_Selection, // box-selection color (defaults to yellow) - ImPlotCol_Query, // box-query color (defaults to green) ImPlotCol_Crosshairs, // crosshairs color (defaults to ImPlotCol_PlotBorder) ImPlotCol_COUNT }; @@ -233,19 +316,6 @@ enum ImPlotLocation_ { ImPlotLocation_SouthEast = ImPlotLocation_South | ImPlotLocation_East // bottom-right }; -// Used to orient items on a plot (e.g. legends, labels, etc.) -enum ImPlotOrientation_ { - ImPlotOrientation_Horizontal, // left/right - ImPlotOrientation_Vertical // up/down -}; - -// Enums for different y-axes. -enum ImPlotYAxis_ { - ImPlotYAxis_1 = 0, // left (default) - ImPlotYAxis_2 = 1, // first on right side - ImPlotYAxis_3 = 2 // second on right side -}; - // Enums for different automatic histogram binning methods (k = bin count or w = bin width) enum ImPlotBin_ { ImPlotBin_Sqrt = -1, // k = sqrt(n) @@ -257,8 +327,8 @@ enum ImPlotBin_ { // Double precision version of ImVec2 used by ImPlot. Extensible by end users. struct ImPlotPoint { double x, y; - ImPlotPoint() { x = y = 0.0; } - ImPlotPoint(double _x, double _y) { x = _x; y = _y; } + ImPlotPoint() { x = y = 0.0; } + ImPlotPoint(double _x, double _y) { x = _x; y = _y; } ImPlotPoint(const ImVec2& p) { x = p.x; y = p.y; } double operator[] (size_t idx) const { return (&x)[idx]; } double& operator[] (size_t idx) { return (&x)[idx]; } @@ -268,24 +338,28 @@ struct ImPlotPoint { #endif }; -// A range defined by a min/max value. Used for plot axes ranges. +// Range defined by a min/max value. struct ImPlotRange { double Min, Max; - ImPlotRange() { Min = 0; Max = 0; } - ImPlotRange(double _min, double _max) { Min = _min; Max = _max; } - bool Contains(double value) const { return value >= Min && value <= Max; }; - double Size() const { return Max - Min; }; + ImPlotRange() { Min = 0; Max = 0; } + ImPlotRange(double _min, double _max) { Min = _min; Max = _max; } + bool Contains(double value) const { return value >= Min && value <= Max; } + double Size() const { return Max - Min; } + double Clamp(double value) const { return (value < Min) ? Min : (value > Max) ? Max : value; } }; -// Combination of two ranges for X and Y axes. -struct ImPlotLimits { +// Combination of two range limits for X and Y axes. Also an AABB defined by Min()/Max(). +struct ImPlotRect { ImPlotRange X, Y; - ImPlotLimits() { } - ImPlotLimits(double x_min, double x_max, double y_min, double y_max) { X.Min = x_min; X.Max = x_max; Y.Min = y_min; Y.Max = y_max; } - bool Contains(const ImPlotPoint& p) const { return Contains(p.x, p.y); } - bool Contains(double x, double y) const { return X.Contains(x) && Y.Contains(y); } - ImPlotPoint Min() const { return ImPlotPoint(X.Min, Y.Min); } - ImPlotPoint Max() const { return ImPlotPoint(X.Max, Y.Max); } + ImPlotRect() { } + ImPlotRect(double x_min, double x_max, double y_min, double y_max) { X.Min = x_min; X.Max = x_max; Y.Min = y_min; Y.Max = y_max; } + bool Contains(const ImPlotPoint& p) const { return Contains(p.x, p.y); } + bool Contains(double x, double y) const { return X.Contains(x) && Y.Contains(y); } + ImPlotPoint Size() const { return ImPlotPoint(X.Size(), Y.Size()); } + ImPlotPoint Clamp(const ImPlotPoint& p) { return Clamp(p.x, p.y); } + ImPlotPoint Clamp(double x, double y) { return ImPlotPoint(X.Clamp(x),Y.Clamp(y)); } + ImPlotPoint Min() const { return ImPlotPoint(X.Min, Y.Min); } + ImPlotPoint Max() const { return ImPlotPoint(X.Max, Y.Max); } }; // Plot style structure @@ -331,14 +405,46 @@ struct ImPlotStyle { IMPLOT_API ImPlotStyle(); }; +#if (IMGUI_VERSION_NUM < 18716) // Renamed in 1.88 +#define ImGuiModFlags ImGuiKeyModFlags +#define ImGuiModFlags_None ImGuiKeyModFlags_None +#define ImGuiModFlags_Ctrl ImGuiKeyModFlags_Ctrl +#define ImGuiModFlags_Shift ImGuiKeyModFlags_Shift +#define ImGuiModFlags_Alt ImGuiKeyModFlags_Alt +#define ImGuiModFlags_Super ImGuiKeyModFlags_Super +#endif + +// Input mapping structure. Default values listed. See also MapInputDefault, MapInputReverse. +struct ImPlotInputMap { + ImGuiMouseButton Pan; // LMB enables panning when held, + ImGuiModFlags PanMod; // none optional modifier that must be held for panning/fitting + ImGuiMouseButton Fit; // LMB initiates fit when double clicked + ImGuiMouseButton Select; // RMB begins box selection when pressed and confirms selection when released + ImGuiMouseButton SelectCancel; // LMB cancels active box selection when pressed; cannot be same as Select + ImGuiModFlags SelectMod; // none optional modifier that must be held for box selection + ImGuiModFlags SelectHorzMod; // Alt expands active box selection horizontally to plot edge when held + ImGuiModFlags SelectVertMod; // Shift expands active box selection vertically to plot edge when held + ImGuiMouseButton Menu; // RMB opens context menus (if enabled) when clicked + ImGuiModFlags OverrideMod; // Ctrl when held, all input is ignored; used to enable axis/plots as DND sources + ImGuiModFlags ZoomMod; // none optional modifier that must be held for scroll wheel zooming + float ZoomRate; // 0.1f zoom rate for scroll (e.g. 0.1f = 10% plot range every scroll click); make negative to invert + IMPLOT_API ImPlotInputMap(); +}; + //----------------------------------------------------------------------------- -// ImPlot End-User API +// [SECTION] Callbacks //----------------------------------------------------------------------------- +// Callback signature for axis tick label formatter. +typedef void (*ImPlotFormatter)(double value, char* buff, int size, void* user_data); + +// Callback signature for data getter. +typedef ImPlotPoint (*ImPlotGetter)(void* user_data, int idx); + namespace ImPlot { //----------------------------------------------------------------------------- -// ImPlot Context +// [SECTION] Contexts //----------------------------------------------------------------------------- // Creates a new ImPlot context. Call this after ImGui::CreateContext. @@ -357,14 +463,14 @@ IMPLOT_API void SetCurrentContext(ImPlotContext* ctx); IMPLOT_API void SetImGuiContext(ImGuiContext* ctx); //----------------------------------------------------------------------------- -// Begin/End Plot +// [SECTION] Begin/End Plot //----------------------------------------------------------------------------- // Starts a 2D plotting context. If this function returns true, EndPlot() MUST // be called! You are encouraged to use the following convention: // // if (BeginPlot(...)) { -// ImPlot::PlotLine(...); +// PlotLine(...); // ... // EndPlot(); // } @@ -374,31 +480,16 @@ IMPLOT_API void SetImGuiContext(ImGuiContext* ctx); // - #title_id must be unique to the current ImGui ID scope. If you need to avoid ID // collisions or don't want to display a title in the plot, use double hashes // (e.g. "MyPlot##HiddenIdText" or "##NoTitle"). -// - If #x_label and/or #y_label are provided, axes labels will be displayed. // - #size is the **frame** size of the plot widget, not the plot area. The default -// size of plots (i.e. when ImVec2(0,0)) can be modified in your ImPlotStyle -// (default is 400x300 px). -// - Auxiliary y-axes must be enabled with ImPlotFlags_YAxis2/3 to be displayed. -// - See ImPlotFlags and ImPlotAxisFlags for more available options. - -IMPLOT_API bool BeginPlot(const char* title_id, - const char* x_label = NULL, - const char* y_label = NULL, - const ImVec2& size = ImVec2(-1,0), - ImPlotFlags flags = ImPlotFlags_None, - ImPlotAxisFlags x_flags = ImPlotAxisFlags_None, - ImPlotAxisFlags y_flags = ImPlotAxisFlags_None, - ImPlotAxisFlags y2_flags = ImPlotAxisFlags_NoGridLines, - ImPlotAxisFlags y3_flags = ImPlotAxisFlags_NoGridLines, - const char* y2_label = NULL, - const char* y3_label = NULL); +// size of plots (i.e. when ImVec2(0,0)) can be modified in your ImPlotStyle. +IMPLOT_API bool BeginPlot(const char* title_id, const ImVec2& size = ImVec2(-1,0), ImPlotFlags flags = ImPlotFlags_None); // Only call EndPlot() if BeginPlot() returns true! Typically called at the end // of an if statement conditioned on BeginPlot(). See example above. IMPLOT_API void EndPlot(); //----------------------------------------------------------------------------- -// Begin/EndSubplots +// [SECTION] Begin/End Subplots //----------------------------------------------------------------------------- // Starts a subdivided plotting context. If the function returns true, @@ -419,16 +510,17 @@ IMPLOT_API void EndPlot(); // EndSubplots(); // } // -// Procudes: +// Produces: // -// [0][1][2] -// [3][4][5] +// [0] | [1] | [2] +// ----|-----|---- +// [3] | [4] | [5] // // Important notes: // // - #title_id must be unique to the current ImGui ID scope. If you need to avoid ID // collisions or don't want to display a title in the plot, use double hashes -// (e.g. "MyPlot##HiddenIdText" or "##NoTitle"). +// (e.g. "MySubplot##HiddenIdText" or "##NoTitle"). // - #rows and #cols must be greater than 0. // - #size is the size of the entire grid of subplots, not the individual plots // - #row_ratios and #col_ratios must have AT LEAST #rows and #cols elements, @@ -459,10 +551,107 @@ IMPLOT_API bool BeginSubplots(const char* title_id, IMPLOT_API void EndSubplots(); //----------------------------------------------------------------------------- -// Plot Items +// [SECTION] Setup //----------------------------------------------------------------------------- -// The template functions below are explicitly instantiated in implot_items.cpp. +// The following API allows you to setup and customize various aspects of the +// current plot. The functions should be called immediately after BeginPlot +// and before any other API calls. Typical usage is as follows: + +// if (BeginPlot(...)) { 1) begin a new plot +// SetupAxis(ImAxis_X1, "My X-Axis"); 2) make Setup calls +// SetupAxis(ImAxis_Y1, "My Y-Axis"); +// SetupLegend(ImPlotLocation_North); +// ... +// SetupFinish(); 3) [optional] explicitly finish setup +// PlotLine(...); 4) plot items +// ... +// EndPlot(); 5) end the plot +// } +// +// Important notes: +// +// - Always call Setup code at the top of your BeginPlot conditional statement. +// - Setup is locked once you start plotting or explicitly call SetupFinish. +// Do NOT call Setup code after you begin plotting or after you make +// any non-Setup API calls (e.g. utils like PlotToPixels also lock Setup) +// - Calling SetupFinish is OPTIONAL, but probably good practice. If you do not +// call it yourself, then the first subsequent plotting or utility function will +// call it for you. + +// Enables an axis or sets the label and/or flags for an existing axis. Leave #label = NULL for no label. +IMPLOT_API void SetupAxis(ImAxis axis, const char* label = NULL, ImPlotAxisFlags flags = ImPlotAxisFlags_None); +// Sets an axis range limits. If ImPlotCond_Always is used, the axes limits will be locked. +IMPLOT_API void SetupAxisLimits(ImAxis axis, double v_min, double v_max, ImPlotCond cond = ImPlotCond_Once); +// Links an axis range limits to external values. Set to NULL for no linkage. The pointer data must remain valid until EndPlot. +IMPLOT_API void SetupAxisLinks(ImAxis axis, double* link_min, double* link_max); +// Sets the format of numeric axis labels via formater specifier (default="%g"). Formated values will be double (i.e. use %f). +IMPLOT_API void SetupAxisFormat(ImAxis axis, const char* fmt); +// Sets the format of numeric axis labels via formatter callback. Given #value, write a label into #buff. Optionally pass user data. +IMPLOT_API void SetupAxisFormat(ImAxis axis, ImPlotFormatter formatter, void* data = NULL); +// Sets an axis' ticks and optionally the labels. To keep the default ticks, set #keep_default=true. +IMPLOT_API void SetupAxisTicks(ImAxis axis, const double* values, int n_ticks, const char* const labels[] = NULL, bool keep_default = false); +// Sets an axis' ticks and optionally the labels for the next plot. To keep the default ticks, set #keep_default=true. +IMPLOT_API void SetupAxisTicks(ImAxis axis, double v_min, double v_max, int n_ticks, const char* const labels[] = NULL, bool keep_default = false); + +// Sets the label and/or flags for primary X and Y axes (shorthand for two calls to SetupAxis). +IMPLOT_API void SetupAxes(const char* x_label, const char* y_label, ImPlotAxisFlags x_flags = ImPlotAxisFlags_None, ImPlotAxisFlags y_flags = ImPlotAxisFlags_None); +// Sets the primary X and Y axes range limits. If ImPlotCond_Always is used, the axes limits will be locked (shorthand for two calls to SetupAxisLimits). +IMPLOT_API void SetupAxesLimits(double x_min, double x_max, double y_min, double y_max, ImPlotCond cond = ImPlotCond_Once); + +// Sets up the plot legend. +IMPLOT_API void SetupLegend(ImPlotLocation location, ImPlotLegendFlags flags = ImPlotLegendFlags_None); +// Set the location of the current plot's mouse position text (default = South|East). +IMPLOT_API void SetupMouseText(ImPlotLocation location, ImPlotMouseTextFlags flags = ImPlotMouseTextFlags_None); + +// Explicitly finalize plot setup. Once you call this, you cannot make anymore Setup calls for the current plot! +// Note that calling this function is OPTIONAL; it will be called by the first subsequent setup-locking API call. +IMPLOT_API void SetupFinish(); + +//----------------------------------------------------------------------------- +// [SECTION] SetNext +//----------------------------------------------------------------------------- + +// Though you should default to the `Setup` API above, there are some scenarios +// where (re)configuring a plot or axis before `BeginPlot` is needed (e.g. if +// using a preceding button or slider widget to change the plot limits). In +// this case, you can use the `SetNext` API below. While this is not as feature +// rich as the Setup API, most common needs are provided. These functions can be +// called anwhere except for inside of `Begin/EndPlot`. For example: + +// if (ImGui::Button("Center Plot")) +// ImPlot::SetNextPlotLimits(-1,1,-1,1); +// if (ImPlot::BeginPlot(...)) { +// ... +// ImPlot::EndPlot(); +// } +// +// Important notes: +// +// - You must still enable non-default axes with SetupAxis for these functions +// to work properly. + +// Sets an upcoming axis range limits. If ImPlotCond_Always is used, the axes limits will be locked. +IMPLOT_API void SetNextAxisLimits(ImAxis axis, double v_min, double v_max, ImPlotCond cond = ImPlotCond_Once); +// Links an upcoming axis range limits to external values. Set to NULL for no linkage. The pointer data must remain valid until EndPlot! +IMPLOT_API void SetNextAxisLinks(ImAxis axis, double* link_min, double* link_max); +// Set an upcoming axis to auto fit to its data. +IMPLOT_API void SetNextAxisToFit(ImAxis axis); + +// Sets the upcoming primary X and Y axes range limits. If ImPlotCond_Always is used, the axes limits will be locked (shorthand for two calls to SetupAxisLimits). +IMPLOT_API void SetNextAxesLimits(double x_min, double x_max, double y_min, double y_max, ImPlotCond cond = ImPlotCond_Once); +// Sets all upcoming axes to auto fit to their data. +IMPLOT_API void SetNextAxesToFit(); + +//----------------------------------------------------------------------------- +// [SECTION] Plot Items +//----------------------------------------------------------------------------- + +// The main plotting API is provied below. Call these functions between +// Begin/EndPlot and after any Setup API calls. Each plots data on the current +// x and y axes, which can be changed with `SetAxis/Axes`. +// +// The templated functions are explicitly instantiated in implot_items.cpp. // They are not intended to be used generically with custom types. You will get // a linker error if you try! All functions support the following scalar types: // @@ -507,71 +696,77 @@ IMPLOT_API void EndSubplots(); // if you try plotting extremely large 64-bit integral types. Proceed with caution! // Plots a standard 2D line plot. -template IMPLOT_API void PlotLine(const char* label_id, const T* values, int count, double xscale=1, double x0=0, int offset=0, int stride=sizeof(T)); -template IMPLOT_API void PlotLine(const char* label_id, const T* xs, const T* ys, int count, int offset=0, int stride=sizeof(T)); - IMPLOT_API void PlotLineG(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, int offset=0); +IMPLOT_TMP void PlotLine(const char* label_id, const T* values, int count, double xscale=1, double x0=0, int offset=0, int stride=sizeof(T)); +IMPLOT_TMP void PlotLine(const char* label_id, const T* xs, const T* ys, int count, int offset=0, int stride=sizeof(T)); +IMPLOT_API void PlotLineG(const char* label_id, ImPlotGetter getter, void* data, int count); // Plots a standard 2D scatter plot. Default marker is ImPlotMarker_Circle. -template IMPLOT_API void PlotScatter(const char* label_id, const T* values, int count, double xscale=1, double x0=0, int offset=0, int stride=sizeof(T)); -template IMPLOT_API void PlotScatter(const char* label_id, const T* xs, const T* ys, int count, int offset=0, int stride=sizeof(T)); - IMPLOT_API void PlotScatterG(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, int offset=0); +IMPLOT_TMP void PlotScatter(const char* label_id, const T* values, int count, double xscale=1, double x0=0, int offset=0, int stride=sizeof(T)); +IMPLOT_TMP void PlotScatter(const char* label_id, const T* xs, const T* ys, int count, int offset=0, int stride=sizeof(T)); +IMPLOT_API void PlotScatterG(const char* label_id, ImPlotGetter getter, void* data, int count); // Plots a a stairstep graph. The y value is continued constantly from every x position, i.e. the interval [x[i], x[i+1]) has the value y[i]. -template IMPLOT_API void PlotStairs(const char* label_id, const T* values, int count, double xscale=1, double x0=0, int offset=0, int stride=sizeof(T)); -template IMPLOT_API void PlotStairs(const char* label_id, const T* xs, const T* ys, int count, int offset=0, int stride=sizeof(T)); - IMPLOT_API void PlotStairsG(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, int offset=0); +IMPLOT_TMP void PlotStairs(const char* label_id, const T* values, int count, double xscale=1, double x0=0, int offset=0, int stride=sizeof(T)); +IMPLOT_TMP void PlotStairs(const char* label_id, const T* xs, const T* ys, int count, int offset=0, int stride=sizeof(T)); +IMPLOT_API void PlotStairsG(const char* label_id, ImPlotGetter getter, void* data, int count); -// Plots a shaded (filled) region between two lines, or a line and a horizontal reference. Set y_ref to +/-INFINITY for infinite fill extents. -template IMPLOT_API void PlotShaded(const char* label_id, const T* values, int count, double y_ref=0, double xscale=1, double x0=0, int offset=0, int stride=sizeof(T)); -template IMPLOT_API void PlotShaded(const char* label_id, const T* xs, const T* ys, int count, double y_ref=0, int offset=0, int stride=sizeof(T)); -template IMPLOT_API void PlotShaded(const char* label_id, const T* xs, const T* ys1, const T* ys2, int count, int offset=0, int stride=sizeof(T)); - IMPLOT_API void PlotShadedG(const char* label_id, ImPlotPoint (*getter1)(void* data, int idx), void* data1, ImPlotPoint (*getter2)(void* data, int idx), void* data2, int count, int offset=0); +// Plots a shaded (filled) region between two lines, or a line and a horizontal reference. Set yref to +/-INFINITY for infinite fill extents. +IMPLOT_TMP void PlotShaded(const char* label_id, const T* values, int count, double yref=0, double xscale=1, double x0=0, int offset=0, int stride=sizeof(T)); +IMPLOT_TMP void PlotShaded(const char* label_id, const T* xs, const T* ys, int count, double yref=0, int offset=0, int stride=sizeof(T)); +IMPLOT_TMP void PlotShaded(const char* label_id, const T* xs, const T* ys1, const T* ys2, int count, int offset=0, int stride=sizeof(T)); +IMPLOT_API void PlotShadedG(const char* label_id, ImPlotGetter getter1, void* data1, ImPlotGetter getter2, void* data2, int count); -// Plots a vertical bar graph. #width and #shift are in X units. -template IMPLOT_API void PlotBars(const char* label_id, const T* values, int count, double width=0.67, double shift=0, int offset=0, int stride=sizeof(T)); -template IMPLOT_API void PlotBars(const char* label_id, const T* xs, const T* ys, int count, double width, int offset=0, int stride=sizeof(T)); - IMPLOT_API void PlotBarsG(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, double width, int offset=0); +// Plots a vertical bar graph. #bar_width and #x0 are in X units. +IMPLOT_TMP void PlotBars(const char* label_id, const T* values, int count, double bar_width=0.67, double x0=0, int offset=0, int stride=sizeof(T)); +IMPLOT_TMP void PlotBars(const char* label_id, const T* xs, const T* ys, int count, double bar_width, int offset=0, int stride=sizeof(T)); +IMPLOT_API void PlotBarsG(const char* label_id, ImPlotGetter getter, void* data, int count, double bar_width); -// Plots a horizontal bar graph. #height and #shift are in Y units. -template IMPLOT_API void PlotBarsH(const char* label_id, const T* values, int count, double height=0.67, double shift=0, int offset=0, int stride=sizeof(T)); -template IMPLOT_API void PlotBarsH(const char* label_id, const T* xs, const T* ys, int count, double height, int offset=0, int stride=sizeof(T)); - IMPLOT_API void PlotBarsHG(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, double height, int offset=0); +// Plots a horizontal bar graph. #bar_height and #y0 are in Y units. +IMPLOT_TMP void PlotBarsH(const char* label_id, const T* values, int count, double bar_height=0.67, double y0=0, int offset=0, int stride=sizeof(T)); +IMPLOT_TMP void PlotBarsH(const char* label_id, const T* xs, const T* ys, int count, double bar_height, int offset=0, int stride=sizeof(T)); +IMPLOT_API void PlotBarsHG(const char* label_id, ImPlotGetter getter, void* data, int count, double bar_height); + +// Plots a group of vertical bars. #values is a row-major matrix with #item_count rows and #group_count cols. #label_ids should have #item_count elements. +IMPLOT_TMP void PlotBarGroups(const char* const label_ids[], const T* values, int item_count, int group_count, double group_width=0.67, double x0=0, ImPlotBarGroupsFlags flags=ImPlotBarGroupsFlags_None); + +// Plots a group of horizontal bars. #values is a row-major matrix with #item_count rows and #group_count cols. #label_ids should have #item_count elements. +IMPLOT_TMP void PlotBarGroupsH(const char* const label_ids[], const T* values, int item_count, int group_count, double group_height=0.67, double y0=0, ImPlotBarGroupsFlags flags=ImPlotBarGroupsFlags_None); // Plots vertical error bar. The label_id should be the same as the label_id of the associated line or bar plot. -template IMPLOT_API void PlotErrorBars(const char* label_id, const T* xs, const T* ys, const T* err, int count, int offset=0, int stride=sizeof(T)); -template IMPLOT_API void PlotErrorBars(const char* label_id, const T* xs, const T* ys, const T* neg, const T* pos, int count, int offset=0, int stride=sizeof(T)); +IMPLOT_TMP void PlotErrorBars(const char* label_id, const T* xs, const T* ys, const T* err, int count, int offset=0, int stride=sizeof(T)); +IMPLOT_TMP void PlotErrorBars(const char* label_id, const T* xs, const T* ys, const T* neg, const T* pos, int count, int offset=0, int stride=sizeof(T)); // Plots horizontal error bars. The label_id should be the same as the label_id of the associated line or bar plot. -template IMPLOT_API void PlotErrorBarsH(const char* label_id, const T* xs, const T* ys, const T* err, int count, int offset=0, int stride=sizeof(T)); -template IMPLOT_API void PlotErrorBarsH(const char* label_id, const T* xs, const T* ys, const T* neg, const T* pos, int count, int offset=0, int stride=sizeof(T)); +IMPLOT_TMP void PlotErrorBarsH(const char* label_id, const T* xs, const T* ys, const T* err, int count, int offset=0, int stride=sizeof(T)); +IMPLOT_TMP void PlotErrorBarsH(const char* label_id, const T* xs, const T* ys, const T* neg, const T* pos, int count, int offset=0, int stride=sizeof(T)); /// Plots vertical stems. -template IMPLOT_API void PlotStems(const char* label_id, const T* values, int count, double y_ref=0, double xscale=1, double x0=0, int offset=0, int stride=sizeof(T)); -template IMPLOT_API void PlotStems(const char* label_id, const T* xs, const T* ys, int count, double y_ref=0, int offset=0, int stride=sizeof(T)); +IMPLOT_TMP void PlotStems(const char* label_id, const T* values, int count, double yref=0, double xscale=1, double x0=0, int offset=0, int stride=sizeof(T)); +IMPLOT_TMP void PlotStems(const char* label_id, const T* xs, const T* ys, int count, double yref=0, int offset=0, int stride=sizeof(T)); /// Plots infinite vertical or horizontal lines (e.g. for references or asymptotes). -template IMPLOT_API void PlotVLines(const char* label_id, const T* xs, int count, int offset=0, int stride=sizeof(T)); -template IMPLOT_API void PlotHLines(const char* label_id, const T* ys, int count, int offset=0, int stride=sizeof(T)); +IMPLOT_TMP void PlotVLines(const char* label_id, const T* xs, int count, int offset=0, int stride=sizeof(T)); +IMPLOT_TMP void PlotHLines(const char* label_id, const T* ys, int count, int offset=0, int stride=sizeof(T)); // Plots a pie chart. If the sum of values > 1 or normalize is true, each value will be normalized. Center and radius are in plot units. #label_fmt can be set to NULL for no labels. -template IMPLOT_API void PlotPieChart(const char* const label_ids[], const T* values, int count, double x, double y, double radius, bool normalize=false, const char* label_fmt="%.1f", double angle0=90); +IMPLOT_TMP void PlotPieChart(const char* const label_ids[], const T* values, int count, double x, double y, double radius, bool normalize=false, const char* label_fmt="%.1f", double angle0=90); // Plots a 2D heatmap chart. Values are expected to be in row-major order. Leave #scale_min and scale_max both at 0 for automatic color scaling, or set them to a predefined range. #label_fmt can be set to NULL for no labels. -template IMPLOT_API void PlotHeatmap(const char* label_id, const T* values, int rows, int cols, double scale_min=0, double scale_max=0, const char* label_fmt="%.1f", const ImPlotPoint& bounds_min=ImPlotPoint(0,0), const ImPlotPoint& bounds_max=ImPlotPoint(1,1)); +IMPLOT_TMP void PlotHeatmap(const char* label_id, const T* values, int rows, int cols, double scale_min=0, double scale_max=0, const char* label_fmt="%.1f", const ImPlotPoint& bounds_min=ImPlotPoint(0,0), const ImPlotPoint& bounds_max=ImPlotPoint(1,1)); // Plots a horizontal histogram. #bins can be a positive integer or an ImPlotBin_ method. If #cumulative is true, each bin contains its count plus the counts of all previous bins. // If #density is true, the PDF is visualized. If both are true, the CDF is visualized. If #range is left unspecified, the min/max of #values will be used as the range. // If #range is specified, outlier values outside of the range are not binned. However, outliers still count toward normalizing and cumulative counts unless #outliers is false. The largest bin count or density is returned. -template IMPLOT_API double PlotHistogram(const char* label_id, const T* values, int count, int bins=ImPlotBin_Sturges, bool cumulative=false, bool density=false, ImPlotRange range=ImPlotRange(), bool outliers=true, double bar_scale=1.0); +IMPLOT_TMP double PlotHistogram(const char* label_id, const T* values, int count, int bins=ImPlotBin_Sturges, bool cumulative=false, bool density=false, ImPlotRange range=ImPlotRange(), bool outliers=true, double bar_scale=1.0); // Plots two dimensional, bivariate histogram as a heatmap. #x_bins and #y_bins can be a positive integer or an ImPlotBin. If #density is true, the PDF is visualized. -// If #range is left unspecified, the min/max of #xs an #ys will be used as the ranges. If #range is specified, outlier values outside of range are not binned. +// If #bounds is left unspecified, the min/max of #xs an #ys will be used as the ranges. If #bounds is specified, outlier values outside of range are not binned. // However, outliers still count toward the normalizing count for density plots unless #outliers is false. The largest bin count or density is returned. -template IMPLOT_API double PlotHistogram2D(const char* label_id, const T* xs, const T* ys, int count, int x_bins=ImPlotBin_Sturges, int y_bins=ImPlotBin_Sturges, bool density=false, ImPlotLimits range=ImPlotLimits(), bool outliers=true); +IMPLOT_TMP double PlotHistogram2D(const char* label_id, const T* xs, const T* ys, int count, int x_bins=ImPlotBin_Sturges, int y_bins=ImPlotBin_Sturges, bool density=false, ImPlotRect range=ImPlotRect(), bool outliers=true); // Plots digital data. Digital plots do not respond to y drag or zoom, and are always referenced to the bottom of the plot. -template IMPLOT_API void PlotDigital(const char* label_id, const T* xs, const T* ys, int count, int offset=0, int stride=sizeof(T)); - IMPLOT_API void PlotDigitalG(const char* label_id, ImPlotPoint (*getter)(void* data, int idx), void* data, int count, int offset=0); +IMPLOT_TMP void PlotDigital(const char* label_id, const T* xs, const T* ys, int count, int offset=0, int stride=sizeof(T)); +IMPLOT_API void PlotDigitalG(const char* label_id, ImPlotGetter getter, void* data, int count); // Plots an axis-aligned image. #bounds_min/bounds_max are in plot coordinates (y-up) and #uv0/uv1 are in texture coordinates (y-down). IMPLOT_API void PlotImage(const char* label_id, ImTextureID user_texture_id, const ImPlotPoint& bounds_min, const ImPlotPoint& bounds_max, const ImVec2& uv0=ImVec2(0,0), const ImVec2& uv1=ImVec2(1,1), const ImVec4& tint_col=ImVec4(1,1,1,1)); @@ -583,163 +778,130 @@ IMPLOT_API void PlotText(const char* text, double x, double y, bool vertical=fal IMPLOT_API void PlotDummy(const char* label_id); //----------------------------------------------------------------------------- -// Plot Utils +// [SECTION] Plot Tools //----------------------------------------------------------------------------- -// The following functions MUST be called BEFORE BeginPlot! +// The following can be used to render interactive elements and/or annotations. +// Like the item plotting functions above, they apply to the current x and y +// axes, which can be changed with `SetAxis/SetAxes`. -// Set the axes range limits of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the axes limits will be locked. -IMPLOT_API void SetNextPlotLimits(double xmin, double xmax, double ymin, double ymax, ImGuiCond cond = ImGuiCond_Once); -// Set the X axis range limits of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the X axis limits will be locked. -IMPLOT_API void SetNextPlotLimitsX(double xmin, double xmax, ImGuiCond cond = ImGuiCond_Once); -// Set the Y axis range limits of the next plot. Call right before BeginPlot(). If ImGuiCond_Always is used, the Y axis limits will be locked. -IMPLOT_API void SetNextPlotLimitsY(double ymin, double ymax, ImGuiCond cond = ImGuiCond_Once, ImPlotYAxis y_axis = ImPlotYAxis_1); -// Links the next plot limits to external values. Set to NULL for no linkage. The pointer data must remain valid until the matching call to EndPlot. -IMPLOT_API void LinkNextPlotLimits(double* xmin, double* xmax, double* ymin, double* ymax, double* ymin2 = NULL, double* ymax2 = NULL, double* ymin3 = NULL, double* ymax3 = NULL); -// Fits the next plot axes to all plotted data if they are unlocked (equivalent to double-clicks). -IMPLOT_API void FitNextPlotAxes(bool x = true, bool y = true, bool y2 = true, bool y3 = true); +// Shows a draggable point at x,y. #col defaults to ImGuiCol_Text. +IMPLOT_API bool DragPoint(int id, double* x, double* y, const ImVec4& col, float size = 4, ImPlotDragToolFlags flags = ImPlotDragToolFlags_None); +// Shows a draggable vertical guide line at an x-value. #col defaults to ImGuiCol_Text. +IMPLOT_API bool DragLineX(int id, double* x, const ImVec4& col, float thickness = 1, ImPlotDragToolFlags flags = ImPlotDragToolFlags_None); +// Shows a draggable horizontal guide line at a y-value. #col defaults to ImGuiCol_Text. +IMPLOT_API bool DragLineY(int id, double* y, const ImVec4& col, float thickness = 1, ImPlotDragToolFlags flags = ImPlotDragToolFlags_None); +// Shows a draggable and resizeable rectangle. +IMPLOT_API bool DragRect(int id, double* x_min, double* y_min, double* x_max, double* y_max, const ImVec4& col, ImPlotDragToolFlags flags = ImPlotDragToolFlags_None); -// Set the X axis ticks and optionally the labels for the next plot. To keep the default ticks, set #keep_default=true. -IMPLOT_API void SetNextPlotTicksX(const double* values, int n_ticks, const char* const labels[] = NULL, bool keep_default = false); -IMPLOT_API void SetNextPlotTicksX(double x_min, double x_max, int n_ticks, const char* const labels[] = NULL, bool keep_default = false); -// Set the Y axis ticks and optionally the labels for the next plot. To keep the default ticks, set #keep_default=true. -IMPLOT_API void SetNextPlotTicksY(const double* values, int n_ticks, const char* const labels[] = NULL, bool keep_default = false, ImPlotYAxis y_axis = ImPlotYAxis_1); -IMPLOT_API void SetNextPlotTicksY(double y_min, double y_max, int n_ticks, const char* const labels[] = NULL, bool keep_default = false, ImPlotYAxis y_axis = ImPlotYAxis_1); +// Shows an annotation callout at a chosen point. Clamping keeps annotations in the plot area. Annotations are always rendered on top. +IMPLOT_API void Annotation(double x, double y, const ImVec4& color, const ImVec2& pix_offset, bool clamp, bool round = false); +IMPLOT_API void Annotation(double x, double y, const ImVec4& color, const ImVec2& pix_offset, bool clamp, const char* fmt, ...) IM_FMTARGS(6); +IMPLOT_API void AnnotationV(double x, double y, const ImVec4& color, const ImVec2& pix_offset, bool clamp, const char* fmt, va_list args) IM_FMTLIST(6); -// Set the format for numeric X axis labels (default="%g"). Formated values will be doubles (i.e. don't supply %d, %i, etc.). Not applicable if ImPlotAxisFlags_Time enabled. -IMPLOT_API void SetNextPlotFormatX(const char* fmt); -// Set the format for numeric Y axis labels (default="%g"). Formated values will be doubles (i.e. don't supply %d, %i, etc.). -IMPLOT_API void SetNextPlotFormatY(const char* fmt, ImPlotYAxis y_axis=ImPlotYAxis_1); +// Shows a x-axis tag at the specified coordinate value. +IMPLOT_API void TagX(double x, const ImVec4& color, bool round = false); +IMPLOT_API void TagX(double x, const ImVec4& color, const char* fmt, ...) IM_FMTARGS(3); +IMPLOT_API void TagXV(double x, const ImVec4& color, const char* fmt, va_list args) IM_FMTLIST(3); -// The following functions MUST be called BETWEEN Begin/EndPlot! +// Shows a y-axis tag at the specified coordinate value. +IMPLOT_API void TagY(double y, const ImVec4& color, bool round = false); +IMPLOT_API void TagY(double y, const ImVec4& color, const char* fmt, ...) IM_FMTARGS(3); +IMPLOT_API void TagYV(double y, const ImVec4& color, const char* fmt, va_list args) IM_FMTLIST(3); -// Select which Y axis will be used for subsequent plot elements. The default is ImPlotYAxis_1, or the first (left) Y axis. Enable 2nd and 3rd axes with ImPlotFlags_YAxisX. -IMPLOT_API void SetPlotYAxis(ImPlotYAxis y_axis); -// Hides or shows the next plot item (i.e. as if it were toggled from the legend). Use ImGuiCond_Always if you need to forcefully set this every frame. -IMPLOT_API void HideNextItem(bool hidden = true, ImGuiCond cond = ImGuiCond_Once); +//----------------------------------------------------------------------------- +// [SECTION] Plot Utils +//----------------------------------------------------------------------------- + +// Select which axis/axes will be used for subsequent plot elements. +IMPLOT_API void SetAxis(ImAxis axis); +IMPLOT_API void SetAxes(ImAxis x_axis, ImAxis y_axis); + +// Convert pixels to a position in the current plot's coordinate system. Passing IMPLOT_AUTO uses the current axes. +IMPLOT_API ImPlotPoint PixelsToPlot(const ImVec2& pix, ImAxis x_axis = IMPLOT_AUTO, ImAxis y_axis = IMPLOT_AUTO); +IMPLOT_API ImPlotPoint PixelsToPlot(float x, float y, ImAxis x_axis = IMPLOT_AUTO, ImAxis y_axis = IMPLOT_AUTO); + +// Convert a position in the current plot's coordinate system to pixels. Passing IMPLOT_AUTO uses the current axes. +IMPLOT_API ImVec2 PlotToPixels(const ImPlotPoint& plt, ImAxis x_axis = IMPLOT_AUTO, ImAxis y_axis = IMPLOT_AUTO); +IMPLOT_API ImVec2 PlotToPixels(double x, double y, ImAxis x_axis = IMPLOT_AUTO, ImAxis y_axis = IMPLOT_AUTO); -// Convert pixels to a position in the current plot's coordinate system. A negative y_axis uses the current value of SetPlotYAxis (ImPlotYAxis_1 initially). -IMPLOT_API ImPlotPoint PixelsToPlot(const ImVec2& pix, ImPlotYAxis y_axis = IMPLOT_AUTO); -IMPLOT_API ImPlotPoint PixelsToPlot(float x, float y, ImPlotYAxis y_axis = IMPLOT_AUTO); -// Convert a position in the current plot's coordinate system to pixels. A negative y_axis uses the current value of SetPlotYAxis (ImPlotYAxis_1 initially). -IMPLOT_API ImVec2 PlotToPixels(const ImPlotPoint& plt, ImPlotYAxis y_axis = IMPLOT_AUTO); -IMPLOT_API ImVec2 PlotToPixels(double x, double y, ImPlotYAxis y_axis = IMPLOT_AUTO); // Get the current Plot position (top-left) in pixels. IMPLOT_API ImVec2 GetPlotPos(); // Get the curent Plot size in pixels. IMPLOT_API ImVec2 GetPlotSize(); + +// Returns the mouse position in x,y coordinates of the current plot. Passing IMPLOT_AUTO uses the current axes. +IMPLOT_API ImPlotPoint GetPlotMousePos(ImAxis x_axis = IMPLOT_AUTO, ImAxis y_axis = IMPLOT_AUTO); +// Returns the current plot axis range. +IMPLOT_API ImPlotRect GetPlotLimits(ImAxis x_axis = IMPLOT_AUTO, ImAxis y_axis = IMPLOT_AUTO); + // Returns true if the plot area in the current plot is hovered. IMPLOT_API bool IsPlotHovered(); -// Returns true if the XAxis plot area in the current plot is hovered. -IMPLOT_API bool IsPlotXAxisHovered(); -// Returns true if the YAxis[n] plot area in the current plot is hovered. -IMPLOT_API bool IsPlotYAxisHovered(ImPlotYAxis y_axis = 0); -// Returns the mouse position in x,y coordinates of the current plot. A negative y_axis uses the current value of SetPlotYAxis (ImPlotYAxis_1 initially). -IMPLOT_API ImPlotPoint GetPlotMousePos(ImPlotYAxis y_axis = IMPLOT_AUTO); -// Returns the current plot axis range. A negative y_axis uses the current value of SetPlotYAxis (ImPlotYAxis_1 initially). -IMPLOT_API ImPlotLimits GetPlotLimits(ImPlotYAxis y_axis = IMPLOT_AUTO); +// Returns true if the axis label area in the current plot is hovered. +IMPLOT_API bool IsAxisHovered(ImAxis axis); +// Returns true if the bounding frame of a subplot is hovered. +IMPLOT_API bool IsSubplotsHovered(); // Returns true if the current plot is being box selected. IMPLOT_API bool IsPlotSelected(); -// Returns the current plot box selection bounds. -IMPLOT_API ImPlotLimits GetPlotSelection(ImPlotYAxis y_axis = IMPLOT_AUTO); +// Returns the current plot box selection bounds. Passing IMPLOT_AUTO uses the current axes. +IMPLOT_API ImPlotRect GetPlotSelection(ImAxis x_axis = IMPLOT_AUTO, ImAxis y_axis = IMPLOT_AUTO); +// Cancels a the current plot box selection. +IMPLOT_API void CancelPlotSelection(); -// Returns true if the current plot is being queried or has an active query. Query must be enabled with ImPlotFlags_Query. -IMPLOT_API bool IsPlotQueried(); -// Returns the current plot query bounds. Query must be enabled with ImPlotFlags_Query. -IMPLOT_API ImPlotLimits GetPlotQuery(ImPlotYAxis y_axis = IMPLOT_AUTO); -// Set the current plot query bounds. Query must be enabled with ImPlotFlags_Query. -IMPLOT_API void SetPlotQuery(const ImPlotLimits& query, ImPlotYAxis y_axis = IMPLOT_AUTO); - -//----------------------------------------------------------------------------- -// Algined Plots -//----------------------------------------------------------------------------- +// Hides or shows the next plot item (i.e. as if it were toggled from the legend). +// Use ImPlotCond_Always if you need to forcefully set this every frame. +IMPLOT_API void HideNextItem(bool hidden = true, ImPlotCond cond = ImPlotCond_Once); +// Use the following around calls to Begin/EndPlot to align l/r/t/b padding. // Consider using Begin/EndSubplots first. They are more feature rich and // accomplish the same behaviour by default. The functions below offer lower // level control of plot alignment. -// Align axis padding over multiple plots in a single row or column. If this function returns true, EndAlignedPlots() must be called. #group_id must be unique. -IMPLOT_API bool BeginAlignedPlots(const char* group_id, ImPlotOrientation orientation = ImPlotOrientation_Vertical); +// Align axis padding over multiple plots in a single row or column. #group_id must +// be unique. If this function returns true, EndAlignedPlots() must be called. +IMPLOT_API bool BeginAlignedPlots(const char* group_id, bool vertical = true); // Only call EndAlignedPlots() if BeginAlignedPlots() returns true! IMPLOT_API void EndAlignedPlots(); //----------------------------------------------------------------------------- -// Plot Tools +// [SECTION] Legend Utils //----------------------------------------------------------------------------- -// The following functions MUST be called BETWEEN Begin/EndPlot! - -// Shows an annotation callout at a chosen point. -IMPLOT_API void Annotate(double x, double y, const ImVec2& pix_offset, const char* fmt, ...) IM_FMTARGS(4); -IMPLOT_API void Annotate(double x, double y, const ImVec2& pix_offset, const ImVec4& color, const char* fmt, ...) IM_FMTARGS(5); -IMPLOT_API void AnnotateV(double x, double y, const ImVec2& pix_offset, const char* fmt, va_list args) IM_FMTLIST(4); -IMPLOT_API void AnnotateV(double x, double y, const ImVec2& pix_offset, const ImVec4& color, const char* fmt, va_list args) IM_FMTLIST(5); - -// Same as above, but the annotation will always be clamped to stay inside the plot area. -IMPLOT_API void AnnotateClamped(double x, double y, const ImVec2& pix_offset, const char* fmt, ...) IM_FMTARGS(4); -IMPLOT_API void AnnotateClamped(double x, double y, const ImVec2& pix_offset, const ImVec4& color, const char* fmt, ...) IM_FMTARGS(5); -IMPLOT_API void AnnotateClampedV(double x, double y, const ImVec2& pix_offset, const char* fmt, va_list args) IM_FMTLIST(4); -IMPLOT_API void AnnotateClampedV(double x, double y, const ImVec2& pix_offset, const ImVec4& color, const char* fmt, va_list args) IM_FMTLIST(5); - -// Shows a draggable vertical guide line at an x-value. #col defaults to ImGuiCol_Text. -IMPLOT_API bool DragLineX(const char* id, double* x_value, bool show_label = true, const ImVec4& col = IMPLOT_AUTO_COL, float thickness = 1); -// Shows a draggable horizontal guide line at a y-value. #col defaults to ImGuiCol_Text. -IMPLOT_API bool DragLineY(const char* id, double* y_value, bool show_label = true, const ImVec4& col = IMPLOT_AUTO_COL, float thickness = 1); -// Shows a draggable point at x,y. #col defaults to ImGuiCol_Text. -IMPLOT_API bool DragPoint(const char* id, double* x, double* y, bool show_label = true, const ImVec4& col = IMPLOT_AUTO_COL, float radius = 4); - -//----------------------------------------------------------------------------- -// Legend Utils and Tools -//----------------------------------------------------------------------------- - -// The following functions MUST be called BETWEEN Begin/EndPlot! - -// Set the location of the current plot's (or subplot's) legend. -IMPLOT_API void SetLegendLocation(ImPlotLocation location, ImPlotOrientation orientation = ImPlotOrientation_Vertical, bool outside = false); -// Set the location of the current plot's mouse position text (default = South|East). -IMPLOT_API void SetMousePosLocation(ImPlotLocation location); -// Returns true if a plot item legend entry is hovered. -IMPLOT_API bool IsLegendEntryHovered(const char* label_id); - // Begin a popup for a legend entry. IMPLOT_API bool BeginLegendPopup(const char* label_id, ImGuiMouseButton mouse_button = 1); // End a popup for a legend entry. IMPLOT_API void EndLegendPopup(); +// Returns true if a plot item legend entry is hovered. +IMPLOT_API bool IsLegendEntryHovered(const char* label_id); //----------------------------------------------------------------------------- -// Drag and Drop Utils +// [SECTION] Drag and Drop //----------------------------------------------------------------------------- -// The following functions MUST be called BETWEEN Begin/EndPlot! - // Turns the current plot's plotting area into a drag and drop target. Don't forget to call EndDragDropTarget! -IMPLOT_API bool BeginDragDropTarget(); +IMPLOT_API bool BeginDragDropTargetPlot(); // Turns the current plot's X-axis into a drag and drop target. Don't forget to call EndDragDropTarget! -IMPLOT_API bool BeginDragDropTargetX(); -// Turns the current plot's Y-Axis into a drag and drop target. Don't forget to call EndDragDropTarget! -IMPLOT_API bool BeginDragDropTargetY(ImPlotYAxis axis = ImPlotYAxis_1); +IMPLOT_API bool BeginDragDropTargetAxis(ImAxis axis); // Turns the current plot's legend into a drag and drop target. Don't forget to call EndDragDropTarget! IMPLOT_API bool BeginDragDropTargetLegend(); // Ends a drag and drop target (currently just an alias for ImGui::EndDragDropTarget). IMPLOT_API void EndDragDropTarget(); // NB: By default, plot and axes drag and drop *sources* require holding the Ctrl modifier to initiate the drag. -// You can change the modifier if desired. If ImGuiKeyModFlags_None is provided, the axes will be locked from panning. +// You can change the modifier if desired. If ImGuiModFlags_None is provided, the axes will be locked from panning. -// Turns the current plot's plotting area into a drag and drop source. Don't forget to call EndDragDropSource! -IMPLOT_API bool BeginDragDropSource(ImGuiKeyModFlags key_mods = ImGuiKeyModFlags_Ctrl, ImGuiDragDropFlags flags = 0); -// Turns the current plot's X-axis into a drag and drop source. Don't forget to call EndDragDropSource! -IMPLOT_API bool BeginDragDropSourceX(ImGuiKeyModFlags key_mods = ImGuiKeyModFlags_Ctrl, ImGuiDragDropFlags flags = 0); -// Turns the current plot's Y-axis into a drag and drop source. Don't forget to call EndDragDropSource! -IMPLOT_API bool BeginDragDropSourceY(ImPlotYAxis axis = ImPlotYAxis_1, ImGuiKeyModFlags key_mods = ImGuiKeyModFlags_Ctrl, ImGuiDragDropFlags flags = 0); +// Turns the current plot's plotting area into a drag and drop source. You must hold Ctrl. Don't forget to call EndDragDropSource! +IMPLOT_API bool BeginDragDropSourcePlot(ImGuiDragDropFlags flags = 0); +// Turns the current plot's X-axis into a drag and drop source. You must hold Ctrl. Don't forget to call EndDragDropSource! +IMPLOT_API bool BeginDragDropSourceAxis(ImAxis axis, ImGuiDragDropFlags flags = 0); // Turns an item in the current plot's legend into drag and drop source. Don't forget to call EndDragDropSource! IMPLOT_API bool BeginDragDropSourceItem(const char* label_id, ImGuiDragDropFlags flags = 0); // Ends a drag and drop source (currently just an alias for ImGui::EndDragDropSource). IMPLOT_API void EndDragDropSource(); //----------------------------------------------------------------------------- -// Plot and Item Styling +// [SECTION] Styling //----------------------------------------------------------------------------- // Styling colors in ImPlot works similarly to styling colors in ImGui, but @@ -825,7 +987,7 @@ IMPLOT_API const char* GetStyleColorName(ImPlotCol idx); IMPLOT_API const char* GetMarkerName(ImPlotMarker idx); //----------------------------------------------------------------------------- -// Colormaps +// [SECTION] Colormaps //----------------------------------------------------------------------------- // Item styling is based on colormaps when the relevant ImPlotCol_XXX is set to @@ -875,7 +1037,7 @@ IMPLOT_API ImVec4 GetColormapColor(int idx, ImPlotColormap cmap = IMPLOT_AUTO); IMPLOT_API ImVec4 SampleColormap(float t, ImPlotColormap cmap = IMPLOT_AUTO); // Shows a vertical color scale with linear spaced ticks using the specified color map. Use double hashes to hide label (e.g. "##NoLabel"). -IMPLOT_API void ColormapScale(const char* label, double scale_min, double scale_max, const ImVec2& size = ImVec2(0,0), ImPlotColormap cmap = IMPLOT_AUTO, const char* fmt = "%g"); +IMPLOT_API void ColormapScale(const char* label, double scale_min, double scale_max, const ImVec2& size = ImVec2(0,0), ImPlotColormap cmap = IMPLOT_AUTO, const char* format = "%g"); // Shows a horizontal slider with a colormap gradient background. Optionally returns the color sampled at t in [0 1]. IMPLOT_API bool ColormapSlider(const char* label, float* t, ImVec4* out = NULL, const char* format = "", ImPlotColormap cmap = IMPLOT_AUTO); // Shows a button with a colormap gradient brackground. @@ -891,7 +1053,19 @@ IMPLOT_API bool ColormapButton(const char* label, const ImVec2& size = ImVec2(0, IMPLOT_API void BustColorCache(const char* plot_title_id = NULL); //----------------------------------------------------------------------------- -// Miscellaneous +// [SECTION] Input Mapping +//----------------------------------------------------------------------------- + +// Provides access to input mapping structure for permanant modifications to controls for pan, select, etc. +IMPLOT_API ImPlotInputMap& GetInputMap(); + +// Default input mapping: pan = LMB drag, box select = RMB drag, fit = LMB double click, context menu = RMB click, zoom = scroll. +IMPLOT_API void MapInputDefault(ImPlotInputMap* dst = NULL); +// Reverse input mapping: pan = RMB drag, box select = LMB drag, fit = LMB double click, context menu = RMB click, zoom = scroll. +IMPLOT_API void MapInputReverse(ImPlotInputMap* dst = NULL); + +//----------------------------------------------------------------------------- +// [SECTION] Miscellaneous //----------------------------------------------------------------------------- // Render icons similar to those that appear in legends (nifty for data lists). @@ -910,6 +1084,8 @@ IMPLOT_API void PopPlotClipRect(); IMPLOT_API bool ShowStyleSelector(const char* label); // Shows ImPlot colormap selector dropdown menu. IMPLOT_API bool ShowColormapSelector(const char* label); +// Shows ImPlot input map selector dropdown menu. +IMPLOT_API bool ShowInputMapSelector(const char* label); // Shows ImPlot style editor block (not a window). IMPLOT_API void ShowStyleEditor(ImPlotStyle* ref = NULL); // Add basic help/info block for end users (not a window). @@ -918,10 +1094,59 @@ IMPLOT_API void ShowUserGuide(); IMPLOT_API void ShowMetricsWindow(bool* p_popen = NULL); //----------------------------------------------------------------------------- -// Demo (add implot_demo.cpp to your sources!) +// [SECTION] Demo //----------------------------------------------------------------------------- -// Shows the ImPlot demo window. +// Shows the ImPlot demo window (add implot_demo.cpp to your sources!) IMPLOT_API void ShowDemoWindow(bool* p_open = NULL); } // namespace ImPlot + +//----------------------------------------------------------------------------- +// [SECTION] Obsolete API +//----------------------------------------------------------------------------- + +// The following functions will be removed! Keep your copy of implot up to date! +// Occasionally set '#define IMPLOT_DISABLE_OBSOLETE_FUNCTIONS' to stay ahead. +// If you absolutely must use these functions and do not want to receive compiler +// warnings, set '#define IMPLOT_DISABLE_OBSOLETE_WARNINGS'. + +#ifndef IMPLOT_DISABLE_OBSOLETE_FUNCTIONS + +#ifndef IMPLOT_DISABLE_DEPRECATED_WARNINGS +#if __cplusplus > 201402L +#define IMPLOT_DEPRECATED(method) [[deprecated]] method +#elif defined( __GNUC__ ) && !defined( __INTEL_COMPILER ) && ( __GNUC__ > 3 || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 1 ) ) +#define IMPLOT_DEPRECATED(method) method __attribute__( ( deprecated ) ) +#elif defined( _MSC_VER ) +#define IMPLOT_DEPRECATED(method) __declspec(deprecated) method +#else +#define IMPLOT_DEPRECATED(method) method +#endif +#else +#define IMPLOT_DEPRECATED(method) method +#endif + +enum ImPlotFlagsObsolete_ { + ImPlotFlags_YAxis2 = 1 << 20, + ImPlotFlags_YAxis3 = 1 << 21, +}; + +namespace ImPlot { + +// OBSOLETED in v0.13 -> PLANNED REMOVAL in v1.0 +IMPLOT_DEPRECATED( IMPLOT_API bool BeginPlot(const char* title_id, + const char* x_label, // = NULL, + const char* y_label, // = NULL, + const ImVec2& size = ImVec2(-1,0), + ImPlotFlags flags = ImPlotFlags_None, + ImPlotAxisFlags x_flags = ImPlotAxisFlags_None, + ImPlotAxisFlags y_flags = ImPlotAxisFlags_None, + ImPlotAxisFlags y2_flags = ImPlotAxisFlags_AuxDefault, + ImPlotAxisFlags y3_flags = ImPlotAxisFlags_AuxDefault, + const char* y2_label = NULL, + const char* y3_label = NULL) ); + +} // namespace ImPlot + +#endif diff --git a/lib/external/imgui/include/implot_internal.h b/lib/external/imgui/include/implot_internal.h index c7f40eacf..12b94be15 100644 --- a/lib/external/imgui/include/implot_internal.h +++ b/lib/external/imgui/include/implot_internal.h @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -// ImPlot v0.11 WIP +// ImPlot v0.13 WIP // You may use this file to debug, understand or extend ImPlot features but we // don't provide any guarantee of forward compatibility! @@ -42,6 +42,7 @@ #error Must include implot.h before implot_internal.h #endif + // Support for pre-1.84 versions. ImPool's GetSize() -> GetBufSize() #if (IMGUI_VERSION_NUM < 18303) #define GetBufSize GetSize @@ -54,16 +55,14 @@ // Constants can be changed unless stated otherwise. We may move some of these // to ImPlotStyleVar_ over time. -// The maximum number of supported y-axes (DO NOT CHANGE THIS) -#define IMPLOT_Y_AXES 3 -// Zoom rate for scroll (e.g. 0.1f = 10% plot range every scroll click) -#define IMPLOT_ZOOM_RATE 0.1f // Mimimum allowable timestamp value 01/01/1970 @ 12:00am (UTC) (DO NOT DECREASE THIS) #define IMPLOT_MIN_TIME 0 // Maximum allowable timestamp value 01/01/3000 @ 12:00am (UTC) (DO NOT INCREASE THIS) #define IMPLOT_MAX_TIME 32503680000 // Default label format for axis labels -#define IMPLOT_LABEL_FMT "%g" +#define IMPLOT_LABEL_FORMAT "%g" +// Max character size for tick labels +#define IMPLOT_LABEL_MAX_SIZE 32 // Plot values less than or equal to 0 will be replaced with this on log scale axes #define IMPLOT_LOG_ZERO DBL_MIN @@ -71,6 +70,9 @@ // [SECTION] Macros //----------------------------------------------------------------------------- +#define IMPLOT_NUM_X_AXES ImAxis_Y1 +#define IMPLOT_NUM_Y_AXES (ImAxis_COUNT - IMPLOT_NUM_X_AXES) + // Split ImU32 color into RGB components [0 255] #define IM_COL32_SPLIT_RGB(col,r,g,b) \ ImU32 r = ((col >> IM_COL32_R_SHIFT) & 0xFF); \ @@ -85,7 +87,7 @@ struct ImPlotTick; struct ImPlotAxis; struct ImPlotAxisColor; struct ImPlotItem; -struct ImPlotLegendData; +struct ImPlotLegend; struct ImPlotPlot; struct ImPlotNextPlotData; @@ -93,7 +95,9 @@ struct ImPlotNextPlotData; // [SECTION] Context Pointer //----------------------------------------------------------------------------- +#ifndef GImPlot extern IMPLOT_API ImPlotContext* GImPlot; // Current implicit context pointer +#endif //----------------------------------------------------------------------------- // [SECTION] Generic Helpers @@ -117,11 +121,11 @@ static inline T ImRemap01(T x, T x0, T x1) { return (x - x0) / (x1 - x0); } // Returns always positive modulo (assumes r != 0) static inline int ImPosMod(int l, int r) { return (l % r + r) % r; } // Returns true if val is NAN or INFINITY -static inline bool ImNanOrInf(double val) { return val == HUGE_VAL || val == -HUGE_VAL || isnan(val); } +static inline bool ImNanOrInf(double val) { return !(val >= -DBL_MAX && val <= DBL_MAX) || isnan(val); } // Turns NANs to 0s static inline double ImConstrainNan(double val) { return isnan(val) ? 0 : val; } // Turns infinity to floating point maximums -static inline double ImConstrainInf(double val) { return val == HUGE_VAL ? DBL_MAX : val == -HUGE_VAL ? - DBL_MAX : val; } +static inline double ImConstrainInf(double val) { return val >= DBL_MAX ? DBL_MAX : val <= -DBL_MAX ? - DBL_MAX : val; } // Turns numbers less than or equal to 0 to 0.001 (sort of arbitrary, is there a better way?) static inline double ImConstrainLog(double val) { return val <= 0 ? 0.001f : val; } // Turns numbers less than 0 to zero @@ -211,42 +215,6 @@ static inline ImU32 ImAlphaU32(ImU32 col, float alpha) { return col & ~((ImU32)((1.0f-alpha)*255)< 0) - Pos += ImMin(written, Size-Pos-1); - } -}; - -// Fixed size point array -template -struct ImPlotPointArray { - inline ImPlotPoint& operator[](int i) { return Data[i]; } - inline const ImPlotPoint& operator[](int i) const { return Data[i]; } - inline int Size() { return N; } - ImPlotPoint Data[N]; -}; - //----------------------------------------------------------------------------- // [SECTION] ImPlot Enums //----------------------------------------------------------------------------- @@ -297,23 +265,6 @@ enum ImPlotTimeFmt_ { // default [ 24 Hour Clock ] ImPlotTimeFmt_Hr // 7pm [ 19:00 ] }; -// Input mapping structure, default values listed in the comments. -struct ImPlotInputMap { - ImGuiMouseButton PanButton; // LMB enables panning when held - ImGuiKeyModFlags PanMod; // none optional modifier that must be held for panning - ImGuiMouseButton FitButton; // LMB fits visible data when double clicked - ImGuiMouseButton ContextMenuButton; // RMB opens plot context menu (if enabled) when clicked - ImGuiMouseButton BoxSelectButton; // RMB begins box selection when pressed and confirms selection when released - ImGuiKeyModFlags BoxSelectMod; // none optional modifier that must be held for box selection - ImGuiMouseButton BoxSelectCancelButton; // LMB cancels active box selection when pressed - ImGuiMouseButton QueryButton; // MMB begins query selection when pressed and end query selection when released - ImGuiKeyModFlags QueryMod; // none optional modifier that must be held for query selection - ImGuiKeyModFlags QueryToggleMod; // Ctrl when held, active box selections turn into queries - ImGuiKeyModFlags HorizontalMod; // Alt expands active box selection/query horizontally to plot edge when held - ImGuiKeyModFlags VerticalMod; // Shift expands active box selection/query vertically to plot edge when held - IMPLOT_API ImPlotInputMap(); -}; - //----------------------------------------------------------------------------- // [SECTION] ImPlot Structs //----------------------------------------------------------------------------- @@ -519,6 +470,54 @@ struct ImPlotAnnotationCollection { } }; +struct ImPlotTag { + ImAxis Axis; + double Value; + ImU32 ColorBg; + ImU32 ColorFg; + int TextOffset; +}; + +struct ImPlotTagCollection { + + ImVector Tags; + ImGuiTextBuffer TextBuffer; + int Size; + + ImPlotTagCollection() { Reset(); } + + void AppendV(ImAxis axis, double value, ImU32 bg, ImU32 fg, const char* fmt, va_list args) IM_FMTLIST(6) { + ImPlotTag tag; + tag.Axis = axis; + tag.Value = value; + tag.ColorBg = bg; + tag.ColorFg = fg; + tag.TextOffset = TextBuffer.size(); + Tags.push_back(tag); + TextBuffer.appendfv(fmt, args); + const char nul[] = ""; + TextBuffer.append(nul,nul+1); + Size++; + } + + void Append(ImAxis axis, double value, ImU32 bg, ImU32 fg, const char* fmt, ...) IM_FMTARGS(6) { + va_list args; + va_start(args, fmt); + AppendV(axis, value, bg, fg, fmt, args); + va_end(args); + } + + const char* GetText(int idx) { + return TextBuffer.Buf.Data + Tags[idx].TextOffset; + } + + void Reset() { + Tags.shrink(0); + TextBuffer.Buf.shrink(0); + Size = 0; + } +}; + // Tick mark info struct ImPlotTick { @@ -543,34 +542,29 @@ struct ImPlotTick struct ImPlotTickCollection { ImVector Ticks; ImGuiTextBuffer TextBuffer; - float TotalWidthMax; - float TotalWidth; - float TotalHeight; - float MaxWidth; - float MaxHeight; + ImVec2 MaxSize; + ImVec2 LateSize; int Size; ImPlotTickCollection() { Reset(); } const ImPlotTick& Append(const ImPlotTick& tick) { if (tick.ShowLabel) { - TotalWidth += tick.ShowLabel ? tick.LabelSize.x : 0; - TotalHeight += tick.ShowLabel ? tick.LabelSize.y : 0; - MaxWidth = tick.LabelSize.x > MaxWidth ? tick.LabelSize.x : MaxWidth; - MaxHeight = tick.LabelSize.y > MaxHeight ? tick.LabelSize.y : MaxHeight; + MaxSize.x = tick.LabelSize.x > MaxSize.x ? tick.LabelSize.x : MaxSize.x; + MaxSize.y = tick.LabelSize.y > MaxSize.y ? tick.LabelSize.y : MaxSize.y; } Ticks.push_back(tick); Size++; return Ticks.back(); } - const ImPlotTick& Append(double value, bool major, bool show_label, const char* fmt) { + const ImPlotTick& Append(double value, bool major, bool show_label, ImPlotFormatter formatter, void* data) { ImPlotTick tick(value, major, show_label); - if (show_label && fmt != NULL) { - char temp[32]; + if (show_label && formatter != NULL) { + char buff[IMPLOT_LABEL_MAX_SIZE]; tick.TextOffset = TextBuffer.size(); - snprintf(temp, 32, fmt, tick.PlotPos); - TextBuffer.append(temp, temp + strlen(temp) + 1); + formatter(tick.PlotPos, buff, sizeof(buff), data); + TextBuffer.append(buff, buff + strlen(buff) + 1); tick.LabelSize = ImGui::CalcTextSize(TextBuffer.Buf.Data + tick.TextOffset); } return Append(tick); @@ -580,10 +574,21 @@ struct ImPlotTickCollection { return TextBuffer.Buf.Data + Ticks[idx].TextOffset; } + void OverrideSize(const ImVec2& size) { + MaxSize.x = size.x > MaxSize.x ? size.x : MaxSize.x; + MaxSize.y = size.y > MaxSize.y ? size.y : MaxSize.y; + } + + void OverrideSizeLate(const ImVec2& size) { + LateSize.x = size.x > LateSize.x ? size.x : LateSize.x; + LateSize.y = size.y > LateSize.y ? size.y : LateSize.y; + } + void Reset() { Ticks.shrink(0); TextBuffer.Buf.shrink(0); - TotalWidth = TotalHeight = MaxWidth = MaxHeight = 0; + MaxSize = LateSize; + LateSize = ImVec2(0,0); Size = 0; } }; @@ -591,37 +596,71 @@ struct ImPlotTickCollection { // Axis state information that must persist after EndPlot struct ImPlotAxis { - ImPlotAxisFlags Flags; - ImPlotAxisFlags PreviousFlags; - ImPlotRange Range; - float Pixels; - ImPlotOrientation Orientation; - bool Dragging; - bool ExtHovered; - bool AllHovered; - bool Present; - bool HasRange; - double* LinkedMin; - double* LinkedMax; - ImPlotTime PickerTimeMin, PickerTimeMax; - int PickerLevel; - ImU32 ColorMaj, ColorMin, ColorTxt; - ImGuiCond RangeCond; - ImRect HoverRect; + ImGuiID ID; + ImPlotAxisFlags Flags; + ImPlotAxisFlags PreviousFlags; + ImPlotCond RangeCond; + ImPlotTickCollection Ticks; + ImPlotRange Range; + ImPlotRange FitExtents; + ImPlotAxis* OrthoAxis; + double* LinkedMin; + double* LinkedMax; + int PickerLevel; + ImPlotTime PickerTimeMin, PickerTimeMax; + float Datum1, Datum2; + float PixelMin, PixelMax; + double LinM, LogD; + ImRect HoverRect; + int LabelOffset; + ImU32 ColorMaj, ColorMin, ColorTick, ColorTxt, ColorBg, ColorHov, ColorAct, ColorHiLi; + char FormatSpec[16]; + ImPlotFormatter Formatter; + void* FormatterData; + bool Enabled; + bool Vertical; + bool FitThisFrame; + bool HasRange; + bool HasFormatSpec; + bool ShowDefaultTicks; + bool Hovered; + bool Held; ImPlotAxis() { - Flags = PreviousFlags = ImPlotAxisFlags_None; - Range.Min = 0; - Range.Max = 1; - Dragging = false; - ExtHovered = false; - AllHovered = false; - LinkedMin = LinkedMax = NULL; - PickerLevel = 0; - ColorMaj = ColorMin = ColorTxt = 0; + Flags = PreviousFlags = ImPlotAxisFlags_None; + Range.Min = 0; + Range.Max = 1; + FitExtents.Min = HUGE_VAL; + FitExtents.Max = -HUGE_VAL; + OrthoAxis = NULL; + LinkedMin = LinkedMax = NULL; + PickerLevel = 0; + Datum1 = Datum2 = 0; + PixelMin = PixelMax = 0; + LabelOffset = -1; + ColorMaj = ColorMin = ColorTick = ColorTxt = ColorBg = ColorHov = ColorAct = 0; + ColorHiLi = IM_COL32_BLACK_TRANS; + Formatter = NULL; + FormatterData = NULL; + Enabled = Hovered = Held = FitThisFrame = HasRange = HasFormatSpec = false; + ShowDefaultTicks = true; } - bool SetMin(double _min, bool force=false) { + inline void Reset() { + Enabled = false; + LabelOffset = -1; + HasFormatSpec = false; + Formatter = NULL; + FormatterData = NULL; + ShowDefaultTicks = true; + FitThisFrame = false; + FitExtents.Min = HUGE_VAL; + FitExtents.Max = -HUGE_VAL; + OrthoAxis = NULL; + Ticks.Reset(); + } + + inline bool SetMin(double _min, bool force=false) { if (!force && IsLockedMin()) return false; _min = ImConstrainNan(ImConstrainInf(_min)); @@ -633,10 +672,11 @@ struct ImPlotAxis return false; Range.Min = _min; PickerTimeMin = ImPlotTime::FromDouble(Range.Min); + UpdateTransformCache(); return true; }; - bool SetMax(double _max, bool force=false) { + inline bool SetMax(double _max, bool force=false) { if (!force && IsLockedMax()) return false; _max = ImConstrainNan(ImConstrainInf(_max)); @@ -648,23 +688,25 @@ struct ImPlotAxis return false; Range.Max = _max; PickerTimeMax = ImPlotTime::FromDouble(Range.Max); + UpdateTransformCache(); return true; }; - void SetRange(double _min, double _max) { - Range.Min = _min; - Range.Max = _max; + inline void SetRange(double v1, double v2) { + Range.Min = ImMin(v1,v2); + Range.Max = ImMax(v1,v2); Constrain(); PickerTimeMin = ImPlotTime::FromDouble(Range.Min); PickerTimeMax = ImPlotTime::FromDouble(Range.Max); + UpdateTransformCache(); } - void SetRange(const ImPlotRange& range) { + inline void SetRange(const ImPlotRange& range) { SetRange(range.Min, range.Max); } - void SetAspect(double unit_per_pix) { - double new_size = unit_per_pix * Pixels; + inline void SetAspect(double unit_per_pix) { + double new_size = unit_per_pix * PixelSize(); double delta = (new_size - Range.Size()) * 0.5f; if (IsLocked()) return; @@ -676,9 +718,11 @@ struct ImPlotAxis SetRange(Range.Min - delta, Range.Max + delta); } - double GetAspect() const { return Range.Size() / Pixels; } + inline float PixelSize() const { return ImAbs(PixelMax - PixelMin); } - void Constrain() { + inline double GetAspect() const { return Range.Size() / PixelSize(); } + + inline void Constrain() { Range.Min = ImConstrainNan(ImConstrainInf(Range.Min)); Range.Max = ImConstrainNan(ImConstrainInf(Range.Max)); if (IsLog()) { @@ -693,41 +737,111 @@ struct ImPlotAxis Range.Max = Range.Min + DBL_EPSILON; } - inline bool IsLabeled() const { return !ImHasFlag(Flags, ImPlotAxisFlags_NoTickLabels); } - inline bool IsInverted() const { return ImHasFlag(Flags, ImPlotAxisFlags_Invert); } + inline void UpdateTransformCache() { + LinM = (PixelMax - PixelMin) / Range.Size(); + LogD = IsLog() ? ImLog10(Range.Max / Range.Min) : 0; + } - inline bool IsAutoFitting() const { return ImHasFlag(Flags, ImPlotAxisFlags_AutoFit); } - inline bool IsRangeLocked() const { return HasRange && RangeCond == ImGuiCond_Always; } + inline double PixelsToPlot(float pix) const { + double plt = (pix - PixelMin) / LinM + Range.Min; + if (IsLog()) { + double t = (plt - Range.Min) / Range.Size(); + plt = ImPow(10, t * LogD) * Range.Min; + } + return plt; + } - inline bool IsLockedMin() const { return !Present || IsRangeLocked() || ImHasFlag(Flags, ImPlotAxisFlags_LockMin); } - inline bool IsLockedMax() const { return !Present || IsRangeLocked() || ImHasFlag(Flags, ImPlotAxisFlags_LockMax); } - inline bool IsLocked() const { return IsLockedMin() && IsLockedMax(); } + inline float PlotToPixels(double plt) const { + if (IsLog()) { + plt = plt <= 0.0 ? IMPLOT_LOG_ZERO : plt; + double t = ImLog10(plt / Range.Min) / LogD; + plt = ImLerp(Range.Min, Range.Max, (float)t); + } + return (float)(PixelMin + LinM * (plt - Range.Min)); + } - inline bool IsInputLockedMin() const { return IsLockedMin() || IsAutoFitting(); } - inline bool IsInputLockedMax() const { return IsLockedMax() || IsAutoFitting(); } - inline bool IsInputLocked() const { return IsLocked() || IsAutoFitting(); } + inline void ExtendFit(double v) { + if (!ImNanOrInf(v) && !(IsLog() && v <= 0)) { + FitExtents.Min = v < FitExtents.Min ? v : FitExtents.Min; + FitExtents.Max = v > FitExtents.Max ? v : FitExtents.Max; + } + } - inline bool IsTime() const { return ImHasFlag(Flags, ImPlotAxisFlags_Time); } - inline bool IsLog() const { return ImHasFlag(Flags, ImPlotAxisFlags_LogScale); } + inline void ExtendFitWith(ImPlotAxis& alt, double v, double v_alt) { + if (ImHasFlag(Flags, ImPlotAxisFlags_RangeFit) && !alt.Range.Contains(v_alt)) + return; + if (!ImNanOrInf(v) && !(IsLog() && v <= 0)) { + FitExtents.Min = v < FitExtents.Min ? v : FitExtents.Min; + FitExtents.Max = v > FitExtents.Max ? v : FitExtents.Max; + } + } + + inline void ApplyFit(float padding) { + const double ext_size = FitExtents.Size() * 0.5; + FitExtents.Min -= ext_size * padding; + FitExtents.Max += ext_size * padding; + if (!IsLockedMin() && !ImNanOrInf(FitExtents.Min)) + Range.Min = FitExtents.Min; + if (!IsLockedMax() && !ImNanOrInf(FitExtents.Max)) + Range.Max = FitExtents.Max; + if (ImAlmostEqual(Range.Min, Range.Max)) { + Range.Max += 0.5; + Range.Min -= 0.5; + } + Constrain(); + UpdateTransformCache(); + } + + inline bool HasLabel() const { return LabelOffset != -1 && !ImHasFlag(Flags, ImPlotAxisFlags_NoLabel); } + inline bool HasGridLines() const { return !ImHasFlag(Flags, ImPlotAxisFlags_NoGridLines); } + inline bool HasTickLabels() const { return !ImHasFlag(Flags, ImPlotAxisFlags_NoTickLabels); } + inline bool HasTickMarks() const { return !ImHasFlag(Flags, ImPlotAxisFlags_NoTickMarks); } + inline bool WillRender() const { return Enabled && (HasGridLines() || HasTickLabels() || HasTickMarks()); } + inline bool IsOpposite() const { return ImHasFlag(Flags, ImPlotAxisFlags_Opposite); } + inline bool IsInverted() const { return ImHasFlag(Flags, ImPlotAxisFlags_Invert); } + inline bool IsForeground() const { return ImHasFlag(Flags, ImPlotAxisFlags_Foreground); } + inline bool IsAutoFitting() const { return ImHasFlag(Flags, ImPlotAxisFlags_AutoFit); } + inline bool CanInitFit() const { return !ImHasFlag(Flags, ImPlotAxisFlags_NoInitialFit) && !HasRange && !LinkedMin && !LinkedMax; } + inline bool IsRangeLocked() const { return HasRange && RangeCond == ImPlotCond_Always; } + inline bool IsLockedMin() const { return !Enabled || IsRangeLocked() || ImHasFlag(Flags, ImPlotAxisFlags_LockMin); } + inline bool IsLockedMax() const { return !Enabled || IsRangeLocked() || ImHasFlag(Flags, ImPlotAxisFlags_LockMax); } + inline bool IsLocked() const { return IsLockedMin() && IsLockedMax(); } + inline bool IsInputLockedMin() const { return IsLockedMin() || IsAutoFitting(); } + inline bool IsInputLockedMax() const { return IsLockedMax() || IsAutoFitting(); } + inline bool IsInputLocked() const { return IsLocked() || IsAutoFitting(); } + inline bool IsTime() const { return ImHasFlag(Flags, ImPlotAxisFlags_Time); } + inline bool IsLog() const { return ImHasFlag(Flags, ImPlotAxisFlags_LogScale); } + inline bool HasMenus() const { return !ImHasFlag(Flags, ImPlotAxisFlags_NoMenus); } + + void PushLinks() { + if (LinkedMin) { *LinkedMin = Range.Min; } + if (LinkedMax) { *LinkedMax = Range.Max; } + } + + void PullLinks() { + if (LinkedMin) { SetMin(*LinkedMin,true); } + if (LinkedMax) { SetMax(*LinkedMax,true); } + } }; // Align plots group data struct ImPlotAlignmentData { - ImPlotOrientation Orientation; + bool Vertical; float PadA; float PadB; float PadAMax; float PadBMax; ImPlotAlignmentData() { - Orientation = ImPlotOrientation_Vertical; + Vertical = true; PadA = PadB = PadAMax = PadBMax = 0; } void Begin() { PadAMax = PadBMax = 0; } - void Update(float& pad_a, float& pad_b) { - if (PadAMax < pad_a) PadAMax = pad_a; - if (pad_a < PadA) pad_a = PadA; - if (PadBMax < pad_b) PadBMax = pad_b; - if (pad_b < PadB) pad_b = PadB; + void Update(float& pad_a, float& pad_b, float& delta_a, float& delta_b) { + float bak_a = pad_a; float bak_b = pad_b; + if (PadAMax < pad_a) { PadAMax = pad_a; } + if (PadBMax < pad_b) { PadBMax = pad_b; } + if (pad_a < PadA) { pad_a = PadA; delta_a = pad_a - bak_a; } else { delta_a = 0; } + if (pad_b < PadB) { pad_b = PadB; delta_b = pad_b - bak_b; } else { delta_b = 0; } } void End() { PadA = PadAMax; PadB = PadBMax; } void Reset() { PadA = PadB = PadAMax = PadBMax = 0; } @@ -738,6 +852,7 @@ struct ImPlotItem { ImGuiID ID; ImU32 Color; + ImRect LegendHoverRect; int NameOffset; bool Show; bool LegendHovered; @@ -755,23 +870,24 @@ struct ImPlotItem }; // Holds Legend state -struct ImPlotLegendData +struct ImPlotLegend { + ImPlotLegendFlags Flags; + ImPlotLegendFlags PreviousFlags; + ImPlotLocation Location; + ImPlotLocation PreviousLocation; ImVector Indices; ImGuiTextBuffer Labels; - bool Hovered; - bool Outside; - bool CanGoInside; - bool FlipSideNextFrame; - ImPlotLocation Location; - ImPlotOrientation Orientation; ImRect Rect; + bool Hovered; + bool Held; + bool CanGoInside; - ImPlotLegendData() { - CanGoInside = true; - Hovered = Outside = FlipSideNextFrame = false; - Location = ImPlotLocation_North | ImPlotLocation_West; - Orientation = ImPlotOrientation_Vertical; + ImPlotLegend() { + Flags = PreviousFlags = ImPlotLegendFlags_None; + CanGoInside = true; + Hovered = Held = false; + Location = ImPlotLocation_NorthWest; } void Reset() { Indices.shrink(0); Labels.Buf.shrink(0); } @@ -781,7 +897,7 @@ struct ImPlotLegendData struct ImPlotItemGroup { ImGuiID ID; - ImPlotLegendData Legend; + ImPlotLegend Legend; ImPool ItemPool; int ColormapIdx; @@ -803,47 +919,106 @@ struct ImPlotItemGroup // Holds Plot state information that must persist after EndPlot struct ImPlotPlot { - ImGuiID ID; - ImPlotFlags Flags; - ImPlotFlags PreviousFlags; - ImPlotAxis XAxis; - ImPlotAxis YAxis[IMPLOT_Y_AXES]; - ImPlotItemGroup Items; - ImVec2 SelectStart; - ImRect SelectRect; - ImVec2 QueryStart; - ImRect QueryRect; - bool Initialized; - bool Selecting; - bool Selected; - bool ContextLocked; - bool Querying; - bool Queried; - bool DraggingQuery; - bool FrameHovered; - bool FrameHeld; - bool PlotHovered; - int CurrentYAxis; - ImPlotLocation MousePosLocation; - ImRect FrameRect; - ImRect CanvasRect; - ImRect PlotRect; - ImRect AxesRect; + ImGuiID ID; + ImPlotFlags Flags; + ImPlotFlags PreviousFlags; + ImPlotLocation MouseTextLocation; + ImPlotMouseTextFlags MouseTextFlags; + ImPlotAxis Axes[ImAxis_COUNT]; + ImGuiTextBuffer TextBuffer; + ImPlotItemGroup Items; + ImAxis CurrentX; + ImAxis CurrentY; + ImRect FrameRect; + ImRect CanvasRect; + ImRect PlotRect; + ImRect AxesRect; + ImRect SelectRect; + ImVec2 SelectStart; + int TitleOffset; + bool JustCreated; + bool Initialized; + bool SetupLocked; + bool FitThisFrame; + bool Hovered; + bool Held; + bool Selecting; + bool Selected; + bool ContextLocked; ImPlotPlot() { Flags = PreviousFlags = ImPlotFlags_None; - XAxis.Orientation = ImPlotOrientation_Horizontal; - for (int i = 0; i < IMPLOT_Y_AXES; ++i) - YAxis[i].Orientation = ImPlotOrientation_Vertical; - SelectStart = QueryStart = ImVec2(0,0); - Initialized = Selecting = Selected = ContextLocked = Querying = Queried = DraggingQuery = false; - CurrentYAxis = 0; - MousePosLocation = ImPlotLocation_South | ImPlotLocation_East; + for (int i = 0; i < IMPLOT_NUM_X_AXES; ++i) + XAxis(i).Vertical = false; + for (int i = 0; i < IMPLOT_NUM_Y_AXES; ++i) + YAxis(i).Vertical = true; + SelectStart = ImVec2(0,0); + CurrentX = ImAxis_X1; + CurrentY = ImAxis_Y1; + MouseTextLocation = ImPlotLocation_South | ImPlotLocation_East; + MouseTextFlags = ImPlotMouseTextFlags_None; + TitleOffset = -1; + JustCreated = true; + Initialized = SetupLocked = FitThisFrame = false; + Hovered = Held = Selected = Selecting = ContextLocked = false; } - inline bool AnyYInputLocked() const { return YAxis[0].IsInputLocked() || (YAxis[1].Present ? YAxis[1].IsInputLocked() : false) || (YAxis[2].Present ? YAxis[2].IsInputLocked() : false); } - inline bool AllYInputLocked() const { return YAxis[0].IsInputLocked() && (YAxis[1].Present ? YAxis[1].IsInputLocked() : true ) && (YAxis[2].Present ? YAxis[2].IsInputLocked() : true ); } - inline bool IsInputLocked() const { return XAxis.IsInputLocked() && YAxis[0].IsInputLocked() && YAxis[1].IsInputLocked() && YAxis[2].IsInputLocked(); } + inline bool IsInputLocked() const { + for (int i = 0; i < IMPLOT_NUM_X_AXES; ++i) { + if (!XAxis(i).IsInputLocked()) + return false; + } + for (int i = 0; i < IMPLOT_NUM_Y_AXES; ++i) { + if (!YAxis(i).IsInputLocked()) + return false; + } + return true; + } + + inline void ClearTextBuffer() { TextBuffer.Buf.shrink(0); } + + inline void SetTitle(const char* title) { + if (title && ImGui::FindRenderedTextEnd(title, NULL) != title) { + TitleOffset = TextBuffer.size(); + TextBuffer.append(title, title + strlen(title) + 1); + } + else { + TitleOffset = -1; + } + } + inline bool HasTitle() const { return TitleOffset != -1 && !ImHasFlag(Flags, ImPlotFlags_NoTitle); } + inline const char* GetTitle() const { return TextBuffer.Buf.Data + TitleOffset; } + + inline ImPlotAxis& XAxis(int i) { return Axes[ImAxis_X1 + i]; } + inline const ImPlotAxis& XAxis(int i) const { return Axes[ImAxis_X1 + i]; } + inline ImPlotAxis& YAxis(int i) { return Axes[ImAxis_Y1 + i]; } + inline const ImPlotAxis& YAxis(int i) const { return Axes[ImAxis_Y1 + i]; } + + inline int EnabledAxesX() { + int cnt = 0; + for (int i = 0; i < IMPLOT_NUM_X_AXES; ++i) + cnt += XAxis(i).Enabled; + return cnt; + } + + inline int EnabledAxesY() { + int cnt = 0; + for (int i = 0; i < IMPLOT_NUM_Y_AXES; ++i) + cnt += YAxis(i).Enabled; + return cnt; + } + + inline void SetAxisLabel(ImPlotAxis& axis, const char* label) { + if (label && ImGui::FindRenderedTextEnd(label, NULL) != label) { + axis.LabelOffset = TextBuffer.size(); + TextBuffer.append(label, label + strlen(label) + 1); + } + else { + axis.LabelOffset = -1; + } + } + + inline const char* GetAxisLabel(const ImPlotAxis& axis) const { return TextBuffer.Buf.Data + axis.LabelOffset; } }; // Holds subplot data that must persist afer EndSubplot @@ -866,52 +1041,35 @@ struct ImPlotSubplot { ImVector ColLinkData; float TempSizes[2]; bool FrameHovered; + bool HasTitle; ImPlotSubplot() { Rows = Cols = CurrentIdx = 0; FrameHovered = false; Items.Legend.Location = ImPlotLocation_North; - Items.Legend.Orientation = ImPlotOrientation_Horizontal; + Items.Legend.Flags = ImPlotLegendFlags_Horizontal|ImPlotLegendFlags_Outside; Items.Legend.CanGoInside = false; + HasTitle = false; } }; // Temporary data storage for upcoming plot struct ImPlotNextPlotData { - ImGuiCond XRangeCond; - ImGuiCond YRangeCond[IMPLOT_Y_AXES]; - ImPlotRange XRange; - ImPlotRange YRange[IMPLOT_Y_AXES]; - bool HasXRange; - bool HasYRange[IMPLOT_Y_AXES]; - bool ShowDefaultTicksX; - bool ShowDefaultTicksY[IMPLOT_Y_AXES]; - char FmtX[16]; - char FmtY[IMPLOT_Y_AXES][16]; - bool HasFmtX; - bool HasFmtY[IMPLOT_Y_AXES]; - bool FitX; - bool FitY[IMPLOT_Y_AXES]; - double* LinkedXmin; - double* LinkedXmax; - double* LinkedYmin[IMPLOT_Y_AXES]; - double* LinkedYmax[IMPLOT_Y_AXES]; + ImPlotCond RangeCond[ImAxis_COUNT]; + ImPlotRange Range[ImAxis_COUNT]; + bool HasRange[ImAxis_COUNT]; + bool Fit[ImAxis_COUNT]; + double* LinkedMin[ImAxis_COUNT]; + double* LinkedMax[ImAxis_COUNT]; ImPlotNextPlotData() { Reset(); } void Reset() { - HasXRange = false; - ShowDefaultTicksX = true; - HasFmtX = false; - FitX = false; - LinkedXmin = LinkedXmax = NULL; - for (int i = 0; i < IMPLOT_Y_AXES; ++i) { - HasYRange[i] = false; - ShowDefaultTicksY[i] = true; - HasFmtY[i] = false; - FitY[i] = false; - LinkedYmin[i] = LinkedYmax[i] = NULL; + for (int i = 0; i < ImAxis_COUNT; ++i) { + HasRange[i] = false; + Fit[i] = false; + LinkedMin[i] = LinkedMax[i] = NULL; } } @@ -935,7 +1093,7 @@ struct ImPlotNextItemData { bool RenderMarkerFill; bool HasHidden; bool Hidden; - ImGuiCond HiddenCond; + ImPlotCond HiddenCond; ImPlotNextItemData() { Reset(); } void Reset() { for (int i = 0; i < 5; ++i) @@ -959,34 +1117,12 @@ struct ImPlotContext { // Tick Marks and Labels ImPlotTickCollection CTicks; - ImPlotTickCollection XTicks; - ImPlotTickCollection YTicks[IMPLOT_Y_AXES]; - float YAxisReference[IMPLOT_Y_AXES]; - // Annotation and User Labels + // Annotation and Tabs ImPlotAnnotationCollection Annotations; + ImPlotTagCollection Tags; - // Transformations and Data Extents - ImPlotScale Scales[IMPLOT_Y_AXES]; - ImRect PixelRange[IMPLOT_Y_AXES]; - double Mx; - double My[IMPLOT_Y_AXES]; - double LogDenX; - double LogDenY[IMPLOT_Y_AXES]; - ImPlotRange ExtentsX; - ImPlotRange ExtentsY[IMPLOT_Y_AXES]; - - // Data Fitting Flags - bool FitThisFrame; - bool FitX; - bool FitY[IMPLOT_Y_AXES]; - - // Axis Rendering Flags - bool RenderX; - bool RenderY[IMPLOT_Y_AXES]; - - - // Axis Locking Flags + // Flags bool ChildWindowMade; // Style and Colormaps @@ -1000,7 +1136,8 @@ struct ImPlotContext { tm Tm; // Temp data for general use - ImVector Temp1, Temp2; + ImVector TempDouble1, TempDouble2; + ImVector TempInt1; // Misc int DigitalPlotItemCnt; @@ -1008,7 +1145,8 @@ struct ImPlotContext { ImPlotNextPlotData NextPlotData; ImPlotNextItemData NextItemData; ImPlotInputMap InputMap; - ImPlotPoint MousePos[IMPLOT_Y_AXES]; + bool OpenContextThisFrame; + ImGuiTextBuffer MousePosStringBuilder; // Align plots ImPool AlignmentData; @@ -1031,18 +1169,11 @@ namespace ImPlot { IMPLOT_API void Initialize(ImPlotContext* ctx); // Resets an ImPlot context for the next call to BeginPlot IMPLOT_API void ResetCtxForNextPlot(ImPlotContext* ctx); -// Restes an ImPlot context for the next call to BeginAlignedPlots +// Resets an ImPlot context for the next call to BeginAlignedPlots IMPLOT_API void ResetCtxForNextAlignedPlots(ImPlotContext* ctx); // Resets an ImPlot context for the next call to BeginSubplot IMPLOT_API void ResetCtxForNextSubplot(ImPlotContext* ctx); -//----------------------------------------------------------------------------- -// [SECTION] Input Utils -//----------------------------------------------------------------------------- - -// Allows changing how keyboard/mouse interaction works. -IMPLOT_API ImPlotInputMap& GetInputMap(); - //----------------------------------------------------------------------------- // [SECTION] Plot Utils //----------------------------------------------------------------------------- @@ -1057,6 +1188,17 @@ IMPLOT_API void BustPlotCache(); // Shows a plot's context menu. IMPLOT_API void ShowPlotContextMenu(ImPlotPlot& plot); +//----------------------------------------------------------------------------- +// [SECTION] Setup Utils +//----------------------------------------------------------------------------- + +// Lock Setup and call SetupFinish if necessary. +static inline void SetupLock() { + if (!GImPlot->CurrentPlot->SetupLocked) + SetupFinish(); + GImPlot->CurrentPlot->SetupLocked = true; +} + //----------------------------------------------------------------------------- // [SECTION] Subplot Utils //----------------------------------------------------------------------------- @@ -1089,66 +1231,90 @@ IMPLOT_API void BustItemCache(); // [SECTION] Axis Utils //----------------------------------------------------------------------------- -// Gets the current y-axis for the current plot -static inline int GetCurrentYAxis() { return GImPlot->CurrentPlot->CurrentYAxis; } -// Updates axis ticks, lins, and label colors -IMPLOT_API void UpdateAxisColors(int axis_flag, ImPlotAxis* axis); +// Returns true if any enabled axis is locked from user input. +static inline bool AnyAxesInputLocked(ImPlotAxis* axes, int count) { + for (int i = 0; i < count; ++i) { + if (axes[i].Enabled && axes[i].IsInputLocked()) + return true; + } + return false; +} -// Updates plot-to-pixel space transformation variables for the current plot. -IMPLOT_API void UpdateTransformCache(); -// Gets the XY scale for the current plot and y-axis -static inline ImPlotScale GetCurrentScale() { return GImPlot->Scales[GetCurrentYAxis()]; } +// Returns true if all enabled axes are locked from user input. +static inline bool AllAxesInputLocked(ImPlotAxis* axes, int count) { + for (int i = 0; i < count; ++i) { + if (axes[i].Enabled && !axes[i].IsInputLocked()) + return false; + } + return true; +} + +static inline bool AnyAxesHeld(ImPlotAxis* axes, int count) { + for (int i = 0; i < count; ++i) { + if (axes[i].Enabled && axes[i].Held) + return true; + } + return false; +} + +static inline bool AnyAxesHovered(ImPlotAxis* axes, int count) { + for (int i = 0; i < count; ++i) { + if (axes[i].Enabled && axes[i].Hovered) + return true; + } + return false; +} + +// Gets the XY scale for the current plot and y-axis (TODO) +static inline ImPlotScale GetCurrentScale() { + ImPlotPlot& plot = *GetCurrentPlot(); + ImPlotAxis& x = plot.Axes[plot.CurrentX]; + ImPlotAxis& y = plot.Axes[plot.CurrentY]; + if (!x.IsLog() && !y.IsLog()) + return ImPlotScale_LinLin; + else if (x.IsLog() && !y.IsLog()) + return ImPlotScale_LogLin; + else if (!x.IsLog() && y.IsLog()) + return ImPlotScale_LinLog; + else + return ImPlotScale_LogLog; +} // Returns true if the user has requested data to be fit. -static inline bool FitThisFrame() { return GImPlot->FitThisFrame; } -// Extend the the extents of an axis on current plot so that it encompes v -static inline void FitPointAxis(ImPlotAxis& axis, ImPlotRange& ext, double v) { - if (!ImNanOrInf(v) && !(ImHasFlag(axis.Flags, ImPlotAxisFlags_LogScale) && v <= 0)) { - ext.Min = v < ext.Min ? v : ext.Min; - ext.Max = v > ext.Max ? v : ext.Max; - } -} -// Extend the the extents of an axis on current plot so that it encompes v -static inline void FitPointMultiAxis(ImPlotAxis& axis, ImPlotAxis& alt, ImPlotRange& ext, double v, double v_alt) { - if (ImHasFlag(axis.Flags, ImPlotAxisFlags_RangeFit) && !alt.Range.Contains(v_alt)) - return; - if (!ImNanOrInf(v) && !(ImHasFlag(axis.Flags, ImPlotAxisFlags_LogScale) && v <= 0)) { - ext.Min = v < ext.Min ? v : ext.Min; - ext.Max = v > ext.Max ? v : ext.Max; - } +static inline bool FitThisFrame() { + return GImPlot->CurrentPlot->FitThisFrame; } + // Extends the current plot's axes so that it encompasses a vertical line at x static inline void FitPointX(double x) { - FitPointAxis(GImPlot->CurrentPlot->XAxis, GImPlot->ExtentsX, x); + ImPlotPlot& plot = *GetCurrentPlot(); + ImPlotAxis& x_axis = plot.Axes[plot.CurrentX]; + x_axis.ExtendFit(x); } + // Extends the current plot's axes so that it encompasses a horizontal line at y static inline void FitPointY(double y) { - const ImPlotYAxis y_axis = GImPlot->CurrentPlot->CurrentYAxis; - FitPointAxis(GImPlot->CurrentPlot->YAxis[y_axis], GImPlot->ExtentsY[y_axis], y); + ImPlotPlot& plot = *GetCurrentPlot(); + ImPlotAxis& y_axis = plot.Axes[plot.CurrentY]; + y_axis.ExtendFit(y); } + // Extends the current plot's axes so that it encompasses point p static inline void FitPoint(const ImPlotPoint& p) { - const ImPlotYAxis y_axis = GImPlot->CurrentPlot->CurrentYAxis; - FitPointMultiAxis(GImPlot->CurrentPlot->XAxis, GImPlot->CurrentPlot->YAxis[y_axis], GImPlot->ExtentsX, p.x, p.y); - FitPointMultiAxis(GImPlot->CurrentPlot->YAxis[y_axis], GImPlot->CurrentPlot->XAxis, GImPlot->ExtentsY[y_axis], p.y, p.x); + ImPlotPlot& plot = *GetCurrentPlot(); + ImPlotAxis& x_axis = plot.Axes[plot.CurrentX]; + ImPlotAxis& y_axis = plot.Axes[plot.CurrentY]; + x_axis.ExtendFitWith(y_axis, p.x, p.y); + y_axis.ExtendFitWith(x_axis, p.y, p.x); } // Returns true if two ranges overlap static inline bool RangesOverlap(const ImPlotRange& r1, const ImPlotRange& r2) { return r1.Min <= r2.Max && r2.Min <= r1.Max; } -// Updates pointers for linked axes from axis internal range. -IMPLOT_API void PushLinkedAxis(ImPlotAxis& axis); -// Updates axis internal range from points for linked axes. -IMPLOT_API void PullLinkedAxis(ImPlotAxis& axis); - // Shows an axis's context menu. IMPLOT_API void ShowAxisContextMenu(ImPlotAxis& axis, ImPlotAxis* equal_axis, bool time_allowed = false); -// Get format spec for axis -static inline const char* GetFormatX() { return GImPlot->NextPlotData.HasFmtX ? GImPlot->NextPlotData.FmtX : IMPLOT_LABEL_FMT; } -static inline const char* GetFormatY(ImPlotYAxis y) { return GImPlot->NextPlotData.HasFmtY[y] ? GImPlot->NextPlotData.FmtY[y] : IMPLOT_LABEL_FMT; } - //----------------------------------------------------------------------------- // [SECTION] Legend Utils //----------------------------------------------------------------------------- @@ -1156,13 +1322,13 @@ static inline const char* GetFormatY(ImPlotYAxis y) { return GImPlot->NextPlotDa // Gets the position of an inner rect that is located inside of an outer rect according to an ImPlotLocation and padding amount. IMPLOT_API ImVec2 GetLocationPos(const ImRect& outer_rect, const ImVec2& inner_size, ImPlotLocation location, const ImVec2& pad = ImVec2(0,0)); // Calculates the bounding box size of a legend -IMPLOT_API ImVec2 CalcLegendSize(ImPlotItemGroup& items, const ImVec2& pad, const ImVec2& spacing, ImPlotOrientation orientation); +IMPLOT_API ImVec2 CalcLegendSize(ImPlotItemGroup& items, const ImVec2& pad, const ImVec2& spacing, bool vertical); // Renders legend entries into a bounding box -IMPLOT_API bool ShowLegendEntries(ImPlotItemGroup& items, const ImRect& legend_bb, bool interactable, const ImVec2& pad, const ImVec2& spacing, ImPlotOrientation orientation, ImDrawList& DrawList); +IMPLOT_API bool ShowLegendEntries(ImPlotItemGroup& items, const ImRect& legend_bb, bool interactable, const ImVec2& pad, const ImVec2& spacing, bool vertical, ImDrawList& DrawList); // Shows an alternate legend for the plot identified by #title_id, outside of the plot frame (can be called before or after of Begin/EndPlot but must occur in the same ImGui window!). -IMPLOT_API void ShowAltLegend(const char* title_id, ImPlotOrientation orientation = ImPlotOrientation_Vertical, const ImVec2 size = ImVec2(0,0), bool interactable = true); +IMPLOT_API void ShowAltLegend(const char* title_id, bool vertical = true, const ImVec2 size = ImVec2(0,0), bool interactable = true); // Shows an legends's context menu. -IMPLOT_API bool ShowLegendContextMenu(ImPlotLegendData& legend, bool visible); +IMPLOT_API bool ShowLegendContextMenu(ImPlotLegend& legend, bool visible); //----------------------------------------------------------------------------- // [SECTION] Tick Utils @@ -1172,16 +1338,16 @@ IMPLOT_API bool ShowLegendContextMenu(ImPlotLegendData& legend, bool visible); IMPLOT_API void LabelTickTime(ImPlotTick& tick, ImGuiTextBuffer& buffer, const ImPlotTime& t, ImPlotDateTimeFmt fmt); // Populates a list of ImPlotTicks with normal spaced and formatted ticks -IMPLOT_API void AddTicksDefault(const ImPlotRange& range, float pix, ImPlotOrientation orn, ImPlotTickCollection& ticks, const char* fmt); +IMPLOT_API void AddTicksDefault(const ImPlotRange& range, float pix, bool vertical, ImPlotTickCollection& ticks, ImPlotFormatter formatter, void* data); // Populates a list of ImPlotTicks with logarithmic space and formatted ticks -IMPLOT_API void AddTicksLogarithmic(const ImPlotRange& range, float pix, ImPlotOrientation orn, ImPlotTickCollection& ticks, const char* fmt); +IMPLOT_API void AddTicksLogarithmic(const ImPlotRange& range, float pix, bool vertical, ImPlotTickCollection& ticks, ImPlotFormatter formatter, void* data); +// Populates a list of ImPlotTicks with custom spaced and labeled ticks +IMPLOT_API void AddTicksCustom(const double* values, const char* const labels[], int n, ImPlotTickCollection& ticks, ImPlotFormatter formatter, void* data); // Populates a list of ImPlotTicks with time formatted ticks. IMPLOT_API void AddTicksTime(const ImPlotRange& range, float plot_width, ImPlotTickCollection& ticks); -// Populates a list of ImPlotTicks with custom spaced and labeled ticks -IMPLOT_API void AddTicksCustom(const double* values, const char* const labels[], int n, ImPlotTickCollection& ticks, const char* fmt); // Create a a string label for a an axis value -IMPLOT_API int LabelAxisValue(const ImPlotAxis& axis, const ImPlotTickCollection& ticks, double value, char* buff, int size); +IMPLOT_API void LabelAxisValue(const ImPlotAxis& axis, double value, char* buff, int size, bool round = false); //----------------------------------------------------------------------------- // [SECTION] Styling Utils @@ -1211,7 +1377,7 @@ static inline ImVec2 CalcTextSizeVertical(const char *text) { return ImVec2(sz.y, sz.x); } // Returns white or black text given background color -static inline ImU32 CalcTextColor(const ImVec4& bg) { return (bg.x * 0.299 + bg.y * 0.587 + bg.z * 0.114) > 0.5 ? IM_COL32_BLACK : IM_COL32_WHITE; } +static inline ImU32 CalcTextColor(const ImVec4& bg) { return (bg.x * 0.299f + bg.y * 0.587f + bg.z * 0.114f) > 0.5f ? IM_COL32_BLACK : IM_COL32_WHITE; } static inline ImU32 CalcTextColor(ImU32 bg) { return CalcTextColor(ImGui::ColorConvertU32ToFloat4(bg)); } // Lightens or darkens a color for hover static inline ImU32 CalcHoverColor(ImU32 col) { return ImMixU32(col, CalcTextColor(col), 32); } @@ -1267,13 +1433,6 @@ void FillRange(ImVector& buffer, int n, T vmin, T vmax) { } } -// Offsets and strides a data buffer -template -static inline T OffsetAndStride(const T* data, int idx, int , int , int stride) { - // idx = ImPosMod(offset + idx, count); - return *(const T*)(const void*)((const unsigned char*)data + (size_t)idx * stride); -} - // Calculate histogram bin counts and widths template static inline void CalculateBins(const T* values, int count, ImPlotBin meth, const ImPlotRange& range, int& bins_out, double& width_out) { diff --git a/lib/external/imgui/include/imstb_rectpack.h b/lib/external/imgui/include/imstb_rectpack.h index 395895216..f6917e7a6 100644 --- a/lib/external/imgui/include/imstb_rectpack.h +++ b/lib/external/imgui/include/imstb_rectpack.h @@ -1,15 +1,19 @@ // [DEAR IMGUI] -// This is a slightly modified version of stb_rect_pack.h 1.00. -// Those changes would need to be pushed into nothings/stb: -// - Added STBRP__CDECL +// This is a slightly modified version of stb_rect_pack.h 1.01. // Grep for [DEAR IMGUI] to find the changes. - -// stb_rect_pack.h - v1.00 - public domain - rectangle packing +// +// stb_rect_pack.h - v1.01 - public domain - rectangle packing // Sean Barrett 2014 // // Useful for e.g. packing rectangular textures into an atlas. // Does not do rotation. // +// Before #including, +// +// #define STB_RECT_PACK_IMPLEMENTATION +// +// in the file that you want to have the implementation. +// // Not necessarily the awesomest packing method, but better than // the totally naive one in stb_truetype (which is primarily what // this is meant to replace). @@ -41,6 +45,7 @@ // // Version history: // +// 1.01 (2021-07-11) always use large rect mode, expose STBRP__MAXVAL in public section // 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles // 0.99 (2019-02-07) warning fixes // 0.11 (2017-03-03) return packing success/fail result @@ -81,11 +86,10 @@ typedef struct stbrp_context stbrp_context; typedef struct stbrp_node stbrp_node; typedef struct stbrp_rect stbrp_rect; -#ifdef STBRP_LARGE_RECTS typedef int stbrp_coord; -#else -typedef unsigned short stbrp_coord; -#endif + +#define STBRP__MAXVAL 0x7fffffff +// Mostly for internal use, but this is the maximum supported coordinate value. STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects); // Assign packed locations to rectangles. The rectangles are of type @@ -213,10 +217,9 @@ struct stbrp_context #define STBRP_ASSERT assert #endif -// [DEAR IMGUI] Added STBRP__CDECL #ifdef _MSC_VER #define STBRP__NOTUSED(v) (void)(v) -#define STBRP__CDECL __cdecl +#define STBRP__CDECL __cdecl #else #define STBRP__NOTUSED(v) (void)sizeof(v) #define STBRP__CDECL @@ -262,9 +265,6 @@ STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_ou STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes) { int i; -#ifndef STBRP_LARGE_RECTS - STBRP_ASSERT(width <= 0xffff && height <= 0xffff); -#endif for (i=0; i < num_nodes-1; ++i) nodes[i].next = &nodes[i+1]; @@ -283,11 +283,7 @@ STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, context->extra[0].y = 0; context->extra[0].next = &context->extra[1]; context->extra[1].x = (stbrp_coord) width; -#ifdef STBRP_LARGE_RECTS context->extra[1].y = (1<<30); -#else - context->extra[1].y = 65535; -#endif context->extra[1].next = NULL; } @@ -433,7 +429,7 @@ static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int widt if (y <= best_y) { if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) { best_x = xpos; - STBRP_ASSERT(y <= best_y); + //STBRP_ASSERT(y <= best_y); [DEAR IMGUI] best_y = y; best_waste = waste; best = prev; @@ -529,7 +525,6 @@ static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, i return res; } -// [DEAR IMGUI] Added STBRP__CDECL static int STBRP__CDECL rect_height_compare(const void *a, const void *b) { const stbrp_rect *p = (const stbrp_rect *) a; @@ -541,7 +536,6 @@ static int STBRP__CDECL rect_height_compare(const void *a, const void *b) return (p->w > q->w) ? -1 : (p->w < q->w); } -// [DEAR IMGUI] Added STBRP__CDECL static int STBRP__CDECL rect_original_order(const void *a, const void *b) { const stbrp_rect *p = (const stbrp_rect *) a; @@ -549,12 +543,6 @@ static int STBRP__CDECL rect_original_order(const void *a, const void *b) return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed); } -#ifdef STBRP_LARGE_RECTS -#define STBRP__MAXVAL 0xffffffff -#else -#define STBRP__MAXVAL 0xffff -#endif - STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects) { int i, all_rects_packed = 1; diff --git a/lib/external/imgui/include/imstb_textedit.h b/lib/external/imgui/include/imstb_textedit.h index 2c635b27d..75a159dac 100644 --- a/lib/external/imgui/include/imstb_textedit.h +++ b/lib/external/imgui/include/imstb_textedit.h @@ -1,10 +1,10 @@ // [DEAR IMGUI] -// This is a slightly modified version of stb_textedit.h 1.13. +// This is a slightly modified version of stb_textedit.h 1.14. // Those changes would need to be pushed into nothings/stb: // - Fix in stb_textedit_discard_redo (see https://github.com/nothings/stb/issues/321) // Grep for [DEAR IMGUI] to find the changes. -// stb_textedit.h - v1.13 - public domain - Sean Barrett +// stb_textedit.h - v1.14 - public domain - Sean Barrett // Development of this library was sponsored by RAD Game Tools // // This C header file implements the guts of a multi-line text-editing @@ -35,6 +35,7 @@ // // VERSION HISTORY // +// 1.14 (2021-07-11) page up/down, various fixes // 1.13 (2019-02-07) fix bug in undo size management // 1.12 (2018-01-29) user can change STB_TEXTEDIT_KEYTYPE, fix redo to avoid crash // 1.11 (2017-03-03) fix HOME on last line, dragging off single-line textfield @@ -58,6 +59,7 @@ // Ulf Winklemann: move-by-word in 1.1 // Fabian Giesen: secondary key inputs in 1.5 // Martins Mozeiko: STB_TEXTEDIT_memmove in 1.6 +// Louis Schnellbach: page up/down in 1.14 // // Bugfixes: // Scott Graham @@ -93,8 +95,8 @@ // moderate sizes. The undo system does no memory allocations, so // it grows STB_TexteditState by the worst-case storage which is (in bytes): // -// [4 + 3 * sizeof(STB_TEXTEDIT_POSITIONTYPE)] * STB_TEXTEDIT_UNDOSTATE_COUNT -// + sizeof(STB_TEXTEDIT_CHARTYPE) * STB_TEXTEDIT_UNDOCHAR_COUNT +// [4 + 3 * sizeof(STB_TEXTEDIT_POSITIONTYPE)] * STB_TEXTEDIT_UNDOSTATECOUNT +// + sizeof(STB_TEXTEDIT_CHARTYPE) * STB_TEXTEDIT_UNDOCHARCOUNT // // // Implementation mode: @@ -716,10 +718,6 @@ static int stb_textedit_paste_internal(STB_TEXTEDIT_STRING *str, STB_TexteditSta state->has_preferred_x = 0; return 1; } - // [DEAR IMGUI] - //// remove the undo since we didn't actually insert the characters - //if (state->undostate.undo_point) - // --state->undostate.undo_point; // note: paste failure will leave deleted selection, may be restored with an undo (see https://github.com/nothings/stb/issues/734 for details) return 0; } diff --git a/lib/external/imgui/include/imstb_truetype.h b/lib/external/imgui/include/imstb_truetype.h index 48c202617..643d37899 100644 --- a/lib/external/imgui/include/imstb_truetype.h +++ b/lib/external/imgui/include/imstb_truetype.h @@ -1,10 +1,19 @@ // [DEAR IMGUI] -// This is a slightly modified version of stb_truetype.h 1.20. +// This is a slightly modified version of stb_truetype.h 1.26. // Mostly fixing for compiler and static analyzer warnings. // Grep for [DEAR IMGUI] to find the changes. -// stb_truetype.h - v1.20 - public domain -// authored from 2009-2016 by Sean Barrett / RAD Game Tools +// stb_truetype.h - v1.26 - public domain +// authored from 2009-2021 by Sean Barrett / RAD Game Tools +// +// ======================================================================= +// +// NO SECURITY GUARANTEE -- DO NOT USE THIS ON UNTRUSTED FONT FILES +// +// This library does no range checking of the offsets found in the file, +// meaning an attacker can use it to read arbitrary memory. +// +// ======================================================================= // // This library processes TrueType files: // parse files @@ -37,11 +46,11 @@ // Daniel Ribeiro Maciel // // Bug/warning reports/fixes: -// "Zer" on mollyrocket Fabian "ryg" Giesen -// Cass Everitt Martins Mozeiko -// stoiko (Haemimont Games) Cap Petschulat -// Brian Hook Omar Cornut -// Walter van Niftrik github:aloucks +// "Zer" on mollyrocket Fabian "ryg" Giesen github:NiLuJe +// Cass Everitt Martins Mozeiko github:aloucks +// stoiko (Haemimont Games) Cap Petschulat github:oyvindjam +// Brian Hook Omar Cornut github:vassvik +// Walter van Niftrik Ryan Griege // David Gow Peter LaValle // David Given Sergey Popov // Ivan-Assen Ivanov Giumo X. Clanjor @@ -49,11 +58,17 @@ // Johan Duparc Thomas Fields // Hou Qiming Derek Vinyard // Rob Loach Cort Stratton -// Kenney Phillis Jr. github:oyvindjam -// Brian Costabile github:vassvik +// Kenney Phillis Jr. Brian Costabile +// Ken Voskuil (kaesve) // // VERSION HISTORY // +// 1.26 (2021-08-28) fix broken rasterizer +// 1.25 (2021-07-11) many fixes +// 1.24 (2020-02-05) fix warning +// 1.23 (2020-02-02) query SVG data for glyphs; query whole kerning table (but only kern not GPOS) +// 1.22 (2019-08-11) minimize missing-glyph duplication; fix kerning if both 'GPOS' and 'kern' are defined +// 1.21 (2019-02-25) fix warning // 1.20 (2019-02-07) PackFontRange skips missing codepoints; GetScaleFontVMetrics() // 1.19 (2018-02-11) GPOS kerning, STBTT_fmod // 1.18 (2018-01-29) add missing function @@ -248,19 +263,6 @@ // recommend it. // // -// SOURCE STATISTICS (based on v0.6c, 2050 LOC) -// -// Documentation & header file 520 LOC \___ 660 LOC documentation -// Sample code 140 LOC / -// Truetype parsing 620 LOC ---- 620 LOC TrueType -// Software rasterization 240 LOC \. -// Curve tessellation 120 LOC \__ 550 LOC Bitmap creation -// Bitmap management 100 LOC / -// Baked bitmap interface 70 LOC / -// Font name matching & access 150 LOC ---- 150 -// C runtime library abstraction 60 LOC ---- 60 -// -// // PERFORMANCE MEASUREMENTS FOR 1.06: // // 32-bit 64-bit @@ -275,8 +277,8 @@ //// SAMPLE PROGRAMS //// // -// Incomplete text-in-3d-api example, which draws quads properly aligned to be lossless -// +// Incomplete text-in-3d-api example, which draws quads properly aligned to be lossless. +// See "tests/truetype_demo_win32.c" for a complete version. #if 0 #define STB_TRUETYPE_IMPLEMENTATION // force following include to generate implementation #include "stb_truetype.h" @@ -302,6 +304,8 @@ void my_stbtt_initfont(void) void my_stbtt_print(float x, float y, char *text) { // assume orthographic projection with units = screen pixels, origin at top left + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, ftex); glBegin(GL_QUADS); @@ -309,10 +313,10 @@ void my_stbtt_print(float x, float y, char *text) if (*text >= 32 && *text < 128) { stbtt_aligned_quad q; stbtt_GetBakedQuad(cdata, 512,512, *text-32, &x,&y,&q,1);//1=opengl & d3d10+,0=d3d9 - glTexCoord2f(q.s0,q.t1); glVertex2f(q.x0,q.y0); - glTexCoord2f(q.s1,q.t1); glVertex2f(q.x1,q.y0); - glTexCoord2f(q.s1,q.t0); glVertex2f(q.x1,q.y1); - glTexCoord2f(q.s0,q.t0); glVertex2f(q.x0,q.y1); + glTexCoord2f(q.s0,q.t0); glVertex2f(q.x0,q.y0); + glTexCoord2f(q.s1,q.t0); glVertex2f(q.x1,q.y0); + glTexCoord2f(q.s1,q.t1); glVertex2f(q.x1,q.y1); + glTexCoord2f(q.s0,q.t1); glVertex2f(q.x0,q.y1); } ++text; } @@ -719,7 +723,7 @@ struct stbtt_fontinfo int numGlyphs; // number of glyphs, needed for range checking - int loca,head,glyf,hhea,hmtx,kern,gpos; // table locations as offset from start of .ttf + int loca,head,glyf,hhea,hmtx,kern,gpos,svg; // table locations as offset from start of .ttf int index_map; // a cmap mapping for our chosen character encoding int indexToLocFormat; // format needed to map from glyph index to glyph @@ -802,6 +806,18 @@ STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, STBTT_DEF int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1); // as above, but takes one or more glyph indices for greater efficiency +typedef struct stbtt_kerningentry +{ + int glyph1; // use stbtt_FindGlyphIndex + int glyph2; + int advance; +} stbtt_kerningentry; + +STBTT_DEF int stbtt_GetKerningTableLength(const stbtt_fontinfo *info); +STBTT_DEF int stbtt_GetKerningTable(const stbtt_fontinfo *info, stbtt_kerningentry* table, int table_length); +// Retrieves a complete list of all of the kerning pairs provided by the font +// stbtt_GetKerningTable never writes more than table_length entries and returns how many entries it did write. +// The table will be sorted by (a.glyph1 == b.glyph1)?(a.glyph2 < b.glyph2):(a.glyph1 < b.glyph1) ////////////////////////////////////////////////////////////////////////////// // @@ -846,6 +862,12 @@ STBTT_DEF int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, s STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *vertices); // frees the data allocated above +STBTT_DEF unsigned char *stbtt_FindSVGDoc(const stbtt_fontinfo *info, int gl); +STBTT_DEF int stbtt_GetCodepointSVG(const stbtt_fontinfo *info, int unicode_codepoint, const char **svg); +STBTT_DEF int stbtt_GetGlyphSVG(const stbtt_fontinfo *info, int gl, const char **svg); +// fills svg with the character's SVG data. +// returns data size or 0 if SVG not found. + ////////////////////////////////////////////////////////////////////////////// // // BITMAP RENDERING @@ -1347,6 +1369,22 @@ static stbtt__buf stbtt__get_subrs(stbtt__buf cff, stbtt__buf fontdict) return stbtt__cff_get_index(&cff); } +// since most people won't use this, find this table the first time it's needed +static int stbtt__get_svg(stbtt_fontinfo *info) +{ + stbtt_uint32 t; + if (info->svg < 0) { + t = stbtt__find_table(info->data, info->fontstart, "SVG "); + if (t) { + stbtt_uint32 offset = ttULONG(info->data + t + 2); + info->svg = t + offset; + } else { + info->svg = 0; + } + } + return info->svg; +} + static int stbtt_InitFont_internal(stbtt_fontinfo *info, unsigned char *data, int fontstart) { stbtt_uint32 cmap, t; @@ -1426,6 +1464,8 @@ static int stbtt_InitFont_internal(stbtt_fontinfo *info, unsigned char *data, in else info->numGlyphs = 0xffff; + info->svg = -1; + // find a cmap encoding table we understand *now* to avoid searching // later. (todo: could make this installable) // the same regardless of glyph. @@ -1509,12 +1549,12 @@ STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codep search += 2; { - stbtt_uint16 offset, start; + stbtt_uint16 offset, start, last; stbtt_uint16 item = (stbtt_uint16) ((search - endCount) >> 1); - STBTT_assert(unicode_codepoint <= ttUSHORT(data + endCount + 2*item)); start = ttUSHORT(data + index_map + 14 + segcount*2 + 2 + 2*item); - if (unicode_codepoint < start) + last = ttUSHORT(data + endCount + 2*item); + if (unicode_codepoint < start || unicode_codepoint > last) return 0; offset = ttUSHORT(data + index_map + 14 + segcount*6 + 2 + 2*item); @@ -1774,7 +1814,7 @@ static int stbtt__GetGlyphShapeTT(const stbtt_fontinfo *info, int glyph_index, s } } num_vertices = stbtt__close_shape(vertices, num_vertices, was_off, start_off, sx,sy,scx,scy,cx,cy); - } else if (numberOfContours == -1) { + } else if (numberOfContours < 0) { // Compound shapes. int more = 1; stbtt_uint8 *comp = data + g + 10; @@ -1841,7 +1881,7 @@ static int stbtt__GetGlyphShapeTT(const stbtt_fontinfo *info, int glyph_index, s if (comp_verts) STBTT_free(comp_verts, info->userdata); return 0; } - if (num_vertices > 0) STBTT_memcpy(tmp, vertices, num_vertices*sizeof(stbtt_vertex)); //-V595 + if (num_vertices > 0 && vertices) STBTT_memcpy(tmp, vertices, num_vertices*sizeof(stbtt_vertex)); STBTT_memcpy(tmp+num_vertices, comp_verts, comp_num_verts*sizeof(stbtt_vertex)); if (vertices) STBTT_free(vertices, info->userdata); vertices = tmp; @@ -1851,9 +1891,6 @@ static int stbtt__GetGlyphShapeTT(const stbtt_fontinfo *info, int glyph_index, s // More components ? more = flags & (1<<5); } - } else if (numberOfContours < 0) { - // @TODO other compound variations? - STBTT_assert(0); } else { // numberOfCounters == 0, do nothing } @@ -2107,7 +2144,7 @@ static int stbtt__run_charstring(const stbtt_fontinfo *info, int glyph_index, st subrs = stbtt__cid_get_glyph_subrs(info, glyph_index); has_subrs = 1; } - // fallthrough + // FALLTHROUGH case 0x1D: // callgsubr if (sp < 1) return STBTT__CSERR("call(g|)subr stack"); v = (int) s[--sp]; @@ -2212,7 +2249,7 @@ static int stbtt__run_charstring(const stbtt_fontinfo *info, int glyph_index, st } break; default: - if (b0 != 255 && b0 != 28 && (b0 < 32 || b0 > 254)) //-V560 + if (b0 != 255 && b0 != 28 && b0 < 32) return STBTT__CSERR("reserved operator"); // push immediate @@ -2282,7 +2319,49 @@ STBTT_DEF void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_inde } } -static int stbtt__GetGlyphKernInfoAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2) +STBTT_DEF int stbtt_GetKerningTableLength(const stbtt_fontinfo *info) +{ + stbtt_uint8 *data = info->data + info->kern; + + // we only look at the first table. it must be 'horizontal' and format 0. + if (!info->kern) + return 0; + if (ttUSHORT(data+2) < 1) // number of tables, need at least 1 + return 0; + if (ttUSHORT(data+8) != 1) // horizontal flag must be set in format + return 0; + + return ttUSHORT(data+10); +} + +STBTT_DEF int stbtt_GetKerningTable(const stbtt_fontinfo *info, stbtt_kerningentry* table, int table_length) +{ + stbtt_uint8 *data = info->data + info->kern; + int k, length; + + // we only look at the first table. it must be 'horizontal' and format 0. + if (!info->kern) + return 0; + if (ttUSHORT(data+2) < 1) // number of tables, need at least 1 + return 0; + if (ttUSHORT(data+8) != 1) // horizontal flag must be set in format + return 0; + + length = ttUSHORT(data+10); + if (table_length < length) + length = table_length; + + for (k = 0; k < length; k++) + { + table[k].glyph1 = ttUSHORT(data+18+(k*6)); + table[k].glyph2 = ttUSHORT(data+20+(k*6)); + table[k].advance = ttSHORT(data+22+(k*6)); + } + + return length; +} + +static int stbtt__GetGlyphKernInfoAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2) { stbtt_uint8 *data = info->data + info->kern; stbtt_uint32 needle, straw; @@ -2312,245 +2391,225 @@ static int stbtt__GetGlyphKernInfoAdvance(const stbtt_fontinfo *info, int glyph return 0; } -static stbtt_int32 stbtt__GetCoverageIndex(stbtt_uint8 *coverageTable, int glyph) +static stbtt_int32 stbtt__GetCoverageIndex(stbtt_uint8 *coverageTable, int glyph) { - stbtt_uint16 coverageFormat = ttUSHORT(coverageTable); - switch(coverageFormat) { - case 1: { - stbtt_uint16 glyphCount = ttUSHORT(coverageTable + 2); + stbtt_uint16 coverageFormat = ttUSHORT(coverageTable); + switch (coverageFormat) { + case 1: { + stbtt_uint16 glyphCount = ttUSHORT(coverageTable + 2); - // Binary search. - stbtt_int32 l=0, r=glyphCount-1, m; - int straw, needle=glyph; - while (l <= r) { - stbtt_uint8 *glyphArray = coverageTable + 4; - stbtt_uint16 glyphID; - m = (l + r) >> 1; - glyphID = ttUSHORT(glyphArray + 2 * m); - straw = glyphID; - if (needle < straw) - r = m - 1; - else if (needle > straw) - l = m + 1; - else { - return m; - } + // Binary search. + stbtt_int32 l=0, r=glyphCount-1, m; + int straw, needle=glyph; + while (l <= r) { + stbtt_uint8 *glyphArray = coverageTable + 4; + stbtt_uint16 glyphID; + m = (l + r) >> 1; + glyphID = ttUSHORT(glyphArray + 2 * m); + straw = glyphID; + if (needle < straw) + r = m - 1; + else if (needle > straw) + l = m + 1; + else { + return m; } - } break; + } + break; + } - case 2: { - stbtt_uint16 rangeCount = ttUSHORT(coverageTable + 2); - stbtt_uint8 *rangeArray = coverageTable + 4; + case 2: { + stbtt_uint16 rangeCount = ttUSHORT(coverageTable + 2); + stbtt_uint8 *rangeArray = coverageTable + 4; - // Binary search. - stbtt_int32 l=0, r=rangeCount-1, m; - int strawStart, strawEnd, needle=glyph; - while (l <= r) { - stbtt_uint8 *rangeRecord; - m = (l + r) >> 1; - rangeRecord = rangeArray + 6 * m; - strawStart = ttUSHORT(rangeRecord); - strawEnd = ttUSHORT(rangeRecord + 2); - if (needle < strawStart) - r = m - 1; - else if (needle > strawEnd) - l = m + 1; - else { - stbtt_uint16 startCoverageIndex = ttUSHORT(rangeRecord + 4); - return startCoverageIndex + glyph - strawStart; - } + // Binary search. + stbtt_int32 l=0, r=rangeCount-1, m; + int strawStart, strawEnd, needle=glyph; + while (l <= r) { + stbtt_uint8 *rangeRecord; + m = (l + r) >> 1; + rangeRecord = rangeArray + 6 * m; + strawStart = ttUSHORT(rangeRecord); + strawEnd = ttUSHORT(rangeRecord + 2); + if (needle < strawStart) + r = m - 1; + else if (needle > strawEnd) + l = m + 1; + else { + stbtt_uint16 startCoverageIndex = ttUSHORT(rangeRecord + 4); + return startCoverageIndex + glyph - strawStart; } - } break; + } + break; + } - default: { - // There are no other cases. - STBTT_assert(0); - } break; - } + default: return -1; // unsupported + } - return -1; + return -1; } static stbtt_int32 stbtt__GetGlyphClass(stbtt_uint8 *classDefTable, int glyph) { - stbtt_uint16 classDefFormat = ttUSHORT(classDefTable); - switch(classDefFormat) - { - case 1: { - stbtt_uint16 startGlyphID = ttUSHORT(classDefTable + 2); - stbtt_uint16 glyphCount = ttUSHORT(classDefTable + 4); - stbtt_uint8 *classDef1ValueArray = classDefTable + 6; + stbtt_uint16 classDefFormat = ttUSHORT(classDefTable); + switch (classDefFormat) + { + case 1: { + stbtt_uint16 startGlyphID = ttUSHORT(classDefTable + 2); + stbtt_uint16 glyphCount = ttUSHORT(classDefTable + 4); + stbtt_uint8 *classDef1ValueArray = classDefTable + 6; - if (glyph >= startGlyphID && glyph < startGlyphID + glyphCount) - return (stbtt_int32)ttUSHORT(classDef1ValueArray + 2 * (glyph - startGlyphID)); + if (glyph >= startGlyphID && glyph < startGlyphID + glyphCount) + return (stbtt_int32)ttUSHORT(classDef1ValueArray + 2 * (glyph - startGlyphID)); + break; + } - // [DEAR IMGUI] Commented to fix static analyzer warning - //classDefTable = classDef1ValueArray + 2 * glyphCount; - } break; + case 2: { + stbtt_uint16 classRangeCount = ttUSHORT(classDefTable + 2); + stbtt_uint8 *classRangeRecords = classDefTable + 4; - case 2: { - stbtt_uint16 classRangeCount = ttUSHORT(classDefTable + 2); - stbtt_uint8 *classRangeRecords = classDefTable + 4; + // Binary search. + stbtt_int32 l=0, r=classRangeCount-1, m; + int strawStart, strawEnd, needle=glyph; + while (l <= r) { + stbtt_uint8 *classRangeRecord; + m = (l + r) >> 1; + classRangeRecord = classRangeRecords + 6 * m; + strawStart = ttUSHORT(classRangeRecord); + strawEnd = ttUSHORT(classRangeRecord + 2); + if (needle < strawStart) + r = m - 1; + else if (needle > strawEnd) + l = m + 1; + else + return (stbtt_int32)ttUSHORT(classRangeRecord + 4); + } + break; + } - // Binary search. - stbtt_int32 l=0, r=classRangeCount-1, m; - int strawStart, strawEnd, needle=glyph; - while (l <= r) { - stbtt_uint8 *classRangeRecord; - m = (l + r) >> 1; - classRangeRecord = classRangeRecords + 6 * m; - strawStart = ttUSHORT(classRangeRecord); - strawEnd = ttUSHORT(classRangeRecord + 2); - if (needle < strawStart) - r = m - 1; - else if (needle > strawEnd) - l = m + 1; - else - return (stbtt_int32)ttUSHORT(classRangeRecord + 4); - } + default: + return -1; // Unsupported definition type, return an error. + } - // [DEAR IMGUI] Commented to fix static analyzer warning - //classDefTable = classRangeRecords + 6 * classRangeCount; - } break; - - default: { - // There are no other cases. - STBTT_assert(0); - } break; - } - - return -1; + // "All glyphs not assigned to a class fall into class 0". (OpenType spec) + return 0; } // Define to STBTT_assert(x) if you want to break on unimplemented formats. #define STBTT_GPOS_TODO_assert(x) -static stbtt_int32 stbtt__GetGlyphGPOSInfoAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2) +static stbtt_int32 stbtt__GetGlyphGPOSInfoAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2) { - stbtt_uint16 lookupListOffset; - stbtt_uint8 *lookupList; - stbtt_uint16 lookupCount; - stbtt_uint8 *data; - stbtt_int32 i; + stbtt_uint16 lookupListOffset; + stbtt_uint8 *lookupList; + stbtt_uint16 lookupCount; + stbtt_uint8 *data; + stbtt_int32 i, sti; - if (!info->gpos) return 0; + if (!info->gpos) return 0; - data = info->data + info->gpos; + data = info->data + info->gpos; - if (ttUSHORT(data+0) != 1) return 0; // Major version 1 - if (ttUSHORT(data+2) != 0) return 0; // Minor version 0 + if (ttUSHORT(data+0) != 1) return 0; // Major version 1 + if (ttUSHORT(data+2) != 0) return 0; // Minor version 0 - lookupListOffset = ttUSHORT(data+8); - lookupList = data + lookupListOffset; - lookupCount = ttUSHORT(lookupList); + lookupListOffset = ttUSHORT(data+8); + lookupList = data + lookupListOffset; + lookupCount = ttUSHORT(lookupList); - for (i=0; i= pairSetCount) return 0; - // Binary search. - while (l <= r) { - stbtt_uint16 secondGlyph; - stbtt_uint8 *pairValue; - m = (l + r) >> 1; - pairValue = pairValueArray + (2 + valueRecordPairSizeInBytes) * m; - secondGlyph = ttUSHORT(pairValue); - straw = secondGlyph; - if (needle < straw) - r = m - 1; - else if (needle > straw) - l = m + 1; - else { - stbtt_int16 xAdvance = ttSHORT(pairValue + 2); - return xAdvance; - } - } - } break; + needle=glyph2; + r=pairValueCount-1; + l=0; - case 2: { - stbtt_uint16 valueFormat1 = ttUSHORT(table + 4); - stbtt_uint16 valueFormat2 = ttUSHORT(table + 6); + // Binary search. + while (l <= r) { + stbtt_uint16 secondGlyph; + stbtt_uint8 *pairValue; + m = (l + r) >> 1; + pairValue = pairValueArray + (2 + valueRecordPairSizeInBytes) * m; + secondGlyph = ttUSHORT(pairValue); + straw = secondGlyph; + if (needle < straw) + r = m - 1; + else if (needle > straw) + l = m + 1; + else { + stbtt_int16 xAdvance = ttSHORT(pairValue + 2); + return xAdvance; + } + } + } else + return 0; + break; + } - stbtt_uint16 classDef1Offset = ttUSHORT(table + 8); - stbtt_uint16 classDef2Offset = ttUSHORT(table + 10); - int glyph1class = stbtt__GetGlyphClass(table + classDef1Offset, glyph1); - int glyph2class = stbtt__GetGlyphClass(table + classDef2Offset, glyph2); + case 2: { + stbtt_uint16 valueFormat1 = ttUSHORT(table + 4); + stbtt_uint16 valueFormat2 = ttUSHORT(table + 6); + if (valueFormat1 == 4 && valueFormat2 == 0) { // Support more formats? + stbtt_uint16 classDef1Offset = ttUSHORT(table + 8); + stbtt_uint16 classDef2Offset = ttUSHORT(table + 10); + int glyph1class = stbtt__GetGlyphClass(table + classDef1Offset, glyph1); + int glyph2class = stbtt__GetGlyphClass(table + classDef2Offset, glyph2); - stbtt_uint16 class1Count = ttUSHORT(table + 12); - stbtt_uint16 class2Count = ttUSHORT(table + 14); - STBTT_assert(glyph1class < class1Count); - STBTT_assert(glyph2class < class2Count); + stbtt_uint16 class1Count = ttUSHORT(table + 12); + stbtt_uint16 class2Count = ttUSHORT(table + 14); + stbtt_uint8 *class1Records, *class2Records; + stbtt_int16 xAdvance; - // TODO: Support more formats. - STBTT_GPOS_TODO_assert(valueFormat1 == 4); - if (valueFormat1 != 4) return 0; - STBTT_GPOS_TODO_assert(valueFormat2 == 0); - if (valueFormat2 != 0) return 0; + if (glyph1class < 0 || glyph1class >= class1Count) return 0; // malformed + if (glyph2class < 0 || glyph2class >= class2Count) return 0; // malformed - if (glyph1class >= 0 && glyph1class < class1Count && glyph2class >= 0 && glyph2class < class2Count) { - stbtt_uint8 *class1Records = table + 16; - stbtt_uint8 *class2Records = class1Records + 2 * (glyph1class * class2Count); - stbtt_int16 xAdvance = ttSHORT(class2Records + 2 * glyph2class); - return xAdvance; - } - } break; - - default: { - // There are no other cases. - STBTT_assert(0); - break; - } // [DEAR IMGUI] removed ; - } - } - break; - } // [DEAR IMGUI] removed ; + class1Records = table + 16; + class2Records = class1Records + 2 * (glyph1class * class2Count); + xAdvance = ttSHORT(class2Records + 2 * glyph2class); + return xAdvance; + } else + return 0; + break; + } default: - // TODO: Implement other stuff. - break; - } - } + return 0; // Unsupported position format + } + } + } - return 0; + return 0; } STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int g1, int g2) @@ -2559,8 +2618,7 @@ STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int g1, int if (info->gpos) xAdvance += stbtt__GetGlyphGPOSInfoAdvance(info, g1, g2); - - if (info->kern) + else if (info->kern) xAdvance += stbtt__GetGlyphKernInfoAdvance(info, g1, g2); return xAdvance; @@ -2621,6 +2679,45 @@ STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *v) STBTT_free(v, info->userdata); } +STBTT_DEF stbtt_uint8 *stbtt_FindSVGDoc(const stbtt_fontinfo *info, int gl) +{ + int i; + stbtt_uint8 *data = info->data; + stbtt_uint8 *svg_doc_list = data + stbtt__get_svg((stbtt_fontinfo *) info); + + int numEntries = ttUSHORT(svg_doc_list); + stbtt_uint8 *svg_docs = svg_doc_list + 2; + + for(i=0; i= ttUSHORT(svg_doc)) && (gl <= ttUSHORT(svg_doc + 2))) + return svg_doc; + } + return 0; +} + +STBTT_DEF int stbtt_GetGlyphSVG(const stbtt_fontinfo *info, int gl, const char **svg) +{ + stbtt_uint8 *data = info->data; + stbtt_uint8 *svg_doc; + + if (info->svg == 0) + return 0; + + svg_doc = stbtt_FindSVGDoc(info, gl); + if (svg_doc != NULL) { + *svg = (char *) data + info->svg + ttULONG(svg_doc + 4); + return ttULONG(svg_doc + 8); + } else { + return 0; + } +} + +STBTT_DEF int stbtt_GetCodepointSVG(const stbtt_fontinfo *info, int unicode_codepoint, const char **svg) +{ + return stbtt_GetGlyphSVG(info, stbtt_FindGlyphIndex(info, unicode_codepoint), svg); +} + ////////////////////////////////////////////////////////////////////////////// // // antialiasing software rasterizer @@ -2970,6 +3067,23 @@ static void stbtt__handle_clipped_edge(float *scanline, int x, stbtt__active_edg } } +static float stbtt__sized_trapezoid_area(float height, float top_width, float bottom_width) +{ + STBTT_assert(top_width >= 0); + STBTT_assert(bottom_width >= 0); + return (top_width + bottom_width) / 2.0f * height; +} + +static float stbtt__position_trapezoid_area(float height, float tx0, float tx1, float bx0, float bx1) +{ + return stbtt__sized_trapezoid_area(height, tx1 - tx0, bx1 - bx0); +} + +static float stbtt__sized_triangle_area(float height, float width) +{ + return height * width / 2; +} + static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill, int len, stbtt__active_edge *e, float y_top) { float y_bottom = y_top+1; @@ -3024,13 +3138,13 @@ static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill, float height; // simple case, only spans one pixel int x = (int) x_top; - height = sy1 - sy0; + height = (sy1 - sy0) * e->direction; STBTT_assert(x >= 0 && x < len); - scanline[x] += e->direction * (1-((x_top - x) + (x_bottom-x))/2) * height; - scanline_fill[x] += e->direction * height; // everything right of this pixel is filled + scanline[x] += stbtt__position_trapezoid_area(height, x_top, x+1.0f, x_bottom, x+1.0f); + scanline_fill[x] += height; // everything right of this pixel is filled } else { int x,x1,x2; - float y_crossing, step, sign, area; + float y_crossing, y_final, step, sign, area; // covers 2+ pixels if (x_top > x_bottom) { // flip scanline vertically; signed area is the same @@ -3042,32 +3156,83 @@ static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill, dx = -dx; dy = -dy; t = x0, x0 = xb, xb = t; - // [DEAR IMGUI] Fix static analyzer warning - (void)dx; // [ImGui: fix static analyzer warning] } + STBTT_assert(dy >= 0); + STBTT_assert(dx >= 0); x1 = (int) x_top; x2 = (int) x_bottom; // compute intersection with y axis at x1+1 - y_crossing = (x1+1 - x0) * dy + y_top; + y_crossing = y_top + dy * (x1+1 - x0); + + // compute intersection with y axis at x2 + y_final = y_top + dy * (x2 - x0); + + // x1 x_top x2 x_bottom + // y_top +------|-----+------------+------------+--------|---+------------+ + // | | | | | | + // | | | | | | + // sy0 | Txxxxx|............|............|............|............| + // y_crossing | *xxxxx.......|............|............|............| + // | | xxxxx..|............|............|............| + // | | /- xx*xxxx........|............|............| + // | | dy < | xxxxxx..|............|............| + // y_final | | \- | xx*xxx.........|............| + // sy1 | | | | xxxxxB...|............| + // | | | | | | + // | | | | | | + // y_bottom +------------+------------+------------+------------+------------+ + // + // goal is to measure the area covered by '.' in each pixel + + // if x2 is right at the right edge of x1, y_crossing can blow up, github #1057 + // @TODO: maybe test against sy1 rather than y_bottom? + if (y_crossing > y_bottom) + y_crossing = y_bottom; sign = e->direction; - // area of the rectangle covered from y0..y_crossing - area = sign * (y_crossing-sy0); - // area of the triangle (x_top,y0), (x+1,y0), (x+1,y_crossing) - scanline[x1] += area * (1-((x_top - x1)+(x1+1-x1))/2); - step = sign * dy; + // area of the rectangle covered from sy0..y_crossing + area = sign * (y_crossing-sy0); + + // area of the triangle (x_top,sy0), (x1+1,sy0), (x1+1,y_crossing) + scanline[x1] += stbtt__sized_triangle_area(area, x1+1 - x_top); + + // check if final y_crossing is blown up; no test case for this + if (y_final > y_bottom) { + int denom = (x2 - (x1+1)); + y_final = y_bottom; + if (denom != 0) { // [DEAR IMGUI] Avoid div by zero (https://github.com/nothings/stb/issues/1316) + dy = (y_final - y_crossing ) / denom; // if denom=0, y_final = y_crossing, so y_final <= y_bottom + } + } + + // in second pixel, area covered by line segment found in first pixel + // is always a rectangle 1 wide * the height of that line segment; this + // is exactly what the variable 'area' stores. it also gets a contribution + // from the line segment within it. the THIRD pixel will get the first + // pixel's rectangle contribution, the second pixel's rectangle contribution, + // and its own contribution. the 'own contribution' is the same in every pixel except + // the leftmost and rightmost, a trapezoid that slides down in each pixel. + // the second pixel's contribution to the third pixel will be the + // rectangle 1 wide times the height change in the second pixel, which is dy. + + step = sign * dy * 1; // dy is dy/dx, change in y for every 1 change in x, + // which multiplied by 1-pixel-width is how much pixel area changes for each step in x + // so the area advances by 'step' every time + for (x = x1+1; x < x2; ++x) { - scanline[x] += area + step/2; + scanline[x] += area + step/2; // area of trapezoid is 1*step/2 area += step; } - y_crossing += dy * (x2 - (x1+1)); + STBTT_assert(STBTT_fabs(area) <= 1.01f); // accumulated error from area += step unless we round step down + STBTT_assert(sy1 > y_final-0.01f); - STBTT_assert(STBTT_fabs(area) <= 1.01f); - - scanline[x2] += area + sign * (1-((x2-x2)+(x_bottom-x2))/2) * (sy1-y_crossing); + // area covered in the last pixel is the rectangle from all the pixels to the left, + // plus the trapezoid filled by the line segment in this pixel all the way to the right edge + scanline[x2] += area + sign * stbtt__position_trapezoid_area(sy1-y_final, (float) x2, x2+1.0f, x_bottom, x2+1.0f); + // the rest of the line is filled based on the total height of the line segment in this pixel scanline_fill[x2] += sign * (sy1-sy0); } } else { @@ -3075,6 +3240,9 @@ static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill, // clipping logic. since this does not match the intended use // of this library, we use a different, very slow brute // force implementation + // note though that this does happen some of the time because + // x_top and x_bottom can be extrapolated at the top & bottom of + // the shape and actually lie outside the bounding box int x; for (x=0; x < len; ++x) { // cases: @@ -3989,6 +4157,7 @@ static float stbtt__oversample_shift(int oversample) STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects) { int i,j,k; + int missing_glyph_added = 0; k=0; for (i=0; i < num_ranges; ++i) { @@ -4000,7 +4169,7 @@ STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, const stb int x0,y0,x1,y1; int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j]; int glyph = stbtt_FindGlyphIndex(info, codepoint); - if (glyph == 0 && spc->skip_missing) { + if (glyph == 0 && (spc->skip_missing || missing_glyph_added)) { rects[k].w = rects[k].h = 0; } else { stbtt_GetGlyphBitmapBoxSubpixel(info,glyph, @@ -4010,6 +4179,8 @@ STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, const stb &x0,&y0,&x1,&y1); rects[k].w = (stbrp_coord) (x1-x0 + spc->padding + spc->h_oversample-1); rects[k].h = (stbrp_coord) (y1-y0 + spc->padding + spc->v_oversample-1); + if (glyph == 0) + missing_glyph_added = 1; } ++k; } @@ -4044,7 +4215,7 @@ STBTT_DEF void stbtt_MakeGlyphBitmapSubpixelPrefilter(const stbtt_fontinfo *info // rects array must be big enough to accommodate all characters in the given ranges STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects) { - int i,j,k, return_value = 1; + int i,j,k, missing_glyph = -1, return_value = 1; // save current values int old_h_over = spc->h_oversample; @@ -4109,6 +4280,13 @@ STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, const bc->yoff = (float) y0 * recip_v + sub_y; bc->xoff2 = (x0 + r->w) * recip_h + sub_x; bc->yoff2 = (y0 + r->h) * recip_v + sub_y; + + if (glyph == 0) + missing_glyph = j; + } else if (spc->skip_missing) { + return_value = 0; + } else if (r->was_packed && r->w == 0 && r->h == 0 && missing_glyph >= 0) { + ranges[i].chardata_for_range[j] = ranges[i].chardata_for_range[missing_glyph]; } else { return_value = 0; // if any fail, report failure } @@ -4132,7 +4310,7 @@ STBTT_DEF void stbtt_PackFontRangesPackRects(stbtt_pack_context *spc, stbrp_rect STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, const unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges) { stbtt_fontinfo info; - int i,j,n, return_value; // [DEAR IMGUI] removed = 1 + int i, j, n, return_value; // [DEAR IMGUI] removed = 1; //stbrp_context *context = (stbrp_context *) spc->pack_info; stbrp_rect *rects; @@ -4301,15 +4479,14 @@ static int stbtt__compute_crossings_x(float x, float y, int nverts, stbtt_vertex float y_frac; int winding = 0; - orig[0] = x; - //orig[1] = y; // [DEAR IMGUI] commented double assignment - // make sure y never passes through a vertex of the shape y_frac = (float) STBTT_fmod(y, 1.0f); if (y_frac < 0.01f) y += 0.01f; else if (y_frac > 0.99f) y -= 0.01f; + + orig[0] = x; orig[1] = y; // test a ray from (-infinity,y) to (x,y) @@ -4371,35 +4548,35 @@ static float stbtt__cuberoot( float x ) return (float) STBTT_pow( x,1.0f/3.0f); } -// x^3 + c*x^2 + b*x + a = 0 +// x^3 + a*x^2 + b*x + c = 0 static int stbtt__solve_cubic(float a, float b, float c, float* r) { - float s = -a / 3; - float p = b - a*a / 3; - float q = a * (2*a*a - 9*b) / 27 + c; + float s = -a / 3; + float p = b - a*a / 3; + float q = a * (2*a*a - 9*b) / 27 + c; float p3 = p*p*p; - float d = q*q + 4*p3 / 27; - if (d >= 0) { - float z = (float) STBTT_sqrt(d); - float u = (-q + z) / 2; - float v = (-q - z) / 2; - u = stbtt__cuberoot(u); - v = stbtt__cuberoot(v); - r[0] = s + u + v; - return 1; - } else { - float u = (float) STBTT_sqrt(-p/3); - float v = (float) STBTT_acos(-STBTT_sqrt(-27/p3) * q / 2) / 3; // p3 must be negative, since d is negative - float m = (float) STBTT_cos(v); + float d = q*q + 4*p3 / 27; + if (d >= 0) { + float z = (float) STBTT_sqrt(d); + float u = (-q + z) / 2; + float v = (-q - z) / 2; + u = stbtt__cuberoot(u); + v = stbtt__cuberoot(v); + r[0] = s + u + v; + return 1; + } else { + float u = (float) STBTT_sqrt(-p/3); + float v = (float) STBTT_acos(-STBTT_sqrt(-27/p3) * q / 2) / 3; // p3 must be negative, since d is negative + float m = (float) STBTT_cos(v); float n = (float) STBTT_cos(v-3.141592/2)*1.732050808f; - r[0] = s + u * 2 * m; - r[1] = s - u * (m + n); - r[2] = s - u * (m - n); + r[0] = s + u * 2 * m; + r[1] = s - u * (m + n); + r[2] = s - u * (m - n); //STBTT_assert( STBTT_fabs(((r[0]+a)*r[0]+b)*r[0]+c) < 0.05f); // these asserts may not be safe at all scales, though they're in bezier t parameter units so maybe? //STBTT_assert( STBTT_fabs(((r[1]+a)*r[1]+b)*r[1]+c) < 0.05f); //STBTT_assert( STBTT_fabs(((r[2]+a)*r[2]+b)*r[2]+c) < 0.05f); - return 3; + return 3; } } @@ -4410,12 +4587,7 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc int w,h; unsigned char *data; - // if one scale is 0, use same scale for both - if (scale_x == 0) scale_x = scale_y; - if (scale_y == 0) { - if (scale_x == 0) return NULL; // if both scales are 0, return NULL - scale_y = scale_x; - } + if (scale == 0) return NULL; stbtt_GetGlyphBitmapBoxSubpixel(info, glyph, scale, scale, 0.0f,0.0f, &ix0,&iy0,&ix1,&iy1); @@ -4481,18 +4653,17 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc for (i=0; i < num_verts; ++i) { float x0 = verts[i].x*scale_x, y0 = verts[i].y*scale_y; - // check against every point here rather than inside line/curve primitives -- @TODO: wrong if multiple 'moves' in a row produce a garbage point, and given culling, probably more efficient to do within line/curve - float dist2 = (x0-sx)*(x0-sx) + (y0-sy)*(y0-sy); - if (dist2 < min_dist*min_dist) - min_dist = (float) STBTT_sqrt(dist2); - - if (verts[i].type == STBTT_vline) { + if (verts[i].type == STBTT_vline && precompute[i] != 0.0f) { float x1 = verts[i-1].x*scale_x, y1 = verts[i-1].y*scale_y; + float dist,dist2 = (x0-sx)*(x0-sx) + (y0-sy)*(y0-sy); + if (dist2 < min_dist*min_dist) + min_dist = (float) STBTT_sqrt(dist2); + // coarse culling against bbox //if (sx > STBTT_min(x0,x1)-min_dist && sx < STBTT_max(x0,x1)+min_dist && // sy > STBTT_min(y0,y1)-min_dist && sy < STBTT_max(y0,y1)+min_dist) - float dist = (float) STBTT_fabs((x1-x0)*(y0-sy) - (y1-y0)*(x0-sx)) * precompute[i]; + dist = (float) STBTT_fabs((x1-x0)*(y0-sy) - (y1-y0)*(x0-sx)) * precompute[i]; STBTT_assert(i != 0); if (dist < min_dist) { // check position along line @@ -4519,7 +4690,8 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc float ax = x1-x0, ay = y1-y0; float bx = x0 - 2*x1 + x2, by = y0 - 2*y1 + y2; float mx = x0 - sx, my = y0 - sy; - float res[3],px,py,t,it; + float res[3] = {0.f,0.f,0.f}; + float px,py,t,it,dist2; float a_inv = precompute[i]; if (a_inv == 0.0) { // if a_inv is 0, it's 2nd degree so use quadratic formula float a = 3*(ax*bx + ay*by); @@ -4546,6 +4718,10 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc float d = (mx*ax+my*ay) * a_inv; num = stbtt__solve_cubic(b, c, d, res); } + dist2 = (x0-sx)*(x0-sx) + (y0-sy)*(y0-sy); + if (dist2 < min_dist*min_dist) + min_dist = (float) STBTT_sqrt(dist2); + if (num >= 1 && res[0] >= 0.0f && res[0] <= 1.0f) { t = res[0], it = 1.0f - t; px = it*it*x0 + 2*t*it*x1 + t*t*x2; @@ -4805,6 +4981,12 @@ STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const // FULL VERSION HISTORY // +// 1.25 (2021-07-11) many fixes +// 1.24 (2020-02-05) fix warning +// 1.23 (2020-02-02) query SVG data for glyphs; query whole kerning table (but only kern not GPOS) +// 1.22 (2019-08-11) minimize missing-glyph duplication; fix kerning if both 'GPOS' and 'kern' are defined +// 1.21 (2019-02-25) fix warning +// 1.20 (2019-02-07) PackFontRange skips missing codepoints; GetScaleFontVMetrics() // 1.19 (2018-02-11) OpenType GPOS kerning (horizontal only), STBTT_fmod // 1.18 (2018-01-29) add missing function // 1.17 (2017-07-23) make more arguments const; doc fix diff --git a/lib/external/imgui/source/TextEditor.cpp b/lib/external/imgui/source/TextEditor.cpp index 83cb66254..10fdf2b4c 100644 --- a/lib/external/imgui/source/TextEditor.cpp +++ b/lib/external/imgui/source/TextEditor.cpp @@ -649,7 +649,7 @@ void TextEditor::HandleKeyboardInputs() { Cut(); else if (ctrl && !shift && !alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_A))) SelectAll(); - else if (!IsReadOnly() && !ctrl && !shift && !alt && (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Enter)) || ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_KeyPadEnter)))) + else if (!IsReadOnly() && !ctrl && !shift && !alt && (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Enter)) || ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_KeypadEnter)))) EnterCharacter('\n', false); else if (!IsReadOnly() && !ctrl && !alt && ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Tab))) EnterCharacter('\t', shift); diff --git a/lib/external/imgui/source/cimgui.cpp b/lib/external/imgui/source/cimgui.cpp index fd54663f6..373224941 100644 --- a/lib/external/imgui/source/cimgui.cpp +++ b/lib/external/imgui/source/cimgui.cpp @@ -1,11 +1,18 @@ //This file is automatically generated by generator.lua from https://github.com/cimgui/cimgui -//based on imgui.h file version "1.86" from Dear ImGui https://github.com/ocornut/imgui -//with imgui_internal.h api +//based on imgui.h file version "1.89 WIP" from Dear ImGui https://github.com/ocornut/imgui //docking branch - -#include "imgui.h" +#ifdef IMGUI_ENABLE_FREETYPE +#ifndef CIMGUI_FREETYPE +#error "IMGUI_FREETYPE should be defined for Freetype linking" +#endif +#else #ifdef CIMGUI_FREETYPE -#include "./imgui/misc/freetype/imgui_freetype.h" +#error "IMGUI_FREETYPE should not be defined without freetype generated cimgui" +#endif +#endif +#include "imgui.h" +#ifdef IMGUI_ENABLE_FREETYPE +#include "imgui_freetype.h" #endif #include "imgui_internal.h" #include "cimgui.h" @@ -84,6 +91,10 @@ CIMGUI_API void igShowMetricsWindow(bool* p_open) { return ImGui::ShowMetricsWindow(p_open); } +CIMGUI_API void igShowDebugLogWindow(bool* p_open) +{ + return ImGui::ShowDebugLogWindow(p_open); +} CIMGUI_API void igShowStackToolWindow(bool* p_open) { return ImGui::ShowStackToolWindow(p_open); @@ -280,11 +291,11 @@ CIMGUI_API float igGetScrollY() { return ImGui::GetScrollY(); } -CIMGUI_API void igSetScrollX_Float(float scroll_x) +CIMGUI_API void igSetScrollX(float scroll_x) { return ImGui::SetScrollX(scroll_x); } -CIMGUI_API void igSetScrollY_Float(float scroll_y) +CIMGUI_API void igSetScrollY(float scroll_y) { return ImGui::SetScrollY(scroll_y); } @@ -304,11 +315,11 @@ CIMGUI_API void igSetScrollHereY(float center_y_ratio) { return ImGui::SetScrollHereY(center_y_ratio); } -CIMGUI_API void igSetScrollFromPosX_Float(float local_x,float center_x_ratio) +CIMGUI_API void igSetScrollFromPosX(float local_x,float center_x_ratio) { return ImGui::SetScrollFromPosX(local_x,center_x_ratio); } -CIMGUI_API void igSetScrollFromPosY_Float(float local_y,float center_y_ratio) +CIMGUI_API void igSetScrollFromPosY(float local_y,float center_y_ratio) { return ImGui::SetScrollFromPosY(local_y,center_y_ratio); } @@ -622,14 +633,6 @@ CIMGUI_API bool igArrowButton(const char* str_id,ImGuiDir dir) { return ImGui::ArrowButton(str_id,dir); } -CIMGUI_API void igImage(ImTextureID user_texture_id,const ImVec2 size,const ImVec2 uv0,const ImVec2 uv1,const ImVec4 tint_col,const ImVec4 border_col) -{ - return ImGui::Image(user_texture_id,size,uv0,uv1,tint_col,border_col); -} -CIMGUI_API bool igImageButton(ImTextureID user_texture_id,const ImVec2 size,const ImVec2 uv0,const ImVec2 uv1,int frame_padding,const ImVec4 bg_col,const ImVec4 tint_col) -{ - return ImGui::ImageButton(user_texture_id,size,uv0,uv1,frame_padding,bg_col,tint_col); -} CIMGUI_API bool igCheckbox(const char* label,bool* v) { return ImGui::Checkbox(label,v); @@ -658,6 +661,14 @@ CIMGUI_API void igBullet() { return ImGui::Bullet(); } +CIMGUI_API void igImage(ImTextureID user_texture_id,const ImVec2 size,const ImVec2 uv0,const ImVec2 uv1,const ImVec4 tint_col,const ImVec4 border_col) +{ + return ImGui::Image(user_texture_id,size,uv0,uv1,tint_col,border_col); +} +CIMGUI_API bool igImageButton(ImTextureID user_texture_id,const ImVec2 size,const ImVec2 uv0,const ImVec2 uv1,int frame_padding,const ImVec4 bg_col,const ImVec4 tint_col) +{ + return ImGui::ImageButton(user_texture_id,size,uv0,uv1,frame_padding,bg_col,tint_col); +} CIMGUI_API bool igBeginCombo(const char* label,const char* preview_value,ImGuiComboFlags flags) { return ImGui::BeginCombo(label,preview_value,flags); @@ -854,7 +865,7 @@ CIMGUI_API bool igColorPicker4(const char* label,float col[4],ImGuiColorEditFlag { return ImGui::ColorPicker4(label,col,flags,ref_col); } -CIMGUI_API bool igColorButton(const char* desc_id,const ImVec4 col,ImGuiColorEditFlags flags,ImVec2 size) +CIMGUI_API bool igColorButton(const char* desc_id,const ImVec4 col,ImGuiColorEditFlags flags,const ImVec2 size) { return ImGui::ColorButton(desc_id,col,flags,size); } @@ -1093,7 +1104,7 @@ CIMGUI_API bool igBeginPopupContextVoid(const char* str_id,ImGuiPopupFlags popup { return ImGui::BeginPopupContextVoid(str_id,popup_flags); } -CIMGUI_API bool igIsPopupOpen_Str(const char* str_id,ImGuiPopupFlags flags) +CIMGUI_API bool igIsPopupOpen(const char* str_id,ImGuiPopupFlags flags) { return ImGui::IsPopupOpen(str_id,flags); } @@ -1149,7 +1160,7 @@ CIMGUI_API int igTableGetRowIndex() { return ImGui::TableGetRowIndex(); } -CIMGUI_API const char* igTableGetColumnName_Int(int column_n) +CIMGUI_API const char* igTableGetColumnName(int column_n) { return ImGui::TableGetColumnName(column_n); } @@ -1393,22 +1404,6 @@ CIMGUI_API ImGuiViewport* igGetMainViewport() { return ImGui::GetMainViewport(); } -CIMGUI_API bool igIsRectVisible_Nil(const ImVec2 size) -{ - return ImGui::IsRectVisible(size); -} -CIMGUI_API bool igIsRectVisible_Vec2(const ImVec2 rect_min,const ImVec2 rect_max) -{ - return ImGui::IsRectVisible(rect_min,rect_max); -} -CIMGUI_API double igGetTime() -{ - return ImGui::GetTime(); -} -CIMGUI_API int igGetFrameCount() -{ - return ImGui::GetFrameCount(); -} CIMGUI_API ImDrawList* igGetBackgroundDrawList_Nil() { return ImGui::GetBackgroundDrawList(); @@ -1425,6 +1420,22 @@ CIMGUI_API ImDrawList* igGetForegroundDrawList_ViewportPtr(ImGuiViewport* viewpo { return ImGui::GetForegroundDrawList(viewport); } +CIMGUI_API bool igIsRectVisible_Nil(const ImVec2 size) +{ + return ImGui::IsRectVisible(size); +} +CIMGUI_API bool igIsRectVisible_Vec2(const ImVec2 rect_min,const ImVec2 rect_max) +{ + return ImGui::IsRectVisible(rect_min,rect_max); +} +CIMGUI_API double igGetTime() +{ + return ImGui::GetTime(); +} +CIMGUI_API int igGetFrameCount() +{ + return ImGui::GetFrameCount(); +} CIMGUI_API ImDrawListSharedData* igGetDrawListSharedData() { return ImGui::GetDrawListSharedData(); @@ -1469,29 +1480,29 @@ CIMGUI_API void igColorConvertHSVtoRGB(float h,float s,float v,float* out_r,floa { return ImGui::ColorConvertHSVtoRGB(h,s,v,*out_r,*out_g,*out_b); } -CIMGUI_API int igGetKeyIndex(ImGuiKey imgui_key) +CIMGUI_API bool igIsKeyDown(ImGuiKey key) { - return ImGui::GetKeyIndex(imgui_key); + return ImGui::IsKeyDown(key); } -CIMGUI_API bool igIsKeyDown(int user_key_index) +CIMGUI_API bool igIsKeyPressed(ImGuiKey key,bool repeat) { - return ImGui::IsKeyDown(user_key_index); + return ImGui::IsKeyPressed(key,repeat); } -CIMGUI_API bool igIsKeyPressed(int user_key_index,bool repeat) +CIMGUI_API bool igIsKeyReleased(ImGuiKey key) { - return ImGui::IsKeyPressed(user_key_index,repeat); + return ImGui::IsKeyReleased(key); } -CIMGUI_API bool igIsKeyReleased(int user_key_index) +CIMGUI_API int igGetKeyPressedAmount(ImGuiKey key,float repeat_delay,float rate) { - return ImGui::IsKeyReleased(user_key_index); + return ImGui::GetKeyPressedAmount(key,repeat_delay,rate); } -CIMGUI_API int igGetKeyPressedAmount(int key_index,float repeat_delay,float rate) +CIMGUI_API const char* igGetKeyName(ImGuiKey key) { - return ImGui::GetKeyPressedAmount(key_index,repeat_delay,rate); + return ImGui::GetKeyName(key); } -CIMGUI_API void igCaptureKeyboardFromApp(bool want_capture_keyboard_value) +CIMGUI_API void igSetNextFrameWantCaptureKeyboard(bool want_capture_keyboard) { - return ImGui::CaptureKeyboardFromApp(want_capture_keyboard_value); + return ImGui::SetNextFrameWantCaptureKeyboard(want_capture_keyboard); } CIMGUI_API bool igIsMouseDown(ImGuiMouseButton button) { @@ -1553,9 +1564,9 @@ CIMGUI_API void igSetMouseCursor(ImGuiMouseCursor cursor_type) { return ImGui::SetMouseCursor(cursor_type); } -CIMGUI_API void igCaptureMouseFromApp(bool want_capture_mouse_value) +CIMGUI_API void igSetNextFrameWantCaptureMouse(bool want_capture_mouse) { - return ImGui::CaptureMouseFromApp(want_capture_mouse_value); + return ImGui::SetNextFrameWantCaptureMouse(want_capture_mouse); } CIMGUI_API const char* igGetClipboardText() { @@ -1581,6 +1592,10 @@ CIMGUI_API const char* igSaveIniSettingsToMemory(size_t* out_ini_size) { return ImGui::SaveIniSettingsToMemory(out_ini_size); } +CIMGUI_API void igDebugTextEncoding(const char* text) +{ + return ImGui::DebugTextEncoding(text); +} CIMGUI_API bool igDebugCheckVersionAndDataLayout(const char* version_str,size_t sz_io,size_t sz_style,size_t sz_vec2,size_t sz_vec4,size_t sz_drawvert,size_t sz_drawidx) { return ImGui::DebugCheckVersionAndDataLayout(version_str,sz_io,sz_style,sz_vec2,sz_vec4,sz_drawvert,sz_drawidx); @@ -1637,6 +1652,34 @@ CIMGUI_API void ImGuiStyle_ScaleAllSizes(ImGuiStyle* self,float scale_factor) { return self->ScaleAllSizes(scale_factor); } +CIMGUI_API void ImGuiIO_AddKeyEvent(ImGuiIO* self,ImGuiKey key,bool down) +{ + return self->AddKeyEvent(key,down); +} +CIMGUI_API void ImGuiIO_AddKeyAnalogEvent(ImGuiIO* self,ImGuiKey key,bool down,float v) +{ + return self->AddKeyAnalogEvent(key,down,v); +} +CIMGUI_API void ImGuiIO_AddMousePosEvent(ImGuiIO* self,float x,float y) +{ + return self->AddMousePosEvent(x,y); +} +CIMGUI_API void ImGuiIO_AddMouseButtonEvent(ImGuiIO* self,int button,bool down) +{ + return self->AddMouseButtonEvent(button,down); +} +CIMGUI_API void ImGuiIO_AddMouseWheelEvent(ImGuiIO* self,float wh_x,float wh_y) +{ + return self->AddMouseWheelEvent(wh_x,wh_y); +} +CIMGUI_API void ImGuiIO_AddMouseViewportEvent(ImGuiIO* self,ImGuiID id) +{ + return self->AddMouseViewportEvent(id); +} +CIMGUI_API void ImGuiIO_AddFocusEvent(ImGuiIO* self,bool focused) +{ + return self->AddFocusEvent(focused); +} CIMGUI_API void ImGuiIO_AddInputCharacter(ImGuiIO* self,unsigned int c) { return self->AddInputCharacter(c); @@ -1649,9 +1692,13 @@ CIMGUI_API void ImGuiIO_AddInputCharactersUTF8(ImGuiIO* self,const char* str) { return self->AddInputCharactersUTF8(str); } -CIMGUI_API void ImGuiIO_AddFocusEvent(ImGuiIO* self,bool focused) +CIMGUI_API void ImGuiIO_SetKeyEventNativeData(ImGuiIO* self,ImGuiKey key,int native_keycode,int native_scancode,int native_legacy_index) { - return self->AddFocusEvent(focused); + return self->SetKeyEventNativeData(key,native_keycode,native_scancode,native_legacy_index); +} +CIMGUI_API void ImGuiIO_SetAppAcceptingEvents(ImGuiIO* self,bool accepting_events) +{ + return self->SetAppAcceptingEvents(accepting_events); } CIMGUI_API void ImGuiIO_ClearInputCharacters(ImGuiIO* self) { @@ -1953,14 +2000,6 @@ CIMGUI_API void ImColor_destroy(ImColor* self) { IM_DELETE(self); } -CIMGUI_API ImColor* ImColor_ImColor_Int(int r,int g,int b,int a) -{ - return IM_NEW(ImColor)(r,g,b,a); -} -CIMGUI_API ImColor* ImColor_ImColor_U32(ImU32 rgba) -{ - return IM_NEW(ImColor)(rgba); -} CIMGUI_API ImColor* ImColor_ImColor_Float(float r,float g,float b,float a) { return IM_NEW(ImColor)(r,g,b,a); @@ -1969,6 +2008,14 @@ CIMGUI_API ImColor* ImColor_ImColor_Vec4(const ImVec4 col) { return IM_NEW(ImColor)(col); } +CIMGUI_API ImColor* ImColor_ImColor_Int(int r,int g,int b,int a) +{ + return IM_NEW(ImColor)(r,g,b,a); +} +CIMGUI_API ImColor* ImColor_ImColor_U32(ImU32 rgba) +{ + return IM_NEW(ImColor)(rgba); +} CIMGUI_API void ImColor_SetHSV(ImColor* self,float h,float s,float v,float a) { return self->SetHSV(h,s,v,a); @@ -2025,7 +2072,7 @@ CIMGUI_API void ImDrawList_destroy(ImDrawList* self) { IM_DELETE(self); } -CIMGUI_API void ImDrawList_PushClipRect(ImDrawList* self,ImVec2 clip_rect_min,ImVec2 clip_rect_max,bool intersect_with_current_clip_rect) +CIMGUI_API void ImDrawList_PushClipRect(ImDrawList* self,const ImVec2 clip_rect_min,const ImVec2 clip_rect_max,bool intersect_with_current_clip_rect) { return self->PushClipRect(clip_rect_min,clip_rect_max,intersect_with_current_clip_rect); } @@ -2505,11 +2552,11 @@ CIMGUI_API const char* ImFont_CalcWordWrapPositionA(ImFont* self,float scale,con { return self->CalcWordWrapPositionA(scale,text,text_end,wrap_width); } -CIMGUI_API void ImFont_RenderChar(ImFont* self,ImDrawList* draw_list,float size,ImVec2 pos,ImU32 col,ImWchar c) +CIMGUI_API void ImFont_RenderChar(ImFont* self,ImDrawList* draw_list,float size,const ImVec2 pos,ImU32 col,ImWchar c) { return self->RenderChar(draw_list,size,pos,col,c); } -CIMGUI_API void ImFont_RenderText(ImFont* self,ImDrawList* draw_list,float size,ImVec2 pos,ImU32 col,const ImVec4 clip_rect,const char* text_begin,const char* text_end,float wrap_width,bool cpu_fine_clip) +CIMGUI_API void ImFont_RenderText(ImFont* self,ImDrawList* draw_list,float size,const ImVec2 pos,ImU32 col,const ImVec4 clip_rect,const char* text_begin,const char* text_end,float wrap_width,bool cpu_fine_clip) { return self->RenderText(draw_list,size,pos,col,clip_rect,text_begin,text_end,wrap_width,cpu_fine_clip); } @@ -2573,2393 +2620,17 @@ CIMGUI_API void ImGuiPlatformMonitor_destroy(ImGuiPlatformMonitor* self) { IM_DELETE(self); } -CIMGUI_API ImGuiID igImHashData(const void* data,size_t data_size,ImU32 seed) +CIMGUI_API ImGuiPlatformImeData* ImGuiPlatformImeData_ImGuiPlatformImeData(void) { - return ImHashData(data,data_size,seed); + return IM_NEW(ImGuiPlatformImeData)(); } -CIMGUI_API ImGuiID igImHashStr(const char* data,size_t data_size,ImU32 seed) -{ - return ImHashStr(data,data_size,seed); -} -CIMGUI_API void igImQsort(void* base,size_t count,size_t size_of_element,int(*compare_func)(void const*,void const*)) -{ - return ImQsort(base,count,size_of_element,compare_func); -} -CIMGUI_API ImU32 igImAlphaBlendColors(ImU32 col_a,ImU32 col_b) -{ - return ImAlphaBlendColors(col_a,col_b); -} -CIMGUI_API bool igImIsPowerOfTwo_Int(int v) -{ - return ImIsPowerOfTwo(v); -} -CIMGUI_API bool igImIsPowerOfTwo_U64(ImU64 v) -{ - return ImIsPowerOfTwo(v); -} -CIMGUI_API int igImUpperPowerOfTwo(int v) -{ - return ImUpperPowerOfTwo(v); -} -CIMGUI_API int igImStricmp(const char* str1,const char* str2) -{ - return ImStricmp(str1,str2); -} -CIMGUI_API int igImStrnicmp(const char* str1,const char* str2,size_t count) -{ - return ImStrnicmp(str1,str2,count); -} -CIMGUI_API void igImStrncpy(char* dst,const char* src,size_t count) -{ - return ImStrncpy(dst,src,count); -} -CIMGUI_API char* igImStrdup(const char* str) -{ - return ImStrdup(str); -} -CIMGUI_API char* igImStrdupcpy(char* dst,size_t* p_dst_size,const char* str) -{ - return ImStrdupcpy(dst,p_dst_size,str); -} -CIMGUI_API const char* igImStrchrRange(const char* str_begin,const char* str_end,char c) -{ - return ImStrchrRange(str_begin,str_end,c); -} -CIMGUI_API int igImStrlenW(const ImWchar* str) -{ - return ImStrlenW(str); -} -CIMGUI_API const char* igImStreolRange(const char* str,const char* str_end) -{ - return ImStreolRange(str,str_end); -} -CIMGUI_API const ImWchar* igImStrbolW(const ImWchar* buf_mid_line,const ImWchar* buf_begin) -{ - return ImStrbolW(buf_mid_line,buf_begin); -} -CIMGUI_API const char* igImStristr(const char* haystack,const char* haystack_end,const char* needle,const char* needle_end) -{ - return ImStristr(haystack,haystack_end,needle,needle_end); -} -CIMGUI_API void igImStrTrimBlanks(char* str) -{ - return ImStrTrimBlanks(str); -} -CIMGUI_API const char* igImStrSkipBlank(const char* str) -{ - return ImStrSkipBlank(str); -} -CIMGUI_API int igImFormatString(char* buf,size_t buf_size,const char* fmt,...) -{ - va_list args; - va_start(args, fmt); - int ret = ImFormatStringV(buf,buf_size,fmt,args); - va_end(args); - return ret; -} -CIMGUI_API int igImFormatStringV(char* buf,size_t buf_size,const char* fmt,va_list args) -{ - return ImFormatStringV(buf,buf_size,fmt,args); -} -CIMGUI_API const char* igImParseFormatFindStart(const char* format) -{ - return ImParseFormatFindStart(format); -} -CIMGUI_API const char* igImParseFormatFindEnd(const char* format) -{ - return ImParseFormatFindEnd(format); -} -CIMGUI_API const char* igImParseFormatTrimDecorations(const char* format,char* buf,size_t buf_size) -{ - return ImParseFormatTrimDecorations(format,buf,buf_size); -} -CIMGUI_API int igImParseFormatPrecision(const char* format,int default_value) -{ - return ImParseFormatPrecision(format,default_value); -} -CIMGUI_API bool igImCharIsBlankA(char c) -{ - return ImCharIsBlankA(c); -} -CIMGUI_API bool igImCharIsBlankW(unsigned int c) -{ - return ImCharIsBlankW(c); -} -CIMGUI_API const char* igImTextCharToUtf8(char out_buf[5],unsigned int c) -{ - return ImTextCharToUtf8(out_buf,c); -} -CIMGUI_API int igImTextStrToUtf8(char* out_buf,int out_buf_size,const ImWchar* in_text,const ImWchar* in_text_end) -{ - return ImTextStrToUtf8(out_buf,out_buf_size,in_text,in_text_end); -} -CIMGUI_API int igImTextCharFromUtf8(unsigned int* out_char,const char* in_text,const char* in_text_end) -{ - return ImTextCharFromUtf8(out_char,in_text,in_text_end); -} -CIMGUI_API int igImTextStrFromUtf8(ImWchar* out_buf,int out_buf_size,const char* in_text,const char* in_text_end,const char** in_remaining) -{ - return ImTextStrFromUtf8(out_buf,out_buf_size,in_text,in_text_end,in_remaining); -} -CIMGUI_API int igImTextCountCharsFromUtf8(const char* in_text,const char* in_text_end) -{ - return ImTextCountCharsFromUtf8(in_text,in_text_end); -} -CIMGUI_API int igImTextCountUtf8BytesFromChar(const char* in_text,const char* in_text_end) -{ - return ImTextCountUtf8BytesFromChar(in_text,in_text_end); -} -CIMGUI_API int igImTextCountUtf8BytesFromStr(const ImWchar* in_text,const ImWchar* in_text_end) -{ - return ImTextCountUtf8BytesFromStr(in_text,in_text_end); -} -CIMGUI_API ImFileHandle igImFileOpen(const char* filename,const char* mode) -{ - return ImFileOpen(filename,mode); -} -CIMGUI_API bool igImFileClose(ImFileHandle file) -{ - return ImFileClose(file); -} -CIMGUI_API ImU64 igImFileGetSize(ImFileHandle file) -{ - return ImFileGetSize(file); -} -CIMGUI_API ImU64 igImFileRead(void* data,ImU64 size,ImU64 count,ImFileHandle file) -{ - return ImFileRead(data,size,count,file); -} -CIMGUI_API ImU64 igImFileWrite(const void* data,ImU64 size,ImU64 count,ImFileHandle file) -{ - return ImFileWrite(data,size,count,file); -} -CIMGUI_API void* igImFileLoadToMemory(const char* filename,const char* mode,size_t* out_file_size,int padding_bytes) -{ - return ImFileLoadToMemory(filename,mode,out_file_size,padding_bytes); -} -CIMGUI_API float igImPow_Float(float x,float y) -{ - return ImPow(x,y); -} -CIMGUI_API double igImPow_double(double x,double y) -{ - return ImPow(x,y); -} -CIMGUI_API float igImLog_Float(float x) -{ - return ImLog(x); -} -CIMGUI_API double igImLog_double(double x) -{ - return ImLog(x); -} -CIMGUI_API int igImAbs_Int(int x) -{ - return ImAbs(x); -} -CIMGUI_API float igImAbs_Float(float x) -{ - return ImAbs(x); -} -CIMGUI_API double igImAbs_double(double x) -{ - return ImAbs(x); -} -CIMGUI_API float igImSign_Float(float x) -{ - return ImSign(x); -} -CIMGUI_API double igImSign_double(double x) -{ - return ImSign(x); -} -CIMGUI_API float igImRsqrt_Float(float x) -{ - return ImRsqrt(x); -} -CIMGUI_API double igImRsqrt_double(double x) -{ - return ImRsqrt(x); -} -CIMGUI_API void igImMin(ImVec2 *pOut,const ImVec2 lhs,const ImVec2 rhs) -{ - *pOut = ImMin(lhs,rhs); -} -CIMGUI_API void igImMax(ImVec2 *pOut,const ImVec2 lhs,const ImVec2 rhs) -{ - *pOut = ImMax(lhs,rhs); -} -CIMGUI_API void igImClamp(ImVec2 *pOut,const ImVec2 v,const ImVec2 mn,ImVec2 mx) -{ - *pOut = ImClamp(v,mn,mx); -} -CIMGUI_API void igImLerp_Vec2Float(ImVec2 *pOut,const ImVec2 a,const ImVec2 b,float t) -{ - *pOut = ImLerp(a,b,t); -} -CIMGUI_API void igImLerp_Vec2Vec2(ImVec2 *pOut,const ImVec2 a,const ImVec2 b,const ImVec2 t) -{ - *pOut = ImLerp(a,b,t); -} -CIMGUI_API void igImLerp_Vec4(ImVec4 *pOut,const ImVec4 a,const ImVec4 b,float t) -{ - *pOut = ImLerp(a,b,t); -} -CIMGUI_API float igImSaturate(float f) -{ - return ImSaturate(f); -} -CIMGUI_API float igImLengthSqr_Vec2(const ImVec2 lhs) -{ - return ImLengthSqr(lhs); -} -CIMGUI_API float igImLengthSqr_Vec4(const ImVec4 lhs) -{ - return ImLengthSqr(lhs); -} -CIMGUI_API float igImInvLength(const ImVec2 lhs,float fail_value) -{ - return ImInvLength(lhs,fail_value); -} -CIMGUI_API float igImFloor_Float(float f) -{ - return ImFloor(f); -} -CIMGUI_API float igImFloorSigned(float f) -{ - return ImFloorSigned(f); -} -CIMGUI_API void igImFloor_Vec2(ImVec2 *pOut,const ImVec2 v) -{ - *pOut = ImFloor(v); -} -CIMGUI_API int igImModPositive(int a,int b) -{ - return ImModPositive(a,b); -} -CIMGUI_API float igImDot(const ImVec2 a,const ImVec2 b) -{ - return ImDot(a,b); -} -CIMGUI_API void igImRotate(ImVec2 *pOut,const ImVec2 v,float cos_a,float sin_a) -{ - *pOut = ImRotate(v,cos_a,sin_a); -} -CIMGUI_API float igImLinearSweep(float current,float target,float speed) -{ - return ImLinearSweep(current,target,speed); -} -CIMGUI_API void igImMul(ImVec2 *pOut,const ImVec2 lhs,const ImVec2 rhs) -{ - *pOut = ImMul(lhs,rhs); -} -CIMGUI_API bool igImIsFloatAboveGuaranteedIntegerPrecision(float f) -{ - return ImIsFloatAboveGuaranteedIntegerPrecision(f); -} -CIMGUI_API void igImBezierCubicCalc(ImVec2 *pOut,const ImVec2 p1,const ImVec2 p2,const ImVec2 p3,const ImVec2 p4,float t) -{ - *pOut = ImBezierCubicCalc(p1,p2,p3,p4,t); -} -CIMGUI_API void igImBezierCubicClosestPoint(ImVec2 *pOut,const ImVec2 p1,const ImVec2 p2,const ImVec2 p3,const ImVec2 p4,const ImVec2 p,int num_segments) -{ - *pOut = ImBezierCubicClosestPoint(p1,p2,p3,p4,p,num_segments); -} -CIMGUI_API void igImBezierCubicClosestPointCasteljau(ImVec2 *pOut,const ImVec2 p1,const ImVec2 p2,const ImVec2 p3,const ImVec2 p4,const ImVec2 p,float tess_tol) -{ - *pOut = ImBezierCubicClosestPointCasteljau(p1,p2,p3,p4,p,tess_tol); -} -CIMGUI_API void igImBezierQuadraticCalc(ImVec2 *pOut,const ImVec2 p1,const ImVec2 p2,const ImVec2 p3,float t) -{ - *pOut = ImBezierQuadraticCalc(p1,p2,p3,t); -} -CIMGUI_API void igImLineClosestPoint(ImVec2 *pOut,const ImVec2 a,const ImVec2 b,const ImVec2 p) -{ - *pOut = ImLineClosestPoint(a,b,p); -} -CIMGUI_API bool igImTriangleContainsPoint(const ImVec2 a,const ImVec2 b,const ImVec2 c,const ImVec2 p) -{ - return ImTriangleContainsPoint(a,b,c,p); -} -CIMGUI_API void igImTriangleClosestPoint(ImVec2 *pOut,const ImVec2 a,const ImVec2 b,const ImVec2 c,const ImVec2 p) -{ - *pOut = ImTriangleClosestPoint(a,b,c,p); -} -CIMGUI_API void igImTriangleBarycentricCoords(const ImVec2 a,const ImVec2 b,const ImVec2 c,const ImVec2 p,float* out_u,float* out_v,float* out_w) -{ - return ImTriangleBarycentricCoords(a,b,c,p,*out_u,*out_v,*out_w); -} -CIMGUI_API float igImTriangleArea(const ImVec2 a,const ImVec2 b,const ImVec2 c) -{ - return ImTriangleArea(a,b,c); -} -CIMGUI_API ImGuiDir igImGetDirQuadrantFromDelta(float dx,float dy) -{ - return ImGetDirQuadrantFromDelta(dx,dy); -} -CIMGUI_API ImVec1* ImVec1_ImVec1_Nil(void) -{ - return IM_NEW(ImVec1)(); -} -CIMGUI_API void ImVec1_destroy(ImVec1* self) +CIMGUI_API void ImGuiPlatformImeData_destroy(ImGuiPlatformImeData* self) { IM_DELETE(self); } -CIMGUI_API ImVec1* ImVec1_ImVec1_Float(float _x) +CIMGUI_API int igGetKeyIndex(ImGuiKey key) { - return IM_NEW(ImVec1)(_x); -} -CIMGUI_API ImVec2ih* ImVec2ih_ImVec2ih_Nil(void) -{ - return IM_NEW(ImVec2ih)(); -} -CIMGUI_API void ImVec2ih_destroy(ImVec2ih* self) -{ - IM_DELETE(self); -} -CIMGUI_API ImVec2ih* ImVec2ih_ImVec2ih_short(short _x,short _y) -{ - return IM_NEW(ImVec2ih)(_x,_y); -} -CIMGUI_API ImVec2ih* ImVec2ih_ImVec2ih_Vec2(const ImVec2 rhs) -{ - return IM_NEW(ImVec2ih)(rhs); -} -CIMGUI_API ImRect* ImRect_ImRect_Nil(void) -{ - return IM_NEW(ImRect)(); -} -CIMGUI_API void ImRect_destroy(ImRect* self) -{ - IM_DELETE(self); -} -CIMGUI_API ImRect* ImRect_ImRect_Vec2(const ImVec2 min,const ImVec2 max) -{ - return IM_NEW(ImRect)(min,max); -} -CIMGUI_API ImRect* ImRect_ImRect_Vec4(const ImVec4 v) -{ - return IM_NEW(ImRect)(v); -} -CIMGUI_API ImRect* ImRect_ImRect_Float(float x1,float y1,float x2,float y2) -{ - return IM_NEW(ImRect)(x1,y1,x2,y2); -} -CIMGUI_API void ImRect_GetCenter(ImVec2 *pOut,ImRect* self) -{ - *pOut = self->GetCenter(); -} -CIMGUI_API void ImRect_GetSize(ImVec2 *pOut,ImRect* self) -{ - *pOut = self->GetSize(); -} -CIMGUI_API float ImRect_GetWidth(ImRect* self) -{ - return self->GetWidth(); -} -CIMGUI_API float ImRect_GetHeight(ImRect* self) -{ - return self->GetHeight(); -} -CIMGUI_API float ImRect_GetArea(ImRect* self) -{ - return self->GetArea(); -} -CIMGUI_API void ImRect_GetTL(ImVec2 *pOut,ImRect* self) -{ - *pOut = self->GetTL(); -} -CIMGUI_API void ImRect_GetTR(ImVec2 *pOut,ImRect* self) -{ - *pOut = self->GetTR(); -} -CIMGUI_API void ImRect_GetBL(ImVec2 *pOut,ImRect* self) -{ - *pOut = self->GetBL(); -} -CIMGUI_API void ImRect_GetBR(ImVec2 *pOut,ImRect* self) -{ - *pOut = self->GetBR(); -} -CIMGUI_API bool ImRect_Contains_Vec2(ImRect* self,const ImVec2 p) -{ - return self->Contains(p); -} -CIMGUI_API bool ImRect_Contains_Rect(ImRect* self,const ImRect r) -{ - return self->Contains(r); -} -CIMGUI_API bool ImRect_Overlaps(ImRect* self,const ImRect r) -{ - return self->Overlaps(r); -} -CIMGUI_API void ImRect_Add_Vec2(ImRect* self,const ImVec2 p) -{ - return self->Add(p); -} -CIMGUI_API void ImRect_Add_Rect(ImRect* self,const ImRect r) -{ - return self->Add(r); -} -CIMGUI_API void ImRect_Expand_Float(ImRect* self,const float amount) -{ - return self->Expand(amount); -} -CIMGUI_API void ImRect_Expand_Vec2(ImRect* self,const ImVec2 amount) -{ - return self->Expand(amount); -} -CIMGUI_API void ImRect_Translate(ImRect* self,const ImVec2 d) -{ - return self->Translate(d); -} -CIMGUI_API void ImRect_TranslateX(ImRect* self,float dx) -{ - return self->TranslateX(dx); -} -CIMGUI_API void ImRect_TranslateY(ImRect* self,float dy) -{ - return self->TranslateY(dy); -} -CIMGUI_API void ImRect_ClipWith(ImRect* self,const ImRect r) -{ - return self->ClipWith(r); -} -CIMGUI_API void ImRect_ClipWithFull(ImRect* self,const ImRect r) -{ - return self->ClipWithFull(r); -} -CIMGUI_API void ImRect_Floor(ImRect* self) -{ - return self->Floor(); -} -CIMGUI_API bool ImRect_IsInverted(ImRect* self) -{ - return self->IsInverted(); -} -CIMGUI_API void ImRect_ToVec4(ImVec4 *pOut,ImRect* self) -{ - *pOut = self->ToVec4(); -} -CIMGUI_API bool igImBitArrayTestBit(const ImU32* arr,int n) -{ - return ImBitArrayTestBit(arr,n); -} -CIMGUI_API void igImBitArrayClearBit(ImU32* arr,int n) -{ - return ImBitArrayClearBit(arr,n); -} -CIMGUI_API void igImBitArraySetBit(ImU32* arr,int n) -{ - return ImBitArraySetBit(arr,n); -} -CIMGUI_API void igImBitArraySetBitRange(ImU32* arr,int n,int n2) -{ - return ImBitArraySetBitRange(arr,n,n2); -} -CIMGUI_API void ImBitVector_Create(ImBitVector* self,int sz) -{ - return self->Create(sz); -} -CIMGUI_API void ImBitVector_Clear(ImBitVector* self) -{ - return self->Clear(); -} -CIMGUI_API bool ImBitVector_TestBit(ImBitVector* self,int n) -{ - return self->TestBit(n); -} -CIMGUI_API void ImBitVector_SetBit(ImBitVector* self,int n) -{ - return self->SetBit(n); -} -CIMGUI_API void ImBitVector_ClearBit(ImBitVector* self,int n) -{ - return self->ClearBit(n); -} -CIMGUI_API ImDrawListSharedData* ImDrawListSharedData_ImDrawListSharedData(void) -{ - return IM_NEW(ImDrawListSharedData)(); -} -CIMGUI_API void ImDrawListSharedData_destroy(ImDrawListSharedData* self) -{ - IM_DELETE(self); -} -CIMGUI_API void ImDrawListSharedData_SetCircleTessellationMaxError(ImDrawListSharedData* self,float max_error) -{ - return self->SetCircleTessellationMaxError(max_error); -} -CIMGUI_API void ImDrawDataBuilder_Clear(ImDrawDataBuilder* self) -{ - return self->Clear(); -} -CIMGUI_API void ImDrawDataBuilder_ClearFreeMemory(ImDrawDataBuilder* self) -{ - return self->ClearFreeMemory(); -} -CIMGUI_API int ImDrawDataBuilder_GetDrawListCount(ImDrawDataBuilder* self) -{ - return self->GetDrawListCount(); -} -CIMGUI_API void ImDrawDataBuilder_FlattenIntoSingleLayer(ImDrawDataBuilder* self) -{ - return self->FlattenIntoSingleLayer(); -} -CIMGUI_API ImGuiStyleMod* ImGuiStyleMod_ImGuiStyleMod_Int(ImGuiStyleVar idx,int v) -{ - return IM_NEW(ImGuiStyleMod)(idx,v); -} -CIMGUI_API void ImGuiStyleMod_destroy(ImGuiStyleMod* self) -{ - IM_DELETE(self); -} -CIMGUI_API ImGuiStyleMod* ImGuiStyleMod_ImGuiStyleMod_Float(ImGuiStyleVar idx,float v) -{ - return IM_NEW(ImGuiStyleMod)(idx,v); -} -CIMGUI_API ImGuiStyleMod* ImGuiStyleMod_ImGuiStyleMod_Vec2(ImGuiStyleVar idx,ImVec2 v) -{ - return IM_NEW(ImGuiStyleMod)(idx,v); -} -CIMGUI_API ImGuiComboPreviewData* ImGuiComboPreviewData_ImGuiComboPreviewData(void) -{ - return IM_NEW(ImGuiComboPreviewData)(); -} -CIMGUI_API void ImGuiComboPreviewData_destroy(ImGuiComboPreviewData* self) -{ - IM_DELETE(self); -} -CIMGUI_API ImGuiMenuColumns* ImGuiMenuColumns_ImGuiMenuColumns(void) -{ - return IM_NEW(ImGuiMenuColumns)(); -} -CIMGUI_API void ImGuiMenuColumns_destroy(ImGuiMenuColumns* self) -{ - IM_DELETE(self); -} -CIMGUI_API void ImGuiMenuColumns_Update(ImGuiMenuColumns* self,float spacing,bool window_reappearing) -{ - return self->Update(spacing,window_reappearing); -} -CIMGUI_API float ImGuiMenuColumns_DeclColumns(ImGuiMenuColumns* self,float w_icon,float w_label,float w_shortcut,float w_mark) -{ - return self->DeclColumns(w_icon,w_label,w_shortcut,w_mark); -} -CIMGUI_API void ImGuiMenuColumns_CalcNextTotalWidth(ImGuiMenuColumns* self,bool update_offsets) -{ - return self->CalcNextTotalWidth(update_offsets); -} -CIMGUI_API ImGuiInputTextState* ImGuiInputTextState_ImGuiInputTextState(void) -{ - return IM_NEW(ImGuiInputTextState)(); -} -CIMGUI_API void ImGuiInputTextState_destroy(ImGuiInputTextState* self) -{ - IM_DELETE(self); -} -CIMGUI_API void ImGuiInputTextState_ClearText(ImGuiInputTextState* self) -{ - return self->ClearText(); -} -CIMGUI_API void ImGuiInputTextState_ClearFreeMemory(ImGuiInputTextState* self) -{ - return self->ClearFreeMemory(); -} -CIMGUI_API int ImGuiInputTextState_GetUndoAvailCount(ImGuiInputTextState* self) -{ - return self->GetUndoAvailCount(); -} -CIMGUI_API int ImGuiInputTextState_GetRedoAvailCount(ImGuiInputTextState* self) -{ - return self->GetRedoAvailCount(); -} -CIMGUI_API void ImGuiInputTextState_OnKeyPressed(ImGuiInputTextState* self,int key) -{ - return self->OnKeyPressed(key); -} -CIMGUI_API void ImGuiInputTextState_CursorAnimReset(ImGuiInputTextState* self) -{ - return self->CursorAnimReset(); -} -CIMGUI_API void ImGuiInputTextState_CursorClamp(ImGuiInputTextState* self) -{ - return self->CursorClamp(); -} -CIMGUI_API bool ImGuiInputTextState_HasSelection(ImGuiInputTextState* self) -{ - return self->HasSelection(); -} -CIMGUI_API void ImGuiInputTextState_ClearSelection(ImGuiInputTextState* self) -{ - return self->ClearSelection(); -} -CIMGUI_API int ImGuiInputTextState_GetCursorPos(ImGuiInputTextState* self) -{ - return self->GetCursorPos(); -} -CIMGUI_API int ImGuiInputTextState_GetSelectionStart(ImGuiInputTextState* self) -{ - return self->GetSelectionStart(); -} -CIMGUI_API int ImGuiInputTextState_GetSelectionEnd(ImGuiInputTextState* self) -{ - return self->GetSelectionEnd(); -} -CIMGUI_API void ImGuiInputTextState_SelectAll(ImGuiInputTextState* self) -{ - return self->SelectAll(); -} -CIMGUI_API ImGuiPopupData* ImGuiPopupData_ImGuiPopupData(void) -{ - return IM_NEW(ImGuiPopupData)(); -} -CIMGUI_API void ImGuiPopupData_destroy(ImGuiPopupData* self) -{ - IM_DELETE(self); -} -CIMGUI_API ImGuiNextWindowData* ImGuiNextWindowData_ImGuiNextWindowData(void) -{ - return IM_NEW(ImGuiNextWindowData)(); -} -CIMGUI_API void ImGuiNextWindowData_destroy(ImGuiNextWindowData* self) -{ - IM_DELETE(self); -} -CIMGUI_API void ImGuiNextWindowData_ClearFlags(ImGuiNextWindowData* self) -{ - return self->ClearFlags(); -} -CIMGUI_API ImGuiNextItemData* ImGuiNextItemData_ImGuiNextItemData(void) -{ - return IM_NEW(ImGuiNextItemData)(); -} -CIMGUI_API void ImGuiNextItemData_destroy(ImGuiNextItemData* self) -{ - IM_DELETE(self); -} -CIMGUI_API void ImGuiNextItemData_ClearFlags(ImGuiNextItemData* self) -{ - return self->ClearFlags(); -} -CIMGUI_API ImGuiLastItemData* ImGuiLastItemData_ImGuiLastItemData(void) -{ - return IM_NEW(ImGuiLastItemData)(); -} -CIMGUI_API void ImGuiLastItemData_destroy(ImGuiLastItemData* self) -{ - IM_DELETE(self); -} -CIMGUI_API ImGuiStackSizes* ImGuiStackSizes_ImGuiStackSizes(void) -{ - return IM_NEW(ImGuiStackSizes)(); -} -CIMGUI_API void ImGuiStackSizes_destroy(ImGuiStackSizes* self) -{ - IM_DELETE(self); -} -CIMGUI_API void ImGuiStackSizes_SetToCurrentState(ImGuiStackSizes* self) -{ - return self->SetToCurrentState(); -} -CIMGUI_API void ImGuiStackSizes_CompareWithCurrentState(ImGuiStackSizes* self) -{ - return self->CompareWithCurrentState(); -} -CIMGUI_API ImGuiPtrOrIndex* ImGuiPtrOrIndex_ImGuiPtrOrIndex_Ptr(void* ptr) -{ - return IM_NEW(ImGuiPtrOrIndex)(ptr); -} -CIMGUI_API void ImGuiPtrOrIndex_destroy(ImGuiPtrOrIndex* self) -{ - IM_DELETE(self); -} -CIMGUI_API ImGuiPtrOrIndex* ImGuiPtrOrIndex_ImGuiPtrOrIndex_Int(int index) -{ - return IM_NEW(ImGuiPtrOrIndex)(index); -} -CIMGUI_API ImGuiListClipperRange ImGuiListClipperRange_FromIndices(int min,int max) -{ - return ImGuiListClipperRange::FromIndices(min,max); -} -CIMGUI_API ImGuiListClipperRange ImGuiListClipperRange_FromPositions(float y1,float y2,int off_min,int off_max) -{ - return ImGuiListClipperRange::FromPositions(y1,y2,off_min,off_max); -} -CIMGUI_API ImGuiListClipperData* ImGuiListClipperData_ImGuiListClipperData(void) -{ - return IM_NEW(ImGuiListClipperData)(); -} -CIMGUI_API void ImGuiListClipperData_destroy(ImGuiListClipperData* self) -{ - IM_DELETE(self); -} -CIMGUI_API void ImGuiListClipperData_Reset(ImGuiListClipperData* self,ImGuiListClipper* clipper) -{ - return self->Reset(clipper); -} -CIMGUI_API ImGuiNavItemData* ImGuiNavItemData_ImGuiNavItemData(void) -{ - return IM_NEW(ImGuiNavItemData)(); -} -CIMGUI_API void ImGuiNavItemData_destroy(ImGuiNavItemData* self) -{ - IM_DELETE(self); -} -CIMGUI_API void ImGuiNavItemData_Clear(ImGuiNavItemData* self) -{ - return self->Clear(); -} -CIMGUI_API ImGuiOldColumnData* ImGuiOldColumnData_ImGuiOldColumnData(void) -{ - return IM_NEW(ImGuiOldColumnData)(); -} -CIMGUI_API void ImGuiOldColumnData_destroy(ImGuiOldColumnData* self) -{ - IM_DELETE(self); -} -CIMGUI_API ImGuiOldColumns* ImGuiOldColumns_ImGuiOldColumns(void) -{ - return IM_NEW(ImGuiOldColumns)(); -} -CIMGUI_API void ImGuiOldColumns_destroy(ImGuiOldColumns* self) -{ - IM_DELETE(self); -} -CIMGUI_API ImGuiDockNode* ImGuiDockNode_ImGuiDockNode(ImGuiID id) -{ - return IM_NEW(ImGuiDockNode)(id); -} -CIMGUI_API void ImGuiDockNode_destroy(ImGuiDockNode* self) -{ - IM_DELETE(self); -} -CIMGUI_API bool ImGuiDockNode_IsRootNode(ImGuiDockNode* self) -{ - return self->IsRootNode(); -} -CIMGUI_API bool ImGuiDockNode_IsDockSpace(ImGuiDockNode* self) -{ - return self->IsDockSpace(); -} -CIMGUI_API bool ImGuiDockNode_IsFloatingNode(ImGuiDockNode* self) -{ - return self->IsFloatingNode(); -} -CIMGUI_API bool ImGuiDockNode_IsCentralNode(ImGuiDockNode* self) -{ - return self->IsCentralNode(); -} -CIMGUI_API bool ImGuiDockNode_IsHiddenTabBar(ImGuiDockNode* self) -{ - return self->IsHiddenTabBar(); -} -CIMGUI_API bool ImGuiDockNode_IsNoTabBar(ImGuiDockNode* self) -{ - return self->IsNoTabBar(); -} -CIMGUI_API bool ImGuiDockNode_IsSplitNode(ImGuiDockNode* self) -{ - return self->IsSplitNode(); -} -CIMGUI_API bool ImGuiDockNode_IsLeafNode(ImGuiDockNode* self) -{ - return self->IsLeafNode(); -} -CIMGUI_API bool ImGuiDockNode_IsEmpty(ImGuiDockNode* self) -{ - return self->IsEmpty(); -} -CIMGUI_API void ImGuiDockNode_Rect(ImRect *pOut,ImGuiDockNode* self) -{ - *pOut = self->Rect(); -} -CIMGUI_API void ImGuiDockNode_SetLocalFlags(ImGuiDockNode* self,ImGuiDockNodeFlags flags) -{ - return self->SetLocalFlags(flags); -} -CIMGUI_API void ImGuiDockNode_UpdateMergedFlags(ImGuiDockNode* self) -{ - return self->UpdateMergedFlags(); -} -CIMGUI_API ImGuiDockContext* ImGuiDockContext_ImGuiDockContext(void) -{ - return IM_NEW(ImGuiDockContext)(); -} -CIMGUI_API void ImGuiDockContext_destroy(ImGuiDockContext* self) -{ - IM_DELETE(self); -} -CIMGUI_API ImGuiViewportP* ImGuiViewportP_ImGuiViewportP(void) -{ - return IM_NEW(ImGuiViewportP)(); -} -CIMGUI_API void ImGuiViewportP_destroy(ImGuiViewportP* self) -{ - IM_DELETE(self); -} -CIMGUI_API void ImGuiViewportP_ClearRequestFlags(ImGuiViewportP* self) -{ - return self->ClearRequestFlags(); -} -CIMGUI_API void ImGuiViewportP_CalcWorkRectPos(ImVec2 *pOut,ImGuiViewportP* self,const ImVec2 off_min) -{ - *pOut = self->CalcWorkRectPos(off_min); -} -CIMGUI_API void ImGuiViewportP_CalcWorkRectSize(ImVec2 *pOut,ImGuiViewportP* self,const ImVec2 off_min,const ImVec2 off_max) -{ - *pOut = self->CalcWorkRectSize(off_min,off_max); -} -CIMGUI_API void ImGuiViewportP_UpdateWorkRect(ImGuiViewportP* self) -{ - return self->UpdateWorkRect(); -} -CIMGUI_API void ImGuiViewportP_GetMainRect(ImRect *pOut,ImGuiViewportP* self) -{ - *pOut = self->GetMainRect(); -} -CIMGUI_API void ImGuiViewportP_GetWorkRect(ImRect *pOut,ImGuiViewportP* self) -{ - *pOut = self->GetWorkRect(); -} -CIMGUI_API void ImGuiViewportP_GetBuildWorkRect(ImRect *pOut,ImGuiViewportP* self) -{ - *pOut = self->GetBuildWorkRect(); -} -CIMGUI_API ImGuiWindowSettings* ImGuiWindowSettings_ImGuiWindowSettings(void) -{ - return IM_NEW(ImGuiWindowSettings)(); -} -CIMGUI_API void ImGuiWindowSettings_destroy(ImGuiWindowSettings* self) -{ - IM_DELETE(self); -} -CIMGUI_API char* ImGuiWindowSettings_GetName(ImGuiWindowSettings* self) -{ - return self->GetName(); -} -CIMGUI_API ImGuiSettingsHandler* ImGuiSettingsHandler_ImGuiSettingsHandler(void) -{ - return IM_NEW(ImGuiSettingsHandler)(); -} -CIMGUI_API void ImGuiSettingsHandler_destroy(ImGuiSettingsHandler* self) -{ - IM_DELETE(self); -} -CIMGUI_API ImGuiMetricsConfig* ImGuiMetricsConfig_ImGuiMetricsConfig(void) -{ - return IM_NEW(ImGuiMetricsConfig)(); -} -CIMGUI_API void ImGuiMetricsConfig_destroy(ImGuiMetricsConfig* self) -{ - IM_DELETE(self); -} -CIMGUI_API ImGuiStackLevelInfo* ImGuiStackLevelInfo_ImGuiStackLevelInfo(void) -{ - return IM_NEW(ImGuiStackLevelInfo)(); -} -CIMGUI_API void ImGuiStackLevelInfo_destroy(ImGuiStackLevelInfo* self) -{ - IM_DELETE(self); -} -CIMGUI_API ImGuiStackTool* ImGuiStackTool_ImGuiStackTool(void) -{ - return IM_NEW(ImGuiStackTool)(); -} -CIMGUI_API void ImGuiStackTool_destroy(ImGuiStackTool* self) -{ - IM_DELETE(self); -} -CIMGUI_API ImGuiContextHook* ImGuiContextHook_ImGuiContextHook(void) -{ - return IM_NEW(ImGuiContextHook)(); -} -CIMGUI_API void ImGuiContextHook_destroy(ImGuiContextHook* self) -{ - IM_DELETE(self); -} -CIMGUI_API ImGuiContext* ImGuiContext_ImGuiContext(ImFontAtlas* shared_font_atlas) -{ - return IM_NEW(ImGuiContext)(shared_font_atlas); -} -CIMGUI_API void ImGuiContext_destroy(ImGuiContext* self) -{ - IM_DELETE(self); -} -CIMGUI_API ImGuiWindow* ImGuiWindow_ImGuiWindow(ImGuiContext* context,const char* name) -{ - return IM_NEW(ImGuiWindow)(context,name); -} -CIMGUI_API void ImGuiWindow_destroy(ImGuiWindow* self) -{ - IM_DELETE(self); -} -CIMGUI_API ImGuiID ImGuiWindow_GetID_Str(ImGuiWindow* self,const char* str,const char* str_end) -{ - return self->GetID(str,str_end); -} -CIMGUI_API ImGuiID ImGuiWindow_GetID_Ptr(ImGuiWindow* self,const void* ptr) -{ - return self->GetID(ptr); -} -CIMGUI_API ImGuiID ImGuiWindow_GetID_Int(ImGuiWindow* self,int n) -{ - return self->GetID(n); -} -CIMGUI_API ImGuiID ImGuiWindow_GetIDNoKeepAlive_Str(ImGuiWindow* self,const char* str,const char* str_end) -{ - return self->GetIDNoKeepAlive(str,str_end); -} -CIMGUI_API ImGuiID ImGuiWindow_GetIDNoKeepAlive_Ptr(ImGuiWindow* self,const void* ptr) -{ - return self->GetIDNoKeepAlive(ptr); -} -CIMGUI_API ImGuiID ImGuiWindow_GetIDNoKeepAlive_Int(ImGuiWindow* self,int n) -{ - return self->GetIDNoKeepAlive(n); -} -CIMGUI_API ImGuiID ImGuiWindow_GetIDFromRectangle(ImGuiWindow* self,const ImRect r_abs) -{ - return self->GetIDFromRectangle(r_abs); -} -CIMGUI_API void ImGuiWindow_Rect(ImRect *pOut,ImGuiWindow* self) -{ - *pOut = self->Rect(); -} -CIMGUI_API float ImGuiWindow_CalcFontSize(ImGuiWindow* self) -{ - return self->CalcFontSize(); -} -CIMGUI_API float ImGuiWindow_TitleBarHeight(ImGuiWindow* self) -{ - return self->TitleBarHeight(); -} -CIMGUI_API void ImGuiWindow_TitleBarRect(ImRect *pOut,ImGuiWindow* self) -{ - *pOut = self->TitleBarRect(); -} -CIMGUI_API float ImGuiWindow_MenuBarHeight(ImGuiWindow* self) -{ - return self->MenuBarHeight(); -} -CIMGUI_API void ImGuiWindow_MenuBarRect(ImRect *pOut,ImGuiWindow* self) -{ - *pOut = self->MenuBarRect(); -} -CIMGUI_API ImGuiTabItem* ImGuiTabItem_ImGuiTabItem(void) -{ - return IM_NEW(ImGuiTabItem)(); -} -CIMGUI_API void ImGuiTabItem_destroy(ImGuiTabItem* self) -{ - IM_DELETE(self); -} -CIMGUI_API ImGuiTabBar* ImGuiTabBar_ImGuiTabBar(void) -{ - return IM_NEW(ImGuiTabBar)(); -} -CIMGUI_API void ImGuiTabBar_destroy(ImGuiTabBar* self) -{ - IM_DELETE(self); -} -CIMGUI_API int ImGuiTabBar_GetTabOrder(ImGuiTabBar* self,const ImGuiTabItem* tab) -{ - return self->GetTabOrder(tab); -} -CIMGUI_API const char* ImGuiTabBar_GetTabName(ImGuiTabBar* self,const ImGuiTabItem* tab) -{ - return self->GetTabName(tab); -} -CIMGUI_API ImGuiTableColumn* ImGuiTableColumn_ImGuiTableColumn(void) -{ - return IM_NEW(ImGuiTableColumn)(); -} -CIMGUI_API void ImGuiTableColumn_destroy(ImGuiTableColumn* self) -{ - IM_DELETE(self); -} -CIMGUI_API ImGuiTable* ImGuiTable_ImGuiTable(void) -{ - return IM_NEW(ImGuiTable)(); -} -CIMGUI_API void ImGuiTable_destroy(ImGuiTable* self) -{ - IM_DELETE(self); -} -CIMGUI_API ImGuiTableTempData* ImGuiTableTempData_ImGuiTableTempData(void) -{ - return IM_NEW(ImGuiTableTempData)(); -} -CIMGUI_API void ImGuiTableTempData_destroy(ImGuiTableTempData* self) -{ - IM_DELETE(self); -} -CIMGUI_API ImGuiTableColumnSettings* ImGuiTableColumnSettings_ImGuiTableColumnSettings(void) -{ - return IM_NEW(ImGuiTableColumnSettings)(); -} -CIMGUI_API void ImGuiTableColumnSettings_destroy(ImGuiTableColumnSettings* self) -{ - IM_DELETE(self); -} -CIMGUI_API ImGuiTableSettings* ImGuiTableSettings_ImGuiTableSettings(void) -{ - return IM_NEW(ImGuiTableSettings)(); -} -CIMGUI_API void ImGuiTableSettings_destroy(ImGuiTableSettings* self) -{ - IM_DELETE(self); -} -CIMGUI_API ImGuiTableColumnSettings* ImGuiTableSettings_GetColumnSettings(ImGuiTableSettings* self) -{ - return self->GetColumnSettings(); -} -CIMGUI_API ImGuiWindow* igGetCurrentWindowRead() -{ - return ImGui::GetCurrentWindowRead(); -} -CIMGUI_API ImGuiWindow* igGetCurrentWindow() -{ - return ImGui::GetCurrentWindow(); -} -CIMGUI_API ImGuiWindow* igFindWindowByID(ImGuiID id) -{ - return ImGui::FindWindowByID(id); -} -CIMGUI_API ImGuiWindow* igFindWindowByName(const char* name) -{ - return ImGui::FindWindowByName(name); -} -CIMGUI_API void igUpdateWindowParentAndRootLinks(ImGuiWindow* window,ImGuiWindowFlags flags,ImGuiWindow* parent_window) -{ - return ImGui::UpdateWindowParentAndRootLinks(window,flags,parent_window); -} -CIMGUI_API void igCalcWindowNextAutoFitSize(ImVec2 *pOut,ImGuiWindow* window) -{ - *pOut = ImGui::CalcWindowNextAutoFitSize(window); -} -CIMGUI_API bool igIsWindowChildOf(ImGuiWindow* window,ImGuiWindow* potential_parent,bool popup_hierarchy,bool dock_hierarchy) -{ - return ImGui::IsWindowChildOf(window,potential_parent,popup_hierarchy,dock_hierarchy); -} -CIMGUI_API bool igIsWindowWithinBeginStackOf(ImGuiWindow* window,ImGuiWindow* potential_parent) -{ - return ImGui::IsWindowWithinBeginStackOf(window,potential_parent); -} -CIMGUI_API bool igIsWindowAbove(ImGuiWindow* potential_above,ImGuiWindow* potential_below) -{ - return ImGui::IsWindowAbove(potential_above,potential_below); -} -CIMGUI_API bool igIsWindowNavFocusable(ImGuiWindow* window) -{ - return ImGui::IsWindowNavFocusable(window); -} -CIMGUI_API void igSetWindowPos_WindowPtr(ImGuiWindow* window,const ImVec2 pos,ImGuiCond cond) -{ - return ImGui::SetWindowPos(window,pos,cond); -} -CIMGUI_API void igSetWindowSize_WindowPtr(ImGuiWindow* window,const ImVec2 size,ImGuiCond cond) -{ - return ImGui::SetWindowSize(window,size,cond); -} -CIMGUI_API void igSetWindowCollapsed_WindowPtr(ImGuiWindow* window,bool collapsed,ImGuiCond cond) -{ - return ImGui::SetWindowCollapsed(window,collapsed,cond); -} -CIMGUI_API void igSetWindowHitTestHole(ImGuiWindow* window,const ImVec2 pos,const ImVec2 size) -{ - return ImGui::SetWindowHitTestHole(window,pos,size); -} -CIMGUI_API void igWindowRectAbsToRel(ImRect *pOut,ImGuiWindow* window,const ImRect r) -{ - *pOut = ImGui::WindowRectAbsToRel(window,r); -} -CIMGUI_API void igWindowRectRelToAbs(ImRect *pOut,ImGuiWindow* window,const ImRect r) -{ - *pOut = ImGui::WindowRectRelToAbs(window,r); -} -CIMGUI_API void igFocusWindow(ImGuiWindow* window) -{ - return ImGui::FocusWindow(window); -} -CIMGUI_API void igFocusTopMostWindowUnderOne(ImGuiWindow* under_this_window,ImGuiWindow* ignore_window) -{ - return ImGui::FocusTopMostWindowUnderOne(under_this_window,ignore_window); -} -CIMGUI_API void igBringWindowToFocusFront(ImGuiWindow* window) -{ - return ImGui::BringWindowToFocusFront(window); -} -CIMGUI_API void igBringWindowToDisplayFront(ImGuiWindow* window) -{ - return ImGui::BringWindowToDisplayFront(window); -} -CIMGUI_API void igBringWindowToDisplayBack(ImGuiWindow* window) -{ - return ImGui::BringWindowToDisplayBack(window); -} -CIMGUI_API void igBringWindowToDisplayBehind(ImGuiWindow* window,ImGuiWindow* above_window) -{ - return ImGui::BringWindowToDisplayBehind(window,above_window); -} -CIMGUI_API int igFindWindowDisplayIndex(ImGuiWindow* window) -{ - return ImGui::FindWindowDisplayIndex(window); -} -CIMGUI_API ImGuiWindow* igFindBottomMostVisibleWindowWithinBeginStack(ImGuiWindow* window) -{ - return ImGui::FindBottomMostVisibleWindowWithinBeginStack(window); -} -CIMGUI_API void igSetCurrentFont(ImFont* font) -{ - return ImGui::SetCurrentFont(font); -} -CIMGUI_API ImFont* igGetDefaultFont() -{ - return ImGui::GetDefaultFont(); -} -CIMGUI_API ImDrawList* igGetForegroundDrawList_WindowPtr(ImGuiWindow* window) -{ - return ImGui::GetForegroundDrawList(window); -} -CIMGUI_API void igInitialize(ImGuiContext* context) -{ - return ImGui::Initialize(context); -} -CIMGUI_API void igShutdown(ImGuiContext* context) -{ - return ImGui::Shutdown(context); -} -CIMGUI_API void igUpdateHoveredWindowAndCaptureFlags() -{ - return ImGui::UpdateHoveredWindowAndCaptureFlags(); -} -CIMGUI_API void igStartMouseMovingWindow(ImGuiWindow* window) -{ - return ImGui::StartMouseMovingWindow(window); -} -CIMGUI_API void igStartMouseMovingWindowOrNode(ImGuiWindow* window,ImGuiDockNode* node,bool undock_floating_node) -{ - return ImGui::StartMouseMovingWindowOrNode(window,node,undock_floating_node); -} -CIMGUI_API void igUpdateMouseMovingWindowNewFrame() -{ - return ImGui::UpdateMouseMovingWindowNewFrame(); -} -CIMGUI_API void igUpdateMouseMovingWindowEndFrame() -{ - return ImGui::UpdateMouseMovingWindowEndFrame(); -} -CIMGUI_API ImGuiID igAddContextHook(ImGuiContext* context,const ImGuiContextHook* hook) -{ - return ImGui::AddContextHook(context,hook); -} -CIMGUI_API void igRemoveContextHook(ImGuiContext* context,ImGuiID hook_to_remove) -{ - return ImGui::RemoveContextHook(context,hook_to_remove); -} -CIMGUI_API void igCallContextHooks(ImGuiContext* context,ImGuiContextHookType type) -{ - return ImGui::CallContextHooks(context,type); -} -CIMGUI_API void igTranslateWindowsInViewport(ImGuiViewportP* viewport,const ImVec2 old_pos,const ImVec2 new_pos) -{ - return ImGui::TranslateWindowsInViewport(viewport,old_pos,new_pos); -} -CIMGUI_API void igScaleWindowsInViewport(ImGuiViewportP* viewport,float scale) -{ - return ImGui::ScaleWindowsInViewport(viewport,scale); -} -CIMGUI_API void igDestroyPlatformWindow(ImGuiViewportP* viewport) -{ - return ImGui::DestroyPlatformWindow(viewport); -} -CIMGUI_API void igSetCurrentViewport(ImGuiWindow* window,ImGuiViewportP* viewport) -{ - return ImGui::SetCurrentViewport(window,viewport); -} -CIMGUI_API const ImGuiPlatformMonitor* igGetViewportPlatformMonitor(ImGuiViewport* viewport) -{ - return ImGui::GetViewportPlatformMonitor(viewport); -} -CIMGUI_API void igMarkIniSettingsDirty_Nil() -{ - return ImGui::MarkIniSettingsDirty(); -} -CIMGUI_API void igMarkIniSettingsDirty_WindowPtr(ImGuiWindow* window) -{ - return ImGui::MarkIniSettingsDirty(window); -} -CIMGUI_API void igClearIniSettings() -{ - return ImGui::ClearIniSettings(); -} -CIMGUI_API ImGuiWindowSettings* igCreateNewWindowSettings(const char* name) -{ - return ImGui::CreateNewWindowSettings(name); -} -CIMGUI_API ImGuiWindowSettings* igFindWindowSettings(ImGuiID id) -{ - return ImGui::FindWindowSettings(id); -} -CIMGUI_API ImGuiWindowSettings* igFindOrCreateWindowSettings(const char* name) -{ - return ImGui::FindOrCreateWindowSettings(name); -} -CIMGUI_API ImGuiSettingsHandler* igFindSettingsHandler(const char* type_name) -{ - return ImGui::FindSettingsHandler(type_name); -} -CIMGUI_API void igSetNextWindowScroll(const ImVec2 scroll) -{ - return ImGui::SetNextWindowScroll(scroll); -} -CIMGUI_API void igSetScrollX_WindowPtr(ImGuiWindow* window,float scroll_x) -{ - return ImGui::SetScrollX(window,scroll_x); -} -CIMGUI_API void igSetScrollY_WindowPtr(ImGuiWindow* window,float scroll_y) -{ - return ImGui::SetScrollY(window,scroll_y); -} -CIMGUI_API void igSetScrollFromPosX_WindowPtr(ImGuiWindow* window,float local_x,float center_x_ratio) -{ - return ImGui::SetScrollFromPosX(window,local_x,center_x_ratio); -} -CIMGUI_API void igSetScrollFromPosY_WindowPtr(ImGuiWindow* window,float local_y,float center_y_ratio) -{ - return ImGui::SetScrollFromPosY(window,local_y,center_y_ratio); -} -CIMGUI_API void igScrollToItem(ImGuiScrollFlags flags) -{ - return ImGui::ScrollToItem(flags); -} -CIMGUI_API void igScrollToRect(ImGuiWindow* window,const ImRect rect,ImGuiScrollFlags flags) -{ - return ImGui::ScrollToRect(window,rect,flags); -} -CIMGUI_API void igScrollToRectEx(ImVec2 *pOut,ImGuiWindow* window,const ImRect rect,ImGuiScrollFlags flags) -{ - *pOut = ImGui::ScrollToRectEx(window,rect,flags); -} -CIMGUI_API void igScrollToBringRectIntoView(ImGuiWindow* window,const ImRect rect) -{ - return ImGui::ScrollToBringRectIntoView(window,rect); -} -CIMGUI_API ImGuiID igGetItemID() -{ - return ImGui::GetItemID(); -} -CIMGUI_API ImGuiItemStatusFlags igGetItemStatusFlags() -{ - return ImGui::GetItemStatusFlags(); -} -CIMGUI_API ImGuiItemFlags igGetItemFlags() -{ - return ImGui::GetItemFlags(); -} -CIMGUI_API ImGuiID igGetActiveID() -{ - return ImGui::GetActiveID(); -} -CIMGUI_API ImGuiID igGetFocusID() -{ - return ImGui::GetFocusID(); -} -CIMGUI_API void igSetActiveID(ImGuiID id,ImGuiWindow* window) -{ - return ImGui::SetActiveID(id,window); -} -CIMGUI_API void igSetFocusID(ImGuiID id,ImGuiWindow* window) -{ - return ImGui::SetFocusID(id,window); -} -CIMGUI_API void igClearActiveID() -{ - return ImGui::ClearActiveID(); -} -CIMGUI_API ImGuiID igGetHoveredID() -{ - return ImGui::GetHoveredID(); -} -CIMGUI_API void igSetHoveredID(ImGuiID id) -{ - return ImGui::SetHoveredID(id); -} -CIMGUI_API void igKeepAliveID(ImGuiID id) -{ - return ImGui::KeepAliveID(id); -} -CIMGUI_API void igMarkItemEdited(ImGuiID id) -{ - return ImGui::MarkItemEdited(id); -} -CIMGUI_API void igPushOverrideID(ImGuiID id) -{ - return ImGui::PushOverrideID(id); -} -CIMGUI_API ImGuiID igGetIDWithSeed(const char* str_id_begin,const char* str_id_end,ImGuiID seed) -{ - return ImGui::GetIDWithSeed(str_id_begin,str_id_end,seed); -} -CIMGUI_API void igItemSize_Vec2(const ImVec2 size,float text_baseline_y) -{ - return ImGui::ItemSize(size,text_baseline_y); -} -CIMGUI_API void igItemSize_Rect(const ImRect bb,float text_baseline_y) -{ - return ImGui::ItemSize(bb,text_baseline_y); -} -CIMGUI_API bool igItemAdd(const ImRect bb,ImGuiID id,const ImRect* nav_bb,ImGuiItemFlags extra_flags) -{ - return ImGui::ItemAdd(bb,id,nav_bb,extra_flags); -} -CIMGUI_API bool igItemHoverable(const ImRect bb,ImGuiID id) -{ - return ImGui::ItemHoverable(bb,id); -} -CIMGUI_API bool igIsClippedEx(const ImRect bb,ImGuiID id) -{ - return ImGui::IsClippedEx(bb,id); -} -CIMGUI_API void igSetLastItemData(ImGuiID item_id,ImGuiItemFlags in_flags,ImGuiItemStatusFlags status_flags,const ImRect item_rect) -{ - return ImGui::SetLastItemData(item_id,in_flags,status_flags,item_rect); -} -CIMGUI_API void igCalcItemSize(ImVec2 *pOut,ImVec2 size,float default_w,float default_h) -{ - *pOut = ImGui::CalcItemSize(size,default_w,default_h); -} -CIMGUI_API float igCalcWrapWidthForPos(const ImVec2 pos,float wrap_pos_x) -{ - return ImGui::CalcWrapWidthForPos(pos,wrap_pos_x); -} -CIMGUI_API void igPushMultiItemsWidths(int components,float width_full) -{ - return ImGui::PushMultiItemsWidths(components,width_full); -} -CIMGUI_API bool igIsItemToggledSelection() -{ - return ImGui::IsItemToggledSelection(); -} -CIMGUI_API void igGetContentRegionMaxAbs(ImVec2 *pOut) -{ - *pOut = ImGui::GetContentRegionMaxAbs(); -} -CIMGUI_API void igShrinkWidths(ImGuiShrinkWidthItem* items,int count,float width_excess) -{ - return ImGui::ShrinkWidths(items,count,width_excess); -} -CIMGUI_API void igPushItemFlag(ImGuiItemFlags option,bool enabled) -{ - return ImGui::PushItemFlag(option,enabled); -} -CIMGUI_API void igPopItemFlag() -{ - return ImGui::PopItemFlag(); -} -CIMGUI_API void igLogBegin(ImGuiLogType type,int auto_open_depth) -{ - return ImGui::LogBegin(type,auto_open_depth); -} -CIMGUI_API void igLogToBuffer(int auto_open_depth) -{ - return ImGui::LogToBuffer(auto_open_depth); -} -CIMGUI_API void igLogRenderedText(const ImVec2* ref_pos,const char* text,const char* text_end) -{ - return ImGui::LogRenderedText(ref_pos,text,text_end); -} -CIMGUI_API void igLogSetNextTextDecoration(const char* prefix,const char* suffix) -{ - return ImGui::LogSetNextTextDecoration(prefix,suffix); -} -CIMGUI_API bool igBeginChildEx(const char* name,ImGuiID id,const ImVec2 size_arg,bool border,ImGuiWindowFlags flags) -{ - return ImGui::BeginChildEx(name,id,size_arg,border,flags); -} -CIMGUI_API void igOpenPopupEx(ImGuiID id,ImGuiPopupFlags popup_flags) -{ - return ImGui::OpenPopupEx(id,popup_flags); -} -CIMGUI_API void igClosePopupToLevel(int remaining,bool restore_focus_to_window_under_popup) -{ - return ImGui::ClosePopupToLevel(remaining,restore_focus_to_window_under_popup); -} -CIMGUI_API void igClosePopupsOverWindow(ImGuiWindow* ref_window,bool restore_focus_to_window_under_popup) -{ - return ImGui::ClosePopupsOverWindow(ref_window,restore_focus_to_window_under_popup); -} -CIMGUI_API void igClosePopupsExceptModals() -{ - return ImGui::ClosePopupsExceptModals(); -} -CIMGUI_API bool igIsPopupOpen_ID(ImGuiID id,ImGuiPopupFlags popup_flags) -{ - return ImGui::IsPopupOpen(id,popup_flags); -} -CIMGUI_API bool igBeginPopupEx(ImGuiID id,ImGuiWindowFlags extra_flags) -{ - return ImGui::BeginPopupEx(id,extra_flags); -} -CIMGUI_API void igBeginTooltipEx(ImGuiTooltipFlags tooltip_flags,ImGuiWindowFlags extra_window_flags) -{ - return ImGui::BeginTooltipEx(tooltip_flags,extra_window_flags); -} -CIMGUI_API void igGetPopupAllowedExtentRect(ImRect *pOut,ImGuiWindow* window) -{ - *pOut = ImGui::GetPopupAllowedExtentRect(window); -} -CIMGUI_API ImGuiWindow* igGetTopMostPopupModal() -{ - return ImGui::GetTopMostPopupModal(); -} -CIMGUI_API ImGuiWindow* igGetTopMostAndVisiblePopupModal() -{ - return ImGui::GetTopMostAndVisiblePopupModal(); -} -CIMGUI_API void igFindBestWindowPosForPopup(ImVec2 *pOut,ImGuiWindow* window) -{ - *pOut = ImGui::FindBestWindowPosForPopup(window); -} -CIMGUI_API void igFindBestWindowPosForPopupEx(ImVec2 *pOut,const ImVec2 ref_pos,const ImVec2 size,ImGuiDir* last_dir,const ImRect r_outer,const ImRect r_avoid,ImGuiPopupPositionPolicy policy) -{ - *pOut = ImGui::FindBestWindowPosForPopupEx(ref_pos,size,last_dir,r_outer,r_avoid,policy); -} -CIMGUI_API bool igBeginViewportSideBar(const char* name,ImGuiViewport* viewport,ImGuiDir dir,float size,ImGuiWindowFlags window_flags) -{ - return ImGui::BeginViewportSideBar(name,viewport,dir,size,window_flags); -} -CIMGUI_API bool igBeginMenuEx(const char* label,const char* icon,bool enabled) -{ - return ImGui::BeginMenuEx(label,icon,enabled); -} -CIMGUI_API bool igMenuItemEx(const char* label,const char* icon,const char* shortcut,bool selected,bool enabled) -{ - return ImGui::MenuItemEx(label,icon,shortcut,selected,enabled); -} -CIMGUI_API bool igBeginComboPopup(ImGuiID popup_id,const ImRect bb,ImGuiComboFlags flags) -{ - return ImGui::BeginComboPopup(popup_id,bb,flags); -} -CIMGUI_API bool igBeginComboPreview() -{ - return ImGui::BeginComboPreview(); -} -CIMGUI_API void igEndComboPreview() -{ - return ImGui::EndComboPreview(); -} -CIMGUI_API void igNavInitWindow(ImGuiWindow* window,bool force_reinit) -{ - return ImGui::NavInitWindow(window,force_reinit); -} -CIMGUI_API void igNavInitRequestApplyResult() -{ - return ImGui::NavInitRequestApplyResult(); -} -CIMGUI_API bool igNavMoveRequestButNoResultYet() -{ - return ImGui::NavMoveRequestButNoResultYet(); -} -CIMGUI_API void igNavMoveRequestSubmit(ImGuiDir move_dir,ImGuiDir clip_dir,ImGuiNavMoveFlags move_flags,ImGuiScrollFlags scroll_flags) -{ - return ImGui::NavMoveRequestSubmit(move_dir,clip_dir,move_flags,scroll_flags); -} -CIMGUI_API void igNavMoveRequestForward(ImGuiDir move_dir,ImGuiDir clip_dir,ImGuiNavMoveFlags move_flags,ImGuiScrollFlags scroll_flags) -{ - return ImGui::NavMoveRequestForward(move_dir,clip_dir,move_flags,scroll_flags); -} -CIMGUI_API void igNavMoveRequestResolveWithLastItem(ImGuiNavItemData* result) -{ - return ImGui::NavMoveRequestResolveWithLastItem(result); -} -CIMGUI_API void igNavMoveRequestCancel() -{ - return ImGui::NavMoveRequestCancel(); -} -CIMGUI_API void igNavMoveRequestApplyResult() -{ - return ImGui::NavMoveRequestApplyResult(); -} -CIMGUI_API void igNavMoveRequestTryWrapping(ImGuiWindow* window,ImGuiNavMoveFlags move_flags) -{ - return ImGui::NavMoveRequestTryWrapping(window,move_flags); -} -CIMGUI_API float igGetNavInputAmount(ImGuiNavInput n,ImGuiInputReadMode mode) -{ - return ImGui::GetNavInputAmount(n,mode); -} -CIMGUI_API void igGetNavInputAmount2d(ImVec2 *pOut,ImGuiNavDirSourceFlags dir_sources,ImGuiInputReadMode mode,float slow_factor,float fast_factor) -{ - *pOut = ImGui::GetNavInputAmount2d(dir_sources,mode,slow_factor,fast_factor); -} -CIMGUI_API int igCalcTypematicRepeatAmount(float t0,float t1,float repeat_delay,float repeat_rate) -{ - return ImGui::CalcTypematicRepeatAmount(t0,t1,repeat_delay,repeat_rate); -} -CIMGUI_API void igActivateItem(ImGuiID id) -{ - return ImGui::ActivateItem(id); -} -CIMGUI_API void igSetNavID(ImGuiID id,ImGuiNavLayer nav_layer,ImGuiID focus_scope_id,const ImRect rect_rel) -{ - return ImGui::SetNavID(id,nav_layer,focus_scope_id,rect_rel); -} -CIMGUI_API void igPushFocusScope(ImGuiID id) -{ - return ImGui::PushFocusScope(id); -} -CIMGUI_API void igPopFocusScope() -{ - return ImGui::PopFocusScope(); -} -CIMGUI_API ImGuiID igGetFocusedFocusScope() -{ - return ImGui::GetFocusedFocusScope(); -} -CIMGUI_API ImGuiID igGetFocusScope() -{ - return ImGui::GetFocusScope(); -} -CIMGUI_API void igSetItemUsingMouseWheel() -{ - return ImGui::SetItemUsingMouseWheel(); -} -CIMGUI_API void igSetActiveIdUsingNavAndKeys() -{ - return ImGui::SetActiveIdUsingNavAndKeys(); -} -CIMGUI_API bool igIsActiveIdUsingNavDir(ImGuiDir dir) -{ - return ImGui::IsActiveIdUsingNavDir(dir); -} -CIMGUI_API bool igIsActiveIdUsingNavInput(ImGuiNavInput input) -{ - return ImGui::IsActiveIdUsingNavInput(input); -} -CIMGUI_API bool igIsActiveIdUsingKey(ImGuiKey key) -{ - return ImGui::IsActiveIdUsingKey(key); -} -CIMGUI_API bool igIsMouseDragPastThreshold(ImGuiMouseButton button,float lock_threshold) -{ - return ImGui::IsMouseDragPastThreshold(button,lock_threshold); -} -CIMGUI_API bool igIsKeyPressedMap(ImGuiKey key,bool repeat) -{ - return ImGui::IsKeyPressedMap(key,repeat); -} -CIMGUI_API bool igIsNavInputDown(ImGuiNavInput n) -{ - return ImGui::IsNavInputDown(n); -} -CIMGUI_API bool igIsNavInputTest(ImGuiNavInput n,ImGuiInputReadMode rm) -{ - return ImGui::IsNavInputTest(n,rm); -} -CIMGUI_API ImGuiKeyModFlags igGetMergedKeyModFlags() -{ - return ImGui::GetMergedKeyModFlags(); -} -CIMGUI_API void igDockContextInitialize(ImGuiContext* ctx) -{ - return ImGui::DockContextInitialize(ctx); -} -CIMGUI_API void igDockContextShutdown(ImGuiContext* ctx) -{ - return ImGui::DockContextShutdown(ctx); -} -CIMGUI_API void igDockContextClearNodes(ImGuiContext* ctx,ImGuiID root_id,bool clear_settings_refs) -{ - return ImGui::DockContextClearNodes(ctx,root_id,clear_settings_refs); -} -CIMGUI_API void igDockContextRebuildNodes(ImGuiContext* ctx) -{ - return ImGui::DockContextRebuildNodes(ctx); -} -CIMGUI_API void igDockContextNewFrameUpdateUndocking(ImGuiContext* ctx) -{ - return ImGui::DockContextNewFrameUpdateUndocking(ctx); -} -CIMGUI_API void igDockContextNewFrameUpdateDocking(ImGuiContext* ctx) -{ - return ImGui::DockContextNewFrameUpdateDocking(ctx); -} -CIMGUI_API void igDockContextEndFrame(ImGuiContext* ctx) -{ - return ImGui::DockContextEndFrame(ctx); -} -CIMGUI_API ImGuiID igDockContextGenNodeID(ImGuiContext* ctx) -{ - return ImGui::DockContextGenNodeID(ctx); -} -CIMGUI_API void igDockContextQueueDock(ImGuiContext* ctx,ImGuiWindow* target,ImGuiDockNode* target_node,ImGuiWindow* payload,ImGuiDir split_dir,float split_ratio,bool split_outer) -{ - return ImGui::DockContextQueueDock(ctx,target,target_node,payload,split_dir,split_ratio,split_outer); -} -CIMGUI_API void igDockContextQueueUndockWindow(ImGuiContext* ctx,ImGuiWindow* window) -{ - return ImGui::DockContextQueueUndockWindow(ctx,window); -} -CIMGUI_API void igDockContextQueueUndockNode(ImGuiContext* ctx,ImGuiDockNode* node) -{ - return ImGui::DockContextQueueUndockNode(ctx,node); -} -CIMGUI_API bool igDockContextCalcDropPosForDocking(ImGuiWindow* target,ImGuiDockNode* target_node,ImGuiWindow* payload,ImGuiDir split_dir,bool split_outer,ImVec2* out_pos) -{ - return ImGui::DockContextCalcDropPosForDocking(target,target_node,payload,split_dir,split_outer,out_pos); -} -CIMGUI_API bool igDockNodeBeginAmendTabBar(ImGuiDockNode* node) -{ - return ImGui::DockNodeBeginAmendTabBar(node); -} -CIMGUI_API void igDockNodeEndAmendTabBar() -{ - return ImGui::DockNodeEndAmendTabBar(); -} -CIMGUI_API ImGuiDockNode* igDockNodeGetRootNode(ImGuiDockNode* node) -{ - return ImGui::DockNodeGetRootNode(node); -} -CIMGUI_API bool igDockNodeIsInHierarchyOf(ImGuiDockNode* node,ImGuiDockNode* parent) -{ - return ImGui::DockNodeIsInHierarchyOf(node,parent); -} -CIMGUI_API int igDockNodeGetDepth(const ImGuiDockNode* node) -{ - return ImGui::DockNodeGetDepth(node); -} -CIMGUI_API ImGuiID igDockNodeGetWindowMenuButtonId(const ImGuiDockNode* node) -{ - return ImGui::DockNodeGetWindowMenuButtonId(node); -} -CIMGUI_API ImGuiDockNode* igGetWindowDockNode() -{ - return ImGui::GetWindowDockNode(); -} -CIMGUI_API bool igGetWindowAlwaysWantOwnTabBar(ImGuiWindow* window) -{ - return ImGui::GetWindowAlwaysWantOwnTabBar(window); -} -CIMGUI_API void igBeginDocked(ImGuiWindow* window,bool* p_open) -{ - return ImGui::BeginDocked(window,p_open); -} -CIMGUI_API void igBeginDockableDragDropSource(ImGuiWindow* window) -{ - return ImGui::BeginDockableDragDropSource(window); -} -CIMGUI_API void igBeginDockableDragDropTarget(ImGuiWindow* window) -{ - return ImGui::BeginDockableDragDropTarget(window); -} -CIMGUI_API void igSetWindowDock(ImGuiWindow* window,ImGuiID dock_id,ImGuiCond cond) -{ - return ImGui::SetWindowDock(window,dock_id,cond); -} -CIMGUI_API void igDockBuilderDockWindow(const char* window_name,ImGuiID node_id) -{ - return ImGui::DockBuilderDockWindow(window_name,node_id); -} -CIMGUI_API ImGuiDockNode* igDockBuilderGetNode(ImGuiID node_id) -{ - return ImGui::DockBuilderGetNode(node_id); -} -CIMGUI_API ImGuiDockNode* igDockBuilderGetCentralNode(ImGuiID node_id) -{ - return ImGui::DockBuilderGetCentralNode(node_id); -} -CIMGUI_API ImGuiID igDockBuilderAddNode(ImGuiID node_id,ImGuiDockNodeFlags flags) -{ - return ImGui::DockBuilderAddNode(node_id,flags); -} -CIMGUI_API void igDockBuilderRemoveNode(ImGuiID node_id) -{ - return ImGui::DockBuilderRemoveNode(node_id); -} -CIMGUI_API void igDockBuilderRemoveNodeDockedWindows(ImGuiID node_id,bool clear_settings_refs) -{ - return ImGui::DockBuilderRemoveNodeDockedWindows(node_id,clear_settings_refs); -} -CIMGUI_API void igDockBuilderRemoveNodeChildNodes(ImGuiID node_id) -{ - return ImGui::DockBuilderRemoveNodeChildNodes(node_id); -} -CIMGUI_API void igDockBuilderSetNodePos(ImGuiID node_id,ImVec2 pos) -{ - return ImGui::DockBuilderSetNodePos(node_id,pos); -} -CIMGUI_API void igDockBuilderSetNodeSize(ImGuiID node_id,ImVec2 size) -{ - return ImGui::DockBuilderSetNodeSize(node_id,size); -} -CIMGUI_API ImGuiID igDockBuilderSplitNode(ImGuiID node_id,ImGuiDir split_dir,float size_ratio_for_node_at_dir,ImGuiID* out_id_at_dir,ImGuiID* out_id_at_opposite_dir) -{ - return ImGui::DockBuilderSplitNode(node_id,split_dir,size_ratio_for_node_at_dir,out_id_at_dir,out_id_at_opposite_dir); -} -CIMGUI_API void igDockBuilderCopyDockSpace(ImGuiID src_dockspace_id,ImGuiID dst_dockspace_id,ImVector_const_charPtr* in_window_remap_pairs) -{ - return ImGui::DockBuilderCopyDockSpace(src_dockspace_id,dst_dockspace_id,in_window_remap_pairs); -} -CIMGUI_API void igDockBuilderCopyNode(ImGuiID src_node_id,ImGuiID dst_node_id,ImVector_ImGuiID* out_node_remap_pairs) -{ - return ImGui::DockBuilderCopyNode(src_node_id,dst_node_id,out_node_remap_pairs); -} -CIMGUI_API void igDockBuilderCopyWindowSettings(const char* src_name,const char* dst_name) -{ - return ImGui::DockBuilderCopyWindowSettings(src_name,dst_name); -} -CIMGUI_API void igDockBuilderFinish(ImGuiID node_id) -{ - return ImGui::DockBuilderFinish(node_id); -} -CIMGUI_API bool igBeginDragDropTargetCustom(const ImRect bb,ImGuiID id) -{ - return ImGui::BeginDragDropTargetCustom(bb,id); -} -CIMGUI_API void igClearDragDrop() -{ - return ImGui::ClearDragDrop(); -} -CIMGUI_API bool igIsDragDropPayloadBeingAccepted() -{ - return ImGui::IsDragDropPayloadBeingAccepted(); -} -CIMGUI_API void igSetWindowClipRectBeforeSetChannel(ImGuiWindow* window,const ImRect clip_rect) -{ - return ImGui::SetWindowClipRectBeforeSetChannel(window,clip_rect); -} -CIMGUI_API void igBeginColumns(const char* str_id,int count,ImGuiOldColumnFlags flags) -{ - return ImGui::BeginColumns(str_id,count,flags); -} -CIMGUI_API void igEndColumns() -{ - return ImGui::EndColumns(); -} -CIMGUI_API void igPushColumnClipRect(int column_index) -{ - return ImGui::PushColumnClipRect(column_index); -} -CIMGUI_API void igPushColumnsBackground() -{ - return ImGui::PushColumnsBackground(); -} -CIMGUI_API void igPopColumnsBackground() -{ - return ImGui::PopColumnsBackground(); -} -CIMGUI_API ImGuiID igGetColumnsID(const char* str_id,int count) -{ - return ImGui::GetColumnsID(str_id,count); -} -CIMGUI_API ImGuiOldColumns* igFindOrCreateColumns(ImGuiWindow* window,ImGuiID id) -{ - return ImGui::FindOrCreateColumns(window,id); -} -CIMGUI_API float igGetColumnOffsetFromNorm(const ImGuiOldColumns* columns,float offset_norm) -{ - return ImGui::GetColumnOffsetFromNorm(columns,offset_norm); -} -CIMGUI_API float igGetColumnNormFromOffset(const ImGuiOldColumns* columns,float offset) -{ - return ImGui::GetColumnNormFromOffset(columns,offset); -} -CIMGUI_API void igTableOpenContextMenu(int column_n) -{ - return ImGui::TableOpenContextMenu(column_n); -} -CIMGUI_API void igTableSetColumnWidth(int column_n,float width) -{ - return ImGui::TableSetColumnWidth(column_n,width); -} -CIMGUI_API void igTableSetColumnSortDirection(int column_n,ImGuiSortDirection sort_direction,bool append_to_sort_specs) -{ - return ImGui::TableSetColumnSortDirection(column_n,sort_direction,append_to_sort_specs); -} -CIMGUI_API int igTableGetHoveredColumn() -{ - return ImGui::TableGetHoveredColumn(); -} -CIMGUI_API float igTableGetHeaderRowHeight() -{ - return ImGui::TableGetHeaderRowHeight(); -} -CIMGUI_API void igTablePushBackgroundChannel() -{ - return ImGui::TablePushBackgroundChannel(); -} -CIMGUI_API void igTablePopBackgroundChannel() -{ - return ImGui::TablePopBackgroundChannel(); -} -CIMGUI_API ImGuiTable* igGetCurrentTable() -{ - return ImGui::GetCurrentTable(); -} -CIMGUI_API ImGuiTable* igTableFindByID(ImGuiID id) -{ - return ImGui::TableFindByID(id); -} -CIMGUI_API bool igBeginTableEx(const char* name,ImGuiID id,int columns_count,ImGuiTableFlags flags,const ImVec2 outer_size,float inner_width) -{ - return ImGui::BeginTableEx(name,id,columns_count,flags,outer_size,inner_width); -} -CIMGUI_API void igTableBeginInitMemory(ImGuiTable* table,int columns_count) -{ - return ImGui::TableBeginInitMemory(table,columns_count); -} -CIMGUI_API void igTableBeginApplyRequests(ImGuiTable* table) -{ - return ImGui::TableBeginApplyRequests(table); -} -CIMGUI_API void igTableSetupDrawChannels(ImGuiTable* table) -{ - return ImGui::TableSetupDrawChannels(table); -} -CIMGUI_API void igTableUpdateLayout(ImGuiTable* table) -{ - return ImGui::TableUpdateLayout(table); -} -CIMGUI_API void igTableUpdateBorders(ImGuiTable* table) -{ - return ImGui::TableUpdateBorders(table); -} -CIMGUI_API void igTableUpdateColumnsWeightFromWidth(ImGuiTable* table) -{ - return ImGui::TableUpdateColumnsWeightFromWidth(table); -} -CIMGUI_API void igTableDrawBorders(ImGuiTable* table) -{ - return ImGui::TableDrawBorders(table); -} -CIMGUI_API void igTableDrawContextMenu(ImGuiTable* table) -{ - return ImGui::TableDrawContextMenu(table); -} -CIMGUI_API void igTableMergeDrawChannels(ImGuiTable* table) -{ - return ImGui::TableMergeDrawChannels(table); -} -CIMGUI_API void igTableSortSpecsSanitize(ImGuiTable* table) -{ - return ImGui::TableSortSpecsSanitize(table); -} -CIMGUI_API void igTableSortSpecsBuild(ImGuiTable* table) -{ - return ImGui::TableSortSpecsBuild(table); -} -CIMGUI_API ImGuiSortDirection igTableGetColumnNextSortDirection(ImGuiTableColumn* column) -{ - return ImGui::TableGetColumnNextSortDirection(column); -} -CIMGUI_API void igTableFixColumnSortDirection(ImGuiTable* table,ImGuiTableColumn* column) -{ - return ImGui::TableFixColumnSortDirection(table,column); -} -CIMGUI_API float igTableGetColumnWidthAuto(ImGuiTable* table,ImGuiTableColumn* column) -{ - return ImGui::TableGetColumnWidthAuto(table,column); -} -CIMGUI_API void igTableBeginRow(ImGuiTable* table) -{ - return ImGui::TableBeginRow(table); -} -CIMGUI_API void igTableEndRow(ImGuiTable* table) -{ - return ImGui::TableEndRow(table); -} -CIMGUI_API void igTableBeginCell(ImGuiTable* table,int column_n) -{ - return ImGui::TableBeginCell(table,column_n); -} -CIMGUI_API void igTableEndCell(ImGuiTable* table) -{ - return ImGui::TableEndCell(table); -} -CIMGUI_API void igTableGetCellBgRect(ImRect *pOut,const ImGuiTable* table,int column_n) -{ - *pOut = ImGui::TableGetCellBgRect(table,column_n); -} -CIMGUI_API const char* igTableGetColumnName_TablePtr(const ImGuiTable* table,int column_n) -{ - return ImGui::TableGetColumnName(table,column_n); -} -CIMGUI_API ImGuiID igTableGetColumnResizeID(const ImGuiTable* table,int column_n,int instance_no) -{ - return ImGui::TableGetColumnResizeID(table,column_n,instance_no); -} -CIMGUI_API float igTableGetMaxColumnWidth(const ImGuiTable* table,int column_n) -{ - return ImGui::TableGetMaxColumnWidth(table,column_n); -} -CIMGUI_API void igTableSetColumnWidthAutoSingle(ImGuiTable* table,int column_n) -{ - return ImGui::TableSetColumnWidthAutoSingle(table,column_n); -} -CIMGUI_API void igTableSetColumnWidthAutoAll(ImGuiTable* table) -{ - return ImGui::TableSetColumnWidthAutoAll(table); -} -CIMGUI_API void igTableRemove(ImGuiTable* table) -{ - return ImGui::TableRemove(table); -} -CIMGUI_API void igTableGcCompactTransientBuffers_TablePtr(ImGuiTable* table) -{ - return ImGui::TableGcCompactTransientBuffers(table); -} -CIMGUI_API void igTableGcCompactTransientBuffers_TableTempDataPtr(ImGuiTableTempData* table) -{ - return ImGui::TableGcCompactTransientBuffers(table); -} -CIMGUI_API void igTableGcCompactSettings() -{ - return ImGui::TableGcCompactSettings(); -} -CIMGUI_API void igTableLoadSettings(ImGuiTable* table) -{ - return ImGui::TableLoadSettings(table); -} -CIMGUI_API void igTableSaveSettings(ImGuiTable* table) -{ - return ImGui::TableSaveSettings(table); -} -CIMGUI_API void igTableResetSettings(ImGuiTable* table) -{ - return ImGui::TableResetSettings(table); -} -CIMGUI_API ImGuiTableSettings* igTableGetBoundSettings(ImGuiTable* table) -{ - return ImGui::TableGetBoundSettings(table); -} -CIMGUI_API void igTableSettingsInstallHandler(ImGuiContext* context) -{ - return ImGui::TableSettingsInstallHandler(context); -} -CIMGUI_API ImGuiTableSettings* igTableSettingsCreate(ImGuiID id,int columns_count) -{ - return ImGui::TableSettingsCreate(id,columns_count); -} -CIMGUI_API ImGuiTableSettings* igTableSettingsFindByID(ImGuiID id) -{ - return ImGui::TableSettingsFindByID(id); -} -CIMGUI_API bool igBeginTabBarEx(ImGuiTabBar* tab_bar,const ImRect bb,ImGuiTabBarFlags flags,ImGuiDockNode* dock_node) -{ - return ImGui::BeginTabBarEx(tab_bar,bb,flags,dock_node); -} -CIMGUI_API ImGuiTabItem* igTabBarFindTabByID(ImGuiTabBar* tab_bar,ImGuiID tab_id) -{ - return ImGui::TabBarFindTabByID(tab_bar,tab_id); -} -CIMGUI_API ImGuiTabItem* igTabBarFindMostRecentlySelectedTabForActiveWindow(ImGuiTabBar* tab_bar) -{ - return ImGui::TabBarFindMostRecentlySelectedTabForActiveWindow(tab_bar); -} -CIMGUI_API void igTabBarAddTab(ImGuiTabBar* tab_bar,ImGuiTabItemFlags tab_flags,ImGuiWindow* window) -{ - return ImGui::TabBarAddTab(tab_bar,tab_flags,window); -} -CIMGUI_API void igTabBarRemoveTab(ImGuiTabBar* tab_bar,ImGuiID tab_id) -{ - return ImGui::TabBarRemoveTab(tab_bar,tab_id); -} -CIMGUI_API void igTabBarCloseTab(ImGuiTabBar* tab_bar,ImGuiTabItem* tab) -{ - return ImGui::TabBarCloseTab(tab_bar,tab); -} -CIMGUI_API void igTabBarQueueReorder(ImGuiTabBar* tab_bar,const ImGuiTabItem* tab,int offset) -{ - return ImGui::TabBarQueueReorder(tab_bar,tab,offset); -} -CIMGUI_API void igTabBarQueueReorderFromMousePos(ImGuiTabBar* tab_bar,const ImGuiTabItem* tab,ImVec2 mouse_pos) -{ - return ImGui::TabBarQueueReorderFromMousePos(tab_bar,tab,mouse_pos); -} -CIMGUI_API bool igTabBarProcessReorder(ImGuiTabBar* tab_bar) -{ - return ImGui::TabBarProcessReorder(tab_bar); -} -CIMGUI_API bool igTabItemEx(ImGuiTabBar* tab_bar,const char* label,bool* p_open,ImGuiTabItemFlags flags,ImGuiWindow* docked_window) -{ - return ImGui::TabItemEx(tab_bar,label,p_open,flags,docked_window); -} -CIMGUI_API void igTabItemCalcSize(ImVec2 *pOut,const char* label,bool has_close_button) -{ - *pOut = ImGui::TabItemCalcSize(label,has_close_button); -} -CIMGUI_API void igTabItemBackground(ImDrawList* draw_list,const ImRect bb,ImGuiTabItemFlags flags,ImU32 col) -{ - return ImGui::TabItemBackground(draw_list,bb,flags,col); -} -CIMGUI_API void igTabItemLabelAndCloseButton(ImDrawList* draw_list,const ImRect bb,ImGuiTabItemFlags flags,ImVec2 frame_padding,const char* label,ImGuiID tab_id,ImGuiID close_button_id,bool is_contents_visible,bool* out_just_closed,bool* out_text_clipped) -{ - return ImGui::TabItemLabelAndCloseButton(draw_list,bb,flags,frame_padding,label,tab_id,close_button_id,is_contents_visible,out_just_closed,out_text_clipped); -} -CIMGUI_API void igRenderText(ImVec2 pos,const char* text,const char* text_end,bool hide_text_after_hash) -{ - return ImGui::RenderText(pos,text,text_end,hide_text_after_hash); -} -CIMGUI_API void igRenderTextWrapped(ImVec2 pos,const char* text,const char* text_end,float wrap_width) -{ - return ImGui::RenderTextWrapped(pos,text,text_end,wrap_width); -} -CIMGUI_API void igRenderTextClipped(const ImVec2 pos_min,const ImVec2 pos_max,const char* text,const char* text_end,const ImVec2* text_size_if_known,const ImVec2 align,const ImRect* clip_rect) -{ - return ImGui::RenderTextClipped(pos_min,pos_max,text,text_end,text_size_if_known,align,clip_rect); -} -CIMGUI_API void igRenderTextClippedEx(ImDrawList* draw_list,const ImVec2 pos_min,const ImVec2 pos_max,const char* text,const char* text_end,const ImVec2* text_size_if_known,const ImVec2 align,const ImRect* clip_rect) -{ - return ImGui::RenderTextClippedEx(draw_list,pos_min,pos_max,text,text_end,text_size_if_known,align,clip_rect); -} -CIMGUI_API void igRenderTextEllipsis(ImDrawList* draw_list,const ImVec2 pos_min,const ImVec2 pos_max,float clip_max_x,float ellipsis_max_x,const char* text,const char* text_end,const ImVec2* text_size_if_known) -{ - return ImGui::RenderTextEllipsis(draw_list,pos_min,pos_max,clip_max_x,ellipsis_max_x,text,text_end,text_size_if_known); -} -CIMGUI_API void igRenderFrame(ImVec2 p_min,ImVec2 p_max,ImU32 fill_col,bool border,float rounding) -{ - return ImGui::RenderFrame(p_min,p_max,fill_col,border,rounding); -} -CIMGUI_API void igRenderFrameBorder(ImVec2 p_min,ImVec2 p_max,float rounding) -{ - return ImGui::RenderFrameBorder(p_min,p_max,rounding); -} -CIMGUI_API void igRenderColorRectWithAlphaCheckerboard(ImDrawList* draw_list,ImVec2 p_min,ImVec2 p_max,ImU32 fill_col,float grid_step,ImVec2 grid_off,float rounding,ImDrawFlags flags) -{ - return ImGui::RenderColorRectWithAlphaCheckerboard(draw_list,p_min,p_max,fill_col,grid_step,grid_off,rounding,flags); -} -CIMGUI_API void igRenderNavHighlight(const ImRect bb,ImGuiID id,ImGuiNavHighlightFlags flags) -{ - return ImGui::RenderNavHighlight(bb,id,flags); -} -CIMGUI_API const char* igFindRenderedTextEnd(const char* text,const char* text_end) -{ - return ImGui::FindRenderedTextEnd(text,text_end); -} -CIMGUI_API void igRenderArrow(ImDrawList* draw_list,ImVec2 pos,ImU32 col,ImGuiDir dir,float scale) -{ - return ImGui::RenderArrow(draw_list,pos,col,dir,scale); -} -CIMGUI_API void igRenderBullet(ImDrawList* draw_list,ImVec2 pos,ImU32 col) -{ - return ImGui::RenderBullet(draw_list,pos,col); -} -CIMGUI_API void igRenderCheckMark(ImDrawList* draw_list,ImVec2 pos,ImU32 col,float sz) -{ - return ImGui::RenderCheckMark(draw_list,pos,col,sz); -} -CIMGUI_API void igRenderMouseCursor(ImDrawList* draw_list,ImVec2 pos,float scale,ImGuiMouseCursor mouse_cursor,ImU32 col_fill,ImU32 col_border,ImU32 col_shadow) -{ - return ImGui::RenderMouseCursor(draw_list,pos,scale,mouse_cursor,col_fill,col_border,col_shadow); -} -CIMGUI_API void igRenderArrowPointingAt(ImDrawList* draw_list,ImVec2 pos,ImVec2 half_sz,ImGuiDir direction,ImU32 col) -{ - return ImGui::RenderArrowPointingAt(draw_list,pos,half_sz,direction,col); -} -CIMGUI_API void igRenderArrowDockMenu(ImDrawList* draw_list,ImVec2 p_min,float sz,ImU32 col) -{ - return ImGui::RenderArrowDockMenu(draw_list,p_min,sz,col); -} -CIMGUI_API void igRenderRectFilledRangeH(ImDrawList* draw_list,const ImRect rect,ImU32 col,float x_start_norm,float x_end_norm,float rounding) -{ - return ImGui::RenderRectFilledRangeH(draw_list,rect,col,x_start_norm,x_end_norm,rounding); -} -CIMGUI_API void igRenderRectFilledWithHole(ImDrawList* draw_list,ImRect outer,ImRect inner,ImU32 col,float rounding) -{ - return ImGui::RenderRectFilledWithHole(draw_list,outer,inner,col,rounding); -} -CIMGUI_API ImDrawFlags igCalcRoundingFlagsForRectInRect(const ImRect r_in,const ImRect r_outer,float threshold) -{ - return ImGui::CalcRoundingFlagsForRectInRect(r_in,r_outer,threshold); -} -CIMGUI_API void igTextEx(const char* text,const char* text_end,ImGuiTextFlags flags) -{ - return ImGui::TextEx(text,text_end,flags); -} -CIMGUI_API bool igButtonEx(const char* label,const ImVec2 size_arg,ImGuiButtonFlags flags) -{ - return ImGui::ButtonEx(label,size_arg,flags); -} -CIMGUI_API bool igCloseButton(ImGuiID id,const ImVec2 pos) -{ - return ImGui::CloseButton(id,pos); -} -CIMGUI_API bool igCollapseButton(ImGuiID id,const ImVec2 pos,ImGuiDockNode* dock_node) -{ - return ImGui::CollapseButton(id,pos,dock_node); -} -CIMGUI_API bool igArrowButtonEx(const char* str_id,ImGuiDir dir,ImVec2 size_arg,ImGuiButtonFlags flags) -{ - return ImGui::ArrowButtonEx(str_id,dir,size_arg,flags); -} -CIMGUI_API void igScrollbar(ImGuiAxis axis) -{ - return ImGui::Scrollbar(axis); -} -CIMGUI_API bool igScrollbarEx(const ImRect bb,ImGuiID id,ImGuiAxis axis,ImS64* p_scroll_v,ImS64 avail_v,ImS64 contents_v,ImDrawFlags flags) -{ - return ImGui::ScrollbarEx(bb,id,axis,p_scroll_v,avail_v,contents_v,flags); -} -CIMGUI_API bool igImageButtonEx(ImGuiID id,ImTextureID texture_id,const ImVec2 size,const ImVec2 uv0,const ImVec2 uv1,const ImVec2 padding,const ImVec4 bg_col,const ImVec4 tint_col) -{ - return ImGui::ImageButtonEx(id,texture_id,size,uv0,uv1,padding,bg_col,tint_col); -} -CIMGUI_API void igGetWindowScrollbarRect(ImRect *pOut,ImGuiWindow* window,ImGuiAxis axis) -{ - *pOut = ImGui::GetWindowScrollbarRect(window,axis); -} -CIMGUI_API ImGuiID igGetWindowScrollbarID(ImGuiWindow* window,ImGuiAxis axis) -{ - return ImGui::GetWindowScrollbarID(window,axis); -} -CIMGUI_API ImGuiID igGetWindowResizeCornerID(ImGuiWindow* window,int n) -{ - return ImGui::GetWindowResizeCornerID(window,n); -} -CIMGUI_API ImGuiID igGetWindowResizeBorderID(ImGuiWindow* window,ImGuiDir dir) -{ - return ImGui::GetWindowResizeBorderID(window,dir); -} -CIMGUI_API void igSeparatorEx(ImGuiSeparatorFlags flags) -{ - return ImGui::SeparatorEx(flags); -} -CIMGUI_API bool igCheckboxFlags_S64Ptr(const char* label,ImS64* flags,ImS64 flags_value) -{ - return ImGui::CheckboxFlags(label,flags,flags_value); -} -CIMGUI_API bool igCheckboxFlags_U64Ptr(const char* label,ImU64* flags,ImU64 flags_value) -{ - return ImGui::CheckboxFlags(label,flags,flags_value); -} -CIMGUI_API bool igButtonBehavior(const ImRect bb,ImGuiID id,bool* out_hovered,bool* out_held,ImGuiButtonFlags flags) -{ - return ImGui::ButtonBehavior(bb,id,out_hovered,out_held,flags); -} -CIMGUI_API bool igDragBehavior(ImGuiID id,ImGuiDataType data_type,void* p_v,float v_speed,const void* p_min,const void* p_max,const char* format,ImGuiSliderFlags flags) -{ - return ImGui::DragBehavior(id,data_type,p_v,v_speed,p_min,p_max,format,flags); -} -CIMGUI_API bool igSliderBehavior(const ImRect bb,ImGuiID id,ImGuiDataType data_type,void* p_v,const void* p_min,const void* p_max,const char* format,ImGuiSliderFlags flags,ImRect* out_grab_bb) -{ - return ImGui::SliderBehavior(bb,id,data_type,p_v,p_min,p_max,format,flags,out_grab_bb); -} -CIMGUI_API bool igSplitterBehavior(const ImRect bb,ImGuiID id,ImGuiAxis axis,float* size1,float* size2,float min_size1,float min_size2,float hover_extend,float hover_visibility_delay,ImU32 bg_col) -{ - return ImGui::SplitterBehavior(bb,id,axis,size1,size2,min_size1,min_size2,hover_extend,hover_visibility_delay,bg_col); -} -CIMGUI_API bool igTreeNodeBehavior(ImGuiID id,ImGuiTreeNodeFlags flags,const char* label,const char* label_end) -{ - return ImGui::TreeNodeBehavior(id,flags,label,label_end); -} -CIMGUI_API bool igTreeNodeBehaviorIsOpen(ImGuiID id,ImGuiTreeNodeFlags flags) -{ - return ImGui::TreeNodeBehaviorIsOpen(id,flags); -} -CIMGUI_API void igTreePushOverrideID(ImGuiID id) -{ - return ImGui::TreePushOverrideID(id); -} -CIMGUI_API const ImGuiDataTypeInfo* igDataTypeGetInfo(ImGuiDataType data_type) -{ - return ImGui::DataTypeGetInfo(data_type); -} -CIMGUI_API int igDataTypeFormatString(char* buf,int buf_size,ImGuiDataType data_type,const void* p_data,const char* format) -{ - return ImGui::DataTypeFormatString(buf,buf_size,data_type,p_data,format); -} -CIMGUI_API void igDataTypeApplyOp(ImGuiDataType data_type,int op,void* output,const void* arg_1,const void* arg_2) -{ - return ImGui::DataTypeApplyOp(data_type,op,output,arg_1,arg_2); -} -CIMGUI_API bool igDataTypeApplyOpFromText(const char* buf,const char* initial_value_buf,ImGuiDataType data_type,void* p_data,const char* format) -{ - return ImGui::DataTypeApplyOpFromText(buf,initial_value_buf,data_type,p_data,format); -} -CIMGUI_API int igDataTypeCompare(ImGuiDataType data_type,const void* arg_1,const void* arg_2) -{ - return ImGui::DataTypeCompare(data_type,arg_1,arg_2); -} -CIMGUI_API bool igDataTypeClamp(ImGuiDataType data_type,void* p_data,const void* p_min,const void* p_max) -{ - return ImGui::DataTypeClamp(data_type,p_data,p_min,p_max); -} -CIMGUI_API bool igInputTextEx(const char* label,const char* hint,char* buf,int buf_size,const ImVec2 size_arg,ImGuiInputTextFlags flags,ImGuiInputTextCallback callback,void* user_data) -{ - return ImGui::InputTextEx(label,hint,buf,buf_size,size_arg,flags,callback,user_data); -} -CIMGUI_API bool igTempInputText(const ImRect bb,ImGuiID id,const char* label,char* buf,int buf_size,ImGuiInputTextFlags flags) -{ - return ImGui::TempInputText(bb,id,label,buf,buf_size,flags); -} -CIMGUI_API bool igTempInputScalar(const ImRect bb,ImGuiID id,const char* label,ImGuiDataType data_type,void* p_data,const char* format,const void* p_clamp_min,const void* p_clamp_max) -{ - return ImGui::TempInputScalar(bb,id,label,data_type,p_data,format,p_clamp_min,p_clamp_max); -} -CIMGUI_API bool igTempInputIsActive(ImGuiID id) -{ - return ImGui::TempInputIsActive(id); -} -CIMGUI_API ImGuiInputTextState* igGetInputTextState(ImGuiID id) -{ - return ImGui::GetInputTextState(id); -} -CIMGUI_API void igColorTooltip(const char* text,const float* col,ImGuiColorEditFlags flags) -{ - return ImGui::ColorTooltip(text,col,flags); -} -CIMGUI_API void igColorEditOptionsPopup(const float* col,ImGuiColorEditFlags flags) -{ - return ImGui::ColorEditOptionsPopup(col,flags); -} -CIMGUI_API void igColorPickerOptionsPopup(const float* ref_col,ImGuiColorEditFlags flags) -{ - return ImGui::ColorPickerOptionsPopup(ref_col,flags); -} -CIMGUI_API int igPlotEx(ImGuiPlotType plot_type,const char* label,float(*values_getter)(void* data,int idx),void* data,int values_count,int values_offset,const char* overlay_text,float scale_min,float scale_max,ImVec2 frame_size) -{ - return ImGui::PlotEx(plot_type,label,values_getter,data,values_count,values_offset,overlay_text,scale_min,scale_max,frame_size); -} -CIMGUI_API void igShadeVertsLinearColorGradientKeepAlpha(ImDrawList* draw_list,int vert_start_idx,int vert_end_idx,ImVec2 gradient_p0,ImVec2 gradient_p1,ImU32 col0,ImU32 col1) -{ - return ImGui::ShadeVertsLinearColorGradientKeepAlpha(draw_list,vert_start_idx,vert_end_idx,gradient_p0,gradient_p1,col0,col1); -} -CIMGUI_API void igShadeVertsLinearUV(ImDrawList* draw_list,int vert_start_idx,int vert_end_idx,const ImVec2 a,const ImVec2 b,const ImVec2 uv_a,const ImVec2 uv_b,bool clamp) -{ - return ImGui::ShadeVertsLinearUV(draw_list,vert_start_idx,vert_end_idx,a,b,uv_a,uv_b,clamp); -} -CIMGUI_API void igGcCompactTransientMiscBuffers() -{ - return ImGui::GcCompactTransientMiscBuffers(); -} -CIMGUI_API void igGcCompactTransientWindowBuffers(ImGuiWindow* window) -{ - return ImGui::GcCompactTransientWindowBuffers(window); -} -CIMGUI_API void igGcAwakeTransientWindowBuffers(ImGuiWindow* window) -{ - return ImGui::GcAwakeTransientWindowBuffers(window); -} -CIMGUI_API void igErrorCheckEndFrameRecover(ImGuiErrorLogCallback log_callback,void* user_data) -{ - return ImGui::ErrorCheckEndFrameRecover(log_callback,user_data); -} -CIMGUI_API void igErrorCheckEndWindowRecover(ImGuiErrorLogCallback log_callback,void* user_data) -{ - return ImGui::ErrorCheckEndWindowRecover(log_callback,user_data); -} -CIMGUI_API void igDebugDrawItemRect(ImU32 col) -{ - return ImGui::DebugDrawItemRect(col); -} -CIMGUI_API void igDebugStartItemPicker() -{ - return ImGui::DebugStartItemPicker(); -} -CIMGUI_API void igShowFontAtlas(ImFontAtlas* atlas) -{ - return ImGui::ShowFontAtlas(atlas); -} -CIMGUI_API void igDebugHookIdInfo(ImGuiID id,ImGuiDataType data_type,const void* data_id,const void* data_id_end) -{ - return ImGui::DebugHookIdInfo(id,data_type,data_id,data_id_end); -} -CIMGUI_API void igDebugNodeColumns(ImGuiOldColumns* columns) -{ - return ImGui::DebugNodeColumns(columns); -} -CIMGUI_API void igDebugNodeDockNode(ImGuiDockNode* node,const char* label) -{ - return ImGui::DebugNodeDockNode(node,label); -} -CIMGUI_API void igDebugNodeDrawList(ImGuiWindow* window,ImGuiViewportP* viewport,const ImDrawList* draw_list,const char* label) -{ - return ImGui::DebugNodeDrawList(window,viewport,draw_list,label); -} -CIMGUI_API void igDebugNodeDrawCmdShowMeshAndBoundingBox(ImDrawList* out_draw_list,const ImDrawList* draw_list,const ImDrawCmd* draw_cmd,bool show_mesh,bool show_aabb) -{ - return ImGui::DebugNodeDrawCmdShowMeshAndBoundingBox(out_draw_list,draw_list,draw_cmd,show_mesh,show_aabb); -} -CIMGUI_API void igDebugNodeFont(ImFont* font) -{ - return ImGui::DebugNodeFont(font); -} -CIMGUI_API void igDebugNodeStorage(ImGuiStorage* storage,const char* label) -{ - return ImGui::DebugNodeStorage(storage,label); -} -CIMGUI_API void igDebugNodeTabBar(ImGuiTabBar* tab_bar,const char* label) -{ - return ImGui::DebugNodeTabBar(tab_bar,label); -} -CIMGUI_API void igDebugNodeTable(ImGuiTable* table) -{ - return ImGui::DebugNodeTable(table); -} -CIMGUI_API void igDebugNodeTableSettings(ImGuiTableSettings* settings) -{ - return ImGui::DebugNodeTableSettings(settings); -} -CIMGUI_API void igDebugNodeWindow(ImGuiWindow* window,const char* label) -{ - return ImGui::DebugNodeWindow(window,label); -} -CIMGUI_API void igDebugNodeWindowSettings(ImGuiWindowSettings* settings) -{ - return ImGui::DebugNodeWindowSettings(settings); -} -CIMGUI_API void igDebugNodeWindowsList(ImVector_ImGuiWindowPtr* windows,const char* label) -{ - return ImGui::DebugNodeWindowsList(windows,label); -} -CIMGUI_API void igDebugNodeWindowsListByBeginStackParent(ImGuiWindow** windows,int windows_size,ImGuiWindow* parent_in_begin_stack) -{ - return ImGui::DebugNodeWindowsListByBeginStackParent(windows,windows_size,parent_in_begin_stack); -} -CIMGUI_API void igDebugNodeViewport(ImGuiViewportP* viewport) -{ - return ImGui::DebugNodeViewport(viewport); -} -CIMGUI_API void igDebugRenderViewportThumbnail(ImDrawList* draw_list,ImGuiViewportP* viewport,const ImRect bb) -{ - return ImGui::DebugRenderViewportThumbnail(draw_list,viewport,bb); -} -CIMGUI_API const ImFontBuilderIO* igImFontAtlasGetBuilderForStbTruetype() -{ - return ImFontAtlasGetBuilderForStbTruetype(); -} -CIMGUI_API void igImFontAtlasBuildInit(ImFontAtlas* atlas) -{ - return ImFontAtlasBuildInit(atlas); -} -CIMGUI_API void igImFontAtlasBuildSetupFont(ImFontAtlas* atlas,ImFont* font,ImFontConfig* font_config,float ascent,float descent) -{ - return ImFontAtlasBuildSetupFont(atlas,font,font_config,ascent,descent); -} -CIMGUI_API void igImFontAtlasBuildPackCustomRects(ImFontAtlas* atlas,void* stbrp_context_opaque) -{ - return ImFontAtlasBuildPackCustomRects(atlas,stbrp_context_opaque); -} -CIMGUI_API void igImFontAtlasBuildFinish(ImFontAtlas* atlas) -{ - return ImFontAtlasBuildFinish(atlas); -} -CIMGUI_API void igImFontAtlasBuildRender8bppRectFromString(ImFontAtlas* atlas,int x,int y,int w,int h,const char* in_str,char in_marker_char,unsigned char in_marker_pixel_value) -{ - return ImFontAtlasBuildRender8bppRectFromString(atlas,x,y,w,h,in_str,in_marker_char,in_marker_pixel_value); -} -CIMGUI_API void igImFontAtlasBuildRender32bppRectFromString(ImFontAtlas* atlas,int x,int y,int w,int h,const char* in_str,char in_marker_char,unsigned int in_marker_pixel_value) -{ - return ImFontAtlasBuildRender32bppRectFromString(atlas,x,y,w,h,in_str,in_marker_char,in_marker_pixel_value); -} -CIMGUI_API void igImFontAtlasBuildMultiplyCalcLookupTable(unsigned char out_table[256],float in_multiply_factor) -{ - return ImFontAtlasBuildMultiplyCalcLookupTable(out_table,in_multiply_factor); -} -CIMGUI_API void igImFontAtlasBuildMultiplyRectAlpha8(const unsigned char table[256],unsigned char* pixels,int x,int y,int w,int h,int stride) -{ - return ImFontAtlasBuildMultiplyRectAlpha8(table,pixels,x,y,w,h,stride); + return ImGui::GetKeyIndex(key); } diff --git a/lib/external/imgui/source/imgui.cpp b/lib/external/imgui/source/imgui.cpp index 785c584f6..012421720 100644 --- a/lib/external/imgui/source/imgui.cpp +++ b/lib/external/imgui/source/imgui.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.86 +// dear imgui, v1.89 WIP // (main code and documentation) // Help: @@ -11,7 +11,7 @@ // - FAQ http://dearimgui.org/faq // - Homepage & latest https://github.com/ocornut/imgui // - Releases & changelog https://github.com/ocornut/imgui/releases -// - Gallery https://github.com/ocornut/imgui/issues/4451 (please post your screenshots/video there!) +// - Gallery https://github.com/ocornut/imgui/issues/5243 (please post your screenshots/video there!) // - Wiki https://github.com/ocornut/imgui/wiki (lots of good stuff there) // - Glossary https://github.com/ocornut/imgui/wiki/Glossary // - Issues & support https://github.com/ocornut/imgui/issues @@ -70,6 +70,7 @@ CODE // [SECTION] STYLING // [SECTION] RENDER HELPERS // [SECTION] MAIN CODE (most of the code! lots of stuff, needs tidying up!) +// [SECTION] INPUTS // [SECTION] ERROR CHECKING // [SECTION] LAYOUT // [SECTION] SCROLLING @@ -83,6 +84,7 @@ CODE // [SECTION] DOCKING // [SECTION] PLATFORM DEPENDENT HELPERS // [SECTION] METRICS/DEBUGGER WINDOW +// [SECTION] DEBUG LOG WINDOW // [SECTION] OTHER DEBUG TOOLS (ITEM PICKER, STACK TOOL) */ @@ -101,6 +103,7 @@ CODE - Easy to hack and improve. - Minimize setup and maintenance. - Minimize state storage on user side. + - Minimize state synchronization. - Portable, minimize dependencies, run on target (consoles, phones, etc.). - Efficient runtime and memory consumption. @@ -128,10 +131,9 @@ CODE - CTRL+X,CTRL+C,CTRL+V to use OS clipboard/ - CTRL+Z,CTRL+Y to undo/redo. - ESCAPE to revert text to its original value. - - You can apply arithmetic operators +,*,/ on numerical values. Use +- to subtract (because - would set a negative value!) - Controls are automatically adjusted for OSX to match standard OSX text editing operations. - General Keyboard controls: enable with ImGuiConfigFlags_NavEnableKeyboard. - - General Gamepad controls: enable with ImGuiConfigFlags_NavEnableGamepad. See suggested mappings in imgui.h ImGuiNavInput_ + download PNG/PSD at http://dearimgui.org/controls_sheets + - General Gamepad controls: enable with ImGuiConfigFlags_NavEnableGamepad. Download controller mapping PNG/PSD at http://dearimgui.org/controls_sheets PROGRAMMER GUIDE @@ -255,9 +257,9 @@ CODE io.DeltaTime = 1.0f/60.0f; // set the time elapsed since the previous frame (in seconds) io.DisplaySize.x = 1920.0f; // set the current display width io.DisplaySize.y = 1280.0f; // set the current display height here - io.MousePos = my_mouse_pos; // set the mouse position - io.MouseDown[0] = my_mouse_buttons[0]; // set the mouse button states - io.MouseDown[1] = my_mouse_buttons[1]; + io.AddMousePosEvent(mouse_x, mouse_y); // update mouse position + io.AddMouseButtonEvent(0, mouse_b[0]); // update mouse button states + io.AddMouseButtonEvent(1, mouse_b[1]); // update mouse button states // Call NewFrame(), after this point you can use ImGui::* functions anytime // (So you want to try calling NewFrame() as early as you can in your main loop to be able to use Dear ImGui everywhere) @@ -292,9 +294,11 @@ CODE void void MyImGuiRenderFunction(ImDrawData* draw_data) { // TODO: Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled + // TODO: Setup texture sampling state: sample with bilinear filtering (NOT point/nearest filtering). Use 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines;' to allow point/nearest filtering. // TODO: Setup viewport covering draw_data->DisplayPos to draw_data->DisplayPos + draw_data->DisplaySize // TODO: Setup orthographic projection matrix cover draw_data->DisplayPos to draw_data->DisplayPos + draw_data->DisplaySize // TODO: Setup shader: vertex { float2 pos, float2 uv, u32 color }, fragment shader sample color from 1 texture, multiply by vertex color. + ImVec2 clip_off = draw_data->DisplayPos; for (int n = 0; n < draw_data->CmdListsCount; n++) { const ImDrawList* cmd_list = draw_data->CmdLists[n]; @@ -309,9 +313,11 @@ CODE } else { - // The texture for the draw call is specified by pcmd->GetTexID(). - // The vast majority of draw calls will use the Dear ImGui texture atlas, which value you have set yourself during initialization. - MyEngineBindTexture((MyTexture*)pcmd->GetTexID()); + // Project scissor/clipping rectangles into framebuffer space + ImVec2 clip_min(pcmd->ClipRect.x - clip_off.x, pcmd->ClipRect.y - clip_off.y); + ImVec2 clip_max(pcmd->ClipRect.z - clip_off.x, pcmd->ClipRect.w - clip_off.y); + if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y) + continue; // We are using scissoring to clip some objects. All low-level graphics API should support it. // - If your engine doesn't support scissoring yet, you may ignore this at first. You will get some small glitches @@ -322,14 +328,16 @@ CODE // - In the interest of supporting multi-viewport applications (see 'docking' branch on github), // always subtract draw_data->DisplayPos from clipping bounds to convert them to your viewport space. // - Note that pcmd->ClipRect contains Min+Max bounds. Some graphics API may use Min+Max, other may use Min+Size (size being Max-Min) - ImVec2 pos = draw_data->DisplayPos; - MyEngineScissor((int)(pcmd->ClipRect.x - pos.x), (int)(pcmd->ClipRect.y - pos.y), (int)(pcmd->ClipRect.z - pos.x), (int)(pcmd->ClipRect.w - pos.y)); + MyEngineSetScissor(clip_min.x, clip_min.y, clip_max.x, clip_max.y); + + // The texture for the draw call is specified by pcmd->GetTexID(). + // The vast majority of draw calls will use the Dear ImGui texture atlas, which value you have set yourself during initialization. + MyEngineBindTexture((MyTexture*)pcmd->GetTexID()); // Render 'pcmd->ElemCount/3' indexed triangles. // By default the indices ImDrawIdx are 16-bit, you can change them to 32-bit in imconfig.h if your engine doesn't support 16-bit indices. - MyEngineDrawIndexedTriangles(pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer, vtx_buffer); + MyEngineDrawIndexedTriangles(pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer + pcmd->IdxOffset, vtx_buffer, pcmd->VtxOffset); } - idx_buffer += pcmd->ElemCount; } } } @@ -338,31 +346,27 @@ CODE USING GAMEPAD/KEYBOARD NAVIGATION CONTROLS ------------------------------------------ - The gamepad/keyboard navigation is fairly functional and keeps being improved. - - Gamepad support is particularly useful to use Dear ImGui on a console system (e.g. PS4, Switch, XB1) without a mouse! - - You can ask questions and report issues at https://github.com/ocornut/imgui/issues/787 + - Gamepad support is particularly useful to use Dear ImGui on a console system (e.g. PlayStation, Switch, Xbox) without a mouse! - The initial focus was to support game controllers, but keyboard is becoming increasingly and decently usable. - Keyboard: - - Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard to enable. - NewFrame() will automatically fill io.NavInputs[] based on your io.KeysDown[] + io.KeyMap[] arrays. - - When keyboard navigation is active (io.NavActive + ImGuiConfigFlags_NavEnableKeyboard), the io.WantCaptureKeyboard flag - will be set. For more advanced uses, you may want to read from: + - Application: Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard to enable. + - When keyboard navigation is active (io.NavActive + ImGuiConfigFlags_NavEnableKeyboard), + the io.WantCaptureKeyboard flag will be set. For more advanced uses, you may want to read from: - io.NavActive: true when a window is focused and it doesn't have the ImGuiWindowFlags_NoNavInputs flag set. - io.NavVisible: true when the navigation cursor is visible (and usually goes false when mouse is used). - or query focus information with e.g. IsWindowFocused(ImGuiFocusedFlags_AnyWindow), IsItemFocused() etc. functions. Please reach out if you think the game vs navigation input sharing could be improved. - Gamepad: - - Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad to enable. - - Backend: Set io.BackendFlags |= ImGuiBackendFlags_HasGamepad + fill the io.NavInputs[] fields before calling NewFrame(). - Note that io.NavInputs[] is cleared by EndFrame(). - - See 'enum ImGuiNavInput_' in imgui.h for a description of inputs. For each entry of io.NavInputs[], set the following values: - 0.0f= not held. 1.0f= fully held. Pass intermediate 0.0f..1.0f values for analog triggers/sticks. - - We use a simple >0.0f test for activation testing, and won't attempt to test for a dead-zone. - Your code will probably need to transform your raw inputs (such as e.g. remapping your 0.2..0.9 raw input range to 0.0..1.0 imgui range, etc.). + - Application: Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad to enable. + - Backend: Set io.BackendFlags |= ImGuiBackendFlags_HasGamepad + call io.AddKeyEvent/AddKeyAnalogEvent() with ImGuiKey_Gamepad_XXX keys. + For analog values (0.0f to 1.0f), backend is responsible to handling a dead-zone and rescaling inputs accordingly. + Backend code will probably need to transform your raw inputs (such as e.g. remapping your 0.2..0.9 raw input range to 0.0..1.0 imgui range, etc.). + - BEFORE 1.87, BACKENDS USED TO WRITE TO io.NavInputs[]. This is now obsolete. Please call io functions instead! - You can download PNG/PSD files depicting the gamepad controls for common controllers at: http://dearimgui.org/controls_sheets - - If you need to share inputs between your game and the imgui parts, the easiest approach is to go all-or-nothing, with a buttons combo - to toggle the target. Please reach out if you think the game vs navigation input sharing could be improved. + - If you need to share inputs between your game and the Dear ImGui interface, the easiest approach is to go all-or-nothing, + with a buttons combo to toggle the target. Please reach out if you think the game vs navigation input sharing could be improved. - Mouse: - - PS4 users: Consider emulating a mouse cursor with DualShock4 touch pad or a spare analog stick as a mouse-emulation fallback. + - PS4/PS5 users: Consider emulating a mouse cursor with DualShock4 touch pad or a spare analog stick as a mouse-emulation fallback. - Consoles/Tablet/Phone users: Consider using a Synergy 1.x server (on your PC) + uSynergy.c (on your console/tablet/phone app) to share your PC mouse/keyboard. - On a TV/console system where readability may be lower or mouse inputs may be awkward, you may want to set the ImGuiConfigFlags_NavEnableSetMousePos flag. Enabling ImGuiConfigFlags_NavEnableSetMousePos + ImGuiBackendFlags_HasSetMousePos instructs dear imgui to move your mouse cursor along with navigation movements. @@ -382,14 +386,46 @@ CODE You can read releases logs https://github.com/ocornut/imgui/releases for more details. (Docking/Viewport Branch) - - 2021/XX/XX (1.XX) - when multi-viewports are enabled, all positions will be in your natural OS coordinates space. It means that: + - 2022/XX/XX (1.XX) - when multi-viewports are enabled, all positions will be in your natural OS coordinates space. It means that: - reference to hard-coded positions such as in SetNextWindowPos(ImVec2(0,0)) are probably not what you want anymore. you may use GetMainViewport()->Pos to offset hard-coded positions, e.g. SetNextWindowPos(GetMainViewport()->Pos) - likewise io.MousePos and GetMousePos() will use OS coordinates. If you query mouse positions to interact with non-imgui coordinates you will need to offset them, e.g. subtract GetWindowViewport()->Pos. - - 2021/XX/XX (1.XX) - Moved IME support functions from io.ImeSetInputScreenPosFn, io.ImeWindowHandle to the PlatformIO api. - + - 2022/07/08 (1.88) - inputs: removed io.NavInputs[] and ImGuiNavInput enum (following 1.87 changes). + - Official backends from 1.87+ -> no issue. + - Official backends from 1.60 to 1.86 -> will build and convert gamepad inputs, unless IMGUI_DISABLE_OBSOLETE_KEYIO is defined. Need updating! + - Custom backends not writing to io.NavInputs[] -> no issue. + - Custom backends writing to io.NavInputs[] -> will build and convert gamepad inputs, unless IMGUI_DISABLE_OBSOLETE_KEYIO is defined. Need fixing! + - TL;DR: Backends should call io.AddKeyEvent()/io.AddKeyAnalogEvent() with ImGuiKey_GamepadXXX values instead of filling io.NavInput[]. + - 2022/06/15 (1.88) - renamed IMGUI_DISABLE_METRICS_WINDOW to IMGUI_DISABLE_DEBUG_TOOLS for correctness. kept support for old define (will obsolete). + - 2022/05/03 (1.88) - backends: osx: removed ImGui_ImplOSX_HandleEvent() from backend API in favor of backend automatically handling event capture. All ImGui_ImplOSX_HandleEvent() calls should be removed as they are now unnecessary. + - 2022/04/05 (1.88) - inputs: renamed ImGuiKeyModFlags to ImGuiModFlags. Kept inline redirection enums (will obsolete). This was never used in public API functions but technically present in imgui.h and ImGuiIO. + - 2022/01/20 (1.87) - inputs: reworded gamepad IO. + - Backend writing to io.NavInputs[] -> backend should call io.AddKeyEvent()/io.AddKeyAnalogEvent() with ImGuiKey_GamepadXXX values. + - 2022/01/19 (1.87) - sliders, drags: removed support for legacy arithmetic operators (+,+-,*,/) when inputing text. This doesn't break any api/code but a feature that used to be accessible by end-users (which seemingly no one used). + - 2022/01/17 (1.87) - inputs: reworked mouse IO. + - Backend writing to io.MousePos -> backend should call io.AddMousePosEvent() + - Backend writing to io.MouseDown[] -> backend should call io.AddMouseButtonEvent() + - Backend writing to io.MouseWheel -> backend should call io.AddMouseWheelEvent() + - Backend writing to io.MouseHoveredViewport -> backend should call io.AddMouseViewportEvent() [Docking branch w/ multi-viewports only] + note: for all calls to IO new functions, the Dear ImGui context should be bound/current. + read https://github.com/ocornut/imgui/issues/4921 for details. + - 2022/01/10 (1.87) - inputs: reworked keyboard IO. Removed io.KeyMap[], io.KeysDown[] in favor of calling io.AddKeyEvent(). Removed GetKeyIndex(), now unecessary. All IsKeyXXX() functions now take ImGuiKey values. All features are still functional until IMGUI_DISABLE_OBSOLETE_KEYIO is defined. Read Changelog and Release Notes for details. + - IsKeyPressed(MY_NATIVE_KEY_XXX) -> use IsKeyPressed(ImGuiKey_XXX) + - IsKeyPressed(GetKeyIndex(ImGuiKey_XXX)) -> use IsKeyPressed(ImGuiKey_XXX) + - Backend writing to io.KeyMap[],io.KeysDown[] -> backend should call io.AddKeyEvent() (+ call io.SetKeyEventNativeData() if you want legacy user code to stil function with legacy key codes). + - Backend writing to io.KeyCtrl, io.KeyShift.. -> backend should call io.AddKeyEvent() with ImGuiKey_ModXXX values. *IF YOU PULLED CODE BETWEEN 2021/01/10 and 2021/01/27: We used to have a io.AddKeyModsEvent() function which was now replaced by io.AddKeyEvent() with ImGuiKey_ModXXX values.* + - one case won't work with backward compatibility: if your custom backend used ImGuiKey as mock native indices (e.g. "io.KeyMap[ImGuiKey_A] = ImGuiKey_A") because those values are now larger than the legacy KeyDown[] array. Will assert. + - inputs: added ImGuiKey_ModCtrl/ImGuiKey_ModShift/ImGuiKey_ModAlt/ImGuiKey_ModSuper values to submit keyboard modifiers using io.AddKeyEvent(), instead of writing directly to io.KeyCtrl, io.KeyShift, io.KeyAlt, io.KeySuper. + - 2022/01/05 (1.87) - inputs: renamed ImGuiKey_KeyPadEnter to ImGuiKey_KeypadEnter to align with new symbols. Kept redirection enum. + - 2022/01/05 (1.87) - removed io.ImeSetInputScreenPosFn() in favor of more flexible io.SetPlatformImeDataFn(). Removed 'void* io.ImeWindowHandle' in favor of writing to 'void* ImGuiViewport::PlatformHandleRaw'. + - 2022/01/01 (1.87) - commented out redirecting functions/enums names that were marked obsolete in 1.69, 1.70, 1.71, 1.72 (March-July 2019) + - ImGui::SetNextTreeNodeOpen() -> use ImGui::SetNextItemOpen() + - ImGui::GetContentRegionAvailWidth() -> use ImGui::GetContentRegionAvail().x + - ImGui::TreeAdvanceToLabelPos() -> use ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetTreeNodeToLabelSpacing()); + - ImFontAtlas::CustomRect -> use ImFontAtlasCustomRect + - ImGuiColorEditFlags_RGB/HSV/HEX -> use ImGuiColorEditFlags_DisplayRGB/HSV/Hex - 2021/12/20 (1.86) - backends: removed obsolete Marmalade backend (imgui_impl_marmalade.cpp) + example. Find last supported version at https://github.com/ocornut/imgui/wiki/Bindings - 2021/11/04 (1.86) - removed CalcListClipping() function. Prefer using ImGuiListClipper which can return non-contiguous ranges. Please open an issue if you think you really need this function. - 2021/08/23 (1.85) - removed GetWindowContentRegionWidth() function. keep inline redirection helper. can use 'GetWindowContentRegionMax().x - GetWindowContentRegionMin().x' instead for generally 'GetContentRegionAvail().x' is more useful. @@ -921,6 +957,7 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext*, ImGuiSetti // Platform Dependents default implementation for IO functions static const char* GetClipboardTextFn_DefaultImpl(void* user_data); static void SetClipboardTextFn_DefaultImpl(void* user_data, const char* text); +static void SetPlatformImeDataFn_DefaultImpl(ImGuiViewport* viewport, ImGuiPlatformImeData* data); namespace ImGui { @@ -954,6 +991,7 @@ static void UpdateDebugToolStackQueries(); // Misc static void UpdateSettings(); +static void UpdateKeyboardInputs(); static void UpdateMouseInputs(); static void UpdateMouseWheel(); static bool UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4], const ImRect& visibility_rect); @@ -1052,7 +1090,7 @@ ImGuiStyle::ImGuiStyle() ColumnsMinSpacing = 6.0f; // Minimum horizontal spacing between two columns. Preferably > (FramePadding.x + 1). ScrollbarSize = 14.0f; // Width of the vertical scrollbar, Height of the horizontal scrollbar ScrollbarRounding = 9.0f; // Radius of grab corners rounding for scrollbar - GrabMinSize = 10.0f; // Minimum width/height of a grab box for slider/scrollbar + GrabMinSize = 12.0f; // Minimum width/height of a grab box for slider/scrollbar GrabRounding = 0.0f; // Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs. LogSliderDeadzone = 4.0f; // The size in pixels of the dead-zone around zero on logarithmic sliders that cross zero. TabRounding = 4.0f; // Radius of upper corners of a tab. Set to 0.0f to have rectangular tabs. @@ -1065,7 +1103,7 @@ ImGuiStyle::ImGuiStyle() DisplaySafeAreaPadding = ImVec2(3,3); // If you cannot see the edge of your screen (e.g. on a TV) increase the safe area padding. Covers popups/tooltips as well regular windows. MouseCursorScale = 1.0f; // Scale software rendered mouse cursor (when io.MouseDrawCursor is enabled). May be removed later. AntiAliasedLines = true; // Enable anti-aliased lines/borders. Disable if you are really tight on CPU/GPU. - AntiAliasedLinesUseTex = true; // Enable anti-aliased lines/borders using textures where possible. Require backend to render with bilinear filtering. + AntiAliasedLinesUseTex = true; // Enable anti-aliased lines/borders using textures where possible. Require backend to render with bilinear filtering (NOT point/nearest filtering). AntiAliasedFill = true; // Enable anti-aliased filled shapes (rounded rectangles, circles, etc.). CurveTessellationTol = 1.25f; // Tessellation tolerance when using PathBezierCurveTo() without a specific number of segments. Decrease for highly tessellated curves (higher quality, more polygons), increase to reduce quality. CircleTessellationMaxError = 0.30f; // Maximum error (in pixels) allowed when using AddCircle()/AddCircleFilled() or drawing rounded corner rectangles with no explicit segment count specified. Decrease for higher quality but more geometry. @@ -1107,7 +1145,7 @@ ImGuiIO::ImGuiIO() { // Most fields are initialized with zero memset(this, 0, sizeof(*this)); - IM_ASSERT(IM_ARRAYSIZE(ImGuiIO::MouseDown) == ImGuiMouseButton_COUNT && IM_ARRAYSIZE(ImGuiIO::MouseClicked) == ImGuiMouseButton_COUNT); // Our pre-C++11 IM_STATIC_ASSERT() macros triggers warning on modern compilers so we don't use it here. + IM_STATIC_ASSERT(IM_ARRAYSIZE(ImGuiIO::MouseDown) == ImGuiMouseButton_COUNT && IM_ARRAYSIZE(ImGuiIO::MouseClicked) == ImGuiMouseButton_COUNT); // Settings ConfigFlags = ImGuiConfigFlags_None; @@ -1119,8 +1157,10 @@ ImGuiIO::ImGuiIO() LogFilename = "imgui_log.txt"; MouseDoubleClickTime = 0.30f; MouseDoubleClickMaxDist = 6.0f; +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO for (int i = 0; i < ImGuiKey_COUNT; i++) KeyMap[i] = -1; +#endif KeyRepeatDelay = 0.275f; KeyRepeatRate = 0.050f; UserData = NULL; @@ -1150,6 +1190,7 @@ ImGuiIO::ImGuiIO() #else ConfigMacOSXBehaviors = false; #endif + ConfigInputTrickleEventQueue = true; ConfigInputTextCursorBlink = true; ConfigWindowsResizeFromEdges = true; ConfigWindowsMoveFromTitleBarOnly = false; @@ -1161,36 +1202,48 @@ ImGuiIO::ImGuiIO() GetClipboardTextFn = GetClipboardTextFn_DefaultImpl; // Platform dependent default implementations SetClipboardTextFn = SetClipboardTextFn_DefaultImpl; ClipboardUserData = NULL; + SetPlatformImeDataFn = SetPlatformImeDataFn_DefaultImpl; // Input (NB: we already have memset zero the entire structure!) MousePos = ImVec2(-FLT_MAX, -FLT_MAX); MousePosPrev = ImVec2(-FLT_MAX, -FLT_MAX); MouseDragThreshold = 6.0f; for (int i = 0; i < IM_ARRAYSIZE(MouseDownDuration); i++) MouseDownDuration[i] = MouseDownDurationPrev[i] = -1.0f; - for (int i = 0; i < IM_ARRAYSIZE(KeysDownDuration); i++) KeysDownDuration[i] = KeysDownDurationPrev[i] = -1.0f; - for (int i = 0; i < IM_ARRAYSIZE(NavInputsDownDuration); i++) NavInputsDownDuration[i] = -1.0f; + for (int i = 0; i < IM_ARRAYSIZE(KeysData); i++) { KeysData[i].DownDuration = KeysData[i].DownDurationPrev = -1.0f; } + AppAcceptingEvents = true; + BackendUsingLegacyKeyArrays = (ImS8)-1; + BackendUsingLegacyNavInputArray = true; // assume using legacy array until proven wrong } // Pass in translated ASCII characters for text input. // - with glfw you can get those from the callback set in glfwSetCharCallback() // - on Windows you can get those using ToAscii+keyboard state, or via the WM_CHAR message +// FIXME: Should in theory be called "AddCharacterEvent()" to be consistent with new API void ImGuiIO::AddInputCharacter(unsigned int c) { - if (c != 0) - InputQueueCharacters.push_back(c <= IM_UNICODE_CODEPOINT_MAX ? (ImWchar)c : IM_UNICODE_CODEPOINT_INVALID); + ImGuiContext& g = *GImGui; + IM_ASSERT(&g.IO == this && "Can only add events to current context."); + if (c == 0 || !AppAcceptingEvents) + return; + + ImGuiInputEvent e; + e.Type = ImGuiInputEventType_Text; + e.Source = ImGuiInputSource_Keyboard; + e.Text.Char = c; + g.InputEventsQueue.push_back(e); } // UTF16 strings use surrogate pairs to encode codepoints >= 0x10000, so // we should save the high surrogate. void ImGuiIO::AddInputCharacterUTF16(ImWchar16 c) { - if (c == 0 && InputQueueSurrogate == 0) + if ((c == 0 && InputQueueSurrogate == 0) || !AppAcceptingEvents) return; if ((c & 0xFC00) == 0xD800) // High surrogate, must save { if (InputQueueSurrogate != 0) - InputQueueCharacters.push_back(IM_UNICODE_CODEPOINT_INVALID); + AddInputCharacter(IM_UNICODE_CODEPOINT_INVALID); InputQueueSurrogate = c; return; } @@ -1200,7 +1253,7 @@ void ImGuiIO::AddInputCharacterUTF16(ImWchar16 c) { if ((c & 0xFC00) != 0xDC00) // Invalid low surrogate { - InputQueueCharacters.push_back(IM_UNICODE_CODEPOINT_INVALID); + AddInputCharacter(IM_UNICODE_CODEPOINT_INVALID); } else { @@ -1213,17 +1266,19 @@ void ImGuiIO::AddInputCharacterUTF16(ImWchar16 c) InputQueueSurrogate = 0; } - InputQueueCharacters.push_back(cp); + AddInputCharacter((unsigned)cp); } void ImGuiIO::AddInputCharactersUTF8(const char* utf8_chars) { + if (!AppAcceptingEvents) + return; while (*utf8_chars != 0) { unsigned int c = 0; utf8_chars += ImTextCharFromUtf8(&c, utf8_chars, NULL); if (c != 0) - InputQueueCharacters.push_back((ImWchar)c); + AddInputCharacter(c); } } @@ -1234,20 +1289,174 @@ void ImGuiIO::ClearInputCharacters() void ImGuiIO::ClearInputKeys() { +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO memset(KeysDown, 0, sizeof(KeysDown)); - for (int n = 0; n < IM_ARRAYSIZE(KeysDownDuration); n++) - KeysDownDuration[n] = KeysDownDurationPrev[n] = -1.0f; +#endif + for (int n = 0; n < IM_ARRAYSIZE(KeysData); n++) + { + KeysData[n].Down = false; + KeysData[n].DownDuration = -1.0f; + KeysData[n].DownDurationPrev = -1.0f; + } KeyCtrl = KeyShift = KeyAlt = KeySuper = false; - KeyMods = KeyModsPrev = ImGuiKeyModFlags_None; - for (int n = 0; n < IM_ARRAYSIZE(NavInputsDownDuration); n++) - NavInputsDownDuration[n] = NavInputsDownDurationPrev[n] = -1.0f; + KeyMods = ImGuiModFlags_None; +} + +// Queue a new key down/up event. +// - ImGuiKey key: Translated key (as in, generally ImGuiKey_A matches the key end-user would use to emit an 'A' character) +// - bool down: Is the key down? use false to signify a key release. +// - float analog_value: 0.0f..1.0f +void ImGuiIO::AddKeyAnalogEvent(ImGuiKey key, bool down, float analog_value) +{ + //if (e->Down) { IMGUI_DEBUG_LOG_IO("AddKeyEvent() Key='%s' %d, NativeKeycode = %d, NativeScancode = %d\n", ImGui::GetKeyName(e->Key), e->Down, e->NativeKeycode, e->NativeScancode); } + if (key == ImGuiKey_None || !AppAcceptingEvents) + return; + ImGuiContext& g = *GImGui; + IM_ASSERT(&g.IO == this && "Can only add events to current context."); + IM_ASSERT(ImGui::IsNamedKey(key)); // Backend needs to pass a valid ImGuiKey_ constant. 0..511 values are legacy native key codes which are not accepted by this API. + IM_ASSERT(!ImGui::IsAliasKey(key)); // Backend cannot submit ImGuiKey_MouseXXX values they are automatically inferred from AddMouseXXX() events. + + // Verify that backend isn't mixing up using new io.AddKeyEvent() api and old io.KeysDown[] + io.KeyMap[] data. +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO + IM_ASSERT((BackendUsingLegacyKeyArrays == -1 || BackendUsingLegacyKeyArrays == 0) && "Backend needs to either only use io.AddKeyEvent(), either only fill legacy io.KeysDown[] + io.KeyMap[]. Not both!"); + if (BackendUsingLegacyKeyArrays == -1) + for (int n = ImGuiKey_NamedKey_BEGIN; n < ImGuiKey_NamedKey_END; n++) + IM_ASSERT(KeyMap[n] == -1 && "Backend needs to either only use io.AddKeyEvent(), either only fill legacy io.KeysDown[] + io.KeyMap[]. Not both!"); + BackendUsingLegacyKeyArrays = 0; +#endif + if (ImGui::IsGamepadKey(key)) + BackendUsingLegacyNavInputArray = false; + + // Partial filter of duplicates (not strictly needed, but makes data neater in particular for key mods and gamepad values which are most commonly spmamed) + ImGuiKeyData* key_data = ImGui::GetKeyData(key); + if (key_data->Down == down && key_data->AnalogValue == analog_value) + { + bool found = false; + for (int n = g.InputEventsQueue.Size - 1; n >= 0 && !found; n--) + if (g.InputEventsQueue[n].Type == ImGuiInputEventType_Key && g.InputEventsQueue[n].Key.Key == key) + found = true; + if (!found) + return; + } + + // Add event + ImGuiInputEvent e; + e.Type = ImGuiInputEventType_Key; + e.Source = ImGui::IsGamepadKey(key) ? ImGuiInputSource_Gamepad : ImGuiInputSource_Keyboard; + e.Key.Key = key; + e.Key.Down = down; + e.Key.AnalogValue = analog_value; + g.InputEventsQueue.push_back(e); +} + +void ImGuiIO::AddKeyEvent(ImGuiKey key, bool down) +{ + if (!AppAcceptingEvents) + return; + AddKeyAnalogEvent(key, down, down ? 1.0f : 0.0f); +} + +// [Optional] Call after AddKeyEvent(). +// Specify native keycode, scancode + Specify index for legacy <1.87 IsKeyXXX() functions with native indices. +// If you are writing a backend in 2022 or don't use IsKeyXXX() with native values that are not ImGuiKey values, you can avoid calling this. +void ImGuiIO::SetKeyEventNativeData(ImGuiKey key, int native_keycode, int native_scancode, int native_legacy_index) +{ + if (key == ImGuiKey_None) + return; + IM_ASSERT(ImGui::IsNamedKey(key)); // >= 512 + IM_ASSERT(native_legacy_index == -1 || ImGui::IsLegacyKey(native_legacy_index)); // >= 0 && <= 511 + IM_UNUSED(native_keycode); // Yet unused + IM_UNUSED(native_scancode); // Yet unused + + // Build native->imgui map so old user code can still call key functions with native 0..511 values. +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO + const int legacy_key = (native_legacy_index != -1) ? native_legacy_index : native_keycode; + if (!ImGui::IsLegacyKey(legacy_key)) + return; + KeyMap[legacy_key] = key; + KeyMap[key] = legacy_key; +#else + IM_UNUSED(key); + IM_UNUSED(native_legacy_index); +#endif +} + +// Set master flag for accepting key/mouse/text events (default to true). Useful if you have native dialog boxes that are interrupting your application loop/refresh, and you want to disable events being queued while your app is frozen. +void ImGuiIO::SetAppAcceptingEvents(bool accepting_events) +{ + AppAcceptingEvents = accepting_events; +} + +// Queue a mouse move event +void ImGuiIO::AddMousePosEvent(float x, float y) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(&g.IO == this && "Can only add events to current context."); + if (!AppAcceptingEvents) + return; + + ImGuiInputEvent e; + e.Type = ImGuiInputEventType_MousePos; + e.Source = ImGuiInputSource_Mouse; + e.MousePos.PosX = x; + e.MousePos.PosY = y; + g.InputEventsQueue.push_back(e); +} + +void ImGuiIO::AddMouseButtonEvent(int mouse_button, bool down) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(&g.IO == this && "Can only add events to current context."); + IM_ASSERT(mouse_button >= 0 && mouse_button < ImGuiMouseButton_COUNT); + if (!AppAcceptingEvents) + return; + + ImGuiInputEvent e; + e.Type = ImGuiInputEventType_MouseButton; + e.Source = ImGuiInputSource_Mouse; + e.MouseButton.Button = mouse_button; + e.MouseButton.Down = down; + g.InputEventsQueue.push_back(e); +} + +// Queue a mouse wheel event (most mouse/API will only have a Y component) +void ImGuiIO::AddMouseWheelEvent(float wheel_x, float wheel_y) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(&g.IO == this && "Can only add events to current context."); + if ((wheel_x == 0.0f && wheel_y == 0.0f) || !AppAcceptingEvents) + return; + + ImGuiInputEvent e; + e.Type = ImGuiInputEventType_MouseWheel; + e.Source = ImGuiInputSource_Mouse; + e.MouseWheel.WheelX = wheel_x; + e.MouseWheel.WheelY = wheel_y; + g.InputEventsQueue.push_back(e); +} + +void ImGuiIO::AddMouseViewportEvent(ImGuiID viewport_id) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(&g.IO == this && "Can only add events to current context."); + IM_ASSERT(g.IO.BackendFlags & ImGuiBackendFlags_HasMouseHoveredViewport); + + ImGuiInputEvent e; + e.Type = ImGuiInputEventType_MouseViewport; + e.Source = ImGuiInputSource_Mouse; + e.MouseViewport.HoveredViewportID = viewport_id; + g.InputEventsQueue.push_back(e); } void ImGuiIO::AddFocusEvent(bool focused) { - // We intentionally overwrite this and process in NewFrame(), in order to give a chance - // to multi-viewports backends to queue AddFocusEvent(false),AddFocusEvent(true) in same frame. - AppFocusLost = !focused; + ImGuiContext& g = *GImGui; + IM_ASSERT(&g.IO == this && "Can only add events to current context."); + + ImGuiInputEvent e; + e.Type = ImGuiInputEventType_Focus; + e.AppFocused.Focused = focused; + g.InputEventsQueue.push_back(e); } //----------------------------------------------------------------------------- @@ -1503,8 +1712,12 @@ const char* ImStrSkipBlank(const char* str) // designed using two-passes worst case, which probably could be improved using the stbsp_vsprintfcb() function.) #ifdef IMGUI_USE_STB_SPRINTF #define STB_SPRINTF_IMPLEMENTATION +#ifdef IMGUI_STB_SPRINTF_FILENAME +#include IMGUI_STB_SPRINTF_FILENAME +#else #include "stb_sprintf.h" #endif +#endif #if defined(_MSC_VER) && !defined(vsnprintf) #define vsnprintf _vsnprintf @@ -1544,6 +1757,25 @@ int ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args) } #endif // #ifdef IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS +void ImFormatStringToTempBuffer(const char** out_buf, const char** out_buf_end, const char* fmt, ...) +{ + ImGuiContext& g = *GImGui; + va_list args; + va_start(args, fmt); + int buf_len = ImFormatStringV(g.TempBuffer.Data, g.TempBuffer.Size, fmt, args); + *out_buf = g.TempBuffer.Data; + if (out_buf_end) { *out_buf_end = g.TempBuffer.Data + buf_len; } + va_end(args); +} + +void ImFormatStringToTempBufferV(const char** out_buf, const char** out_buf_end, const char* fmt, va_list args) +{ + ImGuiContext& g = *GImGui; + int buf_len = ImFormatStringV(g.TempBuffer.Data, g.TempBuffer.Size, fmt, args); + *out_buf = g.TempBuffer.Data; + if (out_buf_end) { *out_buf_end = g.TempBuffer.Data + buf_len; } +} + // CRC32 needs a 1KB lookup table (not cache friendly) // Although the code to generate the table is simple and shorter than the table itself, using a const table allows us to easily: // - avoid an unnecessary branch/memory tap, - keep the ImHashXXX functions usable by static constructors, - make it thread-safe. @@ -2105,18 +2337,15 @@ void ImGuiStorage::SetAllInt(int v) //----------------------------------------------------------------------------- // Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]" -ImGuiTextFilter::ImGuiTextFilter(const char* default_filter) +ImGuiTextFilter::ImGuiTextFilter(const char* default_filter) //-V1077 { + InputBuf[0] = 0; + CountGrep = 0; if (default_filter) { ImStrncpy(InputBuf, default_filter, IM_ARRAYSIZE(InputBuf)); Build(); } - else - { - InputBuf[0] = 0; - CountGrep = 0; - } } bool ImGuiTextFilter::Draw(const char* label, float width) @@ -2431,15 +2660,14 @@ void ImGuiListClipper::Begin(int items_count, float items_height) void ImGuiListClipper::End() { - // In theory here we should assert that we are already at the right position, but it seems saner to just seek at the end and not assert/crash the user. ImGuiContext& g = *GImGui; - if (ItemsCount >= 0 && ItemsCount < INT_MAX && DisplayStart >= 0) - ImGuiListClipper_SeekCursorForItem(this, ItemsCount); - ItemsCount = -1; - - // Restore temporary buffer and fix back pointers which may be invalidated when nesting if (ImGuiListClipperData* data = (ImGuiListClipperData*)TempData) { + // In theory here we should assert that we are already at the right position, but it seems saner to just seek at the end and not assert/crash the user. + if (ItemsCount >= 0 && ItemsCount < INT_MAX && DisplayStart >= 0) + ImGuiListClipper_SeekCursorForItem(this, ItemsCount); + + // Restore temporary buffer and fix back pointers which may be invalidated when nesting IM_ASSERT(data->ListClipper == this); data->StepNo = data->Ranges.Size; if (--g.ClipperTempDataStacked > 0) @@ -2449,6 +2677,7 @@ void ImGuiListClipper::End() } TempData = NULL; } + ItemsCount = -1; } void ImGuiListClipper::ForceDisplayRangeByIndices(int item_min, int item_max) @@ -2465,6 +2694,7 @@ bool ImGuiListClipper::Step() ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; ImGuiListClipperData* data = (ImGuiListClipperData*)TempData; + IM_ASSERT(data != NULL && "Called ImGuiListClipper::Step() too many times, or before ImGuiListClipper::Begin() ?"); ImGuiTable* table = g.CurrentTable; if (table && table->IsInsideRow) @@ -2581,8 +2811,8 @@ bool ImGuiListClipper::Step() // Advance the cursor to the end of the list and then returns 'false' to end the loop. if (ItemsCount < INT_MAX) ImGuiListClipper_SeekCursorForItem(this, ItemsCount); - ItemsCount = -1; + End(); return false; } @@ -3066,6 +3296,34 @@ void ImGui::RenderNavHighlight(const ImRect& bb, ImGuiID id, ImGuiNavHighlightFl } } +void ImGui::RenderMouseCursor(ImVec2 base_pos, float base_scale, ImGuiMouseCursor mouse_cursor, ImU32 col_fill, ImU32 col_border, ImU32 col_shadow) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(mouse_cursor > ImGuiMouseCursor_None && mouse_cursor < ImGuiMouseCursor_COUNT); + ImFontAtlas* font_atlas = g.DrawListSharedData.Font->ContainerAtlas; + for (int n = 0; n < g.Viewports.Size; n++) + { + // We scale cursor with current viewport/monitor, however Windows 10 for its own hardware cursor seems to be using a different scale factor. + ImVec2 offset, size, uv[4]; + if (!font_atlas->GetMouseCursorTexData(mouse_cursor, &offset, &size, &uv[0], &uv[2])) + continue; + ImGuiViewportP* viewport = g.Viewports[n]; + const ImVec2 pos = base_pos - offset; + const float scale = base_scale * viewport->DpiScale; + if (!viewport->GetMainRect().Overlaps(ImRect(pos, pos + ImVec2(size.x + 2, size.y + 2) * scale))) + continue; + ImDrawList* draw_list = GetForegroundDrawList(viewport); + ImTextureID tex_id = font_atlas->TexID; + draw_list->PushTextureID(tex_id); + draw_list->AddImage(tex_id, pos + ImVec2(1, 0) * scale, pos + (ImVec2(1, 0) + size) * scale, uv[2], uv[3], col_shadow); + draw_list->AddImage(tex_id, pos + ImVec2(2, 0) * scale, pos + (ImVec2(2, 0) + size) * scale, uv[2], uv[3], col_shadow); + draw_list->AddImage(tex_id, pos, pos + size * scale, uv[2], uv[3], col_border); + draw_list->AddImage(tex_id, pos, pos + size * scale, uv[0], uv[1], col_fill); + draw_list->PopTextureID(); + } +} + + //----------------------------------------------------------------------------- // [SECTION] MAIN CODE (most of the code! lots of stuff, needs tidying up!) //----------------------------------------------------------------------------- @@ -3081,6 +3339,7 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name) : DrawListInst ViewportAllowPlatformMonitorExtend = -1; ViewportPos = ImVec2(FLT_MAX, FLT_MAX); MoveId = GetID("#MOVE"); + TabId = GetID("#TAB"); ScrollTarget = ImVec2(FLT_MAX, FLT_MAX); ScrollTargetCenterRatio = ImVec2(0.5f, 0.5f); AutoFitFramesX = AutoFitFramesY = -1; @@ -3110,7 +3369,6 @@ ImGuiID ImGuiWindow::GetID(const char* str, const char* str_end) { ImGuiID seed = IDStack.back(); ImGuiID id = ImHashStr(str, str_end ? (str_end - str) : 0, seed); - ImGui::KeepAliveID(id); ImGuiContext& g = *GImGui; if (g.DebugHookIdInfo == id) ImGui::DebugHookIdInfo(id, ImGuiDataType_String, str, str_end); @@ -3121,7 +3379,6 @@ ImGuiID ImGuiWindow::GetID(const void* ptr) { ImGuiID seed = IDStack.back(); ImGuiID id = ImHashData(&ptr, sizeof(void*), seed); - ImGui::KeepAliveID(id); ImGuiContext& g = *GImGui; if (g.DebugHookIdInfo == id) ImGui::DebugHookIdInfo(id, ImGuiDataType_Pointer, ptr, NULL); @@ -3129,37 +3386,6 @@ ImGuiID ImGuiWindow::GetID(const void* ptr) } ImGuiID ImGuiWindow::GetID(int n) -{ - ImGuiID seed = IDStack.back(); - ImGuiID id = ImHashData(&n, sizeof(n), seed); - ImGui::KeepAliveID(id); - ImGuiContext& g = *GImGui; - if (g.DebugHookIdInfo == id) - ImGui::DebugHookIdInfo(id, ImGuiDataType_S32, (void*)(intptr_t)n, NULL); - return id; -} - -ImGuiID ImGuiWindow::GetIDNoKeepAlive(const char* str, const char* str_end) -{ - ImGuiID seed = IDStack.back(); - ImGuiID id = ImHashStr(str, str_end ? (str_end - str) : 0, seed); - ImGuiContext& g = *GImGui; - if (g.DebugHookIdInfo == id) - ImGui::DebugHookIdInfo(id, ImGuiDataType_String, str, str_end); - return id; -} - -ImGuiID ImGuiWindow::GetIDNoKeepAlive(const void* ptr) -{ - ImGuiID seed = IDStack.back(); - ImGuiID id = ImHashData(&ptr, sizeof(void*), seed); - ImGuiContext& g = *GImGui; - if (g.DebugHookIdInfo == id) - ImGui::DebugHookIdInfo(id, ImGuiDataType_Pointer, ptr, NULL); - return id; -} - -ImGuiID ImGuiWindow::GetIDNoKeepAlive(int n) { ImGuiID seed = IDStack.back(); ImGuiID id = ImHashData(&n, sizeof(n), seed); @@ -3175,7 +3401,6 @@ ImGuiID ImGuiWindow::GetIDFromRectangle(const ImRect& r_abs) ImGuiID seed = IDStack.back(); ImRect r_rel = ImGui::WindowRectAbsToRel(this, r_abs); ImGuiID id = ImHashData(&r_rel, sizeof(r_rel), seed); - ImGui::KeepAliveID(id); return id; } @@ -3225,9 +3450,21 @@ void ImGui::GcAwakeTransientWindowBuffers(ImGuiWindow* window) void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window) { ImGuiContext& g = *GImGui; + + // While most behaved code would make an effort to not steal active id during window move/drag operations, + // we at least need to be resilient to it. Cancelling the move is rather aggressive and users of 'master' branch + // may prefer the weird ill-defined half working situation ('docking' did assert), so may need to rework that. + if (g.MovingWindow != NULL && g.ActiveId == g.MovingWindow->MoveId) + { + IMGUI_DEBUG_LOG_ACTIVEID("SetActiveID() cancel MovingWindow\n"); + g.MovingWindow = NULL; + } + + // Set active id g.ActiveIdIsJustActivated = (g.ActiveId != id); if (g.ActiveIdIsJustActivated) { + IMGUI_DEBUG_LOG_ACTIVEID("SetActiveID() old:0x%08X (window \"%s\") -> new:0x%08X (window \"%s\")\n", g.ActiveId, g.ActiveIdWindow ? g.ActiveIdWindow->Name : "", id, window ? window->Name : ""); g.ActiveIdTimer = 0.0f; g.ActiveIdHasBeenPressedBefore = false; g.ActiveIdHasBeenEditedBefore = false; @@ -3246,15 +3483,16 @@ void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window) if (id) { g.ActiveIdIsAlive = id; - g.ActiveIdSource = (g.NavActivateId == id || g.NavActivateInputId == id || g.NavJustMovedToId == id) ? ImGuiInputSource_Nav : ImGuiInputSource_Mouse; + g.ActiveIdSource = (g.NavActivateId == id || g.NavActivateInputId == id || g.NavJustMovedToId == id) ? (ImGuiInputSource)ImGuiInputSource_Nav : ImGuiInputSource_Mouse; } // Clear declaration of inputs claimed by the widget // (Please note that this is WIP and not all keys/inputs are thoroughly declared by all widgets yet) - g.ActiveIdUsingMouseWheel = false; g.ActiveIdUsingNavDirMask = 0x00; + g.ActiveIdUsingKeyInputMask.ClearAllBits(); +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO g.ActiveIdUsingNavInputMask = 0x00; - g.ActiveIdUsingKeyInputMask = 0x00; +#endif } void ImGui::ClearActiveID() @@ -3278,6 +3516,8 @@ ImGuiID ImGui::GetHoveredID() return g.HoveredId ? g.HoveredId : g.HoveredIdPreviousFrame; } +// This is called by ItemAdd(). +// Code not using ItemAdd() may need to call this manually otherwise ActiveId will be cleared. In IMGUI_VERSION_NUM < 18717 this was called by GetID(). void ImGui::KeepAliveID(ImGuiID id) { ImGuiContext& g = *GImGui; @@ -3332,7 +3572,7 @@ bool ImGui::IsItemHovered(ImGuiHoveredFlags flags) { ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; - if (g.NavDisableMouseHover && !g.NavDisableHighlight) + if (g.NavDisableMouseHover && !g.NavDisableHighlight && !(flags & ImGuiHoveredFlags_NoNavOverride)) { if ((g.LastItemData.InFlags & ImGuiItemFlags_Disabled) && !(flags & ImGuiHoveredFlags_AllowWhenDisabled)) return false; @@ -3358,8 +3598,9 @@ bool ImGui::IsItemHovered(ImGuiHoveredFlags flags) // Test if another item is active (e.g. being dragged) if ((flags & ImGuiHoveredFlags_AllowWhenBlockedByActiveItem) == 0) - if (g.ActiveId != 0 && g.ActiveId != g.LastItemData.ID && !g.ActiveIdAllowOverlap && g.ActiveId != window->MoveId) - return false; + if (g.ActiveId != 0 && g.ActiveId != g.LastItemData.ID && !g.ActiveIdAllowOverlap) + if (g.ActiveId != window->MoveId && g.ActiveId != window->TabId) + return false; // Test if interactions on this window are blocked by an active popup or modal. // The ImGuiHoveredFlags_AllowWhenBlockedByPopup flag will be tested here. @@ -3371,8 +3612,9 @@ bool ImGui::IsItemHovered(ImGuiHoveredFlags flags) return false; // Special handling for calling after Begin() which represent the title bar or tab. - // When the window is collapsed (SkipItems==true) that last item will never be overwritten so we need to detect the case. - if ((g.LastItemData.ID == window->ID || g.LastItemData.ID == window->MoveId) && window->WriteAccessed) + // When the window is skipped/collapsed (SkipItems==true) that last item (always ->MoveId submitted by Begin) + // will never be overwritten so we need to detect the case. + if (g.LastItemData.ID == window->MoveId && window->WriteAccessed) return false; } @@ -3393,8 +3635,6 @@ bool ImGui::ItemHoverable(const ImRect& bb, ImGuiID id) return false; if (!IsMouseHoveringRect(bb.Min, bb.Max)) return false; - if (g.NavDisableMouseHover) - return false; if (!IsWindowContentHoverable(window, ImGuiHoveredFlags_None)) { g.HoveredIdDisabled = true; @@ -3430,6 +3670,9 @@ bool ImGui::ItemHoverable(const ImRect& bb, ImGuiID id) IM_DEBUG_BREAK(); } + if (g.NavDisableMouseHover) + return false; + return true; } @@ -3547,20 +3790,23 @@ void ImGui::GetAllocatorFunctions(ImGuiMemAllocFunc* p_alloc_func, ImGuiMemFreeF ImGuiContext* ImGui::CreateContext(ImFontAtlas* shared_font_atlas) { + ImGuiContext* prev_ctx = GetCurrentContext(); ImGuiContext* ctx = IM_NEW(ImGuiContext)(shared_font_atlas); - if (GImGui == NULL) - SetCurrentContext(ctx); - Initialize(ctx); + SetCurrentContext(ctx); + Initialize(); + if (prev_ctx != NULL) + SetCurrentContext(prev_ctx); // Restore previous context if any, else keep new one. return ctx; } void ImGui::DestroyContext(ImGuiContext* ctx) { - if (ctx == NULL) - ctx = GImGui; - Shutdown(ctx); - if (GImGui == ctx) - SetCurrentContext(NULL); + ImGuiContext* prev_ctx = GetCurrentContext(); + if (ctx == NULL) //-V1051 + ctx = prev_ctx; + SetCurrentContext(ctx); + Shutdown(); + SetCurrentContext((prev_ctx != ctx) ? prev_ctx : NULL); IM_DELETE(ctx); } @@ -3741,13 +3987,12 @@ void ImGui::UpdateMouseMovingWindowNewFrame() ImGuiWindow* moving_window = g.MovingWindow->RootWindowDockTree; // When a window stop being submitted while being dragged, it may will its viewport until next Begin() - const bool window_disappared = (!moving_window->WasActive || moving_window->Viewport == NULL); + const bool window_disappared = ((!moving_window->WasActive && !moving_window->Active) || moving_window->Viewport == NULL); if (g.IO.MouseDown[0] && IsMousePosValid(&g.IO.MousePos) && !window_disappared) { ImVec2 pos = g.IO.MousePos - g.ActiveIdClickOffset; if (moving_window->Pos.x != pos.x || moving_window->Pos.y != pos.y) { - MarkIniSettingsDirty(moving_window); SetWindowPos(moving_window, pos, ImGuiCond_Always); if (moving_window->ViewportOwned) // Synchronize viewport immediately because some overlays may relies on clipping rectangle before we Begin() into the window. { @@ -3845,6 +4090,8 @@ void ImGui::UpdateMouseMovingWindowEndFrame() } } +// This is called during NewFrame()->UpdateViewportsNewFrame() only. +// Need to keep in sync with SetWindowPos() static void TranslateWindow(ImGuiWindow* window, const ImVec2& delta) { window->Pos += delta; @@ -3854,6 +4101,7 @@ static void TranslateWindow(ImGuiWindow* window, const ImVec2& delta) window->DC.CursorPos += delta; window->DC.CursorStartPos += delta; window->DC.CursorMaxPos += delta; + window->DC.IdealMaxPos += delta; } static void ScaleWindow(ImGuiWindow* window, float scale) @@ -3870,65 +4118,171 @@ static bool IsWindowActiveAndVisible(ImGuiWindow* window) return (window->Active) && (!window->Hidden); } +static void UpdateAliasKey(ImGuiKey key, bool v, float analog_value) +{ + IM_ASSERT(ImGui::IsAliasKey(key)); + ImGuiKeyData* key_data = ImGui::GetKeyData(key); + key_data->Down = v; + key_data->AnalogValue = analog_value; +} + +static void ImGui::UpdateKeyboardInputs() +{ + ImGuiContext& g = *GImGui; + ImGuiIO& io = g.IO; + + // Import legacy keys or verify they are not used +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO + if (io.BackendUsingLegacyKeyArrays == 0) + { + // Backend used new io.AddKeyEvent() API: Good! Verify that old arrays are never written to externally. + for (int n = 0; n < ImGuiKey_LegacyNativeKey_END; n++) + IM_ASSERT((io.KeysDown[n] == false || IsKeyDown(n)) && "Backend needs to either only use io.AddKeyEvent(), either only fill legacy io.KeysDown[] + io.KeyMap[]. Not both!"); + } + else + { + if (g.FrameCount == 0) + for (int n = ImGuiKey_LegacyNativeKey_BEGIN; n < ImGuiKey_LegacyNativeKey_END; n++) + IM_ASSERT(g.IO.KeyMap[n] == -1 && "Backend is not allowed to write to io.KeyMap[0..511]!"); + + // Build reverse KeyMap (Named -> Legacy) + for (int n = ImGuiKey_NamedKey_BEGIN; n < ImGuiKey_NamedKey_END; n++) + if (io.KeyMap[n] != -1) + { + IM_ASSERT(IsLegacyKey((ImGuiKey)io.KeyMap[n])); + io.KeyMap[io.KeyMap[n]] = n; + } + + // Import legacy keys into new ones + for (int n = ImGuiKey_LegacyNativeKey_BEGIN; n < ImGuiKey_LegacyNativeKey_END; n++) + if (io.KeysDown[n] || io.BackendUsingLegacyKeyArrays == 1) + { + const ImGuiKey key = (ImGuiKey)(io.KeyMap[n] != -1 ? io.KeyMap[n] : n); + IM_ASSERT(io.KeyMap[n] == -1 || IsNamedKey(key)); + io.KeysData[key].Down = io.KeysDown[n]; + if (key != n) + io.KeysDown[key] = io.KeysDown[n]; // Allow legacy code using io.KeysDown[GetKeyIndex()] with old backends + io.BackendUsingLegacyKeyArrays = 1; + } + if (io.BackendUsingLegacyKeyArrays == 1) + { + io.KeysData[ImGuiKey_ModCtrl].Down = io.KeyCtrl; + io.KeysData[ImGuiKey_ModShift].Down = io.KeyShift; + io.KeysData[ImGuiKey_ModAlt].Down = io.KeyAlt; + io.KeysData[ImGuiKey_ModSuper].Down = io.KeySuper; + } + } + +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO + const bool nav_gamepad_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (io.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0; + if (io.BackendUsingLegacyNavInputArray && nav_gamepad_active) + { + #define MAP_LEGACY_NAV_INPUT_TO_KEY1(_KEY, _NAV1) do { io.KeysData[_KEY].Down = (io.NavInputs[_NAV1] > 0.0f); io.KeysData[_KEY].AnalogValue = io.NavInputs[_NAV1]; } while (0) + #define MAP_LEGACY_NAV_INPUT_TO_KEY2(_KEY, _NAV1, _NAV2) do { io.KeysData[_KEY].Down = (io.NavInputs[_NAV1] > 0.0f) || (io.NavInputs[_NAV2] > 0.0f); io.KeysData[_KEY].AnalogValue = ImMax(io.NavInputs[_NAV1], io.NavInputs[_NAV2]); } while (0) + MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadFaceDown, ImGuiNavInput_Activate); + MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadFaceRight, ImGuiNavInput_Cancel); + MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadFaceLeft, ImGuiNavInput_Menu); + MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadFaceUp, ImGuiNavInput_Input); + MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadDpadLeft, ImGuiNavInput_DpadLeft); + MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadDpadRight, ImGuiNavInput_DpadRight); + MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadDpadUp, ImGuiNavInput_DpadUp); + MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadDpadDown, ImGuiNavInput_DpadDown); + MAP_LEGACY_NAV_INPUT_TO_KEY2(ImGuiKey_GamepadL1, ImGuiNavInput_FocusPrev, ImGuiNavInput_TweakSlow); + MAP_LEGACY_NAV_INPUT_TO_KEY2(ImGuiKey_GamepadR1, ImGuiNavInput_FocusNext, ImGuiNavInput_TweakFast); + MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadLStickLeft, ImGuiNavInput_LStickLeft); + MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadLStickRight, ImGuiNavInput_LStickRight); + MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadLStickUp, ImGuiNavInput_LStickUp); + MAP_LEGACY_NAV_INPUT_TO_KEY1(ImGuiKey_GamepadLStickDown, ImGuiNavInput_LStickDown); + #undef NAV_MAP_KEY + } +#endif + +#endif + + // Synchronize io.KeyMods with individual modifiers io.KeyXXX bools, update aliases + io.KeyMods = GetMergedModFlags(); + for (int n = 0; n < ImGuiMouseButton_COUNT; n++) + UpdateAliasKey(MouseButtonToKey(n), io.MouseDown[n], io.MouseDown[n] ? 1.0f : 0.0f); + UpdateAliasKey(ImGuiKey_MouseWheelX, io.MouseWheelH != 0.0f, io.MouseWheelH); + UpdateAliasKey(ImGuiKey_MouseWheelY, io.MouseWheel != 0.0f, io.MouseWheel); + + // Clear gamepad data if disabled + if ((io.BackendFlags & ImGuiBackendFlags_HasGamepad) == 0) + for (int i = ImGuiKey_Gamepad_BEGIN; i < ImGuiKey_Gamepad_END; i++) + { + io.KeysData[i - ImGuiKey_KeysData_OFFSET].Down = false; + io.KeysData[i - ImGuiKey_KeysData_OFFSET].AnalogValue = 0.0f; + } + + // Update keys + for (int i = 0; i < IM_ARRAYSIZE(io.KeysData); i++) + { + ImGuiKeyData* key_data = &io.KeysData[i]; + key_data->DownDurationPrev = key_data->DownDuration; + key_data->DownDuration = key_data->Down ? (key_data->DownDuration < 0.0f ? 0.0f : key_data->DownDuration + io.DeltaTime) : -1.0f; + } +} + static void ImGui::UpdateMouseInputs() { ImGuiContext& g = *GImGui; + ImGuiIO& io = g.IO; // Round mouse position to avoid spreading non-rounded position (e.g. UpdateManualResize doesn't support them well) - if (IsMousePosValid(&g.IO.MousePos)) - g.IO.MousePos = g.MouseLastValidPos = ImFloor(g.IO.MousePos); + if (IsMousePosValid(&io.MousePos)) + io.MousePos = g.MouseLastValidPos = ImFloorSigned(io.MousePos); // If mouse just appeared or disappeared (usually denoted by -FLT_MAX components) we cancel out movement in MouseDelta - if (IsMousePosValid(&g.IO.MousePos) && IsMousePosValid(&g.IO.MousePosPrev)) - g.IO.MouseDelta = g.IO.MousePos - g.IO.MousePosPrev; + if (IsMousePosValid(&io.MousePos) && IsMousePosValid(&io.MousePosPrev)) + io.MouseDelta = io.MousePos - io.MousePosPrev; else - g.IO.MouseDelta = ImVec2(0.0f, 0.0f); + io.MouseDelta = ImVec2(0.0f, 0.0f); // If mouse moved we re-enable mouse hovering in case it was disabled by gamepad/keyboard. In theory should use a >0.0f threshold but would need to reset in everywhere we set this to true. - if (g.IO.MouseDelta.x != 0.0f || g.IO.MouseDelta.y != 0.0f) + if (io.MouseDelta.x != 0.0f || io.MouseDelta.y != 0.0f) g.NavDisableMouseHover = false; - g.IO.MousePosPrev = g.IO.MousePos; - for (int i = 0; i < IM_ARRAYSIZE(g.IO.MouseDown); i++) + io.MousePosPrev = io.MousePos; + for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) { - g.IO.MouseClicked[i] = g.IO.MouseDown[i] && g.IO.MouseDownDuration[i] < 0.0f; - g.IO.MouseClickedCount[i] = 0; // Will be filled below - g.IO.MouseReleased[i] = !g.IO.MouseDown[i] && g.IO.MouseDownDuration[i] >= 0.0f; - g.IO.MouseDownDurationPrev[i] = g.IO.MouseDownDuration[i]; - g.IO.MouseDownDuration[i] = g.IO.MouseDown[i] ? (g.IO.MouseDownDuration[i] < 0.0f ? 0.0f : g.IO.MouseDownDuration[i] + g.IO.DeltaTime) : -1.0f; - if (g.IO.MouseClicked[i]) + io.MouseClicked[i] = io.MouseDown[i] && io.MouseDownDuration[i] < 0.0f; + io.MouseClickedCount[i] = 0; // Will be filled below + io.MouseReleased[i] = !io.MouseDown[i] && io.MouseDownDuration[i] >= 0.0f; + io.MouseDownDurationPrev[i] = io.MouseDownDuration[i]; + io.MouseDownDuration[i] = io.MouseDown[i] ? (io.MouseDownDuration[i] < 0.0f ? 0.0f : io.MouseDownDuration[i] + io.DeltaTime) : -1.0f; + if (io.MouseClicked[i]) { bool is_repeated_click = false; - if ((float)(g.Time - g.IO.MouseClickedTime[i]) < g.IO.MouseDoubleClickTime) + if ((float)(g.Time - io.MouseClickedTime[i]) < io.MouseDoubleClickTime) { - ImVec2 delta_from_click_pos = IsMousePosValid(&g.IO.MousePos) ? (g.IO.MousePos - g.IO.MouseClickedPos[i]) : ImVec2(0.0f, 0.0f); - if (ImLengthSqr(delta_from_click_pos) < g.IO.MouseDoubleClickMaxDist * g.IO.MouseDoubleClickMaxDist) + ImVec2 delta_from_click_pos = IsMousePosValid(&io.MousePos) ? (io.MousePos - io.MouseClickedPos[i]) : ImVec2(0.0f, 0.0f); + if (ImLengthSqr(delta_from_click_pos) < io.MouseDoubleClickMaxDist * io.MouseDoubleClickMaxDist) is_repeated_click = true; } if (is_repeated_click) - g.IO.MouseClickedLastCount[i]++; + io.MouseClickedLastCount[i]++; else - g.IO.MouseClickedLastCount[i] = 1; - g.IO.MouseClickedTime[i] = g.Time; - g.IO.MouseClickedPos[i] = g.IO.MousePos; - g.IO.MouseClickedCount[i] = g.IO.MouseClickedLastCount[i]; - g.IO.MouseDragMaxDistanceAbs[i] = ImVec2(0.0f, 0.0f); - g.IO.MouseDragMaxDistanceSqr[i] = 0.0f; + io.MouseClickedLastCount[i] = 1; + io.MouseClickedTime[i] = g.Time; + io.MouseClickedPos[i] = io.MousePos; + io.MouseClickedCount[i] = io.MouseClickedLastCount[i]; + io.MouseDragMaxDistanceAbs[i] = ImVec2(0.0f, 0.0f); + io.MouseDragMaxDistanceSqr[i] = 0.0f; } - else if (g.IO.MouseDown[i]) + else if (io.MouseDown[i]) { // Maintain the maximum distance we reaching from the initial click position, which is used with dragging threshold - ImVec2 delta_from_click_pos = IsMousePosValid(&g.IO.MousePos) ? (g.IO.MousePos - g.IO.MouseClickedPos[i]) : ImVec2(0.0f, 0.0f); - g.IO.MouseDragMaxDistanceSqr[i] = ImMax(g.IO.MouseDragMaxDistanceSqr[i], ImLengthSqr(delta_from_click_pos)); - g.IO.MouseDragMaxDistanceAbs[i].x = ImMax(g.IO.MouseDragMaxDistanceAbs[i].x, delta_from_click_pos.x < 0.0f ? -delta_from_click_pos.x : delta_from_click_pos.x); - g.IO.MouseDragMaxDistanceAbs[i].y = ImMax(g.IO.MouseDragMaxDistanceAbs[i].y, delta_from_click_pos.y < 0.0f ? -delta_from_click_pos.y : delta_from_click_pos.y); + ImVec2 delta_from_click_pos = IsMousePosValid(&io.MousePos) ? (io.MousePos - io.MouseClickedPos[i]) : ImVec2(0.0f, 0.0f); + io.MouseDragMaxDistanceSqr[i] = ImMax(io.MouseDragMaxDistanceSqr[i], ImLengthSqr(delta_from_click_pos)); + io.MouseDragMaxDistanceAbs[i].x = ImMax(io.MouseDragMaxDistanceAbs[i].x, delta_from_click_pos.x < 0.0f ? -delta_from_click_pos.x : delta_from_click_pos.x); + io.MouseDragMaxDistanceAbs[i].y = ImMax(io.MouseDragMaxDistanceAbs[i].y, delta_from_click_pos.y < 0.0f ? -delta_from_click_pos.y : delta_from_click_pos.y); } // We provide io.MouseDoubleClicked[] as a legacy service - g.IO.MouseDoubleClicked[i] = (g.IO.MouseClickedCount[i] == 2); + io.MouseDoubleClicked[i] = (io.MouseClickedCount[i] == 2); // Clicking any mouse button reactivate mouse hovering which may have been deactivated by gamepad/keyboard navigation - if (g.IO.MouseClicked[i]) + if (io.MouseClicked[i]) g.NavDisableMouseHover = false; } } @@ -3960,10 +4314,13 @@ void ImGui::UpdateMouseWheel() } } - if (g.IO.MouseWheel == 0.0f && g.IO.MouseWheelH == 0.0f) - return; + const bool hovered_id_using_mouse_wheel = (g.HoveredIdPreviousFrame != 0 && g.HoveredIdPreviousFrameUsingMouseWheel); + const bool active_id_using_mouse_wheel_x = g.ActiveIdUsingKeyInputMask.TestBit(ImGuiKey_MouseWheelX); + const bool active_id_using_mouse_wheel_y = g.ActiveIdUsingKeyInputMask.TestBit(ImGuiKey_MouseWheelY); - if ((g.ActiveId != 0 && g.ActiveIdUsingMouseWheel) || (g.HoveredIdPreviousFrame != 0 && g.HoveredIdPreviousFrameUsingMouseWheel)) + float wheel_x = (!hovered_id_using_mouse_wheel && !active_id_using_mouse_wheel_x) ? g.IO.MouseWheelH : 0.0f; + float wheel_y = (!hovered_id_using_mouse_wheel && !active_id_using_mouse_wheel_y) ? g.IO.MouseWheel : 0; + if (wheel_x == 0.0f && wheel_y == 0.0f) return; ImGuiWindow* window = g.WheelingWindow ? g.WheelingWindow : g.HoveredWindow; @@ -3972,7 +4329,7 @@ void ImGui::UpdateMouseWheel() // Zoom / Scale window // FIXME-OBSOLETE: This is an old feature, it still works but pretty much nobody is using it and may be best redesigned. - if (g.IO.MouseWheel != 0.0f && g.IO.KeyCtrl && g.IO.FontAllowUserScaling) + if (wheel_y != 0.0f && g.IO.KeyCtrl && g.IO.FontAllowUserScaling) { StartLockWheelingWindow(window); const float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f); @@ -3996,8 +4353,11 @@ void ImGui::UpdateMouseWheel() // As a standard behavior holding SHIFT while using Vertical Mouse Wheel triggers Horizontal scroll instead // (we avoid doing it on OSX as it the OS input layer handles this already) const bool swap_axis = g.IO.KeyShift && !g.IO.ConfigMacOSXBehaviors; - const float wheel_y = swap_axis ? 0.0f : g.IO.MouseWheel; - const float wheel_x = swap_axis ? g.IO.MouseWheel : g.IO.MouseWheelH; + if (swap_axis) + { + wheel_x = wheel_y; + wheel_y = 0.0f; + } // Vertical Mouse Wheel scrolling if (wheel_y != 0.0f) @@ -4106,15 +4466,16 @@ void ImGui::UpdateHoveredWindowAndCaptureFlags() io.WantTextInput = (g.WantTextInputNextFrame != -1) ? (g.WantTextInputNextFrame != 0) : false; } -ImGuiKeyModFlags ImGui::GetMergedKeyModFlags() +// [Internal] Do not use directly (can read io.KeyMods instead) +ImGuiModFlags ImGui::GetMergedModFlags() { ImGuiContext& g = *GImGui; - ImGuiKeyModFlags key_mod_flags = ImGuiKeyModFlags_None; - if (g.IO.KeyCtrl) { key_mod_flags |= ImGuiKeyModFlags_Ctrl; } - if (g.IO.KeyShift) { key_mod_flags |= ImGuiKeyModFlags_Shift; } - if (g.IO.KeyAlt) { key_mod_flags |= ImGuiKeyModFlags_Alt; } - if (g.IO.KeySuper) { key_mod_flags |= ImGuiKeyModFlags_Super; } - return key_mod_flags; + ImGuiModFlags key_mods = ImGuiModFlags_None; + if (g.IO.KeyCtrl) { key_mods |= ImGuiModFlags_Ctrl; } + if (g.IO.KeyShift) { key_mods |= ImGuiModFlags_Shift; } + if (g.IO.KeyAlt) { key_mods |= ImGuiModFlags_Alt; } + if (g.IO.KeySuper) { key_mods |= ImGuiModFlags_Super; } + return key_mods; } void ImGui::NewFrame() @@ -4203,9 +4564,16 @@ void ImGui::NewFrame() g.HoveredIdUsingMouseWheel = false; g.HoveredIdDisabled = false; - // Update ActiveId data (clear reference to active widget if the widget isn't alive anymore) - if (g.ActiveIdIsAlive != g.ActiveId && g.ActiveIdPreviousFrame == g.ActiveId && g.ActiveId != 0) + // Clear ActiveID if the item is not alive anymore. + // In 1.87, the common most call to KeepAliveID() was moved from GetID() to ItemAdd(). + // As a result, custom widget using ButtonBehavior() _without_ ItemAdd() need to call KeepAliveID() themselves. + if (g.ActiveId != 0 && g.ActiveIdIsAlive != g.ActiveId && g.ActiveIdPreviousFrame == g.ActiveId) + { + IMGUI_DEBUG_LOG_ACTIVEID("NewFrame(): ClearActiveID() because it isn't marked alive anymore!\n"); ClearActiveID(); + } + + // Update ActiveId data (clear reference to active widget if the widget isn't alive anymore) if (g.ActiveId) g.ActiveIdTimer += g.IO.DeltaTime; g.LastActiveIdTimer += g.IO.DeltaTime; @@ -4221,10 +4589,23 @@ void ImGui::NewFrame() if (g.ActiveId == 0) { g.ActiveIdUsingNavDirMask = 0x00; - g.ActiveIdUsingNavInputMask = 0x00; - g.ActiveIdUsingKeyInputMask = 0x00; + g.ActiveIdUsingKeyInputMask.ClearAllBits(); } +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO + if (g.ActiveId == 0) + g.ActiveIdUsingNavInputMask = 0; + else if (g.ActiveIdUsingNavInputMask != 0) + { + // If your custom widget code used: { g.ActiveIdUsingNavInputMask |= (1 << ImGuiNavInput_Cancel); } + // Since IMGUI_VERSION_NUM >= 18804 it should be: { SetActiveIdUsingKey(ImGuiKey_Escape); SetActiveIdUsingKey(ImGuiKey_NavGamepadCancel); } + if (g.ActiveIdUsingNavInputMask & (1 << ImGuiNavInput_Cancel)) + SetActiveIdUsingKey(ImGuiKey_Escape); + if (g.ActiveIdUsingNavInputMask & ~(1 << ImGuiNavInput_Cancel)) + IM_ASSERT(0); // Other values unsupported + } +#endif + // Drag and drop g.DragDropAcceptIdPrev = g.DragDropAcceptIdCurr; g.DragDropAcceptIdCurr = 0; @@ -4237,20 +4618,17 @@ void ImGui::NewFrame() //if (g.IO.AppFocusLost) // ClosePopupsExceptModals(); - // Clear buttons state when focus is lost - // (this is useful so e.g. releasing Alt after focus loss on Alt-Tab doesn't trigger the Alt menu toggle) - if (g.IO.AppFocusLost) - { - g.IO.ClearInputKeys(); - g.IO.AppFocusLost = false; - } + // Process input queue (trickle as many events as possible) + g.InputEventsTrail.resize(0); + UpdateInputEvents(g.IO.ConfigInputTrickleEventQueue); // Update keyboard input state - // Synchronize io.KeyMods with individual modifiers io.KeyXXX bools - g.IO.KeyMods = GetMergedKeyModFlags(); - memcpy(g.IO.KeysDownDurationPrev, g.IO.KeysDownDuration, sizeof(g.IO.KeysDownDuration)); - for (int i = 0; i < IM_ARRAYSIZE(g.IO.KeysDown); i++) - g.IO.KeysDownDuration[i] = g.IO.KeysDown[i] ? (g.IO.KeysDownDuration[i] < 0.0f ? 0.0f : g.IO.KeysDownDuration[i] + g.IO.DeltaTime) : -1.0f; + UpdateKeyboardInputs(); + + //IM_ASSERT(g.IO.KeyCtrl == IsKeyDown(ImGuiKey_LeftCtrl) || IsKeyDown(ImGuiKey_RightCtrl)); + //IM_ASSERT(g.IO.KeyShift == IsKeyDown(ImGuiKey_LeftShift) || IsKeyDown(ImGuiKey_RightShift)); + //IM_ASSERT(g.IO.KeyAlt == IsKeyDown(ImGuiKey_LeftAlt) || IsKeyDown(ImGuiKey_RightAlt)); + //IM_ASSERT(g.IO.KeySuper == IsKeyDown(ImGuiKey_LeftSuper) || IsKeyDown(ImGuiKey_RightSuper)); // Update gamepad/keyboard navigation NavUpdate(); @@ -4277,8 +4655,10 @@ void ImGui::NewFrame() g.MouseCursor = ImGuiMouseCursor_Arrow; g.WantCaptureMouseNextFrame = g.WantCaptureKeyboardNextFrame = g.WantTextInputNextFrame = -1; - g.PlatformImePos = ImVec2(1.0f, 1.0f); // OS Input Method Editor showing on top-left of our window by default - g.PlatformImePosViewport = NULL; + + // Platform IME data: reset for the frame + g.PlatformImeDataPrev = g.PlatformImeData; + g.PlatformImeData.WantVisible = false; // Mouse wheel scrolling, scale UpdateMouseWheel(); @@ -4340,9 +4720,9 @@ void ImGui::NewFrame() CallContextHooks(&g, ImGuiContextHookType_NewFramePost); } -void ImGui::Initialize(ImGuiContext* context) +void ImGui::Initialize() { - ImGuiContext& g = *context; + ImGuiContext& g = *GImGui; IM_ASSERT(!g.Initialized && !g.SettingsLoaded); // Add .ini handle for ImGuiWindow type @@ -4355,11 +4735,11 @@ void ImGui::Initialize(ImGuiContext* context) ini_handler.ReadLineFn = WindowSettingsHandler_ReadLine; ini_handler.ApplyAllFn = WindowSettingsHandler_ApplyAll; ini_handler.WriteAllFn = WindowSettingsHandler_WriteAll; - g.SettingsHandlers.push_back(ini_handler); + AddSettingsHandler(&ini_handler); } // Add .ini handle for ImGuiTable type - TableSettingsInstallHandler(context); + TableSettingsAddSettingsHandler(); // Create default viewport ImGuiViewportP* viewport = IM_NEW(ImGuiViewportP)(); @@ -4368,6 +4748,7 @@ void ImGui::Initialize(ImGuiContext* context) viewport->PlatformWindowCreated = true; viewport->Flags = ImGuiViewportFlags_OwnedByApp; g.Viewports.push_back(viewport); + g.TempBuffer.resize(1024 * 3 + 1, 0); g.PlatformIO.Viewports.push_back(g.Viewports[0]); #ifdef IMGUI_HAS_DOCK @@ -4379,10 +4760,10 @@ void ImGui::Initialize(ImGuiContext* context) } // This function is merely here to free heap allocations. -void ImGui::Shutdown(ImGuiContext* context) +void ImGui::Shutdown() { // The fonts atlas can be used prior to calling NewFrame(), so we clear it even if g.Initialized is FALSE (which would happen if we never called NewFrame) - ImGuiContext& g = *context; + ImGuiContext& g = *GImGui; if (g.IO.Fonts && g.FontAtlasOwnedByContext) { g.IO.Fonts->Locked = false; @@ -4396,18 +4777,10 @@ void ImGui::Shutdown(ImGuiContext* context) // Save settings (unless we haven't attempted to load them: CreateContext/DestroyContext without a call to NewFrame shouldn't save an empty file) if (g.SettingsLoaded && g.IO.IniFilename != NULL) - { - ImGuiContext* backup_context = GImGui; - SetCurrentContext(&g); SaveIniSettingsToDisk(g.IO.IniFilename); - SetCurrentContext(backup_context); - } // Destroy platform windows - ImGuiContext* backup_context = ImGui::GetCurrentContext(); - SetCurrentContext(context); DestroyPlatformWindows(); - SetCurrentContext(backup_context); // Shutdown extensions DockContextShutdown(&g); @@ -4460,6 +4833,7 @@ void ImGui::Shutdown(ImGuiContext* context) g.LogFile = NULL; } g.LogBuffer.clear(); + g.DebugLogBuf.clear(); g.Initialized = false; } @@ -4494,11 +4868,10 @@ static void AddWindowToSortBuffer(ImVector* out_sorted_windows, Im static void AddDrawListToDrawData(ImVector* out_list, ImDrawList* draw_list) { - // Remove trailing command if unused. - // Technically we could return directly instead of popping, but this make things looks neat in Metrics/Debugger window as well. - draw_list->_PopUnusedDrawCmd(); if (draw_list->CmdBuffer.Size == 0) return; + if (draw_list->CmdBuffer.Size == 1 && draw_list->CmdBuffer[0].ElemCount == 0 && draw_list->CmdBuffer[0].UserCallback == NULL) + return; // Draw list sanity check. Detect mismatch between PrimReserve() calls and incrementing _VtxCurrentIdx, _VtxWritePtr etc. // May trigger for you if you are using PrimXXX functions incorrectly. @@ -4595,8 +4968,10 @@ static void SetupViewportDrawData(ImGuiViewportP* viewport, ImVectorOwnerViewport = viewport; for (int n = 0; n < draw_lists->Size; n++) { - draw_data->TotalVtxCount += draw_lists->Data[n]->VtxBuffer.Size; - draw_data->TotalIdxCount += draw_lists->Data[n]->IdxBuffer.Size; + ImDrawList* draw_list = draw_lists->Data[n]; + draw_list->_PopUnusedDrawCmd(); + draw_data->TotalVtxCount += draw_list->VtxBuffer.Size; + draw_data->TotalIdxCount += draw_list->IdxBuffer.Size; } } @@ -4640,6 +5015,7 @@ static void ImGui::RenderDimmedBackgroundBehindWindow(ImGuiWindow* window, ImU32 { // We've already called AddWindowToDrawData() which called DrawList->ChannelsMerge() on DockNodeHost windows, // and draw list have been trimmed already, hence the explicit recreation of a draw command if missing. + // FIXME: This is creating complication, might be simpler if we could inject a drawlist in drawdata at a given position and not attempt to manipulate ImDrawCmd order. ImDrawList* draw_list = window->RootWindowDockTree->DrawList; if (draw_list->CmdBuffer.Size == 0) draw_list->AddDrawCmd(); @@ -4650,12 +5026,15 @@ static void ImGui::RenderDimmedBackgroundBehindWindow(ImGuiWindow* window, ImU32 draw_list->CmdBuffer.pop_back(); draw_list->CmdBuffer.push_front(cmd); draw_list->PopClipRect(); + draw_list->AddDrawCmd(); // We need to create a command as CmdBuffer.back().IdxOffset won't be correct if we append to same command. } // Draw over sibling docking nodes in a same docking tree if (window->RootWindow->DockIsActive) { ImDrawList* draw_list = FindFrontMostVisibleChildWindow(window->RootWindowDockTree)->DrawList; + if (draw_list->CmdBuffer.Size == 0) + draw_list->AddDrawCmd(); draw_list->PushClipRect(viewport_rect.Min, viewport_rect.Max, false); RenderRectFilledWithHole(draw_list, window->RootWindowDockTree->Rect(), window->RootWindow->Rect(), col, 0.0f);// window->RootWindowDockTree->WindowRounding); draw_list->PopClipRect(); @@ -4683,6 +5062,8 @@ static void ImGui::RenderDimmedBackgrounds() { ImGuiContext& g = *GImGui; ImGuiWindow* modal_window = GetTopMostAndVisiblePopupModal(); + if (g.DimBgRatio <= 0.0f && g.NavWindowingHighlightAlpha <= 0.0f) + return; const bool dim_bg_for_modal = (modal_window != NULL); const bool dim_bg_for_window_list = (g.NavWindowingTargetAnim != NULL && g.NavWindowingTargetAnim->Active); if (!dim_bg_for_modal && !dim_bg_for_window_list) @@ -4700,7 +5081,7 @@ static void ImGui::RenderDimmedBackgrounds() { // Draw dimming behind CTRL+Tab target window and behind CTRL+Tab UI window RenderDimmedBackgroundBehindWindow(g.NavWindowingTargetAnim, GetColorU32(ImGuiCol_NavWindowingDimBg, g.DimBgRatio)); - if (g.NavWindowingListWindow != NULL && g.NavWindowingListWindow->Viewport != g.NavWindowingTargetAnim->Viewport) + if (g.NavWindowingListWindow != NULL && g.NavWindowingListWindow->Viewport && g.NavWindowingListWindow->Viewport != g.NavWindowingTargetAnim->Viewport) RenderDimmedBackgroundBehindWindow(g.NavWindowingListWindow, GetColorU32(ImGuiCol_NavWindowingDimBg, g.DimBgRatio)); viewports_already_dimmed[0] = g.NavWindowingTargetAnim->Viewport; viewports_already_dimmed[1] = g.NavWindowingListWindow ? g.NavWindowingListWindow->Viewport : NULL; @@ -4749,14 +5130,12 @@ void ImGui::EndFrame() ErrorCheckEndFrameSanityChecks(); - // Notify OS when our Input Method Editor cursor has moved (e.g. CJK inputs using Microsoft IME) - if (g.PlatformIO.Platform_SetImeInputPos && (g.PlatformImeLastPos.x == FLT_MAX || ImLengthSqr(g.PlatformImePos - g.PlatformImeLastPos) > 0.0001f)) - if (g.PlatformImePosViewport && g.PlatformImePosViewport->PlatformWindowCreated) - { - g.PlatformIO.Platform_SetImeInputPos(g.PlatformImePosViewport, g.PlatformImePos); - g.PlatformImeLastPos = g.PlatformImePos; - g.PlatformImePosViewport = NULL; - } + // Notify Platform/OS when our Input Method Editor cursor has moved (e.g. CJK inputs using Microsoft IME) + if (g.IO.SetPlatformImeDataFn && memcmp(&g.PlatformImeData, &g.PlatformImeDataPrev, sizeof(ImGuiPlatformImeData)) != 0) + { + ImGuiViewport* viewport = FindViewportByID(g.PlatformImeViewport); + g.IO.SetPlatformImeDataFn(viewport ? viewport : GetMainViewport(), &g.PlatformImeData); + } // Hide implicit/fallback "Debug" window if it hasn't been used g.WithinFrameScopeWithImplicitWindow = false; @@ -4822,8 +5201,6 @@ void ImGui::EndFrame() // Clear Input data for next frame g.IO.MouseWheel = g.IO.MouseWheelH = 0.0f; g.IO.InputQueueCharacters.resize(0); - g.IO.KeyModsPrev = g.IO.KeyMods; // doing it here is better than in NewFrame() as we'll tolerate backend writing to KeyMods. If we want to firmly disallow it we should detect it. - memset(g.IO.NavInputs, 0, sizeof(g.IO.NavInputs)); CallContextHooks(&g, ImGuiContextHookType_EndFramePost); } @@ -4872,9 +5249,9 @@ void ImGui::Render() if (first_render_of_frame) RenderDimmedBackgrounds(); - ImVec2 mouse_cursor_offset, mouse_cursor_size, mouse_cursor_uv[4]; - if (g.IO.MouseDrawCursor && g.MouseCursor != ImGuiMouseCursor_None) - g.IO.Fonts->GetMouseCursorTexData(g.MouseCursor, &mouse_cursor_offset, &mouse_cursor_size, &mouse_cursor_uv[0], &mouse_cursor_uv[2]); + // Draw software mouse cursor if requested by io.MouseDrawCursor flag + if (g.IO.MouseDrawCursor && first_render_of_frame && g.MouseCursor != ImGuiMouseCursor_None) + RenderMouseCursor(g.IO.MousePos, g.Style.MouseCursorScale, g.MouseCursor, IM_COL32_WHITE, IM_COL32_BLACK, IM_COL32(0, 0, 0, 48)); // Setup ImDrawData structures for end-user g.IO.MetricsRenderVertices = g.IO.MetricsRenderIndices = 0; @@ -4883,15 +5260,6 @@ void ImGui::Render() ImGuiViewportP* viewport = g.Viewports[n]; viewport->DrawDataBuilder.FlattenIntoSingleLayer(); - // Draw software mouse cursor if requested by io.MouseDrawCursor flag - // (note we scale cursor by current viewport/monitor, however Windows 10 for its own hardware cursor seems to be using a different scale factor) - if (mouse_cursor_size.x > 0.0f && mouse_cursor_size.y > 0.0f && first_render_of_frame) - { - float scale = g.Style.MouseCursorScale * viewport->DpiScale; - if (viewport->GetMainRect().Overlaps(ImRect(g.IO.MousePos, g.IO.MousePos + ImVec2(mouse_cursor_size.x + 2, mouse_cursor_size.y + 2) * scale))) - RenderMouseCursor(GetForegroundDrawList(viewport), g.IO.MousePos, scale, g.MouseCursor, IM_COL32_WHITE, IM_COL32_BLACK, IM_COL32(0, 0, 0, 48)); - } - // Add foreground ImDrawList (for each active viewport) if (viewport->DrawLists[1] != NULL) AddDrawListToDrawData(&viewport->DrawDataBuilder.Layers[0], GetForegroundDrawList(viewport)); @@ -5000,240 +5368,6 @@ static void FindHoveredWindow() g.MovingWindow->Viewport = moving_window_viewport; } -// Test if mouse cursor is hovering given rectangle -// NB- Rectangle is clipped by our current clip setting -// NB- Expand the rectangle to be generous on imprecise inputs systems (g.Style.TouchExtraPadding) -bool ImGui::IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool clip) -{ - ImGuiContext& g = *GImGui; - - // Clip - ImRect rect_clipped(r_min, r_max); - if (clip) - rect_clipped.ClipWith(g.CurrentWindow->ClipRect); - - // Expand for touch input - const ImRect rect_for_touch(rect_clipped.Min - g.Style.TouchExtraPadding, rect_clipped.Max + g.Style.TouchExtraPadding); - if (!rect_for_touch.Contains(g.IO.MousePos)) - return false; - if (!g.MouseViewport->GetMainRect().Overlaps(rect_clipped)) - return false; - return true; -} - -int ImGui::GetKeyIndex(ImGuiKey imgui_key) -{ - IM_ASSERT(imgui_key >= 0 && imgui_key < ImGuiKey_COUNT); - ImGuiContext& g = *GImGui; - return g.IO.KeyMap[imgui_key]; -} - -// Note that dear imgui doesn't know the semantic of each entry of io.KeysDown[]! -// Use your own indices/enums according to how your backend/engine stored them into io.KeysDown[]! -bool ImGui::IsKeyDown(int user_key_index) -{ - if (user_key_index < 0) - return false; - ImGuiContext& g = *GImGui; - IM_ASSERT(user_key_index >= 0 && user_key_index < IM_ARRAYSIZE(g.IO.KeysDown)); - return g.IO.KeysDown[user_key_index]; -} - -// t0 = previous time (e.g.: g.Time - g.IO.DeltaTime) -// t1 = current time (e.g.: g.Time) -// An event is triggered at: -// t = 0.0f t = repeat_delay, t = repeat_delay + repeat_rate*N -int ImGui::CalcTypematicRepeatAmount(float t0, float t1, float repeat_delay, float repeat_rate) -{ - if (t1 == 0.0f) - return 1; - if (t0 >= t1) - return 0; - if (repeat_rate <= 0.0f) - return (t0 < repeat_delay) && (t1 >= repeat_delay); - const int count_t0 = (t0 < repeat_delay) ? -1 : (int)((t0 - repeat_delay) / repeat_rate); - const int count_t1 = (t1 < repeat_delay) ? -1 : (int)((t1 - repeat_delay) / repeat_rate); - const int count = count_t1 - count_t0; - return count; -} - -int ImGui::GetKeyPressedAmount(int key_index, float repeat_delay, float repeat_rate) -{ - ImGuiContext& g = *GImGui; - if (key_index < 0) - return 0; - IM_ASSERT(key_index >= 0 && key_index < IM_ARRAYSIZE(g.IO.KeysDown)); - const float t = g.IO.KeysDownDuration[key_index]; - return CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, repeat_delay, repeat_rate); -} - -bool ImGui::IsKeyPressed(int user_key_index, bool repeat) -{ - ImGuiContext& g = *GImGui; - if (user_key_index < 0) - return false; - IM_ASSERT(user_key_index >= 0 && user_key_index < IM_ARRAYSIZE(g.IO.KeysDown)); - const float t = g.IO.KeysDownDuration[user_key_index]; - if (t == 0.0f) - return true; - if (repeat && t > g.IO.KeyRepeatDelay) - return GetKeyPressedAmount(user_key_index, g.IO.KeyRepeatDelay, g.IO.KeyRepeatRate) > 0; - return false; -} - -bool ImGui::IsKeyReleased(int user_key_index) -{ - ImGuiContext& g = *GImGui; - if (user_key_index < 0) return false; - IM_ASSERT(user_key_index >= 0 && user_key_index < IM_ARRAYSIZE(g.IO.KeysDown)); - return g.IO.KeysDownDurationPrev[user_key_index] >= 0.0f && !g.IO.KeysDown[user_key_index]; -} - -bool ImGui::IsMouseDown(ImGuiMouseButton button) -{ - ImGuiContext& g = *GImGui; - IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); - return g.IO.MouseDown[button]; -} - -bool ImGui::IsMouseClicked(ImGuiMouseButton button, bool repeat) -{ - ImGuiContext& g = *GImGui; - IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); - const float t = g.IO.MouseDownDuration[button]; - if (t == 0.0f) - return true; - - if (repeat && t > g.IO.KeyRepeatDelay) - { - // FIXME: 2019/05/03: Our old repeat code was wrong here and led to doubling the repeat rate, which made it an ok rate for repeat on mouse hold. - int amount = CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, g.IO.KeyRepeatDelay, g.IO.KeyRepeatRate * 0.50f); - if (amount > 0) - return true; - } - return false; -} - -bool ImGui::IsMouseReleased(ImGuiMouseButton button) -{ - ImGuiContext& g = *GImGui; - IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); - return g.IO.MouseReleased[button]; -} - -bool ImGui::IsMouseDoubleClicked(ImGuiMouseButton button) -{ - ImGuiContext& g = *GImGui; - IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); - return g.IO.MouseClickedCount[button] == 2; -} - -int ImGui::GetMouseClickedCount(ImGuiMouseButton button) -{ - ImGuiContext& g = *GImGui; - IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); - return g.IO.MouseClickedCount[button]; -} - -// Return if a mouse click/drag went past the given threshold. Valid to call during the MouseReleased frame. -// [Internal] This doesn't test if the button is pressed -bool ImGui::IsMouseDragPastThreshold(ImGuiMouseButton button, float lock_threshold) -{ - ImGuiContext& g = *GImGui; - IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); - if (lock_threshold < 0.0f) - lock_threshold = g.IO.MouseDragThreshold; - return g.IO.MouseDragMaxDistanceSqr[button] >= lock_threshold * lock_threshold; -} - -bool ImGui::IsMouseDragging(ImGuiMouseButton button, float lock_threshold) -{ - ImGuiContext& g = *GImGui; - IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); - if (!g.IO.MouseDown[button]) - return false; - return IsMouseDragPastThreshold(button, lock_threshold); -} - -ImVec2 ImGui::GetMousePos() -{ - ImGuiContext& g = *GImGui; - return g.IO.MousePos; -} - -// NB: prefer to call right after BeginPopup(). At the time Selectable/MenuItem is activated, the popup is already closed! -ImVec2 ImGui::GetMousePosOnOpeningCurrentPopup() -{ - ImGuiContext& g = *GImGui; - if (g.BeginPopupStack.Size > 0) - return g.OpenPopupStack[g.BeginPopupStack.Size - 1].OpenMousePos; - return g.IO.MousePos; -} - -// We typically use ImVec2(-FLT_MAX,-FLT_MAX) to denote an invalid mouse position. -bool ImGui::IsMousePosValid(const ImVec2* mouse_pos) -{ - // The assert is only to silence a false-positive in XCode Static Analysis. - // Because GImGui is not dereferenced in every code path, the static analyzer assume that it may be NULL (which it doesn't for other functions). - IM_ASSERT(GImGui != NULL); - const float MOUSE_INVALID = -256000.0f; - ImVec2 p = mouse_pos ? *mouse_pos : GImGui->IO.MousePos; - return p.x >= MOUSE_INVALID && p.y >= MOUSE_INVALID; -} - -bool ImGui::IsAnyMouseDown() -{ - ImGuiContext& g = *GImGui; - for (int n = 0; n < IM_ARRAYSIZE(g.IO.MouseDown); n++) - if (g.IO.MouseDown[n]) - return true; - return false; -} - -// Return the delta from the initial clicking position while the mouse button is clicked or was just released. -// This is locked and return 0.0f until the mouse moves past a distance threshold at least once. -// NB: This is only valid if IsMousePosValid(). backends in theory should always keep mouse position valid when dragging even outside the client window. -ImVec2 ImGui::GetMouseDragDelta(ImGuiMouseButton button, float lock_threshold) -{ - ImGuiContext& g = *GImGui; - IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); - if (lock_threshold < 0.0f) - lock_threshold = g.IO.MouseDragThreshold; - if (g.IO.MouseDown[button] || g.IO.MouseReleased[button]) - if (g.IO.MouseDragMaxDistanceSqr[button] >= lock_threshold * lock_threshold) - if (IsMousePosValid(&g.IO.MousePos) && IsMousePosValid(&g.IO.MouseClickedPos[button])) - return g.IO.MousePos - g.IO.MouseClickedPos[button]; - return ImVec2(0.0f, 0.0f); -} - -void ImGui::ResetMouseDragDelta(ImGuiMouseButton button) -{ - ImGuiContext& g = *GImGui; - IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); - // NB: We don't need to reset g.IO.MouseDragMaxDistanceSqr - g.IO.MouseClickedPos[button] = g.IO.MousePos; -} - -ImGuiMouseCursor ImGui::GetMouseCursor() -{ - return GImGui->MouseCursor; -} - -void ImGui::SetMouseCursor(ImGuiMouseCursor cursor_type) -{ - GImGui->MouseCursor = cursor_type; -} - -void ImGui::CaptureKeyboardFromApp(bool capture) -{ - GImGui->WantCaptureKeyboardNextFrame = capture ? 1 : 0; -} - -void ImGui::CaptureMouseFromApp(bool capture) -{ - GImGui->WantCaptureMouseNextFrame = capture ? 1 : 0; -} - bool ImGui::IsItemActive() { ImGuiContext& g = *GImGui; @@ -5349,7 +5483,10 @@ void ImGui::SetItemUsingMouseWheel() if (g.HoveredId == id) g.HoveredIdUsingMouseWheel = true; if (g.ActiveId == id) - g.ActiveIdUsingMouseWheel = true; + { + g.ActiveIdUsingKeyInputMask.SetBit(ImGuiKey_MouseWheelX); + g.ActiveIdUsingKeyInputMask.SetBit(ImGuiKey_MouseWheelY); + } } void ImGui::SetActiveIdUsingNavAndKeys() @@ -5357,8 +5494,7 @@ void ImGui::SetActiveIdUsingNavAndKeys() ImGuiContext& g = *GImGui; IM_ASSERT(g.ActiveId != 0); g.ActiveIdUsingNavDirMask = ~(ImU32)0; - g.ActiveIdUsingNavInputMask = ~(ImU32)0; - g.ActiveIdUsingKeyInputMask = ~(ImU64)0; + g.ActiveIdUsingKeyInputMask.SetAllBits(); NavMoveRequestCancel(); } @@ -5399,15 +5535,16 @@ bool ImGui::BeginChildEx(const char* name, ImGuiID id, const ImVec2& size_arg, b SetNextWindowSize(size); // Build up name. If you need to append to a same child from multiple location in the ID stack, use BeginChild(ImGuiID id) with a stable value. + const char* temp_window_name; if (name) - ImFormatString(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), "%s/%s_%08X", parent_window->Name, name, id); + ImFormatStringToTempBuffer(&temp_window_name, NULL, "%s/%s_%08X", parent_window->Name, name, id); else - ImFormatString(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), "%s/%08X", parent_window->Name, id); + ImFormatStringToTempBuffer(&temp_window_name, NULL, "%s/%08X", parent_window->Name, id); const float backup_border_size = g.Style.ChildBorderSize; if (!border) g.Style.ChildBorderSize = 0.0f; - bool ret = Begin(g.TempBuffer, NULL, flags); + bool ret = Begin(temp_window_name, NULL, flags); g.Style.ChildBorderSize = backup_border_size; ImGuiWindow* child_window = g.CurrentWindow; @@ -5548,7 +5685,6 @@ static void ApplyWindowSettings(ImGuiWindow* window, ImGuiWindowSettings* settin static void UpdateWindowInFocusOrderList(ImGuiWindow* window, bool just_created, ImGuiWindowFlags new_flags) { ImGuiContext& g = *GImGui; - const bool new_is_explicit_child = (new_flags & ImGuiWindowFlags_ChildWindow) != 0; const bool child_flag_changed = new_is_explicit_child != window->IsExplicitChild; if ((just_created || child_flag_changed) && !new_is_explicit_child) @@ -5592,7 +5728,7 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImGuiWindowFlags flags) SetWindowConditionAllowFlags(window, ImGuiCond_FirstUseEver, false); ApplyWindowSettings(window, settings); } - window->DC.CursorStartPos = window->DC.CursorMaxPos = window->Pos; // So first call to CalcContentSize() doesn't return crazy values + window->DC.CursorStartPos = window->DC.CursorMaxPos = window->DC.IdealMaxPos = window->Pos; // So first call to CalcWindowContentSizes() doesn't return crazy values if ((flags & ImGuiWindowFlags_AlwaysAutoResize) != 0) { @@ -5612,7 +5748,6 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImGuiWindowFlags flags) g.Windows.push_front(window); // Quite slow but rare and only once else g.Windows.push_back(window); - UpdateWindowInFocusOrderList(window, true, window->Flags); return window; } @@ -5869,6 +6004,7 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s if (resize_rect.Min.x > resize_rect.Max.x) ImSwap(resize_rect.Min.x, resize_rect.Max.x); if (resize_rect.Min.y > resize_rect.Max.y) ImSwap(resize_rect.Min.y, resize_rect.Max.y); ImGuiID resize_grip_id = window->GetID(resize_grip_n); // == GetWindowResizeCornerID() + KeepAliveID(resize_grip_id); ButtonBehavior(resize_rect, resize_grip_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus); //GetForegroundDrawList(window)->AddRect(resize_rect.Min, resize_rect.Max, IM_COL32(255, 255, 0, 255)); if (hovered || held) @@ -5904,6 +6040,7 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s bool hovered, held; ImRect border_rect = GetResizeBorderRect(window, border_n, grip_hover_inner_size, WINDOWS_HOVER_PADDING); ImGuiID border_id = window->GetID(border_n + 4); // == GetWindowResizeBorderID() + KeepAliveID(border_id); ButtonBehavior(border_rect, border_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus); //GetForegroundDrawLists(window)->AddRect(border_rect.Min, border_rect.Max, IM_COL32(255, 255, 0, 255)); if ((hovered && g.HoveredIdTimer > WINDOWS_RESIZE_FROM_EDGES_FEEDBACK_TIMER) || held) @@ -5928,23 +6065,31 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s window->DC.NavLayerCurrent = ImGuiNavLayer_Main; // Navigation resize (keyboard/gamepad) + // FIXME: This cannot be moved to NavUpdateWindowing() because CalcWindowSizeAfterConstraint() need to callback into user. + // Not even sure the callback works here. if (g.NavWindowingTarget && g.NavWindowingTarget->RootWindowDockTree == window) { - ImVec2 nav_resize_delta; + ImVec2 nav_resize_dir; if (g.NavInputSource == ImGuiInputSource_Keyboard && g.IO.KeyShift) - nav_resize_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_RawKeyboard, ImGuiInputReadMode_Down); + nav_resize_dir = GetKeyVector2d(ImGuiKey_LeftArrow, ImGuiKey_RightArrow, ImGuiKey_UpArrow, ImGuiKey_DownArrow); if (g.NavInputSource == ImGuiInputSource_Gamepad) - nav_resize_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_PadDPad, ImGuiInputReadMode_Down); - if (nav_resize_delta.x != 0.0f || nav_resize_delta.y != 0.0f) + nav_resize_dir = GetKeyVector2d(ImGuiKey_GamepadDpadLeft, ImGuiKey_GamepadDpadRight, ImGuiKey_GamepadDpadUp, ImGuiKey_GamepadDpadDown); + if (nav_resize_dir.x != 0.0f || nav_resize_dir.y != 0.0f) { const float NAV_RESIZE_SPEED = 600.0f; - nav_resize_delta *= ImFloor(NAV_RESIZE_SPEED * g.IO.DeltaTime * ImMin(g.IO.DisplayFramebufferScale.x, g.IO.DisplayFramebufferScale.y)); - nav_resize_delta = ImMax(nav_resize_delta, visibility_rect.Min - window->Pos - window->Size); + const float resize_step = NAV_RESIZE_SPEED * g.IO.DeltaTime * ImMin(g.IO.DisplayFramebufferScale.x, g.IO.DisplayFramebufferScale.y); + g.NavWindowingAccumDeltaSize += nav_resize_dir * resize_step; + g.NavWindowingAccumDeltaSize = ImMax(g.NavWindowingAccumDeltaSize, visibility_rect.Min - window->Pos - window->Size); // We need Pos+Size >= visibility_rect.Min, so Size >= visibility_rect.Min - Pos, so size_delta >= visibility_rect.Min - window->Pos - window->Size g.NavWindowingToggleLayer = false; g.NavDisableMouseHover = true; resize_grip_col[0] = GetColorU32(ImGuiCol_ResizeGripActive); - // FIXME-NAV: Should store and accumulate into a separate size buffer to handle sizing constraints properly, right now a constraint will make us stuck. - size_target = CalcWindowSizeAfterConstraint(window, window->SizeFull + nav_resize_delta); + ImVec2 accum_floored = ImFloor(g.NavWindowingAccumDeltaSize); + if (accum_floored.x != 0.0f || accum_floored.y != 0.0f) + { + // FIXME-NAV: Should store and accumulate into a separate size buffer to handle sizing constraints properly, right now a constraint will make us stuck. + size_target = CalcWindowSizeAfterConstraint(window, window->SizeFull + accum_floored); + g.NavWindowingAccumDeltaSize -= accum_floored; + } } } @@ -5968,8 +6113,8 @@ static inline void ClampWindowRect(ImGuiWindow* window, const ImRect& visibility { ImGuiContext& g = *GImGui; ImVec2 size_for_clamping = window->Size; - if (g.IO.ConfigWindowsMoveFromTitleBarOnly && !(window->Flags & ImGuiWindowFlags_NoTitleBar)) - size_for_clamping.y = window->TitleBarHeight(); + if (g.IO.ConfigWindowsMoveFromTitleBarOnly && (!(window->Flags & ImGuiWindowFlags_NoTitleBar) || window->DockNodeAsHost)) + size_for_clamping.y = ImGui::GetFrameHeight(); // Not using window->TitleBarHeight() as DockNodeAsHost will report 0.0f here. window->Pos = ImClamp(window->Pos, visibility_rect.Min - size_for_clamping, visibility_rect.Max); } @@ -6060,16 +6205,14 @@ void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar } // Render, for docked windows and host windows we ensure bg goes before decorations - ImDrawList* bg_draw_list = window->DockIsActive ? window->DockNode->HostWindow->DrawList : window->DrawList; - if (window->DockIsActive || (flags & ImGuiWindowFlags_DockNodeHost)) - bg_draw_list->ChannelsSetCurrent(0); if (window->DockIsActive) window->DockNode->LastBgColor = bg_col; - - bg_draw_list->AddRectFilled(window->Pos + ImVec2(0, window->TitleBarHeight()), window->Pos + window->Size, bg_col, window_rounding, (flags & ImGuiWindowFlags_NoTitleBar) ? 0 : ImDrawFlags_RoundCornersBottom); - + ImDrawList* bg_draw_list = window->DockIsActive ? window->DockNode->HostWindow->DrawList : window->DrawList; if (window->DockIsActive || (flags & ImGuiWindowFlags_DockNodeHost)) - bg_draw_list->ChannelsSetCurrent(1); + bg_draw_list->ChannelsSetCurrent(DOCKING_HOST_DRAW_CHANNEL_BG); + bg_draw_list->AddRectFilled(window->Pos + ImVec2(0, window->TitleBarHeight()), window->Pos + window->Size, bg_col, window_rounding, (flags & ImGuiWindowFlags_NoTitleBar) ? 0 : ImDrawFlags_RoundCornersBottom); + if (window->DockIsActive || (flags & ImGuiWindowFlags_DockNodeHost)) + bg_draw_list->ChannelsSetCurrent(DOCKING_HOST_DRAW_CHANNEL_FG); } if (window->DockIsActive) window->DockNode->IsBgDrawnThisFrame = true; @@ -6101,8 +6244,10 @@ void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar float unhide_sz_hit = ImFloor(g.FontSize * 0.55f); ImVec2 p = node->Pos; ImRect r(p, p + ImVec2(unhide_sz_hit, unhide_sz_hit)); + ImGuiID unhide_id = window->GetID("#UNHIDE"); + KeepAliveID(unhide_id); bool hovered, held; - if (ButtonBehavior(r, window->GetID("#UNHIDE"), &hovered, &held, ImGuiButtonFlags_FlattenChildren)) + if (ButtonBehavior(r, unhide_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren)) node->WantHiddenTabBarToggle = true; else if (held && IsMouseDragging(0)) StartMouseMovingWindowOrNode(window, node, true); @@ -6240,7 +6385,7 @@ void ImGui::UpdateWindowParentAndRootLinks(ImGuiWindow* window, ImGuiWindowFlags } if (parent_window && (flags & ImGuiWindowFlags_Popup)) window->RootWindowPopupTree = parent_window->RootWindowPopupTree; - if (parent_window && !(flags & ImGuiWindowFlags_Modal) && (flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Popup))) + if (parent_window && !(flags & ImGuiWindowFlags_Modal) && (flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Popup))) // FIXME: simply use _NoTitleBar ? window->RootWindowForTitleBarHighlight = parent_window->RootWindowForTitleBarHighlight; while (window->RootWindowForNav->Flags & ImGuiWindowFlags_NavFlattened) { @@ -6268,7 +6413,9 @@ static ImGuiWindow* ImGui::FindBlockingModal(ImGuiWindow* window) for (int i = g.OpenPopupStack.Size - 1; i >= 0; i--) { ImGuiWindow* popup_window = g.OpenPopupStack.Data[i].Window; - if (popup_window == NULL || !popup_window->WasActive || !(popup_window->Flags & ImGuiWindowFlags_Modal)) // Check WasActive, because this code may run before popup renders on current frame. + if (popup_window == NULL || !(popup_window->Flags & ImGuiWindowFlags_Modal)) + continue; + if (!popup_window->Active && !popup_window->WasActive) // Check WasActive, because this code may run before popup renders on current frame, also check Active to handle newly created windows. continue; if (IsWindowWithinBeginStackOf(window, popup_window)) // Window is rendered over last modal, no render order change needed. break; @@ -6299,8 +6446,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) const bool window_just_created = (window == NULL); if (window_just_created) window = CreateNewWindow(name, flags); - else - UpdateWindowInFocusOrderList(window, window_just_created, flags); // Automatically disable manual moving/resizing when NoInputs is set if ((flags & ImGuiWindowFlags_NoInputs) == ImGuiWindowFlags_NoInputs) @@ -6326,10 +6471,10 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) const bool window_was_appearing = window->Appearing; if (first_begin_of_the_frame) { + UpdateWindowInFocusOrderList(window, window_just_created, flags); window->Appearing = window_just_activated_by_user; if (window->Appearing) SetWindowConditionAllowFlags(window, ImGuiCond_Appearing, true); - window->FlagsPreviousFrame = window->Flags; window->Flags = (ImGuiWindowFlags)flags; window->LastFrameActive = current_frame; @@ -6358,10 +6503,10 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) BeginDocked(window, p_open); flags = window->Flags; if (window->DockIsActive) + { IM_ASSERT(window->DockNode != NULL); - - // Docking currently override constraints - g.NextWindowData.Flags &= ~ImGuiNextWindowDataFlags_HasSizeConstraint; + g.NextWindowData.Flags &= ~ImGuiNextWindowDataFlags_HasSizeConstraint; // Docking currently override constraints + } // Amend the Appearing flag if (window->DockTabIsVisible && !dock_tab_was_visible && dock_node_was_visible && !window->Appearing && !window_was_appearing) @@ -6377,7 +6522,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) } // Parent window is latched only on the first call to Begin() of the frame, so further append-calls can be done from a different window stack - ImGuiWindow* parent_window_in_stack = window->DockIsActive ? window->DockNode->HostWindow : g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back().Window; + ImGuiWindow* parent_window_in_stack = (window->DockIsActive && window->DockNode->HostWindow) ? window->DockNode->HostWindow : g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back().Window; ImGuiWindow* parent_window = first_begin_of_the_frame ? ((flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Popup)) ? parent_window_in_stack : NULL) : window->ParentWindow; IM_ASSERT(parent_window != NULL || !(flags & ImGuiWindowFlags_ChildWindow)); @@ -6401,6 +6546,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) { ImGuiPopupData& popup_ref = g.OpenPopupStack[g.BeginPopupStack.Size]; popup_ref.Window = window; + popup_ref.ParentNavLayer = parent_window_in_stack->DC.NavLayerCurrent; g.BeginPopupStack.push_back(popup_ref); window->PopupId = popup_ref.PopupId; } @@ -6469,6 +6615,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) { // Initialize const bool window_is_child_tooltip = (flags & ImGuiWindowFlags_ChildWindow) && (flags & ImGuiWindowFlags_Tooltip); // FIXME-WIP: Undocumented behavior of Child+Tooltip for pinned tooltip (#1345) + const bool window_just_appearing_after_hidden_for_resize = (window->HiddenFramesCannotSkipItems > 0); window->Active = true; window->HasCloseButton = (p_open != NULL); window->ClipRect = ImVec4(-FLT_MAX, -FLT_MAX, +FLT_MAX, +FLT_MAX); @@ -6478,7 +6625,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) if (flags & ImGuiWindowFlags_DockNodeHost) { window->DrawList->ChannelsSplit(2); - window->DrawList->ChannelsSetCurrent(1); // Render decorations on channel 1 as we will render the backgrounds manually later + window->DrawList->ChannelsSetCurrent(DOCKING_HOST_DRAW_CHANNEL_FG); // Render decorations on channel 1 as we will render the backgrounds manually later } // Restore buffer capacity when woken from a compacted state, to avoid @@ -6502,7 +6649,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // UPDATE CONTENTS SIZE, UPDATE HIDDEN STATUS // Update contents size from last frame for auto-fitting (or use explicit size) - const bool window_just_appearing_after_hidden_for_resize = (window->HiddenFramesCannotSkipItems > 0); CalcWindowContentSizes(window, &window->ContentSize, &window->ContentSizeIdeal); // FIXME: These flags are decremented before they are used. This means that in order to have these fields produce their intended behaviors @@ -6730,13 +6876,24 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) if (window == window->RootWindow) { ImGuiWindow* blocking_modal = FindBlockingModal(window); - - if (blocking_modal != NULL) - BringWindowToDisplayBehind(window, blocking_modal); + IM_ASSERT(blocking_modal != NULL); + BringWindowToDisplayBehind(window, blocking_modal); } } } + // [Test Engine] Register whole window in the item system +#ifdef IMGUI_ENABLE_TEST_ENGINE + if (g.TestEngineHookItems) + { + IM_ASSERT(window->IDStack.Size == 1); + window->IDStack.Size = 0; + IMGUI_TEST_ENGINE_ITEM_ADD(window->Rect(), window->ID); + IMGUI_TEST_ENGINE_ITEM_INFO(window->ID, window->Name, (g.HoveredWindow == window) ? ImGuiItemStatusFlags_HoveredRect : 0); + window->IDStack.Size = 1; + } +#endif + // Decide if we are going to handle borders and resize grips const bool handle_borders_and_resize_grips = (window->DockNodeAsHost || !window->DockIsActive); @@ -6924,6 +7081,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->DC.IdealMaxPos = window->DC.CursorStartPos; window->DC.CurrLineSize = window->DC.PrevLineSize = ImVec2(0.0f, 0.0f); window->DC.CurrLineTextBaseOffset = window->DC.PrevLineTextBaseOffset = 0.0f; + window->DC.IsSameLine = false; window->DC.NavLayerCurrent = ImGuiNavLayer_Main; window->DC.NavLayersActiveMask = window->DC.NavLayersActiveMaskNext; @@ -6965,7 +7123,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) { window->Viewport->PlatformRequestClose = false; g.NavWindowingToggleLayer = false; // Assume user mapped PlatformRequestClose on ALT-F4 so we disable ALT for menu toggle. False positive not an issue. - IMGUI_DEBUG_LOG_VIEWPORT("Window '%s' PlatformRequestClose\n", window->Name); + IMGUI_DEBUG_LOG_VIEWPORT("[viewport] Window '%s' PlatformRequestClose\n", window->Name); *p_open = false; } } @@ -6983,7 +7141,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) /* //if (g.NavWindow == window && g.ActiveId == 0) if (g.ActiveId == window->MoveId) - if (g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_C)) + if (g.IO.KeyCtrl && IsKeyPressed(ImGuiKey_C)) LogToClipboard(); */ @@ -7005,14 +7163,13 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // We fill last item data based on Title Bar/Tab, in order for IsItemHovered() and IsItemActive() to be usable after Begin(). // This is useful to allow creating context menus on title bar only, etc. if (window->DockIsActive) - SetLastItemData(window->ID, g.CurrentItemFlags, window->DockTabItemStatusFlags, window->DockTabItemRect); + SetLastItemData(window->MoveId, g.CurrentItemFlags, window->DockTabItemStatusFlags, window->DockTabItemRect); else SetLastItemData(window->MoveId, g.CurrentItemFlags, IsMouseHoveringRect(title_bar_rect.Min, title_bar_rect.Max, false) ? ImGuiItemStatusFlags_HoveredRect : 0, title_bar_rect); -#ifdef IMGUI_ENABLE_TEST_ENGINE + // [Test Engine] Register title bar / tab if (!(window->Flags & ImGuiWindowFlags_NoTitleBar)) IMGUI_TEST_ENGINE_ITEM_ADD(g.LastItemData.Rect, g.LastItemData.ID); -#endif } else { @@ -7089,6 +7246,10 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) skip_items = true; window->SkipItems = skip_items; + // Restore NavLayersActiveMaskNext to previous value when not visible, so a CTRL+Tab back can use a safe value. + if (window->SkipItems) + window->DC.NavLayersActiveMaskNext = window->DC.NavLayersActiveMask; + // Sanity check: there are two spots which can set Appearing = true // - when 'window_just_activated_by_user' is set -> HiddenFramesCannotSkipItems is set -> SkipItems always false // - in BeginDocked() path when DockNodeIsVisible == DockTabIsVisible == true -> hidden _should_ be all zero // FIXME: Not formally proven, hence the assert. @@ -7150,7 +7311,9 @@ void ImGui::BringWindowToFocusFront(ImGuiWindow* window) IM_ASSERT(window == window->RootWindow); const int cur_order = window->FocusOrder; + // IMHEX PATCH BEGIN //IM_ASSERT(g.WindowsFocusOrder[cur_order] == window); + // IMHEX PATCH END if (g.WindowsFocusOrder.back() == window) return; @@ -7229,16 +7392,13 @@ void ImGui::FocusWindow(ImGuiWindow* window) if (g.NavWindow != window) { - g.NavWindow = window; + SetNavWindow(window); if (window && g.NavDisableMouseHover) g.NavMousePosDirty = true; g.NavId = window ? window->NavLastIds[0] : 0; // Restore NavId + g.NavLayer = ImGuiNavLayer_Main; g.NavFocusScopeId = 0; g.NavIdIsAlive = false; - g.NavLayer = ImGuiNavLayer_Main; - g.NavInitRequest = g.NavMoveSubmitted = g.NavMoveScoringItems = false; - NavUpdateAnyRequestFlag(); - //IMGUI_DEBUG_LOG("FocusWindow(\"%s\")\n", window ? window->Name : NULL); } // Close popups if any @@ -7266,7 +7426,7 @@ void ImGui::FocusWindow(ImGuiWindow* window) // Select in dock node if (dock_node && dock_node->TabBar) - dock_node->TabBar->SelectedTabId = dock_node->TabBar->NextSelectedTabId = window->ID; + dock_node->TabBar->SelectedTabId = dock_node->TabBar->NextSelectedTabId = window->TabId; // Bring to front BringWindowToFocusFront(focus_front_window); @@ -7293,10 +7453,7 @@ void ImGui::FocusTopMostWindowUnderOne(ImGuiWindow* under_this_window, ImGuiWind { // We may later decide to test for different NoXXXInputs based on the active navigation input (mouse vs nav) but that may feel more confusing to the user. ImGuiWindow* window = g.WindowsFocusOrder[i]; - //IM_ASSERT(window == window->RootWindow); - if (window != window->RootWindow) - return; - + IM_ASSERT(window == window->RootWindow); if (window != ignore_window && window->WasActive) if ((window->Flags & (ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs)) != (ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoNavInputs)) { @@ -7611,6 +7768,10 @@ void ImGui::SetWindowPos(ImGuiWindow* window, const ImVec2& pos, ImGuiCond cond) const ImVec2 old_pos = window->Pos; window->Pos = ImFloor(pos); ImVec2 offset = window->Pos - old_pos; + if (offset.x == 0.0f && offset.y == 0.0f) + return; + MarkIniSettingsDirty(window); + // FIXME: share code with TranslateWindow(), need to confirm whether the 3 rect modified by TranslateWindow() are desirable here. window->DC.CursorPos += offset; // As we happen to move the window while it is being appended to (which is a bad idea - will smear) let's at least offset the cursor window->DC.CursorMaxPos += offset; // And more importantly we need to offset CursorMaxPos/CursorStartPos this so ContentSize calculation doesn't get affected. window->DC.IdealMaxPos += offset; @@ -7645,26 +7806,19 @@ void ImGui::SetWindowSize(ImGuiWindow* window, const ImVec2& size, ImGuiCond con window->SetWindowSizeAllowFlags &= ~(ImGuiCond_Once | ImGuiCond_FirstUseEver | ImGuiCond_Appearing); // Set - if (size.x > 0.0f) - { - window->AutoFitFramesX = 0; + ImVec2 old_size = window->SizeFull; + window->AutoFitFramesX = (size.x <= 0.0f) ? 2 : 0; + window->AutoFitFramesY = (size.y <= 0.0f) ? 2 : 0; + if (size.x <= 0.0f) + window->AutoFitOnlyGrows = false; + else window->SizeFull.x = IM_FLOOR(size.x); - } - else - { - window->AutoFitFramesX = 2; + if (size.y <= 0.0f) window->AutoFitOnlyGrows = false; - } - if (size.y > 0.0f) - { - window->AutoFitFramesY = 0; + else window->SizeFull.y = IM_FLOOR(size.y); - } - else - { - window->AutoFitFramesY = 2; - window->AutoFitOnlyGrows = false; - } + if (old_size.x != window->SizeFull.x || old_size.y != window->SizeFull.y) + MarkIniSettingsDirty(window); } void ImGui::SetWindowSize(const ImVec2& size, ImGuiCond cond) @@ -7894,12 +8048,26 @@ void ImGui::PopFocusScope() g.FocusScopeStack.pop_back(); } +// Note: this will likely be called ActivateItem() once we rework our Focus/Activation system! void ImGui::SetKeyboardFocusHere(int offset) { ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; IM_ASSERT(offset >= -1); // -1 is allowed but not below - g.NavWindow = window; + IMGUI_DEBUG_LOG_ACTIVEID("SetKeyboardFocusHere(%d) in window \"%s\"\n", offset, window->Name); + + // It makes sense in the vast majority of cases to never interrupt a drag and drop. + // When we refactor this function into ActivateItem() we may want to make this an option. + // MovingWindow is protected from most user inputs using SetActiveIdUsingNavAndKeys(), but + // is also automatically dropped in the event g.ActiveId is stolen. + if (g.DragDropActive || g.MovingWindow != NULL) + { + IMGUI_DEBUG_LOG_ACTIVEID("SetKeyboardFocusHere() ignored while DragDropActive!\n"); + return; + } + + SetNavWindow(window); + ImGuiScrollFlags scroll_flags = window->Appearing ? ImGuiScrollFlags_KeepVisibleEdgeX | ImGuiScrollFlags_AlwaysCenterY : ImGuiScrollFlags_KeepVisibleEdgeX | ImGuiScrollFlags_KeepVisibleEdgeY; NavMoveRequestSubmit(ImGuiDir_None, offset < 0 ? ImGuiDir_Up : ImGuiDir_Down, ImGuiNavMoveFlags_Tabbing | ImGuiNavMoveFlags_FocusApi, scroll_flags); // FIXME-NAV: Once we refactor tabbing, add LegacyApi flag to not activate non-inputable. if (offset == -1) @@ -7948,7 +8116,7 @@ void ImGui::PushID(const char* str_id) { ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; - ImGuiID id = window->GetIDNoKeepAlive(str_id); + ImGuiID id = window->GetID(str_id); window->IDStack.push_back(id); } @@ -7956,7 +8124,7 @@ void ImGui::PushID(const char* str_id_begin, const char* str_id_end) { ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; - ImGuiID id = window->GetIDNoKeepAlive(str_id_begin, str_id_end); + ImGuiID id = window->GetID(str_id_begin, str_id_end); window->IDStack.push_back(id); } @@ -7964,7 +8132,7 @@ void ImGui::PushID(const void* ptr_id) { ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; - ImGuiID id = window->GetIDNoKeepAlive(ptr_id); + ImGuiID id = window->GetID(ptr_id); window->IDStack.push_back(id); } @@ -7972,7 +8140,7 @@ void ImGui::PushID(int int_id) { ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; - ImGuiID id = window->GetIDNoKeepAlive(int_id); + ImGuiID id = window->GetID(int_id); window->IDStack.push_back(id); } @@ -7992,7 +8160,6 @@ void ImGui::PushOverrideID(ImGuiID id) ImGuiID ImGui::GetIDWithSeed(const char* str, const char* str_end, ImGuiID seed) { ImGuiID id = ImHashStr(str, str_end ? (str_end - str) : 0, seed); - KeepAliveID(id); ImGuiContext& g = *GImGui; if (g.DebugHookIdInfo == id) DebugHookIdInfo(id, ImGuiDataType_String, str, str_end); @@ -8037,15 +8204,530 @@ bool ImGui::IsRectVisible(const ImVec2& rect_min, const ImVec2& rect_max) } +//----------------------------------------------------------------------------- +// [SECTION] INPUTS +//----------------------------------------------------------------------------- + +// Test if mouse cursor is hovering given rectangle +// NB- Rectangle is clipped by our current clip setting +// NB- Expand the rectangle to be generous on imprecise inputs systems (g.Style.TouchExtraPadding) +bool ImGui::IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool clip) +{ + ImGuiContext& g = *GImGui; + + // Clip + ImRect rect_clipped(r_min, r_max); + if (clip) + rect_clipped.ClipWith(g.CurrentWindow->ClipRect); + + // Expand for touch input + const ImRect rect_for_touch(rect_clipped.Min - g.Style.TouchExtraPadding, rect_clipped.Max + g.Style.TouchExtraPadding); + if (!rect_for_touch.Contains(g.IO.MousePos)) + return false; + if (!g.MouseViewport->GetMainRect().Overlaps(rect_clipped)) + return false; + return true; +} + +ImGuiKeyData* ImGui::GetKeyData(ImGuiKey key) +{ + ImGuiContext& g = *GImGui; + int index; +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO + IM_ASSERT(key >= ImGuiKey_LegacyNativeKey_BEGIN && key < ImGuiKey_NamedKey_END); + if (IsLegacyKey(key)) + index = (g.IO.KeyMap[key] != -1) ? g.IO.KeyMap[key] : key; // Remap native->imgui or imgui->native + else + index = key; +#else + IM_ASSERT(IsNamedKey(key) && "Support for user key indices was dropped in favor of ImGuiKey. Please update backend & user code."); + index = key - ImGuiKey_NamedKey_BEGIN; +#endif + return &g.IO.KeysData[index]; +} + +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO +int ImGui::GetKeyIndex(ImGuiKey key) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(IsNamedKey(key)); + const ImGuiKeyData* key_data = GetKeyData(key); + return (int)(key_data - g.IO.KeysData); +} +#endif + +// Those names a provided for debugging purpose and are not meant to be saved persistently not compared. +static const char* const GKeyNames[] = +{ + "Tab", "LeftArrow", "RightArrow", "UpArrow", "DownArrow", "PageUp", "PageDown", + "Home", "End", "Insert", "Delete", "Backspace", "Space", "Enter", "Escape", + "LeftCtrl", "LeftShift", "LeftAlt", "LeftSuper", "RightCtrl", "RightShift", "RightAlt", "RightSuper", "Menu", + "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", + "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", + "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", + "Apostrophe", "Comma", "Minus", "Period", "Slash", "Semicolon", "Equal", "LeftBracket", + "Backslash", "RightBracket", "GraveAccent", "CapsLock", "ScrollLock", "NumLock", "PrintScreen", + "Pause", "Keypad0", "Keypad1", "Keypad2", "Keypad3", "Keypad4", "Keypad5", "Keypad6", + "Keypad7", "Keypad8", "Keypad9", "KeypadDecimal", "KeypadDivide", "KeypadMultiply", + "KeypadSubtract", "KeypadAdd", "KeypadEnter", "KeypadEqual", + "GamepadStart", "GamepadBack", + "GamepadFaceLeft", "GamepadFaceRight", "GamepadFaceUp", "GamepadFaceDown", + "GamepadDpadLeft", "GamepadDpadRight", "GamepadDpadUp", "GamepadDpadDown", + "GamepadL1", "GamepadR1", "GamepadL2", "GamepadR2", "GamepadL3", "GamepadR3", + "GamepadLStickLeft", "GamepadLStickRight", "GamepadLStickUp", "GamepadLStickDown", + "GamepadRStickLeft", "GamepadRStickRight", "GamepadRStickUp", "GamepadRStickDown", + "ModCtrl", "ModShift", "ModAlt", "ModSuper", + "MouseLeft", "MouseRight", "MouseMiddle", "MouseX1", "MouseX2", "MouseWheelX", "MouseWheelY", +}; +IM_STATIC_ASSERT(ImGuiKey_NamedKey_COUNT == IM_ARRAYSIZE(GKeyNames)); + +const char* ImGui::GetKeyName(ImGuiKey key) +{ +#ifdef IMGUI_DISABLE_OBSOLETE_KEYIO + IM_ASSERT((IsNamedKey(key) || key == ImGuiKey_None) && "Support for user key indices was dropped in favor of ImGuiKey. Please update backend and user code."); +#else + if (IsLegacyKey(key)) + { + ImGuiIO& io = GetIO(); + if (io.KeyMap[key] == -1) + return "N/A"; + IM_ASSERT(IsNamedKey((ImGuiKey)io.KeyMap[key])); + key = (ImGuiKey)io.KeyMap[key]; + } +#endif + if (key == ImGuiKey_None) + return "None"; + if (!IsNamedKey(key)) + return "Unknown"; + + return GKeyNames[key - ImGuiKey_NamedKey_BEGIN]; +} + +void ImGui::GetKeyChordName(ImGuiModFlags mods, ImGuiKey key, char* out_buf, int out_buf_size) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT((mods & ~ImGuiModFlags_All) == 0 && "Passing invalid ImGuiModFlags value!"); // A frequent mistake is to pass ImGuiKey_ModXXX instead of ImGuiModFlags_XXX + ImFormatString(out_buf, (size_t)out_buf_size, "%s%s%s%s%s", + (mods & ImGuiModFlags_Ctrl) ? "Ctrl+" : "", + (mods & ImGuiModFlags_Shift) ? "Shift+" : "", + (mods & ImGuiModFlags_Alt) ? "Alt+" : "", + (mods & ImGuiModFlags_Super) ? (g.IO.ConfigMacOSXBehaviors ? "Cmd+" : "Super+") : "", + GetKeyName(key)); +} + +// t0 = previous time (e.g.: g.Time - g.IO.DeltaTime) +// t1 = current time (e.g.: g.Time) +// An event is triggered at: +// t = 0.0f t = repeat_delay, t = repeat_delay + repeat_rate*N +int ImGui::CalcTypematicRepeatAmount(float t0, float t1, float repeat_delay, float repeat_rate) +{ + if (t1 == 0.0f) + return 1; + if (t0 >= t1) + return 0; + if (repeat_rate <= 0.0f) + return (t0 < repeat_delay) && (t1 >= repeat_delay); + const int count_t0 = (t0 < repeat_delay) ? -1 : (int)((t0 - repeat_delay) / repeat_rate); + const int count_t1 = (t1 < repeat_delay) ? -1 : (int)((t1 - repeat_delay) / repeat_rate); + const int count = count_t1 - count_t0; + return count; +} + +void ImGui::GetTypematicRepeatRate(ImGuiInputFlags flags, float* repeat_delay, float* repeat_rate) +{ + ImGuiContext& g = *GImGui; + switch (flags & ImGuiInputFlags_RepeatRateMask_) + { + case ImGuiInputFlags_RepeatRateNavMove: *repeat_delay = g.IO.KeyRepeatDelay * 0.72f; *repeat_rate = g.IO.KeyRepeatRate * 0.80f; return; + case ImGuiInputFlags_RepeatRateNavTweak: *repeat_delay = g.IO.KeyRepeatDelay * 0.72f; *repeat_rate = g.IO.KeyRepeatRate * 0.30f; return; + case ImGuiInputFlags_RepeatRateDefault: default: *repeat_delay = g.IO.KeyRepeatDelay * 1.00f; *repeat_rate = g.IO.KeyRepeatRate * 1.00f; return; + } +} + +// Return value representing the number of presses in the last time period, for the given repeat rate +// (most often returns 0 or 1. The result is generally only >1 when RepeatRate is smaller than DeltaTime, aka large DeltaTime or fast RepeatRate) +int ImGui::GetKeyPressedAmount(ImGuiKey key, float repeat_delay, float repeat_rate) +{ + ImGuiContext& g = *GImGui; + const ImGuiKeyData* key_data = GetKeyData(key); + const float t = key_data->DownDuration; + return CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, repeat_delay, repeat_rate); +} + +// Return 2D vector representing the combination of four cardinal direction, with analog value support (for e.g. ImGuiKey_GamepadLStick* values). +ImVec2 ImGui::GetKeyVector2d(ImGuiKey key_left, ImGuiKey key_right, ImGuiKey key_up, ImGuiKey key_down) +{ + return ImVec2( + GetKeyData(key_right)->AnalogValue - GetKeyData(key_left)->AnalogValue, + GetKeyData(key_down)->AnalogValue - GetKeyData(key_up)->AnalogValue); +} + +// Note that Dear ImGui doesn't know the meaning/semantic of ImGuiKey from 0..511: they are legacy native keycodes. +// Consider transitioning from 'IsKeyDown(MY_ENGINE_KEY_A)' (<1.87) to IsKeyDown(ImGuiKey_A) (>= 1.87) +bool ImGui::IsKeyDown(ImGuiKey key) +{ + const ImGuiKeyData* key_data = GetKeyData(key); + if (!key_data->Down) + return false; + return true; +} + +bool ImGui::IsKeyPressed(ImGuiKey key, bool repeat) +{ + return IsKeyPressedEx(key, repeat ? ImGuiInputFlags_Repeat : ImGuiInputFlags_None); +} + +// Important: unlike legacy IsKeyPressed(ImGuiKey, bool repeat=true) which DEFAULT to repeat, this requires EXPLICIT repeat. +// [Internal] 2022/07: Do not call this directly! It is a temporary entry point which we will soon replace with an overload for IsKeyPressed() when we introduce key ownership. +bool ImGui::IsKeyPressedEx(ImGuiKey key, ImGuiInputFlags flags) +{ + const ImGuiKeyData* key_data = GetKeyData(key); + const float t = key_data->DownDuration; + if (t < 0.0f) + return false; + + bool pressed = (t == 0.0f); + if (!pressed && ((flags & ImGuiInputFlags_Repeat) != 0)) + { + float repeat_delay, repeat_rate; + GetTypematicRepeatRate(flags, &repeat_delay, &repeat_rate); + pressed = (t > repeat_delay) && GetKeyPressedAmount(key, repeat_delay, repeat_rate) > 0; + } + + if (!pressed) + return false; + return true; +} + +bool ImGui::IsKeyReleased(ImGuiKey key) +{ + const ImGuiKeyData* key_data = GetKeyData(key); + if (key_data->DownDurationPrev < 0.0f || key_data->Down) + return false; + return true; +} + +bool ImGui::IsMouseDown(ImGuiMouseButton button) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + return g.IO.MouseDown[button]; +} + +bool ImGui::IsMouseClicked(ImGuiMouseButton button, bool repeat) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + const float t = g.IO.MouseDownDuration[button]; + if (t == 0.0f) + return true; + if (repeat && t > g.IO.KeyRepeatDelay) + return CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, g.IO.KeyRepeatDelay, g.IO.KeyRepeatRate) > 0; + return false; +} + +bool ImGui::IsMouseReleased(ImGuiMouseButton button) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + return g.IO.MouseReleased[button]; +} + +bool ImGui::IsMouseDoubleClicked(ImGuiMouseButton button) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + return g.IO.MouseClickedCount[button] == 2; +} + +int ImGui::GetMouseClickedCount(ImGuiMouseButton button) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + return g.IO.MouseClickedCount[button]; +} + +// Return if a mouse click/drag went past the given threshold. Valid to call during the MouseReleased frame. +// [Internal] This doesn't test if the button is pressed +bool ImGui::IsMouseDragPastThreshold(ImGuiMouseButton button, float lock_threshold) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + if (lock_threshold < 0.0f) + lock_threshold = g.IO.MouseDragThreshold; + return g.IO.MouseDragMaxDistanceSqr[button] >= lock_threshold * lock_threshold; +} + +bool ImGui::IsMouseDragging(ImGuiMouseButton button, float lock_threshold) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + if (!g.IO.MouseDown[button]) + return false; + return IsMouseDragPastThreshold(button, lock_threshold); +} + +ImVec2 ImGui::GetMousePos() +{ + ImGuiContext& g = *GImGui; + return g.IO.MousePos; +} + +// NB: prefer to call right after BeginPopup(). At the time Selectable/MenuItem is activated, the popup is already closed! +ImVec2 ImGui::GetMousePosOnOpeningCurrentPopup() +{ + ImGuiContext& g = *GImGui; + if (g.BeginPopupStack.Size > 0) + return g.OpenPopupStack[g.BeginPopupStack.Size - 1].OpenMousePos; + return g.IO.MousePos; +} + +// We typically use ImVec2(-FLT_MAX,-FLT_MAX) to denote an invalid mouse position. +bool ImGui::IsMousePosValid(const ImVec2* mouse_pos) +{ + // The assert is only to silence a false-positive in XCode Static Analysis. + // Because GImGui is not dereferenced in every code path, the static analyzer assume that it may be NULL (which it doesn't for other functions). + IM_ASSERT(GImGui != NULL); + const float MOUSE_INVALID = -256000.0f; + ImVec2 p = mouse_pos ? *mouse_pos : GImGui->IO.MousePos; + return p.x >= MOUSE_INVALID && p.y >= MOUSE_INVALID; +} + +// [WILL OBSOLETE] This was designed for backends, but prefer having backend maintain a mask of held mouse buttons, because upcoming input queue system will make this invalid. +bool ImGui::IsAnyMouseDown() +{ + ImGuiContext& g = *GImGui; + for (int n = 0; n < IM_ARRAYSIZE(g.IO.MouseDown); n++) + if (g.IO.MouseDown[n]) + return true; + return false; +} + +// Return the delta from the initial clicking position while the mouse button is clicked or was just released. +// This is locked and return 0.0f until the mouse moves past a distance threshold at least once. +// NB: This is only valid if IsMousePosValid(). backends in theory should always keep mouse position valid when dragging even outside the client window. +ImVec2 ImGui::GetMouseDragDelta(ImGuiMouseButton button, float lock_threshold) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + if (lock_threshold < 0.0f) + lock_threshold = g.IO.MouseDragThreshold; + if (g.IO.MouseDown[button] || g.IO.MouseReleased[button]) + if (g.IO.MouseDragMaxDistanceSqr[button] >= lock_threshold * lock_threshold) + if (IsMousePosValid(&g.IO.MousePos) && IsMousePosValid(&g.IO.MouseClickedPos[button])) + return g.IO.MousePos - g.IO.MouseClickedPos[button]; + return ImVec2(0.0f, 0.0f); +} + +void ImGui::ResetMouseDragDelta(ImGuiMouseButton button) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + // NB: We don't need to reset g.IO.MouseDragMaxDistanceSqr + g.IO.MouseClickedPos[button] = g.IO.MousePos; +} + +ImGuiMouseCursor ImGui::GetMouseCursor() +{ + ImGuiContext& g = *GImGui; + return g.MouseCursor; +} + +void ImGui::SetMouseCursor(ImGuiMouseCursor cursor_type) +{ + ImGuiContext& g = *GImGui; + g.MouseCursor = cursor_type; +} + +void ImGui::SetNextFrameWantCaptureKeyboard(bool want_capture_keyboard) +{ + ImGuiContext& g = *GImGui; + g.WantCaptureKeyboardNextFrame = want_capture_keyboard ? 1 : 0; +} + +void ImGui::SetNextFrameWantCaptureMouse(bool want_capture_mouse) +{ + ImGuiContext& g = *GImGui; + g.WantCaptureMouseNextFrame = want_capture_mouse ? 1 : 0; +} + +#ifndef IMGUI_DISABLE_DEBUG_TOOLS +static const char* GetInputSourceName(ImGuiInputSource source) +{ + const char* input_source_names[] = { "None", "Mouse", "Keyboard", "Gamepad", "Nav", "Clipboard" }; + IM_ASSERT(IM_ARRAYSIZE(input_source_names) == ImGuiInputSource_COUNT && source >= 0 && source < ImGuiInputSource_COUNT); + return input_source_names[source]; +} +#endif + +/*static void DebugPrintInputEvent(const char* prefix, const ImGuiInputEvent* e) +{ + if (e->Type == ImGuiInputEventType_MousePos) { IMGUI_DEBUG_LOG_IO("%s: MousePos (%.1f %.1f)\n", prefix, e->MousePos.PosX, e->MousePos.PosY); return; } + if (e->Type == ImGuiInputEventType_MouseButton) { IMGUI_DEBUG_LOG_IO("%s: MouseButton %d %s\n", prefix, e->MouseButton.Button, e->MouseButton.Down ? "Down" : "Up"); return; } + if (e->Type == ImGuiInputEventType_MouseWheel) { IMGUI_DEBUG_LOG_IO("%s: MouseWheel (%.1f %.1f)\n", prefix, e->MouseWheel.WheelX, e->MouseWheel.WheelY); return; } + if (e->Type == ImGuiInputEventType_Key) { IMGUI_DEBUG_LOG_IO("%s: Key \"%s\" %s\n", prefix, ImGui::GetKeyName(e->Key.Key), e->Key.Down ? "Down" : "Up"); return; } + if (e->Type == ImGuiInputEventType_Text) { IMGUI_DEBUG_LOG_IO("%s: Text: %c (U+%08X)\n", prefix, e->Text.Char, e->Text.Char); return; } + if (e->Type == ImGuiInputEventType_Focus) { IMGUI_DEBUG_LOG_IO("%s: AppFocused %d\n", prefix, e->AppFocused.Focused); return; } +}*/ + +// Process input queue +// We always call this with the value of 'bool g.IO.ConfigInputTrickleEventQueue'. +// - trickle_fast_inputs = false : process all events, turn into flattened input state (e.g. successive down/up/down/up will be lost) +// - trickle_fast_inputs = true : process as many events as possible (successive down/up/down/up will be trickled over several frames so nothing is lost) (new feature in 1.87) +void ImGui::UpdateInputEvents(bool trickle_fast_inputs) +{ + ImGuiContext& g = *GImGui; + ImGuiIO& io = g.IO; + + // Only trickle chars<>key when working with InputText() + // FIXME: InputText() could parse event trail? + // FIXME: Could specialize chars<>keys trickling rules for control keys (those not typically associated to characters) + const bool trickle_interleaved_keys_and_text = (trickle_fast_inputs && g.WantTextInputNextFrame == 1); + + bool mouse_moved = false, mouse_wheeled = false, key_changed = false, text_inputted = false; + int mouse_button_changed = 0x00; + ImBitArray key_changed_mask; + + int event_n = 0; + for (; event_n < g.InputEventsQueue.Size; event_n++) + { + const ImGuiInputEvent* e = &g.InputEventsQueue[event_n]; + if (e->Type == ImGuiInputEventType_MousePos) + { + ImVec2 event_pos(e->MousePos.PosX, e->MousePos.PosY); + if (IsMousePosValid(&event_pos)) + event_pos = ImVec2(ImFloorSigned(event_pos.x), ImFloorSigned(event_pos.y)); // Apply same flooring as UpdateMouseInputs() + if (io.MousePos.x != event_pos.x || io.MousePos.y != event_pos.y) + { + // Trickling Rule: Stop processing queued events if we already handled a mouse button change + if (trickle_fast_inputs && (mouse_button_changed != 0 || mouse_wheeled || key_changed || text_inputted)) + break; + io.MousePos = event_pos; + mouse_moved = true; + } + } + else if (e->Type == ImGuiInputEventType_MouseButton) + { + const ImGuiMouseButton button = e->MouseButton.Button; + IM_ASSERT(button >= 0 && button < ImGuiMouseButton_COUNT); + if (io.MouseDown[button] != e->MouseButton.Down) + { + // Trickling Rule: Stop processing queued events if we got multiple action on the same button + if (trickle_fast_inputs && ((mouse_button_changed & (1 << button)) || mouse_wheeled)) + break; + io.MouseDown[button] = e->MouseButton.Down; + mouse_button_changed |= (1 << button); + } + } + else if (e->Type == ImGuiInputEventType_MouseWheel) + { + if (e->MouseWheel.WheelX != 0.0f || e->MouseWheel.WheelY != 0.0f) + { + // Trickling Rule: Stop processing queued events if we got multiple action on the event + if (trickle_fast_inputs && (mouse_moved || mouse_button_changed != 0)) + break; + io.MouseWheelH += e->MouseWheel.WheelX; + io.MouseWheel += e->MouseWheel.WheelY; + mouse_wheeled = true; + } + } + else if (e->Type == ImGuiInputEventType_MouseViewport) + { + io.MouseHoveredViewport = e->MouseViewport.HoveredViewportID; + } + else if (e->Type == ImGuiInputEventType_Key) + { + ImGuiKey key = e->Key.Key; + IM_ASSERT(key != ImGuiKey_None); + const int keydata_index = (key - ImGuiKey_KeysData_OFFSET); + ImGuiKeyData* keydata = &io.KeysData[keydata_index]; + if (keydata->Down != e->Key.Down || keydata->AnalogValue != e->Key.AnalogValue) + { + // Trickling Rule: Stop processing queued events if we got multiple action on the same button + if (trickle_fast_inputs && keydata->Down != e->Key.Down && (key_changed_mask.TestBit(keydata_index) || text_inputted || mouse_button_changed != 0)) + break; + keydata->Down = e->Key.Down; + keydata->AnalogValue = e->Key.AnalogValue; + key_changed = true; + key_changed_mask.SetBit(keydata_index); + + if (key == ImGuiKey_ModCtrl || key == ImGuiKey_ModShift || key == ImGuiKey_ModAlt || key == ImGuiKey_ModSuper) + { + if (key == ImGuiKey_ModCtrl) { io.KeyCtrl = keydata->Down; } + if (key == ImGuiKey_ModShift) { io.KeyShift = keydata->Down; } + if (key == ImGuiKey_ModAlt) { io.KeyAlt = keydata->Down; } + if (key == ImGuiKey_ModSuper) { io.KeySuper = keydata->Down; } + io.KeyMods = GetMergedModFlags(); + } + + // Allow legacy code using io.KeysDown[GetKeyIndex()] with new backends +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO + io.KeysDown[key] = keydata->Down; + if (io.KeyMap[key] != -1) + io.KeysDown[io.KeyMap[key]] = keydata->Down; +#endif + } + } + else if (e->Type == ImGuiInputEventType_Text) + { + // Trickling Rule: Stop processing queued events if keys/mouse have been interacted with + if (trickle_fast_inputs && ((key_changed && trickle_interleaved_keys_and_text) || mouse_button_changed != 0 || mouse_moved || mouse_wheeled)) + break; + unsigned int c = e->Text.Char; + io.InputQueueCharacters.push_back(c <= IM_UNICODE_CODEPOINT_MAX ? (ImWchar)c : IM_UNICODE_CODEPOINT_INVALID); + if (trickle_interleaved_keys_and_text) + text_inputted = true; + } + else if (e->Type == ImGuiInputEventType_Focus) + { + // We intentionally overwrite this and process lower, in order to give a chance + // to multi-viewports backends to queue AddFocusEvent(false) + AddFocusEvent(true) in same frame. + io.AppFocusLost = !e->AppFocused.Focused; + } + else + { + IM_ASSERT(0 && "Unknown event!"); + } + } + + // Record trail (for domain-specific applications wanting to access a precise trail) + //if (event_n != 0) IMGUI_DEBUG_LOG_IO("Processed: %d / Remaining: %d\n", event_n, g.InputEventsQueue.Size - event_n); + for (int n = 0; n < event_n; n++) + g.InputEventsTrail.push_back(g.InputEventsQueue[n]); + + // [DEBUG] + /*if (event_n != 0) + for (int n = 0; n < g.InputEventsQueue.Size; n++) + DebugPrintInputEvent(n < event_n ? "Processed" : "Remaining", &g.InputEventsQueue[n]);*/ + + // Remaining events will be processed on the next frame + if (event_n == g.InputEventsQueue.Size) + g.InputEventsQueue.resize(0); + else + g.InputEventsQueue.erase(g.InputEventsQueue.Data, g.InputEventsQueue.Data + event_n); + + // Clear buttons state when focus is lost + // (this is useful so e.g. releasing Alt after focus loss on Alt-Tab doesn't trigger the Alt menu toggle) + if (g.IO.AppFocusLost) + { + g.IO.ClearInputKeys(); + g.IO.AppFocusLost = false; + } +} + + //----------------------------------------------------------------------------- // [SECTION] ERROR CHECKING //----------------------------------------------------------------------------- // Helper function to verify ABI compatibility between caller code and compiled version of Dear ImGui. // Verify that the type sizes are matching between the calling file's compilation unit and imgui.cpp's compilation unit -// If the user has inconsistent compilation settings, imgui configuration #define, packing pragma, etc. your user code -// may see different structures than what imgui.cpp sees, which is problematic. -// We usually require settings to be in imconfig.h to make sure that they are accessible to all compilation units involved with Dear ImGui. +// If this triggers you have an issue: +// - Most commonly: mismatched headers and compiled code version. +// - Or: mismatched configuration #define, compilation settings, packing pragma etc. +// The configuration settings mentioned in imconfig.h must be set for all compilation units involved with Dear ImGui, +// which is way it is required you put them in your imconfig file (and not just before including imgui.h). +// Otherwise it is possible that different compilation units would see different structure layout bool ImGui::DebugCheckVersionAndDataLayout(const char* version, size_t sz_io, size_t sz_style, size_t sz_vec2, size_t sz_vec4, size_t sz_vert, size_t sz_idx) { bool error = false; @@ -8079,16 +8761,19 @@ static void ImGui::ErrorCheckNewFrameSanityChecks() IM_ASSERT(g.IO.DisplaySize.x >= 0.0f && g.IO.DisplaySize.y >= 0.0f && "Invalid DisplaySize value!"); IM_ASSERT(g.IO.Fonts->IsBuilt() && "Font Atlas not built! Make sure you called ImGui_ImplXXXX_NewFrame() function for renderer backend, which should call io.Fonts->GetTexDataAsRGBA32() / GetTexDataAsAlpha8()"); IM_ASSERT(g.Style.CurveTessellationTol > 0.0f && "Invalid style setting!"); - IM_ASSERT(g.Style.CircleTessellationMaxError > 0.0f && "Invalid style setting!"); + IM_ASSERT(g.Style.CircleTessellationMaxError > 0.0f && "Invalid style setting!"); IM_ASSERT(g.Style.Alpha >= 0.0f && g.Style.Alpha <= 1.0f && "Invalid style setting!"); // Allows us to avoid a few clamps in color computations IM_ASSERT(g.Style.WindowMinSize.x >= 1.0f && g.Style.WindowMinSize.y >= 1.0f && "Invalid style setting."); IM_ASSERT(g.Style.WindowMenuButtonPosition == ImGuiDir_None || g.Style.WindowMenuButtonPosition == ImGuiDir_Left || g.Style.WindowMenuButtonPosition == ImGuiDir_Right); - for (int n = 0; n < ImGuiKey_COUNT; n++) - IM_ASSERT(g.IO.KeyMap[n] >= -1 && g.IO.KeyMap[n] < IM_ARRAYSIZE(g.IO.KeysDown) && "io.KeyMap[] contains an out of bound value (need to be 0..512, or -1 for unmapped key)"); + IM_ASSERT(g.Style.ColorButtonPosition == ImGuiDir_Left || g.Style.ColorButtonPosition == ImGuiDir_Right); +#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO + for (int n = ImGuiKey_NamedKey_BEGIN; n < ImGuiKey_COUNT; n++) + IM_ASSERT(g.IO.KeyMap[n] >= -1 && g.IO.KeyMap[n] < ImGuiKey_LegacyNativeKey_END && "io.KeyMap[] contains an out of bound value (need to be 0..511, or -1 for unmapped key)"); // Check: required key mapping (we intentionally do NOT check all keys to not pressure user into setting up everything, but Space is required and was only added in 1.60 WIP) - if (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) + if ((g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) && g.IO.BackendUsingLegacyKeyArrays == 1) IM_ASSERT(g.IO.KeyMap[ImGuiKey_Space] != -1 && "ImGuiKey_Space is not mapped, required for keyboard navigation."); +#endif // Check: the io.ConfigWindowsResizeFromEdges option requires backend to honor mouse cursor changes and set the ImGuiBackendFlags_HasMouseCursors flag accordingly. if (g.IO.ConfigWindowsResizeFromEdges && !(g.IO.BackendFlags & ImGuiBackendFlags_HasMouseCursors)) @@ -8145,11 +8830,11 @@ static void ImGui::ErrorCheckEndFrameSanityChecks() // send key release events mid-frame. This would normally trigger this assertion and lead to sheared inputs. // We silently accommodate for this case by ignoring/ the case where all io.KeyXXX modifiers were released (aka key_mod_flags == 0), // while still correctly asserting on mid-frame key press events. - const ImGuiKeyModFlags key_mod_flags = GetMergedKeyModFlags(); - IM_ASSERT((key_mod_flags == 0 || g.IO.KeyMods == key_mod_flags) && "Mismatching io.KeyCtrl/io.KeyShift/io.KeyAlt/io.KeySuper vs io.KeyMods"); - IM_UNUSED(key_mod_flags); + const ImGuiModFlags key_mods = GetMergedModFlags(); + IM_ASSERT((key_mods == 0 || g.IO.KeyMods == key_mods) && "Mismatching io.KeyCtrl/io.KeyShift/io.KeyAlt/io.KeySuper vs io.KeyMods"); + IM_UNUSED(key_mods); - // Recover from errors + // [EXPERIMENTAL] Recover from errors: You may call this yourself before EndFrame(). //ErrorCheckEndFrameRecover(); // Report when there is a mismatch of Begin/BeginChild vs End/EndChild calls. Important: Remember that the Begin/BeginChild API requires you @@ -8189,7 +8874,6 @@ void ImGui::ErrorCheckEndFrameRecover(ImGuiErrorLogCallback log_callback, voi IM_ASSERT(window->IsFallbackWindow); break; } - IM_ASSERT(window == g.CurrentWindow); if (window->Flags & ImGuiWindowFlags_ChildWindow) { if (log_callback) log_callback(user_data, "Recovered from missing EndChild() for '%s'", window->Name); @@ -8332,7 +9016,7 @@ void ImGuiStackSizes::CompareWithCurrentState() // - GetWindowContentRegionMin(), GetWindowContentRegionMax() // - BeginGroup() // - EndGroup() -// Also see in imgui_widgets: tab bars, columns. +// Also see in imgui_widgets: tab bars, and in imgui_tables: tables, columns. //----------------------------------------------------------------------------- // Advance cursor given item size for layout. @@ -8349,14 +9033,16 @@ void ImGui::ItemSize(const ImVec2& size, float text_baseline_y) // In theory we should be offsetting the starting position (window->DC.CursorPos), that will be the topic of a larger refactor, // but since ItemSize() is not yet an API that moves the cursor (to handle e.g. wrapping) enlarging the height has the same effect. const float offset_to_match_baseline_y = (text_baseline_y >= 0) ? ImMax(0.0f, window->DC.CurrLineTextBaseOffset - text_baseline_y) : 0.0f; - const float line_height = ImMax(window->DC.CurrLineSize.y, size.y + offset_to_match_baseline_y); + + const float line_y1 = window->DC.IsSameLine ? window->DC.CursorPosPrevLine.y : window->DC.CursorPos.y; + const float line_height = ImMax(window->DC.CurrLineSize.y, /*ImMax(*/window->DC.CursorPos.y - line_y1/*, 0.0f)*/ + size.y + offset_to_match_baseline_y); // Always align ourselves on pixel boundaries //if (g.IO.KeyAlt) window->DrawList->AddRect(window->DC.CursorPos, window->DC.CursorPos + ImVec2(size.x, line_height), IM_COL32(255,0,0,200)); // [DEBUG] window->DC.CursorPosPrevLine.x = window->DC.CursorPos.x + size.x; - window->DC.CursorPosPrevLine.y = window->DC.CursorPos.y; + window->DC.CursorPosPrevLine.y = line_y1; window->DC.CursorPos.x = IM_FLOOR(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); // Next line - window->DC.CursorPos.y = IM_FLOOR(window->DC.CursorPos.y + line_height + g.Style.ItemSpacing.y); // Next line + window->DC.CursorPos.y = IM_FLOOR(line_y1 + line_height + g.Style.ItemSpacing.y); // Next line window->DC.CursorMaxPos.x = ImMax(window->DC.CursorMaxPos.x, window->DC.CursorPosPrevLine.x); window->DC.CursorMaxPos.y = ImMax(window->DC.CursorMaxPos.y, window->DC.CursorPos.y - g.Style.ItemSpacing.y); //if (g.IO.KeyAlt) window->DrawList->AddCircle(window->DC.CursorMaxPos, 3.0f, IM_COL32(255,0,0,255), 4); // [DEBUG] @@ -8365,17 +9051,13 @@ void ImGui::ItemSize(const ImVec2& size, float text_baseline_y) window->DC.CurrLineSize.y = 0.0f; window->DC.PrevLineTextBaseOffset = ImMax(window->DC.CurrLineTextBaseOffset, text_baseline_y); window->DC.CurrLineTextBaseOffset = 0.0f; + window->DC.IsSameLine = false; // Horizontal layout mode if (window->DC.LayoutType == ImGuiLayoutType_Horizontal) SameLine(); } -void ImGui::ItemSize(const ImRect& bb, float text_baseline_y) -{ - ItemSize(bb.GetSize(), text_baseline_y); -} - // Declare item bounding box for clipping and interaction. // Note that the size can be different than the one provided to ItemSize(). Typically, widgets that spread over available surface // declare their minimum size requirement to ItemSize() and provide a larger region to ItemAdd() which is used drawing/interaction. @@ -8395,6 +9077,8 @@ bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb_arg, ImGu // Directional navigation processing if (id != 0) { + KeepAliveID(id); + // Runs prior to clipping early-out // (a) So that NavInitRequest can be honored, for newly opened windows to select a default widget // (b) So that we can scroll up/down past clipped items. This adds a small O(N) cost to regular navigation requests @@ -8450,25 +9134,28 @@ bool ImGui::ItemAdd(const ImRect& bb, ImGuiID id, const ImRect* nav_bb_arg, ImGu // spacing_w >= 0 : enforce spacing amount void ImGui::SameLine(float offset_from_start_x, float spacing_w) { - ImGuiWindow* window = GetCurrentWindow(); + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; if (window->SkipItems) return; - ImGuiContext& g = *GImGui; if (offset_from_start_x != 0.0f) { - if (spacing_w < 0.0f) spacing_w = 0.0f; + if (spacing_w < 0.0f) + spacing_w = 0.0f; window->DC.CursorPos.x = window->Pos.x - window->Scroll.x + offset_from_start_x + spacing_w + window->DC.GroupOffset.x + window->DC.ColumnsOffset.x; window->DC.CursorPos.y = window->DC.CursorPosPrevLine.y; } else { - if (spacing_w < 0.0f) spacing_w = g.Style.ItemSpacing.x; + if (spacing_w < 0.0f) + spacing_w = g.Style.ItemSpacing.x; window->DC.CursorPos.x = window->DC.CursorPosPrevLine.x + spacing_w; window->DC.CursorPos.y = window->DC.CursorPosPrevLine.y; } window->DC.CurrLineSize = window->DC.PrevLineSize; window->DC.CurrLineTextBaseOffset = window->DC.PrevLineTextBaseOffset; + window->DC.IsSameLine = true; } ImVec2 ImGui::GetCursorScreenPos() @@ -8613,7 +9300,8 @@ float ImGui::CalcItemWidth() // The 4.0f here may be changed to match CalcItemWidth() and/or BeginChild() (right now we have a mismatch which is harmless but undesirable) ImVec2 ImGui::CalcItemSize(ImVec2 size, float default_w, float default_h) { - ImGuiWindow* window = GImGui->CurrentWindow; + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; ImVec2 region_max; if (size.x < 0.0f || size.y < 0.0f) @@ -9170,7 +9858,9 @@ ImGuiWindow* ImGui::GetTopMostAndVisiblePopupModal() void ImGui::OpenPopup(const char* str_id, ImGuiPopupFlags popup_flags) { ImGuiContext& g = *GImGui; - OpenPopupEx(g.CurrentWindow->GetID(str_id), popup_flags); + ImGuiID id = g.CurrentWindow->GetID(str_id); + IMGUI_DEBUG_LOG_POPUP("[popup] OpenPopup(\"%s\" -> 0x%08X\n", str_id, id); + OpenPopupEx(id, popup_flags); } void ImGui::OpenPopup(ImGuiID id, ImGuiPopupFlags popup_flags) @@ -9201,7 +9891,7 @@ void ImGui::OpenPopupEx(ImGuiID id, ImGuiPopupFlags popup_flags) popup_ref.OpenPopupPos = NavCalcPreferredRefPos(); popup_ref.OpenMousePos = IsMousePosValid(&g.IO.MousePos) ? g.IO.MousePos : popup_ref.OpenPopupPos; - IMGUI_DEBUG_LOG_POPUP("OpenPopupEx(0x%08X)\n", id); + IMGUI_DEBUG_LOG_POPUP("[popup] OpenPopupEx(0x%08X)\n", id); if (g.OpenPopupStack.Size < current_stack_size + 1) { g.OpenPopupStack.push_back(popup_ref); @@ -9271,7 +9961,7 @@ void ImGui::ClosePopupsOverWindow(ImGuiWindow* ref_window, bool restore_focus_to } if (popup_count_to_keep < g.OpenPopupStack.Size) // This test is not required but it allows to set a convenient breakpoint on the statement below { - IMGUI_DEBUG_LOG_POPUP("ClosePopupsOverWindow(\"%s\") -> ClosePopupToLevel(%d)\n", ref_window->Name, popup_count_to_keep); + IMGUI_DEBUG_LOG_POPUP("[popup] ClosePopupsOverWindow(\"%s\")\n", ref_window ? ref_window->Name : ""); ClosePopupToLevel(popup_count_to_keep, restore_focus_to_window_under_popup); } } @@ -9294,7 +9984,7 @@ void ImGui::ClosePopupsExceptModals() void ImGui::ClosePopupToLevel(int remaining, bool restore_focus_to_window_under_popup) { ImGuiContext& g = *GImGui; - IMGUI_DEBUG_LOG_POPUP("ClosePopupToLevel(%d), restore_focus_to_window_under_popup=%d\n", remaining, restore_focus_to_window_under_popup); + IMGUI_DEBUG_LOG_POPUP("[popup] ClosePopupToLevel(%d), restore_focus_to_window_under_popup=%d\n", remaining, restore_focus_to_window_under_popup); IM_ASSERT(remaining >= 0 && remaining < g.OpenPopupStack.Size); // Trim open popup stack @@ -9339,7 +10029,7 @@ void ImGui::CloseCurrentPopup() break; popup_idx--; } - IMGUI_DEBUG_LOG_POPUP("CloseCurrentPopup %d -> %d\n", g.BeginPopupStack.Size - 1, popup_idx); + IMGUI_DEBUG_LOG_POPUP("[popup] CloseCurrentPopup %d -> %d\n", g.BeginPopupStack.Size - 1, popup_idx); ClosePopupToLevel(popup_idx, true); // A common pattern is to close a popup when selecting a menu item/selectable that will open another window. @@ -9382,7 +10072,8 @@ bool ImGui::BeginPopup(const char* str_id, ImGuiWindowFlags flags) return false; } flags |= ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings; - return BeginPopupEx(g.CurrentWindow->GetID(str_id), flags); + ImGuiID id = g.CurrentWindow->GetID(str_id); + return BeginPopupEx(id, flags); } // If 'p_open' is specified for a modal popup window, the popup will have a regular close button which will close the popup. @@ -9461,7 +10152,7 @@ void ImGui::OpenPopupOnItemClick(const char* str_id, ImGuiPopupFlags popup_flags // - You may want to handle the whole on user side if you have specific needs (e.g. tweaking IsItemHovered() parameters). // This is essentially the same as: // id = str_id ? GetID(str_id) : GetItemID(); -// OpenPopupOnItemClick(str_id); +// OpenPopupOnItemClick(str_id, ImGuiPopupFlags_MouseButtonRight); // return BeginPopup(id); // Which is essentially the same as: // id = str_id ? GetID(str_id) : GetItemID(); @@ -9632,8 +10323,7 @@ ImVec2 ImGui::FindBestWindowPosForPopup(ImGuiWindow* window) } if (window->Flags & ImGuiWindowFlags_Popup) { - ImRect r_avoid = ImRect(window->Pos.x - 1, window->Pos.y - 1, window->Pos.x + 1, window->Pos.y + 1); - return FindBestWindowPosForPopupEx(window->Pos, window->Size, &window->AutoPosLastDirection, r_outer, r_avoid, ImGuiPopupPositionPolicy_Default); + return FindBestWindowPosForPopupEx(window->Pos, window->Size, &window->AutoPosLastDirection, r_outer, ImRect(window->Pos, window->Pos), ImGuiPopupPositionPolicy_Default); // Ideally we'd disable r_avoid here } if (window->Flags & ImGuiWindowFlags_Tooltip) { @@ -9655,8 +10345,22 @@ ImVec2 ImGui::FindBestWindowPosForPopup(ImGuiWindow* window) // [SECTION] KEYBOARD/GAMEPAD NAVIGATION //----------------------------------------------------------------------------- -// FIXME-NAV: The existence of SetNavID vs SetFocusID properly needs to be clarified/reworked. -// In our terminology those should be interchangeable. Those two functions are merely a legacy artifact, so at minimum naming should be clarified. +// FIXME-NAV: The existence of SetNavID vs SetFocusID vs FocusWindow() needs to be clarified/reworked. +// In our terminology those should be interchangeable, yet right now this is super confusing. +// Those two functions are merely a legacy artifact, so at minimum naming should be clarified. + +void ImGui::SetNavWindow(ImGuiWindow* window) +{ + ImGuiContext& g = *GImGui; + if (g.NavWindow != window) + { + IMGUI_DEBUG_LOG_FOCUS("[focus] SetNavWindow(\"%s\")\n", window ? window->Name : ""); + g.NavWindow = window; + } + g.NavInitRequest = g.NavMoveSubmitted = g.NavMoveScoringItems = false; + NavUpdateAnyRequestFlag(); +} + void ImGui::SetNavID(ImGuiID id, ImGuiNavLayer nav_layer, ImGuiID focus_scope_id, const ImRect& rect_rel) { ImGuiContext& g = *GImGui; @@ -9674,12 +10378,12 @@ void ImGui::SetFocusID(ImGuiID id, ImGuiWindow* window) ImGuiContext& g = *GImGui; IM_ASSERT(id != 0); + if (g.NavWindow != window) + SetNavWindow(window); + // Assume that SetFocusID() is called in the context where its window->DC.NavLayerCurrent and window->DC.NavFocusScopeIdCurrent are valid. // Note that window may be != g.CurrentWindow (e.g. SetFocusID call in InputTextEx for multi-line text) const ImGuiNavLayer nav_layer = window->DC.NavLayerCurrent; - if (g.NavWindow != window) - g.NavInitRequest = false; - g.NavWindow = window; g.NavId = id; g.NavLayer = nav_layer; g.NavFocusScopeId = window->DC.NavFocusScopeIdCurrent; @@ -9879,10 +10583,10 @@ static void ImGui::NavProcessItem() const ImGuiItemFlags item_flags = g.LastItemData.InFlags; // Process Init Request - if (g.NavInitRequest && g.NavLayer == window->DC.NavLayerCurrent) + if (g.NavInitRequest && g.NavLayer == window->DC.NavLayerCurrent && (item_flags & ImGuiItemFlags_Disabled) == 0) { // Even if 'ImGuiItemFlags_NoNavDefaultFocus' is on (typically collapse/close button) we record the first ResultId so they can be used as a fallback - const bool candidate_for_nav_default_focus = (item_flags & (ImGuiItemFlags_NoNavDefaultFocus | ImGuiItemFlags_Disabled)) == 0; + const bool candidate_for_nav_default_focus = (item_flags & ImGuiItemFlags_NoNavDefaultFocus) == 0; if (candidate_for_nav_default_focus || g.NavInitResultId == 0) { g.NavInitResultId = id; @@ -9927,7 +10631,8 @@ static void ImGui::NavProcessItem() // Update window-relative bounding box of navigated item if (g.NavId == id) { - g.NavWindow = window; // Always refresh g.NavWindow, because some operations such as FocusItem() don't have a window. + if (g.NavWindow != window) + SetNavWindow(window); // Always refresh g.NavWindow, because some operations such as FocusItem() may not have a window. g.NavLayer = window->DC.NavLayerCurrent; g.NavFocusScopeId = window->DC.NavFocusScopeIdCurrent; g.NavIdIsAlive = true; @@ -10005,10 +10710,11 @@ void ImGui::NavMoveRequestSubmit(ImGuiDir move_dir, ImGuiDir clip_dir, ImGuiNavM g.NavMoveScrollFlags = scroll_flags; g.NavMoveForwardToNextFrame = false; g.NavMoveKeyMods = g.IO.KeyMods; - g.NavTabbingCounter = 0; g.NavMoveResultLocal.Clear(); g.NavMoveResultLocalVisible.Clear(); g.NavMoveResultOther.Clear(); + g.NavTabbingCounter = 0; + g.NavTabbingResultFirst.Clear(); NavUpdateAnyRequestFlag(); } @@ -10078,7 +10784,12 @@ void ImGui::NavRestoreLayer(ImGuiNavLayer layer) { ImGuiContext& g = *GImGui; if (layer == ImGuiNavLayer_Main) - g.NavWindow = NavRestoreLastChildNavWindow(g.NavWindow); + { + ImGuiWindow* prev_nav_window = g.NavWindow; + g.NavWindow = NavRestoreLastChildNavWindow(g.NavWindow); // FIXME-NAV: Should clear ongoing nav requests? + if (prev_nav_window) + IMGUI_DEBUG_LOG_FOCUS("[focus] NavRestoreLayer: from \"%s\" to SetNavWindow(\"%s\")\n", prev_nav_window->Name, g.NavWindow->Name); + } ImGuiWindow* window = g.NavWindow; if (window->NavLastIds[layer] != 0) { @@ -10146,9 +10857,10 @@ static ImVec2 ImGui::NavCalcPreferredRefPos() if (g.NavDisableHighlight || !g.NavDisableMouseHover || !window) { // Mouse (we need a fallback in case the mouse becomes invalid after being used) - if (IsMousePosValid(&g.IO.MousePos)) - return g.IO.MousePos; - return g.MouseLastValidPos; + // The +1.0f offset when stored by OpenPopupEx() allows reopening this or another popup (same or another mouse button) while not moving the mouse, it is pretty standard. + // In theory we could move that +1.0f offset in OpenPopupEx() + ImVec2 p = IsMousePosValid(&g.IO.MousePos) ? g.IO.MousePos : g.MouseLastValidPos; + return ImVec2(p.x + 1.0f, p.y); } else { @@ -10166,44 +10878,27 @@ static ImVec2 ImGui::NavCalcPreferredRefPos() } } -float ImGui::GetNavInputAmount(ImGuiNavInput n, ImGuiInputReadMode mode) +float ImGui::GetNavTweakPressedAmount(ImGuiAxis axis) { ImGuiContext& g = *GImGui; - if (mode == ImGuiInputReadMode_Down) - return g.IO.NavInputs[n]; // Instant, read analog input (0.0f..1.0f, as provided by user) + float repeat_delay, repeat_rate; + GetTypematicRepeatRate(ImGuiInputFlags_RepeatRateNavTweak, &repeat_delay, &repeat_rate); - const float t = g.IO.NavInputsDownDuration[n]; - if (t < 0.0f && mode == ImGuiInputReadMode_Released) // Return 1.0f when just released, no repeat, ignore analog input. - return (g.IO.NavInputsDownDurationPrev[n] >= 0.0f ? 1.0f : 0.0f); - if (t < 0.0f) - return 0.0f; - if (mode == ImGuiInputReadMode_Pressed) // Return 1.0f when just pressed, no repeat, ignore analog input. - return (t == 0.0f) ? 1.0f : 0.0f; - if (mode == ImGuiInputReadMode_Repeat) - return (float)CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, g.IO.KeyRepeatDelay * 0.72f, g.IO.KeyRepeatRate * 0.80f); - if (mode == ImGuiInputReadMode_RepeatSlow) - return (float)CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, g.IO.KeyRepeatDelay * 1.25f, g.IO.KeyRepeatRate * 2.00f); - if (mode == ImGuiInputReadMode_RepeatFast) - return (float)CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, g.IO.KeyRepeatDelay * 0.72f, g.IO.KeyRepeatRate * 0.30f); - return 0.0f; -} - -ImVec2 ImGui::GetNavInputAmount2d(ImGuiNavDirSourceFlags dir_sources, ImGuiInputReadMode mode, float slow_factor, float fast_factor) -{ - ImVec2 delta(0.0f, 0.0f); - if (dir_sources & ImGuiNavDirSourceFlags_RawKeyboard) - delta += ImVec2((float)IsKeyDown(GetKeyIndex(ImGuiKey_RightArrow)) - (float)IsKeyDown(GetKeyIndex(ImGuiKey_LeftArrow)), (float)IsKeyDown(GetKeyIndex(ImGuiKey_DownArrow)) - (float)IsKeyDown(GetKeyIndex(ImGuiKey_UpArrow))); - if (dir_sources & ImGuiNavDirSourceFlags_Keyboard) - delta += ImVec2(GetNavInputAmount(ImGuiNavInput_KeyRight_, mode) - GetNavInputAmount(ImGuiNavInput_KeyLeft_, mode), GetNavInputAmount(ImGuiNavInput_KeyDown_, mode) - GetNavInputAmount(ImGuiNavInput_KeyUp_, mode)); - if (dir_sources & ImGuiNavDirSourceFlags_PadDPad) - delta += ImVec2(GetNavInputAmount(ImGuiNavInput_DpadRight, mode) - GetNavInputAmount(ImGuiNavInput_DpadLeft, mode), GetNavInputAmount(ImGuiNavInput_DpadDown, mode) - GetNavInputAmount(ImGuiNavInput_DpadUp, mode)); - if (dir_sources & ImGuiNavDirSourceFlags_PadLStick) - delta += ImVec2(GetNavInputAmount(ImGuiNavInput_LStickRight, mode) - GetNavInputAmount(ImGuiNavInput_LStickLeft, mode), GetNavInputAmount(ImGuiNavInput_LStickDown, mode) - GetNavInputAmount(ImGuiNavInput_LStickUp, mode)); - if (slow_factor != 0.0f && IsNavInputDown(ImGuiNavInput_TweakSlow)) - delta *= slow_factor; - if (fast_factor != 0.0f && IsNavInputDown(ImGuiNavInput_TweakFast)) - delta *= fast_factor; - return delta; + ImGuiKey key_less, key_more; + if (g.NavInputSource == ImGuiInputSource_Gamepad) + { + key_less = (axis == ImGuiAxis_X) ? ImGuiKey_GamepadDpadLeft : ImGuiKey_GamepadDpadUp; + key_more = (axis == ImGuiAxis_X) ? ImGuiKey_GamepadDpadRight : ImGuiKey_GamepadDpadDown; + } + else + { + key_less = (axis == ImGuiAxis_X) ? ImGuiKey_LeftArrow : ImGuiKey_UpArrow; + key_more = (axis == ImGuiAxis_X) ? ImGuiKey_RightArrow : ImGuiKey_DownArrow; + } + float amount = (float)GetKeyPressedAmount(key_more, repeat_delay, repeat_rate) - (float)GetKeyPressedAmount(key_less, repeat_delay, repeat_rate); + if (amount != 0.0f && IsKeyDown(key_less) && IsKeyDown(key_more)) // Cancel when opposite directions are held, regardless of repeat phase + amount = 0.0f; + return amount; } static void ImGui::NavUpdate() @@ -10212,39 +10907,26 @@ static void ImGui::NavUpdate() ImGuiIO& io = g.IO; io.WantSetMousePos = false; - //if (g.NavScoringDebugCount > 0) IMGUI_DEBUG_LOG("NavScoringDebugCount %d for '%s' layer %d (Init:%d, Move:%d)\n", g.NavScoringDebugCount, g.NavWindow ? g.NavWindow->Name : "NULL", g.NavLayer, g.NavInitRequest || g.NavInitResultId != 0, g.NavMoveRequest); + //if (g.NavScoringDebugCount > 0) IMGUI_DEBUG_LOG_NAV("[nav] NavScoringDebugCount %d for '%s' layer %d (Init:%d, Move:%d)\n", g.NavScoringDebugCount, g.NavWindow ? g.NavWindow->Name : "NULL", g.NavLayer, g.NavInitRequest || g.NavInitResultId != 0, g.NavMoveRequest); - // Set input source as Gamepad when buttons are pressed (as some features differs when used with Gamepad vs Keyboard) - // (do it before we map Keyboard input!) - const bool nav_keyboard_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0; + // Set input source based on which keys are last pressed (as some features differs when used with Gamepad vs Keyboard) + // FIXME-NAV: Now that keys are separated maybe we can get rid of NavInputSource? const bool nav_gamepad_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (io.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0; - if (nav_gamepad_active && g.NavInputSource != ImGuiInputSource_Gamepad) - { - if (io.NavInputs[ImGuiNavInput_Activate] > 0.0f || io.NavInputs[ImGuiNavInput_Input] > 0.0f || io.NavInputs[ImGuiNavInput_Cancel] > 0.0f || io.NavInputs[ImGuiNavInput_Menu] > 0.0f - || io.NavInputs[ImGuiNavInput_DpadLeft] > 0.0f || io.NavInputs[ImGuiNavInput_DpadRight] > 0.0f || io.NavInputs[ImGuiNavInput_DpadUp] > 0.0f || io.NavInputs[ImGuiNavInput_DpadDown] > 0.0f) - g.NavInputSource = ImGuiInputSource_Gamepad; - } - - // Update Keyboard->Nav inputs mapping + const ImGuiKey nav_gamepad_keys_to_change_source[] = { ImGuiKey_GamepadFaceRight, ImGuiKey_GamepadFaceLeft, ImGuiKey_GamepadFaceUp, ImGuiKey_GamepadFaceDown, ImGuiKey_GamepadDpadRight, ImGuiKey_GamepadDpadLeft, ImGuiKey_GamepadDpadUp, ImGuiKey_GamepadDpadDown }; + if (nav_gamepad_active) + for (ImGuiKey key : nav_gamepad_keys_to_change_source) + if (IsKeyDown(key)) + g.NavInputSource = ImGuiInputSource_Gamepad; + const bool nav_keyboard_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0; + const ImGuiKey nav_keyboard_keys_to_change_source[] = { ImGuiKey_Space, ImGuiKey_Enter, ImGuiKey_Escape, ImGuiKey_RightArrow, ImGuiKey_LeftArrow, ImGuiKey_UpArrow, ImGuiKey_DownArrow }; if (nav_keyboard_active) - { - #define NAV_MAP_KEY(_KEY, _NAV_INPUT) do { if (IsKeyDown(io.KeyMap[_KEY])) { io.NavInputs[_NAV_INPUT] = 1.0f; g.NavInputSource = ImGuiInputSource_Keyboard; } } while (0) - NAV_MAP_KEY(ImGuiKey_Space, ImGuiNavInput_Activate ); - NAV_MAP_KEY(ImGuiKey_Enter, ImGuiNavInput_Input ); - NAV_MAP_KEY(ImGuiKey_Escape, ImGuiNavInput_Cancel ); - NAV_MAP_KEY(ImGuiKey_LeftArrow, ImGuiNavInput_KeyLeft_ ); - NAV_MAP_KEY(ImGuiKey_RightArrow,ImGuiNavInput_KeyRight_); - NAV_MAP_KEY(ImGuiKey_UpArrow, ImGuiNavInput_KeyUp_ ); - NAV_MAP_KEY(ImGuiKey_DownArrow, ImGuiNavInput_KeyDown_ ); - if (io.KeyCtrl) - io.NavInputs[ImGuiNavInput_TweakSlow] = 1.0f; - if (io.KeyShift) - io.NavInputs[ImGuiNavInput_TweakFast] = 1.0f; - #undef NAV_MAP_KEY - } - memcpy(io.NavInputsDownDurationPrev, io.NavInputsDownDuration, sizeof(io.NavInputsDownDuration)); - for (int i = 0; i < IM_ARRAYSIZE(io.NavInputs); i++) - io.NavInputsDownDuration[i] = (io.NavInputs[i] > 0.0f) ? (io.NavInputsDownDuration[i] < 0.0f ? 0.0f : io.NavInputsDownDuration[i] + io.DeltaTime) : -1.0f; + for (ImGuiKey key : nav_keyboard_keys_to_change_source) + if (IsKeyDown(key)) + g.NavInputSource = ImGuiInputSource_Keyboard; + if (!nav_gamepad_active && g.NavInputSource == ImGuiInputSource_Gamepad) + g.NavInputSource = ImGuiInputSource_None; + if (!nav_keyboard_active && g.NavInputSource == ImGuiInputSource_Keyboard) + g.NavInputSource = ImGuiInputSource_None; // Process navigation init request (select first/default focus) if (g.NavInitResultId != 0) @@ -10289,10 +10971,10 @@ static void ImGui::NavUpdate() g.NavActivateFlags = ImGuiActivateFlags_None; if (g.NavId != 0 && !g.NavDisableHighlight && !g.NavWindowingTarget && g.NavWindow && !(g.NavWindow->Flags & ImGuiWindowFlags_NoNavInputs)) { - bool activate_down = IsNavInputDown(ImGuiNavInput_Activate); - bool input_down = IsNavInputDown(ImGuiNavInput_Input); - bool activate_pressed = activate_down && IsNavInputTest(ImGuiNavInput_Activate, ImGuiInputReadMode_Pressed); - bool input_pressed = input_down && IsNavInputTest(ImGuiNavInput_Input, ImGuiInputReadMode_Pressed); + const bool activate_down = (nav_keyboard_active && IsKeyDown(ImGuiKey_Space)) || (nav_gamepad_active && IsKeyDown(ImGuiKey_NavGamepadActivate)); + const bool activate_pressed = activate_down && ((nav_keyboard_active && IsKeyPressed(ImGuiKey_Space, false)) || (nav_gamepad_active && IsKeyPressed(ImGuiKey_NavGamepadActivate, false))); + const bool input_down = (nav_keyboard_active && IsKeyDown(ImGuiKey_Enter)) || (nav_gamepad_active && IsKeyDown(ImGuiKey_NavGamepadInput)); + const bool input_pressed = input_down && ((nav_keyboard_active && IsKeyPressed(ImGuiKey_Enter, false)) || (nav_gamepad_active && IsKeyPressed(ImGuiKey_NavGamepadInput, false))); if (g.ActiveId == 0 && activate_pressed) { g.NavActivateId = g.NavId; @@ -10347,13 +11029,17 @@ static void ImGui::NavUpdate() SetScrollY(window, ImFloor(window->Scroll.y + ((move_dir == ImGuiDir_Up) ? -1.0f : +1.0f) * scroll_speed)); } - // *Normal* Manual scroll with NavScrollXXX keys + // *Normal* Manual scroll with LStick // Next movement request will clamp the NavId reference rectangle to the visible area, so navigation will resume within those bounds. - ImVec2 scroll_dir = GetNavInputAmount2d(ImGuiNavDirSourceFlags_PadLStick, ImGuiInputReadMode_Down, 1.0f / 10.0f, 10.0f); - if (scroll_dir.x != 0.0f && window->ScrollbarX) - SetScrollX(window, ImFloor(window->Scroll.x + scroll_dir.x * scroll_speed)); - if (scroll_dir.y != 0.0f) - SetScrollY(window, ImFloor(window->Scroll.y + scroll_dir.y * scroll_speed)); + if (nav_gamepad_active) + { + const ImVec2 scroll_dir = GetKeyVector2d(ImGuiKey_GamepadLStickLeft, ImGuiKey_GamepadLStickRight, ImGuiKey_GamepadLStickUp, ImGuiKey_GamepadLStickDown); + const float tweak_factor = IsKeyDown(ImGuiKey_NavGamepadTweakSlow) ? 1.0f / 10.0f : IsKeyDown(ImGuiKey_NavGamepadTweakFast) ? 10.0f : 1.0f; + if (scroll_dir.x != 0.0f && window->ScrollbarX) + SetScrollX(window, ImFloor(window->Scroll.x + scroll_dir.x * scroll_speed * tweak_factor)); + if (scroll_dir.y != 0.0f) + SetScrollY(window, ImFloor(window->Scroll.y + scroll_dir.y * scroll_speed * tweak_factor)); + } } // Always prioritize mouse highlight if navigation is disabled @@ -10369,7 +11055,7 @@ static void ImGui::NavUpdate() { io.MousePos = io.MousePosPrev = NavCalcPreferredRefPos(); io.WantSetMousePos = true; - //IMGUI_DEBUG_LOG("SetMousePos: (%.1f,%.1f)\n", io.MousePos.x, io.MousePos.y); + //IMGUI_DEBUG_LOG_IO("SetMousePos: (%.1f,%.1f)\n", io.MousePos.x, io.MousePos.y); } // [DEBUG] @@ -10393,7 +11079,7 @@ void ImGui::NavInitRequestApplyResult() // Apply result from previous navigation init request (will typically select the first item, unless SetItemDefaultFocus() has been called) // FIXME-NAV: On _NavFlattened windows, g.NavWindow will only be updated during subsequent frame. Not a problem currently. - IMGUI_DEBUG_LOG_NAV("[nav] NavInitRequest: result NavID 0x%08X in Layer %d Window \"%s\"\n", g.NavInitResultId, g.NavLayer, g.NavWindow->Name); + IMGUI_DEBUG_LOG_NAV("[nav] NavInitRequest: ApplyResult: NavID 0x%08X in Layer %d Window \"%s\"\n", g.NavInitResultId, g.NavLayer, g.NavWindow->Name); SetNavID(g.NavInitResultId, g.NavLayer, 0, g.NavInitResultRectRel); g.NavIdIsAlive = true; // Mark as alive from previous frame as we got a result if (g.NavInitRequestFromMove) @@ -10405,6 +11091,8 @@ void ImGui::NavUpdateCreateMoveRequest() ImGuiContext& g = *GImGui; ImGuiIO& io = g.IO; ImGuiWindow* window = g.NavWindow; + const bool nav_gamepad_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (io.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0; + const bool nav_keyboard_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0; if (g.NavMoveForwardToNextFrame && window != NULL) { @@ -10422,11 +11110,11 @@ void ImGui::NavUpdateCreateMoveRequest() g.NavMoveScrollFlags = ImGuiScrollFlags_None; if (window && !g.NavWindowingTarget && !(window->Flags & ImGuiWindowFlags_NoNavInputs)) { - const ImGuiInputReadMode read_mode = ImGuiInputReadMode_Repeat; - if (!IsActiveIdUsingNavDir(ImGuiDir_Left) && (IsNavInputTest(ImGuiNavInput_DpadLeft, read_mode) || IsNavInputTest(ImGuiNavInput_KeyLeft_, read_mode))) { g.NavMoveDir = ImGuiDir_Left; } - if (!IsActiveIdUsingNavDir(ImGuiDir_Right) && (IsNavInputTest(ImGuiNavInput_DpadRight, read_mode) || IsNavInputTest(ImGuiNavInput_KeyRight_, read_mode))) { g.NavMoveDir = ImGuiDir_Right; } - if (!IsActiveIdUsingNavDir(ImGuiDir_Up) && (IsNavInputTest(ImGuiNavInput_DpadUp, read_mode) || IsNavInputTest(ImGuiNavInput_KeyUp_, read_mode))) { g.NavMoveDir = ImGuiDir_Up; } - if (!IsActiveIdUsingNavDir(ImGuiDir_Down) && (IsNavInputTest(ImGuiNavInput_DpadDown, read_mode) || IsNavInputTest(ImGuiNavInput_KeyDown_, read_mode))) { g.NavMoveDir = ImGuiDir_Down; } + const ImGuiInputFlags repeat_mode = ImGuiInputFlags_Repeat | ImGuiInputFlags_RepeatRateNavMove; + if (!IsActiveIdUsingNavDir(ImGuiDir_Left) && ((nav_gamepad_active && IsKeyPressedEx(ImGuiKey_GamepadDpadLeft, repeat_mode)) || (nav_keyboard_active && IsKeyPressedEx(ImGuiKey_LeftArrow, repeat_mode)))) { g.NavMoveDir = ImGuiDir_Left; } + if (!IsActiveIdUsingNavDir(ImGuiDir_Right) && ((nav_gamepad_active && IsKeyPressedEx(ImGuiKey_GamepadDpadRight, repeat_mode)) || (nav_keyboard_active && IsKeyPressedEx(ImGuiKey_RightArrow, repeat_mode)))) { g.NavMoveDir = ImGuiDir_Right; } + if (!IsActiveIdUsingNavDir(ImGuiDir_Up) && ((nav_gamepad_active && IsKeyPressedEx(ImGuiKey_GamepadDpadUp, repeat_mode)) || (nav_keyboard_active && IsKeyPressedEx(ImGuiKey_UpArrow, repeat_mode)))) { g.NavMoveDir = ImGuiDir_Up; } + if (!IsActiveIdUsingNavDir(ImGuiDir_Down) && ((nav_gamepad_active && IsKeyPressedEx(ImGuiKey_GamepadDpadDown, repeat_mode)) || (nav_keyboard_active && IsKeyPressedEx(ImGuiKey_DownArrow, repeat_mode)))) { g.NavMoveDir = ImGuiDir_Down; } } g.NavMoveClipDir = g.NavMoveDir; g.NavScoringNoClipRect = ImRect(+FLT_MAX, +FLT_MAX, -FLT_MAX, -FLT_MAX); @@ -10434,7 +11122,6 @@ void ImGui::NavUpdateCreateMoveRequest() // Update PageUp/PageDown/Home/End scroll // FIXME-NAV: Consider enabling those keys even without the master ImGuiConfigFlags_NavEnableKeyboard flag? - const bool nav_keyboard_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0; float scoring_rect_offset_y = 0.0f; if (window && g.NavMoveDir == ImGuiDir_None && nav_keyboard_active) scoring_rect_offset_y = NavUpdatePageUpPageDown(); @@ -10446,7 +11133,7 @@ void ImGui::NavUpdateCreateMoveRequest() // [DEBUG] Always send a request #if IMGUI_DEBUG_NAV_SCORING - if (io.KeyCtrl && IsKeyPressedMap(ImGuiKey_C)) + if (io.KeyCtrl && IsKeyPressed(ImGuiKey_C)) g.NavMoveDirForDebug = (ImGuiDir)((g.NavMoveDirForDebug + 1) & 3); if (io.KeyCtrl && g.NavMoveDir == ImGuiDir_None) { @@ -10463,7 +11150,7 @@ void ImGui::NavUpdateCreateMoveRequest() // Moving with no reference triggers a init request (will be used as a fallback if the direction fails to find a match) if (g.NavMoveSubmitted && g.NavId == 0) { - IMGUI_DEBUG_LOG_NAV("[nav] NavInitRequest: from move, window \"%s\", layer=%d\n", g.NavWindow->Name, g.NavLayer); + IMGUI_DEBUG_LOG_NAV("[nav] NavInitRequest: from move, window \"%s\", layer=%d\n", window ? window->Name : "", g.NavLayer); g.NavInitRequest = g.NavInitRequestFromMove = true; g.NavInitResultId = 0; g.NavDisableHighlight = false; @@ -10472,15 +11159,21 @@ void ImGui::NavUpdateCreateMoveRequest() // When using gamepad, we project the reference nav bounding box into window visible area. // This is to allow resuming navigation inside the visible area after doing a large amount of scrolling, since with gamepad every movements are relative // (can't focus a visible object like we can with the mouse). - if (g.NavMoveSubmitted && g.NavInputSource == ImGuiInputSource_Gamepad && g.NavLayer == ImGuiNavLayer_Main && window != NULL) + if (g.NavMoveSubmitted && g.NavInputSource == ImGuiInputSource_Gamepad && g.NavLayer == ImGuiNavLayer_Main && window != NULL)// && (g.NavMoveFlags & ImGuiNavMoveFlags_Forwarded)) { - ImRect window_rect_rel = WindowRectAbsToRel(window, ImRect(window->InnerRect.Min - ImVec2(1, 1), window->InnerRect.Max + ImVec2(1, 1))); - if (!window_rect_rel.Contains(window->NavRectRel[g.NavLayer])) + bool clamp_x = (g.NavMoveFlags & (ImGuiNavMoveFlags_LoopX | ImGuiNavMoveFlags_WrapX)) == 0; + bool clamp_y = (g.NavMoveFlags & (ImGuiNavMoveFlags_LoopY | ImGuiNavMoveFlags_WrapY)) == 0; + ImRect inner_rect_rel = WindowRectAbsToRel(window, ImRect(window->InnerRect.Min - ImVec2(1, 1), window->InnerRect.Max + ImVec2(1, 1))); + if ((clamp_x || clamp_y) && !inner_rect_rel.Contains(window->NavRectRel[g.NavLayer])) { - IMGUI_DEBUG_LOG_NAV("[nav] NavMoveRequest: clamp NavRectRel\n"); - float pad = window->CalcFontSize() * 0.5f; - window_rect_rel.Expand(ImVec2(-ImMin(window_rect_rel.GetWidth(), pad), -ImMin(window_rect_rel.GetHeight(), pad))); // Terrible approximation for the intent of starting navigation from first fully visible item - window->NavRectRel[g.NavLayer].ClipWithFull(window_rect_rel); + //IMGUI_DEBUG_LOG_NAV("[nav] NavMoveRequest: clamp NavRectRel for gamepad move\n"); + float pad_x = ImMin(inner_rect_rel.GetWidth(), window->CalcFontSize() * 0.5f); + float pad_y = ImMin(inner_rect_rel.GetHeight(), window->CalcFontSize() * 0.5f); // Terrible approximation for the intent of starting navigation from first fully visible item + inner_rect_rel.Min.x = clamp_x ? (inner_rect_rel.Min.x + pad_x) : -FLT_MAX; + inner_rect_rel.Max.x = clamp_x ? (inner_rect_rel.Max.x - pad_x) : +FLT_MAX; + inner_rect_rel.Min.y = clamp_y ? (inner_rect_rel.Min.y + pad_y) : -FLT_MAX; + inner_rect_rel.Max.y = clamp_y ? (inner_rect_rel.Max.y - pad_y) : +FLT_MAX; + window->NavRectRel[g.NavLayer].ClipWithFull(inner_rect_rel); g.NavId = g.NavFocusScopeId = 0; } } @@ -10510,7 +11203,7 @@ void ImGui::NavUpdateCreateTabbingRequest() if (window == NULL || g.NavWindowingTarget != NULL || (window->Flags & ImGuiWindowFlags_NoNavInputs)) return; - const bool tab_pressed = IsKeyPressedMap(ImGuiKey_Tab, true) && !IsActiveIdUsingKey(ImGuiKey_Tab) && !g.IO.KeyCtrl && !g.IO.KeyAlt; + const bool tab_pressed = IsKeyPressed(ImGuiKey_Tab, true) && !IsActiveIdUsingKey(ImGuiKey_Tab) && !g.IO.KeyCtrl && !g.IO.KeyAlt; if (!tab_pressed) return; @@ -10523,7 +11216,6 @@ void ImGui::NavUpdateCreateTabbingRequest() ImGuiScrollFlags scroll_flags = window->Appearing ? ImGuiScrollFlags_KeepVisibleEdgeX | ImGuiScrollFlags_AlwaysCenterY : ImGuiScrollFlags_KeepVisibleEdgeX | ImGuiScrollFlags_KeepVisibleEdgeY; ImGuiDir clip_dir = (g.NavTabbingDir < 0) ? ImGuiDir_Up : ImGuiDir_Down; NavMoveRequestSubmit(ImGuiDir_None, clip_dir, ImGuiNavMoveFlags_Tabbing, scroll_flags); // FIXME-NAV: Once we refactor tabbing, add LegacyApi flag to not activate non-inputable. - g.NavTabbingResultFirst.Clear(); g.NavTabbingCounter = -1; } @@ -10581,7 +11273,11 @@ void ImGui::NavMoveRequestApplyResult() } } - g.NavWindow = result->Window; + if (g.NavWindow != result->Window) + { + IMGUI_DEBUG_LOG_FOCUS("[focus] NavMoveRequest: SetNavWindow(\"%s\")\n", result->Window->Name); + g.NavWindow = result->Window; + } if (g.ActiveId != result->ID) ClearActiveID(); if (g.NavId != result->ID) @@ -10623,13 +11319,15 @@ void ImGui::NavMoveRequestApplyResult() static void ImGui::NavUpdateCancelRequest() { ImGuiContext& g = *GImGui; - if (!IsNavInputTest(ImGuiNavInput_Cancel, ImGuiInputReadMode_Pressed)) + const bool nav_gamepad_active = (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (g.IO.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0; + const bool nav_keyboard_active = (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0; + if (!(nav_keyboard_active && IsKeyPressed(ImGuiKey_Escape, false)) && !(nav_gamepad_active && IsKeyPressed(ImGuiKey_NavGamepadCancel, false))) return; - IMGUI_DEBUG_LOG_NAV("[nav] ImGuiNavInput_Cancel\n"); + IMGUI_DEBUG_LOG_NAV("[nav] NavUpdateCancelRequest()\n"); if (g.ActiveId != 0) { - if (!IsActiveIdUsingNavInput(ImGuiNavInput_Cancel)) + if (!IsActiveIdUsingKey(ImGuiKey_Escape) && !IsActiveIdUsingKey(ImGuiKey_NavGamepadCancel)) ClearActiveID(); } else if (g.NavLayer != ImGuiNavLayer_Main) @@ -10649,11 +11347,10 @@ static void ImGui::NavUpdateCancelRequest() SetNavID(child_window->ChildId, ImGuiNavLayer_Main, 0, WindowRectAbsToRel(parent_window, child_rect)); NavRestoreHighlightAfterMove(); } - else if (g.OpenPopupStack.Size > 0) + else if (g.OpenPopupStack.Size > 0 && !(g.OpenPopupStack.back().Window->Flags & ImGuiWindowFlags_Modal)) { // Close open popup/menu - if (!(g.OpenPopupStack.back().Window->Flags & ImGuiWindowFlags_Modal)) - ClosePopupToLevel(g.OpenPopupStack.Size - 1, true); + ClosePopupToLevel(g.OpenPopupStack.Size - 1, true); } else { @@ -10671,16 +11368,14 @@ static void ImGui::NavUpdateCancelRequest() static float ImGui::NavUpdatePageUpPageDown() { ImGuiContext& g = *GImGui; - ImGuiIO& io = g.IO; - ImGuiWindow* window = g.NavWindow; if ((window->Flags & ImGuiWindowFlags_NoNavInputs) || g.NavWindowingTarget != NULL) return 0.0f; - const bool page_up_held = IsKeyDown(io.KeyMap[ImGuiKey_PageUp]) && !IsActiveIdUsingKey(ImGuiKey_PageUp); - const bool page_down_held = IsKeyDown(io.KeyMap[ImGuiKey_PageDown]) && !IsActiveIdUsingKey(ImGuiKey_PageDown); - const bool home_pressed = IsKeyPressed(io.KeyMap[ImGuiKey_Home]) && !IsActiveIdUsingKey(ImGuiKey_Home); - const bool end_pressed = IsKeyPressed(io.KeyMap[ImGuiKey_End]) && !IsActiveIdUsingKey(ImGuiKey_End); + const bool page_up_held = IsKeyDown(ImGuiKey_PageUp) && !IsActiveIdUsingKey(ImGuiKey_PageUp); + const bool page_down_held = IsKeyDown(ImGuiKey_PageDown) && !IsActiveIdUsingKey(ImGuiKey_PageDown); + const bool home_pressed = IsKeyPressed(ImGuiKey_Home) && !IsActiveIdUsingKey(ImGuiKey_Home); + const bool end_pressed = IsKeyPressed(ImGuiKey_End) && !IsActiveIdUsingKey(ImGuiKey_End); if (page_up_held == page_down_held && home_pressed == end_pressed) // Proceed if either (not both) are pressed, otherwise early out return 0.0f; @@ -10690,9 +11385,9 @@ static float ImGui::NavUpdatePageUpPageDown() if (window->DC.NavLayersActiveMask == 0x00 && window->DC.NavHasScroll) { // Fallback manual-scroll when window has no navigable item - if (IsKeyPressed(io.KeyMap[ImGuiKey_PageUp], true)) + if (IsKeyPressed(ImGuiKey_PageUp, true)) SetScrollY(window, window->Scroll.y - window->InnerRect.GetHeight()); - else if (IsKeyPressed(io.KeyMap[ImGuiKey_PageDown], true)) + else if (IsKeyPressed(ImGuiKey_PageDown, true)) SetScrollY(window, window->Scroll.y + window->InnerRect.GetHeight()); else if (home_pressed) SetScrollY(window, 0.0f); @@ -10704,14 +11399,14 @@ static float ImGui::NavUpdatePageUpPageDown() ImRect& nav_rect_rel = window->NavRectRel[g.NavLayer]; const float page_offset_y = ImMax(0.0f, window->InnerRect.GetHeight() - window->CalcFontSize() * 1.0f + nav_rect_rel.GetHeight()); float nav_scoring_rect_offset_y = 0.0f; - if (IsKeyPressed(io.KeyMap[ImGuiKey_PageUp], true)) + if (IsKeyPressed(ImGuiKey_PageUp, true)) { nav_scoring_rect_offset_y = -page_offset_y; g.NavMoveDir = ImGuiDir_Down; // Because our scoring rect is offset up, we request the down direction (so we can always land on the last item) g.NavMoveClipDir = ImGuiDir_Up; g.NavMoveFlags = ImGuiNavMoveFlags_AllowCurrentNavId | ImGuiNavMoveFlags_AlsoScoreVisibleSet; } - else if (IsKeyPressed(io.KeyMap[ImGuiKey_PageDown], true)) + else if (IsKeyPressed(ImGuiKey_PageDown, true)) { nav_scoring_rect_offset_y = +page_offset_y; g.NavMoveDir = ImGuiDir_Up; // Because our scoring rect is offset down, we request the up direction (so we can always land on the last item) @@ -10846,7 +11541,10 @@ static void NavUpdateWindowingHighlightWindow(int focus_change_dir) if (!window_target) window_target = FindWindowNavFocusable((focus_change_dir < 0) ? (g.WindowsFocusOrder.Size - 1) : 0, i_current, focus_change_dir); if (window_target) // Don't reset windowing target if there's a single window in the list + { g.NavWindowingTarget = g.NavWindowingTargetAnim = window_target; + g.NavWindowingAccumDeltaPos = g.NavWindowingAccumDeltaSize = ImVec2(0.0f, 0.0f); + } g.NavWindowingToggleLayer = false; } @@ -10875,13 +11573,16 @@ static void ImGui::NavUpdateWindowing() } // Start CTRL+Tab or Square+L/R window selection - const bool start_windowing_with_gamepad = allow_windowing && !g.NavWindowingTarget && IsNavInputTest(ImGuiNavInput_Menu, ImGuiInputReadMode_Pressed); - const bool start_windowing_with_keyboard = allow_windowing && !g.NavWindowingTarget && io.KeyCtrl && IsKeyPressedMap(ImGuiKey_Tab); + const bool nav_gamepad_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (io.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0; + const bool nav_keyboard_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0; + const bool start_windowing_with_gamepad = allow_windowing && nav_gamepad_active && !g.NavWindowingTarget && IsKeyPressed(ImGuiKey_NavGamepadMenu, false); + const bool start_windowing_with_keyboard = allow_windowing && nav_keyboard_active && !g.NavWindowingTarget && io.KeyCtrl && IsKeyPressed(ImGuiKey_Tab, false); if (start_windowing_with_gamepad || start_windowing_with_keyboard) if (ImGuiWindow* window = g.NavWindow ? g.NavWindow : FindWindowNavFocusable(g.WindowsFocusOrder.Size - 1, -INT_MAX, -1)) { g.NavWindowingTarget = g.NavWindowingTargetAnim = window->RootWindow; g.NavWindowingTimer = g.NavWindowingHighlightAlpha = 0.0f; + g.NavWindowingAccumDeltaPos = g.NavWindowingAccumDeltaSize = ImVec2(0.0f, 0.0f); g.NavWindowingToggleLayer = start_windowing_with_gamepad ? true : false; // Gamepad starts toggling layer g.NavInputSource = start_windowing_with_keyboard ? ImGuiInputSource_Keyboard : ImGuiInputSource_Gamepad; } @@ -10894,7 +11595,7 @@ static void ImGui::NavUpdateWindowing() g.NavWindowingHighlightAlpha = ImMax(g.NavWindowingHighlightAlpha, ImSaturate((g.NavWindowingTimer - NAV_WINDOWING_HIGHLIGHT_DELAY) / 0.05f)); // Select window to focus - const int focus_change_dir = (int)IsNavInputTest(ImGuiNavInput_FocusPrev, ImGuiInputReadMode_RepeatSlow) - (int)IsNavInputTest(ImGuiNavInput_FocusNext, ImGuiInputReadMode_RepeatSlow); + const int focus_change_dir = (int)IsKeyPressed(ImGuiKey_GamepadL1) - (int)IsKeyPressed(ImGuiKey_GamepadR1); if (focus_change_dir != 0) { NavUpdateWindowingHighlightWindow(focus_change_dir); @@ -10902,7 +11603,7 @@ static void ImGui::NavUpdateWindowing() } // Single press toggles NavLayer, long press with L/R apply actual focus on release (until then the window was merely rendered top-most) - if (!IsNavInputDown(ImGuiNavInput_Menu)) + if (!IsKeyDown(ImGuiKey_NavGamepadMenu)) { g.NavWindowingToggleLayer &= (g.NavWindowingHighlightAlpha < 1.0f); // Once button was held long enough we don't consider it a tap-to-toggle-layer press anymore. if (g.NavWindowingToggleLayer && g.NavWindow) @@ -10918,7 +11619,7 @@ static void ImGui::NavUpdateWindowing() { // Visuals only appears after a brief time after pressing TAB the first time, so that a fast CTRL+TAB doesn't add visual noise g.NavWindowingHighlightAlpha = ImMax(g.NavWindowingHighlightAlpha, ImSaturate((g.NavWindowingTimer - NAV_WINDOWING_HIGHLIGHT_DELAY) / 0.05f)); // 1.0f - if (IsKeyPressedMap(ImGuiKey_Tab, true)) + if (IsKeyPressed(ImGuiKey_Tab, true)) NavUpdateWindowingHighlightWindow(io.KeyShift ? +1 : -1); if (!io.KeyCtrl) apply_focus_window = g.NavWindowingTarget; @@ -10927,8 +11628,7 @@ static void ImGui::NavUpdateWindowing() // Keyboard: Press and Release ALT to toggle menu layer // - Testing that only Alt is tested prevents Alt+Shift or AltGR from toggling menu layer. // - AltGR is normally Alt+Ctrl but we can't reliably detect it (not all backends/systems/layout emit it as Alt+Ctrl). But even on keyboards without AltGR we don't want Alt+Ctrl to open menu anyway. - const bool nav_keyboard_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0; - if (nav_keyboard_active && io.KeyMods == ImGuiKeyModFlags_Alt && (io.KeyModsPrev & ImGuiKeyModFlags_Alt) == 0) + if (nav_keyboard_active && IsKeyPressed(ImGuiKey_ModAlt)) { g.NavWindowingToggleLayer = true; g.NavInputSource = ImGuiInputSource_Keyboard; @@ -10941,32 +11641,36 @@ static void ImGui::NavUpdateWindowing() g.NavWindowingToggleLayer = false; // Apply layer toggle on release - // Important: we don't assume that Alt was previously held in order to handle loss of focus when backend calls io.AddFocusEvent(false) // Important: as before version <18314 we lacked an explicit IO event for focus gain/loss, we also compare mouse validity to detect old backends clearing mouse pos on focus loss. - if (!(io.KeyMods & ImGuiKeyModFlags_Alt) && (io.KeyModsPrev & ImGuiKeyModFlags_Alt) && g.NavWindowingToggleLayer) + if (IsKeyReleased(ImGuiKey_ModAlt) && g.NavWindowingToggleLayer) if (g.ActiveId == 0 || g.ActiveIdAllowOverlap) if (IsMousePosValid(&io.MousePos) == IsMousePosValid(&io.MousePosPrev)) apply_toggle_layer = true; - if (!io.KeyAlt) + if (!IsKeyDown(ImGuiKey_ModAlt)) g.NavWindowingToggleLayer = false; } // Move window if (g.NavWindowingTarget && !(g.NavWindowingTarget->Flags & ImGuiWindowFlags_NoMove)) { - ImVec2 move_delta; + ImVec2 nav_move_dir; if (g.NavInputSource == ImGuiInputSource_Keyboard && !io.KeyShift) - move_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_RawKeyboard, ImGuiInputReadMode_Down); + nav_move_dir = GetKeyVector2d(ImGuiKey_LeftArrow, ImGuiKey_RightArrow, ImGuiKey_UpArrow, ImGuiKey_DownArrow); if (g.NavInputSource == ImGuiInputSource_Gamepad) - move_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_PadLStick, ImGuiInputReadMode_Down); - if (move_delta.x != 0.0f || move_delta.y != 0.0f) + nav_move_dir = GetKeyVector2d(ImGuiKey_GamepadLStickLeft, ImGuiKey_GamepadLStickRight, ImGuiKey_GamepadLStickUp, ImGuiKey_GamepadLStickDown); + if (nav_move_dir.x != 0.0f || nav_move_dir.y != 0.0f) { const float NAV_MOVE_SPEED = 800.0f; - const float move_speed = ImFloor(NAV_MOVE_SPEED * io.DeltaTime * ImMin(io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y)); // FIXME: Doesn't handle variable framerate very well - ImGuiWindow* moving_window = g.NavWindowingTarget->RootWindowDockTree; - SetWindowPos(moving_window, moving_window->Pos + move_delta * move_speed, ImGuiCond_Always); - MarkIniSettingsDirty(moving_window); + const float move_step = NAV_MOVE_SPEED * io.DeltaTime * ImMin(io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y); + g.NavWindowingAccumDeltaPos += nav_move_dir * move_step; g.NavDisableMouseHover = true; + ImVec2 accum_floored = ImFloor(g.NavWindowingAccumDeltaPos); + if (accum_floored.x != 0.0f || accum_floored.y != 0.0f) + { + ImGuiWindow* moving_window = g.NavWindowingTarget->RootWindowDockTree; + SetWindowPos(moving_window, moving_window->Pos + accum_floored, ImGuiCond_Always); + g.NavWindowingAccumDeltaPos -= accum_floored; + } } } @@ -11080,6 +11784,12 @@ void ImGui::NavUpdateWindowingOverlay() // [SECTION] DRAG AND DROP //----------------------------------------------------------------------------- +bool ImGui::IsDragDropActive() +{ + ImGuiContext& g = *GImGui; + return g.DragDropActive; +} + void ImGui::ClearDragDrop() { ImGuiContext& g = *GImGui; @@ -11149,6 +11859,7 @@ bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags) // We don't need to maintain/call ClearActiveID() as releasing the button will early out this function and trigger !ActiveIdIsAlive. // Rely on keeping other window->LastItemXXX fields intact. source_id = g.LastItemData.ID = window->GetIDFromRectangle(g.LastItemData.Rect); + KeepAliveID(source_id); bool is_hovered = ItemHoverable(g.LastItemData.Rect, source_id); if (is_hovered && g.IO.MouseClicked[mouse_button]) { @@ -11268,6 +11979,7 @@ bool ImGui::SetDragDropPayload(const char* type, const void* data, size_t data_s } payload.DataFrameCount = g.FrameCount; + // Return whether the payload has been accepted return (g.DragDropAcceptFrameCount == g.FrameCount) || (g.DragDropAcceptFrameCount == g.FrameCount - 1); } @@ -11314,7 +12026,10 @@ bool ImGui::BeginDragDropTarget() const ImRect& display_rect = (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_HasDisplayRect) ? g.LastItemData.DisplayRect : g.LastItemData.Rect; ImGuiID id = g.LastItemData.ID; if (id == 0) + { id = window->GetIDFromRectangle(display_rect); + KeepAliveID(id); + } if (g.DragDropPayload.SourceId == id) return false; @@ -11728,6 +12443,20 @@ ImGuiWindowSettings* ImGui::FindOrCreateWindowSettings(const char* name) return CreateNewWindowSettings(name); } +void ImGui::AddSettingsHandler(const ImGuiSettingsHandler* handler) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(FindSettingsHandler(handler->TypeName) == NULL); + g.SettingsHandlers.push_back(*handler); +} + +void ImGui::RemoveSettingsHandler(const char* type_name) +{ + ImGuiContext& g = *GImGui; + if (ImGuiSettingsHandler* handler = FindSettingsHandler(type_name)) + g.SettingsHandlers.erase(handler); +} + ImGuiSettingsHandler* ImGui::FindSettingsHandler(const char* type_name) { ImGuiContext& g = *GImGui; @@ -11753,7 +12482,8 @@ void ImGui::LoadIniSettingsFromDisk(const char* ini_filename) char* file_data = (char*)ImFileLoadToMemory(ini_filename, "rb", &file_data_size); if (!file_data) return; - LoadIniSettingsFromMemory(file_data, (size_t)file_data_size); + if (file_data_size > 0) + LoadIniSettingsFromMemory(file_data, (size_t)file_data_size); IM_FREE(file_data); } @@ -11955,6 +12685,7 @@ static void WindowSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl buf->appendf("Collapsed=%d\n", settings->Collapsed); if (settings->DockId != 0) { + //buf->appendf("TabId=0x%08X\n", ImHashStr("#TAB", 4, settings->ID)); // window->TabId: this is not read back but writing it makes "debugging" the .ini data easier. if (settings->DockOrder == -1) buf->appendf("DockId=0x%08X\n", settings->DockId); else @@ -12031,7 +12762,7 @@ void ImGui::SetCurrentViewport(ImGuiWindow* current_window, ImGuiViewportP* view return; g.CurrentDpiScale = viewport ? viewport->DpiScale : 1.0f; g.CurrentViewport = viewport; - //IMGUI_DEBUG_LOG_VIEWPORT("SetCurrentViewport changed '%s' 0x%08X\n", current_window ? current_window->Name : NULL, viewport ? viewport->ID : 0); + //IMGUI_DEBUG_LOG_VIEWPORT("[viewport] SetCurrentViewport changed '%s' 0x%08X\n", current_window ? current_window->Name : NULL, viewport ? viewport->ID : 0); // Notify platform layer of viewport changes // FIXME-DPI: This is only currently used for experimenting with handling of multiple DPI @@ -12039,7 +12770,7 @@ void ImGui::SetCurrentViewport(ImGuiWindow* current_window, ImGuiViewportP* view g.PlatformIO.Platform_OnChangedViewport(g.CurrentViewport); } -static void SetWindowViewport(ImGuiWindow* window, ImGuiViewportP* viewport) +void ImGui::SetWindowViewport(ImGuiWindow* window, ImGuiViewportP* viewport) { // Abandon viewport if (window->ViewportOwned && window->Viewport->Window == window) @@ -12146,7 +12877,7 @@ void ImGui::ScaleWindowsInViewport(ImGuiViewportP* viewport, float scale) // If the backend doesn't set MouseLastHoveredViewport or doesn't honor ImGuiViewportFlags_NoInputs, we do a search ourselves. // A) It won't take account of the possibility that non-imgui windows may be in-between our dragged window and our target window. // B) It requires Platform_GetWindowFocus to be implemented by backend. -static ImGuiViewportP* FindHoveredViewportFromPlatformWindowStack(const ImVec2 mouse_platform_pos) +ImGuiViewportP* ImGui::FindHoveredViewportFromPlatformWindowStack(const ImVec2& mouse_platform_pos) { ImGuiContext& g = *GImGui; ImGuiViewportP* best_candidate = NULL; @@ -12298,17 +13029,14 @@ static void ImGui::UpdateViewportsNewFrame() { viewport_hovered = g.IO.MouseHoveredViewport ? (ImGuiViewportP*)FindViewportByID(g.IO.MouseHoveredViewport) : NULL; if (viewport_hovered && (viewport_hovered->Flags & ImGuiViewportFlags_NoInputs)) - { - // Backend failed at honoring its contract if it returned a viewport with the _NoInputs flag. - IM_ASSERT(0); - viewport_hovered = FindHoveredViewportFromPlatformWindowStack(g.IO.MousePos); - } + viewport_hovered = FindHoveredViewportFromPlatformWindowStack(g.IO.MousePos); // Backend failed to handle _NoInputs viewport: revert to our fallback. } else { // If the backend doesn't know how to honor ImGuiViewportFlags_NoInputs, we do a search ourselves. Note that this search: // A) won't take account of the possibility that non-imgui windows may be in-between our dragged window and our target window. - // B) uses LastFrameAsRefViewport as a flawed replacement for the last time a window was focused (we could/should fix that by introducing Focus functions in PlatformIO) + // B) won't take account of how the backend apply parent<>child relationship to secondary viewports, which affects their Z order. + // C) uses LastFrameAsRefViewport as a flawed replacement for the last time a window was focused (we could/should fix that by introducing Focus functions in PlatformIO) viewport_hovered = FindHoveredViewportFromPlatformWindowStack(g.IO.MousePos); } if (viewport_hovered != NULL) @@ -12380,9 +13108,10 @@ ImGuiViewportP* ImGui::AddUpdateViewport(ImGuiWindow* window, ImGuiID id, const ImGuiViewportP* viewport = (ImGuiViewportP*)FindViewportByID(id); if (viewport) { - if (!viewport->PlatformRequestMove) + // Always update for main viewport as we are already pulling correct platform pos/size (see #4900) + if (!viewport->PlatformRequestMove || viewport->ID == IMGUI_VIEWPORT_DEFAULT_ID) viewport->Pos = pos; - if (!viewport->PlatformRequestResize) + if (!viewport->PlatformRequestResize || viewport->ID == IMGUI_VIEWPORT_DEFAULT_ID) viewport->Size = size; viewport->Flags = flags | (viewport->Flags & ImGuiViewportFlags_Minimized); // Preserve existing flags } @@ -12397,7 +13126,7 @@ ImGuiViewportP* ImGui::AddUpdateViewport(ImGuiWindow* window, ImGuiID id, const viewport->Flags = flags; UpdateViewportPlatformMonitor(viewport); g.Viewports.push_back(viewport); - IMGUI_DEBUG_LOG_VIEWPORT("Add Viewport %08X (%s)\n", id, window->Name); + IMGUI_DEBUG_LOG_VIEWPORT("[viewport] Add Viewport %08X '%s'\n", id, window ? window->Name : ""); // We normally setup for all viewports in NewFrame() but here need to handle the mid-frame creation of a new viewport. // We need to extend the fullscreen clip rect so the OverlayDrawList clip is correct for that the first frame @@ -12439,7 +13168,7 @@ static void ImGui::DestroyViewport(ImGuiViewportP* viewport) g.MouseLastHoveredViewport = NULL; // Destroy - IMGUI_DEBUG_LOG_VIEWPORT("Delete Viewport %08X (%s)\n", viewport->ID, viewport->Window ? viewport->Window->Name : "n/a"); + IMGUI_DEBUG_LOG_VIEWPORT("[viewport] Delete Viewport %08X '%s'\n", viewport->ID, viewport->Window ? viewport->Window->Name : "n/a"); DestroyPlatformWindow(viewport); // In most circumstances the platform window will already be destroyed here. IM_ASSERT(g.PlatformIO.Viewports.contains(viewport) == false); IM_ASSERT(g.Viewports[viewport->Idx] == viewport); @@ -12522,7 +13251,8 @@ static void ImGui::WindowSelectViewport(ImGuiWindow* window) { // Merge into host viewport? // We cannot test window->ViewportOwned as it set lower in the function. - bool try_to_merge_into_host_viewport = (window->Viewport && window == window->Viewport->Window && g.ActiveId == 0); + // Testing (g.ActiveId == 0 || g.ActiveIdAllowOverlap) to avoid merging during a short-term widget interaction. Main intent was to avoid during resize (see #4212) + bool try_to_merge_into_host_viewport = (window->Viewport && window == window->Viewport->Window && (g.ActiveId == 0 || g.ActiveIdAllowOverlap)); if (try_to_merge_into_host_viewport) UpdateTryMergeWindowIntoHostViewports(window); } @@ -12554,7 +13284,7 @@ static void ImGui::WindowSelectViewport(ImGuiWindow* window) if ((window->Flags & ImGuiWindowFlags_DockNodeHost) && window->Viewport->LastFrameActive < g.FrameCount && will_be_visible) { // Steal/transfer ownership - IMGUI_DEBUG_LOG_VIEWPORT("Window '%s' steal Viewport %08X from Window '%s'\n", window->Name, window->Viewport->ID, window->Viewport->Window->Name); + IMGUI_DEBUG_LOG_VIEWPORT("[viewport] Window '%s' steal Viewport %08X from Window '%s'\n", window->Name, window->Viewport->ID, window->Viewport->Window->Name); window->Viewport->Window = window; window->Viewport->ID = window->ID; window->Viewport->LastNameHash = 0; @@ -12704,7 +13434,7 @@ void ImGui::UpdatePlatformWindows() bool is_new_platform_window = (viewport->PlatformWindowCreated == false); if (is_new_platform_window) { - IMGUI_DEBUG_LOG_VIEWPORT("Create Platform Window %08X (%s)\n", viewport->ID, viewport->Window ? viewport->Window->Name : "n/a"); + IMGUI_DEBUG_LOG_VIEWPORT("[viewport] Create Platform Window %08X '%s'\n", viewport->ID, viewport->Window ? viewport->Window->Name : "n/a"); g.PlatformIO.Platform_CreateWindow(viewport); if (g.PlatformIO.Renderer_CreateWindow != NULL) g.PlatformIO.Renderer_CreateWindow(viewport); @@ -13077,7 +13807,6 @@ namespace ImGui static void DockContextProcessUndockWindow(ImGuiContext* ctx, ImGuiWindow* window, bool clear_persistent_docking_ref = true); static void DockContextProcessUndockNode(ImGuiContext* ctx, ImGuiDockNode* node); static void DockContextPruneUnusedSettingsNodes(ImGuiContext* ctx); - static ImGuiDockNode* DockContextFindNodeByID(ImGuiContext* ctx, ImGuiID id); static ImGuiDockNode* DockContextBindNodeToWindow(ImGuiContext* ctx, ImGuiWindow* window); static void DockContextBuildNodesFromSettings(ImGuiContext* ctx, ImGuiDockNodeSettings* node_settings_array, int node_settings_count); static void DockContextBuildAddWindowsToNodes(ImGuiContext* ctx, ImGuiID root_id); // Use root_id==0 to add all @@ -13193,8 +13922,9 @@ void ImGui::DockContextClearNodes(ImGuiContext* ctx, ImGuiID root_id, bool clear // (Different from DockSettingsHandler_ClearAll() + DockSettingsHandler_ApplyAll() because this reuses current settings!) void ImGui::DockContextRebuildNodes(ImGuiContext* ctx) { - IMGUI_DEBUG_LOG_DOCKING("DockContextRebuild()\n"); - ImGuiDockContext* dc = &ctx->DockContext; + ImGuiContext& g = *ctx; + ImGuiDockContext* dc = &ctx->DockContext; + IMGUI_DEBUG_LOG_DOCKING("[docking] DockContextRebuildNodes\n"); SaveIniSettingsToMemory(); ImGuiID root_id = 0; // Rebuild all DockContextClearNodes(ctx, root_id, false); @@ -13206,7 +13936,7 @@ void ImGui::DockContextRebuildNodes(ImGuiContext* ctx) void ImGui::DockContextNewFrameUpdateUndocking(ImGuiContext* ctx) { ImGuiContext& g = *ctx; - ImGuiDockContext* dc = &ctx->DockContext; + ImGuiDockContext* dc = &ctx->DockContext; if (!(g.IO.ConfigFlags & ImGuiConfigFlags_DockingEnable)) { if (dc->Nodes.Data.Size > 0 || dc->Requests.Size > 0) @@ -13291,12 +14021,12 @@ void ImGui::DockContextEndFrame(ImGuiContext* ctx) { ImRect bg_rect(node->Pos + ImVec2(0.0f, GetFrameHeight()), node->Pos + node->Size); ImDrawFlags bg_rounding_flags = CalcRoundingFlagsForRectInRect(bg_rect, node->HostWindow->Rect(), DOCKING_SPLITTER_SIZE); - node->HostWindow->DrawList->ChannelsSetCurrent(0); + node->HostWindow->DrawList->ChannelsSetCurrent(DOCKING_HOST_DRAW_CHANNEL_BG); node->HostWindow->DrawList->AddRectFilled(bg_rect.Min, bg_rect.Max, node->LastBgColor, node->HostWindow->WindowRounding, bg_rounding_flags); } } -static ImGuiDockNode* ImGui::DockContextFindNodeByID(ImGuiContext* ctx, ImGuiID id) +ImGuiDockNode* ImGui::DockContextFindNodeByID(ImGuiContext* ctx, ImGuiID id) { return (ImGuiDockNode*)ctx->DockContext.Nodes.GetVoidPtr(id); } @@ -13315,13 +14045,14 @@ ImGuiID ImGui::DockContextGenNodeID(ImGuiContext* ctx) static ImGuiDockNode* ImGui::DockContextAddNode(ImGuiContext* ctx, ImGuiID id) { // Generate an ID for the new node (the exact ID value doesn't matter as long as it is not already used) and add the first window. + ImGuiContext& g = *ctx; if (id == 0) id = DockContextGenNodeID(ctx); else IM_ASSERT(DockContextFindNodeByID(ctx, id) == NULL); // We don't set node->LastFrameAlive on construction. Nodes are always created at all time to reflect .ini settings! - IMGUI_DEBUG_LOG_DOCKING("DockContextAddNode 0x%08X\n", id); + IMGUI_DEBUG_LOG_DOCKING("[docking] DockContextAddNode 0x%08X\n", id); ImGuiDockNode* node = IM_NEW(ImGuiDockNode)(id); ctx->DockContext.Nodes.SetVoidPtr(node->ID, node); return node; @@ -13332,7 +14063,7 @@ static void ImGui::DockContextRemoveNode(ImGuiContext* ctx, ImGuiDockNode* node, ImGuiContext& g = *ctx; ImGuiDockContext* dc = &ctx->DockContext; - IMGUI_DEBUG_LOG_DOCKING("DockContextRemoveNode 0x%08X\n", node->ID); + IMGUI_DEBUG_LOG_DOCKING("[docking] DockContextRemoveNode 0x%08X\n", node->ID); IM_ASSERT(DockContextFindNodeByID(ctx, node->ID) == node); IM_ASSERT(node->ChildNodes[0] == NULL && node->ChildNodes[1] == NULL); IM_ASSERT(node->Windows.Size == 0); @@ -13431,7 +14162,7 @@ static void ImGui::DockContextPruneUnusedSettingsNodes(ImGuiContext* ctx) remove |= (data_root->CountChildWindows == 0); if (remove) { - IMGUI_DEBUG_LOG_DOCKING("DockContextPruneUnusedSettingsNodes: Prune 0x%08X\n", settings->ID); + IMGUI_DEBUG_LOG_DOCKING("[docking] DockContextPruneUnusedSettingsNodes: Prune 0x%08X\n", settings->ID); DockSettingsRemoveNodeReferences(&settings->ID, 1); settings->ID = 0; } @@ -13550,9 +14281,9 @@ void ImGui::DockContextProcessDock(ImGuiContext* ctx, ImGuiDockRequest* req) ImGuiWindow* target_window = req->DockTargetWindow; ImGuiDockNode* node = req->DockTargetNode; if (payload_window) - IMGUI_DEBUG_LOG_DOCKING("DockContextProcessDock node 0x%08X target '%s' dock window '%s', split_dir %d\n", node ? node->ID : 0, target_window ? target_window->Name : "NULL", payload_window ? payload_window->Name : "NULL", req->DockSplitDir); + IMGUI_DEBUG_LOG_DOCKING("[docking] DockContextProcessDock node 0x%08X target '%s' dock window '%s', split_dir %d\n", node ? node->ID : 0, target_window ? target_window->Name : "NULL", payload_window->Name, req->DockSplitDir); else - IMGUI_DEBUG_LOG_DOCKING("DockContextProcessDock node 0x%08X, split_dir %d\n", node ? node->ID : 0, req->DockSplitDir); + IMGUI_DEBUG_LOG_DOCKING("[docking] DockContextProcessDock node 0x%08X, split_dir %d\n", node ? node->ID : 0, req->DockSplitDir); // Decide which Tab will be selected at the end of the operation ImGuiID next_selected_id = 0; @@ -13564,7 +14295,7 @@ void ImGui::DockContextProcessDock(ImGuiContext* ctx, ImGuiDockRequest* req) if (payload_node && payload_node->IsLeafNode()) next_selected_id = payload_node->TabBar->NextSelectedTabId ? payload_node->TabBar->NextSelectedTabId : payload_node->TabBar->SelectedTabId; if (payload_node == NULL) - next_selected_id = payload_window->ID; + next_selected_id = payload_window->TabId; } // FIXME-DOCK: When we are trying to dock an existing single-window node into a loose window, transfer Node ID as well @@ -13701,8 +14432,8 @@ static ImVec2 FixLargeWindowsWhenUndocking(const ImVec2& size, ImGuiViewport* re void ImGui::DockContextProcessUndockWindow(ImGuiContext* ctx, ImGuiWindow* window, bool clear_persistent_docking_ref) { - IMGUI_DEBUG_LOG_DOCKING("DockContextProcessUndockWindow window '%s', clear_persistent_docking_ref = %d\n", window->Name, clear_persistent_docking_ref); - IM_UNUSED(ctx); + ImGuiContext& g = *ctx; + IMGUI_DEBUG_LOG_DOCKING("[docking] DockContextProcessUndockWindow window '%s', clear_persistent_docking_ref = %d\n", window->Name, clear_persistent_docking_ref); if (window->DockNode) DockNodeRemoveWindow(window->DockNode, window, clear_persistent_docking_ref ? 0 : window->DockId); else @@ -13717,7 +14448,8 @@ void ImGui::DockContextProcessUndockWindow(ImGuiContext* ctx, ImGuiWindow* windo void ImGui::DockContextProcessUndockNode(ImGuiContext* ctx, ImGuiDockNode* node) { - IMGUI_DEBUG_LOG_DOCKING("DockContextProcessUndockNode node %08X\n", node->ID); + ImGuiContext& g = *ctx; + IMGUI_DEBUG_LOG_DOCKING("[docking] DockContextProcessUndockNode node %08X\n", node->ID); IM_ASSERT(node->IsLeafNode()); IM_ASSERT(node->Windows.Size >= 1); @@ -13730,14 +14462,6 @@ void ImGui::DockContextProcessUndockNode(ImGuiContext* ctx, ImGuiDockNode* node) new_node->SizeRef = node->SizeRef; DockNodeMoveWindows(new_node, node); DockSettingsRenameNodeReferences(node->ID, new_node->ID); - for (int n = 0; n < new_node->Windows.Size; n++) - { - ImGuiWindow* window = new_node->Windows[n]; - window->Flags &= ~ImGuiWindowFlags_ChildWindow; - if (window->ParentWindow) - window->ParentWindow->DC.ChildWindows.find_erase(window); - UpdateWindowParentAndRootLinks(window, window->Flags, NULL); - } node = new_node; } else @@ -13750,6 +14474,14 @@ void ImGui::DockContextProcessUndockNode(ImGuiContext* ctx, ImGuiDockNode* node) node->ParentNode->AuthorityForViewport = ImGuiDataAuthority_Window; // The node that stays in place keeps the viewport, so our newly dragged out node will create a new viewport node->ParentNode = NULL; } + for (int n = 0; n < node->Windows.Size; n++) + { + ImGuiWindow* window = node->Windows[n]; + window->Flags &= ~ImGuiWindowFlags_ChildWindow; + if (window->ParentWindow) + window->ParentWindow->DC.ChildWindows.find_erase(window); + UpdateWindowParentAndRootLinks(window, window->Flags, NULL); + } node->AuthorityForPos = node->AuthorityForSize = ImGuiDataAuthority_DockNode; node->Size = FixLargeWindowsWhenUndocking(node->Size, node->Windows[0]->Viewport); node->WantMouseMove = true; @@ -13841,7 +14573,7 @@ int ImGui::DockNodeGetTabOrder(ImGuiWindow* window) ImGuiTabBar* tab_bar = window->DockNode->TabBar; if (tab_bar == NULL) return -1; - ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, window->ID); + ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, window->TabId); return tab ? tab_bar->GetTabOrder(tab) : -1; } @@ -13861,7 +14593,7 @@ static void ImGui::DockNodeAddWindow(ImGuiDockNode* node, ImGuiWindow* window, b DockNodeRemoveWindow(window->DockNode, window, 0); } IM_ASSERT(window->DockNode == NULL || window->DockNodeAsHost == NULL); - IMGUI_DEBUG_LOG_DOCKING("DockNodeAddWindow node 0x%08X window '%s'\n", node->ID, window->Name); + IMGUI_DEBUG_LOG_DOCKING("[docking] DockNodeAddWindow node 0x%08X window '%s'\n", node->ID, window->Name); // If more than 2 windows appeared on the same frame leading to the creation of a new hosting window, // we'll hide windows until the host window is ready. Hide the 1st window after its been output (so it is not visible for one frame). @@ -13917,7 +14649,7 @@ static void ImGui::DockNodeRemoveWindow(ImGuiDockNode* node, ImGuiWindow* window //IM_ASSERT(window->RootWindowDockTree == node->HostWindow); //IM_ASSERT(window->LastFrameActive < g.FrameCount); // We may call this from Begin() IM_ASSERT(save_dock_id == 0 || save_dock_id == node->ID); - IMGUI_DEBUG_LOG_DOCKING("DockNodeRemoveWindow node 0x%08X window '%s'\n", node->ID, window->Name); + IMGUI_DEBUG_LOG_DOCKING("[docking] DockNodeRemoveWindow node 0x%08X window '%s'\n", node->ID, window->Name); window->DockNode = NULL; window->DockIsActive = window->DockTabWantClose = false; @@ -13945,7 +14677,7 @@ static void ImGui::DockNodeRemoveWindow(ImGuiDockNode* node, ImGuiWindow* window node->WantHiddenTabBarUpdate = true; if (node->TabBar) { - TabBarRemoveTab(node->TabBar, window->ID); + TabBarRemoveTab(node->TabBar, window->TabId); const int tab_count_threshold_for_tab_bar = node->IsCentralNode() ? 1 : 2; if (node->Windows.Size < tab_count_threshold_for_tab_bar) DockNodeRemoveTabBar(node); @@ -13964,7 +14696,7 @@ static void ImGui::DockNodeRemoveWindow(ImGuiDockNode* node, ImGuiWindow* window if (node->HostWindow->ViewportOwned && node->IsRootNode()) { // Transfer viewport back to the remaining loose window - IMGUI_DEBUG_LOG_VIEWPORT("Node %08X transfer Viewport %08X=>%08X for Window '%s'\n", node->ID, node->HostWindow->Viewport->ID, remaining_window->ID, remaining_window->Name); + IMGUI_DEBUG_LOG_VIEWPORT("[viewport] Node %08X transfer Viewport %08X=>%08X for Window '%s'\n", node->ID, node->HostWindow->Viewport->ID, remaining_window->ID, remaining_window->Name); IM_ASSERT(node->HostWindow->Viewport->Window == node->HostWindow); node->HostWindow->Viewport->Window = remaining_window; node->HostWindow->Viewport->ID = remaining_window->ID; @@ -14006,10 +14738,14 @@ static void ImGui::DockNodeMoveWindows(ImGuiDockNode* dst_node, ImGuiDockNode* s src_node->TabBar = NULL; } - for (int n = 0; n < src_node->Windows.Size; n++) + for (int n_from_node = 0, n_from_tab_bar = 0; n_from_node < src_node->Windows.Size; n_from_node++, n_from_tab_bar++) { // DockNode's TabBar may have non-window Tabs manually appended by user - if (ImGuiWindow* window = src_tab_bar ? src_tab_bar->Tabs[n].Window : src_node->Windows[n]) + while (src_tab_bar && src_tab_bar->Tabs[n_from_tab_bar].Window == NULL) + n_from_tab_bar++; + + // Using TabBar order (FIXME: Why? Clarify + add tests for it) + if (ImGuiWindow* window = src_tab_bar ? src_tab_bar->Tabs[n_from_tab_bar].Window : src_node->Windows[n_from_node]) { window->DockNode = NULL; window->DockIsActive = false; @@ -14128,7 +14864,7 @@ static void ImGui::DockNodeUpdateFlagsAndCollapse(ImGuiDockNode* node) bool node_was_active = (node->LastFrameActive + 1 == g.FrameCount); bool remove = false; remove |= node_was_active && (window->LastFrameActive + 1 < g.FrameCount); - remove |= node_was_active && (node->WantCloseAll || node->WantCloseTabId == window->ID) && window->HasCloseButton && !(window->Flags & ImGuiWindowFlags_UnsavedDocument); // Submit all _expected_ closure from last frame + remove |= node_was_active && (node->WantCloseAll || node->WantCloseTabId == window->TabId) && window->HasCloseButton && !(window->Flags & ImGuiWindowFlags_UnsavedDocument); // Submit all _expected_ closure from last frame remove |= (window->DockTabWantClose); if (remove) { @@ -14474,14 +15210,14 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node) if (central_node_hole && !hole_rect.IsInverted()) { SetWindowHitTestHole(host_window, hole_rect.Min, hole_rect.Max - hole_rect.Min); - SetWindowHitTestHole(host_window->ParentWindow, hole_rect.Min, hole_rect.Max - hole_rect.Min); + if (host_window->ParentWindow) + SetWindowHitTestHole(host_window->ParentWindow, hole_rect.Min, hole_rect.Max - hole_rect.Min); } } // Update position/size, process and draw resizing splitters if (node->IsRootNode() && host_window) { - host_window->DrawList->ChannelsSetCurrent(1); DockNodeTreeUpdatePosSize(node, host_window->Pos, host_window->Size); DockNodeTreeUpdateSplitter(node); } @@ -14489,7 +15225,7 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node) // Draw empty node background (currently can only be the Central Node) if (host_window && node->IsEmpty() && node->IsVisible) { - host_window->DrawList->ChannelsSetCurrent(0); + host_window->DrawList->ChannelsSetCurrent(DOCKING_HOST_DRAW_CHANNEL_BG); node->LastBgColor = (node_flags & ImGuiDockNodeFlags_PassthruCentralNode) ? 0 : GetColorU32(ImGuiCol_DockingEmptyBg); if (node->LastBgColor != 0) host_window->DrawList->AddRectFilled(node->Pos, node->Pos + node->Size, node->LastBgColor); @@ -14502,7 +15238,7 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node) const bool render_dockspace_bg = node->IsRootNode() && host_window && (node_flags & ImGuiDockNodeFlags_PassthruCentralNode) != 0; if (render_dockspace_bg && node->IsVisible) { - host_window->DrawList->ChannelsSetCurrent(0); + host_window->DrawList->ChannelsSetCurrent(DOCKING_HOST_DRAW_CHANNEL_BG); if (central_node_hole) RenderRectFilledWithHole(host_window->DrawList, node->Rect(), central_node->Rect(), GetColorU32(ImGuiCol_WindowBg), 0.0f); else @@ -14511,7 +15247,7 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node) // Draw and populate Tab Bar if (host_window) - host_window->DrawList->ChannelsSetCurrent(1); + host_window->DrawList->ChannelsSetCurrent(DOCKING_HOST_DRAW_CHANNEL_FG); if (host_window && node->Windows.Size > 0) { DockNodeUpdateTabBar(node, host_window); @@ -14525,7 +15261,7 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node) if (node->TabBar && node->TabBar->SelectedTabId) node->SelectedTabId = node->TabBar->SelectedTabId; else if (node->Windows.Size > 0) - node->SelectedTabId = node->Windows[0]->ID; + node->SelectedTabId = node->Windows[0]->TabId; // Draw payload drop target if (host_window && node->IsVisible) @@ -14546,13 +15282,7 @@ static void ImGui::DockNodeUpdate(ImGuiDockNode* node) // Render outer borders last (after the tab bar) if (node->IsRootNode()) - { - host_window->DrawList->ChannelsSetCurrent(1); RenderWindowOuterBorders(host_window); - } - - // Further rendering (= hosted windows background) will be drawn on layer 0 - host_window->DrawList->ChannelsSetCurrent(0); } // End host window @@ -14627,6 +15357,21 @@ void ImGui::DockNodeEndAmendTabBar() End(); } +static bool IsDockNodeTitleBarHighlighted(ImGuiDockNode* node, ImGuiDockNode* root_node, ImGuiWindow* host_window) +{ + // CTRL+Tab highlight (only highlighting leaf node, not whole hierarchy) + ImGuiContext& g = *GImGui; + if (g.NavWindowingTarget) + return (g.NavWindowingTarget->DockNode == node); + + // FIXME-DOCKING: May want alternative to treat central node void differently? e.g. if (g.NavWindow == host_window) + if (g.NavWindow && g.NavWindow->RootWindowForTitleBarHighlight == host_window->RootWindowDockTree && root_node->LastFocusedNodeId == node->ID) + for (ImGuiDockNode* parent_node = g.NavWindow->RootWindow->DockNode; parent_node != NULL; parent_node = parent_node->HostWindow ? parent_node->HostWindow->RootWindow->DockNode : NULL) + if ((parent_node = ImGui::DockNodeGetRootNode(parent_node)) == root_node) + return true; + return false; +} + // Submit the tab bar corresponding to a dock node and various housekeeping details. static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_window) { @@ -14642,9 +15387,7 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w // Decide if we should use a focused title bar color bool is_focused = false; ImGuiDockNode* root_node = DockNodeGetRootNode(node); - if (g.NavWindowingTarget) - is_focused = (g.NavWindowingTarget->DockNode == node); - else if (g.NavWindow && g.NavWindow->RootWindowForTitleBarHighlight == host_window->RootWindowDockTree && root_node->LastFocusedNodeId == node->ID) + if (IsDockNodeTitleBarHighlighted(node, root_node, host_window)) is_focused = true; // Hidden tab bar will show a triangle on the upper-left (in Begin) @@ -14660,7 +15403,7 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w if (is_focused || root_node->VisibleWindow == NULL) root_node->VisibleWindow = node->VisibleWindow; if (node->TabBar) - node->TabBar->VisibleTabId = node->VisibleWindow->ID; + node->TabBar->VisibleTabId = node->VisibleWindow->TabId; } return; } @@ -14711,7 +15454,7 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w for (int window_n = 0; window_n < node->Windows.Size; window_n++) { ImGuiWindow* window = node->Windows[window_n]; - if (TabBarFindTabByID(tab_bar, window->ID) == NULL) + if (TabBarFindTabByID(tab_bar, window->TabId) == NULL) TabBarAddTab(tab_bar, ImGuiTabItemFlags_Unsorted, window); } @@ -14741,22 +15484,22 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w } if (tab_bar->Tabs.Size > tabs_unsorted_start) { - IMGUI_DEBUG_LOG_DOCKING("In node 0x%08X: %d new appearing tabs:%s\n", node->ID, tab_bar->Tabs.Size - tabs_unsorted_start, (tab_bar->Tabs.Size > tabs_unsorted_start + 1) ? " (will sort)" : ""); + IMGUI_DEBUG_LOG_DOCKING("[docking] In node 0x%08X: %d new appearing tabs:%s\n", node->ID, tab_bar->Tabs.Size - tabs_unsorted_start, (tab_bar->Tabs.Size > tabs_unsorted_start + 1) ? " (will sort)" : ""); for (int tab_n = tabs_unsorted_start; tab_n < tab_bar->Tabs.Size; tab_n++) - IMGUI_DEBUG_LOG_DOCKING(" - Tab '%s' Order %d\n", tab_bar->Tabs[tab_n].Window->Name, tab_bar->Tabs[tab_n].Window->DockOrder); + IMGUI_DEBUG_LOG_DOCKING("[docking] - Tab '%s' Order %d\n", tab_bar->Tabs[tab_n].Window->Name, tab_bar->Tabs[tab_n].Window->DockOrder); if (tab_bar->Tabs.Size > tabs_unsorted_start + 1) ImQsort(tab_bar->Tabs.Data + tabs_unsorted_start, tab_bar->Tabs.Size - tabs_unsorted_start, sizeof(ImGuiTabItem), TabItemComparerByDockOrder); } // Apply NavWindow focus back to the tab bar if (g.NavWindow && g.NavWindow->RootWindow->DockNode == node) - tab_bar->SelectedTabId = g.NavWindow->RootWindow->ID; + tab_bar->SelectedTabId = g.NavWindow->RootWindow->TabId; // Selected newly added tabs, or persistent tab ID if the tab bar was just recreated if (tab_bar_is_recreated && TabBarFindTabByID(tab_bar, node->SelectedTabId) != NULL) tab_bar->SelectedTabId = tab_bar->NextSelectedTabId = node->SelectedTabId; else if (tab_bar->Tabs.Size > tabs_count_old) - tab_bar->SelectedTabId = tab_bar->NextSelectedTabId = tab_bar->Tabs.back().Window->ID; + tab_bar->SelectedTabId = tab_bar->NextSelectedTabId = tab_bar->Tabs.back().Window->TabId; // Begin tab bar ImGuiTabBarFlags tab_bar_flags = ImGuiTabBarFlags_Reorderable | ImGuiTabBarFlags_AutoSelectNewTabs; // | ImGuiTabBarFlags_NoTabListScrollingButtons); @@ -14776,7 +15519,7 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w for (int window_n = 0; window_n < node->Windows.Size; window_n++) { ImGuiWindow* window = node->Windows[window_n]; - if ((closed_all || closed_one == window->ID) && window->HasCloseButton && !(window->Flags & ImGuiWindowFlags_UnsavedDocument)) + if ((closed_all || closed_one == window->TabId) && window->HasCloseButton && !(window->Flags & ImGuiWindowFlags_UnsavedDocument)) continue; if (window->LastFrameActive + 1 >= g.FrameCount || !node_was_active) { @@ -14791,11 +15534,12 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w for (int color_n = 0; color_n < ImGuiWindowDockStyleCol_COUNT; color_n++) g.Style.Colors[GWindowDockStyleColors[color_n]] = ColorConvertU32ToFloat4(window->DockStyle.Colors[color_n]); + // Note that TabItemEx() calls TabBarCalcTabID() so our tab item ID will ignore the current ID stack (rightly so) bool tab_open = true; TabItemEx(tab_bar, window->Name, window->HasCloseButton ? &tab_open : NULL, tab_item_flags, window); if (!tab_open) - node->WantCloseTabId = window->ID; - if (tab_bar->VisibleTabId == window->ID) + node->WantCloseTabId = window->TabId; + if (tab_bar->VisibleTabId == window->TabId) node->VisibleWindow = window; // Store last item data so it can be queried with IsItemXXX functions after the user Begin() call @@ -14804,7 +15548,7 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w // Update navigation ID on menu layer if (g.NavWindow && g.NavWindow->RootWindow == window && (window->DC.NavLayersActiveMask & (1 << ImGuiNavLayer_Menu)) == 0) - host_window->NavLastIds[1] = window->ID; + host_window->NavLastIds[1] = window->TabId; } } @@ -14818,7 +15562,7 @@ static void ImGui::DockNodeUpdateTabBar(ImGuiDockNode* node, ImGuiWindow* host_w root_node->VisibleWindow = node->VisibleWindow; // Close button (after VisibleWindow was updated) - // Note that VisibleWindow may have been overrided by CTRL+Tabbing, so VisibleWindow->ID may be != from tab_bar->SelectedTabId + // Note that VisibleWindow may have been overrided by CTRL+Tabbing, so VisibleWindow->TabId may be != from tab_bar->SelectedTabId const bool close_button_is_enabled = node->HasCloseButton && node->VisibleWindow && node->VisibleWindow->HasCloseButton; const bool close_button_is_visible = node->HasCloseButton; //const bool close_button_is_visible = close_button_is_enabled; // Most people would expect this behavior of not even showing the button (leaving a hole since we can't claim that space as other windows in the tba bar have one) @@ -15091,7 +15835,7 @@ static void ImGui::DockNodePreviewDockSetup(ImGuiWindow* host_window, ImGuiDockN ImGuiDockNode* root_payload_as_host = root_payload->DockNodeAsHost; ImGuiDockNode* ref_node_for_rect = (host_node && !host_node->IsVisible) ? DockNodeGetRootNode(host_node) : host_node; if (ref_node_for_rect) - IM_ASSERT(ref_node_for_rect->IsVisible); + IM_ASSERT(ref_node_for_rect->IsVisible == true); // Filter, figure out where we are allowed to dock ImGuiDockNodeFlags src_node_flags = root_payload_as_host ? root_payload_as_host->MergedFlags : root_payload->WindowClass.DockNodeFlagsOverrideSet; @@ -15343,6 +16087,7 @@ void ImGui::DockNodeTreeSplit(ImGuiContext* ctx, ImGuiDockNode* parent_node, ImG void ImGui::DockNodeTreeMerge(ImGuiContext* ctx, ImGuiDockNode* parent_node, ImGuiDockNode* merge_lead_child) { // When called from DockContextProcessUndockNode() it is possible that one of the child is NULL. + ImGuiContext& g = *GImGui; ImGuiDockNode* child_0 = parent_node->ChildNodes[0]; ImGuiDockNode* child_1 = parent_node->ChildNodes[1]; IM_ASSERT(child_0 || child_1); @@ -15352,7 +16097,7 @@ void ImGui::DockNodeTreeMerge(ImGuiContext* ctx, ImGuiDockNode* parent_node, ImG IM_ASSERT(parent_node->TabBar == NULL); IM_ASSERT(parent_node->Windows.Size == 0); } - IMGUI_DEBUG_LOG_DOCKING("DockNodeTreeMerge 0x%08X & 0x%08X back into parent 0x%08X\n", child_0 ? child_0->ID : 0, child_1 ? child_1->ID : 0, parent_node->ID); + IMGUI_DEBUG_LOG_DOCKING("[docking] DockNodeTreeMerge: 0x%08X + 0x%08X back into parent 0x%08X\n", child_0 ? child_0->ID : 0, child_1 ? child_1->ID : 0, parent_node->ID); ImVec2 backup_last_explicit_size = parent_node->SizeRef; DockNodeMoveChildNodes(parent_node, merge_lead_child); @@ -15720,12 +16465,12 @@ ImGuiID ImGui::DockSpace(ImGuiID id, const ImVec2& size_arg, ImGuiDockNodeFlags ImGuiDockNode* node = DockContextFindNodeByID(ctx, id); if (!node) { - IMGUI_DEBUG_LOG_DOCKING("DockSpace: dockspace node 0x%08X created\n", id); + IMGUI_DEBUG_LOG_DOCKING("[docking] DockSpace: dockspace node 0x%08X created\n", id); node = DockContextAddNode(ctx, id); node->SetLocalFlags(ImGuiDockNodeFlags_CentralNode); } if (window_class && window_class->ClassId != node->WindowClass.ClassId) - IMGUI_DEBUG_LOG_DOCKING("DockSpace: dockspace node 0x%08X: setup WindowClass 0x%08X -> 0x%08X\n", id, node->WindowClass.ClassId, window_class->ClassId); + IMGUI_DEBUG_LOG_DOCKING("[docking] DockSpace: dockspace node 0x%08X: setup WindowClass 0x%08X -> 0x%08X\n", id, node->WindowClass.ClassId, window_class->ClassId); node->SharedFlags = flags; node->WindowClass = window_class ? *window_class : ImGuiWindowClass(); @@ -16061,11 +16806,11 @@ void ImGui::DockBuilderRemoveNodeDockedWindows(ImGuiID root_id, bool clear_setti // FIXME-DOCK: We are not exposing nor using split_outer. ImGuiID ImGui::DockBuilderSplitNode(ImGuiID id, ImGuiDir split_dir, float size_ratio_for_node_at_dir, ImGuiID* out_id_at_dir, ImGuiID* out_id_at_opposite_dir) { - ImGuiContext* ctx = GImGui; + ImGuiContext& g = *GImGui; IM_ASSERT(split_dir != ImGuiDir_None); - IMGUI_DEBUG_LOG_DOCKING("DockBuilderSplitNode node 0x%08X, split_dir %d\n", id, split_dir); + IMGUI_DEBUG_LOG_DOCKING("[docking] DockBuilderSplitNode: node 0x%08X, split_dir %d\n", id, split_dir); - ImGuiDockNode* node = DockContextFindNodeByID(ctx, id); + ImGuiDockNode* node = DockContextFindNodeByID(&g, id); if (node == NULL) { IM_ASSERT(node != NULL); @@ -16082,7 +16827,7 @@ ImGuiID ImGui::DockBuilderSplitNode(ImGuiID id, ImGuiDir split_dir, float size_r req.DockSplitDir = split_dir; req.DockSplitRatio = ImSaturate((split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Up) ? size_ratio_for_node_at_dir : 1.0f - size_ratio_for_node_at_dir); req.DockSplitOuter = false; - DockContextProcessDock(ctx, &req); + DockContextProcessDock(&g, &req); ImGuiID id_at_dir = node->ChildNodes[(split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Up) ? 0 : 1]->ID; ImGuiID id_at_opposite_dir = node->ChildNodes[(split_dir == ImGuiDir_Left || split_dir == ImGuiDir_Up) ? 1 : 0]->ID; @@ -16095,8 +16840,8 @@ ImGuiID ImGui::DockBuilderSplitNode(ImGuiID id, ImGuiDir split_dir, float size_r static ImGuiDockNode* DockBuilderCopyNodeRec(ImGuiDockNode* src_node, ImGuiID dst_node_id_if_known, ImVector* out_node_remap_pairs) { - ImGuiContext* ctx = GImGui; - ImGuiDockNode* dst_node = ImGui::DockContextAddNode(ctx, dst_node_id_if_known); + ImGuiContext& g = *GImGui; + ImGuiDockNode* dst_node = ImGui::DockContextAddNode(&g, dst_node_id_if_known); dst_node->SharedFlags = src_node->SharedFlags; dst_node->LocalFlags = src_node->LocalFlags; dst_node->LocalFlagsInWindows = ImGuiDockNodeFlags_None; @@ -16116,7 +16861,7 @@ static ImGuiDockNode* DockBuilderCopyNodeRec(ImGuiDockNode* src_node, ImGuiID ds dst_node->ChildNodes[child_n]->ParentNode = dst_node; } - IMGUI_DEBUG_LOG_DOCKING("Fork node %08X -> %08X (%d childs)\n", src_node->ID, dst_node->ID, dst_node->IsSplitNode() ? 2 : 0); + IMGUI_DEBUG_LOG_DOCKING("[docking] Fork node %08X -> %08X (%d childs)\n", src_node->ID, dst_node->ID, dst_node->IsSplitNode() ? 2 : 0); return dst_node; } @@ -16171,6 +16916,7 @@ void ImGui::DockBuilderCopyWindowSettings(const char* src_name, const char* dst_ // FIXME: Will probably want to change this signature, in particular how the window remapping pairs are passed. void ImGui::DockBuilderCopyDockSpace(ImGuiID src_dockspace_id, ImGuiID dst_dockspace_id, ImVector* in_window_remap_pairs) { + ImGuiContext& g = *GImGui; IM_ASSERT(src_dockspace_id != 0); IM_ASSERT(dst_dockspace_id != 0); IM_ASSERT(in_window_remap_pairs != NULL); @@ -16210,14 +16956,14 @@ void ImGui::DockBuilderCopyDockSpace(ImGuiID src_dockspace_id, ImGuiID dst_docks if (dst_dock_id != 0) { // Docked windows gets redocked into the new node hierarchy. - IMGUI_DEBUG_LOG_DOCKING("Remap live window '%s' 0x%08X -> '%s' 0x%08X\n", src_window_name, src_dock_id, dst_window_name, dst_dock_id); + IMGUI_DEBUG_LOG_DOCKING("[docking] Remap live window '%s' 0x%08X -> '%s' 0x%08X\n", src_window_name, src_dock_id, dst_window_name, dst_dock_id); DockBuilderDockWindow(dst_window_name, dst_dock_id); } else { // Floating windows gets their settings transferred (regardless of whether the new window already exist or not) // When this is leading to a Copy and not a Move, we would get two overlapping floating windows. Could we possibly dock them together? - IMGUI_DEBUG_LOG_DOCKING("Remap window settings '%s' -> '%s'\n", src_window_name, dst_window_name); + IMGUI_DEBUG_LOG_DOCKING("[docking] Remap window settings '%s' -> '%s'\n", src_window_name, dst_window_name); DockBuilderCopyWindowSettings(src_window_name, dst_window_name); } } @@ -16236,7 +16982,7 @@ void ImGui::DockBuilderCopyDockSpace(ImGuiID src_dockspace_id, ImGuiID dst_docks continue; // Docked windows gets redocked into the new node hierarchy. - IMGUI_DEBUG_LOG_DOCKING("Remap window '%s' %08X -> %08X\n", window->Name, src_dock_id, dst_dock_id); + IMGUI_DEBUG_LOG_DOCKING("[docking] Remap window '%s' %08X -> %08X\n", window->Name, src_dock_id, dst_dock_id); DockBuilderDockWindow(window->Name, dst_dock_id); } } @@ -16432,7 +17178,7 @@ void ImGui::BeginDocked(ImGuiWindow* window, bool* p_open) if (node->TabBar && window->WasActive) window->DockOrder = (short)DockNodeGetTabOrder(window); - if ((node->WantCloseAll || node->WantCloseTabId == window->ID) && p_open != NULL) + if ((node->WantCloseAll || node->WantCloseTabId == window->TabId) && p_open != NULL) *p_open = false; // Update ChildId to allow returning from Child to Parent with Escape @@ -16560,7 +17306,7 @@ void ImGui::BeginDockableDragDropTarget(ImGuiWindow* window) static void ImGui::DockSettingsRenameNodeReferences(ImGuiID old_node_id, ImGuiID new_node_id) { ImGuiContext& g = *GImGui; - IMGUI_DEBUG_LOG_DOCKING("DockSettingsRenameNodeReferences: from 0x%08X -> to 0x%08X\n", old_node_id, new_node_id); + IMGUI_DEBUG_LOG_DOCKING("[docking] DockSettingsRenameNodeReferences: from 0x%08X -> to 0x%08X\n", old_node_id, new_node_id); for (int window_n = 0; window_n < g.Windows.Size; window_n++) { ImGuiWindow* window = g.Windows[window_n]; @@ -16898,17 +17644,64 @@ static void SetClipboardTextFn_DefaultImpl(void*, const char* text) #endif +// Win32 API IME support (for Asian languages, etc.) +#if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS) + +#include +#ifdef _MSC_VER +#pragma comment(lib, "imm32") +#endif + +static void SetPlatformImeDataFn_DefaultImpl(ImGuiViewport* viewport, ImGuiPlatformImeData* data) +{ + // Notify OS Input Method Editor of text input position + HWND hwnd = (HWND)viewport->PlatformHandleRaw; +#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS + if (hwnd == 0) + hwnd = (HWND)ImGui::GetIO().ImeWindowHandle; +#endif + if (hwnd == 0) + return; + + ::ImmAssociateContextEx(hwnd, NULL, data->WantVisible ? IACE_DEFAULT : 0); + + if (HIMC himc = ::ImmGetContext(hwnd)) + { + COMPOSITIONFORM composition_form = {}; + composition_form.ptCurrentPos.x = (LONG)(data->InputPos.x - viewport->Pos.x); + composition_form.ptCurrentPos.y = (LONG)(data->InputPos.y - viewport->Pos.y); + composition_form.dwStyle = CFS_FORCE_POSITION; + ::ImmSetCompositionWindow(himc, &composition_form); + CANDIDATEFORM candidate_form = {}; + candidate_form.dwStyle = CFS_CANDIDATEPOS; + candidate_form.ptCurrentPos.x = (LONG)(data->InputPos.x - viewport->Pos.x); + candidate_form.ptCurrentPos.y = (LONG)(data->InputPos.y - viewport->Pos.y); + ::ImmSetCandidateWindow(himc, &candidate_form); + ::ImmReleaseContext(hwnd, himc); + } +} + +#else + +static void SetPlatformImeDataFn_DefaultImpl(ImGuiViewport*, ImGuiPlatformImeData*) {} + +#endif + //----------------------------------------------------------------------------- // [SECTION] METRICS/DEBUGGER WINDOW //----------------------------------------------------------------------------- // - RenderViewportThumbnail() [Internal] // - RenderViewportsThumbnails() [Internal] +// - DebugTextEncoding() // - MetricsHelpMarker() [Internal] +// - ShowFontAtlas() [Internal] // - ShowMetricsWindow() // - DebugNodeColumns() [Internal] // - DebugNodeDockNode() [Internal] // - DebugNodeDrawList() [Internal] // - DebugNodeDrawCmdShowMeshAndBoundingBox() [Internal] +// - DebugNodeFont() [Internal] +// - DebugNodeFontGlyph() [Internal] // - DebugNodeStorage() [Internal] // - DebugNodeTabBar() [Internal] // - DebugNodeViewport() [Internal] @@ -16918,7 +17711,7 @@ static void SetClipboardTextFn_DefaultImpl(void*, const char* text) // - DebugNodeWindowsListByBeginStackParent() [Internal] //----------------------------------------------------------------------------- -#ifndef IMGUI_DISABLE_METRICS_WINDOW +#ifndef IMGUI_DISABLE_DEBUG_TOOLS void ImGui::DebugRenderViewportThumbnail(ImDrawList* draw_list, ImGuiViewportP* viewport, const ImRect& bb) { @@ -16975,11 +17768,47 @@ static void RenderViewportsThumbnails() static int IMGUI_CDECL ViewportComparerByFrontMostStampCount(const void* lhs, const void* rhs) { - const ImGuiViewportP* a = *(const ImGuiViewportP* const *)lhs; - const ImGuiViewportP* b = *(const ImGuiViewportP* const *)rhs; + const ImGuiViewportP* a = *(const ImGuiViewportP* const*)lhs; + const ImGuiViewportP* b = *(const ImGuiViewportP* const*)rhs; return b->LastFrontMostStampCount - a->LastFrontMostStampCount; } +// Helper tool to diagnose between text encoding issues and font loading issues. Pass your UTF-8 string and verify that there are correct. +void ImGui::DebugTextEncoding(const char* str) +{ + Text("Text: \"%s\"", str); + if (!BeginTable("list", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit)) + return; + TableSetupColumn("Offset"); + TableSetupColumn("UTF-8"); + TableSetupColumn("Glyph"); + TableSetupColumn("Codepoint"); + TableHeadersRow(); + for (const char* p = str; *p != 0; ) + { + unsigned int c; + const int c_utf8_len = ImTextCharFromUtf8(&c, p, NULL); + TableNextColumn(); + Text("%d", (int)(p - str)); + TableNextColumn(); + for (int byte_index = 0; byte_index < c_utf8_len; byte_index++) + { + if (byte_index > 0) + SameLine(); + Text("0x%02X", (int)(unsigned char)p[byte_index]); + } + TableNextColumn(); + if (GetFont()->FindGlyphNoFallback((ImWchar)c)) + TextUnformatted(p, p + c_utf8_len); + else + TextUnformatted((c == IM_UNICODE_CODEPOINT_INVALID) ? "[invalid]" : "[missing]"); + TableNextColumn(); + Text("U+%04X", (int)c); + p += c_utf8_len; + } + EndTable(); +} + // Avoid naming collision with imgui_demo.cpp's HelpMarker() for unity builds. static void MetricsHelpMarker(const char* desc) { @@ -16994,15 +17823,32 @@ static void MetricsHelpMarker(const char* desc) } } -#ifndef IMGUI_DISABLE_DEMO_WINDOWS -namespace ImGui { void ShowFontAtlas(ImFontAtlas* atlas); } -#endif +// [DEBUG] List fonts in a font atlas and display its texture +void ImGui::ShowFontAtlas(ImFontAtlas* atlas) +{ + for (int i = 0; i < atlas->Fonts.Size; i++) + { + ImFont* font = atlas->Fonts[i]; + PushID(font); + DebugNodeFont(font); + PopID(); + } + if (TreeNode("Atlas texture", "Atlas texture (%dx%d pixels)", atlas->TexWidth, atlas->TexHeight)) + { + ImVec4 tint_col = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); + ImVec4 border_col = ImVec4(1.0f, 1.0f, 1.0f, 0.5f); + Image(atlas->TexID, ImVec2((float)atlas->TexWidth, (float)atlas->TexHeight), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), tint_col, border_col); + TreePop(); + } +} void ImGui::ShowMetricsWindow(bool* p_open) { ImGuiContext& g = *GImGui; ImGuiIO& io = g.IO; ImGuiMetricsConfig* cfg = &g.DebugMetricsConfig; + if (cfg->ShowDebugLog) + ShowDebugLogWindow(&cfg->ShowDebugLog); if (cfg->ShowStackTool) ShowStackToolWindow(&cfg->ShowStackTool); @@ -17035,19 +17881,20 @@ void ImGui::ShowMetricsWindow(bool* p_open) { static ImRect GetTableRect(ImGuiTable* table, int rect_type, int n) { + ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent); // Always using last submitted instance if (rect_type == TRT_OuterRect) { return table->OuterRect; } else if (rect_type == TRT_InnerRect) { return table->InnerRect; } else if (rect_type == TRT_WorkRect) { return table->WorkRect; } else if (rect_type == TRT_HostClipRect) { return table->HostClipRect; } else if (rect_type == TRT_InnerClipRect) { return table->InnerClipRect; } else if (rect_type == TRT_BackgroundClipRect) { return table->BgClipRect; } - else if (rect_type == TRT_ColumnsRect) { ImGuiTableColumn* c = &table->Columns[n]; return ImRect(c->MinX, table->InnerClipRect.Min.y, c->MaxX, table->InnerClipRect.Min.y + table->LastOuterHeight); } + else if (rect_type == TRT_ColumnsRect) { ImGuiTableColumn* c = &table->Columns[n]; return ImRect(c->MinX, table->InnerClipRect.Min.y, c->MaxX, table->InnerClipRect.Min.y + table_instance->LastOuterHeight); } else if (rect_type == TRT_ColumnsWorkRect) { ImGuiTableColumn* c = &table->Columns[n]; return ImRect(c->WorkMinX, table->WorkRect.Min.y, c->WorkMaxX, table->WorkRect.Max.y); } else if (rect_type == TRT_ColumnsClipRect) { ImGuiTableColumn* c = &table->Columns[n]; return c->ClipRect; } - else if (rect_type == TRT_ColumnsContentHeadersUsed){ ImGuiTableColumn* c = &table->Columns[n]; return ImRect(c->WorkMinX, table->InnerClipRect.Min.y, c->ContentMaxXHeadersUsed, table->InnerClipRect.Min.y + table->LastFirstRowHeight); } // Note: y1/y2 not always accurate - else if (rect_type == TRT_ColumnsContentHeadersIdeal){ImGuiTableColumn* c = &table->Columns[n]; return ImRect(c->WorkMinX, table->InnerClipRect.Min.y, c->ContentMaxXHeadersIdeal, table->InnerClipRect.Min.y + table->LastFirstRowHeight); } - else if (rect_type == TRT_ColumnsContentFrozen) { ImGuiTableColumn* c = &table->Columns[n]; return ImRect(c->WorkMinX, table->InnerClipRect.Min.y, c->ContentMaxXFrozen, table->InnerClipRect.Min.y + table->LastFirstRowHeight); } - else if (rect_type == TRT_ColumnsContentUnfrozen) { ImGuiTableColumn* c = &table->Columns[n]; return ImRect(c->WorkMinX, table->InnerClipRect.Min.y + table->LastFirstRowHeight, c->ContentMaxXUnfrozen, table->InnerClipRect.Max.y); } + else if (rect_type == TRT_ColumnsContentHeadersUsed){ ImGuiTableColumn* c = &table->Columns[n]; return ImRect(c->WorkMinX, table->InnerClipRect.Min.y, c->ContentMaxXHeadersUsed, table->InnerClipRect.Min.y + table_instance->LastFirstRowHeight); } // Note: y1/y2 not always accurate + else if (rect_type == TRT_ColumnsContentHeadersIdeal){ImGuiTableColumn* c = &table->Columns[n]; return ImRect(c->WorkMinX, table->InnerClipRect.Min.y, c->ContentMaxXHeadersIdeal, table->InnerClipRect.Min.y + table_instance->LastFirstRowHeight); } + else if (rect_type == TRT_ColumnsContentFrozen) { ImGuiTableColumn* c = &table->Columns[n]; return ImRect(c->WorkMinX, table->InnerClipRect.Min.y, c->ContentMaxXFrozen, table->InnerClipRect.Min.y + table_instance->LastFirstRowHeight); } + else if (rect_type == TRT_ColumnsContentUnfrozen) { ImGuiTableColumn* c = &table->Columns[n]; return ImRect(c->WorkMinX, table->InnerClipRect.Min.y + table_instance->LastFirstRowHeight, c->ContentMaxXUnfrozen, table->InnerClipRect.Max.y); } IM_ASSERT(0); return ImRect(); } @@ -17070,8 +17917,32 @@ void ImGui::ShowMetricsWindow(bool* p_open) // Tools if (TreeNode("Tools")) { + bool show_encoding_viewer = TreeNode("UTF-8 Encoding viewer"); + SameLine(); + MetricsHelpMarker("You can also call ImGui::DebugTextEncoding() from your code with a given string to test that your UTF-8 encoding settings are correct."); + if (show_encoding_viewer) + { + static char buf[100] = ""; + SetNextItemWidth(-FLT_MIN); + InputText("##Text", buf, IM_ARRAYSIZE(buf)); + if (buf[0] != 0) + DebugTextEncoding(buf); + TreePop(); + } + + // The Item Picker tool is super useful to visually select an item and break into the call-stack of where it was submitted. + if (Checkbox("Show Item Picker", &g.DebugItemPickerActive) && g.DebugItemPickerActive) + DebugStartItemPicker(); + SameLine(); + MetricsHelpMarker("Will call the IM_DEBUG_BREAK() macro to break in debugger.\nWarning: If you don't have a debugger attached, this will probably crash."); + // Stack Tool is your best friend! - Checkbox("Show stack tool", &cfg->ShowStackTool); + Checkbox("Show Debug Log", &cfg->ShowDebugLog); + SameLine(); + MetricsHelpMarker("You can also call ImGui::ShowDebugLogWindow() from your code."); + + // Stack Tool is your best friend! + Checkbox("Show Stack Tool", &cfg->ShowStackTool); SameLine(); MetricsHelpMarker("You can also call ImGui::ShowStackToolWindow() from your code."); @@ -17137,12 +18008,6 @@ void ImGui::ShowMetricsWindow(bool* p_open) } } - // The Item Picker tool is super useful to visually select an item and break into the call-stack of where it was submitted. - if (Button("Item Picker..")) - DebugStartItemPicker(); - SameLine(); - MetricsHelpMarker("Will call the IM_DEBUG_BREAK() macro to break in debugger.\nWarning: If you don't have a debugger attached, this will probably crash."); - TreePop(); } @@ -17216,7 +18081,8 @@ void ImGui::ShowMetricsWindow(bool* p_open) TreePop(); } - if (TreeNode("Inferred order (front-to-back)")) + BulletText("MouseViewport: 0x%08X (UserHovered 0x%08X, LastHovered 0x%08X)", g.MouseViewport ? g.MouseViewport->ID : 0, g.IO.MouseHoveredViewport, g.MouseLastHoveredViewport ? g.MouseLastHoveredViewport->ID : 0); + if (TreeNode("Inferred Z order (front-to-back)")) { static ImVector viewports; viewports.resize(g.Viewports.Size); @@ -17267,14 +18133,19 @@ void ImGui::ShowMetricsWindow(bool* p_open) } // Details for Fonts -#ifndef IMGUI_DISABLE_DEMO_WINDOWS ImFontAtlas* atlas = g.IO.Fonts; if (TreeNode("Fonts", "Fonts (%d)", atlas->Fonts.Size)) { ShowFontAtlas(atlas); TreePop(); } -#endif + + // Details for InputText + if (TreeNode("InputText")) + { + DebugNodeInputTextState(&g.InputTextState); + TreePop(); + } // Details for Docking #ifdef IMGUI_HAS_DOCK @@ -17369,8 +18240,6 @@ void ImGui::ShowMetricsWindow(bool* p_open) // Misc Details if (TreeNode("Internal state")) { - const char* input_source_names[] = { "None", "Mouse", "Keyboard", "Gamepad", "Nav", "Clipboard" }; IM_ASSERT(IM_ARRAYSIZE(input_source_names) == ImGuiInputSource_COUNT); - Text("WINDOWING"); Indent(); Text("HoveredWindow: '%s'", g.HoveredWindow ? g.HoveredWindow->Name : "NULL"); @@ -17383,9 +18252,13 @@ void ImGui::ShowMetricsWindow(bool* p_open) Text("ITEMS"); Indent(); - Text("ActiveId: 0x%08X/0x%08X (%.2f sec), AllowOverlap: %d, Source: %s", g.ActiveId, g.ActiveIdPreviousFrame, g.ActiveIdTimer, g.ActiveIdAllowOverlap, input_source_names[g.ActiveIdSource]); + Text("ActiveId: 0x%08X/0x%08X (%.2f sec), AllowOverlap: %d, Source: %s", g.ActiveId, g.ActiveIdPreviousFrame, g.ActiveIdTimer, g.ActiveIdAllowOverlap, GetInputSourceName(g.ActiveIdSource)); Text("ActiveIdWindow: '%s'", g.ActiveIdWindow ? g.ActiveIdWindow->Name : "NULL"); - Text("ActiveIdUsing: Wheel: %d, NavDirMask: %X, NavInputMask: %X, KeyInputMask: %llX", g.ActiveIdUsingMouseWheel, g.ActiveIdUsingNavDirMask, g.ActiveIdUsingNavInputMask, g.ActiveIdUsingKeyInputMask); + + int active_id_using_key_input_count = 0; + for (int n = ImGuiKey_NamedKey_BEGIN; n < ImGuiKey_NamedKey_END; n++) + active_id_using_key_input_count += g.ActiveIdUsingKeyInputMask[n] ? 1 : 0; + Text("ActiveIdUsing: NavDirMask: %X, KeyInputMask: %d key(s)", g.ActiveIdUsingNavDirMask, active_id_using_key_input_count); Text("HoveredId: 0x%08X (%.2f sec), AllowOverlap: %d", g.HoveredIdPreviousFrame, g.HoveredIdTimer, g.HoveredIdAllowOverlap); // Not displaying g.HoveredId as it is update mid-frame Text("DragDrop: %d, SourceId = 0x%08X, Payload \"%s\" (%d bytes)", g.DragDropActive, g.DragDropPayload.SourceId, g.DragDropPayload.DataType, g.DragDropPayload.DataSize); Unindent(); @@ -17394,7 +18267,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) Indent(); Text("NavWindow: '%s'", g.NavWindow ? g.NavWindow->Name : "NULL"); Text("NavId: 0x%08X, NavLayer: %d", g.NavId, g.NavLayer); - Text("NavInputSource: %s", input_source_names[g.NavInputSource]); + Text("NavInputSource: %s", GetInputSourceName(g.NavInputSource)); Text("NavActive: %d, NavVisible: %d", g.IO.NavActive, g.IO.NavVisible); Text("NavActivateId/DownId/PressedId/InputId: %08X/%08X/%08X/%08X", g.NavActivateId, g.NavActivateDownId, g.NavActivatePressedId, g.NavActivateInputId); Text("NavActivateFlags: %04X", g.NavActivateFlags); @@ -17481,25 +18354,6 @@ void ImGui::ShowMetricsWindow(bool* p_open) End(); } -// [DEBUG] List fonts in a font atlas and display its texture -void ImGui::ShowFontAtlas(ImFontAtlas* atlas) -{ - for (int i = 0; i < atlas->Fonts.Size; i++) - { - ImFont* font = atlas->Fonts[i]; - PushID(font); - DebugNodeFont(font); - PopID(); - } - if (TreeNode("Atlas texture", "Atlas texture (%dx%d pixels)", atlas->TexWidth, atlas->TexHeight)) - { - ImVec4 tint_col = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); - ImVec4 border_col = ImVec4(1.0f, 1.0f, 1.0f, 0.5f); - Image(atlas->TexID, ImVec2((float)atlas->TexWidth, (float)atlas->TexHeight), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), tint_col, border_col); - TreePop(); - } -} - // [DEBUG] Display contents of Columns void ImGui::DebugNodeColumns(ImGuiOldColumns* columns) { @@ -17547,10 +18401,11 @@ void ImGui::DebugNodeDockNode(ImGuiDockNode* node, const char* label) const bool is_active = (g.FrameCount - node->LastFrameActive < 2); // Submitted if (!is_alive) { PushStyleColor(ImGuiCol_Text, GetStyleColorVec4(ImGuiCol_TextDisabled)); } bool open; + ImGuiTreeNodeFlags tree_node_flags = node->IsFocused ? ImGuiTreeNodeFlags_Selected : ImGuiTreeNodeFlags_None; if (node->Windows.Size > 0) - open = TreeNode((void*)(intptr_t)node->ID, "%s 0x%04X%s: %d windows (vis: '%s')", label, node->ID, node->IsVisible ? "" : " (hidden)", node->Windows.Size, node->VisibleWindow ? node->VisibleWindow->Name : "NULL"); + open = TreeNodeEx((void*)(intptr_t)node->ID, tree_node_flags, "%s 0x%04X%s: %d windows (vis: '%s')", label, node->ID, node->IsVisible ? "" : " (hidden)", node->Windows.Size, node->VisibleWindow ? node->VisibleWindow->Name : "NULL"); else - open = TreeNode((void*)(intptr_t)node->ID, "%s 0x%04X%s: %s split (vis: '%s')", label, node->ID, node->IsVisible ? "" : " (hidden)", (node->SplitAxis == ImGuiAxis_X) ? "horizontal" : (node->SplitAxis == ImGuiAxis_Y) ? "vertical" : "n/a", node->VisibleWindow ? node->VisibleWindow->Name : "NULL"); + open = TreeNodeEx((void*)(intptr_t)node->ID, tree_node_flags, "%s 0x%04X%s: %s split (vis: '%s')", label, node->ID, node->IsVisible ? "" : " (hidden)", (node->SplitAxis == ImGuiAxis_X) ? "horizontal" : (node->SplitAxis == ImGuiAxis_Y) ? "vertical" : "n/a", node->VisibleWindow ? node->VisibleWindow->Name : "NULL"); if (!is_alive) { PopStyleColor(); } if (is_active && IsItemHovered()) if (ImGuiWindow* window = node->HostWindow ? node->HostWindow : node->VisibleWindow) @@ -17564,10 +18419,10 @@ void ImGui::DebugNodeDockNode(ImGuiDockNode* node, const char* label) DebugNodeWindow(node->HostWindow, "HostWindow"); DebugNodeWindow(node->VisibleWindow, "VisibleWindow"); BulletText("SelectedTabID: 0x%08X, LastFocusedNodeID: 0x%08X", node->SelectedTabId, node->LastFocusedNodeId); - BulletText("Misc:%s%s%s%s%s%s", + BulletText("Misc:%s%s%s%s%s%s%s", node->IsDockSpace() ? " IsDockSpace" : "", node->IsCentralNode() ? " IsCentralNode" : "", - is_alive ? " IsAlive" : "", is_active ? " IsActive" : "", + is_alive ? " IsAlive" : "", is_active ? " IsActive" : "", node->IsFocused ? " IsFocused" : "", node->WantLockSizeOnce ? " WantLockSizeOnce" : "", node->HasCentralNodeChild ? " HasCentralNodeChild" : ""); if (TreeNode("flags", "Flags Merged: 0x%04X, Local: 0x%04X, InWindows: 0x%04X, Shared: 0x%04X", node->MergedFlags, node->LocalFlags, node->LocalFlagsInWindows, node->SharedFlags)) @@ -17793,17 +18648,13 @@ void ImGui::DebugNodeFont(ImFont* font) ImVec2 cell_p2(cell_p1.x + cell_size, cell_p1.y + cell_size); const ImFontGlyph* glyph = font->FindGlyphNoFallback((ImWchar)(base + n)); draw_list->AddRect(cell_p1, cell_p2, glyph ? IM_COL32(255, 255, 255, 100) : IM_COL32(255, 255, 255, 50)); - if (glyph) - font->RenderChar(draw_list, cell_size, cell_p1, glyph_col, (ImWchar)(base + n)); - if (glyph && IsMouseHoveringRect(cell_p1, cell_p2)) + if (!glyph) + continue; + font->RenderChar(draw_list, cell_size, cell_p1, glyph_col, (ImWchar)(base + n)); + if (IsMouseHoveringRect(cell_p1, cell_p2)) { BeginTooltip(); - Text("Codepoint: U+%04X", base + n); - Separator(); - Text("Visible: %d", glyph->Visible); - Text("AdvanceX: %.1f", glyph->AdvanceX); - Text("Pos: (%.2f,%.2f)->(%.2f,%.2f)", glyph->X0, glyph->Y0, glyph->X1, glyph->Y1); - Text("UV: (%.3f,%.3f)->(%.3f,%.3f)", glyph->U0, glyph->V0, glyph->U1, glyph->V1); + DebugNodeFontGlyph(font, glyph); EndTooltip(); } } @@ -17815,6 +18666,16 @@ void ImGui::DebugNodeFont(ImFont* font) TreePop(); } +void ImGui::DebugNodeFontGlyph(ImFont*, const ImFontGlyph* glyph) +{ + Text("Codepoint: U+%04X", glyph->Codepoint); + Separator(); + Text("Visible: %d", glyph->Visible); + Text("AdvanceX: %.1f", glyph->AdvanceX); + Text("Pos: (%.2f,%.2f)->(%.2f,%.2f)", glyph->X0, glyph->Y0, glyph->X1, glyph->Y1); + Text("UV: (%.3f,%.3f)->(%.3f,%.3f)", glyph->U0, glyph->V0, glyph->U1, glyph->V1); +} + // [DEBUG] Display contents of ImGuiStorage void ImGui::DebugNodeStorage(ImGuiStorage* storage, const char* label) { @@ -18007,6 +18868,63 @@ void ImGui::DebugNodeWindowsListByBeginStackParent(ImGuiWindow** windows, int wi } } +//----------------------------------------------------------------------------- +// [SECTION] DEBUG LOG +//----------------------------------------------------------------------------- + +void ImGui::DebugLog(const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + DebugLogV(fmt, args); + va_end(args); +} + +void ImGui::DebugLogV(const char* fmt, va_list args) +{ + ImGuiContext& g = *GImGui; + const int old_size = g.DebugLogBuf.size(); + g.DebugLogBuf.appendf("[%05d] ", g.FrameCount); + g.DebugLogBuf.appendfv(fmt, args); + if (g.DebugLogFlags & ImGuiDebugLogFlags_OutputToTTY) + IMGUI_DEBUG_PRINTF("%s", g.DebugLogBuf.begin() + old_size); +} + +void ImGui::ShowDebugLogWindow(bool* p_open) +{ + ImGuiContext& g = *GImGui; + if (!(g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasSize)) + SetNextWindowSize(ImVec2(0.0f, GetFontSize() * 12.0f), ImGuiCond_FirstUseEver); + if (!Begin("Dear ImGui Debug Log", p_open) || GetCurrentWindow()->BeginCount > 1) + { + End(); + return; + } + + AlignTextToFramePadding(); + Text("Log events:"); + SameLine(); CheckboxFlags("All", &g.DebugLogFlags, ImGuiDebugLogFlags_EventMask_); + SameLine(); CheckboxFlags("ActiveId", &g.DebugLogFlags, ImGuiDebugLogFlags_EventActiveId); + SameLine(); CheckboxFlags("Focus", &g.DebugLogFlags, ImGuiDebugLogFlags_EventFocus); + SameLine(); CheckboxFlags("Popup", &g.DebugLogFlags, ImGuiDebugLogFlags_EventPopup); + SameLine(); CheckboxFlags("Nav", &g.DebugLogFlags, ImGuiDebugLogFlags_EventNav); + SameLine(); CheckboxFlags("Docking", &g.DebugLogFlags, ImGuiDebugLogFlags_EventDocking); + SameLine(); CheckboxFlags("Viewport", &g.DebugLogFlags, ImGuiDebugLogFlags_EventViewport); + + if (SmallButton("Clear")) + g.DebugLogBuf.clear(); + SameLine(); + if (SmallButton("Copy")) + SetClipboardText(g.DebugLogBuf.c_str()); + BeginChild("##log", ImVec2(0.0f, 0.0f), true, ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_AlwaysHorizontalScrollbar); + TextUnformatted(g.DebugLogBuf.begin(), g.DebugLogBuf.end()); // FIXME-OPT: Could use a line index, but TextUnformatted() has a semi-decent fast path for large text. + if (GetScrollY() >= GetScrollMaxY()) + SetScrollHereY(1.0f); + EndChild(); + + End(); +} + //----------------------------------------------------------------------------- // [SECTION] OTHER DEBUG TOOLS (ITEM PICKER, STACK TOOL) //----------------------------------------------------------------------------- @@ -18021,18 +18939,26 @@ void ImGui::UpdateDebugToolItemPicker() const ImGuiID hovered_id = g.HoveredIdPreviousFrame; SetMouseCursor(ImGuiMouseCursor_Hand); - if (IsKeyPressedMap(ImGuiKey_Escape)) + if (IsKeyPressed(ImGuiKey_Escape)) g.DebugItemPickerActive = false; - if (IsMouseClicked(0) && hovered_id) + const bool change_mapping = g.IO.KeyMods == (ImGuiModFlags_Ctrl | ImGuiModFlags_Shift); + if (!change_mapping && IsMouseClicked(g.DebugItemPickerMouseButton) && hovered_id) { g.DebugItemPickerBreakId = hovered_id; g.DebugItemPickerActive = false; } - SetNextWindowBgAlpha(0.60f); + for (int mouse_button = 0; mouse_button < 3; mouse_button++) + if (change_mapping && IsMouseClicked(mouse_button)) + g.DebugItemPickerMouseButton = (ImU8)mouse_button; + SetNextWindowBgAlpha(0.70f); BeginTooltip(); Text("HoveredId: 0x%08X", hovered_id); Text("Press ESC to abort picking."); - TextColored(GetStyleColorVec4(hovered_id ? ImGuiCol_Text : ImGuiCol_TextDisabled), "Click to break in debugger!"); + const char* mouse_button_names[] = { "Left", "Right", "Middle" }; + if (change_mapping) + Text("Remap w/ Ctrl+Shift: click anywhere to select new mouse button."); + else + TextColored(GetStyleColorVec4(hovered_id ? ImGuiCol_Text : ImGuiCol_TextDisabled), "Click %s Button to break in debugger! (remap w/ Ctrl+Shift)", mouse_button_names[g.DebugItemPickerMouseButton]); EndTooltip(); } @@ -18101,27 +19027,44 @@ void ImGui::DebugHookIdInfo(ImGuiID id, ImGuiDataType data_type, const void* dat ImGuiStackLevelInfo* info = &tool->Results[tool->StackLevel]; IM_ASSERT(info->ID == id && info->QueryFrameCount > 0); - int data_len; switch (data_type) { case ImGuiDataType_S32: ImFormatString(info->Desc, IM_ARRAYSIZE(info->Desc), "%d", (int)(intptr_t)data_id); break; case ImGuiDataType_String: - data_len = data_id_end ? (int)((const char*)data_id_end - (const char*)data_id) : (int)strlen((const char*)data_id); - ImFormatString(info->Desc, IM_ARRAYSIZE(info->Desc), "\"%.*s\"", data_len, (const char*)data_id); + ImFormatString(info->Desc, IM_ARRAYSIZE(info->Desc), "%.*s", data_id_end ? (int)((const char*)data_id_end - (const char*)data_id) : (int)strlen((const char*)data_id), (const char*)data_id); break; case ImGuiDataType_Pointer: ImFormatString(info->Desc, IM_ARRAYSIZE(info->Desc), "(void*)0x%p", data_id); break; case ImGuiDataType_ID: - if (info->Desc[0] == 0) // PushOverrideID() is often used to avoid hashing twice, which would lead to 2 calls to DebugHookIdInfo(). We prioritize the first one. - ImFormatString(info->Desc, IM_ARRAYSIZE(info->Desc), "0x%08X [override]", id); + if (info->Desc[0] != 0) // PushOverrideID() is often used to avoid hashing twice, which would lead to 2 calls to DebugHookIdInfo(). We prioritize the first one. + return; + ImFormatString(info->Desc, IM_ARRAYSIZE(info->Desc), "0x%08X [override]", id); break; default: IM_ASSERT(0); } info->QuerySuccess = true; + info->DataType = data_type; +} + +static int StackToolFormatLevelInfo(ImGuiStackTool* tool, int n, bool format_for_ui, char* buf, size_t buf_size) +{ + ImGuiStackLevelInfo* info = &tool->Results[n]; + ImGuiWindow* window = (info->Desc[0] == 0 && n == 0) ? ImGui::FindWindowByID(info->ID) : NULL; + if (window) // Source: window name (because the root ID don't call GetID() and so doesn't get hooked) + return ImFormatString(buf, buf_size, format_for_ui ? "\"%s\" [window]" : "%s", window->Name); + if (info->QuerySuccess) // Source: GetID() hooks (prioritize over ItemInfo() because we frequently use patterns like: PushID(str), Button("") where they both have same id) + return ImFormatString(buf, buf_size, (format_for_ui && info->DataType == ImGuiDataType_String) ? "\"%s\"" : "%s", info->Desc); + if (tool->StackLevel < tool->Results.Size) // Only start using fallback below when all queries are done, so during queries we don't flickering ??? markers. + return (*buf = 0); +#ifdef IMGUI_ENABLE_TEST_ENGINE + if (const char* label = ImGuiTestEngine_FindItemDebugLabel(GImGui, info->ID)) // Source: ImGuiTestEngine's ItemInfo() + return ImFormatString(buf, buf_size, format_for_ui ? "??? \"%s\"" : "%s", label); +#endif + return ImFormatString(buf, buf_size, "???"); } // Stack Tool: Display UI @@ -18137,6 +19080,7 @@ void ImGui::ShowStackToolWindow(bool* p_open) } // Display hovered/active status + ImGuiStackTool* tool = &g.DebugStackTool; const ImGuiID hovered_id = g.HoveredIdPreviousFrame; const ImGuiID active_id = g.ActiveId; #ifdef IMGUI_ENABLE_TEST_ENGINE @@ -18147,8 +19091,33 @@ void ImGui::ShowStackToolWindow(bool* p_open) SameLine(); MetricsHelpMarker("Hover an item with the mouse to display elements of the ID Stack leading to the item's final ID.\nEach level of the stack correspond to a PushID() call.\nAll levels of the stack are hashed together to make the final ID of a widget (ID displayed at the bottom level of the stack).\nRead FAQ entry about the ID stack for details."); + // CTRL+C to copy path + const float time_since_copy = (float)g.Time - tool->CopyToClipboardLastTime; + Checkbox("Ctrl+C: copy path to clipboard", &tool->CopyToClipboardOnCtrlC); + SameLine(); + TextColored((time_since_copy >= 0.0f && time_since_copy < 0.75f && ImFmod(time_since_copy, 0.25f) < 0.25f * 0.5f) ? ImVec4(1.f, 1.f, 0.3f, 1.f) : ImVec4(), "*COPIED*"); + if (tool->CopyToClipboardOnCtrlC && IsKeyDown(ImGuiKey_ModCtrl) && IsKeyPressed(ImGuiKey_C)) + { + tool->CopyToClipboardLastTime = (float)g.Time; + char* p = g.TempBuffer.Data; + char* p_end = p + g.TempBuffer.Size; + for (int stack_n = 0; stack_n < tool->Results.Size && p + 3 < p_end; stack_n++) + { + *p++ = '/'; + char level_desc[256]; + StackToolFormatLevelInfo(tool, stack_n, false, level_desc, IM_ARRAYSIZE(level_desc)); + for (int n = 0; level_desc[n] && p + 2 < p_end; n++) + { + if (level_desc[n] == '/') + *p++ = '\\'; + *p++ = level_desc[n]; + } + } + *p = '\0'; + SetClipboardText(g.TempBuffer.Data); + } + // Display decorated stack - ImGuiStackTool* tool = &g.DebugStackTool; tool->LastActiveFrame = g.FrameCount; if (tool->Results.Size > 0 && BeginTable("##table", 3, ImGuiTableFlags_Borders)) { @@ -18162,23 +19131,9 @@ void ImGui::ShowStackToolWindow(bool* p_open) ImGuiStackLevelInfo* info = &tool->Results[n]; TableNextColumn(); Text("0x%08X", (n > 0) ? tool->Results[n - 1].ID : 0); - TableNextColumn(); - ImGuiWindow* window = (info->Desc[0] == 0 && n == 0) ? FindWindowByID(info->ID) : NULL; - if (window) // Source: window name (because the root ID don't call GetID() and so doesn't get hooked) - Text("\"%s\" [window]", window->Name); - else if (info->QuerySuccess) // Source: GetID() hooks (prioritize over ItemInfo() because we frequently use patterns like: PushID(str), Button("") where they both have same id) - TextUnformatted(info->Desc); - else if (tool->StackLevel >= tool->Results.Size) // Only start using fallback below when all queries are done, so during queries we don't flickering ??? markers. - { -#ifdef IMGUI_ENABLE_TEST_ENGINE - if (const char* label = ImGuiTestEngine_FindItemDebugLabel(&g, info->ID)) // Source: ImGuiTestEngine's ItemInfo() - Text("??? \"%s\"", label); - else -#endif - TextUnformatted("???"); - } - + StackToolFormatLevelInfo(tool, n, true, g.TempBuffer.Data, g.TempBuffer.Size); + TextUnformatted(g.TempBuffer.Data); TableNextColumn(); Text("0x%08X", info->ID); if (n == tool->Results.Size - 1) @@ -18204,12 +19159,15 @@ void ImGui::DebugNodeWindowSettings(ImGuiWindowSettings*) {} void ImGui::DebugNodeWindowsList(ImVector*, const char*) {} void ImGui::DebugNodeViewport(ImGuiViewportP*) {} +void ImGui::DebugLog(const char*, ...) {} +void ImGui::DebugLogV(const char*, va_list) {} +void ImGui::ShowDebugLogWindow(bool*) {} void ImGui::ShowStackToolWindow(bool*) {} void ImGui::DebugHookIdInfo(ImGuiID, ImGuiDataType, const void*, const void*) {} void ImGui::UpdateDebugToolItemPicker() {} void ImGui::UpdateDebugToolStackQueries() {} -#endif // #ifndef IMGUI_DISABLE_METRICS_WINDOW +#endif // #ifndef IMGUI_DISABLE_DEBUG_TOOLS //----------------------------------------------------------------------------- diff --git a/lib/external/imgui/source/imgui_demo.cpp b/lib/external/imgui/source/imgui_demo.cpp index 5d6779e9a..47b834166 100644 --- a/lib/external/imgui/source/imgui_demo.cpp +++ b/lib/external/imgui/source/imgui_demo.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.86 +// dear imgui, v1.89 WIP // (demo code) // Help: @@ -39,7 +39,7 @@ // Because we can't assume anything about your support of maths operators, we cannot use them in imgui_demo.cpp. // Navigating this file: -// - In Visual Studio IDE: CTRL+comma ("Edit.NavigateTo") can follow symbols in comments, whereas CTRL+F12 ("Edit.GoToImplementation") cannot. +// - In Visual Studio IDE: CTRL+comma ("Edit.GoToAll") can follow symbols in comments, whereas CTRL+F12 ("Edit.GoToImplementation") cannot. // - With Visual Assist installed: ALT+G ("VAssistX.GoToImplementation") can also follow symbols in comments. /* @@ -93,6 +93,7 @@ Index of this file: // Visual Studio warnings #ifdef _MSC_VER +#pragma warning (disable: 4127) // condition expression is constant #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen #pragma warning (disable: 26451) // [Static Analyzer] Arithmetic overflow : Using operator 'xxx' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator 'xxx' to avoid overflow(io.2). #endif @@ -240,7 +241,6 @@ void ImGui::ShowUserGuide() 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::BulletText("You can apply arithmetic operators +,*,/ on numerical values.\nUse +- to subtract."); ImGui::Unindent(); ImGui::BulletText("With keyboard navigation enabled:"); ImGui::Indent(); @@ -316,13 +316,19 @@ void ImGui::ShowDemoWindow(bool* p_open) // Dear ImGui Apps (accessible from the "Tools" menu) static bool show_app_metrics = false; + static bool show_app_debug_log = false; static bool show_app_stack_tool = false; - static bool show_app_style_editor = false; static bool show_app_about = false; + static bool show_app_style_editor = false; - if (show_app_metrics) { ImGui::ShowMetricsWindow(&show_app_metrics); } - if (show_app_stack_tool) { ImGui::ShowStackToolWindow(&show_app_stack_tool); } - if (show_app_about) { ImGui::ShowAboutWindow(&show_app_about); } + if (show_app_metrics) + ImGui::ShowMetricsWindow(&show_app_metrics); + if (show_app_debug_log) + ImGui::ShowDebugLogWindow(&show_app_debug_log); + if (show_app_stack_tool) + ImGui::ShowStackToolWindow(&show_app_stack_tool); + if (show_app_about) + ImGui::ShowAboutWindow(&show_app_about); if (show_app_style_editor) { ImGui::Begin("Dear ImGui Style Editor", &show_app_style_editor); @@ -412,10 +418,14 @@ void ImGui::ShowDemoWindow(bool* p_open) if (ImGui::BeginMenu("Tools")) { IMGUI_DEMO_MARKER("Menu/Tools"); -#ifndef IMGUI_DISABLE_METRICS_WINDOW - ImGui::MenuItem("Metrics/Debugger", NULL, &show_app_metrics); - ImGui::MenuItem("Stack Tool", NULL, &show_app_stack_tool); +#ifndef IMGUI_DISABLE_DEBUG_TOOLS + const bool has_debug_tools = true; +#else + const bool has_debug_tools = false; #endif + ImGui::MenuItem("Metrics/Debugger", NULL, &show_app_metrics, has_debug_tools); + ImGui::MenuItem("Debug Log", NULL, &show_app_debug_log, has_debug_tools); + ImGui::MenuItem("Stack Tool", NULL, &show_app_stack_tool, has_debug_tools); ImGui::MenuItem("Style Editor", NULL, &show_app_style_editor); ImGui::MenuItem("About Dear ImGui", NULL, &show_app_about); ImGui::EndMenu(); @@ -423,7 +433,7 @@ void ImGui::ShowDemoWindow(bool* p_open) ImGui::EndMenuBar(); } - ImGui::Text("dear imgui says hello. (%s)", IMGUI_VERSION); + ImGui::Text("dear imgui says hello! (%s) (%d)", IMGUI_VERSION, IMGUI_VERSION_NUM); ImGui::Spacing(); IMGUI_DEMO_MARKER("Help"); @@ -471,7 +481,7 @@ void ImGui::ShowDemoWindow(bool* p_open) ImGui::SameLine(); ImGui::Text("<>"); } - if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Space))) + if (ImGui::IsKeyPressed(ImGuiKey_Space)) io.ConfigFlags &= ~ImGuiConfigFlags_NoMouse; } ImGui::CheckboxFlags("io.ConfigFlags: NoMouseCursorChange", &io.ConfigFlags, ImGuiConfigFlags_NoMouseCursorChange); @@ -513,8 +523,12 @@ void ImGui::ShowDemoWindow(bool* p_open) ImGui::Unindent(); } + ImGui::Checkbox("io.ConfigInputTrickleEventQueue", &io.ConfigInputTrickleEventQueue); + 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."); ImGui::Checkbox("io.ConfigInputTextCursorBlink", &io.ConfigInputTextCursorBlink); - ImGui::SameLine(); HelpMarker("Enable blinking cursor (optional as some users consider it to be distracting)"); + 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)."); ImGui::Checkbox("io.ConfigWindowsResizeFromEdges", &io.ConfigWindowsResizeFromEdges); @@ -535,6 +549,7 @@ void ImGui::ShowDemoWindow(bool* p_open) "Here we expose them as read-only fields to avoid breaking interactions with your backend."); // Make a local copy to avoid modifying actual backend flags. + // FIXME: We don't use BeginDisabled() to keep label bright, maybe we need a BeginReadonly() equivalent.. ImGuiBackendFlags backend_flags = io.BackendFlags; ImGui::CheckboxFlags("io.BackendFlags: HasGamepad", &backend_flags, ImGuiBackendFlags_HasGamepad); ImGui::CheckboxFlags("io.BackendFlags: HasMouseCursors", &backend_flags, ImGuiBackendFlags_HasMouseCursors); @@ -731,10 +746,6 @@ static void ShowDemoWindowWidgets() IMGUI_DEMO_MARKER("Widgets/Basic/InputInt, InputFloat"); static int i0 = 123; ImGui::InputInt("input int", &i0); - ImGui::SameLine(); HelpMarker( - "You can apply arithmetic operators +,*,/ on numerical values.\n" - " e.g. [ 100 ], input \'*2\', result becomes [ 200 ]\n" - "Use +- to subtract."); static float f0 = 0.001f; ImGui::InputFloat("input float", &f0, 0.01f, 1.0f, "%.3f"); @@ -1914,10 +1925,9 @@ static void ShowDemoWindowWidgets() ImGui::Combo("Display Mode", &display_mode, "Auto/Current\0None\0RGB Only\0HSV Only\0Hex Only\0"); ImGui::SameLine(); HelpMarker( "ColorEdit defaults to displaying RGB inputs if you don't specify a display mode, " - "but the user can change it with a right-click.\n\nColorPicker defaults to displaying RGB+HSV+Hex " + "but the user can change it with a right-click on those inputs.\n\nColorPicker defaults to displaying RGB+HSV+Hex " "if you don't specify a display mode.\n\nYou can change the defaults using SetColorEditOptions()."); - ImGui::Combo("Picker Mode", &picker_mode, "Auto/Current\0Hue bar + SV rect\0Hue wheel + SV triangle\0"); - ImGui::SameLine(); HelpMarker("User can right-click the picker to change mode."); + ImGui::SameLine(); HelpMarker("When not specified explicitly (Auto/Current mode), user can right-click the picker to change mode."); ImGuiColorEditFlags flags = misc_flags; if (!alpha) flags |= ImGuiColorEditFlags_NoAlpha; // This is by default if you call ColorPicker3() instead of ColorPicker4() if (alpha_bar) flags |= ImGuiColorEditFlags_AlphaBar; @@ -1941,6 +1951,15 @@ static void ShowDemoWindowWidgets() if (ImGui::Button("Default: Float + HDR + Hue Wheel")) ImGui::SetColorEditOptions(ImGuiColorEditFlags_Float | ImGuiColorEditFlags_HDR | ImGuiColorEditFlags_PickerHueWheel); + // Always both a small version of both types of pickers (to make it more visible in the demo to people who are skimming quickly through it) + 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); + // HSV encoded support (to avoid RGB<>HSV round trips and singularities when S==0 or V==0) static ImVec4 color_hsv(0.23f, 1.0f, 1.0f, 1.0f); // Stored as HSV! ImGui::Spacing(); @@ -2063,6 +2082,7 @@ static void ShowDemoWindowWidgets() ImGui::DragScalar("drag s16", ImGuiDataType_S16, &s16_v, drag_speed, drag_clamp ? &s16_zero : NULL, drag_clamp ? &s16_fifty : NULL); ImGui::DragScalar("drag u16", ImGuiDataType_U16, &u16_v, drag_speed, drag_clamp ? &u16_zero : NULL, drag_clamp ? &u16_fifty : NULL, "%u ms"); ImGui::DragScalar("drag s32", ImGuiDataType_S32, &s32_v, drag_speed, drag_clamp ? &s32_zero : NULL, drag_clamp ? &s32_fifty : NULL); + ImGui::DragScalar("drag s32 hex", ImGuiDataType_S32, &s32_v, drag_speed, drag_clamp ? &s32_zero : NULL, drag_clamp ? &s32_fifty : NULL, "0x%08X"); 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); @@ -2080,6 +2100,7 @@ static void ShowDemoWindowWidgets() 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"); + ImGui::SliderScalar("slider s32 hex", ImGuiDataType_S32, &s32_v, &s32_zero, &s32_fifty, "0x%04X"); 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"); @@ -2113,9 +2134,9 @@ static void ShowDemoWindowWidgets() ImGui::InputScalar("input s16", ImGuiDataType_S16, &s16_v, inputs_step ? &s16_one : NULL, NULL, "%d"); ImGui::InputScalar("input u16", ImGuiDataType_U16, &u16_v, inputs_step ? &u16_one : NULL, NULL, "%u"); ImGui::InputScalar("input s32", ImGuiDataType_S32, &s32_v, inputs_step ? &s32_one : NULL, NULL, "%d"); - ImGui::InputScalar("input s32 hex", ImGuiDataType_S32, &s32_v, inputs_step ? &s32_one : NULL, NULL, "%08X", ImGuiInputTextFlags_CharsHexadecimal); + ImGui::InputScalar("input s32 hex", ImGuiDataType_S32, &s32_v, inputs_step ? &s32_one : NULL, NULL, "%04X"); ImGui::InputScalar("input u32", ImGuiDataType_U32, &u32_v, inputs_step ? &u32_one : NULL, NULL, "%u"); - ImGui::InputScalar("input u32 hex", ImGuiDataType_U32, &u32_v, inputs_step ? &u32_one : NULL, NULL, "%08X", ImGuiInputTextFlags_CharsHexadecimal); + ImGui::InputScalar("input u32 hex", ImGuiDataType_U32, &u32_v, inputs_step ? &u32_one : NULL, NULL, "%08X"); ImGui::InputScalar("input s64", ImGuiDataType_S64, &s64_v, inputs_step ? &s64_one : NULL); ImGui::InputScalar("input u64", ImGuiDataType_U64, &u64_v, inputs_step ? &u64_one : NULL); ImGui::InputScalar("input float", ImGuiDataType_Float, &f32_v, inputs_step ? &f32_one : NULL); @@ -3266,59 +3287,58 @@ static void ShowDemoWindowLayout() ImGui::DragFloat2("size", (float*)&size, 0.5f, 1.0f, 200.0f, "%.0f"); ImGui::TextWrapped("(Click and drag to scroll)"); + 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."); + for (int n = 0; n < 3; n++) { if (n > 0) ImGui::SameLine(); - ImGui::PushID(n); - ImGui::BeginGroup(); // Lock X position - ImGui::InvisibleButton("##empty", size); + ImGui::PushID(n); + ImGui::InvisibleButton("##canvas", size); if (ImGui::IsItemActive() && ImGui::IsMouseDragging(ImGuiMouseButton_Left)) { offset.x += ImGui::GetIO().MouseDelta.x; offset.y += ImGui::GetIO().MouseDelta.y; } + ImGui::PopID(); + if (!ImGui::IsItemVisible()) // Skip rendering as ImDrawList elements are not clipped. + continue; + const ImVec2 p0 = ImGui::GetItemRectMin(); const ImVec2 p1 = ImGui::GetItemRectMax(); const char* text_str = "Line 1 hello\nLine 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: - HelpMarker( - "Using ImGui::PushClipRect():\n" - "Will alter ImGui hit-testing logic + ImDrawList rendering.\n" - "(use this if you want your clipping rectangle to affect interactions)"); 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: - HelpMarker( - "Using ImDrawList::PushClipRect():\n" - "Will alter ImDrawList rendering only.\n" - "(use this as a shortcut if you are only using ImDrawList calls)"); 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: - HelpMarker( - "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)"); 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; } - ImGui::EndGroup(); - ImGui::PopID(); } ImGui::TreePop(); @@ -3484,7 +3504,7 @@ static void ShowDemoWindowPopups() { HelpMarker("Text() elements don't have stable identifiers so we need to provide one."); static float value = 0.5f; - ImGui::Text("Value = %.3f <-- (1) right-click this value", value); + ImGui::Text("Value = %.3f <-- (1) right-click this text", value); if (ImGui::BeginPopupContextItem("my popup")) { if (ImGui::Selectable("Set to zero")) value = 0.0f; @@ -3611,19 +3631,12 @@ static void ShowDemoWindowPopups() ImGui::TextWrapped("Below we are testing adding menu items to a regular window. It's rather unusual but should work!"); ImGui::Separator(); - // Note: As a quirk in this very specific example, we want to differentiate the parent of this menu from the - // parent of the various popup menus above. To do so we are encloding the items in a PushID()/PopID() block - // to make them two different menusets. If we don't, opening any popup above and hovering our menu here would - // open it. This is because once a menu is active, we allow to switch to a sibling menu by just hovering on it, - // which is the desired behavior for regular menus. - ImGui::PushID("foo"); ImGui::MenuItem("Menu item", "CTRL+M"); if (ImGui::BeginMenu("Menu inside a regular window")) { ShowExampleMenuFile(); ImGui::EndMenu(); } - ImGui::PopID(); ImGui::Separator(); ImGui::TreePop(); } @@ -3947,7 +3960,7 @@ static void ShowDemoWindowTables() sprintf(buf, "Hello %d,%d", column, row); if (contents_type == CT_Text) ImGui::TextUnformatted(buf); - else if (contents_type) + else if (contents_type == CT_FillButton) ImGui::Button(buf, ImVec2(-FLT_MIN, 0.0f)); } } @@ -4491,14 +4504,16 @@ static void ShowDemoWindowTables() { ImGui::TableNextColumn(); ImGui::PushID(column); - ImGui::AlignTextToFramePadding(); // FIXME-TABLE: Workaround for wrong text baseline propagation + ImGui::AlignTextToFramePadding(); // FIXME-TABLE: Workaround for wrong text baseline propagation across columns ImGui::Text("'%s'", column_names[column]); ImGui::Spacing(); ImGui::Text("Input flags:"); EditTableColumnsFlags(&column_flags[column]); ImGui::Spacing(); ImGui::Text("Output flags:"); + ImGui::BeginDisabled(); ShowTableColumnsStatusFlags(column_flags_out[column]); + ImGui::EndDisabled(); ImGui::PopID(); } PopStyleCompact(); @@ -4903,7 +4918,7 @@ static void ShowDemoWindowTables() ImGui::TableSetColumnIndex(1); ImGui::SliderFloat("float1", &dummy_f, 0.0f, 1.0f); ImGui::TableSetColumnIndex(2); - ImGui::SliderFloat("float2", &dummy_f, 0.0f, 1.0f); + ImGui::SliderFloat("##float2", &dummy_f, 0.0f, 1.0f); // No visible label since right-aligned ImGui::PopID(); } ImGui::EndTable(); @@ -5712,6 +5727,8 @@ static void ShowDemoWindowColumns() ImGui::TreePop(); } +namespace ImGui { extern ImGuiKeyData* GetKeyData(ImGuiKey key); } + static void ShowDemoWindowMisc() { IMGUI_DEMO_MARKER("Filtering"); @@ -5738,12 +5755,18 @@ static void ShowDemoWindowMisc() ImGuiIO& io = ImGui::GetIO(); // Display ImGuiIO output flags - ImGui::Text("WantCaptureMouse: %d", io.WantCaptureMouse); - ImGui::Text("WantCaptureMouseUnlessPopupClose: %d", io.WantCaptureMouseUnlessPopupClose); - ImGui::Text("WantCaptureKeyboard: %d", io.WantCaptureKeyboard); - ImGui::Text("WantTextInput: %d", io.WantTextInput); - ImGui::Text("WantSetMousePos: %d", io.WantSetMousePos); - ImGui::Text("NavActive: %d, NavVisible: %d", io.NavActive, io.NavVisible); + IMGUI_DEMO_MARKER("Inputs, Navigation & Focus/Output"); + ImGui::SetNextItemOpen(true, ImGuiCond_Once); + if (ImGui::TreeNode("Output")) + { + ImGui::Text("io.WantCaptureMouse: %d", io.WantCaptureMouse); + ImGui::Text("io.WantCaptureMouseUnlessPopupClose: %d", io.WantCaptureMouseUnlessPopupClose); + ImGui::Text("io.WantCaptureKeyboard: %d", io.WantCaptureKeyboard); + 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); + ImGui::TreePop(); + } // Display Mouse state IMGUI_DEMO_MARKER("Inputs, Navigation & Focus/Mouse State"); @@ -5765,25 +5788,108 @@ static void ShowDemoWindowMisc() } // Display Keyboard/Mouse state - IMGUI_DEMO_MARKER("Inputs, Navigation & Focus/Keyboard & Navigation State"); - if (ImGui::TreeNode("Keyboard & Navigation State")) + IMGUI_DEMO_MARKER("Inputs, Navigation & Focus/Keyboard, Gamepad & Navigation State"); + if (ImGui::TreeNode("Keyboard, Gamepad & Navigation State")) { - ImGui::Text("Keys down:"); for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); i++) if (ImGui::IsKeyDown(i)) { ImGui::SameLine(); ImGui::Text("%d (0x%X) (%.02f secs)", i, i, io.KeysDownDuration[i]); } - ImGui::Text("Keys pressed:"); for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); i++) if (ImGui::IsKeyPressed(i)) { ImGui::SameLine(); ImGui::Text("%d (0x%X)", i, i); } - ImGui::Text("Keys release:"); for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); i++) if (ImGui::IsKeyReleased(i)) { ImGui::SameLine(); ImGui::Text("%d (0x%X)", i, i); } + // We iterate both legacy native range and named ImGuiKey ranges, which is a little odd but this allow displaying the data for old/new backends. + // User code should never have to go through such hoops: old code may use native keycodes, new code may use ImGuiKey codes. +#ifdef IMGUI_DISABLE_OBSOLETE_KEYIO + struct funcs { static bool IsLegacyNativeDupe(ImGuiKey) { return false; } }; + const ImGuiKey key_first = ImGuiKey_NamedKey_BEGIN; +#else + struct funcs { static bool IsLegacyNativeDupe(ImGuiKey key) { return key < 512 && ImGui::GetIO().KeyMap[key] != -1; } }; // Hide Native<>ImGuiKey duplicates when both exists in the array + const ImGuiKey key_first = 0; + //ImGui::Text("Legacy raw:"); for (ImGuiKey key = key_first; key < ImGuiKey_COUNT; key++) { if (io.KeysDown[key]) { ImGui::SameLine(); ImGui::Text("\"%s\" %d", ImGui::GetKeyName(key), key); } } +#endif + ImGui::Text("Keys down:"); for (ImGuiKey key = key_first; key < ImGuiKey_COUNT; key++) { if (funcs::IsLegacyNativeDupe(key)) continue; if (ImGui::IsKeyDown(key)) { ImGui::SameLine(); ImGui::Text("\"%s\" %d (%.02f secs)", ImGui::GetKeyName(key), key, ImGui::GetKeyData(key)->DownDuration); } } + ImGui::Text("Keys pressed:"); for (ImGuiKey key = key_first; key < ImGuiKey_COUNT; key++) { if (funcs::IsLegacyNativeDupe(key)) continue; if (ImGui::IsKeyPressed(key)) { ImGui::SameLine(); ImGui::Text("\"%s\" %d", ImGui::GetKeyName(key), key); } } + ImGui::Text("Keys released:"); for (ImGuiKey key = key_first; key < ImGuiKey_COUNT; key++) { if (funcs::IsLegacyNativeDupe(key)) continue; if (ImGui::IsKeyReleased(key)) { ImGui::SameLine(); ImGui::Text("\"%s\" %d", ImGui::GetKeyName(key), key); } } ImGui::Text("Keys mods: %s%s%s%s", io.KeyCtrl ? "CTRL " : "", io.KeyShift ? "SHIFT " : "", io.KeyAlt ? "ALT " : "", io.KeySuper ? "SUPER " : ""); ImGui::Text("Chars queue:"); for (int i = 0; i < io.InputQueueCharacters.Size; i++) { ImWchar c = io.InputQueueCharacters[i]; ImGui::SameLine(); ImGui::Text("\'%c\' (0x%04X)", (c > ' ' && c <= 255) ? (char)c : '?', c); } // FIXME: We should convert 'c' to UTF-8 here but the functions are not public. - ImGui::Text("NavInputs down:"); for (int i = 0; i < IM_ARRAYSIZE(io.NavInputs); i++) if (io.NavInputs[i] > 0.0f) { ImGui::SameLine(); ImGui::Text("[%d] %.2f (%.02f secs)", i, io.NavInputs[i], io.NavInputsDownDuration[i]); } - ImGui::Text("NavInputs pressed:"); for (int i = 0; i < IM_ARRAYSIZE(io.NavInputs); i++) if (io.NavInputsDownDuration[i] == 0.0f) { ImGui::SameLine(); ImGui::Text("[%d]", i); } + // Draw an arbitrary US keyboard layout to visualize translated keys + { + const ImVec2 key_size = ImVec2(35.0f, 35.0f); + const float key_rounding = 3.0f; + const ImVec2 key_face_size = ImVec2(25.0f, 25.0f); + const ImVec2 key_face_pos = ImVec2(5.0f, 3.0f); + const float key_face_rounding = 2.0f; + const ImVec2 key_label_pos = ImVec2(7.0f, 4.0f); + const ImVec2 key_step = ImVec2(key_size.x - 1.0f, key_size.y - 1.0f); + const float key_row_offset = 9.0f; + + ImVec2 board_min = ImGui::GetCursorScreenPos(); + ImVec2 board_max = ImVec2(board_min.x + 3 * key_step.x + 2 * key_row_offset + 10.0f, board_min.y + 3 * key_step.y + 10.0f); + ImVec2 start_pos = ImVec2(board_min.x + 5.0f - key_step.x, board_min.y); + + struct KeyLayoutData { int Row, Col; const char* Label; ImGuiKey Key; }; + const KeyLayoutData keys_to_display[] = + { + { 0, 0, "", ImGuiKey_Tab }, { 0, 1, "Q", ImGuiKey_Q }, { 0, 2, "W", ImGuiKey_W }, { 0, 3, "E", ImGuiKey_E }, { 0, 4, "R", ImGuiKey_R }, + { 1, 0, "", ImGuiKey_CapsLock }, { 1, 1, "A", ImGuiKey_A }, { 1, 2, "S", ImGuiKey_S }, { 1, 3, "D", ImGuiKey_D }, { 1, 4, "F", ImGuiKey_F }, + { 2, 0, "", ImGuiKey_LeftShift },{ 2, 1, "Z", ImGuiKey_Z }, { 2, 2, "X", ImGuiKey_X }, { 2, 3, "C", ImGuiKey_C }, { 2, 4, "V", ImGuiKey_V } + }; + + // Elements rendered manually via ImDrawList API are not clipped automatically. + // While not strictly necessary, here IsItemVisible() is used to avoid rendering these shapes when they are out of view. + ImGui::Dummy(ImVec2(board_max.x - board_min.x, board_max.y - board_min.y)); + if (ImGui::IsItemVisible()) + { + ImDrawList* draw_list = ImGui::GetWindowDrawList(); + draw_list->PushClipRect(board_min, board_max, true); + for (int n = 0; n < IM_ARRAYSIZE(keys_to_display); n++) + { + const KeyLayoutData* key_data = &keys_to_display[n]; + ImVec2 key_min = ImVec2(start_pos.x + key_data->Col * key_step.x + key_data->Row * key_row_offset, start_pos.y + key_data->Row * key_step.y); + ImVec2 key_max = ImVec2(key_min.x + key_size.x, key_min.y + key_size.y); + draw_list->AddRectFilled(key_min, key_max, IM_COL32(204, 204, 204, 255), key_rounding); + draw_list->AddRect(key_min, key_max, IM_COL32(24, 24, 24, 255), key_rounding); + ImVec2 face_min = ImVec2(key_min.x + key_face_pos.x, key_min.y + key_face_pos.y); + ImVec2 face_max = ImVec2(face_min.x + key_face_size.x, face_min.y + key_face_size.y); + draw_list->AddRect(face_min, face_max, IM_COL32(193, 193, 193, 255), key_face_rounding, ImDrawFlags_None, 2.0f); + draw_list->AddRectFilled(face_min, face_max, IM_COL32(252, 252, 252, 255), key_face_rounding); + ImVec2 label_min = ImVec2(key_min.x + key_label_pos.x, key_min.y + key_label_pos.y); + draw_list->AddText(label_min, IM_COL32(64, 64, 64, 255), key_data->Label); + if (ImGui::IsKeyDown(key_data->Key)) + draw_list->AddRectFilled(key_min, key_max, IM_COL32(255, 0, 0, 128), key_rounding); + } + draw_list->PopClipRect(); + } + } + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Capture override")) + { + 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)."); + + ImGui::Text("io.WantCaptureMouse: %d", io.WantCaptureMouse); + ImGui::Text("io.WantCaptureMouseUnlessPopupClose: %d", io.WantCaptureMouseUnlessPopupClose); + ImGui::Text("io.WantCaptureKeyboard: %d", io.WantCaptureKeyboard); + + HelpMarker( + "Hovering the colored canvas will override io.WantCaptureXXX fields.\n" + "Notice how normally (when set to none), the value of io.WantCaptureKeyboard would be false when hovering and true when clicking."); + 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()", &capture_override_mouse, -1, +1, capture_override_desc[capture_override_mouse + 1], ImGuiSliderFlags_AlwaysClamp); + ImGui::SetNextItemWidth(ImGui::GetFontSize() * 15); + ImGui::SliderInt("SetNextFrameWantCaptureKeyboard()", &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(256.0f, 192.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); - ImGui::Button("Hovering me sets the\nkeyboard capture flag"); - if (ImGui::IsItemHovered()) - ImGui::CaptureKeyboardFromApp(true); - ImGui::SameLine(); - ImGui::Button("Holding me clears the\nthe keyboard capture flag"); - if (ImGui::IsItemActive()) - ImGui::CaptureKeyboardFromApp(false); ImGui::TreePop(); } @@ -5941,6 +6047,9 @@ void ImGui::ShowAboutWindow(bool* p_open) #ifdef IMGUI_DISABLE_OBSOLETE_FUNCTIONS ImGui::Text("define: IMGUI_DISABLE_OBSOLETE_FUNCTIONS"); #endif +#ifdef IMGUI_DISABLE_OBSOLETE_KEYIO + ImGui::Text("define: IMGUI_DISABLE_OBSOLETE_KEYIO"); +#endif #ifdef IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS ImGui::Text("define: IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS"); #endif @@ -6075,7 +6184,7 @@ void ImGui::ShowAboutWindow(bool* p_open) namespace ImGui { IMGUI_API void ShowFontAtlas(ImFontAtlas* atlas); } // Demo helper function to select among loaded fonts. -// Here we use the regular BeginCombo()/EndCombo() api which is more the more flexible one. +// Here we use the regular BeginCombo()/EndCombo() api which is the more flexible one. void ImGui::ShowFontSelector(const char* label) { ImGuiIO& io = ImGui::GetIO(); @@ -7353,7 +7462,7 @@ static void ShowExampleAppSimpleOverlay(bool* p_open) static void ShowExampleAppFullscreen(bool* p_open) { static bool use_work_area = true; - static ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings; + static ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings; // We demonstrate using the full viewport area or the work area (without menu-bars, task-bars etc.) // Based on your use case you may want one of the other. @@ -7606,8 +7715,8 @@ static void ShowExampleAppCustomRendering(bool* p_open) // Context menu (under default mouse threshold) ImVec2 drag_delta = ImGui::GetMouseDragDelta(ImGuiMouseButton_Right); - if (opt_enable_context_menu && ImGui::IsMouseReleased(ImGuiMouseButton_Right) && drag_delta.x == 0.0f && drag_delta.y == 0.0f) - ImGui::OpenPopupOnItemClick("context"); + if (opt_enable_context_menu && drag_delta.x == 0.0f && drag_delta.y == 0.0f) + ImGui::OpenPopupOnItemClick("context", ImGuiPopupFlags_MouseButtonRight); if (ImGui::BeginPopup("context")) { if (adding_line) @@ -7930,7 +8039,8 @@ void ShowExampleAppDocuments(bool* p_open) if (ImGui::MenuItem("Close All Documents", NULL, false, open_count > 0)) for (int doc_n = 0; doc_n < app.Documents.Size; doc_n++) app.Documents[doc_n].DoQueueClose(); - if (ImGui::MenuItem("Exit", "Alt+F4")) {} + if (ImGui::MenuItem("Exit", "Ctrl+F4") && p_open) + *p_open = false; ImGui::EndMenu(); } ImGui::EndMenuBar(); diff --git a/lib/external/imgui/source/imgui_draw.cpp b/lib/external/imgui/source/imgui_draw.cpp index 80ef77d3d..1998cb94b 100644 --- a/lib/external/imgui/source/imgui_draw.cpp +++ b/lib/external/imgui/source/imgui_draw.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.86 +// dear imgui, v1.89 WIP // (drawing and font code) /* @@ -35,7 +35,7 @@ Index of this file: #include "imgui_internal.h" #ifdef IMGUI_ENABLE_FREETYPE -#include "misc/freetype/imgui_freetype.h" +#include "imgui_freetype.h" // IMHEX PATCH #endif #include // vsnprintf, sscanf, printf @@ -90,7 +90,7 @@ Index of this file: #endif //------------------------------------------------------------------------- -// [SECTION] STB libraries implementation +// [SECTION] STB libraries implementation (for stb_truetype and stb_rect_pack) //------------------------------------------------------------------------- // Compile time options: @@ -399,7 +399,7 @@ void ImDrawListSharedData::SetCircleTessellationMaxError(float max_error) for (int i = 0; i < IM_ARRAYSIZE(CircleSegmentCounts); i++) { const float radius = (float)i; - CircleSegmentCounts[i] = (ImU8)((i > 0) ? IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_CALC(radius, CircleSegmentMaxError) : 0); + CircleSegmentCounts[i] = (ImU8)((i > 0) ? IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_CALC(radius, CircleSegmentMaxError) : IM_DRAWLIST_ARCFAST_SAMPLE_MAX); } ArcFastRadiusCutoff = IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_CALC_R(IM_DRAWLIST_ARCFAST_SAMPLE_MAX, CircleSegmentMaxError); } @@ -408,10 +408,9 @@ void ImDrawListSharedData::SetCircleTessellationMaxError(float max_error) void ImDrawList::_ResetForNewFrame() { // Verify that the ImDrawCmd fields we want to memcmp() are contiguous in memory. - // (those should be IM_STATIC_ASSERT() in theory but with our pre C++11 setup the whole check doesn't compile with GCC) - IM_ASSERT(IM_OFFSETOF(ImDrawCmd, ClipRect) == 0); - IM_ASSERT(IM_OFFSETOF(ImDrawCmd, TextureId) == sizeof(ImVec4)); - IM_ASSERT(IM_OFFSETOF(ImDrawCmd, VtxOffset) == sizeof(ImVec4) + sizeof(ImTextureID)); + IM_STATIC_ASSERT(IM_OFFSETOF(ImDrawCmd, ClipRect) == 0); + IM_STATIC_ASSERT(IM_OFFSETOF(ImDrawCmd, TextureId) == sizeof(ImVec4)); + IM_STATIC_ASSERT(IM_OFFSETOF(ImDrawCmd, VtxOffset) == sizeof(ImVec4) + sizeof(ImTextureID)); if (_Splitter._Count > 1) _Splitter.Merge(this); @@ -496,9 +495,10 @@ void ImDrawList::AddCallback(ImDrawCallback callback, void* callback_data) } // Compare ClipRect, TextureId and VtxOffset with a single memcmp() -#define ImDrawCmd_HeaderSize (IM_OFFSETOF(ImDrawCmd, VtxOffset) + sizeof(unsigned int)) -#define ImDrawCmd_HeaderCompare(CMD_LHS, CMD_RHS) (memcmp(CMD_LHS, CMD_RHS, ImDrawCmd_HeaderSize)) // Compare ClipRect, TextureId, VtxOffset -#define ImDrawCmd_HeaderCopy(CMD_DST, CMD_SRC) (memcpy(CMD_DST, CMD_SRC, ImDrawCmd_HeaderSize)) // Copy ClipRect, TextureId, VtxOffset +#define ImDrawCmd_HeaderSize (IM_OFFSETOF(ImDrawCmd, VtxOffset) + sizeof(unsigned int)) +#define ImDrawCmd_HeaderCompare(CMD_LHS, CMD_RHS) (memcmp(CMD_LHS, CMD_RHS, ImDrawCmd_HeaderSize)) // Compare ClipRect, TextureId, VtxOffset +#define ImDrawCmd_HeaderCopy(CMD_DST, CMD_SRC) (memcpy(CMD_DST, CMD_SRC, ImDrawCmd_HeaderSize)) // Copy ClipRect, TextureId, VtxOffset +#define ImDrawCmd_AreSequentialIdxOffset(CMD_0, CMD_1) (CMD_0->IdxOffset + CMD_0->ElemCount == CMD_1->IdxOffset) // Try to merge two last draw commands void ImDrawList::_TryMergeDrawCmds() @@ -506,7 +506,7 @@ void ImDrawList::_TryMergeDrawCmds() IM_ASSERT_PARANOID(CmdBuffer.Size > 0); ImDrawCmd* curr_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1]; ImDrawCmd* prev_cmd = curr_cmd - 1; - if (ImDrawCmd_HeaderCompare(curr_cmd, prev_cmd) == 0 && curr_cmd->UserCallback == NULL && prev_cmd->UserCallback == NULL) + if (ImDrawCmd_HeaderCompare(curr_cmd, prev_cmd) == 0 && ImDrawCmd_AreSequentialIdxOffset(prev_cmd, curr_cmd) && curr_cmd->UserCallback == NULL && prev_cmd->UserCallback == NULL) { prev_cmd->ElemCount += curr_cmd->ElemCount; CmdBuffer.pop_back(); @@ -529,7 +529,7 @@ void ImDrawList::_OnChangedClipRect() // Try to merge with previous command if it matches, else use current command ImDrawCmd* prev_cmd = curr_cmd - 1; - if (curr_cmd->ElemCount == 0 && CmdBuffer.Size > 1 && ImDrawCmd_HeaderCompare(&_CmdHeader, prev_cmd) == 0 && prev_cmd->UserCallback == NULL) + if (curr_cmd->ElemCount == 0 && CmdBuffer.Size > 1 && ImDrawCmd_HeaderCompare(&_CmdHeader, prev_cmd) == 0 && ImDrawCmd_AreSequentialIdxOffset(prev_cmd, curr_cmd) && prev_cmd->UserCallback == NULL) { CmdBuffer.pop_back(); return; @@ -552,7 +552,7 @@ void ImDrawList::_OnChangedTextureID() // Try to merge with previous command if it matches, else use current command ImDrawCmd* prev_cmd = curr_cmd - 1; - if (curr_cmd->ElemCount == 0 && CmdBuffer.Size > 1 && ImDrawCmd_HeaderCompare(&_CmdHeader, prev_cmd) == 0 && prev_cmd->UserCallback == NULL) + if (curr_cmd->ElemCount == 0 && CmdBuffer.Size > 1 && ImDrawCmd_HeaderCompare(&_CmdHeader, prev_cmd) == 0 && ImDrawCmd_AreSequentialIdxOffset(prev_cmd, curr_cmd) && prev_cmd->UserCallback == NULL) { CmdBuffer.pop_back(); return; @@ -588,7 +588,7 @@ int ImDrawList::_CalcCircleAutoSegmentCount(float radius) const } // Render-level scissoring. This is passed down to your render function but not used for CPU-side coarse clipping. Prefer using higher-level ImGui::PushClipRect() to affect logic (hit-testing and widget culling) -void ImDrawList::PushClipRect(ImVec2 cr_min, ImVec2 cr_max, bool intersect_with_current_clip_rect) +void ImDrawList::PushClipRect(const ImVec2& cr_min, const ImVec2& cr_max, bool intersect_with_current_clip_rect) { ImVec4 cr(cr_min.x, cr_min.y, cr_max.x, cr_max.y); if (intersect_with_current_clip_rect) @@ -981,7 +981,8 @@ void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32 } } -// We intentionally avoid using ImVec2 and its math operators here to reduce cost to a minimum for debug/non-inlined builds. +// - We intentionally avoid using ImVec2 and its math operators here to reduce cost to a minimum for debug/non-inlined builds. +// - Filled shapes must always use clockwise winding order. The anti-aliasing fringe depends on it. Counter-clockwise shapes will have "inward" anti-aliasing. void ImDrawList::AddConvexPolyFilled(const ImVec2* points, const int points_count, ImU32 col) { if (points_count < 3) @@ -1065,7 +1066,7 @@ void ImDrawList::AddConvexPolyFilled(const ImVec2* points, const int points_coun void ImDrawList::_PathArcToFastEx(const ImVec2& center, float radius, int a_min_sample, int a_max_sample, int a_step) { - if (radius <= 0.0f) + if (radius < 0.5f) { _Path.push_back(center); return; @@ -1157,7 +1158,7 @@ void ImDrawList::_PathArcToFastEx(const ImVec2& center, float radius, int a_min_ void ImDrawList::_PathArcToN(const ImVec2& center, float radius, float a_min, float a_max, int num_segments) { - if (radius <= 0.0f) + if (radius < 0.5f) { _Path.push_back(center); return; @@ -1176,7 +1177,7 @@ void ImDrawList::_PathArcToN(const ImVec2& center, float radius, float a_min, fl // 0: East, 3: South, 6: West, 9: North, 12: East void ImDrawList::PathArcToFast(const ImVec2& center, float radius, int a_min_of_12, int a_max_of_12) { - if (radius <= 0.0f) + if (radius < 0.5f) { _Path.push_back(center); return; @@ -1186,7 +1187,7 @@ void ImDrawList::PathArcToFast(const ImVec2& center, float radius, int a_min_of_ void ImDrawList::PathArcTo(const ImVec2& center, float radius, float a_min, float a_max, int num_segments) { - if (radius <= 0.0f) + if (radius < 0.5f) { _Path.push_back(center); return; @@ -1214,8 +1215,8 @@ void ImDrawList::PathArcTo(const ImVec2& center, float radius, float a_min, floa const float a_min_segment_angle = a_min_sample * IM_PI * 2.0f / IM_DRAWLIST_ARCFAST_SAMPLE_MAX; const float a_max_segment_angle = a_max_sample * IM_PI * 2.0f / IM_DRAWLIST_ARCFAST_SAMPLE_MAX; - const bool a_emit_start = (a_min_segment_angle - a_min) != 0.0f; - const bool a_emit_end = (a_max - a_max_segment_angle) != 0.0f; + const bool a_emit_start = ImAbs(a_min_segment_angle - a_min) >= 1e-5f; + const bool a_emit_end = ImAbs(a_max - a_max_segment_angle) >= 1e-5f; _Path.reserve(_Path.Size + (a_mid_samples + 1 + (a_emit_start ? 1 : 0) + (a_emit_end ? 1 : 0))); if (a_emit_start) @@ -1367,7 +1368,7 @@ void ImDrawList::PathRect(const ImVec2& a, const ImVec2& b, float rounding, ImDr rounding = ImMin(rounding, ImFabs(b.x - a.x) * ( ((flags & ImDrawFlags_RoundCornersTop) == ImDrawFlags_RoundCornersTop) || ((flags & ImDrawFlags_RoundCornersBottom) == ImDrawFlags_RoundCornersBottom) ? 0.5f : 1.0f ) - 1.0f); rounding = ImMin(rounding, ImFabs(b.y - a.y) * ( ((flags & ImDrawFlags_RoundCornersLeft) == ImDrawFlags_RoundCornersLeft) || ((flags & ImDrawFlags_RoundCornersRight) == ImDrawFlags_RoundCornersRight) ? 0.5f : 1.0f ) - 1.0f); - if (rounding <= 0.0f || (flags & ImDrawFlags_RoundCornersMask_) == ImDrawFlags_RoundCornersNone) + if (rounding < 0.5f || (flags & ImDrawFlags_RoundCornersMask_) == ImDrawFlags_RoundCornersNone) { PathLineTo(a); PathLineTo(ImVec2(b.x, a.y)); @@ -1413,7 +1414,7 @@ void ImDrawList::AddRectFilled(const ImVec2& p_min, const ImVec2& p_max, ImU32 c { if ((col & IM_COL32_A_MASK) == 0) return; - if (rounding <= 0.0f || (flags & ImDrawFlags_RoundCornersMask_) == ImDrawFlags_RoundCornersNone) + if (rounding < 0.5f || (flags & ImDrawFlags_RoundCornersMask_) == ImDrawFlags_RoundCornersNone) { PrimReserve(6, 4); PrimRect(p_min, p_max, col); @@ -1489,7 +1490,7 @@ void ImDrawList::AddTriangleFilled(const ImVec2& p1, const ImVec2& p2, const ImV void ImDrawList::AddCircle(const ImVec2& center, float radius, ImU32 col, int num_segments, float thickness) { - if ((col & IM_COL32_A_MASK) == 0 || radius <= 0.0f) + if ((col & IM_COL32_A_MASK) == 0 || radius < 0.5f) return; if (num_segments <= 0) @@ -1513,7 +1514,7 @@ void ImDrawList::AddCircle(const ImVec2& center, float radius, ImU32 col, int nu void ImDrawList::AddCircleFilled(const ImVec2& center, float radius, ImU32 col, int num_segments) { - if ((col & IM_COL32_A_MASK) == 0 || radius <= 0.0f) + if ((col & IM_COL32_A_MASK) == 0 || radius < 0.5f) return; if (num_segments <= 0) @@ -1653,7 +1654,7 @@ void ImDrawList::AddImageRounded(ImTextureID user_texture_id, const ImVec2& p_mi return; flags = FixRectCornerFlags(flags); - if (rounding <= 0.0f || (flags & ImDrawFlags_RoundCornersMask_) == ImDrawFlags_RoundCornersNone) + if (rounding < 0.5f || (flags & ImDrawFlags_RoundCornersMask_) == ImDrawFlags_RoundCornersNone) { AddImage(user_texture_id, p_min, p_max, uv_min, uv_max, col); return; @@ -1741,13 +1742,13 @@ void ImDrawListSplitter::Merge(ImDrawList* draw_list) for (int i = 1; i < _Count; i++) { ImDrawChannel& ch = _Channels[i]; - - // Equivalent of PopUnusedDrawCmd() for this channel's cmdbuffer and except we don't need to test for UserCallback. - if (ch._CmdBuffer.Size > 0 && ch._CmdBuffer.back().ElemCount == 0) + if (ch._CmdBuffer.Size > 0 && ch._CmdBuffer.back().ElemCount == 0 && ch._CmdBuffer.back().UserCallback == NULL) // Equivalent of PopUnusedDrawCmd() ch._CmdBuffer.pop_back(); if (ch._CmdBuffer.Size > 0 && last_cmd != NULL) { + // Do not include ImDrawCmd_AreSequentialIdxOffset() in the compare as we rebuild IdxOffset values ourselves. + // Manipulating IdxOffset (e.g. by reordering draw commands like done by RenderDimmedBackgroundBehindWindow()) is not supported within a splitter. ImDrawCmd* next_cmd = &ch._CmdBuffer[0]; if (ImDrawCmd_HeaderCompare(last_cmd, next_cmd) == 0 && last_cmd->UserCallback == NULL && next_cmd->UserCallback == NULL) { @@ -2645,8 +2646,8 @@ void ImFontAtlasBuildPackCustomRects(ImFontAtlas* atlas, void* stbrp_context_opa for (int i = 0; i < pack_rects.Size; i++) if (pack_rects[i].was_packed) { - user_rects[i].X = pack_rects[i].x; - user_rects[i].Y = pack_rects[i].y; + user_rects[i].X = (unsigned short)pack_rects[i].x; + user_rects[i].Y = (unsigned short)pack_rects[i].y; IM_ASSERT(pack_rects[i].w == user_rects[i].Width && pack_rects[i].h == user_rects[i].Height); atlas->TexHeight = ImMax(atlas->TexHeight, pack_rects[i].y + pack_rects[i].h); } @@ -2746,13 +2747,13 @@ static void ImFontAtlasBuildRenderLinesTexData(ImFontAtlas* atlas) { unsigned int* write_ptr = &atlas->TexPixelsRGBA32[r->X + ((r->Y + y) * atlas->TexWidth)]; for (unsigned int i = 0; i < pad_left; i++) - *(write_ptr + i) = IM_COL32_BLACK_TRANS; + *(write_ptr + i) = IM_COL32(255, 255, 255, 0); for (unsigned int i = 0; i < line_width; i++) *(write_ptr + pad_left + i) = IM_COL32_WHITE; for (unsigned int i = 0; i < pad_right; i++) - *(write_ptr + pad_left + line_width + i) = IM_COL32_BLACK_TRANS; + *(write_ptr + pad_left + line_width + i) = IM_COL32(255, 255, 255, 0); } // Calculate UVs for this line @@ -3531,7 +3532,7 @@ ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, cons } // Note: as with every ImDrawList drawing function, this expects that the font atlas texture is bound. -void ImFont::RenderChar(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col, ImWchar c) const +void ImFont::RenderChar(ImDrawList* draw_list, float size, const ImVec2& pos, ImU32 col, ImWchar c) const { const ImFontGlyph* glyph = FindGlyph(c); if (!glyph || !glyph->Visible) @@ -3539,26 +3540,25 @@ void ImFont::RenderChar(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col if (glyph->Colored) col |= ~IM_COL32_A_MASK; float scale = (size >= 0.0f) ? (size / FontSize) : 1.0f; - pos.x = IM_FLOOR(pos.x); - pos.y = IM_FLOOR(pos.y); + float x = IM_FLOOR(pos.x); + float y = IM_FLOOR(pos.y); draw_list->PrimReserve(6, 4); - draw_list->PrimRectUV(ImVec2(pos.x + glyph->X0 * scale, pos.y + glyph->Y0 * scale), ImVec2(pos.x + glyph->X1 * scale, pos.y + glyph->Y1 * scale), ImVec2(glyph->U0, glyph->V0), ImVec2(glyph->U1, glyph->V1), col); + draw_list->PrimRectUV(ImVec2(x + glyph->X0 * scale, y + glyph->Y0 * scale), ImVec2(x + glyph->X1 * scale, y + glyph->Y1 * scale), ImVec2(glyph->U0, glyph->V0), ImVec2(glyph->U1, glyph->V1), col); } // Note: as with every ImDrawList drawing function, this expects that the font atlas texture is bound. -void ImFont::RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, float wrap_width, bool cpu_fine_clip) const +void ImFont::RenderText(ImDrawList* draw_list, float size, const ImVec2& pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, float wrap_width, bool cpu_fine_clip) const { if (!text_end) text_end = text_begin + strlen(text_begin); // ImGui:: functions generally already provides a valid text_end, so this is merely to handle direct calls. // Align to be pixel perfect - pos.x = IM_FLOOR(pos.x); - pos.y = IM_FLOOR(pos.y); - float x = pos.x; - float y = pos.y; + float x = IM_FLOOR(pos.x); + float y = IM_FLOOR(pos.y); if (y > clip_rect.w) return; + const float start_x = x; const float scale = size / FontSize; const float line_height = FontSize * scale; const bool word_wrap_enabled = (wrap_width > 0.0f); @@ -3610,14 +3610,14 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col // Calculate how far we can render. Requires two passes on the string data but keeps the code simple and not intrusive for what's essentially an uncommon feature. if (!word_wrap_eol) { - word_wrap_eol = CalcWordWrapPositionA(scale, s, text_end, wrap_width - (x - pos.x)); + word_wrap_eol = CalcWordWrapPositionA(scale, s, text_end, wrap_width - (x - start_x)); if (word_wrap_eol == s) // Wrap_width is too small to fit anything. Force displaying 1 character to minimize the height discontinuity. word_wrap_eol++; // +1 may not be a character start point in UTF-8 but it's ok because we use s >= word_wrap_eol below } if (s >= word_wrap_eol) { - x = pos.x; + x = start_x; y += line_height; word_wrap_eol = NULL; @@ -3648,7 +3648,7 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col { if (c == '\n') { - x = pos.x; + x = start_x; y += line_height; if (y > clip_rect.w) break; // break out of main loop @@ -3744,7 +3744,6 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col // - RenderArrow() // - RenderBullet() // - RenderCheckMark() -// - RenderMouseCursor() // - RenderArrowDockMenu() // - RenderArrowPointingAt() // - RenderRectFilledRangeH() @@ -3806,27 +3805,6 @@ void ImGui::RenderCheckMark(ImDrawList* draw_list, ImVec2 pos, ImU32 col, float draw_list->PathStroke(col, 0, thickness); } -void ImGui::RenderMouseCursor(ImDrawList* draw_list, ImVec2 pos, float scale, ImGuiMouseCursor mouse_cursor, ImU32 col_fill, ImU32 col_border, ImU32 col_shadow) -{ - if (mouse_cursor == ImGuiMouseCursor_None) - return; - IM_ASSERT(mouse_cursor > ImGuiMouseCursor_None && mouse_cursor < ImGuiMouseCursor_COUNT); - - ImFontAtlas* font_atlas = draw_list->_Data->Font->ContainerAtlas; - ImVec2 offset, size, uv[4]; - if (font_atlas->GetMouseCursorTexData(mouse_cursor, &offset, &size, &uv[0], &uv[2])) - { - pos -= offset; - ImTextureID tex_id = font_atlas->TexID; - draw_list->PushTextureID(tex_id); - draw_list->AddImage(tex_id, pos + ImVec2(1, 0) * scale, pos + (ImVec2(1, 0) + size) * scale, uv[2], uv[3], col_shadow); - draw_list->AddImage(tex_id, pos + ImVec2(2, 0) * scale, pos + (ImVec2(2, 0) + size) * scale, uv[2], uv[3], col_shadow); - draw_list->AddImage(tex_id, pos, pos + size * scale, uv[2], uv[3], col_border); - draw_list->AddImage(tex_id, pos, pos + size * scale, uv[0], uv[1], col_fill); - draw_list->PopTextureID(); - } -} - // Render an arrow. 'pos' is position of the arrow tip. half_sz.x is length from base to tip. half_sz.y is length on each side. void ImGui::RenderArrowPointingAt(ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, ImGuiDir direction, ImU32 col) { @@ -3917,7 +3895,7 @@ void ImGui::RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, Im draw_list->PathFillConvex(col); } -void ImGui::RenderRectFilledWithHole(ImDrawList* draw_list, ImRect outer, ImRect inner, ImU32 col, float rounding) +void ImGui::RenderRectFilledWithHole(ImDrawList* draw_list, const ImRect& outer, const ImRect& inner, ImU32 col, float rounding) { const bool fill_L = (inner.Min.x > outer.Min.x); const bool fill_R = (inner.Max.x < outer.Max.x); diff --git a/lib/external/imgui/source/imgui_freetype.cpp b/lib/external/imgui/source/imgui_freetype.cpp index 71a18870f..4066a9a6c 100644 --- a/lib/external/imgui/source/imgui_freetype.cpp +++ b/lib/external/imgui/source/imgui_freetype.cpp @@ -6,6 +6,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2021/08/23: fixed crash when FT_Render_Glyph() fails to render a glyph and returns NULL. // 2021/03/05: added ImGuiFreeTypeBuilderFlags_Bitmap to load bitmap glyphs. // 2021/03/02: set 'atlas->TexPixelsUseColors = true' to help some backends with deciding of a prefered texture format. // 2021/01/28: added support for color-layered glyphs via ImGuiFreeTypeBuilderFlags_LoadColor (require Freetype 2.10+). @@ -225,6 +226,12 @@ namespace uint32_t glyph_index = FT_Get_Char_Index(Face, codepoint); if (glyph_index == 0) return NULL; + + // If this crash for you: FreeType 2.11.0 has a crash bug on some bitmap/colored fonts. + // - https://gitlab.freedesktop.org/freetype/freetype/-/issues/1076 + // - https://github.com/ocornut/imgui/issues/4567 + // - https://github.com/ocornut/imgui/issues/4566 + // You can use FreeType 2.10, or the patched version of 2.11.0 in VcPkg, or probably any upcoming FreeType version. FT_Error error = FT_Load_Glyph(Face, glyph_index, LoadFlags); if (error) return NULL; @@ -361,7 +368,7 @@ struct ImFontBuildSrcGlyphFT uint32_t Codepoint; unsigned int* BitmapData; // Point within one of the dst_tmp_bitmap_buffers[] array - ImFontBuildSrcGlyphFT() { memset(this, 0, sizeof(*this)); } + ImFontBuildSrcGlyphFT() { memset((void*)this, 0, sizeof(*this)); } }; struct ImFontBuildSrcDataFT @@ -539,7 +546,8 @@ bool ImFontAtlasBuildWithFreeTypeEx(FT_Library ft_library, ImFontAtlas* atlas, u // Render glyph into a bitmap (currently held by FreeType) const FT_Bitmap* ft_bitmap = src_tmp.Font.RenderGlyphAndGetInfo(&src_glyph.Info); - IM_ASSERT(ft_bitmap); + if (ft_bitmap == NULL) + continue; // Allocate new temporary chunk if needed const int bitmap_size_in_bytes = src_glyph.Info.Width * src_glyph.Info.Height * 4; diff --git a/lib/external/imgui/source/imgui_impl_glfw.cpp b/lib/external/imgui/source/imgui_impl_glfw.cpp index 2dbdbbc1c..5712f8a46 100644 --- a/lib/external/imgui/source/imgui_impl_glfw.cpp +++ b/lib/external/imgui/source/imgui_impl_glfw.cpp @@ -5,9 +5,9 @@ // Implemented features: // [X] Platform: Clipboard support. +// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy GLFW_KEY_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] // [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange' (note: the resizing cursors requires GLFW 3.4+). -// [X] Platform: Keyboard arrays indexed using GLFW_KEY_* codes, e.g. ImGui::IsKeyPressed(GLFW_KEY_SPACE). // [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. // Issues: @@ -20,7 +20,17 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) -// 2021-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2022-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2022-04-30: Inputs: Fixed ImGui_ImplGlfw_TranslateUntranslatedKey() for lower case letters on OSX. +// 2022-03-23: Inputs: Fixed a regression in 1.87 which resulted in keyboard modifiers events being reported incorrectly on Linux/X11. +// 2022-02-07: Added ImGui_ImplGlfw_InstallCallbacks()/ImGui_ImplGlfw_RestoreCallbacks() helpers to facilitate user installing callbacks after initializing backend. +// 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago)with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion. +// 2021-01-20: Inputs: calling new io.AddKeyAnalogEvent() for gamepad support, instead of writing directly to io.NavInputs[]. +// 2022-01-17: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+). +// 2022-01-17: Inputs: always update key mods next and before key event (not in NewFrame) to fix input queue with very low framerates. +// 2022-01-12: *BREAKING CHANGE*: Now using glfwSetCursorPosCallback(). If you called ImGui_ImplGlfw_InitXXX() with install_callbacks = false, you MUST install glfwSetCursorPosCallback() and forward it to the backend via ImGui_ImplGlfw_CursorPosCallback(). +// 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range. +// 2022-01-05: Inputs: Converting GLFW untranslated keycodes back to translated keycodes (in the ImGui_ImplGlfw_KeyCallback() function) in order to match the behavior of every other backend, and facilitate the use of GLFW with lettered-shortcuts API. // 2021-08-17: *BREAKING CHANGE*: Now using glfwSetWindowFocusCallback() to calling io.AddFocusEvent(). If you called ImGui_ImplGlfw_InitXXX() with install_callbacks = false, you MUST install glfwSetWindowFocusCallback() and forward it to the backend via ImGui_ImplGlfw_WindowFocusCallback(). // 2021-07-29: *BREAKING CHANGE*: Now using glfwSetCursorEnterCallback(). MousePos is correctly reported when the host platform window is hovered but not focused. If you called ImGui_ImplGlfw_InitXXX() with install_callbacks = false, you MUST install glfwSetWindowFocusCallback() callback and forward it to the backend via ImGui_ImplGlfw_CursorEnterCallback(). // 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX). @@ -47,16 +57,32 @@ // 2016-10-15: Misc: Added a void* user_data parameter to Clipboard function handlers. #include "imgui.h" -#include "imgui_internal.h" +#include "imgui_internal.h" // IMHEX PATCH #include "imgui_impl_glfw.h" +// Clang warnings with -Weverything +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast +#pragma clang diagnostic ignored "-Wsign-conversion" // warning: implicit conversion changes signedness +#if __has_warning("-Wzero-as-null-pointer-constant") +#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" +#endif +#endif + // GLFW #include + #ifdef _WIN32 #undef APIENTRY #define GLFW_EXPOSE_NATIVE_WIN32 -#include // for glfwGetWin32Window +#include // for glfwGetWin32Window() #endif +#ifdef __APPLE__ +#define GLFW_EXPOSE_NATIVE_COCOA +#include // for glfwGetCocoaWindow() +#endif + #define GLFW_HAS_WINDOW_TOPMOST (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3200) // 3.2+ GLFW_FLOATING #define GLFW_HAS_WINDOW_HOVERED (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ GLFW_HOVERED #define GLFW_HAS_WINDOW_ALPHA (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ glfwSetWindowOpacity @@ -76,6 +102,8 @@ #else #define GLFW_HAS_MOUSE_PASSTHROUGH (0) #endif +#define GLFW_HAS_GAMEPAD_API (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3300) // 3.3+ glfwGetGamepadState() new api +#define GLFW_HAS_GET_KEY_NAME (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 >= 3200) // 3.2+ glfwGetKeyName() // GLFW data enum GlfwClientApi @@ -91,14 +119,18 @@ struct ImGui_ImplGlfw_Data GlfwClientApi ClientApi; double Time; GLFWwindow* MouseWindow; - bool MouseJustPressed[ImGuiMouseButton_COUNT]; GLFWcursor* MouseCursors[ImGuiMouseCursor_COUNT]; - GLFWwindow* KeyOwnerWindows[512]; + ImVec2 LastValidMousePos; + GLFWwindow* KeyOwnerWindows[GLFW_KEY_LAST]; bool InstalledCallbacks; bool WantUpdateMonitors; +#ifdef _WIN32 + WNDPROC GlfwWndProc; +#endif // Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any. GLFWwindowfocusfun PrevUserCallbackWindowFocus; + GLFWcursorposfun PrevUserCallbackCursorPos; GLFWcursorenterfun PrevUserCallbackCursorEnter; GLFWmousebuttonfun PrevUserCallbackMousebutton; GLFWscrollfun PrevUserCallbackScroll; @@ -106,7 +138,7 @@ struct ImGui_ImplGlfw_Data GLFWcharfun PrevUserCallbackChar; GLFWmonitorfun PrevUserCallbackMonitor; - ImGui_ImplGlfw_Data() { memset(this, 0, sizeof(*this)); } + ImGui_ImplGlfw_Data() { memset((void*)this, 0, sizeof(*this)); } }; // Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts @@ -137,7 +169,8 @@ static void ImGui_ImplGlfw_SetClipboardText(void* user_data, const char* text) glfwSetClipboardString((GLFWwindow*)user_data, text); } -#if defined(OS_WINDOWS) +// IMHEX PATCH BEGIN +#ifdef _WIN32 static const char* ImGui_ImplWin_GetClipboardText(void*) { ImGuiContext& g = *GImGui; @@ -181,6 +214,142 @@ static void ImGui_ImplGlfw_SetClipboardText(void* user_data, const char* text) ::CloseClipboard(); } #endif +// IMHEX PATCH END + +static ImGuiKey ImGui_ImplGlfw_KeyToImGuiKey(int key) +{ + switch (key) + { + case GLFW_KEY_TAB: return ImGuiKey_Tab; + case GLFW_KEY_LEFT: return ImGuiKey_LeftArrow; + case GLFW_KEY_RIGHT: return ImGuiKey_RightArrow; + case GLFW_KEY_UP: return ImGuiKey_UpArrow; + case GLFW_KEY_DOWN: return ImGuiKey_DownArrow; + case GLFW_KEY_PAGE_UP: return ImGuiKey_PageUp; + case GLFW_KEY_PAGE_DOWN: return ImGuiKey_PageDown; + case GLFW_KEY_HOME: return ImGuiKey_Home; + case GLFW_KEY_END: return ImGuiKey_End; + case GLFW_KEY_INSERT: return ImGuiKey_Insert; + case GLFW_KEY_DELETE: return ImGuiKey_Delete; + case GLFW_KEY_BACKSPACE: return ImGuiKey_Backspace; + case GLFW_KEY_SPACE: return ImGuiKey_Space; + case GLFW_KEY_ENTER: return ImGuiKey_Enter; + case GLFW_KEY_ESCAPE: return ImGuiKey_Escape; + case GLFW_KEY_APOSTROPHE: return ImGuiKey_Apostrophe; + case GLFW_KEY_COMMA: return ImGuiKey_Comma; + case GLFW_KEY_MINUS: return ImGuiKey_Minus; + case GLFW_KEY_PERIOD: return ImGuiKey_Period; + case GLFW_KEY_SLASH: return ImGuiKey_Slash; + case GLFW_KEY_SEMICOLON: return ImGuiKey_Semicolon; + case GLFW_KEY_EQUAL: return ImGuiKey_Equal; + case GLFW_KEY_LEFT_BRACKET: return ImGuiKey_LeftBracket; + case GLFW_KEY_BACKSLASH: return ImGuiKey_Backslash; + case GLFW_KEY_RIGHT_BRACKET: return ImGuiKey_RightBracket; + case GLFW_KEY_GRAVE_ACCENT: return ImGuiKey_GraveAccent; + case GLFW_KEY_CAPS_LOCK: return ImGuiKey_CapsLock; + case GLFW_KEY_SCROLL_LOCK: return ImGuiKey_ScrollLock; + case GLFW_KEY_NUM_LOCK: return ImGuiKey_NumLock; + case GLFW_KEY_PRINT_SCREEN: return ImGuiKey_PrintScreen; + case GLFW_KEY_PAUSE: return ImGuiKey_Pause; + case GLFW_KEY_KP_0: return ImGuiKey_Keypad0; + case GLFW_KEY_KP_1: return ImGuiKey_Keypad1; + case GLFW_KEY_KP_2: return ImGuiKey_Keypad2; + case GLFW_KEY_KP_3: return ImGuiKey_Keypad3; + case GLFW_KEY_KP_4: return ImGuiKey_Keypad4; + case GLFW_KEY_KP_5: return ImGuiKey_Keypad5; + case GLFW_KEY_KP_6: return ImGuiKey_Keypad6; + case GLFW_KEY_KP_7: return ImGuiKey_Keypad7; + case GLFW_KEY_KP_8: return ImGuiKey_Keypad8; + case GLFW_KEY_KP_9: return ImGuiKey_Keypad9; + case GLFW_KEY_KP_DECIMAL: return ImGuiKey_KeypadDecimal; + case GLFW_KEY_KP_DIVIDE: return ImGuiKey_KeypadDivide; + case GLFW_KEY_KP_MULTIPLY: return ImGuiKey_KeypadMultiply; + case GLFW_KEY_KP_SUBTRACT: return ImGuiKey_KeypadSubtract; + case GLFW_KEY_KP_ADD: return ImGuiKey_KeypadAdd; + case GLFW_KEY_KP_ENTER: return ImGuiKey_KeypadEnter; + case GLFW_KEY_KP_EQUAL: return ImGuiKey_KeypadEqual; + case GLFW_KEY_LEFT_SHIFT: return ImGuiKey_LeftShift; + case GLFW_KEY_LEFT_CONTROL: return ImGuiKey_LeftCtrl; + case GLFW_KEY_LEFT_ALT: return ImGuiKey_LeftAlt; + case GLFW_KEY_LEFT_SUPER: return ImGuiKey_LeftSuper; + case GLFW_KEY_RIGHT_SHIFT: return ImGuiKey_RightShift; + case GLFW_KEY_RIGHT_CONTROL: return ImGuiKey_RightCtrl; + case GLFW_KEY_RIGHT_ALT: return ImGuiKey_RightAlt; + case GLFW_KEY_RIGHT_SUPER: return ImGuiKey_RightSuper; + case GLFW_KEY_MENU: return ImGuiKey_Menu; + case GLFW_KEY_0: return ImGuiKey_0; + case GLFW_KEY_1: return ImGuiKey_1; + case GLFW_KEY_2: return ImGuiKey_2; + case GLFW_KEY_3: return ImGuiKey_3; + case GLFW_KEY_4: return ImGuiKey_4; + case GLFW_KEY_5: return ImGuiKey_5; + case GLFW_KEY_6: return ImGuiKey_6; + case GLFW_KEY_7: return ImGuiKey_7; + case GLFW_KEY_8: return ImGuiKey_8; + case GLFW_KEY_9: return ImGuiKey_9; + case GLFW_KEY_A: return ImGuiKey_A; + case GLFW_KEY_B: return ImGuiKey_B; + case GLFW_KEY_C: return ImGuiKey_C; + case GLFW_KEY_D: return ImGuiKey_D; + case GLFW_KEY_E: return ImGuiKey_E; + case GLFW_KEY_F: return ImGuiKey_F; + case GLFW_KEY_G: return ImGuiKey_G; + case GLFW_KEY_H: return ImGuiKey_H; + case GLFW_KEY_I: return ImGuiKey_I; + case GLFW_KEY_J: return ImGuiKey_J; + case GLFW_KEY_K: return ImGuiKey_K; + case GLFW_KEY_L: return ImGuiKey_L; + case GLFW_KEY_M: return ImGuiKey_M; + case GLFW_KEY_N: return ImGuiKey_N; + case GLFW_KEY_O: return ImGuiKey_O; + case GLFW_KEY_P: return ImGuiKey_P; + case GLFW_KEY_Q: return ImGuiKey_Q; + case GLFW_KEY_R: return ImGuiKey_R; + case GLFW_KEY_S: return ImGuiKey_S; + case GLFW_KEY_T: return ImGuiKey_T; + case GLFW_KEY_U: return ImGuiKey_U; + case GLFW_KEY_V: return ImGuiKey_V; + case GLFW_KEY_W: return ImGuiKey_W; + case GLFW_KEY_X: return ImGuiKey_X; + case GLFW_KEY_Y: return ImGuiKey_Y; + case GLFW_KEY_Z: return ImGuiKey_Z; + case GLFW_KEY_F1: return ImGuiKey_F1; + case GLFW_KEY_F2: return ImGuiKey_F2; + case GLFW_KEY_F3: return ImGuiKey_F3; + case GLFW_KEY_F4: return ImGuiKey_F4; + case GLFW_KEY_F5: return ImGuiKey_F5; + case GLFW_KEY_F6: return ImGuiKey_F6; + case GLFW_KEY_F7: return ImGuiKey_F7; + case GLFW_KEY_F8: return ImGuiKey_F8; + case GLFW_KEY_F9: return ImGuiKey_F9; + case GLFW_KEY_F10: return ImGuiKey_F10; + case GLFW_KEY_F11: return ImGuiKey_F11; + case GLFW_KEY_F12: return ImGuiKey_F12; + default: return ImGuiKey_None; + } +} + +static int ImGui_ImplGlfw_KeyToModifier(int key) +{ + if (key == GLFW_KEY_LEFT_CONTROL || key == GLFW_KEY_RIGHT_CONTROL) + return GLFW_MOD_CONTROL; + if (key == GLFW_KEY_LEFT_SHIFT || key == GLFW_KEY_RIGHT_SHIFT) + return GLFW_MOD_SHIFT; + if (key == GLFW_KEY_LEFT_ALT || key == GLFW_KEY_RIGHT_ALT) + return GLFW_MOD_ALT; + if (key == GLFW_KEY_LEFT_SUPER || key == GLFW_KEY_RIGHT_SUPER) + return GLFW_MOD_SUPER; + return 0; +} + +static void ImGui_ImplGlfw_UpdateKeyModifiers(int mods) +{ + ImGuiIO& io = ImGui::GetIO(); + io.AddKeyEvent(ImGuiKey_ModCtrl, (mods & GLFW_MOD_CONTROL) != 0); + io.AddKeyEvent(ImGuiKey_ModShift, (mods & GLFW_MOD_SHIFT) != 0); + io.AddKeyEvent(ImGuiKey_ModAlt, (mods & GLFW_MOD_ALT) != 0); + io.AddKeyEvent(ImGuiKey_ModSuper, (mods & GLFW_MOD_SUPER) != 0); +} void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods) { @@ -188,8 +357,11 @@ void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int acti if (bd->PrevUserCallbackMousebutton != NULL && window == bd->Window) bd->PrevUserCallbackMousebutton(window, button, action, mods); - if (action == GLFW_PRESS && button >= 0 && button < IM_ARRAYSIZE(bd->MouseJustPressed)) - bd->MouseJustPressed[button] = true; + ImGui_ImplGlfw_UpdateKeyModifiers(mods); + + ImGuiIO& io = ImGui::GetIO(); + if (button >= 0 && button < ImGuiMouseButton_COUNT) + io.AddMouseButtonEvent(button, action == GLFW_PRESS); } void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset) @@ -199,40 +371,60 @@ void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yo bd->PrevUserCallbackScroll(window, xoffset, yoffset); ImGuiIO& io = ImGui::GetIO(); - io.MouseWheelH += (float)xoffset; - io.MouseWheel += (float)yoffset; + io.AddMouseWheelEvent((float)xoffset, (float)yoffset); } -void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) +static int ImGui_ImplGlfw_TranslateUntranslatedKey(int key, int scancode) +{ +#if GLFW_HAS_GET_KEY_NAME && !defined(__EMSCRIPTEN__) + // GLFW 3.1+ attempts to "untranslate" keys, which goes the opposite of what every other framework does, making using lettered shortcuts difficult. + // (It had reasons to do so: namely GLFW is/was more likely to be used for WASD-type game controls rather than lettered shortcuts, but IHMO the 3.1 change could have been done differently) + // See https://github.com/glfw/glfw/issues/1502 for details. + // Adding a workaround to undo this (so our keys are translated->untranslated->translated, likely a lossy process). + // This won't cover edge cases but this is at least going to cover common cases. + if (key >= GLFW_KEY_KP_0 && key <= GLFW_KEY_KP_EQUAL) + return key; + const char* key_name = glfwGetKeyName(key, scancode); + if (key_name && key_name[0] != 0 && key_name[1] == 0) + { + const char char_names[] = "`-=[]\\,;\'./"; + const int char_keys[] = { GLFW_KEY_GRAVE_ACCENT, GLFW_KEY_MINUS, GLFW_KEY_EQUAL, GLFW_KEY_LEFT_BRACKET, GLFW_KEY_RIGHT_BRACKET, GLFW_KEY_BACKSLASH, GLFW_KEY_COMMA, GLFW_KEY_SEMICOLON, GLFW_KEY_APOSTROPHE, GLFW_KEY_PERIOD, GLFW_KEY_SLASH, 0 }; + IM_ASSERT(IM_ARRAYSIZE(char_names) == IM_ARRAYSIZE(char_keys)); + if (key_name[0] >= '0' && key_name[0] <= '9') { key = GLFW_KEY_0 + (key_name[0] - '0'); } + else if (key_name[0] >= 'A' && key_name[0] <= 'Z') { key = GLFW_KEY_A + (key_name[0] - 'A'); } + else if (key_name[0] >= 'a' && key_name[0] <= 'z') { key = GLFW_KEY_A + (key_name[0] - 'a'); } + else if (const char* p = strchr(char_names, key_name[0])) { key = char_keys[p - char_names]; } + } + // if (action == GLFW_PRESS) printf("key %d scancode %d name '%s'\n", key, scancode, key_name); +#else + IM_UNUSED(scancode); +#endif + return key; +} + +void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int keycode, int scancode, int action, int mods) { ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); if (bd->PrevUserCallbackKey != NULL && window == bd->Window) - bd->PrevUserCallbackKey(window, key, scancode, action, mods); + bd->PrevUserCallbackKey(window, keycode, scancode, action, mods); + + if (action != GLFW_PRESS && action != GLFW_RELEASE) + return; + + // Workaround: X11 does not include current pressed/released modifier key in 'mods' flags. https://github.com/glfw/glfw/issues/1630 + if (int keycode_to_mod = ImGui_ImplGlfw_KeyToModifier(keycode)) + mods = (action == GLFW_PRESS) ? (mods | keycode_to_mod) : (mods & ~keycode_to_mod); + ImGui_ImplGlfw_UpdateKeyModifiers(mods); + + if (keycode >= 0 && keycode < IM_ARRAYSIZE(bd->KeyOwnerWindows)) + bd->KeyOwnerWindows[keycode] = (action == GLFW_PRESS) ? window : NULL; + + keycode = ImGui_ImplGlfw_TranslateUntranslatedKey(keycode, scancode); ImGuiIO& io = ImGui::GetIO(); - if (key >= 0 && key < IM_ARRAYSIZE(io.KeysDown)) - { - if (action == GLFW_PRESS) - { - io.KeysDown[key] = true; - bd->KeyOwnerWindows[key] = window; - } - if (action == GLFW_RELEASE) - { - io.KeysDown[key] = false; - bd->KeyOwnerWindows[key] = NULL; - } - } - - // Modifiers are not reliable across systems - io.KeyCtrl = io.KeysDown[GLFW_KEY_LEFT_CONTROL] || io.KeysDown[GLFW_KEY_RIGHT_CONTROL]; - io.KeyShift = io.KeysDown[GLFW_KEY_LEFT_SHIFT] || io.KeysDown[GLFW_KEY_RIGHT_SHIFT]; - io.KeyAlt = io.KeysDown[GLFW_KEY_LEFT_ALT] || io.KeysDown[GLFW_KEY_RIGHT_ALT]; -#ifdef _WIN32 - io.KeySuper = false; -#else - io.KeySuper = io.KeysDown[GLFW_KEY_LEFT_SUPER] || io.KeysDown[GLFW_KEY_RIGHT_SUPER]; -#endif + ImGuiKey imgui_key = ImGui_ImplGlfw_KeyToImGuiKey(keycode); + io.AddKeyEvent(imgui_key, (action == GLFW_PRESS)); + io.SetKeyEventNativeData(imgui_key, keycode, scancode); // To support legacy indexing (<1.87 user code) } void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused) @@ -245,16 +437,44 @@ void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused) io.AddFocusEvent(focused != 0); } +void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y) +{ + ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); + if (bd->PrevUserCallbackCursorPos != NULL && window == bd->Window) + bd->PrevUserCallbackCursorPos(window, x, y); + + ImGuiIO& io = ImGui::GetIO(); + if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) + { + int window_x, window_y; + glfwGetWindowPos(window, &window_x, &window_y); + x += window_x; + y += window_y; + } + io.AddMousePosEvent((float)x, (float)y); + bd->LastValidMousePos = ImVec2((float)x, (float)y); +} + +// Workaround: X11 seems to send spurious Leave/Enter events which would make us lose our position, +// so we back it up and restore on Leave/Enter (see https://github.com/ocornut/imgui/issues/4984) void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered) { ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); if (bd->PrevUserCallbackCursorEnter != NULL && window == bd->Window) bd->PrevUserCallbackCursorEnter(window, entered); + ImGuiIO& io = ImGui::GetIO(); if (entered) + { bd->MouseWindow = window; - if (!entered && bd->MouseWindow == window) + io.AddMousePosEvent(bd->LastValidMousePos.x, bd->LastValidMousePos.y); + } + else if (!entered && bd->MouseWindow == window) + { + bd->LastValidMousePos = io.MousePos; bd->MouseWindow = NULL; + io.AddMousePosEvent(-FLT_MAX, -FLT_MAX); + } } void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c) @@ -273,6 +493,48 @@ void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor*, int) bd->WantUpdateMonitors = true; } +void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window) +{ + ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); + IM_ASSERT(bd->InstalledCallbacks == false && "Callbacks already installed!"); + IM_ASSERT(bd->Window == window); + + bd->PrevUserCallbackWindowFocus = glfwSetWindowFocusCallback(window, ImGui_ImplGlfw_WindowFocusCallback); + bd->PrevUserCallbackCursorEnter = glfwSetCursorEnterCallback(window, ImGui_ImplGlfw_CursorEnterCallback); + bd->PrevUserCallbackCursorPos = glfwSetCursorPosCallback(window, ImGui_ImplGlfw_CursorPosCallback); + bd->PrevUserCallbackMousebutton = glfwSetMouseButtonCallback(window, ImGui_ImplGlfw_MouseButtonCallback); + bd->PrevUserCallbackScroll = glfwSetScrollCallback(window, ImGui_ImplGlfw_ScrollCallback); + bd->PrevUserCallbackKey = glfwSetKeyCallback(window, ImGui_ImplGlfw_KeyCallback); + bd->PrevUserCallbackChar = glfwSetCharCallback(window, ImGui_ImplGlfw_CharCallback); + bd->PrevUserCallbackMonitor = glfwSetMonitorCallback(ImGui_ImplGlfw_MonitorCallback); + bd->InstalledCallbacks = true; +} + +void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window) +{ + ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); + IM_ASSERT(bd->InstalledCallbacks == true && "Callbacks not installed!"); + IM_ASSERT(bd->Window == window); + + glfwSetWindowFocusCallback(window, bd->PrevUserCallbackWindowFocus); + glfwSetCursorEnterCallback(window, bd->PrevUserCallbackCursorEnter); + glfwSetCursorPosCallback(window, bd->PrevUserCallbackCursorPos); + glfwSetMouseButtonCallback(window, bd->PrevUserCallbackMousebutton); + glfwSetScrollCallback(window, bd->PrevUserCallbackScroll); + glfwSetKeyCallback(window, bd->PrevUserCallbackKey); + glfwSetCharCallback(window, bd->PrevUserCallbackChar); + glfwSetMonitorCallback(bd->PrevUserCallbackMonitor); + bd->InstalledCallbacks = false; + bd->PrevUserCallbackWindowFocus = NULL; + bd->PrevUserCallbackCursorEnter = NULL; + bd->PrevUserCallbackCursorPos = NULL; + bd->PrevUserCallbackMousebutton = NULL; + bd->PrevUserCallbackScroll = NULL; + bd->PrevUserCallbackKey = NULL; + bd->PrevUserCallbackChar = NULL; + bd->PrevUserCallbackMonitor = NULL; +} + static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, GlfwClientApi client_api) { ImGuiIO& io = ImGui::GetIO(); @@ -286,38 +548,15 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used) io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports; // We can create multi-viewports on the Platform side (optional) #if GLFW_HAS_MOUSE_PASSTHROUGH || (GLFW_HAS_WINDOW_HOVERED && defined(_WIN32)) - io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport; // We can set io.MouseHoveredViewport correctly (optional, not easy) + io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport; // We can call io.AddMouseViewportEvent() with correct data (optional) #endif bd->Window = window; bd->Time = 0.0; bd->WantUpdateMonitors = true; - // Keyboard mapping. Dear ImGui will use those indices to peek into the io.KeysDown[] array. - io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; - io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT; - io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT; - io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP; - io.KeyMap[ImGuiKey_DownArrow] = GLFW_KEY_DOWN; - io.KeyMap[ImGuiKey_PageUp] = GLFW_KEY_PAGE_UP; - io.KeyMap[ImGuiKey_PageDown] = GLFW_KEY_PAGE_DOWN; - io.KeyMap[ImGuiKey_Home] = GLFW_KEY_HOME; - io.KeyMap[ImGuiKey_End] = GLFW_KEY_END; - io.KeyMap[ImGuiKey_Insert] = GLFW_KEY_INSERT; - io.KeyMap[ImGuiKey_Delete] = GLFW_KEY_DELETE; - io.KeyMap[ImGuiKey_Backspace] = GLFW_KEY_BACKSPACE; - io.KeyMap[ImGuiKey_Space] = GLFW_KEY_SPACE; - io.KeyMap[ImGuiKey_Enter] = GLFW_KEY_ENTER; - io.KeyMap[ImGuiKey_Escape] = GLFW_KEY_ESCAPE; - io.KeyMap[ImGuiKey_KeyPadEnter] = GLFW_KEY_KP_ENTER; - io.KeyMap[ImGuiKey_A] = GLFW_KEY_A; - io.KeyMap[ImGuiKey_C] = GLFW_KEY_C; - io.KeyMap[ImGuiKey_V] = GLFW_KEY_V; - io.KeyMap[ImGuiKey_X] = GLFW_KEY_X; - io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y; - io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z; - - #if defined(OS_WINDOWS) + // IMHEX PATCH BEGIN + #ifdef _WIN32 io.SetClipboardTextFn = ImGui_ImplWin_SetClipboardText; io.GetClipboardTextFn = ImGui_ImplWin_GetClipboardText; io.ClipboardUserData = bd->Window; @@ -326,6 +565,7 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw io.GetClipboardTextFn = ImGui_ImplGlfw_GetClipboardText; io.ClipboardUserData = bd->Window; #endif + // IMHEX PATCH END // Create mouse cursors // (By design, on X11 cursors are user configurable and some cursors may be missing. When a cursor doesn't exist, @@ -351,23 +591,8 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw glfwSetErrorCallback(prev_error_callback); // Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any. - bd->PrevUserCallbackWindowFocus = NULL; - bd->PrevUserCallbackMousebutton = NULL; - bd->PrevUserCallbackScroll = NULL; - bd->PrevUserCallbackKey = NULL; - bd->PrevUserCallbackChar = NULL; - bd->PrevUserCallbackMonitor = NULL; if (install_callbacks) - { - bd->InstalledCallbacks = true; - bd->PrevUserCallbackWindowFocus = glfwSetWindowFocusCallback(window, ImGui_ImplGlfw_WindowFocusCallback); - bd->PrevUserCallbackCursorEnter = glfwSetCursorEnterCallback(window, ImGui_ImplGlfw_CursorEnterCallback); - bd->PrevUserCallbackMousebutton = glfwSetMouseButtonCallback(window, ImGui_ImplGlfw_MouseButtonCallback); - bd->PrevUserCallbackScroll = glfwSetScrollCallback(window, ImGui_ImplGlfw_ScrollCallback); - bd->PrevUserCallbackKey = glfwSetKeyCallback(window, ImGui_ImplGlfw_KeyCallback); - bd->PrevUserCallbackChar = glfwSetCharCallback(window, ImGui_ImplGlfw_CharCallback); - bd->PrevUserCallbackMonitor = glfwSetMonitorCallback(ImGui_ImplGlfw_MonitorCallback); - } + ImGui_ImplGlfw_InstallCallbacks(window); // Update monitors the first time (note: monitor callback are broken in GLFW 3.2 and earlier, see github.com/glfw/glfw/issues/784) ImGui_ImplGlfw_UpdateMonitors(); @@ -378,6 +603,8 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw main_viewport->PlatformHandle = (void*)bd->Window; #ifdef _WIN32 main_viewport->PlatformHandleRaw = glfwGetWin32Window(bd->Window); +#elif defined(__APPLE__) + main_viewport->PlatformHandleRaw = (void*)glfwGetCocoaWindow(bd->Window); #endif if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) ImGui_ImplGlfw_InitPlatformInterface(); @@ -403,21 +630,14 @@ bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool install_callbacks) void ImGui_ImplGlfw_Shutdown() { - ImGuiIO& io = ImGui::GetIO(); ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); + IM_ASSERT(bd != NULL && "No platform backend to shutdown, or already shutdown?"); + ImGuiIO& io = ImGui::GetIO(); ImGui_ImplGlfw_ShutdownPlatformInterface(); if (bd->InstalledCallbacks) - { - glfwSetWindowFocusCallback(bd->Window, bd->PrevUserCallbackWindowFocus); - glfwSetCursorEnterCallback(bd->Window, bd->PrevUserCallbackCursorEnter); - glfwSetMouseButtonCallback(bd->Window, bd->PrevUserCallbackMousebutton); - glfwSetScrollCallback(bd->Window, bd->PrevUserCallbackScroll); - glfwSetKeyCallback(bd->Window, bd->PrevUserCallbackKey); - glfwSetCharCallback(bd->Window, bd->PrevUserCallbackChar); - glfwSetMonitorCallback(bd->PrevUserCallbackMonitor); - } + ImGui_ImplGlfw_RestoreCallbacks(bd->Window); for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++) glfwDestroyCursor(bd->MouseCursors[cursor_n]); @@ -427,72 +647,59 @@ void ImGui_ImplGlfw_Shutdown() IM_DELETE(bd); } -static void ImGui_ImplGlfw_UpdateMousePosAndButtons() +static void ImGui_ImplGlfw_UpdateMouseData() { ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); ImGuiIO& io = ImGui::GetIO(); ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); + ImGuiID mouse_viewport_id = 0; const ImVec2 mouse_pos_prev = io.MousePos; - io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX); - io.MouseHoveredViewport = 0; - - // Update mouse buttons - // (if a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame) - for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) - { - io.MouseDown[i] = bd->MouseJustPressed[i] || glfwGetMouseButton(bd->Window, i) != 0; - bd->MouseJustPressed[i] = false; - } - for (int n = 0; n < platform_io.Viewports.Size; n++) { ImGuiViewport* viewport = platform_io.Viewports[n]; GLFWwindow* window = (GLFWwindow*)viewport->PlatformHandle; #ifdef __EMSCRIPTEN__ - const bool focused = true; + const bool is_window_focused = true; #else - const bool focused = glfwGetWindowAttrib(window, GLFW_FOCUSED) != 0; + const bool is_window_focused = glfwGetWindowAttrib(window, GLFW_FOCUSED) != 0; #endif - GLFWwindow* mouse_window = (bd->MouseWindow == window || focused) ? window : NULL; - - // Update mouse buttons - if (focused) - for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) - io.MouseDown[i] |= glfwGetMouseButton(window, i) != 0; - - // Set OS mouse position from Dear ImGui if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user) - // (When multi-viewports are enabled, all Dear ImGui positions are same as OS positions) - if (io.WantSetMousePos && focused) - glfwSetCursorPos(window, (double)(mouse_pos_prev.x - viewport->Pos.x), (double)(mouse_pos_prev.y - viewport->Pos.y)); - - // Set Dear ImGui mouse position from OS position - if (mouse_window != NULL) + if (is_window_focused) { - double mouse_x, mouse_y; - glfwGetCursorPos(mouse_window, &mouse_x, &mouse_y); - if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) + // (Optional) Set OS mouse position from Dear ImGui if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user) + // When multi-viewports are enabled, all Dear ImGui positions are same as OS positions. + if (io.WantSetMousePos) + glfwSetCursorPos(window, (double)(mouse_pos_prev.x - viewport->Pos.x), (double)(mouse_pos_prev.y - viewport->Pos.y)); + + // (Optional) Fallback to provide mouse position when focused (ImGui_ImplGlfw_CursorPosCallback already provides this when hovered or captured) + if (bd->MouseWindow == NULL) { - // Multi-viewport mode: mouse position in OS absolute coordinates (io.MousePos is (0,0) when the mouse is on the upper-left of the primary monitor) - int window_x, window_y; - glfwGetWindowPos(window, &window_x, &window_y); - io.MousePos = ImVec2((float)mouse_x + window_x, (float)mouse_y + window_y); - } - else - { - // Single viewport mode: mouse position in client window coordinates (io.MousePos is (0,0) when the mouse is on the upper-left corner of the app window) - io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); + double mouse_x, mouse_y; + glfwGetCursorPos(window, &mouse_x, &mouse_y); + if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) + { + // Single viewport mode: mouse position in client window coordinates (io.MousePos is (0,0) when the mouse is on the upper-left corner of the app window) + // Multi-viewport mode: mouse position in OS absolute coordinates (io.MousePos is (0,0) when the mouse is on the upper-left of the primary monitor) + int window_x, window_y; + glfwGetWindowPos(window, &window_x, &window_y); + mouse_x += window_x; + mouse_y += window_y; + } + bd->LastValidMousePos = ImVec2((float)mouse_x, (float)mouse_y); + io.AddMousePosEvent((float)mouse_x, (float)mouse_y); } } - // (Optional) When using multiple viewports: set io.MouseHoveredViewport to the viewport the OS mouse cursor is hovering. - // Important: this information is not easy to provide and many high-level windowing library won't be able to provide it correctly, because - // - This is _ignoring_ viewports with the ImGuiViewportFlags_NoInputs flag (pass-through windows). - // - This is _regardless_ of whether another viewport is focused or being dragged from. - // If ImGuiBackendFlags_HasMouseHoveredViewport is not set by the backend, imgui will ignore this field and infer the information by relying on the - // rectangles and last focused time of every viewports it knows about. It will be unaware of other windows that may be sitting between or over your windows. - // [GLFW] FIXME: This is currently only correct on Win32. See what we do below with the WM_NCHITTEST, missing an equivalent for other systems. + // (Optional) When using multiple viewports: call io.AddMouseViewportEvent() with the viewport the OS mouse cursor is hovering. + // If ImGuiBackendFlags_HasMouseHoveredViewport is not set by the backend, Dear imGui will ignore this field and infer the information using its flawed heuristic. + // - [X] GLFW >= 3.3 backend ON WINDOWS ONLY does correctly ignore viewports with the _NoInputs flag. + // - [!] GLFW <= 3.2 backend CANNOT correctly ignore viewports with the _NoInputs flag, and CANNOT reported Hovered Viewport because of mouse capture. + // Some backend are not able to handle that correctly. If a backend report an hovered viewport that has the _NoInputs flag (e.g. when dragging a window + // for docking, the viewport has the _NoInputs flag in order to allow us to find the viewport under), then Dear ImGui is forced to ignore the value reported + // by the backend, and use its flawed heuristic to guess the viewport behind. + // - [X] GLFW backend correctly reports this regardless of another viewport behind focused and dragged from (we need this to find a useful drag and drop target). + // FIXME: This is currently only correct on Win32. See what we do below with the WM_NCHITTEST, missing an equivalent for other systems. // See https://github.com/glfw/glfw/issues/1236 if you want to help in making this a GLFW feature. #if GLFW_HAS_MOUSE_PASSTHROUGH || (GLFW_HAS_WINDOW_HOVERED && defined(_WIN32)) const bool window_no_input = (viewport->Flags & ImGuiViewportFlags_NoInputs) != 0; @@ -500,9 +707,14 @@ static void ImGui_ImplGlfw_UpdateMousePosAndButtons() glfwSetWindowAttrib(window, GLFW_MOUSE_PASSTHROUGH, window_no_input); #endif if (glfwGetWindowAttrib(window, GLFW_HOVERED) && !window_no_input) - io.MouseHoveredViewport = viewport->ID; + mouse_viewport_id = viewport->ID; +#else + // We cannot use bd->MouseWindow maintained from CursorEnter/Leave callbacks, because it is locked to the window capturing mouse. #endif } + + if (io.BackendFlags & ImGuiBackendFlags_HasMouseHoveredViewport) + io.AddMouseViewportEvent(mouse_viewport_id); } static void ImGui_ImplGlfw_UpdateMouseCursor() @@ -524,51 +736,69 @@ static void ImGui_ImplGlfw_UpdateMouseCursor() } else { - #if !defined(OS_WINDOWS) + // IMHEX PATCH BEGIN + #ifndef _WIN32 // Show OS mouse cursor // FIXME-PLATFORM: Unfocused windows seems to fail changing the mouse cursor with GLFW 3.2, but 3.3 works here. glfwSetCursor(window, bd->MouseCursors[imgui_cursor] ? bd->MouseCursors[imgui_cursor] : bd->MouseCursors[ImGuiMouseCursor_Arrow]); glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); #endif + // IMHEX PATCH END } } } +// Update gamepad inputs +static inline float Saturate(float v) { return v < 0.0f ? 0.0f : v > 1.0f ? 1.0f : v; } static void ImGui_ImplGlfw_UpdateGamepads() { ImGuiIO& io = ImGui::GetIO(); - memset(io.NavInputs, 0, sizeof(io.NavInputs)); - if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0) + if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0) // FIXME: Technically feeding gamepad shouldn't depend on this now that they are regular inputs. return; - // Update gamepad inputs - #define MAP_BUTTON(NAV_NO, BUTTON_NO) { if (buttons_count > BUTTON_NO && buttons[BUTTON_NO] == GLFW_PRESS) io.NavInputs[NAV_NO] = 1.0f; } - #define MAP_ANALOG(NAV_NO, AXIS_NO, V0, V1) { float v = (axes_count > AXIS_NO) ? axes[AXIS_NO] : V0; v = (v - V0) / (V1 - V0); if (v > 1.0f) v = 1.0f; if (io.NavInputs[NAV_NO] < v) io.NavInputs[NAV_NO] = v; } + io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad; +#if GLFW_HAS_GAMEPAD_API + GLFWgamepadstate gamepad; + if (!glfwGetGamepadState(GLFW_JOYSTICK_1, &gamepad)) + return; + #define MAP_BUTTON(KEY_NO, BUTTON_NO, _UNUSED) do { io.AddKeyEvent(KEY_NO, gamepad.buttons[BUTTON_NO] != 0); } while (0) + #define MAP_ANALOG(KEY_NO, AXIS_NO, _UNUSED, V0, V1) do { float v = gamepad.axes[AXIS_NO]; v = (v - V0) / (V1 - V0); io.AddKeyAnalogEvent(KEY_NO, v > 0.10f, Saturate(v)); } while (0) +#else int axes_count = 0, buttons_count = 0; const float* axes = glfwGetJoystickAxes(GLFW_JOYSTICK_1, &axes_count); const unsigned char* buttons = glfwGetJoystickButtons(GLFW_JOYSTICK_1, &buttons_count); - MAP_BUTTON(ImGuiNavInput_Activate, 0); // Cross / A - MAP_BUTTON(ImGuiNavInput_Cancel, 1); // Circle / B - MAP_BUTTON(ImGuiNavInput_Menu, 2); // Square / X - MAP_BUTTON(ImGuiNavInput_Input, 3); // Triangle / Y - MAP_BUTTON(ImGuiNavInput_DpadLeft, 13); // D-Pad Left - MAP_BUTTON(ImGuiNavInput_DpadRight, 11); // D-Pad Right - MAP_BUTTON(ImGuiNavInput_DpadUp, 10); // D-Pad Up - MAP_BUTTON(ImGuiNavInput_DpadDown, 12); // D-Pad Down - MAP_BUTTON(ImGuiNavInput_FocusPrev, 4); // L1 / LB - MAP_BUTTON(ImGuiNavInput_FocusNext, 5); // R1 / RB - MAP_BUTTON(ImGuiNavInput_TweakSlow, 4); // L1 / LB - MAP_BUTTON(ImGuiNavInput_TweakFast, 5); // R1 / RB - MAP_ANALOG(ImGuiNavInput_LStickLeft, 0, -0.3f, -0.9f); - MAP_ANALOG(ImGuiNavInput_LStickRight,0, +0.3f, +0.9f); - MAP_ANALOG(ImGuiNavInput_LStickUp, 1, +0.3f, +0.9f); - MAP_ANALOG(ImGuiNavInput_LStickDown, 1, -0.3f, -0.9f); + if (axes_count == 0 || buttons_count == 0) + return; + #define MAP_BUTTON(KEY_NO, _UNUSED, BUTTON_NO) do { io.AddKeyEvent(KEY_NO, (buttons_count > BUTTON_NO && buttons[BUTTON_NO] == GLFW_PRESS)); } while (0) + #define MAP_ANALOG(KEY_NO, _UNUSED, AXIS_NO, V0, V1) do { float v = (axes_count > AXIS_NO) ? axes[AXIS_NO] : V0; v = (v - V0) / (V1 - V0); io.AddKeyAnalogEvent(KEY_NO, v > 0.10f, Saturate(v)); } while (0) +#endif + io.BackendFlags |= ImGuiBackendFlags_HasGamepad; + MAP_BUTTON(ImGuiKey_GamepadStart, GLFW_GAMEPAD_BUTTON_START, 7); + MAP_BUTTON(ImGuiKey_GamepadBack, GLFW_GAMEPAD_BUTTON_BACK, 6); + MAP_BUTTON(ImGuiKey_GamepadFaceLeft, GLFW_GAMEPAD_BUTTON_X, 2); // Xbox X, PS Square + MAP_BUTTON(ImGuiKey_GamepadFaceRight, GLFW_GAMEPAD_BUTTON_B, 1); // Xbox B, PS Circle + MAP_BUTTON(ImGuiKey_GamepadFaceUp, GLFW_GAMEPAD_BUTTON_Y, 3); // Xbox Y, PS Triangle + MAP_BUTTON(ImGuiKey_GamepadFaceDown, GLFW_GAMEPAD_BUTTON_A, 0); // Xbox A, PS Cross + MAP_BUTTON(ImGuiKey_GamepadDpadLeft, GLFW_GAMEPAD_BUTTON_DPAD_LEFT, 13); + MAP_BUTTON(ImGuiKey_GamepadDpadRight, GLFW_GAMEPAD_BUTTON_DPAD_RIGHT, 11); + MAP_BUTTON(ImGuiKey_GamepadDpadUp, GLFW_GAMEPAD_BUTTON_DPAD_UP, 10); + MAP_BUTTON(ImGuiKey_GamepadDpadDown, GLFW_GAMEPAD_BUTTON_DPAD_DOWN, 12); + MAP_BUTTON(ImGuiKey_GamepadL1, GLFW_GAMEPAD_BUTTON_LEFT_BUMPER, 4); + MAP_BUTTON(ImGuiKey_GamepadR1, GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER, 5); + MAP_ANALOG(ImGuiKey_GamepadL2, GLFW_GAMEPAD_AXIS_LEFT_TRIGGER, 4, -0.75f, +1.0f); + MAP_ANALOG(ImGuiKey_GamepadR2, GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER, 5, -0.75f, +1.0f); + MAP_BUTTON(ImGuiKey_GamepadL3, GLFW_GAMEPAD_BUTTON_LEFT_THUMB, 8); + MAP_BUTTON(ImGuiKey_GamepadR3, GLFW_GAMEPAD_BUTTON_RIGHT_THUMB, 9); + MAP_ANALOG(ImGuiKey_GamepadLStickLeft, GLFW_GAMEPAD_AXIS_LEFT_X, 0, -0.25f, -1.0f); + MAP_ANALOG(ImGuiKey_GamepadLStickRight, GLFW_GAMEPAD_AXIS_LEFT_X, 0, +0.25f, +1.0f); + MAP_ANALOG(ImGuiKey_GamepadLStickUp, GLFW_GAMEPAD_AXIS_LEFT_Y, 1, -0.25f, -1.0f); + MAP_ANALOG(ImGuiKey_GamepadLStickDown, GLFW_GAMEPAD_AXIS_LEFT_Y, 1, +0.25f, +1.0f); + MAP_ANALOG(ImGuiKey_GamepadRStickLeft, GLFW_GAMEPAD_AXIS_RIGHT_X, 2, -0.25f, -1.0f); + MAP_ANALOG(ImGuiKey_GamepadRStickRight, GLFW_GAMEPAD_AXIS_RIGHT_X, 2, +0.25f, +1.0f); + MAP_ANALOG(ImGuiKey_GamepadRStickUp, GLFW_GAMEPAD_AXIS_RIGHT_Y, 3, -0.25f, -1.0f); + MAP_ANALOG(ImGuiKey_GamepadRStickDown, GLFW_GAMEPAD_AXIS_RIGHT_Y, 3, +0.25f, +1.0f); #undef MAP_BUTTON #undef MAP_ANALOG - if (axes_count > 0 && buttons_count > 0) - io.BackendFlags |= ImGuiBackendFlags_HasGamepad; - else - io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad; } static void ImGui_ImplGlfw_UpdateMonitors() @@ -619,7 +849,7 @@ void ImGui_ImplGlfw_NewFrame() glfwGetFramebufferSize(bd->Window, &display_w, &display_h); io.DisplaySize = ImVec2((float)w, (float)h); if (w > 0 && h > 0) - io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h); + io.DisplayFramebufferScale = ImVec2((float)display_w / (float)w, (float)display_h / (float)h); if (bd->WantUpdateMonitors) ImGui_ImplGlfw_UpdateMonitors(); @@ -628,7 +858,7 @@ void ImGui_ImplGlfw_NewFrame() io.DeltaTime = bd->Time > 0.0 ? (float)(current_time - bd->Time) : (float)(1.0f / 60.0f); bd->Time = current_time; - ImGui_ImplGlfw_UpdateMousePosAndButtons(); + ImGui_ImplGlfw_UpdateMouseData(); ImGui_ImplGlfw_UpdateMouseCursor(); // Update game controllers (if enabled and available) @@ -718,12 +948,15 @@ static void ImGui_ImplGlfw_CreateWindow(ImGuiViewport* viewport) viewport->PlatformHandle = (void*)vd->Window; #ifdef _WIN32 viewport->PlatformHandleRaw = glfwGetWin32Window(vd->Window); +#elif defined(__APPLE__) + viewport->PlatformHandleRaw = (void*)glfwGetCocoaWindow(vd->Window); #endif glfwSetWindowPos(vd->Window, (int)viewport->Pos.x, (int)viewport->Pos.y); // Install GLFW callbacks for secondary viewports glfwSetWindowFocusCallback(vd->Window, ImGui_ImplGlfw_WindowFocusCallback); glfwSetCursorEnterCallback(vd->Window, ImGui_ImplGlfw_CursorEnterCallback); + glfwSetCursorPosCallback(vd->Window, ImGui_ImplGlfw_CursorPosCallback); glfwSetMouseButtonCallback(vd->Window, ImGui_ImplGlfw_MouseButtonCallback); glfwSetScrollCallback(vd->Window, ImGui_ImplGlfw_ScrollCallback); glfwSetKeyCallback(vd->Window, ImGui_ImplGlfw_KeyCallback); @@ -767,12 +1000,12 @@ static void ImGui_ImplGlfw_DestroyWindow(ImGuiViewport* viewport) // We have submitted https://github.com/glfw/glfw/pull/1568 to allow GLFW to support "transparent inputs". // In the meanwhile we implement custom per-platform workarounds here (FIXME-VIEWPORT: Implement same work-around for Linux/OSX!) #if !GLFW_HAS_MOUSE_PASSTHROUGH && GLFW_HAS_WINDOW_HOVERED && defined(_WIN32) -static WNDPROC g_GlfwWndProc = NULL; static LRESULT CALLBACK WndProcNoInputs(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { + ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); if (msg == WM_NCHITTEST) { - // Let mouse pass-through the window. This will allow the backend to set io.MouseHoveredViewport properly (which is OPTIONAL). + // Let mouse pass-through the window. This will allow the backend to call io.AddMouseViewportEvent() properly (which is OPTIONAL). // The ImGuiViewportFlags_NoInputs flag is set while dragging a viewport, as want to detect the window behind the one we are dragging. // If you cannot easily access those viewport flags from your windowing/event code: you may manually synchronize its state e.g. in // your main loop after calling UpdatePlatformWindows(). Iterate all viewports/platform windows and pass the flag to your windowing system. @@ -780,7 +1013,7 @@ static LRESULT CALLBACK WndProcNoInputs(HWND hWnd, UINT msg, WPARAM wParam, LPAR if (viewport->Flags & ImGuiViewportFlags_NoInputs) return HTTRANSPARENT; } - return ::CallWindowProc(g_GlfwWndProc, hWnd, msg, wParam, lParam); + return ::CallWindowProc(bd->GlfwWndProc, hWnd, msg, wParam, lParam); } #endif @@ -801,9 +1034,10 @@ static void ImGui_ImplGlfw_ShowWindow(ImGuiViewport* viewport) // GLFW hack: install hook for WM_NCHITTEST message handler #if !GLFW_HAS_MOUSE_PASSTHROUGH && GLFW_HAS_WINDOW_HOVERED && defined(_WIN32) + ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); ::SetPropA(hwnd, "IMGUI_VIEWPORT", viewport); - if (g_GlfwWndProc == NULL) - g_GlfwWndProc = (WNDPROC)::GetWindowLongPtr(hwnd, GWLP_WNDPROC); + if (bd->GlfwWndProc == NULL) + bd->GlfwWndProc = (WNDPROC)::GetWindowLongPtr(hwnd, GWLP_WNDPROC); ::SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)WndProcNoInputs); #endif @@ -919,31 +1153,6 @@ static void ImGui_ImplGlfw_SwapBuffers(ImGuiViewport* viewport, void*) } } -//-------------------------------------------------------------------------------------------------------- -// IME (Input Method Editor) basic support for e.g. Asian language users -//-------------------------------------------------------------------------------------------------------- - -// We provide a Win32 implementation because this is such a common issue for IME users -#if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) && !defined(IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS) -#define HAS_WIN32_IME 1 -#include -#ifdef _MSC_VER -#pragma comment(lib, "imm32") -#endif -static void ImGui_ImplWin32_SetImeInputPos(ImGuiViewport* viewport, ImVec2 pos) -{ - COMPOSITIONFORM cf = { CFS_FORCE_POSITION, { (LONG)(pos.x - viewport->Pos.x), (LONG)(pos.y - viewport->Pos.y) }, { 0, 0, 0, 0 } }; - if (HWND hwnd = (HWND)viewport->PlatformHandleRaw) - if (HIMC himc = ::ImmGetContext(hwnd)) - { - ::ImmSetCompositionWindow(himc, &cf); - ::ImmReleaseContext(hwnd, himc); - } -} -#else -#define HAS_WIN32_IME 0 -#endif - //-------------------------------------------------------------------------------------------------------- // Vulkan support (the Vulkan renderer needs to call a platform-side support function to create the surface) //-------------------------------------------------------------------------------------------------------- @@ -998,9 +1207,6 @@ static void ImGui_ImplGlfw_InitPlatformInterface() #if GLFW_HAS_VULKAN platform_io.Platform_CreateVkSurface = ImGui_ImplGlfw_CreateVkSurface; #endif -#if HAS_WIN32_IME - platform_io.Platform_SetImeInputPos = ImGui_ImplWin32_SetImeInputPos; -#endif // Register main window handle (which is owned by the main application, not by us) // This is mostly for simplicity and consistency, so that our code (e.g. mouse handling etc.) can use same logic for main and secondary viewports. @@ -1014,4 +1220,9 @@ static void ImGui_ImplGlfw_InitPlatformInterface() static void ImGui_ImplGlfw_ShutdownPlatformInterface() { + ImGui::DestroyPlatformWindows(); } + +#if defined(__clang__) +#pragma clang diagnostic pop +#endif diff --git a/lib/external/imgui/source/imgui_impl_opengl3.cpp b/lib/external/imgui/source/imgui_impl_opengl3.cpp index b8351e965..b7587d0e7 100644 --- a/lib/external/imgui/source/imgui_impl_opengl3.cpp +++ b/lib/external/imgui/source/imgui_impl_opengl3.cpp @@ -5,8 +5,8 @@ // Implemented features: // [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID! -// [X] Renderer: Multi-viewport support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. -// [x] Renderer: Desktop GL only: Support for large meshes (64k+ vertices) with 16-bit indices. +// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. +// [x] Renderer: Large meshes support (64k+ vertices) with 16-bit indices (Desktop OpenGL only). // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. @@ -15,7 +15,11 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) -// 2021-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2022-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2022-05-23: OpenGL: Reworking 2021-12-15 "Using buffer orphaning" so it only happens on Intel GPU, seems to cause problems otherwise. (#4468, #4825, #4832, #5127). +// 2022-05-13: OpenGL: Fix state corruption on OpenGL ES 2.0 due to not preserving GL_ELEMENT_ARRAY_BUFFER_BINDING and vertex attribute states. +// 2021-12-15: OpenGL: Using buffer orphaning + glBufferSubData(), seems to fix leaks with multi-viewports with some Intel HD drivers. +// 2021-08-23: OpenGL: Fixed ES 3.0 shader ("#version 300 es") use normal precision floats to avoid wobbly rendering at HD resolutions. // 2021-08-19: OpenGL: Embed and use our own minimal GL loader (imgui_impl_opengl3_loader.h), removing requirement and support for third-party loader. // 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX). // 2021-06-25: OpenGL: Use OES_vertex_array extension on Emscripten + backup/restore current state. @@ -95,10 +99,27 @@ #else #include // intptr_t #endif +#if defined(__APPLE__) +#include +#endif + +// Clang warnings with -Weverything +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast +#pragma clang diagnostic ignored "-Wsign-conversion" // warning: implicit conversion changes signedness +#if __has_warning("-Wzero-as-null-pointer-constant") +#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" +#endif +#endif // GL includes #if defined(IMGUI_IMPL_OPENGL_ES2) -#include +#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) +#include // Use GL ES 2 +#else +#include // Use GL ES 2 +#endif #if defined(__EMSCRIPTEN__) #ifndef GL_GLEXT_PROTOTYPES #define GL_GLEXT_PROTOTYPES @@ -172,9 +193,12 @@ struct ImGui_ImplOpenGL3_Data GLuint AttribLocationVtxUV; GLuint AttribLocationVtxColor; unsigned int VboHandle, ElementsHandle; + GLsizeiptr VertexBufferSize; + GLsizeiptr IndexBufferSize; bool HasClipOrigin; + bool UseBufferSubData; - ImGui_ImplOpenGL3_Data() { memset(this, 0, sizeof(*this)); } + ImGui_ImplOpenGL3_Data() { memset((void*)this, 0, sizeof(*this)); } }; // Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts @@ -188,6 +212,30 @@ static ImGui_ImplOpenGL3_Data* ImGui_ImplOpenGL3_GetBackendData() static void ImGui_ImplOpenGL3_InitPlatformInterface(); static void ImGui_ImplOpenGL3_ShutdownPlatformInterface(); +// OpenGL vertex attribute state (for ES 1.0 and ES 2.0 only) +#ifndef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY +struct ImGui_ImplOpenGL3_VtxAttribState +{ + GLint Enabled, Size, Type, Normalized, Stride; + GLvoid* Ptr; + + void GetState(GLint index) + { + glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &Enabled); + glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_SIZE, &Size); + glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_TYPE, &Type); + glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &Normalized); + glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_STRIDE, &Stride); + glGetVertexAttribPointerv(index, GL_VERTEX_ATTRIB_ARRAY_POINTER, &Ptr); + } + void SetState(GLint index) + { + glVertexAttribPointer(index, Size, Type, (GLboolean)Normalized, Stride, Ptr); + if (Enabled) glEnableVertexAttribArray(index); else glDisableVertexAttribArray(index); + } +}; +#endif + // Functions bool ImGui_ImplOpenGL3_Init(const char* glsl_version) { @@ -221,6 +269,14 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version) sscanf(gl_version, "%d.%d", &major, &minor); } bd->GlVersion = (GLuint)(major * 100 + minor * 10); + + // Query vendor to enable glBufferSubData kludge +#ifdef _WIN32 + if (const char* vendor = (const char*)glGetString(GL_VENDOR)) + if (strncmp(vendor, "Intel", 5) == 0) + bd->UseBufferSubData = true; +#endif + //printf("GL_MAJOR_VERSION = %d\nGL_MINOR_VERSION = %d\nGL_VENDOR = '%s'\nGL_RENDERER = '%s'\n", major, minor, (const char*)glGetString(GL_VENDOR), (const char*)glGetString(GL_RENDERER)); // [DEBUG] #else bd->GlVersion = 200; // GLES 2 #endif @@ -275,8 +331,9 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version) void ImGui_ImplOpenGL3_Shutdown() { - ImGuiIO& io = ImGui::GetIO(); ImGui_ImplOpenGL3_Data* bd = ImGui_ImplOpenGL3_GetBackendData(); + IM_ASSERT(bd != NULL && "No renderer backend to shutdown, or already shutdown?"); + ImGuiIO& io = ImGui::GetIO(); ImGui_ImplOpenGL3_ShutdownPlatformInterface(); ImGui_ImplOpenGL3_DestroyDeviceObjects(); @@ -389,6 +446,13 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data) GLuint last_sampler; if (bd->GlVersion >= 330) { glGetIntegerv(GL_SAMPLER_BINDING, (GLint*)&last_sampler); } else { last_sampler = 0; } #endif GLuint last_array_buffer; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, (GLint*)&last_array_buffer); +#ifndef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY + // This is part of VAO on OpenGL 3.0+ and OpenGL ES 3.0+. + GLint last_element_array_buffer; glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &last_element_array_buffer); + ImGui_ImplOpenGL3_VtxAttribState last_vtx_attrib_state_pos; last_vtx_attrib_state_pos.GetState(bd->AttribLocationVtxPos); + ImGui_ImplOpenGL3_VtxAttribState last_vtx_attrib_state_uv; last_vtx_attrib_state_uv.GetState(bd->AttribLocationVtxUV); + ImGui_ImplOpenGL3_VtxAttribState last_vtx_attrib_state_color; last_vtx_attrib_state_color.GetState(bd->AttribLocationVtxColor); +#endif #ifdef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY GLuint last_vertex_array_object; glGetIntegerv(GL_VERTEX_ARRAY_BINDING, (GLint*)&last_vertex_array_object); #endif @@ -431,8 +495,31 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data) const ImDrawList* cmd_list = draw_data->CmdLists[n]; // Upload vertex/index buffers - glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)cmd_list->VtxBuffer.Size * (int)sizeof(ImDrawVert), (const GLvoid*)cmd_list->VtxBuffer.Data, GL_STREAM_DRAW); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)cmd_list->IdxBuffer.Size * (int)sizeof(ImDrawIdx), (const GLvoid*)cmd_list->IdxBuffer.Data, GL_STREAM_DRAW); + // - On Intel windows drivers we got reports that regular glBufferData() led to accumulating leaks when using multi-viewports, so we started using orphaning + glBufferSubData(). (See https://github.com/ocornut/imgui/issues/4468) + // - On NVIDIA drivers we got reports that using orphaning + glBufferSubData() led to glitches when using multi-viewports. + // - OpenGL drivers are in a very sorry state in 2022, for now we are switching code path based on vendors. + const GLsizeiptr vtx_buffer_size = (GLsizeiptr)cmd_list->VtxBuffer.Size * (int)sizeof(ImDrawVert); + const GLsizeiptr idx_buffer_size = (GLsizeiptr)cmd_list->IdxBuffer.Size * (int)sizeof(ImDrawIdx); + if (bd->UseBufferSubData) + { + if (bd->VertexBufferSize < vtx_buffer_size) + { + bd->VertexBufferSize = vtx_buffer_size; + glBufferData(GL_ARRAY_BUFFER, bd->VertexBufferSize, NULL, GL_STREAM_DRAW); + } + if (bd->IndexBufferSize < idx_buffer_size) + { + bd->IndexBufferSize = idx_buffer_size; + glBufferData(GL_ELEMENT_ARRAY_BUFFER, bd->IndexBufferSize, NULL, GL_STREAM_DRAW); + } + glBufferSubData(GL_ARRAY_BUFFER, 0, vtx_buffer_size, (const GLvoid*)cmd_list->VtxBuffer.Data); + glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, idx_buffer_size, (const GLvoid*)cmd_list->IdxBuffer.Data); + } + else + { + glBufferData(GL_ARRAY_BUFFER, vtx_buffer_size, (const GLvoid*)cmd_list->VtxBuffer.Data, GL_STREAM_DRAW); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, idx_buffer_size, (const GLvoid*)cmd_list->IdxBuffer.Data, GL_STREAM_DRAW); + } for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) { @@ -449,26 +536,22 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data) else { // Project scissor/clipping rectangles into framebuffer space - ImVec4 clip_rect; - clip_rect.x = (pcmd->ClipRect.x - clip_off.x) * clip_scale.x; - clip_rect.y = (pcmd->ClipRect.y - clip_off.y) * clip_scale.y; - clip_rect.z = (pcmd->ClipRect.z - clip_off.x) * clip_scale.x; - clip_rect.w = (pcmd->ClipRect.w - clip_off.y) * clip_scale.y; + ImVec2 clip_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y); + ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y); + if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y) + continue; - if (clip_rect.x < fb_width && clip_rect.y < fb_height && clip_rect.z >= 0.0f && clip_rect.w >= 0.0f) - { - // Apply scissor/clipping rectangle - glScissor((int)clip_rect.x, (int)(fb_height - clip_rect.w), (int)(clip_rect.z - clip_rect.x), (int)(clip_rect.w - clip_rect.y)); + // Apply scissor/clipping rectangle (Y is inverted in OpenGL) + glScissor((int)clip_min.x, (int)((float)fb_height - clip_max.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y)); - // Bind texture, Draw - glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID()); + // Bind texture, Draw + glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID()); #ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET - if (bd->GlVersion >= 320) - glDrawElementsBaseVertex(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx)), (GLint)pcmd->VtxOffset); - else + if (bd->GlVersion >= 320) + glDrawElementsBaseVertex(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx)), (GLint)pcmd->VtxOffset); + else #endif - glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx))); - } + glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx))); } } } @@ -490,6 +573,12 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data) glBindVertexArray(last_vertex_array_object); #endif glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer); +#ifndef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, last_element_array_buffer); + last_vtx_attrib_state_pos.SetState(bd->AttribLocationVtxPos); + last_vtx_attrib_state_uv.SetState(bd->AttribLocationVtxUV); + last_vtx_attrib_state_color.SetState(bd->AttribLocationVtxColor); +#endif glBlendEquationSeparate(last_blend_equation_rgb, last_blend_equation_alpha); glBlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha); if (last_enable_blend) glEnable(GL_BLEND); else glDisable(GL_BLEND); @@ -520,12 +609,13 @@ bool ImGui_ImplOpenGL3_CreateFontsTexture() io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Load as RGBA 32-bit (75% of the memory is wasted, but default font is so small) because it is more likely to be compatible with user's existing shaders. If your ImTextureId represent a higher-level concept than just a GL texture id, consider calling GetTexDataAsAlpha8() instead to save on GPU memory. // Upload texture to graphics system + // (Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling) GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); glGenTextures(1, &bd->FontTexture); glBindTexture(GL_TEXTURE_2D, bd->FontTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); #ifdef GL_UNPACK_ROW_LENGTH // Not on WebGL/ES glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); #endif @@ -636,7 +726,7 @@ bool ImGui_ImplOpenGL3_CreateDeviceObjects() "}\n"; const GLchar* vertex_shader_glsl_300_es = - "precision mediump float;\n" + "precision highp float;\n" "layout (location = 0) in vec2 Position;\n" "layout (location = 1) in vec2 UV;\n" "layout (location = 2) in vec4 Color;\n" @@ -814,3 +904,7 @@ static void ImGui_ImplOpenGL3_ShutdownPlatformInterface() { ImGui::DestroyPlatformWindows(); } + +#if defined(__clang__) +#pragma clang diagnostic pop +#endif diff --git a/lib/external/imgui/source/imgui_tables.cpp b/lib/external/imgui/source/imgui_tables.cpp index 8a3fe93c1..80ae61376 100644 --- a/lib/external/imgui/source/imgui_tables.cpp +++ b/lib/external/imgui/source/imgui_tables.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.86 +// dear imgui, v1.89 WIP // (tables and columns code) /* @@ -24,7 +24,7 @@ Index of this file: */ // Navigating this file: -// - In Visual Studio IDE: CTRL+comma ("Edit.NavigateTo") can follow symbols in comments, whereas CTRL+F12 ("Edit.GoToImplementation") cannot. +// - In Visual Studio IDE: CTRL+comma ("Edit.GoToAll") can follow symbols in comments, whereas CTRL+F12 ("Edit.GoToImplementation") cannot. // - With Visual Assist installed: ALT+G ("VAssistX.GoToImplementation") can also follow symbols in comments. //----------------------------------------------------------------------------- @@ -361,6 +361,8 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG table->IsLayoutLocked = false; table->InnerWidth = inner_width; temp_data->UserOuterSize = outer_size; + if (instance_no > 0 && table->InstanceDataExtra.Size < instance_no) + table->InstanceDataExtra.push_back(ImGuiTableInstanceData()); // When not using a child window, WorkRect.Max will grow as we append contents. if (use_child_window) @@ -537,7 +539,7 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG if (table->RefScale != 0.0f && table->RefScale != new_ref_scale_unit) { const float scale_factor = new_ref_scale_unit / table->RefScale; - //IMGUI_DEBUG_LOG("[table] %08X RefScaleUnit %.3f -> %.3f, scaling width by %.3f\n", table->ID, table->RefScaleUnit, new_ref_scale_unit, scale_factor); + //IMGUI_DEBUG_PRINT("[table] %08X RefScaleUnit %.3f -> %.3f, scaling width by %.3f\n", table->ID, table->RefScaleUnit, new_ref_scale_unit, scale_factor); for (int n = 0; n < columns_count; n++) table->Columns[n].WidthRequest = table->Columns[n].WidthRequest * scale_factor; } @@ -886,6 +888,7 @@ void ImGui::TableUpdateLayout(ImGuiTable* table) sum_width_requests += table->CellPaddingX * 2.0f; } table->ColumnsEnabledFixedCount = (ImGuiTableColumnIdx)count_fixed; + table->ColumnsStretchSumWeights = stretch_sum_weights; // [Part 4] Apply final widths based on requested widths const ImRect work_rect = table->WorkRect; @@ -933,9 +936,10 @@ void ImGui::TableUpdateLayout(ImGuiTable* table) width_remaining_for_stretched_columns -= 1.0f; } + ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent); table->HoveredColumnBody = -1; table->HoveredColumnBorder = -1; - const ImRect mouse_hit_rect(table->OuterRect.Min.x, table->OuterRect.Min.y, table->OuterRect.Max.x, ImMax(table->OuterRect.Max.y, table->OuterRect.Min.y + table->LastOuterHeight)); + const ImRect mouse_hit_rect(table->OuterRect.Min.x, table->OuterRect.Min.y, table->OuterRect.Max.x, ImMax(table->OuterRect.Max.y, table->OuterRect.Min.y + table_instance->LastOuterHeight)); const bool is_hovering_table = ItemHoverable(mouse_hit_rect, 0); // [Part 6] Setup final position, offset, skip/clip states and clipping rectangles, detect hovered column @@ -1096,23 +1100,15 @@ void ImGui::TableUpdateLayout(ImGuiTable* table) // [Part 10] Hit testing on borders if (table->Flags & ImGuiTableFlags_Resizable) TableUpdateBorders(table); - table->LastFirstRowHeight = 0.0f; + table_instance->LastFirstRowHeight = 0.0f; table->IsLayoutLocked = true; table->IsUsingHeaders = false; // [Part 11] Context menu - if (table->IsContextPopupOpen && table->InstanceCurrent == table->InstanceInteracted) + if (TableBeginContextMenuPopup(table)) { - const ImGuiID context_menu_id = ImHashStr("##ContextMenu", 0, table->ID); - if (BeginPopupEx(context_menu_id, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings)) - { - TableDrawContextMenu(table); - EndPopup(); - } - else - { - table->IsContextPopupOpen = false; - } + TableDrawContextMenu(table); + EndPopup(); } // [Part 13] Sanitize and build sort specs before we have a change to use them for display. @@ -1141,10 +1137,11 @@ void ImGui::TableUpdateBorders(ImGuiTable* table) // use the final height from last frame. Because this is only affecting _interaction_ with columns, it is not // really problematic (whereas the actual visual will be displayed in EndTable() and using the current frame height). // Actual columns highlight/render will be performed in EndTable() and not be affected. + ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent); const float hit_half_width = TABLE_RESIZE_SEPARATOR_HALF_THICKNESS; const float hit_y1 = table->OuterRect.Min.y; - const float hit_y2_body = ImMax(table->OuterRect.Max.y, hit_y1 + table->LastOuterHeight); - const float hit_y2_head = hit_y1 + table->LastFirstRowHeight; + const float hit_y2_body = ImMax(table->OuterRect.Max.y, hit_y1 + table_instance->LastOuterHeight); + const float hit_y2_head = hit_y1 + table_instance->LastFirstRowHeight; for (int order_n = 0; order_n < table->ColumnsCount; order_n++) { @@ -1223,6 +1220,7 @@ void ImGui::EndTable() TableOpenContextMenu((int)table->HoveredColumnBody); // Finalize table height + ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent); inner_window->DC.PrevLineSize = temp_data->HostBackupPrevLineSize; inner_window->DC.CurrLineSize = temp_data->HostBackupCurrLineSize; inner_window->DC.CursorMaxPos = temp_data->HostBackupCursorMaxPos; @@ -1233,7 +1231,7 @@ void ImGui::EndTable() else if (!(flags & ImGuiTableFlags_NoHostExtendY)) table->OuterRect.Max.y = table->InnerRect.Max.y = ImMax(table->OuterRect.Max.y, inner_content_max_y); // Patch OuterRect/InnerRect height table->WorkRect.Max.y = ImMax(table->WorkRect.Max.y, table->OuterRect.Max.y); - table->LastOuterHeight = table->OuterRect.GetHeight(); + table_instance->LastOuterHeight = table->OuterRect.GetHeight(); // Setup inner scrolling range // FIXME: This ideally should be done earlier, in BeginTable() SetNextWindowContentSize call, just like writing to inner_window->DC.CursorMaxPos.y, @@ -1279,17 +1277,23 @@ void ImGui::EndTable() splitter->Merge(inner_window->DrawList); // Update ColumnsAutoFitWidth to get us ahead for host using our size to auto-resize without waiting for next BeginTable() - const float width_spacings = (table->OuterPaddingX * 2.0f) + (table->CellSpacingX1 + table->CellSpacingX2) * (table->ColumnsEnabledCount - 1); - table->ColumnsAutoFitWidth = width_spacings + (table->CellPaddingX * 2.0f) * table->ColumnsEnabledCount; + float auto_fit_width_for_fixed = 0.0f; + float auto_fit_width_for_stretched = 0.0f; + float auto_fit_width_for_stretched_min = 0.0f; for (int column_n = 0; column_n < table->ColumnsCount; column_n++) if (table->EnabledMaskByIndex & ((ImU64)1 << column_n)) { ImGuiTableColumn* column = &table->Columns[column_n]; - if ((column->Flags & ImGuiTableColumnFlags_WidthFixed) && !(column->Flags & ImGuiTableColumnFlags_NoResize)) - table->ColumnsAutoFitWidth += column->WidthRequest; + float column_width_request = ((column->Flags & ImGuiTableColumnFlags_WidthFixed) && !(column->Flags & ImGuiTableColumnFlags_NoResize)) ? column->WidthRequest : TableGetColumnWidthAuto(table, column); + if (column->Flags & ImGuiTableColumnFlags_WidthFixed) + auto_fit_width_for_fixed += column_width_request; else - table->ColumnsAutoFitWidth += TableGetColumnWidthAuto(table, column); + auto_fit_width_for_stretched += column_width_request; + if ((column->Flags & ImGuiTableColumnFlags_WidthStretch) && (column->Flags & ImGuiTableColumnFlags_NoResize) != 0) + auto_fit_width_for_stretched_min = ImMax(auto_fit_width_for_stretched_min, column_width_request / (column->StretchWeight / table->ColumnsStretchSumWeights)); } + const float width_spacings = (table->OuterPaddingX * 2.0f) + (table->CellSpacingX1 + table->CellSpacingX2) * (table->ColumnsEnabledCount - 1); + table->ColumnsAutoFitWidth = width_spacings + (table->CellPaddingX * 2.0f) * table->ColumnsEnabledCount + auto_fit_width_for_fixed + ImMax(auto_fit_width_for_stretched, auto_fit_width_for_stretched_min); // Update scroll if ((table->Flags & ImGuiTableFlags_ScrollX) == 0 && inner_window != outer_window) @@ -1569,18 +1573,21 @@ ImGuiTableColumnFlags ImGui::TableGetColumnFlags(int column_n) // Return the cell rectangle based on currently known height. // - Important: we generally don't know our row height until the end of the row, so Max.y will be incorrect in many situations. -// The only case where this is correct is if we provided a min_row_height to TableNextRow() and don't go below it. +// The only case where this is correct is if we provided a min_row_height to TableNextRow() and don't go below it, or in TableEndRow() when we locked that height. // - Important: if ImGuiTableFlags_PadOuterX is set but ImGuiTableFlags_PadInnerX is not set, the outer-most left and right // columns report a small offset so their CellBgRect can extend up to the outer border. +// FIXME: But the rendering code in TableEndRow() nullifies that with clamping required for scrolling. ImRect ImGui::TableGetCellBgRect(const ImGuiTable* table, int column_n) { const ImGuiTableColumn* column = &table->Columns[column_n]; float x1 = column->MinX; float x2 = column->MaxX; - if (column->PrevEnabledColumn == -1) - x1 -= table->CellSpacingX1; - if (column->NextEnabledColumn == -1) - x2 += table->CellSpacingX2; + //if (column->PrevEnabledColumn == -1) + // x1 -= table->OuterPaddingX; + //if (column->NextEnabledColumn == -1) + // x2 += table->OuterPaddingX; + x1 = ImMax(x1, table->WorkRect.Min.x); + x2 = ImMin(x2, table->WorkRect.Max.x); return ImRect(x1, table->RowPosY1, x2, table->RowPosY2); } @@ -1710,6 +1717,8 @@ void ImGui::TableBeginRow(ImGuiTable* table) table->RowTextBaseline = 0.0f; table->RowIndentOffsetX = window->DC.Indent.x - table->HostIndentX; // Lock indent window->DC.PrevLineTextBaseOffset = 0.0f; + window->DC.CurrLineSize = ImVec2(0.0f, 0.0f); + window->DC.IsSameLine = false; window->DC.CursorMaxPos.y = next_y1; // Making the header BG color non-transparent will allow us to overlay it multiple times when handling smooth dragging. @@ -1746,7 +1755,7 @@ void ImGui::TableEndRow(ImGuiTable* table) const bool unfreeze_rows_actual = (table->CurrentRow + 1 == table->FreezeRowsCount); const bool unfreeze_rows_request = (table->CurrentRow + 1 == table->FreezeRowsRequest); if (table->CurrentRow == 0) - table->LastFirstRowHeight = bg_y2 - bg_y1; + TableGetInstanceData(table, table->InstanceCurrent)->LastFirstRowHeight = bg_y2 - bg_y1; const bool is_visible = (bg_y2 >= table->InnerClipRect.Min.y && bg_y1 <= table->InnerClipRect.Max.y); if (is_visible) @@ -1797,10 +1806,12 @@ void ImGui::TableEndRow(ImGuiTable* table) ImGuiTableCellData* cell_data_end = &table->RowCellData[table->RowCellDataCurrent]; for (ImGuiTableCellData* cell_data = &table->RowCellData[0]; cell_data <= cell_data_end; cell_data++) { + // As we render the BG here we need to clip things (for layout we would not) + // FIXME: This cancels the OuterPadding addition done by TableGetCellBgRect(), need to keep it while rendering correctly while scrolling. const ImGuiTableColumn* column = &table->Columns[cell_data->Column]; ImRect cell_bg_rect = TableGetCellBgRect(table, cell_data->Column); cell_bg_rect.ClipWith(table->BgClipRect); - cell_bg_rect.Min.x = ImMax(cell_bg_rect.Min.x, column->ClipRect.Min.x); // So that first column after frozen one gets clipped + cell_bg_rect.Min.x = ImMax(cell_bg_rect.Min.x, column->ClipRect.Min.x); // So that first column after frozen one gets clipped when scrolling cell_bg_rect.Max.x = ImMin(cell_bg_rect.Max.x, column->MaxX); window->DrawList->AddRectFilled(cell_bg_rect.Min, cell_bg_rect.Max, cell_data->BgColor); } @@ -2083,7 +2094,7 @@ void ImGui::TableSetColumnWidth(int column_n, float width) if (column_0->WidthGiven == column_0_width || column_0->WidthRequest == column_0_width) return; - //IMGUI_DEBUG_LOG("TableSetColumnWidth(%d, %.1f->%.1f)\n", column_0_idx, column_0->WidthGiven, column_0_width); + //IMGUI_DEBUG_PRINT("TableSetColumnWidth(%d, %.1f->%.1f)\n", column_0_idx, column_0->WidthGiven, column_0_width); ImGuiTableColumn* column_1 = (column_0->NextEnabledColumn != -1) ? &table->Columns[column_0->NextEnabledColumn] : NULL; // In this surprisingly not simple because of how we support mixing Fixed and multiple Stretch columns. @@ -2353,7 +2364,7 @@ void ImGui::TableMergeDrawChannels(ImGuiTable* table) // Don't attempt to merge if there are multiple draw calls within the column ImDrawChannel* src_channel = &splitter->_Channels[channel_no]; - if (src_channel->_CmdBuffer.Size > 0 && src_channel->_CmdBuffer.back().ElemCount == 0) + if (src_channel->_CmdBuffer.Size > 0 && src_channel->_CmdBuffer.back().ElemCount == 0 && src_channel->_CmdBuffer.back().UserCallback == NULL) // Equivalent of PopUnusedDrawCmd() src_channel->_CmdBuffer.pop_back(); if (src_channel->_CmdBuffer.Size != 1) continue; @@ -2497,10 +2508,11 @@ void ImGui::TableDrawBorders(ImGuiTable* table) inner_drawlist->PushClipRect(table->Bg0ClipRectForDrawCmd.Min, table->Bg0ClipRectForDrawCmd.Max, false); // Draw inner border and resizing feedback + ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, table->InstanceCurrent); const float border_size = TABLE_BORDER_SIZE; const float draw_y1 = table->InnerRect.Min.y; const float draw_y2_body = table->InnerRect.Max.y; - const float draw_y2_head = table->IsUsingHeaders ? ImMin(table->InnerRect.Max.y, (table->FreezeRowsCount >= 1 ? table->InnerRect.Min.y : table->WorkRect.Min.y) + table->LastFirstRowHeight) : draw_y1; + const float draw_y2_head = table->IsUsingHeaders ? ImMin(table->InnerRect.Max.y, (table->FreezeRowsCount >= 1 ? table->InnerRect.Min.y : table->WorkRect.Min.y) + table_instance->LastFirstRowHeight) : draw_y1; if (table->Flags & ImGuiTableFlags_BordersInnerV) { for (int order_n = 0; order_n < table->ColumnsCount; order_n++) @@ -3017,6 +3029,17 @@ void ImGui::TableOpenContextMenu(int column_n) } } +bool ImGui::TableBeginContextMenuPopup(ImGuiTable* table) +{ + if (!table->IsContextPopupOpen || table->InstanceCurrent != table->InstanceInteracted) + return false; + const ImGuiID context_menu_id = ImHashStr("##ContextMenu", 0, table->ID); + if (BeginPopupEx(context_menu_id, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings)) + return true; + table->IsContextPopupOpen = false; + return false; +} + // Output context menu into current window (generally a popup) // FIXME-TABLE: Ideally this should be writable by the user. Full programmatic access to that data? void ImGui::TableDrawContextMenu(ImGuiTable* table) @@ -3422,9 +3445,8 @@ static void TableSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandle } } -void ImGui::TableSettingsInstallHandler(ImGuiContext* context) +void ImGui::TableSettingsAddSettingsHandler() { - ImGuiContext& g = *context; ImGuiSettingsHandler ini_handler; ini_handler.TypeName = "Table"; ini_handler.TypeHash = ImHashStr("Table"); @@ -3433,7 +3455,7 @@ void ImGui::TableSettingsInstallHandler(ImGuiContext* context) ini_handler.ReadLineFn = TableSettingsHandler_ReadLine; ini_handler.ApplyAllFn = TableSettingsHandler_ApplyAll; ini_handler.WriteAllFn = TableSettingsHandler_WriteAll; - g.SettingsHandlers.push_back(ini_handler); + AddSettingsHandler(&ini_handler); } //------------------------------------------------------------------------- @@ -3447,7 +3469,7 @@ void ImGui::TableSettingsInstallHandler(ImGuiContext* context) // Remove Table (currently only used by TestEngine) void ImGui::TableRemove(ImGuiTable* table) { - //IMGUI_DEBUG_LOG("TableRemove() id=0x%08X\n", table->ID); + //IMGUI_DEBUG_PRINT("TableRemove() id=0x%08X\n", table->ID); ImGuiContext& g = *GImGui; int table_idx = g.Tables.GetIndex(table); //memset(table->RawData.Data, 0, table->RawData.size_in_bytes()); @@ -3459,7 +3481,7 @@ void ImGui::TableRemove(ImGuiTable* table) // Free up/compact internal Table buffers for when it gets unused void ImGui::TableGcCompactTransientBuffers(ImGuiTable* table) { - //IMGUI_DEBUG_LOG("TableGcCompactTransientBuffers() id=0x%08X\n", table->ID); + //IMGUI_DEBUG_PRINT("TableGcCompactTransientBuffers() id=0x%08X\n", table->ID); ImGuiContext& g = *GImGui; IM_ASSERT(table->MemoryCompacted == false); table->SortSpecs.Specs = NULL; @@ -3503,7 +3525,7 @@ void ImGui::TableGcCompactSettings() // - DebugNodeTable() [Internal] //------------------------------------------------------------------------- -#ifndef IMGUI_DISABLE_METRICS_WINDOW +#ifndef IMGUI_DISABLE_DEBUG_TOOLS static const char* DebugNodeTableGetSizingPolicyDesc(ImGuiTableFlags sizing_policy) { @@ -3531,6 +3553,8 @@ void ImGui::DebugNodeTable(ImGuiTable* table) GetForegroundDrawList()->AddRect(GetItemRectMin(), GetItemRectMax(), IM_COL32(255, 255, 0, 255)); if (!open) return; + if (table->InstanceCurrent > 0) + ImGui::Text("** %d instances of same table! Some data below will refer to last instance.", table->InstanceCurrent + 1); bool clear_settings = SmallButton("Clear settings"); BulletText("OuterRect: Pos: (%.1f,%.1f) Size: (%.1f,%.1f) Sizing: '%s'", table->OuterRect.Min.x, table->OuterRect.Min.y, table->OuterRect.GetWidth(), table->OuterRect.GetHeight(), DebugNodeTableGetSizingPolicyDesc(table->Flags)); BulletText("ColumnsGivenWidth: %.1f, ColumnsAutoFitWidth: %.1f, InnerWidth: %.1f%s", table->ColumnsGivenWidth, table->ColumnsAutoFitWidth, table->InnerWidth, table->InnerWidth == 0.0f ? " (auto)" : ""); @@ -3595,7 +3619,7 @@ void ImGui::DebugNodeTableSettings(ImGuiTableSettings* settings) TreePop(); } -#else // #ifndef IMGUI_DISABLE_METRICS_WINDOW +#else // #ifndef IMGUI_DISABLE_DEBUG_TOOLS void ImGui::DebugNodeTable(ImGuiTable*) {} void ImGui::DebugNodeTableSettings(ImGuiTableSettings*) {} @@ -3935,6 +3959,7 @@ void ImGui::NextColumn() { // New row/line: column 0 honor IndentX. window->DC.ColumnsOffset.x = ImMax(column_padding - window->WindowPadding.x, 0.0f); + window->DC.IsSameLine = false; columns->LineMinY = columns->LineMaxY; } window->DC.CursorPos.x = IM_FLOOR(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); diff --git a/lib/external/imgui/source/imgui_widgets.cpp b/lib/external/imgui/source/imgui_widgets.cpp index 89e3681e4..086fa0e61 100644 --- a/lib/external/imgui/source/imgui_widgets.cpp +++ b/lib/external/imgui/source/imgui_widgets.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.86 +// dear imgui, v1.89 WIP // (widgets code) /* @@ -82,6 +82,7 @@ Index of this file: #pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind #pragma GCC diagnostic ignored "-Wformat-nonliteral" // warning: format not a string literal, format string not checked #pragma GCC diagnostic ignored "-Wclass-memaccess" // [__GNUC__ >= 8] warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead +#pragma GCC diagnostic ignored "-Wdeprecated-enum-enum-conversion" // warning: bitwise operation between different enumeration types ('XXXFlags_' and 'XXXFlagsPrivate_') is deprecated #endif //------------------------------------------------------------------------- @@ -166,7 +167,21 @@ void ImGui::TextEx(const char* text, const char* text_end, ImGuiTextFlags flags) const ImVec2 text_pos(window->DC.CursorPos.x, window->DC.CursorPos.y + window->DC.CurrLineTextBaseOffset); const float wrap_pos_x = window->DC.TextWrapPos; const bool wrap_enabled = (wrap_pos_x >= 0.0f); - if (text_end - text > 2000 && !wrap_enabled) + if (text_end - text <= 2000 || wrap_enabled) + { + // Common case + const float wrap_width = wrap_enabled ? CalcWrapWidthForPos(window->DC.CursorPos, wrap_pos_x) : 0.0f; + const ImVec2 text_size = CalcTextSize(text_begin, text_end, false, wrap_width); + + ImRect bb(text_pos, text_pos + text_size); + ItemSize(text_size, 0.0f); + if (!ItemAdd(bb, 0)) + return; + + // Render (we don't hide text after ## in this end-user function) + RenderTextWrapped(bb.Min, text_begin, text_end, wrap_width); + } + else { // Long text! // Perform manual coarse clipping to optimize for long multi-line text @@ -239,19 +254,6 @@ void ImGui::TextEx(const char* text, const char* text_end, ImGuiTextFlags flags) ItemSize(text_size, 0.0f); ItemAdd(bb, 0); } - else - { - const float wrap_width = wrap_enabled ? CalcWrapWidthForPos(window->DC.CursorPos, wrap_pos_x) : 0.0f; - const ImVec2 text_size = CalcTextSize(text_begin, text_end, false, wrap_width); - - ImRect bb(text_pos, text_pos + text_size); - ItemSize(text_size, 0.0f); - if (!ItemAdd(bb, 0)) - return; - - // Render (we don't hide text after ## in this end-user function) - RenderTextWrapped(bb.Min, text_begin, text_end, wrap_width); - } } void ImGui::TextUnformatted(const char* text, const char* text_end) @@ -274,9 +276,9 @@ void ImGui::TextV(const char* fmt, va_list args) return; // FIXME-OPT: Handle the %s shortcut? - ImGuiContext& g = *GImGui; - const char* text_end = g.TempBuffer + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args); - TextEx(g.TempBuffer, text_end, ImGuiTextFlags_NoWidthForLargeClippedText); + const char* text, *text_end; + ImFormatStringToTempBufferV(&text, &text_end, fmt, args); + TextEx(text, text_end, ImGuiTextFlags_NoWidthForLargeClippedText); } void ImGui::TextColored(const ImVec4& col, const char* fmt, ...) @@ -357,8 +359,8 @@ void ImGui::LabelTextV(const char* label, const char* fmt, va_list args) const ImGuiStyle& style = g.Style; const float w = CalcItemWidth(); - const char* value_text_begin = &g.TempBuffer[0]; - const char* value_text_end = value_text_begin + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args); + const char* value_text_begin, *value_text_end; + ImFormatStringToTempBufferV(&value_text_begin, &value_text_end, fmt, args); const ImVec2 value_size = CalcTextSize(value_text_begin, value_text_end, false); const ImVec2 label_size = CalcTextSize(label, NULL, true); @@ -393,8 +395,8 @@ void ImGui::BulletTextV(const char* fmt, va_list args) ImGuiContext& g = *GImGui; const ImGuiStyle& style = g.Style; - const char* text_begin = g.TempBuffer; - const char* text_end = text_begin + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args); + const char* text_begin, *text_end; + ImFormatStringToTempBufferV(&text_begin, &text_end, fmt, args); const ImVec2 label_size = CalcTextSize(text_begin, text_end, false); const ImVec2 total_size = ImVec2(g.FontSize + (label_size.x > 0.0f ? (label_size.x + style.FramePadding.x * 2) : 0.0f), label_size.y); // Empty text doesn't add padding ImVec2 pos = window->DC.CursorPos; @@ -546,13 +548,9 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool { // Poll buttons int mouse_button_clicked = -1; - int mouse_button_released = -1; if ((flags & ImGuiButtonFlags_MouseButtonLeft) && g.IO.MouseClicked[0]) { mouse_button_clicked = 0; } else if ((flags & ImGuiButtonFlags_MouseButtonRight) && g.IO.MouseClicked[1]) { mouse_button_clicked = 1; } else if ((flags & ImGuiButtonFlags_MouseButtonMiddle) && g.IO.MouseClicked[2]) { mouse_button_clicked = 2; } - if ((flags & ImGuiButtonFlags_MouseButtonLeft) && g.IO.MouseReleased[0]) { mouse_button_released = 0; } - else if ((flags & ImGuiButtonFlags_MouseButtonRight) && g.IO.MouseReleased[1]) { mouse_button_released = 1; } - else if ((flags & ImGuiButtonFlags_MouseButtonMiddle) && g.IO.MouseReleased[2]) { mouse_button_released = 2; } if (mouse_button_clicked != -1 && g.ActiveId != id) { @@ -577,15 +575,21 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool FocusWindow(window); } } - if ((flags & ImGuiButtonFlags_PressedOnRelease) && mouse_button_released != -1) + if (flags & ImGuiButtonFlags_PressedOnRelease) { - // Repeat mode trumps on release behavior - const bool has_repeated_at_least_once = (flags & ImGuiButtonFlags_Repeat) && g.IO.MouseDownDurationPrev[mouse_button_released] >= g.IO.KeyRepeatDelay; - if (!has_repeated_at_least_once) - pressed = true; - if (!(flags & ImGuiButtonFlags_NoNavFocus)) - SetFocusID(id, window); - ClearActiveID(); + int mouse_button_released = -1; + if ((flags & ImGuiButtonFlags_MouseButtonLeft) && g.IO.MouseReleased[0]) { mouse_button_released = 0; } + else if ((flags & ImGuiButtonFlags_MouseButtonRight) && g.IO.MouseReleased[1]) { mouse_button_released = 1; } + else if ((flags & ImGuiButtonFlags_MouseButtonMiddle) && g.IO.MouseReleased[2]) { mouse_button_released = 2; } + if (mouse_button_released != -1) + { + const bool has_repeated_at_least_once = (flags & ImGuiButtonFlags_Repeat) && g.IO.MouseDownDurationPrev[mouse_button_released] >= g.IO.KeyRepeatDelay; // Repeat mode trumps on release behavior + if (!has_repeated_at_least_once) + pressed = true; + if (!(flags & ImGuiButtonFlags_NoNavFocus)) + SetFocusID(id, window); + ClearActiveID(); + } } // 'Repeat' mode acts when held regardless of _PressedOn flags (see table above). @@ -607,7 +611,15 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool if (g.NavActivateDownId == id) { bool nav_activated_by_code = (g.NavActivateId == id); - bool nav_activated_by_inputs = IsNavInputTest(ImGuiNavInput_Activate, (flags & ImGuiButtonFlags_Repeat) ? ImGuiInputReadMode_Repeat : ImGuiInputReadMode_Pressed); + bool nav_activated_by_inputs = (g.NavActivatePressedId == id); + if (!nav_activated_by_inputs && (flags & ImGuiButtonFlags_Repeat)) + { + // Avoid pressing both keys from triggering double amount of repeat events + const ImGuiKeyData* key1 = GetKeyData(ImGuiKey_Space); + const ImGuiKeyData* key2 = GetKeyData(ImGuiKey_NavGamepadActivate); + const float t1 = ImMax(key1->DownDuration, key2->DownDuration); + nav_activated_by_inputs = CalcTypematicRepeatAmount(t1 - g.IO.DeltaTime, t1, g.IO.KeyRepeatDelay, g.IO.KeyRepeatRate) > 0; + } if (nav_activated_by_code || nav_activated_by_inputs) { // Set active id so it can be queried by user via IsItemActive(), equivalent of holding the mouse button. @@ -731,6 +743,7 @@ bool ImGui::SmallButton(const char* label) // Then you can keep 'str_id' empty or the same for all your buttons (instead of creating a string based on a non-string id) bool ImGui::InvisibleButton(const char* str_id, const ImVec2& size_arg, ImGuiButtonFlags flags) { + ImGuiContext& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return false; @@ -748,16 +761,17 @@ bool ImGui::InvisibleButton(const char* str_id, const ImVec2& size_arg, ImGuiBut bool hovered, held; bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags); + IMGUI_TEST_ENGINE_ITEM_INFO(id, str_id, g.LastItemData.StatusFlags); return pressed; } bool ImGui::ArrowButtonEx(const char* str_id, ImGuiDir dir, ImVec2 size, ImGuiButtonFlags flags) { + ImGuiContext& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return false; - ImGuiContext& g = *GImGui; const ImGuiID id = window->GetID(str_id); const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size); const float default_size = GetFrameHeight(); @@ -778,6 +792,7 @@ bool ImGui::ArrowButtonEx(const char* str_id, ImGuiDir dir, ImVec2 size, ImGuiBu RenderFrame(bb.Min, bb.Max, bg_col, true, g.Style.FrameRounding); RenderArrow(window->DrawList, bb.Min + ImVec2(ImMax(0.0f, (size.x - g.FontSize) * 0.5f), ImMax(0.0f, (size.y - g.FontSize) * 0.5f)), text_col, dir); + IMGUI_TEST_ENGINE_ITEM_INFO(id, str_id, g.LastItemData.StatusFlags); return pressed; } @@ -841,9 +856,8 @@ bool ImGui::CollapseButton(ImGuiID id, const ImVec2& pos, ImGuiDockNode* dock_no //bool is_dock_menu = (window->DockNodeAsHost && !window->Collapsed); ImU32 bg_col = GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); ImU32 text_col = GetColorU32(ImGuiCol_Text); - ImVec2 center = bb.GetCenter(); if (hovered || held) - window->DrawList->AddCircleFilled(center + ImVec2(0,-0.5f), g.FontSize * 0.5f + 1.0f, bg_col, 12); + window->DrawList->AddCircleFilled(bb.GetCenter() + ImVec2(0,-0.5f), g.FontSize * 0.5f + 1.0f, bg_col, 12); if (dock_node) RenderArrowDockMenu(window->DrawList, bb.Min + g.Style.FramePadding, g.FontSize, text_col); @@ -859,7 +873,7 @@ bool ImGui::CollapseButton(ImGuiID id, const ImVec2& pos, ImGuiDockNode* dock_no ImGuiID ImGui::GetWindowScrollbarID(ImGuiWindow* window, ImGuiAxis axis) { - return window->GetIDNoKeepAlive(axis == ImGuiAxis_X ? "#SCROLLX" : "#SCROLLY"); + return window->GetID(axis == ImGuiAxis_X ? "#SCROLLX" : "#SCROLLY"); } // Return scrollbar rectangle, must only be called for corresponding axis if window->ScrollbarX/Y is set. @@ -880,9 +894,7 @@ void ImGui::Scrollbar(ImGuiAxis axis) { ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; - const ImGuiID id = GetWindowScrollbarID(window, axis); - KeepAliveID(id); // Calculate scrollbar bounding box ImRect bb = GetWindowScrollbarRect(window, axis); @@ -920,6 +932,8 @@ bool ImGui::ScrollbarEx(const ImRect& bb_frame, ImGuiID id, ImGuiAxis axis, ImS6 if (window->SkipItems) return false; + KeepAliveID(id); + const float bb_frame_width = bb_frame.GetWidth(); const float bb_frame_height = bb_frame.GetHeight(); if (bb_frame_width <= 0.0f || bb_frame_height <= 0.0f) @@ -1288,7 +1302,7 @@ void ImGui::Bullet() ImGuiContext& g = *GImGui; const ImGuiStyle& style = g.Style; - const float line_height = ImMax(ImMin(window->DC.CurrLineSize.y, g.FontSize + g.Style.FramePadding.y * 2), g.FontSize); + const float line_height = ImMax(ImMin(window->DC.CurrLineSize.y, g.FontSize + style.FramePadding.y * 2), g.FontSize); const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(g.FontSize, line_height)); ItemSize(bb); if (!ItemAdd(bb, 0)) @@ -1344,6 +1358,7 @@ void ImGui::NewLine() ImGuiContext& g = *GImGui; const ImGuiLayoutType backup_layout_type = window->DC.LayoutType; window->DC.LayoutType = ImGuiLayoutType_Vertical; + window->DC.IsSameLine = false; if (window->DC.CurrLineSize.y > 0.0f) // In the event that we are on a line with items that is smaller that FontSize high, we will preserve its height. ItemSize(ImVec2(0, 0)); else @@ -1541,7 +1556,7 @@ void ImGui::ShrinkWidths(ImGuiShrinkWidthItem* items, int count, float width_exc width_excess -= width_to_remove_per_item * count_same_width; } - // Round width and redistribute remainder left-to-right (could make it an option of the function?) + // Round width and redistribute remainder // Ensure that e.g. the right-most tab of a shrunk tab-bar always reaches exactly at the same distance from the right-most edge of the tab bar separator. width_excess = 0.0f; for (int n = 0; n < count; n++) @@ -1550,10 +1565,13 @@ void ImGui::ShrinkWidths(ImGuiShrinkWidthItem* items, int count, float width_exc width_excess += items[n].Width - width_rounded; items[n].Width = width_rounded; } - if (width_excess > 0.0f) + while (width_excess > 0.0f) for (int n = 0; n < count; n++) - if (items[n].Index < (int)(width_excess + 0.01f)) + if (items[n].Width + 1.0f <= items[n].InitialWidth) + { items[n].Width += 1.0f; + width_excess -= 1.0f; + } } //------------------------------------------------------------------------- @@ -1738,6 +1756,7 @@ bool ImGui::BeginComboPreview() window->DC.CursorPos = preview_data->PreviewRect.Min + g.Style.FramePadding; window->DC.CursorMaxPos = window->DC.CursorPos; window->DC.LayoutType = ImGuiLayoutType_Horizontal; + window->DC.IsSameLine = false; PushClipRect(preview_data->PreviewRect.Min, preview_data->PreviewRect.Max, true); return true; @@ -1763,6 +1782,7 @@ void ImGui::EndComboPreview() window->DC.CursorPosPrevLine = preview_data->BackupCursorPosPrevLine; window->DC.PrevLineTextBaseOffset = preview_data->BackupPrevLineTextBaseOffset; window->DC.LayoutType = preview_data->BackupLayout; + window->DC.IsSameLine = false; preview_data->PreviewRect = ImRect(); } @@ -1870,6 +1890,7 @@ bool ImGui::Combo(const char* label, int* current_item, const char* items_separa // - DataTypeFormatString() // - DataTypeApplyOp() // - DataTypeApplyOpFromText() +// - DataTypeCompare() // - DataTypeClamp() // - GetMinimumStepAtDecimalPrecision // - RoundScalarWithFormat<>() @@ -1909,9 +1930,9 @@ static const char* PatchFormatStringFloatToInt(const char* fmt) #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS if (fmt_start == fmt && fmt_end[0] == 0) return "%d"; - ImGuiContext& g = *GImGui; - ImFormatString(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), "%.*s%%d%s", (int)(fmt_start - fmt), fmt, fmt_end); // Honor leading and trailing decorations, but lose alignment/precision. - return g.TempBuffer; + const char* tmp_format; + ImFormatStringToTempBuffer(&tmp_format, NULL, "%.*s%%d%s", (int)(fmt_start - fmt), fmt, fmt_end); // Honor leading and trailing decorations, but lose alignment/precision. + return tmp_format; #else IM_ASSERT(0 && "DragInt(): Invalid format string!"); // Old versions used a default parameter of "%.0f", please replace with e.g. "%d" #endif @@ -2000,24 +2021,10 @@ void ImGui::DataTypeApplyOp(ImGuiDataType data_type, int op, void* output, const // User can input math operators (e.g. +100) to edit a numerical values. // NB: This is _not_ a full expression evaluator. We should probably add one and replace this dumb mess.. -bool ImGui::DataTypeApplyOpFromText(const char* buf, const char* initial_value_buf, ImGuiDataType data_type, void* p_data, const char* format) +bool ImGui::DataTypeApplyFromText(const char* buf, ImGuiDataType data_type, void* p_data, const char* format) { while (ImCharIsBlankA(*buf)) buf++; - - // We don't support '-' op because it would conflict with inputing negative value. - // Instead you can use +-100 to subtract from an existing value - char op = buf[0]; - if (op == '+' || op == '*' || op == '/') - { - buf++; - while (ImCharIsBlankA(*buf)) - buf++; - } - else - { - op = 0; - } if (!buf[0]) return false; @@ -2026,66 +2033,20 @@ bool ImGui::DataTypeApplyOpFromText(const char* buf, const char* initial_value_b ImGuiDataTypeTempStorage data_backup; memcpy(&data_backup, p_data, type_info->Size); - if (format == NULL) + // Sanitize format + // For float/double we have to ignore format with precision (e.g. "%.2f") because sscanf doesn't take them in, so force them into %f and %lf + char format_sanitized[32]; + if (data_type == ImGuiDataType_Float || data_type == ImGuiDataType_Double) format = type_info->ScanFmt; - - // FIXME-LEGACY: The aim is to remove those operators and write a proper expression evaluator at some point.. - int arg1i = 0; - if (data_type == ImGuiDataType_S32) - { - int* v = (int*)p_data; - int arg0i = *v; - float arg1f = 0.0f; - if (op && sscanf(initial_value_buf, format, &arg0i) < 1) - return false; - // Store operand in a float so we can use fractional value for multipliers (*1.1), but constant always parsed as integer so we can fit big integers (e.g. 2000000003) past float precision - if (op == '+') { if (sscanf(buf, "%d", &arg1i)) *v = (int)(arg0i + arg1i); } // Add (use "+-" to subtract) - else if (op == '*') { if (sscanf(buf, "%f", &arg1f)) *v = (int)(arg0i * arg1f); } // Multiply - else if (op == '/') { if (sscanf(buf, "%f", &arg1f) && arg1f != 0.0f) *v = (int)(arg0i / arg1f); } // Divide - else { if (sscanf(buf, format, &arg1i) == 1) *v = arg1i; } // Assign constant - } - else if (data_type == ImGuiDataType_Float) - { - // For floats we have to ignore format with precision (e.g. "%.2f") because sscanf doesn't take them in - format = "%f"; - float* v = (float*)p_data; - float arg0f = *v, arg1f = 0.0f; - if (op && sscanf(initial_value_buf, format, &arg0f) < 1) - return false; - if (sscanf(buf, format, &arg1f) < 1) - return false; - if (op == '+') { *v = arg0f + arg1f; } // Add (use "+-" to subtract) - else if (op == '*') { *v = arg0f * arg1f; } // Multiply - else if (op == '/') { if (arg1f != 0.0f) *v = arg0f / arg1f; } // Divide - else { *v = arg1f; } // Assign constant - } - else if (data_type == ImGuiDataType_Double) - { - format = "%lf"; // scanf differentiate float/double unlike printf which forces everything to double because of ellipsis - double* v = (double*)p_data; - double arg0f = *v, arg1f = 0.0; - if (op && sscanf(initial_value_buf, format, &arg0f) < 1) - return false; - if (sscanf(buf, format, &arg1f) < 1) - return false; - if (op == '+') { *v = arg0f + arg1f; } // Add (use "+-" to subtract) - else if (op == '*') { *v = arg0f * arg1f; } // Multiply - else if (op == '/') { if (arg1f != 0.0f) *v = arg0f / arg1f; } // Divide - else { *v = arg1f; } // Assign constant - } - else if (data_type == ImGuiDataType_U32 || data_type == ImGuiDataType_S64 || data_type == ImGuiDataType_U64) - { - // All other types assign constant - // We don't bother handling support for legacy operators since they are a little too crappy. Instead we will later implement a proper expression evaluator in the future. - if (sscanf(buf, format, p_data) < 1) - return false; - } else + format = ImParseFormatSanitizeForScanning(format, format_sanitized, IM_ARRAYSIZE(format_sanitized)); + + // Small types need a 32-bit buffer to receive the result from scanf() + int v32 = 0; + if (sscanf(buf, format, type_info->Size >= 4 ? p_data : &v32) < 1) + return false; + if (type_info->Size < 4) { - // Small types need a 32-bit buffer to receive the result from scanf() - int v32; - if (sscanf(buf, format, &v32) < 1) - return false; if (data_type == ImGuiDataType_S8) *(ImS8*)p_data = (ImS8)ImClamp(v32, (int)IM_S8_MIN, (int)IM_S8_MAX); else if (data_type == ImGuiDataType_U8) @@ -2167,45 +2128,17 @@ static float GetMinimumStepAtDecimalPrecision(int decimal_precision) } template -static const char* ImAtoi(const char* src, TYPE* output) -{ - int negative = 0; - if (*src == '-') { negative = 1; src++; } - if (*src == '+') { src++; } - TYPE v = 0; - while (*src >= '0' && *src <= '9') - v = (v * 10) + (*src++ - '0'); - *output = negative ? -v : v; - return src; -} - -// Sanitize format -// - Zero terminate so extra characters after format (e.g. "%f123") don't confuse atof/atoi -// - stb_sprintf.h supports several new modifiers which format numbers in a way that also makes them incompatible atof/atoi. -static void SanitizeFormatString(const char* fmt, char* fmt_out, size_t fmt_out_size) -{ - IM_UNUSED(fmt_out_size); - const char* fmt_end = ImParseFormatFindEnd(fmt); - IM_ASSERT((size_t)(fmt_end - fmt + 1) < fmt_out_size); // Format is too long, let us know if this happens to you! - while (fmt < fmt_end) - { - char c = *(fmt++); - if (c != '\'' && c != '$' && c != '_') // Custom flags provided by stb_sprintf.h. POSIX 2008 also supports '. - *(fmt_out++) = c; - } - *fmt_out = 0; // Zero-terminate -} - -template TYPE ImGui::RoundScalarWithFormatT(const char* format, ImGuiDataType data_type, TYPE v) { + IM_UNUSED(data_type); + IM_ASSERT(data_type == ImGuiDataType_Float || data_type == ImGuiDataType_Double); const char* fmt_start = ImParseFormatFindStart(format); if (fmt_start[0] != '%' || fmt_start[1] == '%') // Don't apply if the value is not visible in the format string return v; // Sanitize format char fmt_sanitized[32]; - SanitizeFormatString(fmt_start, fmt_sanitized, IM_ARRAYSIZE(fmt_sanitized)); + ImParseFormatSanitizeForPrinting(fmt_start, fmt_sanitized, IM_ARRAYSIZE(fmt_sanitized)); fmt_start = fmt_sanitized; // Format value with our rounding, and read back @@ -2214,10 +2147,8 @@ TYPE ImGui::RoundScalarWithFormatT(const char* format, ImGuiDataType data_type, const char* p = v_str; while (*p == ' ') p++; - if (data_type == ImGuiDataType_Float || data_type == ImGuiDataType_Double) - v = (TYPE)ImAtof(p); - else - ImAtoi(p, (SIGNEDTYPE*)&v); + v = (TYPE)ImAtof(p); + return v; } @@ -2267,7 +2198,10 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const else if (g.ActiveIdSource == ImGuiInputSource_Nav) { const int decimal_precision = is_floating_point ? ImParseFormatPrecision(format, 3) : 0; - adjust_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_Keyboard | ImGuiNavDirSourceFlags_PadDPad, ImGuiInputReadMode_RepeatFast, 1.0f / 10.0f, 10.0f)[axis]; + const bool tweak_slow = IsKeyDown((g.NavInputSource == ImGuiInputSource_Gamepad) ? ImGuiKey_NavGamepadTweakSlow : ImGuiKey_NavKeyboardTweakSlow); + const bool tweak_fast = IsKeyDown((g.NavInputSource == ImGuiInputSource_Gamepad) ? ImGuiKey_NavGamepadTweakFast : ImGuiKey_NavKeyboardTweakFast); + const float tweak_factor = tweak_slow ? 1.0f / 1.0f : tweak_fast ? 10.0f : 1.0f; + adjust_delta = GetNavTweakPressedAmount(axis) * tweak_factor; v_speed = ImMax(v_speed, GetMinimumStepAtDecimalPrecision(decimal_precision)); } adjust_delta *= v_speed; @@ -2321,8 +2255,8 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const } // Round to user desired precision based on format string - if (!(flags & ImGuiSliderFlags_NoRoundToFormat)) - v_cur = RoundScalarWithFormatT(format, data_type, v_cur); + if (is_floating_point && !(flags & ImGuiSliderFlags_NoRoundToFormat)) + v_cur = RoundScalarWithFormatT(format, data_type, v_cur); // Preserve remainder after rounding has been applied. This also allow slow tweaking of values. g.DragCurrentAccumDirty = false; @@ -2365,6 +2299,7 @@ bool ImGui::DragBehavior(ImGuiID id, ImGuiDataType data_type, void* p_v, float v ImGuiContext& g = *GImGui; if (g.ActiveId == id) { + // Those are the things we can do easily outside the DragBehaviorT<> template, saves code generation. if (g.ActiveIdSource == ImGuiInputSource_Mouse && !g.IO.MouseDown[0]) ClearActiveID(); else if (g.ActiveIdSource == ImGuiInputSource_Nav && g.NavActivatePressedId == id && !g.ActiveIdIsJustActivated) @@ -2421,26 +2356,20 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* p_data, else if (data_type == ImGuiDataType_S32 && strcmp(format, "%d") != 0) // (FIXME-LEGACY: Patch old "%.0f" format string to use "%d", read function more details.) format = PatchFormatStringFloatToInt(format); - // Tabbing or CTRL-clicking on Drag turns it into an InputText const bool hovered = ItemHoverable(frame_bb, id); bool temp_input_is_active = temp_input_allowed && TempInputIsActive(id); if (!temp_input_is_active) { + // Tabbing or CTRL-clicking on Drag turns it into an InputText const bool input_requested_by_tabbing = temp_input_allowed && (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_FocusedByTabbing) != 0; const bool clicked = (hovered && g.IO.MouseClicked[0]); const bool double_clicked = (hovered && g.IO.MouseClickedCount[0] == 2); - if (input_requested_by_tabbing || clicked || double_clicked || g.NavActivateId == id || g.NavActivateInputId == id) - { - SetActiveID(id, window); - SetFocusID(id, window); - FocusWindow(window); - g.ActiveIdUsingNavDirMask = (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right); - if (temp_input_allowed) - if (input_requested_by_tabbing || (clicked && g.IO.KeyCtrl) || double_clicked || g.NavActivateInputId == id) - temp_input_is_active = true; - } + const bool make_active = (input_requested_by_tabbing || clicked || double_clicked || g.NavActivateId == id || g.NavActivateInputId == id); + if (make_active && temp_input_allowed) + if (input_requested_by_tabbing || (clicked && g.IO.KeyCtrl) || double_clicked || g.NavActivateInputId == id) + temp_input_is_active = true; - // Experimental: simple click (without moving) turns Drag into an InputText + // (Optional) simple click (without moving) turns Drag into an InputText if (g.IO.ConfigDragClickToInputText && temp_input_allowed && !temp_input_is_active) if (g.ActiveId == id && hovered && g.IO.MouseReleased[0] && !IsMouseDragPastThreshold(0, g.IO.MouseDragThreshold * DRAG_MOUSE_THRESHOLD_FACTOR)) { @@ -2448,6 +2377,14 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* p_data, g.NavActivateFlags = ImGuiActivateFlags_PreferInput; temp_input_is_active = true; } + + if (make_active && !temp_input_is_active) + { + SetActiveID(id, window); + SetFocusID(id, window); + FocusWindow(window); + g.ActiveIdUsingNavDirMask = (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right); + } } if (temp_input_is_active) @@ -2702,7 +2639,6 @@ float ImGui::ScaleRatioFromValueT(ImGuiDataType data_type, TYPE v, TYPE v_min, T v_max_fudged = -logarithmic_zero_epsilon; float result; - if (v_clamped <= v_min_fudged) result = 0.0f; // Workaround for values that are in-range but below our fudge else if (v_clamped >= v_max_fudged) @@ -2726,91 +2662,81 @@ float ImGui::ScaleRatioFromValueT(ImGuiDataType data_type, TYPE v, TYPE v_min, T return flipped ? (1.0f - result) : result; } - - // Linear slider - return (float)((FLOATTYPE)(SIGNEDTYPE)(v_clamped - v_min) / (FLOATTYPE)(SIGNEDTYPE)(v_max - v_min)); + else + { + // Linear slider + return (float)((FLOATTYPE)(SIGNEDTYPE)(v_clamped - v_min) / (FLOATTYPE)(SIGNEDTYPE)(v_max - v_min)); + } } // Convert a parametric position on a slider into a value v in the output space (the logical opposite of ScaleRatioFromValueT) template TYPE ImGui::ScaleValueFromRatioT(ImGuiDataType data_type, float t, TYPE v_min, TYPE v_max, bool is_logarithmic, float logarithmic_zero_epsilon, float zero_deadzone_halfsize) { - if (v_min == v_max) + // We special-case the extents because otherwise our logarithmic fudging can lead to "mathematically correct" + // but non-intuitive behaviors like a fully-left slider not actually reaching the minimum value. Also generally simpler. + if (t <= 0.0f || v_min == v_max) return v_min; - const bool is_floating_point = (data_type == ImGuiDataType_Float) || (data_type == ImGuiDataType_Double); + if (t >= 1.0f) + return v_max; - TYPE result; + TYPE result = (TYPE)0; if (is_logarithmic) { - // We special-case the extents because otherwise our fudging can lead to "mathematically correct" but non-intuitive behaviors like a fully-left slider not actually reaching the minimum value - if (t <= 0.0f) - result = v_min; - else if (t >= 1.0f) - result = v_max; - else + // Fudge min/max to avoid getting silly results close to zero + FLOATTYPE v_min_fudged = (ImAbs((FLOATTYPE)v_min) < logarithmic_zero_epsilon) ? ((v_min < 0.0f) ? -logarithmic_zero_epsilon : logarithmic_zero_epsilon) : (FLOATTYPE)v_min; + FLOATTYPE v_max_fudged = (ImAbs((FLOATTYPE)v_max) < logarithmic_zero_epsilon) ? ((v_max < 0.0f) ? -logarithmic_zero_epsilon : logarithmic_zero_epsilon) : (FLOATTYPE)v_max; + + const bool flipped = v_max < v_min; // Check if range is "backwards" + if (flipped) + ImSwap(v_min_fudged, v_max_fudged); + + // Awkward special case - we need ranges of the form (-100 .. 0) to convert to (-100 .. -epsilon), not (-100 .. epsilon) + if ((v_max == 0.0f) && (v_min < 0.0f)) + v_max_fudged = -logarithmic_zero_epsilon; + + float t_with_flip = flipped ? (1.0f - t) : t; // t, but flipped if necessary to account for us flipping the range + + if ((v_min * v_max) < 0.0f) // Range crosses zero, so we have to do this in two parts { - bool flipped = v_max < v_min; // Check if range is "backwards" - - // Fudge min/max to avoid getting silly results close to zero - FLOATTYPE v_min_fudged = (ImAbs((FLOATTYPE)v_min) < logarithmic_zero_epsilon) ? ((v_min < 0.0f) ? -logarithmic_zero_epsilon : logarithmic_zero_epsilon) : (FLOATTYPE)v_min; - FLOATTYPE v_max_fudged = (ImAbs((FLOATTYPE)v_max) < logarithmic_zero_epsilon) ? ((v_max < 0.0f) ? -logarithmic_zero_epsilon : logarithmic_zero_epsilon) : (FLOATTYPE)v_max; - - if (flipped) - ImSwap(v_min_fudged, v_max_fudged); - - // Awkward special case - we need ranges of the form (-100 .. 0) to convert to (-100 .. -epsilon), not (-100 .. epsilon) - if ((v_max == 0.0f) && (v_min < 0.0f)) - v_max_fudged = -logarithmic_zero_epsilon; - - float t_with_flip = flipped ? (1.0f - t) : t; // t, but flipped if necessary to account for us flipping the range - - if ((v_min * v_max) < 0.0f) // Range crosses zero, so we have to do this in two parts - { - float zero_point_center = (-(float)ImMin(v_min, v_max)) / ImAbs((float)v_max - (float)v_min); // The zero point in parametric space - float zero_point_snap_L = zero_point_center - zero_deadzone_halfsize; - float zero_point_snap_R = zero_point_center + zero_deadzone_halfsize; - if (t_with_flip >= zero_point_snap_L && t_with_flip <= zero_point_snap_R) - result = (TYPE)0.0f; // Special case to make getting exactly zero possible (the epsilon prevents it otherwise) - else if (t_with_flip < zero_point_center) - result = (TYPE)-(logarithmic_zero_epsilon * ImPow(-v_min_fudged / logarithmic_zero_epsilon, (FLOATTYPE)(1.0f - (t_with_flip / zero_point_snap_L)))); - else - result = (TYPE)(logarithmic_zero_epsilon * ImPow(v_max_fudged / logarithmic_zero_epsilon, (FLOATTYPE)((t_with_flip - zero_point_snap_R) / (1.0f - zero_point_snap_R)))); - } - else if ((v_min < 0.0f) || (v_max < 0.0f)) // Entirely negative slider - result = (TYPE)-(-v_max_fudged * ImPow(-v_min_fudged / -v_max_fudged, (FLOATTYPE)(1.0f - t_with_flip))); + float zero_point_center = (-(float)ImMin(v_min, v_max)) / ImAbs((float)v_max - (float)v_min); // The zero point in parametric space + float zero_point_snap_L = zero_point_center - zero_deadzone_halfsize; + float zero_point_snap_R = zero_point_center + zero_deadzone_halfsize; + if (t_with_flip >= zero_point_snap_L && t_with_flip <= zero_point_snap_R) + result = (TYPE)0.0f; // Special case to make getting exactly zero possible (the epsilon prevents it otherwise) + else if (t_with_flip < zero_point_center) + result = (TYPE)-(logarithmic_zero_epsilon * ImPow(-v_min_fudged / logarithmic_zero_epsilon, (FLOATTYPE)(1.0f - (t_with_flip / zero_point_snap_L)))); else - result = (TYPE)(v_min_fudged * ImPow(v_max_fudged / v_min_fudged, (FLOATTYPE)t_with_flip)); + result = (TYPE)(logarithmic_zero_epsilon * ImPow(v_max_fudged / logarithmic_zero_epsilon, (FLOATTYPE)((t_with_flip - zero_point_snap_R) / (1.0f - zero_point_snap_R)))); } + else if ((v_min < 0.0f) || (v_max < 0.0f)) // Entirely negative slider + result = (TYPE)-(-v_max_fudged * ImPow(-v_min_fudged / -v_max_fudged, (FLOATTYPE)(1.0f - t_with_flip))); + else + result = (TYPE)(v_min_fudged * ImPow(v_max_fudged / v_min_fudged, (FLOATTYPE)t_with_flip)); } else { // Linear slider + const bool is_floating_point = (data_type == ImGuiDataType_Float) || (data_type == ImGuiDataType_Double); if (is_floating_point) { result = ImLerp(v_min, v_max, t); } - else + else if (t < 1.0) { // - For integer values we want the clicking position to match the grab box so we round above // This code is carefully tuned to work with large values (e.g. high ranges of U64) while preserving this property.. // - Not doing a *1.0 multiply at the end of a range as it tends to be lossy. While absolute aiming at a large s64/u64 // range is going to be imprecise anyway, with this check we at least make the edge values matches expected limits. - if (t < 1.0) - { - FLOATTYPE v_new_off_f = (SIGNEDTYPE)(v_max - v_min) * t; - result = (TYPE)((SIGNEDTYPE)v_min + (SIGNEDTYPE)(v_new_off_f + (FLOATTYPE)(v_min > v_max ? -0.5 : 0.5))); - } - else - { - result = v_max; - } + FLOATTYPE v_new_off_f = (SIGNEDTYPE)(v_max - v_min) * t; + result = (TYPE)((SIGNEDTYPE)v_min + (SIGNEDTYPE)(v_new_off_f + (FLOATTYPE)(v_min > v_max ? -0.5 : 0.5))); } } return result; } -// FIXME: Move more of the code into SliderBehavior() +// FIXME: Try to move more of the code into shared SliderBehavior() template bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_type, TYPE* v, const TYPE v_min, const TYPE v_max, const char* format, ImGuiSliderFlags flags, ImRect* out_grab_bb) { @@ -2820,13 +2746,14 @@ bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_typ const ImGuiAxis axis = (flags & ImGuiSliderFlags_Vertical) ? ImGuiAxis_Y : ImGuiAxis_X; const bool is_logarithmic = (flags & ImGuiSliderFlags_Logarithmic) != 0; const bool is_floating_point = (data_type == ImGuiDataType_Float) || (data_type == ImGuiDataType_Double); + const SIGNEDTYPE v_range = (v_min < v_max ? v_max - v_min : v_min - v_max); - const float grab_padding = 2.0f; + // Calculate bounds + const float grab_padding = 2.0f; // FIXME: Should be part of style. const float slider_sz = (bb.Max[axis] - bb.Min[axis]) - grab_padding * 2.0f; float grab_sz = style.GrabMinSize; - SIGNEDTYPE v_range = (v_min < v_max ? v_max - v_min : v_min - v_max); - if (!is_floating_point && v_range >= 0) // v_range < 0 may happen on integer overflows - grab_sz = ImMax((float)(slider_sz / (v_range + 1)), style.GrabMinSize); // For integer sliders: if possible have the grab size represent 1 unit + if (!is_floating_point && v_range >= 0) // v_range < 0 may happen on integer overflows + grab_sz = ImMax((float)(slider_sz / (v_range + 1)), style.GrabMinSize); // For integer sliders: if possible have the grab size represent 1 unit grab_sz = ImMin(grab_sz, slider_sz); const float slider_usable_sz = slider_sz - grab_sz; const float slider_usable_pos_min = bb.Min[axis] + grab_padding + grab_sz * 0.5f; @@ -2857,7 +2784,17 @@ bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_typ else { const float mouse_abs_pos = g.IO.MousePos[axis]; - clicked_t = (slider_usable_sz > 0.0f) ? ImClamp((mouse_abs_pos - slider_usable_pos_min) / slider_usable_sz, 0.0f, 1.0f) : 0.0f; + if (g.ActiveIdIsJustActivated) + { + float grab_t = ScaleRatioFromValueT(data_type, *v, v_min, v_max, is_logarithmic, logarithmic_zero_epsilon, zero_deadzone_halfsize); + if (axis == ImGuiAxis_Y) + grab_t = 1.0f - grab_t; + const float grab_pos = ImLerp(slider_usable_pos_min, slider_usable_pos_max, grab_t); + const bool clicked_around_grab = (mouse_abs_pos >= grab_pos - grab_sz * 0.5f - 1.0f) && (mouse_abs_pos <= grab_pos + grab_sz * 0.5f + 1.0f); // No harm being extra generous here. + g.SliderGrabClickOffset = (clicked_around_grab && is_floating_point) ? mouse_abs_pos - grab_pos : 0.0f; + } + if (slider_usable_sz > 0.0f) + clicked_t = ImSaturate((mouse_abs_pos - g.SliderGrabClickOffset - slider_usable_pos_min) / slider_usable_sz); if (axis == ImGuiAxis_Y) clicked_t = 1.0f - clicked_t; set_new_value = true; @@ -2871,25 +2808,26 @@ bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_typ g.SliderCurrentAccumDirty = false; } - const ImVec2 input_delta2 = GetNavInputAmount2d(ImGuiNavDirSourceFlags_Keyboard | ImGuiNavDirSourceFlags_PadDPad, ImGuiInputReadMode_RepeatFast, 0.0f, 0.0f); - float input_delta = (axis == ImGuiAxis_X) ? input_delta2.x : -input_delta2.y; + float input_delta = (axis == ImGuiAxis_X) ? GetNavTweakPressedAmount(axis) : -GetNavTweakPressedAmount(axis); if (input_delta != 0.0f) { + const bool tweak_slow = IsKeyDown((g.NavInputSource == ImGuiInputSource_Gamepad) ? ImGuiKey_NavGamepadTweakSlow : ImGuiKey_NavKeyboardTweakSlow); + const bool tweak_fast = IsKeyDown((g.NavInputSource == ImGuiInputSource_Gamepad) ? ImGuiKey_NavGamepadTweakFast : ImGuiKey_NavKeyboardTweakFast); const int decimal_precision = is_floating_point ? ImParseFormatPrecision(format, 3) : 0; if (decimal_precision > 0) { input_delta /= 100.0f; // Gamepad/keyboard tweak speeds in % of slider bounds - if (IsNavInputDown(ImGuiNavInput_TweakSlow)) + if (tweak_slow) input_delta /= 10.0f; } else { - if ((v_range >= -100.0f && v_range <= 100.0f) || IsNavInputDown(ImGuiNavInput_TweakSlow)) + if ((v_range >= -100.0f && v_range <= 100.0f) || tweak_slow) input_delta = ((input_delta < 0.0f) ? -1.0f : +1.0f) / (float)v_range; // Gamepad/keyboard tweak speeds in integer steps else input_delta /= 100.0f; } - if (IsNavInputDown(ImGuiNavInput_TweakFast)) + if (tweak_fast) input_delta *= 10.0f; g.SliderCurrentAccum += input_delta; @@ -2918,8 +2856,8 @@ bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_typ // Calculate what our "new" clicked_t will be, and thus how far we actually moved the slider, and subtract this from the accumulator TYPE v_new = ScaleValueFromRatioT(data_type, clicked_t, v_min, v_max, is_logarithmic, logarithmic_zero_epsilon, zero_deadzone_halfsize); - if (!(flags & ImGuiSliderFlags_NoRoundToFormat)) - v_new = RoundScalarWithFormatT(format, data_type, v_new); + if (is_floating_point && !(flags & ImGuiSliderFlags_NoRoundToFormat)) + v_new = RoundScalarWithFormatT(format, data_type, v_new); float new_clicked_t = ScaleRatioFromValueT(data_type, v_new, v_min, v_max, is_logarithmic, logarithmic_zero_epsilon, zero_deadzone_halfsize); if (delta > 0) @@ -2937,8 +2875,8 @@ bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_typ TYPE v_new = ScaleValueFromRatioT(data_type, clicked_t, v_min, v_max, is_logarithmic, logarithmic_zero_epsilon, zero_deadzone_halfsize); // Round to user desired precision based on format string - if (!(flags & ImGuiSliderFlags_NoRoundToFormat)) - v_new = RoundScalarWithFormatT(format, data_type, v_new); + if (is_floating_point && !(flags & ImGuiSliderFlags_NoRoundToFormat)) + v_new = RoundScalarWithFormatT(format, data_type, v_new); // Apply result if (*v != v_new) @@ -2977,6 +2915,7 @@ bool ImGui::SliderBehavior(const ImRect& bb, ImGuiID id, ImGuiDataType data_type // Read imgui.cpp "API BREAKING CHANGES" section for 1.78 if you hit this assert. IM_ASSERT((flags == 1 || (flags & ImGuiSliderFlags_InvalidMask_) == 0) && "Invalid ImGuiSliderFlags flag! Has the 'float power' argument been mistakenly cast to flags? Call function with ImGuiSliderFlags_Logarithmic flags instead."); + // Those are the things we can do easily outside the SliderBehaviorT<> template, saves code generation. ImGuiContext& g = *GImGui; if ((g.LastItemData.InFlags & ImGuiItemFlags_ReadOnly) || (flags & ImGuiSliderFlags_ReadOnly)) return false; @@ -3039,21 +2978,24 @@ bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* p_dat else if (data_type == ImGuiDataType_S32 && strcmp(format, "%d") != 0) // (FIXME-LEGACY: Patch old "%.0f" format string to use "%d", read function more details.) format = PatchFormatStringFloatToInt(format); - // Tabbing or CTRL-clicking on Slider turns it into an input box const bool hovered = ItemHoverable(frame_bb, id); bool temp_input_is_active = temp_input_allowed && TempInputIsActive(id); if (!temp_input_is_active) { + // Tabbing or CTRL-clicking on Slider turns it into an input box const bool input_requested_by_tabbing = temp_input_allowed && (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_FocusedByTabbing) != 0; const bool clicked = (hovered && g.IO.MouseClicked[0]); - if (input_requested_by_tabbing || clicked || g.NavActivateId == id || g.NavActivateInputId == id) + const bool make_active = (input_requested_by_tabbing || clicked || g.NavActivateId == id || g.NavActivateInputId == id); + if (make_active && temp_input_allowed) + if (input_requested_by_tabbing || (clicked && g.IO.KeyCtrl) || g.NavActivateInputId == id) + temp_input_is_active = true; + + if (make_active && !temp_input_is_active) { SetActiveID(id, window); SetFocusID(id, window); FocusWindow(window); g.ActiveIdUsingNavDirMask |= (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right); - if (temp_input_allowed && (input_requested_by_tabbing || (clicked && g.IO.KeyCtrl) || g.NavActivateInputId == id)) - temp_input_is_active = true; } } @@ -3281,6 +3223,8 @@ bool ImGui::SliderScalarN(const char* label, ImGuiDataType data_type, void* v, i // - ImParseFormatFindStart() [Internal] // - ImParseFormatFindEnd() [Internal] // - ImParseFormatTrimDecorations() [Internal] +// - ImParseFormatSanitizeForPrinting() [Internal] +// - ImParseFormatSanitizeForScanning() [Internal] // - ImParseFormatPrecision() [Internal] // - TempInputTextScalar() [Internal] // - InputScalar() @@ -3344,6 +3288,57 @@ const char* ImParseFormatTrimDecorations(const char* fmt, char* buf, size_t buf_ return buf; } +// Sanitize format +// - Zero terminate so extra characters after format (e.g. "%f123") don't confuse atof/atoi +// - stb_sprintf.h supports several new modifiers which format numbers in a way that also makes them incompatible atof/atoi. +void ImParseFormatSanitizeForPrinting(const char* fmt_in, char* fmt_out, size_t fmt_out_size) +{ + const char* fmt_end = ImParseFormatFindEnd(fmt_in); + IM_UNUSED(fmt_out_size); + IM_ASSERT((size_t)(fmt_end - fmt_in + 1) < fmt_out_size); // Format is too long, let us know if this happens to you! + while (fmt_in < fmt_end) + { + char c = *fmt_in++; + if (c != '\'' && c != '$' && c != '_') // Custom flags provided by stb_sprintf.h. POSIX 2008 also supports '. + *(fmt_out++) = c; + } + *fmt_out = 0; // Zero-terminate +} + +// - For scanning we need to remove all width and precision fields "%3.7f" -> "%f". BUT don't strip types like "%I64d" which includes digits. ! "%07I64d" -> "%I64d" +const char* ImParseFormatSanitizeForScanning(const char* fmt_in, char* fmt_out, size_t fmt_out_size) +{ + const char* fmt_end = ImParseFormatFindEnd(fmt_in); + const char* fmt_out_begin = fmt_out; + IM_UNUSED(fmt_out_size); + IM_ASSERT((size_t)(fmt_end - fmt_in + 1) < fmt_out_size); // Format is too long, let us know if this happens to you! + bool has_type = false; + while (fmt_in < fmt_end) + { + char c = *fmt_in++; + if (!has_type && ((c >= '0' && c <= '9') || c == '.')) + continue; + has_type |= ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); // Stop skipping digits + if (c != '\'' && c != '$' && c != '_') // Custom flags provided by stb_sprintf.h. POSIX 2008 also supports '. + *(fmt_out++) = c; + } + *fmt_out = 0; // Zero-terminate + return fmt_out_begin; +} + +template +static const char* ImAtoi(const char* src, TYPE* output) +{ + int negative = 0; + if (*src == '-') { negative = 1; src++; } + if (*src == '+') { src++; } + TYPE v = 0; + while (*src >= '0' && *src <= '9') + v = (v * 10) + (*src++ - '0'); + *output = negative ? -v : v; + return src; +} + // Parse display precision back from the display format string // FIXME: This is still used by some navigation code path to infer a minimum tweak step, but we should aim to rework widgets so it isn't needed. int ImParseFormatPrecision(const char* fmt, int default_precision) @@ -3390,13 +3385,19 @@ bool ImGui::TempInputText(const ImRect& bb, ImGuiID id, const char* label, char* return value_changed; } +static inline ImGuiInputTextFlags InputScalar_DefaultCharsFilter(ImGuiDataType data_type, const char* format) +{ + if (data_type == ImGuiDataType_Float || data_type == ImGuiDataType_Double) + return ImGuiInputTextFlags_CharsScientific; + const char format_last_char = format[0] ? format[strlen(format) - 1] : 0; + return (format_last_char == 'x' || format_last_char == 'X') ? ImGuiInputTextFlags_CharsHexadecimal : ImGuiInputTextFlags_CharsDecimal; +} + // Note that Drag/Slider functions are only forwarding the min/max values clamping values if the ImGuiSliderFlags_AlwaysClamp flag is set! // This is intended: this way we allow CTRL+Click manual input to set a value out of bounds, for maximum flexibility. // However this may not be ideal for all uses, as some user code may break on out of bound values. bool ImGui::TempInputScalar(const ImRect& bb, ImGuiID id, const char* label, ImGuiDataType data_type, void* p_data, const char* format, const void* p_clamp_min, const void* p_clamp_max) { - ImGuiContext& g = *GImGui; - char fmt_buf[32]; char data_buf[32]; format = ImParseFormatTrimDecorations(format, fmt_buf, IM_ARRAYSIZE(fmt_buf)); @@ -3404,7 +3405,8 @@ bool ImGui::TempInputScalar(const ImRect& bb, ImGuiID id, const char* label, ImG ImStrTrimBlanks(data_buf); ImGuiInputTextFlags flags = ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_NoMarkEdited; - flags |= ((data_type == ImGuiDataType_Float || data_type == ImGuiDataType_Double) ? ImGuiInputTextFlags_CharsScientific : ImGuiInputTextFlags_CharsDecimal); + flags |= InputScalar_DefaultCharsFilter(data_type, format); + bool value_changed = false; if (TempInputText(bb, id, label, data_buf, IM_ARRAYSIZE(data_buf), flags)) { @@ -3414,7 +3416,7 @@ bool ImGui::TempInputScalar(const ImRect& bb, ImGuiID id, const char* label, ImG memcpy(&data_backup, p_data, data_type_size); // Apply new value (or operations) then clamp - DataTypeApplyOpFromText(data_buf, g.InputTextState.InitialTextA.Data, data_type, p_data, NULL); + DataTypeApplyFromText(data_buf, data_type, p_data, format); if (p_clamp_min || p_clamp_max) { if (p_clamp_min && p_clamp_max && DataTypeCompare(data_type, p_clamp_min, p_clamp_max) > 0) @@ -3447,12 +3449,12 @@ bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* p_data char buf[64]; DataTypeFormatString(buf, IM_ARRAYSIZE(buf), data_type, p_data, format); - bool value_changed = false; - if ((flags & (ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsScientific)) == 0) - flags |= ImGuiInputTextFlags_CharsDecimal; - flags |= ImGuiInputTextFlags_AutoSelectAll; - flags |= ImGuiInputTextFlags_NoMarkEdited; // We call MarkItemEdited() ourselves by comparing the actual data rather than the string. + // Testing ActiveId as a minor optimization as filtering is not needed until active + if (g.ActiveId == 0 && (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsScientific)) == 0) + flags |= InputScalar_DefaultCharsFilter(data_type, format); + flags |= ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_NoMarkEdited; // We call MarkItemEdited() ourselves by comparing the actual data rather than the string. + bool value_changed = false; if (p_step != NULL) { const float button_size = GetFrameHeight(); @@ -3461,7 +3463,7 @@ bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* p_data PushID(label); SetNextItemWidth(ImMax(1.0f, CalcItemWidth() - (button_size + style.ItemInnerSpacing.x) * 2)); if (InputText("", buf, IM_ARRAYSIZE(buf), flags)) // PushId(label) + "" gives us the expected ID from outside point of view - value_changed = DataTypeApplyOpFromText(buf, g.InputTextState.InitialTextA.Data, data_type, p_data, format); + value_changed = DataTypeApplyFromText(buf, data_type, p_data, format); // Step buttons const ImVec2 backup_frame_padding = style.FramePadding; @@ -3498,7 +3500,7 @@ bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* p_data else { if (InputText(label, buf, IM_ARRAYSIZE(buf), flags)) - value_changed = DataTypeApplyOpFromText(buf, g.InputTextState.InitialTextA.Data, data_type, p_data, format); + value_changed = DataTypeApplyFromText(buf, data_type, p_data, format); } if (value_changed) MarkItemEdited(g.LastItemData.ID); @@ -3596,7 +3598,11 @@ bool ImGui::InputDouble(const char* label, double* v, double step, double step_f // - InputText() // - InputTextWithHint() // - InputTextMultiline() +// - InputTextGetCharInfo() [Internal] +// - InputTextReindexLines() [Internal] +// - InputTextReindexLinesRange() [Internal] // - InputTextEx() [Internal] +// - DebugNodeInputTextState() [Internal] //------------------------------------------------------------------------- bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data) @@ -3612,7 +3618,7 @@ bool ImGui::InputTextMultiline(const char* label, char* buf, size_t buf_size, co bool ImGui::InputTextWithHint(const char* label, const char* hint, char* buf, size_t buf_size, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data) { - IM_ASSERT(!(flags & ImGuiInputTextFlags_Multiline)); // call InputTextMultiline() + IM_ASSERT(!(flags & ImGuiInputTextFlags_Multiline)); // call InputTextMultiline() or InputTextEx() manually if you need multi-line + hint. return InputTextEx(label, hint, buf, (int)buf_size, ImVec2(0, 0), flags, callback, user_data); } @@ -3703,13 +3709,10 @@ static int is_word_boundary_from_right(ImGuiInputTextState* obj, int idx) static int is_word_boundary_from_left(ImGuiInputTextState* obj, int idx) { if (obj->Flags & ImGuiInputTextFlags_Password) return 0; return idx > 0 ? (!is_separator(obj->TextW[idx - 1]) && is_separator(obj->TextW[idx])) : 1; } static int STB_TEXTEDIT_MOVEWORDLEFT_IMPL(ImGuiInputTextState* obj, int idx) { idx--; while (idx >= 0 && !is_word_boundary_from_right(obj, idx)) idx--; return idx < 0 ? 0 : idx; } static int STB_TEXTEDIT_MOVEWORDRIGHT_MAC(ImGuiInputTextState* obj, int idx) { idx++; int len = obj->CurLenW; while (idx < len && !is_word_boundary_from_left(obj, idx)) idx++; return idx > len ? len : idx; } -#define STB_TEXTEDIT_MOVEWORDLEFT STB_TEXTEDIT_MOVEWORDLEFT_IMPL // They need to be #define for stb_textedit.h -#ifdef __APPLE__ // FIXME: Move setting to IO structure -#define STB_TEXTEDIT_MOVEWORDRIGHT STB_TEXTEDIT_MOVEWORDRIGHT_MAC -#else static int STB_TEXTEDIT_MOVEWORDRIGHT_WIN(ImGuiInputTextState* obj, int idx) { idx++; int len = obj->CurLenW; while (idx < len && !is_word_boundary_from_right(obj, idx)) idx++; return idx > len ? len : idx; } -#define STB_TEXTEDIT_MOVEWORDRIGHT STB_TEXTEDIT_MOVEWORDRIGHT_WIN -#endif +static int STB_TEXTEDIT_MOVEWORDRIGHT_IMPL(ImGuiInputTextState* obj, int idx) { if (ImGui::GetIO().ConfigMacOSXBehaviors) return STB_TEXTEDIT_MOVEWORDRIGHT_MAC(obj, idx); else return STB_TEXTEDIT_MOVEWORDRIGHT_WIN(obj, idx); } +#define STB_TEXTEDIT_MOVEWORDLEFT STB_TEXTEDIT_MOVEWORDLEFT_IMPL // They need to be #define for stb_textedit.h +#define STB_TEXTEDIT_MOVEWORDRIGHT STB_TEXTEDIT_MOVEWORDRIGHT_IMPL static void STB_TEXTEDIT_DELETECHARS(ImGuiInputTextState* obj, int pos, int n) { @@ -3876,7 +3879,7 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f if (c < 0x20) { bool pass = false; - pass |= (c == '\n' && (flags & ImGuiInputTextFlags_Multiline)); + pass |= (c == '\n' && (flags & ImGuiInputTextFlags_Multiline)); // Note that an Enter KEY will emit \r and be ignored (we poll for KEY in InputText() code) pass |= (c == '\t' && (flags & ImGuiInputTextFlags_AllowTabInput)); if (!pass) return false; @@ -3954,6 +3957,41 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f return true; } +// Find the shortest single replacement we can make to get the new text from the old text. +// Important: needs to be run before TextW is rewritten with the new characters because calling STB_TEXTEDIT_GETCHAR() at the end. +// FIXME: Ideally we should transition toward (1) making InsertChars()/DeleteChars() update undo-stack (2) discourage (and keep reconcile) or obsolete (and remove reconcile) accessing buffer directly. +static void InputTextReconcileUndoStateAfterUserCallback(ImGuiInputTextState* state, const char* new_buf_a, int new_length_a) +{ + ImGuiContext& g = *GImGui; + const ImWchar* old_buf = state->TextW.Data; + const int old_length = state->CurLenW; + const int new_length = ImTextCountCharsFromUtf8(new_buf_a, new_buf_a + new_length_a); + g.TempBuffer.reserve_discard((new_length + 1) * sizeof(ImWchar)); + ImWchar* new_buf = (ImWchar*)(void*)g.TempBuffer.Data; + ImTextStrFromUtf8(new_buf, new_length + 1, new_buf_a, new_buf_a + new_length_a); + + const int shorter_length = ImMin(old_length, new_length); + int first_diff; + for (first_diff = 0; first_diff < shorter_length; first_diff++) + if (old_buf[first_diff] != new_buf[first_diff]) + break; + if (first_diff == old_length && first_diff == new_length) + return; + + int old_last_diff = old_length - 1; + int new_last_diff = new_length - 1; + for (; old_last_diff >= first_diff && new_last_diff >= first_diff; old_last_diff--, new_last_diff--) + if (old_buf[old_last_diff] != new_buf[new_last_diff]) + break; + + const int insert_len = new_last_diff - first_diff + 1; + const int delete_len = old_last_diff - first_diff + 1; + if (insert_len > 0 || delete_len > 0) + if (STB_TEXTEDIT_CHARTYPE* p = stb_text_createundo(&state->Stb.undostate, first_diff, delete_len, insert_len)) + for (int i = 0; i < delete_len; i++) + p[i] = ImStb::STB_TEXTEDIT_GETCHAR(state, first_diff + i); +} + // Edit a string of text // - buf_size account for the zero-terminator, so a buf_size of 6 can hold "Hello" but not "Hello!". // This is so we can easily call InputText() on static arrays using ARRAYSIZE() and to match @@ -4074,17 +4112,21 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ state->InitialTextA.resize(buf_len + 1); // UTF-8. we use +1 to make sure that .Data is always pointing to at least an empty string. memcpy(state->InitialTextA.Data, buf, buf_len + 1); + // Preserve cursor position and undo/redo stack if we come back to same widget + // FIXME: Since we reworked this on 2022/06, may want to differenciate recycle_cursor vs recycle_undostate? + bool recycle_state = (state->ID == id && !init_changed_specs); + if (recycle_state && (state->CurLenA != buf_len || (state->TextAIsValid && strncmp(state->TextA.Data, buf, buf_len) != 0))) + recycle_state = false; + // Start edition const char* buf_end = NULL; + state->ID = id; state->TextW.resize(buf_size + 1); // wchar count <= UTF-8 count. we use +1 to make sure that .Data is always pointing to at least an empty string. state->TextA.resize(0); state->TextAIsValid = false; // TextA is not valid yet (we will display buf until then) state->CurLenW = ImTextStrFromUtf8(state->TextW.Data, buf_size, buf, NULL, &buf_end); state->CurLenA = (int)(buf_end - buf); // We can't get the result from ImStrncpy() above because it is not UTF-8 aware. Here we'll cut off malformed UTF-8. - // Preserve cursor position and undo/redo stack if we come back to same widget - // FIXME: For non-readonly widgets we might be able to require that TextAIsValid && TextA == buf ? (untested) and discard undo stack if user buffer has changed. - const bool recycle_state = (state->ID == id && !init_changed_specs); if (recycle_state) { // Recycle existing cursor/selection/undo stack but clamp position @@ -4093,7 +4135,6 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ } else { - state->ID = id; state->ScrollX = 0.0f; stb_textedit_initialize_state(&state->Stb, !is_multiline); } @@ -4120,16 +4161,22 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ FocusWindow(window); // Declare our inputs - IM_ASSERT(ImGuiNavInput_COUNT < 32); g.ActiveIdUsingNavDirMask |= (1 << ImGuiDir_Left) | (1 << ImGuiDir_Right); if (is_multiline || (flags & ImGuiInputTextFlags_CallbackHistory)) g.ActiveIdUsingNavDirMask |= (1 << ImGuiDir_Up) | (1 << ImGuiDir_Down); - g.ActiveIdUsingNavInputMask |= (1 << ImGuiNavInput_Cancel); - g.ActiveIdUsingKeyInputMask |= ((ImU64)1 << ImGuiKey_Home) | ((ImU64)1 << ImGuiKey_End); + SetActiveIdUsingKey(ImGuiKey_Escape); + SetActiveIdUsingKey(ImGuiKey_NavGamepadCancel); + SetActiveIdUsingKey(ImGuiKey_Home); + SetActiveIdUsingKey(ImGuiKey_End); if (is_multiline) - g.ActiveIdUsingKeyInputMask |= ((ImU64)1 << ImGuiKey_PageUp) | ((ImU64)1 << ImGuiKey_PageDown); - if (flags & (ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_AllowTabInput)) // Disable keyboard tabbing out as we will use the \t character. - g.ActiveIdUsingKeyInputMask |= ((ImU64)1 << ImGuiKey_Tab); + { + SetActiveIdUsingKey(ImGuiKey_PageUp); + SetActiveIdUsingKey(ImGuiKey_PageDown); + } + if (flags & (ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_AllowTabInput)) // Disable keyboard tabbing out as we will use the \t character. + { + SetActiveIdUsingKey(ImGuiKey_Tab); + } } // We have an edge case if ActiveId was set through another widget (e.g. widget being swapped), clear id immediately (don't wait until the end of the function) @@ -4144,7 +4191,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ const bool render_cursor = (g.ActiveId == id) || (state && user_scroll_active); bool render_selection = state && (state->HasSelection() || select_all) && (RENDER_SELECTION_WHEN_INACTIVE || render_cursor); bool value_changed = false; - bool enter_pressed = false; + bool validated = false; // When read-only we always use the live data passed to the function // FIXME-OPT: Because our selection/cursor code currently needs the wide text we need to convert it when active, which is not ideal :( @@ -4256,16 +4303,15 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ if (state->SelectedAllMouseLock && !io.MouseDown[0]) state->SelectedAllMouseLock = false; - // It is ill-defined whether the backend needs to send a \t character when pressing the TAB keys. - // Win32 and GLFW naturally do it but not SDL. + // We expect backends to emit a Tab key but some also emit a Tab character which we ignore (#2467, #1336) + // (For Tab and Enter: Win32/SFML/Allegro are sending both keys and chars, GLFW and SDL are only sending keys. For Space they all send all threes) const bool ignore_char_inputs = (io.KeyCtrl && !io.KeyAlt) || (is_osx && io.KeySuper); - if ((flags & ImGuiInputTextFlags_AllowTabInput) && IsKeyPressedMap(ImGuiKey_Tab) && !ignore_char_inputs && !io.KeyShift && !is_readonly) - if (!io.InputQueueCharacters.contains('\t')) - { - unsigned int c = '\t'; // Insert TAB - if (InputTextFilterCharacter(&c, flags, callback, callback_user_data, ImGuiInputSource_Keyboard)) - state->OnKeyPressed((int)c); - } + if ((flags & ImGuiInputTextFlags_AllowTabInput) && IsKeyPressed(ImGuiKey_Tab) && !ignore_char_inputs && !io.KeyShift && !is_readonly) + { + unsigned int c = '\t'; // Insert TAB + if (InputTextFilterCharacter(&c, flags, callback, callback_user_data, ImGuiInputSource_Keyboard)) + state->OnKeyPressed((int)c); + } // Process regular text input (before we check for Return because using some IME will effectively send a Return?) // We ignore CTRL inputs, but need to allow ALT+CTRL as some keyboards (e.g. German) use AltGR (which _is_ Alt+Ctrl) to input certain characters. @@ -4276,7 +4322,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ { // Insert character if they pass filtering unsigned int c = (unsigned int)io.InputQueueCharacters[n]; - if (c == '\t' && io.KeyShift) + if (c == '\t') // Skip Tab, see above. continue; if (InputTextFilterCharacter(&c, flags, callback, callback_user_data, ImGuiInputSource_Keyboard)) state->OnKeyPressed((int)c); @@ -4292,41 +4338,42 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ if (g.ActiveId == id && !g.ActiveIdIsJustActivated && !clear_active_id) { IM_ASSERT(state != NULL); - IM_ASSERT(io.KeyMods == GetMergedKeyModFlags() && "Mismatching io.KeyCtrl/io.KeyShift/io.KeyAlt/io.KeySuper vs io.KeyMods"); // We rarely do this check, but if anything let's do it here. const int row_count_per_page = ImMax((int)((inner_size.y - style.FramePadding.y) / g.FontSize), 1); state->Stb.row_count_per_page = row_count_per_page; const int k_mask = (io.KeyShift ? STB_TEXTEDIT_K_SHIFT : 0); const bool is_osx = io.ConfigMacOSXBehaviors; - const bool is_osx_shift_shortcut = is_osx && (io.KeyMods == (ImGuiKeyModFlags_Super | ImGuiKeyModFlags_Shift)); + const bool is_osx_shift_shortcut = is_osx && (io.KeyMods == (ImGuiModFlags_Super | ImGuiModFlags_Shift)); const bool is_wordmove_key_down = is_osx ? io.KeyAlt : io.KeyCtrl; // OS X style: Text editing cursor movement using Alt instead of Ctrl const bool is_startend_key_down = is_osx && io.KeySuper && !io.KeyCtrl && !io.KeyAlt; // OS X style: Line/Text Start and End using Cmd+Arrows instead of Home/End - const bool is_ctrl_key_only = (io.KeyMods == ImGuiKeyModFlags_Ctrl); - const bool is_shift_key_only = (io.KeyMods == ImGuiKeyModFlags_Shift); - const bool is_shortcut_key = g.IO.ConfigMacOSXBehaviors ? (io.KeyMods == ImGuiKeyModFlags_Super) : (io.KeyMods == ImGuiKeyModFlags_Ctrl); + const bool is_ctrl_key_only = (io.KeyMods == ImGuiModFlags_Ctrl); + const bool is_shift_key_only = (io.KeyMods == ImGuiModFlags_Shift); + const bool is_shortcut_key = g.IO.ConfigMacOSXBehaviors ? (io.KeyMods == ImGuiModFlags_Super) : (io.KeyMods == ImGuiModFlags_Ctrl); - const bool is_cut = ((is_shortcut_key && IsKeyPressedMap(ImGuiKey_X)) || (is_shift_key_only && IsKeyPressedMap(ImGuiKey_Delete))) && !is_readonly && !is_password && (!is_multiline || state->HasSelection()); - const bool is_copy = ((is_shortcut_key && IsKeyPressedMap(ImGuiKey_C)) || (is_ctrl_key_only && IsKeyPressedMap(ImGuiKey_Insert))) && !is_password && (!is_multiline || state->HasSelection()); - const bool is_paste = ((is_shortcut_key && IsKeyPressedMap(ImGuiKey_V)) || (is_shift_key_only && IsKeyPressedMap(ImGuiKey_Insert))) && !is_readonly; - const bool is_undo = ((is_shortcut_key && IsKeyPressedMap(ImGuiKey_Z)) && !is_readonly && is_undoable); - const bool is_redo = ((is_shortcut_key && IsKeyPressedMap(ImGuiKey_Y)) || (is_osx_shift_shortcut && IsKeyPressedMap(ImGuiKey_Z))) && !is_readonly && is_undoable; + const bool is_cut = ((is_shortcut_key && IsKeyPressed(ImGuiKey_X)) || (is_shift_key_only && IsKeyPressed(ImGuiKey_Delete))) && !is_readonly && !is_password && (!is_multiline || state->HasSelection()); + const bool is_copy = ((is_shortcut_key && IsKeyPressed(ImGuiKey_C)) || (is_ctrl_key_only && IsKeyPressed(ImGuiKey_Insert))) && !is_password && (!is_multiline || state->HasSelection()); + const bool is_paste = ((is_shortcut_key && IsKeyPressed(ImGuiKey_V)) || (is_shift_key_only && IsKeyPressed(ImGuiKey_Insert))) && !is_readonly; + const bool is_undo = ((is_shortcut_key && IsKeyPressed(ImGuiKey_Z)) && !is_readonly && is_undoable); + const bool is_redo = ((is_shortcut_key && IsKeyPressed(ImGuiKey_Y)) || (is_osx_shift_shortcut && IsKeyPressed(ImGuiKey_Z))) && !is_readonly && is_undoable; + const bool is_select_all = is_shortcut_key && IsKeyPressed(ImGuiKey_A); // We allow validate/cancel with Nav source (gamepad) to makes it easier to undo an accidental NavInput press with no keyboard wired, but otherwise it isn't very useful. - const bool is_validate_enter = IsKeyPressedMap(ImGuiKey_Enter) || IsKeyPressedMap(ImGuiKey_KeyPadEnter); - const bool is_validate_nav = (IsNavInputTest(ImGuiNavInput_Activate, ImGuiInputReadMode_Pressed) && !IsKeyPressedMap(ImGuiKey_Space)) || IsNavInputTest(ImGuiNavInput_Input, ImGuiInputReadMode_Pressed); - const bool is_cancel = IsKeyPressedMap(ImGuiKey_Escape) || IsNavInputTest(ImGuiNavInput_Cancel, ImGuiInputReadMode_Pressed); + const bool nav_gamepad_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (io.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0; + const bool is_enter_pressed = IsKeyPressed(ImGuiKey_Enter, true) || IsKeyPressed(ImGuiKey_KeypadEnter, true); + const bool is_gamepad_validate = nav_gamepad_active && (IsKeyPressed(ImGuiKey_NavGamepadActivate, false) || IsKeyPressed(ImGuiKey_NavGamepadInput, false)); + const bool is_cancel = IsKeyPressed(ImGuiKey_Escape, false) || (nav_gamepad_active && IsKeyPressed(ImGuiKey_NavGamepadCancel, false)); - if (IsKeyPressedMap(ImGuiKey_LeftArrow)) { state->OnKeyPressed((is_startend_key_down ? STB_TEXTEDIT_K_LINESTART : is_wordmove_key_down ? STB_TEXTEDIT_K_WORDLEFT : STB_TEXTEDIT_K_LEFT) | k_mask); } - else if (IsKeyPressedMap(ImGuiKey_RightArrow)) { state->OnKeyPressed((is_startend_key_down ? STB_TEXTEDIT_K_LINEEND : is_wordmove_key_down ? STB_TEXTEDIT_K_WORDRIGHT : STB_TEXTEDIT_K_RIGHT) | k_mask); } - else if (IsKeyPressedMap(ImGuiKey_UpArrow) && is_multiline) { if (io.KeyCtrl) SetScrollY(draw_window, ImMax(draw_window->Scroll.y - g.FontSize, 0.0f)); else state->OnKeyPressed((is_startend_key_down ? STB_TEXTEDIT_K_TEXTSTART : STB_TEXTEDIT_K_UP) | k_mask); } - else if (IsKeyPressedMap(ImGuiKey_DownArrow) && is_multiline) { if (io.KeyCtrl) SetScrollY(draw_window, ImMin(draw_window->Scroll.y + g.FontSize, GetScrollMaxY())); else state->OnKeyPressed((is_startend_key_down ? STB_TEXTEDIT_K_TEXTEND : STB_TEXTEDIT_K_DOWN) | k_mask); } - else if (IsKeyPressedMap(ImGuiKey_PageUp) && is_multiline) { state->OnKeyPressed(STB_TEXTEDIT_K_PGUP | k_mask); scroll_y -= row_count_per_page * g.FontSize; } - else if (IsKeyPressedMap(ImGuiKey_PageDown) && is_multiline) { state->OnKeyPressed(STB_TEXTEDIT_K_PGDOWN | k_mask); scroll_y += row_count_per_page * g.FontSize; } - else if (IsKeyPressedMap(ImGuiKey_Home)) { state->OnKeyPressed(io.KeyCtrl ? STB_TEXTEDIT_K_TEXTSTART | k_mask : STB_TEXTEDIT_K_LINESTART | k_mask); } - else if (IsKeyPressedMap(ImGuiKey_End)) { state->OnKeyPressed(io.KeyCtrl ? STB_TEXTEDIT_K_TEXTEND | k_mask : STB_TEXTEDIT_K_LINEEND | k_mask); } - else if (IsKeyPressedMap(ImGuiKey_Delete) && !is_readonly && !is_cut) { state->OnKeyPressed(STB_TEXTEDIT_K_DELETE | k_mask); } - else if (IsKeyPressedMap(ImGuiKey_Backspace) && !is_readonly) + if (IsKeyPressed(ImGuiKey_LeftArrow)) { state->OnKeyPressed((is_startend_key_down ? STB_TEXTEDIT_K_LINESTART : is_wordmove_key_down ? STB_TEXTEDIT_K_WORDLEFT : STB_TEXTEDIT_K_LEFT) | k_mask); } + else if (IsKeyPressed(ImGuiKey_RightArrow)) { state->OnKeyPressed((is_startend_key_down ? STB_TEXTEDIT_K_LINEEND : is_wordmove_key_down ? STB_TEXTEDIT_K_WORDRIGHT : STB_TEXTEDIT_K_RIGHT) | k_mask); } + else if (IsKeyPressed(ImGuiKey_UpArrow) && is_multiline) { if (io.KeyCtrl) SetScrollY(draw_window, ImMax(draw_window->Scroll.y - g.FontSize, 0.0f)); else state->OnKeyPressed((is_startend_key_down ? STB_TEXTEDIT_K_TEXTSTART : STB_TEXTEDIT_K_UP) | k_mask); } + else if (IsKeyPressed(ImGuiKey_DownArrow) && is_multiline) { if (io.KeyCtrl) SetScrollY(draw_window, ImMin(draw_window->Scroll.y + g.FontSize, GetScrollMaxY())); else state->OnKeyPressed((is_startend_key_down ? STB_TEXTEDIT_K_TEXTEND : STB_TEXTEDIT_K_DOWN) | k_mask); } + else if (IsKeyPressed(ImGuiKey_PageUp) && is_multiline) { state->OnKeyPressed(STB_TEXTEDIT_K_PGUP | k_mask); scroll_y -= row_count_per_page * g.FontSize; } + else if (IsKeyPressed(ImGuiKey_PageDown) && is_multiline) { state->OnKeyPressed(STB_TEXTEDIT_K_PGDOWN | k_mask); scroll_y += row_count_per_page * g.FontSize; } + else if (IsKeyPressed(ImGuiKey_Home)) { state->OnKeyPressed(io.KeyCtrl ? STB_TEXTEDIT_K_TEXTSTART | k_mask : STB_TEXTEDIT_K_LINESTART | k_mask); } + else if (IsKeyPressed(ImGuiKey_End)) { state->OnKeyPressed(io.KeyCtrl ? STB_TEXTEDIT_K_TEXTEND | k_mask : STB_TEXTEDIT_K_LINEEND | k_mask); } + else if (IsKeyPressed(ImGuiKey_Delete) && !is_readonly && !is_cut) { state->OnKeyPressed(STB_TEXTEDIT_K_DELETE | k_mask); } + else if (IsKeyPressed(ImGuiKey_Backspace) && !is_readonly) { if (!state->HasSelection()) { @@ -4337,12 +4384,17 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ } state->OnKeyPressed(STB_TEXTEDIT_K_BACKSPACE | k_mask); } - else if (is_validate_enter) + else if (is_enter_pressed || is_gamepad_validate) { + // Determine if we turn Enter into a \n character bool ctrl_enter_for_new_line = (flags & ImGuiInputTextFlags_CtrlEnterForNewLine) != 0; - if (!is_multiline || (ctrl_enter_for_new_line && !io.KeyCtrl) || (!ctrl_enter_for_new_line && io.KeyCtrl)) + if (!is_multiline || is_gamepad_validate || (ctrl_enter_for_new_line && !io.KeyCtrl) || (!ctrl_enter_for_new_line && io.KeyCtrl)) { - enter_pressed = clear_active_id = true; + validated = true; + if (io.ConfigInputTextEnterKeepActive && !is_multiline) + state->SelectAll(); // No need to scroll + else + clear_active_id = true; } else if (!is_readonly) { @@ -4351,11 +4403,6 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ state->OnKeyPressed((int)c); } } - else if (is_validate_nav) - { - IM_ASSERT(!is_validate_enter); - enter_pressed = clear_active_id = true; - } else if (is_cancel) { clear_active_id = cancel_edit = true; @@ -4365,7 +4412,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ state->OnKeyPressed(is_undo ? STB_TEXTEDIT_K_UNDO : STB_TEXTEDIT_K_REDO); state->ClearSelection(); } - else if (is_shortcut_key && IsKeyPressedMap(ImGuiKey_A)) + else if (is_select_all) { state->SelectAll(); state->CursorFollow = true; @@ -4447,22 +4494,24 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ } } + // Apply ASCII value + if (!is_readonly) + { + state->TextAIsValid = true; + state->TextA.resize(state->TextW.Size * 4 + 1); + ImTextStrToUtf8(state->TextA.Data, state->TextA.Size, state->TextW.Data, NULL); + } + // When using 'ImGuiInputTextFlags_EnterReturnsTrue' as a special case we reapply the live buffer back to the input buffer before clearing ActiveId, even though strictly speaking it wasn't modified on this frame. // If we didn't do that, code like InputInt() with ImGuiInputTextFlags_EnterReturnsTrue would fail. // This also allows the user to use InputText() with ImGuiInputTextFlags_EnterReturnsTrue without maintaining any user-side storage (please note that if you use this property along ImGuiInputTextFlags_CallbackResize you can end up with your temporary string object unnecessarily allocating once a frame, either store your string data, either if you don't then don't use ImGuiInputTextFlags_CallbackResize). - bool apply_edit_back_to_user_buffer = !cancel_edit || (enter_pressed && (flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0); + const bool apply_edit_back_to_user_buffer = !cancel_edit || (validated && (flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0); if (apply_edit_back_to_user_buffer) { // Apply new value immediately - copy modified buffer back // Note that as soon as the input box is active, the in-widget value gets priority over any underlying modification of the input buffer // FIXME: We actually always render 'buf' when calling DrawList->AddText, making the comment above incorrect. // FIXME-OPT: CPU waste to do this every time the widget is active, should mark dirty state from the stb_textedit callbacks. - if (!is_readonly) - { - state->TextAIsValid = true; - state->TextA.resize(state->TextW.Size * 4 + 1); - ImTextStrToUtf8(state->TextA.Data, state->TextA.Size, state->TextW.Data, NULL); - } // User callback if ((flags & (ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory | ImGuiInputTextFlags_CallbackEdit | ImGuiInputTextFlags_CallbackAlways)) != 0) @@ -4471,18 +4520,18 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ // The reason we specify the usage semantic (Completion/History) is that Completion needs to disable keyboard TABBING at the moment. ImGuiInputTextFlags event_flag = 0; - ImGuiKey event_key = ImGuiKey_COUNT; - if ((flags & ImGuiInputTextFlags_CallbackCompletion) != 0 && IsKeyPressedMap(ImGuiKey_Tab)) + ImGuiKey event_key = ImGuiKey_None; + if ((flags & ImGuiInputTextFlags_CallbackCompletion) != 0 && IsKeyPressed(ImGuiKey_Tab)) { event_flag = ImGuiInputTextFlags_CallbackCompletion; event_key = ImGuiKey_Tab; } - else if ((flags & ImGuiInputTextFlags_CallbackHistory) != 0 && IsKeyPressedMap(ImGuiKey_UpArrow)) + else if ((flags & ImGuiInputTextFlags_CallbackHistory) != 0 && IsKeyPressed(ImGuiKey_UpArrow)) { event_flag = ImGuiInputTextFlags_CallbackHistory; event_key = ImGuiKey_UpArrow; } - else if ((flags & ImGuiInputTextFlags_CallbackHistory) != 0 && IsKeyPressedMap(ImGuiKey_DownArrow)) + else if ((flags & ImGuiInputTextFlags_CallbackHistory) != 0 && IsKeyPressed(ImGuiKey_DownArrow)) { event_flag = ImGuiInputTextFlags_CallbackHistory; event_key = ImGuiKey_DownArrow; @@ -4532,8 +4581,9 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ if (buf_dirty) { IM_ASSERT(callback_data.BufTextLen == (int)strlen(callback_data.Buf)); // You need to maintain BufTextLen if you change the text! + InputTextReconcileUndoStateAfterUserCallback(state, callback_data.Buf, callback_data.BufTextLen); // FIXME: Move the rest of this block inside function and rename to InputTextReconcileStateAfterUserCallback() ? if (callback_data.BufTextLen > backup_current_text_length && is_resizable) - state->TextW.resize(state->TextW.Size + (callback_data.BufTextLen - backup_current_text_length)); + state->TextW.resize(state->TextW.Size + (callback_data.BufTextLen - backup_current_text_length)); // Worse case scenario resize state->CurLenW = ImTextStrFromUtf8(state->TextW.Data, state->TextW.Size, callback_data.Buf, NULL); state->CurLenA = callback_data.BufTextLen; // Assume correct length and valid UTF-8 from user, saves us an extra strlen() state->CursorAnimReset(); @@ -4575,7 +4625,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ apply_new_text_length = ImMin(callback_data.BufTextLen, buf_size - 1); IM_ASSERT(apply_new_text_length <= buf_size); } - //IMGUI_DEBUG_LOG("InputText(\"%s\"): apply_new_text length %d\n", label, apply_new_text_length); + //IMGUI_DEBUG_PRINT("InputText(\"%s\"): apply_new_text length %d\n", label, apply_new_text_length); // If the underlying buffer resize was denied or not carried to the next frame, apply_new_text_length+1 may be >= buf_size. ImStrncpy(buf, apply_new_text, ImMin(apply_new_text_length + 1, buf_size)); @@ -4769,8 +4819,10 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ // Notify OS of text input position for advanced IME (-1 x offset so that Windows IME can cover our cursor. Bit of an extra nicety.) if (!is_readonly) { - g.PlatformImePos = ImVec2(cursor_screen_pos.x - 1, cursor_screen_pos.y - g.FontSize); - g.PlatformImePosViewport = window->Viewport; + g.PlatformImeData.WantVisible = true; + g.PlatformImeData.InputPos = ImVec2(cursor_screen_pos.x - 1.0f, cursor_screen_pos.y - g.FontSize); + g.PlatformImeData.InputLineHeight = g.FontSize; + g.PlatformImeViewport = window->Viewport->ID; } } } @@ -4830,11 +4882,45 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_ IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags); if ((flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0) - return enter_pressed; + return validated; else return value_changed; } +void ImGui::DebugNodeInputTextState(ImGuiInputTextState* state) +{ +#ifndef IMGUI_DISABLE_DEBUG_TOOLS + ImGuiContext& g = *GImGui; + ImStb::STB_TexteditState* stb_state = &state->Stb; + ImStb::StbUndoState* undo_state = &stb_state->undostate; + Text("ID: 0x%08X, ActiveID: 0x%08X", state->ID, g.ActiveId); + Text("CurLenW: %d, CurLenA: %d, Cursor: %d, Selection: %d..%d", state->CurLenA, state->CurLenW, stb_state->cursor, stb_state->select_start, stb_state->select_end); + Text("undo_point: %d, redo_point: %d, undo_char_point: %d, redo_char_point: %d", undo_state->undo_point, undo_state->redo_point, undo_state->undo_char_point, undo_state->redo_char_point); + if (BeginChild("undopoints", ImVec2(0.0f, GetTextLineHeight() * 15), true)) // Visualize undo state + { + PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); + for (int n = 0; n < STB_TEXTEDIT_UNDOSTATECOUNT; n++) + { + ImStb::StbUndoRecord* undo_rec = &undo_state->undo_rec[n]; + const char undo_rec_type = (n < undo_state->undo_point) ? 'u' : (n >= undo_state->redo_point) ? 'r' : ' '; + if (undo_rec_type == ' ') + BeginDisabled(); + char buf[64] = ""; + if (undo_rec_type != ' ' && undo_rec->char_storage != -1) + ImTextStrToUtf8(buf, IM_ARRAYSIZE(buf), undo_state->undo_char + undo_rec->char_storage, undo_state->undo_char + undo_rec->char_storage + undo_rec->insert_length); + Text("%c [%02d] where %03d, insert %03d, delete %03d, char_storage %03d \"%s\"", + undo_rec_type, n, undo_rec->where, undo_rec->insert_length, undo_rec->delete_length, undo_rec->char_storage, buf); + if (undo_rec_type == ' ') + EndDisabled(); + } + PopStyleVar(); + } + EndChild(); +#else + IM_UNUSED(state); +#endif +} + //------------------------------------------------------------------------- // [SECTION] Widgets: ColorEdit, ColorPicker, ColorButton, etc. //------------------------------------------------------------------------- @@ -4984,7 +5070,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag value_changed |= DragInt(ids[n], &i[n], 1.0f, 0, hdr ? 0 : 255, fmt_table_int[fmt_idx][n]); } if (!(flags & ImGuiColorEditFlags_NoOptions)) - OpenPopupOnItemClick("context"); + OpenPopupOnItemClick("context", ImGuiPopupFlags_MouseButtonRight); } } else if ((flags & ImGuiColorEditFlags_DisplayHex) != 0 && (flags & ImGuiColorEditFlags_NoInputs) == 0) @@ -5012,7 +5098,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag IM_UNUSED(r); // Fixes C6031: Return value ignored: 'sscanf'. } if (!(flags & ImGuiColorEditFlags_NoOptions)) - OpenPopupOnItemClick("context"); + OpenPopupOnItemClick("context", ImGuiPopupFlags_MouseButtonRight); } ImGuiWindow* picker_active_window = NULL; @@ -5029,11 +5115,11 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag // Store current color and open a picker g.ColorPickerRef = col_v4; OpenPopup("picker"); - SetNextWindowPos(g.LastItemData.Rect.GetBL() + ImVec2(-1, style.ItemSpacing.y)); + SetNextWindowPos(g.LastItemData.Rect.GetBL() + ImVec2(0.0f, style.ItemSpacing.y)); } } if (!(flags & ImGuiColorEditFlags_NoOptions)) - OpenPopupOnItemClick("context"); + OpenPopupOnItemClick("context", ImGuiPopupFlags_MouseButtonRight); if (BeginPopup("picker")) { @@ -5053,8 +5139,7 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag if (label != label_display_end && !(flags & ImGuiColorEditFlags_NoLabel)) { - const float text_offset_x = (flags & ImGuiColorEditFlags_NoInputs) ? w_button : w_full + style.ItemInnerSpacing.x; - window->DC.CursorPos = ImVec2(pos.x + text_offset_x, pos.y + style.FramePadding.y); + SameLine(0.0f, style.ItemInnerSpacing.x); TextEx(label, label_display_end); } @@ -5247,7 +5332,7 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl } } if (!(flags & ImGuiColorEditFlags_NoOptions)) - OpenPopupOnItemClick("context"); + OpenPopupOnItemClick("context", ImGuiPopupFlags_MouseButtonRight); } else if (flags & ImGuiColorEditFlags_PickerHueBar) { @@ -5264,7 +5349,7 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl value_changed = value_changed_sv = true; } if (!(flags & ImGuiColorEditFlags_NoOptions)) - OpenPopupOnItemClick("context"); + OpenPopupOnItemClick("context", ImGuiPopupFlags_MouseButtonRight); // Hue bar logic SetCursorScreenPos(ImVec2(bar0_pos_x, picker_pos.y)); @@ -5510,7 +5595,7 @@ bool ImGui::ColorPicker4(const char* label, float col[4], ImGuiColorEditFlags fl // FIXME: May want to display/ignore the alpha component in the color display? Yet show it in the tooltip. // 'desc_id' is not called 'label' because we don't display it next to the button, but only in the tooltip. // Note that 'col' may be encoded in HSV if ImGuiColorEditFlags_InputHSV is set. -bool ImGui::ColorButton(const char* desc_id, const ImVec4& col, ImGuiColorEditFlags flags, ImVec2 size) +bool ImGui::ColorButton(const char* desc_id, const ImVec4& col, ImGuiColorEditFlags flags, const ImVec2& size_arg) { ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) @@ -5518,11 +5603,8 @@ bool ImGui::ColorButton(const char* desc_id, const ImVec4& col, ImGuiColorEditFl ImGuiContext& g = *GImGui; const ImGuiID id = window->GetID(desc_id); - float default_size = GetFrameHeight(); - if (size.x == 0.0f) - size.x = default_size; - if (size.y == 0.0f) - size.y = default_size; + const float default_size = GetFrameHeight(); + const ImVec2 size(size_arg.x == 0.0f ? default_size : size_arg.x, size_arg.y == 0.0f ? default_size : size_arg.y); const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size); ItemSize(bb, (size.y >= default_size) ? g.Style.FramePadding.y : 0.0f); if (!ItemAdd(bb, id)) @@ -5820,9 +5902,9 @@ bool ImGui::TreeNodeExV(const char* str_id, ImGuiTreeNodeFlags flags, const char if (window->SkipItems) return false; - ImGuiContext& g = *GImGui; - const char* label_end = g.TempBuffer + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args); - return TreeNodeBehavior(window->GetID(str_id), flags, g.TempBuffer, label_end); + const char* label, *label_end; + ImFormatStringToTempBufferV(&label, &label_end, fmt, args); + return TreeNodeBehavior(window->GetID(str_id), flags, label, label_end); } bool ImGui::TreeNodeExV(const void* ptr_id, ImGuiTreeNodeFlags flags, const char* fmt, va_list args) @@ -5831,12 +5913,19 @@ bool ImGui::TreeNodeExV(const void* ptr_id, ImGuiTreeNodeFlags flags, const char if (window->SkipItems) return false; - ImGuiContext& g = *GImGui; - const char* label_end = g.TempBuffer + ImFormatStringV(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), fmt, args); - return TreeNodeBehavior(window->GetID(ptr_id), flags, g.TempBuffer, label_end); + const char* label, *label_end; + ImFormatStringToTempBufferV(&label, &label_end, fmt, args); + return TreeNodeBehavior(window->GetID(ptr_id), flags, label, label_end); } -bool ImGui::TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags) +void ImGui::TreeNodeSetOpen(ImGuiID id, bool open) +{ + ImGuiContext& g = *GImGui; + ImGuiStorage* storage = g.CurrentWindow->DC.StateStorage; + storage->SetInt(id, open ? 1 : 0); +} + +bool ImGui::TreeNodeUpdateNextOpen(ImGuiID id, ImGuiTreeNodeFlags flags) { if (flags & ImGuiTreeNodeFlags_Leaf) return true; @@ -5852,7 +5941,7 @@ bool ImGui::TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags) if (g.NextItemData.OpenCond & ImGuiCond_Always) { is_open = g.NextItemData.OpenVal; - storage->SetInt(id, is_open); + TreeNodeSetOpen(id, is_open); } else { @@ -5861,7 +5950,7 @@ bool ImGui::TreeNodeBehaviorIsOpen(ImGuiID id, ImGuiTreeNodeFlags flags) if (stored_value == -1) { is_open = g.NextItemData.OpenVal; - storage->SetInt(id, is_open); + TreeNodeSetOpen(id, is_open); } else { @@ -5927,7 +6016,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l // For this purpose we essentially compare if g.NavIdIsAlive went from 0 to 1 between TreeNode() and TreePop(). // This is currently only support 32 level deep and we are fine with (1 << Depth) overflowing into a zero. const bool is_leaf = (flags & ImGuiTreeNodeFlags_Leaf) != 0; - bool is_open = TreeNodeBehaviorIsOpen(id, flags); + bool is_open = TreeNodeUpdateNextOpen(id, flags); if (is_open && !g.NavIdIsAlive && (flags & ImGuiTreeNodeFlags_NavLeftJumpsBackHere) && !(flags & ImGuiTreeNodeFlags_NoTreePushOnOpen)) window->DC.TreeJumpToParentOnPopMask |= (1 << window->DC.TreeDepth); @@ -6760,6 +6849,7 @@ bool ImGui::BeginMenuBar() // We overwrite CursorMaxPos because BeginGroup sets it to CursorPos (essentially the .EmitItem hack in EndMenuBar() would need something analogous here, maybe a BeginGroupEx() with flags). window->DC.CursorPos = window->DC.CursorMaxPos = ImVec2(bar_rect.Min.x + window->DC.MenuBarOffset.x, bar_rect.Min.y + window->DC.MenuBarOffset.y); window->DC.LayoutType = ImGuiLayoutType_Horizontal; + window->DC.IsSameLine = false; window->DC.NavLayerCurrent = ImGuiNavLayer_Menu; window->DC.MenuBarAppending = true; AlignTextToFramePadding(); @@ -6803,6 +6893,7 @@ void ImGui::EndMenuBar() g.GroupStack.back().EmitItem = false; EndGroup(); // Restore position on layer 0 window->DC.LayoutType = ImGuiLayoutType_Vertical; + window->DC.IsSameLine = false; window->DC.NavLayerCurrent = ImGuiNavLayer_Main; window->DC.MenuBarAppending = false; } @@ -6890,14 +6981,19 @@ static bool IsRootOfOpenMenuSet() if ((g.OpenPopupStack.Size <= g.BeginPopupStack.Size) || (window->Flags & ImGuiWindowFlags_ChildMenu)) return false; - // Initially we used 'OpenParentId' to differentiate multiple menu sets from each others (e.g. inside menu bar vs loose menu items) based on parent ID. + // Initially we used 'upper_popup->OpenParentId == window->IDStack.back()' to differentiate multiple menu sets from each others + // (e.g. inside menu bar vs loose menu items) based on parent ID. // This would however prevent the use of e.g. PuhsID() user code submitting menus. // Previously this worked between popup and a first child menu because the first child menu always had the _ChildWindow flag, // making hovering on parent popup possible while first child menu was focused - but this was generally a bug with other side effects. // Instead we don't treat Popup specifically (in order to consistently support menu features in them), maybe the first child menu of a Popup - // doesn't have the _ChildWindow flag, and we rely on this IsRootOfOpenMenuSet() check to allow hovering between root window/popup and first chilld menu. + // doesn't have the _ChildWindow flag, and we rely on this IsRootOfOpenMenuSet() check to allow hovering between root window/popup and first child menu. + // In the end, lack of ID check made it so we could no longer differentiate between separate menu sets. To compensate for that, we at least check parent window nav layer. + // This fixes the most common case of menu opening on hover when moving between window content and menu bar. Multiple different menu sets in same nav layer would still + // open on hover, but that should be a lesser problem, because if such menus are close in proximity in window content then it won't feel weird and if they are far apart + // it likely won't be a problem anyone runs into. const ImGuiPopupData* upper_popup = &g.OpenPopupStack[g.BeginPopupStack.Size]; - return (/*upper_popup->OpenParentId == window->IDStack.back() &&*/ upper_popup->Window && (upper_popup->Window->Flags & ImGuiWindowFlags_ChildMenu)); + return (window->DC.NavLayerCurrent == upper_popup->ParentNavLayer && upper_popup->Window && (upper_popup->Window->Flags & ImGuiWindowFlags_ChildMenu)); } bool ImGui::BeginMenuEx(const char* label, const char* icon, bool enabled) @@ -6912,7 +7008,7 @@ bool ImGui::BeginMenuEx(const char* label, const char* icon, bool enabled) bool menu_is_open = IsPopupOpen(id, ImGuiPopupFlags_None); // Sub-menus are ChildWindow so that mouse can be hovering across them (otherwise top-most popup menu would steal focus and not allow hovering on parent menu) - // The first menu in a hierarchy isn't so hovering doesn't get accross (otherwise e.g. resizing borders with ImGuiButtonFlags_FlattenChildren would react), but top-most BeginMenu() will bypass that limitation. + // The first menu in a hierarchy isn't so hovering doesn't get across (otherwise e.g. resizing borders with ImGuiButtonFlags_FlattenChildren would react), but top-most BeginMenu() will bypass that limitation. ImGuiWindowFlags flags = ImGuiWindowFlags_ChildMenu | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoNavFocus; if (window->Flags & ImGuiWindowFlags_ChildMenu) flags |= ImGuiWindowFlags_ChildWindow; @@ -6949,6 +7045,7 @@ bool ImGui::BeginMenuEx(const char* label, const char* icon, bool enabled) BeginDisabled(); const ImGuiMenuColumns* offsets = &window->DC.MenuColumns; bool pressed; + const ImGuiSelectableFlags selectable_flags = ImGuiSelectableFlags_NoHoldingActiveID | ImGuiSelectableFlags_SelectOnClick | ImGuiSelectableFlags_DontClosePopups; if (window->DC.LayoutType == ImGuiLayoutType_Horizontal) { // Menu inside an horizontal menu bar @@ -6959,7 +7056,7 @@ bool ImGui::BeginMenuEx(const char* label, const char* icon, bool enabled) PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(style.ItemSpacing.x * 2.0f, style.ItemSpacing.y)); float w = label_size.x; ImVec2 text_pos(window->DC.CursorPos.x + offsets->OffsetLabel, window->DC.CursorPos.y + window->DC.CurrLineTextBaseOffset); - pressed = Selectable("", menu_is_open, ImGuiSelectableFlags_NoHoldingActiveID | ImGuiSelectableFlags_SelectOnClick | ImGuiSelectableFlags_DontClosePopups, ImVec2(w, 0.0f)); + pressed = Selectable("", menu_is_open, selectable_flags, ImVec2(w, 0.0f)); RenderText(text_pos, label); PopStyleVar(); window->DC.CursorPos.x += IM_FLOOR(style.ItemSpacing.x * (-1.0f + 0.5f)); // -1 spacing to compensate the spacing added when Selectable() did a SameLine(). It would also work to call SameLine() ourselves after the PopStyleVar(). @@ -6975,7 +7072,7 @@ bool ImGui::BeginMenuEx(const char* label, const char* icon, bool enabled) float min_w = window->DC.MenuColumns.DeclColumns(icon_w, label_size.x, 0.0f, checkmark_w); // Feedback to next frame float extra_w = ImMax(0.0f, GetContentRegionAvail().x - min_w); ImVec2 text_pos(window->DC.CursorPos.x + offsets->OffsetLabel, window->DC.CursorPos.y + window->DC.CurrLineTextBaseOffset); - pressed = Selectable("", menu_is_open, ImGuiSelectableFlags_NoHoldingActiveID | ImGuiSelectableFlags_SelectOnClick | ImGuiSelectableFlags_DontClosePopups | ImGuiSelectableFlags_SpanAvailWidth, ImVec2(min_w, 0.0f)); + pressed = Selectable("", menu_is_open, selectable_flags | ImGuiSelectableFlags_SpanAvailWidth, ImVec2(min_w, 0.0f)); RenderText(text_pos, label); if (icon_w > 0.0f) RenderText(pos + ImVec2(offsets->OffsetIcon, 0.0f), icon); @@ -6984,7 +7081,7 @@ bool ImGui::BeginMenuEx(const char* label, const char* icon, bool enabled) if (!enabled) EndDisabled(); - const bool hovered = (g.HoveredId == id) && enabled; + const bool hovered = (g.HoveredId == id) && enabled && !g.NavDisableMouseHover; if (menuset_is_open) g.NavWindow = backed_nav_window; @@ -6994,7 +7091,7 @@ bool ImGui::BeginMenuEx(const char* label, const char* icon, bool enabled) { // Close menu when not hovering it anymore unless we are moving roughly in the direction of the menu // Implement http://bjk5.com/post/44698559168/breaking-down-amazons-mega-dropdown to avoid using timers, so menus feels more reactive. - bool moving_toward_other_child_menu = false; + bool moving_toward_child_menu = false; ImGuiWindow* child_menu_window = (g.BeginPopupStack.Size < g.OpenPopupStack.Size && g.OpenPopupStack[g.BeginPopupStack.Size].SourceWindow == window) ? g.OpenPopupStack[g.BeginPopupStack.Size].Window : NULL; if (g.HoveredWindow == window && child_menu_window != NULL && !(window->Flags & ImGuiWindowFlags_MenuBar)) { @@ -7005,18 +7102,22 @@ bool ImGui::BeginMenuEx(const char* label, const char* icon, bool enabled) ImVec2 tc = (window->Pos.x < child_menu_window->Pos.x) ? next_window_rect.GetBL() : next_window_rect.GetBR(); float extra = ImClamp(ImFabs(ta.x - tb.x) * 0.30f, ref_unit * 0.5f, ref_unit * 2.5f); // add a bit of extra slack. ta.x += (window->Pos.x < child_menu_window->Pos.x) ? -0.5f : +0.5f; // to avoid numerical issues (FIXME: ??) - tb.y = ta.y + ImMax((tb.y - extra) - ta.y, -ref_unit * 8.0f); // triangle is maximum 200 high to limit the slope and the bias toward large sub-menus // FIXME: Multiply by fb_scale? + tb.y = ta.y + ImMax((tb.y - extra) - ta.y, -ref_unit * 8.0f); // triangle has maximum height to limit the slope and the bias toward large sub-menus tc.y = ta.y + ImMin((tc.y + extra) - ta.y, +ref_unit * 8.0f); - moving_toward_other_child_menu = ImTriangleContainsPoint(ta, tb, tc, g.IO.MousePos); + moving_toward_child_menu = ImTriangleContainsPoint(ta, tb, tc, g.IO.MousePos); //GetForegroundDrawList()->AddTriangleFilled(ta, tb, tc, moving_toward_other_child_menu ? IM_COL32(0,128,0,128) : IM_COL32(128,0,0,128)); // [DEBUG] } - if (menu_is_open && !hovered && g.HoveredWindow == window && g.HoveredIdPreviousFrame != 0 && g.HoveredIdPreviousFrame != id && !moving_toward_other_child_menu) + + // The 'HovereWindow == window' check creates an inconsistency (e.g. moving away from menu slowly tends to hit same window, whereas moving away fast does not) + // But we also need to not close the top-menu menu when moving over void. Perhaps we should extend the triangle check to a larger polygon. + // (Remember to test this on BeginPopup("A")->BeginMenu("B") sequence which behaves slightly differently as B isn't a Child of A and hovering isn't shared.) + if (menu_is_open && !hovered && g.HoveredWindow == window && !moving_toward_child_menu) want_close = true; // Open if (!menu_is_open && pressed) // Click/activate to open want_open = true; - else if (!menu_is_open && hovered && !moving_toward_other_child_menu) // Hover to open + else if (!menu_is_open && hovered && !moving_toward_child_menu) // Hover to open want_open = true; if (g.NavId == id && g.NavMoveDir == ImGuiDir_Right) // Nav-Right to open { @@ -7492,8 +7593,8 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) // Additionally, when using TabBarAddTab() to manipulate tab bar order we occasionally insert new tabs that don't have a width yet, // and we cannot wait for the next BeginTabItem() call. We cannot compute this width within TabBarAddTab() because font size depends on the active window. const char* tab_name = tab_bar->GetTabName(tab); - const bool has_close_button = (tab->Flags & ImGuiTabItemFlags_NoCloseButton) == 0; - tab->ContentWidth = TabItemCalcSize(tab_name, has_close_button).x; + const bool has_close_button = (tab->Flags & ImGuiTabItemFlags_NoCloseButton) ? false : true; + tab->ContentWidth = (tab->RequestedWidth > 0.0f) ? tab->RequestedWidth : TabItemCalcSize(tab_name, has_close_button).x; int section_n = TabItemGetSectionIdx(tab); ImGuiTabBarSection* section = §ions[section_n]; @@ -7502,9 +7603,9 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) // Store data so we can build an array sorted by width if we need to shrink tabs down IM_MSVC_WARNING_SUPPRESS(6385); - int shrink_buffer_index = shrink_buffer_indexes[section_n]++; - g.ShrinkWidthBuffer[shrink_buffer_index].Index = tab_n; - g.ShrinkWidthBuffer[shrink_buffer_index].Width = tab->ContentWidth; + ImGuiShrinkWidthItem* shrink_width_item = &g.ShrinkWidthBuffer[shrink_buffer_indexes[section_n]++]; + shrink_width_item->Index = tab_n; + shrink_width_item->Width = shrink_width_item->InitialWidth = tab->ContentWidth; IM_ASSERT(tab->ContentWidth > 0.0f); tab->Width = tab->ContentWidth; @@ -7594,7 +7695,7 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) // CTRL+TAB can override visible tab temporarily if (g.NavWindowingTarget != NULL && g.NavWindowingTarget->DockNode && g.NavWindowingTarget->DockNode->TabBar == tab_bar) - tab_bar->VisibleTabId = scroll_to_tab_id = g.NavWindowingTarget->ID; + tab_bar->VisibleTabId = scroll_to_tab_id = g.NavWindowingTarget->TabId; // Update scrolling if (scroll_to_tab_id != 0) @@ -7631,7 +7732,7 @@ static ImU32 ImGui::TabBarCalcTabID(ImGuiTabBar* tab_bar, const char* label, I { IM_UNUSED(tab_bar); IM_ASSERT(tab_bar->Flags & ImGuiTabBarFlags_DockNode); - ImGuiID id = ImHashStr(label); + ImGuiID id = docked_window->TabId; KeepAliveID(id); return id; } @@ -7676,14 +7777,14 @@ ImGuiTabItem* ImGui::TabBarFindMostRecentlySelectedTabForActiveWindow(ImGuiTabBa void ImGui::TabBarAddTab(ImGuiTabBar* tab_bar, ImGuiTabItemFlags tab_flags, ImGuiWindow* window) { ImGuiContext& g = *GImGui; - IM_ASSERT(TabBarFindTabByID(tab_bar, window->ID) == NULL); + IM_ASSERT(TabBarFindTabByID(tab_bar, window->TabId) == NULL); IM_ASSERT(g.CurrentTabBar != tab_bar); // Can't work while the tab bar is active as our tab doesn't have an X offset yet, in theory we could/should test something like (tab_bar->CurrFrameVisible < g.FrameCount) but we'd need to solve why triggers the commented early-out assert in BeginTabBarEx() (probably dock node going from implicit to explicit in same frame) if (!window->HasCloseButton) tab_flags |= ImGuiTabItemFlags_NoCloseButton; // Set _NoCloseButton immediately because it will be used for first-frame width calculation. ImGuiTabItem new_tab; - new_tab.ID = window->ID; + new_tab.ID = window->TabId; new_tab.Flags = tab_flags; new_tab.LastFrameVisible = tab_bar->CurrFrameVisible; // Required so BeginTabBar() doesn't ditch the tab if (new_tab.LastFrameVisible == -1) @@ -7705,7 +7806,9 @@ void ImGui::TabBarRemoveTab(ImGuiTabBar* tab_bar, ImGuiID tab_id) // Called on manual closure attempt void ImGui::TabBarCloseTab(ImGuiTabBar* tab_bar, ImGuiTabItem* tab) { - IM_ASSERT(!(tab->Flags & ImGuiTabItemFlags_Button)); + if (tab->Flags & ImGuiTabItemFlags_Button) + return; // A button appended with TabItemButton(). + if (!(tab->Flags & ImGuiTabItemFlags_UnsavedDocument)) { // This will remove a frame of lag for selecting another tab on closure. @@ -8015,10 +8118,13 @@ bool ImGui::TabItemButton(const char* label, ImGuiTabItemFlags flags) bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, ImGuiTabItemFlags flags, ImGuiWindow* docked_window) { // Layout whole tab bar if not already done - if (tab_bar->WantLayout) - TabBarLayout(tab_bar); - ImGuiContext& g = *GImGui; + if (tab_bar->WantLayout) + { + ImGuiNextItemData backup_next_item_data = g.NextItemData; + TabBarLayout(tab_bar); + g.NextItemData = backup_next_item_data; + } ImGuiWindow* window = g.CurrentWindow; if (window->SkipItems) return false; @@ -8044,9 +8150,6 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, else if (p_open == NULL) flags |= ImGuiTabItemFlags_NoCloseButton; - // Calculate tab contents size - ImVec2 size = TabItemCalcSize(label, p_open != NULL); - // Acquire tab data ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, id); bool tab_is_new = false; @@ -8055,11 +8158,17 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, tab_bar->Tabs.push_back(ImGuiTabItem()); tab = &tab_bar->Tabs.back(); tab->ID = id; - tab->Width = size.x; - tab_bar->TabsAddedNew = true; - tab_is_new = true; + tab_bar->TabsAddedNew = tab_is_new = true; } tab_bar->LastTabItemIdx = (ImS16)tab_bar->Tabs.index_from_ptr(tab); + + // Calculate tab contents size + ImVec2 size = TabItemCalcSize(label, p_open != NULL); + tab->RequestedWidth = -1.0f; + if (g.NextItemData.Flags & ImGuiNextItemDataFlags_HasWidth) + size.x = tab->RequestedWidth = g.NextItemData.Width; + if (tab_is_new) + tab->Width = size.x; tab->ContentWidth = size.x; tab->BeginOrder = tab_bar->TabsActiveCount++; @@ -8086,13 +8195,14 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, } // Update selected tab - if (tab_appearing && (tab_bar->Flags & ImGuiTabBarFlags_AutoSelectNewTabs) && tab_bar->NextSelectedTabId == 0) - if (!tab_bar_appearing || tab_bar->SelectedTabId == 0) - if (!is_tab_button) + if (!is_tab_button) + { + if (tab_appearing && (tab_bar->Flags & ImGuiTabBarFlags_AutoSelectNewTabs) && tab_bar->NextSelectedTabId == 0) + if (!tab_bar_appearing || tab_bar->SelectedTabId == 0) tab_bar->NextSelectedTabId = id; // New tabs gets activated - if ((flags & ImGuiTabItemFlags_SetSelected) && (tab_bar->SelectedTabId != id)) // SetSelected can only be passed on explicit tab bar - if (!is_tab_button) + if ((flags & ImGuiTabItemFlags_SetSelected) && (tab_bar->SelectedTabId != id)) // _SetSelected can only be passed on explicit tab bar tab_bar->NextSelectedTabId = id; + } // Lock visibility // (Note: tab_contents_visible != tab_selected... because CTRL+TAB operations may preview some tabs without selecting them!) @@ -8256,7 +8366,7 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, flags |= ImGuiTabItemFlags_NoCloseWithMiddleMouseButton; // Render tab label, process close button - const ImGuiID close_button_id = p_open ? GetIDWithSeed("#CLOSE", NULL, id) : 0; + const ImGuiID close_button_id = p_open ? GetIDWithSeed("#CLOSE", NULL, docked_window ? docked_window->ID : id) : 0; bool just_closed; bool text_clipped; TabItemLabelAndCloseButton(display_draw_list, bb, flags, tab_bar->FramePadding, label, id, close_button_id, tab_contents_visible, &just_closed, &text_clipped); diff --git a/lib/external/imgui/source/imnodes.cpp b/lib/external/imgui/source/imnodes.cpp index 9692de088..7689cb10b 100644 --- a/lib/external/imgui/source/imnodes.cpp +++ b/lib/external/imgui/source/imnodes.cpp @@ -9,7 +9,6 @@ #include "imnodes.h" #include "imnodes_internal.h" -#include #define IMGUI_DEFINE_MATH_OPERATORS #include @@ -19,7 +18,6 @@ #error "Minimum ImGui version requirement not met -- please use a newer version!" #endif -#include #include #include #include @@ -28,9 +26,14 @@ #include #include // strlen, strncmp +// Use secure CRT function variants to avoid MSVC compiler errors +#ifdef _MSC_VER +#define sscanf sscanf_s +#endif + ImNodesContext* GImNodes = NULL; -namespace ImNodes +namespace IMNODES_NAMESPACE { namespace { @@ -116,7 +119,7 @@ inline CubicBezier GetCubicBezier( const ImNodesAttributeType start_type, const float line_segments_per_length) { - assert( + IM_ASSERT( (start_type == ImNodesAttributeType_Input) || (start_type == ImNodesAttributeType_Output)); if (start_type == ImNodesAttributeType_Input) { @@ -252,6 +255,57 @@ inline bool RectangleOverlapsLink( return false; } +// [SECTION] coordinate space conversion helpers + +inline ImVec2 ScreenSpaceToGridSpace(const ImNodesEditorContext& editor, const ImVec2& v) +{ + return v - GImNodes->CanvasOriginScreenSpace - editor.Panning; +} + +inline ImRect ScreenSpaceToGridSpace(const ImNodesEditorContext& editor, const ImRect& r) +{ + return ImRect(ScreenSpaceToGridSpace(editor, r.Min), ScreenSpaceToGridSpace(editor, r.Max)); +} + +inline ImVec2 GridSpaceToScreenSpace(const ImNodesEditorContext& editor, const ImVec2& v) +{ + return v + GImNodes->CanvasOriginScreenSpace + editor.Panning; +} + +inline ImVec2 GridSpaceToEditorSpace(const ImNodesEditorContext& editor, const ImVec2& v) +{ + return v + editor.Panning; +} + +inline ImVec2 EditorSpaceToGridSpace(const ImNodesEditorContext& editor, const ImVec2& v) +{ + return v - editor.Panning; +} + +inline ImVec2 EditorSpaceToScreenSpace(const ImVec2& v) +{ + return GImNodes->CanvasOriginScreenSpace + v; +} + +inline ImVec2 MiniMapSpaceToGridSpace(const ImNodesEditorContext& editor, const ImVec2& v) +{ + return (v - editor.MiniMapContentScreenSpace.Min) / editor.MiniMapScaling + + editor.GridContentBounds.Min; +} + +inline ImVec2 ScreenSpaceToMiniMapSpace(const ImNodesEditorContext& editor, const ImVec2& v) +{ + return (ScreenSpaceToGridSpace(editor, v) - editor.GridContentBounds.Min) * + editor.MiniMapScaling + + editor.MiniMapContentScreenSpace.Min; +} + +inline ImRect ScreenSpaceToMiniMapSpace(const ImNodesEditorContext& editor, const ImRect& r) +{ + return ImRect( + ScreenSpaceToMiniMapSpace(editor, r.Min), ScreenSpaceToMiniMapSpace(editor, r.Max)); +} + // [SECTION] draw list helper void ImDrawListGrowChannels(ImDrawList* draw_list, const int num_channels) @@ -316,8 +370,8 @@ void ImDrawListSplitterSwapChannels( return; } - assert(lhs_idx >= 0 && lhs_idx < splitter._Count); - assert(rhs_idx >= 0 && rhs_idx < splitter._Count); + IM_ASSERT(lhs_idx >= 0 && lhs_idx < splitter._Count); + IM_ASSERT(rhs_idx >= 0 && rhs_idx < splitter._Count); ImDrawChannel& lhs_channel = splitter._Channels[lhs_idx]; ImDrawChannel& rhs_channel = splitter._Channels[rhs_idx]; @@ -413,7 +467,7 @@ void DrawListActivateNodeBackground(const int node_idx) // * SetNodeGridSpacePos // * SetNodeDraggable // after the BeginNode/EndNode function calls? - assert(submission_idx != -1); + IM_ASSERT(submission_idx != -1); const int background_channel_idx = DrawListSubmissionIdxToBackgroundChannelIdx(submission_idx); GImNodes->CanvasDrawList->_Splitter.SetCurrentChannel( GImNodes->CanvasDrawList, background_channel_idx); @@ -421,7 +475,7 @@ void DrawListActivateNodeBackground(const int node_idx) void DrawListSwapSubmissionIndices(const int lhs_idx, const int rhs_idx) { - assert(lhs_idx != rhs_idx); + IM_ASSERT(lhs_idx != rhs_idx); const int lhs_foreground_channel_idx = DrawListSubmissionIdxToForegroundChannelIdx(lhs_idx); const int lhs_background_channel_idx = DrawListSubmissionIdxToBackgroundChannelIdx(lhs_idx); @@ -445,7 +499,7 @@ void DrawListSortChannelsByDepth(const ImVector& node_idx_depth_order) return; } - assert(node_idx_depth_order.Size == GImNodes->NodeIdxSubmissionOrder.Size); + IM_ASSERT(node_idx_depth_order.Size == GImNodes->NodeIdxSubmissionOrder.Size); int start_idx = node_idx_depth_order.Size - 1; @@ -475,7 +529,7 @@ void DrawListSortChannelsByDepth(const ImVector& node_idx_depth_order) break; } } - assert(submission_idx >= 0); + IM_ASSERT(submission_idx >= 0); if (submission_idx == depth_idx) { @@ -497,7 +551,7 @@ ImVec2 GetScreenSpacePinCoordinates( const ImRect& attribute_rect, const ImNodesAttributeType type) { - assert(type == ImNodesAttributeType_Input || type == ImNodesAttributeType_Output); + IM_ASSERT(type == ImNodesAttributeType_Input || type == ImNodesAttributeType_Output); const float x = type == ImNodesAttributeType_Input ? (node_rect.Min.x - GImNodes->Style.PinOffset) : (node_rect.Max.x + GImNodes->Style.PinOffset); @@ -533,21 +587,50 @@ void BeginNodeSelection(ImNodesEditorContext& editor, const int node_idx) // If the node is not already contained in the selection, then we want only // the interaction node to be selected, effective immediately. // + // If the multiple selection modifier is active, we want to add this node + // to the current list of selected nodes. + // // Otherwise, we want to allow for the possibility of multiple nodes to be // moved at once. if (!editor.SelectedNodeIndices.contains(node_idx)) { - editor.SelectedNodeIndices.clear(); editor.SelectedLinkIndices.clear(); + if (!GImNodes->MultipleSelectModifier) + { + editor.SelectedNodeIndices.clear(); + } editor.SelectedNodeIndices.push_back(node_idx); // Ensure that individually selected nodes get rendered on top ImVector& depth_stack = editor.NodeDepthOrder; const int* const elem = depth_stack.find(node_idx); - assert(elem != depth_stack.end()); + IM_ASSERT(elem != depth_stack.end()); depth_stack.erase(elem); depth_stack.push_back(node_idx); } + // Deselect a previously-selected node + else if (GImNodes->MultipleSelectModifier) + { + const int* const node_ptr = editor.SelectedNodeIndices.find(node_idx); + editor.SelectedNodeIndices.erase(node_ptr); + + // Don't allow dragging after deselecting + editor.ClickInteraction.Type = ImNodesClickInteractionType_None; + } + + // To support snapping of multiple nodes, we need to store the offset of + // each node in the selection to the origin of the dragged node. + const ImVec2 ref_origin = editor.Nodes.Pool[node_idx].Origin; + editor.PrimaryNodeOffset = + ref_origin + GImNodes->CanvasOriginScreenSpace + editor.Panning - GImNodes->MousePos; + + editor.SelectedNodeOffsets.clear(); + for (int idx = 0; idx < editor.SelectedNodeIndices.Size; idx++) + { + const int node = editor.SelectedNodeIndices[idx]; + const ImVec2 node_origin = editor.Nodes.Pool[node].Origin - ref_origin; + editor.SelectedNodeOffsets.push_back(node_origin); + } } void BeginLinkSelection(ImNodesEditorContext& editor, const int link_idx) @@ -571,46 +654,6 @@ void BeginLinkDetach(ImNodesEditorContext& editor, const int link_idx, const int GImNodes->DeletedLinkIdx = link_idx; } -void BeginLinkInteraction(ImNodesEditorContext& editor, const int link_idx) -{ - // Check the 'click and drag to detach' case. - if (GImNodes->HoveredPinIdx.HasValue() && - (editor.Pins.Pool[GImNodes->HoveredPinIdx.Value()].Flags & - ImNodesAttributeFlags_EnableLinkDetachWithDragClick) != 0) - { - BeginLinkDetach(editor, link_idx, GImNodes->HoveredPinIdx.Value()); - editor.ClickInteraction.LinkCreation.Type = ImNodesLinkCreationType_FromDetach; - } - // If we aren't near a pin, check if we are clicking the link with the - // modifier pressed. This may also result in a link detach via clicking. - else - { - const bool modifier_pressed = GImNodes->Io.LinkDetachWithModifierClick.Modifier == NULL - ? false - : *GImNodes->Io.LinkDetachWithModifierClick.Modifier; - - if (modifier_pressed) - { - const ImLinkData& link = editor.Links.Pool[link_idx]; - const ImPinData& start_pin = editor.Pins.Pool[link.StartPinIdx]; - const ImPinData& end_pin = editor.Pins.Pool[link.EndPinIdx]; - const ImVec2& mouse_pos = GImNodes->MousePos; - const float dist_to_start = ImLengthSqr(start_pin.Pos - mouse_pos); - const float dist_to_end = ImLengthSqr(end_pin.Pos - mouse_pos); - const int closest_pin_idx = - dist_to_start < dist_to_end ? link.StartPinIdx : link.EndPinIdx; - - editor.ClickInteraction.Type = ImNodesClickInteractionType_LinkCreation; - BeginLinkDetach(editor, link_idx, closest_pin_idx); - editor.ClickInteraction.LinkCreation.Type = ImNodesLinkCreationType_FromDetach; - } - else - { - BeginLinkSelection(editor, link_idx); - } - } -} - void BeginLinkCreation(ImNodesEditorContext& editor, const int hovered_pin_idx) { editor.ClickInteraction.Type = ImNodesClickInteractionType_LinkCreation; @@ -620,6 +663,56 @@ void BeginLinkCreation(ImNodesEditorContext& editor, const int hovered_pin_idx) GImNodes->ImNodesUIState |= ImNodesUIState_LinkStarted; } +void BeginLinkInteraction( + ImNodesEditorContext& editor, + const int link_idx, + const ImOptionalIndex pin_idx = ImOptionalIndex()) +{ + // Check if we are clicking the link with the modifier pressed. + // This will in a link detach via clicking. + + const bool modifier_pressed = GImNodes->Io.LinkDetachWithModifierClick.Modifier == NULL + ? false + : *GImNodes->Io.LinkDetachWithModifierClick.Modifier; + + if (modifier_pressed) + { + const ImLinkData& link = editor.Links.Pool[link_idx]; + const ImPinData& start_pin = editor.Pins.Pool[link.StartPinIdx]; + const ImPinData& end_pin = editor.Pins.Pool[link.EndPinIdx]; + const ImVec2& mouse_pos = GImNodes->MousePos; + const float dist_to_start = ImLengthSqr(start_pin.Pos - mouse_pos); + const float dist_to_end = ImLengthSqr(end_pin.Pos - mouse_pos); + const int closest_pin_idx = dist_to_start < dist_to_end ? link.StartPinIdx : link.EndPinIdx; + + editor.ClickInteraction.Type = ImNodesClickInteractionType_LinkCreation; + BeginLinkDetach(editor, link_idx, closest_pin_idx); + editor.ClickInteraction.LinkCreation.Type = ImNodesLinkCreationType_FromDetach; + } + else + { + if (pin_idx.HasValue()) + { + const int hovered_pin_flags = editor.Pins.Pool[pin_idx.Value()].Flags; + + // Check the 'click and drag to detach' case. + if (hovered_pin_flags & ImNodesAttributeFlags_EnableLinkDetachWithDragClick) + { + BeginLinkDetach(editor, link_idx, pin_idx.Value()); + editor.ClickInteraction.LinkCreation.Type = ImNodesLinkCreationType_FromDetach; + } + else + { + BeginLinkCreation(editor, pin_idx.Value()); + } + } + else + { + BeginLinkSelection(editor, link_idx); + } + } +} + static inline bool IsMiniMapHovered(); void BeginCanvasInteraction(ImNodesEditorContext& editor) @@ -638,34 +731,15 @@ void BeginCanvasInteraction(ImNodesEditorContext& editor) const bool started_panning = GImNodes->AltMouseClicked; - // Handle mini-map interactions - if (IsMiniMapHovered()) + if (started_panning) { - if (started_panning) - { - editor.ClickInteraction.Type = ImNodesClickInteractionType_MiniMapPanning; - } - else if (GImNodes->LeftMouseReleased) - { - editor.ClickInteraction.Type = ImNodesClickInteractionType_MiniMapSnapping; - } - else if (GImNodes->AltMouseScrollDelta != 0.f) - { - editor.ClickInteraction.Type = ImNodesClickInteractionType_MiniMapZooming; - } + editor.ClickInteraction.Type = ImNodesClickInteractionType_Panning; } - // Handle normal editor interactions - else + else if (GImNodes->LeftMouseClicked) { - if (started_panning) - { - editor.ClickInteraction.Type = ImNodesClickInteractionType_Panning; - } - else if (GImNodes->LeftMouseClicked) - { - editor.ClickInteraction.Type = ImNodesClickInteractionType_BoxSelection; - editor.ClickInteraction.BoxSelector.Rect.Min = GImNodes->MousePos; - } + editor.ClickInteraction.Type = ImNodesClickInteractionType_BoxSelection; + editor.ClickInteraction.BoxSelector.Rect.Min = + ScreenSpaceToGridSpace(editor, GImNodes->MousePos); } } @@ -732,18 +806,44 @@ void BoxSelectorUpdateSelection(ImNodesEditorContext& editor, ImRect box_rect) } } +ImVec2 SnapOriginToGrid(ImVec2 origin) +{ + if (GImNodes->Style.Flags & ImNodesStyleFlags_GridSnapping) + { + const float spacing = GImNodes->Style.GridSpacing; + const float spacing2 = spacing * 0.5f; + + // Snap the origin to the nearest grid point in any direction + float modx = fmodf(fabsf(origin.x) + spacing2, spacing) - spacing2; + float mody = fmodf(fabsf(origin.y) + spacing2, spacing) - spacing2; + origin.x += (origin.x < 0.f) ? modx : -modx; + origin.y += (origin.y < 0.f) ? mody : -mody; + } + + return origin; +} + void TranslateSelectedNodes(ImNodesEditorContext& editor) { if (GImNodes->LeftMouseDragging) { - const ImGuiIO& io = ImGui::GetIO(); + // If we have grid snap enabled, don't start moving nodes until we've moved the mouse + // slightly + const bool shouldTranslate = (GImNodes->Style.Flags & ImNodesStyleFlags_GridSnapping) + ? ImGui::GetIO().MouseDragMaxDistanceSqr[0] > 5.0 + : true; + + const ImVec2 origin = SnapOriginToGrid( + GImNodes->MousePos - GImNodes->CanvasOriginScreenSpace - editor.Panning + + editor.PrimaryNodeOffset); for (int i = 0; i < editor.SelectedNodeIndices.size(); ++i) { - const int node_idx = editor.SelectedNodeIndices[i]; - ImNodeData& node = editor.Nodes.Pool[node_idx]; - if (node.Draggable) + const ImVec2 node_rel = editor.SelectedNodeOffsets[i]; + const int node_idx = editor.SelectedNodeIndices[i]; + ImNodeData& node = editor.Nodes.Pool[node_idx]; + if (node.Draggable && shouldTranslate) { - node.Origin += io.MouseDelta; + node.Origin = origin + node_rel + editor.AutoPanningDelta; } } } @@ -835,8 +935,12 @@ void ClickInteractionUpdate(ImNodesEditorContext& editor) { case ImNodesClickInteractionType_BoxSelection: { - ImRect& box_rect = editor.ClickInteraction.BoxSelector.Rect; - box_rect.Max = GImNodes->MousePos; + editor.ClickInteraction.BoxSelector.Rect.Max = + ScreenSpaceToGridSpace(editor, GImNodes->MousePos); + + ImRect box_rect = editor.ClickInteraction.BoxSelector.Rect; + box_rect.Min = GridSpaceToScreenSpace(editor, box_rect.Min); + box_rect.Max = GridSpaceToScreenSpace(editor, box_rect.Max); BoxSelectorUpdateSelection(editor, box_rect); @@ -1003,39 +1107,6 @@ void ClickInteractionUpdate(ImNodesEditorContext& editor) } } break; - case ImNodesClickInteractionType_MiniMapPanning: - { - const bool dragging = GImNodes->AltMouseDragging; - - if (dragging) - { - editor.Panning += ImGui::GetIO().MouseDelta / GImNodes->MiniMapZoom; - } - else - { - editor.ClickInteraction.Type = ImNodesClickInteractionType_None; - } - } - break; - case ImNodesClickInteractionType_MiniMapZooming: - { - GImNodes->MiniMapZoom = fmaxf( - 0.05f, - fminf( - GImNodes->MiniMapZoom + - 0.1f * GImNodes->MiniMapZoom * GImNodes->AltMouseScrollDelta, - 1.f)); - editor.ClickInteraction.Type = ImNodesClickInteractionType_None; - } - break; - case ImNodesClickInteractionType_MiniMapSnapping: - { - editor.Panning += GImNodes->MiniMapRectSnappingOffset; - GImNodes->MiniMapRectSnappingOffset = ImVec2(0.f, 0.f); - - editor.ClickInteraction.Type = ImNodesClickInteractionType_None; - } - break; case ImNodesClickInteractionType_ImGuiItem: { if (GImNodes->LeftMouseReleased) @@ -1046,7 +1117,7 @@ void ClickInteractionUpdate(ImNodesEditorContext& editor) case ImNodesClickInteractionType_None: break; default: - assert(!"Unreachable code!"); + IM_ASSERT(!"Unreachable code!"); break; } } @@ -1154,7 +1225,7 @@ ImOptionalIndex ResolveHoveredNode(const ImVector& depth_stack) } } - assert(node_idx_on_top != -1); + IM_ASSERT(node_idx_on_top != -1); return ImOptionalIndex(node_idx_on_top); } @@ -1184,10 +1255,15 @@ ImOptionalIndex ResolveHoveredLink( const ImPinData& start_pin = pins.Pool[link.StartPinIdx]; const ImPinData& end_pin = pins.Pool[link.EndPinIdx]; - if (GImNodes->HoveredPinIdx == link.StartPinIdx || - GImNodes->HoveredPinIdx == link.EndPinIdx) + // If there is a hovered pin links can only be considered hovered if they use that pin + if (GImNodes->HoveredPinIdx.HasValue()) { - return idx; + if (GImNodes->HoveredPinIdx == link.StartPinIdx || + GImNodes->HoveredPinIdx == link.EndPinIdx) + { + return idx; + } + continue; } // TODO: the calculated CubicBeziers could be cached since we generate them again when @@ -1225,31 +1301,6 @@ ImOptionalIndex ResolveHoveredLink( // [SECTION] render helpers -inline ImVec2 ScreenSpaceToGridSpace(const ImNodesEditorContext& editor, const ImVec2& v) -{ - return v - GImNodes->CanvasOriginScreenSpace - editor.Panning; -} - -inline ImVec2 GridSpaceToScreenSpace(const ImNodesEditorContext& editor, const ImVec2& v) -{ - return v + GImNodes->CanvasOriginScreenSpace + editor.Panning; -} - -inline ImVec2 GridSpaceToEditorSpace(const ImNodesEditorContext& editor, const ImVec2& v) -{ - return v + editor.Panning; -} - -inline ImVec2 EditorSpaceToGridSpace(const ImNodesEditorContext& editor, const ImVec2& v) -{ - return v - editor.Panning; -} - -inline ImVec2 EditorSpaceToScreenSpace(const ImVec2& v) -{ - return GImNodes->CanvasOriginScreenSpace + v; -} - inline ImRect GetItemRect() { return ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax()); } inline ImVec2 GetNodeTitleBarOrigin(const ImNodeData& node) @@ -1278,6 +1329,9 @@ inline ImRect GetNodeTitleRect(const ImNodeData& node) void DrawGrid(ImNodesEditorContext& editor, const ImVec2& canvas_size) { const ImVec2 offset = editor.Panning; + ImU32 line_color = GImNodes->Style.Colors[ImNodesCol_GridLine]; + ImU32 line_color_prim = GImNodes->Style.Colors[ImNodesCol_GridLinePrimary]; + bool draw_primary = GImNodes->Style.Flags & ImNodesStyleFlags_GridLinesPrimary; for (float x = fmodf(offset.x, GImNodes->Style.GridSpacing); x < canvas_size.x; x += GImNodes->Style.GridSpacing) @@ -1285,7 +1339,7 @@ void DrawGrid(ImNodesEditorContext& editor, const ImVec2& canvas_size) GImNodes->CanvasDrawList->AddLine( EditorSpaceToScreenSpace(ImVec2(x, 0.0f)), EditorSpaceToScreenSpace(ImVec2(x, canvas_size.y)), - GImNodes->Style.Colors[ImNodesCol_GridLine]); + offset.x - x == 0.f && draw_primary ? line_color_prim : line_color); } for (float y = fmodf(offset.y, GImNodes->Style.GridSpacing); y < canvas_size.y; @@ -1294,7 +1348,7 @@ void DrawGrid(ImNodesEditorContext& editor, const ImVec2& canvas_size) GImNodes->CanvasDrawList->AddLine( EditorSpaceToScreenSpace(ImVec2(0.0f, y)), EditorSpaceToScreenSpace(ImVec2(canvas_size.x, y)), - GImNodes->Style.Colors[ImNodesCol_GridLine]); + offset.y - y == 0.f && draw_primary ? line_color_prim : line_color); } } @@ -1419,7 +1473,7 @@ void DrawPinShape(const ImVec2& pin_pos, const ImPinData& pin, const ImU32 pin_c } break; default: - assert(!"Invalid PinShape value!"); + IM_ASSERT(!"Invalid PinShape value!"); break; } } @@ -1585,7 +1639,7 @@ void BeginPinAttribute( { // Make sure to call BeginNode() before calling // BeginAttribute() - assert(GImNodes->CurrentScope == ImNodesScope_Node); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_Node); GImNodes->CurrentScope = ImNodesScope_Attribute; ImGui::BeginGroup(); @@ -1609,7 +1663,7 @@ void BeginPinAttribute( void EndPinAttribute() { - assert(GImNodes->CurrentScope == ImNodesScope_Attribute); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_Attribute); GImNodes->CurrentScope = ImNodesScope_Node; ImGui::PopID(); @@ -1634,121 +1688,120 @@ void Initialize(ImNodesContext* context) context->CanvasRectScreenSpace = ImRect(ImVec2(0.f, 0.f), ImVec2(0.f, 0.f)); context->CurrentScope = ImNodesScope_None; - context->MiniMapRectScreenSpace = ImRect(ImVec2(0.f, 0.f), ImVec2(0.f, 0.f)); - context->MiniMapRectSnappingOffset = ImVec2(0.f, 0.f); - context->MiniMapZoom = 0.1f; - context->MiniMapNodeHoveringCallback = NULL; - context->MiniMapNodeHoveringCallbackUserData = NULL; - context->CurrentPinIdx = INT_MAX; context->CurrentNodeIdx = INT_MAX; context->DefaultEditorCtx = EditorContextCreate(); - EditorContextSet(GImNodes->DefaultEditorCtx); + context->EditorCtx = context->DefaultEditorCtx; context->CurrentAttributeFlags = ImNodesAttributeFlags_None; context->AttributeFlagStack.push_back(GImNodes->CurrentAttributeFlags); - StyleColorsDark(); + StyleColorsDark(&context->Style); } void Shutdown(ImNodesContext* ctx) { EditorContextFree(ctx->DefaultEditorCtx); } // [SECTION] minimap -static inline bool IsMiniMapActive() { return GImNodes->MiniMapRectScreenSpace.GetWidth() > 0.f; } +static inline bool IsMiniMapActive() +{ + ImNodesEditorContext& editor = EditorContextGet(); + return editor.MiniMapEnabled && editor.MiniMapSizeFraction > 0.0f; +} static inline bool IsMiniMapHovered() { + ImNodesEditorContext& editor = EditorContextGet(); return IsMiniMapActive() && ImGui::IsMouseHoveringRect( - GImNodes->MiniMapRectScreenSpace.Min, GImNodes->MiniMapRectScreenSpace.Max); + editor.MiniMapRectScreenSpace.Min, editor.MiniMapRectScreenSpace.Max); } -static inline ImRect ToMiniMapRect( - const float minimap_size_fraction, - const ImRect& editor_rect, - const ImNodesMiniMapLocation location) +static inline void CalcMiniMapLayout() { - const ImVec2 editor_size(editor_rect.Max - editor_rect.Min); - const float max_editor_coord = fmaxf(editor_size.x, editor_size.y); - const float mini_map_coord = minimap_size_fraction * max_editor_coord; - const float corner_offset_alpha = fminf(1.f - minimap_size_fraction, 0.1f); - const float corner_offset_coord = corner_offset_alpha * mini_map_coord; + ImNodesEditorContext& editor = EditorContextGet(); + const ImVec2 offset = GImNodes->Style.MiniMapOffset; + const ImVec2 border = GImNodes->Style.MiniMapPadding; + const ImRect editor_rect = GImNodes->CanvasRectScreenSpace; - // Compute the size of the mini-map area; lower bound with some reasonable size values - const ImVec2 mini_map_size(mini_map_coord, mini_map_coord); - - // Corner offset from editor context - const ImVec2 corner_offset(corner_offset_coord, corner_offset_coord); - - switch (location) + // Compute the size of the mini-map area + ImVec2 mini_map_size; + float mini_map_scaling; { - case ImNodesMiniMapLocation_BottomRight: - return ImRect( - editor_rect.Max - corner_offset - mini_map_size, editor_rect.Max - corner_offset); - case ImNodesMiniMapLocation_BottomLeft: - return ImRect( - ImVec2( - editor_rect.Min.x + corner_offset.x, - editor_rect.Max.y - corner_offset.y - mini_map_size.y), - ImVec2( - editor_rect.Min.x + corner_offset.x + mini_map_size.x, - editor_rect.Max.y - corner_offset.y)); - case ImNodesMiniMapLocation_TopRight: - return ImRect( - ImVec2( - editor_rect.Max.x - corner_offset.x - mini_map_size.x, - editor_rect.Min.y + corner_offset.y), - ImVec2( - editor_rect.Max.x - corner_offset.x, - editor_rect.Min.y + corner_offset.y + mini_map_size.y)); - case ImNodesMiniMapLocation_TopLeft: - // [[fallthrough]] - default: - // [[fallthrough]] - break; + const ImVec2 max_size = + ImFloor(editor_rect.GetSize() * editor.MiniMapSizeFraction - border * 2.0f); + const float max_size_aspect_ratio = max_size.x / max_size.y; + const ImVec2 grid_content_size = editor.GridContentBounds.IsInverted() + ? max_size + : ImFloor(editor.GridContentBounds.GetSize()); + const float grid_content_aspect_ratio = grid_content_size.x / grid_content_size.y; + mini_map_size = ImFloor( + grid_content_aspect_ratio > max_size_aspect_ratio + ? ImVec2(max_size.x, max_size.x / grid_content_aspect_ratio) + : ImVec2(max_size.y * grid_content_aspect_ratio, max_size.y)); + mini_map_scaling = mini_map_size.x / grid_content_size.x; } - return ImRect(editor_rect.Min + corner_offset, editor_rect.Min + corner_offset + mini_map_size); + + // Compute location of the mini-map + ImVec2 mini_map_pos; + { + ImVec2 align; + + switch (editor.MiniMapLocation) + { + case ImNodesMiniMapLocation_BottomRight: + align.x = 1.0f; + align.y = 1.0f; + break; + case ImNodesMiniMapLocation_BottomLeft: + align.x = 0.0f; + align.y = 1.0f; + break; + case ImNodesMiniMapLocation_TopRight: + align.x = 1.0f; + align.y = 0.0f; + break; + case ImNodesMiniMapLocation_TopLeft: // [[fallthrough]] + default: + align.x = 0.0f; + align.y = 0.0f; + break; + } + + const ImVec2 top_left_pos = editor_rect.Min + offset + border; + const ImVec2 bottom_right_pos = editor_rect.Max - offset - border - mini_map_size; + mini_map_pos = ImFloor(ImLerp(top_left_pos, bottom_right_pos, align)); + } + + editor.MiniMapRectScreenSpace = + ImRect(mini_map_pos - border, mini_map_pos + mini_map_size + border); + editor.MiniMapContentScreenSpace = ImRect(mini_map_pos, mini_map_pos + mini_map_size); + editor.MiniMapScaling = mini_map_scaling; } -static void MiniMapDrawNode( - ImNodesEditorContext& editor, - const int node_idx, - const ImVec2& editor_center, - const ImVec2& mini_map_center, - const float scaling) +static void MiniMapDrawNode(ImNodesEditorContext& editor, const int node_idx) { const ImNodeData& node = editor.Nodes.Pool[node_idx]; - const ImVec2 editor_node_offset(node.Rect.Min - editor_center); - - const ImVec2 mini_map_node_size((node.Rect.Max - node.Rect.Min) * scaling); - - const ImVec2 mini_map_node_min(editor_node_offset * scaling + mini_map_center); - - const ImVec2 mini_map_node_max(mini_map_node_min + mini_map_node_size); + const ImRect node_rect = ScreenSpaceToMiniMapSpace(editor, node.Rect); // Round to near whole pixel value for corner-rounding to prevent visual glitches - const float mini_map_node_rounding = floorf(node.LayoutStyle.CornerRounding * scaling); + const float mini_map_node_rounding = + floorf(node.LayoutStyle.CornerRounding * editor.MiniMapScaling); ImU32 mini_map_node_background; if (editor.ClickInteraction.Type == ImNodesClickInteractionType_None && - ImGui::IsMouseHoveringRect(mini_map_node_min, mini_map_node_max)) + ImGui::IsMouseHoveringRect(node_rect.Min, node_rect.Max)) { mini_map_node_background = GImNodes->Style.Colors[ImNodesCol_MiniMapNodeBackgroundHovered]; // Run user callback when hovering a mini-map node - if (GImNodes->MiniMapNodeHoveringCallback) + if (editor.MiniMapNodeHoveringCallback) { - GImNodes->MiniMapNodeHoveringCallback( - node.Id, GImNodes->MiniMapNodeHoveringCallbackUserData); + editor.MiniMapNodeHoveringCallback(node.Id, editor.MiniMapNodeHoveringCallbackUserData); } - - // Compute the amount to pan editor to center node selected in the minimap - GImNodes->MiniMapRectSnappingOffset = - editor_center - (node.Rect.Min + node.Rect.Max) * 0.5f; } else if (editor.SelectedNodeIndices.contains(node_idx)) { @@ -1762,28 +1815,23 @@ static void MiniMapDrawNode( const ImU32 mini_map_node_outline = GImNodes->Style.Colors[ImNodesCol_MiniMapNodeOutline]; GImNodes->CanvasDrawList->AddRectFilled( - mini_map_node_min, mini_map_node_max, mini_map_node_background, mini_map_node_rounding); + node_rect.Min, node_rect.Max, mini_map_node_background, mini_map_node_rounding); GImNodes->CanvasDrawList->AddRect( - mini_map_node_min, mini_map_node_max, mini_map_node_outline, mini_map_node_rounding); + node_rect.Min, node_rect.Max, mini_map_node_outline, mini_map_node_rounding); } -static void MiniMapDrawLink( - ImNodesEditorContext& editor, - const int link_idx, - const ImVec2& editor_center, - const ImVec2& mini_map_center, - const float scaling) +static void MiniMapDrawLink(ImNodesEditorContext& editor, const int link_idx) { const ImLinkData& link = editor.Links.Pool[link_idx]; const ImPinData& start_pin = editor.Pins.Pool[link.StartPinIdx]; const ImPinData& end_pin = editor.Pins.Pool[link.EndPinIdx]; const CubicBezier cubic_bezier = GetCubicBezier( - (start_pin.Pos - editor_center) * scaling + mini_map_center, - (end_pin.Pos - editor_center) * scaling + mini_map_center, + ScreenSpaceToMiniMapSpace(editor, start_pin.Pos), + ScreenSpaceToMiniMapSpace(editor, end_pin.Pos), start_pin.Type, - GImNodes->Style.LinkLineSegmentsPerLength / scaling); + GImNodes->Style.LinkLineSegmentsPerLength / editor.MiniMapScaling); // It's possible for a link to be deleted in begin_link_interaction. A user // may detach a link, resulting in the link wire snapping to the mouse @@ -1810,7 +1858,7 @@ static void MiniMapDrawLink( cubic_bezier.P2, cubic_bezier.P3, link_color, - GImNodes->Style.LinkThickness * scaling, + GImNodes->Style.LinkThickness * editor.MiniMapScaling, cubic_bezier.NumSegments); } @@ -1820,9 +1868,7 @@ static void MiniMapUpdate() ImU32 mini_map_background; - // NOTE: use normal background when panning (typically opaque) - if (editor.ClickInteraction.Type != ImNodesClickInteractionType_MiniMapPanning && - IsMiniMapHovered()) + if (IsMiniMapHovered()) { mini_map_background = GImNodes->Style.Colors[ImNodesCol_MiniMapBackgroundHovered]; } @@ -1831,17 +1877,12 @@ static void MiniMapUpdate() mini_map_background = GImNodes->Style.Colors[ImNodesCol_MiniMapBackground]; } - const ImRect& editor_rect = GImNodes->CanvasRectScreenSpace; + // Create a child window bellow mini-map, so it blocks all mouse interaction on canvas. + int flags = ImGuiWindowFlags_NoBackground; + ImGui::SetCursorScreenPos(editor.MiniMapRectScreenSpace.Min); + ImGui::BeginChild("minimap", editor.MiniMapRectScreenSpace.GetSize(), false, flags); - const ImVec2 editor_center( - 0.5f * (editor_rect.Min.x + editor_rect.Max.x), - 0.5f * (editor_rect.Min.y + editor_rect.Max.y)); - - const ImRect& mini_map_rect = GImNodes->MiniMapRectScreenSpace; - - const ImVec2 mini_map_center( - 0.5f * (mini_map_rect.Min.x + mini_map_rect.Max.x), - 0.5f * (mini_map_rect.Min.y + mini_map_rect.Max.y)); + const ImRect& mini_map_rect = editor.MiniMapRectScreenSpace; // Draw minimap background and border GImNodes->CanvasDrawList->AddRectFilled( @@ -1854,15 +1895,12 @@ static void MiniMapUpdate() GImNodes->CanvasDrawList->PushClipRect( mini_map_rect.Min, mini_map_rect.Max, true /* intersect with editor clip-rect */); - // Get zoom scaling (0, 1] - const float scaling = GImNodes->MiniMapZoom; - // Draw links first so they appear under nodes, and we can use the same draw channel for (int link_idx = 0; link_idx < editor.Links.Pool.size(); ++link_idx) { if (editor.Links.InUse[link_idx]) { - MiniMapDrawLink(editor, link_idx, editor_center, mini_map_center, scaling); + MiniMapDrawLink(editor, link_idx); } } @@ -1870,19 +1908,40 @@ static void MiniMapUpdate() { if (editor.Nodes.InUse[node_idx]) { - MiniMapDrawNode(editor, node_idx, editor_center, mini_map_center, scaling); + MiniMapDrawNode(editor, node_idx); } } + // Draw editor canvas rect inside mini-map + { + const ImU32 canvas_color = GImNodes->Style.Colors[ImNodesCol_MiniMapCanvas]; + const ImU32 outline_color = GImNodes->Style.Colors[ImNodesCol_MiniMapCanvasOutline]; + const ImRect rect = ScreenSpaceToMiniMapSpace(editor, GImNodes->CanvasRectScreenSpace); + + GImNodes->CanvasDrawList->AddRectFilled(rect.Min, rect.Max, canvas_color); + GImNodes->CanvasDrawList->AddRect(rect.Min, rect.Max, outline_color); + } + // Have to pop mini-map clip rect GImNodes->CanvasDrawList->PopClipRect(); - // Reset callback info after use - GImNodes->MiniMapNodeHoveringCallback = NULL; - GImNodes->MiniMapNodeHoveringCallbackUserData = NULL; + bool mini_map_is_hovered = ImGui::IsWindowHovered(); - // Reset mini-map area so that it will disappear if MiniMap(...) is not called on the next frame - GImNodes->MiniMapRectScreenSpace = ImRect(ImVec2(0.f, 0.f), ImVec2(0.f, 0.f)); + ImGui::EndChild(); + + bool center_on_click = mini_map_is_hovered && ImGui::IsMouseDown(ImGuiMouseButton_Left) && + editor.ClickInteraction.Type == ImNodesClickInteractionType_None && + !GImNodes->NodeIdxSubmissionOrder.empty(); + if (center_on_click) + { + ImVec2 target = MiniMapSpaceToGridSpace(editor, ImGui::GetMousePos()); + ImVec2 center = GImNodes->CanvasRectScreenSpace.GetSize() * 0.5f; + editor.Panning = ImFloor(center - target); + } + + // Reset callback info after use + editor.MiniMapNodeHoveringCallback = NULL; + editor.MiniMapNodeHoveringCallbackUserData = NULL; } // [SECTION] selection helpers @@ -1891,8 +1950,8 @@ template void SelectObject(const ImObjectPool& objects, ImVector& selected_indices, const int id) { const int idx = ObjectPoolFind(objects, id); - assert(idx >= 0); - assert(selected_indices.find(idx) == selected_indices.end()); + IM_ASSERT(idx >= 0); + IM_ASSERT(selected_indices.find(idx) == selected_indices.end()); selected_indices.push_back(idx); } @@ -1903,8 +1962,8 @@ void ClearObjectSelection( const int id) { const int idx = ObjectPoolFind(objects, id); - assert(idx >= 0); - assert(selected_indices.find(idx) != selected_indices.end()); + IM_ASSERT(idx >= 0); + IM_ASSERT(selected_indices.find(idx) != selected_indices.end()); selected_indices.find_erase_unsorted(idx); } @@ -1916,7 +1975,7 @@ bool IsObjectSelected(const ImObjectPool& objects, ImVector& selected_in } } // namespace -} // namespace ImNodes +} // namespace IMNODES_NAMESPACE // [SECTION] API implementation @@ -1924,23 +1983,25 @@ ImNodesIO::EmulateThreeButtonMouse::EmulateThreeButtonMouse() : Modifier(NULL) { ImNodesIO::LinkDetachWithModifierClick::LinkDetachWithModifierClick() : Modifier(NULL) {} +ImNodesIO::MultipleSelectModifier::MultipleSelectModifier() : Modifier(NULL) {} + ImNodesIO::ImNodesIO() : EmulateThreeButtonMouse(), LinkDetachWithModifierClick(), - AltMouseButton(ImGuiMouseButton_Middle) + AltMouseButton(ImGuiMouseButton_Middle), AutoPanningSpeed(1000.0f) { } ImNodesStyle::ImNodesStyle() - : GridSpacing(32.f), NodeCornerRounding(4.f), NodePaddingHorizontal(8.f), - NodePaddingVertical(8.f), NodeBorderThickness(1.f), LinkThickness(3.f), - LinkLineSegmentsPerLength(0.1f), LinkHoverDistance(10.f), PinCircleRadius(4.f), - PinQuadSideLength(7.f), PinTriangleSideLength(9.5), PinLineThickness(1.f), - PinHoverRadius(10.f), PinOffset(0.f), - Flags(ImNodesStyleFlags_NodeOutline | ImNodesStyleFlags_GridLines), Colors() + : GridSpacing(24.f), NodeCornerRounding(4.f), NodePadding(8.f, 8.f), NodeBorderThickness(1.f), + LinkThickness(3.f), LinkLineSegmentsPerLength(0.1f), LinkHoverDistance(10.f), + PinCircleRadius(4.f), PinQuadSideLength(7.f), PinTriangleSideLength(9.5), + PinLineThickness(1.f), PinHoverRadius(10.f), PinOffset(0.f), MiniMapPadding(8.0f, 8.0f), + MiniMapOffset(4.0f, 4.0f), Flags(ImNodesStyleFlags_NodeOutline | ImNodesStyleFlags_GridLines), + Colors() { } -namespace ImNodes +namespace IMNODES_NAMESPACE { ImNodesContext* CreateContext() { @@ -2007,124 +2068,148 @@ ImNodesIO& GetIO() { return GImNodes->Io; } ImNodesStyle& GetStyle() { return GImNodes->Style; } -void StyleColorsDark() +void StyleColorsDark(ImNodesStyle* dest) { - GImNodes->Style.Colors[ImNodesCol_NodeBackground] = IM_COL32(50, 50, 50, 255); - GImNodes->Style.Colors[ImNodesCol_NodeBackgroundHovered] = IM_COL32(75, 75, 75, 255); - GImNodes->Style.Colors[ImNodesCol_NodeBackgroundSelected] = IM_COL32(75, 75, 75, 255); - GImNodes->Style.Colors[ImNodesCol_NodeOutline] = IM_COL32(100, 100, 100, 255); + if (dest == nullptr) + { + dest = &GImNodes->Style; + } + + dest->Colors[ImNodesCol_NodeBackground] = IM_COL32(50, 50, 50, 255); + dest->Colors[ImNodesCol_NodeBackgroundHovered] = IM_COL32(75, 75, 75, 255); + dest->Colors[ImNodesCol_NodeBackgroundSelected] = IM_COL32(75, 75, 75, 255); + dest->Colors[ImNodesCol_NodeOutline] = IM_COL32(100, 100, 100, 255); // title bar colors match ImGui's titlebg colors - GImNodes->Style.Colors[ImNodesCol_TitleBar] = IM_COL32(41, 74, 122, 255); - GImNodes->Style.Colors[ImNodesCol_TitleBarHovered] = IM_COL32(66, 150, 250, 255); - GImNodes->Style.Colors[ImNodesCol_TitleBarSelected] = IM_COL32(66, 150, 250, 255); + dest->Colors[ImNodesCol_TitleBar] = IM_COL32(41, 74, 122, 255); + dest->Colors[ImNodesCol_TitleBarHovered] = IM_COL32(66, 150, 250, 255); + dest->Colors[ImNodesCol_TitleBarSelected] = IM_COL32(66, 150, 250, 255); // link colors match ImGui's slider grab colors - GImNodes->Style.Colors[ImNodesCol_Link] = IM_COL32(61, 133, 224, 200); - GImNodes->Style.Colors[ImNodesCol_LinkHovered] = IM_COL32(66, 150, 250, 255); - GImNodes->Style.Colors[ImNodesCol_LinkSelected] = IM_COL32(66, 150, 250, 255); + dest->Colors[ImNodesCol_Link] = IM_COL32(61, 133, 224, 200); + dest->Colors[ImNodesCol_LinkHovered] = IM_COL32(66, 150, 250, 255); + dest->Colors[ImNodesCol_LinkSelected] = IM_COL32(66, 150, 250, 255); // pin colors match ImGui's button colors - GImNodes->Style.Colors[ImNodesCol_Pin] = IM_COL32(53, 150, 250, 180); - GImNodes->Style.Colors[ImNodesCol_PinHovered] = IM_COL32(53, 150, 250, 255); + dest->Colors[ImNodesCol_Pin] = IM_COL32(53, 150, 250, 180); + dest->Colors[ImNodesCol_PinHovered] = IM_COL32(53, 150, 250, 255); - GImNodes->Style.Colors[ImNodesCol_BoxSelector] = IM_COL32(61, 133, 224, 30); - GImNodes->Style.Colors[ImNodesCol_BoxSelectorOutline] = IM_COL32(61, 133, 224, 150); + dest->Colors[ImNodesCol_BoxSelector] = IM_COL32(61, 133, 224, 30); + dest->Colors[ImNodesCol_BoxSelectorOutline] = IM_COL32(61, 133, 224, 150); - GImNodes->Style.Colors[ImNodesCol_GridBackground] = IM_COL32(40, 40, 50, 200); - GImNodes->Style.Colors[ImNodesCol_GridLine] = IM_COL32(200, 200, 200, 40); + dest->Colors[ImNodesCol_GridBackground] = IM_COL32(40, 40, 50, 200); + dest->Colors[ImNodesCol_GridLine] = IM_COL32(200, 200, 200, 40); + dest->Colors[ImNodesCol_GridLinePrimary] = IM_COL32(240, 240, 240, 60); // minimap colors - GImNodes->Style.Colors[ImNodesCol_MiniMapBackground] = IM_COL32(25, 25, 25, 100); - GImNodes->Style.Colors[ImNodesCol_MiniMapBackgroundHovered] = IM_COL32(25, 25, 25, 200); - GImNodes->Style.Colors[ImNodesCol_MiniMapOutline] = IM_COL32(150, 150, 150, 100); - GImNodes->Style.Colors[ImNodesCol_MiniMapOutlineHovered] = IM_COL32(150, 150, 150, 200); - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeBackground] = IM_COL32(200, 200, 200, 100); - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeBackgroundHovered] = IM_COL32(200, 200, 200, 255); - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeBackgroundSelected] = - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeBackgroundHovered]; - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeOutline] = IM_COL32(200, 200, 200, 100); - GImNodes->Style.Colors[ImNodesCol_MiniMapLink] = GImNodes->Style.Colors[ImNodesCol_Link]; - GImNodes->Style.Colors[ImNodesCol_MiniMapLinkSelected] = - GImNodes->Style.Colors[ImNodesCol_LinkSelected]; + dest->Colors[ImNodesCol_MiniMapBackground] = IM_COL32(25, 25, 25, 150); + dest->Colors[ImNodesCol_MiniMapBackgroundHovered] = IM_COL32(25, 25, 25, 200); + dest->Colors[ImNodesCol_MiniMapOutline] = IM_COL32(150, 150, 150, 100); + dest->Colors[ImNodesCol_MiniMapOutlineHovered] = IM_COL32(150, 150, 150, 200); + dest->Colors[ImNodesCol_MiniMapNodeBackground] = IM_COL32(200, 200, 200, 100); + dest->Colors[ImNodesCol_MiniMapNodeBackgroundHovered] = IM_COL32(200, 200, 200, 255); + dest->Colors[ImNodesCol_MiniMapNodeBackgroundSelected] = + dest->Colors[ImNodesCol_MiniMapNodeBackgroundHovered]; + dest->Colors[ImNodesCol_MiniMapNodeOutline] = IM_COL32(200, 200, 200, 100); + dest->Colors[ImNodesCol_MiniMapLink] = dest->Colors[ImNodesCol_Link]; + dest->Colors[ImNodesCol_MiniMapLinkSelected] = dest->Colors[ImNodesCol_LinkSelected]; + dest->Colors[ImNodesCol_MiniMapCanvas] = IM_COL32(200, 200, 200, 25); + dest->Colors[ImNodesCol_MiniMapCanvasOutline] = IM_COL32(200, 200, 200, 200); } -void StyleColorsClassic() +void StyleColorsClassic(ImNodesStyle* dest) { - GImNodes->Style.Colors[ImNodesCol_NodeBackground] = IM_COL32(50, 50, 50, 255); - GImNodes->Style.Colors[ImNodesCol_NodeBackgroundHovered] = IM_COL32(75, 75, 75, 255); - GImNodes->Style.Colors[ImNodesCol_NodeBackgroundSelected] = IM_COL32(75, 75, 75, 255); - GImNodes->Style.Colors[ImNodesCol_NodeOutline] = IM_COL32(100, 100, 100, 255); - GImNodes->Style.Colors[ImNodesCol_TitleBar] = IM_COL32(69, 69, 138, 255); - GImNodes->Style.Colors[ImNodesCol_TitleBarHovered] = IM_COL32(82, 82, 161, 255); - GImNodes->Style.Colors[ImNodesCol_TitleBarSelected] = IM_COL32(82, 82, 161, 255); - GImNodes->Style.Colors[ImNodesCol_Link] = IM_COL32(255, 255, 255, 100); - GImNodes->Style.Colors[ImNodesCol_LinkHovered] = IM_COL32(105, 99, 204, 153); - GImNodes->Style.Colors[ImNodesCol_LinkSelected] = IM_COL32(105, 99, 204, 153); - GImNodes->Style.Colors[ImNodesCol_Pin] = IM_COL32(89, 102, 156, 170); - GImNodes->Style.Colors[ImNodesCol_PinHovered] = IM_COL32(102, 122, 179, 200); - GImNodes->Style.Colors[ImNodesCol_BoxSelector] = IM_COL32(82, 82, 161, 100); - GImNodes->Style.Colors[ImNodesCol_BoxSelectorOutline] = IM_COL32(82, 82, 161, 255); - GImNodes->Style.Colors[ImNodesCol_GridBackground] = IM_COL32(40, 40, 50, 200); - GImNodes->Style.Colors[ImNodesCol_GridLine] = IM_COL32(200, 200, 200, 40); + if (dest == nullptr) + { + dest = &GImNodes->Style; + } + + dest->Colors[ImNodesCol_NodeBackground] = IM_COL32(50, 50, 50, 255); + dest->Colors[ImNodesCol_NodeBackgroundHovered] = IM_COL32(75, 75, 75, 255); + dest->Colors[ImNodesCol_NodeBackgroundSelected] = IM_COL32(75, 75, 75, 255); + dest->Colors[ImNodesCol_NodeOutline] = IM_COL32(100, 100, 100, 255); + dest->Colors[ImNodesCol_TitleBar] = IM_COL32(69, 69, 138, 255); + dest->Colors[ImNodesCol_TitleBarHovered] = IM_COL32(82, 82, 161, 255); + dest->Colors[ImNodesCol_TitleBarSelected] = IM_COL32(82, 82, 161, 255); + dest->Colors[ImNodesCol_Link] = IM_COL32(255, 255, 255, 100); + dest->Colors[ImNodesCol_LinkHovered] = IM_COL32(105, 99, 204, 153); + dest->Colors[ImNodesCol_LinkSelected] = IM_COL32(105, 99, 204, 153); + dest->Colors[ImNodesCol_Pin] = IM_COL32(89, 102, 156, 170); + dest->Colors[ImNodesCol_PinHovered] = IM_COL32(102, 122, 179, 200); + dest->Colors[ImNodesCol_BoxSelector] = IM_COL32(82, 82, 161, 100); + dest->Colors[ImNodesCol_BoxSelectorOutline] = IM_COL32(82, 82, 161, 255); + dest->Colors[ImNodesCol_GridBackground] = IM_COL32(40, 40, 50, 200); + dest->Colors[ImNodesCol_GridLine] = IM_COL32(200, 200, 200, 40); + dest->Colors[ImNodesCol_GridLinePrimary] = IM_COL32(240, 240, 240, 60); // minimap colors - GImNodes->Style.Colors[ImNodesCol_MiniMapBackground] = IM_COL32(25, 25, 25, 100); - GImNodes->Style.Colors[ImNodesCol_MiniMapBackgroundHovered] = IM_COL32(25, 25, 25, 200); - GImNodes->Style.Colors[ImNodesCol_MiniMapOutline] = IM_COL32(150, 150, 150, 100); - GImNodes->Style.Colors[ImNodesCol_MiniMapOutlineHovered] = IM_COL32(150, 150, 150, 200); - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeBackground] = IM_COL32(200, 200, 200, 100); - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeBackgroundSelected] = - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeBackgroundHovered]; - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeBackgroundSelected] = IM_COL32(200, 200, 240, 255); - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeOutline] = IM_COL32(200, 200, 200, 100); - GImNodes->Style.Colors[ImNodesCol_MiniMapLink] = GImNodes->Style.Colors[ImNodesCol_Link]; - GImNodes->Style.Colors[ImNodesCol_MiniMapLinkSelected] = - GImNodes->Style.Colors[ImNodesCol_LinkSelected]; + dest->Colors[ImNodesCol_MiniMapBackground] = IM_COL32(25, 25, 25, 100); + dest->Colors[ImNodesCol_MiniMapBackgroundHovered] = IM_COL32(25, 25, 25, 200); + dest->Colors[ImNodesCol_MiniMapOutline] = IM_COL32(150, 150, 150, 100); + dest->Colors[ImNodesCol_MiniMapOutlineHovered] = IM_COL32(150, 150, 150, 200); + dest->Colors[ImNodesCol_MiniMapNodeBackground] = IM_COL32(200, 200, 200, 100); + dest->Colors[ImNodesCol_MiniMapNodeBackgroundSelected] = + dest->Colors[ImNodesCol_MiniMapNodeBackgroundHovered]; + dest->Colors[ImNodesCol_MiniMapNodeBackgroundSelected] = IM_COL32(200, 200, 240, 255); + dest->Colors[ImNodesCol_MiniMapNodeOutline] = IM_COL32(200, 200, 200, 100); + dest->Colors[ImNodesCol_MiniMapLink] = dest->Colors[ImNodesCol_Link]; + dest->Colors[ImNodesCol_MiniMapLinkSelected] = dest->Colors[ImNodesCol_LinkSelected]; + dest->Colors[ImNodesCol_MiniMapCanvas] = IM_COL32(200, 200, 200, 25); + dest->Colors[ImNodesCol_MiniMapCanvasOutline] = IM_COL32(200, 200, 200, 200); } -void StyleColorsLight() +void StyleColorsLight(ImNodesStyle* dest) { - GImNodes->Style.Colors[ImNodesCol_NodeBackground] = IM_COL32(240, 240, 240, 255); - GImNodes->Style.Colors[ImNodesCol_NodeBackgroundHovered] = IM_COL32(240, 240, 240, 255); - GImNodes->Style.Colors[ImNodesCol_NodeBackgroundSelected] = IM_COL32(240, 240, 240, 255); - GImNodes->Style.Colors[ImNodesCol_NodeOutline] = IM_COL32(100, 100, 100, 255); - GImNodes->Style.Colors[ImNodesCol_TitleBar] = IM_COL32(248, 248, 248, 255); - GImNodes->Style.Colors[ImNodesCol_TitleBarHovered] = IM_COL32(209, 209, 209, 255); - GImNodes->Style.Colors[ImNodesCol_TitleBarSelected] = IM_COL32(209, 209, 209, 255); + if (dest == nullptr) + { + dest = &GImNodes->Style; + } + + dest->Colors[ImNodesCol_NodeBackground] = IM_COL32(240, 240, 240, 255); + dest->Colors[ImNodesCol_NodeBackgroundHovered] = IM_COL32(240, 240, 240, 255); + dest->Colors[ImNodesCol_NodeBackgroundSelected] = IM_COL32(240, 240, 240, 255); + dest->Colors[ImNodesCol_NodeOutline] = IM_COL32(100, 100, 100, 255); + dest->Colors[ImNodesCol_TitleBar] = IM_COL32(248, 248, 248, 255); + dest->Colors[ImNodesCol_TitleBarHovered] = IM_COL32(209, 209, 209, 255); + dest->Colors[ImNodesCol_TitleBarSelected] = IM_COL32(209, 209, 209, 255); // original imgui values: 66, 150, 250 - GImNodes->Style.Colors[ImNodesCol_Link] = IM_COL32(66, 150, 250, 100); + dest->Colors[ImNodesCol_Link] = IM_COL32(66, 150, 250, 100); // original imgui values: 117, 138, 204 - GImNodes->Style.Colors[ImNodesCol_LinkHovered] = IM_COL32(66, 150, 250, 242); - GImNodes->Style.Colors[ImNodesCol_LinkSelected] = IM_COL32(66, 150, 250, 242); + dest->Colors[ImNodesCol_LinkHovered] = IM_COL32(66, 150, 250, 242); + dest->Colors[ImNodesCol_LinkSelected] = IM_COL32(66, 150, 250, 242); // original imgui values: 66, 150, 250 - GImNodes->Style.Colors[ImNodesCol_Pin] = IM_COL32(66, 150, 250, 160); - GImNodes->Style.Colors[ImNodesCol_PinHovered] = IM_COL32(66, 150, 250, 255); - GImNodes->Style.Colors[ImNodesCol_BoxSelector] = IM_COL32(90, 170, 250, 30); - GImNodes->Style.Colors[ImNodesCol_BoxSelectorOutline] = IM_COL32(90, 170, 250, 150); - GImNodes->Style.Colors[ImNodesCol_GridBackground] = IM_COL32(225, 225, 225, 255); - GImNodes->Style.Colors[ImNodesCol_GridLine] = IM_COL32(180, 180, 180, 100); + dest->Colors[ImNodesCol_Pin] = IM_COL32(66, 150, 250, 160); + dest->Colors[ImNodesCol_PinHovered] = IM_COL32(66, 150, 250, 255); + dest->Colors[ImNodesCol_BoxSelector] = IM_COL32(90, 170, 250, 30); + dest->Colors[ImNodesCol_BoxSelectorOutline] = IM_COL32(90, 170, 250, 150); + dest->Colors[ImNodesCol_GridBackground] = IM_COL32(225, 225, 225, 255); + dest->Colors[ImNodesCol_GridLine] = IM_COL32(180, 180, 180, 100); + dest->Colors[ImNodesCol_GridLinePrimary] = IM_COL32(120, 120, 120, 100); // minimap colors - GImNodes->Style.Colors[ImNodesCol_MiniMapBackground] = IM_COL32(25, 25, 25, 100); - GImNodes->Style.Colors[ImNodesCol_MiniMapBackgroundHovered] = IM_COL32(25, 25, 25, 200); - GImNodes->Style.Colors[ImNodesCol_MiniMapOutline] = IM_COL32(150, 150, 150, 100); - GImNodes->Style.Colors[ImNodesCol_MiniMapOutlineHovered] = IM_COL32(150, 150, 150, 200); - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeBackground] = IM_COL32(200, 200, 200, 100); - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeBackgroundSelected] = - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeBackgroundHovered]; - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeBackgroundSelected] = IM_COL32(200, 200, 240, 255); - GImNodes->Style.Colors[ImNodesCol_MiniMapNodeOutline] = IM_COL32(200, 200, 200, 100); - GImNodes->Style.Colors[ImNodesCol_MiniMapLink] = GImNodes->Style.Colors[ImNodesCol_Link]; - GImNodes->Style.Colors[ImNodesCol_MiniMapLinkSelected] = - GImNodes->Style.Colors[ImNodesCol_LinkSelected]; + dest->Colors[ImNodesCol_MiniMapBackground] = IM_COL32(25, 25, 25, 100); + dest->Colors[ImNodesCol_MiniMapBackgroundHovered] = IM_COL32(25, 25, 25, 200); + dest->Colors[ImNodesCol_MiniMapOutline] = IM_COL32(150, 150, 150, 100); + dest->Colors[ImNodesCol_MiniMapOutlineHovered] = IM_COL32(150, 150, 150, 200); + dest->Colors[ImNodesCol_MiniMapNodeBackground] = IM_COL32(200, 200, 200, 100); + dest->Colors[ImNodesCol_MiniMapNodeBackgroundSelected] = + dest->Colors[ImNodesCol_MiniMapNodeBackgroundHovered]; + dest->Colors[ImNodesCol_MiniMapNodeBackgroundSelected] = IM_COL32(200, 200, 240, 255); + dest->Colors[ImNodesCol_MiniMapNodeOutline] = IM_COL32(200, 200, 200, 100); + dest->Colors[ImNodesCol_MiniMapLink] = dest->Colors[ImNodesCol_Link]; + dest->Colors[ImNodesCol_MiniMapLinkSelected] = dest->Colors[ImNodesCol_LinkSelected]; + dest->Colors[ImNodesCol_MiniMapCanvas] = IM_COL32(200, 200, 200, 25); + dest->Colors[ImNodesCol_MiniMapCanvasOutline] = IM_COL32(200, 200, 200, 200); } void BeginNodeEditor() { - assert(GImNodes->CurrentScope == ImNodesScope_None); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_None); GImNodes->CurrentScope = ImNodesScope_Editor; // Reset state from previous pass ImNodesEditorContext& editor = EditorContextGet(); + editor.AutoPanningDelta = ImVec2(0, 0); + editor.GridContentBounds = ImRect(FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX); + editor.MiniMapEnabled = false; ObjectPoolReset(editor.Nodes); ObjectPoolReset(editor.Pins); ObjectPoolReset(editor.Links); @@ -2142,16 +2227,20 @@ void BeginNodeEditor() GImNodes->MousePos = ImGui::GetIO().MousePos; GImNodes->LeftMouseClicked = ImGui::IsMouseClicked(0); GImNodes->LeftMouseReleased = ImGui::IsMouseReleased(0); + GImNodes->LeftMouseDragging = ImGui::IsMouseDragging(0, 0.0f); GImNodes->AltMouseClicked = (GImNodes->Io.EmulateThreeButtonMouse.Modifier != NULL && *GImNodes->Io.EmulateThreeButtonMouse.Modifier && GImNodes->LeftMouseClicked) || ImGui::IsMouseClicked(GImNodes->Io.AltMouseButton); - GImNodes->LeftMouseDragging = ImGui::IsMouseDragging(0, 0.0f); GImNodes->AltMouseDragging = (GImNodes->Io.EmulateThreeButtonMouse.Modifier != NULL && GImNodes->LeftMouseDragging && (*GImNodes->Io.EmulateThreeButtonMouse.Modifier)) || ImGui::IsMouseDragging(GImNodes->Io.AltMouseButton, 0.0f); GImNodes->AltMouseScrollDelta = ImGui::GetIO().MouseWheel; + GImNodes->MultipleSelectModifier = + (GImNodes->Io.MultipleSelectModifier.Modifier != NULL + ? *GImNodes->Io.MultipleSelectModifier.Modifier + : ImGui::GetIO().KeyCtrl); GImNodes->ActiveAttribute = false; @@ -2188,11 +2277,17 @@ void BeginNodeEditor() void EndNodeEditor() { - assert(GImNodes->CurrentScope == ImNodesScope_Editor); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_Editor); GImNodes->CurrentScope = ImNodesScope_None; ImNodesEditorContext& editor = EditorContextGet(); + bool no_grid_content = editor.GridContentBounds.IsInverted(); + if (no_grid_content) + { + editor.GridContentBounds = ScreenSpaceToGridSpace(editor, GImNodes->CanvasRectScreenSpace); + } + // Detect ImGui interaction first, because it blocks interaction with the rest of the UI if (GImNodes->LeftMouseClicked && ImGui::IsAnyItemActive()) @@ -2258,12 +2353,19 @@ void EndNodeEditor() DrawListAppendClickInteractionChannel(); DrawListActivateClickInteractionChannel(); + if (IsMiniMapActive()) + { + CalcMiniMapLayout(); + MiniMapUpdate(); + } + // Handle node graph interaction + if (!IsMiniMapHovered()) { if (GImNodes->LeftMouseClicked && GImNodes->HoveredLinkIdx.HasValue()) { - BeginLinkInteraction(editor, GImNodes->HoveredLinkIdx.Value()); + BeginLinkInteraction(editor, GImNodes->HoveredLinkIdx.Value(), GImNodes->HoveredPinIdx); } else if (GImNodes->LeftMouseClicked && GImNodes->HoveredPinIdx.HasValue()) @@ -2283,14 +2385,23 @@ void EndNodeEditor() BeginCanvasInteraction(editor); } - ClickInteractionUpdate(editor); - } + bool should_auto_pan = + editor.ClickInteraction.Type == ImNodesClickInteractionType_BoxSelection || + editor.ClickInteraction.Type == ImNodesClickInteractionType_LinkCreation || + editor.ClickInteraction.Type == ImNodesClickInteractionType_Node; + if (should_auto_pan && !MouseInCanvas()) + { + ImVec2 mouse = ImGui::GetMousePos(); + ImVec2 center = GImNodes->CanvasRectScreenSpace.GetCenter(); + ImVec2 direction = (center - mouse); + direction = direction * ImInvLength(direction, 0.0); - // Mini-map rect will be set with non-zero width if MiniMap(...) was called - if (IsMiniMapActive()) - { - MiniMapUpdate(); + editor.AutoPanningDelta = + direction * ImGui::GetIO().DeltaTime * GImNodes->Io.AutoPanningSpeed; + editor.Panning += editor.AutoPanningDelta; + } } + ClickInteractionUpdate(editor); // At this point, draw commands have been issued for all nodes (and pins). Update the node pool // to detect unused node slots and remove those indices from the depth stack before sorting the @@ -2315,27 +2426,26 @@ void EndNodeEditor() } void MiniMap( - const float minimap_size_fraction, - const ImNodesMiniMapLocation location, - const ImNodesMiniMapNodeHoveringCallback node_hovering_callback, - void* node_hovering_callback_data) + const float minimap_size_fraction, + const ImNodesMiniMapLocation location, + const ImNodesMiniMapNodeHoveringCallback node_hovering_callback, + const ImNodesMiniMapNodeHoveringCallbackUserData node_hovering_callback_data) { // Check that editor size fraction is sane; must be in the range (0, 1] - assert(minimap_size_fraction > 0.f && minimap_size_fraction <= 1.f); + IM_ASSERT(minimap_size_fraction > 0.f && minimap_size_fraction <= 1.f); // Remember to call before EndNodeEditor - assert(GImNodes->CurrentScope == ImNodesScope_Editor); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_Editor); - // Set the size of the mini map to the global state - GImNodes->MiniMapRectScreenSpace = - ToMiniMapRect(minimap_size_fraction, GImNodes->CanvasRectScreenSpace, location); + ImNodesEditorContext& editor = EditorContextGet(); - // We'll know that the mini map is active if GImNodes->MiniMapRectScreenSpace specifies - // a non-zero area (actually, just the width is checked for non-zero size) + editor.MiniMapEnabled = true; + editor.MiniMapSizeFraction = minimap_size_fraction; + editor.MiniMapLocation = location; // Set node hovering callback information - GImNodes->MiniMapNodeHoveringCallback = node_hovering_callback; - GImNodes->MiniMapNodeHoveringCallbackUserData = node_hovering_callback_data; + editor.MiniMapNodeHoveringCallback = node_hovering_callback; + editor.MiniMapNodeHoveringCallbackUserData = node_hovering_callback_data; // Actual drawing/updating of the MiniMap is done in EndNodeEditor so that // mini map is draw over everything and all pin/link positions are updated @@ -2346,7 +2456,7 @@ void MiniMap( void BeginNode(const int node_id) { // Remember to call BeginNodeEditor before calling BeginNode - assert(GImNodes->CurrentScope == ImNodesScope_Editor); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_Editor); GImNodes->CurrentScope = ImNodesScope_Node; ImNodesEditorContext& editor = EditorContextGet(); @@ -2363,8 +2473,7 @@ void BeginNode(const int node_id) node.ColorStyle.TitlebarHovered = GImNodes->Style.Colors[ImNodesCol_TitleBarHovered]; node.ColorStyle.TitlebarSelected = GImNodes->Style.Colors[ImNodesCol_TitleBarSelected]; node.LayoutStyle.CornerRounding = GImNodes->Style.NodeCornerRounding; - node.LayoutStyle.Padding = - ImVec2(GImNodes->Style.NodePaddingHorizontal, GImNodes->Style.NodePaddingVertical); + node.LayoutStyle.Padding = GImNodes->Style.NodePadding; node.LayoutStyle.BorderThickness = GImNodes->Style.NodeBorderThickness; // ImGui::SetCursorPos sets the cursor position, local to the current widget @@ -2381,7 +2490,7 @@ void BeginNode(const int node_id) void EndNode() { - assert(GImNodes->CurrentScope == ImNodesScope_Node); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_Node); GImNodes->CurrentScope = ImNodesScope_Editor; ImNodesEditorContext& editor = EditorContextGet(); @@ -2394,6 +2503,9 @@ void EndNode() node.Rect = GetItemRect(); node.Rect.Expand(node.LayoutStyle.Padding); + editor.GridContentBounds.Add(node.Origin); + editor.GridContentBounds.Add(node.Origin + node.Rect.GetSize()); + if (node.Rect.Contains(GImNodes->MousePos)) { GImNodes->NodeIndicesOverlappingWithMouse.push_back(GImNodes->CurrentNodeIdx); @@ -2404,20 +2516,20 @@ ImVec2 GetNodeDimensions(int node_id) { ImNodesEditorContext& editor = EditorContextGet(); const int node_idx = ObjectPoolFind(editor.Nodes, node_id); - assert(node_idx != -1); // invalid node_id + IM_ASSERT(node_idx != -1); // invalid node_id const ImNodeData& node = editor.Nodes.Pool[node_idx]; return node.Rect.GetSize(); } void BeginNodeTitleBar() { - assert(GImNodes->CurrentScope == ImNodesScope_Node); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_Node); ImGui::BeginGroup(); } void EndNodeTitleBar() { - assert(GImNodes->CurrentScope == ImNodesScope_Node); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_Node); ImGui::EndGroup(); ImNodesEditorContext& editor = EditorContextGet(); @@ -2446,7 +2558,7 @@ void EndOutputAttribute() { EndPinAttribute(); } void BeginStaticAttribute(const int id) { // Make sure to call BeginNode() before calling BeginAttribute() - assert(GImNodes->CurrentScope == ImNodesScope_Node); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_Node); GImNodes->CurrentScope = ImNodesScope_Attribute; GImNodes->CurrentAttributeId = id; @@ -2458,7 +2570,7 @@ void BeginStaticAttribute(const int id) void EndStaticAttribute() { // Make sure to call BeginNode() before calling BeginAttribute() - assert(GImNodes->CurrentScope == ImNodesScope_Attribute); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_Attribute); GImNodes->CurrentScope = ImNodesScope_Node; ImGui::PopID(); @@ -2481,7 +2593,7 @@ void PopAttributeFlag() { // PopAttributeFlag called without a matching PushAttributeFlag! // The bottom value is always the default value, pushed in Initialize(). - assert(GImNodes->AttributeFlagStack.size() > 1); + IM_ASSERT(GImNodes->AttributeFlagStack.size() > 1); GImNodes->AttributeFlagStack.pop_back(); GImNodes->CurrentAttributeFlags = GImNodes->AttributeFlagStack.back(); @@ -2489,7 +2601,7 @@ void PopAttributeFlag() void Link(const int id, const int start_attr_id, const int end_attr_id) { - assert(GImNodes->CurrentScope == ImNodesScope_Editor); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_Editor); ImNodesEditorContext& editor = EditorContextGet(); ImLinkData& link = ObjectPoolFindOrCreateObject(editor.Links, id); @@ -2520,83 +2632,106 @@ void PushColorStyle(const ImNodesCol item, unsigned int color) void PopColorStyle() { - assert(GImNodes->ColorModifierStack.size() > 0); + IM_ASSERT(GImNodes->ColorModifierStack.size() > 0); const ImNodesColElement elem = GImNodes->ColorModifierStack.back(); GImNodes->Style.Colors[elem.Item] = elem.Color; GImNodes->ColorModifierStack.pop_back(); } -float& LookupStyleVar(const ImNodesStyleVar item) +struct ImNodesStyleVarInfo { - // TODO: once the switch gets too big and unwieldy to work with, we could do - // a byte-offset lookup into the Style struct, using the StyleVar as an - // index. This is how ImGui does it. - float* style_var = 0; - switch (item) - { - case ImNodesStyleVar_GridSpacing: - style_var = &GImNodes->Style.GridSpacing; - break; - case ImNodesStyleVar_NodeCornerRounding: - style_var = &GImNodes->Style.NodeCornerRounding; - break; - case ImNodesStyleVar_NodePaddingHorizontal: - style_var = &GImNodes->Style.NodePaddingHorizontal; - break; - case ImNodesStyleVar_NodePaddingVertical: - style_var = &GImNodes->Style.NodePaddingVertical; - break; - case ImNodesStyleVar_NodeBorderThickness: - style_var = &GImNodes->Style.NodeBorderThickness; - break; - case ImNodesStyleVar_LinkThickness: - style_var = &GImNodes->Style.LinkThickness; - break; - case ImNodesStyleVar_LinkLineSegmentsPerLength: - style_var = &GImNodes->Style.LinkLineSegmentsPerLength; - break; - case ImNodesStyleVar_LinkHoverDistance: - style_var = &GImNodes->Style.LinkHoverDistance; - break; - case ImNodesStyleVar_PinCircleRadius: - style_var = &GImNodes->Style.PinCircleRadius; - break; - case ImNodesStyleVar_PinQuadSideLength: - style_var = &GImNodes->Style.PinQuadSideLength; - break; - case ImNodesStyleVar_PinTriangleSideLength: - style_var = &GImNodes->Style.PinTriangleSideLength; - break; - case ImNodesStyleVar_PinLineThickness: - style_var = &GImNodes->Style.PinLineThickness; - break; - case ImNodesStyleVar_PinHoverRadius: - style_var = &GImNodes->Style.PinHoverRadius; - break; - case ImNodesStyleVar_PinOffset: - style_var = &GImNodes->Style.PinOffset; - break; - default: - assert(!"Invalid StyleVar value!"); - } + ImGuiDataType Type; + ImU32 Count; + ImU32 Offset; + void* GetVarPtr(ImNodesStyle* style) const { return (void*)((unsigned char*)style + Offset); } +}; - return *style_var; +static const ImNodesStyleVarInfo GStyleVarInfo[] = { + // ImNodesStyleVar_GridSpacing + {ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImNodesStyle, GridSpacing)}, + // ImNodesStyleVar_NodeCornerRounding + {ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImNodesStyle, NodeCornerRounding)}, + // ImNodesStyleVar_NodePadding + {ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImNodesStyle, NodePadding)}, + // ImNodesStyleVar_NodeBorderThickness + {ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImNodesStyle, NodeBorderThickness)}, + // ImNodesStyleVar_LinkThickness + {ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImNodesStyle, LinkThickness)}, + // ImNodesStyleVar_LinkLineSegmentsPerLength + {ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImNodesStyle, LinkLineSegmentsPerLength)}, + // ImNodesStyleVar_LinkHoverDistance + {ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImNodesStyle, LinkHoverDistance)}, + // ImNodesStyleVar_PinCircleRadius + {ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImNodesStyle, PinCircleRadius)}, + // ImNodesStyleVar_PinQuadSideLength + {ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImNodesStyle, PinQuadSideLength)}, + // ImNodesStyleVar_PinTriangleSideLength + {ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImNodesStyle, PinTriangleSideLength)}, + // ImNodesStyleVar_PinLineThickness + {ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImNodesStyle, PinLineThickness)}, + // ImNodesStyleVar_PinHoverRadius + {ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImNodesStyle, PinHoverRadius)}, + // ImNodesStyleVar_PinOffset + {ImGuiDataType_Float, 1, (ImU32)IM_OFFSETOF(ImNodesStyle, PinOffset)}, + // ImNodesStyleVar_MiniMapPadding + {ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImNodesStyle, MiniMapPadding)}, + // ImNodesStyleVar_MiniMapOffset + {ImGuiDataType_Float, 2, (ImU32)IM_OFFSETOF(ImNodesStyle, MiniMapOffset)}, +}; + +static const ImNodesStyleVarInfo* GetStyleVarInfo(ImNodesStyleVar idx) +{ + IM_ASSERT(idx >= 0 && idx < ImNodesStyleVar_COUNT); + IM_ASSERT(IM_ARRAYSIZE(GStyleVarInfo) == ImNodesStyleVar_COUNT); + return &GStyleVarInfo[idx]; } void PushStyleVar(const ImNodesStyleVar item, const float value) { - float& style_var = LookupStyleVar(item); - GImNodes->StyleModifierStack.push_back(ImNodesStyleVarElement(style_var, item)); - style_var = value; + const ImNodesStyleVarInfo* var_info = GetStyleVarInfo(item); + if (var_info->Type == ImGuiDataType_Float && var_info->Count == 1) + { + float& style_var = *(float*)var_info->GetVarPtr(&GImNodes->Style); + GImNodes->StyleModifierStack.push_back(ImNodesStyleVarElement(item, style_var)); + style_var = value; + return; + } + IM_ASSERT(0 && "Called PushStyleVar() float variant but variable is not a float!"); } -void PopStyleVar() +void PushStyleVar(const ImNodesStyleVar item, const ImVec2& value) { - assert(GImNodes->StyleModifierStack.size() > 0); - const ImNodesStyleVarElement style_elem = GImNodes->StyleModifierStack.back(); - GImNodes->StyleModifierStack.pop_back(); - float& style_var = LookupStyleVar(style_elem.Item); - style_var = style_elem.Value; + const ImNodesStyleVarInfo* var_info = GetStyleVarInfo(item); + if (var_info->Type == ImGuiDataType_Float && var_info->Count == 2) + { + ImVec2& style_var = *(ImVec2*)var_info->GetVarPtr(&GImNodes->Style); + GImNodes->StyleModifierStack.push_back(ImNodesStyleVarElement(item, style_var)); + style_var = value; + return; + } + IM_ASSERT(0 && "Called PushStyleVar() ImVec2 variant but variable is not a ImVec2!"); +} + +void PopStyleVar(int count) +{ + while (count > 0) + { + IM_ASSERT(GImNodes->StyleModifierStack.size() > 0); + const ImNodesStyleVarElement style_backup = GImNodes->StyleModifierStack.back(); + GImNodes->StyleModifierStack.pop_back(); + const ImNodesStyleVarInfo* var_info = GetStyleVarInfo(style_backup.Item); + void* style_var = var_info->GetVarPtr(&GImNodes->Style); + if (var_info->Type == ImGuiDataType_Float && var_info->Count == 1) + { + ((float*)style_var)[0] = style_backup.FloatValue[0]; + } + else if (var_info->Type == ImGuiDataType_Float && var_info->Count == 2) + { + ((float*)style_var)[0] = style_backup.FloatValue[0]; + ((float*)style_var)[1] = style_backup.FloatValue[1]; + } + count--; + } } void SetNodeScreenSpacePos(const int node_id, const ImVec2& screen_space_pos) @@ -2631,7 +2766,7 @@ ImVec2 GetNodeScreenSpacePos(const int node_id) { ImNodesEditorContext& editor = EditorContextGet(); const int node_idx = ObjectPoolFind(editor.Nodes, node_id); - assert(node_idx != -1); + IM_ASSERT(node_idx != -1); ImNodeData& node = editor.Nodes.Pool[node_idx]; return GridSpaceToScreenSpace(editor, node.Origin); } @@ -2640,7 +2775,7 @@ ImVec2 GetNodeEditorSpacePos(const int node_id) { ImNodesEditorContext& editor = EditorContextGet(); const int node_idx = ObjectPoolFind(editor.Nodes, node_id); - assert(node_idx != -1); + IM_ASSERT(node_idx != -1); ImNodeData& node = editor.Nodes.Pool[node_idx]; return GridSpaceToEditorSpace(editor, node.Origin); } @@ -2649,17 +2784,24 @@ ImVec2 GetNodeGridSpacePos(const int node_id) { ImNodesEditorContext& editor = EditorContextGet(); const int node_idx = ObjectPoolFind(editor.Nodes, node_id); - assert(node_idx != -1); + IM_ASSERT(node_idx != -1); ImNodeData& node = editor.Nodes.Pool[node_idx]; return node.Origin; } +void SnapNodeToGrid(int node_id) +{ + ImNodesEditorContext& editor = EditorContextGet(); + ImNodeData& node = ObjectPoolFindOrCreateObject(editor.Nodes, node_id); + node.Origin = SnapOriginToGrid(node.Origin); +} + bool IsEditorHovered() { return MouseInCanvas(); } bool IsNodeHovered(int* const node_id) { - assert(GImNodes->CurrentScope == ImNodesScope_None); - assert(node_id != NULL); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_None); + IM_ASSERT(node_id != NULL); const bool is_hovered = GImNodes->HoveredNodeIdx.HasValue(); if (is_hovered) @@ -2672,8 +2814,8 @@ bool IsNodeHovered(int* const node_id) bool IsLinkHovered(int* const link_id) { - assert(GImNodes->CurrentScope == ImNodesScope_None); - assert(link_id != NULL); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_None); + IM_ASSERT(link_id != NULL); const bool is_hovered = GImNodes->HoveredLinkIdx.HasValue(); if (is_hovered) @@ -2686,8 +2828,8 @@ bool IsLinkHovered(int* const link_id) bool IsPinHovered(int* const attr) { - assert(GImNodes->CurrentScope == ImNodesScope_None); - assert(attr != NULL); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_None); + IM_ASSERT(attr != NULL); const bool is_hovered = GImNodes->HoveredPinIdx.HasValue(); if (is_hovered) @@ -2700,21 +2842,21 @@ bool IsPinHovered(int* const attr) int NumSelectedNodes() { - assert(GImNodes->CurrentScope == ImNodesScope_None); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_None); const ImNodesEditorContext& editor = EditorContextGet(); return editor.SelectedNodeIndices.size(); } int NumSelectedLinks() { - assert(GImNodes->CurrentScope == ImNodesScope_None); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_None); const ImNodesEditorContext& editor = EditorContextGet(); return editor.SelectedLinkIndices.size(); } void GetSelectedNodes(int* node_ids) { - assert(node_ids != NULL); + IM_ASSERT(node_ids != NULL); const ImNodesEditorContext& editor = EditorContextGet(); for (int i = 0; i < editor.SelectedNodeIndices.size(); ++i) @@ -2726,7 +2868,7 @@ void GetSelectedNodes(int* node_ids) void GetSelectedLinks(int* link_ids) { - assert(link_ids != NULL); + IM_ASSERT(link_ids != NULL); const ImNodesEditorContext& editor = EditorContextGet(); for (int i = 0; i < editor.SelectedLinkIndices.size(); ++i) @@ -2786,7 +2928,7 @@ bool IsLinkSelected(int link_id) bool IsAttributeActive() { - assert((GImNodes->CurrentScope & ImNodesScope_Node) != 0); + IM_ASSERT((GImNodes->CurrentScope & ImNodesScope_Node) != 0); if (!GImNodes->ActiveAttribute) { @@ -2798,7 +2940,7 @@ bool IsAttributeActive() bool IsAnyAttributeActive(int* const attribute_id) { - assert((GImNodes->CurrentScope & (ImNodesScope_Node | ImNodesScope_Attribute)) == 0); + IM_ASSERT((GImNodes->CurrentScope & (ImNodesScope_Node | ImNodesScope_Attribute)) == 0); if (!GImNodes->ActiveAttribute) { @@ -2816,8 +2958,8 @@ bool IsAnyAttributeActive(int* const attribute_id) bool IsLinkStarted(int* const started_at_id) { // Call this function after EndNodeEditor()! - assert(GImNodes->CurrentScope == ImNodesScope_None); - assert(started_at_id != NULL); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_None); + IM_ASSERT(started_at_id != NULL); const bool is_started = (GImNodes->ImNodesUIState & ImNodesUIState_LinkStarted) != 0; if (is_started) @@ -2833,7 +2975,7 @@ bool IsLinkStarted(int* const started_at_id) bool IsLinkDropped(int* const started_at_id, const bool including_detached_links) { // Call this function after EndNodeEditor()! - assert(GImNodes->CurrentScope == ImNodesScope_None); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_None); const ImNodesEditorContext& editor = EditorContextGet(); @@ -2856,9 +2998,9 @@ bool IsLinkCreated( int* const ended_at_pin_id, bool* const created_from_snap) { - assert(GImNodes->CurrentScope == ImNodesScope_None); - assert(started_at_pin_id != NULL); - assert(ended_at_pin_id != NULL); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_None); + IM_ASSERT(started_at_pin_id != NULL); + IM_ASSERT(ended_at_pin_id != NULL); const bool is_created = (GImNodes->ImNodesUIState & ImNodesUIState_LinkCreated) != 0; @@ -2898,11 +3040,11 @@ bool IsLinkCreated( int* ended_at_pin_id, bool* created_from_snap) { - assert(GImNodes->CurrentScope == ImNodesScope_None); - assert(started_at_node_id != NULL); - assert(started_at_pin_id != NULL); - assert(ended_at_node_id != NULL); - assert(ended_at_pin_id != NULL); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_None); + IM_ASSERT(started_at_node_id != NULL); + IM_ASSERT(started_at_pin_id != NULL); + IM_ASSERT(ended_at_node_id != NULL); + IM_ASSERT(ended_at_pin_id != NULL); const bool is_created = (GImNodes->ImNodesUIState & ImNodesUIState_LinkCreated) != 0; @@ -2943,7 +3085,7 @@ bool IsLinkCreated( bool IsLinkDestroyed(int* const link_id) { - assert(GImNodes->CurrentScope == ImNodesScope_None); + IM_ASSERT(GImNodes->CurrentScope == ImNodesScope_None); const bool link_destroyed = GImNodes->DeletedLinkIdx.HasValue(); if (link_destroyed) @@ -2972,7 +3114,7 @@ void NodeLineHandler(ImNodesEditorContext& editor, const char* const line) else if (sscanf(line, "origin=%i,%i", &x, &y) == 2) { ImNodeData& node = editor.Nodes.Pool[GImNodes->CurrentNodeIdx]; - node.Origin = ImVec2((float)x, (float)y); + node.Origin = SnapOriginToGrid(ImVec2((float)x, (float)y)); } } @@ -2991,7 +3133,7 @@ const char* SaveEditorStateToIniString( const ImNodesEditorContext* const editor_ptr, size_t* const data_size) { - assert(editor_ptr != NULL); + IM_ASSERT(editor_ptr != NULL); const ImNodesEditorContext& editor = *editor_ptr; GImNodes->TextBuffer.clear(); @@ -3120,4 +3262,4 @@ void LoadEditorStateFromIniFile(ImNodesEditorContext* const editor, const char* LoadEditorStateFromIniString(editor, file_data, data_size); ImGui::MemFree(file_data); } -} // namespace ImNodes +} // namespace IMNODES_NAMESPACE diff --git a/lib/external/imgui/source/implot.cpp b/lib/external/imgui/source/implot.cpp index d6d3fbf05..aea9dbaa7 100644 --- a/lib/external/imgui/source/implot.cpp +++ b/lib/external/imgui/source/implot.cpp @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -// ImPlot v0.11 WIP +// ImPlot v0.13 WIP /* @@ -31,6 +31,43 @@ Below is a change-log of API breaking changes only. If you are using one of the When you are not sure about a old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all implot files. You can read releases logs https://github.com/epezent/implot/releases for more details. +- 2021/10/19 (0.13) MAJOR API OVERHAUL! + - TRIVIAL RENAME: + - ImPlotLimits -> ImPlotRect + - ImPlotYAxis_ -> ImAxis_ + - SetPlotYAxis -> SetAxis + - BeginDragDropTarget -> BeginDragDropTargetPlot + - BeginDragDropSource -> BeginDragDropSourcePlot + - ImPlotFlags_NoMousePos -> ImPlotFlags_NoMouseText + - SetNextPlotLimits -> SetNextAxesLimits + - SetMouseTextLocation -> SetupMouseText + - SIGNATURE MODIFIED: + - PixelsToPlot/PlotToPixels -> added optional X-Axis arg + - GetPlotMousePos -> added optional X-Axis arg + - GetPlotLimits -> added optional X-Axis arg + - GetPlotSelection -> added optional X-Axis arg + - DragLineX/Y/DragPoint -> now takes int id; removed labels (render with Annotation/Tag instead) + - REPLACED: + - IsPlotXAxisHovered/IsPlotXYAxisHovered -> IsAxisHovered(ImAxis) + - BeginDragDropTargetX/BeginDragDropTargetY -> BeginDragDropTargetAxis(ImAxis) + - BeginDragDropSourceX/BeginDragDropSourceY -> BeginDragDropSourceAxis(ImAxis) + - ImPlotCol_XAxis, ImPlotCol_YAxis1, etc. -> ImPlotCol_AxisText (push/pop this around SetupAxis to style individual axes) + - ImPlotCol_XAxisGrid, ImPlotCol_Y1AxisGrid -> ImPlotCol_AxisGrid (push/pop this around SetupAxis to style individual axes) + - SetNextPlotLimitsX/Y -> SetNextAxisLimits(ImAxis) + - LinkNextPlotLimits -> SetNextAxisLinks(ImAxis) + - FitNextPlotAxes -> SetNextAxisToFit(ImAxis)/SetNextAxesToFit + - SetLegendLocation -> SetupLegend + - ImPlotFlags_NoHighlight -> ImPlotLegendFlags_NoHighlight + - ImPlotOrientation -> ImPlotLegendFlags_Horizontal + - Annotate -> Annotation + - REMOVED: + - GetPlotQuery, SetPlotQuery, IsPlotQueried -> use DragRect + - SetNextPlotTicksX, SetNextPlotTicksY -> use SetupAxisTicks + - SetNextPlotFormatX, SetNextPlotFormatY -> use SetupAxisFormat + - AnnotateClamped -> use Annotation(bool clamp = true) + - OBSOLETED: + - BeginPlot (original signature) -> use simplified signature + Setup API +- 2021/07/30 (0.12) - The offset argument of `PlotXG` functions was been removed. Implement offsetting in your getter callback instead. - 2021/03/08 (0.9) - SetColormap and PushColormap(ImVec4*) were removed. Use AddColormap for custom colormap support. LerpColormap was changed to SampleColormap. ShowColormapScale was changed to ColormapScale and requires additional arguments. - 2021/03/07 (0.9) - The signature of ShowColormapScale was modified to accept a ImVec2 size. @@ -74,35 +111,36 @@ You can read releases logs https://github.com/epezent/implot/releases for more d #include "implot.h" #include "implot_internal.h" -#ifdef _MSC_VER -#define sprintf sprintf_s -#endif +#include // Support for pre-1.82 versions. Users on 1.82+ can use 0 (default) flags to mean "all corners" but in order to support older versions we are more explicit. #if (IMGUI_VERSION_NUM < 18102) && !defined(ImDrawFlags_RoundCornersAll) #define ImDrawFlags_RoundCornersAll ImDrawCornerFlags_All #endif +// Visual Studio warnings +#ifdef _MSC_VER +#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen +#endif + +// Clang/GCC warnings with -Weverything +#if defined(__clang__) +#pragma clang diagnostic ignored "-Wformat-nonliteral" // warning: format string is not a string literal +#elif defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wformat-nonliteral" // warning: format not a string literal, format string not checked +#endif + // Global plot context +#ifndef GImPlot ImPlotContext* GImPlot = NULL; +#endif //----------------------------------------------------------------------------- // Struct Implementations //----------------------------------------------------------------------------- ImPlotInputMap::ImPlotInputMap() { - PanButton = ImGuiMouseButton_Left; - PanMod = ImGuiKeyModFlags_None; - FitButton = ImGuiMouseButton_Left; - ContextMenuButton = ImGuiMouseButton_Right; - BoxSelectButton = ImGuiMouseButton_Right; - BoxSelectMod = ImGuiKeyModFlags_None; - BoxSelectCancelButton = ImGuiMouseButton_Left; - QueryButton = ImGuiMouseButton_Middle; - QueryMod = ImGuiKeyModFlags_None; - QueryToggleMod = ImGuiKeyModFlags_Ctrl; - HorizontalMod = ImGuiKeyModFlags_Alt; - VerticalMod = ImGuiKeyModFlags_Shift; + ImPlot::MapInputDefault(this); } ImPlotStyle::ImPlotStyle() { @@ -153,7 +191,7 @@ ImPlotStyle::ImPlotStyle() { namespace ImPlot { const char* GetStyleColorName(ImPlotCol col) { - static const char* col_names[] = { + static const char* col_names[ImPlotCol_COUNT] = { "Line", "Fill", "MarkerOutline", @@ -167,16 +205,13 @@ const char* GetStyleColorName(ImPlotCol col) { "LegendText", "TitleText", "InlayText", - "XAxis", - "XAxisGrid", - "YAxis", - "YAxisGrid", - "YAxis2", - "YAxisGrid2", - "YAxis3", - "YAxisGrid3", + "AxisText", + "AxisGrid", + "AxisTick", + "AxisBg", + "AxisBgHovered", + "AxisBgActive", "Selection", - "Query", "Crosshairs" }; return col_names[col]; @@ -215,16 +250,13 @@ ImVec4 GetAutoColor(ImPlotCol idx) { case ImPlotCol_LegendText: return GetStyleColorVec4(ImPlotCol_InlayText); case ImPlotCol_TitleText: return ImGui::GetStyleColorVec4(ImGuiCol_Text); case ImPlotCol_InlayText: return ImGui::GetStyleColorVec4(ImGuiCol_Text); - case ImPlotCol_XAxis: return ImGui::GetStyleColorVec4(ImGuiCol_Text); - case ImPlotCol_XAxisGrid: return GetStyleColorVec4(ImPlotCol_XAxis) * ImVec4(1,1,1,0.25f); - case ImPlotCol_YAxis: return ImGui::GetStyleColorVec4(ImGuiCol_Text); - case ImPlotCol_YAxisGrid: return GetStyleColorVec4(ImPlotCol_YAxis) * ImVec4(1,1,1,0.25f); - case ImPlotCol_YAxis2: return ImGui::GetStyleColorVec4(ImGuiCol_Text); - case ImPlotCol_YAxisGrid2: return GetStyleColorVec4(ImPlotCol_YAxis2) * ImVec4(1,1,1,0.25f); - case ImPlotCol_YAxis3: return ImGui::GetStyleColorVec4(ImGuiCol_Text); - case ImPlotCol_YAxisGrid3: return GetStyleColorVec4(ImPlotCol_YAxis3) * ImVec4(1,1,1,0.25f); + case ImPlotCol_AxisText: return ImGui::GetStyleColorVec4(ImGuiCol_Text); + case ImPlotCol_AxisGrid: return GetStyleColorVec4(ImPlotCol_AxisText) * ImVec4(1,1,1,0.25f); + case ImPlotCol_AxisTick: return GetStyleColorVec4(ImPlotCol_AxisGrid); + case ImPlotCol_AxisBg: return ImVec4(0,0,0,0); + case ImPlotCol_AxisBgHovered: return ImGui::GetStyleColorVec4(ImGuiCol_ButtonHovered); + case ImPlotCol_AxisBgActive: return ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive); case ImPlotCol_Selection: return ImVec4(1,1,0,1); - case ImPlotCol_Query: return ImVec4(0,1,0,1); case ImPlotCol_Crosshairs: return GetStyleColorVec4(ImPlotCol_PlotBorder); default: return col; } @@ -339,10 +371,10 @@ void AddTextCentered(ImDrawList* DrawList, ImVec2 top_center, ImU32 col, const c } double NiceNum(double x, bool round) { - double f; /* fractional part of x */ - double nf; /* nice, rounded fraction */ + double f; + double nf; int expv = (int)floor(ImLog10(x)); - f = x / ImPow(10.0, (double)expv); /* between 1 and 10 */ + f = x / ImPow(10.0, (double)expv); if (round) if (f < 1.5) nf = 1; @@ -436,7 +468,6 @@ void Initialize(ImPlotContext* ctx) { IMPLOT_APPEND_CMAP(PiYG, false); IMPLOT_APPEND_CMAP(Spectral, false); IMPLOT_APPEND_CMAP(Greys, false); - } void ResetCtxForNextPlot(ImPlotContext* ctx) { @@ -447,22 +478,11 @@ void ResetCtxForNextPlot(ImPlotContext* ctx) { // reset the next plot/item data ctx->NextPlotData.Reset(); ctx->NextItemData.Reset(); - // reset ticks/labels - ctx->XTicks.Reset(); - for (int i = 0; i < 3; ++i) - ctx->YTicks[i].Reset(); // reset labels ctx->Annotations.Reset(); + ctx->Tags.Reset(); // reset extents/fit - ctx->FitThisFrame = false; - ctx->FitX = false; - ctx->ExtentsX.Min = HUGE_VAL; - ctx->ExtentsX.Max = -HUGE_VAL; - for (int i = 0; i < IMPLOT_Y_AXES; i++) { - ctx->ExtentsY[i].Min = HUGE_VAL; - ctx->ExtentsY[i].Max = -HUGE_VAL; - ctx->FitY[i] = false; - } + ctx->OpenContextThisFrame = false; // reset digital plot items count ctx->DigitalPlotItemCnt = 0; ctx->DigitalPlotOffset = 0; @@ -502,84 +522,6 @@ void BustPlotCache() { GImPlot->Subplots.Clear(); } -void PushLinkedAxis(ImPlotAxis& axis) { - if (axis.LinkedMin) { *axis.LinkedMin = axis.Range.Min; } - if (axis.LinkedMax) { *axis.LinkedMax = axis.Range.Max; } -} - -void PullLinkedAxis(ImPlotAxis& axis) { - if (axis.LinkedMin) { axis.SetMin(*axis.LinkedMin,true); } - if (axis.LinkedMax) { axis.SetMax(*axis.LinkedMax,true); } -} - -//----------------------------------------------------------------------------- -// Coordinate Utils -//----------------------------------------------------------------------------- - -void UpdateTransformCache() { - ImPlotContext& gp = *GImPlot; - ImPlotPlot& plot = *gp.CurrentPlot; - // get pixels for transforms - for (int i = 0; i < IMPLOT_Y_AXES; i++) { - gp.PixelRange[i] = ImRect(plot.XAxis.IsInverted() ? plot.PlotRect.Max.x : plot.PlotRect.Min.x, - plot.YAxis[i].IsInverted() ? plot.PlotRect.Min.y : plot.PlotRect.Max.y, - plot.XAxis.IsInverted() ? plot.PlotRect.Min.x : plot.PlotRect.Max.x, - plot.YAxis[i].IsInverted() ? plot.PlotRect.Max.y : plot.PlotRect.Min.y); - gp.My[i] = (gp.PixelRange[i].Max.y - gp.PixelRange[i].Min.y) / plot.YAxis[i].Range.Size(); - } - gp.LogDenX = plot.XAxis.IsLog() ? ImLog10(plot.XAxis.Range.Max / plot.XAxis.Range.Min) : 0; - for (int i = 0; i < IMPLOT_Y_AXES; i++) - gp.LogDenY[i] = plot.YAxis[i].IsLog() ? ImLog10(plot.YAxis[i].Range.Max / plot.YAxis[i].Range.Min) : 0; - gp.Mx = (gp.PixelRange[0].Max.x - gp.PixelRange[0].Min.x) / plot.XAxis.Range.Size(); -} - -ImPlotPoint PixelsToPlot(float x, float y, ImPlotYAxis y_axis_in) { - ImPlotContext& gp = *GImPlot; - ImPlotPlot& plot = *gp.CurrentPlot; - IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "PixelsToPlot() needs to be called between BeginPlot() and EndPlot()!"); - const ImPlotYAxis y_axis = y_axis_in >= 0 ? y_axis_in : plot.CurrentYAxis; - ImPlotPoint plt; - plt.x = (x - gp.PixelRange[y_axis].Min.x) / gp.Mx + plot.XAxis.Range.Min; - plt.y = (y - gp.PixelRange[y_axis].Min.y) / gp.My[y_axis] + plot.YAxis[y_axis].Range.Min; - if (ImHasFlag(plot.XAxis.Flags, ImPlotAxisFlags_LogScale)) { - double t = (plt.x - plot.XAxis.Range.Min) / plot.XAxis.Range.Size(); - plt.x = ImPow(10, t * gp.LogDenX) * plot.XAxis.Range.Min; - } - if (ImHasFlag(plot.YAxis[y_axis].Flags, ImPlotAxisFlags_LogScale)) { - double t = (plt.y - plot.YAxis[y_axis].Range.Min) / plot.YAxis[y_axis].Range.Size(); - plt.y = ImPow(10, t * gp.LogDenY[y_axis]) * plot.YAxis[y_axis].Range.Min; - } - return plt; -} - -ImPlotPoint PixelsToPlot(const ImVec2& pix, ImPlotYAxis y_axis) { - return PixelsToPlot(pix.x, pix.y, y_axis); -} - -ImVec2 PlotToPixels(double x, double y, ImPlotYAxis y_axis_in) { - ImPlotContext& gp = *GImPlot; - IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "PlotToPixels() needs to be called between BeginPlot() and EndPlot()!"); - const ImPlotYAxis y_axis = y_axis_in >= 0 ? y_axis_in : gp.CurrentPlot->CurrentYAxis; - ImVec2 pix; - if (ImHasFlag(gp.CurrentPlot->XAxis.Flags, ImPlotAxisFlags_LogScale)) { - x = x <= 0.0 ? IMPLOT_LOG_ZERO : x; - double t = ImLog10(x / gp.CurrentPlot->XAxis.Range.Min) / gp.LogDenX; - x = ImLerp(gp.CurrentPlot->XAxis.Range.Min, gp.CurrentPlot->XAxis.Range.Max, (float)t); - } - if (ImHasFlag(gp.CurrentPlot->YAxis[y_axis].Flags, ImPlotAxisFlags_LogScale)) { - y = y <= 0.0 ? IMPLOT_LOG_ZERO : y; - double t = ImLog10(y / gp.CurrentPlot->YAxis[y_axis].Range.Min) / gp.LogDenY[y_axis]; - y = ImLerp(gp.CurrentPlot->YAxis[y_axis].Range.Min, gp.CurrentPlot->YAxis[y_axis].Range.Max, (float)t); - } - pix.x = (float)(gp.PixelRange[y_axis].Min.x + gp.Mx * (x - gp.CurrentPlot->XAxis.Range.Min)); - pix.y = (float)(gp.PixelRange[y_axis].Min.y + gp.My[y_axis] * (y - gp.CurrentPlot->YAxis[y_axis].Range.Min)); - return pix; -} - -ImVec2 PlotToPixels(const ImPlotPoint& plt, ImPlotYAxis y_axis) { - return PlotToPixels(plt.x, plt.y, y_axis); -} - //----------------------------------------------------------------------------- // Legend Utils //----------------------------------------------------------------------------- @@ -604,7 +546,7 @@ ImVec2 GetLocationPos(const ImRect& outer_rect, const ImVec2& inner_size, ImPlot return pos; } -ImVec2 CalcLegendSize(ImPlotItemGroup& items, const ImVec2& pad, const ImVec2& spacing, ImPlotOrientation orn) { +ImVec2 CalcLegendSize(ImPlotItemGroup& items, const ImVec2& pad, const ImVec2& spacing, bool vertical) { // vars const int nItems = items.GetLegendCount(); const float txt_ht = ImGui::GetTextLineHeight(); @@ -619,14 +561,22 @@ ImVec2 CalcLegendSize(ImPlotItemGroup& items, const ImVec2& pad, const ImVec2& s sum_label_width += label_width; } // calc legend size - const ImVec2 legend_size = orn == ImPlotOrientation_Vertical ? + const ImVec2 legend_size = vertical ? ImVec2(pad.x * 2 + icon_size + max_label_width, pad.y * 2 + nItems * txt_ht + (nItems - 1) * spacing.y) : ImVec2(pad.x * 2 + icon_size * nItems + sum_label_width + (nItems - 1) * spacing.x, pad.y * 2 + txt_ht); return legend_size; } -bool ShowLegendEntries(ImPlotItemGroup& items, const ImRect& legend_bb, bool hovered, const ImVec2& pad, const ImVec2& spacing, ImPlotOrientation orn, ImDrawList& DrawList) { - ImGuiIO& IO = ImGui::GetIO(); +int LegendSortingComp(void* _items, const void* _a, const void* _b) { + ImPlotItemGroup* items = (ImPlotItemGroup*)_items; + const int a = *(const int*)_a; + const int b = *(const int*)_b; + const char* label_a = items->GetLegendLabel(a); + const char* label_b = items->GetLegendLabel(b); + return strcmp(label_a,label_b); +} + +bool ShowLegendEntries(ImPlotItemGroup& items, const ImRect& legend_bb, bool hovered, const ImVec2& pad, const ImVec2& spacing, bool vertical, ImDrawList& DrawList) { // vars const float txt_ht = ImGui::GetTextLineHeight(); const float icon_size = txt_ht; @@ -636,13 +586,28 @@ bool ShowLegendEntries(ImPlotItemGroup& items, const ImRect& legend_bb, bool hov // render each legend item float sum_label_width = 0; bool any_item_hovered = false; - for (int i = 0; i < items.GetLegendCount(); ++i) { - ImPlotItem* item = items.GetLegendItem(i); - const char* label = items.GetLegendLabel(i); + + const int num_items = items.GetLegendCount(); + if (num_items < 1) + return hovered; + // ImVector& indices = GImPlot->TempInt1; + // indices.resize(num_items); + // // bool sort = true; + // // if (sort && num_items > 1) { + // // qsort_s(indices.Data, num_items, sizeof(int), LegendSortingComp, &items); + // // } + // // else { + // // for (int i = 0; i < num_items; ++i) + // // indices[i] = i; + // // } + for (int i = 0; i < num_items; ++i) { + const int idx = i; //indices[i]; + ImPlotItem* item = items.GetLegendItem(idx); + const char* label = items.GetLegendLabel(idx); const float label_width = ImGui::CalcTextSize(label, NULL, true).x; - const ImVec2 top_left = orn == ImPlotOrientation_Vertical ? - legend_bb.Min + pad + ImVec2(0, i * (txt_ht + spacing.y)) : - legend_bb.Min + pad + ImVec2(i * (icon_size + spacing.x) + sum_label_width, 0); + const ImVec2 top_left = vertical ? + legend_bb.Min + pad + ImVec2(0, i * (txt_ht + spacing.y)) : + legend_bb.Min + pad + ImVec2(i * (icon_size + spacing.x) + sum_label_width, 0); sum_label_width += label_width; ImRect icon_bb; icon_bb.Min = top_left + ImVec2(icon_shrink,icon_shrink); @@ -653,16 +618,27 @@ bool ShowLegendEntries(ImPlotItemGroup& items, const ImRect& legend_bb, bool hov ImU32 col_txt_hl; ImU32 col_item = ImAlphaU32(item->Color,1); - // ImGui::ItemAdd(icon_bb, item->ID, &icon_bb); - // ImGui::KeepAliveID(item->ID); + ImRect button_bb(icon_bb.Min, label_bb.Max); - bool icon_hov = false; - bool icon_hld = false; - bool icon_clk = ImGui::ButtonBehavior(icon_bb, item->ID, &icon_hov, &icon_hld); - if (icon_clk) + ImGui::KeepAliveID(item->ID); + + bool item_hov = false; + bool item_hld = false; + bool item_clk = ImHasFlag(items.Legend.Flags, ImPlotLegendFlags_NoButtons) + ? false + : ImGui::ButtonBehavior(button_bb, item->ID, &item_hov, &item_hld); + + if (item_clk) item->Show = !item->Show; - if (icon_hov || label_bb.Contains(IO.MousePos)) { + + const bool can_hover = (item_hov) + && (!ImHasFlag(items.Legend.Flags, ImPlotLegendFlags_NoHighlightItem) + || !ImHasFlag(items.Legend.Flags, ImPlotLegendFlags_NoHighlightAxis)); + + if (can_hover) { + item->LegendHoverRect.Min = icon_bb.Min; + item->LegendHoverRect.Max = label_bb.Max; item->LegendHovered = true; col_txt_hl = ImMixU32(col_txt, col_item, 64); any_item_hovered = true; @@ -671,14 +647,14 @@ bool ShowLegendEntries(ImPlotItemGroup& items, const ImRect& legend_bb, bool hov col_txt_hl = ImGui::GetColorU32(col_txt); } ImU32 col_icon; - if (icon_hld) + if (item_hld) col_icon = item->Show ? ImAlphaU32(col_item,0.5f) : ImGui::GetColorU32(ImGuiCol_TextDisabled, 0.5f); - else if (icon_hov) + else if (item_hov) col_icon = item->Show ? ImAlphaU32(col_item,0.75f) : ImGui::GetColorU32(ImGuiCol_TextDisabled, 0.75f); else col_icon = item->Show ? col_item : col_txt_dis; - DrawList.AddRectFilled(icon_bb.Min, icon_bb.Max, col_icon, 1); + DrawList.AddRectFilled(icon_bb.Min, icon_bb.Max, col_icon); const char* text_display_end = ImGui::FindRenderedTextEnd(label, NULL); if (label != text_display_end) DrawList.AddText(top_left + ImVec2(icon_size, 0), item->Show ? col_txt_hl : col_txt_dis, label, text_display_end); @@ -690,22 +666,20 @@ bool ShowLegendEntries(ImPlotItemGroup& items, const ImRect& legend_bb, bool hov // Tick Utils //----------------------------------------------------------------------------- -void AddTicksDefault(const ImPlotRange& range, float pix, ImPlotOrientation orn, ImPlotTickCollection& ticks, const char* fmt) { +static const float TICK_FILL_X = 0.8f; +static const float TICK_FILL_Y = 1.0f; + +void AddTicksDefault(const ImPlotRange& range, float pix, bool vertical, ImPlotTickCollection& ticks, ImPlotFormatter formatter, void* data) { const int idx0 = ticks.Size; const int nMinor = 10; - const int nMajor = ImMax(2, (int)IM_ROUND(pix / (orn == ImPlotOrientation_Horizontal ? 400.0f : 300.0f))); + const int nMajor = ImMax(2, (int)IM_ROUND(pix / (vertical ? 300.0f : 400.0f))); const double nice_range = NiceNum(range.Size() * 0.99, false); const double interval = NiceNum(nice_range / (nMajor - 1), true); const double graphmin = floor(range.Min / interval) * interval; const double graphmax = ceil(range.Max / interval) * interval; bool first_major_set = false; int first_major_idx = 0; - - char dummy[32]; - sprintf(dummy,fmt,-ImAbs(interval / nMinor)); - ImVec2 dummy_size = ImGui::CalcTextSize(dummy); ImVec2 total_size(0,0); - for (double major = graphmin; major < graphmax + 0.5 * interval; major += interval) { // is this zero? combat zero formatting issues if (major-interval < 0 && major+interval > 0) @@ -715,19 +689,17 @@ void AddTicksDefault(const ImPlotRange& range, float pix, ImPlotOrientation orn, first_major_idx = ticks.Size; first_major_set = true; } - ticks.Append(major, true, true, fmt); - total_size += dummy_size; + total_size += ticks.Append(major, true, true, formatter, data).LabelSize; } for (int i = 1; i < nMinor; ++i) { double minor = major + i * interval / nMinor; if (range.Contains(minor)) { - ticks.Append(minor, false, true, fmt); - total_size += dummy_size; + total_size += ticks.Append(minor, false, true, formatter, data).LabelSize; } } } // prune if necessary - if ((orn == ImPlotOrientation_Horizontal && total_size.x > pix) || (orn == ImPlotOrientation_Vertical && total_size.y > pix)) { + if ((!vertical && total_size.x > pix*TICK_FILL_X) || (vertical && total_size.y > pix*TICK_FILL_Y)) { for (int i = first_major_idx-1; i >= idx0; i -= 2) ticks.Ticks[i].ShowLabel = false; for (int i = first_major_idx+1; i < ticks.Size; i += 2) @@ -735,10 +707,10 @@ void AddTicksDefault(const ImPlotRange& range, float pix, ImPlotOrientation orn, } } -void AddTicksLogarithmic(const ImPlotRange& range, float pix, ImPlotOrientation orn, ImPlotTickCollection& ticks, const char* fmt) { +void AddTicksLogarithmic(const ImPlotRange& range, float pix, bool vertical, ImPlotTickCollection& ticks, ImPlotFormatter formatter, void* data) { if (range.Min <= 0 || range.Max <= 0) return; - const int nMajor = orn == ImPlotOrientation_Horizontal ? ImMax(2, (int)IM_ROUND(pix * 0.01f)) : ImMax(2, (int)IM_ROUND(pix * 0.02f)); + const int nMajor = vertical ? ImMax(2, (int)IM_ROUND(pix * 0.02f)) : ImMax(2, (int)IM_ROUND(pix * 0.01f)); double log_min = ImLog10(range.Min); double log_max = ImLog10(range.Max); int exp_step = ImMax(1,(int)(log_max - log_min) / nMajor); @@ -753,7 +725,7 @@ void AddTicksLogarithmic(const ImPlotRange& range, float pix, ImPlotOrientation double major2 = ImPow(10, (double)(e + 1)); double interval = (major2 - major1) / 9; if (major1 >= (range.Min - DBL_EPSILON) && major1 <= (range.Max + DBL_EPSILON)) - ticks.Append(major1, true, true, fmt); + ticks.Append(major1, true, true, formatter, data); for (int j = 0; j < exp_step; ++j) { major1 = ImPow(10, (double)(e+j)); major2 = ImPow(10, (double)(e+j+1)); @@ -761,14 +733,14 @@ void AddTicksLogarithmic(const ImPlotRange& range, float pix, ImPlotOrientation for (int i = 1; i < (9 + (int)(j < (exp_step - 1))); ++i) { double minor = major1 + i * interval; if (minor >= (range.Min - DBL_EPSILON) && minor <= (range.Max + DBL_EPSILON)) - ticks.Append(minor, false, false, fmt); + ticks.Append(minor, false, false, formatter, data); } } } } -void AddTicksCustom(const double* values, const char* const labels[], int n, ImPlotTickCollection& ticks, const char* fmt) { +void AddTicksCustom(const double* values, const char* const labels[], int n, ImPlotTickCollection& ticks, ImPlotFormatter formatter, void* data) { for (int i = 0; i < n; ++i) { if (labels != NULL) { ImPlotTick tick(values[i], false, true); @@ -778,7 +750,7 @@ void AddTicksCustom(const double* values, const char* const labels[], int n, ImP ticks.Append(tick); } else { - ticks.Append(values[i], false, true, fmt); + ticks.Append(values[i], false, true, formatter, data); } } } @@ -1008,6 +980,7 @@ ImPlotTime CombineDateTime(const ImPlotTime& date_part, const ImPlotTime& tod_pa return t; } +// TODO: allow users to define these static const char* MONTH_NAMES[] = {"January","February","March","April","May","June","July","August","September","October","November","December"}; static const char* WD_ABRVS[] = {"Su","Mo","Tu","We","Th","Fr","Sa"}; static const char* MONTH_ABRVS[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; @@ -1022,14 +995,14 @@ int FormatTime(const ImPlotTime& t, char* buffer, int size, ImPlotTimeFmt fmt, b if (use_24_hr_clk) { const int hr = Tm.tm_hour; switch(fmt) { - case ImPlotTimeFmt_Us: return snprintf(buffer, size, ".%03d %03d", ms, us); - case ImPlotTimeFmt_SUs: return snprintf(buffer, size, ":%02d.%03d %03d", sec, ms, us); - case ImPlotTimeFmt_SMs: return snprintf(buffer, size, ":%02d.%03d", sec, ms); - case ImPlotTimeFmt_S: return snprintf(buffer, size, ":%02d", sec); - case ImPlotTimeFmt_HrMinSMs: return snprintf(buffer, size, "%02d:%02d:%02d.%03d", hr, min, sec, ms); - case ImPlotTimeFmt_HrMinS: return snprintf(buffer, size, "%02d:%02d:%02d", hr, min, sec); - case ImPlotTimeFmt_HrMin: return snprintf(buffer, size, "%02d:%02d", hr, min); - case ImPlotTimeFmt_Hr: return snprintf(buffer, size, "%02d:00", hr); + case ImPlotTimeFmt_Us: return ImFormatString(buffer, size, ".%03d %03d", ms, us); + case ImPlotTimeFmt_SUs: return ImFormatString(buffer, size, ":%02d.%03d %03d", sec, ms, us); + case ImPlotTimeFmt_SMs: return ImFormatString(buffer, size, ":%02d.%03d", sec, ms); + case ImPlotTimeFmt_S: return ImFormatString(buffer, size, ":%02d", sec); + case ImPlotTimeFmt_HrMinSMs: return ImFormatString(buffer, size, "%02d:%02d:%02d.%03d", hr, min, sec, ms); + case ImPlotTimeFmt_HrMinS: return ImFormatString(buffer, size, "%02d:%02d:%02d", hr, min, sec); + case ImPlotTimeFmt_HrMin: return ImFormatString(buffer, size, "%02d:%02d", hr, min); + case ImPlotTimeFmt_Hr: return ImFormatString(buffer, size, "%02d:00", hr); default: return 0; } } @@ -1037,14 +1010,14 @@ int FormatTime(const ImPlotTime& t, char* buffer, int size, ImPlotTimeFmt fmt, b const char* ap = Tm.tm_hour < 12 ? "am" : "pm"; const int hr = (Tm.tm_hour == 0 || Tm.tm_hour == 12) ? 12 : Tm.tm_hour % 12; switch(fmt) { - case ImPlotTimeFmt_Us: return snprintf(buffer, size, ".%03d %03d", ms, us); - case ImPlotTimeFmt_SUs: return snprintf(buffer, size, ":%02d.%03d %03d", sec, ms, us); - case ImPlotTimeFmt_SMs: return snprintf(buffer, size, ":%02d.%03d", sec, ms); - case ImPlotTimeFmt_S: return snprintf(buffer, size, ":%02d", sec); - case ImPlotTimeFmt_HrMinSMs: return snprintf(buffer, size, "%d:%02d:%02d.%03d%s", hr, min, sec, ms, ap); - case ImPlotTimeFmt_HrMinS: return snprintf(buffer, size, "%d:%02d:%02d%s", hr, min, sec, ap); - case ImPlotTimeFmt_HrMin: return snprintf(buffer, size, "%d:%02d%s", hr, min, ap); - case ImPlotTimeFmt_Hr: return snprintf(buffer, size, "%d%s", hr, ap); + case ImPlotTimeFmt_Us: return ImFormatString(buffer, size, ".%03d %03d", ms, us); + case ImPlotTimeFmt_SUs: return ImFormatString(buffer, size, ":%02d.%03d %03d", sec, ms, us); + case ImPlotTimeFmt_SMs: return ImFormatString(buffer, size, ":%02d.%03d", sec, ms); + case ImPlotTimeFmt_S: return ImFormatString(buffer, size, ":%02d", sec); + case ImPlotTimeFmt_HrMinSMs: return ImFormatString(buffer, size, "%d:%02d:%02d.%03d%s", hr, min, sec, ms, ap); + case ImPlotTimeFmt_HrMinS: return ImFormatString(buffer, size, "%d:%02d:%02d%s", hr, min, sec, ap); + case ImPlotTimeFmt_HrMin: return ImFormatString(buffer, size, "%d:%02d%s", hr, min, ap); + case ImPlotTimeFmt_Hr: return ImFormatString(buffer, size, "%d%s", hr, ap); default: return 0; } } @@ -1059,21 +1032,21 @@ int FormatDate(const ImPlotTime& t, char* buffer, int size, ImPlotDateFmt fmt, b const int yr = year % 100; if (use_iso_8601) { switch (fmt) { - case ImPlotDateFmt_DayMo: return snprintf(buffer, size, "--%02d-%02d", mon, day); - case ImPlotDateFmt_DayMoYr: return snprintf(buffer, size, "%d-%02d-%02d", year, mon, day); - case ImPlotDateFmt_MoYr: return snprintf(buffer, size, "%d-%02d", year, mon); - case ImPlotDateFmt_Mo: return snprintf(buffer, size, "--%02d", mon); - case ImPlotDateFmt_Yr: return snprintf(buffer, size, "%d", year); + case ImPlotDateFmt_DayMo: return ImFormatString(buffer, size, "--%02d-%02d", mon, day); + case ImPlotDateFmt_DayMoYr: return ImFormatString(buffer, size, "%d-%02d-%02d", year, mon, day); + case ImPlotDateFmt_MoYr: return ImFormatString(buffer, size, "%d-%02d", year, mon); + case ImPlotDateFmt_Mo: return ImFormatString(buffer, size, "--%02d", mon); + case ImPlotDateFmt_Yr: return ImFormatString(buffer, size, "%d", year); default: return 0; } } else { switch (fmt) { - case ImPlotDateFmt_DayMo: return snprintf(buffer, size, "%d/%d", mon, day); - case ImPlotDateFmt_DayMoYr: return snprintf(buffer, size, "%d/%d/%02d", mon, day, yr); - case ImPlotDateFmt_MoYr: return snprintf(buffer, size, "%s %d", MONTH_ABRVS[Tm.tm_mon], year); - case ImPlotDateFmt_Mo: return snprintf(buffer, size, "%s", MONTH_ABRVS[Tm.tm_mon]); - case ImPlotDateFmt_Yr: return snprintf(buffer, size, "%d", year); + case ImPlotDateFmt_DayMo: return ImFormatString(buffer, size, "%d/%d", mon, day); + case ImPlotDateFmt_DayMoYr: return ImFormatString(buffer, size, "%d/%d/%02d", mon, day, yr); + case ImPlotDateFmt_MoYr: return ImFormatString(buffer, size, "%s %d", MONTH_ABRVS[Tm.tm_mon], year); + case ImPlotDateFmt_Mo: return ImFormatString(buffer, size, "%s", MONTH_ABRVS[Tm.tm_mon]); + case ImPlotDateFmt_Yr: return ImFormatString(buffer, size, "%d", year); default: return 0; } } @@ -1263,388 +1236,6 @@ void AddTicksTime(const ImPlotRange& range, float plot_width, ImPlotTickCollecti } } -//----------------------------------------------------------------------------- -// Axis Utils -//----------------------------------------------------------------------------- - -static inline int AxisPrecision(const ImPlotAxis& axis, const ImPlotTickCollection& ticks) { - const double range = ticks.Size > 1 ? (ticks.Ticks[1].PlotPos - ticks.Ticks[0].PlotPos) : axis.Range.Size(); - return Precision(range); -} - -static inline double RoundAxisValue(const ImPlotAxis& axis, const ImPlotTickCollection& ticks, double value) { - return RoundTo(value, AxisPrecision(axis,ticks)); -} - -int LabelAxisValue(const ImPlotAxis& axis, const ImPlotTickCollection& ticks, double value, char* buff, int size) { - ImPlotContext& gp = *GImPlot; - if (ImHasFlag(axis.Flags, ImPlotAxisFlags_Time)) { - ImPlotTimeUnit unit = (axis.Orientation == ImPlotOrientation_Horizontal) - ? GetUnitForRange(axis.Range.Size() / (gp.CurrentPlot->PlotRect.GetWidth() / 100)) - : GetUnitForRange(axis.Range.Size() / (gp.CurrentPlot->PlotRect.GetHeight() / 100)); - return FormatDateTime(ImPlotTime::FromDouble(value), buff, size, GetDateTimeFmt(TimeFormatMouseCursor, unit)); - } - else { - double range = ticks.Size > 1 ? (ticks.Ticks[1].PlotPos - ticks.Ticks[0].PlotPos) : axis.Range.Size(); - return snprintf(buff, size, "%.*f", Precision(range), value); - } -} - -void UpdateAxisColors(int axis_flag, ImPlotAxis* axis) { - const ImVec4 col_label = GetStyleColorVec4(axis_flag); - const ImVec4 col_grid = GetStyleColorVec4(axis_flag + 1); - axis->ColorMaj = ImGui::GetColorU32(col_grid); - axis->ColorMin = ImGui::GetColorU32(col_grid*ImVec4(1,1,1,GImPlot->Style.MinorAlpha)); - axis->ColorTxt = ImGui::GetColorU32(col_label); -} - -//----------------------------------------------------------------------------- -// RENDERING -//----------------------------------------------------------------------------- - -static inline void RenderGridLinesX(ImDrawList& DrawList, const ImPlotTickCollection& ticks, const ImRect& rect, ImU32 col_maj, ImU32 col_min, float size_maj, float size_min) { - const float density = ticks.Size / rect.GetWidth(); - ImVec4 col_min4 = ImGui::ColorConvertU32ToFloat4(col_min); - col_min4.w *= ImClamp(ImRemap(density, 0.1f, 0.2f, 1.0f, 0.0f), 0.0f, 1.0f); - col_min = ImGui::ColorConvertFloat4ToU32(col_min4); - for (int t = 0; t < ticks.Size; t++) { - const ImPlotTick& xt = ticks.Ticks[t]; - if (xt.Level == 0) { - if (xt.Major) - DrawList.AddLine(ImVec2(xt.PixelPos, rect.Min.y), ImVec2(xt.PixelPos, rect.Max.y), col_maj, size_maj); - else if (density < 0.2f) - DrawList.AddLine(ImVec2(xt.PixelPos, rect.Min.y), ImVec2(xt.PixelPos, rect.Max.y), col_min, size_min); - } - } -} - -static inline void RenderGridLinesY(ImDrawList& DrawList, const ImPlotTickCollection& ticks, const ImRect& rect, ImU32 col_maj, ImU32 col_min, float size_maj, float size_min) { - const float density = ticks.Size / rect.GetHeight(); - ImVec4 col_min4 = ImGui::ColorConvertU32ToFloat4(col_min); - col_min4.w *= ImClamp(ImRemap(density, 0.1f, 0.2f, 1.0f, 0.0f), 0.0f, 1.0f); - col_min = ImGui::ColorConvertFloat4ToU32(col_min4); - for (int t = 0; t < ticks.Size; t++) { - const ImPlotTick& yt = ticks.Ticks[t]; - if (yt.Major) - DrawList.AddLine(ImVec2(rect.Min.x, yt.PixelPos), ImVec2(rect.Max.x, yt.PixelPos), col_maj, size_maj); - else if (density < 0.2f) - DrawList.AddLine(ImVec2(rect.Min.x, yt.PixelPos), ImVec2(rect.Max.x, yt.PixelPos), col_min, size_min); - } -} - -static inline void RenderSelectionRect(ImDrawList& DrawList, const ImVec2& p_min, const ImVec2& p_max, const ImVec4& col) { - const ImU32 col_bg = ImGui::GetColorU32(col * ImVec4(1,1,1,0.25f)); - const ImU32 col_bd = ImGui::GetColorU32(col); - DrawList.AddRectFilled(p_min, p_max, col_bg); - DrawList.AddRect(p_min, p_max, col_bd); -} - -//----------------------------------------------------------------------------- -// Input Handling -//----------------------------------------------------------------------------- - -void HandlePlotInput(ImPlotPlot& plot) { - - ImGuiContext& G = *GImGui; - ImPlotContext& gp = *GImPlot; - ImGuiIO& IO = ImGui::GetIO(); - - const bool any_hov_y_axis_region = plot.YAxis[0].AllHovered || plot.YAxis[1].AllHovered || plot.YAxis[2].AllHovered; - - bool hov_query = false; - if (plot.PlotHovered && plot.Queried && !plot.Querying) { - ImRect bb_query = plot.QueryRect; - bb_query.Min += plot.PlotRect.Min; - bb_query.Max += plot.PlotRect.Min; - hov_query = bb_query.Contains(IO.MousePos); - } - - // QUERY DRAG ------------------------------------------------------------- - - if (plot.DraggingQuery && (IO.MouseReleased[gp.InputMap.PanButton] || !IO.MouseDown[gp.InputMap.PanButton])) { - plot.DraggingQuery = false; - } - if (plot.DraggingQuery) { - ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeAll); - plot.QueryRect.Min += IO.MouseDelta; - plot.QueryRect.Max += IO.MouseDelta; - } - if (plot.PlotHovered && hov_query && !plot.DraggingQuery && !plot.Selecting && !plot.Items.Legend.Hovered) { - ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeAll); - const bool any_y_dragging = plot.YAxis[0].Dragging || plot.YAxis[1].Dragging || plot.YAxis[2].Dragging; - if (IO.MouseDown[gp.InputMap.PanButton] && !plot.XAxis.Dragging && !any_y_dragging) { - plot.DraggingQuery = true; - } - } - - // DRAG INPUT ------------------------------------------------------------- - - const bool axis_equal = ImHasFlag(plot.Flags, ImPlotFlags_Equal); - - // end drags - if (plot.XAxis.Dragging && (IO.MouseReleased[gp.InputMap.PanButton] || !IO.MouseDown[gp.InputMap.PanButton])) { - plot.XAxis.Dragging = false; - G.IO.MouseDragMaxDistanceSqr[0] = 0; - } - for (int i = 0; i < IMPLOT_Y_AXES; i++) { - if (plot.YAxis[i].Dragging && (IO.MouseReleased[gp.InputMap.PanButton] || !IO.MouseDown[gp.InputMap.PanButton])) { - plot.YAxis[i].Dragging = false; - G.IO.MouseDragMaxDistanceSqr[0] = 0; - } - } - const bool any_y_dragging = plot.YAxis[0].Dragging || plot.YAxis[1].Dragging || plot.YAxis[2].Dragging; - bool drag_in_progress = plot.XAxis.Dragging || any_y_dragging; - // do drag - if (drag_in_progress) { - UpdateTransformCache(); - bool equal_dragged = false; - // special case for axis equal and both x and y0 hovered - if (axis_equal && !plot.XAxis.IsInputLocked() && plot.XAxis.Dragging && !plot.YAxis[0].IsInputLocked() && plot.YAxis[0].Dragging) { - ImPlotPoint plot_tl = PixelsToPlot(plot.PlotRect.Min - IO.MouseDelta, 0); - ImPlotPoint plot_br = PixelsToPlot(plot.PlotRect.Max - IO.MouseDelta, 0); - plot.XAxis.SetMin(plot.XAxis.IsInverted() ? plot_br.x : plot_tl.x); - plot.XAxis.SetMax(plot.XAxis.IsInverted() ? plot_tl.x : plot_br.x); - plot.YAxis[0].SetMin(plot.YAxis[0].IsInverted() ? plot_tl.y : plot_br.y); - plot.YAxis[0].SetMax(plot.YAxis[0].IsInverted() ? plot_br.y : plot_tl.y); - double xar = plot.XAxis.GetAspect(); - double yar = plot.YAxis[0].GetAspect(); - if (!ImAlmostEqual(xar,yar) && !plot.YAxis[0].IsInputLocked()) - plot.XAxis.SetAspect(yar); - equal_dragged = true; - } - if (!plot.XAxis.IsInputLocked() && plot.XAxis.Dragging && !equal_dragged) { - ImPlotPoint plot_tl = PixelsToPlot(plot.PlotRect.Min - IO.MouseDelta, 0); - ImPlotPoint plot_br = PixelsToPlot(plot.PlotRect.Max - IO.MouseDelta, 0); - plot.XAxis.SetMin(plot.XAxis.IsInverted() ? plot_br.x : plot_tl.x); - plot.XAxis.SetMax(plot.XAxis.IsInverted() ? plot_tl.x : plot_br.x); - if (axis_equal) - plot.YAxis[0].SetAspect(plot.XAxis.GetAspect()); - } - for (int i = 0; i < IMPLOT_Y_AXES; i++) { - if (!plot.YAxis[i].IsInputLocked() && plot.YAxis[i].Dragging && !(i == 0 && equal_dragged)) { - ImPlotPoint plot_tl = PixelsToPlot(plot.PlotRect.Min - IO.MouseDelta, i); - ImPlotPoint plot_br = PixelsToPlot(plot.PlotRect.Max - IO.MouseDelta, i); - plot.YAxis[i].SetMin(plot.YAxis[i].IsInverted() ? plot_tl.y : plot_br.y); - plot.YAxis[i].SetMax(plot.YAxis[i].IsInverted() ? plot_br.y : plot_tl.y); - if (i == 0 && axis_equal) - plot.XAxis.SetAspect(plot.YAxis[0].GetAspect()); - } - } - // Set the mouse cursor based on which axes are moving. - int direction = 0; - if (!plot.XAxis.IsInputLocked() && plot.XAxis.Dragging) { - direction |= (1 << 1); - } - for (int i = 0; i < IMPLOT_Y_AXES; i++) { - if (!plot.YAxis[i].Present) { continue; } - if (!plot.YAxis[i].IsInputLocked() && plot.YAxis[i].Dragging) { - direction |= (1 << 2); - break; - } - } - if (IO.MouseDragMaxDistanceSqr[0] > 5) { - if (direction == 0) - ImGui::SetMouseCursor(ImGuiMouseCursor_NotAllowed); - else if (direction == (1 << 1)) - ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeEW); - else if (direction == (1 << 2)) - ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNS); - else - ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeAll); - } - } - // start drag - if (!drag_in_progress && plot.FrameHovered && IO.MouseClicked[gp.InputMap.PanButton] && ImHasFlag(IO.KeyMods, gp.InputMap.PanMod) && !plot.Selecting && !plot.Items.Legend.Hovered && !hov_query && !plot.DraggingQuery) { - if (plot.XAxis.AllHovered) { - plot.XAxis.Dragging = true; - } - for (int i = 0; i < IMPLOT_Y_AXES; i++) { - if (plot.YAxis[i].AllHovered) { - plot.YAxis[i].Dragging = true; - } - } - } - - // SCROLL INPUT ----------------------------------------------------------- - - if (plot.FrameHovered && (plot.XAxis.AllHovered || any_hov_y_axis_region) && IO.MouseWheel != 0) { - UpdateTransformCache(); - float zoom_rate = IMPLOT_ZOOM_RATE; - if (IO.MouseWheel > 0) - zoom_rate = (-zoom_rate) / (1.0f + (2.0f * zoom_rate)); - float tx = ImRemap(IO.MousePos.x, plot.PlotRect.Min.x, plot.PlotRect.Max.x, 0.0f, 1.0f); - float ty = ImRemap(IO.MousePos.y, plot.PlotRect.Min.y, plot.PlotRect.Max.y, 0.0f, 1.0f); - bool equal_zoomed = false; - // special case for axis equal and both x and y0 hovered - if (axis_equal && plot.XAxis.AllHovered && !plot.XAxis.IsInputLocked() && plot.YAxis[0].AllHovered && !plot.YAxis[0].IsInputLocked()) { - const ImPlotPoint& plot_tl = PixelsToPlot(plot.PlotRect.Min - plot.PlotRect.GetSize() * ImVec2(tx * zoom_rate, ty * zoom_rate), 0); - const ImPlotPoint& plot_br = PixelsToPlot(plot.PlotRect.Max + plot.PlotRect.GetSize() * ImVec2((1 - tx) * zoom_rate, (1 - ty) * zoom_rate), 0); - plot.XAxis.SetMin(plot.XAxis.IsInverted() ? plot_br.x : plot_tl.x); - plot.XAxis.SetMax(plot.XAxis.IsInverted() ? plot_tl.x : plot_br.x); - plot.YAxis[0].SetMin(plot.YAxis[0].IsInverted() ? plot_tl.y : plot_br.y); - plot.YAxis[0].SetMax(plot.YAxis[0].IsInverted() ? plot_br.y : plot_tl.y); - double xar = plot.XAxis.GetAspect(); - double yar = plot.YAxis[0].GetAspect(); - if (!ImAlmostEqual(xar,yar) && !plot.YAxis[0].IsInputLocked()) - plot.XAxis.SetAspect(yar); - equal_zoomed = true; - } - if (plot.XAxis.AllHovered && !plot.XAxis.IsInputLocked() && !equal_zoomed) { - const ImPlotPoint& plot_tl = PixelsToPlot(plot.PlotRect.Min - plot.PlotRect.GetSize() * ImVec2(tx * zoom_rate, ty * zoom_rate), 0); - const ImPlotPoint& plot_br = PixelsToPlot(plot.PlotRect.Max + plot.PlotRect.GetSize() * ImVec2((1 - tx) * zoom_rate, (1 - ty) * zoom_rate), 0); - plot.XAxis.SetMin(plot.XAxis.IsInverted() ? plot_br.x : plot_tl.x); - plot.XAxis.SetMax(plot.XAxis.IsInverted() ? plot_tl.x : plot_br.x); - if (axis_equal) - plot.YAxis[0].SetAspect(plot.XAxis.GetAspect()); - } - for (int i = 0; i < IMPLOT_Y_AXES; i++) { - if (plot.YAxis[i].AllHovered && !plot.YAxis[i].IsInputLocked() && !(i == 0 && equal_zoomed)) { - const ImPlotPoint& plot_tl = PixelsToPlot(plot.PlotRect.Min - plot.PlotRect.GetSize() * ImVec2(tx * zoom_rate, ty * zoom_rate), i); - const ImPlotPoint& plot_br = PixelsToPlot(plot.PlotRect.Max + plot.PlotRect.GetSize() * ImVec2((1 - tx) * zoom_rate, (1 - ty) * zoom_rate), i); - plot.YAxis[i].SetMin(plot.YAxis[i].IsInverted() ? plot_tl.y : plot_br.y); - plot.YAxis[i].SetMax(plot.YAxis[i].IsInverted() ? plot_br.y : plot_tl.y); - if (i == 0 && axis_equal) - plot.XAxis.SetAspect(plot.YAxis[0].GetAspect()); - } - } - } - - // BOX-SELECTION AND QUERY ------------------------------------------------ - - // begin selection - if (!ImHasFlag(plot.Flags, ImPlotFlags_NoBoxSelect) && plot.PlotHovered && IO.MouseClicked[gp.InputMap.BoxSelectButton] && ImHasFlag(IO.KeyMods, gp.InputMap.BoxSelectMod)) { - plot.Selecting = true; - plot.SelectStart = IO.MousePos; - plot.SelectRect = ImRect(0,0,0,0); - } - // update selection - if (plot.Selecting) { - UpdateTransformCache(); - const ImVec2 d = plot.SelectStart - IO.MousePos; - const bool x_can_change = !ImHasFlag(IO.KeyMods,gp.InputMap.HorizontalMod) && ImFabs(d.x) > 2; - const bool y_can_change = !ImHasFlag(IO.KeyMods,gp.InputMap.VerticalMod) && ImFabs(d.y) > 2; - // confirm - if (IO.MouseReleased[gp.InputMap.BoxSelectButton] || !IO.MouseDown[gp.InputMap.BoxSelectButton]) { - if (!plot.XAxis.IsInputLocked() && x_can_change) { - ImPlotPoint p1 = PixelsToPlot(plot.SelectStart); - ImPlotPoint p2 = PixelsToPlot(IO.MousePos); - plot.XAxis.SetMin(ImMin(p1.x, p2.x)); - plot.XAxis.SetMax(ImMax(p1.x, p2.x)); - } - for (int i = 0; i < IMPLOT_Y_AXES; i++) { - if (!plot.YAxis[i].IsInputLocked() && y_can_change) { - ImPlotPoint p1 = PixelsToPlot(plot.SelectStart, i); - ImPlotPoint p2 = PixelsToPlot(IO.MousePos, i); - plot.YAxis[i].SetMin(ImMin(p1.y, p2.y)); - plot.YAxis[i].SetMax(ImMax(p1.y, p2.y)); - } - } - if (x_can_change || y_can_change || (ImHasFlag(IO.KeyMods,gp.InputMap.HorizontalMod) && ImHasFlag(IO.KeyMods,gp.InputMap.VerticalMod))) - plot.ContextLocked = gp.InputMap.BoxSelectButton == gp.InputMap.ContextMenuButton; - plot.Selected = plot.Selecting = false; - } - // cancel - else if (IO.MouseClicked[gp.InputMap.BoxSelectCancelButton] || IO.MouseDown[gp.InputMap.BoxSelectCancelButton]) { - plot.Selected = plot.Selecting = false; - plot.ContextLocked = gp.InputMap.BoxSelectButton == gp.InputMap.ContextMenuButton; - } - else if (ImLengthSqr(d) > 4) { - // bad selection - if (plot.IsInputLocked()) { - ImGui::SetMouseCursor(ImGuiMouseCursor_NotAllowed); - plot.ContextLocked = gp.InputMap.BoxSelectButton == gp.InputMap.ContextMenuButton; - plot.Selected = false; - } - else { - // TODO: Handle only min or max locked cases - plot.SelectRect.Min.x = ImHasFlag(IO.KeyMods, gp.InputMap.HorizontalMod) || plot.XAxis.IsInputLocked() ? plot.PlotRect.Min.x : ImMin(plot.SelectStart.x, IO.MousePos.x); - plot.SelectRect.Max.x = ImHasFlag(IO.KeyMods, gp.InputMap.HorizontalMod) || plot.XAxis.IsInputLocked() ? plot.PlotRect.Max.x : ImMax(plot.SelectStart.x, IO.MousePos.x); - plot.SelectRect.Min.y = ImHasFlag(IO.KeyMods, gp.InputMap.VerticalMod) || plot.AllYInputLocked() ? plot.PlotRect.Min.y : ImMin(plot.SelectStart.y, IO.MousePos.y); - plot.SelectRect.Max.y = ImHasFlag(IO.KeyMods, gp.InputMap.VerticalMod) || plot.AllYInputLocked() ? plot.PlotRect.Max.y : ImMax(plot.SelectStart.y, IO.MousePos.y); - plot.SelectRect.Min -= plot.PlotRect.Min; - plot.SelectRect.Max -= plot.PlotRect.Min; - plot.Selected = true; - } - } - else { - plot.Selected = false; - } - } - - // begin query - if (ImHasFlag(plot.Flags, ImPlotFlags_Query) && plot.PlotHovered && IO.MouseClicked[gp.InputMap.QueryButton] && ImHasFlag(IO.KeyMods, gp.InputMap.QueryMod)) { - plot.Querying = true; - plot.QueryStart = IO.MousePos; - plot.QueryRect = ImRect(0,0,0,0); - } - // update query - if (plot.Querying) { - UpdateTransformCache(); - // confirm - if (IO.MouseReleased[gp.InputMap.QueryButton] || IO.MouseReleased[gp.InputMap.BoxSelectButton]) { - plot.Querying = false; - if (plot.QueryRect.GetWidth() > 2 && plot.QueryRect.GetHeight() > 2) { - plot.Queried = true; - plot.ContextLocked = gp.InputMap.BoxSelectButton == gp.InputMap.ContextMenuButton; - } - else - plot.Queried = false; - } - else { - plot.QueryRect.Min.x = ImHasFlag(IO.KeyMods, gp.InputMap.HorizontalMod) ? plot.PlotRect.Min.x : ImMin(plot.QueryStart.x, IO.MousePos.x); - plot.QueryRect.Max.x = ImHasFlag(IO.KeyMods, gp.InputMap.HorizontalMod) ? plot.PlotRect.Max.x : ImMax(plot.QueryStart.x, IO.MousePos.x); - plot.QueryRect.Min.y = ImHasFlag(IO.KeyMods, gp.InputMap.VerticalMod) ? plot.PlotRect.Min.y : ImMin(plot.QueryStart.y, IO.MousePos.y); - plot.QueryRect.Max.y = ImHasFlag(IO.KeyMods, gp.InputMap.VerticalMod) ? plot.PlotRect.Max.y : ImMax(plot.QueryStart.y, IO.MousePos.y); - plot.QueryRect.Min -= plot.PlotRect.Min; - plot.QueryRect.Max -= plot.PlotRect.Min; - plot.Queried = plot.QueryRect.GetWidth() > 2 && plot.QueryRect.GetHeight() > 2; - } - } - - // switch select to query - if (ImHasFlag(plot.Flags, ImPlotFlags_Query) && plot.Selecting && ImHasFlag(IO.KeyMods,gp.InputMap.QueryToggleMod)) { - plot.Selecting = plot.Selected = false; - plot.Querying = plot.Queried = true; - plot.QueryStart = plot.SelectStart; - plot.QueryRect = plot.SelectRect; - - } - // switch query to select - if (!ImHasFlag(plot.Flags, ImPlotFlags_NoBoxSelect) && plot.Querying && !ImHasFlag(IO.KeyMods, gp.InputMap.QueryToggleMod) && !IO.MouseDown[gp.InputMap.QueryButton]) { - plot.Selecting = plot.Selected = true; - plot.Querying = plot.Queried = false; - plot.SelectStart = plot.QueryStart; - plot.SelectRect = plot.QueryRect; - } - - // FIT ----------------------------------------------------------- - - // fit from double click - if ( IO.MouseDoubleClicked[gp.InputMap.FitButton] && plot.FrameHovered && (plot.XAxis.AllHovered || any_hov_y_axis_region) && !plot.Items.Legend.Hovered && !hov_query ) { - gp.FitThisFrame = true; - gp.FitX = plot.XAxis.AllHovered; - for (int i = 0; i < IMPLOT_Y_AXES; i++) - gp.FitY[i] = plot.YAxis[i].AllHovered; - } - // fit from FitNextPlotAxes or auto fit - if (gp.NextPlotData.FitX || ImHasFlag(plot.XAxis.Flags, ImPlotAxisFlags_AutoFit)) { - gp.FitThisFrame = true; - gp.FitX = true; - } - for (int i = 0; i < IMPLOT_Y_AXES; ++i) { - if (gp.NextPlotData.FitY[i] || ImHasFlag(plot.YAxis[i].Flags, ImPlotAxisFlags_AutoFit)) { - gp.FitThisFrame = true; - gp.FitY[i] = true; - } - } - - // FOCUS ------------------------------------------------------------------ - - // focus window - if ((IO.MouseClicked[0] || IO.MouseClicked[1] || IO.MouseClicked[2]) && plot.FrameHovered) - ImGui::FocusWindow(ImGui::GetCurrentWindow()); -} - //----------------------------------------------------------------------------- // Context Menu //----------------------------------------------------------------------------- @@ -1682,10 +1273,10 @@ void ShowAxisContextMenu(ImPlotAxis& axis, ImPlotAxis* equal_axis, bool time_all ImGui::PushItemWidth(75); bool always_locked = axis.IsRangeLocked() || axis.IsAutoFitting(); - bool label = !ImHasFlag(axis.Flags, ImPlotAxisFlags_NoLabel); - bool grid = !ImHasFlag(axis.Flags, ImPlotAxisFlags_NoGridLines); - bool ticks = !ImHasFlag(axis.Flags, ImPlotAxisFlags_NoTickMarks); - bool labels = !ImHasFlag(axis.Flags, ImPlotAxisFlags_NoTickLabels); + bool label = axis.HasLabel(); + bool grid = axis.HasGridLines(); + bool ticks = axis.HasTickMarks(); + bool labels = axis.HasTickLabels(); double drag_speed = (axis.Range.Size() <= DBL_EPSILON) ? DBL_EPSILON * 1.0e+13 : 0.01 * axis.Range.Size(); // recover from almost equal axis limits. if (axis.IsTime()) { @@ -1767,40 +1358,43 @@ void ShowAxisContextMenu(ImPlotAxis& axis, ImPlotAxis* equal_axis, bool time_all ImGui::Separator(); ImGui::CheckboxFlags("Auto-Fit",(unsigned int*)&axis.Flags, ImPlotAxisFlags_AutoFit); - ImGui::CheckboxFlags("Invert",(unsigned int*)&axis.Flags, ImPlotAxisFlags_Invert); BeginDisabledControls(axis.IsTime() && time_allowed); ImGui::CheckboxFlags("Log Scale",(unsigned int*)&axis.Flags, ImPlotAxisFlags_LogScale); EndDisabledControls(axis.IsTime() && time_allowed); - if (time_allowed) { BeginDisabledControls(axis.IsLog()); ImGui::CheckboxFlags("Time",(unsigned int*)&axis.Flags, ImPlotAxisFlags_Time); EndDisabledControls(axis.IsLog()); } - ImGui::Separator(); + ImGui::CheckboxFlags("Invert",(unsigned int*)&axis.Flags, ImPlotAxisFlags_Invert); + ImGui::CheckboxFlags("Opposite",(unsigned int*)&axis.Flags, ImPlotAxisFlags_Opposite); + ImGui::Separator(); + BeginDisabledControls(axis.LabelOffset == -1); if (ImGui::Checkbox("Label", &label)) ImFlipFlag(axis.Flags, ImPlotAxisFlags_NoLabel); + EndDisabledControls(axis.LabelOffset == -1); if (ImGui::Checkbox("Grid Lines", &grid)) ImFlipFlag(axis.Flags, ImPlotAxisFlags_NoGridLines); if (ImGui::Checkbox("Tick Marks", &ticks)) ImFlipFlag(axis.Flags, ImPlotAxisFlags_NoTickMarks); if (ImGui::Checkbox("Tick Labels", &labels)) ImFlipFlag(axis.Flags, ImPlotAxisFlags_NoTickLabels); + } -bool ShowLegendContextMenu(ImPlotLegendData& legend, bool visible) { +bool ShowLegendContextMenu(ImPlotLegend& legend, bool visible) { const float s = ImGui::GetFrameHeight(); bool ret = false; if (ImGui::Checkbox("Show",&visible)) ret = true; if (legend.CanGoInside) - ImGui::Checkbox("Outside", &legend.Outside); - if (ImGui::RadioButton("H", legend.Orientation == ImPlotOrientation_Horizontal)) - legend.Orientation = ImPlotOrientation_Horizontal; + ImGui::CheckboxFlags("Outside",(unsigned int*)&legend.Flags, ImPlotLegendFlags_Outside); + if (ImGui::RadioButton("H", ImHasFlag(legend.Flags, ImPlotLegendFlags_Horizontal))) + legend.Flags |= ImPlotLegendFlags_Horizontal; ImGui::SameLine(); - if (ImGui::RadioButton("V", legend.Orientation == ImPlotOrientation_Vertical)) - legend.Orientation = ImPlotOrientation_Vertical; + if (ImGui::RadioButton("V", !ImHasFlag(legend.Flags, ImPlotLegendFlags_Horizontal))) + legend.Flags &= ~ImPlotLegendFlags_Horizontal; ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(2,2)); if (ImGui::Button("NW",ImVec2(1.5f*s,s))) { legend.Location = ImPlotLocation_NorthWest; } ImGui::SameLine(); if (ImGui::Button("N", ImVec2(1.5f*s,s))) { legend.Location = ImPlotLocation_North; } ImGui::SameLine(); @@ -1827,16 +1421,11 @@ void ShowSubplotsContextMenu(ImPlotSubplot& subplot) { ImFlipFlag(subplot.Flags, ImPlotSubplotFlags_LinkAllY); ImGui::EndMenu(); } - // if (ImHasFlag(subplot.Flags, ImPlotSubplotFlags_ShareItems)) { - // if ((ImGui::BeginMenu("Legend"))) { - // if (ShowLegendContextMenu(subplot.Items.Legend, !ImHasFlag(subplot.Flags, ImPlotSubplotFlags_NoLegend))) - // ImFlipFlag(subplot.Flags, ImPlotSubplotFlags_NoLegend); - // ImGui::EndMenu(); - // } - // } if ((ImGui::BeginMenu("Settings"))) { - if (ImGui::MenuItem("Title",NULL,!ImHasFlag(subplot.Flags, ImPlotSubplotFlags_NoTitle))) + BeginDisabledControls(!subplot.HasTitle); + if (ImGui::MenuItem("Title",NULL,subplot.HasTitle && !ImHasFlag(subplot.Flags, ImPlotSubplotFlags_NoTitle))) ImFlipFlag(subplot.Flags, ImPlotSubplotFlags_NoTitle); + EndDisabledControls(!subplot.HasTitle); if (ImGui::MenuItem("Resizable",NULL,!ImHasFlag(subplot.Flags, ImPlotSubplotFlags_NoResize))) ImFlipFlag(subplot.Flags, ImPlotSubplotFlags_NoResize); if (ImGui::MenuItem("Align",NULL,!ImHasFlag(subplot.Flags, ImPlotSubplotFlags_NoAlign))) @@ -1850,44 +1439,48 @@ void ShowSubplotsContextMenu(ImPlotSubplot& subplot) { void ShowPlotContextMenu(ImPlotPlot& plot) { const bool owns_legend = GImPlot->CurrentItems == &plot.Items; const bool equal = ImHasFlag(plot.Flags, ImPlotFlags_Equal); - if (ImGui::BeginMenu("X-Axis")) { - ImGui::PushID("X"); - ShowAxisContextMenu(plot.XAxis, equal ? &plot.YAxis[0] : NULL, true); - ImGui::PopID(); - ImGui::EndMenu(); - } - for (int i = 0; i < IMPLOT_Y_AXES; i++) { - if (i == 1 && !ImHasFlag(plot.Flags, ImPlotFlags_YAxis2)) { + + char buf[16] = {}; + + for (int i = 0; i < IMPLOT_NUM_X_AXES; i++) { + ImPlotAxis& x_axis = plot.XAxis(i); + if (!x_axis.Enabled || !x_axis.HasMenus()) continue; - } - if (i == 2 && !ImHasFlag(plot.Flags, ImPlotFlags_YAxis3)) { - continue; - } - char buf[10] = {}; - if (i == 0) { - snprintf(buf, sizeof(buf) - 1, "Y-Axis"); - } else { - snprintf(buf, sizeof(buf) - 1, "Y-Axis %d", i + 1); - } - if (ImGui::BeginMenu(buf)) { - ImGui::PushID(i); - ShowAxisContextMenu(plot.YAxis[i], (equal && i == 0) ? &plot.XAxis : NULL, false); - ImGui::PopID(); + ImGui::PushID(i); + ImFormatString(buf, sizeof(buf) - 1, i == 0 ? "X-Axis" : "X-Axis %d", i + 1); + if (ImGui::BeginMenu(x_axis.HasLabel() ? plot.GetAxisLabel(x_axis) : buf)) { + ShowAxisContextMenu(x_axis, equal ? x_axis.OrthoAxis : NULL, false); ImGui::EndMenu(); } + ImGui::PopID(); + } + + for (int i = 0; i < IMPLOT_NUM_Y_AXES; i++) { + ImPlotAxis& y_axis = plot.YAxis(i); + if (!y_axis.Enabled || !y_axis.HasMenus()) + continue; + ImGui::PushID(i); + ImFormatString(buf, sizeof(buf) - 1, i == 0 ? "Y-Axis" : "Y-Axis %d", i + 1); + if (ImGui::BeginMenu(y_axis.HasLabel() ? plot.GetAxisLabel(y_axis) : buf)) { + ShowAxisContextMenu(y_axis, equal ? y_axis.OrthoAxis : NULL, false); + ImGui::EndMenu(); + } + ImGui::PopID(); } ImGui::Separator(); - if ((ImGui::BeginMenu("Legend"))) { - if (owns_legend) { - if (ShowLegendContextMenu(plot.Items.Legend, !ImHasFlag(plot.Flags, ImPlotFlags_NoLegend))) - ImFlipFlag(plot.Flags, ImPlotFlags_NoLegend); + if (!ImHasFlag(GImPlot->CurrentItems->Legend.Flags, ImPlotLegendFlags_NoMenus)) { + if ((ImGui::BeginMenu("Legend"))) { + if (owns_legend) { + if (ShowLegendContextMenu(plot.Items.Legend, !ImHasFlag(plot.Flags, ImPlotFlags_NoLegend))) + ImFlipFlag(plot.Flags, ImPlotFlags_NoLegend); + } + else if (GImPlot->CurrentSubplot != NULL) { + if (ShowLegendContextMenu(GImPlot->CurrentSubplot->Items.Legend, !ImHasFlag(GImPlot->CurrentSubplot->Flags, ImPlotSubplotFlags_NoLegend))) + ImFlipFlag(GImPlot->CurrentSubplot->Flags, ImPlotSubplotFlags_NoLegend); + } + ImGui::EndMenu(); } - else if (GImPlot->CurrentSubplot != NULL) { - if (ShowLegendContextMenu(GImPlot->CurrentSubplot->Items.Legend, !ImHasFlag(GImPlot->CurrentSubplot->Flags, ImPlotSubplotFlags_NoLegend))) - ImFlipFlag(GImPlot->CurrentSubplot->Flags, ImPlotSubplotFlags_NoLegend); - } - ImGui::EndMenu(); } if ((ImGui::BeginMenu("Settings"))) { if (ImGui::MenuItem("Anti-Aliased Lines",NULL,ImHasFlag(plot.Flags, ImPlotFlags_AntiAliased))) @@ -1896,12 +1489,12 @@ void ShowPlotContextMenu(ImPlotPlot& plot) { ImFlipFlag(plot.Flags, ImPlotFlags_Equal); if (ImGui::MenuItem("Box Select",NULL,!ImHasFlag(plot.Flags, ImPlotFlags_NoBoxSelect))) ImFlipFlag(plot.Flags, ImPlotFlags_NoBoxSelect); - if (ImGui::MenuItem("Query",NULL,ImHasFlag(plot.Flags, ImPlotFlags_Query))) - ImFlipFlag(plot.Flags, ImPlotFlags_Query); - if (ImGui::MenuItem("Title",NULL,!ImHasFlag(plot.Flags, ImPlotFlags_NoTitle))) + BeginDisabledControls(plot.TitleOffset == -1); + if (ImGui::MenuItem("Title",NULL,plot.HasTitle())) ImFlipFlag(plot.Flags, ImPlotFlags_NoTitle); - if (ImGui::MenuItem("Mouse Position",NULL,!ImHasFlag(plot.Flags, ImPlotFlags_NoMousePos))) - ImFlipFlag(plot.Flags, ImPlotFlags_NoMousePos); + EndDisabledControls(plot.TitleOffset == -1); + if (ImGui::MenuItem("Mouse Position",NULL,!ImHasFlag(plot.Flags, ImPlotFlags_NoMouseText))) + ImFlipFlag(plot.Flags, ImPlotFlags_NoMouseText); if (ImGui::MenuItem("Crosshairs",NULL,ImHasFlag(plot.Flags, ImPlotFlags_Crosshairs))) ImFlipFlag(plot.Flags, ImPlotFlags_Crosshairs); ImGui::EndMenu(); @@ -1916,72 +1509,756 @@ void ShowPlotContextMenu(ImPlotPlot& plot) { } //----------------------------------------------------------------------------- -// BeginPlot() +// Axis Utils //----------------------------------------------------------------------------- -bool BeginPlot(const char* title, const char* x_label, const char* y1_label, const ImVec2& size, - ImPlotFlags flags, ImPlotAxisFlags x_flags, ImPlotAxisFlags y1_flags, ImPlotAxisFlags y2_flags, ImPlotAxisFlags y3_flags, - const char* y2_label, const char* y3_label) -{ - IM_ASSERT_USER_ERROR(GImPlot != NULL, "No current context. Did you call ImPlot::CreateContext() or ImPlot::SetCurrentContext()?"); +static inline void DefaultFormatter(double value, char* buff, int size, void* data) { + char* fmt = (char*)data; + ImFormatString(buff, size, fmt, value); +} + +static inline int AxisPrecision(const ImPlotAxis& axis) { + const double range = axis.Ticks.Size > 1 ? (axis.Ticks.Ticks[1].PlotPos - axis.Ticks.Ticks[0].PlotPos) : axis.Range.Size(); + return Precision(range); +} + +static inline double RoundAxisValue(const ImPlotAxis& axis, double value) { + return RoundTo(value, AxisPrecision(axis)); +} + +void LabelAxisValue(const ImPlotAxis& axis, double value, char* buff, int size, bool round) { ImPlotContext& gp = *GImPlot; - IM_ASSERT_USER_ERROR(gp.CurrentPlot == NULL, "Mismatched BeginPlot()/EndPlot()!"); - IM_ASSERT_USER_ERROR(!(ImHasFlag(x_flags, ImPlotAxisFlags_Time) && ImHasFlag(x_flags, ImPlotAxisFlags_LogScale)), "ImPlotAxisFlags_Time and ImPlotAxisFlags_LogScale cannot be enabled at the same time!"); - IM_ASSERT_USER_ERROR(!ImHasFlag(y1_flags, ImPlotAxisFlags_Time), "Y axes cannot display time formatted labels!"); + if (axis.IsTime()) { + ImPlotTimeUnit unit = axis.Vertical + ? GetUnitForRange(axis.Range.Size() / (gp.CurrentPlot->PlotRect.GetHeight() / 100)) // TODO: magic value! + : GetUnitForRange(axis.Range.Size() / (gp.CurrentPlot->PlotRect.GetWidth() / 100)); // TODO: magic value! + FormatDateTime(ImPlotTime::FromDouble(value), buff, size, GetDateTimeFmt(TimeFormatMouseCursor, unit)); + } + else { + if (round) + value = RoundAxisValue(axis, value); + ImPlotFormatter formatter = axis.Formatter ? axis.Formatter : DefaultFormatter; + void* data = (axis.Formatter && axis.FormatterData) ? axis.FormatterData : axis.HasFormatSpec ? (void*)axis.FormatSpec : (void*)IMPLOT_LABEL_FORMAT; + formatter(value, buff, size, data); + } +} - // SUBPLOT ID -------------------------------------------------------------- +void UpdateAxisColors(ImPlotAxis& axis) { + const ImVec4 col_grid = GetStyleColorVec4(ImPlotCol_AxisGrid); + axis.ColorMaj = ImGui::GetColorU32(col_grid); + axis.ColorMin = ImGui::GetColorU32(col_grid*ImVec4(1,1,1,GImPlot->Style.MinorAlpha)); + axis.ColorTick = GetStyleColorU32(ImPlotCol_AxisTick); + axis.ColorTxt = GetStyleColorU32(ImPlotCol_AxisText); + axis.ColorBg = GetStyleColorU32(ImPlotCol_AxisBg); + axis.ColorHov = GetStyleColorU32(ImPlotCol_AxisBgHovered); + axis.ColorAct = GetStyleColorU32(ImPlotCol_AxisBgActive); + // axis.ColorHiLi = IM_COL32_BLACK_TRANS; +} - if (gp.CurrentSubplot != NULL) - ImGui::PushID(gp.CurrentSubplot->CurrentIdx); +void PadAndDatumAxesX(ImPlotPlot& plot, float& pad_T, float& pad_B, ImPlotAlignmentData* align) { - // FRONT MATTER ----------------------------------------------------------- + ImPlotContext& gp = *GImPlot; - ImGuiContext &G = *GImGui; - ImGuiWindow * Window = G.CurrentWindow; + const float T = ImGui::GetTextLineHeight(); + const float P = gp.Style.LabelPadding.y; + const float K = gp.Style.MinorTickLen.x; + + int count_T = 0; + int count_B = 0; + float last_T = plot.AxesRect.Min.y; + float last_B = plot.AxesRect.Max.y; + + for (int i = IMPLOT_NUM_X_AXES; i-- > 0;) { // FYI: can iterate forward + ImPlotAxis& axis = plot.XAxis(i); + if (!axis.Enabled) + continue; + const bool label = axis.HasLabel(); + const bool ticks = axis.HasTickLabels(); + const bool opp = axis.IsOpposite(); + const bool time = axis.IsTime(); + if (opp) { + if (count_T++ > 0) + pad_T += K + P; + if (label) + pad_T += T + P; + if (ticks) + pad_T += ImMax(T, axis.Ticks.MaxSize.y) + P + (time ? T + P : 0); + axis.Datum1 = plot.CanvasRect.Min.y + pad_T; + axis.Datum2 = last_T; + last_T = axis.Datum1; + } + else { + if (count_B++ > 0) + pad_B += K + P; + if (label) + pad_B += T + P; + if (ticks) + pad_B += ImMax(T, axis.Ticks.MaxSize.y) + P + (time ? T + P : 0); + axis.Datum1 = plot.CanvasRect.Max.y - pad_B; + axis.Datum2 = last_B; + last_B = axis.Datum1; + } + } + + if (align) { + count_T = count_B = 0; + float delta_T, delta_B; + align->Update(pad_T,pad_B,delta_T,delta_B); + for (int i = IMPLOT_NUM_X_AXES; i-- > 0;) { + ImPlotAxis& axis = plot.XAxis(i); + if (!axis.Enabled) + continue; + if (axis.IsOpposite()) { + axis.Datum1 += delta_T; + axis.Datum2 += count_T++ > 1 ? delta_T : 0; + } + else { + axis.Datum1 -= delta_B; + axis.Datum2 -= count_B++ > 1 ? delta_B : 0; + } + } + } +} + +void PadAndDatumAxesY(ImPlotPlot& plot, float& pad_L, float& pad_R, ImPlotAlignmentData* align) { + + // [ pad_L ] [ pad_R ] + // .................CanvasRect................ + // :TPWPK.PTPWP _____PlotRect____ PWPTP.KPWPT: + // :A # |- A # |- -| # A -| # A: + // :X | X | | X | x: + // :I # |- I # |- -| # I -| # I: + // :S | S | | S | S: + // :3 # |- 0 # |-_______________-| # 1 -| # 2: + // :.........................................: + // + // T = text height + // P = label padding + // K = minor tick length + // W = label width + + ImPlotContext& gp = *GImPlot; + + const float T = ImGui::GetTextLineHeight(); + const float P = gp.Style.LabelPadding.x; + const float K = gp.Style.MinorTickLen.y; + + int count_L = 0; + int count_R = 0; + float last_L = plot.AxesRect.Min.x; + float last_R = plot.AxesRect.Max.x; + + for (int i = IMPLOT_NUM_Y_AXES; i-- > 0;) { // FYI: can iterate forward + ImPlotAxis& axis = plot.YAxis(i); + if (!axis.Enabled) + continue; + const bool label = axis.HasLabel(); + const bool ticks = axis.HasTickLabels(); + const bool opp = axis.IsOpposite(); + if (opp) { + if (count_R++ > 0) + pad_R += K + P; + if (label) + pad_R += T + P; + if (ticks) + pad_R += axis.Ticks.MaxSize.x + P; + axis.Datum1 = plot.CanvasRect.Max.x - pad_R; + axis.Datum2 = last_R; + last_R = axis.Datum1; + } + else { + if (count_L++ > 0) + pad_L += K + P; + if (label) + pad_L += T + P; + if (ticks) + pad_L += axis.Ticks.MaxSize.x + P; + axis.Datum1 = plot.CanvasRect.Min.x + pad_L; + axis.Datum2 = last_L; + last_L = axis.Datum1; + } + } + + plot.PlotRect.Min.x = plot.CanvasRect.Min.x + pad_L; + plot.PlotRect.Max.x = plot.CanvasRect.Max.x - pad_R; + + if (align) { + count_L = count_R = 0; + float delta_L, delta_R; + align->Update(pad_L,pad_R,delta_L,delta_R); + for (int i = IMPLOT_NUM_Y_AXES; i-- > 0;) { + ImPlotAxis& axis = plot.YAxis(i); + if (!axis.Enabled) + continue; + if (axis.IsOpposite()) { + axis.Datum1 -= delta_R; + axis.Datum2 -= count_R++ > 1 ? delta_R : 0; + } + else { + axis.Datum1 += delta_L; + axis.Datum2 += count_L++ > 1 ? delta_L : 0; + } + } + } +} + +//----------------------------------------------------------------------------- +// RENDERING +//----------------------------------------------------------------------------- + +static inline void RenderGridLinesX(ImDrawList& DrawList, const ImPlotTickCollection& ticks, const ImRect& rect, ImU32 col_maj, ImU32 col_min, float size_maj, float size_min) { + const float density = ticks.Size / rect.GetWidth(); + ImVec4 col_min4 = ImGui::ColorConvertU32ToFloat4(col_min); + col_min4.w *= ImClamp(ImRemap(density, 0.1f, 0.2f, 1.0f, 0.0f), 0.0f, 1.0f); + col_min = ImGui::ColorConvertFloat4ToU32(col_min4); + for (int t = 0; t < ticks.Size; t++) { + const ImPlotTick& xt = ticks.Ticks[t]; + if (xt.PixelPos < rect.Min.x || xt.PixelPos > rect.Max.x) + continue; + if (xt.Level == 0) { + if (xt.Major) + DrawList.AddLine(ImVec2(xt.PixelPos, rect.Min.y), ImVec2(xt.PixelPos, rect.Max.y), col_maj, size_maj); + else if (density < 0.2f) + DrawList.AddLine(ImVec2(xt.PixelPos, rect.Min.y), ImVec2(xt.PixelPos, rect.Max.y), col_min, size_min); + } + } +} + +static inline void RenderGridLinesY(ImDrawList& DrawList, const ImPlotTickCollection& ticks, const ImRect& rect, ImU32 col_maj, ImU32 col_min, float size_maj, float size_min) { + const float density = ticks.Size / rect.GetHeight(); + ImVec4 col_min4 = ImGui::ColorConvertU32ToFloat4(col_min); + col_min4.w *= ImClamp(ImRemap(density, 0.1f, 0.2f, 1.0f, 0.0f), 0.0f, 1.0f); + col_min = ImGui::ColorConvertFloat4ToU32(col_min4); + for (int t = 0; t < ticks.Size; t++) { + const ImPlotTick& yt = ticks.Ticks[t]; + if (yt.PixelPos < rect.Min.y || yt.PixelPos > rect.Max.y) + continue; + if (yt.Major) + DrawList.AddLine(ImVec2(rect.Min.x, yt.PixelPos), ImVec2(rect.Max.x, yt.PixelPos), col_maj, size_maj); + else if (density < 0.2f) + DrawList.AddLine(ImVec2(rect.Min.x, yt.PixelPos), ImVec2(rect.Max.x, yt.PixelPos), col_min, size_min); + } +} + +static inline void RenderSelectionRect(ImDrawList& DrawList, const ImVec2& p_min, const ImVec2& p_max, const ImVec4& col) { + const ImU32 col_bg = ImGui::GetColorU32(col * ImVec4(1,1,1,0.25f)); + const ImU32 col_bd = ImGui::GetColorU32(col); + DrawList.AddRectFilled(p_min, p_max, col_bg); + DrawList.AddRect(p_min, p_max, col_bd); +} + +//----------------------------------------------------------------------------- +// Input Handling +//----------------------------------------------------------------------------- + +static const float MOUSE_CURSOR_DRAG_THRESHOLD = 5.0f; +static const float BOX_SELECT_DRAG_THRESHOLD = 4.0f; + +bool UpdateInput(ImPlotPlot& plot) { + + bool changed = false; + + ImPlotContext& gp = *GImPlot; + ImGuiIO& IO = ImGui::GetIO(); + + // BUTTON STATE ----------------------------------------------------------- + + const ImGuiButtonFlags plot_button_flags = ImGuiButtonFlags_AllowItemOverlap + | ImGuiButtonFlags_PressedOnClick + | ImGuiButtonFlags_PressedOnDoubleClick + | ImGuiButtonFlags_MouseButtonLeft + | ImGuiButtonFlags_MouseButtonRight + | ImGuiButtonFlags_MouseButtonMiddle; + const ImGuiButtonFlags axis_button_flags = ImGuiButtonFlags_FlattenChildren + | plot_button_flags; + + const bool plot_clicked = ImGui::ButtonBehavior(plot.PlotRect,plot.ID,&plot.Hovered,&plot.Held,plot_button_flags); + ImGui::SetItemAllowOverlap(); + + if (plot_clicked) { + if (!ImHasFlag(plot.Flags, ImPlotFlags_NoBoxSelect) && IO.MouseClicked[gp.InputMap.Select] && ImHasFlag(IO.KeyMods, gp.InputMap.SelectMod)) { + plot.Selecting = true; + plot.SelectStart = IO.MousePos; + plot.SelectRect = ImRect(0,0,0,0); + } + if (IO.MouseDoubleClicked[gp.InputMap.Fit]) { + plot.FitThisFrame = true; + for (int i = 0; i < ImAxis_COUNT; ++i) + plot.Axes[i].FitThisFrame = true; + } + } + + const bool can_pan = IO.MouseDown[gp.InputMap.Pan] && ImHasFlag(IO.KeyMods, gp.InputMap.PanMod); + + plot.Held = plot.Held && can_pan; + + bool x_click[IMPLOT_NUM_X_AXES] = {false}; + bool x_held[IMPLOT_NUM_X_AXES] = {false}; + bool x_hov[IMPLOT_NUM_X_AXES] = {false}; + + bool y_click[IMPLOT_NUM_Y_AXES] = {false}; + bool y_held[IMPLOT_NUM_Y_AXES] = {false}; + bool y_hov[IMPLOT_NUM_Y_AXES] = {false}; + + for (int i = 0; i < IMPLOT_NUM_X_AXES; ++i) { + ImPlotAxis& xax = plot.XAxis(i); + if (xax.Enabled) { + ImGui::KeepAliveID(xax.ID); + x_click[i] = ImGui::ButtonBehavior(xax.HoverRect,xax.ID,&xax.Hovered,&xax.Held,axis_button_flags); + if (x_click[i] && IO.MouseDoubleClicked[gp.InputMap.Fit]) + plot.FitThisFrame = xax.FitThisFrame = true; + xax.Held = xax.Held && can_pan; + x_hov[i] = xax.Hovered || plot.Hovered; + x_held[i] = xax.Held || plot.Held; + } + } + + for (int i = 0; i < IMPLOT_NUM_Y_AXES; ++i) { + ImPlotAxis& yax = plot.YAxis(i); + if (yax.Enabled) { + ImGui::KeepAliveID(yax.ID); + y_click[i] = ImGui::ButtonBehavior(yax.HoverRect,yax.ID,&yax.Hovered,&yax.Held,axis_button_flags); + if (y_click[i] && IO.MouseDoubleClicked[gp.InputMap.Fit]) + plot.FitThisFrame = yax.FitThisFrame = true; + yax.Held = yax.Held && can_pan; + y_hov[i] = yax.Hovered || plot.Hovered; + y_held[i] = yax.Held || plot.Held; + } + } + + // cancel due to DND activity + if (GImGui->DragDropActive || (IO.KeyMods == gp.InputMap.OverrideMod && gp.InputMap.OverrideMod != 0)) + return false; + + // STATE ------------------------------------------------------------------- + + const bool axis_equal = ImHasFlag(plot.Flags, ImPlotFlags_Equal); + + const bool any_x_hov = plot.Hovered || AnyAxesHovered(&plot.Axes[ImAxis_X1], IMPLOT_NUM_X_AXES); + const bool any_x_held = plot.Held || AnyAxesHeld(&plot.Axes[ImAxis_X1], IMPLOT_NUM_X_AXES); + const bool any_y_hov = plot.Hovered || AnyAxesHovered(&plot.Axes[ImAxis_Y1], IMPLOT_NUM_Y_AXES); + const bool any_y_held = plot.Held || AnyAxesHeld(&plot.Axes[ImAxis_Y1], IMPLOT_NUM_Y_AXES); + const bool any_hov = any_x_hov || any_y_hov; + const bool any_held = any_x_held || any_y_held; + + const ImVec2 select_drag = ImGui::GetMouseDragDelta(gp.InputMap.Select); + const ImVec2 pan_drag = ImGui::GetMouseDragDelta(gp.InputMap.Pan); + const float select_drag_sq = ImLengthSqr(select_drag); + const float pan_drag_sq = ImLengthSqr(pan_drag); + const bool selecting = plot.Selecting && select_drag_sq > MOUSE_CURSOR_DRAG_THRESHOLD; + const bool panning = any_held && pan_drag_sq > MOUSE_CURSOR_DRAG_THRESHOLD; + + // CONTEXT MENU ----------------------------------------------------------- + + if (IO.MouseReleased[gp.InputMap.Menu] && !plot.ContextLocked) + gp.OpenContextThisFrame = true; + + if (selecting || panning) + plot.ContextLocked = true; + else if (!(IO.MouseDown[gp.InputMap.Menu] || IO.MouseReleased[gp.InputMap.Menu])) + plot.ContextLocked = false; + + // DRAG INPUT ------------------------------------------------------------- + + if (any_held && !plot.Selecting) { + int drag_direction = 0; + for (int i = 0; i < IMPLOT_NUM_X_AXES; i++) { + ImPlotAxis& x_axis = plot.XAxis(i); + if (x_held[i] && !x_axis.IsInputLocked()) { + drag_direction |= (1 << 1); + const double plot_l = x_axis.PixelsToPlot(plot.PlotRect.Min.x - IO.MouseDelta.x); + const double plot_r = x_axis.PixelsToPlot(plot.PlotRect.Max.x - IO.MouseDelta.x); + x_axis.SetMin(x_axis.IsInverted() ? plot_r : plot_l); + x_axis.SetMax(x_axis.IsInverted() ? plot_l : plot_r); + if (axis_equal && x_axis.OrthoAxis != NULL) + x_axis.OrthoAxis->SetAspect(x_axis.GetAspect()); + changed = true; + } + } + for (int i = 0; i < IMPLOT_NUM_Y_AXES; i++) { + ImPlotAxis& y_axis = plot.YAxis(i); + if (y_held[i] && !y_axis.IsInputLocked()) { + drag_direction |= (1 << 2); + const double plot_t = y_axis.PixelsToPlot(plot.PlotRect.Min.y - IO.MouseDelta.y); + const double plot_b = y_axis.PixelsToPlot(plot.PlotRect.Max.y - IO.MouseDelta.y); + y_axis.SetMin(y_axis.IsInverted() ? plot_t : plot_b); + y_axis.SetMax(y_axis.IsInverted() ? plot_b : plot_t); + if (axis_equal && y_axis.OrthoAxis != NULL) + y_axis.OrthoAxis->SetAspect(y_axis.GetAspect()); + changed = true; + } + } + if (IO.MouseDragMaxDistanceSqr[gp.InputMap.Pan] > MOUSE_CURSOR_DRAG_THRESHOLD) { + switch (drag_direction) { + case 0 : ImGui::SetMouseCursor(ImGuiMouseCursor_NotAllowed); break; + case (1 << 1) : ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeEW); break; + case (1 << 2) : ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNS); break; + default : ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeAll); break; + } + } + } + + // SCROLL INPUT ----------------------------------------------------------- + + if (any_hov && IO.MouseWheel != 0 && ImHasFlag(IO.KeyMods, gp.InputMap.ZoomMod)) { + + float zoom_rate = gp.InputMap.ZoomRate; + if (IO.MouseWheel > 0) + zoom_rate = (-zoom_rate) / (1.0f + (2.0f * zoom_rate)); + ImVec2 rect_size = plot.PlotRect.GetSize(); + float tx = ImRemap(IO.MousePos.x, plot.PlotRect.Min.x, plot.PlotRect.Max.x, 0.0f, 1.0f); + float ty = ImRemap(IO.MousePos.y, plot.PlotRect.Min.y, plot.PlotRect.Max.y, 0.0f, 1.0f); + + for (int i = 0; i < IMPLOT_NUM_X_AXES; i++) { + ImPlotAxis& x_axis = plot.XAxis(i); + const bool equal_zoom = axis_equal && x_axis.OrthoAxis != NULL; + const bool equal_locked = (equal_zoom != false) && x_axis.OrthoAxis->IsInputLocked(); + if (x_hov[i] && !x_axis.IsInputLocked() && !equal_locked) { + float correction = (plot.Hovered && equal_zoom) ? 0.5f : 1.0f; + const double plot_l = x_axis.PixelsToPlot(plot.PlotRect.Min.x - rect_size.x * tx * zoom_rate * correction); + const double plot_r = x_axis.PixelsToPlot(plot.PlotRect.Max.x + rect_size.x * (1 - tx) * zoom_rate * correction); + x_axis.SetMin(x_axis.IsInverted() ? plot_r : plot_l); + x_axis.SetMax(x_axis.IsInverted() ? plot_l : plot_r); + if (axis_equal && x_axis.OrthoAxis != NULL) + x_axis.OrthoAxis->SetAspect(x_axis.GetAspect()); + changed = true; + } + } + for (int i = 0; i < IMPLOT_NUM_Y_AXES; i++) { + ImPlotAxis& y_axis = plot.YAxis(i); + const bool equal_zoom = axis_equal && y_axis.OrthoAxis != NULL; + const bool equal_locked = equal_zoom && y_axis.OrthoAxis->IsInputLocked(); + if (y_hov[i] && !y_axis.IsInputLocked() && !equal_locked) { + float correction = (plot.Hovered && equal_zoom) ? 0.5f : 1.0f; + const double plot_t = y_axis.PixelsToPlot(plot.PlotRect.Min.y - rect_size.y * ty * zoom_rate * correction); + const double plot_b = y_axis.PixelsToPlot(plot.PlotRect.Max.y + rect_size.y * (1 - ty) * zoom_rate * correction); + y_axis.SetMin(y_axis.IsInverted() ? plot_t : plot_b); + y_axis.SetMax(y_axis.IsInverted() ? plot_b : plot_t); + if (axis_equal && y_axis.OrthoAxis != NULL) + y_axis.OrthoAxis->SetAspect(y_axis.GetAspect()); + changed = true; + } + } + } + + // BOX-SELECTION ---------------------------------------------------------- + + if (plot.Selecting) { + const ImVec2 d = plot.SelectStart - IO.MousePos; + const bool x_can_change = !ImHasFlag(IO.KeyMods,gp.InputMap.SelectHorzMod) && ImFabs(d.x) > 2; + const bool y_can_change = !ImHasFlag(IO.KeyMods,gp.InputMap.SelectVertMod) && ImFabs(d.y) > 2; + // confirm + if (IO.MouseReleased[gp.InputMap.Select]) { + for (int i = 0; i < IMPLOT_NUM_X_AXES; i++) { + ImPlotAxis& x_axis = plot.XAxis(i); + if (!x_axis.IsInputLocked() && x_can_change) { + const double p1 = x_axis.PixelsToPlot(plot.SelectStart.x); + const double p2 = x_axis.PixelsToPlot(IO.MousePos.x); + x_axis.SetMin(ImMin(p1, p2)); + x_axis.SetMax(ImMax(p1, p2)); + changed = true; + } + } + for (int i = 0; i < IMPLOT_NUM_Y_AXES; i++) { + ImPlotAxis& y_axis = plot.YAxis(i); + if (!y_axis.IsInputLocked() && y_can_change) { + const double p1 = y_axis.PixelsToPlot(plot.SelectStart.y); + const double p2 = y_axis.PixelsToPlot(IO.MousePos.y); + y_axis.SetMin(ImMin(p1, p2)); + y_axis.SetMax(ImMax(p1, p2)); + changed = true; + } + } + if (x_can_change || y_can_change || (ImHasFlag(IO.KeyMods,gp.InputMap.SelectHorzMod) && ImHasFlag(IO.KeyMods,gp.InputMap.SelectVertMod))) + gp.OpenContextThisFrame = false; + plot.Selected = plot.Selecting = false; + } + // cancel + else if (IO.MouseReleased[gp.InputMap.SelectCancel]) { + plot.Selected = plot.Selecting = false; + gp.OpenContextThisFrame = false; + } + else if (ImLengthSqr(d) > BOX_SELECT_DRAG_THRESHOLD) { + // bad selection + if (plot.IsInputLocked()) { + ImGui::SetMouseCursor(ImGuiMouseCursor_NotAllowed); + gp.OpenContextThisFrame = false; + plot.Selected = false; + } + else { + // TODO: Handle only min or max locked cases + const bool full_width = ImHasFlag(IO.KeyMods, gp.InputMap.SelectHorzMod) || AllAxesInputLocked(&plot.Axes[ImAxis_X1], IMPLOT_NUM_X_AXES); + const bool full_height = ImHasFlag(IO.KeyMods, gp.InputMap.SelectVertMod) || AllAxesInputLocked(&plot.Axes[ImAxis_Y1], IMPLOT_NUM_Y_AXES); + plot.SelectRect.Min.x = full_width ? plot.PlotRect.Min.x : ImMin(plot.SelectStart.x, IO.MousePos.x); + plot.SelectRect.Max.x = full_width ? plot.PlotRect.Max.x : ImMax(plot.SelectStart.x, IO.MousePos.x); + plot.SelectRect.Min.y = full_height ? plot.PlotRect.Min.y : ImMin(plot.SelectStart.y, IO.MousePos.y); + plot.SelectRect.Max.y = full_height ? plot.PlotRect.Max.y : ImMax(plot.SelectStart.y, IO.MousePos.y); + plot.SelectRect.Min -= plot.PlotRect.Min; + plot.SelectRect.Max -= plot.PlotRect.Min; + plot.Selected = true; + } + } + else { + plot.Selected = false; + } + } + return changed; +} + +//----------------------------------------------------------------------------- +// Next Plot Data (Legacy) +//----------------------------------------------------------------------------- + +void ApplyNextPlotData(ImAxis idx) { + ImPlotContext& gp = *GImPlot; + ImPlotPlot& plot = *GImPlot->CurrentPlot; + ImPlotAxis& axis = plot.Axes[idx]; + if (!axis.Enabled) + return; + double* npd_lmin = gp.NextPlotData.LinkedMin[idx]; + double* npd_lmax = gp.NextPlotData.LinkedMax[idx]; + bool npd_rngh = gp.NextPlotData.HasRange[idx]; + ImPlotCond npd_rngc = gp.NextPlotData.RangeCond[idx]; + ImPlotRange npd_rngv = gp.NextPlotData.Range[idx]; + axis.LinkedMin = npd_lmin; + axis.LinkedMax = npd_lmax; + axis.PullLinks(); + if (npd_rngh) { + if (!plot.Initialized || npd_rngc == ImPlotCond_Always) + axis.SetRange(npd_rngv); + } + axis.HasRange = npd_rngh; + axis.RangeCond = npd_rngc; +} + +//----------------------------------------------------------------------------- +// Setup +//----------------------------------------------------------------------------- + +void SetupAxis(ImAxis idx, const char* label, ImPlotAxisFlags flags) { + IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != NULL && !GImPlot->CurrentPlot->SetupLocked, + "Setup needs to be called after BeginPlot and before any setup locking functions (e.g. PlotX)!"); + IM_ASSERT_USER_ERROR(!(ImHasFlag(flags, ImPlotAxisFlags_Time) && ImHasFlag(flags, ImPlotAxisFlags_LogScale)), + "ImPlotAxisFlags_Time and ImPlotAxisFlags_LogScale cannot be enabled at the same time!"); + IM_ASSERT_USER_ERROR(!(ImHasFlag(flags, ImPlotAxisFlags_Time) && idx >= ImAxis_Y1), + "Y axes cannot display time formatted labels!"); + // get plot and axis + ImPlotPlot& plot = *GImPlot->CurrentPlot; + ImPlotAxis& axis = plot.Axes[idx]; + // set ID + axis.ID = plot.ID + idx + 1; + // check and set flags + if (plot.JustCreated || flags != axis.PreviousFlags) + axis.Flags = flags; + axis.PreviousFlags = flags; + // enable axis + axis.Enabled = true; + // set label + plot.SetAxisLabel(axis,label); + // cache colors + UpdateAxisColors(axis); +} + +void SetupAxisLimits(ImAxis idx, double min_lim, double max_lim, ImPlotCond cond) { + IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != NULL && !GImPlot->CurrentPlot->SetupLocked, + "Setup needs to be called after BeginPlot and before any setup locking functions (e.g. PlotX)!"); // get plot and axis + ImPlotPlot& plot = *GImPlot->CurrentPlot; + ImPlotAxis& axis = plot.Axes[idx]; + IM_ASSERT_USER_ERROR(axis.Enabled, "Axis is not enabled! Did you forget to call SetupAxis()?"); + if (!plot.Initialized || cond == ImPlotCond_Always) + axis.SetRange(min_lim, max_lim); + axis.HasRange = true; + axis.RangeCond = cond; +} + +void SetupAxisFormat(ImAxis idx, const char* fmt) { + IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != NULL && !GImPlot->CurrentPlot->SetupLocked, + "Setup needs to be called after BeginPlot and before any setup locking functions (e.g. PlotX)!"); + ImPlotPlot& plot = *GImPlot->CurrentPlot; + ImPlotAxis& axis = plot.Axes[idx]; + IM_ASSERT_USER_ERROR(axis.Enabled, "Axis is not enabled! Did you forget to call SetupAxis()?"); + axis.HasFormatSpec = fmt != NULL; + if (fmt != NULL) + ImStrncpy(axis.FormatSpec,fmt,sizeof(axis.FormatSpec)); +} + +void SetupAxisLinks(ImAxis idx, double* min_lnk, double* max_lnk) { + IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != NULL && !GImPlot->CurrentPlot->SetupLocked, + "Setup needs to be called after BeginPlot and before any setup locking functions (e.g. PlotX)!"); + ImPlotPlot& plot = *GImPlot->CurrentPlot; + ImPlotAxis& axis = plot.Axes[idx]; + IM_ASSERT_USER_ERROR(axis.Enabled, "Axis is not enabled! Did you forget to call SetupAxis()?"); + axis.LinkedMin = min_lnk; + axis.LinkedMax = max_lnk; + axis.PullLinks(); +} + +void SetupAxisFormat(ImAxis idx, ImPlotFormatter formatter, void* data) { + IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != NULL && !GImPlot->CurrentPlot->SetupLocked, + "Setup needs to be called after BeginPlot and before any setup locking functions (e.g. PlotX)!"); + ImPlotPlot& plot = *GImPlot->CurrentPlot; + ImPlotAxis& axis = plot.Axes[idx]; + IM_ASSERT_USER_ERROR(axis.Enabled, "Axis is not enabled! Did you forget to call SetupAxis()?"); + axis.Formatter = formatter; + axis.FormatterData = data; +} + +void SetupAxisTicks(ImAxis idx, const double* values, int n_ticks, const char* const labels[], bool show_default) { + IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != NULL && !GImPlot->CurrentPlot->SetupLocked, + "Setup needs to be called after BeginPlot and before any setup locking functions (e.g. PlotX)!"); + ImPlotPlot& plot = *GImPlot->CurrentPlot; + ImPlotAxis& axis = plot.Axes[idx]; + IM_ASSERT_USER_ERROR(axis.Enabled, "Axis is not enabled! Did you forget to call SetupAxis()?"); + axis.ShowDefaultTicks = show_default; + AddTicksCustom(values, + labels, + n_ticks, + axis.Ticks, + axis.Formatter ? axis.Formatter : DefaultFormatter, + (axis.Formatter && axis.FormatterData) ? axis.FormatterData : axis.HasFormatSpec ? axis.FormatSpec : (void*)IMPLOT_LABEL_FORMAT); +} + +void SetupAxisTicks(ImAxis idx, double v_min, double v_max, int n_ticks, const char* const labels[], bool show_default) { + IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != NULL && !GImPlot->CurrentPlot->SetupLocked, + "Setup needs to be called after BeginPlot and before any setup locking functions (e.g. PlotX)!"); + IM_ASSERT_USER_ERROR(n_ticks > 1, "The number of ticks must be greater than 1"); + FillRange(GImPlot->TempDouble1, n_ticks, v_min, v_max); + SetupAxisTicks(idx, GImPlot->TempDouble1.Data, n_ticks, labels, show_default); +} + +void SetupAxes(const char* x_label, const char* y_label, ImPlotAxisFlags x_flags, ImPlotAxisFlags y_flags) { + SetupAxis(ImAxis_X1, x_label, x_flags); + SetupAxis(ImAxis_Y1, y_label, y_flags); +} + +void SetupAxesLimits(double x_min, double x_max, double y_min, double y_max, ImPlotCond cond) { + SetupAxisLimits(ImAxis_X1, x_min, x_max, cond); + SetupAxisLimits(ImAxis_Y1, y_min, y_max, cond); +} + +void SetupLegend(ImPlotLocation location, ImPlotLegendFlags flags) { + IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != NULL && !GImPlot->CurrentPlot->SetupLocked, + "Setup needs to be called after BeginPlot and before any setup locking functions (e.g. PlotX)!"); + IM_ASSERT_USER_ERROR(GImPlot->CurrentItems != NULL, + "SetupLegend() needs to be called within an itemized context!"); + ImPlotLegend& legend = GImPlot->CurrentItems->Legend; + // check and set location + if (location != legend.PreviousLocation) + legend.Location = location; + legend.PreviousLocation = location; + // check and set flags + if (flags != legend.PreviousFlags) + legend.Flags = flags; + legend.PreviousFlags = flags; +} + +void SetupMouseText(ImPlotLocation location, ImPlotMouseTextFlags flags) { + IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != NULL && !GImPlot->CurrentPlot->SetupLocked, + "Setup needs to be called after BeginPlot and before any setup locking functions (e.g. PlotX)!"); + GImPlot->CurrentPlot->MouseTextLocation = location; + GImPlot->CurrentPlot->MouseTextFlags = flags; +} + +//----------------------------------------------------------------------------- +// SetNext +//----------------------------------------------------------------------------- + +void SetNextAxisLimits(ImAxis axis, double v_min, double v_max, ImPlotCond cond) { + ImPlotContext& gp = *GImPlot; + IM_ASSERT_USER_ERROR(gp.CurrentPlot == NULL, "SetNextAxisLimits() needs to be called before BeginPlot()!"); + IM_ASSERT(cond == 0 || ImIsPowerOfTwo(cond)); // Make sure the user doesn't attempt to combine multiple condition flags. + gp.NextPlotData.HasRange[axis] = true; + gp.NextPlotData.RangeCond[axis] = cond; + gp.NextPlotData.Range[axis].Min = v_min; + gp.NextPlotData.Range[axis].Max = v_max; +} + +void SetNextAxisLinks(ImAxis axis, double* link_min, double* link_max) { + ImPlotContext& gp = *GImPlot; + IM_ASSERT_USER_ERROR(gp.CurrentPlot == NULL, "SetNextAxisLinks() needs to be called before BeginPlot()!"); + gp.NextPlotData.LinkedMin[axis] = link_min; + gp.NextPlotData.LinkedMax[axis] = link_max; +} + +void SetNextAxisToFit(ImAxis axis) { + ImPlotContext& gp = *GImPlot; + IM_ASSERT_USER_ERROR(gp.CurrentPlot == NULL, "SetNextAxisToFit() needs to be called before BeginPlot()!"); + gp.NextPlotData.Fit[axis] = true; +} + +void SetNextAxesLimits(double x_min, double x_max, double y_min, double y_max, ImPlotCond cond) { + SetNextAxisLimits(ImAxis_X1, x_min, x_max, cond); + SetNextAxisLimits(ImAxis_Y1, y_min, y_max, cond); +} + +void SetNextAxesToFit() { + for (int i = 0; i < ImAxis_COUNT; ++i) + SetNextAxisToFit(i); +} + +//----------------------------------------------------------------------------- +// BeginPlot +//----------------------------------------------------------------------------- + +bool BeginPlot(const char* title_id, const ImVec2& size, ImPlotFlags flags) { + IM_ASSERT_USER_ERROR(GImPlot != NULL, "No current context. Did you call ImPlot::CreateContext() or ImPlot::SetCurrentContext()?"); + IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot == NULL, "Mismatched BeginPlot()/EndPlot()!"); + + // FRONT MATTER ----------------------------------------------------------- + + if (GImPlot->CurrentSubplot != NULL) + ImGui::PushID(GImPlot->CurrentSubplot->CurrentIdx); + + // get globals + ImPlotContext& gp = *GImPlot; + ImGuiContext &G = *GImGui; + ImGuiWindow* Window = G.CurrentWindow; + + // skip if needed if (Window->SkipItems && !gp.CurrentSubplot) { ResetCtxForNextPlot(GImPlot); return false; } - const ImGuiID ID = Window->GetID(title); - const ImGuiStyle &Style = G.Style; - const ImGuiIO & IO = ImGui::GetIO(); - - bool just_created = gp.Plots.GetByKey(ID) == NULL; + // ID and age (TODO: keep track of plot age in frames) + const ImGuiID ID = Window->GetID(title_id); + const bool just_created = gp.Plots.GetByKey(ID) == NULL; gp.CurrentPlot = gp.Plots.GetOrAddByKey(ID); - gp.CurrentPlot->ID = ID; - gp.CurrentPlot->Items.ID = ID; + ImPlotPlot &plot = *gp.CurrentPlot; + plot.ID = ID; + plot.Items.ID = ID - 1; + plot.JustCreated = just_created; + plot.SetupLocked = false; - plot.CurrentYAxis = 0; + // check flags + if (plot.JustCreated) + plot.Flags = flags; + else if (flags != plot.PreviousFlags) + plot.Flags = flags; + plot.PreviousFlags = flags; - if (just_created) { - plot.Flags = flags; - plot.XAxis.Flags = x_flags; - plot.YAxis[0].Flags = y1_flags; - plot.YAxis[1].Flags = y2_flags; - plot.YAxis[2].Flags = y3_flags; - } - else { - // TODO: Check which individual flags changed, and only reset those! - // There's probably an easy bit mask trick I'm not aware of. - if (flags != plot.PreviousFlags) - plot.Flags = flags; - if (x_flags != plot.XAxis.PreviousFlags) - plot.XAxis.Flags = x_flags; - if (y1_flags != plot.YAxis[0].PreviousFlags) - plot.YAxis[0].Flags = y1_flags; - if (y2_flags != plot.YAxis[1].PreviousFlags) - plot.YAxis[1].Flags = y2_flags; - if (y3_flags != plot.YAxis[2].PreviousFlags) - plot.YAxis[2].Flags = y3_flags; + // setup default axes + if (plot.JustCreated) { + SetupAxis(ImAxis_X1); + SetupAxis(ImAxis_Y1); } - plot.PreviousFlags = flags; - plot.XAxis.PreviousFlags = x_flags; - plot.YAxis[0].PreviousFlags = y1_flags; - plot.YAxis[1].PreviousFlags = y2_flags; - plot.YAxis[2].PreviousFlags = y3_flags; + // reset axes + for (int i = 0; i < ImAxis_COUNT; ++i) { + plot.Axes[i].Reset(); + UpdateAxisColors(plot.Axes[i]); + } + // ensure first axes enabled + plot.Axes[ImAxis_X1].Enabled = true; + plot.Axes[ImAxis_Y1].Enabled = true; + // set initial axes + plot.CurrentX = ImAxis_X1; + plot.CurrentY = ImAxis_Y1; + + // process next plot data (legacy) + for (int i = 0; i < ImAxis_COUNT; ++i) + ApplyNextPlotData(i); // capture scroll with a child region if (!ImHasFlag(plot.Flags, ImPlotFlags_NoChild)) { @@ -1990,7 +2267,7 @@ bool BeginPlot(const char* title, const char* x_label, const char* y1_label, con child_size = gp.CurrentSubplot->CellSize; else child_size = ImVec2(size.x == 0 ? gp.Style.PlotDefaultSize.x : size.x, size.y == 0 ? gp.Style.PlotDefaultSize.y : size.y); - ImGui::BeginChild(title, child_size, false, ImGuiWindowFlags_NoScrollbar); + ImGui::BeginChild(title_id, child_size, false, ImGuiWindowFlags_NoScrollbar); Window = ImGui::GetCurrentWindow(); Window->ScrollMax.y = 1.0f; gp.ChildWindowMade = true; @@ -1999,91 +2276,11 @@ bool BeginPlot(const char* title, const char* x_label, const char* y1_label, con gp.ChildWindowMade = false; } - ImDrawList &DrawList = *Window->DrawList; + // clear text buffers + plot.ClearTextBuffer(); + plot.SetTitle(title_id); - // NextPlotData ----------------------------------------------------------- - - // linked axes - plot.XAxis.LinkedMin = gp.NextPlotData.LinkedXmin; - plot.XAxis.LinkedMax = gp.NextPlotData.LinkedXmax; - PullLinkedAxis(plot.XAxis); - for (int i = 0; i < IMPLOT_Y_AXES; ++i) { - plot.YAxis[i].LinkedMin = gp.NextPlotData.LinkedYmin[i]; - plot.YAxis[i].LinkedMax = gp.NextPlotData.LinkedYmax[i]; - PullLinkedAxis(plot.YAxis[i]); - } - - if (gp.NextPlotData.HasXRange) { - if (!plot.Initialized || gp.NextPlotData.XRangeCond == ImGuiCond_Always) - plot.XAxis.SetRange(gp.NextPlotData.XRange); - } - - for (int i = 0; i < IMPLOT_Y_AXES; i++) { - if (gp.NextPlotData.HasYRange[i]) { - if (!plot.Initialized || gp.NextPlotData.YRangeCond[i] == ImGuiCond_Always) - plot.YAxis[i].SetRange(gp.NextPlotData.YRange[i]); - } - } - - // Initialization ------------------------------------------------------------ - - if (!plot.Initialized) { - if (!ImHasFlag(plot.XAxis.Flags,ImPlotAxisFlags_NoInitialFit) && !gp.NextPlotData.HasXRange && !gp.NextPlotData.LinkedXmin && !gp.NextPlotData.LinkedXmax) - gp.FitThisFrame = gp.FitX = true; - for (int i = 0; i < IMPLOT_Y_AXES; ++i) { - if (!ImHasFlag(plot.YAxis[i].Flags,ImPlotAxisFlags_NoInitialFit) && !gp.NextPlotData.HasYRange[i] && !gp.NextPlotData.LinkedYmin[i] && !gp.NextPlotData.LinkedYmax[i]) - gp.FitThisFrame = gp.FitY[i] = true; - } - } - - // AXIS STATES ------------------------------------------------------------ - plot.XAxis.HasRange = gp.NextPlotData.HasXRange; plot.XAxis.RangeCond = gp.NextPlotData.XRangeCond; plot.XAxis.Present = true; - plot.YAxis[0].HasRange = gp.NextPlotData.HasYRange[0]; plot.YAxis[0].RangeCond = gp.NextPlotData.YRangeCond[0]; plot.YAxis[0].Present = true; - plot.YAxis[1].HasRange = gp.NextPlotData.HasYRange[1]; plot.YAxis[1].RangeCond = gp.NextPlotData.YRangeCond[1]; plot.YAxis[1].Present = ImHasFlag(plot.Flags, ImPlotFlags_YAxis2); - plot.YAxis[2].HasRange = gp.NextPlotData.HasYRange[2]; plot.YAxis[2].RangeCond = gp.NextPlotData.YRangeCond[2]; plot.YAxis[2].Present = ImHasFlag(plot.Flags, ImPlotFlags_YAxis3); - - for (int i = 0; i < IMPLOT_Y_AXES; ++i) { - if (!ImHasFlag(plot.XAxis.Flags, ImPlotAxisFlags_LogScale) && !ImHasFlag(plot.YAxis[i].Flags, ImPlotAxisFlags_LogScale)) - gp.Scales[i] = ImPlotScale_LinLin; - else if (ImHasFlag(plot.XAxis.Flags, ImPlotAxisFlags_LogScale) && !ImHasFlag(plot.YAxis[i].Flags, ImPlotAxisFlags_LogScale)) - gp.Scales[i] = ImPlotScale_LogLin; - else if (!ImHasFlag(plot.XAxis.Flags, ImPlotAxisFlags_LogScale) && ImHasFlag(plot.YAxis[i].Flags, ImPlotAxisFlags_LogScale)) - gp.Scales[i] = ImPlotScale_LinLog; - else if (ImHasFlag(plot.XAxis.Flags, ImPlotAxisFlags_LogScale) && ImHasFlag(plot.YAxis[i].Flags, ImPlotAxisFlags_LogScale)) - gp.Scales[i] = ImPlotScale_LogLog; - } - - // constraints - plot.XAxis.Constrain(); - for (int i = 0; i < IMPLOT_Y_AXES; ++i) - plot.YAxis[i].Constrain(); - - // constrain equal axes for primary x and y if not approximately equal - // constrains x to y since x pixel size depends on y labels width, and causes feedback loops in opposite case - if (ImHasFlag(plot.Flags, ImPlotFlags_Equal)) { - double xar = plot.XAxis.GetAspect(); - double yar = plot.YAxis[0].GetAspect(); - // edge case: user has set x range this frame, so fit y to x so that we honor their request for x range - // NB: because of feedback across several frames, the user's x request may not be perfectly honored - if (gp.NextPlotData.HasXRange) { - plot.YAxis[0].SetAspect(xar); - } - else { - if (!ImAlmostEqual(xar,yar) && !plot.YAxis[0].IsInputLocked()) - plot.XAxis.SetAspect(yar); - } - } - - // AXIS COLORS ----------------------------------------------------------------- - - UpdateAxisColors(ImPlotCol_XAxis, &plot.XAxis); - UpdateAxisColors(ImPlotCol_YAxis, &plot.YAxis[0]); - UpdateAxisColors(ImPlotCol_YAxis2, &plot.YAxis[1]); - UpdateAxisColors(ImPlotCol_YAxis3, &plot.YAxis[2]); - - // SIZING, BB, PADDING, HOVER ----------------------------------------------------------- - - // frame size + // set frame size ImVec2 frame_size; if (gp.CurrentSubplot != NULL) frame_size = gp.CurrentSubplot->CellSize; @@ -2097,26 +2294,76 @@ bool BeginPlot(const char* title, const char* x_label, const char* y1_label, con plot.FrameRect = ImRect(Window->DC.CursorPos, Window->DC.CursorPos + frame_size); ImGui::ItemSize(plot.FrameRect); - if (!ImGui::ItemAdd(plot.FrameRect, ID, &plot.FrameRect) && !gp.CurrentSubplot) { + if (!ImGui::ItemAdd(plot.FrameRect, plot.ID, &plot.FrameRect) && !gp.CurrentSubplot) { ResetCtxForNextPlot(GImPlot); return false; } - // NB: ImGuiButtonFlags_AllowItemOverlap and SetItemAllowOverlap() required for DragLine and DragPoint - ImGui::ButtonBehavior(plot.FrameRect,plot.ID,&plot.FrameHovered,&plot.FrameHeld,ImGuiButtonFlags_AllowItemOverlap); - ImGui::SetItemAllowOverlap(); + + // setup items (or dont) + if (gp.CurrentItems == NULL) + gp.CurrentItems = &plot.Items; + + return true; +} + +void SetupFinish() { + IM_ASSERT_USER_ERROR(GImPlot != NULL, "No current context. Did you call ImPlot::CreateContext() or ImPlot::SetCurrentContext()?"); + IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != NULL, "SetupFinish needs to be called after BeginPlot!"); + + ImPlotContext& gp = *GImPlot; + ImGuiContext& G = *GImGui; + ImDrawList& DrawList = *G.CurrentWindow->DrawList; + const ImGuiStyle& Style = G.Style; + + ImPlotPlot &plot = *gp.CurrentPlot; + + // lock setup + plot.SetupLocked = true; + + // finalize axes + for (int i = 0; i < ImAxis_COUNT; ++i) { + if (plot.Axes[i].Enabled) { + plot.Axes[i].Constrain(); + if (!plot.Initialized && plot.Axes[i].CanInitFit()) + plot.FitThisFrame = plot.Axes[i].FitThisFrame = true; + } + } + + // setup NULL orthogonal axes + const bool axis_equal = ImHasFlag(plot.Flags, ImPlotFlags_Equal); + for (int ix = ImAxis_X1, iy = ImAxis_Y1; ix < ImAxis_Y1 || iy < ImAxis_COUNT; ++ix, ++iy) { + ImPlotAxis& x_axis = plot.Axes[ix]; + ImPlotAxis& y_axis = plot.Axes[iy]; + if (x_axis.Enabled && y_axis.Enabled) { + if (x_axis.OrthoAxis == NULL) + x_axis.OrthoAxis = &y_axis; + if (y_axis.OrthoAxis == NULL) + y_axis.OrthoAxis = &x_axis; + } + else if (x_axis.Enabled) + { + if (x_axis.OrthoAxis == NULL && !axis_equal) + x_axis.OrthoAxis = &plot.Axes[ImAxis_Y1]; + } + else if (y_axis.Enabled) { + if (y_axis.OrthoAxis == NULL && !axis_equal) + y_axis.OrthoAxis = &plot.Axes[ImAxis_X1]; + } + } // canvas/axes bb plot.CanvasRect = ImRect(plot.FrameRect.Min + gp.Style.PlotPadding, plot.FrameRect.Max - gp.Style.PlotPadding); plot.AxesRect = plot.FrameRect; // outside legend adjustments - if (!ImHasFlag(plot.Flags, ImPlotFlags_NoLegend) && plot.Items.GetLegendCount() > 0 && plot.Items.Legend.Outside) { - const ImVec2 legend_size = CalcLegendSize(plot.Items, gp.Style.LegendInnerPadding, gp.Style.LegendSpacing, plot.Items.Legend.Orientation); - const bool west = ImHasFlag(plot.Items.Legend.Location, ImPlotLocation_West) && !ImHasFlag(plot.Items.Legend.Location, ImPlotLocation_East); - const bool east = ImHasFlag(plot.Items.Legend.Location, ImPlotLocation_East) && !ImHasFlag(plot.Items.Legend.Location, ImPlotLocation_West); - const bool north = ImHasFlag(plot.Items.Legend.Location, ImPlotLocation_North) && !ImHasFlag(plot.Items.Legend.Location, ImPlotLocation_South); - const bool south = ImHasFlag(plot.Items.Legend.Location, ImPlotLocation_South) && !ImHasFlag(plot.Items.Legend.Location, ImPlotLocation_North); - const bool horz = plot.Items.Legend.Orientation == ImPlotOrientation_Horizontal; + if (!ImHasFlag(plot.Flags, ImPlotFlags_NoLegend) && plot.Items.GetLegendCount() > 0 && ImHasFlag(plot.Items.Legend.Flags, ImPlotLegendFlags_Outside)) { + ImPlotLegend& legend = plot.Items.Legend; + const bool horz = ImHasFlag(legend.Flags, ImPlotLegendFlags_Horizontal); + const ImVec2 legend_size = CalcLegendSize(plot.Items, gp.Style.LegendInnerPadding, gp.Style.LegendSpacing, !horz); + const bool west = ImHasFlag(legend.Location, ImPlotLocation_West) && !ImHasFlag(legend.Location, ImPlotLocation_East); + const bool east = ImHasFlag(legend.Location, ImPlotLocation_East) && !ImHasFlag(legend.Location, ImPlotLocation_West); + const bool north = ImHasFlag(legend.Location, ImPlotLocation_North) && !ImHasFlag(legend.Location, ImPlotLocation_South); + const bool south = ImHasFlag(legend.Location, ImPlotLocation_South) && !ImHasFlag(legend.Location, ImPlotLocation_North); if ((west && !horz) || (west && horz && !north && !south)) { plot.CanvasRect.Min.x += (legend_size.x + gp.Style.LegendPadding.x); plot.AxesRect.Min.x += (legend_size.x + gp.Style.PlotPadding.x); @@ -2135,217 +2382,243 @@ bool BeginPlot(const char* title, const char* x_label, const char* y1_label, con } } - gp.RenderX = (!ImHasFlag(plot.XAxis.Flags, ImPlotAxisFlags_NoGridLines) || - !ImHasFlag(plot.XAxis.Flags, ImPlotAxisFlags_NoTickMarks) || - !ImHasFlag(plot.XAxis.Flags, ImPlotAxisFlags_NoTickLabels)); - for (int i = 0; i < IMPLOT_Y_AXES; i++) { - gp.RenderY[i] = plot.YAxis[i].Present && - (!ImHasFlag(plot.YAxis[i].Flags, ImPlotAxisFlags_NoGridLines) || - !ImHasFlag(plot.YAxis[i].Flags, ImPlotAxisFlags_NoTickMarks) || - !ImHasFlag(plot.YAxis[i].Flags, ImPlotAxisFlags_NoTickLabels)); - } - // plot bb + float pad_top = 0, pad_bot = 0, pad_left = 0, pad_right = 0; - // (1) calc top/bot padding and plot height + // (0) calc top padding form title ImVec2 title_size(0.0f, 0.0f); - const float txt_height = ImGui::GetTextLineHeight(); - if (!ImHasFlag(plot.Flags, ImPlotFlags_NoTitle)){ - title_size = ImGui::CalcTextSize(title, NULL, true); + if (plot.HasTitle()) + title_size = ImGui::CalcTextSize(plot.GetTitle(), NULL, true); + if (title_size.x > 0) { + pad_top += title_size.y + gp.Style.LabelPadding.y; + plot.AxesRect.Min.y += gp.Style.PlotPadding.y + pad_top; } - const bool show_x_label = x_label && !ImHasFlag(plot.XAxis.Flags, ImPlotAxisFlags_NoLabel); + // (1) calc addition top padding and bot padding + PadAndDatumAxesX(plot,pad_top,pad_bot,gp.CurrentAlignmentH); - float pad_top = title_size.x > 0.0f ? title_size.y + gp.Style.LabelPadding.y : 0; - float pad_bot = (plot.XAxis.IsLabeled() ? ImMax(txt_height, gp.XTicks.MaxHeight) + gp.Style.LabelPadding.y + (plot.XAxis.IsTime() ? txt_height + gp.Style.LabelPadding.y : 0) : 0) - + (show_x_label ? txt_height + gp.Style.LabelPadding.y : 0); - // (1*) align plots group - if (gp.CurrentAlignmentH) - gp.CurrentAlignmentH->Update(pad_top,pad_bot); const float plot_height = plot.CanvasRect.GetHeight() - pad_top - pad_bot; // (2) get y tick labels (needed for left/right pad) - for (int i = 0; i < IMPLOT_Y_AXES; i++) { - if (gp.RenderY[i] && gp.NextPlotData.ShowDefaultTicksY[i]) { - if (ImHasFlag(plot.YAxis[i].Flags, ImPlotAxisFlags_LogScale)) - AddTicksLogarithmic(plot.YAxis[i].Range, plot_height, ImPlotOrientation_Vertical, gp.YTicks[i], GetFormatY(i)); + for (int i = 0; i < IMPLOT_NUM_Y_AXES; i++) { + ImPlotAxis& axis = plot.YAxis(i); + if (axis.WillRender() && axis.ShowDefaultTicks) { + if (axis.IsLog()) + AddTicksLogarithmic(axis.Range, + plot_height, + true, + axis.Ticks, + axis.Formatter ? axis.Formatter : DefaultFormatter, + (axis.Formatter && axis.FormatterData) ? axis.FormatterData : axis.HasFormatSpec ? axis.FormatSpec : (void*)IMPLOT_LABEL_FORMAT); else - AddTicksDefault(plot.YAxis[i].Range, plot_height, ImPlotOrientation_Vertical, gp.YTicks[i], GetFormatY(i)); + AddTicksDefault(axis.Range, + plot_height, + true, + axis.Ticks, + axis.Formatter ? axis.Formatter : DefaultFormatter, + (axis.Formatter && axis.FormatterData) ? axis.FormatterData : axis.HasFormatSpec ? axis.FormatSpec : (void*)IMPLOT_LABEL_FORMAT); } } // (3) calc left/right pad - const bool show_y1_label = y1_label && !ImHasFlag(plot.YAxis[0].Flags, ImPlotAxisFlags_NoLabel); - const bool show_y2_label = y2_label && !ImHasFlag(plot.YAxis[1].Flags, ImPlotAxisFlags_NoLabel); - const bool show_y3_label = y3_label && !ImHasFlag(plot.YAxis[2].Flags, ImPlotAxisFlags_NoLabel); - - float pad_left = (show_y1_label ? txt_height + gp.Style.LabelPadding.x : 0) - + (plot.YAxis[0].IsLabeled() ? gp.YTicks[0].MaxWidth + gp.Style.LabelPadding.x : 0); - float pad_right = ((plot.YAxis[1].Present && plot.YAxis[1].IsLabeled()) ? gp.YTicks[1].MaxWidth + gp.Style.LabelPadding.x : 0) - + ((plot.YAxis[1].Present && show_y2_label) ? txt_height + gp.Style.LabelPadding.x : 0) - + ((plot.YAxis[1].Present && plot.YAxis[2].Present) ? gp.Style.LabelPadding.x + gp.Style.MinorTickLen.y : 0) - + ((plot.YAxis[2].Present && plot.YAxis[2].IsLabeled()) ? gp.YTicks[2].MaxWidth + gp.Style.LabelPadding.x : 0) - + ((plot.YAxis[2].Present && show_y3_label) ? txt_height + gp.Style.LabelPadding.x : 0); - - // (3*) align plots group - if (gp.CurrentAlignmentV) - gp.CurrentAlignmentV->Update(pad_left,pad_right); + PadAndDatumAxesY(plot,pad_left,pad_right,gp.CurrentAlignmentV); const float plot_width = plot.CanvasRect.GetWidth() - pad_left - pad_right; // (4) get x ticks - if (gp.RenderX && gp.NextPlotData.ShowDefaultTicksX) { - if (plot.XAxis.IsTime()) - AddTicksTime(plot.XAxis.Range, plot_width, gp.XTicks); - else if (ImHasFlag(plot.XAxis.Flags, ImPlotAxisFlags_LogScale)) - AddTicksLogarithmic(plot.XAxis.Range, plot_width, ImPlotOrientation_Horizontal, gp.XTicks, GetFormatX()); - else - AddTicksDefault(plot.XAxis.Range, plot_width, ImPlotOrientation_Horizontal, gp.XTicks, GetFormatX()); + for (int i = 0; i < IMPLOT_NUM_X_AXES; i++) { + ImPlotAxis& axis = plot.XAxis(i); + if (axis.WillRender() && axis.ShowDefaultTicks) { + if (axis.IsTime()) + AddTicksTime(axis.Range, plot_width, axis.Ticks); + else if (axis.IsLog()) + AddTicksLogarithmic(axis.Range, + plot_width, + false, + axis.Ticks, + axis.Formatter ? axis.Formatter : DefaultFormatter, + (axis.Formatter && axis.FormatterData) ? axis.FormatterData : axis.HasFormatSpec ? axis.FormatSpec : (void*)IMPLOT_LABEL_FORMAT); + else + AddTicksDefault(axis.Range, + plot_width, + false, + axis.Ticks, + axis.Formatter ? axis.Formatter : DefaultFormatter, + (axis.Formatter && axis.FormatterData) ? axis.FormatterData : axis.HasFormatSpec ? axis.FormatSpec : (void*)IMPLOT_LABEL_FORMAT); + } } // (5) calc plot bb - plot.PlotRect = ImRect(plot.CanvasRect.Min + ImVec2(pad_left, pad_top), plot.CanvasRect.Max - ImVec2(pad_right, pad_bot)); - plot.PlotHovered = plot.FrameHovered && plot.PlotRect.Contains(IO.MousePos); + plot.PlotRect = ImRect(plot.CanvasRect.Min + ImVec2(pad_left, pad_top), plot.CanvasRect.Max - ImVec2(pad_right, pad_bot)); - // x axis region bb and hover - plot.XAxis.HoverRect = ImRect(plot.PlotRect.GetBL(), ImVec2(plot.PlotRect.Max.x, plot.AxesRect.Max.y)); - plot.XAxis.ExtHovered = plot.XAxis.HoverRect.Contains(IO.MousePos); - plot.XAxis.AllHovered = plot.XAxis.ExtHovered || plot.PlotHovered; + // HOVER------------------------------------------------------------ - // axis label reference - gp.YAxisReference[0] = plot.PlotRect.Min.x; - gp.YAxisReference[1] = plot.PlotRect.Max.x; - gp.YAxisReference[2] = !plot.YAxis[1].Present ? plot.PlotRect.Max.x : gp.YAxisReference[1] - + (plot.YAxis[1].IsLabeled() ? gp.Style.LabelPadding.x + gp.YTicks[1].MaxWidth : 0) - + (show_y2_label ? txt_height + gp.Style.LabelPadding.x : 0) - + gp.Style.LabelPadding.x + gp.Style.MinorTickLen.y; - - // y axis regions bb and hover - plot.YAxis[0].HoverRect = ImRect(ImVec2(plot.AxesRect.Min.x, plot.PlotRect.Min.y), ImVec2(plot.PlotRect.Min.x, plot.PlotRect.Max.y)); - plot.YAxis[1].HoverRect = plot.YAxis[2].Present - ? ImRect(plot.PlotRect.GetTR(), ImVec2(gp.YAxisReference[2], plot.PlotRect.Max.y)) - : ImRect(plot.PlotRect.GetTR(), ImVec2(plot.AxesRect.Max.x, plot.PlotRect.Max.y)); - - plot.YAxis[2].HoverRect = ImRect(ImVec2(gp.YAxisReference[2], plot.PlotRect.Min.y), ImVec2(plot.AxesRect.Max.x, plot.PlotRect.Max.y)); - - for (int i = 0; i < IMPLOT_Y_AXES; ++i) { - plot.YAxis[i].ExtHovered = plot.YAxis[i].Present && plot.YAxis[i].HoverRect.Contains(IO.MousePos); - plot.YAxis[i].AllHovered = plot.YAxis[i].ExtHovered || plot.PlotHovered; + // axes hover rect, pixel ranges + for (int i = 0; i < IMPLOT_NUM_X_AXES; ++i) { + ImPlotAxis& xax = plot.XAxis(i); + xax.HoverRect = ImRect(ImVec2(plot.PlotRect.Min.x, ImMin(xax.Datum1,xax.Datum2)), + ImVec2(plot.PlotRect.Max.x, ImMax(xax.Datum1,xax.Datum2))); + xax.PixelMin = xax.IsInverted() ? plot.PlotRect.Max.x : plot.PlotRect.Min.x; + xax.PixelMax = xax.IsInverted() ? plot.PlotRect.Min.x : plot.PlotRect.Max.x; + xax.UpdateTransformCache(); } - // AXIS ASPECT RATIOS - plot.XAxis.Pixels = plot.PlotRect.GetWidth(); - for (int i = 0; i < IMPLOT_Y_AXES; ++i) - plot.YAxis[i].Pixels = plot.PlotRect.GetHeight(); + for (int i = 0; i < IMPLOT_NUM_Y_AXES; ++i) { + ImPlotAxis& yax = plot.YAxis(i); + yax.HoverRect = ImRect(ImVec2(ImMin(yax.Datum1,yax.Datum2),plot.PlotRect.Min.y), + ImVec2(ImMax(yax.Datum1,yax.Datum2),plot.PlotRect.Max.y)); + yax.PixelMin = yax.IsInverted() ? plot.PlotRect.Min.y : plot.PlotRect.Max.y; + yax.PixelMax = yax.IsInverted() ? plot.PlotRect.Max.y : plot.PlotRect.Min.y; + yax.UpdateTransformCache(); + } + // Equal axis constraint. Must happen after we set Pixels + // constrain equal axes for primary x and y if not approximately equal + // constrains x to y since x pixel size depends on y labels width, and causes feedback loops in opposite case + if (axis_equal) { + for (int i = 0; i < IMPLOT_NUM_X_AXES; ++i) { + ImPlotAxis& x_axis = plot.XAxis(i); + if (x_axis.OrthoAxis == NULL) + continue; + double xar = x_axis.GetAspect(); + double yar = x_axis.OrthoAxis->GetAspect(); + // edge case: user has set x range this frame, so fit y to x so that we honor their request for x range + // NB: because of feedback across several frames, the user's x request may not be perfectly honored + if (x_axis.HasRange) + x_axis.OrthoAxis->SetAspect(xar); + else if (!ImAlmostEqual(xar,yar) && !x_axis.OrthoAxis->IsInputLocked()) + x_axis.SetAspect(yar); + } + } // INPUT ------------------------------------------------------------------ - HandlePlotInput(plot); + if (!ImHasFlag(plot.Flags, ImPlotFlags_NoInputs)) + UpdateInput(plot); - - UpdateTransformCache(); - - // set mouse position - for (int i = 0; i < IMPLOT_Y_AXES; i++) { - gp.MousePos[i] = PixelsToPlot(IO.MousePos, i); + // fit from FitNextPlotAxes or auto fit + for (int i = 0; i < ImAxis_COUNT; ++i) { + if (gp.NextPlotData.Fit[i] || plot.Axes[i].IsAutoFitting()) { + plot.FitThisFrame = true; + plot.Axes[i].FitThisFrame = true; + } } // RENDER ----------------------------------------------------------------- + const float txt_height = ImGui::GetTextLineHeight(); + // render frame - ImGui::RenderFrame(plot.FrameRect.Min, plot.FrameRect.Max, GetStyleColorU32(ImPlotCol_FrameBg), true, Style.FrameRounding); + if (!ImHasFlag(plot.Flags, ImPlotFlags_NoFrame)) + ImGui::RenderFrame(plot.FrameRect.Min, plot.FrameRect.Max, GetStyleColorU32(ImPlotCol_FrameBg), true, Style.FrameRounding); // grid bg DrawList.AddRectFilled(plot.PlotRect.Min, plot.PlotRect.Max, GetStyleColorU32(ImPlotCol_PlotBg)); - // transform ticks (TODO: Move this into ImPlotTickCollection) - if (gp.RenderX) { - for (int t = 0; t < gp.XTicks.Size; t++) { - ImPlotTick *xt = &gp.XTicks.Ticks[t]; - xt->PixelPos = IM_ROUND(PlotToPixels(xt->PlotPos, 0, 0).x); - } - } - for (int i = 0; i < IMPLOT_Y_AXES; i++) { - if (gp.RenderY[i]) { - for (int t = 0; t < gp.YTicks[i].Size; t++) { - ImPlotTick *yt = &gp.YTicks[i].Ticks[t]; - yt->PixelPos = IM_ROUND(PlotToPixels(0, yt->PlotPos, i).y); + // transform ticks + for (int i = 0; i < ImAxis_COUNT; i++) { + ImPlotAxis& axis = plot.Axes[i]; + if (axis.WillRender()) { + for (int t = 0; t < axis.Ticks.Size; t++) { + ImPlotTick& tk = axis.Ticks.Ticks[t]; + tk.PixelPos = IM_ROUND(axis.PlotToPixels(tk.PlotPos)); } } } // render grid (background) - PushPlotClipRect(gp.Style.PlotBorderSize == 0 ? 1.0f : 0.0f); - if (!ImHasFlag(plot.XAxis.Flags, ImPlotAxisFlags_NoGridLines) && !ImHasFlag(plot.XAxis.Flags, ImPlotAxisFlags_Foreground)) - RenderGridLinesX(DrawList, gp.XTicks, plot.PlotRect, plot.XAxis.ColorMaj, plot.XAxis.ColorMin, gp.Style.MajorGridSize.x, gp.Style.MinorGridSize.x); - for (int i = 0; i < IMPLOT_Y_AXES; i++) { - if (plot.YAxis[i].Present && !ImHasFlag(plot.YAxis[i].Flags, ImPlotAxisFlags_NoGridLines) && !ImHasFlag(plot.YAxis[i].Flags, ImPlotAxisFlags_Foreground)) - RenderGridLinesY(DrawList, gp.YTicks[i], plot.PlotRect, plot.YAxis[i].ColorMaj, plot.YAxis[i].ColorMin, gp.Style.MajorGridSize.y, gp.Style.MinorGridSize.y); + for (int i = 0; i < IMPLOT_NUM_X_AXES; i++) { + ImPlotAxis& x_axis = plot.XAxis(i); + if (x_axis.Enabled && x_axis.HasGridLines() && !x_axis.IsForeground()) + RenderGridLinesX(DrawList, x_axis.Ticks, plot.PlotRect, x_axis.ColorMaj, x_axis.ColorMin, gp.Style.MajorGridSize.x, gp.Style.MinorGridSize.x); } - PopPlotClipRect(); - - // render title - if (title_size.x > 0.0f && !ImHasFlag(plot.Flags, ImPlotFlags_NoTitle)) { - ImU32 col = GetStyleColorU32(ImPlotCol_TitleText); - AddTextCentered(&DrawList,ImVec2(plot.PlotRect.GetCenter().x, plot.CanvasRect.Min.y),col,title); + for (int i = 0; i < IMPLOT_NUM_Y_AXES; i++) { + ImPlotAxis& y_axis = plot.YAxis(i); + if (y_axis.Enabled && y_axis.HasGridLines() && !y_axis.IsForeground()) + RenderGridLinesY(DrawList, y_axis.Ticks, plot.PlotRect, y_axis.ColorMaj, y_axis.ColorMin, gp.Style.MajorGridSize.y, gp.Style.MinorGridSize.y); } - // render axis labels - if (show_x_label) { - const ImVec2 xLabel_size = ImGui::CalcTextSize(x_label); - const ImVec2 xLabel_pos(plot.PlotRect.GetCenter().x - xLabel_size.x * 0.5f, plot.CanvasRect.Max.y - txt_height); - DrawList.AddText(xLabel_pos, plot.XAxis.ColorTxt, x_label); - } - - if (show_y1_label) { - const ImVec2 yLabel_size = CalcTextSizeVertical(y1_label); - const ImVec2 yLabel_pos(plot.CanvasRect.Min.x, plot.PlotRect.GetCenter().y + yLabel_size.y * 0.5f); - AddTextVertical(&DrawList, yLabel_pos, plot.YAxis[0].ColorTxt, y1_label); - } - - const char* y_labels[] = {y2_label, y3_label}; - for (int i = 1; i < IMPLOT_Y_AXES; i++) { - const char* current_label = y_labels[i-1]; - if (plot.YAxis[i].Present && current_label && !ImHasFlag(plot.YAxis[i].Flags, ImPlotAxisFlags_NoLabel)) { - const ImVec2 yLabel_size = CalcTextSizeVertical(current_label); - float label_offset = (plot.YAxis[i].IsLabeled() ? gp.YTicks[i].MaxWidth + gp.Style.LabelPadding.x : 0.0f) + gp.Style.LabelPadding.x; - const ImVec2 yLabel_pos(gp.YAxisReference[i] + label_offset, plot.PlotRect.GetCenter().y + yLabel_size.y * 0.5f); - AddTextVertical(&DrawList, yLabel_pos, plot.YAxis[i].ColorTxt, current_label); - } - } - - // render tick labels - ImGui::PushClipRect(plot.FrameRect.Min, plot.FrameRect.Max, true); - if (!ImHasFlag(plot.XAxis.Flags, ImPlotAxisFlags_NoTickLabels)) { - for (int t = 0; t < gp.XTicks.Size; t++) { - ImPlotTick *xt = &gp.XTicks.Ticks[t]; - if (xt->ShowLabel && xt->PixelPos >= plot.PlotRect.Min.x - 1 && xt->PixelPos <= plot.PlotRect.Max.x + 1) - DrawList.AddText(ImVec2(xt->PixelPos - xt->LabelSize.x * 0.5f, plot.PlotRect.Max.y + gp.Style.LabelPadding.y + xt->Level * (txt_height + gp.Style.LabelPadding.y)), - plot.XAxis.ColorTxt, gp.XTicks.GetText(t)); + // render x axis button, label, tick labels + for (int i = 0; i < IMPLOT_NUM_X_AXES; i++) { + ImPlotAxis& ax = plot.XAxis(i); + if (!ax.Enabled) + continue; + if ((ax.Hovered || ax.Held) && !plot.Held) + DrawList.AddRectFilled(ax.HoverRect.Min, ax.HoverRect.Max, ax.Held ? ax.ColorAct : ax.ColorHov); + else if (ax.ColorHiLi != IM_COL32_BLACK_TRANS) { + DrawList.AddRectFilled(ax.HoverRect.Min, ax.HoverRect.Max, ax.ColorHiLi); + ax.ColorHiLi = IM_COL32_BLACK_TRANS; } - } - for (int i = 0; i < IMPLOT_Y_AXES; i++) { - if (plot.YAxis[i].Present && !ImHasFlag(plot.YAxis[i].Flags, ImPlotAxisFlags_NoTickLabels)) { - for (int t = 0; t < gp.YTicks[i].Size; t++) { - const float x_start = gp.YAxisReference[i] + (i == 0 ? (-gp.Style.LabelPadding.x - gp.YTicks[i].Ticks[t].LabelSize.x) : gp.Style.LabelPadding.x); - ImPlotTick *yt = &gp.YTicks[i].Ticks[t]; - if (yt->ShowLabel && yt->PixelPos >= plot.PlotRect.Min.y - 1 && yt->PixelPos <= plot.PlotRect.Max.y + 1) { - ImVec2 start(x_start, yt->PixelPos - 0.5f * yt->LabelSize.y); - DrawList.AddText(start, plot.YAxis[i].ColorTxt, gp.YTicks[i].GetText(t)); + else if (ax.ColorBg != IM_COL32_BLACK_TRANS) { + DrawList.AddRectFilled(ax.HoverRect.Min, ax.HoverRect.Max, ax.ColorBg); + } + const ImPlotTickCollection& tkc = ax.Ticks; + const bool opp = ax.IsOpposite(); + if (ax.HasLabel()) { + const char* label = plot.GetAxisLabel(ax); + const ImVec2 label_size = ImGui::CalcTextSize(label); + const float label_offset = (ax.HasTickLabels() ? ax.Ticks.MaxSize.y + gp.Style.LabelPadding.y : 0.0f) + + (ax.IsTime() ? txt_height + gp.Style.LabelPadding.y : 0) + + gp.Style.LabelPadding.y; + const ImVec2 label_pos(plot.PlotRect.GetCenter().x - label_size.x * 0.5f, + opp ? ax.Datum1 - label_offset - label_size.y : ax.Datum1 + label_offset); + DrawList.AddText(label_pos, ax.ColorTxt, label); + } + if (ax.HasTickLabels()) { + for (int j = 0; j < tkc.Size; ++j) { + const ImPlotTick& tk = tkc.Ticks[j]; + const float datum = ax.Datum1 + (opp ? (-gp.Style.LabelPadding.y -txt_height -tk.Level * (txt_height + gp.Style.LabelPadding.y)) + : gp.Style.LabelPadding.y + tk.Level * (txt_height + gp.Style.LabelPadding.y)); + if (tk.ShowLabel && tk.PixelPos >= plot.PlotRect.Min.x - 1 && tk.PixelPos <= plot.PlotRect.Max.x + 1) { + ImVec2 start(tk.PixelPos - 0.5f * tk.LabelSize.x, datum); + DrawList.AddText(start, ax.ColorTxt, tkc.GetText(j)); } } } } - ImGui::PopClipRect(); + + // render y axis button, label, tick labels + for (int i = 0; i < IMPLOT_NUM_Y_AXES; i++) { + ImPlotAxis& ax = plot.YAxis(i); + if (!ax.Enabled) + continue; + if ((ax.Hovered || ax.Held) && !plot.Held) + DrawList.AddRectFilled(ax.HoverRect.Min, ax.HoverRect.Max, ax.Held ? ax.ColorAct : ax.ColorHov); + else if (ax.ColorHiLi != IM_COL32_BLACK_TRANS) { + DrawList.AddRectFilled(ax.HoverRect.Min, ax.HoverRect.Max, ax.ColorHiLi); + ax.ColorHiLi = IM_COL32_BLACK_TRANS; + } + else if (ax.ColorBg != IM_COL32_BLACK_TRANS) { + DrawList.AddRectFilled(ax.HoverRect.Min, ax.HoverRect.Max, ax.ColorBg); + } + const ImPlotTickCollection& tkc = ax.Ticks; + const bool opp = ax.IsOpposite(); + if (ax.HasLabel()) { + const char* label = plot.GetAxisLabel(ax); + const ImVec2 label_size = CalcTextSizeVertical(label); + const float label_offset = (ax.HasTickLabels() ? ax.Ticks.MaxSize.x + gp.Style.LabelPadding.x : 0.0f) + + gp.Style.LabelPadding.x; + const ImVec2 label_pos(opp ? ax.Datum1 + label_offset : ax.Datum1 - label_offset - label_size.x, + plot.PlotRect.GetCenter().y + label_size.y * 0.5f); + AddTextVertical(&DrawList, label_pos, ax.ColorTxt, label); + } + if (ax.HasTickLabels()) { + for (int j = 0; j < tkc.Size; ++j) { + const ImPlotTick& tk = tkc.Ticks[j]; + const float datum = ax.Datum1 + (opp ? gp.Style.LabelPadding.x : (-gp.Style.LabelPadding.x - tk.LabelSize.x)); + if (tk.ShowLabel && tk.PixelPos >= plot.PlotRect.Min.y - 1 && tk.PixelPos <= plot.PlotRect.Max.y + 1) { + ImVec2 start(datum, tk.PixelPos - 0.5f * tk.LabelSize.y); + DrawList.AddText(start, ax.ColorTxt, tkc.GetText(j)); + } + } + } + } + + // clear legend (TODO: put elsewhere) plot.Items.Legend.Reset(); - // setup items (or dont) - if (gp.CurrentItems == NULL) - gp.CurrentItems = &plot.Items; - // push ID to see item hashes + // push ID to set item hashes (NB: !!!THIS PROBABLY NEEDS TO BE IN BEGIN PLOT!!!!) ImGui::PushOverrideID(gp.CurrentItems->ID); - return true; } //----------------------------------------------------------------------------- @@ -2354,67 +2627,96 @@ bool BeginPlot(const char* title, const char* x_label, const char* y1_label, con void EndPlot() { IM_ASSERT_USER_ERROR(GImPlot != NULL, "No current context. Did you call ImPlot::CreateContext() or ImPlot::SetCurrentContext()?"); + IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != NULL, "Mismatched BeginPlot()/EndPlot()!"); + + SetupLock(); + ImPlotContext& gp = *GImPlot; - IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "Mismatched BeginPlot()/EndPlot()!"); ImGuiContext &G = *GImGui; - ImPlotPlot &plot = *gp.CurrentPlot; + ImPlotPlot &plot = *gp.CurrentPlot; ImGuiWindow * Window = G.CurrentWindow; ImDrawList & DrawList = *Window->DrawList; const ImGuiIO & IO = ImGui::GetIO(); - // AXIS STATES ------------------------------------------------------------ - - const bool any_y_dragging = plot.YAxis[0].Dragging || plot.YAxis[1].Dragging || plot.YAxis[2].Dragging; - // FINAL RENDER ----------------------------------------------------------- + const bool render_border = gp.Style.PlotBorderSize > 0 && gp.Style.Colors[ImPlotCol_PlotBorder].w > 0; + const bool any_x_held = plot.Held || AnyAxesHeld(&plot.Axes[ImAxis_X1], IMPLOT_NUM_X_AXES); + const bool any_y_held = plot.Held || AnyAxesHeld(&plot.Axes[ImAxis_Y1], IMPLOT_NUM_Y_AXES); + + ImGui::PushClipRect(plot.FrameRect.Min, plot.FrameRect.Max, true); + // render grid (foreground) - PushPlotClipRect(gp.Style.PlotBorderSize == 0 ? 1.0f : 0.0f); - if (!ImHasFlag(plot.XAxis.Flags, ImPlotAxisFlags_NoGridLines) && ImHasFlag(plot.XAxis.Flags, ImPlotAxisFlags_Foreground)) - RenderGridLinesX(DrawList, gp.XTicks, plot.PlotRect, plot.XAxis.ColorMaj, plot.XAxis.ColorMaj, gp.Style.MajorGridSize.x, gp.Style.MinorGridSize.x); - for (int i = 0; i < IMPLOT_Y_AXES; i++) { - if (plot.YAxis[i].Present && !ImHasFlag(plot.YAxis[i].Flags, ImPlotAxisFlags_NoGridLines) && ImHasFlag(plot.YAxis[i].Flags, ImPlotAxisFlags_Foreground)) - RenderGridLinesY(DrawList, gp.YTicks[i], plot.PlotRect, plot.YAxis[i].ColorMaj, plot.YAxis[i].ColorMin, gp.Style.MajorGridSize.y, gp.Style.MinorGridSize.y); + for (int i = 0; i < IMPLOT_NUM_X_AXES; i++) { + ImPlotAxis& x_axis = plot.XAxis(i); + if (x_axis.Enabled && x_axis.HasGridLines() && x_axis.IsForeground()) + RenderGridLinesX(DrawList, x_axis.Ticks, plot.PlotRect, x_axis.ColorMaj, x_axis.ColorMin, gp.Style.MajorGridSize.x, gp.Style.MinorGridSize.x); } - PopPlotClipRect(); - - // render x-ticks - PushPlotClipRect(); - if (!ImHasFlag(plot.XAxis.Flags, ImPlotAxisFlags_NoTickMarks)) { - for (int t = 0; t < gp.XTicks.Size; t++) { - ImPlotTick *xt = &gp.XTicks.Ticks[t]; - if (xt->Level == 0) - DrawList.AddLine(ImVec2(xt->PixelPos, plot.PlotRect.Max.y), - ImVec2(xt->PixelPos, plot.PlotRect.Max.y - (xt->Major ? gp.Style.MajorTickLen.x : gp.Style.MinorTickLen.x)), - plot.XAxis.ColorMaj, - xt->Major ? gp.Style.MajorTickSize.x : gp.Style.MinorTickSize.x); - } + for (int i = 0; i < IMPLOT_NUM_Y_AXES; i++) { + ImPlotAxis& y_axis = plot.YAxis(i); + if (y_axis.Enabled && y_axis.HasGridLines() && y_axis.IsForeground()) + RenderGridLinesY(DrawList, y_axis.Ticks, plot.PlotRect, y_axis.ColorMaj, y_axis.ColorMin, gp.Style.MajorGridSize.y, gp.Style.MinorGridSize.y); } - PopPlotClipRect(); - // render y-ticks - ImGui::PushClipRect(plot.PlotRect.Min, ImVec2(plot.FrameRect.Max.x, plot.PlotRect.Max.y), true); - int axis_count = 0; - for (int i = 0; i < IMPLOT_Y_AXES; i++) { - if (!plot.YAxis[i].Present) { continue; } - axis_count++; - float x_start = gp.YAxisReference[i]; - if (!ImHasFlag(plot.YAxis[i].Flags, ImPlotAxisFlags_NoTickMarks)) { - float direction = (i == 0) ? 1.0f : -1.0f; - bool no_major = axis_count >= 3; - for (int t = 0; t < gp.YTicks[i].Size; t++) { - ImPlotTick *yt = &gp.YTicks[i].Ticks[t]; - ImVec2 start = ImVec2(x_start, yt->PixelPos); - DrawList.AddLine(start, - start + ImVec2(direction * ((!no_major && yt->Major) ? gp.Style.MajorTickLen.y : gp.Style.MinorTickLen.y), 0), - plot.YAxis[i].ColorMaj, - (!no_major && yt->Major) ? gp.Style.MajorTickSize.y : gp.Style.MinorTickSize.y); + + // render title + if (plot.HasTitle()) { + ImU32 col = GetStyleColorU32(ImPlotCol_TitleText); + AddTextCentered(&DrawList,ImVec2(plot.PlotRect.GetCenter().x, plot.CanvasRect.Min.y),col,plot.GetTitle()); + } + + // render x ticks + int count_B = 0, count_T = 0; + for (int i = 0; i < IMPLOT_NUM_X_AXES; i++) { + const ImPlotAxis& ax = plot.XAxis(i); + if (!ax.Enabled) + continue; + const ImPlotTickCollection& tkc = ax.Ticks; + const bool opp = ax.IsOpposite(); + const bool aux = ((opp && count_T > 0)||(!opp && count_B > 0)); + if (ax.HasTickMarks()) { + const float direction = opp ? 1.0f : -1.0f; + for (int j = 0; j < tkc.Size; ++j) { + const ImPlotTick& tk = tkc.Ticks[j]; + if (tk.Level != 0 || tk.PixelPos < plot.PlotRect.Min.x || tk.PixelPos > plot.PlotRect.Max.x) + continue; + const ImVec2 start(tk.PixelPos, ax.Datum1); + const float len = (!aux && tk.Major) ? gp.Style.MajorTickLen.x : gp.Style.MinorTickLen.x; + const float thk = (!aux && tk.Major) ? gp.Style.MajorTickSize.x : gp.Style.MinorTickSize.x; + DrawList.AddLine(start, start + ImVec2(0,direction*len), ax.ColorTick, thk); } + if (aux || !render_border) + DrawList.AddLine(ImVec2(plot.PlotRect.Min.x,ax.Datum1), ImVec2(plot.PlotRect.Max.x,ax.Datum1), ax.ColorTick, gp.Style.MinorTickSize.x); } - if (axis_count >= 3) { - // Draw a bar next to the ticks to act as a visual separator. - DrawList.AddLine(ImVec2(x_start, plot.PlotRect.Min.y), ImVec2(x_start, plot.PlotRect.Max.y), GetStyleColorU32(ImPlotCol_YAxisGrid3), 1); + count_B += !opp; + count_T += opp; + } + + // render y ticks + int count_L = 0, count_R = 0; + for (int i = 0; i < IMPLOT_NUM_Y_AXES; i++) { + const ImPlotAxis& ax = plot.YAxis(i); + if (!ax.Enabled) + continue; + const ImPlotTickCollection& tkc = ax.Ticks; + const bool opp = ax.IsOpposite(); + const bool aux = ((opp && count_R > 0)||(!opp && count_L > 0)); + if (ax.HasTickMarks()) { + const float direction = opp ? -1.0f : 1.0f; + for (int j = 0; j < tkc.Size; ++j) { + const ImPlotTick& tk = tkc.Ticks[j]; + if (tk.Level != 0 || tk.PixelPos < plot.PlotRect.Min.y || tk.PixelPos > plot.PlotRect.Max.y) + continue; + const ImVec2 start(ax.Datum1, tk.PixelPos); + const float len = (!aux && tk.Major) ? gp.Style.MajorTickLen.y : gp.Style.MinorTickLen.y; + const float thk = (!aux && tk.Major) ? gp.Style.MajorTickSize.y : gp.Style.MinorTickSize.y; + DrawList.AddLine(start, start + ImVec2(direction*len,0), ax.ColorTick, thk); + } + if (aux || !render_border) + DrawList.AddLine(ImVec2(ax.Datum1, plot.PlotRect.Min.y), ImVec2(ax.Datum1, plot.PlotRect.Max.y), ax.ColorTick, gp.Style.MinorTickSize.y); } + count_L += !opp; + count_R += opp; } ImGui::PopClipRect(); @@ -2461,12 +2763,9 @@ void EndPlot() { // render selection if (plot.Selected) RenderSelectionRect(DrawList, plot.SelectRect.Min + plot.PlotRect.Min, plot.SelectRect.Max + plot.PlotRect.Min, GetStyleColorVec4(ImPlotCol_Selection)); - // render query - if (plot.Queried) - RenderSelectionRect(DrawList, plot.QueryRect.Min + plot.PlotRect.Min, plot.QueryRect.Max + plot.PlotRect.Min, GetStyleColorVec4(ImPlotCol_Query)); // render crosshairs - if (ImHasFlag(plot.Flags, ImPlotFlags_Crosshairs) && plot.PlotHovered && !(plot.XAxis.Dragging || any_y_dragging) && !plot.Selecting && !plot.Querying && !plot.Items.Legend.Hovered) { + if (ImHasFlag(plot.Flags, ImPlotFlags_Crosshairs) && plot.Hovered && !(any_x_held || any_y_held) && !plot.Selecting && !plot.Items.Legend.Hovered) { ImGui::SetMouseCursor(ImGuiMouseCursor_None); ImVec2 xy = IO.MousePos; ImVec2 h1(plot.PlotRect.Min.x, xy.y); @@ -2485,71 +2784,140 @@ void EndPlot() { } // render mouse pos - if (!ImHasFlag(plot.Flags, ImPlotFlags_NoMousePos) && plot.PlotHovered) { - char buffer[128] = {}; - ImBufferWriter writer(buffer, sizeof(buffer)); - // x - if (ImHasFlag(plot.XAxis.Flags, ImPlotAxisFlags_Time)) { - ImPlotTimeUnit unit = GetUnitForRange(plot.XAxis.Range.Size() / (plot.PlotRect.GetWidth() / 100)); - const int written = FormatDateTime(ImPlotTime::FromDouble(gp.MousePos[0].x), &writer.Buffer[writer.Pos], writer.Size - writer.Pos - 1, GetDateTimeFmt(TimeFormatMouseCursor, unit)); - if (written > 0) - writer.Pos += ImMin(written, writer.Size - writer.Pos - 1); + if (!ImHasFlag(plot.Flags, ImPlotFlags_NoMouseText) && (plot.Hovered || ImHasFlag(plot.MouseTextFlags, ImPlotMouseTextFlags_ShowAlways))) { + + const bool no_aux = ImHasFlag(plot.MouseTextFlags, ImPlotMouseTextFlags_NoAuxAxes); + const bool no_fmt = ImHasFlag(plot.MouseTextFlags, ImPlotMouseTextFlags_NoFormat); + + ImGuiTextBuffer& builder = gp.MousePosStringBuilder; + builder.Buf.shrink(0); + char buff[IMPLOT_LABEL_MAX_SIZE]; + + const int num_x = no_aux ? 1 : IMPLOT_NUM_X_AXES; + for (int i = 0; i < num_x; ++i) { + ImPlotAxis& x_axis = plot.XAxis(i); + if (!x_axis.Enabled) + continue; + if (i > 0) + builder.append(", ("); + double v = x_axis.PixelsToPlot(IO.MousePos.x); + no_fmt ? DefaultFormatter(v,buff,IMPLOT_LABEL_MAX_SIZE,(void*)IMPLOT_LABEL_FORMAT) + : LabelAxisValue(x_axis,v,buff,IMPLOT_LABEL_MAX_SIZE,true); + builder.append(buff); + if (i > 0) + builder.append(")"); } - else { - writer.Write(GetFormatX(), RoundAxisValue(plot.XAxis, gp.XTicks, gp.MousePos[0].x)); + builder.append(", "); + const int num_y = no_aux ? 1 : IMPLOT_NUM_Y_AXES; + for (int i = 0; i < num_y; ++i) { + ImPlotAxis& y_axis = plot.YAxis(i); + if (!y_axis.Enabled) + continue; + if (i > 0) + builder.append(", ("); + double v = y_axis.PixelsToPlot(IO.MousePos.y); + no_fmt ? DefaultFormatter(v,buff,IMPLOT_LABEL_MAX_SIZE,(void*)IMPLOT_LABEL_FORMAT) + : LabelAxisValue(y_axis,v,buff,IMPLOT_LABEL_MAX_SIZE,true); + builder.append(buff); + if (i > 0) + builder.append(")"); } - // y1 - writer.Write(", "); - writer.Write(GetFormatY(0), RoundAxisValue(plot.YAxis[0], gp.YTicks[0], gp.MousePos[0].y)); - // y2 - if (ImHasFlag(plot.Flags, ImPlotFlags_YAxis2)) { - writer.Write(", ("); - writer.Write(GetFormatY(1), RoundAxisValue(plot.YAxis[1], gp.YTicks[1], gp.MousePos[1].y)); - writer.Write(")"); + + if (!builder.empty()) { + const ImVec2 size = ImGui::CalcTextSize(builder.c_str()); + const ImVec2 pos = GetLocationPos(plot.PlotRect, size, plot.MouseTextLocation, gp.Style.MousePosPadding); + DrawList.AddText(pos, GetStyleColorU32(ImPlotCol_InlayText), builder.c_str()); } - // y3 - if (ImHasFlag(plot.Flags, ImPlotFlags_YAxis3)) { - writer.Write(", ("); - writer.Write(GetFormatY(2), RoundAxisValue(plot.YAxis[2], gp.YTicks[2], gp.MousePos[2].y)); - writer.Write(")"); - } - const ImVec2 size = ImGui::CalcTextSize(buffer); - const ImVec2 pos = GetLocationPos(plot.PlotRect, size, plot.MousePosLocation, gp.Style.MousePosPadding); - DrawList.AddText(pos, GetStyleColorU32(ImPlotCol_InlayText), buffer); } PopPlotClipRect(); + // axis side switch + if (!plot.Held) { + ImVec2 mouse_pos = ImGui::GetIO().MousePos; + ImRect trigger_rect = plot.PlotRect; + trigger_rect.Expand(-10); + for (int i = 0; i < IMPLOT_NUM_X_AXES; ++i) { + ImPlotAxis& x_axis = plot.XAxis(i); + if (x_axis.Held && plot.PlotRect.Contains(mouse_pos)) { + const bool opp = ImHasFlag(x_axis.Flags, ImPlotAxisFlags_Opposite); + if (!opp) { + ImRect rect(plot.PlotRect.Min.x - 5, plot.PlotRect.Min.y - 5, + plot.PlotRect.Max.x + 5, plot.PlotRect.Min.y + 5); + if (mouse_pos.y < plot.PlotRect.Max.y - 10) + DrawList.AddRectFilled(rect.Min, rect.Max, x_axis.ColorHov); + if (rect.Contains(mouse_pos)) + x_axis.Flags |= ImPlotAxisFlags_Opposite; + } + else { + ImRect rect(plot.PlotRect.Min.x - 5, plot.PlotRect.Max.y - 5, + plot.PlotRect.Max.x + 5, plot.PlotRect.Max.y + 5); + if (mouse_pos.y > plot.PlotRect.Min.y + 10) + DrawList.AddRectFilled(rect.Min, rect.Max, x_axis.ColorHov); + if (rect.Contains(mouse_pos)) + x_axis.Flags &= ~ImPlotAxisFlags_Opposite; + } + } + } + for (int i = 0; i < IMPLOT_NUM_Y_AXES; ++i) { + ImPlotAxis& y_axis = plot.YAxis(i); + if (y_axis.Held && plot.PlotRect.Contains(mouse_pos)) { + const bool opp = ImHasFlag(y_axis.Flags, ImPlotAxisFlags_Opposite); + if (!opp) { + ImRect rect(plot.PlotRect.Max.x - 5, plot.PlotRect.Min.y - 5, + plot.PlotRect.Max.x + 5, plot.PlotRect.Max.y + 5); + if (mouse_pos.x > plot.PlotRect.Min.x + 10) + DrawList.AddRectFilled(rect.Min, rect.Max, y_axis.ColorHov); + if (rect.Contains(mouse_pos)) + y_axis.Flags |= ImPlotAxisFlags_Opposite; + } + else { + ImRect rect(plot.PlotRect.Min.x - 5, plot.PlotRect.Min.y - 5, + plot.PlotRect.Min.x + 5, plot.PlotRect.Max.y + 5); + if (mouse_pos.x < plot.PlotRect.Max.x - 10) + DrawList.AddRectFilled(rect.Min, rect.Max, y_axis.ColorHov); + if (rect.Contains(mouse_pos)) + y_axis.Flags &= ~ImPlotAxisFlags_Opposite; + } + } + } + } + // reset legend hovers plot.Items.Legend.Hovered = false; for (int i = 0; i < plot.Items.GetItemCount(); ++i) plot.Items.GetItemByIndex(i)->LegendHovered = false; // render legend if (!ImHasFlag(plot.Flags, ImPlotFlags_NoLegend) && plot.Items.GetLegendCount() > 0) { - const ImVec2 legend_size = CalcLegendSize(plot.Items, gp.Style.LegendInnerPadding, gp.Style.LegendSpacing, plot.Items.Legend.Orientation); - const ImVec2 legend_pos = GetLocationPos(plot.Items.Legend.Outside ? plot.FrameRect : plot.PlotRect, + ImPlotLegend& legend = plot.Items.Legend; + const bool legend_out = ImHasFlag(legend.Flags, ImPlotLegendFlags_Outside); + const bool legend_horz = ImHasFlag(legend.Flags, ImPlotLegendFlags_Horizontal); + const ImVec2 legend_size = CalcLegendSize(plot.Items, gp.Style.LegendInnerPadding, gp.Style.LegendSpacing, !legend_horz); + const ImVec2 legend_pos = GetLocationPos(legend_out ? plot.FrameRect : plot.PlotRect, legend_size, - plot.Items.Legend.Location, - plot.Items.Legend.Outside ? gp.Style.PlotPadding : gp.Style.LegendPadding); - plot.Items.Legend.Rect = ImRect(legend_pos, legend_pos + legend_size); + legend.Location, + legend_out ? gp.Style.PlotPadding : gp.Style.LegendPadding); + legend.Rect = ImRect(legend_pos, legend_pos + legend_size); // test hover - plot.Items.Legend.Hovered = plot.FrameHovered && plot.Items.Legend.Rect.Contains(IO.MousePos); + legend.Hovered = ImGui::IsWindowHovered() && legend.Rect.Contains(IO.MousePos); - if (plot.Items.Legend.Outside) + if (legend_out) ImGui::PushClipRect(plot.FrameRect.Min, plot.FrameRect.Max, true); else PushPlotClipRect(); ImU32 col_bg = GetStyleColorU32(ImPlotCol_LegendBg); ImU32 col_bd = GetStyleColorU32(ImPlotCol_LegendBorder); - DrawList.AddRectFilled(plot.Items.Legend.Rect.Min, plot.Items.Legend.Rect.Max, col_bg); - DrawList.AddRect(plot.Items.Legend.Rect.Min, plot.Items.Legend.Rect.Max, col_bd); - bool legend_contextable = ShowLegendEntries(plot.Items, plot.Items.Legend.Rect, plot.Items.Legend.Hovered, gp.Style.LegendInnerPadding, gp.Style.LegendSpacing, plot.Items.Legend.Orientation, DrawList); + DrawList.AddRectFilled(legend.Rect.Min, legend.Rect.Max, col_bg); + DrawList.AddRect(legend.Rect.Min, legend.Rect.Max, col_bd); + bool legend_contextable = ShowLegendEntries(plot.Items, legend.Rect, legend.Hovered, gp.Style.LegendInnerPadding, gp.Style.LegendSpacing, !legend_horz, DrawList) + && !ImHasFlag(legend.Flags, ImPlotLegendFlags_NoMenus); + // main ctx menu - if (legend_contextable && !ImHasFlag(plot.Flags, ImPlotFlags_NoMenus) && IO.MouseReleased[gp.InputMap.ContextMenuButton] && !plot.ContextLocked) + if (gp.OpenContextThisFrame && legend_contextable && !ImHasFlag(plot.Flags, ImPlotFlags_NoMenus)) ImGui::OpenPopup("##LegendContext"); ImGui::PopClipRect(); if (ImGui::BeginPopup("##LegendContext")) { ImGui::Text("Legend"); ImGui::Separator(); - if (ShowLegendContextMenu(plot.Items.Legend, !ImHasFlag(plot.Flags, ImPlotFlags_NoLegend))) + if (ShowLegendContextMenu(legend, !ImHasFlag(plot.Flags, ImPlotFlags_NoLegend))) ImFlipFlag(plot.Flags, ImPlotFlags_NoLegend); ImGui::EndPopup(); } @@ -2557,90 +2925,128 @@ void EndPlot() { else { plot.Items.Legend.Rect = ImRect(); } - if (plot.Items.Legend.FlipSideNextFrame) { - plot.Items.Legend.Outside = !plot.Items.Legend.Outside; - plot.Items.Legend.FlipSideNextFrame = false; - } // render border - if (gp.Style.PlotBorderSize > 0) + if (render_border) DrawList.AddRect(plot.PlotRect.Min, plot.PlotRect.Max, GetStyleColorU32(ImPlotCol_PlotBorder), 0, ImDrawFlags_RoundCornersAll, gp.Style.PlotBorderSize); + // render tags + for (int i = 0; i < gp.Tags.Size; ++i) { + ImPlotTag& tag = gp.Tags.Tags[i]; + ImPlotAxis& axis = plot.Axes[tag.Axis]; + if (!axis.Enabled || !axis.Range.Contains(tag.Value)) + continue; + const char* txt = gp.Tags.GetText(i); + ImVec2 text_size = ImGui::CalcTextSize(txt); + ImVec2 size = text_size + gp.Style.AnnotationPadding * 2; + ImVec2 pos; + axis.Ticks.OverrideSizeLate(size); + float pix = IM_ROUND(axis.PlotToPixels(tag.Value)); + if (axis.Vertical) { + if (axis.IsOpposite()) { + pos = ImVec2(axis.Datum1 + gp.Style.LabelPadding.x, pix - size.y * 0.5f); + DrawList.AddTriangleFilled(ImVec2(axis.Datum1,pix), pos, pos + ImVec2(0,size.y), tag.ColorBg); + } + else { + pos = ImVec2(axis.Datum1 - size.x - gp.Style.LabelPadding.x, pix - size.y * 0.5f); + DrawList.AddTriangleFilled(pos + ImVec2(size.x,0), ImVec2(axis.Datum1,pix), pos+size, tag.ColorBg); + } + } + else { + if (axis.IsOpposite()) { + pos = ImVec2(pix - size.x * 0.5f, axis.Datum1 - size.y - gp.Style.LabelPadding.y ); + DrawList.AddTriangleFilled(pos + ImVec2(0,size.y), pos + size, ImVec2(pix,axis.Datum1), tag.ColorBg); + } + else { + pos = ImVec2(pix - size.x * 0.5f, axis.Datum1 + gp.Style.LabelPadding.y); + DrawList.AddTriangleFilled(pos, ImVec2(pix,axis.Datum1), pos + ImVec2(size.x, 0), tag.ColorBg); + } + } + DrawList.AddRectFilled(pos,pos+size,tag.ColorBg); + DrawList.AddText(pos+gp.Style.AnnotationPadding,tag.ColorFg,txt); + } + // FIT DATA -------------------------------------------------------------- const bool axis_equal = ImHasFlag(plot.Flags, ImPlotFlags_Equal); - if (gp.FitThisFrame) { - if (gp.FitX) { - const double ext_size = gp.ExtentsX.Size() * 0.5; - gp.ExtentsX.Min -= ext_size * gp.Style.FitPadding.x; - gp.ExtentsX.Max += ext_size * gp.Style.FitPadding.x; - if (!plot.XAxis.IsLockedMin() && !ImNanOrInf(gp.ExtentsX.Min)) - plot.XAxis.Range.Min = (gp.ExtentsX.Min); - if (!plot.XAxis.IsLockedMax() && !ImNanOrInf(gp.ExtentsX.Max)) - plot.XAxis.Range.Max = (gp.ExtentsX.Max); - if (ImAlmostEqual(plot.XAxis.Range.Max, plot.XAxis.Range.Min)) { - plot.XAxis.Range.Max += 0.5; - plot.XAxis.Range.Min -= 0.5; - } - plot.XAxis.Constrain(); - if (axis_equal && !gp.FitY[0]) - plot.YAxis[0].SetAspect(plot.XAxis.GetAspect()); - } - for (int i = 0; i < IMPLOT_Y_AXES; i++) { - if (gp.FitY[i]) { - const double ext_size = gp.ExtentsY[i].Size() * 0.5; - gp.ExtentsY[i].Min -= ext_size * gp.Style.FitPadding.y; - gp.ExtentsY[i].Max += ext_size * gp.Style.FitPadding.y; - if (!plot.YAxis[i].IsLockedMin() && !ImNanOrInf(gp.ExtentsY[i].Min)) - plot.YAxis[i].Range.Min = (gp.ExtentsY[i].Min); - if (!plot.YAxis[i].IsLockedMax() && !ImNanOrInf(gp.ExtentsY[i].Max)) - plot.YAxis[i].Range.Max = (gp.ExtentsY[i].Max); - if (ImAlmostEqual(plot.YAxis[i].Range.Max, plot.YAxis[i].Range.Min)) { - plot.YAxis[i].Range.Max += 0.5; - plot.YAxis[i].Range.Min -= 0.5; + if (plot.FitThisFrame) { + for (int i = 0; i < IMPLOT_NUM_X_AXES; i++) { + ImPlotAxis& x_axis = plot.XAxis(i); + if (x_axis.FitThisFrame) { + x_axis.ApplyFit(gp.Style.FitPadding.x); + if (axis_equal && x_axis.OrthoAxis != NULL) { + double aspect = x_axis.GetAspect(); + ImPlotAxis& y_axis = *x_axis.OrthoAxis; + if (y_axis.FitThisFrame) { + y_axis.ApplyFit(gp.Style.FitPadding.y); + y_axis.FitThisFrame = false; + aspect = ImMax(aspect, y_axis.GetAspect()); + } + x_axis.SetAspect(aspect); + y_axis.SetAspect(aspect); } - plot.YAxis[i].Constrain(); - if (i == 0 && axis_equal && !gp.FitX) - plot.XAxis.SetAspect(plot.YAxis[0].GetAspect()); } } - if (axis_equal && gp.FitX && gp.FitY[0]) { - double aspect = ImMax(plot.XAxis.GetAspect(), plot.YAxis[0].GetAspect()); - plot.XAxis.SetAspect(aspect); - plot.YAxis[0].SetAspect(aspect); + for (int i = 0; i < IMPLOT_NUM_Y_AXES; i++) { + ImPlotAxis& y_axis = plot.YAxis(i); + if (y_axis.FitThisFrame) { + y_axis.ApplyFit(gp.Style.FitPadding.y); + if (axis_equal && y_axis.OrthoAxis != NULL) { + double aspect = y_axis.GetAspect(); + ImPlotAxis& x_axis = *y_axis.OrthoAxis; + if (x_axis.FitThisFrame) { + x_axis.ApplyFit(gp.Style.FitPadding.x); + x_axis.FitThisFrame = false; + aspect = ImMax(x_axis.GetAspect(), aspect); + } + x_axis.SetAspect(aspect); + y_axis.SetAspect(aspect); + } + } } + plot.FitThisFrame = false; } // CONTEXT MENUS ----------------------------------------------------------- ImGui::PushOverrideID(plot.ID); + + const bool can_ctx = gp.OpenContextThisFrame && + !ImHasFlag(plot.Flags, ImPlotFlags_NoMenus) && + !plot.Items.Legend.Hovered; + + + // main ctx menu - if (!ImHasFlag(plot.Flags, ImPlotFlags_NoMenus) && plot.PlotHovered && IO.MouseReleased[gp.InputMap.ContextMenuButton] && !plot.Items.Legend.Hovered && !plot.ContextLocked) + if (can_ctx && plot.Hovered) ImGui::OpenPopup("##PlotContext"); if (ImGui::BeginPopup("##PlotContext")) { ShowPlotContextMenu(plot); ImGui::EndPopup(); } - // x-axis ctx menu - if (!ImHasFlag(plot.Flags, ImPlotFlags_NoMenus) && plot.FrameHovered && plot.XAxis.ExtHovered && IO.MouseReleased[gp.InputMap.ContextMenuButton] && !plot.Items.Legend.Hovered && !plot.ContextLocked) - ImGui::OpenPopup("##XContext"); - if (ImGui::BeginPopup("##XContext")) { - ImGui::Text("X-Axis"); ImGui::Separator(); - ShowAxisContextMenu(plot.XAxis, ImHasFlag(plot.Flags, ImPlotFlags_Equal) ? &plot.YAxis[0] : NULL, true); - ImGui::EndPopup(); - } - // y-axes ctx menus - for (int i = 0; i < IMPLOT_Y_AXES; ++i) { + + // axes ctx menus + for (int i = 0; i < IMPLOT_NUM_X_AXES; ++i) { ImGui::PushID(i); - if (!ImHasFlag(plot.Flags, ImPlotFlags_NoMenus) && plot.FrameHovered && plot.YAxis[i].ExtHovered && IO.MouseReleased[gp.InputMap.ContextMenuButton] && !plot.Items.Legend.Hovered && !plot.ContextLocked) + ImPlotAxis& x_axis = plot.XAxis(i); + if (can_ctx && x_axis.Hovered && x_axis.HasMenus()) + ImGui::OpenPopup("##XContext"); + if (ImGui::BeginPopup("##XContext")) { + ImGui::Text(x_axis.HasLabel() ? plot.GetAxisLabel(x_axis) : i == 0 ? "X-Axis" : "X-Axis %d", i + 1); + ImGui::Separator(); + ShowAxisContextMenu(x_axis, axis_equal ? x_axis.OrthoAxis : NULL, true); + ImGui::EndPopup(); + } + ImGui::PopID(); + } + for (int i = 0; i < IMPLOT_NUM_Y_AXES; ++i) { + ImGui::PushID(i); + ImPlotAxis& y_axis = plot.YAxis(i); + if (can_ctx && y_axis.Hovered && y_axis.HasMenus()) ImGui::OpenPopup("##YContext"); if (ImGui::BeginPopup("##YContext")) { - if (i == 0) { - ImGui::Text("Y-Axis"); ImGui::Separator(); - } - else { - ImGui::Text("Y-Axis %d", i + 1); ImGui::Separator(); - } - ShowAxisContextMenu(plot.YAxis[i], (i == 0 && ImHasFlag(plot.Flags, ImPlotFlags_Equal)) ? &plot.XAxis : NULL, false); + ImGui::Text(y_axis.HasLabel() ? plot.GetAxisLabel(y_axis) : i == 0 ? "Y-Axis" : "Y-Axis %d", i + 1); + ImGui::Separator(); + ShowAxisContextMenu(y_axis, axis_equal ? y_axis.OrthoAxis : NULL, false); ImGui::EndPopup(); } ImGui::PopID(); @@ -2649,16 +3055,12 @@ void EndPlot() { // LINKED AXES ------------------------------------------------------------ - PushLinkedAxis(plot.XAxis); - for (int i = 0; i < IMPLOT_Y_AXES; ++i) - PushLinkedAxis(plot.YAxis[i]); + for (int i = 0; i < ImAxis_COUNT; ++i) + plot.Axes[i].PushLinks(); + // CLEANUP ---------------------------------------------------------------- - // resset context locked flag - if (plot.ContextLocked && IO.MouseReleased[gp.InputMap.BoxSelectButton]) - plot.ContextLocked = false; - // remove items if (gp.CurrentItems == &plot.Items) gp.CurrentItems = NULL; @@ -2713,10 +3115,11 @@ void SubplotSetCell(int row, int col) { const bool ly = ImHasFlag(subplot.Flags, ImPlotSubplotFlags_LinkAllY); const bool lr = ImHasFlag(subplot.Flags, ImPlotSubplotFlags_LinkRows); const bool lc = ImHasFlag(subplot.Flags, ImPlotSubplotFlags_LinkCols); - LinkNextPlotLimits(lx ? &subplot.ColLinkData[0].Min : lc ? &subplot.ColLinkData[col].Min : NULL, - lx ? &subplot.ColLinkData[0].Max : lc ? &subplot.ColLinkData[col].Max : NULL, - ly ? &subplot.RowLinkData[0].Min : lr ? &subplot.RowLinkData[row].Min : NULL, - ly ? &subplot.RowLinkData[0].Max : lr ? &subplot.RowLinkData[row].Max : NULL); + + SetNextAxisLinks(ImAxis_X1, lx ? &subplot.ColLinkData[0].Min : lc ? &subplot.ColLinkData[col].Min : NULL, + lx ? &subplot.ColLinkData[0].Max : lc ? &subplot.ColLinkData[col].Max : NULL); + SetNextAxisLinks(ImAxis_Y1, ly ? &subplot.RowLinkData[0].Min : lr ? &subplot.RowLinkData[row].Min : NULL, + ly ? &subplot.RowLinkData[0].Max : lr ? &subplot.RowLinkData[row].Max : NULL); // setup alignment if (!ImHasFlag(subplot.Flags, ImPlotSubplotFlags_NoAlign)) { gp.CurrentAlignmentH = &subplot.RowAlignmentData[row]; @@ -2766,7 +3169,8 @@ bool BeginSubplots(const char* title, int rows, int cols, const ImVec2& size, Im gp.CurrentSubplot = gp.Subplots.GetOrAddByKey(ID); ImPlotSubplot& subplot = *gp.CurrentSubplot; subplot.ID = ID; - subplot.Items.ID = ID; + subplot.Items.ID = ID - 1; + subplot.HasTitle = ImGui::FindRenderedTextEnd(title, NULL) != title; // push ID ImGui::PushID(ID); @@ -2812,7 +3216,6 @@ bool BeginSubplots(const char* title, int rows, int cols, const ImVec2& size, Im // calc plot frame sizes ImVec2 title_size(0.0f, 0.0f); - const float txt_height = ImGui::GetTextLineHeight(); if (!ImHasFlag(subplot.Flags, ImPlotSubplotFlags_NoTitle)) title_size = ImGui::CalcTextSize(title, NULL, true); const float pad_top = title_size.x > 0.0f ? title_size.y + gp.Style.LabelPadding.y : 0; @@ -2823,17 +3226,18 @@ bool BeginSubplots(const char* title, int rows, int cols, const ImVec2& size, Im subplot.GridRect.Max = subplot.FrameRect.Max - half_pad; subplot.FrameHovered = subplot.FrameRect.Contains(ImGui::GetMousePos()) && ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows); - // outside legend adjustments + // outside legend adjustments (TODO: make function) const bool share_items = ImHasFlag(subplot.Flags, ImPlotSubplotFlags_ShareItems); if (share_items) gp.CurrentItems = &subplot.Items; if (share_items && !ImHasFlag(subplot.Flags, ImPlotSubplotFlags_NoLegend) && subplot.Items.GetLegendCount() > 0) { - const ImVec2 legend_size = CalcLegendSize(subplot.Items, gp.Style.LegendInnerPadding, gp.Style.LegendSpacing, subplot.Items.Legend.Orientation); - const bool west = ImHasFlag(subplot.Items.Legend.Location, ImPlotLocation_West) && !ImHasFlag(subplot.Items.Legend.Location, ImPlotLocation_East); - const bool east = ImHasFlag(subplot.Items.Legend.Location, ImPlotLocation_East) && !ImHasFlag(subplot.Items.Legend.Location, ImPlotLocation_West); - const bool north = ImHasFlag(subplot.Items.Legend.Location, ImPlotLocation_North) && !ImHasFlag(subplot.Items.Legend.Location, ImPlotLocation_South); - const bool south = ImHasFlag(subplot.Items.Legend.Location, ImPlotLocation_South) && !ImHasFlag(subplot.Items.Legend.Location, ImPlotLocation_North); - const bool horz = subplot.Items.Legend.Orientation == ImPlotOrientation_Horizontal; + ImPlotLegend& legend = subplot.Items.Legend; + const bool horz = ImHasFlag(legend.Flags, ImPlotLegendFlags_Horizontal); + const ImVec2 legend_size = CalcLegendSize(subplot.Items, gp.Style.LegendInnerPadding, gp.Style.LegendSpacing, !horz); + const bool west = ImHasFlag(legend.Location, ImPlotLocation_West) && !ImHasFlag(legend.Location, ImPlotLocation_East); + const bool east = ImHasFlag(legend.Location, ImPlotLocation_East) && !ImHasFlag(legend.Location, ImPlotLocation_West); + const bool north = ImHasFlag(legend.Location, ImPlotLocation_North) && !ImHasFlag(legend.Location, ImPlotLocation_South); + const bool south = ImHasFlag(legend.Location, ImPlotLocation_South) && !ImHasFlag(legend.Location, ImPlotLocation_North); if ((west && !horz) || (west && horz && !north && !south)) subplot.GridRect.Min.x += (legend_size.x + gp.Style.LegendPadding.x); if ((east && !horz) || (east && horz && !north && !south)) @@ -2855,12 +3259,10 @@ bool BeginSubplots(const char* title, int rows, int cols, const ImVec2& size, Im // render splitters if (!ImHasFlag(subplot.Flags, ImPlotSubplotFlags_NoResize)) { ImDrawList& DrawList = *ImGui::GetWindowDrawList(); - const ImU32 nrm_col = ImGui::ColorConvertFloat4ToU32(GImGui->Style.Colors[ImGuiCol_Separator]); const ImU32 hov_col = ImGui::ColorConvertFloat4ToU32(GImGui->Style.Colors[ImGuiCol_SeparatorHovered]); const ImU32 act_col = ImGui::ColorConvertFloat4ToU32(GImGui->Style.Colors[ImGuiCol_SeparatorActive]); float xpos = subplot.GridRect.Min.x; float ypos = subplot.GridRect.Min.y; - const ImVec2 mouse = ImGui::GetIO().MousePos; int separator = 1; // bool pass = false; for (int r = 0; r < subplot.Rows-1; ++r) { @@ -2943,7 +3345,7 @@ bool BeginSubplots(const char* title, int rows, int cols, const ImVec2& size, Im // set initial cursor pos Window->DC.CursorPos = subplot.GridRect.Min; - // begin alignrmnts + // begin alignments for (int r = 0; r < subplot.Rows; ++r) subplot.RowAlignmentData[r].Begin(); for (int c = 0; c < subplot.Cols; ++c) @@ -2978,7 +3380,8 @@ void EndSubplots() { const bool share_items = ImHasFlag(subplot.Flags, ImPlotSubplotFlags_ShareItems); ImDrawList& DrawList = *ImGui::GetWindowDrawList(); if (share_items && !ImHasFlag(subplot.Flags, ImPlotSubplotFlags_NoLegend) && subplot.Items.GetLegendCount() > 0) { - const ImVec2 legend_size = CalcLegendSize(subplot.Items, gp.Style.LegendInnerPadding, gp.Style.LegendSpacing, subplot.Items.Legend.Orientation); + const bool legend_horz = ImHasFlag(subplot.Items.Legend.Flags, ImPlotLegendFlags_Horizontal); + const ImVec2 legend_size = CalcLegendSize(subplot.Items, gp.Style.LegendInnerPadding, gp.Style.LegendSpacing, !legend_horz); const ImVec2 legend_pos = GetLocationPos(subplot.FrameRect, legend_size, subplot.Items.Legend.Location, gp.Style.PlotPadding); subplot.Items.Legend.Rect = ImRect(legend_pos, legend_pos + legend_size); subplot.Items.Legend.Hovered = subplot.FrameHovered && subplot.Items.Legend.Rect.Contains(ImGui::GetIO().MousePos); @@ -2987,8 +3390,9 @@ void EndSubplots() { ImU32 col_bd = GetStyleColorU32(ImPlotCol_LegendBorder); DrawList.AddRectFilled(subplot.Items.Legend.Rect.Min, subplot.Items.Legend.Rect.Max, col_bg); DrawList.AddRect(subplot.Items.Legend.Rect.Min, subplot.Items.Legend.Rect.Max, col_bd); - bool legend_contextable =ShowLegendEntries(subplot.Items, subplot.Items.Legend.Rect, subplot.Items.Legend.Hovered, gp.Style.LegendInnerPadding, gp.Style.LegendSpacing, subplot.Items.Legend.Orientation, DrawList); - if (legend_contextable && !ImHasFlag(subplot.Flags, ImPlotSubplotFlags_NoMenus) && ImGui::GetIO().MouseReleased[gp.InputMap.ContextMenuButton]) + bool legend_contextable = ShowLegendEntries(subplot.Items, subplot.Items.Legend.Rect, subplot.Items.Legend.Hovered, gp.Style.LegendInnerPadding, gp.Style.LegendSpacing, !legend_horz, DrawList) + && !ImHasFlag(subplot.Items.Legend.Flags, ImPlotLegendFlags_NoMenus); + if (legend_contextable && !ImHasFlag(subplot.Flags, ImPlotSubplotFlags_NoMenus) && ImGui::GetIO().MouseReleased[gp.InputMap.Menu]) ImGui::OpenPopup("##LegendContext"); ImGui::PopClipRect(); if (ImGui::BeginPopup("##LegendContext")) { @@ -3018,231 +3422,137 @@ void EndSubplots() { } //----------------------------------------------------------------------------- -// MISC API +// [SECTION] Plot Utils //----------------------------------------------------------------------------- -bool BeginAlignedPlots(const char* group_id, ImPlotOrientation orientation) { - IM_ASSERT_USER_ERROR(GImPlot != NULL, "No current context. Did you call ImPlot::CreateContext() or ImPlot::SetCurrentContext()?"); - IM_ASSERT_USER_ERROR(GImPlot->CurrentAlignmentH == NULL && GImPlot->CurrentAlignmentV == NULL, "Mismatched BeginAlignedPlots()/EndAlignedPlots()!"); +void SetAxis(ImAxis axis) { ImPlotContext& gp = *GImPlot; - ImGuiContext &G = *GImGui; - ImGuiWindow * Window = G.CurrentWindow; - if (Window->SkipItems) - return false; - const ImGuiID ID = Window->GetID(group_id); - ImPlotAlignmentData* alignment = gp.AlignmentData.GetOrAddByKey(ID); - if (orientation == ImPlotOrientation_Horizontal) - gp.CurrentAlignmentH = alignment; - if (orientation == ImPlotOrientation_Vertical) - gp.CurrentAlignmentV = alignment; - if (alignment->Orientation != orientation) - alignment->Reset(); - alignment->Orientation = orientation; - alignment->Begin(); - return true; + IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "SetAxis() needs to be called between BeginPlot() and EndPlot()!"); + IM_ASSERT_USER_ERROR(axis >= ImAxis_X1 && axis < ImAxis_COUNT, "Axis index out of bounds!"); + IM_ASSERT_USER_ERROR(gp.CurrentPlot->Axes[axis].Enabled, "Axis is not enabled! Did you forget to call SetupAxis()?"); + SetupLock(); + if (axis < ImAxis_Y1) + gp.CurrentPlot->CurrentX = axis; + else + gp.CurrentPlot->CurrentY = axis; } -void EndAlignedPlots() { - IM_ASSERT_USER_ERROR(GImPlot != NULL, "No current context. Did you call ImPlot::CreateContext() or ImPlot::SetCurrentContext()?"); - IM_ASSERT_USER_ERROR(GImPlot->CurrentAlignmentH != NULL || GImPlot->CurrentAlignmentV != NULL, "Mismatched BeginAlignedPlots()/EndAlignedPlots()!"); +void SetAxes(ImAxis x_idx, ImAxis y_idx) { ImPlotContext& gp = *GImPlot; - ImPlotAlignmentData* alignment = gp.CurrentAlignmentH != NULL ? gp.CurrentAlignmentH : (gp.CurrentAlignmentV != NULL ? gp.CurrentAlignmentV : NULL); - if (alignment) - alignment->End(); - ResetCtxForNextAlignedPlots(GImPlot); + IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "SetAxes() needs to be called between BeginPlot() and EndPlot()!"); + IM_ASSERT_USER_ERROR(x_idx >= ImAxis_X1 && x_idx < ImAxis_Y1, "X-Axis index out of bounds!"); + IM_ASSERT_USER_ERROR(y_idx >= ImAxis_Y1 && y_idx < ImAxis_COUNT, "Y-Axis index out of bounds!"); + IM_ASSERT_USER_ERROR(gp.CurrentPlot->Axes[x_idx].Enabled, "Axis is not enabled! Did you forget to call SetupAxis()?"); + IM_ASSERT_USER_ERROR(gp.CurrentPlot->Axes[y_idx].Enabled, "Axis is not enabled! Did you forget to call SetupAxis()?"); + SetupLock(); + gp.CurrentPlot->CurrentX = x_idx; + gp.CurrentPlot->CurrentY = y_idx; } -ImPlotInputMap& GetInputMap() { - return GImPlot->InputMap; -} - -void SetNextPlotLimits(double x_min, double x_max, double y_min, double y_max, ImGuiCond cond) { - IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot == NULL, "SetNextPlotLimits() needs to be called before BeginPlot()!"); - SetNextPlotLimitsX(x_min, x_max, cond); - SetNextPlotLimitsY(y_min, y_max, cond); -} - -void SetNextPlotLimitsX(double x_min, double x_max, ImGuiCond cond) { +ImPlotPoint PixelsToPlot(float x, float y, ImAxis x_idx, ImAxis y_idx) { ImPlotContext& gp = *GImPlot; - IM_ASSERT_USER_ERROR(gp.CurrentPlot == NULL, "SetNextPlotLSetNextPlotLimitsXimitsY() needs to be called before BeginPlot()!"); - IM_ASSERT(cond == 0 || ImIsPowerOfTwo(cond)); // Make sure the user doesn't attempt to combine multiple condition flags. - gp.NextPlotData.HasXRange = true; - gp.NextPlotData.XRangeCond = cond; - gp.NextPlotData.XRange.Min = x_min; - gp.NextPlotData.XRange.Max = x_max; + IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "PixelsToPlot() needs to be called between BeginPlot() and EndPlot()!"); + IM_ASSERT_USER_ERROR(x_idx == IMPLOT_AUTO || (x_idx >= ImAxis_X1 && x_idx < ImAxis_Y1), "X-Axis index out of bounds!"); + IM_ASSERT_USER_ERROR(y_idx == IMPLOT_AUTO || (y_idx >= ImAxis_Y1 && y_idx < ImAxis_COUNT), "Y-Axis index out of bounds!"); + SetupLock(); + ImPlotPlot& plot = *gp.CurrentPlot; + ImPlotAxis& x_axis = x_idx == IMPLOT_AUTO ? plot.Axes[plot.CurrentX] : plot.Axes[x_idx]; + ImPlotAxis& y_axis = y_idx == IMPLOT_AUTO ? plot.Axes[plot.CurrentY] : plot.Axes[y_idx]; + return ImPlotPoint( x_axis.PixelsToPlot(x), y_axis.PixelsToPlot(y) ); } -void SetNextPlotLimitsY(double y_min, double y_max, ImGuiCond cond, ImPlotYAxis y_axis) { +ImPlotPoint PixelsToPlot(const ImVec2& pix, ImAxis x_idx, ImAxis y_idx) { + return PixelsToPlot(pix.x, pix.y, x_idx, y_idx); +} + +ImVec2 PlotToPixels(double x, double y, ImAxis x_idx, ImAxis y_idx) { ImPlotContext& gp = *GImPlot; - IM_ASSERT_USER_ERROR(gp.CurrentPlot == NULL, "SetNextPlotLimitsY() needs to be called before BeginPlot()!"); - IM_ASSERT_USER_ERROR(y_axis >= 0 && y_axis < IMPLOT_Y_AXES, "y_axis needs to be between 0 and IMPLOT_Y_AXES"); - IM_ASSERT(cond == 0 || ImIsPowerOfTwo(cond)); // Make sure the user doesn't attempt to combine multiple condition flags. - gp.NextPlotData.HasYRange[y_axis] = true; - gp.NextPlotData.YRangeCond[y_axis] = cond; - gp.NextPlotData.YRange[y_axis].Min = y_min; - gp.NextPlotData.YRange[y_axis].Max = y_max; + IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "PlotToPixels() needs to be called between BeginPlot() and EndPlot()!"); + IM_ASSERT_USER_ERROR(x_idx == IMPLOT_AUTO || (x_idx >= ImAxis_X1 && x_idx < ImAxis_Y1), "X-Axis index out of bounds!"); + IM_ASSERT_USER_ERROR(y_idx == IMPLOT_AUTO || (y_idx >= ImAxis_Y1 && y_idx < ImAxis_COUNT), "Y-Axis index out of bounds!"); + SetupLock(); + ImPlotPlot& plot = *gp.CurrentPlot; + ImPlotAxis& x_axis = x_idx == IMPLOT_AUTO ? plot.Axes[plot.CurrentX] : plot.Axes[x_idx]; + ImPlotAxis& y_axis = y_idx == IMPLOT_AUTO ? plot.Axes[plot.CurrentY] : plot.Axes[y_idx]; + return ImVec2( x_axis.PlotToPixels(x), y_axis.PlotToPixels(y) ); } -void LinkNextPlotLimits(double* xmin, double* xmax, double* ymin, double* ymax, double* ymin2, double* ymax2, double* ymin3, double* ymax3) { - ImPlotContext& gp = *GImPlot; - gp.NextPlotData.LinkedXmin = xmin; - gp.NextPlotData.LinkedXmax = xmax; - gp.NextPlotData.LinkedYmin[0] = ymin; - gp.NextPlotData.LinkedYmax[0] = ymax; - gp.NextPlotData.LinkedYmin[1] = ymin2; - gp.NextPlotData.LinkedYmax[1] = ymax2; - gp.NextPlotData.LinkedYmin[2] = ymin3; - gp.NextPlotData.LinkedYmax[2] = ymax3; -} - -void FitNextPlotAxes(bool x, bool y, bool y2, bool y3) { - ImPlotContext& gp = *GImPlot; - IM_ASSERT_USER_ERROR(gp.CurrentPlot == NULL, "FitNextPlotAxes() needs to be called before BeginPlot()!"); - gp.NextPlotData.FitX = x; - gp.NextPlotData.FitY[0] = y; - gp.NextPlotData.FitY[1] = y2; - gp.NextPlotData.FitY[2] = y3; -} - -void SetNextPlotTicksX(const double* values, int n_ticks, const char* const labels[], bool show_default) { - ImPlotContext& gp = *GImPlot; - IM_ASSERT_USER_ERROR(gp.CurrentPlot == NULL, "SetNextPlotTicksX() needs to be called before BeginPlot()!"); - gp.NextPlotData.ShowDefaultTicksX = show_default; - AddTicksCustom(values, labels, n_ticks, gp.XTicks, GetFormatX()); -} - -void SetNextPlotTicksX(double x_min, double x_max, int n_ticks, const char* const labels[], bool show_default) { - IM_ASSERT_USER_ERROR(n_ticks > 1, "The number of ticks must be greater than 1"); - static ImVector buffer; - FillRange(buffer, n_ticks, x_min, x_max); - SetNextPlotTicksX(&buffer[0], n_ticks, labels, show_default); -} - -void SetNextPlotTicksY(const double* values, int n_ticks, const char* const labels[], bool show_default, ImPlotYAxis y_axis) { - ImPlotContext& gp = *GImPlot; - IM_ASSERT_USER_ERROR(gp.CurrentPlot == NULL, "SetNextPlotTicksY() needs to be called before BeginPlot()!"); - IM_ASSERT_USER_ERROR(y_axis >= 0 && y_axis < IMPLOT_Y_AXES, "y_axis needs to be between 0 and IMPLOT_Y_AXES"); - gp.NextPlotData.ShowDefaultTicksY[y_axis] = show_default; - AddTicksCustom(values, labels, n_ticks, gp.YTicks[y_axis], GetFormatY(y_axis)); -} - -void SetNextPlotTicksY(double y_min, double y_max, int n_ticks, const char* const labels[], bool show_default, ImPlotYAxis y_axis) { - IM_ASSERT_USER_ERROR(n_ticks > 1, "The number of ticks must be greater than 1"); - static ImVector buffer; - FillRange(buffer, n_ticks, y_min, y_max); - SetNextPlotTicksY(&buffer[0], n_ticks, labels, show_default,y_axis); -} - -void SetNextPlotFormatX(const char* fmt){ - ImPlotContext& gp = *GImPlot; - IM_ASSERT_USER_ERROR(gp.CurrentPlot == NULL, "SetNextPlotFormatX() needs to be called before BeginPlot()!"); - gp.NextPlotData.HasFmtX = true; - ImStrncpy(gp.NextPlotData.FmtX, fmt, 16); -} - -void SetNextPlotFormatY(const char* fmt, ImPlotYAxis y_axis) { - ImPlotContext& gp = *GImPlot; - IM_ASSERT_USER_ERROR(gp.CurrentPlot == NULL, "SetNextPlotFormatY() needs to be called before BeginPlot()!"); - IM_ASSERT_USER_ERROR(y_axis >= 0 && y_axis < IMPLOT_Y_AXES, "y_axis needs to be between 0 and IMPLOT_Y_AXES"); - gp.NextPlotData.HasFmtY[y_axis] = true; - ImStrncpy(gp.NextPlotData.FmtY[y_axis], fmt, 16); -} - -void SetPlotYAxis(ImPlotYAxis y_axis) { - ImPlotContext& gp = *GImPlot; - IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "SetPlotYAxis() needs to be called between BeginPlot() and EndPlot()!"); - IM_ASSERT_USER_ERROR(y_axis >= 0 && y_axis < IMPLOT_Y_AXES, "y_axis needs to be between 0 and IMPLOT_Y_AXES"); - gp.CurrentPlot->CurrentYAxis = y_axis; +ImVec2 PlotToPixels(const ImPlotPoint& plt, ImAxis x_idx, ImAxis y_idx) { + return PlotToPixels(plt.x, plt.y, x_idx, y_idx); } ImVec2 GetPlotPos() { ImPlotContext& gp = *GImPlot; IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "GetPlotPos() needs to be called between BeginPlot() and EndPlot()!"); + SetupLock(); return gp.CurrentPlot->PlotRect.Min; } ImVec2 GetPlotSize() { ImPlotContext& gp = *GImPlot; IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "GetPlotSize() needs to be called between BeginPlot() and EndPlot()!"); + SetupLock(); return gp.CurrentPlot->PlotRect.GetSize(); } -ImDrawList* GetPlotDrawList() { - return ImGui::GetWindowDrawList(); +ImPlotPoint GetPlotMousePos(ImAxis x_idx, ImAxis y_idx) { + IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != NULL, "GetPlotMousePos() needs to be called between BeginPlot() and EndPlot()!"); + SetupLock(); + return PixelsToPlot(ImGui::GetMousePos(), x_idx, y_idx); } -void PushPlotClipRect(float expand) { +ImPlotRect GetPlotLimits(ImAxis x_idx, ImAxis y_idx) { ImPlotContext& gp = *GImPlot; - ImRect rect = gp.CurrentPlot->PlotRect; - rect.Expand(expand); - IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "PushPlotClipRect() needs to be called between BeginPlot() and EndPlot()!"); - ImGui::PushClipRect(rect.Min, rect.Max, true); -} - -void PopPlotClipRect() { - ImGui::PopClipRect(); + IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "GetPlotLimits() needs to be called between BeginPlot() and EndPlot()!"); + IM_ASSERT_USER_ERROR(x_idx == IMPLOT_AUTO || (x_idx >= ImAxis_X1 && x_idx < ImAxis_Y1), "X-Axis index out of bounds!"); + IM_ASSERT_USER_ERROR(y_idx == IMPLOT_AUTO || (y_idx >= ImAxis_Y1 && y_idx < ImAxis_COUNT), "Y-Axis index out of bounds!"); + SetupLock(); + ImPlotPlot& plot = *gp.CurrentPlot; + ImPlotAxis& x_axis = x_idx == IMPLOT_AUTO ? plot.Axes[plot.CurrentX] : plot.Axes[x_idx]; + ImPlotAxis& y_axis = y_idx == IMPLOT_AUTO ? plot.Axes[plot.CurrentY] : plot.Axes[y_idx]; + ImPlotRect limits; + limits.X = x_axis.Range; + limits.Y = y_axis.Range; + return limits; } bool IsPlotHovered() { ImPlotContext& gp = *GImPlot; IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "IsPlotHovered() needs to be called between BeginPlot() and EndPlot()!"); - return gp.CurrentPlot->PlotHovered; + SetupLock(); + return gp.CurrentPlot->Hovered; } -bool IsPlotXAxisHovered() { +bool IsAxisHovered(ImAxis axis) { ImPlotContext& gp = *GImPlot; IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "IsPlotXAxisHovered() needs to be called between BeginPlot() and EndPlot()!"); - return gp.CurrentPlot->XAxis.ExtHovered; + SetupLock(); + return gp.CurrentPlot->Axes[axis].Hovered; } -bool IsPlotYAxisHovered(ImPlotYAxis y_axis_in) { +bool IsSubplotsHovered() { ImPlotContext& gp = *GImPlot; - IM_ASSERT_USER_ERROR(y_axis_in >= -1 && y_axis_in < IMPLOT_Y_AXES, "y_axis needs to between -1 and IMPLOT_Y_AXES"); - IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "IsPlotYAxisHovered() needs to be called between BeginPlot() and EndPlot()!"); - const ImPlotYAxis y_axis = y_axis_in >= 0 ? y_axis_in : gp.CurrentPlot->CurrentYAxis; - return gp.CurrentPlot->YAxis[y_axis].ExtHovered; -} - -ImPlotPoint GetPlotMousePos(ImPlotYAxis y_axis_in) { - ImPlotContext& gp = *GImPlot; - IM_ASSERT_USER_ERROR(y_axis_in >= -1 && y_axis_in < IMPLOT_Y_AXES, "y_axis needs to between -1 and IMPLOT_Y_AXES"); - IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "GetPlotMousePos() needs to be called between BeginPlot() and EndPlot()!"); - const ImPlotYAxis y_axis = y_axis_in >= 0 ? y_axis_in : gp.CurrentPlot->CurrentYAxis; - return gp.MousePos[y_axis]; -} - - -ImPlotLimits GetPlotLimits(ImPlotYAxis y_axis_in) { - ImPlotContext& gp = *GImPlot; - IM_ASSERT_USER_ERROR(y_axis_in >= -1 && y_axis_in < IMPLOT_Y_AXES, "y_axis needs to between -1 and IMPLOT_Y_AXES"); - IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "GetPlotLimits() needs to be called between BeginPlot() and EndPlot()!"); - const ImPlotYAxis y_axis = y_axis_in >= 0 ? y_axis_in : gp.CurrentPlot->CurrentYAxis; - - ImPlotPlot& plot = *gp.CurrentPlot; - ImPlotLimits limits; - limits.X = plot.XAxis.Range; - limits.Y = plot.YAxis[y_axis].Range; - return limits; + IM_ASSERT_USER_ERROR(gp.CurrentSubplot != NULL, "IsSubplotsHovered() needs to be called between BeginSubplots() and EndSubplots()!"); + return gp.CurrentSubplot->FrameHovered; } bool IsPlotSelected() { ImPlotContext& gp = *GImPlot; IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "IsPlotSelected() needs to be called between BeginPlot() and EndPlot()!"); + SetupLock(); return gp.CurrentPlot->Selected; } -ImPlotLimits GetPlotSelection(ImPlotYAxis y_axis) { +ImPlotRect GetPlotSelection(ImAxis x_idx, ImAxis y_idx) { ImPlotContext& gp = *GImPlot; - IM_ASSERT_USER_ERROR(y_axis >= -1 && y_axis < IMPLOT_Y_AXES, "y_axis needs to between -1 and IMPLOT_Y_AXES"); IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "GetPlotSelection() needs to be called between BeginPlot() and EndPlot()!"); + SetupLock(); ImPlotPlot& plot = *gp.CurrentPlot; - y_axis = y_axis >= 0 ? y_axis : gp.CurrentPlot->CurrentYAxis; if (!plot.Selected) - return ImPlotLimits(0,0,0,0); - UpdateTransformCache(); - ImPlotPoint p1 = PixelsToPlot(plot.SelectRect.Min + plot.PlotRect.Min, y_axis); - ImPlotPoint p2 = PixelsToPlot(plot.SelectRect.Max + plot.PlotRect.Min, y_axis); - ImPlotLimits result; + return ImPlotRect(0,0,0,0); + ImPlotPoint p1 = PixelsToPlot(plot.SelectRect.Min + plot.PlotRect.Min, x_idx, y_idx); + ImPlotPoint p2 = PixelsToPlot(plot.SelectRect.Max + plot.PlotRect.Min, x_idx, y_idx); + ImPlotRect result; result.X.Min = ImMin(p1.x, p2.x); result.X.Max = ImMax(p1.x, p2.x); result.Y.Min = ImMin(p1.y, p2.y); @@ -3250,412 +3560,400 @@ ImPlotLimits GetPlotSelection(ImPlotYAxis y_axis) { return result; } -bool IsPlotQueried() { +void CancelPlotSelection() { ImPlotContext& gp = *GImPlot; - IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "IsPlotQueried() needs to be called between BeginPlot() and EndPlot()!"); - return gp.CurrentPlot->Queried; -} - -ImPlotLimits GetPlotQuery(ImPlotYAxis y_axis) { - ImPlotContext& gp = *GImPlot; - IM_ASSERT_USER_ERROR(y_axis >= -1 && y_axis < IMPLOT_Y_AXES, "y_axis needs to between -1 and IMPLOT_Y_AXES"); - IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "GetPlotQuery() needs to be called between BeginPlot() and EndPlot()!"); + IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "CancelPlotSelection() needs to be called between BeginPlot() and EndPlot()!"); + SetupLock(); ImPlotPlot& plot = *gp.CurrentPlot; - y_axis = y_axis >= 0 ? y_axis : gp.CurrentPlot->CurrentYAxis; - if (!plot.Queried) - return ImPlotLimits(0,0,0,0); - UpdateTransformCache(); - ImPlotPoint p1 = PixelsToPlot(plot.QueryRect.Min + plot.PlotRect.Min, y_axis); - ImPlotPoint p2 = PixelsToPlot(plot.QueryRect.Max + plot.PlotRect.Min, y_axis); - ImPlotLimits result; - result.X.Min = ImMin(p1.x, p2.x); - result.X.Max = ImMax(p1.x, p2.x); - result.Y.Min = ImMin(p1.y, p2.y); - result.Y.Max = ImMax(p1.y, p2.y); - return result; + if (plot.Selected) + plot.Selected = plot.Selecting = false; } -void SetPlotQuery(const ImPlotLimits& query, ImPlotYAxis y_axis) { +void HideNextItem(bool hidden, ImPlotCond cond) { ImPlotContext& gp = *GImPlot; - IM_ASSERT_USER_ERROR(y_axis >= -1 && y_axis < IMPLOT_Y_AXES, "y_axis needs to between -1 and IMPLOT_Y_AXES"); - IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "GetPlotQuery() needs to be called between BeginPlot() and EndPlot()!"); - ImPlotPlot& plot = *gp.CurrentPlot; - y_axis = y_axis >= 0 ? y_axis : gp.CurrentPlot->CurrentYAxis; - UpdateTransformCache(); - ImVec2 p1 = PlotToPixels(query.Min(),y_axis); - ImVec2 p2 = PlotToPixels(query.Max(),y_axis); - plot.Queried = true; - plot.Querying = false; - plot.QueryRect = ImRect(ImMin(p1,p2)-plot.PlotRect.Min, ImMax(p1,p2)-plot.PlotRect.Min); + gp.NextItemData.HasHidden = true; + gp.NextItemData.Hidden = hidden; + gp.NextItemData.HiddenCond = cond; } -void AnnotateEx(double x, double y, bool clamp, const ImVec4& col, const ImVec2& off, const char* fmt, va_list args) { +//----------------------------------------------------------------------------- +// [SECTION] Plot Tools +//----------------------------------------------------------------------------- + +void Annotation(double x, double y, const ImVec4& col, const ImVec2& offset, bool clamp, bool round) { ImPlotContext& gp = *GImPlot; - IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "Annotate() needs to be called between BeginPlot() and EndPlot()!"); - ImVec2 pos = PlotToPixels(x,y); + IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "Annotation() needs to be called between BeginPlot() and EndPlot()!"); + SetupLock(); + char x_buff[IMPLOT_LABEL_MAX_SIZE]; + char y_buff[IMPLOT_LABEL_MAX_SIZE]; + ImPlotAxis& x_axis = gp.CurrentPlot->Axes[gp.CurrentPlot->CurrentX]; + ImPlotAxis& y_axis = gp.CurrentPlot->Axes[gp.CurrentPlot->CurrentX]; + LabelAxisValue(x_axis, x, x_buff, sizeof(x_buff), round); + LabelAxisValue(y_axis, y, y_buff, sizeof(y_buff), round); + Annotation(x,y,col,offset,clamp,"%s, %s",x_buff,y_buff); +} + +void AnnotationV(double x, double y, const ImVec4& col, const ImVec2& offset, bool clamp, const char* fmt, va_list args) { + ImPlotContext& gp = *GImPlot; + IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "Annotation() needs to be called between BeginPlot() and EndPlot()!"); + SetupLock(); + ImVec2 pos = PlotToPixels(x,y,IMPLOT_AUTO,IMPLOT_AUTO); ImU32 bg = ImGui::GetColorU32(col); ImU32 fg = col.w == 0 ? GetStyleColorU32(ImPlotCol_InlayText) : CalcTextColor(col); - gp.Annotations.AppendV(pos, off, bg, fg, clamp, fmt, args); + gp.Annotations.AppendV(pos, offset, bg, fg, clamp, fmt, args); } -void AnnotateV(double x, double y, const ImVec2& offset, const char* fmt, va_list args) { - AnnotateEx(x,y,false,ImVec4(0,0,0,0),offset,fmt,args); -} - -void Annotate(double x, double y, const ImVec2& offset, const char* fmt, ...) { +void Annotation(double x, double y, const ImVec4& col, const ImVec2& offset, bool clamp, const char* fmt, ...) { va_list args; va_start(args, fmt); - AnnotateV(x,y,offset,fmt,args); + AnnotationV(x,y,col,offset,clamp,fmt,args); va_end(args); } -void AnnotateV(double x, double y, const ImVec2& offset, const ImVec4& col, const char* fmt, va_list args) { - AnnotateEx(x,y,false,col,offset,fmt,args); +void TagV(ImAxis axis, double v, const ImVec4& col, const char* fmt, va_list args) { + ImPlotContext& gp = *GImPlot; + SetupLock(); + ImU32 bg = ImGui::GetColorU32(col); + ImU32 fg = col.w == 0 ? GetStyleColorU32(ImPlotCol_AxisText) : CalcTextColor(col); + gp.Tags.AppendV(axis,v,bg,fg,fmt,args); } -void Annotate(double x, double y, const ImVec2& offset, const ImVec4& col, const char* fmt, ...) { +void Tag(ImAxis axis, double v, const ImVec4& col, const char* fmt, ...) { va_list args; va_start(args, fmt); - AnnotateV(x,y,offset,col,fmt,args); + TagV(axis,v,col,fmt,args); va_end(args); } -void AnnotateClampedV(double x, double y, const ImVec2& offset, const char* fmt, va_list args) { - AnnotateEx(x,y,true,ImVec4(0,0,0,0),offset,fmt,args); +void Tag(ImAxis axis, double v, const ImVec4& color, bool round) { + ImPlotContext& gp = *GImPlot; + SetupLock(); + char buff[IMPLOT_LABEL_MAX_SIZE]; + ImPlotAxis& ax = gp.CurrentPlot->Axes[axis]; + LabelAxisValue(ax, v, buff, sizeof(buff), round); + Tag(axis,v,color,"%s",buff); } -void AnnotateClamped(double x, double y, const ImVec2& offset, const char* fmt, ...) { +IMPLOT_API void TagX(double x, const ImVec4& color, bool round) { + IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != NULL, "TagX() needs to be called between BeginPlot() and EndPlot()!"); + Tag(GImPlot->CurrentPlot->CurrentX, x, color, round); +} + +IMPLOT_API void TagX(double x, const ImVec4& color, const char* fmt, ...) { + IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != NULL, "TagX() needs to be called between BeginPlot() and EndPlot()!"); va_list args; va_start(args, fmt); - AnnotateClampedV(x,y,offset,fmt,args); + TagV(GImPlot->CurrentPlot->CurrentX,x,color,fmt,args); va_end(args); } -void AnnotateClampedV(double x, double y, const ImVec2& offset, const ImVec4& col, const char* fmt, va_list args) { - AnnotateEx(x,y,true,col,offset,fmt,args); +IMPLOT_API void TagXV(double x, const ImVec4& color, const char* fmt, va_list args) { + IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != NULL, "TagX() needs to be called between BeginPlot() and EndPlot()!"); + TagV(GImPlot->CurrentPlot->CurrentX, x, color, fmt, args); } -void AnnotateClamped(double x, double y, const ImVec2& offset, const ImVec4& col, const char* fmt, ...) { +IMPLOT_API void TagY(double y, const ImVec4& color, bool round) { + IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != NULL, "TagY() needs to be called between BeginPlot() and EndPlot()!"); + Tag(GImPlot->CurrentPlot->CurrentY, y, color, round); +} + +IMPLOT_API void TagY(double y, const ImVec4& color, const char* fmt, ...) { + IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != NULL, "TagY() needs to be called between BeginPlot() and EndPlot()!"); va_list args; va_start(args, fmt); - AnnotateClampedV(x,y,offset,col,fmt,args); + TagV(GImPlot->CurrentPlot->CurrentY,y,color,fmt,args); va_end(args); } -bool DragLineX(const char* id, double* value, bool show_label, const ImVec4& col, float thickness) { +IMPLOT_API void TagYV(double y, const ImVec4& color, const char* fmt, va_list args) { + IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != NULL, "TagY() needs to be called between BeginPlot() and EndPlot()!"); + TagV(GImPlot->CurrentPlot->CurrentY, y, color, fmt, args); +} + +static const float DRAG_GRAB_HALF_SIZE = 4.0f; + +bool DragPoint(int n_id, double* x, double* y, const ImVec4& col, float radius, ImPlotDragToolFlags flags) { + ImGui::PushID("#IMPLOT_DRAG_POINT"); + IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != NULL, "DragPoint() needs to be called between BeginPlot() and EndPlot()!"); + SetupLock(); + + if (!ImHasFlag(flags,ImPlotDragToolFlags_NoFit) && FitThisFrame()) { + FitPoint(ImPlotPoint(*x,*y)); + } + + const bool input = !ImHasFlag(flags, ImPlotDragToolFlags_NoInputs); + const bool show_curs = !ImHasFlag(flags, ImPlotDragToolFlags_NoCursors); + const bool no_delay = !ImHasFlag(flags, ImPlotDragToolFlags_Delayed); + const float grab_half_size = ImMax(DRAG_GRAB_HALF_SIZE, radius); + const ImVec4 color = IsColorAuto(col) ? ImGui::GetStyleColorVec4(ImGuiCol_Text) : col; + const ImU32 col32 = ImGui::ColorConvertFloat4ToU32(color); + + ImVec2 pos = PlotToPixels(*x,*y,IMPLOT_AUTO,IMPLOT_AUTO); + const ImGuiID id = ImGui::GetCurrentWindow()->GetID(n_id); + ImRect rect(pos.x-grab_half_size,pos.y-grab_half_size,pos.x+grab_half_size,pos.y+grab_half_size); + bool hovered = false, held = false; + + ImGui::KeepAliveID(id); + if (input) + ImGui::ButtonBehavior(rect,id,&hovered,&held); + + bool dragging = false; + if (held && ImGui::IsMouseDragging(0)) { + *x = ImPlot::GetPlotMousePos(IMPLOT_AUTO,IMPLOT_AUTO).x; + *y = ImPlot::GetPlotMousePos(IMPLOT_AUTO,IMPLOT_AUTO).y; + dragging = true; + } + + PushPlotClipRect(); + ImDrawList& DrawList = *GetPlotDrawList(); + if ((hovered || held) && show_curs) + ImGui::SetMouseCursor(ImGuiMouseCursor_Hand); + if (dragging && no_delay) + pos = PlotToPixels(*x,*y,IMPLOT_AUTO,IMPLOT_AUTO); + DrawList.AddCircleFilled(pos, radius, col32); + PopPlotClipRect(); + + ImGui::PopID(); + return dragging; +} + +bool DragLineX(int n_id, double* value, const ImVec4& col, float thickness, ImPlotDragToolFlags flags) { + ImGui::PushID("#IMPLOT_DRAG_LINE_X"); ImPlotContext& gp = *GImPlot; IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "DragLineX() needs to be called between BeginPlot() and EndPlot()!"); - const float grab_size = ImMax(5.0f, thickness); + SetupLock(); + + if (!ImHasFlag(flags,ImPlotDragToolFlags_NoFit) && FitThisFrame()) { + FitPointX(*value); + } + + const bool input = !ImHasFlag(flags, ImPlotDragToolFlags_NoInputs); + const bool show_curs = !ImHasFlag(flags, ImPlotDragToolFlags_NoCursors); + const bool no_delay = !ImHasFlag(flags, ImPlotDragToolFlags_Delayed); + const float grab_half_size = ImMax(DRAG_GRAB_HALF_SIZE, thickness/2); float yt = gp.CurrentPlot->PlotRect.Min.y; float yb = gp.CurrentPlot->PlotRect.Max.y; - float x = IM_ROUND(PlotToPixels(*value,0).x); - const bool outside = x < (gp.CurrentPlot->PlotRect.Min.x - grab_size / 2) || x > (gp.CurrentPlot->PlotRect.Max.x + grab_size / 2); - if (outside) - return false; + float x = IM_ROUND(PlotToPixels(*value,0,IMPLOT_AUTO,IMPLOT_AUTO).x); + const ImGuiID id = ImGui::GetCurrentWindow()->GetID(n_id); + ImRect rect(x-grab_half_size,yt,x+grab_half_size,yb); + bool hovered = false, held = false; + + ImGui::KeepAliveID(id); + if (input) + ImGui::ButtonBehavior(rect,id,&hovered,&held); + + if ((hovered || held) && show_curs) + ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeEW); + float len = gp.Style.MajorTickLen.x; ImVec4 color = IsColorAuto(col) ? ImGui::GetStyleColorVec4(ImGuiCol_Text) : col; ImU32 col32 = ImGui::ColorConvertFloat4ToU32(color); - ImDrawList& DrawList = *GetPlotDrawList(); + + bool dragging = false; + if (held && ImGui::IsMouseDragging(0)) { + *value = ImPlot::GetPlotMousePos(IMPLOT_AUTO,IMPLOT_AUTO).x; + dragging = true; + } + PushPlotClipRect(); - DrawList.AddLine(ImVec2(x,yt), ImVec2(x,yb), col32, thickness); + ImDrawList& DrawList = *GetPlotDrawList(); + if (dragging && no_delay) + x = IM_ROUND(PlotToPixels(*value,0,IMPLOT_AUTO,IMPLOT_AUTO).x); + DrawList.AddLine(ImVec2(x,yt), ImVec2(x,yb), col32, thickness); DrawList.AddLine(ImVec2(x,yt), ImVec2(x,yt+len), col32, 3*thickness); DrawList.AddLine(ImVec2(x,yb), ImVec2(x,yb-len), col32, 3*thickness); PopPlotClipRect(); - if (gp.CurrentPlot->Selecting || gp.CurrentPlot->Querying) - return false; - ImVec2 old_cursor_pos = ImGui::GetCursorScreenPos(); - ImVec2 new_cursor_pos = ImVec2(x - grab_size / 2.0f, yt); - ImGui::GetCurrentWindow()->DC.CursorPos = new_cursor_pos; - ImGui::InvisibleButton(id, ImVec2(grab_size, yb-yt)); - ImGui::GetCurrentWindow()->DC.CursorPos = old_cursor_pos; - if (ImGui::IsItemHovered() || ImGui::IsItemActive()) { - gp.CurrentPlot->PlotHovered = false; - ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeEW); - if (show_label) { - char buff[32]; - LabelAxisValue(gp.CurrentPlot->XAxis, gp.XTicks, *value, buff, 32); - gp.Annotations.Append(ImVec2(x,yb),ImVec2(0,0),col32,CalcTextColor(color),true,"%s = %s", id, buff); - } - } - bool dragging = false; - if (ImGui::IsItemActive() && ImGui::IsMouseDragging(0)) { - *value = ImPlot::GetPlotMousePos().x; - *value = ImClamp(*value, gp.CurrentPlot->XAxis.Range.Min, gp.CurrentPlot->XAxis.Range.Max); - dragging = true; - } + + ImGui::PopID(); return dragging; } -bool DragLineY(const char* id, double* value, bool show_label, const ImVec4& col, float thickness) { +bool DragLineY(int n_id, double* value, const ImVec4& col, float thickness, ImPlotDragToolFlags flags) { + ImGui::PushID("#IMPLOT_DRAG_LINE_Y"); ImPlotContext& gp = *GImPlot; IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "DragLineY() needs to be called between BeginPlot() and EndPlot()!"); - const float grab_size = ImMax(5.0f, thickness); + SetupLock(); + + if (!ImHasFlag(flags,ImPlotDragToolFlags_NoFit) && FitThisFrame()) { + FitPointY(*value); + } + + const bool input = !ImHasFlag(flags, ImPlotDragToolFlags_NoInputs); + const bool show_curs = !ImHasFlag(flags, ImPlotDragToolFlags_NoCursors); + const bool no_delay = !ImHasFlag(flags, ImPlotDragToolFlags_Delayed); + const float grab_half_size = ImMax(DRAG_GRAB_HALF_SIZE, thickness/2); float xl = gp.CurrentPlot->PlotRect.Min.x; float xr = gp.CurrentPlot->PlotRect.Max.x; - float y = IM_ROUND(PlotToPixels(0, *value).y); - const bool outside = y < (gp.CurrentPlot->PlotRect.Min.y - grab_size / 2) || y > (gp.CurrentPlot->PlotRect.Max.y + grab_size / 2); - if (outside) - return false; + float y = IM_ROUND(PlotToPixels(0, *value,IMPLOT_AUTO,IMPLOT_AUTO).y); + + const ImGuiID id = ImGui::GetCurrentWindow()->GetID(n_id); + ImRect rect(xl,y-grab_half_size,xr,y+grab_half_size); + bool hovered = false, held = false; + + ImGui::KeepAliveID(id); + if (input) + ImGui::ButtonBehavior(rect,id,&hovered,&held); + + if ((hovered || held) && show_curs) + ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNS); + float len = gp.Style.MajorTickLen.y; ImVec4 color = IsColorAuto(col) ? ImGui::GetStyleColorVec4(ImGuiCol_Text) : col; ImU32 col32 = ImGui::ColorConvertFloat4ToU32(color); - ImDrawList& DrawList = *GetPlotDrawList(); + + bool dragging = false; + if (held && ImGui::IsMouseDragging(0)) { + *value = ImPlot::GetPlotMousePos(IMPLOT_AUTO,IMPLOT_AUTO).y; + dragging = true; + } + PushPlotClipRect(); - DrawList.AddLine(ImVec2(xl,y), ImVec2(xr,y), col32, thickness); + ImDrawList& DrawList = *GetPlotDrawList(); + if (dragging && no_delay) + y = IM_ROUND(PlotToPixels(0, *value,IMPLOT_AUTO,IMPLOT_AUTO).y); + DrawList.AddLine(ImVec2(xl,y), ImVec2(xr,y), col32, thickness); DrawList.AddLine(ImVec2(xl,y), ImVec2(xl+len,y), col32, 3*thickness); DrawList.AddLine(ImVec2(xr,y), ImVec2(xr-len,y), col32, 3*thickness); PopPlotClipRect(); - if (gp.CurrentPlot->Selecting || gp.CurrentPlot->Querying) - return false; - ImVec2 old_cursor_pos = ImGui::GetCursorScreenPos(); - ImVec2 new_cursor_pos = ImVec2(xl, y - grab_size / 2.0f); - ImGui::SetItemAllowOverlap(); - ImGui::GetCurrentWindow()->DC.CursorPos = new_cursor_pos; - ImGui::InvisibleButton(id, ImVec2(xr - xl, grab_size)); - ImGui::GetCurrentWindow()->DC.CursorPos = old_cursor_pos; - int yax = GetCurrentYAxis(); - if (ImGui::IsItemHovered() || ImGui::IsItemActive()) { - gp.CurrentPlot->PlotHovered = false; - ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNS); - if (show_label) { - char buff[32]; - LabelAxisValue(gp.CurrentPlot->YAxis[yax], gp.YTicks[yax], *value, buff, 32); - gp.Annotations.Append(ImVec2(yax == 0 ? xl : xr,y), ImVec2(0,0), col32, CalcTextColor(color), true, "%s = %s", id, buff); - } - } - bool dragging = false; - if (ImGui::IsItemActive() && ImGui::IsMouseDragging(0)) { - *value = ImPlot::GetPlotMousePos().y; - *value = ImClamp(*value, gp.CurrentPlot->YAxis[yax].Range.Min, gp.CurrentPlot->YAxis[yax].Range.Max); - dragging = true; - } + + ImGui::PopID(); return dragging; } -bool DragPoint(const char* id, double* x, double* y, bool show_label, const ImVec4& col, float radius) { - ImPlotContext& gp = *GImPlot; - IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "DragPoint() needs to be called between BeginPlot() and EndPlot()!"); - const float grab_size = ImMax(5.0f, 2*radius); - const bool outside = !GetPlotLimits().Contains(*x,*y); - if (outside) - return false; - const ImVec4 color = IsColorAuto(col) ? ImGui::GetStyleColorVec4(ImGuiCol_Text) : col; - const ImU32 col32 = ImGui::ColorConvertFloat4ToU32(color); - ImDrawList& DrawList = *GetPlotDrawList(); - const ImVec2 pos = PlotToPixels(*x,*y); - int yax = GetCurrentYAxis(); - ImVec2 old_cursor_pos = ImGui::GetCursorScreenPos(); - ImVec2 new_cursor_pos = ImVec2(pos - ImVec2(grab_size,grab_size)*0.5f); - ImGui::GetCurrentWindow()->DC.CursorPos = new_cursor_pos; - ImGui::InvisibleButton(id, ImVec2(grab_size, grab_size)); - ImGui::GetCurrentWindow()->DC.CursorPos = old_cursor_pos; - PushPlotClipRect(); - if (ImGui::IsItemHovered() || ImGui::IsItemActive()) { - DrawList.AddCircleFilled(pos, 1.5f*radius, (col32)); - gp.CurrentPlot->PlotHovered = false; - if (show_label) { - ImVec2 label_pos = pos + ImVec2(16 * GImGui->Style.MouseCursorScale, 8 * GImGui->Style.MouseCursorScale); - char buff1[32]; - char buff2[32]; - LabelAxisValue(gp.CurrentPlot->XAxis, gp.XTicks, *x, buff1, 32); - LabelAxisValue(gp.CurrentPlot->YAxis[yax], gp.YTicks[yax], *y, buff2, 32); - gp.Annotations.Append(label_pos, ImVec2(0.0001f,0.00001f), col32, CalcTextColor(color), true, "%s = %s,%s", id, buff1, buff2); +bool DragRect(int n_id, double* x_min, double* y_min, double* x_max, double* y_max, const ImVec4& col, ImPlotDragToolFlags flags) { + ImGui::PushID("#IMPLOT_DRAG_RECT"); + IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != NULL, "DragRect() needs to be called between BeginPlot() and EndPlot()!"); + SetupLock(); + + if (!ImHasFlag(flags,ImPlotDragToolFlags_NoFit) && FitThisFrame()) { + FitPoint(ImPlotPoint(*x_min,*y_min)); + FitPoint(ImPlotPoint(*x_max,*y_max)); + } + + const bool input = !ImHasFlag(flags, ImPlotDragToolFlags_NoInputs); + const bool show_curs = !ImHasFlag(flags, ImPlotDragToolFlags_NoCursors); + const bool no_delay = !ImHasFlag(flags, ImPlotDragToolFlags_Delayed); + bool h[] = {true,false,true,false}; + double* x[] = {x_min,x_max,x_max,x_min}; + double* y[] = {y_min,y_min,y_max,y_max}; + ImVec2 p[4]; + for (int i = 0; i < 4; ++i) + p[i] = PlotToPixels(*x[i],*y[i],IMPLOT_AUTO,IMPLOT_AUTO); + ImVec2 pc = PlotToPixels((*x_min+*x_max)/2,(*y_min+*y_max)/2,IMPLOT_AUTO,IMPLOT_AUTO); + ImRect rect(ImMin(p[0],p[2]),ImMax(p[0],p[2])); + ImRect rect_grab = rect; rect_grab.Expand(DRAG_GRAB_HALF_SIZE); + + ImGuiMouseCursor cur[4]; + if (show_curs) { + cur[0] = (rect.Min.x == p[0].x && rect.Min.y == p[0].y) || (rect.Max.x == p[0].x && rect.Max.y == p[0].y) ? ImGuiMouseCursor_ResizeNWSE : ImGuiMouseCursor_ResizeNESW; + cur[1] = cur[0] == ImGuiMouseCursor_ResizeNWSE ? ImGuiMouseCursor_ResizeNESW : ImGuiMouseCursor_ResizeNWSE; + cur[2] = cur[1] == ImGuiMouseCursor_ResizeNWSE ? ImGuiMouseCursor_ResizeNESW : ImGuiMouseCursor_ResizeNWSE; + cur[3] = cur[2] == ImGuiMouseCursor_ResizeNWSE ? ImGuiMouseCursor_ResizeNESW : ImGuiMouseCursor_ResizeNWSE; + } + + ImVec4 color = IsColorAuto(col) ? ImGui::GetStyleColorVec4(ImGuiCol_Text) : col; + ImU32 col32 = ImGui::ColorConvertFloat4ToU32(color); + color.w *= 0.25f; + ImU32 col32_a = ImGui::ColorConvertFloat4ToU32(color); + const ImGuiID id = ImGui::GetCurrentWindow()->GetID(n_id); + + bool dragging = false; + bool hovered = false, held = false; + ImRect b_rect(pc.x-DRAG_GRAB_HALF_SIZE,pc.y-DRAG_GRAB_HALF_SIZE,pc.x+DRAG_GRAB_HALF_SIZE,pc.y+DRAG_GRAB_HALF_SIZE); + + ImGui::KeepAliveID(id); + if (input) + ImGui::ButtonBehavior(b_rect,id,&hovered,&held); + + if ((hovered || held) && show_curs) + ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeAll); + if (held && ImGui::IsMouseDragging(0)) { + for (int i = 0; i < 4; ++i) { + ImPlotPoint pp = PixelsToPlot(p[i] + ImGui::GetIO().MouseDelta,IMPLOT_AUTO,IMPLOT_AUTO); + *y[i] = pp.y; + *x[i] = pp.x; + } + dragging = true; + } + + for (int i = 0; i < 4; ++i) { + // points + b_rect = ImRect(p[i].x-DRAG_GRAB_HALF_SIZE,p[i].y-DRAG_GRAB_HALF_SIZE,p[i].x+DRAG_GRAB_HALF_SIZE,p[i].y+DRAG_GRAB_HALF_SIZE); + ImGuiID p_id = id + i + 1; + ImGui::KeepAliveID(p_id); + if (input) + ImGui::ButtonBehavior(b_rect,p_id,&hovered,&held); + if ((hovered || held) && show_curs) + ImGui::SetMouseCursor(cur[i]); + + if (held && ImGui::IsMouseDragging(0)) { + *x[i] = ImPlot::GetPlotMousePos(IMPLOT_AUTO,IMPLOT_AUTO).x; + *y[i] = ImPlot::GetPlotMousePos(IMPLOT_AUTO,IMPLOT_AUTO).y; + dragging = true; + } + + // edges + ImVec2 e_min = ImMin(p[i],p[(i+1)%4]); + ImVec2 e_max = ImMax(p[i],p[(i+1)%4]); + b_rect = h[i] ? ImRect(e_min.x + DRAG_GRAB_HALF_SIZE, e_min.y - DRAG_GRAB_HALF_SIZE, e_max.x - DRAG_GRAB_HALF_SIZE, e_max.y + DRAG_GRAB_HALF_SIZE) + : ImRect(e_min.x - DRAG_GRAB_HALF_SIZE, e_min.y + DRAG_GRAB_HALF_SIZE, e_max.x + DRAG_GRAB_HALF_SIZE, e_max.y - DRAG_GRAB_HALF_SIZE); + ImGuiID e_id = id + i + 5; + ImGui::KeepAliveID(e_id); + if (input) + ImGui::ButtonBehavior(b_rect,e_id,&hovered,&held); + if ((hovered || held) && show_curs) + h[i] ? ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNS) : ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeEW); + if (held && ImGui::IsMouseDragging(0)) { + if (h[i]) + *y[i] = ImPlot::GetPlotMousePos(IMPLOT_AUTO,IMPLOT_AUTO).y; + else + *x[i] = ImPlot::GetPlotMousePos(IMPLOT_AUTO,IMPLOT_AUTO).x; + dragging = true; + } + if (hovered && ImGui::IsMouseDoubleClicked(0)) + { + ImPlotRect b = GetPlotLimits(IMPLOT_AUTO,IMPLOT_AUTO); + if (h[i]) + *y[i] = ((y[i] == y_min && *y_min < *y_max) || (y[i] == y_max && *y_max < *y_min)) ? b.Y.Min : b.Y.Max; + else + *x[i] = ((x[i] == x_min && *x_min < *x_max) || (x[i] == x_max && *x_max < *x_min)) ? b.X.Min : b.X.Max; + dragging = true; } } - else { - DrawList.AddCircleFilled(pos, radius, col32); + + + PushPlotClipRect(); + ImDrawList& DrawList = *GetPlotDrawList(); + if (dragging && no_delay) { + for (int i = 0; i < 4; ++i) + p[i] = PlotToPixels(*x[i],*y[i],IMPLOT_AUTO,IMPLOT_AUTO); + pc = PlotToPixels((*x_min+*x_max)/2,(*y_min+*y_max)/2,IMPLOT_AUTO,IMPLOT_AUTO); + rect = ImRect(ImMin(p[0],p[2]),ImMax(p[0],p[2])); + } + DrawList.AddRectFilled(rect.Min, rect.Max, col32_a); + DrawList.AddRect(rect.Min, rect.Max, col32); + if (input && (dragging || rect_grab.Contains(ImGui::GetMousePos()))) { + DrawList.AddCircleFilled(pc,DRAG_GRAB_HALF_SIZE,col32); + for (int i = 0; i < 4; ++i) + DrawList.AddCircleFilled(p[i],DRAG_GRAB_HALF_SIZE,col32); } PopPlotClipRect(); - - - bool dragging = false; - if (ImGui::IsItemActive() && ImGui::IsMouseDragging(0)) { - *x = ImPlot::GetPlotMousePos().x; - *y = ImPlot::GetPlotMousePos().y; - *x = ImClamp(*x, gp.CurrentPlot->XAxis.Range.Min, gp.CurrentPlot->XAxis.Range.Max); - *y = ImClamp(*y, gp.CurrentPlot->YAxis[yax].Range.Min, gp.CurrentPlot->YAxis[yax].Range.Max); - dragging = true; - } + ImGui::PopID(); return dragging; } -//----------------------------------------------------------------------------- - -#define IMPLOT_ID_PLT 10030910 -#define IMPLOT_ID_LEG 10030911 -#define IMPLOT_ID_XAX 10030912 -#define IMPLOT_ID_YAX 10030913 -#define IMPLOT_ID_ITM 10030914 - -bool BeginDragDropTargetEx(int id, const ImRect& rect) { - ImGuiContext& G = *GImGui; - const ImGuiID ID = G.CurrentWindow->GetID(id); - if (ImGui::ItemAdd(rect, ID, &rect) && - ImGui::BeginDragDropTarget()) - return true; - return false; -} - -bool BeginDragDropTarget() { - return BeginDragDropTargetEx(IMPLOT_ID_PLT, GImPlot->CurrentPlot->PlotRect); -} - -bool BeginDragDropTargetX() { - return BeginDragDropTargetEx(IMPLOT_ID_XAX, GImPlot->CurrentPlot->XAxis.HoverRect); -} - -bool BeginDragDropTargetY(ImPlotYAxis axis) { - return BeginDragDropTargetEx(IMPLOT_ID_YAX + axis, GImPlot->CurrentPlot->YAxis[axis].HoverRect); -} - -bool BeginDragDropTargetLegend() { - return BeginDragDropTargetEx(IMPLOT_ID_LEG, GImPlot->CurrentItems->Legend.Rect); -} - -void EndDragDropTarget() { - ImGui::EndDragDropTarget(); -} - -bool BeginDragDropSourceEx(ImGuiID source_id, bool is_hovered, ImGuiDragDropFlags flags, ImGuiKeyModFlags key_mods) { - ImGuiContext& g = *GImGui; - ImGuiWindow* window = g.CurrentWindow; - ImGuiMouseButton mouse_button = ImGuiMouseButton_Left; - - if (g.IO.MouseDown[mouse_button] == false) { - if (g.ActiveId == source_id) - ImGui::ClearActiveID(); - return false; - } - - if (is_hovered && g.IO.MouseClicked[mouse_button] && g.IO.KeyMods == key_mods) { - ImGui::SetActiveID(source_id, window); - ImGui::FocusWindow(window); - } - - if (g.ActiveId != source_id) { - return false; - } - - g.ActiveIdAllowOverlap = is_hovered; - g.ActiveIdUsingNavDirMask = ~(ImU32)0; - g.ActiveIdUsingNavInputMask = ~(ImU32)0; - g.ActiveIdUsingKeyInputMask = ~(ImU64)0; - - if (ImGui::IsMouseDragging(mouse_button)) { - - if (!g.DragDropActive) { - ImGui::ClearDragDrop(); - ImGuiPayload& payload = g.DragDropPayload; - payload.SourceId = source_id; - payload.SourceParentId = 0; - g.DragDropActive = true; - g.DragDropSourceFlags = 0; - g.DragDropMouseButton = mouse_button; - } - g.DragDropSourceFrameCount = g.FrameCount; - g.DragDropWithinSource = true; - - if (!(flags & ImGuiDragDropFlags_SourceNoPreviewTooltip)) { - ImGui::BeginTooltip(); - if (g.DragDropAcceptIdPrev && (g.DragDropAcceptFlags & ImGuiDragDropFlags_AcceptNoPreviewTooltip)) { - ImGuiWindow* tooltip_window = g.CurrentWindow; - tooltip_window->SkipItems = true; - tooltip_window->HiddenFramesCanSkipItems = 1; - } - } - - return true; - } - - return false; -} - -bool BeginDragDropSource(ImGuiKeyModFlags key_mods, ImGuiDragDropFlags flags) { - if (ImGui::GetIO().KeyMods == key_mods) { - GImPlot->CurrentPlot->XAxis.Dragging = false; - for (int i = 0; i < IMPLOT_Y_AXES; ++i) - GImPlot->CurrentPlot->YAxis[i].Dragging = false; - } - const ImGuiID ID = GImGui->CurrentWindow->GetID(IMPLOT_ID_PLT); - ImRect rect = GImPlot->CurrentPlot->PlotRect; - return ImGui::ItemAdd(rect, ID, &rect) && BeginDragDropSourceEx(ID, GImPlot->CurrentPlot->PlotHovered, flags, key_mods); -} - -bool BeginDragDropSourceX(ImGuiKeyModFlags key_mods, ImGuiDragDropFlags flags) { - if (ImGui::GetIO().KeyMods == key_mods) - GImPlot->CurrentPlot->XAxis.Dragging = false; - const ImGuiID ID = GImGui->CurrentWindow->GetID(IMPLOT_ID_XAX); - ImRect rect = GImPlot->CurrentPlot->XAxis.HoverRect; - return ImGui::ItemAdd(rect, ID, &rect) && BeginDragDropSourceEx(ID, GImPlot->CurrentPlot->XAxis.ExtHovered, flags, key_mods); -} - -bool BeginDragDropSourceY(ImPlotYAxis axis, ImGuiKeyModFlags key_mods, ImGuiDragDropFlags flags) { - if (ImGui::GetIO().KeyMods == key_mods) - GImPlot->CurrentPlot->YAxis[axis].Dragging = false; - const ImGuiID ID = GImGui->CurrentWindow->GetID(IMPLOT_ID_YAX + axis); - ImRect rect = GImPlot->CurrentPlot->YAxis[axis].HoverRect; - return ImGui::ItemAdd(rect, ID, &rect) && BeginDragDropSourceEx(ID, GImPlot->CurrentPlot->YAxis[axis].ExtHovered, flags, key_mods); -} - -bool BeginDragDropSourceItem(const char* label_id, ImGuiDragDropFlags flags) { - ImPlotContext& gp = *GImPlot; - IM_ASSERT_USER_ERROR(gp.CurrentItems != NULL, "BeginDragDropSourceItem() needs to be called within an itemized context!"); - ImGuiID item_id = ImGui::GetIDWithSeed(label_id, NULL, gp.CurrentItems->ID); - ImPlotItem* item = gp.CurrentItems->GetItem(item_id); - bool is_hovered = item && item->LegendHovered; - ImGuiID temp_id = ImGui::GetIDWithSeed("dnd",NULL,item->ID); // total hack - return BeginDragDropSourceEx(temp_id, is_hovered, flags, ImGuiKeyModFlags_None); -} - -void EndDragDropSource() { - ImGui::EndDragDropSource(); -} - -void ItemIcon(const ImVec4& col) { - ItemIcon(ImGui::ColorConvertFloat4ToU32(col)); -} - -void ItemIcon(ImU32 col) { - const float txt_size = ImGui::GetTextLineHeight(); - ImVec2 size(txt_size-4,txt_size); - ImGuiWindow* window = ImGui::GetCurrentWindow(); - ImVec2 pos = window->DC.CursorPos; - ImGui::GetWindowDrawList()->AddRectFilled(pos + ImVec2(0,2), pos + size - ImVec2(0,2), col); - ImGui::Dummy(size); -} - -void ColormapIcon(ImPlotColormap cmap) { - ImPlotContext& gp = *GImPlot; - const float txt_size = ImGui::GetTextLineHeight(); - ImVec2 size(txt_size-4,txt_size); - ImGuiWindow* window = ImGui::GetCurrentWindow(); - ImVec2 pos = window->DC.CursorPos; - ImRect rect(pos+ImVec2(0,2),pos+size-ImVec2(0,2)); - ImDrawList& DrawList = *ImGui::GetWindowDrawList(); - RenderColorBar(gp.ColormapData.GetKeys(cmap),gp.ColormapData.GetKeyCount(cmap),DrawList,rect,false,false,!gp.ColormapData.IsQual(cmap)); - ImGui::Dummy(size); +bool DragRect(int id, ImPlotRect* bounds, const ImVec4& col, ImPlotDragToolFlags flags) { + return DragRect(id, &bounds->X.Min, &bounds->Y.Min,&bounds->X.Max, &bounds->Y.Max, col, flags); } //----------------------------------------------------------------------------- - -void SetLegendLocation(ImPlotLocation location, ImPlotOrientation orientation, bool outside) { - ImPlotContext& gp = *GImPlot; - IM_ASSERT_USER_ERROR(gp.CurrentItems != NULL, "SetLegendLocation() needs to be called within an itemized context!"); - gp.CurrentItems->Legend.Location = location; - gp.CurrentItems->Legend.Orientation = orientation; - if (gp.CurrentItems->Legend.Outside != outside) - gp.CurrentItems->Legend.FlipSideNextFrame = true; -} - -void SetMousePosLocation(ImPlotLocation location) { - ImPlotContext& gp = *GImPlot; - IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "SetMousePosLocation() needs to be called between BeginPlot() and EndPlot()!"); - gp.CurrentPlot->MousePosLocation = location; -} +// [SECTION] Legend Utils and Tools +//----------------------------------------------------------------------------- bool IsLegendEntryHovered(const char* label_id) { ImPlotContext& gp = *GImPlot; IM_ASSERT_USER_ERROR(gp.CurrentItems != NULL, "IsPlotItemHighlight() needs to be called within an itemized context!"); + SetupLock(); ImGuiID id = ImGui::GetIDWithSeed(label_id, NULL, gp.CurrentItems->ID); ImPlotItem* item = gp.CurrentItems->GetItem(id); return item && item->LegendHovered; @@ -3664,6 +3962,7 @@ bool IsLegendEntryHovered(const char* label_id) { bool BeginLegendPopup(const char* label_id, ImGuiMouseButton mouse_button) { ImPlotContext& gp = *GImPlot; IM_ASSERT_USER_ERROR(gp.CurrentItems != NULL, "BeginLegendPopup() needs to be called within an itemized context!"); + SetupLock(); ImGuiWindow* window = GImGui->CurrentWindow; if (window->SkipItems) return false; @@ -3677,10 +3976,11 @@ bool BeginLegendPopup(const char* label_id, ImGuiMouseButton mouse_button) { } void EndLegendPopup() { + SetupLock(); ImGui::EndPopup(); } -void ShowAltLegend(const char* title_id, ImPlotOrientation orientation, const ImVec2 size, bool interactable) { +void ShowAltLegend(const char* title_id, bool vertical, const ImVec2 size, bool interactable) { ImPlotContext& gp = *GImPlot; ImGuiContext &G = *GImGui; ImGuiWindow * Window = G.CurrentWindow; @@ -3691,7 +3991,7 @@ void ShowAltLegend(const char* title_id, ImPlotOrientation orientation, const Im ImVec2 legend_size; ImVec2 default_size = gp.Style.LegendPadding * 2; if (plot != NULL) { - legend_size = CalcLegendSize(plot->Items, gp.Style.LegendInnerPadding, gp.Style.LegendSpacing, orientation); + legend_size = CalcLegendSize(plot->Items, gp.Style.LegendInnerPadding, gp.Style.LegendSpacing, vertical); default_size = legend_size + gp.Style.LegendPadding * 2; } ImVec2 frame_size = ImGui::CalcItemSize(size, default_size.x, default_size.y); @@ -3711,16 +4011,116 @@ void ShowAltLegend(const char* title_id, ImPlotOrientation orientation, const Im DrawList.AddRectFilled(legend_bb.Min, legend_bb.Max, col_bg); DrawList.AddRect(legend_bb.Min, legend_bb.Max, col_bd); // render entries - ShowLegendEntries(plot->Items, legend_bb, interactable, gp.Style.LegendInnerPadding, gp.Style.LegendSpacing, orientation, DrawList); + ShowLegendEntries(plot->Items, legend_bb, interactable, gp.Style.LegendInnerPadding, gp.Style.LegendSpacing, vertical, DrawList); } DrawList.PopClipRect(); } //----------------------------------------------------------------------------- -// STYLING +// [SECTION] Drag and Drop Utils +//----------------------------------------------------------------------------- + +bool BeginDragDropTargetPlot() { + SetupLock(); + ImRect rect = GImPlot->CurrentPlot->PlotRect; + return ImGui::BeginDragDropTargetCustom(rect, GImPlot->CurrentPlot->ID); +} + +bool BeginDragDropTargetAxis(ImAxis axis) { + SetupLock(); + ImPlotPlot& plot = *GImPlot->CurrentPlot; + ImPlotAxis& ax = plot.Axes[axis]; + ImRect rect = ax.HoverRect; + rect.Expand(-3.5f); + return ImGui::BeginDragDropTargetCustom(rect, ax.ID); +} + +bool BeginDragDropTargetLegend() { + SetupLock(); + ImPlotItemGroup& items = *GImPlot->CurrentItems; + ImRect rect = items.Legend.Rect; + return ImGui::BeginDragDropTargetCustom(rect, items.ID); +} + +void EndDragDropTarget() { + SetupLock(); + ImGui::EndDragDropTarget(); +} + +bool BeginDragDropSourcePlot(ImGuiDragDropFlags flags) { + SetupLock(); + ImPlotPlot* plot = GImPlot->CurrentPlot; + if (GImGui->IO.KeyMods == GImPlot->InputMap.OverrideMod || GImGui->DragDropPayload.SourceId == plot->ID) + return ImGui::ItemAdd(plot->PlotRect, plot->ID) && ImGui::BeginDragDropSource(flags); + return false; +} + +bool BeginDragDropSourceAxis(ImAxis idx, ImGuiDragDropFlags flags) { + SetupLock(); + ImPlotAxis& axis = GImPlot->CurrentPlot->Axes[idx]; + if (GImGui->IO.KeyMods == GImPlot->InputMap.OverrideMod || GImGui->DragDropPayload.SourceId == axis.ID) + return ImGui::ItemAdd(axis.HoverRect, axis.ID) && ImGui::BeginDragDropSource(flags); + return false; +} + +bool BeginDragDropSourceItem(const char* label_id, ImGuiDragDropFlags flags) { + SetupLock(); + ImPlotContext& gp = *GImPlot; + IM_ASSERT_USER_ERROR(gp.CurrentItems != NULL, "BeginDragDropSourceItem() needs to be called within an itemized context!"); + ImGuiID item_id = ImGui::GetIDWithSeed(label_id, NULL, gp.CurrentItems->ID); + ImPlotItem* item = gp.CurrentItems->GetItem(item_id); + if (item != NULL) { + return ImGui::ItemAdd(item->LegendHoverRect, item->ID) && ImGui::BeginDragDropSource(flags); + } + return false; +} + +void EndDragDropSource() { + SetupLock(); + ImGui::EndDragDropSource(); +} + +//----------------------------------------------------------------------------- +// [SECTION] Aligned Plots +//----------------------------------------------------------------------------- + +bool BeginAlignedPlots(const char* group_id, bool vertical) { + IM_ASSERT_USER_ERROR(GImPlot != NULL, "No current context. Did you call ImPlot::CreateContext() or ImPlot::SetCurrentContext()?"); + IM_ASSERT_USER_ERROR(GImPlot->CurrentAlignmentH == NULL && GImPlot->CurrentAlignmentV == NULL, "Mismatched BeginAlignedPlots()/EndAlignedPlots()!"); + ImPlotContext& gp = *GImPlot; + ImGuiContext &G = *GImGui; + ImGuiWindow * Window = G.CurrentWindow; + if (Window->SkipItems) + return false; + const ImGuiID ID = Window->GetID(group_id); + ImPlotAlignmentData* alignment = gp.AlignmentData.GetOrAddByKey(ID); + if (vertical) + gp.CurrentAlignmentV = alignment; + else + gp.CurrentAlignmentH = alignment; + if (alignment->Vertical != vertical) + alignment->Reset(); + alignment->Vertical = vertical; + alignment->Begin(); + return true; +} + +void EndAlignedPlots() { + IM_ASSERT_USER_ERROR(GImPlot != NULL, "No current context. Did you call ImPlot::CreateContext() or ImPlot::SetCurrentContext()?"); + IM_ASSERT_USER_ERROR(GImPlot->CurrentAlignmentH != NULL || GImPlot->CurrentAlignmentV != NULL, "Mismatched BeginAlignedPlots()/EndAlignedPlots()!"); + ImPlotContext& gp = *GImPlot; + ImPlotAlignmentData* alignment = gp.CurrentAlignmentH != NULL ? gp.CurrentAlignmentH : (gp.CurrentAlignmentV != NULL ? gp.CurrentAlignmentV : NULL); + if (alignment) + alignment->End(); + ResetCtxForNextAlignedPlots(GImPlot); +} + +//----------------------------------------------------------------------------- +// [SECTION] Plot and Item Styling //----------------------------------------------------------------------------- ImPlotStyle& GetStyle() { + IM_ASSERT_USER_ERROR(GImPlot != NULL, "No current context. Did you call ImPlot::CreateContext() or ImPlot::SetCurrentContext()?"); ImPlotContext& gp = *GImPlot; return gp.Style; } @@ -3822,7 +4222,7 @@ void PopStyleVar(int count) { } //------------------------------------------------------------------------------ -// COLORMAPS +// [Section] Colormaps //------------------------------------------------------------------------------ ImPlotColormap AddColormap(const char* name, const ImVec4* colormap, int size, bool qual) { @@ -3983,10 +4383,10 @@ void ColormapScale(const char* label, double scale_min, double scale_max, const ImPlotRange range(scale_min,scale_max); gp.CTicks.Reset(); - AddTicksDefault(range, frame_size.y, ImPlotOrientation_Vertical, gp.CTicks, fmt); + AddTicksDefault(range, frame_size.y, true, gp.CTicks, DefaultFormatter, (void*)fmt); const float txt_off = gp.Style.LabelPadding.x; - const float pad_right = txt_off + gp.CTicks.MaxWidth + (label_size.x > 0 ? txt_off + label_size.y : 0); + const float pad_right = txt_off + gp.CTicks.MaxSize.x + (label_size.x > 0 ? txt_off + label_size.y : 0); float bar_w = 20; if (frame_size.x == 0) @@ -4008,7 +4408,7 @@ void ColormapScale(const char* label, double scale_min, double scale_max, const ImGui::PushClipRect(bb_frame.Min, bb_frame.Max, true); RenderColorBar(gp.ColormapData.GetKeys(cmap), gp.ColormapData.GetKeyCount(cmap), DrawList, bb_grad, true, true, !gp.ColormapData.IsQual(cmap)); - const ImU32 col_tick = GetStyleColorU32(ImPlotCol_YAxis); + const ImU32 col_tick = GetStyleColorU32(ImPlotCol_AxisText); const ImU32 col_text = ImGui::GetColorU32(ImGuiCol_Text); for (int i = 0; i < gp.CTicks.Size; ++i) { const float ypos = ImRemap((float)gp.CTicks.Ticks[i].PlotPos, (float)range.Max, (float)range.Min, bb_grad.Min.y, bb_grad.Max.y); @@ -4019,7 +4419,7 @@ void ColormapScale(const char* label, double scale_min, double scale_max, const DrawList.AddText(ImVec2(bb_grad.Max.x-1, ypos) + ImVec2(txt_off, -gp.CTicks.Ticks[i].LabelSize.y * 0.5f), col_text, gp.CTicks.GetText(i)); } if (label_size.x > 0) { - ImVec2 label_pos(bb_grad.Max.x - 1 + 2*txt_off + gp.CTicks.MaxWidth, bb_grad.GetCenter().y + label_size.x*0.5f ); + ImVec2 label_pos(bb_grad.Max.x - 1 + 2*txt_off + gp.CTicks.MaxSize.x, bb_grad.GetCenter().y + label_size.x*0.5f ); const char* label_end = ImGui::FindRenderedTextEnd(label); AddTextVertical(&DrawList,label_pos,col_text,label,label_end); } @@ -4090,11 +4490,95 @@ bool ColormapButton(const char* label, const ImVec2& size_arg, ImPlotColormap cm return pressed; } +//----------------------------------------------------------------------------- +// [Section] Miscellaneous +//----------------------------------------------------------------------------- + +ImPlotInputMap& GetInputMap() { + IM_ASSERT_USER_ERROR(GImPlot != NULL, "No current context. Did you call ImPlot::CreateContext() or ImPlot::SetCurrentContext()?"); + ImPlotContext& gp = *GImPlot; + return gp.InputMap; +} + +void MapInputDefault(ImPlotInputMap* dst) { + ImPlotInputMap& map = dst ? *dst : GetInputMap(); + map.Pan = ImGuiMouseButton_Left; + map.PanMod = ImGuiModFlags_None; + map.Fit = ImGuiMouseButton_Left; + map.Menu = ImGuiMouseButton_Right; + map.Select = ImGuiMouseButton_Right; + map.SelectMod = ImGuiModFlags_None; + map.SelectCancel = ImGuiMouseButton_Left; + map.SelectHorzMod = ImGuiModFlags_Alt; + map.SelectVertMod = ImGuiModFlags_Shift; + map.OverrideMod = ImGuiModFlags_Ctrl; + map.ZoomMod = ImGuiModFlags_None; + map.ZoomRate = 0.1f; +} + +void MapInputReverse(ImPlotInputMap* dst) { + ImPlotInputMap& map = dst ? *dst : GetInputMap(); + map.Pan = ImGuiMouseButton_Right; + map.PanMod = ImGuiModFlags_None; + map.Fit = ImGuiMouseButton_Left; + map.Menu = ImGuiMouseButton_Right; + map.Select = ImGuiMouseButton_Left; + map.SelectMod = ImGuiModFlags_None; + map.SelectCancel = ImGuiMouseButton_Right; + map.SelectHorzMod = ImGuiModFlags_Alt; + map.SelectVertMod = ImGuiModFlags_Shift; + map.OverrideMod = ImGuiModFlags_Ctrl; + map.ZoomMod = ImGuiModFlags_None; + map.ZoomRate = 0.1f; +} //----------------------------------------------------------------------------- -// Style Editor etc. +// [Section] Miscellaneous //----------------------------------------------------------------------------- +void ItemIcon(const ImVec4& col) { + ItemIcon(ImGui::ColorConvertFloat4ToU32(col)); +} + +void ItemIcon(ImU32 col) { + const float txt_size = ImGui::GetTextLineHeight(); + ImVec2 size(txt_size-4,txt_size); + ImGuiWindow* window = ImGui::GetCurrentWindow(); + ImVec2 pos = window->DC.CursorPos; + ImGui::GetWindowDrawList()->AddRectFilled(pos + ImVec2(0,2), pos + size - ImVec2(0,2), col); + ImGui::Dummy(size); +} + +void ColormapIcon(ImPlotColormap cmap) { + ImPlotContext& gp = *GImPlot; + const float txt_size = ImGui::GetTextLineHeight(); + ImVec2 size(txt_size-4,txt_size); + ImGuiWindow* window = ImGui::GetCurrentWindow(); + ImVec2 pos = window->DC.CursorPos; + ImRect rect(pos+ImVec2(0,2),pos+size-ImVec2(0,2)); + ImDrawList& DrawList = *ImGui::GetWindowDrawList(); + RenderColorBar(gp.ColormapData.GetKeys(cmap),gp.ColormapData.GetKeyCount(cmap),DrawList,rect,false,false,!gp.ColormapData.IsQual(cmap)); + ImGui::Dummy(size); +} + +ImDrawList* GetPlotDrawList() { + return ImGui::GetWindowDrawList(); +} + +void PushPlotClipRect(float expand) { + ImPlotContext& gp = *GImPlot; + IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "PushPlotClipRect() needs to be called between BeginPlot() and EndPlot()!"); + SetupLock(); + ImRect rect = gp.CurrentPlot->PlotRect; + rect.Expand(expand); + ImGui::PushClipRect(rect.Min, rect.Max, true); +} + +void PopPlotClipRect() { + SetupLock(); + ImGui::PopClipRect(); +} + static void HelpMarker(const char* desc) { ImGui::TextDisabled("(?)"); if (ImGui::IsItemHovered()) { @@ -4140,6 +4624,21 @@ bool ShowColormapSelector(const char* label) { return set; } +bool ShowInputMapSelector(const char* label) { + static int map_idx = -1; + if (ImGui::Combo(label, &map_idx, "Default\0Reversed\0")) + { + switch (map_idx) + { + case 0: MapInputDefault(); break; + case 1: MapInputReverse(); break; + } + return true; + } + return false; +} + + void ShowStyleEditor(ImPlotStyle* ref) { ImPlotContext& gp = *GImPlot; ImPlotStyle& style = GetStyle(); @@ -4414,24 +4913,43 @@ void ShowUserGuide() { ImGui::BulletText("Click legend label icons to show/hide plot items."); } -void ShowAxisMetrics(ImPlotAxis* axis) { - ImGui::Bullet(); ImGui::Text("Flags: %d", axis->Flags); - ImGui::Bullet(); ImGui::Text("Range: [%f,%f]",axis->Range.Min, axis->Range.Max); - ImGui::Bullet(); ImGui::Text("Pixels: %f", axis->Pixels); - ImGui::Bullet(); ImGui::Text("Aspect: %f", axis->GetAspect()); - ImGui::Bullet(); ImGui::Text("Dragging: %s", axis->Dragging ? "true" : "false"); - ImGui::Bullet(); ImGui::Text("ExtHovered: %s", axis->ExtHovered ? "true" : "false"); - ImGui::Bullet(); ImGui::Text("AllHovered: %s", axis->AllHovered ? "true" : "false"); - ImGui::Bullet(); ImGui::Text("Present: %s", axis->Present ? "true" : "false"); - ImGui::Bullet(); ImGui::Text("HasRange: %s", axis->HasRange ? "true" : "false"); - ImGui::Bullet(); ImGui::Text("LinkedMin: %p", (void*)axis->LinkedMin); - ImGui::Bullet(); ImGui::Text("LinkedMax: %p", (void*)axis->LinkedMax); +void ShowTicksMetrics(const ImPlotTickCollection& ticks) { + ImGui::BulletText("Size: %d", ticks.Size); + ImGui::BulletText("MaxSize: [%f,%f]", ticks.MaxSize.x, ticks.MaxSize.y); +} + +void ShowAxisMetrics(const ImPlotPlot& plot, const ImPlotAxis& axis) { + ImGui::BulletText("Label: %s", axis.LabelOffset == -1 ? "[none]" : plot.GetAxisLabel(axis)); + ImGui::BulletText("Flags: 0x%08X", axis.Flags); + ImGui::BulletText("Range: [%f,%f]",axis.Range.Min, axis.Range.Max); + ImGui::BulletText("Pixels: %f", axis.PixelSize()); + ImGui::BulletText("Aspect: %f", axis.GetAspect()); + ImGui::BulletText(axis.OrthoAxis == NULL ? "OrtherAxis: NULL" : "OrthoAxis: 0x%08X", axis.OrthoAxis->ID); + ImGui::BulletText("LinkedMin: %p", (void*)axis.LinkedMin); + ImGui::BulletText("LinkedMax: %p", (void*)axis.LinkedMax); + ImGui::BulletText("HasRange: %s", axis.HasRange ? "true" : "false"); + ImGui::BulletText("Hovered: %s", axis.Hovered ? "true" : "false"); + ImGui::BulletText("Held: %s", axis.Held ? "true" : "false"); + + if (ImGui::TreeNode("Transform")) { + ImGui::BulletText("PixelMin: %f", axis.PixelMin); + ImGui::BulletText("PixelMax: %f", axis.PixelMax); + ImGui::BulletText("LinM: %f", axis.LinM); + ImGui::BulletText("LogD: %f", axis.LogD); + ImGui::TreePop(); + } + + if (ImGui::TreeNode("Ticks")) { + ShowTicksMetrics(axis.Ticks); + ImGui::TreePop(); + } } void ShowMetricsWindow(bool* p_popen) { static bool show_plot_rects = false; static bool show_axes_rects = false; + static bool show_axis_rects = false; static bool show_canvas_rects = false; static bool show_frame_rects = false; static bool show_subplot_frame_rects = false; @@ -4445,6 +4963,7 @@ void ShowMetricsWindow(bool* p_popen) { ImGui::Begin("ImPlot Metrics", p_popen); ImGui::Text("ImPlot " IMPLOT_VERSION); ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate); + ImGui::Text("Mouse Position: [%.0f,%.0f]", io.MousePos.x, io.MousePos.y); ImGui::Separator(); if (ImGui::TreeNode("Tools")) { if (ImGui::Button("Bust Plot Cache")) @@ -4456,9 +4975,9 @@ void ShowMetricsWindow(bool* p_popen) { ImGui::Checkbox("Show Canvas Rects",&show_canvas_rects); ImGui::Checkbox("Show Plot Rects", &show_plot_rects); ImGui::Checkbox("Show Axes Rects", &show_axes_rects); + ImGui::Checkbox("Show Axis Rects", &show_axis_rects); ImGui::Checkbox("Show Subplot Frame Rects", &show_subplot_frame_rects); ImGui::Checkbox("Show Subplot Grid Rects", &show_subplot_grid_rects); - ImGui::TreePop(); } const int n_plots = gp.Plots.GetBufSize(); @@ -4472,13 +4991,13 @@ void ShowMetricsWindow(bool* p_popen) { fg.AddRect(plot->CanvasRect.Min, plot->CanvasRect.Max, IM_COL32(0,255,255,255)); if (show_plot_rects) fg.AddRect(plot->PlotRect.Min, plot->PlotRect.Max, IM_COL32(255,255,0,255)); - if (show_axes_rects) { - fg.AddRect(plot->XAxis.HoverRect.Min, plot->XAxis.HoverRect.Max, IM_COL32(0,255,0,255)); - fg.AddRect(plot->YAxis[0].HoverRect.Min, plot->YAxis[0].HoverRect.Max, IM_COL32(0,255,0,255)); - if (ImHasFlag(plot->Flags, ImPlotFlags_YAxis2)) - fg.AddRect(plot->YAxis[1].HoverRect.Min, plot->YAxis[1].HoverRect.Max, IM_COL32(0,255,0,255)); - if (ImHasFlag(plot->Flags, ImPlotFlags_YAxis3)) - fg.AddRect(plot->YAxis[2].HoverRect.Min, plot->YAxis[2].HoverRect.Max, IM_COL32(0,255,0,255)); + if (show_axes_rects) + fg.AddRect(plot->AxesRect.Min, plot->AxesRect.Max, IM_COL32(0,255,128,255)); + if (show_axis_rects) { + for (int i = 0; i < ImAxis_COUNT; ++i) { + if (plot->Axes[i].Enabled) + fg.AddRect(plot->Axes[i].HoverRect.Min, plot->Axes[i].HoverRect.Max, IM_COL32(0,255,0,255)); + } } } for (int p = 0; p < n_subplots; ++p) { @@ -4491,55 +5010,54 @@ void ShowMetricsWindow(bool* p_popen) { if (ImGui::TreeNode("Plots","Plots (%d)", n_plots)) { for (int p = 0; p < n_plots; ++p) { // plot - ImPlotPlot* plot = gp.Plots.GetByIndex(p); + ImPlotPlot& plot = *gp.Plots.GetByIndex(p); ImGui::PushID(p); - if (ImGui::TreeNode("Plot", "Plot [ID=0x%08X]", plot->ID)) { - int n_items = plot->Items.GetItemCount(); + if (ImGui::TreeNode("Plot", "Plot [0x%08X]", plot.ID)) { + int n_items = plot.Items.GetItemCount(); if (ImGui::TreeNode("Items", "Items (%d)", n_items)) { for (int i = 0; i < n_items; ++i) { - ImPlotItem* item = plot->Items.GetItemByIndex(i); + ImPlotItem* item = plot.Items.GetItemByIndex(i); ImGui::PushID(i); - if (ImGui::TreeNode("Item", "Item [ID=0x%08X]", item->ID)) { + if (ImGui::TreeNode("Item", "Item [0x%08X]", item->ID)) { ImGui::Bullet(); ImGui::Checkbox("Show", &item->Show); ImGui::Bullet(); ImVec4 temp = ImGui::ColorConvertU32ToFloat4(item->Color); if (ImGui::ColorEdit4("Color",&temp.x, ImGuiColorEditFlags_NoInputs)) item->Color = ImGui::ColorConvertFloat4ToU32(temp); - ImGui::Bullet(); ImGui::Text("NameOffset: %d",item->NameOffset); - ImGui::Bullet(); ImGui::Text("Name: %s", item->NameOffset != -1 ? plot->Items.Legend.Labels.Buf.Data + item->NameOffset : "N/A"); - ImGui::Bullet(); ImGui::Text("Hovered: %s",item->LegendHovered ? "true" : "false"); + ImGui::BulletText("NameOffset: %d",item->NameOffset); + ImGui::BulletText("Name: %s", item->NameOffset != -1 ? plot.Items.Legend.Labels.Buf.Data + item->NameOffset : "N/A"); + ImGui::BulletText("Hovered: %s",item->LegendHovered ? "true" : "false"); ImGui::TreePop(); } ImGui::PopID(); } ImGui::TreePop(); } - if (ImGui::TreeNode("X-Axis")) { - ShowAxisMetrics(&plot->XAxis); - ImGui::TreePop(); + char buff[16]; + for (int i = 0; i < IMPLOT_NUM_X_AXES; ++i) { + ImFormatString(buff,16,"X-Axis %d", i+1); + if (plot.XAxis(i).Enabled && ImGui::TreeNode(buff, "X-Axis %d [0x%08X]", i+1, plot.XAxis(i).ID)) { + ShowAxisMetrics(plot, plot.XAxis(i)); + ImGui::TreePop(); + } } - if (ImGui::TreeNode("Y-Axis")) { - ShowAxisMetrics(&plot->YAxis[0]); - ImGui::TreePop(); + for (int i = 0; i < IMPLOT_NUM_Y_AXES; ++i) { + ImFormatString(buff,16,"Y-Axis %d", i+1); + if (plot.YAxis(i).Enabled && ImGui::TreeNode(buff, "Y-Axis %d [0x%08X]", i+1, plot.YAxis(i).ID)) { + ShowAxisMetrics(plot, plot.YAxis(i)); + ImGui::TreePop(); + } } - if (ImHasFlag(plot->Flags, ImPlotFlags_YAxis2) && ImGui::TreeNode("Y-Axis 2")) { - ShowAxisMetrics(&plot->YAxis[1]); - ImGui::TreePop(); - } - if (ImHasFlag(plot->Flags, ImPlotFlags_YAxis3) && ImGui::TreeNode("Y-Axis 3")) { - ShowAxisMetrics(&plot->YAxis[2]); - ImGui::TreePop(); - } - ImGui::Bullet(); ImGui::Text("Flags: 0x%08X", plot->Flags); - ImGui::Bullet(); ImGui::Text("Initialized: %s", plot->Initialized ? "true" : "false"); - ImGui::Bullet(); ImGui::Text("Selecting: %s", plot->Selecting ? "true" : "false"); - ImGui::Bullet(); ImGui::Text("Selected: %s", plot->Selected ? "true" : "false"); - ImGui::Bullet(); ImGui::Text("Querying: %s", plot->Querying ? "true" : "false"); - ImGui::Bullet(); ImGui::Text("Queried: %s", plot->Queried ? "true" : "false"); - ImGui::Bullet(); ImGui::Text("FrameHovered: %s", plot->FrameHovered ? "true" : "false"); - ImGui::Bullet(); ImGui::Text("PlotHovered: %s", plot->PlotHovered ? "true" : "false"); - ImGui::Bullet(); ImGui::Text("LegendHovered: %s", plot->Items.Legend.Hovered ? "true" : "false"); + ImGui::BulletText("Title: %s", plot.HasTitle() ? plot.GetTitle() : "none"); + ImGui::BulletText("Flags: 0x%08X", plot.Flags); + ImGui::BulletText("Initialized: %s", plot.Initialized ? "true" : "false"); + ImGui::BulletText("Selecting: %s", plot.Selecting ? "true" : "false"); + ImGui::BulletText("Selected: %s", plot.Selected ? "true" : "false"); + ImGui::BulletText("Hovered: %s", plot.Hovered ? "true" : "false"); + ImGui::BulletText("Held: %s", plot.Held ? "true" : "false"); + ImGui::BulletText("LegendHovered: %s", plot.Items.Legend.Hovered ? "true" : "false"); + ImGui::BulletText("ContextLocked: %s", plot.ContextLocked ? "true" : "false"); ImGui::TreePop(); } ImGui::PopID(); @@ -4550,33 +5068,33 @@ void ShowMetricsWindow(bool* p_popen) { if (ImGui::TreeNode("Subplots","Subplots (%d)", n_subplots)) { for (int p = 0; p < n_subplots; ++p) { // plot - ImPlotSubplot* plot = gp.Subplots.GetByIndex(p); + ImPlotSubplot& plot = *gp.Subplots.GetByIndex(p); ImGui::PushID(p); - if (ImGui::TreeNode("Subplot", "Subplot [ID=0x%08X]", plot->ID)) { - int n_items = plot->Items.GetItemCount(); + if (ImGui::TreeNode("Subplot", "Subplot [0x%08X]", plot.ID)) { + int n_items = plot.Items.GetItemCount(); if (ImGui::TreeNode("Items", "Items (%d)", n_items)) { for (int i = 0; i < n_items; ++i) { - ImPlotItem* item = plot->Items.GetItemByIndex(i); + ImPlotItem* item = plot.Items.GetItemByIndex(i); ImGui::PushID(i); - if (ImGui::TreeNode("Item", "Item [ID=0x%08X]", item->ID)) { + if (ImGui::TreeNode("Item", "Item [0x%08X]", item->ID)) { ImGui::Bullet(); ImGui::Checkbox("Show", &item->Show); ImGui::Bullet(); ImVec4 temp = ImGui::ColorConvertU32ToFloat4(item->Color); if (ImGui::ColorEdit4("Color",&temp.x, ImGuiColorEditFlags_NoInputs)) item->Color = ImGui::ColorConvertFloat4ToU32(temp); - ImGui::Bullet(); ImGui::Text("NameOffset: %d",item->NameOffset); - ImGui::Bullet(); ImGui::Text("Name: %s", item->NameOffset != -1 ? plot->Items.Legend.Labels.Buf.Data + item->NameOffset : "N/A"); - ImGui::Bullet(); ImGui::Text("Hovered: %s",item->LegendHovered ? "true" : "false"); + ImGui::BulletText("NameOffset: %d",item->NameOffset); + ImGui::BulletText("Name: %s", item->NameOffset != -1 ? plot.Items.Legend.Labels.Buf.Data + item->NameOffset : "N/A"); + ImGui::BulletText("Hovered: %s",item->LegendHovered ? "true" : "false"); ImGui::TreePop(); } ImGui::PopID(); } ImGui::TreePop(); } - ImGui::Bullet(); ImGui::Text("Flags: 0x%08X", plot->Flags); - ImGui::Bullet(); ImGui::Text("FrameHovered: %s", plot->FrameHovered ? "true" : "false"); - ImGui::Bullet(); ImGui::Text("LegendHovered: %s", plot->Items.Legend.Hovered ? "true" : "false"); + ImGui::BulletText("Flags: 0x%08X", plot.Flags); + ImGui::BulletText("FrameHovered: %s", plot.FrameHovered ? "true" : "false"); + ImGui::BulletText("LegendHovered: %s", plot.Items.Legend.Hovered ? "true" : "false"); ImGui::TreePop(); } ImGui::PopID(); @@ -4682,7 +5200,7 @@ bool ShowDatePicker(const char* id, int* level, ImPlotTime* t, const ImPlotTime* GetTime(t_first_mo,&Tm); const int first_wd = Tm.tm_wday; // month year - snprintf(buff, 32, "%s %d", MONTH_NAMES[this_mon], this_year); + ImFormatString(buff, 32, "%s %d", MONTH_NAMES[this_mon], this_year); if (ImGui::Button(buff)) *level = 1; ImGui::SameLine(5*cell_size.x); @@ -4708,10 +5226,12 @@ bool ShowDatePicker(const char* id, int* level, ImPlotTime* t, const ImPlotTime* for (int i = 0; i < 6; ++i) { for (int j = 0; j < 7; ++j) { if (mo == 0 && day > days_last_mo) { - mo = 1; day = 1; + mo = 1; + day = 1; } else if (mo == 1 && day > days_this_mo) { - mo = 2; day = 1; + mo = 2; + day = 1; } const int now_yr = (mo == 0 && this_mon == 0) ? last_year : ((mo == 2 && this_mon == 11) ? next_year : this_year); const int now_mo = mo == 0 ? last_mon : (mo == 1 ? this_mon : next_mon); @@ -4728,7 +5248,7 @@ bool ShowDatePicker(const char* id, int* level, ImPlotTime* t, const ImPlotTime* ImGui::PushStyleColor(ImGuiCol_Text, col_txt); } ImGui::PushID(i*7+j); - snprintf(buff,32,"%d",day); + ImFormatString(buff,32,"%d",day); if (now_yr == min_yr-1 || now_yr == max_yr+1) { ImGui::Dummy(cell_size); } @@ -4752,7 +5272,7 @@ bool ShowDatePicker(const char* id, int* level, ImPlotTime* t, const ImPlotTime* *t = FloorTime(*t, ImPlotTimeUnit_Mo); GetTime(*t, &Tm); int this_yr = Tm.tm_year + 1900; - snprintf(buff, 32, "%d", this_yr); + ImFormatString(buff, 32, "%d", this_yr); if (ImGui::Button(buff)) *level = 2; BeginDisabledControls(this_yr <= min_yr); @@ -4792,7 +5312,7 @@ bool ShowDatePicker(const char* id, int* level, ImPlotTime* t, const ImPlotTime* int this_yr = GetYear(*t); int yr = this_yr - this_yr % 20; ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); - snprintf(buff,32,"%d-%d",yr,yr+19); + ImFormatString(buff,32,"%d-%d",yr,yr+19); ImGui::Button(buff); ImGui::PopItemFlag(); ImGui::SameLine(5*cell_size.x); @@ -4813,7 +5333,7 @@ bool ShowDatePicker(const char* id, int* level, ImPlotTime* t, const ImPlotTime* const bool t1_or_t2 = (t1 != NULL && t1_yr == yr) || (t2 != NULL && t2_yr == yr); if (t1_or_t2) ImGui::PushStyleColor(ImGuiCol_Button, col_btn); - snprintf(buff,32,"%d",yr); + ImFormatString(buff,32,"%d",yr); if (yr<1970||yr>3000) { ImGui::Dummy(cell_size); } @@ -4910,7 +5430,7 @@ bool ShowTimePicker(const char* id, ImPlotTime* t) { } if (!hour24) { ImGui::SameLine(); - if (ImGui::Button(am_pm[ap],ImVec2(height,height))) { + if (ImGui::Button(am_pm[ap],ImVec2(0,height))) { ap = 1 - ap; changed = true; } @@ -4952,16 +5472,13 @@ void StyleColorsAuto(ImPlotStyle* dst) { colors[ImPlotCol_TitleText] = IMPLOT_AUTO_COL; colors[ImPlotCol_InlayText] = IMPLOT_AUTO_COL; colors[ImPlotCol_PlotBorder] = IMPLOT_AUTO_COL; - colors[ImPlotCol_XAxis] = IMPLOT_AUTO_COL; - colors[ImPlotCol_XAxisGrid] = IMPLOT_AUTO_COL; - colors[ImPlotCol_YAxis] = IMPLOT_AUTO_COL; - colors[ImPlotCol_YAxisGrid] = IMPLOT_AUTO_COL; - colors[ImPlotCol_YAxis2] = IMPLOT_AUTO_COL; - colors[ImPlotCol_YAxisGrid2] = IMPLOT_AUTO_COL; - colors[ImPlotCol_YAxis3] = IMPLOT_AUTO_COL; - colors[ImPlotCol_YAxisGrid3] = IMPLOT_AUTO_COL; + colors[ImPlotCol_AxisText] = IMPLOT_AUTO_COL; + colors[ImPlotCol_AxisGrid] = IMPLOT_AUTO_COL; + colors[ImPlotCol_AxisTick] = IMPLOT_AUTO_COL; + colors[ImPlotCol_AxisBg] = IMPLOT_AUTO_COL; + colors[ImPlotCol_AxisBgHovered] = IMPLOT_AUTO_COL; + colors[ImPlotCol_AxisBgActive] = IMPLOT_AUTO_COL; colors[ImPlotCol_Selection] = IMPLOT_AUTO_COL; - colors[ImPlotCol_Query] = IMPLOT_AUTO_COL; colors[ImPlotCol_Crosshairs] = IMPLOT_AUTO_COL; } @@ -4984,16 +5501,13 @@ void StyleColorsClassic(ImPlotStyle* dst) { colors[ImPlotCol_LegendText] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); colors[ImPlotCol_TitleText] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); colors[ImPlotCol_InlayText] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); - colors[ImPlotCol_XAxis] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); - colors[ImPlotCol_XAxisGrid] = ImVec4(0.90f, 0.90f, 0.90f, 0.25f); - colors[ImPlotCol_YAxis] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); - colors[ImPlotCol_YAxisGrid] = ImVec4(0.90f, 0.90f, 0.90f, 0.25f); - colors[ImPlotCol_YAxis2] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); - colors[ImPlotCol_YAxisGrid2] = ImVec4(0.90f, 0.90f, 0.90f, 0.25f); - colors[ImPlotCol_YAxis3] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); - colors[ImPlotCol_YAxisGrid3] = ImVec4(0.90f, 0.90f, 0.90f, 0.25f); + colors[ImPlotCol_AxisText] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); + colors[ImPlotCol_AxisGrid] = ImVec4(0.90f, 0.90f, 0.90f, 0.25f); + colors[ImPlotCol_AxisTick] = IMPLOT_AUTO_COL; // TODO + colors[ImPlotCol_AxisBg] = IMPLOT_AUTO_COL; // TODO + colors[ImPlotCol_AxisBgHovered] = IMPLOT_AUTO_COL; // TODO + colors[ImPlotCol_AxisBgActive] = IMPLOT_AUTO_COL; // TODO colors[ImPlotCol_Selection] = ImVec4(0.97f, 0.97f, 0.39f, 1.00f); - colors[ImPlotCol_Query] = ImVec4(0.00f, 1.00f, 0.59f, 1.00f); colors[ImPlotCol_Crosshairs] = ImVec4(0.50f, 0.50f, 0.50f, 0.75f); } @@ -5016,16 +5530,13 @@ void StyleColorsDark(ImPlotStyle* dst) { colors[ImPlotCol_LegendText] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); colors[ImPlotCol_TitleText] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); colors[ImPlotCol_InlayText] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); - colors[ImPlotCol_XAxis] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); - colors[ImPlotCol_XAxisGrid] = ImVec4(1.00f, 1.00f, 1.00f, 0.25f); - colors[ImPlotCol_YAxis] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); - colors[ImPlotCol_YAxisGrid] = ImVec4(1.00f, 1.00f, 1.00f, 0.25f); - colors[ImPlotCol_YAxis2] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); - colors[ImPlotCol_YAxisGrid2] = ImVec4(1.00f, 1.00f, 1.00f, 0.25f); - colors[ImPlotCol_YAxis3] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); - colors[ImPlotCol_YAxisGrid3] = ImVec4(1.00f, 1.00f, 1.00f, 0.25f); + colors[ImPlotCol_AxisText] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); + colors[ImPlotCol_AxisGrid] = ImVec4(1.00f, 1.00f, 1.00f, 0.25f); + colors[ImPlotCol_AxisTick] = IMPLOT_AUTO_COL; // TODO + colors[ImPlotCol_AxisBg] = IMPLOT_AUTO_COL; // TODO + colors[ImPlotCol_AxisBgHovered] = IMPLOT_AUTO_COL; // TODO + colors[ImPlotCol_AxisBgActive] = IMPLOT_AUTO_COL; // TODO colors[ImPlotCol_Selection] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f); - colors[ImPlotCol_Query] = ImVec4(0.00f, 1.00f, 0.44f, 1.00f); colors[ImPlotCol_Crosshairs] = ImVec4(1.00f, 1.00f, 1.00f, 0.50f); } @@ -5048,17 +5559,37 @@ void StyleColorsLight(ImPlotStyle* dst) { colors[ImPlotCol_LegendText] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); colors[ImPlotCol_TitleText] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); colors[ImPlotCol_InlayText] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); - colors[ImPlotCol_XAxis] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); - colors[ImPlotCol_XAxisGrid] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); - colors[ImPlotCol_YAxis] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); - colors[ImPlotCol_YAxisGrid] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); - colors[ImPlotCol_YAxis2] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); - colors[ImPlotCol_YAxisGrid2] = ImVec4(0.00f, 0.00f, 0.00f, 0.50f); - colors[ImPlotCol_YAxis3] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); - colors[ImPlotCol_YAxisGrid3] = ImVec4(0.00f, 0.00f, 0.00f, 0.50f); + colors[ImPlotCol_AxisText] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); + colors[ImPlotCol_AxisGrid] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); + colors[ImPlotCol_AxisTick] = ImVec4(0.00f, 0.00f, 0.00f, 0.25f); + colors[ImPlotCol_AxisBg] = IMPLOT_AUTO_COL; // TODO + colors[ImPlotCol_AxisBgHovered] = IMPLOT_AUTO_COL; // TODO + colors[ImPlotCol_AxisBgActive] = IMPLOT_AUTO_COL; // TODO colors[ImPlotCol_Selection] = ImVec4(0.82f, 0.64f, 0.03f, 1.00f); - colors[ImPlotCol_Query] = ImVec4(0.00f, 0.84f, 0.37f, 1.00f); colors[ImPlotCol_Crosshairs] = ImVec4(0.00f, 0.00f, 0.00f, 0.50f); } +//----------------------------------------------------------------------------- +// [SECTION] Obsolete Functions/Types +//----------------------------------------------------------------------------- + +#ifndef IMPLOT_DISABLE_OBSOLETE_FUNCTIONS + +bool BeginPlot(const char* title, const char* x_label, const char* y1_label, const ImVec2& size, + ImPlotFlags flags, ImPlotAxisFlags x_flags, ImPlotAxisFlags y1_flags, ImPlotAxisFlags y2_flags, ImPlotAxisFlags y3_flags, + const char* y2_label, const char* y3_label) +{ + if (!BeginPlot(title, size, flags)) + return false; + SetupAxis(ImAxis_X1, x_label, x_flags); + SetupAxis(ImAxis_Y1, y1_label, y1_flags); + if (ImHasFlag(flags, ImPlotFlags_YAxis2)) + SetupAxis(ImAxis_Y2, y2_label, y2_flags); + if (ImHasFlag(flags, ImPlotFlags_YAxis3)) + SetupAxis(ImAxis_Y3, y3_label, y3_flags); + return true; +} + +#endif + } // namespace ImPlot diff --git a/lib/external/imgui/source/implot_demo.cpp b/lib/external/imgui/source/implot_demo.cpp index a1ef3e2c7..e5f7a8892 100644 --- a/lib/external/imgui/source/implot_demo.cpp +++ b/lib/external/imgui/source/implot_demo.cpp @@ -20,7 +20,10 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -// ImPlot v0.11 WIP +// ImPlot v0.13 WIP + +// We define this so that the demo does not accidentally use deprecated API +#define IMPLOT_DISABLE_OBSOLETE_FUNCTIONS #include "implot.h" #include @@ -175,7 +178,7 @@ struct HugeTimeData { }; //----------------------------------------------------------------------------- -// DEMOS +// [SECTION] Demo Functions //----------------------------------------------------------------------------- void ShowDemo_Help() { @@ -210,19 +213,79 @@ void ShowDemo_Help() { //----------------------------------------------------------------------------- -void ShowDemo_Configuration() { +void ButtonSelector(const char* label, ImGuiMouseButton* b) { + ImGui::PushID(label); + if (ImGui::RadioButton("LMB",*b == ImGuiMouseButton_Left)) + *b = ImGuiMouseButton_Left; + ImGui::SameLine(); + if (ImGui::RadioButton("RMB",*b == ImGuiMouseButton_Right)) + *b = ImGuiMouseButton_Right; + ImGui::SameLine(); + if (ImGui::RadioButton("MMB",*b == ImGuiMouseButton_Middle)) + *b = ImGuiMouseButton_Middle; + ImGui::PopID(); +} + +void ModSelector(const char* label, ImGuiModFlags* k) { + ImGui::PushID(label); + ImGui::CheckboxFlags("Ctrl", (unsigned int*)k, ImGuiModFlags_Ctrl); ImGui::SameLine(); + ImGui::CheckboxFlags("Shift", (unsigned int*)k, ImGuiModFlags_Shift); ImGui::SameLine(); + ImGui::CheckboxFlags("Alt", (unsigned int*)k, ImGuiModFlags_Alt); ImGui::SameLine(); + ImGui::CheckboxFlags("Super", (unsigned int*)k, ImGuiModFlags_Super); + ImGui::PopID(); +} + +void InputMapping(const char* label, ImGuiMouseButton* b, ImGuiModFlags* k) { + ImGui::LabelText("##","%s",label); + if (b != NULL) { + ImGui::SameLine(100); + ButtonSelector(label,b); + } + if (k != NULL) { + ImGui::SameLine(300); + ModSelector(label,k); + } +} + +void ShowInputMapping() { + ImPlotInputMap& map = ImPlot::GetInputMap(); + InputMapping("Pan",&map.Pan,&map.PanMod); + InputMapping("Fit",&map.Fit,NULL); + InputMapping("Select",&map.Select,&map.SelectMod); + InputMapping("SelectHorzMod",NULL,&map.SelectHorzMod); + InputMapping("SelectVertMod",NULL,&map.SelectVertMod); + InputMapping("SelectCancel",&map.SelectCancel,NULL); + InputMapping("Menu",&map.Menu,NULL); + InputMapping("OverrideMod",NULL,&map.OverrideMod); + InputMapping("ZoomMod",NULL,&map.ZoomMod); + ImGui::SliderFloat("ZoomRate",&map.ZoomRate,-1,1); +} + +void ShowDemo_Config() { ImGui::ShowFontSelector("Font"); ImGui::ShowStyleSelector("ImGui Style"); ImPlot::ShowStyleSelector("ImPlot Style"); ImPlot::ShowColormapSelector("ImPlot Colormap"); - float indent = ImGui::CalcItemWidth() - ImGui::GetFrameHeight(); + ImPlot::ShowInputMapSelector("Input Map"); ImGui::Separator(); ImGui::Checkbox("Anti-Aliased Lines", &ImPlot::GetStyle().AntiAliasedLines); - ImGui::Separator(); ImGui::Checkbox("Use Local Time", &ImPlot::GetStyle().UseLocalTime); ImGui::Checkbox("Use ISO 8601", &ImPlot::GetStyle().UseISO8601); ImGui::Checkbox("Use 24 Hour Clock", &ImPlot::GetStyle().Use24HourClock); - ImGui::Unindent(indent); + ImGui::Separator(); + if (ImPlot::BeginPlot("Preview")) { + static double now = (double)time(0); + ImPlot::SetupAxis(ImAxis_X1,NULL,ImPlotAxisFlags_Time); + ImPlot::SetupAxisLimits(ImAxis_X1, now, now + 24*3600); + for (int i = 0; i < 10; ++i) { + double x[2] = {now, now + 24*3600}; + double y[2] = {0,i/9.0}; + ImGui::PushID(i); + ImPlot::PlotLine("##Line",x,y,2); + ImGui::PopID(); + } + ImPlot::EndPlot(); + } } //----------------------------------------------------------------------------- @@ -239,7 +302,8 @@ void ShowDemo_LinePlots() { ys2[i] = xs2[i] * xs2[i]; } ImGui::BulletText("Anti-aliasing can be enabled from the plot's context menu (see Help)."); - if (ImPlot::BeginPlot("Line Plot", "x", "f(x)")) { + if (ImPlot::BeginPlot("Line Plot")) { + ImPlot::SetupAxes("x","f(x)"); ImPlot::PlotLine("sin(x)", xs1, ys1, 1001); ImPlot::SetNextMarkerStyle(ImPlotMarker_Circle); ImPlot::PlotLine("x^2", xs2, ys2, 11); @@ -281,8 +345,9 @@ void ShowDemo_FilledLinePlots() { } } - ImPlot::SetNextPlotLimits(0,100,0,500); - if (ImPlot::BeginPlot("Stock Prices", "Days", "Price")) { + if (ImPlot::BeginPlot("Stock Prices")) { + ImPlot::SetupAxes("Days","Price"); + ImPlot::SetupAxesLimits(0,100,0,500); if (show_fills) { ImPlot::PushStyleVar(ImPlotStyleVar_FillAlpha, 0.25f); ImPlot::PlotShaded("Stock 1", xs1, ys1, 101, shade_mode == 0 ? -INFINITY : shade_mode == 1 ? INFINITY : fill_ref); @@ -315,7 +380,7 @@ void ShowDemo_ShadedPlots() { static float alpha = 0.25f; ImGui::DragFloat("Alpha",&alpha,0.01f,0,1); - if (ImPlot::BeginPlot("Shaded Plots", "X-Axis", "Y-Axis")) { + if (ImPlot::BeginPlot("Shaded Plots")) { ImPlot::PushStyleVar(ImPlotStyleVar_FillAlpha, alpha); ImPlot::PlotShaded("Uncertain Data",xs,ys1,ys2,1001); ImPlot::PlotLine("Uncertain Data", xs, ys, 1001); @@ -342,10 +407,10 @@ void ShowDemo_ScatterPlots() { ys2[i] = 0.75f + 0.2f * ((float)rand() / (float)RAND_MAX); } - if (ImPlot::BeginPlot("Scatter Plot", NULL, NULL)) { + if (ImPlot::BeginPlot("Scatter Plot")) { ImPlot::PlotScatter("Data 1", xs1, ys1, 100); ImPlot::PushStyleVar(ImPlotStyleVar_FillAlpha, 0.25f); - ImPlot::SetNextMarkerStyle(ImPlotMarker_Square, 6, ImVec4(0,1,0,0.5f), IMPLOT_AUTO, ImVec4(0,1,0,1)); + ImPlot::SetNextMarkerStyle(ImPlotMarker_Square, 6, ImPlot::GetColormapColor(1), IMPLOT_AUTO, ImPlot::GetColormapColor(1)); ImPlot::PlotScatter("Data 2", xs2, ys2, 50); ImPlot::PopStyleVar(); ImPlot::EndPlot(); @@ -360,7 +425,8 @@ void ShowDemo_StairstepPlots() { ys1[i] = 0.5f + 0.4f * sinf(50 * i * 0.01f); ys2[i] = 0.5f + 0.2f * sinf(25 * i * 0.01f); } - if (ImPlot::BeginPlot("Stairstep Plot", "x", "f(x)")) { + if (ImPlot::BeginPlot("Stairstep Plot")) { + ImPlot::SetupAxes("x","f(x)"); ImPlot::PlotStairs("Signal 1", ys1, 101, 0.01f); ImPlot::SetNextMarkerStyle(ImPlotMarker_Square, 2.0f); ImPlot::PlotStairs("Signal 2", ys2, 101, 0.01f); @@ -371,43 +437,99 @@ void ShowDemo_StairstepPlots() { //----------------------------------------------------------------------------- void ShowDemo_BarPlots() { - static bool horz = false; - static ImS8 midtm[10] = {83, 67, 23, 89, 83, 78, 91, 82, 85, 90}; - static ImS16 final[10] = {80, 62, 56, 99, 55, 78, 88, 78, 90, 100}; - static ImS32 grade[10] = {80, 69, 52, 92, 72, 78, 75, 76, 89, 95}; + static ImS8 data[10] = {1,2,3,4,5,6,7,8,9,10}; + if (ImPlot::BeginPlot("Bar Plot")) { + ImPlot::PlotBars("Bars",data,10,0.7,1); + ImPlot::PlotBarsH("BarsH",data,10,0.4,1); + ImPlot::EndPlot(); + } +} - static const char* labels[] = {"S1","S2","S3","S4","S5","S6","S7","S8","S9","S10"}; +void ShowDemo_BarGroups() { + static ImS8 data[30] = {83, 67, 23, 89, 83, 78, 91, 82, 85, 90, // midterm + 80, 62, 56, 99, 55, 78, 88, 78, 90, 100, // final + 80, 69, 52, 92, 72, 78, 75, 76, 89, 95}; // course + + static const char* ilabels[] = {"Midterm Exam","Final Exam","Course Grade"}; + static const char* glabels[] = {"S1","S2","S3","S4","S5","S6","S7","S8","S9","S10"}; static const double positions[] = {0,1,2,3,4,5,6,7,8,9}; + static int items = 3; + static int groups = 10; + static float size = 0.67f; + + static ImPlotBarGroupsFlags flags = 0; + static bool horz = false; + + ImGui::CheckboxFlags("Stacked", (unsigned int*)&flags, ImPlotBarGroupsFlags_Stacked); + ImGui::SameLine(); ImGui::Checkbox("Horizontal",&horz); - if (horz) { - ImPlot::SetNextPlotLimits(0, 110, -0.5, 9.5, ImGuiCond_Always); - ImPlot::SetNextPlotTicksY(positions, 10, labels); - } - else { - ImPlot::SetNextPlotLimits(-0.5, 9.5, 0, 110, ImGuiCond_Always); - ImPlot::SetNextPlotTicksX(positions, 10, labels); - } - if (ImPlot::BeginPlot("Bar Plot", horz ? "Score" : "Student", horz ? "Student" : "Score", - ImVec2(-1,0), 0, 0, horz ? ImPlotAxisFlags_Invert : 0)) - { + ImGui::SliderInt("Items",&items,1,3); + ImGui::SliderFloat("Size",&size,0,1); + + if (ImPlot::BeginPlot("Bar Group")) { + ImPlot::SetupLegend(ImPlotLocation_East, ImPlotLegendFlags_Outside); if (horz) { - ImPlot::SetLegendLocation(ImPlotLocation_West, ImPlotOrientation_Vertical); - ImPlot::PlotBarsH("Midterm Exam", midtm, 10, 0.2, -0.2); - ImPlot::PlotBarsH("Final Exam", final, 10, 0.2, 0); - ImPlot::PlotBarsH("Course Grade", grade, 10, 0.2, 0.2); + ImPlot::SetupAxes("Score","Student",ImPlotAxisFlags_AutoFit,ImPlotAxisFlags_AutoFit); + ImPlot::SetupAxisTicks(ImAxis_Y1,positions, groups, glabels); + ImPlot::PlotBarGroupsH(ilabels,data,items,groups,size,0,flags); } else { - ImPlot::SetLegendLocation(ImPlotLocation_South, ImPlotOrientation_Horizontal); - ImPlot::PlotBars("Midterm Exam", midtm, 10, 0.2, -0.2); - ImPlot::PlotBars("Final Exam", final, 10, 0.2, 0); - ImPlot::PlotBars("Course Grade", grade, 10, 0.2, 0.2); + ImPlot::SetupAxes("Student","Score",ImPlotAxisFlags_AutoFit,ImPlotAxisFlags_AutoFit); + ImPlot::SetupAxisTicks(ImAxis_X1,positions, groups, glabels); + ImPlot::PlotBarGroups(ilabels,data,items,groups,size,0,flags); } ImPlot::EndPlot(); } } +void ShowDemo_BarStacks() { + + static ImPlotColormap Liars = -1; + if (Liars == -1) { + static const ImU32 Liars_Data[6] = { 4282515870, 4282609140, 4287357182, 4294630301, 4294945280, 4294921472 }; + Liars = ImPlot::AddColormap("Liars", Liars_Data, 6); + } + + static bool diverging = true; + ImGui::Checkbox("Diverging",&diverging); + + static const char* politicians[] = {"Trump","Bachman","Cruz","Gingrich","Palin","Santorum","Walker","Perry","Ryan","McCain","Rubio","Romney","Rand Paul","Christie","Biden","Kasich","Sanders","J Bush","H Clinton","Obama"}; + static int data_reg[] = {18,26,7,14,10,8,6,11,4,4,3,8,6,8,6,5,0,3,1,2, // Pants on Fire + 43,36,30,21,30,27,25,17,11,22,15,16,16,17,12,12,14,6,13,12, // False + 16,13,28,22,15,21,15,18,30,17,24,18,13,10,14,15,17,22,14,12, // Mostly False + 17,10,13,25,12,22,19,26,23,17,22,27,20,26,29,17,18,22,21,27, // Half True + 5,7,16,10,10,12,23,13,17,20,22,16,23,19,20,26,36,29,27,26, // Mostly True + 1,8,6,8,23,10,12,15,15,20,14,15,22,20,19,25,15,18,24,21}; // True + static const char* labels_reg[] = {"Pants on Fire","False","Mostly False","Half True","Mostly True","True"}; + + + static int data_div[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // Pants on Fire (dummy, to order legend logically) + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // False (dummy, to order legend logically) + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // Mostly False (dummy, to order legend logically) + -16,-13,-28,-22,-15,-21,-15,-18,-30,-17,-24,-18,-13,-10,-14,-15,-17,-22,-14,-12, // Mostly False + -43,-36,-30,-21,-30,-27,-25,-17,-11,-22,-15,-16,-16,-17,-12,-12,-14,-6,-13,-12, // False + -18,-26,-7,-14,-10,-8,-6,-11,-4,-4,-3,-8,-6,-8,-6,-5,0,-3,-1,-2, // Pants on Fire + 17,10,13,25,12,22,19,26,23,17,22,27,20,26,29,17,18,22,21,27, // Half True + 5,7,16,10,10,12,23,13,17,20,22,16,23,19,20,26,36,29,27,26, // Mostly True + 1,8,6,8,23,10,12,15,15,20,14,15,22,20,19,25,15,18,24,21}; // True + static const char* labels_div[] = {"Pants on Fire","False","Mostly False","Mostly False","False","Pants on Fire","Half True","Mostly True","True"}; + + ImPlot::PushColormap(Liars); + if (ImPlot::BeginPlot("PolitiFact: Who Lies More?",ImVec2(-1,400),ImPlotFlags_NoMouseText)) { + ImPlot::SetupLegend(ImPlotLocation_South, ImPlotLegendFlags_Outside|ImPlotLegendFlags_Horizontal); + ImPlot::SetupAxes(NULL,NULL,ImPlotAxisFlags_AutoFit|ImPlotAxisFlags_NoDecorations,ImPlotAxisFlags_AutoFit|ImPlotAxisFlags_Invert); + ImPlot::SetupAxisTicks(ImAxis_Y1,0,19,20,politicians,false); + if (diverging) + ImPlot::PlotBarGroupsH(labels_div,data_div,9,20,0.75,0,ImPlotBarGroupsFlags_Stacked); + else + ImPlot::PlotBarGroupsH(labels_reg,data_reg,6,20,0.75,0,ImPlotBarGroupsFlags_Stacked); + ImPlot::EndPlot(); + } + ImPlot::PopColormap(); +} + //----------------------------------------------------------------------------- void ShowDemo_ErrorBars() { @@ -421,23 +543,19 @@ void ShowDemo_ErrorBars() { static float err4[5] = {0.02f, 0.08f, 0.15f, 0.05f, 0.2f}; - ImPlot::SetNextPlotLimits(0, 6, 0, 10); - if (ImPlot::BeginPlot("##ErrorBars",NULL,NULL)) { - + if (ImPlot::BeginPlot("##ErrorBars")) { + ImPlot::SetupAxesLimits(0, 6, 0, 10); ImPlot::PlotBars("Bar", xs, bar, 5, 0.5f); ImPlot::PlotErrorBars("Bar", xs, bar, err1, 5); - ImPlot::SetNextErrorBarStyle(ImPlot::GetColormapColor(1), 0); ImPlot::PlotErrorBars("Line", xs, lin1, err1, err2, 5); ImPlot::SetNextMarkerStyle(ImPlotMarker_Circle); ImPlot::PlotLine("Line", xs, lin1, 5); - ImPlot::PushStyleColor(ImPlotCol_ErrorBar, ImPlot::GetColormapColor(2)); ImPlot::PlotErrorBars("Scatter", xs, lin2, err2, 5); ImPlot::PlotErrorBarsH("Scatter", xs, lin2, err3, err4, 5); ImPlot::PopStyleColor(); ImPlot::PlotScatter("Scatter", xs, lin2, 5); - ImPlot::EndPlot(); } } @@ -449,11 +567,11 @@ void ShowDemo_StemPlots() { ys1[i] = 1.0 + 0.5 * sin(25*xs[i])*cos(2*xs[i]); ys2[i] = 0.5 + 0.25 * sin(10*xs[i]) * sin(xs[i]); } - ImPlot::SetNextPlotLimits(0,1,0,1.6); if (ImPlot::BeginPlot("Stem Plots")) { + ImPlot::SetupAxisLimits(ImAxis_X1,0,1.0); + ImPlot::SetupAxisLimits(ImAxis_Y1,0,1.6); ImPlot::PlotStems("Stems 1",xs,ys1,51); - ImPlot::SetNextLineStyle(ImVec4(1,0.5f,0,0.75f)); - ImPlot::SetNextMarkerStyle(ImPlotMarker_Square,5,ImVec4(1,0.5f,0,0.25f)); + ImPlot::SetNextMarkerStyle(ImPlotMarker_Square,5); ImPlot::PlotStems("Stems 2", xs, ys2,51); ImPlot::EndPlot(); } @@ -461,7 +579,8 @@ void ShowDemo_StemPlots() { void ShowDemo_InfiniteLines() { static double vals[] = {0.25, 0.5, 0.75}; - if (ImPlot::BeginPlot("##Infinite",0,0,ImVec2(-1,0),0,ImPlotAxisFlags_NoInitialFit,ImPlotAxisFlags_NoInitialFit)) { + if (ImPlot::BeginPlot("##Infinite")) { + ImPlot::SetupAxes(NULL,NULL,ImPlotAxisFlags_NoInitialFit,ImPlotAxisFlags_NoInitialFit); ImPlot::PlotVLines("VLines",vals,3); ImPlot::PlotHLines("HLines",vals,3); ImPlot::EndPlot(); @@ -479,8 +598,9 @@ void ShowDemo_PieCharts() { ImGui::Checkbox("Normalize", &normalize); } - ImPlot::SetNextPlotLimits(0,1,0,1,ImGuiCond_Always); - if (ImPlot::BeginPlot("##Pie1", NULL, NULL, ImVec2(250,250), ImPlotFlags_Equal | ImPlotFlags_NoMousePos, ImPlotAxisFlags_NoDecorations, ImPlotAxisFlags_NoDecorations)) { + if (ImPlot::BeginPlot("##Pie1", ImVec2(250,250), ImPlotFlags_Equal | ImPlotFlags_NoMouseText)) { + ImPlot::SetupAxes(NULL, NULL, ImPlotAxisFlags_NoDecorations, ImPlotAxisFlags_NoDecorations); + ImPlot::SetupAxesLimits(0, 1, 0, 1); ImPlot::PlotPieChart(labels1, data1, 4, 0.5, 0.5, 0.4, normalize, "%.2f"); ImPlot::EndPlot(); } @@ -491,8 +611,9 @@ void ShowDemo_PieCharts() { static int data2[] = {1,1,2,3,5}; ImPlot::PushColormap(ImPlotColormap_Pastel); - ImPlot::SetNextPlotLimits(0,1,0,1,ImGuiCond_Always); - if (ImPlot::BeginPlot("##Pie2", NULL, NULL, ImVec2(250,250), ImPlotFlags_Equal | ImPlotFlags_NoMousePos, ImPlotAxisFlags_NoDecorations, ImPlotAxisFlags_NoDecorations)) { + if (ImPlot::BeginPlot("##Pie2", ImVec2(250,250), ImPlotFlags_Equal | ImPlotFlags_NoMouseText)) { + ImPlot::SetupAxes(NULL, NULL, ImPlotAxisFlags_NoDecorations, ImPlotAxisFlags_NoDecorations); + ImPlot::SetupAxesLimits(0, 1, 0, 1); ImPlot::PlotPieChart(labels2, data2, 5, 0.5, 0.5, 0.4, true, "%.0f", 180); ImPlot::EndPlot(); } @@ -529,9 +650,11 @@ void ShowDemo_Heatmaps() { static ImPlotAxisFlags axes_flags = ImPlotAxisFlags_Lock | ImPlotAxisFlags_NoGridLines | ImPlotAxisFlags_NoTickMarks; ImPlot::PushColormap(map); - SetNextPlotTicksX(0 + 1.0/14.0, 1 - 1.0/14.0, 7, xlabels); - SetNextPlotTicksY(1 - 1.0/14.0, 0 + 1.0/14.0, 7, ylabels); - if (ImPlot::BeginPlot("##Heatmap1",NULL,NULL,ImVec2(225,225),ImPlotFlags_NoLegend|ImPlotFlags_NoMousePos,axes_flags,axes_flags)) { + + if (ImPlot::BeginPlot("##Heatmap1",ImVec2(225,225),ImPlotFlags_NoLegend|ImPlotFlags_NoMouseText)) { + ImPlot::SetupAxes(NULL, NULL, axes_flags, axes_flags); + ImPlot::SetupAxisTicks(ImAxis_X1,0 + 1.0/14.0, 1 - 1.0/14.0, 7, xlabels); + ImPlot::SetupAxisTicks(ImAxis_Y1,1 - 1.0/14.0, 0 + 1.0/14.0, 7, ylabels); ImPlot::PlotHeatmap("heat",values1[0],7,7,scale_min,scale_max); ImPlot::EndPlot(); } @@ -540,14 +663,15 @@ void ShowDemo_Heatmaps() { ImGui::SameLine(); - const int size = 200; + const int size = 80; static double values2[size*size]; srand((unsigned int)(ImGui::GetTime()*1000000)); for (int i = 0; i < size*size; ++i) values2[i] = RandomRange(0.0,1.0); - ImPlot::SetNextPlotLimits(-1,1,-1,1); - if (ImPlot::BeginPlot("##Heatmap2",NULL,NULL,ImVec2(225,225),0,ImPlotAxisFlags_NoDecorations,ImPlotAxisFlags_NoDecorations)) { + if (ImPlot::BeginPlot("##Heatmap2",ImVec2(225,225))) { + ImPlot::SetupAxes(NULL, NULL, ImPlotAxisFlags_NoDecorations, ImPlotAxisFlags_NoDecorations); + ImPlot::SetupAxesLimits(-1,1,-1,1); ImPlot::PlotHeatmap("heat1",values2,size,size,0,1,NULL); ImPlot::PlotHeatmap("heat2",values2,size,size,0,1,NULL, ImPlotPoint(-1,-1), ImPlotPoint(0,0)); ImPlot::EndPlot(); @@ -576,10 +700,16 @@ void ShowDemo_Histogram() { ImGui::SliderInt("##Bins", &bins, 1, 100); } if (ImGui::Checkbox("Density", &density)) - ImPlot::FitNextPlotAxes(); + { + ImPlot::SetNextAxisToFit(ImAxis_X1); + ImPlot::SetNextAxisToFit(ImAxis_Y1); + } ImGui::SameLine(); if (ImGui::Checkbox("Cumulative", &cumulative)) - ImPlot::FitNextPlotAxes(); + { + ImPlot::SetNextAxisToFit(ImAxis_X1); + ImPlot::SetNextAxisToFit(ImAxis_Y1); + } ImGui::SameLine(); static bool range = false; ImGui::Checkbox("Range", &range); @@ -619,21 +749,22 @@ void ShowDemo_Histogram() { } void ShowDemo_Histogram2D() { - static int count = 500000; - static int xybins[2] = {200,200}; + static int count = 50000; + static int xybins[2] = {100,100}; static bool density2 = false; - ImGui::SliderInt("Count",&count,100,500000); + ImGui::SliderInt("Count",&count,100,100000); ImGui::SliderInt2("Bins",xybins,1,500); ImGui::SameLine(); ImGui::Checkbox("Density##2",&density2); - static NormalDistribution<500000> dist1(1, 2); - static NormalDistribution<500000> dist2(1, 1); + static NormalDistribution<100000> dist1(1, 2); + static NormalDistribution<100000> dist2(1, 1); double max_count = 0; ImPlotAxisFlags flags = ImPlotAxisFlags_AutoFit|ImPlotAxisFlags_Foreground; ImPlot::PushColormap("Hot"); - ImPlot::SetNextPlotLimits(-6,6,-6,6); - if (ImPlot::BeginPlot("##Hist2D",0,0,ImVec2(ImGui::GetContentRegionAvail().x-100-ImGui::GetStyle().ItemSpacing.x,0),0,flags,flags)) { - max_count = ImPlot::PlotHistogram2D("Hist2D",dist1.Data,dist2.Data,count,xybins[0],xybins[1],density2,ImPlotLimits(-6,6,-6,6)); + if (ImPlot::BeginPlot("##Hist2D",ImVec2(ImGui::GetContentRegionAvail().x-100-ImGui::GetStyle().ItemSpacing.x,0))) { + ImPlot::SetupAxes(NULL, NULL, flags, flags); + ImPlot::SetupAxesLimits(-6,6,-6,6); + max_count = ImPlot::PlotHistogram2D("Hist2D",dist1.Data,dist2.Data,count,xybins[0],xybins[1],density2,ImPlotRect(-6,6,-6,6)); ImPlot::EndPlot(); } ImGui::SameLine(); @@ -673,9 +804,9 @@ void ShowDemo_DigitalPlots() { if (showAnalog[1]) dataAnalog[1].AddPoint(t, cosf(2*t)); } - ImPlot::SetNextPlotLimitsY(-1, 1); - ImPlot::SetNextPlotLimitsX(t - 10.0, t, paused ? ImGuiCond_Once : ImGuiCond_Always); if (ImPlot::BeginPlot("##Digital")) { + ImPlot::SetupAxisLimits(ImAxis_X1, t - 10.0, t, paused ? ImGuiCond_Once : ImGuiCond_Always); + ImPlot::SetupAxisLimits(ImAxis_Y1, -1, 1); for (int i = 0; i < 2; ++i) { if (showDigital[i] && dataDigital[i].Data.size() > 0) { sprintf(label, "digital_%d", i); @@ -732,17 +863,20 @@ void ShowDemo_RealtimePlots() { rdata2.Span = history; static ImPlotAxisFlags flags = ImPlotAxisFlags_NoTickLabels; - ImPlot::SetNextPlotLimitsX(t - history, t, ImGuiCond_Always); - ImPlot::SetNextPlotLimitsY(0,1); - if (ImPlot::BeginPlot("##Scrolling", NULL, NULL, ImVec2(-1,150), 0, flags, flags)) { + + if (ImPlot::BeginPlot("##Scrolling", ImVec2(-1,150))) { + ImPlot::SetupAxes(NULL, NULL, flags, flags); + ImPlot::SetupAxisLimits(ImAxis_X1,t - history, t, ImGuiCond_Always); + ImPlot::SetupAxisLimits(ImAxis_Y1,0,1); ImPlot::SetNextFillStyle(IMPLOT_AUTO_COL,0.5f); ImPlot::PlotShaded("Mouse X", &sdata1.Data[0].x, &sdata1.Data[0].y, sdata1.Data.size(), -INFINITY, sdata1.Offset, 2 * sizeof(float)); ImPlot::PlotLine("Mouse Y", &sdata2.Data[0].x, &sdata2.Data[0].y, sdata2.Data.size(), sdata2.Offset, 2*sizeof(float)); ImPlot::EndPlot(); } - ImPlot::SetNextPlotLimitsX(0, history, ImGuiCond_Always); - ImPlot::SetNextPlotLimitsY(0,1); - if (ImPlot::BeginPlot("##Rolling", NULL, NULL, ImVec2(-1,150), 0, flags, flags)) { + if (ImPlot::BeginPlot("##Rolling", ImVec2(-1,150))) { + ImPlot::SetupAxes(NULL, NULL, flags, flags); + ImPlot::SetupAxisLimits(ImAxis_X1,0,history, ImGuiCond_Always); + ImPlot::SetupAxisLimits(ImAxis_Y1,0,1); ImPlot::PlotLine("Mouse X", &rdata1.Data[0].x, &rdata1.Data[0].y, rdata1.Data.size(), 0, 2 * sizeof(float)); ImPlot::PlotLine("Mouse Y", &rdata2.Data[0].x, &rdata2.Data[0].y, rdata2.Data.size(), 0, 2 * sizeof(float)); ImPlot::EndPlot(); @@ -755,8 +889,11 @@ void ShowDemo_MarkersAndText() { ImGui::DragFloat("Marker Size",&mk_size,0.1f,2.0f,10.0f,"%.2f px"); ImGui::DragFloat("Marker Weight", &mk_weight,0.05f,0.5f,3.0f,"%.2f px"); - ImPlot::SetNextPlotLimits(0, 10, 0, 12); - if (ImPlot::BeginPlot("##MarkerStyles", NULL, NULL, ImVec2(-1,0), ImPlotFlags_CanvasOnly, ImPlotAxisFlags_NoDecorations, ImPlotAxisFlags_NoDecorations)) { + if (ImPlot::BeginPlot("##MarkerStyles", ImVec2(-1,0), ImPlotFlags_CanvasOnly)) { + + ImPlot::SetupAxes(NULL, NULL, ImPlotAxisFlags_NoDecorations, ImPlotAxisFlags_NoDecorations); + ImPlot::SetupAxesLimits(0, 10, 0, 12); + ImS8 xs[2] = {1,4}; ImS8 ys[2] = {10,11}; @@ -799,8 +936,9 @@ void ShowDemo_LogAxes() { } ImGui::BulletText("Open the plot context menu (right click) to change scales."); - ImPlot::SetNextPlotLimits(0.1, 100, 0, 10); - if (ImPlot::BeginPlot("Log Plot", NULL, NULL, ImVec2(-1,0), 0, ImPlotAxisFlags_LogScale )) { + if (ImPlot::BeginPlot("Log Plot", ImVec2(-1,0))) { + ImPlot::SetupAxis(ImAxis_X1, NULL, ImPlotAxisFlags_LogScale); + ImPlot::SetupAxesLimits(0.1, 100, 0, 10); ImPlot::PlotLine("f(x) = x", xs, xs, 1001); ImPlot::PlotLine("f(x) = sin(x)+1", xs, ys1, 1001); ImPlot::PlotLine("f(x) = log(x)", xs, ys2, 1001); @@ -833,8 +971,9 @@ void ShowDemo_TimeAxes() { } } - ImPlot::SetNextPlotLimits(t_min,t_max,0,1); - if (ImPlot::BeginPlot("##Time", NULL, NULL, ImVec2(-1,0), 0, ImPlotAxisFlags_Time)) { + if (ImPlot::BeginPlot("##Time", ImVec2(-1,0))) { + ImPlot::SetupAxis(ImAxis_X1, NULL, ImPlotAxisFlags_Time); + ImPlot::SetupAxesLimits(t_min,t_max,0,1); if (data != NULL) { // downsample our data int downsample = (int)ImPlot::GetPlotLimits().X.Size() / 1000 + 1; @@ -850,70 +989,87 @@ void ShowDemo_TimeAxes() { double t_now = (double)time(0); double y_now = HugeTimeData::GetY(t_now); ImPlot::PlotScatter("Now",&t_now,&y_now,1); - ImPlot::Annotate(t_now,y_now,ImVec2(10,10),ImPlot::GetLastItemColor(),"Now"); + ImPlot::Annotation(t_now,y_now,ImPlot::GetLastItemColor(),ImVec2(10,10),false,"Now"); ImPlot::EndPlot(); } } -void ShowDemo_MultipleYAxes() { +void ShowDemo_MultipleAxes() { static float xs[1001], xs2[1001], ys1[1001], ys2[1001], ys3[1001]; for (int i = 0; i < 1001; ++i) { xs[i] = (i*0.1f); + xs2[i] = xs[i] + 10.0f; ys1[i] = sinf(xs[i]) * 3 + 1; ys2[i] = cosf(xs[i]) * 0.2f + 0.5f; ys3[i] = sinf(xs[i]+0.5f) * 100 + 200; - xs2[i] = xs[i] + 10.0f; } + + static bool x2_axis = true; static bool y2_axis = true; static bool y3_axis = true; + + ImGui::Checkbox("X-Axis 2", &x2_axis); + ImGui::SameLine(); ImGui::Checkbox("Y-Axis 2", &y2_axis); ImGui::SameLine(); ImGui::Checkbox("Y-Axis 3", &y3_axis); - ImGui::SameLine(); - // you can fit axes programatically - ImGui::SameLine(); if (ImGui::Button("Fit X")) ImPlot::FitNextPlotAxes(true, false, false, false); - ImGui::SameLine(); if (ImGui::Button("Fit Y")) ImPlot::FitNextPlotAxes(false, true, false, false); - ImGui::SameLine(); if (ImGui::Button("Fit Y2")) ImPlot::FitNextPlotAxes(false, false, true, false); - ImGui::SameLine(); if (ImGui::Button("Fit Y3")) ImPlot::FitNextPlotAxes(false, false, false, true); + ImGui::BulletText("You can drag axes to the opposite side of the plot."); + ImGui::BulletText("Hover over legend items to see which axis they are plotted on."); - ImPlot::SetNextPlotLimits(0.1, 100, 0, 10); - ImPlot::SetNextPlotLimitsY(0, 1, ImGuiCond_Once, 1); - ImPlot::SetNextPlotLimitsY(0, 300, ImGuiCond_Once, 2); - if (ImPlot::BeginPlot("Multi-Axis Plot", NULL, "Y-Axis 1", ImVec2(-1,0), - (y2_axis ? ImPlotFlags_YAxis2 : 0) | - (y3_axis ? ImPlotFlags_YAxis3 : 0), - ImPlotAxisFlags_None, ImPlotAxisFlags_None, ImPlotAxisFlags_NoGridLines, ImPlotAxisFlags_NoGridLines, - "Y-Axis 2", "Y-Axis 3")) { - ImPlot::PlotLine("f(x) = x", xs, xs, 1001); - ImPlot::PlotLine("f(x) = sin(x)*3+1", xs, ys1, 1001); + if (ImPlot::BeginPlot("Multi-Axis Plot", ImVec2(-1,0))) { + ImPlot::SetupAxes("X-Axis 1", "Y-Axis 1"); + ImPlot::SetupAxesLimits(0, 100, 0, 10); + if (x2_axis) { + ImPlot::SetupAxis(ImAxis_X2, "X-Axis 2",ImPlotAxisFlags_AuxDefault); + ImPlot::SetupAxisLimits(ImAxis_X2, 0, 100); + } if (y2_axis) { - ImPlot::SetPlotYAxis(ImPlotYAxis_2); - ImPlot::PlotLine("f(x) = cos(x)*.2+.5 (Y2)", xs, ys2, 1001); + ImPlot::SetupAxis(ImAxis_Y2, "Y-Axis 2",ImPlotAxisFlags_AuxDefault); + ImPlot::SetupAxisLimits(ImAxis_Y2, 0, 1); } if (y3_axis) { - ImPlot::SetPlotYAxis(ImPlotYAxis_3); - ImPlot::PlotLine("f(x) = sin(x+.5)*100+200 (Y3)", xs2, ys3, 1001); + ImPlot::SetupAxis(ImAxis_Y3, "Y-Axis 3",ImPlotAxisFlags_AuxDefault); + ImPlot::SetupAxisLimits(ImAxis_Y3, 0, 300); + } + + ImPlot::PlotLine("f(x) = x", xs, xs, 1001); + if (x2_axis) { + ImPlot::SetAxes(ImAxis_X2, ImAxis_Y1); + ImPlot::PlotLine("f(x) = sin(x)*3+1", xs2, ys1, 1001); + } + if (y2_axis) { + ImPlot::SetAxes(ImAxis_X1, ImAxis_Y2); + ImPlot::PlotLine("f(x) = cos(x)*.2+.5", xs, ys2, 1001); + } + if (y3_axis) { + ImPlot::SetAxes(ImAxis_X2, ImAxis_Y3); + ImPlot::PlotLine("f(x) = sin(x+.5)*100+200 ", xs2, ys3, 1001); } ImPlot::EndPlot(); } } void ShowDemo_LinkedAxes() { - static double xmin = 0, xmax = 1, ymin = 0, ymax = 1; + static ImPlotRect lims(0,1,0,1); static bool linkx = true, linky = true; int data[2] = {0,1}; ImGui::Checkbox("Link X", &linkx); ImGui::SameLine(); ImGui::Checkbox("Link Y", &linky); + + ImGui::DragScalarN("Limits",ImGuiDataType_Double,&lims.X.Min,4,0.01f); + if (BeginAlignedPlots("AlignedGroup")) { - ImPlot::LinkNextPlotLimits(linkx ? &xmin : NULL , linkx ? &xmax : NULL, linky ? &ymin : NULL, linky ? &ymax : NULL); if (ImPlot::BeginPlot("Plot A")) { + ImPlot::SetupAxisLinks(ImAxis_X1, linkx ? &lims.X.Min : NULL, linkx ? &lims.X.Max : NULL); + ImPlot::SetupAxisLinks(ImAxis_Y1, linky ? &lims.Y.Min : NULL, linky ? &lims.Y.Max : NULL); ImPlot::PlotLine("Line",data,2); ImPlot::EndPlot(); } - ImPlot::LinkNextPlotLimits(linkx ? &xmin : NULL , linkx ? &xmax : NULL, linky ? &ymin : NULL, linky ? &ymax : NULL); if (ImPlot::BeginPlot("Plot B")) { + ImPlot::SetupAxisLinks(ImAxis_X1, linkx ? &lims.X.Min : NULL, linkx ? &lims.X.Max : NULL); + ImPlot::SetupAxisLinks(ImAxis_Y1, linky ? &lims.Y.Min : NULL, linky ? &lims.Y.Max : NULL); ImPlot::PlotLine("Line",data,2); ImPlot::EndPlot(); } @@ -922,13 +1078,20 @@ void ShowDemo_LinkedAxes() { } void ShowDemo_EqualAxes() { - static double xs[1000], ys[1000]; - for (int i = 0; i < 1000; ++i) { - double angle = i * 2 * PI / 999.0; - xs[i] = cos(angle); ys[i] = sin(angle); + ImGui::BulletText("Equal constraint applies to axis pairs (e.g ImAxis_X1/Y1, ImAxis_X2/Y2"); + static double xs1[360], ys1[360]; + for (int i = 0; i < 360; ++i) { + double angle = i * 2 * PI / 359.0; + xs1[i] = cos(angle); ys1[i] = sin(angle); } - if (ImPlot::BeginPlot("",0,0,ImVec2(-1,0),ImPlotFlags_Equal)) { - ImPlot::PlotLine("Circle",xs,ys,1000); + float xs2[] = {-1,0,1,0,-1}; + float ys2[] = {0,1,0,-1,0}; + if (ImPlot::BeginPlot("##EqualAxes",ImVec2(-1,0),ImPlotFlags_Equal)) { + ImPlot::SetupAxis(ImAxis_X2, NULL, ImPlotAxisFlags_AuxDefault); + ImPlot::SetupAxis(ImAxis_Y2, NULL, ImPlotAxisFlags_AuxDefault); + ImPlot::PlotLine("Circle",xs1,ys1,360); + ImPlot::SetAxes(ImAxis_X2, ImAxis_Y2); + ImPlot::PlotLine("Diamond",xs2,ys2,5); ImPlot::EndPlot(); } } @@ -954,7 +1117,8 @@ void ShowDemo_AutoFittingData() { for (int i = 0; i < 101; ++i) data[i] = 1 + sin(i/10.0f); - if (ImPlot::BeginPlot("##DataFitting","X","Y",ImVec2(-1,0),0,xflags,yflags)) { + if (ImPlot::BeginPlot("##DataFitting")) { + ImPlot::SetupAxes("X","Y",xflags,yflags); ImPlot::PlotLine("Line",data,101); ImPlot::PlotStems("Stems",data,101); ImPlot::EndPlot(); @@ -982,13 +1146,11 @@ void ShowDemo_SubplotsSizing() { ImGui::DragScalarN("Col Ratios",ImGuiDataType_Float,cratios,cols,0.01f,0); if (ImPlot::BeginSubplots("My Subplots", rows, cols, ImVec2(-1,400), flags, rratios, cratios)) { for (int i = 0; i < rows*cols; ++i) { - if (ImPlot::BeginPlot("",NULL,NULL,ImVec2(),ImPlotFlags_NoLegend,ImPlotAxisFlags_NoTickLabels,ImPlotAxisFlags_NoTickLabels)) { - char buffer[8]; + if (ImPlot::BeginPlot("",ImVec2(),ImPlotFlags_NoLegend)) { + ImPlot::SetupAxes(NULL,NULL,ImPlotAxisFlags_NoDecorations,ImPlotAxisFlags_NoDecorations); float fi = 0.01f * (i+1); - sprintf(buffer, "data%d", i); - if (i == 0) - ImPlot::SetNextLineStyle(ImVec4(0,1,0,1)); - ImPlot::PlotLineG(buffer,SinewaveGetter,&fi,1000); + ImPlot::SetNextLineStyle(SampleColormap((float)i/(float)(rows*cols-1),ImPlotColormap_Jet)); + ImPlot::PlotLineG("data",SinewaveGetter,&fi,1000); ImPlot::EndPlot(); } } @@ -1000,6 +1162,7 @@ void ShowDemo_SubplotItemSharing() { static ImPlotSubplotFlags flags = ImPlotSubplotFlags_ShareItems; ImGui::CheckboxFlags("ImPlotSubplotFlags_ShareItems", (unsigned int*)&flags, ImPlotSubplotFlags_ShareItems); ImGui::CheckboxFlags("ImPlotSubplotFlags_ColMajor", (unsigned int*)&flags, ImPlotSubplotFlags_ColMajor); + ImGui::BulletText("Drag and drop items from the legend onto plots (except for 'common')"); static int rows = 2; static int cols = 3; static int id[] = {0,1,2,3,4,5}; @@ -1024,8 +1187,8 @@ void ShowDemo_SubplotItemSharing() { } } } - if (ImPlot::BeginDragDropTarget()) { - if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("MY_DND")) + if (ImPlot::BeginDragDropTargetPlot()) { + if (ImGui::AcceptDragDropPayload("MY_DND")) id[curj] = i; ImPlot::EndDragDropTarget(); } @@ -1047,8 +1210,8 @@ void ShowDemo_SubplotAxisLinking() { static int cols = 2; if (ImPlot::BeginSubplots("##AxisLinking", rows, cols, ImVec2(-1,400), flags)) { for (int i = 0; i < rows*cols; ++i) { - ImPlot::SetNextPlotLimits(0,1000,-1,1); if (ImPlot::BeginPlot("")) { + ImPlot::SetupAxesLimits(0,1000,-1,1); float fc = 0.01f; ImPlot::PlotLineG("common",SinewaveGetter,&fc,1000); ImPlot::EndPlot(); @@ -1058,104 +1221,6 @@ void ShowDemo_SubplotAxisLinking() { } } -void ShowDemo_Querying() { - static ImVector data; - static ImPlotLimits range, query, select; - static bool init = true; - if (init) { - for (int i = 0; i < 50; ++i) - { - double x = RandomRange(0.0, 1.0); - double y = RandomRange(0.0, 1.0); - data.push_back(ImPlotPoint(x,y)); - } - init = false; - } - - ImGui::BulletText("Middle click (or Ctrl + right click) and drag to create a query rect."); - ImGui::Indent(); - ImGui::BulletText("Hold Alt to expand query horizontally."); - ImGui::BulletText("Hold Shift to expand query vertically."); - ImGui::BulletText("The query rect can be dragged after it's created."); - ImGui::Unindent(); - ImGui::BulletText("Ctrl + click in the plot area to draw points."); - - ImPlot::SetNextPlotLimits(0,1,0,1); - if (ImPlot::BeginPlot("##Centroid", NULL, NULL, ImVec2(-1,0), ImPlotFlags_Query)) { - if (ImPlot::IsPlotHovered() && ImGui::IsMouseClicked(0) && ImGui::GetIO().KeyCtrl) { - ImPlotPoint pt = ImPlot::GetPlotMousePos(); - data.push_back(pt); - } - if (data.size() > 0) - ImPlot::PlotScatter("Points", &data[0].x, &data[0].y, data.size(), 0, 2 * sizeof(double)); - if (ImPlot::IsPlotQueried() && data.size() > 0) { - ImPlotLimits range2 = ImPlot::GetPlotQuery(); - int cnt = 0; - ImPlotPoint avg; - for (int i = 0; i < data.size(); ++i) { - if (range2.Contains(data[i].x, data[i].y)) { - avg.x += data[i].x; - avg.y += data[i].y; - cnt++; - } - } - if (cnt > 0) { - avg.x = avg.x / cnt; - avg.y = avg.y / cnt; - ImPlot::SetNextMarkerStyle(ImPlotMarker_Square); - ImPlot::PlotScatter("Centroid", &avg.x, &avg.y, 1); - } - } - range = ImPlot::GetPlotLimits(); - query = ImPlot::GetPlotQuery(); - select = ImPlot::GetPlotSelection(); - ImPlot::EndPlot(); - } - ImGui::Text("Limits: [%g,%g,%g,%g]", range.X.Min, range.X.Max, range.Y.Min, range.Y.Max); - ImGui::Text("Query: [%g,%g,%g,%g]", query.X.Min, query.X.Max, query.Y.Min, query.Y.Max); - ImGui::Text("Selection: [%g,%g,%g,%g]", select.X.Min, select.X.Max, select.Y.Min, select.Y.Max); -} - -void ShowDemo_Views() { - static float x_data[512]; - static float y_data1[512]; - static float y_data2[512]; - static float y_data3[512]; - static float sampling_freq = 44100; - static float freq = 500; - for (size_t i = 0; i < 512; ++i) { - const float t = i / sampling_freq; - x_data[i] = t; - const float arg = 2 * 3.14f * freq * t; - y_data1[i] = sinf(arg); - y_data2[i] = y_data1[i] * -0.6f + sinf(2 * arg) * 0.4f; - y_data3[i] = y_data2[i] * -0.6f + sinf(3 * arg) * 0.4f; - } - ImGui::BulletText("Query the first plot to render a subview in the second plot (see above for controls)."); - ImPlotAxisFlags flags = ImPlotAxisFlags_NoTickLabels; - static bool use_selection = false; - ImGui::Checkbox("Use Box Selection",&use_selection); - bool is_viewed = false; - ImPlotLimits view; - ImPlot::SetNextPlotLimits(0,0.01,-1,1); - if (ImPlot::BeginPlot("##View1",NULL,NULL,ImVec2(-1,150), ImPlotFlags_Query, flags, flags)) { - ImPlot::PlotLine("Signal 1", x_data, y_data1, 512); - ImPlot::PlotLine("Signal 2", x_data, y_data2, 512); - ImPlot::PlotLine("Signal 3", x_data, y_data3, 512); - is_viewed = use_selection ? ImPlot::IsPlotSelected() : ImPlot::IsPlotQueried(); - view = use_selection ? ImPlot::GetPlotSelection() : ImPlot::GetPlotQuery(); - ImPlot::EndPlot(); - } - ImPlot::SetNextPlotLimits(view.X.Min, view.X.Max, view.Y.Min, view.Y.Max, ImGuiCond_Always); - if (ImPlot::BeginPlot("##View2",NULL,NULL,ImVec2(-1,150), ImPlotFlags_CanvasOnly, ImPlotAxisFlags_NoDecorations, ImPlotAxisFlags_NoDecorations)) { - if (is_viewed) { - ImPlot::PlotLine("Signal 1", x_data, y_data1, 512); - ImPlot::PlotLine("Signal 2", x_data, y_data2, 512); - ImPlot::PlotLine("Signal 3", x_data, y_data3, 512); - } - ImPlot::EndPlot(); - } -} void ShowDemo_LegendOptions() { static ImPlotLocation loc = ImPlotLocation_East; @@ -1171,8 +1236,11 @@ void ShowDemo_LegendOptions() { ImGui::SliderFloat2("LegendInnerPadding", (float*)&GetStyle().LegendInnerPadding, 0.0f, 10.0f, "%.0f"); ImGui::SliderFloat2("LegendSpacing", (float*)&GetStyle().LegendSpacing, 0.0f, 5.0f, "%.0f"); - if (ImPlot::BeginPlot("##Legend","x","y",ImVec2(-1,0))) { - ImPlot::SetLegendLocation(loc, h ? ImPlotOrientation_Horizontal : ImPlotOrientation_Vertical, o); + if (ImPlot::BeginPlot("##Legend",ImVec2(-1,0))) { + ImPlotLegendFlags flags = ImPlotLegendFlags_None; + if (h) flags |= ImPlotLegendFlags_Horizontal; + if (o) flags |= ImPlotLegendFlags_Outside; + ImPlot::SetupLegend(loc, flags); static MyImPlot::WaveData data1(0.001, 0.2, 2, 0.75); static MyImPlot::WaveData data2(0.001, 0.2, 4, 0.25); static MyImPlot::WaveData data3(0.001, 0.2, 6, 0.5); @@ -1185,41 +1253,23 @@ void ShowDemo_LegendOptions() { } } -void ShowDemo_DragLines() { - ImGui::BulletText("Click and drag the horizontal and vertical lines."); - static double x1 = 0.2; - static double x2 = 0.8; - static double y1 = 0.25; - static double y2 = 0.75; - static double f = 0.1; - static bool show_labels = true; - ImGui::Checkbox("Show Labels##1",&show_labels); - ImPlot::SetNextPlotLimits(0,1,0,1); - if (ImPlot::BeginPlot("##guides",0,0,ImVec2(-1,0),ImPlotFlags_YAxis2)) { - ImPlot::DragLineX("x1",&x1,show_labels); - ImPlot::DragLineX("x2",&x2,show_labels); - ImPlot::DragLineY("y1",&y1,show_labels); - ImPlot::DragLineY("y2",&y2,show_labels); - double xs[1000], ys[1000]; - for (int i = 0; i < 1000; ++i) { - xs[i] = (x2+x1)/2+fabs(x2-x1)*(i/1000.0f - 0.5f); - ys[i] = (y1+y2)/2+fabs(y2-y1)/2*sin(f*i/10); - } - ImPlot::PlotLine("Interactive Data", xs, ys, 1000); - ImPlot::SetPlotYAxis(ImPlotYAxis_2); - ImPlot::DragLineY("f",&f,show_labels,ImVec4(1,0.5f,1,1)); - ImPlot::EndPlot(); - } -} - void ShowDemo_DragPoints() { - static bool show_labels = true; - ImGui::BulletText("Click and drag any point."); - ImGui::Checkbox("Show Labels##2",&show_labels); - ImPlotAxisFlags flags = ImPlotAxisFlags_NoTickLabels | ImPlotAxisFlags_NoTickMarks; - ImPlot::SetNextPlotLimits(0,1,0,1); - if (ImPlot::BeginPlot("##Bezier",0,0,ImVec2(-1,0),ImPlotFlags_CanvasOnly,flags,flags)) { + ImGui::BulletText("Click and drag each point."); + static ImPlotDragToolFlags flags = ImPlotDragToolFlags_None; + ImGui::CheckboxFlags("NoCursors", (unsigned int*)&flags, ImPlotDragToolFlags_NoCursors); ImGui::SameLine(); + ImGui::CheckboxFlags("NoFit", (unsigned int*)&flags, ImPlotDragToolFlags_NoFit); ImGui::SameLine(); + ImGui::CheckboxFlags("NoInput", (unsigned int*)&flags, ImPlotDragToolFlags_NoInputs); + ImPlotAxisFlags ax_flags = ImPlotAxisFlags_NoTickLabels | ImPlotAxisFlags_NoTickMarks; + if (ImPlot::BeginPlot("##Bezier",ImVec2(-1,0),ImPlotFlags_CanvasOnly)) { + ImPlot::SetupAxes(0,0,ax_flags,ax_flags); + ImPlot::SetupAxesLimits(0,1,0,1); static ImPlotPoint P[] = {ImPlotPoint(.05f,.05f), ImPlotPoint(0.2,0.4), ImPlotPoint(0.8,0.6), ImPlotPoint(.95f,.95f)}; + + ImPlot::DragPoint(0,&P[0].x,&P[0].y, ImVec4(0,0.9f,0,1),4,flags); + ImPlot::DragPoint(1,&P[1].x,&P[1].y, ImVec4(1,0.5f,1,1),4,flags); + ImPlot::DragPoint(2,&P[2].x,&P[2].y, ImVec4(0,0.5f,1,1),4,flags); + ImPlot::DragPoint(3,&P[3].x,&P[3].y, ImVec4(0,0.9f,0,1),4,flags); + static ImPlotPoint B[100]; for (int i = 0; i < 100; ++i) { double t = i / 99.0; @@ -1230,16 +1280,157 @@ void ShowDemo_DragPoints() { double w4 = t*t*t; B[i] = ImPlotPoint(w1*P[0].x + w2*P[1].x + w3*P[2].x + w4*P[3].x, w1*P[0].y + w2*P[1].y + w3*P[2].y + w4*P[3].y); } - ImPlot::SetNextLineStyle(ImVec4(0,0.9f,0,1), 2); - ImPlot::PlotLine("##bez",&B[0].x, &B[0].y, 100, 0, sizeof(ImPlotPoint)); + + ImPlot::SetNextLineStyle(ImVec4(1,0.5f,1,1)); ImPlot::PlotLine("##h1",&P[0].x, &P[0].y, 2, 0, sizeof(ImPlotPoint)); ImPlot::SetNextLineStyle(ImVec4(0,0.5f,1,1)); ImPlot::PlotLine("##h2",&P[2].x, &P[2].y, 2, 0, sizeof(ImPlotPoint)); - ImPlot::DragPoint("P0",&P[0].x,&P[0].y, show_labels, ImVec4(0,0.9f,0,1)); - ImPlot::DragPoint("P1",&P[1].x,&P[1].y, show_labels, ImVec4(1,0.5f,1,1)); - ImPlot::DragPoint("P2",&P[2].x,&P[2].y, show_labels, ImVec4(0,0.5f,1,1)); - ImPlot::DragPoint("P3",&P[3].x,&P[3].y, show_labels, ImVec4(0,0.9f,0,1)); + ImPlot::SetNextLineStyle(ImVec4(0,0.9f,0,1), 2); + ImPlot::PlotLine("##bez",&B[0].x, &B[0].y, 100, 0, sizeof(ImPlotPoint)); + + ImPlot::EndPlot(); + } +} + +void ShowDemo_DragLines() { + ImGui::BulletText("Click and drag the horizontal and vertical lines."); + static double x1 = 0.2; + static double x2 = 0.8; + static double y1 = 0.25; + static double y2 = 0.75; + static double f = 0.1; + static ImPlotDragToolFlags flags = ImPlotDragToolFlags_None; + ImGui::CheckboxFlags("NoCursors", (unsigned int*)&flags, ImPlotDragToolFlags_NoCursors); ImGui::SameLine(); + ImGui::CheckboxFlags("NoFit", (unsigned int*)&flags, ImPlotDragToolFlags_NoFit); ImGui::SameLine(); + ImGui::CheckboxFlags("NoInput", (unsigned int*)&flags, ImPlotDragToolFlags_NoInputs); + if (ImPlot::BeginPlot("##lines",ImVec2(-1,0))) { + ImPlot::SetupAxesLimits(0,1,0,1); + ImPlot::DragLineX(0,&x1,ImVec4(1,1,1,1),1,flags); + ImPlot::DragLineX(1,&x2,ImVec4(1,1,1,1),1,flags); + ImPlot::DragLineY(2,&y1,ImVec4(1,1,1,1),1,flags); + ImPlot::DragLineY(3,&y2,ImVec4(1,1,1,1),1,flags); + double xs[1000], ys[1000]; + for (int i = 0; i < 1000; ++i) { + xs[i] = (x2+x1)/2+fabs(x2-x1)*(i/1000.0f - 0.5f); + ys[i] = (y1+y2)/2+fabs(y2-y1)/2*sin(f*i/10); + } + ImPlot::PlotLine("Interactive Data", xs, ys, 1000); + ImPlot::DragLineY(120482,&f,ImVec4(1,0.5f,1,1),1,flags); + ImPlot::EndPlot(); + } +} + +void ShowDemo_DragRects() { + + static float x_data[512]; + static float y_data1[512]; + static float y_data2[512]; + static float y_data3[512]; + static float sampling_freq = 44100; + static float freq = 500; + for (size_t i = 0; i < 512; ++i) { + const float t = i / sampling_freq; + x_data[i] = t; + const float arg = 2 * 3.14f * freq * t; + y_data1[i] = sinf(arg); + y_data2[i] = y_data1[i] * -0.6f + sinf(2 * arg) * 0.4f; + y_data3[i] = y_data2[i] * -0.6f + sinf(3 * arg) * 0.4f; + } + ImGui::BulletText("Click and drag the edges, corners, and center of the rect."); + static ImPlotRect rect(0.0025,0.0045,0,0.5); + static ImPlotDragToolFlags flags = ImPlotDragToolFlags_None; + ImGui::CheckboxFlags("NoCursors", (unsigned int*)&flags, ImPlotDragToolFlags_NoCursors); ImGui::SameLine(); + ImGui::CheckboxFlags("NoFit", (unsigned int*)&flags, ImPlotDragToolFlags_NoFit); ImGui::SameLine(); + ImGui::CheckboxFlags("NoInput", (unsigned int*)&flags, ImPlotDragToolFlags_NoInputs); + + if (ImPlot::BeginPlot("##Main",ImVec2(-1,150))) { + ImPlot::SetupAxes(NULL,NULL,ImPlotAxisFlags_NoTickLabels,ImPlotAxisFlags_NoTickLabels); + ImPlot::SetupAxesLimits(0,0.01,-1,1); + ImPlot::PlotLine("Signal 1", x_data, y_data1, 512); + ImPlot::PlotLine("Signal 2", x_data, y_data2, 512); + ImPlot::PlotLine("Signal 3", x_data, y_data3, 512); + ImPlot::DragRect(0,&rect.X.Min,&rect.Y.Min,&rect.X.Max,&rect.Y.Max,ImVec4(1,0,1,1),flags); + ImPlot::EndPlot(); + } + if (ImPlot::BeginPlot("##rect",ImVec2(-1,150), ImPlotFlags_CanvasOnly)) { + ImPlot::SetupAxes(NULL,NULL,ImPlotAxisFlags_NoDecorations,ImPlotAxisFlags_NoDecorations); + ImPlot::SetupAxesLimits(rect.X.Min, rect.X.Max, rect.Y.Min, rect.Y.Max, ImGuiCond_Always); + ImPlot::PlotLine("Signal 1", x_data, y_data1, 512); + ImPlot::PlotLine("Signal 2", x_data, y_data2, 512); + ImPlot::PlotLine("Signal 3", x_data, y_data3, 512); + ImPlot::EndPlot(); + } +} + +ImPlotPoint FindCentroid(const ImVector& data, ImPlotRect& bounds, int& cnt) { + cnt = 0; + ImPlotPoint avg; + for (int i = 0; i < data.size(); ++i) { + if (bounds.Contains(data[i].x, data[i].y)) { + avg.x += data[i].x; + avg.y += data[i].y; + cnt++; + } + } + if (cnt > 0) { + avg.x = avg.x / cnt; + avg.y = avg.y / cnt; + } + return avg; +} + +void ShowDemo_Querying() { + static ImVector data; + static ImVector rects; + static ImPlotRect limits, select; + static bool init = true; + if (init) { + for (int i = 0; i < 50; ++i) + { + double x = RandomRange(0.1, 0.9); + double y = RandomRange(0.1, 0.9); + data.push_back(ImPlotPoint(x,y)); + } + init = false; + } + + ImGui::BulletText("Box select and left click mouse to create a new query rect."); + ImGui::BulletText("Ctrl + click in the plot area to draw points."); + + if (ImGui::Button("Clear Queries")) + rects.shrink(0); + + if (ImPlot::BeginPlot("##Centroid")) { + ImPlot::SetupAxesLimits(0,1,0,1); + if (ImPlot::IsPlotHovered() && ImGui::IsMouseClicked(0) && ImGui::GetIO().KeyCtrl) { + ImPlotPoint pt = ImPlot::GetPlotMousePos(); + data.push_back(pt); + } + ImPlot::PlotScatter("Points", &data[0].x, &data[0].y, data.size(), 0, 2 * sizeof(double)); + if (ImPlot::IsPlotSelected()) { + select = ImPlot::GetPlotSelection(); + int cnt; + ImPlotPoint centroid = FindCentroid(data,select,cnt); + if (cnt > 0) { + ImPlot::SetNextMarkerStyle(ImPlotMarker_Square,6); + ImPlot::PlotScatter("Centroid", ¢roid.x, ¢roid.y, 1); + } + if (ImGui::IsMouseClicked(ImPlot::GetInputMap().SelectCancel)) { + CancelPlotSelection(); + rects.push_back(select); + } + } + for (int i = 0; i < rects.size(); ++i) { + int cnt; + ImPlotPoint centroid = FindCentroid(data,rects[i],cnt); + if (cnt > 0) { + ImPlot::SetNextMarkerStyle(ImPlotMarker_Square,6); + ImPlot::PlotScatter("Centroid", ¢roid.x, ¢roid.y, 1); + } + ImPlot::DragRect(i,&rects[i].X.Min,&rects[i].Y.Min,&rects[i].X.Max,&rects[i].Y.Max,ImVec4(1,0,1,1)); + } + limits = ImPlot::GetPlotLimits(); ImPlot::EndPlot(); } } @@ -1247,23 +1438,44 @@ void ShowDemo_DragPoints() { void ShowDemo_Annotations() { static bool clamp = false; ImGui::Checkbox("Clamp",&clamp); - ImPlot::SetNextPlotLimits(0,2,0,1); if (ImPlot::BeginPlot("##Annotations")) { - + ImPlot::SetupAxesLimits(0,2,0,1); static float p[] = {0.25f, 0.25f, 0.75f, 0.75f, 0.25f}; ImPlot::PlotScatter("##Points",&p[0],&p[1],4); ImVec4 col = GetLastItemColor(); - clamp ? ImPlot::AnnotateClamped(0.25,0.25,ImVec2(-15,15),col,"BL") : ImPlot::Annotate(0.25,0.25,ImVec2(-15,15),col,"BL"); - clamp ? ImPlot::AnnotateClamped(0.75,0.25,ImVec2(15,15),col,"BR") : ImPlot::Annotate(0.75,0.25,ImVec2(15,15),col,"BR"); - clamp ? ImPlot::AnnotateClamped(0.75,0.75,ImVec2(15,-15),col,"TR") : ImPlot::Annotate(0.75,0.75,ImVec2(15,-15),col,"TR"); - clamp ? ImPlot::AnnotateClamped(0.25,0.75,ImVec2(-15,-15),col,"TL") : ImPlot::Annotate(0.25,0.75,ImVec2(-15,-15),col,"TL"); - clamp ? ImPlot::AnnotateClamped(0.5,0.5,ImVec2(0,0),col,"Center") : ImPlot::Annotate(0.5,0.5,ImVec2(0,0),col,"Center"); + ImPlot::Annotation(0.25,0.25,col,ImVec2(-15,15),clamp,"BL"); + ImPlot::Annotation(0.75,0.25,col,ImVec2(15,15),clamp,"BR"); + ImPlot::Annotation(0.75,0.75,col,ImVec2(15,-15),clamp,"TR"); + ImPlot::Annotation(0.25,0.75,col,ImVec2(-15,-15),clamp,"TL"); + ImPlot::Annotation(0.5,0.5,col,ImVec2(0,0),clamp,"Center"); + + ImPlot::Annotation(1.25,0.75,ImVec4(0,1,0,1),ImVec2(0,0),clamp); float bx[] = {1.2f,1.5f,1.8f}; float by[] = {0.25f, 0.5f, 0.75f}; ImPlot::PlotBars("##Bars",bx,by,3,0.2); for (int i = 0; i < 3; ++i) - ImPlot::Annotate(bx[i],by[i],ImVec2(0,-5),"B[%d]=%.2f",i,by[i]); + ImPlot::Annotation(bx[i],by[i],ImVec4(0,0,0,0),ImVec2(0,-5),clamp,"B[%d]=%.2f",i,by[i]); + ImPlot::EndPlot(); + } +} + +void ShowDemo_Tags() { + static bool show = true; + ImGui::Checkbox("Show Tags",&show); + if (ImPlot::BeginPlot("##Tags")) { + ImPlot::SetupAxis(ImAxis_X2); + ImPlot::SetupAxis(ImAxis_Y2); + if (show) { + ImPlot::TagX(0.25, ImVec4(1,1,0,1)); + ImPlot::TagY(0.75, ImVec4(1,1,0,1)); + static double drag_tag = 0.25; + ImPlot::DragLineY(0,&drag_tag,ImVec4(1,0,0,1),1,ImPlotDragToolFlags_NoFit); + ImPlot::TagY(drag_tag, ImVec4(1,0,0,1), "Drag"); + SetAxes(ImAxis_X2, ImAxis_Y2); + ImPlot::TagX(0.5, ImVec4(0,1,1,1), "%s", "MyTag"); + ImPlot::TagY(0.5, ImVec4(0,1,1,1), "Tag: %d", 42); + } ImPlot::EndPlot(); } } @@ -1282,7 +1494,7 @@ void ShowDemo_DragAndDrop() { struct MyDndItem { int Idx; int Plt; - int Yax; + ImAxis Yax; char Label[16]; ImVector Data; ImVec4 Color; @@ -1290,7 +1502,7 @@ void ShowDemo_DragAndDrop() { static int i = 0; Idx = i++; Plt = 0; - Yax = ImPlotYAxis_1; + Yax = ImAxis_Y1; sprintf(Label, "%02d Hz", Idx+1); Color = RandomColor(); Data.reserve(1001); @@ -1299,7 +1511,7 @@ void ShowDemo_DragAndDrop() { Data.push_back(ImVec2(t, 0.5f + 0.5f * sinf(2*3.14f*t*(Idx+1)))); } } - void Reset() { Plt = 0; Yax = ImPlotYAxis_1; } + void Reset() { Plt = 0; Yax = ImAxis_Y1; } }; const int k_dnd = 20; @@ -1309,7 +1521,7 @@ void ShowDemo_DragAndDrop() { // child window to serve as initial source for our DND items ImGui::BeginChild("DND_LEFT",ImVec2(100,400)); - if (ImGui::Button("Reset Data", ImVec2(100, 0))) { + if (ImGui::Button("Reset Data")) { for (int k = 0; k < k_dnd; ++k) dnd[k].Reset(); dndx = dndy = NULL; @@ -1338,16 +1550,19 @@ void ShowDemo_DragAndDrop() { ImGui::BeginChild("DND_RIGHT",ImVec2(-1,400)); // plot 1 (time series) ImPlotAxisFlags flags = ImPlotAxisFlags_NoTickLabels | ImPlotAxisFlags_NoGridLines; - if (ImPlot::BeginPlot("##DND1", NULL, "[drop here]", ImVec2(-1,195), ImPlotFlags_YAxis2 | ImPlotFlags_YAxis3, flags | ImPlotAxisFlags_Lock, flags, flags, flags, "[drop here]", "[drop here]")) { + if (ImPlot::BeginPlot("##DND1", ImVec2(-1,195))) { + ImPlot::SetupAxis(ImAxis_X1, NULL, flags|ImPlotAxisFlags_Lock); + ImPlot::SetupAxis(ImAxis_Y1, "[drop here]", flags); + ImPlot::SetupAxis(ImAxis_Y2, "[drop here]", flags|ImPlotAxisFlags_Opposite); + ImPlot::SetupAxis(ImAxis_Y3, "[drop here]", flags|ImPlotAxisFlags_Opposite); + for (int k = 0; k < k_dnd; ++k) { if (dnd[k].Plt == 1 && dnd[k].Data.size() > 0) { - ImPlot::SetPlotYAxis(dnd[k].Yax); + ImPlot::SetAxis(dnd[k].Yax); ImPlot::SetNextLineStyle(dnd[k].Color); - static char label[32]; - sprintf(label,"%s (Y%d)", dnd[k].Label, dnd[k].Yax+1); - ImPlot::PlotLine(label, &dnd[k].Data[0].x, &dnd[k].Data[0].y, dnd[k].Data.size(), 0, 2 * sizeof(float)); + ImPlot::PlotLine(dnd[k].Label, &dnd[k].Data[0].x, &dnd[k].Data[0].y, dnd[k].Data.size(), 0, 2 * sizeof(float)); // allow legend item labels to be DND sources - if (ImPlot::BeginDragDropSourceItem(label)) { + if (ImPlot::BeginDragDropSourceItem(dnd[k].Label)) { ImGui::SetDragDropPayload("MY_DND", &k, sizeof(int)); ImPlot::ItemIcon(dnd[k].Color); ImGui::SameLine(); ImGui::TextUnformatted(dnd[k].Label); @@ -1356,15 +1571,15 @@ void ShowDemo_DragAndDrop() { } } // allow the main plot area to be a DND target - if (ImPlot::BeginDragDropTarget()) { + if (ImPlot::BeginDragDropTargetPlot()) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("MY_DND")) { - int i = *(int*)payload->Data; dnd[i].Plt = 1; dnd[i].Yax = 0; + int i = *(int*)payload->Data; dnd[i].Plt = 1; dnd[i].Yax = ImAxis_Y1; } ImPlot::EndDragDropTarget(); } // allow each y-axis to be a DND target - for (int y = 0; y < 3; ++y) { - if (ImPlot::BeginDragDropTargetY(y)) { + for (int y = ImAxis_Y1; y <= ImAxis_Y3; ++y) { + if (ImPlot::BeginDragDropTargetAxis(y)) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("MY_DND")) { int i = *(int*)payload->Data; dnd[i].Plt = 1; dnd[i].Yax = y; } @@ -1374,72 +1589,75 @@ void ShowDemo_DragAndDrop() { // allow the legend to be a DND target if (ImPlot::BeginDragDropTargetLegend()) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("MY_DND")) { - int i = *(int*)payload->Data; dnd[i].Plt = 1; dnd[i].Yax = 0; + int i = *(int*)payload->Data; dnd[i].Plt = 1; dnd[i].Yax = ImAxis_Y1; } ImPlot::EndDragDropTarget(); } ImPlot::EndPlot(); } // plot 2 (Lissajous) - ImPlot::PushStyleColor(ImPlotCol_XAxis, dndx == NULL ? ImPlot::GetStyle().Colors[ImPlotCol_XAxis] : dndx->Color); - ImPlot::PushStyleColor(ImPlotCol_YAxis, dndy == NULL ? ImPlot::GetStyle().Colors[ImPlotCol_YAxis] : dndy->Color); - if (ImPlot::BeginPlot("##DND2", dndx == NULL ? "[drop here]" : dndx->Label, dndy == NULL ? "[drop here]" : dndy->Label, ImVec2(-1,195), 0, flags, flags )) { + if (ImPlot::BeginPlot("##DND2", ImVec2(-1,195))) { + ImPlot::PushStyleColor(ImPlotCol_AxisBg, dndx != NULL ? dndx->Color : ImPlot::GetStyle().Colors[ImPlotCol_AxisBg]); + ImPlot::SetupAxis(ImAxis_X1, dndx == NULL ? "[drop here]" : dndx->Label, flags); + ImPlot::PushStyleColor(ImPlotCol_AxisBg, dndy != NULL ? dndy->Color : ImPlot::GetStyle().Colors[ImPlotCol_AxisBg]); + ImPlot::SetupAxis(ImAxis_Y1, dndy == NULL ? "[drop here]" : dndy->Label, flags); + ImPlot::PopStyleColor(2); if (dndx != NULL && dndy != NULL) { ImVec4 mixed((dndx->Color.x + dndy->Color.x)/2,(dndx->Color.y + dndy->Color.y)/2,(dndx->Color.z + dndy->Color.z)/2,(dndx->Color.w + dndy->Color.w)/2); ImPlot::SetNextLineStyle(mixed); ImPlot::PlotLine("##dndxy", &dndx->Data[0].y, &dndy->Data[0].y, dndx->Data.size(), 0, 2 * sizeof(float)); } // allow the x-axis to be a DND target - if (ImPlot::BeginDragDropTargetX()) { + if (ImPlot::BeginDragDropTargetAxis(ImAxis_X1)) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("MY_DND")) { int i = *(int*)payload->Data; dndx = &dnd[i]; } ImPlot::EndDragDropTarget(); } // allow the x-axis to be a DND source - if (dndx != NULL && ImPlot::BeginDragDropSourceX()) { + if (dndx != NULL && ImPlot::BeginDragDropSourceAxis(ImAxis_X1)) { ImGui::SetDragDropPayload("MY_DND", &dndx->Idx, sizeof(int)); ImPlot::ItemIcon(dndx->Color); ImGui::SameLine(); ImGui::TextUnformatted(dndx->Label); ImPlot::EndDragDropSource(); } // allow the y-axis to be a DND target - if (ImPlot::BeginDragDropTargetY()) { + if (ImPlot::BeginDragDropTargetAxis(ImAxis_Y1)) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("MY_DND")) { int i = *(int*)payload->Data; dndy = &dnd[i]; } ImPlot::EndDragDropTarget(); } // allow the y-axis to be a DND source - if (dndy != NULL && ImPlot::BeginDragDropSourceY()) { + if (dndy != NULL && ImPlot::BeginDragDropSourceAxis(ImAxis_Y1)) { ImGui::SetDragDropPayload("MY_DND", &dndy->Idx, sizeof(int)); ImPlot::ItemIcon(dndy->Color); ImGui::SameLine(); ImGui::TextUnformatted(dndy->Label); ImPlot::EndDragDropSource(); } // allow the plot area to be a DND target - if (ImPlot::BeginDragDropTarget()) { + if (ImPlot::BeginDragDropTargetPlot()) { if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("MY_DND")) { int i = *(int*)payload->Data; dndx = dndy = &dnd[i]; } } // allow the plot area to be a DND source - if (ImPlot::BeginDragDropSource()) { + if (ImPlot::BeginDragDropSourcePlot()) { ImGui::TextUnformatted("Yes, you can\ndrag this!"); ImPlot::EndDragDropSource(); } ImPlot::EndPlot(); } - ImPlot::PopStyleColor(2); ImGui::EndChild(); } void ShowDemo_Tables() { #ifdef IMGUI_HAS_TABLE - static ImGuiTableFlags flags = ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_RowBg; + static ImGuiTableFlags flags = ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | + ImGuiTableFlags_RowBg | ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable; static bool anim = true; static int offset = 0; - ImGui::BulletText("Plots can be used inside of ImGui tables as a means of creating subplots."); + ImGui::BulletText("Plots can be used inside of ImGui tables as another means of creating subplots."); ImGui::Checkbox("Animate",&anim); if (anim) offset = (offset + 1) % 100; @@ -1492,7 +1710,7 @@ void ShowDemo_OffsetAndStride() { ImGui::BulletText("The offset value indicates which circle point index is considered the first."); ImGui::BulletText("Offsets can be negative and/or larger than the actual data count."); ImGui::SliderInt("Offset", &offset, -2*k_points_per, 2*k_points_per); - if (ImPlot::BeginPlot("##strideoffset",0,0,ImVec2(-1,0), ImPlotFlags_Equal)) { + if (ImPlot::BeginPlot("##strideoffset",ImVec2(-1,0),ImPlotFlags_Equal)) { ImPlot::PushColormap(ImPlotColormap_Jet); char buff[16]; for (int c = 0; c < k_circles; ++c) { @@ -1540,6 +1758,23 @@ void ShowDemo_CustomDataAndGetters() { } } +void MetricFormatter(double value, char* buff, int size, void* data) { + const char* unit = (const char*)data; + static double v[] = {1000000000,1000000,1000,1,0.001,0.000001,0.000000001}; + static const char* p[] = {"G","M","k","","m","u","n"}; + if (value == 0) { + snprintf(buff,size,"0 %s", unit); + return; + } + for (int i = 0; i < 7; ++i) { + if (fabs(value) >= v[i]) { + snprintf(buff,size,"%g %s%s",value/v[i],p[i],unit); + return; + } + } + snprintf(buff,size,"%g %s%s",value/v[6],p[6],unit); +} + void ShowDemo_TickLabels() { static bool custom_fmt = true; static bool custom_ticks = false; @@ -1551,27 +1786,29 @@ void ShowDemo_TickLabels() { ImGui::SameLine(); ImGui::Checkbox("Show Custom Labels", &custom_labels); } - double pi = 3.14; + const double pi = 3.14; const char* pi_str[] = {"PI"}; - static double yticks[] = {1,3,7,9}; + static double yticks[] = {100,300,700,900}; static const char* ylabels[] = {"One","Three","Seven","Nine"}; static double yticks_aux[] = {0.2,0.4,0.6}; static const char* ylabels_aux[] = {"A","B","C","D","E","F"}; - if (custom_fmt) { - ImPlot::SetNextPlotFormatX("%g ms"); - ImPlot::SetNextPlotFormatY("%g Hz", ImPlotYAxis_1); - ImPlot::SetNextPlotFormatY("%g dB", ImPlotYAxis_2); - ImPlot::SetNextPlotFormatY("%g km", ImPlotYAxis_3); - } - if (custom_ticks) { - ImPlot::SetNextPlotTicksX(&pi,1,custom_labels ? pi_str : NULL, true); - ImPlot::SetNextPlotTicksY(yticks, 4, custom_labels ? ylabels : NULL, ImPlotYAxis_1); - ImPlot::SetNextPlotTicksY(yticks_aux, 3, custom_labels ? ylabels_aux : NULL, false, ImPlotYAxis_2); - ImPlot::SetNextPlotTicksY(0, 1, 6, custom_labels ? ylabels_aux : NULL, false, ImPlotYAxis_3); - } - ImPlot::SetNextPlotLimits(2.5,5,0,10); - if (ImPlot::BeginPlot("##Ticks", NULL, NULL, ImVec2(-1,0), ImPlotFlags_YAxis2 | ImPlotFlags_YAxis3)) { - // nothing to see here, just the ticks + + if (ImPlot::BeginPlot("##Ticks")) { + ImPlot::SetupAxesLimits(2.5,5,0,1000); + ImPlot::SetupAxis(ImAxis_Y2, NULL, ImPlotAxisFlags_AuxDefault); + ImPlot::SetupAxis(ImAxis_Y3, NULL, ImPlotAxisFlags_AuxDefault); + if (custom_fmt) { + ImPlot::SetupAxisFormat(ImAxis_X1, "%g ms"); + ImPlot::SetupAxisFormat(ImAxis_Y1, MetricFormatter, (void*)"Hz"); + ImPlot::SetupAxisFormat(ImAxis_Y2, "%g dB"); + ImPlot::SetupAxisFormat(ImAxis_Y3, MetricFormatter, (void*)"m"); + } + if (custom_ticks) { + ImPlot::SetupAxisTicks(ImAxis_X1, &pi,1,custom_labels ? pi_str : NULL, true); + ImPlot::SetupAxisTicks(ImAxis_Y1, yticks, 4, custom_labels ? ylabels : NULL, false); + ImPlot::SetupAxisTicks(ImAxis_Y2, yticks_aux, 3, custom_labels ? ylabels_aux : NULL, false); + ImPlot::SetupAxisTicks(ImAxis_Y3, 0, 1, 6, custom_labels ? ylabels_aux : NULL, false); + } ImPlot::EndPlot(); } } @@ -1581,8 +1818,9 @@ void ShowDemo_CustomStyles() { // normally you wouldn't change the entire style each frame ImPlotStyle backup = ImPlot::GetStyle(); MyImPlot::StyleSeaborn(); - ImPlot::SetNextPlotLimits(-0.5f, 9.5f, 0, 10); - if (ImPlot::BeginPlot("seaborn style", "x-axis", "y-axis")) { + if (ImPlot::BeginPlot("seaborn style")) { + ImPlot::SetupAxes( "x-axis", "y-axis"); + ImPlot::SetupAxesLimits(-0.5f, 9.5f, 0, 10); unsigned int lin[10] = {8,8,9,7,8,8,8,9,7,8}; unsigned int bar[10] = {1,2,5,3,4,1,2,5,3,4}; unsigned int dot[10] = {7,6,6,7,8,5,6,5,8,7}; @@ -1626,8 +1864,8 @@ void ShowDemo_LegendPopups() { for (int i = 0; i < 101; ++i) vals[i] = amplitude * sinf(frequency * i); - ImPlot::SetNextPlotLimits(0,100,-1,1); if (ImPlot::BeginPlot("Right Click the Legend")) { + ImPlot::SetupAxesLimits(0,100,-1,1); // rendering logic ImPlot::PushStyleVar(ImPlotStyleVar_FillAlpha, alpha); if (!line) { @@ -1660,6 +1898,15 @@ void ShowDemo_LegendPopups() { } } +void ShowDemo_ColormapTools() { + static int cmap = 0; + if (ImPlot::ColormapButton("Colormap Button",ImVec2(0,0),cmap)) { + cmap = (cmap + 1) % ImPlot::GetColormapCount(); + } + ImPlot::ColormapIcon(cmap); ImGui::SameLine(); ImGui::Text("Colormap Icon"); + ImPlot::ColormapScale("Colormap Scale",0,1,ImVec2(0,0),cmap); +} + void ShowDemo_CustomPlottersAndTooltips() { ImGui::BulletText("You can create custom plotters or extend ImPlot using implot_internal.h."); double dates[] = {1546300800,1546387200,1546473600,1546560000,1546819200,1546905600,1546992000,1547078400,1547164800,1547424000,1547510400,1547596800,1547683200,1547769600,1547942400,1548028800,1548115200,1548201600,1548288000,1548374400,1548633600,1548720000,1548806400,1548892800,1548979200,1549238400,1549324800,1549411200,1549497600,1549584000,1549843200,1549929600,1550016000,1550102400,1550188800,1550361600,1550448000,1550534400,1550620800,1550707200,1550793600,1551052800,1551139200,1551225600,1551312000,1551398400,1551657600,1551744000,1551830400,1551916800,1552003200,1552262400,1552348800,1552435200,1552521600,1552608000,1552867200,1552953600,1553040000,1553126400,1553212800,1553472000,1553558400,1553644800,1553731200,1553817600,1554076800,1554163200,1554249600,1554336000,1554422400,1554681600,1554768000,1554854400,1554940800,1555027200,1555286400,1555372800,1555459200,1555545600,1555632000,1555891200,1555977600,1556064000,1556150400,1556236800,1556496000,1556582400,1556668800,1556755200,1556841600,1557100800,1557187200,1557273600,1557360000,1557446400,1557705600,1557792000,1557878400,1557964800,1558051200,1558310400,1558396800,1558483200,1558569600,1558656000,1558828800,1558915200,1559001600,1559088000,1559174400,1559260800,1559520000,1559606400,1559692800,1559779200,1559865600,1560124800,1560211200,1560297600,1560384000,1560470400,1560729600,1560816000,1560902400,1560988800,1561075200,1561334400,1561420800,1561507200,1561593600,1561680000,1561939200,1562025600,1562112000,1562198400,1562284800,1562544000,1562630400,1562716800,1562803200,1562889600,1563148800,1563235200,1563321600,1563408000,1563494400,1563753600,1563840000,1563926400,1564012800,1564099200,1564358400,1564444800,1564531200,1564617600,1564704000,1564963200,1565049600,1565136000,1565222400,1565308800,1565568000,1565654400,1565740800,1565827200,1565913600,1566172800,1566259200,1566345600,1566432000,1566518400,1566777600,1566864000,1566950400,1567036800,1567123200,1567296000,1567382400,1567468800,1567555200,1567641600,1567728000,1567987200,1568073600,1568160000,1568246400,1568332800,1568592000,1568678400,1568764800,1568851200,1568937600,1569196800,1569283200,1569369600,1569456000,1569542400,1569801600,1569888000,1569974400,1570060800,1570147200,1570406400,1570492800,1570579200,1570665600,1570752000,1571011200,1571097600,1571184000,1571270400,1571356800,1571616000,1571702400,1571788800,1571875200,1571961600}; @@ -1675,9 +1922,11 @@ void ShowDemo_CustomPlottersAndTooltips() { ImGui::SameLine(); ImGui::ColorEdit4("##Bull", &bullCol.x, ImGuiColorEditFlags_NoInputs); ImGui::SameLine(); ImGui::ColorEdit4("##Bear", &bearCol.x, ImGuiColorEditFlags_NoInputs); ImPlot::GetStyle().UseLocalTime = false; - ImPlot::SetNextPlotFormatY("$%.0f"); - ImPlot::SetNextPlotLimits(1546300800, 1571961600, 1250, 1600); - if (ImPlot::BeginPlot("Candlestick Chart",NULL,NULL,ImVec2(-1,0),0,ImPlotAxisFlags_Time,ImPlotAxisFlags_AutoFit|ImPlotAxisFlags_RangeFit)) { + + if (ImPlot::BeginPlot("Candlestick Chart",ImVec2(-1,0))) { + ImPlot::SetupAxes(NULL,NULL,ImPlotAxisFlags_Time,ImPlotAxisFlags_AutoFit|ImPlotAxisFlags_RangeFit); + ImPlot::SetupAxesLimits(1546300800, 1571961600, 1250, 1600); + ImPlot::SetupAxisFormat(ImAxis_Y1, "$%.0f"); MyImPlot::PlotCandlestick("GOOGL",dates, opens, closes, lows, highs, 218, tooltip, 0.25f, bullCol, bearCol); ImPlot::EndPlot(); } @@ -1759,6 +2008,10 @@ void ShowDemoWindow(bool* p_open) { ShowDemo_StairstepPlots(); if (ImGui::CollapsingHeader("Bar Plots")) ShowDemo_BarPlots(); + if (ImGui::CollapsingHeader("Bar Groups")) + ShowDemo_BarGroups(); + if (ImGui::CollapsingHeader("Bar Stacks")) + ShowDemo_BarStacks(); if (ImGui::CollapsingHeader("Error Bars")) ShowDemo_ErrorBars(); if (ImGui::CollapsingHeader("Stem Plots##")) @@ -1797,8 +2050,8 @@ void ShowDemoWindow(bool* p_open) { ShowDemo_LogAxes(); if (ImGui::CollapsingHeader("Time Axes")) ShowDemo_TimeAxes(); - if (ImGui::CollapsingHeader("Multiple Y-Axes")) - ShowDemo_MultipleYAxes(); + if (ImGui::CollapsingHeader("Multiple Axes")) + ShowDemo_MultipleAxes(); if (ImGui::CollapsingHeader("Tick Labels")) ShowDemo_TickLabels(); if (ImGui::CollapsingHeader("Linked Axes")) @@ -1812,22 +2065,26 @@ void ShowDemoWindow(bool* p_open) { if (ImGui::BeginTabItem("Tools")) { if (ImGui::CollapsingHeader("Offset and Stride")) ShowDemo_OffsetAndStride(); - if (ImGui::CollapsingHeader("Querying")) - ShowDemo_Querying(); - if (ImGui::CollapsingHeader("Views")) - ShowDemo_Views(); - if (ImGui::CollapsingHeader("Drag Lines")) - ShowDemo_DragLines(); if (ImGui::CollapsingHeader("Drag Points")) ShowDemo_DragPoints(); + if (ImGui::CollapsingHeader("Drag Lines")) + ShowDemo_DragLines(); + if (ImGui::CollapsingHeader("Drag Rects")) + ShowDemo_DragRects(); + if (ImGui::CollapsingHeader("Querying")) + ShowDemo_Querying(); if (ImGui::CollapsingHeader("Annotations")) ShowDemo_Annotations(); + if (ImGui::CollapsingHeader("Tags")) + ShowDemo_Tags(); if (ImGui::CollapsingHeader("Drag and Drop")) ShowDemo_DragAndDrop(); if (ImGui::CollapsingHeader("Legend Options")) ShowDemo_LegendOptions(); if (ImGui::CollapsingHeader("Legend Popups")) ShowDemo_LegendPopups(); + if (ImGui::CollapsingHeader("Colormap Tools")) + ShowDemo_ColormapTools(); ImGui::EndTabItem(); } if (ImGui::BeginTabItem("Custom")) { @@ -1842,7 +2099,7 @@ void ShowDemoWindow(bool* p_open) { ImGui::EndTabItem(); } if (ImGui::BeginTabItem("Config")) { - ShowDemo_Configuration(); + ShowDemo_Config(); ImGui::EndTabItem(); } if (ImGui::BeginTabItem("Help")) { @@ -1881,11 +2138,11 @@ ImPlotPoint Spiral(void*, int idx) { 0.5f + (a + b*Th / (2.0f * (float)3.14))*sin(Th)); } -// Example for Tables section. Generates a quick and simple shaded line plot. See implementation at bottom. void Sparkline(const char* id, const float* values, int count, float min_v, float max_v, int offset, const ImVec4& col, const ImVec2& size) { ImPlot::PushStyleVar(ImPlotStyleVar_PlotPadding, ImVec2(0,0)); - ImPlot::SetNextPlotLimits(0, count - 1, min_v, max_v, ImGuiCond_Always); - if (ImPlot::BeginPlot(id,0,0,size,ImPlotFlags_CanvasOnly|ImPlotFlags_NoChild,ImPlotAxisFlags_NoDecorations,ImPlotAxisFlags_NoDecorations)) { + if (ImPlot::BeginPlot(id,size,ImPlotFlags_CanvasOnly|ImPlotFlags_NoChild)) { + ImPlot::SetupAxes(0,0,ImPlotAxisFlags_NoDecorations,ImPlotAxisFlags_NoDecorations); + ImPlot::SetupAxesLimits(0, count - 1, min_v, max_v, ImGuiCond_Always); ImPlot::PushStyleColor(ImPlotCol_Line, col); ImPlot::PlotLine(id, values, count, 1, 0, offset); ImPlot::PushStyleVar(ImPlotStyleVar_FillAlpha, 0.25f); @@ -1915,16 +2172,11 @@ void StyleSeaborn() { colors[ImPlotCol_LegendText] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); colors[ImPlotCol_TitleText] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); colors[ImPlotCol_InlayText] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); - colors[ImPlotCol_XAxis] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); - colors[ImPlotCol_XAxisGrid] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); - colors[ImPlotCol_YAxis] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); - colors[ImPlotCol_YAxisGrid] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); - colors[ImPlotCol_YAxis2] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); - colors[ImPlotCol_YAxisGrid2] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); - colors[ImPlotCol_YAxis3] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); - colors[ImPlotCol_YAxisGrid3] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); + colors[ImPlotCol_AxisText] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); + colors[ImPlotCol_AxisGrid] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); + colors[ImPlotCol_AxisBgHovered] = ImVec4(0.92f, 0.92f, 0.95f, 1.00f); + colors[ImPlotCol_AxisBgActive] = ImVec4(0.92f, 0.92f, 0.95f, 0.75f); colors[ImPlotCol_Selection] = ImVec4(1.00f, 0.65f, 0.00f, 1.00f); - colors[ImPlotCol_Query] = ImVec4(0.23f, 0.10f, 0.64f, 1.00f); colors[ImPlotCol_Crosshairs] = ImVec4(0.23f, 0.10f, 0.64f, 0.50f); style.LineWeight = 1.5; @@ -1947,7 +2199,7 @@ void StyleSeaborn() { style.PlotPadding = ImVec2(12,12); style.LabelPadding = ImVec2(5,5); style.LegendPadding = ImVec2(5,5); - style.MousePosPadding = ImVec2(5,5); + style.MousePosPadding = ImVec2(5,5); style.PlotMinSize = ImVec2(300,225); } @@ -2138,8 +2390,9 @@ void ShowBenchmarkTool() { ImGui::ProgressBar((float)L / (float)(max_items - 1)); - ImPlot::SetNextPlotLimits(0,1000,0,1,ImGuiCond_Always); - if (ImPlot::BeginPlot("##Bench",NULL,NULL,ImVec2(-1,0),ImPlotFlags_NoChild | ImPlotFlags_CanvasOnly,ImPlotAxisFlags_NoDecorations,ImPlotAxisFlags_NoDecorations)) { + if (ImPlot::BeginPlot("##Bench",ImVec2(-1,0),ImPlotFlags_NoChild | ImPlotFlags_CanvasOnly)) { + ImPlot::SetupAxes(NULL,NULL,ImPlotAxisFlags_NoDecorations,ImPlotAxisFlags_NoDecorations); + ImPlot::SetupAxesLimits(0,1000,0,1,ImGuiCond_Always); if (running) { if (mode == BenchMode::Line) { for (int i = 0; i < L; ++i) { @@ -2184,9 +2437,10 @@ void ShowBenchmarkTool() { } ImPlot::EndPlot(); } - ImPlot::SetNextPlotLimits(0,500,0,500,ImGuiCond_Always); static char buffer[64]; - if (ImPlot::BeginPlot("##Stats", "Items (1,000 pts each)", "Framerate (Hz)", ImVec2(-1,0), ImPlotFlags_NoChild)) { + if (ImPlot::BeginPlot("##Stats", ImVec2(-1,0), ImPlotFlags_NoChild)) { + ImPlot::SetupAxes("Items (1,000 pts each)", "Framerate (Hz)"); + ImPlot::SetupAxesLimits(0,500,0,500,ImGuiCond_Always); for (int run = 0; run < records.size(); ++run) { if (records[run].Data.Size > 1) { sprintf(buffer, "B%d-%s%s", run + 1, names[records[run].Mode], records[run].AA ? "-AA" : ""); diff --git a/lib/external/imgui/source/implot_items.cpp b/lib/external/imgui/source/implot_items.cpp index 4abbb648e..ae750c98e 100644 --- a/lib/external/imgui/source/implot_items.cpp +++ b/lib/external/imgui/source/implot_items.cpp @@ -20,27 +20,42 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -// ImPlot v0.11 WIP +// ImPlot v0.13 WIP #include "implot.h" #include "implot_internal.h" -#ifdef _MSC_VER -#define sprintf sprintf_s -#endif - #define SQRT_1_2 0.70710678118f #define SQRT_3_2 0.86602540378f -#define IMPLOT_NORMALIZE2F_OVER_ZERO(VX, VY) \ - { \ - float d2 = VX * VX + VY * VY; \ - if (d2 > 0.0f) { \ - float inv_len = 1.0f / ImSqrt(d2); \ - VX *= inv_len; \ - VY *= inv_len; \ - } \ - } +#ifndef IMPLOT_NO_FORCE_INLINE + #ifdef _MSC_VER + #define IMPLOT_INLINE __forceinline + #elif defined(__GNUC__) + #define IMPLOT_INLINE inline __attribute__((__always_inline__)) + #elif defined(__CLANG__) + #if __has_attribute(__always_inline__) + #define IMPLOT_INLINE inline __attribute__((__always_inline__)) + #else + #define IMPLOT_INLINE inline + #endif + #else + #define IMPLOT_INLINE inline + #endif +#else + #define IMPLOT_INLINE inline +#endif + +#if defined __SSE__ || defined __x86_64__ || defined _M_X64 +#ifndef IMGUI_ENABLE_SSE +#include +#endif +static IMPLOT_INLINE float ImInvSqrt(float x) { return _mm_cvtss_f32(_mm_rsqrt_ss(_mm_set_ss(x))); } +#else +static IMPLOT_INLINE float ImInvSqrt(float x) { return 1.0f / sqrtf(x); } +#endif + +#define IMPLOT_NORMALIZE2F_OVER_ZERO(VX,VY) do { float d2 = VX*VX + VY*VY; if (d2 > 0.0f) { float inv_len = ImInvSqrt(d2); VX *= inv_len; VY *= inv_len; } } while (0) // Support for pre-1.82 versions. Users on 1.82+ can use 0 (default) flags to mean "all corners" but in order to support older versions we are more explicit. #if (IMGUI_VERSION_NUM < 18102) && !defined(ImDrawFlags_RoundCornersAll) @@ -49,6 +64,16 @@ namespace ImPlot { +//----------------------------------------------------------------------------- +// Utils +//----------------------------------------------------------------------------- + +// Calc maximum index size of ImDrawIdx +template +struct MaxIdx { static const unsigned int Value; }; +template <> const unsigned int MaxIdx::Value = 65535; +template <> const unsigned int MaxIdx::Value = 4294967295; + //----------------------------------------------------------------------------- // Item Utils //----------------------------------------------------------------------------- @@ -81,6 +106,11 @@ ImPlotItem* GetItem(const char* label_id) { return gp.CurrentItems->GetItem(label_id); } +bool IsItemHidden(const char* label_id) { + ImPlotItem* item = GetItem(label_id); + return item != NULL && !item->Show; +} + ImPlotItem* GetCurrentItem() { ImPlotContext& gp = *GImPlot; return gp.CurrentItem; @@ -121,13 +151,6 @@ ImVec4 GetLastItemColor() { return ImVec4(); } -void HideNextItem(bool hidden, ImGuiCond cond) { - ImPlotContext& gp = *GImPlot; - gp.NextItemData.HasHidden = true; - gp.NextItemData.Hidden = hidden; - gp.NextItemData.HiddenCond = cond; -} - void BustItemCache() { ImPlotContext& gp = *GImPlot; for (int p = 0; p < gp.Plots.GetBufSize(); ++p) { @@ -162,10 +185,15 @@ void BustColorCache(const char* plot_title_id) { // Begin/EndItem //----------------------------------------------------------------------------- +static const float ITEM_HIGHLIGHT_LINE_SCALE = 2.0f; +static const float ITEM_HIGHLIGHT_MARK_SCALE = 1.25f; + + // Begins a new item. Returns false if the item should not be plotted. bool BeginItem(const char* label_id, ImPlotCol recolor_from) { ImPlotContext& gp = *GImPlot; IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "PlotX() needs to be called between BeginPlot() and EndPlot()!"); + SetupLock(); bool just_created; ImPlotItem* item = RegisterOrGetItem(label_id, &just_created); // set current item @@ -215,12 +243,21 @@ bool BeginItem(const char* label_id, ImPlotCol recolor_from) { s.DigitalBitGap = s.DigitalBitGap < 0 ? gp.Style.DigitalBitGap : s.DigitalBitGap; // apply alpha modifier(s) s.Colors[ImPlotCol_Fill].w *= s.FillAlpha; - // s.Colors[ImPlotCol_MarkerFill].w *= s.FillAlpha; // TODO: this should be separate, if it at all + s.Colors[ImPlotCol_MarkerFill].w *= s.FillAlpha; // TODO: this should be separate, if it at all // apply highlight mods - if (item->LegendHovered && !ImHasFlag(gp.CurrentPlot->Flags, ImPlotFlags_NoHighlight)) { - s.LineWeight *= 2; - s.MarkerWeight *= 2; - // TODO: highlight fills? + if (item->LegendHovered) { + if (!ImHasFlag(gp.CurrentItems->Legend.Flags, ImPlotLegendFlags_NoHighlightItem)) { + s.LineWeight *= ITEM_HIGHLIGHT_LINE_SCALE; + s.MarkerSize *= ITEM_HIGHLIGHT_MARK_SCALE; + s.MarkerWeight *= ITEM_HIGHLIGHT_LINE_SCALE; + // TODO: how to highlight fills? + } + if (!ImHasFlag(gp.CurrentItems->Legend.Flags, ImPlotLegendFlags_NoHighlightAxis)) { + if (gp.CurrentPlot->EnabledAxesX() > 1) + gp.CurrentPlot->Axes[gp.CurrentPlot->CurrentX].ColorHiLi = item->Color; + if (gp.CurrentPlot->EnabledAxesY() > 1) + gp.CurrentPlot->Axes[gp.CurrentPlot->CurrentY].ColorHiLi = item->Color; + } } // set render flags s.RenderLine = s.Colors[ImPlotCol_Line].w > 0 && s.LineWeight > 0; @@ -245,6 +282,23 @@ void EndItem() { gp.CurrentItem = NULL; } +//----------------------------------------------------------------------------- +// INDEXERS +//----------------------------------------------------------------------------- + +// Offsets and strides a data buffer +template +IMPLOT_INLINE T IndexData(const T* data, int idx, int count, int offset, int stride) { + const int s = ((offset == 0) << 0) | ((stride == sizeof(T)) << 1); + switch (s) { + case 3 : return data[idx]; + case 2 : return data[(offset + idx) % count]; + case 1 : return *(const T*)(const void*)((const unsigned char*)data + (size_t)((idx) ) * stride); + case 0 : return *(const T*)(const void*)((const unsigned char*)data + (size_t)((offset + idx) % count) * stride); + default: return T(0); + } +} + //----------------------------------------------------------------------------- // GETTERS //----------------------------------------------------------------------------- @@ -252,135 +306,110 @@ void EndItem() { // Getters can be thought of as iterators that convert user data (e.g. raw arrays) // to ImPlotPoints +template +struct GetterIdx { + GetterIdx(const T* data, int count, int offset = 0, int stride = sizeof(T)) : + Data(data), + Count(count), + Offset(count ? ImPosMod(offset, count) : 0), + Stride(stride) + { } + template IMPLOT_INLINE double operator()(I idx) const { + return (double)IndexData(Data, idx, Count, Offset, Stride); + } + const T* Data; + int Count; + int Offset; + int Stride; +}; + +struct GetterLin { + GetterLin(double m, double b) : M(m), B(b) { } + template IMPLOT_INLINE double operator()(I idx) const { + return M * idx + B; + } + const double M; + const double B; +}; + +struct GetterRef { + GetterRef(double ref) : Ref(ref) { } + template IMPLOT_INLINE double operator()(I) const { return Ref; } + const double Ref; +}; + +template +struct GetterXY { + GetterXY(TGetterX x, TGetterY y, int count) : GetterX(x), GetterY(y), Count(count) { } + template IMPLOT_INLINE ImPlotPoint operator()(I idx) const { + return ImPlotPoint(GetterX(idx),GetterY(idx)); + } + const TGetterX GetterX; + const TGetterY GetterY; + const int Count; +}; + // Interprets an array of Y points as ImPlotPoints where the X value is the index template -struct GetterYs { - GetterYs(const T* ys, int count, double xscale, double x0, int offset, int stride) : - Ys(ys), - Count(count), - XScale(xscale), - X0(x0), - Offset(count ? ImPosMod(offset, count) : 0), - Stride(stride) - { } - inline ImPlotPoint operator()(int idx) const { - return ImPlotPoint(X0 + XScale * idx, (double)OffsetAndStride(Ys, idx, Count, Offset, Stride)); - } - const T* const Ys; - const int Count; - const double XScale; - const double X0; - const int Offset; - const int Stride; -}; - -// Interprets separate arrays for X and Y points as ImPlotPoints -template -struct GetterXsYs { - GetterXsYs(const T* xs, const T* ys, int count, int offset, int stride) : +struct GetterXs { + GetterXs(const T* xs, int count, double yscale, double y0, int offset, int stride) : Xs(xs), - Ys(ys), Count(count), + YScale(yscale), + Y0(y0), Offset(count ? ImPosMod(offset, count) : 0), Stride(stride) { } - inline ImPlotPoint operator()(int idx) const { - return ImPlotPoint((double)OffsetAndStride(Xs, idx, Count, Offset, Stride), (double)OffsetAndStride(Ys, idx, Count, Offset, Stride)); + template IMPLOT_INLINE ImPlotPoint operator()(I idx) const { + return ImPlotPoint((double)IndexData(Xs, idx, Count, Offset, Stride), Y0 + YScale * idx); } const T* const Xs; - const T* const Ys; - const int Count; - const int Offset; - const int Stride; -}; - -// Always returns a constant Y reference value where the X value is the index -struct GetterYRef { - GetterYRef(double y_ref, int count, double xscale, double x0) : - YRef(y_ref), - Count(count), - XScale(xscale), - X0(x0) - { } - inline ImPlotPoint operator()(int idx) const { - return ImPlotPoint(X0 + XScale*idx, YRef); - } - const double YRef; - const int Count; - const double XScale; - const double X0; -}; - -// Interprets an array of X points as ImPlotPoints where the Y value is a constant reference value -template -struct GetterXsYRef { - GetterXsYRef(const T* xs, double y_ref, int count, int offset, int stride) : - Xs(xs), - YRef(y_ref), - Count(count), - Offset(count ? ImPosMod(offset, count) : 0), - Stride(stride) - { } - inline ImPlotPoint operator()(int idx) const { - return ImPlotPoint((double)OffsetAndStride(Xs, idx, Count, Offset, Stride), YRef); - } - const T* const Xs; - const double YRef; - const int Count; - const int Offset; - const int Stride; -}; - -// Interprets an array of Y points as ImPlotPoints where the X value is a constant reference value -template -struct GetterXRefYs { - GetterXRefYs(double x_ref, const T* ys, int count, int offset, int stride) : - XRef(x_ref), - Ys(ys), - Count(count), - Offset(count ? ImPosMod(offset, count) : 0), - Stride(stride) - { } - inline ImPlotPoint operator()(int idx) const { - return ImPlotPoint(XRef, (double)OffsetAndStride(Ys, idx, Count, Offset, Stride)); - } - const double XRef; - const T* const Ys; const int Count; + const double YScale; + const double Y0; const int Offset; const int Stride; }; /// Interprets a user's function pointer as ImPlotPoints struct GetterFuncPtr { - GetterFuncPtr(ImPlotPoint (*getter)(void* data, int idx), void* data, int count, int offset) : + GetterFuncPtr(ImPlotPoint (*getter)(void* data, int idx), void* data, int count) : Getter(getter), Data(data), - Count(count), - Offset(count ? ImPosMod(offset, count) : 0) + Count(count) { } - inline ImPlotPoint operator()(int idx) const { - idx = ImPosMod(Offset + idx, Count); + template IMPLOT_INLINE ImPlotPoint operator()(I idx) const { return Getter(Data, idx); } ImPlotPoint (* const Getter)(void* data, int idx); void* const Data; const int Count; - const int Offset; }; -template -struct GetterBarV { - const T* Ys; double XShift; int Count; int Offset; int Stride; - GetterBarV(const T* ys, double xshift, int count, int offset, int stride) { Ys = ys; XShift = xshift; Count = count; Offset = offset; Stride = stride; } - inline ImPlotPoint operator()(int idx) const { return ImPlotPoint((double)idx + (double)XShift, (double)OffsetAndStride(Ys, idx, Count, Offset, Stride)); } +template +struct GetterOverrideX { + GetterOverrideX(const TGetter& getter, double x) : Getter(getter), X(x), Count(getter.Count) { } + template IMPLOT_INLINE ImPlotPoint operator()(I idx) const { + ImPlotPoint p = Getter(idx); + p.x = X; + return p; + } + const TGetter& Getter; + const double X; + const int Count; }; -template -struct GetterBarH { - const T* Xs; double YShift; int Count; int Offset; int Stride; - GetterBarH(const T* xs, double yshift, int count, int offset, int stride) { Xs = xs; YShift = yshift; Count = count; Offset = offset; Stride = stride; } - inline ImPlotPoint operator()(int idx) const { return ImPlotPoint((double)OffsetAndStride(Xs, idx, Count, Offset, Stride), (double)idx + (double)YShift); } +template +struct GetterOverrideY { + GetterOverrideY(const TGetter& getter, double y) : Getter(getter), Y(y), Count(getter.Count) { } + template IMPLOT_INLINE ImPlotPoint operator()(I idx) const { + ImPlotPoint p = Getter(idx); + p.y = Y; + return p; + } + const TGetter& Getter; + const double Y; + const int Count; }; template @@ -394,11 +423,11 @@ struct GetterError { Offset(count ? ImPosMod(offset, count) : 0), Stride(stride) { } - inline ImPlotPointError operator()(int idx) const { - return ImPlotPointError((double)OffsetAndStride(Xs, idx, Count, Offset, Stride), - (double)OffsetAndStride(Ys, idx, Count, Offset, Stride), - (double)OffsetAndStride(Neg, idx, Count, Offset, Stride), - (double)OffsetAndStride(Pos, idx, Count, Offset, Stride)); + template IMPLOT_INLINE ImPlotPointError operator()(I idx) const { + return ImPlotPointError((double)IndexData(Xs, idx, Count, Offset, Stride), + (double)IndexData(Ys, idx, Count, Offset, Stride), + (double)IndexData(Neg, idx, Count, Offset, Stride), + (double)IndexData(Pos, idx, Count, Offset, Stride)); } const T* const Xs; const T* const Ys; @@ -415,73 +444,71 @@ struct GetterError { // Transforms convert points in plot space (i.e. ImPlotPoint) to pixel space (i.e. ImVec2) -// Transforms points for linear x and linear y space -struct TransformerLinLin { - TransformerLinLin() : YAxis(GetCurrentYAxis()) {} - // inline ImVec2 operator()(const ImPlotPoint& plt) const { return (*this)(plt.x, plt.y); } - inline ImVec2 operator()(const ImPlotPoint& plt) const { - ImPlotContext& gp = *GImPlot; - return ImVec2( (float)(gp.PixelRange[YAxis].Min.x + gp.Mx * (plt.x - gp.CurrentPlot->XAxis.Range.Min)), - (float)(gp.PixelRange[YAxis].Min.y + gp.My[YAxis] * (plt.y - gp.CurrentPlot->YAxis[YAxis].Range.Min)) ); - } - const int YAxis; +struct TransformerLin { + TransformerLin(double pixMin, double pltMin, double, double m, double ) : PixMin(pixMin), PltMin(pltMin), M(m) { } + template IMPLOT_INLINE float operator()(T p) const { return (float)(PixMin + M * (p - PltMin)); } + double PixMin, PltMin, M; }; -// Transforms points for log x and linear y space -struct TransformerLogLin { - TransformerLogLin() : YAxis(GetCurrentYAxis()) {} - inline ImVec2 operator()(const ImPlotPoint& plt) const { - ImPlotContext& gp = *GImPlot; - double x = plt.x <= 0.0 ? IMPLOT_LOG_ZERO : plt.x; - double t = ImLog10(x / gp.CurrentPlot->XAxis.Range.Min) / gp.LogDenX; - x = ImLerp(gp.CurrentPlot->XAxis.Range.Min, gp.CurrentPlot->XAxis.Range.Max, (float)t); - return ImVec2( (float)(gp.PixelRange[YAxis].Min.x + gp.Mx * (x - gp.CurrentPlot->XAxis.Range.Min)), - (float)(gp.PixelRange[YAxis].Min.y + gp.My[YAxis] * (plt.y - gp.CurrentPlot->YAxis[YAxis].Range.Min)) ); +struct TransformerLog { + TransformerLog(double pixMin, double pltMin, double pltMax, double m, double den) : Den(den), PltMin(pltMin), PltMax(pltMax), PixMin(pixMin), M(m) { } + template IMPLOT_INLINE float operator()(T p) const { + p = p <= 0.0 ? IMPLOT_LOG_ZERO : p; + double t = ImLog10(p / PltMin) / Den; + p = ImLerp(PltMin, PltMax, (float)t); + return (float)(PixMin + M * (p - PltMin)); } - const int YAxis; + double Den, PltMin, PltMax, PixMin, M; }; -// Transforms points for linear x and log y space -struct TransformerLinLog { - TransformerLinLog() : YAxis(GetCurrentYAxis()) {} - inline ImVec2 operator()(const ImPlotPoint& plt) const { - ImPlotContext& gp = *GImPlot; - double y = plt.y <= 0.0 ? IMPLOT_LOG_ZERO : plt.y; - double t = ImLog10(y / gp.CurrentPlot->YAxis[YAxis].Range.Min) / gp.LogDenY[YAxis]; - y = ImLerp(gp.CurrentPlot->YAxis[YAxis].Range.Min, gp.CurrentPlot->YAxis[YAxis].Range.Max, (float)t); - return ImVec2( (float)(gp.PixelRange[YAxis].Min.x + gp.Mx * (plt.x - gp.CurrentPlot->XAxis.Range.Min)), - (float)(gp.PixelRange[YAxis].Min.y + gp.My[YAxis] * (y - gp.CurrentPlot->YAxis[YAxis].Range.Min)) ); +template +struct TransformerXY { + TransformerXY(const ImPlotAxis& x_axis, const ImPlotAxis& y_axis) : + Tx(x_axis.PixelMin, + x_axis.Range.Min, + x_axis.Range.Max, + x_axis.LinM, + x_axis.LogD), + Ty(y_axis.PixelMin, + y_axis.Range.Min, + y_axis.Range.Max, + y_axis.LinM, + y_axis.LogD) + { } + + TransformerXY(const ImPlotPlot& plot) : + TransformerXY(plot.Axes[plot.CurrentX], plot.Axes[plot.CurrentY]) + { } + + TransformerXY() : + TransformerXY(*GImPlot->CurrentPlot) + { } + + template IMPLOT_INLINE ImVec2 operator()(const P& plt) const { + ImVec2 out; + out.x = Tx(plt.x); + out.y = Ty(plt.y); + return out; } - const int YAxis; + TransformerX Tx; + TransformerY Ty; }; -// Transforms points for log x and log y space -struct TransformerLogLog { - TransformerLogLog() : YAxis(GetCurrentYAxis()) {} - inline ImVec2 operator()(const ImPlotPoint& plt) const { - ImPlotContext& gp = *GImPlot; - double x = plt.x <= 0.0 ? IMPLOT_LOG_ZERO : plt.x; - double y = plt.y <= 0.0 ? IMPLOT_LOG_ZERO : plt.y; - double t = ImLog10(x / gp.CurrentPlot->XAxis.Range.Min) / gp.LogDenX; - x = ImLerp(gp.CurrentPlot->XAxis.Range.Min, gp.CurrentPlot->XAxis.Range.Max, (float)t); - t = ImLog10(y / gp.CurrentPlot->YAxis[YAxis].Range.Min) / gp.LogDenY[YAxis]; - y = ImLerp(gp.CurrentPlot->YAxis[YAxis].Range.Min, gp.CurrentPlot->YAxis[YAxis].Range.Max, (float)t); - return ImVec2( (float)(gp.PixelRange[YAxis].Min.x + gp.Mx * (x - gp.CurrentPlot->XAxis.Range.Min)), - (float)(gp.PixelRange[YAxis].Min.y + gp.My[YAxis] * (y - gp.CurrentPlot->YAxis[YAxis].Range.Min)) ); - } - const int YAxis; -}; +typedef TransformerXY TransformerLinLin; +typedef TransformerXY TransformerLinLog; +typedef TransformerXY TransformerLogLin; +typedef TransformerXY TransformerLogLog; //----------------------------------------------------------------------------- // PRIMITIVE RENDERERS //----------------------------------------------------------------------------- -inline void AddLine(const ImVec2& P1, const ImVec2& P2, float weight, ImU32 col, ImDrawList& DrawList, ImVec2 uv) { +IMPLOT_INLINE void PrimLine(const ImVec2& P1, const ImVec2& P2, float half_weight, ImU32 col, ImDrawList& DrawList, ImVec2 uv) { float dx = P2.x - P1.x; float dy = P2.y - P1.y; IMPLOT_NORMALIZE2F_OVER_ZERO(dx, dy); - dx *= (weight * 0.5f); - dy *= (weight * 0.5f); + dx *= half_weight; + dy *= half_weight; DrawList._VtxWritePtr[0].pos.x = P1.x + dy; DrawList._VtxWritePtr[0].pos.y = P1.y - dx; DrawList._VtxWritePtr[0].uv = uv; @@ -509,7 +536,7 @@ inline void AddLine(const ImVec2& P1, const ImVec2& P2, float weight, ImU32 col, DrawList._VtxCurrentIdx += 4; } -inline void AddRectFilled(const ImVec2& Pmin, const ImVec2& Pmax, ImU32 col, ImDrawList& DrawList, ImVec2 uv) { +IMPLOT_INLINE void PrimRectFilled(const ImVec2& Pmin, const ImVec2& Pmax, ImU32 col, ImDrawList& DrawList, ImVec2 uv) { DrawList._VtxWritePtr[0].pos = Pmin; DrawList._VtxWritePtr[0].uv = uv; DrawList._VtxWritePtr[0].col = col; @@ -537,22 +564,22 @@ inline void AddRectFilled(const ImVec2& Pmin, const ImVec2& Pmax, ImU32 col, ImD template struct LineStripRenderer { - inline LineStripRenderer(const TGetter& getter, const TTransformer& transformer, ImU32 col, float weight) : + IMPLOT_INLINE LineStripRenderer(const TGetter& getter, const TTransformer& transformer, ImU32 col, float weight) : Getter(getter), Transformer(transformer), Prims(Getter.Count - 1), Col(col), - Weight(weight) + HalfWeight(weight/2) { P1 = Transformer(Getter(0)); } - inline bool operator()(ImDrawList& DrawList, const ImRect& cull_rect, const ImVec2& uv, int prim) const { + IMPLOT_INLINE bool operator()(ImDrawList& DrawList, const ImRect& cull_rect, const ImVec2& uv, int prim) const { ImVec2 P2 = Transformer(Getter(prim + 1)); if (!cull_rect.Overlaps(ImRect(ImMin(P1, P2), ImMax(P1, P2)))) { P1 = P2; return false; } - AddLine(P1,P2,Weight,Col,DrawList,uv); + PrimLine(P1,P2,HalfWeight,Col,DrawList,uv); P1 = P2; return true; } @@ -560,15 +587,43 @@ struct LineStripRenderer { const TTransformer& Transformer; const int Prims; const ImU32 Col; - const float Weight; + const float HalfWeight; mutable ImVec2 P1; static const int IdxConsumed = 6; static const int VtxConsumed = 4; }; +template +struct LineSegmentsRenderer { + IMPLOT_INLINE LineSegmentsRenderer(const TGetter1& getter1, const TGetter2& getter2, const TTransformer& transformer, ImU32 col, float weight) : + Getter1(getter1), + Getter2(getter2), + Transformer(transformer), + Prims(ImMin(Getter1.Count, Getter2.Count)), + Col(col), + HalfWeight(weight/2) + {} + IMPLOT_INLINE bool operator()(ImDrawList& DrawList, const ImRect& cull_rect, const ImVec2& uv, int prim) const { + ImVec2 P1 = Transformer(Getter1(prim)); + ImVec2 P2 = Transformer(Getter2(prim)); + if (!cull_rect.Overlaps(ImRect(ImMin(P1, P2), ImMax(P1, P2)))) + return false; + PrimLine(P1,P2,HalfWeight,Col,DrawList,uv); + return true; + } + const TGetter1& Getter1; + const TGetter2& Getter2; + const TTransformer& Transformer; + const int Prims; + const ImU32 Col; + const float HalfWeight; + static const int IdxConsumed = 6; + static const int VtxConsumed = 4; +}; + template struct StairsRenderer { - inline StairsRenderer(const TGetter& getter, const TTransformer& transformer, ImU32 col, float weight) : + IMPLOT_INLINE StairsRenderer(const TGetter& getter, const TTransformer& transformer, ImU32 col, float weight) : Getter(getter), Transformer(transformer), Prims(Getter.Count - 1), @@ -577,17 +632,14 @@ struct StairsRenderer { { P1 = Transformer(Getter(0)); } - inline bool operator()(ImDrawList& DrawList, const ImRect& cull_rect, const ImVec2& uv, int prim) const { + IMPLOT_INLINE bool operator()(ImDrawList& DrawList, const ImRect& cull_rect, const ImVec2& uv, int prim) const { ImVec2 P2 = Transformer(Getter(prim + 1)); if (!cull_rect.Overlaps(ImRect(ImMin(P1, P2), ImMax(P1, P2)))) { P1 = P2; return false; } - AddRectFilled(ImVec2(P1.x, P1.y + HalfWeight), ImVec2(P2.x, P1.y - HalfWeight), Col, DrawList, uv); - AddRectFilled(ImVec2(P2.x - HalfWeight, P2.y), ImVec2(P2.x + HalfWeight, P1.y), Col, DrawList, uv); - - // AddLine(P1, P12, Weight, Col, DrawList, uv); - // AddLine(P12, P2, Weight, Col, DrawList, uv); + PrimRectFilled(ImVec2(P1.x, P1.y + HalfWeight), ImVec2(P2.x, P1.y - HalfWeight), Col, DrawList, uv); + PrimRectFilled(ImVec2(P2.x - HalfWeight, P2.y), ImVec2(P2.x + HalfWeight, P1.y), Col, DrawList, uv); P1 = P2; return true; } @@ -601,37 +653,11 @@ struct StairsRenderer { static const int VtxConsumed = 8; }; -template -struct LineSegmentsRenderer { - inline LineSegmentsRenderer(const TGetter1& getter1, const TGetter2& getter2, const TTransformer& transformer, ImU32 col, float weight) : - Getter1(getter1), - Getter2(getter2), - Transformer(transformer), - Prims(ImMin(Getter1.Count, Getter2.Count)), - Col(col), - Weight(weight) - {} - inline bool operator()(ImDrawList& DrawList, const ImRect& cull_rect, const ImVec2& uv, int prim) const { - ImVec2 P1 = Transformer(Getter1(prim)); - ImVec2 P2 = Transformer(Getter2(prim)); - if (!cull_rect.Overlaps(ImRect(ImMin(P1, P2), ImMax(P1, P2)))) - return false; - AddLine(P1,P2,Weight,Col,DrawList,uv); - return true; - } - const TGetter1& Getter1; - const TGetter2& Getter2; - const TTransformer& Transformer; - const int Prims; - const ImU32 Col; - const float Weight; - static const int IdxConsumed = 6; - static const int VtxConsumed = 4; -}; + template struct ShadedRenderer { - ShadedRenderer(const TGetter1& getter1, const TGetter2& getter2, const TTransformer& transformer, ImU32 col) : + IMPLOT_INLINE ShadedRenderer(const TGetter1& getter1, const TGetter2& getter2, const TTransformer& transformer, ImU32 col) : Getter1(getter1), Getter2(getter2), Transformer(transformer), @@ -642,7 +668,7 @@ struct ShadedRenderer { P12 = Transformer(Getter2(0)); } - inline bool operator()(ImDrawList& DrawList, const ImRect& cull_rect, const ImVec2& uv, int prim) const { + IMPLOT_INLINE bool operator()(ImDrawList& DrawList, const ImRect& cull_rect, const ImVec2& uv, int prim) const { ImVec2 P21 = Transformer(Getter1(prim+1)); ImVec2 P22 = Transformer(Getter2(prim+1)); ImRect rect(ImMin(ImMin(ImMin(P11,P12),P21),P22), ImMax(ImMax(ImMax(P11,P12),P21),P22)); @@ -673,8 +699,8 @@ struct ShadedRenderer { DrawList._IdxWritePtr[1] = (ImDrawIdx)(DrawList._VtxCurrentIdx + 1 + intersect); DrawList._IdxWritePtr[2] = (ImDrawIdx)(DrawList._VtxCurrentIdx + 3); DrawList._IdxWritePtr[3] = (ImDrawIdx)(DrawList._VtxCurrentIdx + 1); - DrawList._IdxWritePtr[4] = (ImDrawIdx)(DrawList._VtxCurrentIdx + 3 - intersect); - DrawList._IdxWritePtr[5] = (ImDrawIdx)(DrawList._VtxCurrentIdx + 4); + DrawList._IdxWritePtr[4] = (ImDrawIdx)(DrawList._VtxCurrentIdx + 4); + DrawList._IdxWritePtr[5] = (ImDrawIdx)(DrawList._VtxCurrentIdx + 3 - intersect); DrawList._IdxWritePtr += 6; DrawList._VtxCurrentIdx += 5; P11 = P21; @@ -692,15 +718,9 @@ struct ShadedRenderer { static const int VtxConsumed = 5; }; -// Stupid way of calculating maximum index size of ImDrawIdx without integer overflow issues -template -struct MaxIdx { static const unsigned int Value; }; -template <> const unsigned int MaxIdx::Value = 65535; -template <> const unsigned int MaxIdx::Value = 4294967295; - /// Renders primitive shapes in bulk as efficiently as possible. template -inline void RenderPrimitives(const Renderer& renderer, ImDrawList& DrawList, const ImRect& cull_rect) { +IMPLOT_INLINE void RenderPrimitives(const Renderer& renderer, ImDrawList& DrawList, const ImRect& cull_rect) { unsigned int prims = renderer.Prims; unsigned int prims_culled = 0; unsigned int idx = 0; @@ -737,7 +757,7 @@ inline void RenderPrimitives(const Renderer& renderer, ImDrawList& DrawList, con } template -inline void RenderLineStrip(const Getter& getter, const Transformer& transformer, ImDrawList& DrawList, float line_weight, ImU32 col) { +IMPLOT_INLINE void RenderLineStrip(const Getter& getter, const Transformer& transformer, ImDrawList& DrawList, float line_weight, ImU32 col) { ImPlotContext& gp = *GImPlot; if (ImHasFlag(gp.CurrentPlot->Flags, ImPlotFlags_AntiAliased) || gp.Style.AntiAliasedLines) { ImVec2 p1 = transformer(getter(0)); @@ -754,7 +774,7 @@ inline void RenderLineStrip(const Getter& getter, const Transformer& transformer } template -inline void RenderLineSegments(const Getter1& getter1, const Getter2& getter2, const Transformer& transformer, ImDrawList& DrawList, float line_weight, ImU32 col) { +IMPLOT_INLINE void RenderLineSegments(const Getter1& getter1, const Getter2& getter2, const Transformer& transformer, ImDrawList& DrawList, float line_weight, ImU32 col) { ImPlotContext& gp = *GImPlot; if (ImHasFlag(gp.CurrentPlot->Flags, ImPlotFlags_AntiAliased) || gp.Style.AntiAliasedLines) { int I = ImMin(getter1.Count, getter2.Count); @@ -771,7 +791,7 @@ inline void RenderLineSegments(const Getter1& getter1, const Getter2& getter2, c } template -inline void RenderStairs(const Getter& getter, const Transformer& transformer, ImDrawList& DrawList, float line_weight, ImU32 col) { +IMPLOT_INLINE void RenderStairs(const Getter& getter, const Transformer& transformer, ImDrawList& DrawList, float line_weight, ImU32 col) { ImPlotContext& gp = *GImPlot; if (ImHasFlag(gp.CurrentPlot->Flags, ImPlotFlags_AntiAliased) || gp.Style.AntiAliasedLines) { ImVec2 p1 = transformer(getter(0)); @@ -794,14 +814,14 @@ inline void RenderStairs(const Getter& getter, const Transformer& transformer, I // MARKER RENDERERS //----------------------------------------------------------------------------- -inline void TransformMarker(ImVec2* points, int n, const ImVec2& c, float s) { +IMPLOT_INLINE void TransformMarker(ImVec2* points, int n, const ImVec2& c, float s) { for (int i = 0; i < n; ++i) { points[i].x = c.x + points[i].x * s; points[i].y = c.y + points[i].y * s; } } -inline void RenderMarkerGeneral(ImDrawList& DrawList, ImVec2* points, int n, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) { +IMPLOT_INLINE void RenderMarkerGeneral(ImDrawList& DrawList, ImVec2* points, int n, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) { TransformMarker(points, n, c, s); if (fill) DrawList.AddConvexPolyFilled(points, n, col_fill); @@ -811,7 +831,7 @@ inline void RenderMarkerGeneral(ImDrawList& DrawList, ImVec2* points, int n, con } } -inline void RenderMarkerCircle(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) { +IMPLOT_INLINE void RenderMarkerCircle(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) { ImVec2 marker[10] = {ImVec2(1.0f, 0.0f), ImVec2(0.809017f, 0.58778524f), ImVec2(0.30901697f, 0.95105654f), @@ -825,37 +845,37 @@ inline void RenderMarkerCircle(ImDrawList& DrawList, const ImVec2& c, float s, b RenderMarkerGeneral(DrawList, marker, 10, c, s, outline, col_outline, fill, col_fill, weight); } -inline void RenderMarkerDiamond(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) { +IMPLOT_INLINE void RenderMarkerDiamond(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) { ImVec2 marker[4] = {ImVec2(1, 0), ImVec2(0, -1), ImVec2(-1, 0), ImVec2(0, 1)}; RenderMarkerGeneral(DrawList, marker, 4, c, s, outline, col_outline, fill, col_fill, weight); } -inline void RenderMarkerSquare(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) { +IMPLOT_INLINE void RenderMarkerSquare(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) { ImVec2 marker[4] = {ImVec2(SQRT_1_2,SQRT_1_2),ImVec2(SQRT_1_2,-SQRT_1_2),ImVec2(-SQRT_1_2,-SQRT_1_2),ImVec2(-SQRT_1_2,SQRT_1_2)}; RenderMarkerGeneral(DrawList, marker, 4, c, s, outline, col_outline, fill, col_fill, weight); } -inline void RenderMarkerUp(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) { +IMPLOT_INLINE void RenderMarkerUp(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) { ImVec2 marker[3] = {ImVec2(SQRT_3_2,0.5f),ImVec2(0,-1),ImVec2(-SQRT_3_2,0.5f)}; RenderMarkerGeneral(DrawList, marker, 3, c, s, outline, col_outline, fill, col_fill, weight); } -inline void RenderMarkerDown(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) { +IMPLOT_INLINE void RenderMarkerDown(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) { ImVec2 marker[3] = {ImVec2(SQRT_3_2,-0.5f),ImVec2(0,1),ImVec2(-SQRT_3_2,-0.5f)}; RenderMarkerGeneral(DrawList, marker, 3, c, s, outline, col_outline, fill, col_fill, weight); } -inline void RenderMarkerLeft(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) { +IMPLOT_INLINE void RenderMarkerLeft(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) { ImVec2 marker[3] = {ImVec2(-1,0), ImVec2(0.5, SQRT_3_2), ImVec2(0.5, -SQRT_3_2)}; RenderMarkerGeneral(DrawList, marker, 3, c, s, outline, col_outline, fill, col_fill, weight); } -inline void RenderMarkerRight(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) { +IMPLOT_INLINE void RenderMarkerRight(ImDrawList& DrawList, const ImVec2& c, float s, bool outline, ImU32 col_outline, bool fill, ImU32 col_fill, float weight) { ImVec2 marker[3] = {ImVec2(1,0), ImVec2(-0.5, SQRT_3_2), ImVec2(-0.5, -SQRT_3_2)}; RenderMarkerGeneral(DrawList, marker, 3, c, s, outline, col_outline, fill, col_fill, weight); } -inline void RenderMarkerAsterisk(ImDrawList& DrawList, const ImVec2& c, float s, bool /*outline*/, ImU32 col_outline, bool /*fill*/, ImU32 /*col_fill*/, float weight) { +IMPLOT_INLINE void RenderMarkerAsterisk(ImDrawList& DrawList, const ImVec2& c, float s, bool /*outline*/, ImU32 col_outline, bool /*fill*/, ImU32 /*col_fill*/, float weight) { ImVec2 marker[6] = {ImVec2(SQRT_3_2, 0.5f), ImVec2(0, -1), ImVec2(-SQRT_3_2, 0.5f), ImVec2(SQRT_3_2, -0.5f), ImVec2(0, 1), ImVec2(-SQRT_3_2, -0.5f)}; TransformMarker(marker, 6, c, s); DrawList.AddLine(marker[0], marker[5], col_outline, weight); @@ -863,14 +883,14 @@ inline void RenderMarkerAsterisk(ImDrawList& DrawList, const ImVec2& c, float s, DrawList.AddLine(marker[2], marker[3], col_outline, weight); } -inline void RenderMarkerPlus(ImDrawList& DrawList, const ImVec2& c, float s, bool /*outline*/, ImU32 col_outline, bool /*fill*/, ImU32 /*col_fill*/, float weight) { +IMPLOT_INLINE void RenderMarkerPlus(ImDrawList& DrawList, const ImVec2& c, float s, bool /*outline*/, ImU32 col_outline, bool /*fill*/, ImU32 /*col_fill*/, float weight) { ImVec2 marker[4] = {ImVec2(1, 0), ImVec2(0, -1), ImVec2(-1, 0), ImVec2(0, 1)}; TransformMarker(marker, 4, c, s); DrawList.AddLine(marker[0], marker[2], col_outline, weight); DrawList.AddLine(marker[1], marker[3], col_outline, weight); } -inline void RenderMarkerCross(ImDrawList& DrawList, const ImVec2& c, float s, bool /*outline*/, ImU32 col_outline, bool /*fill*/, ImU32 /*col_fill*/, float weight) { +IMPLOT_INLINE void RenderMarkerCross(ImDrawList& DrawList, const ImVec2& c, float s, bool /*outline*/, ImU32 col_outline, bool /*fill*/, ImU32 /*col_fill*/, float weight) { ImVec2 marker[4] = {ImVec2(SQRT_1_2,SQRT_1_2),ImVec2(SQRT_1_2,-SQRT_1_2),ImVec2(-SQRT_1_2,-SQRT_1_2),ImVec2(-SQRT_1_2,SQRT_1_2)}; TransformMarker(marker, 4, c, s); DrawList.AddLine(marker[0], marker[2], col_outline, weight); @@ -878,7 +898,7 @@ inline void RenderMarkerCross(ImDrawList& DrawList, const ImVec2& c, float s, bo } template -inline void RenderMarkers(Getter getter, Transformer transformer, ImDrawList& DrawList, ImPlotMarker marker, float size, bool rend_mk_line, ImU32 col_mk_line, float weight, bool rend_mk_fill, ImU32 col_mk_fill) { +IMPLOT_INLINE void RenderMarkers(Getter getter, Transformer transformer, ImDrawList& DrawList, ImPlotMarker marker, float size, bool rend_mk_line, ImU32 col_mk_line, float weight, bool rend_mk_fill, ImU32 col_mk_fill) { static void (*marker_table[ImPlotMarker_COUNT])(ImDrawList&, const ImVec2&, float s, bool, ImU32, bool, ImU32, float) = { RenderMarkerCircle, RenderMarkerSquare, @@ -905,7 +925,7 @@ inline void RenderMarkers(Getter getter, Transformer transformer, ImDrawList& Dr //----------------------------------------------------------------------------- template -inline void PlotLineEx(const char* label_id, const Getter& getter) { +IMPLOT_INLINE void PlotLineEx(const char* label_id, const Getter& getter) { if (BeginItem(label_id, ImPlotCol_Line)) { if (FitThisFrame()) { for (int i = 0; i < getter.Count; ++i) { @@ -926,8 +946,9 @@ inline void PlotLineEx(const char* label_id, const Getter& getter) { } // render markers if (s.Marker != ImPlotMarker_None) { - PopPlotClipRect(); - PushPlotClipRect(s.MarkerSize); + // uncomment lines below to render markers over plot rect border + // PopPlotClipRect(); + // PushPlotClipRect(s.MarkerSize); const ImU32 col_line = ImGui::GetColorU32(s.Colors[ImPlotCol_MarkerOutline]); const ImU32 col_fill = ImGui::GetColorU32(s.Colors[ImPlotCol_MarkerFill]); switch (GetCurrentScale()) { @@ -941,9 +962,10 @@ inline void PlotLineEx(const char* label_id, const Getter& getter) { } } + template void PlotLine(const char* label_id, const T* values, int count, double xscale, double x0, int offset, int stride) { - GetterYs getter(values,count,xscale,x0,offset,stride); + GetterXY> getter(GetterLin(xscale,x0),GetterIdx(values,count,offset,stride),count); PlotLineEx(label_id, getter); } @@ -960,7 +982,7 @@ template IMPLOT_API void PlotLine(const char* label_id, const double* va template void PlotLine(const char* label_id, const T* xs, const T* ys, int count, int offset, int stride) { - GetterXsYs getter(xs,ys,count,offset,stride); + GetterXY,GetterIdx> getter(GetterIdx(xs,count,offset,stride),GetterIdx(ys,count,offset,stride),count); return PlotLineEx(label_id, getter); } @@ -976,8 +998,8 @@ template IMPLOT_API void PlotLine(const char* label_id, const float* xs, template IMPLOT_API void PlotLine(const char* label_id, const double* xs, const double* ys, int count, int offset, int stride); // custom -void PlotLineG(const char* label_id, ImPlotPoint (*getter_func)(void* data, int idx), void* data, int count, int offset) { - GetterFuncPtr getter(getter_func,data, count, offset); +void PlotLineG(const char* label_id, ImPlotGetter getter_func, void* data, int count) { + GetterFuncPtr getter(getter_func,data, count); return PlotLineEx(label_id, getter); } @@ -986,7 +1008,7 @@ void PlotLineG(const char* label_id, ImPlotPoint (*getter_func)(void* data, int //----------------------------------------------------------------------------- template -inline void PlotScatterEx(const char* label_id, const Getter& getter) { +IMPLOT_INLINE void PlotScatterEx(const char* label_id, const Getter& getter) { if (BeginItem(label_id, ImPlotCol_MarkerOutline)) { if (FitThisFrame()) { for (int i = 0; i < getter.Count; ++i) { @@ -999,8 +1021,9 @@ inline void PlotScatterEx(const char* label_id, const Getter& getter) { // render markers ImPlotMarker marker = s.Marker == ImPlotMarker_None ? ImPlotMarker_Circle : s.Marker; if (marker != ImPlotMarker_None) { - PopPlotClipRect(); - PushPlotClipRect(s.MarkerSize); + // uncomment lines below to render markers over plot rect border + // PopPlotClipRect(); + // PushPlotClipRect(s.MarkerSize); const ImU32 col_line = ImGui::GetColorU32(s.Colors[ImPlotCol_MarkerOutline]); const ImU32 col_fill = ImGui::GetColorU32(s.Colors[ImPlotCol_MarkerFill]); switch (GetCurrentScale()) { @@ -1016,7 +1039,7 @@ inline void PlotScatterEx(const char* label_id, const Getter& getter) { template void PlotScatter(const char* label_id, const T* values, int count, double xscale, double x0, int offset, int stride) { - GetterYs getter(values,count,xscale,x0,offset,stride); + GetterXY> getter(GetterLin(xscale,x0),GetterIdx(values,count,offset,stride),count); PlotScatterEx(label_id, getter); } @@ -1033,7 +1056,7 @@ template IMPLOT_API void PlotScatter(const char* label_id, const double* template void PlotScatter(const char* label_id, const T* xs, const T* ys, int count, int offset, int stride) { - GetterXsYs getter(xs,ys,count,offset,stride); + GetterXY,GetterIdx> getter(GetterIdx(xs,count,offset,stride),GetterIdx(ys,count,offset,stride),count); return PlotScatterEx(label_id, getter); } @@ -1049,8 +1072,8 @@ template IMPLOT_API void PlotScatter(const char* label_id, const float* x template IMPLOT_API void PlotScatter(const char* label_id, const double* xs, const double* ys, int count, int offset, int stride); // custom -void PlotScatterG(const char* label_id, ImPlotPoint (*getter_func)(void* data, int idx), void* data, int count, int offset) { - GetterFuncPtr getter(getter_func,data, count, offset); +void PlotScatterG(const char* label_id, ImPlotGetter getter_func, void* data, int count) { + GetterFuncPtr getter(getter_func,data, count); return PlotScatterEx(label_id, getter); } @@ -1059,7 +1082,7 @@ void PlotScatterG(const char* label_id, ImPlotPoint (*getter_func)(void* data, i //----------------------------------------------------------------------------- template -inline void PlotStairsEx(const char* label_id, const Getter& getter) { +IMPLOT_INLINE void PlotStairsEx(const char* label_id, const Getter& getter) { if (BeginItem(label_id, ImPlotCol_Line)) { if (FitThisFrame()) { for (int i = 0; i < getter.Count; ++i) { @@ -1097,7 +1120,7 @@ inline void PlotStairsEx(const char* label_id, const Getter& getter) { template void PlotStairs(const char* label_id, const T* values, int count, double xscale, double x0, int offset, int stride) { - GetterYs getter(values,count,xscale,x0,offset,stride); + GetterXY> getter(GetterLin(xscale,x0),GetterIdx(values,count,offset,stride),count); PlotStairsEx(label_id, getter); } @@ -1114,7 +1137,7 @@ template IMPLOT_API void PlotStairs(const char* label_id, const double* template void PlotStairs(const char* label_id, const T* xs, const T* ys, int count, int offset, int stride) { - GetterXsYs getter(xs,ys,count,offset,stride); + GetterXY,GetterIdx> getter(GetterIdx(xs,count,offset,stride),GetterIdx(ys,count,offset,stride),count); return PlotStairsEx(label_id, getter); } @@ -1130,8 +1153,8 @@ template IMPLOT_API void PlotStairs(const char* label_id, const float* xs template IMPLOT_API void PlotStairs(const char* label_id, const double* xs, const double* ys, int count, int offset, int stride); // custom -void PlotStairsG(const char* label_id, ImPlotPoint (*getter_func)(void* data, int idx), void* data, int count, int offset) { - GetterFuncPtr getter(getter_func,data, count, offset); +void PlotStairsG(const char* label_id, ImPlotGetter getter_func, void* data, int count) { + GetterFuncPtr getter(getter_func,data, count); return PlotStairsEx(label_id, getter); } @@ -1140,7 +1163,7 @@ void PlotStairsG(const char* label_id, ImPlotPoint (*getter_func)(void* data, in //----------------------------------------------------------------------------- template -inline void PlotShadedEx(const char* label_id, const Getter1& getter1, const Getter2& getter2, bool fit2) { +IMPLOT_INLINE void PlotShadedEx(const char* label_id, const Getter1& getter1, const Getter2& getter2, bool fit2) { if (BeginItem(label_id, ImPlotCol_Fill)) { if (FitThisFrame()) { for (int i = 0; i < getter1.Count; ++i) @@ -1168,16 +1191,16 @@ inline void PlotShadedEx(const char* label_id, const Getter1& getter1, const Get template void PlotShaded(const char* label_id, const T* values, int count, double y_ref, double xscale, double x0, int offset, int stride) { bool fit2 = true; - if (y_ref == -HUGE_VAL) { + if (!(y_ref > -DBL_MAX)) { // filters out nans too fit2 = false; - y_ref = GetPlotLimits().Y.Min; + y_ref = GetPlotLimits(IMPLOT_AUTO,IMPLOT_AUTO).Y.Min; } - if (y_ref == HUGE_VAL) { + if (!(y_ref < DBL_MAX)) { // filters out nans too fit2 = false; - y_ref = GetPlotLimits().Y.Max; + y_ref = GetPlotLimits(IMPLOT_AUTO,IMPLOT_AUTO).Y.Max; } - GetterYs getter1(values,count,xscale,x0,offset,stride); - GetterYRef getter2(y_ref,count,xscale,x0); + GetterXY> getter1(GetterLin(xscale,x0),GetterIdx(values,count,offset,stride),count); + GetterXY getter2(GetterLin(xscale,x0),GetterRef(y_ref),count); PlotShadedEx(label_id, getter1, getter2, fit2); } @@ -1195,16 +1218,16 @@ template IMPLOT_API void PlotShaded(const char* label_id, const double* template void PlotShaded(const char* label_id, const T* xs, const T* ys, int count, double y_ref, int offset, int stride) { bool fit2 = true; - if (y_ref == -HUGE_VAL) { + if (!(y_ref > -DBL_MAX)) { // filters out nans too fit2 = false; - y_ref = GetPlotLimits().Y.Min; + y_ref = GetPlotLimits(IMPLOT_AUTO,IMPLOT_AUTO).Y.Min; } - if (y_ref == HUGE_VAL) { + if (!(y_ref < DBL_MAX)) { // filters out nans too fit2 = false; - y_ref = GetPlotLimits().Y.Max; + y_ref = GetPlotLimits(IMPLOT_AUTO,IMPLOT_AUTO).Y.Max; } - GetterXsYs getter1(xs, ys, count, offset, stride); - GetterXsYRef getter2(xs, y_ref, count, offset, stride); + GetterXY,GetterIdx> getter1(GetterIdx(xs,count,offset,stride),GetterIdx(ys,count,offset,stride),count); + GetterXY,GetterRef> getter2(GetterIdx(xs,count,offset,stride),GetterRef(y_ref),count); PlotShadedEx(label_id, getter1, getter2, fit2); } @@ -1221,8 +1244,8 @@ template IMPLOT_API void PlotShaded(const char* label_id, const double* template void PlotShaded(const char* label_id, const T* xs, const T* ys1, const T* ys2, int count, int offset, int stride) { - GetterXsYs getter1(xs, ys1, count, offset, stride); - GetterXsYs getter2(xs, ys2, count, offset, stride); + GetterXY,GetterIdx> getter1(GetterIdx(xs,count,offset,stride),GetterIdx(ys1,count,offset,stride),count); + GetterXY,GetterIdx> getter2(GetterIdx(xs,count,offset,stride),GetterIdx(ys2,count,offset,stride),count); PlotShadedEx(label_id, getter1, getter2, true); } @@ -1238,9 +1261,9 @@ template IMPLOT_API void PlotShaded(const char* label_id, const float* xs template IMPLOT_API void PlotShaded(const char* label_id, const double* xs, const double* ys1, const double* ys2, int count, int offset, int stride); // custom -void PlotShadedG(const char* label_id, ImPlotPoint (*g1)(void* data, int idx), void* data1, ImPlotPoint (*g2)(void* data, int idx), void* data2, int count, int offset) { - GetterFuncPtr getter1(g1, data1, count, offset); - GetterFuncPtr getter2(g2, data2, count, offset); +void PlotShadedG(const char* label_id, ImPlotGetter getter_func1, void* data1, ImPlotGetter getter_func2, void* data2, int count) { + GetterFuncPtr getter1(getter_func1, data1, count); + GetterFuncPtr getter2(getter_func2, data2, count); PlotShadedEx(label_id, getter1, getter2, true); } @@ -1250,15 +1273,16 @@ void PlotShadedG(const char* label_id, ImPlotPoint (*g1)(void* data, int idx), v // TODO: Migrate to RenderPrimitives -template -void PlotBarsEx(const char* label_id, const Getter& getter, double width) { +template +void PlotBarsEx(const char* label_id, const Getter1& getter1, const Getter2 getter2, double width) { if (BeginItem(label_id, ImPlotCol_Fill)) { const double half_width = width / 2; if (FitThisFrame()) { - for (int i = 0; i < getter.Count; ++i) { - ImPlotPoint p = getter(i); - FitPoint(ImPlotPoint(p.x - half_width, p.y)); - FitPoint(ImPlotPoint(p.x + half_width, 0)); + for (int i = 0; i < getter1.Count; ++i) { + ImPlotPoint p1 = getter1(i); + ImPlotPoint p2 = getter2(i); + FitPoint(ImPlotPoint(p1.x - half_width, p1.y)); + FitPoint(ImPlotPoint(p2.x + half_width, p2.y)); } } const ImPlotNextItemData& s = GetItemData(); @@ -1268,12 +1292,20 @@ void PlotBarsEx(const char* label_id, const Getter& getter, double width) { bool rend_line = s.RenderLine; if (s.RenderFill && col_line == col_fill) rend_line = false; - for (int i = 0; i < getter.Count; ++i) { - ImPlotPoint p = getter(i); - if (p.y == 0) + for (int i = 0; i < getter1.Count; ++i) { + ImPlotPoint p1 = getter1(i); + ImPlotPoint p2 = getter2(i); + if (p1.y == p2.y) continue; - ImVec2 a = PlotToPixels(p.x - half_width, p.y); - ImVec2 b = PlotToPixels(p.x + half_width, 0); + ImVec2 a = PlotToPixels(p1.x - half_width, p1.y,IMPLOT_AUTO,IMPLOT_AUTO); + ImVec2 b = PlotToPixels(p2.x + half_width, p2.y,IMPLOT_AUTO,IMPLOT_AUTO); + float width_px = ImAbs(a.x-b.x); + if (width_px < 1.0f) { + a.x += a.x > b.x ? (1-width_px) / 2 : (width_px-1) / 2; + b.x += b.x > a.x ? (1-width_px) / 2 : (width_px-1) / 2; + } + // a.x = IM_ROUND(a.x); + // b.x = IM_ROUND(b.x); if (s.RenderFill) DrawList.AddRectFilled(a, b, col_fill); if (rend_line) @@ -1285,8 +1317,9 @@ void PlotBarsEx(const char* label_id, const Getter& getter, double width) { template void PlotBars(const char* label_id, const T* values, int count, double width, double shift, int offset, int stride) { - GetterBarV getter(values,shift,count,offset,stride); - PlotBarsEx(label_id, getter, width); + GetterXY> getter1(GetterLin(1.0,shift),GetterIdx(values,count,offset,stride),count); + GetterXY getter2(GetterLin(1.0,shift),GetterRef(0),count); + PlotBarsEx(label_id, getter1, getter2, width); } template IMPLOT_API void PlotBars(const char* label_id, const ImS8* values, int count, double width, double shift, int offset, int stride); @@ -1302,8 +1335,9 @@ template IMPLOT_API void PlotBars(const char* label_id, const double* va template void PlotBars(const char* label_id, const T* xs, const T* ys, int count, double width, int offset, int stride) { - GetterXsYs getter(xs,ys,count,offset,stride); - PlotBarsEx(label_id, getter, width); + GetterXY,GetterIdx> getter1(GetterIdx(xs,count,offset,stride),GetterIdx(ys,count,offset,stride),count); + GetterXY,GetterRef> getter2(GetterIdx(xs,count,offset,stride),GetterRef(0),count); + PlotBarsEx(label_id, getter1, getter2, width); } template IMPLOT_API void PlotBars(const char* label_id, const ImS8* xs, const ImS8* ys, int count, double width, int offset, int stride); @@ -1318,9 +1352,10 @@ template IMPLOT_API void PlotBars(const char* label_id, const float* xs, template IMPLOT_API void PlotBars(const char* label_id, const double* xs, const double* ys, int count, double width, int offset, int stride); // custom -void PlotBarsG(const char* label_id, ImPlotPoint (*getter_func)(void* data, int idx), void* data, int count, double width, int offset) { - GetterFuncPtr getter(getter_func, data, count, offset); - PlotBarsEx(label_id, getter, width); +void PlotBarsG(const char* label_id, ImPlotGetter getter_func, void* data, int count, double width) { + GetterFuncPtr getter1(getter_func, data, count); + GetterOverrideY getter2(getter1,0); + PlotBarsEx(label_id, getter1, getter2, width); } //----------------------------------------------------------------------------- @@ -1329,15 +1364,16 @@ void PlotBarsG(const char* label_id, ImPlotPoint (*getter_func)(void* data, int // TODO: Migrate to RenderPrimitives -template -void PlotBarsHEx(const char* label_id, const Getter& getter, THeight height) { +template +void PlotBarsHEx(const char* label_id, const Getter1& getter1, const Getter2& getter2, double height) { if (BeginItem(label_id, ImPlotCol_Fill)) { - const THeight half_height = height / 2; + const double half_height = height / 2; if (FitThisFrame()) { - for (int i = 0; i < getter.Count; ++i) { - ImPlotPoint p = getter(i); - FitPoint(ImPlotPoint(0, p.y - half_height)); - FitPoint(ImPlotPoint(p.x, p.y + half_height)); + for (int i = 0; i < getter1.Count; ++i) { + ImPlotPoint p1 = getter1(i); + ImPlotPoint p2 = getter2(i); + FitPoint(ImPlotPoint(p1.x, p1.y - half_height)); + FitPoint(ImPlotPoint(p2.x, p2.y + half_height)); } } const ImPlotNextItemData& s = GetItemData(); @@ -1347,12 +1383,13 @@ void PlotBarsHEx(const char* label_id, const Getter& getter, THeight height) { bool rend_line = s.RenderLine; if (s.RenderFill && col_line == col_fill) rend_line = false; - for (int i = 0; i < getter.Count; ++i) { - ImPlotPoint p = getter(i); - if (p.x == 0) + for (int i = 0; i < getter1.Count; ++i) { + ImPlotPoint p1 = getter1(i); + ImPlotPoint p2 = getter2(i); + if (p1.x == p2.x) continue; - ImVec2 a = PlotToPixels(0, p.y - half_height); - ImVec2 b = PlotToPixels(p.x, p.y + half_height); + ImVec2 a = PlotToPixels(p1.x, p1.y - half_height,IMPLOT_AUTO,IMPLOT_AUTO); + ImVec2 b = PlotToPixels(p2.x, p2.y + half_height,IMPLOT_AUTO,IMPLOT_AUTO); if (s.RenderFill) DrawList.AddRectFilled(a, b, col_fill); if (rend_line) @@ -1364,8 +1401,9 @@ void PlotBarsHEx(const char* label_id, const Getter& getter, THeight height) { template void PlotBarsH(const char* label_id, const T* values, int count, double height, double shift, int offset, int stride) { - GetterBarH getter(values,shift,count,offset,stride); - PlotBarsHEx(label_id, getter, height); + GetterXY,GetterLin> getter1(GetterIdx(values,count,offset,stride),GetterLin(1.0,shift),count); + GetterXY getter2(GetterRef(0),GetterLin(1.0,shift),count); + PlotBarsHEx(label_id, getter1, getter2, height); } template IMPLOT_API void PlotBarsH(const char* label_id, const ImS8* values, int count, double height, double shift, int offset, int stride); @@ -1381,8 +1419,9 @@ template IMPLOT_API void PlotBarsH(const char* label_id, const double* v template void PlotBarsH(const char* label_id, const T* xs, const T* ys, int count, double height, int offset, int stride) { - GetterXsYs getter(xs,ys,count,offset,stride); - PlotBarsHEx(label_id, getter, height); + GetterXY,GetterIdx> getter1(GetterIdx(xs,count,offset,stride),GetterIdx(ys,count,offset,stride),count); + GetterXY> getter2(GetterRef(0),GetterIdx(ys,count,offset,stride),count); + PlotBarsHEx(label_id, getter1, getter2, height); } template IMPLOT_API void PlotBarsH(const char* label_id, const ImS8* xs, const ImS8* ys, int count, double height, int offset, int stride); @@ -1397,11 +1436,122 @@ template IMPLOT_API void PlotBarsH(const char* label_id, const float* xs, template IMPLOT_API void PlotBarsH(const char* label_id, const double* xs, const double* ys, int count, double height, int offset, int stride); // custom -void PlotBarsHG(const char* label_id, ImPlotPoint (*getter_func)(void* data, int idx), void* data, int count, double height, int offset) { - GetterFuncPtr getter(getter_func, data, count, offset); - PlotBarsHEx(label_id, getter, height); +void PlotBarsHG(const char* label_id, ImPlotGetter getter_func, void* data, int count, double height) { + GetterFuncPtr getter1(getter_func, data, count); + GetterOverrideX getter2(getter1,0); + PlotBarsHEx(label_id, getter1, getter2, height); } +//----------------------------------------------------------------------------- +// PLOT BAR GROUPS +//----------------------------------------------------------------------------- + +template +void PlotBarGroups(const char* const label_ids[], const T* values, int items, int groups, double width, double shift, ImPlotBarGroupsFlags flags) { + if (ImHasFlag(flags, ImPlotBarGroupsFlags_Stacked)) { + SetupLock(); + GImPlot->TempDouble1.resize(4*groups); + double* temp = GImPlot->TempDouble1.Data; + double* neg = &temp[0]; + double* pos = &temp[groups]; + double* curr_min = &temp[groups*2]; + double* curr_max = &temp[groups*3]; + for (int g = 0; g < groups*2; ++g) + temp[g] = 0; + for (int i = 0; i < items; ++i) { + if (!IsItemHidden(label_ids[i])) { + for (int g = 0; g < groups; ++g) { + double v = (double)values[i*groups+g]; + if (v > 0) { + curr_min[g] = pos[g]; + curr_max[g] = curr_min[g] + v; + pos[g] += v; + } + else { + curr_max[g] = neg[g]; + curr_min[g] = curr_max[g] + v; + neg[g] += v; + } + } + } + GetterXY> getter1(GetterLin(1.0,shift),GetterIdx(curr_min,groups),groups); + GetterXY> getter2(GetterLin(1.0,shift),GetterIdx(curr_max,groups),groups); + PlotBarsEx(label_ids[i],getter1,getter2,width); + } + } + else { + const double subwidth = width / items; + for (int i = 0; i < items; ++i) { + const double subshift = (i+0.5)*subwidth - width/2; + PlotBars(label_ids[i],&values[i*groups],groups,subwidth,subshift+shift); + } + } +} + +template IMPLOT_API void PlotBarGroups(const char* const label_ids[], const ImS8* values, int items, int groups, double width, double shift, ImPlotBarGroupsFlags flags); +template IMPLOT_API void PlotBarGroups(const char* const label_ids[], const ImU8* values, int items, int groups, double width, double shift, ImPlotBarGroupsFlags flags); +template IMPLOT_API void PlotBarGroups(const char* const label_ids[], const ImS16* values, int items, int groups, double width, double shift, ImPlotBarGroupsFlags flags); +template IMPLOT_API void PlotBarGroups(const char* const label_ids[], const ImU16* values, int items, int groups, double width, double shift, ImPlotBarGroupsFlags flags); +template IMPLOT_API void PlotBarGroups(const char* const label_ids[], const ImS32* values, int items, int groups, double width, double shift, ImPlotBarGroupsFlags flags); +template IMPLOT_API void PlotBarGroups(const char* const label_ids[], const ImU32* values, int items, int groups, double width, double shift, ImPlotBarGroupsFlags flags); +template IMPLOT_API void PlotBarGroups(const char* const label_ids[], const ImS64* values, int items, int groups, double width, double shift, ImPlotBarGroupsFlags flags); +template IMPLOT_API void PlotBarGroups(const char* const label_ids[], const ImU64* values, int items, int groups, double width, double shift, ImPlotBarGroupsFlags flags); +template IMPLOT_API void PlotBarGroups(const char* const label_ids[], const float* values, int items, int groups, double width, double shift, ImPlotBarGroupsFlags flags); +template IMPLOT_API void PlotBarGroups(const char* const label_ids[], const double* values, int items, int groups, double width, double shift, ImPlotBarGroupsFlags flags); + +template +void PlotBarGroupsH(const char* const label_ids[], const T* values, int items, int groups, double height, double shift, ImPlotBarGroupsFlags flags) { + if (ImHasFlag(flags, ImPlotBarGroupsFlags_Stacked)) { + SetupLock(); + GImPlot->TempDouble1.resize(4*groups); + double* temp = GImPlot->TempDouble1.Data; + double* neg = &temp[0]; + double* pos = &temp[groups]; + double* curr_min = &temp[groups*2]; + double* curr_max = &temp[groups*3]; + for (int g = 0; g < groups*2; ++g) + temp[g] = 0; + for (int i = 0; i < items; ++i) { + if (!IsItemHidden(label_ids[i])) { + for (int g = 0; g < groups; ++g) { + double v = (double)values[i*groups+g]; + if (v > 0) { + curr_min[g] = pos[g]; + curr_max[g] = curr_min[g] + v; + pos[g] += v; + } + else { + curr_max[g] = neg[g]; + curr_min[g] = curr_max[g] + v; + neg[g] += v; + } + } + } + GetterXY,GetterLin> getter1(GetterIdx(curr_min,groups),GetterLin(1.0,shift),groups); + GetterXY,GetterLin> getter2(GetterIdx(curr_max,groups),GetterLin(1.0,shift),groups); + PlotBarsHEx(label_ids[i],getter1,getter2,height); + } + } + else { + const double subheight = height / items; + for (int i = 0; i < items; ++i) { + const double subshift = (i+0.5)*subheight - height/2; + PlotBarsH(label_ids[i],&values[i*groups],groups,subheight,subshift+shift); + } + } +} + +template IMPLOT_API void PlotBarGroupsH(const char* const label_ids[], const ImS8* values, int items, int groups, double width, double shift, ImPlotBarGroupsFlags flags); +template IMPLOT_API void PlotBarGroupsH(const char* const label_ids[], const ImU8* values, int items, int groups, double width, double shift, ImPlotBarGroupsFlags flags); +template IMPLOT_API void PlotBarGroupsH(const char* const label_ids[], const ImS16* values, int items, int groups, double width, double shift, ImPlotBarGroupsFlags flags); +template IMPLOT_API void PlotBarGroupsH(const char* const label_ids[], const ImU16* values, int items, int groups, double width, double shift, ImPlotBarGroupsFlags flags); +template IMPLOT_API void PlotBarGroupsH(const char* const label_ids[], const ImS32* values, int items, int groups, double width, double shift, ImPlotBarGroupsFlags flags); +template IMPLOT_API void PlotBarGroupsH(const char* const label_ids[], const ImU32* values, int items, int groups, double width, double shift, ImPlotBarGroupsFlags flags); +template IMPLOT_API void PlotBarGroupsH(const char* const label_ids[], const ImS64* values, int items, int groups, double width, double shift, ImPlotBarGroupsFlags flags); +template IMPLOT_API void PlotBarGroupsH(const char* const label_ids[], const ImU64* values, int items, int groups, double width, double shift, ImPlotBarGroupsFlags flags); +template IMPLOT_API void PlotBarGroupsH(const char* const label_ids[], const float* values, int items, int groups, double width, double shift, ImPlotBarGroupsFlags flags); +template IMPLOT_API void PlotBarGroupsH(const char* const label_ids[], const double* values, int items, int groups, double width, double shift, ImPlotBarGroupsFlags flags); + //----------------------------------------------------------------------------- // PLOT ERROR BARS //----------------------------------------------------------------------------- @@ -1423,8 +1573,8 @@ void PlotErrorBarsEx(const char* label_id, const Getter& getter) { const float half_whisker = s.ErrorBarSize * 0.5f; for (int i = 0; i < getter.Count; ++i) { ImPlotPointError e = getter(i); - ImVec2 p1 = PlotToPixels(e.X, e.Y - e.Neg); - ImVec2 p2 = PlotToPixels(e.X, e.Y + e.Pos); + ImVec2 p1 = PlotToPixels(e.X, e.Y - e.Neg,IMPLOT_AUTO,IMPLOT_AUTO); + ImVec2 p2 = PlotToPixels(e.X, e.Y + e.Pos,IMPLOT_AUTO,IMPLOT_AUTO); DrawList.AddLine(p1,p2,col, s.ErrorBarWeight); if (rend_whisker) { DrawList.AddLine(p1 - ImVec2(half_whisker, 0), p1 + ImVec2(half_whisker, 0), col, s.ErrorBarWeight); @@ -1490,8 +1640,8 @@ void PlotErrorBarsHEx(const char* label_id, const Getter& getter) { const float half_whisker = s.ErrorBarSize * 0.5f; for (int i = 0; i < getter.Count; ++i) { ImPlotPointError e = getter(i); - ImVec2 p1 = PlotToPixels(e.X - e.Neg, e.Y); - ImVec2 p2 = PlotToPixels(e.X + e.Pos, e.Y); + ImVec2 p1 = PlotToPixels(e.X - e.Neg, e.Y,IMPLOT_AUTO,IMPLOT_AUTO); + ImVec2 p2 = PlotToPixels(e.X + e.Pos, e.Y,IMPLOT_AUTO,IMPLOT_AUTO); DrawList.AddLine(p1, p2, col, s.ErrorBarWeight); if (rend_whisker) { DrawList.AddLine(p1 - ImVec2(0, half_whisker), p1 + ImVec2(0, half_whisker), col, s.ErrorBarWeight); @@ -1541,7 +1691,7 @@ template IMPLOT_API void PlotErrorBarsH(const char* label_id, const doub //----------------------------------------------------------------------------- template -inline void PlotStemsEx(const char* label_id, const GetterM& get_mark, const GetterB& get_base) { +IMPLOT_INLINE void PlotStemsEx(const char* label_id, const GetterM& get_mark, const GetterB& get_base) { if (BeginItem(label_id, ImPlotCol_Line)) { if (FitThisFrame()) { for (int i = 0; i < get_base.Count; ++i) { @@ -1581,8 +1731,8 @@ inline void PlotStemsEx(const char* label_id, const GetterM& get_mark, const Get template void PlotStems(const char* label_id, const T* values, int count, double y_ref, double xscale, double x0, int offset, int stride) { - GetterYs get_mark(values,count,xscale,x0,offset,stride); - GetterYRef get_base(y_ref,count,xscale,x0); + GetterXY> get_mark(GetterLin(xscale,x0),GetterIdx(values,count,offset,stride),count); + GetterXY get_base(GetterLin(xscale,x0),GetterRef(y_ref),count); PlotStemsEx(label_id, get_mark, get_base); } @@ -1599,8 +1749,8 @@ template IMPLOT_API void PlotStems(const char* label_id, const double* v template void PlotStems(const char* label_id, const T* xs, const T* ys, int count, double y_ref, int offset, int stride) { - GetterXsYs get_mark(xs,ys,count,offset,stride); - GetterXsYRef get_base(xs,y_ref,count,offset,stride); + GetterXY,GetterIdx> get_mark(GetterIdx(xs,count,offset,stride),GetterIdx(ys,count,offset,stride),count); + GetterXY,GetterRef> get_base(GetterIdx(xs,count,offset,stride),GetterRef(y_ref),count); PlotStemsEx(label_id, get_mark, get_base); } @@ -1622,9 +1772,9 @@ template IMPLOT_API void PlotStems(const char* label_id, const double* x template void PlotVLines(const char* label_id, const T* xs, int count, int offset, int stride) { if (BeginItem(label_id, ImPlotCol_Line)) { - const ImPlotLimits lims = GetPlotLimits(); - GetterXsYRef get_min(xs,lims.Y.Min,count,offset,stride); - GetterXsYRef get_max(xs,lims.Y.Max,count,offset,stride); + const ImPlotRect lims = GetPlotLimits(IMPLOT_AUTO,IMPLOT_AUTO); + GetterXY,GetterRef> get_min(GetterIdx(xs,count,offset,stride),GetterRef(lims.Y.Min),count); + GetterXY,GetterRef> get_max(GetterIdx(xs,count,offset,stride),GetterRef(lims.Y.Max),count); if (FitThisFrame()) { for (int i = 0; i < get_min.Count; ++i) FitPointX(get_min(i).x); @@ -1660,9 +1810,9 @@ template IMPLOT_API void PlotVLines(const char* label_id, const double* template void PlotHLines(const char* label_id, const T* ys, int count, int offset, int stride) { if (BeginItem(label_id, ImPlotCol_Line)) { - const ImPlotLimits lims = GetPlotLimits(); - GetterXRefYs get_min(lims.X.Min,ys,count,offset,stride); - GetterXRefYs get_max(lims.X.Max,ys,count,offset,stride); + const ImPlotRect lims = GetPlotLimits(IMPLOT_AUTO,IMPLOT_AUTO); + GetterXY> get_min(GetterRef(lims.X.Min),GetterIdx(ys,count,offset,stride),count); + GetterXY> get_max(GetterRef(lims.X.Max),GetterIdx(ys,count,offset,stride),count); if (FitThisFrame()) { for (int i = 0; i < get_min.Count; ++i) FitPointY(get_min(i).y); @@ -1698,15 +1848,15 @@ template IMPLOT_API void PlotHLines(const char* label_id, const double* // PLOT PIE CHART //----------------------------------------------------------------------------- -inline void RenderPieSlice(ImDrawList& DrawList, const ImPlotPoint& center, double radius, double a0, double a1, ImU32 col) { +IMPLOT_INLINE void RenderPieSlice(ImDrawList& DrawList, const ImPlotPoint& center, double radius, double a0, double a1, ImU32 col) { static const float resolution = 50 / (2 * IM_PI); static ImVec2 buffer[50]; - buffer[0] = PlotToPixels(center); + buffer[0] = PlotToPixels(center,IMPLOT_AUTO,IMPLOT_AUTO); int n = ImMax(3, (int)((a1 - a0) * resolution)); double da = (a1 - a0) / (n - 1); for (int i = 0; i < n; ++i) { double a = a0 + i * da; - buffer[i + 1] = PlotToPixels(center.x + radius * cos(a), center.y + radius * sin(a)); + buffer[i + 1] = PlotToPixels(center.x + radius * cos(a), center.y + radius * sin(a),IMPLOT_AUTO,IMPLOT_AUTO); } DrawList.AddConvexPolyFilled(buffer, n + 1, col); } @@ -1752,10 +1902,10 @@ void PlotPieChart(const char* const label_ids[], const T* values, int count, dou double percent = normalize ? (double)values[i] / sum : (double)values[i]; a1 = a0 + 2 * IM_PI * percent; if (item->Show) { - sprintf(buffer, fmt, (double)values[i]); + ImFormatString(buffer, 32, fmt, (double)values[i]); ImVec2 size = ImGui::CalcTextSize(buffer); double angle = a0 + (a1 - a0) * 0.5; - ImVec2 pos = PlotToPixels(center.x + 0.5 * radius * cos(angle), center.y + 0.5 * radius * sin(angle)); + ImVec2 pos = PlotToPixels(center.x + 0.5 * radius * cos(angle), center.y + 0.5 * radius * sin(angle),IMPLOT_AUTO,IMPLOT_AUTO); ImU32 col = CalcTextColor(ImGui::ColorConvertU32ToFloat4(item->Color)); DrawList.AddText(pos - size * 0.5f, col, buffer); } @@ -1787,12 +1937,12 @@ struct RectInfo { template struct RectRenderer { - inline RectRenderer(const TGetter& getter, const TTransformer& transformer) : + IMPLOT_INLINE RectRenderer(const TGetter& getter, const TTransformer& transformer) : Getter(getter), Transformer(transformer), Prims(Getter.Count) {} - inline bool operator()(ImDrawList& DrawList, const ImRect& cull_rect, const ImVec2& uv, int prim) const { + IMPLOT_INLINE bool operator()(ImDrawList& DrawList, const ImRect& cull_rect, const ImVec2& uv, int prim) const { RectInfo rect = Getter(prim); ImVec2 P1 = Transformer(rect.Min); ImVec2 P2 = Transformer(rect.Max); @@ -1849,7 +1999,7 @@ struct GetterHeatmap { HalfSize(Width*0.5, Height*0.5) { } - inline RectInfo operator()(int idx) const { + template IMPLOT_INLINE RectInfo operator()(I idx) const { double val = (double)Values[idx]; const int r = idx / Cols; const int c = idx % Cols; @@ -1906,7 +2056,7 @@ void RenderHeatmap(Transformer transformer, ImDrawList& DrawList, const T* value p.y = yref + ydir * (0.5*h + r*h); ImVec2 px = transformer(p); char buff[32]; - sprintf(buff, fmt, values[i]); + ImFormatString(buff, 32, fmt, values[i]); ImVec2 size = ImGui::CalcTextSize(buff); double t = ImClamp(ImRemap01((double)values[i], scale_min, scale_max),0.0,1.0); ImVec4 color = SampleColormap((float)t); @@ -1970,8 +2120,8 @@ double PlotHistogram(const char* label_id, const T* values, int count, int bins, else width = range.Size() / bins; - ImVector& bin_centers = GImPlot->Temp1; - ImVector& bin_counts = GImPlot->Temp2; + ImVector& bin_centers = GImPlot->TempDouble1; + ImVector& bin_counts = GImPlot->TempDouble2; bin_centers.resize(bins); bin_counts.resize(bins); int below = 0; @@ -2038,7 +2188,7 @@ template IMPLOT_API double PlotHistogram(const char* label_id, const dou //----------------------------------------------------------------------------- template -double PlotHistogram2D(const char* label_id, const T* xs, const T* ys, int count, int x_bins, int y_bins, bool density, ImPlotLimits range, bool outliers) { +double PlotHistogram2D(const char* label_id, const T* xs, const T* ys, int count, int x_bins, int y_bins, bool density, ImPlotRect range, bool outliers) { if (count <= 0 || x_bins == 0 || y_bins == 0) return 0; @@ -2068,7 +2218,7 @@ double PlotHistogram2D(const char* label_id, const T* xs, const T* ys, int count const int bins = x_bins * y_bins; - ImVector& bin_counts = GImPlot->Temp1; + ImVector& bin_counts = GImPlot->TempDouble1; bin_counts.resize(bins); for (int b = 0; b < bins; ++b) @@ -2111,16 +2261,16 @@ double PlotHistogram2D(const char* label_id, const T* xs, const T* ys, int count return max_count; } -template IMPLOT_API double PlotHistogram2D(const char* label_id, const ImS8* xs, const ImS8* ys, int count, int x_bins, int y_bins, bool density, ImPlotLimits range, bool outliers); -template IMPLOT_API double PlotHistogram2D(const char* label_id, const ImU8* xs, const ImU8* ys, int count, int x_bins, int y_bins, bool density, ImPlotLimits range, bool outliers); -template IMPLOT_API double PlotHistogram2D(const char* label_id, const ImS16* xs, const ImS16* ys, int count, int x_bins, int y_bins, bool density, ImPlotLimits range, bool outliers); -template IMPLOT_API double PlotHistogram2D(const char* label_id, const ImU16* xs, const ImU16* ys, int count, int x_bins, int y_bins, bool density, ImPlotLimits range, bool outliers); -template IMPLOT_API double PlotHistogram2D(const char* label_id, const ImS32* xs, const ImS32* ys, int count, int x_bins, int y_bins, bool density, ImPlotLimits range, bool outliers); -template IMPLOT_API double PlotHistogram2D(const char* label_id, const ImU32* xs, const ImU32* ys, int count, int x_bins, int y_bins, bool density, ImPlotLimits range, bool outliers); -template IMPLOT_API double PlotHistogram2D(const char* label_id, const ImS64* xs, const ImS64* ys, int count, int x_bins, int y_bins, bool density, ImPlotLimits range, bool outliers); -template IMPLOT_API double PlotHistogram2D(const char* label_id, const ImU64* xs, const ImU64* ys, int count, int x_bins, int y_bins, bool density, ImPlotLimits range, bool outliers); -template IMPLOT_API double PlotHistogram2D(const char* label_id, const float* xs, const float* ys, int count, int x_bins, int y_bins, bool density, ImPlotLimits range, bool outliers); -template IMPLOT_API double PlotHistogram2D(const char* label_id, const double* xs, const double* ys, int count, int x_bins, int y_bins, bool density, ImPlotLimits range, bool outliers); +template IMPLOT_API double PlotHistogram2D(const char* label_id, const ImS8* xs, const ImS8* ys, int count, int x_bins, int y_bins, bool density, ImPlotRect range, bool outliers); +template IMPLOT_API double PlotHistogram2D(const char* label_id, const ImU8* xs, const ImU8* ys, int count, int x_bins, int y_bins, bool density, ImPlotRect range, bool outliers); +template IMPLOT_API double PlotHistogram2D(const char* label_id, const ImS16* xs, const ImS16* ys, int count, int x_bins, int y_bins, bool density, ImPlotRect range, bool outliers); +template IMPLOT_API double PlotHistogram2D(const char* label_id, const ImU16* xs, const ImU16* ys, int count, int x_bins, int y_bins, bool density, ImPlotRect range, bool outliers); +template IMPLOT_API double PlotHistogram2D(const char* label_id, const ImS32* xs, const ImS32* ys, int count, int x_bins, int y_bins, bool density, ImPlotRect range, bool outliers); +template IMPLOT_API double PlotHistogram2D(const char* label_id, const ImU32* xs, const ImU32* ys, int count, int x_bins, int y_bins, bool density, ImPlotRect range, bool outliers); +template IMPLOT_API double PlotHistogram2D(const char* label_id, const ImS64* xs, const ImS64* ys, int count, int x_bins, int y_bins, bool density, ImPlotRect range, bool outliers); +template IMPLOT_API double PlotHistogram2D(const char* label_id, const ImU64* xs, const ImU64* ys, int count, int x_bins, int y_bins, bool density, ImPlotRect range, bool outliers); +template IMPLOT_API double PlotHistogram2D(const char* label_id, const float* xs, const float* ys, int count, int x_bins, int y_bins, bool density, ImPlotRect range, bool outliers); +template IMPLOT_API double PlotHistogram2D(const char* label_id, const double* xs, const double* ys, int count, int x_bins, int y_bins, bool density, ImPlotRect range, bool outliers); //----------------------------------------------------------------------------- // PLOT DIGITAL @@ -2129,13 +2279,16 @@ template IMPLOT_API double PlotHistogram2D(const char* label_id, const d // TODO: Make this behave like all the other plot types (.e. not fixed in y axis) template -inline void PlotDigitalEx(const char* label_id, Getter getter) { +IMPLOT_INLINE void PlotDigitalEx(const char* label_id, Getter getter) { if (BeginItem(label_id, ImPlotCol_Fill)) { ImPlotContext& gp = *GImPlot; ImDrawList& DrawList = *GetPlotDrawList(); const ImPlotNextItemData& s = GetItemData(); if (getter.Count > 1 && s.RenderFill) { - const int y_axis = GetCurrentYAxis(); + ImPlotPlot& plot = *gp.CurrentPlot; + ImPlotAxis& x_axis = plot.Axes[plot.CurrentX]; + ImPlotAxis& y_axis = plot.Axes[plot.CurrentY]; + int pixYMax = 0; ImPlotPoint itemData1 = getter(0); for (int i = 0; i < getter.Count; ++i) { @@ -2151,24 +2304,24 @@ inline void PlotDigitalEx(const char* label_id, Getter getter) { int pixY_1 = (int)(pixY_1_float); //allow only positive values int pixY_chPosOffset = (int)(ImMax(s.DigitalBitHeight, pixY_1_float) + s.DigitalBitGap); pixYMax = ImMax(pixYMax, pixY_chPosOffset); - ImVec2 pMin = PlotToPixels(itemData1); - ImVec2 pMax = PlotToPixels(itemData2); - int pixY_Offset = 20; //20 pixel from bottom due to mouse cursor label - pMin.y = (gp.PixelRange[y_axis].Min.y) + ((-gp.DigitalPlotOffset) - pixY_Offset); - pMax.y = (gp.PixelRange[y_axis].Min.y) + ((-gp.DigitalPlotOffset) - pixY_0 - pixY_1 - pixY_Offset); + ImVec2 pMin = PlotToPixels(itemData1,IMPLOT_AUTO,IMPLOT_AUTO); + ImVec2 pMax = PlotToPixels(itemData2,IMPLOT_AUTO,IMPLOT_AUTO); + int pixY_Offset = 0; //20 pixel from bottom due to mouse cursor label + pMin.y = (y_axis.PixelMin) + ((-gp.DigitalPlotOffset) - pixY_Offset); + pMax.y = (y_axis.PixelMin) + ((-gp.DigitalPlotOffset) - pixY_0 - pixY_1 - pixY_Offset); //plot only one rectangle for same digital state while (((i+2) < getter.Count) && (itemData1.y == itemData2.y)) { const int in = (i + 1); itemData2 = getter(in); if (ImNanOrInf(itemData2.y)) break; - pMax.x = PlotToPixels(itemData2).x; + pMax.x = PlotToPixels(itemData2,IMPLOT_AUTO,IMPLOT_AUTO).x; i++; } //do not extend plot outside plot range - if (pMin.x < gp.PixelRange[y_axis].Min.x) pMin.x = gp.PixelRange[y_axis].Min.x; - if (pMax.x < gp.PixelRange[y_axis].Min.x) pMax.x = gp.PixelRange[y_axis].Min.x; - if (pMin.x > gp.PixelRange[y_axis].Max.x) pMin.x = gp.PixelRange[y_axis].Max.x; - if (pMax.x > gp.PixelRange[y_axis].Max.x) pMax.x = gp.PixelRange[y_axis].Max.x; + if (pMin.x < x_axis.PixelMin) pMin.x = x_axis.PixelMin; + if (pMax.x < x_axis.PixelMin) pMax.x = x_axis.PixelMin; + if (pMin.x > x_axis.PixelMax) pMin.x = x_axis.PixelMax; + if (pMax.x > x_axis.PixelMax) pMax.x = x_axis.PixelMax; //plot a rectangle that extends up to x2 with y1 height if ((pMax.x > pMin.x) && (gp.CurrentPlot->PlotRect.Contains(pMin) || gp.CurrentPlot->PlotRect.Contains(pMax))) { // ImVec4 colAlpha = item->Color; @@ -2187,7 +2340,7 @@ inline void PlotDigitalEx(const char* label_id, Getter getter) { template void PlotDigital(const char* label_id, const T* xs, const T* ys, int count, int offset, int stride) { - GetterXsYs getter(xs,ys,count,offset,stride); + GetterXY,GetterIdx> getter(GetterIdx(xs,count,offset,stride),GetterIdx(ys,count,offset,stride),count); return PlotDigitalEx(label_id, getter); } @@ -2203,8 +2356,8 @@ template IMPLOT_API void PlotDigital(const char* label_id, const float* x template IMPLOT_API void PlotDigital(const char* label_id, const double* xs, const double* ys, int count, int offset, int stride); // custom -void PlotDigitalG(const char* label_id, ImPlotPoint (*getter_func)(void* data, int idx), void* data, int count, int offset) { - GetterFuncPtr getter(getter_func,data,count,offset); +void PlotDigitalG(const char* label_id, ImPlotGetter getter_func, void* data, int count) { + GetterFuncPtr getter(getter_func,data,count); return PlotDigitalEx(label_id, getter); } @@ -2221,8 +2374,8 @@ void PlotImage(const char* label_id, ImTextureID user_texture_id, const ImPlotPo ImU32 tint_col32 = ImGui::ColorConvertFloat4ToU32(tint_col); GetCurrentItem()->Color = tint_col32; ImDrawList& DrawList = *GetPlotDrawList(); - ImVec2 p1 = PlotToPixels(bmin.x, bmax.y); - ImVec2 p2 = PlotToPixels(bmax.x, bmin.y); + ImVec2 p1 = PlotToPixels(bmin.x, bmax.y,IMPLOT_AUTO,IMPLOT_AUTO); + ImVec2 p2 = PlotToPixels(bmax.x, bmin.y,IMPLOT_AUTO,IMPLOT_AUTO); PushPlotClipRect(); DrawList.AddImage(user_texture_id, p1, p2, uv0, uv1, tint_col32); PopPlotClipRect(); @@ -2237,16 +2390,27 @@ void PlotImage(const char* label_id, ImTextureID user_texture_id, const ImPlotPo // double void PlotText(const char* text, double x, double y, bool vertical, const ImVec2& pixel_offset) { IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != NULL, "PlotText() needs to be called between BeginPlot() and EndPlot()!"); + SetupLock(); ImDrawList & DrawList = *GetPlotDrawList(); PushPlotClipRect(); ImU32 colTxt = GetStyleColorU32(ImPlotCol_InlayText); if (vertical) { - ImVec2 ctr = CalcTextSizeVertical(text) * 0.5f; - ImVec2 pos = PlotToPixels(ImPlotPoint(x,y)) + ImVec2(-ctr.x, ctr.y) + pixel_offset; + ImVec2 siz = CalcTextSizeVertical(text) * 0.5f; + ImVec2 ctr = siz * 0.5f; + ImVec2 pos = PlotToPixels(ImPlotPoint(x,y),IMPLOT_AUTO,IMPLOT_AUTO) + ImVec2(-ctr.x, ctr.y) + pixel_offset; + if (FitThisFrame()) { + FitPoint(PixelsToPlot(pos)); + FitPoint(PixelsToPlot(pos.x + siz.x, pos.y - siz.y)); + } AddTextVertical(&DrawList, pos, colTxt, text); } else { - ImVec2 pos = PlotToPixels(ImPlotPoint(x,y)) - ImGui::CalcTextSize(text) * 0.5f + pixel_offset; + ImVec2 siz = ImGui::CalcTextSize(text); + ImVec2 pos = PlotToPixels(ImPlotPoint(x,y),IMPLOT_AUTO,IMPLOT_AUTO) - siz * 0.5f + pixel_offset; + if (FitThisFrame()) { + FitPoint(PixelsToPlot(pos)); + FitPoint(PixelsToPlot(pos+siz)); + } DrawList.AddText(pos, colTxt, text); } PopPlotClipRect(); diff --git a/lib/libimhex/CMakeLists.txt b/lib/libimhex/CMakeLists.txt index 801d1687b..db53ca2f2 100644 --- a/lib/libimhex/CMakeLists.txt +++ b/lib/libimhex/CMakeLists.txt @@ -11,6 +11,7 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../external/microtar ${CMAKE_CURREN set_target_properties(microtar PROPERTIES POSITION_INDEPENDENT_CODE ON) set(NFD_PORTAL ON CACHE BOOL "Use Portals for Linux file dialogs" FORCE) +set(NFD_USE_ALLOWEDCONTENTTYPES OFF CACHE BOOL "Disable allowedContentTypes for macOS file dialogs" FORCE) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../external/nativefiledialog ${CMAKE_CURRENT_BINARY_DIR}/external/nativefiledialog EXCLUDE_FROM_ALL) set_target_properties(nfd PROPERTIES POSITION_INDEPENDENT_CODE ON) target_compile_definitions(nfd PUBLIC NFD_MACOS_ALLOWEDCONTENTTYPES=0) diff --git a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp index 931c298e1..aee98fa2c 100644 --- a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp +++ b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp @@ -504,7 +504,7 @@ namespace ImGui { bool value_changed = false; if (InputTextEx(label, nullptr, buf, IM_ARRAYSIZE(buf), ImVec2(CalcItemWidth() - frame_size.x, label_size.y + style.FramePadding.y * 2.0f), flags)) - value_changed = DataTypeApplyOpFromText(buf, GImGui->InputTextState.InitialTextA.Data, ImGuiDataType_U64, value, "%llX"); + value_changed = DataTypeApplyFromText(buf, ImGuiDataType_U64, value, "%llX"); if (value_changed) MarkItemEdited(GImGui->LastItemData.ID); @@ -585,7 +585,7 @@ namespace ImGui { flags |= ImGuiInputTextFlags_NoMarkEdited; // We call MarkItemEdited() ourselves by comparing the actual data rather than the string. if (InputText(label, buf, IM_ARRAYSIZE(buf), flags, callback, user_data)) - value_changed = DataTypeApplyOpFromText(buf, g.InputTextState.InitialTextA.Data, data_type, p_data, format); + value_changed = DataTypeApplyFromText(buf, data_type, p_data, format); if (value_changed) MarkItemEdited(g.LastItemData.ID); diff --git a/main/include/window.hpp b/main/include/window.hpp index 8eccf3865..51395ad45 100644 --- a/main/include/window.hpp +++ b/main/include/window.hpp @@ -33,6 +33,8 @@ namespace hex { void frame(); void frameEnd(); + void processEvent() { this->m_hadEvent = true; } + void initGLFW(); void initImGui(); void exitGLFW(); @@ -56,6 +58,10 @@ namespace hex { std::fs::path m_imguiSettingsPath; bool m_mouseButtonDown = false; + + bool m_hadEvent = false; + bool m_frameRateTemporarilyUnlocked = false; + double m_frameRateUnlockTime = 0; }; } \ No newline at end of file diff --git a/main/source/init/tasks.cpp b/main/source/init/tasks.cpp index 61cabab2f..9f719b716 100644 --- a/main/source/init/tasks.cpp +++ b/main/source/init/tasks.cpp @@ -154,7 +154,7 @@ namespace hex::init { fonts->AddFontFromMemoryCompressedTTF(codicons_compressed_data, codicons_compressed_size, fontSize, &cfg, codiconsRange); fonts->AddFontFromMemoryCompressedTTF(unifont_compressed_data, unifont_compressed_size, fontSize, &cfg, unifontRange); - ImGuiFreeType::BuildFontAtlas(fonts); + fonts->Build(); View::setFontAtlas(fonts); View::setFontConfig(cfg); diff --git a/main/source/window/window.cpp b/main/source/window/window.cpp index 7bbf6535b..9ccaa2328 100644 --- a/main/source/window/window.cpp +++ b/main/source/window/window.cpp @@ -175,18 +175,31 @@ namespace hex { while (!glfwWindowShouldClose(this->m_window)) { if (!glfwGetWindowAttrib(this->m_window, GLFW_VISIBLE) || glfwGetWindowAttrib(this->m_window, GLFW_ICONIFIED)) { glfwWaitEvents(); - } else { - const bool frameRateThrottled = !(ImGui::IsPopupOpen(ImGuiID(0), ImGuiPopupFlags_AnyPopupId) || Task::getRunningTaskCount() > 0 || this->m_mouseButtonDown); + glfwPollEvents(); + + bool frameRateUnlocked = ImGui::IsPopupOpen(ImGuiID(0), ImGuiPopupFlags_AnyPopupId) || Task::getRunningTaskCount() > 0 || this->m_mouseButtonDown || this->m_hadEvent; const double timeout = std::max(0.0, (1.0 / 5.0) - (glfwGetTime() - this->m_lastFrameTime)); - glfwWaitEventsTimeout(frameRateThrottled ? timeout : 0); + if ((this->m_lastFrameTime - this->m_frameRateUnlockTime) > 5 && this->m_frameRateTemporarilyUnlocked && !frameRateUnlocked) { + this->m_frameRateTemporarilyUnlocked = false; + } + + if (frameRateUnlocked || this->m_frameRateTemporarilyUnlocked) { + if (!this->m_frameRateTemporarilyUnlocked) { + this->m_frameRateTemporarilyUnlocked = true; + this->m_frameRateUnlockTime = this->m_lastFrameTime; + } + } else { + glfwWaitEventsTimeout(timeout); + } } this->frameBegin(); this->frame(); this->frameEnd(); + this->m_hadEvent = false; } } @@ -556,6 +569,7 @@ namespace hex { win->frameBegin(); win->frame(); win->frameEnd(); + win->processEvent(); }); glfwSetWindowSizeCallback(this->m_window, [](GLFWwindow *window, int width, int height) { @@ -568,6 +582,7 @@ namespace hex { win->frameBegin(); win->frame(); win->frameEnd(); + win->processEvent(); }); glfwSetMouseButtonCallback(this->m_window, [](GLFWwindow *window, int button, int action, int mods) { @@ -579,28 +594,22 @@ namespace hex { win->m_mouseButtonDown = true; else if (action == GLFW_RELEASE) win->m_mouseButtonDown = false; + win->processEvent(); }); glfwSetKeyCallback(this->m_window, [](GLFWwindow *window, int key, int scancode, int action, int mods) { + hex::unused(mods); + auto keyName = glfwGetKeyName(key, scancode); if (keyName != nullptr) key = std::toupper(keyName[0]); auto win = static_cast(glfwGetWindowUserPointer(window)); - auto &io = ImGui::GetIO(); if (action == GLFW_PRESS || action == GLFW_REPEAT) { win->m_pressedKeys.push_back(key); - io.KeysDown[key] = true; - io.KeyCtrl = (mods & GLFW_MOD_CONTROL) != 0; - io.KeyShift = (mods & GLFW_MOD_SHIFT) != 0; - io.KeyAlt = (mods & GLFW_MOD_ALT) != 0; - } else if (action == GLFW_RELEASE) { - io.KeysDown[key] = false; - io.KeyCtrl = (mods & GLFW_MOD_CONTROL) != 0; - io.KeyShift = (mods & GLFW_MOD_SHIFT) != 0; - io.KeyAlt = (mods & GLFW_MOD_ALT) != 0; } + win->processEvent(); }); glfwSetDropCallback(this->m_window, [](GLFWwindow *, int count, const char **paths) { @@ -628,6 +637,13 @@ namespace hex { } }); + glfwSetCursorPosCallback(this->m_window, [](GLFWwindow *window, double x, double y) { + hex::unused(x, y); + + auto win = static_cast(glfwGetWindowUserPointer(window)); + win->processEvent(); + }); + glfwSetWindowCloseCallback(this->m_window, [](GLFWwindow *window) { EventManager::post(window); }); @@ -665,28 +681,6 @@ namespace hex { io.Fonts->ConfigData.push_back(entry); io.ConfigViewportsNoTaskBarIcon = false; - io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; - io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT; - io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT; - io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP; - io.KeyMap[ImGuiKey_DownArrow] = GLFW_KEY_DOWN; - io.KeyMap[ImGuiKey_PageUp] = GLFW_KEY_PAGE_UP; - io.KeyMap[ImGuiKey_PageDown] = GLFW_KEY_PAGE_DOWN; - io.KeyMap[ImGuiKey_Home] = GLFW_KEY_HOME; - io.KeyMap[ImGuiKey_End] = GLFW_KEY_END; - io.KeyMap[ImGuiKey_Insert] = GLFW_KEY_INSERT; - io.KeyMap[ImGuiKey_Delete] = GLFW_KEY_DELETE; - io.KeyMap[ImGuiKey_Backspace] = GLFW_KEY_BACKSPACE; - io.KeyMap[ImGuiKey_Space] = GLFW_KEY_SPACE; - io.KeyMap[ImGuiKey_Enter] = GLFW_KEY_ENTER; - io.KeyMap[ImGuiKey_Escape] = GLFW_KEY_ESCAPE; - io.KeyMap[ImGuiKey_KeyPadEnter] = GLFW_KEY_KP_ENTER; - io.KeyMap[ImGuiKey_A] = GLFW_KEY_A; - io.KeyMap[ImGuiKey_C] = GLFW_KEY_C; - io.KeyMap[ImGuiKey_V] = GLFW_KEY_V; - io.KeyMap[ImGuiKey_X] = GLFW_KEY_X; - io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y; - io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z; ImNodes::PushAttributeFlag(ImNodesAttributeFlags_EnableLinkDetachWithDragClick); ImNodes::PushAttributeFlag(ImNodesAttributeFlags_EnableLinkCreationOnSnap); diff --git a/plugins/builtin/source/content/data_processor_nodes.cpp b/plugins/builtin/source/content/data_processor_nodes.cpp index 10037c258..7153b7b7a 100644 --- a/plugins/builtin/source/content/data_processor_nodes.cpp +++ b/plugins/builtin/source/content/data_processor_nodes.cpp @@ -996,8 +996,10 @@ namespace hex::plugin::builtin { } void drawPlot(const ImVec2 &viewSize) { - ImPlot::SetNextPlotLimits(0, 256, 0.5, float(*std::max_element(this->m_counts.begin(), this->m_counts.end())) * 1.1F, ImGuiCond_Always); - if (ImPlot::BeginPlot("##distribution", "Address", "Count", viewSize, ImPlotFlags_NoLegend | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect, ImPlotAxisFlags_Lock, ImPlotAxisFlags_Lock | ImPlotAxisFlags_LogScale, ImPlotAxisFlags_NoLabel | ImPlotAxisFlags_NoTickLabels, ImPlotAxisFlags_NoLabel | ImPlotAxisFlags_NoTickLabels)) { + if (ImPlot::BeginPlot("##distribution", viewSize, ImPlotFlags_NoLegend | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect)) { + ImPlot::SetupAxes("Address", "Count", ImPlotAxisFlags_Lock, ImPlotAxisFlags_Lock | ImPlotAxisFlags_LogScale); + ImPlot::SetupAxesLimits(0, 256, 1, double(*std::max_element(this->m_counts.begin(), this->m_counts.end())) * 1.1F, ImGuiCond_Always); + static auto x = [] { std::array result { 0 }; std::iota(result.begin(), result.end(), 0); diff --git a/plugins/builtin/source/content/tools_entries.cpp b/plugins/builtin/source/content/tools_entries.cpp index ff4c3dea4..15cd6893e 100644 --- a/plugins/builtin/source/content/tools_entries.cpp +++ b/plugins/builtin/source/content/tools_entries.cpp @@ -412,7 +412,7 @@ namespace hex::plugin::builtin { ImGui::EndTable(); } - ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth()); + ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x); if (ImGui::InputText("##input", mathInput, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)) { ImGui::SetKeyboardFocusHere(); evaluate = true; @@ -622,7 +622,7 @@ namespace hex::plugin::builtin { ImGui::TableNextColumn(); if (ImGui::Hyperlink(link.c_str())) { - if (ImGui::GetMergedKeyModFlags() == ImGuiKeyModFlags_Ctrl) + if (ImGui::IsKeyDown(ImGuiKey_LeftCtrl)) hex::openWebpage(link); else ImGui::SetClipboardText(link.c_str()); diff --git a/plugins/builtin/source/content/views/view_bookmarks.cpp b/plugins/builtin/source/content/views/view_bookmarks.cpp index c23ca457d..a272d7063 100644 --- a/plugins/builtin/source/content/views/view_bookmarks.cpp +++ b/plugins/builtin/source/content/views/view_bookmarks.cpp @@ -123,7 +123,7 @@ namespace hex::plugin::builtin { void ViewBookmarks::drawContent() { if (ImGui::Begin(View::toWindowName("hex.builtin.view.bookmarks.name").c_str(), &this->getWindowOpenState())) { - ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth()); + ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x); ImGui::InputTextWithHint("##filter", "hex.builtin.common.filter"_lang, this->m_currFilter); ImGui::PopItemWidth(); diff --git a/plugins/builtin/source/content/views/view_find.cpp b/plugins/builtin/source/content/views/view_find.cpp index 262ea88f6..8e50c66f2 100644 --- a/plugins/builtin/source/content/views/view_find.cpp +++ b/plugins/builtin/source/content/views/view_find.cpp @@ -529,7 +529,7 @@ namespace hex::plugin::builtin { auto &currOccurrences = this->m_sortedOccurrences[provider]; - ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth()); + ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x); if (ImGui::InputTextWithHint("##filter", "hex.builtin.common.filter"_lang, this->m_currFilter)) { this->m_sortedOccurrences = this->m_foundOccurrences; diff --git a/plugins/builtin/source/content/views/view_hashes.cpp b/plugins/builtin/source/content/views/view_hashes.cpp index 5d25151e9..cfacec6c2 100644 --- a/plugins/builtin/source/content/views/view_hashes.cpp +++ b/plugins/builtin/source/content/views/view_hashes.cpp @@ -85,7 +85,7 @@ namespace hex::plugin::builtin { if (this->m_newHashName.empty() && this->m_selectedHash != nullptr) this->m_newHashName = hex::format("{} {}", LangEntry(this->m_selectedHash->getUnlocalizedName()), static_cast("hex.builtin.view.hashes.hash"_lang)); - if (ImGui::BeginChild("##settings", ImVec2(ImGui::GetContentRegionAvailWidth(), 200_scaled), true)) { + if (ImGui::BeginChild("##settings", ImVec2(ImGui::GetContentRegionAvail().x, 200_scaled), true)) { if (this->m_selectedHash != nullptr) { auto startPos = ImGui::GetCursorPosY(); this->m_selectedHash->draw(); @@ -110,7 +110,7 @@ namespace hex::plugin::builtin { } ImGui::EndDisabled(); - if (ImGui::BeginTable("##hashes", 3, ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Borders, ImVec2(ImGui::GetContentRegionAvailWidth(), ImGui::GetTextLineHeightWithSpacing() * 10))) { + if (ImGui::BeginTable("##hashes", 3, ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Borders, ImVec2(ImGui::GetContentRegionAvail().x, ImGui::GetTextLineHeightWithSpacing() * 10))) { ImGui::TableSetupColumn("hex.builtin.view.hashes.name"_lang); ImGui::TableSetupColumn("hex.builtin.view.hashes.type"_lang); ImGui::TableSetupColumn("hex.builtin.view.hashes.result"_lang, ImGuiTableColumnFlags_WidthStretch); @@ -159,7 +159,7 @@ namespace hex::plugin::builtin { else result = "???"; - ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth()); + ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x); ImGui::InputText("##result", result, ImGuiInputTextFlags_ReadOnly); ImGui::PopItemWidth(); diff --git a/plugins/builtin/source/content/views/view_hex_editor.cpp b/plugins/builtin/source/content/views/view_hex_editor.cpp index fdf009d8a..b7ab90e06 100644 --- a/plugins/builtin/source/content/views/view_hex_editor.cpp +++ b/plugins/builtin/source/content/views/view_hex_editor.cpp @@ -44,7 +44,7 @@ namespace hex::plugin::builtin { } ImGui::SetKeyboardFocusHere(); - ImGui::CaptureKeyboardFromApp(true); + ImGui::SetNextFrameWantCaptureKeyboard(true); if (ImGui::InputText("##input", this->m_input, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)) { if (auto result = this->m_evaluator.evaluate(this->m_input); result.has_value()) { const auto inputResult = result.value(); @@ -531,7 +531,7 @@ namespace hex::plugin::builtin { } else { ImGui::SetKeyboardFocusHere(); - ImGui::CaptureKeyboardFromApp(true); + ImGui::SetNextFrameWantCaptureKeyboard(true); if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) { this->m_editingAddress = std::nullopt; @@ -682,8 +682,9 @@ namespace hex::plugin::builtin { if (ImHexApi::Provider::isValid()) { auto provider = ImHexApi::Provider::get(); - ImGuiListClipper clipper(std::ceil(provider->getSize() / (long double)(this->m_bytesPerRow)), CharacterSize.y); + ImGuiListClipper clipper; + clipper.Begin(std::ceil(provider->getSize() / (long double)(this->m_bytesPerRow)), CharacterSize.y); while (clipper.Step()) { this->m_visibleRowCount = clipper.DisplayEnd - clipper.DisplayStart; @@ -1039,7 +1040,7 @@ namespace hex::plugin::builtin { void ViewHexEditor::drawContent() { if (ImGui::Begin(View::toWindowName(this->getUnlocalizedName()).c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoNavInputs | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) { - const auto FooterSize = ImVec2(ImGui::GetContentRegionAvailWidth(), ImGui::GetTextLineHeightWithSpacing() * 3); + const auto FooterSize = ImVec2(ImGui::GetContentRegionAvail().x, ImGui::GetTextLineHeightWithSpacing() * 3); const auto TableSize = ImGui::GetContentRegionAvail() - ImVec2(0, FooterSize.y); this->drawPopup(); diff --git a/plugins/builtin/source/content/views/view_information.cpp b/plugins/builtin/source/content/views/view_information.cpp index c6fc4b475..96a926cc3 100644 --- a/plugins/builtin/source/content/views/view_information.cpp +++ b/plugins/builtin/source/content/views/view_information.cpp @@ -101,7 +101,7 @@ namespace hex::plugin::builtin { { this->m_blockSize = std::max(std::ceil(provider->getActualSize() / 2048.0F), 256); - std::array valueCounts = { 0 }, blockValueCounts = { 0 }; + std::array blockValueCounts = { 0 }; this->m_blockEntropy.clear(); this->m_valueCounts.fill(0); @@ -110,7 +110,7 @@ namespace hex::plugin::builtin { u64 count = 0; for (u8 byte : reader) { - valueCounts[byte]++; + this->m_valueCounts[byte]++; blockValueCounts[byte]++; count++; @@ -121,9 +121,7 @@ namespace hex::plugin::builtin { } } - this->m_valueCounts = valueCounts; - - this->m_averageEntropy = calculateEntropy(valueCounts, provider->getSize()); + this->m_averageEntropy = calculateEntropy(this->m_valueCounts, provider->getSize()); if (!this->m_blockEntropy.empty()) this->m_highestBlockEntropy = *std::max_element(this->m_blockEntropy.begin(), this->m_blockEntropy.end()); else @@ -142,7 +140,7 @@ namespace hex::plugin::builtin { if (ImHexApi::Provider::isValid() && provider->isReadable()) { ImGui::BeginDisabled(this->m_analyzing); { - if (ImGui::Button("hex.builtin.view.information.analyze"_lang, ImVec2(ImGui::GetContentRegionAvailWidth(), 0))) + if (ImGui::Button("hex.builtin.view.information.analyze"_lang, ImVec2(ImGui::GetContentRegionAvail().x, 0))) this->analyze(); } ImGui::EndDisabled(); @@ -218,8 +216,10 @@ namespace hex::plugin::builtin { ImPlot::PushStyleColor(ImPlotCol_FrameBg, ImGui::GetColorU32(ImGuiCol_WindowBg)); ImGui::TextUnformatted("hex.builtin.view.information.distribution"_lang); - ImPlot::SetNextPlotLimits(0, 256, 0.5, float(*std::max_element(this->m_valueCounts.begin(), this->m_valueCounts.end())) * 1.1F, ImGuiCond_Always); - if (ImPlot::BeginPlot("##distribution", "Address", "Count", ImVec2(-1, 0), ImPlotFlags_NoChild | ImPlotFlags_NoLegend | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect, ImPlotAxisFlags_Lock, ImPlotAxisFlags_Lock | ImPlotAxisFlags_LogScale)) { + if (ImPlot::BeginPlot("##distribution", ImVec2(-1, 0), ImPlotFlags_NoChild | ImPlotFlags_NoLegend | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect)) { + ImPlot::SetupAxes("Address", "Count", ImPlotAxisFlags_Lock, ImPlotAxisFlags_Lock | ImPlotAxisFlags_LogScale); + ImPlot::SetupAxesLimits(0, 256, 1, double(*std::max_element(this->m_valueCounts.begin(), this->m_valueCounts.end())) * 1.1F, ImGuiCond_Always); + static auto x = [] { std::array result { 0 }; std::iota(result.begin(), result.end(), 0); @@ -235,12 +235,14 @@ namespace hex::plugin::builtin { ImGui::TextUnformatted("hex.builtin.view.information.entropy"_lang); - ImPlot::SetNextPlotLimits(0, this->m_blockEntropy.size(), -0.1, 1.1, ImGuiCond_Always); - if (ImPlot::BeginPlot("##entropy", "Address", "Entropy", ImVec2(-1, 0), ImPlotFlags_NoChild | ImPlotFlags_CanvasOnly | ImPlotFlags_AntiAliased, ImPlotAxisFlags_Lock | ImPlotAxisFlags_NoTickLabels, ImPlotAxisFlags_Lock)) { + if (ImPlot::BeginPlot("##entropy", ImVec2(-1, 0), ImPlotFlags_NoChild | ImPlotFlags_CanvasOnly)) { + ImPlot::SetupAxes("Address", "Entropy", ImPlotAxisFlags_Lock, ImPlotAxisFlags_Lock); + ImPlot::SetupAxesLimits(0, this->m_blockEntropy.size(), -0.1F, 1.1F, ImGuiCond_Always); + ImPlot::PlotLine("##entropy_line", this->m_blockEntropy.data(), this->m_blockEntropy.size()); - if (ImPlot::DragLineX("Position", &this->m_entropyHandlePosition, false)) { - u64 address = u64(this->m_entropyHandlePosition * this->m_blockSize) + provider->getBaseAddress(); + if (ImPlot::DragLineX(1, &this->m_entropyHandlePosition, ImGui::GetStyleColorVec4(ImGuiCol_Text))) { + u64 address = u64(std::max(this->m_entropyHandlePosition, 0) * this->m_blockSize) + provider->getBaseAddress(); address = std::min(address, provider->getBaseAddress() + provider->getSize() - 1); ImHexApi::HexEditor::setSelection(address, 1); } diff --git a/plugins/builtin/source/content/views/view_patches.cpp b/plugins/builtin/source/content/views/view_patches.cpp index 03ab2fa7e..cf58e97db 100644 --- a/plugins/builtin/source/content/views/view_patches.cpp +++ b/plugins/builtin/source/content/views/view_patches.cpp @@ -46,8 +46,9 @@ namespace hex::plugin::builtin { auto &patches = provider->getPatches(); u32 index = 0; - ImGuiListClipper clipper(patches.size()); + ImGuiListClipper clipper; + clipper.Begin(patches.size()); while (clipper.Step()) { auto iter = patches.begin(); for (auto i = 0; i < clipper.DisplayStart; i++) diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index 7aa485d6e..23d85e730 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -438,7 +438,10 @@ namespace hex::plugin::builtin { void ViewPatternEditor::drawConsole(ImVec2 size) { ImGui::PushStyleColor(ImGuiCol_ChildBg, this->m_textEditor.GetPalette()[u32(TextEditor::PaletteIndex::Background)]); if (ImGui::BeginChild("##console", size, true, ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_HorizontalScrollbar)) { - ImGuiListClipper clipper(this->m_console.size()); + ImGuiListClipper clipper; + + clipper.Begin(this->m_console.size()); + while (clipper.Step()) for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { const auto &[level, message] = this->m_console[i]; @@ -488,7 +491,7 @@ namespace hex::plugin::builtin { ImGui::PushID(index++); ON_SCOPE_EXIT { ImGui::PopID(); }; - ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth()); + ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x); constexpr const char *Types[] = { "I", "F", "S", "B" }; if (ImGui::BeginCombo("", Types[static_cast(type)])) { for (auto i = 0; i < IM_ARRAYSIZE(Types); i++) { @@ -502,13 +505,13 @@ namespace hex::plugin::builtin { ImGui::TableNextColumn(); - ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth()); + ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x); ImGui::InputText("###name", name); ImGui::PopItemWidth(); ImGui::TableNextColumn(); - ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth()); + ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x); switch (type) { case EnvVarType::Integer: { diff --git a/plugins/builtin/source/content/views/view_yara.cpp b/plugins/builtin/source/content/views/view_yara.cpp index 2762e1afa..a01717bb6 100644 --- a/plugins/builtin/source/content/views/view_yara.cpp +++ b/plugins/builtin/source/content/views/view_yara.cpp @@ -128,7 +128,9 @@ namespace hex::plugin::builtin { auto consoleSize = ImGui::GetContentRegionAvail(); if (ImGui::BeginChild("##console", consoleSize, true, ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_HorizontalScrollbar)) { - ImGuiListClipper clipper(this->m_consoleMessages.size()); + ImGuiListClipper clipper; + + clipper.Begin(this->m_consoleMessages.size()); while (clipper.Step()) for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { const auto &message = this->m_consoleMessages[i];