Prima::Outlines(3)
β¨ NAME β¨
Prima::Outlines β tree view widgets. Yep bestie, this is the Prima::Outlines(3) page from the User Contributed Perl Documentation, and it's all about making tree-shaped stuff show up in Prima π
π SYNOPSIS π
use Prima qw(Outlines Application);
my $outline = Prima::StringOutline-> create(
items => [
[ 'Simple item' ],
[ 'Embedded items', [['#1'], ['#2']]],
],
);
$outline-> expand_all;
run Prima;
my $outline = Prima::StringOutline-> create(
iconStyle => 'triangle',
...
);
π¦ DESCRIPTION π¦
Okay so this module hands you a whole set of widget classes made for displaying tree-like structures. Prima::OutlineViewer is the generic one β it has the basic functionality and defines the interface for its descendants, which are Prima::StringOutline, Prima::Outline, and Prima::DirectoryOutline. Slay πΈ
π³ Prima::OutlineViewer π³
This bad boy presents a generic interface for browsing tree-like lists. Each node in the linked list represents an item. The node format is already predefined, and it's an anonymous array with these index definitions:
#0β Item id in an unspecified format. The simplest implementation,Prima::StringOutline, treats the scalar as a text string. The more complex classes store references to arrays or hashes here. See theitemsarticle of a concrete class for the format of the node record.#1β Reference to a child node.undefif there is none.#2β A boolean flag that selects if the node is to be shown as expanded, e.g. all of its immediate children are visible.#3β Width of an item in pixels.
Indices above3should not be used, because eventual changes to the implementation of the class may use these. The general idea is that the data at index#0should be self-sufficient to define an item. No cap π
To support a custom format of the node, these notifications should be overloaded: DrawItem, MeasureItem, and Stringify. Since DrawItem is called for every item, a gross method draw_items can be overloaded instead. See also Prima::StringOutline and Prima::Outline.
The class employs two ways to address an item: index-wise and item-wise. The index-wise one counts only the visible ( non-expanded ) items and is represented by an integer index. The item-wise addressing cannot be expressed by an integer index, and the full node structure is used as a reference. It is important to use a valid reference here, since the class does not always perform the check if the node belongs to the internal node list β due to speed reasons π
Prima::OutlineViewer is a descendant of Prima::Widget::GroupScroller and Prima::Widget::MouseScroller, so some of their properties and methods are not described here.
Heads up bestie: this class is not usable directly π«Ά
π Properties π
autoHeight INTEGERβ If set to1, changesitemHeightautomatically according to the widget font height. If0, it does not influence anything. WhenitemHeightis set explicitly, this value changes to0. Default value:1β¨dragable BOOLEANβ If1, allows the items to be dragged interactively by pressing the Control key together with the left mouse button. If0, item dragging is disabled. Default value:1drawLines BOOLEANβ If1, draws dotted tree lines left of the items. Default value:1extendedSelect BOOLEANβ Manages the way the user selects multiple items, and it's only actual whenmultiSelectis1. If0, the user must click each item to mark it as selected. If1, the user can drag the mouse or use the Shift key plus arrow keys to perform range selection; the Control key can be used to select individual items. Default value:0focusedItem INTEGERβ Selects the focused item index. If-1, no item is focused. It's mostly a run-time property, but it can be set during the widget creation stage given that the item list is accessible at this stage too.iconCollapsed ICONβ Sets the image that is displayed when a tree branch is collapsed.iconExpanded ICONβ Sets the image that is displayed when a tree branch is expanded.iconStyle STYLEβ Sets visual style, one of:default,plusminus, ortriangle. The default style is set in$Prima::Outlines::default_styleand is currently'plusminus', but it can be overridden byskin. The default style for the current default skinflatis'triangle'.indent INTEGERβ Width in pixels of the indent between item levels. Default value:12itemHeight INTEGERβ Selects the height of the items in pixels. Since the outline classes do not support items with various heights, changes to this property affect all items. Default value: default font heightitems ARRAYβ Provides access to the items as an anonymous array. The format of an item is described in the opening article ( seePrima::OutlineViewer). Default value:[]multiSelect BOOLEANβ If0, the user can only select one item, which is also reported by thefocusedItemproperty. If1, the user can select more than one item. In this case, thefocusedItem'th item is not necessarily selected. To access the selected item list, use theselectedItemsproperty. Default value:0offset INTEGERβ Horizontal offset of the item list in pixels.selectedItems ARRAYβARRAYis an array of integer indices of the selected items. Note that these are the items visible on the screen only. The property doesn't handle the selection status of the collapsed items. The widget keeps the selection status on each node, visible and invisible ( e.g. the node is invisible if its parent node is collapsed ). However,selectedItemsaccounts for the visible nodes only; to manipulate the node status or both visible and invisible nodes, use theselect_item,unselect_item, andtoggle_itemmethods.showItemHint BOOLEANβ If1, allows activation of a hint label when the mouse pointer is hovered above an item that does not fit horizontally into the widget inferiors. If0, the hint is never shown. See also:makehint. Default value:1topItem INTEGERβ Selects the first item drawn.
π Methods π
add_selection ARRAY, FLAGβ Sets item indices fromARRAYin selected or deselected state, depending on theFLAGvalue, correspondingly1or0. Note that these are the items visible on the screen only. The method doesn't handle the selection status of the collapsed items. Only for the multi-select mode.adjust INDEX, EXPANDβ Performs expansion (1) or collapse (0) of theINDEXth item, depending on theEXPANDboolean flag value.calibrateβ Recalculates the node tree and item dimensions. Used internally.delete_items [ NODE = undef, OFFSET = 0, LENGTH = undef ]β DeletesLENGTHchildren items ofNODEatOFFSET. IfNODEisundef, the root node is assumed. IfLENGTHisundef, all items afterOFFSETare deleted.delete_item NODEβ DeletesNODEfrom the item list.deselect_allβ Removes selection from all items. Only for multi-select mode.draw_items CANVAS, PAINT_DATAβ Called from within thePaintnotification to draw items. The default behavior is to call theDrawItemnotification for every visible item.PAINT_DATAis an array of arrays, where each consists of the parameters passed to theDrawItemnotification. This method is overridden in some descendant classes, to increase the speed of the drawing routine. SeeDrawItemforPAINT_DATAparameters description.get_index NODEβ Traverses all items forNODEand finds if it is visible. If it is, returns two integers: the first is the item index and the second is the item depth level. If the node is not visible,-1, undefis returned.get_index_text INDEXβ Returns the text string associated with theINDEXth item. Since the class does not assume the item storage organization, the text is queried via theStringifynotification.get_index_width INDEXβ Returns the width in pixels of theINDEXth item, which is a cached result of theMeasureItemnotification, stored under index#3in a node.get_item INDEXβ Returns two scalars corresponding to theINDEXth item: the node reference and its depth level. IfINDEXis outside the list boundaries, an empty array is returned.get_item_parent NODEβ Returns two scalars, corresponding to theNODE: its parent node reference and offset of theNODEin the parent's immediate children list.get_item_text NODEβ Returns the text string associated with theNODE. Since the class does not assume the item storage organization, the text is queried via theStringifynotification.get_item_width NODEβ Returns width in pixels of theINDEXth item, which is a cached result of theMeasureItemnotification, stored under index#3in a node.expand_all [ NODE = undef ].β Expands all nodes underNODE. IfNODEisundef, the root node is assumed. If the tree is large, the execution can take a significant amount of time β³insert_items NODE, OFFSET, @ITEMSβ Inserts one or moreITEMSunderNODEwithOFFSET. IfNODEisundef, the root node is assumed.iterate ACTION, FULLβ Traverses the item tree and calls theACTIONsubroutine on each node. If theFULLboolean flag is1, all nodes are traversed. If0, only the expanded nodes are traversed.ACTIONsubroutine is called with the following parameters:#0β Node reference#1β Parent node reference; ifundef, the node is the root.#2β Node offset in the parent item list.#3β Node index.#4β Node depth level.0means the root node.#5β A boolean flag, set to1if the node is the last child in the parent node list, set to0otherwise.#6β Visibility index. Wheniterateis called withFULL = 1, the index is the item index as seen on the screen. If the item is not visible, the index isundef. Wheniterateis called withFULL = 1, the index is always the same asnode index.
is_selected INDEX, ITEMβ Returns1if an item is selected,0if it is not. The method can address the item either directly (ITEM) or by itsINDEXin the screen position.makehint SHOW, INDEXβ okay so this one controls the hint label of the INDEXth item. If the boolean flag SHOW is 1, theshowItemHintproperty is 1, and the item index does not fit horizontally in the widget inferiors, then the hint label is shown. By default the label is removed automatically as soon as the user moves the mouse pointer away from the item. If SHOW is 0, the hint label is hidden immediately. periodt πpoint2item Y, [ HEIGHT ]β returns the index of the item that occupies the horizontal axis at Y in the widget coordinates. If HEIGHT is specified, it must be the widget height; if it is not, the value is fetched by callingPrima::Widget::height. If the value is known, passing it topoint2itemthus achieves some speed-up. literally free speed β‘select_allβ selects all items. Only for multi-select mode. β¨set_item_selected INDEX, ITEM, FLAGβ sets the selection flag of an item. If FLAG is 1, the item is selected. If 0, it is deselected. The method can address the item either directly ( ITEM ) or by its INDEX. Only for the multi-select mode. π«Άselect_item INDEX, ITEMβ selects an item. The method can address the item either directly ( ITEM ) or by its INDEX. Only for the multi-select mode. πtoggle_item INDEX, ITEMβ toggles selection of an item. The method can address the item either directly ( ITEM ) or by its INDEX. Only for the multi-select mode. πunselect_item INDEX, ITEMβ deselects an item. The method can address the item either directly ( ITEM ) or by its INDEX. Only for the multi-select mode. πvalidate_items ITEMSβ traverses an array of ITEMS and changes every node so that eventual scalars above index #3 are deleted. It also adds default values to a node if it contains less than 3 scalars. cleanup era π§Ή
π« Events π«
Expand NODE, EXPANDβ called when NODE is expanded ( 1 ) or collapsed ( 0 ). The EXPAND boolean flag reflects the action taken. πΈDragItem OLD_INDEX, NEW_INDEXβ called when the user finishes the drag of an item from OLD_INDEX to NEW_INDEX position. The default action rearranges the item list according to the dragging action. πDrawItem CANVAS, NODE, X1, Y1, X2, Y2, INDEX, SELECTED, FOCUSED, PRELIGHTβ called when the INDEXth item contained in NODE is to be drawn on CANVAS. X1, Y1, X2, Y2 coordinates define the exterior rectangle of the item in widget coordinates. SELECTED, FOCUSED, and PRELIGHT boolean flags are set to 1 if the item is selected, focused, or pre-lighted, respectively; 0 otherwise. π¨MeasureItem NODE, LEVEL, REFβ stores the width of the NODE item in pixels into the REF scalar reference. LEVEL is the node depth as returned byget_itemfor the reference. This notification must be called from within thebegin_paint_info/end_paint_infoblock. πSelectItem [[INDEX, ITEM, SELECTED], [INDEX, ITEM, SELECTED], ...]β called when an item gets selected or deselected. The array passed contains a set of arrays for each item where each contains either an integer INDEX or the ITEM, or both. In case the INDEX is undef, the item is invisible; if the ITEM is undef, then the caller didn't bother to callget_itemfor speed reasons, and the receiver should call this function. The SELECTED flag contains the new value of the item. π«ΆStringify NODE, TEXT_REFβ stores text string associated with the NODE item into the TEXT_REF scalar reference. π
πΈ Prima::StringOutline πΈ
A descendant of the Prima::OutlineViewer class, provides a standard single-text-item widget. The items can be defined by supplying a text as the first scalar in the node array structure:
$string_outline-> items([ 'String', [ 'Descendant' ]]);
π¦ Prima::Outline π¦
A variant of Prima::StringOutline, with the only difference that the text is stored not in the first scalar in a node but as a first scalar in an anonymous array, which in turn is the first node scalar. The class does not define either format or the number of scalars in the array, and as such presents a half-abstract class. main character energy, but abstract π«
ποΈ Prima::DirectoryOutline ποΈ
Provides a standard widget with the item tree mapped to the directory structure, so that each item is mapped to a directory. Depending on the type of the host OS, there is either a single root directory ( unix ), or one or more disk drive root items ( win32 ). π₯οΈ
The node format is defined as follows:
#0β Directory name, string.#1β Parent path; an empty string for the root items.#2β Icon width in pixels, integer.#3β Drive icon; defined only for the root items under Windows to reflect the drive type ( hard, floppy, etc ).
π Properties π
closedGlyphs INTEGERβ the number of horizontal equal-width images in theclosedIconproperty. Default value: 1.closedIcon ICONβ provides an icon representation for the collapsed items.openedGlyphs INTEGERβ the number of horizontal equal-width images in theopenedIconproperty. Default value: 1.openedIcon OBJECTβ provides an icon representation for the expanded items.path STRINGβ runtime-only property. Selects the current file system path.showDotDirs BOOLEANβ selects if the directories with the first dot character are shown in the tree view. The treatment of the dot-prefixed names as hidden is traditional to unix and is of doubtful use under Windows. Default value: 0.
π οΈ Methods π οΈ
files [ FILE_TYPE ]β if the FILE_TYPE value is not specified, the list of all files in the current directory is returned. If FILE_TYPE is given, only the files of the types are returned. The FILE_TYPE is a string, one of those returned byPrima::Utils::getdir( seegetdirin Prima::Utils ). πget_directory_tree PATHβ reads the file structure under PATH and returns a newly created hierarchy structure in the class node format. If theshowDotDirsproperty value is 0, the dot-prefixed names are not included. Used internally inside theExpandnotification. π³
π AUTHOR π
Dmitry Karasik, <dmitry@karasik.eu.org>. π
π SEE ALSO π
Prima, Prima::Widget, <examples/outline.pl>. π
and thatβs the whole page, bestie π«Ά source/version: perl v5.42.0, date: 2024-08-20 β Prima::Outlines(3) out π
β¨
π¦ 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