diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp index fd7800cbbc..0452556ab0 100644 --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -487,8 +487,8 @@ public: break; case WID_AP_AIRPORT_LIST: { - int num_clicked = this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget, 0, this->line_height); - if (num_clicked == INT_MAX) break; + int32_t num_clicked = this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget, 0, this->line_height); + if (num_clicked == INT32_MAX) break; const AirportSpec *as = AirportClass::Get(_selected_airport_class)->GetSpec(num_clicked); if (as->IsAvailable()) this->SelectOtherAirport(num_clicked); break; diff --git a/src/departures_gui.cpp b/src/departures_gui.cpp index 0bb25ff396..03fc6711c6 100644 --- a/src/departures_gui.cpp +++ b/src/departures_gui.cpp @@ -403,9 +403,9 @@ public: /* We need to find the departure corresponding to where the user clicked. */ uint32_t id_v = (pt.y - this->GetWidget(WID_DB_LIST)->pos_y) / this->entry_height; - if (id_v >= this->vscroll->GetCapacity()) return; // click out of bounds + if (id_v >= (uint32_t)this->vscroll->GetCapacity()) return; // click out of bounds - id_v += this->vscroll->GetPosition(); + id_v += (uint32_t)this->vscroll->GetPosition(); if (id_v >= (this->departures->size() + this->arrivals->size())) return; // click out of list bound @@ -769,7 +769,7 @@ void DeparturesWindow::DrawDeparturesListItems(const Rect &r) const } } - if (i < this->vscroll->GetPosition()) { + if (i < (uint32_t)this->vscroll->GetPosition()) { continue; } diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index a74496c007..6739f7963a 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -461,10 +461,10 @@ struct DepotWindow : Window { } ym = (y - matrix_widget->pos_y) % this->resize.step_height; - int row = this->vscroll->GetScrolledRowFromWidget(y, this, WID_D_MATRIX); + int32_t row = this->vscroll->GetScrolledRowFromWidget(y, this, WID_D_MATRIX); uint pos = (row * this->num_columns) + xt; - if (row == INT_MAX || this->vehicle_list.size() + this->wagon_list.size() <= pos) { + if (row == INT32_MAX || this->vehicle_list.size() + this->wagon_list.size() <= pos) { /* Clicking on 'line' / 'block' without a vehicle */ if (this->type == VEH_TRAIN) { /* End the dragging */ diff --git a/src/framerate_gui.cpp b/src/framerate_gui.cpp index 249d6b953c..a0a134d3c2 100644 --- a/src/framerate_gui.cpp +++ b/src/framerate_gui.cpp @@ -596,7 +596,7 @@ struct FramerateWindow : Window { void DrawElementTimesColumn(const Rect &r, StringID heading_str, const CachedDecimal *values) const { const Scrollbar *sb = this->GetScrollbar(WID_FRW_SCROLLBAR); - uint16_t skip = sb->GetPosition(); + int32_t skip = sb->GetPosition(); int drawable = this->num_displayed; int y = r.top; DrawString(r.left, r.right, y, heading_str, TC_FROMSTRING, SA_CENTER, true); @@ -618,7 +618,7 @@ struct FramerateWindow : Window { void DrawElementAllocationsColumn(const Rect &r) const { const Scrollbar *sb = this->GetScrollbar(WID_FRW_SCROLLBAR); - uint16_t skip = sb->GetPosition(); + int32_t skip = sb->GetPosition(); int drawable = this->num_displayed; int y = r.top; DrawString(r.left, r.right, y, STR_FRAMERATE_MEMORYUSE, TC_FROMSTRING, SA_CENTER, true); @@ -652,7 +652,7 @@ struct FramerateWindow : Window { case WID_FRW_TIMES_NAMES: { /* Render a column of titles for performance element names */ const Scrollbar *sb = this->GetScrollbar(WID_FRW_SCROLLBAR); - uint16_t skip = sb->GetPosition(); + int32_t skip = sb->GetPosition(); int drawable = this->num_displayed; int y = r.top + GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal; // first line contains headings in the value columns for (PerformanceElement e : DISPLAY_ORDER_PFE) { @@ -696,8 +696,8 @@ struct FramerateWindow : Window { case WID_FRW_TIMES_AVERAGE: { /* Open time graph windows when clicking detail measurement lines */ const Scrollbar *sb = this->GetScrollbar(WID_FRW_SCROLLBAR); - int line = sb->GetScrolledRowFromWidget(pt.y, this, widget, WidgetDimensions::scaled.vsep_normal + GetCharacterHeight(FS_NORMAL)); - if (line != INT_MAX) { + int32_t line = sb->GetScrolledRowFromWidget(pt.y, this, widget, WidgetDimensions::scaled.vsep_normal + GetCharacterHeight(FS_NORMAL)); + if (line != INT32_MAX) { line++; /* Find the visible line that was clicked */ for (PerformanceElement e : DISPLAY_ORDER_PFE) { diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index 27ccc6c55e..0f80fbc9b4 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -887,7 +887,7 @@ struct ExcludingCargoBaseGraphWindow : BaseGraphWindow { } case WID_ECBG_MATRIX: { - uint row = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_ECBG_MATRIX); + int32_t row = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_ECBG_MATRIX); if (row >= this->vscroll->GetCount()) return; for (const CargoSpec *cs : _sorted_standard_cargo_specs) { @@ -2027,7 +2027,7 @@ struct StationCargoGraphWindow final : BaseGraphWindow { } case WID_SCG_MATRIX: { - uint row = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SCG_MATRIX); + int32_t row = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SCG_MATRIX); if (row >= this->vscroll->GetCount()) return; for (const CargoSpec *cs : _sorted_standard_cargo_specs) { diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp index 5d88815fed..60a7e50615 100644 --- a/src/newgrf_debug_gui.cpp +++ b/src/newgrf_debug_gui.cpp @@ -339,7 +339,7 @@ struct NewGRFInspectWindow : Window { Scrollbar *vscroll; - int first_variable_line_index = 0; + int32_t first_variable_line_index = 0; bool redraw_panel = false; bool redraw_scrollbar = false; @@ -569,7 +569,7 @@ struct NewGRFInspectWindow : Window { const void *base = nih->GetInstance(index); const void *base_spec = nih->GetSpec(index); - uint i = 0; + int32_t i = 0; auto guard = scope_guard([&]() { if (this->log_console) { @@ -577,12 +577,12 @@ struct NewGRFInspectWindow : Window { DEBUG(misc, 0, "*** END ***"); } - uint count = std::min(UINT16_MAX, i); + const int32_t count = i; if (vscroll->GetCount() != count) { /* Not nice and certainly a hack, but it beats duplicating * this whole function just to count the actual number of * elements. Especially because they need to be redrawn. */ - uint position = this->vscroll->GetPosition(); + const int32_t position = this->vscroll->GetPosition(); const_cast(this)->vscroll->SetCount(count); const_cast(this)->redraw_scrollbar = true; if (position != this->vscroll->GetPosition()) { @@ -921,8 +921,8 @@ struct NewGRFInspectWindow : Window { case WID_NGRFI_MAINPANEL: { /* Get the line, make sure it's within the boundaries. */ - int line = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NGRFI_MAINPANEL, WidgetDimensions::scaled.framerect.top); - if (line == INT_MAX) return; + int32_t line = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NGRFI_MAINPANEL, WidgetDimensions::scaled.framerect.top); + if (line == INT32_MAX) return; if (this->sprite_dump) { if (_ctrl_pressed) { diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index b8002110b2..3fc817d91d 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -151,12 +151,12 @@ static void ShowNewGRFInfo(const GRFConfig *c, const Rect &r, bool show_params) struct NewGRFParametersWindow : public Window { static GRFParameterInfo dummy_parameter_info; ///< Dummy info in case a newgrf didn't provide info about some parameter. GRFConfig *grf_config; ///< Set the parameters of this GRFConfig. - uint clicked_button; ///< The row in which a button was clicked or UINT_MAX. + int32_t clicked_button; ///< The row in which a button was clicked or INT_MAX when none is selected. bool clicked_increase; ///< True if the increase button was clicked, false for the decrease button. bool clicked_dropdown; ///< Whether the dropdown is open. bool closing_dropdown; ///< True, if the dropdown list is currently closing. GUITimer timeout; ///< How long before we unpress the last-pressed button? - uint clicked_row; ///< The selected parameter + int32_t clicked_row; ///< The selected parameter, or INT_MAX when none is selected. int line_height; ///< Height of a row in the matrix widget. Scrollbar *vscroll; bool action14present; ///< True if action14 information is present. @@ -164,10 +164,10 @@ struct NewGRFParametersWindow : public Window { NewGRFParametersWindow(WindowDesc *desc, bool is_baseset, GRFConfig *c, bool editable) : Window(desc), grf_config(c), - clicked_button(UINT_MAX), + clicked_button(INT32_MAX), clicked_dropdown(false), closing_dropdown(false), - clicked_row(UINT_MAX), + clicked_row(INT32_MAX), editable(editable) { this->action14present = (c->num_valid_params != c->param.size() || !c->param_info.empty()); @@ -294,7 +294,7 @@ struct NewGRFParametersWindow : public Window { int button_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2; int text_y_offset = (this->line_height - GetCharacterHeight(FS_NORMAL)) / 2; - for (uint i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < this->vscroll->GetCount(); i++) { + for (int32_t i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < this->vscroll->GetCount(); i++) { GRFParameterInfo &par_info = this->GetParameterInfo(i); uint32_t current_value = par_info.GetValue(this->grf_config); bool selected = (i == this->clicked_row); @@ -366,7 +366,7 @@ struct NewGRFParametersWindow : public Window { case WID_NP_BACKGROUND: { if (!this->editable) break; - uint num = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NP_BACKGROUND); + int32_t num = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NP_BACKGROUND); if (num >= this->vscroll->GetCount()) break; if (this->clicked_row != num) { @@ -505,8 +505,8 @@ struct NewGRFParametersWindow : public Window { } this->vscroll->SetCount(this->action14present ? this->grf_config->num_valid_params : this->grf_config->num_params); - if (this->clicked_row != UINT_MAX && this->clicked_row >= this->vscroll->GetCount()) { - this->clicked_row = UINT_MAX; + if (this->clicked_row != INT32_MAX && this->clicked_row >= this->vscroll->GetCount()) { + this->clicked_row = INT32_MAX; CloseChildWindows(WC_QUERY_STRING); } } @@ -514,7 +514,7 @@ struct NewGRFParametersWindow : public Window { void OnRealtimeTick(uint delta_ms) override { if (timeout.Elapsed(delta_ms)) { - this->clicked_button = UINT_MAX; + this->clicked_button = INT32_MAX; this->SetDirty(); } } diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 2cacd39067..54cab1f523 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -1577,8 +1577,8 @@ private: */ VehicleOrderID GetOrderFromPt(int y) { - int sel = this->vscroll->GetScrolledRowFromWidget(y, this, WID_O_ORDER_LIST, WidgetDimensions::scaled.framerect.top); - if (sel == INT_MAX) return INVALID_VEH_ORDER_ID; + int32_t sel = this->vscroll->GetScrolledRowFromWidget(y, this, WID_O_ORDER_LIST, WidgetDimensions::scaled.framerect.top); + if (sel == INT32_MAX) return INVALID_VEH_ORDER_ID; /* One past the orders is the 'End of Orders' line. */ assert(IsInsideBS(sel, 0, vehicle->GetNumOrders() + 1)); return sel; diff --git a/src/programmable_signals_gui.cpp b/src/programmable_signals_gui.cpp index f89d3767cc..96f3b62f26 100644 --- a/src/programmable_signals_gui.cpp +++ b/src/programmable_signals_gui.cpp @@ -699,13 +699,13 @@ private: int GetInstructionFromPt(int y) { NWidgetBase *nwid = this->GetWidget(PROGRAM_WIDGET_INSTRUCTION_LIST); - int sel = (y - nwid->pos_y - WidgetDimensions::scaled.framerect.top) / nwid->resize_y; // Selected line + int32_t sel = (y - nwid->pos_y - WidgetDimensions::scaled.framerect.top) / nwid->resize_y; // Selected line - if ((uint)sel >= this->vscroll->GetCapacity()) return -1; + if (sel >= this->vscroll->GetCapacity()) return -1; sel += this->vscroll->GetPosition(); - return (sel <= int(this->instructions.size()) && sel >= 0) ? sel : -1; + return (sel <= (int32_t)(this->instructions.size()) && sel >= 0) ? sel : -1; } void RebuildInstructionList() diff --git a/src/schdispatch_gui.cpp b/src/schdispatch_gui.cpp index 1309cad045..2ce992b3ef 100644 --- a/src/schdispatch_gui.cpp +++ b/src/schdispatch_gui.cpp @@ -912,7 +912,7 @@ struct SchdispatchWindow : GeneralVehicleWindow { int xm = x % this->resize.step_width; if (xt >= this->num_columns) return { nullptr, false }; - uint row = y / this->resize.step_height; + int32_t row = y / this->resize.step_height; if (row >= this->vscroll->GetCapacity()) return { nullptr, false }; uint pos = ((row + this->vscroll->GetPosition()) * this->num_columns) + xt; diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index b67ae282cb..02cd9c5da1 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -3066,8 +3066,8 @@ struct GameSettingsWindow : Window { if (widget != WID_GS_OPTIONSPANEL) return; - uint btn = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GS_OPTIONSPANEL, WidgetDimensions::scaled.framerect.top); - if (btn == INT_MAX || (int)btn < this->warn_lines) return; + int32_t btn = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GS_OPTIONSPANEL, WidgetDimensions::scaled.framerect.top); + if (btn == INT32_MAX || btn < this->warn_lines) return; btn -= this->warn_lines; uint cur_row = 0; diff --git a/src/station_gui.cpp b/src/station_gui.cpp index ae598e439d..1ea5ebf110 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -2587,7 +2587,7 @@ struct SelectStationWindow : Window { tr.top += this->resize.step_height; } - for (uint i = std::max(1, this->vscroll->GetPosition()); i <= _stations_nearby_list.size(); ++i, tr.top += this->resize.step_height) { + for (int32_t i = std::max(1, this->vscroll->GetPosition()); (size_t)i <= _stations_nearby_list.size(); ++i, tr.top += this->resize.step_height) { /* Don't draw anything if it extends past the end of the window. */ if (i - this->vscroll->GetPosition() >= this->vscroll->GetCapacity()) break; diff --git a/src/story_gui.cpp b/src/story_gui.cpp index 318d1266db..f68a855378 100644 --- a/src/story_gui.cpp +++ b/src/story_gui.cpp @@ -498,12 +498,12 @@ protected: * Get the total height of the content displayed in this window. * @return the height in pixels */ - uint GetContentHeight() + int32_t GetContentHeight() { this->EnsureStoryPageElementLayout(); /* The largest bottom coordinate of any element is the height of the content */ - uint max_y = std::accumulate(this->layout_cache.begin(), this->layout_cache.end(), 0, [](uint max_y, const LayoutCacheElement &ce) -> uint { return std::max(max_y, ce.bounds.bottom); }); + int32_t max_y = std::accumulate(this->layout_cache.begin(), this->layout_cache.end(), 0, [](int32_t max_y, const LayoutCacheElement &ce) -> int32_t { return std::max(max_y, ce.bounds.bottom); }); return max_y; } diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp index 403cae1ff7..e65675332e 100644 --- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -431,8 +431,8 @@ struct TimetableWindow : GeneralVehicleWindow { int GetOrderFromTimetableWndPt(int y, [[maybe_unused]] const Vehicle *v) { - int sel = this->vscroll->GetScrolledRowFromWidget(y, this, WID_VT_TIMETABLE_PANEL, WidgetDimensions::scaled.framerect.top); - if (sel == INT_MAX) return INVALID_ORDER; + int32_t sel = this->vscroll->GetScrolledRowFromWidget(y, this, WID_VT_TIMETABLE_PANEL, WidgetDimensions::scaled.framerect.top); + if (sel == INT32_MAX) return INVALID_ORDER; assert(IsInsideBS(sel, 0, v->GetNumOrders() * 2)); return sel; } diff --git a/src/tracerestrict_gui.cpp b/src/tracerestrict_gui.cpp index b98e0b79e9..47fe204ddd 100644 --- a/src/tracerestrict_gui.cpp +++ b/src/tracerestrict_gui.cpp @@ -2862,9 +2862,9 @@ private: int GetItemIndexFromPt(int y) { NWidgetBase *nwid = this->GetWidget(TR_WIDGET_INSTRUCTION_LIST); - int sel = (y - nwid->pos_y - WidgetDimensions::scaled.framerect.top) / nwid->resize_y; // Selected line + int32_t sel = (y - nwid->pos_y - WidgetDimensions::scaled.framerect.top) / nwid->resize_y; // Selected line - if ((uint)sel >= this->vscroll->GetCapacity()) return -1; + if (sel >= this->vscroll->GetCapacity()) return -1; sel += this->vscroll->GetPosition(); diff --git a/src/widget.cpp b/src/widget.cpp index 52f0188aa3..e6c359d46e 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -2330,13 +2330,13 @@ void NWidgetViewport::UpdateViewportCoordinates(Window *w) * @param widget Widget number of the widget clicked in. * @param padding Amount of empty space between the widget edge and the top of the first row. Default value is \c 0. * @param line_height Height of a single row. A negative value means using the vertical resize step of the widget. - * @return Row number clicked at. If clicked at a wrong position, #INT_MAX is returned. + * @return Row number clicked at. If clicked at a wrong position, #Scrollbar::npos is returned. */ -int Scrollbar::GetScrolledRowFromWidget(int clickpos, const Window * const w, WidgetID widget, int padding, int line_height) const +Scrollbar::size_type Scrollbar::GetScrolledRowFromWidget(int clickpos, const Window * const w, WidgetID widget, int padding, int line_height) const { - uint pos = w->GetRowFromWidget(clickpos, widget, padding, line_height); + int pos = w->GetRowFromWidget(clickpos, widget, padding, line_height); if (pos != INT_MAX) pos += this->GetPosition(); - return (pos >= this->GetCount()) ? INT_MAX : pos; + return (pos < 0 || pos >= this->GetCount()) ? Scrollbar::npos : pos; } /** diff --git a/src/widget_type.h b/src/widget_type.h index 5cd4abf104..36ec01b881 100644 --- a/src/widget_type.h +++ b/src/widget_type.h @@ -707,12 +707,16 @@ public: * Scrollbar data structure */ class Scrollbar { +public: + using size_type = int32_t; + static constexpr size_type max_size_type = std::numeric_limits::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 */ @@ -730,7 +734,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; } @@ -739,7 +743,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; } @@ -748,7 +752,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; } @@ -758,7 +762,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()); } @@ -780,7 +784,7 @@ public: { assert(stepsize > 0); - this->stepsize = ClampTo(stepsize); + this->stepsize = ClampTo(stepsize); } /** @@ -790,9 +794,9 @@ public: */ void SetCount(size_t num) { - assert(num <= MAX_UVALUE(uint16_t)); + assert(num < Scrollbar::max_size_type); - this->count = ClampTo(num); + this->count = ClampTo(num); /* Ensure position is within bounds */ this->SetPosition(this->pos); } @@ -804,9 +808,9 @@ public: */ void SetCapacity(size_t capacity) { - assert(capacity <= MAX_UVALUE(uint16_t)); + assert(capacity < Scrollbar::max_size_type); - this->cap = ClampTo(capacity); + this->cap = ClampTo(capacity); /* Ensure position is within bounds */ this->SetPosition(this->pos); } @@ -818,9 +822,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; } @@ -849,7 +853,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 */ @@ -860,7 +864,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. @@ -870,7 +874,7 @@ public: template 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(this->GetCapacity(), this->GetCount() - this->GetPosition())); return std::make_pair(first, last); @@ -889,9 +893,9 @@ public: template 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);