Find custom graphics control object from graphics handle
2 views (last 30 days)
Show older comments
I am trying to implement a controller family, managing gui interaction. My class should replace the standard m-file created when using guide.
Currently the controller class is very simple:
classdef Figure < handle
%FIGURE Summary of this class goes here
% Detailed explanation goes here
properties
gfx
end
methods
function obj = Figure()
% create new figure
obj.gfx = matlab.ui.Figure();
end
end
end
I would now like to add other elements to my figure. Matlab graphics therefore implements a composite pattern which enables adding or removing other matlab.ui elements in a simple fashion, i.e. each element has "Parent" and "Children" references. Moreover this enables travelling up and down the tree representing the structure of the graphical user interface.
At some point I might like to find my corresponding customized controller object. But since the composite is located in matlab.ui, this is not directly accessible.
What is the best solution to achieve this?
Thanks, Daniel
3 Comments
Adam
on 27 Jan 2017
If you use savefig and openfig all you are saving and loading is the Matlab figure and its contents. The object of your 'Figure' class is not saved or reloaded at all.
To do this you would need to save it as a .mat file not saving the current figure.
I still don't understand what you define as a 'controller' though. Do you just mean the graphics object? I have various classes containing the word controller, but they contain many functions that I have written that act on figures and their components so the terminology is confusing to me in your case.
If you are referring to your Figure class as the controller then I'm not sure what you mean by 'all controller objects in the subtree' as you only have the one controller, which is your 'Figure' object.
You can access child objects via the usual method of
gfx.Children
and then onwards down the tree from there.
Accepted Answer
Steven Lord
on 27 Jan 2017
It sounds like you may be trying to do the same type of thing App Designer is doing. You may want to see if that satisfies your needs (or comes close enough that you can use the code it creates as a starting point.)
0 Comments
More Answers (0)
See Also
Categories
Find more on Graphics Object Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!