How does a ScrollAreaGadget decide to display scrollbars?

Everything else that doesn't fall into one of the other PB categories.
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

How does a ScrollAreaGadget decide to display scrollbars?

Post by tinman »

It seems broken in some situations, where it will show scrollbars when they are not needed and not show them when they are needed. Sometimes. Check this code:

Code: Select all

#MIN_WW = 100
#MIN_WH = 100

ww = 400
wh = 300

#MIN_SW = 500
#MIN_SH = 500

sw = 500
sh = 500

If OpenWindow(0, #CW_USEDEFAULT, #CW_USEDEFAULT, ww, wh, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_TitleBar, "Test")

    If CreateGadgetList(WindowID()) 
        ScrollAreaGadget(1, 10, 10, ww - 20, wh - 20, sw, sh, 20)
            ButtonGadget(2, 0, 0, #MIN_SW, #MIN_SH, "You suck! ;)")
        CloseGadgetList()
    EndIf

    Repeat
        ev.l = WaitWindowEvent()
        While ev
            Select ev
                Case #PB_Event_CloseWindow
                    quit = 1
                    
                Case #PB_Event_SizeWindow
                    ww = WindowWidth() : If ww < #MIN_WW : ww = #MIN_WW : redo = 1 : EndIf
                    wh = WindowHeight() : If wh < #MIN_WH : wh = #MIN_WH : redo = 1 : EndIf
                    If redo : redo = 0 : ResizeWindow(ww, wh) : EndIf
                    
                    If (ww-20)>sw : sw = ww-20 : EndIf
                    If sw < #MIN_SW : sw = #MIN_SW : EndIf

                    If (wh-20)>sh : sh = wh-20 : EndIf
                    If sh < #MIN_SW : sh = #MIN_SW : EndIf

                    ResizeGadget(1, 10, 10, ww-20, wh-20)
                    SetGadgetAttribute(1, #PB_ScrollArea_InnerWidth, sw)
                    SetGadgetAttribute(1, #PB_ScrollArea_InnerHeight, sh)
            EndSelect
            
            ev = WindowEvent()
        Wend
    Until quit=1
    
    CloseWindow(0)
EndIf
End
And here's a screengrab of it being broken -> here.

Even if I make the inner sizes smaller than the window size (by the width of the border, which according to the docs I shouldn't do) it still doesn't work. What I'm trying to achieve here is to have the scrollbars appear only when the area goes below a certain size and for the area just to be displayed plainly when it is above this size.

Perhaps my code just sucks, but it does appear as if the gadget cannot decide when it should have scrollbars.

Any takers?
Cheers.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Unless I am misunderstanding your desired results, this code does the trick for me.

Code: Select all

#MIN_WW = 100 
#MIN_WH = 100 

ww = 400 
wh = 300 

#MIN_SW = 500 
#MIN_SH = 500 

sw = 500 
sh = 500 

If OpenWindow(0, #CW_USEDEFAULT, #CW_USEDEFAULT, ww, wh, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_TitleBar, "Test") 
  
  If CreateGadgetList(WindowID()) 
    ;ScrollAreaGadget(1, 10, 10, ww - 20, wh - 20, sw, sh, 20) 
    ScrollAreaGadget(1, 10, 10, ww - 20, wh - 20, #MIN_SW + 20, #MIN_SH + 20, 20) 
    ButtonGadget(2, 0, 0, #MIN_SW, #MIN_SH, "You suck! ;)") 
    CloseGadgetList() 
  EndIf 
  
  Repeat 
    ev.l = WaitWindowEvent() 
    While ev 
      Select ev 
        Case #PB_Event_CloseWindow 
          quit = 1 
          
        Case #PB_Event_SizeWindow 
          ww = WindowWidth() : If ww < #MIN_WW : ww = #MIN_WW : redo = 1 : EndIf 
          wh = WindowHeight() : If wh < #MIN_WH : wh = #MIN_WH : redo = 1 : EndIf 
          If redo : redo = 0 : ResizeWindow(ww, wh) : EndIf 
          
          ;If (ww-20)>sw : sw = ww-20 : EndIf 
          ;If sw < #MIN_SW : sw = #MIN_SW : EndIf 
          
          ;If (wh-20)>sh : sh = wh-20 : EndIf 
          ;If sh < #MIN_SW : sh = #MIN_SW : EndIf 
          
          ResizeGadget(1, 10, 10, ww-20, wh-20) 
          ;SetGadgetAttribute(1, #PB_ScrollArea_InnerWidth, sw) 
          ;SetGadgetAttribute(1, #PB_ScrollArea_InnerHeight, sh) 
      EndSelect 
      
      ev = WindowEvent() 
    Wend 
  Until quit=1 
  
  CloseWindow(0) 
EndIf 
End 
I changed the initial ScrollAreaWidth & ScrollAreaHeight then commented out a few lines.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

Sorry for dragging up an old thread, but I can't find any way round this. If someone can tell me how to set the scrollbar visibility properties of a ScrollAreaGadget manually using the API then I'll never bother with this stuff again.

Even if you create an empty ScrollAreaGadget and don't bother trying to resize the inside of it, then the scrollbar gadgets do not appear until after they should. Or they disappear prematurely. In any case, it ends up like the image link I posted above. Put these two lines into the #PB_Event_SizeWindow block and see for yourself:

Code: Select all

    Debug "Gadget width = "+Str(GadgetWidth(1))
    Debug "Inner width = "+Str(GetGadgetAttribute(#PB_ScrollArea_InnerWidth))
Slowly resize the window horizontally and you will see that the width of the gadget becomes less than the area of the inside but the scrollbars do not get shown for a few pixels at the limit of the size (I mean gadget width - border size of gadget).

@Sparkie: Thanks for the suggestion, but that's not what I'm trying to do. What I'd like is the scrollarea to be displayed with scrollbars when the size of the inner area is below a minimum size. When the size of the gadget is above this minimum size then it should not have the scrollbars, and the size of the inner area should follow the size of the gadget (so that the children of the ScrollAreaGadget do not get clipped before the borders).
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Post Reply