Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
ImGuiListClipper Struct Reference

#include <src/imgui/imgui.h>

Public Member Functions

IMGUI_API ImGuiListClipper ()
 
IMGUI_API ~ImGuiListClipper ()
 
IMGUI_API void Begin (int items_count, float items_height=-1.0f)
 
IMGUI_API void End ()
 
IMGUI_API bool Step ()
 
 ImGuiListClipper (int items_count, float items_height=-1.0f)
 

Public Attributes

int DisplayStart
 
int DisplayEnd
 
int ItemsCount
 
int StepNo
 
int ItemsFrozen
 
float ItemsHeight
 
float StartPosY
 

Detailed Description

Constructor & Destructor Documentation

◆ ImGuiListClipper() [1/2]

ImGuiListClipper::ImGuiListClipper ( )
2273{
2274 memset(this, 0, sizeof(*this));
2275 ItemsCount = -1;
2276}
int ItemsCount
Definition imgui.h:2143

◆ ~ImGuiListClipper()

ImGuiListClipper::~ImGuiListClipper ( )
2279{
2280 IM_ASSERT(ItemsCount == -1 && "Forgot to call End(), or to Step() until false?");
2281}
#define IM_ASSERT(_EXPR)
Definition imgui.h:81

References IM_ASSERT.

◆ ImGuiListClipper() [2/2]

ImGuiListClipper::ImGuiListClipper ( int  items_count,
float  items_height = -1.0f 
)
inline
2159{ memset(this, 0, sizeof(*this)); ItemsCount = -1; Begin(items_count, items_height); } // [removed in 1.79]
IMGUI_API void Begin(int items_count, float items_height=-1.0f)
Definition imgui.cpp:2286

Member Function Documentation

◆ Begin()

void ImGuiListClipper::Begin ( int  items_count,
float  items_height = -1.0f 
)
2287{
2288 ImGuiContext& g = *GImGui;
2289 ImGuiWindow* window = g.CurrentWindow;
2290
2291 if (ImGuiTable* table = g.CurrentTable)
2292 if (table->IsInsideRow)
2293 ImGui::TableEndRow(table);
2294
2295 StartPosY = window->DC.CursorPos.y;
2296 ItemsHeight = items_height;
2297 ItemsCount = items_count;
2298 ItemsFrozen = 0;
2299 StepNo = 0;
2300 DisplayStart = -1;
2301 DisplayEnd = 0;
2302}
ImGuiContext * GImGui
Definition imgui.cpp:960
ImVec2 CursorPos
Definition imgui_internal.h:1754
IMGUI_API void TableEndRow(ImGuiTable *table)
Definition imgui_tables.cpp:1715
Definition imgui_internal.h:1351
ImGuiWindow * CurrentWindow
Definition imgui_internal.h:1380
ImGuiTable * CurrentTable
Definition imgui_internal.h:1519
float ItemsHeight
Definition imgui.h:2146
int StepNo
Definition imgui.h:2144
int DisplayStart
Definition imgui.h:2139
int ItemsFrozen
Definition imgui.h:2145
int DisplayEnd
Definition imgui.h:2140
float StartPosY
Definition imgui.h:2147
Definition imgui_internal.h:2096
Definition imgui_internal.h:1807
ImGuiWindowTempData DC
Definition imgui_internal.h:1861
float y
Definition imgui.h:246

References ImGuiContext::CurrentTable, ImGuiContext::CurrentWindow, ImGuiWindowTempData::CursorPos, ImGuiWindow::DC, GImGui, ImGui::TableEndRow(), and ImVec2::y.

Referenced by ImGui::DebugNodeDrawList(), ExampleAppLog::Draw(), ShowDemoWindowColumns(), ShowDemoWindowTables(), and ShowExampleAppLongText().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ End()

void ImGuiListClipper::End ( )
2305{
2306 if (ItemsCount < 0) // Already ended
2307 return;
2308
2309 // In theory here we should assert that ImGui::GetCursorPosY() == StartPosY + DisplayEnd * ItemsHeight, but it feels saner to just seek at the end and not assert/crash the user.
2310 if (ItemsCount < INT_MAX && DisplayStart >= 0)
2312 ItemsCount = -1;
2313 StepNo = 3;
2314}
static void SetCursorPosYAndSetupForPrevLine(float pos_y, float line_height)
Definition imgui.cpp:2247

References SetCursorPosYAndSetupForPrevLine().

Referenced by ExampleAppLog::Draw().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Step()

