fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
a8034e9
v2.1.1a
1local PANEL =class . create ( "RadioPanel" , "Label" ) 2 3PANEL : ACCESSOR ( "Option" , "m_iOption" ) 4PANEL : ACCESSOR ( "Horizontal" , "m_bHorizontal" , false ) 5 6function PANEL : RadioPanel () 7self : super () -- Initialize our baseclass 8self : SetFocusable ( true ) 9self : SetDrawPanel ( true ) 10self : SetBGColor ( color ( 215 , 215 , 215 )) 11 12self : TextMargin ( 0 , 4 , 0 , 0 ) 13self : SetTextAlignmentX ( "center" ) 14self : SetTextAlignmentY ( "top" ) 15self : SetTextColor ( color_darkgrey ) 16self : DockPadding ( 2 , 18 , 2 , 2 ) 17 18self . OPTIONS ={} 19end 20 21function PANEL : Skin () 22self : super ( "Skin" ) 23gui . skinHook ( "Init" , "SubPanel" , self ) 24end 25 26function PANEL : AddOption ( id , label , active ) 27local option =self : Add ( "RadioBox" ) 28option : SetText ( label ) 29option : Dock ( self . m_bHorizontal and DOCK_LEFT or DOCK_TOP ) 30option . OnClick =function () 31self : SetValue ( id ) 32end 33 34self . OPTIONS [ id ] =option 35 36if active then 37self : SetValue ( id ) 38end 39 40return option 41end 42 43function PANEL : PerformLayout () 44self : SizeToChildren ( self . m_bHorizontal , not self . m_bHorizontal ) 45end 46 47function PANEL : SetValue ( id ) 48if self . m_iOption ~= id then 49for i , option in pairs ( self . OPTIONS ) do 50option : SetToggled ( i == id ) 51end 52self : OnSelectOption ( id , self . m_iOption ) 53self . m_iOption =id 54end 55end 56 57function PANEL : OnSelectOption ( id , prev ) 58-- OVERRIDE 59end