uipanel border type problem

5 views (last 30 days)
André
André on 2 May 2018
Edited: André on 2 May 2018
I am designing a GUI where I want to nest 2 or 3 panels in such a way they are perfectly aligned. If I run the following code to nest 100 panels (just an extreme example) inside each other:
a = figure
b=uipanel(a, 'units', 'pixels', 'position', [10, 10, 200, 200]);
for i=1:99
b = uipanel(b, 'units', 'pixels', 'BorderType', 'etchedout','OuterPosition', [1, 1, 200, 200]);
b.Position(1:2) = b.Position(1:2)-b.BorderWidth;
end
I get this:
I corrected the border width offset, but still the panels are not properly aligned. This problem doesn't happen if I use a border of type 'line'. Is there any way to perfectly align all the nested panels for any border type?
In addition, for a 'BorderWidth' of 1, a border of type 'line' has still a different width than a border of type 'etchedout'. It also should be '0' when border type is 'none', but is still '1'. How to find the true border width?
Regards
  5 Comments
Jan
Jan on 2 May 2018
@André: Please post the code, which creates the shown figure and which reproduces the problem. This is more useful than posting some other code, which creates 100 nested panel, which you do not need at all. I'm not sure, which detail the actual problem is.
André
André on 2 May 2018
Edited: André on 2 May 2018
The code is on the bottom of this post. Please ignore the panelInterdistances parameter, I set it to 0. The following figure explains my reasoning:
In the image, the blue panel object is insede another panel. p is the original vertical Position(2) of the blue panel, according to the definition of the MATLAB documentation: Distance from the inner bottom edge of the parent container to the outer bottom edge of the panel (by default p=1pixel, which correspondes to 0 in normalized units), m is the border width, h1 is the container panel heigth --Position(4)-- and h2 is the height of the blue panel. So if I want to perfeclty align an object from below, I just need to set p=0 and subtract m. On the other hand, if I want to perfeclty align an object from above, my start position is given by the red equation.
The great question here is: What is the true value of m in pixels? It seems to be different when I choose a "etchedout" border and when I choose a "line" border. Even if the BorderType = 'none', the BorderWidth property is sill 1. So I conclude that m is not the BorderWidth value. In fact, from my 100 panels experiment with BorderWidth=1, it seems that:
  • m=1 for "etchedout"
  • m=0 for "line"
  • m=-1!!! for "none".
You can confirm this by running the 100 panel experiment code with different border types and varying the start position between -1,0 and 1. Or I am completely wrong with the reasoning of the scheme I attached.
Another thing I found out is that I can properly align the 100 panels from below or from above, using the code aboce, but I cannot do the same with my GUI, using the code below. I suspect it has to do with rounding errors from the panel dimension calculations when dividing the GUI into various panels...
%%Screen dimensions
screenResolution = get(0,'screensize');
screen_Width = screenResolution(3);
screen_Height = screenResolution(4);
%%Figure dimensions
FIG_dims = [screen_Width, screen_Height]*0.8;
FIG_Position = [(screen_Width-FIG_dims(1))/2,...
(screen_Height-FIG_dims(2))/2,...
FIG_dims];
%%Draw the figure
FIG = figure('Tag', 'FIG',...
'Visible', 'on',... % Switch to off??????????????????
'Units', 'pixels',...
'OuterPosition', FIG_Position);
drawnow; % Correct OuterPosition bugs (size will be wrong if I dont do this).
%%Parameters
outerMargins = 0.01*FIG.Position(3);
panelInterDistance = 0/2;
Main_Size = 0.9; % 90% of mother panel height is for the main panel and 10% for the footer panel.
left_right_ratio = 0.9; % left panel is 10% smaller (in width) than right panel (not considering the panel inter distance).
%%Mother panel
Mother_Dims = [FIG.Position(3) - 2*outerMargins,...
FIG.Position(4) - 2*outerMargins];
Mother_Position = [outerMargins,...
outerMargins,...
Mother_Dims];
PANEL_Mother = uipanel(FIG, 'Tag', 'PANEL_Mother',...
'Units', 'pixels',...
'Position', Mother_Position,...
'BorderType', 'etchedout');
%%Main panel
Main_Height = Mother_Dims(2)*Main_Size-panelInterDistance/2;
Main_Dims = [Mother_Dims(1), Main_Height];
Main_Position = [-1,...
Mother_Dims(2)-Main_Height-1-1,...
Main_Dims];
PANEL_Main = uipanel(PANEL_Mother, 'Tag', 'PANEL_Main',...
'Units', 'pixels',...
'Position', Main_Position,...
'BorderType', 'etchedout');
%%Footer panel
Footer_Height = Mother_Dims(2)*(1-Main_Size)-panelInterDistance/2;
Footer_Dims = [Mother_Dims(1), Footer_Height];
Footer_Position = [-1,...
-1,...
Footer_Dims];
PANEL_Footer = uipanel(PANEL_Mother, 'Tag', 'PANEL_Footer',...
'Units', 'pixels',...
'Position', Footer_Position,...
'BorderType', 'etchedin');
%%Left panel
Left_Dims = [(Main_Dims(1)*left_right_ratio-panelInterDistance)/2, Main_Dims(2)];
Left_Position = [-1,...
-1,...
Left_Dims];
PANEL_Left = uipanel(PANEL_Main, 'Tag', 'PANEL_Left',...
'Units', 'pixels',...
'Position', Left_Position,...
'BorderType', 'etchedout');
%%Right panel
Right_Dims = [(Main_Dims(1)*(1+(1-left_right_ratio))-panelInterDistance)/2, Main_Dims(2)];
Right_Position = [1+Left_Dims(1)+panelInterDistance,...
-1,...
Right_Dims];
PANEL_Right = uipanel(PANEL_Main, 'Tag', 'PANEL_Right',...
'Units', 'pixels',...
'Position', Right_Position,...
'BorderType', 'etchedout');

Sign in to comment.

Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!