Skip to content

Commit 54f37fa

Browse files
authored
Merge pull request #193 from mathworks/192-buttongrid-update-errors-if-there-are-zero-buttons
fixes #192 ButtonGrid update errors if there are zero buttons
2 parents de6905d + fe44c87 commit 54f37fa

6 files changed

Lines changed: 80 additions & 9 deletions

File tree

.github/workflows/git-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
platform: [ubuntu-latest, windows-latest]
1818

1919
# List of MATLAB releases over which to run the tests.
20-
matlab-version: [R2023b, R2024a, R2024b, latest]
20+
matlab-version: [R2023b, R2024a, R2024b, R2025b, R2026a, latest]
2121

2222
# UITest with gestures only from R2023b and later.
2323

test/+wt/+test/ButtonGrid.m

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ function testCreationByIcon(testCase)
3535
icon = ["add" "delete" "play" "pause" "stop"] + "_24.png";
3636

3737
testCase.verifySetProperty("Icon", icon);
38+
39+
diag = "Expected update to run without warnings.";
40+
testCase.verifyWarningFree(@()testCase.Widget.forceUpdate(false), diag)
3841

3942
end %function
4043

@@ -50,6 +53,23 @@ function testCreationByTextAndIcon(testCase)
5053

5154
expNum = max(numel(text), numel(icon));
5255
testCase.verifyNumElements(testCase.Widget.Button, expNum)
56+
57+
diag = "Expected update to run without warnings.";
58+
testCase.verifyWarningFree(@()testCase.Widget.forceUpdate(false), diag)
59+
60+
end %function
61+
62+
63+
function testEmptyButtons(testCase)
64+
% Add buttons by Icon and Text
65+
66+
testCase.verifySetProperty("Icon", strings(1,0));
67+
testCase.verifySetProperty("Text", strings(1,0));
68+
69+
testCase.verifyEmpty(testCase.Widget.Button)
70+
71+
diag = "Expected update to run without warnings.";
72+
testCase.verifyWarningFree(@()testCase.Widget.forceUpdate(false), diag)
5373

5474
end %function
5575

@@ -65,6 +85,9 @@ function testMissingIcons(testCase)
6585

6686
expNum = max(numel(text), numel(icon));
6787
testCase.verifyNumElements(testCase.Widget.Button, expNum)
88+
89+
diag = "Expected update to run without warnings.";
90+
testCase.verifyWarningFree(@()testCase.Widget.forceUpdate(false), diag)
6891

6992
end %function
7093

@@ -80,6 +103,9 @@ function testMissingText(testCase)
80103

81104
expNum = max(numel(text), numel(icon));
82105
testCase.verifyNumElements(testCase.Widget.Button, expNum)
106+
107+
diag = "Expected update to run without warnings.";
108+
testCase.verifyWarningFree(@()testCase.Widget.forceUpdate(false), diag)
83109

84110
end %function
85111

@@ -97,6 +123,9 @@ function testExtraTooltip(testCase)
97123

98124
expNum = max(numel(text), numel(icon));
99125
testCase.verifyNumElements(testCase.Widget.Button, expNum)
126+
127+
diag = "Expected update to run without warnings.";
128+
testCase.verifyWarningFree(@()testCase.Widget.forceUpdate(false), diag)
100129

101130
end %function
102131

@@ -127,6 +156,9 @@ function testPressButton(testCase)
127156
testCase.verifyEqual([evts.Button], buttons)
128157
testCase.verifyEqual(string({evts.Text}), text)
129158
testCase.verifyEqual(string({evts.Tag}), tag)
159+
160+
diag = "Expected update to run without warnings.";
161+
testCase.verifyWarningFree(@()testCase.Widget.forceUpdate(false), diag)
130162

131163
end %function
132164

@@ -137,6 +169,9 @@ function testBackgroundColor(testCase)
137169
newValue = [1 0.5 0.2];
138170
testCase.verifySetProperty("BackgroundColor", newValue);
139171
testCase.verifyEqual(testCase.Widget.Grid.BackgroundColor, newValue);
172+
173+
diag = "Expected update to run without warnings.";
174+
testCase.verifyWarningFree(@()testCase.Widget.forceUpdate(false), diag)
140175

141176
end %function
142177

