Skip to content

Instantly share code, notes, and snippets.

@seandenigris
Last active January 9, 2020 10:23
Show Gist options
  • Save seandenigris/4981414 to your computer and use it in GitHub Desktop.
Save seandenigris/4981414 to your computer and use it in GitHub Desktop.
Pharo: Dynamically Create a UI with Spec
"Requires at least the Spec version from Pharo 2.0"
| layout widget |
model := DynamicComposableModel new.
layout := SpecLayout composed.
layout newColumn: [ :col |
{1. 2. 3} do: [:e | | selector |
selector := ('accessorTo', e asString) asSymbol.
model instantiateModels: {selector. #TextInputFieldModel}.
widget := model perform: selector.
widget text: e asString.
col newRow: [ :r | r add: selector ] height: 25 ].
model instantiateModels: {#addButton. #ButtonModel}.
widget := model addButton.
widget
label: 'Add 4';
action: [ ].
col newRow: [ :r | r add: #addButton ] height: 30 ].
model openWithSpecLayout: layout.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment