Expand GUI in App UIFigure by a button for to extend the showing
조회 수: 7 (최근 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!