Determine size of programmatic layout

8 visualizaciones (últimos 30 días)
Norton Allen
Norton Allen el 29 de Nov. de 2021
Respondida: Pratheek el 23 de Feb. de 2024
I am designing a tool to create an app programmatically using uifigure and its various containers. I specifically plan to use uigridlayout in order to take advantage of its automatic sizing using 'fit'. After the figure is laid out, I would like to resize the uifigure to the size of the enclosed layout.
  • This would be trivial if the uigridlayout had a 'Position' property.
  • I can look at the 'Position' property of all the widgets contained in the uigridlayout to calculate the maximum width and height, but note that those values are only relative to the enclosing layout (the uigridlayout). If I nest a uigridlayout inside another uigridlayout, I have to perform this operation recursively to find the overall dimensions.
  • I assume the same holds true for any nested containers
Is there an easier way?
  3 comentarios
Matthew Reaves
Matthew Reaves el 26 de Dic. de 2021
I am also interested in this issue. I am working on a UI. I organized uilabel's and uieditfield's into uipanel's, arranging them using a uigridlayout whose parent is the uipanel. I would like that panel to automatically resize to fit the entire contents of the uigridlayout, but it does not appear that this is supported.
Norton Allen
Norton Allen el 26 de Dic. de 2021
I went ahead and wrote a function to calculate the size of the uigridlayout so I could set the size of the parent. I am not sure how robust it is, since it is tailored to the widgets I needed. I see no reason that a uigridlayout should not have a read-only Position property -- maybe someday!
There are still some problems with this approach that are apparently unsolvable. Specifically, there is no way to determine when the layout is finalized so the reported positions are stable. I have used 'drawnow' in the past to wait for drawing to complete, but in this case, that is not enough. I submitted a ticket for that, and it is now on the developers' radar.

Iniciar sesión para comentar.

Respuesta aceptada

Pratheek
Pratheek el 23 de Feb. de 2024
Hi Norton,
The Position property has been added to the uigridlayout in MATLAB R2022b, which simplifies the process of resizing the uifigure to match the size of the enclosed layout.
Please find the documentation link below:

Más respuestas (0)

Categorías

Más información sobre Develop uifigure-Based Apps en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by