Skip to content

Commit ed0bf6c

Browse files
rjackeyrjackey
authored andcommitted
#48, work on updating all property mixins
1 parent 8fe35e7 commit ed0bf6c

File tree

11 files changed

+273
-195
lines changed

11 files changed

+273
-195
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info>
3+
<Category UUID="FileClassCategory">
4+
<Label UUID="design"/>
5+
</Category>
6+
</Info>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info location="setStylePropsInPriority.m" type="File"/>
Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,47 @@
11
classdef BackgroundColorable < handle
2-
3-
% Mixin for component with colorable background
2+
% Mixin to add styles to a component
3+
4+
% Copyright 2020-2023 The MathWorks Inc.
5+
46

5-
% Copyright 2020-2022 The MathWorks Inc.
6-
7-
87
%% Internal properties
9-
properties (AbortSet, Transient, NonCopyable, ...
10-
Access = {?matlab.ui.componentcontainer.ComponentContainer})
11-
8+
properties (AbortSet, Transient, NonCopyable, Hidden, SetAccess = protected)
9+
1210
% List of graphics controls to apply to
1311
BackgroundColorableComponents (:,1) matlab.graphics.Graphics
14-
12+
13+
% Listener to background color changes
1514
BackgroundColorListener event.proplistener
1615

1716
end %properties
18-
19-
20-
17+
18+
19+
%% Accessors
20+
methods
21+
22+
function set.BackgroundColorableComponents(obj,value)
23+
obj.BackgroundColorableComponents = value;
24+
obj.updateBackgroundColorableComponents()
25+
obj.listenForBackgroundChange();
26+
end
27+
28+
end %methods
29+
30+
31+
2132
%% Methods
2233
methods (Access = protected)
23-
34+
2435
function updateBackgroundColorableComponents(obj)
25-
26-
hasProp = isprop(obj.BackgroundColorableComponents,'BackgroundColor');
27-
wt.utility.fastSet(obj.BackgroundColorableComponents(hasProp),...
28-
"BackgroundColor",obj.BackgroundColor); %#ok<MCNPN>
29-
36+
37+
% What needs to be updated?
38+
comps = obj.BackgroundColorableComponents;
39+
newValue = obj.BackgroundColor; %#ok<MCNPN>
40+
propNames = ["BackgroundColor","Color"];
41+
42+
% Set the subcomponent properties in prioritized order
43+
wt.utility.setStylePropsInPriority(comps, propNames, newValue);
44+
3045
end %function
3146

3247

@@ -42,18 +57,5 @@ function listenForBackgroundChange(obj)
4257
end %function
4358

4459
end %methods
45-
46-
4760

48-
%% Accessors
49-
methods
50-
51-
function set.BackgroundColorableComponents(obj,value)
52-
obj.BackgroundColorableComponents = value;
53-
obj.listenForBackgroundChange();
54-
obj.updateBackgroundColorableComponents()
55-
end
56-
57-
end %methods
58-
5961
end %classdef
Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,61 @@
11
classdef ButtonColorable < handle
2-
% Mixin for component with colorable button
3-
%
2+
% Mixin to add styles to a component
3+
4+
% Copyright 2020-2023 The MathWorks Inc.
5+
46

5-
% Copyright 2020-2021 The MathWorks Inc.
6-
7-
87
%% Properties
98
properties (AbortSet)
10-
9+
1110
% Button Color
1211
ButtonColor (1,3) double {wt.validators.mustBeBetweenZeroAndOne} = [1 1 1] * 0.96
13-
12+
1413
end %properties
15-
16-
17-
14+
15+
16+
1817
%% Internal properties
19-
properties (AbortSet, Transient, NonCopyable, ...
20-
Access = {?wt.abstract.BaseWidget, ?matlab.uitest.TestCase, ?matlab.ui.componentcontainer.ComponentContainer} )
21-
18+
properties (AbortSet, Transient, NonCopyable, Hidden, SetAccess = protected)
19+
2220
% List of graphics controls to apply to
2321
ButtonColorableComponents (:,1) matlab.graphics.Graphics
24-
22+
2523
end %properties
26-
27-
28-
24+
25+
26+
2927
%% Accessors
3028
methods
31-
29+
3230
function set.ButtonColor(obj,value)
3331
obj.ButtonColor = value;
3432
obj.updateButtonColorableComponents()
3533
end
36-
34+
3735
function set.ButtonColorableComponents(obj,value)
3836
obj.ButtonColorableComponents = value;
3937
obj.updateButtonColorableComponents()
4038
end
41-
39+
4240
end %methods
43-
44-
45-
41+
42+
43+
4644
%% Methods
4745
methods (Access = protected)
48-
46+
4947
function updateButtonColorableComponents(obj)
50-
51-
% If the component has ButtonColor, use that. Otherwise, use
52-
% BackgroundColor.
53-
hasProp = isprop(obj.ButtonColorableComponents,'ButtonColor');
54-
wt.utility.fastSet(obj.ButtonColorableComponents(hasProp),...
55-
"ButtonColor",obj.ButtonColor);
56-
wt.utility.fastSet(obj.ButtonColorableComponents(~hasProp),...
57-
"BackgroundColor",obj.ButtonColor);
58-
48+
49+
% What needs to be updated?
50+
comps = obj.ButtonColorableComponents;
51+
newValue = obj.ButtonColor;
52+
propNames = ["ButtonColor","BackgroundColor"];
53+
54+
% Set the subcomponent properties in prioritized order
55+
wt.utility.setStylePropsInPriority(comps, propNames, newValue);
56+
5957
end %function
60-
58+
6159
end %methods
62-
60+
6361
end %classdef

