Permalink
Browse files

Updated DButton

Remove AccessorFuncs that we derive from DLabel.
Got rid of white space.
Added DButton:SetEnabled so calling it actually affects the button, instead of simply affecting the text.
  • Loading branch information...
1 parent 2299062 commit 4aa24f768a993ee855020e572743f85a3952b9e7 @robotboy655 robotboy655 committed Sep 30, 2014
Showing with 30 additions and 35 deletions.
  1. +30 −35 garrysmod/lua/vgui/dbutton.lua
@@ -1,26 +1,18 @@
---[[ _
- ( )
- _| | __ _ __ ___ ___ _ _
+--[[ _
+ ( )
+ _| | __ _ __ ___ ___ _ _
/'_` | /'__`\( '__)/' _ ` _ `\ /'_` )
( (_| |( ___/| | | ( ) ( ) |( (_| |
-`\__,_)`\____)(_) (_) (_) (_)`\__,_)
+`\__,_)`\____)(_) (_) (_) (_)`\__,_)
DButton
-
- Default Button
--]]
local PANEL = {}
-AccessorFunc( PANEL, "m_bBorder", "DrawBorder", FORCE_BOOL )
-AccessorFunc( PANEL, "m_bDisabled", "Disabled", FORCE_BOOL )
-AccessorFunc( PANEL, "m_FontName", "Font" )
-
-
---[[---------------------------------------------------------
+AccessorFunc( PANEL, "m_bBorder", "DrawBorder", FORCE_BOOL )
------------------------------------------------------------]]
function PANEL:Init()
self:SetContentAlignment( 5 )
@@ -31,8 +23,7 @@ function PANEL:Init()
--
self:SetDrawBorder( true )
self:SetDrawBackground( true )
-
- --
+
self:SetTall( 22 )
self:SetMouseInputEnabled( true )
self:SetKeyboardInputEnabled( true )
@@ -77,13 +68,10 @@ end
PANEL.SetIcon = PANEL.SetImage
---[[---------------------------------------------------------
-
------------------------------------------------------------]]
function PANEL:Paint( w, h )
derma.SkinHook( "Paint", "Button", self, w, h )
-
+
--
-- Draw the button text
--
@@ -96,9 +84,9 @@ end
-----------------------------------------------------------]]
function PANEL:UpdateColours( skin )
- if ( self:GetDisabled() ) then return self:SetTextStyleColor( skin.Colours.Button.Disabled ) end
- if ( self.Depressed || self.m_bSelected ) then return self:SetTextStyleColor( skin.Colours.Button.Down ) end
- if ( self.Hovered ) then return self:SetTextStyleColor( skin.Colours.Button.Hover ) end
+ if ( self:GetDisabled() ) then return self:SetTextStyleColor( skin.Colours.Button.Disabled ) end
+ if ( self.Depressed || self.m_bSelected ) then return self:SetTextStyleColor( skin.Colours.Button.Down ) end
+ if ( self.Hovered ) then return self:SetTextStyleColor( skin.Colours.Button.Hover ) end
return self:SetTextStyleColor( skin.Colours.Button.Normal )
@@ -108,18 +96,18 @@ end
Name: PerformLayout
-----------------------------------------------------------]]
function PANEL:PerformLayout()
-
+
--
-- If we have an image we have to place the image on the left
-- and make the text align to the left, then set the inset
-- so the text will be to the right of the icon.
--
if ( IsValid( self.m_Image ) ) then
-
- self.m_Image:SetPos( 4, (self:GetTall() - self.m_Image:GetTall()) * 0.5 )
- self:SetTextInset( self.m_Image:GetWide() + 16, 0 )
+ self.m_Image:SetPos( 4, ( self:GetTall() - self.m_Image:GetTall() ) * 0.5 )
+ self:SetTextInset( self.m_Image:GetWide() + 16, 0 )
+
end
DLabel.PerformLayout( self )
@@ -131,30 +119,38 @@ end
-----------------------------------------------------------]]
function PANEL:SetDisabled( bDisabled )
- self.m_bDisabled = bDisabled
+ self.m_bDisabled = bDisabled
+ self:InvalidateLayout()
+
+end
+
+-- Override the default engine method, so it actually does something for DButton
+function PANEL:SetEnabled( bEnabled )
+
+ self.m_bDisabled = !bEnabled
self:InvalidateLayout()
end
--[[---------------------------------------------------------
- Name: SetConsoleCommand
+ Name: SetConsoleCommand
-----------------------------------------------------------]]
function PANEL:SetConsoleCommand( strName, strArgs )
self.DoClick = function( self, val )
- RunConsoleCommand( strName, strArgs )
- end
+ RunConsoleCommand( strName, strArgs )
+ end
end
--[[---------------------------------------------------------
- Name: GenerateExample
+ Name: GenerateExample
-----------------------------------------------------------]]
function PANEL:GenerateExample( ClassName, PropertySheet, Width, Height )
local ctrl = vgui.Create( ClassName )
- ctrl:SetText( "Example Button" )
- ctrl:SetWide( 200 )
+ ctrl:SetText( "Example Button" )
+ ctrl:SetWide( 200 )
PropertySheet:AddSheet( ClassName, ctrl, nil, true, true )
@@ -178,13 +174,12 @@ function PANEL:OnMouseReleased( mousecode )
end
-
local PANEL = derma.DefineControl( "DButton", "A standard Button", PANEL, "DLabel" )
PANEL = table.Copy( PANEL )
--[[---------------------------------------------------------
- Name: SetActionFunction
+ Name: SetActionFunction
-----------------------------------------------------------]]
function PANEL:SetActionFunction( func )

0 comments on commit 4aa24f7

Please sign in to comment.