App::MathImage::Perl::WidgetBits -- miscellaneous Tk widget helpers
use App::MathImage::Perl::WidgetBits 'with_underline';
($str, -underline => $pos) = with_underline($str)
This function is designed for use on a -label or -text argument to a Tk::Menu or similar.
-label
-text
Tk::Menu
$menu->command (-label => with_underline("_File"), -command => ...)
If $str has an underscore like "Save _As" then return 3 values "Save As", -underline => 5 so the underscore becomes a -underline parameter, ie.
$str
"Save As", -underline => 5
-underline
-label => "Save As", -underline => 5,
If $str doesn't have an underscore then return $str unchanged.
A literal underscore can be included by doubling it, for example
"Literal__Underscore" # gives "Literal_Underscore"
Extracting an underline position from a string like this is easier than counting characters manually to make a -underline argument. It's also easier if translating labels into other languages (Locale::TextDomain or similar) since the underline position will be different in a different language or there might be no underline at all.
Locale::TextDomain
Nothing is exported by default but all the functions can be imported in usual Exporter style
A with_underline() import is recommended for source readability, though it works perfectly well with a full module name.
with_underline()
Tk, Tk::Menu
http://user42.tuxfamily.org/math-image/index.html
Copyright 2011, 2012, 2013, 2014, 2019 Kevin Ryde
Math-Image is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Math-Image is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Math-Image. If not, see http://www.gnu.org/licenses/.
To install App::MathImage, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::MathImage
CPAN shell
perl -MCPAN -e shell install App::MathImage
For more information on module installation, please visit the detailed CPAN module installation guide.