Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/mobile/event/mouse: proposal: embed image.Point in Event #14027

Closed
jnjackins opened this issue Jan 20, 2016 · 4 comments
Closed

x/mobile/event/mouse: proposal: embed image.Point in Event #14027

jnjackins opened this issue Jan 20, 2016 · 4 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@jnjackins
Copy link
Contributor

mouse.Event currently looks like this:

type Event struct {
    // X and Y are the mouse location, in pixels.
    X, Y float32

    // Button is the mouse button being pressed or released. Its value may be
    // zero, for a mouse move or drag without any button change.
    Button Button

    // Modifiers is a bitmask representing a set of modifier keys:
    // key.ModShift, key.ModAlt, etc.
    Modifiers key.Modifiers

    // Direction is the direction of the mouse event: DirPress, DirRelease,
    // or DirNone (for mouse moves or drags).
    Direction Direction
}

What is the purpose of using float32 for X and Y? Is it ever the case that sub-pixel information is needed for mouse events?

I propose that we instead embed image.Point, as in https://godoc.org/9fans.net/go/draw#Mouse, to ease the following kind of code:

// ev is a mouse.Event
if ev.Point.In(myWidget.Bounds()) {
    ev.Point = ev.Point.Sub(myWidget.Bounds().Min)
    myWidget.SendMouseEvent(ev)
}

I would appreciate any comment on the reasoning behind the current approach, and whether my proposed approach could work. Thanks!

@jnjackins
Copy link
Contributor Author

FYI @crawshaw @nigeltao

@nigeltao
Copy link
Contributor

Android's underlying events have sub-pixel precision: http://developer.android.com/reference/android/view/MotionEvent.html#getX() returns a float, not an int.

I am less day-to-day familiar with OS X and iOS, but I believe that they are also sub-pixel precision. For example, older iOS apps made for a 1024x768 logical resolution are mapped to modern iOS hardware's 2048x1536 physical resolution by multiplying or dividing everything by 2, and similarly on Retina desktops, so that you can get half-pixel mouse event locations.

@bradfitz bradfitz added this to the Unreleased milestone Jan 21, 2016
@bradfitz
Copy link
Contributor

ping @nigeltao. Please make a decision on this.

@bradfitz bradfitz added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Aug 22, 2016
@nigeltao
Copy link
Contributor

My decision is to leave the fields as they are: float32 values.

If it really is onerous, we could introduce an Event.Point method that returns an image.Point, but there is the question of whether that should round down or round to nearest. It seems easier (and in my experience, not onerous) to let the programmer write exactly what they want when converting to an image.Point.

@golang golang locked and limited conversation to collaborators Aug 25, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

4 participants