Property Inspector for custom classes

6 views (last 30 days)
.json
.json on 11 Nov 2024
Commented: .json on 18 Dec 2024
I'd like to use Property Inspector to be able to edit custom classes. From what I can see, this works (i.e., I can type "inspect(obj)" and edit properties) as long as the classes are handle classes, but it doesn't seem as effective as for some built-in classes. For example:
  • If I look at Figure of Axes objects in Property Inspector, properties are listed in groups. This doesn't occur for my custom classes even if I inherit matlab.mixin.CustomDisplay and implement getPropertyGroups (which enables grouping of properties in the command window display of a class).
  • Editors are sensible for integers, logicals etc. Figures etc have nice specialised editors for colours, fonts, etc. Is there any way that I can reuse those?
I've attached a picture showing an example of what I'm meaning for the plot line inspector--showing the sections (e.g. "Color and Styling", "Markers", etc) for the different properties, and the special editor used for the line colour.
  3 Comments
.json
.json on 16 Dec 2024
No; for clarity I've updated the question removing the part about arrays (which work fine--I'd mistakenly used an array of shallow copies of the same object handle rather than deep copies); the other two items remain unresolved.

Sign in to comment.

Accepted Answer

Kanishk
Kanishk on 18 Dec 2024
I understand you want to group properties in the Property Inspector and require a way to have rich editors for colors, fonts and more. Analyzing the documentation and code available for the Property inspector, I get that some features of the Property Inspector are specifically designed to cater the graphics objects which provides features like grouping and rich editors.
To get editors for color and font, a simple app in appdesigner can be designed with "uicolorpicker" and "uisetfont". To demonstrate, I have made simple class and placed a very naive condition in the app to check if the field requires the color picker. I have attached the app the in the answer and here is the code for the custom class.
classdef MyCustomClass < handle
properties
Property1
Property2
Color(3,1) double
isvalid logical
end
methods
function obj = MyCustomClass(prop1, prop2)
obj.Property1 = prop1;
obj.Property2 = prop2;
obj.Color = [0 1 1];
obj.isvalid = true;
end
end
methods(Static)
function y = add
y = obj.Property1+obj.Property2;
end
end
end
To run the app with a class object,
>> obj = MyCustomClass(10,20);
>> inspectApp(obj)
This launches the following app:
For grouping Properties, I was not able to come with a simple solution. One idea is to design groupings of properties in HTML and using "uihtml" to show in the app designer.
I also found some MATLAB File Exchange submissions which might be of help.
Happy Coding!
  1 Comment
.json
.json on 18 Dec 2024
Thanks, that's a reasonable approach to get around the limitations

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!