HeinrichApfelmus / threepenny-gui

GUI framework that uses the web browser as a display.
https://heinrichapfelmus.github.io/threepenny-gui/
Other
437 stars 77 forks source link

mouse coordinates only using pageX and pageY #166

Closed jerbaroo closed 7 years ago

jerbaroo commented 7 years ago

I have attached images showing the previous behaviour and the updated behaviour in both Chrome and Electron.

The code used displays a div with text "foo" at the coordinates where the right-click took place. In each case the right click actually took place on the "s" of "Proofs".

Electron before electron-err

Electron after electron-fix

Chrome before chrome-err

Chrome after chrome-fix

jerbaroo commented 7 years ago

Reading the documentation I realised the previous behaviour was the intended behaviour.

However exposing some more of the event data to the user would be helpful.

It seems at first, for my use-case, like I could use the previous behaviour and get the coordinates relative to the source element, and then attach the foo div relative to the source element. However I need to set a high z-index on the foo div, but in CSS you cannot set a z-index of a child greater than a parent, so I'm attaching the foo div to the HTML body.

My revised suggestion @HeinrichApfelmus would be to return a data type with multiple fields, from all events, something like:

-- (not all fields covered here)
data EventData = EventData {
    ePageX   :: Maybe Int
  , ePageY   :: Maybe Int
  , eOffsetX :: Maybe Int
  , eOffsetY :: Maybe Int
  , eWhich   :: Maybe Int
  , eValue   :: Maybe String
}

To not break the API the existing event functions like mousemove could extract the relevant field.