Skip to content

Commit 5d158a0

Browse files
committed
Refactored some code to close Issue #28 and others:
- added wt.mixin.PropertyViewable.m - Modified all widgets to inherit the PropertyViewable mixin - Added a protected method "getPropertyGroups" to all widgets to overrride componentcontainer method with "getPropertyGroups" from PropertyViewable mixin
1 parent cd98d96 commit 5d158a0

15 files changed

+198
-33
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
classdef PropertyViewable < handle
2+
% Mixin for component to organize the display of properties in the
3+
% command window.
4+
%
5+
6+
% Copyright 2020-2022 The MathWorks Inc.
7+
8+
%% Properties
9+
properties (AbortSet, Transient, NonCopyable)
10+
11+
12+
end
13+
14+
15+
%% Accessors
16+
methods (Hidden, Access = protected)
17+
18+
function groups = getPropertyGroups(obj)
19+
% Customize how the properties are displayed
20+
21+
% Ignore most superclass properties for default display
22+
persistent superProps
23+
if isempty(superProps)
24+
superProps = properties('matlab.ui.componentcontainer.ComponentContainer');
25+
end
26+
27+
% Get the relevant properties (ignore Superclass properties)
28+
allProps = properties(obj);
29+
propNames = setdiff(allProps, superProps, 'stable');
30+
31+
% Remove properties we don't need to see
32+
propNames(startsWith(propNames, "Font")) = [];
33+
propNames(matches(propNames, "Enable")) = [];
34+
35+
% Split callbacks, fonts, and colorizations
36+
isCallback = endsWith(propNames, "Fcn");
37+
isColor = endsWith(propNames, "Color");
38+
normalProps = propNames(~isCallback);
39+
callbackProps = propNames(isCallback & ~isColor);
40+
41+
% Define the property gorups
42+
groups = [
43+
matlab.mixin.util.PropertyGroup(callbackProps)
44+
matlab.mixin.util.PropertyGroup(normalProps)
45+
matlab.mixin.util.PropertyGroup(["Position", "Units"])
46+
];
47+
48+
% Ignore Empty Groups
49+
groups(~[groups.NumProperties]) = [];
50+
51+
end
52+
53+
end
54+
end

widgets/+wt/ButtonGrid.m

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
classdef ButtonGrid < matlab.ui.componentcontainer.ComponentContainer & ...
22
wt.mixin.BackgroundColorable & ...
3-
wt.mixin.Enableable & wt.mixin.FontStyled & wt.mixin.ButtonColorable
3+
wt.mixin.Enableable & wt.mixin.FontStyled & wt.mixin.ButtonColorable & ...
4+
wt.mixin.PropertyViewable
45

56
% A grid of buttons with a single callback/event
67

7-
% Copyright 2020-2022 The MathWorks Inc.
8-
8+
% Copyright 2020-2022 The MathWorks Inc.
99

1010

1111
%% Events
@@ -29,9 +29,6 @@
2929

3030
% Tooltip
3131
Tooltip (1,:) string
32-
33-
% Grid
34-
Grid (1,1) matlab.ui.container.GridLayout
3532

3633
% Tag
3734
ButtonTag (1,:) string
@@ -66,6 +63,9 @@
6663

6764
% Buttons (other widgets like ListSelector also access this)
6865
Button (1,:) matlab.ui.control.Button
66+
67+
% Grid
68+
Grid (1,1) matlab.ui.container.GridLayout
6969

7070
end %properties
7171

@@ -173,6 +173,14 @@ function onButtonPushed(obj,evt)
173173
notify(obj,"ButtonPushed",evtOut);
174174

175175
end %function
176+
177+
function propGroups = getPropertyGroups(obj)
178+
% Override the ComponentContainer GetPropertyGroups with newly
179+
% customiziable mixin. This can probably also be specific to each control.
180+
181+
propGroups = [email protected](obj);
182+
183+
end
176184

177185
end %methods
178186

widgets/+wt/CheckboxList.m

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
classdef CheckboxList < matlab.ui.componentcontainer.ComponentContainer & ...
22
wt.mixin.Enableable & wt.mixin.FontStyled & wt.mixin.Tooltipable & ...
3-
wt.mixin.BackgroundColorable
3+
wt.mixin.BackgroundColorable & wt.mixin.PropertyViewable
44

55

66
% A checkbox list
@@ -86,7 +86,7 @@ function setup(obj)
8686
obj.Grid.Scrollable = true;
8787

8888
% Default background to Control Color
89-
obj.BackgroundColor = [0.94 0.94 0.94];
89+
obj.BackgroundColor = [1 1 1];
9090

