1+ classdef TemplateBaseApp < wt .apps .BaseApp
2+ % Implements a template for a BaseApp
3+
4+
5+ %% Internal Components
6+ % Create properties here for each control, layout, or view component
7+ % that will be placed directly into the main app window.
8+ properties ( Transient , NonCopyable , SetAccess = protected )
9+
10+ % Once the app is created and debugged, consider also protecting
11+ % get access to these properties. Leave them accessible to unit
12+ % tests, however. Use this example:
13+ % GetAccess = {?matlab.uitest.TestCase, ?wt.apps.BaseApp})
14+
15+ % Grid Layouts
16+ % (BaseApp already brings "Grid", the main Grid layout in the window)
17+ Tab1Grid matlab.ui.container.GridLayout
18+ Tab2Grid matlab.ui.container.GridLayout
19+ Panel1Grid matlab.ui.container.GridLayout
20+ Panel2Grid matlab.ui.container.GridLayout
21+
22+ % Panels
23+ Panel1 matlab.ui.container.Panel
24+ Panel2 matlab.ui.container.Panel
25+
26+ % Tabs
27+ TabGroup matlab.ui.container.TabGroup
28+ Tab1 matlab.ui.container.Tab
29+ Tab2 matlab.ui.container.Tab
30+
31+ % View Components
32+ % View1 packageName.ClassName
33+ % View2 packageName.ClassName
34+
35+ % Temporary label components
36+ Panel1Text matlab.ui.control.Label
37+ Panel2Text matlab.ui.control.Label
38+ Tab1Text matlab.ui.control.Label
39+ Tab2Text matlab.ui.control.Label
40+
41+ end % properties
42+
43+
44+
45+ %% Setup and Configuration of the App
46+ methods ( Access = protected )
47+
48+ function setup(app )
49+ % Runs once on instantiation of the app
50+
51+ % Set the name
52+ app.Name = " My App" ;
53+
54+ % Configure the main grid
55+ app.Grid.ColumnWidth = {300 ,' 1x' };
56+ app.Grid.RowHeight = {' 1x' ,150 };
57+ app.Grid.Padding = 5 ;
58+
59+ % Create a panel
60+ app.Panel1 = uipanel(app .Grid );
61+ app.Panel1.Title = " Panel 1" ;
62+ app.Panel1.Layout.Row = [1 2 ];
63+ app.Panel1.Layout.Column = 1 ;
64+ app.Panel1.BackgroundColor = " magenta" ;
65+
66+ % Create a panel
67+ app.Panel2 = uipanel(app .Grid );
68+ app.Panel2.Title = " Panel 2" ;
69+ app.Panel2.Layout.Row = 2 ;
70+ app.Panel2.Layout.Column = 2 ;
71+ app.Panel2.BackgroundColor = " white" ;
72+
73+ % Create a tab group
74+ app.TabGroup = uitabgroup(app .Grid );
75+ app.TabGroup.Layout.Row = 1 ;
76+ app.TabGroup.Layout.Column = 2 ;
77+ app.TabGroup.SelectionChangedFcn = @(h ,e )onTabChanged(app ,e );
78+
79+ % Create Tabs, each with a grid
80+ app.Tab1 = uitab(app .TabGroup );
81+ app.Tab1.Title = ' Tab 1' ;
82+
83+ app.Tab2 = uitab(app .TabGroup );
84+ app.Tab2.Title = ' Tab 2' ;
85+
86+ % Create grid layouts to position content inside each container
87+ app.Panel1Grid = uigridlayout(app .Panel1 , [1 ,1 ]," Padding" , 0 );
88+ app.Panel2Grid = uigridlayout(app .Panel2 , [1 ,1 ]," Padding" , 0 );
89+ app.Tab1Grid = uigridlayout(app .Tab1 , [1 ,1 ]," Padding" , 0 );
90+ app.Tab2Grid = uigridlayout(app .Tab2 , [1 ,1 ]," Padding" , 0 );
91+
92+ % Place some temporary content in each container
93+ app.Panel1Text = uilabel(app .Panel1Grid );
94+ app.Panel1Text.Text = " Panel 1 Contents" ;
95+ app.Panel1Text.Layout.Row = 1 ;
96+ app.Panel1Text.Layout.Column = 1 ;
97+ app.Panel1Text.BackgroundColor = " red" ;
98+
99+ app.Panel2Text = uilabel(app .Panel2Grid );
100+ app.Panel2Text.Text = " Panel 2 Contents" ;
101+ app.Panel2Text.Layout.Row = 1 ;
102+ app.Panel2Text.Layout.Column = 1 ;
103+ app.Panel2Text.BackgroundColor = " green" ;
104+
105+ app.Tab1Text = uilabel(app .Tab1Grid );
106+ app.Tab1Text.Text = " Tab 1 Contents" ;
107+ app.Tab1Text.Layout.Row = 1 ;
108+ app.Tab1Text.Layout.Column = 1 ;
109+ app.Tab1Text.BackgroundColor = " cyan" ;
110+
111+ app.Tab2Text = uilabel(app .Tab2Grid );
112+ app.Tab2Text.Text = " Tab 2 Contents" ;
113+ app.Tab2Text.Layout.Row = 1 ;
114+ app.Tab2Text.Layout.Column = 1 ;
115+ app.Tab2Text.BackgroundColor = " blue" ;
116+
117+ % Additional examples:
118+ % (add other views, layouts, and components here as needed)
119+ % app.View1 = packageName.ClassName( app.Tab1Grid );
120+ % app.View2 = packageName.ClassName( app.Tab2Grid );
121+
122+ end % function
123+
124+ end % methods
125+
126+ %% Update
127+ methods ( Access = protected )
128+
129+ function update(app )
130+ % Update the display of the app
131+ % For the main app, app.update() must be called explicitly
132+ % during callbacks or other changes that require contents to
133+ % refresh.
134+
135+ end % function
136+
137+ end % methods
138+
139+
140+ %% Callbacks
141+ methods
142+
143+ function onTabChanged(app ,evt )
144+ % Triggered on changing tab
145+
146+ % (this method is optional if using tabs)
147+
148+ newTab = evt .NewValue ;
149+ disp(" Selected Tab: " + newTab .Title );
150+
151+ end % function
152+
153+ end % methods
154+
155+
156+
157+ %% Private Methods
158+ methods ( Access = private )
159+
160+ % (optionally add any internal methods here)
161+
162+ end % methods
163+
164+ end % classdef
0 commit comments