77 % Copyright 2020-2025 The MathWorks, Inc.
88
99
10+ %% Events
11+ events (ListenAccess = public )
12+
13+ % Triggered after the figure's theme has changed
14+ WidgetThemeChanged
15+
16+ end % event
17+
18+
1019 %% Properties
1120 properties (AbortSet )
1221
3342 % Position of the app window
3443 Position
3544
45+ % Theme of the app window
46+ Theme
47+
3648 % Visibility of the app window
3749 Visible
3850
6981 end
7082
7183
84+ function value = get .Theme(app )
85+ value = app .Figure.Theme;
86+ end
87+
88+ function set .Theme(app ,value )
89+ app.Figure.Theme = value ;
90+ end
91+
92+
7293 function value = get .Visible(app )
7394 value = app .Figure.Visible;
7495 end
113134 end % properties
114135
115136
137+ properties (Transient , NonCopyable , Access = private )
138+
139+ % Listener for theme changes
140+ InternalThemeChangedListener event.listener
141+
142+ end % properties
143+
144+
116145
117146 %% Abstract methods (subclass must implement these)
118147 methods (Abstract , Access = protected )
@@ -162,6 +191,12 @@ function forceUpdate(app)
162191 ' CloseRequestFcn' ,@(h ,e )close(app ), ...
163192 ' Visible' ,' off' );
164193
194+ % Listen to theme changes (R2025a and later only)
195+ if ~isMATLABReleaseOlderThan(" R2025a" )
196+ app.InternalThemeChangedListener = listener(app .Figure," ThemeChanged" ,...
197+ @(~,evt )onThemeChanged_I(app ));
198+ end
199+
165200 % Create MainGridLayout
166201 app.Grid = uigridlayout(app .Figure,[1 1 ]);
167202 app.Grid.Padding = [0 0 0 0 ];
@@ -494,6 +529,33 @@ function updateTitle(app)
494529 end % methods
495530
496531
532+ %% Hidden Methods
533+ methods (Hidden , Sealed )
534+
535+ function color = getThemeColor(app , semanticColorId )
536+ % Get color from theme and semantic variable
537+
538+ msg = " MATLAB R2025a or later is needed to call wt.apps.BaseApp.getThemeColor()." ;
539+ assert(~isMATLABReleaseOlderThan(" R2025a" ), msg )
540+
541+ % Get the theme
542+ try
543+ theme = app .Figure.Theme;
544+ catch exception
545+ theme = matlab .graphics.theme.GraphicsTheme();
546+ end
547+
548+ % Get theme from semantic variable
549+ % This is undocumented and may change. Better to call the
550+ % getThemeColor method rather than reusing this directly.
551+ color = matlab .graphics.internal.themes.getAttributeValue(...
552+ theme , semanticColorId );
553+
554+ end % function
555+
556+ end % methods
557+
558+
497559 %% Private methods
498560 methods (Access = private )
499561
@@ -520,6 +582,14 @@ function updateTitle(app)
520582
521583 end % function
522584
585+
586+ function onThemeChanged_I(app )
587+ % Handle theme changes
588+
589+ notify(app ," WidgetThemeChanged" )
590+
591+ end % function
592+
523593 end % methods
524594
525595
0 commit comments