Child item with an x position greater than its parent panel's width still appears inside it

I get the width of a panel in pixels like this:
set(MyPanel,'units','pixel')
pos = MyPanel.Position;
set(MyPanel,'units','normalized')
The width comes back as 510 px, yet a child of this panel that has an x position of 600 or more still appears inside the panel. How is this possible?
Edit to provide a minimum working example and steps to reproduce the problem:
Step 1: Create an app using the "2-Panel App with Auto-Reflow" template
Step 2: Set startupFcn to the following:
function startupFcn(app)
drawnow
fig_position = app.UIFigure.Position;
fig_width = fig_position(3);
fig_height = fig_position(4);
app.GridLayout.ColumnWidth = {0.54*fig_width, 0.46*fig_width};
app.GridLayout.RowHeight = fig_height;
app.UIFigure.WindowState = 'maximized';
MyPanel = uipanel(app.LeftPanel,"Units","normalized","Position",[0 0.5 1 0.3]);
pos = getpixelposition(MyPanel);
pos3 = app.LeftPanel.Position;
pos2 = getpixelposition(app.LeftPanel);
end
Step 3: Set a breakpoint at the end of the function and hover over app.LeftPanel.Position and pos3. You will see that the width value for some reason is different! (See images below)

13 comentarios

May be there are some child/objects that you didn't expect it's there, and dind't inspect them?
@Bruno Luong No it's a direct child of the Panel. Also, I noticed that the width value returned by MyPanel.Position is incorrect for some reason...
I can't reproduce what you report:
h=uipanel;
set(h,'unit','pixel');
pp=get(h,'position')
pp = 1×4
1 1 577 433
ax=uiaxes(h);
set(ax,'unit','pixel');
pa=get(ax,'position')
pa = 1×4
10 10 400 300
pa(1)=pp(3)+1
pa = 1×4
578 10 400 300
set(ax,'position',pa) % axes must disappear since it is overflowed on the extrem right side
@Bruno Luong Maybe providing a bit more context will help. I'm building the app using the 2-Panel App with Auto-Reflow template. So the app.LeftPanel has a Position vector of [1 1 864 837]. I define MyPanel as follows:
MyPanel = uipanel(app.LeftPanel,"Units","normalized","Position",[0 0.5 1 0.3])
So in theory the width of MyPanel should be 864 pixels, yet I get 510 pixels (which is the same even if I use the getpixelposition).
I am unclear as to how the High Density Display accommodations affect these numbers (if at all.)
@Walter Roberson The size the app.UIFigure component is in line with my screen resolution, so I assume that it's not an issue. I haven't messed with anything related to High Density Display accommodations either.
It will be helpful if you can provide a minimum working example.
@Bruno Luong I edited the question to provide that.
With this command
MyPanel = uipanel(app.LeftPanel,"Units","normalized","Position",[0 0.5 1 0.3])
You create another uipanel within the LeftPanel, not the app figure.
As I told above, you might have some other oject that you are not suspected it is there.
@Bruno Luong That still doesn't explain what I mention in the edit though.
I add drawnow (attached test file)
drawnow
MyPanel = uipanel(app.LeftPanel,"Units","normalized","Position",[0 0.5 1 0.3]);
drawnow
pos = getpixelposition(MyPanel); % <- width 218
pos3 = app.LeftPanel.Position; % <- width 220
pos2 = getpixelposition(app.LeftPanel); % <- width 220
Command line output without debugger:
>> app1
pos =
1.0000 240.0000 344.0000 143.4000
pos3 =
1 1 346 480
pos2 =
1 1 346 480
>>
So it reduces 1 pixel each side. Seems like not an abnormal size.
@Bruno Luong Yes this is it! For some reason now the width is correct in my app. Thank you!
Just keep in mind that App and GUI workflow is Event driven, so concurrent and can be quite surprise if you don't pay close attention.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Develop Apps Using App Designer en Centro de ayuda y File Exchange.

Productos

Versión

R2020b

Etiquetas

Preguntada:

el 26 de Abr. de 2022

Editada:

el 26 de Abr. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by