Skip to content

Commit 0527cb7

Browse files
committed
work on dialogs
1 parent 9a22fee commit 0527cb7

File tree

3 files changed

+103
-16
lines changed

3 files changed

+103
-16
lines changed

widgets/+wt/+abstract/BaseDialog2.m

Lines changed: 89 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,72 @@
7575
end %methods
7676

7777

78+
%% Lower Button Properties
79+
% The dialog subclass can change these values
80+
properties (Dependent)
81+
82+
LowerButtonText
83+
84+
LowerButtonTag
85+
86+
LowerButtonTooltip
87+
88+
LowerButtonEnable
89+
90+
LowerButtonWidth
91+
92+
LowerButtonHeight
93+
94+
end %methods
95+
96+
% Accessors
97+
methods
98+
99+
function value = get.LowerButtonText(obj)
100+
value = obj.LowerButtons.Text;
101+
end
102+
function set.LowerButtonText(obj,value)
103+
obj.LowerButtons.Text = value;
104+
end
105+
106+
function value = get.LowerButtonTag(obj)
107+
value = obj.LowerButtons.ButtonTag;
108+
end
109+
function set.LowerButtonTag(obj,value)
110+
obj.LowerButtons.ButtonTag = value;
111+
end
112+
113+
function value = get.LowerButtonTooltip(obj)
114+
value = obj.LowerButtons.Tooltip;
115+
end
116+
function set.LowerButtonTooltip(obj,value)
117+
obj.LowerButtons.Tooltip = value;
118+
end
119+
120+
function value = get.LowerButtonEnable(obj)
121+
value = obj.LowerButtons.ButtonEnable;
122+
end
123+
function set.LowerButtonEnable(obj,value)
124+
obj.LowerButtons.ButtonEnable = value;
125+
end
126+
127+
function value = get.LowerButtonWidth(obj)
128+
value = obj.LowerButtons.ButtonWidth;
129+
end
130+
function set.LowerButtonWidth(obj,value)
131+
obj.LowerButtons.ButtonWidth = value;
132+
end
133+
134+
function value = get.LowerButtonHeight(obj)
135+
value = obj.LowerButtons.ButtonHeight;
136+
end
137+
function set.LowerButtonHeight(obj,value)
138+
obj.LowerButtons.ButtonHeight = value;
139+
end
140+
141+
end %methods
142+
143+
78144
%% Internal Properties
79145
properties (Transient, NonCopyable, Hidden, SetAccess = private)
80146

@@ -105,6 +171,9 @@
105171
% Modal image (optional)
106172
ModalImage matlab.ui.control.Image
107173

174+
% Lower buttons (optional)
175+
LowerButtons wt.ButtonGrid
176+
108177
end %properties
109178

110179

@@ -199,17 +268,6 @@ function positionOver(obj, refComp)
199268

200269
end %function
201270

202-
203-
function b = addButtons(obj, labels)
204-
% Adds buttons to the lower dialog area
205-
206-
b = wt.ButtonGrid(obj.InnerGrid,"Text",labels,"Icon",[]);
207-
b.ButtonWidth(:) = {'fit'};
208-
b.Layout.Row = 2;
209-
b.Layout.Column = 2;
210-
211-
end %function
212-
213271
end %methods
214272

215273

@@ -239,6 +297,7 @@ function setup(obj)
239297
% Close Button
240298
obj.CloseButton = uibutton(obj.OuterPanel);
241299
obj.CloseButton.Text = "";
300+
obj.CloseButton.Tag = "close";
242301
obj.CloseButton.IconAlignment = "center";
243302
obj.CloseButton.ButtonPushedFcn = @(src,evt)obj.onClosePushed();
244303

@@ -286,6 +345,12 @@ function setup(obj)
286345
szF = posF(3:4);
287346
obj.ModalImage.Position = [1 1 szF];
288347

348+
% Add lower buttons
349+
obj.LowerButtons = wt.ButtonGrid(obj.InnerGrid,"Text",[],"Icon",[]);
350+
obj.LowerButtons.Layout.Row = 2;
351+
obj.LowerButtons.Layout.Column = 2;
352+
obj.LowerButtons.DefaultSize = 'fit';
353+
289354
% Bring the dialog back to the top
290355
uistack(obj,"top");
291356

@@ -307,6 +372,19 @@ function update(obj)
307372
obj.repositionCloseButton();
308373

309374
end %function
375+
376+
377+
function updateBackgroundColorableComponents(obj)
378+
% Update components that are affected by BackgroundColor
379+
% (overrides the superclass method)
380+
381+
% Update grid color
382+
set([obj.InnerGrid, obj.Grid], "BackgroundColor", obj.BackgroundColor);
383+
384+
% Call superclass method
385+
obj.updateBackgroundColorableComponents@wt.mixin.BackgroundColorable();
386+
387+
end %function
310388

311389

312390
function onClosePushed(obj)

widgets/+wt/+dialog/Login.m

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
end %properties
1313

1414

15-
%% Protected methods
15+
%% Protected methods
1616
methods (Access = protected)
17-
17+
1818
function setup(obj)
1919
% Configure the widget
2020

@@ -25,7 +25,8 @@ function setup(obj)
2525
obj.setup@wt.abstract.BaseDialog2();
2626

2727
% Add buttons
28-
b = addButtons(obj, ["Login","Cancel"]);
28+
obj.LowerButtonText = ["Login","Cancel"];
29+
obj.LowerButtonTag = ["login","cancel"];
2930

3031
% Configure grid
3132
obj.Grid.RowHeight = {25,25};
@@ -37,7 +38,7 @@ function setup(obj)
3738
% Add labels
3839
col = 1;
3940
startRow = 1;
40-
lbl = obj.addRowLabels(["Username:","Password"], ...
41+
obj.addRowLabels(["Username:","Password"], ...
4142
obj.Grid, col, startRow);
4243

4344
% Add controls
@@ -48,7 +49,10 @@ function setup(obj)
4849
obj.PasswordField = wt.PasswordField(obj.Grid);
4950
obj.PasswordField.Layout.Row = 2;
5051
obj.PasswordField.Layout.Column = 2;
51-
52+
53+
% Update component lists
54+
% obj.BackgroundColorableComponents = [obj.Grid]
55+
5256
end %function
5357

5458
end %methods

widgets/+wt/ButtonGrid.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
% Alignment of the icon
4343
IconAlignment (1,1) wt.enum.AlignmentState = wt.enum.AlignmentState.top
4444

45+
% Default size of new buttons ('1x' or 'fit')
46+
DefaultSize {mustBeMember(DefaultSize,{'1x','fit'})} = '1x'
47+
4548
end %properties
4649

4750

@@ -149,9 +152,11 @@ function update(obj)
149152
if obj.Orientation == "vertical"
150153
obj.Button(idx).Layout.Column = 1;
151154
obj.Button(idx).Layout.Row = idx;
155+
obj.Grid.ColumnWidth{idx} = obj.DefaultSize;
152156
else
153157
obj.Button(idx).Layout.Column = idx;
154158
obj.Button(idx).Layout.Row = 1;
159+
obj.Grid.ColumnWidth{idx} = obj.DefaultSize;
155160
end %if obj.Orientation == "vertical"
156161

157162
end %for idx = 1:numNew

0 commit comments

Comments
 (0)