Changing default figure toolbar button's callback in App designer
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
So I have made a simple app with the App Designer and have run into some issues. I have a figure and some buttons on the app. Issue is that when I pan the figure it does not reset the axes properly, hence, there are white borders all around my figure.
I can manually fix this by triggering app.UIAxes.XLim and YLim with values taken from the size of the actual image in the figure. The issue is how do I trigger this.
There is already a "Reset View" button in the figure but does not work. It resets the figure to some values prior to me manually fixing the XLimand YLim so there are still white borders around my image. Appanretly there is an internal function resetplotview which could be used, but it does not seem to work.
I could make one extra button to my control panel which then does my own "reset", but I was thinking that there is already a "Reset View" button in the figure itself so maybe I can just change the callback function? Well I found the button by findall(app.UIAxes.Toolbar,'Tooltip','Restore View'); but if I change the ButtonPushedFcn to my own function it just gives me this error:
Warning: Undefined function 'restoreview' for input arguments of type
'matlab.ui.controls.ToolbarPushButton'.
Error while evaluating ButtonPushedFcn for axes toolbar.
I have the restoreview function in my script file:
function restoreview(e,d)
% Default ButtonPushedFcn for the reset view toolbar button
@(e,d)matlab.graphics.controls.internal.resetHelper(d.Axes,true);
% Add our own end, which is to reset the axes manually
app.UIAxes.XLim=[0, im.XData(2)];
app.UIAxes.YLim=[0, im.YData(2)];
end
Any help?
I know I can use just a character vector as a callback and it'll execute it as command(s) but that's realllly not what I want to do.
2 Kommentare
Antworten (1)
Aaron Ward
am 19 Jan. 2021
I recently worked out another solution. Note this applies to R2020A (I haven't tested other versions). The steps are as follows:
- Create the toolbar without the 'restoreview' button.
- Create the 'restoreview' button via 'axtoolbarbtn' function.
- Create a 'ButtonPushedFcn' for the newly created button and supply the callback handle.
- In the callback function, reset the axis limits.
% step 1
app.tb = axtoolbar(app.axis, {'zoomin', 'zoomout', 'export'});
% step 2
btn = axtoolbarbtn(app.sagittal_axes_tb, 'push');
btn.Icon = 'restoreview';
% step 3
btn.ButtonPushedFcn = createCallbackFcn(app, @restoreview, true);
% step 4
function restoreview(app, event)
limits = [lower upper];
app.axis.XLim = limits;
app.axis.YLim = limits;
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Develop Apps Using App Designer 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!