|
2 | 2 | % Mixin for component with colorable background |
3 | 3 | % |
4 | 4 |
|
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. |
16 | 6 |
|
17 | 7 |
|
18 | 8 | %% Internal properties |
19 | 9 | properties (AbortSet, Transient, NonCopyable, ... |
20 | | - Access = {?wt.abstract.BaseWidget, ?wt.test.BaseWidgetTest} ) |
| 10 | + Access = {?matlab.ui.componentcontainer.ComponentContainer}) |
21 | 11 |
|
22 | 12 | % List of graphics controls to apply to |
23 | 13 | BackgroundColorableComponents (:,1) matlab.graphics.Graphics |
24 | 14 |
|
| 15 | + BackgroundColorListener event.proplistener |
| 16 | + |
25 | 17 | end %properties |
26 | 18 |
|
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 | + |
45 | 20 |
|
46 | 21 | %% Methods |
47 | 22 | methods (Access = protected) |
48 | 23 |
|
49 | 24 | function updateBackgroundColorableComponents(obj) |
50 | | - |
| 25 | + |
51 | 26 | hasProp = isprop(obj.BackgroundColorableComponents,'BackgroundColor'); |
52 | 27 | wt.utility.fastSet(obj.BackgroundColorableComponents(hasProp),... |
53 | | - "BackgroundColor",obj.BackgroundColor); |
| 28 | + "BackgroundColor",obj.BackgroundColor); %#ok<MCNPN> |
54 | 29 |
|
55 | 30 | 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 |
56 | 56 |
|
57 | 57 | end %methods |
58 | 58 |
|
|
0 commit comments