Skip to content

Commit

Permalink
Updated DButton
Browse files Browse the repository at this point in the history
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
robotboy655 committed Sep 30, 2014
1 parent 2299062 commit 4aa24f7
Showing 1 changed file with 30 additions and 35 deletions.
65 changes: 30 additions & 35 deletions 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 )
Expand All @@ -31,8 +23,7 @@ function PANEL:Init()
--
self:SetDrawBorder( true )
self:SetDrawBackground( true )
--
self:SetTall( 22 )
self:SetMouseInputEnabled( true )
self:SetKeyboardInputEnabled( true )
Expand Down Expand Up @@ -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
--
Expand All @@ -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 )
Expand All @@ -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 )
Expand All @@ -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 )
Expand All @@ -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 )
Expand Down

0 comments on commit 4aa24f7

Please sign in to comment.