fix: storage label 45deg tilt, smart MB/GB display
- lbl_sd_info: fixed width 280px + LV_TEXT_ALIGN_LEFT - lbl_sd_pct: fixed width 60px + LV_TEXT_ALIGN_RIGHT - ui_set_sd: show MB when used < 1024 (e.g. '61 MB / 7.3 GB') instead of '0.1 / 7.3 GB'
This commit is contained in:
+15
-4
@@ -213,10 +213,14 @@ void ui_init()
|
||||
/* size text left-aligned */
|
||||
lbl_sd_info = make_label(scr, &lv_font_montserrat_14, CLR_GRAY,
|
||||
LV_ALIGN_TOP_LEFT, 28, 350, "0.0 / 0.0 GB");
|
||||
lv_obj_set_width(lbl_sd_info, 280); /* fixed width prevents 45° drift */
|
||||
lv_obj_set_style_text_align(lbl_sd_info, LV_TEXT_ALIGN_LEFT, 0);
|
||||
|
||||
/* percentage right-aligned */
|
||||
lbl_sd_pct = make_label(scr, &lv_font_montserrat_14, CLR_GRAY,
|
||||
LV_ALIGN_TOP_RIGHT, -28, 350, "0%");
|
||||
lv_obj_set_width(lbl_sd_pct, 60); /* fixed width prevents 45° drift */
|
||||
lv_obj_set_style_text_align(lbl_sd_pct, LV_TEXT_ALIGN_RIGHT, 0);
|
||||
|
||||
/* ────────────────────────────────────────────────────────────── */
|
||||
/* CLOCK AREA (y = 385 … 490) */
|
||||
@@ -327,12 +331,19 @@ void ui_set_sd(uint64_t used_mb, uint64_t total_mb)
|
||||
|
||||
/* Format with one decimal using integer math (LVGL builtin sprintf
|
||||
may lack %f support) */
|
||||
uint32_t used_gb_i = (uint32_t)(used_mb / 1024);
|
||||
uint32_t used_gb_f = (uint32_t)((used_mb % 1024) * 10 / 1024);
|
||||
uint32_t total_gb_i = (uint32_t)(total_mb / 1024);
|
||||
uint32_t total_gb_f = (uint32_t)((total_mb % 1024) * 10 / 1024);
|
||||
lv_label_set_text_fmt(lbl_sd_info, "%lu.%lu / %lu.%lu GB",
|
||||
used_gb_i, used_gb_f, total_gb_i, total_gb_f);
|
||||
if (used_mb < 1024) {
|
||||
/* Show used in MB when under 1 GB, e.g. "61 MB / 7.3 GB" */
|
||||
lv_label_set_text_fmt(lbl_sd_info, "%lu MB / %lu.%lu GB",
|
||||
(uint32_t)used_mb, total_gb_i, total_gb_f);
|
||||
} else {
|
||||
/* Show both in GB with one decimal, e.g. "2.4 / 7.3 GB" */
|
||||
uint32_t used_gb_i = (uint32_t)(used_mb / 1024);
|
||||
uint32_t used_gb_f = (uint32_t)((used_mb % 1024) * 10 / 1024);
|
||||
lv_label_set_text_fmt(lbl_sd_info, "%lu.%lu / %lu.%lu GB",
|
||||
used_gb_i, used_gb_f, total_gb_i, total_gb_f);
|
||||
}
|
||||
lv_label_set_text_fmt(lbl_sd_pct, "%d%%", pct);
|
||||
|
||||
/* bar turns red when storage > 90% */
|
||||
|
||||
Reference in New Issue
Block a user