bool ImGuiListClipper::Step ( )
2317{
2318 ImGuiContext& g = *GImGui;
2319 ImGuiWindow* window = g.CurrentWindow;
2320
2321 ImGuiTable* table = g.CurrentTable;
2322 if (table && table->IsInsideRow)
2323 ImGui::TableEndRow(table);
2324
2325 // No items
2327 {
2328 End();
2329 return false;
2330 }
2331
2332 // Step 0: Let you process the first element (regardless of it being visible or not, so we can measure the element height)
2333 if (StepNo == 0)
2334 {
2335 // While we are in frozen row state, keep displaying items one by one, unclipped
2336 // FIXME: Could be stored as a table-agnostic state.
2337 if (table != NULL && !table->IsUnfrozenRows)
2338 {
2340 DisplayEnd = ItemsFrozen + 1;
2341 ItemsFrozen++;
2342 return true;
2343 }
2344
2345 StartPosY = window->DC.CursorPos.y;
2346 if (ItemsHeight <= 0.0f)
2347 {
2348 // Submit the first item so we can measure its height (generally it is 0..1)
2350 DisplayEnd = ItemsFrozen + 1;
2351 StepNo = 1;
2352 return true;
2353 }
2354
2355 // Already has item height (given by user in Begin): skip to calculating step
2357 StepNo = 2;
2358 }
2359
2360 // Step 1: the clipper infer height from first element
2361 if (StepNo == 1)
2362 {
2363 IM_ASSERT(ItemsHeight <= 0.0f);
2364 if (table)
2365 {
2366 const float pos_y1 = table->RowPosY1; // Using this instead of StartPosY to handle clipper straddling the frozen row
2367 const float pos_y2 = table->RowPosY2; // Using this instead of CursorPos.y to take account of tallest cell.
2368 ItemsHeight = pos_y2 - pos_y1;
2369 window->DC.CursorPos.y = pos_y2;
2370 }
2371 else
2372 {
2373 ItemsHeight = window->DC.CursorPos.y - StartPosY;
2374 }
2375 IM_ASSERT(ItemsHeight > 0.0f && "Unable to calculate item height! First item hasn't moved the cursor vertically!");
2376 StepNo = 2;
2377 }
2378
2379 // Reached end of list
2380 if (DisplayEnd >= ItemsCount)
2381 {
2382 End();
2383 return false;
2384 }
2385
2386 // Step 2: calculate the actual range of elements to display, and position the cursor before the first element
2387 if (StepNo == 2)
2388 {
2389 IM_ASSERT(ItemsHeight > 0.0f);
2390
2391 int already_submitted = DisplayEnd;
2393 DisplayStart += already_submitted;
2394 DisplayEnd += already_submitted;
2395
2396 // Seek cursor
2397 if (DisplayStart > already_submitted)
2399
2400 StepNo = 3;
2401 return true;
2402 }
2403
2404 // Step 3: the clipper validate that we have reached the expected Y position (corresponding to element DisplayEnd),
2405 // Advance the cursor to the end of the list and then returns 'false' to end the loop.
2406 if (StepNo == 3)
2407 {
2408 // Seek cursor
2409 if (ItemsCount < INT_MAX)
2411 ItemsCount = -1;
2412 return false;
2413 }
2414
2415 IM_ASSERT(0);
2416 return false;
2417}
static bool GetSkipItemForListClipping()
Definition imgui.cpp:2198
IMGUI_API void CalcListClipping(int items_count, float items_height, int *out_items_display_start, int *out_items_display_end)
Definition imgui.cpp:2207
IMGUI_API void End()
Definition imgui.cpp:2304
bool IsUnfrozenRows
Definition imgui_internal.h:2194
bool IsInsideRow
Definition imgui_internal.h:2184
float RowPosY2
Definition imgui_internal.h:2117
float RowPosY1
Definition imgui_internal.h:2116

References ImGui::CalcListClipping(), ImGuiContext::CurrentTable, ImGuiContext::CurrentWindow, ImGuiWindowTempData::CursorPos, ImGuiWindow::DC, GetSkipItemForListClipping(), GImGui, IM_ASSERT, ImGuiTable::IsInsideRow, ImGuiTable::IsUnfrozenRows, ImGuiTable::RowPosY1, ImGuiTable::RowPosY2, SetCursorPosYAndSetupForPrevLine(), ImGui::TableEndRow(), and ImVec2::y.

Referenced by ImGui::DebugNodeDrawList(), ExampleAppLog::Draw(), ShowDemoWindowColumns(), ShowDemoWindowTables(), and ShowExampleAppLongText().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ DisplayEnd

◆ DisplayStart

◆ ItemsCount

int ImGuiListClipper::ItemsCount

◆ ItemsFrozen

int ImGuiListClipper::ItemsFrozen

◆ ItemsHeight

float ImGuiListClipper::ItemsHeight

◆ StartPosY

float ImGuiListClipper::StartPosY

◆ StepNo

int ImGuiListClipper::StepNo

The documentation for this struct was generated from the following files: