vlang / vlang/gui

on_hover receives absolute mouse coordinates; every other mouse callback receives relative ones

Open Beginner friendly
#81 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
V
Stars
193
Forks
19
PR merge metrics
No merged PRs in 30d

Description

Summary

on_hover is the only mouse callback that receives window-absolute coordinates. on_click, on_any_click, on_mouse_move and on_mouse_up all receive coordinates relative to the widget's own shape.

Because both hand you an Event with mouse_x / mouse_y, nothing signals the difference. Hit-testing code written against one and reused for the other silently reads the wrong position.

Where it comes from

The relative path goes through execute_mouse_callback in event_traversal.v:61, which converts before dispatch:

// Make mouse coordinates relative to layout.shape
mut ev := event_relative_to(layout.shape, e)
callback(layout, mut ev, mut w)

on_hover is dispatched from layout_hover in layout.v:145 instead, which builds a synthetic event straight from the context and never converts:

mut ev := Event{
    ...
    mouse_x: ctx.mouse_pos_x
    mouse_y: ctx.mouse_pos_y
    ...
}
on_hover := layout.shape.events.on_hover

Effect

Inside a canvas that hit-tests its own content, the two handlers need different arithmetic for the same pointer position:

on_any_click: fn (l &gui.Layout, mut e gui.Event, mut w gui.Window) {
    hit(e.mouse_x, e.mouse_y)                            // already relative
}
on_hover: fn (mut l gui.Layout, mut e gui.Event, mut w gui.Window) {
    hit(e.mouse_x - l.shape.x, e.mouse_y - l.shape.y)    // must subtract
}

Using the same expression in both compiles, runs, and quietly misses every target in one of them.

Suggestion

Either convert in layout_hover the way execute_mouse_callback does, or document the difference on on_hover. Converting looks like the smaller surprise, though it would change behaviour for anyone already compensating.

Version: gui at e699bcf, V 0.5.2, macOS arm64.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in layout.v:145 at layout_hover and compare its synthetic Event with execute_mouse_callback in event_traversal.v:61, including event_relative_to. Decide how on_hover should align with the other mouse callbacks, then verify that hit-testing receives consistent widget-relative mouse_x and mouse_y values without breaking the documented behavior.

Written by the indexing model from the issue text.

Assessment

Domain
desktop
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.