Skip to content

Commit

Permalink
fix(bw): change char selection order when editing names (#5390)
Browse files Browse the repository at this point in the history
  • Loading branch information
philmoz authored and pfeerick committed Aug 8, 2024
1 parent 97447ad commit 854a9bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion companion/src/shared/namevalidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "textvalidator.h"

// characters supportd by B&W radio firmware gui editor
constexpr char NAME_VALID_PATTERN_BW[] {"[ A-Za-z0-9\\-]*"};
constexpr char NAME_VALID_PATTERN_BW[] {"[ A-Za-z0-9\\_\\-\\,\\.]*"};
// characters supported by color radio firmware keyboard widget
constexpr char NAME_VALID_PATTERN_COLOR[] {"[ A-Za-z0-9\\-\\_\\,\\.\"\\+\\/\\*\\=\\%\\!\\?\\#\\<\\>\\@\\$\\(\\)\\{\\}\\[\\]\\;\\:\\']*"};

Expand Down
34 changes: 14 additions & 20 deletions radio/src/gui/common/stdlcd/draw_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,26 +159,18 @@ char getPreviousChar(char c, uint8_t position)
return c - 1;
}

static bool isNameCharset(int v)
{
char c = (char)v;

if (c == ' ')
return true;

if (c == '-')
return true;
static const char nameChars[] = " abcdefghijklmnopqrstuvwxyz0123456789_-,.";

if (c >= '0' && c <= '9')
return true;

if (c >= 'A' && c <= 'Z')
return true;

if (c >= 'a' && c <= 'z')
return true;

return false;
static int nameCharIdx(char v)
{
if (islower(v)) return v - 'a' + 1;
if (isupper(v)) return v - 'A' + 1;
if (isdigit(v)) return v - '0' + 27;
if (v == '_') return 37;
if (v == '-') return 38;
if (v == ',') return 39;
if (v == '.') return 40;
return 0;
}

void editName(coord_t x, coord_t y, char* name, uint8_t size, event_t event,
Expand All @@ -202,7 +194,9 @@ void editName(coord_t x, coord_t y, char* name, uint8_t size, event_t event,
int8_t v = c ? c : ' ';

if (IS_NEXT_EVENT(event) || IS_PREVIOUS_EVENT(event)) {
v = checkIncDec(event, abs(v), ' ', 'z', 0, isNameCharset);
bool caps = isupper(v);
v = nameChars[checkIncDec(event, nameCharIdx(v), 0, DIM(nameChars)-2)];
if (caps && islower(v)) v = toupper(v);
}

switch (event) {
Expand Down

0 comments on commit 854a9bb

Please sign in to comment.