GUI flickers when customly resized
Mostra commenti meno recenti
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
Risposta accettata
Più risposte (1)
Matt Fig
il 22 Feb 2011
0 voti
No flicker here. What renderer are you using? I am using painters.
1 Commento
Oleg Komarov
il 23 Feb 2011
Categorie
Scopri di più su Startup and Shutdown in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!