Home of the Squeezebox™ & Transporter® network music players.
Results 1 to 7 of 7
  1. #1
    Senior Member Philip Meyer's Avatar
    Join Date
    Apr 2005
    Location
    UK
    Posts
    5,596

    Formatting text to a series of lines to fit a display

    I have a plugin that gets text from a file and allows the text to be read using up/down arrows.

    However, it currently scrolls long lines. I'd like to read the content and reformat it into lines that fit the display width (i.e. taking into account the font size, etc).

    I think I'd need to strip out carriage returns/line feeds so I have one long line of text. I'd then split the text up into an array of lines where each line nicely fits to the width. If the font changes, I'd recalculate the lines?

    I assume there are some functions to do this already? Where should I be looking?

  2. #2
    Former Squeezebox Guy andyg's Avatar
    Join Date
    Jan 2006
    Location
    Pittsburgh, PA
    Posts
    7,396

    Formatting text to a series of lines to fit adisplay

    On Jun 19, 2008, at 5:32 PM, Phil Meyer wrote:

    > I have a plugin that gets text from a file and allows the text to be
    > read using up/down arrows.
    >
    > However, it currently scrolls long lines. I'd like to read the
    > content and reformat it into lines that fit the display width (i.e.
    > taking into account the font size, etc).
    >
    > I think I'd need to strip out carriage returns/line feeds so I have
    > one long line of text. I'd then split the text up into an array of
    > lines where each line nicely fits to the width. If the font
    > changes, I'd recalculate the lines?
    >
    > I assume there are some functions to do this already? Where should
    > I be looking?


    There's already a function to change a long line into a series of
    lines that all fit on the display, see
    Slim::Buttons::XMLBrowser::_breakItemIntoLines. There's some XML-
    specific stuff in there but it should be obvious what you need to do.

    We should probably make this a standard Slim::Utils::Misc function.



  3. #3
    Senior Member
    Join Date
    Apr 2005
    Posts
    8,410

    Formatting text to a series of lines to fit adisplay

    See Slim::Buttons::XMLBrowser, better still create a hash for the data and
    push into xmlbrowser with it as the data - see what infobrowser plugins do
    for this.

    ----- Original Message -----
    From: "Phil Meyer" <slim (AT) hergest (DOT) demon.co.uk>
    To: <developers (AT) lists (DOT) slimdevices.com>
    Sent: Thursday, June 19, 2008 10:32 PM
    Subject: [Developers] Formatting text to a series of lines to fit a display


    >I have a plugin that gets text from a file and allows the text to be read
    >using up/down arrows.
    >
    > However, it currently scrolls long lines. I'd like to read the content
    > and reformat it into lines that fit the display width (i.e. taking into
    > account the font size, etc).
    >
    > I think I'd need to strip out carriage returns/line feeds so I have one
    > long line of text. I'd then split the text up into an array of lines
    > where each line nicely fits to the width. If the font changes, I'd
    > recalculate the lines?
    >
    > I assume there are some functions to do this already? Where should I be
    > looking?
    >

  4. #4
    Senior Member Philip Meyer's Avatar
    Join Date
    Apr 2005
    Location
    UK
    Posts
    5,596

    Formatting text to a series of lines to fit adisplay

    Great - thanks guys.

    Phil

  5. #5
    Senior Member Philip Meyer's Avatar
    Join Date
    Apr 2005
    Location
    UK
    Posts
    5,596

    Formatting text to a series of lines to fit adisplay

    >better still create a hash for the data and
    >push into xmlbrowser with it as the data - see what infobrowser plugins do
    >for this.
    >

    Hmm, I've been staring at infobrowser plugins and xmlbrowser code for a bit and I can't figure it out.

    Am I along the right lines here? I'm getting confused over arrays, lists and references; I think I'm close, but I'm not passing @items in the correct form?

    sub DisplayFile
    {
    my ($client, $file) = @_;

    my $lines = ReadFile($client, $file);

    my %params = (
    modeName => 'SongFileViewer',
    url => sub {
    my ( $client, $gotFeed, $params ) = @_;

    my %item = ( name => 'Content', item => $lines, wrap => 1, );
    my @items = ( %item );

    my %opml = (
    type => 'opml',
    items => @items,
    );
    my %p = (client => $client);
    $gotFeed->(\%opml, \%p);
    },
    title => getDisplayName(),
    );

    Slim::Buttons::Common:ushMode($client, 'xmlbrowser', \%params);
    }

  6. #6
    Senior Member
    Join Date
    Apr 2005
    Posts
    8,410

    Formatting text to a series of lines to fitadisplay

    Sorry Phil, looks like I sent you off looking in slightly the wrong place...

    Its not too easy to just call this from by pushing into xmlbrowser, however
    you can do the following:

    my $item = {
    title => 'the title',
    description => 'very long piece of text that will be displayed on
    multiple lines'
    };

    Slim::Buttons::XMLBrowser::displayItemDescription( $client, $item);



    ----- Original Message -----
    From: "Phil Meyer" <slim (AT) hergest (DOT) demon.co.uk>
    To: <developers (AT) lists (DOT) slimdevices.com>
    Sent: Friday, June 20, 2008 2:10 AM
    Subject: Re: [Developers] Formatting text to a series of lines to fit
    adisplay


    > >better still create a hash for the data and
    >>push into xmlbrowser with it as the data - see what infobrowser plugins do
    >>for this.
    >>

    > Hmm, I've been staring at infobrowser plugins and xmlbrowser code for a
    > bit and I can't figure it out.



  7. #7
    Senior Member Philip Meyer's Avatar
    Join Date
    Apr 2005
    Location
    UK
    Posts
    5,596

    Formatting text to a series of lines to fitadisplay

    >however you can do the following:
    >
    > my $item = {
    > title => 'the title',
    > description => 'very long piece of text that will be displayed on
    >multiple lines'
    > };
    >
    > Slim::Buttons::XMLBrowser::displayItemDescription( $client, $item);
    >

    Ah, that's easier for me to comprehend. Thanks for the help. It's basically working now, although I am joining long lines together with a space separator. I've tried to join with a carriage return or line feed to force new paragraphs to start on new lines, but I guess it doesn't understand that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •