mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Refactor printing CJK menu with large font into OLED.cpp
This commit is contained in:
@@ -267,6 +267,26 @@ void OLED::print(const char *const str, FontStyle fontStyle) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints a static string message designed to use the whole screen, starting
|
||||||
|
* from the top-left corner.
|
||||||
|
*
|
||||||
|
* If the message starts with a newline (`\\x01`), the string starting from
|
||||||
|
* after the newline is printed in the large font. Otherwise, the message
|
||||||
|
* is printed in the small font.
|
||||||
|
*
|
||||||
|
* @param string The string message to be printed
|
||||||
|
*/
|
||||||
|
void OLED::printWholeScreen(const char *string) {
|
||||||
|
setCursor(0, 0);
|
||||||
|
if (string[0] == '\x01') {
|
||||||
|
// Empty first line means that this uses large font (for CJK).
|
||||||
|
OLED::print(string + 1, FontStyle::LARGE);
|
||||||
|
} else {
|
||||||
|
OLED::print(string, FontStyle::SMALL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline void stripLeaderZeros(char *buffer, uint8_t places) {
|
inline void stripLeaderZeros(char *buffer, uint8_t places) {
|
||||||
// Removing the leading zero's by swapping them to SymbolSpace
|
// Removing the leading zero's by swapping them to SymbolSpace
|
||||||
// Stop 1 short so that we dont blank entire number if its zero
|
// Stop 1 short so that we dont blank entire number if its zero
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ public:
|
|||||||
static bool getRotation() { return inLeftHandedMode; }
|
static bool getRotation() { return inLeftHandedMode; }
|
||||||
static int16_t getCursorX() { return cursor_x; }
|
static int16_t getCursorX() { return cursor_x; }
|
||||||
static void print(const char *string, FontStyle fontStyle); // Draw a string to the current location, with selected font
|
static void print(const char *string, FontStyle fontStyle); // Draw a string to the current location, with selected font
|
||||||
|
static void printWholeScreen(const char *string);
|
||||||
// Set the cursor location by pixels
|
// Set the cursor location by pixels
|
||||||
static void setCursor(int16_t x, int16_t y) {
|
static void setCursor(int16_t x, int16_t y) {
|
||||||
cursor_x = x;
|
cursor_x = x;
|
||||||
|
|||||||
@@ -237,17 +237,6 @@ const menuitem advancedMenu[] = {
|
|||||||
{nullptr, nullptr, nullptr} // end of menu marker. DO NOT REMOVE
|
{nullptr, nullptr, nullptr} // end of menu marker. DO NOT REMOVE
|
||||||
};
|
};
|
||||||
|
|
||||||
static void printShortDescriptionDoubleLine(SettingsItemIndex settingsItemIndex) {
|
|
||||||
uint8_t shortDescIndex = static_cast<uint8_t>(settingsItemIndex);
|
|
||||||
OLED::setCursor(0, 0);
|
|
||||||
if (SettingsShortNames[shortDescIndex][0] == '\x01') {
|
|
||||||
// Empty first line means that this uses large font (for CJK).
|
|
||||||
OLED::print(SettingsShortNames[shortDescIndex] + 1, FontStyle::LARGE);
|
|
||||||
} else {
|
|
||||||
OLED::print(SettingsShortNames[shortDescIndex], FontStyle::SMALL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints two small lines (or one line for CJK) of short description for
|
* Prints two small lines (or one line for CJK) of short description for
|
||||||
* setting items and prepares cursor after it.
|
* setting items and prepares cursor after it.
|
||||||
@@ -257,7 +246,8 @@ static void printShortDescriptionDoubleLine(SettingsItemIndex settingsItemIndex)
|
|||||||
*/
|
*/
|
||||||
static void printShortDescription(SettingsItemIndex settingsItemIndex, uint16_t cursorCharPosition) {
|
static void printShortDescription(SettingsItemIndex settingsItemIndex, uint16_t cursorCharPosition) {
|
||||||
// print short description (default single line, explicit double line)
|
// print short description (default single line, explicit double line)
|
||||||
printShortDescriptionDoubleLine(settingsItemIndex);
|
uint8_t shortDescIndex = static_cast<uint8_t>(settingsItemIndex);
|
||||||
|
OLED::printWholeScreen(SettingsShortNames[shortDescIndex]);
|
||||||
|
|
||||||
// prepare cursor for value
|
// prepare cursor for value
|
||||||
// make room for scroll indicator
|
// make room for scroll indicator
|
||||||
@@ -1011,18 +1001,8 @@ static bool animOpenState = false;
|
|||||||
|
|
||||||
static void displayMenu(size_t index) {
|
static void displayMenu(size_t index) {
|
||||||
// Call into the menu
|
// Call into the menu
|
||||||
const char *textPtr = SettingsMenuEntries[index];
|
|
||||||
FontStyle font;
|
|
||||||
if (textPtr[0] == '\x01') { // `\x01` is used as newline.
|
|
||||||
// Empty first line means that this uses large font (for CJK).
|
|
||||||
font = FontStyle::LARGE;
|
|
||||||
textPtr++;
|
|
||||||
} else {
|
|
||||||
font = FontStyle::SMALL;
|
|
||||||
}
|
|
||||||
OLED::setCursor(0, 0);
|
|
||||||
// Draw title
|
// Draw title
|
||||||
OLED::print(textPtr, font);
|
OLED::printWholeScreen(SettingsMenuEntries[index]);
|
||||||
// Draw symbol
|
// Draw symbol
|
||||||
// 16 pixel wide image
|
// 16 pixel wide image
|
||||||
// 2 pixel wide scrolling indicator
|
// 2 pixel wide scrolling indicator
|
||||||
|
|||||||
Reference in New Issue
Block a user