fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
a8034e9
v2.1.2
1local PANEL =class . create ( "CheckPanel" , "Label" ) 2 3PANEL : ACCESSOR ( "Value" , "m_iValue" , 0 ) 4 5function PANEL : CheckPanel () 6self : super () -- Initialize our baseclass 7self : SetFocusable ( true ) 8self : SetDrawPanel ( true ) 9self : SetBGColor ( color ( 215 , 215 , 215 )) 10 11self : TextMargin ( 0 , 4 , 0 , 0 ) 12self : SetTextAlignmentX ( "center" ) 13self : SetTextAlignmentY ( "top" ) 14self : SetTextColor ( color_darkgrey ) 15self : DockPadding ( 2 , 18 , 2 , 2 ) 16 17self . OPTIONS ={} 18end 19 20function PANEL : Skin () 21self : super ( "Skin" ) 22gui . skinHook ( "Init" , "SubPanel" , self ) 23end 24 25function PANEL : AddOption ( id , label , toggled ) 26local option =self : Add ( "CheckBox" ) 27option : SetText ( label ) 28option : Dock ( DOCK_TOP ) 29option : SetToggled ( toggled ) 30option . OnToggle =function () 31if self . m_iValue ~= self : GetValue () then 32self : OnValueChanged ( self . m_iValue ) 33end 34end 35 36self . OPTIONS [ id ] =option 37return option 38end 39 40function PANEL : PerformLayout () 41self : SizeToChildren ( false , true ) 42end 43 44function PANEL : GetValue () 45self . m_iValue =0 46for id , option in pairs ( self . OPTIONS ) do 47if option : IsToggled () then 48self . m_iValue =bit . bor ( self . m_iValue , id ) 49end 50end 51return self . m_iValue 52end 53 54function PANEL : SetValue ( value ) 55if self . m_iValue ~= value then 56self . m_iValue =value 57for id , option in pairs ( self . OPTIONS ) do 58-- DON'T use SetToggled, since it would call OnValueChanged 59-- We call OnValueChanged manually to reduce calls 60option . m_bToggled =bit . band ( value , id ) == id 61end 62self : OnValueChanged ( value ) -- Manual call 63end 64end 65 66function PANEL : OnValueChanged ( value ) 67-- OVERRIDE 68end