Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Does Matlab need better GUI controls?
Date: Tue, 14 Apr 2009 17:34:01 +0000 (UTC)
Organization: Battelle Energy Alliance (INL)
Lines: 68
Message-ID: <gs2he9$2nk$1@fred.mathworks.com>
References: <gs10ct$rfm$1@fred.mathworks.com> <gs11id$fs2$1@fred.mathworks.com> <1CUEl.16394$D32.8488@flpi146.ffdc.sbc.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1239730441 2804 172.30.248.38 (14 Apr 2009 17:34:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 14 Apr 2009 17:34:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 688530
Xref: news.mathworks.com comp.soft-sys.matlab:532696


"Nasser Abbasi" <nma@12000.org> wrote in message 
> True. But real tabbed GUI menus is a big missing item in Matlab GUI.


Speaking of tabbed GUIs, I am curious how others have implemented the idea of tabs without having them.  This trivial GUI shows how I usually do it.  How do others "fake it?"



function [] = panels()
% Fake tabs are no tabs.
SCR = get(0,'Screensize');
fp = [SCR(3)/2-200 ,SCR(4)/2-200 , 400, 400];
W = {'units','pixels','position'};
hf = figure('Numbert','of','Menu','no',W{:},fp,'Name','Fun Quartics');
S.ax = axes(W{:},[50 100 300 230]);
S.pb1 = uicontrol(hf,'sty','push',W{:},[50 20 300 40],'str',...
                  'Plot Random Quartic Polynomial','fonts',12);
S.tg(1) = uicontrol(hf,'sty','tog',W{:},[50 355 60 40],...
                    'str','PLOT','val',1);
S.tg(2) = uicontrol(hf,'sty','tog',W{:},[110 355 60 40],...
                    'str','FIT','val',0,'enable','off');
W = {'style','edit',W{:}};                
S.ed(5) = uicontrol(hf,W{:},[50 100 300 30]);
S.ed(4) = uicontrol(hf,W{:},[50 140 300 30]);
S.ed(3) = uicontrol(hf,W{:},[50 180 300 30]);
S.ed(2) = uicontrol(hf,W{:},[50 220 300 30]);
S.ed(1) = uicontrol(hf,W{:},[50 260 300 30]);
set(S.pb1,'callback',{@pbcall,S})
set(S.tg(:),{'callback'},{{@tgcall,S}})
set(S.ed(:),'visible','off','fontsize',12,'fontweight','b')


function [] = pbcall(varargin)
% Callback for pushbutton.
S = varargin{3};
x = -10:.1:10;
plot(S.ax,x,polyval(-5 + ceil(rand(1,5)*7),x));
set(S.tg(2),'enable','on');


function [] = tgcall(varargin)
% Callback for togglebutton.
S = varargin{3};
stat = get(S.tg(:),'val');

if ~all([stat{:}])
    set(varargin{1},'val',1);
    return
end

L = get(S.ax,'children');

switch varargin{1}
    case S.tg(1)
        set([S.ax,S.pb1,L],{'visible'},{'on'})
        set(S.ed(:),{'visible'},{'off'})
        set(S.tg(2),'val',0)
    case S.tg(2)
        STR = 'The x^0 coefficient is:  ';
        set(S.tg(1),'val',0)
        set([S.ax,S.pb1,L],{'visible'},{'off'})
        set(S.ed(:),{'visible'},{'on'})
        p = round(polyfit(get(L,'xdata'),get(L,'ydata'),4));
        for ii = 0:4
            STR(7) = num2str(ii);
            set(S.ed(5-ii),'str',[STR,num2str(p(5-ii))])
        end
end