Clear Filters
Clear Filters

Class instance inherited from `matlab.mi​xin.Custom​Display` is not displayed as struct in Variable Editor.

1 view (last 30 days)
Hi folks,
I am trying to create a base class from which every other class in my project should inherit. This class should contain just a few properties and some simple methods that should be common to all objects in the project. One of the functionalities I would like to implement is a custom order/selection of the display of properties, as explained in the documentation e.g. here and here.
I believe I have correctly inherited from the 'matlab.mixin.CustomDisplay' class and overloaded the methods 'getPropertyGroups' and 'properties', because the order and selection is altered as desired. However, one thing is wrong: whenever I open my objects in the Variable Editor (e.g. with 'openvar'), only text is displayed (Figure 1) instead of the traditional 'struct' visualization that allows me to explore each property individually (Figure 2).
Figure 1 Figure 1 (Variable Editor when CustomDisplay is implemented)
Figure 2 Figure 2 (Variable Editor when CustomDisplay is not implemented)
For clarity, I am adding here my overloaded methods (Access = protected), based on the comments found here. The 'order_properties' method is just a variation of the suggestion found here.
function all_props = properties(this)
if nargout == 0
disp(builtin("properties",this));
else
all_props = order_properties(this);
end
end
function property_list = getPropertyGroups(this)
if ~isscalar(this)
list = getPropertyGroups@matlab.mixin.CustomDisplay(this);
property_list = list;
else
all_props = properties(this);
n_props = length(all_props);
args = cell(2,n_props);
for p = 1 : n_props
args{1,p} = all_props{p};
args{2,p} = this.(all_props{p});
end
args = struct(args{:});
property_list = matlab.mixin.util.PropertyGroup(args);
end
end
Any advice on how to fix this, or at least try to understand the source of the problem, is greatly appreciated.
Thank you,
P.S.: I am unsure whether my question is related to this bug, nor if it has already been fixed.
  1 Comment
Michael Kirsch
Michael Kirsch on 12 May 2022
Hi Tiago,
the documentation you are referring to is that of the CustomDisplay class, the purpose of which is to alter the presentation of the class when an instance is invoked to present its contents in the MATLAB command line window or the output pane of a MATLAB Live Editor Script. Using this class does not alter the presentation in the variable editor.
Changing the order of the properties in the variable editor is not supported as of MATLAB R2022aU1, they are always presented (when publicly accessible) in the order they are defined in the class. Derived classes present their properties first and then those of the class they are derived from.
The variable editor falls back to the text-based presentation because you are overriding the "properties" method which is not documented and leads to the editor being non-interactive.
Kind regards,
Michael

Sign in to comment.

Answers (0)

Categories

Find more on Software Development Tools in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!