Developing UI Component Classes | post-setup initialisation method ?
Show older comments
¿Does there exist (or is there a way of defining) a method which executes:
- once only;
- after the setup method;
- before the update method?
Motivation is (irreversible) object initialisation conditional on one or more property values passed to the constructor.
To this end, the setup method is unsuitable since
"Any property values passed as name-value pair arguments to the UI component's constructor method are assigned after the setup method executes."
The update method is by definition, not a one-shot method.
Accepted Answer
More Answers (1)
Greg
on 15 Apr 2021
1 vote
Your part about "before the update method" is a moving target. The update method is supposed to execute during a graphics flush (i.e., drawnow or pause calls). So depending on the code, your update method might occur more often than another.
In my componentcontainers, I've found the update method completely useless (and even detrimental). I leave it blank, and build my own method named draw that I can call if and when I want it to execute. A trick I use to accomplish the "do stuff before update" is a "skipUpdate" property. Define it as true by default, then the bottom of the constructor sets it to false. Inside the update method, the very first thing is if obj.skipUpdate;return;end.
1 Comment
Categories
Find more on App Building 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!