Cuis-Smalltalk offers several easy to use options for menus to inform or to ask the user to make a choice.
The class PopUpMenu provides an easy way to render a dialog that
displays information, asks the user for confirmation,
or ask the user to select an option.
It is similar to the JavaScript DOM functions alert
and confirm
.
For example:
PopUpMenu inform: 'Something interesting just happened.'.
Example 4.1: Simple pop up menu
likesIceCream := PopUpMenu confirm: 'Do you like ice cream?'. likesIceCream print. "prints true or false"
Example 4.2: Yes or No pop up menu
likesIceCream := PopUpMenu confirm: 'Do you like ice cream?' trueChoice: 'Love it!' falseChoice: 'Not for me'. likesIceCream print. "prints true or false"
Example 4.3: Two choices pop up menu
color := PopUpMenu withCaption: 'Choose a color.' chooseFrom: #('red' 'green' 'blue'). color print. "prints choice index 1, 2, or 3"
Example 4.4: Many choices pop up menu
The class StringRequestMorph prompts the user to enter a text response. It can verify the response using a provided block that returns a Boolean value indicating whether the response is valid. It can also evaluate a block if the user clicks the cancel button.
For example:
Figure 4.9: A StringRequestMorph open
StringRequestMorph request: 'Comment' initialAnswer: 'no comment' verifying: [ :answer | answer isEmpty not ] do: [ :answer | answer print ] orCancel: [ 'canceled' print ].
Example 4.7: Request a string from the user