When a class defines methods with the pragma magritteDescription as exemplified in How to define a Magritte form field, the message Object>>#asGtMagritteViewModel
asGtMagritteViewModel
^ GtMagritteViewModel forObject: self
will produce a view model that can then be converted into a BlElement
Object << #BlElement
traits: {TBlTransformable + TBlEventTarget + TBlDebug};
slots: {
#spaceReference .
#parent .
#children .
#bounds .
#measuredBounds .
#boundsCache .
#eventDispatcher .
#constraints .
#layout .
#transformation .
#taskQueue .
#errorHandler .
#userData .
#visuals .
#flags .
#theme };
tag: 'Core';
package: 'Bloc'
using GtMagritteViewModel>>#asElement
asElement
| aFrame |
aFrame := BrFrame new.
aFrame
hFitContentLimited;
vFitContent;
constraintsDo: [ :c |
c frame horizontal alignCenter.
c frame vertical alignCenter ];
addAptitude: (BrLayoutResizerAptitude new
exactToMatchParent: [ aFrame children ];
matchParentToMatchParent: [ aFrame children ];
fitContentToFitContent: [ aFrame children ];
fitContentLimitedToFitContentLimited: [ aFrame children ]);
withAsyncFutureDo: [ :anElementFuture |
anElementFuture
whenPending: [ :theContainer |
theContainer
addChild: (BrLabel new
fitContent;
aptitude: (BrGlamorousLabelAptitude new
foreground: BrGlamorousColors disabledButtonTextColor);
text: 'Preparing...';
constraintsDo: [ :c |
c frame horizontal alignCenter.
c frame vertical alignCenter ]) ];
whenError: [ :theContainer :anError |
theContainer userData at: self class gtMementoSymbol put: anError.
theContainer
removeChildren;
addChild: (anError asDebuggableElement
hFitContentLimited;
vFitContent;
constraintsDo: [ :c |
c frame horizontal alignCenter.
c frame vertical alignCenter ]) ];
whenSuccess: [ :theFrame :aMemento | self initializeForm: theFrame forMemento: aMemento ] ].
aFrame asyncFuture
executionConfiguration: GtMagritteBuilderUtility executionConfiguration.
aFrame asyncFuture future: self mementoFuture.
^ aFrame
.
Let’s use this example once again on GtClassCreationForm
GtBehaviorCreationForm << #GtClassCreationForm
slots: { #superclassName . #classVars . #pools };
tag: 'Forms - Models';
package: 'GToolkit-Pharo-Coder-UI'
.
Putting all that we’ve learned so far together, a form for adding a class can be produced through calling:
GtClassCreationForm new asGtMagritteViewModel asElement
This can be used within elements and stencils to cohabitate models and their respective UIs.