Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions chapter-04/contents.texinfo
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ layout := window layoutMorph.
layout padding: 10.
window
openInWorld;
morphExtent: 300 @@ layout minimumExtent y.}
morphExtent: 400 @@ layout minimumExtent y.}

@smalltalkMethod{toggleColor,
layout color: (
Expand All @@ -84,6 +84,8 @@ to see its tooltip (a.k.a balloon text).
Click the "Toggle" button several times and
note how the window background color changes.

@figure{ButtomDemo window, ch04-buttondemo-window, 4}

@cindex widget @subentry menu
@node Menu
@section Menu
Expand All @@ -109,13 +111,13 @@ PopUpMenu inform: 'Something interesting just happened.'.}

@figure{A pop up menu to answer Yes or No, ch04-popupmenu-confirm, 4}

@smalltalkExampleCaption{Yes or No pop up menu,popupMenu2,
@smalltalkExampleCaption{Yes or No pop up menu, popupMenu2,
likesIceCream := PopUpMenu confirm: 'Do you like ice cream?'.
likesIceCream print. "prints true or false"}

@figure{A pop up menu to select among two choices, ch04-popupmenu-confirm-truechoice-falsechoice, 4}

@smalltalkExampleCaption{Two choices pop up menu,popupMenu3,
@smalltalkExampleCaption{Two choices pop up menu, popupMenu3,
likesIceCream := PopUpMenu
confirm: 'Do you like ice cream?'
trueChoice: 'Love it!'
Expand All @@ -126,42 +128,41 @@ likesIceCream print. "prints true or false"}

@smalltalkExampleCaption{Many choices pop up menu, popupMenu4,
color := PopUpMenu withCaption: 'Choose a color.' chooseFrom: #('red' 'green' 'blue').
color print. "prints choice index 1@comma{} 2@comma{} or 3"}
color print. "prints choice to the Transcript as an index 1@comma{} 2@comma{} or 3"}

@cindex widget @subentry menu @subentry selection
@subsection Selection menu

The @class{SelectionMenu} class is a subclass of @class{PopupMenu}; it
gives a bit more flexibility to the developer. Indeed, once the user
selects a menu entry, instead of returning this index entry as
@class{PopUp Menu} does, it returns an associated object to this
@class{PopUpMenu} does, it can return an associated object to this
entry. It is therefore more flexible.

In our example we want a color object instead of an index. To do so, we tell
@class{SelectionMenu} about a collection of colors from which to obtain the
returned value depending on the user-selected menu entry.

For example:

@smalltalkExampleCaption{Selection menu@comma{} index answer,popupMenu5,
@smalltalkExampleCaption{Selection menu with object answer, popupMenu5,
labels := #('Red sky at sunset' 'A Clockwork Orange'
'Yellow submarine' 'Green peace' 'The Blue dot' 'Purple rain').
lines := #(3 6). "draw lines after these indexes"
menu := SelectionMenu labels: labels lines: lines.
colors := @{Color red . Color orange . Color yellow . Color green . Color blue . Color purple@}.
menu := SelectionMenu labels: labels lines: lines selections: colors.
selection := menu startUpMenu.
selection print. "prints the selected menu entry index"}

Still returns the index of the selected menu entry, which may not be very
helpful.
selection print. "prints the selected menu entry's object"}

@figure{A selection menu without title, ch04-selectionmenu, 3}

What we want is a color object instead of an index. To do so, we tell
@class{SelectionMenu} about a collection of colors from which to obtain the
returned value depending on the user-selected menu entry.
If you would rather return the index of the selected menu entry, simply call
the @class{SelectionMenu} class's instance creation method @method{labels:lines:}
instead. To do so, remove the line beginning with 'colors' in our example above
and replace the line beginning with 'menu' with this line:

@smalltalkExampleCaption{Selection menu@comma{} value answer,popupMenu6,
@dots{}
colors := @{Color red . Color orange. Color yellow . Color green . Color blue . Color purple@}.
menu := SelectionMenu labels: labels lines: lines selections: colors.
selection := menu startUpMenu.
selection print. "prints the selected color"}
@smalltalkExampleCaption{Selection menu with index answer, popupMenu6,
menu := SelectionMenu labels: labels lines: lines. "replaces previous menu line"}

In the following example, we demonstrate a use case of
@class{SelectionMenu} in a @class{MenuDemo} class.
Expand Down Expand Up @@ -199,7 +200,7 @@ appropriate selection of colors from which to pick an answer.
@return{} SelectionMenu
labels: #('Red sky at sunset' 'A Clockwork Orange' 'Yellow submarine' 'Green peace'
'The Blue dot' 'Purple rain')
selections: @{Color red . Color orange. Color yellow . Color green . Color blue . Color purple@}}
selections: @{Color red . Color orange . Color yellow . Color green . Color blue . Color purple@}}

@figure{A selection menu open, ch04-selectionmenu2, 6}

Expand Down
Binary file added chapter-04/img/ch04-buttondemo-window.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading