# Scrollbar Class Reference

Scrollbar data structure. More...

`#include <window_gui.h>`

## Public Member Functions
| Scrollbar (bool is_vertical)
FORCEINLINE uint16 | GetCount () const
| Gets the number of elements in the list.
FORCEINLINE uint16 | GetCapacity () const
| Gets the number of visible elements of the scrollbar.
FORCEINLINE uint16 | GetPosition () const
| Gets the position of the first visible element in the list.
FORCEINLINE bool | IsVisible (uint16 item) const
| Checks whether given current item is visible in the list.
void | SetCount (int num)
| Sets the number of elements in the list.
void | SetCapacity (int capacity)
| Set the capacity of visible elements.
void | SetCapacityFromWidget (Window *w, int widget, int padding=0)
| Set capacity of visible elements from the size and resize properties of a widget.
void | SetPosition (int position)
| Sets the position of the first visible element.
void | UpdatePosition (int difference)
| Updates the position of the first visible element by the given amount.
void | ScrollTowards (int position)
| Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown either at the bottom or top of the window depending on where in the list it was.
## Private Attributes
const bool | is_vertical
| Scrollbar has vertical orientation.
uint16 | count
| Number of elements in the list.
uint16 | cap
| Number of visible elements of the scroll bar.
uint16 | pos
| Index of first visible item of the list.

## Detailed Description

Scrollbar data structure.

Definition at line 175 of file window_gui.h.

## Member Function Documentation

FORCEINLINE uint16 Scrollbar::GetCapacity | ( |  | ) | const`[inline]`

Gets the number of visible elements of the scrollbar.

Returns:
  the number of visible elements

Definition at line 200 of file window_gui.h.

References cap.

Referenced by DispatchMouseWheelEvent(), BaseVehicleListWindow::DrawVehicleListItems(), StationViewWindow::DrawWaitingCargo(), VehicleDetailsWindow::DrawWidget(), RefitWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), SubsidyListWindow::DrawWidget(), SelectStationWindow< T >::DrawWidget(), GameSettingsWindow::DrawWidget(), MessageHistoryWindow::DrawWidget(), NewGRFAddWindow::DrawWidget(), NetworkGameWindow::DrawWidget(), SaveLoadWindow::DrawWidget(), IndustryDirectoryWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), VehicleGroupWindow::DrawWidget(), BuildVehicleWindow::DrawWidget(), OrdersWindow::GetOrderFromPt(), HandleScrollbarHittest(), IsVisible(), VehicleListWindow::OnClick(), TownDirectoryWindow::OnClick(), SubsidyListWindow::OnClick(), SignListWindow::OnClick(), BuildRailStationWindow::OnClick(), NetworkLobbyWindow::OnClick(), NetworkGameWindow::OnClick(), NetworkContentListWindow::OnClick(), IndustryDirectoryWindow::OnClick(), VehicleGroupWindow::OnClick(), BuildBridgeWindow::OnClick(), VehicleGroupWindow::OnDragDrop(), NewGRFWindow::OnInvalidateData(), NewGRFAddWindow::OnKeyPress(), NetworkGameWindow::OnKeyPress(), NetworkContentListWindow::OnKeyPress(), BuildRailWaypointWindow::OnPaint(), DepotWindow::OnPaint(), AIDebugWindow::OnPaint(), VehicleDetailsWindow::OnResize(), VehicleListWindow::OnResize(), RefitWindow::OnResize(), NewGRFWindow::OnResize(), NetworkLobbyWindow::OnResize(), NetworkGameWindow::OnResize(), NetworkContentListWindow::OnResize(), BuildIndustryWindow::OnResize(), VehicleGroupWindow::OnResize(), DepotWindow::OnResize(), BuildVehicleWindow::OnResize(), BuildBridgeWindow::OnResize(), AISettingsWindow::OnResize(), AIListWindow::OnResize(), ScrollbarClickPositioning(), and ScrollTowards().

FORCEINLINE uint16 Scrollbar::GetCount | ( |  | ) | const`[inline]`

Gets the number of elements in the list.

Returns:
  the number of elements

Definition at line 191 of file window_gui.h.

References count.

Referenced by DispatchMouseWheelEvent(), SignListWindow::DrawWidget(), HandleScrollbarHittest(), SignListWindow::OnClick(), NetworkStartServerWindow::OnClick(), SaveLoadWindow::OnClick(), BuildRailWaypointWindow::OnPaint(), AIDebugWindow::OnPaint(), VehicleListWindow::SetStringParameters(), and SignListWindow::SetStringParameters().

