imgui_tables.cpp 139 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891
  1. // dear imgui, v1.80 WIP
  2. // (tables and columns code)
  3. /*
  4. *
  5. * Index of this file:
  6. *
  7. * // [SECTION] Widgets: BeginTable, EndTable, etc.
  8. * // [SECTION] Widgets: Columns, BeginColumns, EndColumns, etc.
  9. *
  10. */
  11. #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
  12. #define _CRT_SECURE_NO_WARNINGS
  13. #endif
  14. #include "imgui.h"
  15. #ifndef IMGUI_DISABLE
  16. #ifndef IMGUI_DEFINE_MATH_OPERATORS
  17. #define IMGUI_DEFINE_MATH_OPERATORS
  18. #endif
  19. #include "imgui_internal.h"
  20. #if defined(_MSC_VER) && _MSC_VER <= 1500 // MSVC 2008 or earlier
  21. #include <stddef.h> // intptr_t
  22. #else
  23. #include <stdint.h> // intptr_t
  24. #endif
  25. // Visual Studio warnings
  26. #ifdef _MSC_VER
  27. #pragma warning (disable: 4127) // condition expression is constant
  28. #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen
  29. #if defined(_MSC_VER) && _MSC_VER >= 1922 // MSVC 2019 16.2 or later
  30. #pragma warning (disable: 5054) // operator '|': deprecated between enumerations of different types
  31. #endif
  32. #endif
  33. // Clang/GCC warnings with -Weverything
  34. #if defined(__clang__)
  35. #if __has_warning("-Wunknown-warning-option")
  36. #pragma clang diagnostic ignored "-Wunknown-warning-option" // warning: unknown warning group 'xxx' // not all warnings are known by all Clang versions and they tend to be rename-happy.. so ignoring warnings triggers new warnings on some configuration. Great!
  37. #endif
  38. #pragma clang diagnostic ignored "-Wunknown-pragmas" // warning: unknown warning group 'xxx'
  39. #pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast // yes, they are more terse.
  40. #pragma clang diagnostic ignored "-Wfloat-equal" // warning: comparing floating point with == or != is unsafe // storing and comparing against same constants (typically 0.0f) is ok.
  41. #pragma clang diagnostic ignored "-Wsign-conversion" // warning: implicit conversion changes signedness
  42. #pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" // warning: zero as null pointer constant // some standard header variations use #define NULL 0
  43. #pragma clang diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function // using printf() is a misery with this as C++ va_arg ellipsis changes float to double.
  44. #pragma clang diagnostic ignored "-Wenum-enum-conversion" // warning: bitwise operation between different enumeration types ('XXXFlags_' and 'XXXFlagsPrivate_')
  45. #pragma clang diagnostic ignored "-Wdeprecated-enum-enum-conversion"// warning: bitwise operation between different enumeration types ('XXXFlags_' and 'XXXFlagsPrivate_') is deprecated
  46. #pragma clang diagnostic ignored "-Wimplicit-int-float-conversion" // warning: implicit conversion from 'xxx' to 'float' may lose precision
  47. #elif defined(__GNUC__)
  48. #pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind
  49. #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
  50. #endif
  51. //-----------------------------------------------------------------------------
  52. // [SECTION] Widgets: BeginTable, EndTable, etc.
  53. //-----------------------------------------------------------------------------
  54. //-----------------------------------------------------------------------------
  55. // Typical call flow: (root level is public API):
  56. // - BeginTable() user begin into a table
  57. // - BeginChild() - (if ScrollX/ScrollY is set)
  58. // - TableBeginUpdateColumns() - apply resize/order requests, lock columns active state, order
  59. // - TableSetupColumn() user submit columns details (optional)
  60. // - TableAutoHeaders() or TableHeader() user submit a headers row (optional)
  61. // - TableSortSpecsClickColumn()
  62. // - TableGetSortSpecs() user queries updated sort specs (optional)
  63. // - TableNextRow() / TableNextCell() user begin into the first row, also automatically called by TableAutoHeaders()
  64. // - TableUpdateLayout() - called by the FIRST call to TableNextRow()
  65. // - TableUpdateDrawChannels() - setup ImDrawList channels
  66. // - TableUpdateBorders() - detect hovering columns for resize, ahead of contents submission
  67. // - TableDrawContextMenu() - draw right-click context menu
  68. // - [...] user emit contents
  69. // - EndTable() user ends the table
  70. // - TableDrawBorders() - draw outer borders, inner vertical borders
  71. // - TableDrawMergeChannels() - merge draw channels if clipping isn't required
  72. // - TableSetColumnWidth() - apply resizing width
  73. // - TableUpdateColumnsWeightFromWidth()
  74. // - EndChild() - (if ScrollX/ScrollY is set)
  75. //-----------------------------------------------------------------------------
  76. // Configuration
  77. static const float TABLE_RESIZE_SEPARATOR_HALF_THICKNESS = 4.0f; // Extend outside inner borders.
  78. static const float TABLE_RESIZE_SEPARATOR_FEEDBACK_TIMER = 0.06f; // Delay/timer before making the hover feedback (color+cursor) visible because tables/columns tends to be more cramped.
  79. // Helper
  80. inline ImGuiTableFlags TableFixFlags(ImGuiTableFlags flags)
  81. {
  82. // Adjust flags: set default sizing policy
  83. if ((flags & ImGuiTableFlags_SizingPolicyMaskX_) == 0)
  84. flags |= (flags & ImGuiTableFlags_ScrollX) ? ImGuiTableFlags_SizingPolicyFixedX : ImGuiTableFlags_SizingPolicyStretchX;
  85. // Adjust flags: MultiSortable automatically enable Sortable
  86. if (flags & ImGuiTableFlags_MultiSortable)
  87. flags |= ImGuiTableFlags_Sortable;
  88. // Adjust flags: disable saved settings if there's nothing to save
  89. if ((flags & (ImGuiTableFlags_Resizable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Sortable)) == 0)
  90. flags |= ImGuiTableFlags_NoSavedSettings;
  91. // Adjust flags: enforce borders when resizable
  92. if (flags & ImGuiTableFlags_Resizable)
  93. flags |= ImGuiTableFlags_BordersVInner;
  94. // Adjust flags: disable top rows freezing if there's no scrolling
  95. // In theory we could want to assert if ScrollFreeze was set without the corresponding scroll flag, but that would hinder demos.
  96. if ((flags & ImGuiTableFlags_ScrollX) == 0)
  97. flags &= ~ImGuiTableFlags_ScrollFreezeColumnsMask_;
  98. if ((flags & ImGuiTableFlags_ScrollY) == 0)
  99. flags &= ~ImGuiTableFlags_ScrollFreezeRowsMask_;
  100. // Adjust flags: disable NoHostExtendY if we have any scrolling going on
  101. if ((flags & ImGuiTableFlags_NoHostExtendY) && (flags & (ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY)) != 0)
  102. flags &= ~ImGuiTableFlags_NoHostExtendY;
  103. // Adjust flags: we don't support NoClipX with (FreezeColumns > 0), we could with some work but it doesn't appear to be worth the effort
  104. if (flags & ImGuiTableFlags_ScrollFreezeColumnsMask_)
  105. flags &= ~ImGuiTableFlags_NoClipX;
  106. return flags;
  107. }
  108. // About 'outer_size':
  109. // The meaning of outer_size needs to differ slightly depending of if we are using ScrollX/ScrollY flags.
  110. // With ScrollX/ScrollY: using a child window for scrolling:
  111. // - outer_size.y < 0.0f -> bottom align
  112. // - outer_size.y = 0.0f -> bottom align: consistent with BeginChild(), best to preserve (0,0) default arg
  113. // - outer_size.y > 0.0f -> fixed child height
  114. // Without scrolling, we output table directly in parent window:
  115. // - outer_size.y < 0.0f -> bottom align (will auto extend, unless NoHostExtendV is set)
  116. // - outer_size.y = 0.0f -> zero minimum height (will auto extend, unless NoHostExtendV is set)
  117. // - outer_size.y > 0.0f -> minimum height (will auto extend, unless NoHostExtendV is set)
  118. // About: 'inner_width':
  119. // With ScrollX:
  120. // - inner_width < 0.0f -> *illegal* fit in known width (right align from outer_size.x) <-- weird
  121. // - inner_width = 0.0f -> auto enlarge: *only* fixed size columns, which will take space they need (proportional columns becomes fixed columns) <-- desired default :(
  122. // - inner_width > 0.0f -> fit in known width: fixed column take space they need if possible (otherwise shrink down), proportional columns share remaining space.
  123. // Without ScrollX:
  124. // - inner_width < 0.0f -> fit in known width (right align from outer_size.x) <-- desired default
  125. // - inner_width = 0.0f -> auto enlarge: will emit contents size in parent window
  126. // - inner_width > 0.0f -> fit in known width (bypass outer_size.x, permitted but not useful, should instead alter outer_width)
  127. // FIXME-TABLE: This is currently not very useful.
  128. // FIXME-TABLE: Replace enlarge vs fixed width by a flag.
  129. // Even if not really useful, we allow 'inner_scroll_width < outer_size.x' for consistency and to facilitate understanding of what the value does.
  130. bool ImGui::BeginTable(const char* str_id, int columns_count, ImGuiTableFlags flags, const ImVec2& outer_size, float inner_width)
  131. {
  132. ImGuiID id = GetID(str_id);
  133. return BeginTableEx(str_id, id, columns_count, flags, outer_size, inner_width);
  134. }
  135. bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImGuiTableFlags flags, const ImVec2& outer_size, float inner_width)
  136. {
  137. ImGuiContext& g = *GImGui;
  138. ImGuiWindow* outer_window = GetCurrentWindow();
  139. if (outer_window->SkipItems) // Consistent with other tables + beneficial side effect that assert on miscalling EndTable() will be more visible.
  140. return false;
  141. // Sanity checks
  142. IM_ASSERT(columns_count > 0 && columns_count < IMGUI_TABLE_MAX_COLUMNS && "Only 0..63 columns allowed!");
  143. if (flags & ImGuiTableFlags_ScrollX)
  144. IM_ASSERT(inner_width >= 0.0f);
  145. const bool use_child_window = (flags & (ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY)) != 0;
  146. const ImVec2 avail_size = GetContentRegionAvail();
  147. ImVec2 actual_outer_size = CalcItemSize(outer_size, ImMax(avail_size.x, 1.0f), use_child_window ? ImMax(avail_size.y, 1.0f) : 0.0f);
  148. ImRect outer_rect(outer_window->DC.CursorPos, outer_window->DC.CursorPos + actual_outer_size);
  149. // If an outer size is specified ahead we will be able to early out when not visible. Exact clipping rules may evolve.
  150. if (use_child_window && IsClippedEx(outer_rect, 0, false))
  151. {
  152. ItemSize(outer_rect);
  153. return false;
  154. }
  155. flags = TableFixFlags(flags);
  156. if (outer_window->Flags & ImGuiWindowFlags_NoSavedSettings)
  157. flags |= ImGuiTableFlags_NoSavedSettings;
  158. // Acquire storage for the table
  159. ImGuiTable* table = g.Tables.GetOrAddByKey(id);
  160. const ImGuiTableFlags table_last_flags = table->Flags;
  161. const int instance_no = (table->LastFrameActive != g.FrameCount) ? 0 : table->InstanceNo + 1;
  162. const ImGuiID instance_id = id + instance_no;
  163. if (instance_no > 0)
  164. IM_ASSERT(table->ColumnsCount == columns_count && "BeginTable(): Cannot change columns count mid-frame while preserving same ID");
  165. // Initialize
  166. table->ID = id;
  167. table->Flags = flags;
  168. table->InstanceNo = (ImS16)instance_no;
  169. table->LastFrameActive = g.FrameCount;
  170. table->OuterWindow = table->InnerWindow = outer_window;
  171. table->ColumnsCount = columns_count;
  172. table->ColumnsNames.Buf.resize(0);
  173. table->IsInitializing = false;
  174. table->IsLayoutLocked = false;
  175. table->InnerWidth = inner_width;
  176. table->OuterRect = outer_rect;
  177. table->WorkRect = outer_rect;
  178. if (use_child_window)
  179. {
  180. // Ensure no vertical scrollbar appears if we only want horizontal one, to make flag consistent (we have no other way to disable vertical scrollbar of a window while keeping the horizontal one showing)
  181. ImVec2 override_content_size(FLT_MAX, FLT_MAX);
  182. if ((flags & ImGuiTableFlags_ScrollX) && !(flags & ImGuiTableFlags_ScrollY))
  183. override_content_size.y = FLT_MIN;
  184. // Ensure specified width (when not specified, Stretched columns will act as if the width == OuterWidth and never lead to any scrolling)
  185. // We don't handle inner_width < 0.0f, we could potentially use it to right-align based on the right side of the child window work rect,
  186. // which would require knowing ahead if we are going to have decoration taking horizontal spaces (typically a vertical scrollbar).
  187. if (inner_width != 0.0f)
  188. override_content_size.x = inner_width;
  189. if (override_content_size.x != FLT_MAX || override_content_size.y != FLT_MAX)
  190. SetNextWindowContentSize(ImVec2(override_content_size.x != FLT_MAX ? override_content_size.x : 0.0f, override_content_size.y != FLT_MAX ? override_content_size.y : 0.0f));
  191. // Create scrolling region (without border = zero window padding)
  192. ImGuiWindowFlags child_flags = (flags & ImGuiTableFlags_ScrollX) ? ImGuiWindowFlags_HorizontalScrollbar : ImGuiWindowFlags_None;
  193. BeginChildEx(name, instance_id, table->OuterRect.GetSize(), false, child_flags);
  194. table->InnerWindow = g.CurrentWindow;
  195. table->WorkRect = table->InnerWindow->WorkRect;
  196. table->OuterRect = table->InnerWindow->Rect();
  197. }
  198. else
  199. {
  200. // WorkRect.Max will grow as we append contents.
  201. PushID(instance_id);
  202. }
  203. // Borders
  204. // - None ........Content..... Pad .....Content........
  205. // - VOuter | Pad ..Content..... Pad .....Content.. Pad | // FIXME-TABLE: Not handled properly
  206. // - VInner ........Content.. Pad | Pad ..Content........ // FIXME-TABLE: Not handled properly
  207. // - VOuter+VInner | Pad ..Content.. Pad | Pad ..Content.. Pad |
  208. const bool has_cell_padding_x = (flags & ImGuiTableFlags_BordersVOuter) != 0;
  209. ImGuiWindow* inner_window = table->InnerWindow;
  210. table->CellPaddingX1 = has_cell_padding_x ? g.Style.CellPadding.x + 1.0f : 0.0f;
  211. table->CellPaddingX2 = has_cell_padding_x ? g.Style.CellPadding.x : 0.0f;
  212. table->CellPaddingY = g.Style.CellPadding.y;
  213. table->CellSpacingX = has_cell_padding_x ? 0.0f : g.Style.CellPadding.x;
  214. table->CurrentColumn = -1;
  215. table->CurrentRow = -1;
  216. table->RowBgColorCounter = 0;
  217. table->LastRowFlags = ImGuiTableRowFlags_None;
  218. table->HostClipRect = inner_window->ClipRect;
  219. table->InnerClipRect = (inner_window == outer_window) ? table->WorkRect : inner_window->ClipRect;
  220. table->InnerClipRect.ClipWith(table->WorkRect); // We need this to honor inner_width
  221. table->InnerClipRect.ClipWith(table->HostClipRect);
  222. table->InnerClipRect.Max.y = (flags & ImGuiTableFlags_NoHostExtendY) ? table->WorkRect.Max.y : inner_window->ClipRect.Max.y;
  223. table->BackgroundClipRect = table->InnerClipRect;
  224. table->RowPosY1 = table->RowPosY2 = table->WorkRect.Min.y; // This is needed somehow
  225. table->RowTextBaseline = 0.0f; // This will be cleared again by TableBeginRow()
  226. table->FreezeRowsRequest = (ImS8)((flags & ImGuiTableFlags_ScrollFreezeRowsMask_) >> ImGuiTableFlags_ScrollFreezeRowsShift_);
  227. table->FreezeRowsCount = (inner_window->Scroll.y != 0.0f) ? table->FreezeRowsRequest : 0;
  228. table->FreezeColumnsRequest = (ImS8)((flags & ImGuiTableFlags_ScrollFreezeColumnsMask_) >> ImGuiTableFlags_ScrollFreezeColumnsShift_);
  229. table->FreezeColumnsCount = (inner_window->Scroll.x != 0.0f) ? table->FreezeColumnsRequest : 0;
  230. table->IsFreezeRowsPassed = (table->FreezeRowsCount == 0);
  231. table->DeclColumnsCount = 0;
  232. table->HoveredColumnBody = -1;
  233. table->HoveredColumnBorder = -1;
  234. table->RightMostActiveColumn = -1;
  235. // Using opaque colors facilitate overlapping elements of the grid
  236. table->BorderColorStrong = GetColorU32(ImGuiCol_TableBorderStrong);
  237. table->BorderColorLight = GetColorU32(ImGuiCol_TableBorderLight);
  238. table->BorderX1 = table->InnerClipRect.Min.x;// +((table->Flags & ImGuiTableFlags_BordersOuter) ? 0.0f : -1.0f);
  239. table->BorderX2 = table->InnerClipRect.Max.x;// +((table->Flags & ImGuiTableFlags_BordersOuter) ? 0.0f : +1.0f);
  240. // Make table current
  241. g.CurrentTableStack.push_back(ImGuiPtrOrIndex(g.Tables.GetIndex(table)));
  242. g.CurrentTable = table;
  243. outer_window->DC.CurrentTable = table;
  244. if ((table_last_flags & ImGuiTableFlags_Reorderable) && !(flags & ImGuiTableFlags_Reorderable))
  245. table->IsResetDisplayOrderRequest = true;
  246. // Clear data if columns count changed
  247. if (table->Columns.Size != 0 && table->Columns.Size != columns_count)
  248. {
  249. table->Columns.resize(0);
  250. table->DisplayOrder.resize(0);
  251. }
  252. // Setup default columns state
  253. if (table->Columns.Size == 0)
  254. {
  255. table->IsInitializing = table->IsSettingsRequestLoad = table->IsSortSpecsDirty = true;
  256. table->Columns.reserve(columns_count);
  257. table->DisplayOrder.reserve(columns_count);
  258. for (int n = 0; n < columns_count; n++)
  259. {
  260. ImGuiTableColumn column;
  261. column.IndexDisplayOrder = (ImS8)n;
  262. table->Columns.push_back(column);
  263. table->DisplayOrder.push_back(column.IndexDisplayOrder);
  264. }
  265. }
  266. // Load settings
  267. if (table->IsSettingsRequestLoad)
  268. TableLoadSettings(table);
  269. // Grab a copy of window fields we will modify
  270. table->BackupSkipItems = inner_window->SkipItems;
  271. table->BackupWorkRect = inner_window->WorkRect;
  272. table->BackupCursorMaxPos = inner_window->DC.CursorMaxPos;
  273. // Disable output until user calls TableNextRow() or TableNextCell() leading to the TableUpdateLayout() call..
  274. // This is not strictly necessary but will reduce cases were misleading "out of table" output will be confusing to the user.
  275. // Because we cannot safely assert in EndTable() when no rows have been created, this seems like our best option.
  276. inner_window->SkipItems = true;
  277. // Update/lock which columns will be Active for the frame
  278. TableBeginUpdateColumns(table);
  279. return true;
  280. }
  281. void ImGui::TableBeginUpdateColumns(ImGuiTable* table)
  282. {
  283. // Handle resizing request
  284. // (We process this at the first TableBegin of the frame)
  285. // FIXME-TABLE: Preserve contents width _while resizing down_ until releasing.
  286. // FIXME-TABLE: Contains columns if our work area doesn't allow for scrolling.
  287. if (table->InstanceNo == 0)
  288. {
  289. if (table->ResizedColumn != -1 && table->ResizedColumnNextWidth != FLT_MAX)
  290. TableSetColumnWidth(table, &table->Columns[table->ResizedColumn], table->ResizedColumnNextWidth);
  291. table->LastResizedColumn = table->ResizedColumn;
  292. table->ResizedColumnNextWidth = FLT_MAX;
  293. table->ResizedColumn = -1;
  294. }
  295. // Handle reordering request
  296. // Note: we don't clear ReorderColumn after handling the request.
  297. if (table->InstanceNo == 0)
  298. {
  299. if (table->HeldHeaderColumn == -1 && table->ReorderColumn != -1)
  300. table->ReorderColumn = -1;
  301. table->HeldHeaderColumn = -1;
  302. if (table->ReorderColumn != -1 && table->ReorderColumnDir != 0)
  303. {
  304. // We need to handle reordering across hidden columns.
  305. // In the configuration below, moving C to the right of E will lead to:
  306. // ... C [D] E ---> ... [D] E C (Column name/index)
  307. // ... 2 3 4 ... 2 3 4 (Display order)
  308. const int reorder_dir = table->ReorderColumnDir;
  309. IM_ASSERT(reorder_dir == -1 || reorder_dir == +1);
  310. IM_ASSERT(table->Flags & ImGuiTableFlags_Reorderable);
  311. ImGuiTableColumn* src_column = &table->Columns[table->ReorderColumn];
  312. ImGuiTableColumn* dst_column = &table->Columns[(reorder_dir == -1) ? src_column->PrevActiveColumn : src_column->NextActiveColumn];
  313. IM_UNUSED(dst_column);
  314. const int src_order = src_column->IndexDisplayOrder;
  315. const int dst_order = dst_column->IndexDisplayOrder;
  316. src_column->IndexDisplayOrder = (ImS8)dst_order;
  317. for (int order_n = src_order + reorder_dir; order_n != dst_order + reorder_dir; order_n += reorder_dir)
  318. table->Columns[table->DisplayOrder[order_n]].IndexDisplayOrder -= (ImS8)reorder_dir;
  319. IM_ASSERT(dst_column->IndexDisplayOrder == dst_order - reorder_dir);
  320. // Display order is stored in both columns->IndexDisplayOrder and table->DisplayOrder[], rebuild the later from the former.
  321. for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
  322. table->DisplayOrder[table->Columns[column_n].IndexDisplayOrder] = (ImS8)column_n;
  323. table->ReorderColumnDir = 0;
  324. table->IsSettingsDirty = true;
  325. }
  326. }
  327. // Handle display order reset request
  328. if (table->IsResetDisplayOrderRequest)
  329. {
  330. for (int n = 0; n < table->ColumnsCount; n++)
  331. table->DisplayOrder[n] = table->Columns[n].IndexDisplayOrder = (ImU8)n;
  332. table->IsResetDisplayOrderRequest = false;
  333. table->IsSettingsDirty = true;
  334. }
  335. // Setup and lock Active state and order
  336. table->ColumnsActiveCount = 0;
  337. table->IsDefaultDisplayOrder = true;
  338. ImGuiTableColumn* last_active_column = NULL;
  339. bool want_column_auto_fit = false;
  340. for (int order_n = 0; order_n < table->ColumnsCount; order_n++)
  341. {
  342. const int column_n = table->DisplayOrder[order_n];
  343. if (column_n != order_n)
  344. table->IsDefaultDisplayOrder = false;
  345. ImGuiTableColumn* column = &table->Columns[column_n];
  346. column->NameOffset = -1;
  347. if (!(table->Flags & ImGuiTableFlags_Hideable) || (column->Flags & ImGuiTableColumnFlags_NoHide))
  348. column->NextIsActive = true;
  349. if (column->IsActive != column->NextIsActive)
  350. {
  351. column->IsActive = column->NextIsActive;
  352. table->IsSettingsDirty = true;
  353. if (!column->IsActive && column->SortOrder != -1)
  354. table->IsSortSpecsDirty = true;
  355. }
  356. if (column->SortOrder > 0 && !(table->Flags & ImGuiTableFlags_MultiSortable))
  357. table->IsSortSpecsDirty = true;
  358. if (column->AutoFitQueue != 0x00)
  359. want_column_auto_fit = true;
  360. ImU64 index_mask = (ImU64)1 << column_n;
  361. ImU64 display_order_mask = (ImU64)1 << column->IndexDisplayOrder;
  362. if (column->IsActive)
  363. {
  364. column->PrevActiveColumn = column->NextActiveColumn = -1;
  365. if (last_active_column)
  366. {
  367. last_active_column->NextActiveColumn = (ImS8)column_n;
  368. column->PrevActiveColumn = (ImS8)table->Columns.index_from_ptr(last_active_column);
  369. }
  370. column->IndexWithinActiveSet = (ImS8)table->ColumnsActiveCount;
  371. table->ColumnsActiveCount++;
  372. table->ActiveMaskByIndex |= index_mask;
  373. table->ActiveMaskByDisplayOrder |= display_order_mask;
  374. last_active_column = column;
  375. }
  376. else
  377. {
  378. column->IndexWithinActiveSet = -1;
  379. table->ActiveMaskByIndex &= ~index_mask;
  380. table->ActiveMaskByDisplayOrder &= ~display_order_mask;
  381. }
  382. IM_ASSERT(column->IndexWithinActiveSet <= column->IndexDisplayOrder);
  383. }
  384. table->VisibleMaskByIndex = table->ActiveMaskByIndex; // Columns will be masked out by TableUpdateLayout() when Clipped
  385. table->RightMostActiveColumn = (ImS8)(last_active_column ? table->Columns.index_from_ptr(last_active_column) : -1);
  386. // Disable child window clipping while fitting columns. This is not strictly necessary but makes it possible to avoid
  387. // the column fitting to wait until the first visible frame of the child container (may or not be a good thing).
  388. if (want_column_auto_fit && table->OuterWindow != table->InnerWindow)
  389. table->InnerWindow->SkipItems = false;
  390. }
  391. void ImGui::TableUpdateDrawChannels(ImGuiTable* table)
  392. {
  393. // Allocate draw channels.
  394. // - We allocate them following the storage order instead of the display order so reordering won't needlessly increase overall dormant memory cost
  395. // - We isolate headers draw commands in their own channels instead of just altering clip rects. This is in order to facilitate merging of draw commands.
  396. // - After crossing FreezeRowsCount, all columns see their current draw channel increased.
  397. // - We only use the dummy draw channel so we can push a null clipping rectangle into it without affecting other channels, while simplifying per-row/per-cell overhead. It will be empty and discarded when merged.
  398. // Draw channel allocation (before merging):
  399. // - NoClip --> 1+1 channels: background + foreground (same clip rect == 1 draw call)
  400. // - Clip --> 1+N channels
  401. // - FreezeRows || FreezeColumns --> 1+N*2 (unless scrolling value is zero)
  402. // - FreezeRows && FreezeColunns --> 2+N*2 (unless scrolling value is zero)
  403. const int freeze_row_multiplier = (table->FreezeRowsCount > 0) ? 2 : 1;
  404. const int channels_for_row = (table->Flags & ImGuiTableFlags_NoClipX) ? 1 : table->ColumnsActiveCount;
  405. const int channels_for_background = 1;
  406. const int channels_for_dummy = (table->ColumnsActiveCount < table->ColumnsCount || table->VisibleMaskByIndex != table->ActiveMaskByIndex) ? +1 : 0;
  407. const int channels_total = channels_for_background + (channels_for_row * freeze_row_multiplier) + channels_for_dummy;
  408. table->DrawSplitter.Split(table->InnerWindow->DrawList, channels_total);
  409. table->DummyDrawChannel = channels_for_dummy ? (ImS8)(channels_total - 1) : -1;
  410. int draw_channel_current = 1;
  411. for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
  412. {
  413. ImGuiTableColumn* column = &table->Columns[column_n];
  414. if (!column->IsClipped)
  415. {
  416. column->DrawChannelRowsBeforeFreeze = (ImS8)(draw_channel_current);
  417. column->DrawChannelRowsAfterFreeze = (ImS8)(draw_channel_current + (table->FreezeRowsCount > 0 ? channels_for_row : 0));
  418. if (!(table->Flags & ImGuiTableFlags_NoClipX))
  419. draw_channel_current++;
  420. }
  421. else
  422. {
  423. column->DrawChannelRowsBeforeFreeze = column->DrawChannelRowsAfterFreeze = table->DummyDrawChannel;
  424. }
  425. column->DrawChannelCurrent = column->DrawChannelRowsBeforeFreeze;
  426. }
  427. }
  428. // Adjust flags: default width mode + weighted columns are not allowed when auto extending
  429. static ImGuiTableColumnFlags TableFixColumnFlags(ImGuiTable* table, ImGuiTableColumnFlags flags)
  430. {
  431. // Sizing Policy
  432. if ((flags & ImGuiTableColumnFlags_WidthMask_) == 0)
  433. {
  434. if (table->Flags & ImGuiTableFlags_SizingPolicyFixedX)
  435. flags |= ((table->Flags & ImGuiTableFlags_Resizable) && !(flags & ImGuiTableColumnFlags_NoResize)) ? ImGuiTableColumnFlags_WidthFixed : ImGuiTableColumnFlags_WidthAlwaysAutoResize;
  436. else
  437. flags |= ImGuiTableColumnFlags_WidthStretch;
  438. }
  439. IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiTableColumnFlags_WidthMask_)); // Check that only 1 of each set is used.
  440. if ((flags & ImGuiTableColumnFlags_WidthAlwaysAutoResize))// || ((flags & ImGuiTableColumnFlags_WidthStretch) && (table->Flags & ImGuiTableFlags_SizingPolicyStretchX)))
  441. flags |= ImGuiTableColumnFlags_NoResize;
  442. //if ((flags & ImGuiTableColumnFlags_WidthStretch) && (table->Flags & ImGuiTableFlags_SizingPolicyFixedX))
  443. // flags = (flags & ~ImGuiTableColumnFlags_WidthMask_) | ImGuiTableColumnFlags_WidthFixed;
  444. // Sorting
  445. if ((flags & ImGuiTableColumnFlags_NoSortAscending) && (flags & ImGuiTableColumnFlags_NoSortDescending))
  446. flags |= ImGuiTableColumnFlags_NoSort;
  447. // Alignment
  448. //if ((flags & ImGuiTableColumnFlags_AlignMask_) == 0)
  449. // flags |= ImGuiTableColumnFlags_AlignCenter;
  450. //IM_ASSERT(ImIsPowerOfTwo(flags & ImGuiTableColumnFlags_AlignMask_)); // Check that only 1 of each set is used.
  451. return flags;
  452. }
  453. static void TableFixColumnSortDirection(ImGuiTableColumn* column)
  454. {
  455. // Handle NoSortAscending/NoSortDescending
  456. if (column->SortDirection == ImGuiSortDirection_Ascending && (column->Flags & ImGuiTableColumnFlags_NoSortAscending))
  457. column->SortDirection = ImGuiSortDirection_Descending;
  458. else if (column->SortDirection == ImGuiSortDirection_Descending && (column->Flags & ImGuiTableColumnFlags_NoSortDescending))
  459. column->SortDirection = ImGuiSortDirection_Ascending;
  460. }
  461. static float TableGetMinColumnWidth()
  462. {
  463. ImGuiContext& g = *GImGui;
  464. // return g.Style.ColumnsMinSpacing;
  465. return g.Style.FramePadding.x * 3.0f;
  466. }
  467. // Layout columns for the frame
  468. // Runs on the first call to TableNextRow(), to give a chance for TableSetupColumn() to be called first.
  469. // FIXME-TABLE: Our width (and therefore our WorkRect) will be minimal in the first frame for WidthAlwaysAutoResize columns,
  470. // increase feedback side-effect with widgets relying on WorkRect.Max.x. Maybe provide a default distribution for WidthAlwaysAutoResize columns?
  471. void ImGui::TableUpdateLayout(ImGuiTable* table)
  472. {
  473. IM_ASSERT(table->IsLayoutLocked == false);
  474. // Compute offset, clip rect for the frame
  475. const ImRect work_rect = table->WorkRect;
  476. const float padding_auto_x = table->CellPaddingX1; // Can't make auto padding larger than what WorkRect knows about so right-alignment matches.
  477. const float min_column_width = TableGetMinColumnWidth();
  478. int count_fixed = 0;
  479. float width_fixed = 0.0f;
  480. float total_weights = 0.0f;
  481. table->LeftMostStretchedColumnDisplayOrder = -1;
  482. for (int order_n = 0; order_n < table->ColumnsCount; order_n++)
  483. {
  484. if (!(table->ActiveMaskByDisplayOrder & ((ImU64)1 << order_n)))
  485. continue;
  486. const int column_n = table->DisplayOrder[order_n];
  487. ImGuiTableColumn* column = &table->Columns[column_n];
  488. // Adjust flags: default width mode + weighted columns are not allowed when auto extending
  489. // FIXME-TABLE: Clarify why we need to do this again here and not just in TableSetupColumn()
  490. column->Flags = TableFixColumnFlags(table, column->FlagsIn);
  491. // We have a unusual edge case where if the user doesn't call TableGetSortSpecs() but has sorting enabled
  492. // or varying sorting flags, we still want the sorting arrows to honor those flags.
  493. if (table->Flags & ImGuiTableFlags_Sortable)
  494. TableFixColumnSortDirection(column);
  495. if (column->Flags & (ImGuiTableColumnFlags_WidthAlwaysAutoResize | ImGuiTableColumnFlags_WidthFixed))
  496. {
  497. // Latch initial size for fixed columns
  498. count_fixed += 1;
  499. const bool init_size = (column->AutoFitQueue != 0x00) || (column->Flags & ImGuiTableColumnFlags_WidthAlwaysAutoResize);
  500. if (init_size)
  501. {
  502. // Combine width from regular rows + width from headers unless requested not to
  503. float width_request = (float)ImMax(column->ContentWidthRowsFrozen, column->ContentWidthRowsUnfrozen);
  504. if (!(table->Flags & ImGuiTableFlags_NoHeadersWidth) && !(column->Flags & ImGuiTableColumnFlags_NoHeaderWidth))
  505. width_request = ImMax(width_request, (float)column->ContentWidthHeadersDesired);
  506. column->WidthRequested = ImMax(width_request + padding_auto_x, min_column_width);
  507. // FIXME-TABLE: Increase minimum size during init frame to avoid biasing auto-fitting widgets (e.g. TextWrapped) too much.
  508. // Otherwise what tends to happen is that TextWrapped would output a very large height (= first frame scrollbar display very off + clipper would skip lots of items)
  509. // This is merely making the side-effect less extreme, but doesn't properly fixes it.
  510. if (column->AutoFitQueue > 0x01 && table->IsInitializing)
  511. column->WidthRequested = ImMax(column->WidthRequested, min_column_width * 4.0f);
  512. }
  513. width_fixed += column->WidthRequested;
  514. }
  515. else
  516. {
  517. IM_ASSERT(column->Flags & ImGuiTableColumnFlags_WidthStretch);
  518. IM_ASSERT(column->ResizeWeight > 0.0f);
  519. total_weights += column->ResizeWeight;
  520. if (table->LeftMostStretchedColumnDisplayOrder == -1)
  521. table->LeftMostStretchedColumnDisplayOrder = (ImS8)column->IndexDisplayOrder;
  522. }
  523. }
  524. // Layout
  525. const float width_spacings = table->CellSpacingX * (table->ColumnsActiveCount - 1);
  526. float width_avail;
  527. if ((table->Flags & ImGuiTableFlags_ScrollX) && (table->InnerWidth == 0.0f))
  528. width_avail = table->InnerClipRect.GetWidth() - width_spacings - 1.0f;
  529. else
  530. width_avail = work_rect.GetWidth() - width_spacings - 1.0f; // Remove -1.0f to cancel out the +1.0f we are doing in EndTable() to make last column line visible
  531. const float width_avail_for_stretched_columns = width_avail - width_fixed;
  532. float width_remaining_for_stretched_columns = width_avail_for_stretched_columns;
  533. // Apply final width based on requested widths
  534. // Mark some columns as not resizable
  535. int count_resizable = 0;
  536. table->ColumnsTotalWidth = width_spacings;
  537. for (int order_n = 0; order_n < table->ColumnsCount; order_n++)
  538. {
  539. if (!(table->ActiveMaskByDisplayOrder & ((ImU64)1 << order_n)))
  540. continue;
  541. ImGuiTableColumn* column = &table->Columns[table->DisplayOrder[order_n]];
  542. // Allocate width for stretched/weighted columns
  543. if (column->Flags & ImGuiTableColumnFlags_WidthStretch)
  544. {
  545. float weight_ratio = column->ResizeWeight / total_weights;
  546. column->WidthRequested = IM_FLOOR(ImMax(width_avail_for_stretched_columns * weight_ratio, min_column_width) + 0.01f);
  547. width_remaining_for_stretched_columns -= column->WidthRequested;
  548. // [Resize Rule 2] Resizing from right-side of a weighted column before a fixed column froward sizing to left-side of fixed column
  549. // We also need to copy the NoResize flag..
  550. if (column->NextActiveColumn != -1)
  551. if (ImGuiTableColumn* next_column = &table->Columns[column->NextActiveColumn])
  552. if (next_column->Flags & ImGuiTableColumnFlags_WidthFixed)
  553. column->Flags |= (next_column->Flags & ImGuiTableColumnFlags_NoDirectResize_);
  554. }
  555. // [Resize Rule 1] The right-most active column is not resizable if there is at least one Stretch column (see comments in TableResizeColumn().)
  556. if (column->NextActiveColumn == -1 && table->LeftMostStretchedColumnDisplayOrder != -1)
  557. column->Flags |= ImGuiTableColumnFlags_NoDirectResize_;
  558. if (!(column->Flags & ImGuiTableColumnFlags_NoResize))
  559. count_resizable++;
  560. // Assign final width, record width in case we will need to shrink
  561. column->WidthGiven = ImFloor(ImMax(column->WidthRequested, min_column_width));
  562. table->ColumnsTotalWidth += column->WidthGiven;
  563. }
  564. #if 0
  565. const float width_excess = table->ColumnsTotalWidth - work_rect.GetWidth();
  566. if ((table->Flags & ImGuiTableFlags_SizingPolicyStretchX) && width_excess > 0.0f)
  567. {
  568. // Shrink widths when the total does not fit
  569. // FIXME-TABLE: This is working but confuses/conflicts with manual resizing.
  570. // FIXME-TABLE: Policy to shrink down below below ideal/requested width if there's no room?
  571. g.ShrinkWidthBuffer.resize(table->ColumnsActiveCount);
  572. for (int order_n = 0, active_n = 0; order_n < table->ColumnsCount; order_n++)
  573. {
  574. if (!(table->ActiveMaskByDisplayOrder & ((ImU64)1 << order_n)))
  575. continue;
  576. const int column_n = table->DisplayOrder[order_n];
  577. g.ShrinkWidthBuffer[active_n].Index = column_n;
  578. g.ShrinkWidthBuffer[active_n].Width = table->Columns[column_n].WidthGiven;
  579. active_n++;
  580. }
  581. ShrinkWidths(g.ShrinkWidthBuffer.Data, g.ShrinkWidthBuffer.Size, width_excess);
  582. for (int n = 0; n < g.ShrinkWidthBuffer.Size; n++)
  583. table->Columns[g.ShrinkWidthBuffer.Data[n].Index].WidthGiven = ImMax(g.ShrinkWidthBuffer.Data[n].Width, min_column_size);
  584. // FIXME: Need to alter table->ColumnsTotalWidth
  585. }
  586. else
  587. #endif
  588. // Redistribute remainder width due to rounding (remainder width is < 1.0f * number of Stretch column)
  589. // Using right-to-left distribution (more likely to match resizing cursor), could be adjusted depending where the mouse cursor is and/or relative weights.
  590. // FIXME-TABLE: May be simpler to store floating width and floor final positions only
  591. // FIXME-TABLE: Make it optional? User might prefer to preserve pixel perfect same size?
  592. if (width_remaining_for_stretched_columns >= 1.0f)
  593. for (int order_n = table->ColumnsCount - 1; total_weights > 0.0f && width_remaining_for_stretched_columns >= 1.0f && order_n >= 0; order_n--)
  594. {
  595. if (!(table->ActiveMaskByDisplayOrder & ((ImU64)1 << order_n)))
  596. continue;
  597. ImGuiTableColumn* column = &table->Columns[table->DisplayOrder[order_n]];
  598. if (!(column->Flags & ImGuiTableColumnFlags_WidthStretch))
  599. continue;
  600. column->WidthRequested += 1.0f;
  601. column->WidthGiven += 1.0f;
  602. width_remaining_for_stretched_columns -= 1.0f;
  603. }
  604. // Setup final position, offset and clipping rectangles
  605. int active_n = 0;
  606. float offset_x = (table->FreezeColumnsCount > 0) ? table->OuterRect.Min.x : work_rect.Min.x;
  607. ImRect host_clip_rect = table->InnerClipRect;
  608. for (int order_n = 0; order_n < table->ColumnsCount; order_n++)
  609. {
  610. const int column_n = table->DisplayOrder[order_n];
  611. ImGuiTableColumn* column = &table->Columns[column_n];
  612. if (table->FreezeColumnsCount > 0 && table->FreezeColumnsCount == active_n)
  613. offset_x += work_rect.Min.x - table->OuterRect.Min.x;
  614. if (!(table->ActiveMaskByDisplayOrder & ((ImU64)1 << order_n)))
  615. {
  616. // Hidden column: clear a few fields and we are done with it for the remainder of the function.
  617. // We set a zero-width clip rect however we pay attention to set Min.y/Max.y properly to not interfere with the clipper.
  618. column->MinX = column->MaxX = offset_x;
  619. column->StartXRows = column->StartXHeaders = offset_x;
  620. column->WidthGiven = 0.0f;
  621. column->ClipRect.Min.x = offset_x;
  622. column->ClipRect.Min.y = work_rect.Min.y;
  623. column->ClipRect.Max.x = offset_x;
  624. column->ClipRect.Max.y = FLT_MAX;
  625. column->ClipRect.ClipWithFull(host_clip_rect);
  626. column->IsClipped = true;
  627. continue;
  628. }
  629. float max_x = FLT_MAX;
  630. if (table->Flags & ImGuiTableFlags_ScrollX)
  631. {
  632. // Frozen columns can't reach beyond visible width else scrolling will naturally break.
  633. if (order_n < table->FreezeColumnsRequest)
  634. max_x = table->InnerClipRect.Max.x - (table->FreezeColumnsRequest - order_n) * min_column_width;
  635. }
  636. else
  637. {
  638. // If horizontal scrolling if disabled, we apply a final lossless shrinking of columns in order to make sure they are all visible.
  639. // Because of this we also know that all of the columns will always fit in table->WorkRect and therefore in table->InnerRect (because ScrollX is off)
  640. max_x = table->WorkRect.Max.x - (table->ColumnsActiveCount - (column->IndexWithinActiveSet + 1)) * min_column_width;
  641. }
  642. if (offset_x + column->WidthGiven > max_x)
  643. column->WidthGiven = ImMax(max_x - offset_x, min_column_width);
  644. column->MinX = offset_x;
  645. column->MaxX = column->MinX + column->WidthGiven;
  646. //// A one pixel padding on the right side makes clipping more noticeable and contents look less cramped.
  647. column->ClipRect.Min.x = column->MinX;
  648. column->ClipRect.Min.y = work_rect.Min.y;
  649. column->ClipRect.Max.x = column->MaxX;// -1.0f;
  650. column->ClipRect.Max.y = FLT_MAX;
  651. column->ClipRect.ClipWithFull(host_clip_rect);
  652. column->IsClipped = (column->ClipRect.Max.x <= column->ClipRect.Min.x) && (column->AutoFitQueue & 1) == 0 && (column->CannotSkipItemsQueue & 1) == 0;
  653. if (column->IsClipped)
  654. {
  655. // Columns with the _WidthAlwaysAutoResize sizing policy will never be updated then.
  656. table->VisibleMaskByIndex &= ~((ImU64)1 << column_n);
  657. }
  658. else
  659. {
  660. // Starting cursor position
  661. column->StartXRows = column->StartXHeaders = column->MinX + table->CellPaddingX1;
  662. // Alignment
  663. // FIXME-TABLE: This align based on the whole column width, not per-cell, and therefore isn't useful in many cases.
  664. // (To be able to honor this we might be able to store a log of cells width, per row, for visible rows, but nav/programmatic scroll would have visible artifacts.)
  665. //if (column->Flags & ImGuiTableColumnFlags_AlignRight)
  666. // column->StartXRows = ImMax(column->StartXRows, column->MaxX - column->ContentWidthRowsUnfrozen);
  667. //else if (column->Flags & ImGuiTableColumnFlags_AlignCenter)
  668. // column->StartXRows = ImLerp(column->StartXRows, ImMax(column->StartXRows, column->MaxX - column->ContentWidthRowsUnfrozen), 0.5f);
  669. // Reset content width variables
  670. const float initial_max_pos_x = column->MinX + table->CellPaddingX1;
  671. column->ContentMaxPosRowsFrozen = column->ContentMaxPosRowsUnfrozen = initial_max_pos_x;
  672. column->ContentMaxPosHeadersUsed = column->ContentMaxPosHeadersDesired = initial_max_pos_x;
  673. }
  674. // Don't decrement auto-fit counters until container window got a chance to submit its items
  675. if (table->BackupSkipItems == false)
  676. {
  677. column->AutoFitQueue >>= 1;
  678. column->CannotSkipItemsQueue >>= 1;
  679. }
  680. if (active_n < table->FreezeColumnsCount)
  681. host_clip_rect.Min.x = ImMax(host_clip_rect.Min.x, column->MaxX + 2.0f);
  682. offset_x += column->WidthGiven + table->CellSpacingX;
  683. active_n++;
  684. }
  685. // Clear Resizable flag if none of our column are actually resizable (either via an explicit _NoResize flag, either because of using _WidthAlwaysAutoResize/_WidthStretch)
  686. // This will hide the resizing option from the context menu.
  687. if (count_resizable == 0 && (table->Flags & ImGuiTableFlags_Resizable))
  688. table->Flags &= ~ImGuiTableFlags_Resizable;
  689. // Allocate draw channels
  690. TableUpdateDrawChannels(table);
  691. // Borders
  692. if (table->Flags & ImGuiTableFlags_Resizable)
  693. TableUpdateBorders(table);
  694. // Reset fields after we used them in TableSetupResize()
  695. table->LastFirstRowHeight = 0.0f;
  696. table->IsLayoutLocked = true;
  697. table->IsUsingHeaders = false;
  698. // Context menu
  699. if (table->IsContextPopupOpen && table->InstanceNo == table->InstanceInteracted)
  700. {
  701. if (BeginPopup("##TableContextMenu"))
  702. {
  703. TableDrawContextMenu(table, table->ContextPopupColumn);
  704. EndPopup();
  705. }
  706. else
  707. {
  708. table->IsContextPopupOpen = false;
  709. }
  710. }
  711. // Initial state
  712. ImGuiWindow* inner_window = table->InnerWindow;
  713. if (table->Flags & ImGuiTableFlags_NoClipX)
  714. table->DrawSplitter.SetCurrentChannel(inner_window->DrawList, 1);
  715. else
  716. inner_window->DrawList->PushClipRect(inner_window->ClipRect.Min, inner_window->ClipRect.Max, false);
  717. }
  718. // Process interaction on resizing borders. Actual size change will be applied in EndTable()
  719. // - Set table->HoveredColumnBorder with a short delay/timer to reduce feedback noise
  720. // - Submit ahead of table contents and header, use ImGuiButtonFlags_AllowItemOverlap to prioritize widgets overlapping the same area.
  721. void ImGui::TableUpdateBorders(ImGuiTable* table)
  722. {
  723. ImGuiContext& g = *GImGui;
  724. IM_ASSERT(table->Flags & ImGuiTableFlags_Resizable);
  725. // At this point OuterRect height may be zero or under actual final height, so we rely on temporal coherency and use
  726. // the final height from last frame. Because this is only affecting _interaction_ with columns, it is not really problematic.
  727. // (whereas the actual visual will be displayed in EndTable() and using the current frame height)
  728. // Actual columns highlight/render will be performed in EndTable() and not be affected.
  729. const bool borders_full_height = (table->IsUsingHeaders == false) || (table->Flags & ImGuiTableFlags_BordersVFullHeight);
  730. const float hit_half_width = TABLE_RESIZE_SEPARATOR_HALF_THICKNESS;
  731. const float hit_y1 = table->OuterRect.Min.y;
  732. const float hit_y2_full = ImMax(table->OuterRect.Max.y, hit_y1 + table->LastOuterHeight);
  733. const float hit_y2 = borders_full_height ? hit_y2_full : (hit_y1 + table->LastFirstRowHeight);
  734. const float mouse_x_hover_body = (g.IO.MousePos.y >= hit_y1 && g.IO.MousePos.y < hit_y2_full) ? g.IO.MousePos.x : FLT_MAX;
  735. for (int order_n = 0; order_n < table->ColumnsCount; order_n++)
  736. {
  737. if (!(table->ActiveMaskByDisplayOrder & ((ImU64)1 << order_n)))
  738. continue;
  739. const int column_n = table->DisplayOrder[order_n];
  740. ImGuiTableColumn* column = &table->Columns[column_n];
  741. // Detect hovered column:
  742. // - we perform an unusually low-level check here.. not using IsMouseHoveringRect() to avoid touch padding.
  743. // - we don't care about the full set of IsItemHovered() feature either.
  744. if (mouse_x_hover_body >= column->MinX && mouse_x_hover_body < column->MaxX)
  745. table->HoveredColumnBody = (ImS8)column_n;
  746. if (column->Flags & (ImGuiTableColumnFlags_NoResize | ImGuiTableColumnFlags_NoDirectResize_))
  747. continue;
  748. ImGuiID column_id = table->ID + (table->InstanceNo * table->ColumnsCount) + column_n;
  749. ImRect hit_rect(column->MaxX - hit_half_width, hit_y1, column->MaxX + hit_half_width, hit_y2);
  750. //GetForegroundDrawList()->AddRect(hit_rect.Min, hit_rect.Max, IM_COL32(255, 0, 0, 100));
  751. KeepAliveID(column_id);
  752. bool hovered = false, held = false;
  753. bool pressed = ButtonBehavior(hit_rect, column_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_AllowItemOverlap | ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnDoubleClick);
  754. if (pressed && IsMouseDoubleClicked(0) && !(column->Flags & ImGuiTableColumnFlags_WidthStretch))
  755. {
  756. // FIXME-TABLE: Double-clicking on column edge could auto-fit weighted column?
  757. TableSetColumnAutofit(table, column_n);
  758. ClearActiveID();
  759. held = hovered = false;
  760. }
  761. if (held)
  762. {
  763. table->ResizedColumn = (ImS8)column_n;
  764. table->InstanceInteracted = table->InstanceNo;
  765. }
  766. if ((hovered && g.HoveredIdTimer > TABLE_RESIZE_SEPARATOR_FEEDBACK_TIMER) || held)
  767. {
  768. table->HoveredColumnBorder = (ImS8)column_n;
  769. SetMouseCursor(ImGuiMouseCursor_ResizeEW);
  770. }
  771. }
  772. }
  773. void ImGui::EndTable()
  774. {
  775. ImGuiContext& g = *GImGui;
  776. ImGuiTable* table = g.CurrentTable;
  777. IM_ASSERT(table != NULL && "Only call EndTable() is BeginTable() returns true!");
  778. // This assert would be very useful to catch a common error... unfortunately it would probably trigger in some cases,
  779. // and for consistency user may sometimes output empty tables (and still benefit from e.g. outer border)
  780. //IM_ASSERT(table->IsLayoutLocked && "Table unused: never called TableNextRow(), is that the intent?");
  781. // If the user never got to call TableNextRow() or TableNextCell(), we call layout ourselves to ensure all our
  782. // code paths are consistent (instead of just hoping that TableBegin/TableEnd will work), get borders drawn, etc.
  783. if (!table->IsLayoutLocked)
  784. TableUpdateLayout(table);
  785. const ImGuiTableFlags flags = table->Flags;
  786. ImGuiWindow* inner_window = table->InnerWindow;
  787. ImGuiWindow* outer_window = table->OuterWindow;
  788. IM_ASSERT(inner_window == g.CurrentWindow);
  789. IM_ASSERT(outer_window == inner_window || outer_window == inner_window->ParentWindow);
  790. if (table->IsInsideRow)
  791. TableEndRow(table);
  792. // Finalize table height
  793. inner_window->SkipItems = table->BackupSkipItems;
  794. inner_window->DC.CursorMaxPos = table->BackupCursorMaxPos;
  795. if (inner_window != outer_window)
  796. {
  797. table->OuterRect.Max.y = ImMax(table->OuterRect.Max.y, inner_window->Pos.y + inner_window->Size.y);
  798. inner_window->DC.CursorMaxPos.y = table->RowPosY2;
  799. }
  800. else if (!(flags & ImGuiTableFlags_NoHostExtendY))
  801. {
  802. table->OuterRect.Max.y = ImMax(table->OuterRect.Max.y, inner_window->DC.CursorPos.y);
  803. inner_window->DC.CursorMaxPos.y = table->RowPosY2;
  804. }
  805. table->WorkRect.Max.y = ImMax(table->WorkRect.Max.y, table->OuterRect.Max.y);
  806. table->LastOuterHeight = table->OuterRect.GetHeight();
  807. // Store content width reference for each column
  808. float max_pos_x = inner_window->DC.CursorMaxPos.x;
  809. for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
  810. {
  811. ImGuiTableColumn* column = &table->Columns[column_n];
  812. // Store content width (for both Headers and Rows)
  813. //float ref_x = column->MinX;
  814. float ref_x_rows = column->StartXRows - table->CellPaddingX1;
  815. float ref_x_headers = column->StartXHeaders - table->CellPaddingX1;
  816. column->ContentWidthRowsFrozen = (ImS16)ImMax(0.0f, column->ContentMaxPosRowsFrozen - ref_x_rows);
  817. column->ContentWidthRowsUnfrozen = (ImS16)ImMax(0.0f, column->ContentMaxPosRowsUnfrozen - ref_x_rows);
  818. column->ContentWidthHeadersUsed = (ImS16)ImMax(0.0f, column->ContentMaxPosHeadersUsed - ref_x_headers);
  819. column->ContentWidthHeadersDesired = (ImS16)ImMax(0.0f, column->ContentMaxPosHeadersDesired - ref_x_headers);
  820. if (table->ActiveMaskByIndex & ((ImU64)1 << column_n))
  821. max_pos_x = ImMax(max_pos_x, column->MaxX);
  822. }
  823. // Add an extra 1 pixel so we can see the last column vertical line if it lies on the right-most edge.
  824. inner_window->DC.CursorMaxPos.x = max_pos_x + 1;
  825. if (!(flags & ImGuiTableFlags_NoClipX))
  826. inner_window->DrawList->PopClipRect();
  827. inner_window->ClipRect = inner_window->DrawList->_ClipRectStack.back();
  828. // Draw borders
  829. if ((flags & ImGuiTableFlags_Borders) != 0)
  830. TableDrawBorders(table);
  831. // Flatten channels and merge draw calls
  832. table->DrawSplitter.SetCurrentChannel(inner_window->DrawList, 0);
  833. TableDrawMergeChannels(table);
  834. // When releasing a column being resized, scroll to keep the resulting column in sight
  835. const float min_column_width = TableGetMinColumnWidth();
  836. if (!(table->Flags & ImGuiTableFlags_ScrollX) && inner_window != outer_window)
  837. {
  838. inner_window->Scroll.x = 0.0f;
  839. }
  840. else if (table->LastResizedColumn != -1 && table->ResizedColumn == -1 && inner_window->ScrollbarX && table->InstanceInteracted == table->InstanceNo)
  841. {
  842. ImGuiTableColumn* column = &table->Columns[table->LastResizedColumn];
  843. if (column->MaxX < table->InnerClipRect.Min.x)
  844. SetScrollFromPosX(inner_window, column->MaxX - inner_window->Pos.x - min_column_width, 1.0f);
  845. else if (column->MaxX > table->InnerClipRect.Max.x)
  846. SetScrollFromPosX(inner_window, column->MaxX - inner_window->Pos.x + min_column_width, 1.0f);
  847. }
  848. // Apply resizing/dragging at the end of the frame
  849. if (table->ResizedColumn != -1)
  850. {
  851. ImGuiTableColumn* column = &table->Columns[table->ResizedColumn];
  852. const float new_x2 = (g.IO.MousePos.x - g.ActiveIdClickOffset.x + TABLE_RESIZE_SEPARATOR_HALF_THICKNESS);
  853. const float new_width = ImFloor(new_x2 - column->MinX);
  854. table->ResizedColumnNextWidth = new_width;
  855. }
  856. // Layout in outer window
  857. inner_window->WorkRect = table->BackupWorkRect;
  858. inner_window->SkipItems = table->BackupSkipItems;
  859. outer_window->DC.CursorPos = table->OuterRect.Min;
  860. outer_window->DC.ColumnsOffset.x = 0.0f;
  861. if (inner_window != outer_window)
  862. {
  863. // Override EndChild's ItemSize with our own to enable auto-resize on the X axis when possible
  864. float backup_outer_cursor_pos_x = outer_window->DC.CursorPos.x;
  865. EndChild();
  866. outer_window->DC.CursorMaxPos.x = backup_outer_cursor_pos_x + table->ColumnsTotalWidth + 1.0f + inner_window->ScrollbarSizes.x;
  867. }
  868. else
  869. {
  870. PopID();
  871. ImVec2 item_size = table->OuterRect.GetSize();
  872. item_size.x = table->ColumnsTotalWidth;
  873. ItemSize(item_size);
  874. }
  875. // Save settings
  876. if (table->IsSettingsDirty)
  877. TableSaveSettings(table);
  878. // Clear or restore current table, if any
  879. IM_ASSERT(g.CurrentWindow == outer_window);
  880. IM_ASSERT(g.CurrentTable == table);
  881. outer_window->DC.CurrentTable = NULL;
  882. g.CurrentTableStack.pop_back();
  883. g.CurrentTable = g.CurrentTableStack.Size ? g.Tables.GetByIndex(g.CurrentTableStack.back().Index) : NULL;
  884. }
  885. // FIXME-TABLE: This is a mess, need to redesign how we render borders.
  886. void ImGui::TableDrawBorders(ImGuiTable* table)
  887. {
  888. ImGuiWindow* inner_window = table->InnerWindow;
  889. ImGuiWindow* outer_window = table->OuterWindow;
  890. table->DrawSplitter.SetCurrentChannel(inner_window->DrawList, 0);
  891. if (inner_window->Hidden || !table->HostClipRect.Overlaps(table->InnerClipRect))
  892. return;
  893. ImDrawList* inner_drawlist = inner_window->DrawList;
  894. ImDrawList* outer_drawlist = outer_window->DrawList;
  895. // Draw inner border and resizing feedback
  896. const float draw_y1 = table->OuterRect.Min.y;
  897. float draw_y2_base = (table->FreezeRowsCount >= 1 ? table->OuterRect.Min.y : table->WorkRect.Min.y) + table->LastFirstRowHeight;
  898. float draw_y2_full = table->OuterRect.Max.y;
  899. ImU32 border_base_col;
  900. if (!table->IsUsingHeaders || (table->Flags & ImGuiTableFlags_BordersVFullHeight))
  901. {
  902. draw_y2_base = draw_y2_full;
  903. border_base_col = table->BorderColorLight;
  904. }
  905. else
  906. {
  907. border_base_col = table->BorderColorStrong;
  908. }
  909. if ((table->Flags & ImGuiTableFlags_BordersVOuter) && (table->InnerWindow == table->OuterWindow))
  910. inner_drawlist->AddLine(ImVec2(table->OuterRect.Min.x, draw_y1), ImVec2(table->OuterRect.Min.x, draw_y2_base), border_base_col, 1.0f);
  911. if (table->Flags & ImGuiTableFlags_BordersVInner)
  912. {
  913. for (int order_n = 0; order_n < table->ColumnsCount; order_n++)
  914. {
  915. if (!(table->ActiveMaskByDisplayOrder & ((ImU64)1 << order_n)))
  916. continue;
  917. const int column_n = table->DisplayOrder[order_n];
  918. ImGuiTableColumn* column = &table->Columns[column_n];
  919. const bool is_hovered = (table->HoveredColumnBorder == column_n);
  920. const bool is_resized = (table->ResizedColumn == column_n) && (table->InstanceInteracted == table->InstanceNo);
  921. const bool is_resizable = (column->Flags & (ImGuiTableColumnFlags_NoResize | ImGuiTableColumnFlags_NoDirectResize_)) == 0;
  922. bool draw_right_border = (column->MaxX <= table->InnerClipRect.Max.x) || (is_resized || is_hovered);
  923. if (column->NextActiveColumn == -1 && !is_resizable)
  924. draw_right_border = false;
  925. if (draw_right_border && column->MaxX > column->ClipRect.Min.x) // FIXME-TABLE FIXME-STYLE: Assume BorderSize==1, this is problematic if we want to increase the border size..
  926. {
  927. // Draw in outer window so right-most column won't be clipped
  928. // Always draw full height border when:
  929. // - not using headers
  930. // - user specify ImGuiTableFlags_BordersFullHeight
  931. // - being interacted with
  932. // - on the delimitation of frozen column scrolling
  933. const ImU32 col = is_resized ? GetColorU32(ImGuiCol_SeparatorActive) : is_hovered ? GetColorU32(ImGuiCol_SeparatorHovered) : border_base_col;
  934. float draw_y2 = draw_y2_base;
  935. if (is_hovered || is_resized || (table->FreezeColumnsCount != -1 && table->FreezeColumnsCount == order_n + 1))
  936. draw_y2 = draw_y2_full;
  937. inner_drawlist->AddLine(ImVec2(column->MaxX, draw_y1), ImVec2(column->MaxX, draw_y2), col, 1.0f);
  938. }
  939. }
  940. }
  941. // Draw outer border
  942. if (table->Flags & ImGuiTableFlags_BordersOuter)
  943. {
  944. // Display outer border offset by 1 which is a simple way to display it without adding an extra draw call
  945. // (Without the offset, in outer_window it would be rendered behind cells, because child windows are above their parent.
  946. // In inner_window, it won't reach out over scrollbars. Another weird solution would be to display part of it in inner window,
  947. // and the part that's over scrollbars in the outer window..)
  948. // Either solution currently won't allow us to use a larger border size: the border would clipped.
  949. ImRect outer_border = table->OuterRect;
  950. const ImU32 outer_col = table->BorderColorStrong;
  951. if (inner_window != outer_window)
  952. outer_border.Expand(1.0f);
  953. if ((table->Flags & ImGuiTableFlags_BordersOuter) == ImGuiTableFlags_BordersOuter)
  954. outer_drawlist->AddRect(outer_border.Min, outer_border.Max, outer_col);
  955. else if (table->Flags & ImGuiTableFlags_BordersVOuter)
  956. {
  957. outer_drawlist->AddLine(outer_border.Min, ImVec2(outer_border.Min.x, outer_border.Max.y), outer_col);
  958. outer_drawlist->AddLine(ImVec2(outer_border.Max.x, outer_border.Min.y), outer_border.Max, outer_col);
  959. }
  960. else if (table->Flags & ImGuiTableFlags_BordersHOuter)
  961. {
  962. outer_drawlist->AddLine(outer_border.Min, ImVec2(outer_border.Max.x, outer_border.Min.y), outer_col);
  963. outer_drawlist->AddLine(ImVec2(outer_border.Min.x, outer_border.Max.y), outer_border.Max, outer_col);
  964. }
  965. }
  966. if ((table->Flags & ImGuiTableFlags_BordersHInner) && table->RowPosY2 < table->OuterRect.Max.y)
  967. {
  968. // Draw bottom-most row border
  969. const float border_y = table->RowPosY2;
  970. if (border_y >= table->BackgroundClipRect.Min.y && border_y < table->BackgroundClipRect.Max.y)
  971. inner_drawlist->AddLine(ImVec2(table->BorderX1, border_y), ImVec2(table->BorderX2, border_y), table->BorderColorLight);
  972. }
  973. }
  974. static void TableUpdateColumnsWeightFromWidth(ImGuiTable* table)
  975. {
  976. IM_ASSERT(table->LeftMostStretchedColumnDisplayOrder != -1);
  977. // Measure existing quantity
  978. float visible_weight = 0.0f;
  979. float visible_width = 0.0f;
  980. for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
  981. {
  982. ImGuiTableColumn* column = &table->Columns[column_n];
  983. if (!column->IsActive || !(column->Flags & ImGuiTableColumnFlags_WidthStretch))
  984. continue;
  985. visible_weight += column->ResizeWeight;
  986. visible_width += column->WidthRequested;
  987. }
  988. IM_ASSERT(visible_weight > 0.0f && visible_width > 0.0f);
  989. // Apply new weights
  990. for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
  991. {
  992. ImGuiTableColumn* column = &table->Columns[column_n];
  993. if (!column->IsActive || !(column->Flags & ImGuiTableColumnFlags_WidthStretch))
  994. continue;
  995. column->ResizeWeight = (column->WidthRequested + 0.0f) / visible_width;
  996. }
  997. }
  998. void ImGui::TableSetColumnWidth(ImGuiTable* table, ImGuiTableColumn* column_0, float column_0_width)
  999. {
  1000. // Constraints
  1001. float min_width = TableGetMinColumnWidth();
  1002. float max_width_0 = FLT_MAX;
  1003. if (!(table->Flags & ImGuiTableFlags_ScrollX))
  1004. max_width_0 = (table->WorkRect.Max.x - column_0->MinX) - (table->ColumnsActiveCount - (column_0->IndexWithinActiveSet + 1)) * min_width;
  1005. column_0_width = ImClamp(column_0_width, min_width, max_width_0);
  1006. // Compare both requested and actual given width to avoid overwriting requested width when column is stuck (minimum size, bounded)
  1007. if (column_0->WidthGiven == column_0_width || column_0->WidthRequested == column_0_width)
  1008. return;
  1009. ImGuiTableColumn* column_1 = (column_0->NextActiveColumn != -1) ? &table->Columns[column_0->NextActiveColumn] : NULL;
  1010. // In this surprisingly not simple because of how we support mixing Fixed and Stretch columns.
  1011. // When forwarding resize from Wn| to Fn+1| we need to be considerate of the _NoResize flag on Fn+1.
  1012. // FIXME-TABLE: Find a way to rewrite all of this so interactions feel more consistent for the user.
  1013. // Scenarios:
  1014. // - F1 F2 F3 resize from F1| or F2| --> ok: alter ->WidthRequested of Fixed column. Subsequent columns will be offset.
  1015. // - F1 F2 F3 resize from F3| --> ok: alter ->WidthRequested of Fixed column. If active, ScrollX extent can be altered.
  1016. // - F1 F2 W3 resize from F1| or F2| --> ok: alter ->WidthRequested of Fixed column. If active, ScrollX extent can be altered, but it doesn't make much sense as the Weighted column will always be minimal size.
  1017. // - F1 F2 W3 resize from W3| --> ok: no-op (disabled by Resize Rule 1)
  1018. // - W1 W2 W3 resize from W1| or W2| --> FIXME
  1019. // - W1 W2 W3 resize from W3| --> ok: no-op (disabled by Resize Rule 1)
  1020. // - W1 F2 F3 resize from F3| --> ok: no-op (disabled by Resize Rule 1)
  1021. // - W1 F2 resize from F2| --> ok: no-op (disabled by Resize Rule 1)
  1022. // - W1 W2 F3 resize from W1| or W2| --> ok
  1023. // - W1 F2 W3 resize from W1| or F2| --> FIXME
  1024. // - F1 W2 F3 resize from W2| --> ok
  1025. // - W1 F2 F3 resize from W1| --> ok: equivalent to resizing |F2. F3 will not move. (forwarded by Resize Rule 2)
  1026. // - W1 F2 F3 resize from F2| --> FIXME should resize F2, F3 and not have effect on W1 (Stretch columns are _before_ the Fixed column).
  1027. // Rules:
  1028. // - [Resize Rule 1] Can't resize from right of right-most visible column if there is any Stretch column. Implemented in TableUpdateLayout().
  1029. // - [Resize Rule 2] Resizing from right-side of a Stretch column before a fixed column froward sizing to left-side of fixed column.
  1030. // - [Resize Rule 3] If we are are followed by a fixed column and we have a Stretch column before, we need to ensure that our left border won't move.
  1031. if (column_0->Flags & ImGuiTableColumnFlags_WidthFixed)
  1032. {
  1033. // [Resize Rule 3] If we are are followed by a fixed column and we have a Stretch column before, we need to
  1034. // ensure that our left border won't move, which we can do by making sure column_a/column_b resizes cancels each others.
  1035. if (column_1 && (column_1->Flags & ImGuiTableColumnFlags_WidthFixed))
  1036. if (table->LeftMostStretchedColumnDisplayOrder != -1 && table->LeftMostStretchedColumnDisplayOrder < column_0->IndexDisplayOrder)
  1037. {
  1038. // (old_a + old_b == new_a + new_b) --> (new_a == old_a + old_b - new_b)
  1039. float column_1_width = ImMax(column_1->WidthRequested - (column_0_width - column_0->WidthRequested), min_width);
  1040. column_0_width = column_0->WidthRequested + column_1->WidthRequested - column_1_width;
  1041. column_1->WidthRequested = column_1_width;
  1042. }
  1043. // Apply
  1044. //IMGUI_DEBUG_LOG("TableSetColumnWidth(%d, %.1f->%.1f)\n", column_0_idx, column_0->WidthRequested, column_0_width);
  1045. column_0->WidthRequested = column_0_width;
  1046. }
  1047. else if (column_0->Flags & ImGuiTableColumnFlags_WidthStretch)
  1048. {
  1049. // [Resize Rule 2]
  1050. if (column_1 && (column_1->Flags & ImGuiTableColumnFlags_WidthFixed))
  1051. {
  1052. float off = (column_0->WidthGiven - column_0_width);
  1053. float column_1_width = column_1->WidthGiven + off;
  1054. column_1->WidthRequested = ImMax(min_width, column_1_width);
  1055. return;
  1056. }
  1057. // (old_a + old_b == new_a + new_b) --> (new_a == old_a + old_b - new_b)
  1058. float column_1_width = ImMax(column_1->WidthRequested - (column_0_width - column_0->WidthRequested), min_width);
  1059. column_0_width = column_0->WidthRequested + column_1->WidthRequested - column_1_width;
  1060. column_1->WidthRequested = column_1_width;
  1061. column_0->WidthRequested = column_0_width;
  1062. TableUpdateColumnsWeightFromWidth(table);
  1063. }
  1064. table->IsSettingsDirty = true;
  1065. }
  1066. // Columns where the contents didn't stray off their local clip rectangle can be merged into a same draw command.
  1067. // To achieve this we merge their clip rect and make them contiguous in the channel list so they can be merged.
  1068. // So here we'll reorder the draw cmd which can be merged, by arranging them into a maximum of 4 distinct groups:
  1069. //
  1070. // 1 group: 2 groups: 2 groups: 4 groups:
  1071. // [ 0. ] no freeze [ 0. ] row freeze [ 01 ] col freeze [ 01 ] row+col freeze
  1072. // [ .. ] or no scroll [ 1. ] and v-scroll [ .. ] and h-scroll [ 23 ] and v+h-scroll
  1073. //
  1074. // Each column itself can use 1 channel (row freeze disabled) or 2 channels (row freeze enabled).
  1075. // When the contents of a column didn't stray off its limit, we move its channels into the corresponding group
  1076. // based on its position (within frozen rows/columns set or not).
  1077. // At the end of the operation our 1-4 groups will each have a ImDrawCmd using the same ClipRect, and they will be merged by the DrawSplitter.Merge() call.
  1078. //
  1079. // Column channels will not be merged into one of the 1-4 groups in the following cases:
  1080. // - The contents stray off its clipping rectangle (we only compare the MaxX value, not the MinX value).
  1081. // Direct ImDrawList calls won't be noticed so if you use them make sure the ImGui:: bounds matches, by e.g. calling SetCursorScreenPos().
  1082. // - The channel uses more than one draw command itself (we drop all our merging stuff here.. we could do better but it's going to be rare)
  1083. //
  1084. // This function is particularly tricky to understand.. take a breath.
  1085. void ImGui::TableDrawMergeChannels(ImGuiTable* table)
  1086. {
  1087. ImGuiContext& g = *GImGui;
  1088. ImDrawListSplitter* splitter = &table->DrawSplitter;
  1089. const bool is_frozen_v = (table->FreezeRowsCount > 0);
  1090. const bool is_frozen_h = (table->FreezeColumnsCount > 0);
  1091. int merge_set_mask = 0;
  1092. int merge_set_channels_count[4] = { 0 };
  1093. ImU64 merge_set_channels_mask[4] = { 0 };
  1094. ImRect merge_set_clip_rect[4];
  1095. for (int n = 0; n < IM_ARRAYSIZE(merge_set_clip_rect); n++)
  1096. merge_set_clip_rect[n] = ImVec4(+FLT_MAX, +FLT_MAX, -FLT_MAX, -FLT_MAX);
  1097. bool merge_set_all_fit_within_inner_rect = (table->Flags & ImGuiTableFlags_NoHostExtendY) == 0;
  1098. // 1. Scan channels and take note of those who can be merged
  1099. for (int order_n = 0; order_n < table->ColumnsCount; order_n++)
  1100. {
  1101. if (!(table->ActiveMaskByDisplayOrder & ((ImU64)1 << order_n)))
  1102. continue;
  1103. const int column_n = table->DisplayOrder[order_n];
  1104. ImGuiTableColumn* column = &table->Columns[column_n];
  1105. const int merge_set_sub_count = is_frozen_v ? 2 : 1;
  1106. for (int merge_set_sub_n = 0; merge_set_sub_n < merge_set_sub_count; merge_set_sub_n++)
  1107. {
  1108. const int channel_no = (merge_set_sub_n == 0) ? column->DrawChannelRowsBeforeFreeze : column->DrawChannelRowsAfterFreeze;
  1109. // Don't attempt to merge if there are multiple calls within the column
  1110. ImDrawChannel* src_channel = &splitter->_Channels[channel_no];
  1111. if (src_channel->_CmdBuffer.Size > 0 && src_channel->_CmdBuffer.back().ElemCount == 0)
  1112. src_channel->_CmdBuffer.pop_back();
  1113. if (src_channel->_CmdBuffer.Size != 1)
  1114. continue;
  1115. // Find out the width of this merge set and check if it will fit in our column.
  1116. float width_contents;
  1117. if (merge_set_sub_count == 1) // No row freeze (same as testing !is_frozen_v)
  1118. width_contents = ImMax(column->ContentWidthRowsUnfrozen, column->ContentWidthHeadersUsed);
  1119. else if (merge_set_sub_n == 0) // Row freeze: use width before freeze
  1120. width_contents = ImMax(column->ContentWidthRowsFrozen, column->ContentWidthHeadersUsed);
  1121. else // Row freeze: use width after freeze
  1122. width_contents = column->ContentWidthRowsUnfrozen;
  1123. if (width_contents > column->WidthGiven && !(column->Flags & ImGuiTableColumnFlags_NoClipX))
  1124. continue;
  1125. const int dst_merge_set_n = (is_frozen_h && column_n < table->FreezeColumnsCount ? 0 : 2) + (is_frozen_v ? merge_set_sub_n : 1);
  1126. IM_ASSERT(merge_set_channels_count[dst_merge_set_n] < (int)sizeof(merge_set_channels_mask[dst_merge_set_n]) * 8);
  1127. merge_set_mask |= (1 << dst_merge_set_n);
  1128. merge_set_channels_mask[dst_merge_set_n] |= (ImU64)1 << channel_no;
  1129. merge_set_channels_count[dst_merge_set_n]++;
  1130. merge_set_clip_rect[dst_merge_set_n].Add(src_channel->_CmdBuffer[0].ClipRect);
  1131. // If we end with a single set and hosted by the outer window, we'll attempt to merge our draw command with
  1132. // the existing outer window command. But we can only do so if our columns all fit within the expected clip rect,
  1133. // otherwise clipping will be incorrect when ScrollX is disabled.
  1134. // FIXME-TABLE FIXME-WORKRECT: We are wasting a merge opportunity on tables without scrolling if column don't fit within host clip rect, solely because of the half-padding difference between window->WorkRect and window->InnerClipRect
  1135. // 2019/10/22: (1) This is breaking table_2_draw_calls but I cannot seem to repro what it is attempting to fix...
  1136. // cf git fce2e8dc "Fixed issue with clipping when outerwindow==innerwindow / support ScrollH without ScrollV."
  1137. // 2019/10/22: (2) Clamping code in TableUpdateLayout() seemingly made this not necessary...
  1138. #if 0
  1139. if (column->MinX < table->InnerClipRect.Min.x || column->MaxX > table->InnerClipRect.Max.x)
  1140. merge_set_all_fit_within_inner_rect = false;
  1141. #endif
  1142. }
  1143. // Invalidate current draw channel (we don't clear DrawChannelBeforeRowFreeze/DrawChannelAfterRowFreeze solely to facilitate debugging)
  1144. column->DrawChannelCurrent = -1;
  1145. }
  1146. // 2. Rewrite channel list in our preferred order
  1147. if (merge_set_mask != 0)
  1148. {
  1149. // Use shared temporary storage so the allocation gets amortized
  1150. g.DrawChannelsTempMergeBuffer.resize(splitter->_Count - 1);
  1151. ImDrawChannel* dst_tmp = g.DrawChannelsTempMergeBuffer.Data;
  1152. ImU64 remaining_mask = ((splitter->_Count < 64) ? ((ImU64)1 << splitter->_Count) - 1 : ~(ImU64)0) & ~1;
  1153. const bool may_extend_clip_rect_to_host_rect = ImIsPowerOfTwo(merge_set_mask);
  1154. for (int merge_set_n = 0; merge_set_n < 4; merge_set_n++)
  1155. if (merge_set_channels_count[merge_set_n])
  1156. {
  1157. ImU64 merge_channels_mask = merge_set_channels_mask[merge_set_n];
  1158. ImRect merge_clip_rect = merge_set_clip_rect[merge_set_n];
  1159. if (may_extend_clip_rect_to_host_rect)
  1160. {
  1161. //GetOverlayDrawList()->AddRect(table->HostClipRect.Min, table->HostClipRect.Max, IM_COL32(255, 0, 0, 200), 0.0f, ~0, 3.0f);
  1162. //GetOverlayDrawList()->AddRect(table->InnerClipRect.Min, table->InnerClipRect.Max, IM_COL32(0, 255, 0, 200), 0.0f, ~0, 1.0f);
  1163. //GetOverlayDrawList()->AddRect(merge_clip_rect.Min, merge_clip_rect.Max, IM_COL32(255, 0, 0, 200), 0.0f, ~0, 2.0f);
  1164. merge_clip_rect.Add(merge_set_all_fit_within_inner_rect ? table->HostClipRect : table->InnerClipRect);
  1165. //GetOverlayDrawList()->AddRect(merge_clip_rect.Min, merge_clip_rect.Max, IM_COL32(0, 255, 0, 200));
  1166. }
  1167. remaining_mask &= ~merge_channels_mask;
  1168. for (int n = 0; n < splitter->_Count && merge_channels_mask != 0; n++)
  1169. {
  1170. // Copy + overwrite new clip rect
  1171. const ImU64 n_mask = (ImU64)1 << n;
  1172. if ((merge_channels_mask & n_mask) == 0)
  1173. continue;
  1174. ImDrawChannel* channel = &splitter->_Channels[n];
  1175. IM_ASSERT(channel->_CmdBuffer.Size == 1 && merge_clip_rect.Contains(ImRect(channel->_CmdBuffer[0].ClipRect)));
  1176. channel->_CmdBuffer[0].ClipRect = *(ImVec4*)&merge_clip_rect;
  1177. memcpy(dst_tmp++, channel, sizeof(ImDrawChannel));
  1178. merge_channels_mask &= ~n_mask;
  1179. }
  1180. }
  1181. // Append channels that we didn't reorder at the end of the list
  1182. for (int n = 0; n < splitter->_Count && remaining_mask != 0; n++)
  1183. {
  1184. const ImU64 n_mask = (ImU64)1 << n;
  1185. if ((remaining_mask & n_mask) == 0)
  1186. continue;
  1187. ImDrawChannel* channel = &splitter->_Channels[n];
  1188. memcpy(dst_tmp++, channel, sizeof(ImDrawChannel));
  1189. remaining_mask &= ~n_mask;
  1190. }
  1191. IM_ASSERT(dst_tmp == g.DrawChannelsTempMergeBuffer.Data + g.DrawChannelsTempMergeBuffer.Size);
  1192. memcpy(splitter->_Channels.Data + 1, g.DrawChannelsTempMergeBuffer.Data, (splitter->_Count - 1) * sizeof(ImDrawChannel));
  1193. }
  1194. // 3. Actually merge (channels using the same clip rect will be contiguous and naturally merged)
  1195. splitter->Merge(table->InnerWindow->DrawList);
  1196. }
  1197. // We use a default parameter of 'init_width_or_weight == -1'
  1198. // ImGuiTableColumnFlags_WidthFixed, width <= 0 --> init width == auto
  1199. // ImGuiTableColumnFlags_WidthFixed, width > 0 --> init width == manual
  1200. // ImGuiTableColumnFlags_WidthStretch, weight < 0 --> init weight == 1.0f
  1201. // ImGuiTableColumnFlags_WidthStretch, weight >= 0 --> init weight == custom
  1202. // Use a different API?
  1203. void ImGui::TableSetupColumn(const char* label, ImGuiTableColumnFlags flags, float init_width_or_weight, ImGuiID user_id)
  1204. {
  1205. ImGuiContext& g = *GImGui;
  1206. ImGuiTable* table = g.CurrentTable;
  1207. IM_ASSERT(table != NULL && "Need to call TableSetupColumn() after BeginTable()!");
  1208. IM_ASSERT(!table->IsLayoutLocked && "Need to call call TableSetupColumn() before first row!");
  1209. IM_ASSERT(table->DeclColumnsCount >= 0 && table->DeclColumnsCount < table->ColumnsCount && "Called TableSetupColumn() too many times!");
  1210. ImGuiTableColumn* column = &table->Columns[table->DeclColumnsCount];
  1211. table->DeclColumnsCount++;
  1212. // When passing a width automatically enforce WidthFixed policy (vs TableFixColumnFlags would default to WidthAlwaysAutoResize)
  1213. // (we write down to FlagsIn which is a little misleading, another solution would be to pass init_width_or_weight to TableFixColumnFlags)
  1214. if ((flags & ImGuiTableColumnFlags_WidthMask_) == 0)
  1215. if ((table->Flags & ImGuiTableFlags_SizingPolicyFixedX) && (init_width_or_weight > 0.0f))
  1216. flags |= ImGuiTableColumnFlags_WidthFixed;
  1217. column->UserID = user_id;
  1218. column->FlagsIn = flags;
  1219. column->Flags = TableFixColumnFlags(table, column->FlagsIn);
  1220. flags = column->Flags;
  1221. // Initialize defaults
  1222. if (table->IsInitializing && !table->IsSettingsLoaded)
  1223. {
  1224. // Init width or weight
  1225. // Disable auto-fit if a default fixed width has been specified
  1226. if ((flags & ImGuiTableColumnFlags_WidthFixed) && init_width_or_weight > 0.0f)
  1227. {
  1228. column->WidthRequested = init_width_or_weight;
  1229. column->AutoFitQueue = 0x00;
  1230. }
  1231. if (flags & ImGuiTableColumnFlags_WidthStretch)
  1232. {
  1233. IM_ASSERT(init_width_or_weight < 0.0f || init_width_or_weight > 0.0f);
  1234. column->ResizeWeight = (init_width_or_weight < 0.0f ? 1.0f : init_width_or_weight);
  1235. }
  1236. else
  1237. {
  1238. column->ResizeWeight = 1.0f;
  1239. }
  1240. // Init default visibility/sort state
  1241. if (flags & ImGuiTableColumnFlags_DefaultHide)
  1242. column->IsActive = column->NextIsActive = false;
  1243. if (flags & ImGuiTableColumnFlags_DefaultSort)
  1244. column->SortOrder = 0; // Multiple columns using _DefaultSort will be reordered when building the sort specs.
  1245. }
  1246. // Store name (append with zero-terminator in contiguous buffer)
  1247. IM_ASSERT(column->NameOffset == -1);
  1248. if (label != NULL)
  1249. {
  1250. column->NameOffset = (ImS16)table->ColumnsNames.size();
  1251. table->ColumnsNames.append(label, label + strlen(label) + 1);
  1252. }
  1253. }
  1254. // Starts into the first cell of a new row
  1255. void ImGui::TableNextRow(ImGuiTableRowFlags row_flags, float min_row_height)
  1256. {
  1257. ImGuiContext& g = *GImGui;
  1258. ImGuiTable* table = g.CurrentTable;
  1259. if (table->CurrentRow == -1)
  1260. TableUpdateLayout(table);
  1261. else if (table->IsInsideRow)
  1262. TableEndRow(table);
  1263. table->LastRowFlags = table->RowFlags;
  1264. table->RowFlags = row_flags;
  1265. TableBeginRow(table);
  1266. // We honor min_row_height requested by user, but cannot guarantee per-row maximum height,
  1267. // because that would essentially require a unique clipping rectangle per-cell.
  1268. table->RowPosY2 += table->CellPaddingY * 2.0f;
  1269. table->RowPosY2 = ImMax(table->RowPosY2, table->RowPosY1 + min_row_height);
  1270. TableBeginCell(table, 0);
  1271. }
  1272. // [Internal]
  1273. void ImGui::TableBeginRow(ImGuiTable* table)
  1274. {
  1275. ImGuiWindow* window = table->InnerWindow;
  1276. IM_ASSERT(!table->IsInsideRow);
  1277. // New row
  1278. table->CurrentRow++;
  1279. table->CurrentColumn = -1;
  1280. table->RowBgColor = IM_COL32_DISABLE;
  1281. table->IsInsideRow = true;
  1282. // Begin frozen rows
  1283. float next_y1 = table->RowPosY2;
  1284. if (table->CurrentRow == 0 && table->FreezeRowsCount > 0)
  1285. next_y1 = window->DC.CursorPos.y = table->OuterRect.Min.y;
  1286. table->RowPosY1 = table->RowPosY2 = next_y1;
  1287. table->RowTextBaseline = 0.0f;
  1288. window->DC.CursorMaxPos.y = next_y1;
  1289. // Making the header BG color non-transparent will allow us to overlay it multiple times when handling smooth dragging.
  1290. if (table->RowFlags & ImGuiTableRowFlags_Headers)
  1291. {
  1292. table->RowBgColor = GetColorU32(ImGuiCol_TableHeaderBg);
  1293. if (table->CurrentRow == 0)
  1294. table->IsUsingHeaders = true;
  1295. }
  1296. }
  1297. // [Internal]
  1298. void ImGui::TableEndRow(ImGuiTable* table)
  1299. {
  1300. ImGuiContext& g = *GImGui;
  1301. ImGuiWindow* window = g.CurrentWindow;
  1302. IM_ASSERT(window == table->InnerWindow);
  1303. IM_ASSERT(table->IsInsideRow);
  1304. TableEndCell(table);
  1305. // Position cursor at the bottom of our row so it can be used for e.g. clipping calculation.
  1306. // However it is likely that the next call to TableBeginCell() will reposition the cursor to take account of vertical padding.
  1307. window->DC.CursorPos.y = table->RowPosY2;
  1308. // Row background fill
  1309. const float bg_y1 = table->RowPosY1;
  1310. const float bg_y2 = table->RowPosY2;
  1311. if (table->CurrentRow == 0)
  1312. table->LastFirstRowHeight = bg_y2 - bg_y1;
  1313. if (table->CurrentRow >= 0 && bg_y2 >= table->InnerClipRect.Min.y && bg_y1 <= table->InnerClipRect.Max.y)
  1314. {
  1315. // Decide of background color for the row
  1316. ImU32 bg_col = 0;
  1317. if (table->RowBgColor != IM_COL32_DISABLE)
  1318. bg_col = table->RowBgColor;
  1319. else if (table->Flags & ImGuiTableFlags_RowBg)
  1320. bg_col = GetColorU32((table->RowBgColorCounter & 1) ? ImGuiCol_TableRowBgAlt : ImGuiCol_TableRowBg);
  1321. // Decide of top border color
  1322. ImU32 border_col = 0;
  1323. if (table->CurrentRow != 0 || table->InnerWindow == table->OuterWindow)
  1324. {
  1325. if (table->Flags & ImGuiTableFlags_BordersHInner)
  1326. {
  1327. //if (table->CurrentRow == 0 && table->InnerWindow == table->OuterWindow)
  1328. // border_col = table->BorderOuterColor;
  1329. //else
  1330. if (table->CurrentRow > 0)// && !(table->LastRowFlags & ImGuiTableRowFlags_Headers))
  1331. border_col = (table->LastRowFlags & ImGuiTableRowFlags_Headers) ? table->BorderColorStrong : table->BorderColorLight;
  1332. }
  1333. else
  1334. {
  1335. //if (table->RowFlags & ImGuiTableRowFlags_Headers)
  1336. // border_col = table->BorderOuterColor;
  1337. }
  1338. }
  1339. if (bg_col != 0 || border_col != 0)
  1340. table->DrawSplitter.SetCurrentChannel(window->DrawList, 0);
  1341. // Draw background
  1342. // We soft/cpu clip this so all backgrounds and borders can share the same clipping rectangle
  1343. if (bg_col)
  1344. {
  1345. ImRect bg_rect(table->WorkRect.Min.x, bg_y1, table->WorkRect.Max.x, bg_y2);
  1346. bg_rect.ClipWith(table->BackgroundClipRect);
  1347. if (bg_rect.Min.y < bg_rect.Max.y)
  1348. window->DrawList->AddRectFilledMultiColor(bg_rect.Min, bg_rect.Max, bg_col, bg_col, bg_col, bg_col);
  1349. }
  1350. // Draw top border
  1351. const float border_y = bg_y1;
  1352. if (border_col && border_y >= table->BackgroundClipRect.Min.y && border_y < table->BackgroundClipRect.Max.y)
  1353. window->DrawList->AddLine(ImVec2(table->BorderX1, border_y), ImVec2(table->BorderX2, border_y), border_col);
  1354. }
  1355. const bool unfreeze_rows = (table->CurrentRow + 1 == table->FreezeRowsCount && table->FreezeRowsCount > 0);
  1356. // Draw bottom border (always strong)
  1357. const bool draw_separating_border = unfreeze_rows;// || (table->RowFlags & ImGuiTableRowFlags_Headers);
  1358. if (draw_separating_border)
  1359. if (bg_y2 >= table->BackgroundClipRect.Min.y && bg_y2 < table->BackgroundClipRect.Max.y)
  1360. window->DrawList->AddLine(ImVec2(table->BorderX1, bg_y2), ImVec2(table->BorderX2, bg_y2), table->BorderColorStrong);
  1361. // End frozen rows (when we are past the last frozen row line, teleport cursor and alter clipping rectangle)
  1362. // We need to do that in TableEndRow() instead of TableBeginRow() so the list clipper can mark end of row and get the new cursor position.
  1363. if (unfreeze_rows)
  1364. {
  1365. IM_ASSERT(table->IsFreezeRowsPassed == false);
  1366. table->IsFreezeRowsPassed = true;
  1367. table->DrawSplitter.SetCurrentChannel(window->DrawList, 0);
  1368. ImRect r;
  1369. r.Min.x = table->InnerClipRect.Min.x;
  1370. r.Min.y = ImMax(table->RowPosY2 + 1, window->InnerClipRect.Min.y);
  1371. r.Max.x = table->InnerClipRect.Max.x;
  1372. r.Max.y = window->InnerClipRect.Max.y;
  1373. table->BackgroundClipRect = r;
  1374. float row_height = table->RowPosY2 - table->RowPosY1;
  1375. table->RowPosY2 = window->DC.CursorPos.y = table->WorkRect.Min.y + table->RowPosY2 - table->OuterRect.Min.y;
  1376. table->RowPosY1 = table->RowPosY2 - row_height;
  1377. for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
  1378. {
  1379. ImGuiTableColumn* column = &table->Columns[column_n];
  1380. column->DrawChannelCurrent = column->DrawChannelRowsAfterFreeze;
  1381. column->ClipRect.Min.y = r.Min.y;
  1382. }
  1383. }
  1384. if (!(table->RowFlags & ImGuiTableRowFlags_Headers))
  1385. table->RowBgColorCounter++;
  1386. table->IsInsideRow = false;
  1387. }
  1388. // [Internal] Called by TableNextRow()TableNextCell()!
  1389. // This is called a lot, so we need to be mindful of unnecessary overhead.
  1390. void ImGui::TableBeginCell(ImGuiTable* table, int column_no)
  1391. {
  1392. table->CurrentColumn = column_no;
  1393. ImGuiTableColumn* column = &table->Columns[column_no];
  1394. ImGuiWindow* window = table->InnerWindow;
  1395. const float start_x = (table->RowFlags & ImGuiTableRowFlags_Headers) ? column->StartXHeaders : column->StartXRows;
  1396. window->DC.LastItemId = 0;
  1397. window->DC.CursorPos = ImVec2(start_x, table->RowPosY1 + table->CellPaddingY);
  1398. window->DC.CursorMaxPos.x = window->DC.CursorPos.x;
  1399. window->DC.ColumnsOffset.x = start_x - window->Pos.x - window->DC.Indent.x; // FIXME-WORKRECT // FIXME-TABLE: Recurse
  1400. window->DC.CurrLineTextBaseOffset = table->RowTextBaseline;
  1401. window->WorkRect.Min.y = window->DC.CursorPos.y;
  1402. window->WorkRect.Min.x = column->MinX + table->CellPaddingX1;
  1403. window->WorkRect.Max.x = column->MaxX - table->CellPaddingX2;
  1404. // To allow ImGuiListClipper to function we propagate our row height
  1405. if (!column->IsActive)
  1406. window->DC.CursorPos.y = ImMax(window->DC.CursorPos.y, table->RowPosY2);
  1407. // FIXME-COLUMNS: Setup baseline, preserve across columns (how can we obtain first line baseline tho..)
  1408. // window->DC.CurrLineTextBaseOffset = ImMax(window->DC.CurrLineTextBaseOffset, g.Style.FramePadding.y);
  1409. window->SkipItems = column->IsClipped ? true : table->BackupSkipItems;
  1410. if (table->Flags & ImGuiTableFlags_NoClipX)
  1411. {
  1412. table->DrawSplitter.SetCurrentChannel(window->DrawList, 1);
  1413. }
  1414. else
  1415. {
  1416. table->DrawSplitter.SetCurrentChannel(window->DrawList, column->DrawChannelCurrent);
  1417. //window->ClipRect = column->ClipRect;
  1418. //IM_ASSERT(column->ClipRect.Max.x > column->ClipRect.Min.x && column->ClipRect.Max.y > column->ClipRect.Min.y);
  1419. //window->DrawList->_ClipRectStack.back() = ImVec4(column->ClipRect.Min.x, column->ClipRect.Min.y, column->ClipRect.Max.x, column->ClipRect.Max.y);
  1420. //window->DrawList->UpdateClipRect();
  1421. window->DrawList->PopClipRect();
  1422. window->DrawList->PushClipRect(column->ClipRect.Min, column->ClipRect.Max, false);
  1423. //IMGUI_DEBUG_LOG("%d (%.0f,%.0f)(%.0f,%.0f)\n", column_no, column->ClipRect.Min.x, column->ClipRect.Min.y, column->ClipRect.Max.x, column->ClipRect.Max.y);
  1424. window->ClipRect = window->DrawList->_ClipRectStack.back();
  1425. }
  1426. }
  1427. // [Internal] Called by TableNextRow()TableNextCell()!
  1428. void ImGui::TableEndCell(ImGuiTable* table)
  1429. {
  1430. ImGuiTableColumn* column = &table->Columns[table->CurrentColumn];
  1431. ImGuiWindow* window = table->InnerWindow;
  1432. // Report maximum position so we can infer content size per column.
  1433. float* p_max_pos_x;
  1434. if (table->RowFlags & ImGuiTableRowFlags_Headers)
  1435. p_max_pos_x = &column->ContentMaxPosHeadersUsed; // Useful in case user submit contents in header row that is not a TableHeader() call
  1436. else
  1437. p_max_pos_x = table->IsFreezeRowsPassed ? &column->ContentMaxPosRowsUnfrozen : &column->ContentMaxPosRowsFrozen;
  1438. *p_max_pos_x = ImMax(*p_max_pos_x, window->DC.CursorMaxPos.x);
  1439. table->RowPosY2 = ImMax(table->RowPosY2, window->DC.CursorMaxPos.y + table->CellPaddingY);
  1440. // Propagate text baseline for the entire row
  1441. // FIXME-TABLE: Here we propagate text baseline from the last line of the cell.. instead of the first one.
  1442. table->RowTextBaseline = ImMax(table->RowTextBaseline, window->DC.PrevLineTextBaseOffset);
  1443. }
  1444. // Append into the next cell
  1445. // FIXME-TABLE: Wrapping to next row should be optional?
  1446. bool ImGui::TableNextCell()
  1447. {
  1448. ImGuiContext& g = *GImGui;
  1449. ImGuiTable* table = g.CurrentTable;
  1450. if (table->CurrentColumn != -1 && table->CurrentColumn + 1 < table->ColumnsCount)
  1451. {
  1452. TableEndCell(table);
  1453. TableBeginCell(table, table->CurrentColumn + 1);
  1454. }
  1455. else
  1456. {
  1457. TableNextRow();
  1458. }
  1459. int column_n = table->CurrentColumn;
  1460. return (table->VisibleMaskByIndex & ((ImU64)1 << column_n)) != 0;
  1461. }
  1462. const char* ImGui::TableGetColumnName(int column_n)
  1463. {
  1464. ImGuiContext& g = *GImGui;
  1465. ImGuiTable* table = g.CurrentTable;
  1466. if (!table)
  1467. return NULL;
  1468. if (column_n < 0)
  1469. column_n = table->CurrentColumn;
  1470. return TableGetColumnName(table, column_n);
  1471. }
  1472. bool ImGui::TableGetColumnIsVisible(int column_n)
  1473. {
  1474. ImGuiContext& g = *GImGui;
  1475. ImGuiTable* table = g.CurrentTable;
  1476. if (!table)
  1477. return false;
  1478. if (column_n < 0)
  1479. column_n = table->CurrentColumn;
  1480. return (table->VisibleMaskByIndex & ((ImU64)1 << column_n)) != 0;
  1481. }
  1482. int ImGui::TableGetColumnIndex()
  1483. {
  1484. ImGuiContext& g = *GImGui;
  1485. ImGuiTable* table = g.CurrentTable;
  1486. if (!table)
  1487. return 0;
  1488. return table->CurrentColumn;
  1489. }
  1490. bool ImGui::TableSetColumnIndex(int column_idx)
  1491. {
  1492. ImGuiContext& g = *GImGui;
  1493. ImGuiTable* table = g.CurrentTable;
  1494. if (!table)
  1495. return false;
  1496. if (table->CurrentColumn != column_idx)
  1497. {
  1498. if (table->CurrentColumn != -1)
  1499. TableEndCell(table);
  1500. IM_ASSERT(column_idx >= 0 && table->ColumnsCount);
  1501. TableBeginCell(table, column_idx);
  1502. }
  1503. return (table->VisibleMaskByIndex & ((ImU64)1 << column_idx)) != 0;
  1504. }
  1505. // Return the cell rectangle based on currently known height.
  1506. // Important: we generally don't know our row height until the end of the row, so Max.y will be incorrect in many situations.
  1507. // The only case where this is correct is if we provided a min_row_height to TableNextRow() and don't go below it.
  1508. ImRect ImGui::TableGetCellRect()
  1509. {
  1510. ImGuiContext& g = *GImGui;
  1511. ImGuiTable* table = g.CurrentTable;
  1512. ImGuiTableColumn* column = &table->Columns[table->CurrentColumn];
  1513. return ImRect(column->MinX, table->RowPosY1, column->MaxX, table->RowPosY2);
  1514. }
  1515. const char* ImGui::TableGetColumnName(ImGuiTable* table, int column_no)
  1516. {
  1517. ImGuiTableColumn* column = &table->Columns[column_no];
  1518. if (column->NameOffset == -1)
  1519. return NULL;
  1520. return &table->ColumnsNames.Buf[column->NameOffset];
  1521. }
  1522. void ImGui::TableSetColumnAutofit(ImGuiTable* table, int column_no)
  1523. {
  1524. // Disable clipping then auto-fit, will take 2 frames
  1525. // (we don't take a shortcut for unclipped columns to reduce inconsistencies when e.g. resizing multiple columns)
  1526. ImGuiTableColumn* column = &table->Columns[column_no];
  1527. column->CannotSkipItemsQueue = (1 << 0);
  1528. column->AutoFitQueue = (1 << 1);
  1529. }
  1530. void ImGui::PushTableBackground()
  1531. {
  1532. ImGuiContext& g = *GImGui;
  1533. ImGuiWindow* window = g.CurrentWindow;
  1534. ImGuiTable* table = g.CurrentTable;
  1535. table->DrawSplitter.SetCurrentChannel(window->DrawList, 0);
  1536. PushClipRect(table->HostClipRect.Min, table->HostClipRect.Max, false);
  1537. }
  1538. void ImGui::PopTableBackground()
  1539. {
  1540. ImGuiContext& g = *GImGui;
  1541. ImGuiWindow* window = g.CurrentWindow;
  1542. ImGuiTable* table = g.CurrentTable;
  1543. ImGuiTableColumn* column = &table->Columns[table->CurrentColumn];
  1544. table->DrawSplitter.SetCurrentChannel(window->DrawList, column->DrawChannelCurrent);
  1545. PopClipRect();
  1546. }
  1547. // Output context menu into current window (generally a popup)
  1548. // FIXME-TABLE: Ideally this should be writable by the user. Full programmatic access to that data?
  1549. void ImGui::TableDrawContextMenu(ImGuiTable* table, int selected_column_n)
  1550. {
  1551. ImGuiContext& g = *GImGui;
  1552. ImGuiWindow* window = g.CurrentWindow;
  1553. if (window->SkipItems)
  1554. return;
  1555. bool want_separator = false;
  1556. selected_column_n = ImClamp(selected_column_n, -1, table->ColumnsCount - 1);
  1557. // Sizing
  1558. if (table->Flags & ImGuiTableFlags_Resizable)
  1559. {
  1560. if (ImGuiTableColumn* selected_column = (selected_column_n != -1) ? &table->Columns[selected_column_n] : NULL)
  1561. {
  1562. const bool can_resize = !(selected_column->Flags & (ImGuiTableColumnFlags_NoResize | ImGuiTableColumnFlags_WidthStretch)) && selected_column->IsActive;
  1563. if (MenuItem("Size column to fit", NULL, false, can_resize))
  1564. TableSetColumnAutofit(table, selected_column_n);
  1565. }
  1566. if (MenuItem("Size all columns to fit", NULL))
  1567. {
  1568. for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
  1569. {
  1570. ImGuiTableColumn* column = &table->Columns[column_n];
  1571. if (column->IsActive)
  1572. TableSetColumnAutofit(table, column_n);
  1573. }
  1574. }
  1575. want_separator = true;
  1576. }
  1577. // Ordering
  1578. if (table->Flags & ImGuiTableFlags_Reorderable)
  1579. {
  1580. if (MenuItem("Reset order", NULL, false, !table->IsDefaultDisplayOrder))
  1581. table->IsResetDisplayOrderRequest = true;
  1582. want_separator = true;
  1583. }
  1584. // Hiding / Visibility
  1585. if (table->Flags & ImGuiTableFlags_Hideable)
  1586. {
  1587. if (want_separator)
  1588. Separator();
  1589. want_separator = false;
  1590. PushItemFlag(ImGuiItemFlags_SelectableDontClosePopup, true);
  1591. for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
  1592. {
  1593. ImGuiTableColumn* column = &table->Columns[column_n];
  1594. const char* name = TableGetColumnName(table, column_n);
  1595. if (name == NULL)
  1596. name = "<Unknown>";
  1597. // Make sure we can't hide the last active column
  1598. bool menu_item_active = (column->Flags & ImGuiTableColumnFlags_NoHide) ? false : true;
  1599. if (column->IsActive && table->ColumnsActiveCount <= 1)
  1600. menu_item_active = false;
  1601. if (MenuItem(name, NULL, column->IsActive, menu_item_active))
  1602. column->NextIsActive = !column->IsActive;
  1603. }
  1604. PopItemFlag();
  1605. }
  1606. }
  1607. // This is a helper to output TableHeader() calls based on the column names declared in TableSetupColumn().
  1608. // The intent is that advanced users willing to create customized headers would not need to use this helper and may create their own.
  1609. // However presently this function uses too many internal structures/calls.
  1610. void ImGui::TableAutoHeaders()
  1611. {
  1612. ImGuiContext& g = *GImGui;
  1613. ImGuiWindow* window = g.CurrentWindow;
  1614. ImGuiTable* table = g.CurrentTable;
  1615. IM_ASSERT(table != NULL && "Need to call TableAutoHeaders() after BeginTable()!");
  1616. TableNextRow(ImGuiTableRowFlags_Headers, GetTextLineHeight() + g.Style.CellPadding.y * 2.0f);
  1617. if (window->SkipItems)
  1618. return;
  1619. // This for loop is constructed to not make use of internal functions,
  1620. // as this is intended to be a base template to copy and build from.
  1621. int open_context_popup = INT_MAX;
  1622. const int columns_count = table->ColumnsCount;
  1623. for (int column_n = 0; column_n < columns_count; column_n++)
  1624. {
  1625. if (!TableSetColumnIndex(column_n))
  1626. continue;
  1627. const char* name = TableGetColumnName(column_n);
  1628. // [DEBUG] Test custom user elements
  1629. #if 0
  1630. if (column_n < 2)
  1631. {
  1632. static bool b[2] = {};
  1633. PushID(column_n);
  1634. PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
  1635. Checkbox("##", &b[column_n]);
  1636. PopStyleVar();
  1637. PopID();
  1638. SameLine(0.0f, g.Style.ItemInnerSpacing.x);
  1639. }
  1640. #endif
  1641. // [DEBUG]
  1642. //if (g.IO.KeyCtrl) { static char buf[32]; name = buf; ImGuiTableColumn* c = &table->Columns[column_n]; if (c->Flags & ImGuiTableColumnFlags_WidthStretch) ImFormatString(buf, 32, "%.3f>%.1f", c->ResizeWeight, c->WidthGiven); else ImFormatString(buf, 32, "%.1f", c->WidthGiven); }
  1643. // Push an id to allow unnamed labels (generally accidental, but let's behave nicely with them)
  1644. PushID(table->InstanceNo * table->ColumnsCount + column_n);
  1645. TableHeader(name);
  1646. PopID();
  1647. // We don't use BeginPopupContextItem() because we want the popup to stay up even after the column is hidden
  1648. if (IsMouseReleased(1) && IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup))
  1649. open_context_popup = column_n;
  1650. }
  1651. // FIXME-TABLE: This is not user-land code any more...
  1652. // FIXME-TABLE: Need to explain why this is here!
  1653. window->SkipItems = table->BackupSkipItems;
  1654. // Allow opening popup from the right-most section after the last column
  1655. // FIXME-TABLE: This is not user-land code any more... perhaps instead we should expose hovered column.
  1656. // and allow some sort of row-centric IsItemHovered() for full flexibility?
  1657. float unused_x1 = table->WorkRect.Min.x;
  1658. if (table->RightMostActiveColumn != -1)
  1659. unused_x1 = ImMax(unused_x1, table->Columns[table->RightMostActiveColumn].MaxX);
  1660. if (unused_x1 < table->WorkRect.Max.x)
  1661. {
  1662. // FIXME: We inherit ClipRect/SkipItem from last submitted column (active or not), let's temporarily override it.
  1663. // Because we don't perform any rendering here we just overwrite window->ClipRect used by logic.
  1664. window->ClipRect = table->InnerClipRect;
  1665. ImVec2 backup_cursor_max_pos = window->DC.CursorMaxPos;
  1666. window->DC.CursorPos = ImVec2(unused_x1, table->RowPosY1);
  1667. ImVec2 size = ImVec2(table->WorkRect.Max.x - window->DC.CursorPos.x, table->RowPosY2 - table->RowPosY1);
  1668. if (size.x > 0.0f && size.y > 0.0f)
  1669. {
  1670. InvisibleButton("##RemainingSpace", size);
  1671. window->DC.CursorPos.y -= g.Style.ItemSpacing.y;
  1672. window->DC.CursorMaxPos = backup_cursor_max_pos; // Don't feed back into the width of the Header row
  1673. // We don't use BeginPopupContextItem() because we want the popup to stay up even after the column is hidden
  1674. if (IsMouseReleased(1) && IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup))
  1675. open_context_popup = -1;
  1676. }
  1677. window->ClipRect = window->DrawList->_ClipRectStack.back();
  1678. }
  1679. // Open Context Menu
  1680. if (open_context_popup != INT_MAX)
  1681. if (table->Flags & (ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable))
  1682. {
  1683. table->IsContextPopupOpen = true;
  1684. table->ContextPopupColumn = (ImS8)open_context_popup;
  1685. table->InstanceInteracted = table->InstanceNo;
  1686. OpenPopup("##TableContextMenu");
  1687. }
  1688. }
  1689. // Emit a column header (text + optional sort order)
  1690. // We cpu-clip text here so that all columns headers can be merged into a same draw call.
  1691. // FIXME-TABLE: Should hold a selection state.
  1692. void ImGui::TableHeader(const char* label)
  1693. {
  1694. ImGuiContext& g = *GImGui;
  1695. ImGuiWindow* window = g.CurrentWindow;
  1696. if (window->SkipItems)
  1697. return;
  1698. ImGuiTable* table = g.CurrentTable;
  1699. IM_ASSERT(table != NULL && "Need to call TableAutoHeaders() after BeginTable()!");
  1700. IM_ASSERT(table->CurrentColumn != -1);
  1701. const int column_n = table->CurrentColumn;
  1702. ImGuiTableColumn* column = &table->Columns[column_n];
  1703. float row_height = GetTextLineHeight();
  1704. ImRect cell_r = TableGetCellRect();
  1705. //GetForegroundDrawList()->AddRect(cell_r.Min, cell_r.Max, IM_COL32(255, 0, 0, 255)); // [DEBUG]
  1706. ImRect work_r = cell_r;
  1707. work_r.Min.x = window->DC.CursorPos.x;
  1708. work_r.Max.y = work_r.Min.y + row_height;
  1709. // Label
  1710. if (label == NULL)
  1711. label = "";
  1712. const char* label_end = FindRenderedTextEnd(label);
  1713. ImVec2 label_size = CalcTextSize(label, label_end, true);
  1714. ImVec2 label_pos = window->DC.CursorPos;
  1715. float ellipsis_max = work_r.Max.x;
  1716. // Selectable
  1717. PushID(label);
  1718. // FIXME-TABLE: Fix when padding are disabled.
  1719. //window->DC.CursorPos.x = column->MinX + table->CellPadding.x;
  1720. // Keep header highlighted when context menu is open. (FIXME-TABLE: however we cannot assume the ID of said popup if it has been created by the user...)
  1721. const bool selected = (table->IsContextPopupOpen && table->ContextPopupColumn == column_n && table->InstanceInteracted == table->InstanceNo);
  1722. const bool pressed = Selectable("", selected, ImGuiSelectableFlags_DrawHoveredWhenHeld, ImVec2(0.0f, row_height));
  1723. const bool held = IsItemActive();
  1724. if (held)
  1725. table->HeldHeaderColumn = (ImS8)column_n;
  1726. window->DC.CursorPos.y -= g.Style.ItemSpacing.y * 0.5f;
  1727. // Drag and drop: re-order columns. Frozen columns are not reorderable.
  1728. // FIXME-TABLE: Scroll request while reordering a column and it lands out of the scrolling zone.
  1729. if (held && (table->Flags & ImGuiTableFlags_Reorderable) && IsMouseDragging(0) && !g.DragDropActive)
  1730. {
  1731. // While moving a column it will jump on the other side of the mouse, so we also test for MouseDelta.x
  1732. table->ReorderColumn = (ImS8)column_n;
  1733. table->InstanceInteracted = table->InstanceNo;
  1734. if (g.IO.MouseDelta.x < 0.0f && g.IO.MousePos.x < cell_r.Min.x)
  1735. if (column->PrevActiveColumn != -1 && (column->IndexWithinActiveSet < table->FreezeColumnsRequest) == (table->Columns[column->PrevActiveColumn].IndexWithinActiveSet < table->FreezeColumnsRequest))
  1736. table->ReorderColumnDir = -1;
  1737. if (g.IO.MouseDelta.x > 0.0f && g.IO.MousePos.x > cell_r.Max.x)
  1738. if (column->NextActiveColumn != -1 && (column->IndexWithinActiveSet < table->FreezeColumnsRequest) == (table->Columns[column->NextActiveColumn].IndexWithinActiveSet < table->FreezeColumnsRequest))
  1739. table->ReorderColumnDir = +1;
  1740. }
  1741. // Sort order arrow
  1742. float w_arrow = 0.0f;
  1743. float w_sort_text = 0.0f;
  1744. if ((table->Flags & ImGuiTableFlags_Sortable) && !(column->Flags & ImGuiTableColumnFlags_NoSort))
  1745. {
  1746. const float ARROW_SCALE = 0.75f;
  1747. w_arrow = ImFloor(g.FontSize * ARROW_SCALE + g.Style.FramePadding.x);// table->CellPadding.x);
  1748. if (column->SortOrder != -1)
  1749. {
  1750. w_sort_text = 0.0f;
  1751. char sort_order_suf[8];
  1752. if (column->SortOrder > 0)
  1753. {
  1754. ImFormatString(sort_order_suf, IM_ARRAYSIZE(sort_order_suf), "%d", column->SortOrder + 1);
  1755. w_sort_text = g.Style.ItemInnerSpacing.x + CalcTextSize(sort_order_suf).x;
  1756. }
  1757. float x = ImMax(cell_r.Min.x, work_r.Max.x - w_arrow - w_sort_text);
  1758. ellipsis_max -= w_arrow + w_sort_text;
  1759. float y = label_pos.y;
  1760. ImU32 col = GetColorU32(ImGuiCol_Text);
  1761. if (column->SortOrder > 0)
  1762. {
  1763. PushStyleColor(ImGuiCol_Text, GetColorU32(ImGuiCol_Text, 0.70f));
  1764. RenderText(ImVec2(x + g.Style.ItemInnerSpacing.x, y), sort_order_suf);
  1765. PopStyleColor();
  1766. x += w_sort_text;
  1767. }
  1768. RenderArrow(window->DrawList, ImVec2(x, y), col, column->SortDirection == ImGuiSortDirection_Ascending ? ImGuiDir_Down : ImGuiDir_Up, ARROW_SCALE);
  1769. }
  1770. // Handle clicking on column header to adjust Sort Order
  1771. if (pressed && table->ReorderColumn != column_n)
  1772. TableSortSpecsClickColumn(table, column, g.IO.KeyShift);
  1773. }
  1774. // Render clipped label
  1775. // Clipping here ensure that in the majority of situations, all our header cells will be merged into a single draw call.
  1776. //window->DrawList->AddCircleFilled(ImVec2(ellipsis_max, label_pos.y), 40, IM_COL32_WHITE);
  1777. RenderTextEllipsis(window->DrawList, label_pos, ImVec2(ellipsis_max, label_pos.y + row_height + g.Style.FramePadding.y), ellipsis_max, ellipsis_max, label, label_end, &label_size);
  1778. // We feed our unclipped width to the column without writing on CursorMaxPos, so that column is still considering for merging.
  1779. // FIXME-TABLE: Clarify policies of how label width and potential decorations (arrows) fit into auto-resize of the column
  1780. float max_pos_x = label_pos.x + label_size.x + w_sort_text + w_arrow;
  1781. column->ContentMaxPosHeadersUsed = ImMax(column->ContentMaxPosHeadersUsed, work_r.Max.x);// ImMin(max_pos_x, work_r.Max.x));
  1782. column->ContentMaxPosHeadersDesired = ImMax(column->ContentMaxPosHeadersDesired, max_pos_x);
  1783. PopID();
  1784. }
  1785. void ImGui::TableSortSpecsClickColumn(ImGuiTable* table, ImGuiTableColumn* clicked_column, bool add_to_existing_sort_orders)
  1786. {
  1787. if (!(table->Flags & ImGuiTableFlags_MultiSortable))
  1788. add_to_existing_sort_orders = false;
  1789. ImS8 sort_order_max = 0;
  1790. if (add_to_existing_sort_orders)
  1791. for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
  1792. sort_order_max = ImMax(sort_order_max, table->Columns[column_n].SortOrder);
  1793. for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
  1794. {
  1795. ImGuiTableColumn* column = &table->Columns[column_n];
  1796. if (column == clicked_column)
  1797. {
  1798. // Set new sort direction and sort order
  1799. // - If the PreferSortDescending flag is set, we will default to a Descending direction on the first click.
  1800. // - Note that the PreferSortAscending flag is never checked, it is essentially the default and therefore a no-op.
  1801. // - Note that the NoSortAscending/NoSortDescending flags are processed in TableSortSpecsSanitize(), and they may change/revert
  1802. // the value of SortDirection. We could technically also do it here but it would be unnecessary and duplicate code.
  1803. if (column->SortOrder == -1)
  1804. column->SortDirection = (column->Flags & ImGuiTableColumnFlags_PreferSortDescending) ? (ImS8)ImGuiSortDirection_Descending : (ImU8)(ImGuiSortDirection_Ascending);
  1805. else
  1806. column->SortDirection = (ImU8)((column->SortDirection == ImGuiSortDirection_Ascending) ? ImGuiSortDirection_Descending : ImGuiSortDirection_Ascending);
  1807. if (column->SortOrder == -1 || !add_to_existing_sort_orders)
  1808. column->SortOrder = add_to_existing_sort_orders ? sort_order_max + 1 : 0;
  1809. }
  1810. else
  1811. {
  1812. if (!add_to_existing_sort_orders)
  1813. column->SortOrder = -1;
  1814. }
  1815. TableFixColumnSortDirection(column);
  1816. }
  1817. table->IsSettingsDirty = true;
  1818. table->IsSortSpecsDirty = true;
  1819. }
  1820. // Return NULL if no sort specs.
  1821. // Return ->WantSort == true when the specs have changed since the last query.
  1822. const ImGuiTableSortSpecs* ImGui::TableGetSortSpecs()
  1823. {
  1824. ImGuiContext& g = *GImGui;
  1825. ImGuiTable* table = g.CurrentTable;
  1826. IM_ASSERT(table != NULL);
  1827. if (!(table->Flags & ImGuiTableFlags_Sortable))
  1828. return NULL;
  1829. // Flatten sort specs into user facing data
  1830. const bool was_dirty = table->IsSortSpecsDirty;
  1831. if (was_dirty)
  1832. {
  1833. TableSortSpecsSanitize(table);
  1834. // Write output
  1835. table->SortSpecsData.resize(table->SortSpecsCount);
  1836. table->SortSpecs.ColumnsMask = 0x00;
  1837. for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
  1838. {
  1839. ImGuiTableColumn* column = &table->Columns[column_n];
  1840. if (column->SortOrder == -1)
  1841. continue;
  1842. ImGuiTableSortSpecsColumn* sort_spec = &table->SortSpecsData[column->SortOrder];
  1843. sort_spec->ColumnUserID = column->UserID;
  1844. sort_spec->ColumnIndex = (ImU8)column_n;
  1845. sort_spec->SortOrder = (ImU8)column->SortOrder;
  1846. sort_spec->SortSign = (column->SortDirection == ImGuiSortDirection_Ascending) ? +1 : -1;
  1847. sort_spec->SortDirection = column->SortDirection;
  1848. table->SortSpecs.ColumnsMask |= (ImU64)1 << column_n;
  1849. }
  1850. }
  1851. // User facing data
  1852. table->SortSpecs.Specs = table->SortSpecsData.Data;
  1853. table->SortSpecs.SpecsCount = table->SortSpecsData.Size;
  1854. table->SortSpecs.SpecsChanged = was_dirty;
  1855. table->IsSortSpecsDirty = false;
  1856. return table->SortSpecs.SpecsCount ? &table->SortSpecs : NULL;
  1857. }
  1858. bool ImGui::TableGetColumnIsSorted(int column_n)
  1859. {
  1860. ImGuiContext& g = *GImGui;
  1861. ImGuiTable* table = g.CurrentTable;
  1862. if (!table)
  1863. return false;
  1864. if (column_n < 0)
  1865. column_n = table->CurrentColumn;
  1866. ImGuiTableColumn* column = &table->Columns[column_n];
  1867. return (column->SortOrder != -1);
  1868. }
  1869. void ImGui::TableSortSpecsSanitize(ImGuiTable* table)
  1870. {
  1871. // Clear SortOrder from hidden column and verify that there's no gap or duplicate.
  1872. int sort_order_count = 0;
  1873. ImU64 sort_order_mask = 0x00;
  1874. for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
  1875. {
  1876. ImGuiTableColumn* column = &table->Columns[column_n];
  1877. if (column->SortOrder != -1 && !column->IsActive)
  1878. column->SortOrder = -1;
  1879. if (column->SortOrder == -1)
  1880. continue;
  1881. sort_order_count++;
  1882. sort_order_mask |= ((ImU64)1 << column->SortOrder);
  1883. IM_ASSERT(sort_order_count < (int)sizeof(sort_order_mask) * 8);
  1884. }
  1885. const bool need_fix_linearize = ((ImU64)1 << sort_order_count) != (sort_order_mask + 1);
  1886. const bool need_fix_single_sort_order = (sort_order_count > 1) && !(table->Flags & ImGuiTableFlags_MultiSortable);
  1887. if (need_fix_linearize || need_fix_single_sort_order)
  1888. {
  1889. ImU64 fixed_mask = 0x00;
  1890. for (int sort_n = 0; sort_n < sort_order_count; sort_n++)
  1891. {
  1892. // Fix: Rewrite sort order fields if needed so they have no gap or duplicate.
  1893. // (e.g. SortOrder 0 disappeared, SortOrder 1..2 exists --> rewrite then as SortOrder 0..1)
  1894. int column_with_smallest_sort_order = -1;
  1895. for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
  1896. if ((fixed_mask & ((ImU64)1 << (ImU64)column_n)) == 0 && table->Columns[column_n].SortOrder != -1)
  1897. if (column_with_smallest_sort_order == -1 || table->Columns[column_n].SortOrder < table->Columns[column_with_smallest_sort_order].SortOrder)
  1898. column_with_smallest_sort_order = column_n;
  1899. IM_ASSERT(column_with_smallest_sort_order != -1);
  1900. fixed_mask |= ((ImU64)1 << column_with_smallest_sort_order);
  1901. table->Columns[column_with_smallest_sort_order].SortOrder = (ImS8)sort_n;
  1902. // Fix: Make sure only one column has a SortOrder if ImGuiTableFlags_MultiSortable is not set.
  1903. if (need_fix_single_sort_order)
  1904. {
  1905. for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
  1906. if (column_n != column_with_smallest_sort_order)
  1907. table->Columns[column_n].SortOrder = -1;
  1908. break;
  1909. }
  1910. }
  1911. }
  1912. // Fallback default sort order (if no column has the ImGuiTableColumnFlags_DefaultSort flag)
  1913. if (sort_order_count == 0 && table->IsInitializing)
  1914. for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
  1915. {
  1916. ImGuiTableColumn* column = &table->Columns[column_n];
  1917. if (!(column->Flags & ImGuiTableColumnFlags_NoSort) && column->IsActive)
  1918. {
  1919. sort_order_count = 1;
  1920. column->SortOrder = 0;
  1921. break;
  1922. }
  1923. }
  1924. table->SortSpecsCount = (ImS8)sort_order_count;
  1925. }
  1926. //-------------------------------------------------------------------------
  1927. // TABLE - .ini settings
  1928. //-------------------------------------------------------------------------
  1929. // [Init] 1: TableSettingsHandler_ReadXXXX() Load and parse .ini file into TableSettings.
  1930. // [Main] 2: TableLoadSettings() When table is created, bind Table to TableSettings, serialize TableSettings data into Table.
  1931. // [Main] 3: TableSaveSettings() When table properties are modified, serialize Table data into bound or new TableSettings, mark .ini as dirty.
  1932. // [Main] 4: TableSettingsHandler_WriteAll() When .ini file is dirty (which can come from other source), save TableSettings into .ini file.
  1933. //-------------------------------------------------------------------------
  1934. static ImGuiTableSettings* CreateTableSettings(ImGuiID id, int columns_count)
  1935. {
  1936. ImGuiContext& g = *GImGui;
  1937. ImGuiTableSettings* settings = g.SettingsTables.alloc_chunk(sizeof(ImGuiTableSettings) + (size_t)columns_count * sizeof(ImGuiTableColumnSettings));
  1938. IM_PLACEMENT_NEW(settings) ImGuiTableSettings();
  1939. ImGuiTableColumnSettings* settings_column = settings->GetColumnSettings();
  1940. for (int n = 0; n < columns_count; n++, settings_column++)
  1941. IM_PLACEMENT_NEW(settings_column) ImGuiTableColumnSettings();
  1942. settings->ID = id;
  1943. settings->ColumnsCount = settings->ColumnsCountMax = (ImS8)columns_count;
  1944. return settings;
  1945. }
  1946. static ImGuiTableSettings* FindTableSettingsByID(ImGuiID id)
  1947. {
  1948. // FIXME-OPT: Might want to store a lookup map for this?
  1949. ImGuiContext& g = *GImGui;
  1950. for (ImGuiTableSettings* settings = g.SettingsTables.begin(); settings != NULL; settings = g.SettingsTables.next_chunk(settings))
  1951. if (settings->ID == id)
  1952. return settings;
  1953. return NULL;
  1954. }
  1955. ImGuiTableSettings* ImGui::TableFindSettings(ImGuiTable* table)
  1956. {
  1957. if (table->SettingsOffset == -1)
  1958. return NULL;
  1959. ImGuiContext& g = *GImGui;
  1960. ImGuiTableSettings* settings = g.SettingsTables.ptr_from_offset(table->SettingsOffset);
  1961. IM_ASSERT(settings->ID == table->ID);
  1962. if (settings->ColumnsCountMax < table->ColumnsCount)
  1963. {
  1964. settings->ID = 0; // Ditch storage if we won't fit because of a count change
  1965. return NULL;
  1966. }
  1967. return settings;
  1968. }
  1969. void ImGui::TableSaveSettings(ImGuiTable* table)
  1970. {
  1971. table->IsSettingsDirty = false;
  1972. if (table->Flags & ImGuiTableFlags_NoSavedSettings)
  1973. return;
  1974. // Bind or create settings data
  1975. ImGuiContext& g = *GImGui;
  1976. ImGuiTableSettings* settings = TableFindSettings(table);
  1977. if (settings == NULL)
  1978. {
  1979. settings = CreateTableSettings(table->ID, table->ColumnsCount);
  1980. table->SettingsOffset = g.SettingsTables.offset_from_ptr(settings);
  1981. }
  1982. settings->ColumnsCount = (ImS8)table->ColumnsCount;
  1983. // Serialize ImGuiTableSettings/ImGuiTableColumnSettings --> ImGuiTable/ImGuiTableColumn
  1984. IM_ASSERT(settings->ID == table->ID);
  1985. IM_ASSERT(settings->ColumnsCount == table->ColumnsCount && settings->ColumnsCountMax >= settings->ColumnsCount);
  1986. ImGuiTableColumn* column = table->Columns.Data;
  1987. ImGuiTableColumnSettings* column_settings = settings->GetColumnSettings();
  1988. // FIXME-TABLE: Logic to avoid saving default widths?
  1989. settings->SaveFlags = ImGuiTableFlags_Resizable;
  1990. for (int n = 0; n < table->ColumnsCount; n++, column++, column_settings++)
  1991. {
  1992. //column_settings->WidthOrWeight = column->WidthRequested; // FIXME-WIP
  1993. column_settings->Index = (ImS8)n;
  1994. column_settings->DisplayOrder = column->IndexDisplayOrder;
  1995. column_settings->SortOrder = column->SortOrder;
  1996. column_settings->SortDirection = column->SortDirection;
  1997. column_settings->Visible = column->IsActive;
  1998. // We skip saving some data in the .ini file when they are unnecessary to restore our state
  1999. // FIXME-TABLE: We don't have logic to easily compare SortOrder to DefaultSortOrder yet.
  2000. if (column->IndexDisplayOrder != n)
  2001. settings->SaveFlags |= ImGuiTableFlags_Reorderable;;
  2002. if (column_settings->SortOrder != -1)
  2003. settings->SaveFlags |= ImGuiTableFlags_Sortable;
  2004. if (column_settings->Visible != ((column->Flags & ImGuiTableColumnFlags_DefaultHide) == 0))
  2005. settings->SaveFlags |= ImGuiTableFlags_Hideable;
  2006. }
  2007. settings->SaveFlags &= table->Flags;
  2008. MarkIniSettingsDirty();
  2009. }
  2010. void ImGui::TableLoadSettings(ImGuiTable* table)
  2011. {
  2012. ImGuiContext& g = *GImGui;
  2013. table->IsSettingsRequestLoad = false;
  2014. if (table->Flags & ImGuiTableFlags_NoSavedSettings)
  2015. return;
  2016. // Bind settings
  2017. ImGuiTableSettings* settings;
  2018. if (table->SettingsOffset == -1)
  2019. {
  2020. settings = FindTableSettingsByID(table->ID);
  2021. if (settings == NULL)
  2022. return;
  2023. table->SettingsOffset = g.SettingsTables.offset_from_ptr(settings);
  2024. }
  2025. else
  2026. {
  2027. settings = g.SettingsTables.ptr_from_offset(table->SettingsOffset);
  2028. }
  2029. table->IsSettingsLoaded = true;
  2030. settings->SaveFlags = table->Flags;
  2031. // Serialize ImGuiTable/ImGuiTableColumn --> ImGuiTableSettings/ImGuiTableColumnSettings
  2032. ImGuiTableColumnSettings* column_settings = settings->GetColumnSettings();
  2033. for (int data_n = 0; data_n < settings->ColumnsCount; data_n++, column_settings++)
  2034. {
  2035. int column_n = column_settings->Index;
  2036. if (column_n < 0 || column_n >= table->ColumnsCount)
  2037. continue;
  2038. ImGuiTableColumn* column = &table->Columns[column_n];
  2039. //column->WidthRequested = column_settings->WidthOrWeight; // FIXME-WIP
  2040. if (column_settings->DisplayOrder != -1)
  2041. column->IndexDisplayOrder = column_settings->DisplayOrder;
  2042. if (column_settings->SortOrder != -1)
  2043. {
  2044. column->SortOrder = column_settings->SortOrder;
  2045. column->SortDirection = column_settings->SortDirection;
  2046. }
  2047. column->IsActive = column->NextIsActive = column_settings->Visible;
  2048. }
  2049. // FIXME-TABLE: Need to validate .ini data
  2050. for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
  2051. table->DisplayOrder[table->Columns[column_n].IndexDisplayOrder] = (ImU8)column_n;
  2052. }
  2053. void* ImGui::TableSettingsHandler_ReadOpen(ImGuiContext*, ImGuiSettingsHandler*, const char* name)
  2054. {
  2055. ImGuiID id = 0;
  2056. int columns_count = 0;
  2057. if (sscanf(name, "0x%08X,%d", &id, &columns_count) < 2)
  2058. return NULL;
  2059. return CreateTableSettings(id, columns_count);
  2060. }
  2061. void ImGui::TableSettingsHandler_ReadLine(ImGuiContext*, ImGuiSettingsHandler*, void* entry, const char* line)
  2062. {
  2063. // "Column 0 UserID=0x42AD2D21 Width=100 Visible=1 Order=0 Sort=0v"
  2064. ImGuiTableSettings* settings = (ImGuiTableSettings*)entry;
  2065. int column_n = 0, r = 0, n = 0;
  2066. if (sscanf(line, "Column %d%n", &column_n, &r) == 1) { line = ImStrSkipBlank(line + r); } else { return; }
  2067. if (column_n < 0 || column_n >= settings->ColumnsCount)
  2068. return;
  2069. char c = 0;
  2070. ImGuiTableColumnSettings* column = settings->GetColumnSettings() + column_n;
  2071. column->Index = (ImS8)column_n;
  2072. if (sscanf(line, "UserID=0x%08X%n", (ImU32*)&n, &r) == 1) { line = ImStrSkipBlank(line + r); column->UserID = (ImGuiID)n; }
  2073. if (sscanf(line, "Width=%d%n", &n, &r) == 1) { line = ImStrSkipBlank(line + r); /* .. */ settings->SaveFlags |= ImGuiTableFlags_Resizable; }
  2074. if (sscanf(line, "Visible=%d%n", &n, &r) == 1) { line = ImStrSkipBlank(line + r); column->Visible = (ImU8)n; settings->SaveFlags |= ImGuiTableFlags_Hideable; }
  2075. if (sscanf(line, "Order=%d%n", &n, &r) == 1) { line = ImStrSkipBlank(line + r); column->DisplayOrder = (ImS8)n; settings->SaveFlags |= ImGuiTableFlags_Reorderable; }
  2076. if (sscanf(line, "Sort=%d%c%n", &n, &c, &r) == 2) { line = ImStrSkipBlank(line + r); column->SortOrder = (ImS8)n; column->SortDirection = (c == '^') ? ImGuiSortDirection_Descending : ImGuiSortDirection_Ascending; settings->SaveFlags |= ImGuiTableFlags_Sortable; }
  2077. }
  2078. void ImGui::TableSettingsHandler_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandler* handler, ImGuiTextBuffer* buf)
  2079. {
  2080. ImGuiContext& g = *ctx;
  2081. for (ImGuiTableSettings* settings = g.SettingsTables.begin(); settings != NULL; settings = g.SettingsTables.next_chunk(settings))
  2082. {
  2083. if (settings->ID == 0) // Skip ditched settings
  2084. continue;
  2085. // TableSaveSettings() may clear some of those flags when we establish that the data can be stripped (e.g. Order was unchanged)
  2086. const bool save_size = (settings->SaveFlags & ImGuiTableFlags_Resizable) != 0;
  2087. const bool save_visible = (settings->SaveFlags & ImGuiTableFlags_Hideable) != 0;
  2088. const bool save_order = (settings->SaveFlags & ImGuiTableFlags_Reorderable) != 0;
  2089. const bool save_sort = (settings->SaveFlags & ImGuiTableFlags_Sortable) != 0;
  2090. if (!save_size && !save_visible && !save_order && !save_sort)
  2091. continue;
  2092. buf->reserve(buf->size() + 30 + settings->ColumnsCount * 50); // ballpark reserve
  2093. buf->appendf("[%s][0x%08X,%d]\n", handler->TypeName, settings->ID, settings->ColumnsCount);
  2094. ImGuiTableColumnSettings* column = settings->GetColumnSettings();
  2095. for (int column_n = 0; column_n < settings->ColumnsCount; column_n++, column++)
  2096. {
  2097. // "Column 0 UserID=0x42AD2D21 Width=100 Visible=1 Order=0 Sort=0v"
  2098. if (column->UserID != 0)
  2099. buf->appendf("Column %-2d UserID=%08X", column_n, column->UserID);
  2100. else
  2101. buf->appendf("Column %-2d", column_n);
  2102. if (save_size) buf->appendf(" Width=%d", 0);// (int)settings_column->WidthOrWeight); // FIXME-TABLE
  2103. if (save_visible) buf->appendf(" Visible=%d", column->Visible);
  2104. if (save_order) buf->appendf(" Order=%d", column->DisplayOrder);
  2105. if (save_sort && column->SortOrder != -1) buf->appendf(" Sort=%d%c", column->SortOrder, (column->SortDirection == ImGuiSortDirection_Ascending) ? 'v' : '^');
  2106. buf->append("\n");
  2107. }
  2108. buf->append("\n");
  2109. }
  2110. }
  2111. //-------------------------------------------------------------------------
  2112. // TABLE - Debugging
  2113. //-------------------------------------------------------------------------
  2114. // - DebugNodeTable() [Internal]
  2115. //-------------------------------------------------------------------------
  2116. #ifndef IMGUI_DISABLE_METRICS_WINDOW
  2117. void ImGui::DebugNodeTable(ImGuiTable* table)
  2118. {
  2119. char buf[256];
  2120. char* p = buf;
  2121. const char* buf_end = buf + IM_ARRAYSIZE(buf);
  2122. ImFormatString(p, buf_end - p, "Table 0x%08X (%d columns, in '%s')", table->ID, table->ColumnsCount, table->OuterWindow->Name);
  2123. bool open = TreeNode(table, "%s", buf);
  2124. if (IsItemHovered())
  2125. GetForegroundDrawList()->AddRect(table->OuterRect.Min, table->OuterRect.Max, IM_COL32(255, 255, 0, 255));
  2126. if (open)
  2127. {
  2128. for (int n = 0; n < table->ColumnsCount; n++)
  2129. {
  2130. ImGuiTableColumn* column = &table->Columns[n];
  2131. const char* name = TableGetColumnName(table, n);
  2132. BulletText("Column %d order %d name '%s': +%.1f to +%.1f\n"
  2133. "Active: %d, Clipped: %d, DrawChannels: %d,%d\n"
  2134. "WidthGiven/Requested: %.1f/%.1f, Weight: %.2f\n"
  2135. "UserID: 0x%08X, Flags: 0x%04X: %s%s%s%s..",
  2136. n, column->IndexDisplayOrder, name ? name : "NULL", column->MinX - table->WorkRect.Min.x, column->MaxX - table->WorkRect.Min.x,
  2137. column->IsActive, column->IsClipped, column->DrawChannelRowsBeforeFreeze, column->DrawChannelRowsAfterFreeze,
  2138. column->WidthGiven, column->WidthRequested, column->ResizeWeight,
  2139. column->UserID, column->Flags,
  2140. (column->Flags & ImGuiTableColumnFlags_WidthFixed) ? "WidthFixed " : "",
  2141. (column->Flags & ImGuiTableColumnFlags_WidthStretch) ? "WidthStretch " : "",
  2142. (column->Flags & ImGuiTableColumnFlags_WidthAlwaysAutoResize) ? "WidthAlwaysAutoResize " : "",
  2143. (column->Flags & ImGuiTableColumnFlags_NoResize) ? "NoResize " : "");
  2144. }
  2145. ImGuiTableSettings* settings = TableFindSettings(table);
  2146. if (settings && TreeNode("Settings"))
  2147. {
  2148. BulletText("SaveFlags: 0x%08X", settings->SaveFlags);
  2149. BulletText("ColumnsCount: %d (max %d)", settings->ColumnsCount, settings->ColumnsCountMax);
  2150. for (int n = 0; n < settings->ColumnsCount; n++)
  2151. {
  2152. ImGuiTableColumnSettings* column_settings = &settings->GetColumnSettings()[n];
  2153. BulletText("Column %d Order %d SortOrder %d Visible %d UserID 0x%08X WidthOrWeight %.3f",
  2154. n, column_settings->DisplayOrder, column_settings->SortOrder, column_settings->Visible, column_settings->UserID, column_settings->WidthOrWeight);
  2155. }
  2156. TreePop();
  2157. }
  2158. TreePop();
  2159. }
  2160. }
  2161. #endif // #ifndef IMGUI_DISABLE_METRICS_WINDOW
  2162. //-------------------------------------------------------------------------
  2163. //-------------------------------------------------------------------------
  2164. // [SECTION] Widgets: Columns, BeginColumns, EndColumns, etc.
  2165. // (This is a legacy API, prefer using BeginTable/EndTable!)
  2166. //-------------------------------------------------------------------------
  2167. // - SetWindowClipRectBeforeSetChannel() [Internal]
  2168. // - GetColumnIndex()
  2169. // - GetColumnsCount()
  2170. // - GetColumnOffset()
  2171. // - GetColumnWidth()
  2172. // - SetColumnOffset()
  2173. // - SetColumnWidth()
  2174. // - PushColumnClipRect() [Internal]
  2175. // - PushColumnsBackground() [Internal]
  2176. // - PopColumnsBackground() [Internal]
  2177. // - FindOrCreateColumns() [Internal]
  2178. // - GetColumnsID() [Internal]
  2179. // - BeginColumns()
  2180. // - NextColumn()
  2181. // - EndColumns()
  2182. // - Columns()
  2183. //-------------------------------------------------------------------------
  2184. // [Internal] Small optimization to avoid calls to PopClipRect/SetCurrentChannel/PushClipRect in sequences,
  2185. // they would meddle many times with the underlying ImDrawCmd.
  2186. // Instead, we do a preemptive overwrite of clipping rectangle _without_ altering the command-buffer and let
  2187. // the subsequent single call to SetCurrentChannel() does it things once.
  2188. void ImGui::SetWindowClipRectBeforeSetChannel(ImGuiWindow* window, const ImRect& clip_rect)
  2189. {
  2190. ImVec4 clip_rect_vec4 = clip_rect.ToVec4();
  2191. window->ClipRect = clip_rect;
  2192. window->DrawList->_CmdHeader.ClipRect = clip_rect_vec4;
  2193. window->DrawList->_ClipRectStack.Data[window->DrawList->_ClipRectStack.Size - 1] = clip_rect_vec4;
  2194. }
  2195. int ImGui::GetColumnIndex()
  2196. {
  2197. ImGuiWindow* window = GetCurrentWindowRead();
  2198. return window->DC.CurrentColumns ? window->DC.CurrentColumns->Current : 0;
  2199. }
  2200. int ImGui::GetColumnsCount()
  2201. {
  2202. ImGuiWindow* window = GetCurrentWindowRead();
  2203. return window->DC.CurrentColumns ? window->DC.CurrentColumns->Count : 1;
  2204. }
  2205. float ImGui::GetColumnOffsetFromNorm(const ImGuiOldColumns* columns, float offset_norm)
  2206. {
  2207. return offset_norm * (columns->OffMaxX - columns->OffMinX);
  2208. }
  2209. float ImGui::GetColumnNormFromOffset(const ImGuiOldColumns* columns, float offset)
  2210. {
  2211. return offset / (columns->OffMaxX - columns->OffMinX);
  2212. }
  2213. static const float COLUMNS_HIT_RECT_HALF_WIDTH = 4.0f;
  2214. static float GetDraggedColumnOffset(ImGuiOldColumns* columns, int column_index)
  2215. {
  2216. // Active (dragged) column always follow mouse. The reason we need this is that dragging a column to the right edge of an auto-resizing
  2217. // window creates a feedback loop because we store normalized positions. So while dragging we enforce absolute positioning.
  2218. ImGuiContext& g = *GImGui;
  2219. ImGuiWindow* window = g.CurrentWindow;
  2220. IM_ASSERT(column_index > 0); // We are not supposed to drag column 0.
  2221. IM_ASSERT(g.ActiveId == columns->ID + ImGuiID(column_index));
  2222. float x = g.IO.MousePos.x - g.ActiveIdClickOffset.x + COLUMNS_HIT_RECT_HALF_WIDTH - window->Pos.x;
  2223. x = ImMax(x, ImGui::GetColumnOffset(column_index - 1) + g.Style.ColumnsMinSpacing);
  2224. if ((columns->Flags & ImGuiOldColumnFlags_NoPreserveWidths))
  2225. x = ImMin(x, ImGui::GetColumnOffset(column_index + 1) - g.Style.ColumnsMinSpacing);
  2226. return x;
  2227. }
  2228. float ImGui::GetColumnOffset(int column_index)
  2229. {
  2230. ImGuiWindow* window = GetCurrentWindowRead();
  2231. ImGuiOldColumns* columns = window->DC.CurrentColumns;
  2232. if (columns == NULL)
  2233. return 0.0f;
  2234. if (column_index < 0)
  2235. column_index = columns->Current;
  2236. IM_ASSERT(column_index < columns->Columns.Size);
  2237. const float t = columns->Columns[column_index].OffsetNorm;
  2238. const float x_offset = ImLerp(columns->OffMinX, columns->OffMaxX, t);
  2239. return x_offset;
  2240. }
  2241. static float GetColumnWidthEx(ImGuiOldColumns* columns, int column_index, bool before_resize = false)
  2242. {
  2243. if (column_index < 0)
  2244. column_index = columns->Current;
  2245. float offset_norm;
  2246. if (before_resize)
  2247. offset_norm = columns->Columns[column_index + 1].OffsetNormBeforeResize - columns->Columns[column_index].OffsetNormBeforeResize;
  2248. else
  2249. offset_norm = columns->Columns[column_index + 1].OffsetNorm - columns->Columns[column_index].OffsetNorm;
  2250. return ImGui::GetColumnOffsetFromNorm(columns, offset_norm);
  2251. }
  2252. float ImGui::GetColumnWidth(int column_index)
  2253. {
  2254. ImGuiContext& g = *GImGui;
  2255. ImGuiWindow* window = g.CurrentWindow;
  2256. ImGuiOldColumns* columns = window->DC.CurrentColumns;
  2257. if (columns == NULL)
  2258. return GetContentRegionAvail().x;
  2259. if (column_index < 0)
  2260. column_index = columns->Current;
  2261. return GetColumnOffsetFromNorm(columns, columns->Columns[column_index + 1].OffsetNorm - columns->Columns[column_index].OffsetNorm);
  2262. }
  2263. void ImGui::SetColumnOffset(int column_index, float offset)
  2264. {
  2265. ImGuiContext& g = *GImGui;
  2266. ImGuiWindow* window = g.CurrentWindow;
  2267. ImGuiOldColumns* columns = window->DC.CurrentColumns;
  2268. IM_ASSERT(columns != NULL);
  2269. if (column_index < 0)
  2270. column_index = columns->Current;
  2271. IM_ASSERT(column_index < columns->Columns.Size);
  2272. const bool preserve_width = !(columns->Flags & ImGuiOldColumnFlags_NoPreserveWidths) && (column_index < columns->Count - 1);
  2273. const float width = preserve_width ? GetColumnWidthEx(columns, column_index, columns->IsBeingResized) : 0.0f;
  2274. if (!(columns->Flags & ImGuiOldColumnFlags_NoForceWithinWindow))
  2275. offset = ImMin(offset, columns->OffMaxX - g.Style.ColumnsMinSpacing * (columns->Count - column_index));
  2276. columns->Columns[column_index].OffsetNorm = GetColumnNormFromOffset(columns, offset - columns->OffMinX);
  2277. if (preserve_width)
  2278. SetColumnOffset(column_index + 1, offset + ImMax(g.Style.ColumnsMinSpacing, width));
  2279. }
  2280. void ImGui::SetColumnWidth(int column_index, float width)
  2281. {
  2282. ImGuiWindow* window = GetCurrentWindowRead();
  2283. ImGuiOldColumns* columns = window->DC.CurrentColumns;
  2284. IM_ASSERT(columns != NULL);
  2285. if (column_index < 0)
  2286. column_index = columns->Current;
  2287. SetColumnOffset(column_index + 1, GetColumnOffset(column_index) + width);
  2288. }
  2289. void ImGui::PushColumnClipRect(int column_index)
  2290. {
  2291. ImGuiWindow* window = GetCurrentWindowRead();
  2292. ImGuiOldColumns* columns = window->DC.CurrentColumns;
  2293. if (column_index < 0)
  2294. column_index = columns->Current;
  2295. ImGuiOldColumnData* column = &columns->Columns[column_index];
  2296. PushClipRect(column->ClipRect.Min, column->ClipRect.Max, false);
  2297. }
  2298. // Get into the columns background draw command (which is generally the same draw command as before we called BeginColumns)
  2299. void ImGui::PushColumnsBackground()
  2300. {
  2301. ImGuiWindow* window = GetCurrentWindowRead();
  2302. ImGuiOldColumns* columns = window->DC.CurrentColumns;
  2303. if (columns->Count == 1)
  2304. return;
  2305. // Optimization: avoid SetCurrentChannel() + PushClipRect()
  2306. columns->HostBackupClipRect = window->ClipRect;
  2307. SetWindowClipRectBeforeSetChannel(window, columns->HostInitialClipRect);
  2308. columns->Splitter.SetCurrentChannel(window->DrawList, 0);
  2309. }
  2310. void ImGui::PopColumnsBackground()
  2311. {
  2312. ImGuiWindow* window = GetCurrentWindowRead();
  2313. ImGuiOldColumns* columns = window->DC.CurrentColumns;
  2314. if (columns->Count == 1)
  2315. return;
  2316. // Optimization: avoid PopClipRect() + SetCurrentChannel()
  2317. SetWindowClipRectBeforeSetChannel(window, columns->HostBackupClipRect);
  2318. columns->Splitter.SetCurrentChannel(window->DrawList, columns->Current + 1);
  2319. }
  2320. ImGuiOldColumns* ImGui::FindOrCreateColumns(ImGuiWindow* window, ImGuiID id)
  2321. {
  2322. // We have few columns per window so for now we don't need bother much with turning this into a faster lookup.
  2323. for (int n = 0; n < window->ColumnsStorage.Size; n++)
  2324. if (window->ColumnsStorage[n].ID == id)
  2325. return &window->ColumnsStorage[n];
  2326. window->ColumnsStorage.push_back(ImGuiOldColumns());
  2327. ImGuiOldColumns* columns = &window->ColumnsStorage.back();
  2328. columns->ID = id;
  2329. return columns;
  2330. }
  2331. ImGuiID ImGui::GetColumnsID(const char* str_id, int columns_count)
  2332. {
  2333. ImGuiWindow* window = GetCurrentWindow();
  2334. // Differentiate column ID with an arbitrary prefix for cases where users name their columns set the same as another widget.
  2335. // In addition, when an identifier isn't explicitly provided we include the number of columns in the hash to make it uniquer.
  2336. PushID(0x11223347 + (str_id ? 0 : columns_count));
  2337. ImGuiID id = window->GetID(str_id ? str_id : "columns");
  2338. PopID();
  2339. return id;
  2340. }
  2341. void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiOldColumnFlags flags)
  2342. {
  2343. ImGuiContext& g = *GImGui;
  2344. ImGuiWindow* window = GetCurrentWindow();
  2345. IM_ASSERT(columns_count >= 1);
  2346. IM_ASSERT(window->DC.CurrentColumns == NULL); // Nested columns are currently not supported
  2347. // Acquire storage for the columns set
  2348. ImGuiID id = GetColumnsID(str_id, columns_count);
  2349. ImGuiOldColumns* columns = FindOrCreateColumns(window, id);
  2350. IM_ASSERT(columns->ID == id);
  2351. columns->Current = 0;
  2352. columns->Count = columns_count;
  2353. columns->Flags = flags;
  2354. window->DC.CurrentColumns = columns;
  2355. columns->HostCursorPosY = window->DC.CursorPos.y;
  2356. columns->HostCursorMaxPosX = window->DC.CursorMaxPos.x;
  2357. columns->HostInitialClipRect = window->ClipRect;
  2358. columns->HostBackupParentWorkRect = window->ParentWorkRect;
  2359. window->ParentWorkRect = window->WorkRect;
  2360. // Set state for first column
  2361. // We aim so that the right-most column will have the same clipping width as other after being clipped by parent ClipRect
  2362. const float column_padding = g.Style.ItemSpacing.x;
  2363. const float half_clip_extend_x = ImFloor(ImMax(window->WindowPadding.x * 0.5f, window->WindowBorderSize));
  2364. const float max_1 = window->WorkRect.Max.x + column_padding - ImMax(column_padding - window->WindowPadding.x, 0.0f);
  2365. const float max_2 = window->WorkRect.Max.x + half_clip_extend_x;
  2366. columns->OffMinX = window->DC.Indent.x - column_padding + ImMax(column_padding - window->WindowPadding.x, 0.0f);
  2367. columns->OffMaxX = ImMax(ImMin(max_1, max_2) - window->Pos.x, columns->OffMinX + 1.0f);
  2368. columns->LineMinY = columns->LineMaxY = window->DC.CursorPos.y;
  2369. // Clear data if columns count changed
  2370. if (columns->Columns.Size != 0 && columns->Columns.Size != columns_count + 1)
  2371. columns->Columns.resize(0);
  2372. // Initialize default widths
  2373. columns->IsFirstFrame = (columns->Columns.Size == 0);
  2374. if (columns->Columns.Size == 0)
  2375. {
  2376. columns->Columns.reserve(columns_count + 1);
  2377. for (int n = 0; n < columns_count + 1; n++)
  2378. {
  2379. ImGuiOldColumnData column;
  2380. column.OffsetNorm = n / (float)columns_count;
  2381. columns->Columns.push_back(column);
  2382. }
  2383. }
  2384. for (int n = 0; n < columns_count; n++)
  2385. {
  2386. // Compute clipping rectangle
  2387. ImGuiOldColumnData* column = &columns->Columns[n];
  2388. float clip_x1 = IM_ROUND(window->Pos.x + GetColumnOffset(n));
  2389. float clip_x2 = IM_ROUND(window->Pos.x + GetColumnOffset(n + 1) - 1.0f);
  2390. column->ClipRect = ImRect(clip_x1, -FLT_MAX, clip_x2, +FLT_MAX);
  2391. column->ClipRect.ClipWithFull(window->ClipRect);
  2392. }
  2393. if (columns->Count > 1)
  2394. {
  2395. columns->Splitter.Split(window->DrawList, 1 + columns->Count);
  2396. columns->Splitter.SetCurrentChannel(window->DrawList, 1);
  2397. PushColumnClipRect(0);
  2398. }
  2399. // We don't generally store Indent.x inside ColumnsOffset because it may be manipulated by the user.
  2400. float offset_0 = GetColumnOffset(columns->Current);
  2401. float offset_1 = GetColumnOffset(columns->Current + 1);
  2402. float width = offset_1 - offset_0;
  2403. PushItemWidth(width * 0.65f);
  2404. window->DC.ColumnsOffset.x = ImMax(column_padding - window->WindowPadding.x, 0.0f);
  2405. window->DC.CursorPos.x = IM_FLOOR(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x);
  2406. window->WorkRect.Max.x = window->Pos.x + offset_1 - column_padding;
  2407. }
  2408. void ImGui::NextColumn()
  2409. {
  2410. ImGuiWindow* window = GetCurrentWindow();
  2411. if (window->SkipItems || window->DC.CurrentColumns == NULL)
  2412. return;
  2413. ImGuiContext& g = *GImGui;
  2414. ImGuiOldColumns* columns = window->DC.CurrentColumns;
  2415. if (columns->Count == 1)
  2416. {
  2417. window->DC.CursorPos.x = IM_FLOOR(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x);
  2418. IM_ASSERT(columns->Current == 0);
  2419. return;
  2420. }
  2421. // Next column
  2422. if (++columns->Current == columns->Count)
  2423. columns->Current = 0;
  2424. PopItemWidth();
  2425. // Optimization: avoid PopClipRect() + SetCurrentChannel() + PushClipRect()
  2426. // (which would needlessly attempt to update commands in the wrong channel, then pop or overwrite them),
  2427. ImGuiOldColumnData* column = &columns->Columns[columns->Current];
  2428. SetWindowClipRectBeforeSetChannel(window, column->ClipRect);
  2429. columns->Splitter.SetCurrentChannel(window->DrawList, columns->Current + 1);
  2430. const float column_padding = g.Style.ItemSpacing.x;
  2431. columns->LineMaxY = ImMax(columns->LineMaxY, window->DC.CursorPos.y);
  2432. if (columns->Current > 0)
  2433. {
  2434. // Columns 1+ ignore IndentX (by canceling it out)
  2435. // FIXME-COLUMNS: Unnecessary, could be locked?
  2436. window->DC.ColumnsOffset.x = GetColumnOffset(columns->Current) - window->DC.Indent.x + column_padding;
  2437. }
  2438. else
  2439. {
  2440. // New row/line: column 0 honor IndentX.
  2441. window->DC.ColumnsOffset.x = ImMax(column_padding - window->WindowPadding.x, 0.0f);
  2442. columns->LineMinY = columns->LineMaxY;
  2443. }
  2444. window->DC.CursorPos.x = IM_FLOOR(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x);
  2445. window->DC.CursorPos.y = columns->LineMinY;
  2446. window->DC.CurrLineSize = ImVec2(0.0f, 0.0f);
  2447. window->DC.CurrLineTextBaseOffset = 0.0f;
  2448. // FIXME-COLUMNS: Share code with BeginColumns() - move code on columns setup.
  2449. float offset_0 = GetColumnOffset(columns->Current);
  2450. float offset_1 = GetColumnOffset(columns->Current + 1);
  2451. float width = offset_1 - offset_0;
  2452. PushItemWidth(width * 0.65f);
  2453. window->WorkRect.Max.x = window->Pos.x + offset_1 - column_padding;
  2454. }
  2455. void ImGui::EndColumns()
  2456. {
  2457. ImGuiContext& g = *GImGui;
  2458. ImGuiWindow* window = GetCurrentWindow();
  2459. ImGuiOldColumns* columns = window->DC.CurrentColumns;
  2460. IM_ASSERT(columns != NULL);
  2461. PopItemWidth();
  2462. if (columns->Count > 1)
  2463. {
  2464. PopClipRect();
  2465. columns->Splitter.Merge(window->DrawList);
  2466. }
  2467. const ImGuiOldColumnFlags flags = columns->Flags;
  2468. columns->LineMaxY = ImMax(columns->LineMaxY, window->DC.CursorPos.y);
  2469. window->DC.CursorPos.y = columns->LineMaxY;
  2470. if (!(flags & ImGuiOldColumnFlags_GrowParentContentsSize))
  2471. window->DC.CursorMaxPos.x = columns->HostCursorMaxPosX; // Restore cursor max pos, as columns don't grow parent
  2472. // Draw columns borders and handle resize
  2473. // The IsBeingResized flag ensure we preserve pre-resize columns width so back-and-forth are not lossy
  2474. bool is_being_resized = false;
  2475. if (!(flags & ImGuiOldColumnFlags_NoBorder) && !window->SkipItems)
  2476. {
  2477. // We clip Y boundaries CPU side because very long triangles are mishandled by some GPU drivers.
  2478. const float y1 = ImMax(columns->HostCursorPosY, window->ClipRect.Min.y);
  2479. const float y2 = ImMin(window->DC.CursorPos.y, window->ClipRect.Max.y);
  2480. int dragging_column = -1;
  2481. for (int n = 1; n < columns->Count; n++)
  2482. {
  2483. ImGuiOldColumnData* column = &columns->Columns[n];
  2484. float x = window->Pos.x + GetColumnOffset(n);
  2485. const ImGuiID column_id = columns->ID + ImGuiID(n);
  2486. const float column_hit_hw = COLUMNS_HIT_RECT_HALF_WIDTH;
  2487. const ImRect column_hit_rect(ImVec2(x - column_hit_hw, y1), ImVec2(x + column_hit_hw, y2));
  2488. KeepAliveID(column_id);
  2489. if (IsClippedEx(column_hit_rect, column_id, false))
  2490. continue;
  2491. bool hovered = false, held = false;
  2492. if (!(flags & ImGuiOldColumnFlags_NoResize))
  2493. {
  2494. ButtonBehavior(column_hit_rect, column_id, &hovered, &held);
  2495. if (hovered || held)
  2496. g.MouseCursor = ImGuiMouseCursor_ResizeEW;
  2497. if (held && !(column->Flags & ImGuiOldColumnFlags_NoResize))
  2498. dragging_column = n;
  2499. }
  2500. // Draw column
  2501. const ImU32 col = GetColorU32(held ? ImGuiCol_SeparatorActive : hovered ? ImGuiCol_SeparatorHovered : ImGuiCol_Separator);
  2502. const float xi = IM_FLOOR(x);
  2503. window->DrawList->AddLine(ImVec2(xi, y1 + 1.0f), ImVec2(xi, y2), col);
  2504. }
  2505. // Apply dragging after drawing the column lines, so our rendered lines are in sync with how items were displayed during the frame.
  2506. if (dragging_column != -1)
  2507. {
  2508. if (!columns->IsBeingResized)
  2509. for (int n = 0; n < columns->Count + 1; n++)
  2510. columns->Columns[n].OffsetNormBeforeResize = columns->Columns[n].OffsetNorm;
  2511. columns->IsBeingResized = is_being_resized = true;
  2512. float x = GetDraggedColumnOffset(columns, dragging_column);
  2513. SetColumnOffset(dragging_column, x);
  2514. }
  2515. }
  2516. columns->IsBeingResized = is_being_resized;
  2517. window->WorkRect = window->ParentWorkRect;
  2518. window->ParentWorkRect = columns->HostBackupParentWorkRect;
  2519. window->DC.CurrentColumns = NULL;
  2520. window->DC.ColumnsOffset.x = 0.0f;
  2521. window->DC.CursorPos.x = IM_FLOOR(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x);
  2522. }
  2523. void ImGui::Columns(int columns_count, const char* id, bool border)
  2524. {
  2525. ImGuiWindow* window = GetCurrentWindow();
  2526. IM_ASSERT(columns_count >= 1);
  2527. ImGuiOldColumnFlags flags = (border ? 0 : ImGuiOldColumnFlags_NoBorder);
  2528. //flags |= ImGuiOldColumnFlags_NoPreserveWidths; // NB: Legacy behavior
  2529. ImGuiOldColumns* columns = window->DC.CurrentColumns;
  2530. if (columns != NULL && columns->Count == columns_count && columns->Flags == flags)
  2531. return;
  2532. if (columns != NULL)
  2533. EndColumns();
  2534. if (columns_count != 1)
  2535. BeginColumns(id, columns_count, flags);
  2536. }
  2537. //-------------------------------------------------------------------------
  2538. #endif // #ifndef IMGUI_DISABLE