• Print

Author Topic: A couple dnumslider questions  (Read 4935 times)

0 Members and 1 Guest are viewing this topic.

Offline Doomed

  • Newbie
  • *
  • Posts: 28
  • Karma: 0
A couple dnumslider questions
« on: July 10, 2017, 01:32:38 pm »
1. How would I go about setting the increments of a dnumslider? E.g move by 5's or 10's instead of 1's

2. Is it possible for the user to type their own values on the right?



Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: A couple dnumslider questions
« Reply #1 on: July 10, 2017, 02:04:35 pm »
1. You could use DNumSlider:OnValueChanged to change the value of the slider by this amount (using Panel:GetValue + amount_you_want)

2. You could use a DTextEntry to get a value, then set the slider's value to that of the DTextEntry.
Examples:
Code: Lua
  1. -- For altering the increment
  2. local frame = vgui.Create( "DFrame" )
  3. frame:SetSize( 500, 200 )
  4. frame:Center()
  5. frame:MakePopup()
  6.  
  7. local slider = vgui.Create( "DNumSlider", frame )
  8. slider:SetPos( 50, 50 )
  9. slider:SetSize( 300, 100 )
  10. slider:SetText( "Some text" )
  11. slider:SetMin( 0 )
  12. slider:SetMax( 1000 )
  13. slider:SetDecimals( 0 )
  14. slider:OnValueChanged( slider:SetValue( slider:GetValue() + 5 ) ) -- Increments by 5
  15.  
Code: Lua
  1. -- For using text to change value
  2. local frame = vgui.Create( "DFrame" )
  3. frame:SetSize( 500, 200 )
  4. frame:Center()
  5. frame:MakePopup()
  6.  
  7. local slider = vgui.Create( "DNumSlider", frame )
  8. slider:SetPos( 50, 50 )
  9. slider:SetSize( 300, 100 )
  10. slider:SetText( "Some text" )
  11. slider:SetMin( 0 )
  12. slider:SetMax( 256 )
  13. slider:SetDecimals( 2 ) -- Allows 2 points after decimal (1 = 1.00)
  14.  
  15. local text = vgui.Create( "DTextEntry", frame )
  16. text:SetPos( 75, 50 )
  17. text:SetSize( 50, 50 )
  18. text:OnValueChange( slider:SetValue( text:GetValue() ) )
  19.  
Keep in mind that is rough code, I just wrote it up in like a minute or two. Keep in mind it may or may not work, but you should use this as a basis of what you want it to do.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

  • Print