~jonegil


#572 Fwd: Detecting mouse wheel 1 year, 12 days ago

Comment by ~jonegil on ~eliasnaur/gio

It makes sense to not use image.Rectangle for ScrollBounds,

But does that explain why the behaviour for Scrolls changes when I add a handler to listen for Clicks as well?

#572 Fwd: Detecting mouse wheel 1 year, 13 days ago

Comment by ~jonegil on ~eliasnaur/gio

Thanks Elias

A minimalist version that reproduces the effect is available here. It uses gio 0.6. The program listens for scrolls in the window and prints in the terminal. https://github.com/jonegil/gui-with-gio/blob/bug-scrolling/teleprompter/code/main.go

If the event code only listens for scroll events, it catches the Y dimension as expected, including when X in ScrollBounds is 0

// Scrolled a mouse wheel?
for {
  ev, ok := gtx.Event(
    pointer.Filter{
      Target: tag,
      Kinds:  pointer.Scroll,
      ScrollBounds: image.Rectangle{
        Min: image.Point{X: 0, Y: -1},
        Max: image.Point{X: 0, Y: +1},
      },
    },
  )
  if !ok {
    break
  }
  fmt.Printf("SCROLL: %+v\n", ev)
}

Printed output, +/- 1 in Scroll.Y:

SCROLL: {Kind:Scroll Source:Mouse PointerID:0 Priority:Foremost Time:10h38m56.531s Buttons: Position:(471,276) Scroll:(0,1) Modifiers:}
SCROLL: {Kind:Scroll Source:Mouse PointerID:0 Priority:Foremost Time:10h38m56.921s Buttons: Position:(471,276) Scroll:(0,-1) Modifiers:}

However, if it also listens for pointer clicks, the Y dimension is ignored:

// Scrolled a mouse wheel?
      for {
        ev, ok := gtx.Event(
          pointer.Filter{
            Target: tag,
            Kinds:  pointer.Scroll,
            ScrollBounds: image.Rectangle{
              Min: image.Point{X: 0, Y: -1},
              Max: image.Point{X: 0, Y: +1},
            },
          },
        )
        if !ok {
          break
        }
        fmt.Printf("SCROLL: %+v\n", ev)
      }

      // Pressed a mouse button?
      for {
        ev, ok := gtx.Event(
          pointer.Filter{
            Target: tag,
            Kinds:  pointer.Press,
          },
        )
        if !ok {
          break
        }
        fmt.Printf("PRESS : %+v\n", ev)
      }

Printed output, 0 Scroll.Y

SCROLL: {Kind:Scroll Source:Mouse PointerID:0 Priority:Foremost Time:10h39m12.312s Buttons: Position:(540,422) Scroll:(0,0) Modifiers:}
SCROLL: {Kind:Scroll Source:Mouse PointerID:0 Priority:Foremost Time:10h39m12.671s Buttons: Position:(540,422) Scroll:(0,0) Modifiers:}

However, by changing the ScrollBounds to have a +/-1 X-dimension, things start working again

ScrollBounds: image.Rectangle{
  Min: image.Point{X: -1, Y: -1},
  Max: image.Point{X: +1, Y: +1},
},

the output again shows non-zero values in Scroll.Y even when I listen both for scrolls and for clicks.

SCROLL: {Kind:Scroll Source:Mouse PointerID:0 Priority:Foremost Time:10h50m26.484s Buttons: Position:(488,334) Scroll:(0,1) Modifiers:}
SCROLL: {Kind:Scroll Source:Mouse PointerID:0 Priority:Foremost Time:10h50m26.609s Buttons: Position:(488,334) Scroll:(0,-1) Modifiers:}

#572 Fwd: Detecting mouse wheel 1 year, 15 days ago

on ~eliasnaur/gio

~jonegil, can I ask you to help me pinpoint the issue by minimizing your program as much as possible? As I understand it, Chris' program works as intended, so I'm trying to locate the breaking difference from his program to yours. Thank you.

#572 Fwd: Detecting mouse wheel 1 year, 27 days ago

Comment by ~jonegil on ~eliasnaur/gio

Thank you Chris!

Yes, your program works as intended without X coordinate. If I add an explicit X it works equally well with X:0 and X: 1 (or X:-1).

Your code gives clean events:

SCROLL: {Kind:Scroll Source:Mouse PointerID:0 Priority:Foremost Time:5h18m6.992s Buttons: Position:(64.63672,46.26953) Scroll:(0,100) Modifiers:}
SCROLL: {Kind:Scroll Source:Mouse PointerID:0 Priority:Foremost Time:5h18m7.52s Buttons: Position:(64.63672,46.26953) Scroll:(0,-100) Modifiers:}

Adding a print to my original progam [1 above] and removing X or setting X in Scrollbounds to 0 gives

SCROLL: {Kind:Scroll Source:Mouse PointerID:0 Priority:Foremost Time:5h19m1.32s Buttons: Position:(476.33203,382.47656) Scroll:(0,0) Modifiers:}
SCROLL: {Kind:Scroll Source:Mouse PointerID:0 Priority:Foremost Time:5h19m1.62s Buttons: Position:(476.33203,382.47656) Scroll:(0,0) Modifiers:}
SCROLL: {Kind:Scroll Source:Mouse PointerID:0 Priority:Foremost Time:5h19m1.688s Buttons: Position:(476.33203,382.47656) Scroll:(0,0) Modifiers:}

