Overwriting Grid Layout Does Not Delete Existing Grid Layout.
7 ビュー (過去 30 日間)
古いコメントを表示
Overwriting an existing Grid Layout does not delete the existing Grid Layout. I think this might be the cause the random issues I am currently encountering in App Designer. Is this a bug? My real app needs to overwrite grid layouts often.
Please run the attached app as an example.
7 件のコメント
dpb
2022 年 8 月 18 日
編集済み: dpb
2022 年 8 月 19 日
I looked at that code; I didn't see anything in it that does anything with those layouts so it's not possible to see just how you're trying to do this.
I still say if you don't have the handles to these various layouts you can't do anything with any one of them specifically, and I certainly would NOT expect from the documenation that somehow "overwriting" a given grid layout (not even sure how you would be thinking you're "overwriting" it; there's no such functionality documented that would be similar to the behavior of subplot, say, that will transparently delete existing axes if a new one overlays an existing one's position.
If your code is intended to demonstrate changing layout sizes as is, then as I mentioned before, it's not the way to go about rearranging the app layout -- you change the properties/sizes of the layout dynamically by changing its properties instead; there are examples in the doc of creating resizing UIs based on content at runtime.
The gridlayout itself covers the entire uifigure and has components in it; some of which may be nested grids, but NOT multiple gridlayouts that one can swap out; that's not the model.
Without a lot more detail of just how this manipulation is being done, I'd put the crash-and-burn symptoms down as pilot error.
There might could be additional documentation and/or perhaps the use you've made should provide a warning -- there's not enough detail given in the doc to be totally unambiguous about making multiple calls to uigridlayout without a parent argument and not deleting an existing handle first as to what that actually does or if that is or is not an acceptable programming practice.
That could be worth a service request from tech support as to whether that is or is not considered legal. But, certainly it is NOT a documented usage in any of the mutiple examples and looking at the organization of how it is used in those examples, that certainly doesn't appear to me to be the intended use so I'm not surprised if it seems to cause issues when doing so.
回答 (2 件)
Image Analyst
2022 年 8 月 19 日
Try calling this little function:
%=====================================================================
% Erases all lines and rectangles from the specified image axes.
function ClearLinesFromAxes(handlesToAxes)
axesHandlesToChildObjects = findobj(handlesToAxes, 'Type', 'line');
if ~isempty(axesHandlesToChildObjects)
delete(axesHandlesToChildObjects);
end
axesHandlesToChildObjects = findobj(handlesToAxes, 'Type', 'rectangle');
if ~isempty(axesHandlesToChildObjects)
delete(axesHandlesToChildObjects);
end
return; % from ClearLinesFromAxes
If you also want to remove lines created by xline() and yline() I believe you have to find objects of those types also.
0 件のコメント
dpb
2022 年 8 月 19 日
編集済み: dpb
2022 年 8 月 19 日
Well, still without any real klews as to what it is you're trying to do here, I believe that based on my reading of the doc of syntax and examples for the gridlayout object, the way to accomplish what the above code would do for a given layout would be
function startupFcn(app)
NGridColumns=20;
hGrid=uigridlayout(app.UIFigure,[1,1]); % Create the grid, save handle, '1x'by'1x' initially
for n = 2:NGridColumns
hUIG.ColumnWidth=repmat({'1x'},1,n); % reset column to "n" elements
end
app.hGrid=hGrid; % save in the global struct for use elsewhere
end
IOW, change the grid layout you have defined, don't try to overlay multiple layouts on the same figure -- that just isn't the way it works, there's only one layout(*) but it can take on (almost) any desired configuration dynamically.
I'm guessing that probably one of the auto-fit scenarios would more nearly be what you're looking for, where the container will resize automagically based on its input and you're trying to do that with "roll your own" code instead of using builtin features. But, that's a guess since we're pretty-much blind here.
(*) At the top app figure level; there can be nested layouts or layouts inside containers like panels, but they're still then "sub-layouts" of the parent.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Develop Apps Using App Designer についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!