File: ef230-2023-08/www/examples/menuplus.m Download

function main
% test menuplus NOT FINISHED
clc;
menu_plus('My title',{'option 1','option 2','opt 3'})

function r = menu_plus(menutitle,options)
global G;
G.button=0;
G.text='';
scrsz = get(0,'ScreenSize');
sw = scrsz(3);
sh = scrsz(4);
bw=100;
bh=25;
nb = length(options);
h=figure('windowstyle','modal','Position',[sw/2-bw/2,sh/2-nb*bh/2,bw,nb*bh]);
bw=100;
bh=25;
for i=1:nb
    % Create a button
    uicontrol('Style', 'pushbutton', ...
        'String', options{i},...    % text to display
        'Position', [0,(nb-i)*bh,bw,bh],...  %x,y,w,h
        'UserData',i,...
        'Callback', @button_callback); % function that gets called when button is pressed.
end
waitfor(h)
r = G.button;

function button_callback(hObject, eventdata)
global G;
G.button = get(hObject,'UserData');
G.text = get(hObject,'String');
close(gcf);
eventdata
hObject
return