Skip to content

Commit 5546685

Browse files
authored
Merge pull request #161 from mathworks/157-titlefontstyled-mixin-should-prioritize-properties-beginning-with-title-first-to-allow-propagating-down-a-hierarchy
157 titlefontstyled mixin should prioritize properties beginning with title first to allow propagating down a hierarchy
2 parents 0dc7317 + b18f0dd commit 5546685

File tree

4 files changed

+140
-104
lines changed

4 files changed

+140
-104
lines changed

test/+wt/+test/PasswordField.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ function testValue(testCase)
4141

4242

4343
function testTyping(testCase)
44+
45+
testCase.assumeMinimumRelease("R2024a")
4446

4547
% Running in desktop mode?
4648
testCase.assumeEqual(exist('desktop', 'file'), 6, 'Cannot find function ''desktop.m''.')
Lines changed: 122 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,217 +1,243 @@
11
classdef TitleFontStyled < handle
22
% Mixin for component with Font properties
3-
3+
44
% Copyright 2020-2025 The MathWorks Inc.
5-
6-
5+
6+
77
%% Properties
88
properties (AbortSet)
9-
9+
1010
% Font name
1111
TitleFontName char {mustBeNonempty} = 'Helvetica'
12-
12+
1313
% Font size in points
1414
TitleFontSize (1,1) double {mustBePositive,mustBeFinite} = 14
15-
15+
1616
% Font weight (normal/bold)
1717
TitleFontWeight (1,1) wt.enum.FontWeightState = 'bold'
18-
18+
1919
% Font angle (normal/italic)
2020
TitleFontAngle (1,1) wt.enum.FontAngleState = 'normal'
21-
21+
2222
end %properties
23-
24-
23+
24+
2525
properties (AbortSet, Dependent)
26-
26+
2727
% Font Color
2828
TitleColor (1,3) double {mustBeInRange(TitleColor,0,1)}
29-
29+
3030
end %properties
31-
32-
31+
32+
3333
properties (AbortSet, NeverAmbiguous)
34-
34+
3535
% Font color mode
3636
TitleColorMode (1,1) wt.enum.AutoManualState = 'auto'
37-
37+
3838
end %properties
39-
40-
39+
40+
4141
%% Internal properties
4242
properties (AbortSet, Hidden)
43-
43+
4444
% Font Color
4545
TitleColor_I (1,3) double {mustBeInRange(TitleColor_I,0,1)} = [0.38 0.38 0.38];
46-
46+
4747
end %properties
48-
49-
48+
49+
5050
properties (AbortSet, Transient, NonCopyable, Hidden, SetAccess = protected)
51-
51+
5252
% List of graphics controls to apply to
5353
TitleFontStyledComponents (:,1) matlab.graphics.Graphics
54-
54+
5555
end %properties
56-
57-
56+
57+
5858
properties (Transient, NonCopyable, Access = private)
59-
59+
6060
% Listener for theme changes
6161
ThemeChangedListener event.listener
62-
62+
6363
end %properties
64-
65-
64+
65+
6666
%% Property Accessors
67-
67+
6868
methods
69-
69+
7070
function set.TitleFontName(obj,value)
7171
obj.TitleFontName = value;
7272
obj.updateTitleFontStyledComponents("FontName",value)
7373
end
74-
74+
7575
function set.TitleFontSize(obj,value)
7676
obj.TitleFontSize = value;
7777
obj.updateTitleFontStyledComponents("FontSize",value)
7878
end
79-
79+
8080
function set.TitleFontWeight(obj,value)
8181
obj.TitleFontWeight = value;
8282
obj.updateTitleFontStyledComponents("FontWeight",value)
8383
end
84-
84+
8585
function set.TitleFontAngle(obj,value)
8686
obj.TitleFontAngle = value;
8787
obj.updateTitleFontStyledComponents("FontAngle",value)
8888
end
89-
89+
9090
function value = get.TitleColor(obj)
9191
value = obj.TitleColor_I;
9292
end
93-
93+
9494
function set.TitleColor(obj, value)
9595
obj.TitleColorMode = 'manual';
9696
obj.TitleColor_I = value;
9797
end
98-
98+
9999
function set.TitleColorMode(obj, value)
100100
obj.TitleColorMode = value;
101101
obj.applyTheme();
102102
end
103-
103+
104104
function set.TitleColor_I(obj,value)
105105
obj.TitleColor_I = value;
106106
obj.updateTitleFontStyledComponents("FontColor", obj.TitleColor_I);
107107
end
108-
108+
109109
function set.TitleFontStyledComponents(obj,value)
110110
obj.TitleFontStyledComponents = value;
111111
obj.applyTheme();
112112
obj.updateTitleFontStyledComponents()
113113
end
114-
114+
115115
end %methods
116-
117-
116+
117+
118118
%% Constructor
119119
methods
120-
120+
121121
function obj = TitleFontStyled()
122-
122+
123123
% Confirm BaseWidget and R2025a or newer
124124
if matches("WidgetThemeChanged", events(obj)) ...
125125
&& ~isMATLABReleaseOlderThan("R2025a")
126-
126+
127127
% Listen to theme changes
128128
obj.ThemeChangedListener = ...
129129
listener(obj, "WidgetThemeChanged", @(~,~)applyTheme(obj));
130-
130+
131131
end %if
132-
132+
133133
end %function
134-
134+
135135
end %methods
136-
137-
136+
137+
138138
%% Protected Methods
139139
methods (Access = protected)
140-
140+
141141
function updateTitleFontStyledComponents(obj,prop,value)
142-
142+
143143
% Get the components
144144
comps = obj.TitleFontStyledComponents;
145-
146-
% Font color properties in prioritized order
147-
colorProps = ["TitleColor","FontColor","ForegroundColor"];
148-
145+
149146
% Updating all or a specific property?
150147
if nargin < 3
151-
152-
% Set all subcomponent properties
153-
wt.utility.setStylePropsInPriority(comps,"FontName",obj.TitleFontName)
154-
wt.utility.setStylePropsInPriority(comps,"FontSize",obj.TitleFontSize)
155-
wt.utility.setStylePropsInPriority(comps,"FontWeight",obj.TitleFontWeight)
156-
wt.utility.setStylePropsInPriority(comps,"FontAngle",obj.TitleFontAngle)
157-
wt.utility.setStylePropsInPriority(comps,colorProps, obj.TitleColor_I);
158-
159-
elseif prop == "FontColor"
160-
% Update just the FontColor property
161-
162-
% Set the subcomponent property
163-
wt.utility.setStylePropsInPriority(comps, colorProps, value);
164-
165-
else
166-
167-
% Set the subcomponent property
168-
wt.utility.setStylePropsInPriority(comps, prop, value);
169-
170-
end %if
171-
148+
prop = "";
149+
end
150+
151+
switch prop
152+
153+
case "TitleFontName"
154+
155+
wt.utility.setStylePropsInPriority(comps,...
156+
["TitleFontName","FontName"], value);
157+
158+
case "TitleFontSize"
159+
160+
wt.utility.setStylePropsInPriority(comps,...
161+
["TitleFontSize","FontSize"], value);
162+
163+
case "TitleFontWeight"
164+
165+
wt.utility.setStylePropsInPriority(comps,...
166+
["TitleFontWeight","FontWeight"], value);
167+
168+
case "TitleFontAngle"
169+
170+
wt.utility.setStylePropsInPriority(comps,...
171+
["TitleFontAngle","FontAngle"], value);
172+
173+
case "TitleColor"
174+
175+
wt.utility.setStylePropsInPriority(comps,...
176+
["TitleColor","FontColor","ForegroundColor"], value);
177+
178+
otherwise
179+
180+
% Set all subcomponent properties
181+
wt.utility.setStylePropsInPriority(comps,...
182+
["TitleFontName","FontName"],obj.TitleFontName)
183+
184+
wt.utility.setStylePropsInPriority(comps,...
185+
["TitleFontSize","FontSize"],obj.TitleFontSize)
186+
187+
wt.utility.setStylePropsInPriority(comps,...
188+
["TitleFontWeight","FontWeight"],obj.TitleFontWeight)
189+
190+
wt.utility.setStylePropsInPriority(comps,...
191+
["TitleFontAngle","FontAngle"],obj.TitleFontAngle)
192+
193+
wt.utility.setStylePropsInPriority(comps,...
194+
["TitleColor","FontColor","ForegroundColor"], obj.TitleColor_I);
195+
196+
end %switch
197+
172198
end %function
173-
174-
199+
200+
175201
function color = getDefaultTitleColor(obj)
176202
% Returns the default color for 'auto' mode (R2025a and later)
177203
% The result is dependent on theme
178204
% Widget subclass may override this
179-
205+
180206
try
181207
color = obj.getThemeColor("--mw-color-secondary"); %#ok<MCNPN>
182-
208+
183209
catch exception
184-
210+
185211
color = obj.TitleColor_I;
186-
212+
187213
id = "wt:applyTheme:getThemeColorFail";
188214
msg = "Unable to get default theme color: %s";
189215
warning(id, msg, exception.message)
190-
216+
191217
end %try
192-
218+
193219
end %function
194-
220+
195221
end %methods
196-
197-
222+
223+
198224
%% Private Methods
199225
methods (Access = private)
200-
226+
201227
function applyTheme(obj)
202-
228+
203229
% If color mode is auto, use standard theme color
204230
if obj.TitleColorMode == "auto" ...
205231
&& ~isMATLABReleaseOlderThan("R2025a")
206-
232+
207233
% Use standard theme color
208234
obj.TitleColor_I = obj.getDefaultTitleColor();
209235

210236
end %if
211-
237+
212238
end %function
213-
239+
214240
end %methods
215-
216-
241+
242+
217243
end %classdef

0 commit comments

Comments
 (0)