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