mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[kandinsky | code] Coding style improvement in the new font (part 1)
This commit is contained in:
@@ -31,95 +31,6 @@ bool isItalic(mp_token_kind_t tokenKind) {
|
||||
if (tokenKind == MP_TOKEN_STRING) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static_assert(MP_TOKEN_ELLIPSIS + 1 == MP_TOKEN_KW_FALSE
|
||||
&& MP_TOKEN_KW_FALSE + 1 == MP_TOKEN_KW_NONE
|
||||
&& MP_TOKEN_KW_NONE + 1 == MP_TOKEN_KW_TRUE
|
||||
&& MP_TOKEN_KW_TRUE + 1 == MP_TOKEN_KW___DEBUG__
|
||||
&& MP_TOKEN_KW___DEBUG__ + 1 == MP_TOKEN_KW_AND
|
||||
&& MP_TOKEN_KW_AND + 1 == MP_TOKEN_KW_AS
|
||||
&& MP_TOKEN_KW_AS + 1 == MP_TOKEN_KW_ASSERT
|
||||
/* Here there are keywords that depend on MICROPY_PY_ASYNC_AWAIT, we do
|
||||
* not test them */
|
||||
&& MP_TOKEN_KW_BREAK + 1 == MP_TOKEN_KW_CLASS
|
||||
&& MP_TOKEN_KW_CLASS + 1 == MP_TOKEN_KW_CONTINUE
|
||||
&& MP_TOKEN_KW_CONTINUE + 1 == MP_TOKEN_KW_DEF
|
||||
&& MP_TOKEN_KW_DEF + 1 == MP_TOKEN_KW_DEL
|
||||
&& MP_TOKEN_KW_DEL + 1 == MP_TOKEN_KW_ELIF
|
||||
&& MP_TOKEN_KW_ELIF + 1 == MP_TOKEN_KW_ELSE
|
||||
&& MP_TOKEN_KW_ELSE + 1 == MP_TOKEN_KW_EXCEPT
|
||||
&& MP_TOKEN_KW_EXCEPT + 1 == MP_TOKEN_KW_FINALLY
|
||||
&& MP_TOKEN_KW_FINALLY + 1 == MP_TOKEN_KW_FOR
|
||||
&& MP_TOKEN_KW_FOR + 1 == MP_TOKEN_KW_FROM
|
||||
&& MP_TOKEN_KW_FROM + 1 == MP_TOKEN_KW_GLOBAL
|
||||
&& MP_TOKEN_KW_GLOBAL + 1 == MP_TOKEN_KW_IF
|
||||
&& MP_TOKEN_KW_IF + 1 == MP_TOKEN_KW_IMPORT
|
||||
&& MP_TOKEN_KW_IMPORT + 1 == MP_TOKEN_KW_IN
|
||||
&& MP_TOKEN_KW_IN + 1 == MP_TOKEN_KW_IS
|
||||
&& MP_TOKEN_KW_IS + 1 == MP_TOKEN_KW_LAMBDA
|
||||
&& MP_TOKEN_KW_LAMBDA + 1 == MP_TOKEN_KW_NONLOCAL
|
||||
&& MP_TOKEN_KW_NONLOCAL + 1 == MP_TOKEN_KW_NOT
|
||||
&& MP_TOKEN_KW_NOT + 1 == MP_TOKEN_KW_OR
|
||||
&& MP_TOKEN_KW_OR + 1 == MP_TOKEN_KW_PASS
|
||||
&& MP_TOKEN_KW_PASS + 1 == MP_TOKEN_KW_RAISE
|
||||
&& MP_TOKEN_KW_RAISE + 1 == MP_TOKEN_KW_RETURN
|
||||
&& MP_TOKEN_KW_RETURN + 1 == MP_TOKEN_KW_TRY
|
||||
&& MP_TOKEN_KW_TRY + 1 == MP_TOKEN_KW_WHILE
|
||||
&& MP_TOKEN_KW_WHILE + 1 == MP_TOKEN_KW_WITH
|
||||
&& MP_TOKEN_KW_WITH + 1 == MP_TOKEN_KW_YIELD
|
||||
&& MP_TOKEN_KW_YIELD + 1 == MP_TOKEN_OP_ASSIGN
|
||||
&& MP_TOKEN_OP_ASSIGN + 1 == MP_TOKEN_OP_TILDE,
|
||||
"MP_TOKEN order changed, so Code::PythonTextArea::TokenColor might need to change too.");
|
||||
if (tokenKind >= MP_TOKEN_KW_FALSE && tokenKind <= MP_TOKEN_KW_YIELD) {
|
||||
return true;
|
||||
}
|
||||
static_assert(MP_TOKEN_OP_TILDE + 1 == MP_TOKEN_OP_LESS
|
||||
&& MP_TOKEN_OP_LESS + 1 == MP_TOKEN_OP_MORE
|
||||
&& MP_TOKEN_OP_MORE + 1 == MP_TOKEN_OP_DBL_EQUAL
|
||||
&& MP_TOKEN_OP_DBL_EQUAL + 1 == MP_TOKEN_OP_LESS_EQUAL
|
||||
&& MP_TOKEN_OP_LESS_EQUAL + 1 == MP_TOKEN_OP_MORE_EQUAL
|
||||
&& MP_TOKEN_OP_MORE_EQUAL + 1 == MP_TOKEN_OP_NOT_EQUAL
|
||||
&& MP_TOKEN_OP_NOT_EQUAL + 1 == MP_TOKEN_OP_PIPE
|
||||
&& MP_TOKEN_OP_PIPE + 1 == MP_TOKEN_OP_CARET
|
||||
&& MP_TOKEN_OP_CARET + 1 == MP_TOKEN_OP_AMPERSAND
|
||||
&& MP_TOKEN_OP_AMPERSAND + 1 == MP_TOKEN_OP_DBL_LESS
|
||||
&& MP_TOKEN_OP_DBL_LESS + 1 == MP_TOKEN_OP_DBL_MORE
|
||||
&& MP_TOKEN_OP_DBL_MORE + 1 == MP_TOKEN_OP_PLUS
|
||||
&& MP_TOKEN_OP_PLUS + 1 == MP_TOKEN_OP_MINUS
|
||||
&& MP_TOKEN_OP_MINUS + 1 == MP_TOKEN_OP_STAR
|
||||
&& MP_TOKEN_OP_STAR + 1 == MP_TOKEN_OP_AT
|
||||
&& MP_TOKEN_OP_AT + 1 == MP_TOKEN_OP_DBL_SLASH
|
||||
&& MP_TOKEN_OP_DBL_SLASH + 1 == MP_TOKEN_OP_SLASH
|
||||
&& MP_TOKEN_OP_SLASH + 1 == MP_TOKEN_OP_PERCENT
|
||||
&& MP_TOKEN_OP_PERCENT + 1 == MP_TOKEN_OP_DBL_STAR
|
||||
&& MP_TOKEN_OP_DBL_STAR + 1 == MP_TOKEN_DEL_PIPE_EQUAL
|
||||
&& MP_TOKEN_DEL_PIPE_EQUAL + 1 == MP_TOKEN_DEL_CARET_EQUAL
|
||||
&& MP_TOKEN_DEL_CARET_EQUAL + 1 == MP_TOKEN_DEL_AMPERSAND_EQUAL
|
||||
&& MP_TOKEN_DEL_AMPERSAND_EQUAL + 1 == MP_TOKEN_DEL_DBL_LESS_EQUAL
|
||||
&& MP_TOKEN_DEL_DBL_LESS_EQUAL + 1 == MP_TOKEN_DEL_DBL_MORE_EQUAL
|
||||
&& MP_TOKEN_DEL_DBL_MORE_EQUAL + 1 == MP_TOKEN_DEL_PLUS_EQUAL
|
||||
&& MP_TOKEN_DEL_PLUS_EQUAL + 1 == MP_TOKEN_DEL_MINUS_EQUAL
|
||||
&& MP_TOKEN_DEL_MINUS_EQUAL + 1 == MP_TOKEN_DEL_STAR_EQUAL
|
||||
&& MP_TOKEN_DEL_STAR_EQUAL + 1 == MP_TOKEN_DEL_AT_EQUAL
|
||||
&& MP_TOKEN_DEL_AT_EQUAL + 1 == MP_TOKEN_DEL_DBL_SLASH_EQUAL
|
||||
&& MP_TOKEN_DEL_DBL_SLASH_EQUAL + 1 == MP_TOKEN_DEL_SLASH_EQUAL
|
||||
&& MP_TOKEN_DEL_SLASH_EQUAL + 1 == MP_TOKEN_DEL_PERCENT_EQUAL
|
||||
&& MP_TOKEN_DEL_PERCENT_EQUAL + 1 == MP_TOKEN_DEL_DBL_STAR_EQUAL
|
||||
&& MP_TOKEN_DEL_DBL_STAR_EQUAL + 1 == MP_TOKEN_DEL_PAREN_OPEN
|
||||
&& MP_TOKEN_DEL_PAREN_OPEN + 1 == MP_TOKEN_DEL_PAREN_CLOSE
|
||||
&& MP_TOKEN_DEL_PAREN_CLOSE + 1 == MP_TOKEN_DEL_BRACKET_OPEN
|
||||
&& MP_TOKEN_DEL_BRACKET_OPEN + 1 == MP_TOKEN_DEL_BRACKET_CLOSE
|
||||
&& MP_TOKEN_DEL_BRACKET_CLOSE + 1 == MP_TOKEN_DEL_BRACE_OPEN
|
||||
&& MP_TOKEN_DEL_BRACE_OPEN + 1 == MP_TOKEN_DEL_BRACE_CLOSE
|
||||
&& MP_TOKEN_DEL_BRACE_CLOSE + 1 == MP_TOKEN_DEL_COMMA
|
||||
&& MP_TOKEN_DEL_COMMA + 1 == MP_TOKEN_DEL_COLON
|
||||
&& MP_TOKEN_DEL_COLON + 1 == MP_TOKEN_DEL_PERIOD
|
||||
&& MP_TOKEN_DEL_PERIOD + 1 == MP_TOKEN_DEL_SEMICOLON
|
||||
&& MP_TOKEN_DEL_SEMICOLON + 1 == MP_TOKEN_DEL_EQUAL
|
||||
&& MP_TOKEN_DEL_EQUAL + 1 == MP_TOKEN_DEL_MINUS_MORE,
|
||||
"MP_TOKEN order changed, so Code::PythonTextArea::TokenColor might need to change too.");
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -393,8 +304,8 @@ void PythonTextArea::ContentView::drawLine(KDContext * ctx, int line, const char
|
||||
|
||||
// If the token is being autocompleted, use DefaultColor/Font
|
||||
KDColor color = (tokenFrom <= autocompleteStart && autocompleteStart < tokenEnd) ? Palette::CodeText : TokenColor(lex->tok_kind);
|
||||
bool font = (tokenFrom <= autocompleteStart && autocompleteStart < tokenEnd) ? false:isItalic(lex->tok_kind);
|
||||
|
||||
bool italic = (tokenFrom <= autocompleteStart && autocompleteStart < tokenEnd) ? false : isItalic(lex->tok_kind);
|
||||
|
||||
LOG_DRAW("Draw \"%.*s\" for token %d\n", tokenLength, tokenFrom, lex->tok_kind);
|
||||
drawStringAt(ctx, line,
|
||||
UTF8Helper::GlyphOffsetAtCodePoint(text, tokenFrom),
|
||||
@@ -405,7 +316,8 @@ void PythonTextArea::ContentView::drawLine(KDContext * ctx, int line, const char
|
||||
selectionStart,
|
||||
selectionEnd,
|
||||
HighlightColor,
|
||||
font);
|
||||
italic
|
||||
);
|
||||
|
||||
mp_lexer_to_next(lex);
|
||||
LOG_DRAW("Pop token %d\n", lex->tok_kind);
|
||||
|
||||
Reference in New Issue
Block a user