UIFigure button callbacks not working when cursor over uiimage (R2020b)

5 Ansichten (letzte 30 Tage)
Adam Snyder
Adam Snyder am 15 Dez. 2020
I really just need WindowButtonMotionFunction to work, but it doesn't:
classdef SIMineyCricket < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
SwitchLabel matlab.ui.control.Label
Switch matlab.ui.control.Switch
cricketImage matlab.ui.control.Image
refPinImage matlab.ui.control.Image
DataStreamAxes matlab.ui.control.UIAxes
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
app.UIFigure.UserData = struct('clickedObject',{[]},'lastPosition',{[]});
end
% Window button motion function: UIFigure
function UIFigureWindowButtonMotion(app, event)
disp(randi(10));
if ~isempty(app.UIFigure.UserData.clickedObject)
app.UIFigure.UserData.clickedObject.Position = [app.UIFigure.CurrentPoint,app.UIFigure.UserData.clickedObject.Position(3:4)];
end
end
% Image clicked function: refPinImage
function refPinImageClicked(app, event)
disp('clicked pin')
if ~isempty(app.UIFigure.UserData.clickedObject)
%drop object
app.UIFigure.UserData.clickedObject = [];
else
%pick up object
app.UIFigure.UserData.clickedObject = event.Source;
end
end
% Window button down function: UIFigure
function UIFigureWindowButtonDown(app, event)
display(app.UIFigure.CurrentPoint);
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 679 481];
app.UIFigure.Name = 'MATLAB App';
app.UIFigure.WindowButtonDownFcn = createCallbackFcn(app, @UIFigureWindowButtonDown, true);
app.UIFigure.WindowButtonMotionFcn = createCallbackFcn(app, @UIFigureWindowButtonMotion, true);
% Create SwitchLabel
app.SwitchLabel = uilabel(app.UIFigure);
app.SwitchLabel.HorizontalAlignment = 'center';
app.SwitchLabel.Position = [605 190 42 22];
app.SwitchLabel.Text = 'Switch';
% Create Switch
app.Switch = uiswitch(app.UIFigure, 'slider');
app.Switch.Position = [603 227 45 20];
% Create cricketImage
app.cricketImage = uiimage(app.UIFigure);
app.cricketImage.Position = [11 15 341 222];
app.cricketImage.ImageSource = 'cricket.jpg';
% Create refPinImage
app.refPinImage = uiimage(app.UIFigure);
app.refPinImage.ImageClickedFcn = createCallbackFcn(app, @refPinImageClicked, true);
app.refPinImage.Position = [351 161 72 76];
app.refPinImage.ImageSource = 'pin.png';
% Create DataStreamAxes
app.DataStreamAxes = uiaxes(app.UIFigure);
title(app.DataStreamAxes, 'Data Stream')
xlabel(app.DataStreamAxes, 'time (s)')
ylabel(app.DataStreamAxes, 'mV')
app.DataStreamAxes.ColorOrder = [0 0.447 0.741;0.85 0.325 0.098;0.929 0.694 0.125;0.494 0.184 0.556;0.466 0.674 0.188;0.301 0.745 0.933;0.635 0.078 0.184];
app.DataStreamAxes.TickDir = 'out';
app.DataStreamAxes.Tag = 'DataStream';
app.DataStreamAxes.Position = [11 246 659 226];
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = SIMineyCricket
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end

Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by