Skip to content
Raphael Menges edited this page Mar 3, 2016 · 7 revisions

Notifications are sent by Interactive Elements to registered listeners.

Sensor listener

To create a listener, one has to implement the abstract class given in the interface called SensorListener.

class ScrollListener : public eyegui::SensorListener
{
public:
    void virtual penetrated(eyegui::Layout* pLayout, std::string id, float amount)
    {
      scrolling = amount; // example
    }
};

The interface expects a pointer to the layout, the id of the sensor and a weak pointer to an instance of your listener implementation.

auto scrollListener = std::shared_ptr<ScrollListener>(new ScrollListener);
eyegui::registerSensorListener(pLayout, "scroll_up", scrollListener);

Button listener

To create a listener, one has to implement the abstract class given in the interface called ButtonListener.

class ModeListener : public eyegui::ButtonListener
{
public:
    void virtual hit(eyegui::Layout* pLayout, std::string id)
    {
      toggleMode(); // example
    }
    void virtual down(eyegui::Layout* pLayout, std::string id) {}
    void virtual up(eyegui::Layout* pLayout, std::string id) {}
};

The interface expects a pointer to the layout, the id of the button and a weak pointer to an instance of your listener implementation.

auto modeListener = std::shared_ptr<ModeListener>(new ModeListener);
eyegui::registerButtonListener(pLayout, "mode", modeListener);

Keyboard listener

To create a listener, one has to implement the abstract class given in the interface called KeyboardListener.

class TypingListener : public eyegui::KeyboardListener
{
public:
    void virtual keyPressed(eyegui::Layout* pLayout, std::string id, std::u16string value)
    {
        word += value; // example
    }
    void virtual keyPressed(eyegui::Layout* pLayout, std::string id, std::string value) {}
};

The interface expects a pointer to the layout, the id of the button and a weak pointer to an instance of your listener implementation.

auto typingListener = std::shared_ptr<TypingListener>(new TypingListener);
eyegui::registerKeyboardListener(pLayout, "keyboard", typingListener);

Clone this wiki locally