FORCEINLINE uint16 Scrollbar::GetPosition | ( |  | ) | const`[inline]`

Gets the position of the first visible element in the list.

Returns:
  the position of the element

Definition at line 209 of file window_gui.h.

References pos.

Referenced by DepotWindow::DrawVehicleInDepot(), BaseVehicleListWindow::DrawVehicleListItems(), StationViewWindow::DrawWaitingCargo(), DropdownWindow::DrawWidget(), RefitWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), TownAuthorityWindow::DrawWidget(), TimetableWindow::DrawWidget(), SubsidyListWindow::DrawWidget(), SelectStationWindow< T >::DrawWidget(), SignListWindow::DrawWidget(), GameSettingsWindow::DrawWidget(), BuildRailStationWindow::DrawWidget(), OrdersWindow::DrawWidget(), MessageHistoryWindow::DrawWidget(), NewGRFAddWindow::DrawWidget(), NetworkGameWindow::DrawWidget(), SaveLoadWindow::DrawWidget(), IndustryDirectoryWindow::DrawWidget(), BuildIndustryWindow::DrawWidget(), VehicleGroupWindow::DrawWidget(), DepotWindow::DrawWidget(), BuildVehicleWindow::DrawWidget(), BuildBridgeWindow::DrawWidget(), AIDebugWindow::DrawWidget(), AIConfigWindow::DrawWidget(), DropdownWindow::GetDropDownItem(), OrdersWindow::GetOrderFromPt(), HandleScrollbarHittest(), IsVisible(), VehicleListWindow::OnClick(), RefitWindow::OnClick(), TownDirectoryWindow::OnClick(), TownAuthorityWindow::OnClick(), SubsidyListWindow::OnClick(), SelectStationWindow< T >::OnClick(), SignListWindow::OnClick(), GameSettingsWindow::OnClick(), BuildRailWaypointWindow::OnClick(), BuildRailStationWindow::OnClick(), NewGRFWindow::OnClick(), NewGRFAddWindow::OnClick(), NetworkLobbyWindow::OnClick(), NetworkStartServerWindow::OnClick(), NetworkGameWindow::OnClick(), NetworkContentListWindow::OnClick(), SaveLoadWindow::OnClick(), IndustryDirectoryWindow::OnClick(), BuildIndustryWindow::OnClick(), VehicleGroupWindow::OnClick(), BuildVehicleWindow::OnClick(), BuildBridgeWindow::OnClick(), AIConfigWindow::OnClick(), AISettingsWindow::OnClick(), AIListWindow::OnClick(), VehicleGroupWindow::OnDragDrop(), BuildRailWaypointWindow::OnPaint(), AIDebugWindow::OnPaint(), DropdownWindow::OnTick(), and ScrollTowards().

FORCEINLINE bool Scrollbar::IsVisible | ( | uint16 | item | ) | const`[inline]`

Checks whether given current item is visible in the list.

Parameters:

  | item | to check

Returns:
  true iff the item is visible

Definition at line 219 of file window_gui.h.

References GetCapacity(), GetPosition(), and IsInsideBS().

Referenced by TimetableWindow::DrawWidget(), SignListWindow::DrawWidget(), BuildRailStationWindow::DrawWidget(), OrdersWindow::DrawWidget(), NewGRFWindow::DrawWidget(), BuildBridgeWindow::DrawWidget(), AIDebugWindow::DrawWidget(), AIConfigWindow::DrawWidget(), AISettingsWindow::DrawWidget(), and AIListWindow::DrawWidget().

void Scrollbar::ScrollTowards | ( | int | position | ) | `[inline]`

Scroll towards the given position; if the item is visible nothing happens, otherwise it will be shown either at the bottom or top of the window depending on where in the list it was.

Parameters:

  | position | the position to scroll towards.

Definition at line 284 of file window_gui.h.

References GetCapacity(), GetPosition(), and SetPosition().

Referenced by NewGRFWindow::OnClick(), AIConfigWindow::OnClick(), NewGRFAddWindow::ScrollToSelected(), NetworkContentListWindow::ScrollToSelected(), and NetworkGameWindow::ScrollToSelectedServer().

void Scrollbar::SetCapacity | ( | int | capacity | ) | `[inline]`

Set the capacity of visible elements.

Parameters:

  | capacity | the new capacity

Note:
  updates the position if needed

