Expand GUI in App UIFigure by a button for to extend the showing
8 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I'm trying to expand down part of the UIFigure of a MATLAB App by a button push.
As example:
from: - to ->
I tryied to change the weight of the figure but it does not work properly:
% IN THE BUTTON CALLBACK
posicio_actual = app.UIFigure.Position; % Exemple : 666 346 588 389 [posX, posY, amplada, llargada]
posicio_actual(4) = posicio_actual(4) + 150;
app.UIFigure.Resize = 'off';
app.UIFigure.AutoResizeChildren = 'off';
app.UIFigure.Position = posicio_actual;
But this is the result:
The below part does not show.
Thank you!
0 件のコメント
採用された回答
Voss
2022 年 7 月 15 日
The Position of each component (specifically Position([1 2]), which are the x- and y-coordinates of the lower-left corner of the component) is measured from the bottom-left corner of its parent container (i.e., figure/uifigure/uipanel/whatever), so when the uifigure's height increases by 150 pixels, in order to do what you want, you actually need to move all the components in the uifigure up by 150 pixels at the same time. (Also, since the uifigure is expanding downward, it makes sense to move the bottom of the uifigure down by 150 pixels so that the top edge remains in the same place it was.)
Here is an example with a traditional figure, where the pushbutton toggles the state of the figure between "expanded" and "collapsed" (you can run it and make sure it does what you want, then apply the same logic to your app):
handles = struct();
handles.figure = figure('Units','pixels');
handles.top_ax = axes( ...
'Units','pixels', ...
'Position',[30 30 200 200]);
handles.bottom_ax = axes( ...
'Units','pixels', ...
'Position',[30 -120 400 90]);
handles.pushbutton = uicontrol( ...
'Units','pixels', ...
'Position',[260 30 70 26], ...
'String','Expand', ...
'Callback',{@cb_expand,true});
guidata(handles.figure,handles);
function cb_expand(src,~,do_expand)
handles = guidata(src);
dy = 150;
if ~do_expand
dy = -dy;
end
pos = get(handles.figure,'Position');
pos([2 4]) = pos([2 4])+[-dy dy];
set(handles.figure,'Position',pos);
pos = get(handles.top_ax,'Position');
pos(2) = pos(2)+dy;
set(handles.top_ax,'Position',pos);
pos = get(handles.bottom_ax,'Position');
pos(2) = pos(2)+dy;
set(handles.bottom_ax,'Position',pos);
pos = get(handles.pushbutton,'Position');
pos(2) = pos(2)+dy;
set(handles.pushbutton,'Position',pos);
if do_expand
new_str = 'Collapse';
else
new_str = 'Expand';
end
set(handles.pushbutton, ...
'String',new_str, ...
'Callback',{@cb_expand,~do_expand});
end
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Develop uifigure-Based Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!