cancel
Showing results for 
Search instead for 
Did you mean: 

Swipe container with ClickListener for each page

MCA_Dev
Associate III

Hello,

I've implemented, using the Designer, a Swipe container composed by 2 pages which are respectively 2 containers (SwipeContainerPage1, SwipeContainerPage2).

Each page includes some text and box which are updated on page swipe change and everything works fine.

Now I want to command an Action (a page change) when the user presses for a couple of seconds (let's say 2 seconds) SwipeContainerPage1 or SwipeContainerPage2 while maintaing the swiping property of this macro object.

Is this possible? I've taken as a reference the "ClickListener_Implementation_longPress" as a reference but with no success...

(Edited) I tried doing this and it works for the first page (calls goTo_GUITemperatureSet_Action()) but it blocks the swipe capability and I cannot go to the SwipeContainerPage2:

//In the .hpp file
class GUIMainSwipe_View : public GUIMainSwipe_ViewBase
{
public:
    GUIMainSwipe_View();
    virtual ~GUIMainSwipe_View() {}
    virtual void setupScreen();
    virtual void tearDownScreen();
    virtual void handleTickEvent();

    //container click handler
    void containerClickHandler(const Container& c, const ClickEvent& evt);		
protected:
	Callback<GUIMainSwipe_View, const Container&, const ClickEvent&> containerClickedCallback;
	uint8_t		CurrSubPage;

	bool  SwipeContainerPage1_Pressed_status;
	int   SwipeContainerPage1_Pressed_timeout;
	bool  SwipeContainerPage2_Pressed_status;
	int   SwipeContainerPage2_Pressed_timeout;
};

 

//In the .cpp file

GUIMainSwipe_View::GUIMainSwipe_View():
containerClickedCallback(this, &GUIMainSwipe_View::containerClickHandler)
{
   //Set curr sub page
   CurrSubPage = SwipeContainer.getSelectedPage();
}

void GUIMainSwipe_View::setupScreen()
{
  GUIMainSwipe_ViewBase::setupScreen();
  //User init code
  SwipeContainerPage1.setClickAction(containerClickedCallback);	
  SwipeContainerPage2.setClickAction(containerClickedCallback);
  ...
}

void GUIMainSwipe_View::containerClickHandler(const Container& c, const ClickEvent& evt)
{
	if (&c == &SwipeContainerPage1)
	{
		if (evt.getType() == ClickEvent::PRESSED)
		{	
			SwipeContainerPage1_Pressed_status = true;
		}
		else if (evt.getType() == ClickEvent::RELEASED)
		{
			SwipeContainerPage1_Pressed_status = false;
			SwipeContainerPage1_Pressed_timeout = 0;
		}
	}
	else if (&c == &SwipeContainerPage2)
	{
		if (evt.getType() == ClickEvent::PRESSED)
		{	
			SwipeContainerPage2_Pressed_status = true;
		}
		else if (evt.getType() == ClickEvent::RELEASED)
		{
			SwipeContainerPage2_Pressed_status = false;
			SwipeContainerPage2_Pressed_timeout = 0;
		}		
	}
}

void GUIMainSwipe_View::handleTickEvent()
{
	//Evaluate long press for page change
	if (SwipeContainerPage1_Pressed_status == true)
	{
		SwipeContainerPage1_Pressed_timeout++;
		if (SwipeContainerPage1_Pressed_timeout == GUIMAINSWIPE_BUTTON_LONG_PRESS_TIMEOUT)
		{
			goTo_GUITemperatureSet_Action();
			SwipeContainerPage1_Pressed_status = false;
		}
	}	
	if (SwipeContainerPage2_Pressed_status == true)
	{
		SwipeContainerPage2_Pressed_timeout++;
		if (SwipeContainerPage2_Pressed_timeout == GUIMAINSWIPE_BUTTON_LONG_PRESS_TIMEOUT)
		{
			goTo_GUITemperatureSet_Action();
			SwipeContainerPage2_Pressed_status = false;
		}
	}		

}

Any hint will be appreciated, thank you!

2 REPLIES 2
LouisB
ST Employee

Hello @MCA_Dev ,

Could you give more details. What does the goTo_GUITemperatureSet_Action() ?

BR,

 

Louis BOUDO
ST Software Engineer | TouchGFX

Thank you for your reply @LouisB.

The goTo_GUITemperatureSet_Action() is an action I setup from the designer to command a screen change.

void GUIMainSwipe_ViewBase::goTo_GUITemperatureSet_Action()
{
    //goTo_GUITemperatureSet_Interaction
    //When goTo_GUITemperatureSet_Action is called change screen to GUITemperatureSet_
    //Go to GUITemperatureSet_ with no screen transition
    application().gotoGUITemperatureSet_ScreenNoTransition();
}

Probably I've should've asked this question before:

is it possible to have both the swipe feature (setup from the designer, it contain two pages: SwipeContainerPage1 and SwipeContainerPage2) and setup afterwards the clickListener (in the user code) for SwipeContainerPage1 and SwipeContainerPage2 to trigger a long pressure on those containers? Or should I setup the Mixin ClickListener to the objects inside the container to make it work (for example Temp2_textArea_Page2 and Temp1_textArea_Page1) ?

MCA_Dev_0-1753186752899.png

I'm still quite new to this libraries and specifically C++, hopefully you can give me some help to make it through...

Thank you!

Best regards,

M.