Open Shelf…

Implementing an ‘About’ page

I was asked just now to explain how the ‘About’ page in ATV Loader works, and since it’s actually really simple, I thought I’d share it here.

It actually uses BRDocumentController, which can display any of the following components:

  • Title header, with or without an icon
  • Scrollable text (actually a BRParagraphTextControl)
  • A button, with a target & action

You can create your About.txt file in TextEdit in plain text mode (or your favourite plain-text editor), but be sure to save it using UTF-16 format. That last bit is important, because that’s what BRParagraphTextControl expects by default, although you can provide a different encoding by calling -setDocumentPath:encoding: instead of -setDocumentPath: as I do in the following example. I prefer UTF-16 though, since that means it’s fully localizable (you’ll never need to worry that under a different locale you’ll need a different encoding, at run time).

To use BRDocumentController, you call your choice of the header, document, and button setup methods, and finally call -doLayout to arrange your chosen items prior to display. This last is also important — without that, everything will be positioned at the lower-left, on top of one another. Any setup functions you don’t call will not create that object, so, as in the example below, not calling -setButtonTitle:action:target: will result in no button being created or displayed.

Here’s the code I use in ATV Loader, tweaked slightly to inline a separate method:


- (BRLayerController *) _showAbout
{
    // 'About' file path
    NSBundle * bundle = [NSBundle bundleForClass: [self class]];
    NSString * path = [bundle pathForResource: @"About" ofType: @"txt"];
    if ( path == nil )
        return ( nil );

    BRDocumentController * result = [[BRDocumentController alloc]
                                     initWithScene: [self scene]];

    // by default uses Unicode (UTF-16), which is what we used when
    // creating the file
    [result setDocumentPath: path];

    [result setHeaderTitle:
        BRLocalizedString(@"About ATVLoader", @"'About' document header")];
    [result setHeaderIcon: [self listIcon]
         horizontalOffset: [self listIconHorizontalOffset]
            kerningFactor: [self listIconKerningFactor]];

    [result doLayout];

    return ( [result autorelease] );
}

No Responses

Note that comments are displayed in reverse chronological order with topmost comments being freshest. Subscribe | Comment

Leave a Reply

You must be logged in to post a comment.