ScrollingLabel - a funny label widget with scrolling capabilities

ScrollingLabel widget demo ScrollingLabel is a dynamic label which scrolls from all sides when the parent widget is not large enough. This widget can be used when you need to build very compact interfaces and display long strings of information.

Example of use :

You just need to create a standard widget just like a GtkLabel

<?php
# ....
$text = 'The quick brown fox jumps over the lazy dog.';
$vbox = new GtkVbox();
$vbox->pack_start(new ScrollingLabel( $text ), false, false); #(1)
$vbox->show_all();
# ....
Gtk::main();
?>

Code source

See the attached sources.

Highlights

  • widget tree: GtkFixed / GtkEventBox / GtkLabel,
  • GtkEventBox is used to catch button click,
  • GtkFixed is a special composite widget that allows widget placement and moves,
  • so we move the event box and inside label just to follow the event box (its parent widget),
  • you can adjust class members as needed ; change source or override class
  • click on the event box resets the position
  • an application can handle a few such scrolling widget when not under heavy load ; take care not to use too many instances of this widget

Enhancement

  • we should track the configure event from GtkEventBox and set timeout as needed. With the code as it stands currently, a timeout function is running even when not needed
AttachmentSize
scrolling-label.php_.txt3.03 KB