uicontrol vs annotation render order

1 visualizzazione (ultimi 30 giorni)
Jim Hokanson
Jim Hokanson il 12 Dic 2017
Commentato: Jim Hokanson il 22 Dic 2017
I was hoping to get uicontrols rendered below annotations. The order of creation of a uicontrol vs an annotation does not seem to matter, the annotation always seems to be below the control.
clf
set(gcf,'Units','normalized')
p = [0.0339 0.0452 0.1071 0.0476];
wtf2 = annotation('rectangle',[0 p(2) 1 0.1],'Color','g','FaceColor','g');
wtf = uicontrol('Style','Text','String','This is a test','Units','normalized','Position',p);
wtf3 = annotation('rectangle',[0 p(2) 1 0.1],'Color','b','FaceColor','b');
In the code example above neither annotation covers the uicontrol. Is this documented somewhere? Presumably I could use a textbox annotation to fix this behavior but I was hoping to understand the difference between annotations and uicontrols, particularly with regard to rendering.
  2 Commenti
Walter Roberson
Walter Roberson il 12 Dic 2017
If I recall correctly you are using a release from R2014b onwards? Because in releases before that, uicontrol were always on top.
Jim Hokanson
Jim Hokanson il 12 Dic 2017
Oops, yes, using 2017a. It seems that uicontrols are still always on top.

Accedi per commentare.

Risposte (1)

Amy
Amy il 21 Dic 2017
Hi Jim - for more information on how graphics objects are rendered in releases since R2014b, try looking into these two documentation pages:
If all you want is to hide the uicontrol beneath an annotation/rectangle, you could always just set its 'Visible' property to 'off'!
  1 Commento
Jim Hokanson
Jim Hokanson il 22 Dic 2017
Thanks Amy.
I don't actually see any mention of the relationship between annotations and uicontrols in the linked documentation.
I'm able to get the behavior I need by changing my text uicontrol to an annotation. The use case is specifically that I'm moving annotation lines and these lines may overlap with text. In that case I want the lines to hide the text. However, changing the visibility of the text means 1) I need to pay attention to the relationship between the line and the text (which I'm not currently doing) and 2) a potential partial hiding of the text (if the line could actually block the text) turns into a complete hiding of the text box.
Again, as I said I've managed to get a workaround. I guess that intuitively I expected rendering order of all things attached to the figure, would by default, be determined by their creation order (with maybe some mechanism for reordering post-hoc). Instead it seems like uicontrols and annotations have been artificially separated into two distinct groups for rendering.
Thanks again, Jim

Accedi per commentare.

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by