summaryrefslogtreecommitdiff
path: root/src/widget_type.h
diff options
context:
space:
mode:
authorPeter Nelson <peter1138@openttd.org>2021-05-07 12:36:08 +0100
committerPeterN <peter@fuzzle.org>2021-05-08 09:52:54 +0100
commit52b16237ad863ce30746ac7efc46a9ece7e3bdd2 (patch)
tree4cd5c83fb53da9c89219c7d0eba636d04b5d3634 /src/widget_type.h
parent8321ef0061fa898cfb215e57c67aebd7411475e1 (diff)
downloadopenttd-52b16237ad863ce30746ac7efc46a9ece7e3bdd2.tar.xz
Codechange: Don't update window contents if scrollbar position has not moved.
Diffstat (limited to 'src/widget_type.h')
-rw-r--r--src/widget_type.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/widget_type.h b/src/widget_type.h
index 200711356..c50a263d6 100644
--- a/src/widget_type.h
+++ b/src/widget_type.h
@@ -737,12 +737,15 @@ public:
/**
* Sets the position of the first visible element
* @param position the position of the element
+ * @return true iff the position has changed
*/
- void SetPosition(int position)
+ bool SetPosition(int position)
{
assert(position >= 0);
assert(this->count <= this->cap ? (position == 0) : (position + this->cap <= this->count));
+ uint16 old_pos = this->pos;
this->pos = position;
+ return this->pos != old_pos;
}
/**
@@ -750,16 +753,17 @@ public:
* If the position would be too low or high it will be clamped appropriately
* @param difference the amount of change requested
* @param unit The stepping unit of \a difference
+ * @return true iff the position has changed
*/
- void UpdatePosition(int difference, ScrollbarStepping unit = SS_SMALL)
+ bool UpdatePosition(int difference, ScrollbarStepping unit = SS_SMALL)
{
- if (difference == 0) return;
+ if (difference == 0) return false;
switch (unit) {
case SS_SMALL: difference *= this->stepsize; break;
case SS_BIG: difference *= this->cap; break;
default: break;
}
- this->SetPosition(Clamp(this->pos + difference, 0, std::max(this->count - this->cap, 0)));
+ return this->SetPosition(Clamp(this->pos + difference, 0, std::max(this->count - this->cap, 0)));
}
/**