Skip to content

Commit 027a7ba

Browse files
committed
Clipper: use line size instead of cursor comparaison when range are large. (ocornut#3609, ocornut#3962 + ocornut/imgui_club#20)
1 parent a76bc52 commit 027a7ba

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

Diff for: imgui.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -2471,17 +2471,23 @@ bool ImGuiListClipper::Step()
24712471
if (ItemsHeight <= 0.0f)
24722472
{
24732473
IM_ASSERT(data->StepNo == 1);
2474+
bool affected_by_floating_point_precision = false;
24742475
if (table)
24752476
{
24762477
const float pos_y1 = table->RowPosY1; // Using RowPosY1 instead of StartPosY to handle clipper straddling the frozen row
24772478
const float pos_y2 = table->RowPosY2; // Using RowPosY2 instead of CursorPos.y to take account of tallest cell.
24782479
ItemsHeight = pos_y2 - pos_y1;
24792480
window->DC.CursorPos.y = pos_y2;
2481+
affected_by_floating_point_precision = ImIsFloatAboveGuaranteedIntegerPrecision(pos_y1) || ImIsFloatAboveGuaranteedIntegerPrecision(pos_y2);
24802482
}
24812483
else
24822484
{
24832485
ItemsHeight = (window->DC.CursorPos.y - StartPosY) / (float)(DisplayEnd - DisplayStart);
2486+
affected_by_floating_point_precision = ImIsFloatAboveGuaranteedIntegerPrecision(StartPosY) || ImIsFloatAboveGuaranteedIntegerPrecision(window->DC.CursorPos.y);
24842487
}
2488+
if (affected_by_floating_point_precision)
2489+
ItemsHeight = window->DC.PrevLineSize.y + g.Style.ItemSpacing.y; // FIXME: Technically wouldn't allow multi-line entries.
2490+
24852491
IM_ASSERT(ItemsHeight > 0.0f && "Unable to calculate item height! First item hasn't moved the cursor vertically!");
24862492
calc_clipping = true; // If item height had to be calculated, calculate clipping afterwards.
24872493
}

Diff for: imgui.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Index of this file:
6464
// Version
6565
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens)
6666
#define IMGUI_VERSION "1.86 WIP"
67-
#define IMGUI_VERSION_NUM 18515
67+
#define IMGUI_VERSION_NUM 18516
6868
#define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx))
6969
#define IMGUI_HAS_TABLE
7070

Diff for: imgui_internal.h

+1
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ static inline float ImDot(const ImVec2& a, const ImVec2& b)
448448
static inline ImVec2 ImRotate(const ImVec2& v, float cos_a, float sin_a) { return ImVec2(v.x * cos_a - v.y * sin_a, v.x * sin_a + v.y * cos_a); }
449449
static inline float ImLinearSweep(float current, float target, float speed) { if (current < target) return ImMin(current + speed, target); if (current > target) return ImMax(current - speed, target); return current; }
450450
static inline ImVec2 ImMul(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x * rhs.x, lhs.y * rhs.y); }
451+
static inline bool ImIsFloatAboveGuaranteedIntegerPrecision(float f) { return f <= -16777216 || f >= 16777216; }
451452
IM_MSVC_RUNTIME_CHECKS_RESTORE
452453

453454
// Helpers: Geometry

0 commit comments

Comments
 (0)