- In terminal, run
elm package install elm-lang/mouse - Also run
elm package install elm-lang/keyboard
- Rename the module MouseFollow
- Import Mouse and Keyboard
- In the definition of
main, changeApp.beginnerProgramtoApp.program - In the argument of
App.program, changemodel = modeltoinit = init - Add
subscriptions = subscriptionsto the argument ofApp.program
- Below the model, add a new type declaration for
init- We want
initto be a tuple containing aModeland aCmd Msg
- We want
- Define
initto be a tuple containingmodelandCmd.none
- Below
update, add a new type declaration forsubscriptions- We want
subscriptionsto accept aModeland return aSub Msg
- We want
- Define
subscriptionsto take an argumentmodeland returnSub.none
- Remove
DisplayTogglefrom the type declaration ofMsg - Also remove the
DisplayTogglecase from the definition ofupdate - Change the type declaration of
updateto return a tuple containing aModeland aCmd Msg - In the
NoOpcase ofupdate, return a tuple containingmodelandCmd.none
- Remove
viewListItemand its type declaration - In the
view, output an emptydiv
- Change the type declaration of
model- Remove the current properties
- Add
xandyas integers - Add
codeas a string
- Change the definition of
model- Set
xandyto be zero - Set
codeto be the string containing the number one
- Set
- Import
Html.Attributesexposing(..) - Style the
divin the view:- Give it a
1pxblack border - Set the
displaytoinline-block - Set its
positiontoabsolute - Give it
10pxofpadding
- Give it a
- Give it some dynamic features:
- Set the
leftpositioning tox - Set the
toppositioning toy - Use
codeas the contents
- Set the
- Add
MouseMsgandKeyMsgto the type declaration ofMsgMouseMsgtakes an argument of typeMouse.PositionKeyMsgtakes an argument of typeKeyboard.KeyCode
- Add
MouseMsgto theupdatecase with an argument namedposition:- Change
xtoposition.x - Change
ytoposition.y - Include
Cmd.nonein the returned tuple
- Change
- Add
KeyMsgto theupdatecase with an argument namedkeycode:- Change
codeon the model to the string version ofkeycode - Include
Cmd.nonein the returned tuple
- Change
- Replace
Sub.nonewithSub.batch, which takes a list as its argument - Add
Mouse.movesto the list, withMouseMsgas its argument - Add
Keyboard.downsto the list, withKeyMsgas its argument