cancel
Showing results for 
Search instead for 
Did you mean: 

touchgfx::slider: Сan I change the slider value only by moving its thumb?

skvotcher
Associate II

Good evening.

I am developing in the medical field and have encountered a problem: to eliminate accidental touch errors, it's necessary for the user to be able to change slider values only through deliberate actions, such as a thoughtful movement of the slider.

Could you please tell me if it's possible to implement slider behavior using standard means in such a way that the value changes only if the user moves the slider thumb? That is, if a click occurs within the slider nothing will happen, but if the click is on the slider thumb and it starts moving, only then will the values change?

Thank you for your response.

 

Regards, Alexander.

3 REPLIES 3
skvotcher
Associate II

I found only this method, but it doesn't work properly and seems to me not very scalable.

void Sets::sliderClickHandler(const Slider& s, const ClickEvent& e)
{		
	sliderFlag = true;
	
	if (e.getType() == ClickEvent::PRESSED)
	{
		int clickX = e.getX()-slider.getX();		
		Drawable* indicator = slider.getFirstChild()->getNextSibling()->getNextSibling();
		int x = indicator->getX();		
		int rightX = x + indicator->getWidth();		
		if (clickX >= x && clickX <= rightX)
		{		
			
		}
	}
	if (e.getType() == ClickEvent::RELEASED) 
	{
		//slider.setTouchable(false);
		sliderFlag = false;
	}		
	
}

Firstly, in future versions of TouchGFX, the initialization order might change, and then the indicator could become a different element.

Secondly, the code I provided doesn't work correctly; it always determines that the click occurred on the slider thumb because, after the click, the thumb moves to the point of the click.

I'm really hoping for your help.

 

 

Yoann KLEIN
ST Employee

Hello @skvotcher,

For me, a way to differentiate an accidental click from a drag gesture could be to use the handleDragEvent() on your slider. Then, when a click/drag is detected, this method will be triggered and pass a DragEvent object, which will expose different distances and coordinates attributes, such as the deltaX and deltaY drag distances. 

You could then define that the gesture was a click if the delta distances are < 20 px for example, and consider it was a drag otherwise.

I'm not sure it's the best solution, but it could work.

Please also check out the demos and examples in TouchGFX Designer 4.23.0.

Hope it helps ! 

Yoann KLEIN
ST Software Developer | TouchGFX

Thank you for your response.

However, when setting the Draggable parameter for the slider, a situation arises where its image starts to blend. Unfortunately, this is not suitable.