# A new slider : TextVerticalDrag

**URL:** <https://forum.juce.com/t/a-new-slider-textverticaldrag/5796>\
**Category:** General JUCE discussion\
**Created:** [October 22, 2010, 8:17am UTC](https://forum.juce.com/t/a-new-slider-textverticaldrag/5796 "2010-10-22T08:17:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![djWhite](https://avatars.discourse-cdn.com/v4/letter/d/3be4f8/32.png) [@djWhite](https://forum.juce.com/u/djWhite)\
**Post date:** [October 22, 2010, 8:17am UTC](https://forum.juce.com/t/a-new-slider-textverticaldrag/5796/1 "2010-10-22T08:17:00Z")

</div>

Hi Jules,

in my app I need a new kind of slider. Just a label displaying the value with the possibility to change the value by clicking on it (like LinearBar) or dragging up and down with the mouse (like RotaryVerticalDrag)  
If you like to add this kind of slider to the list there are just few changes in the juce\_slider.ccp and header.

Best regards,  
Andrea

juce\_slider.h  
add this as last enum SliderStyle

```auto
TextVerticalDrag,	/**< A text label shown the value that can be changed by draggin the mouse up-and-down.
							@see setRotaryParameters*/
```

juce\_slider.cpp

```auto
void Slider::lookAndFeelChanged()
{
	[...] (line 356)
if ((style == LinearBar) || (style == TextVerticalDrag))
	valueBox->addMouseListener (this, false);
	[...]
}

(line 827)
void Slider::paint (Graphics& g)
{
	if ((style != IncDecButtons) && (style != TextVerticalDrag))
	[...]
}

void Slider::resized()
{
	[...] (line 880)
	if ((style == LinearBar) || (style == TextVerticalDrag))
	{
		if (valueBox != 0)
			valueBox->setBounds (getLocalBounds());
	}
	[...] (line 915)
	if ((style == LinearBar) || (style == TextVerticalDrag))
	{
		const int barIndent = 1;
		sliderRegionStart = barIndent;
	[...]
}

void Slider::restoreMouseIfHidden()
{
	[...] (line 1154)
		Point<int> mousePos;

		if (style == RotaryHorizontalDrag || style == RotaryVerticalDrag || style == TextVerticalDrag)
		{
						mousePos = Desktop::getLastMouseDownPosition();
	[...]
}

void Slider::mouseDrag (const MouseEvent& e)
{
	[...] (line 1276)
				double scaledMousePos = (mousePos - sliderRegionStart) / (double) sliderRegionSize;

				if (style == RotaryHorizontalDrag
					|| style == RotaryVerticalDrag || style == TextVerticalDrag
					|| style == IncDecButtons
	[...] (line 1330)
						if (isVertical() || style == RotaryVerticalDrag || style == TextVerticalDrag
						 || (style == IncDecButtons && ! incDecDragDirectionIsHorizontal()))
						speed = -speed;
	[...]
}
```

---

<div class="post-metadata">

**Author:** ![valhalladsp](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/valhalladsp/32/71_2.png) [@valhalladsp](https://forum.juce.com/u/valhalladsp)\
**Post date:** [October 23, 2010, 5:01am UTC](https://forum.juce.com/t/a-new-slider-textverticaldrag/5796/2 "2010-10-23T05:01:59Z")

</div>

Very cool! The latest plugins from Audio Damage use this idea of “numbers as sliders.” It makes for a very tidy GUI, that is easy to read and use.

Sean Costello

---

<div class="post-metadata">

**Author:** ![djWhite](https://avatars.discourse-cdn.com/v4/letter/d/3be4f8/32.png) [@djWhite](https://forum.juce.com/u/djWhite)\
**Post date:** [October 27, 2010, 8:32am UTC](https://forum.juce.com/t/a-new-slider-textverticaldrag/5796/3 "2010-10-27T08:32:02Z")

</div>

Thanks Sean, I hope Jules like it too so he can add to the library.

Andrea

---

<div class="post-metadata">

**Author:** ![masshacker](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/masshacker/32/650_2.png) [@masshacker](https://forum.juce.com/u/masshacker)\
**Post date:** [October 27, 2010, 8:47am UTC](https://forum.juce.com/t/a-new-slider-textverticaldrag/5796/4 "2010-10-27T08:47:25Z")

</div>

> [@](#):
>
> Thanks Sean, I hope Jules like it too so he can add to the library.

+1!

---

<div class="post-metadata">

**Author:** ![valhalladsp](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/valhalladsp/32/71_2.png) [@valhalladsp](https://forum.juce.com/u/valhalladsp)\
**Post date:** [January 27, 2011, 4:41am UTC](https://forum.juce.com/t/a-new-slider-textverticaldrag/5796/5 "2011-01-27T04:41:06Z")

</div>

I’ve been revisiting this today. Ideally, a TextVerticalDrag slider would have the ability to use a larger or smaller font size than the default value for the sliders. Would this be best handled by a LookAndFeel modification, or by creating a new TextSlider class that has the ability to change text size, font, etc?

Sean Costello

---

<div class="post-metadata">

**Author:** ![valhalladsp](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/valhalladsp/32/71_2.png) [@valhalladsp](https://forum.juce.com/u/valhalladsp)\
**Post date:** [January 27, 2011, 6:21pm UTC](https://forum.juce.com/t/a-new-slider-textverticaldrag/5796/6 "2011-01-27T18:21:22Z")

</div>

Another relevant thread on this topic: [http://www.rawmaterialsoftware.com/viewtopic.php?f=2&t=3809](http://www.rawmaterialsoftware.com/viewtopic.php?f=2&t=3809)

I’ve also thought about using a rotary slider, making it invisible, and having a Label behind it that is tied into the slider via my code (in my case, via the actual plugin parameter computation code). In general, I have been thinking about using separate Label components for my sliders, instead of using the labels that are associated with the Slider class, so I can move coefficient range warping into the plugin code instead of within the control. But that is probably a subject for a different thread.

Sean Costello