Definition at line 245 of file window_gui.h.

References cap, count, max(), MAX_UVALUE, and pos.

Referenced by DropdownWindow::DropdownWindow(), MessageHistoryWindow::OnResize(), VehicleGroupWindow::OnResize(), DepotWindow::OnResize(), AISettingsWindow::OnResize(), AIListWindow::OnResize(), and SetCapacityFromWidget().

void Scrollbar::SetCapacityFromWidget | ( | Window * | w,
|  | int | widget,
|  | int | padding = `0` |
| ) |  |  |

Set capacity of visible elements from the size and resize properties of a widget.

Parameters:

  | w | Window.
  | widget | Widget with size and resize properties.
  | padding | Padding to subtract from the size.

Note:
  Updates the position if needed.

Definition at line 89 of file window.cpp.

References NWidgetBase::current_x, NWidgetBase::current_y, Window::GetWidget(), is_vertical, NWidgetBase::resize_x, NWidgetBase::resize_y, and SetCapacity().

Referenced by NewGRFWindow::OnInvalidateData(), VehicleDetailsWindow::OnResize(), VehicleListWindow::OnResize(), RefitWindow::OnResize(), TownDirectoryWindow::OnResize(), TimetableWindow::OnResize(), SubsidyListWindow::OnResize(), SelectStationWindow< T >::OnResize(), StationViewWindow::OnResize(), SignListWindow::OnResize(), GameSettingsWindow::OnResize(), OrdersWindow::OnResize(), NewGRFWindow::OnResize(), NewGRFAddWindow::OnResize(), NetworkLobbyWindow::OnResize(), NetworkGameWindow::OnResize(), NetworkContentListWindow::OnResize(), SaveLoadWindow::OnResize(), IndustryDirectoryWindow::OnResize(), BuildIndustryWindow::OnResize(), VehicleGroupWindow::OnResize(), DepotWindow::OnResize(), BuildVehicleWindow::OnResize(), BuildBridgeWindow::OnResize(), and AIDebugWindow::OnResize().

void Scrollbar::SetCount | ( | int | num | ) | `[inline]`

Sets the number of elements in the list.

Parameters:

  | num | the number of elements in the list

Note:
  updates the position if needed

Definition at line 229 of file window_gui.h.

References cap, count, MAX_UVALUE, and pos.

Referenced by NetworkContentListWindow::BuildContentList(), NewGRFAddWindow::BuildGrfList(), NetworkGameWindow::BuildNetworkGameList(), IndustryDirectoryWindow::BuildSortIndustriesList(), CompanyStationsWindow::BuildStationsList(), DropdownWindow::DropdownWindow(), ReplaceVehicleWindow::GenerateLists(), GameSettingsWindow::OnClick(), BuildRailStationWindow::OnDropdownSelect(), SubsidyListWindow::OnInvalidateData(), SelectStationWindow< T >::OnInvalidateData(), SignListWindow::OnInvalidateData(), OrdersWindow::OnInvalidateData(), MessageHistoryWindow::OnInvalidateData(), NewGRFWindow::OnInvalidateData(), VehicleDetailsWindow::OnPaint(), RefitWindow::OnPaint(), TownAuthorityWindow::OnPaint(), TimetableWindow::OnPaint(), StationViewWindow::OnPaint(), NetworkLobbyWindow::OnPaint(), SaveLoadWindow::OnPaint(), VehicleGroupWindow::OnPaint(), DepotWindow::OnPaint(), BuildVehicleWindow::OnPaint(), and AIDebugWindow::OnPaint().

void Scrollbar::SetPosition | ( | int | position | ) | `[inline]`

Sets the position of the first visible element.

Parameters:

  | position | the position of the element

Definition at line 260 of file window_gui.h.

References cap, count, and pos.

Referenced by BuildRailStationWindow::OnDropdownSelect(), AIDebugWindow::OnPaint(), ScrollTowards(), and UpdatePosition().

void Scrollbar::UpdatePosition | ( | int | difference | ) | `[inline]`

Updates the position of the first visible element by the given amount.

If the position would be too low or high it will be clamped appropriately

Parameters:

  | difference | the amount of change requested

Definition at line 272 of file window_gui.h.

References cap, Clamp(), count, max(), pos, and SetPosition().

Referenced by DispatchMouseWheelEvent(), DropdownWindow::OnTick(), and ScrollbarClickPositioning().

The documentation for this class was generated from the following files:

- src/window_gui.h
- src/window.cpp