How to implement scrolling

The code in this section demonstrates horizontal and vertical scrolling using CTextView::ScrollDisplayL(). This function can be used to scroll text horizontally (left or right and to the start or end of a line), and vertically (page or line up, page or line down). Note that scrolling down means that the text appears to move upwards, scrolling left means it appears to move rightwards.

Scroll left

The following code scrolls the display left by 40 pixels, causing the text to move right. If no horizontal scroll jump value is set, the scroll jump will be the default value of 20 pixels.

iTextView->SetHorizontalScrollJump(40); // scroll jump is 40 pixels
iTextView->ScrollDisplayL(TCursorPosition::EFLeft); // scroll left

Scroll down

The following example scrolls the display downwards.

  • Use ScrollDisplayL() until the end of the document is reached, at which point ScrollDisplayL() returns zero.

  • Here, the scroll includes blank space (the second argument is CTextLayout::EFAllowScrollingBlankSpace), so scrolling continues until the last line in the document reaches the top of the display. By default, blank space is not scrolled, in which case the scroll ends when the last line appears at the bottom of the display.

TInt pixelsScrolled;
do pixelsScrolled=iTextView->ScrollDisplayL
    (TCursorPosition::EFLineDown,CTextView::EFAllowScrollingBlankSpace);
while (pixelsScrolled);

Note