views:

801

answers:

3

I have a single line CEikLabel in my application that needs to scroll text.

The simple solution that comes to mind (but possibly naive) would be something like..

[begin pseduo code]

 on timer.fire {
  set slightly shifted text in label
  redraw label
 }
 start timer

[end pseudo code]

Using a CPeriodic class as the timer and label.DrawDeferred() on each update.

Do you think this is the best way, it may be rather inefficient redrawing the label two or three times a second.. but is there any other way?

Thanks :)

+1  A: 

I don't know whether there is another way to do it and can't say whether the approach you have in your mind will be inefficient. However, you may want to take a look at this thread which discusses pretty much the same question as yours and also briefly mentions somewhat the same solution as the one you have conceived of.

ayaz
the discussion in this thread does not actually apply to inserting text into CEikLabel objects
adam
@Adam: In particular, yes, it does not. But it applies to 'ticker' texts in general, irrespective of where you want the text to appear.
ayaz
+1  A: 

I've seen the timer based solution used for scrolling item names in listboxes.

A couple of things to watch out for are that it could flicker a bit while scrolling and that you need to make sure the text you put on the label is not too long, otherwise it will automatically clip the string and add an elipsis (...)

Use TextUtils::ClipToFit to get a string that fits on the label and remove the elipsis it adds before putting the text on the label (search for KTextUtilClipEndChar in your clipped string). You will need to work out how many characters to skip at the beginning of the string before passing it to the clip function.

Mark Cheeseborough
A: 

I have done it like this

TTimeIntervalMicroSeconds32 scrolltime(70000);
iPeriodicScroll = CPeriodic::NewL(CActive::EPriorityIdle);
iPeriodicScroll->Start(scrolltime, scrolltime, TCallBack(CVisTagContainerView::ScrollTextL, this));

and then in the repeated function

CEikLabel *label = iContainer->Label();
const TDesC16 *temp = label->Text();
if (temp->Length() <= 0) { 
    if (iTextState != ETextIdle) { return; }
    DownloadMoreTextL();
    return;
}
TPtrC16 right = temp->Right(temp->Length()-1);
label->SetTextL(right);
label->DrawDeferred();

So text moves right to left, and when all gone, the label is repopulated by DownloadMoreTextL

adam