Go to the first, previous, next, last section, table of contents.

Label in action

Labels are from the outset not interactive, only allowing the (dynamic) display of text strings. Using a device event encapsulator, making them come alive is quite simple:


module Main(main) where

import Concurrent
import Haggis

coordTrack :: DC -> IO DisplayHandle
coordTrack dc =
 label "(0,0)" dc      >>= \ (lab,dh) ->
 catchDeviceEv True dh >>= \ (idev,dh') ->
 let
  trackPointer =
   getDeviceEv idev >>= \ev ->
   let
    pos = getEvCoord ev
   in
   setLabel lab (show pos) >>
   trackPointer
 in
 forkIO trackPointer >>
 return dh'

main  :: IO ()
main =
 mkDC []         >>= \dc ->
  coordTrack dc  >>= \dh ->
 realiseDH dc dh

Coordinate tracker

A label component is created using the label function, which requires the initial string to display. The details of how we can catch device input on an arbitrary component is covered well elsewhere (@xref{InputDevice} for more inexampleion), but the above example uses the catchDeviceEv to divert all device input destined for the Label.

To track the position of the pointer within the Label area, a little process is created which keeps the Label string displayed consistent with the current position of the mouse pointer.


Go to the first, previous, next, last section, table of contents.