MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB技术文章 (https://www.labfans.com/bbs/forumdisplay.php?f=25)
-   -   Matlab toolstrip – part 8 (galleries) - undocumentedmatlab (https://www.labfans.com/bbs/showthread.php?t=27445)

poster 2024-12-08 20:21

Matlab toolstrip – part 8 (galleries) - undocumentedmatlab
 
In [URL="https://undocumentedmatlab.com/articles/tag/toolstrip"]previous posts[/URL] I showed how we can create custom Matlab app toolstrips using various controls (buttons, checkboxes, drop-downs, lists etc.). Today I will show how we can incorporate gallery panels into our Matlab toolstrip.
[IMG]https://undocumentedmatlab.com/images/Toolstrip_Gallery.png[/IMG]
Toolstrips can be a bit complex to develop so I’m proceeding slowly, with each post in the miniseries building on the previous posts. I encourage you to review the earlier posts in the [URL="https://undocumentedmatlab.com/articles/tag/toolstrip"]Toolstrip miniseries[/URL] before reading this post.

Also, remember to add the following code snippet at the beginning of your code so that the relevant toolstrip classes will be recognized by Matlab:

import matlab.ui.internal.toolstrip.*[B]Gallery sub-components[/B]

[IMG]https://undocumentedmatlab.com/images/Toolstrip_Gallery_hierarchy.png[/IMG]Toolstrip gallery popup components Toolstrip galleries are panels of buttons (typically large icons with an attached text label), which are grouped in “categories”. The gallery content can be presented either in-line within the toolstrip (a Gallery control), or as a drop-down button’s popup panel (a DropDownGalleryButton control). In either case, the displayed popup panel is a GalleryPopup object, that is composed of one or more GalleryCategory, each of which has one or more GalleryItem (push-button) and/or ToggleGalleryItem (toggle-button).
[LIST][*]Gallery or DropDownGalleryButton[LIST][*]GalleryPopup[LIST][*]GalleryCategory[LIST][*]GalleryItem or ToggleGalleryItem[*]GalleryItem or ToggleGalleryItem[*]…[/LIST][*]GalleryCategory[*]…[/LIST][/LIST][/LIST]For a demonstration of toolstrip Galleries, see the code files in [I]%matlabroot%/toolbox/matlab/toolstrip/+matlab/+ui/+internal/+desktop/[/I], specifically [I]showcaseToolGroup.m[/I] and [I]showcaseBuildTab_Gallery.m[/I].

[B]GalleryPopup[/B]

We first create the GalleryPopup object, then add to it a few GalleryCategory groups of GalleryItem, ToggleGalleryItem buttons. In the example below, we use a ButtonGroup to ensure that only a single ToggleGalleryItem button is selected:

import matlab.ui.internal.toolstrip.*popup = GalleryPopup('ShowSelection',true);% Create gallery categoriescat1 = GalleryCategory('CATEGORY #1 SINGLE'); popup.add(cat1);cat2 = GalleryCategory('CATEGORY #2 SINGLE'); popup.add(cat2);cat3 = GalleryCategory('CATEGORY #3 SINGLE'); popup.add(cat3);% Create a button-group to control item selectabilitygroup = matlab.ui.internal.toolstrip.ButtonGroup;% Add items to the gallery categoriesfpath = [fullfile(matlabroot,'toolbox','matlab','toolstrip','web','image') filesep]; % icons pathitem1 = ToggleGalleryItem('Biology', Icon([fpath 'biology_app_24.png']), group);item1.Description = 'Select the Biology gizmo';item1.ItemPushedFcn = @(x,y) ItemPushedCallback(x,y);cat1.add(item1);item2 = ToggleGalleryItem('Code Generation', Icon([fpath 'code_gen_app_24.png']), group);cat1.add(item2);item3 = ToggleGalleryItem('Control', Icon([fpath 'control_app_24.png']), group);cat1.add(item3);item4 = ToggleGalleryItem('Database', Icon([fpath 'database_app_24.png']), group);cat1.add(item4);...[IMG]https://undocumentedmatlab.com/images/GalleryPopup_single_icon_view.png[/IMG]Single-selection GalleryPopup (icon view)
Note that in a real-world situation, we’d assign a [B]Description[/B], [B]Tag[/B] and [B]ItemPushedFcn[/B] to all gallery items. This was elided from the code snippet above for readability, but should be part of any actual GUI. The [B]Description[/B] only appears as tooltip popup in icon-view (shown above), but appears as a visible label in list-view (see below).

[B]Gallery items selection: push-button action, single-selection toggle, multiple selection toggle[/B]

If we use ToggleGalleryItem without a ButtonGroup, multiple gallery items can be selected, rather than just a single selection as shown above:

...item1 = ToggleGalleryItem('Biology', Icon([fpath 'biology_app_24.png']));item1.Description = 'Select the Biology gizmo';item1.ItemPushedFcn = @(x,y) ItemPushedCallback(x,y);cat1.add(item1);item2 = ToggleGalleryItem('Code Generation', Icon([fpath 'code_gen_app_24.png']));cat1.add(item2);item3 = ToggleGalleryItem('Control', Icon([fpath 'control_app_24.png']));cat1.add(item3);item4 = ToggleGalleryItem('Database', Icon([fpath 'database_app_24.png']));cat1.add(item4);...[IMG]https://undocumentedmatlab.com/images/GalleryPopup_multiple_icon_view.png[/IMG]Multiple-selection GalleryPopup (icon view)
Alternatively, if we use GalleryItem instead of ToggleGalleryItem, the gallery items would be push-buttons rather than toggle-buttons. This enables us to present a gallery of single-action state-less push-buttons, rather than state-full toggle-buttons. The ability to customize the gallery items as either state-less push-buttons or single/multiple toggle-buttons supports a wide range of application use-cases.

[B]Customizing the GalleryPopup[/B]

Properties that affect the GalleryPopup appearance are:
[LIST][*][B]DisplayState[/B] – initial display mode of gallery items (string; default=’icon_view’, valid values: ‘icon_view’,’list_view’)[*][B]GalleryItemRowCount[/B] – number of rows used in the display of the in-line gallery (integer; default=1, valid values: 0,1,2). A Value of 2 should typically be used with a small icon and [B]GalleryItemWidth[/B] (see below)[*][B]GalleryItemTextLineCount[/B] – number of rows used for display of the item label (integer; default=2, valid values: 0,1,2)[*][B]ShowSelection[/B] – whether or not to display the last-selected item (logical; default=false). Needs to be true for Gallery and false for DropDownGalleryButton.[*][B]GalleryItemWidth[/B] – number of pixels to allocate for each gallery item (integer, hidden; default=80)[*][B]FavoritesEnabled[/B] – whether or not to enable a “Favorites” category (logical, hidden; default=false)[/LIST]All of these properties are defined as private in the GalleryPopup class, and can only be specified during the class object’s construction. For example, instead of the default icon-view, we can display the gallery items as a list, by setting the GalleryPopup‘s [B]DisplayState[/B] property to 'list_view' during construction:

popup = GalleryPopup('DisplayState','list_view');[IMG]https://undocumentedmatlab.com/images/GalleryPopup_single_list_view.png[/IMG]GalleryPopup (list view)
Switching from icon-view to list-view and back can also be done by clicking the corresponding icon near the popup’s top-right corner (next to the interactive search-box).

[B]Gallery and DropDownGalleryButton[/B]

Now that we have prepared GalleryPopup, let’s integrate it in our toolstrip.
We have two choices — either in-line within the toolstrip section (using Gallery), or as a compact drop-down button (using DropDownGalleryButton):

% Inline gallerysection = hTab.addSection('Multiple Selection Gallery');column = section.addColumn();popup = GalleryPopup('ShowSelection',true);% add the GalleryPopup creation code abovegallery = Gallery(popup, 'MinColumnCount',2, 'MaxColumnCount',4);column.add(gallery);% Drop-down gallerysection = hTab.addSection('Drop Down Gallery');column = section.addColumn();popup = GalleryPopup();% add the GalleryPopup creation code abovebutton = DropDownGalleryButton(popup, 'Examples', Icon.MATLAB_24);button.MinColumnCount = 5;column.add(button);[IMG]https://undocumentedmatlab.com/images/Toolstrip_Gallery.png[/IMG]
Clicking any of the drop-down (arrow) widgets will display the associated GalleryPopup.
The Gallery and DropDownGalleryButton objects have several useful settable properties:
[LIST][*][B]Popup[/B] – a GalleryPopup object handle, which is displayed when the user clicks the drop-down (arrow) widget. Only settable in the constructor, not after object creation.[*][B]MinColumnCount[/B] – minimum number of item columns to display (integer; default=1). In Gallery, this property is only settable in the constructor, not after object creation; if not enough width is available to display these columns, the control collapses into a drop-down. In DropDownGalleryButton, this property can be set even after object creation (despite incorrect internal documentation), and controls the width of the popup panel.[*][B]MaxColumnCount[/B] – maximal number of items columns to display (integer; default=10). In Gallery, this property is only settable in the constructor, not after object creation. In DropDownGalleryButton, this property can be set even after object creation but in any case seems to have no visible effect.[*][B]Description[/B] – tooltip text displayed when the mouse hovers over the Gallery area (outside the area of the internal gallery items, which have their own individual Descriptions), or over the DropDownGalleryButton control.[*][B]TextOverlay[/B] – a semi-transparent text label overlaid on top of the gallery panel (string, default=”). Only available in Gallery, not DropDownGalleryButton.[/LIST]For example:

gallery = Gallery(popup, 'MinColumnCount',2, 'MaxColumnCount',4);gallery.TextOverlay = 'Select from these items';[IMG]https://undocumentedmatlab.com/images/Toolstrip_TextOverlay.png[/IMG]Effect of TextOverlay

[B]Toolstrip miniseries roadmap[/B]

The next post will discuss popup forms. These are similar in concept to galleries, in the sense that when we click the drop-down widget a custom popup panel is displayed. In the case of a popup form, this is a fully-customizable Matlab GUI figure.
Following that, I plan to discuss toolstrip collapsibility, the Toolpack framework, docking layout, DataBrowser panel, QAB (Quick Access Bar), underlying Java controls, and adding toolstrips to figures – not necessarily in this order.
Matlab toolstrips can be a bit complex, so I plan to proceed in small steps, each post building on top of its predecessors.
If you would like me to assist you in building a custom toolstrip or GUI for your Matlab program, [URL="https://undocumentedmatlab.com/consulting"]please let me know[/URL].

The post [URL="https://undocumentedmatlab.com/articles/matlab-toolstrip-part-8-galleries"]Matlab toolstrip – part 8 (galleries)[/URL] appeared first on [URL="https://undocumentedmatlab.com"]Undocumented Matlab[/URL].

[B]Related posts:[/B]
[LIST=1][*][URL="https://undocumentedmatlab.com/articles/matlab-toolstrip-part-7-selection-controls"]Matlab toolstrip – part 7 (selection controls) [/URL] Matlab toolstrips can contain a wide variety of selection controls: popups, combo-boxes, and galleries. ...[*][URL="https://undocumentedmatlab.com/articles/matlab-toolstrip-part-6-complex-controls"]Matlab toolstrip – part 6 (complex controls) [/URL] Multiple types of customizable controls can be added to Matlab toolstrips...[*][URL="https://undocumentedmatlab.com/articles/matlab-toolstrip-part-9-popup-figures"]Matlab toolstrip – part 9 (popup figures) [/URL] Custom popup figures can be attached to Matlab GUI toolstrip controls. ...[*][URL="https://undocumentedmatlab.com/articles/matlab-toolstrip-part-5-icons"]Matlab toolstrip – part 5 (icons) [/URL] Icons can be specified in various ways for toolstrip controls and the app window itself. ...[/LIST]

[url=https://undocumentedmatlab.com/articles/matlab-toolstrip-part-8-galleries?utm_source=rss&utm_medium=rss&utm_campaign=matlab-toolstrip-part-8-galleries]More...[/url]


所有时间均为北京时间。现在的时间是 23:31

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.