Codechange: Use SetPosition() to clamp after changing count/capacity.

This commit is contained in:
2023-05-07 10:44:50 +01:00
committed by PeterN
parent 6202eae9d5
commit 878c5d8d85

View File

@@ -721,9 +721,8 @@ public:
assert(num <= MAX_UVALUE(uint16)); assert(num <= MAX_UVALUE(uint16));
this->count = ClampTo<uint16_t>(num); this->count = ClampTo<uint16_t>(num);
num -= this->cap; /* Ensure position is within bounds */
if (num < 0) num = 0; this->SetPosition(this->pos);
if (num < this->pos) this->pos = num;
} }
/** /**
@@ -736,7 +735,8 @@ public:
assert(capacity <= MAX_UVALUE(uint16)); assert(capacity <= MAX_UVALUE(uint16));
this->cap = ClampTo<uint16_t>(capacity); this->cap = ClampTo<uint16_t>(capacity);
if (this->cap + this->pos > this->count) this->pos = std::max(0, this->count - this->cap); /* Ensure position is within bounds */
this->SetPosition(this->pos);
} }
void SetCapacityFromWidget(Window *w, int widget, int padding = 0); void SetCapacityFromWidget(Window *w, int widget, int padding = 0);