changeset 32757:d43bec544e8e stable

getpixelposition: handle rel_to_fig option correctly (bug #65096) * getpixelposition.m: Don't add lower left hand corner position of parent figure when relative mode used. Shorten input validation to use just one ! operator.
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Mon, 08 Jan 2024 20:27:39 +0100
parents 13404200b381
children 4168d91bc123 e5694f558ad9
files scripts/gui/getpixelposition.m
diffstat 1 files changed, 10 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/gui/getpixelposition.m	Tue Jan 16 11:50:41 2024 -0800
+++ b/scripts/gui/getpixelposition.m	Mon Jan 08 20:27:39 2024 +0100
@@ -37,7 +37,7 @@
 ## is computed relative to the enclosing figure object.
 ##
 ## The return value @var{pos} is a 4-element vector with values
-## @code{[ lower_left_X, lower_left_Y, width, height ]}.
+## @code{[lower_left_X, lower_left_Y, width, height]}.
 ##
 ## @seealso{get}
 ## @end deftypefn
@@ -48,23 +48,24 @@
     print_usage ();
   endif
 
-  if (! isscalar (h) || ! ishghandle (h))
+  if (! (isscalar (h) && ishghandle (h)))
     error ("getpixelposition: H must be a scalar graphics handle");
   endif
 
-  if (! any (strcmp (get (h, "type"), {"uibuttongroup", "uicontrol", ...
-                                       "uitable", "uipanel", ...
-                                       "axes", "figure"})))
+  if (! any (strcmp (get (h, "type"),
+                     {"uibuttongroup", "uicontrol", "uitable", "uipanel", ...
+                      "axes", "figure"})))
     pos = zeros (1, 4);
     return;
   endif
 
   pos = __get_position__ (h, "pixels");
 
-  if (rel_to_fig)
-    while (! isfigure (h))
-      h = get (h, "parent");
-      pos(1:2) += __get_position__ (h, "pixels")(1:2);
+  if (rel_to_fig && ! isfigure (h))
+    hpar = get (h, "parent");
+    while (! isfigure (hpar))
+      pos(1:2) += __get_position__ (hpar, "pixels")(1:2);
+      hpar = get (hpar, "parent");
     endwhile
   endif