Property Inspector for custom classes

5 vues (au cours des 30 derniers jours)
.json
.json le 11 Nov 2024
Commenté : .json le 18 Déc 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 commentaires
Abhas
Abhas le 6 Déc 2024
Hi @.json,
Is your issue resolved?
.json
.json le 16 Déc 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.

Connectez-vous pour commenter.

Réponse acceptée

Kanishk
Kanishk le 18 Déc 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 commentaire
.json
.json le 18 Déc 2024
Thanks, that's a reasonable approach to get around the limitations

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Object Properties dans Help Center et File Exchange

Produits


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by