Permalink
Browse files

Clean up DLabelURL/Editable

Renamed DLabelEditable.OnTextChanged to
DLabelEditable.OnLabelTextChanged to prevent confusion/problems with
DTextEntry.OnTextChanged
  • Loading branch information...
1 parent 0078f4a commit 9f164bea795a77ee83a67dc33f308b5f8a74404c @robotboy655 robotboy655 committed Apr 22, 2016
Showing with 27 additions and 40 deletions.
  1. +15 −16 garrysmod/lua/vgui/dlabeleditable.lua
  2. +12 −24 garrysmod/lua/vgui/dlabelurl.lua
@@ -1,14 +1,13 @@
-PANEL = {}
+local PANEL = {}
function PANEL:Init()
-
end
function PANEL:SizeToContents()
- local w, h = self:GetContentSize()
- self:SetSize( w+ 16, h ) -- Add a bit more room so it looks nice as a textbox :)
+ local w, h = self:GetContentSize()
+ self:SetSize( w + 16, h ) -- Add a bit more room so it looks nice as a textbox :)
end
@@ -18,30 +17,30 @@ function PANEL:DoDoubleClick()
TextEdit:Dock( FILL )
TextEdit:SetText( self:GetText() )
TextEdit:SetFont( self:GetFont() )
-
+
TextEdit.OnEnter = function()
-
- local text = self:OnTextChanged( TextEdit:GetText() )
+
+ local text = self:OnLabelTextChanged( TextEdit:GetText() )
self:SetText( text )
hook.Run( "OnTextEntryLoseFocus", TextEdit )
TextEdit:Remove()
-
+
end
-
+
TextEdit.OnLoseFocus = function()
-
+
hook.Run( "OnTextEntryLoseFocus", TextEdit )
TextEdit:Remove()
-
+
end
-
- TextEdit:RequestFocus()
- TextEdit:OnGetFocus() -- Because the keyboard input might not be enabled yet! (spawnmenu)
- TextEdit:SelectAllText( true )
+
+ TextEdit:RequestFocus()
+ TextEdit:OnGetFocus() -- Because the keyboard input might not be enabled yet! (spawnmenu)
+ TextEdit:SelectAllText( true )
end
-function PANEL:OnTextChanged( text )
+function PANEL:OnLabelTextChanged( text )
return text
end
@@ -1,46 +1,37 @@
---[[ _
- ( )
- _| | __ _ __ ___ ___ _ _
- /'_` | /'__`\( '__)/' _ ` _ `\ /'_` )
-( (_| |( ___/| | | ( ) ( ) |( (_| |
-`\__,_)`\____)(_) (_) (_) (_)`\__,_)
-
- DLabelURL
---]]
local PANEL = {}
-AccessorFunc( PANEL, "m_colText", "TextColor" )
-AccessorFunc( PANEL, "m_colTextStyle", "TextStyleColor" )
+AccessorFunc( PANEL, "m_colText", "TextColor" )
+AccessorFunc( PANEL, "m_colTextStyle", "TextStyleColor" )
-AccessorFunc( PANEL, "m_bAutoStretchVertical", "AutoStretchVertical" )
+AccessorFunc( PANEL, "m_bAutoStretchVertical", "AutoStretchVertical" )
--[[---------------------------------------------------------
Init
-----------------------------------------------------------]]
function PANEL:Init()
self:SetTextColor( Color( 0, 0, 255 ) )
-
+
-- Nicer default height
self:SetTall( 20 )
-
+
-- This turns off the engine drawing
self:SetPaintBackgroundEnabled( false )
self:SetPaintBorderEnabled( false )
-
+
end
--[[---------------------------------------------------------
SetTextColor
-----------------------------------------------------------]]
function PANEL:ApplySchemeSettings( col )
- self:UpdateColours( self:GetSkin() );
-
+ self:UpdateColours( self:GetSkin() )
+
local col = self.m_colTextStyle
if ( self.m_colText ) then col = self.m_colText end
-
+
self:SetFGColor( col.r, col.g, col.b, col.a )
end
@@ -56,15 +47,14 @@ function PANEL:GetColor()
end
-
--[[---------------------------------------------------------
Exited
-----------------------------------------------------------]]
function PANEL:OnCursorEntered()
-
+
self:InvalidateLayout()
self:SetTextColor( Color( 0, 50, 255 ) )
-
+
end
--[[---------------------------------------------------------
@@ -74,15 +64,13 @@ function PANEL:OnCursorExited()
self:InvalidateLayout()
self:SetTextColor( Color( 0, 50, 255 ) )
-
+
end
--[[---------------------------------------------------------
UpdateColours
-----------------------------------------------------------]]
function PANEL:UpdateColours( skin )
-
end
-
derma.DefineControl( "DLabelURL", "A Label", PANEL, "URLLabel" )

0 comments on commit 9f164be

Please sign in to comment.