diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index c73ebfbb87..e1db8ba7d8 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -43,6 +43,7 @@ - feat(disp): Enable rendering to display subsection - feat(keyboard): add user-defined modes - Add support for RT-Thread RTOS +- feat(disp): add utility functions/macros for dealing with non-fullscreen displays ## v8.0.2 (16.07.2021) - fix(theme) improve button focus of keyboard diff --git a/src/hal/lv_hal_disp.c b/src/hal/lv_hal_disp.c index e3e1fc8b60..43b7f43677 100644 --- a/src/hal/lv_hal_disp.c +++ b/src/hal/lv_hal_disp.c @@ -345,9 +345,9 @@ lv_coord_t lv_disp_get_physical_hor_res(lv_disp_t * disp) switch(disp->driver->rotated) { case LV_DISP_ROT_90: case LV_DISP_ROT_270: - return disp->driver->physical_ver_res; + return disp->driver->physical_ver_res > 0 ? disp->driver->physical_ver_res : disp->driver->ver_res; default: - return disp->driver->physical_hor_res; + return disp->driver->physical_hor_res > 0 ? disp->driver->physical_hor_res : disp->driver->hor_res; } } } @@ -368,9 +368,61 @@ lv_coord_t lv_disp_get_physical_ver_res(lv_disp_t * disp) switch(disp->driver->rotated) { case LV_DISP_ROT_90: case LV_DISP_ROT_270: - return disp->driver->physical_hor_res; + return disp->driver->physical_hor_res > 0 ? disp->driver->physical_hor_res : disp->driver->hor_res; default: - return disp->driver->physical_ver_res; + return disp->driver->physical_ver_res > 0 ? disp->driver->physical_ver_res : disp->driver->ver_res; + } + } +} + +/** + * Get the horizontal offset from the full / physical display + * @param disp pointer to a display (NULL to use the default display) + * @return the horizontal offset from the full / physical display + */ +lv_coord_t lv_disp_get_offset_x(lv_disp_t * disp) +{ + if(disp == NULL) disp = lv_disp_get_default(); + + if(disp == NULL) { + return 0; + } + else { + switch(disp->driver->rotated) { + case LV_DISP_ROT_90: + return disp->driver->offset_y; + case LV_DISP_ROT_180: + return lv_disp_get_physical_hor_res(disp) - disp->driver->offset_x; + case LV_DISP_ROT_270: + return lv_disp_get_physical_hor_res(disp) - disp->driver->offset_y; + default: + return disp->driver->offset_x; + } + } +} + +/** + * Get the vertical offset from the full / physical display + * @param disp pointer to a display (NULL to use the default display) + * @return the horizontal offset from the full / physical display + */ +lv_coord_t lv_disp_get_offset_y(lv_disp_t * disp) +{ + if(disp == NULL) disp = lv_disp_get_default(); + + if(disp == NULL) { + return 0; + } + else { + switch(disp->driver->rotated) { + case LV_DISP_ROT_90: + return disp->driver->offset_x; + case LV_DISP_ROT_180: + return lv_disp_get_physical_ver_res(disp) - disp->driver->offset_y; + case LV_DISP_ROT_270: + return lv_disp_get_physical_ver_res(disp) - disp->driver->offset_x; + default: + return disp->driver->offset_y; } } } diff --git a/src/hal/lv_hal_disp.h b/src/hal/lv_hal_disp.h index 96af056ba6..b7ea5047bb 100644 --- a/src/hal/lv_hal_disp.h +++ b/src/hal/lv_hal_disp.h @@ -273,6 +273,20 @@ lv_coord_t lv_disp_get_physical_hor_res(lv_disp_t * disp); */ lv_coord_t lv_disp_get_physical_ver_res(lv_disp_t * disp); +/** + * Get the horizontal offset from the full / physical display + * @param disp pointer to a display (NULL to use the default display) + * @return the horizontal offset from the full / physical display + */ +lv_coord_t lv_disp_get_offset_x(lv_disp_t * disp); + +/** + * Get the vertical offset from the full / physical display + * @param disp pointer to a display (NULL to use the default display) + * @return the horizontal offset from the full / physical display + */ +lv_coord_t lv_disp_get_offset_y(lv_disp_t * disp); + /** * Get if anti-aliasing is enabled for a display or not * @param disp pointer to a display (NULL to use the default display)