NAME

Gtk2::Ex::TickerView -- scrolling ticker display widget

SYNOPSIS

use Gtk2::Ex::TickerView;
my $ticker = Gtk2::Ex::TickerView->new (model => $model,
                                        ...);
my $renderer = Gtk2::CellRendererText->new;
$ticker->pack_start ($renderer, 0);
$ticker->set_attributes ($renderer, text => 0);  # column

WIDGET HIERARCHY

Gtk2::Ex::TickerView is a subclass of Gtk2::DrawingArea, but that might change so it's recommended you only rely on Gtk2::Widget.

Gtk2::Widget
  Gtk2::DrawingArea
    Gtk2::Ex::TickerView

The interfaces implemented are:

Gtk2::CellLayout

Or rather the set of methods in Gtk2::CellLayout are implemented, since as of Gtk2-Perl version 1.161 it's not yet an actual GInterface.

DESCRIPTION

A Gtk2::Ex::TickerView widget displays items from a Gtk2::TreeModel scrolling horizontally across the window, like a news bar or stock ticker.

+----------------------------------------------------------+
| st item  * The second item  * The third item   * The fou |
+----------------------------------------------------------+
    <---- scrolling

Items are drawn using one or more Gtk2::CellRenderer objects set into the view as per the Gtk2::CellLayout interface. For scrolling text you would use Gtk2::CellRendererText.

If two or more renderers are set then they're drawn one after the other for each item (ie. row of the model). For example you could have a Gtk2::CellRendererPixbuf to draw an icon then a Gtk2::CellRendererText to draw some text and they scroll across together. (The icon could use the model's data, or be just a fixed blob to go before every item.)

The display and scrolling direction follow the widget text direction (the set_direction method, per Gtk2::Widget). For ltr mode item 0 starts at the left of the window and items scroll to the left. For rtl item 0 starts at the right of the window and items scroll to the right.

+----------------------------------------------------------+
| m five  * item four  * item three  * item two  * item on |
+----------------------------------------------------------+
                    right to left mode, scrolling ----->

Any text or drawing direction within the cell renderers is a matter for them. For Gtk2::CellRendererText Pango recognises right-to-left scripts such as Arabic based on the utf-8 characters and shouldn't need any special setups.

Currently only a list style model is expected and only the topmost level of the model is drawn, so for instance a Gtk2::ListStore suits. Perhaps in the future something will be done to descend into and draw child rows too.

The whole Gtk model/view/layout/renderer/attributes stuff as provided here is ridiculously complicated. Its power comes when showing a big updating list or wanting customized drawing, but the amount of code to get started with something on the screen is not nice. Have a look at "Tree and List Widget Overview" in the Gtk reference manual if you haven't already, then examples/simple.pl in the Gtk2::Ex::TickerView sources is more or less the minimum to actually display something.

FUNCTIONS

Gtk2::Ex::TickerView->new (key => value, ...)

Create and return a Gtk2::Ex::TickerView widget. Optional key/value pairs can be given to set initial properties as per Glib::Object->new.

$ticker->scroll_pixels ($n)

Scroll the ticker contents across by $n pixels. Postive $n moves in the normal scrolled direction or a negative value goes backwards. $n doesn't have to be an integer, the display position is maintained as a floating point value.

$ticker->scroll_to_start ()

Scroll the ticker contents back to the start, ie. the first row in the model.

PROPERTIES

model (object implementing Gtk2::TreeModel, default undef)

This is any object implementing the Gtk2::TreeModel interface, for example a Gtk2::ListStore. It supplies the data to be displayed. Until this is set the ticker is blank.

run (boolean, default 1)

Whether to run the ticker, ie. to scroll it across the screen under a timer. If false then the ticker just draws the items at its current position, without moving (except by the programatic scroll calls above, or user dragging with mouse button 1).

speed (floating point pixels per second, default 25)

The speed the items scroll across, in pixels per second.

frame-rate (floating point frames per second, default 4)

The number of times each second the ticker moves and redraws. (Each move is speed divided by frame-rate many pixels.)

fixed-height-mode (boolean, default false)

If true then assume all rows in the model have the same height. This means the ticker can ask its renderers about just one row from the model, instead of going through all of them. If the model is big this makes size negotiation with the ticker's container parent much faster.

The text direction which gives the display order and scrolling is not a property but instead accessed with the usual widget get_direction and set_direction methods (see Gtk2::Widget).

The visible property in the cell renderer(s) is recognised and a renderer that's not visible is skipped and takes no space. Each visible can be set globally in the renderer to suppress it entirely, or controlled with the attributes mechanism (or data setup function) to suppress just selected items from the model.

OTHER NOTES

Mouse button 1 is setup for the user to drag the display back and forwards. This is good to see something that's just gone off the edge, or to skip past boring bits. Perhaps in the future the button used will be customizable.

Some scrolling optimizations are attempted. In the current implementation when the window is unobscured a scroll is done by a "CopyArea" and a draw of the balance at the end. To avoid hammering the server any further copying is deferred until hearing back from the server that the last completed (a NoExpose event normally). All scroll steps are also spun through an idle handler (at roughly GDK_PRIORITY_REDRAW priority), with the aim of collapsing say multiple MotionNotify events from a user drag. The effect of all this is probably only noticable if your frame-rate is a bit too high or the server is lagged by other operations.

SEE ALSO

Gtk2::CellLayout, Gtk2::TreeModel, Gtk2::CellRenderer