Page 1 of 1

ScrollAreaGadget and mouse wheel

Posted: Tue Mar 11, 2025 1:04 pm
by jak64
ScrollAreaGadget and mouse wheel

Hello,
I noticed that if in a ScrollAreaGadget we put CanvasGadget, then the mouse wheel does not work to scroll the list vertically.

the scroll bar works but not the mouse wheel.

Do you know why?

Thank you

Re: ScrollAreaGadget and mouse wheel

Posted: Tue Mar 11, 2025 1:30 pm
by jacdelad
Maybe the messages are sent to the canvas? Can you post a simple code to show the behaviour?

Re: ScrollAreaGadget and mouse wheel

Posted: Tue Mar 11, 2025 3:09 pm
by Axolotl
jacdelad is right.
If your Mouse is over the Canvas Gadget it will receive the events.
The question is how can I fix this?
You can see a probably working solution in this simple example. (I borrowed the basis from the help file)

Code: Select all

EnableExplicit 

Procedure BindScrollDatas()
  SetWindowTitle(0, "ScrollAreaGadget (" + GetGadgetAttribute(0, #PB_ScrollArea_X) + ", " + GetGadgetAttribute(0, #PB_ScrollArea_Y) + ")") 
EndProcedure

Procedure Trace(Message.s) 
  Debug "INFO: " + Message + " " 
EndProcedure 
  
Procedure Main() 
  Protected wheelstep, dy, scrollY  

  wheelstep = 30 
  
  If OpenWindow(0, 0, 0, 405, 240, "ScrollAreaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ScrollAreaGadget(0, 10, 10, 390, 220, 575, 555, 30)
      ButtonGadget(1, 10, 0, 230, 20, "Button 1")
      ButtonGadget(2, 50, 30, 230, 20, "Button 2")
      ButtonGadget(3, 90, 60, 230, 20, "Button 3")
      TextGadget(4,  130, 90, 230, 20, "This is the content of a ScrollAreaGadget!", #PB_Text_Right)

      CanvasGadget(10, 0, 120, 390, 100)  ; addition to the Help example 
    CloseGadgetList()
  
    BindGadgetEvent(0, @BindScrollDatas()) 
  
    Repeat
      Select WaitWindowEvent()
        Case  #PB_Event_CloseWindow
          End
        Case  #PB_Event_Gadget
          Select EventGadget() 
            Case 0
              Trace("A Scroll has been used ! (" + GetGadgetAttribute(0, #PB_ScrollArea_X) + ", " + GetGadgetAttribute(0, #PB_ScrollArea_Y) + ")")
            Case 1
              Trace("Button 1 was pressed!")
            Case 2
              Trace("Button 2 was pressed!")
            Case 3
              Trace("Button 3 was pressed!")

            Case 10
              Select EventType() 
                Case #PB_EventType_MouseWheel 
                  dy = GetGadgetAttribute(10, #PB_Canvas_WheelDelta) 
                  
                  scrollY = GetGadgetAttribute(0, #PB_ScrollArea_Y) - (wheelstep * dy)  ; tricky part 
                  SetGadgetAttribute(0, #PB_ScrollArea_Y, scrollY) 
                  Trace("The Canvas received the Mouse Wheel Event. " + scrollY) 
              EndSelect 
          EndSelect
      EndSelect
    ForEver
  EndIf 
  ProcedureReturn 0 
EndProcedure 

End Main() 

Re: ScrollAreaGadget and mouse wheel

Posted: Tue Mar 11, 2025 3:30 pm
by jak64
Here is an example.
The support wheel does not work to scroll vertically.

Code: Select all

EnableExplicit 
Global i.i
Global y.i

OpenWindow(0, 0, 0, 405, 240, "ScrollAreaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    
    ScrollAreaGadget(0, 10, 10, 390, 220, 200, 555, 30)
    For i = 1 To 100
      CanvasGadget(i, 0, y, 390, 20)  ; addition to the Help example 
      StartDrawing(CanvasOutput(i))
      DrawingMode(#PB_2DDrawing_Transparent)
      FillArea(0, 0, #Red, #Black)
      DrawText(5, 2, Str(i), #White)
      StopDrawing()           
      y + 22
    Next i
    CloseGadgetList()
    SetGadgetAttribute(0, #PB_ScrollArea_InnerHeight , (i-1)*22)
  
    Repeat
      Select WaitWindowEvent()
        Case  #PB_Event_CloseWindow
          End
      EndSelect
    ForEver

Re: ScrollAreaGadget and mouse wheel

Posted: Tue Mar 11, 2025 4:36 pm
by jacdelad
Well, as I said, the canvasses receive the messages.

Anyway, what do you want to achieve? 100 canvasses seem a bit overkill.

Re: ScrollAreaGadget and mouse wheel

Posted: Tue Mar 11, 2025 4:37 pm
by Axolotl
@jak64,
pretty much a way I would not use the canvas. But anyway I added this to your example. Keep in mind, the innerwidth is only 200.

Code: Select all

EnableExplicit 
Global i.i
Global y.i, dy, scrollY 

OpenWindow(0, 0, 0, 405, 240, "ScrollAreaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    
    ScrollAreaGadget(0, 10, 10, 390, 220, 200, 555, 30)
    For i = 1 To 100
      CanvasGadget(i, 0, y, 390, 20)  ; addition to the Help example 
      StartDrawing(CanvasOutput(i))
      DrawingMode(#PB_2DDrawing_Transparent)
      FillArea(0, 0, #Red, #Black)
      DrawText(5, 2, Str(i), #White)
      StopDrawing()           
      y + 22
    Next i
    CloseGadgetList()
    SetGadgetAttribute(0, #PB_ScrollArea_InnerHeight , (i-1)*22)
  
    Repeat
      Select WaitWindowEvent()
        Case  #PB_Event_CloseWindow
          End

        Case  #PB_Event_Gadget 
          i = EventGadget() 
          If i = 0 
            Debug "Scrool Area " 
          
          ElseIf GadgetType(i) = #PB_GadgetType_Canvas  
            Select EventType() 
              Case #PB_EventType_MouseWheel 
                dy = GetGadgetAttribute(i, #PB_Canvas_WheelDelta) 
                scrollY = GetGadgetAttribute(0, #PB_ScrollArea_Y) - (30 * dy)  ; tricky part 
                SetGadgetAttribute(0, #PB_ScrollArea_Y, scrollY) 
            EndSelect 
          EndIf 
      EndSelect
    ForEver
    

Re: ScrollAreaGadget and mouse wheel

Posted: Tue Mar 11, 2025 5:00 pm
by Axolotl
okay, with some changes it works as expected.

Code: Select all

EnableExplicit 
Global i.i
Global y.i, dy, scrollY 

OpenWindow(0, 0, 0, 405, 240, "ScrollAreaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    
    ScrollAreaGadget(0, 10, 10, 390, 220, 390, 555, 30) ; *) change 200 to 390 
    For i = 1 To 100
      CanvasGadget(i, 0, y, 200, 20)  ; *) change 390 to 200 
      StartDrawing(CanvasOutput(i))
      DrawingMode(#PB_2DDrawing_Transparent)
      FillArea(0, 0, #Red, #Black)
      DrawText(5, 2, Str(i), #White)
      StopDrawing()           
      y + 22
    Next i
    CloseGadgetList()
    SetGadgetAttribute(0, #PB_ScrollArea_InnerHeight , (i-1)*22)
  
    Repeat
      Select WaitWindowEvent()
        Case  #PB_Event_CloseWindow
          End

        Case  #PB_Event_Gadget 
          i = EventGadget() 
          If i = 0 
            Debug "Scroll Area " 
          
          ElseIf GadgetType(i) = #PB_GadgetType_Canvas  
            Select EventType() 
              Case #PB_EventType_MouseWheel 
                dy = GetGadgetAttribute(i, #PB_Canvas_WheelDelta) 
                scrollY = GetGadgetAttribute(0, #PB_ScrollArea_Y) - (30 * dy)  ; tricky part 
                SetGadgetAttribute(0, #PB_ScrollArea_Y, scrollY) 
            EndSelect 
          EndIf 
      EndSelect
    ForEver

Re: ScrollAreaGadget and mouse wheel

Posted: Sun Aug 10, 2025 11:34 am
by jak64
Thank you axolot!

Re: ScrollAreaGadget and mouse wheel

Posted: Mon Aug 11, 2025 3:13 pm
by moulder61
@Axolotl

I am having issues mixing scrollareagadgets and canvasgadgets in my project and your solutions here are really helpful to me.

Thanks. :D

Moulder.