Skip to content

Commit a44f241

Browse files
committed
fixes #192 ButtonGrid update errors if there are zero buttons
1 parent de6905d commit a44f241

2 files changed

Lines changed: 49 additions & 2 deletions

File tree

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(), 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(), 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(), 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(), 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(), 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(), 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(), 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(), 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(), 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(), 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(), 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(), diag)
229276

230277
end
231278

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)