ScrollAreaGadget and mouse wheel

Just starting out? Need help? Post your questions and find answers here.
jak64
Enthusiast
Enthusiast
Posts: 625
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

ScrollAreaGadget and mouse wheel

Post 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
User avatar
jacdelad
Addict
Addict
Posts: 2004
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: ScrollAreaGadget and mouse wheel

Post by jacdelad »

Maybe the messages are sent to the canvas? Can you post a simple code to show the behaviour?
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Axolotl
Addict
Addict
Posts: 832
Joined: Wed Dec 31, 2008 3:36 pm

Re: ScrollAreaGadget and mouse wheel

Post 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() 
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
jak64
Enthusiast
Enthusiast
Posts: 625
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: ScrollAreaGadget and mouse wheel

Post 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
User avatar
jacdelad
Addict
Addict
Posts: 2004
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: ScrollAreaGadget and mouse wheel

Post by jacdelad »

Well, as I said, the canvasses receive the messages.

Anyway, what do you want to achieve? 100 canvasses seem a bit overkill.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Axolotl
Addict
Addict
Posts: 832
Joined: Wed Dec 31, 2008 3:36 pm

Re: ScrollAreaGadget and mouse wheel

Post 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
    
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Axolotl
Addict
Addict
Posts: 832
Joined: Wed Dec 31, 2008 3:36 pm

Re: ScrollAreaGadget and mouse wheel

Post 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
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
jak64
Enthusiast
Enthusiast
Posts: 625
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: ScrollAreaGadget and mouse wheel

Post by jak64 »

Thank you axolot!
User avatar
moulder61
Enthusiast
Enthusiast
Posts: 193
Joined: Sun Sep 19, 2021 6:16 pm
Location: U.K.

Re: ScrollAreaGadget and mouse wheel

Post 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.
"If it ain't broke, fix it until it is!

This message is brought to you thanks to SenselessComments.com

My PB stuff for Linux: "https://u.pcloud.link/publink/show?code ... z3MR0T3jyV
Post Reply