Permalink
Browse files

Cleaned up more vgui panels

DPanelList - resizing the panel will no longer scroll down miles below
the maximum scroll value
CtrlColor - Better handling of resizing
  • Loading branch information...
1 parent 13dc3e8 commit 30e59a8276a6ee9a20dede92ecb067db45c606d0 @robotboy655 robotboy655 committed May 11, 2016
@@ -6,8 +6,6 @@ AccessorFunc( PANEL, "m_ConVarG", "ConVarG" )
AccessorFunc( PANEL, "m_ConVarB", "ConVarB" )
AccessorFunc( PANEL, "m_ConVarA", "ConVarA" )
-local ColorRows = 16
-
--[[---------------------------------------------------------
Name: Init
-----------------------------------------------------------]]
@@ -24,10 +22,20 @@ end
-----------------------------------------------------------]]
function PANEL:PerformLayout( x, y )
+ -- Number of panels in one row
+ local ColorRows = math.ceil( #self.Mixer.Palette:GetChildren() / 3 )
+
-- We try to avoid the ugly gap on the right.
-- This seems a bit heavy handed to be calling in PerformLayout.
self.Mixer.Palette:SetButtonSize( self:GetWide() / ColorRows )
+ -- Get rid of the gap by centering the palette using an ugly hack
+ local s = ( self:GetWide() - ColorRows * self.Mixer.Palette:GetButtonSize() ) / 2
+ self.Mixer.Palette:DockMargin( s, 8, s, 0 )
+
+ -- Better height scaling for extra wide panels
+ self:SetTall( math.max( 230, self:GetWide() / 1.5 ) )
+
end
--[[---------------------------------------------------------
@@ -1,10 +1,8 @@
local PANEL = {}
-local Padding = 5
-
--[[---------------------------------------------------------
- Name: Init
+ Name: Init
-----------------------------------------------------------]]
function PANEL:Init()
@@ -15,21 +13,21 @@ function PANEL:Init()
end
--[[---------------------------------------------------------
- Name: SetConVar
+ Name: SetConVar
-----------------------------------------------------------]]
function PANEL:SetConVar( cvar )
self.ConVarValue = cvar
end
--[[---------------------------------------------------------
- Name: ConVar
+ Name: ConVar
-----------------------------------------------------------]]
function PANEL:ConVar()
return self.ConVarValue
end
--[[---------------------------------------------------------
- Name: ControlValues
+ Name: ControlValues
-----------------------------------------------------------]]
function PANEL:ControlValues( kv )
@@ -39,23 +37,23 @@ function PANEL:ControlValues( kv )
end
--[[---------------------------------------------------------
- Name: PerformLayout
+ Name: PerformLayout
-----------------------------------------------------------]]
function PANEL:PerformLayout()
local y = 5
self.Label:SetPos( 5, y )
self.Label:SetWide( self:GetWide() )
-
+
y = y + self.Label:GetTall()
y = y + 5
-
+
return y
end
--[[---------------------------------------------------------
- Name: TestForChanges
+ Name: TestForChanges
-----------------------------------------------------------]]
function PANEL:TestForChanges()
@@ -65,17 +63,16 @@ function PANEL:TestForChanges()
end
--[[---------------------------------------------------------
- Name: Think
+ Name: Think
-----------------------------------------------------------]]
function PANEL:Think()
if ( self.NextPoll && self.NextPoll > CurTime() ) then return end
-
+
self.NextPoll = CurTime() + 0.1
-
+
self:TestForChanges()
end
-
-vgui.Register( "ContextBase", PANEL, "Panel" )
+vgui.Register( "ContextBase", PANEL, "Panel" )
@@ -1,18 +1,6 @@
---[[
- _
- ( )
- _| | __ _ __ ___ ___ _ _
- /'_` | /'__`\( '__)/' _ ` _ `\ /'_` )
-( (_| |( ___/| | | ( ) ( ) |( (_| |
-`\__,_)`\____)(_) (_) (_) (_)`\__,_)
-
- DColorMixer
---]]
-
local PANEL = {}
-
AccessorFunc( PANEL, "m_ConVarR", "ConVarR" )
AccessorFunc( PANEL, "m_ConVarG", "ConVarG" )
AccessorFunc( PANEL, "m_ConVarB", "ConVarB" )
@@ -42,7 +30,7 @@ local function CreateWangFunction( self, colindex )
end
self:UpdateColor( self.m_Color )
- end
+ end
return OnValueChanged
end
@@ -69,9 +57,8 @@ function PANEL:Init()
self:SetColor( Color( color.r, color.g, color.b, self.m_bAlpha and color.a or 255 ) )
end
self.Palette.OnRightClickButton = function( ctrl, btn )
- ctrl:SaveColor( btn, self:GetColor() );
+ ctrl:SaveColor( btn, self:GetColor() )
end
-
-- The label
self.label = vgui.Create( "DLabel", self )
@@ -88,36 +75,36 @@ function PANEL:Init()
self.WangsPanel:SetVisible( self.m_bWangsPanel )
self.txtR = self.WangsPanel:Add( "DNumberWang" )
- self.txtR:SetDecimals( 0 )
- self.txtR:SetMinMax( 0, 255 )
- self.txtR:SetTall( 20 )
- self.txtR:Dock( TOP )
- self.txtR:DockMargin( 0, 0, 0, 0 )
- self.txtR:SetTextColor( Color( 150, 0, 0, 255 ) )
+ self.txtR:SetDecimals( 0 )
+ self.txtR:SetMinMax( 0, 255 )
+ self.txtR:SetTall( 20 )
+ self.txtR:Dock( TOP )
+ self.txtR:DockMargin( 0, 0, 0, 0 )
+ self.txtR:SetTextColor( Color( 150, 0, 0, 255 ) )
self.txtG = self.WangsPanel:Add( "DNumberWang" )
- self.txtG:SetDecimals( 0 )
- self.txtG:SetMinMax( 0, 255 )
- self.txtG:SetTall( 20 )
- self.txtG:Dock( TOP )
- self.txtG:DockMargin( 0, 4, 0, 0 )
- self.txtG:SetTextColor( Color( 0, 150, 0, 255 ) )
+ self.txtG:SetDecimals( 0 )
+ self.txtG:SetMinMax( 0, 255 )
+ self.txtG:SetTall( 20 )
+ self.txtG:Dock( TOP )
+ self.txtG:DockMargin( 0, 4, 0, 0 )
+ self.txtG:SetTextColor( Color( 0, 150, 0, 255 ) )
self.txtB = self.WangsPanel:Add( "DNumberWang" )
- self.txtB:SetDecimals( 0 )
- self.txtB:SetMinMax( 0, 255 )
- self.txtB:SetTall( 20 )
- self.txtB:Dock( TOP )
- self.txtB:DockMargin( 0, 4, 0, 0 )
- self.txtB:SetTextColor( Color( 0, 0, 150, 255 ) )
+ self.txtB:SetDecimals( 0 )
+ self.txtB:SetMinMax( 0, 255 )
+ self.txtB:SetTall( 20 )
+ self.txtB:Dock( TOP )
+ self.txtB:DockMargin( 0, 4, 0, 0 )
+ self.txtB:SetTextColor( Color( 0, 0, 150, 255 ) )
self.txtA = self.WangsPanel:Add( "DNumberWang" )
- self.txtA:SetDecimals( 0 )
- self.txtA:SetMinMax( 0, 255 )
- self.txtA:SetTall( 20 )
- self.txtA:Dock( TOP )
- self.txtA:DockMargin( 0, 4, 0, 0 )
- self.txtA:SetTextColor( Color( 80, 80, 80, 255 ) )
+ self.txtA:SetDecimals( 0 )
+ self.txtA:SetMinMax( 0, 255 )
+ self.txtA:SetTall( 20 )
+ self.txtA:Dock( TOP )
+ self.txtA:DockMargin( 0, 4, 0, 0 )
+ self.txtA:SetTextColor( Color( 80, 80, 80, 255 ) )
self.txtR.OnValueChanged = CreateWangFunction( self, "r" )
self.txtG.OnValueChanged = CreateWangFunction( self, "g" )
@@ -140,7 +127,6 @@ function PANEL:Init()
self:SetBaseColor( color )
end
-
self.Alpha = vgui.Create( "DAlphaBar", self )
self.Alpha:DockMargin( 4, 0, 0, 0 )
self.Alpha:Dock( RIGHT )
@@ -151,9 +137,6 @@ function PANEL:Init()
self:UpdateColor( self.m_Color )
end
-
-
-
-- Layout
self:UpdateColor( self.m_Color )
self:SetSize( 256, 230 )
@@ -166,9 +149,9 @@ end
-----------------------------------------------------------]]
function PANEL:SetLabel( text )
- if ( !text or ( text == "" ) ) then
+ if ( !text or text == "" ) then
self.label:SetVisible( false )
-
+
return
end
@@ -178,7 +161,6 @@ function PANEL:SetLabel( text )
self:InvalidateLayout()
end
-
--[[---------------------------------------------------------
Name: SetPalette
-----------------------------------------------------------]]
@@ -268,7 +250,6 @@ end
Name: TranslateValues ( Todo? )
-----------------------------------------------------------]]
function PANEL:TranslateValues( x, y )
-
end
--[[---------------------------------------------------------
@@ -305,11 +286,11 @@ end
function PANEL:UpdateConVar( strName, strKey, color )
if ( !strName ) then return end
- local col = color[strKey]
+ local col = color[ strKey ]
RunConsoleCommand( strName, tostring( col ) )
- self[ 'ConVarOld'..strName ] = col
+ self[ "ConVarOld" .. strName ] = col
end
--[[---------------------------------------------------------
@@ -388,7 +369,7 @@ end
function PANEL:GetVector()
- local col = self:GetColor();
+ local col = self:GetColor()
return Vector( col.r / 255, col.g / 255, col.b / 255 )
end
@@ -416,8 +397,8 @@ function PANEL:ConVarThink()
local b, changed_b = self:DoConVarThink( self.m_ConVarB )
local a, changed_a = 255, false
- if ( self.m_ConVarA ) then
- a, changed_a = self:DoConVarThink( self.m_ConVarA, 'a' )
+ if ( self.m_ConVarA ) then
+ a, changed_a = self:DoConVarThink( self.m_ConVarA, "a" )
end
if ( changed_r or changed_g or changed_b or changed_a ) then
@@ -433,10 +414,10 @@ function PANEL:DoConVarThink( convar )
if ( !convar ) then return end
local fValue = GetConVarNumber( convar )
- local fOldValue = self[ 'ConVarOld'..convar ]
+ local fOldValue = self[ "ConVarOld" .. convar ]
if ( fOldValue && fValue == fOldValue ) then return fOldValue, false end
- self[ 'ConVarOld'..convar ] = fValue
+ self[ "ConVarOld" .. convar ] = fValue
return fValue, true
@@ -448,10 +429,10 @@ end
function PANEL:GenerateExample( ClassName, PropertySheet, Width, Height )
local ctrl = vgui.Create( ClassName )
- ctrl:SetSize( 256, 256 )
+ ctrl:SetSize( 256, 256 )
PropertySheet:AddSheet( ClassName, ctrl, nil, true, true )
end
-derma.DefineControl( "DColorMixer", "", PANEL, "DPanel" )
+derma.DefineControl( "DColorMixer", "", PANEL, "DPanel" )
Oops, something went wrong.

0 comments on commit 30e59a8

Please sign in to comment.