Codechange: use int32_t instead of uint16_t for scroll bar position/size/capacity
This commit is contained in:
@@ -678,12 +678,16 @@ public:
|
||||
* Scrollbar data structure
|
||||
*/
|
||||
class Scrollbar {
|
||||
public:
|
||||
using size_type = int32_t;
|
||||
static constexpr size_type max_size_type = std::numeric_limits<size_type>::max();
|
||||
static constexpr size_type npos = max_size_type;
|
||||
private:
|
||||
const bool is_vertical; ///< Scrollbar has vertical orientation.
|
||||
uint16_t count; ///< Number of elements in the list.
|
||||
uint16_t cap; ///< Number of visible elements of the scroll bar.
|
||||
uint16_t pos; ///< Index of first visible item of the list.
|
||||
uint16_t stepsize; ///< Distance to scroll, when pressing the buttons or using the wheel.
|
||||
size_type count; ///< Number of elements in the list.
|
||||
size_type cap; ///< Number of visible elements of the scroll bar.
|
||||
size_type pos; ///< Index of first visible item of the list.
|
||||
size_type stepsize; ///< Distance to scroll, when pressing the buttons or using the wheel.
|
||||
|
||||
public:
|
||||
/** Stepping sizes when scrolling */
|
||||
@@ -701,7 +705,7 @@ public:
|
||||
* Gets the number of elements in the list
|
||||
* @return the number of elements
|
||||
*/
|
||||
inline uint16_t GetCount() const
|
||||
inline size_type GetCount() const
|
||||
{
|
||||
return this->count;
|
||||
}
|
||||
@@ -710,7 +714,7 @@ public:
|
||||
* Gets the number of visible elements of the scrollbar
|
||||
* @return the number of visible elements
|
||||
*/
|
||||
inline uint16_t GetCapacity() const
|
||||
inline size_type GetCapacity() const
|
||||
{
|
||||
return this->cap;
|
||||
}
|
||||
@@ -719,7 +723,7 @@ public:
|
||||
* Gets the position of the first visible element in the list
|
||||
* @return the position of the element
|
||||
*/
|
||||
inline uint16_t GetPosition() const
|
||||
inline size_type GetPosition() const
|
||||
{
|
||||
return this->pos;
|
||||
}
|
||||
@@ -729,7 +733,7 @@ public:
|
||||
* @param item to check
|
||||
* @return true iff the item is visible
|
||||
*/
|
||||
inline bool IsVisible(uint16_t item) const
|
||||
inline bool IsVisible(size_type item) const
|
||||
{
|
||||
return IsInsideBS(item, this->GetPosition(), this->GetCapacity());
|
||||
}
|
||||
@@ -751,7 +755,7 @@ public:
|
||||
{
|
||||
assert(stepsize > 0);
|
||||
|
||||
this->stepsize = ClampTo<uint16_t>(stepsize);
|
||||
this->stepsize = ClampTo<size_type>(stepsize);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -761,9 +765,9 @@ public:
|
||||
*/
|
||||
void SetCount(size_t num)
|
||||
{
|
||||
assert(num <= MAX_UVALUE(uint16_t));
|
||||
assert(num < Scrollbar::max_size_type);
|
||||
|
||||
this->count = ClampTo<uint16_t>(num);
|
||||
this->count = ClampTo<size_type>(num);
|
||||
/* Ensure position is within bounds */
|
||||
this->SetPosition(this->pos);
|
||||
}
|
||||
@@ -775,9 +779,9 @@ public:
|
||||
*/
|
||||
void SetCapacity(size_t capacity)
|
||||
{
|
||||
assert(capacity <= MAX_UVALUE(uint16_t));
|
||||
assert(capacity < Scrollbar::max_size_type);
|
||||
|
||||
this->cap = ClampTo<uint16_t>(capacity);
|
||||
this->cap = ClampTo<size_type>(capacity);
|
||||
/* Ensure position is within bounds */
|
||||
this->SetPosition(this->pos);
|
||||
}
|
||||
@@ -789,9 +793,9 @@ public:
|
||||
* @param position the position of the element
|
||||
* @return true iff the position has changed
|
||||
*/
|
||||
bool SetPosition(int position)
|
||||
bool SetPosition(size_type position)
|
||||
{
|
||||
uint16_t old_pos = this->pos;
|
||||
size_type old_pos = this->pos;
|
||||
this->pos = Clamp(position, 0, std::max(this->count - this->cap, 0));
|
||||
return this->pos != old_pos;
|
||||
}
|
||||
@@ -820,7 +824,7 @@ public:
|
||||
* the window depending on where in the list it was.
|
||||
* @param position the position to scroll towards.
|
||||
*/
|
||||
void ScrollTowards(int position)
|
||||
void ScrollTowards(size_type position)
|
||||
{
|
||||
if (position < this->GetPosition()) {
|
||||
/* scroll up to the item */
|
||||
@@ -831,7 +835,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
int GetScrolledRowFromWidget(int clickpos, const Window * const w, WidgetID widget, int padding = 0, int line_height = -1) const;
|
||||
size_type GetScrolledRowFromWidget(int clickpos, const Window * const w, WidgetID widget, int padding = 0, int line_height = -1) const;
|
||||
|
||||
/**
|
||||
* Get a pair of iterators for the range of visible elements in a container.
|
||||
@@ -841,7 +845,7 @@ public:
|
||||
template <typename Tcontainer>
|
||||
auto GetVisibleRangeIterators(Tcontainer &container) const
|
||||
{
|
||||
assert(this->GetCount() == container.size()); // Scrollbar and container size must match.
|
||||
assert((size_t)this->GetCount() == container.size()); // Scrollbar and container size must match.
|
||||
auto first = std::next(std::begin(container), this->GetPosition());
|
||||
auto last = std::next(first, std::min<size_t>(this->GetCapacity(), this->GetCount() - this->GetPosition()));
|
||||
return std::make_pair(first, last);
|
||||
@@ -860,9 +864,9 @@ public:
|
||||
template <typename Tcontainer>
|
||||
typename Tcontainer::iterator GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window * const w, WidgetID widget, int padding = 0, int line_height = -1) const
|
||||
{
|
||||
assert(this->GetCount() == container.size()); // Scrollbar and container size must match.
|
||||
int row = this->GetScrolledRowFromWidget(clickpos, w, widget, padding, line_height);
|
||||
if (row == INT_MAX) return std::end(container);
|
||||
assert((size_t)this->GetCount() == container.size()); // Scrollbar and container size must match.
|
||||
size_type row = this->GetScrolledRowFromWidget(clickpos, w, widget, padding, line_height);
|
||||
if (row == Scrollbar::npos) return std::end(container);
|
||||
|
||||
typename Tcontainer::iterator it = std::begin(container);
|
||||
std::advance(it, row);
|
||||
|
Reference in New Issue
Block a user