![]() |
![]()
| ![]() |
![]()
NAMEPrima::Widget::Link - routines for interactive links DESCRIPTIONThe class can be used in widgets that need to feature links, i e a highlighted rectangle, usually of text. When the user moves mouse or click on a link, depending on the link type, various action can be executed. A "tooltip" link type can display a hint with (rich) text, and a "hyperlink" link can open a browser or pod viewer. The programmer can also customize these actions. SYNOPSISuse Prima qw(Label Application); my $main_window = Prima::MainWindow->new( size => [400, 100] ); $main_window->insert( Label => centered => 1, text => \ "L<tip://$0/ttt|tip>, L<pod://Prima/|podviewer>, L<http://google.com/|browser>, L<id|custom>", onLink => sub { print "$_[2]\n" }, ); run Prima; =pod =head1 ttt this is a tooltip =for podview <img src="data:base64"> R0lGODdhFgAVAIAAAAAAAP///ywAAAAAFgAVAIAAAAD///8CLIyPqcutsKALQKI6qT11R69lWDJm 5omm6jqBjucycEx+bVOSNNf1+/NjCREFADs= Link typesLink types can be set with the url syntax. There are four recognized link types that behave differently. TooltipsThese are not really links in the strict sense, as clicking on them doesn't cause any action, however when the user hovers mouse over a tooltip, the module loads the pod content from the url, and displays it as a hint. The idea behind this feature is to collect all tootip cards in a pod section, and referencing them in a text like in the example code in SYNOPSIS above. Syntax: "L<tip://FILEPATH_OR_MODULE/SECTION>" or "L<tip://FILEPATH_OR_MODULE>" where "FILEPATH_OR_MODULE" can refer either to a file (path with slashes/backslashes) or a perl module (with "::"s ). Tooltip text, when selected, is underscored by a dashed line, vs all other link types that draw solid line. Pod sectionsThese links both diplay a pod section preview, like the toolkip, but also open a pod viewer with the referred section when clicked on. Syntax: "L<pod://FILEPATH_OR_MODULE/SECTION>" or "L<pod://FILEPATH_OR_MODULE>" where "FILEPATH_OR_MODULE" can refer either to a file (path with slashes/backslashes) or a perl module (with "::"s ). HyperlinksLinks with schemes "ftp://", "http://", and "https://" open a browser when clicked on. Custom linksAll other urls, not matched by either scheme above, are expected to be handled programmatically. The preview, if any is handled by the "LinkPreview" event, and click by "Link" event. See Events below. UsageSince "Prima::Widget::Link" is not a widget by itself but a collection of routines in a class, an object of such class should be instantiated programmatically and attached to a widget that needs to display links, an owner widget. The owner needs to call mouse and paint methods from inside its "on_mousedown" etc relevant events. The owner might also want to overload link events, see below. MarkupPrima::Drawable::Markup understands the "L<..|..>" command, which is, unlike perlpod, is formatted with its arguments reversed, to stay consistent with the other markup commands (i e it is "L<http://google.com|search>", not "L<search|http://google.com>" . The simple way to incorporate rich text in both widget and link handler is to use "Prima::Drawable::Markup" to handle the markup parsing, and use the resulting object from the same class both for widget drawing and for the link reactions. One just needs to add " markup =" $markup_object > to " Prima::Widget::Link-"new() >. APIProperties
Methods
EventsAll events are send to the owner, not to the link object itself, however the "SELF" parameter is sent and contains the link object.
AUTHORDmitry Karasik, <dmitry@karasik.eu.org>. SEE ALSOPrima, Prima::Drawable::Markup, Prima::Label, Prima::PodView
|