9191
% Create the Select All checkbox
9292
obj.AllCheck = matlab.ui.control.CheckBox(...
@@ -156,8 +156,16 @@ function update(obj)
156156
end
157157

158158
end %function
159-
160-
159+
160+
function propGroups = getPropertyGroups(obj)
161+
% Override the ComponentContainer GetPropertyGroups with newly
162+
% customiziable mixin. This can probably also be specific to each control.
163+
164+
propGroups = [email protected](obj);
165+
166+
end
167+
168+
161169
function updateFontStyledComponents(obj,varargin)
162170

163171
% Call superclass method first

widgets/+wt/ColorSelector.m

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
classdef ColorSelector < matlab.ui.componentcontainer.ComponentContainer & ...
22
wt.mixin.Enableable & wt.mixin.FontStyled & wt.mixin.Tooltipable & ...
3-
wt.mixin.FieldColorable
3+
wt.mixin.FieldColorable & wt.mixin.PropertyViewable
44
% A color selection control with browse button
55

66
% Copyright 2020-2022 The MathWorks Inc.
@@ -62,7 +62,7 @@ function setup(obj)
6262
obj.Grid.RowHeight = {'1x'};
6363
obj.Grid.RowSpacing = 2;
6464
obj.Grid.ColumnSpacing = 2;
65-
obj.Grid.Padding = 2;
65+
obj.Grid.Padding = 0;
6666

6767
% Set default size
6868
obj.Position(3:4) = [100 25];
@@ -100,6 +100,15 @@ function update(obj)
100100
obj.ButtonControl.BackgroundColor = obj.Value;
101101

102102
end %function
103+
104+
105+
function propGroups = getPropertyGroups(obj)
106+
% Override the ComponentContainer GetPropertyGroups with newly
107+
% customiziable mixin. This can probably also be specific to each control.
108+
109+
propGroups = [email protected](obj);
110+
111+
end %function
103112

104113

105114
function updateFieldVisibility(obj)

widgets/+wt/DatetimeSelector.m

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
classdef DatetimeSelector < matlab.ui.componentcontainer.ComponentContainer & ...
2-
wt.mixin.Enableable & wt.mixin.FontStyled & wt.mixin.FieldColorable
2+
wt.mixin.Enableable & wt.mixin.FontStyled & wt.mixin.FieldColorable & ...
3+
wt.mixin.PropertyViewable
34
% A date and time selection control
45

56
% Copyright 2022 The MathWorks Inc.
@@ -92,7 +93,7 @@ function setup(obj)
9293
obj.Grid.RowHeight = {'1x'};
9394
obj.Grid.RowSpacing = 2;
9495
obj.Grid.ColumnSpacing = 2;
95-
obj.Grid.Padding = 2;
96+
obj.Grid.Padding = 0;
9697

9798
% Configure Grid
9899
obj.Grid.ColumnWidth = {'9x',5,'4x','4x',0,0};
@@ -214,6 +215,15 @@ function update(obj)
214215
end %function
215216

216217

218+
function propGroups = getPropertyGroups(obj)
219+
% Override the ComponentContainer GetPropertyGroups with newly
220+
% customiziable mixin. This can probably also be specific to each control.
221+
222+
propGroups = [email protected](obj);
223+
224+
end %function
225+
226+
217227
function onDateEdited(obj,evt)
218228
% Triggered on edits
219229

widgets/+wt/FileSelector.m

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
classdef FileSelector < matlab.ui.componentcontainer.ComponentContainer & ...
22
wt.mixin.ErrorHandling & ...
33
wt.mixin.Enableable & wt.mixin.FontStyled & wt.mixin.Tooltipable &...
4-
wt.mixin.FieldColorable & wt.mixin.ButtonColorable
4+
wt.mixin.FieldColorable & wt.mixin.ButtonColorable & ...
5+
wt.mixin.PropertyViewable
56
% A file/folder selection control with browse button
67

78
% Copyright 2020-2022 The MathWorks Inc.
@@ -101,7 +102,7 @@ function setup(obj)
101102
obj.Grid.RowHeight = {'1x'};
102103
obj.Grid.RowSpacing = 2;
103104
obj.Grid.ColumnSpacing = 2;
104-
obj.Grid.Padding = 2;
105+
obj.Grid.Padding = 0;
105106

106107
% Configure Grid
107108
obj.Grid.ColumnWidth = {'1x',25};
@@ -167,6 +168,15 @@ function update(obj)
167168
end %function
168169

169170

171+
function propGroups = getPropertyGroups(obj)
172+
% Override the ComponentContainer GetPropertyGroups with newly
173+
% customiziable mixin. This can probably also be specific to each control.
174+
175+
propGroups = [email protected](obj);
176+
177+
end %function
178+
179+
170180
function updateButtonIcon(obj)
171181

172182
% Update the button icon

widgets/+wt/ListSelector.m

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
classdef ListSelector < matlab.ui.componentcontainer.ComponentContainer & ...
22
wt.mixin.BackgroundColorable & wt.mixin.Enableable &...
33
wt.mixin.FontStyled & wt.mixin.ButtonColorable &...
4-
wt.mixin.FieldColorable
4+
wt.mixin.FieldColorable & wt.mixin.PropertyViewable
55

66
% Select from an array of items and add them to a list
77

@@ -110,7 +110,7 @@ function setup(obj)
110110
obj.Grid.RowHeight = {'1x'};
111111
obj.Grid.RowSpacing = 2;
112112
obj.Grid.ColumnSpacing = 2;
113-
obj.Grid.Padding = 2;
113+
obj.Grid.Padding = 0;
114114

115115
% Set default size
116116
obj.Position(3:4) = [120 130];
@@ -170,6 +170,15 @@ function update(obj)
170170
obj.updateEnables();
171171

172172
end %function
173+
174+
175+
function propGroups = getPropertyGroups(obj)
176+
% Override the ComponentContainer GetPropertyGroups with newly
177+
% customiziable mixin. This can probably also be specific to each control.
178+
179+
propGroups = [email protected](obj);
180+
181+
end %function
173182

174183

175184
function updateEnables(obj)

widgets/+wt/ListSelectorTwoPane.m

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
classdef ListSelectorTwoPane < matlab.ui.componentcontainer.ComponentContainer & ...
22
wt.mixin.Enableable &...
33
wt.mixin.FontStyled & wt.mixin.ButtonColorable &...
4-
wt.mixin.FieldColorable & wt.mixin.BackgroundColorable
4+
wt.mixin.FieldColorable & wt.mixin.BackgroundColorable & ...
5+
wt.mixin.PropertyViewable
56

67
% Select from an array of items and add them to a list
78

@@ -106,7 +107,7 @@ function setup(obj)
106107
obj.Grid.RowHeight = {'1x'};
107108
obj.Grid.RowSpacing = 2;
108109
obj.Grid.ColumnSpacing = 2;
109-
obj.Grid.Padding = 2;
110+
obj.Grid.Padding = 0;
110111

111112
% Set default size
112113
obj.Position(3:4) = [200 160];
@@ -193,7 +194,15 @@ function update(obj)
193194

194195
end %function
195196

196-
197+
function propGroups = getPropertyGroups(obj)
198+
% Override the ComponentContainer GetPropertyGroups with newly
199+
% customiziable mixin. This can probably also be specific to each control.
200+
201+
propGroups = [email protected](obj);
202+
203+
end %function
204+
205+
197206
function updateEnables(obj)
198207

199208
% Button enables

widgets/+wt/PasswordField.m

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
classdef PasswordField < matlab.ui.componentcontainer.ComponentContainer & ...
2-
wt.mixin.BackgroundColorable
2+
wt.mixin.BackgroundColorable & wt.mixin.PropertyViewable
33

44
% A password entry field
55

@@ -50,7 +50,7 @@ function setup(obj)
5050
obj.Grid.RowHeight = {'1x'};
5151
obj.Grid.RowSpacing = 2;
5252
obj.Grid.ColumnSpacing = 2;
53-
obj.Grid.Padding = 2;
53+
obj.Grid.Padding = 0;
5454

5555
% Establish Background Color Listener
5656
obj.BackgroundColorableComponents = obj.Grid;
@@ -91,6 +91,14 @@ function update(obj)
9191

9292
end %function
9393

94+
function propGroups = getPropertyGroups(obj)
95+
% Override the ComponentContainer GetPropertyGroups with newly
96+
% customiziable mixin. This can probably also be specific to each control.
97+
98+
propGroups = [email protected](obj);
99+
100+
end % function
101+
94102
% function updateBackgroundColorableComponents(obj)
95103
% % Override Default BGC Update with Additional Components
96104
% obj.Grid.BackgroundColor = obj.BackgroundColor;

widgets/+wt/ProgressBar.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
classdef ProgressBar < matlab.ui.componentcontainer.ComponentContainer & ...
2-
wt.mixin.FontStyled
2+
wt.mixin.FontStyled & wt.mixin.PropertyViewable
33

44
% A progress bar with status and cancel button
55

@@ -341,6 +341,14 @@ function update(obj)
341341
obj.Grid.ColumnWidth = colWidths;
342342

343343
end %function
344+
345+
function propGroups = getPropertyGroups(obj)
346+
% Override the ComponentContainer GetPropertyGroups with newly
347+
% customiziable mixin. This can probably also be specific to each control.
348+
349+
propGroups = [email protected](obj);
350+
351+
end % function
344352

345353
end %methods
346354

0 commit comments

Comments
 (0)