Clipper: use line size instead of cursor comparaison when range are large. (#3609, #3962 + https://github.com/ocornut/imgui_club/issues/20)

This commit is contained in:
ocornut
2021-12-06 16:20:53 +01:00
parent a76bc52da5
commit 027a7ba3eb
3 changed files with 8 additions and 1 deletions

View File

@ -2471,17 +2471,23 @@ bool ImGuiListClipper::Step()
if (ItemsHeight <= 0.0f)
{
IM_ASSERT(data->StepNo == 1);
bool affected_by_floating_point_precision = false;
if (table)
{
const float pos_y1 = table->RowPosY1; // Using RowPosY1 instead of StartPosY to handle clipper straddling the frozen row
const float pos_y2 = table->RowPosY2; // Using RowPosY2 instead of CursorPos.y to take account of tallest cell.
ItemsHeight = pos_y2 - pos_y1;
window->DC.CursorPos.y = pos_y2;
affected_by_floating_point_precision = ImIsFloatAboveGuaranteedIntegerPrecision(pos_y1) || ImIsFloatAboveGuaranteedIntegerPrecision(pos_y2);
}
else
{
ItemsHeight = (window->DC.CursorPos.y - StartPosY) / (float)(DisplayEnd - DisplayStart);
affected_by_floating_point_precision = ImIsFloatAboveGuaranteedIntegerPrecision(StartPosY) || ImIsFloatAboveGuaranteedIntegerPrecision(window->DC.CursorPos.y);
}
if (affected_by_floating_point_precision)
ItemsHeight = window->DC.PrevLineSize.y + g.Style.ItemSpacing.y; // FIXME: Technically wouldn't allow multi-line entries.
IM_ASSERT(ItemsHeight > 0.0f && "Unable to calculate item height! First item hasn't moved the cursor vertically!");
calc_clipping = true; // If item height had to be calculated, calculate clipping afterwards.
}