Skip to content

Commit c426b06

Browse files
authored
Merge pull request #29 from mathworks/CodeCleanup_Issue28
Code cleanup issue28
2 parents f828222 + 5d158a0 commit c426b06

25 files changed

+525
-176
lines changed

widgets/+wt/+mixin/BackgroundColorable.m

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,57 @@
22
% Mixin for component with colorable background
33
%
44

5-
% Copyright 2020-2021 The MathWorks Inc.
6-
7-
8-
%% Properties
9-
properties (AbortSet, Abstract)
10-
11-
% Background Color
12-
BackgroundColor (1,3) double {wt.validators.mustBeBetweenZeroAndOne}
13-
14-
end %properties
15-
5+
% Copyright 2020-2022 The MathWorks Inc.
166

177

188
%% Internal properties
199
properties (AbortSet, Transient, NonCopyable, ...
20-
Access = {?wt.abstract.BaseWidget, ?wt.test.BaseWidgetTest} )
10+
Access = {?matlab.ui.componentcontainer.ComponentContainer})
2111

2212
% List of graphics controls to apply to
2313
BackgroundColorableComponents (:,1) matlab.graphics.Graphics
2414

15+
BackgroundColorListener event.proplistener
16+
2517
end %properties
2618

27-
28-
29-
%% Accessors
30-
methods
31-
32-
% function set.BackgroundColor(obj,value)
33-
% obj.BackgroundColor = value;
34-
% obj.updateBackgroundColorableComponents()
35-
% end
36-
37-
function set.BackgroundColorableComponents(obj,value)
38-
obj.BackgroundColorableComponents = value;
39-
obj.updateBackgroundColorableComponents()
40-
end
41-
42-
end %methods
43-
44-
19+
4520

4621
%% Methods
4722
methods (Access = protected)
4823

4924
function updateBackgroundColorableComponents(obj)
50-
25+
5126
hasProp = isprop(obj.BackgroundColorableComponents,'BackgroundColor');
5227
wt.utility.fastSet(obj.BackgroundColorableComponents(hasProp),...
53-
"BackgroundColor",obj.BackgroundColor);
28+
"BackgroundColor",obj.BackgroundColor); %#ok<MCNPN>
5429

5530
end %function
31+
32+
33+
function listenForBackgroundChange(obj)
34+
35+
% Establish Listener for Background Color Change
36+
if isempty(obj.BackgroundColorListener)
37+
obj.BackgroundColorListener = ...
38+
addlistener(obj,'BackgroundColor','PostSet',...
39+
@(h,e)obj.updateBackgroundColorableComponents());
40+
end
41+
42+
end %function
43+
44+
end %methods
45+
46+
47+
48+
%% Accessors
49+
methods
50+
51+
function set.BackgroundColorableComponents(obj,value)
52+
obj.BackgroundColorableComponents = value;
53+
obj.listenForBackgroundChange();
54+
obj.updateBackgroundColorableComponents()
55+
end
5656

5757
end %methods
5858

widgets/+wt/+mixin/ButtonColorable.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
%% Internal properties
1919
properties (AbortSet, Transient, NonCopyable, ...
20-
Access = {?wt.abstract.BaseWidget, ?wt.test.BaseWidgetTest} )
20+
Access = {?wt.abstract.BaseWidget, ?wt.test.BaseWidgetTest, ?matlab.ui.componentcontainer.ComponentContainer} )
2121

2222
% List of graphics controls to apply to
2323
ButtonColorableComponents (:,1) matlab.graphics.Graphics

widgets/+wt/+mixin/Enableable.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
%% Internal properties
1818
properties (AbortSet, Transient, NonCopyable, ...
19-
Access = {?wt.abstract.BaseWidget, ?wt.test.BaseWidgetTest} )
19+
Access = {?wt.abstract.BaseWidget, ?wt.test.BaseWidgetTest, ?matlab.ui.componentcontainer.ComponentContainer} )
2020

2121
% List of graphics controls to apply to
2222
EnableableComponents (:,1) matlab.graphics.Graphics

widgets/+wt/+mixin/FieldColorable.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
%% Internal properties
1717
properties (AbortSet, Transient, NonCopyable, ...
18-
Access = {?wt.abstract.BaseWidget, ?wt.test.BaseWidgetTest} )
18+
Access = {?wt.abstract.BaseWidget, ?wt.test.BaseWidgetTest, ?matlab.ui.componentcontainer.ComponentContainer} )
1919

2020
% List of graphics controls to apply to
2121
FieldColorableComponents (:,1) matlab.graphics.Graphics

widgets/+wt/+mixin/FontColorable.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
%% Internal properties
1818
properties (AbortSet, Transient, NonCopyable, ...
19-
Access = {?wt.abstract.BaseWidget, ?wt.test.BaseWidgetTest} )
19+
Access = {?wt.abstract.BaseWidget, ?wt.test.BaseWidgetTest, ?matlab.ui.componentcontainer.ComponentContainer} )
2020

2121
% List of graphics controls to apply to
2222
FontColorableComponents (:,1) matlab.graphics.Graphics

widgets/+wt/+mixin/FontStyled.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
%% Internal properties
3030
properties (AbortSet, Transient, NonCopyable, ...
31-
Access = {?wt.abstract.BaseWidget, ?wt.test.BaseWidgetTest} )
31+
Access = {?wt.abstract.BaseWidget, ?wt.test.BaseWidgetTest, ?matlab.ui.componentcontainer.ComponentContainer} )
3232

3333
% List of graphics controls to apply to
3434
FontStyledComponents (:,1) matlab.graphics.Graphics

widgets/+wt/+mixin/GridOrganized.m

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
classdef GridOrganized < handle
2+
% Mixin for component to be organized within a 1x1 UIGridLayout
3+
%
4+
5+
% Copyright 2020-2022 The MathWorks Inc.
6+
7+
%% Properties
8+
properties (AbortSet, Transient, NonCopyable)
9+
10+
% GridLayout
11+
Grid (1,1) matlab.ui.container.GridLayout
12+
13+
end
14+
15+
16+
%% Accessors
17+
methods (Access = protected)
18+
19+
function establishGrid(obj)
20+
21+
% Construct Grid Layout to Manage Building Blocks
22+
obj.Grid = uigridlayout(obj);
23+
obj.Grid.ColumnWidth = {'1x'};
24+
obj.Grid.RowHeight = {'1x'};
25+
obj.Grid.RowSpacing = 2;
26+
obj.Grid.ColumnSpacing = 2;
27+
obj.Grid.Padding = 2;
28+
29+
end
30+
31+
end
32+
end
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/+mixin/TitleColorable.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
%% Internal properties
1818
properties (AbortSet, Transient, NonCopyable, ...
19-
Access = {?wt.abstract.BaseWidget, ?wt.test.BaseWidgetTest} )
19+
Access = {?wt.abstract.BaseWidget, ?wt.test.BaseWidgetTest, ?matlab.ui.componentcontainer.ComponentContainer} )
2020

2121
% List of graphics controls to apply to
2222
TitleColorableComponents (:,1) matlab.graphics.Graphics

widgets/+wt/+mixin/Tooltipable.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
%% Internal properties
1818
properties (AbortSet, Transient, NonCopyable, ...
19-
Access = {?wt.abstract.BaseWidget, ?wt.test.BaseWidgetTest} )
19+
Access = {?wt.abstract.BaseWidget, ?wt.test.BaseWidgetTest, ?matlab.ui.componentcontainer.ComponentContainer} )
2020

2121
% List of graphics controls to apply to
2222
TooltipableComponents (:,1) matlab.graphics.Graphics

0 commit comments

Comments
 (0)