cancel
Showing results for 
Search instead for 
Did you mean: 

How does one override handleDragEvent(const DragEvent& event); method of a SwipeContainer thet is a member of a View object.

manto.1
Senior

I have a MainView that has a member Swipe containter.

class MainViewBase : public touchgfx::View<MainPresenter>
{
public:
    MainViewBase();
    virtual ~MainViewBase() {}
    virtual void setupScreen();
 
protected:
    FrontendApplication& application() {
        return *static_cast<FrontendApplication*>(touchgfx::Application::getInstance());
    }
 
    /*
     * Member Declarations
     */
    touchgfx::SwipeContainer swipeContainer;

Every swipeContainer has a virtual method handleDragEvent

class SwipeContainer : public Container
{
public:
    SwipeContainer();
    virtual ~SwipeContainer();
 
    virtual void handleTickEvent();
    virtual void handleClickEvent(const ClickEvent& event);
    virtual void handleDragEvent(const DragEvent& event);
    virtual void handleGestureEvent(const GestureEvent& event);

I would like to implement a slideMenu expansion when swipe cointainer detects drag in Y direction. Where can I overide handleDragEvent of this swipeContainer and redefine what I want?

1 REPLY 1
Yoann KLEIN
ST Employee

Hello @manto.1​ ,

Like you said, the SwipeContainer member is called in the MainViewBase class.

Since the MainView class derives from the MainViewBase class, you can easily access and override the MainViewBase class members and methods in your MainView class :

  • Override the SwipeContainer handleDragEvent() method in MainView.hpp
void handleDragEvent(const DragEvent& event) override; 
  • Implement this method in your MainView.cpp
void MainView::handleDragEvent(const DragEvent& event)
{
}

Then, every time the user will drag the SwipeContainer, this method will be called.

You will be able to easily access to X and Y coordinates and/or dragging directions on the screen, thanks to the methods implemented in the DragEvent class, e.g. getDeltaY()(https://support.touchgfx.com/4.18/docs/api/classes/classtouchgfx_1_1_drag_event).

Hope that this helped,

/Yoann

Yoann KLEIN
ST Software Developer | TouchGFX