Page 1 of 1

Resizing ScrollAreaGadgets

Posted: Thu Jun 26, 2003 9:07 pm
by tinman
OK, I'm obviously missing something. My test code:
<snip>
My question: how do you resize the scrolling area of the ScrollAreaGadget?


Thanks to Paul, here's a working version. Some might find it useful. Apparently the only way to resize the inner area of a ScrollAreaGadget at the moment is to re-make it and the gadgets within.

Code: Select all

If OpenWindow(0, 0, 0, 408, 308, 0, "ertyuj")
    If CreateGadgetList(WindowID())
        ScrollAreaGadget(1, 4, 4, 192, 142, 300, 250, 20, 0)
            ButtonGadget(2, 4, 4, 144, 242, "rtyhmn", 0)
            ButtonGadget(3, 152, 4, 144, 242, "blurp", 0)
            CloseGadgetList()
    EndIf
    
    While quit=0
        ev.l = WaitWindowEvent()
        While ev
            If ev=#WM_LBUTTONDOWN
                If foo=1
                    FreeGadget(1)
                    ScrollAreaGadget(1, 4, 4, 400, 300, 400, 300, 20, 0)
                        ButtonGadget(2, 4, 4, 194, 292, "rtyhmn", 0)
                        ButtonGadget(3, 202, 4, 194, 292, "blurp", 0)
                        CloseGadgetList()
                Else
                    FreeGadget(1)
                    ScrollAreaGadget(1, 4, 4, 192, 142, 300, 250, 20, 0)
                        ButtonGadget(2, 4, 4, 144, 242, "rtyhmn", 0)
                        ButtonGadget(3, 152, 4, 144, 242, "blurp", 0)
                        CloseGadgetList()
                EndIf
                foo = 1 - foo
            EndIf
            
            If ev.l=#PB_Event_CloseWindow
                quit = 1
            EndIf
            
            ev = WindowEvent()
        Wend
    Wend
    
    CloseWindow(0)
EndIf
End
Thanks Paul :)

Posted: Fri Jun 27, 2003 12:07 am
by tinman
Or an alternative version which does not require you to free the gadgets:

Code: Select all

