Prima::Buttons(3)
๐ธ NAME ๐ธ
Prima::Buttons โ buttons, checkboxes, radios. This is the Prima::Buttons(3) manual page from User Contributed Perl Documentation, bestie, and it's literally all about button widgets ๐
.
โจ SYNOPSIS โจ
use Prima qw(Application Buttons StdBitmap);
my $window = Prima::MainWindow-> create;
Prima::Button-> new(
owner => $window,
text => 'Simple button',
pack => {},
);
$window-> insert( 'Prima::SpeedButton' ,
pack => {},
image => Prima::StdBitmap::icon(0),
);
run Prima;
๐ฆ DESCRIPTION ๐ฆ
Prima::Buttons provides button widgets that include push buttons, check-boxes, and radio buttons. It also provides the Prima::GroupBox class used as a container for the checkboxes and radio buttons. No cap, it's giving full button buffet ๐.
The module provides the following classes:
*Prima::AbstractButton
Prima::Button
Prima::SpeedButton
*Prima::Cluster
Prima::CheckBox
Prima::Radio
Prima::GroupBox
Note: * - marked classes are abstract. Yes bestie, those ones are the blueprint vibes, not the "make one directly" vibes ๐
๐ซถ USAGE ๐ซถ
use Prima::Buttons;
my $button = $widget-> insert( 'Prima::Button',
text => 'Push button',
onClick => sub { print "hey!\n" },
);
$button-> flat(1);
my $group = $widget-> insert( 'Prima::GroupBox',
onRadioClick => sub { print $_[1]-> text, "\n"; }
);
$group-> insert( 'Prima::Radio', text => 'Selection 1');
$group-> insert( 'Prima::Radio', text => 'Selection 2', pressed => 1);
$group-> index(0);
๐ Prima::AbstractButton ๐
Prima::AbstractButton realizes the common functionality of buttons. It provides a reaction to mouse and keyboard events and calls the Click notification when the user activates the button. The activation can be done by:
- Mouse click ๐ฑ๏ธ
- The spacebar key is pressed
"{default}"(seedefaultproperty) boolean variable is set and the Enter key is pressed. This works even if the button is out of focus."{accel}"character variable is assigned and the corresponding character key is pressed. The"{accel}"variable is extracted automatically from the text string passed to thetextproperty. This works even if the button is out of focus.
๐ Events ๐
Checkโ Abstract callback event.Clickโ Called whenever the user activates the button.
๐ Properties ๐
hotKey CHARโ A key (defined byCHAR) that the button will react to if pressed if the button has the focus. The combinationALT + Keyworks always whether the button has the focus or not.pressed BOOLEANโ Manages the pressed state of the button.
Default value: 0
text STRINGโ The text that is drawn in the button. IfSTRINGcontains the"~"(tilde) character, the following character is treated as a hotkey, and the character is underlined. If the user presses the corresponding character key then theClickevent is called. This works even if the button is out of focus.
๐ง Methods ๐ง
draw_veil CANVAS, X1, Y1, X2, Y2โ Draws a rectangular veil shape over theCANVASin given boundaries. This is the default method of drawing the button in the disabled state.draw_caption CANVAS, X, Yโ Draws a single line of text stored in thetextproperty on theCANVASat theX,Ycoordinates. Underlines an eventual tilde-escaped character and draws the text with dimmed colors if the button is disabled. If the button is focused, draws a dotted rectangle around the text.caption_box [ CANVAS = self ]โ Calculates geometrical extensions of the string stored in thetextproperty, in pixels. Returns two integers, the width and the height of the string for the font currently selected on theCANVAS.
If CANVAS is undefined, the widget's font is used for the calculations instead.
๐ Prima::Button ๐
Okay so this is the push button widget, and it extends Prima::AbstractButton by letting an image be drawn right alongside the text. Icon + label energy. ๐ผ๏ธโจ
๐ Properties ๐
autoHeightBOOLEAN โ If it's1, the button height automatically changes whenever the text extensions change. Default value:1. ๐autoRepeatBOOLEAN โ If set, the widget behaves like a keyboard button: after the firstClickevent, a timeout is set, and if the button is still pressed after that, theClickevent is repeatedly fired. Can be useful for stuff like emulating scroll-bar arrow buttons. Default value:0. ๐autoShapingBOOLEAN โ If1, the button "shape" is automatically updated when the button size and/or font are updated, if the current skin can make use of non-rectangular shapes. Generally unneeded unless the owner of the button has a different back color or features some custom painting. Default value:0. See also:examples/triangle.pl,examples/dragdrop.pl. ๐งautoWidthBOOLEAN โ If1, the button width is automatically changed as text extensions change. Default value:1. ๐borderWidthINTEGER โ Width of the border around the button. Default value: depends on the skin. ๐๏ธcheckableBOOLEAN โ Selects if the button toggles the checked state when the user presses it. Default value:0. โcheckedBOOLEAN โ Selects whether the button is checked or not. Only actual when thecheckableproperty is set. See alsoholdGlyph. Default value:0. ๐defaultBOOLEAN โ Defines if the button should react when the user presses the enter button. If set, the button is drawn with a black border, indicating that it executes the 'default' action. Useful for OK-buttons in dialogs. Default value:0. ๐defaultGlyphINTEGER | IMAGE | METAFILE โ Selects the index of the default sub-image. Default value:0. ๐ผ๏ธdisabledGlyphINTEGER | IMAGE | METAFILE โ Selects the index of the sub-image for the disabled button state. Ifimagedoes not contain such a sub-image, thedefaultGlyphsub-image is drawn and is dimmed over using thedraw_veilmethod. Default value:1. ๐flatBOOLEAN โ Selects special 'flat' mode, when a button is painted without a border when the mouse pointer is outside the button boundaries. This mode is useful for toolbar buttons. See alsohiliteGlyph. Default value:0. ๐ชglyphsINTEGER โ If a button is to be drawn with an image, it can be passed in theimageproperty. If, however, the button must be drawn with several different images, there are no several image-holding properties. Instead, the image object can be logically split vertically into several equal sub-images. This allows the image resource to contain all button states in a single image file. Theglyphsproperty assigns how many such sub-images the image object contains. The sub-image indices can be assigned to reflect the different button states. These indices are selected by the following integer properties:defaultGlyph,hiliteGlyph,disabledGlyph,pressedGlyph, andholdGlyph. Default value:1. ๐งฉhiliteโ Read-only property, returns1if the button is highlighted,0otherwise. โจhiliteGlyphINTEGER | IMAGE | METAFILER โ Selects the index of the sub-image for the state when the mouse pointer is hovering over the button. This image is used only when theflatproperty is set. Ifimagedoes not contain such a sub-image, thedefaultGlyphsub-image is drawn. Default value:0. ๐ฆholdGlyphINTEGE | IMAGE | METAFILER โ Selects the index of the sub-image for the state when the button is checked. This image is used only when thecheckableproperty is set. Ifimagedoes not contain such a sub-image, thedefaultGlyphsub-image is drawn. Default value:3. ๐ซถimageOBJECT โ If set, the image object is drawn next with the button text, on the top or on the left (see theverticalproperty). If the OBJECT contains several sub-images, then the corresponding sub-image is drawn for each button state. See theglyphsproperty. Can also be aPrima::Drawable::Metafileobject, however, theimageScalefactor wouldn't work on it. Default value:undef. ๐imageFileFILENAME โ An alternative to image selection that loads an image from the file. During the creation state, if set together with theimageproperty, is superseded by the latter. To allow easy multiframe image access, the FILENAME string is checked if it contains a number after the colon in the string end. Such as,imageFile('image.gif:3')loads the fourth frame fromimage.gif. ๐imageScaleSCALE โ Manages the zoom factor for the image. Default value:1. ๐modalResultINTEGER โ Contains a custom integer value, preferably one ofmb::XXXconstants. If a button with non-zeromodalResultis owned by a currently executing modal window, and is pressed, itsmodalResultvalue is copied to themodalResultproperty of the owner window, and the latter is closed. This scheme is helpful for the following dialog design:
$dialog-> insert( 'Prima::Button', modalResult => mb::OK,
text => '~Ok', default => 1);
$dialog-> insert( 'Prima::Button', modalResult => mb::Cancel,
text => 'Cancel);
return if $dialog-> execute != mb::OK.
The toolkit defines the following default constants for modalResult use:
mb::OK or mb::Ok
mb::Cancel
mb::Yes
mb::No
mb::Abort
mb::Retry
mb::Ignore
mb::Help
However, any other integer value can be safely used. Default value: 0. ๐
smoothScalingBOOL โ Tries to paint the image as smoothly as possible. When the system doesn't support ARGB layering, smooth scaling of icons will be restricted to integer-scaling only (i.e.2x,3x, etc) because the smoothed color plane will not match pixelated mask plane, and because box-scaling with non-integer zooms looks ugly. Default value:true. See also:ui_scalein Prima::Image. ๐งผpressedGlyphINTEGER | IMAGE | METAFILE โ Selects the index of the sub-image for the pressed state of the button. Ifimagedoes not contain such a sub-image, thedefaultGlyphsub-image is drawn. ๐ฅtransparentBOOLEAN โ Seetransparentin Prima::Widget. If set, the background is not painted. ๐ซงverticalBOOLEAN โ Determines the position of the image next to the text string. If1, the image is drawn above the text; left to the text if0. In a special case when text is an empty string, the image is centered. โฌ๏ธ
โก Prima::SpeedButton โก
A convenience class, same as Prima::Button but with default squared shape and text property set to an empty string. โจ
๐ธ Prima::Cluster ๐ธ
An abstract class with common functionality of Prima::CheckBox and Prima::RadioButton. Reassigns default actions on tab and back-tab keys, so the sibling cluster widgets are not selected. Has ownerBackColor property set to 1, to prevent usage of background color from wc::Button palette. ๐
๐ Properties ๐
autoBOOLEAN โ If set, the button is automatically checked when the button is in focus. This functionality allows the use of arrow keys for navigating the radio buttons without pressing the spacebar key. It also has a drawback: if a radio button gets focused without user intervention, or indirectly, it also gets checked, so that behavior might confuse. The said can be exemplified when an unchecked radio button in a notebook widget becomes active by turning the notebook page. Although this property is present in thePrima::CheckBoxclass, it is not used in there. ๐
๐ ๏ธ Methods ๐ ๏ธ
checkโ Alias tochecked(1). โuncheckโ Alias tochecked(0). โฌtoggleโ Reverts thecheckedstate of the button and returns the new state. ๐
๐ป Prima::Radio ๐ป
Represents the standard radio button that can be checked or unchecked. When checked, delivers the RadioClick event to the owner if the latter provides one. The button uses the standard toolkit images with sbmp::RadioXXX indices when using the classic skin. If the images can not be loaded, the button is drawn with the graphic primitives. ๐ฏ
๐ Events ๐
Checkโ Called when the button was checked. โ
โ Prima::CheckBox โ
Represents the standard check box button, that can be checked or unchecked. The button uses the standard toolkit images with sbmp::CheckBoxXXX indices when using the classic skin. If the images can not be loaded, the button is drawn with graphic primitives. ๐
๐ Prima::GroupBox ๐
A container for radio and checkbox buttons (but can contain any widgets). The widget draws a rectangular box and a title string. Uses the transparent property to determine if it needs to paint its background. The class does not provide a method to calculate the extension of the inner rectangle. However, it can be safely assumed that all offsets except the upper are 5 pixels. The upper offset is dependent on a font and constitutes half of the font height. ๐ฆ
๐ Events ๐
RadioClickBUTTON โ Called whenever one of the children radio buttons is checked. BUTTON parameter contains the newly checked button. The default action of the class is that all checked buttons, except BUTTON, are unchecked. Since the flow type of theRadioClickevent isnt::PrivateFirst, theon_radioclickmethod must be directly overloaded to disable this functionality. ๐ฏ
๐ Properties ๐
borderBOOLEAN โ If set (default), draws a border along the widget boundaries. ๐ผ๏ธindexINTEGER โ Checks the child radio button withindex. The indexing is based on the index in the widget list, returned by thePrima::Widget::widgetsmethod. ๐ขvalueBITFIELD โ BITFIELD is an unsigned integer, where each bit corresponds to thecheckedstate of a child check-box button. The indexing is based on the index in the widget list, returned by thePrima::Widget::widgetsmethod. ๐งฎ
๐ BUGS ๐
Tilde escaping in text is not realized, but is planned to. There currently is no way to avoid tilde underscoring. ๐ญ
Radio buttons can get unexpectedly checked when used in notebooks. See auto. ๐ตโ๐ซ
The Prima::GroupBox::value parameter is an integer, which size is architecture-dependent. Shifting towards a vector is considered a good idea. ๐ซ
๐ AUTHOR ๐
Dmitry Karasik, <dmitry@karasik.eu.org>. ๐
๐ SEE ALSO ๐
okay so after you've absorbed all of that, here's your little reading list bestie โ go binge these next, no cap:
Primaโ the mothership, the blueprint, the whole ecosystem ๐Prima::Widgetโ the base class everything (including your fave buttons) is built on โจPrima::Windowโ for when you want the whole window vibe, not just a lil button ๐Prima::Drawable::Metafileโ the drawable-shenanigans sibling, lowkey essential ๐ฆPrima::StdBitmapโ where all the standard bitmaps live ๐ธexamples/buttons.plโ actual runnable code, chef's kiss ๐examples/buttons2.plโ the sequel, and yes it ate ๐ซถ
and that's the whole page, bestie โ you made it to the end ๐ like, genuinely iconic behavior.
tiny cute sign-off because you deserve it: this was the Prima::Buttons(3) page, served up by perl v5.42.0, stamped 2024-08-20. go forth and make your buttons gorgeous, you absolute main character ๐โจ๐๐
๐ฅ๐
๐ฆ 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