Selaa lähdekoodia

Columns: ImDrawList::Channels* functions now work inside columns.

Use a private splitter in columns, paving way for removal of obsolete ImDrawList::Channels* functions.
Rokas Kupstys 5 vuotta sitten
vanhempi
commit
9cff4d6e5e
5 muutettua tiedostoa jossa 16 lisäystä ja 10 poistoa
  1. 2 0
      docs/CHANGELOG.txt
  2. 5 2
      imgui.h
  3. 1 1
      imgui_draw.cpp
  4. 1 0
      imgui_internal.h
  5. 7 7
      imgui_widgets.cpp

+ 2 - 0
docs/CHANGELOG.txt

@@ -79,6 +79,8 @@ Other Changes:
   In the current branch they are essentially the same as AddCircle(), AddCircleFilled() but as
   In the current branch they are essentially the same as AddCircle(), AddCircleFilled() but as
   we will rework the circle rendering functions to use textures and automatic segment count
   we will rework the circle rendering functions to use textures and automatic segment count
   selection, those new api can fill a gap. [@ShironekoBen]
   selection, those new api can fill a gap. [@ShironekoBen]
+- Columns: ImDrawList::Channels* functions now work inside columns. Added extra comments to
+  suggest using user-owned ImDrawListSplitter instead of ImDrawList functions. [@rokups]
 - Misc: Added ImGuiMouseCursor_NotAllowed enum so it can be used by more shared widgets. [@rokups]
 - Misc: Added ImGuiMouseCursor_NotAllowed enum so it can be used by more shared widgets. [@rokups]
 - Misc: Disable format checks when using stb_printf, to allow using extra formats.
 - Misc: Disable format checks when using stb_printf, to allow using extra formats.
   Made IMGUI_USE_STB_SPRINTF a properly documented imconfig.h flag. (#2954) [@loicmolinari]
   Made IMGUI_USE_STB_SPRINTF a properly documented imconfig.h flag. (#2954) [@loicmolinari]

+ 5 - 2
imgui.h

@@ -1987,8 +1987,11 @@ struct ImDrawList
     IMGUI_API ImDrawList* CloneOutput() const;                                  // Create a clone of the CmdBuffer/IdxBuffer/VtxBuffer.
     IMGUI_API ImDrawList* CloneOutput() const;                                  // Create a clone of the CmdBuffer/IdxBuffer/VtxBuffer.
 
 
     // Advanced: Channels
     // Advanced: Channels
-    // - Use to split render into layers. By switching channels to can render out-of-order (e.g. submit foreground primitives before background primitives)
-    // - Use to minimize draw calls (e.g. if going back-and-forth between multiple non-overlapping clipping rectangles, prefer to append into separate channels then merge at the end)
+    // - Use to split render into layers. By switching channels to can render out-of-order (e.g. submit FG primitives before BG primitives)
+    // - Use to minimize draw calls (e.g. if going back-and-forth between multiple clipping rectangles, prefer to append into separate channels then merge at the end)
+    // - FIXME-OBSOLETE: This API shouldn't have been in ImDrawList in the first place!
+    //   Prefer using your own persistent copy of ImDrawListSplitter as you can stack them.
+    //   Using the ImDrawList::ChannelsXXXX you cannot stack a split over another.
     inline void     ChannelsSplit(int count)    { _Splitter.Split(this, count); }
     inline void     ChannelsSplit(int count)    { _Splitter.Split(this, count); }
     inline void     ChannelsMerge()             { _Splitter.Merge(this); }
     inline void     ChannelsMerge()             { _Splitter.Merge(this); }
     inline void     ChannelsSetCurrent(int n)   { _Splitter.SetCurrentChannel(this, n); }
     inline void     ChannelsSetCurrent(int n)   { _Splitter.SetCurrentChannel(this, n); }

+ 1 - 1
imgui_draw.cpp

@@ -1307,7 +1307,7 @@ void ImDrawListSplitter::ClearFreeMemory()
 
 
 void ImDrawListSplitter::Split(ImDrawList* draw_list, int channels_count)
 void ImDrawListSplitter::Split(ImDrawList* draw_list, int channels_count)
 {
 {
-    IM_ASSERT(_Current == 0 && _Count <= 1);
+    IM_ASSERT(_Current == 0 && _Count <= 1 && "Nested channel splitting is not supported. Please use separate instances of ImDrawListSplitter.");
     int old_channels_count = _Channels.Size;
     int old_channels_count = _Channels.Size;
     if (old_channels_count < channels_count)
     if (old_channels_count < channels_count)
         _Channels.resize(channels_count);
         _Channels.resize(channels_count);

+ 1 - 0
imgui_internal.h

@@ -843,6 +843,7 @@ struct ImGuiColumns
     ImRect              HostClipRect;           // Backup of ClipRect at the time of BeginColumns()
     ImRect              HostClipRect;           // Backup of ClipRect at the time of BeginColumns()
     ImRect              HostWorkRect;           // Backup of WorkRect at the time of BeginColumns()
     ImRect              HostWorkRect;           // Backup of WorkRect at the time of BeginColumns()
     ImVector<ImGuiColumnData> Columns;
     ImVector<ImGuiColumnData> Columns;
+    ImDrawListSplitter  Splitter;
 
 
     ImGuiColumns()      { Clear(); }
     ImGuiColumns()      { Clear(); }
     void Clear()
     void Clear()

+ 7 - 7
imgui_widgets.cpp

@@ -7400,7 +7400,7 @@ void ImGui::PushColumnsBackground()
     ImGuiColumns* columns = window->DC.CurrentColumns;
     ImGuiColumns* columns = window->DC.CurrentColumns;
     if (columns->Count == 1)
     if (columns->Count == 1)
         return;
         return;
-    window->DrawList->ChannelsSetCurrent(0);
+    columns->Splitter.SetCurrentChannel(window->DrawList, 0);
     int cmd_size = window->DrawList->CmdBuffer.Size;
     int cmd_size = window->DrawList->CmdBuffer.Size;
     PushClipRect(columns->HostClipRect.Min, columns->HostClipRect.Max, false);
     PushClipRect(columns->HostClipRect.Min, columns->HostClipRect.Max, false);
     IM_UNUSED(cmd_size);
     IM_UNUSED(cmd_size);
@@ -7413,7 +7413,7 @@ void ImGui::PopColumnsBackground()
     ImGuiColumns* columns = window->DC.CurrentColumns;
     ImGuiColumns* columns = window->DC.CurrentColumns;
     if (columns->Count == 1)
     if (columns->Count == 1)
         return;
         return;
-    window->DrawList->ChannelsSetCurrent(columns->Current + 1);
+    columns->Splitter.SetCurrentChannel(window->DrawList, columns->Current + 1);
     PopClipRect();
     PopClipRect();
 }
 }
 
 
@@ -7504,8 +7504,8 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlag
 
 
     if (columns->Count > 1)
     if (columns->Count > 1)
     {
     {
-        window->DrawList->ChannelsSplit(1 + columns->Count);
-        window->DrawList->ChannelsSetCurrent(1);
+        columns->Splitter.Split(window->DrawList, 1 + columns->Count);
+        columns->Splitter.SetCurrentChannel(window->DrawList, 1);
         PushColumnClipRect(0);
         PushColumnClipRect(0);
     }
     }
 
 
@@ -7544,14 +7544,14 @@ void ImGui::NextColumn()
         // Columns 1+ ignore IndentX (by canceling it out)
         // Columns 1+ ignore IndentX (by canceling it out)
         // FIXME-COLUMNS: Unnecessary, could be locked?
         // FIXME-COLUMNS: Unnecessary, could be locked?
         window->DC.ColumnsOffset.x = GetColumnOffset(columns->Current) - window->DC.Indent.x + column_padding;
         window->DC.ColumnsOffset.x = GetColumnOffset(columns->Current) - window->DC.Indent.x + column_padding;
-        window->DrawList->ChannelsSetCurrent(columns->Current + 1);
+        columns->Splitter.SetCurrentChannel(window->DrawList, columns->Current + 1);
     }
     }
     else
     else
     {
     {
         // New row/line
         // New row/line
         // Column 0 honor IndentX
         // Column 0 honor IndentX
         window->DC.ColumnsOffset.x = ImMax(column_padding - window->WindowPadding.x, 0.0f);
         window->DC.ColumnsOffset.x = ImMax(column_padding - window->WindowPadding.x, 0.0f);
-        window->DrawList->ChannelsSetCurrent(1);
+        columns->Splitter.SetCurrentChannel(window->DrawList, 1);
         columns->Current = 0;
         columns->Current = 0;
         columns->LineMinY = columns->LineMaxY;
         columns->LineMinY = columns->LineMaxY;
     }
     }
@@ -7581,7 +7581,7 @@ void ImGui::EndColumns()
     if (columns->Count > 1)
     if (columns->Count > 1)
     {
     {
         PopClipRect();
         PopClipRect();
-        window->DrawList->ChannelsMerge();
+        columns->Splitter.Merge(window->DrawList);
     }
     }
 
 
     const ImGuiColumnsFlags flags = columns->Flags;
     const ImGuiColumnsFlags flags = columns->Flags;