How to re-center a panel after the resize of the App?.

2 views (last 30 days)
I have an figure in the center of a panel of my app.
When the page is full screen there is the possibiity to increase all the chldren element of that panel.
In my case have a figure used as backgroud to show some data and i cannot find the same command to resize.
I was searching for setting the figure and the data in the center of the page full screen instead of resize it, how can i do it?
I place some images to give you an idea of the problem:
in fullscreesn png you can se in the red square the position I would like to obtain for the table in full screenwithout resize.

Answers (1)

Nivedita
Nivedita on 6 Sep 2023
Hi Pietro,
I understand that you are facing trouble keeping the figure in the centre of your app when resizing it.
You can achieve the following using the steps below:
  • Define a “UIFigureSizeChanged” callback function in the following manner:
% Size changed function: UIFigure
function UIFigureSizeChanged(app, event)
if app.UIFigure.WindowState == "maximized"
app.Panel.Position = [0 0 app.UIFigure.Position(3) app.UIFigure.Position(4)];
position = get(groot, 'Screensize');
app.Image.Position = [(position(3) - app.Image.Position(3)) / 2, (position(4) - app.Image.Position(4)) / 2, app.Image.Position(3), app.Image.Position(4)];
elseif app.UIFigure.WindowState == "normal"
app.Panel.Position = [0 0 app.UIFigure.Position(3) app.UIFigure.Position(4)];
app.Image.Position = [(app.Panel.Position(3) - app.Image.Position(3)) / 2, (app.Panel.Position(4) - app.Image.Position(4)) / 2, app.Image.Position(3), app.Image.Position(4)];
end
end
  • In the code above, I have used a panel and placed an image in the centre of the panel. In both the “maximized” and “normal” state of the app, the panel position and size are updated to fit the entire UI Figure area.
  • When the UI Figure will be in the “maximized” state, the size of the desktop screen is stored in the “position” variable and using this, the image placed in the panel is pushed to the centre of the screen with the dimensions intact.
  • When the UI Figure is in the “normal” state, the image will be pushed to the centre of the panel using the position of the panel keeping the dimension intact.
  • One thing to keep in mind here is that the “UIFigureSizeChanged” callback function only works when the “AutoResizeChildren” property is not selected, so make sure to uncheck the box.
I hope this helps!
Regards,
Nivedita.

Categories

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

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!