Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sources/Application/Views/BaseClasses/UITextField.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class UITextField : public UIField, public Observable {
private:
int selected_;
uint8_t currentChar_ = 0;
uint8_t lastUsedChar_ = 'A';
Variable *src_; // Pointer instead of reference
const etl::string<MAX_UITEXTFIELD_LABEL_LENGTH> label_;
uint8_t fourcc_;
Expand Down
56 changes: 20 additions & 36 deletions sources/Application/Views/BaseClasses/UITextField.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -82,52 +82,37 @@ template <uint8_t MaxLength> void UITextField<MaxLength>::OnEditClick() {

template <uint8_t MaxLength>
void UITextField<MaxLength>::ProcessArrow(unsigned short mask) {
auto buffer(src_->GetString());
etl::string<MAX_VARIABLE_STRING_LENGTH> buffer(src_->GetString());
auto applyAndNotify = [&]() {
src_->SetString(buffer.c_str(), true);
SetChanged();
NotifyObservers(
reinterpret_cast<I_ObservableData *>(static_cast<uintptr_t>(fourcc_)));
};

// If the variable's value is empty, we need to initialize it when the user
// starts editing
bool isEmptyBuffer = buffer.empty();

switch (mask) {
case EPBM_UP:
// If buffer is empty or matches default, initialize with 'A'
if (isEmptyBuffer || buffer.compare(defaultValue_) == 0) {
currentChar_ = 0;
buffer.clear();
buffer.append("A");
src_->SetString(buffer.c_str(), true);
} else {
buffer[currentChar_] = getNext(buffer.c_str()[currentChar_], false);
src_->SetString(buffer.c_str(), true);
}
SetChanged();
NotifyObservers(
reinterpret_cast<I_ObservableData *>(static_cast<uintptr_t>(fourcc_)));
break;
case EPBM_DOWN:
// If buffer is empty or matches default, initialize with 'A'
if (isEmptyBuffer || buffer.compare(defaultValue_) == 0) {
currentChar_ = 0;
buffer.clear();
buffer.append("A");
src_->SetString(buffer.c_str(), true);
buffer = "A";
} else {
buffer[currentChar_] = getNext((char)buffer.c_str()[currentChar_], true);
src_->SetString(buffer.c_str(), true);
buffer[currentChar_] =
getNext(buffer.c_str()[currentChar_], mask == EPBM_DOWN);
}
SetChanged();
NotifyObservers(
reinterpret_cast<I_ObservableData *>(static_cast<uintptr_t>(fourcc_)));
applyAndNotify();
break;
case EPBM_LEFT:
// If we're showing the default value and user presses left, initialize with
// the default
if (isEmptyBuffer) {
buffer = defaultValue_;
src_->SetString(buffer.c_str(), true);
SetChanged();
NotifyObservers(reinterpret_cast<I_ObservableData *>(
static_cast<uintptr_t>(fourcc_)));
applyAndNotify();
}
if (currentChar_ > 0) {
currentChar_--;
Expand All @@ -138,24 +123,23 @@ void UITextField<MaxLength>::ProcessArrow(unsigned short mask) {
// with the default
if (isEmptyBuffer) {
buffer = defaultValue_;
src_->SetString(buffer.c_str(), true);
SetChanged();
NotifyObservers(reinterpret_cast<I_ObservableData *>(
static_cast<uintptr_t>(fourcc_)));
applyAndNotify();
}
if (currentChar_ < (buffer.length() - 1)) {
currentChar_++;
// -1 to allow for adding 1 more char
} else if (currentChar_ < (MaxLength - 1)) {
currentChar_++;
buffer.append("A");
src_->SetString(buffer.c_str(), true);
SetChanged();
NotifyObservers(reinterpret_cast<I_ObservableData *>(
static_cast<uintptr_t>(fourcc_)));
char str[2] = {lastUsedChar_, 0};
buffer.append(str);
applyAndNotify();
}
break;
};

// remember last used char for appending when user moves right at the end
// of the string
lastUsedChar_= buffer.c_str()[currentChar_];
};

template <uint8_t MaxLength>
Expand Down