Prima::...et::Link(3)
β¨ NAME β¨
Prima::Widget::Link β routines for interactive links. Thatβs the whole name vibe, bestie π
πΈ DESCRIPTION πΈ
So hereβs the tea: this class is for widgets that need to show links β like, actual highlighted rectangles, usually with a line of text in them. When the user moves the mouse over a link or clicks it, different actions can fire depending on the link type. A "tooltip" link can display a hint with (rich) text, and a "hyperlink" link can open a browser or a pod viewer. And if youβre the programmer, you can customize these actions too. Periodt π
Also hi, this page is the Prima::...et::Link(3) situation from User Contributed Perl Documentation β weβre folding that in right here at the top instead of making you read a stale header line π«Ά
π¦ SYNOPSIS π¦
use 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 types π
Link types can be set with the url syntax. Four recognized link types behave differently, and theyβre giving very distinct main character energy π
π Tooltips
These are not links in the strict sense, because clicking on them doesnβt cause any action. But when the user hovers the mouse over a tooltip, the module loads the pod content from the URL and displays it as a hint. Obsessed, honestly.
The idea behind this feature is to collect all tooltip cards in a pod section and reference them in the 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).
The tooltip text, when selected, is underscored by a dashed line, vs all other link types that use a solid line. Cute little differentiation moment π
π Pod sections
These links display a pod section preview like the tooltip but also open a pod viewer with the referred section when clicked on. So theyβre like tooltipβs extroverted sibling.
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).
π Hyperlinks
Links with schemes ftp://, http://, and https:// open a browser when clicked on. Classic internet behavior, no notes π₯
π§‘ Custom links
All other URLs, not matched by either scheme above, are expected to be handled programmatically. The preview, if any, should be handled by the LinkPreview event, and the mouse click by the Link event.
See Events below.
π Usage π
Since 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 an owner widget that needs to display links.
The owner widget needs to call the mouse and paint methods from inside its on_mousedown etc relevant events. The owner widget class might also want to overload link events β see below how. Itβs giving βyouβre the main character, but the link object is your sidekickβ energy β¨
π Markup π
Prima::Drawable::Markup understands the L<..|..> command, which β 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 the 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() >. Yes bestie, thatβs the exact weird little incantation from the page β we keep the facts, we just add sparkle π«
π API π
β Properties
rectanglesβ Contains an array of rectangles in arbitrary coordinates that could be used to map screen coordinates to a URL. Filled automatically.referencesβ An array of URLs.
π οΈ Methods
add_positions_from_blocks LINK_ID, BLOCKS, %DEFAULTSβ Used when the link object is not bound to any markup object but recalculation of the visual rectangle that the link occupies is needed due to change in formatting, f ex after a change in widget size, font size, etc.%DEFAULTSis sent internally totb::block_walkwhich may need eventual default parameters. ScansBLOCKSand add monotonically increasingLINK_IDto new link rectangles. Return newLINK_ID.clear_positionsβ Clears the content ofrectangles.id2rectangles IDβ Returns rectangles mapped to a link ID. There can be more than 1 rectangle bound to a single link ID since link text could be f ex wrapped.open_podview URLβ Opens a pod viewer with the URL.open_browser URLβ Opens a web browser with the URL.reset_positions_markup BLOCKS, %DEFAULTSβ Used when the link object is bound to a markup object and recalculation of the visual rectangle that the link occupies is needed due to change in formatting, f ex after a change in widget size, font size, etc.%DEFAULTSis sent internally totb::block_walkwhich may need eventual default parameters.
π« Events
All events are sent to the owner, not to the link object itself, however, the SELF parameter which contains the link object is always the first parameter. Important bestie detail π«Ά
Link SELF, URL, BUTTON, MODβ Sent to the owner, if any, from within theon_mousedownevent to indicate that the link was pressed on.LinkPreview SELF, URL_REFβ Sent to the owner, if any, from within theon_mousemoveevent. The owner may want to fillURL_REFwith (rich) text that will be displayed as a link preview.LinkAdjustRect SELF, RECT_REFβ Since the owner may implement a scrollable view or any other view that has a coordinate system that is not necessarily consistent with the rectangles stored in the link object, this event will be called when a link rectangle needs to be mapped to the owner coordinates.
π AUTHOR π
Dmitry Karasik, <dmitry@karasik.eu.org>.
πΈ SEE ALSO πΈ
Prima, Prima::Drawable::Markup, Prima::Label, Prima::Drawable::Pod
okay thatβs the whole page bestie π
β this was Prima::...et::Link(3) from the perl v5.42.0 docs, dated 2024-08-20. go slay your links! πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Prima 1.74000-bp160.1.13 Β· AGPL-3.0-only AND BSD-2-Clause
- opensuse-leap 16.0: perl-Prima 1.74000-bp160.1.13 Β· AGPL-3.0-only AND BSD-2-Clause
- opensuse-leap 16.0: perl-Prima 1.74000-bp160.1.13 Β· AGPL-3.0-only AND BSD-2-Clause
- opensuse-leap 16.0: perl-Prima 1.74000-bp160.1.13 Β· AGPL-3.0-only AND BSD-2-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms