MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / UpdateListPositionOnKeyPress

Method UpdateListPositionOnKeyPress

src/widget.cpp:2474–2517  ·  view source on GitHub ↗

* Update the given list position as if it were on this scroll bar when the given keycode was pressed. * This does not update the actual position of this scroll bar, that is left to the caller. It does, * however use the capacity and count of the scroll bar for the bounds and amount to scroll. * * When the count is 0 or the return is ES_NOT_HANDLED, then the position is not updated. * With WKC

Source from the content-addressed store, hash-verified

2472 * @return ES_NOT_HANDLED when another key than the 6 specific keys was pressed, otherwise ES_HANDLED.
2473 */
2474EventState Scrollbar::UpdateListPositionOnKeyPress(int &list_position, uint16_t keycode) const
2475{
2476 int new_pos = list_position;
2477 switch (keycode) {
2478 case WKC_UP:
2479 /* scroll up by one */
2480 new_pos--;
2481 break;
2482
2483 case WKC_DOWN:
2484 /* scroll down by one */
2485 new_pos++;
2486 break;
2487
2488 case WKC_PAGEUP:
2489 /* scroll up a page */
2490 new_pos -= this->GetCapacity();
2491 break;
2492
2493 case WKC_PAGEDOWN:
2494 /* scroll down a page */
2495 new_pos += this->GetCapacity();
2496 break;
2497
2498 case WKC_HOME:
2499 /* jump to beginning */
2500 new_pos = 0;
2501 break;
2502
2503 case WKC_END:
2504 /* jump to end */
2505 new_pos = this->GetCount() - 1;
2506 break;
2507
2508 default:
2509 return ES_NOT_HANDLED;
2510 }
2511
2512 /* If there are no elements, there is nothing to scroll/update. */
2513 if (this->GetCount() != 0) {
2514 list_position = Clamp(new_pos, 0, this->GetCount() - 1);
2515 }
2516 return ES_HANDLED;
2517}
2518
2519
2520/**

Callers 3

OnKeyPressMethod · 0.80
OnKeyPressMethod · 0.80
OnKeyPressMethod · 0.80

Calls 3

GetCapacityMethod · 0.95
GetCountMethod · 0.95
ClampFunction · 0.85

Tested by

no test coverage detected