Custom Label attached to Custom Slider


#1

Hello,
I am new to Juce and curious if anyone has found a way to connect a custom Label class to a custom slider class.

.attachedcomponent doesn’t seem to work and creating a custom text box through lookandfeel methods seems to break the drawing of my custom slider?

I’m curious if there is a way to force and update through Label::setText(); and Slider::getTextfromValue.

Is there a way to connect a Label to a Slider out side the bounds of the slider?


#2

The problem with the .attachtoComponent(&slider, is this Bool );

Hopefully, I’m missing the obvious solution!

P.S.
If I’m not completely off track I believe the solution is in the sliderValueChanged().


#3

The Label has no idea about values and ranges. But you can connect two sliders, using one as Slider (LinearBar, TextBoxBelow) and the other Slider (Rotary, NoTextBox). The LinearBar will display the text on top of a slider-like rectangle. If you don’t want the bar in the background, you can set the colours to be the same as the background.

To connect them, either connect them to the same parameter, or use the getValueObject() to connect them:

Slider s1 (LinearBar, TextBoxBelow);
Slider s2 (Rotary, NoTextBox);
s2.getValueObject().referTo (s1.getValueObject());

Hope that helps

N.B. the attachToComponent is meant to set a position relative to the component you attach the label to. It does nothing about the displayed content.


#4

I thought of that but haven’t gotten around to testing it.
That was my next attempt.
However, This did work, although not very elegant.

void sliderValueChanged(Slider* slider) override
{
	

	if (slider == &mSlider)
	{
		x = mTime.getValue();
		push = std::to_string(x);
		DisplayLabel.setText(push, dontSendNotification);
	}

}

Thank you for the quick reply, I just got this up and working!
I am going to work to make it update the slider upon user input aswell.

string push;
int x;

“I used an int to remove the decimals”