widgets/+wt/+mixin/Enableable.m

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
classdef Enableable < handle
2-
% Mixin for component with Enable property
2+
% Mixin to add styles to a component
33

4-
% Copyright 2020-2021 The MathWorks Inc.
4+
% Copyright 2020-2023 The MathWorks Inc.
55

66

77
%% Properties
@@ -15,9 +15,8 @@
1515

1616

1717
%% Internal properties
18-
properties (AbortSet, Transient, NonCopyable, ...
19-
Access = {?wt.abstract.BaseWidget, ?matlab.uitest.TestCase, ?matlab.ui.componentcontainer.ComponentContainer} )
20-
18+
properties (AbortSet, Transient, NonCopyable, Hidden, SetAccess = protected)
19+
2120
% List of graphics controls to apply to
2221
EnableableComponents (:,1) matlab.graphics.Graphics
2322

@@ -46,8 +45,14 @@
4645
methods (Access = protected)
4746

4847
function updateEnableableComponents(obj)
49-
50-
wt.utility.fastSet(obj.EnableableComponents,"Enable",obj.Enable);
48+
49+
% What needs to be updated?
50+
comps = obj.EnableableComponents;
51+
newValue = obj.Enable;
52+
propNames = "Enable";
53+
54+
% Set the subcomponent properties in prioritized order
55+
wt.utility.setStylePropsInPriority(comps, propNames, newValue);
5156

5257
end %function
5358

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,61 @@
11
classdef FieldColorable < handle
2-
% Mixin for component with colorable text field
2+
% Mixin to add styles to a component
3+
4+
% Copyright 2020-2023 The MathWorks Inc.
5+
36

4-
% Copyright 2020-2021 The MathWorks Inc.
5-
67
%% Properties
78
properties (AbortSet)
8-
9+
910
% Field Color
1011
FieldColor (1,3) double {wt.validators.mustBeBetweenZeroAndOne} = [1 1 1]
11-
12+
1213
end %properties
13-
14-
15-
14+
15+
16+
1617
%% Internal properties
17-
properties (AbortSet, Transient, NonCopyable, ...
18-
Access = {?wt.abstract.BaseWidget, ?matlab.uitest.TestCase, ?matlab.ui.componentcontainer.ComponentContainer} )
19-
18+
properties (AbortSet, Transient, NonCopyable, Hidden, SetAccess = protected)
19+
2020
% List of graphics controls to apply to
2121
FieldColorableComponents (:,1) matlab.graphics.Graphics
22-
22+
2323
end %properties
24-
25-
26-
24+
25+
26+
2727
%% Accessors
2828
methods
29-
29+
3030
function set.FieldColor(obj,value)
3131
obj.FieldColor = value;
3232
obj.updateFieldColorableComponents()
3333
end
34-
34+
3535
function set.FieldColorableComponents(obj,value)
3636
obj.FieldColorableComponents = value;
3737
obj.updateFieldColorableComponents()
3838
end
39-
39+
4040
end %methods
41-
42-
43-
41+
42+
43+
4444
%% Methods
4545
methods (Access = protected)
46-
46+
4747
function updateFieldColorableComponents(obj)
48-
49-
wt.utility.fastSet(obj.FieldColorableComponents,"BackgroundColor",obj.FieldColor);
50-
48+
49+
% What needs to be updated?
50+
comps = obj.FieldColorableComponents;
51+
newValue = obj.FieldColor;
52+
propNames = ["FieldColor","BackgroundColor","Color"];
53+
54+
% Set the subcomponent properties in prioritized order
55+
wt.utility.setStylePropsInPriority(comps, propNames, newValue);
56+
5157
end %function
52-
58+
5359
end %methods
54-
60+
5561
end %classdef

0 commit comments

Comments
 (0)