Jump to content

Synchronizing a label/TexEdit with slider


wctltya

Recommended Posts

I have label/TextEdit and slider widgets and would like to sync label/TextEdit value with the slider position.

Actually I do it, but when slider is on it's final position, i.e. is released, but not during the movement. I tried with the following approach:

 if((pe->type == GEVENT_GWIN_SLIDER) && ((((GEventGWinSlider *)pe)->type == GSLIDER_EVENT_MOVE)  || (((GEventGWinSlider *)pe)->type == GSLIDER_EVENT_SET))){
        NewValue = gwinSliderGetPosition(ghSlider);
    }

but it doesn't work.

Is it possible to have an auto sync by for example attaching label/TextEdit as listener of slider events or so? The events systems is not so clear for me.

Link to comment
Share on other sites

I'm confused Joel, because inmarket said:

3 hours ago, inmarket said:

The position to use is available in the event itself.

So, how to get it if I shall not use gwinSliderGetPosition()? Where is it?

Actually I'm using following approach: 

pe->type == GEVENT_GWIN_SLIDER) {
        NewValue = gwinSliderGetPosition(ghSlider);
}

Then I'm using the NewValue to update the numeric value in the Label. 

Is that approach wrong? Or is there better one? Where I can see a demo where a label or TextEdit are synced with slider?

Link to comment
Share on other sites

The new position (value) is part of the event that you receive:

typedef struct GEventGWinSlider {
	GEventType		type;				// The type of this event (GEVENT_GWIN_SLIDER)
	GHandle			gwin;				// The slider that is returning results
	#if GWIN_WIDGET_TAGS
		WidgetTag	tag;				// The slider tag
	#endif
	int				position;

	uint8_t			action;
		#define GSLIDER_EVENT_SET		4		/* Slider position is set. This is the only event returned by default   */
		#define GSLIDER_EVENT_CANCEL	3		/* Slider position changing has been cancelled */
		#define GSLIDER_EVENT_START		2		/* Slider position has started changing */
		#define GSLIDER_EVENT_MOVE		1		/* Slider position has been moved */
} GEventGWinSlider;

Have a look at the slider demo, it shows exactly how to do that.
Here's a simplified section of that (untested):

const char* sAction;
GEvent* event;
GEventGWinSliderEvent* sliderEvent;

event = geventEventWait(&gl, TIME_INFINITE);

switch(event->type) {

	// Handle slider events
	case GEVENT_GWIN_SLIDER: {
		// Cast to slider event
		sliderEvent = (GEventGWinSlider*)event;
		switch(sliderEvent->action) {
			case GSLIDER_EVENT_SET:		sAction = "SET";		break;
			case GSLIDER_EVENT_CANCEL:	sAction = "CANCEL";		break;
			case GSLIDER_EVENT_MOVE:	sAction = "MOVE";		break;
			case GSLIDER_EVENT_START:	sAction = "START";		break;
		}
		printf("Slider position = %d %s\n", sliderEvent->position, sAction);
		break;
	}

	default:
		break;
}

 

Link to comment
Share on other sites

  • 10 months later...

Hi guys!

I'm tried do same.

I did 2 sliders. I want synchronize realtime slider1 with slider2.

But slider2 change position only when I released slider1.

uint16_t Slider_Position = 0;
GEventGWinSlider * sliderEvent;
void guiEventLoop(void)
{
    GEvent* pe;

    while (1) {
        // Get an event
        pe = geventEventWait(&gl, TIME_INFINITE);
        switch (pe->type) {

          case GEVENT_GWIN_SLIDER:
                //Slider_Position = ((GEventGWinSlider *)pe)->position;
                sliderEvent = (GEventGWinSlider*)pe;
                gwinSliderSetPosition(ghSlider2,Slider_Position);

                break;   

         }

   }

}

 

Edited by TheProdigalCat
Link to comment
Share on other sites

That is because a slider can be cancelled by moving your finger off the slider while still touched. By default the slider only returns an event when its value is truly set which is on release.

To get the extra events it is either a listener flag or more likely a slider init flag (I can't remember which). See the slider demo program because it shows how to get the extra events.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...