Adapt launcher layout to display orientation
This commit is contained in:
@@ -17,7 +17,9 @@ def parse_args() -> argparse.Namespace:
|
|||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description=(
|
description=(
|
||||||
"Create an uncompressed LVGL .bin image for "
|
"Create an uncompressed LVGL .bin image for "
|
||||||
"/sdcard/tactility/launcher/background.bin"
|
"/sdcard/tactility/launcher/background.bin. Use a square image sized "
|
||||||
|
"to the display's longest edge to support both orientations without scaling "
|
||||||
|
"(for example, 320x320 for a 320x240 display)."
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
parser.add_argument("input", type=Path, help="Source image")
|
parser.add_argument("input", type=Path, help="Source image")
|
||||||
|
|||||||
@@ -233,6 +233,11 @@ public:
|
|||||||
lv_obj_set_style_pad_all(parent, 0, LV_PART_MAIN);
|
lv_obj_set_style_pad_all(parent, 0, LV_PART_MAIN);
|
||||||
lv_obj_clear_flag(parent, LV_OBJ_FLAG_SCROLLABLE);
|
lv_obj_clear_flag(parent, LV_OBJ_FLAG_SCROLLABLE);
|
||||||
|
|
||||||
|
auto* display = lv_obj_get_display(parent);
|
||||||
|
const auto display_width = lv_display_get_horizontal_resolution(display);
|
||||||
|
const auto display_height = lv_display_get_vertical_resolution(display);
|
||||||
|
const bool is_portrait = display_height > display_width;
|
||||||
|
|
||||||
auto background_path = lvgl::PATH_PREFIX + app.getPaths()->getAssetsPath(BACKGROUND_ASSET);
|
auto background_path = lvgl::PATH_PREFIX + app.getPaths()->getAssetsPath(BACKGROUND_ASSET);
|
||||||
std::string sd_card_path;
|
std::string sd_card_path;
|
||||||
if (findFirstMountedSdCardPath(sd_card_path)) {
|
if (findFirstMountedSdCardPath(sd_card_path)) {
|
||||||
@@ -241,15 +246,27 @@ public:
|
|||||||
const auto lvgl_custom_background_path = lvgl::PATH_PREFIX + custom_background_path;
|
const auto lvgl_custom_background_path = lvgl::PATH_PREFIX + custom_background_path;
|
||||||
lv_image_header_t header {};
|
lv_image_header_t header {};
|
||||||
if (lv_image_decoder_get_info(lvgl_custom_background_path.c_str(), &header) == LV_RESULT_OK) {
|
if (lv_image_decoder_get_info(lvgl_custom_background_path.c_str(), &header) == LV_RESULT_OK) {
|
||||||
background_path = lvgl_custom_background_path;
|
if (header.w >= display_width && header.h >= display_height) {
|
||||||
LOG_I(
|
background_path = lvgl_custom_background_path;
|
||||||
TAG,
|
LOG_I(
|
||||||
"Using SD background %s (%ux%u, format 0x%02x)",
|
TAG,
|
||||||
custom_background_path.c_str(),
|
"Using SD background %s (%ux%u, format 0x%02x)",
|
||||||
header.w,
|
custom_background_path.c_str(),
|
||||||
header.h,
|
header.w,
|
||||||
header.cf
|
header.h,
|
||||||
);
|
header.cf
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
LOG_W(
|
||||||
|
TAG,
|
||||||
|
"Ignoring undersized SD background %s (%ux%u for %dx%d display)",
|
||||||
|
custom_background_path.c_str(),
|
||||||
|
header.w,
|
||||||
|
header.h,
|
||||||
|
display_width,
|
||||||
|
display_height
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG_W(TAG, "Ignoring invalid SD background %s", custom_background_path.c_str());
|
LOG_W(TAG, "Ignoring invalid SD background %s", custom_background_path.c_str());
|
||||||
}
|
}
|
||||||
@@ -277,7 +294,7 @@ public:
|
|||||||
lv_obj_align(dateLabel, LV_ALIGN_TOP_LEFT, 20, 118);
|
lv_obj_align(dateLabel, LV_ALIGN_TOP_LEFT, 20, 118);
|
||||||
|
|
||||||
dataLabel = lv_label_create(parent);
|
dataLabel = lv_label_create(parent);
|
||||||
lv_obj_set_width(dataLabel, 225);
|
lv_obj_set_width(dataLabel, is_portrait ? display_width - 40 : 225);
|
||||||
lv_label_set_long_mode(dataLabel, LV_LABEL_LONG_MODE_WRAP);
|
lv_label_set_long_mode(dataLabel, LV_LABEL_LONG_MODE_WRAP);
|
||||||
lv_obj_set_style_text_font(dataLabel, lvgl_get_text_font(FONT_SIZE_SMALL), LV_PART_MAIN);
|
lv_obj_set_style_text_font(dataLabel, lvgl_get_text_font(FONT_SIZE_SMALL), LV_PART_MAIN);
|
||||||
lv_obj_set_style_text_color(dataLabel, MUTED_TEXT_COLOR, LV_PART_MAIN);
|
lv_obj_set_style_text_color(dataLabel, MUTED_TEXT_COLOR, LV_PART_MAIN);
|
||||||
@@ -289,9 +306,15 @@ public:
|
|||||||
lv_obj_align(statusLabel, LV_ALIGN_TOP_RIGHT, -15, 8);
|
lv_obj_align(statusLabel, LV_ALIGN_TOP_RIGHT, -15, 8);
|
||||||
|
|
||||||
auto* buttonRail = lv_obj_create(parent);
|
auto* buttonRail = lv_obj_create(parent);
|
||||||
lv_obj_set_size(buttonRail, 60, 184);
|
if (is_portrait) {
|
||||||
lv_obj_align(buttonRail, LV_ALIGN_RIGHT_MID, -7, 8);
|
lv_obj_set_size(buttonRail, 184, 60);
|
||||||
lv_obj_set_flex_flow(buttonRail, LV_FLEX_FLOW_COLUMN);
|
lv_obj_align(buttonRail, LV_ALIGN_BOTTOM_MID, 0, -7);
|
||||||
|
lv_obj_set_flex_flow(buttonRail, LV_FLEX_FLOW_ROW);
|
||||||
|
} else {
|
||||||
|
lv_obj_set_size(buttonRail, 60, 184);
|
||||||
|
lv_obj_align(buttonRail, LV_ALIGN_RIGHT_MID, -7, 8);
|
||||||
|
lv_obj_set_flex_flow(buttonRail, LV_FLEX_FLOW_COLUMN);
|
||||||
|
}
|
||||||
lv_obj_set_flex_align(buttonRail, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
lv_obj_set_flex_align(buttonRail, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||||
lv_obj_set_style_pad_all(buttonRail, 0, LV_PART_MAIN);
|
lv_obj_set_style_pad_all(buttonRail, 0, LV_PART_MAIN);
|
||||||
lv_obj_set_style_border_width(buttonRail, 0, LV_PART_MAIN);
|
lv_obj_set_style_border_width(buttonRail, 0, LV_PART_MAIN);
|
||||||
|
|||||||
Reference in New Issue
Block a user