cancel
Showing results for 
Search instead for 
Did you mean: 

How To Get Current Page While Using Swipe Container.

KKurt.1
Associate II

So i want to change the page of the swipe container using flex buttons. There is setSelectePage function in swipecontainer class for that but its little meaningless when i dont know which page i am in. Is there a way to get currentpage? Or is there any other way to achieve this?

1 ACCEPTED SOLUTION

Accepted Solutions
Alexandre RENOUX
Principal

Great, glad you found the answer.

However, what you did will only work with the Simulator because when using an IDE like CubeIDE or IAR to build your project, it uses a library within which there is the SwipeContainer. Therefore, your changes will not be taken into account when building and downloading the binary into your board.

Find enclosed an example with a custom SwipeContainer class. If you press the button at the top left of the screen, it prints the current page index.

/Alexandre

View solution in original post

4 REPLIES 4
Alexandre RENOUX
Principal

Hello,

Indeed there's no getter for the currentPage index but this is something that needs to be added, hopefully soon.

For the time being, in case you don't use the Swipe movement, you can know the current page you are by using a variable.

For instance :

uint8_t currentPageNumber;

Then when your application starts you know exactly the first page you are in. Let's say you have 3 pages and you start at page 1. Then when the view is initialized, you simply set currentPageNumber = 0. Then if you say setCurrentPage(1), you know you'll be Page 2 so currentPageNumber = 1.

In case you are using the Swipe movement, you need to add a getter in SwipeContainer.cpp and .hpp manually. But this will become your files so they need to be in your gui/ folder, therefore you won't be able to use the Designer to create your SwipeContainer and you will code the implementation yourself.

I'll try to make an example and enclose it to this thread.

/Alexandre

KKurt.1
Associate II

Hello, Thanks for your answer. Yes i am using both swipe movement and external flex button. So if i use swipe movement to change the page i couldnt know which page i am in. But i managed to find a solution.

So i noticed if i change the source files of the swipecontainer i cant use it with touchgfx. But that is not true for include files. I found that swipecontainer class already have currentPage variable but its in private. I simple added getter function in include files that returns that currentpage variable without changing the source files. And everything if working perfectly now.

Thanks for your answer.

Alexandre RENOUX
Principal

Great, glad you found the answer.

However, what you did will only work with the Simulator because when using an IDE like CubeIDE or IAR to build your project, it uses a library within which there is the SwipeContainer. Therefore, your changes will not be taken into account when building and downloading the binary into your board.

Find enclosed an example with a custom SwipeContainer class. If you press the button at the top left of the screen, it prints the current page index.

/Alexandre

KKurt.1
Associate II

Brilliant.

Thank you for this example. Although i can't see the swipe container on designer, it still works in simulation mode.

Thanks again.