Mercurial > octave
changeset 33225:b6f8862f2f5b
uifigure.m: Handle prop/val overrides better (bug #65459)
* uifigure.m: Update documentation to state that "AutoResizeChildren", "Icon",
and "Scrollable" properties are not implemented. Check prop/val pairs in varargin
and strip out properties not implemented by regular figure object. Call
__go_figure__ with remaining prop/val pairs. After calling addproperty() to
add special uifigure properties, set them to the specified values saved earlier.
Modify BIST test to verify new behavior.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 19 Mar 2024 16:33:20 -0700 |
parents | d174bfd66e28 |
children | 461f5517c06c |
files | scripts/gui/uifigure.m |
diffstat | 1 files changed, 21 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/gui/uifigure.m Tue Mar 19 15:12:42 2024 -0700 +++ b/scripts/gui/uifigure.m Tue Mar 19 16:33:20 2024 -0700 @@ -37,6 +37,9 @@ ## @ref{Figure Properties}. This function differs from @code{figure} in that ## the created figure is optimized for application development, rather than ## plotting. This means features such as menubars and toolbars are turned off. +## This is not perfect replacement for the @sc{matlab} uifigure object as the +## properties @qcode{"AutoResizeChildren"}, @qcode{"Icon"}, and +## @qcode{"Scrollable"} are not implemented. ## @seealso{uipanel, uibuttongroup} ## @end deftypefn @@ -47,33 +50,43 @@ function h = uifigure (varargin) - if (mod (nargin, 2) != 0) + if (rem (nargin, 2) != 0) error ("uifigure: PROPERTY/VALUE parameters must occur in pairs"); endif + strfcn = @(s) any (strcmpi (s, {'AutoResizeChildren', 'Icon', 'Scrollable'})); + idx = cellfun (strfcn, varargin (1:2:end)); + if (any (idx)) + idx = repelem (idx, 2); + props = varargin(idx); # save special props for applying later + varargin(idx) = []; # remove special props from varargin + endif + h = __go_figure__ (NaN, "handlevisibility", "off", "numbertitle", "off", "integerhandle", "off", - "menubar", "none", "toolbar", "none"); + "menubar", "none", "toolbar", "none", + varargin{:}); ## Add uifigure-specific properties on top of regular figure graphics object ## FIXME: There is no implementation behind these properties. addproperty ("AutoResizeChildren", h, "boolean", "on"); + addproperty ("Icon", h, "data", []); addproperty ("Scrollable", h, "boolean", "off"); - ## Apply any overrides. - if (! isempty (varargin)) - set (h, varargin{:}); + ## Set values for special properties added above + if (! isempty (props)) + set (h, props{:}); endif endfunction %!test -%! hf = uifigure ("visible", "off"); +%! hf = uifigure ("visible", "off", "Icon", magic (3)); %! unwind_protect %! assert (isfigure (hf)); -%! assert (get (hf, {"numbertitle", "menubar", "scrollable"}), -%! {"off", "none", "off"}); +%! assert (get (hf, {"numbertitle", "menubar", "icon", "scrollable"}), +%! {"off", "none", magic(3), "off"}); %! unwind_protect_cleanup %! close (hf); %! end_unwind_protect