fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
52bc85d
v2.1.1
1local PANEL =class . create ( "ScrollPanel" , "Panel" ) 2 3function PANEL : ScrollPanel () 4self : super () -- Initialize our baseclass 5self : DockPadding ( 0 , 0 , 0 , 0 ) 6 7self . m_pCanvas =self : Add ( "Panel" ) 8self . m_pCanvas : SetBGColor ( color ( 215 , 215 , 215 )) 9 10-- Create the scroll bar 11self . m_pVBar =self : Add ( "ScrollBar" ) 12self . m_pVBar : DockMargin ( - 1 , 0 , 0 , 0 ) 13self . m_pVBar : Dock ( DOCK_RIGHT ) 14 15-- Disable us from setting padding after creation 16self . DockPadding =function () end 17 18-- Adding things to the ScrollPanel will actually be adding it to the canvas 19self . Add =function ( this , class ) 20return this . m_pCanvas : Add ( class ) 21end 22end 23 24function PANEL : OnChildAdded ( child ) 25end 26 27function PANEL : SizeToContents () 28self : SetSize ( self . m_pCanvas : GetSize ()) 29end 30 31function PANEL : GetVBar () 32return self . m_pVBar 33end 34 35function PANEL : GetCanvas () 36return self . m_pCanvas 37end 38 39function PANEL : InnerWidth () 40return self : GetCanvas (): GetWidth () 41end 42 43function PANEL : Rebuild () 44self : GetCanvas (): SizeToChildren ( false , true ) 45if self . m_bNoSizing and self : GetCanvas (): GetHeight () < self : GetHeight () then 46self : GetCanvas (): SetPos ( 0 , ( self : GetHeight () - self : GetCanvas (): GetHeight ()) * 0.5 ) 47end 48end 49 50function PANEL : OnMouseWheeled ( x , y ) 51return self . m_pVBar : OnMouseWheeled ( x , y ) 52end 53 54function PANEL : OnVScroll ( iOffset ) 55self . m_pCanvas : SetPos ( 0 , iOffset ) 56end 57 58function PANEL : ScrollToChild ( panel ) 59self : PerformLayout () 60 61local x , y =self . m_pCanvas : GetChildPosition ( panel ) 62local w , h =panel : GetSize () 63 64y =y + h * 0.5 ; 65y =y - self : GetHeight () * 0.5 ; 66 67self . m_pVBar : SetY ( y ) 68--self.m_pVBar:AnimateTo(y, 0.5, 0, 0.5); 69end 70 71function PANEL : PerformLayout () 72local wide =self : GetWidth () 73local ypos =0 74local xpos =0 75 76self . m_pVBar : SetUp ( self : GetHeight (), self . m_pCanvas : GetHeight ()) 77ypos =self . m_pVBar : GetOffset () 78 79if self . m_pVBar . m_bEnabled then 80wide =wide - self . m_pVBar : GetWidth () 81wide =wide - self . m_pVBar . m_tDockMargins . left - self . m_pVBar . m_tDockMargins . right 82end 83 84self . m_pCanvas : SetPos ( 0 , ypos ) 85self . m_pCanvas : SetWidth ( wide ) 86 87self : Rebuild () 88end 89 90function PANEL : SetScroll ( scroll ) 91self . m_pVBar : SetScroll ( scroll ) 92end 93 94function PANEL : Clear () 95self . m_pVBar : SetScroll ( 0 ) 96self . m_pCanvas : Clear () 97self : InvalidateLayout () 98end