Enhancement: ScrollAreaGadget

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Enhancement: ScrollAreaGadget

Post by IdeasVacuum »

From the Help:
#PB_ScrollArea_Center : If the inner size is smaller than the outer one,
then the inner area is automatically centered.
-Works perfectly but does not cater for when the inner size is larger than the outer size.

It can be done - should be part of the PB #PB_ScrollArea_Center function.

Rashad's solution:

Code: Select all

Enumeration
#Win
#Panel
#Scrl
#Canv
#Temp
EndEnumeration

If OpenWindow(#Win, 0, 0, 700, 650, "ScrollArea scrollbar positions", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

SetWindowColor(#Win, RGB(240,240,240))

PanelGadget(#Panel, 1, 1, 698, 648)

AddGadgetItem(#Panel, -1, "Tab 0")

ScrollAreaGadget(#Scrl, 5,  40,  376,  570, 1000, 1000, 10, #PB_ScrollArea_BorderLess | #PB_ScrollArea_Center)
   CanvasGadget(#Canv, 0,   0, 1000, 1000, #PB_Canvas_Container)
CloseGadgetList() ;#Canv
CloseGadgetList() ;#Scrl

   StartDrawing(CanvasOutput(#Canv))
            Box(0, 0, GadgetWidth(#Canv), GadgetHeight(#Canv), RGB(192,192,192))
         LineXY(500,   0,  500, 1000, RGB(200,000,000))
         LineXY(  0, 500, 1000,  500, RGB(200,000,000))
    DrawingMode(#PB_2DDrawing_Outlined)
            Box(332, 235, 336, 530, RGB(000,000,200))

    StopDrawing()
    
    SetGadgetAttribute(#Scrl, #PB_ScrollArea_X, 1000)
    hpos = GetGadgetAttribute(#Scrl, #PB_ScrollArea_X)
    
    SetGadgetAttribute(#Scrl, #PB_ScrollArea_Y, 1000)
    vpos = GetGadgetAttribute(#Scrl, #PB_ScrollArea_Y)              

    SetGadgetAttribute(#Scrl, #PB_ScrollArea_X, hpos/2)
    SetGadgetAttribute(#Scrl, #PB_ScrollArea_Y, vpos/2)

Repeat
Until WaitWindowEvent(1) = #PB_Event_CloseWindow
EndIf
IdeasVacuum
If it sounds simple, you have not grasped the complexity.