IMK log.Print only shows pointer position and time. I am expecting a
positive or negative roll direction here. In case it's not here, what
event is the correct one? I looked at the material list. But I
couldn't figure out how gio scroll using the mouse.
{Scroll Mouse 0 Foremost 51h26m22.093s (44,65) (0,0) }
On Tue, Jan 25, 2022 at 1:41 PM Elias Naur <mail@eliasnaur.com> wrote:
>> On Tue Jan 25, 2022 at 13:27, R D wrote:> > I was trying to modify the slider value using the mouse wheel. Easy example> > would be the youtube volume slider. After hovering then rolling up or> > downward I can easily increase or decrease the value of the slider. Another> > one would be a zoomable element> > <https://developer.mozilla.org/en-US/docs/Web/API/Element/wheel_event>.> >>> Ok, but then what's missing from the pointer.Scroll events you log.Print? Are they> not correctly reflecting mouse wheel movement?>> Elias
On Tue Jan 25, 2022 at 14:32, R D wrote:
> IMK log.Print only shows pointer position and time. I am expecting a> positive or negative roll direction here. In case it's not here, what> event is the correct one? I looked at the material list. But I> couldn't figure out how gio scroll using the mouse.> {Scroll Mouse 0 Foremost 51h26m22.093s (44,65) (0,0) }>
I would expect pointer.Event.Scroll to contain scroll distances as well. Can
you scroll any of the Gio examples, such as the kitchen program? If not, there
may be a bug in Gio.
Elias
I can scroll in kitchen example without any problem.
On Tue, Jan 25, 2022 at 2:55 PM Elias Naur <mail@eliasnaur.com> wrote:
>> On Tue Jan 25, 2022 at 14:32, R D wrote:> > IMK log.Print only shows pointer position and time. I am expecting a> > positive or negative roll direction here. In case it's not here, what> > event is the correct one? I looked at the material list. But I> > couldn't figure out how gio scroll using the mouse.> > {Scroll Mouse 0 Foremost 51h26m22.093s (44,65) (0,0) }> >>> I would expect pointer.Event.Scroll to contain scroll distances as well. Can> you scroll any of the Gio examples, such as the kitchen program? If not, there> may be a bug in Gio.>> Elias
On Tue Jan 25, 2022 at 15:06, R D wrote:
> I can scroll in kitchen example without any problem.>
But your example doesn't report scrolling? Please post a minimal, yet complete
program that clearly demonstrates the problem.
Thanks,
Elias
> On Tue, Jan 25, 2022 at 2:55 PM Elias Naur <mail@eliasnaur.com> wrote:> >> > On Tue Jan 25, 2022 at 14:32, R D wrote:> > > IMK log.Print only shows pointer position and time. I am expecting a> > > positive or negative roll direction here. In case it's not here, what> > > event is the correct one? I looked at the material list. But I> > > couldn't figure out how gio scroll using the mouse.> > > {Scroll Mouse 0 Foremost 51h26m22.093s (44,65) (0,0) }> > >> >> > I would expect pointer.Event.Scroll to contain scroll distances as well. Can> > you scroll any of the Gio examples, such as the kitchen program? If not, there> > may be a bug in Gio.> >> > Elias
It sounds like you just need to use gesture.Scroll to listen for
scrolling operations on the slider.
https://pkg.go.dev/gioui.org/gesture#Scroll.Scroll
You should be able to put a clip.Rect on top of the area the slider
occupies and then call gesture.Scroll.Add to make the area listen for
scroll events. gesture.Scroll.Scroll will then report distance
scrolled in pixels, which you can convert to motion of the control of
interest.
Does that make sense? If not, perhaps you could provide a modified
gioui.org/example/hello that demonstrates what you've tried?
Cheers,
Chris
Sorry for the late response. As Chris suggested I added scrval.Add()
read user input and used scrval.Scroll() to read the input value. This
is what I was looking for. But for some reason I get 0 for rolling up
and 100 for rolling down. Are these values expected constants or am I
missing something?
var scrval = gesture.Scroll{}
func doButton(ops *op.Ops, q event.Queue) {
// Process events that arrived between the last frame and this one.
for _, ev := range q.Events(tag) {
if x, ok := ev.(pointer.Event); ok {
switch x.Type {
case pointer.Press:
pressed = true
case pointer.Release:
pressed = false
case pointer.Scroll:
// log.Println("Scroll", ev.(pointer.Event))
log.Println(scrval.Scroll(unit.Metric{
PxPerDp: .1,
PxPerSp: .1,
}, q, time.Now(), gesture.Vertical))
pressed = !pressed
}
}
}
scrval.Add(ops, image.Rect(0, 0, 100, 100))
// Confine the area of interest to a 100x100 rectangle.
area := clip.Rect(image.Rect(0, 0, 100, 100)).Push(ops)
// Declare the tag.
pointer.InputOp{
Tag: tag,
Types: pointer.Press | pointer.Release | pointer.Scroll,
}.Add(ops)
area.Pop()
defer clip.Rect{Max: image.Pt(100, 100)}.Push(ops).Pop()
var c color.NRGBA
if pressed {
c = color.NRGBA{R: 0xFF, A: 0xFF}
} else {
c = color.NRGBA{G: 0xFF, A: 0xFF}
}
paint.ColorOp{Color: c}.Add(ops)
paint.PaintOp{}.Add(ops)
}
func main() {
window := app.NewWindow(app.Title("Title"))
window.Center()
go func() {
w := app.NewWindow(app.Size(unit.Dp(800), unit.Dp(700)))
if err := loop(w); err != nil {
log.Fatal(err)
}
os.Exit(0)
}()
app.Main()
}
On Tue, Jan 25, 2022 at 4:03 PM Chris Waldon
<christopher.waldon.dev@gmail.com> wrote:
>> It sounds like you just need to use gesture.Scroll to listen for> scrolling operations on the slider.>> https://pkg.go.dev/gioui.org/gesture#Scroll.Scroll>> You should be able to put a clip.Rect on top of the area the slider> occupies and then call gesture.Scroll.Add to make the area listen for> scroll events. gesture.Scroll.Scroll will then report distance> scrolled in pixels, which you can convert to motion of the control of> interest.>> Does that make sense? If not, perhaps you could provide a modified> gioui.org/example/hello that demonstrates what you've tried?>> Cheers,> Chris
On Tue Jan 25, 2022 at 20:37, R D wrote:
> Sorry for the late response. As Chris suggested I added scrval.Add()> read user input and used scrval.Scroll() to read the input value. This> is what I was looking for. But for some reason I get 0 for rolling up> and 100 for rolling down. Are these values expected constants or am I> missing something?>> var scrval = gesture.Scroll{}>> func doButton(ops *op.Ops, q event.Queue) {> // Process events that arrived between the last frame and this one.>> for _, ev := range q.Events(tag) {> if x, ok := ev.(pointer.Event); ok {> switch x.Type {> case pointer.Press:> pressed = true> case pointer.Release:> pressed = false> case pointer.Scroll:> // log.Println("Scroll", ev.(pointer.Event))> log.Println(scrval.Scroll(unit.Metric{> PxPerDp: .1,> PxPerSp: .1,> }, q, time.Now(), gesture.Vertical))> pressed = !pressed>> }> }> }>> scrval.Add(ops, image.Rect(0, 0, 100, 100))> // Confine the area of interest to a 100x100 rectangle.> area := clip.Rect(image.Rect(0, 0, 100, 100)).Push(ops)> // Declare the tag.> pointer.InputOp{> Tag: tag,> Types: pointer.Press | pointer.Release | pointer.Scroll,
Ah, I forgot that you have to set ScrollBounds to describe the bounds
of your scrolling area.
> }.Add(ops)> area.Pop()>
Elias