|
% Here's a less than ideal solution:
function testgui
f=figure;
ed=uicontrol('Parent',f,...
'Units','normalized',...
'Position',[0.3 0.45 0.2 0.1],...
'String','0',...
'BackgroundColor','white');
pb=uicontrol('Parent',f,...
'Units','normalized',...
'Position',[0.3 0.3 0.2 0.1],...
'String','Inc by 1',...
'ToolTip','Right-click to change increment amount',...
'ButtonDownFcn',{@pb_ButtonDownFcn},...
'Callback',{@pb_Callback,1});
function pb_Callback(src,eventdata,varargin)
% varargin is amount to increment by
str=get(ed,'String');
num=str2double(str);
newnum=num+varargin{1};
set(ed,'String',num2str(newnum));
end
function pb_ButtonDownFcn(src,eventdata)
str=get(pb,'String');
if strcmp(str,'Inc by 1');
set(pb,'String','Inc by 10');
set(pb,'Callback',{@pb_Callback,10});
else
set(pb,'String','Inc by 1');
set(pb,'Callback',{@pb_Callback,1});
end
end
end
% This could be expanded by adding a context menu with several increment values
% (1, 10, 100, etc), where the callback resets the string and callback properties
% of the pushbutton. But this doesn't catch <Shift> like you wanted.
|