🚸 Fix / improve Marlin UI and Color UI

This commit is contained in:
Scott Lahteine 2024-08-29 15:41:08 -05:00
parent 21fddc1cc8
commit 68a2459808
15 changed files with 151 additions and 96 deletions

View file

@ -213,7 +213,7 @@ void menu_info_board() {
START_SCREEN();
STATIC_ITEM_F(F(BOARD_INFO_NAME), SS_DEFAULT|SS_INVERT); // MyPrinterController
#ifdef BOARD_WEBSITE_URL
STATIC_ITEM_F(F(BOARD_WEBSITE_URL), SS_LEFT); // www.my3dprinter.com
STATIC_ITEM_F(F(BOARD_WEBSITE_URL), SS_CENTER); // www.my3dprinter.com
#endif
PSTRING_ITEM(MSG_INFO_BAUDRATE, STRINGIFY(BAUDRATE), SS_CENTER); // Baud: 250000
PSTRING_ITEM(MSG_INFO_PROTOCOL, PROTOCOL_VERSION, SS_CENTER); // Protocol: 1.0

View file

@ -265,7 +265,7 @@ class MenuItem_bool : public MenuEditItemBase {
* MenuItem_<type>::action(arg3...)
*
* Examples:
* BACK_ITEM(MSG_INFO_SCREEN)
* BACK_ITEM(MSG_PREV_SCREEN)
* MenuItem_back::action(flabel, ...)
* MenuItem_back::draw(sel, row, flabel, ...)
*

View file

@ -94,7 +94,7 @@ class MenuItem_sdfolder : public MenuItem_sdbase {
static void action(FSTR_P const, CardReader &theCard) {
card.cd(theCard.filename);
encoderTopLine = 0;
ui.encoderPosition = 2 * (ENCODER_STEPS_PER_MENU_ITEM);
ui.encoderPosition = (card.get_num_items() ? 2 : 1) * (ENCODER_STEPS_PER_MENU_ITEM);
ui.screen_changed = true;
TERN_(HAS_MARLINUI_U8GLIB, ui.drawing_screen = false);
ui.refresh();

View file

@ -501,6 +501,7 @@ void menu_move() {
#endif
START_MENU();
BACK_ITEM(MSG_TUNE);
#if HAS_X_AXIS
SUBMENU_N(X_AXIS, MSG_FTM_CMPN_MODE, menu_ftm_shaper_x);

View file

@ -30,40 +30,40 @@
const tImage NoLogo = { nullptr, 0, 0, NOCOLORS };
const tImage images[imgCount] = {
TERN(SHOW_BOOTSCREEN, BOOTSCREEN_LOGO, NoLogo),
HotEnd_64x64x4,
Bed_64x64x4,
Bed_Heated_64x64x4,
Chamber_64x64x4,
Chamber_Heated_64x64x4,
Fan0_64x64x4,
Fan_Slow0_64x64x4,
Fan_Slow1_64x64x4,
Fan_Fast0_64x64x4,
Fan_Fast1_64x64x4,
Feedrate_32x32x4,
Flowrate_32x32x4,
SD_64x64x4,
Menu_64x64x4,
Settings_64x64x4,
Directory_32x32x4,
Confirm_64x64x4,
Cancel_64x64x4,
Increase_64x64x4,
Decrease_64x64x4,
Back_32x32x4,
Up_32x32x4,
Down_32x32x4,
Left_32x32x4,
Right_32x32x4,
Refresh_32x32x4,
Leveling_32x32x4,
Slider8x16x4,
Home_64x64x4,
BtnRounded_64x52x4,
BtnRounded_42x39x4,
Time_Elapsed_32x32x4,
Time_Remaining_32x32x4,
TERN(SHOW_BOOTSCREEN, BOOTSCREEN_LOGO, NoLogo), // imgBootScreen
HotEnd_64x64x4, // imgHotEnd
Bed_64x64x4, // imgBed
Bed_Heated_64x64x4, // imgBedHeated
Chamber_64x64x4, // imgChamber
Chamber_Heated_64x64x4, // imgChamberHeated
Fan0_64x64x4, // imgFanIdle
Fan_Slow0_64x64x4, // imgFanSlow0
Fan_Slow1_64x64x4, // imgFanSlow1
Fan_Fast0_64x64x4, // imgFanFast0
Fan_Fast1_64x64x4, // imgFanFast1
Feedrate_32x32x4, // imgFeedRate
Flowrate_32x32x4, // imgFlowRate
SD_64x64x4, // imgSD
Menu_64x64x4, // imgMenu
Settings_64x64x4, // imgSettings
Directory_32x32x4, // imgDirectory
Confirm_64x64x4, // imgConfirm
Cancel_64x64x4, // imgCancel
Increase_64x64x4, // imgIncrease
Decrease_64x64x4, // imgDecrease
Back_32x32x4, // imgBack
Up_32x32x4, // imgUp
Down_32x32x4, // imgDown
Left_32x32x4, // imgLeft
Right_32x32x4, // imgRight
Refresh_32x32x4, // imgRefresh
Leveling_32x32x4, // imgLeveling
Slider8x16x4, // imgSlider
Home_64x64x4, // imgHome
BtnRounded_64x52x4, // imgBtn52Rounded
BtnRounded_42x39x4, // imgBtn39Rounded
Time_Elapsed_32x32x4, // imgTimeElapsed
Time_Remaining_32x32x4, // imgTimeRemaining
};
#endif // HAS_GRAPHICAL_TFT

View file

@ -30,40 +30,40 @@
#endif
enum MarlinImage : uint8_t {
imgBootScreen = 0x00,
imgHotEnd,
imgBed,
imgBedHeated,
imgChamber,
imgChamberHeated,
imgFanIdle,
imgFanSlow0,
imgFanSlow1,
imgFanFast0,
imgFanFast1,
imgFeedRate,
imgFlowRate,
imgSD,
imgMenu,
imgSettings,
imgDirectory,
imgConfirm,
imgCancel,
imgIncrease,
imgDecrease,
imgBack,
imgUp,
imgDown,
imgLeft,
imgRight,
imgRefresh,
imgLeveling,
imgSlider,
imgHome,
imgBtn52Rounded,
imgBtn39Rounded,
imgTimeElapsed,
imgTimeRemaining,
imgBootScreen = 0x00, // BOOTSCREEN_LOGO / NoLogo
imgHotEnd, // HotEnd_64x64x4
imgBed, // Bed_64x64x4
imgBedHeated, // Bed_Heated_64x64x4
imgChamber, // Chamber_64x64x4
imgChamberHeated, // Chamber_Heated_64x64x4
imgFanIdle, // Fan0_64x64x4
imgFanSlow0, // Fan_Slow0_64x64x4
imgFanSlow1, // Fan_Slow1_64x64x4
imgFanFast0, // Fan_Fast0_64x64x4
imgFanFast1, // Fan_Fast1_64x64x4
imgFeedRate, // Feedrate_32x32x4
imgFlowRate, // Flowrate_32x32x4
imgSD, // SD_64x64x4
imgMenu, // Menu_64x64x4
imgSettings, // Settings_64x64x4
imgDirectory, // Directory_32x32x4
imgConfirm, // Confirm_64x64x4
imgCancel, // Cancel_64x64x4
imgIncrease, // Increase_64x64x4
imgDecrease, // Decrease_64x64x4
imgBack, // Back_32x32x4
imgUp, // Up_32x32x4
imgDown, // Down_32x32x4
imgLeft, // Left_32x32x4
imgRight, // Right_32x32x4
imgRefresh, // Refresh_32x32x4
imgLeveling, // Leveling_32x32x4
imgSlider, // Slider8x16x4
imgHome, // Home_64x64x4
imgBtn52Rounded, // BtnRounded_64x52x4
imgBtn39Rounded, // BtnRounded_42x39x4
imgTimeElapsed, // Time_Elapsed_32x32x4
imgTimeRemaining, // Time_Remaining_32x32x4
// Special values - must be at the end!
imgCount,
noImage = imgCount,

View file

@ -46,6 +46,8 @@
#define COLOR_SD_ENABLED COLOR_CONTROL_ENABLED
#define COLOR_SD_DISABLED COLOR_CONTROL_DISABLED
#define COLOR_MENU_TEXT COLOR_WHITE
#define COLOR_MENU_STATIC_TEXT COLOR_WHITE
#define COLOR_MENU_BACK_TEXT COLOR_YELLOW
#define COLOR_MENU_VALUE_FONT COLOR_ORANGE2
#define COLOR_SLIDER COLOR_ORANGE2
#define COLOR_INCREASE COLOR_WHITE

View file

@ -106,6 +106,12 @@
#ifndef COLOR_MENU_TEXT
#define COLOR_MENU_TEXT COLOR_YELLOW
#endif
#ifndef COLOR_MENU_TEXT
#define COLOR_MENU_STATIC_TEXT COLOR_SILVER
#endif
#ifndef COLOR_MENU_BACK_TEXT
#define COLOR_MENU_BACK_TEXT COLOR_CYAN
#endif
#ifndef COLOR_MENU_VALUE
#define COLOR_MENU_VALUE COLOR_WHITE
#endif

View file

@ -104,6 +104,12 @@
#ifndef COLOR_MENU_TEXT
#define COLOR_MENU_TEXT COLOR_YELLOW
#endif
#ifndef COLOR_MENU_STATIC_TEXT
#define COLOR_MENU_STATIC_TEXT COLOR_SILVER
#endif
#ifndef COLOR_MENU_BACK_TEXT
#define COLOR_MENU_BACK_TEXT COLOR_WHITE
#endif
#ifndef COLOR_MENU_VALUE
#define COLOR_MENU_VALUE COLOR_WHITE
#endif

View file

@ -24,12 +24,20 @@
// -------------------------------- Core Parameters --------------------------------
#define MENU_TEXT_X 16
#define MENU_TEXT_X (5 + 32 + 5 + 6)
#define MENU_TEXT_Y tft_string.vcenter(MENU_ITEM_HEIGHT)
#define MENU_ITEM_ICON_X 5
#define MENU_ITEM_ICON_Y 5
#define MENU_ITEM_ICON_SPACE 42
#define MENU_ITEM_ICON_SPACE (5 + 32 + 5)
#ifndef MENU_ITEM_SUBMENU_ICON_X
#define MENU_ITEM_SUBMENU_ICON_X (TFT_WIDTH - 32 - 32)
#endif
#ifndef MENU_ITEM_BACK_LINE_SHIFT
#define MENU_ITEM_BACK_LINE_SHIFT -32
#endif
#define MENU_ITEM_HEIGHT 43
#define MENU_LINE_HEIGHT (MENU_ITEM_HEIGHT + 2)

View file

@ -29,7 +29,7 @@
#define MENU_ITEM_ICON_X 5
#define MENU_ITEM_ICON_Y 5
#define MENU_ITEM_ICON_SPACE 42
#define MENU_ITEM_ICON_SPACE (5 + 32 + 5)
#define MENU_ITEM_HEIGHT 43
#define MENU_LINE_HEIGHT (MENU_ITEM_HEIGHT + 2)

View file

@ -29,7 +29,7 @@
#define MENU_ITEM_ICON_X 5
#define MENU_ITEM_ICON_Y 5
#define MENU_ITEM_ICON_SPACE 42
#define MENU_ITEM_ICON_SPACE (5 + 32 + 5)
#define MENU_ITEM_HEIGHT 36
#define MENU_LINE_HEIGHT (MENU_ITEM_HEIGHT + 2)

View file

@ -29,7 +29,7 @@
#define MENU_ITEM_ICON_X 5
#define MENU_ITEM_ICON_Y 5
#define MENU_ITEM_ICON_SPACE 42
#define MENU_ITEM_ICON_SPACE (5 + 32 + 5)
#define MENU_ITEM_HEIGHT 43
#define MENU_LINE_HEIGHT (MENU_ITEM_HEIGHT + 2)

View file

@ -222,7 +222,9 @@ void menu_line(const uint8_t row, uint16_t color) {
text_line(MENU_TOP_LINE_Y + cursor.y * MENU_LINE_HEIGHT, color);
}
void menu_item(const uint8_t row, bool sel ) {
uint16_t menu_item(const uint8_t row, const bool sel) {
const uint16_t lineColor = sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND;
#if ENABLED(TOUCH_SCREEN)
if (row == 0) {
touch.clear();
@ -230,11 +232,13 @@ void menu_item(const uint8_t row, bool sel ) {
}
#endif
menu_line(row, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
menu_line(row, lineColor);
#if ENABLED(TOUCH_SCREEN)
const TouchControlType tct = TERN(SINGLE_TOUCH_NAVIGATION, true, sel) ? MENU_CLICK : MENU_ITEM;
touch.add_control(tct, 0, MENU_TOP_LINE_Y + row * MENU_LINE_HEIGHT, TFT_WIDTH, MENU_ITEM_HEIGHT, encoderTopLine + row);
#endif
return lineColor;
}
void add_control(uint16_t x, uint16_t y, TouchControlType control_type, intptr_t data, MarlinImage image, bool is_enabled, uint16_t color_enabled, uint16_t color_disabled) {
@ -319,30 +323,57 @@ void lcd_put_int(const int i) {
// Draw a generic menu item with pre_char (if selected) and post_char
void MenuItemBase::_draw(const bool sel, const uint8_t row, FSTR_P const ftpl, const char pre_char, const char post_char) {
menu_item(row, sel);
const uint16_t lineColor = menu_item(row, sel);
const char *string = FTOP(ftpl);
#ifndef MENU_ITEM_BACK_LINE_SHIFT
#define MENU_ITEM_BACK_LINE_SHIFT 0
#endif
int8_t line_shift = 0;
uint16_t color = COLOR_MENU_TEXT;
// Determine an image to show in the left column
MarlinImage image = noImage;
switch (*string) {
case LCD_STR_REFRESH[0]: image = imgRefresh; break;
case LCD_STR_FOLDER[0]: image = imgDirectory; break;
if (pre_char == LCD_STR_UPLEVEL[0]) {
image = imgLeft;
color = COLOR_MENU_BACK_TEXT;
}
else {
switch (*string) {
case LCD_STR_REFRESH[0]: image = imgRefresh; break;
case LCD_STR_FOLDER[0]: image = imgDirectory; break;
}
if (image != noImage) {
line_shift = MENU_ITEM_ICON_SPACE;
string++;
if (*string == ' ') string++;
}
}
uint8_t offset = MENU_TEXT_X;
// For narrower screens text-only items align fully left
// For wider screens text aligns on the post-icon column
uint8_t text_x = (TFT_WIDTH >= 480) ? MENU_ITEM_ICON_SPACE : MENU_TEXT_X;
if (image != noImage) {
string++;
offset = MENU_ITEM_ICON_SPACE;
tft.add_image(MENU_ITEM_ICON_X, MENU_ITEM_ICON_Y, image, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
text_x = MENU_ITEM_ICON_SPACE;
tft.add_image(MENU_ITEM_ICON_X + line_shift, MENU_ITEM_ICON_Y, image, color, lineColor);
}
// Add the text content from ftpl
tft_string.set(string, itemIndex, itemStringC, itemStringF);
tft.add_text(text_x + line_shift, MENU_TEXT_Y, color, tft_string);
tft.add_text(offset, MENU_TEXT_Y, COLOR_MENU_TEXT, tft_string);
#ifndef MENU_ITEM_SUBMENU_ICON_X
#define MENU_ITEM_SUBMENU_ICON_X (TFT_WIDTH - 32)
#endif
if (post_char == LCD_STR_ARROW_RIGHT[0])
tft.add_image(MENU_ITEM_SUBMENU_ICON_X, MENU_ITEM_ICON_Y, imgRight, color, lineColor);
}
// Draw a menu item with a (potentially) editable value
void MenuEditItemBase::draw(const bool sel, const uint8_t row, FSTR_P const ftpl, const char * const inStr, const bool pgm) {
menu_item(row, sel);
(void)menu_item(row, sel);
tft_string.set(ftpl, itemIndex, itemStringC, itemStringF);
tft.add_text(MENU_TEXT_X, MENU_TEXT_Y, COLOR_MENU_TEXT, tft_string);
@ -354,7 +385,7 @@ void MenuEditItemBase::draw(const bool sel, const uint8_t row, FSTR_P const ftpl
// Draw a static item with no left-right margin required. Centered by default.
void MenuItem_static::draw(const uint8_t row, FSTR_P const ftpl, const uint8_t style/*=SS_DEFAULT*/, const char *vstr/*=nullptr*/) {
menu_item(row);
(void)menu_item(row);
if (ftpl)
tft_string.set(ftpl, itemIndex, itemStringC, itemStringF);
@ -364,7 +395,7 @@ void MenuItem_static::draw(const uint8_t row, FSTR_P const ftpl, const uint8_t s
const bool center = bool(style & SS_CENTER), full = bool(style & SS_FULL);
if (!full || !vstr) {
if (vstr) tft_string.add(vstr);
tft.add_text(center ? tft_string.center(TFT_WIDTH) : 0, MENU_TEXT_Y, COLOR_MENU_TEXT, tft_string);
tft.add_text(center ? tft_string.center(TFT_WIDTH) : 0, MENU_TEXT_Y, COLOR_MENU_STATIC_TEXT, tft_string);
return;
}
@ -372,21 +403,22 @@ void MenuItem_static::draw(const uint8_t row, FSTR_P const ftpl, const uint8_t s
if (*vstr == ':') { tft_string.add(':'); vstr++; }
// Left-justified label
tft.add_text(0, MENU_TEXT_Y, COLOR_MENU_TEXT, tft_string);
tft.add_text(0, MENU_TEXT_Y, COLOR_MENU_STATIC_TEXT, tft_string);
// Right-justified value, after spaces
while (*vstr == ' ') vstr++;
tft_string.set(vstr);
tft.add_text(TFT_WIDTH - 1 - tft_string.width(), MENU_TEXT_Y, COLOR_MENU_TEXT, tft_string);
tft.add_text(TFT_WIDTH - 1 - tft_string.width(), MENU_TEXT_Y, COLOR_MENU_STATIC_TEXT, tft_string);
}
#if HAS_MEDIA
void MenuItem_sdbase::draw(const bool sel, const uint8_t row, FSTR_P const, CardReader &theCard, const bool isDir) {
menu_item(row, sel);
if (isDir) tft.add_image(MENU_ITEM_ICON_X, MENU_ITEM_ICON_Y, imgDirectory, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
const uint16_t lineColor = menu_item(row, sel);
constexpr uint8_t line_shift = (TFT_WIDTH >= 480) ? MENU_ITEM_ICON_SPACE : 0;
if (isDir) tft.add_image(MENU_ITEM_ICON_X + line_shift, MENU_ITEM_ICON_Y, imgDirectory, COLOR_MENU_TEXT, lineColor);
uint8_t maxlen = (MENU_ITEM_HEIGHT) - (MENU_TEXT_Y) + 1;
tft.add_text(MENU_ITEM_ICON_SPACE, MENU_TEXT_Y, COLOR_MENU_TEXT, ui.scrolled_filename(theCard, maxlen, sel));
tft.add_text(MENU_ITEM_ICON_SPACE + line_shift, MENU_TEXT_Y, COLOR_MENU_TEXT, ui.scrolled_filename(theCard, maxlen, sel));
}
#endif

View file

@ -114,7 +114,7 @@ void draw_fan_status(uint16_t x, uint16_t y, const bool blink);
void text_line(const uint16_t y, uint16_t color=COLOR_BACKGROUND);
void menu_line(const uint8_t row, uint16_t color=COLOR_BACKGROUND);
void menu_item(const uint8_t row, bool sel = false);
uint16_t menu_item(const uint8_t row, bool sel = false);
typedef void (*screenFunc_t)();
void add_control(