GUI flickers when customly resized
Afficher commentaires plus anciens
When I select the checkbox "Show stats" the GUI is resized w/o any flicker, whereas selecting "Show buttons" causes the GUI to flicker due to the custom resize. How can I eliminate the flicker?
Run the following example GUI (any other best-practice advises are really welcome):
function example
% Figure Window
S.fh = figure('Units','pixels','Pos',[600 500 370 225],...
'Menubar','none','Resize','off');
% Uipanel for buttons
S.upB = uipanel('Title','Show buttons','Units','pixels','Pos',[10 90 351 65]);
% Buttons check box
S.cbB = setdiff(findall(S.upB),S.upB);
set(S.cbB,'Style','checkbox','Parent',S.fh,'Visible','on',...
'Value',1,'Pos',[20 148 90 15],'Callback',{@cb_call,S.upB});
% Uipanel for stats
S.upS = uipanel('Title','Show stats','Units','pixels','Pos',[10 10 351 65]);
% Stats check box
S.cbS = setdiff(findall(S.upS),S.upS);
set(S.cbS,'Style','checkbox','Parent',S.fh,'Visible','on',...
'Value',1,'Pos',[20 68 90 15],'Callback',{@cb_call,S.upS});
% textbox
S.txDisp = uicontrol('Style','text','Pos',[10 170 200 55]);
S.txComp = uicontrol('Style','text','Pos',[225 178 115 33]);
% cb_call -----------------------------------------------------------------
function cb_call(varargin)
if get(varargin{1},'Value')
resizeFig(get(varargin{3},'Pos') - 5,...
unique([varargin{1},S.cbB]),S.upB,S.txComp,S.txDisp,S.fh)
set(varargin{3},'Visible','on');
else
set(varargin{3},'Visible','off');
resizeFig(-get(varargin{3},'Pos') + 5,...
unique([varargin{1},S.cbB]),S.upB,S.txComp,S.txDisp,S.fh)
end
setFocusFig(varargin{1})
end
% resizeFig ---------------------------------------------------------------
function resizeFig(height,varargin)
set(varargin{end},'Pos', get(varargin{end},'Pos') + [0 -height(end) 0 height(end)])
for h = [varargin{1:end-1}]
set(h,'Pos', get(h,'Pos') + [0 height(end) 0 0])
end
end
% setFocusFig -------------------------------------------------------------
function setFocusFig(hObject)
% Workaround to set focus to figure
set(hObject, 'Enable', 'off');
drawnow;
set(hObject, 'Enable', 'on');
end
end
Réponse acceptée
Plus de réponses (1)
Matt Fig
le 22 Fév 2011
0 votes
No flicker here. What renderer are you using? I am using painters.
1 commentaire
Oleg Komarov
le 23 Fév 2011
Catégories
En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!