I.e. the event registers, but the Y-value is 0.

Best regards J

#572 Fwd: Detecting mouse wheel 1 year, 29 days ago

Ticket created by ~jonegil on ~eliasnaur/gio

Detecting mouse scrolls is non intuitive.

In the example on https://gioui.org/doc/architecture/input,

// Declare tag as being one of the targets. event.Op(ops, tag)

is called before painting operations commence.

However, it this example [1], event.Op(&ops, tag) needs to be called at the very end of case app.FrameEvent:

If event.Op(&ops, tag) is called too early, for example around the lines of code where the tag is used and it contextually is natural to register it, behaviour is strange:

  • scrolls are not detected
  • however, scrolling while pressing (and not releasing) any mouse buttion works well. Strange

Finally, the scroll event in Y-direction only works if ScrollBounds has x distance as well:

 ScrollBounds: image.Rectangle{
          Min: image.Point{X: -1, Y: -1},
          Max: image.Point{X: +1, Y: +1},
        },

Thanks to JK for helping identify these

Best regards JE

[1] https://github.com/jonegil/gui-with-gio/blob/5c4a46b6760257a3a4dc95a4df49e79c621ebb00/teleprompter/code/main.go#L371

---------- Forwarded message --------- From: Jon Egil Strand jon.egil.strand@gmail.com Date: Tue, 19 Mar 2024 at 20:57 Subject: Re: Detecting mouse wheel To: jkvatne@online.no Cc: ~eliasnaur/gio@lists.sr.ht

Thank you for your reply.

To add mystery to the enigma:

Adding breadth to X in ScrollBounds work as you describe.

Min: image.Point{X: 0, Y: -100}, Max: image.Point{X: 1, Y: +100},

If I then press and hold Left, Right or Wheel, scrolling works as expected. No buttonpress = no scroll

Jon Egil

On Tue, 19 Mar 2024 at 09:32, Jan Kåre Vatne jkvatne@online.no wrote:

Hi Jon. Yes the scrolling is strange.

I have been able to make your app work by the following changes.

  1. Move the tag registration to just before the Finalize section 2a. Either change the ScrollBounds to { Min: image.Point{X: 0, Y: -100}, Max: image.Point{X: 1, Y: +100}} 2b. Or add an identical ScrollBound to the mouse button filter.

The last change is really strange. I have tried to debug the gio code, but it is very complicated. I think there must be an error in the gio code, concerning merging of filters. There is no reason the x range should be different from 0,0. And it fails only when there are two different scroll bounds.

A few more tips: The red stripe should be one line height, scaled with the font size. The maximum scroll delta (now 100) should also be one line height.

Jan Kåre Vatne

#430 pointer.Scroll always 0 2 years ago

on ~eliasnaur/gio

Hi ~jonegil, nice work! I'm glad that you've got things working again with the new input system. I took your teleprompter for a spin, and I'll leave some comments about it on your repo. I'm going to close out this issue since you've got it working.

#433 Text shaper handling of line trailing whitespace 2 years ago

on ~eliasnaur/gio

#430 pointer.Scroll always 0 2 years ago

Comment by ~jonegil on ~eliasnaur/gio

Thanks this works well

I sat the limits at +/-200. In my macbook it seldom gets above 100, so 200 should be sensible.

The teleprompter is turning out a nice litte event handler. Mouse, keyboard, animation ...

  • mouse for scrolling
  • spacebar for animation
  • B/S for bigger and smaller fonts
  • W/N for wider and narrower text area
  • U/D for moving the focusbar up down
  • +/- for faster and slower
  • Shift for larger changes

Take it for a spin at https://github.com/jonegil/gui-with-gio/tree/main/teleprompter

#430 pointer.Scroll always 0 2 years ago

Comment by ~jonegil on ~eliasnaur/gio

Sure, thanks Chris!

It's from the event-handler tutorial I wrote, teleprompter, and I guess you want to look here: https://github.com/jonegil/gui-with-gio/blob/797306f67fcfeeae29cfdb5df8d5fcd44b3ddb84/teleprompter/code/main.go#L307

The smallest replication I could extract is here, same code: https://gist.github.com/jonegil/dce02fbecd444b81b72d72ab0351826b

#430 pointer.Scroll always 0 2 years ago

Ticket created by ~jonegil on ~eliasnaur/gio

Listening for pointer.Scroll events works well and returns plenty of useful information, such as Position, Modifiers etc...

But I totally fail to extract any non-zero value for Scroll. At best it's -0, whatever that means.

pointer.Event{
    Type:0x40, 
    Source:0x0, 
    PointerID:0x0, 
    Priority:0x1, 
    Time:21388567272986, 
    Buttons:0x0, 
    Position:f32.Point{X:214.54305, Y:101.27048}, 
    Scroll:f32.Point{X:0, Y:-0}, 
    Modifiers:0x5
} 

pointer.Event.Scroll.Y used to include this information which was very practical. I see there's also a gesture package, but would prefer receiving the information directly in the pointer.Scroll if possible.

The behaviour is the same on my mac laptop/touchpad and with an external mouse.

Best regards J