📄 tabpanel.m
字号:
TabBuildUp(fig,figname,tab,handles);
%
UpdateTabpanel(fig,tab,guihandles(fig));
%
struct2handle(t,fig);
%
handles = guihandles(fig);
for i=1:length(t)
tag = t(i).properties.Tag;
tmp = tag(1:max(find(tag=='_'))-1);
tmp = tmp(max(find(tmp=='_'))+1:end);
%
h = findobj(handles.(tab.tag)(end-length(tab.names)-1:end-2),'String',tmp);
%
tg = get(h,'Userdata');
set(h,'Userdata',[tg {tag}])
end% for
try
delete(findobj(get(fig,'children'),'UserData',[tab.tag '_warning']));
end% try
uicontrol('Parent',fig,'Style','text','Tag',tab.tag,'String', ...
{'TABPANEL' '!!! CHANGE NOTHING !!!' '' 'usage for editing tabpanel' ...
'---------------------------------------------------------' ['tabpanel(''' figname ''',''' tab.tag ''')']}, ...
'Enable','inactive', 'units','pixels','position',tab.pos, ...
'BackgroundColor',[.2 .2 .2],'foregroundcolor',[1 .25 0], 'Visible','off','FontSize',8,'UserData',[tab.tag '_warning']);
TPConstructor(fig,figname,tab,handles);
%
for i = get(findobj(handles.(tab.tag)(end-length(tab.names)-1:end-2),'String',tab.current),'Userdata')
set(handles.(char(i)),'visible','on')
end% for
return
end% if
%
else
%
set(findobj(fig,'Tag',tag),'units','pixels')
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TabPanel Constructor wird zum ersten mal gestartet
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% tabpanel settings-struct
%
tab.tag = tag;
tab.pos = get(findobj(fig,'Tag',tab.tag),'position');
try
[cancel order] = unique(action);
tab.names = action(sort(order));
catch
errordlg({'tabpanel do not exist yet' 'try again with (e.g.):' '' ...
['tabpanel(''' figname ''',''' tab.tag ''',{''Tab1'' ''Tab2'' ''Tab3''})']}, ...
'Not enough input arguments.','modal')
return
end% try
tab.fontsize = 8;
tab.fontname = 'default';
tab.current = tab.names{1};
tab.outlet = [1 1];
tab.height = 21;
tab.dim = [];
for i=1:length(tab.names)
tmp = tab.names{i}(~ismember(tab.names{i},' .,:;\/<>''~+-_',''));
tab.dim = [tab.dim sum((tmp<90)*1.5+(tmp>90))+0.5];
tab.names{i} = tmp;
end ;
tab.outbreak = 3;
tab.CurrBackColor = get(0,'defaultFigureColor');
tab.CurrForeColor = get(0,'defaultTextColor');
tab.BackColor = tab.CurrBackColor - [0.3 0.3 0.3];
tab.ForeColor = tab.CurrForeColor + [0.2 0.2 0.2];
tab.XCallback = get(fig,'CloseRequestFcn');
tab.Callback = ...
['tpchandles = guihandles(gcbo);' ...
'tpctab = get(tpchandles.(get(gcbo,''Tag''))(end),''UserData'');' ...
'tpchtab = findobj(tpchandles.(tpctab.tag)(end-length(tpctab.names)-1:end-2),''String'',tpctab.current);' ...
'tpcpos = get(tpchtab,''position'');' ...
'set(tpchtab,''Enable'',''on'',''Fontweight'',''normal'',' ...
'''position'',[tpcpos(1:3) tpctab.height],' ...
'''BackGroundColor'',tpctab.BackColor,' ...
'''ForeGroundColor'',tpctab.ForeColor);' ...
'tpcpos = get(gcbo,''Position'');' ...
'set(gcbo,''Enable'',''inactive'',''Fontweight'',''bold'',' ...
'''Position'',tpcpos+[0 0 0 tpctab.outbreak],' ...
'''BackGroundColor'',tpctab.CurrBackColor,' ...
'''ForeGroundColor'',tpctab.CurrForeColor);' ...
'set(findobj(tpchandles.(tpctab.tag),''String'',''backhide''),''position'',[tpcpos(1:3) + [1 0 -3] 2]);' ...
'tpcvisoff = [];' ...
'for tpci=unique(get(tpchtab,''UserData''));' ...
'tpcvisoff = [tpcvisoff getfield(tpchandles,char(tpci))];' ...
'end;' ...
'tpcvison = [];' ...
'for tpci=unique(get(gcbo,''UserData''));' ...
'tpcvison = [tpcvison getfield(tpchandles,char(tpci))];' ...
'end;' ...
'set(tpcvisoff,''Visible'',''off'');' ...
'set(tpcvison,''Visible'',''on'');' ...
'drawnow;' ...
'tpctab.current = get(gcbo,''String'');' ...
'set(tpchandles.(tpctab.tag)(end),''UserData'',tpctab);' ...
'clear tpchandles tpchtab tpci tpcpos tpctab tpcvisoff tpcvison visoff vison'];
%
TabBuildUp(fig,figname,tab,handles)
%
end% if
TPConstructor(fig,figname,tab,handles)
%
%
% Update TabPanel
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function UpdateTabpanel(fig,tab,handles)
%-------------------------------------------------------------------------------
%
% axes
tab.dim = round((tab.pos(3)-tab.outlet(1)-tab.outlet(2))/sum(tab.dim)*tab.dim);
tab.dim(end) = tab.dim(end)-(tab.outlet(1)+sum(tab.dim))+tab.pos(3)-tab.outlet(2);
%
pos = tab.pos-[0 0 0 tab.height+tab.outbreak-3];
set(handles.(tab.tag)(end-1),'position',[pos+[0 1 -1 -2]],'color',tab.CurrBackColor)
%
% background
tmp = find(strcmp(tab.names,tab.current));
tmp1 = [tab.outlet(1) tab.dim];
pos = {[tab.pos(1:2)+[sum(tmp1(1:tmp))+1 tab.pos(4)-tab.height-tab.outbreak] tab.dim(tmp)-3 2];...
[sum(pos([1 3]))-2 pos(2)+1 1 pos(4)-3];[tab.pos(1:3)+[1 1 -2] 1];[pos(1:2)+[1 1] 1 pos(4)-3]; ...
[pos(1)+1 sum(pos([2 4]))-3 pos(3)-2 1];[sum(pos([1 3]))-1 pos(2) 1 pos(4)-1]; ...
[tab.pos(1:3) 1];[pos(1:2) 1 pos(4)-1];[pos(1) sum(pos([2 4]))-2 pos(3) 1]};
clr = {[tab.CurrBackColor];[(tab.CurrBackColor)*.7];[(tab.CurrBackColor)*.7]; ...
[(tab.CurrBackColor)*.8+[.2 .2 .2]];[(tab.CurrBackColor)*.8+[.2 .2 .2]]; ...
[(tab.CurrBackColor)*.2];[(tab.CurrBackColor)*.2]; ...
[(tab.CurrBackColor)*.5+[.5 .5 .5]];[(tab.CurrBackColor)*.5+[.5 .5 .5]]};
set(handles.(tab.tag)(2:end-length(tab.names)-2), ...
{'Position'},pos, ...
{'BackgroundColor'},clr, ...
{'ForegroundColor'},clr)
%
% tabs
pos = [];
for i=1:length(tab.names)
tmp = tab.outbreak*strcmp(tab.names{i},tab.current);
tmp1 = [tab.outlet(1) tab.dim];
pos{i} = [tab.pos(1)+sum(tmp1(1:i)) tab.pos(2)+tab.pos(4)-tab.height-tab.outbreak tab.dim(i) tab.height+tmp];
end% for
set(handles.(tab.tag)(end-length(tab.names)-1:end-2), ...
'backgroundcolor',tab.BackColor, ...
'foregroundcolor',tab.ForeColor, ...
{'position'},pos(end:-1:1)', ...
{'String'},tab.names(end:-1:1)');
%
% current tab
set(findobj(handles.(tab.tag)(end-length(tab.names)-1:end-2),'String',tab.current), ...
'BackgroundColor',tab.CurrBackColor, ...
'ForegroundColor',tab.CurrForeColor, ...
'FontWeight','bold', ...
'Enable','inactive');
%
set(handles.(tab.tag)(end),'visible','off','UserData',tab)
%
%
% TabPanel Contructor User Interface
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function TPConstructor(fig,figname,tab,handles)
%-------------------------------------------------------------------------------
%
% delete existing constructors
try
tmp = fieldnames(handles);
delete(handles.(tmp{strncmp(tmp,'constructor_',12)}))
end% try
UpdateTabpanel(fig,tab,guihandles(fig));
hgsave(fig,figname)
%
%
% gerechnet von der unteren rechten Ecke des Tabpanels
ypos = -3;
xpos = 2;
%
% constructor
h(1) = uicontrol('Parent',fig,'Style','edit','Tag',['constructor_' tab.tag], ...
'BackgroundColor',[1 1 1], 'Visible', 'off', ...
'units','pixels','position',[sum(tab.pos([1 3]))-139-xpos tab.pos(2)-ypos-1 139 19]);
%
% info
h(2) = uicontrol('Parent',fig,'Style','pushbutton','Tag', ...
['constructor_' tab.tag], 'Callback',['tabpanel(get(gcf,''Name''),''' tab.tag ''',''info'')'], ...
'BackgroundColor',[0 0 0],'ForegroundColor',[1 1 1],'FontWeight','bold','String','i',...
'ToolTipString','finisches edit mode', 'Visible', 'off', ...
'units','pixels','position',[sum(tab.pos([1 3]))-17-xpos tab.pos(2)-ypos 15 16]);
%
% setting
hv = get(fig,'HandleVisibility');
set(fig,'HandleVisibility','on')
cmenu = uicontextmenu('Tag',['constructor_' tab.tag]);
set(fig,'HandleVisibility',hv);
h(3) = uicontrol('Parent',fig,'Style','pushbutton','Tag',['constructor_' tab.tag], 'Enable','inactive', ...
'Callback','tabpanel(get(gcf,''Name''),''color'')', 'Visible', 'off', ...
'BackgroundColor',[1 1 0.85],'ForegroundColor',[0.25 0.25 0.25],'String','settings',...
'ToolTipString','use right mouse button to change colors','uicontextmenu', cmenu, ...
'units','pixels','position',[sum(tab.pos([1 3]))-61-xpos tab.pos(2)-ypos 44 16]);
uimenu(cmenu,'Label','current tabname', 'Callback', ['tabpanel(get(gcf,''Name''),''' tab.tag ''',''size'')']);
uimenu(cmenu,'Label','font options', 'Callback', ['tabpanel(get(gcf,''Name''),''' tab.tag ''',''font'')']);
uimenu(cmenu,'Label','general settings', 'Callback', ['tabpanel(get(gcf,''Name''),''' tab.tag ''',''height'')']);
uimenu(cmenu,'Label','backgroundcolor for current panel', 'Callback', ['tabpanel(get(gcf,''Name''),''' tab.tag ''',''CurrBackColor'')'],'separator','on');
uimenu(cmenu,'Label','font color for current panel', 'Callback', ['tabpanel(get(gcf,''Name''),''' tab.tag ''',''CurrForeColor'')']);
uimenu(cmenu,'Label','backgroundcolor for other tabpanel', 'Callback', ['tabpanel(get(gcf,''Name''),''' tab.tag ''',''BackColor'')']);
uimenu(cmenu,'Label','font color for other tabpanels', 'Callback', ['tabpanel(get(gcf,''Name''),''' tab.tag ''',''ForeColor'')']);
%
% update
h(4) = uicontrol('Parent',fig,'Style','pushbutton','Tag',['constructor_' tab.tag], ...
'Callback',['tabpanel(get(gcf,''Name''),''' tab.tag ''',''update'')'], 'Visible', 'off', ...
'BackgroundColor',[1 0.85 0.85],'ForegroundColor',[0.25 0.25 0.25],'String','update',...
'ToolTipString','update changed tabpanel', ...
'units','pixels','position',[sum(tab.pos([1 3]))-104-xpos tab.pos(2)-ypos 43 16]);
%
% edit
h(5) = uicontrol('Parent',fig,'Style','pushbutton','Tag',['constructor_' tab.tag], ...
'Callback',['tabpanel(get(gcf,''Name''),''' tab.tag ''',''edit'')'], 'Visible', 'off', ...
'BackgroundColor',[0.8 1 0.8],'ForegroundColor',[0.25 0.25 0.25],'String','edit',...
'ToolTipString','open guide to edit tabpanel', ...
'units','pixels','position',[sum(tab.pos([1 3]))-137-xpos tab.pos(2)-ypos 33 16]);
set(h,'Visible','on')
drawnow
%
%
%
% Aufbau der Grundelemente
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function TabBuildUp(fig,figname,tab,handles)
%-------------------------------------------------------------------------------%
h = [];
%
% axes background
pos = tab.pos-[0 0 0 tab.height+tab.outbreak-3];
h{end+1} = axes('parent',fig,'units','pixels','position',pos+[0 1 -1 -2],'HandleVisibility','off', ...
'Tag',tab.tag,'Box','on','color',tab.CurrBackColor, ...
'XTickLabel',[],'YTickLabel',[],'XTick',[],'YTick',[]);
%
% handle-Vektor
for i=1:length(tab.names)
h{end+1} = uicontrol('Parent',fig, ...
'Style','pushbutton', ...
'Tag',tab.tag,'String',tab.names{i}, ...
'Callback',tab.Callback);
end% if
%
% background
for i={'ah' 'ah' 'ad' 'ad' 'ih' 'ih' 'id' 'id' 'hide'}
h{end+1} = uicontrol('Parent',fig, ...
'Style','text', ...
'Tag',tab.tag, ...
'String',['back' char(i)], ...
'Enable','inactive', ...
'units','pixels');
end% for
%
% warnung
h{end+1} = uicontrol('Parent',fig,'Style','text','Tag',tab.tag,'String', ...
{'TABPANEL' '!!! CHANGE NOTHING !!!' '' 'usage for editing tabpanel' ...
'---------------------------------------------------------' ...
['tabpanel(''' figname ''',''' tab.tag ''')']}, ...
'Enable','inactive', 'units','pixels','position',get(handles.(tab.tag)(end),'Position'), ...
'BackgroundColor',[.2 .2 .2],'foregroundcolor',[1 .25 0],'Visible','off','FontSize',8,'UserData',[tab.tag '_warning']);
%
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -