From 4520e1e1d438c6eb3d12e6fba0cbe5d1f45be9b1 Mon Sep 17 00:00:00 2001 From: sakul-45 <81963567+sakul-45@users.noreply.github.com> Date: Wed, 7 Jul 2021 12:48:39 +0200 Subject: [PATCH] Function for testing handling of figures with UI --- figure_testing.m | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 figure_testing.m diff --git a/figure_testing.m b/figure_testing.m new file mode 100644 index 0000000..edf9598 --- /dev/null +++ b/figure_testing.m @@ -0,0 +1,65 @@ +%% function for testing of uifigures and buttons +function [] = figure_testing() +%% figure with "Apply", "Reset" and "Done" button +%create figure +fig = figure; +fig.Name = 'Test Window'; +fig.Units = 'Normalized'; +fig.Position = [.2 .2 .6 .6]; +fig.Tag = 'Test Window'; + +%create push buttons +a = uicontrol(fig,'Style','pushbutton'); +a.String = 'Apply'; +a.Units = 'Normalized'; +a.Position = [.52 .01 .15 .05]; +a.FontUnits = 'Normalized'; +a.FontSize = 0.6; +a.Tag = 'Apply'; +a.Callback = @ApplyButtonPushed; + +r = uicontrol(fig,'Style','pushbutton'); +r.String = 'Reset'; +r.Units = 'Normalized'; +r.Position = [.68 .01 .15 .05]; +r.FontUnits = 'Normalized'; +r.FontSize = 0.6; +r.Tag = 'Reset'; +r.Callback = @ResetButtonPushed; + +d = uicontrol(fig,'Style','pushbutton'); +d.String = 'Done'; +d.Units = 'Normalized'; +d.Position = [.84 .01 .15 .05]; +d.FontUnits = 'Normalized'; +d.FontSize = 0.6; +d.Tag = 'Done'; +d.Callback = @DoneButtonPushed; + +%create input field +inp = uicontrol(fig,'Style','edit'); +inp.Units = 'Normalized'; +inp.Position = [.01 .01 .5 .05]; +inp.HorizontalAlignment = 'left'; +inp.FontUnits = 'Normalized'; +inp.FontSize = 0.6; +% inp.Tag = 'input'; + +uicontrol(inp); %passes focus to input + +%% Callback functions + function ApplyButtonPushed(src,event) + out = get(inp,'String'); + txt = strcat("Applied correction by ",out," points!"); + disp(txt) + end + + function ResetButtonPushed(src,event) + disp('Resetted data!') + end + + function DoneButtonPushed(src,event) + close 'Test Window' + end + +end