I'd like to customize some of the MATLAB uicontrols (such as the drop-down box) to give them more user-friendly functionality.
My question is: Is it possible to extend/inherit the uicontrol? If so, how do you do it? If not, is there a workaround?
I have tried this basic code just to get it setup, but I receive the following error:
The specified super-class 'uicontrol' contains a parse error or cannot be found on
MATLAB's search path, possibly shadowed by another file with the same name.
classdef ComboBox < uicontrol
methods(Access = public)
function obj = ComboBox()
set(obj, 'Style', 'popup');
end
end
end
The error occurs when I try to add it to a figure:
cmb = ComboBox();
set(cmb, 'Parent', obj.ui_figure);
Edit: After thinking about it, I think this would be a decent workaround, however, I'd still like to know how to extend uicontrol if it's possible.
classdef ComboBox < uicontrol
properties(Access = public)
Control;
end
methods(Access = public)
function obj = ComboBox(parent, items)
obj.Control = uicontrol();
set(obj.Control, 'Style', 'popup');
set(obj.Control, 'Parent', parent);
set(obj.Control, 'String', items);
end
end
end
There is no documented way (as of R2013a) to write subclasses to MATLAB Handle Graphics classes. In fact, because of the way MATLAB stores the hg objects, we can't even get the class of an hg object easily. For example:
One solution to this is to write a class which subclasses either
handle
, orhgsetget
, and keeps a handle to a uicontrol object as a private property. For example:You can then use the
ComboBox
as you would any otheruicontrol
handle:There are undocumented ways of extending handle graphics classes, but I'm not familiar with them. Check out this reference: http://undocumentedmatlab.com/blog/introduction-to-udd/