UI::Various::RichTerm::base - abstract helper class for RichTerm's UI elements
# This module should only be used by the UI::Various::RichTerm UI # element classes!
This module provides some helper functions for the UI elements of the rich console.
The documentation of this module is only intended for developers of the package itself.
All functions of the module will be included as second "base class" (in @ISA). Note that this is not a diamond pattern as this "base class" does not import anything besides Exporter.
@ISA
Exporter
a hash of decoration characters for window borders (W1 to W9 without W5), box borders (B1 to B9 without B5), check boxes (CL and CR), radio buttons (RL and RR) and normal buttons (BL and BR)
W1
W9
W5
B1
B9
B5
CL
CR
RL
RR
BL
BR
The module provides the following common (internal) methods for all UI::Various::RichTerm UI element classes:
($width, $height) = $ui_element->_size($string, $content_width);
my ($w, $h) = $self->_size($self->text, $content_width);
$string the string to be analysed $content_width preferred width of content
This method determines the width and height of a UI element.
If the UI element has it's own defined (not inherited) widht and/or height, no other calculation is made (no matter if the string will fit or not).
If no own width is defined, the text will be wrapped into lines no longer than the given preferred maximum width and the length of the longest of line is returned. If a sub-string has no word boundary to break it into chunks smaller than $content_width, $content_width is returned even though the string will not really fit when it will be displayed later.)
$content_width
If no own height is defined, the number of lines of the wrapped string is returned.
width and height of the string when it will be displayed later
$string = $ui_element->_format($prefix, $decoration_before, $effect_before, $text, $effect_after, $decoration_after, $width, $height); or $string = $ui_element->_format($prefix, $decoration_before, $effect_before, \@text, $effect_after, $decoration_after, $width, $height);
my ($w, $h) = $self->_size($self->text, $content_width); $string = $self->_format('(1) ', '', '[ ', $self->text, ' ]', '', $w, $h);
$prefix text in front of first line $decoration_before decoration before content of each line $effect_before effect before content of each line $text string to be wrapped or reference to wrapped text lines $effect_after end of effect after content of each line $decoration_after decoration after content of each line $width the width returned by _size above $height the height returned by _size above
This method formats the given text into a text box of the previously (_size) determined width and height, decorates it with some additional strings (e.g. to symbolise a button) and a prefix set by its parent. Note that the (latter) prefix is only added to the first line with text, all additional lines gets a blank prefix of the same length.
_size
Also note that the given text can either be a string which is wrapped or a reference to an array of already wrapped strings that only need the final formatting.
The decorations and prefix will cause the resulting text box to be wider than the given width, which only describes the width of the text itself. The effect is sort of a zero-width decoration (applied to the text without padding), usually an ANSI escape sequence.
And as already described under _size above, the layout will be broken if it can't fit. The display of everything is preferred over cutting of possible important parts.
the rectangular text box for the given string
UI::Various
Copyright (C) Thomas Dorner.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See LICENSE file for more details.
Thomas Dorner <dorner@cpan.org>
To install UI::Various, copy and paste the appropriate command in to your terminal.
cpanm
cpanm UI::Various
CPAN shell
perl -MCPAN -e shell install UI::Various
For more information on module installation, please visit the detailed CPAN module installation guide.