Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bw): change char selection order when editing names #5390

Merged
merged 3 commits into from
Aug 8, 2024
Merged
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
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
Loading