Skip to content

Commit

Permalink
getpixelposition: handle rel_to_fig option correctly (bug #65096)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
pantxo committed Jan 8, 2024
1 parent 876061b commit 2e0d287
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions scripts/gui/getpixelposition.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 2e0d287

Please sign in to comment.