If OpenWindow(0, 0, 0, 408, 308, 0, "ertyuj")
    If CreateGadgetList(WindowID())
        sag.l = ScrollAreaGadget(1, 4, 4, 192, 142, 300, 250, 20, 0)
        ; Method 1 - slightly nicer IMO, no guarantees you'll have gadgets in the scrollarea to get the parent of
        ar.l = GetWindow_(sag, #GW_CHILD)
            bg.l = ButtonGadget(2, 4, 4, 144, 242, "rtyhmn", 0)
            ; Alternate - should always work
            ;ar.l = GetParent_(bg)
            ButtonGadget(3, 152, 4, 144, 242, "blurp", 0)
            CloseGadgetList()
            
    EndIf
    
    While quit=0
        ev.l = WaitWindowEvent()
        While ev
            If ev=#WM_LBUTTONDOWN
                If foo=0
                    ResizeGadget(1, 4, 4, 400, 300)
                    ResizeGadget(2, 4, 4, 194, 292)
                    ResizeGadget(3, 202, 4, 194, 292)
                    MoveWindow_(ar, 0, 0, 400, 300, 0)
                Else
                    ResizeGadget(1, 4, 4, 192, 142)
                    ResizeGadget(2, 4, 4, 144, 242)
                    ResizeGadget(3, 152, 4, 144, 242)
                    MoveWindow_(ar, 0, 0, 300, 250, 0)
                EndIf
                foo = 1 - foo
            EndIf
            
            If ev.l=#PB_Event_CloseWindow
                quit = 1
            EndIf
            
            ev = WindowEvent()
        Wend
    Wend
    
    CloseWindow(0)
EndIf
End
(Edit: found a cleaner way to do it, assuming the internal workings of the ScrollArea gadget never changes ;)

Posted: Fri Jun 27, 2003 11:57 pm
by Andre
I think, both code examples have a 'bug' :roll:

Directly after opening the window with the ScrollAreaGadget: If you click OUTSIDE the scroll-area, the resizing (displaying both buttons in full-size) is also done. This normally shouldn't be the happen.
(Forgive me, I'm not able to solve this problem myself now... :wink:)

Posted: Sat Jun 28, 2003 11:37 am
by tinman
Andre wrote:I think, both code examples have a 'bug' :roll:

Directly after opening the window with the ScrollAreaGadget: If you click OUTSIDE the scroll-area, the resizing (displaying both buttons in full-size)
No, the clicking can be done anywhere, it was only used to control when to do the resize for this example.

Posted: Sun Jun 29, 2003 11:20 am
by tinman
OK, more problems, hopefully someone can help. What I'm trying to do here is have the ScrollArea gadget resize, along with it's insides. However, the minimum size of the inside should be a certain size (in this case, width = 200 and height = 200). The sizes are all hardcoded at the moment (sizes of ScrollArea border) which are used to calculate the size of the inside.

Code: Select all

Global sag.l

#SCROLL_AREA_FLAGS = 0
;#SCROLL_AREA_FLAGS = #PB_ScrollArea_Flat
;#SCROLL_AREA_FLAGS = #PB_ScrollArea_Raised
;#SCROLL_AREA_FLAGS = #PB_ScrollArea_Single
;#SCROLL_AREA_FLAGS = #PB_ScrollArea_Borderless


#BORDER_LEFT = 0
#BORDER_RIGHT = 1
#BORDER_TOP = 2
#BORDER_BOTTOM = 3
Procedure.l int_Virtual_BorderSize(gadget_flags.l, border.l)
    DefType.l   border_size
    
    Select border_flags & (#PB_ScrollArea_Flat|#PB_ScrollArea_Raised|#PB_ScrollArea_Single|#PB_ScrollArea_BorderLess)
        Case #PB_ScrollArea_Flat
            border_size = 2
        
        Case #PB_ScrollArea_Raised
            border_size = 2
        
        Case #PB_ScrollArea_Single
            border_size = 1
        
        Case #PB_ScrollArea_BorderLess
            border_size = 0
        
        Default
            border_size = 2
    EndSelect
    
    ProcedureReturn border_size
EndProcedure


Procedure.l SizeCallback(WindowID.l, Message.l, wParam.l, lParam.l)
    DefType.l   result
    
    result = #PB_ProcessPureBasicEvents

    If WindowID = UseWindow(0)
        Select Message
            Case #WM_SIZE
                sag_width.l = WindowWidth() - 4
                sag_height.l = WindowHeight() - 4
                scroll_width = sag_width - int_Virtual_BorderSize(#SCROLL_AREA_FLAGS, #BORDER_LEFT) - int_Virtual_BorderSize(#SCROLL_AREA_FLAGS, #BORDER_RIGHT)
                If scroll_width < 200
                    scroll_width = 200
                EndIf
                scroll_height = sag_height - int_Virtual_BorderSize(#SCROLL_AREA_FLAGS, #BORDER_TOP) - int_Virtual_BorderSize(#SCROLL_AREA_FLAGS, #BORDER_BOTTOM)
                If scroll_height < 200
                    scroll_height = 200
                EndIf
                
                Debug "Gadget width = "+Str(sag_width)
                Debug "Gadget height = "+Str(sag_height)
                Debug "Inner width = "+Str(scroll_width)
                Debug "Inner height = "+Str(scroll_height)
                
                ar.l = GetWindow_(sag, #GW_CHILD)
                MoveWindow_(ar, 0, 0, scroll_width, scroll_height, 0)
                ResizeGadget(1, 2, 2, sag_width, sag_height)
        EndSelect
    EndIf

    ProcedureReturn result
EndProcedure


If OpenWindow(0, 0, 0, 408, 308, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_TitleBar, "ertyuj")
    If CreateGadgetList(WindowID())
        sag = ScrollAreaGadget(1, 2, 2, WindowWidth()-4, WindowHeight()-4, WindowWidth()-8, WindowHeight()-8, 20, #SCROLL_AREA_FLAGS)
        CloseGadgetList()
    EndIf
    
    SetWindowCallback(@SizeCallback())

    While quit=0
        ev.l = WaitWindowEvent()
        While ev
            If ev.l=#PB_Event_CloseWindow
                quit = 1
            EndIf
            
            ev = WindowEvent()
        Wend
    Wend
    
    SetWindowCallback(0)

    CloseWindow(0)
EndIf
End
(Edit: corrected the code, now it shows the problem I am really having ;)

The problem here is that as you resize the window so that it gets smaller than the minimum size of the inside area then the scrollbars appear. That is OK. However, now if you enlarge the window again, so that it is bigger than the minimum the scrollbars stay visible (seems to be because the scrollbars cover some of the area which would be used by the inside area of the gadget). This seems like a problem with the logic used to decide when to show or hide the scrollbars, but I don't know if it's a PB or a Windows (98 ;) thing or whether I'm guessing wrongly.

Any help would be appreciated.

Posted: Sun Jun 29, 2003 5:00 pm
by freak
Put the "ResizeGadget" line before the "MoveWindow_" line in the callback
Don't ask me why, but then it works. :wink:

Timo

Posted: Sun Jun 29, 2003 7:54 pm
by Andre
There is still a problem: the scrollbars only disappears, if I resize the window very fast to a new larger size. If I'm doing it with less speed, the scrollbars are still visible, also with a very large window size...
(Tested with and without debug output)

Posted: Sun Jun 29, 2003 8:47 pm
by tinman
Andre wrote:There is still a problem: the scrollbars only disappears, if I resize the window very fast to a new larger size. If I'm doing it with less speed, the scrollbars are still visible, also with a very large window size...
(Tested with and without debug output)
Ahh, excellent. I had the same problem earlier but I thought it may have just been Win89 ;) since fr34k seemed to think it worked OK. I guess you tested with WinXP?

Posted: Sun Jun 29, 2003 9:11 pm
by Andre
tinman wrote:Ahh, excellent. I had the same problem earlier but I thought it may have just been Win89 ;) since fr34k seemed to think it worked OK. I guess you tested with WinXP?
Correct, as always WinXP SP1.