fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
a8034e9
v2.1.2
1local PANEL =class . create ( "Tab" , "Button" ) 2 3PANEL : ACCESSOR ( "Active" , "m_bActive" , false ) 4PANEL : ACCESSOR ( "ContentPanel" , "m_pContentPanel" ) 5PANEL : ACCESSOR ( "ActiveColor" , "m_cActiveColor" ) 6 7function PANEL : Tab () 8self : super () 9self : SetTextAlignmentX ( "left" ) 10self : TextMargin ( 28 , 0 , 0 , 0 ) 11end 12 13function PANEL : OnClick () 14if self . m_pContentPanel then 15self . m_pContentPanel : GetParent (): SetActivePanel ( self . m_pContentPanel ) 16end 17end 18 19function PANEL : SetImage ( file ) 20if not file then return end 21self . m_pImage =graphics . newImage ( file ) 22end 23 24function PANEL : PrePaint ( w , h ) 25gui . skinHook ( "Paint" , "Tab" , self , w , h ) 26end 27 28function PANEL : Paint ( w , h ) 29if self . m_pImage then 30graphics . setColor ( color_white ) 31graphics . easyDraw ( self . m_pImage , 4 , 4 , 0 , 16 , 16 ) 32end 33self : PaintLabel ( w , h ) 34end 35 36function PANEL : PaintOverlay ( w , h ) 37gui . skinHook ( "PaintOverlay" , "Button" , self , w , h ) 38end 39 40local PANEL =class . create ( "TabContents" , "Panel" ) 41 42PANEL : ACCESSOR ( "Tab" , "m_pTab" ) 43 44function PANEL : TabContents () 45self : super () 46 47self : Dock ( DOCK_FILL ) 48self : DockMargin ( 0 , 0 , 0 , 0 ) 49self : SetVisible ( false ) 50end 51 52local PANEL =class . create ( "TabbedPanel" , "Panel" ) 53 54function PANEL : TabbedPanel () 55self : super () 56self : SetDrawPanel ( false ) 57self : DockPadding ( 0 , 0 , 0 , 0 ) 58 59-- Collection of all the tabs 60self . m_pTabBar =self : Add ( "Panel" ) 61self . m_pTabBar : Dock ( DOCK_TOP ) 62self . m_pTabBar : DockPadding ( 0 , 0 , 0 , 0 ) 63self . m_pTabBar : DockMargin ( 0 , 0 , 0 , 0 ) 64self . m_pTabBar : SetDrawPanel ( false ) 65 66self . m_pActivePanel =nil 67end 68 69function PANEL : SetActivePanel ( panel ) 70if self . m_pActivePanel then 71self . m_pActivePanel : SetVisible ( false ) 72self . m_pActivePanel : GetTab (): SetActive ( false ) 73end 74panel : SetVisible ( true ) 75panel : GetTab (): SetActive ( true ) 76self . m_pActivePanel =panel 77end 78 79function PANEL : AddTab ( name , icon , active ) 80local content =self : Add ( "TabContents" ) 81 82local tab =self . m_pTabBar : Add ( "Tab" ) 83tab : DockMargin ( 0 , 0 , 0 , 0 ) 84tab : Dock ( DOCK_LEFT ) 85tab : SetText ( name ) 86tab : SetContentPanel ( content ) 87tab : SetImage ( icon ) 88tab : SetWidth ( 82 ) 89 90content : SetTab ( tab ) 91 92if active then 93self : SetActivePanel ( content ) 94end 95 96return content 97end