[ion/events] Factor includes of layout_events.h

Change-Id: Id7f68f4dfb4727453a02437a0b824492a8c94730
This commit is contained in:
Gabriel Ozouf
2020-10-06 16:11:28 +02:00
committed by Émilie Feral
parent 4ea8263185
commit b0b6fe33c9
4 changed files with 26 additions and 21 deletions

View File

@@ -36,6 +36,9 @@ public:
bool isDefined() const;
static constexpr int PageSize = Keyboard::NumberOfKeys;
private:
bool defaultIsDefined() const;
const char * defaultText() const;
uint8_t m_id;
};

View File

@@ -1,5 +1,4 @@
#include <ion/events.h>
#include <layout_events.h>
namespace Ion {
namespace Events {
@@ -8,18 +7,11 @@ void didPressNewKey() {
}
bool Event::isDefined() const {
if (isKeyboardEvent()) {
return s_dataForEvent[m_id].isDefined();
} else {
return (*this == None || *this == Termination || *this == USBEnumeration || *this == USBPlug || *this == BatteryCharging);
}
return defaultIsDefined();
}
const char * Event::text() const {
if (m_id >= 4*PageSize) {
return nullptr;
}
return s_dataForEvent[m_id].text();
return defaultText();
}
}

View File

@@ -52,5 +52,20 @@ bool Event::hasText() const {
return text() != nullptr;
}
bool Event::defaultIsDefined() const {
if (isKeyboardEvent()) {
return s_dataForEvent[m_id].isDefined();
} else {
return (*this == None || *this == Termination || *this == USBEnumeration || *this == USBPlug || *this == BatteryCharging);
}
}
const char * Event::defaultText() const {
if (m_id >= 4*PageSize) {
return nullptr;
}
return s_dataForEvent[m_id].text();
}
}
}

View File

@@ -1,7 +1,6 @@
#include "events.h"
#include "haptics.h"
#include <ion/events.h>
#include <layout_events.h>
#include <SDL.h>
namespace Ion {
@@ -17,21 +16,17 @@ char * sharedExternalTextBuffer() {
}
const char * Event::text() const {
if (m_id >= 4*PageSize) {
if (*this == ExternalText) {
return const_cast<const char *>(sharedExternalTextBuffer());
}
return nullptr;
if (*this == ExternalText) {
return const_cast<const char *>(sharedExternalTextBuffer());
}
return s_dataForEvent[m_id].text();
return defaultText();
}
bool Event::isDefined() const {
if (isKeyboardEvent()) {
return s_dataForEvent[m_id].isDefined();
} else {
return (*this == None || *this == Termination || *this == USBEnumeration || *this == USBPlug || *this == BatteryCharging || *this == ExternalText);
if (*this == ExternalText) {
return true;
}
return defaultIsDefined();
}
}