wctltya Posted February 21, 2017 Report Share Posted February 21, 2017 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 More sharing options...
inmarket Posted February 21, 2017 Report Share Posted February 21, 2017 Don't use gwinSliderGetPosition to get the position for your label as the final position has not been set yet (and won't be until you release). The position to use is available in the event itself. Link to comment Share on other sites More sharing options...
wctltya Posted February 21, 2017 Author Report Share Posted February 21, 2017 I see inmarket, but then what you would advice me? Link to comment Share on other sites More sharing options...
Joel Bodenmann Posted February 21, 2017 Report Share Posted February 21, 2017 Do the same thing that you're doing now but read the value that comes as part of the event that you receive as @inmarket suggested. Then, everything will work exactly the way you want it without any dirty or complex workarounds. Link to comment Share on other sites More sharing options...
wctltya Posted February 21, 2017 Author Report Share Posted February 21, 2017 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 More sharing options...
Joel Bodenmann Posted February 21, 2017 Report Share Posted February 21, 2017 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 More sharing options...
wctltya Posted February 21, 2017 Author Report Share Posted February 21, 2017 Thank you Joel, It is my mistake (as usual ), somehow I haven't seen: sliderEvent->position In the slider demo. Sorry, and thank you again for your time. Link to comment Share on other sites More sharing options...
Joel Bodenmann Posted February 21, 2017 Report Share Posted February 21, 2017 No problem. Glad to hear that you manged to get it working Link to comment Share on other sites More sharing options...
TheProdigalCat Posted January 10, 2018 Report Share Posted January 10, 2018 (edited) 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 January 10, 2018 by TheProdigalCat Link to comment Share on other sites More sharing options...
inmarket Posted January 11, 2018 Report Share Posted January 11, 2018 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 More sharing options...
TheProdigalCat Posted January 11, 2018 Report Share Posted January 11, 2018 (edited) Thanks! Added gwinSliderSendExtendedEvents(ghSlider1, TRUE); That works! Now both sliders working syncronously! Edited January 11, 2018 by TheProdigalCat Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now