@@ -156,6 +191,9 @@ function testOrientation(testCase)
156191
testCase.verifySetProperty("Orientation", "vertical");
157192
testCase.verifyNumElements(testCase.Widget.Grid.RowHeight, numel(icon));
158193
testCase.verifyNumElements(testCase.Widget.Grid.ColumnWidth, 1);
194+
195+
diag = "Expected update to run without warnings.";
196+
testCase.verifyWarningFree(@()testCase.Widget.forceUpdate(false), diag)
159197

160198
end %function
161199

@@ -188,6 +226,9 @@ function testIconAlignment(testCase)
188226
newValue = "left";
189227
testCase.verifySetProperty("IconAlignment", newValue);
190228
testCase.verifyMatches(button.IconAlignment, newValue);
229+
230+
diag = "Expected update to run without warnings.";
231+
testCase.verifyWarningFree(@()testCase.Widget.forceUpdate(false), diag)
191232

192233
end %function
193234

@@ -212,6 +253,9 @@ function testButtonWidthHeight(testCase)
212253
testCase.verifySetProperty("Text", ["1", "2", "3", "4"], ["1", "2", "3", "4"])
213254
testCase.verifyEqual(testCase.Widget.ButtonWidth, {10 20 30 30})
214255

256+
diag = "Expected update to run without warnings.";
257+
testCase.verifyWarningFree(@()testCase.Widget.forceUpdate(false), diag)
258+
215259
% Change to vertical layout
216260
newOrientation = "vertical";
217261
testCase.verifySetProperty("Orientation", newOrientation);
@@ -226,6 +270,9 @@ function testButtonWidthHeight(testCase)
226270

227271
testCase.verifySetProperty("ButtonWidth", {10 'fit'}, {10})
228272
testCase.verifySetProperty("ButtonWidth", 20, {20})
273+
274+
diag = "Expected update to run without warnings.";
275+
testCase.verifyWarningFree(@()testCase.Widget.forceUpdate(false), diag)
229276

230277
end
231278

widgets/+wt/+abstract/BaseViewChart.m

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,18 @@
6464
%% Debugging Methods
6565
methods
6666

67-
function forceUpdateChart(obj)
67+
function forceUpdateChart(obj, showMessage)
6868
% Forces update to run (For debugging only!)
6969

70-
disp("DEBUG: Forcing update for " + class(obj));
70+
arguments
71+
obj
72+
showMessage (1,1) logical = true
73+
end
74+
75+
if showMessage
76+
disp("DEBUG: Forcing update for " + class(obj));
77+
end
78+
7179
obj.update();
7280

7381
end %function

widgets/+wt/+abstract/BaseViewController.m

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,18 @@
8585
%% Debugging Methods
8686
methods
8787

88-
function forceUpdate(obj)
88+
function forceUpdate(obj, showMessage)
8989
% Forces update to run (For debugging only!)
9090

91-
disp("DEBUG: Forcing update for " + class(obj));
91+
arguments
92+
obj
93+
showMessage (1,1) logical = true
94+
end
95+
96+
if showMessage
97+
disp("DEBUG: Forcing update for " + class(obj));
98+
end
99+
92100
obj.update();
93101

94102
end %function

widgets/+wt/+abstract/BaseWidget.m

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,18 @@
5454
%% Debugging Methods
5555
methods
5656

57-
function forceUpdate(obj)
57+
function forceUpdate(obj, showMessage)
5858
% Forces update to run (For debugging only!)
5959

60-
disp("DEBUG: Forcing update for " + class(obj));
60+
arguments
61+
obj
62+
showMessage (1,1) logical = true
63+
end
64+
65+
if showMessage
66+
disp("DEBUG: Forcing update for " + class(obj));
67+
end
68+
6169
obj.update();
6270

6371
end %function

widgets/+wt/ButtonGrid.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ function update(obj)
181181
end
182182

183183
% Remove any extra rows/cols from the grid
184-
if obj.Orientation == "vertical"
184+
if obj.Orientation == "vertical" && numNew > 0
185185
obj.Grid.RowHeight(numNew+1:end) = [];
186186
obj.Grid.ColumnWidth = obj.Grid.ColumnWidth(1);
187-
else
187+
elseif obj.Orientation == "horizontal" && numNew > 0
188188
obj.Grid.ColumnWidth(numNew+1:end) = [];
189189
obj.Grid.RowHeight = obj.Grid.RowHeight(1);
190190
end

0 commit comments

Comments
 (0)