214214    end  % properties
215215
216216
217+     %%  Constructor 
218+     methods 
219+ 
220+         function  obj  =  BaseExternalDialog(fig , varargin )
221+ 
222+             arguments 
223+                 %  Figure parent - Empty if not provided
224+                 fig  matlab.ui.Figure  {mustBeScalarOrEmpty } =  matlab.ui.Figure.empty(0 )
225+             end 
226+ 
227+             arguments  (Repeating )
228+                 %  Property-value pairs
229+                 varargin 
230+             end 
231+ 
232+ 
233+             %  Was a calling figure provided?
234+             if  isscalar(fig ) &&  isvalid(fig )
235+ 
236+                 %  Get the figure size
237+                 posF =  getpixelposition(fig );
238+                 szFig =  posF(3 : 4 );
239+ 
240+                 %  Add modal image
241+                 modalImage =  uiimage(fig );
242+                 modalImage.ImageSource =  " overlay_gray.png"  ;
243+                 modalImage.ScaleMethod =  " stretch"  ;
244+                 modalImage.Visible =  " off"  ;
245+                 modalImage.Position =  [1  1  szFig ];
246+                 modalImage.Tooltip =  " Close the dialog box to continue using the app."  ;
247+                 modalImage.Tag =  " ModalImage"  ;
248+ 
249+             end  % if
250+ 
251+             %  Call superclass constructor
252+             obj 
=  [email protected] (
" Parent" ,[], varargin{
: });
253+ 
254+             %  Was a calling figure provided?
255+             if  isscalar(fig ) &&  isvalid(fig )
256+ 
257+                 %  Store the modal background image
258+                 obj.ModalImage =  modalImage ;
259+ 
260+                 %  Update the modal image positioning
261+                 obj .updateModalImage();
262+ 
263+             end  % if
264+ 
265+         end  % function
266+ 
267+     end  % methods
268+ 
269+ 
217270
218271    %%  Destructor 
219272    methods 
@@ -349,7 +402,10 @@ function setup(obj)
349402            %  Configure the dialog
350403
351404            %  Store the parent figure
352-             obj.CallingFigure =  ancestor(obj ,' figure'  );
405+             callingFig =  ancestor(obj ,' figure'  );
406+             if  isscalar(callingFig )
407+                 obj.CallingFigure =  callingFig ;
408+             end 
353409
354410            %  Get the size input
355411            sizeInput =  obj .Size ;
@@ -362,7 +418,8 @@ function setup(obj)
362418            obj .positionOverCallingFigure()
363419
364420            %  Apply the same theme (R2025a and later)
365-             if  ~isMATLABReleaseOlderThan(" R2025a"  )
421+             if  ~isMATLABReleaseOlderThan(" R2025a"  ) &&  ...
422+                     isscalar(obj .CallingFigure ) &&  isvalid(obj .CallingFigure )
366423                obj.DialogFigure.Theme =  obj .CallingFigure .Theme ;
367424            end 
368425
@@ -393,14 +450,6 @@ function setup(obj)
393450            obj.Grid.ColumnSpacing =  5 ;
394451            obj.Grid.Scrollable =  true ;
395452
396-             %  Add modal image over the app's figure
397-             obj.ModalImage =  uiimage(obj .CallingFigure );
398-             obj.ModalImage.ImageSource =  " overlay_gray.png"  ;
399-             obj.ModalImage.ScaleMethod =  " stretch"  ;
400-             obj.ModalImage.Tooltip =  " Close the dialog box to continue using the app."  ;
401-             obj.ModalImage.Visible =  " off"  ;
402-             obj.ModalImage.Position =  [1  1  1  1 ];
403- 
404453            %  Add lower buttons
405454            obj.DialogButtons =  wt .ButtonGrid(obj .InnerGrid ," Text"  ,[]," Icon"  ,[]);
406455            obj.DialogButtons.Layout.Row =  2 ;
@@ -483,22 +532,26 @@ function checkDeletionCriteria(obj)
483532        function  positionOverCallingFigure(obj )
484533            %  Positions the dialog centered over the reference figure
485534
486-             %  Reference component size and position
487-             refPos =  getpixelposition(obj .CallingFigure , true );
488-             refSize =  refPos(3 : 4 );
489-             refCornerA =  refPos(1 : 2 );
535+             %  Is there a calling figure?
536+             if  isscalar(obj .CallingFigure ) &&  isvalid(obj .CallingFigure )
537+ 
538+                 %  Reference component size and position
539+                 refPos =  getpixelposition(obj .CallingFigure , true );
540+                 refSize =  refPos(3 : 4 );
541+                 refCornerA =  refPos(1 : 2 );
490542
491-             %  Dialog size
492-             dlgSize =  obj .DialogFigure .Position(3 : 4 );
543+                  %  Dialog size
544+                  dlgSize =  obj .DialogFigure .Position(3 : 4 );
493545
494-             %  center it over the figure
546+                  %  center it over the figure
495547
496-             %  Calculate lower-left corner
497-             dlgPos =  floor((refSize  -  dlgSize ) /  2 ) +  refCornerA ;
548+                  %  Calculate lower-left corner
549+                  dlgPos =  floor((refSize  -  dlgSize ) /  2 ) +  refCornerA ;
498550
499-             %  Set final position
500-             obj.DialogFigure.Position =  [dlgPos  dlgSize ];
551+                  %  Set final position
552+                  obj.DialogFigure.Position =  [dlgPos  dlgSize ];
501553
554+             end  % if
502555
503556        end  % function
504557
@@ -511,6 +564,11 @@ function positionOverCallingFigure(obj)
511564        function  updateModalImage(obj )
512565            %  Triggered when the Modal property is changed
513566
567+             %  Return now if no modal image
568+             if  ~isscalar(obj .ModalImage ) ||  ~isvalid(obj .ModalImage )
569+                 return 
570+             end 
571+ 
514572            %  If toggled on, do the following
515573            if  obj .Modal 
516574
@@ -537,9 +595,6 @@ function onDialogButtonPushed(obj,evt)
537595            %  The pushed button's Tag (or Name if Tag is empty) will be
538596            %  set as the LastAction
539597
540-             %  Request to assign output
541-             obj .assignOutput();
542- 
543598            %  What button was pushed?
544599            if  isa(evt , " matlab.ui.eventdata.WindowCloseRequestData"  )
545600                srcButton =  " close"  ;
@@ -562,6 +617,9 @@ function onDialogButtonPushed(obj,evt)
562617            %  Set last action
563618            obj.LastAction =  action ;
564619
620+             %  Request to assign output
621+             obj .assignOutput();
622+ 
565623            %  Prep event data
566624            evtOut =  wt .eventdata .DialogButtonPushedData ;
567625            evtOut.Action =  obj .LastAction ;
0 commit comments