Prima::Notebooks(3)
Prima::Notebooks(3) Β· User Contributed Perl Documentation Β· bestie, this is the multipage-widget lore and it's giving iconic container energy π
π NAME π
Prima::Notebooks β multipage widgets π¦
πΈ DESCRIPTION πΈ
This module is your little squad of widgets for organizing multipage containers, aka notebooks. Prima::Notebook brings the basic functionality of that kind of widget container. Prima::TabSet is the page selector control, and Prima::TabbedNotebook combines these two into a ready-to-use multipage control with interactive navigation. Periodt. β¨
β¨ SYNOPSIS β¨
use Prima qw(Notebooks Buttons Application);
my $nb = Prima::TabbedNotebook-> new(
tabs => [ 'First page', 'Second page', 'Second page' ],
size => [ 300, 200 ],
);
$nb-> insert_to_page( 1, 'Prima::Button' );
$nb-> insert_to_page( 2,
[ 'Prima::Button', bottom => 10 ],
[ 'Prima::Button', bottom => 150 ],
);
$nb-> Notebook-> backColor( cl::Green );
run Prima;
π¦ Prima::Notebook π¦
This class gives you basic widget container functionality. It's basically a grouping widget that hides and shows child widgets whenever the pageIndex property changes. Lowkey the whole vibe. π
β¨ Properties β¨
defaultInsertPageINTEGER β picks which page widgets attached by theinsertcall get assigned to. If it's set toundef, the default page is the current page. Default value:undef.pageCountINTEGER β picks the number of pages. If you reduce the number of pages, widgets that belong to the rejected pages are removed from the notebook's storage. No leftovers, bestie.pageIndexINTEGER β picks the index of the current page. Valid values go from0topageCount - 1.
π Methods π
attach_to_page INDEX, @WIDGETSβ attaches@WIDGETSto theINDEXth page. The widgets don't necessarily have to be children of the notebook widget. If theINDEXth page is not the current one, the widgets get hidden and disabled; otherwise their state is not changed.contains_widget WIDGETβ searches forWIDGETin the attached widgets list. If it finds it, returns two integers: the location page index and the widget list index. Otherwise returns an empty list.delete_page [ INDEX = -1, REMOVE_CHILDREN = 1 ]β deletes theINDEXth page and detaches the widgets associated with it. IfREMOVE_CHILDRENis1, the detached widgets are destroyed.delete_widget WIDGETβ detachesWIDGETfrom the widget list and destroys the widget.detach_from_page WIDGETβ detachesWIDGETfrom the widget list.insert CLASS, %PROFILE [[ CLASS, %PROFILE], ... ]β creates one or more widgets with theownerproperty set to the caller widget, and returns the list of references to the newly created objects. Seeinsertin Prima::Widget for details.insert_page [ INDEX = -1 ]β inserts a new empty page atINDEX. The valid range is from0topageCount; settingINDEXequal topageCountis equivalent to appending a page to the end of the page list.insert_to_page INDEX, CLASS, %PROFILE, [[ CLASS, %PROFILE], ... ]β inserts one or more widgets to theINDEXth page. SettingCLASSandPROFILE, plus the return values, is fully equivalent to theinsertmethod. Seeinsertin Prima::Widget for details.insert_transparent CLASS, %PROFILE, [[ CLASS, %PROFILE], ... ]β inserts one or more widgets to the notebook widget, but does not add widgets to the widget list, so the widgets are not flipped together with pages. Useful for setting omnipresent ( or transparent ) widgets, visible on all pages. SettingCLASSandPROFILE, plus the return values, is fully equivalent to theinsertmethod. Seeinsertin Prima::Widget for details.move_widget WIDGET, INDEXβ movesWIDGETto theINDEXth page.widget_get WIDGET, PROPERTYβ returns thePROPERTYvalue ofWIDGET. IfPROPERTYis affected by the page flipping mechanism, the internal flag value is returned instead.widget_set WIDGET, %PROFILEβ callssetonWIDGETwithPROFILEand updates the internalvisible,enabled,current, andgeometryproperties if these are present inPROFILE. Seesetin Prima::Object.widgets_from_page INDEXβ returns the list of widgets associated with theINDEXth page.
π₯ Events π₯
Change OLD_PAGE_INDEX, NEW_PAGE_INDEXβ called when thepageIndexvalue is changed fromOLD_PAGE_INDEXtoNEW_PAGE_INDEX. Current implementation invokes this notification while the notebook widget is in the locked state, so no redraw requests are honored during the execution of the notification.
π Bugs π
Since the notebook operates directly on children widgets' ::visible and ::enable properties, there's a problem when a widget associated with a non-active page must be explicitly hidden or disabled. As a result, such a widget would become visible and enabled anyway. This happens because Prima API does not cache property requests. For example, after the execution of the following code
$notebook-> pageIndex(1);
my $widget = $notebook-> insert_to_page( 0, ... );
$widget-> visible(0);
$notebook-> pageIndex(0);
$widget will still become visible. As a workaround, the widget_set method can be suggested, to be called together with the explicit state calls. Changing the
$widget-> visible(0);
code to
$notebook-> widget_set( $widget, visible => 0);
solves the problem, but introduces an inconsistency in API. π
π§ Prima::TabSet π§
The Prima::TabSet class implements the functionality of an interactive page switcher. A widget is presented as a set of horizontal bookmark-styled tabs with text identifiers. It's giving very demure, very page-selector. π
πΈ Properties πΈ
coloredBOOLEAN β a boolean property that selects whether each tab uses a unique color ( OS/2 Warp 4 style ), or all tabs are drawn withbackColor. Default value:1.colorsetARRAY β lets you specify custom colors for the tabs. Used only whencoloredis set to1.firstTabINTEGER β selects the first ( leftmost ) visible tab.focusedTabINTEGER β selects the currently focused tab. This property value is almost always equal totabIndexexcept when the widget is navigated by arrow keys, and the tab selection does not occur until the user presses the return key.topMostBOOLEAN β selects the way the widget is oriented. If1, the widget is drawn as if it resides on top of another widget. If0, it is drawn as if it is at the bottom. Default value:1.tabIndexINDEX β selects theINDEXth tab. When changed, theChangenotification is triggered.tabsARRAY β an array of text scalars. Each scalar corresponds to a tab and is displayed correspondingly. The class supports single-line text strings only; newline characters are not respected.
π Methods π
get_item_width INDEXβ returns the width in pixels of theINDEXth tab.tab2firstTab INDEXβ returns the index of the tab that will be drawn leftmost if theINDEXth tab is to be displayed.insert_tab TEXT, [ POSITION = -1 ]β inserts a new tab text at the given position, which is at the end by default.delete_tab POSITIONβ removes the tab from the given position.
π¦ Events π¦
Changeβ triggered when thetabIndexproperty is changed.DrawTab CANVAS, INDEX, COLOR_SET, POLYGON1, POLYGON2β called when theINDEXth tab is to be drawn onCANVAS.COLOR_SETis an array reference that consists of four cached color values: foreground, background, dark 3d color, and light 3d color.POLYGON1andPOLYGON2are array references that contain four points as integer pairs in(X,Y)-coordinates.POLYGON1keeps the coordinates of the larger polygon of a tab, whilePOLYGON2keeps the smaller. Text is displayed inside the larger polygon:
POLYGON1
[2,3] [4,5]
o..........o
. .
[0,1]. TAB_TEXT . [6,7]
o................o
POLYGON2
[0,1] [2,3]
o................o
[6,7]o..............o[4,5]
Depending on the topMost property value, POLYGON1 and POLYGON2 change their mutual vertical orientation. The notification is always called from within the begin_paint/end_paint block.
MeasureTab INDEX, REFβ stores the width of theINDEXth tab in pixels into theREFscalar value. This notification must be called from within thebegin_paint_info/end_paint_infoblock.
π Prima::TabbedNotebook π
okay so bestie, this class is the collab we all needed: it combines the functionality of Prima::TabSet and Prima::Notebook, giving you the interactive multipage widget functionality. The page indexing scheme has two levels: the first level is equivalent to the tabs provided by Prima::TabSet. Each first-level tab, in turn, may contain one or more second-level pages, which can be switched using native Prima::TabbedNotebook controls.
Term check, because words matter: the first-level tabs are referred to as tabs, and the second-level ones are pages. iykyk π
β¨ Properties β¨
The class forwards the following properties of Prima::TabSet, which are described in Prima::TabSet: colored, colorset.
defaultInsertPageINTEGER β Selects the page where widgets attached by theinsertcall are assigned to. If set toundef, the default page is the current page. Default value:undef.notebookClassSTRING β Assigns the notebook widget class. Create-only property. Default value:Prima::Notebook.notebookProfileHASH β Assigns a hash of properties passed to the notebook widget during the creation. Create-only property.notebookDelegationsARRAY β Assigns a list of delegated notifications to the notebook widget. Create-only property.orientationINTEGER β Selects one of the followingtno::XXXconstants:tno::Topβ The TabSet will be drawn at the top of the widget.tno::Bottomβ The TabSet will be drawn at the bottom of the widget.
Default value: tno::Top.
pageIndexINTEGER β Selects the *INDEX*th page or a tabset widget (the second-level tab). When this property is triggered,tabIndexcan change its value, and theChangenotification is triggered.styleINTEGER β Selects one of the followingtns::XXXconstants:tns::Standardβ The widget will have a raised border surrounding it and a+/-control at the top for moving between pages.tns::Simpleβ The widget will have no decorations (other than a standard border). It is recommended to have only one second-level page per tab with this style.
Default value: tns::Standard.
tabIndexINTEGER β Selects the *INDEX*th tab on the tabset widget using the first-level tab numeration.tabsARRAY β Manages the number and names of notebook pages. ARRAY is an anonymous array of text scalars where each corresponds to a single first-level tab and a single notebook page, however, with a single exception. To define second-level tabs, the same text string must be repeated as many times as many second-level tabs are needed. For example, the code
$nb-> tabs('1st', ('2nd') x 3);
results in the creation of a notebook of four pages and two first-level tabs. The tab '2nd' contains three second-level pages.
The property implicitly operates the underlying notebook's pageCount property. When changed at run-time, its effect on the children widgets is therefore the same. See pageCount for more information.
tabsetClassSTRING β Assigns the tab set widget class. Create-only property. Default value:Prima::TabSet.tabsetProfileHASH β Assigns a hash of properties passed to the tab set widget during the creation. Create-only property.tabsetDelegationsARRAY β Assigns a list of delegated notifications to the tab set widget. Create-only property.
πΈ Methods πΈ
The class forwards the following methods of Prima::Notebook, which are described in Prima::Notebook: attach_to_page, insert_to_page, insert, insert_transparent, delete_widget, detach_from_page, move_widget, contains_widget, widget_get, widget_set, widgets_from_page.
tab2page INDEXβ Returns the second-level tab index that corresponds to the *INDEX*th first-level tab.page2tab INDEXβ Returns the first-level tab index that corresponds to the *INDEX*th second-level tab.insert_page TEXT, [ POSITION = -1 ]β Inserts a new page with text at the given position, which is at the end by default. If the TEXT is the same as the existing tab left or right from POSITION, the page is joined to the existing tab as a page; otherwise, a new tab is created.delete_page POSITIONβ Removes the page from the given position.
π¦ Events π¦
Change OLD_PAGE_INDEX, NEW_PAGE_INDEXβ Triggered when thepageIndexproperty changes its value from OLD_PAGE_INDEX to NEW_PAGE_INDEX.
π AUTHORS π
Dmitry Karasik, <dmitry@karasik.eu.org>. Teo Sankaro, <teo_sankaro@hotmail.com>.
π SEE ALSO π
Prima, Prima::Widget, examples/notebook.pl.
π later bestie β this manual page is from perl v5.42.0, dated 2024-08-20, and it's Prima::Notebooks(3) π«Ά
π¦ 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