ScrollAreaGadget(): Permanently displaying scrollbars?

Windows specific forum
User avatar
Dreamland Fantasy
Enthusiast
Enthusiast
Posts: 335
Joined: Fri Jun 11, 2004 9:35 pm
Location: Glasgow, UK
Contact:

ScrollAreaGadget(): Permanently displaying scrollbars?

Post by Dreamland Fantasy »

Hi there,

I was wondering, is it possible to permanently display scrollbars on a ScrollAreaGadget()? Specifically, I'm just looking to always have the vertical scrollbar displayed.

Kind regards,

Francis
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: ScrollAreaGadget(): Permanently displaying scrollbars?

Post by RASHAD »

Hi

Code: Select all

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If ScrollAreaGadget(1, 10, 10, 480, 380, 450,350, 10, 0)
    ButtonGadget(2, 10, 100, 100, 20, "Button", 0)
    CloseGadgetList()
  EndIf
  
  ShowScrollBar_(GadgetID(1), #SB_BOTH, 1)
 
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
EndIf
Egypt my love
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: ScrollAreaGadget(): Permanently displaying scrollbars?

Post by mk-soft »

You can change inner width and height of scroll area.

Code: Select all

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

Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(0)
  dy = WindowHeight(0)
  If dy > 550
    SetGadgetAttribute(0, #PB_ScrollArea_InnerHeight, dy - 20)
  EndIf
  SetGadgetAttribute(0, #PB_ScrollArea_InnerWidth, dx - 30 - 20)
  ResizeGadget(0, 10, 10, dx - 20, dy - 20)
EndProcedure

#WinStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget

If OpenWindow(0, #PB_Ignore, #PB_Ignore, 420, 240, "ScrollAreaGadget", #WinStyle)
  ScrollAreaGadget(0, 10, 10, 400, 220, 370, 550, 30)
  ButtonGadget  (1, 10, 10, 230, 30,"Button 1")
  ButtonGadget  (2, 50, 50, 230, 30,"Button 2")
  ButtonGadget  (3, 90, 90, 230, 30,"Button 3")
  TextGadget    (4,130,130, 230, 20,"This is the content of a ScrollAreaGadget!",#PB_Text_Right)
  CloseGadgetList()
  
  BindGadgetEvent(0, @ BindScrollDatas())
  BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), 0)
  
  Repeat
    Select WaitWindowEvent()
      Case  #PB_Event_CloseWindow
        End
      Case  #PB_Event_Gadget
        Select EventGadget()
          Case 0
            
          Case 1
            MessageRequester("Info","Button 1 was pressed!",#PB_MessageRequester_Ok)
          Case 2
            MessageRequester("Info","Button 2 was pressed!",#PB_MessageRequester_Ok)
          Case 3
            MessageRequester("Info","Button 3 was pressed!",#PB_MessageRequester_Ok)
        EndSelect
    EndSelect
  ForEver
EndIf
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: ScrollAreaGadget(): Permanently displaying scrollbars?

Post by mk-soft »

Ok, with Rashad API

Code: Select all

Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(0)
  dy = WindowHeight(0)
  ResizeGadget(0, 10, 10, dx - 20, dy - 20)
  ShowScrollBar_(GadgetID(0), #SB_VERT, 1)
  ShowScrollBar_(GadgetID(0), #SB_HORZ, 0)
  
EndProcedure

#WinStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget

If OpenWindow(0, 0, 0, 500, 400, "Window", #WinStyle)
  If ScrollAreaGadget(0, 10, 10, 480, 380, 450, 350, 10, 0)
    ButtonGadget(1, 10, 100, 100, 20, "Button", 0)
    CloseGadgetList()
  EndIf
  
  ShowScrollBar_(GadgetID(0), #SB_VERT, 1)
  ShowScrollBar_(GadgetID(0), #SB_HORZ, 0)
  
  BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), 0)
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
EndIf
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Dreamland Fantasy
Enthusiast
Enthusiast
Posts: 335
Joined: Fri Jun 11, 2004 9:35 pm
Location: Glasgow, UK
Contact:

Re: ScrollAreaGadget(): Permanently displaying scrollbars?

Post by Dreamland Fantasy »

Thanks for the quick response RASHAD. :)

I actually already tried using ShowScrollBar_(), but I could not get it to work with my code. Your test code works fine, but if I plug the ShowScrollBar_(GadgetID(1), #SB_BOTH, 1) into my code only the horizontal bar is displayed. :?

I'm using Dialogs to create the window and gadgets. Stripping my code down to just the window and gadget creation works fine with the ShowScrollBar_(), so I'm very confused why it is not working in the full code. :?

Kind regards,

Francis
User avatar
Dreamland Fantasy
Enthusiast
Enthusiast
Posts: 335
Joined: Fri Jun 11, 2004 9:35 pm
Location: Glasgow, UK
Contact:

Re: ScrollAreaGadget(): Permanently displaying scrollbars?

Post by Dreamland Fantasy »

mk-soft wrote: Mon Oct 03, 2022 10:12 am You can change inner width and height of scroll area.
The inner width and height is already being dynamically changed. Depending on what is being displayed, the inner width and height could be smaller than the scroll area gadget.

Kind regards,

Francis
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: ScrollAreaGadget(): Permanently displaying scrollbars?

Post by mk-soft »

You have to call the function ShowScrollBar after each change of size or inner size
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: ScrollAreaGadget(): Permanently displaying scrollbars?

Post by RASHAD »

Hi Francis
Try mk-soft idea

Code: Select all

Procedure scrollCB()
  ShowScrollBar_(GadgetID(1), #SB_VERT, 1)
EndProcedure

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If ScrollAreaGadget(1, 10, 10, 480, 380, 450,350, 10, 0)
    ShowScrollBar_(GadgetID(1), #SB_VERT, 1)
    ButtonGadget(2, 10, 100, 100, 20, "Button", 0)
    CloseGadgetList()
  EndIf
  
  BindGadgetEvent(1,@scrollCB())
 
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
EndIf
Egypt my love
User avatar
Dreamland Fantasy
Enthusiast
Enthusiast
Posts: 335
Joined: Fri Jun 11, 2004 9:35 pm
Location: Glasgow, UK
Contact:

Re: ScrollAreaGadget(): Permanently displaying scrollbars?

Post by Dreamland Fantasy »

mk-soft wrote: Mon Oct 03, 2022 10:51 am You have to call the function ShowScrollBar after each change of size or inner size
Ah, yes. That's where I was going wrong. Moving the ShowScrollBar_() to after the inner height change fixed it. :D

Many thanks mk-soft and RASHAD.

Kind regards,

Francis
Post Reply