diff --git a/src/widget_type.h b/src/widget_type.h index 0e8f940c60..e697b3ea5d 100644 --- a/src/widget_type.h +++ b/src/widget_type.h @@ -721,9 +721,8 @@ public: assert(num <= MAX_UVALUE(uint16)); this->count = ClampTo(num); - num -= this->cap; - if (num < 0) num = 0; - if (num < this->pos) this->pos = num; + /* Ensure position is within bounds */ + this->SetPosition(this->pos); } /** @@ -736,7 +735,8 @@ public: assert(capacity <= MAX_UVALUE(uint16)); this->cap = ClampTo(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);