Skip to content

Commit 585078b

Browse files
committed
tweaks to BackgroundColorable, GridOrganized, and SliderSpinner
1 parent a34a1fe commit 585078b

File tree

3 files changed

+34
-49
lines changed

3 files changed

+34
-49
lines changed

widgets/+wt/+mixin/BackgroundColorable.m

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,7 @@
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-
Access = {?matlab.ui.componentcontainer.ComponentContainer})
11-
12-
%BackgroundColor (1,3) double {wt.validators.mustBeBetweenZeroAndOne}
13-
14-
15-
end %properties
16-
5+
% Copyright 2020-2022 The MathWorks Inc.
176

187

198
%% Internal properties
@@ -23,51 +12,47 @@
2312
% List of graphics controls to apply to
2413
BackgroundColorableComponents (:,1) matlab.graphics.Graphics
2514

15+
BackgroundColorListener event.proplistener
16+
2617
end %properties
2718

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

4721
%% Methods
4822
methods (Access = protected)
4923

5024
function updateBackgroundColorableComponents(obj)
5125

52-
5326
hasProp = isprop(obj.BackgroundColorableComponents,'BackgroundColor');
5427
wt.utility.fastSet(obj.BackgroundColorableComponents(hasProp),...
55-
"BackgroundColor",obj.BackgroundColor);
28+
"BackgroundColor",obj.BackgroundColor); %#ok<MCNPN>
5629

5730
end %function
5831

5932

6033
function listenForBackgroundChange(obj)
6134

6235
% Establish Listener for Background Color Change
63-
addlistener(obj,'BackgroundColor','PostSet',...
64-
@(h,e)obj.updateBackgroundColorableComponents());
36+
if isempty(obj.BackgroundColorListener)
37+
obj.BackgroundColorListener = ...
38+
addlistener(obj,'BackgroundColor','PostSet',...
39+
@(h,e)obj.updateBackgroundColorableComponents());
40+
end
6541

66-
end
42+
end %function
43+
44+
end %methods
45+
6746

68-
6947

48+
%% Accessors
49+
methods
7050

51+
function set.BackgroundColorableComponents(obj,value)
52+
obj.BackgroundColorableComponents = value;
53+
obj.listenForBackgroundChange();
54+
obj.updateBackgroundColorableComponents()
55+
end
7156

7257
end %methods
7358

widgets/+wt/+mixin/GridOrganized.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
classdef GridOrganized < handle
22
% Mixin for component to be organized within a 1x1 UIGridLayout
33
%
4+
5+
% Copyright 2020-2022 The MathWorks Inc.
46

57
%% Properties
68
properties (AbortSet, Transient, NonCopyable)

widgets/+wt/SliderSpinner.m

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
classdef SliderSpinner < matlab.ui.componentcontainer.ComponentContainer & ...
2-
wt.mixin.ErrorHandling & wt.mixin.GridOrganized &...
32
wt.mixin.Enableable & wt.mixin.FontStyled &...
43
wt.mixin.FieldColorable & wt.mixin.BackgroundColorable
54
% A slider and spinner combination
65

7-
% Copyright 2020-2021 The MathWorks Inc.
6+
% Copyright 2020-2022 The MathWorks Inc.
87

98

109
%% Public properties
@@ -71,8 +70,11 @@
7170

7271
%% Internal Properties
7372
properties ( Transient, NonCopyable, ...
74-
Access = {?wt.abstract.BaseWidget, ?wt.test.BaseWidgetTest, ?matlab.ui.componentcontainer.ComponentContainer} )
73+
Access = {?wt.test.BaseWidgetTest, ?matlab.ui.componentcontainer.ComponentContainer} )
7574

75+
% Grid Layout
76+
Grid (1,1) matlab.ui.container.GridLayout
77+
7678
% Slider
7779
Slider (1,1) matlab.ui.control.Slider
7880

@@ -88,20 +90,15 @@
8890

8991
function setup(obj)
9092

91-
% Establish Grid for Control
92-
obj.establishGrid();
93-
94-
% Establish Background Color Listener
95-
obj.BackgroundColorableComponents = obj.Grid;
96-
obj.listenForBackgroundChange();
97-
9893
% Set default size
9994
obj.Position(3:4) = [200 40];
10095

101-
% Configure Main Grid
102-
obj.Grid.Padding = 2;
103-
obj.Grid.ColumnSpacing = 5;
96+
% Construct Grid Layout to Manage Building Blocks
97+
obj.Grid = uigridlayout(obj,[1 2]);
10498
obj.Grid.ColumnWidth = {'1x',75};
99+
obj.Grid.ColumnSpacing = 5;
100+
obj.Grid.RowHeight = {'1x'};
101+
obj.Grid.Padding = [0 0 0 0];
105102

106103
% Slider
107104
obj.Slider = uislider(obj.Grid);
@@ -116,6 +113,7 @@ function setup(obj)
116113
obj.Spinner.Limits = [0 100];
117114

118115
% Update the internal component lists
116+
obj.BackgroundColorableComponents = obj.Grid;
119117
obj.FontStyledComponents = [obj.Spinner, obj.Slider];
120118
obj.EnableableComponents = [obj.Spinner, obj.Slider];
121119
obj.FieldColorableComponents = [obj.Spinner];

0 commit comments

Comments
 (0)